]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #7169 from donaldsharp/some_code_cleanup
[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
5d5393b9 76FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
77 {
78 .val_bool = false,
79 .match_profile = "traditional",
80 .match_version = "< 7.4",
81 },
82 { .val_bool = true },
5d5393b9
DL
83)
84FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
85 { .val_bool = true, .match_profile = "datacenter", },
86 { .val_bool = false },
5d5393b9 87)
aef999a2
DA
88FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
89 { .val_bool = true, .match_profile = "datacenter", },
90 { .val_bool = false },
91)
5d5393b9 92FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
5d5393b9
DL
95)
96FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
5d5393b9
DL
99)
100FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
101 { .val_ulong = 10, .match_profile = "datacenter", },
102 { .val_ulong = 120 },
103)
104FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
105 { .val_ulong = 9, .match_profile = "datacenter", },
106 { .val_ulong = 180 },
107)
108FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
109 { .val_ulong = 3, .match_profile = "datacenter", },
110 { .val_ulong = 60 },
111)
1d3fdccf
DA
112FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
113 { .val_bool = false, .match_profile = "datacenter", },
114 { .val_bool = false, .match_version = "< 7.4", },
115 { .val_bool = true },
116)
5d5393b9 117
dd65f45e
DL
118DEFINE_HOOK(bgp_inst_config_write,
119 (struct bgp *bgp, struct vty *vty),
120 (bgp, vty))
718e3744 121
36235319
QY
122#define GR_NO_OPER \
123 "The Graceful Restart No Operation was executed as cmd same as previous one."
124#define GR_INVALID \
125 "The Graceful Restart command used is not valid at this moment."
d62a17ae 126static struct peer_group *listen_range_exists(struct bgp *bgp,
127 struct prefix *range, int exact);
128
055679e9 129/* Show BGP peer's information. */
130enum show_type {
131 show_all,
132 show_peer,
133 show_ipv4_all,
134 show_ipv6_all,
135 show_ipv4_peer,
136 show_ipv6_peer
137};
138
36235319
QY
139static struct peer_group *listen_range_exists(struct bgp *bgp,
140 struct prefix *range, int exact);
2986cac2 141
36235319
QY
142static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
143 struct bgp *bgp,
144 bool use_json,
145 json_object *json);
2986cac2 146
36235319
QY
147static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
148 enum show_type type,
149 const char *ip_str,
150 afi_t afi, bool use_json);
2986cac2 151
d62a17ae 152static enum node_type bgp_node_type(afi_t afi, safi_t safi)
153{
154 switch (afi) {
155 case AFI_IP:
156 switch (safi) {
157 case SAFI_UNICAST:
158 return BGP_IPV4_NODE;
d62a17ae 159 case SAFI_MULTICAST:
160 return BGP_IPV4M_NODE;
d62a17ae 161 case SAFI_LABELED_UNICAST:
162 return BGP_IPV4L_NODE;
d62a17ae 163 case SAFI_MPLS_VPN:
164 return BGP_VPNV4_NODE;
7c40bf39 165 case SAFI_FLOWSPEC:
166 return BGP_FLOWSPECV4_NODE;
5c525538
RW
167 default:
168 /* not expected */
169 return BGP_IPV4_NODE;
d62a17ae 170 }
171 break;
172 case AFI_IP6:
173 switch (safi) {
174 case SAFI_UNICAST:
175 return BGP_IPV6_NODE;
d62a17ae 176 case SAFI_MULTICAST:
177 return BGP_IPV6M_NODE;
d62a17ae 178 case SAFI_LABELED_UNICAST:
179 return BGP_IPV6L_NODE;
d62a17ae 180 case SAFI_MPLS_VPN:
181 return BGP_VPNV6_NODE;
7c40bf39 182 case SAFI_FLOWSPEC:
183 return BGP_FLOWSPECV6_NODE;
5c525538
RW
184 default:
185 /* not expected */
186 return BGP_IPV4_NODE;
d62a17ae 187 }
188 break;
189 case AFI_L2VPN:
190 return BGP_EVPN_NODE;
b26f891d 191 case AFI_UNSPEC:
d62a17ae 192 case AFI_MAX:
193 // We should never be here but to clarify the switch statement..
194 return BGP_IPV4_NODE;
d62a17ae 195 }
196
197 // Impossible to happen
198 return BGP_IPV4_NODE;
f51bae9c 199}
20eb8864 200
5cb5f4d0
DD
201static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
202{
203 if (afi == AFI_IP && safi == SAFI_UNICAST)
204 return "IPv4 Unicast";
205 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
206 return "IPv4 Multicast";
207 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
208 return "IPv4 Labeled Unicast";
209 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
210 return "IPv4 VPN";
211 else if (afi == AFI_IP && safi == SAFI_ENCAP)
212 return "IPv4 Encap";
213 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
214 return "IPv4 Flowspec";
215 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
216 return "IPv6 Unicast";
217 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
218 return "IPv6 Multicast";
219 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
220 return "IPv6 Labeled Unicast";
221 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
222 return "IPv6 VPN";
223 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
224 return "IPv6 Encap";
225 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
226 return "IPv6 Flowspec";
227 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
228 return "L2VPN EVPN";
8e5509b0 229 else
5cb5f4d0 230 return "Unknown";
5cb5f4d0
DD
231}
232
233/*
234 * Please note that we have intentionally camelCased
235 * the return strings here. So if you want
236 * to use this function, please ensure you
237 * are doing this within json output
238 */
239static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
240{
241 if (afi == AFI_IP && safi == SAFI_UNICAST)
242 return "ipv4Unicast";
243 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
244 return "ipv4Multicast";
245 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
246 return "ipv4LabeledUnicast";
247 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
248 return "ipv4Vpn";
249 else if (afi == AFI_IP && safi == SAFI_ENCAP)
250 return "ipv4Encap";
251 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
252 return "ipv4Flowspec";
253 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
254 return "ipv6Unicast";
255 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
256 return "ipv6Multicast";
257 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
258 return "ipv6LabeledUnicast";
259 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
260 return "ipv6Vpn";
261 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
262 return "ipv6Encap";
263 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
264 return "ipv6Flowspec";
265 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
266 return "l2VpnEvpn";
8e5509b0 267 else
5cb5f4d0 268 return "Unknown";
5cb5f4d0
DD
269}
270
718e3744 271/* Utility function to get address family from current node. */
d62a17ae 272afi_t bgp_node_afi(struct vty *vty)
273{
274 afi_t afi;
275 switch (vty->node) {
276 case BGP_IPV6_NODE:
277 case BGP_IPV6M_NODE:
278 case BGP_IPV6L_NODE:
279 case BGP_VPNV6_NODE:
7c40bf39 280 case BGP_FLOWSPECV6_NODE:
d62a17ae 281 afi = AFI_IP6;
282 break;
283 case BGP_EVPN_NODE:
284 afi = AFI_L2VPN;
285 break;
286 default:
287 afi = AFI_IP;
288 break;
289 }
290 return afi;
718e3744 291}
292
293/* Utility function to get subsequent address family from current
294 node. */
d62a17ae 295safi_t bgp_node_safi(struct vty *vty)
296{
297 safi_t safi;
298 switch (vty->node) {
299 case BGP_VPNV4_NODE:
300 case BGP_VPNV6_NODE:
301 safi = SAFI_MPLS_VPN;
302 break;
303 case BGP_IPV4M_NODE:
304 case BGP_IPV6M_NODE:
305 safi = SAFI_MULTICAST;
306 break;
307 case BGP_EVPN_NODE:
308 safi = SAFI_EVPN;
309 break;
310 case BGP_IPV4L_NODE:
311 case BGP_IPV6L_NODE:
312 safi = SAFI_LABELED_UNICAST;
313 break;
7c40bf39 314 case BGP_FLOWSPECV4_NODE:
315 case BGP_FLOWSPECV6_NODE:
316 safi = SAFI_FLOWSPEC;
317 break;
d62a17ae 318 default:
319 safi = SAFI_UNICAST;
320 break;
321 }
322 return safi;
718e3744 323}
324
55f91488
QY
325/**
326 * Converts an AFI in string form to afi_t
327 *
328 * @param afi string, one of
329 * - "ipv4"
330 * - "ipv6"
81cf0de5 331 * - "l2vpn"
55f91488
QY
332 * @return the corresponding afi_t
333 */
d62a17ae 334afi_t bgp_vty_afi_from_str(const char *afi_str)
335{
336 afi_t afi = AFI_MAX; /* unknown */
337 if (strmatch(afi_str, "ipv4"))
338 afi = AFI_IP;
339 else if (strmatch(afi_str, "ipv6"))
340 afi = AFI_IP6;
81cf0de5
CS
341 else if (strmatch(afi_str, "l2vpn"))
342 afi = AFI_L2VPN;
d62a17ae 343 return afi;
344}
345
346int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
347 afi_t *afi)
348{
349 int ret = 0;
350 if (argv_find(argv, argc, "ipv4", index)) {
351 ret = 1;
352 if (afi)
353 *afi = AFI_IP;
354 } else if (argv_find(argv, argc, "ipv6", index)) {
355 ret = 1;
356 if (afi)
357 *afi = AFI_IP6;
8688b3e7
DS
358 } else if (argv_find(argv, argc, "l2vpn", index)) {
359 ret = 1;
360 if (afi)
361 *afi = AFI_L2VPN;
d62a17ae 362 }
363 return ret;
46f296b4
LB
364}
365
375a2e67 366/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 367safi_t bgp_vty_safi_from_str(const char *safi_str)
368{
369 safi_t safi = SAFI_MAX; /* unknown */
370 if (strmatch(safi_str, "multicast"))
371 safi = SAFI_MULTICAST;
372 else if (strmatch(safi_str, "unicast"))
373 safi = SAFI_UNICAST;
374 else if (strmatch(safi_str, "vpn"))
375 safi = SAFI_MPLS_VPN;
81cf0de5
CS
376 else if (strmatch(safi_str, "evpn"))
377 safi = SAFI_EVPN;
d62a17ae 378 else if (strmatch(safi_str, "labeled-unicast"))
379 safi = SAFI_LABELED_UNICAST;
7c40bf39 380 else if (strmatch(safi_str, "flowspec"))
381 safi = SAFI_FLOWSPEC;
d62a17ae 382 return safi;
383}
384
385int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
386 safi_t *safi)
387{
388 int ret = 0;
389 if (argv_find(argv, argc, "unicast", index)) {
390 ret = 1;
391 if (safi)
392 *safi = SAFI_UNICAST;
393 } else if (argv_find(argv, argc, "multicast", index)) {
394 ret = 1;
395 if (safi)
396 *safi = SAFI_MULTICAST;
397 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
398 ret = 1;
399 if (safi)
400 *safi = SAFI_LABELED_UNICAST;
401 } else if (argv_find(argv, argc, "vpn", index)) {
402 ret = 1;
403 if (safi)
404 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
405 } else if (argv_find(argv, argc, "evpn", index)) {
406 ret = 1;
407 if (safi)
408 *safi = SAFI_EVPN;
7c40bf39 409 } else if (argv_find(argv, argc, "flowspec", index)) {
410 ret = 1;
411 if (safi)
412 *safi = SAFI_FLOWSPEC;
d62a17ae 413 }
414 return ret;
46f296b4
LB
415}
416
5d5393b9
DL
417int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
418 enum bgp_instance_type inst_type)
419{
420 int ret = bgp_get(bgp, as, name, inst_type);
421
422 if (ret == BGP_CREATED) {
423 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
424 DFLT_BGP_CONNECT_RETRY);
425
426 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 427 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 428 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 429 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
430 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
431 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 432 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 433 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 434 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 435 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
436 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
437 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
5d5393b9
DL
438
439 ret = BGP_SUCCESS;
440 }
441 return ret;
442}
443
7eeee51e 444/*
f212a857 445 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 446 *
f212a857
DS
447 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
448 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
449 * to appropriate values for the calling function. This is to allow the
450 * calling function to make decisions appropriate for the show command
451 * that is being parsed.
452 *
453 * The show commands are generally of the form:
d62a17ae 454 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
455 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
456 *
457 * Since we use argv_find if the show command in particular doesn't have:
458 * [ip]
18c57037 459 * [<view|vrf> VIEWVRFNAME]
375a2e67 460 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
461 * The command parsing should still be ok.
462 *
463 * vty -> The vty for the command so we can output some useful data in
464 * the event of a parse error in the vrf.
465 * argv -> The command tokens
466 * argc -> How many command tokens we have
d62a17ae 467 * idx -> The current place in the command, generally should be 0 for this
468 * function
7eeee51e
DS
469 * afi -> The parsed afi if it was included in the show command, returned here
470 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 471 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 472 * use_json -> json is configured or not
7eeee51e
DS
473 *
474 * The function returns the correct location in the parse tree for the
475 * last token found.
0e37c258
DS
476 *
477 * Returns 0 for failure to parse correctly, else the idx position of where
478 * it found the last token.
7eeee51e 479 */
d62a17ae 480int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
481 struct cmd_token **argv, int argc,
482 int *idx, afi_t *afi, safi_t *safi,
9f049418 483 struct bgp **bgp, bool use_json)
d62a17ae 484{
485 char *vrf_name = NULL;
486
487 assert(afi);
488 assert(safi);
489 assert(bgp);
490
491 if (argv_find(argv, argc, "ip", idx))
492 *afi = AFI_IP;
493
9a8bdf1c 494 if (argv_find(argv, argc, "view", idx))
d62a17ae 495 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
496 else if (argv_find(argv, argc, "vrf", idx)) {
497 vrf_name = argv[*idx + 1]->arg;
498 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
499 vrf_name = NULL;
500 }
501 if (vrf_name) {
d62a17ae 502 if (strmatch(vrf_name, "all"))
503 *bgp = NULL;
504 else {
505 *bgp = bgp_lookup_by_name(vrf_name);
506 if (!*bgp) {
52e5b8c4
SP
507 if (use_json) {
508 json_object *json = NULL;
509 json = json_object_new_object();
510 json_object_string_add(
511 json, "warning",
512 "View/Vrf is unknown");
513 vty_out(vty, "%s\n",
514 json_object_to_json_string_ext(json,
515 JSON_C_TO_STRING_PRETTY));
516 json_object_free(json);
517 }
ca61fd25
DS
518 else
519 vty_out(vty, "View/Vrf %s is unknown\n",
520 vrf_name);
d62a17ae 521 *idx = 0;
522 return 0;
523 }
524 }
525 } else {
526 *bgp = bgp_get_default();
527 if (!*bgp) {
52e5b8c4
SP
528 if (use_json) {
529 json_object *json = NULL;
530 json = json_object_new_object();
531 json_object_string_add(
532 json, "warning",
533 "Default BGP instance not found");
534 vty_out(vty, "%s\n",
535 json_object_to_json_string_ext(json,
536 JSON_C_TO_STRING_PRETTY));
537 json_object_free(json);
538 }
ca61fd25
DS
539 else
540 vty_out(vty,
541 "Default BGP instance not found\n");
d62a17ae 542 *idx = 0;
543 return 0;
544 }
545 }
546
547 if (argv_find_and_parse_afi(argv, argc, idx, afi))
548 argv_find_and_parse_safi(argv, argc, idx, safi);
549
550 *idx += 1;
551 return *idx;
552}
553
3dc339cd 554static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 555{
556 struct interface *ifp = NULL;
557
558 if (su->sa.sa_family == AF_INET)
559 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
560 else if (su->sa.sa_family == AF_INET6)
561 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
562 su->sin6.sin6_scope_id,
563 bgp->vrf_id);
564
565 if (ifp)
3dc339cd 566 return true;
d62a17ae 567
3dc339cd 568 return false;
718e3744 569}
570
571/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
572/* This is used only for configuration, so disallow if attempted on
573 * a dynamic neighbor.
574 */
d62a17ae 575static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
576{
577 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
578 int ret;
579 union sockunion su;
580 struct peer *peer;
581
582 if (!bgp) {
583 return NULL;
584 }
585
586 ret = str2sockunion(ip_str, &su);
587 if (ret < 0) {
588 peer = peer_lookup_by_conf_if(bgp, ip_str);
589 if (!peer) {
590 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
591 == NULL) {
592 vty_out(vty,
593 "%% Malformed address or name: %s\n",
594 ip_str);
595 return NULL;
596 }
597 }
598 } else {
599 peer = peer_lookup(bgp, &su);
600 if (!peer) {
601 vty_out(vty,
602 "%% Specify remote-as or peer-group commands first\n");
603 return NULL;
604 }
605 if (peer_dynamic_neighbor(peer)) {
606 vty_out(vty,
607 "%% Operation not allowed on a dynamic neighbor\n");
608 return NULL;
609 }
610 }
611 return peer;
718e3744 612}
613
614/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
615/* This is used only for configuration, so disallow if attempted on
616 * a dynamic neighbor.
617 */
d62a17ae 618struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
619{
620 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
621 int ret;
622 union sockunion su;
623 struct peer *peer = NULL;
624 struct peer_group *group = NULL;
625
626 if (!bgp) {
627 return NULL;
628 }
629
630 ret = str2sockunion(peer_str, &su);
631 if (ret == 0) {
632 /* IP address, locate peer. */
633 peer = peer_lookup(bgp, &su);
634 } else {
635 /* Not IP, could match either peer configured on interface or a
636 * group. */
637 peer = peer_lookup_by_conf_if(bgp, peer_str);
638 if (!peer)
639 group = peer_group_lookup(bgp, peer_str);
640 }
641
642 if (peer) {
643 if (peer_dynamic_neighbor(peer)) {
644 vty_out(vty,
645 "%% Operation not allowed on a dynamic neighbor\n");
646 return NULL;
647 }
648
649 return peer;
650 }
651
652 if (group)
653 return group->conf;
654
655 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
656
657 return NULL;
658}
659
660int bgp_vty_return(struct vty *vty, int ret)
661{
662 const char *str = NULL;
663
664 switch (ret) {
665 case BGP_ERR_INVALID_VALUE:
666 str = "Invalid value";
667 break;
668 case BGP_ERR_INVALID_FLAG:
669 str = "Invalid flag";
670 break;
671 case BGP_ERR_PEER_GROUP_SHUTDOWN:
672 str = "Peer-group has been shutdown. Activate the peer-group first";
673 break;
674 case BGP_ERR_PEER_FLAG_CONFLICT:
675 str = "Can't set override-capability and strict-capability-match at the same time";
676 break;
677 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
678 str = "Specify remote-as or peer-group remote AS first";
679 break;
680 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
681 str = "Cannot change the peer-group. Deconfigure first";
682 break;
683 case BGP_ERR_PEER_GROUP_MISMATCH:
684 str = "Peer is not a member of this peer-group";
685 break;
686 case BGP_ERR_PEER_FILTER_CONFLICT:
687 str = "Prefix/distribute list can not co-exist";
688 break;
689 case BGP_ERR_NOT_INTERNAL_PEER:
690 str = "Invalid command. Not an internal neighbor";
691 break;
692 case BGP_ERR_REMOVE_PRIVATE_AS:
693 str = "remove-private-AS cannot be configured for IBGP peers";
694 break;
695 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
696 str = "Local-AS allowed only for EBGP peers";
697 break;
698 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
699 str = "Cannot have local-as same as BGP AS number";
700 break;
701 case BGP_ERR_TCPSIG_FAILED:
702 str = "Error while applying TCP-Sig to session(s)";
703 break;
704 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
705 str = "ebgp-multihop and ttl-security cannot be configured together";
706 break;
707 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
708 str = "ttl-security only allowed for EBGP peers";
709 break;
710 case BGP_ERR_AS_OVERRIDE:
711 str = "as-override cannot be configured for IBGP peers";
712 break;
713 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
714 str = "Invalid limit for number of dynamic neighbors";
715 break;
716 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
717 str = "Dynamic neighbor listen range already exists";
718 break;
719 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
720 str = "Operation not allowed on a dynamic neighbor";
721 break;
722 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
723 str = "Operation not allowed on a directly connected neighbor";
724 break;
725 case BGP_ERR_PEER_SAFI_CONFLICT:
055679e9 726 str = GR_INVALID;
727 break;
728 case BGP_ERR_GR_INVALID_CMD:
729 str = "The Graceful Restart command used is not valid at this moment.";
730 break;
731 case BGP_ERR_GR_OPERATION_FAILED:
732 str = "The Graceful Restart Operation failed due to an err.";
733 break;
734 case BGP_GR_NO_OPERATION:
735 str = GR_NO_OPER;
d62a17ae 736 break;
737 }
738 if (str) {
739 vty_out(vty, "%% %s\n", str);
740 return CMD_WARNING_CONFIG_FAILED;
741 }
742 return CMD_SUCCESS;
718e3744 743}
744
7aafcaca 745/* BGP clear sort. */
d62a17ae 746enum clear_sort {
747 clear_all,
748 clear_peer,
749 clear_group,
750 clear_external,
751 clear_as
7aafcaca
DS
752};
753
d62a17ae 754static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
755 safi_t safi, int error)
756{
757 switch (error) {
758 case BGP_ERR_AF_UNCONFIGURED:
759 vty_out(vty,
760 "%%BGP: Enable %s address family for the neighbor %s\n",
5cb5f4d0 761 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 762 break;
763 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
764 vty_out(vty,
765 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
766 peer->host);
767 break;
768 default:
769 break;
770 }
7aafcaca
DS
771}
772
dc912615 773static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 774 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
775{
776 int ret = 0;
777
778 /* if afi/.safi not specified, spin thru all of them */
779 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
780 afi_t tmp_afi;
781 safi_t tmp_safi;
782
783 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
784 if (!peer->afc[tmp_afi][tmp_safi])
785 continue;
786
787 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 788 ret = peer_clear(peer, nnode);
dc912615
DS
789 else
790 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
791 stype);
792 }
793 /* if afi specified and safi not, spin thru safis on this afi */
794 } else if (safi == SAFI_UNSPEC) {
795 safi_t tmp_safi;
796
797 for (tmp_safi = SAFI_UNICAST;
798 tmp_safi < SAFI_MAX; tmp_safi++) {
799 if (!peer->afc[afi][tmp_safi])
800 continue;
801
802 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 803 ret = peer_clear(peer, nnode);
dc912615
DS
804 else
805 ret = peer_clear_soft(peer, afi,
806 tmp_safi, stype);
807 }
808 /* both afi/safi specified, let the caller know if not defined */
809 } else {
810 if (!peer->afc[afi][safi])
811 return 1;
812
813 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 814 ret = peer_clear(peer, nnode);
dc912615
DS
815 else
816 ret = peer_clear_soft(peer, afi, safi, stype);
817 }
818
819 return ret;
820}
821
7aafcaca 822/* `clear ip bgp' functions. */
d62a17ae 823static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
824 enum clear_sort sort, enum bgp_clear_type stype,
825 const char *arg)
826{
dc912615 827 int ret = 0;
3ae8bfa5 828 bool found = false;
d62a17ae 829 struct peer *peer;
dc95985f 830
831 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 832
833 /* Clear all neighbors. */
834 /*
835 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
836 * nodes on the BGP instance as that may get freed if it is a
837 * doppelganger
d62a17ae 838 */
839 if (sort == clear_all) {
840 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 841
842 bgp_peer_gr_flags_update(peer);
843
36235319 844 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 845 gr_router_detected = true;
846
c368171c 847 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 848 stype);
d62a17ae 849
850 if (ret < 0)
851 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 852 }
853
36235319
QY
854 if (gr_router_detected
855 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 856 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
857 } else if (!gr_router_detected
858 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 859 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 860 }
d62a17ae 861
862 /* This is to apply read-only mode on this clear. */
863 if (stype == BGP_CLEAR_SOFT_NONE)
864 bgp->update_delay_over = 0;
865
866 return CMD_SUCCESS;
7aafcaca
DS
867 }
868
3ae8bfa5 869 /* Clear specified neighbor. */
d62a17ae 870 if (sort == clear_peer) {
871 union sockunion su;
d62a17ae 872
873 /* Make sockunion for lookup. */
874 ret = str2sockunion(arg, &su);
875 if (ret < 0) {
876 peer = peer_lookup_by_conf_if(bgp, arg);
877 if (!peer) {
878 peer = peer_lookup_by_hostname(bgp, arg);
879 if (!peer) {
880 vty_out(vty,
881 "Malformed address or name: %s\n",
882 arg);
883 return CMD_WARNING;
884 }
885 }
886 } else {
887 peer = peer_lookup(bgp, &su);
888 if (!peer) {
889 vty_out(vty,
890 "%%BGP: Unknown neighbor - \"%s\"\n",
891 arg);
892 return CMD_WARNING;
893 }
894 }
7aafcaca 895
dc95985f 896 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
897 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
898
dc912615
DS
899 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
900
901 /* if afi/safi not defined for this peer, let caller know */
902 if (ret == 1)
3ae8bfa5 903 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 904
d62a17ae 905 if (ret < 0)
906 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 907
d62a17ae 908 return CMD_SUCCESS;
7aafcaca 909 }
7aafcaca 910
3ae8bfa5 911 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 912 if (sort == clear_group) {
913 struct peer_group *group;
7aafcaca 914
d62a17ae 915 group = peer_group_lookup(bgp, arg);
916 if (!group) {
917 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
918 return CMD_WARNING;
919 }
920
921 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 922 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 923
d62a17ae 924 if (ret < 0)
925 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
926 else
927 found = true;
d62a17ae 928 }
3ae8bfa5
PM
929
930 if (!found)
931 vty_out(vty,
932 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 933 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 934
d62a17ae 935 return CMD_SUCCESS;
7aafcaca 936 }
7aafcaca 937
3ae8bfa5 938 /* Clear all external (eBGP) neighbors. */
d62a17ae 939 if (sort == clear_external) {
940 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
941 if (peer->sort == BGP_PEER_IBGP)
942 continue;
7aafcaca 943
dc95985f 944 bgp_peer_gr_flags_update(peer);
945
36235319 946 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 947 gr_router_detected = true;
dc95985f 948
c368171c 949 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 950
d62a17ae 951 if (ret < 0)
952 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
953 else
954 found = true;
d62a17ae 955 }
3ae8bfa5 956
36235319
QY
957 if (gr_router_detected
958 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 959 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
960 } else if (!gr_router_detected
961 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 962 bgp_zebra_send_capabilities(bgp, true);
963 }
964
3ae8bfa5
PM
965 if (!found)
966 vty_out(vty,
967 "%%BGP: No external %s peer is configured\n",
5cb5f4d0 968 get_afi_safi_str(afi, safi, false));
3ae8bfa5 969
d62a17ae 970 return CMD_SUCCESS;
971 }
972
3ae8bfa5 973 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 974 if (sort == clear_as) {
3ae8bfa5 975 as_t as = strtoul(arg, NULL, 10);
d62a17ae 976
977 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
978 if (peer->as != as)
979 continue;
980
dc95985f 981 bgp_peer_gr_flags_update(peer);
982
36235319 983 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 984 gr_router_detected = true;
dc95985f 985
c368171c 986 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 987
988 if (ret < 0)
989 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
990 else
991 found = true;
d62a17ae 992 }
3ae8bfa5 993
36235319
QY
994 if (gr_router_detected
995 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 996 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
997 } else if (!gr_router_detected
998 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 999 bgp_zebra_send_capabilities(bgp, true);
1000 }
1001
3ae8bfa5 1002 if (!found)
d62a17ae 1003 vty_out(vty,
3ae8bfa5 1004 "%%BGP: No %s peer is configured with AS %s\n",
5cb5f4d0 1005 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1006
d62a17ae 1007 return CMD_SUCCESS;
1008 }
1009
1010 return CMD_SUCCESS;
1011}
1012
1013static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1014 safi_t safi, enum clear_sort sort,
1015 enum bgp_clear_type stype, const char *arg)
1016{
1017 struct bgp *bgp;
1018
1019 /* BGP structure lookup. */
1020 if (name) {
1021 bgp = bgp_lookup_by_name(name);
1022 if (bgp == NULL) {
1023 vty_out(vty, "Can't find BGP instance %s\n", name);
1024 return CMD_WARNING;
1025 }
1026 } else {
1027 bgp = bgp_get_default();
1028 if (bgp == NULL) {
1029 vty_out(vty, "No BGP process is configured\n");
1030 return CMD_WARNING;
1031 }
1032 }
1033
1034 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1035}
1036
1037/* clear soft inbound */
d62a17ae 1038static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1039{
99b3ebd3
NS
1040 afi_t afi;
1041 safi_t safi;
1042
1043 FOREACH_AFI_SAFI (afi, safi)
1044 bgp_clear_vty(vty, name, afi, safi, clear_all,
1045 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1046}
1047
1048/* clear soft outbound */
d62a17ae 1049static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1050{
99b3ebd3
NS
1051 afi_t afi;
1052 safi_t safi;
1053
1054 FOREACH_AFI_SAFI (afi, safi)
1055 bgp_clear_vty(vty, name, afi, safi, clear_all,
1056 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1057}
1058
1059
f787d7a0 1060#ifndef VTYSH_EXTRACT_PL
2e4c2296 1061#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1062#endif
1063
8029b216
AK
1064DEFUN_HIDDEN (bgp_local_mac,
1065 bgp_local_mac_cmd,
093e3f23 1066 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1067 BGP_STR
1068 "Local MAC config\n"
1069 "VxLAN Network Identifier\n"
1070 "VNI number\n"
1071 "local mac\n"
1072 "mac address\n"
1073 "mac-mobility sequence\n"
1074 "seq number\n")
1075{
1076 int rv;
1077 vni_t vni;
1078 struct ethaddr mac;
1079 struct ipaddr ip;
1080 uint32_t seq;
1081 struct bgp *bgp;
1082
1083 vni = strtoul(argv[3]->arg, NULL, 10);
1084 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1085 vty_out(vty, "%% Malformed MAC address\n");
1086 return CMD_WARNING;
1087 }
1088 memset(&ip, 0, sizeof(ip));
1089 seq = strtoul(argv[7]->arg, NULL, 10);
1090
1091 bgp = bgp_get_default();
1092 if (!bgp) {
1093 vty_out(vty, "Default BGP instance is not there\n");
1094 return CMD_WARNING;
1095 }
1096
b5e140c8
AK
1097 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1098 zero_esi);
8029b216
AK
1099 if (rv < 0) {
1100 vty_out(vty, "Internal error\n");
1101 return CMD_WARNING;
1102 }
1103
1104 return CMD_SUCCESS;
1105}
1106
1107DEFUN_HIDDEN (no_bgp_local_mac,
1108 no_bgp_local_mac_cmd,
093e3f23 1109 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1110 NO_STR
1111 BGP_STR
1112 "Local MAC config\n"
1113 "VxLAN Network Identifier\n"
1114 "VNI number\n"
1115 "local mac\n"
1116 "mac address\n")
1117{
1118 int rv;
1119 vni_t vni;
1120 struct ethaddr mac;
1121 struct ipaddr ip;
1122 struct bgp *bgp;
1123
1124 vni = strtoul(argv[4]->arg, NULL, 10);
1125 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1126 vty_out(vty, "%% Malformed MAC address\n");
1127 return CMD_WARNING;
1128 }
1129 memset(&ip, 0, sizeof(ip));
1130
1131 bgp = bgp_get_default();
1132 if (!bgp) {
1133 vty_out(vty, "Default BGP instance is not there\n");
1134 return CMD_WARNING;
1135 }
1136
ec0ab544 1137 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1138 if (rv < 0) {
1139 vty_out(vty, "Internal error\n");
1140 return CMD_WARNING;
1141 }
1142
1143 return CMD_SUCCESS;
1144}
1145
718e3744 1146DEFUN (no_synchronization,
1147 no_synchronization_cmd,
1148 "no synchronization",
1149 NO_STR
1150 "Perform IGP synchronization\n")
1151{
d62a17ae 1152 return CMD_SUCCESS;
718e3744 1153}
1154
1155DEFUN (no_auto_summary,
1156 no_auto_summary_cmd,
1157 "no auto-summary",
1158 NO_STR
1159 "Enable automatic network number summarization\n")
1160{
d62a17ae 1161 return CMD_SUCCESS;
718e3744 1162}
3d515fd9 1163
718e3744 1164/* "router bgp" commands. */
505e5056 1165DEFUN_NOSH (router_bgp,
f412b39a 1166 router_bgp_cmd,
2ed9fe4a 1167 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1168 ROUTER_STR
1169 BGP_STR
31500417
DW
1170 AS_STR
1171 BGP_INSTANCE_HELP_STR)
718e3744 1172{
d62a17ae 1173 int idx_asn = 2;
1174 int idx_view_vrf = 3;
1175 int idx_vrf = 4;
ecec9495 1176 int is_new_bgp = 0;
d62a17ae 1177 int ret;
1178 as_t as;
1179 struct bgp *bgp;
1180 const char *name = NULL;
1181 enum bgp_instance_type inst_type;
1182
1183 // "router bgp" without an ASN
1184 if (argc == 2) {
1185 // Pending: Make VRF option available for ASN less config
1186 bgp = bgp_get_default();
1187
1188 if (bgp == NULL) {
1189 vty_out(vty, "%% No BGP process is configured\n");
1190 return CMD_WARNING_CONFIG_FAILED;
1191 }
1192
1193 if (listcount(bm->bgp) > 1) {
996c9314 1194 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1195 return CMD_WARNING_CONFIG_FAILED;
1196 }
1197 }
1198
1199 // "router bgp X"
1200 else {
1201 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1202
1203 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1204 if (argc > 3) {
1205 name = argv[idx_vrf]->arg;
1206
9a8bdf1c
PG
1207 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1208 if (strmatch(name, VRF_DEFAULT_NAME))
1209 name = NULL;
1210 else
1211 inst_type = BGP_INSTANCE_TYPE_VRF;
1212 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1213 inst_type = BGP_INSTANCE_TYPE_VIEW;
1214 }
1215
ecec9495
AD
1216 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1217 is_new_bgp = (bgp_lookup(as, name) == NULL);
1218
5d5393b9 1219 ret = bgp_get_vty(&bgp, &as, name, inst_type);
d62a17ae 1220 switch (ret) {
d62a17ae 1221 case BGP_ERR_AS_MISMATCH:
1222 vty_out(vty, "BGP is already running; AS is %u\n", as);
1223 return CMD_WARNING_CONFIG_FAILED;
1224 case BGP_ERR_INSTANCE_MISMATCH:
1225 vty_out(vty,
1226 "BGP instance name and AS number mismatch\n");
1227 vty_out(vty,
1228 "BGP instance is already running; AS is %u\n",
1229 as);
1230 return CMD_WARNING_CONFIG_FAILED;
1231 }
1232
3bd70bf8
PZ
1233 /*
1234 * If we just instantiated the default instance, complete
1235 * any pending VRF-VPN leaking that was configured via
1236 * earlier "router bgp X vrf FOO" blocks.
1237 */
ecec9495 1238 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1239 vpn_leak_postchange_all();
1240
48381346
CS
1241 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1242 bgp_vpn_leak_export(bgp);
d62a17ae 1243 /* Pending: handle when user tries to change a view to vrf n vv.
1244 */
1245 }
1246
0b5131c9
MK
1247 /* unset the auto created flag as the user config is now present */
1248 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1249 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1250
1251 return CMD_SUCCESS;
718e3744 1252}
1253
718e3744 1254/* "no router bgp" commands. */
1255DEFUN (no_router_bgp,
1256 no_router_bgp_cmd,
2ed9fe4a 1257 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1258 NO_STR
1259 ROUTER_STR
1260 BGP_STR
31500417
DW
1261 AS_STR
1262 BGP_INSTANCE_HELP_STR)
718e3744 1263{
d62a17ae 1264 int idx_asn = 3;
1265 int idx_vrf = 5;
1266 as_t as;
1267 struct bgp *bgp;
1268 const char *name = NULL;
718e3744 1269
d62a17ae 1270 // "no router bgp" without an ASN
1271 if (argc == 3) {
1272 // Pending: Make VRF option available for ASN less config
1273 bgp = bgp_get_default();
718e3744 1274
d62a17ae 1275 if (bgp == NULL) {
1276 vty_out(vty, "%% No BGP process is configured\n");
1277 return CMD_WARNING_CONFIG_FAILED;
1278 }
7fb21a9f 1279
d62a17ae 1280 if (listcount(bm->bgp) > 1) {
996c9314 1281 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1282 return CMD_WARNING_CONFIG_FAILED;
1283 }
0b5131c9
MK
1284
1285 if (bgp->l3vni) {
1286 vty_out(vty, "%% Please unconfigure l3vni %u",
1287 bgp->l3vni);
1288 return CMD_WARNING_CONFIG_FAILED;
1289 }
d62a17ae 1290 } else {
1291 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1292
d62a17ae 1293 if (argc > 4)
1294 name = argv[idx_vrf]->arg;
7fb21a9f 1295
d62a17ae 1296 /* Lookup bgp structure. */
1297 bgp = bgp_lookup(as, name);
1298 if (!bgp) {
1299 vty_out(vty, "%% Can't find BGP instance\n");
1300 return CMD_WARNING_CONFIG_FAILED;
1301 }
0b5131c9
MK
1302
1303 if (bgp->l3vni) {
dd5868c2 1304 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1305 bgp->l3vni);
1306 return CMD_WARNING_CONFIG_FAILED;
1307 }
dd5868c2
DS
1308
1309 /* Cannot delete default instance if vrf instances exist */
1310 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1311 struct listnode *node;
1312 struct bgp *tmp_bgp;
1313
1314 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1315 if (tmp_bgp->inst_type
1316 == BGP_INSTANCE_TYPE_VRF) {
1317 vty_out(vty,
1318 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1319 return CMD_WARNING_CONFIG_FAILED;
1320 }
1321 }
1322 }
d62a17ae 1323 }
718e3744 1324
9ecf931b
CS
1325 if (bgp_vpn_leak_unimport(bgp, vty))
1326 return CMD_WARNING_CONFIG_FAILED;
1327
d62a17ae 1328 bgp_delete(bgp);
718e3744 1329
d62a17ae 1330 return CMD_SUCCESS;
718e3744 1331}
1332
6b0655a2 1333
718e3744 1334/* BGP router-id. */
1335
f787d7a0 1336DEFPY (bgp_router_id,
718e3744 1337 bgp_router_id_cmd,
1338 "bgp router-id A.B.C.D",
1339 BGP_STR
1340 "Override configured router identifier\n"
1341 "Manually configured router identifier\n")
1342{
d62a17ae 1343 VTY_DECLVAR_CONTEXT(bgp, bgp);
1344 bgp_router_id_static_set(bgp, router_id);
1345 return CMD_SUCCESS;
718e3744 1346}
1347
f787d7a0 1348DEFPY (no_bgp_router_id,
718e3744 1349 no_bgp_router_id_cmd,
31500417 1350 "no bgp router-id [A.B.C.D]",
718e3744 1351 NO_STR
1352 BGP_STR
31500417
DW
1353 "Override configured router identifier\n"
1354 "Manually configured router identifier\n")
718e3744 1355{
d62a17ae 1356 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1357
d62a17ae 1358 if (router_id_str) {
1359 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1360 vty_out(vty, "%% BGP router-id doesn't match\n");
1361 return CMD_WARNING_CONFIG_FAILED;
1362 }
e018c7cc 1363 }
718e3744 1364
d62a17ae 1365 router_id.s_addr = 0;
1366 bgp_router_id_static_set(bgp, router_id);
718e3744 1367
d62a17ae 1368 return CMD_SUCCESS;
718e3744 1369}
1370
6b0655a2 1371
718e3744 1372/* BGP Cluster ID. */
718e3744 1373DEFUN (bgp_cluster_id,
1374 bgp_cluster_id_cmd,
838758ac 1375 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1376 BGP_STR
1377 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1378 "Route-Reflector Cluster-id in IP address format\n"
1379 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1380{
d62a17ae 1381 VTY_DECLVAR_CONTEXT(bgp, bgp);
1382 int idx_ipv4 = 2;
1383 int ret;
1384 struct in_addr cluster;
718e3744 1385
d62a17ae 1386 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1387 if (!ret) {
1388 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1389 return CMD_WARNING_CONFIG_FAILED;
1390 }
718e3744 1391
d62a17ae 1392 bgp_cluster_id_set(bgp, &cluster);
1393 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1394
d62a17ae 1395 return CMD_SUCCESS;
718e3744 1396}
1397
718e3744 1398DEFUN (no_bgp_cluster_id,
1399 no_bgp_cluster_id_cmd,
c7178fe7 1400 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1401 NO_STR
1402 BGP_STR
838758ac
DW
1403 "Configure Route-Reflector Cluster-id\n"
1404 "Route-Reflector Cluster-id in IP address format\n"
1405 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1406{
d62a17ae 1407 VTY_DECLVAR_CONTEXT(bgp, bgp);
1408 bgp_cluster_id_unset(bgp);
1409 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1410
d62a17ae 1411 return CMD_SUCCESS;
718e3744 1412}
1413
718e3744 1414DEFUN (bgp_confederation_identifier,
1415 bgp_confederation_identifier_cmd,
9ccf14f7 1416 "bgp confederation identifier (1-4294967295)",
718e3744 1417 "BGP specific commands\n"
1418 "AS confederation parameters\n"
1419 "AS number\n"
1420 "Set routing domain confederation AS\n")
1421{
d62a17ae 1422 VTY_DECLVAR_CONTEXT(bgp, bgp);
1423 int idx_number = 3;
1424 as_t as;
718e3744 1425
d62a17ae 1426 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1427
d62a17ae 1428 bgp_confederation_id_set(bgp, as);
718e3744 1429
d62a17ae 1430 return CMD_SUCCESS;
718e3744 1431}
1432
1433DEFUN (no_bgp_confederation_identifier,
1434 no_bgp_confederation_identifier_cmd,
838758ac 1435 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1436 NO_STR
1437 "BGP specific commands\n"
1438 "AS confederation parameters\n"
3a2d747c
QY
1439 "AS number\n"
1440 "Set routing domain confederation AS\n")
718e3744 1441{
d62a17ae 1442 VTY_DECLVAR_CONTEXT(bgp, bgp);
1443 bgp_confederation_id_unset(bgp);
718e3744 1444
d62a17ae 1445 return CMD_SUCCESS;
718e3744 1446}
1447
718e3744 1448DEFUN (bgp_confederation_peers,
1449 bgp_confederation_peers_cmd,
12dcf78e 1450 "bgp confederation peers (1-4294967295)...",
718e3744 1451 "BGP specific commands\n"
1452 "AS confederation parameters\n"
1453 "Peer ASs in BGP confederation\n"
1454 AS_STR)
1455{
d62a17ae 1456 VTY_DECLVAR_CONTEXT(bgp, bgp);
1457 int idx_asn = 3;
1458 as_t as;
1459 int i;
718e3744 1460
d62a17ae 1461 for (i = idx_asn; i < argc; i++) {
1462 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1463
d62a17ae 1464 if (bgp->as == as) {
1465 vty_out(vty,
1466 "%% Local member-AS not allowed in confed peer list\n");
1467 continue;
1468 }
718e3744 1469
d62a17ae 1470 bgp_confederation_peers_add(bgp, as);
1471 }
1472 return CMD_SUCCESS;
718e3744 1473}
1474
1475DEFUN (no_bgp_confederation_peers,
1476 no_bgp_confederation_peers_cmd,
e83a9414 1477 "no bgp confederation peers (1-4294967295)...",
718e3744 1478 NO_STR
1479 "BGP specific commands\n"
1480 "AS confederation parameters\n"
1481 "Peer ASs in BGP confederation\n"
1482 AS_STR)
1483{
d62a17ae 1484 VTY_DECLVAR_CONTEXT(bgp, bgp);
1485 int idx_asn = 4;
1486 as_t as;
1487 int i;
718e3744 1488
d62a17ae 1489 for (i = idx_asn; i < argc; i++) {
1490 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1491
d62a17ae 1492 bgp_confederation_peers_remove(bgp, as);
1493 }
1494 return CMD_SUCCESS;
718e3744 1495}
6b0655a2 1496
5e242b0d
DS
1497/**
1498 * Central routine for maximum-paths configuration.
1499 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1500 * @set: 1 for setting values, 0 for removing the max-paths config.
1501 */
d62a17ae 1502static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1503 const char *mpaths, uint16_t options,
d62a17ae 1504 int set)
1505{
1506 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1507 uint16_t maxpaths = 0;
d62a17ae 1508 int ret;
1509 afi_t afi;
1510 safi_t safi;
1511
1512 afi = bgp_node_afi(vty);
1513 safi = bgp_node_safi(vty);
1514
1515 if (set) {
1516 maxpaths = strtol(mpaths, NULL, 10);
1517 if (maxpaths > multipath_num) {
1518 vty_out(vty,
1519 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1520 maxpaths, multipath_num);
1521 return CMD_WARNING_CONFIG_FAILED;
1522 }
1523 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1524 options);
1525 } else
1526 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1527
1528 if (ret < 0) {
1529 vty_out(vty,
1530 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1531 (set == 1) ? "" : "un",
1532 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1533 maxpaths, afi, safi);
1534 return CMD_WARNING_CONFIG_FAILED;
1535 }
1536
1537 bgp_recalculate_all_bestpaths(bgp);
1538
1539 return CMD_SUCCESS;
165b5fff
JB
1540}
1541
abc920f8
DS
1542DEFUN (bgp_maxmed_admin,
1543 bgp_maxmed_admin_cmd,
1544 "bgp max-med administrative ",
1545 BGP_STR
1546 "Advertise routes with max-med\n"
1547 "Administratively applied, for an indefinite period\n")
1548{
d62a17ae 1549 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1550
d62a17ae 1551 bgp->v_maxmed_admin = 1;
1552 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1553
d62a17ae 1554 bgp_maxmed_update(bgp);
abc920f8 1555
d62a17ae 1556 return CMD_SUCCESS;
abc920f8
DS
1557}
1558
1559DEFUN (bgp_maxmed_admin_medv,
1560 bgp_maxmed_admin_medv_cmd,
4668a151 1561 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1562 BGP_STR
1563 "Advertise routes with max-med\n"
1564 "Administratively applied, for an indefinite period\n"
1565 "Max MED value to be used\n")
1566{
d62a17ae 1567 VTY_DECLVAR_CONTEXT(bgp, bgp);
1568 int idx_number = 3;
abc920f8 1569
d62a17ae 1570 bgp->v_maxmed_admin = 1;
1571 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1572
d62a17ae 1573 bgp_maxmed_update(bgp);
abc920f8 1574
d62a17ae 1575 return CMD_SUCCESS;
abc920f8
DS
1576}
1577
1578DEFUN (no_bgp_maxmed_admin,
1579 no_bgp_maxmed_admin_cmd,
4668a151 1580 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1581 NO_STR
1582 BGP_STR
1583 "Advertise routes with max-med\n"
838758ac
DW
1584 "Administratively applied, for an indefinite period\n"
1585 "Max MED value to be used\n")
abc920f8 1586{
d62a17ae 1587 VTY_DECLVAR_CONTEXT(bgp, bgp);
1588 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1589 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1590 bgp_maxmed_update(bgp);
abc920f8 1591
d62a17ae 1592 return CMD_SUCCESS;
abc920f8
DS
1593}
1594
abc920f8
DS
1595DEFUN (bgp_maxmed_onstartup,
1596 bgp_maxmed_onstartup_cmd,
4668a151 1597 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1598 BGP_STR
1599 "Advertise routes with max-med\n"
1600 "Effective on a startup\n"
1601 "Time (seconds) period for max-med\n"
1602 "Max MED value to be used\n")
1603{
d62a17ae 1604 VTY_DECLVAR_CONTEXT(bgp, bgp);
1605 int idx = 0;
4668a151 1606
d62a17ae 1607 argv_find(argv, argc, "(5-86400)", &idx);
1608 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1609 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1610 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1611 else
1612 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1613
d62a17ae 1614 bgp_maxmed_update(bgp);
abc920f8 1615
d62a17ae 1616 return CMD_SUCCESS;
abc920f8
DS
1617}
1618
1619DEFUN (no_bgp_maxmed_onstartup,
1620 no_bgp_maxmed_onstartup_cmd,
4668a151 1621 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1622 NO_STR
1623 BGP_STR
1624 "Advertise routes with max-med\n"
838758ac
DW
1625 "Effective on a startup\n"
1626 "Time (seconds) period for max-med\n"
1627 "Max MED value to be used\n")
abc920f8 1628{
d62a17ae 1629 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1630
d62a17ae 1631 /* Cancel max-med onstartup if its on */
1632 if (bgp->t_maxmed_onstartup) {
1633 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1634 bgp->maxmed_onstartup_over = 1;
1635 }
abc920f8 1636
d62a17ae 1637 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1638 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1639
d62a17ae 1640 bgp_maxmed_update(bgp);
abc920f8 1641
d62a17ae 1642 return CMD_SUCCESS;
abc920f8
DS
1643}
1644
d70583f7
D
1645static int bgp_global_update_delay_config_vty(struct vty *vty,
1646 uint16_t update_delay,
1647 uint16_t establish_wait)
1648{
1649 struct listnode *node, *nnode;
1650 struct bgp *bgp;
1651 bool vrf_cfg = false;
1652
1653 /*
1654 * See if update-delay is set per-vrf and warn user to delete it
1655 * Note that we only need to check this if this is the first time
1656 * setting the global config.
1657 */
1658 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1659 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1660 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1661 vty_out(vty,
1662 "%% update-delay configuration found in vrf %s\n",
1663 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1664 ? VRF_DEFAULT_NAME
1665 : bgp->name);
1666 vrf_cfg = true;
1667 }
1668 }
1669 }
1670
1671 if (vrf_cfg) {
1672 vty_out(vty,
1673 "%%Failed: global update-delay config not permitted\n");
1674 return CMD_WARNING;
1675 }
1676
1677 if (!establish_wait) { /* update-delay <delay> */
1678 bm->v_update_delay = update_delay;
1679 bm->v_establish_wait = bm->v_update_delay;
1680 } else {
1681 /* update-delay <delay> <establish-wait> */
1682 if (update_delay < establish_wait) {
1683 vty_out(vty,
1684 "%%Failed: update-delay less than the establish-wait!\n");
1685 return CMD_WARNING_CONFIG_FAILED;
1686 }
1687
1688 bm->v_update_delay = update_delay;
1689 bm->v_establish_wait = establish_wait;
1690 }
1691
1692 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1693 bgp->v_update_delay = bm->v_update_delay;
1694 bgp->v_establish_wait = bm->v_establish_wait;
1695 }
1696
1697 return CMD_SUCCESS;
1698}
1699
1700static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1701{
1702 struct listnode *node, *nnode;
1703 struct bgp *bgp;
1704
1705 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1706 bm->v_establish_wait = bm->v_update_delay;
1707
1708 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1709 bgp->v_update_delay = bm->v_update_delay;
1710 bgp->v_establish_wait = bm->v_establish_wait;
1711 }
1712
1713 return CMD_SUCCESS;
1714}
1715
1716static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1717 uint16_t establish_wait)
f188f2c4 1718{
d62a17ae 1719 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1720
d70583f7
D
1721 /* if configured globally, per-instance config is not allowed */
1722 if (bm->v_update_delay) {
1723 vty_out(vty,
1724 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1725 return CMD_WARNING_CONFIG_FAILED;
1726 }
1727
f188f2c4 1728
d70583f7 1729 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1730 {
1731 bgp->v_update_delay = update_delay;
1732 bgp->v_establish_wait = bgp->v_update_delay;
1733 return CMD_SUCCESS;
1734 }
f188f2c4 1735
d62a17ae 1736 /* update-delay <delay> <establish-wait> */
d62a17ae 1737 if (update_delay < establish_wait) {
1738 vty_out(vty,
1739 "%%Failed: update-delay less than the establish-wait!\n");
1740 return CMD_WARNING_CONFIG_FAILED;
1741 }
f188f2c4 1742
d62a17ae 1743 bgp->v_update_delay = update_delay;
1744 bgp->v_establish_wait = establish_wait;
f188f2c4 1745
d62a17ae 1746 return CMD_SUCCESS;
f188f2c4
DS
1747}
1748
d62a17ae 1749static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1750{
d62a17ae 1751 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1752
d70583f7
D
1753 /* If configured globally, cannot remove from one bgp instance */
1754 if (bm->v_update_delay) {
1755 vty_out(vty,
1756 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
1757 return CMD_WARNING_CONFIG_FAILED;
1758 }
d62a17ae 1759 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1760 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1761
d62a17ae 1762 return CMD_SUCCESS;
f188f2c4
DS
1763}
1764
2b791107 1765void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1766{
d70583f7
D
1767 /* If configured globally, no need to display per-instance value */
1768 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 1769 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1770 if (bgp->v_update_delay != bgp->v_establish_wait)
1771 vty_out(vty, " %d", bgp->v_establish_wait);
1772 vty_out(vty, "\n");
1773 }
f188f2c4
DS
1774}
1775
d70583f7
D
1776/* Global update-delay configuration */
1777DEFPY (bgp_global_update_delay,
1778 bgp_global_update_delay_cmd,
1779 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
1780 BGP_STR
1781 "Force initial delay for best-path and updates for all bgp instances\n"
1782 "Max delay in seconds\n"
1783 "Establish wait in seconds\n")
1784{
1785 return bgp_global_update_delay_config_vty(vty, delay, wait);
1786}
f188f2c4 1787
d70583f7
D
1788/* Global update-delay deconfiguration */
1789DEFPY (no_bgp_global_update_delay,
1790 no_bgp_global_update_delay_cmd,
1791 "no bgp update-delay [(0-3600) [(1-3600)]]",
1792 NO_STR
1793 BGP_STR
f188f2c4 1794 "Force initial delay for best-path and updates\n"
d70583f7
D
1795 "Max delay in seconds\n"
1796 "Establish wait in seconds\n")
f188f2c4 1797{
d70583f7 1798 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
1799}
1800
d70583f7
D
1801/* Update-delay configuration */
1802
1803DEFPY (bgp_update_delay,
1804 bgp_update_delay_cmd,
1805 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 1806 "Force initial delay for best-path and updates\n"
d70583f7
D
1807 "Max delay in seconds\n"
1808 "Establish wait in seconds\n")
f188f2c4 1809{
d70583f7 1810 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
1811}
1812
1813/* Update-delay deconfiguration */
d70583f7 1814DEFPY (no_bgp_update_delay,
f188f2c4 1815 no_bgp_update_delay_cmd,
838758ac
DW
1816 "no update-delay [(0-3600) [(1-3600)]]",
1817 NO_STR
f188f2c4 1818 "Force initial delay for best-path and updates\n"
d70583f7
D
1819 "Max delay in seconds\n"
1820 "Establish wait in seconds\n")
f188f2c4 1821{
d62a17ae 1822 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1823}
1824
5e242b0d 1825
8fa7732f
QY
1826static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1827 bool set)
cb1faec9 1828{
d62a17ae 1829 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1830
8fa7732f
QY
1831 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1832 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
1833
1834 return CMD_SUCCESS;
1835}
1836
8fa7732f
QY
1837static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1838 bool set)
555e09d4
QY
1839{
1840 VTY_DECLVAR_CONTEXT(bgp, bgp);
1841
8fa7732f
QY
1842 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1843 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 1844
d62a17ae 1845 return CMD_SUCCESS;
cb1faec9
DS
1846}
1847
2b791107 1848void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1849{
555e09d4
QY
1850 uint32_t quanta =
1851 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1852 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1853 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1854}
1855
555e09d4
QY
1856void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1857{
1858 uint32_t quanta =
1859 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1860 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1861 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1862}
cb1faec9 1863
8fa7732f
QY
1864/* Packet quanta configuration
1865 *
1866 * XXX: The value set here controls the size of a stack buffer in the IO
1867 * thread. When changing these limits be careful to prevent stack overflow.
1868 *
1869 * Furthermore, the maximums used here should correspond to
1870 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1871 */
1872DEFPY (bgp_wpkt_quanta,
cb1faec9 1873 bgp_wpkt_quanta_cmd,
8fa7732f 1874 "[no] write-quanta (1-64)$quanta",
d7fa34c1 1875 NO_STR
8fa7732f 1876 "How many packets to write to peer socket per run\n"
cb1faec9
DS
1877 "Number of packets\n")
1878{
8fa7732f 1879 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
cb1faec9
DS
1880}
1881
8fa7732f 1882DEFPY (bgp_rpkt_quanta,
555e09d4 1883 bgp_rpkt_quanta_cmd,
8fa7732f 1884 "[no] read-quanta (1-10)$quanta",
555e09d4
QY
1885 NO_STR
1886 "How many packets to read from peer socket per I/O cycle\n"
1887 "Number of packets\n")
1888{
8fa7732f 1889 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
1890}
1891
2b791107 1892void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1893{
37a333fe 1894 if (!bgp->heuristic_coalesce)
d62a17ae 1895 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1896}
1897
1898
1899DEFUN (bgp_coalesce_time,
1900 bgp_coalesce_time_cmd,
6147e2c6 1901 "coalesce-time (0-4294967295)",
3f9c7369
DS
1902 "Subgroup coalesce timer\n"
1903 "Subgroup coalesce timer value (in ms)\n")
1904{
d62a17ae 1905 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1906
d62a17ae 1907 int idx = 0;
1908 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1909 bgp->heuristic_coalesce = false;
d62a17ae 1910 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1911 return CMD_SUCCESS;
3f9c7369
DS
1912}
1913
1914DEFUN (no_bgp_coalesce_time,
1915 no_bgp_coalesce_time_cmd,
6147e2c6 1916 "no coalesce-time (0-4294967295)",
3a2d747c 1917 NO_STR
3f9c7369
DS
1918 "Subgroup coalesce timer\n"
1919 "Subgroup coalesce timer value (in ms)\n")
1920{
d62a17ae 1921 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1922
37a333fe 1923 bgp->heuristic_coalesce = true;
d62a17ae 1924 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1925 return CMD_SUCCESS;
3f9c7369
DS
1926}
1927
5e242b0d
DS
1928/* Maximum-paths configuration */
1929DEFUN (bgp_maxpaths,
1930 bgp_maxpaths_cmd,
6319fd63 1931 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1932 "Forward packets over multiple paths\n"
1933 "Number of paths\n")
1934{
d62a17ae 1935 int idx_number = 1;
1936 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1937 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1938}
1939
d62a17ae 1940ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1941 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1942 "Forward packets over multiple paths\n"
1943 "Number of paths\n")
596c17ba 1944
165b5fff
JB
1945DEFUN (bgp_maxpaths_ibgp,
1946 bgp_maxpaths_ibgp_cmd,
6319fd63 1947 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1948 "Forward packets over multiple paths\n"
1949 "iBGP-multipath\n"
1950 "Number of paths\n")
1951{
d62a17ae 1952 int idx_number = 2;
1953 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1954 argv[idx_number]->arg, 0, 1);
5e242b0d 1955}
165b5fff 1956
d62a17ae 1957ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1958 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1959 "Forward packets over multiple paths\n"
1960 "iBGP-multipath\n"
1961 "Number of paths\n")
596c17ba 1962
5e242b0d
DS
1963DEFUN (bgp_maxpaths_ibgp_cluster,
1964 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1965 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1966 "Forward packets over multiple paths\n"
1967 "iBGP-multipath\n"
1968 "Number of paths\n"
1969 "Match the cluster length\n")
1970{
d62a17ae 1971 int idx_number = 2;
1972 return bgp_maxpaths_config_vty(
1973 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1974 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1975}
1976
d62a17ae 1977ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1978 "maximum-paths ibgp " CMD_RANGE_STR(
1979 1, MULTIPATH_NUM) " equal-cluster-length",
1980 "Forward packets over multiple paths\n"
1981 "iBGP-multipath\n"
1982 "Number of paths\n"
1983 "Match the cluster length\n")
596c17ba 1984
165b5fff
JB
1985DEFUN (no_bgp_maxpaths,
1986 no_bgp_maxpaths_cmd,
6319fd63 1987 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1988 NO_STR
1989 "Forward packets over multiple paths\n"
1990 "Number of paths\n")
1991{
d62a17ae 1992 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1993}
1994
d62a17ae 1995ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1996 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1997 "Forward packets over multiple paths\n"
1998 "Number of paths\n")
596c17ba 1999
165b5fff
JB
2000DEFUN (no_bgp_maxpaths_ibgp,
2001 no_bgp_maxpaths_ibgp_cmd,
6319fd63 2002 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
2003 NO_STR
2004 "Forward packets over multiple paths\n"
2005 "iBGP-multipath\n"
838758ac
DW
2006 "Number of paths\n"
2007 "Match the cluster length\n")
165b5fff 2008{
d62a17ae 2009 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2010}
2011
d62a17ae 2012ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2013 "no maximum-paths ibgp [" CMD_RANGE_STR(
2014 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2015 NO_STR
2016 "Forward packets over multiple paths\n"
2017 "iBGP-multipath\n"
2018 "Number of paths\n"
2019 "Match the cluster length\n")
596c17ba 2020
dd65f45e
DL
2021static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2022 afi_t afi, safi_t safi)
165b5fff 2023{
d62a17ae 2024 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 2025 vty_out(vty, " maximum-paths %d\n",
2026 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2027 }
165b5fff 2028
d62a17ae 2029 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 2030 vty_out(vty, " maximum-paths ibgp %d",
2031 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2032 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2033 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2034 vty_out(vty, " equal-cluster-length");
2035 vty_out(vty, "\n");
2036 }
165b5fff 2037}
6b0655a2 2038
718e3744 2039/* BGP timers. */
2040
2041DEFUN (bgp_timers,
2042 bgp_timers_cmd,
6147e2c6 2043 "timers bgp (0-65535) (0-65535)",
718e3744 2044 "Adjust routing timers\n"
2045 "BGP timers\n"
2046 "Keepalive interval\n"
2047 "Holdtime\n")
2048{
d62a17ae 2049 VTY_DECLVAR_CONTEXT(bgp, bgp);
2050 int idx_number = 2;
2051 int idx_number_2 = 3;
2052 unsigned long keepalive = 0;
2053 unsigned long holdtime = 0;
718e3744 2054
d62a17ae 2055 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2056 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2057
d62a17ae 2058 /* Holdtime value check. */
2059 if (holdtime < 3 && holdtime != 0) {
2060 vty_out(vty,
2061 "%% hold time value must be either 0 or greater than 3\n");
2062 return CMD_WARNING_CONFIG_FAILED;
2063 }
718e3744 2064
5d5393b9 2065 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY);
718e3744 2066
d62a17ae 2067 return CMD_SUCCESS;
718e3744 2068}
2069
2070DEFUN (no_bgp_timers,
2071 no_bgp_timers_cmd,
838758ac 2072 "no timers bgp [(0-65535) (0-65535)]",
718e3744 2073 NO_STR
2074 "Adjust routing timers\n"
838758ac
DW
2075 "BGP timers\n"
2076 "Keepalive interval\n"
2077 "Holdtime\n")
718e3744 2078{
d62a17ae 2079 VTY_DECLVAR_CONTEXT(bgp, bgp);
5d5393b9
DL
2080 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2081 DFLT_BGP_CONNECT_RETRY);
718e3744 2082
d62a17ae 2083 return CMD_SUCCESS;
718e3744 2084}
2085
6b0655a2 2086
718e3744 2087DEFUN (bgp_client_to_client_reflection,
2088 bgp_client_to_client_reflection_cmd,
2089 "bgp client-to-client reflection",
2090 "BGP specific commands\n"
2091 "Configure client to client route reflection\n"
2092 "reflection of routes allowed\n")
2093{
d62a17ae 2094 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2095 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
d62a17ae 2096 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2097
d62a17ae 2098 return CMD_SUCCESS;
718e3744 2099}
2100
2101DEFUN (no_bgp_client_to_client_reflection,
2102 no_bgp_client_to_client_reflection_cmd,
2103 "no bgp client-to-client reflection",
2104 NO_STR
2105 "BGP specific commands\n"
2106 "Configure client to client route reflection\n"
2107 "reflection of routes allowed\n")
2108{
d62a17ae 2109 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2110 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
d62a17ae 2111 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2112
d62a17ae 2113 return CMD_SUCCESS;
718e3744 2114}
2115
2116/* "bgp always-compare-med" configuration. */
2117DEFUN (bgp_always_compare_med,
2118 bgp_always_compare_med_cmd,
2119 "bgp always-compare-med",
2120 "BGP specific commands\n"
2121 "Allow comparing MED from different neighbors\n")
2122{
d62a17ae 2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2124 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
d62a17ae 2125 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2126
d62a17ae 2127 return CMD_SUCCESS;
718e3744 2128}
2129
2130DEFUN (no_bgp_always_compare_med,
2131 no_bgp_always_compare_med_cmd,
2132 "no bgp always-compare-med",
2133 NO_STR
2134 "BGP specific commands\n"
2135 "Allow comparing MED from different neighbors\n")
2136{
d62a17ae 2137 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2138 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
d62a17ae 2139 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2140
d62a17ae 2141 return CMD_SUCCESS;
718e3744 2142}
6b0655a2 2143
9dac9fc8
DA
2144
2145DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2146 "bgp ebgp-requires-policy",
2147 "BGP specific commands\n"
2148 "Require in and out policy for eBGP peers (RFC8212)\n")
2149{
2150 VTY_DECLVAR_CONTEXT(bgp, bgp);
1d3fdccf 2151 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
9dac9fc8
DA
2152 return CMD_SUCCESS;
2153}
2154
2155DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2156 "no bgp ebgp-requires-policy",
2157 NO_STR
2158 "BGP specific commands\n"
2159 "Require in and out policy for eBGP peers (RFC8212)\n")
2160{
2161 VTY_DECLVAR_CONTEXT(bgp, bgp);
1d3fdccf 2162 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
9dac9fc8
DA
2163 return CMD_SUCCESS;
2164}
2165
fb29348a
DA
2166DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2167 "bgp reject-as-sets",
2168 "BGP specific commands\n"
2169 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2170{
2171 VTY_DECLVAR_CONTEXT(bgp, bgp);
2172 struct listnode *node, *nnode;
2173 struct peer *peer;
2174
7f972cd8 2175 bgp->reject_as_sets = true;
fb29348a
DA
2176
2177 /* Reset existing BGP sessions to reject routes
2178 * with aspath containing AS_SET or AS_CONFED_SET.
2179 */
2180 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2181 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2182 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2183 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2184 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2185 }
2186 }
2187
2188 return CMD_SUCCESS;
2189}
2190
2191DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2192 "no bgp reject-as-sets",
2193 NO_STR
2194 "BGP specific commands\n"
2195 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2196{
2197 VTY_DECLVAR_CONTEXT(bgp, bgp);
2198 struct listnode *node, *nnode;
2199 struct peer *peer;
2200
7f972cd8 2201 bgp->reject_as_sets = false;
fb29348a
DA
2202
2203 /* Reset existing BGP sessions to reject routes
2204 * with aspath containing AS_SET or AS_CONFED_SET.
2205 */
2206 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2207 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2208 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2209 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2210 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2211 }
2212 }
2213
2214 return CMD_SUCCESS;
2215}
9dac9fc8 2216
718e3744 2217/* "bgp deterministic-med" configuration. */
2218DEFUN (bgp_deterministic_med,
2219 bgp_deterministic_med_cmd,
2220 "bgp deterministic-med",
2221 "BGP specific commands\n"
2222 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2223{
d62a17ae 2224 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 2225
892fedb6
DA
2226 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2227 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
d62a17ae 2228 bgp_recalculate_all_bestpaths(bgp);
2229 }
7aafcaca 2230
d62a17ae 2231 return CMD_SUCCESS;
718e3744 2232}
2233
2234DEFUN (no_bgp_deterministic_med,
2235 no_bgp_deterministic_med_cmd,
2236 "no bgp deterministic-med",
2237 NO_STR
2238 "BGP specific commands\n"
2239 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2240{
d62a17ae 2241 VTY_DECLVAR_CONTEXT(bgp, bgp);
2242 int bestpath_per_as_used;
2243 afi_t afi;
2244 safi_t safi;
2245 struct peer *peer;
2246 struct listnode *node, *nnode;
2247
892fedb6 2248 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
d62a17ae 2249 bestpath_per_as_used = 0;
2250
2251 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 2252 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
2253 if (bgp_addpath_dmed_required(
2254 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
2255 bestpath_per_as_used = 1;
2256 break;
2257 }
d62a17ae 2258
2259 if (bestpath_per_as_used)
2260 break;
2261 }
2262
2263 if (bestpath_per_as_used) {
2264 vty_out(vty,
2265 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2266 return CMD_WARNING_CONFIG_FAILED;
2267 } else {
892fedb6 2268 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
d62a17ae 2269 bgp_recalculate_all_bestpaths(bgp);
2270 }
2271 }
2272
2273 return CMD_SUCCESS;
718e3744 2274}
538621f2 2275
055679e9 2276/* "bgp graceful-restart mode" configuration. */
538621f2 2277DEFUN (bgp_graceful_restart,
2ba1fe69 2278 bgp_graceful_restart_cmd,
2279 "bgp graceful-restart",
2280 "BGP specific commands\n"
2281 GR_CMD
055679e9 2282 )
538621f2 2283{
055679e9 2284 int ret = BGP_GR_FAILURE;
2285
2286 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2287 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2288
d62a17ae 2289 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2290
2291 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2292
36235319
QY
2293 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2294 ret);
5cce3f05 2295
055679e9 2296 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2297 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2298 vty_out(vty,
2299 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2300 return bgp_vty_return(vty, ret);
538621f2 2301}
2302
2303DEFUN (no_bgp_graceful_restart,
2ba1fe69 2304 no_bgp_graceful_restart_cmd,
2305 "no bgp graceful-restart",
2306 NO_STR
2307 "BGP specific commands\n"
2308 NO_GR_CMD
055679e9 2309 )
538621f2 2310{
d62a17ae 2311 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2312
2313 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2314 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2315
2316 int ret = BGP_GR_FAILURE;
2317
2318 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2319
36235319
QY
2320 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2321 ret);
5cce3f05 2322
055679e9 2323 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2324 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2325 vty_out(vty,
2326 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2327
2328 return bgp_vty_return(vty, ret);
538621f2 2329}
2330
93406d87 2331DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2332 bgp_graceful_restart_stalepath_time_cmd,
2333 "bgp graceful-restart stalepath-time (1-4095)",
2334 "BGP specific commands\n"
2335 "Graceful restart capability parameters\n"
2336 "Set the max time to hold onto restarting peer's stale paths\n"
2337 "Delay value (seconds)\n")
93406d87 2338{
d62a17ae 2339 VTY_DECLVAR_CONTEXT(bgp, bgp);
2340 int idx_number = 3;
d7c0a89a 2341 uint32_t stalepath;
93406d87 2342
d62a17ae 2343 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2344 bgp->stalepath_time = stalepath;
2345 return CMD_SUCCESS;
93406d87 2346}
2347
eb6f1b41 2348DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2349 bgp_graceful_restart_restart_time_cmd,
2350 "bgp graceful-restart restart-time (1-4095)",
2351 "BGP specific commands\n"
2352 "Graceful restart capability parameters\n"
2353 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2354 "Delay value (seconds)\n")
eb6f1b41 2355{
d62a17ae 2356 VTY_DECLVAR_CONTEXT(bgp, bgp);
2357 int idx_number = 3;
d7c0a89a 2358 uint32_t restart;
eb6f1b41 2359
d62a17ae 2360 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2361 bgp->restart_time = restart;
2362 return CMD_SUCCESS;
eb6f1b41
PG
2363}
2364
cfd47646 2365DEFUN (bgp_graceful_restart_select_defer_time,
2366 bgp_graceful_restart_select_defer_time_cmd,
2367 "bgp graceful-restart select-defer-time (0-3600)",
2368 "BGP specific commands\n"
2369 "Graceful restart capability parameters\n"
2370 "Set the time to defer the BGP route selection after restart\n"
2371 "Delay value (seconds, 0 - disable)\n")
2372{
2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
2374 int idx_number = 3;
2375 uint32_t defer_time;
2376
2377 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2378 bgp->select_defer_time = defer_time;
2379 if (defer_time == 0)
892fedb6 2380 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2381 else
892fedb6 2382 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2383
2384 return CMD_SUCCESS;
2385}
2386
93406d87 2387DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2388 no_bgp_graceful_restart_stalepath_time_cmd,
2389 "no bgp graceful-restart stalepath-time [(1-4095)]",
2390 NO_STR
2391 "BGP specific commands\n"
2392 "Graceful restart capability parameters\n"
2393 "Set the max time to hold onto restarting peer's stale paths\n"
2394 "Delay value (seconds)\n")
93406d87 2395{
d62a17ae 2396 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2397
d62a17ae 2398 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2399 return CMD_SUCCESS;
93406d87 2400}
2401
eb6f1b41 2402DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2403 no_bgp_graceful_restart_restart_time_cmd,
2404 "no bgp graceful-restart restart-time [(1-4095)]",
2405 NO_STR
2406 "BGP specific commands\n"
2407 "Graceful restart capability parameters\n"
2408 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2409 "Delay value (seconds)\n")
eb6f1b41 2410{
d62a17ae 2411 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2412
d62a17ae 2413 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2414 return CMD_SUCCESS;
eb6f1b41
PG
2415}
2416
cfd47646 2417DEFUN (no_bgp_graceful_restart_select_defer_time,
2418 no_bgp_graceful_restart_select_defer_time_cmd,
2419 "no bgp graceful-restart select-defer-time [(0-3600)]",
2420 NO_STR
2421 "BGP specific commands\n"
2422 "Graceful restart capability parameters\n"
2423 "Set the time to defer the BGP route selection after restart\n"
2424 "Delay value (seconds)\n")
2425{
2426 VTY_DECLVAR_CONTEXT(bgp, bgp);
2427
2428 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2429 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2430
2431 return CMD_SUCCESS;
2432}
2433
43fc21b3 2434DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2435 bgp_graceful_restart_preserve_fw_cmd,
2436 "bgp graceful-restart preserve-fw-state",
2437 "BGP specific commands\n"
2438 "Graceful restart capability parameters\n"
2439 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2440{
d62a17ae 2441 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2442 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2443 return CMD_SUCCESS;
43fc21b3
JC
2444}
2445
2446DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2447 no_bgp_graceful_restart_preserve_fw_cmd,
2448 "no bgp graceful-restart preserve-fw-state",
2449 NO_STR
2450 "BGP specific commands\n"
2451 "Graceful restart capability parameters\n"
2452 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2453{
d62a17ae 2454 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2455 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2456 return CMD_SUCCESS;
43fc21b3
JC
2457}
2458
055679e9 2459DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2460 bgp_graceful_restart_disable_cmd,
2461 "bgp graceful-restart-disable",
2462 "BGP specific commands\n"
2463 GR_DISABLE)
055679e9 2464{
2465 int ret = BGP_GR_FAILURE;
2466
2467 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2468 zlog_debug(
2ba1fe69 2469 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2470
055679e9 2471 VTY_DECLVAR_CONTEXT(bgp, bgp);
2472
2473 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2474
dc95985f 2475 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2476 bgp->peer, ret);
5cce3f05 2477
055679e9 2478 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2479 zlog_debug(
2ba1fe69 2480 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2481 vty_out(vty,
2482 "Graceful restart configuration changed, reset all peers to take effect\n");
2483
055679e9 2484 return bgp_vty_return(vty, ret);
2485}
2486
2487DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2488 no_bgp_graceful_restart_disable_cmd,
2489 "no bgp graceful-restart-disable",
2490 NO_STR
2491 "BGP specific commands\n"
2492 NO_GR_DISABLE
055679e9 2493 )
2494{
2495 VTY_DECLVAR_CONTEXT(bgp, bgp);
2496
2497 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2498 zlog_debug(
2ba1fe69 2499 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2500
2501 int ret = BGP_GR_FAILURE;
2502
2503 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2504
36235319
QY
2505 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2506 ret);
5cce3f05 2507
055679e9 2508 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2509 zlog_debug(
2ba1fe69 2510 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2511 vty_out(vty,
2512 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2513
2514 return bgp_vty_return(vty, ret);
2515}
2516
2517DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2518 bgp_neighbor_graceful_restart_set_cmd,
2519 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2520 NEIGHBOR_STR
2521 NEIGHBOR_ADDR_STR2
2522 GR_NEIGHBOR_CMD
055679e9 2523 )
2524{
2525 int idx_peer = 1;
2526 struct peer *peer;
2527 int ret = BGP_GR_FAILURE;
2528
dc95985f 2529 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2530
055679e9 2531 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2532 zlog_debug(
2ba1fe69 2533 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2534
055679e9 2535 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2536 if (!peer)
2537 return CMD_WARNING_CONFIG_FAILED;
2538
2539 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2540
dc95985f 2541 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2542 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2543
2544 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2545 zlog_debug(
2ba1fe69 2546 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2547 vty_out(vty,
2548 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2549
2550 return bgp_vty_return(vty, ret);
2551}
2552
2553DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2554 no_bgp_neighbor_graceful_restart_set_cmd,
2555 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2556 NO_STR
2557 NEIGHBOR_STR
2558 NEIGHBOR_ADDR_STR2
2559 NO_GR_NEIGHBOR_CMD
055679e9 2560 )
2561{
2562 int idx_peer = 2;
2563 int ret = BGP_GR_FAILURE;
2564 struct peer *peer;
2565
dc95985f 2566 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2567
055679e9 2568 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2569 if (!peer)
2570 return CMD_WARNING_CONFIG_FAILED;
2571
2572 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2573 zlog_debug(
2ba1fe69 2574 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2575
2576 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2577
dc95985f 2578 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2579 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2580
2581 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2582 zlog_debug(
2ba1fe69 2583 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2584 vty_out(vty,
2585 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2586
2587 return bgp_vty_return(vty, ret);
2588}
2589
2590DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2591 bgp_neighbor_graceful_restart_helper_set_cmd,
2592 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2593 NEIGHBOR_STR
2594 NEIGHBOR_ADDR_STR2
2595 GR_NEIGHBOR_HELPER_CMD
055679e9 2596 )
2597{
2598 int idx_peer = 1;
2599 struct peer *peer;
2600 int ret = BGP_GR_FAILURE;
2601
dc95985f 2602 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2603
055679e9 2604 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2605 zlog_debug(
2ba1fe69 2606 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2607
055679e9 2608 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2609
055679e9 2610 if (!peer)
2611 return CMD_WARNING_CONFIG_FAILED;
2612
2613
2614 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2615
dc95985f 2616 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2617 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2618
055679e9 2619 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2620 zlog_debug(
2ba1fe69 2621 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2622 vty_out(vty,
2623 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2624
2625 return bgp_vty_return(vty, ret);
2626}
2627
2628DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2629 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2630 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2631 NO_STR
2632 NEIGHBOR_STR
2633 NEIGHBOR_ADDR_STR2
2634 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2635 )
2636{
2637 int idx_peer = 2;
2638 int ret = BGP_GR_FAILURE;
2639 struct peer *peer;
2640
dc95985f 2641 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2642
055679e9 2643 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2644 if (!peer)
2645 return CMD_WARNING_CONFIG_FAILED;
2646
2647 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2648 zlog_debug(
2ba1fe69 2649 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 2650
36235319 2651 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 2652
dc95985f 2653 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2654 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2655
2656 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2657 zlog_debug(
2ba1fe69 2658 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2659 vty_out(vty,
2660 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2661
2662 return bgp_vty_return(vty, ret);
2663}
2664
2665DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 2666 bgp_neighbor_graceful_restart_disable_set_cmd,
2667 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2668 NEIGHBOR_STR
2669 NEIGHBOR_ADDR_STR2
2670 GR_NEIGHBOR_DISABLE_CMD
055679e9 2671 )
2672{
2673 int idx_peer = 1;
2674 struct peer *peer;
2675 int ret = BGP_GR_FAILURE;
2676
dc95985f 2677 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2678
055679e9 2679 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2680 zlog_debug(
2ba1fe69 2681 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2682
2683 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2684 if (!peer)
2685 return CMD_WARNING_CONFIG_FAILED;
2686
36235319 2687 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 2688
2689 if (peer->bgp->t_startup)
2690 bgp_peer_gr_flags_update(peer);
2691
dc95985f 2692 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2693 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2694
055679e9 2695 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2696 zlog_debug(
2ba1fe69 2697 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2698 vty_out(vty,
2699 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2700
2701 return bgp_vty_return(vty, ret);
2702}
2703
2704DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 2705 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2706 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2707 NO_STR
2708 NEIGHBOR_STR
2709 NEIGHBOR_ADDR_STR2
2710 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 2711 )
2712{
2713 int idx_peer = 2;
2714 int ret = BGP_GR_FAILURE;
2715 struct peer *peer;
2716
dc95985f 2717 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2718
055679e9 2719 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2720 if (!peer)
2721 return CMD_WARNING_CONFIG_FAILED;
2722
2723 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2724 zlog_debug(
2ba1fe69 2725 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2726
2727 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2728
dc95985f 2729 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2730 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2731
2732 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2733 zlog_debug(
2ba1fe69 2734 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2735 vty_out(vty,
2736 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2737
2738 return bgp_vty_return(vty, ret);
2739}
2740
d6e3c15b 2741DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2742 bgp_graceful_restart_disable_eor_cmd,
2743 "bgp graceful-restart disable-eor",
2744 "BGP specific commands\n"
2745 "Graceful restart configuration parameters\n"
2746 "Disable EOR Check\n")
2747{
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2749 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2750
d6e3c15b 2751 return CMD_SUCCESS;
2752}
2753
2754DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2755 no_bgp_graceful_restart_disable_eor_cmd,
2756 "no bgp graceful-restart disable-eor",
2757 NO_STR
2758 "BGP specific commands\n"
2759 "Graceful restart configuration parameters\n"
2760 "Disable EOR Check\n")
2761{
2762 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2763 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2764
2765 return CMD_SUCCESS;
2766}
2767
2768DEFUN (bgp_graceful_restart_rib_stale_time,
2769 bgp_graceful_restart_rib_stale_time_cmd,
2770 "bgp graceful-restart rib-stale-time (1-3600)",
2771 "BGP specific commands\n"
2772 "Graceful restart configuration parameters\n"
2773 "Specify the stale route removal timer in rib\n"
2774 "Delay value (seconds)\n")
2775{
2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
2777 int idx_number = 3;
2778 uint32_t stale_time;
2779
2780 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2781 bgp->rib_stale_time = stale_time;
2782 /* Send the stale timer update message to RIB */
2783 if (bgp_zebra_stale_timer_update(bgp))
2784 return CMD_WARNING;
2785
2786 return CMD_SUCCESS;
2787}
2788
2789DEFUN (no_bgp_graceful_restart_rib_stale_time,
2790 no_bgp_graceful_restart_rib_stale_time_cmd,
2791 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2792 NO_STR
2793 "BGP specific commands\n"
2794 "Graceful restart configuration parameters\n"
2795 "Specify the stale route removal timer in rib\n"
2796 "Delay value (seconds)\n")
2797{
2798 VTY_DECLVAR_CONTEXT(bgp, bgp);
2799
2800 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
2801 /* Send the stale timer update message to RIB */
2802 if (bgp_zebra_stale_timer_update(bgp))
2803 return CMD_WARNING;
2804
d6e3c15b 2805 return CMD_SUCCESS;
2806}
2807
05bd726c 2808static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
2809 struct bgp *bgp)
2810{
2811 bgp_static_redo_import_check(bgp);
2812 bgp_redistribute_redo(bgp);
2813 bgp_clear_star_soft_out(vty, bgp->name);
2814 bgp_clear_star_soft_in(vty, bgp->name);
2815}
2816
2817static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
2818{
2819 struct listnode *node, *nnode;
2820 struct bgp *bgp;
2821 bool vrf_cfg = false;
2822
2823 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
2824 return CMD_SUCCESS;
2825
2826 /* See if graceful-shutdown is set per-vrf and warn user to delete */
2827 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2828 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2829 vty_out(vty,
2830 "%% graceful-shutdown configuration found in vrf %s\n",
2831 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
2832 VRF_DEFAULT_NAME : bgp->name);
2833 vrf_cfg = true;
2834 }
2835 }
2836
2837 if (vrf_cfg) {
2838 vty_out(vty,
2839 "%%Failed: global graceful-shutdown not permitted\n");
2840 return CMD_WARNING;
2841 }
2842
2843 /* Set flag globally */
2844 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
2845
2846 /* Initiate processing for all BGP instances. */
2847 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
2848 bgp_initiate_graceful_shut_unshut(vty, bgp);
2849
2850 return CMD_SUCCESS;
2851}
2852
2853static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
2854{
2855 struct listnode *node, *nnode;
2856 struct bgp *bgp;
2857
2858 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
2859 return CMD_SUCCESS;
2860
2861 /* Unset flag globally */
2862 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
2863
2864 /* Initiate processing for all BGP instances. */
2865 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
2866 bgp_initiate_graceful_shut_unshut(vty, bgp);
2867
2868 return CMD_SUCCESS;
2869}
2870
7f323236
DW
2871/* "bgp graceful-shutdown" configuration */
2872DEFUN (bgp_graceful_shutdown,
2873 bgp_graceful_shutdown_cmd,
2874 "bgp graceful-shutdown",
2875 BGP_STR
2876 "Graceful shutdown parameters\n")
2877{
05bd726c 2878 if (vty->node == CONFIG_NODE)
2879 return bgp_global_graceful_shutdown_config_vty(vty);
2880
7f323236
DW
2881 VTY_DECLVAR_CONTEXT(bgp, bgp);
2882
05bd726c 2883 /* if configured globally, per-instance config is not allowed */
2884 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
2885 vty_out(vty,
2886 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
2887 return CMD_WARNING_CONFIG_FAILED;
2888 }
2889
892fedb6
DA
2890 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2891 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
05bd726c 2892 bgp_initiate_graceful_shut_unshut(vty, bgp);
7f323236
DW
2893 }
2894
2895 return CMD_SUCCESS;
2896}
2897
2898DEFUN (no_bgp_graceful_shutdown,
2899 no_bgp_graceful_shutdown_cmd,
2900 "no bgp graceful-shutdown",
2901 NO_STR
2902 BGP_STR
2903 "Graceful shutdown parameters\n")
2904{
05bd726c 2905 if (vty->node == CONFIG_NODE)
2906 return bgp_global_graceful_shutdown_deconfig_vty(vty);
2907
7f323236
DW
2908 VTY_DECLVAR_CONTEXT(bgp, bgp);
2909
05bd726c 2910 /* If configured globally, cannot remove from one bgp instance */
2911 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
2912 vty_out(vty,
2913 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
2914 return CMD_WARNING_CONFIG_FAILED;
2915 }
2916
892fedb6
DA
2917 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2918 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
05bd726c 2919 bgp_initiate_graceful_shut_unshut(vty, bgp);
7f323236
DW
2920 }
2921
2922 return CMD_SUCCESS;
2923}
2924
718e3744 2925/* "bgp fast-external-failover" configuration. */
2926DEFUN (bgp_fast_external_failover,
2927 bgp_fast_external_failover_cmd,
2928 "bgp fast-external-failover",
2929 BGP_STR
2930 "Immediately reset session if a link to a directly connected external peer goes down\n")
2931{
d62a17ae 2932 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2933 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
d62a17ae 2934 return CMD_SUCCESS;
718e3744 2935}
2936
2937DEFUN (no_bgp_fast_external_failover,
2938 no_bgp_fast_external_failover_cmd,
2939 "no bgp fast-external-failover",
2940 NO_STR
2941 BGP_STR
2942 "Immediately reset session if a link to a directly connected external peer goes down\n")
2943{
d62a17ae 2944 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2945 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
d62a17ae 2946 return CMD_SUCCESS;
718e3744 2947}
6b0655a2 2948
718e3744 2949/* "bgp bestpath compare-routerid" configuration. */
2950DEFUN (bgp_bestpath_compare_router_id,
2951 bgp_bestpath_compare_router_id_cmd,
2952 "bgp bestpath compare-routerid",
2953 "BGP specific commands\n"
2954 "Change the default bestpath selection\n"
2955 "Compare router-id for identical EBGP paths\n")
2956{
d62a17ae 2957 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2958 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
d62a17ae 2959 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2960
d62a17ae 2961 return CMD_SUCCESS;
718e3744 2962}
2963
2964DEFUN (no_bgp_bestpath_compare_router_id,
2965 no_bgp_bestpath_compare_router_id_cmd,
2966 "no bgp bestpath compare-routerid",
2967 NO_STR
2968 "BGP specific commands\n"
2969 "Change the default bestpath selection\n"
2970 "Compare router-id for identical EBGP paths\n")
2971{
d62a17ae 2972 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2973 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
d62a17ae 2974 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2975
d62a17ae 2976 return CMD_SUCCESS;
718e3744 2977}
6b0655a2 2978
718e3744 2979/* "bgp bestpath as-path ignore" configuration. */
2980DEFUN (bgp_bestpath_aspath_ignore,
2981 bgp_bestpath_aspath_ignore_cmd,
2982 "bgp bestpath as-path ignore",
2983 "BGP specific commands\n"
2984 "Change the default bestpath selection\n"
2985 "AS-path attribute\n"
2986 "Ignore as-path length in selecting a route\n")
2987{
d62a17ae 2988 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2989 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
d62a17ae 2990 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2991
d62a17ae 2992 return CMD_SUCCESS;
718e3744 2993}
2994
2995DEFUN (no_bgp_bestpath_aspath_ignore,
2996 no_bgp_bestpath_aspath_ignore_cmd,
2997 "no bgp bestpath as-path ignore",
2998 NO_STR
2999 "BGP specific commands\n"
3000 "Change the default bestpath selection\n"
3001 "AS-path attribute\n"
3002 "Ignore as-path length in selecting a route\n")
3003{
d62a17ae 3004 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3005 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
d62a17ae 3006 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3007
d62a17ae 3008 return CMD_SUCCESS;
718e3744 3009}
6b0655a2 3010
6811845b 3011/* "bgp bestpath as-path confed" configuration. */
3012DEFUN (bgp_bestpath_aspath_confed,
3013 bgp_bestpath_aspath_confed_cmd,
3014 "bgp bestpath as-path confed",
3015 "BGP specific commands\n"
3016 "Change the default bestpath selection\n"
3017 "AS-path attribute\n"
3018 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3019{
d62a17ae 3020 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3021 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
d62a17ae 3022 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3023
d62a17ae 3024 return CMD_SUCCESS;
6811845b 3025}
3026
3027DEFUN (no_bgp_bestpath_aspath_confed,
3028 no_bgp_bestpath_aspath_confed_cmd,
3029 "no bgp bestpath as-path confed",
3030 NO_STR
3031 "BGP specific commands\n"
3032 "Change the default bestpath selection\n"
3033 "AS-path attribute\n"
3034 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3035{
d62a17ae 3036 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3037 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
d62a17ae 3038 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3039
d62a17ae 3040 return CMD_SUCCESS;
6811845b 3041}
6b0655a2 3042
2fdd455c
PM
3043/* "bgp bestpath as-path multipath-relax" configuration. */
3044DEFUN (bgp_bestpath_aspath_multipath_relax,
3045 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3046 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3047 "BGP specific commands\n"
3048 "Change the default bestpath selection\n"
3049 "AS-path attribute\n"
3050 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3051 "Generate an AS_SET\n"
16fc1eec
DS
3052 "Do not generate an AS_SET\n")
3053{
d62a17ae 3054 VTY_DECLVAR_CONTEXT(bgp, bgp);
3055 int idx = 0;
892fedb6 3056 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3057
d62a17ae 3058 /* no-as-set is now the default behavior so we can silently
3059 * ignore it */
3060 if (argv_find(argv, argc, "as-set", &idx))
892fedb6 3061 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3062 else
892fedb6 3063 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 3064
d62a17ae 3065 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3066
d62a17ae 3067 return CMD_SUCCESS;
16fc1eec
DS
3068}
3069
219178b6
DW
3070DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3071 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3072 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3073 NO_STR
3074 "BGP specific commands\n"
3075 "Change the default bestpath selection\n"
3076 "AS-path attribute\n"
3077 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3078 "Generate an AS_SET\n"
16fc1eec
DS
3079 "Do not generate an AS_SET\n")
3080{
d62a17ae 3081 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
3082 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3083 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3084 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3085
d62a17ae 3086 return CMD_SUCCESS;
2fdd455c 3087}
6b0655a2 3088
848973c7 3089/* "bgp log-neighbor-changes" configuration. */
3090DEFUN (bgp_log_neighbor_changes,
3091 bgp_log_neighbor_changes_cmd,
3092 "bgp log-neighbor-changes",
3093 "BGP specific commands\n"
3094 "Log neighbor up/down and reset reason\n")
3095{
d62a17ae 3096 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3097 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
d62a17ae 3098 return CMD_SUCCESS;
848973c7 3099}
3100
3101DEFUN (no_bgp_log_neighbor_changes,
3102 no_bgp_log_neighbor_changes_cmd,
3103 "no bgp log-neighbor-changes",
3104 NO_STR
3105 "BGP specific commands\n"
3106 "Log neighbor up/down and reset reason\n")
3107{
d62a17ae 3108 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3109 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
d62a17ae 3110 return CMD_SUCCESS;
848973c7 3111}
6b0655a2 3112
718e3744 3113/* "bgp bestpath med" configuration. */
3114DEFUN (bgp_bestpath_med,
3115 bgp_bestpath_med_cmd,
2d8c1a4d 3116 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3117 "BGP specific commands\n"
3118 "Change the default bestpath selection\n"
3119 "MED attribute\n"
3120 "Compare MED among confederation paths\n"
838758ac
DW
3121 "Treat missing MED as the least preferred one\n"
3122 "Treat missing MED as the least preferred one\n"
3123 "Compare MED among confederation paths\n")
718e3744 3124{
d62a17ae 3125 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 3126
d62a17ae 3127 int idx = 0;
3128 if (argv_find(argv, argc, "confed", &idx))
892fedb6 3129 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3130 idx = 0;
3131 if (argv_find(argv, argc, "missing-as-worst", &idx))
892fedb6 3132 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3133
d62a17ae 3134 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3135
d62a17ae 3136 return CMD_SUCCESS;
718e3744 3137}
3138
718e3744 3139DEFUN (no_bgp_bestpath_med,
3140 no_bgp_bestpath_med_cmd,
2d8c1a4d 3141 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3142 NO_STR
3143 "BGP specific commands\n"
3144 "Change the default bestpath selection\n"
3145 "MED attribute\n"
3146 "Compare MED among confederation paths\n"
3a2d747c
QY
3147 "Treat missing MED as the least preferred one\n"
3148 "Treat missing MED as the least preferred one\n"
3149 "Compare MED among confederation paths\n")
718e3744 3150{
d62a17ae 3151 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 3152
d62a17ae 3153 int idx = 0;
3154 if (argv_find(argv, argc, "confed", &idx))
892fedb6 3155 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3156 idx = 0;
3157 if (argv_find(argv, argc, "missing-as-worst", &idx))
892fedb6 3158 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 3159
d62a17ae 3160 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3161
d62a17ae 3162 return CMD_SUCCESS;
718e3744 3163}
3164
f7e1c681 3165/* "bgp bestpath bandwidth" configuration. */
3166DEFPY (bgp_bestpath_bw,
3167 bgp_bestpath_bw_cmd,
ad36d216 3168 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3169 "BGP specific commands\n"
3170 "Change the default bestpath selection\n"
3171 "Link Bandwidth attribute\n"
3172 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3173 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3174 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3175{
3176 VTY_DECLVAR_CONTEXT(bgp, bgp);
3177 afi_t afi;
3178 safi_t safi;
3179
ad36d216
DS
3180 if (!bw_cfg) {
3181 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3182 return CMD_ERR_INCOMPLETE;
f7e1c681 3183 }
ad36d216
DS
3184 if (!strcmp(bw_cfg, "ignore"))
3185 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3186 else if (!strcmp(bw_cfg, "skip-missing"))
3187 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3188 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3189 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3190 else
3191 return CMD_ERR_NO_MATCH;
f7e1c681 3192
3193 /* This config is used in route install, so redo that. */
3194 FOREACH_AFI_SAFI (afi, safi) {
3195 if (!bgp_fibupd_safi(safi))
3196 continue;
3197 bgp_zebra_announce_table(bgp, afi, safi);
3198 }
3199
3200 return CMD_SUCCESS;
3201}
3202
ad36d216
DS
3203DEFPY (no_bgp_bestpath_bw,
3204 no_bgp_bestpath_bw_cmd,
3205 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3206 NO_STR
3207 "BGP specific commands\n"
3208 "Change the default bestpath selection\n"
3209 "Link Bandwidth attribute\n"
3210 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3211 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3212 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3213{
3214 VTY_DECLVAR_CONTEXT(bgp, bgp);
3215 afi_t afi;
3216 safi_t safi;
3217
3218 bgp->lb_handling = BGP_LINK_BW_ECMP;
3219
3220 /* This config is used in route install, so redo that. */
3221 FOREACH_AFI_SAFI (afi, safi) {
3222 if (!bgp_fibupd_safi(safi))
3223 continue;
3224 bgp_zebra_announce_table(bgp, afi, safi);
3225 }
3226 return CMD_SUCCESS;
3227}
3228
718e3744 3229/* "no bgp default ipv4-unicast". */
3230DEFUN (no_bgp_default_ipv4_unicast,
3231 no_bgp_default_ipv4_unicast_cmd,
3232 "no bgp default ipv4-unicast",
3233 NO_STR
3234 "BGP specific commands\n"
3235 "Configure BGP defaults\n"
3236 "Activate ipv4-unicast for a peer by default\n")
3237{
d62a17ae 3238 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3239 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3240 return CMD_SUCCESS;
718e3744 3241}
3242
3243DEFUN (bgp_default_ipv4_unicast,
3244 bgp_default_ipv4_unicast_cmd,
3245 "bgp default ipv4-unicast",
3246 "BGP specific commands\n"
3247 "Configure BGP defaults\n"
3248 "Activate ipv4-unicast for a peer by default\n")
3249{
d62a17ae 3250 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3251 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3252 return CMD_SUCCESS;
718e3744 3253}
6b0655a2 3254
04b6bdc0
DW
3255/* Display hostname in certain command outputs */
3256DEFUN (bgp_default_show_hostname,
3257 bgp_default_show_hostname_cmd,
3258 "bgp default show-hostname",
3259 "BGP specific commands\n"
3260 "Configure BGP defaults\n"
0437e105 3261 "Show hostname in certain command outputs\n")
04b6bdc0 3262{
d62a17ae 3263 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3264 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
d62a17ae 3265 return CMD_SUCCESS;
04b6bdc0
DW
3266}
3267
3268DEFUN (no_bgp_default_show_hostname,
3269 no_bgp_default_show_hostname_cmd,
3270 "no bgp default show-hostname",
3271 NO_STR
3272 "BGP specific commands\n"
3273 "Configure BGP defaults\n"
0437e105 3274 "Show hostname in certain command outputs\n")
04b6bdc0 3275{
d62a17ae 3276 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3277 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
d62a17ae 3278 return CMD_SUCCESS;
04b6bdc0
DW
3279}
3280
aef999a2
DA
3281/* Display hostname in certain command outputs */
3282DEFUN (bgp_default_show_nexthop_hostname,
3283 bgp_default_show_nexthop_hostname_cmd,
3284 "bgp default show-nexthop-hostname",
3285 "BGP specific commands\n"
3286 "Configure BGP defaults\n"
3287 "Show hostname for nexthop in certain command outputs\n")
3288{
3289 VTY_DECLVAR_CONTEXT(bgp, bgp);
3290 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3291 return CMD_SUCCESS;
3292}
3293
3294DEFUN (no_bgp_default_show_nexthop_hostname,
3295 no_bgp_default_show_nexthop_hostname_cmd,
3296 "no bgp default show-nexthop-hostname",
3297 NO_STR
3298 "BGP specific commands\n"
3299 "Configure BGP defaults\n"
3300 "Show hostname for nexthop in certain command outputs\n")
3301{
3302 VTY_DECLVAR_CONTEXT(bgp, bgp);
3303 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3304 return CMD_SUCCESS;
3305}
3306
8233ef81 3307/* "bgp network import-check" configuration. */
718e3744 3308DEFUN (bgp_network_import_check,
3309 bgp_network_import_check_cmd,
5623e905 3310 "bgp network import-check",
718e3744 3311 "BGP specific commands\n"
3312 "BGP network command\n"
5623e905 3313 "Check BGP network route exists in IGP\n")
718e3744 3314{
d62a17ae 3315 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
3316 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3317 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
d62a17ae 3318 bgp_static_redo_import_check(bgp);
3319 }
078430f6 3320
d62a17ae 3321 return CMD_SUCCESS;
718e3744 3322}
3323
d62a17ae 3324ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3325 "bgp network import-check exact",
3326 "BGP specific commands\n"
3327 "BGP network command\n"
3328 "Check BGP network route exists in IGP\n"
3329 "Match route precisely\n")
8233ef81 3330
718e3744 3331DEFUN (no_bgp_network_import_check,
3332 no_bgp_network_import_check_cmd,
5623e905 3333 "no bgp network import-check",
718e3744 3334 NO_STR
3335 "BGP specific commands\n"
3336 "BGP network command\n"
3337 "Check BGP network route exists in IGP\n")
3338{
d62a17ae 3339 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
3340 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3341 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
d62a17ae 3342 bgp_static_redo_import_check(bgp);
3343 }
5623e905 3344
d62a17ae 3345 return CMD_SUCCESS;
718e3744 3346}
6b0655a2 3347
718e3744 3348DEFUN (bgp_default_local_preference,
3349 bgp_default_local_preference_cmd,
6147e2c6 3350 "bgp default local-preference (0-4294967295)",
718e3744 3351 "BGP specific commands\n"
3352 "Configure BGP defaults\n"
3353 "local preference (higher=more preferred)\n"
3354 "Configure default local preference value\n")
3355{
d62a17ae 3356 VTY_DECLVAR_CONTEXT(bgp, bgp);
3357 int idx_number = 3;
d7c0a89a 3358 uint32_t local_pref;
718e3744 3359
d62a17ae 3360 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3361
d62a17ae 3362 bgp_default_local_preference_set(bgp, local_pref);
3363 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3364
d62a17ae 3365 return CMD_SUCCESS;
718e3744 3366}
3367
3368DEFUN (no_bgp_default_local_preference,
3369 no_bgp_default_local_preference_cmd,
838758ac 3370 "no bgp default local-preference [(0-4294967295)]",
718e3744 3371 NO_STR
3372 "BGP specific commands\n"
3373 "Configure BGP defaults\n"
838758ac
DW
3374 "local preference (higher=more preferred)\n"
3375 "Configure default local preference value\n")
718e3744 3376{
d62a17ae 3377 VTY_DECLVAR_CONTEXT(bgp, bgp);
3378 bgp_default_local_preference_unset(bgp);
3379 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3380
d62a17ae 3381 return CMD_SUCCESS;
718e3744 3382}
3383
6b0655a2 3384
3f9c7369
DS
3385DEFUN (bgp_default_subgroup_pkt_queue_max,
3386 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 3387 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
3388 "BGP specific commands\n"
3389 "Configure BGP defaults\n"
3390 "subgroup-pkt-queue-max\n"
3391 "Configure subgroup packet queue max\n")
8bd9d948 3392{
d62a17ae 3393 VTY_DECLVAR_CONTEXT(bgp, bgp);
3394 int idx_number = 3;
d7c0a89a 3395 uint32_t max_size;
8bd9d948 3396
d62a17ae 3397 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3398
d62a17ae 3399 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 3400
d62a17ae 3401 return CMD_SUCCESS;
3f9c7369
DS
3402}
3403
3404DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3405 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 3406 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
3407 NO_STR
3408 "BGP specific commands\n"
3409 "Configure BGP defaults\n"
838758ac
DW
3410 "subgroup-pkt-queue-max\n"
3411 "Configure subgroup packet queue max\n")
3f9c7369 3412{
d62a17ae 3413 VTY_DECLVAR_CONTEXT(bgp, bgp);
3414 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3415 return CMD_SUCCESS;
8bd9d948
DS
3416}
3417
813d4307 3418
8bd9d948
DS
3419DEFUN (bgp_rr_allow_outbound_policy,
3420 bgp_rr_allow_outbound_policy_cmd,
3421 "bgp route-reflector allow-outbound-policy",
3422 "BGP specific commands\n"
3423 "Allow modifications made by out route-map\n"
3424 "on ibgp neighbors\n")
3425{
d62a17ae 3426 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3427
892fedb6
DA
3428 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3429 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
d62a17ae 3430 update_group_announce_rrclients(bgp);
3431 bgp_clear_star_soft_out(vty, bgp->name);
3432 }
8bd9d948 3433
d62a17ae 3434 return CMD_SUCCESS;
8bd9d948
DS
3435}
3436
3437DEFUN (no_bgp_rr_allow_outbound_policy,
3438 no_bgp_rr_allow_outbound_policy_cmd,
3439 "no bgp route-reflector allow-outbound-policy",
3440 NO_STR
3441 "BGP specific commands\n"
3442 "Allow modifications made by out route-map\n"
3443 "on ibgp neighbors\n")
3444{
d62a17ae 3445 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3446
892fedb6
DA
3447 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3448 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
d62a17ae 3449 update_group_announce_rrclients(bgp);
3450 bgp_clear_star_soft_out(vty, bgp->name);
3451 }
8bd9d948 3452
d62a17ae 3453 return CMD_SUCCESS;
8bd9d948
DS
3454}
3455
f14e6fdb
DS
3456DEFUN (bgp_listen_limit,
3457 bgp_listen_limit_cmd,
9ccf14f7 3458 "bgp listen limit (1-5000)",
f14e6fdb 3459 "BGP specific commands\n"
1601a46f 3460 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3461 "Maximum number of BGP Dynamic Neighbors that can be created\n"
f14e6fdb
DS
3462 "Configure Dynamic Neighbors listen limit value\n")
3463{
d62a17ae 3464 VTY_DECLVAR_CONTEXT(bgp, bgp);
3465 int idx_number = 3;
3466 int listen_limit;
f14e6fdb 3467
d62a17ae 3468 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3469
d62a17ae 3470 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3471
d62a17ae 3472 return CMD_SUCCESS;
f14e6fdb
DS
3473}
3474
3475DEFUN (no_bgp_listen_limit,
3476 no_bgp_listen_limit_cmd,
838758ac 3477 "no bgp listen limit [(1-5000)]",
1601a46f 3478 NO_STR
f14e6fdb 3479 "BGP specific commands\n"
1601a46f 3480 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3481 "Maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac 3482 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3483{
d62a17ae 3484 VTY_DECLVAR_CONTEXT(bgp, bgp);
3485 bgp_listen_limit_unset(bgp);
3486 return CMD_SUCCESS;
f14e6fdb
DS
3487}
3488
3489
20eb8864 3490/*
3491 * Check if this listen range is already configured. Check for exact
3492 * match or overlap based on input.
3493 */
d62a17ae 3494static struct peer_group *listen_range_exists(struct bgp *bgp,
3495 struct prefix *range, int exact)
3496{
3497 struct listnode *node, *nnode;
3498 struct listnode *node1, *nnode1;
3499 struct peer_group *group;
3500 struct prefix *lr;
3501 afi_t afi;
3502 int match;
3503
3504 afi = family2afi(range->family);
3505 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3506 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3507 lr)) {
3508 if (exact)
3509 match = prefix_same(range, lr);
3510 else
3511 match = (prefix_match(range, lr)
3512 || prefix_match(lr, range));
3513 if (match)
3514 return group;
3515 }
3516 }
3517
3518 return NULL;
20eb8864 3519}
3520
f14e6fdb
DS
3521DEFUN (bgp_listen_range,
3522 bgp_listen_range_cmd,
d7b9898c 3523 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3524 "BGP specific commands\n"
d7fa34c1
QY
3525 "Configure BGP dynamic neighbors listen range\n"
3526 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3527 NEIGHBOR_ADDR_STR
3528 "Member of the peer-group\n"
3529 "Peer-group name\n")
f14e6fdb 3530{
d62a17ae 3531 VTY_DECLVAR_CONTEXT(bgp, bgp);
3532 struct prefix range;
3533 struct peer_group *group, *existing_group;
3534 afi_t afi;
3535 int ret;
3536 int idx = 0;
3537
3538 argv_find(argv, argc, "A.B.C.D/M", &idx);
3539 argv_find(argv, argc, "X:X::X:X/M", &idx);
3540 char *prefix = argv[idx]->arg;
d7b9898c 3541 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3542 char *peergroup = argv[idx]->arg;
3543
3544 /* Convert IP prefix string to struct prefix. */
3545 ret = str2prefix(prefix, &range);
3546 if (!ret) {
3547 vty_out(vty, "%% Malformed listen range\n");
3548 return CMD_WARNING_CONFIG_FAILED;
3549 }
3550
3551 afi = family2afi(range.family);
3552
3553 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3554 vty_out(vty,
3555 "%% Malformed listen range (link-local address)\n");
3556 return CMD_WARNING_CONFIG_FAILED;
3557 }
3558
3559 apply_mask(&range);
3560
3561 /* Check if same listen range is already configured. */
3562 existing_group = listen_range_exists(bgp, &range, 1);
3563 if (existing_group) {
3564 if (strcmp(existing_group->name, peergroup) == 0)
3565 return CMD_SUCCESS;
3566 else {
3567 vty_out(vty,
3568 "%% Same listen range is attached to peer-group %s\n",
3569 existing_group->name);
3570 return CMD_WARNING_CONFIG_FAILED;
3571 }
3572 }
3573
3574 /* Check if an overlapping listen range exists. */
3575 if (listen_range_exists(bgp, &range, 0)) {
3576 vty_out(vty,
3577 "%% Listen range overlaps with existing listen range\n");
3578 return CMD_WARNING_CONFIG_FAILED;
3579 }
3580
3581 group = peer_group_lookup(bgp, peergroup);
3582 if (!group) {
3583 vty_out(vty, "%% Configure the peer-group first\n");
3584 return CMD_WARNING_CONFIG_FAILED;
3585 }
3586
3587 ret = peer_group_listen_range_add(group, &range);
3588 return bgp_vty_return(vty, ret);
f14e6fdb
DS
3589}
3590
3591DEFUN (no_bgp_listen_range,
3592 no_bgp_listen_range_cmd,
d7b9898c 3593 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 3594 NO_STR
f14e6fdb 3595 "BGP specific commands\n"
d7fa34c1
QY
3596 "Unconfigure BGP dynamic neighbors listen range\n"
3597 "Unconfigure BGP dynamic neighbors listen range\n"
3598 NEIGHBOR_ADDR_STR
3599 "Member of the peer-group\n"
3600 "Peer-group name\n")
f14e6fdb 3601{
d62a17ae 3602 VTY_DECLVAR_CONTEXT(bgp, bgp);
3603 struct prefix range;
3604 struct peer_group *group;
3605 afi_t afi;
3606 int ret;
3607 int idx = 0;
3608
3609 argv_find(argv, argc, "A.B.C.D/M", &idx);
3610 argv_find(argv, argc, "X:X::X:X/M", &idx);
3611 char *prefix = argv[idx]->arg;
21d88a71 3612 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3613 char *peergroup = argv[idx]->arg;
3614
3615 /* Convert IP prefix string to struct prefix. */
3616 ret = str2prefix(prefix, &range);
3617 if (!ret) {
3618 vty_out(vty, "%% Malformed listen range\n");
3619 return CMD_WARNING_CONFIG_FAILED;
3620 }
3621
3622 afi = family2afi(range.family);
3623
3624 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3625 vty_out(vty,
3626 "%% Malformed listen range (link-local address)\n");
3627 return CMD_WARNING_CONFIG_FAILED;
3628 }
3629
3630 apply_mask(&range);
3631
3632 group = peer_group_lookup(bgp, peergroup);
3633 if (!group) {
3634 vty_out(vty, "%% Peer-group does not exist\n");
3635 return CMD_WARNING_CONFIG_FAILED;
3636 }
3637
3638 ret = peer_group_listen_range_del(group, &range);
3639 return bgp_vty_return(vty, ret);
3640}
3641
2b791107 3642void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 3643{
3644 struct peer_group *group;
3645 struct listnode *node, *nnode, *rnode, *nrnode;
3646 struct prefix *range;
3647 afi_t afi;
3648 char buf[PREFIX2STR_BUFFER];
3649
3650 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3651 vty_out(vty, " bgp listen limit %d\n",
3652 bgp->dynamic_neighbors_limit);
3653
3654 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3655 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3656 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3657 nrnode, range)) {
3658 prefix2str(range, buf, sizeof(buf));
3659 vty_out(vty,
3660 " bgp listen range %s peer-group %s\n",
3661 buf, group->name);
3662 }
3663 }
3664 }
f14e6fdb
DS
3665}
3666
3667
907f92c8
DS
3668DEFUN (bgp_disable_connected_route_check,
3669 bgp_disable_connected_route_check_cmd,
3670 "bgp disable-ebgp-connected-route-check",
3671 "BGP specific commands\n"
3672 "Disable checking if nexthop is connected on ebgp sessions\n")
3673{
d62a17ae 3674 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3675 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
d62a17ae 3676 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3677
d62a17ae 3678 return CMD_SUCCESS;
907f92c8
DS
3679}
3680
3681DEFUN (no_bgp_disable_connected_route_check,
3682 no_bgp_disable_connected_route_check_cmd,
3683 "no bgp disable-ebgp-connected-route-check",
3684 NO_STR
3685 "BGP specific commands\n"
3686 "Disable checking if nexthop is connected on ebgp sessions\n")
3687{
d62a17ae 3688 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3689 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
d62a17ae 3690 bgp_clear_star_soft_in(vty, bgp->name);
3691
3692 return CMD_SUCCESS;
3693}
3694
3695
3696static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3697 const char *as_str, afi_t afi, safi_t safi)
3698{
3699 VTY_DECLVAR_CONTEXT(bgp, bgp);
3700 int ret;
3701 as_t as;
3702 int as_type = AS_SPECIFIED;
3703 union sockunion su;
3704
3705 if (as_str[0] == 'i') {
3706 as = 0;
3707 as_type = AS_INTERNAL;
3708 } else if (as_str[0] == 'e') {
3709 as = 0;
3710 as_type = AS_EXTERNAL;
3711 } else {
3712 /* Get AS number. */
3713 as = strtoul(as_str, NULL, 10);
3714 }
3715
390485fd 3716 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 3717 ret = str2sockunion(peer_str, &su);
3718 if (ret < 0) {
390485fd
DS
3719 struct peer *peer;
3720
3721 /* Check if existing interface peer */
3722 peer = peer_lookup_by_conf_if(bgp, peer_str);
3723
d62a17ae 3724 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3725 safi);
390485fd
DS
3726
3727 /* if not interface peer, check peer-group settings */
3728 if (ret < 0 && !peer) {
d62a17ae 3729 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3730 if (ret < 0) {
3731 vty_out(vty,
390485fd 3732 "%% Create the peer-group or interface first\n");
d62a17ae 3733 return CMD_WARNING_CONFIG_FAILED;
3734 }
3735 return CMD_SUCCESS;
3736 }
3737 } else {
3738 if (peer_address_self_check(bgp, &su)) {
3739 vty_out(vty,
3740 "%% Can not configure the local system as neighbor\n");
3741 return CMD_WARNING_CONFIG_FAILED;
3742 }
3743 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3744 }
3745
3746 /* This peer belongs to peer group. */
3747 switch (ret) {
3748 case BGP_ERR_PEER_GROUP_MEMBER:
3749 vty_out(vty,
faa16034 3750 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 3751 return CMD_WARNING_CONFIG_FAILED;
3752 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3753 vty_out(vty,
faa16034 3754 "%% Peer-group members must be all internal or all external\n");
d62a17ae 3755 return CMD_WARNING_CONFIG_FAILED;
3756 }
3757 return bgp_vty_return(vty, ret);
718e3744 3758}
3759
f26845f9
QY
3760DEFUN (bgp_default_shutdown,
3761 bgp_default_shutdown_cmd,
3762 "[no] bgp default shutdown",
3763 NO_STR
3764 BGP_STR
3765 "Configure BGP defaults\n"
b012cbe2 3766 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
3767{
3768 VTY_DECLVAR_CONTEXT(bgp, bgp);
3769 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
3770 return CMD_SUCCESS;
3771}
3772
736b68f3
DS
3773DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
3774 BGP_STR
9ddf4b81 3775 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
3776 "Add a shutdown message (RFC 8203)\n"
3777 "Shutdown message\n")
9cf59432 3778{
736b68f3 3779 char *msgstr = NULL;
8389c83a 3780
9cf59432
DS
3781 VTY_DECLVAR_CONTEXT(bgp, bgp);
3782
8389c83a 3783 if (argc > 3)
f80e35b6 3784 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
3785
3786 bgp_shutdown_enable(bgp, msgstr);
3787 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
3788
3789 return CMD_SUCCESS;
3790}
3791
736b68f3 3792DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 3793 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
3794{
3795 VTY_DECLVAR_CONTEXT(bgp, bgp);
3796
3797 bgp_shutdown_enable(bgp, NULL);
3798
3799 return CMD_SUCCESS;
3800}
8389c83a 3801
736b68f3 3802DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 3803 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
3804{
3805 VTY_DECLVAR_CONTEXT(bgp, bgp);
3806
3807 bgp_shutdown_disable(bgp);
3808
3809 return CMD_SUCCESS;
3810}
3811
9ddf4b81 3812ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 3813 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 3814 "Administrative shutdown of the BGP instance\n"
1b6e7a88 3815 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 3816
718e3744 3817DEFUN (neighbor_remote_as,
3818 neighbor_remote_as_cmd,
3a2d747c 3819 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 3820 NEIGHBOR_STR
3821 NEIGHBOR_ADDR_STR2
3822 "Specify a BGP neighbor\n"
d7fa34c1 3823 AS_STR
3a2d747c
QY
3824 "Internal BGP peer\n"
3825 "External BGP peer\n")
718e3744 3826{
d62a17ae 3827 int idx_peer = 1;
3828 int idx_remote_as = 3;
3829 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
3830 argv[idx_remote_as]->arg, AFI_IP,
3831 SAFI_UNICAST);
3832}
3833
3834static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
3835 afi_t afi, safi_t safi, int v6only,
3836 const char *peer_group_name,
3837 const char *as_str)
3838{
3839 VTY_DECLVAR_CONTEXT(bgp, bgp);
3840 as_t as = 0;
3841 int as_type = AS_UNSPECIFIED;
3842 struct peer *peer;
3843 struct peer_group *group;
3844 int ret = 0;
3845 union sockunion su;
3846
3847 group = peer_group_lookup(bgp, conf_if);
3848
3849 if (group) {
3850 vty_out(vty, "%% Name conflict with peer-group \n");
3851 return CMD_WARNING_CONFIG_FAILED;
3852 }
3853
3854 if (as_str) {
3855 if (as_str[0] == 'i') {
3856 as_type = AS_INTERNAL;
3857 } else if (as_str[0] == 'e') {
3858 as_type = AS_EXTERNAL;
3859 } else {
3860 /* Get AS number. */
3861 as = strtoul(as_str, NULL, 10);
3862 as_type = AS_SPECIFIED;
3863 }
3864 }
3865
3866 peer = peer_lookup_by_conf_if(bgp, conf_if);
3867 if (peer) {
3868 if (as_str)
cc4d4ce8 3869 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 3870 afi, safi);
3871 } else {
892fedb6 3872 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 3873 && afi == AFI_IP && safi == SAFI_UNICAST)
3874 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3875 as_type, 0, 0, NULL);
3876 else
3877 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3878 as_type, afi, safi, NULL);
3879
3880 if (!peer) {
3881 vty_out(vty, "%% BGP failed to create peer\n");
3882 return CMD_WARNING_CONFIG_FAILED;
3883 }
3884
3885 if (v6only)
527de3dc 3886 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3887
3888 /* Request zebra to initiate IPv6 RAs on this interface. We do
3889 * this
3890 * any unnumbered peer in order to not worry about run-time
3891 * transitions
3892 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3893 * address
3894 * gets deleted later etc.)
3895 */
3896 if (peer->ifp)
3897 bgp_zebra_initiate_radv(bgp, peer);
3898 }
3899
3900 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3901 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3902 if (v6only)
527de3dc 3903 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3904 else
527de3dc 3905 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3906
3907 /* v6only flag changed. Reset bgp seesion */
3908 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3909 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3910 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3911 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3912 } else
3913 bgp_session_reset(peer);
3914 }
3915
9fb964de
PM
3916 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3917 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3918 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 3919 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 3920 }
d62a17ae 3921
3922 if (peer_group_name) {
3923 group = peer_group_lookup(bgp, peer_group_name);
3924 if (!group) {
3925 vty_out(vty, "%% Configure the peer-group first\n");
3926 return CMD_WARNING_CONFIG_FAILED;
3927 }
3928
3929 ret = peer_group_bind(bgp, &su, peer, group, &as);
3930 }
3931
3932 return bgp_vty_return(vty, ret);
a80beece
DS
3933}
3934
4c48cf63
DW
3935DEFUN (neighbor_interface_config,
3936 neighbor_interface_config_cmd,
d7b9898c 3937 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
3938 NEIGHBOR_STR
3939 "Interface name or neighbor tag\n"
31500417
DW
3940 "Enable BGP on interface\n"
3941 "Member of the peer-group\n"
16cedbb0 3942 "Peer-group name\n")
4c48cf63 3943{
d62a17ae 3944 int idx_word = 1;
3945 int idx_peer_group_word = 4;
31500417 3946
d62a17ae 3947 if (argc > idx_peer_group_word)
3948 return peer_conf_interface_get(
3949 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3950 argv[idx_peer_group_word]->arg, NULL);
3951 else
3952 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3953 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3954}
3955
4c48cf63
DW
3956DEFUN (neighbor_interface_config_v6only,
3957 neighbor_interface_config_v6only_cmd,
d7b9898c 3958 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
3959 NEIGHBOR_STR
3960 "Interface name or neighbor tag\n"
3961 "Enable BGP on interface\n"
31500417
DW
3962 "Enable BGP with v6 link-local only\n"
3963 "Member of the peer-group\n"
16cedbb0 3964 "Peer-group name\n")
4c48cf63 3965{
d62a17ae 3966 int idx_word = 1;
3967 int idx_peer_group_word = 5;
31500417 3968
d62a17ae 3969 if (argc > idx_peer_group_word)
3970 return peer_conf_interface_get(
3971 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3972 argv[idx_peer_group_word]->arg, NULL);
31500417 3973
d62a17ae 3974 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3975 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3976}
3977
a80beece 3978
b3a39dc5
DD
3979DEFUN (neighbor_interface_config_remote_as,
3980 neighbor_interface_config_remote_as_cmd,
3a2d747c 3981 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3982 NEIGHBOR_STR
3983 "Interface name or neighbor tag\n"
3984 "Enable BGP on interface\n"
3a2d747c 3985 "Specify a BGP neighbor\n"
d7fa34c1 3986 AS_STR
3a2d747c
QY
3987 "Internal BGP peer\n"
3988 "External BGP peer\n")
b3a39dc5 3989{
d62a17ae 3990 int idx_word = 1;
3991 int idx_remote_as = 4;
3992 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3993 SAFI_UNICAST, 0, NULL,
3994 argv[idx_remote_as]->arg);
b3a39dc5
DD
3995}
3996
3997DEFUN (neighbor_interface_v6only_config_remote_as,
3998 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3999 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
4000 NEIGHBOR_STR
4001 "Interface name or neighbor tag\n"
3a2d747c 4002 "Enable BGP with v6 link-local only\n"
b3a39dc5 4003 "Enable BGP on interface\n"
3a2d747c 4004 "Specify a BGP neighbor\n"
d7fa34c1 4005 AS_STR
3a2d747c
QY
4006 "Internal BGP peer\n"
4007 "External BGP peer\n")
b3a39dc5 4008{
d62a17ae 4009 int idx_word = 1;
4010 int idx_remote_as = 5;
4011 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4012 SAFI_UNICAST, 1, NULL,
4013 argv[idx_remote_as]->arg);
b3a39dc5
DD
4014}
4015
718e3744 4016DEFUN (neighbor_peer_group,
4017 neighbor_peer_group_cmd,
4018 "neighbor WORD peer-group",
4019 NEIGHBOR_STR
a80beece 4020 "Interface name or neighbor tag\n"
718e3744 4021 "Configure peer-group\n")
4022{
d62a17ae 4023 VTY_DECLVAR_CONTEXT(bgp, bgp);
4024 int idx_word = 1;
4025 struct peer *peer;
4026 struct peer_group *group;
718e3744 4027
d62a17ae 4028 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4029 if (peer) {
4030 vty_out(vty, "%% Name conflict with interface: \n");
4031 return CMD_WARNING_CONFIG_FAILED;
4032 }
718e3744 4033
d62a17ae 4034 group = peer_group_get(bgp, argv[idx_word]->arg);
4035 if (!group) {
4036 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4037 return CMD_WARNING_CONFIG_FAILED;
4038 }
718e3744 4039
d62a17ae 4040 return CMD_SUCCESS;
718e3744 4041}
4042
4043DEFUN (no_neighbor,
4044 no_neighbor_cmd,
dab8cd00 4045 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 4046 NO_STR
4047 NEIGHBOR_STR
3a2d747c
QY
4048 NEIGHBOR_ADDR_STR2
4049 "Specify a BGP neighbor\n"
4050 AS_STR
4051 "Internal BGP peer\n"
4052 "External BGP peer\n")
718e3744 4053{
d62a17ae 4054 VTY_DECLVAR_CONTEXT(bgp, bgp);
4055 int idx_peer = 2;
4056 int ret;
4057 union sockunion su;
4058 struct peer_group *group;
4059 struct peer *peer;
4060 struct peer *other;
4061
4062 ret = str2sockunion(argv[idx_peer]->arg, &su);
4063 if (ret < 0) {
4064 /* look up for neighbor by interface name config. */
4065 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4066 if (peer) {
4067 /* Request zebra to terminate IPv6 RAs on this
4068 * interface. */
4069 if (peer->ifp)
4070 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 4071 peer_notify_unconfig(peer);
d62a17ae 4072 peer_delete(peer);
4073 return CMD_SUCCESS;
4074 }
f14e6fdb 4075
d62a17ae 4076 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4e2786df
DA
4077 if (group) {
4078 peer_group_notify_unconfig(group);
d62a17ae 4079 peer_group_delete(group);
4e2786df 4080 } else {
d62a17ae 4081 vty_out(vty, "%% Create the peer-group first\n");
4082 return CMD_WARNING_CONFIG_FAILED;
4083 }
4084 } else {
4085 peer = peer_lookup(bgp, &su);
4086 if (peer) {
4087 if (peer_dynamic_neighbor(peer)) {
4088 vty_out(vty,
4089 "%% Operation not allowed on a dynamic neighbor\n");
4090 return CMD_WARNING_CONFIG_FAILED;
4091 }
4092
4093 other = peer->doppelganger;
b3a3290e
DS
4094
4095 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4096 bgp_zebra_terminate_radv(peer->bgp, peer);
4097
4e2786df 4098 peer_notify_unconfig(peer);
d62a17ae 4099 peer_delete(peer);
4e2786df
DA
4100 if (other && other->status != Deleted) {
4101 peer_notify_unconfig(other);
d62a17ae 4102 peer_delete(other);
4e2786df 4103 }
d62a17ae 4104 }
1ff9a340 4105 }
718e3744 4106
d62a17ae 4107 return CMD_SUCCESS;
718e3744 4108}
4109
a80beece
DS
4110DEFUN (no_neighbor_interface_config,
4111 no_neighbor_interface_config_cmd,
d7b9898c 4112 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
4113 NO_STR
4114 NEIGHBOR_STR
4115 "Interface name\n"
31500417
DW
4116 "Configure BGP on interface\n"
4117 "Enable BGP with v6 link-local only\n"
4118 "Member of the peer-group\n"
16cedbb0 4119 "Peer-group name\n"
3a2d747c
QY
4120 "Specify a BGP neighbor\n"
4121 AS_STR
4122 "Internal BGP peer\n"
4123 "External BGP peer\n")
a80beece 4124{
d62a17ae 4125 VTY_DECLVAR_CONTEXT(bgp, bgp);
4126 int idx_word = 2;
4127 struct peer *peer;
4128
4129 /* look up for neighbor by interface name config. */
4130 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4131 if (peer) {
4132 /* Request zebra to terminate IPv6 RAs on this interface. */
4133 if (peer->ifp)
4134 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 4135 peer_notify_unconfig(peer);
d62a17ae 4136 peer_delete(peer);
4137 } else {
4138 vty_out(vty, "%% Create the bgp interface first\n");
4139 return CMD_WARNING_CONFIG_FAILED;
4140 }
4141 return CMD_SUCCESS;
a80beece
DS
4142}
4143
718e3744 4144DEFUN (no_neighbor_peer_group,
4145 no_neighbor_peer_group_cmd,
4146 "no neighbor WORD peer-group",
4147 NO_STR
4148 NEIGHBOR_STR
4149 "Neighbor tag\n"
4150 "Configure peer-group\n")
4151{
d62a17ae 4152 VTY_DECLVAR_CONTEXT(bgp, bgp);
4153 int idx_word = 2;
4154 struct peer_group *group;
718e3744 4155
d62a17ae 4156 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4e2786df
DA
4157 if (group) {
4158 peer_group_notify_unconfig(group);
d62a17ae 4159 peer_group_delete(group);
4e2786df 4160 } else {
d62a17ae 4161 vty_out(vty, "%% Create the peer-group first\n");
4162 return CMD_WARNING_CONFIG_FAILED;
4163 }
4164 return CMD_SUCCESS;
718e3744 4165}
4166
a80beece
DS
4167DEFUN (no_neighbor_interface_peer_group_remote_as,
4168 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 4169 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 4170 NO_STR
4171 NEIGHBOR_STR
a80beece 4172 "Interface name or neighbor tag\n"
718e3744 4173 "Specify a BGP neighbor\n"
3a2d747c
QY
4174 AS_STR
4175 "Internal BGP peer\n"
4176 "External BGP peer\n")
718e3744 4177{
d62a17ae 4178 VTY_DECLVAR_CONTEXT(bgp, bgp);
4179 int idx_word = 2;
4180 struct peer_group *group;
4181 struct peer *peer;
4182
4183 /* look up for neighbor by interface name config. */
4184 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4185 if (peer) {
390485fd 4186 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 4187 return CMD_SUCCESS;
4188 }
4189
4190 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4191 if (group)
4192 peer_group_remote_as_delete(group);
4193 else {
4194 vty_out(vty, "%% Create the peer-group or interface first\n");
4195 return CMD_WARNING_CONFIG_FAILED;
4196 }
4197 return CMD_SUCCESS;
718e3744 4198}
6b0655a2 4199
718e3744 4200DEFUN (neighbor_local_as,
4201 neighbor_local_as_cmd,
9ccf14f7 4202 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 4203 NEIGHBOR_STR
4204 NEIGHBOR_ADDR_STR2
4205 "Specify a local-as number\n"
4206 "AS number used as local AS\n")
4207{
d62a17ae 4208 int idx_peer = 1;
4209 int idx_number = 3;
4210 struct peer *peer;
4211 int ret;
4212 as_t as;
718e3744 4213
d62a17ae 4214 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4215 if (!peer)
4216 return CMD_WARNING_CONFIG_FAILED;
718e3744 4217
d62a17ae 4218 as = strtoul(argv[idx_number]->arg, NULL, 10);
4219 ret = peer_local_as_set(peer, as, 0, 0);
4220 return bgp_vty_return(vty, ret);
718e3744 4221}
4222
4223DEFUN (neighbor_local_as_no_prepend,
4224 neighbor_local_as_no_prepend_cmd,
9ccf14f7 4225 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 4226 NEIGHBOR_STR
4227 NEIGHBOR_ADDR_STR2
4228 "Specify a local-as number\n"
4229 "AS number used as local AS\n"
4230 "Do not prepend local-as to updates from ebgp peers\n")
4231{
d62a17ae 4232 int idx_peer = 1;
4233 int idx_number = 3;
4234 struct peer *peer;
4235 int ret;
4236 as_t as;
718e3744 4237
d62a17ae 4238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4239 if (!peer)
4240 return CMD_WARNING_CONFIG_FAILED;
718e3744 4241
d62a17ae 4242 as = strtoul(argv[idx_number]->arg, NULL, 10);
4243 ret = peer_local_as_set(peer, as, 1, 0);
4244 return bgp_vty_return(vty, ret);
718e3744 4245}
4246
9d3f9705
AC
4247DEFUN (neighbor_local_as_no_prepend_replace_as,
4248 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 4249 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
4250 NEIGHBOR_STR
4251 NEIGHBOR_ADDR_STR2
4252 "Specify a local-as number\n"
4253 "AS number used as local AS\n"
4254 "Do not prepend local-as to updates from ebgp peers\n"
4255 "Do not prepend local-as to updates from ibgp peers\n")
4256{
d62a17ae 4257 int idx_peer = 1;
4258 int idx_number = 3;
4259 struct peer *peer;
4260 int ret;
4261 as_t as;
9d3f9705 4262
d62a17ae 4263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4264 if (!peer)
4265 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4266
d62a17ae 4267 as = strtoul(argv[idx_number]->arg, NULL, 10);
4268 ret = peer_local_as_set(peer, as, 1, 1);
4269 return bgp_vty_return(vty, ret);
9d3f9705
AC
4270}
4271
718e3744 4272DEFUN (no_neighbor_local_as,
4273 no_neighbor_local_as_cmd,
a636c635 4274 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 4275 NO_STR
4276 NEIGHBOR_STR
4277 NEIGHBOR_ADDR_STR2
a636c635
DW
4278 "Specify a local-as number\n"
4279 "AS number used as local AS\n"
4280 "Do not prepend local-as to updates from ebgp peers\n"
4281 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4282{
d62a17ae 4283 int idx_peer = 2;
4284 struct peer *peer;
4285 int ret;
718e3744 4286
d62a17ae 4287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4288 if (!peer)
4289 return CMD_WARNING_CONFIG_FAILED;
718e3744 4290
d62a17ae 4291 ret = peer_local_as_unset(peer);
4292 return bgp_vty_return(vty, ret);
718e3744 4293}
4294
718e3744 4295
3f9c7369
DS
4296DEFUN (neighbor_solo,
4297 neighbor_solo_cmd,
9ccf14f7 4298 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4299 NEIGHBOR_STR
4300 NEIGHBOR_ADDR_STR2
4301 "Solo peer - part of its own update group\n")
4302{
d62a17ae 4303 int idx_peer = 1;
4304 struct peer *peer;
4305 int ret;
3f9c7369 4306
d62a17ae 4307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4308 if (!peer)
4309 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4310
d62a17ae 4311 ret = update_group_adjust_soloness(peer, 1);
4312 return bgp_vty_return(vty, ret);
3f9c7369
DS
4313}
4314
4315DEFUN (no_neighbor_solo,
4316 no_neighbor_solo_cmd,
9ccf14f7 4317 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4318 NO_STR
4319 NEIGHBOR_STR
4320 NEIGHBOR_ADDR_STR2
4321 "Solo peer - part of its own update group\n")
4322{
d62a17ae 4323 int idx_peer = 2;
4324 struct peer *peer;
4325 int ret;
3f9c7369 4326
d62a17ae 4327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4328 if (!peer)
4329 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4330
d62a17ae 4331 ret = update_group_adjust_soloness(peer, 0);
4332 return bgp_vty_return(vty, ret);
3f9c7369
DS
4333}
4334
0df7c91f
PJ
4335DEFUN (neighbor_password,
4336 neighbor_password_cmd,
9ccf14f7 4337 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
4338 NEIGHBOR_STR
4339 NEIGHBOR_ADDR_STR2
4340 "Set a password\n"
4341 "The password\n")
4342{
d62a17ae 4343 int idx_peer = 1;
4344 int idx_line = 3;
4345 struct peer *peer;
4346 int ret;
0df7c91f 4347
d62a17ae 4348 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4349 if (!peer)
4350 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4351
d62a17ae 4352 ret = peer_password_set(peer, argv[idx_line]->arg);
4353 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4354}
4355
4356DEFUN (no_neighbor_password,
4357 no_neighbor_password_cmd,
a636c635 4358 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
4359 NO_STR
4360 NEIGHBOR_STR
4361 NEIGHBOR_ADDR_STR2
16cedbb0
QY
4362 "Set a password\n"
4363 "The password\n")
0df7c91f 4364{
d62a17ae 4365 int idx_peer = 2;
4366 struct peer *peer;
4367 int ret;
0df7c91f 4368
d62a17ae 4369 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4370 if (!peer)
4371 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4372
d62a17ae 4373 ret = peer_password_unset(peer);
4374 return bgp_vty_return(vty, ret);
0df7c91f 4375}
6b0655a2 4376
718e3744 4377DEFUN (neighbor_activate,
4378 neighbor_activate_cmd,
9ccf14f7 4379 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4380 NEIGHBOR_STR
4381 NEIGHBOR_ADDR_STR2
4382 "Enable the Address Family for this Neighbor\n")
4383{
d62a17ae 4384 int idx_peer = 1;
4385 int ret;
4386 struct peer *peer;
718e3744 4387
d62a17ae 4388 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4389 if (!peer)
4390 return CMD_WARNING_CONFIG_FAILED;
718e3744 4391
d62a17ae 4392 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4393 return bgp_vty_return(vty, ret);
718e3744 4394}
4395
d62a17ae 4396ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4397 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4398 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4399 "Enable the Address Family for this Neighbor\n")
596c17ba 4400
718e3744 4401DEFUN (no_neighbor_activate,
4402 no_neighbor_activate_cmd,
9ccf14f7 4403 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4404 NO_STR
4405 NEIGHBOR_STR
4406 NEIGHBOR_ADDR_STR2
4407 "Enable the Address Family for this Neighbor\n")
4408{
d62a17ae 4409 int idx_peer = 2;
4410 int ret;
4411 struct peer *peer;
718e3744 4412
d62a17ae 4413 /* Lookup peer. */
4414 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4415 if (!peer)
4416 return CMD_WARNING_CONFIG_FAILED;
718e3744 4417
d62a17ae 4418 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4419 return bgp_vty_return(vty, ret);
718e3744 4420}
6b0655a2 4421
d62a17ae 4422ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4423 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4424 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4425 "Enable the Address Family for this Neighbor\n")
596c17ba 4426
718e3744 4427DEFUN (neighbor_set_peer_group,
4428 neighbor_set_peer_group_cmd,
d7b9898c 4429 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4430 NEIGHBOR_STR
a80beece 4431 NEIGHBOR_ADDR_STR2
718e3744 4432 "Member of the peer-group\n"
16cedbb0 4433 "Peer-group name\n")
718e3744 4434{
d62a17ae 4435 VTY_DECLVAR_CONTEXT(bgp, bgp);
4436 int idx_peer = 1;
4437 int idx_word = 3;
4438 int ret;
4439 as_t as;
4440 union sockunion su;
4441 struct peer *peer;
4442 struct peer_group *group;
4443
d62a17ae 4444 ret = str2sockunion(argv[idx_peer]->arg, &su);
4445 if (ret < 0) {
4446 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4447 if (!peer) {
4448 vty_out(vty, "%% Malformed address or name: %s\n",
4449 argv[idx_peer]->arg);
4450 return CMD_WARNING_CONFIG_FAILED;
4451 }
4452 } else {
4453 if (peer_address_self_check(bgp, &su)) {
4454 vty_out(vty,
4455 "%% Can not configure the local system as neighbor\n");
4456 return CMD_WARNING_CONFIG_FAILED;
4457 }
4458
4459 /* Disallow for dynamic neighbor. */
4460 peer = peer_lookup(bgp, &su);
4461 if (peer && peer_dynamic_neighbor(peer)) {
4462 vty_out(vty,
4463 "%% Operation not allowed on a dynamic neighbor\n");
4464 return CMD_WARNING_CONFIG_FAILED;
4465 }
4466 }
4467
4468 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4469 if (!group) {
4470 vty_out(vty, "%% Configure the peer-group first\n");
4471 return CMD_WARNING_CONFIG_FAILED;
4472 }
4473
4474 ret = peer_group_bind(bgp, &su, peer, group, &as);
4475
4476 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4477 vty_out(vty,
4478 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4479 as);
4480 return CMD_WARNING_CONFIG_FAILED;
4481 }
4482
4483 return bgp_vty_return(vty, ret);
4484}
4485
4486ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4487 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4488 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4489 "Member of the peer-group\n"
4490 "Peer-group name\n")
596c17ba 4491
718e3744 4492DEFUN (no_neighbor_set_peer_group,
4493 no_neighbor_set_peer_group_cmd,
d7b9898c 4494 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4495 NO_STR
4496 NEIGHBOR_STR
a80beece 4497 NEIGHBOR_ADDR_STR2
718e3744 4498 "Member of the peer-group\n"
16cedbb0 4499 "Peer-group name\n")
718e3744 4500{
d62a17ae 4501 VTY_DECLVAR_CONTEXT(bgp, bgp);
4502 int idx_peer = 2;
4503 int idx_word = 4;
4504 int ret;
4505 struct peer *peer;
4506 struct peer_group *group;
4507
4508 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4509 if (!peer)
4510 return CMD_WARNING_CONFIG_FAILED;
4511
4512 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4513 if (!group) {
4514 vty_out(vty, "%% Configure the peer-group first\n");
4515 return CMD_WARNING_CONFIG_FAILED;
4516 }
718e3744 4517
b3a3290e
DS
4518 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4519 bgp_zebra_terminate_radv(peer->bgp, peer);
4520
4e2786df 4521 peer_notify_unconfig(peer);
827ed707 4522 ret = peer_delete(peer);
718e3744 4523
d62a17ae 4524 return bgp_vty_return(vty, ret);
718e3744 4525}
6b0655a2 4526
d62a17ae 4527ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4528 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4529 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4530 "Member of the peer-group\n"
4531 "Peer-group name\n")
596c17ba 4532
d62a17ae 4533static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4534 uint32_t flag, int set)
718e3744 4535{
d62a17ae 4536 int ret;
4537 struct peer *peer;
718e3744 4538
d62a17ae 4539 peer = peer_and_group_lookup_vty(vty, ip_str);
4540 if (!peer)
4541 return CMD_WARNING_CONFIG_FAILED;
718e3744 4542
7ebe625c
QY
4543 /*
4544 * If 'neighbor <interface>', then this is for directly connected peers,
4545 * we should not accept disable-connected-check.
4546 */
4547 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4548 vty_out(vty,
3efd0893 4549 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
4550 ip_str);
4551 return CMD_WARNING_CONFIG_FAILED;
4552 }
4553
d62a17ae 4554 if (!set && flag == PEER_FLAG_SHUTDOWN)
4555 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4556
d62a17ae 4557 if (set)
4558 ret = peer_flag_set(peer, flag);
4559 else
4560 ret = peer_flag_unset(peer, flag);
718e3744 4561
d62a17ae 4562 return bgp_vty_return(vty, ret);
718e3744 4563}
4564
47cbc09b 4565static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4566{
d62a17ae 4567 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4568}
4569
d62a17ae 4570static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4571 uint32_t flag)
718e3744 4572{
d62a17ae 4573 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4574}
4575
4576/* neighbor passive. */
4577DEFUN (neighbor_passive,
4578 neighbor_passive_cmd,
9ccf14f7 4579 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4580 NEIGHBOR_STR
4581 NEIGHBOR_ADDR_STR2
4582 "Don't send open messages to this neighbor\n")
4583{
d62a17ae 4584 int idx_peer = 1;
4585 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4586}
4587
4588DEFUN (no_neighbor_passive,
4589 no_neighbor_passive_cmd,
9ccf14f7 4590 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4591 NO_STR
4592 NEIGHBOR_STR
4593 NEIGHBOR_ADDR_STR2
4594 "Don't send open messages to this neighbor\n")
4595{
d62a17ae 4596 int idx_peer = 2;
4597 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4598}
6b0655a2 4599
718e3744 4600/* neighbor shutdown. */
73d70fa6
DL
4601DEFUN (neighbor_shutdown_msg,
4602 neighbor_shutdown_msg_cmd,
4603 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 4604 NEIGHBOR_STR
4605 NEIGHBOR_ADDR_STR2
73d70fa6 4606 "Administratively shut down this neighbor\n"
70335e0a 4607 "Add a shutdown message (RFC 8203)\n"
73d70fa6 4608 "Shutdown message\n")
718e3744 4609{
d62a17ae 4610 int idx_peer = 1;
73d70fa6 4611
d62a17ae 4612 if (argc >= 5) {
4613 struct peer *peer =
4614 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4615 char *message;
73d70fa6 4616
d62a17ae 4617 if (!peer)
4618 return CMD_WARNING_CONFIG_FAILED;
4619 message = argv_concat(argv, argc, 4);
4620 peer_tx_shutdown_message_set(peer, message);
4621 XFREE(MTYPE_TMP, message);
4622 }
73d70fa6 4623
d62a17ae 4624 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 4625}
4626
d62a17ae 4627ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4628 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4629 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4630 "Administratively shut down this neighbor\n")
73d70fa6
DL
4631
4632DEFUN (no_neighbor_shutdown_msg,
4633 no_neighbor_shutdown_msg_cmd,
4634 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4635 NO_STR
4636 NEIGHBOR_STR
4637 NEIGHBOR_ADDR_STR2
4638 "Administratively shut down this neighbor\n"
70335e0a 4639 "Remove a shutdown message (RFC 8203)\n"
73d70fa6 4640 "Shutdown message\n")
718e3744 4641{
d62a17ae 4642 int idx_peer = 2;
73d70fa6 4643
d62a17ae 4644 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4645 PEER_FLAG_SHUTDOWN);
718e3744 4646}
6b0655a2 4647
d62a17ae 4648ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4649 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4650 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4651 "Administratively shut down this neighbor\n")
73d70fa6 4652
8336c896
DA
4653DEFUN(neighbor_shutdown_rtt,
4654 neighbor_shutdown_rtt_cmd,
4655 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
4656 NEIGHBOR_STR
4657 NEIGHBOR_ADDR_STR2
4658 "Administratively shut down this neighbor\n"
4659 "Shutdown if round-trip-time is higher than expected\n"
4660 "Round-trip-time in milliseconds\n"
4661 "Specify the number of keepalives before shutdown\n"
4662 "The number of keepalives with higher RTT to shutdown\n")
4663{
4664 int idx_peer = 1;
4665 int idx_rtt = 4;
4666 int idx_count = 0;
4667 struct peer *peer;
4668
4669 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4670
4671 if (!peer)
4672 return CMD_WARNING_CONFIG_FAILED;
4673
4674 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
4675
4676 if (argv_find(argv, argc, "count", &idx_count))
4677 peer->rtt_keepalive_conf =
4678 strtol(argv[idx_count + 1]->arg, NULL, 10);
4679
4680 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4681 PEER_FLAG_RTT_SHUTDOWN);
4682}
4683
4684DEFUN(no_neighbor_shutdown_rtt,
4685 no_neighbor_shutdown_rtt_cmd,
4686 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
4687 NO_STR
4688 NEIGHBOR_STR
4689 NEIGHBOR_ADDR_STR2
4690 "Administratively shut down this neighbor\n"
4691 "Shutdown if round-trip-time is higher than expected\n"
4692 "Round-trip-time in milliseconds\n"
4693 "Specify the number of keepalives before shutdown\n"
4694 "The number of keepalives with higher RTT to shutdown\n")
4695{
4696 int idx_peer = 2;
4697 struct peer *peer;
4698
4699 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4700
4701 if (!peer)
4702 return CMD_WARNING_CONFIG_FAILED;
4703
4704 peer->rtt_expected = 0;
4705 peer->rtt_keepalive_conf = 1;
4706
4707 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4708 PEER_FLAG_RTT_SHUTDOWN);
4709}
4710
718e3744 4711/* neighbor capability dynamic. */
4712DEFUN (neighbor_capability_dynamic,
4713 neighbor_capability_dynamic_cmd,
9ccf14f7 4714 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4715 NEIGHBOR_STR
4716 NEIGHBOR_ADDR_STR2
4717 "Advertise capability to the peer\n"
4718 "Advertise dynamic capability to this neighbor\n")
4719{
d62a17ae 4720 int idx_peer = 1;
4721 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4722 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4723}
4724
4725DEFUN (no_neighbor_capability_dynamic,
4726 no_neighbor_capability_dynamic_cmd,
9ccf14f7 4727 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4728 NO_STR
4729 NEIGHBOR_STR
4730 NEIGHBOR_ADDR_STR2
4731 "Advertise capability to the peer\n"
4732 "Advertise dynamic capability to this neighbor\n")
4733{
d62a17ae 4734 int idx_peer = 2;
4735 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4736 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4737}
6b0655a2 4738
718e3744 4739/* neighbor dont-capability-negotiate */
4740DEFUN (neighbor_dont_capability_negotiate,
4741 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4742 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4743 NEIGHBOR_STR
4744 NEIGHBOR_ADDR_STR2
4745 "Do not perform capability negotiation\n")
4746{
d62a17ae 4747 int idx_peer = 1;
4748 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4749 PEER_FLAG_DONT_CAPABILITY);
718e3744 4750}
4751
4752DEFUN (no_neighbor_dont_capability_negotiate,
4753 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4754 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4755 NO_STR
4756 NEIGHBOR_STR
4757 NEIGHBOR_ADDR_STR2
4758 "Do not perform capability negotiation\n")
4759{
d62a17ae 4760 int idx_peer = 2;
4761 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4762 PEER_FLAG_DONT_CAPABILITY);
718e3744 4763}
6b0655a2 4764
8a92a8a0
DS
4765/* neighbor capability extended next hop encoding */
4766DEFUN (neighbor_capability_enhe,
4767 neighbor_capability_enhe_cmd,
9ccf14f7 4768 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4769 NEIGHBOR_STR
4770 NEIGHBOR_ADDR_STR2
4771 "Advertise capability to the peer\n"
4772 "Advertise extended next-hop capability to the peer\n")
4773{
d62a17ae 4774 int idx_peer = 1;
4775 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4776 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4777}
4778
4779DEFUN (no_neighbor_capability_enhe,
4780 no_neighbor_capability_enhe_cmd,
9ccf14f7 4781 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4782 NO_STR
4783 NEIGHBOR_STR
4784 NEIGHBOR_ADDR_STR2
4785 "Advertise capability to the peer\n"
4786 "Advertise extended next-hop capability to the peer\n")
4787{
d62a17ae 4788 int idx_peer = 2;
4789 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4790 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4791}
4792
d62a17ae 4793static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4794 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 4795 int set)
718e3744 4796{
d62a17ae 4797 int ret;
4798 struct peer *peer;
718e3744 4799
d62a17ae 4800 peer = peer_and_group_lookup_vty(vty, peer_str);
4801 if (!peer)
4802 return CMD_WARNING_CONFIG_FAILED;
718e3744 4803
d62a17ae 4804 if (set)
4805 ret = peer_af_flag_set(peer, afi, safi, flag);
4806 else
4807 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 4808
d62a17ae 4809 return bgp_vty_return(vty, ret);
718e3744 4810}
4811
d62a17ae 4812static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4813 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4814{
d62a17ae 4815 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 4816}
4817
d62a17ae 4818static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4819 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4820{
d62a17ae 4821 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 4822}
6b0655a2 4823
718e3744 4824/* neighbor capability orf prefix-list. */
4825DEFUN (neighbor_capability_orf_prefix,
4826 neighbor_capability_orf_prefix_cmd,
9ccf14f7 4827 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4828 NEIGHBOR_STR
4829 NEIGHBOR_ADDR_STR2
4830 "Advertise capability to the peer\n"
4831 "Advertise ORF capability to the peer\n"
4832 "Advertise prefixlist ORF capability to this neighbor\n"
4833 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4834 "Capability to RECEIVE the ORF from this neighbor\n"
4835 "Capability to SEND the ORF to this neighbor\n")
4836{
d62a17ae 4837 int idx_send_recv = 5;
db45f64d
DS
4838 char *peer_str = argv[1]->arg;
4839 struct peer *peer;
4840 afi_t afi = bgp_node_afi(vty);
4841 safi_t safi = bgp_node_safi(vty);
d62a17ae 4842
db45f64d
DS
4843 peer = peer_and_group_lookup_vty(vty, peer_str);
4844 if (!peer)
d62a17ae 4845 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4846
db45f64d
DS
4847 if (strmatch(argv[idx_send_recv]->text, "send"))
4848 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
4849 PEER_FLAG_ORF_PREFIX_SM);
4850
4851 if (strmatch(argv[idx_send_recv]->text, "receive"))
4852 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
4853 PEER_FLAG_ORF_PREFIX_RM);
4854
4855 if (strmatch(argv[idx_send_recv]->text, "both"))
4856 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
4857 PEER_FLAG_ORF_PREFIX_SM)
4858 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
4859 PEER_FLAG_ORF_PREFIX_RM);
4860
4861 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4862}
4863
4864ALIAS_HIDDEN(
4865 neighbor_capability_orf_prefix,
4866 neighbor_capability_orf_prefix_hidden_cmd,
4867 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4868 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4869 "Advertise capability to the peer\n"
4870 "Advertise ORF capability to the peer\n"
4871 "Advertise prefixlist ORF capability to this neighbor\n"
4872 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4873 "Capability to RECEIVE the ORF from this neighbor\n"
4874 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4875
718e3744 4876DEFUN (no_neighbor_capability_orf_prefix,
4877 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 4878 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4879 NO_STR
4880 NEIGHBOR_STR
4881 NEIGHBOR_ADDR_STR2
4882 "Advertise capability to the peer\n"
4883 "Advertise ORF capability to the peer\n"
4884 "Advertise prefixlist ORF capability to this neighbor\n"
4885 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4886 "Capability to RECEIVE the ORF from this neighbor\n"
4887 "Capability to SEND the ORF to this neighbor\n")
4888{
d62a17ae 4889 int idx_send_recv = 6;
db45f64d
DS
4890 char *peer_str = argv[2]->arg;
4891 struct peer *peer;
4892 afi_t afi = bgp_node_afi(vty);
4893 safi_t safi = bgp_node_safi(vty);
d62a17ae 4894
db45f64d
DS
4895 peer = peer_and_group_lookup_vty(vty, peer_str);
4896 if (!peer)
d62a17ae 4897 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4898
db45f64d
DS
4899 if (strmatch(argv[idx_send_recv]->text, "send"))
4900 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4901 PEER_FLAG_ORF_PREFIX_SM);
4902
4903 if (strmatch(argv[idx_send_recv]->text, "receive"))
4904 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4905 PEER_FLAG_ORF_PREFIX_RM);
4906
4907 if (strmatch(argv[idx_send_recv]->text, "both"))
4908 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4909 PEER_FLAG_ORF_PREFIX_SM)
4910 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4911 PEER_FLAG_ORF_PREFIX_RM);
4912
4913 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4914}
4915
4916ALIAS_HIDDEN(
4917 no_neighbor_capability_orf_prefix,
4918 no_neighbor_capability_orf_prefix_hidden_cmd,
4919 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4920 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4921 "Advertise capability to the peer\n"
4922 "Advertise ORF capability to the peer\n"
4923 "Advertise prefixlist ORF capability to this neighbor\n"
4924 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4925 "Capability to RECEIVE the ORF from this neighbor\n"
4926 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4927
718e3744 4928/* neighbor next-hop-self. */
4929DEFUN (neighbor_nexthop_self,
4930 neighbor_nexthop_self_cmd,
9ccf14f7 4931 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4932 NEIGHBOR_STR
4933 NEIGHBOR_ADDR_STR2
a538debe 4934 "Disable the next hop calculation for this neighbor\n")
718e3744 4935{
d62a17ae 4936 int idx_peer = 1;
4937 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4938 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 4939}
9e7a53c1 4940
d62a17ae 4941ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
4942 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4943 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4944 "Disable the next hop calculation for this neighbor\n")
596c17ba 4945
a538debe
DS
4946/* neighbor next-hop-self. */
4947DEFUN (neighbor_nexthop_self_force,
4948 neighbor_nexthop_self_force_cmd,
9ccf14f7 4949 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4950 NEIGHBOR_STR
4951 NEIGHBOR_ADDR_STR2
4952 "Disable the next hop calculation for this neighbor\n"
4953 "Set the next hop to self for reflected routes\n")
4954{
d62a17ae 4955 int idx_peer = 1;
4956 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4957 bgp_node_safi(vty),
4958 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 4959}
4960
d62a17ae 4961ALIAS_HIDDEN(neighbor_nexthop_self_force,
4962 neighbor_nexthop_self_force_hidden_cmd,
4963 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4964 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4965 "Disable the next hop calculation for this neighbor\n"
4966 "Set the next hop to self for reflected routes\n")
596c17ba 4967
1bc4e531
DA
4968ALIAS_HIDDEN(neighbor_nexthop_self_force,
4969 neighbor_nexthop_self_all_hidden_cmd,
4970 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4971 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4972 "Disable the next hop calculation for this neighbor\n"
4973 "Set the next hop to self for reflected routes\n")
4974
718e3744 4975DEFUN (no_neighbor_nexthop_self,
4976 no_neighbor_nexthop_self_cmd,
9ccf14f7 4977 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4978 NO_STR
4979 NEIGHBOR_STR
4980 NEIGHBOR_ADDR_STR2
a538debe 4981 "Disable the next hop calculation for this neighbor\n")
718e3744 4982{
d62a17ae 4983 int idx_peer = 2;
4984 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4985 bgp_node_afi(vty), bgp_node_safi(vty),
4986 PEER_FLAG_NEXTHOP_SELF);
718e3744 4987}
6b0655a2 4988
d62a17ae 4989ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4990 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4991 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4992 "Disable the next hop calculation for this neighbor\n")
596c17ba 4993
88b8ed8d 4994DEFUN (no_neighbor_nexthop_self_force,
a538debe 4995 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 4996 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4997 NO_STR
4998 NEIGHBOR_STR
4999 NEIGHBOR_ADDR_STR2
5000 "Disable the next hop calculation for this neighbor\n"
5001 "Set the next hop to self for reflected routes\n")
88b8ed8d 5002{
d62a17ae 5003 int idx_peer = 2;
5004 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5005 bgp_node_afi(vty), bgp_node_safi(vty),
5006 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5007}
a538debe 5008
d62a17ae 5009ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5010 no_neighbor_nexthop_self_force_hidden_cmd,
5011 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5012 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5013 "Disable the next hop calculation for this neighbor\n"
5014 "Set the next hop to self for reflected routes\n")
596c17ba 5015
1bc4e531
DA
5016ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5017 no_neighbor_nexthop_self_all_hidden_cmd,
5018 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5019 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5020 "Disable the next hop calculation for this neighbor\n"
5021 "Set the next hop to self for reflected routes\n")
5022
c7122e14
DS
5023/* neighbor as-override */
5024DEFUN (neighbor_as_override,
5025 neighbor_as_override_cmd,
9ccf14f7 5026 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
5027 NEIGHBOR_STR
5028 NEIGHBOR_ADDR_STR2
5029 "Override ASNs in outbound updates if aspath equals remote-as\n")
5030{
d62a17ae 5031 int idx_peer = 1;
5032 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5033 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5034}
5035
d62a17ae 5036ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5037 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5038 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5039 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5040
c7122e14
DS
5041DEFUN (no_neighbor_as_override,
5042 no_neighbor_as_override_cmd,
9ccf14f7 5043 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
5044 NO_STR
5045 NEIGHBOR_STR
5046 NEIGHBOR_ADDR_STR2
5047 "Override ASNs in outbound updates if aspath equals remote-as\n")
5048{
d62a17ae 5049 int idx_peer = 2;
5050 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5051 bgp_node_afi(vty), bgp_node_safi(vty),
5052 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5053}
5054
d62a17ae 5055ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5056 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5057 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5058 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5059
718e3744 5060/* neighbor remove-private-AS. */
5061DEFUN (neighbor_remove_private_as,
5062 neighbor_remove_private_as_cmd,
9ccf14f7 5063 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 5064 NEIGHBOR_STR
5065 NEIGHBOR_ADDR_STR2
5000f21c 5066 "Remove private ASNs in outbound updates\n")
718e3744 5067{
d62a17ae 5068 int idx_peer = 1;
5069 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5070 bgp_node_safi(vty),
5071 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5072}
5073
d62a17ae 5074ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5075 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5076 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5077 "Remove private ASNs in outbound updates\n")
596c17ba 5078
5000f21c
DS
5079DEFUN (neighbor_remove_private_as_all,
5080 neighbor_remove_private_as_all_cmd,
9ccf14f7 5081 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
5082 NEIGHBOR_STR
5083 NEIGHBOR_ADDR_STR2
5084 "Remove private ASNs in outbound updates\n"
efd7904e 5085 "Apply to all AS numbers\n")
5000f21c 5086{
d62a17ae 5087 int idx_peer = 1;
5088 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5089 bgp_node_safi(vty),
5090 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5091}
5092
d62a17ae 5093ALIAS_HIDDEN(neighbor_remove_private_as_all,
5094 neighbor_remove_private_as_all_hidden_cmd,
5095 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5096 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5097 "Remove private ASNs in outbound updates\n"
5098 "Apply to all AS numbers")
596c17ba 5099
5000f21c
DS
5100DEFUN (neighbor_remove_private_as_replace_as,
5101 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 5102 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
5103 NEIGHBOR_STR
5104 NEIGHBOR_ADDR_STR2
5105 "Remove private ASNs in outbound updates\n"
5106 "Replace private ASNs with our ASN in outbound updates\n")
5107{
d62a17ae 5108 int idx_peer = 1;
5109 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5110 bgp_node_safi(vty),
5111 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5112}
5113
d62a17ae 5114ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5115 neighbor_remove_private_as_replace_as_hidden_cmd,
5116 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5117 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5118 "Remove private ASNs in outbound updates\n"
5119 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5120
5000f21c
DS
5121DEFUN (neighbor_remove_private_as_all_replace_as,
5122 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 5123 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
5124 NEIGHBOR_STR
5125 NEIGHBOR_ADDR_STR2
5126 "Remove private ASNs in outbound updates\n"
16cedbb0 5127 "Apply to all AS numbers\n"
5000f21c
DS
5128 "Replace private ASNs with our ASN in outbound updates\n")
5129{
d62a17ae 5130 int idx_peer = 1;
5131 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5132 bgp_node_safi(vty),
5133 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5134}
5135
d62a17ae 5136ALIAS_HIDDEN(
5137 neighbor_remove_private_as_all_replace_as,
5138 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5139 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5140 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5141 "Remove private ASNs in outbound updates\n"
5142 "Apply to all AS numbers\n"
5143 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5144
718e3744 5145DEFUN (no_neighbor_remove_private_as,
5146 no_neighbor_remove_private_as_cmd,
9ccf14f7 5147 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 5148 NO_STR
5149 NEIGHBOR_STR
5150 NEIGHBOR_ADDR_STR2
5000f21c 5151 "Remove private ASNs in outbound updates\n")
718e3744 5152{
d62a17ae 5153 int idx_peer = 2;
5154 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5155 bgp_node_afi(vty), bgp_node_safi(vty),
5156 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5157}
6b0655a2 5158
d62a17ae 5159ALIAS_HIDDEN(no_neighbor_remove_private_as,
5160 no_neighbor_remove_private_as_hidden_cmd,
5161 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5162 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5163 "Remove private ASNs in outbound updates\n")
596c17ba 5164
88b8ed8d 5165DEFUN (no_neighbor_remove_private_as_all,
5000f21c 5166 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 5167 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
5168 NO_STR
5169 NEIGHBOR_STR
5170 NEIGHBOR_ADDR_STR2
5171 "Remove private ASNs in outbound updates\n"
16cedbb0 5172 "Apply to all AS numbers\n")
88b8ed8d 5173{
d62a17ae 5174 int idx_peer = 2;
5175 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5176 bgp_node_afi(vty), bgp_node_safi(vty),
5177 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5178}
5000f21c 5179
d62a17ae 5180ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5181 no_neighbor_remove_private_as_all_hidden_cmd,
5182 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5183 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5184 "Remove private ASNs in outbound updates\n"
5185 "Apply to all AS numbers\n")
596c17ba 5186
88b8ed8d 5187DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 5188 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 5189 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
5190 NO_STR
5191 NEIGHBOR_STR
5192 NEIGHBOR_ADDR_STR2
5193 "Remove private ASNs in outbound updates\n"
5194 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5195{
d62a17ae 5196 int idx_peer = 2;
5197 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5198 bgp_node_afi(vty), bgp_node_safi(vty),
5199 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5200}
5000f21c 5201
d62a17ae 5202ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5203 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5204 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5205 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5206 "Remove private ASNs in outbound updates\n"
5207 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5208
88b8ed8d 5209DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 5210 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 5211 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
5212 NO_STR
5213 NEIGHBOR_STR
5214 NEIGHBOR_ADDR_STR2
5215 "Remove private ASNs in outbound updates\n"
16cedbb0 5216 "Apply to all AS numbers\n"
5000f21c 5217 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5218{
d62a17ae 5219 int idx_peer = 2;
5220 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5221 bgp_node_afi(vty), bgp_node_safi(vty),
5222 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5223}
5000f21c 5224
d62a17ae 5225ALIAS_HIDDEN(
5226 no_neighbor_remove_private_as_all_replace_as,
5227 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5228 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5229 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5230 "Remove private ASNs in outbound updates\n"
5231 "Apply to all AS numbers\n"
5232 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5233
5000f21c 5234
718e3744 5235/* neighbor send-community. */
5236DEFUN (neighbor_send_community,
5237 neighbor_send_community_cmd,
9ccf14f7 5238 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 5239 NEIGHBOR_STR
5240 NEIGHBOR_ADDR_STR2
5241 "Send Community attribute to this neighbor\n")
5242{
d62a17ae 5243 int idx_peer = 1;
27c05d4d 5244
d62a17ae 5245 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5246 bgp_node_safi(vty),
5247 PEER_FLAG_SEND_COMMUNITY);
718e3744 5248}
5249
d62a17ae 5250ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5251 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5252 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5253 "Send Community attribute to this neighbor\n")
596c17ba 5254
718e3744 5255DEFUN (no_neighbor_send_community,
5256 no_neighbor_send_community_cmd,
9ccf14f7 5257 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 5258 NO_STR
5259 NEIGHBOR_STR
5260 NEIGHBOR_ADDR_STR2
5261 "Send Community attribute to this neighbor\n")
5262{
d62a17ae 5263 int idx_peer = 2;
27c05d4d 5264
d62a17ae 5265 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5266 bgp_node_afi(vty), bgp_node_safi(vty),
5267 PEER_FLAG_SEND_COMMUNITY);
718e3744 5268}
6b0655a2 5269
d62a17ae 5270ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5271 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5272 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5273 "Send Community attribute to this neighbor\n")
596c17ba 5274
718e3744 5275/* neighbor send-community extended. */
5276DEFUN (neighbor_send_community_type,
5277 neighbor_send_community_type_cmd,
57d187bc 5278 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5279 NEIGHBOR_STR
5280 NEIGHBOR_ADDR_STR2
5281 "Send Community attribute to this neighbor\n"
5282 "Send Standard and Extended Community attributes\n"
57d187bc 5283 "Send Standard, Large and Extended Community attributes\n"
718e3744 5284 "Send Extended Community attributes\n"
57d187bc
JS
5285 "Send Standard Community attributes\n"
5286 "Send Large Community attributes\n")
718e3744 5287{
27c05d4d 5288 const char *type = argv[argc - 1]->text;
db45f64d
DS
5289 char *peer_str = argv[1]->arg;
5290 struct peer *peer;
5291 afi_t afi = bgp_node_afi(vty);
5292 safi_t safi = bgp_node_safi(vty);
d62a17ae 5293
db45f64d
DS
5294 peer = peer_and_group_lookup_vty(vty, peer_str);
5295 if (!peer)
5296 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5297
db45f64d
DS
5298 if (strmatch(type, "standard"))
5299 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5300 PEER_FLAG_SEND_COMMUNITY);
5301
5302 if (strmatch(type, "extended"))
5303 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5304 PEER_FLAG_SEND_EXT_COMMUNITY);
5305
5306 if (strmatch(type, "large"))
5307 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5308 PEER_FLAG_SEND_LARGE_COMMUNITY);
5309
5310 if (strmatch(type, "both")) {
5311 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5312 PEER_FLAG_SEND_COMMUNITY)
5313 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5314 PEER_FLAG_SEND_EXT_COMMUNITY);
5315 }
5316 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5317 PEER_FLAG_SEND_COMMUNITY)
5318 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5319 PEER_FLAG_SEND_EXT_COMMUNITY)
5320 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5321 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5322}
5323
5324ALIAS_HIDDEN(
5325 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5326 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5327 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5328 "Send Community attribute to this neighbor\n"
5329 "Send Standard and Extended Community attributes\n"
5330 "Send Standard, Large and Extended Community attributes\n"
5331 "Send Extended Community attributes\n"
5332 "Send Standard Community attributes\n"
5333 "Send Large Community attributes\n")
596c17ba 5334
718e3744 5335DEFUN (no_neighbor_send_community_type,
5336 no_neighbor_send_community_type_cmd,
57d187bc 5337 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5338 NO_STR
5339 NEIGHBOR_STR
5340 NEIGHBOR_ADDR_STR2
5341 "Send Community attribute to this neighbor\n"
5342 "Send Standard and Extended Community attributes\n"
57d187bc 5343 "Send Standard, Large and Extended Community attributes\n"
718e3744 5344 "Send Extended Community attributes\n"
57d187bc
JS
5345 "Send Standard Community attributes\n"
5346 "Send Large Community attributes\n")
718e3744 5347{
d62a17ae 5348 const char *type = argv[argc - 1]->text;
db45f64d
DS
5349 char *peer_str = argv[2]->arg;
5350 struct peer *peer;
5351 afi_t afi = bgp_node_afi(vty);
5352 safi_t safi = bgp_node_safi(vty);
5353
5354 peer = peer_and_group_lookup_vty(vty, peer_str);
5355 if (!peer)
5356 return CMD_WARNING_CONFIG_FAILED;
5357
5358 if (strmatch(type, "standard"))
5359 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5360 PEER_FLAG_SEND_COMMUNITY);
5361
5362 if (strmatch(type, "extended"))
5363 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5364 PEER_FLAG_SEND_EXT_COMMUNITY);
5365
5366 if (strmatch(type, "large"))
5367 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5368 PEER_FLAG_SEND_LARGE_COMMUNITY);
5369
5370 if (strmatch(type, "both")) {
d62a17ae 5371
db45f64d
DS
5372 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5373 PEER_FLAG_SEND_COMMUNITY)
5374 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5375 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5376 }
5377
db45f64d
DS
5378 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5379 PEER_FLAG_SEND_COMMUNITY)
5380 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5381 PEER_FLAG_SEND_EXT_COMMUNITY)
5382 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5383 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5384}
5385
5386ALIAS_HIDDEN(
5387 no_neighbor_send_community_type,
5388 no_neighbor_send_community_type_hidden_cmd,
5389 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5390 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5391 "Send Community attribute to this neighbor\n"
5392 "Send Standard and Extended Community attributes\n"
5393 "Send Standard, Large and Extended Community attributes\n"
5394 "Send Extended Community attributes\n"
5395 "Send Standard Community attributes\n"
5396 "Send Large Community attributes\n")
596c17ba 5397
718e3744 5398/* neighbor soft-reconfig. */
5399DEFUN (neighbor_soft_reconfiguration,
5400 neighbor_soft_reconfiguration_cmd,
9ccf14f7 5401 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5402 NEIGHBOR_STR
5403 NEIGHBOR_ADDR_STR2
5404 "Per neighbor soft reconfiguration\n"
5405 "Allow inbound soft reconfiguration for this neighbor\n")
5406{
d62a17ae 5407 int idx_peer = 1;
5408 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5409 bgp_node_safi(vty),
5410 PEER_FLAG_SOFT_RECONFIG);
718e3744 5411}
5412
d62a17ae 5413ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5414 neighbor_soft_reconfiguration_hidden_cmd,
5415 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5416 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5417 "Per neighbor soft reconfiguration\n"
5418 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5419
718e3744 5420DEFUN (no_neighbor_soft_reconfiguration,
5421 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 5422 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5423 NO_STR
5424 NEIGHBOR_STR
5425 NEIGHBOR_ADDR_STR2
5426 "Per neighbor soft reconfiguration\n"
5427 "Allow inbound soft reconfiguration for this neighbor\n")
5428{
d62a17ae 5429 int idx_peer = 2;
5430 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5431 bgp_node_afi(vty), bgp_node_safi(vty),
5432 PEER_FLAG_SOFT_RECONFIG);
718e3744 5433}
6b0655a2 5434
d62a17ae 5435ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5436 no_neighbor_soft_reconfiguration_hidden_cmd,
5437 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5438 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5439 "Per neighbor soft reconfiguration\n"
5440 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5441
718e3744 5442DEFUN (neighbor_route_reflector_client,
5443 neighbor_route_reflector_client_cmd,
9ccf14f7 5444 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5445 NEIGHBOR_STR
5446 NEIGHBOR_ADDR_STR2
5447 "Configure a neighbor as Route Reflector client\n")
5448{
d62a17ae 5449 int idx_peer = 1;
5450 struct peer *peer;
718e3744 5451
5452
d62a17ae 5453 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5454 if (!peer)
5455 return CMD_WARNING_CONFIG_FAILED;
718e3744 5456
d62a17ae 5457 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5458 bgp_node_safi(vty),
5459 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5460}
5461
d62a17ae 5462ALIAS_HIDDEN(neighbor_route_reflector_client,
5463 neighbor_route_reflector_client_hidden_cmd,
5464 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5465 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5466 "Configure a neighbor as Route Reflector client\n")
596c17ba 5467
718e3744 5468DEFUN (no_neighbor_route_reflector_client,
5469 no_neighbor_route_reflector_client_cmd,
9ccf14f7 5470 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5471 NO_STR
5472 NEIGHBOR_STR
5473 NEIGHBOR_ADDR_STR2
5474 "Configure a neighbor as Route Reflector client\n")
5475{
d62a17ae 5476 int idx_peer = 2;
5477 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5478 bgp_node_afi(vty), bgp_node_safi(vty),
5479 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5480}
6b0655a2 5481
d62a17ae 5482ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5483 no_neighbor_route_reflector_client_hidden_cmd,
5484 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5485 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5486 "Configure a neighbor as Route Reflector client\n")
596c17ba 5487
718e3744 5488/* neighbor route-server-client. */
5489DEFUN (neighbor_route_server_client,
5490 neighbor_route_server_client_cmd,
9ccf14f7 5491 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5492 NEIGHBOR_STR
5493 NEIGHBOR_ADDR_STR2
5494 "Configure a neighbor as Route Server client\n")
5495{
d62a17ae 5496 int idx_peer = 1;
5497 struct peer *peer;
2a3d5731 5498
d62a17ae 5499 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5500 if (!peer)
5501 return CMD_WARNING_CONFIG_FAILED;
5502 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5503 bgp_node_safi(vty),
5504 PEER_FLAG_RSERVER_CLIENT);
718e3744 5505}
5506
d62a17ae 5507ALIAS_HIDDEN(neighbor_route_server_client,
5508 neighbor_route_server_client_hidden_cmd,
5509 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5510 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5511 "Configure a neighbor as Route Server client\n")
596c17ba 5512
718e3744 5513DEFUN (no_neighbor_route_server_client,
5514 no_neighbor_route_server_client_cmd,
9ccf14f7 5515 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5516 NO_STR
5517 NEIGHBOR_STR
5518 NEIGHBOR_ADDR_STR2
5519 "Configure a neighbor as Route Server client\n")
fee0f4c6 5520{
d62a17ae 5521 int idx_peer = 2;
5522 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5523 bgp_node_afi(vty), bgp_node_safi(vty),
5524 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5525}
6b0655a2 5526
d62a17ae 5527ALIAS_HIDDEN(no_neighbor_route_server_client,
5528 no_neighbor_route_server_client_hidden_cmd,
5529 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5530 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5531 "Configure a neighbor as Route Server client\n")
596c17ba 5532
fee0f4c6 5533DEFUN (neighbor_nexthop_local_unchanged,
5534 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5535 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5536 NEIGHBOR_STR
5537 NEIGHBOR_ADDR_STR2
5538 "Configure treatment of outgoing link-local nexthop attribute\n"
5539 "Leave link-local nexthop unchanged for this peer\n")
5540{
d62a17ae 5541 int idx_peer = 1;
5542 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5543 bgp_node_safi(vty),
5544 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 5545}
6b0655a2 5546
fee0f4c6 5547DEFUN (no_neighbor_nexthop_local_unchanged,
5548 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5549 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5550 NO_STR
5551 NEIGHBOR_STR
5552 NEIGHBOR_ADDR_STR2
5553 "Configure treatment of outgoing link-local-nexthop attribute\n"
5554 "Leave link-local nexthop unchanged for this peer\n")
718e3744 5555{
d62a17ae 5556 int idx_peer = 2;
5557 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5558 bgp_node_afi(vty), bgp_node_safi(vty),
5559 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 5560}
6b0655a2 5561
718e3744 5562DEFUN (neighbor_attr_unchanged,
5563 neighbor_attr_unchanged_cmd,
a8206004 5564 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 5565 NEIGHBOR_STR
5566 NEIGHBOR_ADDR_STR2
5567 "BGP attribute is propagated unchanged to this neighbor\n"
5568 "As-path attribute\n"
5569 "Nexthop attribute\n"
a8206004 5570 "Med attribute\n")
718e3744 5571{
d62a17ae 5572 int idx = 0;
8eeb0335
DW
5573 char *peer_str = argv[1]->arg;
5574 struct peer *peer;
db45f64d
DS
5575 bool aspath = false;
5576 bool nexthop = false;
5577 bool med = false;
8eeb0335
DW
5578 afi_t afi = bgp_node_afi(vty);
5579 safi_t safi = bgp_node_safi(vty);
db45f64d 5580 int ret = 0;
8eeb0335
DW
5581
5582 peer = peer_and_group_lookup_vty(vty, peer_str);
5583 if (!peer)
5584 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5585
5586 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5587 aspath = true;
5588
d62a17ae 5589 idx = 0;
5590 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5591 nexthop = true;
5592
d62a17ae 5593 idx = 0;
5594 if (argv_find(argv, argc, "med", &idx))
db45f64d 5595 med = true;
d62a17ae 5596
8eeb0335 5597 /* no flags means all of them! */
db45f64d
DS
5598 if (!aspath && !nexthop && !med) {
5599 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
5600 PEER_FLAG_AS_PATH_UNCHANGED);
5601 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5602 PEER_FLAG_NEXTHOP_UNCHANGED);
5603 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5604 PEER_FLAG_MED_UNCHANGED);
8eeb0335 5605 } else {
db45f64d
DS
5606 if (!aspath) {
5607 if (peer_af_flag_check(peer, afi, safi,
5608 PEER_FLAG_AS_PATH_UNCHANGED)) {
5609 ret |= peer_af_flag_unset_vty(
5610 vty, peer_str, afi, safi,
5611 PEER_FLAG_AS_PATH_UNCHANGED);
5612 }
5613 } else
5614 ret |= peer_af_flag_set_vty(
5615 vty, peer_str, afi, safi,
5616 PEER_FLAG_AS_PATH_UNCHANGED);
5617
5618 if (!nexthop) {
5619 if (peer_af_flag_check(peer, afi, safi,
5620 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5621 ret |= peer_af_flag_unset_vty(
5622 vty, peer_str, afi, safi,
5623 PEER_FLAG_NEXTHOP_UNCHANGED);
5624 }
5625 } else
5626 ret |= peer_af_flag_set_vty(
5627 vty, peer_str, afi, safi,
5628 PEER_FLAG_NEXTHOP_UNCHANGED);
5629
5630 if (!med) {
5631 if (peer_af_flag_check(peer, afi, safi,
5632 PEER_FLAG_MED_UNCHANGED)) {
5633 ret |= peer_af_flag_unset_vty(
5634 vty, peer_str, afi, safi,
5635 PEER_FLAG_MED_UNCHANGED);
5636 }
5637 } else
5638 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5639 PEER_FLAG_MED_UNCHANGED);
d62a17ae 5640 }
5641
db45f64d 5642 return ret;
d62a17ae 5643}
5644
5645ALIAS_HIDDEN(
5646 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5647 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5648 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5649 "BGP attribute is propagated unchanged to this neighbor\n"
5650 "As-path attribute\n"
5651 "Nexthop attribute\n"
5652 "Med attribute\n")
596c17ba 5653
718e3744 5654DEFUN (no_neighbor_attr_unchanged,
5655 no_neighbor_attr_unchanged_cmd,
a8206004 5656 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 5657 NO_STR
718e3744 5658 NEIGHBOR_STR
5659 NEIGHBOR_ADDR_STR2
31500417
DW
5660 "BGP attribute is propagated unchanged to this neighbor\n"
5661 "As-path attribute\n"
40e718b5 5662 "Nexthop attribute\n"
a8206004 5663 "Med attribute\n")
718e3744 5664{
d62a17ae 5665 int idx = 0;
db45f64d
DS
5666 char *peer_str = argv[2]->arg;
5667 struct peer *peer;
5668 bool aspath = false;
5669 bool nexthop = false;
5670 bool med = false;
5671 afi_t afi = bgp_node_afi(vty);
5672 safi_t safi = bgp_node_safi(vty);
5673 int ret = 0;
5674
5675 peer = peer_and_group_lookup_vty(vty, peer_str);
5676 if (!peer)
5677 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5678
5679 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5680 aspath = true;
5681
d62a17ae 5682 idx = 0;
5683 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5684 nexthop = true;
5685
d62a17ae 5686 idx = 0;
5687 if (argv_find(argv, argc, "med", &idx))
db45f64d 5688 med = true;
d62a17ae 5689
db45f64d
DS
5690 if (!aspath && !nexthop && !med) // no flags means all of them!
5691 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5692 PEER_FLAG_AS_PATH_UNCHANGED)
5693 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5694 PEER_FLAG_NEXTHOP_UNCHANGED)
5695 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5696 PEER_FLAG_MED_UNCHANGED);
5697
5698 if (aspath)
5699 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5700 PEER_FLAG_AS_PATH_UNCHANGED);
5701
5702 if (nexthop)
5703 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5704 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 5705
db45f64d
DS
5706 if (med)
5707 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5708 PEER_FLAG_MED_UNCHANGED);
5709
5710 return ret;
d62a17ae 5711}
5712
5713ALIAS_HIDDEN(
5714 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5715 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5716 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5717 "BGP attribute is propagated unchanged to this neighbor\n"
5718 "As-path attribute\n"
5719 "Nexthop attribute\n"
5720 "Med attribute\n")
718e3744 5721
718e3744 5722/* EBGP multihop configuration. */
d62a17ae 5723static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5724 const char *ttl_str)
718e3744 5725{
d62a17ae 5726 struct peer *peer;
5727 unsigned int ttl;
718e3744 5728
d62a17ae 5729 peer = peer_and_group_lookup_vty(vty, ip_str);
5730 if (!peer)
5731 return CMD_WARNING_CONFIG_FAILED;
718e3744 5732
d62a17ae 5733 if (peer->conf_if)
5734 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 5735
d62a17ae 5736 if (!ttl_str)
5737 ttl = MAXTTL;
5738 else
5739 ttl = strtoul(ttl_str, NULL, 10);
718e3744 5740
d62a17ae 5741 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 5742}
5743
d62a17ae 5744static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5745{
d62a17ae 5746 struct peer *peer;
718e3744 5747
d62a17ae 5748 peer = peer_and_group_lookup_vty(vty, ip_str);
5749 if (!peer)
5750 return CMD_WARNING_CONFIG_FAILED;
718e3744 5751
d62a17ae 5752 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 5753}
5754
5755/* neighbor ebgp-multihop. */
5756DEFUN (neighbor_ebgp_multihop,
5757 neighbor_ebgp_multihop_cmd,
9ccf14f7 5758 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 5759 NEIGHBOR_STR
5760 NEIGHBOR_ADDR_STR2
5761 "Allow EBGP neighbors not on directly connected networks\n")
5762{
d62a17ae 5763 int idx_peer = 1;
5764 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5765}
5766
5767DEFUN (neighbor_ebgp_multihop_ttl,
5768 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 5769 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 5770 NEIGHBOR_STR
5771 NEIGHBOR_ADDR_STR2
5772 "Allow EBGP neighbors not on directly connected networks\n"
5773 "maximum hop count\n")
5774{
d62a17ae 5775 int idx_peer = 1;
5776 int idx_number = 3;
5777 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
5778 argv[idx_number]->arg);
718e3744 5779}
5780
5781DEFUN (no_neighbor_ebgp_multihop,
5782 no_neighbor_ebgp_multihop_cmd,
a636c635 5783 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 5784 NO_STR
5785 NEIGHBOR_STR
5786 NEIGHBOR_ADDR_STR2
a636c635
DW
5787 "Allow EBGP neighbors not on directly connected networks\n"
5788 "maximum hop count\n")
718e3744 5789{
d62a17ae 5790 int idx_peer = 2;
5791 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5792}
5793
6b0655a2 5794
6ffd2079 5795/* disable-connected-check */
5796DEFUN (neighbor_disable_connected_check,
5797 neighbor_disable_connected_check_cmd,
7ebe625c 5798 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5799 NEIGHBOR_STR
7ebe625c 5800 NEIGHBOR_ADDR_STR2
a636c635
DW
5801 "one-hop away EBGP peer using loopback address\n"
5802 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5803{
d62a17ae 5804 int idx_peer = 1;
5805 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5806 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5807}
5808
5809DEFUN (no_neighbor_disable_connected_check,
5810 no_neighbor_disable_connected_check_cmd,
7ebe625c 5811 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5812 NO_STR
5813 NEIGHBOR_STR
7ebe625c 5814 NEIGHBOR_ADDR_STR2
a636c635
DW
5815 "one-hop away EBGP peer using loopback address\n"
5816 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5817{
d62a17ae 5818 int idx_peer = 2;
5819 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5820 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5821}
5822
47cbc09b
PM
5823
5824/* enforce-first-as */
5825DEFUN (neighbor_enforce_first_as,
5826 neighbor_enforce_first_as_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5828 NEIGHBOR_STR
5829 NEIGHBOR_ADDR_STR2
5830 "Enforce the first AS for EBGP routes\n")
5831{
5832 int idx_peer = 1;
5833
5834 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5835 PEER_FLAG_ENFORCE_FIRST_AS);
5836}
5837
5838DEFUN (no_neighbor_enforce_first_as,
5839 no_neighbor_enforce_first_as_cmd,
5840 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5841 NO_STR
5842 NEIGHBOR_STR
5843 NEIGHBOR_ADDR_STR2
5844 "Enforce the first AS for EBGP routes\n")
5845{
5846 int idx_peer = 2;
5847
5848 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5849 PEER_FLAG_ENFORCE_FIRST_AS);
5850}
5851
5852
718e3744 5853DEFUN (neighbor_description,
5854 neighbor_description_cmd,
e961923c 5855 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 5856 NEIGHBOR_STR
5857 NEIGHBOR_ADDR_STR2
5858 "Neighbor specific description\n"
5859 "Up to 80 characters describing this neighbor\n")
5860{
d62a17ae 5861 int idx_peer = 1;
5862 int idx_line = 3;
5863 struct peer *peer;
5864 char *str;
718e3744 5865
d62a17ae 5866 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5867 if (!peer)
5868 return CMD_WARNING_CONFIG_FAILED;
718e3744 5869
d62a17ae 5870 str = argv_concat(argv, argc, idx_line);
718e3744 5871
d62a17ae 5872 peer_description_set(peer, str);
718e3744 5873
d62a17ae 5874 XFREE(MTYPE_TMP, str);
718e3744 5875
d62a17ae 5876 return CMD_SUCCESS;
718e3744 5877}
5878
5879DEFUN (no_neighbor_description,
5880 no_neighbor_description_cmd,
a14810f4 5881 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 5882 NO_STR
5883 NEIGHBOR_STR
5884 NEIGHBOR_ADDR_STR2
a14810f4 5885 "Neighbor specific description\n")
718e3744 5886{
d62a17ae 5887 int idx_peer = 2;
5888 struct peer *peer;
718e3744 5889
d62a17ae 5890 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5891 if (!peer)
5892 return CMD_WARNING_CONFIG_FAILED;
718e3744 5893
d62a17ae 5894 peer_description_unset(peer);
718e3744 5895
d62a17ae 5896 return CMD_SUCCESS;
718e3744 5897}
5898
a14810f4
PM
5899ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
5900 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5901 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5902 "Neighbor specific description\n"
5903 "Up to 80 characters describing this neighbor\n")
6b0655a2 5904
718e3744 5905/* Neighbor update-source. */
d62a17ae 5906static int peer_update_source_vty(struct vty *vty, const char *peer_str,
5907 const char *source_str)
5908{
5909 struct peer *peer;
5910 struct prefix p;
a14810f4 5911 union sockunion su;
d62a17ae 5912
5913 peer = peer_and_group_lookup_vty(vty, peer_str);
5914 if (!peer)
5915 return CMD_WARNING_CONFIG_FAILED;
5916
5917 if (peer->conf_if)
5918 return CMD_WARNING;
5919
5920 if (source_str) {
a14810f4 5921 if (str2sockunion(source_str, &su) == 0)
d62a17ae 5922 peer_update_source_addr_set(peer, &su);
5923 else {
5924 if (str2prefix(source_str, &p)) {
5925 vty_out(vty,
5926 "%% Invalid update-source, remove prefix length \n");
5927 return CMD_WARNING_CONFIG_FAILED;
5928 } else
5929 peer_update_source_if_set(peer, source_str);
5930 }
5931 } else
5932 peer_update_source_unset(peer);
5933
5934 return CMD_SUCCESS;
5935}
5936
5937#define BGP_UPDATE_SOURCE_HELP_STR \
5938 "IPv4 address\n" \
5939 "IPv6 address\n" \
5940 "Interface name (requires zebra to be running)\n"
369688c0 5941
718e3744 5942DEFUN (neighbor_update_source,
5943 neighbor_update_source_cmd,
9ccf14f7 5944 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 5945 NEIGHBOR_STR
5946 NEIGHBOR_ADDR_STR2
5947 "Source of routing updates\n"
369688c0 5948 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5949{
d62a17ae 5950 int idx_peer = 1;
5951 int idx_peer_2 = 3;
5952 return peer_update_source_vty(vty, argv[idx_peer]->arg,
5953 argv[idx_peer_2]->arg);
718e3744 5954}
5955
5956DEFUN (no_neighbor_update_source,
5957 no_neighbor_update_source_cmd,
c7178fe7 5958 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 5959 NO_STR
5960 NEIGHBOR_STR
5961 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
5962 "Source of routing updates\n"
5963 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5964{
d62a17ae 5965 int idx_peer = 2;
5966 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5967}
6b0655a2 5968
d62a17ae 5969static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
5970 afi_t afi, safi_t safi,
5971 const char *rmap, int set)
718e3744 5972{
d62a17ae 5973 int ret;
5974 struct peer *peer;
80912664 5975 struct route_map *route_map = NULL;
718e3744 5976
d62a17ae 5977 peer = peer_and_group_lookup_vty(vty, peer_str);
5978 if (!peer)
5979 return CMD_WARNING_CONFIG_FAILED;
718e3744 5980
1de27621 5981 if (set) {
80912664
DS
5982 if (rmap)
5983 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
5984 ret = peer_default_originate_set(peer, afi, safi,
5985 rmap, route_map);
5986 } else
d62a17ae 5987 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 5988
d62a17ae 5989 return bgp_vty_return(vty, ret);
718e3744 5990}
5991
5992/* neighbor default-originate. */
5993DEFUN (neighbor_default_originate,
5994 neighbor_default_originate_cmd,
9ccf14f7 5995 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 5996 NEIGHBOR_STR
5997 NEIGHBOR_ADDR_STR2
5998 "Originate default route to this neighbor\n")
5999{
d62a17ae 6000 int idx_peer = 1;
6001 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6002 bgp_node_afi(vty),
6003 bgp_node_safi(vty), NULL, 1);
718e3744 6004}
6005
d62a17ae 6006ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6007 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6008 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6009 "Originate default route to this neighbor\n")
596c17ba 6010
718e3744 6011DEFUN (neighbor_default_originate_rmap,
6012 neighbor_default_originate_rmap_cmd,
9ccf14f7 6013 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6014 NEIGHBOR_STR
6015 NEIGHBOR_ADDR_STR2
6016 "Originate default route to this neighbor\n"
6017 "Route-map to specify criteria to originate default\n"
6018 "route-map name\n")
6019{
d62a17ae 6020 int idx_peer = 1;
6021 int idx_word = 4;
6022 return peer_default_originate_set_vty(
6023 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6024 argv[idx_word]->arg, 1);
718e3744 6025}
6026
d62a17ae 6027ALIAS_HIDDEN(
6028 neighbor_default_originate_rmap,
6029 neighbor_default_originate_rmap_hidden_cmd,
6030 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6031 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6032 "Originate default route to this neighbor\n"
6033 "Route-map to specify criteria to originate default\n"
6034 "route-map name\n")
596c17ba 6035
718e3744 6036DEFUN (no_neighbor_default_originate,
6037 no_neighbor_default_originate_cmd,
a636c635 6038 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6039 NO_STR
6040 NEIGHBOR_STR
6041 NEIGHBOR_ADDR_STR2
a636c635
DW
6042 "Originate default route to this neighbor\n"
6043 "Route-map to specify criteria to originate default\n"
6044 "route-map name\n")
718e3744 6045{
d62a17ae 6046 int idx_peer = 2;
6047 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6048 bgp_node_afi(vty),
6049 bgp_node_safi(vty), NULL, 0);
718e3744 6050}
6051
d62a17ae 6052ALIAS_HIDDEN(
6053 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6054 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6055 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6056 "Originate default route to this neighbor\n"
6057 "Route-map to specify criteria to originate default\n"
6058 "route-map name\n")
596c17ba 6059
6b0655a2 6060
718e3744 6061/* Set neighbor's BGP port. */
d62a17ae 6062static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6063 const char *port_str)
6064{
6065 struct peer *peer;
d7c0a89a 6066 uint16_t port;
d62a17ae 6067 struct servent *sp;
6068
6069 peer = peer_lookup_vty(vty, ip_str);
6070 if (!peer)
6071 return CMD_WARNING_CONFIG_FAILED;
6072
6073 if (!port_str) {
6074 sp = getservbyname("bgp", "tcp");
6075 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6076 } else {
6077 port = strtoul(port_str, NULL, 10);
6078 }
718e3744 6079
d62a17ae 6080 peer_port_set(peer, port);
718e3744 6081
d62a17ae 6082 return CMD_SUCCESS;
718e3744 6083}
6084
f418446b 6085/* Set specified peer's BGP port. */
718e3744 6086DEFUN (neighbor_port,
6087 neighbor_port_cmd,
9ccf14f7 6088 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 6089 NEIGHBOR_STR
6090 NEIGHBOR_ADDR_STR
6091 "Neighbor's BGP port\n"
6092 "TCP port number\n")
6093{
d62a17ae 6094 int idx_ip = 1;
6095 int idx_number = 3;
6096 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6097 argv[idx_number]->arg);
718e3744 6098}
6099
6100DEFUN (no_neighbor_port,
6101 no_neighbor_port_cmd,
9ccf14f7 6102 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 6103 NO_STR
6104 NEIGHBOR_STR
6105 NEIGHBOR_ADDR_STR
8334fd5a
DW
6106 "Neighbor's BGP port\n"
6107 "TCP port number\n")
718e3744 6108{
d62a17ae 6109 int idx_ip = 2;
6110 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 6111}
6112
6b0655a2 6113
718e3744 6114/* neighbor weight. */
d62a17ae 6115static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6116 safi_t safi, const char *weight_str)
718e3744 6117{
d62a17ae 6118 int ret;
6119 struct peer *peer;
6120 unsigned long weight;
718e3744 6121
d62a17ae 6122 peer = peer_and_group_lookup_vty(vty, ip_str);
6123 if (!peer)
6124 return CMD_WARNING_CONFIG_FAILED;
718e3744 6125
d62a17ae 6126 weight = strtoul(weight_str, NULL, 10);
718e3744 6127
d62a17ae 6128 ret = peer_weight_set(peer, afi, safi, weight);
6129 return bgp_vty_return(vty, ret);
718e3744 6130}
6131
d62a17ae 6132static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6133 safi_t safi)
718e3744 6134{
d62a17ae 6135 int ret;
6136 struct peer *peer;
718e3744 6137
d62a17ae 6138 peer = peer_and_group_lookup_vty(vty, ip_str);
6139 if (!peer)
6140 return CMD_WARNING_CONFIG_FAILED;
718e3744 6141
d62a17ae 6142 ret = peer_weight_unset(peer, afi, safi);
6143 return bgp_vty_return(vty, ret);
718e3744 6144}
6145
6146DEFUN (neighbor_weight,
6147 neighbor_weight_cmd,
9ccf14f7 6148 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 6149 NEIGHBOR_STR
6150 NEIGHBOR_ADDR_STR2
6151 "Set default weight for routes from this neighbor\n"
6152 "default weight\n")
6153{
d62a17ae 6154 int idx_peer = 1;
6155 int idx_number = 3;
6156 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6157 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6158}
6159
d62a17ae 6160ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6161 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6162 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6163 "Set default weight for routes from this neighbor\n"
6164 "default weight\n")
596c17ba 6165
718e3744 6166DEFUN (no_neighbor_weight,
6167 no_neighbor_weight_cmd,
9ccf14f7 6168 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 6169 NO_STR
6170 NEIGHBOR_STR
6171 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6172 "Set default weight for routes from this neighbor\n"
6173 "default weight\n")
718e3744 6174{
d62a17ae 6175 int idx_peer = 2;
6176 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6177 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6178}
6179
d62a17ae 6180ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6181 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6182 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6183 "Set default weight for routes from this neighbor\n"
6184 "default weight\n")
596c17ba 6185
6b0655a2 6186
718e3744 6187/* Override capability negotiation. */
6188DEFUN (neighbor_override_capability,
6189 neighbor_override_capability_cmd,
9ccf14f7 6190 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 6191 NEIGHBOR_STR
6192 NEIGHBOR_ADDR_STR2
6193 "Override capability negotiation result\n")
6194{
d62a17ae 6195 int idx_peer = 1;
6196 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6197 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6198}
6199
6200DEFUN (no_neighbor_override_capability,
6201 no_neighbor_override_capability_cmd,
9ccf14f7 6202 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 6203 NO_STR
6204 NEIGHBOR_STR
6205 NEIGHBOR_ADDR_STR2
6206 "Override capability negotiation result\n")
6207{
d62a17ae 6208 int idx_peer = 2;
6209 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6210 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6211}
6b0655a2 6212
718e3744 6213DEFUN (neighbor_strict_capability,
6214 neighbor_strict_capability_cmd,
9fb964de 6215 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 6216 NEIGHBOR_STR
9fb964de 6217 NEIGHBOR_ADDR_STR2
718e3744 6218 "Strict capability negotiation match\n")
6219{
9fb964de
PM
6220 int idx_peer = 1;
6221
6222 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 6223 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6224}
6225
6226DEFUN (no_neighbor_strict_capability,
6227 no_neighbor_strict_capability_cmd,
9fb964de 6228 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 6229 NO_STR
6230 NEIGHBOR_STR
9fb964de 6231 NEIGHBOR_ADDR_STR2
718e3744 6232 "Strict capability negotiation match\n")
6233{
9fb964de
PM
6234 int idx_peer = 2;
6235
6236 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 6237 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6238}
6b0655a2 6239
d62a17ae 6240static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6241 const char *keep_str, const char *hold_str)
718e3744 6242{
d62a17ae 6243 int ret;
6244 struct peer *peer;
d7c0a89a
QY
6245 uint32_t keepalive;
6246 uint32_t holdtime;
718e3744 6247
d62a17ae 6248 peer = peer_and_group_lookup_vty(vty, ip_str);
6249 if (!peer)
6250 return CMD_WARNING_CONFIG_FAILED;
718e3744 6251
d62a17ae 6252 keepalive = strtoul(keep_str, NULL, 10);
6253 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6254
d62a17ae 6255 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6256
d62a17ae 6257 return bgp_vty_return(vty, ret);
718e3744 6258}
6b0655a2 6259
d62a17ae 6260static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6261{
d62a17ae 6262 int ret;
6263 struct peer *peer;
718e3744 6264
d62a17ae 6265 peer = peer_and_group_lookup_vty(vty, ip_str);
6266 if (!peer)
6267 return CMD_WARNING_CONFIG_FAILED;
718e3744 6268
d62a17ae 6269 ret = peer_timers_unset(peer);
718e3744 6270
d62a17ae 6271 return bgp_vty_return(vty, ret);
718e3744 6272}
6273
6274DEFUN (neighbor_timers,
6275 neighbor_timers_cmd,
9ccf14f7 6276 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 6277 NEIGHBOR_STR
6278 NEIGHBOR_ADDR_STR2
6279 "BGP per neighbor timers\n"
6280 "Keepalive interval\n"
6281 "Holdtime\n")
6282{
d62a17ae 6283 int idx_peer = 1;
6284 int idx_number = 3;
6285 int idx_number_2 = 4;
6286 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6287 argv[idx_number]->arg,
6288 argv[idx_number_2]->arg);
718e3744 6289}
6290
6291DEFUN (no_neighbor_timers,
6292 no_neighbor_timers_cmd,
9ccf14f7 6293 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 6294 NO_STR
6295 NEIGHBOR_STR
6296 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6297 "BGP per neighbor timers\n"
6298 "Keepalive interval\n"
6299 "Holdtime\n")
718e3744 6300{
d62a17ae 6301 int idx_peer = 2;
6302 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6303}
6b0655a2 6304
813d4307 6305
d62a17ae 6306static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6307 const char *time_str)
718e3744 6308{
d62a17ae 6309 int ret;
6310 struct peer *peer;
d7c0a89a 6311 uint32_t connect;
718e3744 6312
d62a17ae 6313 peer = peer_and_group_lookup_vty(vty, ip_str);
6314 if (!peer)
6315 return CMD_WARNING_CONFIG_FAILED;
718e3744 6316
d62a17ae 6317 connect = strtoul(time_str, NULL, 10);
718e3744 6318
d62a17ae 6319 ret = peer_timers_connect_set(peer, connect);
718e3744 6320
d62a17ae 6321 return bgp_vty_return(vty, ret);
718e3744 6322}
6323
d62a17ae 6324static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6325{
d62a17ae 6326 int ret;
6327 struct peer *peer;
718e3744 6328
d62a17ae 6329 peer = peer_and_group_lookup_vty(vty, ip_str);
6330 if (!peer)
6331 return CMD_WARNING_CONFIG_FAILED;
718e3744 6332
d62a17ae 6333 ret = peer_timers_connect_unset(peer);
718e3744 6334
d62a17ae 6335 return bgp_vty_return(vty, ret);
718e3744 6336}
6337
6338DEFUN (neighbor_timers_connect,
6339 neighbor_timers_connect_cmd,
9ccf14f7 6340 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 6341 NEIGHBOR_STR
966f821c 6342 NEIGHBOR_ADDR_STR2
718e3744 6343 "BGP per neighbor timers\n"
6344 "BGP connect timer\n"
6345 "Connect timer\n")
6346{
d62a17ae 6347 int idx_peer = 1;
6348 int idx_number = 4;
6349 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6350 argv[idx_number]->arg);
718e3744 6351}
6352
6353DEFUN (no_neighbor_timers_connect,
6354 no_neighbor_timers_connect_cmd,
9ccf14f7 6355 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 6356 NO_STR
6357 NEIGHBOR_STR
966f821c 6358 NEIGHBOR_ADDR_STR2
718e3744 6359 "BGP per neighbor timers\n"
8334fd5a
DW
6360 "BGP connect timer\n"
6361 "Connect timer\n")
718e3744 6362{
d62a17ae 6363 int idx_peer = 2;
6364 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6365}
6366
6b0655a2 6367
d62a17ae 6368static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6369 const char *time_str, int set)
718e3744 6370{
d62a17ae 6371 int ret;
6372 struct peer *peer;
d7c0a89a 6373 uint32_t routeadv = 0;
718e3744 6374
d62a17ae 6375 peer = peer_and_group_lookup_vty(vty, ip_str);
6376 if (!peer)
6377 return CMD_WARNING_CONFIG_FAILED;
718e3744 6378
d62a17ae 6379 if (time_str)
6380 routeadv = strtoul(time_str, NULL, 10);
718e3744 6381
d62a17ae 6382 if (set)
6383 ret = peer_advertise_interval_set(peer, routeadv);
6384 else
6385 ret = peer_advertise_interval_unset(peer);
718e3744 6386
d62a17ae 6387 return bgp_vty_return(vty, ret);
718e3744 6388}
6389
6390DEFUN (neighbor_advertise_interval,
6391 neighbor_advertise_interval_cmd,
9ccf14f7 6392 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 6393 NEIGHBOR_STR
966f821c 6394 NEIGHBOR_ADDR_STR2
718e3744 6395 "Minimum interval between sending BGP routing updates\n"
6396 "time in seconds\n")
6397{
d62a17ae 6398 int idx_peer = 1;
6399 int idx_number = 3;
6400 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6401 argv[idx_number]->arg, 1);
718e3744 6402}
6403
6404DEFUN (no_neighbor_advertise_interval,
6405 no_neighbor_advertise_interval_cmd,
9ccf14f7 6406 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 6407 NO_STR
6408 NEIGHBOR_STR
966f821c 6409 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6410 "Minimum interval between sending BGP routing updates\n"
6411 "time in seconds\n")
718e3744 6412{
d62a17ae 6413 int idx_peer = 2;
6414 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6415}
6416
6b0655a2 6417
518f0eb1
DS
6418/* Time to wait before processing route-map updates */
6419DEFUN (bgp_set_route_map_delay_timer,
6420 bgp_set_route_map_delay_timer_cmd,
6147e2c6 6421 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
6422 SET_STR
6423 "BGP route-map delay timer\n"
6424 "Time in secs to wait before processing route-map changes\n"
f414725f 6425 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6426{
d62a17ae 6427 int idx_number = 3;
d7c0a89a 6428 uint32_t rmap_delay_timer;
d62a17ae 6429
6430 if (argv[idx_number]->arg) {
6431 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6432 bm->rmap_update_timer = rmap_delay_timer;
6433
6434 /* if the dynamic update handling is being disabled, and a timer
6435 * is
6436 * running, stop the timer and act as if the timer has already
6437 * fired.
6438 */
6439 if (!rmap_delay_timer && bm->t_rmap_update) {
6440 BGP_TIMER_OFF(bm->t_rmap_update);
6441 thread_execute(bm->master, bgp_route_map_update_timer,
6442 NULL, 0);
6443 }
6444 return CMD_SUCCESS;
6445 } else {
6446 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6447 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 6448 }
518f0eb1
DS
6449}
6450
6451DEFUN (no_bgp_set_route_map_delay_timer,
6452 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 6453 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 6454 NO_STR
3a2d747c 6455 BGP_STR
518f0eb1 6456 "Default BGP route-map delay timer\n"
8334fd5a
DW
6457 "Reset to default time to wait for processing route-map changes\n"
6458 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6459{
518f0eb1 6460
d62a17ae 6461 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 6462
d62a17ae 6463 return CMD_SUCCESS;
518f0eb1
DS
6464}
6465
718e3744 6466/* neighbor interface */
d62a17ae 6467static int peer_interface_vty(struct vty *vty, const char *ip_str,
6468 const char *str)
718e3744 6469{
d62a17ae 6470 struct peer *peer;
718e3744 6471
d62a17ae 6472 peer = peer_lookup_vty(vty, ip_str);
6473 if (!peer || peer->conf_if) {
6474 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6475 return CMD_WARNING_CONFIG_FAILED;
6476 }
718e3744 6477
d62a17ae 6478 if (str)
6479 peer_interface_set(peer, str);
6480 else
6481 peer_interface_unset(peer);
718e3744 6482
d62a17ae 6483 return CMD_SUCCESS;
718e3744 6484}
6485
6486DEFUN (neighbor_interface,
6487 neighbor_interface_cmd,
9ccf14f7 6488 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 6489 NEIGHBOR_STR
6490 NEIGHBOR_ADDR_STR
6491 "Interface\n"
6492 "Interface name\n")
6493{
d62a17ae 6494 int idx_ip = 1;
6495 int idx_word = 3;
6496 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 6497}
6498
6499DEFUN (no_neighbor_interface,
6500 no_neighbor_interface_cmd,
9ccf14f7 6501 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 6502 NO_STR
6503 NEIGHBOR_STR
16cedbb0 6504 NEIGHBOR_ADDR_STR2
718e3744 6505 "Interface\n"
6506 "Interface name\n")
6507{
d62a17ae 6508 int idx_peer = 2;
6509 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6510}
6b0655a2 6511
718e3744 6512DEFUN (neighbor_distribute_list,
6513 neighbor_distribute_list_cmd,
9ccf14f7 6514 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6515 NEIGHBOR_STR
6516 NEIGHBOR_ADDR_STR2
6517 "Filter updates to/from this neighbor\n"
6518 "IP access-list number\n"
6519 "IP access-list number (expanded range)\n"
6520 "IP Access-list name\n"
6521 "Filter incoming updates\n"
6522 "Filter outgoing updates\n")
6523{
d62a17ae 6524 int idx_peer = 1;
6525 int idx_acl = 3;
6526 int direct, ret;
6527 struct peer *peer;
a8206004 6528
d62a17ae 6529 const char *pstr = argv[idx_peer]->arg;
6530 const char *acl = argv[idx_acl]->arg;
6531 const char *inout = argv[argc - 1]->text;
a8206004 6532
d62a17ae 6533 peer = peer_and_group_lookup_vty(vty, pstr);
6534 if (!peer)
6535 return CMD_WARNING_CONFIG_FAILED;
a8206004 6536
d62a17ae 6537 /* Check filter direction. */
6538 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6539 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6540 direct, acl);
a8206004 6541
d62a17ae 6542 return bgp_vty_return(vty, ret);
718e3744 6543}
6544
d62a17ae 6545ALIAS_HIDDEN(
6546 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6547 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6549 "Filter updates to/from this neighbor\n"
6550 "IP access-list number\n"
6551 "IP access-list number (expanded range)\n"
6552 "IP Access-list name\n"
6553 "Filter incoming updates\n"
6554 "Filter outgoing updates\n")
596c17ba 6555
718e3744 6556DEFUN (no_neighbor_distribute_list,
6557 no_neighbor_distribute_list_cmd,
9ccf14f7 6558 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6559 NO_STR
6560 NEIGHBOR_STR
6561 NEIGHBOR_ADDR_STR2
6562 "Filter updates to/from this neighbor\n"
6563 "IP access-list number\n"
6564 "IP access-list number (expanded range)\n"
6565 "IP Access-list name\n"
6566 "Filter incoming updates\n"
6567 "Filter outgoing updates\n")
6568{
d62a17ae 6569 int idx_peer = 2;
6570 int direct, ret;
6571 struct peer *peer;
a8206004 6572
d62a17ae 6573 const char *pstr = argv[idx_peer]->arg;
6574 const char *inout = argv[argc - 1]->text;
a8206004 6575
d62a17ae 6576 peer = peer_and_group_lookup_vty(vty, pstr);
6577 if (!peer)
6578 return CMD_WARNING_CONFIG_FAILED;
a8206004 6579
d62a17ae 6580 /* Check filter direction. */
6581 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6582 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6583 direct);
a8206004 6584
d62a17ae 6585 return bgp_vty_return(vty, ret);
718e3744 6586}
6b0655a2 6587
d62a17ae 6588ALIAS_HIDDEN(
6589 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6590 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6591 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6592 "Filter updates to/from this neighbor\n"
6593 "IP access-list number\n"
6594 "IP access-list number (expanded range)\n"
6595 "IP Access-list name\n"
6596 "Filter incoming updates\n"
6597 "Filter outgoing updates\n")
596c17ba 6598
718e3744 6599/* Set prefix list to the peer. */
d62a17ae 6600static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6601 afi_t afi, safi_t safi,
6602 const char *name_str,
6603 const char *direct_str)
718e3744 6604{
d62a17ae 6605 int ret;
d62a17ae 6606 int direct = FILTER_IN;
cf9ac8bf 6607 struct peer *peer;
718e3744 6608
d62a17ae 6609 peer = peer_and_group_lookup_vty(vty, ip_str);
6610 if (!peer)
6611 return CMD_WARNING_CONFIG_FAILED;
718e3744 6612
d62a17ae 6613 /* Check filter direction. */
6614 if (strncmp(direct_str, "i", 1) == 0)
6615 direct = FILTER_IN;
6616 else if (strncmp(direct_str, "o", 1) == 0)
6617 direct = FILTER_OUT;
718e3744 6618
d62a17ae 6619 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 6620
d62a17ae 6621 return bgp_vty_return(vty, ret);
718e3744 6622}
6623
d62a17ae 6624static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6625 afi_t afi, safi_t safi,
6626 const char *direct_str)
718e3744 6627{
d62a17ae 6628 int ret;
6629 struct peer *peer;
6630 int direct = FILTER_IN;
718e3744 6631
d62a17ae 6632 peer = peer_and_group_lookup_vty(vty, ip_str);
6633 if (!peer)
6634 return CMD_WARNING_CONFIG_FAILED;
e52702f2 6635
d62a17ae 6636 /* Check filter direction. */
6637 if (strncmp(direct_str, "i", 1) == 0)
6638 direct = FILTER_IN;
6639 else if (strncmp(direct_str, "o", 1) == 0)
6640 direct = FILTER_OUT;
718e3744 6641
d62a17ae 6642 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 6643
d62a17ae 6644 return bgp_vty_return(vty, ret);
718e3744 6645}
6646
6647DEFUN (neighbor_prefix_list,
6648 neighbor_prefix_list_cmd,
9ccf14f7 6649 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6650 NEIGHBOR_STR
6651 NEIGHBOR_ADDR_STR2
6652 "Filter updates to/from this neighbor\n"
6653 "Name of a prefix list\n"
6654 "Filter incoming updates\n"
6655 "Filter outgoing updates\n")
6656{
d62a17ae 6657 int idx_peer = 1;
6658 int idx_word = 3;
6659 int idx_in_out = 4;
6660 return peer_prefix_list_set_vty(
6661 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6662 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6663}
6664
d62a17ae 6665ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6666 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6667 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6668 "Filter updates to/from this neighbor\n"
6669 "Name of a prefix list\n"
6670 "Filter incoming updates\n"
6671 "Filter outgoing updates\n")
596c17ba 6672
718e3744 6673DEFUN (no_neighbor_prefix_list,
6674 no_neighbor_prefix_list_cmd,
9ccf14f7 6675 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6676 NO_STR
6677 NEIGHBOR_STR
6678 NEIGHBOR_ADDR_STR2
6679 "Filter updates to/from this neighbor\n"
6680 "Name of a prefix list\n"
6681 "Filter incoming updates\n"
6682 "Filter outgoing updates\n")
6683{
d62a17ae 6684 int idx_peer = 2;
6685 int idx_in_out = 5;
6686 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6687 bgp_node_afi(vty), bgp_node_safi(vty),
6688 argv[idx_in_out]->arg);
718e3744 6689}
6b0655a2 6690
d62a17ae 6691ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6692 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6693 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6694 "Filter updates to/from this neighbor\n"
6695 "Name of a prefix list\n"
6696 "Filter incoming updates\n"
6697 "Filter outgoing updates\n")
596c17ba 6698
d62a17ae 6699static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6700 safi_t safi, const char *name_str,
6701 const char *direct_str)
718e3744 6702{
d62a17ae 6703 int ret;
6704 struct peer *peer;
6705 int direct = FILTER_IN;
718e3744 6706
d62a17ae 6707 peer = peer_and_group_lookup_vty(vty, ip_str);
6708 if (!peer)
6709 return CMD_WARNING_CONFIG_FAILED;
718e3744 6710
d62a17ae 6711 /* Check filter direction. */
6712 if (strncmp(direct_str, "i", 1) == 0)
6713 direct = FILTER_IN;
6714 else if (strncmp(direct_str, "o", 1) == 0)
6715 direct = FILTER_OUT;
718e3744 6716
d62a17ae 6717 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 6718
d62a17ae 6719 return bgp_vty_return(vty, ret);
718e3744 6720}
6721
d62a17ae 6722static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6723 safi_t safi, const char *direct_str)
718e3744 6724{
d62a17ae 6725 int ret;
6726 struct peer *peer;
6727 int direct = FILTER_IN;
718e3744 6728
d62a17ae 6729 peer = peer_and_group_lookup_vty(vty, ip_str);
6730 if (!peer)
6731 return CMD_WARNING_CONFIG_FAILED;
718e3744 6732
d62a17ae 6733 /* Check filter direction. */
6734 if (strncmp(direct_str, "i", 1) == 0)
6735 direct = FILTER_IN;
6736 else if (strncmp(direct_str, "o", 1) == 0)
6737 direct = FILTER_OUT;
718e3744 6738
d62a17ae 6739 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 6740
d62a17ae 6741 return bgp_vty_return(vty, ret);
718e3744 6742}
6743
6744DEFUN (neighbor_filter_list,
6745 neighbor_filter_list_cmd,
9ccf14f7 6746 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6747 NEIGHBOR_STR
6748 NEIGHBOR_ADDR_STR2
6749 "Establish BGP filters\n"
6750 "AS path access-list name\n"
6751 "Filter incoming routes\n"
6752 "Filter outgoing routes\n")
6753{
d62a17ae 6754 int idx_peer = 1;
6755 int idx_word = 3;
6756 int idx_in_out = 4;
6757 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6758 bgp_node_safi(vty), argv[idx_word]->arg,
6759 argv[idx_in_out]->arg);
718e3744 6760}
6761
d62a17ae 6762ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
6763 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6764 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6765 "Establish BGP filters\n"
6766 "AS path access-list name\n"
6767 "Filter incoming routes\n"
6768 "Filter outgoing routes\n")
596c17ba 6769
718e3744 6770DEFUN (no_neighbor_filter_list,
6771 no_neighbor_filter_list_cmd,
9ccf14f7 6772 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6773 NO_STR
6774 NEIGHBOR_STR
6775 NEIGHBOR_ADDR_STR2
6776 "Establish BGP filters\n"
6777 "AS path access-list name\n"
6778 "Filter incoming routes\n"
6779 "Filter outgoing routes\n")
6780{
d62a17ae 6781 int idx_peer = 2;
6782 int idx_in_out = 5;
6783 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
6784 bgp_node_afi(vty), bgp_node_safi(vty),
6785 argv[idx_in_out]->arg);
718e3744 6786}
6b0655a2 6787
d62a17ae 6788ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
6789 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6790 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6791 "Establish BGP filters\n"
6792 "AS path access-list name\n"
6793 "Filter incoming routes\n"
6794 "Filter outgoing routes\n")
596c17ba 6795
718e3744 6796/* Set route-map to the peer. */
d62a17ae 6797static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
6798 afi_t afi, safi_t safi, const char *name_str,
6799 const char *direct_str)
718e3744 6800{
d62a17ae 6801 int ret;
6802 struct peer *peer;
6803 int direct = RMAP_IN;
1de27621 6804 struct route_map *route_map;
718e3744 6805
d62a17ae 6806 peer = peer_and_group_lookup_vty(vty, ip_str);
6807 if (!peer)
6808 return CMD_WARNING_CONFIG_FAILED;
718e3744 6809
d62a17ae 6810 /* Check filter direction. */
6811 if (strncmp(direct_str, "in", 2) == 0)
6812 direct = RMAP_IN;
6813 else if (strncmp(direct_str, "o", 1) == 0)
6814 direct = RMAP_OUT;
718e3744 6815
1de27621
DA
6816 route_map = route_map_lookup_warn_noexist(vty, name_str);
6817 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 6818
d62a17ae 6819 return bgp_vty_return(vty, ret);
718e3744 6820}
6821
d62a17ae 6822static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
6823 afi_t afi, safi_t safi,
6824 const char *direct_str)
718e3744 6825{
d62a17ae 6826 int ret;
6827 struct peer *peer;
6828 int direct = RMAP_IN;
718e3744 6829
d62a17ae 6830 peer = peer_and_group_lookup_vty(vty, ip_str);
6831 if (!peer)
6832 return CMD_WARNING_CONFIG_FAILED;
718e3744 6833
d62a17ae 6834 /* Check filter direction. */
6835 if (strncmp(direct_str, "in", 2) == 0)
6836 direct = RMAP_IN;
6837 else if (strncmp(direct_str, "o", 1) == 0)
6838 direct = RMAP_OUT;
718e3744 6839
d62a17ae 6840 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 6841
d62a17ae 6842 return bgp_vty_return(vty, ret);
718e3744 6843}
6844
6845DEFUN (neighbor_route_map,
6846 neighbor_route_map_cmd,
9ccf14f7 6847 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6848 NEIGHBOR_STR
6849 NEIGHBOR_ADDR_STR2
6850 "Apply route map to neighbor\n"
6851 "Name of route map\n"
6852 "Apply map to incoming routes\n"
2a3d5731 6853 "Apply map to outbound routes\n")
718e3744 6854{
d62a17ae 6855 int idx_peer = 1;
6856 int idx_word = 3;
6857 int idx_in_out = 4;
6858 return peer_route_map_set_vty(
6859 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6860 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6861}
6862
d62a17ae 6863ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
6864 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6865 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6866 "Apply route map to neighbor\n"
6867 "Name of route map\n"
6868 "Apply map to incoming routes\n"
6869 "Apply map to outbound routes\n")
596c17ba 6870
718e3744 6871DEFUN (no_neighbor_route_map,
6872 no_neighbor_route_map_cmd,
9ccf14f7 6873 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6874 NO_STR
6875 NEIGHBOR_STR
6876 NEIGHBOR_ADDR_STR2
6877 "Apply route map to neighbor\n"
6878 "Name of route map\n"
6879 "Apply map to incoming routes\n"
2a3d5731 6880 "Apply map to outbound routes\n")
718e3744 6881{
d62a17ae 6882 int idx_peer = 2;
6883 int idx_in_out = 5;
6884 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
6885 bgp_node_afi(vty), bgp_node_safi(vty),
6886 argv[idx_in_out]->arg);
718e3744 6887}
6b0655a2 6888
d62a17ae 6889ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
6890 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6891 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6892 "Apply route map to neighbor\n"
6893 "Name of route map\n"
6894 "Apply map to incoming routes\n"
6895 "Apply map to outbound routes\n")
596c17ba 6896
718e3744 6897/* Set unsuppress-map to the peer. */
d62a17ae 6898static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
6899 afi_t afi, safi_t safi,
6900 const char *name_str)
718e3744 6901{
d62a17ae 6902 int ret;
6903 struct peer *peer;
1de27621 6904 struct route_map *route_map;
718e3744 6905
d62a17ae 6906 peer = peer_and_group_lookup_vty(vty, ip_str);
6907 if (!peer)
6908 return CMD_WARNING_CONFIG_FAILED;
718e3744 6909
1de27621
DA
6910 route_map = route_map_lookup_warn_noexist(vty, name_str);
6911 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 6912
d62a17ae 6913 return bgp_vty_return(vty, ret);
718e3744 6914}
6915
6916/* Unset route-map from the peer. */
d62a17ae 6917static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
6918 afi_t afi, safi_t safi)
718e3744 6919{
d62a17ae 6920 int ret;
6921 struct peer *peer;
718e3744 6922
d62a17ae 6923 peer = peer_and_group_lookup_vty(vty, ip_str);
6924 if (!peer)
6925 return CMD_WARNING_CONFIG_FAILED;
718e3744 6926
d62a17ae 6927 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 6928
d62a17ae 6929 return bgp_vty_return(vty, ret);
718e3744 6930}
6931
6932DEFUN (neighbor_unsuppress_map,
6933 neighbor_unsuppress_map_cmd,
9ccf14f7 6934 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6935 NEIGHBOR_STR
6936 NEIGHBOR_ADDR_STR2
6937 "Route-map to selectively unsuppress suppressed routes\n"
6938 "Name of route map\n")
6939{
d62a17ae 6940 int idx_peer = 1;
6941 int idx_word = 3;
6942 return peer_unsuppress_map_set_vty(
6943 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6944 argv[idx_word]->arg);
718e3744 6945}
6946
d62a17ae 6947ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
6948 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6950 "Route-map to selectively unsuppress suppressed routes\n"
6951 "Name of route map\n")
596c17ba 6952
718e3744 6953DEFUN (no_neighbor_unsuppress_map,
6954 no_neighbor_unsuppress_map_cmd,
9ccf14f7 6955 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6956 NO_STR
6957 NEIGHBOR_STR
6958 NEIGHBOR_ADDR_STR2
6959 "Route-map to selectively unsuppress suppressed routes\n"
6960 "Name of route map\n")
6961{
d62a17ae 6962 int idx_peer = 2;
6963 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
6964 bgp_node_afi(vty),
6965 bgp_node_safi(vty));
718e3744 6966}
6b0655a2 6967
d62a17ae 6968ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
6969 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6970 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6971 "Route-map to selectively unsuppress suppressed routes\n"
6972 "Name of route map\n")
596c17ba 6973
d62a17ae 6974static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
6975 afi_t afi, safi_t safi,
6976 const char *num_str,
6977 const char *threshold_str, int warning,
9cbd06e0
DA
6978 const char *restart_str,
6979 const char *force_str)
718e3744 6980{
d62a17ae 6981 int ret;
6982 struct peer *peer;
d7c0a89a
QY
6983 uint32_t max;
6984 uint8_t threshold;
6985 uint16_t restart;
718e3744 6986
d62a17ae 6987 peer = peer_and_group_lookup_vty(vty, ip_str);
6988 if (!peer)
6989 return CMD_WARNING_CONFIG_FAILED;
718e3744 6990
d62a17ae 6991 max = strtoul(num_str, NULL, 10);
6992 if (threshold_str)
6993 threshold = atoi(threshold_str);
6994 else
6995 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 6996
d62a17ae 6997 if (restart_str)
6998 restart = atoi(restart_str);
6999 else
7000 restart = 0;
0a486e5f 7001
d62a17ae 7002 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
9cbd06e0 7003 restart, force_str ? true : false);
718e3744 7004
d62a17ae 7005 return bgp_vty_return(vty, ret);
718e3744 7006}
7007
d62a17ae 7008static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7009 afi_t afi, safi_t safi)
718e3744 7010{
d62a17ae 7011 int ret;
7012 struct peer *peer;
718e3744 7013
d62a17ae 7014 peer = peer_and_group_lookup_vty(vty, ip_str);
7015 if (!peer)
7016 return CMD_WARNING_CONFIG_FAILED;
718e3744 7017
d62a17ae 7018 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 7019
d62a17ae 7020 return bgp_vty_return(vty, ret);
718e3744 7021}
7022
fde246e8
DA
7023/* Maximum number of prefix to be sent to the neighbor. */
7024DEFUN(neighbor_maximum_prefix_out,
7025 neighbor_maximum_prefix_out_cmd,
7026 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7027 NEIGHBOR_STR
7028 NEIGHBOR_ADDR_STR2
7029 "Maximum number of prefixes to be sent to this peer\n"
7030 "Maximum no. of prefix limit\n")
7031{
7032 int idx_peer = 1;
7033 int idx_number = 3;
7034 struct peer *peer;
7035 uint32_t max;
7036 afi_t afi = bgp_node_afi(vty);
7037 safi_t safi = bgp_node_safi(vty);
7038
7039 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7040 if (!peer)
7041 return CMD_WARNING_CONFIG_FAILED;
7042
7043 max = strtoul(argv[idx_number]->arg, NULL, 10);
7044
7045 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7046 peer->pmax_out[afi][safi] = max;
7047
7048 return CMD_SUCCESS;
7049}
7050
7051DEFUN(no_neighbor_maximum_prefix_out,
7052 no_neighbor_maximum_prefix_out_cmd,
7053 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7054 NO_STR
7055 NEIGHBOR_STR
7056 NEIGHBOR_ADDR_STR2
7057 "Maximum number of prefixes to be sent to this peer\n")
7058{
7059 int idx_peer = 2;
7060 struct peer *peer;
7061 afi_t afi = bgp_node_afi(vty);
7062 safi_t safi = bgp_node_safi(vty);
7063
7064 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7065 if (!peer)
7066 return CMD_WARNING_CONFIG_FAILED;
7067
ae00326a 7068 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
fde246e8
DA
7069 peer->pmax_out[afi][safi] = 0;
7070
7071 return CMD_SUCCESS;
7072}
7073
9cbd06e0
DA
7074/* Maximum number of prefix configuration. Prefix count is different
7075 for each peer configuration. So this configuration can be set for
718e3744 7076 each peer configuration. */
7077DEFUN (neighbor_maximum_prefix,
7078 neighbor_maximum_prefix_cmd,
9cbd06e0 7079 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
718e3744 7080 NEIGHBOR_STR
7081 NEIGHBOR_ADDR_STR2
7082 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7083 "maximum no. of prefix limit\n"
7084 "Force checking all received routes not only accepted\n")
718e3744 7085{
d62a17ae 7086 int idx_peer = 1;
7087 int idx_number = 3;
9cbd06e0
DA
7088 int idx_force = 0;
7089 char *force = NULL;
7090
7091 if (argv_find(argv, argc, "force", &idx_force))
7092 force = argv[idx_force]->arg;
7093
d62a17ae 7094 return peer_maximum_prefix_set_vty(
7095 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7096 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7097}
7098
d62a17ae 7099ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7100 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7101 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7102 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7103 "maximum no. of prefix limit\n"
7104 "Force checking all received routes not only accepted\n")
596c17ba 7105
e0701b79 7106DEFUN (neighbor_maximum_prefix_threshold,
7107 neighbor_maximum_prefix_threshold_cmd,
9cbd06e0 7108 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
e0701b79 7109 NEIGHBOR_STR
7110 NEIGHBOR_ADDR_STR2
7111 "Maximum number of prefix accept from this peer\n"
7112 "maximum no. of prefix limit\n"
9cbd06e0
DA
7113 "Threshold value (%) at which to generate a warning msg\n"
7114 "Force checking all received routes not only accepted\n")
e0701b79 7115{
d62a17ae 7116 int idx_peer = 1;
7117 int idx_number = 3;
7118 int idx_number_2 = 4;
9cbd06e0
DA
7119 int idx_force = 0;
7120 char *force = NULL;
7121
7122 if (argv_find(argv, argc, "force", &idx_force))
7123 force = argv[idx_force]->arg;
7124
d62a17ae 7125 return peer_maximum_prefix_set_vty(
7126 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7127 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7128}
e0701b79 7129
d62a17ae 7130ALIAS_HIDDEN(
7131 neighbor_maximum_prefix_threshold,
7132 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7133 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7134 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7135 "Maximum number of prefix accept from this peer\n"
7136 "maximum no. of prefix limit\n"
9cbd06e0
DA
7137 "Threshold value (%) at which to generate a warning msg\n"
7138 "Force checking all received routes not only accepted\n")
596c17ba 7139
718e3744 7140DEFUN (neighbor_maximum_prefix_warning,
7141 neighbor_maximum_prefix_warning_cmd,
9cbd06e0 7142 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
718e3744 7143 NEIGHBOR_STR
7144 NEIGHBOR_ADDR_STR2
7145 "Maximum number of prefix accept from this peer\n"
7146 "maximum no. of prefix limit\n"
9cbd06e0
DA
7147 "Only give warning message when limit is exceeded\n"
7148 "Force checking all received routes not only accepted\n")
718e3744 7149{
d62a17ae 7150 int idx_peer = 1;
7151 int idx_number = 3;
9cbd06e0
DA
7152 int idx_force = 0;
7153 char *force = NULL;
7154
7155 if (argv_find(argv, argc, "force", &idx_force))
7156 force = argv[idx_force]->arg;
7157
d62a17ae 7158 return peer_maximum_prefix_set_vty(
7159 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7160 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7161}
7162
d62a17ae 7163ALIAS_HIDDEN(
7164 neighbor_maximum_prefix_warning,
7165 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7166 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7167 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7168 "Maximum number of prefix accept from this peer\n"
7169 "maximum no. of prefix limit\n"
9cbd06e0
DA
7170 "Only give warning message when limit is exceeded\n"
7171 "Force checking all received routes not only accepted\n")
596c17ba 7172
e0701b79 7173DEFUN (neighbor_maximum_prefix_threshold_warning,
7174 neighbor_maximum_prefix_threshold_warning_cmd,
9cbd06e0 7175 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
e0701b79 7176 NEIGHBOR_STR
7177 NEIGHBOR_ADDR_STR2
7178 "Maximum number of prefix accept from this peer\n"
7179 "maximum no. of prefix limit\n"
7180 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7181 "Only give warning message when limit is exceeded\n"
7182 "Force checking all received routes not only accepted\n")
e0701b79 7183{
d62a17ae 7184 int idx_peer = 1;
7185 int idx_number = 3;
7186 int idx_number_2 = 4;
9cbd06e0
DA
7187 int idx_force = 0;
7188 char *force = NULL;
7189
7190 if (argv_find(argv, argc, "force", &idx_force))
7191 force = argv[idx_force]->arg;
7192
d62a17ae 7193 return peer_maximum_prefix_set_vty(
7194 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7195 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7196}
7197
d62a17ae 7198ALIAS_HIDDEN(
7199 neighbor_maximum_prefix_threshold_warning,
7200 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7201 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7202 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7203 "Maximum number of prefix accept from this peer\n"
7204 "maximum no. of prefix limit\n"
7205 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7206 "Only give warning message when limit is exceeded\n"
7207 "Force checking all received routes not only accepted\n")
596c17ba 7208
0a486e5f 7209DEFUN (neighbor_maximum_prefix_restart,
7210 neighbor_maximum_prefix_restart_cmd,
9cbd06e0 7211 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
0a486e5f 7212 NEIGHBOR_STR
7213 NEIGHBOR_ADDR_STR2
7214 "Maximum number of prefix accept from this peer\n"
7215 "maximum no. of prefix limit\n"
7216 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7217 "Restart interval in minutes\n"
7218 "Force checking all received routes not only accepted\n")
0a486e5f 7219{
d62a17ae 7220 int idx_peer = 1;
7221 int idx_number = 3;
7222 int idx_number_2 = 5;
9cbd06e0
DA
7223 int idx_force = 0;
7224 char *force = NULL;
7225
7226 if (argv_find(argv, argc, "force", &idx_force))
7227 force = argv[idx_force]->arg;
7228
d62a17ae 7229 return peer_maximum_prefix_set_vty(
7230 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7231 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7232}
7233
d62a17ae 7234ALIAS_HIDDEN(
7235 neighbor_maximum_prefix_restart,
7236 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7237 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7238 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7239 "Maximum number of prefix accept from this peer\n"
7240 "maximum no. of prefix limit\n"
7241 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7242 "Restart interval in minutes\n"
7243 "Force checking all received routes not only accepted\n")
596c17ba 7244
0a486e5f 7245DEFUN (neighbor_maximum_prefix_threshold_restart,
7246 neighbor_maximum_prefix_threshold_restart_cmd,
9cbd06e0 7247 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
0a486e5f 7248 NEIGHBOR_STR
7249 NEIGHBOR_ADDR_STR2
16cedbb0 7250 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 7251 "maximum no. of prefix limit\n"
7252 "Threshold value (%) at which to generate a warning msg\n"
7253 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7254 "Restart interval in minutes\n"
7255 "Force checking all received routes not only accepted\n")
0a486e5f 7256{
d62a17ae 7257 int idx_peer = 1;
7258 int idx_number = 3;
7259 int idx_number_2 = 4;
7260 int idx_number_3 = 6;
9cbd06e0
DA
7261 int idx_force = 0;
7262 char *force = NULL;
7263
7264 if (argv_find(argv, argc, "force", &idx_force))
7265 force = argv[idx_force]->arg;
7266
d62a17ae 7267 return peer_maximum_prefix_set_vty(
7268 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7269 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
9cbd06e0 7270 argv[idx_number_3]->arg, force);
d62a17ae 7271}
7272
7273ALIAS_HIDDEN(
7274 neighbor_maximum_prefix_threshold_restart,
7275 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7276 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7277 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7278 "Maximum number of prefixes to accept from this peer\n"
7279 "maximum no. of prefix limit\n"
7280 "Threshold value (%) at which to generate a warning msg\n"
7281 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7282 "Restart interval in minutes\n"
7283 "Force checking all received routes not only accepted\n")
596c17ba 7284
718e3744 7285DEFUN (no_neighbor_maximum_prefix,
7286 no_neighbor_maximum_prefix_cmd,
9cbd06e0 7287 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
718e3744 7288 NO_STR
7289 NEIGHBOR_STR
7290 NEIGHBOR_ADDR_STR2
16cedbb0 7291 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
7292 "maximum no. of prefix limit\n"
7293 "Threshold value (%) at which to generate a warning msg\n"
7294 "Restart bgp connection after limit is exceeded\n"
16cedbb0 7295 "Restart interval in minutes\n"
9cbd06e0
DA
7296 "Only give warning message when limit is exceeded\n"
7297 "Force checking all received routes not only accepted\n")
718e3744 7298{
d62a17ae 7299 int idx_peer = 2;
7300 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7301 bgp_node_afi(vty),
7302 bgp_node_safi(vty));
718e3744 7303}
e52702f2 7304
d62a17ae 7305ALIAS_HIDDEN(
7306 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7307 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7308 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7309 "Maximum number of prefixes to accept from this peer\n"
7310 "maximum no. of prefix limit\n"
7311 "Threshold value (%) at which to generate a warning msg\n"
7312 "Restart bgp connection after limit is exceeded\n"
7313 "Restart interval in minutes\n"
9cbd06e0
DA
7314 "Only give warning message when limit is exceeded\n"
7315 "Force checking all received routes not only accepted\n")
596c17ba 7316
718e3744 7317
718e3744 7318/* "neighbor allowas-in" */
7319DEFUN (neighbor_allowas_in,
7320 neighbor_allowas_in_cmd,
fd8503f5 7321 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7322 NEIGHBOR_STR
7323 NEIGHBOR_ADDR_STR2
31500417 7324 "Accept as-path with my AS present in it\n"
f79f7a7b 7325 "Number of occurrences of AS number\n"
fd8503f5 7326 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7327{
d62a17ae 7328 int idx_peer = 1;
7329 int idx_number_origin = 3;
7330 int ret;
7331 int origin = 0;
7332 struct peer *peer;
7333 int allow_num = 0;
7334
7335 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7336 if (!peer)
7337 return CMD_WARNING_CONFIG_FAILED;
7338
7339 if (argc <= idx_number_origin)
7340 allow_num = 3;
7341 else {
7342 if (argv[idx_number_origin]->type == WORD_TKN)
7343 origin = 1;
7344 else
7345 allow_num = atoi(argv[idx_number_origin]->arg);
7346 }
7347
7348 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7349 allow_num, origin);
7350
7351 return bgp_vty_return(vty, ret);
7352}
7353
7354ALIAS_HIDDEN(
7355 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7356 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7357 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7358 "Accept as-path with my AS present in it\n"
f79f7a7b 7359 "Number of occurrences of AS number\n"
d62a17ae 7360 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7361
718e3744 7362DEFUN (no_neighbor_allowas_in,
7363 no_neighbor_allowas_in_cmd,
fd8503f5 7364 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7365 NO_STR
7366 NEIGHBOR_STR
7367 NEIGHBOR_ADDR_STR2
8334fd5a 7368 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7369 "Number of occurrences of AS number\n"
fd8503f5 7370 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7371{
d62a17ae 7372 int idx_peer = 2;
7373 int ret;
7374 struct peer *peer;
718e3744 7375
d62a17ae 7376 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7377 if (!peer)
7378 return CMD_WARNING_CONFIG_FAILED;
718e3744 7379
d62a17ae 7380 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
7381 bgp_node_safi(vty));
718e3744 7382
d62a17ae 7383 return bgp_vty_return(vty, ret);
718e3744 7384}
6b0655a2 7385
d62a17ae 7386ALIAS_HIDDEN(
7387 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
7388 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7389 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7390 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7391 "Number of occurrences of AS number\n"
d62a17ae 7392 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7393
fa411a21
NH
7394DEFUN (neighbor_ttl_security,
7395 neighbor_ttl_security_cmd,
7ebe625c 7396 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 7397 NEIGHBOR_STR
7ebe625c 7398 NEIGHBOR_ADDR_STR2
16cedbb0 7399 "BGP ttl-security parameters\n"
d7fa34c1
QY
7400 "Specify the maximum number of hops to the BGP peer\n"
7401 "Number of hops to BGP peer\n")
fa411a21 7402{
d62a17ae 7403 int idx_peer = 1;
7404 int idx_number = 4;
7405 struct peer *peer;
7406 int gtsm_hops;
7407
7408 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7409 if (!peer)
7410 return CMD_WARNING_CONFIG_FAILED;
7411
7412 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
7413
7ebe625c
QY
7414 /*
7415 * If 'neighbor swpX', then this is for directly connected peers,
7416 * we should not accept a ttl-security hops value greater than 1.
7417 */
e2521429 7418 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7ebe625c
QY
7419 vty_out(vty,
7420 "%s is directly connected peer, hops cannot exceed 1\n",
7421 argv[idx_peer]->arg);
7422 return CMD_WARNING_CONFIG_FAILED;
7423 }
7424
d62a17ae 7425 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
7426}
7427
7428DEFUN (no_neighbor_ttl_security,
7429 no_neighbor_ttl_security_cmd,
7ebe625c 7430 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
7431 NO_STR
7432 NEIGHBOR_STR
7ebe625c 7433 NEIGHBOR_ADDR_STR2
16cedbb0 7434 "BGP ttl-security parameters\n"
3a2d747c
QY
7435 "Specify the maximum number of hops to the BGP peer\n"
7436 "Number of hops to BGP peer\n")
fa411a21 7437{
d62a17ae 7438 int idx_peer = 2;
7439 struct peer *peer;
fa411a21 7440
d62a17ae 7441 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7442 if (!peer)
7443 return CMD_WARNING_CONFIG_FAILED;
fa411a21 7444
d62a17ae 7445 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 7446}
6b0655a2 7447
adbac85e
DW
7448DEFUN (neighbor_addpath_tx_all_paths,
7449 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7450 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7451 NEIGHBOR_STR
7452 NEIGHBOR_ADDR_STR2
7453 "Use addpath to advertise all paths to a neighbor\n")
7454{
d62a17ae 7455 int idx_peer = 1;
7456 struct peer *peer;
adbac85e 7457
d62a17ae 7458 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7459 if (!peer)
7460 return CMD_WARNING_CONFIG_FAILED;
adbac85e 7461
dcc68b5e
MS
7462 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7463 BGP_ADDPATH_ALL);
7464 return CMD_SUCCESS;
adbac85e
DW
7465}
7466
d62a17ae 7467ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
7468 neighbor_addpath_tx_all_paths_hidden_cmd,
7469 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7470 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7471 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7472
adbac85e
DW
7473DEFUN (no_neighbor_addpath_tx_all_paths,
7474 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7475 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7476 NO_STR
7477 NEIGHBOR_STR
7478 NEIGHBOR_ADDR_STR2
7479 "Use addpath to advertise all paths to a neighbor\n")
7480{
d62a17ae 7481 int idx_peer = 2;
dcc68b5e
MS
7482 struct peer *peer;
7483
7484 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7485 if (!peer)
7486 return CMD_WARNING_CONFIG_FAILED;
7487
7488 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7489 != BGP_ADDPATH_ALL) {
7490 vty_out(vty,
7491 "%% Peer not currently configured to transmit all paths.");
7492 return CMD_WARNING_CONFIG_FAILED;
7493 }
7494
7495 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7496 BGP_ADDPATH_NONE);
7497
7498 return CMD_SUCCESS;
adbac85e
DW
7499}
7500
d62a17ae 7501ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7502 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7503 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7504 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7505 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7506
06370dac
DW
7507DEFUN (neighbor_addpath_tx_bestpath_per_as,
7508 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7509 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7510 NEIGHBOR_STR
7511 NEIGHBOR_ADDR_STR2
7512 "Use addpath to advertise the bestpath per each neighboring AS\n")
7513{
d62a17ae 7514 int idx_peer = 1;
7515 struct peer *peer;
06370dac 7516
d62a17ae 7517 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7518 if (!peer)
7519 return CMD_WARNING_CONFIG_FAILED;
06370dac 7520
dcc68b5e
MS
7521 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7522 BGP_ADDPATH_BEST_PER_AS);
7523
7524 return CMD_SUCCESS;
06370dac
DW
7525}
7526
d62a17ae 7527ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7528 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7529 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7530 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7531 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7532
06370dac
DW
7533DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7534 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7535 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7536 NO_STR
7537 NEIGHBOR_STR
7538 NEIGHBOR_ADDR_STR2
7539 "Use addpath to advertise the bestpath per each neighboring AS\n")
7540{
d62a17ae 7541 int idx_peer = 2;
dcc68b5e
MS
7542 struct peer *peer;
7543
7544 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7545 if (!peer)
7546 return CMD_WARNING_CONFIG_FAILED;
7547
7548 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7549 != BGP_ADDPATH_BEST_PER_AS) {
7550 vty_out(vty,
7551 "%% Peer not currently configured to transmit all best path per as.");
7552 return CMD_WARNING_CONFIG_FAILED;
7553 }
7554
7555 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7556 BGP_ADDPATH_NONE);
7557
7558 return CMD_SUCCESS;
06370dac
DW
7559}
7560
d62a17ae 7561ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7562 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7563 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7564 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7565 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7566
2b31007c
RZ
7567DEFPY(
7568 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7569 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7570 NEIGHBOR_STR
7571 NEIGHBOR_ADDR_STR2
7572 "Detect AS loops before sending to neighbor\n")
7573{
7574 struct peer *peer;
7575
7576 peer = peer_and_group_lookup_vty(vty, neighbor);
7577 if (!peer)
7578 return CMD_WARNING_CONFIG_FAILED;
7579
7580 peer->as_path_loop_detection = true;
7581
7582 return CMD_SUCCESS;
7583}
7584
7585DEFPY(
7586 no_neighbor_aspath_loop_detection,
7587 no_neighbor_aspath_loop_detection_cmd,
7588 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7589 NO_STR
7590 NEIGHBOR_STR
7591 NEIGHBOR_ADDR_STR2
7592 "Detect AS loops before sending to neighbor\n")
7593{
7594 struct peer *peer;
7595
7596 peer = peer_and_group_lookup_vty(vty, neighbor);
7597 if (!peer)
7598 return CMD_WARNING_CONFIG_FAILED;
7599
7600 peer->as_path_loop_detection = false;
7601
7602 return CMD_SUCCESS;
7603}
7604
b9c7bc5a 7605static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 7606 struct ecommunity **list, bool is_rt6)
ddb5b488 7607{
b9c7bc5a
PZ
7608 struct ecommunity *ecom = NULL;
7609 struct ecommunity *ecomadd;
ddb5b488 7610
b9c7bc5a 7611 for (; argc; --argc, ++argv) {
9a659715
PG
7612 if (is_rt6)
7613 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
7614 ECOMMUNITY_ROUTE_TARGET,
7615 0);
7616 else
7617 ecomadd = ecommunity_str2com(argv[0]->arg,
7618 ECOMMUNITY_ROUTE_TARGET,
7619 0);
b9c7bc5a
PZ
7620 if (!ecomadd) {
7621 vty_out(vty, "Malformed community-list value\n");
7622 if (ecom)
7623 ecommunity_free(&ecom);
7624 return CMD_WARNING_CONFIG_FAILED;
7625 }
ddb5b488 7626
b9c7bc5a
PZ
7627 if (ecom) {
7628 ecommunity_merge(ecom, ecomadd);
7629 ecommunity_free(&ecomadd);
7630 } else {
7631 ecom = ecomadd;
7632 }
7633 }
7634
7635 if (*list) {
7636 ecommunity_free(&*list);
ddb5b488 7637 }
b9c7bc5a
PZ
7638 *list = ecom;
7639
7640 return CMD_SUCCESS;
ddb5b488
PZ
7641}
7642
0ca70ba5
DS
7643/*
7644 * v2vimport is true if we are handling a `import vrf ...` command
7645 */
7646static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 7647{
0ca70ba5
DS
7648 afi_t afi;
7649
ddb5b488 7650 switch (vty->node) {
b9c7bc5a 7651 case BGP_IPV4_NODE:
0ca70ba5
DS
7652 afi = AFI_IP;
7653 break;
b9c7bc5a 7654 case BGP_IPV6_NODE:
0ca70ba5
DS
7655 afi = AFI_IP6;
7656 break;
ddb5b488
PZ
7657 default:
7658 vty_out(vty,
b9c7bc5a 7659 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 7660 return AFI_MAX;
ddb5b488 7661 }
69b07479 7662
0ca70ba5
DS
7663 if (!v2vimport) {
7664 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7665 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7666 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7667 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7668 vty_out(vty,
7669 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7670 return AFI_MAX;
7671 }
7672 } else {
7673 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7674 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7675 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7676 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7677 vty_out(vty,
7678 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7679 return AFI_MAX;
7680 }
7681 }
7682 return afi;
ddb5b488
PZ
7683}
7684
b9c7bc5a
PZ
7685DEFPY (af_rd_vpn_export,
7686 af_rd_vpn_export_cmd,
7687 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7688 NO_STR
ddb5b488 7689 "Specify route distinguisher\n"
b9c7bc5a
PZ
7690 "Between current address-family and vpn\n"
7691 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7692 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7693{
7694 VTY_DECLVAR_CONTEXT(bgp, bgp);
7695 struct prefix_rd prd;
7696 int ret;
ddb5b488 7697 afi_t afi;
b9c7bc5a 7698 int idx = 0;
c6423c31 7699 bool yes = true;
ddb5b488 7700
b9c7bc5a 7701 if (argv_find(argv, argc, "no", &idx))
c6423c31 7702 yes = false;
b9c7bc5a
PZ
7703
7704 if (yes) {
7705 ret = str2prefix_rd(rd_str, &prd);
7706 if (!ret) {
7707 vty_out(vty, "%% Malformed rd\n");
7708 return CMD_WARNING_CONFIG_FAILED;
7709 }
ddb5b488
PZ
7710 }
7711
0ca70ba5 7712 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7713 if (afi == AFI_MAX)
7714 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7715
69b07479
DS
7716 /*
7717 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7718 */
7719 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7720 bgp_get_default(), bgp);
ddb5b488 7721
69b07479
DS
7722 if (yes) {
7723 bgp->vpn_policy[afi].tovpn_rd = prd;
7724 SET_FLAG(bgp->vpn_policy[afi].flags,
7725 BGP_VPN_POLICY_TOVPN_RD_SET);
7726 } else {
7727 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7728 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
7729 }
7730
69b07479
DS
7731 /* post-change: re-export vpn routes */
7732 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7733 bgp_get_default(), bgp);
7734
ddb5b488
PZ
7735 return CMD_SUCCESS;
7736}
7737
b9c7bc5a
PZ
7738ALIAS (af_rd_vpn_export,
7739 af_no_rd_vpn_export_cmd,
7740 "no rd vpn export",
ddb5b488 7741 NO_STR
b9c7bc5a
PZ
7742 "Specify route distinguisher\n"
7743 "Between current address-family and vpn\n"
7744 "For routes leaked from current address-family to vpn\n")
ddb5b488 7745
b9c7bc5a
PZ
7746DEFPY (af_label_vpn_export,
7747 af_label_vpn_export_cmd,
e70e9f8e 7748 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 7749 NO_STR
ddb5b488 7750 "label value for VRF\n"
b9c7bc5a
PZ
7751 "Between current address-family and vpn\n"
7752 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
7753 "Label Value <0-1048575>\n"
7754 "Automatically assign a label\n")
ddb5b488
PZ
7755{
7756 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7757 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 7758 afi_t afi;
b9c7bc5a 7759 int idx = 0;
c6423c31 7760 bool yes = true;
b9c7bc5a
PZ
7761
7762 if (argv_find(argv, argc, "no", &idx))
c6423c31 7763 yes = false;
ddb5b488 7764
21a16cc2
PZ
7765 /* If "no ...", squash trailing parameter */
7766 if (!yes)
7767 label_auto = NULL;
7768
e70e9f8e
PZ
7769 if (yes) {
7770 if (!label_auto)
7771 label = label_val; /* parser should force unsigned */
7772 }
ddb5b488 7773
0ca70ba5 7774 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7775 if (afi == AFI_MAX)
7776 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 7777
e70e9f8e 7778
69b07479
DS
7779 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7780 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
7781 /* no change */
7782 return CMD_SUCCESS;
e70e9f8e 7783
69b07479
DS
7784 /*
7785 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7786 */
7787 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7788 bgp_get_default(), bgp);
7789
7790 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7791 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
7792
7793 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
7794
7795 /*
7796 * label has previously been automatically
7797 * assigned by labelpool: release it
7798 *
7799 * NB if tovpn_label == MPLS_LABEL_NONE it
7800 * means the automatic assignment is in flight
7801 * and therefore the labelpool callback must
7802 * detect that the auto label is not needed.
7803 */
7804
7805 bgp_lp_release(LP_TYPE_VRF,
7806 &bgp->vpn_policy[afi],
7807 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 7808 }
69b07479
DS
7809 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7810 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7811 }
ddb5b488 7812
69b07479
DS
7813 bgp->vpn_policy[afi].tovpn_label = label;
7814 if (label_auto) {
7815 SET_FLAG(bgp->vpn_policy[afi].flags,
7816 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7817 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
7818 vpn_leak_label_callback);
ddb5b488
PZ
7819 }
7820
69b07479
DS
7821 /* post-change: re-export vpn routes */
7822 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7823 bgp_get_default(), bgp);
7824
ddb5b488
PZ
7825 return CMD_SUCCESS;
7826}
7827
b9c7bc5a
PZ
7828ALIAS (af_label_vpn_export,
7829 af_no_label_vpn_export_cmd,
7830 "no label vpn export",
7831 NO_STR
7832 "label value for VRF\n"
7833 "Between current address-family and vpn\n"
7834 "For routes leaked from current address-family to vpn\n")
ddb5b488 7835
b9c7bc5a
PZ
7836DEFPY (af_nexthop_vpn_export,
7837 af_nexthop_vpn_export_cmd,
8c85ca28 7838 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 7839 NO_STR
ddb5b488 7840 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
7841 "Between current address-family and vpn\n"
7842 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7843 "IPv4 prefix\n"
7844 "IPv6 prefix\n")
7845{
7846 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 7847 afi_t afi;
ddb5b488
PZ
7848 struct prefix p;
7849
8c85ca28
QY
7850 if (!no) {
7851 if (!nexthop_su) {
7852 vty_out(vty, "%% Nexthop required\n");
7853 return CMD_WARNING_CONFIG_FAILED;
7854 }
8c85ca28 7855 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
7856 return CMD_WARNING_CONFIG_FAILED;
7857 }
ddb5b488 7858
0ca70ba5 7859 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7860 if (afi == AFI_MAX)
7861 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7862
69b07479
DS
7863 /*
7864 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7865 */
7866 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7867 bgp_get_default(), bgp);
ddb5b488 7868
8c85ca28 7869 if (!no) {
69b07479
DS
7870 bgp->vpn_policy[afi].tovpn_nexthop = p;
7871 SET_FLAG(bgp->vpn_policy[afi].flags,
7872 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7873 } else {
7874 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7875 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
7876 }
7877
69b07479
DS
7878 /* post-change: re-export vpn routes */
7879 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7880 bgp_get_default(), bgp);
7881
ddb5b488
PZ
7882 return CMD_SUCCESS;
7883}
7884
b9c7bc5a 7885static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 7886{
b9c7bc5a
PZ
7887 if (!strcmp(dstr, "import")) {
7888 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7889 } else if (!strcmp(dstr, "export")) {
7890 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7891 } else if (!strcmp(dstr, "both")) {
7892 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7893 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7894 } else {
7895 vty_out(vty, "%% direction parse error\n");
7896 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7897 }
ddb5b488
PZ
7898 return CMD_SUCCESS;
7899}
7900
b9c7bc5a
PZ
7901DEFPY (af_rt_vpn_imexport,
7902 af_rt_vpn_imexport_cmd,
7903 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
7904 NO_STR
7905 "Specify route target list\n"
ddb5b488 7906 "Specify route target list\n"
b9c7bc5a
PZ
7907 "Between current address-family and vpn\n"
7908 "For routes leaked from vpn to current address-family: match any\n"
7909 "For routes leaked from current address-family to vpn: set\n"
7910 "both import: match any and export: set\n"
ddb5b488
PZ
7911 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7912{
7913 VTY_DECLVAR_CONTEXT(bgp, bgp);
7914 int ret;
7915 struct ecommunity *ecom = NULL;
7916 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7917 vpn_policy_direction_t dir;
7918 afi_t afi;
7919 int idx = 0;
c6423c31 7920 bool yes = true;
ddb5b488 7921
b9c7bc5a 7922 if (argv_find(argv, argc, "no", &idx))
c6423c31 7923 yes = false;
b9c7bc5a 7924
0ca70ba5 7925 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7926 if (afi == AFI_MAX)
7927 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7928
b9c7bc5a 7929 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7930 if (ret != CMD_SUCCESS)
7931 return ret;
7932
b9c7bc5a
PZ
7933 if (yes) {
7934 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7935 vty_out(vty, "%% Missing RTLIST\n");
7936 return CMD_WARNING_CONFIG_FAILED;
7937 }
c6423c31 7938 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
7939 if (ret != CMD_SUCCESS) {
7940 return ret;
7941 }
ddb5b488
PZ
7942 }
7943
69b07479
DS
7944 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7945 if (!dodir[dir])
ddb5b488 7946 continue;
ddb5b488 7947
69b07479 7948 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7949
69b07479
DS
7950 if (yes) {
7951 if (bgp->vpn_policy[afi].rtlist[dir])
7952 ecommunity_free(
7953 &bgp->vpn_policy[afi].rtlist[dir]);
7954 bgp->vpn_policy[afi].rtlist[dir] =
7955 ecommunity_dup(ecom);
7956 } else {
7957 if (bgp->vpn_policy[afi].rtlist[dir])
7958 ecommunity_free(
7959 &bgp->vpn_policy[afi].rtlist[dir]);
7960 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 7961 }
69b07479
DS
7962
7963 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7964 }
69b07479 7965
d555f3e9
PZ
7966 if (ecom)
7967 ecommunity_free(&ecom);
ddb5b488
PZ
7968
7969 return CMD_SUCCESS;
7970}
7971
b9c7bc5a
PZ
7972ALIAS (af_rt_vpn_imexport,
7973 af_no_rt_vpn_imexport_cmd,
7974 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
7975 NO_STR
7976 "Specify route target list\n"
b9c7bc5a
PZ
7977 "Specify route target list\n"
7978 "Between current address-family and vpn\n"
7979 "For routes leaked from vpn to current address-family\n"
7980 "For routes leaked from current address-family to vpn\n"
7981 "both import and export\n")
7982
7983DEFPY (af_route_map_vpn_imexport,
7984 af_route_map_vpn_imexport_cmd,
7985/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
7986 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
7987 NO_STR
ddb5b488 7988 "Specify route map\n"
b9c7bc5a
PZ
7989 "Between current address-family and vpn\n"
7990 "For routes leaked from vpn to current address-family\n"
7991 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7992 "name of route-map\n")
7993{
7994 VTY_DECLVAR_CONTEXT(bgp, bgp);
7995 int ret;
7996 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7997 vpn_policy_direction_t dir;
7998 afi_t afi;
ddb5b488 7999 int idx = 0;
c6423c31 8000 bool yes = true;
ddb5b488 8001
b9c7bc5a 8002 if (argv_find(argv, argc, "no", &idx))
c6423c31 8003 yes = false;
b9c7bc5a 8004
0ca70ba5 8005 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8006 if (afi == AFI_MAX)
8007 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8008
b9c7bc5a 8009 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8010 if (ret != CMD_SUCCESS)
8011 return ret;
8012
69b07479
DS
8013 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8014 if (!dodir[dir])
ddb5b488 8015 continue;
ddb5b488 8016
69b07479 8017 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8018
69b07479
DS
8019 if (yes) {
8020 if (bgp->vpn_policy[afi].rmap_name[dir])
8021 XFREE(MTYPE_ROUTE_MAP_NAME,
8022 bgp->vpn_policy[afi].rmap_name[dir]);
8023 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8024 MTYPE_ROUTE_MAP_NAME, rmap_str);
8025 bgp->vpn_policy[afi].rmap[dir] =
1de27621 8026 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
8027 if (!bgp->vpn_policy[afi].rmap[dir])
8028 return CMD_SUCCESS;
8029 } else {
8030 if (bgp->vpn_policy[afi].rmap_name[dir])
8031 XFREE(MTYPE_ROUTE_MAP_NAME,
8032 bgp->vpn_policy[afi].rmap_name[dir]);
8033 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8034 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 8035 }
69b07479
DS
8036
8037 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
8038 }
8039
8040 return CMD_SUCCESS;
8041}
8042
b9c7bc5a
PZ
8043ALIAS (af_route_map_vpn_imexport,
8044 af_no_route_map_vpn_imexport_cmd,
8045 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8046 NO_STR
8047 "Specify route map\n"
b9c7bc5a
PZ
8048 "Between current address-family and vpn\n"
8049 "For routes leaked from vpn to current address-family\n"
8050 "For routes leaked from current address-family to vpn\n")
8051
bb4f6190 8052DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8053 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8054 "Import routes from another VRF\n"
8055 "Vrf routes being filtered\n"
8056 "Specify route map\n"
8057 "name of route-map\n")
8058{
8059 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8060 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8061 afi_t afi;
bb4f6190
DS
8062 struct bgp *bgp_default;
8063
0ca70ba5 8064 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8065 if (afi == AFI_MAX)
8066 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8067
8068 bgp_default = bgp_get_default();
8069 if (!bgp_default) {
8070 int32_t ret;
8071 as_t as = bgp->as;
8072
8073 /* Auto-create assuming the same AS */
5d5393b9
DL
8074 ret = bgp_get_vty(&bgp_default, &as, NULL,
8075 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8076
8077 if (ret) {
8078 vty_out(vty,
8079 "VRF default is not configured as a bgp instance\n");
8080 return CMD_WARNING;
8081 }
8082 }
8083
69b07479 8084 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8085
ae6a6fb4
DS
8086 if (bgp->vpn_policy[afi].rmap_name[dir])
8087 XFREE(MTYPE_ROUTE_MAP_NAME,
8088 bgp->vpn_policy[afi].rmap_name[dir]);
8089 bgp->vpn_policy[afi].rmap_name[dir] =
8090 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8091 bgp->vpn_policy[afi].rmap[dir] =
8092 route_map_lookup_warn_noexist(vty, rmap_str);
8093 if (!bgp->vpn_policy[afi].rmap[dir])
8094 return CMD_SUCCESS;
8095
8096 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8097 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8098
69b07479
DS
8099 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8100
bb4f6190
DS
8101 return CMD_SUCCESS;
8102}
8103
ae6a6fb4
DS
8104DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8105 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8106 NO_STR
8107 "Import routes from another VRF\n"
8108 "Vrf routes being filtered\n"
ae6a6fb4
DS
8109 "Specify route map\n"
8110 "name of route-map\n")
8111{
8112 VTY_DECLVAR_CONTEXT(bgp, bgp);
8113 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8114 afi_t afi;
8115
8116 afi = vpn_policy_getafi(vty, bgp, true);
8117 if (afi == AFI_MAX)
8118 return CMD_WARNING_CONFIG_FAILED;
8119
8120 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8121
8122 if (bgp->vpn_policy[afi].rmap_name[dir])
8123 XFREE(MTYPE_ROUTE_MAP_NAME,
8124 bgp->vpn_policy[afi].rmap_name[dir]);
8125 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8126 bgp->vpn_policy[afi].rmap[dir] = NULL;
8127
8128 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8129 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8130 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8131
8132 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8133
8134 return CMD_SUCCESS;
8135}
bb4f6190 8136
4d1b335c
DA
8137DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8138 "[no] import vrf VIEWVRFNAME$import_name",
8139 NO_STR
8140 "Import routes from another VRF\n"
8141 "VRF to import from\n"
8142 "The name of the VRF\n")
12a844a5
DS
8143{
8144 VTY_DECLVAR_CONTEXT(bgp, bgp);
8145 struct listnode *node;
79ef8664
DS
8146 struct bgp *vrf_bgp, *bgp_default;
8147 int32_t ret = 0;
8148 as_t as = bgp->as;
12a844a5
DS
8149 bool remove = false;
8150 int32_t idx = 0;
8151 char *vname;
a8dadcf6 8152 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8153 safi_t safi;
8154 afi_t afi;
8155
867f0cca 8156 if (import_name == NULL) {
8157 vty_out(vty, "%% Missing import name\n");
8158 return CMD_WARNING;
8159 }
8160
ae6a6fb4
DS
8161 if (strcmp(import_name, "route-map") == 0) {
8162 vty_out(vty, "%% Must include route-map name\n");
8163 return CMD_WARNING;
8164 }
8165
12a844a5
DS
8166 if (argv_find(argv, argc, "no", &idx))
8167 remove = true;
8168
0ca70ba5
DS
8169 afi = vpn_policy_getafi(vty, bgp, true);
8170 if (afi == AFI_MAX)
8171 return CMD_WARNING_CONFIG_FAILED;
8172
12a844a5
DS
8173 safi = bgp_node_safi(vty);
8174
25679caa 8175 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 8176 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
8177 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8178 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8179 remove ? "unimport" : "import", import_name);
8180 return CMD_WARNING;
8181 }
8182
79ef8664
DS
8183 bgp_default = bgp_get_default();
8184 if (!bgp_default) {
8185 /* Auto-create assuming the same AS */
5d5393b9
DL
8186 ret = bgp_get_vty(&bgp_default, &as, NULL,
8187 BGP_INSTANCE_TYPE_DEFAULT);
79ef8664
DS
8188
8189 if (ret) {
8190 vty_out(vty,
8191 "VRF default is not configured as a bgp instance\n");
8192 return CMD_WARNING;
8193 }
8194 }
8195
12a844a5
DS
8196 vrf_bgp = bgp_lookup_by_name(import_name);
8197 if (!vrf_bgp) {
5742e42b 8198 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
8199 vrf_bgp = bgp_default;
8200 else
0fb8d6e6 8201 /* Auto-create assuming the same AS */
5d5393b9 8202 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 8203
6e2c7fe6 8204 if (ret) {
020a3f60
DS
8205 vty_out(vty,
8206 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
8207 import_name);
8208 return CMD_WARNING;
8209 }
12a844a5
DS
8210 }
8211
12a844a5 8212 if (remove) {
44338987 8213 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 8214 } else {
44338987 8215 /* Already importing from "import_vrf"? */
12a844a5
DS
8216 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8217 vname)) {
8218 if (strcmp(vname, import_name) == 0)
8219 return CMD_WARNING;
8220 }
8221
44338987 8222 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
8223 }
8224
8225 return CMD_SUCCESS;
8226}
8227
b9c7bc5a
PZ
8228/* This command is valid only in a bgp vrf instance or the default instance */
8229DEFPY (bgp_imexport_vpn,
8230 bgp_imexport_vpn_cmd,
8231 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
8232 NO_STR
8233 "Import routes to this address-family\n"
8234 "Export routes from this address-family\n"
8235 "to/from default instance VPN RIB\n")
ddb5b488
PZ
8236{
8237 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8238 int previous_state;
ddb5b488 8239 afi_t afi;
b9c7bc5a 8240 safi_t safi;
ddb5b488 8241 int idx = 0;
c6423c31 8242 bool yes = true;
b9c7bc5a
PZ
8243 int flag;
8244 vpn_policy_direction_t dir;
ddb5b488 8245
b9c7bc5a 8246 if (argv_find(argv, argc, "no", &idx))
c6423c31 8247 yes = false;
ddb5b488 8248
b9c7bc5a
PZ
8249 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
8250 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 8251
b9c7bc5a
PZ
8252 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
8253 return CMD_WARNING_CONFIG_FAILED;
8254 }
ddb5b488 8255
b9c7bc5a
PZ
8256 afi = bgp_node_afi(vty);
8257 safi = bgp_node_safi(vty);
8258 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
8259 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
8260 return CMD_WARNING_CONFIG_FAILED;
8261 }
ddb5b488 8262
b9c7bc5a
PZ
8263 if (!strcmp(direction_str, "import")) {
8264 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
8265 dir = BGP_VPN_POLICY_DIR_FROMVPN;
8266 } else if (!strcmp(direction_str, "export")) {
8267 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
8268 dir = BGP_VPN_POLICY_DIR_TOVPN;
8269 } else {
8270 vty_out(vty, "%% unknown direction %s\n", direction_str);
8271 return CMD_WARNING_CONFIG_FAILED;
8272 }
8273
8274 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 8275
b9c7bc5a
PZ
8276 if (yes) {
8277 SET_FLAG(bgp->af_flags[afi][safi], flag);
8278 if (!previous_state) {
8279 /* trigger export current vrf */
ddb5b488
PZ
8280 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8281 }
b9c7bc5a
PZ
8282 } else {
8283 if (previous_state) {
8284 /* trigger un-export current vrf */
8285 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8286 }
8287 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
8288 }
8289
8290 return CMD_SUCCESS;
8291}
8292
301ad80a
PG
8293DEFPY (af_routetarget_import,
8294 af_routetarget_import_cmd,
9a659715 8295 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
8296 NO_STR
8297 "Specify route target list\n"
8298 "Specify route target list\n"
9a659715
PG
8299 "Specify route target list\n"
8300 "Specify route target list\n"
301ad80a
PG
8301 "Flow-spec redirect type route target\n"
8302 "Import routes to this address-family\n"
9a659715 8303 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
8304{
8305 VTY_DECLVAR_CONTEXT(bgp, bgp);
8306 int ret;
8307 struct ecommunity *ecom = NULL;
301ad80a 8308 afi_t afi;
9a659715 8309 int idx = 0, idx_unused = 0;
c6423c31
PG
8310 bool yes = true;
8311 bool rt6 = false;
301ad80a
PG
8312
8313 if (argv_find(argv, argc, "no", &idx))
c6423c31 8314 yes = false;
301ad80a 8315
9a659715
PG
8316 if (argv_find(argv, argc, "rt6", &idx_unused) ||
8317 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 8318 rt6 = true;
301ad80a 8319
0ca70ba5 8320 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8321 if (afi == AFI_MAX)
8322 return CMD_WARNING_CONFIG_FAILED;
8323
9a659715
PG
8324 if (rt6 && afi != AFI_IP6)
8325 return CMD_WARNING_CONFIG_FAILED;
8326
301ad80a
PG
8327 if (yes) {
8328 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8329 vty_out(vty, "%% Missing RTLIST\n");
8330 return CMD_WARNING_CONFIG_FAILED;
8331 }
9a659715 8332 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
8333 if (ret != CMD_SUCCESS)
8334 return ret;
8335 }
69b07479
DS
8336
8337 if (yes) {
8338 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8339 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8340 .import_redirect_rtlist);
69b07479
DS
8341 bgp->vpn_policy[afi].import_redirect_rtlist =
8342 ecommunity_dup(ecom);
8343 } else {
8344 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8345 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8346 .import_redirect_rtlist);
69b07479 8347 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 8348 }
69b07479 8349
301ad80a
PG
8350 if (ecom)
8351 ecommunity_free(&ecom);
8352
8353 return CMD_SUCCESS;
8354}
8355
505e5056 8356DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 8357 address_family_ipv4_safi_cmd,
8358 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8359 "Enter Address Family command mode\n"
8360 "Address Family\n"
8361 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 8362{
f51bae9c 8363
d62a17ae 8364 if (argc == 3) {
2131d5cf 8365 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8366 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8367 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8368 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8369 && safi != SAFI_EVPN) {
31947174
MK
8370 vty_out(vty,
8371 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8372 return CMD_WARNING_CONFIG_FAILED;
8373 }
d62a17ae 8374 vty->node = bgp_node_type(AFI_IP, safi);
8375 } else
8376 vty->node = BGP_IPV4_NODE;
718e3744 8377
d62a17ae 8378 return CMD_SUCCESS;
718e3744 8379}
8380
505e5056 8381DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 8382 address_family_ipv6_safi_cmd,
8383 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8384 "Enter Address Family command mode\n"
8385 "Address Family\n"
8386 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 8387{
d62a17ae 8388 if (argc == 3) {
2131d5cf 8389 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8390 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8391 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8392 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8393 && safi != SAFI_EVPN) {
31947174
MK
8394 vty_out(vty,
8395 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8396 return CMD_WARNING_CONFIG_FAILED;
8397 }
d62a17ae 8398 vty->node = bgp_node_type(AFI_IP6, safi);
8399 } else
8400 vty->node = BGP_IPV6_NODE;
25ffbdc1 8401
d62a17ae 8402 return CMD_SUCCESS;
25ffbdc1 8403}
718e3744 8404
d6902373 8405#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 8406DEFUN_NOSH (address_family_vpnv4,
718e3744 8407 address_family_vpnv4_cmd,
8334fd5a 8408 "address-family vpnv4 [unicast]",
718e3744 8409 "Enter Address Family command mode\n"
8c3deaae 8410 "Address Family\n"
3a2d747c 8411 "Address Family modifier\n")
718e3744 8412{
d62a17ae 8413 vty->node = BGP_VPNV4_NODE;
8414 return CMD_SUCCESS;
718e3744 8415}
8416
505e5056 8417DEFUN_NOSH (address_family_vpnv6,
8ecd3266 8418 address_family_vpnv6_cmd,
8334fd5a 8419 "address-family vpnv6 [unicast]",
8ecd3266 8420 "Enter Address Family command mode\n"
8c3deaae 8421 "Address Family\n"
3a2d747c 8422 "Address Family modifier\n")
8ecd3266 8423{
d62a17ae 8424 vty->node = BGP_VPNV6_NODE;
8425 return CMD_SUCCESS;
8ecd3266 8426}
64e4a6c5 8427#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 8428
505e5056 8429DEFUN_NOSH (address_family_evpn,
4e0b7b6d 8430 address_family_evpn_cmd,
7111c1a0 8431 "address-family l2vpn evpn",
4e0b7b6d 8432 "Enter Address Family command mode\n"
7111c1a0
QY
8433 "Address Family\n"
8434 "Address Family modifier\n")
4e0b7b6d 8435{
2131d5cf 8436 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8437 vty->node = BGP_EVPN_NODE;
8438 return CMD_SUCCESS;
4e0b7b6d
PG
8439}
8440
505e5056 8441DEFUN_NOSH (exit_address_family,
718e3744 8442 exit_address_family_cmd,
8443 "exit-address-family",
8444 "Exit from Address Family configuration mode\n")
8445{
d62a17ae 8446 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
8447 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
8448 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
8449 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
8450 || vty->node == BGP_EVPN_NODE
8451 || vty->node == BGP_FLOWSPECV4_NODE
8452 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 8453 vty->node = BGP_NODE;
8454 return CMD_SUCCESS;
718e3744 8455}
6b0655a2 8456
8ad7271d 8457/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 8458static int bgp_clear_prefix(struct vty *vty, const char *view_name,
8459 const char *ip_str, afi_t afi, safi_t safi,
8460 struct prefix_rd *prd)
8461{
8462 int ret;
8463 struct prefix match;
9bcb3eef
DS
8464 struct bgp_dest *dest;
8465 struct bgp_dest *rm;
d62a17ae 8466 struct bgp *bgp;
8467 struct bgp_table *table;
8468 struct bgp_table *rib;
8469
8470 /* BGP structure lookup. */
8471 if (view_name) {
8472 bgp = bgp_lookup_by_name(view_name);
8473 if (bgp == NULL) {
8474 vty_out(vty, "%% Can't find BGP instance %s\n",
8475 view_name);
8476 return CMD_WARNING;
8477 }
8478 } else {
8479 bgp = bgp_get_default();
8480 if (bgp == NULL) {
8481 vty_out(vty, "%% No BGP process is configured\n");
8482 return CMD_WARNING;
8483 }
8484 }
8485
8486 /* Check IP address argument. */
8487 ret = str2prefix(ip_str, &match);
8488 if (!ret) {
8489 vty_out(vty, "%% address is malformed\n");
8490 return CMD_WARNING;
8491 }
8492
8493 match.family = afi2family(afi);
8494 rib = bgp->rib[afi][safi];
8495
8496 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
8497 for (dest = bgp_table_top(rib); dest;
8498 dest = bgp_route_next(dest)) {
8499 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8500
9bcb3eef 8501 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 8502 continue;
8503
9bcb3eef 8504 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
8505 if (table == NULL)
8506 continue;
8507
8508 if ((rm = bgp_node_match(table, &match)) != NULL) {
8509 const struct prefix *rm_p =
9bcb3eef 8510 bgp_dest_get_prefix(rm);
b54892e0
DS
8511
8512 if (rm_p->prefixlen == match.prefixlen) {
8513 SET_FLAG(rm->flags,
8514 BGP_NODE_USER_CLEAR);
8515 bgp_process(bgp, rm, afi, safi);
d62a17ae 8516 }
9bcb3eef 8517 bgp_dest_unlock_node(rm);
d62a17ae 8518 }
8519 }
8520 } else {
9bcb3eef
DS
8521 if ((dest = bgp_node_match(rib, &match)) != NULL) {
8522 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8523
9bcb3eef
DS
8524 if (dest_p->prefixlen == match.prefixlen) {
8525 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
8526 bgp_process(bgp, dest, afi, safi);
d62a17ae 8527 }
9bcb3eef 8528 bgp_dest_unlock_node(dest);
d62a17ae 8529 }
8530 }
8531
8532 return CMD_SUCCESS;
8ad7271d
DS
8533}
8534
b09b5ae0 8535/* one clear bgp command to rule them all */
718e3744 8536DEFUN (clear_ip_bgp_all,
8537 clear_ip_bgp_all_cmd,
453c92f6 8538 "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 8539 CLEAR_STR
8540 IP_STR
8541 BGP_STR
838758ac 8542 BGP_INSTANCE_HELP_STR
510afcd6 8543 BGP_AFI_HELP_STR
fd5e7b70 8544 "Address Family\n"
510afcd6 8545 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 8546 "Address Family modifier\n"
b09b5ae0 8547 "Clear all peers\n"
453c92f6 8548 "BGP IPv4 neighbor to clear\n"
a80beece 8549 "BGP IPv6 neighbor to clear\n"
838758ac 8550 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
8551 "Clear peers with the AS number\n"
8552 "Clear all external peers\n"
718e3744 8553 "Clear all members of peer-group\n"
b09b5ae0 8554 "BGP peer-group name\n"
b09b5ae0
DW
8555 BGP_SOFT_STR
8556 BGP_SOFT_IN_STR
b09b5ae0
DW
8557 BGP_SOFT_OUT_STR
8558 BGP_SOFT_IN_STR
8559 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 8560 BGP_SOFT_OUT_STR)
718e3744 8561{
d62a17ae 8562 char *vrf = NULL;
8563
dc912615
DS
8564 afi_t afi = AFI_UNSPEC;
8565 safi_t safi = SAFI_UNSPEC;
d62a17ae 8566 enum clear_sort clr_sort = clear_peer;
8567 enum bgp_clear_type clr_type;
8568 char *clr_arg = NULL;
8569
8570 int idx = 0;
8571
8572 /* clear [ip] bgp */
8573 if (argv_find(argv, argc, "ip", &idx))
8574 afi = AFI_IP;
8575
9a8bdf1c
PG
8576 /* [<vrf> VIEWVRFNAME] */
8577 if (argv_find(argv, argc, "vrf", &idx)) {
8578 vrf = argv[idx + 1]->arg;
8579 idx += 2;
8580 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8581 vrf = NULL;
8582 } else if (argv_find(argv, argc, "view", &idx)) {
8583 /* [<view> VIEWVRFNAME] */
d62a17ae 8584 vrf = argv[idx + 1]->arg;
8585 idx += 2;
8586 }
d62a17ae 8587 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8588 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8589 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8590
d7b9898c 8591 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 8592 if (argv_find(argv, argc, "*", &idx)) {
8593 clr_sort = clear_all;
8594 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8595 clr_sort = clear_peer;
8596 clr_arg = argv[idx]->arg;
8597 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8598 clr_sort = clear_peer;
8599 clr_arg = argv[idx]->arg;
8600 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8601 clr_sort = clear_group;
8602 idx++;
8603 clr_arg = argv[idx]->arg;
d7b9898c 8604 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 8605 clr_sort = clear_peer;
8606 clr_arg = argv[idx]->arg;
8fa7d444
DS
8607 } else if (argv_find(argv, argc, "WORD", &idx)) {
8608 clr_sort = clear_peer;
8609 clr_arg = argv[idx]->arg;
d62a17ae 8610 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8611 clr_sort = clear_as;
8612 clr_arg = argv[idx]->arg;
8613 } else if (argv_find(argv, argc, "external", &idx)) {
8614 clr_sort = clear_external;
8615 }
8616
8617 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8618 if (argv_find(argv, argc, "soft", &idx)) {
8619 if (argv_find(argv, argc, "in", &idx)
8620 || argv_find(argv, argc, "out", &idx))
8621 clr_type = strmatch(argv[idx]->text, "in")
8622 ? BGP_CLEAR_SOFT_IN
8623 : BGP_CLEAR_SOFT_OUT;
8624 else
8625 clr_type = BGP_CLEAR_SOFT_BOTH;
8626 } else if (argv_find(argv, argc, "in", &idx)) {
8627 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8628 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8629 : BGP_CLEAR_SOFT_IN;
8630 } else if (argv_find(argv, argc, "out", &idx)) {
8631 clr_type = BGP_CLEAR_SOFT_OUT;
8632 } else
8633 clr_type = BGP_CLEAR_SOFT_NONE;
8634
8635 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 8636}
01080f7c 8637
8ad7271d
DS
8638DEFUN (clear_ip_bgp_prefix,
8639 clear_ip_bgp_prefix_cmd,
18c57037 8640 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
8641 CLEAR_STR
8642 IP_STR
8643 BGP_STR
838758ac 8644 BGP_INSTANCE_HELP_STR
8ad7271d 8645 "Clear bestpath and re-advertise\n"
0c7b1b01 8646 "IPv4 prefix\n")
8ad7271d 8647{
d62a17ae 8648 char *vrf = NULL;
8649 char *prefix = NULL;
8ad7271d 8650
d62a17ae 8651 int idx = 0;
01080f7c 8652
d62a17ae 8653 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
8654 if (argv_find(argv, argc, "vrf", &idx)) {
8655 vrf = argv[idx + 1]->arg;
8656 idx += 2;
8657 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8658 vrf = NULL;
8659 } else if (argv_find(argv, argc, "view", &idx)) {
8660 /* [<view> VIEWVRFNAME] */
8661 vrf = argv[idx + 1]->arg;
8662 idx += 2;
8663 }
0c7b1b01 8664
d62a17ae 8665 prefix = argv[argc - 1]->arg;
8ad7271d 8666
d62a17ae 8667 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 8668}
8ad7271d 8669
b09b5ae0
DW
8670DEFUN (clear_bgp_ipv6_safi_prefix,
8671 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 8672 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8673 CLEAR_STR
3a2d747c 8674 IP_STR
718e3744 8675 BGP_STR
8c3deaae 8676 "Address Family\n"
46f296b4 8677 BGP_SAFI_HELP_STR
b09b5ae0 8678 "Clear bestpath and re-advertise\n"
0c7b1b01 8679 "IPv6 prefix\n")
718e3744 8680{
9b475e76
PG
8681 int idx_safi = 0;
8682 int idx_ipv6_prefix = 0;
8683 safi_t safi = SAFI_UNICAST;
8684 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8685 argv[idx_ipv6_prefix]->arg : NULL;
8686
8687 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 8688 return bgp_clear_prefix(
9b475e76
PG
8689 vty, NULL, prefix, AFI_IP6,
8690 safi, NULL);
838758ac 8691}
01080f7c 8692
b09b5ae0
DW
8693DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8694 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 8695 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8696 CLEAR_STR
3a2d747c 8697 IP_STR
718e3744 8698 BGP_STR
838758ac 8699 BGP_INSTANCE_HELP_STR
8c3deaae 8700 "Address Family\n"
46f296b4 8701 BGP_SAFI_HELP_STR
b09b5ae0 8702 "Clear bestpath and re-advertise\n"
0c7b1b01 8703 "IPv6 prefix\n")
718e3744 8704{
9b475e76 8705 int idx_safi = 0;
9a8bdf1c 8706 int idx_vrfview = 0;
9b475e76
PG
8707 int idx_ipv6_prefix = 0;
8708 safi_t safi = SAFI_UNICAST;
8709 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8710 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 8711 char *vrfview = NULL;
9b475e76 8712
9a8bdf1c
PG
8713 /* [<view|vrf> VIEWVRFNAME] */
8714 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8715 vrfview = argv[idx_vrfview + 1]->arg;
8716 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8717 vrfview = NULL;
8718 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8719 /* [<view> VIEWVRFNAME] */
8720 vrfview = argv[idx_vrfview + 1]->arg;
8721 }
9b475e76
PG
8722 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8723
d62a17ae 8724 return bgp_clear_prefix(
9b475e76
PG
8725 vty, vrfview, prefix,
8726 AFI_IP6, safi, NULL);
718e3744 8727}
8728
b09b5ae0
DW
8729DEFUN (show_bgp_views,
8730 show_bgp_views_cmd,
d6e3c605 8731 "show [ip] bgp views",
b09b5ae0 8732 SHOW_STR
d6e3c605 8733 IP_STR
01080f7c 8734 BGP_STR
b09b5ae0 8735 "Show the defined BGP views\n")
01080f7c 8736{
d62a17ae 8737 struct list *inst = bm->bgp;
8738 struct listnode *node;
8739 struct bgp *bgp;
01080f7c 8740
d62a17ae 8741 vty_out(vty, "Defined BGP views:\n");
8742 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8743 /* Skip VRFs. */
8744 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
8745 continue;
8746 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
8747 bgp->as);
8748 }
e52702f2 8749
d62a17ae 8750 return CMD_SUCCESS;
e0081f70
ML
8751}
8752
8386ac43 8753DEFUN (show_bgp_vrfs,
8754 show_bgp_vrfs_cmd,
d6e3c605 8755 "show [ip] bgp vrfs [json]",
8386ac43 8756 SHOW_STR
d6e3c605 8757 IP_STR
8386ac43 8758 BGP_STR
8759 "Show BGP VRFs\n"
9973d184 8760 JSON_STR)
8386ac43 8761{
fe1dc5a3 8762 char buf[ETHER_ADDR_STRLEN];
d62a17ae 8763 struct list *inst = bm->bgp;
8764 struct listnode *node;
8765 struct bgp *bgp;
9f049418 8766 bool uj = use_json(argc, argv);
d62a17ae 8767 json_object *json = NULL;
8768 json_object *json_vrfs = NULL;
8769 int count = 0;
d62a17ae 8770
d62a17ae 8771 if (uj) {
8772 json = json_object_new_object();
8773 json_vrfs = json_object_new_object();
8774 }
8775
8776 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8777 const char *name, *type;
8778 struct peer *peer;
7fe96307 8779 struct listnode *node2, *nnode2;
d62a17ae 8780 int peers_cfg, peers_estb;
8781 json_object *json_vrf = NULL;
d62a17ae 8782
8783 /* Skip Views. */
8784 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
8785 continue;
8786
8787 count++;
efb4077a 8788 if (!uj && count == 1) {
fe1dc5a3 8789 vty_out(vty,
efb4077a 8790 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 8791 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
8792 "#PeersEstb", "Name");
8793 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
8794 "L3-VNI", "RouterMAC", "Interface");
8795 }
d62a17ae 8796
8797 peers_cfg = peers_estb = 0;
8798 if (uj)
8799 json_vrf = json_object_new_object();
8800
8801
7fe96307 8802 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 8803 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8804 continue;
8805 peers_cfg++;
8806 if (peer->status == Established)
8807 peers_estb++;
8808 }
8809
8810 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 8811 name = VRF_DEFAULT_NAME;
d62a17ae 8812 type = "DFLT";
8813 } else {
8814 name = bgp->name;
8815 type = "VRF";
8816 }
8817
a8bf7d9c 8818
d62a17ae 8819 if (uj) {
a4d82a8a
PZ
8820 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8821 ? -1
8822 : (int64_t)bgp->vrf_id;
d62a17ae 8823 json_object_string_add(json_vrf, "type", type);
8824 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8825 json_object_string_add(json_vrf, "routerId",
8826 inet_ntoa(bgp->router_id));
8827 json_object_int_add(json_vrf, "numConfiguredPeers",
8828 peers_cfg);
8829 json_object_int_add(json_vrf, "numEstablishedPeers",
8830 peers_estb);
8831
fe1dc5a3 8832 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
8833 json_object_string_add(
8834 json_vrf, "rmac",
8835 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
8836 json_object_string_add(json_vrf, "interface",
8837 ifindex2ifname(bgp->l3vni_svi_ifindex,
8838 bgp->vrf_id));
d62a17ae 8839 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 8840 } else {
fe1dc5a3 8841 vty_out(vty,
efb4077a 8842 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
8843 type,
8844 bgp->vrf_id == VRF_UNKNOWN ? -1
8845 : (int)bgp->vrf_id,
8846 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
8847 peers_estb, name);
8848 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
8849 bgp->l3vni,
8850 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
8851 ifindex2ifname(bgp->l3vni_svi_ifindex,
8852 bgp->vrf_id));
8853 }
d62a17ae 8854 }
8855
8856 if (uj) {
8857 json_object_object_add(json, "vrfs", json_vrfs);
8858
8859 json_object_int_add(json, "totalVrfs", count);
8860
996c9314
LB
8861 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8862 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8863 json_object_free(json);
8864 } else {
8865 if (count)
8866 vty_out(vty,
8867 "\nTotal number of VRFs (including default): %d\n",
8868 count);
8869 }
8870
8871 return CMD_SUCCESS;
8386ac43 8872}
8873
48ecf8f5
DS
8874DEFUN (show_bgp_mac_hash,
8875 show_bgp_mac_hash_cmd,
8876 "show bgp mac hash",
8877 SHOW_STR
8878 BGP_STR
8879 "Mac Address\n"
8880 "Mac Address database\n")
8881{
8882 bgp_mac_dump_table(vty);
8883
8884 return CMD_SUCCESS;
8885}
acf71666 8886
e3b78da8 8887static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 8888{
0291c246 8889 struct vty *vty = (struct vty *)args;
e3b78da8 8890 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 8891
60466a63 8892 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
8893 tip->refcnt);
8894}
8895
8896static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
8897{
8898 vty_out(vty, "self nexthop database:\n");
af97a18b 8899 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
8900
8901 vty_out(vty, "Tunnel-ip database:\n");
8902 hash_iterate(bgp->tip_hash,
e3b78da8 8903 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
8904 vty);
8905}
8906
15c81ca4
DS
8907DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
8908 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
8909 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
8910 "martian next-hops\n"
8911 "martian next-hop database\n")
acf71666 8912{
0291c246 8913 struct bgp *bgp = NULL;
15c81ca4 8914 int idx = 0;
9a8bdf1c
PG
8915 char *name = NULL;
8916
8917 /* [<vrf> VIEWVRFNAME] */
8918 if (argv_find(argv, argc, "vrf", &idx)) {
8919 name = argv[idx + 1]->arg;
8920 if (name && strmatch(name, VRF_DEFAULT_NAME))
8921 name = NULL;
8922 } else if (argv_find(argv, argc, "view", &idx))
8923 /* [<view> VIEWVRFNAME] */
8924 name = argv[idx + 1]->arg;
8925 if (name)
8926 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
8927 else
8928 bgp = bgp_get_default();
acf71666 8929
acf71666
MK
8930 if (!bgp) {
8931 vty_out(vty, "%% No BGP process is configured\n");
8932 return CMD_WARNING;
8933 }
8934 bgp_show_martian_nexthops(vty, bgp);
8935
8936 return CMD_SUCCESS;
8937}
8938
f412b39a 8939DEFUN (show_bgp_memory,
4bf6a362 8940 show_bgp_memory_cmd,
7fa12b13 8941 "show [ip] bgp memory",
4bf6a362 8942 SHOW_STR
3a2d747c 8943 IP_STR
4bf6a362
PJ
8944 BGP_STR
8945 "Global BGP memory statistics\n")
8946{
d62a17ae 8947 char memstrbuf[MTYPE_MEMSTR_LEN];
8948 unsigned long count;
8949
8950 /* RIB related usage stats */
8951 count = mtype_stats_alloc(MTYPE_BGP_NODE);
8952 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
8953 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 8954 count * sizeof(struct bgp_dest)));
d62a17ae 8955
8956 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
8957 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
8958 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 8959 count * sizeof(struct bgp_path_info)));
d62a17ae 8960 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
8961 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
8962 count,
4b7e6066
DS
8963 mtype_memstr(
8964 memstrbuf, sizeof(memstrbuf),
8965 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 8966
8967 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
8968 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
8969 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8970 count * sizeof(struct bgp_static)));
8971
8972 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
8973 vty_out(vty, "%ld Packets, using %s of memory\n", count,
8974 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8975 count * sizeof(struct bpacket)));
8976
8977 /* Adj-In/Out */
8978 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
8979 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
8980 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8981 count * sizeof(struct bgp_adj_in)));
8982 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
8983 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
8984 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8985 count * sizeof(struct bgp_adj_out)));
8986
8987 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
8988 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
8989 count,
8990 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8991 count * sizeof(struct bgp_nexthop_cache)));
8992
8993 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
8994 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
8995 count,
8996 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8997 count * sizeof(struct bgp_damp_info)));
8998
8999 /* Attributes */
9000 count = attr_count();
9001 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9002 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9003 count * sizeof(struct attr)));
9004
9005 if ((count = attr_unknown_count()))
9006 vty_out(vty, "%ld unknown attributes\n", count);
9007
9008 /* AS_PATH attributes */
9009 count = aspath_count();
9010 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9011 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9012 count * sizeof(struct aspath)));
9013
9014 count = mtype_stats_alloc(MTYPE_AS_SEG);
9015 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9016 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9017 count * sizeof(struct assegment)));
9018
9019 /* Other attributes */
9020 if ((count = community_count()))
9021 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9022 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9023 count * sizeof(struct community)));
d62a17ae 9024 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9025 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9026 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9027 count * sizeof(struct ecommunity)));
d62a17ae 9028 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9029 vty_out(vty,
9030 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9031 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9032 count * sizeof(struct lcommunity)));
d62a17ae 9033
9034 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9035 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9036 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9037 count * sizeof(struct cluster_list)));
9038
9039 /* Peer related usage */
9040 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9041 vty_out(vty, "%ld peers, using %s of memory\n", count,
9042 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9043 count * sizeof(struct peer)));
9044
9045 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9046 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9047 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9048 count * sizeof(struct peer_group)));
9049
9050 /* Other */
d62a17ae 9051 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9052 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9053 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9054 count * sizeof(regex_t)));
d62a17ae 9055 return CMD_SUCCESS;
4bf6a362 9056}
fee0f4c6 9057
57a9c8a8
DS
9058static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9059{
9060 json_object *bestpath = json_object_new_object();
9061
892fedb6 9062 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9063 json_object_string_add(bestpath, "asPath", "ignore");
9064
892fedb6 9065 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9066 json_object_string_add(bestpath, "asPath", "confed");
9067
892fedb6
DA
9068 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9069 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9070 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9071 "as-set");
9072 else
a4d82a8a 9073 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9074 "true");
9075 } else
a4d82a8a 9076 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9077
892fedb6 9078 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9079 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9080 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9081 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9082 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9083 json_object_string_add(bestpath, "med", "confed");
892fedb6 9084 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
9085 json_object_string_add(bestpath, "med",
9086 "missing-as-worst");
9087 else
9088 json_object_string_add(bestpath, "med", "true");
9089 }
9090
9091 json_object_object_add(json, "bestPath", bestpath);
9092}
9093
3577f1c5
DD
9094/* Print the error code/subcode for why the peer is down */
9095static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9096 json_object *json_peer, bool use_json)
9097{
9098 const char *code_str;
9099 const char *subcode_str;
9100
9101 if (use_json) {
9102 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9103 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9104 char errorcodesubcode_hexstr[5];
9105 char errorcodesubcode_str[256];
9106
9107 code_str = bgp_notify_code_str(peer->notify.code);
9108 subcode_str = bgp_notify_subcode_str(
9109 peer->notify.code,
9110 peer->notify.subcode);
9111
772270f3
QY
9112 snprintf(errorcodesubcode_hexstr,
9113 sizeof(errorcodesubcode_hexstr), "%02X%02X",
9114 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
9115 json_object_string_add(json_peer,
9116 "lastErrorCodeSubcode",
9117 errorcodesubcode_hexstr);
9118 snprintf(errorcodesubcode_str, 255, "%s%s",
9119 code_str, subcode_str);
9120 json_object_string_add(json_peer,
9121 "lastNotificationReason",
9122 errorcodesubcode_str);
9123 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9124 && peer->notify.code == BGP_NOTIFY_CEASE
9125 && (peer->notify.subcode
9126 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9127 || peer->notify.subcode
9128 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9129 && peer->notify.length) {
9130 char msgbuf[1024];
9131 const char *msg_str;
9132
9133 msg_str = bgp_notify_admin_message(
9134 msgbuf, sizeof(msgbuf),
9135 (uint8_t *)peer->notify.data,
9136 peer->notify.length);
9137 if (msg_str)
9138 json_object_string_add(
9139 json_peer,
9140 "lastShutdownDescription",
9141 msg_str);
9142 }
9143
c258527b 9144 }
3577f1c5
DD
9145 json_object_string_add(json_peer, "lastResetDueTo",
9146 peer_down_str[(int)peer->last_reset]);
05912a17
DD
9147 json_object_int_add(json_peer, "lastResetCode",
9148 peer->last_reset);
3577f1c5
DD
9149 } else {
9150 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9151 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9152 code_str = bgp_notify_code_str(peer->notify.code);
9153 subcode_str =
9154 bgp_notify_subcode_str(peer->notify.code,
9155 peer->notify.subcode);
9156 vty_out(vty, " Notification %s (%s%s)\n",
9157 peer->last_reset == PEER_DOWN_NOTIFY_SEND
9158 ? "sent"
9159 : "received",
9160 code_str, subcode_str);
9161 } else {
e91c24c8 9162 vty_out(vty, " %s\n",
3577f1c5
DD
9163 peer_down_str[(int)peer->last_reset]);
9164 }
9165 }
9166}
9167
9168static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
9169 safi_t safi)
9170{
9171 return ((peer->status != Established) ||
9172 !peer->afc_recv[afi][safi]);
9173}
9174
9175static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
9176 struct peer *peer, json_object *json_peer,
9177 int max_neighbor_width, bool use_json)
9178{
9179 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9180 int len;
9181
9182 if (use_json) {
9183 if (peer_dynamic_neighbor(peer))
9184 json_object_boolean_true_add(json_peer,
9185 "dynamicPeer");
9186 if (peer->hostname)
9187 json_object_string_add(json_peer, "hostname",
9188 peer->hostname);
9189
9190 if (peer->domainname)
9191 json_object_string_add(json_peer, "domainname",
9192 peer->domainname);
9193 json_object_int_add(json_peer, "connectionsEstablished",
9194 peer->established);
9195 json_object_int_add(json_peer, "connectionsDropped",
9196 peer->dropped);
9197 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9198 use_json, json_peer);
9199 if (peer->status == Established)
9200 json_object_string_add(json_peer, "lastResetDueTo",
9201 "AFI/SAFI Not Negotiated");
9202 else
9203 bgp_show_peer_reset(NULL, peer, json_peer, true);
9204 } else {
9205 dn_flag[1] = '\0';
9206 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
9207 if (peer->hostname
892fedb6 9208 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
9209 len = vty_out(vty, "%s%s(%s)", dn_flag,
9210 peer->hostname, peer->host);
9211 else
9212 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9213
9214 /* pad the neighbor column with spaces */
9215 if (len < max_neighbor_width)
9216 vty_out(vty, "%*s", max_neighbor_width - len,
9217 " ");
e91c24c8 9218 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
9219 peer->dropped,
9220 peer_uptime(peer->uptime, timebuf,
9221 BGP_UPTIME_LEN, 0, NULL));
9222 if (peer->status == Established)
9223 vty_out(vty, " AFI/SAFI Not Negotiated\n");
9224 else
9225 bgp_show_peer_reset(vty, peer, NULL,
9226 false);
9227 }
9228}
c258527b 9229
3577f1c5 9230
718e3744 9231/* Show BGP peer's summary information. */
d62a17ae 9232static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10b49f14
DA
9233 bool show_failed, bool show_established,
9234 bool use_json)
d62a17ae 9235{
9236 struct peer *peer;
9237 struct listnode *node, *nnode;
9238 unsigned int count = 0, dn_count = 0;
9239 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9240 char neighbor_buf[VTY_BUFSIZ];
9241 int neighbor_col_default_width = 16;
3577f1c5 9242 int len, failed_count = 0;
d62a17ae 9243 int max_neighbor_width = 0;
9244 int pfx_rcd_safi;
3c13337d 9245 json_object *json = NULL;
d62a17ae 9246 json_object *json_peer = NULL;
9247 json_object *json_peers = NULL;
50e05855 9248 struct peer_af *paf;
d3ada366 9249 struct bgp_filter *filter;
d62a17ae 9250
9251 /* labeled-unicast routes are installed in the unicast table so in order
9252 * to
9253 * display the correct PfxRcd value we must look at SAFI_UNICAST
9254 */
3577f1c5 9255
d62a17ae 9256 if (safi == SAFI_LABELED_UNICAST)
9257 pfx_rcd_safi = SAFI_UNICAST;
9258 else
9259 pfx_rcd_safi = safi;
9260
9261 if (use_json) {
3c13337d 9262 json = json_object_new_object();
d62a17ae 9263 json_peers = json_object_new_object();
3577f1c5
DD
9264 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9265 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9266 continue;
9267
9268 if (peer->afc[afi][safi]) {
9269 /* See if we have at least a single failed peer */
9270 if (bgp_has_peer_failed(peer, afi, safi))
9271 failed_count++;
9272 count++;
9273 }
9274 if (peer_dynamic_neighbor(peer))
9275 dn_count++;
9276 }
c258527b 9277
d62a17ae 9278 } else {
9279 /* Loop over all neighbors that will be displayed to determine
9280 * how many
9281 * characters are needed for the Neighbor column
9282 */
9283 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9284 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9285 continue;
9286
9287 if (peer->afc[afi][safi]) {
9288 memset(dn_flag, '\0', sizeof(dn_flag));
9289 if (peer_dynamic_neighbor(peer))
9290 dn_flag[0] = '*';
9291
9292 if (peer->hostname
892fedb6
DA
9293 && CHECK_FLAG(bgp->flags,
9294 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
9295 snprintf(neighbor_buf,
9296 sizeof(neighbor_buf),
9297 "%s%s(%s) ", dn_flag,
9298 peer->hostname, peer->host);
d62a17ae 9299 else
772270f3
QY
9300 snprintf(neighbor_buf,
9301 sizeof(neighbor_buf), "%s%s ",
9302 dn_flag, peer->host);
d62a17ae 9303
9304 len = strlen(neighbor_buf);
9305
9306 if (len > max_neighbor_width)
9307 max_neighbor_width = len;
c258527b 9308
3577f1c5
DD
9309 /* See if we have at least a single failed peer */
9310 if (bgp_has_peer_failed(peer, afi, safi))
9311 failed_count++;
9312 count++;
d62a17ae 9313 }
9314 }
f933309e 9315
d62a17ae 9316 /* Originally we displayed the Neighbor column as 16
9317 * characters wide so make that the default
9318 */
9319 if (max_neighbor_width < neighbor_col_default_width)
9320 max_neighbor_width = neighbor_col_default_width;
9321 }
f933309e 9322
3577f1c5
DD
9323 if (show_failed && !failed_count) {
9324 if (use_json) {
9325 json_object_int_add(json, "failedPeersCount", 0);
9326 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 9327 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
9328
9329 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9330 json, JSON_C_TO_STRING_PRETTY));
9331 json_object_free(json);
9332 } else {
9333 vty_out(vty, "%% No failed BGP neighbors found\n");
9334 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9335 }
9336 return CMD_SUCCESS;
9337 }
c258527b 9338
3577f1c5 9339 count = 0; /* Reset the value as its used again */
d62a17ae 9340 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9341 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9342 continue;
9343
ea47320b
DL
9344 if (!peer->afc[afi][safi])
9345 continue;
d62a17ae 9346
ea47320b
DL
9347 if (!count) {
9348 unsigned long ents;
9349 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 9350 int64_t vrf_id_ui;
d62a17ae 9351
a4d82a8a
PZ
9352 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9353 ? -1
9354 : (int64_t)bgp->vrf_id;
ea47320b
DL
9355
9356 /* Usage summary and header */
9357 if (use_json) {
9358 json_object_string_add(
9359 json, "routerId",
9360 inet_ntoa(bgp->router_id));
60466a63
QY
9361 json_object_int_add(json, "as", bgp->as);
9362 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
9363 json_object_string_add(
9364 json, "vrfName",
9365 (bgp->inst_type
9366 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9367 ? VRF_DEFAULT_NAME
ea47320b
DL
9368 : bgp->name);
9369 } else {
9370 vty_out(vty,
9371 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 9372 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
9373 bgp->vrf_id == VRF_UNKNOWN
9374 ? -1
9375 : (int)bgp->vrf_id);
ea47320b
DL
9376 vty_out(vty, "\n");
9377 }
d62a17ae 9378
ea47320b 9379 if (bgp_update_delay_configured(bgp)) {
d62a17ae 9380 if (use_json) {
ea47320b 9381 json_object_int_add(
60466a63 9382 json, "updateDelayLimit",
ea47320b 9383 bgp->v_update_delay);
d62a17ae 9384
ea47320b
DL
9385 if (bgp->v_update_delay
9386 != bgp->v_establish_wait)
d62a17ae 9387 json_object_int_add(
9388 json,
ea47320b
DL
9389 "updateDelayEstablishWait",
9390 bgp->v_establish_wait);
d62a17ae 9391
60466a63 9392 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9393 json_object_string_add(
9394 json,
9395 "updateDelayFirstNeighbor",
9396 bgp->update_delay_begin_time);
9397 json_object_boolean_true_add(
9398 json,
9399 "updateDelayInProgress");
9400 } else {
9401 if (bgp->update_delay_over) {
d62a17ae 9402 json_object_string_add(
9403 json,
9404 "updateDelayFirstNeighbor",
9405 bgp->update_delay_begin_time);
ea47320b 9406 json_object_string_add(
d62a17ae 9407 json,
ea47320b
DL
9408 "updateDelayBestpathResumed",
9409 bgp->update_delay_end_time);
9410 json_object_string_add(
d62a17ae 9411 json,
ea47320b
DL
9412 "updateDelayZebraUpdateResume",
9413 bgp->update_delay_zebra_resume_time);
9414 json_object_string_add(
9415 json,
9416 "updateDelayPeerUpdateResume",
9417 bgp->update_delay_peers_resume_time);
d62a17ae 9418 }
ea47320b
DL
9419 }
9420 } else {
9421 vty_out(vty,
9422 "Read-only mode update-delay limit: %d seconds\n",
9423 bgp->v_update_delay);
9424 if (bgp->v_update_delay
9425 != bgp->v_establish_wait)
d62a17ae 9426 vty_out(vty,
ea47320b
DL
9427 " Establish wait: %d seconds\n",
9428 bgp->v_establish_wait);
d62a17ae 9429
60466a63 9430 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9431 vty_out(vty,
9432 " First neighbor established: %s\n",
9433 bgp->update_delay_begin_time);
9434 vty_out(vty,
9435 " Delay in progress\n");
9436 } else {
9437 if (bgp->update_delay_over) {
d62a17ae 9438 vty_out(vty,
9439 " First neighbor established: %s\n",
9440 bgp->update_delay_begin_time);
9441 vty_out(vty,
ea47320b
DL
9442 " Best-paths resumed: %s\n",
9443 bgp->update_delay_end_time);
9444 vty_out(vty,
9445 " zebra update resumed: %s\n",
9446 bgp->update_delay_zebra_resume_time);
9447 vty_out(vty,
9448 " peers update resumed: %s\n",
9449 bgp->update_delay_peers_resume_time);
d62a17ae 9450 }
9451 }
9452 }
ea47320b 9453 }
d62a17ae 9454
ea47320b
DL
9455 if (use_json) {
9456 if (bgp_maxmed_onstartup_configured(bgp)
9457 && bgp->maxmed_active)
9458 json_object_boolean_true_add(
60466a63 9459 json, "maxMedOnStartup");
ea47320b
DL
9460 if (bgp->v_maxmed_admin)
9461 json_object_boolean_true_add(
60466a63 9462 json, "maxMedAdministrative");
d62a17ae 9463
ea47320b
DL
9464 json_object_int_add(
9465 json, "tableVersion",
60466a63 9466 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 9467
60466a63
QY
9468 ents = bgp_table_count(bgp->rib[afi][safi]);
9469 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
9470 json_object_int_add(
9471 json, "ribMemory",
9bcb3eef 9472 ents * sizeof(struct bgp_dest));
d62a17ae 9473
210ec2a0 9474 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
9475 json_object_int_add(json, "peerCount", ents);
9476 json_object_int_add(json, "peerMemory",
9477 ents * sizeof(struct peer));
d62a17ae 9478
ea47320b
DL
9479 if ((ents = listcount(bgp->group))) {
9480 json_object_int_add(
60466a63 9481 json, "peerGroupCount", ents);
ea47320b
DL
9482 json_object_int_add(
9483 json, "peerGroupMemory",
996c9314
LB
9484 ents * sizeof(struct
9485 peer_group));
ea47320b 9486 }
d62a17ae 9487
ea47320b
DL
9488 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9489 BGP_CONFIG_DAMPENING))
9490 json_object_boolean_true_add(
60466a63 9491 json, "dampeningEnabled");
ea47320b
DL
9492 } else {
9493 if (bgp_maxmed_onstartup_configured(bgp)
9494 && bgp->maxmed_active)
d62a17ae 9495 vty_out(vty,
ea47320b
DL
9496 "Max-med on-startup active\n");
9497 if (bgp->v_maxmed_admin)
d62a17ae 9498 vty_out(vty,
ea47320b 9499 "Max-med administrative active\n");
d62a17ae 9500
60466a63
QY
9501 vty_out(vty, "BGP table version %" PRIu64 "\n",
9502 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 9503
60466a63 9504 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
9505 vty_out(vty,
9506 "RIB entries %ld, using %s of memory\n",
9507 ents,
9bcb3eef
DS
9508 mtype_memstr(
9509 memstrbuf, sizeof(memstrbuf),
9510 ents
9511 * sizeof(struct
9512 bgp_dest)));
ea47320b
DL
9513
9514 /* Peer related usage */
210ec2a0 9515 ents = bgp->af_peer_count[afi][safi];
60466a63 9516 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
9517 ents,
9518 mtype_memstr(
60466a63
QY
9519 memstrbuf, sizeof(memstrbuf),
9520 ents * sizeof(struct peer)));
ea47320b
DL
9521
9522 if ((ents = listcount(bgp->group)))
d62a17ae 9523 vty_out(vty,
ea47320b 9524 "Peer groups %ld, using %s of memory\n",
d62a17ae 9525 ents,
9526 mtype_memstr(
9527 memstrbuf,
9528 sizeof(memstrbuf),
996c9314
LB
9529 ents * sizeof(struct
9530 peer_group)));
d62a17ae 9531
ea47320b
DL
9532 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9533 BGP_CONFIG_DAMPENING))
60466a63 9534 vty_out(vty, "Dampening enabled.\n");
ea47320b 9535 vty_out(vty, "\n");
d62a17ae 9536
ea47320b
DL
9537 /* Subtract 8 here because 'Neighbor' is
9538 * 8 characters */
9539 vty_out(vty, "Neighbor");
60466a63
QY
9540 vty_out(vty, "%*s", max_neighbor_width - 8,
9541 " ");
3577f1c5
DD
9542 if (show_failed)
9543 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
9544 else
9545 vty_out(vty,
db92d226 9546 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
d62a17ae 9547 }
ea47320b 9548 }
d62a17ae 9549
d55811cc 9550 paf = peer_af_find(peer, afi, safi);
d3ada366 9551 filter = &peer->filter[afi][safi];
db92d226 9552
ea47320b 9553 count++;
3577f1c5
DD
9554 /* Works for both failed & successful cases */
9555 if (peer_dynamic_neighbor(peer))
9556 dn_count++;
d62a17ae 9557
ea47320b 9558 if (use_json) {
3577f1c5
DD
9559 json_peer = NULL;
9560
9561 if (show_failed &&
9562 bgp_has_peer_failed(peer, afi, safi)) {
9563 json_peer = json_object_new_object();
9564 bgp_show_failed_summary(vty, bgp, peer,
9565 json_peer, 0, use_json);
9566 } else if (!show_failed) {
10b49f14
DA
9567 if (show_established
9568 && bgp_has_peer_failed(peer, afi, safi))
9569 continue;
9570
3577f1c5
DD
9571 json_peer = json_object_new_object();
9572 if (peer_dynamic_neighbor(peer)) {
9573 json_object_boolean_true_add(json_peer,
9574 "dynamicPeer");
9575 }
d62a17ae 9576
3577f1c5
DD
9577 if (peer->hostname)
9578 json_object_string_add(json_peer, "hostname",
9579 peer->hostname);
9580
9581 if (peer->domainname)
9582 json_object_string_add(json_peer, "domainname",
9583 peer->domainname);
9584
9585 json_object_int_add(json_peer, "remoteAs", peer->as);
9586 json_object_int_add(json_peer, "version", 4);
9587 json_object_int_add(json_peer, "msgRcvd",
9588 PEER_TOTAL_RX(peer));
9589 json_object_int_add(json_peer, "msgSent",
9590 PEER_TOTAL_TX(peer));
9591
43aa5965
QY
9592 atomic_size_t outq_count, inq_count;
9593 outq_count = atomic_load_explicit(
9594 &peer->obuf->count,
9595 memory_order_relaxed);
9596 inq_count = atomic_load_explicit(
9597 &peer->ibuf->count,
9598 memory_order_relaxed);
9599
3577f1c5
DD
9600 json_object_int_add(json_peer, "tableVersion",
9601 peer->version[afi][safi]);
9602 json_object_int_add(json_peer, "outq",
43aa5965
QY
9603 outq_count);
9604 json_object_int_add(json_peer, "inq",
9605 inq_count);
3577f1c5
DD
9606 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9607 use_json, json_peer);
9608
3577f1c5
DD
9609 json_object_int_add(json_peer, "pfxRcd",
9610 peer->pcount[afi][pfx_rcd_safi]);
9611
3577f1c5
DD
9612 if (paf && PAF_SUBGRP(paf))
9613 json_object_int_add(json_peer,
9614 "pfxSnt",
9615 (PAF_SUBGRP(paf))->scount);
cb9196e7 9616 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
9617 || CHECK_FLAG(peer->bgp->flags,
9618 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
9619 json_object_string_add(json_peer, "state",
9620 "Idle (Admin)");
9621 else if (peer->afc_recv[afi][safi])
9622 json_object_string_add(
9623 json_peer, "state",
9624 lookup_msg(bgp_status_msg, peer->status,
9625 NULL));
9626 else if (CHECK_FLAG(peer->sflags,
9627 PEER_STATUS_PREFIX_OVERFLOW))
9628 json_object_string_add(json_peer, "state",
9629 "Idle (PfxCt)");
9630 else
9631 json_object_string_add(
9632 json_peer, "state",
9633 lookup_msg(bgp_status_msg, peer->status,
9634 NULL));
200116db
DD
9635 json_object_int_add(json_peer, "connectionsEstablished",
9636 peer->established);
9637 json_object_int_add(json_peer, "connectionsDropped",
9638 peer->dropped);
b4e9dcba 9639 }
3577f1c5
DD
9640 /* Avoid creating empty peer dicts in JSON */
9641 if (json_peer == NULL)
9642 continue;
ea47320b
DL
9643
9644 if (peer->conf_if)
60466a63 9645 json_object_string_add(json_peer, "idType",
ea47320b
DL
9646 "interface");
9647 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
9648 json_object_string_add(json_peer, "idType",
9649 "ipv4");
ea47320b 9650 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
9651 json_object_string_add(json_peer, "idType",
9652 "ipv6");
ea47320b
DL
9653 json_object_object_add(json_peers, peer->host,
9654 json_peer);
9655 } else {
3577f1c5
DD
9656 if (show_failed &&
9657 bgp_has_peer_failed(peer, afi, safi)) {
9658 bgp_show_failed_summary(vty, bgp, peer, NULL,
9659 max_neighbor_width,
9660 use_json);
9661 } else if (!show_failed) {
10b49f14
DA
9662 if (show_established
9663 && bgp_has_peer_failed(peer, afi, safi))
9664 continue;
9665
3577f1c5
DD
9666 memset(dn_flag, '\0', sizeof(dn_flag));
9667 if (peer_dynamic_neighbor(peer)) {
9668 dn_flag[0] = '*';
9669 }
d62a17ae 9670
3577f1c5 9671 if (peer->hostname
892fedb6
DA
9672 && CHECK_FLAG(bgp->flags,
9673 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 9674 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
9675 peer->hostname,
9676 peer->host);
d62a17ae 9677 else
3577f1c5
DD
9678 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9679
9680 /* pad the neighbor column with spaces */
9681 if (len < max_neighbor_width)
9682 vty_out(vty, "%*s", max_neighbor_width - len,
9683 " ");
9684
43aa5965
QY
9685 atomic_size_t outq_count, inq_count;
9686 outq_count = atomic_load_explicit(
9687 &peer->obuf->count,
9688 memory_order_relaxed);
9689 inq_count = atomic_load_explicit(
9690 &peer->ibuf->count,
9691 memory_order_relaxed);
9692
566bdaf6 9693 vty_out(vty,
6cde4b45 9694 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
3577f1c5 9695 peer->as, PEER_TOTAL_RX(peer),
566bdaf6 9696 PEER_TOTAL_TX(peer),
43aa5965
QY
9697 peer->version[afi][safi], inq_count,
9698 outq_count,
3577f1c5
DD
9699 peer_uptime(peer->uptime, timebuf,
9700 BGP_UPTIME_LEN, 0, NULL));
9701
db92d226 9702 if (peer->status == Established) {
d3ada366
DA
9703 if (peer->afc_recv[afi][safi]) {
9704 if (CHECK_FLAG(
9705 bgp->flags,
9706 BGP_FLAG_EBGP_REQUIRES_POLICY)
9707 && !bgp_inbound_policy_exists(
9708 peer, filter))
9709 vty_out(vty, " %12s",
9710 "(Policy)");
9711 else
9712 vty_out(vty,
6cde4b45 9713 " %12u",
d3ada366
DA
9714 peer->pcount
9715 [afi]
9716 [pfx_rcd_safi]);
9717 } else {
3577f1c5 9718 vty_out(vty, " NoNeg");
d3ada366 9719 }
db92d226 9720
d3ada366
DA
9721 if (paf && PAF_SUBGRP(paf)) {
9722 if (CHECK_FLAG(
9723 bgp->flags,
9724 BGP_FLAG_EBGP_REQUIRES_POLICY)
9725 && !bgp_outbound_policy_exists(
9726 peer, filter))
9727 vty_out(vty, " %8s",
9728 "(Policy)");
9729 else
9730 vty_out(vty,
6cde4b45 9731 " %8u",
d3ada366
DA
9732 (PAF_SUBGRP(
9733 paf))
9734 ->scount);
9735 }
db92d226 9736 } else {
736b68f3
DS
9737 if (CHECK_FLAG(peer->flags,
9738 PEER_FLAG_SHUTDOWN)
9739 || CHECK_FLAG(peer->bgp->flags,
9740 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
9741 vty_out(vty, " Idle (Admin)");
9742 else if (CHECK_FLAG(
9743 peer->sflags,
9744 PEER_STATUS_PREFIX_OVERFLOW))
9745 vty_out(vty, " Idle (PfxCt)");
9746 else
9747 vty_out(vty, " %12s",
9748 lookup_msg(bgp_status_msg,
9749 peer->status, NULL));
db92d226 9750
6cde4b45 9751 vty_out(vty, " %8u", 0);
3577f1c5
DD
9752 }
9753 vty_out(vty, "\n");
d62a17ae 9754 }
3577f1c5 9755
d62a17ae 9756 }
9757 }
f933309e 9758
d62a17ae 9759 if (use_json) {
9760 json_object_object_add(json, "peers", json_peers);
3577f1c5 9761 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 9762 json_object_int_add(json, "totalPeers", count);
9763 json_object_int_add(json, "dynamicPeers", dn_count);
9764
3577f1c5
DD
9765 if (!show_failed)
9766 bgp_show_bestpath_json(bgp, json);
57a9c8a8 9767
996c9314
LB
9768 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9769 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9770 json_object_free(json);
9771 } else {
9772 if (count)
9773 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9774 else {
d6ceaca3 9775 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 9776 get_afi_safi_str(afi, safi, false));
d62a17ae 9777 }
b05a1c8b 9778
d6ceaca3 9779 if (dn_count) {
d62a17ae 9780 vty_out(vty, "* - dynamic neighbor\n");
9781 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
9782 dn_count, bgp->dynamic_neighbors_limit);
9783 }
9784 }
1ff9a340 9785
d62a17ae 9786 return CMD_SUCCESS;
718e3744 9787}
9788
d62a17ae 9789static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10b49f14
DA
9790 int safi, bool show_failed,
9791 bool show_established, bool use_json)
d62a17ae 9792{
9793 int is_first = 1;
9794 int afi_wildcard = (afi == AFI_MAX);
9795 int safi_wildcard = (safi == SAFI_MAX);
9796 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 9797 bool nbr_output = false;
d62a17ae 9798
9799 if (use_json && is_wildcard)
9800 vty_out(vty, "{\n");
9801 if (afi_wildcard)
9802 afi = 1; /* AFI_IP */
9803 while (afi < AFI_MAX) {
9804 if (safi_wildcard)
9805 safi = 1; /* SAFI_UNICAST */
9806 while (safi < SAFI_MAX) {
318cac96 9807 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 9808 nbr_output = true;
f86897b9 9809
d62a17ae 9810 if (is_wildcard) {
9811 /*
9812 * So limit output to those afi/safi
9813 * pairs that
9814 * actualy have something interesting in
9815 * them
9816 */
9817 if (use_json) {
d62a17ae 9818 if (!is_first)
9819 vty_out(vty, ",\n");
9820 else
9821 is_first = 0;
9822
9823 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
9824 get_afi_safi_str(afi,
9825 safi,
9826 true));
d62a17ae 9827 } else {
9828 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
9829 get_afi_safi_str(afi,
9830 safi,
9831 false));
d62a17ae 9832 }
9833 }
10b49f14
DA
9834 bgp_show_summary(vty, bgp, afi, safi,
9835 show_failed, show_established,
3577f1c5 9836 use_json);
d62a17ae 9837 }
9838 safi++;
d62a17ae 9839 if (!safi_wildcard)
9840 safi = SAFI_MAX;
9841 }
9842 afi++;
ee851c8c 9843 if (!afi_wildcard)
d62a17ae 9844 afi = AFI_MAX;
9845 }
9846
9847 if (use_json && is_wildcard)
9848 vty_out(vty, "}\n");
ca61fd25
DS
9849 else if (!nbr_output) {
9850 if (use_json)
9851 vty_out(vty, "{}\n");
9852 else
9853 vty_out(vty, "%% No BGP neighbors found\n");
9854 }
d62a17ae 9855}
9856
9857static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5 9858 safi_t safi, bool show_failed,
10b49f14 9859 bool show_established,
3577f1c5 9860 bool use_json)
d62a17ae 9861{
9862 struct listnode *node, *nnode;
9863 struct bgp *bgp;
d62a17ae 9864 int is_first = 1;
9f049418 9865 bool nbr_output = false;
d62a17ae 9866
9867 if (use_json)
9868 vty_out(vty, "{\n");
9869
9870 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 9871 nbr_output = true;
d62a17ae 9872 if (use_json) {
d62a17ae 9873 if (!is_first)
9874 vty_out(vty, ",\n");
9875 else
9876 is_first = 0;
9877
9878 vty_out(vty, "\"%s\":",
9879 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9880 ? VRF_DEFAULT_NAME
d62a17ae 9881 : bgp->name);
9882 } else {
9883 vty_out(vty, "\nInstance %s:\n",
9884 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9885 ? VRF_DEFAULT_NAME
d62a17ae 9886 : bgp->name);
9887 }
3577f1c5 9888 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 9889 show_established, use_json);
d62a17ae 9890 }
9891
9892 if (use_json)
9893 vty_out(vty, "}\n");
9f049418
DS
9894 else if (!nbr_output)
9895 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 9896}
9897
9898int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10b49f14
DA
9899 safi_t safi, bool show_failed, bool show_established,
9900 bool use_json)
d62a17ae 9901{
9902 struct bgp *bgp;
9903
9904 if (name) {
9905 if (strmatch(name, "all")) {
10b49f14
DA
9906 bgp_show_all_instances_summary_vty(
9907 vty, afi, safi, show_failed, show_established,
9908 use_json);
d62a17ae 9909 return CMD_SUCCESS;
9910 } else {
9911 bgp = bgp_lookup_by_name(name);
9912
9913 if (!bgp) {
9914 if (use_json)
9915 vty_out(vty, "{}\n");
9916 else
9917 vty_out(vty,
ca61fd25 9918 "%% BGP instance not found\n");
d62a17ae 9919 return CMD_WARNING;
9920 }
9921
f86897b9 9922 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
10b49f14
DA
9923 show_failed, show_established,
9924 use_json);
d62a17ae 9925 return CMD_SUCCESS;
9926 }
9927 }
9928
9929 bgp = bgp_get_default();
9930
9931 if (bgp)
3577f1c5 9932 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 9933 show_established, use_json);
9f049418 9934 else {
ca61fd25
DS
9935 if (use_json)
9936 vty_out(vty, "{}\n");
9937 else
9938 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
9939 return CMD_WARNING;
9940 }
d62a17ae 9941
9942 return CMD_SUCCESS;
4fb25c53
DW
9943}
9944
716b2d8a 9945/* `show [ip] bgp summary' commands. */
96f3485c 9946DEFPY (show_ip_bgp_summary,
718e3744 9947 show_ip_bgp_summary_cmd,
96f3485c 9948 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
718e3744 9949 SHOW_STR
9950 IP_STR
9951 BGP_STR
8386ac43 9952 BGP_INSTANCE_HELP_STR
46f296b4 9953 BGP_AFI_HELP_STR
dd6bd0f1 9954 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 9955 "Display the entries for all address families\n"
b05a1c8b 9956 "Summary of BGP neighbor status\n"
10b49f14 9957 "Show only sessions in Established state\n"
3577f1c5 9958 "Show only sessions not in Established state\n"
9973d184 9959 JSON_STR)
718e3744 9960{
d62a17ae 9961 char *vrf = NULL;
9962 afi_t afi = AFI_MAX;
9963 safi_t safi = SAFI_MAX;
3577f1c5 9964 bool show_failed = false;
10b49f14 9965 bool show_established = false;
d62a17ae 9966
9967 int idx = 0;
9968
9969 /* show [ip] bgp */
96f3485c 9970 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 9971 afi = AFI_IP;
9a8bdf1c
PG
9972 /* [<vrf> VIEWVRFNAME] */
9973 if (argv_find(argv, argc, "vrf", &idx)) {
9974 vrf = argv[idx + 1]->arg;
9975 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9976 vrf = NULL;
9977 } else if (argv_find(argv, argc, "view", &idx))
9978 /* [<view> VIEWVRFNAME] */
9979 vrf = argv[idx + 1]->arg;
d62a17ae 9980 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9981 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
9982 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9983 }
9984
3577f1c5
DD
9985 if (argv_find(argv, argc, "failed", &idx))
9986 show_failed = true;
10b49f14
DA
9987 if (argv_find(argv, argc, "established", &idx))
9988 show_established = true;
3577f1c5 9989
10b49f14
DA
9990 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
9991 show_established, uj);
d62a17ae 9992}
9993
5cb5f4d0 9994const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 9995{
5cb5f4d0
DD
9996 if (for_json)
9997 return get_afi_safi_json_str(afi, safi);
d62a17ae 9998 else
5cb5f4d0 9999 return get_afi_safi_vty_str(afi, safi);
27162734
LB
10000}
10001
d62a17ae 10002
10003static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
10004 afi_t afi, safi_t safi,
d7c0a89a
QY
10005 uint16_t adv_smcap, uint16_t adv_rmcap,
10006 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 10007 bool use_json, json_object *json_pref)
d62a17ae 10008{
10009 /* Send-Mode */
10010 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10011 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
10012 if (use_json) {
10013 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10014 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10015 json_object_string_add(json_pref, "sendMode",
10016 "advertisedAndReceived");
10017 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10018 json_object_string_add(json_pref, "sendMode",
10019 "advertised");
10020 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10021 json_object_string_add(json_pref, "sendMode",
10022 "received");
10023 } else {
10024 vty_out(vty, " Send-mode: ");
10025 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10026 vty_out(vty, "advertised");
10027 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10028 vty_out(vty, "%sreceived",
10029 CHECK_FLAG(p->af_cap[afi][safi],
10030 adv_smcap)
10031 ? ", "
10032 : "");
10033 vty_out(vty, "\n");
10034 }
10035 }
10036
10037 /* Receive-Mode */
10038 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10039 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
10040 if (use_json) {
10041 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10042 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10043 json_object_string_add(json_pref, "recvMode",
10044 "advertisedAndReceived");
10045 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10046 json_object_string_add(json_pref, "recvMode",
10047 "advertised");
10048 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10049 json_object_string_add(json_pref, "recvMode",
10050 "received");
10051 } else {
10052 vty_out(vty, " Receive-mode: ");
10053 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10054 vty_out(vty, "advertised");
10055 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10056 vty_out(vty, "%sreceived",
10057 CHECK_FLAG(p->af_cap[afi][safi],
10058 adv_rmcap)
10059 ? ", "
10060 : "");
10061 vty_out(vty, "\n");
10062 }
10063 }
10064}
10065
13909c4f
DS
10066static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
10067 struct peer *p,
10068 bool use_json,
10069 json_object *json)
2986cac2 10070{
08c2d52a 10071 bool rbit_status = false;
2986cac2 10072
10073 if (!use_json)
a53ca37b 10074 vty_out(vty, "\n R bit: ");
2986cac2 10075
13909c4f
DS
10076 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
10077 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
10078 && (p->status == Established)) {
2986cac2 10079
10080 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 10081 rbit_status = true;
2986cac2 10082 else
08c2d52a 10083 rbit_status = false;
2986cac2 10084 }
10085
10086 if (rbit_status) {
10087 if (use_json)
13909c4f 10088 json_object_boolean_true_add(json, "rBit");
2986cac2 10089 else
10090 vty_out(vty, "True\n");
10091 } else {
10092 if (use_json)
13909c4f 10093 json_object_boolean_false_add(json, "rBit");
2986cac2 10094 else
10095 vty_out(vty, "False\n");
10096 }
10097}
10098
13909c4f
DS
10099static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
10100 struct peer *peer,
10101 bool use_json,
10102 json_object *json)
2986cac2 10103{
2bb5d39b 10104 const char *mode = "NotApplicable";
2986cac2 10105
10106 if (!use_json)
a53ca37b 10107 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 10108
13909c4f
DS
10109 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10110 && (peer->status == Established)) {
2986cac2 10111
13909c4f
DS
10112 if ((peer->nsf_af_count == 0)
10113 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10114
2986cac2 10115 mode = "Disable";
10116
13909c4f
DS
10117 } else if (peer->nsf_af_count == 0
10118 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10119
2986cac2 10120 mode = "Helper";
10121
13909c4f
DS
10122 } else if (peer->nsf_af_count != 0
10123 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10124
2986cac2 10125 mode = "Restart";
2986cac2 10126 }
10127 }
10128
10129 if (use_json) {
13909c4f 10130 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 10131 } else
10132 vty_out(vty, mode, "\n");
10133}
10134
13909c4f
DS
10135static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
10136 struct peer *p,
10137 bool use_json,
10138 json_object *json)
2986cac2 10139{
10140 const char *mode = "Invalid";
10141
10142 if (!use_json)
a53ca37b 10143 vty_out(vty, " Local GR Mode: ");
2986cac2 10144
10145 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
10146 mode = "Helper";
10147 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
10148 mode = "Restart";
10149 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
10150 mode = "Disable";
2ba1fe69 10151 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 10152 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
10153 mode = "Helper*";
10154 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
10155 mode = "Restart*";
10156 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
10157 mode = "Disable*";
10158 else
10159 mode = "Invalid*";
2ba1fe69 10160 }
2986cac2 10161
10162 if (use_json) {
13909c4f 10163 json_object_string_add(json, "localGrMode", mode);
2986cac2 10164 } else {
10165 vty_out(vty, mode, "\n");
10166 }
10167}
10168
13909c4f
DS
10169static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
10170 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 10171{
2ba1fe69 10172 afi_t afi;
10173 safi_t safi;
2986cac2 10174 json_object *json_afi_safi = NULL;
10175 json_object *json_timer = NULL;
10176 json_object *json_endofrib_status = NULL;
9e3b51a7 10177 bool eor_flag = false;
2986cac2 10178
10179 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10180 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
10181 if (!peer->afc[afi][safi])
10182 continue;
2986cac2 10183
13909c4f
DS
10184 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10185 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
10186 continue;
9e3b51a7 10187
13909c4f
DS
10188 if (use_json) {
10189 json_afi_safi = json_object_new_object();
10190 json_endofrib_status = json_object_new_object();
10191 json_timer = json_object_new_object();
10192 }
2986cac2 10193
13909c4f
DS
10194 if (peer->eor_stime[afi][safi]
10195 >= peer->pkt_stime[afi][safi])
10196 eor_flag = true;
10197 else
10198 eor_flag = false;
2986cac2 10199
13909c4f 10200 if (!use_json) {
a53ca37b 10201 vty_out(vty, " %s:\n",
13909c4f 10202 get_afi_safi_str(afi, safi, false));
2986cac2 10203
a53ca37b 10204 vty_out(vty, " F bit: ");
698ba8d0 10205 }
2986cac2 10206
13909c4f
DS
10207 if (peer->nsf[afi][safi]
10208 && CHECK_FLAG(peer->af_cap[afi][safi],
10209 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 10210
13909c4f
DS
10211 if (use_json) {
10212 json_object_boolean_true_add(
2986cac2 10213 json_afi_safi, "fBit");
13909c4f
DS
10214 } else
10215 vty_out(vty, "True\n");
10216 } else {
10217 if (use_json)
10218 json_object_boolean_false_add(
10219 json_afi_safi, "fBit");
10220 else
10221 vty_out(vty, "False\n");
10222 }
2986cac2 10223
13909c4f 10224 if (!use_json)
a53ca37b 10225 vty_out(vty, " End-of-RIB sent: ");
2986cac2 10226
13909c4f
DS
10227 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10228 PEER_STATUS_EOR_SEND)) {
10229 if (use_json) {
10230 json_object_boolean_true_add(
2986cac2 10231 json_endofrib_status,
13909c4f 10232 "endOfRibSend");
9e3b51a7 10233
13909c4f
DS
10234 PRINT_EOR_JSON(eor_flag);
10235 } else {
10236 vty_out(vty, "Yes\n");
10237 vty_out(vty,
a53ca37b 10238 " End-of-RIB sent after update: ");
2986cac2 10239
13909c4f
DS
10240 PRINT_EOR(eor_flag);
10241 }
10242 } else {
10243 if (use_json) {
10244 json_object_boolean_false_add(
2986cac2 10245 json_endofrib_status,
13909c4f
DS
10246 "endOfRibSend");
10247 json_object_boolean_false_add(
9e3b51a7 10248 json_endofrib_status,
13909c4f
DS
10249 "endOfRibSentAfterUpdate");
10250 } else {
10251 vty_out(vty, "No\n");
10252 vty_out(vty,
a53ca37b 10253 " End-of-RIB sent after update: ");
13909c4f 10254 vty_out(vty, "No\n");
2986cac2 10255 }
13909c4f 10256 }
2986cac2 10257
a53ca37b
DA
10258 if (!use_json)
10259 vty_out(vty, " End-of-RIB received: ");
10260
10261 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10262 PEER_STATUS_EOR_RECEIVED)) {
10263 if (use_json)
10264 json_object_boolean_true_add(
10265 json_endofrib_status,
10266 "endOfRibRecv");
10267 else
10268 vty_out(vty, "Yes\n");
10269 } else {
10270 if (use_json)
10271 json_object_boolean_false_add(
10272 json_endofrib_status,
10273 "endOfRibRecv");
10274 else
10275 vty_out(vty, "No\n");
10276 }
10277
13909c4f
DS
10278 if (use_json) {
10279 json_object_int_add(json_timer,
10280 "stalePathTimer",
10281 peer->bgp->stalepath_time);
2986cac2 10282
13909c4f
DS
10283 if (peer->t_gr_stale != NULL) {
10284 json_object_int_add(
2986cac2 10285 json_timer,
10286 "stalePathTimerRemaining",
10287 thread_timer_remain_second(
13909c4f
DS
10288 peer->t_gr_stale));
10289 }
3a75afa4 10290
13909c4f
DS
10291 /* Display Configured Selection
10292 * Deferral only when when
10293 * Gr mode is enabled.
10294 */
10295 if (CHECK_FLAG(peer->flags,
10296 PEER_FLAG_GRACEFUL_RESTART)) {
10297 json_object_int_add(
3a75afa4 10298 json_timer,
2986cac2 10299 "selectionDeferralTimer",
10300 peer->bgp->stalepath_time);
13909c4f 10301 }
2986cac2 10302
13909c4f
DS
10303 if (peer->bgp->gr_info[afi][safi]
10304 .t_select_deferral
10305 != NULL) {
2986cac2 10306
13909c4f 10307 json_object_int_add(
2986cac2 10308 json_timer,
10309 "selectionDeferralTimerRemaining",
10310 thread_timer_remain_second(
13909c4f
DS
10311 peer->bgp
10312 ->gr_info[afi]
10313 [safi]
10314 .t_select_deferral));
10315 }
10316 } else {
a53ca37b 10317 vty_out(vty, " Timers:\n");
13909c4f 10318 vty_out(vty,
a53ca37b
DA
10319 " Configured Stale Path Time(sec): %u\n",
10320 peer->bgp->stalepath_time);
2986cac2 10321
a53ca37b 10322 if (peer->t_gr_stale != NULL)
2986cac2 10323 vty_out(vty,
a53ca37b 10324 " Stale Path Remaining(sec): %ld\n",
2986cac2 10325 thread_timer_remain_second(
13909c4f 10326 peer->t_gr_stale));
13909c4f
DS
10327 /* Display Configured Selection
10328 * Deferral only when when
10329 * Gr mode is enabled.
10330 */
10331 if (CHECK_FLAG(peer->flags,
a53ca37b 10332 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 10333 vty_out(vty,
a53ca37b 10334 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 10335 peer->bgp->select_defer_time);
2986cac2 10336
13909c4f
DS
10337 if (peer->bgp->gr_info[afi][safi]
10338 .t_select_deferral
a53ca37b 10339 != NULL)
13909c4f 10340 vty_out(vty,
a53ca37b 10341 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 10342 thread_timer_remain_second(
13909c4f
DS
10343 peer->bgp
10344 ->gr_info[afi]
10345 [safi]
10346 .t_select_deferral));
2986cac2 10347 }
13909c4f
DS
10348 if (use_json) {
10349 json_object_object_add(json_afi_safi,
10350 "endOfRibStatus",
10351 json_endofrib_status);
10352 json_object_object_add(json_afi_safi, "timers",
10353 json_timer);
10354 json_object_object_add(
10355 json, get_afi_safi_str(afi, safi, true),
10356 json_afi_safi);
10357 }
2986cac2 10358 }
10359 }
10360}
10361
36235319
QY
10362static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
10363 struct peer *p,
10364 bool use_json,
10365 json_object *json)
2986cac2 10366{
10367 if (use_json) {
10368 json_object *json_timer = NULL;
10369
10370 json_timer = json_object_new_object();
10371
13909c4f
DS
10372 json_object_int_add(json_timer, "configuredRestartTimer",
10373 p->bgp->restart_time);
2986cac2 10374
13909c4f
DS
10375 json_object_int_add(json_timer, "receivedRestartTimer",
10376 p->v_gr_restart);
2986cac2 10377
13909c4f
DS
10378 if (p->t_gr_restart != NULL)
10379 json_object_int_add(
10380 json_timer, "restartTimerRemaining",
10381 thread_timer_remain_second(p->t_gr_restart));
2986cac2 10382
10383 json_object_object_add(json, "timers", json_timer);
10384 } else {
10385
a53ca37b
DA
10386 vty_out(vty, " Timers:\n");
10387 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 10388 p->bgp->restart_time);
2986cac2 10389
a53ca37b 10390 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
10391 p->v_gr_restart);
10392 if (p->t_gr_restart != NULL)
a53ca37b 10393 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 10394 thread_timer_remain_second(p->t_gr_restart));
36235319 10395 if (p->t_gr_restart != NULL) {
a53ca37b 10396 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
10397 thread_timer_remain_second(p->t_gr_restart));
10398 }
2986cac2 10399 }
10400}
10401
10402static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 10403 bool use_json, json_object *json)
2986cac2 10404{
10405 char buf[SU_ADDRSTRLEN] = {0};
10406 char dn_flag[2] = {0};
2b7165e7
QY
10407 /* '*' + v6 address of neighbor */
10408 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 10409
2986cac2 10410 if (!p->conf_if && peer_dynamic_neighbor(p))
10411 dn_flag[0] = '*';
10412
10413 if (p->conf_if) {
10414 if (use_json)
13909c4f
DS
10415 json_object_string_add(
10416 json, "neighborAddr",
2986cac2 10417 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
10418 ? "none"
10419 : sockunion2str(&p->su, buf,
10420 SU_ADDRSTRLEN));
2986cac2 10421 else
13909c4f 10422 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 10423 BGP_PEER_SU_UNSPEC(p)
10424 ? "none"
10425 : sockunion2str(&p->su, buf,
10426 SU_ADDRSTRLEN));
10427 } else {
772270f3
QY
10428 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
10429 p->host);
2986cac2 10430
10431 if (use_json)
36235319
QY
10432 json_object_string_add(json, "neighborAddr",
10433 neighborAddr);
2986cac2 10434 else
36235319 10435 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 10436 }
10437
10438 /* more gr info in new format */
10439 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
10440}
10441
d62a17ae 10442static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 10443 safi_t safi, bool use_json,
d62a17ae 10444 json_object *json_neigh)
10445{
0291c246
MK
10446 struct bgp_filter *filter;
10447 struct peer_af *paf;
10448 char orf_pfx_name[BUFSIZ];
10449 int orf_pfx_count;
10450 json_object *json_af = NULL;
10451 json_object *json_prefA = NULL;
10452 json_object *json_prefB = NULL;
10453 json_object *json_addr = NULL;
d62a17ae 10454
10455 if (use_json) {
10456 json_addr = json_object_new_object();
10457 json_af = json_object_new_object();
10458 filter = &p->filter[afi][safi];
10459
10460 if (peer_group_active(p))
10461 json_object_string_add(json_addr, "peerGroupMember",
10462 p->group->name);
10463
10464 paf = peer_af_find(p, afi, safi);
10465 if (paf && PAF_SUBGRP(paf)) {
10466 json_object_int_add(json_addr, "updateGroupId",
10467 PAF_UPDGRP(paf)->id);
10468 json_object_int_add(json_addr, "subGroupId",
10469 PAF_SUBGRP(paf)->id);
10470 json_object_int_add(json_addr, "packetQueueLength",
10471 bpacket_queue_virtual_length(paf));
10472 }
10473
10474 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10475 || CHECK_FLAG(p->af_cap[afi][safi],
10476 PEER_CAP_ORF_PREFIX_SM_RCV)
10477 || CHECK_FLAG(p->af_cap[afi][safi],
10478 PEER_CAP_ORF_PREFIX_RM_ADV)
10479 || CHECK_FLAG(p->af_cap[afi][safi],
10480 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10481 json_object_int_add(json_af, "orfType",
10482 ORF_TYPE_PREFIX);
10483 json_prefA = json_object_new_object();
10484 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
10485 PEER_CAP_ORF_PREFIX_SM_ADV,
10486 PEER_CAP_ORF_PREFIX_RM_ADV,
10487 PEER_CAP_ORF_PREFIX_SM_RCV,
10488 PEER_CAP_ORF_PREFIX_RM_RCV,
10489 use_json, json_prefA);
10490 json_object_object_add(json_af, "orfPrefixList",
10491 json_prefA);
10492 }
10493
10494 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10495 || CHECK_FLAG(p->af_cap[afi][safi],
10496 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10497 || CHECK_FLAG(p->af_cap[afi][safi],
10498 PEER_CAP_ORF_PREFIX_RM_ADV)
10499 || CHECK_FLAG(p->af_cap[afi][safi],
10500 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10501 json_object_int_add(json_af, "orfOldType",
10502 ORF_TYPE_PREFIX_OLD);
10503 json_prefB = json_object_new_object();
10504 bgp_show_peer_afi_orf_cap(
10505 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10506 PEER_CAP_ORF_PREFIX_RM_ADV,
10507 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10508 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
10509 json_prefB);
10510 json_object_object_add(json_af, "orfOldPrefixList",
10511 json_prefB);
10512 }
10513
10514 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10515 || CHECK_FLAG(p->af_cap[afi][safi],
10516 PEER_CAP_ORF_PREFIX_SM_RCV)
10517 || CHECK_FLAG(p->af_cap[afi][safi],
10518 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10519 || CHECK_FLAG(p->af_cap[afi][safi],
10520 PEER_CAP_ORF_PREFIX_RM_ADV)
10521 || CHECK_FLAG(p->af_cap[afi][safi],
10522 PEER_CAP_ORF_PREFIX_RM_RCV)
10523 || CHECK_FLAG(p->af_cap[afi][safi],
10524 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10525 json_object_object_add(json_addr, "afDependentCap",
10526 json_af);
10527 else
10528 json_object_free(json_af);
10529
772270f3
QY
10530 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10531 p->host, afi, safi);
d62a17ae 10532 orf_pfx_count = prefix_bgp_show_prefix_list(
10533 NULL, afi, orf_pfx_name, use_json);
10534
10535 if (CHECK_FLAG(p->af_sflags[afi][safi],
10536 PEER_STATUS_ORF_PREFIX_SEND)
10537 || orf_pfx_count) {
10538 if (CHECK_FLAG(p->af_sflags[afi][safi],
10539 PEER_STATUS_ORF_PREFIX_SEND))
10540 json_object_boolean_true_add(json_neigh,
10541 "orfSent");
10542 if (orf_pfx_count)
10543 json_object_int_add(json_addr, "orfRecvCounter",
10544 orf_pfx_count);
10545 }
10546 if (CHECK_FLAG(p->af_sflags[afi][safi],
10547 PEER_STATUS_ORF_WAIT_REFRESH))
10548 json_object_string_add(
10549 json_addr, "orfFirstUpdate",
10550 "deferredUntilORFOrRouteRefreshRecvd");
10551
10552 if (CHECK_FLAG(p->af_flags[afi][safi],
10553 PEER_FLAG_REFLECTOR_CLIENT))
10554 json_object_boolean_true_add(json_addr,
10555 "routeReflectorClient");
10556 if (CHECK_FLAG(p->af_flags[afi][safi],
10557 PEER_FLAG_RSERVER_CLIENT))
10558 json_object_boolean_true_add(json_addr,
10559 "routeServerClient");
10560 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10561 json_object_boolean_true_add(json_addr,
10562 "inboundSoftConfigPermit");
10563
10564 if (CHECK_FLAG(p->af_flags[afi][safi],
10565 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10566 json_object_boolean_true_add(
10567 json_addr,
10568 "privateAsNumsAllReplacedInUpdatesToNbr");
10569 else if (CHECK_FLAG(p->af_flags[afi][safi],
10570 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10571 json_object_boolean_true_add(
10572 json_addr,
10573 "privateAsNumsReplacedInUpdatesToNbr");
10574 else if (CHECK_FLAG(p->af_flags[afi][safi],
10575 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10576 json_object_boolean_true_add(
10577 json_addr,
10578 "privateAsNumsAllRemovedInUpdatesToNbr");
10579 else if (CHECK_FLAG(p->af_flags[afi][safi],
10580 PEER_FLAG_REMOVE_PRIVATE_AS))
10581 json_object_boolean_true_add(
10582 json_addr,
10583 "privateAsNumsRemovedInUpdatesToNbr");
10584
dcc68b5e
MS
10585 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10586 json_object_boolean_true_add(
10587 json_addr,
10588 bgp_addpath_names(p->addpath_type[afi][safi])
10589 ->type_json_name);
d62a17ae 10590
10591 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10592 json_object_string_add(json_addr,
10593 "overrideASNsInOutboundUpdates",
10594 "ifAspathEqualRemoteAs");
10595
10596 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10597 || CHECK_FLAG(p->af_flags[afi][safi],
10598 PEER_FLAG_FORCE_NEXTHOP_SELF))
10599 json_object_boolean_true_add(json_addr,
10600 "routerAlwaysNextHop");
10601 if (CHECK_FLAG(p->af_flags[afi][safi],
10602 PEER_FLAG_AS_PATH_UNCHANGED))
10603 json_object_boolean_true_add(
10604 json_addr, "unchangedAsPathPropogatedToNbr");
10605 if (CHECK_FLAG(p->af_flags[afi][safi],
10606 PEER_FLAG_NEXTHOP_UNCHANGED))
10607 json_object_boolean_true_add(
10608 json_addr, "unchangedNextHopPropogatedToNbr");
10609 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10610 json_object_boolean_true_add(
10611 json_addr, "unchangedMedPropogatedToNbr");
10612 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10613 || CHECK_FLAG(p->af_flags[afi][safi],
10614 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10615 if (CHECK_FLAG(p->af_flags[afi][safi],
10616 PEER_FLAG_SEND_COMMUNITY)
10617 && CHECK_FLAG(p->af_flags[afi][safi],
10618 PEER_FLAG_SEND_EXT_COMMUNITY))
10619 json_object_string_add(json_addr,
10620 "commAttriSentToNbr",
10621 "extendedAndStandard");
10622 else if (CHECK_FLAG(p->af_flags[afi][safi],
10623 PEER_FLAG_SEND_EXT_COMMUNITY))
10624 json_object_string_add(json_addr,
10625 "commAttriSentToNbr",
10626 "extended");
10627 else
10628 json_object_string_add(json_addr,
10629 "commAttriSentToNbr",
10630 "standard");
10631 }
10632 if (CHECK_FLAG(p->af_flags[afi][safi],
10633 PEER_FLAG_DEFAULT_ORIGINATE)) {
10634 if (p->default_rmap[afi][safi].name)
10635 json_object_string_add(
10636 json_addr, "defaultRouteMap",
10637 p->default_rmap[afi][safi].name);
10638
10639 if (paf && PAF_SUBGRP(paf)
10640 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10641 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10642 json_object_boolean_true_add(json_addr,
10643 "defaultSent");
10644 else
10645 json_object_boolean_true_add(json_addr,
10646 "defaultNotSent");
10647 }
10648
dff8f48d 10649 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10650 if (is_evpn_enabled())
60466a63
QY
10651 json_object_boolean_true_add(
10652 json_addr, "advertiseAllVnis");
dff8f48d
MK
10653 }
10654
d62a17ae 10655 if (filter->plist[FILTER_IN].name
10656 || filter->dlist[FILTER_IN].name
10657 || filter->aslist[FILTER_IN].name
10658 || filter->map[RMAP_IN].name)
10659 json_object_boolean_true_add(json_addr,
10660 "inboundPathPolicyConfig");
10661 if (filter->plist[FILTER_OUT].name
10662 || filter->dlist[FILTER_OUT].name
10663 || filter->aslist[FILTER_OUT].name
10664 || filter->map[RMAP_OUT].name || filter->usmap.name)
10665 json_object_boolean_true_add(
10666 json_addr, "outboundPathPolicyConfig");
10667
10668 /* prefix-list */
10669 if (filter->plist[FILTER_IN].name)
10670 json_object_string_add(json_addr,
10671 "incomingUpdatePrefixFilterList",
10672 filter->plist[FILTER_IN].name);
10673 if (filter->plist[FILTER_OUT].name)
10674 json_object_string_add(json_addr,
10675 "outgoingUpdatePrefixFilterList",
10676 filter->plist[FILTER_OUT].name);
10677
10678 /* distribute-list */
10679 if (filter->dlist[FILTER_IN].name)
10680 json_object_string_add(
10681 json_addr, "incomingUpdateNetworkFilterList",
10682 filter->dlist[FILTER_IN].name);
10683 if (filter->dlist[FILTER_OUT].name)
10684 json_object_string_add(
10685 json_addr, "outgoingUpdateNetworkFilterList",
10686 filter->dlist[FILTER_OUT].name);
10687
10688 /* filter-list. */
10689 if (filter->aslist[FILTER_IN].name)
10690 json_object_string_add(json_addr,
10691 "incomingUpdateAsPathFilterList",
10692 filter->aslist[FILTER_IN].name);
10693 if (filter->aslist[FILTER_OUT].name)
10694 json_object_string_add(json_addr,
10695 "outgoingUpdateAsPathFilterList",
10696 filter->aslist[FILTER_OUT].name);
10697
10698 /* route-map. */
10699 if (filter->map[RMAP_IN].name)
10700 json_object_string_add(
10701 json_addr, "routeMapForIncomingAdvertisements",
10702 filter->map[RMAP_IN].name);
10703 if (filter->map[RMAP_OUT].name)
10704 json_object_string_add(
10705 json_addr, "routeMapForOutgoingAdvertisements",
10706 filter->map[RMAP_OUT].name);
10707
9dac9fc8 10708 /* ebgp-requires-policy (inbound) */
1d3fdccf 10709 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10710 && !bgp_inbound_policy_exists(p, filter))
10711 json_object_string_add(
10712 json_addr, "inboundEbgpRequiresPolicy",
10713 "Inbound updates discarded due to missing policy");
10714
10715 /* ebgp-requires-policy (outbound) */
1d3fdccf 10716 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10717 && (!bgp_outbound_policy_exists(p, filter)))
10718 json_object_string_add(
10719 json_addr, "outboundEbgpRequiresPolicy",
10720 "Outbound updates discarded due to missing policy");
10721
d62a17ae 10722 /* unsuppress-map */
10723 if (filter->usmap.name)
10724 json_object_string_add(json_addr,
10725 "selectiveUnsuppressRouteMap",
10726 filter->usmap.name);
10727
10728 /* Receive prefix count */
10729 json_object_int_add(json_addr, "acceptedPrefixCounter",
10730 p->pcount[afi][safi]);
50e05855
AD
10731 if (paf && PAF_SUBGRP(paf))
10732 json_object_int_add(json_addr, "sentPrefixCounter",
10733 (PAF_SUBGRP(paf))->scount);
d62a17ae 10734
fde246e8
DA
10735 /* Maximum prefix */
10736 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10737 json_object_int_add(json_addr, "prefixOutAllowedMax",
10738 p->pmax_out[afi][safi]);
10739
d62a17ae 10740 /* Maximum prefix */
10741 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10742 json_object_int_add(json_addr, "prefixAllowedMax",
10743 p->pmax[afi][safi]);
10744 if (CHECK_FLAG(p->af_flags[afi][safi],
10745 PEER_FLAG_MAX_PREFIX_WARNING))
10746 json_object_boolean_true_add(
10747 json_addr, "prefixAllowedMaxWarning");
10748 json_object_int_add(json_addr,
10749 "prefixAllowedWarningThresh",
10750 p->pmax_threshold[afi][safi]);
10751 if (p->pmax_restart[afi][safi])
10752 json_object_int_add(
10753 json_addr,
10754 "prefixAllowedRestartIntervalMsecs",
10755 p->pmax_restart[afi][safi] * 60000);
10756 }
2986cac2 10757 json_object_object_add(json_neigh,
36235319 10758 get_afi_safi_str(afi, safi, true),
d62a17ae 10759 json_addr);
10760
10761 } else {
10762 filter = &p->filter[afi][safi];
10763
10764 vty_out(vty, " For address family: %s\n",
5cb5f4d0 10765 get_afi_safi_str(afi, safi, false));
d62a17ae 10766
10767 if (peer_group_active(p))
10768 vty_out(vty, " %s peer-group member\n",
10769 p->group->name);
10770
10771 paf = peer_af_find(p, afi, safi);
10772 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 10773 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 10774 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10775 vty_out(vty, " Packet Queue length %d\n",
10776 bpacket_queue_virtual_length(paf));
10777 } else {
10778 vty_out(vty, " Not part of any update group\n");
10779 }
10780 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10781 || CHECK_FLAG(p->af_cap[afi][safi],
10782 PEER_CAP_ORF_PREFIX_SM_RCV)
10783 || CHECK_FLAG(p->af_cap[afi][safi],
10784 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10785 || CHECK_FLAG(p->af_cap[afi][safi],
10786 PEER_CAP_ORF_PREFIX_RM_ADV)
10787 || CHECK_FLAG(p->af_cap[afi][safi],
10788 PEER_CAP_ORF_PREFIX_RM_RCV)
10789 || CHECK_FLAG(p->af_cap[afi][safi],
10790 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10791 vty_out(vty, " AF-dependant capabilities:\n");
10792
10793 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10794 || CHECK_FLAG(p->af_cap[afi][safi],
10795 PEER_CAP_ORF_PREFIX_SM_RCV)
10796 || CHECK_FLAG(p->af_cap[afi][safi],
10797 PEER_CAP_ORF_PREFIX_RM_ADV)
10798 || CHECK_FLAG(p->af_cap[afi][safi],
10799 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10800 vty_out(vty,
10801 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10802 ORF_TYPE_PREFIX);
10803 bgp_show_peer_afi_orf_cap(
10804 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10805 PEER_CAP_ORF_PREFIX_RM_ADV,
10806 PEER_CAP_ORF_PREFIX_SM_RCV,
10807 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10808 }
10809 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10810 || CHECK_FLAG(p->af_cap[afi][safi],
10811 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10812 || CHECK_FLAG(p->af_cap[afi][safi],
10813 PEER_CAP_ORF_PREFIX_RM_ADV)
10814 || CHECK_FLAG(p->af_cap[afi][safi],
10815 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10816 vty_out(vty,
10817 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10818 ORF_TYPE_PREFIX_OLD);
10819 bgp_show_peer_afi_orf_cap(
10820 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10821 PEER_CAP_ORF_PREFIX_RM_ADV,
10822 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10823 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10824 }
10825
772270f3
QY
10826 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10827 p->host, afi, safi);
d62a17ae 10828 orf_pfx_count = prefix_bgp_show_prefix_list(
10829 NULL, afi, orf_pfx_name, use_json);
10830
10831 if (CHECK_FLAG(p->af_sflags[afi][safi],
10832 PEER_STATUS_ORF_PREFIX_SEND)
10833 || orf_pfx_count) {
10834 vty_out(vty, " Outbound Route Filter (ORF):");
10835 if (CHECK_FLAG(p->af_sflags[afi][safi],
10836 PEER_STATUS_ORF_PREFIX_SEND))
10837 vty_out(vty, " sent;");
10838 if (orf_pfx_count)
10839 vty_out(vty, " received (%d entries)",
10840 orf_pfx_count);
10841 vty_out(vty, "\n");
10842 }
10843 if (CHECK_FLAG(p->af_sflags[afi][safi],
10844 PEER_STATUS_ORF_WAIT_REFRESH))
10845 vty_out(vty,
10846 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10847
10848 if (CHECK_FLAG(p->af_flags[afi][safi],
10849 PEER_FLAG_REFLECTOR_CLIENT))
10850 vty_out(vty, " Route-Reflector Client\n");
10851 if (CHECK_FLAG(p->af_flags[afi][safi],
10852 PEER_FLAG_RSERVER_CLIENT))
10853 vty_out(vty, " Route-Server Client\n");
10854 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10855 vty_out(vty,
10856 " Inbound soft reconfiguration allowed\n");
10857
10858 if (CHECK_FLAG(p->af_flags[afi][safi],
10859 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10860 vty_out(vty,
10861 " Private AS numbers (all) replaced in updates to this neighbor\n");
10862 else if (CHECK_FLAG(p->af_flags[afi][safi],
10863 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10864 vty_out(vty,
10865 " Private AS numbers replaced in updates to this neighbor\n");
10866 else if (CHECK_FLAG(p->af_flags[afi][safi],
10867 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10868 vty_out(vty,
10869 " Private AS numbers (all) removed in updates to this neighbor\n");
10870 else if (CHECK_FLAG(p->af_flags[afi][safi],
10871 PEER_FLAG_REMOVE_PRIVATE_AS))
10872 vty_out(vty,
10873 " Private AS numbers removed in updates to this neighbor\n");
10874
dcc68b5e
MS
10875 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10876 vty_out(vty, " %s\n",
10877 bgp_addpath_names(p->addpath_type[afi][safi])
10878 ->human_description);
d62a17ae 10879
10880 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10881 vty_out(vty,
10882 " Override ASNs in outbound updates if aspath equals remote-as\n");
10883
10884 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10885 || CHECK_FLAG(p->af_flags[afi][safi],
10886 PEER_FLAG_FORCE_NEXTHOP_SELF))
10887 vty_out(vty, " NEXT_HOP is always this router\n");
10888 if (CHECK_FLAG(p->af_flags[afi][safi],
10889 PEER_FLAG_AS_PATH_UNCHANGED))
10890 vty_out(vty,
10891 " AS_PATH is propagated unchanged to this neighbor\n");
10892 if (CHECK_FLAG(p->af_flags[afi][safi],
10893 PEER_FLAG_NEXTHOP_UNCHANGED))
10894 vty_out(vty,
10895 " NEXT_HOP is propagated unchanged to this neighbor\n");
10896 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10897 vty_out(vty,
10898 " MED is propagated unchanged to this neighbor\n");
10899 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10900 || CHECK_FLAG(p->af_flags[afi][safi],
10901 PEER_FLAG_SEND_EXT_COMMUNITY)
10902 || CHECK_FLAG(p->af_flags[afi][safi],
10903 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10904 vty_out(vty,
10905 " Community attribute sent to this neighbor");
10906 if (CHECK_FLAG(p->af_flags[afi][safi],
10907 PEER_FLAG_SEND_COMMUNITY)
10908 && CHECK_FLAG(p->af_flags[afi][safi],
10909 PEER_FLAG_SEND_EXT_COMMUNITY)
10910 && CHECK_FLAG(p->af_flags[afi][safi],
10911 PEER_FLAG_SEND_LARGE_COMMUNITY))
10912 vty_out(vty, "(all)\n");
10913 else if (CHECK_FLAG(p->af_flags[afi][safi],
10914 PEER_FLAG_SEND_LARGE_COMMUNITY))
10915 vty_out(vty, "(large)\n");
10916 else if (CHECK_FLAG(p->af_flags[afi][safi],
10917 PEER_FLAG_SEND_EXT_COMMUNITY))
10918 vty_out(vty, "(extended)\n");
10919 else
10920 vty_out(vty, "(standard)\n");
10921 }
10922 if (CHECK_FLAG(p->af_flags[afi][safi],
10923 PEER_FLAG_DEFAULT_ORIGINATE)) {
10924 vty_out(vty, " Default information originate,");
10925
10926 if (p->default_rmap[afi][safi].name)
10927 vty_out(vty, " default route-map %s%s,",
10928 p->default_rmap[afi][safi].map ? "*"
10929 : "",
10930 p->default_rmap[afi][safi].name);
10931 if (paf && PAF_SUBGRP(paf)
10932 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10933 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10934 vty_out(vty, " default sent\n");
10935 else
10936 vty_out(vty, " default not sent\n");
10937 }
10938
dff8f48d
MK
10939 /* advertise-vni-all */
10940 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10941 if (is_evpn_enabled())
dff8f48d
MK
10942 vty_out(vty, " advertise-all-vni\n");
10943 }
10944
d62a17ae 10945 if (filter->plist[FILTER_IN].name
10946 || filter->dlist[FILTER_IN].name
10947 || filter->aslist[FILTER_IN].name
10948 || filter->map[RMAP_IN].name)
10949 vty_out(vty, " Inbound path policy configured\n");
10950 if (filter->plist[FILTER_OUT].name
10951 || filter->dlist[FILTER_OUT].name
10952 || filter->aslist[FILTER_OUT].name
10953 || filter->map[RMAP_OUT].name || filter->usmap.name)
10954 vty_out(vty, " Outbound path policy configured\n");
10955
10956 /* prefix-list */
10957 if (filter->plist[FILTER_IN].name)
10958 vty_out(vty,
10959 " Incoming update prefix filter list is %s%s\n",
10960 filter->plist[FILTER_IN].plist ? "*" : "",
10961 filter->plist[FILTER_IN].name);
10962 if (filter->plist[FILTER_OUT].name)
10963 vty_out(vty,
10964 " Outgoing update prefix filter list is %s%s\n",
10965 filter->plist[FILTER_OUT].plist ? "*" : "",
10966 filter->plist[FILTER_OUT].name);
10967
10968 /* distribute-list */
10969 if (filter->dlist[FILTER_IN].name)
10970 vty_out(vty,
10971 " Incoming update network filter list is %s%s\n",
10972 filter->dlist[FILTER_IN].alist ? "*" : "",
10973 filter->dlist[FILTER_IN].name);
10974 if (filter->dlist[FILTER_OUT].name)
10975 vty_out(vty,
10976 " Outgoing update network filter list is %s%s\n",
10977 filter->dlist[FILTER_OUT].alist ? "*" : "",
10978 filter->dlist[FILTER_OUT].name);
10979
10980 /* filter-list. */
10981 if (filter->aslist[FILTER_IN].name)
10982 vty_out(vty,
10983 " Incoming update AS path filter list is %s%s\n",
10984 filter->aslist[FILTER_IN].aslist ? "*" : "",
10985 filter->aslist[FILTER_IN].name);
10986 if (filter->aslist[FILTER_OUT].name)
10987 vty_out(vty,
10988 " Outgoing update AS path filter list is %s%s\n",
10989 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10990 filter->aslist[FILTER_OUT].name);
10991
10992 /* route-map. */
10993 if (filter->map[RMAP_IN].name)
10994 vty_out(vty,
10995 " Route map for incoming advertisements is %s%s\n",
10996 filter->map[RMAP_IN].map ? "*" : "",
10997 filter->map[RMAP_IN].name);
10998 if (filter->map[RMAP_OUT].name)
10999 vty_out(vty,
11000 " Route map for outgoing advertisements is %s%s\n",
11001 filter->map[RMAP_OUT].map ? "*" : "",
11002 filter->map[RMAP_OUT].name);
11003
9dac9fc8 11004 /* ebgp-requires-policy (inbound) */
1d3fdccf 11005 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11006 && !bgp_inbound_policy_exists(p, filter))
11007 vty_out(vty,
11008 " Inbound updates discarded due to missing policy\n");
11009
11010 /* ebgp-requires-policy (outbound) */
1d3fdccf 11011 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11012 && !bgp_outbound_policy_exists(p, filter))
11013 vty_out(vty,
11014 " Outbound updates discarded due to missing policy\n");
11015
d62a17ae 11016 /* unsuppress-map */
11017 if (filter->usmap.name)
11018 vty_out(vty,
11019 " Route map for selective unsuppress is %s%s\n",
11020 filter->usmap.map ? "*" : "",
11021 filter->usmap.name);
11022
11023 /* Receive prefix count */
6cde4b45 11024 vty_out(vty, " %u accepted prefixes\n",
a0a87037 11025 p->pcount[afi][safi]);
d62a17ae 11026
fde246e8
DA
11027 /* maximum-prefix-out */
11028 if (CHECK_FLAG(p->af_flags[afi][safi],
11029 PEER_FLAG_MAX_PREFIX_OUT))
11030 vty_out(vty,
6cde4b45 11031 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
11032 p->pmax_out[afi][safi]);
11033
d62a17ae 11034 /* Maximum prefix */
11035 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 11036 vty_out(vty,
6cde4b45 11037 " Maximum prefixes allowed %u%s\n",
d62a17ae 11038 p->pmax[afi][safi],
11039 CHECK_FLAG(p->af_flags[afi][safi],
11040 PEER_FLAG_MAX_PREFIX_WARNING)
11041 ? " (warning-only)"
11042 : "");
11043 vty_out(vty, " Threshold for warning message %d%%",
11044 p->pmax_threshold[afi][safi]);
11045 if (p->pmax_restart[afi][safi])
11046 vty_out(vty, ", restart interval %d min",
11047 p->pmax_restart[afi][safi]);
11048 vty_out(vty, "\n");
11049 }
11050
11051 vty_out(vty, "\n");
11052 }
11053}
11054
9f049418 11055static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 11056 json_object *json)
718e3744 11057{
d62a17ae 11058 struct bgp *bgp;
11059 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
11060 char timebuf[BGP_UPTIME_LEN];
11061 char dn_flag[2];
d62a17ae 11062 afi_t afi;
11063 safi_t safi;
d7c0a89a
QY
11064 uint16_t i;
11065 uint8_t *msg;
d62a17ae 11066 json_object *json_neigh = NULL;
11067 time_t epoch_tbuf;
718e3744 11068
d62a17ae 11069 bgp = p->bgp;
11070
11071 if (use_json)
11072 json_neigh = json_object_new_object();
11073
11074 memset(dn_flag, '\0', sizeof(dn_flag));
11075 if (!p->conf_if && peer_dynamic_neighbor(p))
11076 dn_flag[0] = '*';
11077
11078 if (!use_json) {
11079 if (p->conf_if) /* Configured interface name. */
11080 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
11081 BGP_PEER_SU_UNSPEC(p)
11082 ? "None"
11083 : sockunion2str(&p->su, buf,
11084 SU_ADDRSTRLEN));
11085 else /* Configured IP address. */
11086 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
11087 p->host);
11088 }
11089
11090 if (use_json) {
11091 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
11092 json_object_string_add(json_neigh, "bgpNeighborAddr",
11093 "none");
11094 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
11095 json_object_string_add(
11096 json_neigh, "bgpNeighborAddr",
11097 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
11098
11099 json_object_int_add(json_neigh, "remoteAs", p->as);
11100
11101 if (p->change_local_as)
11102 json_object_int_add(json_neigh, "localAs",
11103 p->change_local_as);
11104 else
11105 json_object_int_add(json_neigh, "localAs", p->local_as);
11106
11107 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
11108 json_object_boolean_true_add(json_neigh,
11109 "localAsNoPrepend");
11110
11111 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
11112 json_object_boolean_true_add(json_neigh,
11113 "localAsReplaceAs");
11114 } else {
11115 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
11116 || (p->as_type == AS_INTERNAL))
11117 vty_out(vty, "remote AS %u, ", p->as);
11118 else
11119 vty_out(vty, "remote AS Unspecified, ");
11120 vty_out(vty, "local AS %u%s%s, ",
11121 p->change_local_as ? p->change_local_as : p->local_as,
11122 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
11123 ? " no-prepend"
11124 : "",
11125 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
11126 ? " replace-as"
11127 : "");
11128 }
faa16034
DS
11129 /* peer type internal or confed-internal */
11130 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 11131 if (use_json) {
11132 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11133 json_object_boolean_true_add(
11134 json_neigh, "nbrConfedInternalLink");
11135 else
11136 json_object_boolean_true_add(json_neigh,
11137 "nbrInternalLink");
11138 } else {
11139 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11140 vty_out(vty, "confed-internal link\n");
11141 else
11142 vty_out(vty, "internal link\n");
11143 }
faa16034
DS
11144 /* peer type external or confed-external */
11145 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 11146 if (use_json) {
11147 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11148 json_object_boolean_true_add(
11149 json_neigh, "nbrConfedExternalLink");
11150 else
11151 json_object_boolean_true_add(json_neigh,
11152 "nbrExternalLink");
11153 } else {
11154 if (bgp_confederation_peers_check(bgp, p->as))
11155 vty_out(vty, "confed-external link\n");
11156 else
11157 vty_out(vty, "external link\n");
11158 }
faa16034
DS
11159 } else {
11160 if (use_json)
11161 json_object_boolean_true_add(json_neigh,
11162 "nbrUnspecifiedLink");
11163 else
11164 vty_out(vty, "unspecified link\n");
d62a17ae 11165 }
11166
11167 /* Description. */
11168 if (p->desc) {
11169 if (use_json)
11170 json_object_string_add(json_neigh, "nbrDesc", p->desc);
11171 else
11172 vty_out(vty, " Description: %s\n", p->desc);
11173 }
11174
11175 if (p->hostname) {
11176 if (use_json) {
11177 if (p->hostname)
11178 json_object_string_add(json_neigh, "hostname",
11179 p->hostname);
11180
11181 if (p->domainname)
11182 json_object_string_add(json_neigh, "domainname",
11183 p->domainname);
11184 } else {
11185 if (p->domainname && (p->domainname[0] != '\0'))
11186 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
11187 p->domainname);
11188 else
11189 vty_out(vty, "Hostname: %s\n", p->hostname);
11190 }
11191 }
11192
11193 /* Peer-group */
11194 if (p->group) {
11195 if (use_json) {
11196 json_object_string_add(json_neigh, "peerGroup",
11197 p->group->name);
11198
11199 if (dn_flag[0]) {
11200 struct prefix prefix, *range = NULL;
11201
11202 sockunion2hostprefix(&(p->su), &prefix);
11203 range = peer_group_lookup_dynamic_neighbor_range(
11204 p->group, &prefix);
11205
11206 if (range) {
11207 prefix2str(range, buf1, sizeof(buf1));
11208 json_object_string_add(
11209 json_neigh,
11210 "peerSubnetRangeGroup", buf1);
11211 }
11212 }
11213 } else {
11214 vty_out(vty,
11215 " Member of peer-group %s for session parameters\n",
11216 p->group->name);
11217
11218 if (dn_flag[0]) {
11219 struct prefix prefix, *range = NULL;
11220
11221 sockunion2hostprefix(&(p->su), &prefix);
11222 range = peer_group_lookup_dynamic_neighbor_range(
11223 p->group, &prefix);
11224
11225 if (range) {
d62a17ae 11226 vty_out(vty,
1b78780b
DL
11227 " Belongs to the subnet range group: %pFX\n",
11228 range);
d62a17ae 11229 }
11230 }
11231 }
11232 }
11233
11234 if (use_json) {
11235 /* Administrative shutdown. */
cb9196e7
DS
11236 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11237 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 11238 json_object_boolean_true_add(json_neigh,
11239 "adminShutDown");
11240
11241 /* BGP Version. */
11242 json_object_int_add(json_neigh, "bgpVersion", 4);
11243 json_object_string_add(
11244 json_neigh, "remoteRouterId",
11245 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
11246 json_object_string_add(
11247 json_neigh, "localRouterId",
11248 inet_ntop(AF_INET, &bgp->router_id, buf1,
11249 sizeof(buf1)));
d62a17ae 11250
11251 /* Confederation */
11252 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11253 && bgp_confederation_peers_check(bgp, p->as))
11254 json_object_boolean_true_add(json_neigh,
11255 "nbrCommonAdmin");
11256
11257 /* Status. */
11258 json_object_string_add(
11259 json_neigh, "bgpState",
11260 lookup_msg(bgp_status_msg, p->status, NULL));
11261
11262 if (p->status == Established) {
11263 time_t uptime;
d62a17ae 11264
11265 uptime = bgp_clock();
11266 uptime -= p->uptime;
d62a17ae 11267 epoch_tbuf = time(NULL) - uptime;
11268
d3c7efed
DS
11269 json_object_int_add(json_neigh, "bgpTimerUpMsec",
11270 uptime * 1000);
d62a17ae 11271 json_object_string_add(json_neigh, "bgpTimerUpString",
11272 peer_uptime(p->uptime, timebuf,
11273 BGP_UPTIME_LEN, 0,
11274 NULL));
11275 json_object_int_add(json_neigh,
11276 "bgpTimerUpEstablishedEpoch",
11277 epoch_tbuf);
11278 }
11279
11280 else if (p->status == Active) {
11281 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11282 json_object_string_add(json_neigh, "bgpStateIs",
11283 "passive");
11284 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11285 json_object_string_add(json_neigh, "bgpStateIs",
11286 "passiveNSF");
11287 }
11288
11289 /* read timer */
11290 time_t uptime;
a2700b50 11291 struct tm tm;
d62a17ae 11292
11293 uptime = bgp_clock();
11294 uptime -= p->readtime;
a2700b50
MS
11295 gmtime_r(&uptime, &tm);
11296
d62a17ae 11297 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
11298 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11299 + (tm.tm_hour * 3600000));
d62a17ae 11300
11301 uptime = bgp_clock();
11302 uptime -= p->last_write;
a2700b50
MS
11303 gmtime_r(&uptime, &tm);
11304
d62a17ae 11305 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
11306 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11307 + (tm.tm_hour * 3600000));
d62a17ae 11308
11309 uptime = bgp_clock();
11310 uptime -= p->update_time;
a2700b50
MS
11311 gmtime_r(&uptime, &tm);
11312
d62a17ae 11313 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
11314 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11315 + (tm.tm_hour * 3600000));
d62a17ae 11316
11317 /* Configured timer values. */
11318 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
11319 p->v_holdtime * 1000);
11320 json_object_int_add(json_neigh,
11321 "bgpTimerKeepAliveIntervalMsecs",
11322 p->v_keepalive * 1000);
b90a8e13 11323 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11324 json_object_int_add(json_neigh,
11325 "bgpTimerConfiguredHoldTimeMsecs",
11326 p->holdtime * 1000);
11327 json_object_int_add(
11328 json_neigh,
11329 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11330 p->keepalive * 1000);
5d5393b9
DL
11331 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11332 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11333 json_object_int_add(json_neigh,
11334 "bgpTimerConfiguredHoldTimeMsecs",
11335 bgp->default_holdtime);
11336 json_object_int_add(
11337 json_neigh,
11338 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11339 bgp->default_keepalive);
d62a17ae 11340 }
11341 } else {
11342 /* Administrative shutdown. */
cb9196e7
DS
11343 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11344 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 11345 vty_out(vty, " Administratively shut down\n");
11346
11347 /* BGP Version. */
11348 vty_out(vty, " BGP version 4");
0e38aeb4 11349 vty_out(vty, ", remote router ID %s",
d62a17ae 11350 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
11351 vty_out(vty, ", local router ID %s\n",
11352 inet_ntop(AF_INET, &bgp->router_id, buf1,
11353 sizeof(buf1)));
d62a17ae 11354
11355 /* Confederation */
11356 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11357 && bgp_confederation_peers_check(bgp, p->as))
11358 vty_out(vty,
11359 " Neighbor under common administration\n");
11360
11361 /* Status. */
11362 vty_out(vty, " BGP state = %s",
11363 lookup_msg(bgp_status_msg, p->status, NULL));
11364
11365 if (p->status == Established)
11366 vty_out(vty, ", up for %8s",
11367 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
11368 0, NULL));
11369
11370 else if (p->status == Active) {
11371 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11372 vty_out(vty, " (passive)");
11373 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11374 vty_out(vty, " (NSF passive)");
11375 }
11376 vty_out(vty, "\n");
11377
11378 /* read timer */
11379 vty_out(vty, " Last read %s",
11380 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
11381 NULL));
11382 vty_out(vty, ", Last write %s\n",
11383 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
11384 NULL));
11385
11386 /* Configured timer values. */
11387 vty_out(vty,
11388 " Hold time is %d, keepalive interval is %d seconds\n",
11389 p->v_holdtime, p->v_keepalive);
b90a8e13 11390 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11391 vty_out(vty, " Configured hold time is %d",
11392 p->holdtime);
11393 vty_out(vty, ", keepalive interval is %d seconds\n",
11394 p->keepalive);
5d5393b9
DL
11395 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11396 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11397 vty_out(vty, " Configured hold time is %d",
11398 bgp->default_holdtime);
11399 vty_out(vty, ", keepalive interval is %d seconds\n",
11400 bgp->default_keepalive);
d62a17ae 11401 }
11402 }
11403 /* Capability. */
11404 if (p->status == Established) {
11405 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
11406 || p->afc_recv[AFI_IP][SAFI_UNICAST]
11407 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
11408 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
11409 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
11410 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
11411 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
11412 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
11413 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
11414 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
11415 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
11416 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 11417 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
11418 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 11419 || p->afc_adv[AFI_IP][SAFI_ENCAP]
11420 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 11421 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
11422 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 11423 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
11424 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
11425 if (use_json) {
11426 json_object *json_cap = NULL;
11427
11428 json_cap = json_object_new_object();
11429
11430 /* AS4 */
11431 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11432 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11433 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
11434 && CHECK_FLAG(p->cap,
11435 PEER_CAP_AS4_RCV))
11436 json_object_string_add(
11437 json_cap, "4byteAs",
11438 "advertisedAndReceived");
11439 else if (CHECK_FLAG(p->cap,
11440 PEER_CAP_AS4_ADV))
11441 json_object_string_add(
11442 json_cap, "4byteAs",
11443 "advertised");
11444 else if (CHECK_FLAG(p->cap,
11445 PEER_CAP_AS4_RCV))
11446 json_object_string_add(
11447 json_cap, "4byteAs",
11448 "received");
11449 }
11450
11451 /* AddPath */
11452 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11453 || CHECK_FLAG(p->cap,
11454 PEER_CAP_ADDPATH_ADV)) {
11455 json_object *json_add = NULL;
11456 const char *print_store;
11457
11458 json_add = json_object_new_object();
11459
05c7a1cc
QY
11460 FOREACH_AFI_SAFI (afi, safi) {
11461 json_object *json_sub = NULL;
11462 json_sub =
11463 json_object_new_object();
5cb5f4d0
DD
11464 print_store = get_afi_safi_str(
11465 afi, safi, true);
d62a17ae 11466
05c7a1cc
QY
11467 if (CHECK_FLAG(
11468 p->af_cap[afi]
11469 [safi],
11470 PEER_CAP_ADDPATH_AF_TX_ADV)
11471 || CHECK_FLAG(
11472 p->af_cap[afi]
11473 [safi],
11474 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 11475 if (CHECK_FLAG(
11476 p->af_cap
11477 [afi]
11478 [safi],
11479 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 11480 && CHECK_FLAG(
d62a17ae 11481 p->af_cap
11482 [afi]
11483 [safi],
05c7a1cc
QY
11484 PEER_CAP_ADDPATH_AF_TX_RCV))
11485 json_object_boolean_true_add(
11486 json_sub,
11487 "txAdvertisedAndReceived");
11488 else if (
11489 CHECK_FLAG(
11490 p->af_cap
11491 [afi]
11492 [safi],
11493 PEER_CAP_ADDPATH_AF_TX_ADV))
11494 json_object_boolean_true_add(
11495 json_sub,
11496 "txAdvertised");
11497 else if (
11498 CHECK_FLAG(
11499 p->af_cap
11500 [afi]
11501 [safi],
11502 PEER_CAP_ADDPATH_AF_TX_RCV))
11503 json_object_boolean_true_add(
11504 json_sub,
11505 "txReceived");
11506 }
d62a17ae 11507
05c7a1cc
QY
11508 if (CHECK_FLAG(
11509 p->af_cap[afi]
11510 [safi],
11511 PEER_CAP_ADDPATH_AF_RX_ADV)
11512 || CHECK_FLAG(
11513 p->af_cap[afi]
11514 [safi],
11515 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 11516 if (CHECK_FLAG(
11517 p->af_cap
11518 [afi]
11519 [safi],
11520 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 11521 && CHECK_FLAG(
d62a17ae 11522 p->af_cap
11523 [afi]
11524 [safi],
11525 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
11526 json_object_boolean_true_add(
11527 json_sub,
11528 "rxAdvertisedAndReceived");
11529 else if (
11530 CHECK_FLAG(
11531 p->af_cap
11532 [afi]
11533 [safi],
11534 PEER_CAP_ADDPATH_AF_RX_ADV))
11535 json_object_boolean_true_add(
11536 json_sub,
11537 "rxAdvertised");
11538 else if (
11539 CHECK_FLAG(
11540 p->af_cap
11541 [afi]
11542 [safi],
11543 PEER_CAP_ADDPATH_AF_RX_RCV))
11544 json_object_boolean_true_add(
11545 json_sub,
11546 "rxReceived");
d62a17ae 11547 }
11548
05c7a1cc
QY
11549 if (CHECK_FLAG(
11550 p->af_cap[afi]
11551 [safi],
11552 PEER_CAP_ADDPATH_AF_TX_ADV)
11553 || CHECK_FLAG(
11554 p->af_cap[afi]
11555 [safi],
11556 PEER_CAP_ADDPATH_AF_TX_RCV)
11557 || CHECK_FLAG(
11558 p->af_cap[afi]
11559 [safi],
11560 PEER_CAP_ADDPATH_AF_RX_ADV)
11561 || CHECK_FLAG(
11562 p->af_cap[afi]
11563 [safi],
11564 PEER_CAP_ADDPATH_AF_RX_RCV))
11565 json_object_object_add(
11566 json_add,
11567 print_store,
11568 json_sub);
11569 else
11570 json_object_free(
11571 json_sub);
11572 }
11573
d62a17ae 11574 json_object_object_add(
11575 json_cap, "addPath", json_add);
11576 }
11577
11578 /* Dynamic */
11579 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11580 || CHECK_FLAG(p->cap,
11581 PEER_CAP_DYNAMIC_ADV)) {
11582 if (CHECK_FLAG(p->cap,
11583 PEER_CAP_DYNAMIC_ADV)
11584 && CHECK_FLAG(p->cap,
11585 PEER_CAP_DYNAMIC_RCV))
11586 json_object_string_add(
11587 json_cap, "dynamic",
11588 "advertisedAndReceived");
11589 else if (CHECK_FLAG(
11590 p->cap,
11591 PEER_CAP_DYNAMIC_ADV))
11592 json_object_string_add(
11593 json_cap, "dynamic",
11594 "advertised");
11595 else if (CHECK_FLAG(
11596 p->cap,
11597 PEER_CAP_DYNAMIC_RCV))
11598 json_object_string_add(
11599 json_cap, "dynamic",
11600 "received");
11601 }
11602
11603 /* Extended nexthop */
11604 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11605 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11606 json_object *json_nxt = NULL;
11607 const char *print_store;
11608
11609
11610 if (CHECK_FLAG(p->cap,
11611 PEER_CAP_ENHE_ADV)
11612 && CHECK_FLAG(p->cap,
11613 PEER_CAP_ENHE_RCV))
11614 json_object_string_add(
11615 json_cap,
11616 "extendedNexthop",
11617 "advertisedAndReceived");
11618 else if (CHECK_FLAG(p->cap,
11619 PEER_CAP_ENHE_ADV))
11620 json_object_string_add(
11621 json_cap,
11622 "extendedNexthop",
11623 "advertised");
11624 else if (CHECK_FLAG(p->cap,
11625 PEER_CAP_ENHE_RCV))
11626 json_object_string_add(
11627 json_cap,
11628 "extendedNexthop",
11629 "received");
11630
11631 if (CHECK_FLAG(p->cap,
11632 PEER_CAP_ENHE_RCV)) {
11633 json_nxt =
11634 json_object_new_object();
11635
11636 for (safi = SAFI_UNICAST;
11637 safi < SAFI_MAX; safi++) {
11638 if (CHECK_FLAG(
11639 p->af_cap
11640 [AFI_IP]
11641 [safi],
11642 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 11643 print_store = get_afi_safi_str(
d62a17ae 11644 AFI_IP,
5cb5f4d0 11645 safi, true);
d62a17ae 11646 json_object_string_add(
11647 json_nxt,
11648 print_store,
54f29523 11649 "recieved"); /* misspelled for compatibility */
d62a17ae 11650 }
11651 }
11652 json_object_object_add(
11653 json_cap,
11654 "extendedNexthopFamililesByPeer",
11655 json_nxt);
11656 }
11657 }
11658
11659 /* Route Refresh */
11660 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11661 || CHECK_FLAG(p->cap,
11662 PEER_CAP_REFRESH_NEW_RCV)
11663 || CHECK_FLAG(p->cap,
11664 PEER_CAP_REFRESH_OLD_RCV)) {
11665 if (CHECK_FLAG(p->cap,
11666 PEER_CAP_REFRESH_ADV)
11667 && (CHECK_FLAG(
11668 p->cap,
11669 PEER_CAP_REFRESH_NEW_RCV)
11670 || CHECK_FLAG(
11671 p->cap,
11672 PEER_CAP_REFRESH_OLD_RCV))) {
11673 if (CHECK_FLAG(
11674 p->cap,
11675 PEER_CAP_REFRESH_OLD_RCV)
11676 && CHECK_FLAG(
11677 p->cap,
11678 PEER_CAP_REFRESH_NEW_RCV))
11679 json_object_string_add(
11680 json_cap,
11681 "routeRefresh",
11682 "advertisedAndReceivedOldNew");
11683 else {
11684 if (CHECK_FLAG(
11685 p->cap,
11686 PEER_CAP_REFRESH_OLD_RCV))
11687 json_object_string_add(
11688 json_cap,
11689 "routeRefresh",
11690 "advertisedAndReceivedOld");
11691 else
11692 json_object_string_add(
11693 json_cap,
11694 "routeRefresh",
11695 "advertisedAndReceivedNew");
11696 }
11697 } else if (
11698 CHECK_FLAG(
11699 p->cap,
11700 PEER_CAP_REFRESH_ADV))
11701 json_object_string_add(
11702 json_cap,
11703 "routeRefresh",
11704 "advertised");
11705 else if (
11706 CHECK_FLAG(
11707 p->cap,
11708 PEER_CAP_REFRESH_NEW_RCV)
11709 || CHECK_FLAG(
11710 p->cap,
11711 PEER_CAP_REFRESH_OLD_RCV))
11712 json_object_string_add(
11713 json_cap,
11714 "routeRefresh",
11715 "received");
11716 }
11717
11718 /* Multiprotocol Extensions */
11719 json_object *json_multi = NULL;
11720 json_multi = json_object_new_object();
11721
05c7a1cc
QY
11722 FOREACH_AFI_SAFI (afi, safi) {
11723 if (p->afc_adv[afi][safi]
11724 || p->afc_recv[afi][safi]) {
11725 json_object *json_exten = NULL;
11726 json_exten =
11727 json_object_new_object();
11728
d62a17ae 11729 if (p->afc_adv[afi][safi]
05c7a1cc
QY
11730 && p->afc_recv[afi][safi])
11731 json_object_boolean_true_add(
11732 json_exten,
11733 "advertisedAndReceived");
11734 else if (p->afc_adv[afi][safi])
11735 json_object_boolean_true_add(
11736 json_exten,
11737 "advertised");
11738 else if (p->afc_recv[afi][safi])
11739 json_object_boolean_true_add(
11740 json_exten,
11741 "received");
d62a17ae 11742
05c7a1cc
QY
11743 json_object_object_add(
11744 json_multi,
5cb5f4d0
DD
11745 get_afi_safi_str(afi,
11746 safi,
11747 true),
05c7a1cc 11748 json_exten);
d62a17ae 11749 }
11750 }
11751 json_object_object_add(
11752 json_cap, "multiprotocolExtensions",
11753 json_multi);
11754
d77114b7 11755 /* Hostname capabilities */
60466a63 11756 json_object *json_hname = NULL;
d77114b7
MK
11757
11758 json_hname = json_object_new_object();
11759
11760 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11761 json_object_string_add(
60466a63
QY
11762 json_hname, "advHostName",
11763 bgp->peer_self->hostname
11764 ? bgp->peer_self
11765 ->hostname
d77114b7
MK
11766 : "n/a");
11767 json_object_string_add(
60466a63
QY
11768 json_hname, "advDomainName",
11769 bgp->peer_self->domainname
11770 ? bgp->peer_self
11771 ->domainname
d77114b7
MK
11772 : "n/a");
11773 }
11774
11775
11776 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11777 json_object_string_add(
60466a63
QY
11778 json_hname, "rcvHostName",
11779 p->hostname ? p->hostname
11780 : "n/a");
d77114b7 11781 json_object_string_add(
60466a63
QY
11782 json_hname, "rcvDomainName",
11783 p->domainname ? p->domainname
11784 : "n/a");
d77114b7
MK
11785 }
11786
60466a63 11787 json_object_object_add(json_cap, "hostName",
d77114b7
MK
11788 json_hname);
11789
d62a17ae 11790 /* Gracefull Restart */
11791 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11792 || CHECK_FLAG(p->cap,
11793 PEER_CAP_RESTART_ADV)) {
11794 if (CHECK_FLAG(p->cap,
11795 PEER_CAP_RESTART_ADV)
11796 && CHECK_FLAG(p->cap,
11797 PEER_CAP_RESTART_RCV))
11798 json_object_string_add(
11799 json_cap,
11800 "gracefulRestart",
11801 "advertisedAndReceived");
11802 else if (CHECK_FLAG(
11803 p->cap,
11804 PEER_CAP_RESTART_ADV))
11805 json_object_string_add(
11806 json_cap,
11807 "gracefulRestartCapability",
11808 "advertised");
11809 else if (CHECK_FLAG(
11810 p->cap,
11811 PEER_CAP_RESTART_RCV))
11812 json_object_string_add(
11813 json_cap,
11814 "gracefulRestartCapability",
11815 "received");
11816
11817 if (CHECK_FLAG(p->cap,
11818 PEER_CAP_RESTART_RCV)) {
11819 int restart_af_count = 0;
11820 json_object *json_restart =
11821 NULL;
11822 json_restart =
11823 json_object_new_object();
11824
11825 json_object_int_add(
11826 json_cap,
11827 "gracefulRestartRemoteTimerMsecs",
11828 p->v_gr_restart * 1000);
11829
05c7a1cc
QY
11830 FOREACH_AFI_SAFI (afi, safi) {
11831 if (CHECK_FLAG(
11832 p->af_cap
11833 [afi]
11834 [safi],
11835 PEER_CAP_RESTART_AF_RCV)) {
11836 json_object *
11837 json_sub =
11838 NULL;
11839 json_sub =
11840 json_object_new_object();
11841
d62a17ae 11842 if (CHECK_FLAG(
11843 p->af_cap
11844 [afi]
11845 [safi],
05c7a1cc
QY
11846 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11847 json_object_boolean_true_add(
11848 json_sub,
11849 "preserved");
11850 restart_af_count++;
11851 json_object_object_add(
11852 json_restart,
5cb5f4d0 11853 get_afi_safi_str(
05c7a1cc 11854 afi,
5cb5f4d0
DD
11855 safi,
11856 true),
05c7a1cc 11857 json_sub);
d62a17ae 11858 }
11859 }
11860 if (!restart_af_count) {
11861 json_object_string_add(
11862 json_cap,
11863 "addressFamiliesByPeer",
11864 "none");
11865 json_object_free(
11866 json_restart);
11867 } else
11868 json_object_object_add(
11869 json_cap,
11870 "addressFamiliesByPeer",
11871 json_restart);
11872 }
11873 }
11874 json_object_object_add(json_neigh,
11875 "neighborCapabilities",
11876 json_cap);
11877 } else {
11878 vty_out(vty, " Neighbor capabilities:\n");
11879
11880 /* AS4 */
11881 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11882 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11883 vty_out(vty, " 4 Byte AS:");
11884 if (CHECK_FLAG(p->cap,
11885 PEER_CAP_AS4_ADV))
11886 vty_out(vty, " advertised");
11887 if (CHECK_FLAG(p->cap,
11888 PEER_CAP_AS4_RCV))
11889 vty_out(vty, " %sreceived",
11890 CHECK_FLAG(
11891 p->cap,
11892 PEER_CAP_AS4_ADV)
11893 ? "and "
11894 : "");
11895 vty_out(vty, "\n");
11896 }
11897
11898 /* AddPath */
11899 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11900 || CHECK_FLAG(p->cap,
11901 PEER_CAP_ADDPATH_ADV)) {
11902 vty_out(vty, " AddPath:\n");
11903
05c7a1cc
QY
11904 FOREACH_AFI_SAFI (afi, safi) {
11905 if (CHECK_FLAG(
11906 p->af_cap[afi]
11907 [safi],
11908 PEER_CAP_ADDPATH_AF_TX_ADV)
11909 || CHECK_FLAG(
11910 p->af_cap[afi]
11911 [safi],
11912 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11913 vty_out(vty,
11914 " %s: TX ",
5cb5f4d0 11915 get_afi_safi_str(
05c7a1cc 11916 afi,
5cb5f4d0
DD
11917 safi,
11918 false));
05c7a1cc 11919
d62a17ae 11920 if (CHECK_FLAG(
11921 p->af_cap
11922 [afi]
11923 [safi],
05c7a1cc 11924 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 11925 vty_out(vty,
05c7a1cc 11926 "advertised %s",
5cb5f4d0 11927 get_afi_safi_str(
d62a17ae 11928 afi,
5cb5f4d0
DD
11929 safi,
11930 false));
d62a17ae 11931
05c7a1cc
QY
11932 if (CHECK_FLAG(
11933 p->af_cap
11934 [afi]
11935 [safi],
11936 PEER_CAP_ADDPATH_AF_TX_RCV))
11937 vty_out(vty,
11938 "%sreceived",
11939 CHECK_FLAG(
11940 p->af_cap
11941 [afi]
11942 [safi],
11943 PEER_CAP_ADDPATH_AF_TX_ADV)
11944 ? " and "
11945 : "");
d62a17ae 11946
05c7a1cc
QY
11947 vty_out(vty, "\n");
11948 }
d62a17ae 11949
05c7a1cc
QY
11950 if (CHECK_FLAG(
11951 p->af_cap[afi]
11952 [safi],
11953 PEER_CAP_ADDPATH_AF_RX_ADV)
11954 || CHECK_FLAG(
11955 p->af_cap[afi]
11956 [safi],
11957 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11958 vty_out(vty,
11959 " %s: RX ",
5cb5f4d0 11960 get_afi_safi_str(
05c7a1cc 11961 afi,
5cb5f4d0
DD
11962 safi,
11963 false));
d62a17ae 11964
11965 if (CHECK_FLAG(
11966 p->af_cap
11967 [afi]
11968 [safi],
05c7a1cc 11969 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 11970 vty_out(vty,
05c7a1cc 11971 "advertised %s",
5cb5f4d0 11972 get_afi_safi_str(
d62a17ae 11973 afi,
5cb5f4d0
DD
11974 safi,
11975 false));
d62a17ae 11976
05c7a1cc
QY
11977 if (CHECK_FLAG(
11978 p->af_cap
11979 [afi]
11980 [safi],
11981 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 11982 vty_out(vty,
05c7a1cc
QY
11983 "%sreceived",
11984 CHECK_FLAG(
11985 p->af_cap
11986 [afi]
11987 [safi],
11988 PEER_CAP_ADDPATH_AF_RX_ADV)
11989 ? " and "
11990 : "");
11991
11992 vty_out(vty, "\n");
d62a17ae 11993 }
05c7a1cc 11994 }
d62a17ae 11995 }
11996
11997 /* Dynamic */
11998 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11999 || CHECK_FLAG(p->cap,
12000 PEER_CAP_DYNAMIC_ADV)) {
12001 vty_out(vty, " Dynamic:");
12002 if (CHECK_FLAG(p->cap,
12003 PEER_CAP_DYNAMIC_ADV))
12004 vty_out(vty, " advertised");
12005 if (CHECK_FLAG(p->cap,
12006 PEER_CAP_DYNAMIC_RCV))
12007 vty_out(vty, " %sreceived",
12008 CHECK_FLAG(
12009 p->cap,
12010 PEER_CAP_DYNAMIC_ADV)
12011 ? "and "
12012 : "");
12013 vty_out(vty, "\n");
12014 }
12015
12016 /* Extended nexthop */
12017 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12018 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12019 vty_out(vty, " Extended nexthop:");
12020 if (CHECK_FLAG(p->cap,
12021 PEER_CAP_ENHE_ADV))
12022 vty_out(vty, " advertised");
12023 if (CHECK_FLAG(p->cap,
12024 PEER_CAP_ENHE_RCV))
12025 vty_out(vty, " %sreceived",
12026 CHECK_FLAG(
12027 p->cap,
12028 PEER_CAP_ENHE_ADV)
12029 ? "and "
12030 : "");
12031 vty_out(vty, "\n");
12032
12033 if (CHECK_FLAG(p->cap,
12034 PEER_CAP_ENHE_RCV)) {
12035 vty_out(vty,
12036 " Address families by peer:\n ");
12037 for (safi = SAFI_UNICAST;
12038 safi < SAFI_MAX; safi++)
12039 if (CHECK_FLAG(
12040 p->af_cap
12041 [AFI_IP]
12042 [safi],
12043 PEER_CAP_ENHE_AF_RCV))
12044 vty_out(vty,
12045 " %s\n",
5cb5f4d0 12046 get_afi_safi_str(
d62a17ae 12047 AFI_IP,
5cb5f4d0
DD
12048 safi,
12049 false));
d62a17ae 12050 }
12051 }
12052
12053 /* Route Refresh */
12054 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12055 || CHECK_FLAG(p->cap,
12056 PEER_CAP_REFRESH_NEW_RCV)
12057 || CHECK_FLAG(p->cap,
12058 PEER_CAP_REFRESH_OLD_RCV)) {
12059 vty_out(vty, " Route refresh:");
12060 if (CHECK_FLAG(p->cap,
12061 PEER_CAP_REFRESH_ADV))
12062 vty_out(vty, " advertised");
12063 if (CHECK_FLAG(p->cap,
12064 PEER_CAP_REFRESH_NEW_RCV)
12065 || CHECK_FLAG(
12066 p->cap,
12067 PEER_CAP_REFRESH_OLD_RCV))
12068 vty_out(vty, " %sreceived(%s)",
12069 CHECK_FLAG(
12070 p->cap,
12071 PEER_CAP_REFRESH_ADV)
12072 ? "and "
12073 : "",
12074 (CHECK_FLAG(
12075 p->cap,
12076 PEER_CAP_REFRESH_OLD_RCV)
12077 && CHECK_FLAG(
12078 p->cap,
12079 PEER_CAP_REFRESH_NEW_RCV))
12080 ? "old & new"
12081 : CHECK_FLAG(
12082 p->cap,
12083 PEER_CAP_REFRESH_OLD_RCV)
12084 ? "old"
12085 : "new");
12086
12087 vty_out(vty, "\n");
12088 }
12089
12090 /* Multiprotocol Extensions */
05c7a1cc
QY
12091 FOREACH_AFI_SAFI (afi, safi)
12092 if (p->afc_adv[afi][safi]
12093 || p->afc_recv[afi][safi]) {
12094 vty_out(vty,
12095 " Address Family %s:",
5cb5f4d0
DD
12096 get_afi_safi_str(
12097 afi,
12098 safi,
12099 false));
05c7a1cc 12100 if (p->afc_adv[afi][safi])
d62a17ae 12101 vty_out(vty,
05c7a1cc
QY
12102 " advertised");
12103 if (p->afc_recv[afi][safi])
12104 vty_out(vty,
12105 " %sreceived",
12106 p->afc_adv[afi]
12107 [safi]
12108 ? "and "
12109 : "");
12110 vty_out(vty, "\n");
12111 }
d62a17ae 12112
12113 /* Hostname capability */
60466a63 12114 vty_out(vty, " Hostname Capability:");
d77114b7
MK
12115
12116 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
12117 vty_out(vty,
12118 " advertised (name: %s,domain name: %s)",
60466a63
QY
12119 bgp->peer_self->hostname
12120 ? bgp->peer_self
12121 ->hostname
d77114b7 12122 : "n/a",
60466a63
QY
12123 bgp->peer_self->domainname
12124 ? bgp->peer_self
12125 ->domainname
d77114b7
MK
12126 : "n/a");
12127 } else {
12128 vty_out(vty, " not advertised");
d62a17ae 12129 }
12130
d77114b7 12131 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
12132 vty_out(vty,
12133 " received (name: %s,domain name: %s)",
60466a63
QY
12134 p->hostname ? p->hostname
12135 : "n/a",
12136 p->domainname ? p->domainname
12137 : "n/a");
d77114b7
MK
12138 } else {
12139 vty_out(vty, " not received");
12140 }
12141
12142 vty_out(vty, "\n");
12143
61bfbd51 12144 /* Graceful Restart */
d62a17ae 12145 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12146 || CHECK_FLAG(p->cap,
12147 PEER_CAP_RESTART_ADV)) {
12148 vty_out(vty,
61bfbd51 12149 " Graceful Restart Capability:");
d62a17ae 12150 if (CHECK_FLAG(p->cap,
12151 PEER_CAP_RESTART_ADV))
12152 vty_out(vty, " advertised");
12153 if (CHECK_FLAG(p->cap,
12154 PEER_CAP_RESTART_RCV))
12155 vty_out(vty, " %sreceived",
12156 CHECK_FLAG(
12157 p->cap,
12158 PEER_CAP_RESTART_ADV)
12159 ? "and "
12160 : "");
12161 vty_out(vty, "\n");
12162
12163 if (CHECK_FLAG(p->cap,
12164 PEER_CAP_RESTART_RCV)) {
12165 int restart_af_count = 0;
12166
12167 vty_out(vty,
12168 " Remote Restart timer is %d seconds\n",
12169 p->v_gr_restart);
12170 vty_out(vty,
12171 " Address families by peer:\n ");
12172
05c7a1cc
QY
12173 FOREACH_AFI_SAFI (afi, safi)
12174 if (CHECK_FLAG(
12175 p->af_cap
12176 [afi]
12177 [safi],
12178 PEER_CAP_RESTART_AF_RCV)) {
12179 vty_out(vty,
12180 "%s%s(%s)",
12181 restart_af_count
12182 ? ", "
12183 : "",
5cb5f4d0 12184 get_afi_safi_str(
05c7a1cc 12185 afi,
5cb5f4d0
DD
12186 safi,
12187 false),
05c7a1cc
QY
12188 CHECK_FLAG(
12189 p->af_cap
12190 [afi]
12191 [safi],
12192 PEER_CAP_RESTART_AF_PRESERVE_RCV)
12193 ? "preserved"
12194 : "not preserved");
12195 restart_af_count++;
12196 }
d62a17ae 12197 if (!restart_af_count)
12198 vty_out(vty, "none");
12199 vty_out(vty, "\n");
12200 }
2986cac2 12201 } /* Gracefull Restart */
d62a17ae 12202 }
12203 }
12204 }
12205
12206 /* graceful restart information */
d62a17ae 12207 json_object *json_grace = NULL;
12208 json_object *json_grace_send = NULL;
12209 json_object *json_grace_recv = NULL;
12210 int eor_send_af_count = 0;
12211 int eor_receive_af_count = 0;
12212
12213 if (use_json) {
12214 json_grace = json_object_new_object();
12215 json_grace_send = json_object_new_object();
12216 json_grace_recv = json_object_new_object();
12217
36235319
QY
12218 if ((p->status == Established)
12219 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
12220 FOREACH_AFI_SAFI (afi, safi) {
12221 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 12222 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
12223 json_object_boolean_true_add(
12224 json_grace_send,
5cb5f4d0
DD
12225 get_afi_safi_str(afi,
12226 safi,
12227 true));
05c7a1cc 12228 eor_send_af_count++;
d62a17ae 12229 }
12230 }
05c7a1cc
QY
12231 FOREACH_AFI_SAFI (afi, safi) {
12232 if (CHECK_FLAG(
36235319
QY
12233 p->af_sflags[afi][safi],
12234 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
12235 json_object_boolean_true_add(
12236 json_grace_recv,
5cb5f4d0
DD
12237 get_afi_safi_str(afi,
12238 safi,
12239 true));
05c7a1cc 12240 eor_receive_af_count++;
d62a17ae 12241 }
12242 }
12243 }
36235319
QY
12244 json_object_object_add(json_grace, "endOfRibSend",
12245 json_grace_send);
12246 json_object_object_add(json_grace, "endOfRibRecv",
12247 json_grace_recv);
d62a17ae 12248
d62a17ae 12249
12250 if (p->t_gr_restart)
12251 json_object_int_add(json_grace,
12252 "gracefulRestartTimerMsecs",
12253 thread_timer_remain_second(
12254 p->t_gr_restart)
12255 * 1000);
12256
12257 if (p->t_gr_stale)
12258 json_object_int_add(
12259 json_grace,
12260 "gracefulStalepathTimerMsecs",
12261 thread_timer_remain_second(
12262 p->t_gr_stale)
12263 * 1000);
2986cac2 12264 /* more gr info in new format */
12265 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 12266 json_grace);
d62a17ae 12267 json_object_object_add(
12268 json_neigh, "gracefulRestartInfo", json_grace);
12269 } else {
2089dd80 12270 vty_out(vty, " Graceful restart information:\n");
36235319
QY
12271 if ((p->status == Established)
12272 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12273
d62a17ae 12274 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
12275 FOREACH_AFI_SAFI (afi, safi) {
12276 if (CHECK_FLAG(p->af_sflags[afi][safi],
12277 PEER_STATUS_EOR_SEND)) {
12278 vty_out(vty, "%s%s",
12279 eor_send_af_count ? ", "
12280 : "",
36235319
QY
12281 get_afi_safi_str(
12282 afi, safi,
12283 false));
05c7a1cc 12284 eor_send_af_count++;
d62a17ae 12285 }
12286 }
12287 vty_out(vty, "\n");
12288 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
12289 FOREACH_AFI_SAFI (afi, safi) {
12290 if (CHECK_FLAG(
12291 p->af_sflags[afi][safi],
12292 PEER_STATUS_EOR_RECEIVED)) {
12293 vty_out(vty, "%s%s",
12294 eor_receive_af_count
12295 ? ", "
12296 : "",
5cb5f4d0
DD
12297 get_afi_safi_str(afi,
12298 safi,
12299 false));
05c7a1cc 12300 eor_receive_af_count++;
d62a17ae 12301 }
12302 }
12303 vty_out(vty, "\n");
12304 }
12305
12306 if (p->t_gr_restart)
12307 vty_out(vty,
12308 " The remaining time of restart timer is %ld\n",
12309 thread_timer_remain_second(
12310 p->t_gr_restart));
12311
12312 if (p->t_gr_stale)
12313 vty_out(vty,
12314 " The remaining time of stalepath timer is %ld\n",
12315 thread_timer_remain_second(
12316 p->t_gr_stale));
2986cac2 12317
12318 /* more gr info in new format */
12319 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 12320 }
2986cac2 12321
d62a17ae 12322 if (use_json) {
12323 json_object *json_stat = NULL;
12324 json_stat = json_object_new_object();
12325 /* Packet counts. */
43aa5965
QY
12326
12327 atomic_size_t outq_count, inq_count;
12328 outq_count = atomic_load_explicit(&p->obuf->count,
12329 memory_order_relaxed);
12330 inq_count = atomic_load_explicit(&p->ibuf->count,
12331 memory_order_relaxed);
12332
12333 json_object_int_add(json_stat, "depthInq",
12334 (unsigned long)inq_count);
d62a17ae 12335 json_object_int_add(json_stat, "depthOutq",
43aa5965 12336 (unsigned long)outq_count);
0112e9e0
QY
12337 json_object_int_add(json_stat, "opensSent",
12338 atomic_load_explicit(&p->open_out,
12339 memory_order_relaxed));
12340 json_object_int_add(json_stat, "opensRecv",
12341 atomic_load_explicit(&p->open_in,
12342 memory_order_relaxed));
d62a17ae 12343 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
12344 atomic_load_explicit(&p->notify_out,
12345 memory_order_relaxed));
d62a17ae 12346 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
12347 atomic_load_explicit(&p->notify_in,
12348 memory_order_relaxed));
12349 json_object_int_add(json_stat, "updatesSent",
12350 atomic_load_explicit(&p->update_out,
12351 memory_order_relaxed));
12352 json_object_int_add(json_stat, "updatesRecv",
12353 atomic_load_explicit(&p->update_in,
12354 memory_order_relaxed));
d62a17ae 12355 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
12356 atomic_load_explicit(&p->keepalive_out,
12357 memory_order_relaxed));
d62a17ae 12358 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
12359 atomic_load_explicit(&p->keepalive_in,
12360 memory_order_relaxed));
d62a17ae 12361 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
12362 atomic_load_explicit(&p->refresh_out,
12363 memory_order_relaxed));
d62a17ae 12364 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
12365 atomic_load_explicit(&p->refresh_in,
12366 memory_order_relaxed));
d62a17ae 12367 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
12368 atomic_load_explicit(&p->dynamic_cap_out,
12369 memory_order_relaxed));
d62a17ae 12370 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
12371 atomic_load_explicit(&p->dynamic_cap_in,
12372 memory_order_relaxed));
12373 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
12374 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 12375 json_object_object_add(json_neigh, "messageStats", json_stat);
12376 } else {
43aa5965
QY
12377 atomic_size_t outq_count, inq_count;
12378 outq_count = atomic_load_explicit(&p->obuf->count,
12379 memory_order_relaxed);
12380 inq_count = atomic_load_explicit(&p->ibuf->count,
12381 memory_order_relaxed);
12382
d62a17ae 12383 /* Packet counts. */
12384 vty_out(vty, " Message statistics:\n");
43aa5965
QY
12385 vty_out(vty, " Inq depth is %zu\n", inq_count);
12386 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 12387 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
12388 vty_out(vty, " Opens: %10d %10d\n",
12389 atomic_load_explicit(&p->open_out,
12390 memory_order_relaxed),
12391 atomic_load_explicit(&p->open_in,
12392 memory_order_relaxed));
12393 vty_out(vty, " Notifications: %10d %10d\n",
12394 atomic_load_explicit(&p->notify_out,
12395 memory_order_relaxed),
12396 atomic_load_explicit(&p->notify_in,
12397 memory_order_relaxed));
12398 vty_out(vty, " Updates: %10d %10d\n",
12399 atomic_load_explicit(&p->update_out,
12400 memory_order_relaxed),
12401 atomic_load_explicit(&p->update_in,
12402 memory_order_relaxed));
12403 vty_out(vty, " Keepalives: %10d %10d\n",
12404 atomic_load_explicit(&p->keepalive_out,
12405 memory_order_relaxed),
12406 atomic_load_explicit(&p->keepalive_in,
12407 memory_order_relaxed));
12408 vty_out(vty, " Route Refresh: %10d %10d\n",
12409 atomic_load_explicit(&p->refresh_out,
12410 memory_order_relaxed),
12411 atomic_load_explicit(&p->refresh_in,
12412 memory_order_relaxed));
d62a17ae 12413 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
12414 atomic_load_explicit(&p->dynamic_cap_out,
12415 memory_order_relaxed),
12416 atomic_load_explicit(&p->dynamic_cap_in,
12417 memory_order_relaxed));
12418 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
12419 PEER_TOTAL_RX(p));
d62a17ae 12420 }
12421
12422 if (use_json) {
12423 /* advertisement-interval */
12424 json_object_int_add(json_neigh,
12425 "minBtwnAdvertisementRunsTimerMsecs",
12426 p->v_routeadv * 1000);
12427
12428 /* Update-source. */
12429 if (p->update_if || p->update_source) {
12430 if (p->update_if)
12431 json_object_string_add(json_neigh,
12432 "updateSource",
12433 p->update_if);
12434 else if (p->update_source)
12435 json_object_string_add(
12436 json_neigh, "updateSource",
12437 sockunion2str(p->update_source, buf1,
12438 SU_ADDRSTRLEN));
12439 }
12440 } else {
12441 /* advertisement-interval */
12442 vty_out(vty,
12443 " Minimum time between advertisement runs is %d seconds\n",
12444 p->v_routeadv);
12445
12446 /* Update-source. */
12447 if (p->update_if || p->update_source) {
12448 vty_out(vty, " Update source is ");
12449 if (p->update_if)
12450 vty_out(vty, "%s", p->update_if);
12451 else if (p->update_source)
12452 vty_out(vty, "%s",
12453 sockunion2str(p->update_source, buf1,
12454 SU_ADDRSTRLEN));
12455 vty_out(vty, "\n");
12456 }
12457
12458 vty_out(vty, "\n");
12459 }
12460
12461 /* Address Family Information */
12462 json_object *json_hold = NULL;
12463
12464 if (use_json)
12465 json_hold = json_object_new_object();
12466
05c7a1cc
QY
12467 FOREACH_AFI_SAFI (afi, safi)
12468 if (p->afc[afi][safi])
12469 bgp_show_peer_afi(vty, p, afi, safi, use_json,
12470 json_hold);
d62a17ae 12471
12472 if (use_json) {
12473 json_object_object_add(json_neigh, "addressFamilyInfo",
12474 json_hold);
12475 json_object_int_add(json_neigh, "connectionsEstablished",
12476 p->established);
12477 json_object_int_add(json_neigh, "connectionsDropped",
12478 p->dropped);
12479 } else
12480 vty_out(vty, " Connections established %d; dropped %d\n",
12481 p->established, p->dropped);
12482
12483 if (!p->last_reset) {
12484 if (use_json)
12485 json_object_string_add(json_neigh, "lastReset",
12486 "never");
12487 else
12488 vty_out(vty, " Last reset never\n");
12489 } else {
12490 if (use_json) {
12491 time_t uptime;
a2700b50 12492 struct tm tm;
d62a17ae 12493
12494 uptime = bgp_clock();
12495 uptime -= p->resettime;
a2700b50
MS
12496 gmtime_r(&uptime, &tm);
12497
d62a17ae 12498 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
12499 (tm.tm_sec * 1000)
12500 + (tm.tm_min * 60000)
12501 + (tm.tm_hour * 3600000));
3577f1c5 12502 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 12503 } else {
12504 vty_out(vty, " Last reset %s, ",
12505 peer_uptime(p->resettime, timebuf,
12506 BGP_UPTIME_LEN, 0, NULL));
12507
3577f1c5 12508 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 12509 if (p->last_reset_cause_size) {
12510 msg = p->last_reset_cause;
12511 vty_out(vty,
12512 " Message received that caused BGP to send a NOTIFICATION:\n ");
12513 for (i = 1; i <= p->last_reset_cause_size;
12514 i++) {
12515 vty_out(vty, "%02X", *msg++);
12516
12517 if (i != p->last_reset_cause_size) {
12518 if (i % 16 == 0) {
12519 vty_out(vty, "\n ");
12520 } else if (i % 4 == 0) {
12521 vty_out(vty, " ");
12522 }
12523 }
12524 }
12525 vty_out(vty, "\n");
12526 }
12527 }
12528 }
12529
12530 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
12531 if (use_json)
12532 json_object_boolean_true_add(json_neigh,
12533 "prefixesConfigExceedMax");
12534 else
12535 vty_out(vty,
12536 " Peer had exceeded the max. no. of prefixes configured.\n");
12537
12538 if (p->t_pmax_restart) {
12539 if (use_json) {
12540 json_object_boolean_true_add(
12541 json_neigh, "reducePrefixNumFrom");
12542 json_object_int_add(json_neigh,
12543 "restartInTimerMsec",
12544 thread_timer_remain_second(
12545 p->t_pmax_restart)
12546 * 1000);
12547 } else
12548 vty_out(vty,
12549 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
12550 p->host, thread_timer_remain_second(
12551 p->t_pmax_restart));
d62a17ae 12552 } else {
12553 if (use_json)
12554 json_object_boolean_true_add(
12555 json_neigh,
12556 "reducePrefixNumAndClearIpBgp");
12557 else
12558 vty_out(vty,
12559 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
12560 p->host);
12561 }
12562 }
12563
12564 /* EBGP Multihop and GTSM */
12565 if (p->sort != BGP_PEER_IBGP) {
12566 if (use_json) {
e2521429 12567 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12568 json_object_int_add(json_neigh,
12569 "externalBgpNbrMaxHopsAway",
12570 p->gtsm_hops);
c8d6f0d6 12571 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12572 json_object_int_add(json_neigh,
12573 "externalBgpNbrMaxHopsAway",
12574 p->ttl);
12575 } else {
e2521429 12576 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12577 vty_out(vty,
12578 " External BGP neighbor may be up to %d hops away.\n",
12579 p->gtsm_hops);
c8d6f0d6 12580 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12581 vty_out(vty,
12582 " External BGP neighbor may be up to %d hops away.\n",
12583 p->ttl);
12584 }
12585 } else {
e2521429 12586 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 12587 if (use_json)
12588 json_object_int_add(json_neigh,
12589 "internalBgpNbrMaxHopsAway",
12590 p->gtsm_hops);
12591 else
12592 vty_out(vty,
12593 " Internal BGP neighbor may be up to %d hops away.\n",
12594 p->gtsm_hops);
12595 }
12596 }
12597
12598 /* Local address. */
12599 if (p->su_local) {
12600 if (use_json) {
12601 json_object_string_add(json_neigh, "hostLocal",
12602 sockunion2str(p->su_local, buf1,
12603 SU_ADDRSTRLEN));
12604 json_object_int_add(json_neigh, "portLocal",
12605 ntohs(p->su_local->sin.sin_port));
12606 } else
12607 vty_out(vty, "Local host: %s, Local port: %d\n",
12608 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
12609 ntohs(p->su_local->sin.sin_port));
12610 }
12611
12612 /* Remote address. */
12613 if (p->su_remote) {
12614 if (use_json) {
12615 json_object_string_add(json_neigh, "hostForeign",
12616 sockunion2str(p->su_remote, buf1,
12617 SU_ADDRSTRLEN));
12618 json_object_int_add(json_neigh, "portForeign",
12619 ntohs(p->su_remote->sin.sin_port));
12620 } else
12621 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12622 sockunion2str(p->su_remote, buf1,
12623 SU_ADDRSTRLEN),
12624 ntohs(p->su_remote->sin.sin_port));
12625 }
12626
12627 /* Nexthop display. */
12628 if (p->su_local) {
12629 if (use_json) {
12630 json_object_string_add(json_neigh, "nexthop",
12631 inet_ntop(AF_INET,
12632 &p->nexthop.v4, buf1,
12633 sizeof(buf1)));
12634 json_object_string_add(json_neigh, "nexthopGlobal",
12635 inet_ntop(AF_INET6,
12636 &p->nexthop.v6_global,
12637 buf1, sizeof(buf1)));
12638 json_object_string_add(json_neigh, "nexthopLocal",
12639 inet_ntop(AF_INET6,
12640 &p->nexthop.v6_local,
12641 buf1, sizeof(buf1)));
12642 if (p->shared_network)
12643 json_object_string_add(json_neigh,
12644 "bgpConnection",
12645 "sharedNetwork");
12646 else
12647 json_object_string_add(json_neigh,
12648 "bgpConnection",
12649 "nonSharedNetwork");
12650 } else {
12651 vty_out(vty, "Nexthop: %s\n",
12652 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12653 sizeof(buf1)));
12654 vty_out(vty, "Nexthop global: %s\n",
12655 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12656 sizeof(buf1)));
12657 vty_out(vty, "Nexthop local: %s\n",
12658 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12659 sizeof(buf1)));
12660 vty_out(vty, "BGP connection: %s\n",
12661 p->shared_network ? "shared network"
12662 : "non shared network");
12663 }
12664 }
12665
12666 /* Timer information. */
12667 if (use_json) {
12668 json_object_int_add(json_neigh, "connectRetryTimer",
12669 p->v_connect);
12670 if (p->status == Established && p->rtt)
12671 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12672 p->rtt);
12673 if (p->t_start)
12674 json_object_int_add(
12675 json_neigh, "nextStartTimerDueInMsecs",
12676 thread_timer_remain_second(p->t_start) * 1000);
12677 if (p->t_connect)
12678 json_object_int_add(
12679 json_neigh, "nextConnectTimerDueInMsecs",
12680 thread_timer_remain_second(p->t_connect)
12681 * 1000);
12682 if (p->t_routeadv) {
12683 json_object_int_add(json_neigh, "mraiInterval",
12684 p->v_routeadv);
12685 json_object_int_add(
12686 json_neigh, "mraiTimerExpireInMsecs",
12687 thread_timer_remain_second(p->t_routeadv)
12688 * 1000);
12689 }
12690 if (p->password)
12691 json_object_int_add(json_neigh, "authenticationEnabled",
12692 1);
12693
12694 if (p->t_read)
12695 json_object_string_add(json_neigh, "readThread", "on");
12696 else
12697 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
12698
12699 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 12700 json_object_string_add(json_neigh, "writeThread", "on");
12701 else
12702 json_object_string_add(json_neigh, "writeThread",
12703 "off");
12704 } else {
12705 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12706 p->v_connect);
12707 if (p->status == Established && p->rtt)
12708 vty_out(vty, "Estimated round trip time: %d ms\n",
12709 p->rtt);
12710 if (p->t_start)
12711 vty_out(vty, "Next start timer due in %ld seconds\n",
12712 thread_timer_remain_second(p->t_start));
12713 if (p->t_connect)
12714 vty_out(vty, "Next connect timer due in %ld seconds\n",
12715 thread_timer_remain_second(p->t_connect));
12716 if (p->t_routeadv)
12717 vty_out(vty,
12718 "MRAI (interval %u) timer expires in %ld seconds\n",
12719 p->v_routeadv,
12720 thread_timer_remain_second(p->t_routeadv));
12721 if (p->password)
12722 vty_out(vty, "Peer Authentication Enabled\n");
12723
cac9e917 12724 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
12725 p->t_read ? "on" : "off",
12726 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12727 ? "on"
cac9e917 12728 : "off", p->fd);
d62a17ae 12729 }
12730
12731 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12732 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12733 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12734
12735 if (!use_json)
12736 vty_out(vty, "\n");
12737
12738 /* BFD information. */
12739 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12740
12741 if (use_json) {
12742 if (p->conf_if) /* Configured interface name. */
12743 json_object_object_add(json, p->conf_if, json_neigh);
12744 else /* Configured IP address. */
12745 json_object_object_add(json, p->host, json_neigh);
12746 }
12747}
12748
36235319
QY
12749static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
12750 enum show_type type,
12751 union sockunion *su,
12752 const char *conf_if, afi_t afi,
74a630b6 12753 bool use_json)
2986cac2 12754{
12755 struct listnode *node, *nnode;
12756 struct peer *peer;
12757 int find = 0;
12758 safi_t safi = SAFI_UNICAST;
74a630b6 12759 json_object *json = NULL;
2986cac2 12760 json_object *json_neighbor = NULL;
12761
74a630b6
NT
12762 if (use_json) {
12763 json = json_object_new_object();
12764 json_neighbor = json_object_new_object();
12765 }
12766
2986cac2 12767 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12768
12769 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12770 continue;
12771
12772 if ((peer->afc[afi][safi]) == 0)
12773 continue;
12774
2ba1fe69 12775 if (type == show_all) {
2986cac2 12776 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 12777 json_neighbor);
2986cac2 12778
74a630b6 12779 if (use_json) {
13909c4f
DS
12780 json_object_object_add(json, peer->host,
12781 json_neighbor);
74a630b6
NT
12782 json_neighbor = NULL;
12783 }
2986cac2 12784
2ba1fe69 12785 } else if (type == show_peer) {
2986cac2 12786 if (conf_if) {
12787 if ((peer->conf_if
13909c4f
DS
12788 && !strcmp(peer->conf_if, conf_if))
12789 || (peer->hostname
2986cac2 12790 && !strcmp(peer->hostname, conf_if))) {
12791 find = 1;
13909c4f
DS
12792 bgp_show_peer_gr_status(vty, peer,
12793 use_json,
12794 json_neighbor);
2986cac2 12795 }
12796 } else {
12797 if (sockunion_same(&peer->su, su)) {
12798 find = 1;
13909c4f
DS
12799 bgp_show_peer_gr_status(vty, peer,
12800 use_json,
12801 json_neighbor);
2986cac2 12802 }
12803 }
13909c4f
DS
12804 if (use_json && find)
12805 json_object_object_add(json, peer->host,
12806 json_neighbor);
2986cac2 12807 }
12808
74a630b6
NT
12809 if (find) {
12810 json_neighbor = NULL;
2986cac2 12811 break;
74a630b6 12812 }
2986cac2 12813 }
12814
12815 if (type == show_peer && !find) {
12816 if (use_json)
13909c4f 12817 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 12818 else
12819 vty_out(vty, "%% No such neighbor\n");
12820 }
12821 if (use_json) {
13909c4f
DS
12822 vty_out(vty, "%s\n",
12823 json_object_to_json_string_ext(
12824 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
12825
12826 if (json_neighbor)
12827 json_object_free(json_neighbor);
12828 json_object_free(json);
2986cac2 12829 } else {
12830 vty_out(vty, "\n");
12831 }
12832
12833 return CMD_SUCCESS;
12834}
12835
d62a17ae 12836static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12837 enum show_type type, union sockunion *su,
9f049418 12838 const char *conf_if, bool use_json,
d62a17ae 12839 json_object *json)
12840{
12841 struct listnode *node, *nnode;
12842 struct peer *peer;
12843 int find = 0;
9f049418 12844 bool nbr_output = false;
d1927ebe
AS
12845 afi_t afi = AFI_MAX;
12846 safi_t safi = SAFI_MAX;
12847
12848 if (type == show_ipv4_peer || type == show_ipv4_all) {
12849 afi = AFI_IP;
12850 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12851 afi = AFI_IP6;
12852 }
d62a17ae 12853
12854 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12855 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12856 continue;
12857
12858 switch (type) {
12859 case show_all:
12860 bgp_show_peer(vty, peer, use_json, json);
9f049418 12861 nbr_output = true;
d62a17ae 12862 break;
12863 case show_peer:
12864 if (conf_if) {
12865 if ((peer->conf_if
12866 && !strcmp(peer->conf_if, conf_if))
12867 || (peer->hostname
12868 && !strcmp(peer->hostname, conf_if))) {
12869 find = 1;
12870 bgp_show_peer(vty, peer, use_json,
12871 json);
12872 }
12873 } else {
12874 if (sockunion_same(&peer->su, su)) {
12875 find = 1;
12876 bgp_show_peer(vty, peer, use_json,
12877 json);
12878 }
12879 }
12880 break;
d1927ebe
AS
12881 case show_ipv4_peer:
12882 case show_ipv6_peer:
12883 FOREACH_SAFI (safi) {
12884 if (peer->afc[afi][safi]) {
12885 if (conf_if) {
12886 if ((peer->conf_if
12887 && !strcmp(peer->conf_if, conf_if))
12888 || (peer->hostname
12889 && !strcmp(peer->hostname, conf_if))) {
12890 find = 1;
12891 bgp_show_peer(vty, peer, use_json,
12892 json);
12893 break;
12894 }
12895 } else {
12896 if (sockunion_same(&peer->su, su)) {
12897 find = 1;
12898 bgp_show_peer(vty, peer, use_json,
12899 json);
12900 break;
12901 }
12902 }
12903 }
12904 }
12905 break;
12906 case show_ipv4_all:
12907 case show_ipv6_all:
12908 FOREACH_SAFI (safi) {
12909 if (peer->afc[afi][safi]) {
12910 bgp_show_peer(vty, peer, use_json, json);
12911 nbr_output = true;
12912 break;
12913 }
12914 }
12915 break;
d62a17ae 12916 }
12917 }
12918
d1927ebe
AS
12919 if ((type == show_peer || type == show_ipv4_peer ||
12920 type == show_ipv6_peer) && !find) {
d62a17ae 12921 if (use_json)
12922 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12923 else
88b7d255 12924 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 12925 }
12926
d1927ebe
AS
12927 if (type != show_peer && type != show_ipv4_peer &&
12928 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 12929 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 12930
d62a17ae 12931 if (use_json) {
996c9314
LB
12932 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12933 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 12934 } else {
12935 vty_out(vty, "\n");
12936 }
12937
12938 return CMD_SUCCESS;
12939}
12940
36235319
QY
12941static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12942 enum show_type type,
12943 const char *ip_str,
12944 afi_t afi, bool use_json)
2986cac2 12945{
12946
12947 int ret;
12948 struct bgp *bgp;
12949 union sockunion su;
2986cac2 12950
12951 bgp = bgp_get_default();
12952
13909c4f
DS
12953 if (!bgp)
12954 return;
2986cac2 12955
13909c4f
DS
12956 if (!use_json)
12957 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12958 NULL);
2986cac2 12959
13909c4f
DS
12960 if (ip_str) {
12961 ret = str2sockunion(ip_str, &su);
12962 if (ret < 0)
13909c4f 12963 bgp_show_neighbor_graceful_restart(
74a630b6
NT
12964 vty, bgp, type, NULL, ip_str, afi, use_json);
12965 else
12966 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
12967 NULL, afi, use_json);
13909c4f
DS
12968 } else
12969 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 12970 afi, use_json);
2986cac2 12971}
12972
d62a17ae 12973static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
12974 enum show_type type,
12975 const char *ip_str,
9f049418 12976 bool use_json)
d62a17ae 12977{
0291c246
MK
12978 struct listnode *node, *nnode;
12979 struct bgp *bgp;
71aedaa3 12980 union sockunion su;
0291c246 12981 json_object *json = NULL;
71aedaa3 12982 int ret, is_first = 1;
9f049418 12983 bool nbr_output = false;
d62a17ae 12984
12985 if (use_json)
12986 vty_out(vty, "{\n");
12987
12988 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 12989 nbr_output = true;
d62a17ae 12990 if (use_json) {
12991 if (!(json = json_object_new_object())) {
af4c2728 12992 flog_err(
e50f7cfd 12993 EC_BGP_JSON_MEM_ERROR,
d62a17ae 12994 "Unable to allocate memory for JSON object");
12995 vty_out(vty,
12996 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12997 return;
12998 }
12999
13000 json_object_int_add(json, "vrfId",
13001 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
13002 ? -1
13003 : (int64_t)bgp->vrf_id);
d62a17ae 13004 json_object_string_add(
13005 json, "vrfName",
13006 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13007 ? VRF_DEFAULT_NAME
d62a17ae 13008 : bgp->name);
13009
13010 if (!is_first)
13011 vty_out(vty, ",\n");
13012 else
13013 is_first = 0;
13014
13015 vty_out(vty, "\"%s\":",
13016 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13017 ? VRF_DEFAULT_NAME
d62a17ae 13018 : bgp->name);
13019 } else {
13020 vty_out(vty, "\nInstance %s:\n",
13021 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13022 ? VRF_DEFAULT_NAME
d62a17ae 13023 : bgp->name);
13024 }
71aedaa3 13025
d1927ebe
AS
13026 if (type == show_peer || type == show_ipv4_peer ||
13027 type == show_ipv6_peer) {
71aedaa3
DS
13028 ret = str2sockunion(ip_str, &su);
13029 if (ret < 0)
13030 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13031 use_json, json);
13032 else
13033 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13034 use_json, json);
13035 } else {
d1927ebe 13036 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
13037 use_json, json);
13038 }
b77004d6 13039 json_object_free(json);
121067e9 13040 json = NULL;
d62a17ae 13041 }
13042
3e78a6ce 13043 if (use_json)
d62a17ae 13044 vty_out(vty, "}\n");
9f049418
DS
13045 else if (!nbr_output)
13046 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 13047}
13048
13049static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
13050 enum show_type type, const char *ip_str,
9f049418 13051 bool use_json)
d62a17ae 13052{
13053 int ret;
13054 struct bgp *bgp;
13055 union sockunion su;
13056 json_object *json = NULL;
13057
13058 if (name) {
13059 if (strmatch(name, "all")) {
71aedaa3
DS
13060 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
13061 use_json);
d62a17ae 13062 return CMD_SUCCESS;
13063 } else {
13064 bgp = bgp_lookup_by_name(name);
13065 if (!bgp) {
13066 if (use_json) {
13067 json = json_object_new_object();
d62a17ae 13068 vty_out(vty, "%s\n",
13069 json_object_to_json_string_ext(
13070 json,
13071 JSON_C_TO_STRING_PRETTY));
13072 json_object_free(json);
13073 } else
13074 vty_out(vty,
9f049418 13075 "%% BGP instance not found\n");
d62a17ae 13076
13077 return CMD_WARNING;
13078 }
13079 }
13080 } else {
13081 bgp = bgp_get_default();
13082 }
13083
13084 if (bgp) {
13085 json = json_object_new_object();
13086 if (ip_str) {
13087 ret = str2sockunion(ip_str, &su);
13088 if (ret < 0)
13089 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13090 use_json, json);
13091 else
13092 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13093 use_json, json);
13094 } else {
13095 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
13096 json);
13097 }
13098 json_object_free(json);
ca61fd25
DS
13099 } else {
13100 if (use_json)
13101 vty_out(vty, "{}\n");
13102 else
13103 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 13104 }
13105
13106 return CMD_SUCCESS;
4fb25c53
DW
13107}
13108
2986cac2 13109
13110
13111/* "show [ip] bgp neighbors graceful-restart" commands. */
13112DEFUN (show_ip_bgp_neighbors_gracrful_restart,
13113 show_ip_bgp_neighbors_graceful_restart_cmd,
13114 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
13115 SHOW_STR
13116 BGP_STR
13117 IP_STR
13118 IPV6_STR
13119 NEIGHBOR_STR
13120 "Neighbor to display information about\n"
13121 "Neighbor to display information about\n"
13122 "Neighbor on BGP configured interface\n"
13123 GR_SHOW
13124 JSON_STR)
13125{
13126 char *sh_arg = NULL;
13127 enum show_type sh_type;
13128 int idx = 0;
13129 afi_t afi = AFI_MAX;
2986cac2 13130 bool uj = use_json(argc, argv);
13131
36235319 13132 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 13133 afi = AFI_MAX;
13134
13135 idx++;
13136
13137 if (argv_find(argv, argc, "A.B.C.D", &idx)
13138 || argv_find(argv, argc, "X:X::X:X", &idx)
13139 || argv_find(argv, argc, "WORD", &idx)) {
13140 sh_type = show_peer;
13141 sh_arg = argv[idx]->arg;
13142 } else
13143 sh_type = show_all;
13144
13145 if (!argv_find(argv, argc, "graceful-restart", &idx))
13146 return CMD_SUCCESS;
13147
13148
36235319
QY
13149 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
13150 afi, uj);
2986cac2 13151}
13152
716b2d8a 13153/* "show [ip] bgp neighbors" commands. */
718e3744 13154DEFUN (show_ip_bgp_neighbors,
13155 show_ip_bgp_neighbors_cmd,
24345e82 13156 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 13157 SHOW_STR
13158 IP_STR
13159 BGP_STR
f2a8972b 13160 BGP_INSTANCE_HELP_STR
8c3deaae
QY
13161 "Address Family\n"
13162 "Address Family\n"
718e3744 13163 "Detailed information on TCP and BGP neighbor connections\n"
13164 "Neighbor to display information about\n"
a80beece 13165 "Neighbor to display information about\n"
91d37724 13166 "Neighbor on BGP configured interface\n"
9973d184 13167 JSON_STR)
718e3744 13168{
d62a17ae 13169 char *vrf = NULL;
13170 char *sh_arg = NULL;
13171 enum show_type sh_type;
d1927ebe 13172 afi_t afi = AFI_MAX;
718e3744 13173
9f049418 13174 bool uj = use_json(argc, argv);
718e3744 13175
d62a17ae 13176 int idx = 0;
718e3744 13177
9a8bdf1c
PG
13178 /* [<vrf> VIEWVRFNAME] */
13179 if (argv_find(argv, argc, "vrf", &idx)) {
13180 vrf = argv[idx + 1]->arg;
13181 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13182 vrf = NULL;
13183 } else if (argv_find(argv, argc, "view", &idx))
13184 /* [<view> VIEWVRFNAME] */
d62a17ae 13185 vrf = argv[idx + 1]->arg;
718e3744 13186
d62a17ae 13187 idx++;
d1927ebe
AS
13188
13189 if (argv_find(argv, argc, "ipv4", &idx)) {
13190 sh_type = show_ipv4_all;
13191 afi = AFI_IP;
13192 } else if (argv_find(argv, argc, "ipv6", &idx)) {
13193 sh_type = show_ipv6_all;
13194 afi = AFI_IP6;
13195 } else {
13196 sh_type = show_all;
13197 }
13198
d62a17ae 13199 if (argv_find(argv, argc, "A.B.C.D", &idx)
13200 || argv_find(argv, argc, "X:X::X:X", &idx)
13201 || argv_find(argv, argc, "WORD", &idx)) {
13202 sh_type = show_peer;
13203 sh_arg = argv[idx]->arg;
d1927ebe
AS
13204 }
13205
13206 if (sh_type == show_peer && afi == AFI_IP) {
13207 sh_type = show_ipv4_peer;
13208 } else if (sh_type == show_peer && afi == AFI_IP6) {
13209 sh_type = show_ipv6_peer;
13210 }
856ca177 13211
d62a17ae 13212 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 13213}
13214
716b2d8a 13215/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 13216 paths' and `show ip mbgp paths'. Those functions results are the
13217 same.*/
f412b39a 13218DEFUN (show_ip_bgp_paths,
718e3744 13219 show_ip_bgp_paths_cmd,
46f296b4 13220 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 13221 SHOW_STR
13222 IP_STR
13223 BGP_STR
46f296b4 13224 BGP_SAFI_HELP_STR
718e3744 13225 "Path information\n")
13226{
d62a17ae 13227 vty_out(vty, "Address Refcnt Path\n");
13228 aspath_print_all_vty(vty);
13229 return CMD_SUCCESS;
718e3744 13230}
13231
718e3744 13232#include "hash.h"
13233
e3b78da8 13234static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 13235 struct vty *vty)
718e3744 13236{
d62a17ae 13237 struct community *com;
718e3744 13238
e3b78da8 13239 com = (struct community *)bucket->data;
3f65c5b1 13240 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 13241 community_str(com, false));
718e3744 13242}
13243
13244/* Show BGP's community internal data. */
f412b39a 13245DEFUN (show_ip_bgp_community_info,
718e3744 13246 show_ip_bgp_community_info_cmd,
bec37ba5 13247 "show [ip] bgp community-info",
718e3744 13248 SHOW_STR
13249 IP_STR
13250 BGP_STR
13251 "List all bgp community information\n")
13252{
d62a17ae 13253 vty_out(vty, "Address Refcnt Community\n");
718e3744 13254
d62a17ae 13255 hash_iterate(community_hash(),
e3b78da8 13256 (void (*)(struct hash_bucket *,
d62a17ae 13257 void *))community_show_all_iterator,
13258 vty);
718e3744 13259
d62a17ae 13260 return CMD_SUCCESS;
718e3744 13261}
13262
e3b78da8 13263static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 13264 struct vty *vty)
57d187bc 13265{
d62a17ae 13266 struct lcommunity *lcom;
57d187bc 13267
e3b78da8 13268 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 13269 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 13270 lcommunity_str(lcom, false));
57d187bc
JS
13271}
13272
13273/* Show BGP's community internal data. */
13274DEFUN (show_ip_bgp_lcommunity_info,
13275 show_ip_bgp_lcommunity_info_cmd,
13276 "show ip bgp large-community-info",
13277 SHOW_STR
13278 IP_STR
13279 BGP_STR
13280 "List all bgp large-community information\n")
13281{
d62a17ae 13282 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 13283
d62a17ae 13284 hash_iterate(lcommunity_hash(),
e3b78da8 13285 (void (*)(struct hash_bucket *,
d62a17ae 13286 void *))lcommunity_show_all_iterator,
13287 vty);
57d187bc 13288
d62a17ae 13289 return CMD_SUCCESS;
57d187bc 13290}
2986cac2 13291/* Graceful Restart */
13292
13293static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
13294 struct bgp *bgp,
13295 bool use_json,
13296 json_object *json)
2986cac2 13297{
57d187bc
JS
13298
13299
2986cac2 13300 vty_out(vty, "\n%s", SHOW_GR_HEADER);
13301
7318ae88 13302 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 13303
13304 switch (bgp_global_gr_mode) {
13305
13306 case GLOBAL_HELPER:
13909c4f 13307 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 13308 break;
13309
13310 case GLOBAL_GR:
13909c4f 13311 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 13312 break;
13313
13314 case GLOBAL_DISABLE:
13909c4f 13315 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 13316 break;
13317
13318 case GLOBAL_INVALID:
2986cac2 13319 vty_out(vty,
2ba1fe69 13320 "Global BGP GR Mode Invalid\n");
2986cac2 13321 break;
13322 }
13323 vty_out(vty, "\n");
13324}
13325
36235319
QY
13326static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
13327 enum show_type type,
13328 const char *ip_str,
13329 afi_t afi, bool use_json)
2986cac2 13330{
13331 if ((afi == AFI_MAX) && (ip_str == NULL)) {
13332 afi = AFI_IP;
13333
13334 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
13335
36235319
QY
13336 bgp_show_neighbor_graceful_restart_vty(
13337 vty, type, ip_str, afi, use_json);
2986cac2 13338 afi++;
13339 }
13340 } else if (afi != AFI_MAX) {
36235319
QY
13341 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
13342 use_json);
2986cac2 13343 } else {
13344 return CMD_ERR_INCOMPLETE;
13345 }
13346
13347 return CMD_SUCCESS;
13348}
13349/* Graceful Restart */
13350
f412b39a 13351DEFUN (show_ip_bgp_attr_info,
718e3744 13352 show_ip_bgp_attr_info_cmd,
bec37ba5 13353 "show [ip] bgp attribute-info",
718e3744 13354 SHOW_STR
13355 IP_STR
13356 BGP_STR
13357 "List all bgp attribute information\n")
13358{
d62a17ae 13359 attr_show_all(vty);
13360 return CMD_SUCCESS;
718e3744 13361}
6b0655a2 13362
03915806
CS
13363static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
13364 afi_t afi, safi_t safi,
13365 bool use_json, json_object *json)
53089bec 13366{
13367 struct bgp *bgp;
13368 struct listnode *node;
13369 char *vname;
13370 char buf1[INET6_ADDRSTRLEN];
13371 char *ecom_str;
13372 vpn_policy_direction_t dir;
13373
03915806 13374 if (json) {
b46dfd20
DS
13375 json_object *json_import_vrfs = NULL;
13376 json_object *json_export_vrfs = NULL;
13377
b46dfd20
DS
13378 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13379
53089bec 13380 if (!bgp) {
b46dfd20
DS
13381 vty_out(vty, "%s\n",
13382 json_object_to_json_string_ext(
13383 json,
13384 JSON_C_TO_STRING_PRETTY));
13385 json_object_free(json);
13386
53089bec 13387 return CMD_WARNING;
13388 }
b46dfd20 13389
94d4c685
DS
13390 /* Provide context for the block */
13391 json_object_string_add(json, "vrf", name ? name : "default");
13392 json_object_string_add(json, "afiSafi",
5cb5f4d0 13393 get_afi_safi_str(afi, safi, true));
94d4c685 13394
b46dfd20
DS
13395 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13396 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
13397 json_object_string_add(json, "importFromVrfs", "none");
13398 json_object_string_add(json, "importRts", "none");
13399 } else {
6ce24e52
DS
13400 json_import_vrfs = json_object_new_array();
13401
b46dfd20
DS
13402 for (ALL_LIST_ELEMENTS_RO(
13403 bgp->vpn_policy[afi].import_vrf,
13404 node, vname))
13405 json_object_array_add(json_import_vrfs,
13406 json_object_new_string(vname));
13407
b20875ea
CS
13408 json_object_object_add(json, "importFromVrfs",
13409 json_import_vrfs);
b46dfd20 13410 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13411 if (bgp->vpn_policy[afi].rtlist[dir]) {
13412 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13413 bgp->vpn_policy[afi].rtlist[dir],
13414 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13415 json_object_string_add(json, "importRts",
13416 ecom_str);
13417 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13418 } else
13419 json_object_string_add(json, "importRts",
13420 "none");
b46dfd20
DS
13421 }
13422
13423 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13424 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
13425 json_object_string_add(json, "exportToVrfs", "none");
13426 json_object_string_add(json, "routeDistinguisher",
13427 "none");
13428 json_object_string_add(json, "exportRts", "none");
13429 } else {
6ce24e52
DS
13430 json_export_vrfs = json_object_new_array();
13431
b46dfd20
DS
13432 for (ALL_LIST_ELEMENTS_RO(
13433 bgp->vpn_policy[afi].export_vrf,
13434 node, vname))
13435 json_object_array_add(json_export_vrfs,
13436 json_object_new_string(vname));
13437 json_object_object_add(json, "exportToVrfs",
13438 json_export_vrfs);
13439 json_object_string_add(json, "routeDistinguisher",
13440 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13441 buf1, RD_ADDRSTRLEN));
13442
13443 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13444 if (bgp->vpn_policy[afi].rtlist[dir]) {
13445 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13446 bgp->vpn_policy[afi].rtlist[dir],
13447 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13448 json_object_string_add(json, "exportRts",
13449 ecom_str);
13450 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13451 } else
13452 json_object_string_add(json, "exportRts",
13453 "none");
b46dfd20
DS
13454 }
13455
03915806
CS
13456 if (use_json) {
13457 vty_out(vty, "%s\n",
13458 json_object_to_json_string_ext(json,
b46dfd20 13459 JSON_C_TO_STRING_PRETTY));
03915806
CS
13460 json_object_free(json);
13461 }
53089bec 13462 } else {
b46dfd20
DS
13463 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13464
53089bec 13465 if (!bgp) {
b46dfd20 13466 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 13467 return CMD_WARNING;
13468 }
53089bec 13469
b46dfd20
DS
13470 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13471 BGP_CONFIG_VRF_TO_VRF_IMPORT))
13472 vty_out(vty,
13473 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 13474 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13475 else {
13476 vty_out(vty,
13477 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 13478 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13479
13480 for (ALL_LIST_ELEMENTS_RO(
13481 bgp->vpn_policy[afi].import_vrf,
13482 node, vname))
13483 vty_out(vty, " %s\n", vname);
13484
13485 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13486 ecom_str = NULL;
13487 if (bgp->vpn_policy[afi].rtlist[dir]) {
13488 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13489 bgp->vpn_policy[afi].rtlist[dir],
13490 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 13491 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 13492
b20875ea
CS
13493 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13494 } else
13495 vty_out(vty, "Import RT(s):\n");
53089bec 13496 }
53089bec 13497
b46dfd20
DS
13498 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13499 BGP_CONFIG_VRF_TO_VRF_EXPORT))
13500 vty_out(vty,
13501 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 13502 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13503 else {
13504 vty_out(vty,
04c9077f 13505 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 13506 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13507
13508 for (ALL_LIST_ELEMENTS_RO(
13509 bgp->vpn_policy[afi].export_vrf,
13510 node, vname))
13511 vty_out(vty, " %s\n", vname);
13512
13513 vty_out(vty, "RD: %s\n",
13514 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13515 buf1, RD_ADDRSTRLEN));
13516
13517 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13518 if (bgp->vpn_policy[afi].rtlist[dir]) {
13519 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13520 bgp->vpn_policy[afi].rtlist[dir],
13521 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13522 vty_out(vty, "Export RT: %s\n", ecom_str);
13523 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13524 } else
13525 vty_out(vty, "Import RT(s):\n");
53089bec 13526 }
53089bec 13527 }
13528
13529 return CMD_SUCCESS;
13530}
13531
03915806
CS
13532static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
13533 safi_t safi, bool use_json)
13534{
13535 struct listnode *node, *nnode;
13536 struct bgp *bgp;
13537 char *vrf_name = NULL;
13538 json_object *json = NULL;
13539 json_object *json_vrf = NULL;
13540 json_object *json_vrfs = NULL;
13541
13542 if (use_json) {
13543 json = json_object_new_object();
13544 json_vrfs = json_object_new_object();
13545 }
13546
13547 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13548
13549 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
13550 vrf_name = bgp->name;
13551
13552 if (use_json) {
13553 json_vrf = json_object_new_object();
13554 } else {
13555 vty_out(vty, "\nInstance %s:\n",
13556 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13557 ? VRF_DEFAULT_NAME : bgp->name);
13558 }
13559 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
13560 if (use_json) {
13561 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13562 json_object_object_add(json_vrfs,
13563 VRF_DEFAULT_NAME, json_vrf);
13564 else
13565 json_object_object_add(json_vrfs, vrf_name,
13566 json_vrf);
13567 }
13568 }
13569
13570 if (use_json) {
13571 json_object_object_add(json, "vrfs", json_vrfs);
13572 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
13573 JSON_C_TO_STRING_PRETTY));
13574 json_object_free(json);
13575 }
13576
13577 return CMD_SUCCESS;
13578}
13579
53089bec 13580/* "show [ip] bgp route-leak" command. */
13581DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
13582 show_ip_bgp_route_leak_cmd,
13583 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
13584 SHOW_STR
13585 IP_STR
13586 BGP_STR
13587 BGP_INSTANCE_HELP_STR
13588 BGP_AFI_HELP_STR
13589 BGP_SAFI_HELP_STR
13590 "Route leaking information\n"
13591 JSON_STR)
53089bec 13592{
13593 char *vrf = NULL;
13594 afi_t afi = AFI_MAX;
13595 safi_t safi = SAFI_MAX;
13596
9f049418 13597 bool uj = use_json(argc, argv);
53089bec 13598 int idx = 0;
03915806 13599 json_object *json = NULL;
53089bec 13600
13601 /* show [ip] bgp */
13602 if (argv_find(argv, argc, "ip", &idx)) {
13603 afi = AFI_IP;
13604 safi = SAFI_UNICAST;
13605 }
13606 /* [vrf VIEWVRFNAME] */
13607 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
13608 vty_out(vty,
13609 "%% This command is not applicable to BGP views\n");
53089bec 13610 return CMD_WARNING;
13611 }
13612
9a8bdf1c
PG
13613 if (argv_find(argv, argc, "vrf", &idx)) {
13614 vrf = argv[idx + 1]->arg;
13615 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13616 vrf = NULL;
13617 }
53089bec 13618 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13619 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13620 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13621 }
13622
13623 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
13624 vty_out(vty,
13625 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 13626 return CMD_WARNING;
13627 }
13628
03915806
CS
13629 if (vrf && strmatch(vrf, "all"))
13630 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13631
13632 if (uj)
13633 json = json_object_new_object();
13634
13635 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 13636}
13637
d62a17ae 13638static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13639 safi_t safi)
f186de26 13640{
d62a17ae 13641 struct listnode *node, *nnode;
13642 struct bgp *bgp;
f186de26 13643
d62a17ae 13644 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13645 vty_out(vty, "\nInstance %s:\n",
13646 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13647 ? VRF_DEFAULT_NAME
d62a17ae 13648 : bgp->name);
13649 update_group_show(bgp, afi, safi, vty, 0);
13650 }
f186de26 13651}
13652
d62a17ae 13653static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13654 int safi, uint64_t subgrp_id)
4fb25c53 13655{
d62a17ae 13656 struct bgp *bgp;
4fb25c53 13657
d62a17ae 13658 if (name) {
13659 if (strmatch(name, "all")) {
13660 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13661 return CMD_SUCCESS;
13662 } else {
13663 bgp = bgp_lookup_by_name(name);
13664 }
13665 } else {
13666 bgp = bgp_get_default();
13667 }
4fb25c53 13668
d62a17ae 13669 if (bgp)
13670 update_group_show(bgp, afi, safi, vty, subgrp_id);
13671 return CMD_SUCCESS;
4fb25c53
DW
13672}
13673
8fe8a7f6
DS
13674DEFUN (show_ip_bgp_updgrps,
13675 show_ip_bgp_updgrps_cmd,
c1a44e43 13676 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 13677 SHOW_STR
13678 IP_STR
13679 BGP_STR
13680 BGP_INSTANCE_HELP_STR
c9e571b4 13681 BGP_AFI_HELP_STR
9bedbb1e 13682 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
13683 "Detailed info about dynamic update groups\n"
13684 "Specific subgroup to display detailed info for\n")
8386ac43 13685{
d62a17ae 13686 char *vrf = NULL;
13687 afi_t afi = AFI_IP6;
13688 safi_t safi = SAFI_UNICAST;
13689 uint64_t subgrp_id = 0;
13690
13691 int idx = 0;
13692
13693 /* show [ip] bgp */
13694 if (argv_find(argv, argc, "ip", &idx))
13695 afi = AFI_IP;
9a8bdf1c
PG
13696 /* [<vrf> VIEWVRFNAME] */
13697 if (argv_find(argv, argc, "vrf", &idx)) {
13698 vrf = argv[idx + 1]->arg;
13699 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13700 vrf = NULL;
13701 } else if (argv_find(argv, argc, "view", &idx))
13702 /* [<view> VIEWVRFNAME] */
13703 vrf = argv[idx + 1]->arg;
d62a17ae 13704 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13705 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13706 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13707 }
5bf15956 13708
d62a17ae 13709 /* get subgroup id, if provided */
13710 idx = argc - 1;
13711 if (argv[idx]->type == VARIABLE_TKN)
13712 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 13713
d62a17ae 13714 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
13715}
13716
f186de26 13717DEFUN (show_bgp_instance_all_ipv6_updgrps,
13718 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 13719 "show [ip] bgp <view|vrf> all update-groups",
f186de26 13720 SHOW_STR
716b2d8a 13721 IP_STR
f186de26 13722 BGP_STR
13723 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 13724 "Detailed info about dynamic update groups\n")
f186de26 13725{
d62a17ae 13726 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13727 return CMD_SUCCESS;
f186de26 13728}
13729
43d3f4fc
DS
13730DEFUN (show_bgp_l2vpn_evpn_updgrps,
13731 show_bgp_l2vpn_evpn_updgrps_cmd,
13732 "show [ip] bgp l2vpn evpn update-groups",
13733 SHOW_STR
13734 IP_STR
13735 BGP_STR
13736 "l2vpn address family\n"
13737 "evpn sub-address family\n"
13738 "Detailed info about dynamic update groups\n")
13739{
13740 char *vrf = NULL;
13741 uint64_t subgrp_id = 0;
13742
13743 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13744 return CMD_SUCCESS;
13745}
13746
5bf15956
DW
13747DEFUN (show_bgp_updgrps_stats,
13748 show_bgp_updgrps_stats_cmd,
716b2d8a 13749 "show [ip] bgp update-groups statistics",
3f9c7369 13750 SHOW_STR
716b2d8a 13751 IP_STR
3f9c7369 13752 BGP_STR
0c7b1b01 13753 "Detailed info about dynamic update groups\n"
3f9c7369
DS
13754 "Statistics\n")
13755{
d62a17ae 13756 struct bgp *bgp;
3f9c7369 13757
d62a17ae 13758 bgp = bgp_get_default();
13759 if (bgp)
13760 update_group_show_stats(bgp, vty);
3f9c7369 13761
d62a17ae 13762 return CMD_SUCCESS;
3f9c7369
DS
13763}
13764
8386ac43 13765DEFUN (show_bgp_instance_updgrps_stats,
13766 show_bgp_instance_updgrps_stats_cmd,
18c57037 13767 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 13768 SHOW_STR
716b2d8a 13769 IP_STR
8386ac43 13770 BGP_STR
13771 BGP_INSTANCE_HELP_STR
0c7b1b01 13772 "Detailed info about dynamic update groups\n"
8386ac43 13773 "Statistics\n")
13774{
d62a17ae 13775 int idx_word = 3;
13776 struct bgp *bgp;
8386ac43 13777
d62a17ae 13778 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13779 if (bgp)
13780 update_group_show_stats(bgp, vty);
8386ac43 13781
d62a17ae 13782 return CMD_SUCCESS;
8386ac43 13783}
13784
d62a17ae 13785static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13786 afi_t afi, safi_t safi,
13787 const char *what, uint64_t subgrp_id)
3f9c7369 13788{
d62a17ae 13789 struct bgp *bgp;
8386ac43 13790
d62a17ae 13791 if (name)
13792 bgp = bgp_lookup_by_name(name);
13793 else
13794 bgp = bgp_get_default();
8386ac43 13795
d62a17ae 13796 if (bgp) {
13797 if (!strcmp(what, "advertise-queue"))
13798 update_group_show_adj_queue(bgp, afi, safi, vty,
13799 subgrp_id);
13800 else if (!strcmp(what, "advertised-routes"))
13801 update_group_show_advertised(bgp, afi, safi, vty,
13802 subgrp_id);
13803 else if (!strcmp(what, "packet-queue"))
13804 update_group_show_packet_queue(bgp, afi, safi, vty,
13805 subgrp_id);
13806 }
3f9c7369
DS
13807}
13808
dc64bdec
QY
13809DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13810 show_ip_bgp_instance_updgrps_adj_s_cmd,
13811 "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",
13812 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13813 BGP_SAFI_HELP_STR
13814 "Detailed info about dynamic update groups\n"
13815 "Specific subgroup to display info for\n"
13816 "Advertisement queue\n"
13817 "Announced routes\n"
13818 "Packet queue\n")
3f9c7369 13819{
dc64bdec
QY
13820 uint64_t subgrp_id = 0;
13821 afi_t afiz;
13822 safi_t safiz;
13823 if (sgid)
13824 subgrp_id = strtoull(sgid, NULL, 10);
13825
13826 if (!ip && !afi)
13827 afiz = AFI_IP6;
13828 if (!ip && afi)
13829 afiz = bgp_vty_afi_from_str(afi);
13830 if (ip && !afi)
13831 afiz = AFI_IP;
13832 if (ip && afi) {
13833 afiz = bgp_vty_afi_from_str(afi);
13834 if (afiz != AFI_IP)
13835 vty_out(vty,
13836 "%% Cannot specify both 'ip' and 'ipv6'\n");
13837 return CMD_WARNING;
13838 }
d62a17ae 13839
dc64bdec 13840 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 13841
dc64bdec 13842 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 13843 return CMD_SUCCESS;
13844}
13845
d62a17ae 13846static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13847{
13848 struct listnode *node, *nnode;
13849 struct prefix *range;
13850 struct peer *conf;
13851 struct peer *peer;
13852 char buf[PREFIX2STR_BUFFER];
13853 afi_t afi;
13854 safi_t safi;
13855 const char *peer_status;
13856 const char *af_str;
13857 int lr_count;
13858 int dynamic;
13859 int af_cfgd;
13860
13861 conf = group->conf;
13862
13863 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 13864 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 13865 group->name, conf->as);
d62a17ae 13866 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 13867 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 13868 group->name, group->bgp->as);
d62a17ae 13869 } else {
13870 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13871 }
f14e6fdb 13872
d62a17ae 13873 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13874 vty_out(vty, " Peer-group type is internal\n");
13875 else
13876 vty_out(vty, " Peer-group type is external\n");
13877
13878 /* Display AFs configured. */
13879 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
13880 FOREACH_AFI_SAFI (afi, safi) {
13881 if (conf->afc[afi][safi]) {
13882 af_cfgd = 1;
5cb5f4d0 13883 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 13884 }
05c7a1cc 13885 }
d62a17ae 13886 if (!af_cfgd)
13887 vty_out(vty, " none\n");
13888 else
13889 vty_out(vty, "\n");
13890
13891 /* Display listen ranges (for dynamic neighbors), if any */
13892 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13893 if (afi == AFI_IP)
13894 af_str = "IPv4";
13895 else if (afi == AFI_IP6)
13896 af_str = "IPv6";
13897 else
13898 af_str = "???";
13899 lr_count = listcount(group->listen_range[afi]);
13900 if (lr_count) {
13901 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13902 af_str);
13903
13904
13905 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13906 nnode, range)) {
13907 prefix2str(range, buf, sizeof(buf));
13908 vty_out(vty, " %s\n", buf);
13909 }
13910 }
13911 }
f14e6fdb 13912
d62a17ae 13913 /* Display group members and their status */
13914 if (listcount(group->peer)) {
13915 vty_out(vty, " Peer-group members:\n");
13916 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
13917 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
13918 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13919 peer_status = "Idle (Admin)";
13920 else if (CHECK_FLAG(peer->sflags,
13921 PEER_STATUS_PREFIX_OVERFLOW))
13922 peer_status = "Idle (PfxCt)";
13923 else
13924 peer_status = lookup_msg(bgp_status_msg,
13925 peer->status, NULL);
13926
13927 dynamic = peer_dynamic_neighbor(peer);
13928 vty_out(vty, " %s %s %s \n", peer->host,
13929 dynamic ? "(dynamic)" : "", peer_status);
13930 }
13931 }
f14e6fdb 13932
d62a17ae 13933 return CMD_SUCCESS;
13934}
13935
ff9959b0
QY
13936static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13937 const char *group_name)
d62a17ae 13938{
ff9959b0 13939 struct bgp *bgp;
d62a17ae 13940 struct listnode *node, *nnode;
13941 struct peer_group *group;
ff9959b0
QY
13942 bool found = false;
13943
13944 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13945
13946 if (!bgp) {
9f049418 13947 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
13948 return CMD_WARNING;
13949 }
d62a17ae 13950
13951 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
13952 if (group_name) {
13953 if (strmatch(group->name, group_name)) {
d62a17ae 13954 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
13955 found = true;
13956 break;
d62a17ae 13957 }
ff9959b0
QY
13958 } else {
13959 bgp_show_one_peer_group(vty, group);
d62a17ae 13960 }
f14e6fdb 13961 }
f14e6fdb 13962
ff9959b0 13963 if (group_name && !found)
d62a17ae 13964 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 13965
d62a17ae 13966 return CMD_SUCCESS;
f14e6fdb
DS
13967}
13968
f14e6fdb
DS
13969DEFUN (show_ip_bgp_peer_groups,
13970 show_ip_bgp_peer_groups_cmd,
18c57037 13971 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
13972 SHOW_STR
13973 IP_STR
13974 BGP_STR
8386ac43 13975 BGP_INSTANCE_HELP_STR
d6e3c605
QY
13976 "Detailed information on BGP peer groups\n"
13977 "Peer group name\n")
f14e6fdb 13978{
d62a17ae 13979 char *vrf, *pg;
d62a17ae 13980 int idx = 0;
f14e6fdb 13981
a4d82a8a
PZ
13982 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13983 : NULL;
d62a17ae 13984 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 13985
ff9959b0 13986 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 13987}
3f9c7369 13988
d6e3c605 13989
718e3744 13990/* Redistribute VTY commands. */
13991
718e3744 13992DEFUN (bgp_redistribute_ipv4,
13993 bgp_redistribute_ipv4_cmd,
40d1cbfb 13994 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 13995 "Redistribute information from another routing protocol\n"
ab0181ee 13996 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 13997{
d62a17ae 13998 VTY_DECLVAR_CONTEXT(bgp, bgp);
13999 int idx_protocol = 1;
14000 int type;
718e3744 14001
d62a17ae 14002 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14003 if (type < 0) {
14004 vty_out(vty, "%% Invalid route type\n");
14005 return CMD_WARNING_CONFIG_FAILED;
14006 }
7f323236 14007
d62a17ae 14008 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 14009 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 14010}
14011
d62a17ae 14012ALIAS_HIDDEN(
14013 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
14014 "redistribute " FRR_IP_REDIST_STR_BGPD,
14015 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 14016
718e3744 14017DEFUN (bgp_redistribute_ipv4_rmap,
14018 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 14019 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 14020 "Redistribute information from another routing protocol\n"
ab0181ee 14021 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14022 "Route map reference\n"
14023 "Pointer to route-map entries\n")
14024{
d62a17ae 14025 VTY_DECLVAR_CONTEXT(bgp, bgp);
14026 int idx_protocol = 1;
14027 int idx_word = 3;
14028 int type;
14029 struct bgp_redist *red;
e923dd62 14030 bool changed;
1de27621
DA
14031 struct route_map *route_map = route_map_lookup_warn_noexist(
14032 vty, argv[idx_word]->arg);
718e3744 14033
d62a17ae 14034 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14035 if (type < 0) {
14036 vty_out(vty, "%% Invalid route type\n");
14037 return CMD_WARNING_CONFIG_FAILED;
14038 }
718e3744 14039
d62a17ae 14040 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
14041 changed =
14042 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14043 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 14044}
14045
d62a17ae 14046ALIAS_HIDDEN(
14047 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
14048 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
14049 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14050 "Route map reference\n"
14051 "Pointer to route-map entries\n")
596c17ba 14052
718e3744 14053DEFUN (bgp_redistribute_ipv4_metric,
14054 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 14055 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 14056 "Redistribute information from another routing protocol\n"
ab0181ee 14057 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14058 "Metric for redistributed routes\n"
14059 "Default metric\n")
14060{
d62a17ae 14061 VTY_DECLVAR_CONTEXT(bgp, bgp);
14062 int idx_protocol = 1;
14063 int idx_number = 3;
14064 int type;
d7c0a89a 14065 uint32_t metric;
d62a17ae 14066 struct bgp_redist *red;
e923dd62 14067 bool changed;
d62a17ae 14068
14069 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14070 if (type < 0) {
14071 vty_out(vty, "%% Invalid route type\n");
14072 return CMD_WARNING_CONFIG_FAILED;
14073 }
14074 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14075
14076 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 14077 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
14078 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 14079}
14080
14081ALIAS_HIDDEN(
14082 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
14083 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
14084 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14085 "Metric for redistributed routes\n"
14086 "Default metric\n")
596c17ba 14087
718e3744 14088DEFUN (bgp_redistribute_ipv4_rmap_metric,
14089 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 14090 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 14091 "Redistribute information from another routing protocol\n"
ab0181ee 14092 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14093 "Route map reference\n"
14094 "Pointer to route-map entries\n"
14095 "Metric for redistributed routes\n"
14096 "Default metric\n")
14097{
d62a17ae 14098 VTY_DECLVAR_CONTEXT(bgp, bgp);
14099 int idx_protocol = 1;
14100 int idx_word = 3;
14101 int idx_number = 5;
14102 int type;
d7c0a89a 14103 uint32_t metric;
d62a17ae 14104 struct bgp_redist *red;
e923dd62 14105 bool changed;
1de27621
DA
14106 struct route_map *route_map =
14107 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14108
14109 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14110 if (type < 0) {
14111 vty_out(vty, "%% Invalid route type\n");
14112 return CMD_WARNING_CONFIG_FAILED;
14113 }
14114 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14115
14116 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
14117 changed =
14118 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14119 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
14120 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 14121}
14122
14123ALIAS_HIDDEN(
14124 bgp_redistribute_ipv4_rmap_metric,
14125 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
14126 "redistribute " FRR_IP_REDIST_STR_BGPD
14127 " route-map WORD metric (0-4294967295)",
14128 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14129 "Route map reference\n"
14130 "Pointer to route-map entries\n"
14131 "Metric for redistributed routes\n"
14132 "Default metric\n")
596c17ba 14133
718e3744 14134DEFUN (bgp_redistribute_ipv4_metric_rmap,
14135 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 14136 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 14137 "Redistribute information from another routing protocol\n"
ab0181ee 14138 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14139 "Metric for redistributed routes\n"
14140 "Default metric\n"
14141 "Route map reference\n"
14142 "Pointer to route-map entries\n")
14143{
d62a17ae 14144 VTY_DECLVAR_CONTEXT(bgp, bgp);
14145 int idx_protocol = 1;
14146 int idx_number = 3;
14147 int idx_word = 5;
14148 int type;
d7c0a89a 14149 uint32_t metric;
d62a17ae 14150 struct bgp_redist *red;
e923dd62 14151 bool changed;
1de27621
DA
14152 struct route_map *route_map =
14153 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14154
14155 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14156 if (type < 0) {
14157 vty_out(vty, "%% Invalid route type\n");
14158 return CMD_WARNING_CONFIG_FAILED;
14159 }
14160 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14161
14162 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 14163 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
14164 changed |=
14165 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14166 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 14167}
14168
14169ALIAS_HIDDEN(
14170 bgp_redistribute_ipv4_metric_rmap,
14171 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
14172 "redistribute " FRR_IP_REDIST_STR_BGPD
14173 " metric (0-4294967295) route-map WORD",
14174 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14175 "Metric for redistributed routes\n"
14176 "Default metric\n"
14177 "Route map reference\n"
14178 "Pointer to route-map entries\n")
596c17ba 14179
7c8ff89e
DS
14180DEFUN (bgp_redistribute_ipv4_ospf,
14181 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 14182 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
14183 "Redistribute information from another routing protocol\n"
14184 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14185 "Non-main Kernel Routing Table\n"
14186 "Instance ID/Table ID\n")
7c8ff89e 14187{
d62a17ae 14188 VTY_DECLVAR_CONTEXT(bgp, bgp);
14189 int idx_ospf_table = 1;
14190 int idx_number = 2;
d7c0a89a
QY
14191 unsigned short instance;
14192 unsigned short protocol;
7c8ff89e 14193
d62a17ae 14194 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 14195
d62a17ae 14196 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14197 protocol = ZEBRA_ROUTE_OSPF;
14198 else
14199 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 14200
d62a17ae 14201 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14202 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
14203}
14204
d62a17ae 14205ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
14206 "redistribute <ospf|table> (1-65535)",
14207 "Redistribute information from another routing protocol\n"
14208 "Open Shortest Path First (OSPFv2)\n"
14209 "Non-main Kernel Routing Table\n"
14210 "Instance ID/Table ID\n")
596c17ba 14211
7c8ff89e
DS
14212DEFUN (bgp_redistribute_ipv4_ospf_rmap,
14213 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 14214 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
14215 "Redistribute information from another routing protocol\n"
14216 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14217 "Non-main Kernel Routing Table\n"
14218 "Instance ID/Table ID\n"
7c8ff89e
DS
14219 "Route map reference\n"
14220 "Pointer to route-map entries\n")
14221{
d62a17ae 14222 VTY_DECLVAR_CONTEXT(bgp, bgp);
14223 int idx_ospf_table = 1;
14224 int idx_number = 2;
14225 int idx_word = 4;
14226 struct bgp_redist *red;
d7c0a89a 14227 unsigned short instance;
d62a17ae 14228 int protocol;
e923dd62 14229 bool changed;
1de27621
DA
14230 struct route_map *route_map =
14231 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14232
14233 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14234 protocol = ZEBRA_ROUTE_OSPF;
14235 else
14236 protocol = ZEBRA_ROUTE_TABLE;
14237
14238 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14239 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
14240 changed =
14241 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14242 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14243}
14244
14245ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
14246 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
14247 "redistribute <ospf|table> (1-65535) route-map WORD",
14248 "Redistribute information from another routing protocol\n"
14249 "Open Shortest Path First (OSPFv2)\n"
14250 "Non-main Kernel Routing Table\n"
14251 "Instance ID/Table ID\n"
14252 "Route map reference\n"
14253 "Pointer to route-map entries\n")
596c17ba 14254
7c8ff89e
DS
14255DEFUN (bgp_redistribute_ipv4_ospf_metric,
14256 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 14257 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
14258 "Redistribute information from another routing protocol\n"
14259 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14260 "Non-main Kernel Routing Table\n"
14261 "Instance ID/Table ID\n"
7c8ff89e
DS
14262 "Metric for redistributed routes\n"
14263 "Default metric\n")
14264{
d62a17ae 14265 VTY_DECLVAR_CONTEXT(bgp, bgp);
14266 int idx_ospf_table = 1;
14267 int idx_number = 2;
14268 int idx_number_2 = 4;
d7c0a89a 14269 uint32_t metric;
d62a17ae 14270 struct bgp_redist *red;
d7c0a89a 14271 unsigned short instance;
d62a17ae 14272 int protocol;
e923dd62 14273 bool changed;
d62a17ae 14274
14275 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14276 protocol = ZEBRA_ROUTE_OSPF;
14277 else
14278 protocol = ZEBRA_ROUTE_TABLE;
14279
14280 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14281 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14282
14283 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14284 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14285 metric);
14286 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14287}
14288
14289ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
14290 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
14291 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14292 "Redistribute information from another routing protocol\n"
14293 "Open Shortest Path First (OSPFv2)\n"
14294 "Non-main Kernel Routing Table\n"
14295 "Instance ID/Table ID\n"
14296 "Metric for redistributed routes\n"
14297 "Default metric\n")
596c17ba 14298
7c8ff89e
DS
14299DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
14300 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 14301 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
14302 "Redistribute information from another routing protocol\n"
14303 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14304 "Non-main Kernel Routing Table\n"
14305 "Instance ID/Table ID\n"
7c8ff89e
DS
14306 "Route map reference\n"
14307 "Pointer to route-map entries\n"
14308 "Metric for redistributed routes\n"
14309 "Default metric\n")
14310{
d62a17ae 14311 VTY_DECLVAR_CONTEXT(bgp, bgp);
14312 int idx_ospf_table = 1;
14313 int idx_number = 2;
14314 int idx_word = 4;
14315 int idx_number_2 = 6;
d7c0a89a 14316 uint32_t metric;
d62a17ae 14317 struct bgp_redist *red;
d7c0a89a 14318 unsigned short instance;
d62a17ae 14319 int protocol;
e923dd62 14320 bool changed;
1de27621
DA
14321 struct route_map *route_map =
14322 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14323
14324 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14325 protocol = ZEBRA_ROUTE_OSPF;
14326 else
14327 protocol = ZEBRA_ROUTE_TABLE;
14328
14329 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14330 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14331
14332 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
14333 changed =
14334 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14335 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14336 metric);
14337 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14338}
14339
14340ALIAS_HIDDEN(
14341 bgp_redistribute_ipv4_ospf_rmap_metric,
14342 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
14343 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14344 "Redistribute information from another routing protocol\n"
14345 "Open Shortest Path First (OSPFv2)\n"
14346 "Non-main Kernel Routing Table\n"
14347 "Instance ID/Table ID\n"
14348 "Route map reference\n"
14349 "Pointer to route-map entries\n"
14350 "Metric for redistributed routes\n"
14351 "Default metric\n")
596c17ba 14352
7c8ff89e
DS
14353DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
14354 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 14355 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
14356 "Redistribute information from another routing protocol\n"
14357 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14358 "Non-main Kernel Routing Table\n"
14359 "Instance ID/Table ID\n"
7c8ff89e
DS
14360 "Metric for redistributed routes\n"
14361 "Default metric\n"
14362 "Route map reference\n"
14363 "Pointer to route-map entries\n")
14364{
d62a17ae 14365 VTY_DECLVAR_CONTEXT(bgp, bgp);
14366 int idx_ospf_table = 1;
14367 int idx_number = 2;
14368 int idx_number_2 = 4;
14369 int idx_word = 6;
d7c0a89a 14370 uint32_t metric;
d62a17ae 14371 struct bgp_redist *red;
d7c0a89a 14372 unsigned short instance;
d62a17ae 14373 int protocol;
e923dd62 14374 bool changed;
1de27621
DA
14375 struct route_map *route_map =
14376 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14377
14378 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14379 protocol = ZEBRA_ROUTE_OSPF;
14380 else
14381 protocol = ZEBRA_ROUTE_TABLE;
14382
14383 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14384 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14385
14386 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14387 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14388 metric);
1de27621
DA
14389 changed |=
14390 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14391 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14392}
14393
14394ALIAS_HIDDEN(
14395 bgp_redistribute_ipv4_ospf_metric_rmap,
14396 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
14397 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14398 "Redistribute information from another routing protocol\n"
14399 "Open Shortest Path First (OSPFv2)\n"
14400 "Non-main Kernel Routing Table\n"
14401 "Instance ID/Table ID\n"
14402 "Metric for redistributed routes\n"
14403 "Default metric\n"
14404 "Route map reference\n"
14405 "Pointer to route-map entries\n")
596c17ba 14406
7c8ff89e
DS
14407DEFUN (no_bgp_redistribute_ipv4_ospf,
14408 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 14409 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
14410 NO_STR
14411 "Redistribute information from another routing protocol\n"
14412 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 14413 "Non-main Kernel Routing Table\n"
31500417
DW
14414 "Instance ID/Table ID\n"
14415 "Metric for redistributed routes\n"
14416 "Default metric\n"
14417 "Route map reference\n"
14418 "Pointer to route-map entries\n")
7c8ff89e 14419{
d62a17ae 14420 VTY_DECLVAR_CONTEXT(bgp, bgp);
14421 int idx_ospf_table = 2;
14422 int idx_number = 3;
d7c0a89a 14423 unsigned short instance;
d62a17ae 14424 int protocol;
14425
14426 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14427 protocol = ZEBRA_ROUTE_OSPF;
14428 else
14429 protocol = ZEBRA_ROUTE_TABLE;
14430
14431 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14432 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
14433}
14434
14435ALIAS_HIDDEN(
14436 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 14437 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14438 NO_STR
14439 "Redistribute information from another routing protocol\n"
14440 "Open Shortest Path First (OSPFv2)\n"
14441 "Non-main Kernel Routing Table\n"
14442 "Instance ID/Table ID\n"
14443 "Metric for redistributed routes\n"
14444 "Default metric\n"
14445 "Route map reference\n"
14446 "Pointer to route-map entries\n")
596c17ba 14447
718e3744 14448DEFUN (no_bgp_redistribute_ipv4,
14449 no_bgp_redistribute_ipv4_cmd,
e27957c0 14450 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14451 NO_STR
14452 "Redistribute information from another routing protocol\n"
3b14d86e 14453 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
14454 "Metric for redistributed routes\n"
14455 "Default metric\n"
14456 "Route map reference\n"
14457 "Pointer to route-map entries\n")
718e3744 14458{
d62a17ae 14459 VTY_DECLVAR_CONTEXT(bgp, bgp);
14460 int idx_protocol = 2;
14461 int type;
14462
14463 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14464 if (type < 0) {
14465 vty_out(vty, "%% Invalid route type\n");
14466 return CMD_WARNING_CONFIG_FAILED;
14467 }
14468 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
14469}
14470
14471ALIAS_HIDDEN(
14472 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
14473 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 14474 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14475 NO_STR
14476 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14477 "Metric for redistributed routes\n"
14478 "Default metric\n"
14479 "Route map reference\n"
14480 "Pointer to route-map entries\n")
596c17ba 14481
718e3744 14482DEFUN (bgp_redistribute_ipv6,
14483 bgp_redistribute_ipv6_cmd,
40d1cbfb 14484 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 14485 "Redistribute information from another routing protocol\n"
ab0181ee 14486 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 14487{
d62a17ae 14488 VTY_DECLVAR_CONTEXT(bgp, bgp);
14489 int idx_protocol = 1;
14490 int type;
718e3744 14491
d62a17ae 14492 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14493 if (type < 0) {
14494 vty_out(vty, "%% Invalid route type\n");
14495 return CMD_WARNING_CONFIG_FAILED;
14496 }
718e3744 14497
d62a17ae 14498 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14499 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 14500}
14501
14502DEFUN (bgp_redistribute_ipv6_rmap,
14503 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 14504 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 14505 "Redistribute information from another routing protocol\n"
ab0181ee 14506 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14507 "Route map reference\n"
14508 "Pointer to route-map entries\n")
14509{
d62a17ae 14510 VTY_DECLVAR_CONTEXT(bgp, bgp);
14511 int idx_protocol = 1;
14512 int idx_word = 3;
14513 int type;
14514 struct bgp_redist *red;
e923dd62 14515 bool changed;
1de27621
DA
14516 struct route_map *route_map =
14517 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 14518
d62a17ae 14519 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14520 if (type < 0) {
14521 vty_out(vty, "%% Invalid route type\n");
14522 return CMD_WARNING_CONFIG_FAILED;
14523 }
718e3744 14524
d62a17ae 14525 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14526 changed =
14527 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14528 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14529}
14530
14531DEFUN (bgp_redistribute_ipv6_metric,
14532 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 14533 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 14534 "Redistribute information from another routing protocol\n"
ab0181ee 14535 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14536 "Metric for redistributed routes\n"
14537 "Default metric\n")
14538{
d62a17ae 14539 VTY_DECLVAR_CONTEXT(bgp, bgp);
14540 int idx_protocol = 1;
14541 int idx_number = 3;
14542 int type;
d7c0a89a 14543 uint32_t metric;
d62a17ae 14544 struct bgp_redist *red;
e923dd62 14545 bool changed;
d62a17ae 14546
14547 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14548 if (type < 0) {
14549 vty_out(vty, "%% Invalid route type\n");
14550 return CMD_WARNING_CONFIG_FAILED;
14551 }
14552 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14553
d62a17ae 14554 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14555 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
14556 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14557}
14558
14559DEFUN (bgp_redistribute_ipv6_rmap_metric,
14560 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 14561 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 14562 "Redistribute information from another routing protocol\n"
ab0181ee 14563 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14564 "Route map reference\n"
14565 "Pointer to route-map entries\n"
14566 "Metric for redistributed routes\n"
14567 "Default metric\n")
14568{
d62a17ae 14569 VTY_DECLVAR_CONTEXT(bgp, bgp);
14570 int idx_protocol = 1;
14571 int idx_word = 3;
14572 int idx_number = 5;
14573 int type;
d7c0a89a 14574 uint32_t metric;
d62a17ae 14575 struct bgp_redist *red;
e923dd62 14576 bool changed;
1de27621
DA
14577 struct route_map *route_map =
14578 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14579
14580 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14581 if (type < 0) {
14582 vty_out(vty, "%% Invalid route type\n");
14583 return CMD_WARNING_CONFIG_FAILED;
14584 }
14585 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14586
d62a17ae 14587 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14588 changed =
14589 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14590 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
14591 metric);
14592 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14593}
14594
14595DEFUN (bgp_redistribute_ipv6_metric_rmap,
14596 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 14597 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 14598 "Redistribute information from another routing protocol\n"
ab0181ee 14599 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14600 "Metric for redistributed routes\n"
14601 "Default metric\n"
14602 "Route map reference\n"
14603 "Pointer to route-map entries\n")
14604{
d62a17ae 14605 VTY_DECLVAR_CONTEXT(bgp, bgp);
14606 int idx_protocol = 1;
14607 int idx_number = 3;
14608 int idx_word = 5;
14609 int type;
d7c0a89a 14610 uint32_t metric;
d62a17ae 14611 struct bgp_redist *red;
e923dd62 14612 bool changed;
1de27621
DA
14613 struct route_map *route_map =
14614 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14615
14616 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14617 if (type < 0) {
14618 vty_out(vty, "%% Invalid route type\n");
14619 return CMD_WARNING_CONFIG_FAILED;
14620 }
14621 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14622
d62a17ae 14623 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14624 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14625 metric);
1de27621
DA
14626 changed |=
14627 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14628 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14629}
14630
14631DEFUN (no_bgp_redistribute_ipv6,
14632 no_bgp_redistribute_ipv6_cmd,
e27957c0 14633 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14634 NO_STR
14635 "Redistribute information from another routing protocol\n"
3b14d86e 14636 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
14637 "Metric for redistributed routes\n"
14638 "Default metric\n"
14639 "Route map reference\n"
14640 "Pointer to route-map entries\n")
718e3744 14641{
d62a17ae 14642 VTY_DECLVAR_CONTEXT(bgp, bgp);
14643 int idx_protocol = 2;
14644 int type;
718e3744 14645
d62a17ae 14646 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14647 if (type < 0) {
14648 vty_out(vty, "%% Invalid route type\n");
14649 return CMD_WARNING_CONFIG_FAILED;
14650 }
718e3744 14651
d62a17ae 14652 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14653}
14654
dd65f45e
DL
14655static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14656 afi_t afi, safi_t safi)
d62a17ae 14657{
14658 int i;
14659
14660 /* Unicast redistribution only. */
14661 if (safi != SAFI_UNICAST)
2b791107 14662 return;
d62a17ae 14663
14664 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14665 /* Redistribute BGP does not make sense. */
14666 if (i != ZEBRA_ROUTE_BGP) {
14667 struct list *red_list;
14668 struct listnode *node;
14669 struct bgp_redist *red;
14670
14671 red_list = bgp->redist[afi][i];
14672 if (!red_list)
14673 continue;
14674
14675 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 14676 /* "redistribute" configuration. */
14677 vty_out(vty, " redistribute %s",
14678 zebra_route_string(i));
14679 if (red->instance)
14680 vty_out(vty, " %d", red->instance);
14681 if (red->redist_metric_flag)
14682 vty_out(vty, " metric %u",
14683 red->redist_metric);
14684 if (red->rmap.name)
14685 vty_out(vty, " route-map %s",
14686 red->rmap.name);
14687 vty_out(vty, "\n");
14688 }
14689 }
14690 }
718e3744 14691}
6b0655a2 14692
dd65f45e
DL
14693/* peer-group helpers for config-write */
14694
14695static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14696{
14697 if (!peer_group_active(peer)) {
14698 if (CHECK_FLAG(peer->flags_invert, flag))
14699 return !CHECK_FLAG(peer->flags, flag);
14700 else
14701 return !!CHECK_FLAG(peer->flags, flag);
14702 }
14703
14704 return !!CHECK_FLAG(peer->flags_override, flag);
14705}
14706
14707static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14708 uint32_t flag)
14709{
14710 if (!peer_group_active(peer)) {
14711 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14712 return !peer_af_flag_check(peer, afi, safi, flag);
14713 else
14714 return !!peer_af_flag_check(peer, afi, safi, flag);
14715 }
14716
14717 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14718}
14719
14720static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14721 uint8_t type, int direct)
14722{
14723 struct bgp_filter *filter;
14724
14725 if (peer_group_active(peer))
14726 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14727 type);
14728
14729 filter = &peer->filter[afi][safi];
14730 switch (type) {
14731 case PEER_FT_DISTRIBUTE_LIST:
14732 return !!(filter->dlist[direct].name);
14733 case PEER_FT_FILTER_LIST:
14734 return !!(filter->aslist[direct].name);
14735 case PEER_FT_PREFIX_LIST:
14736 return !!(filter->plist[direct].name);
14737 case PEER_FT_ROUTE_MAP:
14738 return !!(filter->map[direct].name);
14739 case PEER_FT_UNSUPPRESS_MAP:
14740 return !!(filter->usmap.name);
14741 default:
14742 return false;
14743 }
14744}
14745
14746/* Return true if the addpath type is set for peer and different from
14747 * peer-group.
14748 */
3dc339cd
DA
14749static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
14750 safi_t safi)
dd65f45e
DL
14751{
14752 enum bgp_addpath_strat type, g_type;
14753
14754 type = peer->addpath_type[afi][safi];
14755
14756 if (type != BGP_ADDPATH_NONE) {
14757 if (peer_group_active(peer)) {
14758 g_type = peer->group->conf->addpath_type[afi][safi];
14759
14760 if (type != g_type)
3dc339cd 14761 return true;
dd65f45e 14762 else
3dc339cd 14763 return false;
dd65f45e
DL
14764 }
14765
3dc339cd 14766 return true;
dd65f45e
DL
14767 }
14768
3dc339cd 14769 return false;
dd65f45e
DL
14770}
14771
b9c7bc5a 14772/* This is part of the address-family block (unicast only) */
dd65f45e 14773static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
14774 afi_t afi)
14775{
b9c7bc5a 14776 int indent = 2;
ddb5b488 14777
8a066a70 14778 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
14779 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14780 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
14781 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14782 bgp->vpn_policy[afi]
bb4f6190 14783 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
14784 else
14785 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14786 bgp->vpn_policy[afi]
14787 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14788 }
12a844a5
DS
14789 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14790 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14791 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14792 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14793 return;
14794
e70e9f8e
PZ
14795 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14796 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14797
14798 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14799
14800 } else {
14801 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14802 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14803 bgp->vpn_policy[afi].tovpn_label);
14804 }
ddb5b488
PZ
14805 }
14806 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14807 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14808 char buf[RD_ADDRSTRLEN];
b9c7bc5a 14809 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
14810 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14811 sizeof(buf)));
14812 }
14813 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14814 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14815
14816 char buf[PREFIX_STRLEN];
14817 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14818 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14819 sizeof(buf))) {
14820
b9c7bc5a
PZ
14821 vty_out(vty, "%*snexthop vpn export %s\n",
14822 indent, "", buf);
ddb5b488
PZ
14823 }
14824 }
14825 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14826 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14827 && ecommunity_cmp(
14828 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14829 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14830
14831 char *b = ecommunity_ecom2str(
14832 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14833 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14834 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
14835 XFREE(MTYPE_ECOMMUNITY_STR, b);
14836 } else {
14837 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14838 char *b = ecommunity_ecom2str(
14839 bgp->vpn_policy[afi]
14840 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14841 ECOMMUNITY_FORMAT_ROUTE_MAP,
14842 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14843 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
14844 XFREE(MTYPE_ECOMMUNITY_STR, b);
14845 }
14846 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14847 char *b = ecommunity_ecom2str(
14848 bgp->vpn_policy[afi]
14849 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14850 ECOMMUNITY_FORMAT_ROUTE_MAP,
14851 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14852 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
14853 XFREE(MTYPE_ECOMMUNITY_STR, b);
14854 }
14855 }
bb4f6190
DS
14856
14857 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 14858 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
14859 bgp->vpn_policy[afi]
14860 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 14861
301ad80a
PG
14862 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14863 char *b = ecommunity_ecom2str(
14864 bgp->vpn_policy[afi]
14865 .import_redirect_rtlist,
14866 ECOMMUNITY_FORMAT_ROUTE_MAP,
14867 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 14868
9a659715
PG
14869 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
14870 != ECOMMUNITY_SIZE)
c6423c31 14871 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
14872 indent, "", b);
14873 else
14874 vty_out(vty, "%*srt redirect import %s\n",
14875 indent, "", b);
301ad80a
PG
14876 XFREE(MTYPE_ECOMMUNITY_STR, b);
14877 }
ddb5b488
PZ
14878}
14879
dd65f45e
DL
14880static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14881 afi_t afi, safi_t safi)
14882{
14883 struct bgp_filter *filter;
14884 char *addr;
14885
14886 addr = peer->host;
14887 filter = &peer->filter[afi][safi];
14888
14889 /* distribute-list. */
14890 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14891 FILTER_IN))
14892 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14893 filter->dlist[FILTER_IN].name);
14894
14895 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14896 FILTER_OUT))
14897 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14898 filter->dlist[FILTER_OUT].name);
14899
14900 /* prefix-list. */
14901 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14902 FILTER_IN))
14903 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14904 filter->plist[FILTER_IN].name);
14905
14906 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14907 FILTER_OUT))
14908 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14909 filter->plist[FILTER_OUT].name);
14910
14911 /* route-map. */
14912 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14913 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14914 filter->map[RMAP_IN].name);
14915
14916 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14917 RMAP_OUT))
14918 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14919 filter->map[RMAP_OUT].name);
14920
14921 /* unsuppress-map */
14922 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14923 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14924 filter->usmap.name);
14925
14926 /* filter-list. */
14927 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14928 FILTER_IN))
14929 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14930 filter->aslist[FILTER_IN].name);
14931
14932 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14933 FILTER_OUT))
14934 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14935 filter->aslist[FILTER_OUT].name);
14936}
14937
14938/* BGP peer configuration display function. */
14939static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14940 struct peer *peer)
14941{
14942 struct peer *g_peer = NULL;
14943 char buf[SU_ADDRSTRLEN];
14944 char *addr;
14945 int if_pg_printed = false;
14946 int if_ras_printed = false;
14947
14948 /* Skip dynamic neighbors. */
14949 if (peer_dynamic_neighbor(peer))
14950 return;
14951
14952 if (peer->conf_if)
14953 addr = peer->conf_if;
14954 else
14955 addr = peer->host;
14956
14957 /************************************
14958 ****** Global to the neighbor ******
14959 ************************************/
14960 if (peer->conf_if) {
14961 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14962 vty_out(vty, " neighbor %s interface v6only", addr);
14963 else
14964 vty_out(vty, " neighbor %s interface", addr);
14965
14966 if (peer_group_active(peer)) {
14967 vty_out(vty, " peer-group %s", peer->group->name);
14968 if_pg_printed = true;
14969 } else if (peer->as_type == AS_SPECIFIED) {
14970 vty_out(vty, " remote-as %u", peer->as);
14971 if_ras_printed = true;
14972 } else if (peer->as_type == AS_INTERNAL) {
14973 vty_out(vty, " remote-as internal");
14974 if_ras_printed = true;
14975 } else if (peer->as_type == AS_EXTERNAL) {
14976 vty_out(vty, " remote-as external");
14977 if_ras_printed = true;
14978 }
14979
14980 vty_out(vty, "\n");
14981 }
14982
14983 /* remote-as and peer-group */
14984 /* peer is a member of a peer-group */
14985 if (peer_group_active(peer)) {
14986 g_peer = peer->group->conf;
14987
14988 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14989 if (peer->as_type == AS_SPECIFIED) {
14990 vty_out(vty, " neighbor %s remote-as %u\n",
14991 addr, peer->as);
14992 } else if (peer->as_type == AS_INTERNAL) {
14993 vty_out(vty,
14994 " neighbor %s remote-as internal\n",
14995 addr);
14996 } else if (peer->as_type == AS_EXTERNAL) {
14997 vty_out(vty,
14998 " neighbor %s remote-as external\n",
14999 addr);
15000 }
15001 }
15002
15003 /* For swpX peers we displayed the peer-group
15004 * via 'neighbor swpX interface peer-group PGNAME' */
15005 if (!if_pg_printed)
15006 vty_out(vty, " neighbor %s peer-group %s\n", addr,
15007 peer->group->name);
15008 }
15009
15010 /* peer is NOT a member of a peer-group */
15011 else {
15012 /* peer is a peer-group, declare the peer-group */
15013 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
15014 vty_out(vty, " neighbor %s peer-group\n", addr);
15015 }
15016
15017 if (!if_ras_printed) {
15018 if (peer->as_type == AS_SPECIFIED) {
15019 vty_out(vty, " neighbor %s remote-as %u\n",
15020 addr, peer->as);
15021 } else if (peer->as_type == AS_INTERNAL) {
15022 vty_out(vty,
15023 " neighbor %s remote-as internal\n",
15024 addr);
15025 } else if (peer->as_type == AS_EXTERNAL) {
15026 vty_out(vty,
15027 " neighbor %s remote-as external\n",
15028 addr);
15029 }
15030 }
15031 }
15032
15033 /* local-as */
15034 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
15035 vty_out(vty, " neighbor %s local-as %u", addr,
15036 peer->change_local_as);
15037 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
15038 vty_out(vty, " no-prepend");
15039 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
15040 vty_out(vty, " replace-as");
15041 vty_out(vty, "\n");
15042 }
15043
15044 /* description */
15045 if (peer->desc) {
15046 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
15047 }
15048
15049 /* shutdown */
15050 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
15051 if (peer->tx_shutdown_message)
15052 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
15053 peer->tx_shutdown_message);
15054 else
15055 vty_out(vty, " neighbor %s shutdown\n", addr);
15056 }
15057
8336c896
DA
15058 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
15059 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
15060 peer->rtt_expected, peer->rtt_keepalive_conf);
15061
dd65f45e
DL
15062 /* bfd */
15063 if (peer->bfd_info) {
15064 if (!peer_group_active(peer) || !g_peer->bfd_info) {
15065 bgp_bfd_peer_config_write(vty, peer, addr);
15066 }
15067 }
15068
15069 /* password */
15070 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
15071 vty_out(vty, " neighbor %s password %s\n", addr,
15072 peer->password);
15073
15074 /* neighbor solo */
15075 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
15076 if (!peer_group_active(peer)) {
15077 vty_out(vty, " neighbor %s solo\n", addr);
15078 }
15079 }
15080
15081 /* BGP port */
15082 if (peer->port != BGP_PORT_DEFAULT) {
15083 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
15084 }
15085
15086 /* Local interface name */
15087 if (peer->ifname) {
15088 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
15089 }
15090
15091 /* passive */
15092 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
15093 vty_out(vty, " neighbor %s passive\n", addr);
15094
15095 /* ebgp-multihop */
15096 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
15097 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
15098 && peer->ttl == MAXTTL)) {
dd65f45e
DL
15099 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
15100 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
15101 peer->ttl);
15102 }
15103 }
15104
15105 /* ttl-security hops */
e2521429 15106 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
15107 if (!peer_group_active(peer)
15108 || g_peer->gtsm_hops != peer->gtsm_hops) {
15109 vty_out(vty, " neighbor %s ttl-security hops %d\n",
15110 addr, peer->gtsm_hops);
15111 }
15112 }
15113
15114 /* disable-connected-check */
15115 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
15116 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
15117
15118 /* enforce-first-as */
15119 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
15120 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
15121
15122 /* update-source */
15123 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
15124 if (peer->update_source)
15125 vty_out(vty, " neighbor %s update-source %s\n", addr,
15126 sockunion2str(peer->update_source, buf,
15127 SU_ADDRSTRLEN));
15128 else if (peer->update_if)
15129 vty_out(vty, " neighbor %s update-source %s\n", addr,
15130 peer->update_if);
15131 }
15132
15133 /* advertisement-interval */
15134 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
15135 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
15136 peer->routeadv);
15137
15138 /* timers */
15139 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
15140 vty_out(vty, " neighbor %s timers %u %u\n", addr,
15141 peer->keepalive, peer->holdtime);
15142
15143 /* timers connect */
15144 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
15145 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15146 peer->connect);
5d5393b9
DL
15147 /* need special-case handling for changed default values due to
15148 * config profile / version (because there is no "timers bgp connect"
15149 * command, we need to save this per-peer :/)
15150 */
15151 else if (!peer_group_active(peer) && !peer->connect &&
15152 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
15153 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15154 peer->bgp->default_connect_retry);
dd65f45e
DL
15155
15156 /* capability dynamic */
15157 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
15158 vty_out(vty, " neighbor %s capability dynamic\n", addr);
15159
15160 /* capability extended-nexthop */
15161 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
15162 if (!peer->conf_if) {
15163 if (CHECK_FLAG(peer->flags_invert,
15164 PEER_FLAG_CAPABILITY_ENHE))
15165 vty_out(vty,
15166 " no neighbor %s capability extended-nexthop\n",
15167 addr);
15168 else
15169 vty_out(vty,
15170 " neighbor %s capability extended-nexthop\n",
15171 addr);
15172 }
15173 }
15174
15175 /* dont-capability-negotiation */
15176 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
15177 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
15178
15179 /* override-capability */
15180 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
15181 vty_out(vty, " neighbor %s override-capability\n", addr);
15182
15183 /* strict-capability-match */
15184 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
15185 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
15186
15187 /* Sender side AS path loop detection. */
15188 if (peer->as_path_loop_detection)
15189 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
15190 addr);
cfd47646 15191
15192 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 15193 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 15194
15195 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 15196 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 15197 vty_out(vty,
15198 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
15199 } else if (CHECK_FLAG(
15200 peer->peer_gr_new_status_flag,
15201 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 15202 vty_out(vty,
15203 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
15204 } else if (
15205 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
15206 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
15207 && !(CHECK_FLAG(
15208 peer->peer_gr_new_status_flag,
15209 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
15210 vty_out(vty, " neighbor %s graceful-restart-disable\n",
15211 addr);
cfd47646 15212 }
15213 }
dd65f45e
DL
15214}
15215
15216/* BGP peer configuration display function. */
15217static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
15218 struct peer *peer, afi_t afi, safi_t safi)
15219{
15220 struct peer *g_peer = NULL;
15221 char *addr;
15222 bool flag_scomm, flag_secomm, flag_slcomm;
15223
15224 /* Skip dynamic neighbors. */
15225 if (peer_dynamic_neighbor(peer))
15226 return;
15227
15228 if (peer->conf_if)
15229 addr = peer->conf_if;
15230 else
15231 addr = peer->host;
15232
15233 /************************************
15234 ****** Per AF to the neighbor ******
15235 ************************************/
15236 if (peer_group_active(peer)) {
15237 g_peer = peer->group->conf;
15238
15239 /* If the peer-group is active but peer is not, print a 'no
15240 * activate' */
15241 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
15242 vty_out(vty, " no neighbor %s activate\n", addr);
15243 }
15244
15245 /* If the peer-group is not active but peer is, print an
15246 'activate' */
15247 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
15248 vty_out(vty, " neighbor %s activate\n", addr);
15249 }
15250 } else {
15251 if (peer->afc[afi][safi]) {
15252 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
15253 if (CHECK_FLAG(bgp->flags,
15254 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
15255 vty_out(vty, " neighbor %s activate\n",
15256 addr);
15257 }
15258 } else
15259 vty_out(vty, " neighbor %s activate\n", addr);
15260 } else {
15261 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
15262 if (!CHECK_FLAG(bgp->flags,
15263 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
15264 vty_out(vty,
15265 " no neighbor %s activate\n",
15266 addr);
15267 }
15268 }
15269 }
15270 }
15271
15272 /* addpath TX knobs */
15273 if (peergroup_af_addpath_check(peer, afi, safi)) {
15274 switch (peer->addpath_type[afi][safi]) {
15275 case BGP_ADDPATH_ALL:
15276 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
15277 addr);
15278 break;
15279 case BGP_ADDPATH_BEST_PER_AS:
15280 vty_out(vty,
15281 " neighbor %s addpath-tx-bestpath-per-AS\n",
15282 addr);
15283 break;
15284 case BGP_ADDPATH_MAX:
15285 case BGP_ADDPATH_NONE:
15286 break;
15287 }
15288 }
15289
15290 /* ORF capability. */
15291 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
15292 || peergroup_af_flag_check(peer, afi, safi,
15293 PEER_FLAG_ORF_PREFIX_RM)) {
15294 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
15295
15296 if (peergroup_af_flag_check(peer, afi, safi,
15297 PEER_FLAG_ORF_PREFIX_SM)
15298 && peergroup_af_flag_check(peer, afi, safi,
15299 PEER_FLAG_ORF_PREFIX_RM))
15300 vty_out(vty, " both");
15301 else if (peergroup_af_flag_check(peer, afi, safi,
15302 PEER_FLAG_ORF_PREFIX_SM))
15303 vty_out(vty, " send");
15304 else
15305 vty_out(vty, " receive");
15306 vty_out(vty, "\n");
15307 }
15308
dd65f45e
DL
15309 /* Route reflector client. */
15310 if (peergroup_af_flag_check(peer, afi, safi,
15311 PEER_FLAG_REFLECTOR_CLIENT)) {
15312 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
15313 }
15314
15315 /* next-hop-self force */
15316 if (peergroup_af_flag_check(peer, afi, safi,
15317 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
15318 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
15319 }
15320
15321 /* next-hop-self */
15322 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
15323 vty_out(vty, " neighbor %s next-hop-self\n", addr);
15324 }
15325
15326 /* remove-private-AS */
15327 if (peergroup_af_flag_check(peer, afi, safi,
15328 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
15329 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
15330 addr);
15331 }
15332
15333 else if (peergroup_af_flag_check(peer, afi, safi,
15334 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
15335 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
15336 addr);
15337 }
15338
15339 else if (peergroup_af_flag_check(peer, afi, safi,
15340 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
15341 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
15342 }
15343
15344 else if (peergroup_af_flag_check(peer, afi, safi,
15345 PEER_FLAG_REMOVE_PRIVATE_AS)) {
15346 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
15347 }
15348
15349 /* as-override */
15350 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
15351 vty_out(vty, " neighbor %s as-override\n", addr);
15352 }
15353
15354 /* send-community print. */
15355 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
15356 PEER_FLAG_SEND_COMMUNITY);
15357 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
15358 PEER_FLAG_SEND_EXT_COMMUNITY);
15359 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
15360 PEER_FLAG_SEND_LARGE_COMMUNITY);
15361
15362 if (flag_scomm && flag_secomm && flag_slcomm) {
15363 vty_out(vty, " no neighbor %s send-community all\n", addr);
15364 } else {
15365 if (flag_scomm)
15366 vty_out(vty, " no neighbor %s send-community\n", addr);
15367 if (flag_secomm)
15368 vty_out(vty,
15369 " no neighbor %s send-community extended\n",
15370 addr);
15371
15372 if (flag_slcomm)
15373 vty_out(vty, " no neighbor %s send-community large\n",
15374 addr);
15375 }
15376
15377 /* Default information */
15378 if (peergroup_af_flag_check(peer, afi, safi,
15379 PEER_FLAG_DEFAULT_ORIGINATE)) {
15380 vty_out(vty, " neighbor %s default-originate", addr);
15381
15382 if (peer->default_rmap[afi][safi].name)
15383 vty_out(vty, " route-map %s",
15384 peer->default_rmap[afi][safi].name);
15385
15386 vty_out(vty, "\n");
15387 }
15388
15389 /* Soft reconfiguration inbound. */
15390 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
15391 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
15392 addr);
15393 }
15394
15395 /* maximum-prefix. */
15396 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 15397 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
15398 peer->pmax[afi][safi]);
15399
15400 if (peer->pmax_threshold[afi][safi]
15401 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
15402 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
15403 if (peer_af_flag_check(peer, afi, safi,
15404 PEER_FLAG_MAX_PREFIX_WARNING))
15405 vty_out(vty, " warning-only");
15406 if (peer->pmax_restart[afi][safi])
15407 vty_out(vty, " restart %u",
15408 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
15409 if (peer_af_flag_check(peer, afi, safi,
15410 PEER_FLAG_MAX_PREFIX_FORCE))
15411 vty_out(vty, " force");
dd65f45e
DL
15412
15413 vty_out(vty, "\n");
15414 }
15415
fde246e8
DA
15416 /* maximum-prefix-out */
15417 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 15418 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
15419 addr, peer->pmax_out[afi][safi]);
15420
dd65f45e
DL
15421 /* Route server client. */
15422 if (peergroup_af_flag_check(peer, afi, safi,
15423 PEER_FLAG_RSERVER_CLIENT)) {
15424 vty_out(vty, " neighbor %s route-server-client\n", addr);
15425 }
15426
15427 /* Nexthop-local unchanged. */
15428 if (peergroup_af_flag_check(peer, afi, safi,
15429 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
15430 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
15431 }
15432
15433 /* allowas-in <1-10> */
15434 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
15435 if (peer_af_flag_check(peer, afi, safi,
15436 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
15437 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
15438 } else if (peer->allowas_in[afi][safi] == 3) {
15439 vty_out(vty, " neighbor %s allowas-in\n", addr);
15440 } else {
15441 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
15442 peer->allowas_in[afi][safi]);
15443 }
15444 }
15445
15446 /* weight */
15447 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
15448 vty_out(vty, " neighbor %s weight %lu\n", addr,
15449 peer->weight[afi][safi]);
15450
15451 /* Filter. */
15452 bgp_config_write_filter(vty, peer, afi, safi);
15453
15454 /* atribute-unchanged. */
15455 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
15456 || (safi != SAFI_EVPN
15457 && peer_af_flag_check(peer, afi, safi,
15458 PEER_FLAG_NEXTHOP_UNCHANGED))
15459 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
15460
15461 if (!peer_group_active(peer)
15462 || peergroup_af_flag_check(peer, afi, safi,
15463 PEER_FLAG_AS_PATH_UNCHANGED)
15464 || peergroup_af_flag_check(peer, afi, safi,
15465 PEER_FLAG_NEXTHOP_UNCHANGED)
15466 || peergroup_af_flag_check(peer, afi, safi,
15467 PEER_FLAG_MED_UNCHANGED)) {
15468
15469 vty_out(vty,
15470 " neighbor %s attribute-unchanged%s%s%s\n",
15471 addr,
15472 peer_af_flag_check(peer, afi, safi,
15473 PEER_FLAG_AS_PATH_UNCHANGED)
15474 ? " as-path"
15475 : "",
15476 peer_af_flag_check(peer, afi, safi,
15477 PEER_FLAG_NEXTHOP_UNCHANGED)
15478 ? " next-hop"
15479 : "",
15480 peer_af_flag_check(peer, afi, safi,
15481 PEER_FLAG_MED_UNCHANGED)
15482 ? " med"
15483 : "");
15484 }
15485 }
15486}
15487
15488/* Address family based peer configuration display. */
15489static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
15490 safi_t safi)
15491{
15492 struct peer *peer;
15493 struct peer_group *group;
15494 struct listnode *node, *nnode;
15495
15496
15497 vty_frame(vty, " !\n address-family ");
15498 if (afi == AFI_IP) {
15499 if (safi == SAFI_UNICAST)
15500 vty_frame(vty, "ipv4 unicast");
15501 else if (safi == SAFI_LABELED_UNICAST)
15502 vty_frame(vty, "ipv4 labeled-unicast");
15503 else if (safi == SAFI_MULTICAST)
15504 vty_frame(vty, "ipv4 multicast");
15505 else if (safi == SAFI_MPLS_VPN)
15506 vty_frame(vty, "ipv4 vpn");
15507 else if (safi == SAFI_ENCAP)
15508 vty_frame(vty, "ipv4 encap");
15509 else if (safi == SAFI_FLOWSPEC)
15510 vty_frame(vty, "ipv4 flowspec");
15511 } else if (afi == AFI_IP6) {
15512 if (safi == SAFI_UNICAST)
15513 vty_frame(vty, "ipv6 unicast");
15514 else if (safi == SAFI_LABELED_UNICAST)
15515 vty_frame(vty, "ipv6 labeled-unicast");
15516 else if (safi == SAFI_MULTICAST)
15517 vty_frame(vty, "ipv6 multicast");
15518 else if (safi == SAFI_MPLS_VPN)
15519 vty_frame(vty, "ipv6 vpn");
15520 else if (safi == SAFI_ENCAP)
15521 vty_frame(vty, "ipv6 encap");
15522 else if (safi == SAFI_FLOWSPEC)
15523 vty_frame(vty, "ipv6 flowspec");
15524 } else if (afi == AFI_L2VPN) {
15525 if (safi == SAFI_EVPN)
15526 vty_frame(vty, "l2vpn evpn");
15527 }
15528 vty_frame(vty, "\n");
15529
15530 bgp_config_write_distance(vty, bgp, afi, safi);
15531
15532 bgp_config_write_network(vty, bgp, afi, safi);
15533
15534 bgp_config_write_redistribute(vty, bgp, afi, safi);
15535
8a4e7fe6
DA
15536 /* BGP flag dampening. */
15537 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
15538 bgp_config_write_damp(vty, afi, safi);
15539
dd65f45e
DL
15540 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
15541 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
15542
15543 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15544 /* Skip dynamic neighbors. */
15545 if (peer_dynamic_neighbor(peer))
15546 continue;
15547
15548 /* Do not display doppelganger peers */
15549 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15550 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
15551 }
15552
15553 bgp_config_write_maxpaths(vty, bgp, afi, safi);
15554 bgp_config_write_table_map(vty, bgp, afi, safi);
15555
15556 if (safi == SAFI_EVPN)
15557 bgp_config_write_evpn_info(vty, bgp, afi, safi);
15558
15559 if (safi == SAFI_FLOWSPEC)
15560 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
15561
15562 if (safi == SAFI_UNICAST) {
15563 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
15564 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15565 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
15566
15567 vty_out(vty, " export vpn\n");
15568 }
15569 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15570 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
15571
15572 vty_out(vty, " import vpn\n");
15573 }
15574 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15575 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15576 char *name;
15577
15578 for (ALL_LIST_ELEMENTS_RO(
15579 bgp->vpn_policy[afi].import_vrf, node,
15580 name))
15581 vty_out(vty, " import vrf %s\n", name);
15582 }
15583 }
15584
15585 vty_endframe(vty, " exit-address-family\n");
15586}
15587
15588int bgp_config_write(struct vty *vty)
15589{
15590 struct bgp *bgp;
15591 struct peer_group *group;
15592 struct peer *peer;
15593 struct listnode *node, *nnode;
15594 struct listnode *mnode, *mnnode;
15595
15596 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
15597 vty_out(vty, "bgp route-map delay-timer %u\n",
15598 bm->rmap_update_timer);
15599
d70583f7
D
15600 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
15601 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
15602 if (bm->v_update_delay != bm->v_establish_wait)
15603 vty_out(vty, " %d", bm->v_establish_wait);
15604 vty_out(vty, "\n");
15605 }
15606
05bd726c 15607 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
15608 vty_out(vty, "bgp graceful-shutdown\n");
15609
dd65f45e
DL
15610 /* BGP configuration. */
15611 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
15612
15613 /* skip all auto created vrf as they dont have user config */
15614 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
15615 continue;
15616
15617 /* Router bgp ASN */
15618 vty_out(vty, "router bgp %u", bgp->as);
15619
15620 if (bgp->name)
15621 vty_out(vty, " %s %s",
15622 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
15623 ? "view" : "vrf", bgp->name);
15624 vty_out(vty, "\n");
15625
15626 /* BGP fast-external-failover. */
15627 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
15628 vty_out(vty, " no bgp fast-external-failover\n");
15629
15630 /* BGP router ID. */
15631 if (bgp->router_id_static.s_addr != 0)
15632 vty_out(vty, " bgp router-id %s\n",
15633 inet_ntoa(bgp->router_id_static));
15634
15635 /* BGP log-neighbor-changes. */
892fedb6 15636 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 15637 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 15638 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
15639 CHECK_FLAG(bgp->flags,
15640 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
15641 ? ""
15642 : "no ");
15643
15644 /* BGP configuration. */
892fedb6 15645 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
15646 vty_out(vty, " bgp always-compare-med\n");
15647
15648 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
15649 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
15650 != SAVE_BGP_EBGP_REQUIRES_POLICY)
15651 vty_out(vty, " %sbgp ebgp-requires-policy\n",
15652 CHECK_FLAG(bgp->flags,
15653 BGP_FLAG_EBGP_REQUIRES_POLICY)
15654 ? ""
15655 : "no ");
dd65f45e
DL
15656
15657 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 15658 if (bgp->reject_as_sets)
dd65f45e
DL
15659 vty_out(vty, " bgp reject-as-sets\n");
15660
15661 /* BGP default ipv4-unicast. */
892fedb6 15662 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
15663 vty_out(vty, " no bgp default ipv4-unicast\n");
15664
15665 /* BGP default local-preference. */
15666 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15667 vty_out(vty, " bgp default local-preference %u\n",
15668 bgp->default_local_pref);
15669
15670 /* BGP default show-hostname */
892fedb6 15671 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 15672 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 15673 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 15674 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
15675 ? ""
15676 : "no ");
15677
aef999a2
DA
15678 /* BGP default show-nexthop-hostname */
15679 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15680 != SAVE_BGP_SHOW_HOSTNAME)
15681 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
15682 CHECK_FLAG(bgp->flags,
15683 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15684 ? ""
15685 : "no ");
15686
dd65f45e
DL
15687 /* BGP default subgroup-pkt-queue-max. */
15688 if (bgp->default_subgroup_pkt_queue_max
15689 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15690 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15691 bgp->default_subgroup_pkt_queue_max);
15692
15693 /* BGP client-to-client reflection. */
892fedb6 15694 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
15695 vty_out(vty, " no bgp client-to-client reflection\n");
15696
15697 /* BGP cluster ID. */
15698 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15699 vty_out(vty, " bgp cluster-id %s\n",
15700 inet_ntoa(bgp->cluster_id));
15701
15702 /* Disable ebgp connected nexthop check */
892fedb6 15703 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
15704 vty_out(vty,
15705 " bgp disable-ebgp-connected-route-check\n");
15706
15707 /* Confederation identifier*/
15708 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15709 vty_out(vty, " bgp confederation identifier %u\n",
15710 bgp->confed_id);
15711
15712 /* Confederation peer */
15713 if (bgp->confed_peers_cnt > 0) {
15714 int i;
15715
15716 vty_out(vty, " bgp confederation peers");
15717
15718 for (i = 0; i < bgp->confed_peers_cnt; i++)
15719 vty_out(vty, " %u", bgp->confed_peers[i]);
15720
15721 vty_out(vty, "\n");
15722 }
15723
15724 /* BGP deterministic-med. */
892fedb6 15725 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 15726 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 15727 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
15728 CHECK_FLAG(bgp->flags,
15729 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
15730 ? ""
15731 : "no ");
15732
15733 /* BGP update-delay. */
15734 bgp_config_write_update_delay(vty, bgp);
15735
15736 if (bgp->v_maxmed_onstartup
15737 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15738 vty_out(vty, " bgp max-med on-startup %u",
15739 bgp->v_maxmed_onstartup);
15740 if (bgp->maxmed_onstartup_value
15741 != BGP_MAXMED_VALUE_DEFAULT)
15742 vty_out(vty, " %u",
15743 bgp->maxmed_onstartup_value);
15744 vty_out(vty, "\n");
15745 }
15746 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15747 vty_out(vty, " bgp max-med administrative");
15748 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15749 vty_out(vty, " %u", bgp->maxmed_admin_value);
15750 vty_out(vty, "\n");
15751 }
15752
15753 /* write quanta */
15754 bgp_config_write_wpkt_quanta(vty, bgp);
15755 /* read quanta */
15756 bgp_config_write_rpkt_quanta(vty, bgp);
15757
15758 /* coalesce time */
15759 bgp_config_write_coalesce_time(vty, bgp);
15760
05bd726c 15761 /* BGP per-instance graceful-shutdown */
15762 /* BGP-wide settings and per-instance settings are mutually
15763 * exclusive.
15764 */
15765 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
15766 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
15767 vty_out(vty, " bgp graceful-shutdown\n");
15768
dd65f45e
DL
15769 /* BGP graceful-restart. */
15770 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15771 vty_out(vty,
15772 " bgp graceful-restart stalepath-time %u\n",
15773 bgp->stalepath_time);
cfd47646 15774
dd65f45e
DL
15775 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15776 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15777 bgp->restart_time);
cfd47646 15778
15779 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15780 vty_out(vty,
15781 " bgp graceful-restart select-defer-time %u\n",
15782 bgp->select_defer_time);
15783
15784 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
15785 vty_out(vty, " bgp graceful-restart\n");
15786
cfd47646 15787 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15788 vty_out(vty, " bgp graceful-restart-disable\n");
15789
dd65f45e 15790 /* BGP graceful-restart Preserve State F bit. */
892fedb6 15791 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
15792 vty_out(vty,
15793 " bgp graceful-restart preserve-fw-state\n");
15794
dc95985f 15795 /* Stale timer for RIB */
15796 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15797 vty_out(vty,
15798 " bgp graceful-restart rib-stale-time %u\n",
15799 bgp->rib_stale_time);
15800
dd65f45e 15801 /* BGP bestpath method. */
892fedb6 15802 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 15803 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 15804 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
15805 vty_out(vty, " bgp bestpath as-path confed\n");
15806
892fedb6
DA
15807 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15808 if (CHECK_FLAG(bgp->flags,
15809 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
15810 vty_out(vty,
15811 " bgp bestpath as-path multipath-relax as-set\n");
15812 } else {
15813 vty_out(vty,
15814 " bgp bestpath as-path multipath-relax\n");
15815 }
15816 }
15817
892fedb6 15818 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
15819 vty_out(vty,
15820 " bgp route-reflector allow-outbound-policy\n");
15821 }
892fedb6 15822 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 15823 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
15824 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
15825 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 15826 vty_out(vty, " bgp bestpath med");
892fedb6 15827 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 15828 vty_out(vty, " confed");
892fedb6
DA
15829 if (CHECK_FLAG(bgp->flags,
15830 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
15831 vty_out(vty, " missing-as-worst");
15832 vty_out(vty, "\n");
15833 }
15834
f7e1c681 15835 /* Link bandwidth handling. */
15836 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
15837 vty_out(vty, " bgp bestpath bandwidth ignore\n");
15838 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
15839 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
15840 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
15841 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
15842
dd65f45e 15843 /* BGP network import check. */
892fedb6 15844 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 15845 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 15846 vty_out(vty, " %sbgp network import-check\n",
892fedb6 15847 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
15848 ? ""
15849 : "no ");
15850
15851 /* BGP timers configuration. */
5d5393b9
DL
15852 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15853 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
15854 vty_out(vty, " timers bgp %u %u\n",
15855 bgp->default_keepalive, bgp->default_holdtime);
15856
15857 /* peer-group */
15858 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15859 bgp_config_write_peer_global(vty, bgp, group->conf);
15860 }
15861
15862 /* Normal neighbor configuration. */
15863 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15864 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15865 bgp_config_write_peer_global(vty, bgp, peer);
15866 }
15867
15868 /* listen range and limit for dynamic BGP neighbors */
15869 bgp_config_write_listen(vty, bgp);
15870
15871 /*
15872 * BGP default autoshutdown neighbors
15873 *
15874 * This must be placed after any peer and peer-group
15875 * configuration, to avoid setting all peers to shutdown after
15876 * a daemon restart, which is undesired behavior. (see #2286)
15877 */
15878 if (bgp->autoshutdown)
15879 vty_out(vty, " bgp default shutdown\n");
15880
9cf59432
DS
15881 /* BGP instance administrative shutdown */
15882 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
15883 vty_out(vty, " bgp shutdown\n");
15884
dd65f45e
DL
15885 /* IPv4 unicast configuration. */
15886 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15887
15888 /* IPv4 multicast configuration. */
15889 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15890
15891 /* IPv4 labeled-unicast configuration. */
15892 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15893
15894 /* IPv4 VPN configuration. */
15895 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15896
15897 /* ENCAPv4 configuration. */
15898 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15899
15900 /* FLOWSPEC v4 configuration. */
15901 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15902
15903 /* IPv6 unicast configuration. */
15904 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15905
15906 /* IPv6 multicast configuration. */
15907 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15908
15909 /* IPv6 labeled-unicast configuration. */
15910 bgp_config_write_family(vty, bgp, AFI_IP6,
15911 SAFI_LABELED_UNICAST);
15912
15913 /* IPv6 VPN configuration. */
15914 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15915
15916 /* ENCAPv6 configuration. */
15917 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15918
15919 /* FLOWSPEC v6 configuration. */
15920 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15921
15922 /* EVPN configuration. */
15923 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15924
15925 hook_call(bgp_inst_config_write, bgp, vty);
15926
49e5a4a0 15927#ifdef ENABLE_BGP_VNC
dd65f45e
DL
15928 bgp_rfapi_cfg_write(vty, bgp);
15929#endif
15930
15931 vty_out(vty, "!\n");
15932 }
15933 return 0;
15934}
15935
ddb5b488 15936
718e3744 15937/* BGP node structure. */
d62a17ae 15938static struct cmd_node bgp_node = {
f4b8291f 15939 .name = "bgp",
62b346ee 15940 .node = BGP_NODE,
24389580 15941 .parent_node = CONFIG_NODE,
62b346ee 15942 .prompt = "%s(config-router)# ",
612c2c15 15943 .config_write = bgp_config_write,
718e3744 15944};
15945
d62a17ae 15946static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 15947 .name = "bgp ipv4 unicast",
62b346ee 15948 .node = BGP_IPV4_NODE,
24389580 15949 .parent_node = BGP_NODE,
62b346ee 15950 .prompt = "%s(config-router-af)# ",
718e3744 15951};
15952
d62a17ae 15953static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 15954 .name = "bgp ipv4 multicast",
62b346ee 15955 .node = BGP_IPV4M_NODE,
24389580 15956 .parent_node = BGP_NODE,
62b346ee 15957 .prompt = "%s(config-router-af)# ",
718e3744 15958};
15959
d62a17ae 15960static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 15961 .name = "bgp ipv4 labeled unicast",
62b346ee 15962 .node = BGP_IPV4L_NODE,
24389580 15963 .parent_node = BGP_NODE,
62b346ee 15964 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
15965};
15966
d62a17ae 15967static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 15968 .name = "bgp ipv6",
62b346ee 15969 .node = BGP_IPV6_NODE,
24389580 15970 .parent_node = BGP_NODE,
62b346ee 15971 .prompt = "%s(config-router-af)# ",
718e3744 15972};
15973
d62a17ae 15974static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 15975 .name = "bgp ipv6 multicast",
62b346ee 15976 .node = BGP_IPV6M_NODE,
24389580 15977 .parent_node = BGP_NODE,
62b346ee 15978 .prompt = "%s(config-router-af)# ",
25ffbdc1 15979};
15980
d62a17ae 15981static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 15982 .name = "bgp ipv6 labeled unicast",
62b346ee 15983 .node = BGP_IPV6L_NODE,
24389580 15984 .parent_node = BGP_NODE,
62b346ee 15985 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
15986};
15987
62b346ee 15988static struct cmd_node bgp_vpnv4_node = {
f4b8291f 15989 .name = "bgp vpnv4",
62b346ee 15990 .node = BGP_VPNV4_NODE,
24389580 15991 .parent_node = BGP_NODE,
62b346ee 15992 .prompt = "%s(config-router-af)# ",
62b346ee 15993};
6b0655a2 15994
62b346ee 15995static struct cmd_node bgp_vpnv6_node = {
f4b8291f 15996 .name = "bgp vpnv6",
62b346ee 15997 .node = BGP_VPNV6_NODE,
24389580 15998 .parent_node = BGP_NODE,
62b346ee 15999 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 16000};
8ecd3266 16001
62b346ee 16002static struct cmd_node bgp_evpn_node = {
f4b8291f 16003 .name = "bgp evpn",
62b346ee 16004 .node = BGP_EVPN_NODE,
24389580 16005 .parent_node = BGP_NODE,
62b346ee 16006 .prompt = "%s(config-router-evpn)# ",
62b346ee 16007};
4e0b7b6d 16008
62b346ee 16009static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 16010 .name = "bgp evpn vni",
62b346ee 16011 .node = BGP_EVPN_VNI_NODE,
24389580 16012 .parent_node = BGP_EVPN_NODE,
62b346ee 16013 .prompt = "%s(config-router-af-vni)# ",
62b346ee 16014};
90e60aa7 16015
62b346ee 16016static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 16017 .name = "bgp ipv4 flowspec",
62b346ee 16018 .node = BGP_FLOWSPECV4_NODE,
24389580 16019 .parent_node = BGP_NODE,
62b346ee 16020 .prompt = "%s(config-router-af)# ",
62b346ee 16021};
7c40bf39 16022
62b346ee 16023static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 16024 .name = "bgp ipv6 flowspec",
62b346ee 16025 .node = BGP_FLOWSPECV6_NODE,
24389580 16026 .parent_node = BGP_NODE,
62b346ee 16027 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 16028};
7c40bf39 16029
d62a17ae 16030static void community_list_vty(void);
1f8ae70b 16031
d62a17ae 16032static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 16033{
d62a17ae 16034 struct bgp *bgp;
16035 struct peer *peer;
d62a17ae 16036 struct listnode *lnbgp, *lnpeer;
b8a815e5 16037
d62a17ae 16038 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16039 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
16040 /* only provide suggestions on the appropriate input
16041 * token type,
16042 * they'll otherwise show up multiple times */
16043 enum cmd_token_type match_type;
16044 char *name = peer->host;
d48ed3e0 16045
d62a17ae 16046 if (peer->conf_if) {
16047 match_type = VARIABLE_TKN;
16048 name = peer->conf_if;
16049 } else if (strchr(peer->host, ':'))
16050 match_type = IPV6_TKN;
16051 else
16052 match_type = IPV4_TKN;
d48ed3e0 16053
d62a17ae 16054 if (token->type != match_type)
16055 continue;
d48ed3e0 16056
d62a17ae 16057 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
16058 }
d62a17ae 16059 }
b8a815e5
DL
16060}
16061
16062static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 16063 {.varname = "neighbor", .completions = bgp_ac_neighbor},
16064 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 16065 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 16066 {.completions = NULL}};
16067
47a306a0
DS
16068static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
16069{
16070 struct bgp *bgp;
16071 struct peer_group *group;
16072 struct listnode *lnbgp, *lnpeer;
16073
16074 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16075 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
16076 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
16077 group->name));
16078 }
16079}
16080
16081static const struct cmd_variable_handler bgp_var_peergroup[] = {
16082 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
16083 {.completions = NULL} };
16084
d62a17ae 16085void bgp_vty_init(void)
16086{
16087 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 16088 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 16089
16090 /* Install bgp top node. */
612c2c15
DL
16091 install_node(&bgp_node);
16092 install_node(&bgp_ipv4_unicast_node);
16093 install_node(&bgp_ipv4_multicast_node);
16094 install_node(&bgp_ipv4_labeled_unicast_node);
16095 install_node(&bgp_ipv6_unicast_node);
16096 install_node(&bgp_ipv6_multicast_node);
16097 install_node(&bgp_ipv6_labeled_unicast_node);
16098 install_node(&bgp_vpnv4_node);
16099 install_node(&bgp_vpnv6_node);
16100 install_node(&bgp_evpn_node);
16101 install_node(&bgp_evpn_vni_node);
16102 install_node(&bgp_flowspecv4_node);
16103 install_node(&bgp_flowspecv6_node);
d62a17ae 16104
16105 /* Install default VTY commands to new nodes. */
16106 install_default(BGP_NODE);
16107 install_default(BGP_IPV4_NODE);
16108 install_default(BGP_IPV4M_NODE);
16109 install_default(BGP_IPV4L_NODE);
16110 install_default(BGP_IPV6_NODE);
16111 install_default(BGP_IPV6M_NODE);
16112 install_default(BGP_IPV6L_NODE);
16113 install_default(BGP_VPNV4_NODE);
16114 install_default(BGP_VPNV6_NODE);
7c40bf39 16115 install_default(BGP_FLOWSPECV4_NODE);
16116 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 16117 install_default(BGP_EVPN_NODE);
16118 install_default(BGP_EVPN_VNI_NODE);
16119
8029b216
AK
16120 /* "bgp local-mac" hidden commands. */
16121 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
16122 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
16123
d62a17ae 16124 /* bgp route-map delay-timer commands. */
16125 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
16126 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16127
d70583f7
D
16128 /* global bgp update-delay command */
16129 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
16130 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
16131
05bd726c 16132 /* global bgp graceful-shutdown command */
16133 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
16134 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
16135
d62a17ae 16136 /* Dummy commands (Currently not supported) */
16137 install_element(BGP_NODE, &no_synchronization_cmd);
16138 install_element(BGP_NODE, &no_auto_summary_cmd);
16139
16140 /* "router bgp" commands. */
16141 install_element(CONFIG_NODE, &router_bgp_cmd);
16142
16143 /* "no router bgp" commands. */
16144 install_element(CONFIG_NODE, &no_router_bgp_cmd);
16145
16146 /* "bgp router-id" commands. */
16147 install_element(BGP_NODE, &bgp_router_id_cmd);
16148 install_element(BGP_NODE, &no_bgp_router_id_cmd);
16149
16150 /* "bgp cluster-id" commands. */
16151 install_element(BGP_NODE, &bgp_cluster_id_cmd);
16152 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
16153
16154 /* "bgp confederation" commands. */
16155 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
16156 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
16157
16158 /* "bgp confederation peers" commands. */
16159 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
16160 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
16161
16162 /* bgp max-med command */
16163 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
16164 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
16165 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
16166 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
16167 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
16168
16169 /* bgp disable-ebgp-connected-nh-check */
16170 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
16171 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
16172
16173 /* bgp update-delay command */
16174 install_element(BGP_NODE, &bgp_update_delay_cmd);
16175 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 16176
16177 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 16178 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 16179
16180 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
16181 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
16182
16183 /* "maximum-paths" commands. */
16184 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
16185 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
16186 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
16187 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
16188 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
16189 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
16190 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
16191 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
16192 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
16193 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
16194 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16195 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
16196 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
16197 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16198 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
16199
39edabac
PG
16200 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
16201 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
16202 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
16203 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16204 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 16205 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
16206 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
16207 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
16208 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16209 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
16210
16211 /* "timers bgp" commands. */
16212 install_element(BGP_NODE, &bgp_timers_cmd);
16213 install_element(BGP_NODE, &no_bgp_timers_cmd);
16214
16215 /* route-map delay-timer commands - per instance for backwards compat.
16216 */
16217 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
16218 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16219
16220 /* "bgp client-to-client reflection" commands */
16221 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
16222 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
16223
16224 /* "bgp always-compare-med" commands */
16225 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
16226 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
16227
9dac9fc8
DA
16228 /* bgp ebgp-requires-policy */
16229 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
16230 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
16231
fb29348a
DA
16232 /* bgp reject-as-sets */
16233 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
16234 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
16235
d62a17ae 16236 /* "bgp deterministic-med" commands */
16237 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
16238 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
16239
055679e9 16240 /* "bgp graceful-restart" command */
36235319
QY
16241 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
16242 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 16243
16244 /* "bgp graceful-restart-disable" command */
36235319
QY
16245 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
16246 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 16247
16248 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
16249 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
16250 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 16251
16252 /* "neighbor a:b:c:d graceful-restart-disable" command */
16253 install_element(BGP_NODE,
16254 &bgp_neighbor_graceful_restart_disable_set_cmd);
16255 install_element(BGP_NODE,
16256 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
16257
16258 /* "neighbor a:b:c:d graceful-restart-helper" command */
16259 install_element(BGP_NODE,
16260 &bgp_neighbor_graceful_restart_helper_set_cmd);
16261 install_element(BGP_NODE,
16262 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
16263
d62a17ae 16264 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
16265 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
16266 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
16267 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 16268 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 16269 install_element(BGP_NODE,
16270 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 16271 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
16272 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
16273
d6e3c15b 16274 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
16275 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 16276 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
16277 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 16278
7f323236
DW
16279 /* "bgp graceful-shutdown" commands */
16280 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
16281 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
16282
d62a17ae 16283 /* "bgp fast-external-failover" commands */
16284 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
16285 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
16286
d62a17ae 16287 /* "bgp bestpath compare-routerid" commands */
16288 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
16289 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
16290
16291 /* "bgp bestpath as-path ignore" commands */
16292 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
16293 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
16294
16295 /* "bgp bestpath as-path confed" commands */
16296 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
16297 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
16298
16299 /* "bgp bestpath as-path multipath-relax" commands */
16300 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
16301 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
16302
16303 /* "bgp log-neighbor-changes" commands */
16304 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
16305 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
16306
16307 /* "bgp bestpath med" commands */
16308 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
16309 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
16310
f7e1c681 16311 /* "bgp bestpath bandwidth" commands */
16312 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 16313 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 16314
d62a17ae 16315 /* "no bgp default ipv4-unicast" commands. */
16316 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
16317 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
16318
16319 /* "bgp network import-check" commands. */
16320 install_element(BGP_NODE, &bgp_network_import_check_cmd);
16321 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
16322 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
16323
16324 /* "bgp default local-preference" commands. */
16325 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
16326 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
16327
16328 /* bgp default show-hostname */
16329 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
16330 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
16331
aef999a2
DA
16332 /* bgp default show-nexthop-hostname */
16333 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
16334 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
16335
d62a17ae 16336 /* "bgp default subgroup-pkt-queue-max" commands. */
16337 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
16338 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
16339
16340 /* bgp ibgp-allow-policy-mods command */
16341 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
16342 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
16343
16344 /* "bgp listen limit" commands. */
16345 install_element(BGP_NODE, &bgp_listen_limit_cmd);
16346 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
16347
16348 /* "bgp listen range" commands. */
16349 install_element(BGP_NODE, &bgp_listen_range_cmd);
16350 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
16351
8175f54a 16352 /* "bgp default shutdown" command */
f26845f9 16353 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
16354
16355 /* "bgp shutdown" commands */
16356 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 16357 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 16358 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 16359 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 16360
d62a17ae 16361 /* "neighbor remote-as" commands. */
16362 install_element(BGP_NODE, &neighbor_remote_as_cmd);
16363 install_element(BGP_NODE, &neighbor_interface_config_cmd);
16364 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
16365 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
16366 install_element(BGP_NODE,
16367 &neighbor_interface_v6only_config_remote_as_cmd);
16368 install_element(BGP_NODE, &no_neighbor_cmd);
16369 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
16370
16371 /* "neighbor peer-group" commands. */
16372 install_element(BGP_NODE, &neighbor_peer_group_cmd);
16373 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
16374 install_element(BGP_NODE,
16375 &no_neighbor_interface_peer_group_remote_as_cmd);
16376
16377 /* "neighbor local-as" commands. */
16378 install_element(BGP_NODE, &neighbor_local_as_cmd);
16379 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
16380 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
16381 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
16382
16383 /* "neighbor solo" commands. */
16384 install_element(BGP_NODE, &neighbor_solo_cmd);
16385 install_element(BGP_NODE, &no_neighbor_solo_cmd);
16386
16387 /* "neighbor password" commands. */
16388 install_element(BGP_NODE, &neighbor_password_cmd);
16389 install_element(BGP_NODE, &no_neighbor_password_cmd);
16390
16391 /* "neighbor activate" commands. */
16392 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
16393 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
16394 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
16395 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
16396 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
16397 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
16398 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
16399 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
16400 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 16401 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
16402 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 16403 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
16404
16405 /* "no neighbor activate" commands. */
16406 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
16407 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
16408 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
16409 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
16410 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
16411 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
16412 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
16413 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
16414 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 16415 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
16416 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 16417 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
16418
16419 /* "neighbor peer-group" set commands. */
16420 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
16421 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16422 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
16423 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16424 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
16425 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
16426 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16427 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 16428 install_element(BGP_FLOWSPECV4_NODE,
16429 &neighbor_set_peer_group_hidden_cmd);
16430 install_element(BGP_FLOWSPECV6_NODE,
16431 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 16432
16433 /* "no neighbor peer-group unset" commands. */
16434 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
16435 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16436 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16437 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16438 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16439 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16440 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16441 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 16442 install_element(BGP_FLOWSPECV4_NODE,
16443 &no_neighbor_set_peer_group_hidden_cmd);
16444 install_element(BGP_FLOWSPECV6_NODE,
16445 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 16446
16447 /* "neighbor softreconfiguration inbound" commands.*/
16448 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
16449 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
16450 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
16451 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16452 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
16453 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16454 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
16455 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16456 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
16457 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16458 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
16459 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16460 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
16461 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16462 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
16463 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16464 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
16465 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 16466 install_element(BGP_FLOWSPECV4_NODE,
16467 &neighbor_soft_reconfiguration_cmd);
16468 install_element(BGP_FLOWSPECV4_NODE,
16469 &no_neighbor_soft_reconfiguration_cmd);
16470 install_element(BGP_FLOWSPECV6_NODE,
16471 &neighbor_soft_reconfiguration_cmd);
16472 install_element(BGP_FLOWSPECV6_NODE,
16473 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
16474 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
16475 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 16476
16477 /* "neighbor attribute-unchanged" commands. */
16478 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
16479 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
16480 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
16481 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
16482 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
16483 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
16484 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
16485 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
16486 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
16487 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
16488 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
16489 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
16490 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
16491 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
16492 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
16493 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
16494 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
16495 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
16496
16497 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
16498 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
16499
16500 /* "nexthop-local unchanged" commands */
16501 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
16502 install_element(BGP_IPV6_NODE,
16503 &no_neighbor_nexthop_local_unchanged_cmd);
16504
16505 /* "neighbor next-hop-self" commands. */
16506 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
16507 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
16508 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
16509 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
16510 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
16511 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
16512 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
16513 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
16514 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
16515 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
16516 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
16517 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
16518 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
16519 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
16520 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
16521 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
16522 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
16523 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
16524 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
16525 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 16526
16527 /* "neighbor next-hop-self force" commands. */
16528 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
16529 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
16530 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16531 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16532 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
16533 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16534 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16535 install_element(BGP_IPV4_NODE,
16536 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16537 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
16538 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16539 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16540 install_element(BGP_IPV4M_NODE,
16541 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16542 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
16543 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16544 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16545 install_element(BGP_IPV4L_NODE,
16546 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16547 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
16548 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16549 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16550 install_element(BGP_IPV6_NODE,
16551 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16552 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
16553 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16554 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16555 install_element(BGP_IPV6M_NODE,
16556 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16557 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
16558 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16559 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16560 install_element(BGP_IPV6L_NODE,
16561 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16562 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
16563 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16564 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16565 install_element(BGP_VPNV4_NODE,
16566 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16567 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
16568 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16569 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16570 install_element(BGP_VPNV6_NODE,
16571 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
16572 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
16573 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 16574
16575 /* "neighbor as-override" commands. */
16576 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
16577 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
16578 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
16579 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
16580 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
16581 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
16582 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
16583 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
16584 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
16585 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
16586 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
16587 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
16588 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
16589 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
16590 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
16591 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
16592 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
16593 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
16594
16595 /* "neighbor remove-private-AS" commands. */
16596 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
16597 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
16598 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
16599 install_element(BGP_NODE,
16600 &no_neighbor_remove_private_as_all_hidden_cmd);
16601 install_element(BGP_NODE,
16602 &neighbor_remove_private_as_replace_as_hidden_cmd);
16603 install_element(BGP_NODE,
16604 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
16605 install_element(BGP_NODE,
16606 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
16607 install_element(
16608 BGP_NODE,
16609 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
16610 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
16611 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
16612 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
16613 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16614 install_element(BGP_IPV4_NODE,
16615 &neighbor_remove_private_as_replace_as_cmd);
16616 install_element(BGP_IPV4_NODE,
16617 &no_neighbor_remove_private_as_replace_as_cmd);
16618 install_element(BGP_IPV4_NODE,
16619 &neighbor_remove_private_as_all_replace_as_cmd);
16620 install_element(BGP_IPV4_NODE,
16621 &no_neighbor_remove_private_as_all_replace_as_cmd);
16622 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
16623 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
16624 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
16625 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
16626 install_element(BGP_IPV4M_NODE,
16627 &neighbor_remove_private_as_replace_as_cmd);
16628 install_element(BGP_IPV4M_NODE,
16629 &no_neighbor_remove_private_as_replace_as_cmd);
16630 install_element(BGP_IPV4M_NODE,
16631 &neighbor_remove_private_as_all_replace_as_cmd);
16632 install_element(BGP_IPV4M_NODE,
16633 &no_neighbor_remove_private_as_all_replace_as_cmd);
16634 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
16635 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
16636 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
16637 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
16638 install_element(BGP_IPV4L_NODE,
16639 &neighbor_remove_private_as_replace_as_cmd);
16640 install_element(BGP_IPV4L_NODE,
16641 &no_neighbor_remove_private_as_replace_as_cmd);
16642 install_element(BGP_IPV4L_NODE,
16643 &neighbor_remove_private_as_all_replace_as_cmd);
16644 install_element(BGP_IPV4L_NODE,
16645 &no_neighbor_remove_private_as_all_replace_as_cmd);
16646 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
16647 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
16648 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
16649 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16650 install_element(BGP_IPV6_NODE,
16651 &neighbor_remove_private_as_replace_as_cmd);
16652 install_element(BGP_IPV6_NODE,
16653 &no_neighbor_remove_private_as_replace_as_cmd);
16654 install_element(BGP_IPV6_NODE,
16655 &neighbor_remove_private_as_all_replace_as_cmd);
16656 install_element(BGP_IPV6_NODE,
16657 &no_neighbor_remove_private_as_all_replace_as_cmd);
16658 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
16659 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
16660 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
16661 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
16662 install_element(BGP_IPV6M_NODE,
16663 &neighbor_remove_private_as_replace_as_cmd);
16664 install_element(BGP_IPV6M_NODE,
16665 &no_neighbor_remove_private_as_replace_as_cmd);
16666 install_element(BGP_IPV6M_NODE,
16667 &neighbor_remove_private_as_all_replace_as_cmd);
16668 install_element(BGP_IPV6M_NODE,
16669 &no_neighbor_remove_private_as_all_replace_as_cmd);
16670 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
16671 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
16672 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
16673 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
16674 install_element(BGP_IPV6L_NODE,
16675 &neighbor_remove_private_as_replace_as_cmd);
16676 install_element(BGP_IPV6L_NODE,
16677 &no_neighbor_remove_private_as_replace_as_cmd);
16678 install_element(BGP_IPV6L_NODE,
16679 &neighbor_remove_private_as_all_replace_as_cmd);
16680 install_element(BGP_IPV6L_NODE,
16681 &no_neighbor_remove_private_as_all_replace_as_cmd);
16682 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
16683 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
16684 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
16685 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16686 install_element(BGP_VPNV4_NODE,
16687 &neighbor_remove_private_as_replace_as_cmd);
16688 install_element(BGP_VPNV4_NODE,
16689 &no_neighbor_remove_private_as_replace_as_cmd);
16690 install_element(BGP_VPNV4_NODE,
16691 &neighbor_remove_private_as_all_replace_as_cmd);
16692 install_element(BGP_VPNV4_NODE,
16693 &no_neighbor_remove_private_as_all_replace_as_cmd);
16694 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
16695 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
16696 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
16697 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16698 install_element(BGP_VPNV6_NODE,
16699 &neighbor_remove_private_as_replace_as_cmd);
16700 install_element(BGP_VPNV6_NODE,
16701 &no_neighbor_remove_private_as_replace_as_cmd);
16702 install_element(BGP_VPNV6_NODE,
16703 &neighbor_remove_private_as_all_replace_as_cmd);
16704 install_element(BGP_VPNV6_NODE,
16705 &no_neighbor_remove_private_as_all_replace_as_cmd);
16706
16707 /* "neighbor send-community" commands.*/
16708 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
16709 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
16710 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
16711 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
16712 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
16713 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
16714 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
16715 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
16716 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
16717 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
16718 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
16719 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
16720 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
16721 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
16722 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
16723 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
16724 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
16725 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
16726 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
16727 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
16728 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
16729 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
16730 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
16731 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
16732 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
16733 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
16734 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
16735 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
16736 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
16737 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
16738 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
16739 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
16740 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
16741 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
16742 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
16743 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
16744
16745 /* "neighbor route-reflector" commands.*/
16746 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
16747 install_element(BGP_NODE,
16748 &no_neighbor_route_reflector_client_hidden_cmd);
16749 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
16750 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
16751 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
16752 install_element(BGP_IPV4M_NODE,
16753 &no_neighbor_route_reflector_client_cmd);
16754 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
16755 install_element(BGP_IPV4L_NODE,
16756 &no_neighbor_route_reflector_client_cmd);
16757 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
16758 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
16759 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
16760 install_element(BGP_IPV6M_NODE,
16761 &no_neighbor_route_reflector_client_cmd);
16762 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
16763 install_element(BGP_IPV6L_NODE,
16764 &no_neighbor_route_reflector_client_cmd);
16765 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
16766 install_element(BGP_VPNV4_NODE,
16767 &no_neighbor_route_reflector_client_cmd);
16768 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
16769 install_element(BGP_VPNV6_NODE,
16770 &no_neighbor_route_reflector_client_cmd);
7c40bf39 16771 install_element(BGP_FLOWSPECV4_NODE,
16772 &neighbor_route_reflector_client_cmd);
16773 install_element(BGP_FLOWSPECV4_NODE,
16774 &no_neighbor_route_reflector_client_cmd);
16775 install_element(BGP_FLOWSPECV6_NODE,
16776 &neighbor_route_reflector_client_cmd);
16777 install_element(BGP_FLOWSPECV6_NODE,
16778 &no_neighbor_route_reflector_client_cmd);
d62a17ae 16779 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
16780 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
16781
16782 /* "neighbor route-server" commands.*/
16783 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16784 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16785 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16786 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16787 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16788 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16789 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16790 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16791 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16792 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16793 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16794 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16795 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16796 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16797 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16798 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16799 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16800 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
16801 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16802 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 16803 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16804 install_element(BGP_FLOWSPECV4_NODE,
16805 &no_neighbor_route_server_client_cmd);
16806 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16807 install_element(BGP_FLOWSPECV6_NODE,
16808 &no_neighbor_route_server_client_cmd);
d62a17ae 16809
16810 /* "neighbor addpath-tx-all-paths" commands.*/
16811 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16812 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16813 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16814 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16815 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16816 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16817 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16818 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16819 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16820 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16821 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16822 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16823 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16824 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16825 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16826 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16827 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16828 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16829
16830 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16831 install_element(BGP_NODE,
16832 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16833 install_element(BGP_NODE,
16834 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16835 install_element(BGP_IPV4_NODE,
16836 &neighbor_addpath_tx_bestpath_per_as_cmd);
16837 install_element(BGP_IPV4_NODE,
16838 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16839 install_element(BGP_IPV4M_NODE,
16840 &neighbor_addpath_tx_bestpath_per_as_cmd);
16841 install_element(BGP_IPV4M_NODE,
16842 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16843 install_element(BGP_IPV4L_NODE,
16844 &neighbor_addpath_tx_bestpath_per_as_cmd);
16845 install_element(BGP_IPV4L_NODE,
16846 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16847 install_element(BGP_IPV6_NODE,
16848 &neighbor_addpath_tx_bestpath_per_as_cmd);
16849 install_element(BGP_IPV6_NODE,
16850 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16851 install_element(BGP_IPV6M_NODE,
16852 &neighbor_addpath_tx_bestpath_per_as_cmd);
16853 install_element(BGP_IPV6M_NODE,
16854 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16855 install_element(BGP_IPV6L_NODE,
16856 &neighbor_addpath_tx_bestpath_per_as_cmd);
16857 install_element(BGP_IPV6L_NODE,
16858 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16859 install_element(BGP_VPNV4_NODE,
16860 &neighbor_addpath_tx_bestpath_per_as_cmd);
16861 install_element(BGP_VPNV4_NODE,
16862 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16863 install_element(BGP_VPNV6_NODE,
16864 &neighbor_addpath_tx_bestpath_per_as_cmd);
16865 install_element(BGP_VPNV6_NODE,
16866 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16867
2b31007c
RZ
16868 /* "neighbor sender-as-path-loop-detection" commands. */
16869 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16870 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16871
d62a17ae 16872 /* "neighbor passive" commands. */
16873 install_element(BGP_NODE, &neighbor_passive_cmd);
16874 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16875
16876
16877 /* "neighbor shutdown" commands. */
16878 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16879 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16880 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16881 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
16882 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
16883 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 16884
16885 /* "neighbor capability extended-nexthop" commands.*/
16886 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16887 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16888
16889 /* "neighbor capability orf prefix-list" commands.*/
16890 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16891 install_element(BGP_NODE,
16892 &no_neighbor_capability_orf_prefix_hidden_cmd);
16893 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16894 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16895 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16896 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16897 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16898 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16899 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16900 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16901 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16902 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16903 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16904 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16905
16906 /* "neighbor capability dynamic" commands.*/
16907 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16908 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16909
16910 /* "neighbor dont-capability-negotiate" commands. */
16911 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16912 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16913
16914 /* "neighbor ebgp-multihop" commands. */
16915 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16916 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16917 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16918
16919 /* "neighbor disable-connected-check" commands. */
16920 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16921 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16922
47cbc09b
PM
16923 /* "neighbor enforce-first-as" commands. */
16924 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16925 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16926
d62a17ae 16927 /* "neighbor description" commands. */
16928 install_element(BGP_NODE, &neighbor_description_cmd);
16929 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 16930 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 16931
16932 /* "neighbor update-source" commands. "*/
16933 install_element(BGP_NODE, &neighbor_update_source_cmd);
16934 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16935
16936 /* "neighbor default-originate" commands. */
16937 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16938 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16939 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16940 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16941 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16942 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16943 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16944 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16945 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16946 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16947 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16948 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16949 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16950 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16951 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16952 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16953 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16954 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16955 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16956 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16957 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16958
16959 /* "neighbor port" commands. */
16960 install_element(BGP_NODE, &neighbor_port_cmd);
16961 install_element(BGP_NODE, &no_neighbor_port_cmd);
16962
16963 /* "neighbor weight" commands. */
16964 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16965 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16966
16967 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16968 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16969 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16970 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16971 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16972 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16973 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16974 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16975 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16976 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16977 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16978 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16979 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16980 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16981 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16982 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16983
16984 /* "neighbor override-capability" commands. */
16985 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16986 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16987
16988 /* "neighbor strict-capability-match" commands. */
16989 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16990 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16991
16992 /* "neighbor timers" commands. */
16993 install_element(BGP_NODE, &neighbor_timers_cmd);
16994 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16995
16996 /* "neighbor timers connect" commands. */
16997 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16998 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16999
17000 /* "neighbor advertisement-interval" commands. */
17001 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
17002 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
17003
17004 /* "neighbor interface" commands. */
17005 install_element(BGP_NODE, &neighbor_interface_cmd);
17006 install_element(BGP_NODE, &no_neighbor_interface_cmd);
17007
17008 /* "neighbor distribute" commands. */
17009 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
17010 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
17011 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
17012 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
17013 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
17014 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
17015 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
17016 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
17017 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
17018 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
17019 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
17020 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
17021 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
17022 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
17023 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
17024 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
17025 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
17026 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
17027
17028 /* "neighbor prefix-list" commands. */
17029 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
17030 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
17031 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
17032 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
17033 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
17034 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
17035 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
17036 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
17037 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
17038 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
17039 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
17040 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
17041 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
17042 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
17043 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
17044 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
17045 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
17046 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 17047 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
17048 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
17049 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
17050 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 17051
17052 /* "neighbor filter-list" commands. */
17053 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
17054 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
17055 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
17056 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
17057 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
17058 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
17059 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
17060 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
17061 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
17062 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
17063 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
17064 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
17065 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
17066 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
17067 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
17068 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
17069 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
17070 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 17071 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
17072 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
17073 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
17074 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 17075
17076 /* "neighbor route-map" commands. */
17077 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
17078 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
17079 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
17080 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
17081 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
17082 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
17083 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
17084 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
17085 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
17086 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
17087 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
17088 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
17089 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
17090 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
17091 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
17092 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
17093 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
17094 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 17095 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
17096 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
17097 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
17098 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
17099 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
17100 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 17101
17102 /* "neighbor unsuppress-map" commands. */
17103 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
17104 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
17105 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
17106 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
17107 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
17108 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
17109 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
17110 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
17111 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
17112 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
17113 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
17114 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
17115 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
17116 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
17117 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
17118 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
17119 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
17120 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
17121
fde246e8
DA
17122 /* neighbor maximum-prefix-out commands. */
17123 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
17124 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
17125 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
17126 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17127 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
17128 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17129 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
17130 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17131 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
17132 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17133 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
17134 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17135 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
17136 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17137 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
17138 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17139 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
17140 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17141
d62a17ae 17142 /* "neighbor maximum-prefix" commands. */
17143 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
17144 install_element(BGP_NODE,
17145 &neighbor_maximum_prefix_threshold_hidden_cmd);
17146 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
17147 install_element(BGP_NODE,
17148 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
17149 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
17150 install_element(BGP_NODE,
17151 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
17152 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
17153 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
17154 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17155 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17156 install_element(BGP_IPV4_NODE,
17157 &neighbor_maximum_prefix_threshold_warning_cmd);
17158 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17159 install_element(BGP_IPV4_NODE,
17160 &neighbor_maximum_prefix_threshold_restart_cmd);
17161 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
17162 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
17163 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17164 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
17165 install_element(BGP_IPV4M_NODE,
17166 &neighbor_maximum_prefix_threshold_warning_cmd);
17167 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
17168 install_element(BGP_IPV4M_NODE,
17169 &neighbor_maximum_prefix_threshold_restart_cmd);
17170 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
17171 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
17172 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17173 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
17174 install_element(BGP_IPV4L_NODE,
17175 &neighbor_maximum_prefix_threshold_warning_cmd);
17176 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
17177 install_element(BGP_IPV4L_NODE,
17178 &neighbor_maximum_prefix_threshold_restart_cmd);
17179 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
17180 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
17181 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17182 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17183 install_element(BGP_IPV6_NODE,
17184 &neighbor_maximum_prefix_threshold_warning_cmd);
17185 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17186 install_element(BGP_IPV6_NODE,
17187 &neighbor_maximum_prefix_threshold_restart_cmd);
17188 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
17189 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
17190 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17191 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
17192 install_element(BGP_IPV6M_NODE,
17193 &neighbor_maximum_prefix_threshold_warning_cmd);
17194 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
17195 install_element(BGP_IPV6M_NODE,
17196 &neighbor_maximum_prefix_threshold_restart_cmd);
17197 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
17198 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
17199 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17200 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
17201 install_element(BGP_IPV6L_NODE,
17202 &neighbor_maximum_prefix_threshold_warning_cmd);
17203 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
17204 install_element(BGP_IPV6L_NODE,
17205 &neighbor_maximum_prefix_threshold_restart_cmd);
17206 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
17207 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
17208 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17209 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17210 install_element(BGP_VPNV4_NODE,
17211 &neighbor_maximum_prefix_threshold_warning_cmd);
17212 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17213 install_element(BGP_VPNV4_NODE,
17214 &neighbor_maximum_prefix_threshold_restart_cmd);
17215 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
17216 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
17217 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17218 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17219 install_element(BGP_VPNV6_NODE,
17220 &neighbor_maximum_prefix_threshold_warning_cmd);
17221 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17222 install_element(BGP_VPNV6_NODE,
17223 &neighbor_maximum_prefix_threshold_restart_cmd);
17224 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
17225
17226 /* "neighbor allowas-in" */
17227 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
17228 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
17229 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
17230 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
17231 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
17232 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
17233 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
17234 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
17235 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
17236 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
17237 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
17238 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
17239 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
17240 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
17241 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
17242 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
17243 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
17244 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
17245 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
17246 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
17247
17248 /* address-family commands. */
17249 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
17250 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 17251#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 17252 install_element(BGP_NODE, &address_family_vpnv4_cmd);
17253 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 17254#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 17255
d62a17ae 17256 install_element(BGP_NODE, &address_family_evpn_cmd);
17257
17258 /* "exit-address-family" command. */
17259 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
17260 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
17261 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
17262 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
17263 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
17264 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
17265 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
17266 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 17267 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
17268 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 17269 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
17270
17271 /* "clear ip bgp commands" */
17272 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
17273
17274 /* clear ip bgp prefix */
17275 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
17276 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
17277 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
17278
17279 /* "show [ip] bgp summary" commands. */
17280 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 17281 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 17282 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 17283 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 17284 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
17285 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 17286 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
17287
17288 /* "show [ip] bgp neighbors" commands. */
17289 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
17290
36235319 17291 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 17292
d62a17ae 17293 /* "show [ip] bgp peer-group" commands. */
17294 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
17295
17296 /* "show [ip] bgp paths" commands. */
17297 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
17298
17299 /* "show [ip] bgp community" commands. */
17300 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
17301
17302 /* "show ip bgp large-community" commands. */
17303 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
17304 /* "show [ip] bgp attribute-info" commands. */
17305 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 17306 /* "show [ip] bgp route-leak" command */
17307 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 17308
17309 /* "redistribute" commands. */
17310 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
17311 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
17312 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
17313 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
17314 install_element(BGP_NODE,
17315 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
17316 install_element(BGP_NODE,
17317 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
17318 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
17319 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
17320 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
17321 install_element(BGP_NODE,
17322 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
17323 install_element(BGP_NODE,
17324 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
17325 install_element(BGP_NODE,
17326 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
17327 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
17328 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
17329 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
17330 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
17331 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
17332 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
17333 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
17334 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
17335 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
17336 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
17337 install_element(BGP_IPV4_NODE,
17338 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
17339 install_element(BGP_IPV4_NODE,
17340 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
17341 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
17342 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
17343 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
17344 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
17345 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
17346 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
17347
b9c7bc5a
PZ
17348 /* import|export vpn [route-map WORD] */
17349 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
17350 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 17351
12a844a5
DS
17352 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
17353 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
17354
d62a17ae 17355 /* ttl_security commands */
17356 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
17357 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
17358
17359 /* "show [ip] bgp memory" commands. */
17360 install_element(VIEW_NODE, &show_bgp_memory_cmd);
17361
acf71666
MK
17362 /* "show bgp martian next-hop" */
17363 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
17364
48ecf8f5
DS
17365 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
17366
d62a17ae 17367 /* "show [ip] bgp views" commands. */
17368 install_element(VIEW_NODE, &show_bgp_views_cmd);
17369
17370 /* "show [ip] bgp vrfs" commands. */
17371 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
17372
17373 /* Community-list. */
17374 community_list_vty();
ddb5b488
PZ
17375
17376 /* vpn-policy commands */
b9c7bc5a
PZ
17377 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
17378 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
17379 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
17380 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
17381 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
17382 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
17383 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
17384 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
17385 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
17386 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
17387 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
17388 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 17389
301ad80a
PG
17390 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
17391 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
17392
b9c7bc5a
PZ
17393 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
17394 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
17395 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
17396 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
17397 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
17398 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
17399 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
17400 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
17401 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
17402 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 17403}
6b0655a2 17404
718e3744 17405#include "memory.h"
17406#include "bgp_regex.h"
17407#include "bgp_clist.h"
17408#include "bgp_ecommunity.h"
17409
17410/* VTY functions. */
17411
17412/* Direction value to string conversion. */
d62a17ae 17413static const char *community_direct_str(int direct)
17414{
17415 switch (direct) {
17416 case COMMUNITY_DENY:
17417 return "deny";
17418 case COMMUNITY_PERMIT:
17419 return "permit";
17420 default:
17421 return "unknown";
17422 }
718e3744 17423}
17424
17425/* Display error string. */
d62a17ae 17426static void community_list_perror(struct vty *vty, int ret)
17427{
17428 switch (ret) {
17429 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
17430 vty_out(vty, "%% Can't find community-list\n");
17431 break;
17432 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
17433 vty_out(vty, "%% Malformed community-list value\n");
17434 break;
17435 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
17436 vty_out(vty,
17437 "%% Community name conflict, previously defined as standard community\n");
17438 break;
17439 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
17440 vty_out(vty,
17441 "%% Community name conflict, previously defined as expanded community\n");
17442 break;
17443 }
718e3744 17444}
17445
5bf15956
DW
17446/* "community-list" keyword help string. */
17447#define COMMUNITY_LIST_STR "Add a community list entry\n"
17448
7336e101
SP
17449/*community-list standard */
17450DEFUN (community_list_standard,
17451 bgp_community_list_standard_cmd,
2f8cc0e5 17452 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17453 BGP_STR
718e3744 17454 COMMUNITY_LIST_STR
17455 "Community list number (standard)\n"
5bf15956 17456 "Add an standard community-list entry\n"
718e3744 17457 "Community list name\n"
2f8cc0e5
DA
17458 "Sequence number of an entry\n"
17459 "Sequence number\n"
718e3744 17460 "Specify community to reject\n"
17461 "Specify community to accept\n"
17462 COMMUNITY_VAL_STR)
17463{
d62a17ae 17464 char *cl_name_or_number = NULL;
2f8cc0e5 17465 char *seq = NULL;
d62a17ae 17466 int direct = 0;
17467 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 17468 int idx = 0;
7336e101 17469
2f8cc0e5
DA
17470 argv_find(argv, argc, "(1-4294967295)", &idx);
17471 if (idx)
17472 seq = argv[idx]->arg;
17473
17474 idx = 0;
d62a17ae 17475 argv_find(argv, argc, "(1-99)", &idx);
17476 argv_find(argv, argc, "WORD", &idx);
17477 cl_name_or_number = argv[idx]->arg;
17478 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17479 : COMMUNITY_DENY;
17480 argv_find(argv, argc, "AA:NN", &idx);
17481 char *str = argv_concat(argv, argc, idx);
42f914d4 17482
2f8cc0e5
DA
17483 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17484 direct, style);
42f914d4 17485
d62a17ae 17486 XFREE(MTYPE_TMP, str);
42f914d4 17487
d62a17ae 17488 if (ret < 0) {
17489 /* Display error string. */
17490 community_list_perror(vty, ret);
17491 return CMD_WARNING_CONFIG_FAILED;
17492 }
42f914d4 17493
d62a17ae 17494 return CMD_SUCCESS;
718e3744 17495}
17496
7336e101
SP
17497DEFUN (no_community_list_standard_all,
17498 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 17499 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17500 NO_STR
17501 BGP_STR
17502 COMMUNITY_LIST_STR
17503 "Community list number (standard)\n"
17504 "Add an standard community-list entry\n"
17505 "Community list name\n"
2f8cc0e5
DA
17506 "Sequence number of an entry\n"
17507 "Sequence number\n"
7336e101
SP
17508 "Specify community to reject\n"
17509 "Specify community to accept\n"
17510 COMMUNITY_VAL_STR)
718e3744 17511{
d62a17ae 17512 char *cl_name_or_number = NULL;
174b5cb9 17513 char *str = NULL;
d62a17ae 17514 int direct = 0;
17515 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 17516 char *seq = NULL;
d62a17ae 17517 int idx = 0;
7336e101 17518
2f8cc0e5
DA
17519 argv_find(argv, argc, "(1-4294967295)", &idx);
17520 if (idx)
17521 seq = argv[idx]->arg;
17522
17523 idx = 0;
174b5cb9
DA
17524 argv_find(argv, argc, "permit", &idx);
17525 argv_find(argv, argc, "deny", &idx);
17526
17527 if (idx) {
17528 direct = argv_find(argv, argc, "permit", &idx)
17529 ? COMMUNITY_PERMIT
17530 : COMMUNITY_DENY;
17531
17532 idx = 0;
17533 argv_find(argv, argc, "AA:NN", &idx);
17534 str = argv_concat(argv, argc, idx);
17535 }
17536
17537 idx = 0;
d62a17ae 17538 argv_find(argv, argc, "(1-99)", &idx);
17539 argv_find(argv, argc, "WORD", &idx);
17540 cl_name_or_number = argv[idx]->arg;
42f914d4 17541
2f8cc0e5 17542 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17543 direct, style);
42f914d4 17544
d62a17ae 17545 XFREE(MTYPE_TMP, str);
daf9ddbb 17546
d62a17ae 17547 if (ret < 0) {
17548 community_list_perror(vty, ret);
17549 return CMD_WARNING_CONFIG_FAILED;
17550 }
42f914d4 17551
d62a17ae 17552 return CMD_SUCCESS;
718e3744 17553}
7336e101 17554
174b5cb9
DA
17555ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
17556 "no bgp community-list <(1-99)|standard WORD>",
17557 NO_STR BGP_STR COMMUNITY_LIST_STR
17558 "Community list number (standard)\n"
17559 "Add an standard community-list entry\n"
17560 "Community list name\n")
17561
7336e101
SP
17562/*community-list expanded */
17563DEFUN (community_list_expanded_all,
17564 bgp_community_list_expanded_all_cmd,
2f8cc0e5 17565 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17566 BGP_STR
17567 COMMUNITY_LIST_STR
718e3744 17568 "Community list number (expanded)\n"
5bf15956 17569 "Add an expanded community-list entry\n"
718e3744 17570 "Community list name\n"
2f8cc0e5
DA
17571 "Sequence number of an entry\n"
17572 "Sequence number\n"
718e3744 17573 "Specify community to reject\n"
17574 "Specify community to accept\n"
17575 COMMUNITY_VAL_STR)
17576{
d62a17ae 17577 char *cl_name_or_number = NULL;
2f8cc0e5 17578 char *seq = NULL;
d62a17ae 17579 int direct = 0;
17580 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17581 int idx = 0;
7b9a4750 17582
2f8cc0e5
DA
17583 argv_find(argv, argc, "(1-4294967295)", &idx);
17584 if (idx)
17585 seq = argv[idx]->arg;
17586
17587 idx = 0;
17588
d62a17ae 17589 argv_find(argv, argc, "(100-500)", &idx);
17590 argv_find(argv, argc, "WORD", &idx);
17591 cl_name_or_number = argv[idx]->arg;
17592 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17593 : COMMUNITY_DENY;
17594 argv_find(argv, argc, "AA:NN", &idx);
17595 char *str = argv_concat(argv, argc, idx);
42f914d4 17596
2f8cc0e5
DA
17597 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17598 direct, style);
42f914d4 17599
d62a17ae 17600 XFREE(MTYPE_TMP, str);
42f914d4 17601
d62a17ae 17602 if (ret < 0) {
17603 /* Display error string. */
17604 community_list_perror(vty, ret);
17605 return CMD_WARNING_CONFIG_FAILED;
17606 }
42f914d4 17607
d62a17ae 17608 return CMD_SUCCESS;
718e3744 17609}
17610
7336e101
SP
17611DEFUN (no_community_list_expanded_all,
17612 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 17613 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17614 NO_STR
17615 BGP_STR
17616 COMMUNITY_LIST_STR
17617 "Community list number (expanded)\n"
17618 "Add an expanded community-list entry\n"
17619 "Community list name\n"
2f8cc0e5
DA
17620 "Sequence number of an entry\n"
17621 "Sequence number\n"
7336e101
SP
17622 "Specify community to reject\n"
17623 "Specify community to accept\n"
17624 COMMUNITY_VAL_STR)
718e3744 17625{
d62a17ae 17626 char *cl_name_or_number = NULL;
2f8cc0e5 17627 char *seq = NULL;
174b5cb9 17628 char *str = NULL;
d62a17ae 17629 int direct = 0;
17630 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17631 int idx = 0;
174b5cb9 17632
2f8cc0e5
DA
17633 argv_find(argv, argc, "(1-4294967295)", &idx);
17634 if (idx)
17635 seq = argv[idx]->arg;
17636
17637 idx = 0;
174b5cb9
DA
17638 argv_find(argv, argc, "permit", &idx);
17639 argv_find(argv, argc, "deny", &idx);
17640
17641 if (idx) {
17642 direct = argv_find(argv, argc, "permit", &idx)
17643 ? COMMUNITY_PERMIT
17644 : COMMUNITY_DENY;
17645
17646 idx = 0;
17647 argv_find(argv, argc, "AA:NN", &idx);
17648 str = argv_concat(argv, argc, idx);
7336e101 17649 }
174b5cb9
DA
17650
17651 idx = 0;
d62a17ae 17652 argv_find(argv, argc, "(100-500)", &idx);
17653 argv_find(argv, argc, "WORD", &idx);
17654 cl_name_or_number = argv[idx]->arg;
42f914d4 17655
2f8cc0e5 17656 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17657 direct, style);
42f914d4 17658
d62a17ae 17659 XFREE(MTYPE_TMP, str);
daf9ddbb 17660
d62a17ae 17661 if (ret < 0) {
17662 community_list_perror(vty, ret);
17663 return CMD_WARNING_CONFIG_FAILED;
17664 }
42f914d4 17665
d62a17ae 17666 return CMD_SUCCESS;
718e3744 17667}
17668
174b5cb9
DA
17669ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
17670 "no bgp community-list <(100-500)|expanded WORD>",
17671 NO_STR IP_STR COMMUNITY_LIST_STR
17672 "Community list number (expanded)\n"
17673 "Add an expanded community-list entry\n"
17674 "Community list name\n")
17675
8d9b8ed9
PM
17676/* Return configuration string of community-list entry. */
17677static const char *community_list_config_str(struct community_entry *entry)
17678{
17679 const char *str;
17680
17681 if (entry->any)
17682 str = "";
17683 else {
17684 if (entry->style == COMMUNITY_LIST_STANDARD)
17685 str = community_str(entry->u.com, false);
17686 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
17687 str = lcommunity_str(entry->u.lcom, false);
17688 else
17689 str = entry->config;
17690 }
17691 return str;
17692}
17693
d62a17ae 17694static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 17695{
d62a17ae 17696 struct community_entry *entry;
718e3744 17697
d62a17ae 17698 for (entry = list->head; entry; entry = entry->next) {
17699 if (entry == list->head) {
17700 if (all_digit(list->name))
17701 vty_out(vty, "Community %s list %s\n",
17702 entry->style == COMMUNITY_LIST_STANDARD
17703 ? "standard"
17704 : "(expanded) access",
17705 list->name);
17706 else
17707 vty_out(vty, "Named Community %s list %s\n",
17708 entry->style == COMMUNITY_LIST_STANDARD
17709 ? "standard"
17710 : "expanded",
17711 list->name);
17712 }
17713 if (entry->any)
17714 vty_out(vty, " %s\n",
17715 community_direct_str(entry->direct));
17716 else
17717 vty_out(vty, " %s %s\n",
17718 community_direct_str(entry->direct),
8d9b8ed9 17719 community_list_config_str(entry));
d62a17ae 17720 }
718e3744 17721}
17722
7336e101
SP
17723DEFUN (show_community_list,
17724 show_bgp_community_list_cmd,
17725 "show bgp community-list",
718e3744 17726 SHOW_STR
7336e101 17727 BGP_STR
718e3744 17728 "List community-list\n")
17729{
d62a17ae 17730 struct community_list *list;
17731 struct community_list_master *cm;
718e3744 17732
d62a17ae 17733 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17734 if (!cm)
17735 return CMD_SUCCESS;
718e3744 17736
d62a17ae 17737 for (list = cm->num.head; list; list = list->next)
17738 community_list_show(vty, list);
718e3744 17739
d62a17ae 17740 for (list = cm->str.head; list; list = list->next)
17741 community_list_show(vty, list);
718e3744 17742
d62a17ae 17743 return CMD_SUCCESS;
718e3744 17744}
17745
7336e101
SP
17746DEFUN (show_community_list_arg,
17747 show_bgp_community_list_arg_cmd,
960b69b9 17748 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
17749 SHOW_STR
17750 BGP_STR
718e3744 17751 "List community-list\n"
17752 "Community-list number\n"
960b69b9 17753 "Community-list name\n"
17754 "Detailed information on community-list\n")
718e3744 17755{
d62a17ae 17756 int idx_comm_list = 3;
17757 struct community_list *list;
718e3744 17758
e237b0d2 17759 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17760 COMMUNITY_LIST_MASTER);
17761 if (!list) {
17762 vty_out(vty, "%% Can't find community-list\n");
17763 return CMD_WARNING;
17764 }
718e3744 17765
d62a17ae 17766 community_list_show(vty, list);
718e3744 17767
d62a17ae 17768 return CMD_SUCCESS;
718e3744 17769}
6b0655a2 17770
57d187bc
JS
17771/*
17772 * Large Community code.
17773 */
d62a17ae 17774static int lcommunity_list_set_vty(struct vty *vty, int argc,
17775 struct cmd_token **argv, int style,
17776 int reject_all_digit_name)
17777{
17778 int ret;
17779 int direct;
17780 char *str;
17781 int idx = 0;
17782 char *cl_name;
2f8cc0e5
DA
17783 char *seq = NULL;
17784
947073e3 17785 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 17786 seq = argv[idx]->arg;
d62a17ae 17787
2f8cc0e5 17788 idx = 0;
d62a17ae 17789 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17790 : COMMUNITY_DENY;
17791
17792 /* All digit name check. */
17793 idx = 0;
17794 argv_find(argv, argc, "WORD", &idx);
17795 argv_find(argv, argc, "(1-99)", &idx);
17796 argv_find(argv, argc, "(100-500)", &idx);
17797 cl_name = argv[idx]->arg;
17798 if (reject_all_digit_name && all_digit(cl_name)) {
17799 vty_out(vty, "%% Community name cannot have all digits\n");
17800 return CMD_WARNING_CONFIG_FAILED;
17801 }
17802
17803 idx = 0;
17804 argv_find(argv, argc, "AA:BB:CC", &idx);
17805 argv_find(argv, argc, "LINE", &idx);
17806 /* Concat community string argument. */
17807 if (idx)
17808 str = argv_concat(argv, argc, idx);
17809 else
17810 str = NULL;
17811
2f8cc0e5 17812 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 17813
17814 /* Free temporary community list string allocated by
17815 argv_concat(). */
0a22ddfb 17816 XFREE(MTYPE_TMP, str);
d62a17ae 17817
17818 if (ret < 0) {
17819 community_list_perror(vty, ret);
17820 return CMD_WARNING_CONFIG_FAILED;
17821 }
17822 return CMD_SUCCESS;
17823}
17824
17825static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17826 struct cmd_token **argv, int style)
17827{
17828 int ret;
17829 int direct = 0;
17830 char *str = NULL;
17831 int idx = 0;
2f8cc0e5 17832 char *seq = NULL;
d62a17ae 17833
947073e3 17834 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 17835 seq = argv[idx]->arg;
d62a17ae 17836
2f8cc0e5 17837 idx = 0;
d62a17ae 17838 argv_find(argv, argc, "permit", &idx);
17839 argv_find(argv, argc, "deny", &idx);
17840
17841 if (idx) {
17842 /* Check the list direct. */
17843 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17844 direct = COMMUNITY_PERMIT;
17845 else
17846 direct = COMMUNITY_DENY;
17847
17848 idx = 0;
17849 argv_find(argv, argc, "LINE", &idx);
17850 argv_find(argv, argc, "AA:AA:NN", &idx);
17851 /* Concat community string argument. */
17852 str = argv_concat(argv, argc, idx);
17853 }
17854
17855 idx = 0;
17856 argv_find(argv, argc, "(1-99)", &idx);
17857 argv_find(argv, argc, "(100-500)", &idx);
17858 argv_find(argv, argc, "WORD", &idx);
17859
17860 /* Unset community list. */
2f8cc0e5 17861 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 17862 style);
17863
17864 /* Free temporary community list string allocated by
17865 argv_concat(). */
0a22ddfb 17866 XFREE(MTYPE_TMP, str);
d62a17ae 17867
17868 if (ret < 0) {
17869 community_list_perror(vty, ret);
17870 return CMD_WARNING_CONFIG_FAILED;
17871 }
17872
17873 return CMD_SUCCESS;
57d187bc
JS
17874}
17875
17876/* "large-community-list" keyword help string. */
17877#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17878#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17879
7336e101
SP
17880DEFUN (lcommunity_list_standard,
17881 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17882 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17883 BGP_STR
17884 LCOMMUNITY_LIST_STR
17885 "Large Community list number (standard)\n"
2f8cc0e5
DA
17886 "Sequence number of an entry\n"
17887 "Sequence number\n"
7336e101
SP
17888 "Specify large community to reject\n"
17889 "Specify large community to accept\n"
17890 LCOMMUNITY_VAL_STR)
52951b63 17891{
d62a17ae 17892 return lcommunity_list_set_vty(vty, argc, argv,
17893 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
17894}
17895
7336e101
SP
17896DEFUN (lcommunity_list_expanded,
17897 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17898 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17899 BGP_STR
17900 LCOMMUNITY_LIST_STR
17901 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17902 "Sequence number of an entry\n"
17903 "Sequence number\n"
7336e101
SP
17904 "Specify large community to reject\n"
17905 "Specify large community to accept\n"
17906 "An ordered list as a regular-expression\n")
57d187bc 17907{
d62a17ae 17908 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17909 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
17910}
17911
7336e101
SP
17912DEFUN (lcommunity_list_name_standard,
17913 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17914 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17915 BGP_STR
17916 LCOMMUNITY_LIST_STR
17917 "Specify standard large-community-list\n"
17918 "Large Community list name\n"
2f8cc0e5
DA
17919 "Sequence number of an entry\n"
17920 "Sequence number\n"
7336e101
SP
17921 "Specify large community to reject\n"
17922 "Specify large community to accept\n"
17923 LCOMMUNITY_VAL_STR)
52951b63 17924{
d62a17ae 17925 return lcommunity_list_set_vty(vty, argc, argv,
17926 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
17927}
17928
7336e101
SP
17929DEFUN (lcommunity_list_name_expanded,
17930 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17931 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17932 BGP_STR
17933 LCOMMUNITY_LIST_STR
17934 "Specify expanded large-community-list\n"
17935 "Large Community list name\n"
2f8cc0e5
DA
17936 "Sequence number of an entry\n"
17937 "Sequence number\n"
7336e101
SP
17938 "Specify large community to reject\n"
17939 "Specify large community to accept\n"
17940 "An ordered list as a regular-expression\n")
57d187bc 17941{
d62a17ae 17942 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17943 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
17944}
17945
4378f57c
DA
17946DEFUN (no_lcommunity_list_all,
17947 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
17948 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17949 NO_STR
17950 BGP_STR
17951 LCOMMUNITY_LIST_STR
17952 "Large Community list number (standard)\n"
17953 "Large Community list number (expanded)\n"
17954 "Large Community list name\n")
57d187bc 17955{
7336e101
SP
17956 return lcommunity_list_unset_vty(vty, argc, argv,
17957 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17958}
17959
4378f57c
DA
17960DEFUN (no_lcommunity_list_name_standard_all,
17961 no_bgp_lcommunity_list_name_standard_all_cmd,
17962 "no bgp large-community-list standard WORD",
17963 NO_STR
17964 BGP_STR
17965 LCOMMUNITY_LIST_STR
17966 "Specify standard large-community-list\n"
17967 "Large Community list name\n")
17968{
17969 return lcommunity_list_unset_vty(vty, argc, argv,
17970 LARGE_COMMUNITY_LIST_STANDARD);
17971}
17972
7336e101
SP
17973DEFUN (no_lcommunity_list_name_expanded_all,
17974 no_bgp_lcommunity_list_name_expanded_all_cmd,
17975 "no bgp large-community-list expanded WORD",
17976 NO_STR
17977 BGP_STR
17978 LCOMMUNITY_LIST_STR
17979 "Specify expanded large-community-list\n"
17980 "Large Community list name\n")
57d187bc 17981{
d62a17ae 17982 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17983 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17984}
17985
7336e101
SP
17986DEFUN (no_lcommunity_list_standard,
17987 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17988 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17989 NO_STR
17990 BGP_STR
17991 LCOMMUNITY_LIST_STR
17992 "Large Community list number (standard)\n"
2f8cc0e5
DA
17993 "Sequence number of an entry\n"
17994 "Sequence number\n"
7336e101
SP
17995 "Specify large community to reject\n"
17996 "Specify large community to accept\n"
17997 LCOMMUNITY_VAL_STR)
57d187bc 17998{
d62a17ae 17999 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18000 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18001}
18002
7336e101
SP
18003DEFUN (no_lcommunity_list_expanded,
18004 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 18005 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18006 NO_STR
18007 BGP_STR
18008 LCOMMUNITY_LIST_STR
18009 "Large Community list number (expanded)\n"
2f8cc0e5
DA
18010 "Sequence number of an entry\n"
18011 "Sequence number\n"
7336e101
SP
18012 "Specify large community to reject\n"
18013 "Specify large community to accept\n"
18014 "An ordered list as a regular-expression\n")
57d187bc 18015{
d62a17ae 18016 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18017 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18018}
18019
7336e101
SP
18020DEFUN (no_lcommunity_list_name_standard,
18021 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 18022 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
18023 NO_STR
18024 BGP_STR
18025 LCOMMUNITY_LIST_STR
18026 "Specify standard large-community-list\n"
18027 "Large Community list name\n"
2f8cc0e5
DA
18028 "Sequence number of an entry\n"
18029 "Sequence number\n"
7336e101
SP
18030 "Specify large community to reject\n"
18031 "Specify large community to accept\n"
18032 LCOMMUNITY_VAL_STR)
57d187bc 18033{
d62a17ae 18034 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18035 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18036}
18037
7336e101
SP
18038DEFUN (no_lcommunity_list_name_expanded,
18039 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 18040 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18041 NO_STR
18042 BGP_STR
18043 LCOMMUNITY_LIST_STR
18044 "Specify expanded large-community-list\n"
18045 "Large community list name\n"
2f8cc0e5
DA
18046 "Sequence number of an entry\n"
18047 "Sequence number\n"
7336e101
SP
18048 "Specify large community to reject\n"
18049 "Specify large community to accept\n"
18050 "An ordered list as a regular-expression\n")
57d187bc 18051{
d62a17ae 18052 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18053 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18054}
18055
d62a17ae 18056static void lcommunity_list_show(struct vty *vty, struct community_list *list)
18057{
18058 struct community_entry *entry;
18059
18060 for (entry = list->head; entry; entry = entry->next) {
18061 if (entry == list->head) {
18062 if (all_digit(list->name))
18063 vty_out(vty, "Large community %s list %s\n",
169b72c8 18064 entry->style ==
18065 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 18066 ? "standard"
18067 : "(expanded) access",
18068 list->name);
18069 else
18070 vty_out(vty,
18071 "Named large community %s list %s\n",
169b72c8 18072 entry->style ==
18073 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 18074 ? "standard"
18075 : "expanded",
18076 list->name);
18077 }
18078 if (entry->any)
18079 vty_out(vty, " %s\n",
18080 community_direct_str(entry->direct));
18081 else
18082 vty_out(vty, " %s %s\n",
18083 community_direct_str(entry->direct),
8d9b8ed9 18084 community_list_config_str(entry));
d62a17ae 18085 }
57d187bc
JS
18086}
18087
7336e101
SP
18088DEFUN (show_lcommunity_list,
18089 show_bgp_lcommunity_list_cmd,
18090 "show bgp large-community-list",
57d187bc 18091 SHOW_STR
7336e101 18092 BGP_STR
57d187bc
JS
18093 "List large-community list\n")
18094{
d62a17ae 18095 struct community_list *list;
18096 struct community_list_master *cm;
57d187bc 18097
d62a17ae 18098 cm = community_list_master_lookup(bgp_clist,
18099 LARGE_COMMUNITY_LIST_MASTER);
18100 if (!cm)
18101 return CMD_SUCCESS;
57d187bc 18102
d62a17ae 18103 for (list = cm->num.head; list; list = list->next)
18104 lcommunity_list_show(vty, list);
57d187bc 18105
d62a17ae 18106 for (list = cm->str.head; list; list = list->next)
18107 lcommunity_list_show(vty, list);
57d187bc 18108
d62a17ae 18109 return CMD_SUCCESS;
57d187bc
JS
18110}
18111
7336e101
SP
18112DEFUN (show_lcommunity_list_arg,
18113 show_bgp_lcommunity_list_arg_cmd,
960b69b9 18114 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
18115 SHOW_STR
18116 BGP_STR
57d187bc 18117 "List large-community list\n"
960b69b9 18118 "Large-community-list number\n"
18119 "Large-community-list name\n"
18120 "Detailed information on large-community-list\n")
57d187bc 18121{
d62a17ae 18122 struct community_list *list;
57d187bc 18123
e237b0d2 18124 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 18125 LARGE_COMMUNITY_LIST_MASTER);
18126 if (!list) {
960b69b9 18127 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 18128 return CMD_WARNING;
18129 }
57d187bc 18130
d62a17ae 18131 lcommunity_list_show(vty, list);
57d187bc 18132
d62a17ae 18133 return CMD_SUCCESS;
57d187bc
JS
18134}
18135
718e3744 18136/* "extcommunity-list" keyword help string. */
18137#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
18138#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
18139
7336e101
SP
18140DEFUN (extcommunity_list_standard,
18141 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 18142 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 18143 BGP_STR
718e3744 18144 EXTCOMMUNITY_LIST_STR
18145 "Extended Community list number (standard)\n"
718e3744 18146 "Specify standard extcommunity-list\n"
5bf15956 18147 "Community list name\n"
2f8cc0e5
DA
18148 "Sequence number of an entry\n"
18149 "Sequence number\n"
718e3744 18150 "Specify community to reject\n"
18151 "Specify community to accept\n"
18152 EXTCOMMUNITY_VAL_STR)
18153{
d62a17ae 18154 int style = EXTCOMMUNITY_LIST_STANDARD;
18155 int direct = 0;
18156 char *cl_number_or_name = NULL;
2f8cc0e5 18157 char *seq = NULL;
42f914d4 18158
d62a17ae 18159 int idx = 0;
7b9a4750 18160
d62a17ae 18161 argv_find(argv, argc, "(1-99)", &idx);
18162 argv_find(argv, argc, "WORD", &idx);
18163 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 18164
409148f6 18165 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18166 seq = argv[idx]->arg;
18167
d62a17ae 18168 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18169 : COMMUNITY_DENY;
18170 argv_find(argv, argc, "AA:NN", &idx);
18171 char *str = argv_concat(argv, argc, idx);
42f914d4 18172
2f8cc0e5 18173 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 18174 direct, style);
42f914d4 18175
d62a17ae 18176 XFREE(MTYPE_TMP, str);
42f914d4 18177
d62a17ae 18178 if (ret < 0) {
18179 community_list_perror(vty, ret);
18180 return CMD_WARNING_CONFIG_FAILED;
18181 }
42f914d4 18182
d62a17ae 18183 return CMD_SUCCESS;
718e3744 18184}
18185
7336e101
SP
18186DEFUN (extcommunity_list_name_expanded,
18187 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 18188 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18189 BGP_STR
18190 EXTCOMMUNITY_LIST_STR
5bf15956 18191 "Extended Community list number (expanded)\n"
718e3744 18192 "Specify expanded extcommunity-list\n"
18193 "Extended Community list name\n"
2f8cc0e5
DA
18194 "Sequence number of an entry\n"
18195 "Sequence number\n"
718e3744 18196 "Specify community to reject\n"
18197 "Specify community to accept\n"
18198 "An ordered list as a regular-expression\n")
18199{
d62a17ae 18200 int style = EXTCOMMUNITY_LIST_EXPANDED;
18201 int direct = 0;
18202 char *cl_number_or_name = NULL;
2f8cc0e5 18203 char *seq = NULL;
d62a17ae 18204 int idx = 0;
7336e101 18205
d62a17ae 18206 argv_find(argv, argc, "(100-500)", &idx);
18207 argv_find(argv, argc, "WORD", &idx);
18208 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 18209
409148f6 18210 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18211 seq = argv[idx]->arg;
18212
d62a17ae 18213 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18214 : COMMUNITY_DENY;
18215 argv_find(argv, argc, "LINE", &idx);
18216 char *str = argv_concat(argv, argc, idx);
42f914d4 18217
2f8cc0e5 18218 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 18219 direct, style);
42f914d4 18220
d62a17ae 18221 XFREE(MTYPE_TMP, str);
42f914d4 18222
d62a17ae 18223 if (ret < 0) {
18224 community_list_perror(vty, ret);
18225 return CMD_WARNING_CONFIG_FAILED;
18226 }
42f914d4 18227
d62a17ae 18228 return CMD_SUCCESS;
718e3744 18229}
18230
7336e101
SP
18231DEFUN (no_extcommunity_list_standard_all,
18232 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 18233 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18234 NO_STR
18235 BGP_STR
18236 EXTCOMMUNITY_LIST_STR
813d4307 18237 "Extended Community list number (standard)\n"
718e3744 18238 "Specify standard extcommunity-list\n"
5bf15956 18239 "Community list name\n"
2f8cc0e5
DA
18240 "Sequence number of an entry\n"
18241 "Sequence number\n"
718e3744 18242 "Specify community to reject\n"
18243 "Specify community to accept\n"
18244 EXTCOMMUNITY_VAL_STR)
18245{
d62a17ae 18246 int style = EXTCOMMUNITY_LIST_STANDARD;
18247 int direct = 0;
18248 char *cl_number_or_name = NULL;
d4455c89 18249 char *str = NULL;
2f8cc0e5 18250 char *seq = NULL;
d62a17ae 18251 int idx = 0;
d4455c89 18252
409148f6 18253 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18254 seq = argv[idx]->arg;
18255
18256 idx = 0;
d4455c89
DA
18257 argv_find(argv, argc, "permit", &idx);
18258 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
18259 if (idx) {
18260 direct = argv_find(argv, argc, "permit", &idx)
18261 ? COMMUNITY_PERMIT
18262 : COMMUNITY_DENY;
18263
18264 idx = 0;
18265 argv_find(argv, argc, "AA:NN", &idx);
18266 str = argv_concat(argv, argc, idx);
18267 }
18268
18269 idx = 0;
d62a17ae 18270 argv_find(argv, argc, "(1-99)", &idx);
18271 argv_find(argv, argc, "WORD", &idx);
18272 cl_number_or_name = argv[idx]->arg;
42f914d4 18273
d62a17ae 18274 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18275 seq, direct, style);
42f914d4 18276
d62a17ae 18277 XFREE(MTYPE_TMP, str);
42f914d4 18278
d62a17ae 18279 if (ret < 0) {
18280 community_list_perror(vty, ret);
18281 return CMD_WARNING_CONFIG_FAILED;
18282 }
42f914d4 18283
d62a17ae 18284 return CMD_SUCCESS;
718e3744 18285}
18286
d4455c89
DA
18287ALIAS(no_extcommunity_list_standard_all,
18288 no_bgp_extcommunity_list_standard_all_list_cmd,
18289 "no bgp extcommunity-list <(1-99)|standard WORD>",
18290 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18291 "Extended Community list number (standard)\n"
18292 "Specify standard extcommunity-list\n"
18293 "Community list name\n")
18294
7336e101
SP
18295DEFUN (no_extcommunity_list_expanded_all,
18296 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 18297 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18298 NO_STR
18299 BGP_STR
18300 EXTCOMMUNITY_LIST_STR
718e3744 18301 "Extended Community list number (expanded)\n"
718e3744 18302 "Specify expanded extcommunity-list\n"
5bf15956 18303 "Extended Community list name\n"
2f8cc0e5
DA
18304 "Sequence number of an entry\n"
18305 "Sequence number\n"
718e3744 18306 "Specify community to reject\n"
18307 "Specify community to accept\n"
18308 "An ordered list as a regular-expression\n")
18309{
d62a17ae 18310 int style = EXTCOMMUNITY_LIST_EXPANDED;
18311 int direct = 0;
18312 char *cl_number_or_name = NULL;
d4455c89 18313 char *str = NULL;
2f8cc0e5 18314 char *seq = NULL;
d62a17ae 18315 int idx = 0;
d4455c89 18316
409148f6 18317 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18318 seq = argv[idx]->arg;
18319
18320 idx = 0;
d4455c89
DA
18321 argv_find(argv, argc, "permit", &idx);
18322 argv_find(argv, argc, "deny", &idx);
18323
18324 if (idx) {
18325 direct = argv_find(argv, argc, "permit", &idx)
18326 ? COMMUNITY_PERMIT
18327 : COMMUNITY_DENY;
18328
18329 idx = 0;
18330 argv_find(argv, argc, "LINE", &idx);
18331 str = argv_concat(argv, argc, idx);
18332 }
18333
18334 idx = 0;
d62a17ae 18335 argv_find(argv, argc, "(100-500)", &idx);
18336 argv_find(argv, argc, "WORD", &idx);
18337 cl_number_or_name = argv[idx]->arg;
42f914d4 18338
d62a17ae 18339 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18340 seq, direct, style);
42f914d4 18341
d62a17ae 18342 XFREE(MTYPE_TMP, str);
42f914d4 18343
d62a17ae 18344 if (ret < 0) {
18345 community_list_perror(vty, ret);
18346 return CMD_WARNING_CONFIG_FAILED;
18347 }
42f914d4 18348
d62a17ae 18349 return CMD_SUCCESS;
718e3744 18350}
18351
d4455c89
DA
18352ALIAS(no_extcommunity_list_expanded_all,
18353 no_bgp_extcommunity_list_expanded_all_list_cmd,
18354 "no bgp extcommunity-list <(100-500)|expanded WORD>",
18355 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18356 "Extended Community list number (expanded)\n"
18357 "Specify expanded extcommunity-list\n"
18358 "Extended Community list name\n")
18359
d62a17ae 18360static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 18361{
d62a17ae 18362 struct community_entry *entry;
718e3744 18363
d62a17ae 18364 for (entry = list->head; entry; entry = entry->next) {
18365 if (entry == list->head) {
18366 if (all_digit(list->name))
18367 vty_out(vty, "Extended community %s list %s\n",
18368 entry->style == EXTCOMMUNITY_LIST_STANDARD
18369 ? "standard"
18370 : "(expanded) access",
18371 list->name);
18372 else
18373 vty_out(vty,
18374 "Named extended community %s list %s\n",
18375 entry->style == EXTCOMMUNITY_LIST_STANDARD
18376 ? "standard"
18377 : "expanded",
18378 list->name);
18379 }
18380 if (entry->any)
18381 vty_out(vty, " %s\n",
18382 community_direct_str(entry->direct));
18383 else
18384 vty_out(vty, " %s %s\n",
18385 community_direct_str(entry->direct),
8d9b8ed9 18386 community_list_config_str(entry));
d62a17ae 18387 }
718e3744 18388}
18389
7336e101
SP
18390DEFUN (show_extcommunity_list,
18391 show_bgp_extcommunity_list_cmd,
18392 "show bgp extcommunity-list",
718e3744 18393 SHOW_STR
7336e101 18394 BGP_STR
718e3744 18395 "List extended-community list\n")
18396{
d62a17ae 18397 struct community_list *list;
18398 struct community_list_master *cm;
718e3744 18399
d62a17ae 18400 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18401 if (!cm)
18402 return CMD_SUCCESS;
718e3744 18403
d62a17ae 18404 for (list = cm->num.head; list; list = list->next)
18405 extcommunity_list_show(vty, list);
718e3744 18406
d62a17ae 18407 for (list = cm->str.head; list; list = list->next)
18408 extcommunity_list_show(vty, list);
718e3744 18409
d62a17ae 18410 return CMD_SUCCESS;
718e3744 18411}
18412
7336e101
SP
18413DEFUN (show_extcommunity_list_arg,
18414 show_bgp_extcommunity_list_arg_cmd,
960b69b9 18415 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
18416 SHOW_STR
18417 BGP_STR
718e3744 18418 "List extended-community list\n"
18419 "Extcommunity-list number\n"
960b69b9 18420 "Extcommunity-list name\n"
18421 "Detailed information on extcommunity-list\n")
718e3744 18422{
d62a17ae 18423 int idx_comm_list = 3;
18424 struct community_list *list;
718e3744 18425
e237b0d2 18426 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18427 EXTCOMMUNITY_LIST_MASTER);
18428 if (!list) {
18429 vty_out(vty, "%% Can't find extcommunity-list\n");
18430 return CMD_WARNING;
18431 }
718e3744 18432
d62a17ae 18433 extcommunity_list_show(vty, list);
718e3744 18434
d62a17ae 18435 return CMD_SUCCESS;
718e3744 18436}
6b0655a2 18437
718e3744 18438/* Display community-list and extcommunity-list configuration. */
d62a17ae 18439static int community_list_config_write(struct vty *vty)
18440{
18441 struct community_list *list;
18442 struct community_entry *entry;
18443 struct community_list_master *cm;
18444 int write = 0;
18445
18446 /* Community-list. */
18447 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18448
18449 for (list = cm->num.head; list; list = list->next)
18450 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18451 vty_out(vty,
18452 "bgp community-list %s seq %" PRId64 " %s %s\n",
18453 list->name, entry->seq,
d62a17ae 18454 community_direct_str(entry->direct),
18455 community_list_config_str(entry));
18456 write++;
18457 }
18458 for (list = cm->str.head; list; list = list->next)
18459 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18460 vty_out(vty,
18461 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 18462 entry->style == COMMUNITY_LIST_STANDARD
18463 ? "standard"
18464 : "expanded",
2f8cc0e5
DA
18465 list->name, entry->seq,
18466 community_direct_str(entry->direct),
d62a17ae 18467 community_list_config_str(entry));
18468 write++;
18469 }
18470
18471 /* Extcommunity-list. */
18472 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18473
18474 for (list = cm->num.head; list; list = list->next)
18475 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18476 vty_out(vty,
18477 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
18478 list->name, entry->seq,
18479 community_direct_str(entry->direct),
d62a17ae 18480 community_list_config_str(entry));
18481 write++;
18482 }
18483 for (list = cm->str.head; list; list = list->next)
18484 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18485 vty_out(vty,
6cde4b45 18486 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 18487 entry->style == EXTCOMMUNITY_LIST_STANDARD
18488 ? "standard"
18489 : "expanded",
2f8cc0e5
DA
18490 list->name, entry->seq,
18491 community_direct_str(entry->direct),
d62a17ae 18492 community_list_config_str(entry));
18493 write++;
18494 }
18495
18496
18497 /* lcommunity-list. */
18498 cm = community_list_master_lookup(bgp_clist,
18499 LARGE_COMMUNITY_LIST_MASTER);
18500
18501 for (list = cm->num.head; list; list = list->next)
18502 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18503 vty_out(vty,
6cde4b45 18504 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
18505 list->name, entry->seq,
18506 community_direct_str(entry->direct),
d62a17ae 18507 community_list_config_str(entry));
18508 write++;
18509 }
18510 for (list = cm->str.head; list; list = list->next)
18511 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18512 vty_out(vty,
6cde4b45 18513 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 18514
d62a17ae 18515 entry->style == LARGE_COMMUNITY_LIST_STANDARD
18516 ? "standard"
18517 : "expanded",
2f8cc0e5 18518 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 18519 community_list_config_str(entry));
18520 write++;
18521 }
18522
18523 return write;
18524}
18525
612c2c15 18526static int community_list_config_write(struct vty *vty);
d62a17ae 18527static struct cmd_node community_list_node = {
f4b8291f 18528 .name = "community list",
62b346ee
DL
18529 .node = COMMUNITY_LIST_NODE,
18530 .prompt = "",
612c2c15 18531 .config_write = community_list_config_write,
718e3744 18532};
18533
d62a17ae 18534static void community_list_vty(void)
18535{
612c2c15 18536 install_node(&community_list_node);
d62a17ae 18537
18538 /* Community-list. */
7336e101
SP
18539 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
18540 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
18541 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 18542 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 18543 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 18544 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
18545 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
18546 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 18547
18548 /* Extcommunity-list. */
7336e101
SP
18549 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
18550 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
18551 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
18552 install_element(CONFIG_NODE,
18553 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 18554 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
18555 install_element(CONFIG_NODE,
18556 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
18557 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
18558 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 18559
18560 /* Large Community List */
7336e101 18561 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
18562 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
18563 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 18564 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
18565 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
18566 install_element(CONFIG_NODE,
18567 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
18568 install_element(CONFIG_NODE,
18569 &no_bgp_lcommunity_list_name_expanded_all_cmd);
18570 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
18571 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
18572 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
18573 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
18574 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
18575 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 18576}