]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
topotest: add bgp flowspec ipv4/ipv6 test
[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
d62a17ae 1645static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1646 const char *wait)
f188f2c4 1647{
d62a17ae 1648 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1649 uint16_t update_delay;
1650 uint16_t establish_wait;
f188f2c4 1651
d62a17ae 1652 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1653
d62a17ae 1654 if (!wait) /* update-delay <delay> */
1655 {
1656 bgp->v_update_delay = update_delay;
1657 bgp->v_establish_wait = bgp->v_update_delay;
1658 return CMD_SUCCESS;
1659 }
f188f2c4 1660
d62a17ae 1661 /* update-delay <delay> <establish-wait> */
1662 establish_wait = atoi(wait);
1663 if (update_delay < establish_wait) {
1664 vty_out(vty,
1665 "%%Failed: update-delay less than the establish-wait!\n");
1666 return CMD_WARNING_CONFIG_FAILED;
1667 }
f188f2c4 1668
d62a17ae 1669 bgp->v_update_delay = update_delay;
1670 bgp->v_establish_wait = establish_wait;
f188f2c4 1671
d62a17ae 1672 return CMD_SUCCESS;
f188f2c4
DS
1673}
1674
d62a17ae 1675static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1676{
d62a17ae 1677 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1678
d62a17ae 1679 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1680 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1681
d62a17ae 1682 return CMD_SUCCESS;
f188f2c4
DS
1683}
1684
2b791107 1685void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1686{
d62a17ae 1687 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1688 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1689 if (bgp->v_update_delay != bgp->v_establish_wait)
1690 vty_out(vty, " %d", bgp->v_establish_wait);
1691 vty_out(vty, "\n");
1692 }
f188f2c4
DS
1693}
1694
1695
1696/* Update-delay configuration */
1697DEFUN (bgp_update_delay,
1698 bgp_update_delay_cmd,
6147e2c6 1699 "update-delay (0-3600)",
f188f2c4
DS
1700 "Force initial delay for best-path and updates\n"
1701 "Seconds\n")
1702{
d62a17ae 1703 int idx_number = 1;
1704 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1705}
1706
1707DEFUN (bgp_update_delay_establish_wait,
1708 bgp_update_delay_establish_wait_cmd,
6147e2c6 1709 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1710 "Force initial delay for best-path and updates\n"
1711 "Seconds\n"
f188f2c4
DS
1712 "Seconds\n")
1713{
d62a17ae 1714 int idx_number = 1;
1715 int idx_number_2 = 2;
1716 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1717 argv[idx_number_2]->arg);
f188f2c4
DS
1718}
1719
1720/* Update-delay deconfiguration */
1721DEFUN (no_bgp_update_delay,
1722 no_bgp_update_delay_cmd,
838758ac
DW
1723 "no update-delay [(0-3600) [(1-3600)]]",
1724 NO_STR
f188f2c4 1725 "Force initial delay for best-path and updates\n"
838758ac 1726 "Seconds\n"
7111c1a0 1727 "Seconds\n")
f188f2c4 1728{
d62a17ae 1729 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1730}
1731
5e242b0d 1732
8fa7732f
QY
1733static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1734 bool set)
cb1faec9 1735{
d62a17ae 1736 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1737
8fa7732f
QY
1738 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1739 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
1740
1741 return CMD_SUCCESS;
1742}
1743
8fa7732f
QY
1744static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1745 bool set)
555e09d4
QY
1746{
1747 VTY_DECLVAR_CONTEXT(bgp, bgp);
1748
8fa7732f
QY
1749 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1750 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 1751
d62a17ae 1752 return CMD_SUCCESS;
cb1faec9
DS
1753}
1754
2b791107 1755void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1756{
555e09d4
QY
1757 uint32_t quanta =
1758 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1759 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1760 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1761}
1762
555e09d4
QY
1763void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1764{
1765 uint32_t quanta =
1766 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1767 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1768 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1769}
cb1faec9 1770
8fa7732f
QY
1771/* Packet quanta configuration
1772 *
1773 * XXX: The value set here controls the size of a stack buffer in the IO
1774 * thread. When changing these limits be careful to prevent stack overflow.
1775 *
1776 * Furthermore, the maximums used here should correspond to
1777 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1778 */
1779DEFPY (bgp_wpkt_quanta,
cb1faec9 1780 bgp_wpkt_quanta_cmd,
8fa7732f 1781 "[no] write-quanta (1-64)$quanta",
d7fa34c1 1782 NO_STR
8fa7732f 1783 "How many packets to write to peer socket per run\n"
cb1faec9
DS
1784 "Number of packets\n")
1785{
8fa7732f 1786 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
cb1faec9
DS
1787}
1788
8fa7732f 1789DEFPY (bgp_rpkt_quanta,
555e09d4 1790 bgp_rpkt_quanta_cmd,
8fa7732f 1791 "[no] read-quanta (1-10)$quanta",
555e09d4
QY
1792 NO_STR
1793 "How many packets to read from peer socket per I/O cycle\n"
1794 "Number of packets\n")
1795{
8fa7732f 1796 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
1797}
1798
2b791107 1799void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1800{
37a333fe 1801 if (!bgp->heuristic_coalesce)
d62a17ae 1802 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1803}
1804
1805
1806DEFUN (bgp_coalesce_time,
1807 bgp_coalesce_time_cmd,
6147e2c6 1808 "coalesce-time (0-4294967295)",
3f9c7369
DS
1809 "Subgroup coalesce timer\n"
1810 "Subgroup coalesce timer value (in ms)\n")
1811{
d62a17ae 1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1813
d62a17ae 1814 int idx = 0;
1815 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1816 bgp->heuristic_coalesce = false;
d62a17ae 1817 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1818 return CMD_SUCCESS;
3f9c7369
DS
1819}
1820
1821DEFUN (no_bgp_coalesce_time,
1822 no_bgp_coalesce_time_cmd,
6147e2c6 1823 "no coalesce-time (0-4294967295)",
3a2d747c 1824 NO_STR
3f9c7369
DS
1825 "Subgroup coalesce timer\n"
1826 "Subgroup coalesce timer value (in ms)\n")
1827{
d62a17ae 1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1829
37a333fe 1830 bgp->heuristic_coalesce = true;
d62a17ae 1831 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1832 return CMD_SUCCESS;
3f9c7369
DS
1833}
1834
5e242b0d
DS
1835/* Maximum-paths configuration */
1836DEFUN (bgp_maxpaths,
1837 bgp_maxpaths_cmd,
6319fd63 1838 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1839 "Forward packets over multiple paths\n"
1840 "Number of paths\n")
1841{
d62a17ae 1842 int idx_number = 1;
1843 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1844 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1845}
1846
d62a17ae 1847ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1848 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1849 "Forward packets over multiple paths\n"
1850 "Number of paths\n")
596c17ba 1851
165b5fff
JB
1852DEFUN (bgp_maxpaths_ibgp,
1853 bgp_maxpaths_ibgp_cmd,
6319fd63 1854 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1855 "Forward packets over multiple paths\n"
1856 "iBGP-multipath\n"
1857 "Number of paths\n")
1858{
d62a17ae 1859 int idx_number = 2;
1860 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1861 argv[idx_number]->arg, 0, 1);
5e242b0d 1862}
165b5fff 1863
d62a17ae 1864ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1865 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1866 "Forward packets over multiple paths\n"
1867 "iBGP-multipath\n"
1868 "Number of paths\n")
596c17ba 1869
5e242b0d
DS
1870DEFUN (bgp_maxpaths_ibgp_cluster,
1871 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1872 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1873 "Forward packets over multiple paths\n"
1874 "iBGP-multipath\n"
1875 "Number of paths\n"
1876 "Match the cluster length\n")
1877{
d62a17ae 1878 int idx_number = 2;
1879 return bgp_maxpaths_config_vty(
1880 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1881 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1882}
1883
d62a17ae 1884ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1885 "maximum-paths ibgp " CMD_RANGE_STR(
1886 1, MULTIPATH_NUM) " equal-cluster-length",
1887 "Forward packets over multiple paths\n"
1888 "iBGP-multipath\n"
1889 "Number of paths\n"
1890 "Match the cluster length\n")
596c17ba 1891
165b5fff
JB
1892DEFUN (no_bgp_maxpaths,
1893 no_bgp_maxpaths_cmd,
6319fd63 1894 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1895 NO_STR
1896 "Forward packets over multiple paths\n"
1897 "Number of paths\n")
1898{
d62a17ae 1899 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1900}
1901
d62a17ae 1902ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1903 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1904 "Forward packets over multiple paths\n"
1905 "Number of paths\n")
596c17ba 1906
165b5fff
JB
1907DEFUN (no_bgp_maxpaths_ibgp,
1908 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1909 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1910 NO_STR
1911 "Forward packets over multiple paths\n"
1912 "iBGP-multipath\n"
838758ac
DW
1913 "Number of paths\n"
1914 "Match the cluster length\n")
165b5fff 1915{
d62a17ae 1916 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1917}
1918
d62a17ae 1919ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1920 "no maximum-paths ibgp [" CMD_RANGE_STR(
1921 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1922 NO_STR
1923 "Forward packets over multiple paths\n"
1924 "iBGP-multipath\n"
1925 "Number of paths\n"
1926 "Match the cluster length\n")
596c17ba 1927
dd65f45e
DL
1928static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
1929 afi_t afi, safi_t safi)
165b5fff 1930{
d62a17ae 1931 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1932 vty_out(vty, " maximum-paths %d\n",
1933 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1934 }
165b5fff 1935
d62a17ae 1936 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1937 vty_out(vty, " maximum-paths ibgp %d",
1938 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1939 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1940 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1941 vty_out(vty, " equal-cluster-length");
1942 vty_out(vty, "\n");
1943 }
165b5fff 1944}
6b0655a2 1945
718e3744 1946/* BGP timers. */
1947
1948DEFUN (bgp_timers,
1949 bgp_timers_cmd,
6147e2c6 1950 "timers bgp (0-65535) (0-65535)",
718e3744 1951 "Adjust routing timers\n"
1952 "BGP timers\n"
1953 "Keepalive interval\n"
1954 "Holdtime\n")
1955{
d62a17ae 1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957 int idx_number = 2;
1958 int idx_number_2 = 3;
1959 unsigned long keepalive = 0;
1960 unsigned long holdtime = 0;
718e3744 1961
d62a17ae 1962 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1963 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1964
d62a17ae 1965 /* Holdtime value check. */
1966 if (holdtime < 3 && holdtime != 0) {
1967 vty_out(vty,
1968 "%% hold time value must be either 0 or greater than 3\n");
1969 return CMD_WARNING_CONFIG_FAILED;
1970 }
718e3744 1971
5d5393b9 1972 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY);
718e3744 1973
d62a17ae 1974 return CMD_SUCCESS;
718e3744 1975}
1976
1977DEFUN (no_bgp_timers,
1978 no_bgp_timers_cmd,
838758ac 1979 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1980 NO_STR
1981 "Adjust routing timers\n"
838758ac
DW
1982 "BGP timers\n"
1983 "Keepalive interval\n"
1984 "Holdtime\n")
718e3744 1985{
d62a17ae 1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
5d5393b9
DL
1987 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
1988 DFLT_BGP_CONNECT_RETRY);
718e3744 1989
d62a17ae 1990 return CMD_SUCCESS;
718e3744 1991}
1992
6b0655a2 1993
718e3744 1994DEFUN (bgp_client_to_client_reflection,
1995 bgp_client_to_client_reflection_cmd,
1996 "bgp client-to-client reflection",
1997 "BGP specific commands\n"
1998 "Configure client to client route reflection\n"
1999 "reflection of routes allowed\n")
2000{
d62a17ae 2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2002 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
d62a17ae 2003 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2004
d62a17ae 2005 return CMD_SUCCESS;
718e3744 2006}
2007
2008DEFUN (no_bgp_client_to_client_reflection,
2009 no_bgp_client_to_client_reflection_cmd,
2010 "no bgp client-to-client reflection",
2011 NO_STR
2012 "BGP specific commands\n"
2013 "Configure client to client route reflection\n"
2014 "reflection of routes allowed\n")
2015{
d62a17ae 2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2017 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
d62a17ae 2018 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2019
d62a17ae 2020 return CMD_SUCCESS;
718e3744 2021}
2022
2023/* "bgp always-compare-med" configuration. */
2024DEFUN (bgp_always_compare_med,
2025 bgp_always_compare_med_cmd,
2026 "bgp always-compare-med",
2027 "BGP specific commands\n"
2028 "Allow comparing MED from different neighbors\n")
2029{
d62a17ae 2030 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2031 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
d62a17ae 2032 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2033
d62a17ae 2034 return CMD_SUCCESS;
718e3744 2035}
2036
2037DEFUN (no_bgp_always_compare_med,
2038 no_bgp_always_compare_med_cmd,
2039 "no bgp always-compare-med",
2040 NO_STR
2041 "BGP specific commands\n"
2042 "Allow comparing MED from different neighbors\n")
2043{
d62a17ae 2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2045 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
d62a17ae 2046 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2047
d62a17ae 2048 return CMD_SUCCESS;
718e3744 2049}
6b0655a2 2050
9dac9fc8
DA
2051
2052DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2053 "bgp ebgp-requires-policy",
2054 "BGP specific commands\n"
2055 "Require in and out policy for eBGP peers (RFC8212)\n")
2056{
2057 VTY_DECLVAR_CONTEXT(bgp, bgp);
1d3fdccf 2058 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
9dac9fc8
DA
2059 return CMD_SUCCESS;
2060}
2061
2062DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2063 "no bgp ebgp-requires-policy",
2064 NO_STR
2065 "BGP specific commands\n"
2066 "Require in and out policy for eBGP peers (RFC8212)\n")
2067{
2068 VTY_DECLVAR_CONTEXT(bgp, bgp);
1d3fdccf 2069 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
9dac9fc8
DA
2070 return CMD_SUCCESS;
2071}
2072
fb29348a
DA
2073DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2074 "bgp reject-as-sets",
2075 "BGP specific commands\n"
2076 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2077{
2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079 struct listnode *node, *nnode;
2080 struct peer *peer;
2081
7f972cd8 2082 bgp->reject_as_sets = true;
fb29348a
DA
2083
2084 /* Reset existing BGP sessions to reject routes
2085 * with aspath containing AS_SET or AS_CONFED_SET.
2086 */
2087 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2088 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2089 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2090 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2091 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2092 }
2093 }
2094
2095 return CMD_SUCCESS;
2096}
2097
2098DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2099 "no bgp reject-as-sets",
2100 NO_STR
2101 "BGP specific commands\n"
2102 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2103{
2104 VTY_DECLVAR_CONTEXT(bgp, bgp);
2105 struct listnode *node, *nnode;
2106 struct peer *peer;
2107
7f972cd8 2108 bgp->reject_as_sets = false;
fb29348a
DA
2109
2110 /* Reset existing BGP sessions to reject routes
2111 * with aspath containing AS_SET or AS_CONFED_SET.
2112 */
2113 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2114 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2115 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2116 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2117 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2118 }
2119 }
2120
2121 return CMD_SUCCESS;
2122}
9dac9fc8 2123
718e3744 2124/* "bgp deterministic-med" configuration. */
2125DEFUN (bgp_deterministic_med,
2126 bgp_deterministic_med_cmd,
2127 "bgp deterministic-med",
2128 "BGP specific commands\n"
2129 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2130{
d62a17ae 2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 2132
892fedb6
DA
2133 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2134 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
d62a17ae 2135 bgp_recalculate_all_bestpaths(bgp);
2136 }
7aafcaca 2137
d62a17ae 2138 return CMD_SUCCESS;
718e3744 2139}
2140
2141DEFUN (no_bgp_deterministic_med,
2142 no_bgp_deterministic_med_cmd,
2143 "no bgp deterministic-med",
2144 NO_STR
2145 "BGP specific commands\n"
2146 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2147{
d62a17ae 2148 VTY_DECLVAR_CONTEXT(bgp, bgp);
2149 int bestpath_per_as_used;
2150 afi_t afi;
2151 safi_t safi;
2152 struct peer *peer;
2153 struct listnode *node, *nnode;
2154
892fedb6 2155 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
d62a17ae 2156 bestpath_per_as_used = 0;
2157
2158 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 2159 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
2160 if (bgp_addpath_dmed_required(
2161 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
2162 bestpath_per_as_used = 1;
2163 break;
2164 }
d62a17ae 2165
2166 if (bestpath_per_as_used)
2167 break;
2168 }
2169
2170 if (bestpath_per_as_used) {
2171 vty_out(vty,
2172 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2173 return CMD_WARNING_CONFIG_FAILED;
2174 } else {
892fedb6 2175 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
d62a17ae 2176 bgp_recalculate_all_bestpaths(bgp);
2177 }
2178 }
2179
2180 return CMD_SUCCESS;
718e3744 2181}
538621f2 2182
055679e9 2183/* "bgp graceful-restart mode" configuration. */
538621f2 2184DEFUN (bgp_graceful_restart,
2ba1fe69 2185 bgp_graceful_restart_cmd,
2186 "bgp graceful-restart",
2187 "BGP specific commands\n"
2188 GR_CMD
055679e9 2189 )
538621f2 2190{
055679e9 2191 int ret = BGP_GR_FAILURE;
2192
2193 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2194 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2195
d62a17ae 2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2197
2198 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2199
36235319
QY
2200 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2201 ret);
5cce3f05 2202
055679e9 2203 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2204 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2205 vty_out(vty,
2206 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2207 return bgp_vty_return(vty, ret);
538621f2 2208}
2209
2210DEFUN (no_bgp_graceful_restart,
2ba1fe69 2211 no_bgp_graceful_restart_cmd,
2212 "no bgp graceful-restart",
2213 NO_STR
2214 "BGP specific commands\n"
2215 NO_GR_CMD
055679e9 2216 )
538621f2 2217{
d62a17ae 2218 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2219
2220 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2221 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2222
2223 int ret = BGP_GR_FAILURE;
2224
2225 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2226
36235319
QY
2227 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2228 ret);
5cce3f05 2229
055679e9 2230 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2231 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2232 vty_out(vty,
2233 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2234
2235 return bgp_vty_return(vty, ret);
538621f2 2236}
2237
93406d87 2238DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2239 bgp_graceful_restart_stalepath_time_cmd,
2240 "bgp graceful-restart stalepath-time (1-4095)",
2241 "BGP specific commands\n"
2242 "Graceful restart capability parameters\n"
2243 "Set the max time to hold onto restarting peer's stale paths\n"
2244 "Delay value (seconds)\n")
93406d87 2245{
d62a17ae 2246 VTY_DECLVAR_CONTEXT(bgp, bgp);
2247 int idx_number = 3;
d7c0a89a 2248 uint32_t stalepath;
93406d87 2249
d62a17ae 2250 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2251 bgp->stalepath_time = stalepath;
2252 return CMD_SUCCESS;
93406d87 2253}
2254
eb6f1b41 2255DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2256 bgp_graceful_restart_restart_time_cmd,
2257 "bgp graceful-restart restart-time (1-4095)",
2258 "BGP specific commands\n"
2259 "Graceful restart capability parameters\n"
2260 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2261 "Delay value (seconds)\n")
eb6f1b41 2262{
d62a17ae 2263 VTY_DECLVAR_CONTEXT(bgp, bgp);
2264 int idx_number = 3;
d7c0a89a 2265 uint32_t restart;
eb6f1b41 2266
d62a17ae 2267 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2268 bgp->restart_time = restart;
2269 return CMD_SUCCESS;
eb6f1b41
PG
2270}
2271
cfd47646 2272DEFUN (bgp_graceful_restart_select_defer_time,
2273 bgp_graceful_restart_select_defer_time_cmd,
2274 "bgp graceful-restart select-defer-time (0-3600)",
2275 "BGP specific commands\n"
2276 "Graceful restart capability parameters\n"
2277 "Set the time to defer the BGP route selection after restart\n"
2278 "Delay value (seconds, 0 - disable)\n")
2279{
2280 VTY_DECLVAR_CONTEXT(bgp, bgp);
2281 int idx_number = 3;
2282 uint32_t defer_time;
2283
2284 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2285 bgp->select_defer_time = defer_time;
2286 if (defer_time == 0)
892fedb6 2287 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2288 else
892fedb6 2289 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2290
2291 return CMD_SUCCESS;
2292}
2293
93406d87 2294DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2295 no_bgp_graceful_restart_stalepath_time_cmd,
2296 "no bgp graceful-restart stalepath-time [(1-4095)]",
2297 NO_STR
2298 "BGP specific commands\n"
2299 "Graceful restart capability parameters\n"
2300 "Set the max time to hold onto restarting peer's stale paths\n"
2301 "Delay value (seconds)\n")
93406d87 2302{
d62a17ae 2303 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2304
d62a17ae 2305 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2306 return CMD_SUCCESS;
93406d87 2307}
2308
eb6f1b41 2309DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2310 no_bgp_graceful_restart_restart_time_cmd,
2311 "no bgp graceful-restart restart-time [(1-4095)]",
2312 NO_STR
2313 "BGP specific commands\n"
2314 "Graceful restart capability parameters\n"
2315 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2316 "Delay value (seconds)\n")
eb6f1b41 2317{
d62a17ae 2318 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2319
d62a17ae 2320 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2321 return CMD_SUCCESS;
eb6f1b41
PG
2322}
2323
cfd47646 2324DEFUN (no_bgp_graceful_restart_select_defer_time,
2325 no_bgp_graceful_restart_select_defer_time_cmd,
2326 "no bgp graceful-restart select-defer-time [(0-3600)]",
2327 NO_STR
2328 "BGP specific commands\n"
2329 "Graceful restart capability parameters\n"
2330 "Set the time to defer the BGP route selection after restart\n"
2331 "Delay value (seconds)\n")
2332{
2333 VTY_DECLVAR_CONTEXT(bgp, bgp);
2334
2335 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2336 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2337
2338 return CMD_SUCCESS;
2339}
2340
43fc21b3 2341DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2342 bgp_graceful_restart_preserve_fw_cmd,
2343 "bgp graceful-restart preserve-fw-state",
2344 "BGP specific commands\n"
2345 "Graceful restart capability parameters\n"
2346 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2347{
d62a17ae 2348 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2349 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2350 return CMD_SUCCESS;
43fc21b3
JC
2351}
2352
2353DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2354 no_bgp_graceful_restart_preserve_fw_cmd,
2355 "no bgp graceful-restart preserve-fw-state",
2356 NO_STR
2357 "BGP specific commands\n"
2358 "Graceful restart capability parameters\n"
2359 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2360{
d62a17ae 2361 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2362 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2363 return CMD_SUCCESS;
43fc21b3
JC
2364}
2365
055679e9 2366DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2367 bgp_graceful_restart_disable_cmd,
2368 "bgp graceful-restart-disable",
2369 "BGP specific commands\n"
2370 GR_DISABLE)
055679e9 2371{
2372 int ret = BGP_GR_FAILURE;
2373
2374 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2375 zlog_debug(
2ba1fe69 2376 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2377
055679e9 2378 VTY_DECLVAR_CONTEXT(bgp, bgp);
2379
2380 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2381
dc95985f 2382 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2383 bgp->peer, ret);
5cce3f05 2384
055679e9 2385 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2386 zlog_debug(
2ba1fe69 2387 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2388 vty_out(vty,
2389 "Graceful restart configuration changed, reset all peers to take effect\n");
2390
055679e9 2391 return bgp_vty_return(vty, ret);
2392}
2393
2394DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2395 no_bgp_graceful_restart_disable_cmd,
2396 "no bgp graceful-restart-disable",
2397 NO_STR
2398 "BGP specific commands\n"
2399 NO_GR_DISABLE
055679e9 2400 )
2401{
2402 VTY_DECLVAR_CONTEXT(bgp, bgp);
2403
2404 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2405 zlog_debug(
2ba1fe69 2406 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2407
2408 int ret = BGP_GR_FAILURE;
2409
2410 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2411
36235319
QY
2412 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2413 ret);
5cce3f05 2414
055679e9 2415 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2416 zlog_debug(
2ba1fe69 2417 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2418 vty_out(vty,
2419 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2420
2421 return bgp_vty_return(vty, ret);
2422}
2423
2424DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2425 bgp_neighbor_graceful_restart_set_cmd,
2426 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2427 NEIGHBOR_STR
2428 NEIGHBOR_ADDR_STR2
2429 GR_NEIGHBOR_CMD
055679e9 2430 )
2431{
2432 int idx_peer = 1;
2433 struct peer *peer;
2434 int ret = BGP_GR_FAILURE;
2435
dc95985f 2436 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2437
055679e9 2438 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2439 zlog_debug(
2ba1fe69 2440 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2441
055679e9 2442 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2443 if (!peer)
2444 return CMD_WARNING_CONFIG_FAILED;
2445
2446 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2447
dc95985f 2448 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2449 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2450
2451 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2452 zlog_debug(
2ba1fe69 2453 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2454 vty_out(vty,
2455 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2456
2457 return bgp_vty_return(vty, ret);
2458}
2459
2460DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2461 no_bgp_neighbor_graceful_restart_set_cmd,
2462 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2463 NO_STR
2464 NEIGHBOR_STR
2465 NEIGHBOR_ADDR_STR2
2466 NO_GR_NEIGHBOR_CMD
055679e9 2467 )
2468{
2469 int idx_peer = 2;
2470 int ret = BGP_GR_FAILURE;
2471 struct peer *peer;
2472
dc95985f 2473 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2474
055679e9 2475 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2476 if (!peer)
2477 return CMD_WARNING_CONFIG_FAILED;
2478
2479 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2480 zlog_debug(
2ba1fe69 2481 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2482
2483 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2484
dc95985f 2485 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2486 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2487
2488 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2489 zlog_debug(
2ba1fe69 2490 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2491 vty_out(vty,
2492 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2493
2494 return bgp_vty_return(vty, ret);
2495}
2496
2497DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2498 bgp_neighbor_graceful_restart_helper_set_cmd,
2499 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2500 NEIGHBOR_STR
2501 NEIGHBOR_ADDR_STR2
2502 GR_NEIGHBOR_HELPER_CMD
055679e9 2503 )
2504{
2505 int idx_peer = 1;
2506 struct peer *peer;
2507 int ret = BGP_GR_FAILURE;
2508
dc95985f 2509 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2510
055679e9 2511 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2512 zlog_debug(
2ba1fe69 2513 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2514
055679e9 2515 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2516
055679e9 2517 if (!peer)
2518 return CMD_WARNING_CONFIG_FAILED;
2519
2520
2521 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2522
dc95985f 2523 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2524 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2525
055679e9 2526 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2527 zlog_debug(
2ba1fe69 2528 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2529 vty_out(vty,
2530 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2531
2532 return bgp_vty_return(vty, ret);
2533}
2534
2535DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2536 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2537 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2538 NO_STR
2539 NEIGHBOR_STR
2540 NEIGHBOR_ADDR_STR2
2541 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2542 )
2543{
2544 int idx_peer = 2;
2545 int ret = BGP_GR_FAILURE;
2546 struct peer *peer;
2547
dc95985f 2548 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2549
055679e9 2550 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2551 if (!peer)
2552 return CMD_WARNING_CONFIG_FAILED;
2553
2554 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2555 zlog_debug(
2ba1fe69 2556 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 2557
36235319 2558 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 2559
dc95985f 2560 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2561 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2562
2563 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2564 zlog_debug(
2ba1fe69 2565 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2566 vty_out(vty,
2567 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2568
2569 return bgp_vty_return(vty, ret);
2570}
2571
2572DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 2573 bgp_neighbor_graceful_restart_disable_set_cmd,
2574 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2575 NEIGHBOR_STR
2576 NEIGHBOR_ADDR_STR2
2577 GR_NEIGHBOR_DISABLE_CMD
055679e9 2578 )
2579{
2580 int idx_peer = 1;
2581 struct peer *peer;
2582 int ret = BGP_GR_FAILURE;
2583
dc95985f 2584 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2585
055679e9 2586 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2587 zlog_debug(
2ba1fe69 2588 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2589
2590 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2591 if (!peer)
2592 return CMD_WARNING_CONFIG_FAILED;
2593
36235319 2594 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 2595
2596 if (peer->bgp->t_startup)
2597 bgp_peer_gr_flags_update(peer);
2598
dc95985f 2599 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2600 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2601
055679e9 2602 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2603 zlog_debug(
2ba1fe69 2604 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2605 vty_out(vty,
2606 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2607
2608 return bgp_vty_return(vty, ret);
2609}
2610
2611DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 2612 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2613 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2614 NO_STR
2615 NEIGHBOR_STR
2616 NEIGHBOR_ADDR_STR2
2617 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 2618 )
2619{
2620 int idx_peer = 2;
2621 int ret = BGP_GR_FAILURE;
2622 struct peer *peer;
2623
dc95985f 2624 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2625
055679e9 2626 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2627 if (!peer)
2628 return CMD_WARNING_CONFIG_FAILED;
2629
2630 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2631 zlog_debug(
2ba1fe69 2632 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2633
2634 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2635
dc95985f 2636 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2637 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2638
2639 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2640 zlog_debug(
2ba1fe69 2641 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2642 vty_out(vty,
2643 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2644
2645 return bgp_vty_return(vty, ret);
2646}
2647
d6e3c15b 2648DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2649 bgp_graceful_restart_disable_eor_cmd,
2650 "bgp graceful-restart disable-eor",
2651 "BGP specific commands\n"
2652 "Graceful restart configuration parameters\n"
2653 "Disable EOR Check\n")
2654{
2655 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2656 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2657
d6e3c15b 2658 return CMD_SUCCESS;
2659}
2660
2661DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2662 no_bgp_graceful_restart_disable_eor_cmd,
2663 "no bgp graceful-restart disable-eor",
2664 NO_STR
2665 "BGP specific commands\n"
2666 "Graceful restart configuration parameters\n"
2667 "Disable EOR Check\n")
2668{
2669 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2670 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2671
2672 return CMD_SUCCESS;
2673}
2674
2675DEFUN (bgp_graceful_restart_rib_stale_time,
2676 bgp_graceful_restart_rib_stale_time_cmd,
2677 "bgp graceful-restart rib-stale-time (1-3600)",
2678 "BGP specific commands\n"
2679 "Graceful restart configuration parameters\n"
2680 "Specify the stale route removal timer in rib\n"
2681 "Delay value (seconds)\n")
2682{
2683 VTY_DECLVAR_CONTEXT(bgp, bgp);
2684 int idx_number = 3;
2685 uint32_t stale_time;
2686
2687 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2688 bgp->rib_stale_time = stale_time;
2689 /* Send the stale timer update message to RIB */
2690 if (bgp_zebra_stale_timer_update(bgp))
2691 return CMD_WARNING;
2692
2693 return CMD_SUCCESS;
2694}
2695
2696DEFUN (no_bgp_graceful_restart_rib_stale_time,
2697 no_bgp_graceful_restart_rib_stale_time_cmd,
2698 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2699 NO_STR
2700 "BGP specific commands\n"
2701 "Graceful restart configuration parameters\n"
2702 "Specify the stale route removal timer in rib\n"
2703 "Delay value (seconds)\n")
2704{
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706
2707 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
2708 /* Send the stale timer update message to RIB */
2709 if (bgp_zebra_stale_timer_update(bgp))
2710 return CMD_WARNING;
2711
d6e3c15b 2712 return CMD_SUCCESS;
2713}
2714
7f323236
DW
2715/* "bgp graceful-shutdown" configuration */
2716DEFUN (bgp_graceful_shutdown,
2717 bgp_graceful_shutdown_cmd,
2718 "bgp graceful-shutdown",
2719 BGP_STR
2720 "Graceful shutdown parameters\n")
2721{
2722 VTY_DECLVAR_CONTEXT(bgp, bgp);
2723
892fedb6
DA
2724 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2725 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
7f323236
DW
2726 bgp_static_redo_import_check(bgp);
2727 bgp_redistribute_redo(bgp);
2728 bgp_clear_star_soft_out(vty, bgp->name);
2729 bgp_clear_star_soft_in(vty, bgp->name);
2730 }
2731
2732 return CMD_SUCCESS;
2733}
2734
2735DEFUN (no_bgp_graceful_shutdown,
2736 no_bgp_graceful_shutdown_cmd,
2737 "no bgp graceful-shutdown",
2738 NO_STR
2739 BGP_STR
2740 "Graceful shutdown parameters\n")
2741{
2742 VTY_DECLVAR_CONTEXT(bgp, bgp);
2743
892fedb6
DA
2744 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2745 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
7f323236
DW
2746 bgp_static_redo_import_check(bgp);
2747 bgp_redistribute_redo(bgp);
2748 bgp_clear_star_soft_out(vty, bgp->name);
2749 bgp_clear_star_soft_in(vty, bgp->name);
2750 }
2751
2752 return CMD_SUCCESS;
2753}
2754
718e3744 2755/* "bgp fast-external-failover" configuration. */
2756DEFUN (bgp_fast_external_failover,
2757 bgp_fast_external_failover_cmd,
2758 "bgp fast-external-failover",
2759 BGP_STR
2760 "Immediately reset session if a link to a directly connected external peer goes down\n")
2761{
d62a17ae 2762 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2763 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
d62a17ae 2764 return CMD_SUCCESS;
718e3744 2765}
2766
2767DEFUN (no_bgp_fast_external_failover,
2768 no_bgp_fast_external_failover_cmd,
2769 "no bgp fast-external-failover",
2770 NO_STR
2771 BGP_STR
2772 "Immediately reset session if a link to a directly connected external peer goes down\n")
2773{
d62a17ae 2774 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2775 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
d62a17ae 2776 return CMD_SUCCESS;
718e3744 2777}
6b0655a2 2778
718e3744 2779/* "bgp bestpath compare-routerid" configuration. */
2780DEFUN (bgp_bestpath_compare_router_id,
2781 bgp_bestpath_compare_router_id_cmd,
2782 "bgp bestpath compare-routerid",
2783 "BGP specific commands\n"
2784 "Change the default bestpath selection\n"
2785 "Compare router-id for identical EBGP paths\n")
2786{
d62a17ae 2787 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2788 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
d62a17ae 2789 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2790
d62a17ae 2791 return CMD_SUCCESS;
718e3744 2792}
2793
2794DEFUN (no_bgp_bestpath_compare_router_id,
2795 no_bgp_bestpath_compare_router_id_cmd,
2796 "no bgp bestpath compare-routerid",
2797 NO_STR
2798 "BGP specific commands\n"
2799 "Change the default bestpath selection\n"
2800 "Compare router-id for identical EBGP paths\n")
2801{
d62a17ae 2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2803 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
d62a17ae 2804 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2805
d62a17ae 2806 return CMD_SUCCESS;
718e3744 2807}
6b0655a2 2808
718e3744 2809/* "bgp bestpath as-path ignore" configuration. */
2810DEFUN (bgp_bestpath_aspath_ignore,
2811 bgp_bestpath_aspath_ignore_cmd,
2812 "bgp bestpath as-path ignore",
2813 "BGP specific commands\n"
2814 "Change the default bestpath selection\n"
2815 "AS-path attribute\n"
2816 "Ignore as-path length in selecting a route\n")
2817{
d62a17ae 2818 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2819 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
d62a17ae 2820 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2821
d62a17ae 2822 return CMD_SUCCESS;
718e3744 2823}
2824
2825DEFUN (no_bgp_bestpath_aspath_ignore,
2826 no_bgp_bestpath_aspath_ignore_cmd,
2827 "no bgp bestpath as-path ignore",
2828 NO_STR
2829 "BGP specific commands\n"
2830 "Change the default bestpath selection\n"
2831 "AS-path attribute\n"
2832 "Ignore as-path length in selecting a route\n")
2833{
d62a17ae 2834 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2835 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
d62a17ae 2836 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2837
d62a17ae 2838 return CMD_SUCCESS;
718e3744 2839}
6b0655a2 2840
6811845b 2841/* "bgp bestpath as-path confed" configuration. */
2842DEFUN (bgp_bestpath_aspath_confed,
2843 bgp_bestpath_aspath_confed_cmd,
2844 "bgp bestpath as-path confed",
2845 "BGP specific commands\n"
2846 "Change the default bestpath selection\n"
2847 "AS-path attribute\n"
2848 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2849{
d62a17ae 2850 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2851 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
d62a17ae 2852 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2853
d62a17ae 2854 return CMD_SUCCESS;
6811845b 2855}
2856
2857DEFUN (no_bgp_bestpath_aspath_confed,
2858 no_bgp_bestpath_aspath_confed_cmd,
2859 "no bgp bestpath as-path confed",
2860 NO_STR
2861 "BGP specific commands\n"
2862 "Change the default bestpath selection\n"
2863 "AS-path attribute\n"
2864 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2865{
d62a17ae 2866 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2867 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
d62a17ae 2868 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2869
d62a17ae 2870 return CMD_SUCCESS;
6811845b 2871}
6b0655a2 2872
2fdd455c
PM
2873/* "bgp bestpath as-path multipath-relax" configuration. */
2874DEFUN (bgp_bestpath_aspath_multipath_relax,
2875 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2876 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2877 "BGP specific commands\n"
2878 "Change the default bestpath selection\n"
2879 "AS-path attribute\n"
2880 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2881 "Generate an AS_SET\n"
16fc1eec
DS
2882 "Do not generate an AS_SET\n")
2883{
d62a17ae 2884 VTY_DECLVAR_CONTEXT(bgp, bgp);
2885 int idx = 0;
892fedb6 2886 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2887
d62a17ae 2888 /* no-as-set is now the default behavior so we can silently
2889 * ignore it */
2890 if (argv_find(argv, argc, "as-set", &idx))
892fedb6 2891 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 2892 else
892fedb6 2893 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2894
d62a17ae 2895 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2896
d62a17ae 2897 return CMD_SUCCESS;
16fc1eec
DS
2898}
2899
219178b6
DW
2900DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2901 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2902 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2903 NO_STR
2904 "BGP specific commands\n"
2905 "Change the default bestpath selection\n"
2906 "AS-path attribute\n"
2907 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2908 "Generate an AS_SET\n"
16fc1eec
DS
2909 "Do not generate an AS_SET\n")
2910{
d62a17ae 2911 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
2912 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2913 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 2914 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2915
d62a17ae 2916 return CMD_SUCCESS;
2fdd455c 2917}
6b0655a2 2918
848973c7 2919/* "bgp log-neighbor-changes" configuration. */
2920DEFUN (bgp_log_neighbor_changes,
2921 bgp_log_neighbor_changes_cmd,
2922 "bgp log-neighbor-changes",
2923 "BGP specific commands\n"
2924 "Log neighbor up/down and reset reason\n")
2925{
d62a17ae 2926 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2927 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
d62a17ae 2928 return CMD_SUCCESS;
848973c7 2929}
2930
2931DEFUN (no_bgp_log_neighbor_changes,
2932 no_bgp_log_neighbor_changes_cmd,
2933 "no bgp log-neighbor-changes",
2934 NO_STR
2935 "BGP specific commands\n"
2936 "Log neighbor up/down and reset reason\n")
2937{
d62a17ae 2938 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2939 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
d62a17ae 2940 return CMD_SUCCESS;
848973c7 2941}
6b0655a2 2942
718e3744 2943/* "bgp bestpath med" configuration. */
2944DEFUN (bgp_bestpath_med,
2945 bgp_bestpath_med_cmd,
2d8c1a4d 2946 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2947 "BGP specific commands\n"
2948 "Change the default bestpath selection\n"
2949 "MED attribute\n"
2950 "Compare MED among confederation paths\n"
838758ac
DW
2951 "Treat missing MED as the least preferred one\n"
2952 "Treat missing MED as the least preferred one\n"
2953 "Compare MED among confederation paths\n")
718e3744 2954{
d62a17ae 2955 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2956
d62a17ae 2957 int idx = 0;
2958 if (argv_find(argv, argc, "confed", &idx))
892fedb6 2959 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 2960 idx = 0;
2961 if (argv_find(argv, argc, "missing-as-worst", &idx))
892fedb6 2962 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2963
d62a17ae 2964 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2965
d62a17ae 2966 return CMD_SUCCESS;
718e3744 2967}
2968
718e3744 2969DEFUN (no_bgp_bestpath_med,
2970 no_bgp_bestpath_med_cmd,
2d8c1a4d 2971 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2972 NO_STR
2973 "BGP specific commands\n"
2974 "Change the default bestpath selection\n"
2975 "MED attribute\n"
2976 "Compare MED among confederation paths\n"
3a2d747c
QY
2977 "Treat missing MED as the least preferred one\n"
2978 "Treat missing MED as the least preferred one\n"
2979 "Compare MED among confederation paths\n")
718e3744 2980{
d62a17ae 2981 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2982
d62a17ae 2983 int idx = 0;
2984 if (argv_find(argv, argc, "confed", &idx))
892fedb6 2985 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 2986 idx = 0;
2987 if (argv_find(argv, argc, "missing-as-worst", &idx))
892fedb6 2988 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2989
d62a17ae 2990 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2991
d62a17ae 2992 return CMD_SUCCESS;
718e3744 2993}
2994
f7e1c681 2995/* "bgp bestpath bandwidth" configuration. */
2996DEFPY (bgp_bestpath_bw,
2997 bgp_bestpath_bw_cmd,
ad36d216 2998 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 2999 "BGP specific commands\n"
3000 "Change the default bestpath selection\n"
3001 "Link Bandwidth attribute\n"
3002 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3003 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3004 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3005{
3006 VTY_DECLVAR_CONTEXT(bgp, bgp);
3007 afi_t afi;
3008 safi_t safi;
3009
ad36d216
DS
3010 if (!bw_cfg) {
3011 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3012 return CMD_ERR_INCOMPLETE;
f7e1c681 3013 }
ad36d216
DS
3014 if (!strcmp(bw_cfg, "ignore"))
3015 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3016 else if (!strcmp(bw_cfg, "skip-missing"))
3017 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3018 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3019 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3020 else
3021 return CMD_ERR_NO_MATCH;
f7e1c681 3022
3023 /* This config is used in route install, so redo that. */
3024 FOREACH_AFI_SAFI (afi, safi) {
3025 if (!bgp_fibupd_safi(safi))
3026 continue;
3027 bgp_zebra_announce_table(bgp, afi, safi);
3028 }
3029
3030 return CMD_SUCCESS;
3031}
3032
ad36d216
DS
3033DEFPY (no_bgp_bestpath_bw,
3034 no_bgp_bestpath_bw_cmd,
3035 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3036 NO_STR
3037 "BGP specific commands\n"
3038 "Change the default bestpath selection\n"
3039 "Link Bandwidth attribute\n"
3040 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3041 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3042 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3043{
3044 VTY_DECLVAR_CONTEXT(bgp, bgp);
3045 afi_t afi;
3046 safi_t safi;
3047
3048 bgp->lb_handling = BGP_LINK_BW_ECMP;
3049
3050 /* This config is used in route install, so redo that. */
3051 FOREACH_AFI_SAFI (afi, safi) {
3052 if (!bgp_fibupd_safi(safi))
3053 continue;
3054 bgp_zebra_announce_table(bgp, afi, safi);
3055 }
3056 return CMD_SUCCESS;
3057}
3058
718e3744 3059/* "no bgp default ipv4-unicast". */
3060DEFUN (no_bgp_default_ipv4_unicast,
3061 no_bgp_default_ipv4_unicast_cmd,
3062 "no bgp default ipv4-unicast",
3063 NO_STR
3064 "BGP specific commands\n"
3065 "Configure BGP defaults\n"
3066 "Activate ipv4-unicast for a peer by default\n")
3067{
d62a17ae 3068 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3069 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3070 return CMD_SUCCESS;
718e3744 3071}
3072
3073DEFUN (bgp_default_ipv4_unicast,
3074 bgp_default_ipv4_unicast_cmd,
3075 "bgp default ipv4-unicast",
3076 "BGP specific commands\n"
3077 "Configure BGP defaults\n"
3078 "Activate ipv4-unicast for a peer by default\n")
3079{
d62a17ae 3080 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3081 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3082 return CMD_SUCCESS;
718e3744 3083}
6b0655a2 3084
04b6bdc0
DW
3085/* Display hostname in certain command outputs */
3086DEFUN (bgp_default_show_hostname,
3087 bgp_default_show_hostname_cmd,
3088 "bgp default show-hostname",
3089 "BGP specific commands\n"
3090 "Configure BGP defaults\n"
0437e105 3091 "Show hostname in certain command outputs\n")
04b6bdc0 3092{
d62a17ae 3093 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3094 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
d62a17ae 3095 return CMD_SUCCESS;
04b6bdc0
DW
3096}
3097
3098DEFUN (no_bgp_default_show_hostname,
3099 no_bgp_default_show_hostname_cmd,
3100 "no bgp default show-hostname",
3101 NO_STR
3102 "BGP specific commands\n"
3103 "Configure BGP defaults\n"
0437e105 3104 "Show hostname in certain command outputs\n")
04b6bdc0 3105{
d62a17ae 3106 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3107 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
d62a17ae 3108 return CMD_SUCCESS;
04b6bdc0
DW
3109}
3110
aef999a2
DA
3111/* Display hostname in certain command outputs */
3112DEFUN (bgp_default_show_nexthop_hostname,
3113 bgp_default_show_nexthop_hostname_cmd,
3114 "bgp default show-nexthop-hostname",
3115 "BGP specific commands\n"
3116 "Configure BGP defaults\n"
3117 "Show hostname for nexthop in certain command outputs\n")
3118{
3119 VTY_DECLVAR_CONTEXT(bgp, bgp);
3120 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3121 return CMD_SUCCESS;
3122}
3123
3124DEFUN (no_bgp_default_show_nexthop_hostname,
3125 no_bgp_default_show_nexthop_hostname_cmd,
3126 "no bgp default show-nexthop-hostname",
3127 NO_STR
3128 "BGP specific commands\n"
3129 "Configure BGP defaults\n"
3130 "Show hostname for nexthop in certain command outputs\n")
3131{
3132 VTY_DECLVAR_CONTEXT(bgp, bgp);
3133 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3134 return CMD_SUCCESS;
3135}
3136
8233ef81 3137/* "bgp network import-check" configuration. */
718e3744 3138DEFUN (bgp_network_import_check,
3139 bgp_network_import_check_cmd,
5623e905 3140 "bgp network import-check",
718e3744 3141 "BGP specific commands\n"
3142 "BGP network command\n"
5623e905 3143 "Check BGP network route exists in IGP\n")
718e3744 3144{
d62a17ae 3145 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
3146 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3147 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
d62a17ae 3148 bgp_static_redo_import_check(bgp);
3149 }
078430f6 3150
d62a17ae 3151 return CMD_SUCCESS;
718e3744 3152}
3153
d62a17ae 3154ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3155 "bgp network import-check exact",
3156 "BGP specific commands\n"
3157 "BGP network command\n"
3158 "Check BGP network route exists in IGP\n"
3159 "Match route precisely\n")
8233ef81 3160
718e3744 3161DEFUN (no_bgp_network_import_check,
3162 no_bgp_network_import_check_cmd,
5623e905 3163 "no bgp network import-check",
718e3744 3164 NO_STR
3165 "BGP specific commands\n"
3166 "BGP network command\n"
3167 "Check BGP network route exists in IGP\n")
3168{
d62a17ae 3169 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
3170 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3171 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
d62a17ae 3172 bgp_static_redo_import_check(bgp);
3173 }
5623e905 3174
d62a17ae 3175 return CMD_SUCCESS;
718e3744 3176}
6b0655a2 3177
718e3744 3178DEFUN (bgp_default_local_preference,
3179 bgp_default_local_preference_cmd,
6147e2c6 3180 "bgp default local-preference (0-4294967295)",
718e3744 3181 "BGP specific commands\n"
3182 "Configure BGP defaults\n"
3183 "local preference (higher=more preferred)\n"
3184 "Configure default local preference value\n")
3185{
d62a17ae 3186 VTY_DECLVAR_CONTEXT(bgp, bgp);
3187 int idx_number = 3;
d7c0a89a 3188 uint32_t local_pref;
718e3744 3189
d62a17ae 3190 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3191
d62a17ae 3192 bgp_default_local_preference_set(bgp, local_pref);
3193 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3194
d62a17ae 3195 return CMD_SUCCESS;
718e3744 3196}
3197
3198DEFUN (no_bgp_default_local_preference,
3199 no_bgp_default_local_preference_cmd,
838758ac 3200 "no bgp default local-preference [(0-4294967295)]",
718e3744 3201 NO_STR
3202 "BGP specific commands\n"
3203 "Configure BGP defaults\n"
838758ac
DW
3204 "local preference (higher=more preferred)\n"
3205 "Configure default local preference value\n")
718e3744 3206{
d62a17ae 3207 VTY_DECLVAR_CONTEXT(bgp, bgp);
3208 bgp_default_local_preference_unset(bgp);
3209 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3210
d62a17ae 3211 return CMD_SUCCESS;
718e3744 3212}
3213
6b0655a2 3214
3f9c7369
DS
3215DEFUN (bgp_default_subgroup_pkt_queue_max,
3216 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 3217 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
3218 "BGP specific commands\n"
3219 "Configure BGP defaults\n"
3220 "subgroup-pkt-queue-max\n"
3221 "Configure subgroup packet queue max\n")
8bd9d948 3222{
d62a17ae 3223 VTY_DECLVAR_CONTEXT(bgp, bgp);
3224 int idx_number = 3;
d7c0a89a 3225 uint32_t max_size;
8bd9d948 3226
d62a17ae 3227 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3228
d62a17ae 3229 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 3230
d62a17ae 3231 return CMD_SUCCESS;
3f9c7369
DS
3232}
3233
3234DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3235 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 3236 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
3237 NO_STR
3238 "BGP specific commands\n"
3239 "Configure BGP defaults\n"
838758ac
DW
3240 "subgroup-pkt-queue-max\n"
3241 "Configure subgroup packet queue max\n")
3f9c7369 3242{
d62a17ae 3243 VTY_DECLVAR_CONTEXT(bgp, bgp);
3244 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3245 return CMD_SUCCESS;
8bd9d948
DS
3246}
3247
813d4307 3248
8bd9d948
DS
3249DEFUN (bgp_rr_allow_outbound_policy,
3250 bgp_rr_allow_outbound_policy_cmd,
3251 "bgp route-reflector allow-outbound-policy",
3252 "BGP specific commands\n"
3253 "Allow modifications made by out route-map\n"
3254 "on ibgp neighbors\n")
3255{
d62a17ae 3256 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3257
892fedb6
DA
3258 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3259 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
d62a17ae 3260 update_group_announce_rrclients(bgp);
3261 bgp_clear_star_soft_out(vty, bgp->name);
3262 }
8bd9d948 3263
d62a17ae 3264 return CMD_SUCCESS;
8bd9d948
DS
3265}
3266
3267DEFUN (no_bgp_rr_allow_outbound_policy,
3268 no_bgp_rr_allow_outbound_policy_cmd,
3269 "no bgp route-reflector allow-outbound-policy",
3270 NO_STR
3271 "BGP specific commands\n"
3272 "Allow modifications made by out route-map\n"
3273 "on ibgp neighbors\n")
3274{
d62a17ae 3275 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3276
892fedb6
DA
3277 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3278 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
d62a17ae 3279 update_group_announce_rrclients(bgp);
3280 bgp_clear_star_soft_out(vty, bgp->name);
3281 }
8bd9d948 3282
d62a17ae 3283 return CMD_SUCCESS;
8bd9d948
DS
3284}
3285
f14e6fdb
DS
3286DEFUN (bgp_listen_limit,
3287 bgp_listen_limit_cmd,
9ccf14f7 3288 "bgp listen limit (1-5000)",
f14e6fdb 3289 "BGP specific commands\n"
1601a46f 3290 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3291 "Maximum number of BGP Dynamic Neighbors that can be created\n"
f14e6fdb
DS
3292 "Configure Dynamic Neighbors listen limit value\n")
3293{
d62a17ae 3294 VTY_DECLVAR_CONTEXT(bgp, bgp);
3295 int idx_number = 3;
3296 int listen_limit;
f14e6fdb 3297
d62a17ae 3298 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3299
d62a17ae 3300 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3301
d62a17ae 3302 return CMD_SUCCESS;
f14e6fdb
DS
3303}
3304
3305DEFUN (no_bgp_listen_limit,
3306 no_bgp_listen_limit_cmd,
838758ac 3307 "no bgp listen limit [(1-5000)]",
1601a46f 3308 NO_STR
f14e6fdb 3309 "BGP specific commands\n"
1601a46f 3310 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3311 "Maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac 3312 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3313{
d62a17ae 3314 VTY_DECLVAR_CONTEXT(bgp, bgp);
3315 bgp_listen_limit_unset(bgp);
3316 return CMD_SUCCESS;
f14e6fdb
DS
3317}
3318
3319
20eb8864 3320/*
3321 * Check if this listen range is already configured. Check for exact
3322 * match or overlap based on input.
3323 */
d62a17ae 3324static struct peer_group *listen_range_exists(struct bgp *bgp,
3325 struct prefix *range, int exact)
3326{
3327 struct listnode *node, *nnode;
3328 struct listnode *node1, *nnode1;
3329 struct peer_group *group;
3330 struct prefix *lr;
3331 afi_t afi;
3332 int match;
3333
3334 afi = family2afi(range->family);
3335 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3336 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3337 lr)) {
3338 if (exact)
3339 match = prefix_same(range, lr);
3340 else
3341 match = (prefix_match(range, lr)
3342 || prefix_match(lr, range));
3343 if (match)
3344 return group;
3345 }
3346 }
3347
3348 return NULL;
20eb8864 3349}
3350
f14e6fdb
DS
3351DEFUN (bgp_listen_range,
3352 bgp_listen_range_cmd,
d7b9898c 3353 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3354 "BGP specific commands\n"
d7fa34c1
QY
3355 "Configure BGP dynamic neighbors listen range\n"
3356 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3357 NEIGHBOR_ADDR_STR
3358 "Member of the peer-group\n"
3359 "Peer-group name\n")
f14e6fdb 3360{
d62a17ae 3361 VTY_DECLVAR_CONTEXT(bgp, bgp);
3362 struct prefix range;
3363 struct peer_group *group, *existing_group;
3364 afi_t afi;
3365 int ret;
3366 int idx = 0;
3367
3368 argv_find(argv, argc, "A.B.C.D/M", &idx);
3369 argv_find(argv, argc, "X:X::X:X/M", &idx);
3370 char *prefix = argv[idx]->arg;
d7b9898c 3371 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3372 char *peergroup = argv[idx]->arg;
3373
3374 /* Convert IP prefix string to struct prefix. */
3375 ret = str2prefix(prefix, &range);
3376 if (!ret) {
3377 vty_out(vty, "%% Malformed listen range\n");
3378 return CMD_WARNING_CONFIG_FAILED;
3379 }
3380
3381 afi = family2afi(range.family);
3382
3383 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3384 vty_out(vty,
3385 "%% Malformed listen range (link-local address)\n");
3386 return CMD_WARNING_CONFIG_FAILED;
3387 }
3388
3389 apply_mask(&range);
3390
3391 /* Check if same listen range is already configured. */
3392 existing_group = listen_range_exists(bgp, &range, 1);
3393 if (existing_group) {
3394 if (strcmp(existing_group->name, peergroup) == 0)
3395 return CMD_SUCCESS;
3396 else {
3397 vty_out(vty,
3398 "%% Same listen range is attached to peer-group %s\n",
3399 existing_group->name);
3400 return CMD_WARNING_CONFIG_FAILED;
3401 }
3402 }
3403
3404 /* Check if an overlapping listen range exists. */
3405 if (listen_range_exists(bgp, &range, 0)) {
3406 vty_out(vty,
3407 "%% Listen range overlaps with existing listen range\n");
3408 return CMD_WARNING_CONFIG_FAILED;
3409 }
3410
3411 group = peer_group_lookup(bgp, peergroup);
3412 if (!group) {
3413 vty_out(vty, "%% Configure the peer-group first\n");
3414 return CMD_WARNING_CONFIG_FAILED;
3415 }
3416
3417 ret = peer_group_listen_range_add(group, &range);
3418 return bgp_vty_return(vty, ret);
f14e6fdb
DS
3419}
3420
3421DEFUN (no_bgp_listen_range,
3422 no_bgp_listen_range_cmd,
d7b9898c 3423 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 3424 NO_STR
f14e6fdb 3425 "BGP specific commands\n"
d7fa34c1
QY
3426 "Unconfigure BGP dynamic neighbors listen range\n"
3427 "Unconfigure BGP dynamic neighbors listen range\n"
3428 NEIGHBOR_ADDR_STR
3429 "Member of the peer-group\n"
3430 "Peer-group name\n")
f14e6fdb 3431{
d62a17ae 3432 VTY_DECLVAR_CONTEXT(bgp, bgp);
3433 struct prefix range;
3434 struct peer_group *group;
3435 afi_t afi;
3436 int ret;
3437 int idx = 0;
3438
3439 argv_find(argv, argc, "A.B.C.D/M", &idx);
3440 argv_find(argv, argc, "X:X::X:X/M", &idx);
3441 char *prefix = argv[idx]->arg;
21d88a71 3442 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3443 char *peergroup = argv[idx]->arg;
3444
3445 /* Convert IP prefix string to struct prefix. */
3446 ret = str2prefix(prefix, &range);
3447 if (!ret) {
3448 vty_out(vty, "%% Malformed listen range\n");
3449 return CMD_WARNING_CONFIG_FAILED;
3450 }
3451
3452 afi = family2afi(range.family);
3453
3454 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3455 vty_out(vty,
3456 "%% Malformed listen range (link-local address)\n");
3457 return CMD_WARNING_CONFIG_FAILED;
3458 }
3459
3460 apply_mask(&range);
3461
3462 group = peer_group_lookup(bgp, peergroup);
3463 if (!group) {
3464 vty_out(vty, "%% Peer-group does not exist\n");
3465 return CMD_WARNING_CONFIG_FAILED;
3466 }
3467
3468 ret = peer_group_listen_range_del(group, &range);
3469 return bgp_vty_return(vty, ret);
3470}
3471
2b791107 3472void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 3473{
3474 struct peer_group *group;
3475 struct listnode *node, *nnode, *rnode, *nrnode;
3476 struct prefix *range;
3477 afi_t afi;
3478 char buf[PREFIX2STR_BUFFER];
3479
3480 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3481 vty_out(vty, " bgp listen limit %d\n",
3482 bgp->dynamic_neighbors_limit);
3483
3484 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3485 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3486 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3487 nrnode, range)) {
3488 prefix2str(range, buf, sizeof(buf));
3489 vty_out(vty,
3490 " bgp listen range %s peer-group %s\n",
3491 buf, group->name);
3492 }
3493 }
3494 }
f14e6fdb
DS
3495}
3496
3497
907f92c8
DS
3498DEFUN (bgp_disable_connected_route_check,
3499 bgp_disable_connected_route_check_cmd,
3500 "bgp disable-ebgp-connected-route-check",
3501 "BGP specific commands\n"
3502 "Disable checking if nexthop is connected on ebgp sessions\n")
3503{
d62a17ae 3504 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3505 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
d62a17ae 3506 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3507
d62a17ae 3508 return CMD_SUCCESS;
907f92c8
DS
3509}
3510
3511DEFUN (no_bgp_disable_connected_route_check,
3512 no_bgp_disable_connected_route_check_cmd,
3513 "no bgp disable-ebgp-connected-route-check",
3514 NO_STR
3515 "BGP specific commands\n"
3516 "Disable checking if nexthop is connected on ebgp sessions\n")
3517{
d62a17ae 3518 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3519 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
d62a17ae 3520 bgp_clear_star_soft_in(vty, bgp->name);
3521
3522 return CMD_SUCCESS;
3523}
3524
3525
3526static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3527 const char *as_str, afi_t afi, safi_t safi)
3528{
3529 VTY_DECLVAR_CONTEXT(bgp, bgp);
3530 int ret;
3531 as_t as;
3532 int as_type = AS_SPECIFIED;
3533 union sockunion su;
3534
3535 if (as_str[0] == 'i') {
3536 as = 0;
3537 as_type = AS_INTERNAL;
3538 } else if (as_str[0] == 'e') {
3539 as = 0;
3540 as_type = AS_EXTERNAL;
3541 } else {
3542 /* Get AS number. */
3543 as = strtoul(as_str, NULL, 10);
3544 }
3545
390485fd 3546 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 3547 ret = str2sockunion(peer_str, &su);
3548 if (ret < 0) {
390485fd
DS
3549 struct peer *peer;
3550
3551 /* Check if existing interface peer */
3552 peer = peer_lookup_by_conf_if(bgp, peer_str);
3553
d62a17ae 3554 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3555 safi);
390485fd
DS
3556
3557 /* if not interface peer, check peer-group settings */
3558 if (ret < 0 && !peer) {
d62a17ae 3559 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3560 if (ret < 0) {
3561 vty_out(vty,
390485fd 3562 "%% Create the peer-group or interface first\n");
d62a17ae 3563 return CMD_WARNING_CONFIG_FAILED;
3564 }
3565 return CMD_SUCCESS;
3566 }
3567 } else {
3568 if (peer_address_self_check(bgp, &su)) {
3569 vty_out(vty,
3570 "%% Can not configure the local system as neighbor\n");
3571 return CMD_WARNING_CONFIG_FAILED;
3572 }
3573 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3574 }
3575
3576 /* This peer belongs to peer group. */
3577 switch (ret) {
3578 case BGP_ERR_PEER_GROUP_MEMBER:
3579 vty_out(vty,
faa16034 3580 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 3581 return CMD_WARNING_CONFIG_FAILED;
3582 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3583 vty_out(vty,
faa16034 3584 "%% Peer-group members must be all internal or all external\n");
d62a17ae 3585 return CMD_WARNING_CONFIG_FAILED;
3586 }
3587 return bgp_vty_return(vty, ret);
718e3744 3588}
3589
f26845f9
QY
3590DEFUN (bgp_default_shutdown,
3591 bgp_default_shutdown_cmd,
3592 "[no] bgp default shutdown",
3593 NO_STR
3594 BGP_STR
3595 "Configure BGP defaults\n"
b012cbe2 3596 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
3597{
3598 VTY_DECLVAR_CONTEXT(bgp, bgp);
3599 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
3600 return CMD_SUCCESS;
3601}
3602
718e3744 3603DEFUN (neighbor_remote_as,
3604 neighbor_remote_as_cmd,
3a2d747c 3605 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 3606 NEIGHBOR_STR
3607 NEIGHBOR_ADDR_STR2
3608 "Specify a BGP neighbor\n"
d7fa34c1 3609 AS_STR
3a2d747c
QY
3610 "Internal BGP peer\n"
3611 "External BGP peer\n")
718e3744 3612{
d62a17ae 3613 int idx_peer = 1;
3614 int idx_remote_as = 3;
3615 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
3616 argv[idx_remote_as]->arg, AFI_IP,
3617 SAFI_UNICAST);
3618}
3619
3620static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
3621 afi_t afi, safi_t safi, int v6only,
3622 const char *peer_group_name,
3623 const char *as_str)
3624{
3625 VTY_DECLVAR_CONTEXT(bgp, bgp);
3626 as_t as = 0;
3627 int as_type = AS_UNSPECIFIED;
3628 struct peer *peer;
3629 struct peer_group *group;
3630 int ret = 0;
3631 union sockunion su;
3632
3633 group = peer_group_lookup(bgp, conf_if);
3634
3635 if (group) {
3636 vty_out(vty, "%% Name conflict with peer-group \n");
3637 return CMD_WARNING_CONFIG_FAILED;
3638 }
3639
3640 if (as_str) {
3641 if (as_str[0] == 'i') {
3642 as_type = AS_INTERNAL;
3643 } else if (as_str[0] == 'e') {
3644 as_type = AS_EXTERNAL;
3645 } else {
3646 /* Get AS number. */
3647 as = strtoul(as_str, NULL, 10);
3648 as_type = AS_SPECIFIED;
3649 }
3650 }
3651
3652 peer = peer_lookup_by_conf_if(bgp, conf_if);
3653 if (peer) {
3654 if (as_str)
cc4d4ce8 3655 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 3656 afi, safi);
3657 } else {
892fedb6 3658 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 3659 && afi == AFI_IP && safi == SAFI_UNICAST)
3660 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3661 as_type, 0, 0, NULL);
3662 else
3663 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3664 as_type, afi, safi, NULL);
3665
3666 if (!peer) {
3667 vty_out(vty, "%% BGP failed to create peer\n");
3668 return CMD_WARNING_CONFIG_FAILED;
3669 }
3670
3671 if (v6only)
527de3dc 3672 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3673
3674 /* Request zebra to initiate IPv6 RAs on this interface. We do
3675 * this
3676 * any unnumbered peer in order to not worry about run-time
3677 * transitions
3678 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3679 * address
3680 * gets deleted later etc.)
3681 */
3682 if (peer->ifp)
3683 bgp_zebra_initiate_radv(bgp, peer);
3684 }
3685
3686 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3687 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3688 if (v6only)
527de3dc 3689 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3690 else
527de3dc 3691 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3692
3693 /* v6only flag changed. Reset bgp seesion */
3694 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3695 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3696 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3697 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3698 } else
3699 bgp_session_reset(peer);
3700 }
3701
9fb964de
PM
3702 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3703 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3704 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 3705 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 3706 }
d62a17ae 3707
3708 if (peer_group_name) {
3709 group = peer_group_lookup(bgp, peer_group_name);
3710 if (!group) {
3711 vty_out(vty, "%% Configure the peer-group first\n");
3712 return CMD_WARNING_CONFIG_FAILED;
3713 }
3714
3715 ret = peer_group_bind(bgp, &su, peer, group, &as);
3716 }
3717
3718 return bgp_vty_return(vty, ret);
a80beece
DS
3719}
3720
4c48cf63
DW
3721DEFUN (neighbor_interface_config,
3722 neighbor_interface_config_cmd,
d7b9898c 3723 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
3724 NEIGHBOR_STR
3725 "Interface name or neighbor tag\n"
31500417
DW
3726 "Enable BGP on interface\n"
3727 "Member of the peer-group\n"
16cedbb0 3728 "Peer-group name\n")
4c48cf63 3729{
d62a17ae 3730 int idx_word = 1;
3731 int idx_peer_group_word = 4;
31500417 3732
d62a17ae 3733 if (argc > idx_peer_group_word)
3734 return peer_conf_interface_get(
3735 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3736 argv[idx_peer_group_word]->arg, NULL);
3737 else
3738 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3739 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3740}
3741
4c48cf63
DW
3742DEFUN (neighbor_interface_config_v6only,
3743 neighbor_interface_config_v6only_cmd,
d7b9898c 3744 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
3745 NEIGHBOR_STR
3746 "Interface name or neighbor tag\n"
3747 "Enable BGP on interface\n"
31500417
DW
3748 "Enable BGP with v6 link-local only\n"
3749 "Member of the peer-group\n"
16cedbb0 3750 "Peer-group name\n")
4c48cf63 3751{
d62a17ae 3752 int idx_word = 1;
3753 int idx_peer_group_word = 5;
31500417 3754
d62a17ae 3755 if (argc > idx_peer_group_word)
3756 return peer_conf_interface_get(
3757 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3758 argv[idx_peer_group_word]->arg, NULL);
31500417 3759
d62a17ae 3760 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3761 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3762}
3763
a80beece 3764
b3a39dc5
DD
3765DEFUN (neighbor_interface_config_remote_as,
3766 neighbor_interface_config_remote_as_cmd,
3a2d747c 3767 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3768 NEIGHBOR_STR
3769 "Interface name or neighbor tag\n"
3770 "Enable BGP on interface\n"
3a2d747c 3771 "Specify a BGP neighbor\n"
d7fa34c1 3772 AS_STR
3a2d747c
QY
3773 "Internal BGP peer\n"
3774 "External BGP peer\n")
b3a39dc5 3775{
d62a17ae 3776 int idx_word = 1;
3777 int idx_remote_as = 4;
3778 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3779 SAFI_UNICAST, 0, NULL,
3780 argv[idx_remote_as]->arg);
b3a39dc5
DD
3781}
3782
3783DEFUN (neighbor_interface_v6only_config_remote_as,
3784 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3785 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3786 NEIGHBOR_STR
3787 "Interface name or neighbor tag\n"
3a2d747c 3788 "Enable BGP with v6 link-local only\n"
b3a39dc5 3789 "Enable BGP on interface\n"
3a2d747c 3790 "Specify a BGP neighbor\n"
d7fa34c1 3791 AS_STR
3a2d747c
QY
3792 "Internal BGP peer\n"
3793 "External BGP peer\n")
b3a39dc5 3794{
d62a17ae 3795 int idx_word = 1;
3796 int idx_remote_as = 5;
3797 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3798 SAFI_UNICAST, 1, NULL,
3799 argv[idx_remote_as]->arg);
b3a39dc5
DD
3800}
3801
718e3744 3802DEFUN (neighbor_peer_group,
3803 neighbor_peer_group_cmd,
3804 "neighbor WORD peer-group",
3805 NEIGHBOR_STR
a80beece 3806 "Interface name or neighbor tag\n"
718e3744 3807 "Configure peer-group\n")
3808{
d62a17ae 3809 VTY_DECLVAR_CONTEXT(bgp, bgp);
3810 int idx_word = 1;
3811 struct peer *peer;
3812 struct peer_group *group;
718e3744 3813
d62a17ae 3814 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3815 if (peer) {
3816 vty_out(vty, "%% Name conflict with interface: \n");
3817 return CMD_WARNING_CONFIG_FAILED;
3818 }
718e3744 3819
d62a17ae 3820 group = peer_group_get(bgp, argv[idx_word]->arg);
3821 if (!group) {
3822 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3823 return CMD_WARNING_CONFIG_FAILED;
3824 }
718e3744 3825
d62a17ae 3826 return CMD_SUCCESS;
718e3744 3827}
3828
3829DEFUN (no_neighbor,
3830 no_neighbor_cmd,
dab8cd00 3831 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3832 NO_STR
3833 NEIGHBOR_STR
3a2d747c
QY
3834 NEIGHBOR_ADDR_STR2
3835 "Specify a BGP neighbor\n"
3836 AS_STR
3837 "Internal BGP peer\n"
3838 "External BGP peer\n")
718e3744 3839{
d62a17ae 3840 VTY_DECLVAR_CONTEXT(bgp, bgp);
3841 int idx_peer = 2;
3842 int ret;
3843 union sockunion su;
3844 struct peer_group *group;
3845 struct peer *peer;
3846 struct peer *other;
3847
3848 ret = str2sockunion(argv[idx_peer]->arg, &su);
3849 if (ret < 0) {
3850 /* look up for neighbor by interface name config. */
3851 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3852 if (peer) {
3853 /* Request zebra to terminate IPv6 RAs on this
3854 * interface. */
3855 if (peer->ifp)
3856 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3857 peer_notify_unconfig(peer);
d62a17ae 3858 peer_delete(peer);
3859 return CMD_SUCCESS;
3860 }
f14e6fdb 3861
d62a17ae 3862 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4e2786df
DA
3863 if (group) {
3864 peer_group_notify_unconfig(group);
d62a17ae 3865 peer_group_delete(group);
4e2786df 3866 } else {
d62a17ae 3867 vty_out(vty, "%% Create the peer-group first\n");
3868 return CMD_WARNING_CONFIG_FAILED;
3869 }
3870 } else {
3871 peer = peer_lookup(bgp, &su);
3872 if (peer) {
3873 if (peer_dynamic_neighbor(peer)) {
3874 vty_out(vty,
3875 "%% Operation not allowed on a dynamic neighbor\n");
3876 return CMD_WARNING_CONFIG_FAILED;
3877 }
3878
3879 other = peer->doppelganger;
b3a3290e
DS
3880
3881 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
3882 bgp_zebra_terminate_radv(peer->bgp, peer);
3883
4e2786df 3884 peer_notify_unconfig(peer);
d62a17ae 3885 peer_delete(peer);
4e2786df
DA
3886 if (other && other->status != Deleted) {
3887 peer_notify_unconfig(other);
d62a17ae 3888 peer_delete(other);
4e2786df 3889 }
d62a17ae 3890 }
1ff9a340 3891 }
718e3744 3892
d62a17ae 3893 return CMD_SUCCESS;
718e3744 3894}
3895
a80beece
DS
3896DEFUN (no_neighbor_interface_config,
3897 no_neighbor_interface_config_cmd,
d7b9898c 3898 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3899 NO_STR
3900 NEIGHBOR_STR
3901 "Interface name\n"
31500417
DW
3902 "Configure BGP on interface\n"
3903 "Enable BGP with v6 link-local only\n"
3904 "Member of the peer-group\n"
16cedbb0 3905 "Peer-group name\n"
3a2d747c
QY
3906 "Specify a BGP neighbor\n"
3907 AS_STR
3908 "Internal BGP peer\n"
3909 "External BGP peer\n")
a80beece 3910{
d62a17ae 3911 VTY_DECLVAR_CONTEXT(bgp, bgp);
3912 int idx_word = 2;
3913 struct peer *peer;
3914
3915 /* look up for neighbor by interface name config. */
3916 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3917 if (peer) {
3918 /* Request zebra to terminate IPv6 RAs on this interface. */
3919 if (peer->ifp)
3920 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3921 peer_notify_unconfig(peer);
d62a17ae 3922 peer_delete(peer);
3923 } else {
3924 vty_out(vty, "%% Create the bgp interface first\n");
3925 return CMD_WARNING_CONFIG_FAILED;
3926 }
3927 return CMD_SUCCESS;
a80beece
DS
3928}
3929
718e3744 3930DEFUN (no_neighbor_peer_group,
3931 no_neighbor_peer_group_cmd,
3932 "no neighbor WORD peer-group",
3933 NO_STR
3934 NEIGHBOR_STR
3935 "Neighbor tag\n"
3936 "Configure peer-group\n")
3937{
d62a17ae 3938 VTY_DECLVAR_CONTEXT(bgp, bgp);
3939 int idx_word = 2;
3940 struct peer_group *group;
718e3744 3941
d62a17ae 3942 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4e2786df
DA
3943 if (group) {
3944 peer_group_notify_unconfig(group);
d62a17ae 3945 peer_group_delete(group);
4e2786df 3946 } else {
d62a17ae 3947 vty_out(vty, "%% Create the peer-group first\n");
3948 return CMD_WARNING_CONFIG_FAILED;
3949 }
3950 return CMD_SUCCESS;
718e3744 3951}
3952
a80beece
DS
3953DEFUN (no_neighbor_interface_peer_group_remote_as,
3954 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3955 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3956 NO_STR
3957 NEIGHBOR_STR
a80beece 3958 "Interface name or neighbor tag\n"
718e3744 3959 "Specify a BGP neighbor\n"
3a2d747c
QY
3960 AS_STR
3961 "Internal BGP peer\n"
3962 "External BGP peer\n")
718e3744 3963{
d62a17ae 3964 VTY_DECLVAR_CONTEXT(bgp, bgp);
3965 int idx_word = 2;
3966 struct peer_group *group;
3967 struct peer *peer;
3968
3969 /* look up for neighbor by interface name config. */
3970 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3971 if (peer) {
390485fd 3972 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 3973 return CMD_SUCCESS;
3974 }
3975
3976 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3977 if (group)
3978 peer_group_remote_as_delete(group);
3979 else {
3980 vty_out(vty, "%% Create the peer-group or interface first\n");
3981 return CMD_WARNING_CONFIG_FAILED;
3982 }
3983 return CMD_SUCCESS;
718e3744 3984}
6b0655a2 3985
718e3744 3986DEFUN (neighbor_local_as,
3987 neighbor_local_as_cmd,
9ccf14f7 3988 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3989 NEIGHBOR_STR
3990 NEIGHBOR_ADDR_STR2
3991 "Specify a local-as number\n"
3992 "AS number used as local AS\n")
3993{
d62a17ae 3994 int idx_peer = 1;
3995 int idx_number = 3;
3996 struct peer *peer;
3997 int ret;
3998 as_t as;
718e3744 3999
d62a17ae 4000 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4001 if (!peer)
4002 return CMD_WARNING_CONFIG_FAILED;
718e3744 4003
d62a17ae 4004 as = strtoul(argv[idx_number]->arg, NULL, 10);
4005 ret = peer_local_as_set(peer, as, 0, 0);
4006 return bgp_vty_return(vty, ret);
718e3744 4007}
4008
4009DEFUN (neighbor_local_as_no_prepend,
4010 neighbor_local_as_no_prepend_cmd,
9ccf14f7 4011 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 4012 NEIGHBOR_STR
4013 NEIGHBOR_ADDR_STR2
4014 "Specify a local-as number\n"
4015 "AS number used as local AS\n"
4016 "Do not prepend local-as to updates from ebgp peers\n")
4017{
d62a17ae 4018 int idx_peer = 1;
4019 int idx_number = 3;
4020 struct peer *peer;
4021 int ret;
4022 as_t as;
718e3744 4023
d62a17ae 4024 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4025 if (!peer)
4026 return CMD_WARNING_CONFIG_FAILED;
718e3744 4027
d62a17ae 4028 as = strtoul(argv[idx_number]->arg, NULL, 10);
4029 ret = peer_local_as_set(peer, as, 1, 0);
4030 return bgp_vty_return(vty, ret);
718e3744 4031}
4032
9d3f9705
AC
4033DEFUN (neighbor_local_as_no_prepend_replace_as,
4034 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 4035 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
4036 NEIGHBOR_STR
4037 NEIGHBOR_ADDR_STR2
4038 "Specify a local-as number\n"
4039 "AS number used as local AS\n"
4040 "Do not prepend local-as to updates from ebgp peers\n"
4041 "Do not prepend local-as to updates from ibgp peers\n")
4042{
d62a17ae 4043 int idx_peer = 1;
4044 int idx_number = 3;
4045 struct peer *peer;
4046 int ret;
4047 as_t as;
9d3f9705 4048
d62a17ae 4049 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4050 if (!peer)
4051 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4052
d62a17ae 4053 as = strtoul(argv[idx_number]->arg, NULL, 10);
4054 ret = peer_local_as_set(peer, as, 1, 1);
4055 return bgp_vty_return(vty, ret);
9d3f9705
AC
4056}
4057
718e3744 4058DEFUN (no_neighbor_local_as,
4059 no_neighbor_local_as_cmd,
a636c635 4060 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 4061 NO_STR
4062 NEIGHBOR_STR
4063 NEIGHBOR_ADDR_STR2
a636c635
DW
4064 "Specify a local-as number\n"
4065 "AS number used as local AS\n"
4066 "Do not prepend local-as to updates from ebgp peers\n"
4067 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4068{
d62a17ae 4069 int idx_peer = 2;
4070 struct peer *peer;
4071 int ret;
718e3744 4072
d62a17ae 4073 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4074 if (!peer)
4075 return CMD_WARNING_CONFIG_FAILED;
718e3744 4076
d62a17ae 4077 ret = peer_local_as_unset(peer);
4078 return bgp_vty_return(vty, ret);
718e3744 4079}
4080
718e3744 4081
3f9c7369
DS
4082DEFUN (neighbor_solo,
4083 neighbor_solo_cmd,
9ccf14f7 4084 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4085 NEIGHBOR_STR
4086 NEIGHBOR_ADDR_STR2
4087 "Solo peer - part of its own update group\n")
4088{
d62a17ae 4089 int idx_peer = 1;
4090 struct peer *peer;
4091 int ret;
3f9c7369 4092
d62a17ae 4093 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4094 if (!peer)
4095 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4096
d62a17ae 4097 ret = update_group_adjust_soloness(peer, 1);
4098 return bgp_vty_return(vty, ret);
3f9c7369
DS
4099}
4100
4101DEFUN (no_neighbor_solo,
4102 no_neighbor_solo_cmd,
9ccf14f7 4103 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4104 NO_STR
4105 NEIGHBOR_STR
4106 NEIGHBOR_ADDR_STR2
4107 "Solo peer - part of its own update group\n")
4108{
d62a17ae 4109 int idx_peer = 2;
4110 struct peer *peer;
4111 int ret;
3f9c7369 4112
d62a17ae 4113 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4114 if (!peer)
4115 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4116
d62a17ae 4117 ret = update_group_adjust_soloness(peer, 0);
4118 return bgp_vty_return(vty, ret);
3f9c7369
DS
4119}
4120
0df7c91f
PJ
4121DEFUN (neighbor_password,
4122 neighbor_password_cmd,
9ccf14f7 4123 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
4124 NEIGHBOR_STR
4125 NEIGHBOR_ADDR_STR2
4126 "Set a password\n"
4127 "The password\n")
4128{
d62a17ae 4129 int idx_peer = 1;
4130 int idx_line = 3;
4131 struct peer *peer;
4132 int ret;
0df7c91f 4133
d62a17ae 4134 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4135 if (!peer)
4136 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4137
d62a17ae 4138 ret = peer_password_set(peer, argv[idx_line]->arg);
4139 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4140}
4141
4142DEFUN (no_neighbor_password,
4143 no_neighbor_password_cmd,
a636c635 4144 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
4145 NO_STR
4146 NEIGHBOR_STR
4147 NEIGHBOR_ADDR_STR2
16cedbb0
QY
4148 "Set a password\n"
4149 "The password\n")
0df7c91f 4150{
d62a17ae 4151 int idx_peer = 2;
4152 struct peer *peer;
4153 int ret;
0df7c91f 4154
d62a17ae 4155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4156 if (!peer)
4157 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4158
d62a17ae 4159 ret = peer_password_unset(peer);
4160 return bgp_vty_return(vty, ret);
0df7c91f 4161}
6b0655a2 4162
718e3744 4163DEFUN (neighbor_activate,
4164 neighbor_activate_cmd,
9ccf14f7 4165 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4166 NEIGHBOR_STR
4167 NEIGHBOR_ADDR_STR2
4168 "Enable the Address Family for this Neighbor\n")
4169{
d62a17ae 4170 int idx_peer = 1;
4171 int ret;
4172 struct peer *peer;
718e3744 4173
d62a17ae 4174 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4175 if (!peer)
4176 return CMD_WARNING_CONFIG_FAILED;
718e3744 4177
d62a17ae 4178 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4179 return bgp_vty_return(vty, ret);
718e3744 4180}
4181
d62a17ae 4182ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4183 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4184 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4185 "Enable the Address Family for this Neighbor\n")
596c17ba 4186
718e3744 4187DEFUN (no_neighbor_activate,
4188 no_neighbor_activate_cmd,
9ccf14f7 4189 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4190 NO_STR
4191 NEIGHBOR_STR
4192 NEIGHBOR_ADDR_STR2
4193 "Enable the Address Family for this Neighbor\n")
4194{
d62a17ae 4195 int idx_peer = 2;
4196 int ret;
4197 struct peer *peer;
718e3744 4198
d62a17ae 4199 /* Lookup peer. */
4200 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4201 if (!peer)
4202 return CMD_WARNING_CONFIG_FAILED;
718e3744 4203
d62a17ae 4204 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4205 return bgp_vty_return(vty, ret);
718e3744 4206}
6b0655a2 4207
d62a17ae 4208ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4209 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4210 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4211 "Enable the Address Family for this Neighbor\n")
596c17ba 4212
718e3744 4213DEFUN (neighbor_set_peer_group,
4214 neighbor_set_peer_group_cmd,
d7b9898c 4215 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4216 NEIGHBOR_STR
a80beece 4217 NEIGHBOR_ADDR_STR2
718e3744 4218 "Member of the peer-group\n"
16cedbb0 4219 "Peer-group name\n")
718e3744 4220{
d62a17ae 4221 VTY_DECLVAR_CONTEXT(bgp, bgp);
4222 int idx_peer = 1;
4223 int idx_word = 3;
4224 int ret;
4225 as_t as;
4226 union sockunion su;
4227 struct peer *peer;
4228 struct peer_group *group;
4229
d62a17ae 4230 ret = str2sockunion(argv[idx_peer]->arg, &su);
4231 if (ret < 0) {
4232 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4233 if (!peer) {
4234 vty_out(vty, "%% Malformed address or name: %s\n",
4235 argv[idx_peer]->arg);
4236 return CMD_WARNING_CONFIG_FAILED;
4237 }
4238 } else {
4239 if (peer_address_self_check(bgp, &su)) {
4240 vty_out(vty,
4241 "%% Can not configure the local system as neighbor\n");
4242 return CMD_WARNING_CONFIG_FAILED;
4243 }
4244
4245 /* Disallow for dynamic neighbor. */
4246 peer = peer_lookup(bgp, &su);
4247 if (peer && peer_dynamic_neighbor(peer)) {
4248 vty_out(vty,
4249 "%% Operation not allowed on a dynamic neighbor\n");
4250 return CMD_WARNING_CONFIG_FAILED;
4251 }
4252 }
4253
4254 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4255 if (!group) {
4256 vty_out(vty, "%% Configure the peer-group first\n");
4257 return CMD_WARNING_CONFIG_FAILED;
4258 }
4259
4260 ret = peer_group_bind(bgp, &su, peer, group, &as);
4261
4262 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4263 vty_out(vty,
4264 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4265 as);
4266 return CMD_WARNING_CONFIG_FAILED;
4267 }
4268
4269 return bgp_vty_return(vty, ret);
4270}
4271
4272ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4273 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4274 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4275 "Member of the peer-group\n"
4276 "Peer-group name\n")
596c17ba 4277
718e3744 4278DEFUN (no_neighbor_set_peer_group,
4279 no_neighbor_set_peer_group_cmd,
d7b9898c 4280 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4281 NO_STR
4282 NEIGHBOR_STR
a80beece 4283 NEIGHBOR_ADDR_STR2
718e3744 4284 "Member of the peer-group\n"
16cedbb0 4285 "Peer-group name\n")
718e3744 4286{
d62a17ae 4287 VTY_DECLVAR_CONTEXT(bgp, bgp);
4288 int idx_peer = 2;
4289 int idx_word = 4;
4290 int ret;
4291 struct peer *peer;
4292 struct peer_group *group;
4293
4294 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4295 if (!peer)
4296 return CMD_WARNING_CONFIG_FAILED;
4297
4298 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4299 if (!group) {
4300 vty_out(vty, "%% Configure the peer-group first\n");
4301 return CMD_WARNING_CONFIG_FAILED;
4302 }
718e3744 4303
b3a3290e
DS
4304 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4305 bgp_zebra_terminate_radv(peer->bgp, peer);
4306
4e2786df 4307 peer_notify_unconfig(peer);
827ed707 4308 ret = peer_delete(peer);
718e3744 4309
d62a17ae 4310 return bgp_vty_return(vty, ret);
718e3744 4311}
6b0655a2 4312
d62a17ae 4313ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4314 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4315 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4316 "Member of the peer-group\n"
4317 "Peer-group name\n")
596c17ba 4318
d62a17ae 4319static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4320 uint32_t flag, int set)
718e3744 4321{
d62a17ae 4322 int ret;
4323 struct peer *peer;
718e3744 4324
d62a17ae 4325 peer = peer_and_group_lookup_vty(vty, ip_str);
4326 if (!peer)
4327 return CMD_WARNING_CONFIG_FAILED;
718e3744 4328
7ebe625c
QY
4329 /*
4330 * If 'neighbor <interface>', then this is for directly connected peers,
4331 * we should not accept disable-connected-check.
4332 */
4333 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4334 vty_out(vty,
3efd0893 4335 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
4336 ip_str);
4337 return CMD_WARNING_CONFIG_FAILED;
4338 }
4339
d62a17ae 4340 if (!set && flag == PEER_FLAG_SHUTDOWN)
4341 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4342
d62a17ae 4343 if (set)
4344 ret = peer_flag_set(peer, flag);
4345 else
4346 ret = peer_flag_unset(peer, flag);
718e3744 4347
d62a17ae 4348 return bgp_vty_return(vty, ret);
718e3744 4349}
4350
47cbc09b 4351static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4352{
d62a17ae 4353 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4354}
4355
d62a17ae 4356static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4357 uint32_t flag)
718e3744 4358{
d62a17ae 4359 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4360}
4361
4362/* neighbor passive. */
4363DEFUN (neighbor_passive,
4364 neighbor_passive_cmd,
9ccf14f7 4365 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4366 NEIGHBOR_STR
4367 NEIGHBOR_ADDR_STR2
4368 "Don't send open messages to this neighbor\n")
4369{
d62a17ae 4370 int idx_peer = 1;
4371 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4372}
4373
4374DEFUN (no_neighbor_passive,
4375 no_neighbor_passive_cmd,
9ccf14f7 4376 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4377 NO_STR
4378 NEIGHBOR_STR
4379 NEIGHBOR_ADDR_STR2
4380 "Don't send open messages to this neighbor\n")
4381{
d62a17ae 4382 int idx_peer = 2;
4383 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4384}
6b0655a2 4385
718e3744 4386/* neighbor shutdown. */
73d70fa6
DL
4387DEFUN (neighbor_shutdown_msg,
4388 neighbor_shutdown_msg_cmd,
4389 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 4390 NEIGHBOR_STR
4391 NEIGHBOR_ADDR_STR2
73d70fa6 4392 "Administratively shut down this neighbor\n"
70335e0a 4393 "Add a shutdown message (RFC 8203)\n"
73d70fa6 4394 "Shutdown message\n")
718e3744 4395{
d62a17ae 4396 int idx_peer = 1;
73d70fa6 4397
d62a17ae 4398 if (argc >= 5) {
4399 struct peer *peer =
4400 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4401 char *message;
73d70fa6 4402
d62a17ae 4403 if (!peer)
4404 return CMD_WARNING_CONFIG_FAILED;
4405 message = argv_concat(argv, argc, 4);
4406 peer_tx_shutdown_message_set(peer, message);
4407 XFREE(MTYPE_TMP, message);
4408 }
73d70fa6 4409
d62a17ae 4410 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 4411}
4412
d62a17ae 4413ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4414 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4415 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4416 "Administratively shut down this neighbor\n")
73d70fa6
DL
4417
4418DEFUN (no_neighbor_shutdown_msg,
4419 no_neighbor_shutdown_msg_cmd,
4420 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4421 NO_STR
4422 NEIGHBOR_STR
4423 NEIGHBOR_ADDR_STR2
4424 "Administratively shut down this neighbor\n"
70335e0a 4425 "Remove a shutdown message (RFC 8203)\n"
73d70fa6 4426 "Shutdown message\n")
718e3744 4427{
d62a17ae 4428 int idx_peer = 2;
73d70fa6 4429
d62a17ae 4430 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4431 PEER_FLAG_SHUTDOWN);
718e3744 4432}
6b0655a2 4433
d62a17ae 4434ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4435 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4436 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4437 "Administratively shut down this neighbor\n")
73d70fa6 4438
718e3744 4439/* neighbor capability dynamic. */
4440DEFUN (neighbor_capability_dynamic,
4441 neighbor_capability_dynamic_cmd,
9ccf14f7 4442 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4443 NEIGHBOR_STR
4444 NEIGHBOR_ADDR_STR2
4445 "Advertise capability to the peer\n"
4446 "Advertise dynamic capability to this neighbor\n")
4447{
d62a17ae 4448 int idx_peer = 1;
4449 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4450 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4451}
4452
4453DEFUN (no_neighbor_capability_dynamic,
4454 no_neighbor_capability_dynamic_cmd,
9ccf14f7 4455 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4456 NO_STR
4457 NEIGHBOR_STR
4458 NEIGHBOR_ADDR_STR2
4459 "Advertise capability to the peer\n"
4460 "Advertise dynamic capability to this neighbor\n")
4461{
d62a17ae 4462 int idx_peer = 2;
4463 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4464 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4465}
6b0655a2 4466
718e3744 4467/* neighbor dont-capability-negotiate */
4468DEFUN (neighbor_dont_capability_negotiate,
4469 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4470 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4471 NEIGHBOR_STR
4472 NEIGHBOR_ADDR_STR2
4473 "Do not perform capability negotiation\n")
4474{
d62a17ae 4475 int idx_peer = 1;
4476 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4477 PEER_FLAG_DONT_CAPABILITY);
718e3744 4478}
4479
4480DEFUN (no_neighbor_dont_capability_negotiate,
4481 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4482 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4483 NO_STR
4484 NEIGHBOR_STR
4485 NEIGHBOR_ADDR_STR2
4486 "Do not perform capability negotiation\n")
4487{
d62a17ae 4488 int idx_peer = 2;
4489 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4490 PEER_FLAG_DONT_CAPABILITY);
718e3744 4491}
6b0655a2 4492
8a92a8a0
DS
4493/* neighbor capability extended next hop encoding */
4494DEFUN (neighbor_capability_enhe,
4495 neighbor_capability_enhe_cmd,
9ccf14f7 4496 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4497 NEIGHBOR_STR
4498 NEIGHBOR_ADDR_STR2
4499 "Advertise capability to the peer\n"
4500 "Advertise extended next-hop capability to the peer\n")
4501{
d62a17ae 4502 int idx_peer = 1;
4503 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4504 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4505}
4506
4507DEFUN (no_neighbor_capability_enhe,
4508 no_neighbor_capability_enhe_cmd,
9ccf14f7 4509 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4510 NO_STR
4511 NEIGHBOR_STR
4512 NEIGHBOR_ADDR_STR2
4513 "Advertise capability to the peer\n"
4514 "Advertise extended next-hop capability to the peer\n")
4515{
d62a17ae 4516 int idx_peer = 2;
4517 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4518 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4519}
4520
d62a17ae 4521static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4522 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 4523 int set)
718e3744 4524{
d62a17ae 4525 int ret;
4526 struct peer *peer;
718e3744 4527
d62a17ae 4528 peer = peer_and_group_lookup_vty(vty, peer_str);
4529 if (!peer)
4530 return CMD_WARNING_CONFIG_FAILED;
718e3744 4531
d62a17ae 4532 if (set)
4533 ret = peer_af_flag_set(peer, afi, safi, flag);
4534 else
4535 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 4536
d62a17ae 4537 return bgp_vty_return(vty, ret);
718e3744 4538}
4539
d62a17ae 4540static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4541 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4542{
d62a17ae 4543 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 4544}
4545
d62a17ae 4546static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4547 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4548{
d62a17ae 4549 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 4550}
6b0655a2 4551
718e3744 4552/* neighbor capability orf prefix-list. */
4553DEFUN (neighbor_capability_orf_prefix,
4554 neighbor_capability_orf_prefix_cmd,
9ccf14f7 4555 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4556 NEIGHBOR_STR
4557 NEIGHBOR_ADDR_STR2
4558 "Advertise capability to the peer\n"
4559 "Advertise ORF capability to the peer\n"
4560 "Advertise prefixlist ORF capability to this neighbor\n"
4561 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4562 "Capability to RECEIVE the ORF from this neighbor\n"
4563 "Capability to SEND the ORF to this neighbor\n")
4564{
d62a17ae 4565 int idx_send_recv = 5;
db45f64d
DS
4566 char *peer_str = argv[1]->arg;
4567 struct peer *peer;
4568 afi_t afi = bgp_node_afi(vty);
4569 safi_t safi = bgp_node_safi(vty);
d62a17ae 4570
db45f64d
DS
4571 peer = peer_and_group_lookup_vty(vty, peer_str);
4572 if (!peer)
d62a17ae 4573 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4574
db45f64d
DS
4575 if (strmatch(argv[idx_send_recv]->text, "send"))
4576 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
4577 PEER_FLAG_ORF_PREFIX_SM);
4578
4579 if (strmatch(argv[idx_send_recv]->text, "receive"))
4580 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
4581 PEER_FLAG_ORF_PREFIX_RM);
4582
4583 if (strmatch(argv[idx_send_recv]->text, "both"))
4584 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
4585 PEER_FLAG_ORF_PREFIX_SM)
4586 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
4587 PEER_FLAG_ORF_PREFIX_RM);
4588
4589 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4590}
4591
4592ALIAS_HIDDEN(
4593 neighbor_capability_orf_prefix,
4594 neighbor_capability_orf_prefix_hidden_cmd,
4595 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4596 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4597 "Advertise capability to the peer\n"
4598 "Advertise ORF capability to the peer\n"
4599 "Advertise prefixlist ORF capability to this neighbor\n"
4600 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4601 "Capability to RECEIVE the ORF from this neighbor\n"
4602 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4603
718e3744 4604DEFUN (no_neighbor_capability_orf_prefix,
4605 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 4606 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4607 NO_STR
4608 NEIGHBOR_STR
4609 NEIGHBOR_ADDR_STR2
4610 "Advertise capability to the peer\n"
4611 "Advertise ORF capability to the peer\n"
4612 "Advertise prefixlist ORF capability to this neighbor\n"
4613 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4614 "Capability to RECEIVE the ORF from this neighbor\n"
4615 "Capability to SEND the ORF to this neighbor\n")
4616{
d62a17ae 4617 int idx_send_recv = 6;
db45f64d
DS
4618 char *peer_str = argv[2]->arg;
4619 struct peer *peer;
4620 afi_t afi = bgp_node_afi(vty);
4621 safi_t safi = bgp_node_safi(vty);
d62a17ae 4622
db45f64d
DS
4623 peer = peer_and_group_lookup_vty(vty, peer_str);
4624 if (!peer)
d62a17ae 4625 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4626
db45f64d
DS
4627 if (strmatch(argv[idx_send_recv]->text, "send"))
4628 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4629 PEER_FLAG_ORF_PREFIX_SM);
4630
4631 if (strmatch(argv[idx_send_recv]->text, "receive"))
4632 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4633 PEER_FLAG_ORF_PREFIX_RM);
4634
4635 if (strmatch(argv[idx_send_recv]->text, "both"))
4636 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4637 PEER_FLAG_ORF_PREFIX_SM)
4638 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4639 PEER_FLAG_ORF_PREFIX_RM);
4640
4641 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4642}
4643
4644ALIAS_HIDDEN(
4645 no_neighbor_capability_orf_prefix,
4646 no_neighbor_capability_orf_prefix_hidden_cmd,
4647 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4648 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4649 "Advertise capability to the peer\n"
4650 "Advertise ORF capability to the peer\n"
4651 "Advertise prefixlist ORF capability to this neighbor\n"
4652 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4653 "Capability to RECEIVE the ORF from this neighbor\n"
4654 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4655
718e3744 4656/* neighbor next-hop-self. */
4657DEFUN (neighbor_nexthop_self,
4658 neighbor_nexthop_self_cmd,
9ccf14f7 4659 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4660 NEIGHBOR_STR
4661 NEIGHBOR_ADDR_STR2
a538debe 4662 "Disable the next hop calculation for this neighbor\n")
718e3744 4663{
d62a17ae 4664 int idx_peer = 1;
4665 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4666 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 4667}
9e7a53c1 4668
d62a17ae 4669ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
4670 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4671 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4672 "Disable the next hop calculation for this neighbor\n")
596c17ba 4673
a538debe
DS
4674/* neighbor next-hop-self. */
4675DEFUN (neighbor_nexthop_self_force,
4676 neighbor_nexthop_self_force_cmd,
9ccf14f7 4677 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4678 NEIGHBOR_STR
4679 NEIGHBOR_ADDR_STR2
4680 "Disable the next hop calculation for this neighbor\n"
4681 "Set the next hop to self for reflected routes\n")
4682{
d62a17ae 4683 int idx_peer = 1;
4684 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4685 bgp_node_safi(vty),
4686 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 4687}
4688
d62a17ae 4689ALIAS_HIDDEN(neighbor_nexthop_self_force,
4690 neighbor_nexthop_self_force_hidden_cmd,
4691 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4692 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4693 "Disable the next hop calculation for this neighbor\n"
4694 "Set the next hop to self for reflected routes\n")
596c17ba 4695
1bc4e531
DA
4696ALIAS_HIDDEN(neighbor_nexthop_self_force,
4697 neighbor_nexthop_self_all_hidden_cmd,
4698 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4700 "Disable the next hop calculation for this neighbor\n"
4701 "Set the next hop to self for reflected routes\n")
4702
718e3744 4703DEFUN (no_neighbor_nexthop_self,
4704 no_neighbor_nexthop_self_cmd,
9ccf14f7 4705 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4706 NO_STR
4707 NEIGHBOR_STR
4708 NEIGHBOR_ADDR_STR2
a538debe 4709 "Disable the next hop calculation for this neighbor\n")
718e3744 4710{
d62a17ae 4711 int idx_peer = 2;
4712 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4713 bgp_node_afi(vty), bgp_node_safi(vty),
4714 PEER_FLAG_NEXTHOP_SELF);
718e3744 4715}
6b0655a2 4716
d62a17ae 4717ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4718 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4719 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4720 "Disable the next hop calculation for this neighbor\n")
596c17ba 4721
88b8ed8d 4722DEFUN (no_neighbor_nexthop_self_force,
a538debe 4723 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 4724 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4725 NO_STR
4726 NEIGHBOR_STR
4727 NEIGHBOR_ADDR_STR2
4728 "Disable the next hop calculation for this neighbor\n"
4729 "Set the next hop to self for reflected routes\n")
88b8ed8d 4730{
d62a17ae 4731 int idx_peer = 2;
4732 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4733 bgp_node_afi(vty), bgp_node_safi(vty),
4734 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 4735}
a538debe 4736
d62a17ae 4737ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4738 no_neighbor_nexthop_self_force_hidden_cmd,
4739 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4741 "Disable the next hop calculation for this neighbor\n"
4742 "Set the next hop to self for reflected routes\n")
596c17ba 4743
1bc4e531
DA
4744ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4745 no_neighbor_nexthop_self_all_hidden_cmd,
4746 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4747 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4748 "Disable the next hop calculation for this neighbor\n"
4749 "Set the next hop to self for reflected routes\n")
4750
c7122e14
DS
4751/* neighbor as-override */
4752DEFUN (neighbor_as_override,
4753 neighbor_as_override_cmd,
9ccf14f7 4754 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4755 NEIGHBOR_STR
4756 NEIGHBOR_ADDR_STR2
4757 "Override ASNs in outbound updates if aspath equals remote-as\n")
4758{
d62a17ae 4759 int idx_peer = 1;
4760 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4761 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4762}
4763
d62a17ae 4764ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4765 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4766 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4767 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4768
c7122e14
DS
4769DEFUN (no_neighbor_as_override,
4770 no_neighbor_as_override_cmd,
9ccf14f7 4771 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4772 NO_STR
4773 NEIGHBOR_STR
4774 NEIGHBOR_ADDR_STR2
4775 "Override ASNs in outbound updates if aspath equals remote-as\n")
4776{
d62a17ae 4777 int idx_peer = 2;
4778 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4779 bgp_node_afi(vty), bgp_node_safi(vty),
4780 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4781}
4782
d62a17ae 4783ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4784 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4785 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4786 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4787
718e3744 4788/* neighbor remove-private-AS. */
4789DEFUN (neighbor_remove_private_as,
4790 neighbor_remove_private_as_cmd,
9ccf14f7 4791 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4792 NEIGHBOR_STR
4793 NEIGHBOR_ADDR_STR2
5000f21c 4794 "Remove private ASNs in outbound updates\n")
718e3744 4795{
d62a17ae 4796 int idx_peer = 1;
4797 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4798 bgp_node_safi(vty),
4799 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4800}
4801
d62a17ae 4802ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4803 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4804 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4805 "Remove private ASNs in outbound updates\n")
596c17ba 4806
5000f21c
DS
4807DEFUN (neighbor_remove_private_as_all,
4808 neighbor_remove_private_as_all_cmd,
9ccf14f7 4809 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4810 NEIGHBOR_STR
4811 NEIGHBOR_ADDR_STR2
4812 "Remove private ASNs in outbound updates\n"
efd7904e 4813 "Apply to all AS numbers\n")
5000f21c 4814{
d62a17ae 4815 int idx_peer = 1;
4816 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4817 bgp_node_safi(vty),
4818 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4819}
4820
d62a17ae 4821ALIAS_HIDDEN(neighbor_remove_private_as_all,
4822 neighbor_remove_private_as_all_hidden_cmd,
4823 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4824 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4825 "Remove private ASNs in outbound updates\n"
4826 "Apply to all AS numbers")
596c17ba 4827
5000f21c
DS
4828DEFUN (neighbor_remove_private_as_replace_as,
4829 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4830 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4831 NEIGHBOR_STR
4832 NEIGHBOR_ADDR_STR2
4833 "Remove private ASNs in outbound updates\n"
4834 "Replace private ASNs with our ASN in outbound updates\n")
4835{
d62a17ae 4836 int idx_peer = 1;
4837 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4838 bgp_node_safi(vty),
4839 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4840}
4841
d62a17ae 4842ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4843 neighbor_remove_private_as_replace_as_hidden_cmd,
4844 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4845 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4846 "Remove private ASNs in outbound updates\n"
4847 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4848
5000f21c
DS
4849DEFUN (neighbor_remove_private_as_all_replace_as,
4850 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4851 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4852 NEIGHBOR_STR
4853 NEIGHBOR_ADDR_STR2
4854 "Remove private ASNs in outbound updates\n"
16cedbb0 4855 "Apply to all AS numbers\n"
5000f21c
DS
4856 "Replace private ASNs with our ASN in outbound updates\n")
4857{
d62a17ae 4858 int idx_peer = 1;
4859 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4860 bgp_node_safi(vty),
4861 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4862}
4863
d62a17ae 4864ALIAS_HIDDEN(
4865 neighbor_remove_private_as_all_replace_as,
4866 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4867 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4868 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4869 "Remove private ASNs in outbound updates\n"
4870 "Apply to all AS numbers\n"
4871 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4872
718e3744 4873DEFUN (no_neighbor_remove_private_as,
4874 no_neighbor_remove_private_as_cmd,
9ccf14f7 4875 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4876 NO_STR
4877 NEIGHBOR_STR
4878 NEIGHBOR_ADDR_STR2
5000f21c 4879 "Remove private ASNs in outbound updates\n")
718e3744 4880{
d62a17ae 4881 int idx_peer = 2;
4882 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4883 bgp_node_afi(vty), bgp_node_safi(vty),
4884 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4885}
6b0655a2 4886
d62a17ae 4887ALIAS_HIDDEN(no_neighbor_remove_private_as,
4888 no_neighbor_remove_private_as_hidden_cmd,
4889 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4890 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4891 "Remove private ASNs in outbound updates\n")
596c17ba 4892
88b8ed8d 4893DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4894 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4895 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4896 NO_STR
4897 NEIGHBOR_STR
4898 NEIGHBOR_ADDR_STR2
4899 "Remove private ASNs in outbound updates\n"
16cedbb0 4900 "Apply to all AS numbers\n")
88b8ed8d 4901{
d62a17ae 4902 int idx_peer = 2;
4903 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4904 bgp_node_afi(vty), bgp_node_safi(vty),
4905 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4906}
5000f21c 4907
d62a17ae 4908ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4909 no_neighbor_remove_private_as_all_hidden_cmd,
4910 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4911 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4912 "Remove private ASNs in outbound updates\n"
4913 "Apply to all AS numbers\n")
596c17ba 4914
88b8ed8d 4915DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4916 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4917 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4918 NO_STR
4919 NEIGHBOR_STR
4920 NEIGHBOR_ADDR_STR2
4921 "Remove private ASNs in outbound updates\n"
4922 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4923{
d62a17ae 4924 int idx_peer = 2;
4925 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4926 bgp_node_afi(vty), bgp_node_safi(vty),
4927 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4928}
5000f21c 4929
d62a17ae 4930ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4931 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4932 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4933 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4934 "Remove private ASNs in outbound updates\n"
4935 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4936
88b8ed8d 4937DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4938 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4939 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4940 NO_STR
4941 NEIGHBOR_STR
4942 NEIGHBOR_ADDR_STR2
4943 "Remove private ASNs in outbound updates\n"
16cedbb0 4944 "Apply to all AS numbers\n"
5000f21c 4945 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4946{
d62a17ae 4947 int idx_peer = 2;
4948 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4949 bgp_node_afi(vty), bgp_node_safi(vty),
4950 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4951}
5000f21c 4952
d62a17ae 4953ALIAS_HIDDEN(
4954 no_neighbor_remove_private_as_all_replace_as,
4955 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4956 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4957 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4958 "Remove private ASNs in outbound updates\n"
4959 "Apply to all AS numbers\n"
4960 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4961
5000f21c 4962
718e3744 4963/* neighbor send-community. */
4964DEFUN (neighbor_send_community,
4965 neighbor_send_community_cmd,
9ccf14f7 4966 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4967 NEIGHBOR_STR
4968 NEIGHBOR_ADDR_STR2
4969 "Send Community attribute to this neighbor\n")
4970{
d62a17ae 4971 int idx_peer = 1;
27c05d4d 4972
d62a17ae 4973 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4974 bgp_node_safi(vty),
4975 PEER_FLAG_SEND_COMMUNITY);
718e3744 4976}
4977
d62a17ae 4978ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4979 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4980 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4981 "Send Community attribute to this neighbor\n")
596c17ba 4982
718e3744 4983DEFUN (no_neighbor_send_community,
4984 no_neighbor_send_community_cmd,
9ccf14f7 4985 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4986 NO_STR
4987 NEIGHBOR_STR
4988 NEIGHBOR_ADDR_STR2
4989 "Send Community attribute to this neighbor\n")
4990{
d62a17ae 4991 int idx_peer = 2;
27c05d4d 4992
d62a17ae 4993 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4994 bgp_node_afi(vty), bgp_node_safi(vty),
4995 PEER_FLAG_SEND_COMMUNITY);
718e3744 4996}
6b0655a2 4997
d62a17ae 4998ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4999 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5000 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5001 "Send Community attribute to this neighbor\n")
596c17ba 5002
718e3744 5003/* neighbor send-community extended. */
5004DEFUN (neighbor_send_community_type,
5005 neighbor_send_community_type_cmd,
57d187bc 5006 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5007 NEIGHBOR_STR
5008 NEIGHBOR_ADDR_STR2
5009 "Send Community attribute to this neighbor\n"
5010 "Send Standard and Extended Community attributes\n"
57d187bc 5011 "Send Standard, Large and Extended Community attributes\n"
718e3744 5012 "Send Extended Community attributes\n"
57d187bc
JS
5013 "Send Standard Community attributes\n"
5014 "Send Large Community attributes\n")
718e3744 5015{
27c05d4d 5016 const char *type = argv[argc - 1]->text;
db45f64d
DS
5017 char *peer_str = argv[1]->arg;
5018 struct peer *peer;
5019 afi_t afi = bgp_node_afi(vty);
5020 safi_t safi = bgp_node_safi(vty);
d62a17ae 5021
db45f64d
DS
5022 peer = peer_and_group_lookup_vty(vty, peer_str);
5023 if (!peer)
5024 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5025
db45f64d
DS
5026 if (strmatch(type, "standard"))
5027 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5028 PEER_FLAG_SEND_COMMUNITY);
5029
5030 if (strmatch(type, "extended"))
5031 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5032 PEER_FLAG_SEND_EXT_COMMUNITY);
5033
5034 if (strmatch(type, "large"))
5035 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5036 PEER_FLAG_SEND_LARGE_COMMUNITY);
5037
5038 if (strmatch(type, "both")) {
5039 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5040 PEER_FLAG_SEND_COMMUNITY)
5041 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5042 PEER_FLAG_SEND_EXT_COMMUNITY);
5043 }
5044 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5045 PEER_FLAG_SEND_COMMUNITY)
5046 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5047 PEER_FLAG_SEND_EXT_COMMUNITY)
5048 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5049 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5050}
5051
5052ALIAS_HIDDEN(
5053 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5054 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5055 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5056 "Send Community attribute to this neighbor\n"
5057 "Send Standard and Extended Community attributes\n"
5058 "Send Standard, Large and Extended Community attributes\n"
5059 "Send Extended Community attributes\n"
5060 "Send Standard Community attributes\n"
5061 "Send Large Community attributes\n")
596c17ba 5062
718e3744 5063DEFUN (no_neighbor_send_community_type,
5064 no_neighbor_send_community_type_cmd,
57d187bc 5065 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5066 NO_STR
5067 NEIGHBOR_STR
5068 NEIGHBOR_ADDR_STR2
5069 "Send Community attribute to this neighbor\n"
5070 "Send Standard and Extended Community attributes\n"
57d187bc 5071 "Send Standard, Large and Extended Community attributes\n"
718e3744 5072 "Send Extended Community attributes\n"
57d187bc
JS
5073 "Send Standard Community attributes\n"
5074 "Send Large Community attributes\n")
718e3744 5075{
d62a17ae 5076 const char *type = argv[argc - 1]->text;
db45f64d
DS
5077 char *peer_str = argv[2]->arg;
5078 struct peer *peer;
5079 afi_t afi = bgp_node_afi(vty);
5080 safi_t safi = bgp_node_safi(vty);
5081
5082 peer = peer_and_group_lookup_vty(vty, peer_str);
5083 if (!peer)
5084 return CMD_WARNING_CONFIG_FAILED;
5085
5086 if (strmatch(type, "standard"))
5087 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5088 PEER_FLAG_SEND_COMMUNITY);
5089
5090 if (strmatch(type, "extended"))
5091 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5092 PEER_FLAG_SEND_EXT_COMMUNITY);
5093
5094 if (strmatch(type, "large"))
5095 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5096 PEER_FLAG_SEND_LARGE_COMMUNITY);
5097
5098 if (strmatch(type, "both")) {
d62a17ae 5099
db45f64d
DS
5100 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5101 PEER_FLAG_SEND_COMMUNITY)
5102 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5103 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5104 }
5105
db45f64d
DS
5106 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5107 PEER_FLAG_SEND_COMMUNITY)
5108 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5109 PEER_FLAG_SEND_EXT_COMMUNITY)
5110 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5111 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5112}
5113
5114ALIAS_HIDDEN(
5115 no_neighbor_send_community_type,
5116 no_neighbor_send_community_type_hidden_cmd,
5117 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5118 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5119 "Send Community attribute to this neighbor\n"
5120 "Send Standard and Extended Community attributes\n"
5121 "Send Standard, Large and Extended Community attributes\n"
5122 "Send Extended Community attributes\n"
5123 "Send Standard Community attributes\n"
5124 "Send Large Community attributes\n")
596c17ba 5125
718e3744 5126/* neighbor soft-reconfig. */
5127DEFUN (neighbor_soft_reconfiguration,
5128 neighbor_soft_reconfiguration_cmd,
9ccf14f7 5129 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5130 NEIGHBOR_STR
5131 NEIGHBOR_ADDR_STR2
5132 "Per neighbor soft reconfiguration\n"
5133 "Allow inbound soft reconfiguration for this neighbor\n")
5134{
d62a17ae 5135 int idx_peer = 1;
5136 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5137 bgp_node_safi(vty),
5138 PEER_FLAG_SOFT_RECONFIG);
718e3744 5139}
5140
d62a17ae 5141ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5142 neighbor_soft_reconfiguration_hidden_cmd,
5143 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5144 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5145 "Per neighbor soft reconfiguration\n"
5146 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5147
718e3744 5148DEFUN (no_neighbor_soft_reconfiguration,
5149 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 5150 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5151 NO_STR
5152 NEIGHBOR_STR
5153 NEIGHBOR_ADDR_STR2
5154 "Per neighbor soft reconfiguration\n"
5155 "Allow inbound soft reconfiguration for this neighbor\n")
5156{
d62a17ae 5157 int idx_peer = 2;
5158 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5159 bgp_node_afi(vty), bgp_node_safi(vty),
5160 PEER_FLAG_SOFT_RECONFIG);
718e3744 5161}
6b0655a2 5162
d62a17ae 5163ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5164 no_neighbor_soft_reconfiguration_hidden_cmd,
5165 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5166 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5167 "Per neighbor soft reconfiguration\n"
5168 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5169
718e3744 5170DEFUN (neighbor_route_reflector_client,
5171 neighbor_route_reflector_client_cmd,
9ccf14f7 5172 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5173 NEIGHBOR_STR
5174 NEIGHBOR_ADDR_STR2
5175 "Configure a neighbor as Route Reflector client\n")
5176{
d62a17ae 5177 int idx_peer = 1;
5178 struct peer *peer;
718e3744 5179
5180
d62a17ae 5181 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5182 if (!peer)
5183 return CMD_WARNING_CONFIG_FAILED;
718e3744 5184
d62a17ae 5185 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5186 bgp_node_safi(vty),
5187 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5188}
5189
d62a17ae 5190ALIAS_HIDDEN(neighbor_route_reflector_client,
5191 neighbor_route_reflector_client_hidden_cmd,
5192 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5193 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5194 "Configure a neighbor as Route Reflector client\n")
596c17ba 5195
718e3744 5196DEFUN (no_neighbor_route_reflector_client,
5197 no_neighbor_route_reflector_client_cmd,
9ccf14f7 5198 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5199 NO_STR
5200 NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "Configure a neighbor as Route Reflector client\n")
5203{
d62a17ae 5204 int idx_peer = 2;
5205 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5206 bgp_node_afi(vty), bgp_node_safi(vty),
5207 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5208}
6b0655a2 5209
d62a17ae 5210ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5211 no_neighbor_route_reflector_client_hidden_cmd,
5212 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5213 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5214 "Configure a neighbor as Route Reflector client\n")
596c17ba 5215
718e3744 5216/* neighbor route-server-client. */
5217DEFUN (neighbor_route_server_client,
5218 neighbor_route_server_client_cmd,
9ccf14f7 5219 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5220 NEIGHBOR_STR
5221 NEIGHBOR_ADDR_STR2
5222 "Configure a neighbor as Route Server client\n")
5223{
d62a17ae 5224 int idx_peer = 1;
5225 struct peer *peer;
2a3d5731 5226
d62a17ae 5227 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5228 if (!peer)
5229 return CMD_WARNING_CONFIG_FAILED;
5230 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5231 bgp_node_safi(vty),
5232 PEER_FLAG_RSERVER_CLIENT);
718e3744 5233}
5234
d62a17ae 5235ALIAS_HIDDEN(neighbor_route_server_client,
5236 neighbor_route_server_client_hidden_cmd,
5237 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5238 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5239 "Configure a neighbor as Route Server client\n")
596c17ba 5240
718e3744 5241DEFUN (no_neighbor_route_server_client,
5242 no_neighbor_route_server_client_cmd,
9ccf14f7 5243 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5244 NO_STR
5245 NEIGHBOR_STR
5246 NEIGHBOR_ADDR_STR2
5247 "Configure a neighbor as Route Server client\n")
fee0f4c6 5248{
d62a17ae 5249 int idx_peer = 2;
5250 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5251 bgp_node_afi(vty), bgp_node_safi(vty),
5252 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5253}
6b0655a2 5254
d62a17ae 5255ALIAS_HIDDEN(no_neighbor_route_server_client,
5256 no_neighbor_route_server_client_hidden_cmd,
5257 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5258 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5259 "Configure a neighbor as Route Server client\n")
596c17ba 5260
fee0f4c6 5261DEFUN (neighbor_nexthop_local_unchanged,
5262 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5263 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5264 NEIGHBOR_STR
5265 NEIGHBOR_ADDR_STR2
5266 "Configure treatment of outgoing link-local nexthop attribute\n"
5267 "Leave link-local nexthop unchanged for this peer\n")
5268{
d62a17ae 5269 int idx_peer = 1;
5270 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5271 bgp_node_safi(vty),
5272 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 5273}
6b0655a2 5274
fee0f4c6 5275DEFUN (no_neighbor_nexthop_local_unchanged,
5276 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5277 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5278 NO_STR
5279 NEIGHBOR_STR
5280 NEIGHBOR_ADDR_STR2
5281 "Configure treatment of outgoing link-local-nexthop attribute\n"
5282 "Leave link-local nexthop unchanged for this peer\n")
718e3744 5283{
d62a17ae 5284 int idx_peer = 2;
5285 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5286 bgp_node_afi(vty), bgp_node_safi(vty),
5287 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 5288}
6b0655a2 5289
718e3744 5290DEFUN (neighbor_attr_unchanged,
5291 neighbor_attr_unchanged_cmd,
a8206004 5292 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 5293 NEIGHBOR_STR
5294 NEIGHBOR_ADDR_STR2
5295 "BGP attribute is propagated unchanged to this neighbor\n"
5296 "As-path attribute\n"
5297 "Nexthop attribute\n"
a8206004 5298 "Med attribute\n")
718e3744 5299{
d62a17ae 5300 int idx = 0;
8eeb0335
DW
5301 char *peer_str = argv[1]->arg;
5302 struct peer *peer;
db45f64d
DS
5303 bool aspath = false;
5304 bool nexthop = false;
5305 bool med = false;
8eeb0335
DW
5306 afi_t afi = bgp_node_afi(vty);
5307 safi_t safi = bgp_node_safi(vty);
db45f64d 5308 int ret = 0;
8eeb0335
DW
5309
5310 peer = peer_and_group_lookup_vty(vty, peer_str);
5311 if (!peer)
5312 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5313
5314 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5315 aspath = true;
5316
d62a17ae 5317 idx = 0;
5318 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5319 nexthop = true;
5320
d62a17ae 5321 idx = 0;
5322 if (argv_find(argv, argc, "med", &idx))
db45f64d 5323 med = true;
d62a17ae 5324
8eeb0335 5325 /* no flags means all of them! */
db45f64d
DS
5326 if (!aspath && !nexthop && !med) {
5327 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
5328 PEER_FLAG_AS_PATH_UNCHANGED);
5329 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5330 PEER_FLAG_NEXTHOP_UNCHANGED);
5331 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5332 PEER_FLAG_MED_UNCHANGED);
8eeb0335 5333 } else {
db45f64d
DS
5334 if (!aspath) {
5335 if (peer_af_flag_check(peer, afi, safi,
5336 PEER_FLAG_AS_PATH_UNCHANGED)) {
5337 ret |= peer_af_flag_unset_vty(
5338 vty, peer_str, afi, safi,
5339 PEER_FLAG_AS_PATH_UNCHANGED);
5340 }
5341 } else
5342 ret |= peer_af_flag_set_vty(
5343 vty, peer_str, afi, safi,
5344 PEER_FLAG_AS_PATH_UNCHANGED);
5345
5346 if (!nexthop) {
5347 if (peer_af_flag_check(peer, afi, safi,
5348 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5349 ret |= peer_af_flag_unset_vty(
5350 vty, peer_str, afi, safi,
5351 PEER_FLAG_NEXTHOP_UNCHANGED);
5352 }
5353 } else
5354 ret |= peer_af_flag_set_vty(
5355 vty, peer_str, afi, safi,
5356 PEER_FLAG_NEXTHOP_UNCHANGED);
5357
5358 if (!med) {
5359 if (peer_af_flag_check(peer, afi, safi,
5360 PEER_FLAG_MED_UNCHANGED)) {
5361 ret |= peer_af_flag_unset_vty(
5362 vty, peer_str, afi, safi,
5363 PEER_FLAG_MED_UNCHANGED);
5364 }
5365 } else
5366 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5367 PEER_FLAG_MED_UNCHANGED);
d62a17ae 5368 }
5369
db45f64d 5370 return ret;
d62a17ae 5371}
5372
5373ALIAS_HIDDEN(
5374 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5375 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5376 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5377 "BGP attribute is propagated unchanged to this neighbor\n"
5378 "As-path attribute\n"
5379 "Nexthop attribute\n"
5380 "Med attribute\n")
596c17ba 5381
718e3744 5382DEFUN (no_neighbor_attr_unchanged,
5383 no_neighbor_attr_unchanged_cmd,
a8206004 5384 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 5385 NO_STR
718e3744 5386 NEIGHBOR_STR
5387 NEIGHBOR_ADDR_STR2
31500417
DW
5388 "BGP attribute is propagated unchanged to this neighbor\n"
5389 "As-path attribute\n"
40e718b5 5390 "Nexthop attribute\n"
a8206004 5391 "Med attribute\n")
718e3744 5392{
d62a17ae 5393 int idx = 0;
db45f64d
DS
5394 char *peer_str = argv[2]->arg;
5395 struct peer *peer;
5396 bool aspath = false;
5397 bool nexthop = false;
5398 bool med = false;
5399 afi_t afi = bgp_node_afi(vty);
5400 safi_t safi = bgp_node_safi(vty);
5401 int ret = 0;
5402
5403 peer = peer_and_group_lookup_vty(vty, peer_str);
5404 if (!peer)
5405 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5406
5407 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5408 aspath = true;
5409
d62a17ae 5410 idx = 0;
5411 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5412 nexthop = true;
5413
d62a17ae 5414 idx = 0;
5415 if (argv_find(argv, argc, "med", &idx))
db45f64d 5416 med = true;
d62a17ae 5417
db45f64d
DS
5418 if (!aspath && !nexthop && !med) // no flags means all of them!
5419 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5420 PEER_FLAG_AS_PATH_UNCHANGED)
5421 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5422 PEER_FLAG_NEXTHOP_UNCHANGED)
5423 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5424 PEER_FLAG_MED_UNCHANGED);
5425
5426 if (aspath)
5427 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5428 PEER_FLAG_AS_PATH_UNCHANGED);
5429
5430 if (nexthop)
5431 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5432 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 5433
db45f64d
DS
5434 if (med)
5435 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5436 PEER_FLAG_MED_UNCHANGED);
5437
5438 return ret;
d62a17ae 5439}
5440
5441ALIAS_HIDDEN(
5442 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5443 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5444 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5445 "BGP attribute is propagated unchanged to this neighbor\n"
5446 "As-path attribute\n"
5447 "Nexthop attribute\n"
5448 "Med attribute\n")
718e3744 5449
718e3744 5450/* EBGP multihop configuration. */
d62a17ae 5451static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5452 const char *ttl_str)
718e3744 5453{
d62a17ae 5454 struct peer *peer;
5455 unsigned int ttl;
718e3744 5456
d62a17ae 5457 peer = peer_and_group_lookup_vty(vty, ip_str);
5458 if (!peer)
5459 return CMD_WARNING_CONFIG_FAILED;
718e3744 5460
d62a17ae 5461 if (peer->conf_if)
5462 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 5463
d62a17ae 5464 if (!ttl_str)
5465 ttl = MAXTTL;
5466 else
5467 ttl = strtoul(ttl_str, NULL, 10);
718e3744 5468
d62a17ae 5469 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 5470}
5471
d62a17ae 5472static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5473{
d62a17ae 5474 struct peer *peer;
718e3744 5475
d62a17ae 5476 peer = peer_and_group_lookup_vty(vty, ip_str);
5477 if (!peer)
5478 return CMD_WARNING_CONFIG_FAILED;
718e3744 5479
d62a17ae 5480 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 5481}
5482
5483/* neighbor ebgp-multihop. */
5484DEFUN (neighbor_ebgp_multihop,
5485 neighbor_ebgp_multihop_cmd,
9ccf14f7 5486 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 5487 NEIGHBOR_STR
5488 NEIGHBOR_ADDR_STR2
5489 "Allow EBGP neighbors not on directly connected networks\n")
5490{
d62a17ae 5491 int idx_peer = 1;
5492 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5493}
5494
5495DEFUN (neighbor_ebgp_multihop_ttl,
5496 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 5497 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 5498 NEIGHBOR_STR
5499 NEIGHBOR_ADDR_STR2
5500 "Allow EBGP neighbors not on directly connected networks\n"
5501 "maximum hop count\n")
5502{
d62a17ae 5503 int idx_peer = 1;
5504 int idx_number = 3;
5505 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
5506 argv[idx_number]->arg);
718e3744 5507}
5508
5509DEFUN (no_neighbor_ebgp_multihop,
5510 no_neighbor_ebgp_multihop_cmd,
a636c635 5511 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 5512 NO_STR
5513 NEIGHBOR_STR
5514 NEIGHBOR_ADDR_STR2
a636c635
DW
5515 "Allow EBGP neighbors not on directly connected networks\n"
5516 "maximum hop count\n")
718e3744 5517{
d62a17ae 5518 int idx_peer = 2;
5519 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5520}
5521
6b0655a2 5522
6ffd2079 5523/* disable-connected-check */
5524DEFUN (neighbor_disable_connected_check,
5525 neighbor_disable_connected_check_cmd,
7ebe625c 5526 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5527 NEIGHBOR_STR
7ebe625c 5528 NEIGHBOR_ADDR_STR2
a636c635
DW
5529 "one-hop away EBGP peer using loopback address\n"
5530 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5531{
d62a17ae 5532 int idx_peer = 1;
5533 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5534 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5535}
5536
5537DEFUN (no_neighbor_disable_connected_check,
5538 no_neighbor_disable_connected_check_cmd,
7ebe625c 5539 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5540 NO_STR
5541 NEIGHBOR_STR
7ebe625c 5542 NEIGHBOR_ADDR_STR2
a636c635
DW
5543 "one-hop away EBGP peer using loopback address\n"
5544 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5545{
d62a17ae 5546 int idx_peer = 2;
5547 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5548 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5549}
5550
47cbc09b
PM
5551
5552/* enforce-first-as */
5553DEFUN (neighbor_enforce_first_as,
5554 neighbor_enforce_first_as_cmd,
5555 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5556 NEIGHBOR_STR
5557 NEIGHBOR_ADDR_STR2
5558 "Enforce the first AS for EBGP routes\n")
5559{
5560 int idx_peer = 1;
5561
5562 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5563 PEER_FLAG_ENFORCE_FIRST_AS);
5564}
5565
5566DEFUN (no_neighbor_enforce_first_as,
5567 no_neighbor_enforce_first_as_cmd,
5568 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5569 NO_STR
5570 NEIGHBOR_STR
5571 NEIGHBOR_ADDR_STR2
5572 "Enforce the first AS for EBGP routes\n")
5573{
5574 int idx_peer = 2;
5575
5576 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5577 PEER_FLAG_ENFORCE_FIRST_AS);
5578}
5579
5580
718e3744 5581DEFUN (neighbor_description,
5582 neighbor_description_cmd,
e961923c 5583 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 5584 NEIGHBOR_STR
5585 NEIGHBOR_ADDR_STR2
5586 "Neighbor specific description\n"
5587 "Up to 80 characters describing this neighbor\n")
5588{
d62a17ae 5589 int idx_peer = 1;
5590 int idx_line = 3;
5591 struct peer *peer;
5592 char *str;
718e3744 5593
d62a17ae 5594 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5595 if (!peer)
5596 return CMD_WARNING_CONFIG_FAILED;
718e3744 5597
d62a17ae 5598 str = argv_concat(argv, argc, idx_line);
718e3744 5599
d62a17ae 5600 peer_description_set(peer, str);
718e3744 5601
d62a17ae 5602 XFREE(MTYPE_TMP, str);
718e3744 5603
d62a17ae 5604 return CMD_SUCCESS;
718e3744 5605}
5606
5607DEFUN (no_neighbor_description,
5608 no_neighbor_description_cmd,
a14810f4 5609 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 5610 NO_STR
5611 NEIGHBOR_STR
5612 NEIGHBOR_ADDR_STR2
a14810f4 5613 "Neighbor specific description\n")
718e3744 5614{
d62a17ae 5615 int idx_peer = 2;
5616 struct peer *peer;
718e3744 5617
d62a17ae 5618 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5619 if (!peer)
5620 return CMD_WARNING_CONFIG_FAILED;
718e3744 5621
d62a17ae 5622 peer_description_unset(peer);
718e3744 5623
d62a17ae 5624 return CMD_SUCCESS;
718e3744 5625}
5626
a14810f4
PM
5627ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
5628 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5629 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5630 "Neighbor specific description\n"
5631 "Up to 80 characters describing this neighbor\n")
6b0655a2 5632
718e3744 5633/* Neighbor update-source. */
d62a17ae 5634static int peer_update_source_vty(struct vty *vty, const char *peer_str,
5635 const char *source_str)
5636{
5637 struct peer *peer;
5638 struct prefix p;
a14810f4 5639 union sockunion su;
d62a17ae 5640
5641 peer = peer_and_group_lookup_vty(vty, peer_str);
5642 if (!peer)
5643 return CMD_WARNING_CONFIG_FAILED;
5644
5645 if (peer->conf_if)
5646 return CMD_WARNING;
5647
5648 if (source_str) {
a14810f4 5649 if (str2sockunion(source_str, &su) == 0)
d62a17ae 5650 peer_update_source_addr_set(peer, &su);
5651 else {
5652 if (str2prefix(source_str, &p)) {
5653 vty_out(vty,
5654 "%% Invalid update-source, remove prefix length \n");
5655 return CMD_WARNING_CONFIG_FAILED;
5656 } else
5657 peer_update_source_if_set(peer, source_str);
5658 }
5659 } else
5660 peer_update_source_unset(peer);
5661
5662 return CMD_SUCCESS;
5663}
5664
5665#define BGP_UPDATE_SOURCE_HELP_STR \
5666 "IPv4 address\n" \
5667 "IPv6 address\n" \
5668 "Interface name (requires zebra to be running)\n"
369688c0 5669
718e3744 5670DEFUN (neighbor_update_source,
5671 neighbor_update_source_cmd,
9ccf14f7 5672 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 5673 NEIGHBOR_STR
5674 NEIGHBOR_ADDR_STR2
5675 "Source of routing updates\n"
369688c0 5676 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5677{
d62a17ae 5678 int idx_peer = 1;
5679 int idx_peer_2 = 3;
5680 return peer_update_source_vty(vty, argv[idx_peer]->arg,
5681 argv[idx_peer_2]->arg);
718e3744 5682}
5683
5684DEFUN (no_neighbor_update_source,
5685 no_neighbor_update_source_cmd,
c7178fe7 5686 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 5687 NO_STR
5688 NEIGHBOR_STR
5689 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
5690 "Source of routing updates\n"
5691 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5692{
d62a17ae 5693 int idx_peer = 2;
5694 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5695}
6b0655a2 5696
d62a17ae 5697static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
5698 afi_t afi, safi_t safi,
5699 const char *rmap, int set)
718e3744 5700{
d62a17ae 5701 int ret;
5702 struct peer *peer;
80912664 5703 struct route_map *route_map = NULL;
718e3744 5704
d62a17ae 5705 peer = peer_and_group_lookup_vty(vty, peer_str);
5706 if (!peer)
5707 return CMD_WARNING_CONFIG_FAILED;
718e3744 5708
1de27621 5709 if (set) {
80912664
DS
5710 if (rmap)
5711 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
5712 ret = peer_default_originate_set(peer, afi, safi,
5713 rmap, route_map);
5714 } else
d62a17ae 5715 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 5716
d62a17ae 5717 return bgp_vty_return(vty, ret);
718e3744 5718}
5719
5720/* neighbor default-originate. */
5721DEFUN (neighbor_default_originate,
5722 neighbor_default_originate_cmd,
9ccf14f7 5723 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Originate default route to this neighbor\n")
5727{
d62a17ae 5728 int idx_peer = 1;
5729 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5730 bgp_node_afi(vty),
5731 bgp_node_safi(vty), NULL, 1);
718e3744 5732}
5733
d62a17ae 5734ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
5735 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5737 "Originate default route to this neighbor\n")
596c17ba 5738
718e3744 5739DEFUN (neighbor_default_originate_rmap,
5740 neighbor_default_originate_rmap_cmd,
9ccf14f7 5741 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 5742 NEIGHBOR_STR
5743 NEIGHBOR_ADDR_STR2
5744 "Originate default route to this neighbor\n"
5745 "Route-map to specify criteria to originate default\n"
5746 "route-map name\n")
5747{
d62a17ae 5748 int idx_peer = 1;
5749 int idx_word = 4;
5750 return peer_default_originate_set_vty(
5751 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5752 argv[idx_word]->arg, 1);
718e3744 5753}
5754
d62a17ae 5755ALIAS_HIDDEN(
5756 neighbor_default_originate_rmap,
5757 neighbor_default_originate_rmap_hidden_cmd,
5758 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5759 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5760 "Originate default route to this neighbor\n"
5761 "Route-map to specify criteria to originate default\n"
5762 "route-map name\n")
596c17ba 5763
718e3744 5764DEFUN (no_neighbor_default_originate,
5765 no_neighbor_default_originate_cmd,
a636c635 5766 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 5767 NO_STR
5768 NEIGHBOR_STR
5769 NEIGHBOR_ADDR_STR2
a636c635
DW
5770 "Originate default route to this neighbor\n"
5771 "Route-map to specify criteria to originate default\n"
5772 "route-map name\n")
718e3744 5773{
d62a17ae 5774 int idx_peer = 2;
5775 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5776 bgp_node_afi(vty),
5777 bgp_node_safi(vty), NULL, 0);
718e3744 5778}
5779
d62a17ae 5780ALIAS_HIDDEN(
5781 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5782 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5784 "Originate default route to this neighbor\n"
5785 "Route-map to specify criteria to originate default\n"
5786 "route-map name\n")
596c17ba 5787
6b0655a2 5788
718e3744 5789/* Set neighbor's BGP port. */
d62a17ae 5790static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5791 const char *port_str)
5792{
5793 struct peer *peer;
d7c0a89a 5794 uint16_t port;
d62a17ae 5795 struct servent *sp;
5796
5797 peer = peer_lookup_vty(vty, ip_str);
5798 if (!peer)
5799 return CMD_WARNING_CONFIG_FAILED;
5800
5801 if (!port_str) {
5802 sp = getservbyname("bgp", "tcp");
5803 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5804 } else {
5805 port = strtoul(port_str, NULL, 10);
5806 }
718e3744 5807
d62a17ae 5808 peer_port_set(peer, port);
718e3744 5809
d62a17ae 5810 return CMD_SUCCESS;
718e3744 5811}
5812
f418446b 5813/* Set specified peer's BGP port. */
718e3744 5814DEFUN (neighbor_port,
5815 neighbor_port_cmd,
9ccf14f7 5816 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 5817 NEIGHBOR_STR
5818 NEIGHBOR_ADDR_STR
5819 "Neighbor's BGP port\n"
5820 "TCP port number\n")
5821{
d62a17ae 5822 int idx_ip = 1;
5823 int idx_number = 3;
5824 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5825 argv[idx_number]->arg);
718e3744 5826}
5827
5828DEFUN (no_neighbor_port,
5829 no_neighbor_port_cmd,
9ccf14f7 5830 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 5831 NO_STR
5832 NEIGHBOR_STR
5833 NEIGHBOR_ADDR_STR
8334fd5a
DW
5834 "Neighbor's BGP port\n"
5835 "TCP port number\n")
718e3744 5836{
d62a17ae 5837 int idx_ip = 2;
5838 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 5839}
5840
6b0655a2 5841
718e3744 5842/* neighbor weight. */
d62a17ae 5843static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5844 safi_t safi, const char *weight_str)
718e3744 5845{
d62a17ae 5846 int ret;
5847 struct peer *peer;
5848 unsigned long weight;
718e3744 5849
d62a17ae 5850 peer = peer_and_group_lookup_vty(vty, ip_str);
5851 if (!peer)
5852 return CMD_WARNING_CONFIG_FAILED;
718e3744 5853
d62a17ae 5854 weight = strtoul(weight_str, NULL, 10);
718e3744 5855
d62a17ae 5856 ret = peer_weight_set(peer, afi, safi, weight);
5857 return bgp_vty_return(vty, ret);
718e3744 5858}
5859
d62a17ae 5860static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5861 safi_t safi)
718e3744 5862{
d62a17ae 5863 int ret;
5864 struct peer *peer;
718e3744 5865
d62a17ae 5866 peer = peer_and_group_lookup_vty(vty, ip_str);
5867 if (!peer)
5868 return CMD_WARNING_CONFIG_FAILED;
718e3744 5869
d62a17ae 5870 ret = peer_weight_unset(peer, afi, safi);
5871 return bgp_vty_return(vty, ret);
718e3744 5872}
5873
5874DEFUN (neighbor_weight,
5875 neighbor_weight_cmd,
9ccf14f7 5876 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5877 NEIGHBOR_STR
5878 NEIGHBOR_ADDR_STR2
5879 "Set default weight for routes from this neighbor\n"
5880 "default weight\n")
5881{
d62a17ae 5882 int idx_peer = 1;
5883 int idx_number = 3;
5884 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5885 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5886}
5887
d62a17ae 5888ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5889 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5891 "Set default weight for routes from this neighbor\n"
5892 "default weight\n")
596c17ba 5893
718e3744 5894DEFUN (no_neighbor_weight,
5895 no_neighbor_weight_cmd,
9ccf14f7 5896 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5897 NO_STR
5898 NEIGHBOR_STR
5899 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5900 "Set default weight for routes from this neighbor\n"
5901 "default weight\n")
718e3744 5902{
d62a17ae 5903 int idx_peer = 2;
5904 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5905 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5906}
5907
d62a17ae 5908ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5909 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5910 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5911 "Set default weight for routes from this neighbor\n"
5912 "default weight\n")
596c17ba 5913
6b0655a2 5914
718e3744 5915/* Override capability negotiation. */
5916DEFUN (neighbor_override_capability,
5917 neighbor_override_capability_cmd,
9ccf14f7 5918 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5919 NEIGHBOR_STR
5920 NEIGHBOR_ADDR_STR2
5921 "Override capability negotiation result\n")
5922{
d62a17ae 5923 int idx_peer = 1;
5924 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5925 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5926}
5927
5928DEFUN (no_neighbor_override_capability,
5929 no_neighbor_override_capability_cmd,
9ccf14f7 5930 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5931 NO_STR
5932 NEIGHBOR_STR
5933 NEIGHBOR_ADDR_STR2
5934 "Override capability negotiation result\n")
5935{
d62a17ae 5936 int idx_peer = 2;
5937 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5938 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5939}
6b0655a2 5940
718e3744 5941DEFUN (neighbor_strict_capability,
5942 neighbor_strict_capability_cmd,
9fb964de 5943 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5944 NEIGHBOR_STR
9fb964de 5945 NEIGHBOR_ADDR_STR2
718e3744 5946 "Strict capability negotiation match\n")
5947{
9fb964de
PM
5948 int idx_peer = 1;
5949
5950 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5951 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5952}
5953
5954DEFUN (no_neighbor_strict_capability,
5955 no_neighbor_strict_capability_cmd,
9fb964de 5956 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5957 NO_STR
5958 NEIGHBOR_STR
9fb964de 5959 NEIGHBOR_ADDR_STR2
718e3744 5960 "Strict capability negotiation match\n")
5961{
9fb964de
PM
5962 int idx_peer = 2;
5963
5964 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5965 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5966}
6b0655a2 5967
d62a17ae 5968static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5969 const char *keep_str, const char *hold_str)
718e3744 5970{
d62a17ae 5971 int ret;
5972 struct peer *peer;
d7c0a89a
QY
5973 uint32_t keepalive;
5974 uint32_t holdtime;
718e3744 5975
d62a17ae 5976 peer = peer_and_group_lookup_vty(vty, ip_str);
5977 if (!peer)
5978 return CMD_WARNING_CONFIG_FAILED;
718e3744 5979
d62a17ae 5980 keepalive = strtoul(keep_str, NULL, 10);
5981 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5982
d62a17ae 5983 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5984
d62a17ae 5985 return bgp_vty_return(vty, ret);
718e3744 5986}
6b0655a2 5987
d62a17ae 5988static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5989{
d62a17ae 5990 int ret;
5991 struct peer *peer;
718e3744 5992
d62a17ae 5993 peer = peer_and_group_lookup_vty(vty, ip_str);
5994 if (!peer)
5995 return CMD_WARNING_CONFIG_FAILED;
718e3744 5996
d62a17ae 5997 ret = peer_timers_unset(peer);
718e3744 5998
d62a17ae 5999 return bgp_vty_return(vty, ret);
718e3744 6000}
6001
6002DEFUN (neighbor_timers,
6003 neighbor_timers_cmd,
9ccf14f7 6004 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
6007 "BGP per neighbor timers\n"
6008 "Keepalive interval\n"
6009 "Holdtime\n")
6010{
d62a17ae 6011 int idx_peer = 1;
6012 int idx_number = 3;
6013 int idx_number_2 = 4;
6014 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6015 argv[idx_number]->arg,
6016 argv[idx_number_2]->arg);
718e3744 6017}
6018
6019DEFUN (no_neighbor_timers,
6020 no_neighbor_timers_cmd,
9ccf14f7 6021 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 6022 NO_STR
6023 NEIGHBOR_STR
6024 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6025 "BGP per neighbor timers\n"
6026 "Keepalive interval\n"
6027 "Holdtime\n")
718e3744 6028{
d62a17ae 6029 int idx_peer = 2;
6030 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6031}
6b0655a2 6032
813d4307 6033
d62a17ae 6034static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6035 const char *time_str)
718e3744 6036{
d62a17ae 6037 int ret;
6038 struct peer *peer;
d7c0a89a 6039 uint32_t connect;
718e3744 6040
d62a17ae 6041 peer = peer_and_group_lookup_vty(vty, ip_str);
6042 if (!peer)
6043 return CMD_WARNING_CONFIG_FAILED;
718e3744 6044
d62a17ae 6045 connect = strtoul(time_str, NULL, 10);
718e3744 6046
d62a17ae 6047 ret = peer_timers_connect_set(peer, connect);
718e3744 6048
d62a17ae 6049 return bgp_vty_return(vty, ret);
718e3744 6050}
6051
d62a17ae 6052static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6053{
d62a17ae 6054 int ret;
6055 struct peer *peer;
718e3744 6056
d62a17ae 6057 peer = peer_and_group_lookup_vty(vty, ip_str);
6058 if (!peer)
6059 return CMD_WARNING_CONFIG_FAILED;
718e3744 6060
d62a17ae 6061 ret = peer_timers_connect_unset(peer);
718e3744 6062
d62a17ae 6063 return bgp_vty_return(vty, ret);
718e3744 6064}
6065
6066DEFUN (neighbor_timers_connect,
6067 neighbor_timers_connect_cmd,
9ccf14f7 6068 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 6069 NEIGHBOR_STR
966f821c 6070 NEIGHBOR_ADDR_STR2
718e3744 6071 "BGP per neighbor timers\n"
6072 "BGP connect timer\n"
6073 "Connect timer\n")
6074{
d62a17ae 6075 int idx_peer = 1;
6076 int idx_number = 4;
6077 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6078 argv[idx_number]->arg);
718e3744 6079}
6080
6081DEFUN (no_neighbor_timers_connect,
6082 no_neighbor_timers_connect_cmd,
9ccf14f7 6083 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 6084 NO_STR
6085 NEIGHBOR_STR
966f821c 6086 NEIGHBOR_ADDR_STR2
718e3744 6087 "BGP per neighbor timers\n"
8334fd5a
DW
6088 "BGP connect timer\n"
6089 "Connect timer\n")
718e3744 6090{
d62a17ae 6091 int idx_peer = 2;
6092 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6093}
6094
6b0655a2 6095
d62a17ae 6096static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6097 const char *time_str, int set)
718e3744 6098{
d62a17ae 6099 int ret;
6100 struct peer *peer;
d7c0a89a 6101 uint32_t routeadv = 0;
718e3744 6102
d62a17ae 6103 peer = peer_and_group_lookup_vty(vty, ip_str);
6104 if (!peer)
6105 return CMD_WARNING_CONFIG_FAILED;
718e3744 6106
d62a17ae 6107 if (time_str)
6108 routeadv = strtoul(time_str, NULL, 10);
718e3744 6109
d62a17ae 6110 if (set)
6111 ret = peer_advertise_interval_set(peer, routeadv);
6112 else
6113 ret = peer_advertise_interval_unset(peer);
718e3744 6114
d62a17ae 6115 return bgp_vty_return(vty, ret);
718e3744 6116}
6117
6118DEFUN (neighbor_advertise_interval,
6119 neighbor_advertise_interval_cmd,
9ccf14f7 6120 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 6121 NEIGHBOR_STR
966f821c 6122 NEIGHBOR_ADDR_STR2
718e3744 6123 "Minimum interval between sending BGP routing updates\n"
6124 "time in seconds\n")
6125{
d62a17ae 6126 int idx_peer = 1;
6127 int idx_number = 3;
6128 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6129 argv[idx_number]->arg, 1);
718e3744 6130}
6131
6132DEFUN (no_neighbor_advertise_interval,
6133 no_neighbor_advertise_interval_cmd,
9ccf14f7 6134 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 6135 NO_STR
6136 NEIGHBOR_STR
966f821c 6137 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6138 "Minimum interval between sending BGP routing updates\n"
6139 "time in seconds\n")
718e3744 6140{
d62a17ae 6141 int idx_peer = 2;
6142 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6143}
6144
6b0655a2 6145
518f0eb1
DS
6146/* Time to wait before processing route-map updates */
6147DEFUN (bgp_set_route_map_delay_timer,
6148 bgp_set_route_map_delay_timer_cmd,
6147e2c6 6149 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
6150 SET_STR
6151 "BGP route-map delay timer\n"
6152 "Time in secs to wait before processing route-map changes\n"
f414725f 6153 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6154{
d62a17ae 6155 int idx_number = 3;
d7c0a89a 6156 uint32_t rmap_delay_timer;
d62a17ae 6157
6158 if (argv[idx_number]->arg) {
6159 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6160 bm->rmap_update_timer = rmap_delay_timer;
6161
6162 /* if the dynamic update handling is being disabled, and a timer
6163 * is
6164 * running, stop the timer and act as if the timer has already
6165 * fired.
6166 */
6167 if (!rmap_delay_timer && bm->t_rmap_update) {
6168 BGP_TIMER_OFF(bm->t_rmap_update);
6169 thread_execute(bm->master, bgp_route_map_update_timer,
6170 NULL, 0);
6171 }
6172 return CMD_SUCCESS;
6173 } else {
6174 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6175 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 6176 }
518f0eb1
DS
6177}
6178
6179DEFUN (no_bgp_set_route_map_delay_timer,
6180 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 6181 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 6182 NO_STR
3a2d747c 6183 BGP_STR
518f0eb1 6184 "Default BGP route-map delay timer\n"
8334fd5a
DW
6185 "Reset to default time to wait for processing route-map changes\n"
6186 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6187{
518f0eb1 6188
d62a17ae 6189 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 6190
d62a17ae 6191 return CMD_SUCCESS;
518f0eb1
DS
6192}
6193
f414725f 6194
718e3744 6195/* neighbor interface */
d62a17ae 6196static int peer_interface_vty(struct vty *vty, const char *ip_str,
6197 const char *str)
718e3744 6198{
d62a17ae 6199 struct peer *peer;
718e3744 6200
d62a17ae 6201 peer = peer_lookup_vty(vty, ip_str);
6202 if (!peer || peer->conf_if) {
6203 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6204 return CMD_WARNING_CONFIG_FAILED;
6205 }
718e3744 6206
d62a17ae 6207 if (str)
6208 peer_interface_set(peer, str);
6209 else
6210 peer_interface_unset(peer);
718e3744 6211
d62a17ae 6212 return CMD_SUCCESS;
718e3744 6213}
6214
6215DEFUN (neighbor_interface,
6216 neighbor_interface_cmd,
9ccf14f7 6217 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 6218 NEIGHBOR_STR
6219 NEIGHBOR_ADDR_STR
6220 "Interface\n"
6221 "Interface name\n")
6222{
d62a17ae 6223 int idx_ip = 1;
6224 int idx_word = 3;
6225 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 6226}
6227
6228DEFUN (no_neighbor_interface,
6229 no_neighbor_interface_cmd,
9ccf14f7 6230 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 6231 NO_STR
6232 NEIGHBOR_STR
16cedbb0 6233 NEIGHBOR_ADDR_STR2
718e3744 6234 "Interface\n"
6235 "Interface name\n")
6236{
d62a17ae 6237 int idx_peer = 2;
6238 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6239}
6b0655a2 6240
718e3744 6241DEFUN (neighbor_distribute_list,
6242 neighbor_distribute_list_cmd,
9ccf14f7 6243 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6244 NEIGHBOR_STR
6245 NEIGHBOR_ADDR_STR2
6246 "Filter updates to/from this neighbor\n"
6247 "IP access-list number\n"
6248 "IP access-list number (expanded range)\n"
6249 "IP Access-list name\n"
6250 "Filter incoming updates\n"
6251 "Filter outgoing updates\n")
6252{
d62a17ae 6253 int idx_peer = 1;
6254 int idx_acl = 3;
6255 int direct, ret;
6256 struct peer *peer;
a8206004 6257
d62a17ae 6258 const char *pstr = argv[idx_peer]->arg;
6259 const char *acl = argv[idx_acl]->arg;
6260 const char *inout = argv[argc - 1]->text;
a8206004 6261
d62a17ae 6262 peer = peer_and_group_lookup_vty(vty, pstr);
6263 if (!peer)
6264 return CMD_WARNING_CONFIG_FAILED;
a8206004 6265
d62a17ae 6266 /* Check filter direction. */
6267 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6268 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6269 direct, acl);
a8206004 6270
d62a17ae 6271 return bgp_vty_return(vty, ret);
718e3744 6272}
6273
d62a17ae 6274ALIAS_HIDDEN(
6275 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6276 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6277 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6278 "Filter updates to/from this neighbor\n"
6279 "IP access-list number\n"
6280 "IP access-list number (expanded range)\n"
6281 "IP Access-list name\n"
6282 "Filter incoming updates\n"
6283 "Filter outgoing updates\n")
596c17ba 6284
718e3744 6285DEFUN (no_neighbor_distribute_list,
6286 no_neighbor_distribute_list_cmd,
9ccf14f7 6287 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6288 NO_STR
6289 NEIGHBOR_STR
6290 NEIGHBOR_ADDR_STR2
6291 "Filter updates to/from this neighbor\n"
6292 "IP access-list number\n"
6293 "IP access-list number (expanded range)\n"
6294 "IP Access-list name\n"
6295 "Filter incoming updates\n"
6296 "Filter outgoing updates\n")
6297{
d62a17ae 6298 int idx_peer = 2;
6299 int direct, ret;
6300 struct peer *peer;
a8206004 6301
d62a17ae 6302 const char *pstr = argv[idx_peer]->arg;
6303 const char *inout = argv[argc - 1]->text;
a8206004 6304
d62a17ae 6305 peer = peer_and_group_lookup_vty(vty, pstr);
6306 if (!peer)
6307 return CMD_WARNING_CONFIG_FAILED;
a8206004 6308
d62a17ae 6309 /* Check filter direction. */
6310 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6311 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6312 direct);
a8206004 6313
d62a17ae 6314 return bgp_vty_return(vty, ret);
718e3744 6315}
6b0655a2 6316
d62a17ae 6317ALIAS_HIDDEN(
6318 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6319 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6320 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6321 "Filter updates to/from this neighbor\n"
6322 "IP access-list number\n"
6323 "IP access-list number (expanded range)\n"
6324 "IP Access-list name\n"
6325 "Filter incoming updates\n"
6326 "Filter outgoing updates\n")
596c17ba 6327
718e3744 6328/* Set prefix list to the peer. */
d62a17ae 6329static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6330 afi_t afi, safi_t safi,
6331 const char *name_str,
6332 const char *direct_str)
718e3744 6333{
d62a17ae 6334 int ret;
d62a17ae 6335 int direct = FILTER_IN;
cf9ac8bf 6336 struct peer *peer;
718e3744 6337
d62a17ae 6338 peer = peer_and_group_lookup_vty(vty, ip_str);
6339 if (!peer)
6340 return CMD_WARNING_CONFIG_FAILED;
718e3744 6341
d62a17ae 6342 /* Check filter direction. */
6343 if (strncmp(direct_str, "i", 1) == 0)
6344 direct = FILTER_IN;
6345 else if (strncmp(direct_str, "o", 1) == 0)
6346 direct = FILTER_OUT;
718e3744 6347
d62a17ae 6348 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 6349
d62a17ae 6350 return bgp_vty_return(vty, ret);
718e3744 6351}
6352
d62a17ae 6353static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6354 afi_t afi, safi_t safi,
6355 const char *direct_str)
718e3744 6356{
d62a17ae 6357 int ret;
6358 struct peer *peer;
6359 int direct = FILTER_IN;
718e3744 6360
d62a17ae 6361 peer = peer_and_group_lookup_vty(vty, ip_str);
6362 if (!peer)
6363 return CMD_WARNING_CONFIG_FAILED;
e52702f2 6364
d62a17ae 6365 /* Check filter direction. */
6366 if (strncmp(direct_str, "i", 1) == 0)
6367 direct = FILTER_IN;
6368 else if (strncmp(direct_str, "o", 1) == 0)
6369 direct = FILTER_OUT;
718e3744 6370
d62a17ae 6371 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 6372
d62a17ae 6373 return bgp_vty_return(vty, ret);
718e3744 6374}
6375
6376DEFUN (neighbor_prefix_list,
6377 neighbor_prefix_list_cmd,
9ccf14f7 6378 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6379 NEIGHBOR_STR
6380 NEIGHBOR_ADDR_STR2
6381 "Filter updates to/from this neighbor\n"
6382 "Name of a prefix list\n"
6383 "Filter incoming updates\n"
6384 "Filter outgoing updates\n")
6385{
d62a17ae 6386 int idx_peer = 1;
6387 int idx_word = 3;
6388 int idx_in_out = 4;
6389 return peer_prefix_list_set_vty(
6390 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6391 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6392}
6393
d62a17ae 6394ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6395 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6396 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6397 "Filter updates to/from this neighbor\n"
6398 "Name of a prefix list\n"
6399 "Filter incoming updates\n"
6400 "Filter outgoing updates\n")
596c17ba 6401
718e3744 6402DEFUN (no_neighbor_prefix_list,
6403 no_neighbor_prefix_list_cmd,
9ccf14f7 6404 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6405 NO_STR
6406 NEIGHBOR_STR
6407 NEIGHBOR_ADDR_STR2
6408 "Filter updates to/from this neighbor\n"
6409 "Name of a prefix list\n"
6410 "Filter incoming updates\n"
6411 "Filter outgoing updates\n")
6412{
d62a17ae 6413 int idx_peer = 2;
6414 int idx_in_out = 5;
6415 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6416 bgp_node_afi(vty), bgp_node_safi(vty),
6417 argv[idx_in_out]->arg);
718e3744 6418}
6b0655a2 6419
d62a17ae 6420ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6421 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6422 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6423 "Filter updates to/from this neighbor\n"
6424 "Name of a prefix list\n"
6425 "Filter incoming updates\n"
6426 "Filter outgoing updates\n")
596c17ba 6427
d62a17ae 6428static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6429 safi_t safi, const char *name_str,
6430 const char *direct_str)
718e3744 6431{
d62a17ae 6432 int ret;
6433 struct peer *peer;
6434 int direct = FILTER_IN;
718e3744 6435
d62a17ae 6436 peer = peer_and_group_lookup_vty(vty, ip_str);
6437 if (!peer)
6438 return CMD_WARNING_CONFIG_FAILED;
718e3744 6439
d62a17ae 6440 /* Check filter direction. */
6441 if (strncmp(direct_str, "i", 1) == 0)
6442 direct = FILTER_IN;
6443 else if (strncmp(direct_str, "o", 1) == 0)
6444 direct = FILTER_OUT;
718e3744 6445
d62a17ae 6446 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 6447
d62a17ae 6448 return bgp_vty_return(vty, ret);
718e3744 6449}
6450
d62a17ae 6451static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6452 safi_t safi, const char *direct_str)
718e3744 6453{
d62a17ae 6454 int ret;
6455 struct peer *peer;
6456 int direct = FILTER_IN;
718e3744 6457
d62a17ae 6458 peer = peer_and_group_lookup_vty(vty, ip_str);
6459 if (!peer)
6460 return CMD_WARNING_CONFIG_FAILED;
718e3744 6461
d62a17ae 6462 /* Check filter direction. */
6463 if (strncmp(direct_str, "i", 1) == 0)
6464 direct = FILTER_IN;
6465 else if (strncmp(direct_str, "o", 1) == 0)
6466 direct = FILTER_OUT;
718e3744 6467
d62a17ae 6468 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 6469
d62a17ae 6470 return bgp_vty_return(vty, ret);
718e3744 6471}
6472
6473DEFUN (neighbor_filter_list,
6474 neighbor_filter_list_cmd,
9ccf14f7 6475 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6476 NEIGHBOR_STR
6477 NEIGHBOR_ADDR_STR2
6478 "Establish BGP filters\n"
6479 "AS path access-list name\n"
6480 "Filter incoming routes\n"
6481 "Filter outgoing routes\n")
6482{
d62a17ae 6483 int idx_peer = 1;
6484 int idx_word = 3;
6485 int idx_in_out = 4;
6486 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6487 bgp_node_safi(vty), argv[idx_word]->arg,
6488 argv[idx_in_out]->arg);
718e3744 6489}
6490
d62a17ae 6491ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
6492 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6493 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6494 "Establish BGP filters\n"
6495 "AS path access-list name\n"
6496 "Filter incoming routes\n"
6497 "Filter outgoing routes\n")
596c17ba 6498
718e3744 6499DEFUN (no_neighbor_filter_list,
6500 no_neighbor_filter_list_cmd,
9ccf14f7 6501 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6502 NO_STR
6503 NEIGHBOR_STR
6504 NEIGHBOR_ADDR_STR2
6505 "Establish BGP filters\n"
6506 "AS path access-list name\n"
6507 "Filter incoming routes\n"
6508 "Filter outgoing routes\n")
6509{
d62a17ae 6510 int idx_peer = 2;
6511 int idx_in_out = 5;
6512 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
6513 bgp_node_afi(vty), bgp_node_safi(vty),
6514 argv[idx_in_out]->arg);
718e3744 6515}
6b0655a2 6516
d62a17ae 6517ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
6518 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6519 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6520 "Establish BGP filters\n"
6521 "AS path access-list name\n"
6522 "Filter incoming routes\n"
6523 "Filter outgoing routes\n")
596c17ba 6524
718e3744 6525/* Set route-map to the peer. */
d62a17ae 6526static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
6527 afi_t afi, safi_t safi, const char *name_str,
6528 const char *direct_str)
718e3744 6529{
d62a17ae 6530 int ret;
6531 struct peer *peer;
6532 int direct = RMAP_IN;
1de27621 6533 struct route_map *route_map;
718e3744 6534
d62a17ae 6535 peer = peer_and_group_lookup_vty(vty, ip_str);
6536 if (!peer)
6537 return CMD_WARNING_CONFIG_FAILED;
718e3744 6538
d62a17ae 6539 /* Check filter direction. */
6540 if (strncmp(direct_str, "in", 2) == 0)
6541 direct = RMAP_IN;
6542 else if (strncmp(direct_str, "o", 1) == 0)
6543 direct = RMAP_OUT;
718e3744 6544
1de27621
DA
6545 route_map = route_map_lookup_warn_noexist(vty, name_str);
6546 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 6547
d62a17ae 6548 return bgp_vty_return(vty, ret);
718e3744 6549}
6550
d62a17ae 6551static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
6552 afi_t afi, safi_t safi,
6553 const char *direct_str)
718e3744 6554{
d62a17ae 6555 int ret;
6556 struct peer *peer;
6557 int direct = RMAP_IN;
718e3744 6558
d62a17ae 6559 peer = peer_and_group_lookup_vty(vty, ip_str);
6560 if (!peer)
6561 return CMD_WARNING_CONFIG_FAILED;
718e3744 6562
d62a17ae 6563 /* Check filter direction. */
6564 if (strncmp(direct_str, "in", 2) == 0)
6565 direct = RMAP_IN;
6566 else if (strncmp(direct_str, "o", 1) == 0)
6567 direct = RMAP_OUT;
718e3744 6568
d62a17ae 6569 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 6570
d62a17ae 6571 return bgp_vty_return(vty, ret);
718e3744 6572}
6573
6574DEFUN (neighbor_route_map,
6575 neighbor_route_map_cmd,
9ccf14f7 6576 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6577 NEIGHBOR_STR
6578 NEIGHBOR_ADDR_STR2
6579 "Apply route map to neighbor\n"
6580 "Name of route map\n"
6581 "Apply map to incoming routes\n"
2a3d5731 6582 "Apply map to outbound routes\n")
718e3744 6583{
d62a17ae 6584 int idx_peer = 1;
6585 int idx_word = 3;
6586 int idx_in_out = 4;
6587 return peer_route_map_set_vty(
6588 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6589 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6590}
6591
d62a17ae 6592ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
6593 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6594 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6595 "Apply route map to neighbor\n"
6596 "Name of route map\n"
6597 "Apply map to incoming routes\n"
6598 "Apply map to outbound routes\n")
596c17ba 6599
718e3744 6600DEFUN (no_neighbor_route_map,
6601 no_neighbor_route_map_cmd,
9ccf14f7 6602 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6603 NO_STR
6604 NEIGHBOR_STR
6605 NEIGHBOR_ADDR_STR2
6606 "Apply route map to neighbor\n"
6607 "Name of route map\n"
6608 "Apply map to incoming routes\n"
2a3d5731 6609 "Apply map to outbound routes\n")
718e3744 6610{
d62a17ae 6611 int idx_peer = 2;
6612 int idx_in_out = 5;
6613 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
6614 bgp_node_afi(vty), bgp_node_safi(vty),
6615 argv[idx_in_out]->arg);
718e3744 6616}
6b0655a2 6617
d62a17ae 6618ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
6619 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6620 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6621 "Apply route map to neighbor\n"
6622 "Name of route map\n"
6623 "Apply map to incoming routes\n"
6624 "Apply map to outbound routes\n")
596c17ba 6625
718e3744 6626/* Set unsuppress-map to the peer. */
d62a17ae 6627static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
6628 afi_t afi, safi_t safi,
6629 const char *name_str)
718e3744 6630{
d62a17ae 6631 int ret;
6632 struct peer *peer;
1de27621 6633 struct route_map *route_map;
718e3744 6634
d62a17ae 6635 peer = peer_and_group_lookup_vty(vty, ip_str);
6636 if (!peer)
6637 return CMD_WARNING_CONFIG_FAILED;
718e3744 6638
1de27621
DA
6639 route_map = route_map_lookup_warn_noexist(vty, name_str);
6640 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 6641
d62a17ae 6642 return bgp_vty_return(vty, ret);
718e3744 6643}
6644
6645/* Unset route-map from the peer. */
d62a17ae 6646static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
6647 afi_t afi, safi_t safi)
718e3744 6648{
d62a17ae 6649 int ret;
6650 struct peer *peer;
718e3744 6651
d62a17ae 6652 peer = peer_and_group_lookup_vty(vty, ip_str);
6653 if (!peer)
6654 return CMD_WARNING_CONFIG_FAILED;
718e3744 6655
d62a17ae 6656 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 6657
d62a17ae 6658 return bgp_vty_return(vty, ret);
718e3744 6659}
6660
6661DEFUN (neighbor_unsuppress_map,
6662 neighbor_unsuppress_map_cmd,
9ccf14f7 6663 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6664 NEIGHBOR_STR
6665 NEIGHBOR_ADDR_STR2
6666 "Route-map to selectively unsuppress suppressed routes\n"
6667 "Name of route map\n")
6668{
d62a17ae 6669 int idx_peer = 1;
6670 int idx_word = 3;
6671 return peer_unsuppress_map_set_vty(
6672 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6673 argv[idx_word]->arg);
718e3744 6674}
6675
d62a17ae 6676ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
6677 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6678 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6679 "Route-map to selectively unsuppress suppressed routes\n"
6680 "Name of route map\n")
596c17ba 6681
718e3744 6682DEFUN (no_neighbor_unsuppress_map,
6683 no_neighbor_unsuppress_map_cmd,
9ccf14f7 6684 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6685 NO_STR
6686 NEIGHBOR_STR
6687 NEIGHBOR_ADDR_STR2
6688 "Route-map to selectively unsuppress suppressed routes\n"
6689 "Name of route map\n")
6690{
d62a17ae 6691 int idx_peer = 2;
6692 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
6693 bgp_node_afi(vty),
6694 bgp_node_safi(vty));
718e3744 6695}
6b0655a2 6696
d62a17ae 6697ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
6698 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6699 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6700 "Route-map to selectively unsuppress suppressed routes\n"
6701 "Name of route map\n")
596c17ba 6702
d62a17ae 6703static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
6704 afi_t afi, safi_t safi,
6705 const char *num_str,
6706 const char *threshold_str, int warning,
9cbd06e0
DA
6707 const char *restart_str,
6708 const char *force_str)
718e3744 6709{
d62a17ae 6710 int ret;
6711 struct peer *peer;
d7c0a89a
QY
6712 uint32_t max;
6713 uint8_t threshold;
6714 uint16_t restart;
718e3744 6715
d62a17ae 6716 peer = peer_and_group_lookup_vty(vty, ip_str);
6717 if (!peer)
6718 return CMD_WARNING_CONFIG_FAILED;
718e3744 6719
d62a17ae 6720 max = strtoul(num_str, NULL, 10);
6721 if (threshold_str)
6722 threshold = atoi(threshold_str);
6723 else
6724 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 6725
d62a17ae 6726 if (restart_str)
6727 restart = atoi(restart_str);
6728 else
6729 restart = 0;
0a486e5f 6730
d62a17ae 6731 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
9cbd06e0 6732 restart, force_str ? true : false);
718e3744 6733
d62a17ae 6734 return bgp_vty_return(vty, ret);
718e3744 6735}
6736
d62a17ae 6737static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
6738 afi_t afi, safi_t safi)
718e3744 6739{
d62a17ae 6740 int ret;
6741 struct peer *peer;
718e3744 6742
d62a17ae 6743 peer = peer_and_group_lookup_vty(vty, ip_str);
6744 if (!peer)
6745 return CMD_WARNING_CONFIG_FAILED;
718e3744 6746
d62a17ae 6747 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 6748
d62a17ae 6749 return bgp_vty_return(vty, ret);
718e3744 6750}
6751
fde246e8
DA
6752/* Maximum number of prefix to be sent to the neighbor. */
6753DEFUN(neighbor_maximum_prefix_out,
6754 neighbor_maximum_prefix_out_cmd,
6755 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
6756 NEIGHBOR_STR
6757 NEIGHBOR_ADDR_STR2
6758 "Maximum number of prefixes to be sent to this peer\n"
6759 "Maximum no. of prefix limit\n")
6760{
6761 int idx_peer = 1;
6762 int idx_number = 3;
6763 struct peer *peer;
6764 uint32_t max;
6765 afi_t afi = bgp_node_afi(vty);
6766 safi_t safi = bgp_node_safi(vty);
6767
6768 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6769 if (!peer)
6770 return CMD_WARNING_CONFIG_FAILED;
6771
6772 max = strtoul(argv[idx_number]->arg, NULL, 10);
6773
6774 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
6775 peer->pmax_out[afi][safi] = max;
6776
6777 return CMD_SUCCESS;
6778}
6779
6780DEFUN(no_neighbor_maximum_prefix_out,
6781 no_neighbor_maximum_prefix_out_cmd,
6782 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
6783 NO_STR
6784 NEIGHBOR_STR
6785 NEIGHBOR_ADDR_STR2
6786 "Maximum number of prefixes to be sent to this peer\n")
6787{
6788 int idx_peer = 2;
6789 struct peer *peer;
6790 afi_t afi = bgp_node_afi(vty);
6791 safi_t safi = bgp_node_safi(vty);
6792
6793 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6794 if (!peer)
6795 return CMD_WARNING_CONFIG_FAILED;
6796
ae00326a 6797 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
fde246e8
DA
6798 peer->pmax_out[afi][safi] = 0;
6799
6800 return CMD_SUCCESS;
6801}
6802
9cbd06e0
DA
6803/* Maximum number of prefix configuration. Prefix count is different
6804 for each peer configuration. So this configuration can be set for
718e3744 6805 each peer configuration. */
6806DEFUN (neighbor_maximum_prefix,
6807 neighbor_maximum_prefix_cmd,
9cbd06e0 6808 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
718e3744 6809 NEIGHBOR_STR
6810 NEIGHBOR_ADDR_STR2
6811 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
6812 "maximum no. of prefix limit\n"
6813 "Force checking all received routes not only accepted\n")
718e3744 6814{
d62a17ae 6815 int idx_peer = 1;
6816 int idx_number = 3;
9cbd06e0
DA
6817 int idx_force = 0;
6818 char *force = NULL;
6819
6820 if (argv_find(argv, argc, "force", &idx_force))
6821 force = argv[idx_force]->arg;
6822
d62a17ae 6823 return peer_maximum_prefix_set_vty(
6824 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 6825 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 6826}
6827
d62a17ae 6828ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 6829 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 6830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6831 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
6832 "maximum no. of prefix limit\n"
6833 "Force checking all received routes not only accepted\n")
596c17ba 6834
e0701b79 6835DEFUN (neighbor_maximum_prefix_threshold,
6836 neighbor_maximum_prefix_threshold_cmd,
9cbd06e0 6837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
e0701b79 6838 NEIGHBOR_STR
6839 NEIGHBOR_ADDR_STR2
6840 "Maximum number of prefix accept from this peer\n"
6841 "maximum no. of prefix limit\n"
9cbd06e0
DA
6842 "Threshold value (%) at which to generate a warning msg\n"
6843 "Force checking all received routes not only accepted\n")
e0701b79 6844{
d62a17ae 6845 int idx_peer = 1;
6846 int idx_number = 3;
6847 int idx_number_2 = 4;
9cbd06e0
DA
6848 int idx_force = 0;
6849 char *force = NULL;
6850
6851 if (argv_find(argv, argc, "force", &idx_force))
6852 force = argv[idx_force]->arg;
6853
d62a17ae 6854 return peer_maximum_prefix_set_vty(
6855 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 6856 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 6857}
e0701b79 6858
d62a17ae 6859ALIAS_HIDDEN(
6860 neighbor_maximum_prefix_threshold,
6861 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 6862 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 6863 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6864 "Maximum number of prefix accept from this peer\n"
6865 "maximum no. of prefix limit\n"
9cbd06e0
DA
6866 "Threshold value (%) at which to generate a warning msg\n"
6867 "Force checking all received routes not only accepted\n")
596c17ba 6868
718e3744 6869DEFUN (neighbor_maximum_prefix_warning,
6870 neighbor_maximum_prefix_warning_cmd,
9cbd06e0 6871 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
718e3744 6872 NEIGHBOR_STR
6873 NEIGHBOR_ADDR_STR2
6874 "Maximum number of prefix accept from this peer\n"
6875 "maximum no. of prefix limit\n"
9cbd06e0
DA
6876 "Only give warning message when limit is exceeded\n"
6877 "Force checking all received routes not only accepted\n")
718e3744 6878{
d62a17ae 6879 int idx_peer = 1;
6880 int idx_number = 3;
9cbd06e0
DA
6881 int idx_force = 0;
6882 char *force = NULL;
6883
6884 if (argv_find(argv, argc, "force", &idx_force))
6885 force = argv[idx_force]->arg;
6886
d62a17ae 6887 return peer_maximum_prefix_set_vty(
6888 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 6889 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 6890}
6891
d62a17ae 6892ALIAS_HIDDEN(
6893 neighbor_maximum_prefix_warning,
6894 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 6895 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 6896 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6897 "Maximum number of prefix accept from this peer\n"
6898 "maximum no. of prefix limit\n"
9cbd06e0
DA
6899 "Only give warning message when limit is exceeded\n"
6900 "Force checking all received routes not only accepted\n")
596c17ba 6901
e0701b79 6902DEFUN (neighbor_maximum_prefix_threshold_warning,
6903 neighbor_maximum_prefix_threshold_warning_cmd,
9cbd06e0 6904 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
e0701b79 6905 NEIGHBOR_STR
6906 NEIGHBOR_ADDR_STR2
6907 "Maximum number of prefix accept from this peer\n"
6908 "maximum no. of prefix limit\n"
6909 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
6910 "Only give warning message when limit is exceeded\n"
6911 "Force checking all received routes not only accepted\n")
e0701b79 6912{
d62a17ae 6913 int idx_peer = 1;
6914 int idx_number = 3;
6915 int idx_number_2 = 4;
9cbd06e0
DA
6916 int idx_force = 0;
6917 char *force = NULL;
6918
6919 if (argv_find(argv, argc, "force", &idx_force))
6920 force = argv[idx_force]->arg;
6921
d62a17ae 6922 return peer_maximum_prefix_set_vty(
6923 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 6924 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 6925}
6926
d62a17ae 6927ALIAS_HIDDEN(
6928 neighbor_maximum_prefix_threshold_warning,
6929 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 6930 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 6931 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6932 "Maximum number of prefix accept from this peer\n"
6933 "maximum no. of prefix limit\n"
6934 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
6935 "Only give warning message when limit is exceeded\n"
6936 "Force checking all received routes not only accepted\n")
596c17ba 6937
0a486e5f 6938DEFUN (neighbor_maximum_prefix_restart,
6939 neighbor_maximum_prefix_restart_cmd,
9cbd06e0 6940 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
0a486e5f 6941 NEIGHBOR_STR
6942 NEIGHBOR_ADDR_STR2
6943 "Maximum number of prefix accept from this peer\n"
6944 "maximum no. of prefix limit\n"
6945 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
6946 "Restart interval in minutes\n"
6947 "Force checking all received routes not only accepted\n")
0a486e5f 6948{
d62a17ae 6949 int idx_peer = 1;
6950 int idx_number = 3;
6951 int idx_number_2 = 5;
9cbd06e0
DA
6952 int idx_force = 0;
6953 char *force = NULL;
6954
6955 if (argv_find(argv, argc, "force", &idx_force))
6956 force = argv[idx_force]->arg;
6957
d62a17ae 6958 return peer_maximum_prefix_set_vty(
6959 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 6960 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 6961}
6962
d62a17ae 6963ALIAS_HIDDEN(
6964 neighbor_maximum_prefix_restart,
6965 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 6966 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 6967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6968 "Maximum number of prefix accept from this peer\n"
6969 "maximum no. of prefix limit\n"
6970 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
6971 "Restart interval in minutes\n"
6972 "Force checking all received routes not only accepted\n")
596c17ba 6973
0a486e5f 6974DEFUN (neighbor_maximum_prefix_threshold_restart,
6975 neighbor_maximum_prefix_threshold_restart_cmd,
9cbd06e0 6976 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
0a486e5f 6977 NEIGHBOR_STR
6978 NEIGHBOR_ADDR_STR2
16cedbb0 6979 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6980 "maximum no. of prefix limit\n"
6981 "Threshold value (%) at which to generate a warning msg\n"
6982 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
6983 "Restart interval in minutes\n"
6984 "Force checking all received routes not only accepted\n")
0a486e5f 6985{
d62a17ae 6986 int idx_peer = 1;
6987 int idx_number = 3;
6988 int idx_number_2 = 4;
6989 int idx_number_3 = 6;
9cbd06e0
DA
6990 int idx_force = 0;
6991 char *force = NULL;
6992
6993 if (argv_find(argv, argc, "force", &idx_force))
6994 force = argv[idx_force]->arg;
6995
d62a17ae 6996 return peer_maximum_prefix_set_vty(
6997 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6998 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
9cbd06e0 6999 argv[idx_number_3]->arg, force);
d62a17ae 7000}
7001
7002ALIAS_HIDDEN(
7003 neighbor_maximum_prefix_threshold_restart,
7004 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7005 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7006 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7007 "Maximum number of prefixes to accept from this peer\n"
7008 "maximum no. of prefix limit\n"
7009 "Threshold value (%) at which to generate a warning msg\n"
7010 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7011 "Restart interval in minutes\n"
7012 "Force checking all received routes not only accepted\n")
596c17ba 7013
718e3744 7014DEFUN (no_neighbor_maximum_prefix,
7015 no_neighbor_maximum_prefix_cmd,
9cbd06e0 7016 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
718e3744 7017 NO_STR
7018 NEIGHBOR_STR
7019 NEIGHBOR_ADDR_STR2
16cedbb0 7020 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
7021 "maximum no. of prefix limit\n"
7022 "Threshold value (%) at which to generate a warning msg\n"
7023 "Restart bgp connection after limit is exceeded\n"
16cedbb0 7024 "Restart interval in minutes\n"
9cbd06e0
DA
7025 "Only give warning message when limit is exceeded\n"
7026 "Force checking all received routes not only accepted\n")
718e3744 7027{
d62a17ae 7028 int idx_peer = 2;
7029 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7030 bgp_node_afi(vty),
7031 bgp_node_safi(vty));
718e3744 7032}
e52702f2 7033
d62a17ae 7034ALIAS_HIDDEN(
7035 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7036 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7037 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7038 "Maximum number of prefixes to accept from this peer\n"
7039 "maximum no. of prefix limit\n"
7040 "Threshold value (%) at which to generate a warning msg\n"
7041 "Restart bgp connection after limit is exceeded\n"
7042 "Restart interval in minutes\n"
9cbd06e0
DA
7043 "Only give warning message when limit is exceeded\n"
7044 "Force checking all received routes not only accepted\n")
596c17ba 7045
718e3744 7046
718e3744 7047/* "neighbor allowas-in" */
7048DEFUN (neighbor_allowas_in,
7049 neighbor_allowas_in_cmd,
fd8503f5 7050 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7051 NEIGHBOR_STR
7052 NEIGHBOR_ADDR_STR2
31500417 7053 "Accept as-path with my AS present in it\n"
f79f7a7b 7054 "Number of occurrences of AS number\n"
fd8503f5 7055 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7056{
d62a17ae 7057 int idx_peer = 1;
7058 int idx_number_origin = 3;
7059 int ret;
7060 int origin = 0;
7061 struct peer *peer;
7062 int allow_num = 0;
7063
7064 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7065 if (!peer)
7066 return CMD_WARNING_CONFIG_FAILED;
7067
7068 if (argc <= idx_number_origin)
7069 allow_num = 3;
7070 else {
7071 if (argv[idx_number_origin]->type == WORD_TKN)
7072 origin = 1;
7073 else
7074 allow_num = atoi(argv[idx_number_origin]->arg);
7075 }
7076
7077 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7078 allow_num, origin);
7079
7080 return bgp_vty_return(vty, ret);
7081}
7082
7083ALIAS_HIDDEN(
7084 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7085 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7086 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7087 "Accept as-path with my AS present in it\n"
f79f7a7b 7088 "Number of occurrences of AS number\n"
d62a17ae 7089 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7090
718e3744 7091DEFUN (no_neighbor_allowas_in,
7092 no_neighbor_allowas_in_cmd,
fd8503f5 7093 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7094 NO_STR
7095 NEIGHBOR_STR
7096 NEIGHBOR_ADDR_STR2
8334fd5a 7097 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7098 "Number of occurrences of AS number\n"
fd8503f5 7099 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7100{
d62a17ae 7101 int idx_peer = 2;
7102 int ret;
7103 struct peer *peer;
718e3744 7104
d62a17ae 7105 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7106 if (!peer)
7107 return CMD_WARNING_CONFIG_FAILED;
718e3744 7108
d62a17ae 7109 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
7110 bgp_node_safi(vty));
718e3744 7111
d62a17ae 7112 return bgp_vty_return(vty, ret);
718e3744 7113}
6b0655a2 7114
d62a17ae 7115ALIAS_HIDDEN(
7116 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
7117 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7118 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7119 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7120 "Number of occurrences of AS number\n"
d62a17ae 7121 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7122
fa411a21
NH
7123DEFUN (neighbor_ttl_security,
7124 neighbor_ttl_security_cmd,
7ebe625c 7125 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 7126 NEIGHBOR_STR
7ebe625c 7127 NEIGHBOR_ADDR_STR2
16cedbb0 7128 "BGP ttl-security parameters\n"
d7fa34c1
QY
7129 "Specify the maximum number of hops to the BGP peer\n"
7130 "Number of hops to BGP peer\n")
fa411a21 7131{
d62a17ae 7132 int idx_peer = 1;
7133 int idx_number = 4;
7134 struct peer *peer;
7135 int gtsm_hops;
7136
7137 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7138 if (!peer)
7139 return CMD_WARNING_CONFIG_FAILED;
7140
7141 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
7142
7ebe625c
QY
7143 /*
7144 * If 'neighbor swpX', then this is for directly connected peers,
7145 * we should not accept a ttl-security hops value greater than 1.
7146 */
e2521429 7147 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7ebe625c
QY
7148 vty_out(vty,
7149 "%s is directly connected peer, hops cannot exceed 1\n",
7150 argv[idx_peer]->arg);
7151 return CMD_WARNING_CONFIG_FAILED;
7152 }
7153
d62a17ae 7154 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
7155}
7156
7157DEFUN (no_neighbor_ttl_security,
7158 no_neighbor_ttl_security_cmd,
7ebe625c 7159 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
7160 NO_STR
7161 NEIGHBOR_STR
7ebe625c 7162 NEIGHBOR_ADDR_STR2
16cedbb0 7163 "BGP ttl-security parameters\n"
3a2d747c
QY
7164 "Specify the maximum number of hops to the BGP peer\n"
7165 "Number of hops to BGP peer\n")
fa411a21 7166{
d62a17ae 7167 int idx_peer = 2;
7168 struct peer *peer;
fa411a21 7169
d62a17ae 7170 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7171 if (!peer)
7172 return CMD_WARNING_CONFIG_FAILED;
fa411a21 7173
d62a17ae 7174 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 7175}
6b0655a2 7176
adbac85e
DW
7177DEFUN (neighbor_addpath_tx_all_paths,
7178 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7179 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7180 NEIGHBOR_STR
7181 NEIGHBOR_ADDR_STR2
7182 "Use addpath to advertise all paths to a neighbor\n")
7183{
d62a17ae 7184 int idx_peer = 1;
7185 struct peer *peer;
adbac85e 7186
d62a17ae 7187 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7188 if (!peer)
7189 return CMD_WARNING_CONFIG_FAILED;
adbac85e 7190
dcc68b5e
MS
7191 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7192 BGP_ADDPATH_ALL);
7193 return CMD_SUCCESS;
adbac85e
DW
7194}
7195
d62a17ae 7196ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
7197 neighbor_addpath_tx_all_paths_hidden_cmd,
7198 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7199 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7200 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7201
adbac85e
DW
7202DEFUN (no_neighbor_addpath_tx_all_paths,
7203 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7204 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7205 NO_STR
7206 NEIGHBOR_STR
7207 NEIGHBOR_ADDR_STR2
7208 "Use addpath to advertise all paths to a neighbor\n")
7209{
d62a17ae 7210 int idx_peer = 2;
dcc68b5e
MS
7211 struct peer *peer;
7212
7213 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7214 if (!peer)
7215 return CMD_WARNING_CONFIG_FAILED;
7216
7217 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7218 != BGP_ADDPATH_ALL) {
7219 vty_out(vty,
7220 "%% Peer not currently configured to transmit all paths.");
7221 return CMD_WARNING_CONFIG_FAILED;
7222 }
7223
7224 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7225 BGP_ADDPATH_NONE);
7226
7227 return CMD_SUCCESS;
adbac85e
DW
7228}
7229
d62a17ae 7230ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7231 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7232 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7233 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7234 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7235
06370dac
DW
7236DEFUN (neighbor_addpath_tx_bestpath_per_as,
7237 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7238 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7239 NEIGHBOR_STR
7240 NEIGHBOR_ADDR_STR2
7241 "Use addpath to advertise the bestpath per each neighboring AS\n")
7242{
d62a17ae 7243 int idx_peer = 1;
7244 struct peer *peer;
06370dac 7245
d62a17ae 7246 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7247 if (!peer)
7248 return CMD_WARNING_CONFIG_FAILED;
06370dac 7249
dcc68b5e
MS
7250 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7251 BGP_ADDPATH_BEST_PER_AS);
7252
7253 return CMD_SUCCESS;
06370dac
DW
7254}
7255
d62a17ae 7256ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7257 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7258 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7259 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7260 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7261
06370dac
DW
7262DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7263 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7264 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7265 NO_STR
7266 NEIGHBOR_STR
7267 NEIGHBOR_ADDR_STR2
7268 "Use addpath to advertise the bestpath per each neighboring AS\n")
7269{
d62a17ae 7270 int idx_peer = 2;
dcc68b5e
MS
7271 struct peer *peer;
7272
7273 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7274 if (!peer)
7275 return CMD_WARNING_CONFIG_FAILED;
7276
7277 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7278 != BGP_ADDPATH_BEST_PER_AS) {
7279 vty_out(vty,
7280 "%% Peer not currently configured to transmit all best path per as.");
7281 return CMD_WARNING_CONFIG_FAILED;
7282 }
7283
7284 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7285 BGP_ADDPATH_NONE);
7286
7287 return CMD_SUCCESS;
06370dac
DW
7288}
7289
d62a17ae 7290ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7291 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7292 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7293 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7294 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7295
2b31007c
RZ
7296DEFPY(
7297 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7298 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7299 NEIGHBOR_STR
7300 NEIGHBOR_ADDR_STR2
7301 "Detect AS loops before sending to neighbor\n")
7302{
7303 struct peer *peer;
7304
7305 peer = peer_and_group_lookup_vty(vty, neighbor);
7306 if (!peer)
7307 return CMD_WARNING_CONFIG_FAILED;
7308
7309 peer->as_path_loop_detection = true;
7310
7311 return CMD_SUCCESS;
7312}
7313
7314DEFPY(
7315 no_neighbor_aspath_loop_detection,
7316 no_neighbor_aspath_loop_detection_cmd,
7317 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7318 NO_STR
7319 NEIGHBOR_STR
7320 NEIGHBOR_ADDR_STR2
7321 "Detect AS loops before sending to neighbor\n")
7322{
7323 struct peer *peer;
7324
7325 peer = peer_and_group_lookup_vty(vty, neighbor);
7326 if (!peer)
7327 return CMD_WARNING_CONFIG_FAILED;
7328
7329 peer->as_path_loop_detection = false;
7330
7331 return CMD_SUCCESS;
7332}
7333
b9c7bc5a 7334static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
9a659715 7335 struct ecommunity **list, int is_rt6)
ddb5b488 7336{
b9c7bc5a
PZ
7337 struct ecommunity *ecom = NULL;
7338 struct ecommunity *ecomadd;
ddb5b488 7339
b9c7bc5a 7340 for (; argc; --argc, ++argv) {
9a659715
PG
7341 if (is_rt6)
7342 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
7343 ECOMMUNITY_ROUTE_TARGET,
7344 0);
7345 else
7346 ecomadd = ecommunity_str2com(argv[0]->arg,
7347 ECOMMUNITY_ROUTE_TARGET,
7348 0);
b9c7bc5a
PZ
7349 if (!ecomadd) {
7350 vty_out(vty, "Malformed community-list value\n");
7351 if (ecom)
7352 ecommunity_free(&ecom);
7353 return CMD_WARNING_CONFIG_FAILED;
7354 }
ddb5b488 7355
b9c7bc5a
PZ
7356 if (ecom) {
7357 ecommunity_merge(ecom, ecomadd);
7358 ecommunity_free(&ecomadd);
7359 } else {
7360 ecom = ecomadd;
7361 }
7362 }
7363
7364 if (*list) {
7365 ecommunity_free(&*list);
ddb5b488 7366 }
b9c7bc5a
PZ
7367 *list = ecom;
7368
7369 return CMD_SUCCESS;
ddb5b488
PZ
7370}
7371
0ca70ba5
DS
7372/*
7373 * v2vimport is true if we are handling a `import vrf ...` command
7374 */
7375static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 7376{
0ca70ba5
DS
7377 afi_t afi;
7378
ddb5b488 7379 switch (vty->node) {
b9c7bc5a 7380 case BGP_IPV4_NODE:
0ca70ba5
DS
7381 afi = AFI_IP;
7382 break;
b9c7bc5a 7383 case BGP_IPV6_NODE:
0ca70ba5
DS
7384 afi = AFI_IP6;
7385 break;
ddb5b488
PZ
7386 default:
7387 vty_out(vty,
b9c7bc5a 7388 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 7389 return AFI_MAX;
ddb5b488 7390 }
69b07479 7391
0ca70ba5
DS
7392 if (!v2vimport) {
7393 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7394 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7395 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7396 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7397 vty_out(vty,
7398 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7399 return AFI_MAX;
7400 }
7401 } else {
7402 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7403 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7404 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7405 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7406 vty_out(vty,
7407 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7408 return AFI_MAX;
7409 }
7410 }
7411 return afi;
ddb5b488
PZ
7412}
7413
b9c7bc5a
PZ
7414DEFPY (af_rd_vpn_export,
7415 af_rd_vpn_export_cmd,
7416 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7417 NO_STR
ddb5b488 7418 "Specify route distinguisher\n"
b9c7bc5a
PZ
7419 "Between current address-family and vpn\n"
7420 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7421 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7422{
7423 VTY_DECLVAR_CONTEXT(bgp, bgp);
7424 struct prefix_rd prd;
7425 int ret;
ddb5b488 7426 afi_t afi;
b9c7bc5a
PZ
7427 int idx = 0;
7428 int yes = 1;
ddb5b488 7429
b9c7bc5a 7430 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7431 yes = 0;
b9c7bc5a
PZ
7432
7433 if (yes) {
7434 ret = str2prefix_rd(rd_str, &prd);
7435 if (!ret) {
7436 vty_out(vty, "%% Malformed rd\n");
7437 return CMD_WARNING_CONFIG_FAILED;
7438 }
ddb5b488
PZ
7439 }
7440
0ca70ba5 7441 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7442 if (afi == AFI_MAX)
7443 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7444
69b07479
DS
7445 /*
7446 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7447 */
7448 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7449 bgp_get_default(), bgp);
ddb5b488 7450
69b07479
DS
7451 if (yes) {
7452 bgp->vpn_policy[afi].tovpn_rd = prd;
7453 SET_FLAG(bgp->vpn_policy[afi].flags,
7454 BGP_VPN_POLICY_TOVPN_RD_SET);
7455 } else {
7456 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7457 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
7458 }
7459
69b07479
DS
7460 /* post-change: re-export vpn routes */
7461 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7462 bgp_get_default(), bgp);
7463
ddb5b488
PZ
7464 return CMD_SUCCESS;
7465}
7466
b9c7bc5a
PZ
7467ALIAS (af_rd_vpn_export,
7468 af_no_rd_vpn_export_cmd,
7469 "no rd vpn export",
ddb5b488 7470 NO_STR
b9c7bc5a
PZ
7471 "Specify route distinguisher\n"
7472 "Between current address-family and vpn\n"
7473 "For routes leaked from current address-family to vpn\n")
ddb5b488 7474
b9c7bc5a
PZ
7475DEFPY (af_label_vpn_export,
7476 af_label_vpn_export_cmd,
e70e9f8e 7477 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 7478 NO_STR
ddb5b488 7479 "label value for VRF\n"
b9c7bc5a
PZ
7480 "Between current address-family and vpn\n"
7481 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
7482 "Label Value <0-1048575>\n"
7483 "Automatically assign a label\n")
ddb5b488
PZ
7484{
7485 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7486 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 7487 afi_t afi;
b9c7bc5a
PZ
7488 int idx = 0;
7489 int yes = 1;
7490
7491 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7492 yes = 0;
ddb5b488 7493
21a16cc2
PZ
7494 /* If "no ...", squash trailing parameter */
7495 if (!yes)
7496 label_auto = NULL;
7497
e70e9f8e
PZ
7498 if (yes) {
7499 if (!label_auto)
7500 label = label_val; /* parser should force unsigned */
7501 }
ddb5b488 7502
0ca70ba5 7503 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7504 if (afi == AFI_MAX)
7505 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 7506
e70e9f8e 7507
69b07479
DS
7508 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7509 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
7510 /* no change */
7511 return CMD_SUCCESS;
e70e9f8e 7512
69b07479
DS
7513 /*
7514 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7515 */
7516 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7517 bgp_get_default(), bgp);
7518
7519 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7520 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
7521
7522 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
7523
7524 /*
7525 * label has previously been automatically
7526 * assigned by labelpool: release it
7527 *
7528 * NB if tovpn_label == MPLS_LABEL_NONE it
7529 * means the automatic assignment is in flight
7530 * and therefore the labelpool callback must
7531 * detect that the auto label is not needed.
7532 */
7533
7534 bgp_lp_release(LP_TYPE_VRF,
7535 &bgp->vpn_policy[afi],
7536 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 7537 }
69b07479
DS
7538 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7539 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7540 }
ddb5b488 7541
69b07479
DS
7542 bgp->vpn_policy[afi].tovpn_label = label;
7543 if (label_auto) {
7544 SET_FLAG(bgp->vpn_policy[afi].flags,
7545 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7546 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
7547 vpn_leak_label_callback);
ddb5b488
PZ
7548 }
7549
69b07479
DS
7550 /* post-change: re-export vpn routes */
7551 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7552 bgp_get_default(), bgp);
7553
ddb5b488
PZ
7554 return CMD_SUCCESS;
7555}
7556
b9c7bc5a
PZ
7557ALIAS (af_label_vpn_export,
7558 af_no_label_vpn_export_cmd,
7559 "no label vpn export",
7560 NO_STR
7561 "label value for VRF\n"
7562 "Between current address-family and vpn\n"
7563 "For routes leaked from current address-family to vpn\n")
ddb5b488 7564
b9c7bc5a
PZ
7565DEFPY (af_nexthop_vpn_export,
7566 af_nexthop_vpn_export_cmd,
8c85ca28 7567 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 7568 NO_STR
ddb5b488 7569 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
7570 "Between current address-family and vpn\n"
7571 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7572 "IPv4 prefix\n"
7573 "IPv6 prefix\n")
7574{
7575 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 7576 afi_t afi;
ddb5b488
PZ
7577 struct prefix p;
7578
8c85ca28
QY
7579 if (!no) {
7580 if (!nexthop_su) {
7581 vty_out(vty, "%% Nexthop required\n");
7582 return CMD_WARNING_CONFIG_FAILED;
7583 }
b9c7bc5a 7584
8c85ca28 7585 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
7586 return CMD_WARNING_CONFIG_FAILED;
7587 }
ddb5b488 7588
0ca70ba5 7589 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7590 if (afi == AFI_MAX)
7591 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7592
69b07479
DS
7593 /*
7594 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7595 */
7596 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7597 bgp_get_default(), bgp);
ddb5b488 7598
8c85ca28 7599 if (!no) {
69b07479
DS
7600 bgp->vpn_policy[afi].tovpn_nexthop = p;
7601 SET_FLAG(bgp->vpn_policy[afi].flags,
7602 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7603 } else {
7604 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7605 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
7606 }
7607
69b07479
DS
7608 /* post-change: re-export vpn routes */
7609 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7610 bgp_get_default(), bgp);
7611
ddb5b488
PZ
7612 return CMD_SUCCESS;
7613}
7614
b9c7bc5a 7615static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 7616{
b9c7bc5a
PZ
7617 if (!strcmp(dstr, "import")) {
7618 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7619 } else if (!strcmp(dstr, "export")) {
7620 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7621 } else if (!strcmp(dstr, "both")) {
7622 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7623 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7624 } else {
7625 vty_out(vty, "%% direction parse error\n");
7626 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7627 }
ddb5b488
PZ
7628 return CMD_SUCCESS;
7629}
7630
b9c7bc5a
PZ
7631DEFPY (af_rt_vpn_imexport,
7632 af_rt_vpn_imexport_cmd,
7633 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
7634 NO_STR
7635 "Specify route target list\n"
ddb5b488 7636 "Specify route target list\n"
b9c7bc5a
PZ
7637 "Between current address-family and vpn\n"
7638 "For routes leaked from vpn to current address-family: match any\n"
7639 "For routes leaked from current address-family to vpn: set\n"
7640 "both import: match any and export: set\n"
ddb5b488
PZ
7641 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7642{
7643 VTY_DECLVAR_CONTEXT(bgp, bgp);
7644 int ret;
7645 struct ecommunity *ecom = NULL;
7646 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7647 vpn_policy_direction_t dir;
7648 afi_t afi;
7649 int idx = 0;
b9c7bc5a 7650 int yes = 1;
ddb5b488 7651
b9c7bc5a 7652 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7653 yes = 0;
b9c7bc5a 7654
0ca70ba5 7655 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7656 if (afi == AFI_MAX)
7657 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7658
b9c7bc5a 7659 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7660 if (ret != CMD_SUCCESS)
7661 return ret;
7662
b9c7bc5a
PZ
7663 if (yes) {
7664 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7665 vty_out(vty, "%% Missing RTLIST\n");
7666 return CMD_WARNING_CONFIG_FAILED;
7667 }
9a659715 7668 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, 0);
b9c7bc5a
PZ
7669 if (ret != CMD_SUCCESS) {
7670 return ret;
7671 }
ddb5b488
PZ
7672 }
7673
69b07479
DS
7674 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7675 if (!dodir[dir])
ddb5b488 7676 continue;
ddb5b488 7677
69b07479 7678 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7679
69b07479
DS
7680 if (yes) {
7681 if (bgp->vpn_policy[afi].rtlist[dir])
7682 ecommunity_free(
7683 &bgp->vpn_policy[afi].rtlist[dir]);
7684 bgp->vpn_policy[afi].rtlist[dir] =
7685 ecommunity_dup(ecom);
7686 } else {
7687 if (bgp->vpn_policy[afi].rtlist[dir])
7688 ecommunity_free(
7689 &bgp->vpn_policy[afi].rtlist[dir]);
7690 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 7691 }
69b07479
DS
7692
7693 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7694 }
69b07479 7695
d555f3e9
PZ
7696 if (ecom)
7697 ecommunity_free(&ecom);
ddb5b488
PZ
7698
7699 return CMD_SUCCESS;
7700}
7701
b9c7bc5a
PZ
7702ALIAS (af_rt_vpn_imexport,
7703 af_no_rt_vpn_imexport_cmd,
7704 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
7705 NO_STR
7706 "Specify route target list\n"
b9c7bc5a
PZ
7707 "Specify route target list\n"
7708 "Between current address-family and vpn\n"
7709 "For routes leaked from vpn to current address-family\n"
7710 "For routes leaked from current address-family to vpn\n"
7711 "both import and export\n")
7712
7713DEFPY (af_route_map_vpn_imexport,
7714 af_route_map_vpn_imexport_cmd,
7715/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
7716 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
7717 NO_STR
ddb5b488 7718 "Specify route map\n"
b9c7bc5a
PZ
7719 "Between current address-family and vpn\n"
7720 "For routes leaked from vpn to current address-family\n"
7721 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7722 "name of route-map\n")
7723{
7724 VTY_DECLVAR_CONTEXT(bgp, bgp);
7725 int ret;
7726 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7727 vpn_policy_direction_t dir;
7728 afi_t afi;
ddb5b488 7729 int idx = 0;
b9c7bc5a 7730 int yes = 1;
ddb5b488 7731
b9c7bc5a 7732 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7733 yes = 0;
b9c7bc5a 7734
0ca70ba5 7735 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7736 if (afi == AFI_MAX)
7737 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7738
b9c7bc5a 7739 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7740 if (ret != CMD_SUCCESS)
7741 return ret;
7742
69b07479
DS
7743 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7744 if (!dodir[dir])
ddb5b488 7745 continue;
ddb5b488 7746
69b07479 7747 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7748
69b07479
DS
7749 if (yes) {
7750 if (bgp->vpn_policy[afi].rmap_name[dir])
7751 XFREE(MTYPE_ROUTE_MAP_NAME,
7752 bgp->vpn_policy[afi].rmap_name[dir]);
7753 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
7754 MTYPE_ROUTE_MAP_NAME, rmap_str);
7755 bgp->vpn_policy[afi].rmap[dir] =
1de27621 7756 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
7757 if (!bgp->vpn_policy[afi].rmap[dir])
7758 return CMD_SUCCESS;
7759 } else {
7760 if (bgp->vpn_policy[afi].rmap_name[dir])
7761 XFREE(MTYPE_ROUTE_MAP_NAME,
7762 bgp->vpn_policy[afi].rmap_name[dir]);
7763 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7764 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 7765 }
69b07479
DS
7766
7767 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
7768 }
7769
7770 return CMD_SUCCESS;
7771}
7772
b9c7bc5a
PZ
7773ALIAS (af_route_map_vpn_imexport,
7774 af_no_route_map_vpn_imexport_cmd,
7775 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
7776 NO_STR
7777 "Specify route map\n"
b9c7bc5a
PZ
7778 "Between current address-family and vpn\n"
7779 "For routes leaked from vpn to current address-family\n"
7780 "For routes leaked from current address-family to vpn\n")
7781
bb4f6190 7782DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 7783 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
7784 "Import routes from another VRF\n"
7785 "Vrf routes being filtered\n"
7786 "Specify route map\n"
7787 "name of route-map\n")
7788{
7789 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
7790 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7791 afi_t afi;
bb4f6190
DS
7792 struct bgp *bgp_default;
7793
0ca70ba5 7794 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
7795 if (afi == AFI_MAX)
7796 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
7797
7798 bgp_default = bgp_get_default();
7799 if (!bgp_default) {
7800 int32_t ret;
7801 as_t as = bgp->as;
7802
7803 /* Auto-create assuming the same AS */
5d5393b9
DL
7804 ret = bgp_get_vty(&bgp_default, &as, NULL,
7805 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
7806
7807 if (ret) {
7808 vty_out(vty,
7809 "VRF default is not configured as a bgp instance\n");
7810 return CMD_WARNING;
7811 }
7812 }
7813
69b07479 7814 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 7815
ae6a6fb4
DS
7816 if (bgp->vpn_policy[afi].rmap_name[dir])
7817 XFREE(MTYPE_ROUTE_MAP_NAME,
7818 bgp->vpn_policy[afi].rmap_name[dir]);
7819 bgp->vpn_policy[afi].rmap_name[dir] =
7820 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
7821 bgp->vpn_policy[afi].rmap[dir] =
7822 route_map_lookup_warn_noexist(vty, rmap_str);
7823 if (!bgp->vpn_policy[afi].rmap[dir])
7824 return CMD_SUCCESS;
7825
7826 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7827 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 7828
69b07479
DS
7829 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7830
bb4f6190
DS
7831 return CMD_SUCCESS;
7832}
7833
ae6a6fb4
DS
7834DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
7835 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
7836 NO_STR
7837 "Import routes from another VRF\n"
7838 "Vrf routes being filtered\n"
ae6a6fb4
DS
7839 "Specify route map\n"
7840 "name of route-map\n")
7841{
7842 VTY_DECLVAR_CONTEXT(bgp, bgp);
7843 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7844 afi_t afi;
7845
7846 afi = vpn_policy_getafi(vty, bgp, true);
7847 if (afi == AFI_MAX)
7848 return CMD_WARNING_CONFIG_FAILED;
7849
7850 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7851
7852 if (bgp->vpn_policy[afi].rmap_name[dir])
7853 XFREE(MTYPE_ROUTE_MAP_NAME,
7854 bgp->vpn_policy[afi].rmap_name[dir]);
7855 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7856 bgp->vpn_policy[afi].rmap[dir] = NULL;
7857
7858 if (bgp->vpn_policy[afi].import_vrf->count == 0)
7859 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7860 BGP_CONFIG_VRF_TO_VRF_IMPORT);
7861
7862 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7863
7864 return CMD_SUCCESS;
7865}
bb4f6190 7866
4d1b335c
DA
7867DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7868 "[no] import vrf VIEWVRFNAME$import_name",
7869 NO_STR
7870 "Import routes from another VRF\n"
7871 "VRF to import from\n"
7872 "The name of the VRF\n")
12a844a5
DS
7873{
7874 VTY_DECLVAR_CONTEXT(bgp, bgp);
7875 struct listnode *node;
79ef8664
DS
7876 struct bgp *vrf_bgp, *bgp_default;
7877 int32_t ret = 0;
7878 as_t as = bgp->as;
12a844a5
DS
7879 bool remove = false;
7880 int32_t idx = 0;
7881 char *vname;
a8dadcf6 7882 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
7883 safi_t safi;
7884 afi_t afi;
7885
867f0cca 7886 if (import_name == NULL) {
7887 vty_out(vty, "%% Missing import name\n");
7888 return CMD_WARNING;
7889 }
7890
ae6a6fb4
DS
7891 if (strcmp(import_name, "route-map") == 0) {
7892 vty_out(vty, "%% Must include route-map name\n");
7893 return CMD_WARNING;
7894 }
7895
12a844a5
DS
7896 if (argv_find(argv, argc, "no", &idx))
7897 remove = true;
7898
0ca70ba5
DS
7899 afi = vpn_policy_getafi(vty, bgp, true);
7900 if (afi == AFI_MAX)
7901 return CMD_WARNING_CONFIG_FAILED;
7902
12a844a5
DS
7903 safi = bgp_node_safi(vty);
7904
25679caa 7905 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 7906 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
7907 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7908 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7909 remove ? "unimport" : "import", import_name);
7910 return CMD_WARNING;
7911 }
7912
79ef8664
DS
7913 bgp_default = bgp_get_default();
7914 if (!bgp_default) {
7915 /* Auto-create assuming the same AS */
5d5393b9
DL
7916 ret = bgp_get_vty(&bgp_default, &as, NULL,
7917 BGP_INSTANCE_TYPE_DEFAULT);
79ef8664
DS
7918
7919 if (ret) {
7920 vty_out(vty,
7921 "VRF default is not configured as a bgp instance\n");
7922 return CMD_WARNING;
7923 }
7924 }
7925
12a844a5
DS
7926 vrf_bgp = bgp_lookup_by_name(import_name);
7927 if (!vrf_bgp) {
5742e42b 7928 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
7929 vrf_bgp = bgp_default;
7930 else
0fb8d6e6 7931 /* Auto-create assuming the same AS */
5d5393b9 7932 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 7933
6e2c7fe6 7934 if (ret) {
020a3f60
DS
7935 vty_out(vty,
7936 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
7937 import_name);
7938 return CMD_WARNING;
7939 }
12a844a5
DS
7940 }
7941
12a844a5 7942 if (remove) {
44338987 7943 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 7944 } else {
44338987 7945 /* Already importing from "import_vrf"? */
12a844a5
DS
7946 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7947 vname)) {
7948 if (strcmp(vname, import_name) == 0)
7949 return CMD_WARNING;
7950 }
7951
44338987 7952 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
7953 }
7954
7955 return CMD_SUCCESS;
7956}
7957
b9c7bc5a
PZ
7958/* This command is valid only in a bgp vrf instance or the default instance */
7959DEFPY (bgp_imexport_vpn,
7960 bgp_imexport_vpn_cmd,
7961 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
7962 NO_STR
7963 "Import routes to this address-family\n"
7964 "Export routes from this address-family\n"
7965 "to/from default instance VPN RIB\n")
ddb5b488
PZ
7966{
7967 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7968 int previous_state;
ddb5b488 7969 afi_t afi;
b9c7bc5a 7970 safi_t safi;
ddb5b488 7971 int idx = 0;
b9c7bc5a
PZ
7972 int yes = 1;
7973 int flag;
7974 vpn_policy_direction_t dir;
ddb5b488 7975
b9c7bc5a 7976 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7977 yes = 0;
ddb5b488 7978
b9c7bc5a
PZ
7979 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7980 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7981
b9c7bc5a
PZ
7982 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7983 return CMD_WARNING_CONFIG_FAILED;
7984 }
ddb5b488 7985
b9c7bc5a
PZ
7986 afi = bgp_node_afi(vty);
7987 safi = bgp_node_safi(vty);
7988 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7989 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7990 return CMD_WARNING_CONFIG_FAILED;
7991 }
ddb5b488 7992
b9c7bc5a
PZ
7993 if (!strcmp(direction_str, "import")) {
7994 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7995 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7996 } else if (!strcmp(direction_str, "export")) {
7997 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7998 dir = BGP_VPN_POLICY_DIR_TOVPN;
7999 } else {
8000 vty_out(vty, "%% unknown direction %s\n", direction_str);
8001 return CMD_WARNING_CONFIG_FAILED;
8002 }
8003
8004 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 8005
b9c7bc5a
PZ
8006 if (yes) {
8007 SET_FLAG(bgp->af_flags[afi][safi], flag);
8008 if (!previous_state) {
8009 /* trigger export current vrf */
ddb5b488
PZ
8010 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8011 }
b9c7bc5a
PZ
8012 } else {
8013 if (previous_state) {
8014 /* trigger un-export current vrf */
8015 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8016 }
8017 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
8018 }
8019
8020 return CMD_SUCCESS;
8021}
8022
301ad80a
PG
8023DEFPY (af_routetarget_import,
8024 af_routetarget_import_cmd,
9a659715 8025 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
8026 NO_STR
8027 "Specify route target list\n"
8028 "Specify route target list\n"
9a659715
PG
8029 "Specify route target list\n"
8030 "Specify route target list\n"
301ad80a
PG
8031 "Flow-spec redirect type route target\n"
8032 "Import routes to this address-family\n"
9a659715 8033 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
8034{
8035 VTY_DECLVAR_CONTEXT(bgp, bgp);
8036 int ret;
8037 struct ecommunity *ecom = NULL;
301ad80a 8038 afi_t afi;
9a659715 8039 int idx = 0, idx_unused = 0;
301ad80a 8040 int yes = 1;
9a659715 8041 int rt6 = 0;
301ad80a
PG
8042
8043 if (argv_find(argv, argc, "no", &idx))
8044 yes = 0;
8045
9a659715
PG
8046 if (argv_find(argv, argc, "rt6", &idx_unused) ||
8047 argv_find(argv, argc, "route-target6", &idx_unused))
8048 rt6 = 1;
8049
0ca70ba5 8050 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8051 if (afi == AFI_MAX)
8052 return CMD_WARNING_CONFIG_FAILED;
8053
9a659715
PG
8054 if (rt6 && afi != AFI_IP6)
8055 return CMD_WARNING_CONFIG_FAILED;
8056
301ad80a
PG
8057 if (yes) {
8058 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8059 vty_out(vty, "%% Missing RTLIST\n");
8060 return CMD_WARNING_CONFIG_FAILED;
8061 }
9a659715 8062 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
8063 if (ret != CMD_SUCCESS)
8064 return ret;
8065 }
69b07479
DS
8066
8067 if (yes) {
8068 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8069 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8070 .import_redirect_rtlist);
69b07479
DS
8071 bgp->vpn_policy[afi].import_redirect_rtlist =
8072 ecommunity_dup(ecom);
8073 } else {
8074 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8075 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8076 .import_redirect_rtlist);
69b07479 8077 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 8078 }
69b07479 8079
301ad80a
PG
8080 if (ecom)
8081 ecommunity_free(&ecom);
8082
8083 return CMD_SUCCESS;
8084}
8085
505e5056 8086DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 8087 address_family_ipv4_safi_cmd,
8088 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8089 "Enter Address Family command mode\n"
8090 "Address Family\n"
8091 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 8092{
f51bae9c 8093
d62a17ae 8094 if (argc == 3) {
2131d5cf 8095 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8096 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8097 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8098 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8099 && safi != SAFI_EVPN) {
31947174
MK
8100 vty_out(vty,
8101 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8102 return CMD_WARNING_CONFIG_FAILED;
8103 }
d62a17ae 8104 vty->node = bgp_node_type(AFI_IP, safi);
8105 } else
8106 vty->node = BGP_IPV4_NODE;
718e3744 8107
d62a17ae 8108 return CMD_SUCCESS;
718e3744 8109}
8110
505e5056 8111DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 8112 address_family_ipv6_safi_cmd,
8113 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8114 "Enter Address Family command mode\n"
8115 "Address Family\n"
8116 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 8117{
d62a17ae 8118 if (argc == 3) {
2131d5cf 8119 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8120 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8121 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8122 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8123 && safi != SAFI_EVPN) {
31947174
MK
8124 vty_out(vty,
8125 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8126 return CMD_WARNING_CONFIG_FAILED;
8127 }
d62a17ae 8128 vty->node = bgp_node_type(AFI_IP6, safi);
8129 } else
8130 vty->node = BGP_IPV6_NODE;
25ffbdc1 8131
d62a17ae 8132 return CMD_SUCCESS;
25ffbdc1 8133}
718e3744 8134
d6902373 8135#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 8136DEFUN_NOSH (address_family_vpnv4,
718e3744 8137 address_family_vpnv4_cmd,
8334fd5a 8138 "address-family vpnv4 [unicast]",
718e3744 8139 "Enter Address Family command mode\n"
8c3deaae 8140 "Address Family\n"
3a2d747c 8141 "Address Family modifier\n")
718e3744 8142{
d62a17ae 8143 vty->node = BGP_VPNV4_NODE;
8144 return CMD_SUCCESS;
718e3744 8145}
8146
505e5056 8147DEFUN_NOSH (address_family_vpnv6,
8ecd3266 8148 address_family_vpnv6_cmd,
8334fd5a 8149 "address-family vpnv6 [unicast]",
8ecd3266 8150 "Enter Address Family command mode\n"
8c3deaae 8151 "Address Family\n"
3a2d747c 8152 "Address Family modifier\n")
8ecd3266 8153{
d62a17ae 8154 vty->node = BGP_VPNV6_NODE;
8155 return CMD_SUCCESS;
8ecd3266 8156}
64e4a6c5 8157#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 8158
505e5056 8159DEFUN_NOSH (address_family_evpn,
4e0b7b6d 8160 address_family_evpn_cmd,
7111c1a0 8161 "address-family l2vpn evpn",
4e0b7b6d 8162 "Enter Address Family command mode\n"
7111c1a0
QY
8163 "Address Family\n"
8164 "Address Family modifier\n")
4e0b7b6d 8165{
2131d5cf 8166 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8167 vty->node = BGP_EVPN_NODE;
8168 return CMD_SUCCESS;
4e0b7b6d
PG
8169}
8170
505e5056 8171DEFUN_NOSH (exit_address_family,
718e3744 8172 exit_address_family_cmd,
8173 "exit-address-family",
8174 "Exit from Address Family configuration mode\n")
8175{
d62a17ae 8176 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
8177 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
8178 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
8179 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
8180 || vty->node == BGP_EVPN_NODE
8181 || vty->node == BGP_FLOWSPECV4_NODE
8182 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 8183 vty->node = BGP_NODE;
8184 return CMD_SUCCESS;
718e3744 8185}
6b0655a2 8186
8ad7271d 8187/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 8188static int bgp_clear_prefix(struct vty *vty, const char *view_name,
8189 const char *ip_str, afi_t afi, safi_t safi,
8190 struct prefix_rd *prd)
8191{
8192 int ret;
8193 struct prefix match;
9bcb3eef
DS
8194 struct bgp_dest *dest;
8195 struct bgp_dest *rm;
d62a17ae 8196 struct bgp *bgp;
8197 struct bgp_table *table;
8198 struct bgp_table *rib;
8199
8200 /* BGP structure lookup. */
8201 if (view_name) {
8202 bgp = bgp_lookup_by_name(view_name);
8203 if (bgp == NULL) {
8204 vty_out(vty, "%% Can't find BGP instance %s\n",
8205 view_name);
8206 return CMD_WARNING;
8207 }
8208 } else {
8209 bgp = bgp_get_default();
8210 if (bgp == NULL) {
8211 vty_out(vty, "%% No BGP process is configured\n");
8212 return CMD_WARNING;
8213 }
8214 }
8215
8216 /* Check IP address argument. */
8217 ret = str2prefix(ip_str, &match);
8218 if (!ret) {
8219 vty_out(vty, "%% address is malformed\n");
8220 return CMD_WARNING;
8221 }
8222
8223 match.family = afi2family(afi);
8224 rib = bgp->rib[afi][safi];
8225
8226 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
8227 for (dest = bgp_table_top(rib); dest;
8228 dest = bgp_route_next(dest)) {
8229 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8230
9bcb3eef 8231 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 8232 continue;
8233
9bcb3eef 8234 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
8235 if (table == NULL)
8236 continue;
8237
8238 if ((rm = bgp_node_match(table, &match)) != NULL) {
8239 const struct prefix *rm_p =
9bcb3eef 8240 bgp_dest_get_prefix(rm);
b54892e0
DS
8241
8242 if (rm_p->prefixlen == match.prefixlen) {
8243 SET_FLAG(rm->flags,
8244 BGP_NODE_USER_CLEAR);
8245 bgp_process(bgp, rm, afi, safi);
d62a17ae 8246 }
9bcb3eef 8247 bgp_dest_unlock_node(rm);
d62a17ae 8248 }
8249 }
8250 } else {
9bcb3eef
DS
8251 if ((dest = bgp_node_match(rib, &match)) != NULL) {
8252 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8253
9bcb3eef
DS
8254 if (dest_p->prefixlen == match.prefixlen) {
8255 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
8256 bgp_process(bgp, dest, afi, safi);
d62a17ae 8257 }
9bcb3eef 8258 bgp_dest_unlock_node(dest);
d62a17ae 8259 }
8260 }
8261
8262 return CMD_SUCCESS;
8ad7271d
DS
8263}
8264
b09b5ae0 8265/* one clear bgp command to rule them all */
718e3744 8266DEFUN (clear_ip_bgp_all,
8267 clear_ip_bgp_all_cmd,
453c92f6 8268 "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 8269 CLEAR_STR
8270 IP_STR
8271 BGP_STR
838758ac 8272 BGP_INSTANCE_HELP_STR
510afcd6 8273 BGP_AFI_HELP_STR
fd5e7b70 8274 "Address Family\n"
510afcd6 8275 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 8276 "Address Family modifier\n"
b09b5ae0 8277 "Clear all peers\n"
453c92f6 8278 "BGP IPv4 neighbor to clear\n"
a80beece 8279 "BGP IPv6 neighbor to clear\n"
838758ac 8280 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
8281 "Clear peers with the AS number\n"
8282 "Clear all external peers\n"
718e3744 8283 "Clear all members of peer-group\n"
b09b5ae0 8284 "BGP peer-group name\n"
b09b5ae0
DW
8285 BGP_SOFT_STR
8286 BGP_SOFT_IN_STR
b09b5ae0
DW
8287 BGP_SOFT_OUT_STR
8288 BGP_SOFT_IN_STR
8289 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 8290 BGP_SOFT_OUT_STR)
718e3744 8291{
d62a17ae 8292 char *vrf = NULL;
8293
dc912615
DS
8294 afi_t afi = AFI_UNSPEC;
8295 safi_t safi = SAFI_UNSPEC;
d62a17ae 8296 enum clear_sort clr_sort = clear_peer;
8297 enum bgp_clear_type clr_type;
8298 char *clr_arg = NULL;
8299
8300 int idx = 0;
8301
8302 /* clear [ip] bgp */
8303 if (argv_find(argv, argc, "ip", &idx))
8304 afi = AFI_IP;
8305
9a8bdf1c
PG
8306 /* [<vrf> VIEWVRFNAME] */
8307 if (argv_find(argv, argc, "vrf", &idx)) {
8308 vrf = argv[idx + 1]->arg;
8309 idx += 2;
8310 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8311 vrf = NULL;
8312 } else if (argv_find(argv, argc, "view", &idx)) {
8313 /* [<view> VIEWVRFNAME] */
d62a17ae 8314 vrf = argv[idx + 1]->arg;
8315 idx += 2;
8316 }
d62a17ae 8317 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8318 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8319 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8320
d7b9898c 8321 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 8322 if (argv_find(argv, argc, "*", &idx)) {
8323 clr_sort = clear_all;
8324 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8325 clr_sort = clear_peer;
8326 clr_arg = argv[idx]->arg;
8327 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8328 clr_sort = clear_peer;
8329 clr_arg = argv[idx]->arg;
8330 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8331 clr_sort = clear_group;
8332 idx++;
8333 clr_arg = argv[idx]->arg;
d7b9898c 8334 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 8335 clr_sort = clear_peer;
8336 clr_arg = argv[idx]->arg;
8fa7d444
DS
8337 } else if (argv_find(argv, argc, "WORD", &idx)) {
8338 clr_sort = clear_peer;
8339 clr_arg = argv[idx]->arg;
d62a17ae 8340 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8341 clr_sort = clear_as;
8342 clr_arg = argv[idx]->arg;
8343 } else if (argv_find(argv, argc, "external", &idx)) {
8344 clr_sort = clear_external;
8345 }
8346
8347 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8348 if (argv_find(argv, argc, "soft", &idx)) {
8349 if (argv_find(argv, argc, "in", &idx)
8350 || argv_find(argv, argc, "out", &idx))
8351 clr_type = strmatch(argv[idx]->text, "in")
8352 ? BGP_CLEAR_SOFT_IN
8353 : BGP_CLEAR_SOFT_OUT;
8354 else
8355 clr_type = BGP_CLEAR_SOFT_BOTH;
8356 } else if (argv_find(argv, argc, "in", &idx)) {
8357 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8358 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8359 : BGP_CLEAR_SOFT_IN;
8360 } else if (argv_find(argv, argc, "out", &idx)) {
8361 clr_type = BGP_CLEAR_SOFT_OUT;
8362 } else
8363 clr_type = BGP_CLEAR_SOFT_NONE;
8364
8365 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 8366}
01080f7c 8367
8ad7271d
DS
8368DEFUN (clear_ip_bgp_prefix,
8369 clear_ip_bgp_prefix_cmd,
18c57037 8370 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
8371 CLEAR_STR
8372 IP_STR
8373 BGP_STR
838758ac 8374 BGP_INSTANCE_HELP_STR
8ad7271d 8375 "Clear bestpath and re-advertise\n"
0c7b1b01 8376 "IPv4 prefix\n")
8ad7271d 8377{
d62a17ae 8378 char *vrf = NULL;
8379 char *prefix = NULL;
8ad7271d 8380
d62a17ae 8381 int idx = 0;
01080f7c 8382
d62a17ae 8383 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
8384 if (argv_find(argv, argc, "vrf", &idx)) {
8385 vrf = argv[idx + 1]->arg;
8386 idx += 2;
8387 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8388 vrf = NULL;
8389 } else if (argv_find(argv, argc, "view", &idx)) {
8390 /* [<view> VIEWVRFNAME] */
8391 vrf = argv[idx + 1]->arg;
8392 idx += 2;
8393 }
0c7b1b01 8394
d62a17ae 8395 prefix = argv[argc - 1]->arg;
8ad7271d 8396
d62a17ae 8397 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 8398}
8ad7271d 8399
b09b5ae0
DW
8400DEFUN (clear_bgp_ipv6_safi_prefix,
8401 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 8402 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8403 CLEAR_STR
3a2d747c 8404 IP_STR
718e3744 8405 BGP_STR
8c3deaae 8406 "Address Family\n"
46f296b4 8407 BGP_SAFI_HELP_STR
b09b5ae0 8408 "Clear bestpath and re-advertise\n"
0c7b1b01 8409 "IPv6 prefix\n")
718e3744 8410{
9b475e76
PG
8411 int idx_safi = 0;
8412 int idx_ipv6_prefix = 0;
8413 safi_t safi = SAFI_UNICAST;
8414 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8415 argv[idx_ipv6_prefix]->arg : NULL;
8416
8417 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 8418 return bgp_clear_prefix(
9b475e76
PG
8419 vty, NULL, prefix, AFI_IP6,
8420 safi, NULL);
838758ac 8421}
01080f7c 8422
b09b5ae0
DW
8423DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8424 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 8425 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8426 CLEAR_STR
3a2d747c 8427 IP_STR
718e3744 8428 BGP_STR
838758ac 8429 BGP_INSTANCE_HELP_STR
8c3deaae 8430 "Address Family\n"
46f296b4 8431 BGP_SAFI_HELP_STR
b09b5ae0 8432 "Clear bestpath and re-advertise\n"
0c7b1b01 8433 "IPv6 prefix\n")
718e3744 8434{
9b475e76 8435 int idx_safi = 0;
9a8bdf1c 8436 int idx_vrfview = 0;
9b475e76
PG
8437 int idx_ipv6_prefix = 0;
8438 safi_t safi = SAFI_UNICAST;
8439 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8440 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 8441 char *vrfview = NULL;
9b475e76 8442
9a8bdf1c
PG
8443 /* [<view|vrf> VIEWVRFNAME] */
8444 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8445 vrfview = argv[idx_vrfview + 1]->arg;
8446 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8447 vrfview = NULL;
8448 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8449 /* [<view> VIEWVRFNAME] */
8450 vrfview = argv[idx_vrfview + 1]->arg;
8451 }
9b475e76
PG
8452 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8453
d62a17ae 8454 return bgp_clear_prefix(
9b475e76
PG
8455 vty, vrfview, prefix,
8456 AFI_IP6, safi, NULL);
718e3744 8457}
8458
b09b5ae0
DW
8459DEFUN (show_bgp_views,
8460 show_bgp_views_cmd,
d6e3c605 8461 "show [ip] bgp views",
b09b5ae0 8462 SHOW_STR
d6e3c605 8463 IP_STR
01080f7c 8464 BGP_STR
b09b5ae0 8465 "Show the defined BGP views\n")
01080f7c 8466{
d62a17ae 8467 struct list *inst = bm->bgp;
8468 struct listnode *node;
8469 struct bgp *bgp;
01080f7c 8470
d62a17ae 8471 vty_out(vty, "Defined BGP views:\n");
8472 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8473 /* Skip VRFs. */
8474 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
8475 continue;
8476 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
8477 bgp->as);
8478 }
e52702f2 8479
d62a17ae 8480 return CMD_SUCCESS;
e0081f70
ML
8481}
8482
8386ac43 8483DEFUN (show_bgp_vrfs,
8484 show_bgp_vrfs_cmd,
d6e3c605 8485 "show [ip] bgp vrfs [json]",
8386ac43 8486 SHOW_STR
d6e3c605 8487 IP_STR
8386ac43 8488 BGP_STR
8489 "Show BGP VRFs\n"
9973d184 8490 JSON_STR)
8386ac43 8491{
fe1dc5a3 8492 char buf[ETHER_ADDR_STRLEN];
d62a17ae 8493 struct list *inst = bm->bgp;
8494 struct listnode *node;
8495 struct bgp *bgp;
9f049418 8496 bool uj = use_json(argc, argv);
d62a17ae 8497 json_object *json = NULL;
8498 json_object *json_vrfs = NULL;
8499 int count = 0;
d62a17ae 8500
d62a17ae 8501 if (uj) {
8502 json = json_object_new_object();
8503 json_vrfs = json_object_new_object();
8504 }
8505
8506 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8507 const char *name, *type;
8508 struct peer *peer;
7fe96307 8509 struct listnode *node2, *nnode2;
d62a17ae 8510 int peers_cfg, peers_estb;
8511 json_object *json_vrf = NULL;
d62a17ae 8512
8513 /* Skip Views. */
8514 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
8515 continue;
8516
8517 count++;
efb4077a 8518 if (!uj && count == 1) {
fe1dc5a3 8519 vty_out(vty,
efb4077a 8520 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 8521 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
8522 "#PeersEstb", "Name");
8523 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
8524 "L3-VNI", "RouterMAC", "Interface");
8525 }
d62a17ae 8526
8527 peers_cfg = peers_estb = 0;
8528 if (uj)
8529 json_vrf = json_object_new_object();
8530
8531
7fe96307 8532 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 8533 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8534 continue;
8535 peers_cfg++;
8536 if (peer->status == Established)
8537 peers_estb++;
8538 }
8539
8540 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 8541 name = VRF_DEFAULT_NAME;
d62a17ae 8542 type = "DFLT";
8543 } else {
8544 name = bgp->name;
8545 type = "VRF";
8546 }
8547
a8bf7d9c 8548
d62a17ae 8549 if (uj) {
a4d82a8a
PZ
8550 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8551 ? -1
8552 : (int64_t)bgp->vrf_id;
d62a17ae 8553 json_object_string_add(json_vrf, "type", type);
8554 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8555 json_object_string_add(json_vrf, "routerId",
8556 inet_ntoa(bgp->router_id));
8557 json_object_int_add(json_vrf, "numConfiguredPeers",
8558 peers_cfg);
8559 json_object_int_add(json_vrf, "numEstablishedPeers",
8560 peers_estb);
8561
fe1dc5a3 8562 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
8563 json_object_string_add(
8564 json_vrf, "rmac",
8565 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
8566 json_object_string_add(json_vrf, "interface",
8567 ifindex2ifname(bgp->l3vni_svi_ifindex,
8568 bgp->vrf_id));
d62a17ae 8569 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 8570 } else {
fe1dc5a3 8571 vty_out(vty,
efb4077a 8572 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
8573 type,
8574 bgp->vrf_id == VRF_UNKNOWN ? -1
8575 : (int)bgp->vrf_id,
8576 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
8577 peers_estb, name);
8578 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
8579 bgp->l3vni,
8580 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
8581 ifindex2ifname(bgp->l3vni_svi_ifindex,
8582 bgp->vrf_id));
8583 }
d62a17ae 8584 }
8585
8586 if (uj) {
8587 json_object_object_add(json, "vrfs", json_vrfs);
8588
8589 json_object_int_add(json, "totalVrfs", count);
8590
996c9314
LB
8591 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8592 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8593 json_object_free(json);
8594 } else {
8595 if (count)
8596 vty_out(vty,
8597 "\nTotal number of VRFs (including default): %d\n",
8598 count);
8599 }
8600
8601 return CMD_SUCCESS;
8386ac43 8602}
8603
48ecf8f5
DS
8604DEFUN (show_bgp_mac_hash,
8605 show_bgp_mac_hash_cmd,
8606 "show bgp mac hash",
8607 SHOW_STR
8608 BGP_STR
8609 "Mac Address\n"
8610 "Mac Address database\n")
8611{
8612 bgp_mac_dump_table(vty);
8613
8614 return CMD_SUCCESS;
8615}
acf71666 8616
e3b78da8 8617static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 8618{
0291c246 8619 struct vty *vty = (struct vty *)args;
e3b78da8 8620 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 8621
60466a63 8622 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
8623 tip->refcnt);
8624}
8625
8626static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
8627{
8628 vty_out(vty, "self nexthop database:\n");
af97a18b 8629 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
8630
8631 vty_out(vty, "Tunnel-ip database:\n");
8632 hash_iterate(bgp->tip_hash,
e3b78da8 8633 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
8634 vty);
8635}
8636
15c81ca4
DS
8637DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
8638 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
8639 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
8640 "martian next-hops\n"
8641 "martian next-hop database\n")
acf71666 8642{
0291c246 8643 struct bgp *bgp = NULL;
15c81ca4 8644 int idx = 0;
9a8bdf1c
PG
8645 char *name = NULL;
8646
8647 /* [<vrf> VIEWVRFNAME] */
8648 if (argv_find(argv, argc, "vrf", &idx)) {
8649 name = argv[idx + 1]->arg;
8650 if (name && strmatch(name, VRF_DEFAULT_NAME))
8651 name = NULL;
8652 } else if (argv_find(argv, argc, "view", &idx))
8653 /* [<view> VIEWVRFNAME] */
8654 name = argv[idx + 1]->arg;
8655 if (name)
8656 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
8657 else
8658 bgp = bgp_get_default();
acf71666 8659
acf71666
MK
8660 if (!bgp) {
8661 vty_out(vty, "%% No BGP process is configured\n");
8662 return CMD_WARNING;
8663 }
8664 bgp_show_martian_nexthops(vty, bgp);
8665
8666 return CMD_SUCCESS;
8667}
8668
f412b39a 8669DEFUN (show_bgp_memory,
4bf6a362 8670 show_bgp_memory_cmd,
7fa12b13 8671 "show [ip] bgp memory",
4bf6a362 8672 SHOW_STR
3a2d747c 8673 IP_STR
4bf6a362
PJ
8674 BGP_STR
8675 "Global BGP memory statistics\n")
8676{
d62a17ae 8677 char memstrbuf[MTYPE_MEMSTR_LEN];
8678 unsigned long count;
8679
8680 /* RIB related usage stats */
8681 count = mtype_stats_alloc(MTYPE_BGP_NODE);
8682 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
8683 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 8684 count * sizeof(struct bgp_dest)));
d62a17ae 8685
8686 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
8687 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
8688 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 8689 count * sizeof(struct bgp_path_info)));
d62a17ae 8690 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
8691 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
8692 count,
4b7e6066
DS
8693 mtype_memstr(
8694 memstrbuf, sizeof(memstrbuf),
8695 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 8696
8697 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
8698 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
8699 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8700 count * sizeof(struct bgp_static)));
8701
8702 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
8703 vty_out(vty, "%ld Packets, using %s of memory\n", count,
8704 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8705 count * sizeof(struct bpacket)));
8706
8707 /* Adj-In/Out */
8708 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
8709 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
8710 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8711 count * sizeof(struct bgp_adj_in)));
8712 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
8713 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
8714 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8715 count * sizeof(struct bgp_adj_out)));
8716
8717 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
8718 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
8719 count,
8720 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8721 count * sizeof(struct bgp_nexthop_cache)));
8722
8723 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
8724 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
8725 count,
8726 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8727 count * sizeof(struct bgp_damp_info)));
8728
8729 /* Attributes */
8730 count = attr_count();
8731 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
8732 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8733 count * sizeof(struct attr)));
8734
8735 if ((count = attr_unknown_count()))
8736 vty_out(vty, "%ld unknown attributes\n", count);
8737
8738 /* AS_PATH attributes */
8739 count = aspath_count();
8740 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
8741 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8742 count * sizeof(struct aspath)));
8743
8744 count = mtype_stats_alloc(MTYPE_AS_SEG);
8745 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
8746 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8747 count * sizeof(struct assegment)));
8748
8749 /* Other attributes */
8750 if ((count = community_count()))
8751 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8752 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8753 count * sizeof(struct community)));
d62a17ae 8754 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
8755 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8756 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8757 count * sizeof(struct ecommunity)));
d62a17ae 8758 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
8759 vty_out(vty,
8760 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
8761 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8762 count * sizeof(struct lcommunity)));
d62a17ae 8763
8764 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
8765 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
8766 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8767 count * sizeof(struct cluster_list)));
8768
8769 /* Peer related usage */
8770 count = mtype_stats_alloc(MTYPE_BGP_PEER);
8771 vty_out(vty, "%ld peers, using %s of memory\n", count,
8772 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8773 count * sizeof(struct peer)));
8774
8775 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
8776 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
8777 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8778 count * sizeof(struct peer_group)));
8779
8780 /* Other */
d62a17ae 8781 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
8782 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
8783 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8784 count * sizeof(regex_t)));
d62a17ae 8785 return CMD_SUCCESS;
4bf6a362 8786}
fee0f4c6 8787
57a9c8a8
DS
8788static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
8789{
8790 json_object *bestpath = json_object_new_object();
8791
892fedb6 8792 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
8793 json_object_string_add(bestpath, "asPath", "ignore");
8794
892fedb6 8795 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
8796 json_object_string_add(bestpath, "asPath", "confed");
8797
892fedb6
DA
8798 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
8799 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 8800 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8801 "as-set");
8802 else
a4d82a8a 8803 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8804 "true");
8805 } else
a4d82a8a 8806 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 8807
892fedb6 8808 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 8809 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
8810 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
8811 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
8812 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 8813 json_object_string_add(bestpath, "med", "confed");
892fedb6 8814 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
8815 json_object_string_add(bestpath, "med",
8816 "missing-as-worst");
8817 else
8818 json_object_string_add(bestpath, "med", "true");
8819 }
8820
8821 json_object_object_add(json, "bestPath", bestpath);
8822}
8823
3577f1c5
DD
8824/* Print the error code/subcode for why the peer is down */
8825static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
8826 json_object *json_peer, bool use_json)
8827{
8828 const char *code_str;
8829 const char *subcode_str;
8830
8831 if (use_json) {
8832 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8833 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8834 char errorcodesubcode_hexstr[5];
8835 char errorcodesubcode_str[256];
8836
8837 code_str = bgp_notify_code_str(peer->notify.code);
8838 subcode_str = bgp_notify_subcode_str(
8839 peer->notify.code,
8840 peer->notify.subcode);
8841
772270f3
QY
8842 snprintf(errorcodesubcode_hexstr,
8843 sizeof(errorcodesubcode_hexstr), "%02X%02X",
8844 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
8845 json_object_string_add(json_peer,
8846 "lastErrorCodeSubcode",
8847 errorcodesubcode_hexstr);
8848 snprintf(errorcodesubcode_str, 255, "%s%s",
8849 code_str, subcode_str);
8850 json_object_string_add(json_peer,
8851 "lastNotificationReason",
8852 errorcodesubcode_str);
8853 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8854 && peer->notify.code == BGP_NOTIFY_CEASE
8855 && (peer->notify.subcode
8856 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8857 || peer->notify.subcode
8858 == BGP_NOTIFY_CEASE_ADMIN_RESET)
8859 && peer->notify.length) {
8860 char msgbuf[1024];
8861 const char *msg_str;
8862
8863 msg_str = bgp_notify_admin_message(
8864 msgbuf, sizeof(msgbuf),
8865 (uint8_t *)peer->notify.data,
8866 peer->notify.length);
8867 if (msg_str)
8868 json_object_string_add(
8869 json_peer,
8870 "lastShutdownDescription",
8871 msg_str);
8872 }
8873
c258527b 8874 }
3577f1c5
DD
8875 json_object_string_add(json_peer, "lastResetDueTo",
8876 peer_down_str[(int)peer->last_reset]);
05912a17
DD
8877 json_object_int_add(json_peer, "lastResetCode",
8878 peer->last_reset);
3577f1c5
DD
8879 } else {
8880 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8881 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8882 code_str = bgp_notify_code_str(peer->notify.code);
8883 subcode_str =
8884 bgp_notify_subcode_str(peer->notify.code,
8885 peer->notify.subcode);
8886 vty_out(vty, " Notification %s (%s%s)\n",
8887 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8888 ? "sent"
8889 : "received",
8890 code_str, subcode_str);
8891 } else {
e91c24c8 8892 vty_out(vty, " %s\n",
3577f1c5
DD
8893 peer_down_str[(int)peer->last_reset]);
8894 }
8895 }
8896}
8897
8898static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8899 safi_t safi)
8900{
8901 return ((peer->status != Established) ||
8902 !peer->afc_recv[afi][safi]);
8903}
8904
8905static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8906 struct peer *peer, json_object *json_peer,
8907 int max_neighbor_width, bool use_json)
8908{
8909 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8910 int len;
8911
8912 if (use_json) {
8913 if (peer_dynamic_neighbor(peer))
8914 json_object_boolean_true_add(json_peer,
8915 "dynamicPeer");
8916 if (peer->hostname)
8917 json_object_string_add(json_peer, "hostname",
8918 peer->hostname);
8919
8920 if (peer->domainname)
8921 json_object_string_add(json_peer, "domainname",
8922 peer->domainname);
8923 json_object_int_add(json_peer, "connectionsEstablished",
8924 peer->established);
8925 json_object_int_add(json_peer, "connectionsDropped",
8926 peer->dropped);
8927 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8928 use_json, json_peer);
8929 if (peer->status == Established)
8930 json_object_string_add(json_peer, "lastResetDueTo",
8931 "AFI/SAFI Not Negotiated");
8932 else
8933 bgp_show_peer_reset(NULL, peer, json_peer, true);
8934 } else {
8935 dn_flag[1] = '\0';
8936 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8937 if (peer->hostname
892fedb6 8938 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
8939 len = vty_out(vty, "%s%s(%s)", dn_flag,
8940 peer->hostname, peer->host);
8941 else
8942 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8943
8944 /* pad the neighbor column with spaces */
8945 if (len < max_neighbor_width)
8946 vty_out(vty, "%*s", max_neighbor_width - len,
8947 " ");
e91c24c8 8948 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
8949 peer->dropped,
8950 peer_uptime(peer->uptime, timebuf,
8951 BGP_UPTIME_LEN, 0, NULL));
8952 if (peer->status == Established)
8953 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8954 else
8955 bgp_show_peer_reset(vty, peer, NULL,
8956 false);
8957 }
8958}
c258527b 8959
3577f1c5 8960
718e3744 8961/* Show BGP peer's summary information. */
d62a17ae 8962static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10b49f14
DA
8963 bool show_failed, bool show_established,
8964 bool use_json)
d62a17ae 8965{
8966 struct peer *peer;
8967 struct listnode *node, *nnode;
8968 unsigned int count = 0, dn_count = 0;
8969 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8970 char neighbor_buf[VTY_BUFSIZ];
8971 int neighbor_col_default_width = 16;
3577f1c5 8972 int len, failed_count = 0;
d62a17ae 8973 int max_neighbor_width = 0;
8974 int pfx_rcd_safi;
3c13337d 8975 json_object *json = NULL;
d62a17ae 8976 json_object *json_peer = NULL;
8977 json_object *json_peers = NULL;
50e05855 8978 struct peer_af *paf;
d3ada366 8979 struct bgp_filter *filter;
d62a17ae 8980
8981 /* labeled-unicast routes are installed in the unicast table so in order
8982 * to
8983 * display the correct PfxRcd value we must look at SAFI_UNICAST
8984 */
3577f1c5 8985
d62a17ae 8986 if (safi == SAFI_LABELED_UNICAST)
8987 pfx_rcd_safi = SAFI_UNICAST;
8988 else
8989 pfx_rcd_safi = safi;
8990
8991 if (use_json) {
3c13337d 8992 json = json_object_new_object();
d62a17ae 8993 json_peers = json_object_new_object();
3577f1c5
DD
8994 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8995 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8996 continue;
8997
8998 if (peer->afc[afi][safi]) {
8999 /* See if we have at least a single failed peer */
9000 if (bgp_has_peer_failed(peer, afi, safi))
9001 failed_count++;
9002 count++;
9003 }
9004 if (peer_dynamic_neighbor(peer))
9005 dn_count++;
9006 }
c258527b 9007
d62a17ae 9008 } else {
9009 /* Loop over all neighbors that will be displayed to determine
9010 * how many
9011 * characters are needed for the Neighbor column
9012 */
9013 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9014 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9015 continue;
9016
9017 if (peer->afc[afi][safi]) {
9018 memset(dn_flag, '\0', sizeof(dn_flag));
9019 if (peer_dynamic_neighbor(peer))
9020 dn_flag[0] = '*';
9021
9022 if (peer->hostname
892fedb6
DA
9023 && CHECK_FLAG(bgp->flags,
9024 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
9025 snprintf(neighbor_buf,
9026 sizeof(neighbor_buf),
9027 "%s%s(%s) ", dn_flag,
9028 peer->hostname, peer->host);
d62a17ae 9029 else
772270f3
QY
9030 snprintf(neighbor_buf,
9031 sizeof(neighbor_buf), "%s%s ",
9032 dn_flag, peer->host);
d62a17ae 9033
9034 len = strlen(neighbor_buf);
9035
9036 if (len > max_neighbor_width)
9037 max_neighbor_width = len;
c258527b 9038
3577f1c5
DD
9039 /* See if we have at least a single failed peer */
9040 if (bgp_has_peer_failed(peer, afi, safi))
9041 failed_count++;
9042 count++;
d62a17ae 9043 }
9044 }
f933309e 9045
d62a17ae 9046 /* Originally we displayed the Neighbor column as 16
9047 * characters wide so make that the default
9048 */
9049 if (max_neighbor_width < neighbor_col_default_width)
9050 max_neighbor_width = neighbor_col_default_width;
9051 }
f933309e 9052
3577f1c5
DD
9053 if (show_failed && !failed_count) {
9054 if (use_json) {
9055 json_object_int_add(json, "failedPeersCount", 0);
9056 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 9057 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
9058
9059 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9060 json, JSON_C_TO_STRING_PRETTY));
9061 json_object_free(json);
9062 } else {
9063 vty_out(vty, "%% No failed BGP neighbors found\n");
9064 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9065 }
9066 return CMD_SUCCESS;
9067 }
c258527b 9068
3577f1c5 9069 count = 0; /* Reset the value as its used again */
d62a17ae 9070 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9071 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9072 continue;
9073
ea47320b
DL
9074 if (!peer->afc[afi][safi])
9075 continue;
d62a17ae 9076
ea47320b
DL
9077 if (!count) {
9078 unsigned long ents;
9079 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 9080 int64_t vrf_id_ui;
d62a17ae 9081
a4d82a8a
PZ
9082 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9083 ? -1
9084 : (int64_t)bgp->vrf_id;
ea47320b
DL
9085
9086 /* Usage summary and header */
9087 if (use_json) {
9088 json_object_string_add(
9089 json, "routerId",
9090 inet_ntoa(bgp->router_id));
60466a63
QY
9091 json_object_int_add(json, "as", bgp->as);
9092 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
9093 json_object_string_add(
9094 json, "vrfName",
9095 (bgp->inst_type
9096 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9097 ? VRF_DEFAULT_NAME
ea47320b
DL
9098 : bgp->name);
9099 } else {
9100 vty_out(vty,
9101 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 9102 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
9103 bgp->vrf_id == VRF_UNKNOWN
9104 ? -1
9105 : (int)bgp->vrf_id);
ea47320b
DL
9106 vty_out(vty, "\n");
9107 }
d62a17ae 9108
ea47320b 9109 if (bgp_update_delay_configured(bgp)) {
d62a17ae 9110 if (use_json) {
ea47320b 9111 json_object_int_add(
60466a63 9112 json, "updateDelayLimit",
ea47320b 9113 bgp->v_update_delay);
d62a17ae 9114
ea47320b
DL
9115 if (bgp->v_update_delay
9116 != bgp->v_establish_wait)
d62a17ae 9117 json_object_int_add(
9118 json,
ea47320b
DL
9119 "updateDelayEstablishWait",
9120 bgp->v_establish_wait);
d62a17ae 9121
60466a63 9122 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9123 json_object_string_add(
9124 json,
9125 "updateDelayFirstNeighbor",
9126 bgp->update_delay_begin_time);
9127 json_object_boolean_true_add(
9128 json,
9129 "updateDelayInProgress");
9130 } else {
9131 if (bgp->update_delay_over) {
d62a17ae 9132 json_object_string_add(
9133 json,
9134 "updateDelayFirstNeighbor",
9135 bgp->update_delay_begin_time);
ea47320b 9136 json_object_string_add(
d62a17ae 9137 json,
ea47320b
DL
9138 "updateDelayBestpathResumed",
9139 bgp->update_delay_end_time);
9140 json_object_string_add(
d62a17ae 9141 json,
ea47320b
DL
9142 "updateDelayZebraUpdateResume",
9143 bgp->update_delay_zebra_resume_time);
9144 json_object_string_add(
9145 json,
9146 "updateDelayPeerUpdateResume",
9147 bgp->update_delay_peers_resume_time);
d62a17ae 9148 }
ea47320b
DL
9149 }
9150 } else {
9151 vty_out(vty,
9152 "Read-only mode update-delay limit: %d seconds\n",
9153 bgp->v_update_delay);
9154 if (bgp->v_update_delay
9155 != bgp->v_establish_wait)
d62a17ae 9156 vty_out(vty,
ea47320b
DL
9157 " Establish wait: %d seconds\n",
9158 bgp->v_establish_wait);
d62a17ae 9159
60466a63 9160 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9161 vty_out(vty,
9162 " First neighbor established: %s\n",
9163 bgp->update_delay_begin_time);
9164 vty_out(vty,
9165 " Delay in progress\n");
9166 } else {
9167 if (bgp->update_delay_over) {
d62a17ae 9168 vty_out(vty,
9169 " First neighbor established: %s\n",
9170 bgp->update_delay_begin_time);
9171 vty_out(vty,
ea47320b
DL
9172 " Best-paths resumed: %s\n",
9173 bgp->update_delay_end_time);
9174 vty_out(vty,
9175 " zebra update resumed: %s\n",
9176 bgp->update_delay_zebra_resume_time);
9177 vty_out(vty,
9178 " peers update resumed: %s\n",
9179 bgp->update_delay_peers_resume_time);
d62a17ae 9180 }
9181 }
9182 }
ea47320b 9183 }
d62a17ae 9184
ea47320b
DL
9185 if (use_json) {
9186 if (bgp_maxmed_onstartup_configured(bgp)
9187 && bgp->maxmed_active)
9188 json_object_boolean_true_add(
60466a63 9189 json, "maxMedOnStartup");
ea47320b
DL
9190 if (bgp->v_maxmed_admin)
9191 json_object_boolean_true_add(
60466a63 9192 json, "maxMedAdministrative");
d62a17ae 9193
ea47320b
DL
9194 json_object_int_add(
9195 json, "tableVersion",
60466a63 9196 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 9197
60466a63
QY
9198 ents = bgp_table_count(bgp->rib[afi][safi]);
9199 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
9200 json_object_int_add(
9201 json, "ribMemory",
9bcb3eef 9202 ents * sizeof(struct bgp_dest));
d62a17ae 9203
210ec2a0 9204 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
9205 json_object_int_add(json, "peerCount", ents);
9206 json_object_int_add(json, "peerMemory",
9207 ents * sizeof(struct peer));
d62a17ae 9208
ea47320b
DL
9209 if ((ents = listcount(bgp->group))) {
9210 json_object_int_add(
60466a63 9211 json, "peerGroupCount", ents);
ea47320b
DL
9212 json_object_int_add(
9213 json, "peerGroupMemory",
996c9314
LB
9214 ents * sizeof(struct
9215 peer_group));
ea47320b 9216 }
d62a17ae 9217
ea47320b
DL
9218 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9219 BGP_CONFIG_DAMPENING))
9220 json_object_boolean_true_add(
60466a63 9221 json, "dampeningEnabled");
ea47320b
DL
9222 } else {
9223 if (bgp_maxmed_onstartup_configured(bgp)
9224 && bgp->maxmed_active)
d62a17ae 9225 vty_out(vty,
ea47320b
DL
9226 "Max-med on-startup active\n");
9227 if (bgp->v_maxmed_admin)
d62a17ae 9228 vty_out(vty,
ea47320b 9229 "Max-med administrative active\n");
d62a17ae 9230
60466a63
QY
9231 vty_out(vty, "BGP table version %" PRIu64 "\n",
9232 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 9233
60466a63 9234 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
9235 vty_out(vty,
9236 "RIB entries %ld, using %s of memory\n",
9237 ents,
9bcb3eef
DS
9238 mtype_memstr(
9239 memstrbuf, sizeof(memstrbuf),
9240 ents
9241 * sizeof(struct
9242 bgp_dest)));
ea47320b
DL
9243
9244 /* Peer related usage */
210ec2a0 9245 ents = bgp->af_peer_count[afi][safi];
60466a63 9246 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
9247 ents,
9248 mtype_memstr(
60466a63
QY
9249 memstrbuf, sizeof(memstrbuf),
9250 ents * sizeof(struct peer)));
ea47320b
DL
9251
9252 if ((ents = listcount(bgp->group)))
d62a17ae 9253 vty_out(vty,
ea47320b 9254 "Peer groups %ld, using %s of memory\n",
d62a17ae 9255 ents,
9256 mtype_memstr(
9257 memstrbuf,
9258 sizeof(memstrbuf),
996c9314
LB
9259 ents * sizeof(struct
9260 peer_group)));
d62a17ae 9261
ea47320b
DL
9262 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9263 BGP_CONFIG_DAMPENING))
60466a63 9264 vty_out(vty, "Dampening enabled.\n");
ea47320b 9265 vty_out(vty, "\n");
d62a17ae 9266
ea47320b
DL
9267 /* Subtract 8 here because 'Neighbor' is
9268 * 8 characters */
9269 vty_out(vty, "Neighbor");
60466a63
QY
9270 vty_out(vty, "%*s", max_neighbor_width - 8,
9271 " ");
3577f1c5
DD
9272 if (show_failed)
9273 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
9274 else
9275 vty_out(vty,
db92d226 9276 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
d62a17ae 9277 }
ea47320b 9278 }
d62a17ae 9279
d55811cc 9280 paf = peer_af_find(peer, afi, safi);
d3ada366 9281 filter = &peer->filter[afi][safi];
db92d226 9282
ea47320b 9283 count++;
3577f1c5
DD
9284 /* Works for both failed & successful cases */
9285 if (peer_dynamic_neighbor(peer))
9286 dn_count++;
d62a17ae 9287
ea47320b 9288 if (use_json) {
3577f1c5
DD
9289 json_peer = NULL;
9290
9291 if (show_failed &&
9292 bgp_has_peer_failed(peer, afi, safi)) {
9293 json_peer = json_object_new_object();
9294 bgp_show_failed_summary(vty, bgp, peer,
9295 json_peer, 0, use_json);
9296 } else if (!show_failed) {
10b49f14
DA
9297 if (show_established
9298 && bgp_has_peer_failed(peer, afi, safi))
9299 continue;
9300
3577f1c5
DD
9301 json_peer = json_object_new_object();
9302 if (peer_dynamic_neighbor(peer)) {
9303 json_object_boolean_true_add(json_peer,
9304 "dynamicPeer");
9305 }
d62a17ae 9306
3577f1c5
DD
9307 if (peer->hostname)
9308 json_object_string_add(json_peer, "hostname",
9309 peer->hostname);
9310
9311 if (peer->domainname)
9312 json_object_string_add(json_peer, "domainname",
9313 peer->domainname);
9314
9315 json_object_int_add(json_peer, "remoteAs", peer->as);
9316 json_object_int_add(json_peer, "version", 4);
9317 json_object_int_add(json_peer, "msgRcvd",
9318 PEER_TOTAL_RX(peer));
9319 json_object_int_add(json_peer, "msgSent",
9320 PEER_TOTAL_TX(peer));
9321
43aa5965
QY
9322 atomic_size_t outq_count, inq_count;
9323 outq_count = atomic_load_explicit(
9324 &peer->obuf->count,
9325 memory_order_relaxed);
9326 inq_count = atomic_load_explicit(
9327 &peer->ibuf->count,
9328 memory_order_relaxed);
9329
3577f1c5
DD
9330 json_object_int_add(json_peer, "tableVersion",
9331 peer->version[afi][safi]);
9332 json_object_int_add(json_peer, "outq",
43aa5965
QY
9333 outq_count);
9334 json_object_int_add(json_peer, "inq",
9335 inq_count);
3577f1c5
DD
9336 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9337 use_json, json_peer);
9338
3577f1c5
DD
9339 json_object_int_add(json_peer, "pfxRcd",
9340 peer->pcount[afi][pfx_rcd_safi]);
9341
3577f1c5
DD
9342 if (paf && PAF_SUBGRP(paf))
9343 json_object_int_add(json_peer,
9344 "pfxSnt",
9345 (PAF_SUBGRP(paf))->scount);
9346 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9347 json_object_string_add(json_peer, "state",
9348 "Idle (Admin)");
9349 else if (peer->afc_recv[afi][safi])
9350 json_object_string_add(
9351 json_peer, "state",
9352 lookup_msg(bgp_status_msg, peer->status,
9353 NULL));
9354 else if (CHECK_FLAG(peer->sflags,
9355 PEER_STATUS_PREFIX_OVERFLOW))
9356 json_object_string_add(json_peer, "state",
9357 "Idle (PfxCt)");
9358 else
9359 json_object_string_add(
9360 json_peer, "state",
9361 lookup_msg(bgp_status_msg, peer->status,
9362 NULL));
200116db
DD
9363 json_object_int_add(json_peer, "connectionsEstablished",
9364 peer->established);
9365 json_object_int_add(json_peer, "connectionsDropped",
9366 peer->dropped);
b4e9dcba 9367 }
3577f1c5
DD
9368 /* Avoid creating empty peer dicts in JSON */
9369 if (json_peer == NULL)
9370 continue;
ea47320b
DL
9371
9372 if (peer->conf_if)
60466a63 9373 json_object_string_add(json_peer, "idType",
ea47320b
DL
9374 "interface");
9375 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
9376 json_object_string_add(json_peer, "idType",
9377 "ipv4");
ea47320b 9378 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
9379 json_object_string_add(json_peer, "idType",
9380 "ipv6");
ea47320b
DL
9381 json_object_object_add(json_peers, peer->host,
9382 json_peer);
9383 } else {
3577f1c5
DD
9384 if (show_failed &&
9385 bgp_has_peer_failed(peer, afi, safi)) {
9386 bgp_show_failed_summary(vty, bgp, peer, NULL,
9387 max_neighbor_width,
9388 use_json);
9389 } else if (!show_failed) {
10b49f14
DA
9390 if (show_established
9391 && bgp_has_peer_failed(peer, afi, safi))
9392 continue;
9393
3577f1c5
DD
9394 memset(dn_flag, '\0', sizeof(dn_flag));
9395 if (peer_dynamic_neighbor(peer)) {
9396 dn_flag[0] = '*';
9397 }
d62a17ae 9398
3577f1c5 9399 if (peer->hostname
892fedb6
DA
9400 && CHECK_FLAG(bgp->flags,
9401 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 9402 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
9403 peer->hostname,
9404 peer->host);
d62a17ae 9405 else
3577f1c5
DD
9406 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9407
9408 /* pad the neighbor column with spaces */
9409 if (len < max_neighbor_width)
9410 vty_out(vty, "%*s", max_neighbor_width - len,
9411 " ");
9412
43aa5965
QY
9413 atomic_size_t outq_count, inq_count;
9414 outq_count = atomic_load_explicit(
9415 &peer->obuf->count,
9416 memory_order_relaxed);
9417 inq_count = atomic_load_explicit(
9418 &peer->ibuf->count,
9419 memory_order_relaxed);
9420
566bdaf6 9421 vty_out(vty,
6cde4b45 9422 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
3577f1c5 9423 peer->as, PEER_TOTAL_RX(peer),
566bdaf6 9424 PEER_TOTAL_TX(peer),
43aa5965
QY
9425 peer->version[afi][safi], inq_count,
9426 outq_count,
3577f1c5
DD
9427 peer_uptime(peer->uptime, timebuf,
9428 BGP_UPTIME_LEN, 0, NULL));
9429
db92d226 9430 if (peer->status == Established) {
d3ada366
DA
9431 if (peer->afc_recv[afi][safi]) {
9432 if (CHECK_FLAG(
9433 bgp->flags,
9434 BGP_FLAG_EBGP_REQUIRES_POLICY)
9435 && !bgp_inbound_policy_exists(
9436 peer, filter))
9437 vty_out(vty, " %12s",
9438 "(Policy)");
9439 else
9440 vty_out(vty,
6cde4b45 9441 " %12u",
d3ada366
DA
9442 peer->pcount
9443 [afi]
9444 [pfx_rcd_safi]);
9445 } else {
3577f1c5 9446 vty_out(vty, " NoNeg");
d3ada366 9447 }
db92d226 9448
d3ada366
DA
9449 if (paf && PAF_SUBGRP(paf)) {
9450 if (CHECK_FLAG(
9451 bgp->flags,
9452 BGP_FLAG_EBGP_REQUIRES_POLICY)
9453 && !bgp_outbound_policy_exists(
9454 peer, filter))
9455 vty_out(vty, " %8s",
9456 "(Policy)");
9457 else
9458 vty_out(vty,
6cde4b45 9459 " %8u",
d3ada366
DA
9460 (PAF_SUBGRP(
9461 paf))
9462 ->scount);
9463 }
db92d226 9464 } else {
3577f1c5
DD
9465 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9466 vty_out(vty, " Idle (Admin)");
9467 else if (CHECK_FLAG(
9468 peer->sflags,
9469 PEER_STATUS_PREFIX_OVERFLOW))
9470 vty_out(vty, " Idle (PfxCt)");
9471 else
9472 vty_out(vty, " %12s",
9473 lookup_msg(bgp_status_msg,
9474 peer->status, NULL));
db92d226 9475
6cde4b45 9476 vty_out(vty, " %8u", 0);
3577f1c5
DD
9477 }
9478 vty_out(vty, "\n");
d62a17ae 9479 }
3577f1c5 9480
d62a17ae 9481 }
9482 }
f933309e 9483
d62a17ae 9484 if (use_json) {
9485 json_object_object_add(json, "peers", json_peers);
3577f1c5 9486 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 9487 json_object_int_add(json, "totalPeers", count);
9488 json_object_int_add(json, "dynamicPeers", dn_count);
9489
3577f1c5
DD
9490 if (!show_failed)
9491 bgp_show_bestpath_json(bgp, json);
57a9c8a8 9492
996c9314
LB
9493 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9494 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9495 json_object_free(json);
9496 } else {
9497 if (count)
9498 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9499 else {
d6ceaca3 9500 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 9501 get_afi_safi_str(afi, safi, false));
d62a17ae 9502 }
b05a1c8b 9503
d6ceaca3 9504 if (dn_count) {
d62a17ae 9505 vty_out(vty, "* - dynamic neighbor\n");
9506 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
9507 dn_count, bgp->dynamic_neighbors_limit);
9508 }
9509 }
1ff9a340 9510
d62a17ae 9511 return CMD_SUCCESS;
718e3744 9512}
9513
d62a17ae 9514static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10b49f14
DA
9515 int safi, bool show_failed,
9516 bool show_established, bool use_json)
d62a17ae 9517{
9518 int is_first = 1;
9519 int afi_wildcard = (afi == AFI_MAX);
9520 int safi_wildcard = (safi == SAFI_MAX);
9521 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 9522 bool nbr_output = false;
d62a17ae 9523
9524 if (use_json && is_wildcard)
9525 vty_out(vty, "{\n");
9526 if (afi_wildcard)
9527 afi = 1; /* AFI_IP */
9528 while (afi < AFI_MAX) {
9529 if (safi_wildcard)
9530 safi = 1; /* SAFI_UNICAST */
9531 while (safi < SAFI_MAX) {
318cac96 9532 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 9533 nbr_output = true;
f86897b9 9534
d62a17ae 9535 if (is_wildcard) {
9536 /*
9537 * So limit output to those afi/safi
9538 * pairs that
9539 * actualy have something interesting in
9540 * them
9541 */
9542 if (use_json) {
d62a17ae 9543 if (!is_first)
9544 vty_out(vty, ",\n");
9545 else
9546 is_first = 0;
9547
9548 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
9549 get_afi_safi_str(afi,
9550 safi,
9551 true));
d62a17ae 9552 } else {
9553 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
9554 get_afi_safi_str(afi,
9555 safi,
9556 false));
d62a17ae 9557 }
9558 }
10b49f14
DA
9559 bgp_show_summary(vty, bgp, afi, safi,
9560 show_failed, show_established,
3577f1c5 9561 use_json);
d62a17ae 9562 }
9563 safi++;
d62a17ae 9564 if (!safi_wildcard)
9565 safi = SAFI_MAX;
9566 }
9567 afi++;
ee851c8c 9568 if (!afi_wildcard)
d62a17ae 9569 afi = AFI_MAX;
9570 }
9571
9572 if (use_json && is_wildcard)
9573 vty_out(vty, "}\n");
ca61fd25
DS
9574 else if (!nbr_output) {
9575 if (use_json)
9576 vty_out(vty, "{}\n");
9577 else
9578 vty_out(vty, "%% No BGP neighbors found\n");
9579 }
d62a17ae 9580}
9581
9582static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5 9583 safi_t safi, bool show_failed,
10b49f14 9584 bool show_established,
3577f1c5 9585 bool use_json)
d62a17ae 9586{
9587 struct listnode *node, *nnode;
9588 struct bgp *bgp;
d62a17ae 9589 int is_first = 1;
9f049418 9590 bool nbr_output = false;
d62a17ae 9591
9592 if (use_json)
9593 vty_out(vty, "{\n");
9594
9595 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 9596 nbr_output = true;
d62a17ae 9597 if (use_json) {
d62a17ae 9598 if (!is_first)
9599 vty_out(vty, ",\n");
9600 else
9601 is_first = 0;
9602
9603 vty_out(vty, "\"%s\":",
9604 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9605 ? VRF_DEFAULT_NAME
d62a17ae 9606 : bgp->name);
9607 } else {
9608 vty_out(vty, "\nInstance %s:\n",
9609 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9610 ? VRF_DEFAULT_NAME
d62a17ae 9611 : bgp->name);
9612 }
3577f1c5 9613 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 9614 show_established, use_json);
d62a17ae 9615 }
9616
9617 if (use_json)
9618 vty_out(vty, "}\n");
9f049418
DS
9619 else if (!nbr_output)
9620 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 9621}
9622
9623int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10b49f14
DA
9624 safi_t safi, bool show_failed, bool show_established,
9625 bool use_json)
d62a17ae 9626{
9627 struct bgp *bgp;
9628
9629 if (name) {
9630 if (strmatch(name, "all")) {
10b49f14
DA
9631 bgp_show_all_instances_summary_vty(
9632 vty, afi, safi, show_failed, show_established,
9633 use_json);
d62a17ae 9634 return CMD_SUCCESS;
9635 } else {
9636 bgp = bgp_lookup_by_name(name);
9637
9638 if (!bgp) {
9639 if (use_json)
9640 vty_out(vty, "{}\n");
9641 else
9642 vty_out(vty,
ca61fd25 9643 "%% BGP instance not found\n");
d62a17ae 9644 return CMD_WARNING;
9645 }
9646
f86897b9 9647 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
10b49f14
DA
9648 show_failed, show_established,
9649 use_json);
d62a17ae 9650 return CMD_SUCCESS;
9651 }
9652 }
9653
9654 bgp = bgp_get_default();
9655
9656 if (bgp)
3577f1c5 9657 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 9658 show_established, use_json);
9f049418 9659 else {
ca61fd25
DS
9660 if (use_json)
9661 vty_out(vty, "{}\n");
9662 else
9663 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
9664 return CMD_WARNING;
9665 }
d62a17ae 9666
9667 return CMD_SUCCESS;
4fb25c53
DW
9668}
9669
716b2d8a 9670/* `show [ip] bgp summary' commands. */
47fc97cc 9671DEFUN (show_ip_bgp_summary,
718e3744 9672 show_ip_bgp_summary_cmd,
10b49f14 9673 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [established|failed] [json]",
718e3744 9674 SHOW_STR
9675 IP_STR
9676 BGP_STR
8386ac43 9677 BGP_INSTANCE_HELP_STR
46f296b4 9678 BGP_AFI_HELP_STR
dd6bd0f1 9679 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 9680 "Summary of BGP neighbor status\n"
10b49f14 9681 "Show only sessions in Established state\n"
3577f1c5 9682 "Show only sessions not in Established state\n"
9973d184 9683 JSON_STR)
718e3744 9684{
d62a17ae 9685 char *vrf = NULL;
9686 afi_t afi = AFI_MAX;
9687 safi_t safi = SAFI_MAX;
3577f1c5 9688 bool show_failed = false;
10b49f14 9689 bool show_established = false;
d62a17ae 9690
9691 int idx = 0;
9692
9693 /* show [ip] bgp */
9694 if (argv_find(argv, argc, "ip", &idx))
9695 afi = AFI_IP;
9a8bdf1c
PG
9696 /* [<vrf> VIEWVRFNAME] */
9697 if (argv_find(argv, argc, "vrf", &idx)) {
9698 vrf = argv[idx + 1]->arg;
9699 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9700 vrf = NULL;
9701 } else if (argv_find(argv, argc, "view", &idx))
9702 /* [<view> VIEWVRFNAME] */
9703 vrf = argv[idx + 1]->arg;
d62a17ae 9704 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9705 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
9706 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9707 }
9708
3577f1c5
DD
9709 if (argv_find(argv, argc, "failed", &idx))
9710 show_failed = true;
10b49f14
DA
9711 if (argv_find(argv, argc, "established", &idx))
9712 show_established = true;
3577f1c5 9713
9f049418 9714 bool uj = use_json(argc, argv);
d62a17ae 9715
10b49f14
DA
9716 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
9717 show_established, uj);
d62a17ae 9718}
9719
5cb5f4d0 9720const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 9721{
5cb5f4d0
DD
9722 if (for_json)
9723 return get_afi_safi_json_str(afi, safi);
d62a17ae 9724 else
5cb5f4d0 9725 return get_afi_safi_vty_str(afi, safi);
27162734
LB
9726}
9727
d62a17ae 9728
9729static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
9730 afi_t afi, safi_t safi,
d7c0a89a
QY
9731 uint16_t adv_smcap, uint16_t adv_rmcap,
9732 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 9733 bool use_json, json_object *json_pref)
d62a17ae 9734{
9735 /* Send-Mode */
9736 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9737 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
9738 if (use_json) {
9739 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9740 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9741 json_object_string_add(json_pref, "sendMode",
9742 "advertisedAndReceived");
9743 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9744 json_object_string_add(json_pref, "sendMode",
9745 "advertised");
9746 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9747 json_object_string_add(json_pref, "sendMode",
9748 "received");
9749 } else {
9750 vty_out(vty, " Send-mode: ");
9751 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9752 vty_out(vty, "advertised");
9753 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9754 vty_out(vty, "%sreceived",
9755 CHECK_FLAG(p->af_cap[afi][safi],
9756 adv_smcap)
9757 ? ", "
9758 : "");
9759 vty_out(vty, "\n");
9760 }
9761 }
9762
9763 /* Receive-Mode */
9764 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9765 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
9766 if (use_json) {
9767 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9768 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9769 json_object_string_add(json_pref, "recvMode",
9770 "advertisedAndReceived");
9771 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9772 json_object_string_add(json_pref, "recvMode",
9773 "advertised");
9774 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9775 json_object_string_add(json_pref, "recvMode",
9776 "received");
9777 } else {
9778 vty_out(vty, " Receive-mode: ");
9779 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9780 vty_out(vty, "advertised");
9781 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9782 vty_out(vty, "%sreceived",
9783 CHECK_FLAG(p->af_cap[afi][safi],
9784 adv_rmcap)
9785 ? ", "
9786 : "");
9787 vty_out(vty, "\n");
9788 }
9789 }
9790}
9791
13909c4f
DS
9792static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
9793 struct peer *p,
9794 bool use_json,
9795 json_object *json)
2986cac2 9796{
08c2d52a 9797 bool rbit_status = false;
2986cac2 9798
9799 if (!use_json)
a53ca37b 9800 vty_out(vty, "\n R bit: ");
2986cac2 9801
13909c4f
DS
9802 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
9803 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
9804 && (p->status == Established)) {
2986cac2 9805
9806 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 9807 rbit_status = true;
2986cac2 9808 else
08c2d52a 9809 rbit_status = false;
2986cac2 9810 }
9811
9812 if (rbit_status) {
9813 if (use_json)
13909c4f 9814 json_object_boolean_true_add(json, "rBit");
2986cac2 9815 else
9816 vty_out(vty, "True\n");
9817 } else {
9818 if (use_json)
13909c4f 9819 json_object_boolean_false_add(json, "rBit");
2986cac2 9820 else
9821 vty_out(vty, "False\n");
9822 }
9823}
9824
13909c4f
DS
9825static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
9826 struct peer *peer,
9827 bool use_json,
9828 json_object *json)
2986cac2 9829{
2bb5d39b 9830 const char *mode = "NotApplicable";
2986cac2 9831
9832 if (!use_json)
a53ca37b 9833 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 9834
13909c4f
DS
9835 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9836 && (peer->status == Established)) {
2986cac2 9837
13909c4f
DS
9838 if ((peer->nsf_af_count == 0)
9839 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9840
2986cac2 9841 mode = "Disable";
9842
13909c4f
DS
9843 } else if (peer->nsf_af_count == 0
9844 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9845
2986cac2 9846 mode = "Helper";
9847
13909c4f
DS
9848 } else if (peer->nsf_af_count != 0
9849 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9850
2986cac2 9851 mode = "Restart";
2986cac2 9852 }
9853 }
9854
9855 if (use_json) {
13909c4f 9856 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 9857 } else
9858 vty_out(vty, mode, "\n");
9859}
9860
13909c4f
DS
9861static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
9862 struct peer *p,
9863 bool use_json,
9864 json_object *json)
2986cac2 9865{
9866 const char *mode = "Invalid";
9867
9868 if (!use_json)
a53ca37b 9869 vty_out(vty, " Local GR Mode: ");
2986cac2 9870
9871 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
9872 mode = "Helper";
9873 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
9874 mode = "Restart";
9875 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
9876 mode = "Disable";
2ba1fe69 9877 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 9878 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
9879 mode = "Helper*";
9880 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
9881 mode = "Restart*";
9882 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
9883 mode = "Disable*";
9884 else
9885 mode = "Invalid*";
2ba1fe69 9886 }
2986cac2 9887
9888 if (use_json) {
13909c4f 9889 json_object_string_add(json, "localGrMode", mode);
2986cac2 9890 } else {
9891 vty_out(vty, mode, "\n");
9892 }
9893}
9894
13909c4f
DS
9895static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
9896 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 9897{
2ba1fe69 9898 afi_t afi;
9899 safi_t safi;
2986cac2 9900 json_object *json_afi_safi = NULL;
9901 json_object *json_timer = NULL;
9902 json_object *json_endofrib_status = NULL;
9e3b51a7 9903 bool eor_flag = false;
2986cac2 9904
9905 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9906 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
9907 if (!peer->afc[afi][safi])
9908 continue;
2986cac2 9909
13909c4f
DS
9910 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9911 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
9912 continue;
9e3b51a7 9913
13909c4f
DS
9914 if (use_json) {
9915 json_afi_safi = json_object_new_object();
9916 json_endofrib_status = json_object_new_object();
9917 json_timer = json_object_new_object();
9918 }
2986cac2 9919
13909c4f
DS
9920 if (peer->eor_stime[afi][safi]
9921 >= peer->pkt_stime[afi][safi])
9922 eor_flag = true;
9923 else
9924 eor_flag = false;
2986cac2 9925
13909c4f 9926 if (!use_json) {
a53ca37b 9927 vty_out(vty, " %s:\n",
13909c4f 9928 get_afi_safi_str(afi, safi, false));
2986cac2 9929
a53ca37b 9930 vty_out(vty, " F bit: ");
698ba8d0 9931 }
2986cac2 9932
13909c4f
DS
9933 if (peer->nsf[afi][safi]
9934 && CHECK_FLAG(peer->af_cap[afi][safi],
9935 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 9936
13909c4f
DS
9937 if (use_json) {
9938 json_object_boolean_true_add(
2986cac2 9939 json_afi_safi, "fBit");
13909c4f
DS
9940 } else
9941 vty_out(vty, "True\n");
9942 } else {
9943 if (use_json)
9944 json_object_boolean_false_add(
9945 json_afi_safi, "fBit");
9946 else
9947 vty_out(vty, "False\n");
9948 }
2986cac2 9949
13909c4f 9950 if (!use_json)
a53ca37b 9951 vty_out(vty, " End-of-RIB sent: ");
2986cac2 9952
13909c4f
DS
9953 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9954 PEER_STATUS_EOR_SEND)) {
9955 if (use_json) {
9956 json_object_boolean_true_add(
2986cac2 9957 json_endofrib_status,
13909c4f 9958 "endOfRibSend");
9e3b51a7 9959
13909c4f
DS
9960 PRINT_EOR_JSON(eor_flag);
9961 } else {
9962 vty_out(vty, "Yes\n");
9963 vty_out(vty,
a53ca37b 9964 " End-of-RIB sent after update: ");
2986cac2 9965
13909c4f
DS
9966 PRINT_EOR(eor_flag);
9967 }
9968 } else {
9969 if (use_json) {
9970 json_object_boolean_false_add(
2986cac2 9971 json_endofrib_status,
13909c4f
DS
9972 "endOfRibSend");
9973 json_object_boolean_false_add(
9e3b51a7 9974 json_endofrib_status,
13909c4f
DS
9975 "endOfRibSentAfterUpdate");
9976 } else {
9977 vty_out(vty, "No\n");
9978 vty_out(vty,
a53ca37b 9979 " End-of-RIB sent after update: ");
13909c4f 9980 vty_out(vty, "No\n");
2986cac2 9981 }
13909c4f 9982 }
2986cac2 9983
a53ca37b
DA
9984 if (!use_json)
9985 vty_out(vty, " End-of-RIB received: ");
9986
9987 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9988 PEER_STATUS_EOR_RECEIVED)) {
9989 if (use_json)
9990 json_object_boolean_true_add(
9991 json_endofrib_status,
9992 "endOfRibRecv");
9993 else
9994 vty_out(vty, "Yes\n");
9995 } else {
9996 if (use_json)
9997 json_object_boolean_false_add(
9998 json_endofrib_status,
9999 "endOfRibRecv");
10000 else
10001 vty_out(vty, "No\n");
10002 }
10003
13909c4f
DS
10004 if (use_json) {
10005 json_object_int_add(json_timer,
10006 "stalePathTimer",
10007 peer->bgp->stalepath_time);
2986cac2 10008
13909c4f
DS
10009 if (peer->t_gr_stale != NULL) {
10010 json_object_int_add(
2986cac2 10011 json_timer,
10012 "stalePathTimerRemaining",
10013 thread_timer_remain_second(
13909c4f
DS
10014 peer->t_gr_stale));
10015 }
3a75afa4 10016
13909c4f
DS
10017 /* Display Configured Selection
10018 * Deferral only when when
10019 * Gr mode is enabled.
10020 */
10021 if (CHECK_FLAG(peer->flags,
10022 PEER_FLAG_GRACEFUL_RESTART)) {
10023 json_object_int_add(
3a75afa4 10024 json_timer,
2986cac2 10025 "selectionDeferralTimer",
10026 peer->bgp->stalepath_time);
13909c4f 10027 }
2986cac2 10028
13909c4f
DS
10029 if (peer->bgp->gr_info[afi][safi]
10030 .t_select_deferral
10031 != NULL) {
2986cac2 10032
13909c4f 10033 json_object_int_add(
2986cac2 10034 json_timer,
10035 "selectionDeferralTimerRemaining",
10036 thread_timer_remain_second(
13909c4f
DS
10037 peer->bgp
10038 ->gr_info[afi]
10039 [safi]
10040 .t_select_deferral));
10041 }
10042 } else {
a53ca37b 10043 vty_out(vty, " Timers:\n");
13909c4f 10044 vty_out(vty,
a53ca37b
DA
10045 " Configured Stale Path Time(sec): %u\n",
10046 peer->bgp->stalepath_time);
2986cac2 10047
a53ca37b 10048 if (peer->t_gr_stale != NULL)
2986cac2 10049 vty_out(vty,
a53ca37b 10050 " Stale Path Remaining(sec): %ld\n",
2986cac2 10051 thread_timer_remain_second(
13909c4f 10052 peer->t_gr_stale));
13909c4f
DS
10053 /* Display Configured Selection
10054 * Deferral only when when
10055 * Gr mode is enabled.
10056 */
10057 if (CHECK_FLAG(peer->flags,
a53ca37b 10058 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 10059 vty_out(vty,
a53ca37b 10060 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 10061 peer->bgp->select_defer_time);
2986cac2 10062
13909c4f
DS
10063 if (peer->bgp->gr_info[afi][safi]
10064 .t_select_deferral
a53ca37b 10065 != NULL)
13909c4f 10066 vty_out(vty,
a53ca37b 10067 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 10068 thread_timer_remain_second(
13909c4f
DS
10069 peer->bgp
10070 ->gr_info[afi]
10071 [safi]
10072 .t_select_deferral));
2986cac2 10073 }
13909c4f
DS
10074 if (use_json) {
10075 json_object_object_add(json_afi_safi,
10076 "endOfRibStatus",
10077 json_endofrib_status);
10078 json_object_object_add(json_afi_safi, "timers",
10079 json_timer);
10080 json_object_object_add(
10081 json, get_afi_safi_str(afi, safi, true),
10082 json_afi_safi);
10083 }
2986cac2 10084 }
10085 }
10086}
10087
36235319
QY
10088static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
10089 struct peer *p,
10090 bool use_json,
10091 json_object *json)
2986cac2 10092{
10093 if (use_json) {
10094 json_object *json_timer = NULL;
10095
10096 json_timer = json_object_new_object();
10097
13909c4f
DS
10098 json_object_int_add(json_timer, "configuredRestartTimer",
10099 p->bgp->restart_time);
2986cac2 10100
13909c4f
DS
10101 json_object_int_add(json_timer, "receivedRestartTimer",
10102 p->v_gr_restart);
2986cac2 10103
13909c4f
DS
10104 if (p->t_gr_restart != NULL)
10105 json_object_int_add(
10106 json_timer, "restartTimerRemaining",
10107 thread_timer_remain_second(p->t_gr_restart));
2986cac2 10108
10109 json_object_object_add(json, "timers", json_timer);
10110 } else {
10111
a53ca37b
DA
10112 vty_out(vty, " Timers:\n");
10113 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 10114 p->bgp->restart_time);
2986cac2 10115
a53ca37b 10116 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
10117 p->v_gr_restart);
10118 if (p->t_gr_restart != NULL)
a53ca37b 10119 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 10120 thread_timer_remain_second(p->t_gr_restart));
36235319 10121 if (p->t_gr_restart != NULL) {
a53ca37b 10122 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
10123 thread_timer_remain_second(p->t_gr_restart));
10124 }
2986cac2 10125 }
10126}
10127
10128static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 10129 bool use_json, json_object *json)
2986cac2 10130{
10131 char buf[SU_ADDRSTRLEN] = {0};
10132 char dn_flag[2] = {0};
2b7165e7
QY
10133 /* '*' + v6 address of neighbor */
10134 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 10135
2986cac2 10136 if (!p->conf_if && peer_dynamic_neighbor(p))
10137 dn_flag[0] = '*';
10138
10139 if (p->conf_if) {
10140 if (use_json)
13909c4f
DS
10141 json_object_string_add(
10142 json, "neighborAddr",
2986cac2 10143 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
10144 ? "none"
10145 : sockunion2str(&p->su, buf,
10146 SU_ADDRSTRLEN));
2986cac2 10147 else
13909c4f 10148 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 10149 BGP_PEER_SU_UNSPEC(p)
10150 ? "none"
10151 : sockunion2str(&p->su, buf,
10152 SU_ADDRSTRLEN));
10153 } else {
772270f3
QY
10154 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
10155 p->host);
2986cac2 10156
10157 if (use_json)
36235319
QY
10158 json_object_string_add(json, "neighborAddr",
10159 neighborAddr);
2986cac2 10160 else
36235319 10161 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 10162 }
10163
10164 /* more gr info in new format */
10165 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
10166}
10167
d62a17ae 10168static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 10169 safi_t safi, bool use_json,
d62a17ae 10170 json_object *json_neigh)
10171{
0291c246
MK
10172 struct bgp_filter *filter;
10173 struct peer_af *paf;
10174 char orf_pfx_name[BUFSIZ];
10175 int orf_pfx_count;
10176 json_object *json_af = NULL;
10177 json_object *json_prefA = NULL;
10178 json_object *json_prefB = NULL;
10179 json_object *json_addr = NULL;
d62a17ae 10180
10181 if (use_json) {
10182 json_addr = json_object_new_object();
10183 json_af = json_object_new_object();
10184 filter = &p->filter[afi][safi];
10185
10186 if (peer_group_active(p))
10187 json_object_string_add(json_addr, "peerGroupMember",
10188 p->group->name);
10189
10190 paf = peer_af_find(p, afi, safi);
10191 if (paf && PAF_SUBGRP(paf)) {
10192 json_object_int_add(json_addr, "updateGroupId",
10193 PAF_UPDGRP(paf)->id);
10194 json_object_int_add(json_addr, "subGroupId",
10195 PAF_SUBGRP(paf)->id);
10196 json_object_int_add(json_addr, "packetQueueLength",
10197 bpacket_queue_virtual_length(paf));
10198 }
10199
10200 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10201 || CHECK_FLAG(p->af_cap[afi][safi],
10202 PEER_CAP_ORF_PREFIX_SM_RCV)
10203 || CHECK_FLAG(p->af_cap[afi][safi],
10204 PEER_CAP_ORF_PREFIX_RM_ADV)
10205 || CHECK_FLAG(p->af_cap[afi][safi],
10206 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10207 json_object_int_add(json_af, "orfType",
10208 ORF_TYPE_PREFIX);
10209 json_prefA = json_object_new_object();
10210 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
10211 PEER_CAP_ORF_PREFIX_SM_ADV,
10212 PEER_CAP_ORF_PREFIX_RM_ADV,
10213 PEER_CAP_ORF_PREFIX_SM_RCV,
10214 PEER_CAP_ORF_PREFIX_RM_RCV,
10215 use_json, json_prefA);
10216 json_object_object_add(json_af, "orfPrefixList",
10217 json_prefA);
10218 }
10219
10220 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10221 || CHECK_FLAG(p->af_cap[afi][safi],
10222 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10223 || CHECK_FLAG(p->af_cap[afi][safi],
10224 PEER_CAP_ORF_PREFIX_RM_ADV)
10225 || CHECK_FLAG(p->af_cap[afi][safi],
10226 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10227 json_object_int_add(json_af, "orfOldType",
10228 ORF_TYPE_PREFIX_OLD);
10229 json_prefB = json_object_new_object();
10230 bgp_show_peer_afi_orf_cap(
10231 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10232 PEER_CAP_ORF_PREFIX_RM_ADV,
10233 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10234 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
10235 json_prefB);
10236 json_object_object_add(json_af, "orfOldPrefixList",
10237 json_prefB);
10238 }
10239
10240 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10241 || CHECK_FLAG(p->af_cap[afi][safi],
10242 PEER_CAP_ORF_PREFIX_SM_RCV)
10243 || CHECK_FLAG(p->af_cap[afi][safi],
10244 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10245 || CHECK_FLAG(p->af_cap[afi][safi],
10246 PEER_CAP_ORF_PREFIX_RM_ADV)
10247 || CHECK_FLAG(p->af_cap[afi][safi],
10248 PEER_CAP_ORF_PREFIX_RM_RCV)
10249 || CHECK_FLAG(p->af_cap[afi][safi],
10250 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10251 json_object_object_add(json_addr, "afDependentCap",
10252 json_af);
10253 else
10254 json_object_free(json_af);
10255
772270f3
QY
10256 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10257 p->host, afi, safi);
d62a17ae 10258 orf_pfx_count = prefix_bgp_show_prefix_list(
10259 NULL, afi, orf_pfx_name, use_json);
10260
10261 if (CHECK_FLAG(p->af_sflags[afi][safi],
10262 PEER_STATUS_ORF_PREFIX_SEND)
10263 || orf_pfx_count) {
10264 if (CHECK_FLAG(p->af_sflags[afi][safi],
10265 PEER_STATUS_ORF_PREFIX_SEND))
10266 json_object_boolean_true_add(json_neigh,
10267 "orfSent");
10268 if (orf_pfx_count)
10269 json_object_int_add(json_addr, "orfRecvCounter",
10270 orf_pfx_count);
10271 }
10272 if (CHECK_FLAG(p->af_sflags[afi][safi],
10273 PEER_STATUS_ORF_WAIT_REFRESH))
10274 json_object_string_add(
10275 json_addr, "orfFirstUpdate",
10276 "deferredUntilORFOrRouteRefreshRecvd");
10277
10278 if (CHECK_FLAG(p->af_flags[afi][safi],
10279 PEER_FLAG_REFLECTOR_CLIENT))
10280 json_object_boolean_true_add(json_addr,
10281 "routeReflectorClient");
10282 if (CHECK_FLAG(p->af_flags[afi][safi],
10283 PEER_FLAG_RSERVER_CLIENT))
10284 json_object_boolean_true_add(json_addr,
10285 "routeServerClient");
10286 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10287 json_object_boolean_true_add(json_addr,
10288 "inboundSoftConfigPermit");
10289
10290 if (CHECK_FLAG(p->af_flags[afi][safi],
10291 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10292 json_object_boolean_true_add(
10293 json_addr,
10294 "privateAsNumsAllReplacedInUpdatesToNbr");
10295 else if (CHECK_FLAG(p->af_flags[afi][safi],
10296 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10297 json_object_boolean_true_add(
10298 json_addr,
10299 "privateAsNumsReplacedInUpdatesToNbr");
10300 else if (CHECK_FLAG(p->af_flags[afi][safi],
10301 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10302 json_object_boolean_true_add(
10303 json_addr,
10304 "privateAsNumsAllRemovedInUpdatesToNbr");
10305 else if (CHECK_FLAG(p->af_flags[afi][safi],
10306 PEER_FLAG_REMOVE_PRIVATE_AS))
10307 json_object_boolean_true_add(
10308 json_addr,
10309 "privateAsNumsRemovedInUpdatesToNbr");
10310
dcc68b5e
MS
10311 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10312 json_object_boolean_true_add(
10313 json_addr,
10314 bgp_addpath_names(p->addpath_type[afi][safi])
10315 ->type_json_name);
d62a17ae 10316
10317 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10318 json_object_string_add(json_addr,
10319 "overrideASNsInOutboundUpdates",
10320 "ifAspathEqualRemoteAs");
10321
10322 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10323 || CHECK_FLAG(p->af_flags[afi][safi],
10324 PEER_FLAG_FORCE_NEXTHOP_SELF))
10325 json_object_boolean_true_add(json_addr,
10326 "routerAlwaysNextHop");
10327 if (CHECK_FLAG(p->af_flags[afi][safi],
10328 PEER_FLAG_AS_PATH_UNCHANGED))
10329 json_object_boolean_true_add(
10330 json_addr, "unchangedAsPathPropogatedToNbr");
10331 if (CHECK_FLAG(p->af_flags[afi][safi],
10332 PEER_FLAG_NEXTHOP_UNCHANGED))
10333 json_object_boolean_true_add(
10334 json_addr, "unchangedNextHopPropogatedToNbr");
10335 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10336 json_object_boolean_true_add(
10337 json_addr, "unchangedMedPropogatedToNbr");
10338 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10339 || CHECK_FLAG(p->af_flags[afi][safi],
10340 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10341 if (CHECK_FLAG(p->af_flags[afi][safi],
10342 PEER_FLAG_SEND_COMMUNITY)
10343 && CHECK_FLAG(p->af_flags[afi][safi],
10344 PEER_FLAG_SEND_EXT_COMMUNITY))
10345 json_object_string_add(json_addr,
10346 "commAttriSentToNbr",
10347 "extendedAndStandard");
10348 else if (CHECK_FLAG(p->af_flags[afi][safi],
10349 PEER_FLAG_SEND_EXT_COMMUNITY))
10350 json_object_string_add(json_addr,
10351 "commAttriSentToNbr",
10352 "extended");
10353 else
10354 json_object_string_add(json_addr,
10355 "commAttriSentToNbr",
10356 "standard");
10357 }
10358 if (CHECK_FLAG(p->af_flags[afi][safi],
10359 PEER_FLAG_DEFAULT_ORIGINATE)) {
10360 if (p->default_rmap[afi][safi].name)
10361 json_object_string_add(
10362 json_addr, "defaultRouteMap",
10363 p->default_rmap[afi][safi].name);
10364
10365 if (paf && PAF_SUBGRP(paf)
10366 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10367 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10368 json_object_boolean_true_add(json_addr,
10369 "defaultSent");
10370 else
10371 json_object_boolean_true_add(json_addr,
10372 "defaultNotSent");
10373 }
10374
dff8f48d 10375 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10376 if (is_evpn_enabled())
60466a63
QY
10377 json_object_boolean_true_add(
10378 json_addr, "advertiseAllVnis");
dff8f48d
MK
10379 }
10380
d62a17ae 10381 if (filter->plist[FILTER_IN].name
10382 || filter->dlist[FILTER_IN].name
10383 || filter->aslist[FILTER_IN].name
10384 || filter->map[RMAP_IN].name)
10385 json_object_boolean_true_add(json_addr,
10386 "inboundPathPolicyConfig");
10387 if (filter->plist[FILTER_OUT].name
10388 || filter->dlist[FILTER_OUT].name
10389 || filter->aslist[FILTER_OUT].name
10390 || filter->map[RMAP_OUT].name || filter->usmap.name)
10391 json_object_boolean_true_add(
10392 json_addr, "outboundPathPolicyConfig");
10393
10394 /* prefix-list */
10395 if (filter->plist[FILTER_IN].name)
10396 json_object_string_add(json_addr,
10397 "incomingUpdatePrefixFilterList",
10398 filter->plist[FILTER_IN].name);
10399 if (filter->plist[FILTER_OUT].name)
10400 json_object_string_add(json_addr,
10401 "outgoingUpdatePrefixFilterList",
10402 filter->plist[FILTER_OUT].name);
10403
10404 /* distribute-list */
10405 if (filter->dlist[FILTER_IN].name)
10406 json_object_string_add(
10407 json_addr, "incomingUpdateNetworkFilterList",
10408 filter->dlist[FILTER_IN].name);
10409 if (filter->dlist[FILTER_OUT].name)
10410 json_object_string_add(
10411 json_addr, "outgoingUpdateNetworkFilterList",
10412 filter->dlist[FILTER_OUT].name);
10413
10414 /* filter-list. */
10415 if (filter->aslist[FILTER_IN].name)
10416 json_object_string_add(json_addr,
10417 "incomingUpdateAsPathFilterList",
10418 filter->aslist[FILTER_IN].name);
10419 if (filter->aslist[FILTER_OUT].name)
10420 json_object_string_add(json_addr,
10421 "outgoingUpdateAsPathFilterList",
10422 filter->aslist[FILTER_OUT].name);
10423
10424 /* route-map. */
10425 if (filter->map[RMAP_IN].name)
10426 json_object_string_add(
10427 json_addr, "routeMapForIncomingAdvertisements",
10428 filter->map[RMAP_IN].name);
10429 if (filter->map[RMAP_OUT].name)
10430 json_object_string_add(
10431 json_addr, "routeMapForOutgoingAdvertisements",
10432 filter->map[RMAP_OUT].name);
10433
9dac9fc8 10434 /* ebgp-requires-policy (inbound) */
1d3fdccf 10435 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10436 && !bgp_inbound_policy_exists(p, filter))
10437 json_object_string_add(
10438 json_addr, "inboundEbgpRequiresPolicy",
10439 "Inbound updates discarded due to missing policy");
10440
10441 /* ebgp-requires-policy (outbound) */
1d3fdccf 10442 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10443 && (!bgp_outbound_policy_exists(p, filter)))
10444 json_object_string_add(
10445 json_addr, "outboundEbgpRequiresPolicy",
10446 "Outbound updates discarded due to missing policy");
10447
d62a17ae 10448 /* unsuppress-map */
10449 if (filter->usmap.name)
10450 json_object_string_add(json_addr,
10451 "selectiveUnsuppressRouteMap",
10452 filter->usmap.name);
10453
10454 /* Receive prefix count */
10455 json_object_int_add(json_addr, "acceptedPrefixCounter",
10456 p->pcount[afi][safi]);
50e05855
AD
10457 if (paf && PAF_SUBGRP(paf))
10458 json_object_int_add(json_addr, "sentPrefixCounter",
10459 (PAF_SUBGRP(paf))->scount);
d62a17ae 10460
fde246e8
DA
10461 /* Maximum prefix */
10462 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10463 json_object_int_add(json_addr, "prefixOutAllowedMax",
10464 p->pmax_out[afi][safi]);
10465
d62a17ae 10466 /* Maximum prefix */
10467 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10468 json_object_int_add(json_addr, "prefixAllowedMax",
10469 p->pmax[afi][safi]);
10470 if (CHECK_FLAG(p->af_flags[afi][safi],
10471 PEER_FLAG_MAX_PREFIX_WARNING))
10472 json_object_boolean_true_add(
10473 json_addr, "prefixAllowedMaxWarning");
10474 json_object_int_add(json_addr,
10475 "prefixAllowedWarningThresh",
10476 p->pmax_threshold[afi][safi]);
10477 if (p->pmax_restart[afi][safi])
10478 json_object_int_add(
10479 json_addr,
10480 "prefixAllowedRestartIntervalMsecs",
10481 p->pmax_restart[afi][safi] * 60000);
10482 }
2986cac2 10483 json_object_object_add(json_neigh,
36235319 10484 get_afi_safi_str(afi, safi, true),
d62a17ae 10485 json_addr);
10486
10487 } else {
10488 filter = &p->filter[afi][safi];
10489
10490 vty_out(vty, " For address family: %s\n",
5cb5f4d0 10491 get_afi_safi_str(afi, safi, false));
d62a17ae 10492
10493 if (peer_group_active(p))
10494 vty_out(vty, " %s peer-group member\n",
10495 p->group->name);
10496
10497 paf = peer_af_find(p, afi, safi);
10498 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 10499 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 10500 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10501 vty_out(vty, " Packet Queue length %d\n",
10502 bpacket_queue_virtual_length(paf));
10503 } else {
10504 vty_out(vty, " Not part of any update group\n");
10505 }
10506 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10507 || CHECK_FLAG(p->af_cap[afi][safi],
10508 PEER_CAP_ORF_PREFIX_SM_RCV)
10509 || CHECK_FLAG(p->af_cap[afi][safi],
10510 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10511 || CHECK_FLAG(p->af_cap[afi][safi],
10512 PEER_CAP_ORF_PREFIX_RM_ADV)
10513 || CHECK_FLAG(p->af_cap[afi][safi],
10514 PEER_CAP_ORF_PREFIX_RM_RCV)
10515 || CHECK_FLAG(p->af_cap[afi][safi],
10516 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10517 vty_out(vty, " AF-dependant capabilities:\n");
10518
10519 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10520 || CHECK_FLAG(p->af_cap[afi][safi],
10521 PEER_CAP_ORF_PREFIX_SM_RCV)
10522 || CHECK_FLAG(p->af_cap[afi][safi],
10523 PEER_CAP_ORF_PREFIX_RM_ADV)
10524 || CHECK_FLAG(p->af_cap[afi][safi],
10525 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10526 vty_out(vty,
10527 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10528 ORF_TYPE_PREFIX);
10529 bgp_show_peer_afi_orf_cap(
10530 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10531 PEER_CAP_ORF_PREFIX_RM_ADV,
10532 PEER_CAP_ORF_PREFIX_SM_RCV,
10533 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10534 }
10535 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10536 || CHECK_FLAG(p->af_cap[afi][safi],
10537 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10538 || CHECK_FLAG(p->af_cap[afi][safi],
10539 PEER_CAP_ORF_PREFIX_RM_ADV)
10540 || CHECK_FLAG(p->af_cap[afi][safi],
10541 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10542 vty_out(vty,
10543 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10544 ORF_TYPE_PREFIX_OLD);
10545 bgp_show_peer_afi_orf_cap(
10546 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10547 PEER_CAP_ORF_PREFIX_RM_ADV,
10548 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10549 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10550 }
10551
772270f3
QY
10552 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10553 p->host, afi, safi);
d62a17ae 10554 orf_pfx_count = prefix_bgp_show_prefix_list(
10555 NULL, afi, orf_pfx_name, use_json);
10556
10557 if (CHECK_FLAG(p->af_sflags[afi][safi],
10558 PEER_STATUS_ORF_PREFIX_SEND)
10559 || orf_pfx_count) {
10560 vty_out(vty, " Outbound Route Filter (ORF):");
10561 if (CHECK_FLAG(p->af_sflags[afi][safi],
10562 PEER_STATUS_ORF_PREFIX_SEND))
10563 vty_out(vty, " sent;");
10564 if (orf_pfx_count)
10565 vty_out(vty, " received (%d entries)",
10566 orf_pfx_count);
10567 vty_out(vty, "\n");
10568 }
10569 if (CHECK_FLAG(p->af_sflags[afi][safi],
10570 PEER_STATUS_ORF_WAIT_REFRESH))
10571 vty_out(vty,
10572 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10573
10574 if (CHECK_FLAG(p->af_flags[afi][safi],
10575 PEER_FLAG_REFLECTOR_CLIENT))
10576 vty_out(vty, " Route-Reflector Client\n");
10577 if (CHECK_FLAG(p->af_flags[afi][safi],
10578 PEER_FLAG_RSERVER_CLIENT))
10579 vty_out(vty, " Route-Server Client\n");
10580 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10581 vty_out(vty,
10582 " Inbound soft reconfiguration allowed\n");
10583
10584 if (CHECK_FLAG(p->af_flags[afi][safi],
10585 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10586 vty_out(vty,
10587 " Private AS numbers (all) replaced in updates to this neighbor\n");
10588 else if (CHECK_FLAG(p->af_flags[afi][safi],
10589 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10590 vty_out(vty,
10591 " Private AS numbers replaced in updates to this neighbor\n");
10592 else if (CHECK_FLAG(p->af_flags[afi][safi],
10593 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10594 vty_out(vty,
10595 " Private AS numbers (all) removed in updates to this neighbor\n");
10596 else if (CHECK_FLAG(p->af_flags[afi][safi],
10597 PEER_FLAG_REMOVE_PRIVATE_AS))
10598 vty_out(vty,
10599 " Private AS numbers removed in updates to this neighbor\n");
10600
dcc68b5e
MS
10601 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10602 vty_out(vty, " %s\n",
10603 bgp_addpath_names(p->addpath_type[afi][safi])
10604 ->human_description);
d62a17ae 10605
10606 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10607 vty_out(vty,
10608 " Override ASNs in outbound updates if aspath equals remote-as\n");
10609
10610 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10611 || CHECK_FLAG(p->af_flags[afi][safi],
10612 PEER_FLAG_FORCE_NEXTHOP_SELF))
10613 vty_out(vty, " NEXT_HOP is always this router\n");
10614 if (CHECK_FLAG(p->af_flags[afi][safi],
10615 PEER_FLAG_AS_PATH_UNCHANGED))
10616 vty_out(vty,
10617 " AS_PATH is propagated unchanged to this neighbor\n");
10618 if (CHECK_FLAG(p->af_flags[afi][safi],
10619 PEER_FLAG_NEXTHOP_UNCHANGED))
10620 vty_out(vty,
10621 " NEXT_HOP is propagated unchanged to this neighbor\n");
10622 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10623 vty_out(vty,
10624 " MED is propagated unchanged to this neighbor\n");
10625 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10626 || CHECK_FLAG(p->af_flags[afi][safi],
10627 PEER_FLAG_SEND_EXT_COMMUNITY)
10628 || CHECK_FLAG(p->af_flags[afi][safi],
10629 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10630 vty_out(vty,
10631 " Community attribute sent to this neighbor");
10632 if (CHECK_FLAG(p->af_flags[afi][safi],
10633 PEER_FLAG_SEND_COMMUNITY)
10634 && CHECK_FLAG(p->af_flags[afi][safi],
10635 PEER_FLAG_SEND_EXT_COMMUNITY)
10636 && CHECK_FLAG(p->af_flags[afi][safi],
10637 PEER_FLAG_SEND_LARGE_COMMUNITY))
10638 vty_out(vty, "(all)\n");
10639 else if (CHECK_FLAG(p->af_flags[afi][safi],
10640 PEER_FLAG_SEND_LARGE_COMMUNITY))
10641 vty_out(vty, "(large)\n");
10642 else if (CHECK_FLAG(p->af_flags[afi][safi],
10643 PEER_FLAG_SEND_EXT_COMMUNITY))
10644 vty_out(vty, "(extended)\n");
10645 else
10646 vty_out(vty, "(standard)\n");
10647 }
10648 if (CHECK_FLAG(p->af_flags[afi][safi],
10649 PEER_FLAG_DEFAULT_ORIGINATE)) {
10650 vty_out(vty, " Default information originate,");
10651
10652 if (p->default_rmap[afi][safi].name)
10653 vty_out(vty, " default route-map %s%s,",
10654 p->default_rmap[afi][safi].map ? "*"
10655 : "",
10656 p->default_rmap[afi][safi].name);
10657 if (paf && PAF_SUBGRP(paf)
10658 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10659 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10660 vty_out(vty, " default sent\n");
10661 else
10662 vty_out(vty, " default not sent\n");
10663 }
10664
dff8f48d
MK
10665 /* advertise-vni-all */
10666 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10667 if (is_evpn_enabled())
dff8f48d
MK
10668 vty_out(vty, " advertise-all-vni\n");
10669 }
10670
d62a17ae 10671 if (filter->plist[FILTER_IN].name
10672 || filter->dlist[FILTER_IN].name
10673 || filter->aslist[FILTER_IN].name
10674 || filter->map[RMAP_IN].name)
10675 vty_out(vty, " Inbound path policy configured\n");
10676 if (filter->plist[FILTER_OUT].name
10677 || filter->dlist[FILTER_OUT].name
10678 || filter->aslist[FILTER_OUT].name
10679 || filter->map[RMAP_OUT].name || filter->usmap.name)
10680 vty_out(vty, " Outbound path policy configured\n");
10681
10682 /* prefix-list */
10683 if (filter->plist[FILTER_IN].name)
10684 vty_out(vty,
10685 " Incoming update prefix filter list is %s%s\n",
10686 filter->plist[FILTER_IN].plist ? "*" : "",
10687 filter->plist[FILTER_IN].name);
10688 if (filter->plist[FILTER_OUT].name)
10689 vty_out(vty,
10690 " Outgoing update prefix filter list is %s%s\n",
10691 filter->plist[FILTER_OUT].plist ? "*" : "",
10692 filter->plist[FILTER_OUT].name);
10693
10694 /* distribute-list */
10695 if (filter->dlist[FILTER_IN].name)
10696 vty_out(vty,
10697 " Incoming update network filter list is %s%s\n",
10698 filter->dlist[FILTER_IN].alist ? "*" : "",
10699 filter->dlist[FILTER_IN].name);
10700 if (filter->dlist[FILTER_OUT].name)
10701 vty_out(vty,
10702 " Outgoing update network filter list is %s%s\n",
10703 filter->dlist[FILTER_OUT].alist ? "*" : "",
10704 filter->dlist[FILTER_OUT].name);
10705
10706 /* filter-list. */
10707 if (filter->aslist[FILTER_IN].name)
10708 vty_out(vty,
10709 " Incoming update AS path filter list is %s%s\n",
10710 filter->aslist[FILTER_IN].aslist ? "*" : "",
10711 filter->aslist[FILTER_IN].name);
10712 if (filter->aslist[FILTER_OUT].name)
10713 vty_out(vty,
10714 " Outgoing update AS path filter list is %s%s\n",
10715 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10716 filter->aslist[FILTER_OUT].name);
10717
10718 /* route-map. */
10719 if (filter->map[RMAP_IN].name)
10720 vty_out(vty,
10721 " Route map for incoming advertisements is %s%s\n",
10722 filter->map[RMAP_IN].map ? "*" : "",
10723 filter->map[RMAP_IN].name);
10724 if (filter->map[RMAP_OUT].name)
10725 vty_out(vty,
10726 " Route map for outgoing advertisements is %s%s\n",
10727 filter->map[RMAP_OUT].map ? "*" : "",
10728 filter->map[RMAP_OUT].name);
10729
9dac9fc8 10730 /* ebgp-requires-policy (inbound) */
1d3fdccf 10731 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10732 && !bgp_inbound_policy_exists(p, filter))
10733 vty_out(vty,
10734 " Inbound updates discarded due to missing policy\n");
10735
10736 /* ebgp-requires-policy (outbound) */
1d3fdccf 10737 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10738 && !bgp_outbound_policy_exists(p, filter))
10739 vty_out(vty,
10740 " Outbound updates discarded due to missing policy\n");
10741
d62a17ae 10742 /* unsuppress-map */
10743 if (filter->usmap.name)
10744 vty_out(vty,
10745 " Route map for selective unsuppress is %s%s\n",
10746 filter->usmap.map ? "*" : "",
10747 filter->usmap.name);
10748
10749 /* Receive prefix count */
6cde4b45 10750 vty_out(vty, " %u accepted prefixes\n",
a0a87037 10751 p->pcount[afi][safi]);
d62a17ae 10752
fde246e8
DA
10753 /* maximum-prefix-out */
10754 if (CHECK_FLAG(p->af_flags[afi][safi],
10755 PEER_FLAG_MAX_PREFIX_OUT))
10756 vty_out(vty,
6cde4b45 10757 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
10758 p->pmax_out[afi][safi]);
10759
d62a17ae 10760 /* Maximum prefix */
10761 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 10762 vty_out(vty,
6cde4b45 10763 " Maximum prefixes allowed %u%s\n",
d62a17ae 10764 p->pmax[afi][safi],
10765 CHECK_FLAG(p->af_flags[afi][safi],
10766 PEER_FLAG_MAX_PREFIX_WARNING)
10767 ? " (warning-only)"
10768 : "");
10769 vty_out(vty, " Threshold for warning message %d%%",
10770 p->pmax_threshold[afi][safi]);
10771 if (p->pmax_restart[afi][safi])
10772 vty_out(vty, ", restart interval %d min",
10773 p->pmax_restart[afi][safi]);
10774 vty_out(vty, "\n");
10775 }
10776
10777 vty_out(vty, "\n");
10778 }
10779}
10780
9f049418 10781static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 10782 json_object *json)
718e3744 10783{
d62a17ae 10784 struct bgp *bgp;
10785 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
10786 char timebuf[BGP_UPTIME_LEN];
10787 char dn_flag[2];
d62a17ae 10788 afi_t afi;
10789 safi_t safi;
d7c0a89a
QY
10790 uint16_t i;
10791 uint8_t *msg;
d62a17ae 10792 json_object *json_neigh = NULL;
10793 time_t epoch_tbuf;
718e3744 10794
d62a17ae 10795 bgp = p->bgp;
10796
10797 if (use_json)
10798 json_neigh = json_object_new_object();
10799
10800 memset(dn_flag, '\0', sizeof(dn_flag));
10801 if (!p->conf_if && peer_dynamic_neighbor(p))
10802 dn_flag[0] = '*';
10803
10804 if (!use_json) {
10805 if (p->conf_if) /* Configured interface name. */
10806 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
10807 BGP_PEER_SU_UNSPEC(p)
10808 ? "None"
10809 : sockunion2str(&p->su, buf,
10810 SU_ADDRSTRLEN));
10811 else /* Configured IP address. */
10812 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
10813 p->host);
10814 }
10815
10816 if (use_json) {
10817 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
10818 json_object_string_add(json_neigh, "bgpNeighborAddr",
10819 "none");
10820 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
10821 json_object_string_add(
10822 json_neigh, "bgpNeighborAddr",
10823 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
10824
10825 json_object_int_add(json_neigh, "remoteAs", p->as);
10826
10827 if (p->change_local_as)
10828 json_object_int_add(json_neigh, "localAs",
10829 p->change_local_as);
10830 else
10831 json_object_int_add(json_neigh, "localAs", p->local_as);
10832
10833 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
10834 json_object_boolean_true_add(json_neigh,
10835 "localAsNoPrepend");
10836
10837 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
10838 json_object_boolean_true_add(json_neigh,
10839 "localAsReplaceAs");
10840 } else {
10841 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
10842 || (p->as_type == AS_INTERNAL))
10843 vty_out(vty, "remote AS %u, ", p->as);
10844 else
10845 vty_out(vty, "remote AS Unspecified, ");
10846 vty_out(vty, "local AS %u%s%s, ",
10847 p->change_local_as ? p->change_local_as : p->local_as,
10848 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
10849 ? " no-prepend"
10850 : "",
10851 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
10852 ? " replace-as"
10853 : "");
10854 }
faa16034
DS
10855 /* peer type internal or confed-internal */
10856 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 10857 if (use_json) {
10858 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10859 json_object_boolean_true_add(
10860 json_neigh, "nbrConfedInternalLink");
10861 else
10862 json_object_boolean_true_add(json_neigh,
10863 "nbrInternalLink");
10864 } else {
10865 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10866 vty_out(vty, "confed-internal link\n");
10867 else
10868 vty_out(vty, "internal link\n");
10869 }
faa16034
DS
10870 /* peer type external or confed-external */
10871 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 10872 if (use_json) {
10873 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10874 json_object_boolean_true_add(
10875 json_neigh, "nbrConfedExternalLink");
10876 else
10877 json_object_boolean_true_add(json_neigh,
10878 "nbrExternalLink");
10879 } else {
10880 if (bgp_confederation_peers_check(bgp, p->as))
10881 vty_out(vty, "confed-external link\n");
10882 else
10883 vty_out(vty, "external link\n");
10884 }
faa16034
DS
10885 } else {
10886 if (use_json)
10887 json_object_boolean_true_add(json_neigh,
10888 "nbrUnspecifiedLink");
10889 else
10890 vty_out(vty, "unspecified link\n");
d62a17ae 10891 }
10892
10893 /* Description. */
10894 if (p->desc) {
10895 if (use_json)
10896 json_object_string_add(json_neigh, "nbrDesc", p->desc);
10897 else
10898 vty_out(vty, " Description: %s\n", p->desc);
10899 }
10900
10901 if (p->hostname) {
10902 if (use_json) {
10903 if (p->hostname)
10904 json_object_string_add(json_neigh, "hostname",
10905 p->hostname);
10906
10907 if (p->domainname)
10908 json_object_string_add(json_neigh, "domainname",
10909 p->domainname);
10910 } else {
10911 if (p->domainname && (p->domainname[0] != '\0'))
10912 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
10913 p->domainname);
10914 else
10915 vty_out(vty, "Hostname: %s\n", p->hostname);
10916 }
10917 }
10918
10919 /* Peer-group */
10920 if (p->group) {
10921 if (use_json) {
10922 json_object_string_add(json_neigh, "peerGroup",
10923 p->group->name);
10924
10925 if (dn_flag[0]) {
10926 struct prefix prefix, *range = NULL;
10927
10928 sockunion2hostprefix(&(p->su), &prefix);
10929 range = peer_group_lookup_dynamic_neighbor_range(
10930 p->group, &prefix);
10931
10932 if (range) {
10933 prefix2str(range, buf1, sizeof(buf1));
10934 json_object_string_add(
10935 json_neigh,
10936 "peerSubnetRangeGroup", buf1);
10937 }
10938 }
10939 } else {
10940 vty_out(vty,
10941 " Member of peer-group %s for session parameters\n",
10942 p->group->name);
10943
10944 if (dn_flag[0]) {
10945 struct prefix prefix, *range = NULL;
10946
10947 sockunion2hostprefix(&(p->su), &prefix);
10948 range = peer_group_lookup_dynamic_neighbor_range(
10949 p->group, &prefix);
10950
10951 if (range) {
d62a17ae 10952 vty_out(vty,
1b78780b
DL
10953 " Belongs to the subnet range group: %pFX\n",
10954 range);
d62a17ae 10955 }
10956 }
10957 }
10958 }
10959
10960 if (use_json) {
10961 /* Administrative shutdown. */
10962 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10963 json_object_boolean_true_add(json_neigh,
10964 "adminShutDown");
10965
10966 /* BGP Version. */
10967 json_object_int_add(json_neigh, "bgpVersion", 4);
10968 json_object_string_add(
10969 json_neigh, "remoteRouterId",
10970 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
10971 json_object_string_add(
10972 json_neigh, "localRouterId",
10973 inet_ntop(AF_INET, &bgp->router_id, buf1,
10974 sizeof(buf1)));
d62a17ae 10975
10976 /* Confederation */
10977 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10978 && bgp_confederation_peers_check(bgp, p->as))
10979 json_object_boolean_true_add(json_neigh,
10980 "nbrCommonAdmin");
10981
10982 /* Status. */
10983 json_object_string_add(
10984 json_neigh, "bgpState",
10985 lookup_msg(bgp_status_msg, p->status, NULL));
10986
10987 if (p->status == Established) {
10988 time_t uptime;
d62a17ae 10989
10990 uptime = bgp_clock();
10991 uptime -= p->uptime;
d62a17ae 10992 epoch_tbuf = time(NULL) - uptime;
10993
d3c7efed
DS
10994 json_object_int_add(json_neigh, "bgpTimerUpMsec",
10995 uptime * 1000);
d62a17ae 10996 json_object_string_add(json_neigh, "bgpTimerUpString",
10997 peer_uptime(p->uptime, timebuf,
10998 BGP_UPTIME_LEN, 0,
10999 NULL));
11000 json_object_int_add(json_neigh,
11001 "bgpTimerUpEstablishedEpoch",
11002 epoch_tbuf);
11003 }
11004
11005 else if (p->status == Active) {
11006 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11007 json_object_string_add(json_neigh, "bgpStateIs",
11008 "passive");
11009 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11010 json_object_string_add(json_neigh, "bgpStateIs",
11011 "passiveNSF");
11012 }
11013
11014 /* read timer */
11015 time_t uptime;
a2700b50 11016 struct tm tm;
d62a17ae 11017
11018 uptime = bgp_clock();
11019 uptime -= p->readtime;
a2700b50
MS
11020 gmtime_r(&uptime, &tm);
11021
d62a17ae 11022 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
11023 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11024 + (tm.tm_hour * 3600000));
d62a17ae 11025
11026 uptime = bgp_clock();
11027 uptime -= p->last_write;
a2700b50
MS
11028 gmtime_r(&uptime, &tm);
11029
d62a17ae 11030 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
11031 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11032 + (tm.tm_hour * 3600000));
d62a17ae 11033
11034 uptime = bgp_clock();
11035 uptime -= p->update_time;
a2700b50
MS
11036 gmtime_r(&uptime, &tm);
11037
d62a17ae 11038 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
11039 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11040 + (tm.tm_hour * 3600000));
d62a17ae 11041
11042 /* Configured timer values. */
11043 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
11044 p->v_holdtime * 1000);
11045 json_object_int_add(json_neigh,
11046 "bgpTimerKeepAliveIntervalMsecs",
11047 p->v_keepalive * 1000);
b90a8e13 11048 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11049 json_object_int_add(json_neigh,
11050 "bgpTimerConfiguredHoldTimeMsecs",
11051 p->holdtime * 1000);
11052 json_object_int_add(
11053 json_neigh,
11054 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11055 p->keepalive * 1000);
5d5393b9
DL
11056 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11057 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11058 json_object_int_add(json_neigh,
11059 "bgpTimerConfiguredHoldTimeMsecs",
11060 bgp->default_holdtime);
11061 json_object_int_add(
11062 json_neigh,
11063 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11064 bgp->default_keepalive);
d62a17ae 11065 }
11066 } else {
11067 /* Administrative shutdown. */
11068 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
11069 vty_out(vty, " Administratively shut down\n");
11070
11071 /* BGP Version. */
11072 vty_out(vty, " BGP version 4");
0e38aeb4 11073 vty_out(vty, ", remote router ID %s",
d62a17ae 11074 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
11075 vty_out(vty, ", local router ID %s\n",
11076 inet_ntop(AF_INET, &bgp->router_id, buf1,
11077 sizeof(buf1)));
d62a17ae 11078
11079 /* Confederation */
11080 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11081 && bgp_confederation_peers_check(bgp, p->as))
11082 vty_out(vty,
11083 " Neighbor under common administration\n");
11084
11085 /* Status. */
11086 vty_out(vty, " BGP state = %s",
11087 lookup_msg(bgp_status_msg, p->status, NULL));
11088
11089 if (p->status == Established)
11090 vty_out(vty, ", up for %8s",
11091 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
11092 0, NULL));
11093
11094 else if (p->status == Active) {
11095 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11096 vty_out(vty, " (passive)");
11097 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11098 vty_out(vty, " (NSF passive)");
11099 }
11100 vty_out(vty, "\n");
11101
11102 /* read timer */
11103 vty_out(vty, " Last read %s",
11104 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
11105 NULL));
11106 vty_out(vty, ", Last write %s\n",
11107 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
11108 NULL));
11109
11110 /* Configured timer values. */
11111 vty_out(vty,
11112 " Hold time is %d, keepalive interval is %d seconds\n",
11113 p->v_holdtime, p->v_keepalive);
b90a8e13 11114 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11115 vty_out(vty, " Configured hold time is %d",
11116 p->holdtime);
11117 vty_out(vty, ", keepalive interval is %d seconds\n",
11118 p->keepalive);
5d5393b9
DL
11119 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11120 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11121 vty_out(vty, " Configured hold time is %d",
11122 bgp->default_holdtime);
11123 vty_out(vty, ", keepalive interval is %d seconds\n",
11124 bgp->default_keepalive);
d62a17ae 11125 }
11126 }
11127 /* Capability. */
11128 if (p->status == Established) {
11129 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
11130 || p->afc_recv[AFI_IP][SAFI_UNICAST]
11131 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
11132 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
11133 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
11134 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
11135 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
11136 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
11137 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
11138 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
11139 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
11140 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 11141 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
11142 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 11143 || p->afc_adv[AFI_IP][SAFI_ENCAP]
11144 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 11145 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
11146 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 11147 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
11148 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
11149 if (use_json) {
11150 json_object *json_cap = NULL;
11151
11152 json_cap = json_object_new_object();
11153
11154 /* AS4 */
11155 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11156 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11157 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
11158 && CHECK_FLAG(p->cap,
11159 PEER_CAP_AS4_RCV))
11160 json_object_string_add(
11161 json_cap, "4byteAs",
11162 "advertisedAndReceived");
11163 else if (CHECK_FLAG(p->cap,
11164 PEER_CAP_AS4_ADV))
11165 json_object_string_add(
11166 json_cap, "4byteAs",
11167 "advertised");
11168 else if (CHECK_FLAG(p->cap,
11169 PEER_CAP_AS4_RCV))
11170 json_object_string_add(
11171 json_cap, "4byteAs",
11172 "received");
11173 }
11174
11175 /* AddPath */
11176 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11177 || CHECK_FLAG(p->cap,
11178 PEER_CAP_ADDPATH_ADV)) {
11179 json_object *json_add = NULL;
11180 const char *print_store;
11181
11182 json_add = json_object_new_object();
11183
05c7a1cc
QY
11184 FOREACH_AFI_SAFI (afi, safi) {
11185 json_object *json_sub = NULL;
11186 json_sub =
11187 json_object_new_object();
5cb5f4d0
DD
11188 print_store = get_afi_safi_str(
11189 afi, safi, true);
d62a17ae 11190
05c7a1cc
QY
11191 if (CHECK_FLAG(
11192 p->af_cap[afi]
11193 [safi],
11194 PEER_CAP_ADDPATH_AF_TX_ADV)
11195 || CHECK_FLAG(
11196 p->af_cap[afi]
11197 [safi],
11198 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 11199 if (CHECK_FLAG(
11200 p->af_cap
11201 [afi]
11202 [safi],
11203 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 11204 && CHECK_FLAG(
d62a17ae 11205 p->af_cap
11206 [afi]
11207 [safi],
05c7a1cc
QY
11208 PEER_CAP_ADDPATH_AF_TX_RCV))
11209 json_object_boolean_true_add(
11210 json_sub,
11211 "txAdvertisedAndReceived");
11212 else if (
11213 CHECK_FLAG(
11214 p->af_cap
11215 [afi]
11216 [safi],
11217 PEER_CAP_ADDPATH_AF_TX_ADV))
11218 json_object_boolean_true_add(
11219 json_sub,
11220 "txAdvertised");
11221 else if (
11222 CHECK_FLAG(
11223 p->af_cap
11224 [afi]
11225 [safi],
11226 PEER_CAP_ADDPATH_AF_TX_RCV))
11227 json_object_boolean_true_add(
11228 json_sub,
11229 "txReceived");
11230 }
d62a17ae 11231
05c7a1cc
QY
11232 if (CHECK_FLAG(
11233 p->af_cap[afi]
11234 [safi],
11235 PEER_CAP_ADDPATH_AF_RX_ADV)
11236 || CHECK_FLAG(
11237 p->af_cap[afi]
11238 [safi],
11239 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 11240 if (CHECK_FLAG(
11241 p->af_cap
11242 [afi]
11243 [safi],
11244 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 11245 && CHECK_FLAG(
d62a17ae 11246 p->af_cap
11247 [afi]
11248 [safi],
11249 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
11250 json_object_boolean_true_add(
11251 json_sub,
11252 "rxAdvertisedAndReceived");
11253 else if (
11254 CHECK_FLAG(
11255 p->af_cap
11256 [afi]
11257 [safi],
11258 PEER_CAP_ADDPATH_AF_RX_ADV))
11259 json_object_boolean_true_add(
11260 json_sub,
11261 "rxAdvertised");
11262 else if (
11263 CHECK_FLAG(
11264 p->af_cap
11265 [afi]
11266 [safi],
11267 PEER_CAP_ADDPATH_AF_RX_RCV))
11268 json_object_boolean_true_add(
11269 json_sub,
11270 "rxReceived");
d62a17ae 11271 }
11272
05c7a1cc
QY
11273 if (CHECK_FLAG(
11274 p->af_cap[afi]
11275 [safi],
11276 PEER_CAP_ADDPATH_AF_TX_ADV)
11277 || CHECK_FLAG(
11278 p->af_cap[afi]
11279 [safi],
11280 PEER_CAP_ADDPATH_AF_TX_RCV)
11281 || CHECK_FLAG(
11282 p->af_cap[afi]
11283 [safi],
11284 PEER_CAP_ADDPATH_AF_RX_ADV)
11285 || CHECK_FLAG(
11286 p->af_cap[afi]
11287 [safi],
11288 PEER_CAP_ADDPATH_AF_RX_RCV))
11289 json_object_object_add(
11290 json_add,
11291 print_store,
11292 json_sub);
11293 else
11294 json_object_free(
11295 json_sub);
11296 }
11297
d62a17ae 11298 json_object_object_add(
11299 json_cap, "addPath", json_add);
11300 }
11301
11302 /* Dynamic */
11303 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11304 || CHECK_FLAG(p->cap,
11305 PEER_CAP_DYNAMIC_ADV)) {
11306 if (CHECK_FLAG(p->cap,
11307 PEER_CAP_DYNAMIC_ADV)
11308 && CHECK_FLAG(p->cap,
11309 PEER_CAP_DYNAMIC_RCV))
11310 json_object_string_add(
11311 json_cap, "dynamic",
11312 "advertisedAndReceived");
11313 else if (CHECK_FLAG(
11314 p->cap,
11315 PEER_CAP_DYNAMIC_ADV))
11316 json_object_string_add(
11317 json_cap, "dynamic",
11318 "advertised");
11319 else if (CHECK_FLAG(
11320 p->cap,
11321 PEER_CAP_DYNAMIC_RCV))
11322 json_object_string_add(
11323 json_cap, "dynamic",
11324 "received");
11325 }
11326
11327 /* Extended nexthop */
11328 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11329 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11330 json_object *json_nxt = NULL;
11331 const char *print_store;
11332
11333
11334 if (CHECK_FLAG(p->cap,
11335 PEER_CAP_ENHE_ADV)
11336 && CHECK_FLAG(p->cap,
11337 PEER_CAP_ENHE_RCV))
11338 json_object_string_add(
11339 json_cap,
11340 "extendedNexthop",
11341 "advertisedAndReceived");
11342 else if (CHECK_FLAG(p->cap,
11343 PEER_CAP_ENHE_ADV))
11344 json_object_string_add(
11345 json_cap,
11346 "extendedNexthop",
11347 "advertised");
11348 else if (CHECK_FLAG(p->cap,
11349 PEER_CAP_ENHE_RCV))
11350 json_object_string_add(
11351 json_cap,
11352 "extendedNexthop",
11353 "received");
11354
11355 if (CHECK_FLAG(p->cap,
11356 PEER_CAP_ENHE_RCV)) {
11357 json_nxt =
11358 json_object_new_object();
11359
11360 for (safi = SAFI_UNICAST;
11361 safi < SAFI_MAX; safi++) {
11362 if (CHECK_FLAG(
11363 p->af_cap
11364 [AFI_IP]
11365 [safi],
11366 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 11367 print_store = get_afi_safi_str(
d62a17ae 11368 AFI_IP,
5cb5f4d0 11369 safi, true);
d62a17ae 11370 json_object_string_add(
11371 json_nxt,
11372 print_store,
54f29523 11373 "recieved"); /* misspelled for compatibility */
d62a17ae 11374 }
11375 }
11376 json_object_object_add(
11377 json_cap,
11378 "extendedNexthopFamililesByPeer",
11379 json_nxt);
11380 }
11381 }
11382
11383 /* Route Refresh */
11384 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11385 || CHECK_FLAG(p->cap,
11386 PEER_CAP_REFRESH_NEW_RCV)
11387 || CHECK_FLAG(p->cap,
11388 PEER_CAP_REFRESH_OLD_RCV)) {
11389 if (CHECK_FLAG(p->cap,
11390 PEER_CAP_REFRESH_ADV)
11391 && (CHECK_FLAG(
11392 p->cap,
11393 PEER_CAP_REFRESH_NEW_RCV)
11394 || CHECK_FLAG(
11395 p->cap,
11396 PEER_CAP_REFRESH_OLD_RCV))) {
11397 if (CHECK_FLAG(
11398 p->cap,
11399 PEER_CAP_REFRESH_OLD_RCV)
11400 && CHECK_FLAG(
11401 p->cap,
11402 PEER_CAP_REFRESH_NEW_RCV))
11403 json_object_string_add(
11404 json_cap,
11405 "routeRefresh",
11406 "advertisedAndReceivedOldNew");
11407 else {
11408 if (CHECK_FLAG(
11409 p->cap,
11410 PEER_CAP_REFRESH_OLD_RCV))
11411 json_object_string_add(
11412 json_cap,
11413 "routeRefresh",
11414 "advertisedAndReceivedOld");
11415 else
11416 json_object_string_add(
11417 json_cap,
11418 "routeRefresh",
11419 "advertisedAndReceivedNew");
11420 }
11421 } else if (
11422 CHECK_FLAG(
11423 p->cap,
11424 PEER_CAP_REFRESH_ADV))
11425 json_object_string_add(
11426 json_cap,
11427 "routeRefresh",
11428 "advertised");
11429 else if (
11430 CHECK_FLAG(
11431 p->cap,
11432 PEER_CAP_REFRESH_NEW_RCV)
11433 || CHECK_FLAG(
11434 p->cap,
11435 PEER_CAP_REFRESH_OLD_RCV))
11436 json_object_string_add(
11437 json_cap,
11438 "routeRefresh",
11439 "received");
11440 }
11441
11442 /* Multiprotocol Extensions */
11443 json_object *json_multi = NULL;
11444 json_multi = json_object_new_object();
11445
05c7a1cc
QY
11446 FOREACH_AFI_SAFI (afi, safi) {
11447 if (p->afc_adv[afi][safi]
11448 || p->afc_recv[afi][safi]) {
11449 json_object *json_exten = NULL;
11450 json_exten =
11451 json_object_new_object();
11452
d62a17ae 11453 if (p->afc_adv[afi][safi]
05c7a1cc
QY
11454 && p->afc_recv[afi][safi])
11455 json_object_boolean_true_add(
11456 json_exten,
11457 "advertisedAndReceived");
11458 else if (p->afc_adv[afi][safi])
11459 json_object_boolean_true_add(
11460 json_exten,
11461 "advertised");
11462 else if (p->afc_recv[afi][safi])
11463 json_object_boolean_true_add(
11464 json_exten,
11465 "received");
d62a17ae 11466
05c7a1cc
QY
11467 json_object_object_add(
11468 json_multi,
5cb5f4d0
DD
11469 get_afi_safi_str(afi,
11470 safi,
11471 true),
05c7a1cc 11472 json_exten);
d62a17ae 11473 }
11474 }
11475 json_object_object_add(
11476 json_cap, "multiprotocolExtensions",
11477 json_multi);
11478
d77114b7 11479 /* Hostname capabilities */
60466a63 11480 json_object *json_hname = NULL;
d77114b7
MK
11481
11482 json_hname = json_object_new_object();
11483
11484 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11485 json_object_string_add(
60466a63
QY
11486 json_hname, "advHostName",
11487 bgp->peer_self->hostname
11488 ? bgp->peer_self
11489 ->hostname
d77114b7
MK
11490 : "n/a");
11491 json_object_string_add(
60466a63
QY
11492 json_hname, "advDomainName",
11493 bgp->peer_self->domainname
11494 ? bgp->peer_self
11495 ->domainname
d77114b7
MK
11496 : "n/a");
11497 }
11498
11499
11500 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11501 json_object_string_add(
60466a63
QY
11502 json_hname, "rcvHostName",
11503 p->hostname ? p->hostname
11504 : "n/a");
d77114b7 11505 json_object_string_add(
60466a63
QY
11506 json_hname, "rcvDomainName",
11507 p->domainname ? p->domainname
11508 : "n/a");
d77114b7
MK
11509 }
11510
60466a63 11511 json_object_object_add(json_cap, "hostName",
d77114b7
MK
11512 json_hname);
11513
d62a17ae 11514 /* Gracefull Restart */
11515 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11516 || CHECK_FLAG(p->cap,
11517 PEER_CAP_RESTART_ADV)) {
11518 if (CHECK_FLAG(p->cap,
11519 PEER_CAP_RESTART_ADV)
11520 && CHECK_FLAG(p->cap,
11521 PEER_CAP_RESTART_RCV))
11522 json_object_string_add(
11523 json_cap,
11524 "gracefulRestart",
11525 "advertisedAndReceived");
11526 else if (CHECK_FLAG(
11527 p->cap,
11528 PEER_CAP_RESTART_ADV))
11529 json_object_string_add(
11530 json_cap,
11531 "gracefulRestartCapability",
11532 "advertised");
11533 else if (CHECK_FLAG(
11534 p->cap,
11535 PEER_CAP_RESTART_RCV))
11536 json_object_string_add(
11537 json_cap,
11538 "gracefulRestartCapability",
11539 "received");
11540
11541 if (CHECK_FLAG(p->cap,
11542 PEER_CAP_RESTART_RCV)) {
11543 int restart_af_count = 0;
11544 json_object *json_restart =
11545 NULL;
11546 json_restart =
11547 json_object_new_object();
11548
11549 json_object_int_add(
11550 json_cap,
11551 "gracefulRestartRemoteTimerMsecs",
11552 p->v_gr_restart * 1000);
11553
05c7a1cc
QY
11554 FOREACH_AFI_SAFI (afi, safi) {
11555 if (CHECK_FLAG(
11556 p->af_cap
11557 [afi]
11558 [safi],
11559 PEER_CAP_RESTART_AF_RCV)) {
11560 json_object *
11561 json_sub =
11562 NULL;
11563 json_sub =
11564 json_object_new_object();
11565
d62a17ae 11566 if (CHECK_FLAG(
11567 p->af_cap
11568 [afi]
11569 [safi],
05c7a1cc
QY
11570 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11571 json_object_boolean_true_add(
11572 json_sub,
11573 "preserved");
11574 restart_af_count++;
11575 json_object_object_add(
11576 json_restart,
5cb5f4d0 11577 get_afi_safi_str(
05c7a1cc 11578 afi,
5cb5f4d0
DD
11579 safi,
11580 true),
05c7a1cc 11581 json_sub);
d62a17ae 11582 }
11583 }
11584 if (!restart_af_count) {
11585 json_object_string_add(
11586 json_cap,
11587 "addressFamiliesByPeer",
11588 "none");
11589 json_object_free(
11590 json_restart);
11591 } else
11592 json_object_object_add(
11593 json_cap,
11594 "addressFamiliesByPeer",
11595 json_restart);
11596 }
11597 }
11598 json_object_object_add(json_neigh,
11599 "neighborCapabilities",
11600 json_cap);
11601 } else {
11602 vty_out(vty, " Neighbor capabilities:\n");
11603
11604 /* AS4 */
11605 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11606 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11607 vty_out(vty, " 4 Byte AS:");
11608 if (CHECK_FLAG(p->cap,
11609 PEER_CAP_AS4_ADV))
11610 vty_out(vty, " advertised");
11611 if (CHECK_FLAG(p->cap,
11612 PEER_CAP_AS4_RCV))
11613 vty_out(vty, " %sreceived",
11614 CHECK_FLAG(
11615 p->cap,
11616 PEER_CAP_AS4_ADV)
11617 ? "and "
11618 : "");
11619 vty_out(vty, "\n");
11620 }
11621
11622 /* AddPath */
11623 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11624 || CHECK_FLAG(p->cap,
11625 PEER_CAP_ADDPATH_ADV)) {
11626 vty_out(vty, " AddPath:\n");
11627
05c7a1cc
QY
11628 FOREACH_AFI_SAFI (afi, safi) {
11629 if (CHECK_FLAG(
11630 p->af_cap[afi]
11631 [safi],
11632 PEER_CAP_ADDPATH_AF_TX_ADV)
11633 || CHECK_FLAG(
11634 p->af_cap[afi]
11635 [safi],
11636 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11637 vty_out(vty,
11638 " %s: TX ",
5cb5f4d0 11639 get_afi_safi_str(
05c7a1cc 11640 afi,
5cb5f4d0
DD
11641 safi,
11642 false));
05c7a1cc 11643
d62a17ae 11644 if (CHECK_FLAG(
11645 p->af_cap
11646 [afi]
11647 [safi],
05c7a1cc 11648 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 11649 vty_out(vty,
05c7a1cc 11650 "advertised %s",
5cb5f4d0 11651 get_afi_safi_str(
d62a17ae 11652 afi,
5cb5f4d0
DD
11653 safi,
11654 false));
d62a17ae 11655
05c7a1cc
QY
11656 if (CHECK_FLAG(
11657 p->af_cap
11658 [afi]
11659 [safi],
11660 PEER_CAP_ADDPATH_AF_TX_RCV))
11661 vty_out(vty,
11662 "%sreceived",
11663 CHECK_FLAG(
11664 p->af_cap
11665 [afi]
11666 [safi],
11667 PEER_CAP_ADDPATH_AF_TX_ADV)
11668 ? " and "
11669 : "");
d62a17ae 11670
05c7a1cc
QY
11671 vty_out(vty, "\n");
11672 }
d62a17ae 11673
05c7a1cc
QY
11674 if (CHECK_FLAG(
11675 p->af_cap[afi]
11676 [safi],
11677 PEER_CAP_ADDPATH_AF_RX_ADV)
11678 || CHECK_FLAG(
11679 p->af_cap[afi]
11680 [safi],
11681 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11682 vty_out(vty,
11683 " %s: RX ",
5cb5f4d0 11684 get_afi_safi_str(
05c7a1cc 11685 afi,
5cb5f4d0
DD
11686 safi,
11687 false));
d62a17ae 11688
11689 if (CHECK_FLAG(
11690 p->af_cap
11691 [afi]
11692 [safi],
05c7a1cc 11693 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 11694 vty_out(vty,
05c7a1cc 11695 "advertised %s",
5cb5f4d0 11696 get_afi_safi_str(
d62a17ae 11697 afi,
5cb5f4d0
DD
11698 safi,
11699 false));
d62a17ae 11700
05c7a1cc
QY
11701 if (CHECK_FLAG(
11702 p->af_cap
11703 [afi]
11704 [safi],
11705 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 11706 vty_out(vty,
05c7a1cc
QY
11707 "%sreceived",
11708 CHECK_FLAG(
11709 p->af_cap
11710 [afi]
11711 [safi],
11712 PEER_CAP_ADDPATH_AF_RX_ADV)
11713 ? " and "
11714 : "");
11715
11716 vty_out(vty, "\n");
d62a17ae 11717 }
05c7a1cc 11718 }
d62a17ae 11719 }
11720
11721 /* Dynamic */
11722 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11723 || CHECK_FLAG(p->cap,
11724 PEER_CAP_DYNAMIC_ADV)) {
11725 vty_out(vty, " Dynamic:");
11726 if (CHECK_FLAG(p->cap,
11727 PEER_CAP_DYNAMIC_ADV))
11728 vty_out(vty, " advertised");
11729 if (CHECK_FLAG(p->cap,
11730 PEER_CAP_DYNAMIC_RCV))
11731 vty_out(vty, " %sreceived",
11732 CHECK_FLAG(
11733 p->cap,
11734 PEER_CAP_DYNAMIC_ADV)
11735 ? "and "
11736 : "");
11737 vty_out(vty, "\n");
11738 }
11739
11740 /* Extended nexthop */
11741 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11742 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11743 vty_out(vty, " Extended nexthop:");
11744 if (CHECK_FLAG(p->cap,
11745 PEER_CAP_ENHE_ADV))
11746 vty_out(vty, " advertised");
11747 if (CHECK_FLAG(p->cap,
11748 PEER_CAP_ENHE_RCV))
11749 vty_out(vty, " %sreceived",
11750 CHECK_FLAG(
11751 p->cap,
11752 PEER_CAP_ENHE_ADV)
11753 ? "and "
11754 : "");
11755 vty_out(vty, "\n");
11756
11757 if (CHECK_FLAG(p->cap,
11758 PEER_CAP_ENHE_RCV)) {
11759 vty_out(vty,
11760 " Address families by peer:\n ");
11761 for (safi = SAFI_UNICAST;
11762 safi < SAFI_MAX; safi++)
11763 if (CHECK_FLAG(
11764 p->af_cap
11765 [AFI_IP]
11766 [safi],
11767 PEER_CAP_ENHE_AF_RCV))
11768 vty_out(vty,
11769 " %s\n",
5cb5f4d0 11770 get_afi_safi_str(
d62a17ae 11771 AFI_IP,
5cb5f4d0
DD
11772 safi,
11773 false));
d62a17ae 11774 }
11775 }
11776
11777 /* Route Refresh */
11778 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11779 || CHECK_FLAG(p->cap,
11780 PEER_CAP_REFRESH_NEW_RCV)
11781 || CHECK_FLAG(p->cap,
11782 PEER_CAP_REFRESH_OLD_RCV)) {
11783 vty_out(vty, " Route refresh:");
11784 if (CHECK_FLAG(p->cap,
11785 PEER_CAP_REFRESH_ADV))
11786 vty_out(vty, " advertised");
11787 if (CHECK_FLAG(p->cap,
11788 PEER_CAP_REFRESH_NEW_RCV)
11789 || CHECK_FLAG(
11790 p->cap,
11791 PEER_CAP_REFRESH_OLD_RCV))
11792 vty_out(vty, " %sreceived(%s)",
11793 CHECK_FLAG(
11794 p->cap,
11795 PEER_CAP_REFRESH_ADV)
11796 ? "and "
11797 : "",
11798 (CHECK_FLAG(
11799 p->cap,
11800 PEER_CAP_REFRESH_OLD_RCV)
11801 && CHECK_FLAG(
11802 p->cap,
11803 PEER_CAP_REFRESH_NEW_RCV))
11804 ? "old & new"
11805 : CHECK_FLAG(
11806 p->cap,
11807 PEER_CAP_REFRESH_OLD_RCV)
11808 ? "old"
11809 : "new");
11810
11811 vty_out(vty, "\n");
11812 }
11813
11814 /* Multiprotocol Extensions */
05c7a1cc
QY
11815 FOREACH_AFI_SAFI (afi, safi)
11816 if (p->afc_adv[afi][safi]
11817 || p->afc_recv[afi][safi]) {
11818 vty_out(vty,
11819 " Address Family %s:",
5cb5f4d0
DD
11820 get_afi_safi_str(
11821 afi,
11822 safi,
11823 false));
05c7a1cc 11824 if (p->afc_adv[afi][safi])
d62a17ae 11825 vty_out(vty,
05c7a1cc
QY
11826 " advertised");
11827 if (p->afc_recv[afi][safi])
11828 vty_out(vty,
11829 " %sreceived",
11830 p->afc_adv[afi]
11831 [safi]
11832 ? "and "
11833 : "");
11834 vty_out(vty, "\n");
11835 }
d62a17ae 11836
11837 /* Hostname capability */
60466a63 11838 vty_out(vty, " Hostname Capability:");
d77114b7
MK
11839
11840 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
11841 vty_out(vty,
11842 " advertised (name: %s,domain name: %s)",
60466a63
QY
11843 bgp->peer_self->hostname
11844 ? bgp->peer_self
11845 ->hostname
d77114b7 11846 : "n/a",
60466a63
QY
11847 bgp->peer_self->domainname
11848 ? bgp->peer_self
11849 ->domainname
d77114b7
MK
11850 : "n/a");
11851 } else {
11852 vty_out(vty, " not advertised");
d62a17ae 11853 }
11854
d77114b7 11855 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
11856 vty_out(vty,
11857 " received (name: %s,domain name: %s)",
60466a63
QY
11858 p->hostname ? p->hostname
11859 : "n/a",
11860 p->domainname ? p->domainname
11861 : "n/a");
d77114b7
MK
11862 } else {
11863 vty_out(vty, " not received");
11864 }
11865
11866 vty_out(vty, "\n");
11867
61bfbd51 11868 /* Graceful Restart */
d62a17ae 11869 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11870 || CHECK_FLAG(p->cap,
11871 PEER_CAP_RESTART_ADV)) {
11872 vty_out(vty,
61bfbd51 11873 " Graceful Restart Capability:");
d62a17ae 11874 if (CHECK_FLAG(p->cap,
11875 PEER_CAP_RESTART_ADV))
11876 vty_out(vty, " advertised");
11877 if (CHECK_FLAG(p->cap,
11878 PEER_CAP_RESTART_RCV))
11879 vty_out(vty, " %sreceived",
11880 CHECK_FLAG(
11881 p->cap,
11882 PEER_CAP_RESTART_ADV)
11883 ? "and "
11884 : "");
11885 vty_out(vty, "\n");
11886
11887 if (CHECK_FLAG(p->cap,
11888 PEER_CAP_RESTART_RCV)) {
11889 int restart_af_count = 0;
11890
11891 vty_out(vty,
11892 " Remote Restart timer is %d seconds\n",
11893 p->v_gr_restart);
11894 vty_out(vty,
11895 " Address families by peer:\n ");
11896
05c7a1cc
QY
11897 FOREACH_AFI_SAFI (afi, safi)
11898 if (CHECK_FLAG(
11899 p->af_cap
11900 [afi]
11901 [safi],
11902 PEER_CAP_RESTART_AF_RCV)) {
11903 vty_out(vty,
11904 "%s%s(%s)",
11905 restart_af_count
11906 ? ", "
11907 : "",
5cb5f4d0 11908 get_afi_safi_str(
05c7a1cc 11909 afi,
5cb5f4d0
DD
11910 safi,
11911 false),
05c7a1cc
QY
11912 CHECK_FLAG(
11913 p->af_cap
11914 [afi]
11915 [safi],
11916 PEER_CAP_RESTART_AF_PRESERVE_RCV)
11917 ? "preserved"
11918 : "not preserved");
11919 restart_af_count++;
11920 }
d62a17ae 11921 if (!restart_af_count)
11922 vty_out(vty, "none");
11923 vty_out(vty, "\n");
11924 }
2986cac2 11925 } /* Gracefull Restart */
d62a17ae 11926 }
11927 }
11928 }
11929
11930 /* graceful restart information */
d62a17ae 11931 json_object *json_grace = NULL;
11932 json_object *json_grace_send = NULL;
11933 json_object *json_grace_recv = NULL;
11934 int eor_send_af_count = 0;
11935 int eor_receive_af_count = 0;
11936
11937 if (use_json) {
11938 json_grace = json_object_new_object();
11939 json_grace_send = json_object_new_object();
11940 json_grace_recv = json_object_new_object();
11941
36235319
QY
11942 if ((p->status == Established)
11943 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
11944 FOREACH_AFI_SAFI (afi, safi) {
11945 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 11946 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
11947 json_object_boolean_true_add(
11948 json_grace_send,
5cb5f4d0
DD
11949 get_afi_safi_str(afi,
11950 safi,
11951 true));
05c7a1cc 11952 eor_send_af_count++;
d62a17ae 11953 }
11954 }
05c7a1cc
QY
11955 FOREACH_AFI_SAFI (afi, safi) {
11956 if (CHECK_FLAG(
36235319
QY
11957 p->af_sflags[afi][safi],
11958 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
11959 json_object_boolean_true_add(
11960 json_grace_recv,
5cb5f4d0
DD
11961 get_afi_safi_str(afi,
11962 safi,
11963 true));
05c7a1cc 11964 eor_receive_af_count++;
d62a17ae 11965 }
11966 }
11967 }
36235319
QY
11968 json_object_object_add(json_grace, "endOfRibSend",
11969 json_grace_send);
11970 json_object_object_add(json_grace, "endOfRibRecv",
11971 json_grace_recv);
d62a17ae 11972
d62a17ae 11973
11974 if (p->t_gr_restart)
11975 json_object_int_add(json_grace,
11976 "gracefulRestartTimerMsecs",
11977 thread_timer_remain_second(
11978 p->t_gr_restart)
11979 * 1000);
11980
11981 if (p->t_gr_stale)
11982 json_object_int_add(
11983 json_grace,
11984 "gracefulStalepathTimerMsecs",
11985 thread_timer_remain_second(
11986 p->t_gr_stale)
11987 * 1000);
2986cac2 11988 /* more gr info in new format */
11989 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 11990 json_grace);
d62a17ae 11991 json_object_object_add(
11992 json_neigh, "gracefulRestartInfo", json_grace);
11993 } else {
2089dd80 11994 vty_out(vty, " Graceful restart information:\n");
36235319
QY
11995 if ((p->status == Established)
11996 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11997
d62a17ae 11998 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
11999 FOREACH_AFI_SAFI (afi, safi) {
12000 if (CHECK_FLAG(p->af_sflags[afi][safi],
12001 PEER_STATUS_EOR_SEND)) {
12002 vty_out(vty, "%s%s",
12003 eor_send_af_count ? ", "
12004 : "",
36235319
QY
12005 get_afi_safi_str(
12006 afi, safi,
12007 false));
05c7a1cc 12008 eor_send_af_count++;
d62a17ae 12009 }
12010 }
12011 vty_out(vty, "\n");
12012 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
12013 FOREACH_AFI_SAFI (afi, safi) {
12014 if (CHECK_FLAG(
12015 p->af_sflags[afi][safi],
12016 PEER_STATUS_EOR_RECEIVED)) {
12017 vty_out(vty, "%s%s",
12018 eor_receive_af_count
12019 ? ", "
12020 : "",
5cb5f4d0
DD
12021 get_afi_safi_str(afi,
12022 safi,
12023 false));
05c7a1cc 12024 eor_receive_af_count++;
d62a17ae 12025 }
12026 }
12027 vty_out(vty, "\n");
12028 }
12029
12030 if (p->t_gr_restart)
12031 vty_out(vty,
12032 " The remaining time of restart timer is %ld\n",
12033 thread_timer_remain_second(
12034 p->t_gr_restart));
12035
12036 if (p->t_gr_stale)
12037 vty_out(vty,
12038 " The remaining time of stalepath timer is %ld\n",
12039 thread_timer_remain_second(
12040 p->t_gr_stale));
2986cac2 12041
12042 /* more gr info in new format */
12043 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 12044 }
2986cac2 12045
d62a17ae 12046 if (use_json) {
12047 json_object *json_stat = NULL;
12048 json_stat = json_object_new_object();
12049 /* Packet counts. */
43aa5965
QY
12050
12051 atomic_size_t outq_count, inq_count;
12052 outq_count = atomic_load_explicit(&p->obuf->count,
12053 memory_order_relaxed);
12054 inq_count = atomic_load_explicit(&p->ibuf->count,
12055 memory_order_relaxed);
12056
12057 json_object_int_add(json_stat, "depthInq",
12058 (unsigned long)inq_count);
d62a17ae 12059 json_object_int_add(json_stat, "depthOutq",
43aa5965 12060 (unsigned long)outq_count);
0112e9e0
QY
12061 json_object_int_add(json_stat, "opensSent",
12062 atomic_load_explicit(&p->open_out,
12063 memory_order_relaxed));
12064 json_object_int_add(json_stat, "opensRecv",
12065 atomic_load_explicit(&p->open_in,
12066 memory_order_relaxed));
d62a17ae 12067 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
12068 atomic_load_explicit(&p->notify_out,
12069 memory_order_relaxed));
d62a17ae 12070 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
12071 atomic_load_explicit(&p->notify_in,
12072 memory_order_relaxed));
12073 json_object_int_add(json_stat, "updatesSent",
12074 atomic_load_explicit(&p->update_out,
12075 memory_order_relaxed));
12076 json_object_int_add(json_stat, "updatesRecv",
12077 atomic_load_explicit(&p->update_in,
12078 memory_order_relaxed));
d62a17ae 12079 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
12080 atomic_load_explicit(&p->keepalive_out,
12081 memory_order_relaxed));
d62a17ae 12082 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
12083 atomic_load_explicit(&p->keepalive_in,
12084 memory_order_relaxed));
d62a17ae 12085 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
12086 atomic_load_explicit(&p->refresh_out,
12087 memory_order_relaxed));
d62a17ae 12088 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
12089 atomic_load_explicit(&p->refresh_in,
12090 memory_order_relaxed));
d62a17ae 12091 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
12092 atomic_load_explicit(&p->dynamic_cap_out,
12093 memory_order_relaxed));
d62a17ae 12094 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
12095 atomic_load_explicit(&p->dynamic_cap_in,
12096 memory_order_relaxed));
12097 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
12098 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 12099 json_object_object_add(json_neigh, "messageStats", json_stat);
12100 } else {
43aa5965
QY
12101 atomic_size_t outq_count, inq_count;
12102 outq_count = atomic_load_explicit(&p->obuf->count,
12103 memory_order_relaxed);
12104 inq_count = atomic_load_explicit(&p->ibuf->count,
12105 memory_order_relaxed);
12106
d62a17ae 12107 /* Packet counts. */
12108 vty_out(vty, " Message statistics:\n");
43aa5965
QY
12109 vty_out(vty, " Inq depth is %zu\n", inq_count);
12110 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 12111 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
12112 vty_out(vty, " Opens: %10d %10d\n",
12113 atomic_load_explicit(&p->open_out,
12114 memory_order_relaxed),
12115 atomic_load_explicit(&p->open_in,
12116 memory_order_relaxed));
12117 vty_out(vty, " Notifications: %10d %10d\n",
12118 atomic_load_explicit(&p->notify_out,
12119 memory_order_relaxed),
12120 atomic_load_explicit(&p->notify_in,
12121 memory_order_relaxed));
12122 vty_out(vty, " Updates: %10d %10d\n",
12123 atomic_load_explicit(&p->update_out,
12124 memory_order_relaxed),
12125 atomic_load_explicit(&p->update_in,
12126 memory_order_relaxed));
12127 vty_out(vty, " Keepalives: %10d %10d\n",
12128 atomic_load_explicit(&p->keepalive_out,
12129 memory_order_relaxed),
12130 atomic_load_explicit(&p->keepalive_in,
12131 memory_order_relaxed));
12132 vty_out(vty, " Route Refresh: %10d %10d\n",
12133 atomic_load_explicit(&p->refresh_out,
12134 memory_order_relaxed),
12135 atomic_load_explicit(&p->refresh_in,
12136 memory_order_relaxed));
d62a17ae 12137 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
12138 atomic_load_explicit(&p->dynamic_cap_out,
12139 memory_order_relaxed),
12140 atomic_load_explicit(&p->dynamic_cap_in,
12141 memory_order_relaxed));
12142 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
12143 PEER_TOTAL_RX(p));
d62a17ae 12144 }
12145
12146 if (use_json) {
12147 /* advertisement-interval */
12148 json_object_int_add(json_neigh,
12149 "minBtwnAdvertisementRunsTimerMsecs",
12150 p->v_routeadv * 1000);
12151
12152 /* Update-source. */
12153 if (p->update_if || p->update_source) {
12154 if (p->update_if)
12155 json_object_string_add(json_neigh,
12156 "updateSource",
12157 p->update_if);
12158 else if (p->update_source)
12159 json_object_string_add(
12160 json_neigh, "updateSource",
12161 sockunion2str(p->update_source, buf1,
12162 SU_ADDRSTRLEN));
12163 }
12164 } else {
12165 /* advertisement-interval */
12166 vty_out(vty,
12167 " Minimum time between advertisement runs is %d seconds\n",
12168 p->v_routeadv);
12169
12170 /* Update-source. */
12171 if (p->update_if || p->update_source) {
12172 vty_out(vty, " Update source is ");
12173 if (p->update_if)
12174 vty_out(vty, "%s", p->update_if);
12175 else if (p->update_source)
12176 vty_out(vty, "%s",
12177 sockunion2str(p->update_source, buf1,
12178 SU_ADDRSTRLEN));
12179 vty_out(vty, "\n");
12180 }
12181
12182 vty_out(vty, "\n");
12183 }
12184
12185 /* Address Family Information */
12186 json_object *json_hold = NULL;
12187
12188 if (use_json)
12189 json_hold = json_object_new_object();
12190
05c7a1cc
QY
12191 FOREACH_AFI_SAFI (afi, safi)
12192 if (p->afc[afi][safi])
12193 bgp_show_peer_afi(vty, p, afi, safi, use_json,
12194 json_hold);
d62a17ae 12195
12196 if (use_json) {
12197 json_object_object_add(json_neigh, "addressFamilyInfo",
12198 json_hold);
12199 json_object_int_add(json_neigh, "connectionsEstablished",
12200 p->established);
12201 json_object_int_add(json_neigh, "connectionsDropped",
12202 p->dropped);
12203 } else
12204 vty_out(vty, " Connections established %d; dropped %d\n",
12205 p->established, p->dropped);
12206
12207 if (!p->last_reset) {
12208 if (use_json)
12209 json_object_string_add(json_neigh, "lastReset",
12210 "never");
12211 else
12212 vty_out(vty, " Last reset never\n");
12213 } else {
12214 if (use_json) {
12215 time_t uptime;
a2700b50 12216 struct tm tm;
d62a17ae 12217
12218 uptime = bgp_clock();
12219 uptime -= p->resettime;
a2700b50
MS
12220 gmtime_r(&uptime, &tm);
12221
d62a17ae 12222 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
12223 (tm.tm_sec * 1000)
12224 + (tm.tm_min * 60000)
12225 + (tm.tm_hour * 3600000));
3577f1c5 12226 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 12227 } else {
12228 vty_out(vty, " Last reset %s, ",
12229 peer_uptime(p->resettime, timebuf,
12230 BGP_UPTIME_LEN, 0, NULL));
12231
3577f1c5 12232 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 12233 if (p->last_reset_cause_size) {
12234 msg = p->last_reset_cause;
12235 vty_out(vty,
12236 " Message received that caused BGP to send a NOTIFICATION:\n ");
12237 for (i = 1; i <= p->last_reset_cause_size;
12238 i++) {
12239 vty_out(vty, "%02X", *msg++);
12240
12241 if (i != p->last_reset_cause_size) {
12242 if (i % 16 == 0) {
12243 vty_out(vty, "\n ");
12244 } else if (i % 4 == 0) {
12245 vty_out(vty, " ");
12246 }
12247 }
12248 }
12249 vty_out(vty, "\n");
12250 }
12251 }
12252 }
12253
12254 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
12255 if (use_json)
12256 json_object_boolean_true_add(json_neigh,
12257 "prefixesConfigExceedMax");
12258 else
12259 vty_out(vty,
12260 " Peer had exceeded the max. no. of prefixes configured.\n");
12261
12262 if (p->t_pmax_restart) {
12263 if (use_json) {
12264 json_object_boolean_true_add(
12265 json_neigh, "reducePrefixNumFrom");
12266 json_object_int_add(json_neigh,
12267 "restartInTimerMsec",
12268 thread_timer_remain_second(
12269 p->t_pmax_restart)
12270 * 1000);
12271 } else
12272 vty_out(vty,
12273 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
12274 p->host, thread_timer_remain_second(
12275 p->t_pmax_restart));
d62a17ae 12276 } else {
12277 if (use_json)
12278 json_object_boolean_true_add(
12279 json_neigh,
12280 "reducePrefixNumAndClearIpBgp");
12281 else
12282 vty_out(vty,
12283 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
12284 p->host);
12285 }
12286 }
12287
12288 /* EBGP Multihop and GTSM */
12289 if (p->sort != BGP_PEER_IBGP) {
12290 if (use_json) {
e2521429 12291 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12292 json_object_int_add(json_neigh,
12293 "externalBgpNbrMaxHopsAway",
12294 p->gtsm_hops);
c8d6f0d6 12295 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12296 json_object_int_add(json_neigh,
12297 "externalBgpNbrMaxHopsAway",
12298 p->ttl);
12299 } else {
e2521429 12300 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12301 vty_out(vty,
12302 " External BGP neighbor may be up to %d hops away.\n",
12303 p->gtsm_hops);
c8d6f0d6 12304 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12305 vty_out(vty,
12306 " External BGP neighbor may be up to %d hops away.\n",
12307 p->ttl);
12308 }
12309 } else {
e2521429 12310 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 12311 if (use_json)
12312 json_object_int_add(json_neigh,
12313 "internalBgpNbrMaxHopsAway",
12314 p->gtsm_hops);
12315 else
12316 vty_out(vty,
12317 " Internal BGP neighbor may be up to %d hops away.\n",
12318 p->gtsm_hops);
12319 }
12320 }
12321
12322 /* Local address. */
12323 if (p->su_local) {
12324 if (use_json) {
12325 json_object_string_add(json_neigh, "hostLocal",
12326 sockunion2str(p->su_local, buf1,
12327 SU_ADDRSTRLEN));
12328 json_object_int_add(json_neigh, "portLocal",
12329 ntohs(p->su_local->sin.sin_port));
12330 } else
12331 vty_out(vty, "Local host: %s, Local port: %d\n",
12332 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
12333 ntohs(p->su_local->sin.sin_port));
12334 }
12335
12336 /* Remote address. */
12337 if (p->su_remote) {
12338 if (use_json) {
12339 json_object_string_add(json_neigh, "hostForeign",
12340 sockunion2str(p->su_remote, buf1,
12341 SU_ADDRSTRLEN));
12342 json_object_int_add(json_neigh, "portForeign",
12343 ntohs(p->su_remote->sin.sin_port));
12344 } else
12345 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12346 sockunion2str(p->su_remote, buf1,
12347 SU_ADDRSTRLEN),
12348 ntohs(p->su_remote->sin.sin_port));
12349 }
12350
12351 /* Nexthop display. */
12352 if (p->su_local) {
12353 if (use_json) {
12354 json_object_string_add(json_neigh, "nexthop",
12355 inet_ntop(AF_INET,
12356 &p->nexthop.v4, buf1,
12357 sizeof(buf1)));
12358 json_object_string_add(json_neigh, "nexthopGlobal",
12359 inet_ntop(AF_INET6,
12360 &p->nexthop.v6_global,
12361 buf1, sizeof(buf1)));
12362 json_object_string_add(json_neigh, "nexthopLocal",
12363 inet_ntop(AF_INET6,
12364 &p->nexthop.v6_local,
12365 buf1, sizeof(buf1)));
12366 if (p->shared_network)
12367 json_object_string_add(json_neigh,
12368 "bgpConnection",
12369 "sharedNetwork");
12370 else
12371 json_object_string_add(json_neigh,
12372 "bgpConnection",
12373 "nonSharedNetwork");
12374 } else {
12375 vty_out(vty, "Nexthop: %s\n",
12376 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12377 sizeof(buf1)));
12378 vty_out(vty, "Nexthop global: %s\n",
12379 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12380 sizeof(buf1)));
12381 vty_out(vty, "Nexthop local: %s\n",
12382 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12383 sizeof(buf1)));
12384 vty_out(vty, "BGP connection: %s\n",
12385 p->shared_network ? "shared network"
12386 : "non shared network");
12387 }
12388 }
12389
12390 /* Timer information. */
12391 if (use_json) {
12392 json_object_int_add(json_neigh, "connectRetryTimer",
12393 p->v_connect);
12394 if (p->status == Established && p->rtt)
12395 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12396 p->rtt);
12397 if (p->t_start)
12398 json_object_int_add(
12399 json_neigh, "nextStartTimerDueInMsecs",
12400 thread_timer_remain_second(p->t_start) * 1000);
12401 if (p->t_connect)
12402 json_object_int_add(
12403 json_neigh, "nextConnectTimerDueInMsecs",
12404 thread_timer_remain_second(p->t_connect)
12405 * 1000);
12406 if (p->t_routeadv) {
12407 json_object_int_add(json_neigh, "mraiInterval",
12408 p->v_routeadv);
12409 json_object_int_add(
12410 json_neigh, "mraiTimerExpireInMsecs",
12411 thread_timer_remain_second(p->t_routeadv)
12412 * 1000);
12413 }
12414 if (p->password)
12415 json_object_int_add(json_neigh, "authenticationEnabled",
12416 1);
12417
12418 if (p->t_read)
12419 json_object_string_add(json_neigh, "readThread", "on");
12420 else
12421 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
12422
12423 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 12424 json_object_string_add(json_neigh, "writeThread", "on");
12425 else
12426 json_object_string_add(json_neigh, "writeThread",
12427 "off");
12428 } else {
12429 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12430 p->v_connect);
12431 if (p->status == Established && p->rtt)
12432 vty_out(vty, "Estimated round trip time: %d ms\n",
12433 p->rtt);
12434 if (p->t_start)
12435 vty_out(vty, "Next start timer due in %ld seconds\n",
12436 thread_timer_remain_second(p->t_start));
12437 if (p->t_connect)
12438 vty_out(vty, "Next connect timer due in %ld seconds\n",
12439 thread_timer_remain_second(p->t_connect));
12440 if (p->t_routeadv)
12441 vty_out(vty,
12442 "MRAI (interval %u) timer expires in %ld seconds\n",
12443 p->v_routeadv,
12444 thread_timer_remain_second(p->t_routeadv));
12445 if (p->password)
12446 vty_out(vty, "Peer Authentication Enabled\n");
12447
cac9e917 12448 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
12449 p->t_read ? "on" : "off",
12450 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12451 ? "on"
cac9e917 12452 : "off", p->fd);
d62a17ae 12453 }
12454
12455 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12456 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12457 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12458
12459 if (!use_json)
12460 vty_out(vty, "\n");
12461
12462 /* BFD information. */
12463 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12464
12465 if (use_json) {
12466 if (p->conf_if) /* Configured interface name. */
12467 json_object_object_add(json, p->conf_if, json_neigh);
12468 else /* Configured IP address. */
12469 json_object_object_add(json, p->host, json_neigh);
12470 }
12471}
12472
36235319
QY
12473static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
12474 enum show_type type,
12475 union sockunion *su,
12476 const char *conf_if, afi_t afi,
74a630b6 12477 bool use_json)
2986cac2 12478{
12479 struct listnode *node, *nnode;
12480 struct peer *peer;
12481 int find = 0;
12482 safi_t safi = SAFI_UNICAST;
74a630b6 12483 json_object *json = NULL;
2986cac2 12484 json_object *json_neighbor = NULL;
12485
74a630b6
NT
12486 if (use_json) {
12487 json = json_object_new_object();
12488 json_neighbor = json_object_new_object();
12489 }
12490
2986cac2 12491 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12492
12493 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12494 continue;
12495
12496 if ((peer->afc[afi][safi]) == 0)
12497 continue;
12498
2ba1fe69 12499 if (type == show_all) {
2986cac2 12500 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 12501 json_neighbor);
2986cac2 12502
74a630b6 12503 if (use_json) {
13909c4f
DS
12504 json_object_object_add(json, peer->host,
12505 json_neighbor);
74a630b6
NT
12506 json_neighbor = NULL;
12507 }
2986cac2 12508
2ba1fe69 12509 } else if (type == show_peer) {
2986cac2 12510 if (conf_if) {
12511 if ((peer->conf_if
13909c4f
DS
12512 && !strcmp(peer->conf_if, conf_if))
12513 || (peer->hostname
2986cac2 12514 && !strcmp(peer->hostname, conf_if))) {
12515 find = 1;
13909c4f
DS
12516 bgp_show_peer_gr_status(vty, peer,
12517 use_json,
12518 json_neighbor);
2986cac2 12519 }
12520 } else {
12521 if (sockunion_same(&peer->su, su)) {
12522 find = 1;
13909c4f
DS
12523 bgp_show_peer_gr_status(vty, peer,
12524 use_json,
12525 json_neighbor);
2986cac2 12526 }
12527 }
13909c4f
DS
12528 if (use_json && find)
12529 json_object_object_add(json, peer->host,
12530 json_neighbor);
2986cac2 12531 }
12532
74a630b6
NT
12533 if (find) {
12534 json_neighbor = NULL;
2986cac2 12535 break;
74a630b6 12536 }
2986cac2 12537 }
12538
12539 if (type == show_peer && !find) {
12540 if (use_json)
13909c4f 12541 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 12542 else
12543 vty_out(vty, "%% No such neighbor\n");
12544 }
12545 if (use_json) {
13909c4f
DS
12546 vty_out(vty, "%s\n",
12547 json_object_to_json_string_ext(
12548 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
12549
12550 if (json_neighbor)
12551 json_object_free(json_neighbor);
12552 json_object_free(json);
2986cac2 12553 } else {
12554 vty_out(vty, "\n");
12555 }
12556
12557 return CMD_SUCCESS;
12558}
12559
d62a17ae 12560static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12561 enum show_type type, union sockunion *su,
9f049418 12562 const char *conf_if, bool use_json,
d62a17ae 12563 json_object *json)
12564{
12565 struct listnode *node, *nnode;
12566 struct peer *peer;
12567 int find = 0;
9f049418 12568 bool nbr_output = false;
d1927ebe
AS
12569 afi_t afi = AFI_MAX;
12570 safi_t safi = SAFI_MAX;
12571
12572 if (type == show_ipv4_peer || type == show_ipv4_all) {
12573 afi = AFI_IP;
12574 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12575 afi = AFI_IP6;
12576 }
d62a17ae 12577
12578 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12579 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12580 continue;
12581
12582 switch (type) {
12583 case show_all:
12584 bgp_show_peer(vty, peer, use_json, json);
9f049418 12585 nbr_output = true;
d62a17ae 12586 break;
12587 case show_peer:
12588 if (conf_if) {
12589 if ((peer->conf_if
12590 && !strcmp(peer->conf_if, conf_if))
12591 || (peer->hostname
12592 && !strcmp(peer->hostname, conf_if))) {
12593 find = 1;
12594 bgp_show_peer(vty, peer, use_json,
12595 json);
12596 }
12597 } else {
12598 if (sockunion_same(&peer->su, su)) {
12599 find = 1;
12600 bgp_show_peer(vty, peer, use_json,
12601 json);
12602 }
12603 }
12604 break;
d1927ebe
AS
12605 case show_ipv4_peer:
12606 case show_ipv6_peer:
12607 FOREACH_SAFI (safi) {
12608 if (peer->afc[afi][safi]) {
12609 if (conf_if) {
12610 if ((peer->conf_if
12611 && !strcmp(peer->conf_if, conf_if))
12612 || (peer->hostname
12613 && !strcmp(peer->hostname, conf_if))) {
12614 find = 1;
12615 bgp_show_peer(vty, peer, use_json,
12616 json);
12617 break;
12618 }
12619 } else {
12620 if (sockunion_same(&peer->su, su)) {
12621 find = 1;
12622 bgp_show_peer(vty, peer, use_json,
12623 json);
12624 break;
12625 }
12626 }
12627 }
12628 }
12629 break;
12630 case show_ipv4_all:
12631 case show_ipv6_all:
12632 FOREACH_SAFI (safi) {
12633 if (peer->afc[afi][safi]) {
12634 bgp_show_peer(vty, peer, use_json, json);
12635 nbr_output = true;
12636 break;
12637 }
12638 }
12639 break;
d62a17ae 12640 }
12641 }
12642
d1927ebe
AS
12643 if ((type == show_peer || type == show_ipv4_peer ||
12644 type == show_ipv6_peer) && !find) {
d62a17ae 12645 if (use_json)
12646 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12647 else
88b7d255 12648 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 12649 }
12650
d1927ebe
AS
12651 if (type != show_peer && type != show_ipv4_peer &&
12652 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 12653 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 12654
d62a17ae 12655 if (use_json) {
996c9314
LB
12656 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12657 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 12658 } else {
12659 vty_out(vty, "\n");
12660 }
12661
12662 return CMD_SUCCESS;
12663}
12664
36235319
QY
12665static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12666 enum show_type type,
12667 const char *ip_str,
12668 afi_t afi, bool use_json)
2986cac2 12669{
12670
12671 int ret;
12672 struct bgp *bgp;
12673 union sockunion su;
2986cac2 12674
12675 bgp = bgp_get_default();
12676
13909c4f
DS
12677 if (!bgp)
12678 return;
2986cac2 12679
13909c4f
DS
12680 if (!use_json)
12681 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12682 NULL);
2986cac2 12683
13909c4f
DS
12684 if (ip_str) {
12685 ret = str2sockunion(ip_str, &su);
12686 if (ret < 0)
13909c4f 12687 bgp_show_neighbor_graceful_restart(
74a630b6
NT
12688 vty, bgp, type, NULL, ip_str, afi, use_json);
12689 else
12690 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
12691 NULL, afi, use_json);
13909c4f
DS
12692 } else
12693 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 12694 afi, use_json);
2986cac2 12695}
12696
d62a17ae 12697static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
12698 enum show_type type,
12699 const char *ip_str,
9f049418 12700 bool use_json)
d62a17ae 12701{
0291c246
MK
12702 struct listnode *node, *nnode;
12703 struct bgp *bgp;
71aedaa3 12704 union sockunion su;
0291c246 12705 json_object *json = NULL;
71aedaa3 12706 int ret, is_first = 1;
9f049418 12707 bool nbr_output = false;
d62a17ae 12708
12709 if (use_json)
12710 vty_out(vty, "{\n");
12711
12712 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 12713 nbr_output = true;
d62a17ae 12714 if (use_json) {
12715 if (!(json = json_object_new_object())) {
af4c2728 12716 flog_err(
e50f7cfd 12717 EC_BGP_JSON_MEM_ERROR,
d62a17ae 12718 "Unable to allocate memory for JSON object");
12719 vty_out(vty,
12720 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12721 return;
12722 }
12723
12724 json_object_int_add(json, "vrfId",
12725 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
12726 ? -1
12727 : (int64_t)bgp->vrf_id);
d62a17ae 12728 json_object_string_add(
12729 json, "vrfName",
12730 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12731 ? VRF_DEFAULT_NAME
d62a17ae 12732 : bgp->name);
12733
12734 if (!is_first)
12735 vty_out(vty, ",\n");
12736 else
12737 is_first = 0;
12738
12739 vty_out(vty, "\"%s\":",
12740 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12741 ? VRF_DEFAULT_NAME
d62a17ae 12742 : bgp->name);
12743 } else {
12744 vty_out(vty, "\nInstance %s:\n",
12745 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12746 ? VRF_DEFAULT_NAME
d62a17ae 12747 : bgp->name);
12748 }
71aedaa3 12749
d1927ebe
AS
12750 if (type == show_peer || type == show_ipv4_peer ||
12751 type == show_ipv6_peer) {
71aedaa3
DS
12752 ret = str2sockunion(ip_str, &su);
12753 if (ret < 0)
12754 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12755 use_json, json);
12756 else
12757 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12758 use_json, json);
12759 } else {
d1927ebe 12760 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
12761 use_json, json);
12762 }
b77004d6 12763 json_object_free(json);
121067e9 12764 json = NULL;
d62a17ae 12765 }
12766
01cbfd04 12767 if (use_json) {
d62a17ae 12768 vty_out(vty, "}\n");
121067e9
DS
12769 if (json)
12770 json_object_free(json);
01cbfd04 12771 }
9f049418
DS
12772 else if (!nbr_output)
12773 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12774}
12775
12776static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
12777 enum show_type type, const char *ip_str,
9f049418 12778 bool use_json)
d62a17ae 12779{
12780 int ret;
12781 struct bgp *bgp;
12782 union sockunion su;
12783 json_object *json = NULL;
12784
12785 if (name) {
12786 if (strmatch(name, "all")) {
71aedaa3
DS
12787 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
12788 use_json);
d62a17ae 12789 return CMD_SUCCESS;
12790 } else {
12791 bgp = bgp_lookup_by_name(name);
12792 if (!bgp) {
12793 if (use_json) {
12794 json = json_object_new_object();
d62a17ae 12795 vty_out(vty, "%s\n",
12796 json_object_to_json_string_ext(
12797 json,
12798 JSON_C_TO_STRING_PRETTY));
12799 json_object_free(json);
12800 } else
12801 vty_out(vty,
9f049418 12802 "%% BGP instance not found\n");
d62a17ae 12803
12804 return CMD_WARNING;
12805 }
12806 }
12807 } else {
12808 bgp = bgp_get_default();
12809 }
12810
12811 if (bgp) {
12812 json = json_object_new_object();
12813 if (ip_str) {
12814 ret = str2sockunion(ip_str, &su);
12815 if (ret < 0)
12816 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12817 use_json, json);
12818 else
12819 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12820 use_json, json);
12821 } else {
12822 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
12823 json);
12824 }
12825 json_object_free(json);
ca61fd25
DS
12826 } else {
12827 if (use_json)
12828 vty_out(vty, "{}\n");
12829 else
12830 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12831 }
12832
12833 return CMD_SUCCESS;
4fb25c53
DW
12834}
12835
2986cac2 12836
12837
12838/* "show [ip] bgp neighbors graceful-restart" commands. */
12839DEFUN (show_ip_bgp_neighbors_gracrful_restart,
12840 show_ip_bgp_neighbors_graceful_restart_cmd,
12841 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
12842 SHOW_STR
12843 BGP_STR
12844 IP_STR
12845 IPV6_STR
12846 NEIGHBOR_STR
12847 "Neighbor to display information about\n"
12848 "Neighbor to display information about\n"
12849 "Neighbor on BGP configured interface\n"
12850 GR_SHOW
12851 JSON_STR)
12852{
12853 char *sh_arg = NULL;
12854 enum show_type sh_type;
12855 int idx = 0;
12856 afi_t afi = AFI_MAX;
2986cac2 12857 bool uj = use_json(argc, argv);
12858
36235319 12859 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 12860 afi = AFI_MAX;
12861
12862 idx++;
12863
12864 if (argv_find(argv, argc, "A.B.C.D", &idx)
12865 || argv_find(argv, argc, "X:X::X:X", &idx)
12866 || argv_find(argv, argc, "WORD", &idx)) {
12867 sh_type = show_peer;
12868 sh_arg = argv[idx]->arg;
12869 } else
12870 sh_type = show_all;
12871
12872 if (!argv_find(argv, argc, "graceful-restart", &idx))
12873 return CMD_SUCCESS;
12874
12875
36235319
QY
12876 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
12877 afi, uj);
2986cac2 12878}
12879
716b2d8a 12880/* "show [ip] bgp neighbors" commands. */
718e3744 12881DEFUN (show_ip_bgp_neighbors,
12882 show_ip_bgp_neighbors_cmd,
24345e82 12883 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 12884 SHOW_STR
12885 IP_STR
12886 BGP_STR
f2a8972b 12887 BGP_INSTANCE_HELP_STR
8c3deaae
QY
12888 "Address Family\n"
12889 "Address Family\n"
718e3744 12890 "Detailed information on TCP and BGP neighbor connections\n"
12891 "Neighbor to display information about\n"
a80beece 12892 "Neighbor to display information about\n"
91d37724 12893 "Neighbor on BGP configured interface\n"
9973d184 12894 JSON_STR)
718e3744 12895{
d62a17ae 12896 char *vrf = NULL;
12897 char *sh_arg = NULL;
12898 enum show_type sh_type;
d1927ebe 12899 afi_t afi = AFI_MAX;
718e3744 12900
9f049418 12901 bool uj = use_json(argc, argv);
718e3744 12902
d62a17ae 12903 int idx = 0;
718e3744 12904
9a8bdf1c
PG
12905 /* [<vrf> VIEWVRFNAME] */
12906 if (argv_find(argv, argc, "vrf", &idx)) {
12907 vrf = argv[idx + 1]->arg;
12908 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12909 vrf = NULL;
12910 } else if (argv_find(argv, argc, "view", &idx))
12911 /* [<view> VIEWVRFNAME] */
d62a17ae 12912 vrf = argv[idx + 1]->arg;
718e3744 12913
d62a17ae 12914 idx++;
d1927ebe
AS
12915
12916 if (argv_find(argv, argc, "ipv4", &idx)) {
12917 sh_type = show_ipv4_all;
12918 afi = AFI_IP;
12919 } else if (argv_find(argv, argc, "ipv6", &idx)) {
12920 sh_type = show_ipv6_all;
12921 afi = AFI_IP6;
12922 } else {
12923 sh_type = show_all;
12924 }
12925
d62a17ae 12926 if (argv_find(argv, argc, "A.B.C.D", &idx)
12927 || argv_find(argv, argc, "X:X::X:X", &idx)
12928 || argv_find(argv, argc, "WORD", &idx)) {
12929 sh_type = show_peer;
12930 sh_arg = argv[idx]->arg;
d1927ebe
AS
12931 }
12932
12933 if (sh_type == show_peer && afi == AFI_IP) {
12934 sh_type = show_ipv4_peer;
12935 } else if (sh_type == show_peer && afi == AFI_IP6) {
12936 sh_type = show_ipv6_peer;
12937 }
856ca177 12938
d62a17ae 12939 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 12940}
12941
716b2d8a 12942/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 12943 paths' and `show ip mbgp paths'. Those functions results are the
12944 same.*/
f412b39a 12945DEFUN (show_ip_bgp_paths,
718e3744 12946 show_ip_bgp_paths_cmd,
46f296b4 12947 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 12948 SHOW_STR
12949 IP_STR
12950 BGP_STR
46f296b4 12951 BGP_SAFI_HELP_STR
718e3744 12952 "Path information\n")
12953{
d62a17ae 12954 vty_out(vty, "Address Refcnt Path\n");
12955 aspath_print_all_vty(vty);
12956 return CMD_SUCCESS;
718e3744 12957}
12958
718e3744 12959#include "hash.h"
12960
e3b78da8 12961static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12962 struct vty *vty)
718e3744 12963{
d62a17ae 12964 struct community *com;
718e3744 12965
e3b78da8 12966 com = (struct community *)bucket->data;
3f65c5b1 12967 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 12968 community_str(com, false));
718e3744 12969}
12970
12971/* Show BGP's community internal data. */
f412b39a 12972DEFUN (show_ip_bgp_community_info,
718e3744 12973 show_ip_bgp_community_info_cmd,
bec37ba5 12974 "show [ip] bgp community-info",
718e3744 12975 SHOW_STR
12976 IP_STR
12977 BGP_STR
12978 "List all bgp community information\n")
12979{
d62a17ae 12980 vty_out(vty, "Address Refcnt Community\n");
718e3744 12981
d62a17ae 12982 hash_iterate(community_hash(),
e3b78da8 12983 (void (*)(struct hash_bucket *,
d62a17ae 12984 void *))community_show_all_iterator,
12985 vty);
718e3744 12986
d62a17ae 12987 return CMD_SUCCESS;
718e3744 12988}
12989
e3b78da8 12990static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12991 struct vty *vty)
57d187bc 12992{
d62a17ae 12993 struct lcommunity *lcom;
57d187bc 12994
e3b78da8 12995 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 12996 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 12997 lcommunity_str(lcom, false));
57d187bc
JS
12998}
12999
13000/* Show BGP's community internal data. */
13001DEFUN (show_ip_bgp_lcommunity_info,
13002 show_ip_bgp_lcommunity_info_cmd,
13003 "show ip bgp large-community-info",
13004 SHOW_STR
13005 IP_STR
13006 BGP_STR
13007 "List all bgp large-community information\n")
13008{
d62a17ae 13009 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 13010
d62a17ae 13011 hash_iterate(lcommunity_hash(),
e3b78da8 13012 (void (*)(struct hash_bucket *,
d62a17ae 13013 void *))lcommunity_show_all_iterator,
13014 vty);
57d187bc 13015
d62a17ae 13016 return CMD_SUCCESS;
57d187bc 13017}
2986cac2 13018/* Graceful Restart */
13019
13020static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
13021 struct bgp *bgp,
13022 bool use_json,
13023 json_object *json)
2986cac2 13024{
57d187bc
JS
13025
13026
2986cac2 13027 vty_out(vty, "\n%s", SHOW_GR_HEADER);
13028
7318ae88 13029 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 13030
13031 switch (bgp_global_gr_mode) {
13032
13033 case GLOBAL_HELPER:
13909c4f 13034 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 13035 break;
13036
13037 case GLOBAL_GR:
13909c4f 13038 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 13039 break;
13040
13041 case GLOBAL_DISABLE:
13909c4f 13042 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 13043 break;
13044
13045 case GLOBAL_INVALID:
2986cac2 13046 vty_out(vty,
2ba1fe69 13047 "Global BGP GR Mode Invalid\n");
2986cac2 13048 break;
13049 }
13050 vty_out(vty, "\n");
13051}
13052
36235319
QY
13053static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
13054 enum show_type type,
13055 const char *ip_str,
13056 afi_t afi, bool use_json)
2986cac2 13057{
13058 if ((afi == AFI_MAX) && (ip_str == NULL)) {
13059 afi = AFI_IP;
13060
13061 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
13062
36235319
QY
13063 bgp_show_neighbor_graceful_restart_vty(
13064 vty, type, ip_str, afi, use_json);
2986cac2 13065 afi++;
13066 }
13067 } else if (afi != AFI_MAX) {
36235319
QY
13068 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
13069 use_json);
2986cac2 13070 } else {
13071 return CMD_ERR_INCOMPLETE;
13072 }
13073
13074 return CMD_SUCCESS;
13075}
13076/* Graceful Restart */
13077
f412b39a 13078DEFUN (show_ip_bgp_attr_info,
718e3744 13079 show_ip_bgp_attr_info_cmd,
bec37ba5 13080 "show [ip] bgp attribute-info",
718e3744 13081 SHOW_STR
13082 IP_STR
13083 BGP_STR
13084 "List all bgp attribute information\n")
13085{
d62a17ae 13086 attr_show_all(vty);
13087 return CMD_SUCCESS;
718e3744 13088}
6b0655a2 13089
03915806
CS
13090static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
13091 afi_t afi, safi_t safi,
13092 bool use_json, json_object *json)
53089bec 13093{
13094 struct bgp *bgp;
13095 struct listnode *node;
13096 char *vname;
13097 char buf1[INET6_ADDRSTRLEN];
13098 char *ecom_str;
13099 vpn_policy_direction_t dir;
13100
03915806 13101 if (json) {
b46dfd20
DS
13102 json_object *json_import_vrfs = NULL;
13103 json_object *json_export_vrfs = NULL;
13104
b46dfd20
DS
13105 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13106
53089bec 13107 if (!bgp) {
b46dfd20
DS
13108 vty_out(vty, "%s\n",
13109 json_object_to_json_string_ext(
13110 json,
13111 JSON_C_TO_STRING_PRETTY));
13112 json_object_free(json);
13113
53089bec 13114 return CMD_WARNING;
13115 }
b46dfd20 13116
94d4c685
DS
13117 /* Provide context for the block */
13118 json_object_string_add(json, "vrf", name ? name : "default");
13119 json_object_string_add(json, "afiSafi",
5cb5f4d0 13120 get_afi_safi_str(afi, safi, true));
94d4c685 13121
b46dfd20
DS
13122 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13123 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
13124 json_object_string_add(json, "importFromVrfs", "none");
13125 json_object_string_add(json, "importRts", "none");
13126 } else {
6ce24e52
DS
13127 json_import_vrfs = json_object_new_array();
13128
b46dfd20
DS
13129 for (ALL_LIST_ELEMENTS_RO(
13130 bgp->vpn_policy[afi].import_vrf,
13131 node, vname))
13132 json_object_array_add(json_import_vrfs,
13133 json_object_new_string(vname));
13134
b20875ea
CS
13135 json_object_object_add(json, "importFromVrfs",
13136 json_import_vrfs);
b46dfd20 13137 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13138 if (bgp->vpn_policy[afi].rtlist[dir]) {
13139 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13140 bgp->vpn_policy[afi].rtlist[dir],
13141 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13142 json_object_string_add(json, "importRts",
13143 ecom_str);
13144 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13145 } else
13146 json_object_string_add(json, "importRts",
13147 "none");
b46dfd20
DS
13148 }
13149
13150 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13151 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
13152 json_object_string_add(json, "exportToVrfs", "none");
13153 json_object_string_add(json, "routeDistinguisher",
13154 "none");
13155 json_object_string_add(json, "exportRts", "none");
13156 } else {
6ce24e52
DS
13157 json_export_vrfs = json_object_new_array();
13158
b46dfd20
DS
13159 for (ALL_LIST_ELEMENTS_RO(
13160 bgp->vpn_policy[afi].export_vrf,
13161 node, vname))
13162 json_object_array_add(json_export_vrfs,
13163 json_object_new_string(vname));
13164 json_object_object_add(json, "exportToVrfs",
13165 json_export_vrfs);
13166 json_object_string_add(json, "routeDistinguisher",
13167 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13168 buf1, RD_ADDRSTRLEN));
13169
13170 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13171 if (bgp->vpn_policy[afi].rtlist[dir]) {
13172 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13173 bgp->vpn_policy[afi].rtlist[dir],
13174 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13175 json_object_string_add(json, "exportRts",
13176 ecom_str);
13177 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13178 } else
13179 json_object_string_add(json, "exportRts",
13180 "none");
b46dfd20
DS
13181 }
13182
03915806
CS
13183 if (use_json) {
13184 vty_out(vty, "%s\n",
13185 json_object_to_json_string_ext(json,
b46dfd20 13186 JSON_C_TO_STRING_PRETTY));
03915806
CS
13187 json_object_free(json);
13188 }
53089bec 13189 } else {
b46dfd20
DS
13190 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13191
53089bec 13192 if (!bgp) {
b46dfd20 13193 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 13194 return CMD_WARNING;
13195 }
53089bec 13196
b46dfd20
DS
13197 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13198 BGP_CONFIG_VRF_TO_VRF_IMPORT))
13199 vty_out(vty,
13200 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 13201 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13202 else {
13203 vty_out(vty,
13204 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 13205 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13206
13207 for (ALL_LIST_ELEMENTS_RO(
13208 bgp->vpn_policy[afi].import_vrf,
13209 node, vname))
13210 vty_out(vty, " %s\n", vname);
13211
13212 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13213 ecom_str = NULL;
13214 if (bgp->vpn_policy[afi].rtlist[dir]) {
13215 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13216 bgp->vpn_policy[afi].rtlist[dir],
13217 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 13218 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 13219
b20875ea
CS
13220 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13221 } else
13222 vty_out(vty, "Import RT(s):\n");
53089bec 13223 }
53089bec 13224
b46dfd20
DS
13225 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13226 BGP_CONFIG_VRF_TO_VRF_EXPORT))
13227 vty_out(vty,
13228 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 13229 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13230 else {
13231 vty_out(vty,
04c9077f 13232 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 13233 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13234
13235 for (ALL_LIST_ELEMENTS_RO(
13236 bgp->vpn_policy[afi].export_vrf,
13237 node, vname))
13238 vty_out(vty, " %s\n", vname);
13239
13240 vty_out(vty, "RD: %s\n",
13241 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13242 buf1, RD_ADDRSTRLEN));
13243
13244 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13245 if (bgp->vpn_policy[afi].rtlist[dir]) {
13246 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13247 bgp->vpn_policy[afi].rtlist[dir],
13248 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13249 vty_out(vty, "Export RT: %s\n", ecom_str);
13250 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13251 } else
13252 vty_out(vty, "Import RT(s):\n");
53089bec 13253 }
53089bec 13254 }
13255
13256 return CMD_SUCCESS;
13257}
13258
03915806
CS
13259static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
13260 safi_t safi, bool use_json)
13261{
13262 struct listnode *node, *nnode;
13263 struct bgp *bgp;
13264 char *vrf_name = NULL;
13265 json_object *json = NULL;
13266 json_object *json_vrf = NULL;
13267 json_object *json_vrfs = NULL;
13268
13269 if (use_json) {
13270 json = json_object_new_object();
13271 json_vrfs = json_object_new_object();
13272 }
13273
13274 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13275
13276 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
13277 vrf_name = bgp->name;
13278
13279 if (use_json) {
13280 json_vrf = json_object_new_object();
13281 } else {
13282 vty_out(vty, "\nInstance %s:\n",
13283 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13284 ? VRF_DEFAULT_NAME : bgp->name);
13285 }
13286 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
13287 if (use_json) {
13288 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13289 json_object_object_add(json_vrfs,
13290 VRF_DEFAULT_NAME, json_vrf);
13291 else
13292 json_object_object_add(json_vrfs, vrf_name,
13293 json_vrf);
13294 }
13295 }
13296
13297 if (use_json) {
13298 json_object_object_add(json, "vrfs", json_vrfs);
13299 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
13300 JSON_C_TO_STRING_PRETTY));
13301 json_object_free(json);
13302 }
13303
13304 return CMD_SUCCESS;
13305}
13306
53089bec 13307/* "show [ip] bgp route-leak" command. */
13308DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
13309 show_ip_bgp_route_leak_cmd,
13310 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
13311 SHOW_STR
13312 IP_STR
13313 BGP_STR
13314 BGP_INSTANCE_HELP_STR
13315 BGP_AFI_HELP_STR
13316 BGP_SAFI_HELP_STR
13317 "Route leaking information\n"
13318 JSON_STR)
53089bec 13319{
13320 char *vrf = NULL;
13321 afi_t afi = AFI_MAX;
13322 safi_t safi = SAFI_MAX;
13323
9f049418 13324 bool uj = use_json(argc, argv);
53089bec 13325 int idx = 0;
03915806 13326 json_object *json = NULL;
53089bec 13327
13328 /* show [ip] bgp */
13329 if (argv_find(argv, argc, "ip", &idx)) {
13330 afi = AFI_IP;
13331 safi = SAFI_UNICAST;
13332 }
13333 /* [vrf VIEWVRFNAME] */
13334 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
13335 vty_out(vty,
13336 "%% This command is not applicable to BGP views\n");
53089bec 13337 return CMD_WARNING;
13338 }
13339
9a8bdf1c
PG
13340 if (argv_find(argv, argc, "vrf", &idx)) {
13341 vrf = argv[idx + 1]->arg;
13342 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13343 vrf = NULL;
13344 }
53089bec 13345 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13346 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13347 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13348 }
13349
13350 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
13351 vty_out(vty,
13352 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 13353 return CMD_WARNING;
13354 }
13355
03915806
CS
13356 if (vrf && strmatch(vrf, "all"))
13357 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13358
13359 if (uj)
13360 json = json_object_new_object();
13361
13362 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 13363}
13364
d62a17ae 13365static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13366 safi_t safi)
f186de26 13367{
d62a17ae 13368 struct listnode *node, *nnode;
13369 struct bgp *bgp;
f186de26 13370
d62a17ae 13371 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13372 vty_out(vty, "\nInstance %s:\n",
13373 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13374 ? VRF_DEFAULT_NAME
d62a17ae 13375 : bgp->name);
13376 update_group_show(bgp, afi, safi, vty, 0);
13377 }
f186de26 13378}
13379
d62a17ae 13380static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13381 int safi, uint64_t subgrp_id)
4fb25c53 13382{
d62a17ae 13383 struct bgp *bgp;
4fb25c53 13384
d62a17ae 13385 if (name) {
13386 if (strmatch(name, "all")) {
13387 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13388 return CMD_SUCCESS;
13389 } else {
13390 bgp = bgp_lookup_by_name(name);
13391 }
13392 } else {
13393 bgp = bgp_get_default();
13394 }
4fb25c53 13395
d62a17ae 13396 if (bgp)
13397 update_group_show(bgp, afi, safi, vty, subgrp_id);
13398 return CMD_SUCCESS;
4fb25c53
DW
13399}
13400
8fe8a7f6
DS
13401DEFUN (show_ip_bgp_updgrps,
13402 show_ip_bgp_updgrps_cmd,
c1a44e43 13403 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 13404 SHOW_STR
13405 IP_STR
13406 BGP_STR
13407 BGP_INSTANCE_HELP_STR
c9e571b4 13408 BGP_AFI_HELP_STR
9bedbb1e 13409 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
13410 "Detailed info about dynamic update groups\n"
13411 "Specific subgroup to display detailed info for\n")
8386ac43 13412{
d62a17ae 13413 char *vrf = NULL;
13414 afi_t afi = AFI_IP6;
13415 safi_t safi = SAFI_UNICAST;
13416 uint64_t subgrp_id = 0;
13417
13418 int idx = 0;
13419
13420 /* show [ip] bgp */
13421 if (argv_find(argv, argc, "ip", &idx))
13422 afi = AFI_IP;
9a8bdf1c
PG
13423 /* [<vrf> VIEWVRFNAME] */
13424 if (argv_find(argv, argc, "vrf", &idx)) {
13425 vrf = argv[idx + 1]->arg;
13426 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13427 vrf = NULL;
13428 } else if (argv_find(argv, argc, "view", &idx))
13429 /* [<view> VIEWVRFNAME] */
13430 vrf = argv[idx + 1]->arg;
d62a17ae 13431 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13432 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13433 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13434 }
5bf15956 13435
d62a17ae 13436 /* get subgroup id, if provided */
13437 idx = argc - 1;
13438 if (argv[idx]->type == VARIABLE_TKN)
13439 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 13440
d62a17ae 13441 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
13442}
13443
f186de26 13444DEFUN (show_bgp_instance_all_ipv6_updgrps,
13445 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 13446 "show [ip] bgp <view|vrf> all update-groups",
f186de26 13447 SHOW_STR
716b2d8a 13448 IP_STR
f186de26 13449 BGP_STR
13450 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 13451 "Detailed info about dynamic update groups\n")
f186de26 13452{
d62a17ae 13453 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13454 return CMD_SUCCESS;
f186de26 13455}
13456
43d3f4fc
DS
13457DEFUN (show_bgp_l2vpn_evpn_updgrps,
13458 show_bgp_l2vpn_evpn_updgrps_cmd,
13459 "show [ip] bgp l2vpn evpn update-groups",
13460 SHOW_STR
13461 IP_STR
13462 BGP_STR
13463 "l2vpn address family\n"
13464 "evpn sub-address family\n"
13465 "Detailed info about dynamic update groups\n")
13466{
13467 char *vrf = NULL;
13468 uint64_t subgrp_id = 0;
13469
13470 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13471 return CMD_SUCCESS;
13472}
13473
5bf15956
DW
13474DEFUN (show_bgp_updgrps_stats,
13475 show_bgp_updgrps_stats_cmd,
716b2d8a 13476 "show [ip] bgp update-groups statistics",
3f9c7369 13477 SHOW_STR
716b2d8a 13478 IP_STR
3f9c7369 13479 BGP_STR
0c7b1b01 13480 "Detailed info about dynamic update groups\n"
3f9c7369
DS
13481 "Statistics\n")
13482{
d62a17ae 13483 struct bgp *bgp;
3f9c7369 13484
d62a17ae 13485 bgp = bgp_get_default();
13486 if (bgp)
13487 update_group_show_stats(bgp, vty);
3f9c7369 13488
d62a17ae 13489 return CMD_SUCCESS;
3f9c7369
DS
13490}
13491
8386ac43 13492DEFUN (show_bgp_instance_updgrps_stats,
13493 show_bgp_instance_updgrps_stats_cmd,
18c57037 13494 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 13495 SHOW_STR
716b2d8a 13496 IP_STR
8386ac43 13497 BGP_STR
13498 BGP_INSTANCE_HELP_STR
0c7b1b01 13499 "Detailed info about dynamic update groups\n"
8386ac43 13500 "Statistics\n")
13501{
d62a17ae 13502 int idx_word = 3;
13503 struct bgp *bgp;
8386ac43 13504
d62a17ae 13505 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13506 if (bgp)
13507 update_group_show_stats(bgp, vty);
8386ac43 13508
d62a17ae 13509 return CMD_SUCCESS;
8386ac43 13510}
13511
d62a17ae 13512static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13513 afi_t afi, safi_t safi,
13514 const char *what, uint64_t subgrp_id)
3f9c7369 13515{
d62a17ae 13516 struct bgp *bgp;
8386ac43 13517
d62a17ae 13518 if (name)
13519 bgp = bgp_lookup_by_name(name);
13520 else
13521 bgp = bgp_get_default();
8386ac43 13522
d62a17ae 13523 if (bgp) {
13524 if (!strcmp(what, "advertise-queue"))
13525 update_group_show_adj_queue(bgp, afi, safi, vty,
13526 subgrp_id);
13527 else if (!strcmp(what, "advertised-routes"))
13528 update_group_show_advertised(bgp, afi, safi, vty,
13529 subgrp_id);
13530 else if (!strcmp(what, "packet-queue"))
13531 update_group_show_packet_queue(bgp, afi, safi, vty,
13532 subgrp_id);
13533 }
3f9c7369
DS
13534}
13535
dc64bdec
QY
13536DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13537 show_ip_bgp_instance_updgrps_adj_s_cmd,
13538 "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",
13539 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13540 BGP_SAFI_HELP_STR
13541 "Detailed info about dynamic update groups\n"
13542 "Specific subgroup to display info for\n"
13543 "Advertisement queue\n"
13544 "Announced routes\n"
13545 "Packet queue\n")
3f9c7369 13546{
dc64bdec
QY
13547 uint64_t subgrp_id = 0;
13548 afi_t afiz;
13549 safi_t safiz;
13550 if (sgid)
13551 subgrp_id = strtoull(sgid, NULL, 10);
13552
13553 if (!ip && !afi)
13554 afiz = AFI_IP6;
13555 if (!ip && afi)
13556 afiz = bgp_vty_afi_from_str(afi);
13557 if (ip && !afi)
13558 afiz = AFI_IP;
13559 if (ip && afi) {
13560 afiz = bgp_vty_afi_from_str(afi);
13561 if (afiz != AFI_IP)
13562 vty_out(vty,
13563 "%% Cannot specify both 'ip' and 'ipv6'\n");
13564 return CMD_WARNING;
13565 }
d62a17ae 13566
dc64bdec 13567 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 13568
dc64bdec 13569 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 13570 return CMD_SUCCESS;
13571}
13572
d62a17ae 13573static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13574{
13575 struct listnode *node, *nnode;
13576 struct prefix *range;
13577 struct peer *conf;
13578 struct peer *peer;
13579 char buf[PREFIX2STR_BUFFER];
13580 afi_t afi;
13581 safi_t safi;
13582 const char *peer_status;
13583 const char *af_str;
13584 int lr_count;
13585 int dynamic;
13586 int af_cfgd;
13587
13588 conf = group->conf;
13589
13590 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 13591 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 13592 group->name, conf->as);
d62a17ae 13593 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 13594 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 13595 group->name, group->bgp->as);
d62a17ae 13596 } else {
13597 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13598 }
f14e6fdb 13599
d62a17ae 13600 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13601 vty_out(vty, " Peer-group type is internal\n");
13602 else
13603 vty_out(vty, " Peer-group type is external\n");
13604
13605 /* Display AFs configured. */
13606 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
13607 FOREACH_AFI_SAFI (afi, safi) {
13608 if (conf->afc[afi][safi]) {
13609 af_cfgd = 1;
5cb5f4d0 13610 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 13611 }
05c7a1cc 13612 }
d62a17ae 13613 if (!af_cfgd)
13614 vty_out(vty, " none\n");
13615 else
13616 vty_out(vty, "\n");
13617
13618 /* Display listen ranges (for dynamic neighbors), if any */
13619 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13620 if (afi == AFI_IP)
13621 af_str = "IPv4";
13622 else if (afi == AFI_IP6)
13623 af_str = "IPv6";
13624 else
13625 af_str = "???";
13626 lr_count = listcount(group->listen_range[afi]);
13627 if (lr_count) {
13628 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13629 af_str);
13630
13631
13632 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13633 nnode, range)) {
13634 prefix2str(range, buf, sizeof(buf));
13635 vty_out(vty, " %s\n", buf);
13636 }
13637 }
13638 }
f14e6fdb 13639
d62a17ae 13640 /* Display group members and their status */
13641 if (listcount(group->peer)) {
13642 vty_out(vty, " Peer-group members:\n");
13643 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
13644 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
13645 peer_status = "Idle (Admin)";
13646 else if (CHECK_FLAG(peer->sflags,
13647 PEER_STATUS_PREFIX_OVERFLOW))
13648 peer_status = "Idle (PfxCt)";
13649 else
13650 peer_status = lookup_msg(bgp_status_msg,
13651 peer->status, NULL);
13652
13653 dynamic = peer_dynamic_neighbor(peer);
13654 vty_out(vty, " %s %s %s \n", peer->host,
13655 dynamic ? "(dynamic)" : "", peer_status);
13656 }
13657 }
f14e6fdb 13658
d62a17ae 13659 return CMD_SUCCESS;
13660}
13661
ff9959b0
QY
13662static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13663 const char *group_name)
d62a17ae 13664{
ff9959b0 13665 struct bgp *bgp;
d62a17ae 13666 struct listnode *node, *nnode;
13667 struct peer_group *group;
ff9959b0
QY
13668 bool found = false;
13669
13670 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13671
13672 if (!bgp) {
9f049418 13673 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
13674 return CMD_WARNING;
13675 }
d62a17ae 13676
13677 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
13678 if (group_name) {
13679 if (strmatch(group->name, group_name)) {
d62a17ae 13680 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
13681 found = true;
13682 break;
d62a17ae 13683 }
ff9959b0
QY
13684 } else {
13685 bgp_show_one_peer_group(vty, group);
d62a17ae 13686 }
f14e6fdb 13687 }
f14e6fdb 13688
ff9959b0 13689 if (group_name && !found)
d62a17ae 13690 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 13691
d62a17ae 13692 return CMD_SUCCESS;
f14e6fdb
DS
13693}
13694
f14e6fdb
DS
13695DEFUN (show_ip_bgp_peer_groups,
13696 show_ip_bgp_peer_groups_cmd,
18c57037 13697 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
13698 SHOW_STR
13699 IP_STR
13700 BGP_STR
8386ac43 13701 BGP_INSTANCE_HELP_STR
d6e3c605
QY
13702 "Detailed information on BGP peer groups\n"
13703 "Peer group name\n")
f14e6fdb 13704{
d62a17ae 13705 char *vrf, *pg;
d62a17ae 13706 int idx = 0;
f14e6fdb 13707
a4d82a8a
PZ
13708 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13709 : NULL;
d62a17ae 13710 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 13711
ff9959b0 13712 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 13713}
3f9c7369 13714
d6e3c605 13715
718e3744 13716/* Redistribute VTY commands. */
13717
718e3744 13718DEFUN (bgp_redistribute_ipv4,
13719 bgp_redistribute_ipv4_cmd,
40d1cbfb 13720 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 13721 "Redistribute information from another routing protocol\n"
ab0181ee 13722 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 13723{
d62a17ae 13724 VTY_DECLVAR_CONTEXT(bgp, bgp);
13725 int idx_protocol = 1;
13726 int type;
718e3744 13727
d62a17ae 13728 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13729 if (type < 0) {
13730 vty_out(vty, "%% Invalid route type\n");
13731 return CMD_WARNING_CONFIG_FAILED;
13732 }
7f323236 13733
d62a17ae 13734 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13735 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 13736}
13737
d62a17ae 13738ALIAS_HIDDEN(
13739 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
13740 "redistribute " FRR_IP_REDIST_STR_BGPD,
13741 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 13742
718e3744 13743DEFUN (bgp_redistribute_ipv4_rmap,
13744 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 13745 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 13746 "Redistribute information from another routing protocol\n"
ab0181ee 13747 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13748 "Route map reference\n"
13749 "Pointer to route-map entries\n")
13750{
d62a17ae 13751 VTY_DECLVAR_CONTEXT(bgp, bgp);
13752 int idx_protocol = 1;
13753 int idx_word = 3;
13754 int type;
13755 struct bgp_redist *red;
e923dd62 13756 bool changed;
1de27621
DA
13757 struct route_map *route_map = route_map_lookup_warn_noexist(
13758 vty, argv[idx_word]->arg);
718e3744 13759
d62a17ae 13760 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13761 if (type < 0) {
13762 vty_out(vty, "%% Invalid route type\n");
13763 return CMD_WARNING_CONFIG_FAILED;
13764 }
718e3744 13765
d62a17ae 13766 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13767 changed =
13768 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13769 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 13770}
13771
d62a17ae 13772ALIAS_HIDDEN(
13773 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
13774 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13775 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13776 "Route map reference\n"
13777 "Pointer to route-map entries\n")
596c17ba 13778
718e3744 13779DEFUN (bgp_redistribute_ipv4_metric,
13780 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 13781 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13782 "Redistribute information from another routing protocol\n"
ab0181ee 13783 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13784 "Metric for redistributed routes\n"
13785 "Default metric\n")
13786{
d62a17ae 13787 VTY_DECLVAR_CONTEXT(bgp, bgp);
13788 int idx_protocol = 1;
13789 int idx_number = 3;
13790 int type;
d7c0a89a 13791 uint32_t metric;
d62a17ae 13792 struct bgp_redist *red;
e923dd62 13793 bool changed;
d62a17ae 13794
13795 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13796 if (type < 0) {
13797 vty_out(vty, "%% Invalid route type\n");
13798 return CMD_WARNING_CONFIG_FAILED;
13799 }
13800 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13801
13802 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13803 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13804 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13805}
13806
13807ALIAS_HIDDEN(
13808 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
13809 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13810 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13811 "Metric for redistributed routes\n"
13812 "Default metric\n")
596c17ba 13813
718e3744 13814DEFUN (bgp_redistribute_ipv4_rmap_metric,
13815 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 13816 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 13817 "Redistribute information from another routing protocol\n"
ab0181ee 13818 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13819 "Route map reference\n"
13820 "Pointer to route-map entries\n"
13821 "Metric for redistributed routes\n"
13822 "Default metric\n")
13823{
d62a17ae 13824 VTY_DECLVAR_CONTEXT(bgp, bgp);
13825 int idx_protocol = 1;
13826 int idx_word = 3;
13827 int idx_number = 5;
13828 int type;
d7c0a89a 13829 uint32_t metric;
d62a17ae 13830 struct bgp_redist *red;
e923dd62 13831 bool changed;
1de27621
DA
13832 struct route_map *route_map =
13833 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13834
13835 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13836 if (type < 0) {
13837 vty_out(vty, "%% Invalid route type\n");
13838 return CMD_WARNING_CONFIG_FAILED;
13839 }
13840 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13841
13842 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13843 changed =
13844 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13845 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13846 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13847}
13848
13849ALIAS_HIDDEN(
13850 bgp_redistribute_ipv4_rmap_metric,
13851 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
13852 "redistribute " FRR_IP_REDIST_STR_BGPD
13853 " route-map WORD metric (0-4294967295)",
13854 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13855 "Route map reference\n"
13856 "Pointer to route-map entries\n"
13857 "Metric for redistributed routes\n"
13858 "Default metric\n")
596c17ba 13859
718e3744 13860DEFUN (bgp_redistribute_ipv4_metric_rmap,
13861 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 13862 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 13863 "Redistribute information from another routing protocol\n"
ab0181ee 13864 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13865 "Metric for redistributed routes\n"
13866 "Default metric\n"
13867 "Route map reference\n"
13868 "Pointer to route-map entries\n")
13869{
d62a17ae 13870 VTY_DECLVAR_CONTEXT(bgp, bgp);
13871 int idx_protocol = 1;
13872 int idx_number = 3;
13873 int idx_word = 5;
13874 int type;
d7c0a89a 13875 uint32_t metric;
d62a17ae 13876 struct bgp_redist *red;
e923dd62 13877 bool changed;
1de27621
DA
13878 struct route_map *route_map =
13879 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13880
13881 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13882 if (type < 0) {
13883 vty_out(vty, "%% Invalid route type\n");
13884 return CMD_WARNING_CONFIG_FAILED;
13885 }
13886 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13887
13888 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13889 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
13890 changed |=
13891 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13892 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13893}
13894
13895ALIAS_HIDDEN(
13896 bgp_redistribute_ipv4_metric_rmap,
13897 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
13898 "redistribute " FRR_IP_REDIST_STR_BGPD
13899 " metric (0-4294967295) route-map WORD",
13900 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13901 "Metric for redistributed routes\n"
13902 "Default metric\n"
13903 "Route map reference\n"
13904 "Pointer to route-map entries\n")
596c17ba 13905
7c8ff89e
DS
13906DEFUN (bgp_redistribute_ipv4_ospf,
13907 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 13908 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
13909 "Redistribute information from another routing protocol\n"
13910 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13911 "Non-main Kernel Routing Table\n"
13912 "Instance ID/Table ID\n")
7c8ff89e 13913{
d62a17ae 13914 VTY_DECLVAR_CONTEXT(bgp, bgp);
13915 int idx_ospf_table = 1;
13916 int idx_number = 2;
d7c0a89a
QY
13917 unsigned short instance;
13918 unsigned short protocol;
7c8ff89e 13919
d62a17ae 13920 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 13921
d62a17ae 13922 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13923 protocol = ZEBRA_ROUTE_OSPF;
13924 else
13925 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 13926
d62a17ae 13927 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13928 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
13929}
13930
d62a17ae 13931ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
13932 "redistribute <ospf|table> (1-65535)",
13933 "Redistribute information from another routing protocol\n"
13934 "Open Shortest Path First (OSPFv2)\n"
13935 "Non-main Kernel Routing Table\n"
13936 "Instance ID/Table ID\n")
596c17ba 13937
7c8ff89e
DS
13938DEFUN (bgp_redistribute_ipv4_ospf_rmap,
13939 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 13940 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
13941 "Redistribute information from another routing protocol\n"
13942 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13943 "Non-main Kernel Routing Table\n"
13944 "Instance ID/Table ID\n"
7c8ff89e
DS
13945 "Route map reference\n"
13946 "Pointer to route-map entries\n")
13947{
d62a17ae 13948 VTY_DECLVAR_CONTEXT(bgp, bgp);
13949 int idx_ospf_table = 1;
13950 int idx_number = 2;
13951 int idx_word = 4;
13952 struct bgp_redist *red;
d7c0a89a 13953 unsigned short instance;
d62a17ae 13954 int protocol;
e923dd62 13955 bool changed;
1de27621
DA
13956 struct route_map *route_map =
13957 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13958
13959 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13960 protocol = ZEBRA_ROUTE_OSPF;
13961 else
13962 protocol = ZEBRA_ROUTE_TABLE;
13963
13964 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13965 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13966 changed =
13967 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13968 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13969}
13970
13971ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
13972 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
13973 "redistribute <ospf|table> (1-65535) route-map WORD",
13974 "Redistribute information from another routing protocol\n"
13975 "Open Shortest Path First (OSPFv2)\n"
13976 "Non-main Kernel Routing Table\n"
13977 "Instance ID/Table ID\n"
13978 "Route map reference\n"
13979 "Pointer to route-map entries\n")
596c17ba 13980
7c8ff89e
DS
13981DEFUN (bgp_redistribute_ipv4_ospf_metric,
13982 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 13983 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
13984 "Redistribute information from another routing protocol\n"
13985 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13986 "Non-main Kernel Routing Table\n"
13987 "Instance ID/Table ID\n"
7c8ff89e
DS
13988 "Metric for redistributed routes\n"
13989 "Default metric\n")
13990{
d62a17ae 13991 VTY_DECLVAR_CONTEXT(bgp, bgp);
13992 int idx_ospf_table = 1;
13993 int idx_number = 2;
13994 int idx_number_2 = 4;
d7c0a89a 13995 uint32_t metric;
d62a17ae 13996 struct bgp_redist *red;
d7c0a89a 13997 unsigned short instance;
d62a17ae 13998 int protocol;
e923dd62 13999 bool changed;
d62a17ae 14000
14001 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14002 protocol = ZEBRA_ROUTE_OSPF;
14003 else
14004 protocol = ZEBRA_ROUTE_TABLE;
14005
14006 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14007 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14008
14009 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14010 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14011 metric);
14012 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14013}
14014
14015ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
14016 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
14017 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14018 "Redistribute information from another routing protocol\n"
14019 "Open Shortest Path First (OSPFv2)\n"
14020 "Non-main Kernel Routing Table\n"
14021 "Instance ID/Table ID\n"
14022 "Metric for redistributed routes\n"
14023 "Default metric\n")
596c17ba 14024
7c8ff89e
DS
14025DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
14026 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 14027 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
14028 "Redistribute information from another routing protocol\n"
14029 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14030 "Non-main Kernel Routing Table\n"
14031 "Instance ID/Table ID\n"
7c8ff89e
DS
14032 "Route map reference\n"
14033 "Pointer to route-map entries\n"
14034 "Metric for redistributed routes\n"
14035 "Default metric\n")
14036{
d62a17ae 14037 VTY_DECLVAR_CONTEXT(bgp, bgp);
14038 int idx_ospf_table = 1;
14039 int idx_number = 2;
14040 int idx_word = 4;
14041 int idx_number_2 = 6;
d7c0a89a 14042 uint32_t metric;
d62a17ae 14043 struct bgp_redist *red;
d7c0a89a 14044 unsigned short instance;
d62a17ae 14045 int protocol;
e923dd62 14046 bool changed;
1de27621
DA
14047 struct route_map *route_map =
14048 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14049
14050 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14051 protocol = ZEBRA_ROUTE_OSPF;
14052 else
14053 protocol = ZEBRA_ROUTE_TABLE;
14054
14055 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14056 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14057
14058 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
14059 changed =
14060 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14061 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14062 metric);
14063 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14064}
14065
14066ALIAS_HIDDEN(
14067 bgp_redistribute_ipv4_ospf_rmap_metric,
14068 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
14069 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14070 "Redistribute information from another routing protocol\n"
14071 "Open Shortest Path First (OSPFv2)\n"
14072 "Non-main Kernel Routing Table\n"
14073 "Instance ID/Table ID\n"
14074 "Route map reference\n"
14075 "Pointer to route-map entries\n"
14076 "Metric for redistributed routes\n"
14077 "Default metric\n")
596c17ba 14078
7c8ff89e
DS
14079DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
14080 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 14081 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
14082 "Redistribute information from another routing protocol\n"
14083 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14084 "Non-main Kernel Routing Table\n"
14085 "Instance ID/Table ID\n"
7c8ff89e
DS
14086 "Metric for redistributed routes\n"
14087 "Default metric\n"
14088 "Route map reference\n"
14089 "Pointer to route-map entries\n")
14090{
d62a17ae 14091 VTY_DECLVAR_CONTEXT(bgp, bgp);
14092 int idx_ospf_table = 1;
14093 int idx_number = 2;
14094 int idx_number_2 = 4;
14095 int idx_word = 6;
d7c0a89a 14096 uint32_t metric;
d62a17ae 14097 struct bgp_redist *red;
d7c0a89a 14098 unsigned short instance;
d62a17ae 14099 int protocol;
e923dd62 14100 bool changed;
1de27621
DA
14101 struct route_map *route_map =
14102 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14103
14104 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14105 protocol = ZEBRA_ROUTE_OSPF;
14106 else
14107 protocol = ZEBRA_ROUTE_TABLE;
14108
14109 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14110 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14111
14112 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14113 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14114 metric);
1de27621
DA
14115 changed |=
14116 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14117 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14118}
14119
14120ALIAS_HIDDEN(
14121 bgp_redistribute_ipv4_ospf_metric_rmap,
14122 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
14123 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14124 "Redistribute information from another routing protocol\n"
14125 "Open Shortest Path First (OSPFv2)\n"
14126 "Non-main Kernel Routing Table\n"
14127 "Instance ID/Table ID\n"
14128 "Metric for redistributed routes\n"
14129 "Default metric\n"
14130 "Route map reference\n"
14131 "Pointer to route-map entries\n")
596c17ba 14132
7c8ff89e
DS
14133DEFUN (no_bgp_redistribute_ipv4_ospf,
14134 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 14135 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
14136 NO_STR
14137 "Redistribute information from another routing protocol\n"
14138 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 14139 "Non-main Kernel Routing Table\n"
31500417
DW
14140 "Instance ID/Table ID\n"
14141 "Metric for redistributed routes\n"
14142 "Default metric\n"
14143 "Route map reference\n"
14144 "Pointer to route-map entries\n")
7c8ff89e 14145{
d62a17ae 14146 VTY_DECLVAR_CONTEXT(bgp, bgp);
14147 int idx_ospf_table = 2;
14148 int idx_number = 3;
d7c0a89a 14149 unsigned short instance;
d62a17ae 14150 int protocol;
14151
14152 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14153 protocol = ZEBRA_ROUTE_OSPF;
14154 else
14155 protocol = ZEBRA_ROUTE_TABLE;
14156
14157 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14158 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
14159}
14160
14161ALIAS_HIDDEN(
14162 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 14163 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14164 NO_STR
14165 "Redistribute information from another routing protocol\n"
14166 "Open Shortest Path First (OSPFv2)\n"
14167 "Non-main Kernel Routing Table\n"
14168 "Instance ID/Table ID\n"
14169 "Metric for redistributed routes\n"
14170 "Default metric\n"
14171 "Route map reference\n"
14172 "Pointer to route-map entries\n")
596c17ba 14173
718e3744 14174DEFUN (no_bgp_redistribute_ipv4,
14175 no_bgp_redistribute_ipv4_cmd,
e27957c0 14176 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14177 NO_STR
14178 "Redistribute information from another routing protocol\n"
3b14d86e 14179 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
14180 "Metric for redistributed routes\n"
14181 "Default metric\n"
14182 "Route map reference\n"
14183 "Pointer to route-map entries\n")
718e3744 14184{
d62a17ae 14185 VTY_DECLVAR_CONTEXT(bgp, bgp);
14186 int idx_protocol = 2;
14187 int type;
14188
14189 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14190 if (type < 0) {
14191 vty_out(vty, "%% Invalid route type\n");
14192 return CMD_WARNING_CONFIG_FAILED;
14193 }
14194 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
14195}
14196
14197ALIAS_HIDDEN(
14198 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
14199 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 14200 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14201 NO_STR
14202 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14203 "Metric for redistributed routes\n"
14204 "Default metric\n"
14205 "Route map reference\n"
14206 "Pointer to route-map entries\n")
596c17ba 14207
718e3744 14208DEFUN (bgp_redistribute_ipv6,
14209 bgp_redistribute_ipv6_cmd,
40d1cbfb 14210 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 14211 "Redistribute information from another routing protocol\n"
ab0181ee 14212 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 14213{
d62a17ae 14214 VTY_DECLVAR_CONTEXT(bgp, bgp);
14215 int idx_protocol = 1;
14216 int type;
718e3744 14217
d62a17ae 14218 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14219 if (type < 0) {
14220 vty_out(vty, "%% Invalid route type\n");
14221 return CMD_WARNING_CONFIG_FAILED;
14222 }
718e3744 14223
d62a17ae 14224 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14225 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 14226}
14227
14228DEFUN (bgp_redistribute_ipv6_rmap,
14229 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 14230 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 14231 "Redistribute information from another routing protocol\n"
ab0181ee 14232 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14233 "Route map reference\n"
14234 "Pointer to route-map entries\n")
14235{
d62a17ae 14236 VTY_DECLVAR_CONTEXT(bgp, bgp);
14237 int idx_protocol = 1;
14238 int idx_word = 3;
14239 int type;
14240 struct bgp_redist *red;
e923dd62 14241 bool changed;
1de27621
DA
14242 struct route_map *route_map =
14243 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 14244
d62a17ae 14245 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14246 if (type < 0) {
14247 vty_out(vty, "%% Invalid route type\n");
14248 return CMD_WARNING_CONFIG_FAILED;
14249 }
718e3744 14250
d62a17ae 14251 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14252 changed =
14253 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14254 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14255}
14256
14257DEFUN (bgp_redistribute_ipv6_metric,
14258 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 14259 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 14260 "Redistribute information from another routing protocol\n"
ab0181ee 14261 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14262 "Metric for redistributed routes\n"
14263 "Default metric\n")
14264{
d62a17ae 14265 VTY_DECLVAR_CONTEXT(bgp, bgp);
14266 int idx_protocol = 1;
14267 int idx_number = 3;
14268 int type;
d7c0a89a 14269 uint32_t metric;
d62a17ae 14270 struct bgp_redist *red;
e923dd62 14271 bool changed;
d62a17ae 14272
14273 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14274 if (type < 0) {
14275 vty_out(vty, "%% Invalid route type\n");
14276 return CMD_WARNING_CONFIG_FAILED;
14277 }
14278 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14279
d62a17ae 14280 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14281 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
14282 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14283}
14284
14285DEFUN (bgp_redistribute_ipv6_rmap_metric,
14286 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 14287 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 14288 "Redistribute information from another routing protocol\n"
ab0181ee 14289 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14290 "Route map reference\n"
14291 "Pointer to route-map entries\n"
14292 "Metric for redistributed routes\n"
14293 "Default metric\n")
14294{
d62a17ae 14295 VTY_DECLVAR_CONTEXT(bgp, bgp);
14296 int idx_protocol = 1;
14297 int idx_word = 3;
14298 int idx_number = 5;
14299 int type;
d7c0a89a 14300 uint32_t metric;
d62a17ae 14301 struct bgp_redist *red;
e923dd62 14302 bool changed;
1de27621
DA
14303 struct route_map *route_map =
14304 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14305
14306 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14307 if (type < 0) {
14308 vty_out(vty, "%% Invalid route type\n");
14309 return CMD_WARNING_CONFIG_FAILED;
14310 }
14311 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14312
d62a17ae 14313 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14314 changed =
14315 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14316 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
14317 metric);
14318 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14319}
14320
14321DEFUN (bgp_redistribute_ipv6_metric_rmap,
14322 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 14323 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 14324 "Redistribute information from another routing protocol\n"
ab0181ee 14325 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14326 "Metric for redistributed routes\n"
14327 "Default metric\n"
14328 "Route map reference\n"
14329 "Pointer to route-map entries\n")
14330{
d62a17ae 14331 VTY_DECLVAR_CONTEXT(bgp, bgp);
14332 int idx_protocol = 1;
14333 int idx_number = 3;
14334 int idx_word = 5;
14335 int type;
d7c0a89a 14336 uint32_t metric;
d62a17ae 14337 struct bgp_redist *red;
e923dd62 14338 bool changed;
1de27621
DA
14339 struct route_map *route_map =
14340 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14341
14342 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14343 if (type < 0) {
14344 vty_out(vty, "%% Invalid route type\n");
14345 return CMD_WARNING_CONFIG_FAILED;
14346 }
14347 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14348
d62a17ae 14349 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14350 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14351 metric);
1de27621
DA
14352 changed |=
14353 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14354 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14355}
14356
14357DEFUN (no_bgp_redistribute_ipv6,
14358 no_bgp_redistribute_ipv6_cmd,
e27957c0 14359 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14360 NO_STR
14361 "Redistribute information from another routing protocol\n"
3b14d86e 14362 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
14363 "Metric for redistributed routes\n"
14364 "Default metric\n"
14365 "Route map reference\n"
14366 "Pointer to route-map entries\n")
718e3744 14367{
d62a17ae 14368 VTY_DECLVAR_CONTEXT(bgp, bgp);
14369 int idx_protocol = 2;
14370 int type;
718e3744 14371
d62a17ae 14372 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14373 if (type < 0) {
14374 vty_out(vty, "%% Invalid route type\n");
14375 return CMD_WARNING_CONFIG_FAILED;
14376 }
718e3744 14377
d62a17ae 14378 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14379}
14380
dd65f45e
DL
14381static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14382 afi_t afi, safi_t safi)
d62a17ae 14383{
14384 int i;
14385
14386 /* Unicast redistribution only. */
14387 if (safi != SAFI_UNICAST)
2b791107 14388 return;
d62a17ae 14389
14390 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14391 /* Redistribute BGP does not make sense. */
14392 if (i != ZEBRA_ROUTE_BGP) {
14393 struct list *red_list;
14394 struct listnode *node;
14395 struct bgp_redist *red;
14396
14397 red_list = bgp->redist[afi][i];
14398 if (!red_list)
14399 continue;
14400
14401 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 14402 /* "redistribute" configuration. */
14403 vty_out(vty, " redistribute %s",
14404 zebra_route_string(i));
14405 if (red->instance)
14406 vty_out(vty, " %d", red->instance);
14407 if (red->redist_metric_flag)
14408 vty_out(vty, " metric %u",
14409 red->redist_metric);
14410 if (red->rmap.name)
14411 vty_out(vty, " route-map %s",
14412 red->rmap.name);
14413 vty_out(vty, "\n");
14414 }
14415 }
14416 }
718e3744 14417}
6b0655a2 14418
dd65f45e
DL
14419/* peer-group helpers for config-write */
14420
14421static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14422{
14423 if (!peer_group_active(peer)) {
14424 if (CHECK_FLAG(peer->flags_invert, flag))
14425 return !CHECK_FLAG(peer->flags, flag);
14426 else
14427 return !!CHECK_FLAG(peer->flags, flag);
14428 }
14429
14430 return !!CHECK_FLAG(peer->flags_override, flag);
14431}
14432
14433static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14434 uint32_t flag)
14435{
14436 if (!peer_group_active(peer)) {
14437 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14438 return !peer_af_flag_check(peer, afi, safi, flag);
14439 else
14440 return !!peer_af_flag_check(peer, afi, safi, flag);
14441 }
14442
14443 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14444}
14445
14446static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14447 uint8_t type, int direct)
14448{
14449 struct bgp_filter *filter;
14450
14451 if (peer_group_active(peer))
14452 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14453 type);
14454
14455 filter = &peer->filter[afi][safi];
14456 switch (type) {
14457 case PEER_FT_DISTRIBUTE_LIST:
14458 return !!(filter->dlist[direct].name);
14459 case PEER_FT_FILTER_LIST:
14460 return !!(filter->aslist[direct].name);
14461 case PEER_FT_PREFIX_LIST:
14462 return !!(filter->plist[direct].name);
14463 case PEER_FT_ROUTE_MAP:
14464 return !!(filter->map[direct].name);
14465 case PEER_FT_UNSUPPRESS_MAP:
14466 return !!(filter->usmap.name);
14467 default:
14468 return false;
14469 }
14470}
14471
14472/* Return true if the addpath type is set for peer and different from
14473 * peer-group.
14474 */
3dc339cd
DA
14475static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
14476 safi_t safi)
dd65f45e
DL
14477{
14478 enum bgp_addpath_strat type, g_type;
14479
14480 type = peer->addpath_type[afi][safi];
14481
14482 if (type != BGP_ADDPATH_NONE) {
14483 if (peer_group_active(peer)) {
14484 g_type = peer->group->conf->addpath_type[afi][safi];
14485
14486 if (type != g_type)
3dc339cd 14487 return true;
dd65f45e 14488 else
3dc339cd 14489 return false;
dd65f45e
DL
14490 }
14491
3dc339cd 14492 return true;
dd65f45e
DL
14493 }
14494
3dc339cd 14495 return false;
dd65f45e
DL
14496}
14497
b9c7bc5a 14498/* This is part of the address-family block (unicast only) */
dd65f45e 14499static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
14500 afi_t afi)
14501{
b9c7bc5a 14502 int indent = 2;
ddb5b488 14503
8a066a70 14504 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
14505 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14506 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
14507 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14508 bgp->vpn_policy[afi]
bb4f6190 14509 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
14510 else
14511 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14512 bgp->vpn_policy[afi]
14513 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14514 }
12a844a5
DS
14515 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14516 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14517 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14518 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14519 return;
14520
e70e9f8e
PZ
14521 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14522 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14523
14524 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14525
14526 } else {
14527 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14528 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14529 bgp->vpn_policy[afi].tovpn_label);
14530 }
ddb5b488
PZ
14531 }
14532 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14533 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14534 char buf[RD_ADDRSTRLEN];
b9c7bc5a 14535 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
14536 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14537 sizeof(buf)));
14538 }
14539 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14540 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14541
14542 char buf[PREFIX_STRLEN];
14543 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14544 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14545 sizeof(buf))) {
14546
b9c7bc5a
PZ
14547 vty_out(vty, "%*snexthop vpn export %s\n",
14548 indent, "", buf);
ddb5b488
PZ
14549 }
14550 }
14551 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14552 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14553 && ecommunity_cmp(
14554 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14555 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14556
14557 char *b = ecommunity_ecom2str(
14558 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14559 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14560 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
14561 XFREE(MTYPE_ECOMMUNITY_STR, b);
14562 } else {
14563 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14564 char *b = ecommunity_ecom2str(
14565 bgp->vpn_policy[afi]
14566 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14567 ECOMMUNITY_FORMAT_ROUTE_MAP,
14568 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14569 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
14570 XFREE(MTYPE_ECOMMUNITY_STR, b);
14571 }
14572 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14573 char *b = ecommunity_ecom2str(
14574 bgp->vpn_policy[afi]
14575 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14576 ECOMMUNITY_FORMAT_ROUTE_MAP,
14577 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14578 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
14579 XFREE(MTYPE_ECOMMUNITY_STR, b);
14580 }
14581 }
bb4f6190
DS
14582
14583 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 14584 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
14585 bgp->vpn_policy[afi]
14586 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 14587
301ad80a
PG
14588 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14589 char *b = ecommunity_ecom2str(
14590 bgp->vpn_policy[afi]
14591 .import_redirect_rtlist,
14592 ECOMMUNITY_FORMAT_ROUTE_MAP,
14593 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 14594
9a659715
PG
14595 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
14596 != ECOMMUNITY_SIZE)
14597 vty_out(vty, "%*srt redirect import %s\n",
14598 indent, "", b);
14599 else
14600 vty_out(vty, "%*srt redirect import %s\n",
14601 indent, "", b);
301ad80a
PG
14602 XFREE(MTYPE_ECOMMUNITY_STR, b);
14603 }
ddb5b488
PZ
14604}
14605
dd65f45e
DL
14606static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14607 afi_t afi, safi_t safi)
14608{
14609 struct bgp_filter *filter;
14610 char *addr;
14611
14612 addr = peer->host;
14613 filter = &peer->filter[afi][safi];
14614
14615 /* distribute-list. */
14616 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14617 FILTER_IN))
14618 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14619 filter->dlist[FILTER_IN].name);
14620
14621 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14622 FILTER_OUT))
14623 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14624 filter->dlist[FILTER_OUT].name);
14625
14626 /* prefix-list. */
14627 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14628 FILTER_IN))
14629 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14630 filter->plist[FILTER_IN].name);
14631
14632 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14633 FILTER_OUT))
14634 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14635 filter->plist[FILTER_OUT].name);
14636
14637 /* route-map. */
14638 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14639 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14640 filter->map[RMAP_IN].name);
14641
14642 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14643 RMAP_OUT))
14644 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14645 filter->map[RMAP_OUT].name);
14646
14647 /* unsuppress-map */
14648 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14649 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14650 filter->usmap.name);
14651
14652 /* filter-list. */
14653 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14654 FILTER_IN))
14655 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14656 filter->aslist[FILTER_IN].name);
14657
14658 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14659 FILTER_OUT))
14660 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14661 filter->aslist[FILTER_OUT].name);
14662}
14663
14664/* BGP peer configuration display function. */
14665static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14666 struct peer *peer)
14667{
14668 struct peer *g_peer = NULL;
14669 char buf[SU_ADDRSTRLEN];
14670 char *addr;
14671 int if_pg_printed = false;
14672 int if_ras_printed = false;
14673
14674 /* Skip dynamic neighbors. */
14675 if (peer_dynamic_neighbor(peer))
14676 return;
14677
14678 if (peer->conf_if)
14679 addr = peer->conf_if;
14680 else
14681 addr = peer->host;
14682
14683 /************************************
14684 ****** Global to the neighbor ******
14685 ************************************/
14686 if (peer->conf_if) {
14687 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14688 vty_out(vty, " neighbor %s interface v6only", addr);
14689 else
14690 vty_out(vty, " neighbor %s interface", addr);
14691
14692 if (peer_group_active(peer)) {
14693 vty_out(vty, " peer-group %s", peer->group->name);
14694 if_pg_printed = true;
14695 } else if (peer->as_type == AS_SPECIFIED) {
14696 vty_out(vty, " remote-as %u", peer->as);
14697 if_ras_printed = true;
14698 } else if (peer->as_type == AS_INTERNAL) {
14699 vty_out(vty, " remote-as internal");
14700 if_ras_printed = true;
14701 } else if (peer->as_type == AS_EXTERNAL) {
14702 vty_out(vty, " remote-as external");
14703 if_ras_printed = true;
14704 }
14705
14706 vty_out(vty, "\n");
14707 }
14708
14709 /* remote-as and peer-group */
14710 /* peer is a member of a peer-group */
14711 if (peer_group_active(peer)) {
14712 g_peer = peer->group->conf;
14713
14714 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14715 if (peer->as_type == AS_SPECIFIED) {
14716 vty_out(vty, " neighbor %s remote-as %u\n",
14717 addr, peer->as);
14718 } else if (peer->as_type == AS_INTERNAL) {
14719 vty_out(vty,
14720 " neighbor %s remote-as internal\n",
14721 addr);
14722 } else if (peer->as_type == AS_EXTERNAL) {
14723 vty_out(vty,
14724 " neighbor %s remote-as external\n",
14725 addr);
14726 }
14727 }
14728
14729 /* For swpX peers we displayed the peer-group
14730 * via 'neighbor swpX interface peer-group PGNAME' */
14731 if (!if_pg_printed)
14732 vty_out(vty, " neighbor %s peer-group %s\n", addr,
14733 peer->group->name);
14734 }
14735
14736 /* peer is NOT a member of a peer-group */
14737 else {
14738 /* peer is a peer-group, declare the peer-group */
14739 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
14740 vty_out(vty, " neighbor %s peer-group\n", addr);
14741 }
14742
14743 if (!if_ras_printed) {
14744 if (peer->as_type == AS_SPECIFIED) {
14745 vty_out(vty, " neighbor %s remote-as %u\n",
14746 addr, peer->as);
14747 } else if (peer->as_type == AS_INTERNAL) {
14748 vty_out(vty,
14749 " neighbor %s remote-as internal\n",
14750 addr);
14751 } else if (peer->as_type == AS_EXTERNAL) {
14752 vty_out(vty,
14753 " neighbor %s remote-as external\n",
14754 addr);
14755 }
14756 }
14757 }
14758
14759 /* local-as */
14760 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
14761 vty_out(vty, " neighbor %s local-as %u", addr,
14762 peer->change_local_as);
14763 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
14764 vty_out(vty, " no-prepend");
14765 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
14766 vty_out(vty, " replace-as");
14767 vty_out(vty, "\n");
14768 }
14769
14770 /* description */
14771 if (peer->desc) {
14772 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
14773 }
14774
14775 /* shutdown */
14776 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
14777 if (peer->tx_shutdown_message)
14778 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
14779 peer->tx_shutdown_message);
14780 else
14781 vty_out(vty, " neighbor %s shutdown\n", addr);
14782 }
14783
14784 /* bfd */
14785 if (peer->bfd_info) {
14786 if (!peer_group_active(peer) || !g_peer->bfd_info) {
14787 bgp_bfd_peer_config_write(vty, peer, addr);
14788 }
14789 }
14790
14791 /* password */
14792 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
14793 vty_out(vty, " neighbor %s password %s\n", addr,
14794 peer->password);
14795
14796 /* neighbor solo */
14797 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
14798 if (!peer_group_active(peer)) {
14799 vty_out(vty, " neighbor %s solo\n", addr);
14800 }
14801 }
14802
14803 /* BGP port */
14804 if (peer->port != BGP_PORT_DEFAULT) {
14805 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
14806 }
14807
14808 /* Local interface name */
14809 if (peer->ifname) {
14810 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
14811 }
14812
14813 /* passive */
14814 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
14815 vty_out(vty, " neighbor %s passive\n", addr);
14816
14817 /* ebgp-multihop */
14818 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
14819 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
14820 && peer->ttl == MAXTTL)) {
dd65f45e
DL
14821 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
14822 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
14823 peer->ttl);
14824 }
14825 }
14826
14827 /* ttl-security hops */
e2521429 14828 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
14829 if (!peer_group_active(peer)
14830 || g_peer->gtsm_hops != peer->gtsm_hops) {
14831 vty_out(vty, " neighbor %s ttl-security hops %d\n",
14832 addr, peer->gtsm_hops);
14833 }
14834 }
14835
14836 /* disable-connected-check */
14837 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
14838 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
14839
14840 /* enforce-first-as */
14841 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
14842 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
14843
14844 /* update-source */
14845 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
14846 if (peer->update_source)
14847 vty_out(vty, " neighbor %s update-source %s\n", addr,
14848 sockunion2str(peer->update_source, buf,
14849 SU_ADDRSTRLEN));
14850 else if (peer->update_if)
14851 vty_out(vty, " neighbor %s update-source %s\n", addr,
14852 peer->update_if);
14853 }
14854
14855 /* advertisement-interval */
14856 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
14857 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
14858 peer->routeadv);
14859
14860 /* timers */
14861 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
14862 vty_out(vty, " neighbor %s timers %u %u\n", addr,
14863 peer->keepalive, peer->holdtime);
14864
14865 /* timers connect */
14866 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
14867 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14868 peer->connect);
5d5393b9
DL
14869 /* need special-case handling for changed default values due to
14870 * config profile / version (because there is no "timers bgp connect"
14871 * command, we need to save this per-peer :/)
14872 */
14873 else if (!peer_group_active(peer) && !peer->connect &&
14874 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
14875 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14876 peer->bgp->default_connect_retry);
dd65f45e
DL
14877
14878 /* capability dynamic */
14879 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
14880 vty_out(vty, " neighbor %s capability dynamic\n", addr);
14881
14882 /* capability extended-nexthop */
14883 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
14884 if (!peer->conf_if) {
14885 if (CHECK_FLAG(peer->flags_invert,
14886 PEER_FLAG_CAPABILITY_ENHE))
14887 vty_out(vty,
14888 " no neighbor %s capability extended-nexthop\n",
14889 addr);
14890 else
14891 vty_out(vty,
14892 " neighbor %s capability extended-nexthop\n",
14893 addr);
14894 }
14895 }
14896
14897 /* dont-capability-negotiation */
14898 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
14899 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
14900
14901 /* override-capability */
14902 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
14903 vty_out(vty, " neighbor %s override-capability\n", addr);
14904
14905 /* strict-capability-match */
14906 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
14907 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
14908
14909 /* Sender side AS path loop detection. */
14910 if (peer->as_path_loop_detection)
14911 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
14912 addr);
cfd47646 14913
14914 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14915 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 14916
14917 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14918 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 14919 vty_out(vty,
14920 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
14921 } else if (CHECK_FLAG(
14922 peer->peer_gr_new_status_flag,
14923 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 14924 vty_out(vty,
14925 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
14926 } else if (
14927 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
14928 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
14929 && !(CHECK_FLAG(
14930 peer->peer_gr_new_status_flag,
14931 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
14932 vty_out(vty, " neighbor %s graceful-restart-disable\n",
14933 addr);
cfd47646 14934 }
14935 }
dd65f45e
DL
14936}
14937
14938/* BGP peer configuration display function. */
14939static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
14940 struct peer *peer, afi_t afi, safi_t safi)
14941{
14942 struct peer *g_peer = NULL;
14943 char *addr;
14944 bool flag_scomm, flag_secomm, flag_slcomm;
14945
14946 /* Skip dynamic neighbors. */
14947 if (peer_dynamic_neighbor(peer))
14948 return;
14949
14950 if (peer->conf_if)
14951 addr = peer->conf_if;
14952 else
14953 addr = peer->host;
14954
14955 /************************************
14956 ****** Per AF to the neighbor ******
14957 ************************************/
14958 if (peer_group_active(peer)) {
14959 g_peer = peer->group->conf;
14960
14961 /* If the peer-group is active but peer is not, print a 'no
14962 * activate' */
14963 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
14964 vty_out(vty, " no neighbor %s activate\n", addr);
14965 }
14966
14967 /* If the peer-group is not active but peer is, print an
14968 'activate' */
14969 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
14970 vty_out(vty, " neighbor %s activate\n", addr);
14971 }
14972 } else {
14973 if (peer->afc[afi][safi]) {
14974 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
14975 if (CHECK_FLAG(bgp->flags,
14976 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
14977 vty_out(vty, " neighbor %s activate\n",
14978 addr);
14979 }
14980 } else
14981 vty_out(vty, " neighbor %s activate\n", addr);
14982 } else {
14983 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
14984 if (!CHECK_FLAG(bgp->flags,
14985 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
14986 vty_out(vty,
14987 " no neighbor %s activate\n",
14988 addr);
14989 }
14990 }
14991 }
14992 }
14993
14994 /* addpath TX knobs */
14995 if (peergroup_af_addpath_check(peer, afi, safi)) {
14996 switch (peer->addpath_type[afi][safi]) {
14997 case BGP_ADDPATH_ALL:
14998 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
14999 addr);
15000 break;
15001 case BGP_ADDPATH_BEST_PER_AS:
15002 vty_out(vty,
15003 " neighbor %s addpath-tx-bestpath-per-AS\n",
15004 addr);
15005 break;
15006 case BGP_ADDPATH_MAX:
15007 case BGP_ADDPATH_NONE:
15008 break;
15009 }
15010 }
15011
15012 /* ORF capability. */
15013 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
15014 || peergroup_af_flag_check(peer, afi, safi,
15015 PEER_FLAG_ORF_PREFIX_RM)) {
15016 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
15017
15018 if (peergroup_af_flag_check(peer, afi, safi,
15019 PEER_FLAG_ORF_PREFIX_SM)
15020 && peergroup_af_flag_check(peer, afi, safi,
15021 PEER_FLAG_ORF_PREFIX_RM))
15022 vty_out(vty, " both");
15023 else if (peergroup_af_flag_check(peer, afi, safi,
15024 PEER_FLAG_ORF_PREFIX_SM))
15025 vty_out(vty, " send");
15026 else
15027 vty_out(vty, " receive");
15028 vty_out(vty, "\n");
15029 }
15030
dd65f45e
DL
15031 /* Route reflector client. */
15032 if (peergroup_af_flag_check(peer, afi, safi,
15033 PEER_FLAG_REFLECTOR_CLIENT)) {
15034 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
15035 }
15036
15037 /* next-hop-self force */
15038 if (peergroup_af_flag_check(peer, afi, safi,
15039 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
15040 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
15041 }
15042
15043 /* next-hop-self */
15044 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
15045 vty_out(vty, " neighbor %s next-hop-self\n", addr);
15046 }
15047
15048 /* remove-private-AS */
15049 if (peergroup_af_flag_check(peer, afi, safi,
15050 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
15051 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
15052 addr);
15053 }
15054
15055 else if (peergroup_af_flag_check(peer, afi, safi,
15056 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
15057 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
15058 addr);
15059 }
15060
15061 else if (peergroup_af_flag_check(peer, afi, safi,
15062 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
15063 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
15064 }
15065
15066 else if (peergroup_af_flag_check(peer, afi, safi,
15067 PEER_FLAG_REMOVE_PRIVATE_AS)) {
15068 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
15069 }
15070
15071 /* as-override */
15072 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
15073 vty_out(vty, " neighbor %s as-override\n", addr);
15074 }
15075
15076 /* send-community print. */
15077 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
15078 PEER_FLAG_SEND_COMMUNITY);
15079 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
15080 PEER_FLAG_SEND_EXT_COMMUNITY);
15081 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
15082 PEER_FLAG_SEND_LARGE_COMMUNITY);
15083
15084 if (flag_scomm && flag_secomm && flag_slcomm) {
15085 vty_out(vty, " no neighbor %s send-community all\n", addr);
15086 } else {
15087 if (flag_scomm)
15088 vty_out(vty, " no neighbor %s send-community\n", addr);
15089 if (flag_secomm)
15090 vty_out(vty,
15091 " no neighbor %s send-community extended\n",
15092 addr);
15093
15094 if (flag_slcomm)
15095 vty_out(vty, " no neighbor %s send-community large\n",
15096 addr);
15097 }
15098
15099 /* Default information */
15100 if (peergroup_af_flag_check(peer, afi, safi,
15101 PEER_FLAG_DEFAULT_ORIGINATE)) {
15102 vty_out(vty, " neighbor %s default-originate", addr);
15103
15104 if (peer->default_rmap[afi][safi].name)
15105 vty_out(vty, " route-map %s",
15106 peer->default_rmap[afi][safi].name);
15107
15108 vty_out(vty, "\n");
15109 }
15110
15111 /* Soft reconfiguration inbound. */
15112 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
15113 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
15114 addr);
15115 }
15116
15117 /* maximum-prefix. */
15118 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 15119 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
15120 peer->pmax[afi][safi]);
15121
15122 if (peer->pmax_threshold[afi][safi]
15123 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
15124 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
15125 if (peer_af_flag_check(peer, afi, safi,
15126 PEER_FLAG_MAX_PREFIX_WARNING))
15127 vty_out(vty, " warning-only");
15128 if (peer->pmax_restart[afi][safi])
15129 vty_out(vty, " restart %u",
15130 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
15131 if (peer_af_flag_check(peer, afi, safi,
15132 PEER_FLAG_MAX_PREFIX_FORCE))
15133 vty_out(vty, " force");
dd65f45e
DL
15134
15135 vty_out(vty, "\n");
15136 }
15137
fde246e8
DA
15138 /* maximum-prefix-out */
15139 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 15140 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
15141 addr, peer->pmax_out[afi][safi]);
15142
dd65f45e
DL
15143 /* Route server client. */
15144 if (peergroup_af_flag_check(peer, afi, safi,
15145 PEER_FLAG_RSERVER_CLIENT)) {
15146 vty_out(vty, " neighbor %s route-server-client\n", addr);
15147 }
15148
15149 /* Nexthop-local unchanged. */
15150 if (peergroup_af_flag_check(peer, afi, safi,
15151 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
15152 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
15153 }
15154
15155 /* allowas-in <1-10> */
15156 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
15157 if (peer_af_flag_check(peer, afi, safi,
15158 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
15159 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
15160 } else if (peer->allowas_in[afi][safi] == 3) {
15161 vty_out(vty, " neighbor %s allowas-in\n", addr);
15162 } else {
15163 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
15164 peer->allowas_in[afi][safi]);
15165 }
15166 }
15167
15168 /* weight */
15169 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
15170 vty_out(vty, " neighbor %s weight %lu\n", addr,
15171 peer->weight[afi][safi]);
15172
15173 /* Filter. */
15174 bgp_config_write_filter(vty, peer, afi, safi);
15175
15176 /* atribute-unchanged. */
15177 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
15178 || (safi != SAFI_EVPN
15179 && peer_af_flag_check(peer, afi, safi,
15180 PEER_FLAG_NEXTHOP_UNCHANGED))
15181 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
15182
15183 if (!peer_group_active(peer)
15184 || peergroup_af_flag_check(peer, afi, safi,
15185 PEER_FLAG_AS_PATH_UNCHANGED)
15186 || peergroup_af_flag_check(peer, afi, safi,
15187 PEER_FLAG_NEXTHOP_UNCHANGED)
15188 || peergroup_af_flag_check(peer, afi, safi,
15189 PEER_FLAG_MED_UNCHANGED)) {
15190
15191 vty_out(vty,
15192 " neighbor %s attribute-unchanged%s%s%s\n",
15193 addr,
15194 peer_af_flag_check(peer, afi, safi,
15195 PEER_FLAG_AS_PATH_UNCHANGED)
15196 ? " as-path"
15197 : "",
15198 peer_af_flag_check(peer, afi, safi,
15199 PEER_FLAG_NEXTHOP_UNCHANGED)
15200 ? " next-hop"
15201 : "",
15202 peer_af_flag_check(peer, afi, safi,
15203 PEER_FLAG_MED_UNCHANGED)
15204 ? " med"
15205 : "");
15206 }
15207 }
15208}
15209
15210/* Address family based peer configuration display. */
15211static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
15212 safi_t safi)
15213{
15214 struct peer *peer;
15215 struct peer_group *group;
15216 struct listnode *node, *nnode;
15217
15218
15219 vty_frame(vty, " !\n address-family ");
15220 if (afi == AFI_IP) {
15221 if (safi == SAFI_UNICAST)
15222 vty_frame(vty, "ipv4 unicast");
15223 else if (safi == SAFI_LABELED_UNICAST)
15224 vty_frame(vty, "ipv4 labeled-unicast");
15225 else if (safi == SAFI_MULTICAST)
15226 vty_frame(vty, "ipv4 multicast");
15227 else if (safi == SAFI_MPLS_VPN)
15228 vty_frame(vty, "ipv4 vpn");
15229 else if (safi == SAFI_ENCAP)
15230 vty_frame(vty, "ipv4 encap");
15231 else if (safi == SAFI_FLOWSPEC)
15232 vty_frame(vty, "ipv4 flowspec");
15233 } else if (afi == AFI_IP6) {
15234 if (safi == SAFI_UNICAST)
15235 vty_frame(vty, "ipv6 unicast");
15236 else if (safi == SAFI_LABELED_UNICAST)
15237 vty_frame(vty, "ipv6 labeled-unicast");
15238 else if (safi == SAFI_MULTICAST)
15239 vty_frame(vty, "ipv6 multicast");
15240 else if (safi == SAFI_MPLS_VPN)
15241 vty_frame(vty, "ipv6 vpn");
15242 else if (safi == SAFI_ENCAP)
15243 vty_frame(vty, "ipv6 encap");
15244 else if (safi == SAFI_FLOWSPEC)
15245 vty_frame(vty, "ipv6 flowspec");
15246 } else if (afi == AFI_L2VPN) {
15247 if (safi == SAFI_EVPN)
15248 vty_frame(vty, "l2vpn evpn");
15249 }
15250 vty_frame(vty, "\n");
15251
15252 bgp_config_write_distance(vty, bgp, afi, safi);
15253
15254 bgp_config_write_network(vty, bgp, afi, safi);
15255
15256 bgp_config_write_redistribute(vty, bgp, afi, safi);
15257
8a4e7fe6
DA
15258 /* BGP flag dampening. */
15259 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
15260 bgp_config_write_damp(vty, afi, safi);
15261
dd65f45e
DL
15262 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
15263 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
15264
15265 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15266 /* Skip dynamic neighbors. */
15267 if (peer_dynamic_neighbor(peer))
15268 continue;
15269
15270 /* Do not display doppelganger peers */
15271 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15272 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
15273 }
15274
15275 bgp_config_write_maxpaths(vty, bgp, afi, safi);
15276 bgp_config_write_table_map(vty, bgp, afi, safi);
15277
15278 if (safi == SAFI_EVPN)
15279 bgp_config_write_evpn_info(vty, bgp, afi, safi);
15280
15281 if (safi == SAFI_FLOWSPEC)
15282 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
15283
15284 if (safi == SAFI_UNICAST) {
15285 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
15286 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15287 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
15288
15289 vty_out(vty, " export vpn\n");
15290 }
15291 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15292 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
15293
15294 vty_out(vty, " import vpn\n");
15295 }
15296 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15297 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15298 char *name;
15299
15300 for (ALL_LIST_ELEMENTS_RO(
15301 bgp->vpn_policy[afi].import_vrf, node,
15302 name))
15303 vty_out(vty, " import vrf %s\n", name);
15304 }
15305 }
15306
15307 vty_endframe(vty, " exit-address-family\n");
15308}
15309
15310int bgp_config_write(struct vty *vty)
15311{
15312 struct bgp *bgp;
15313 struct peer_group *group;
15314 struct peer *peer;
15315 struct listnode *node, *nnode;
15316 struct listnode *mnode, *mnnode;
15317
15318 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
15319 vty_out(vty, "bgp route-map delay-timer %u\n",
15320 bm->rmap_update_timer);
15321
15322 /* BGP configuration. */
15323 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
15324
15325 /* skip all auto created vrf as they dont have user config */
15326 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
15327 continue;
15328
15329 /* Router bgp ASN */
15330 vty_out(vty, "router bgp %u", bgp->as);
15331
15332 if (bgp->name)
15333 vty_out(vty, " %s %s",
15334 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
15335 ? "view" : "vrf", bgp->name);
15336 vty_out(vty, "\n");
15337
15338 /* BGP fast-external-failover. */
15339 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
15340 vty_out(vty, " no bgp fast-external-failover\n");
15341
15342 /* BGP router ID. */
15343 if (bgp->router_id_static.s_addr != 0)
15344 vty_out(vty, " bgp router-id %s\n",
15345 inet_ntoa(bgp->router_id_static));
15346
15347 /* BGP log-neighbor-changes. */
892fedb6 15348 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 15349 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 15350 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
15351 CHECK_FLAG(bgp->flags,
15352 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
15353 ? ""
15354 : "no ");
15355
15356 /* BGP configuration. */
892fedb6 15357 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
15358 vty_out(vty, " bgp always-compare-med\n");
15359
15360 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
15361 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
15362 != SAVE_BGP_EBGP_REQUIRES_POLICY)
15363 vty_out(vty, " %sbgp ebgp-requires-policy\n",
15364 CHECK_FLAG(bgp->flags,
15365 BGP_FLAG_EBGP_REQUIRES_POLICY)
15366 ? ""
15367 : "no ");
dd65f45e
DL
15368
15369 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 15370 if (bgp->reject_as_sets)
dd65f45e
DL
15371 vty_out(vty, " bgp reject-as-sets\n");
15372
15373 /* BGP default ipv4-unicast. */
892fedb6 15374 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
15375 vty_out(vty, " no bgp default ipv4-unicast\n");
15376
15377 /* BGP default local-preference. */
15378 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15379 vty_out(vty, " bgp default local-preference %u\n",
15380 bgp->default_local_pref);
15381
15382 /* BGP default show-hostname */
892fedb6 15383 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 15384 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 15385 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 15386 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
15387 ? ""
15388 : "no ");
15389
aef999a2
DA
15390 /* BGP default show-nexthop-hostname */
15391 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15392 != SAVE_BGP_SHOW_HOSTNAME)
15393 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
15394 CHECK_FLAG(bgp->flags,
15395 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15396 ? ""
15397 : "no ");
15398
dd65f45e
DL
15399 /* BGP default subgroup-pkt-queue-max. */
15400 if (bgp->default_subgroup_pkt_queue_max
15401 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15402 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15403 bgp->default_subgroup_pkt_queue_max);
15404
15405 /* BGP client-to-client reflection. */
892fedb6 15406 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
15407 vty_out(vty, " no bgp client-to-client reflection\n");
15408
15409 /* BGP cluster ID. */
15410 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15411 vty_out(vty, " bgp cluster-id %s\n",
15412 inet_ntoa(bgp->cluster_id));
15413
15414 /* Disable ebgp connected nexthop check */
892fedb6 15415 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
15416 vty_out(vty,
15417 " bgp disable-ebgp-connected-route-check\n");
15418
15419 /* Confederation identifier*/
15420 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15421 vty_out(vty, " bgp confederation identifier %u\n",
15422 bgp->confed_id);
15423
15424 /* Confederation peer */
15425 if (bgp->confed_peers_cnt > 0) {
15426 int i;
15427
15428 vty_out(vty, " bgp confederation peers");
15429
15430 for (i = 0; i < bgp->confed_peers_cnt; i++)
15431 vty_out(vty, " %u", bgp->confed_peers[i]);
15432
15433 vty_out(vty, "\n");
15434 }
15435
15436 /* BGP deterministic-med. */
892fedb6 15437 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 15438 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 15439 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
15440 CHECK_FLAG(bgp->flags,
15441 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
15442 ? ""
15443 : "no ");
15444
15445 /* BGP update-delay. */
15446 bgp_config_write_update_delay(vty, bgp);
15447
15448 if (bgp->v_maxmed_onstartup
15449 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15450 vty_out(vty, " bgp max-med on-startup %u",
15451 bgp->v_maxmed_onstartup);
15452 if (bgp->maxmed_onstartup_value
15453 != BGP_MAXMED_VALUE_DEFAULT)
15454 vty_out(vty, " %u",
15455 bgp->maxmed_onstartup_value);
15456 vty_out(vty, "\n");
15457 }
15458 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15459 vty_out(vty, " bgp max-med administrative");
15460 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15461 vty_out(vty, " %u", bgp->maxmed_admin_value);
15462 vty_out(vty, "\n");
15463 }
15464
15465 /* write quanta */
15466 bgp_config_write_wpkt_quanta(vty, bgp);
15467 /* read quanta */
15468 bgp_config_write_rpkt_quanta(vty, bgp);
15469
15470 /* coalesce time */
15471 bgp_config_write_coalesce_time(vty, bgp);
15472
15473 /* BGP graceful-restart. */
15474 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15475 vty_out(vty,
15476 " bgp graceful-restart stalepath-time %u\n",
15477 bgp->stalepath_time);
cfd47646 15478
dd65f45e
DL
15479 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15480 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15481 bgp->restart_time);
cfd47646 15482
15483 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15484 vty_out(vty,
15485 " bgp graceful-restart select-defer-time %u\n",
15486 bgp->select_defer_time);
15487
15488 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
15489 vty_out(vty, " bgp graceful-restart\n");
15490
cfd47646 15491 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15492 vty_out(vty, " bgp graceful-restart-disable\n");
15493
dd65f45e 15494 /* BGP graceful-shutdown */
892fedb6 15495 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
dd65f45e
DL
15496 vty_out(vty, " bgp graceful-shutdown\n");
15497
15498 /* BGP graceful-restart Preserve State F bit. */
892fedb6 15499 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
15500 vty_out(vty,
15501 " bgp graceful-restart preserve-fw-state\n");
15502
dc95985f 15503 /* Stale timer for RIB */
15504 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15505 vty_out(vty,
15506 " bgp graceful-restart rib-stale-time %u\n",
15507 bgp->rib_stale_time);
15508
dd65f45e 15509 /* BGP bestpath method. */
892fedb6 15510 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 15511 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 15512 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
15513 vty_out(vty, " bgp bestpath as-path confed\n");
15514
892fedb6
DA
15515 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15516 if (CHECK_FLAG(bgp->flags,
15517 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
15518 vty_out(vty,
15519 " bgp bestpath as-path multipath-relax as-set\n");
15520 } else {
15521 vty_out(vty,
15522 " bgp bestpath as-path multipath-relax\n");
15523 }
15524 }
15525
892fedb6 15526 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
15527 vty_out(vty,
15528 " bgp route-reflector allow-outbound-policy\n");
15529 }
892fedb6 15530 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 15531 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
15532 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
15533 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 15534 vty_out(vty, " bgp bestpath med");
892fedb6 15535 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 15536 vty_out(vty, " confed");
892fedb6
DA
15537 if (CHECK_FLAG(bgp->flags,
15538 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
15539 vty_out(vty, " missing-as-worst");
15540 vty_out(vty, "\n");
15541 }
15542
f7e1c681 15543 /* Link bandwidth handling. */
15544 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
15545 vty_out(vty, " bgp bestpath bandwidth ignore\n");
15546 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
15547 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
15548 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
15549 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
15550
dd65f45e 15551 /* BGP network import check. */
892fedb6 15552 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 15553 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 15554 vty_out(vty, " %sbgp network import-check\n",
892fedb6 15555 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
15556 ? ""
15557 : "no ");
15558
15559 /* BGP timers configuration. */
5d5393b9
DL
15560 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15561 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
15562 vty_out(vty, " timers bgp %u %u\n",
15563 bgp->default_keepalive, bgp->default_holdtime);
15564
15565 /* peer-group */
15566 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15567 bgp_config_write_peer_global(vty, bgp, group->conf);
15568 }
15569
15570 /* Normal neighbor configuration. */
15571 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15572 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15573 bgp_config_write_peer_global(vty, bgp, peer);
15574 }
15575
15576 /* listen range and limit for dynamic BGP neighbors */
15577 bgp_config_write_listen(vty, bgp);
15578
15579 /*
15580 * BGP default autoshutdown neighbors
15581 *
15582 * This must be placed after any peer and peer-group
15583 * configuration, to avoid setting all peers to shutdown after
15584 * a daemon restart, which is undesired behavior. (see #2286)
15585 */
15586 if (bgp->autoshutdown)
15587 vty_out(vty, " bgp default shutdown\n");
15588
15589 /* IPv4 unicast configuration. */
15590 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15591
15592 /* IPv4 multicast configuration. */
15593 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15594
15595 /* IPv4 labeled-unicast configuration. */
15596 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15597
15598 /* IPv4 VPN configuration. */
15599 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15600
15601 /* ENCAPv4 configuration. */
15602 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15603
15604 /* FLOWSPEC v4 configuration. */
15605 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15606
15607 /* IPv6 unicast configuration. */
15608 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15609
15610 /* IPv6 multicast configuration. */
15611 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15612
15613 /* IPv6 labeled-unicast configuration. */
15614 bgp_config_write_family(vty, bgp, AFI_IP6,
15615 SAFI_LABELED_UNICAST);
15616
15617 /* IPv6 VPN configuration. */
15618 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15619
15620 /* ENCAPv6 configuration. */
15621 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15622
15623 /* FLOWSPEC v6 configuration. */
15624 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15625
15626 /* EVPN configuration. */
15627 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15628
15629 hook_call(bgp_inst_config_write, bgp, vty);
15630
49e5a4a0 15631#ifdef ENABLE_BGP_VNC
dd65f45e
DL
15632 bgp_rfapi_cfg_write(vty, bgp);
15633#endif
15634
15635 vty_out(vty, "!\n");
15636 }
15637 return 0;
15638}
15639
ddb5b488 15640
718e3744 15641/* BGP node structure. */
d62a17ae 15642static struct cmd_node bgp_node = {
f4b8291f 15643 .name = "bgp",
62b346ee 15644 .node = BGP_NODE,
24389580 15645 .parent_node = CONFIG_NODE,
62b346ee 15646 .prompt = "%s(config-router)# ",
612c2c15 15647 .config_write = bgp_config_write,
718e3744 15648};
15649
d62a17ae 15650static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 15651 .name = "bgp ipv4 unicast",
62b346ee 15652 .node = BGP_IPV4_NODE,
24389580 15653 .parent_node = BGP_NODE,
62b346ee 15654 .prompt = "%s(config-router-af)# ",
718e3744 15655};
15656
d62a17ae 15657static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 15658 .name = "bgp ipv4 multicast",
62b346ee 15659 .node = BGP_IPV4M_NODE,
24389580 15660 .parent_node = BGP_NODE,
62b346ee 15661 .prompt = "%s(config-router-af)# ",
718e3744 15662};
15663
d62a17ae 15664static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 15665 .name = "bgp ipv4 labeled unicast",
62b346ee 15666 .node = BGP_IPV4L_NODE,
24389580 15667 .parent_node = BGP_NODE,
62b346ee 15668 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
15669};
15670
d62a17ae 15671static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 15672 .name = "bgp ipv6",
62b346ee 15673 .node = BGP_IPV6_NODE,
24389580 15674 .parent_node = BGP_NODE,
62b346ee 15675 .prompt = "%s(config-router-af)# ",
718e3744 15676};
15677
d62a17ae 15678static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 15679 .name = "bgp ipv6 multicast",
62b346ee 15680 .node = BGP_IPV6M_NODE,
24389580 15681 .parent_node = BGP_NODE,
62b346ee 15682 .prompt = "%s(config-router-af)# ",
25ffbdc1 15683};
15684
d62a17ae 15685static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 15686 .name = "bgp ipv6 labeled unicast",
62b346ee 15687 .node = BGP_IPV6L_NODE,
24389580 15688 .parent_node = BGP_NODE,
62b346ee 15689 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
15690};
15691
62b346ee 15692static struct cmd_node bgp_vpnv4_node = {
f4b8291f 15693 .name = "bgp vpnv4",
62b346ee 15694 .node = BGP_VPNV4_NODE,
24389580 15695 .parent_node = BGP_NODE,
62b346ee 15696 .prompt = "%s(config-router-af)# ",
62b346ee 15697};
6b0655a2 15698
62b346ee 15699static struct cmd_node bgp_vpnv6_node = {
f4b8291f 15700 .name = "bgp vpnv6",
62b346ee 15701 .node = BGP_VPNV6_NODE,
24389580 15702 .parent_node = BGP_NODE,
62b346ee 15703 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 15704};
8ecd3266 15705
62b346ee 15706static struct cmd_node bgp_evpn_node = {
f4b8291f 15707 .name = "bgp evpn",
62b346ee 15708 .node = BGP_EVPN_NODE,
24389580 15709 .parent_node = BGP_NODE,
62b346ee 15710 .prompt = "%s(config-router-evpn)# ",
62b346ee 15711};
4e0b7b6d 15712
62b346ee 15713static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 15714 .name = "bgp evpn vni",
62b346ee 15715 .node = BGP_EVPN_VNI_NODE,
24389580 15716 .parent_node = BGP_EVPN_NODE,
62b346ee 15717 .prompt = "%s(config-router-af-vni)# ",
62b346ee 15718};
90e60aa7 15719
62b346ee 15720static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 15721 .name = "bgp ipv4 flowspec",
62b346ee 15722 .node = BGP_FLOWSPECV4_NODE,
24389580 15723 .parent_node = BGP_NODE,
62b346ee 15724 .prompt = "%s(config-router-af)# ",
62b346ee 15725};
7c40bf39 15726
62b346ee 15727static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 15728 .name = "bgp ipv6 flowspec",
62b346ee 15729 .node = BGP_FLOWSPECV6_NODE,
24389580 15730 .parent_node = BGP_NODE,
62b346ee 15731 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 15732};
7c40bf39 15733
d62a17ae 15734static void community_list_vty(void);
1f8ae70b 15735
d62a17ae 15736static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 15737{
d62a17ae 15738 struct bgp *bgp;
15739 struct peer *peer;
d62a17ae 15740 struct listnode *lnbgp, *lnpeer;
b8a815e5 15741
d62a17ae 15742 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15743 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
15744 /* only provide suggestions on the appropriate input
15745 * token type,
15746 * they'll otherwise show up multiple times */
15747 enum cmd_token_type match_type;
15748 char *name = peer->host;
d48ed3e0 15749
d62a17ae 15750 if (peer->conf_if) {
15751 match_type = VARIABLE_TKN;
15752 name = peer->conf_if;
15753 } else if (strchr(peer->host, ':'))
15754 match_type = IPV6_TKN;
15755 else
15756 match_type = IPV4_TKN;
d48ed3e0 15757
d62a17ae 15758 if (token->type != match_type)
15759 continue;
d48ed3e0 15760
d62a17ae 15761 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
15762 }
d62a17ae 15763 }
b8a815e5
DL
15764}
15765
15766static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 15767 {.varname = "neighbor", .completions = bgp_ac_neighbor},
15768 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 15769 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 15770 {.completions = NULL}};
15771
47a306a0
DS
15772static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
15773{
15774 struct bgp *bgp;
15775 struct peer_group *group;
15776 struct listnode *lnbgp, *lnpeer;
15777
15778 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15779 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
15780 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
15781 group->name));
15782 }
15783}
15784
15785static const struct cmd_variable_handler bgp_var_peergroup[] = {
15786 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
15787 {.completions = NULL} };
15788
d62a17ae 15789void bgp_vty_init(void)
15790{
15791 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 15792 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 15793
15794 /* Install bgp top node. */
612c2c15
DL
15795 install_node(&bgp_node);
15796 install_node(&bgp_ipv4_unicast_node);
15797 install_node(&bgp_ipv4_multicast_node);
15798 install_node(&bgp_ipv4_labeled_unicast_node);
15799 install_node(&bgp_ipv6_unicast_node);
15800 install_node(&bgp_ipv6_multicast_node);
15801 install_node(&bgp_ipv6_labeled_unicast_node);
15802 install_node(&bgp_vpnv4_node);
15803 install_node(&bgp_vpnv6_node);
15804 install_node(&bgp_evpn_node);
15805 install_node(&bgp_evpn_vni_node);
15806 install_node(&bgp_flowspecv4_node);
15807 install_node(&bgp_flowspecv6_node);
d62a17ae 15808
15809 /* Install default VTY commands to new nodes. */
15810 install_default(BGP_NODE);
15811 install_default(BGP_IPV4_NODE);
15812 install_default(BGP_IPV4M_NODE);
15813 install_default(BGP_IPV4L_NODE);
15814 install_default(BGP_IPV6_NODE);
15815 install_default(BGP_IPV6M_NODE);
15816 install_default(BGP_IPV6L_NODE);
15817 install_default(BGP_VPNV4_NODE);
15818 install_default(BGP_VPNV6_NODE);
7c40bf39 15819 install_default(BGP_FLOWSPECV4_NODE);
15820 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 15821 install_default(BGP_EVPN_NODE);
15822 install_default(BGP_EVPN_VNI_NODE);
15823
8029b216
AK
15824 /* "bgp local-mac" hidden commands. */
15825 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
15826 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
15827
d62a17ae 15828 /* bgp route-map delay-timer commands. */
15829 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
15830 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15831
15832 /* Dummy commands (Currently not supported) */
15833 install_element(BGP_NODE, &no_synchronization_cmd);
15834 install_element(BGP_NODE, &no_auto_summary_cmd);
15835
15836 /* "router bgp" commands. */
15837 install_element(CONFIG_NODE, &router_bgp_cmd);
15838
15839 /* "no router bgp" commands. */
15840 install_element(CONFIG_NODE, &no_router_bgp_cmd);
15841
15842 /* "bgp router-id" commands. */
15843 install_element(BGP_NODE, &bgp_router_id_cmd);
15844 install_element(BGP_NODE, &no_bgp_router_id_cmd);
15845
15846 /* "bgp cluster-id" commands. */
15847 install_element(BGP_NODE, &bgp_cluster_id_cmd);
15848 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
15849
15850 /* "bgp confederation" commands. */
15851 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
15852 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
15853
15854 /* "bgp confederation peers" commands. */
15855 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
15856 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
15857
15858 /* bgp max-med command */
15859 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
15860 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
15861 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
15862 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
15863 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
15864
15865 /* bgp disable-ebgp-connected-nh-check */
15866 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
15867 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
15868
15869 /* bgp update-delay command */
15870 install_element(BGP_NODE, &bgp_update_delay_cmd);
15871 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
15872 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
15873
15874 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 15875 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 15876
15877 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
15878 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
15879
15880 /* "maximum-paths" commands. */
15881 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
15882 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
15883 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
15884 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
15885 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
15886 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
15887 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
15888 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
15889 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
15890 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
15891 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15892 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
15893 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
15894 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15895 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
15896
39edabac
PG
15897 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
15898 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
15899 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
15900 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15901 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 15902 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
15903 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
15904 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
15905 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15906 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15907
15908 /* "timers bgp" commands. */
15909 install_element(BGP_NODE, &bgp_timers_cmd);
15910 install_element(BGP_NODE, &no_bgp_timers_cmd);
15911
15912 /* route-map delay-timer commands - per instance for backwards compat.
15913 */
15914 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
15915 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15916
15917 /* "bgp client-to-client reflection" commands */
15918 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
15919 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
15920
15921 /* "bgp always-compare-med" commands */
15922 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
15923 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
15924
9dac9fc8
DA
15925 /* bgp ebgp-requires-policy */
15926 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
15927 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
15928
fb29348a
DA
15929 /* bgp reject-as-sets */
15930 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
15931 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
15932
d62a17ae 15933 /* "bgp deterministic-med" commands */
15934 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
15935 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
15936
055679e9 15937 /* "bgp graceful-restart" command */
36235319
QY
15938 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
15939 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 15940
15941 /* "bgp graceful-restart-disable" command */
36235319
QY
15942 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
15943 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 15944
15945 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
15946 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
15947 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 15948
15949 /* "neighbor a:b:c:d graceful-restart-disable" command */
15950 install_element(BGP_NODE,
15951 &bgp_neighbor_graceful_restart_disable_set_cmd);
15952 install_element(BGP_NODE,
15953 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
15954
15955 /* "neighbor a:b:c:d graceful-restart-helper" command */
15956 install_element(BGP_NODE,
15957 &bgp_neighbor_graceful_restart_helper_set_cmd);
15958 install_element(BGP_NODE,
15959 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
15960
d62a17ae 15961 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
15962 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
15963 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
15964 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 15965 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 15966 install_element(BGP_NODE,
15967 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 15968 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
15969 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
15970
d6e3c15b 15971 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
15972 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 15973 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
15974 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 15975
7f323236
DW
15976 /* "bgp graceful-shutdown" commands */
15977 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
15978 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
15979
d62a17ae 15980 /* "bgp fast-external-failover" commands */
15981 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
15982 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
15983
d62a17ae 15984 /* "bgp bestpath compare-routerid" commands */
15985 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
15986 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
15987
15988 /* "bgp bestpath as-path ignore" commands */
15989 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
15990 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
15991
15992 /* "bgp bestpath as-path confed" commands */
15993 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
15994 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
15995
15996 /* "bgp bestpath as-path multipath-relax" commands */
15997 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
15998 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
15999
16000 /* "bgp log-neighbor-changes" commands */
16001 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
16002 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
16003
16004 /* "bgp bestpath med" commands */
16005 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
16006 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
16007
f7e1c681 16008 /* "bgp bestpath bandwidth" commands */
16009 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 16010 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 16011
d62a17ae 16012 /* "no bgp default ipv4-unicast" commands. */
16013 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
16014 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
16015
16016 /* "bgp network import-check" commands. */
16017 install_element(BGP_NODE, &bgp_network_import_check_cmd);
16018 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
16019 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
16020
16021 /* "bgp default local-preference" commands. */
16022 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
16023 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
16024
16025 /* bgp default show-hostname */
16026 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
16027 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
16028
aef999a2
DA
16029 /* bgp default show-nexthop-hostname */
16030 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
16031 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
16032
d62a17ae 16033 /* "bgp default subgroup-pkt-queue-max" commands. */
16034 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
16035 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
16036
16037 /* bgp ibgp-allow-policy-mods command */
16038 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
16039 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
16040
16041 /* "bgp listen limit" commands. */
16042 install_element(BGP_NODE, &bgp_listen_limit_cmd);
16043 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
16044
16045 /* "bgp listen range" commands. */
16046 install_element(BGP_NODE, &bgp_listen_range_cmd);
16047 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
16048
8175f54a 16049 /* "bgp default shutdown" command */
f26845f9
QY
16050 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
16051
d62a17ae 16052 /* "neighbor remote-as" commands. */
16053 install_element(BGP_NODE, &neighbor_remote_as_cmd);
16054 install_element(BGP_NODE, &neighbor_interface_config_cmd);
16055 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
16056 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
16057 install_element(BGP_NODE,
16058 &neighbor_interface_v6only_config_remote_as_cmd);
16059 install_element(BGP_NODE, &no_neighbor_cmd);
16060 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
16061
16062 /* "neighbor peer-group" commands. */
16063 install_element(BGP_NODE, &neighbor_peer_group_cmd);
16064 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
16065 install_element(BGP_NODE,
16066 &no_neighbor_interface_peer_group_remote_as_cmd);
16067
16068 /* "neighbor local-as" commands. */
16069 install_element(BGP_NODE, &neighbor_local_as_cmd);
16070 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
16071 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
16072 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
16073
16074 /* "neighbor solo" commands. */
16075 install_element(BGP_NODE, &neighbor_solo_cmd);
16076 install_element(BGP_NODE, &no_neighbor_solo_cmd);
16077
16078 /* "neighbor password" commands. */
16079 install_element(BGP_NODE, &neighbor_password_cmd);
16080 install_element(BGP_NODE, &no_neighbor_password_cmd);
16081
16082 /* "neighbor activate" commands. */
16083 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
16084 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
16085 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
16086 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
16087 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
16088 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
16089 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
16090 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
16091 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 16092 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
16093 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 16094 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
16095
16096 /* "no neighbor activate" commands. */
16097 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
16098 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
16099 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
16100 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
16101 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
16102 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
16103 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
16104 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
16105 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 16106 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
16107 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 16108 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
16109
16110 /* "neighbor peer-group" set commands. */
16111 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
16112 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16113 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
16114 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16115 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
16116 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
16117 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16118 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 16119 install_element(BGP_FLOWSPECV4_NODE,
16120 &neighbor_set_peer_group_hidden_cmd);
16121 install_element(BGP_FLOWSPECV6_NODE,
16122 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 16123
16124 /* "no neighbor peer-group unset" commands. */
16125 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
16126 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16127 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16128 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16129 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16130 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16131 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16132 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 16133 install_element(BGP_FLOWSPECV4_NODE,
16134 &no_neighbor_set_peer_group_hidden_cmd);
16135 install_element(BGP_FLOWSPECV6_NODE,
16136 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 16137
16138 /* "neighbor softreconfiguration inbound" commands.*/
16139 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
16140 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
16141 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
16142 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16143 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
16144 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16145 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
16146 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16147 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
16148 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16149 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
16150 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16151 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
16152 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16153 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
16154 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16155 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
16156 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 16157 install_element(BGP_FLOWSPECV4_NODE,
16158 &neighbor_soft_reconfiguration_cmd);
16159 install_element(BGP_FLOWSPECV4_NODE,
16160 &no_neighbor_soft_reconfiguration_cmd);
16161 install_element(BGP_FLOWSPECV6_NODE,
16162 &neighbor_soft_reconfiguration_cmd);
16163 install_element(BGP_FLOWSPECV6_NODE,
16164 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
16165 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
16166 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 16167
16168 /* "neighbor attribute-unchanged" commands. */
16169 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
16170 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
16171 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
16172 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
16173 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
16174 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
16175 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
16176 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
16177 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
16178 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
16179 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
16180 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
16181 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
16182 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
16183 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
16184 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
16185 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
16186 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
16187
16188 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
16189 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
16190
16191 /* "nexthop-local unchanged" commands */
16192 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
16193 install_element(BGP_IPV6_NODE,
16194 &no_neighbor_nexthop_local_unchanged_cmd);
16195
16196 /* "neighbor next-hop-self" commands. */
16197 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
16198 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
16199 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
16200 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
16201 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
16202 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
16203 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
16204 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
16205 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
16206 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
16207 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
16208 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
16209 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
16210 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
16211 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
16212 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
16213 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
16214 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
16215 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
16216 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 16217
16218 /* "neighbor next-hop-self force" commands. */
16219 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
16220 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
16221 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16222 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16223 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
16224 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16225 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16226 install_element(BGP_IPV4_NODE,
16227 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16228 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
16229 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16230 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16231 install_element(BGP_IPV4M_NODE,
16232 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16233 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
16234 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16235 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16236 install_element(BGP_IPV4L_NODE,
16237 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16238 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
16239 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16240 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16241 install_element(BGP_IPV6_NODE,
16242 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16243 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
16244 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16245 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16246 install_element(BGP_IPV6M_NODE,
16247 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16248 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
16249 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16250 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16251 install_element(BGP_IPV6L_NODE,
16252 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16253 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
16254 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16255 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16256 install_element(BGP_VPNV4_NODE,
16257 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16258 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
16259 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16260 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16261 install_element(BGP_VPNV6_NODE,
16262 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
16263 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
16264 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 16265
16266 /* "neighbor as-override" commands. */
16267 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
16268 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
16269 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
16270 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
16271 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
16272 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
16273 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
16274 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
16275 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
16276 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
16277 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
16278 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
16279 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
16280 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
16281 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
16282 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
16283 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
16284 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
16285
16286 /* "neighbor remove-private-AS" commands. */
16287 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
16288 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
16289 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
16290 install_element(BGP_NODE,
16291 &no_neighbor_remove_private_as_all_hidden_cmd);
16292 install_element(BGP_NODE,
16293 &neighbor_remove_private_as_replace_as_hidden_cmd);
16294 install_element(BGP_NODE,
16295 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
16296 install_element(BGP_NODE,
16297 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
16298 install_element(
16299 BGP_NODE,
16300 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
16301 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
16302 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
16303 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
16304 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16305 install_element(BGP_IPV4_NODE,
16306 &neighbor_remove_private_as_replace_as_cmd);
16307 install_element(BGP_IPV4_NODE,
16308 &no_neighbor_remove_private_as_replace_as_cmd);
16309 install_element(BGP_IPV4_NODE,
16310 &neighbor_remove_private_as_all_replace_as_cmd);
16311 install_element(BGP_IPV4_NODE,
16312 &no_neighbor_remove_private_as_all_replace_as_cmd);
16313 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
16314 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
16315 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
16316 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
16317 install_element(BGP_IPV4M_NODE,
16318 &neighbor_remove_private_as_replace_as_cmd);
16319 install_element(BGP_IPV4M_NODE,
16320 &no_neighbor_remove_private_as_replace_as_cmd);
16321 install_element(BGP_IPV4M_NODE,
16322 &neighbor_remove_private_as_all_replace_as_cmd);
16323 install_element(BGP_IPV4M_NODE,
16324 &no_neighbor_remove_private_as_all_replace_as_cmd);
16325 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
16326 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
16327 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
16328 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
16329 install_element(BGP_IPV4L_NODE,
16330 &neighbor_remove_private_as_replace_as_cmd);
16331 install_element(BGP_IPV4L_NODE,
16332 &no_neighbor_remove_private_as_replace_as_cmd);
16333 install_element(BGP_IPV4L_NODE,
16334 &neighbor_remove_private_as_all_replace_as_cmd);
16335 install_element(BGP_IPV4L_NODE,
16336 &no_neighbor_remove_private_as_all_replace_as_cmd);
16337 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
16338 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
16339 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
16340 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16341 install_element(BGP_IPV6_NODE,
16342 &neighbor_remove_private_as_replace_as_cmd);
16343 install_element(BGP_IPV6_NODE,
16344 &no_neighbor_remove_private_as_replace_as_cmd);
16345 install_element(BGP_IPV6_NODE,
16346 &neighbor_remove_private_as_all_replace_as_cmd);
16347 install_element(BGP_IPV6_NODE,
16348 &no_neighbor_remove_private_as_all_replace_as_cmd);
16349 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
16350 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
16351 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
16352 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
16353 install_element(BGP_IPV6M_NODE,
16354 &neighbor_remove_private_as_replace_as_cmd);
16355 install_element(BGP_IPV6M_NODE,
16356 &no_neighbor_remove_private_as_replace_as_cmd);
16357 install_element(BGP_IPV6M_NODE,
16358 &neighbor_remove_private_as_all_replace_as_cmd);
16359 install_element(BGP_IPV6M_NODE,
16360 &no_neighbor_remove_private_as_all_replace_as_cmd);
16361 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
16362 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
16363 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
16364 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
16365 install_element(BGP_IPV6L_NODE,
16366 &neighbor_remove_private_as_replace_as_cmd);
16367 install_element(BGP_IPV6L_NODE,
16368 &no_neighbor_remove_private_as_replace_as_cmd);
16369 install_element(BGP_IPV6L_NODE,
16370 &neighbor_remove_private_as_all_replace_as_cmd);
16371 install_element(BGP_IPV6L_NODE,
16372 &no_neighbor_remove_private_as_all_replace_as_cmd);
16373 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
16374 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
16375 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
16376 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16377 install_element(BGP_VPNV4_NODE,
16378 &neighbor_remove_private_as_replace_as_cmd);
16379 install_element(BGP_VPNV4_NODE,
16380 &no_neighbor_remove_private_as_replace_as_cmd);
16381 install_element(BGP_VPNV4_NODE,
16382 &neighbor_remove_private_as_all_replace_as_cmd);
16383 install_element(BGP_VPNV4_NODE,
16384 &no_neighbor_remove_private_as_all_replace_as_cmd);
16385 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
16386 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
16387 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
16388 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16389 install_element(BGP_VPNV6_NODE,
16390 &neighbor_remove_private_as_replace_as_cmd);
16391 install_element(BGP_VPNV6_NODE,
16392 &no_neighbor_remove_private_as_replace_as_cmd);
16393 install_element(BGP_VPNV6_NODE,
16394 &neighbor_remove_private_as_all_replace_as_cmd);
16395 install_element(BGP_VPNV6_NODE,
16396 &no_neighbor_remove_private_as_all_replace_as_cmd);
16397
16398 /* "neighbor send-community" commands.*/
16399 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
16400 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
16401 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
16402 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
16403 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
16404 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
16405 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
16406 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
16407 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
16408 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
16409 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
16410 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
16411 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
16412 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
16413 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
16414 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
16415 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
16416 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
16417 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
16418 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
16419 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
16420 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
16421 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
16422 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
16423 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
16424 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
16425 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
16426 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
16427 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
16428 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
16429 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
16430 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
16431 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
16432 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
16433 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
16434 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
16435
16436 /* "neighbor route-reflector" commands.*/
16437 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
16438 install_element(BGP_NODE,
16439 &no_neighbor_route_reflector_client_hidden_cmd);
16440 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
16441 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
16442 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
16443 install_element(BGP_IPV4M_NODE,
16444 &no_neighbor_route_reflector_client_cmd);
16445 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
16446 install_element(BGP_IPV4L_NODE,
16447 &no_neighbor_route_reflector_client_cmd);
16448 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
16449 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
16450 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
16451 install_element(BGP_IPV6M_NODE,
16452 &no_neighbor_route_reflector_client_cmd);
16453 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
16454 install_element(BGP_IPV6L_NODE,
16455 &no_neighbor_route_reflector_client_cmd);
16456 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
16457 install_element(BGP_VPNV4_NODE,
16458 &no_neighbor_route_reflector_client_cmd);
16459 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
16460 install_element(BGP_VPNV6_NODE,
16461 &no_neighbor_route_reflector_client_cmd);
7c40bf39 16462 install_element(BGP_FLOWSPECV4_NODE,
16463 &neighbor_route_reflector_client_cmd);
16464 install_element(BGP_FLOWSPECV4_NODE,
16465 &no_neighbor_route_reflector_client_cmd);
16466 install_element(BGP_FLOWSPECV6_NODE,
16467 &neighbor_route_reflector_client_cmd);
16468 install_element(BGP_FLOWSPECV6_NODE,
16469 &no_neighbor_route_reflector_client_cmd);
d62a17ae 16470 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
16471 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
16472
16473 /* "neighbor route-server" commands.*/
16474 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16475 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16476 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16477 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16478 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16479 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16480 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16481 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16482 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16483 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16484 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16485 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16486 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16487 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16488 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16489 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16490 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16491 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
16492 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16493 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 16494 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16495 install_element(BGP_FLOWSPECV4_NODE,
16496 &no_neighbor_route_server_client_cmd);
16497 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16498 install_element(BGP_FLOWSPECV6_NODE,
16499 &no_neighbor_route_server_client_cmd);
d62a17ae 16500
16501 /* "neighbor addpath-tx-all-paths" commands.*/
16502 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16503 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16504 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16505 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16506 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16507 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16508 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16509 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16510 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16511 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16512 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16513 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16514 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16515 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16516 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16517 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16518 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16519 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16520
16521 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16522 install_element(BGP_NODE,
16523 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16524 install_element(BGP_NODE,
16525 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16526 install_element(BGP_IPV4_NODE,
16527 &neighbor_addpath_tx_bestpath_per_as_cmd);
16528 install_element(BGP_IPV4_NODE,
16529 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16530 install_element(BGP_IPV4M_NODE,
16531 &neighbor_addpath_tx_bestpath_per_as_cmd);
16532 install_element(BGP_IPV4M_NODE,
16533 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16534 install_element(BGP_IPV4L_NODE,
16535 &neighbor_addpath_tx_bestpath_per_as_cmd);
16536 install_element(BGP_IPV4L_NODE,
16537 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16538 install_element(BGP_IPV6_NODE,
16539 &neighbor_addpath_tx_bestpath_per_as_cmd);
16540 install_element(BGP_IPV6_NODE,
16541 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16542 install_element(BGP_IPV6M_NODE,
16543 &neighbor_addpath_tx_bestpath_per_as_cmd);
16544 install_element(BGP_IPV6M_NODE,
16545 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16546 install_element(BGP_IPV6L_NODE,
16547 &neighbor_addpath_tx_bestpath_per_as_cmd);
16548 install_element(BGP_IPV6L_NODE,
16549 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16550 install_element(BGP_VPNV4_NODE,
16551 &neighbor_addpath_tx_bestpath_per_as_cmd);
16552 install_element(BGP_VPNV4_NODE,
16553 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16554 install_element(BGP_VPNV6_NODE,
16555 &neighbor_addpath_tx_bestpath_per_as_cmd);
16556 install_element(BGP_VPNV6_NODE,
16557 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16558
2b31007c
RZ
16559 /* "neighbor sender-as-path-loop-detection" commands. */
16560 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16561 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16562
d62a17ae 16563 /* "neighbor passive" commands. */
16564 install_element(BGP_NODE, &neighbor_passive_cmd);
16565 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16566
16567
16568 /* "neighbor shutdown" commands. */
16569 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16570 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16571 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16572 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
16573
16574 /* "neighbor capability extended-nexthop" commands.*/
16575 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16576 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16577
16578 /* "neighbor capability orf prefix-list" commands.*/
16579 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16580 install_element(BGP_NODE,
16581 &no_neighbor_capability_orf_prefix_hidden_cmd);
16582 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16583 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16584 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16585 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16586 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16587 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16588 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16589 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16590 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16591 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16592 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16593 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16594
16595 /* "neighbor capability dynamic" commands.*/
16596 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16597 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16598
16599 /* "neighbor dont-capability-negotiate" commands. */
16600 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16601 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16602
16603 /* "neighbor ebgp-multihop" commands. */
16604 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16605 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16606 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16607
16608 /* "neighbor disable-connected-check" commands. */
16609 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16610 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16611
47cbc09b
PM
16612 /* "neighbor enforce-first-as" commands. */
16613 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16614 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16615
d62a17ae 16616 /* "neighbor description" commands. */
16617 install_element(BGP_NODE, &neighbor_description_cmd);
16618 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 16619 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 16620
16621 /* "neighbor update-source" commands. "*/
16622 install_element(BGP_NODE, &neighbor_update_source_cmd);
16623 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16624
16625 /* "neighbor default-originate" commands. */
16626 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16627 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16628 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16629 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16630 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16631 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16632 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16633 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16634 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16635 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16636 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16637 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16638 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16639 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16640 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16641 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16642 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16643 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16644 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16645 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16646 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16647
16648 /* "neighbor port" commands. */
16649 install_element(BGP_NODE, &neighbor_port_cmd);
16650 install_element(BGP_NODE, &no_neighbor_port_cmd);
16651
16652 /* "neighbor weight" commands. */
16653 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16654 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16655
16656 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16657 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16658 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16659 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16660 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16661 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16662 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16663 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16664 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16665 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16666 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16667 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16668 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16669 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16670 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16671 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16672
16673 /* "neighbor override-capability" commands. */
16674 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16675 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16676
16677 /* "neighbor strict-capability-match" commands. */
16678 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16679 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16680
16681 /* "neighbor timers" commands. */
16682 install_element(BGP_NODE, &neighbor_timers_cmd);
16683 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16684
16685 /* "neighbor timers connect" commands. */
16686 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16687 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16688
16689 /* "neighbor advertisement-interval" commands. */
16690 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
16691 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
16692
16693 /* "neighbor interface" commands. */
16694 install_element(BGP_NODE, &neighbor_interface_cmd);
16695 install_element(BGP_NODE, &no_neighbor_interface_cmd);
16696
16697 /* "neighbor distribute" commands. */
16698 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
16699 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
16700 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
16701 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
16702 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
16703 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
16704 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
16705 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
16706 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
16707 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
16708 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
16709 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
16710 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
16711 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
16712 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
16713 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
16714 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
16715 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
16716
16717 /* "neighbor prefix-list" commands. */
16718 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
16719 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
16720 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
16721 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
16722 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
16723 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
16724 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
16725 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
16726 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
16727 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
16728 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
16729 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
16730 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
16731 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
16732 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
16733 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
16734 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
16735 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 16736 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
16737 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
16738 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
16739 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 16740
16741 /* "neighbor filter-list" commands. */
16742 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
16743 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
16744 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
16745 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
16746 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
16747 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
16748 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
16749 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
16750 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
16751 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
16752 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
16753 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
16754 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
16755 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
16756 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
16757 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
16758 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
16759 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 16760 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
16761 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
16762 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
16763 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 16764
16765 /* "neighbor route-map" commands. */
16766 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
16767 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
16768 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
16769 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
16770 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
16771 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
16772 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
16773 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
16774 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
16775 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
16776 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
16777 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
16778 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
16779 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
16780 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
16781 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
16782 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
16783 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 16784 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
16785 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
16786 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
16787 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
16788 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
16789 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 16790
16791 /* "neighbor unsuppress-map" commands. */
16792 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
16793 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
16794 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
16795 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
16796 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
16797 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
16798 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
16799 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
16800 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
16801 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
16802 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
16803 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
16804 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
16805 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
16806 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
16807 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
16808 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
16809 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
16810
fde246e8
DA
16811 /* neighbor maximum-prefix-out commands. */
16812 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
16813 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
16814 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
16815 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16816 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
16817 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16818 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
16819 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16820 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
16821 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16822 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
16823 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16824 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
16825 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16826 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
16827 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16828 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
16829 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16830
d62a17ae 16831 /* "neighbor maximum-prefix" commands. */
16832 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
16833 install_element(BGP_NODE,
16834 &neighbor_maximum_prefix_threshold_hidden_cmd);
16835 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
16836 install_element(BGP_NODE,
16837 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
16838 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
16839 install_element(BGP_NODE,
16840 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
16841 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
16842 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
16843 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16844 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16845 install_element(BGP_IPV4_NODE,
16846 &neighbor_maximum_prefix_threshold_warning_cmd);
16847 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16848 install_element(BGP_IPV4_NODE,
16849 &neighbor_maximum_prefix_threshold_restart_cmd);
16850 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
16851 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
16852 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16853 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
16854 install_element(BGP_IPV4M_NODE,
16855 &neighbor_maximum_prefix_threshold_warning_cmd);
16856 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
16857 install_element(BGP_IPV4M_NODE,
16858 &neighbor_maximum_prefix_threshold_restart_cmd);
16859 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
16860 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
16861 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16862 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
16863 install_element(BGP_IPV4L_NODE,
16864 &neighbor_maximum_prefix_threshold_warning_cmd);
16865 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
16866 install_element(BGP_IPV4L_NODE,
16867 &neighbor_maximum_prefix_threshold_restart_cmd);
16868 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
16869 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
16870 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16871 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16872 install_element(BGP_IPV6_NODE,
16873 &neighbor_maximum_prefix_threshold_warning_cmd);
16874 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16875 install_element(BGP_IPV6_NODE,
16876 &neighbor_maximum_prefix_threshold_restart_cmd);
16877 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
16878 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
16879 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16880 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
16881 install_element(BGP_IPV6M_NODE,
16882 &neighbor_maximum_prefix_threshold_warning_cmd);
16883 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
16884 install_element(BGP_IPV6M_NODE,
16885 &neighbor_maximum_prefix_threshold_restart_cmd);
16886 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
16887 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
16888 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16889 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
16890 install_element(BGP_IPV6L_NODE,
16891 &neighbor_maximum_prefix_threshold_warning_cmd);
16892 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
16893 install_element(BGP_IPV6L_NODE,
16894 &neighbor_maximum_prefix_threshold_restart_cmd);
16895 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
16896 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
16897 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16898 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16899 install_element(BGP_VPNV4_NODE,
16900 &neighbor_maximum_prefix_threshold_warning_cmd);
16901 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16902 install_element(BGP_VPNV4_NODE,
16903 &neighbor_maximum_prefix_threshold_restart_cmd);
16904 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
16905 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
16906 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16907 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16908 install_element(BGP_VPNV6_NODE,
16909 &neighbor_maximum_prefix_threshold_warning_cmd);
16910 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16911 install_element(BGP_VPNV6_NODE,
16912 &neighbor_maximum_prefix_threshold_restart_cmd);
16913 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
16914
16915 /* "neighbor allowas-in" */
16916 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
16917 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
16918 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
16919 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
16920 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
16921 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
16922 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
16923 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
16924 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
16925 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
16926 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
16927 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
16928 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
16929 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
16930 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
16931 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
16932 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
16933 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
16934 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
16935 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
16936
16937 /* address-family commands. */
16938 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
16939 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 16940#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 16941 install_element(BGP_NODE, &address_family_vpnv4_cmd);
16942 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 16943#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 16944
d62a17ae 16945 install_element(BGP_NODE, &address_family_evpn_cmd);
16946
16947 /* "exit-address-family" command. */
16948 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
16949 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
16950 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
16951 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
16952 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
16953 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
16954 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
16955 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 16956 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
16957 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 16958 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
16959
16960 /* "clear ip bgp commands" */
16961 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
16962
16963 /* clear ip bgp prefix */
16964 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
16965 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
16966 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
16967
16968 /* "show [ip] bgp summary" commands. */
16969 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 16970 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 16971 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 16972 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 16973 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
16974 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 16975 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
16976
16977 /* "show [ip] bgp neighbors" commands. */
16978 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
16979
36235319 16980 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 16981
d62a17ae 16982 /* "show [ip] bgp peer-group" commands. */
16983 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
16984
16985 /* "show [ip] bgp paths" commands. */
16986 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
16987
16988 /* "show [ip] bgp community" commands. */
16989 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
16990
16991 /* "show ip bgp large-community" commands. */
16992 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
16993 /* "show [ip] bgp attribute-info" commands. */
16994 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 16995 /* "show [ip] bgp route-leak" command */
16996 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 16997
16998 /* "redistribute" commands. */
16999 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
17000 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
17001 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
17002 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
17003 install_element(BGP_NODE,
17004 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
17005 install_element(BGP_NODE,
17006 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
17007 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
17008 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
17009 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
17010 install_element(BGP_NODE,
17011 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
17012 install_element(BGP_NODE,
17013 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
17014 install_element(BGP_NODE,
17015 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
17016 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
17017 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
17018 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
17019 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
17020 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
17021 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
17022 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
17023 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
17024 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
17025 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
17026 install_element(BGP_IPV4_NODE,
17027 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
17028 install_element(BGP_IPV4_NODE,
17029 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
17030 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
17031 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
17032 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
17033 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
17034 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
17035 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
17036
b9c7bc5a
PZ
17037 /* import|export vpn [route-map WORD] */
17038 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
17039 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 17040
12a844a5
DS
17041 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
17042 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
17043
d62a17ae 17044 /* ttl_security commands */
17045 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
17046 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
17047
17048 /* "show [ip] bgp memory" commands. */
17049 install_element(VIEW_NODE, &show_bgp_memory_cmd);
17050
acf71666
MK
17051 /* "show bgp martian next-hop" */
17052 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
17053
48ecf8f5
DS
17054 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
17055
d62a17ae 17056 /* "show [ip] bgp views" commands. */
17057 install_element(VIEW_NODE, &show_bgp_views_cmd);
17058
17059 /* "show [ip] bgp vrfs" commands. */
17060 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
17061
17062 /* Community-list. */
17063 community_list_vty();
ddb5b488
PZ
17064
17065 /* vpn-policy commands */
b9c7bc5a
PZ
17066 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
17067 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
17068 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
17069 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
17070 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
17071 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
17072 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
17073 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
17074 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
17075 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
17076 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
17077 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 17078
301ad80a
PG
17079 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
17080 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
17081
b9c7bc5a
PZ
17082 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
17083 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
17084 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
17085 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
17086 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
17087 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
17088 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
17089 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
17090 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
17091 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 17092}
6b0655a2 17093
718e3744 17094#include "memory.h"
17095#include "bgp_regex.h"
17096#include "bgp_clist.h"
17097#include "bgp_ecommunity.h"
17098
17099/* VTY functions. */
17100
17101/* Direction value to string conversion. */
d62a17ae 17102static const char *community_direct_str(int direct)
17103{
17104 switch (direct) {
17105 case COMMUNITY_DENY:
17106 return "deny";
17107 case COMMUNITY_PERMIT:
17108 return "permit";
17109 default:
17110 return "unknown";
17111 }
718e3744 17112}
17113
17114/* Display error string. */
d62a17ae 17115static void community_list_perror(struct vty *vty, int ret)
17116{
17117 switch (ret) {
17118 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
17119 vty_out(vty, "%% Can't find community-list\n");
17120 break;
17121 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
17122 vty_out(vty, "%% Malformed community-list value\n");
17123 break;
17124 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
17125 vty_out(vty,
17126 "%% Community name conflict, previously defined as standard community\n");
17127 break;
17128 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
17129 vty_out(vty,
17130 "%% Community name conflict, previously defined as expanded community\n");
17131 break;
17132 }
718e3744 17133}
17134
5bf15956
DW
17135/* "community-list" keyword help string. */
17136#define COMMUNITY_LIST_STR "Add a community list entry\n"
17137
7336e101
SP
17138/*community-list standard */
17139DEFUN (community_list_standard,
17140 bgp_community_list_standard_cmd,
2f8cc0e5 17141 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17142 BGP_STR
718e3744 17143 COMMUNITY_LIST_STR
17144 "Community list number (standard)\n"
5bf15956 17145 "Add an standard community-list entry\n"
718e3744 17146 "Community list name\n"
2f8cc0e5
DA
17147 "Sequence number of an entry\n"
17148 "Sequence number\n"
718e3744 17149 "Specify community to reject\n"
17150 "Specify community to accept\n"
17151 COMMUNITY_VAL_STR)
17152{
d62a17ae 17153 char *cl_name_or_number = NULL;
2f8cc0e5 17154 char *seq = NULL;
d62a17ae 17155 int direct = 0;
17156 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 17157 int idx = 0;
7336e101 17158
2f8cc0e5
DA
17159 argv_find(argv, argc, "(1-4294967295)", &idx);
17160 if (idx)
17161 seq = argv[idx]->arg;
17162
17163 idx = 0;
d62a17ae 17164 argv_find(argv, argc, "(1-99)", &idx);
17165 argv_find(argv, argc, "WORD", &idx);
17166 cl_name_or_number = argv[idx]->arg;
17167 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17168 : COMMUNITY_DENY;
17169 argv_find(argv, argc, "AA:NN", &idx);
17170 char *str = argv_concat(argv, argc, idx);
42f914d4 17171
2f8cc0e5
DA
17172 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17173 direct, style);
42f914d4 17174
d62a17ae 17175 XFREE(MTYPE_TMP, str);
42f914d4 17176
d62a17ae 17177 if (ret < 0) {
17178 /* Display error string. */
17179 community_list_perror(vty, ret);
17180 return CMD_WARNING_CONFIG_FAILED;
17181 }
42f914d4 17182
d62a17ae 17183 return CMD_SUCCESS;
718e3744 17184}
17185
7336e101
SP
17186DEFUN (no_community_list_standard_all,
17187 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 17188 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17189 NO_STR
17190 BGP_STR
17191 COMMUNITY_LIST_STR
17192 "Community list number (standard)\n"
17193 "Add an standard community-list entry\n"
17194 "Community list name\n"
2f8cc0e5
DA
17195 "Sequence number of an entry\n"
17196 "Sequence number\n"
7336e101
SP
17197 "Specify community to reject\n"
17198 "Specify community to accept\n"
17199 COMMUNITY_VAL_STR)
718e3744 17200{
d62a17ae 17201 char *cl_name_or_number = NULL;
174b5cb9 17202 char *str = NULL;
d62a17ae 17203 int direct = 0;
17204 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 17205 char *seq = NULL;
d62a17ae 17206 int idx = 0;
7336e101 17207
2f8cc0e5
DA
17208 argv_find(argv, argc, "(1-4294967295)", &idx);
17209 if (idx)
17210 seq = argv[idx]->arg;
17211
17212 idx = 0;
174b5cb9
DA
17213 argv_find(argv, argc, "permit", &idx);
17214 argv_find(argv, argc, "deny", &idx);
17215
17216 if (idx) {
17217 direct = argv_find(argv, argc, "permit", &idx)
17218 ? COMMUNITY_PERMIT
17219 : COMMUNITY_DENY;
17220
17221 idx = 0;
17222 argv_find(argv, argc, "AA:NN", &idx);
17223 str = argv_concat(argv, argc, idx);
17224 }
17225
17226 idx = 0;
d62a17ae 17227 argv_find(argv, argc, "(1-99)", &idx);
17228 argv_find(argv, argc, "WORD", &idx);
17229 cl_name_or_number = argv[idx]->arg;
42f914d4 17230
2f8cc0e5 17231 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17232 direct, style);
42f914d4 17233
d62a17ae 17234 XFREE(MTYPE_TMP, str);
daf9ddbb 17235
d62a17ae 17236 if (ret < 0) {
17237 community_list_perror(vty, ret);
17238 return CMD_WARNING_CONFIG_FAILED;
17239 }
42f914d4 17240
d62a17ae 17241 return CMD_SUCCESS;
718e3744 17242}
7336e101 17243
174b5cb9
DA
17244ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
17245 "no bgp community-list <(1-99)|standard WORD>",
17246 NO_STR BGP_STR COMMUNITY_LIST_STR
17247 "Community list number (standard)\n"
17248 "Add an standard community-list entry\n"
17249 "Community list name\n")
17250
7336e101
SP
17251/*community-list expanded */
17252DEFUN (community_list_expanded_all,
17253 bgp_community_list_expanded_all_cmd,
2f8cc0e5 17254 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17255 BGP_STR
17256 COMMUNITY_LIST_STR
718e3744 17257 "Community list number (expanded)\n"
5bf15956 17258 "Add an expanded community-list entry\n"
718e3744 17259 "Community list name\n"
2f8cc0e5
DA
17260 "Sequence number of an entry\n"
17261 "Sequence number\n"
718e3744 17262 "Specify community to reject\n"
17263 "Specify community to accept\n"
17264 COMMUNITY_VAL_STR)
17265{
d62a17ae 17266 char *cl_name_or_number = NULL;
2f8cc0e5 17267 char *seq = NULL;
d62a17ae 17268 int direct = 0;
17269 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17270 int idx = 0;
7b9a4750 17271
2f8cc0e5
DA
17272 argv_find(argv, argc, "(1-4294967295)", &idx);
17273 if (idx)
17274 seq = argv[idx]->arg;
17275
17276 idx = 0;
17277
d62a17ae 17278 argv_find(argv, argc, "(100-500)", &idx);
17279 argv_find(argv, argc, "WORD", &idx);
17280 cl_name_or_number = argv[idx]->arg;
17281 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17282 : COMMUNITY_DENY;
17283 argv_find(argv, argc, "AA:NN", &idx);
17284 char *str = argv_concat(argv, argc, idx);
42f914d4 17285
2f8cc0e5
DA
17286 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17287 direct, style);
42f914d4 17288
d62a17ae 17289 XFREE(MTYPE_TMP, str);
42f914d4 17290
d62a17ae 17291 if (ret < 0) {
17292 /* Display error string. */
17293 community_list_perror(vty, ret);
17294 return CMD_WARNING_CONFIG_FAILED;
17295 }
42f914d4 17296
d62a17ae 17297 return CMD_SUCCESS;
718e3744 17298}
17299
7336e101
SP
17300DEFUN (no_community_list_expanded_all,
17301 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 17302 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17303 NO_STR
17304 BGP_STR
17305 COMMUNITY_LIST_STR
17306 "Community list number (expanded)\n"
17307 "Add an expanded community-list entry\n"
17308 "Community list name\n"
2f8cc0e5
DA
17309 "Sequence number of an entry\n"
17310 "Sequence number\n"
7336e101
SP
17311 "Specify community to reject\n"
17312 "Specify community to accept\n"
17313 COMMUNITY_VAL_STR)
718e3744 17314{
d62a17ae 17315 char *cl_name_or_number = NULL;
2f8cc0e5 17316 char *seq = NULL;
174b5cb9 17317 char *str = NULL;
d62a17ae 17318 int direct = 0;
17319 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17320 int idx = 0;
174b5cb9 17321
2f8cc0e5
DA
17322 argv_find(argv, argc, "(1-4294967295)", &idx);
17323 if (idx)
17324 seq = argv[idx]->arg;
17325
17326 idx = 0;
174b5cb9
DA
17327 argv_find(argv, argc, "permit", &idx);
17328 argv_find(argv, argc, "deny", &idx);
17329
17330 if (idx) {
17331 direct = argv_find(argv, argc, "permit", &idx)
17332 ? COMMUNITY_PERMIT
17333 : COMMUNITY_DENY;
17334
17335 idx = 0;
17336 argv_find(argv, argc, "AA:NN", &idx);
17337 str = argv_concat(argv, argc, idx);
7336e101 17338 }
174b5cb9
DA
17339
17340 idx = 0;
d62a17ae 17341 argv_find(argv, argc, "(100-500)", &idx);
17342 argv_find(argv, argc, "WORD", &idx);
17343 cl_name_or_number = argv[idx]->arg;
42f914d4 17344
2f8cc0e5 17345 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17346 direct, style);
42f914d4 17347
d62a17ae 17348 XFREE(MTYPE_TMP, str);
daf9ddbb 17349
d62a17ae 17350 if (ret < 0) {
17351 community_list_perror(vty, ret);
17352 return CMD_WARNING_CONFIG_FAILED;
17353 }
42f914d4 17354
d62a17ae 17355 return CMD_SUCCESS;
718e3744 17356}
17357
174b5cb9
DA
17358ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
17359 "no bgp community-list <(100-500)|expanded WORD>",
17360 NO_STR IP_STR COMMUNITY_LIST_STR
17361 "Community list number (expanded)\n"
17362 "Add an expanded community-list entry\n"
17363 "Community list name\n")
17364
8d9b8ed9
PM
17365/* Return configuration string of community-list entry. */
17366static const char *community_list_config_str(struct community_entry *entry)
17367{
17368 const char *str;
17369
17370 if (entry->any)
17371 str = "";
17372 else {
17373 if (entry->style == COMMUNITY_LIST_STANDARD)
17374 str = community_str(entry->u.com, false);
17375 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
17376 str = lcommunity_str(entry->u.lcom, false);
17377 else
17378 str = entry->config;
17379 }
17380 return str;
17381}
17382
d62a17ae 17383static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 17384{
d62a17ae 17385 struct community_entry *entry;
718e3744 17386
d62a17ae 17387 for (entry = list->head; entry; entry = entry->next) {
17388 if (entry == list->head) {
17389 if (all_digit(list->name))
17390 vty_out(vty, "Community %s list %s\n",
17391 entry->style == COMMUNITY_LIST_STANDARD
17392 ? "standard"
17393 : "(expanded) access",
17394 list->name);
17395 else
17396 vty_out(vty, "Named Community %s list %s\n",
17397 entry->style == COMMUNITY_LIST_STANDARD
17398 ? "standard"
17399 : "expanded",
17400 list->name);
17401 }
17402 if (entry->any)
17403 vty_out(vty, " %s\n",
17404 community_direct_str(entry->direct));
17405 else
17406 vty_out(vty, " %s %s\n",
17407 community_direct_str(entry->direct),
8d9b8ed9 17408 community_list_config_str(entry));
d62a17ae 17409 }
718e3744 17410}
17411
7336e101
SP
17412DEFUN (show_community_list,
17413 show_bgp_community_list_cmd,
17414 "show bgp community-list",
718e3744 17415 SHOW_STR
7336e101 17416 BGP_STR
718e3744 17417 "List community-list\n")
17418{
d62a17ae 17419 struct community_list *list;
17420 struct community_list_master *cm;
718e3744 17421
d62a17ae 17422 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17423 if (!cm)
17424 return CMD_SUCCESS;
718e3744 17425
d62a17ae 17426 for (list = cm->num.head; list; list = list->next)
17427 community_list_show(vty, list);
718e3744 17428
d62a17ae 17429 for (list = cm->str.head; list; list = list->next)
17430 community_list_show(vty, list);
718e3744 17431
d62a17ae 17432 return CMD_SUCCESS;
718e3744 17433}
17434
7336e101
SP
17435DEFUN (show_community_list_arg,
17436 show_bgp_community_list_arg_cmd,
960b69b9 17437 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
17438 SHOW_STR
17439 BGP_STR
718e3744 17440 "List community-list\n"
17441 "Community-list number\n"
960b69b9 17442 "Community-list name\n"
17443 "Detailed information on community-list\n")
718e3744 17444{
d62a17ae 17445 int idx_comm_list = 3;
17446 struct community_list *list;
718e3744 17447
e237b0d2 17448 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17449 COMMUNITY_LIST_MASTER);
17450 if (!list) {
17451 vty_out(vty, "%% Can't find community-list\n");
17452 return CMD_WARNING;
17453 }
718e3744 17454
d62a17ae 17455 community_list_show(vty, list);
718e3744 17456
d62a17ae 17457 return CMD_SUCCESS;
718e3744 17458}
6b0655a2 17459
57d187bc
JS
17460/*
17461 * Large Community code.
17462 */
d62a17ae 17463static int lcommunity_list_set_vty(struct vty *vty, int argc,
17464 struct cmd_token **argv, int style,
17465 int reject_all_digit_name)
17466{
17467 int ret;
17468 int direct;
17469 char *str;
17470 int idx = 0;
17471 char *cl_name;
2f8cc0e5
DA
17472 char *seq = NULL;
17473
947073e3 17474 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 17475 seq = argv[idx]->arg;
d62a17ae 17476
2f8cc0e5 17477 idx = 0;
d62a17ae 17478 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17479 : COMMUNITY_DENY;
17480
17481 /* All digit name check. */
17482 idx = 0;
17483 argv_find(argv, argc, "WORD", &idx);
17484 argv_find(argv, argc, "(1-99)", &idx);
17485 argv_find(argv, argc, "(100-500)", &idx);
17486 cl_name = argv[idx]->arg;
17487 if (reject_all_digit_name && all_digit(cl_name)) {
17488 vty_out(vty, "%% Community name cannot have all digits\n");
17489 return CMD_WARNING_CONFIG_FAILED;
17490 }
17491
17492 idx = 0;
17493 argv_find(argv, argc, "AA:BB:CC", &idx);
17494 argv_find(argv, argc, "LINE", &idx);
17495 /* Concat community string argument. */
17496 if (idx)
17497 str = argv_concat(argv, argc, idx);
17498 else
17499 str = NULL;
17500
2f8cc0e5 17501 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 17502
17503 /* Free temporary community list string allocated by
17504 argv_concat(). */
0a22ddfb 17505 XFREE(MTYPE_TMP, str);
d62a17ae 17506
17507 if (ret < 0) {
17508 community_list_perror(vty, ret);
17509 return CMD_WARNING_CONFIG_FAILED;
17510 }
17511 return CMD_SUCCESS;
17512}
17513
17514static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17515 struct cmd_token **argv, int style)
17516{
17517 int ret;
17518 int direct = 0;
17519 char *str = NULL;
17520 int idx = 0;
2f8cc0e5 17521 char *seq = NULL;
d62a17ae 17522
947073e3 17523 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 17524 seq = argv[idx]->arg;
d62a17ae 17525
2f8cc0e5 17526 idx = 0;
d62a17ae 17527 argv_find(argv, argc, "permit", &idx);
17528 argv_find(argv, argc, "deny", &idx);
17529
17530 if (idx) {
17531 /* Check the list direct. */
17532 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17533 direct = COMMUNITY_PERMIT;
17534 else
17535 direct = COMMUNITY_DENY;
17536
17537 idx = 0;
17538 argv_find(argv, argc, "LINE", &idx);
17539 argv_find(argv, argc, "AA:AA:NN", &idx);
17540 /* Concat community string argument. */
17541 str = argv_concat(argv, argc, idx);
17542 }
17543
17544 idx = 0;
17545 argv_find(argv, argc, "(1-99)", &idx);
17546 argv_find(argv, argc, "(100-500)", &idx);
17547 argv_find(argv, argc, "WORD", &idx);
17548
17549 /* Unset community list. */
2f8cc0e5 17550 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 17551 style);
17552
17553 /* Free temporary community list string allocated by
17554 argv_concat(). */
0a22ddfb 17555 XFREE(MTYPE_TMP, str);
d62a17ae 17556
17557 if (ret < 0) {
17558 community_list_perror(vty, ret);
17559 return CMD_WARNING_CONFIG_FAILED;
17560 }
17561
17562 return CMD_SUCCESS;
57d187bc
JS
17563}
17564
17565/* "large-community-list" keyword help string. */
17566#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17567#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17568
7336e101
SP
17569DEFUN (lcommunity_list_standard,
17570 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17571 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17572 BGP_STR
17573 LCOMMUNITY_LIST_STR
17574 "Large Community list number (standard)\n"
2f8cc0e5
DA
17575 "Sequence number of an entry\n"
17576 "Sequence number\n"
7336e101
SP
17577 "Specify large community to reject\n"
17578 "Specify large community to accept\n"
17579 LCOMMUNITY_VAL_STR)
52951b63 17580{
d62a17ae 17581 return lcommunity_list_set_vty(vty, argc, argv,
17582 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
17583}
17584
7336e101
SP
17585DEFUN (lcommunity_list_expanded,
17586 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17587 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17588 BGP_STR
17589 LCOMMUNITY_LIST_STR
17590 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17591 "Sequence number of an entry\n"
17592 "Sequence number\n"
7336e101
SP
17593 "Specify large community to reject\n"
17594 "Specify large community to accept\n"
17595 "An ordered list as a regular-expression\n")
57d187bc 17596{
d62a17ae 17597 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17598 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
17599}
17600
7336e101
SP
17601DEFUN (lcommunity_list_name_standard,
17602 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17603 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17604 BGP_STR
17605 LCOMMUNITY_LIST_STR
17606 "Specify standard large-community-list\n"
17607 "Large Community list name\n"
2f8cc0e5
DA
17608 "Sequence number of an entry\n"
17609 "Sequence number\n"
7336e101
SP
17610 "Specify large community to reject\n"
17611 "Specify large community to accept\n"
17612 LCOMMUNITY_VAL_STR)
52951b63 17613{
d62a17ae 17614 return lcommunity_list_set_vty(vty, argc, argv,
17615 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
17616}
17617
7336e101
SP
17618DEFUN (lcommunity_list_name_expanded,
17619 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17620 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17621 BGP_STR
17622 LCOMMUNITY_LIST_STR
17623 "Specify expanded large-community-list\n"
17624 "Large Community list name\n"
2f8cc0e5
DA
17625 "Sequence number of an entry\n"
17626 "Sequence number\n"
7336e101
SP
17627 "Specify large community to reject\n"
17628 "Specify large community to accept\n"
17629 "An ordered list as a regular-expression\n")
57d187bc 17630{
d62a17ae 17631 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17632 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
17633}
17634
4378f57c
DA
17635DEFUN (no_lcommunity_list_all,
17636 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
17637 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17638 NO_STR
17639 BGP_STR
17640 LCOMMUNITY_LIST_STR
17641 "Large Community list number (standard)\n"
17642 "Large Community list number (expanded)\n"
17643 "Large Community list name\n")
57d187bc 17644{
7336e101
SP
17645 return lcommunity_list_unset_vty(vty, argc, argv,
17646 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17647}
17648
4378f57c
DA
17649DEFUN (no_lcommunity_list_name_standard_all,
17650 no_bgp_lcommunity_list_name_standard_all_cmd,
17651 "no bgp large-community-list standard WORD",
17652 NO_STR
17653 BGP_STR
17654 LCOMMUNITY_LIST_STR
17655 "Specify standard large-community-list\n"
17656 "Large Community list name\n")
17657{
17658 return lcommunity_list_unset_vty(vty, argc, argv,
17659 LARGE_COMMUNITY_LIST_STANDARD);
17660}
17661
7336e101
SP
17662DEFUN (no_lcommunity_list_name_expanded_all,
17663 no_bgp_lcommunity_list_name_expanded_all_cmd,
17664 "no bgp large-community-list expanded WORD",
17665 NO_STR
17666 BGP_STR
17667 LCOMMUNITY_LIST_STR
17668 "Specify expanded large-community-list\n"
17669 "Large Community list name\n")
57d187bc 17670{
d62a17ae 17671 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17672 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17673}
17674
7336e101
SP
17675DEFUN (no_lcommunity_list_standard,
17676 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17677 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17678 NO_STR
17679 BGP_STR
17680 LCOMMUNITY_LIST_STR
17681 "Large Community list number (standard)\n"
2f8cc0e5
DA
17682 "Sequence number of an entry\n"
17683 "Sequence number\n"
7336e101
SP
17684 "Specify large community to reject\n"
17685 "Specify large community to accept\n"
17686 LCOMMUNITY_VAL_STR)
57d187bc 17687{
d62a17ae 17688 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17689 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17690}
17691
7336e101
SP
17692DEFUN (no_lcommunity_list_expanded,
17693 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17694 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17695 NO_STR
17696 BGP_STR
17697 LCOMMUNITY_LIST_STR
17698 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17699 "Sequence number of an entry\n"
17700 "Sequence number\n"
7336e101
SP
17701 "Specify large community to reject\n"
17702 "Specify large community to accept\n"
17703 "An ordered list as a regular-expression\n")
57d187bc 17704{
d62a17ae 17705 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17706 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17707}
17708
7336e101
SP
17709DEFUN (no_lcommunity_list_name_standard,
17710 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17711 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17712 NO_STR
17713 BGP_STR
17714 LCOMMUNITY_LIST_STR
17715 "Specify standard large-community-list\n"
17716 "Large Community list name\n"
2f8cc0e5
DA
17717 "Sequence number of an entry\n"
17718 "Sequence number\n"
7336e101
SP
17719 "Specify large community to reject\n"
17720 "Specify large community to accept\n"
17721 LCOMMUNITY_VAL_STR)
57d187bc 17722{
d62a17ae 17723 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17724 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17725}
17726
7336e101
SP
17727DEFUN (no_lcommunity_list_name_expanded,
17728 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17729 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17730 NO_STR
17731 BGP_STR
17732 LCOMMUNITY_LIST_STR
17733 "Specify expanded large-community-list\n"
17734 "Large community list name\n"
2f8cc0e5
DA
17735 "Sequence number of an entry\n"
17736 "Sequence number\n"
7336e101
SP
17737 "Specify large community to reject\n"
17738 "Specify large community to accept\n"
17739 "An ordered list as a regular-expression\n")
57d187bc 17740{
d62a17ae 17741 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17742 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17743}
17744
d62a17ae 17745static void lcommunity_list_show(struct vty *vty, struct community_list *list)
17746{
17747 struct community_entry *entry;
17748
17749 for (entry = list->head; entry; entry = entry->next) {
17750 if (entry == list->head) {
17751 if (all_digit(list->name))
17752 vty_out(vty, "Large community %s list %s\n",
169b72c8 17753 entry->style ==
17754 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17755 ? "standard"
17756 : "(expanded) access",
17757 list->name);
17758 else
17759 vty_out(vty,
17760 "Named large community %s list %s\n",
169b72c8 17761 entry->style ==
17762 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17763 ? "standard"
17764 : "expanded",
17765 list->name);
17766 }
17767 if (entry->any)
17768 vty_out(vty, " %s\n",
17769 community_direct_str(entry->direct));
17770 else
17771 vty_out(vty, " %s %s\n",
17772 community_direct_str(entry->direct),
8d9b8ed9 17773 community_list_config_str(entry));
d62a17ae 17774 }
57d187bc
JS
17775}
17776
7336e101
SP
17777DEFUN (show_lcommunity_list,
17778 show_bgp_lcommunity_list_cmd,
17779 "show bgp large-community-list",
57d187bc 17780 SHOW_STR
7336e101 17781 BGP_STR
57d187bc
JS
17782 "List large-community list\n")
17783{
d62a17ae 17784 struct community_list *list;
17785 struct community_list_master *cm;
57d187bc 17786
d62a17ae 17787 cm = community_list_master_lookup(bgp_clist,
17788 LARGE_COMMUNITY_LIST_MASTER);
17789 if (!cm)
17790 return CMD_SUCCESS;
57d187bc 17791
d62a17ae 17792 for (list = cm->num.head; list; list = list->next)
17793 lcommunity_list_show(vty, list);
57d187bc 17794
d62a17ae 17795 for (list = cm->str.head; list; list = list->next)
17796 lcommunity_list_show(vty, list);
57d187bc 17797
d62a17ae 17798 return CMD_SUCCESS;
57d187bc
JS
17799}
17800
7336e101
SP
17801DEFUN (show_lcommunity_list_arg,
17802 show_bgp_lcommunity_list_arg_cmd,
960b69b9 17803 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
17804 SHOW_STR
17805 BGP_STR
57d187bc 17806 "List large-community list\n"
960b69b9 17807 "Large-community-list number\n"
17808 "Large-community-list name\n"
17809 "Detailed information on large-community-list\n")
57d187bc 17810{
d62a17ae 17811 struct community_list *list;
57d187bc 17812
e237b0d2 17813 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 17814 LARGE_COMMUNITY_LIST_MASTER);
17815 if (!list) {
960b69b9 17816 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 17817 return CMD_WARNING;
17818 }
57d187bc 17819
d62a17ae 17820 lcommunity_list_show(vty, list);
57d187bc 17821
d62a17ae 17822 return CMD_SUCCESS;
57d187bc
JS
17823}
17824
718e3744 17825/* "extcommunity-list" keyword help string. */
17826#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
17827#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
17828
7336e101
SP
17829DEFUN (extcommunity_list_standard,
17830 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 17831 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17832 BGP_STR
718e3744 17833 EXTCOMMUNITY_LIST_STR
17834 "Extended Community list number (standard)\n"
718e3744 17835 "Specify standard extcommunity-list\n"
5bf15956 17836 "Community list name\n"
2f8cc0e5
DA
17837 "Sequence number of an entry\n"
17838 "Sequence number\n"
718e3744 17839 "Specify community to reject\n"
17840 "Specify community to accept\n"
17841 EXTCOMMUNITY_VAL_STR)
17842{
d62a17ae 17843 int style = EXTCOMMUNITY_LIST_STANDARD;
17844 int direct = 0;
17845 char *cl_number_or_name = NULL;
2f8cc0e5 17846 char *seq = NULL;
42f914d4 17847
d62a17ae 17848 int idx = 0;
7b9a4750 17849
d62a17ae 17850 argv_find(argv, argc, "(1-99)", &idx);
17851 argv_find(argv, argc, "WORD", &idx);
17852 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 17853
409148f6 17854 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
17855 seq = argv[idx]->arg;
17856
d62a17ae 17857 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17858 : COMMUNITY_DENY;
17859 argv_find(argv, argc, "AA:NN", &idx);
17860 char *str = argv_concat(argv, argc, idx);
42f914d4 17861
2f8cc0e5 17862 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17863 direct, style);
42f914d4 17864
d62a17ae 17865 XFREE(MTYPE_TMP, str);
42f914d4 17866
d62a17ae 17867 if (ret < 0) {
17868 community_list_perror(vty, ret);
17869 return CMD_WARNING_CONFIG_FAILED;
17870 }
42f914d4 17871
d62a17ae 17872 return CMD_SUCCESS;
718e3744 17873}
17874
7336e101
SP
17875DEFUN (extcommunity_list_name_expanded,
17876 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 17877 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17878 BGP_STR
17879 EXTCOMMUNITY_LIST_STR
5bf15956 17880 "Extended Community list number (expanded)\n"
718e3744 17881 "Specify expanded extcommunity-list\n"
17882 "Extended Community list name\n"
2f8cc0e5
DA
17883 "Sequence number of an entry\n"
17884 "Sequence number\n"
718e3744 17885 "Specify community to reject\n"
17886 "Specify community to accept\n"
17887 "An ordered list as a regular-expression\n")
17888{
d62a17ae 17889 int style = EXTCOMMUNITY_LIST_EXPANDED;
17890 int direct = 0;
17891 char *cl_number_or_name = NULL;
2f8cc0e5 17892 char *seq = NULL;
d62a17ae 17893 int idx = 0;
7336e101 17894
d62a17ae 17895 argv_find(argv, argc, "(100-500)", &idx);
17896 argv_find(argv, argc, "WORD", &idx);
17897 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 17898
409148f6 17899 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
17900 seq = argv[idx]->arg;
17901
d62a17ae 17902 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17903 : COMMUNITY_DENY;
17904 argv_find(argv, argc, "LINE", &idx);
17905 char *str = argv_concat(argv, argc, idx);
42f914d4 17906
2f8cc0e5 17907 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17908 direct, style);
42f914d4 17909
d62a17ae 17910 XFREE(MTYPE_TMP, str);
42f914d4 17911
d62a17ae 17912 if (ret < 0) {
17913 community_list_perror(vty, ret);
17914 return CMD_WARNING_CONFIG_FAILED;
17915 }
42f914d4 17916
d62a17ae 17917 return CMD_SUCCESS;
718e3744 17918}
17919
7336e101
SP
17920DEFUN (no_extcommunity_list_standard_all,
17921 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 17922 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17923 NO_STR
17924 BGP_STR
17925 EXTCOMMUNITY_LIST_STR
813d4307 17926 "Extended Community list number (standard)\n"
718e3744 17927 "Specify standard extcommunity-list\n"
5bf15956 17928 "Community list name\n"
2f8cc0e5
DA
17929 "Sequence number of an entry\n"
17930 "Sequence number\n"
718e3744 17931 "Specify community to reject\n"
17932 "Specify community to accept\n"
17933 EXTCOMMUNITY_VAL_STR)
17934{
d62a17ae 17935 int style = EXTCOMMUNITY_LIST_STANDARD;
17936 int direct = 0;
17937 char *cl_number_or_name = NULL;
d4455c89 17938 char *str = NULL;
2f8cc0e5 17939 char *seq = NULL;
d62a17ae 17940 int idx = 0;
d4455c89 17941
409148f6 17942 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
17943 seq = argv[idx]->arg;
17944
17945 idx = 0;
d4455c89
DA
17946 argv_find(argv, argc, "permit", &idx);
17947 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
17948 if (idx) {
17949 direct = argv_find(argv, argc, "permit", &idx)
17950 ? COMMUNITY_PERMIT
17951 : COMMUNITY_DENY;
17952
17953 idx = 0;
17954 argv_find(argv, argc, "AA:NN", &idx);
17955 str = argv_concat(argv, argc, idx);
17956 }
17957
17958 idx = 0;
d62a17ae 17959 argv_find(argv, argc, "(1-99)", &idx);
17960 argv_find(argv, argc, "WORD", &idx);
17961 cl_number_or_name = argv[idx]->arg;
42f914d4 17962
d62a17ae 17963 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 17964 seq, direct, style);
42f914d4 17965
d62a17ae 17966 XFREE(MTYPE_TMP, str);
42f914d4 17967
d62a17ae 17968 if (ret < 0) {
17969 community_list_perror(vty, ret);
17970 return CMD_WARNING_CONFIG_FAILED;
17971 }
42f914d4 17972
d62a17ae 17973 return CMD_SUCCESS;
718e3744 17974}
17975
d4455c89
DA
17976ALIAS(no_extcommunity_list_standard_all,
17977 no_bgp_extcommunity_list_standard_all_list_cmd,
17978 "no bgp extcommunity-list <(1-99)|standard WORD>",
17979 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17980 "Extended Community list number (standard)\n"
17981 "Specify standard extcommunity-list\n"
17982 "Community list name\n")
17983
7336e101
SP
17984DEFUN (no_extcommunity_list_expanded_all,
17985 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 17986 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17987 NO_STR
17988 BGP_STR
17989 EXTCOMMUNITY_LIST_STR
718e3744 17990 "Extended Community list number (expanded)\n"
718e3744 17991 "Specify expanded extcommunity-list\n"
5bf15956 17992 "Extended Community list name\n"
2f8cc0e5
DA
17993 "Sequence number of an entry\n"
17994 "Sequence number\n"
718e3744 17995 "Specify community to reject\n"
17996 "Specify community to accept\n"
17997 "An ordered list as a regular-expression\n")
17998{
d62a17ae 17999 int style = EXTCOMMUNITY_LIST_EXPANDED;
18000 int direct = 0;
18001 char *cl_number_or_name = NULL;
d4455c89 18002 char *str = NULL;
2f8cc0e5 18003 char *seq = NULL;
d62a17ae 18004 int idx = 0;
d4455c89 18005
409148f6 18006 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18007 seq = argv[idx]->arg;
18008
18009 idx = 0;
d4455c89
DA
18010 argv_find(argv, argc, "permit", &idx);
18011 argv_find(argv, argc, "deny", &idx);
18012
18013 if (idx) {
18014 direct = argv_find(argv, argc, "permit", &idx)
18015 ? COMMUNITY_PERMIT
18016 : COMMUNITY_DENY;
18017
18018 idx = 0;
18019 argv_find(argv, argc, "LINE", &idx);
18020 str = argv_concat(argv, argc, idx);
18021 }
18022
18023 idx = 0;
d62a17ae 18024 argv_find(argv, argc, "(100-500)", &idx);
18025 argv_find(argv, argc, "WORD", &idx);
18026 cl_number_or_name = argv[idx]->arg;
42f914d4 18027
d62a17ae 18028 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18029 seq, direct, style);
42f914d4 18030
d62a17ae 18031 XFREE(MTYPE_TMP, str);
42f914d4 18032
d62a17ae 18033 if (ret < 0) {
18034 community_list_perror(vty, ret);
18035 return CMD_WARNING_CONFIG_FAILED;
18036 }
42f914d4 18037
d62a17ae 18038 return CMD_SUCCESS;
718e3744 18039}
18040
d4455c89
DA
18041ALIAS(no_extcommunity_list_expanded_all,
18042 no_bgp_extcommunity_list_expanded_all_list_cmd,
18043 "no bgp extcommunity-list <(100-500)|expanded WORD>",
18044 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18045 "Extended Community list number (expanded)\n"
18046 "Specify expanded extcommunity-list\n"
18047 "Extended Community list name\n")
18048
d62a17ae 18049static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 18050{
d62a17ae 18051 struct community_entry *entry;
718e3744 18052
d62a17ae 18053 for (entry = list->head; entry; entry = entry->next) {
18054 if (entry == list->head) {
18055 if (all_digit(list->name))
18056 vty_out(vty, "Extended community %s list %s\n",
18057 entry->style == EXTCOMMUNITY_LIST_STANDARD
18058 ? "standard"
18059 : "(expanded) access",
18060 list->name);
18061 else
18062 vty_out(vty,
18063 "Named extended community %s list %s\n",
18064 entry->style == EXTCOMMUNITY_LIST_STANDARD
18065 ? "standard"
18066 : "expanded",
18067 list->name);
18068 }
18069 if (entry->any)
18070 vty_out(vty, " %s\n",
18071 community_direct_str(entry->direct));
18072 else
18073 vty_out(vty, " %s %s\n",
18074 community_direct_str(entry->direct),
8d9b8ed9 18075 community_list_config_str(entry));
d62a17ae 18076 }
718e3744 18077}
18078
7336e101
SP
18079DEFUN (show_extcommunity_list,
18080 show_bgp_extcommunity_list_cmd,
18081 "show bgp extcommunity-list",
718e3744 18082 SHOW_STR
7336e101 18083 BGP_STR
718e3744 18084 "List extended-community list\n")
18085{
d62a17ae 18086 struct community_list *list;
18087 struct community_list_master *cm;
718e3744 18088
d62a17ae 18089 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18090 if (!cm)
18091 return CMD_SUCCESS;
718e3744 18092
d62a17ae 18093 for (list = cm->num.head; list; list = list->next)
18094 extcommunity_list_show(vty, list);
718e3744 18095
d62a17ae 18096 for (list = cm->str.head; list; list = list->next)
18097 extcommunity_list_show(vty, list);
718e3744 18098
d62a17ae 18099 return CMD_SUCCESS;
718e3744 18100}
18101
7336e101
SP
18102DEFUN (show_extcommunity_list_arg,
18103 show_bgp_extcommunity_list_arg_cmd,
960b69b9 18104 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
18105 SHOW_STR
18106 BGP_STR
718e3744 18107 "List extended-community list\n"
18108 "Extcommunity-list number\n"
960b69b9 18109 "Extcommunity-list name\n"
18110 "Detailed information on extcommunity-list\n")
718e3744 18111{
d62a17ae 18112 int idx_comm_list = 3;
18113 struct community_list *list;
718e3744 18114
e237b0d2 18115 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18116 EXTCOMMUNITY_LIST_MASTER);
18117 if (!list) {
18118 vty_out(vty, "%% Can't find extcommunity-list\n");
18119 return CMD_WARNING;
18120 }
718e3744 18121
d62a17ae 18122 extcommunity_list_show(vty, list);
718e3744 18123
d62a17ae 18124 return CMD_SUCCESS;
718e3744 18125}
6b0655a2 18126
718e3744 18127/* Display community-list and extcommunity-list configuration. */
d62a17ae 18128static int community_list_config_write(struct vty *vty)
18129{
18130 struct community_list *list;
18131 struct community_entry *entry;
18132 struct community_list_master *cm;
18133 int write = 0;
18134
18135 /* Community-list. */
18136 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18137
18138 for (list = cm->num.head; list; list = list->next)
18139 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18140 vty_out(vty,
18141 "bgp community-list %s seq %" PRId64 " %s %s\n",
18142 list->name, entry->seq,
d62a17ae 18143 community_direct_str(entry->direct),
18144 community_list_config_str(entry));
18145 write++;
18146 }
18147 for (list = cm->str.head; list; list = list->next)
18148 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18149 vty_out(vty,
18150 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 18151 entry->style == COMMUNITY_LIST_STANDARD
18152 ? "standard"
18153 : "expanded",
2f8cc0e5
DA
18154 list->name, entry->seq,
18155 community_direct_str(entry->direct),
d62a17ae 18156 community_list_config_str(entry));
18157 write++;
18158 }
18159
18160 /* Extcommunity-list. */
18161 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18162
18163 for (list = cm->num.head; list; list = list->next)
18164 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18165 vty_out(vty,
18166 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
18167 list->name, entry->seq,
18168 community_direct_str(entry->direct),
d62a17ae 18169 community_list_config_str(entry));
18170 write++;
18171 }
18172 for (list = cm->str.head; list; list = list->next)
18173 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18174 vty_out(vty,
6cde4b45 18175 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 18176 entry->style == EXTCOMMUNITY_LIST_STANDARD
18177 ? "standard"
18178 : "expanded",
2f8cc0e5
DA
18179 list->name, entry->seq,
18180 community_direct_str(entry->direct),
d62a17ae 18181 community_list_config_str(entry));
18182 write++;
18183 }
18184
18185
18186 /* lcommunity-list. */
18187 cm = community_list_master_lookup(bgp_clist,
18188 LARGE_COMMUNITY_LIST_MASTER);
18189
18190 for (list = cm->num.head; list; list = list->next)
18191 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18192 vty_out(vty,
6cde4b45 18193 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
18194 list->name, entry->seq,
18195 community_direct_str(entry->direct),
d62a17ae 18196 community_list_config_str(entry));
18197 write++;
18198 }
18199 for (list = cm->str.head; list; list = list->next)
18200 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18201 vty_out(vty,
6cde4b45 18202 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 18203
d62a17ae 18204 entry->style == LARGE_COMMUNITY_LIST_STANDARD
18205 ? "standard"
18206 : "expanded",
2f8cc0e5 18207 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 18208 community_list_config_str(entry));
18209 write++;
18210 }
18211
18212 return write;
18213}
18214
612c2c15 18215static int community_list_config_write(struct vty *vty);
d62a17ae 18216static struct cmd_node community_list_node = {
f4b8291f 18217 .name = "community list",
62b346ee
DL
18218 .node = COMMUNITY_LIST_NODE,
18219 .prompt = "",
612c2c15 18220 .config_write = community_list_config_write,
718e3744 18221};
18222
d62a17ae 18223static void community_list_vty(void)
18224{
612c2c15 18225 install_node(&community_list_node);
d62a17ae 18226
18227 /* Community-list. */
7336e101
SP
18228 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
18229 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
18230 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 18231 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 18232 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 18233 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
18234 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
18235 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 18236
18237 /* Extcommunity-list. */
7336e101
SP
18238 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
18239 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
18240 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
18241 install_element(CONFIG_NODE,
18242 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 18243 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
18244 install_element(CONFIG_NODE,
18245 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
18246 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
18247 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 18248
18249 /* Large Community List */
7336e101 18250 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
18251 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
18252 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 18253 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
18254 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
18255 install_element(CONFIG_NODE,
18256 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
18257 install_element(CONFIG_NODE,
18258 &no_bgp_lcommunity_list_name_expanded_all_cmd);
18259 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
18260 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
18261 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
18262 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
18263 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
18264 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 18265}