]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgp, zebra: add family attribute to ipset and iptable context
[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
PZ
7334static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
7335 struct ecommunity **list)
ddb5b488 7336{
b9c7bc5a
PZ
7337 struct ecommunity *ecom = NULL;
7338 struct ecommunity *ecomadd;
ddb5b488 7339
b9c7bc5a 7340 for (; argc; --argc, ++argv) {
ddb5b488 7341
b9c7bc5a
PZ
7342 ecomadd = ecommunity_str2com(argv[0]->arg,
7343 ECOMMUNITY_ROUTE_TARGET, 0);
7344 if (!ecomadd) {
7345 vty_out(vty, "Malformed community-list value\n");
7346 if (ecom)
7347 ecommunity_free(&ecom);
7348 return CMD_WARNING_CONFIG_FAILED;
7349 }
ddb5b488 7350
b9c7bc5a
PZ
7351 if (ecom) {
7352 ecommunity_merge(ecom, ecomadd);
7353 ecommunity_free(&ecomadd);
7354 } else {
7355 ecom = ecomadd;
7356 }
7357 }
7358
7359 if (*list) {
7360 ecommunity_free(&*list);
ddb5b488 7361 }
b9c7bc5a
PZ
7362 *list = ecom;
7363
7364 return CMD_SUCCESS;
ddb5b488
PZ
7365}
7366
0ca70ba5
DS
7367/*
7368 * v2vimport is true if we are handling a `import vrf ...` command
7369 */
7370static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 7371{
0ca70ba5
DS
7372 afi_t afi;
7373
ddb5b488 7374 switch (vty->node) {
b9c7bc5a 7375 case BGP_IPV4_NODE:
0ca70ba5
DS
7376 afi = AFI_IP;
7377 break;
b9c7bc5a 7378 case BGP_IPV6_NODE:
0ca70ba5
DS
7379 afi = AFI_IP6;
7380 break;
ddb5b488
PZ
7381 default:
7382 vty_out(vty,
b9c7bc5a 7383 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 7384 return AFI_MAX;
ddb5b488 7385 }
69b07479 7386
0ca70ba5
DS
7387 if (!v2vimport) {
7388 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7389 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7390 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7391 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7392 vty_out(vty,
7393 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7394 return AFI_MAX;
7395 }
7396 } else {
7397 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7398 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7399 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7400 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7401 vty_out(vty,
7402 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7403 return AFI_MAX;
7404 }
7405 }
7406 return afi;
ddb5b488
PZ
7407}
7408
b9c7bc5a
PZ
7409DEFPY (af_rd_vpn_export,
7410 af_rd_vpn_export_cmd,
7411 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7412 NO_STR
ddb5b488 7413 "Specify route distinguisher\n"
b9c7bc5a
PZ
7414 "Between current address-family and vpn\n"
7415 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7416 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7417{
7418 VTY_DECLVAR_CONTEXT(bgp, bgp);
7419 struct prefix_rd prd;
7420 int ret;
ddb5b488 7421 afi_t afi;
b9c7bc5a
PZ
7422 int idx = 0;
7423 int yes = 1;
ddb5b488 7424
b9c7bc5a 7425 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7426 yes = 0;
b9c7bc5a
PZ
7427
7428 if (yes) {
7429 ret = str2prefix_rd(rd_str, &prd);
7430 if (!ret) {
7431 vty_out(vty, "%% Malformed rd\n");
7432 return CMD_WARNING_CONFIG_FAILED;
7433 }
ddb5b488
PZ
7434 }
7435
0ca70ba5 7436 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7437 if (afi == AFI_MAX)
7438 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7439
69b07479
DS
7440 /*
7441 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7442 */
7443 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7444 bgp_get_default(), bgp);
ddb5b488 7445
69b07479
DS
7446 if (yes) {
7447 bgp->vpn_policy[afi].tovpn_rd = prd;
7448 SET_FLAG(bgp->vpn_policy[afi].flags,
7449 BGP_VPN_POLICY_TOVPN_RD_SET);
7450 } else {
7451 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7452 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
7453 }
7454
69b07479
DS
7455 /* post-change: re-export vpn routes */
7456 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7457 bgp_get_default(), bgp);
7458
ddb5b488
PZ
7459 return CMD_SUCCESS;
7460}
7461
b9c7bc5a
PZ
7462ALIAS (af_rd_vpn_export,
7463 af_no_rd_vpn_export_cmd,
7464 "no rd vpn export",
ddb5b488 7465 NO_STR
b9c7bc5a
PZ
7466 "Specify route distinguisher\n"
7467 "Between current address-family and vpn\n"
7468 "For routes leaked from current address-family to vpn\n")
ddb5b488 7469
b9c7bc5a
PZ
7470DEFPY (af_label_vpn_export,
7471 af_label_vpn_export_cmd,
e70e9f8e 7472 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 7473 NO_STR
ddb5b488 7474 "label value for VRF\n"
b9c7bc5a
PZ
7475 "Between current address-family and vpn\n"
7476 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
7477 "Label Value <0-1048575>\n"
7478 "Automatically assign a label\n")
ddb5b488
PZ
7479{
7480 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7481 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 7482 afi_t afi;
b9c7bc5a
PZ
7483 int idx = 0;
7484 int yes = 1;
7485
7486 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7487 yes = 0;
ddb5b488 7488
21a16cc2
PZ
7489 /* If "no ...", squash trailing parameter */
7490 if (!yes)
7491 label_auto = NULL;
7492
e70e9f8e
PZ
7493 if (yes) {
7494 if (!label_auto)
7495 label = label_val; /* parser should force unsigned */
7496 }
ddb5b488 7497
0ca70ba5 7498 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7499 if (afi == AFI_MAX)
7500 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 7501
e70e9f8e 7502
69b07479
DS
7503 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7504 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
7505 /* no change */
7506 return CMD_SUCCESS;
e70e9f8e 7507
69b07479
DS
7508 /*
7509 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7510 */
7511 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7512 bgp_get_default(), bgp);
7513
7514 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7515 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
7516
7517 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
7518
7519 /*
7520 * label has previously been automatically
7521 * assigned by labelpool: release it
7522 *
7523 * NB if tovpn_label == MPLS_LABEL_NONE it
7524 * means the automatic assignment is in flight
7525 * and therefore the labelpool callback must
7526 * detect that the auto label is not needed.
7527 */
7528
7529 bgp_lp_release(LP_TYPE_VRF,
7530 &bgp->vpn_policy[afi],
7531 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 7532 }
69b07479
DS
7533 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7534 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7535 }
ddb5b488 7536
69b07479
DS
7537 bgp->vpn_policy[afi].tovpn_label = label;
7538 if (label_auto) {
7539 SET_FLAG(bgp->vpn_policy[afi].flags,
7540 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7541 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
7542 vpn_leak_label_callback);
ddb5b488
PZ
7543 }
7544
69b07479
DS
7545 /* post-change: re-export vpn routes */
7546 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7547 bgp_get_default(), bgp);
7548
ddb5b488
PZ
7549 return CMD_SUCCESS;
7550}
7551
b9c7bc5a
PZ
7552ALIAS (af_label_vpn_export,
7553 af_no_label_vpn_export_cmd,
7554 "no label vpn export",
7555 NO_STR
7556 "label value for VRF\n"
7557 "Between current address-family and vpn\n"
7558 "For routes leaked from current address-family to vpn\n")
ddb5b488 7559
b9c7bc5a
PZ
7560DEFPY (af_nexthop_vpn_export,
7561 af_nexthop_vpn_export_cmd,
8c85ca28 7562 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 7563 NO_STR
ddb5b488 7564 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
7565 "Between current address-family and vpn\n"
7566 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7567 "IPv4 prefix\n"
7568 "IPv6 prefix\n")
7569{
7570 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 7571 afi_t afi;
ddb5b488
PZ
7572 struct prefix p;
7573
8c85ca28
QY
7574 if (!no) {
7575 if (!nexthop_su) {
7576 vty_out(vty, "%% Nexthop required\n");
7577 return CMD_WARNING_CONFIG_FAILED;
7578 }
b9c7bc5a 7579
8c85ca28 7580 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
7581 return CMD_WARNING_CONFIG_FAILED;
7582 }
ddb5b488 7583
0ca70ba5 7584 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7585 if (afi == AFI_MAX)
7586 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7587
69b07479
DS
7588 /*
7589 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7590 */
7591 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7592 bgp_get_default(), bgp);
ddb5b488 7593
8c85ca28 7594 if (!no) {
69b07479
DS
7595 bgp->vpn_policy[afi].tovpn_nexthop = p;
7596 SET_FLAG(bgp->vpn_policy[afi].flags,
7597 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7598 } else {
7599 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7600 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
7601 }
7602
69b07479
DS
7603 /* post-change: re-export vpn routes */
7604 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7605 bgp_get_default(), bgp);
7606
ddb5b488
PZ
7607 return CMD_SUCCESS;
7608}
7609
b9c7bc5a 7610static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 7611{
b9c7bc5a
PZ
7612 if (!strcmp(dstr, "import")) {
7613 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7614 } else if (!strcmp(dstr, "export")) {
7615 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7616 } else if (!strcmp(dstr, "both")) {
7617 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7618 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7619 } else {
7620 vty_out(vty, "%% direction parse error\n");
7621 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7622 }
ddb5b488
PZ
7623 return CMD_SUCCESS;
7624}
7625
b9c7bc5a
PZ
7626DEFPY (af_rt_vpn_imexport,
7627 af_rt_vpn_imexport_cmd,
7628 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
7629 NO_STR
7630 "Specify route target list\n"
ddb5b488 7631 "Specify route target list\n"
b9c7bc5a
PZ
7632 "Between current address-family and vpn\n"
7633 "For routes leaked from vpn to current address-family: match any\n"
7634 "For routes leaked from current address-family to vpn: set\n"
7635 "both import: match any and export: set\n"
ddb5b488
PZ
7636 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7637{
7638 VTY_DECLVAR_CONTEXT(bgp, bgp);
7639 int ret;
7640 struct ecommunity *ecom = NULL;
7641 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7642 vpn_policy_direction_t dir;
7643 afi_t afi;
7644 int idx = 0;
b9c7bc5a 7645 int yes = 1;
ddb5b488 7646
b9c7bc5a 7647 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7648 yes = 0;
b9c7bc5a 7649
0ca70ba5 7650 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7651 if (afi == AFI_MAX)
7652 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7653
b9c7bc5a 7654 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7655 if (ret != CMD_SUCCESS)
7656 return ret;
7657
b9c7bc5a
PZ
7658 if (yes) {
7659 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7660 vty_out(vty, "%% Missing RTLIST\n");
7661 return CMD_WARNING_CONFIG_FAILED;
7662 }
7663 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7664 if (ret != CMD_SUCCESS) {
7665 return ret;
7666 }
ddb5b488
PZ
7667 }
7668
69b07479
DS
7669 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7670 if (!dodir[dir])
ddb5b488 7671 continue;
ddb5b488 7672
69b07479 7673 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7674
69b07479
DS
7675 if (yes) {
7676 if (bgp->vpn_policy[afi].rtlist[dir])
7677 ecommunity_free(
7678 &bgp->vpn_policy[afi].rtlist[dir]);
7679 bgp->vpn_policy[afi].rtlist[dir] =
7680 ecommunity_dup(ecom);
7681 } else {
7682 if (bgp->vpn_policy[afi].rtlist[dir])
7683 ecommunity_free(
7684 &bgp->vpn_policy[afi].rtlist[dir]);
7685 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 7686 }
69b07479
DS
7687
7688 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7689 }
69b07479 7690
d555f3e9
PZ
7691 if (ecom)
7692 ecommunity_free(&ecom);
ddb5b488
PZ
7693
7694 return CMD_SUCCESS;
7695}
7696
b9c7bc5a
PZ
7697ALIAS (af_rt_vpn_imexport,
7698 af_no_rt_vpn_imexport_cmd,
7699 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
7700 NO_STR
7701 "Specify route target list\n"
b9c7bc5a
PZ
7702 "Specify route target list\n"
7703 "Between current address-family and vpn\n"
7704 "For routes leaked from vpn to current address-family\n"
7705 "For routes leaked from current address-family to vpn\n"
7706 "both import and export\n")
7707
7708DEFPY (af_route_map_vpn_imexport,
7709 af_route_map_vpn_imexport_cmd,
7710/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
7711 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
7712 NO_STR
ddb5b488 7713 "Specify route map\n"
b9c7bc5a
PZ
7714 "Between current address-family and vpn\n"
7715 "For routes leaked from vpn to current address-family\n"
7716 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7717 "name of route-map\n")
7718{
7719 VTY_DECLVAR_CONTEXT(bgp, bgp);
7720 int ret;
7721 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7722 vpn_policy_direction_t dir;
7723 afi_t afi;
ddb5b488 7724 int idx = 0;
b9c7bc5a 7725 int yes = 1;
ddb5b488 7726
b9c7bc5a 7727 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7728 yes = 0;
b9c7bc5a 7729
0ca70ba5 7730 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7731 if (afi == AFI_MAX)
7732 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7733
b9c7bc5a 7734 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7735 if (ret != CMD_SUCCESS)
7736 return ret;
7737
69b07479
DS
7738 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7739 if (!dodir[dir])
ddb5b488 7740 continue;
ddb5b488 7741
69b07479 7742 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7743
69b07479
DS
7744 if (yes) {
7745 if (bgp->vpn_policy[afi].rmap_name[dir])
7746 XFREE(MTYPE_ROUTE_MAP_NAME,
7747 bgp->vpn_policy[afi].rmap_name[dir]);
7748 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
7749 MTYPE_ROUTE_MAP_NAME, rmap_str);
7750 bgp->vpn_policy[afi].rmap[dir] =
1de27621 7751 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
7752 if (!bgp->vpn_policy[afi].rmap[dir])
7753 return CMD_SUCCESS;
7754 } else {
7755 if (bgp->vpn_policy[afi].rmap_name[dir])
7756 XFREE(MTYPE_ROUTE_MAP_NAME,
7757 bgp->vpn_policy[afi].rmap_name[dir]);
7758 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7759 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 7760 }
69b07479
DS
7761
7762 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
7763 }
7764
7765 return CMD_SUCCESS;
7766}
7767
b9c7bc5a
PZ
7768ALIAS (af_route_map_vpn_imexport,
7769 af_no_route_map_vpn_imexport_cmd,
7770 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
7771 NO_STR
7772 "Specify route map\n"
b9c7bc5a
PZ
7773 "Between current address-family and vpn\n"
7774 "For routes leaked from vpn to current address-family\n"
7775 "For routes leaked from current address-family to vpn\n")
7776
bb4f6190 7777DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 7778 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
7779 "Import routes from another VRF\n"
7780 "Vrf routes being filtered\n"
7781 "Specify route map\n"
7782 "name of route-map\n")
7783{
7784 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
7785 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7786 afi_t afi;
bb4f6190
DS
7787 struct bgp *bgp_default;
7788
0ca70ba5 7789 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
7790 if (afi == AFI_MAX)
7791 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
7792
7793 bgp_default = bgp_get_default();
7794 if (!bgp_default) {
7795 int32_t ret;
7796 as_t as = bgp->as;
7797
7798 /* Auto-create assuming the same AS */
5d5393b9
DL
7799 ret = bgp_get_vty(&bgp_default, &as, NULL,
7800 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
7801
7802 if (ret) {
7803 vty_out(vty,
7804 "VRF default is not configured as a bgp instance\n");
7805 return CMD_WARNING;
7806 }
7807 }
7808
69b07479 7809 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 7810
ae6a6fb4
DS
7811 if (bgp->vpn_policy[afi].rmap_name[dir])
7812 XFREE(MTYPE_ROUTE_MAP_NAME,
7813 bgp->vpn_policy[afi].rmap_name[dir]);
7814 bgp->vpn_policy[afi].rmap_name[dir] =
7815 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
7816 bgp->vpn_policy[afi].rmap[dir] =
7817 route_map_lookup_warn_noexist(vty, rmap_str);
7818 if (!bgp->vpn_policy[afi].rmap[dir])
7819 return CMD_SUCCESS;
7820
7821 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7822 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 7823
69b07479
DS
7824 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7825
bb4f6190
DS
7826 return CMD_SUCCESS;
7827}
7828
ae6a6fb4
DS
7829DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
7830 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
7831 NO_STR
7832 "Import routes from another VRF\n"
7833 "Vrf routes being filtered\n"
ae6a6fb4
DS
7834 "Specify route map\n"
7835 "name of route-map\n")
7836{
7837 VTY_DECLVAR_CONTEXT(bgp, bgp);
7838 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7839 afi_t afi;
7840
7841 afi = vpn_policy_getafi(vty, bgp, true);
7842 if (afi == AFI_MAX)
7843 return CMD_WARNING_CONFIG_FAILED;
7844
7845 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7846
7847 if (bgp->vpn_policy[afi].rmap_name[dir])
7848 XFREE(MTYPE_ROUTE_MAP_NAME,
7849 bgp->vpn_policy[afi].rmap_name[dir]);
7850 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7851 bgp->vpn_policy[afi].rmap[dir] = NULL;
7852
7853 if (bgp->vpn_policy[afi].import_vrf->count == 0)
7854 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7855 BGP_CONFIG_VRF_TO_VRF_IMPORT);
7856
7857 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7858
7859 return CMD_SUCCESS;
7860}
bb4f6190 7861
4d1b335c
DA
7862DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7863 "[no] import vrf VIEWVRFNAME$import_name",
7864 NO_STR
7865 "Import routes from another VRF\n"
7866 "VRF to import from\n"
7867 "The name of the VRF\n")
12a844a5
DS
7868{
7869 VTY_DECLVAR_CONTEXT(bgp, bgp);
7870 struct listnode *node;
79ef8664
DS
7871 struct bgp *vrf_bgp, *bgp_default;
7872 int32_t ret = 0;
7873 as_t as = bgp->as;
12a844a5
DS
7874 bool remove = false;
7875 int32_t idx = 0;
7876 char *vname;
a8dadcf6 7877 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
7878 safi_t safi;
7879 afi_t afi;
7880
867f0cca 7881 if (import_name == NULL) {
7882 vty_out(vty, "%% Missing import name\n");
7883 return CMD_WARNING;
7884 }
7885
ae6a6fb4
DS
7886 if (strcmp(import_name, "route-map") == 0) {
7887 vty_out(vty, "%% Must include route-map name\n");
7888 return CMD_WARNING;
7889 }
7890
12a844a5
DS
7891 if (argv_find(argv, argc, "no", &idx))
7892 remove = true;
7893
0ca70ba5
DS
7894 afi = vpn_policy_getafi(vty, bgp, true);
7895 if (afi == AFI_MAX)
7896 return CMD_WARNING_CONFIG_FAILED;
7897
12a844a5
DS
7898 safi = bgp_node_safi(vty);
7899
25679caa 7900 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 7901 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
7902 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7903 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7904 remove ? "unimport" : "import", import_name);
7905 return CMD_WARNING;
7906 }
7907
79ef8664
DS
7908 bgp_default = bgp_get_default();
7909 if (!bgp_default) {
7910 /* Auto-create assuming the same AS */
5d5393b9
DL
7911 ret = bgp_get_vty(&bgp_default, &as, NULL,
7912 BGP_INSTANCE_TYPE_DEFAULT);
79ef8664
DS
7913
7914 if (ret) {
7915 vty_out(vty,
7916 "VRF default is not configured as a bgp instance\n");
7917 return CMD_WARNING;
7918 }
7919 }
7920
12a844a5
DS
7921 vrf_bgp = bgp_lookup_by_name(import_name);
7922 if (!vrf_bgp) {
5742e42b 7923 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
7924 vrf_bgp = bgp_default;
7925 else
0fb8d6e6 7926 /* Auto-create assuming the same AS */
5d5393b9 7927 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 7928
6e2c7fe6 7929 if (ret) {
020a3f60
DS
7930 vty_out(vty,
7931 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
7932 import_name);
7933 return CMD_WARNING;
7934 }
12a844a5
DS
7935 }
7936
12a844a5 7937 if (remove) {
44338987 7938 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 7939 } else {
44338987 7940 /* Already importing from "import_vrf"? */
12a844a5
DS
7941 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7942 vname)) {
7943 if (strcmp(vname, import_name) == 0)
7944 return CMD_WARNING;
7945 }
7946
44338987 7947 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
7948 }
7949
7950 return CMD_SUCCESS;
7951}
7952
b9c7bc5a
PZ
7953/* This command is valid only in a bgp vrf instance or the default instance */
7954DEFPY (bgp_imexport_vpn,
7955 bgp_imexport_vpn_cmd,
7956 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
7957 NO_STR
7958 "Import routes to this address-family\n"
7959 "Export routes from this address-family\n"
7960 "to/from default instance VPN RIB\n")
ddb5b488
PZ
7961{
7962 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7963 int previous_state;
ddb5b488 7964 afi_t afi;
b9c7bc5a 7965 safi_t safi;
ddb5b488 7966 int idx = 0;
b9c7bc5a
PZ
7967 int yes = 1;
7968 int flag;
7969 vpn_policy_direction_t dir;
ddb5b488 7970
b9c7bc5a 7971 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7972 yes = 0;
ddb5b488 7973
b9c7bc5a
PZ
7974 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7975 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7976
b9c7bc5a
PZ
7977 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7978 return CMD_WARNING_CONFIG_FAILED;
7979 }
ddb5b488 7980
b9c7bc5a
PZ
7981 afi = bgp_node_afi(vty);
7982 safi = bgp_node_safi(vty);
7983 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7984 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7985 return CMD_WARNING_CONFIG_FAILED;
7986 }
ddb5b488 7987
b9c7bc5a
PZ
7988 if (!strcmp(direction_str, "import")) {
7989 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7990 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7991 } else if (!strcmp(direction_str, "export")) {
7992 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7993 dir = BGP_VPN_POLICY_DIR_TOVPN;
7994 } else {
7995 vty_out(vty, "%% unknown direction %s\n", direction_str);
7996 return CMD_WARNING_CONFIG_FAILED;
7997 }
7998
7999 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 8000
b9c7bc5a
PZ
8001 if (yes) {
8002 SET_FLAG(bgp->af_flags[afi][safi], flag);
8003 if (!previous_state) {
8004 /* trigger export current vrf */
ddb5b488
PZ
8005 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8006 }
b9c7bc5a
PZ
8007 } else {
8008 if (previous_state) {
8009 /* trigger un-export current vrf */
8010 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8011 }
8012 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
8013 }
8014
8015 return CMD_SUCCESS;
8016}
8017
301ad80a
PG
8018DEFPY (af_routetarget_import,
8019 af_routetarget_import_cmd,
8020 "[no] <rt|route-target> redirect import RTLIST...",
8021 NO_STR
8022 "Specify route target list\n"
8023 "Specify route target list\n"
8024 "Flow-spec redirect type route target\n"
8025 "Import routes to this address-family\n"
8026 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8027{
8028 VTY_DECLVAR_CONTEXT(bgp, bgp);
8029 int ret;
8030 struct ecommunity *ecom = NULL;
301ad80a
PG
8031 afi_t afi;
8032 int idx = 0;
8033 int yes = 1;
8034
8035 if (argv_find(argv, argc, "no", &idx))
8036 yes = 0;
8037
0ca70ba5 8038 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8039 if (afi == AFI_MAX)
8040 return CMD_WARNING_CONFIG_FAILED;
8041
301ad80a
PG
8042 if (yes) {
8043 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8044 vty_out(vty, "%% Missing RTLIST\n");
8045 return CMD_WARNING_CONFIG_FAILED;
8046 }
8047 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
8048 if (ret != CMD_SUCCESS)
8049 return ret;
8050 }
69b07479
DS
8051
8052 if (yes) {
8053 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8054 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8055 .import_redirect_rtlist);
69b07479
DS
8056 bgp->vpn_policy[afi].import_redirect_rtlist =
8057 ecommunity_dup(ecom);
8058 } else {
8059 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8060 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8061 .import_redirect_rtlist);
69b07479 8062 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 8063 }
69b07479 8064
301ad80a
PG
8065 if (ecom)
8066 ecommunity_free(&ecom);
8067
8068 return CMD_SUCCESS;
8069}
8070
505e5056 8071DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 8072 address_family_ipv4_safi_cmd,
8073 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8074 "Enter Address Family command mode\n"
8075 "Address Family\n"
8076 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 8077{
f51bae9c 8078
d62a17ae 8079 if (argc == 3) {
2131d5cf 8080 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8081 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8082 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8083 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8084 && safi != SAFI_EVPN) {
31947174
MK
8085 vty_out(vty,
8086 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8087 return CMD_WARNING_CONFIG_FAILED;
8088 }
d62a17ae 8089 vty->node = bgp_node_type(AFI_IP, safi);
8090 } else
8091 vty->node = BGP_IPV4_NODE;
718e3744 8092
d62a17ae 8093 return CMD_SUCCESS;
718e3744 8094}
8095
505e5056 8096DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 8097 address_family_ipv6_safi_cmd,
8098 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8099 "Enter Address Family command mode\n"
8100 "Address Family\n"
8101 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 8102{
d62a17ae 8103 if (argc == 3) {
2131d5cf 8104 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8105 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8106 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8107 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8108 && safi != SAFI_EVPN) {
31947174
MK
8109 vty_out(vty,
8110 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8111 return CMD_WARNING_CONFIG_FAILED;
8112 }
d62a17ae 8113 vty->node = bgp_node_type(AFI_IP6, safi);
8114 } else
8115 vty->node = BGP_IPV6_NODE;
25ffbdc1 8116
d62a17ae 8117 return CMD_SUCCESS;
25ffbdc1 8118}
718e3744 8119
d6902373 8120#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 8121DEFUN_NOSH (address_family_vpnv4,
718e3744 8122 address_family_vpnv4_cmd,
8334fd5a 8123 "address-family vpnv4 [unicast]",
718e3744 8124 "Enter Address Family command mode\n"
8c3deaae 8125 "Address Family\n"
3a2d747c 8126 "Address Family modifier\n")
718e3744 8127{
d62a17ae 8128 vty->node = BGP_VPNV4_NODE;
8129 return CMD_SUCCESS;
718e3744 8130}
8131
505e5056 8132DEFUN_NOSH (address_family_vpnv6,
8ecd3266 8133 address_family_vpnv6_cmd,
8334fd5a 8134 "address-family vpnv6 [unicast]",
8ecd3266 8135 "Enter Address Family command mode\n"
8c3deaae 8136 "Address Family\n"
3a2d747c 8137 "Address Family modifier\n")
8ecd3266 8138{
d62a17ae 8139 vty->node = BGP_VPNV6_NODE;
8140 return CMD_SUCCESS;
8ecd3266 8141}
64e4a6c5 8142#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 8143
505e5056 8144DEFUN_NOSH (address_family_evpn,
4e0b7b6d 8145 address_family_evpn_cmd,
7111c1a0 8146 "address-family l2vpn evpn",
4e0b7b6d 8147 "Enter Address Family command mode\n"
7111c1a0
QY
8148 "Address Family\n"
8149 "Address Family modifier\n")
4e0b7b6d 8150{
2131d5cf 8151 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8152 vty->node = BGP_EVPN_NODE;
8153 return CMD_SUCCESS;
4e0b7b6d
PG
8154}
8155
505e5056 8156DEFUN_NOSH (exit_address_family,
718e3744 8157 exit_address_family_cmd,
8158 "exit-address-family",
8159 "Exit from Address Family configuration mode\n")
8160{
d62a17ae 8161 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
8162 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
8163 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
8164 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
8165 || vty->node == BGP_EVPN_NODE
8166 || vty->node == BGP_FLOWSPECV4_NODE
8167 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 8168 vty->node = BGP_NODE;
8169 return CMD_SUCCESS;
718e3744 8170}
6b0655a2 8171
8ad7271d 8172/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 8173static int bgp_clear_prefix(struct vty *vty, const char *view_name,
8174 const char *ip_str, afi_t afi, safi_t safi,
8175 struct prefix_rd *prd)
8176{
8177 int ret;
8178 struct prefix match;
9bcb3eef
DS
8179 struct bgp_dest *dest;
8180 struct bgp_dest *rm;
d62a17ae 8181 struct bgp *bgp;
8182 struct bgp_table *table;
8183 struct bgp_table *rib;
8184
8185 /* BGP structure lookup. */
8186 if (view_name) {
8187 bgp = bgp_lookup_by_name(view_name);
8188 if (bgp == NULL) {
8189 vty_out(vty, "%% Can't find BGP instance %s\n",
8190 view_name);
8191 return CMD_WARNING;
8192 }
8193 } else {
8194 bgp = bgp_get_default();
8195 if (bgp == NULL) {
8196 vty_out(vty, "%% No BGP process is configured\n");
8197 return CMD_WARNING;
8198 }
8199 }
8200
8201 /* Check IP address argument. */
8202 ret = str2prefix(ip_str, &match);
8203 if (!ret) {
8204 vty_out(vty, "%% address is malformed\n");
8205 return CMD_WARNING;
8206 }
8207
8208 match.family = afi2family(afi);
8209 rib = bgp->rib[afi][safi];
8210
8211 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
8212 for (dest = bgp_table_top(rib); dest;
8213 dest = bgp_route_next(dest)) {
8214 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8215
9bcb3eef 8216 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 8217 continue;
8218
9bcb3eef 8219 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
8220 if (table == NULL)
8221 continue;
8222
8223 if ((rm = bgp_node_match(table, &match)) != NULL) {
8224 const struct prefix *rm_p =
9bcb3eef 8225 bgp_dest_get_prefix(rm);
b54892e0
DS
8226
8227 if (rm_p->prefixlen == match.prefixlen) {
8228 SET_FLAG(rm->flags,
8229 BGP_NODE_USER_CLEAR);
8230 bgp_process(bgp, rm, afi, safi);
d62a17ae 8231 }
9bcb3eef 8232 bgp_dest_unlock_node(rm);
d62a17ae 8233 }
8234 }
8235 } else {
9bcb3eef
DS
8236 if ((dest = bgp_node_match(rib, &match)) != NULL) {
8237 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8238
9bcb3eef
DS
8239 if (dest_p->prefixlen == match.prefixlen) {
8240 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
8241 bgp_process(bgp, dest, afi, safi);
d62a17ae 8242 }
9bcb3eef 8243 bgp_dest_unlock_node(dest);
d62a17ae 8244 }
8245 }
8246
8247 return CMD_SUCCESS;
8ad7271d
DS
8248}
8249
b09b5ae0 8250/* one clear bgp command to rule them all */
718e3744 8251DEFUN (clear_ip_bgp_all,
8252 clear_ip_bgp_all_cmd,
453c92f6 8253 "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 8254 CLEAR_STR
8255 IP_STR
8256 BGP_STR
838758ac 8257 BGP_INSTANCE_HELP_STR
510afcd6 8258 BGP_AFI_HELP_STR
fd5e7b70 8259 "Address Family\n"
510afcd6 8260 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 8261 "Address Family modifier\n"
b09b5ae0 8262 "Clear all peers\n"
453c92f6 8263 "BGP IPv4 neighbor to clear\n"
a80beece 8264 "BGP IPv6 neighbor to clear\n"
838758ac 8265 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
8266 "Clear peers with the AS number\n"
8267 "Clear all external peers\n"
718e3744 8268 "Clear all members of peer-group\n"
b09b5ae0 8269 "BGP peer-group name\n"
b09b5ae0
DW
8270 BGP_SOFT_STR
8271 BGP_SOFT_IN_STR
b09b5ae0
DW
8272 BGP_SOFT_OUT_STR
8273 BGP_SOFT_IN_STR
8274 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 8275 BGP_SOFT_OUT_STR)
718e3744 8276{
d62a17ae 8277 char *vrf = NULL;
8278
dc912615
DS
8279 afi_t afi = AFI_UNSPEC;
8280 safi_t safi = SAFI_UNSPEC;
d62a17ae 8281 enum clear_sort clr_sort = clear_peer;
8282 enum bgp_clear_type clr_type;
8283 char *clr_arg = NULL;
8284
8285 int idx = 0;
8286
8287 /* clear [ip] bgp */
8288 if (argv_find(argv, argc, "ip", &idx))
8289 afi = AFI_IP;
8290
9a8bdf1c
PG
8291 /* [<vrf> VIEWVRFNAME] */
8292 if (argv_find(argv, argc, "vrf", &idx)) {
8293 vrf = argv[idx + 1]->arg;
8294 idx += 2;
8295 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8296 vrf = NULL;
8297 } else if (argv_find(argv, argc, "view", &idx)) {
8298 /* [<view> VIEWVRFNAME] */
d62a17ae 8299 vrf = argv[idx + 1]->arg;
8300 idx += 2;
8301 }
d62a17ae 8302 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8303 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8304 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8305
d7b9898c 8306 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 8307 if (argv_find(argv, argc, "*", &idx)) {
8308 clr_sort = clear_all;
8309 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8310 clr_sort = clear_peer;
8311 clr_arg = argv[idx]->arg;
8312 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8313 clr_sort = clear_peer;
8314 clr_arg = argv[idx]->arg;
8315 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8316 clr_sort = clear_group;
8317 idx++;
8318 clr_arg = argv[idx]->arg;
d7b9898c 8319 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 8320 clr_sort = clear_peer;
8321 clr_arg = argv[idx]->arg;
8fa7d444
DS
8322 } else if (argv_find(argv, argc, "WORD", &idx)) {
8323 clr_sort = clear_peer;
8324 clr_arg = argv[idx]->arg;
d62a17ae 8325 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8326 clr_sort = clear_as;
8327 clr_arg = argv[idx]->arg;
8328 } else if (argv_find(argv, argc, "external", &idx)) {
8329 clr_sort = clear_external;
8330 }
8331
8332 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8333 if (argv_find(argv, argc, "soft", &idx)) {
8334 if (argv_find(argv, argc, "in", &idx)
8335 || argv_find(argv, argc, "out", &idx))
8336 clr_type = strmatch(argv[idx]->text, "in")
8337 ? BGP_CLEAR_SOFT_IN
8338 : BGP_CLEAR_SOFT_OUT;
8339 else
8340 clr_type = BGP_CLEAR_SOFT_BOTH;
8341 } else if (argv_find(argv, argc, "in", &idx)) {
8342 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8343 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8344 : BGP_CLEAR_SOFT_IN;
8345 } else if (argv_find(argv, argc, "out", &idx)) {
8346 clr_type = BGP_CLEAR_SOFT_OUT;
8347 } else
8348 clr_type = BGP_CLEAR_SOFT_NONE;
8349
8350 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 8351}
01080f7c 8352
8ad7271d
DS
8353DEFUN (clear_ip_bgp_prefix,
8354 clear_ip_bgp_prefix_cmd,
18c57037 8355 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
8356 CLEAR_STR
8357 IP_STR
8358 BGP_STR
838758ac 8359 BGP_INSTANCE_HELP_STR
8ad7271d 8360 "Clear bestpath and re-advertise\n"
0c7b1b01 8361 "IPv4 prefix\n")
8ad7271d 8362{
d62a17ae 8363 char *vrf = NULL;
8364 char *prefix = NULL;
8ad7271d 8365
d62a17ae 8366 int idx = 0;
01080f7c 8367
d62a17ae 8368 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
8369 if (argv_find(argv, argc, "vrf", &idx)) {
8370 vrf = argv[idx + 1]->arg;
8371 idx += 2;
8372 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8373 vrf = NULL;
8374 } else if (argv_find(argv, argc, "view", &idx)) {
8375 /* [<view> VIEWVRFNAME] */
8376 vrf = argv[idx + 1]->arg;
8377 idx += 2;
8378 }
0c7b1b01 8379
d62a17ae 8380 prefix = argv[argc - 1]->arg;
8ad7271d 8381
d62a17ae 8382 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 8383}
8ad7271d 8384
b09b5ae0
DW
8385DEFUN (clear_bgp_ipv6_safi_prefix,
8386 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 8387 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8388 CLEAR_STR
3a2d747c 8389 IP_STR
718e3744 8390 BGP_STR
8c3deaae 8391 "Address Family\n"
46f296b4 8392 BGP_SAFI_HELP_STR
b09b5ae0 8393 "Clear bestpath and re-advertise\n"
0c7b1b01 8394 "IPv6 prefix\n")
718e3744 8395{
9b475e76
PG
8396 int idx_safi = 0;
8397 int idx_ipv6_prefix = 0;
8398 safi_t safi = SAFI_UNICAST;
8399 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8400 argv[idx_ipv6_prefix]->arg : NULL;
8401
8402 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 8403 return bgp_clear_prefix(
9b475e76
PG
8404 vty, NULL, prefix, AFI_IP6,
8405 safi, NULL);
838758ac 8406}
01080f7c 8407
b09b5ae0
DW
8408DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8409 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 8410 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8411 CLEAR_STR
3a2d747c 8412 IP_STR
718e3744 8413 BGP_STR
838758ac 8414 BGP_INSTANCE_HELP_STR
8c3deaae 8415 "Address Family\n"
46f296b4 8416 BGP_SAFI_HELP_STR
b09b5ae0 8417 "Clear bestpath and re-advertise\n"
0c7b1b01 8418 "IPv6 prefix\n")
718e3744 8419{
9b475e76 8420 int idx_safi = 0;
9a8bdf1c 8421 int idx_vrfview = 0;
9b475e76
PG
8422 int idx_ipv6_prefix = 0;
8423 safi_t safi = SAFI_UNICAST;
8424 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8425 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 8426 char *vrfview = NULL;
9b475e76 8427
9a8bdf1c
PG
8428 /* [<view|vrf> VIEWVRFNAME] */
8429 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8430 vrfview = argv[idx_vrfview + 1]->arg;
8431 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8432 vrfview = NULL;
8433 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8434 /* [<view> VIEWVRFNAME] */
8435 vrfview = argv[idx_vrfview + 1]->arg;
8436 }
9b475e76
PG
8437 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8438
d62a17ae 8439 return bgp_clear_prefix(
9b475e76
PG
8440 vty, vrfview, prefix,
8441 AFI_IP6, safi, NULL);
718e3744 8442}
8443
b09b5ae0
DW
8444DEFUN (show_bgp_views,
8445 show_bgp_views_cmd,
d6e3c605 8446 "show [ip] bgp views",
b09b5ae0 8447 SHOW_STR
d6e3c605 8448 IP_STR
01080f7c 8449 BGP_STR
b09b5ae0 8450 "Show the defined BGP views\n")
01080f7c 8451{
d62a17ae 8452 struct list *inst = bm->bgp;
8453 struct listnode *node;
8454 struct bgp *bgp;
01080f7c 8455
d62a17ae 8456 vty_out(vty, "Defined BGP views:\n");
8457 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8458 /* Skip VRFs. */
8459 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
8460 continue;
8461 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
8462 bgp->as);
8463 }
e52702f2 8464
d62a17ae 8465 return CMD_SUCCESS;
e0081f70
ML
8466}
8467
8386ac43 8468DEFUN (show_bgp_vrfs,
8469 show_bgp_vrfs_cmd,
d6e3c605 8470 "show [ip] bgp vrfs [json]",
8386ac43 8471 SHOW_STR
d6e3c605 8472 IP_STR
8386ac43 8473 BGP_STR
8474 "Show BGP VRFs\n"
9973d184 8475 JSON_STR)
8386ac43 8476{
fe1dc5a3 8477 char buf[ETHER_ADDR_STRLEN];
d62a17ae 8478 struct list *inst = bm->bgp;
8479 struct listnode *node;
8480 struct bgp *bgp;
9f049418 8481 bool uj = use_json(argc, argv);
d62a17ae 8482 json_object *json = NULL;
8483 json_object *json_vrfs = NULL;
8484 int count = 0;
d62a17ae 8485
d62a17ae 8486 if (uj) {
8487 json = json_object_new_object();
8488 json_vrfs = json_object_new_object();
8489 }
8490
8491 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8492 const char *name, *type;
8493 struct peer *peer;
7fe96307 8494 struct listnode *node2, *nnode2;
d62a17ae 8495 int peers_cfg, peers_estb;
8496 json_object *json_vrf = NULL;
d62a17ae 8497
8498 /* Skip Views. */
8499 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
8500 continue;
8501
8502 count++;
efb4077a 8503 if (!uj && count == 1) {
fe1dc5a3 8504 vty_out(vty,
efb4077a 8505 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 8506 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
8507 "#PeersEstb", "Name");
8508 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
8509 "L3-VNI", "RouterMAC", "Interface");
8510 }
d62a17ae 8511
8512 peers_cfg = peers_estb = 0;
8513 if (uj)
8514 json_vrf = json_object_new_object();
8515
8516
7fe96307 8517 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 8518 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8519 continue;
8520 peers_cfg++;
8521 if (peer->status == Established)
8522 peers_estb++;
8523 }
8524
8525 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 8526 name = VRF_DEFAULT_NAME;
d62a17ae 8527 type = "DFLT";
8528 } else {
8529 name = bgp->name;
8530 type = "VRF";
8531 }
8532
a8bf7d9c 8533
d62a17ae 8534 if (uj) {
a4d82a8a
PZ
8535 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8536 ? -1
8537 : (int64_t)bgp->vrf_id;
d62a17ae 8538 json_object_string_add(json_vrf, "type", type);
8539 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8540 json_object_string_add(json_vrf, "routerId",
8541 inet_ntoa(bgp->router_id));
8542 json_object_int_add(json_vrf, "numConfiguredPeers",
8543 peers_cfg);
8544 json_object_int_add(json_vrf, "numEstablishedPeers",
8545 peers_estb);
8546
fe1dc5a3 8547 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
8548 json_object_string_add(
8549 json_vrf, "rmac",
8550 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
8551 json_object_string_add(json_vrf, "interface",
8552 ifindex2ifname(bgp->l3vni_svi_ifindex,
8553 bgp->vrf_id));
d62a17ae 8554 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 8555 } else {
fe1dc5a3 8556 vty_out(vty,
efb4077a 8557 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
8558 type,
8559 bgp->vrf_id == VRF_UNKNOWN ? -1
8560 : (int)bgp->vrf_id,
8561 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
8562 peers_estb, name);
8563 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
8564 bgp->l3vni,
8565 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
8566 ifindex2ifname(bgp->l3vni_svi_ifindex,
8567 bgp->vrf_id));
8568 }
d62a17ae 8569 }
8570
8571 if (uj) {
8572 json_object_object_add(json, "vrfs", json_vrfs);
8573
8574 json_object_int_add(json, "totalVrfs", count);
8575
996c9314
LB
8576 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8577 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8578 json_object_free(json);
8579 } else {
8580 if (count)
8581 vty_out(vty,
8582 "\nTotal number of VRFs (including default): %d\n",
8583 count);
8584 }
8585
8586 return CMD_SUCCESS;
8386ac43 8587}
8588
48ecf8f5
DS
8589DEFUN (show_bgp_mac_hash,
8590 show_bgp_mac_hash_cmd,
8591 "show bgp mac hash",
8592 SHOW_STR
8593 BGP_STR
8594 "Mac Address\n"
8595 "Mac Address database\n")
8596{
8597 bgp_mac_dump_table(vty);
8598
8599 return CMD_SUCCESS;
8600}
acf71666 8601
e3b78da8 8602static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 8603{
0291c246 8604 struct vty *vty = (struct vty *)args;
e3b78da8 8605 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 8606
60466a63 8607 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
8608 tip->refcnt);
8609}
8610
8611static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
8612{
8613 vty_out(vty, "self nexthop database:\n");
af97a18b 8614 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
8615
8616 vty_out(vty, "Tunnel-ip database:\n");
8617 hash_iterate(bgp->tip_hash,
e3b78da8 8618 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
8619 vty);
8620}
8621
15c81ca4
DS
8622DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
8623 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
8624 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
8625 "martian next-hops\n"
8626 "martian next-hop database\n")
acf71666 8627{
0291c246 8628 struct bgp *bgp = NULL;
15c81ca4 8629 int idx = 0;
9a8bdf1c
PG
8630 char *name = NULL;
8631
8632 /* [<vrf> VIEWVRFNAME] */
8633 if (argv_find(argv, argc, "vrf", &idx)) {
8634 name = argv[idx + 1]->arg;
8635 if (name && strmatch(name, VRF_DEFAULT_NAME))
8636 name = NULL;
8637 } else if (argv_find(argv, argc, "view", &idx))
8638 /* [<view> VIEWVRFNAME] */
8639 name = argv[idx + 1]->arg;
8640 if (name)
8641 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
8642 else
8643 bgp = bgp_get_default();
acf71666 8644
acf71666
MK
8645 if (!bgp) {
8646 vty_out(vty, "%% No BGP process is configured\n");
8647 return CMD_WARNING;
8648 }
8649 bgp_show_martian_nexthops(vty, bgp);
8650
8651 return CMD_SUCCESS;
8652}
8653
f412b39a 8654DEFUN (show_bgp_memory,
4bf6a362 8655 show_bgp_memory_cmd,
7fa12b13 8656 "show [ip] bgp memory",
4bf6a362 8657 SHOW_STR
3a2d747c 8658 IP_STR
4bf6a362
PJ
8659 BGP_STR
8660 "Global BGP memory statistics\n")
8661{
d62a17ae 8662 char memstrbuf[MTYPE_MEMSTR_LEN];
8663 unsigned long count;
8664
8665 /* RIB related usage stats */
8666 count = mtype_stats_alloc(MTYPE_BGP_NODE);
8667 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
8668 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 8669 count * sizeof(struct bgp_dest)));
d62a17ae 8670
8671 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
8672 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
8673 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 8674 count * sizeof(struct bgp_path_info)));
d62a17ae 8675 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
8676 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
8677 count,
4b7e6066
DS
8678 mtype_memstr(
8679 memstrbuf, sizeof(memstrbuf),
8680 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 8681
8682 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
8683 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
8684 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8685 count * sizeof(struct bgp_static)));
8686
8687 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
8688 vty_out(vty, "%ld Packets, using %s of memory\n", count,
8689 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8690 count * sizeof(struct bpacket)));
8691
8692 /* Adj-In/Out */
8693 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
8694 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
8695 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8696 count * sizeof(struct bgp_adj_in)));
8697 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
8698 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
8699 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8700 count * sizeof(struct bgp_adj_out)));
8701
8702 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
8703 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
8704 count,
8705 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8706 count * sizeof(struct bgp_nexthop_cache)));
8707
8708 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
8709 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
8710 count,
8711 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8712 count * sizeof(struct bgp_damp_info)));
8713
8714 /* Attributes */
8715 count = attr_count();
8716 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
8717 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8718 count * sizeof(struct attr)));
8719
8720 if ((count = attr_unknown_count()))
8721 vty_out(vty, "%ld unknown attributes\n", count);
8722
8723 /* AS_PATH attributes */
8724 count = aspath_count();
8725 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
8726 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8727 count * sizeof(struct aspath)));
8728
8729 count = mtype_stats_alloc(MTYPE_AS_SEG);
8730 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
8731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8732 count * sizeof(struct assegment)));
8733
8734 /* Other attributes */
8735 if ((count = community_count()))
8736 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8737 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8738 count * sizeof(struct community)));
d62a17ae 8739 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
8740 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8741 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8742 count * sizeof(struct ecommunity)));
d62a17ae 8743 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
8744 vty_out(vty,
8745 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
8746 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8747 count * sizeof(struct lcommunity)));
d62a17ae 8748
8749 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
8750 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
8751 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8752 count * sizeof(struct cluster_list)));
8753
8754 /* Peer related usage */
8755 count = mtype_stats_alloc(MTYPE_BGP_PEER);
8756 vty_out(vty, "%ld peers, using %s of memory\n", count,
8757 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8758 count * sizeof(struct peer)));
8759
8760 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
8761 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
8762 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8763 count * sizeof(struct peer_group)));
8764
8765 /* Other */
d62a17ae 8766 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
8767 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
8768 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8769 count * sizeof(regex_t)));
d62a17ae 8770 return CMD_SUCCESS;
4bf6a362 8771}
fee0f4c6 8772
57a9c8a8
DS
8773static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
8774{
8775 json_object *bestpath = json_object_new_object();
8776
892fedb6 8777 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
8778 json_object_string_add(bestpath, "asPath", "ignore");
8779
892fedb6 8780 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
8781 json_object_string_add(bestpath, "asPath", "confed");
8782
892fedb6
DA
8783 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
8784 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 8785 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8786 "as-set");
8787 else
a4d82a8a 8788 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8789 "true");
8790 } else
a4d82a8a 8791 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 8792
892fedb6 8793 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 8794 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
8795 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
8796 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
8797 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 8798 json_object_string_add(bestpath, "med", "confed");
892fedb6 8799 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
8800 json_object_string_add(bestpath, "med",
8801 "missing-as-worst");
8802 else
8803 json_object_string_add(bestpath, "med", "true");
8804 }
8805
8806 json_object_object_add(json, "bestPath", bestpath);
8807}
8808
3577f1c5
DD
8809/* Print the error code/subcode for why the peer is down */
8810static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
8811 json_object *json_peer, bool use_json)
8812{
8813 const char *code_str;
8814 const char *subcode_str;
8815
8816 if (use_json) {
8817 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8818 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8819 char errorcodesubcode_hexstr[5];
8820 char errorcodesubcode_str[256];
8821
8822 code_str = bgp_notify_code_str(peer->notify.code);
8823 subcode_str = bgp_notify_subcode_str(
8824 peer->notify.code,
8825 peer->notify.subcode);
8826
772270f3
QY
8827 snprintf(errorcodesubcode_hexstr,
8828 sizeof(errorcodesubcode_hexstr), "%02X%02X",
8829 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
8830 json_object_string_add(json_peer,
8831 "lastErrorCodeSubcode",
8832 errorcodesubcode_hexstr);
8833 snprintf(errorcodesubcode_str, 255, "%s%s",
8834 code_str, subcode_str);
8835 json_object_string_add(json_peer,
8836 "lastNotificationReason",
8837 errorcodesubcode_str);
8838 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8839 && peer->notify.code == BGP_NOTIFY_CEASE
8840 && (peer->notify.subcode
8841 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8842 || peer->notify.subcode
8843 == BGP_NOTIFY_CEASE_ADMIN_RESET)
8844 && peer->notify.length) {
8845 char msgbuf[1024];
8846 const char *msg_str;
8847
8848 msg_str = bgp_notify_admin_message(
8849 msgbuf, sizeof(msgbuf),
8850 (uint8_t *)peer->notify.data,
8851 peer->notify.length);
8852 if (msg_str)
8853 json_object_string_add(
8854 json_peer,
8855 "lastShutdownDescription",
8856 msg_str);
8857 }
8858
c258527b 8859 }
3577f1c5
DD
8860 json_object_string_add(json_peer, "lastResetDueTo",
8861 peer_down_str[(int)peer->last_reset]);
05912a17
DD
8862 json_object_int_add(json_peer, "lastResetCode",
8863 peer->last_reset);
3577f1c5
DD
8864 } else {
8865 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8866 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8867 code_str = bgp_notify_code_str(peer->notify.code);
8868 subcode_str =
8869 bgp_notify_subcode_str(peer->notify.code,
8870 peer->notify.subcode);
8871 vty_out(vty, " Notification %s (%s%s)\n",
8872 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8873 ? "sent"
8874 : "received",
8875 code_str, subcode_str);
8876 } else {
e91c24c8 8877 vty_out(vty, " %s\n",
3577f1c5
DD
8878 peer_down_str[(int)peer->last_reset]);
8879 }
8880 }
8881}
8882
8883static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8884 safi_t safi)
8885{
8886 return ((peer->status != Established) ||
8887 !peer->afc_recv[afi][safi]);
8888}
8889
8890static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8891 struct peer *peer, json_object *json_peer,
8892 int max_neighbor_width, bool use_json)
8893{
8894 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8895 int len;
8896
8897 if (use_json) {
8898 if (peer_dynamic_neighbor(peer))
8899 json_object_boolean_true_add(json_peer,
8900 "dynamicPeer");
8901 if (peer->hostname)
8902 json_object_string_add(json_peer, "hostname",
8903 peer->hostname);
8904
8905 if (peer->domainname)
8906 json_object_string_add(json_peer, "domainname",
8907 peer->domainname);
8908 json_object_int_add(json_peer, "connectionsEstablished",
8909 peer->established);
8910 json_object_int_add(json_peer, "connectionsDropped",
8911 peer->dropped);
8912 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8913 use_json, json_peer);
8914 if (peer->status == Established)
8915 json_object_string_add(json_peer, "lastResetDueTo",
8916 "AFI/SAFI Not Negotiated");
8917 else
8918 bgp_show_peer_reset(NULL, peer, json_peer, true);
8919 } else {
8920 dn_flag[1] = '\0';
8921 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8922 if (peer->hostname
892fedb6 8923 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
8924 len = vty_out(vty, "%s%s(%s)", dn_flag,
8925 peer->hostname, peer->host);
8926 else
8927 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8928
8929 /* pad the neighbor column with spaces */
8930 if (len < max_neighbor_width)
8931 vty_out(vty, "%*s", max_neighbor_width - len,
8932 " ");
e91c24c8 8933 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
8934 peer->dropped,
8935 peer_uptime(peer->uptime, timebuf,
8936 BGP_UPTIME_LEN, 0, NULL));
8937 if (peer->status == Established)
8938 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8939 else
8940 bgp_show_peer_reset(vty, peer, NULL,
8941 false);
8942 }
8943}
c258527b 8944
3577f1c5 8945
718e3744 8946/* Show BGP peer's summary information. */
d62a17ae 8947static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10b49f14
DA
8948 bool show_failed, bool show_established,
8949 bool use_json)
d62a17ae 8950{
8951 struct peer *peer;
8952 struct listnode *node, *nnode;
8953 unsigned int count = 0, dn_count = 0;
8954 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8955 char neighbor_buf[VTY_BUFSIZ];
8956 int neighbor_col_default_width = 16;
3577f1c5 8957 int len, failed_count = 0;
d62a17ae 8958 int max_neighbor_width = 0;
8959 int pfx_rcd_safi;
3c13337d 8960 json_object *json = NULL;
d62a17ae 8961 json_object *json_peer = NULL;
8962 json_object *json_peers = NULL;
50e05855 8963 struct peer_af *paf;
d3ada366 8964 struct bgp_filter *filter;
d62a17ae 8965
8966 /* labeled-unicast routes are installed in the unicast table so in order
8967 * to
8968 * display the correct PfxRcd value we must look at SAFI_UNICAST
8969 */
3577f1c5 8970
d62a17ae 8971 if (safi == SAFI_LABELED_UNICAST)
8972 pfx_rcd_safi = SAFI_UNICAST;
8973 else
8974 pfx_rcd_safi = safi;
8975
8976 if (use_json) {
3c13337d 8977 json = json_object_new_object();
d62a17ae 8978 json_peers = json_object_new_object();
3577f1c5
DD
8979 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8980 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8981 continue;
8982
8983 if (peer->afc[afi][safi]) {
8984 /* See if we have at least a single failed peer */
8985 if (bgp_has_peer_failed(peer, afi, safi))
8986 failed_count++;
8987 count++;
8988 }
8989 if (peer_dynamic_neighbor(peer))
8990 dn_count++;
8991 }
c258527b 8992
d62a17ae 8993 } else {
8994 /* Loop over all neighbors that will be displayed to determine
8995 * how many
8996 * characters are needed for the Neighbor column
8997 */
8998 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8999 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9000 continue;
9001
9002 if (peer->afc[afi][safi]) {
9003 memset(dn_flag, '\0', sizeof(dn_flag));
9004 if (peer_dynamic_neighbor(peer))
9005 dn_flag[0] = '*';
9006
9007 if (peer->hostname
892fedb6
DA
9008 && CHECK_FLAG(bgp->flags,
9009 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
9010 snprintf(neighbor_buf,
9011 sizeof(neighbor_buf),
9012 "%s%s(%s) ", dn_flag,
9013 peer->hostname, peer->host);
d62a17ae 9014 else
772270f3
QY
9015 snprintf(neighbor_buf,
9016 sizeof(neighbor_buf), "%s%s ",
9017 dn_flag, peer->host);
d62a17ae 9018
9019 len = strlen(neighbor_buf);
9020
9021 if (len > max_neighbor_width)
9022 max_neighbor_width = len;
c258527b 9023
3577f1c5
DD
9024 /* See if we have at least a single failed peer */
9025 if (bgp_has_peer_failed(peer, afi, safi))
9026 failed_count++;
9027 count++;
d62a17ae 9028 }
9029 }
f933309e 9030
d62a17ae 9031 /* Originally we displayed the Neighbor column as 16
9032 * characters wide so make that the default
9033 */
9034 if (max_neighbor_width < neighbor_col_default_width)
9035 max_neighbor_width = neighbor_col_default_width;
9036 }
f933309e 9037
3577f1c5
DD
9038 if (show_failed && !failed_count) {
9039 if (use_json) {
9040 json_object_int_add(json, "failedPeersCount", 0);
9041 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 9042 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
9043
9044 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9045 json, JSON_C_TO_STRING_PRETTY));
9046 json_object_free(json);
9047 } else {
9048 vty_out(vty, "%% No failed BGP neighbors found\n");
9049 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9050 }
9051 return CMD_SUCCESS;
9052 }
c258527b 9053
3577f1c5 9054 count = 0; /* Reset the value as its used again */
d62a17ae 9055 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9056 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9057 continue;
9058
ea47320b
DL
9059 if (!peer->afc[afi][safi])
9060 continue;
d62a17ae 9061
ea47320b
DL
9062 if (!count) {
9063 unsigned long ents;
9064 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 9065 int64_t vrf_id_ui;
d62a17ae 9066
a4d82a8a
PZ
9067 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9068 ? -1
9069 : (int64_t)bgp->vrf_id;
ea47320b
DL
9070
9071 /* Usage summary and header */
9072 if (use_json) {
9073 json_object_string_add(
9074 json, "routerId",
9075 inet_ntoa(bgp->router_id));
60466a63
QY
9076 json_object_int_add(json, "as", bgp->as);
9077 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
9078 json_object_string_add(
9079 json, "vrfName",
9080 (bgp->inst_type
9081 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9082 ? VRF_DEFAULT_NAME
ea47320b
DL
9083 : bgp->name);
9084 } else {
9085 vty_out(vty,
9086 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 9087 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
9088 bgp->vrf_id == VRF_UNKNOWN
9089 ? -1
9090 : (int)bgp->vrf_id);
ea47320b
DL
9091 vty_out(vty, "\n");
9092 }
d62a17ae 9093
ea47320b 9094 if (bgp_update_delay_configured(bgp)) {
d62a17ae 9095 if (use_json) {
ea47320b 9096 json_object_int_add(
60466a63 9097 json, "updateDelayLimit",
ea47320b 9098 bgp->v_update_delay);
d62a17ae 9099
ea47320b
DL
9100 if (bgp->v_update_delay
9101 != bgp->v_establish_wait)
d62a17ae 9102 json_object_int_add(
9103 json,
ea47320b
DL
9104 "updateDelayEstablishWait",
9105 bgp->v_establish_wait);
d62a17ae 9106
60466a63 9107 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9108 json_object_string_add(
9109 json,
9110 "updateDelayFirstNeighbor",
9111 bgp->update_delay_begin_time);
9112 json_object_boolean_true_add(
9113 json,
9114 "updateDelayInProgress");
9115 } else {
9116 if (bgp->update_delay_over) {
d62a17ae 9117 json_object_string_add(
9118 json,
9119 "updateDelayFirstNeighbor",
9120 bgp->update_delay_begin_time);
ea47320b 9121 json_object_string_add(
d62a17ae 9122 json,
ea47320b
DL
9123 "updateDelayBestpathResumed",
9124 bgp->update_delay_end_time);
9125 json_object_string_add(
d62a17ae 9126 json,
ea47320b
DL
9127 "updateDelayZebraUpdateResume",
9128 bgp->update_delay_zebra_resume_time);
9129 json_object_string_add(
9130 json,
9131 "updateDelayPeerUpdateResume",
9132 bgp->update_delay_peers_resume_time);
d62a17ae 9133 }
ea47320b
DL
9134 }
9135 } else {
9136 vty_out(vty,
9137 "Read-only mode update-delay limit: %d seconds\n",
9138 bgp->v_update_delay);
9139 if (bgp->v_update_delay
9140 != bgp->v_establish_wait)
d62a17ae 9141 vty_out(vty,
ea47320b
DL
9142 " Establish wait: %d seconds\n",
9143 bgp->v_establish_wait);
d62a17ae 9144
60466a63 9145 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9146 vty_out(vty,
9147 " First neighbor established: %s\n",
9148 bgp->update_delay_begin_time);
9149 vty_out(vty,
9150 " Delay in progress\n");
9151 } else {
9152 if (bgp->update_delay_over) {
d62a17ae 9153 vty_out(vty,
9154 " First neighbor established: %s\n",
9155 bgp->update_delay_begin_time);
9156 vty_out(vty,
ea47320b
DL
9157 " Best-paths resumed: %s\n",
9158 bgp->update_delay_end_time);
9159 vty_out(vty,
9160 " zebra update resumed: %s\n",
9161 bgp->update_delay_zebra_resume_time);
9162 vty_out(vty,
9163 " peers update resumed: %s\n",
9164 bgp->update_delay_peers_resume_time);
d62a17ae 9165 }
9166 }
9167 }
ea47320b 9168 }
d62a17ae 9169
ea47320b
DL
9170 if (use_json) {
9171 if (bgp_maxmed_onstartup_configured(bgp)
9172 && bgp->maxmed_active)
9173 json_object_boolean_true_add(
60466a63 9174 json, "maxMedOnStartup");
ea47320b
DL
9175 if (bgp->v_maxmed_admin)
9176 json_object_boolean_true_add(
60466a63 9177 json, "maxMedAdministrative");
d62a17ae 9178
ea47320b
DL
9179 json_object_int_add(
9180 json, "tableVersion",
60466a63 9181 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 9182
60466a63
QY
9183 ents = bgp_table_count(bgp->rib[afi][safi]);
9184 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
9185 json_object_int_add(
9186 json, "ribMemory",
9bcb3eef 9187 ents * sizeof(struct bgp_dest));
d62a17ae 9188
210ec2a0 9189 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
9190 json_object_int_add(json, "peerCount", ents);
9191 json_object_int_add(json, "peerMemory",
9192 ents * sizeof(struct peer));
d62a17ae 9193
ea47320b
DL
9194 if ((ents = listcount(bgp->group))) {
9195 json_object_int_add(
60466a63 9196 json, "peerGroupCount", ents);
ea47320b
DL
9197 json_object_int_add(
9198 json, "peerGroupMemory",
996c9314
LB
9199 ents * sizeof(struct
9200 peer_group));
ea47320b 9201 }
d62a17ae 9202
ea47320b
DL
9203 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9204 BGP_CONFIG_DAMPENING))
9205 json_object_boolean_true_add(
60466a63 9206 json, "dampeningEnabled");
ea47320b
DL
9207 } else {
9208 if (bgp_maxmed_onstartup_configured(bgp)
9209 && bgp->maxmed_active)
d62a17ae 9210 vty_out(vty,
ea47320b
DL
9211 "Max-med on-startup active\n");
9212 if (bgp->v_maxmed_admin)
d62a17ae 9213 vty_out(vty,
ea47320b 9214 "Max-med administrative active\n");
d62a17ae 9215
60466a63
QY
9216 vty_out(vty, "BGP table version %" PRIu64 "\n",
9217 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 9218
60466a63 9219 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
9220 vty_out(vty,
9221 "RIB entries %ld, using %s of memory\n",
9222 ents,
9bcb3eef
DS
9223 mtype_memstr(
9224 memstrbuf, sizeof(memstrbuf),
9225 ents
9226 * sizeof(struct
9227 bgp_dest)));
ea47320b
DL
9228
9229 /* Peer related usage */
210ec2a0 9230 ents = bgp->af_peer_count[afi][safi];
60466a63 9231 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
9232 ents,
9233 mtype_memstr(
60466a63
QY
9234 memstrbuf, sizeof(memstrbuf),
9235 ents * sizeof(struct peer)));
ea47320b
DL
9236
9237 if ((ents = listcount(bgp->group)))
d62a17ae 9238 vty_out(vty,
ea47320b 9239 "Peer groups %ld, using %s of memory\n",
d62a17ae 9240 ents,
9241 mtype_memstr(
9242 memstrbuf,
9243 sizeof(memstrbuf),
996c9314
LB
9244 ents * sizeof(struct
9245 peer_group)));
d62a17ae 9246
ea47320b
DL
9247 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9248 BGP_CONFIG_DAMPENING))
60466a63 9249 vty_out(vty, "Dampening enabled.\n");
ea47320b 9250 vty_out(vty, "\n");
d62a17ae 9251
ea47320b
DL
9252 /* Subtract 8 here because 'Neighbor' is
9253 * 8 characters */
9254 vty_out(vty, "Neighbor");
60466a63
QY
9255 vty_out(vty, "%*s", max_neighbor_width - 8,
9256 " ");
3577f1c5
DD
9257 if (show_failed)
9258 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
9259 else
9260 vty_out(vty,
db92d226 9261 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
d62a17ae 9262 }
ea47320b 9263 }
d62a17ae 9264
d55811cc 9265 paf = peer_af_find(peer, afi, safi);
d3ada366 9266 filter = &peer->filter[afi][safi];
db92d226 9267
ea47320b 9268 count++;
3577f1c5
DD
9269 /* Works for both failed & successful cases */
9270 if (peer_dynamic_neighbor(peer))
9271 dn_count++;
d62a17ae 9272
ea47320b 9273 if (use_json) {
3577f1c5
DD
9274 json_peer = NULL;
9275
9276 if (show_failed &&
9277 bgp_has_peer_failed(peer, afi, safi)) {
9278 json_peer = json_object_new_object();
9279 bgp_show_failed_summary(vty, bgp, peer,
9280 json_peer, 0, use_json);
9281 } else if (!show_failed) {
10b49f14
DA
9282 if (show_established
9283 && bgp_has_peer_failed(peer, afi, safi))
9284 continue;
9285
3577f1c5
DD
9286 json_peer = json_object_new_object();
9287 if (peer_dynamic_neighbor(peer)) {
9288 json_object_boolean_true_add(json_peer,
9289 "dynamicPeer");
9290 }
d62a17ae 9291
3577f1c5
DD
9292 if (peer->hostname)
9293 json_object_string_add(json_peer, "hostname",
9294 peer->hostname);
9295
9296 if (peer->domainname)
9297 json_object_string_add(json_peer, "domainname",
9298 peer->domainname);
9299
9300 json_object_int_add(json_peer, "remoteAs", peer->as);
9301 json_object_int_add(json_peer, "version", 4);
9302 json_object_int_add(json_peer, "msgRcvd",
9303 PEER_TOTAL_RX(peer));
9304 json_object_int_add(json_peer, "msgSent",
9305 PEER_TOTAL_TX(peer));
9306
43aa5965
QY
9307 atomic_size_t outq_count, inq_count;
9308 outq_count = atomic_load_explicit(
9309 &peer->obuf->count,
9310 memory_order_relaxed);
9311 inq_count = atomic_load_explicit(
9312 &peer->ibuf->count,
9313 memory_order_relaxed);
9314
3577f1c5
DD
9315 json_object_int_add(json_peer, "tableVersion",
9316 peer->version[afi][safi]);
9317 json_object_int_add(json_peer, "outq",
43aa5965
QY
9318 outq_count);
9319 json_object_int_add(json_peer, "inq",
9320 inq_count);
3577f1c5
DD
9321 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9322 use_json, json_peer);
9323
3577f1c5
DD
9324 json_object_int_add(json_peer, "pfxRcd",
9325 peer->pcount[afi][pfx_rcd_safi]);
9326
3577f1c5
DD
9327 if (paf && PAF_SUBGRP(paf))
9328 json_object_int_add(json_peer,
9329 "pfxSnt",
9330 (PAF_SUBGRP(paf))->scount);
9331 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9332 json_object_string_add(json_peer, "state",
9333 "Idle (Admin)");
9334 else if (peer->afc_recv[afi][safi])
9335 json_object_string_add(
9336 json_peer, "state",
9337 lookup_msg(bgp_status_msg, peer->status,
9338 NULL));
9339 else if (CHECK_FLAG(peer->sflags,
9340 PEER_STATUS_PREFIX_OVERFLOW))
9341 json_object_string_add(json_peer, "state",
9342 "Idle (PfxCt)");
9343 else
9344 json_object_string_add(
9345 json_peer, "state",
9346 lookup_msg(bgp_status_msg, peer->status,
9347 NULL));
200116db
DD
9348 json_object_int_add(json_peer, "connectionsEstablished",
9349 peer->established);
9350 json_object_int_add(json_peer, "connectionsDropped",
9351 peer->dropped);
b4e9dcba 9352 }
3577f1c5
DD
9353 /* Avoid creating empty peer dicts in JSON */
9354 if (json_peer == NULL)
9355 continue;
ea47320b
DL
9356
9357 if (peer->conf_if)
60466a63 9358 json_object_string_add(json_peer, "idType",
ea47320b
DL
9359 "interface");
9360 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
9361 json_object_string_add(json_peer, "idType",
9362 "ipv4");
ea47320b 9363 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
9364 json_object_string_add(json_peer, "idType",
9365 "ipv6");
ea47320b
DL
9366 json_object_object_add(json_peers, peer->host,
9367 json_peer);
9368 } else {
3577f1c5
DD
9369 if (show_failed &&
9370 bgp_has_peer_failed(peer, afi, safi)) {
9371 bgp_show_failed_summary(vty, bgp, peer, NULL,
9372 max_neighbor_width,
9373 use_json);
9374 } else if (!show_failed) {
10b49f14
DA
9375 if (show_established
9376 && bgp_has_peer_failed(peer, afi, safi))
9377 continue;
9378
3577f1c5
DD
9379 memset(dn_flag, '\0', sizeof(dn_flag));
9380 if (peer_dynamic_neighbor(peer)) {
9381 dn_flag[0] = '*';
9382 }
d62a17ae 9383
3577f1c5 9384 if (peer->hostname
892fedb6
DA
9385 && CHECK_FLAG(bgp->flags,
9386 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 9387 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
9388 peer->hostname,
9389 peer->host);
d62a17ae 9390 else
3577f1c5
DD
9391 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9392
9393 /* pad the neighbor column with spaces */
9394 if (len < max_neighbor_width)
9395 vty_out(vty, "%*s", max_neighbor_width - len,
9396 " ");
9397
43aa5965
QY
9398 atomic_size_t outq_count, inq_count;
9399 outq_count = atomic_load_explicit(
9400 &peer->obuf->count,
9401 memory_order_relaxed);
9402 inq_count = atomic_load_explicit(
9403 &peer->ibuf->count,
9404 memory_order_relaxed);
9405
566bdaf6 9406 vty_out(vty,
6cde4b45 9407 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
3577f1c5 9408 peer->as, PEER_TOTAL_RX(peer),
566bdaf6 9409 PEER_TOTAL_TX(peer),
43aa5965
QY
9410 peer->version[afi][safi], inq_count,
9411 outq_count,
3577f1c5
DD
9412 peer_uptime(peer->uptime, timebuf,
9413 BGP_UPTIME_LEN, 0, NULL));
9414
db92d226 9415 if (peer->status == Established) {
d3ada366
DA
9416 if (peer->afc_recv[afi][safi]) {
9417 if (CHECK_FLAG(
9418 bgp->flags,
9419 BGP_FLAG_EBGP_REQUIRES_POLICY)
9420 && !bgp_inbound_policy_exists(
9421 peer, filter))
9422 vty_out(vty, " %12s",
9423 "(Policy)");
9424 else
9425 vty_out(vty,
6cde4b45 9426 " %12u",
d3ada366
DA
9427 peer->pcount
9428 [afi]
9429 [pfx_rcd_safi]);
9430 } else {
3577f1c5 9431 vty_out(vty, " NoNeg");
d3ada366 9432 }
db92d226 9433
d3ada366
DA
9434 if (paf && PAF_SUBGRP(paf)) {
9435 if (CHECK_FLAG(
9436 bgp->flags,
9437 BGP_FLAG_EBGP_REQUIRES_POLICY)
9438 && !bgp_outbound_policy_exists(
9439 peer, filter))
9440 vty_out(vty, " %8s",
9441 "(Policy)");
9442 else
9443 vty_out(vty,
6cde4b45 9444 " %8u",
d3ada366
DA
9445 (PAF_SUBGRP(
9446 paf))
9447 ->scount);
9448 }
db92d226 9449 } else {
3577f1c5
DD
9450 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9451 vty_out(vty, " Idle (Admin)");
9452 else if (CHECK_FLAG(
9453 peer->sflags,
9454 PEER_STATUS_PREFIX_OVERFLOW))
9455 vty_out(vty, " Idle (PfxCt)");
9456 else
9457 vty_out(vty, " %12s",
9458 lookup_msg(bgp_status_msg,
9459 peer->status, NULL));
db92d226 9460
6cde4b45 9461 vty_out(vty, " %8u", 0);
3577f1c5
DD
9462 }
9463 vty_out(vty, "\n");
d62a17ae 9464 }
3577f1c5 9465
d62a17ae 9466 }
9467 }
f933309e 9468
d62a17ae 9469 if (use_json) {
9470 json_object_object_add(json, "peers", json_peers);
3577f1c5 9471 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 9472 json_object_int_add(json, "totalPeers", count);
9473 json_object_int_add(json, "dynamicPeers", dn_count);
9474
3577f1c5
DD
9475 if (!show_failed)
9476 bgp_show_bestpath_json(bgp, json);
57a9c8a8 9477
996c9314
LB
9478 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9479 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9480 json_object_free(json);
9481 } else {
9482 if (count)
9483 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9484 else {
d6ceaca3 9485 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 9486 get_afi_safi_str(afi, safi, false));
d62a17ae 9487 }
b05a1c8b 9488
d6ceaca3 9489 if (dn_count) {
d62a17ae 9490 vty_out(vty, "* - dynamic neighbor\n");
9491 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
9492 dn_count, bgp->dynamic_neighbors_limit);
9493 }
9494 }
1ff9a340 9495
d62a17ae 9496 return CMD_SUCCESS;
718e3744 9497}
9498
d62a17ae 9499static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10b49f14
DA
9500 int safi, bool show_failed,
9501 bool show_established, bool use_json)
d62a17ae 9502{
9503 int is_first = 1;
9504 int afi_wildcard = (afi == AFI_MAX);
9505 int safi_wildcard = (safi == SAFI_MAX);
9506 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 9507 bool nbr_output = false;
d62a17ae 9508
9509 if (use_json && is_wildcard)
9510 vty_out(vty, "{\n");
9511 if (afi_wildcard)
9512 afi = 1; /* AFI_IP */
9513 while (afi < AFI_MAX) {
9514 if (safi_wildcard)
9515 safi = 1; /* SAFI_UNICAST */
9516 while (safi < SAFI_MAX) {
318cac96 9517 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 9518 nbr_output = true;
f86897b9 9519
d62a17ae 9520 if (is_wildcard) {
9521 /*
9522 * So limit output to those afi/safi
9523 * pairs that
9524 * actualy have something interesting in
9525 * them
9526 */
9527 if (use_json) {
d62a17ae 9528 if (!is_first)
9529 vty_out(vty, ",\n");
9530 else
9531 is_first = 0;
9532
9533 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
9534 get_afi_safi_str(afi,
9535 safi,
9536 true));
d62a17ae 9537 } else {
9538 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
9539 get_afi_safi_str(afi,
9540 safi,
9541 false));
d62a17ae 9542 }
9543 }
10b49f14
DA
9544 bgp_show_summary(vty, bgp, afi, safi,
9545 show_failed, show_established,
3577f1c5 9546 use_json);
d62a17ae 9547 }
9548 safi++;
d62a17ae 9549 if (!safi_wildcard)
9550 safi = SAFI_MAX;
9551 }
9552 afi++;
ee851c8c 9553 if (!afi_wildcard)
d62a17ae 9554 afi = AFI_MAX;
9555 }
9556
9557 if (use_json && is_wildcard)
9558 vty_out(vty, "}\n");
ca61fd25
DS
9559 else if (!nbr_output) {
9560 if (use_json)
9561 vty_out(vty, "{}\n");
9562 else
9563 vty_out(vty, "%% No BGP neighbors found\n");
9564 }
d62a17ae 9565}
9566
9567static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5 9568 safi_t safi, bool show_failed,
10b49f14 9569 bool show_established,
3577f1c5 9570 bool use_json)
d62a17ae 9571{
9572 struct listnode *node, *nnode;
9573 struct bgp *bgp;
d62a17ae 9574 int is_first = 1;
9f049418 9575 bool nbr_output = false;
d62a17ae 9576
9577 if (use_json)
9578 vty_out(vty, "{\n");
9579
9580 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 9581 nbr_output = true;
d62a17ae 9582 if (use_json) {
d62a17ae 9583 if (!is_first)
9584 vty_out(vty, ",\n");
9585 else
9586 is_first = 0;
9587
9588 vty_out(vty, "\"%s\":",
9589 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9590 ? VRF_DEFAULT_NAME
d62a17ae 9591 : bgp->name);
9592 } else {
9593 vty_out(vty, "\nInstance %s:\n",
9594 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9595 ? VRF_DEFAULT_NAME
d62a17ae 9596 : bgp->name);
9597 }
3577f1c5 9598 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 9599 show_established, use_json);
d62a17ae 9600 }
9601
9602 if (use_json)
9603 vty_out(vty, "}\n");
9f049418
DS
9604 else if (!nbr_output)
9605 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 9606}
9607
9608int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10b49f14
DA
9609 safi_t safi, bool show_failed, bool show_established,
9610 bool use_json)
d62a17ae 9611{
9612 struct bgp *bgp;
9613
9614 if (name) {
9615 if (strmatch(name, "all")) {
10b49f14
DA
9616 bgp_show_all_instances_summary_vty(
9617 vty, afi, safi, show_failed, show_established,
9618 use_json);
d62a17ae 9619 return CMD_SUCCESS;
9620 } else {
9621 bgp = bgp_lookup_by_name(name);
9622
9623 if (!bgp) {
9624 if (use_json)
9625 vty_out(vty, "{}\n");
9626 else
9627 vty_out(vty,
ca61fd25 9628 "%% BGP instance not found\n");
d62a17ae 9629 return CMD_WARNING;
9630 }
9631
f86897b9 9632 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
10b49f14
DA
9633 show_failed, show_established,
9634 use_json);
d62a17ae 9635 return CMD_SUCCESS;
9636 }
9637 }
9638
9639 bgp = bgp_get_default();
9640
9641 if (bgp)
3577f1c5 9642 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 9643 show_established, use_json);
9f049418 9644 else {
ca61fd25
DS
9645 if (use_json)
9646 vty_out(vty, "{}\n");
9647 else
9648 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
9649 return CMD_WARNING;
9650 }
d62a17ae 9651
9652 return CMD_SUCCESS;
4fb25c53
DW
9653}
9654
716b2d8a 9655/* `show [ip] bgp summary' commands. */
47fc97cc 9656DEFUN (show_ip_bgp_summary,
718e3744 9657 show_ip_bgp_summary_cmd,
10b49f14 9658 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [established|failed] [json]",
718e3744 9659 SHOW_STR
9660 IP_STR
9661 BGP_STR
8386ac43 9662 BGP_INSTANCE_HELP_STR
46f296b4 9663 BGP_AFI_HELP_STR
dd6bd0f1 9664 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 9665 "Summary of BGP neighbor status\n"
10b49f14 9666 "Show only sessions in Established state\n"
3577f1c5 9667 "Show only sessions not in Established state\n"
9973d184 9668 JSON_STR)
718e3744 9669{
d62a17ae 9670 char *vrf = NULL;
9671 afi_t afi = AFI_MAX;
9672 safi_t safi = SAFI_MAX;
3577f1c5 9673 bool show_failed = false;
10b49f14 9674 bool show_established = false;
d62a17ae 9675
9676 int idx = 0;
9677
9678 /* show [ip] bgp */
9679 if (argv_find(argv, argc, "ip", &idx))
9680 afi = AFI_IP;
9a8bdf1c
PG
9681 /* [<vrf> VIEWVRFNAME] */
9682 if (argv_find(argv, argc, "vrf", &idx)) {
9683 vrf = argv[idx + 1]->arg;
9684 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9685 vrf = NULL;
9686 } else if (argv_find(argv, argc, "view", &idx))
9687 /* [<view> VIEWVRFNAME] */
9688 vrf = argv[idx + 1]->arg;
d62a17ae 9689 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9690 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
9691 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9692 }
9693
3577f1c5
DD
9694 if (argv_find(argv, argc, "failed", &idx))
9695 show_failed = true;
10b49f14
DA
9696 if (argv_find(argv, argc, "established", &idx))
9697 show_established = true;
3577f1c5 9698
9f049418 9699 bool uj = use_json(argc, argv);
d62a17ae 9700
10b49f14
DA
9701 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
9702 show_established, uj);
d62a17ae 9703}
9704
5cb5f4d0 9705const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 9706{
5cb5f4d0
DD
9707 if (for_json)
9708 return get_afi_safi_json_str(afi, safi);
d62a17ae 9709 else
5cb5f4d0 9710 return get_afi_safi_vty_str(afi, safi);
27162734
LB
9711}
9712
d62a17ae 9713
9714static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
9715 afi_t afi, safi_t safi,
d7c0a89a
QY
9716 uint16_t adv_smcap, uint16_t adv_rmcap,
9717 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 9718 bool use_json, json_object *json_pref)
d62a17ae 9719{
9720 /* Send-Mode */
9721 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9722 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
9723 if (use_json) {
9724 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9725 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9726 json_object_string_add(json_pref, "sendMode",
9727 "advertisedAndReceived");
9728 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9729 json_object_string_add(json_pref, "sendMode",
9730 "advertised");
9731 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9732 json_object_string_add(json_pref, "sendMode",
9733 "received");
9734 } else {
9735 vty_out(vty, " Send-mode: ");
9736 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9737 vty_out(vty, "advertised");
9738 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9739 vty_out(vty, "%sreceived",
9740 CHECK_FLAG(p->af_cap[afi][safi],
9741 adv_smcap)
9742 ? ", "
9743 : "");
9744 vty_out(vty, "\n");
9745 }
9746 }
9747
9748 /* Receive-Mode */
9749 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9750 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
9751 if (use_json) {
9752 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9753 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9754 json_object_string_add(json_pref, "recvMode",
9755 "advertisedAndReceived");
9756 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9757 json_object_string_add(json_pref, "recvMode",
9758 "advertised");
9759 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9760 json_object_string_add(json_pref, "recvMode",
9761 "received");
9762 } else {
9763 vty_out(vty, " Receive-mode: ");
9764 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9765 vty_out(vty, "advertised");
9766 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9767 vty_out(vty, "%sreceived",
9768 CHECK_FLAG(p->af_cap[afi][safi],
9769 adv_rmcap)
9770 ? ", "
9771 : "");
9772 vty_out(vty, "\n");
9773 }
9774 }
9775}
9776
13909c4f
DS
9777static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
9778 struct peer *p,
9779 bool use_json,
9780 json_object *json)
2986cac2 9781{
08c2d52a 9782 bool rbit_status = false;
2986cac2 9783
9784 if (!use_json)
a53ca37b 9785 vty_out(vty, "\n R bit: ");
2986cac2 9786
13909c4f
DS
9787 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
9788 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
9789 && (p->status == Established)) {
2986cac2 9790
9791 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 9792 rbit_status = true;
2986cac2 9793 else
08c2d52a 9794 rbit_status = false;
2986cac2 9795 }
9796
9797 if (rbit_status) {
9798 if (use_json)
13909c4f 9799 json_object_boolean_true_add(json, "rBit");
2986cac2 9800 else
9801 vty_out(vty, "True\n");
9802 } else {
9803 if (use_json)
13909c4f 9804 json_object_boolean_false_add(json, "rBit");
2986cac2 9805 else
9806 vty_out(vty, "False\n");
9807 }
9808}
9809
13909c4f
DS
9810static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
9811 struct peer *peer,
9812 bool use_json,
9813 json_object *json)
2986cac2 9814{
2bb5d39b 9815 const char *mode = "NotApplicable";
2986cac2 9816
9817 if (!use_json)
a53ca37b 9818 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 9819
13909c4f
DS
9820 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9821 && (peer->status == Established)) {
2986cac2 9822
13909c4f
DS
9823 if ((peer->nsf_af_count == 0)
9824 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9825
2986cac2 9826 mode = "Disable";
9827
13909c4f
DS
9828 } else if (peer->nsf_af_count == 0
9829 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9830
2986cac2 9831 mode = "Helper";
9832
13909c4f
DS
9833 } else if (peer->nsf_af_count != 0
9834 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9835
2986cac2 9836 mode = "Restart";
2986cac2 9837 }
9838 }
9839
9840 if (use_json) {
13909c4f 9841 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 9842 } else
9843 vty_out(vty, mode, "\n");
9844}
9845
13909c4f
DS
9846static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
9847 struct peer *p,
9848 bool use_json,
9849 json_object *json)
2986cac2 9850{
9851 const char *mode = "Invalid";
9852
9853 if (!use_json)
a53ca37b 9854 vty_out(vty, " Local GR Mode: ");
2986cac2 9855
9856 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
9857 mode = "Helper";
9858 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
9859 mode = "Restart";
9860 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
9861 mode = "Disable";
2ba1fe69 9862 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 9863 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
9864 mode = "Helper*";
9865 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
9866 mode = "Restart*";
9867 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
9868 mode = "Disable*";
9869 else
9870 mode = "Invalid*";
2ba1fe69 9871 }
2986cac2 9872
9873 if (use_json) {
13909c4f 9874 json_object_string_add(json, "localGrMode", mode);
2986cac2 9875 } else {
9876 vty_out(vty, mode, "\n");
9877 }
9878}
9879
13909c4f
DS
9880static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
9881 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 9882{
2ba1fe69 9883 afi_t afi;
9884 safi_t safi;
2986cac2 9885 json_object *json_afi_safi = NULL;
9886 json_object *json_timer = NULL;
9887 json_object *json_endofrib_status = NULL;
9e3b51a7 9888 bool eor_flag = false;
2986cac2 9889
9890 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9891 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
9892 if (!peer->afc[afi][safi])
9893 continue;
2986cac2 9894
13909c4f
DS
9895 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9896 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
9897 continue;
9e3b51a7 9898
13909c4f
DS
9899 if (use_json) {
9900 json_afi_safi = json_object_new_object();
9901 json_endofrib_status = json_object_new_object();
9902 json_timer = json_object_new_object();
9903 }
2986cac2 9904
13909c4f
DS
9905 if (peer->eor_stime[afi][safi]
9906 >= peer->pkt_stime[afi][safi])
9907 eor_flag = true;
9908 else
9909 eor_flag = false;
2986cac2 9910
13909c4f 9911 if (!use_json) {
a53ca37b 9912 vty_out(vty, " %s:\n",
13909c4f 9913 get_afi_safi_str(afi, safi, false));
2986cac2 9914
a53ca37b 9915 vty_out(vty, " F bit: ");
698ba8d0 9916 }
2986cac2 9917
13909c4f
DS
9918 if (peer->nsf[afi][safi]
9919 && CHECK_FLAG(peer->af_cap[afi][safi],
9920 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 9921
13909c4f
DS
9922 if (use_json) {
9923 json_object_boolean_true_add(
2986cac2 9924 json_afi_safi, "fBit");
13909c4f
DS
9925 } else
9926 vty_out(vty, "True\n");
9927 } else {
9928 if (use_json)
9929 json_object_boolean_false_add(
9930 json_afi_safi, "fBit");
9931 else
9932 vty_out(vty, "False\n");
9933 }
2986cac2 9934
13909c4f 9935 if (!use_json)
a53ca37b 9936 vty_out(vty, " End-of-RIB sent: ");
2986cac2 9937
13909c4f
DS
9938 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9939 PEER_STATUS_EOR_SEND)) {
9940 if (use_json) {
9941 json_object_boolean_true_add(
2986cac2 9942 json_endofrib_status,
13909c4f 9943 "endOfRibSend");
9e3b51a7 9944
13909c4f
DS
9945 PRINT_EOR_JSON(eor_flag);
9946 } else {
9947 vty_out(vty, "Yes\n");
9948 vty_out(vty,
a53ca37b 9949 " End-of-RIB sent after update: ");
2986cac2 9950
13909c4f
DS
9951 PRINT_EOR(eor_flag);
9952 }
9953 } else {
9954 if (use_json) {
9955 json_object_boolean_false_add(
2986cac2 9956 json_endofrib_status,
13909c4f
DS
9957 "endOfRibSend");
9958 json_object_boolean_false_add(
9e3b51a7 9959 json_endofrib_status,
13909c4f
DS
9960 "endOfRibSentAfterUpdate");
9961 } else {
9962 vty_out(vty, "No\n");
9963 vty_out(vty,
a53ca37b 9964 " End-of-RIB sent after update: ");
13909c4f 9965 vty_out(vty, "No\n");
2986cac2 9966 }
13909c4f 9967 }
2986cac2 9968
a53ca37b
DA
9969 if (!use_json)
9970 vty_out(vty, " End-of-RIB received: ");
9971
9972 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9973 PEER_STATUS_EOR_RECEIVED)) {
9974 if (use_json)
9975 json_object_boolean_true_add(
9976 json_endofrib_status,
9977 "endOfRibRecv");
9978 else
9979 vty_out(vty, "Yes\n");
9980 } else {
9981 if (use_json)
9982 json_object_boolean_false_add(
9983 json_endofrib_status,
9984 "endOfRibRecv");
9985 else
9986 vty_out(vty, "No\n");
9987 }
9988
13909c4f
DS
9989 if (use_json) {
9990 json_object_int_add(json_timer,
9991 "stalePathTimer",
9992 peer->bgp->stalepath_time);
2986cac2 9993
13909c4f
DS
9994 if (peer->t_gr_stale != NULL) {
9995 json_object_int_add(
2986cac2 9996 json_timer,
9997 "stalePathTimerRemaining",
9998 thread_timer_remain_second(
13909c4f
DS
9999 peer->t_gr_stale));
10000 }
3a75afa4 10001
13909c4f
DS
10002 /* Display Configured Selection
10003 * Deferral only when when
10004 * Gr mode is enabled.
10005 */
10006 if (CHECK_FLAG(peer->flags,
10007 PEER_FLAG_GRACEFUL_RESTART)) {
10008 json_object_int_add(
3a75afa4 10009 json_timer,
2986cac2 10010 "selectionDeferralTimer",
10011 peer->bgp->stalepath_time);
13909c4f 10012 }
2986cac2 10013
13909c4f
DS
10014 if (peer->bgp->gr_info[afi][safi]
10015 .t_select_deferral
10016 != NULL) {
2986cac2 10017
13909c4f 10018 json_object_int_add(
2986cac2 10019 json_timer,
10020 "selectionDeferralTimerRemaining",
10021 thread_timer_remain_second(
13909c4f
DS
10022 peer->bgp
10023 ->gr_info[afi]
10024 [safi]
10025 .t_select_deferral));
10026 }
10027 } else {
a53ca37b 10028 vty_out(vty, " Timers:\n");
13909c4f 10029 vty_out(vty,
a53ca37b
DA
10030 " Configured Stale Path Time(sec): %u\n",
10031 peer->bgp->stalepath_time);
2986cac2 10032
a53ca37b 10033 if (peer->t_gr_stale != NULL)
2986cac2 10034 vty_out(vty,
a53ca37b 10035 " Stale Path Remaining(sec): %ld\n",
2986cac2 10036 thread_timer_remain_second(
13909c4f 10037 peer->t_gr_stale));
13909c4f
DS
10038 /* Display Configured Selection
10039 * Deferral only when when
10040 * Gr mode is enabled.
10041 */
10042 if (CHECK_FLAG(peer->flags,
a53ca37b 10043 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 10044 vty_out(vty,
a53ca37b 10045 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 10046 peer->bgp->select_defer_time);
2986cac2 10047
13909c4f
DS
10048 if (peer->bgp->gr_info[afi][safi]
10049 .t_select_deferral
a53ca37b 10050 != NULL)
13909c4f 10051 vty_out(vty,
a53ca37b 10052 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 10053 thread_timer_remain_second(
13909c4f
DS
10054 peer->bgp
10055 ->gr_info[afi]
10056 [safi]
10057 .t_select_deferral));
2986cac2 10058 }
13909c4f
DS
10059 if (use_json) {
10060 json_object_object_add(json_afi_safi,
10061 "endOfRibStatus",
10062 json_endofrib_status);
10063 json_object_object_add(json_afi_safi, "timers",
10064 json_timer);
10065 json_object_object_add(
10066 json, get_afi_safi_str(afi, safi, true),
10067 json_afi_safi);
10068 }
2986cac2 10069 }
10070 }
10071}
10072
36235319
QY
10073static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
10074 struct peer *p,
10075 bool use_json,
10076 json_object *json)
2986cac2 10077{
10078 if (use_json) {
10079 json_object *json_timer = NULL;
10080
10081 json_timer = json_object_new_object();
10082
13909c4f
DS
10083 json_object_int_add(json_timer, "configuredRestartTimer",
10084 p->bgp->restart_time);
2986cac2 10085
13909c4f
DS
10086 json_object_int_add(json_timer, "receivedRestartTimer",
10087 p->v_gr_restart);
2986cac2 10088
13909c4f
DS
10089 if (p->t_gr_restart != NULL)
10090 json_object_int_add(
10091 json_timer, "restartTimerRemaining",
10092 thread_timer_remain_second(p->t_gr_restart));
2986cac2 10093
10094 json_object_object_add(json, "timers", json_timer);
10095 } else {
10096
a53ca37b
DA
10097 vty_out(vty, " Timers:\n");
10098 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 10099 p->bgp->restart_time);
2986cac2 10100
a53ca37b 10101 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
10102 p->v_gr_restart);
10103 if (p->t_gr_restart != NULL)
a53ca37b 10104 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 10105 thread_timer_remain_second(p->t_gr_restart));
36235319 10106 if (p->t_gr_restart != NULL) {
a53ca37b 10107 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
10108 thread_timer_remain_second(p->t_gr_restart));
10109 }
2986cac2 10110 }
10111}
10112
10113static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 10114 bool use_json, json_object *json)
2986cac2 10115{
10116 char buf[SU_ADDRSTRLEN] = {0};
10117 char dn_flag[2] = {0};
2b7165e7
QY
10118 /* '*' + v6 address of neighbor */
10119 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 10120
2986cac2 10121 if (!p->conf_if && peer_dynamic_neighbor(p))
10122 dn_flag[0] = '*';
10123
10124 if (p->conf_if) {
10125 if (use_json)
13909c4f
DS
10126 json_object_string_add(
10127 json, "neighborAddr",
2986cac2 10128 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
10129 ? "none"
10130 : sockunion2str(&p->su, buf,
10131 SU_ADDRSTRLEN));
2986cac2 10132 else
13909c4f 10133 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 10134 BGP_PEER_SU_UNSPEC(p)
10135 ? "none"
10136 : sockunion2str(&p->su, buf,
10137 SU_ADDRSTRLEN));
10138 } else {
772270f3
QY
10139 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
10140 p->host);
2986cac2 10141
10142 if (use_json)
36235319
QY
10143 json_object_string_add(json, "neighborAddr",
10144 neighborAddr);
2986cac2 10145 else
36235319 10146 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 10147 }
10148
10149 /* more gr info in new format */
10150 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
10151}
10152
d62a17ae 10153static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 10154 safi_t safi, bool use_json,
d62a17ae 10155 json_object *json_neigh)
10156{
0291c246
MK
10157 struct bgp_filter *filter;
10158 struct peer_af *paf;
10159 char orf_pfx_name[BUFSIZ];
10160 int orf_pfx_count;
10161 json_object *json_af = NULL;
10162 json_object *json_prefA = NULL;
10163 json_object *json_prefB = NULL;
10164 json_object *json_addr = NULL;
d62a17ae 10165
10166 if (use_json) {
10167 json_addr = json_object_new_object();
10168 json_af = json_object_new_object();
10169 filter = &p->filter[afi][safi];
10170
10171 if (peer_group_active(p))
10172 json_object_string_add(json_addr, "peerGroupMember",
10173 p->group->name);
10174
10175 paf = peer_af_find(p, afi, safi);
10176 if (paf && PAF_SUBGRP(paf)) {
10177 json_object_int_add(json_addr, "updateGroupId",
10178 PAF_UPDGRP(paf)->id);
10179 json_object_int_add(json_addr, "subGroupId",
10180 PAF_SUBGRP(paf)->id);
10181 json_object_int_add(json_addr, "packetQueueLength",
10182 bpacket_queue_virtual_length(paf));
10183 }
10184
10185 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10186 || CHECK_FLAG(p->af_cap[afi][safi],
10187 PEER_CAP_ORF_PREFIX_SM_RCV)
10188 || CHECK_FLAG(p->af_cap[afi][safi],
10189 PEER_CAP_ORF_PREFIX_RM_ADV)
10190 || CHECK_FLAG(p->af_cap[afi][safi],
10191 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10192 json_object_int_add(json_af, "orfType",
10193 ORF_TYPE_PREFIX);
10194 json_prefA = json_object_new_object();
10195 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
10196 PEER_CAP_ORF_PREFIX_SM_ADV,
10197 PEER_CAP_ORF_PREFIX_RM_ADV,
10198 PEER_CAP_ORF_PREFIX_SM_RCV,
10199 PEER_CAP_ORF_PREFIX_RM_RCV,
10200 use_json, json_prefA);
10201 json_object_object_add(json_af, "orfPrefixList",
10202 json_prefA);
10203 }
10204
10205 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10206 || CHECK_FLAG(p->af_cap[afi][safi],
10207 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10208 || CHECK_FLAG(p->af_cap[afi][safi],
10209 PEER_CAP_ORF_PREFIX_RM_ADV)
10210 || CHECK_FLAG(p->af_cap[afi][safi],
10211 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10212 json_object_int_add(json_af, "orfOldType",
10213 ORF_TYPE_PREFIX_OLD);
10214 json_prefB = json_object_new_object();
10215 bgp_show_peer_afi_orf_cap(
10216 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10217 PEER_CAP_ORF_PREFIX_RM_ADV,
10218 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10219 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
10220 json_prefB);
10221 json_object_object_add(json_af, "orfOldPrefixList",
10222 json_prefB);
10223 }
10224
10225 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10226 || CHECK_FLAG(p->af_cap[afi][safi],
10227 PEER_CAP_ORF_PREFIX_SM_RCV)
10228 || CHECK_FLAG(p->af_cap[afi][safi],
10229 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10230 || CHECK_FLAG(p->af_cap[afi][safi],
10231 PEER_CAP_ORF_PREFIX_RM_ADV)
10232 || CHECK_FLAG(p->af_cap[afi][safi],
10233 PEER_CAP_ORF_PREFIX_RM_RCV)
10234 || CHECK_FLAG(p->af_cap[afi][safi],
10235 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10236 json_object_object_add(json_addr, "afDependentCap",
10237 json_af);
10238 else
10239 json_object_free(json_af);
10240
772270f3
QY
10241 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10242 p->host, afi, safi);
d62a17ae 10243 orf_pfx_count = prefix_bgp_show_prefix_list(
10244 NULL, afi, orf_pfx_name, use_json);
10245
10246 if (CHECK_FLAG(p->af_sflags[afi][safi],
10247 PEER_STATUS_ORF_PREFIX_SEND)
10248 || orf_pfx_count) {
10249 if (CHECK_FLAG(p->af_sflags[afi][safi],
10250 PEER_STATUS_ORF_PREFIX_SEND))
10251 json_object_boolean_true_add(json_neigh,
10252 "orfSent");
10253 if (orf_pfx_count)
10254 json_object_int_add(json_addr, "orfRecvCounter",
10255 orf_pfx_count);
10256 }
10257 if (CHECK_FLAG(p->af_sflags[afi][safi],
10258 PEER_STATUS_ORF_WAIT_REFRESH))
10259 json_object_string_add(
10260 json_addr, "orfFirstUpdate",
10261 "deferredUntilORFOrRouteRefreshRecvd");
10262
10263 if (CHECK_FLAG(p->af_flags[afi][safi],
10264 PEER_FLAG_REFLECTOR_CLIENT))
10265 json_object_boolean_true_add(json_addr,
10266 "routeReflectorClient");
10267 if (CHECK_FLAG(p->af_flags[afi][safi],
10268 PEER_FLAG_RSERVER_CLIENT))
10269 json_object_boolean_true_add(json_addr,
10270 "routeServerClient");
10271 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10272 json_object_boolean_true_add(json_addr,
10273 "inboundSoftConfigPermit");
10274
10275 if (CHECK_FLAG(p->af_flags[afi][safi],
10276 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10277 json_object_boolean_true_add(
10278 json_addr,
10279 "privateAsNumsAllReplacedInUpdatesToNbr");
10280 else if (CHECK_FLAG(p->af_flags[afi][safi],
10281 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10282 json_object_boolean_true_add(
10283 json_addr,
10284 "privateAsNumsReplacedInUpdatesToNbr");
10285 else if (CHECK_FLAG(p->af_flags[afi][safi],
10286 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10287 json_object_boolean_true_add(
10288 json_addr,
10289 "privateAsNumsAllRemovedInUpdatesToNbr");
10290 else if (CHECK_FLAG(p->af_flags[afi][safi],
10291 PEER_FLAG_REMOVE_PRIVATE_AS))
10292 json_object_boolean_true_add(
10293 json_addr,
10294 "privateAsNumsRemovedInUpdatesToNbr");
10295
dcc68b5e
MS
10296 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10297 json_object_boolean_true_add(
10298 json_addr,
10299 bgp_addpath_names(p->addpath_type[afi][safi])
10300 ->type_json_name);
d62a17ae 10301
10302 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10303 json_object_string_add(json_addr,
10304 "overrideASNsInOutboundUpdates",
10305 "ifAspathEqualRemoteAs");
10306
10307 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10308 || CHECK_FLAG(p->af_flags[afi][safi],
10309 PEER_FLAG_FORCE_NEXTHOP_SELF))
10310 json_object_boolean_true_add(json_addr,
10311 "routerAlwaysNextHop");
10312 if (CHECK_FLAG(p->af_flags[afi][safi],
10313 PEER_FLAG_AS_PATH_UNCHANGED))
10314 json_object_boolean_true_add(
10315 json_addr, "unchangedAsPathPropogatedToNbr");
10316 if (CHECK_FLAG(p->af_flags[afi][safi],
10317 PEER_FLAG_NEXTHOP_UNCHANGED))
10318 json_object_boolean_true_add(
10319 json_addr, "unchangedNextHopPropogatedToNbr");
10320 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10321 json_object_boolean_true_add(
10322 json_addr, "unchangedMedPropogatedToNbr");
10323 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10324 || CHECK_FLAG(p->af_flags[afi][safi],
10325 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10326 if (CHECK_FLAG(p->af_flags[afi][safi],
10327 PEER_FLAG_SEND_COMMUNITY)
10328 && CHECK_FLAG(p->af_flags[afi][safi],
10329 PEER_FLAG_SEND_EXT_COMMUNITY))
10330 json_object_string_add(json_addr,
10331 "commAttriSentToNbr",
10332 "extendedAndStandard");
10333 else if (CHECK_FLAG(p->af_flags[afi][safi],
10334 PEER_FLAG_SEND_EXT_COMMUNITY))
10335 json_object_string_add(json_addr,
10336 "commAttriSentToNbr",
10337 "extended");
10338 else
10339 json_object_string_add(json_addr,
10340 "commAttriSentToNbr",
10341 "standard");
10342 }
10343 if (CHECK_FLAG(p->af_flags[afi][safi],
10344 PEER_FLAG_DEFAULT_ORIGINATE)) {
10345 if (p->default_rmap[afi][safi].name)
10346 json_object_string_add(
10347 json_addr, "defaultRouteMap",
10348 p->default_rmap[afi][safi].name);
10349
10350 if (paf && PAF_SUBGRP(paf)
10351 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10352 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10353 json_object_boolean_true_add(json_addr,
10354 "defaultSent");
10355 else
10356 json_object_boolean_true_add(json_addr,
10357 "defaultNotSent");
10358 }
10359
dff8f48d 10360 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10361 if (is_evpn_enabled())
60466a63
QY
10362 json_object_boolean_true_add(
10363 json_addr, "advertiseAllVnis");
dff8f48d
MK
10364 }
10365
d62a17ae 10366 if (filter->plist[FILTER_IN].name
10367 || filter->dlist[FILTER_IN].name
10368 || filter->aslist[FILTER_IN].name
10369 || filter->map[RMAP_IN].name)
10370 json_object_boolean_true_add(json_addr,
10371 "inboundPathPolicyConfig");
10372 if (filter->plist[FILTER_OUT].name
10373 || filter->dlist[FILTER_OUT].name
10374 || filter->aslist[FILTER_OUT].name
10375 || filter->map[RMAP_OUT].name || filter->usmap.name)
10376 json_object_boolean_true_add(
10377 json_addr, "outboundPathPolicyConfig");
10378
10379 /* prefix-list */
10380 if (filter->plist[FILTER_IN].name)
10381 json_object_string_add(json_addr,
10382 "incomingUpdatePrefixFilterList",
10383 filter->plist[FILTER_IN].name);
10384 if (filter->plist[FILTER_OUT].name)
10385 json_object_string_add(json_addr,
10386 "outgoingUpdatePrefixFilterList",
10387 filter->plist[FILTER_OUT].name);
10388
10389 /* distribute-list */
10390 if (filter->dlist[FILTER_IN].name)
10391 json_object_string_add(
10392 json_addr, "incomingUpdateNetworkFilterList",
10393 filter->dlist[FILTER_IN].name);
10394 if (filter->dlist[FILTER_OUT].name)
10395 json_object_string_add(
10396 json_addr, "outgoingUpdateNetworkFilterList",
10397 filter->dlist[FILTER_OUT].name);
10398
10399 /* filter-list. */
10400 if (filter->aslist[FILTER_IN].name)
10401 json_object_string_add(json_addr,
10402 "incomingUpdateAsPathFilterList",
10403 filter->aslist[FILTER_IN].name);
10404 if (filter->aslist[FILTER_OUT].name)
10405 json_object_string_add(json_addr,
10406 "outgoingUpdateAsPathFilterList",
10407 filter->aslist[FILTER_OUT].name);
10408
10409 /* route-map. */
10410 if (filter->map[RMAP_IN].name)
10411 json_object_string_add(
10412 json_addr, "routeMapForIncomingAdvertisements",
10413 filter->map[RMAP_IN].name);
10414 if (filter->map[RMAP_OUT].name)
10415 json_object_string_add(
10416 json_addr, "routeMapForOutgoingAdvertisements",
10417 filter->map[RMAP_OUT].name);
10418
9dac9fc8 10419 /* ebgp-requires-policy (inbound) */
1d3fdccf 10420 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10421 && !bgp_inbound_policy_exists(p, filter))
10422 json_object_string_add(
10423 json_addr, "inboundEbgpRequiresPolicy",
10424 "Inbound updates discarded due to missing policy");
10425
10426 /* ebgp-requires-policy (outbound) */
1d3fdccf 10427 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10428 && (!bgp_outbound_policy_exists(p, filter)))
10429 json_object_string_add(
10430 json_addr, "outboundEbgpRequiresPolicy",
10431 "Outbound updates discarded due to missing policy");
10432
d62a17ae 10433 /* unsuppress-map */
10434 if (filter->usmap.name)
10435 json_object_string_add(json_addr,
10436 "selectiveUnsuppressRouteMap",
10437 filter->usmap.name);
10438
10439 /* Receive prefix count */
10440 json_object_int_add(json_addr, "acceptedPrefixCounter",
10441 p->pcount[afi][safi]);
50e05855
AD
10442 if (paf && PAF_SUBGRP(paf))
10443 json_object_int_add(json_addr, "sentPrefixCounter",
10444 (PAF_SUBGRP(paf))->scount);
d62a17ae 10445
fde246e8
DA
10446 /* Maximum prefix */
10447 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10448 json_object_int_add(json_addr, "prefixOutAllowedMax",
10449 p->pmax_out[afi][safi]);
10450
d62a17ae 10451 /* Maximum prefix */
10452 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10453 json_object_int_add(json_addr, "prefixAllowedMax",
10454 p->pmax[afi][safi]);
10455 if (CHECK_FLAG(p->af_flags[afi][safi],
10456 PEER_FLAG_MAX_PREFIX_WARNING))
10457 json_object_boolean_true_add(
10458 json_addr, "prefixAllowedMaxWarning");
10459 json_object_int_add(json_addr,
10460 "prefixAllowedWarningThresh",
10461 p->pmax_threshold[afi][safi]);
10462 if (p->pmax_restart[afi][safi])
10463 json_object_int_add(
10464 json_addr,
10465 "prefixAllowedRestartIntervalMsecs",
10466 p->pmax_restart[afi][safi] * 60000);
10467 }
2986cac2 10468 json_object_object_add(json_neigh,
36235319 10469 get_afi_safi_str(afi, safi, true),
d62a17ae 10470 json_addr);
10471
10472 } else {
10473 filter = &p->filter[afi][safi];
10474
10475 vty_out(vty, " For address family: %s\n",
5cb5f4d0 10476 get_afi_safi_str(afi, safi, false));
d62a17ae 10477
10478 if (peer_group_active(p))
10479 vty_out(vty, " %s peer-group member\n",
10480 p->group->name);
10481
10482 paf = peer_af_find(p, afi, safi);
10483 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 10484 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 10485 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10486 vty_out(vty, " Packet Queue length %d\n",
10487 bpacket_queue_virtual_length(paf));
10488 } else {
10489 vty_out(vty, " Not part of any update group\n");
10490 }
10491 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10492 || CHECK_FLAG(p->af_cap[afi][safi],
10493 PEER_CAP_ORF_PREFIX_SM_RCV)
10494 || CHECK_FLAG(p->af_cap[afi][safi],
10495 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10496 || CHECK_FLAG(p->af_cap[afi][safi],
10497 PEER_CAP_ORF_PREFIX_RM_ADV)
10498 || CHECK_FLAG(p->af_cap[afi][safi],
10499 PEER_CAP_ORF_PREFIX_RM_RCV)
10500 || CHECK_FLAG(p->af_cap[afi][safi],
10501 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10502 vty_out(vty, " AF-dependant capabilities:\n");
10503
10504 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10505 || CHECK_FLAG(p->af_cap[afi][safi],
10506 PEER_CAP_ORF_PREFIX_SM_RCV)
10507 || CHECK_FLAG(p->af_cap[afi][safi],
10508 PEER_CAP_ORF_PREFIX_RM_ADV)
10509 || CHECK_FLAG(p->af_cap[afi][safi],
10510 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10511 vty_out(vty,
10512 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10513 ORF_TYPE_PREFIX);
10514 bgp_show_peer_afi_orf_cap(
10515 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10516 PEER_CAP_ORF_PREFIX_RM_ADV,
10517 PEER_CAP_ORF_PREFIX_SM_RCV,
10518 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10519 }
10520 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10521 || CHECK_FLAG(p->af_cap[afi][safi],
10522 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10523 || CHECK_FLAG(p->af_cap[afi][safi],
10524 PEER_CAP_ORF_PREFIX_RM_ADV)
10525 || CHECK_FLAG(p->af_cap[afi][safi],
10526 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10527 vty_out(vty,
10528 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10529 ORF_TYPE_PREFIX_OLD);
10530 bgp_show_peer_afi_orf_cap(
10531 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10532 PEER_CAP_ORF_PREFIX_RM_ADV,
10533 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10534 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10535 }
10536
772270f3
QY
10537 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10538 p->host, afi, safi);
d62a17ae 10539 orf_pfx_count = prefix_bgp_show_prefix_list(
10540 NULL, afi, orf_pfx_name, use_json);
10541
10542 if (CHECK_FLAG(p->af_sflags[afi][safi],
10543 PEER_STATUS_ORF_PREFIX_SEND)
10544 || orf_pfx_count) {
10545 vty_out(vty, " Outbound Route Filter (ORF):");
10546 if (CHECK_FLAG(p->af_sflags[afi][safi],
10547 PEER_STATUS_ORF_PREFIX_SEND))
10548 vty_out(vty, " sent;");
10549 if (orf_pfx_count)
10550 vty_out(vty, " received (%d entries)",
10551 orf_pfx_count);
10552 vty_out(vty, "\n");
10553 }
10554 if (CHECK_FLAG(p->af_sflags[afi][safi],
10555 PEER_STATUS_ORF_WAIT_REFRESH))
10556 vty_out(vty,
10557 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10558
10559 if (CHECK_FLAG(p->af_flags[afi][safi],
10560 PEER_FLAG_REFLECTOR_CLIENT))
10561 vty_out(vty, " Route-Reflector Client\n");
10562 if (CHECK_FLAG(p->af_flags[afi][safi],
10563 PEER_FLAG_RSERVER_CLIENT))
10564 vty_out(vty, " Route-Server Client\n");
10565 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10566 vty_out(vty,
10567 " Inbound soft reconfiguration allowed\n");
10568
10569 if (CHECK_FLAG(p->af_flags[afi][safi],
10570 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10571 vty_out(vty,
10572 " Private AS numbers (all) replaced in updates to this neighbor\n");
10573 else if (CHECK_FLAG(p->af_flags[afi][safi],
10574 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10575 vty_out(vty,
10576 " Private AS numbers replaced in updates to this neighbor\n");
10577 else if (CHECK_FLAG(p->af_flags[afi][safi],
10578 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10579 vty_out(vty,
10580 " Private AS numbers (all) removed in updates to this neighbor\n");
10581 else if (CHECK_FLAG(p->af_flags[afi][safi],
10582 PEER_FLAG_REMOVE_PRIVATE_AS))
10583 vty_out(vty,
10584 " Private AS numbers removed in updates to this neighbor\n");
10585
dcc68b5e
MS
10586 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10587 vty_out(vty, " %s\n",
10588 bgp_addpath_names(p->addpath_type[afi][safi])
10589 ->human_description);
d62a17ae 10590
10591 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10592 vty_out(vty,
10593 " Override ASNs in outbound updates if aspath equals remote-as\n");
10594
10595 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10596 || CHECK_FLAG(p->af_flags[afi][safi],
10597 PEER_FLAG_FORCE_NEXTHOP_SELF))
10598 vty_out(vty, " NEXT_HOP is always this router\n");
10599 if (CHECK_FLAG(p->af_flags[afi][safi],
10600 PEER_FLAG_AS_PATH_UNCHANGED))
10601 vty_out(vty,
10602 " AS_PATH is propagated unchanged to this neighbor\n");
10603 if (CHECK_FLAG(p->af_flags[afi][safi],
10604 PEER_FLAG_NEXTHOP_UNCHANGED))
10605 vty_out(vty,
10606 " NEXT_HOP is propagated unchanged to this neighbor\n");
10607 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10608 vty_out(vty,
10609 " MED is propagated unchanged to this neighbor\n");
10610 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10611 || CHECK_FLAG(p->af_flags[afi][safi],
10612 PEER_FLAG_SEND_EXT_COMMUNITY)
10613 || CHECK_FLAG(p->af_flags[afi][safi],
10614 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10615 vty_out(vty,
10616 " Community attribute sent to this neighbor");
10617 if (CHECK_FLAG(p->af_flags[afi][safi],
10618 PEER_FLAG_SEND_COMMUNITY)
10619 && CHECK_FLAG(p->af_flags[afi][safi],
10620 PEER_FLAG_SEND_EXT_COMMUNITY)
10621 && CHECK_FLAG(p->af_flags[afi][safi],
10622 PEER_FLAG_SEND_LARGE_COMMUNITY))
10623 vty_out(vty, "(all)\n");
10624 else if (CHECK_FLAG(p->af_flags[afi][safi],
10625 PEER_FLAG_SEND_LARGE_COMMUNITY))
10626 vty_out(vty, "(large)\n");
10627 else if (CHECK_FLAG(p->af_flags[afi][safi],
10628 PEER_FLAG_SEND_EXT_COMMUNITY))
10629 vty_out(vty, "(extended)\n");
10630 else
10631 vty_out(vty, "(standard)\n");
10632 }
10633 if (CHECK_FLAG(p->af_flags[afi][safi],
10634 PEER_FLAG_DEFAULT_ORIGINATE)) {
10635 vty_out(vty, " Default information originate,");
10636
10637 if (p->default_rmap[afi][safi].name)
10638 vty_out(vty, " default route-map %s%s,",
10639 p->default_rmap[afi][safi].map ? "*"
10640 : "",
10641 p->default_rmap[afi][safi].name);
10642 if (paf && PAF_SUBGRP(paf)
10643 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10644 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10645 vty_out(vty, " default sent\n");
10646 else
10647 vty_out(vty, " default not sent\n");
10648 }
10649
dff8f48d
MK
10650 /* advertise-vni-all */
10651 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10652 if (is_evpn_enabled())
dff8f48d
MK
10653 vty_out(vty, " advertise-all-vni\n");
10654 }
10655
d62a17ae 10656 if (filter->plist[FILTER_IN].name
10657 || filter->dlist[FILTER_IN].name
10658 || filter->aslist[FILTER_IN].name
10659 || filter->map[RMAP_IN].name)
10660 vty_out(vty, " Inbound path policy configured\n");
10661 if (filter->plist[FILTER_OUT].name
10662 || filter->dlist[FILTER_OUT].name
10663 || filter->aslist[FILTER_OUT].name
10664 || filter->map[RMAP_OUT].name || filter->usmap.name)
10665 vty_out(vty, " Outbound path policy configured\n");
10666
10667 /* prefix-list */
10668 if (filter->plist[FILTER_IN].name)
10669 vty_out(vty,
10670 " Incoming update prefix filter list is %s%s\n",
10671 filter->plist[FILTER_IN].plist ? "*" : "",
10672 filter->plist[FILTER_IN].name);
10673 if (filter->plist[FILTER_OUT].name)
10674 vty_out(vty,
10675 " Outgoing update prefix filter list is %s%s\n",
10676 filter->plist[FILTER_OUT].plist ? "*" : "",
10677 filter->plist[FILTER_OUT].name);
10678
10679 /* distribute-list */
10680 if (filter->dlist[FILTER_IN].name)
10681 vty_out(vty,
10682 " Incoming update network filter list is %s%s\n",
10683 filter->dlist[FILTER_IN].alist ? "*" : "",
10684 filter->dlist[FILTER_IN].name);
10685 if (filter->dlist[FILTER_OUT].name)
10686 vty_out(vty,
10687 " Outgoing update network filter list is %s%s\n",
10688 filter->dlist[FILTER_OUT].alist ? "*" : "",
10689 filter->dlist[FILTER_OUT].name);
10690
10691 /* filter-list. */
10692 if (filter->aslist[FILTER_IN].name)
10693 vty_out(vty,
10694 " Incoming update AS path filter list is %s%s\n",
10695 filter->aslist[FILTER_IN].aslist ? "*" : "",
10696 filter->aslist[FILTER_IN].name);
10697 if (filter->aslist[FILTER_OUT].name)
10698 vty_out(vty,
10699 " Outgoing update AS path filter list is %s%s\n",
10700 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10701 filter->aslist[FILTER_OUT].name);
10702
10703 /* route-map. */
10704 if (filter->map[RMAP_IN].name)
10705 vty_out(vty,
10706 " Route map for incoming advertisements is %s%s\n",
10707 filter->map[RMAP_IN].map ? "*" : "",
10708 filter->map[RMAP_IN].name);
10709 if (filter->map[RMAP_OUT].name)
10710 vty_out(vty,
10711 " Route map for outgoing advertisements is %s%s\n",
10712 filter->map[RMAP_OUT].map ? "*" : "",
10713 filter->map[RMAP_OUT].name);
10714
9dac9fc8 10715 /* ebgp-requires-policy (inbound) */
1d3fdccf 10716 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10717 && !bgp_inbound_policy_exists(p, filter))
10718 vty_out(vty,
10719 " Inbound updates discarded due to missing policy\n");
10720
10721 /* ebgp-requires-policy (outbound) */
1d3fdccf 10722 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10723 && !bgp_outbound_policy_exists(p, filter))
10724 vty_out(vty,
10725 " Outbound updates discarded due to missing policy\n");
10726
d62a17ae 10727 /* unsuppress-map */
10728 if (filter->usmap.name)
10729 vty_out(vty,
10730 " Route map for selective unsuppress is %s%s\n",
10731 filter->usmap.map ? "*" : "",
10732 filter->usmap.name);
10733
10734 /* Receive prefix count */
6cde4b45 10735 vty_out(vty, " %u accepted prefixes\n",
a0a87037 10736 p->pcount[afi][safi]);
d62a17ae 10737
fde246e8
DA
10738 /* maximum-prefix-out */
10739 if (CHECK_FLAG(p->af_flags[afi][safi],
10740 PEER_FLAG_MAX_PREFIX_OUT))
10741 vty_out(vty,
6cde4b45 10742 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
10743 p->pmax_out[afi][safi]);
10744
d62a17ae 10745 /* Maximum prefix */
10746 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 10747 vty_out(vty,
6cde4b45 10748 " Maximum prefixes allowed %u%s\n",
d62a17ae 10749 p->pmax[afi][safi],
10750 CHECK_FLAG(p->af_flags[afi][safi],
10751 PEER_FLAG_MAX_PREFIX_WARNING)
10752 ? " (warning-only)"
10753 : "");
10754 vty_out(vty, " Threshold for warning message %d%%",
10755 p->pmax_threshold[afi][safi]);
10756 if (p->pmax_restart[afi][safi])
10757 vty_out(vty, ", restart interval %d min",
10758 p->pmax_restart[afi][safi]);
10759 vty_out(vty, "\n");
10760 }
10761
10762 vty_out(vty, "\n");
10763 }
10764}
10765
9f049418 10766static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 10767 json_object *json)
718e3744 10768{
d62a17ae 10769 struct bgp *bgp;
10770 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
10771 char timebuf[BGP_UPTIME_LEN];
10772 char dn_flag[2];
d62a17ae 10773 afi_t afi;
10774 safi_t safi;
d7c0a89a
QY
10775 uint16_t i;
10776 uint8_t *msg;
d62a17ae 10777 json_object *json_neigh = NULL;
10778 time_t epoch_tbuf;
718e3744 10779
d62a17ae 10780 bgp = p->bgp;
10781
10782 if (use_json)
10783 json_neigh = json_object_new_object();
10784
10785 memset(dn_flag, '\0', sizeof(dn_flag));
10786 if (!p->conf_if && peer_dynamic_neighbor(p))
10787 dn_flag[0] = '*';
10788
10789 if (!use_json) {
10790 if (p->conf_if) /* Configured interface name. */
10791 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
10792 BGP_PEER_SU_UNSPEC(p)
10793 ? "None"
10794 : sockunion2str(&p->su, buf,
10795 SU_ADDRSTRLEN));
10796 else /* Configured IP address. */
10797 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
10798 p->host);
10799 }
10800
10801 if (use_json) {
10802 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
10803 json_object_string_add(json_neigh, "bgpNeighborAddr",
10804 "none");
10805 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
10806 json_object_string_add(
10807 json_neigh, "bgpNeighborAddr",
10808 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
10809
10810 json_object_int_add(json_neigh, "remoteAs", p->as);
10811
10812 if (p->change_local_as)
10813 json_object_int_add(json_neigh, "localAs",
10814 p->change_local_as);
10815 else
10816 json_object_int_add(json_neigh, "localAs", p->local_as);
10817
10818 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
10819 json_object_boolean_true_add(json_neigh,
10820 "localAsNoPrepend");
10821
10822 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
10823 json_object_boolean_true_add(json_neigh,
10824 "localAsReplaceAs");
10825 } else {
10826 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
10827 || (p->as_type == AS_INTERNAL))
10828 vty_out(vty, "remote AS %u, ", p->as);
10829 else
10830 vty_out(vty, "remote AS Unspecified, ");
10831 vty_out(vty, "local AS %u%s%s, ",
10832 p->change_local_as ? p->change_local_as : p->local_as,
10833 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
10834 ? " no-prepend"
10835 : "",
10836 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
10837 ? " replace-as"
10838 : "");
10839 }
faa16034
DS
10840 /* peer type internal or confed-internal */
10841 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 10842 if (use_json) {
10843 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10844 json_object_boolean_true_add(
10845 json_neigh, "nbrConfedInternalLink");
10846 else
10847 json_object_boolean_true_add(json_neigh,
10848 "nbrInternalLink");
10849 } else {
10850 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10851 vty_out(vty, "confed-internal link\n");
10852 else
10853 vty_out(vty, "internal link\n");
10854 }
faa16034
DS
10855 /* peer type external or confed-external */
10856 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 10857 if (use_json) {
10858 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10859 json_object_boolean_true_add(
10860 json_neigh, "nbrConfedExternalLink");
10861 else
10862 json_object_boolean_true_add(json_neigh,
10863 "nbrExternalLink");
10864 } else {
10865 if (bgp_confederation_peers_check(bgp, p->as))
10866 vty_out(vty, "confed-external link\n");
10867 else
10868 vty_out(vty, "external link\n");
10869 }
faa16034
DS
10870 } else {
10871 if (use_json)
10872 json_object_boolean_true_add(json_neigh,
10873 "nbrUnspecifiedLink");
10874 else
10875 vty_out(vty, "unspecified link\n");
d62a17ae 10876 }
10877
10878 /* Description. */
10879 if (p->desc) {
10880 if (use_json)
10881 json_object_string_add(json_neigh, "nbrDesc", p->desc);
10882 else
10883 vty_out(vty, " Description: %s\n", p->desc);
10884 }
10885
10886 if (p->hostname) {
10887 if (use_json) {
10888 if (p->hostname)
10889 json_object_string_add(json_neigh, "hostname",
10890 p->hostname);
10891
10892 if (p->domainname)
10893 json_object_string_add(json_neigh, "domainname",
10894 p->domainname);
10895 } else {
10896 if (p->domainname && (p->domainname[0] != '\0'))
10897 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
10898 p->domainname);
10899 else
10900 vty_out(vty, "Hostname: %s\n", p->hostname);
10901 }
10902 }
10903
10904 /* Peer-group */
10905 if (p->group) {
10906 if (use_json) {
10907 json_object_string_add(json_neigh, "peerGroup",
10908 p->group->name);
10909
10910 if (dn_flag[0]) {
10911 struct prefix prefix, *range = NULL;
10912
10913 sockunion2hostprefix(&(p->su), &prefix);
10914 range = peer_group_lookup_dynamic_neighbor_range(
10915 p->group, &prefix);
10916
10917 if (range) {
10918 prefix2str(range, buf1, sizeof(buf1));
10919 json_object_string_add(
10920 json_neigh,
10921 "peerSubnetRangeGroup", buf1);
10922 }
10923 }
10924 } else {
10925 vty_out(vty,
10926 " Member of peer-group %s for session parameters\n",
10927 p->group->name);
10928
10929 if (dn_flag[0]) {
10930 struct prefix prefix, *range = NULL;
10931
10932 sockunion2hostprefix(&(p->su), &prefix);
10933 range = peer_group_lookup_dynamic_neighbor_range(
10934 p->group, &prefix);
10935
10936 if (range) {
d62a17ae 10937 vty_out(vty,
1b78780b
DL
10938 " Belongs to the subnet range group: %pFX\n",
10939 range);
d62a17ae 10940 }
10941 }
10942 }
10943 }
10944
10945 if (use_json) {
10946 /* Administrative shutdown. */
10947 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10948 json_object_boolean_true_add(json_neigh,
10949 "adminShutDown");
10950
10951 /* BGP Version. */
10952 json_object_int_add(json_neigh, "bgpVersion", 4);
10953 json_object_string_add(
10954 json_neigh, "remoteRouterId",
10955 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
10956 json_object_string_add(
10957 json_neigh, "localRouterId",
10958 inet_ntop(AF_INET, &bgp->router_id, buf1,
10959 sizeof(buf1)));
d62a17ae 10960
10961 /* Confederation */
10962 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10963 && bgp_confederation_peers_check(bgp, p->as))
10964 json_object_boolean_true_add(json_neigh,
10965 "nbrCommonAdmin");
10966
10967 /* Status. */
10968 json_object_string_add(
10969 json_neigh, "bgpState",
10970 lookup_msg(bgp_status_msg, p->status, NULL));
10971
10972 if (p->status == Established) {
10973 time_t uptime;
d62a17ae 10974
10975 uptime = bgp_clock();
10976 uptime -= p->uptime;
d62a17ae 10977 epoch_tbuf = time(NULL) - uptime;
10978
d3c7efed
DS
10979 json_object_int_add(json_neigh, "bgpTimerUpMsec",
10980 uptime * 1000);
d62a17ae 10981 json_object_string_add(json_neigh, "bgpTimerUpString",
10982 peer_uptime(p->uptime, timebuf,
10983 BGP_UPTIME_LEN, 0,
10984 NULL));
10985 json_object_int_add(json_neigh,
10986 "bgpTimerUpEstablishedEpoch",
10987 epoch_tbuf);
10988 }
10989
10990 else if (p->status == Active) {
10991 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10992 json_object_string_add(json_neigh, "bgpStateIs",
10993 "passive");
10994 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10995 json_object_string_add(json_neigh, "bgpStateIs",
10996 "passiveNSF");
10997 }
10998
10999 /* read timer */
11000 time_t uptime;
a2700b50 11001 struct tm tm;
d62a17ae 11002
11003 uptime = bgp_clock();
11004 uptime -= p->readtime;
a2700b50
MS
11005 gmtime_r(&uptime, &tm);
11006
d62a17ae 11007 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
11008 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11009 + (tm.tm_hour * 3600000));
d62a17ae 11010
11011 uptime = bgp_clock();
11012 uptime -= p->last_write;
a2700b50
MS
11013 gmtime_r(&uptime, &tm);
11014
d62a17ae 11015 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
11016 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11017 + (tm.tm_hour * 3600000));
d62a17ae 11018
11019 uptime = bgp_clock();
11020 uptime -= p->update_time;
a2700b50
MS
11021 gmtime_r(&uptime, &tm);
11022
d62a17ae 11023 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
11024 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11025 + (tm.tm_hour * 3600000));
d62a17ae 11026
11027 /* Configured timer values. */
11028 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
11029 p->v_holdtime * 1000);
11030 json_object_int_add(json_neigh,
11031 "bgpTimerKeepAliveIntervalMsecs",
11032 p->v_keepalive * 1000);
b90a8e13 11033 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11034 json_object_int_add(json_neigh,
11035 "bgpTimerConfiguredHoldTimeMsecs",
11036 p->holdtime * 1000);
11037 json_object_int_add(
11038 json_neigh,
11039 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11040 p->keepalive * 1000);
5d5393b9
DL
11041 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11042 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11043 json_object_int_add(json_neigh,
11044 "bgpTimerConfiguredHoldTimeMsecs",
11045 bgp->default_holdtime);
11046 json_object_int_add(
11047 json_neigh,
11048 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11049 bgp->default_keepalive);
d62a17ae 11050 }
11051 } else {
11052 /* Administrative shutdown. */
11053 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
11054 vty_out(vty, " Administratively shut down\n");
11055
11056 /* BGP Version. */
11057 vty_out(vty, " BGP version 4");
0e38aeb4 11058 vty_out(vty, ", remote router ID %s",
d62a17ae 11059 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
11060 vty_out(vty, ", local router ID %s\n",
11061 inet_ntop(AF_INET, &bgp->router_id, buf1,
11062 sizeof(buf1)));
d62a17ae 11063
11064 /* Confederation */
11065 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11066 && bgp_confederation_peers_check(bgp, p->as))
11067 vty_out(vty,
11068 " Neighbor under common administration\n");
11069
11070 /* Status. */
11071 vty_out(vty, " BGP state = %s",
11072 lookup_msg(bgp_status_msg, p->status, NULL));
11073
11074 if (p->status == Established)
11075 vty_out(vty, ", up for %8s",
11076 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
11077 0, NULL));
11078
11079 else if (p->status == Active) {
11080 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11081 vty_out(vty, " (passive)");
11082 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11083 vty_out(vty, " (NSF passive)");
11084 }
11085 vty_out(vty, "\n");
11086
11087 /* read timer */
11088 vty_out(vty, " Last read %s",
11089 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
11090 NULL));
11091 vty_out(vty, ", Last write %s\n",
11092 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
11093 NULL));
11094
11095 /* Configured timer values. */
11096 vty_out(vty,
11097 " Hold time is %d, keepalive interval is %d seconds\n",
11098 p->v_holdtime, p->v_keepalive);
b90a8e13 11099 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11100 vty_out(vty, " Configured hold time is %d",
11101 p->holdtime);
11102 vty_out(vty, ", keepalive interval is %d seconds\n",
11103 p->keepalive);
5d5393b9
DL
11104 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11105 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11106 vty_out(vty, " Configured hold time is %d",
11107 bgp->default_holdtime);
11108 vty_out(vty, ", keepalive interval is %d seconds\n",
11109 bgp->default_keepalive);
d62a17ae 11110 }
11111 }
11112 /* Capability. */
11113 if (p->status == Established) {
11114 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
11115 || p->afc_recv[AFI_IP][SAFI_UNICAST]
11116 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
11117 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
11118 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
11119 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
11120 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
11121 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
11122 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
11123 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
11124 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
11125 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 11126 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
11127 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 11128 || p->afc_adv[AFI_IP][SAFI_ENCAP]
11129 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 11130 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
11131 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 11132 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
11133 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
11134 if (use_json) {
11135 json_object *json_cap = NULL;
11136
11137 json_cap = json_object_new_object();
11138
11139 /* AS4 */
11140 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11141 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11142 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
11143 && CHECK_FLAG(p->cap,
11144 PEER_CAP_AS4_RCV))
11145 json_object_string_add(
11146 json_cap, "4byteAs",
11147 "advertisedAndReceived");
11148 else if (CHECK_FLAG(p->cap,
11149 PEER_CAP_AS4_ADV))
11150 json_object_string_add(
11151 json_cap, "4byteAs",
11152 "advertised");
11153 else if (CHECK_FLAG(p->cap,
11154 PEER_CAP_AS4_RCV))
11155 json_object_string_add(
11156 json_cap, "4byteAs",
11157 "received");
11158 }
11159
11160 /* AddPath */
11161 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11162 || CHECK_FLAG(p->cap,
11163 PEER_CAP_ADDPATH_ADV)) {
11164 json_object *json_add = NULL;
11165 const char *print_store;
11166
11167 json_add = json_object_new_object();
11168
05c7a1cc
QY
11169 FOREACH_AFI_SAFI (afi, safi) {
11170 json_object *json_sub = NULL;
11171 json_sub =
11172 json_object_new_object();
5cb5f4d0
DD
11173 print_store = get_afi_safi_str(
11174 afi, safi, true);
d62a17ae 11175
05c7a1cc
QY
11176 if (CHECK_FLAG(
11177 p->af_cap[afi]
11178 [safi],
11179 PEER_CAP_ADDPATH_AF_TX_ADV)
11180 || CHECK_FLAG(
11181 p->af_cap[afi]
11182 [safi],
11183 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 11184 if (CHECK_FLAG(
11185 p->af_cap
11186 [afi]
11187 [safi],
11188 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 11189 && CHECK_FLAG(
d62a17ae 11190 p->af_cap
11191 [afi]
11192 [safi],
05c7a1cc
QY
11193 PEER_CAP_ADDPATH_AF_TX_RCV))
11194 json_object_boolean_true_add(
11195 json_sub,
11196 "txAdvertisedAndReceived");
11197 else if (
11198 CHECK_FLAG(
11199 p->af_cap
11200 [afi]
11201 [safi],
11202 PEER_CAP_ADDPATH_AF_TX_ADV))
11203 json_object_boolean_true_add(
11204 json_sub,
11205 "txAdvertised");
11206 else if (
11207 CHECK_FLAG(
11208 p->af_cap
11209 [afi]
11210 [safi],
11211 PEER_CAP_ADDPATH_AF_TX_RCV))
11212 json_object_boolean_true_add(
11213 json_sub,
11214 "txReceived");
11215 }
d62a17ae 11216
05c7a1cc
QY
11217 if (CHECK_FLAG(
11218 p->af_cap[afi]
11219 [safi],
11220 PEER_CAP_ADDPATH_AF_RX_ADV)
11221 || CHECK_FLAG(
11222 p->af_cap[afi]
11223 [safi],
11224 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 11225 if (CHECK_FLAG(
11226 p->af_cap
11227 [afi]
11228 [safi],
11229 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 11230 && CHECK_FLAG(
d62a17ae 11231 p->af_cap
11232 [afi]
11233 [safi],
11234 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
11235 json_object_boolean_true_add(
11236 json_sub,
11237 "rxAdvertisedAndReceived");
11238 else if (
11239 CHECK_FLAG(
11240 p->af_cap
11241 [afi]
11242 [safi],
11243 PEER_CAP_ADDPATH_AF_RX_ADV))
11244 json_object_boolean_true_add(
11245 json_sub,
11246 "rxAdvertised");
11247 else if (
11248 CHECK_FLAG(
11249 p->af_cap
11250 [afi]
11251 [safi],
11252 PEER_CAP_ADDPATH_AF_RX_RCV))
11253 json_object_boolean_true_add(
11254 json_sub,
11255 "rxReceived");
d62a17ae 11256 }
11257
05c7a1cc
QY
11258 if (CHECK_FLAG(
11259 p->af_cap[afi]
11260 [safi],
11261 PEER_CAP_ADDPATH_AF_TX_ADV)
11262 || CHECK_FLAG(
11263 p->af_cap[afi]
11264 [safi],
11265 PEER_CAP_ADDPATH_AF_TX_RCV)
11266 || CHECK_FLAG(
11267 p->af_cap[afi]
11268 [safi],
11269 PEER_CAP_ADDPATH_AF_RX_ADV)
11270 || CHECK_FLAG(
11271 p->af_cap[afi]
11272 [safi],
11273 PEER_CAP_ADDPATH_AF_RX_RCV))
11274 json_object_object_add(
11275 json_add,
11276 print_store,
11277 json_sub);
11278 else
11279 json_object_free(
11280 json_sub);
11281 }
11282
d62a17ae 11283 json_object_object_add(
11284 json_cap, "addPath", json_add);
11285 }
11286
11287 /* Dynamic */
11288 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11289 || CHECK_FLAG(p->cap,
11290 PEER_CAP_DYNAMIC_ADV)) {
11291 if (CHECK_FLAG(p->cap,
11292 PEER_CAP_DYNAMIC_ADV)
11293 && CHECK_FLAG(p->cap,
11294 PEER_CAP_DYNAMIC_RCV))
11295 json_object_string_add(
11296 json_cap, "dynamic",
11297 "advertisedAndReceived");
11298 else if (CHECK_FLAG(
11299 p->cap,
11300 PEER_CAP_DYNAMIC_ADV))
11301 json_object_string_add(
11302 json_cap, "dynamic",
11303 "advertised");
11304 else if (CHECK_FLAG(
11305 p->cap,
11306 PEER_CAP_DYNAMIC_RCV))
11307 json_object_string_add(
11308 json_cap, "dynamic",
11309 "received");
11310 }
11311
11312 /* Extended nexthop */
11313 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11314 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11315 json_object *json_nxt = NULL;
11316 const char *print_store;
11317
11318
11319 if (CHECK_FLAG(p->cap,
11320 PEER_CAP_ENHE_ADV)
11321 && CHECK_FLAG(p->cap,
11322 PEER_CAP_ENHE_RCV))
11323 json_object_string_add(
11324 json_cap,
11325 "extendedNexthop",
11326 "advertisedAndReceived");
11327 else if (CHECK_FLAG(p->cap,
11328 PEER_CAP_ENHE_ADV))
11329 json_object_string_add(
11330 json_cap,
11331 "extendedNexthop",
11332 "advertised");
11333 else if (CHECK_FLAG(p->cap,
11334 PEER_CAP_ENHE_RCV))
11335 json_object_string_add(
11336 json_cap,
11337 "extendedNexthop",
11338 "received");
11339
11340 if (CHECK_FLAG(p->cap,
11341 PEER_CAP_ENHE_RCV)) {
11342 json_nxt =
11343 json_object_new_object();
11344
11345 for (safi = SAFI_UNICAST;
11346 safi < SAFI_MAX; safi++) {
11347 if (CHECK_FLAG(
11348 p->af_cap
11349 [AFI_IP]
11350 [safi],
11351 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 11352 print_store = get_afi_safi_str(
d62a17ae 11353 AFI_IP,
5cb5f4d0 11354 safi, true);
d62a17ae 11355 json_object_string_add(
11356 json_nxt,
11357 print_store,
54f29523 11358 "recieved"); /* misspelled for compatibility */
d62a17ae 11359 }
11360 }
11361 json_object_object_add(
11362 json_cap,
11363 "extendedNexthopFamililesByPeer",
11364 json_nxt);
11365 }
11366 }
11367
11368 /* Route Refresh */
11369 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11370 || CHECK_FLAG(p->cap,
11371 PEER_CAP_REFRESH_NEW_RCV)
11372 || CHECK_FLAG(p->cap,
11373 PEER_CAP_REFRESH_OLD_RCV)) {
11374 if (CHECK_FLAG(p->cap,
11375 PEER_CAP_REFRESH_ADV)
11376 && (CHECK_FLAG(
11377 p->cap,
11378 PEER_CAP_REFRESH_NEW_RCV)
11379 || CHECK_FLAG(
11380 p->cap,
11381 PEER_CAP_REFRESH_OLD_RCV))) {
11382 if (CHECK_FLAG(
11383 p->cap,
11384 PEER_CAP_REFRESH_OLD_RCV)
11385 && CHECK_FLAG(
11386 p->cap,
11387 PEER_CAP_REFRESH_NEW_RCV))
11388 json_object_string_add(
11389 json_cap,
11390 "routeRefresh",
11391 "advertisedAndReceivedOldNew");
11392 else {
11393 if (CHECK_FLAG(
11394 p->cap,
11395 PEER_CAP_REFRESH_OLD_RCV))
11396 json_object_string_add(
11397 json_cap,
11398 "routeRefresh",
11399 "advertisedAndReceivedOld");
11400 else
11401 json_object_string_add(
11402 json_cap,
11403 "routeRefresh",
11404 "advertisedAndReceivedNew");
11405 }
11406 } else if (
11407 CHECK_FLAG(
11408 p->cap,
11409 PEER_CAP_REFRESH_ADV))
11410 json_object_string_add(
11411 json_cap,
11412 "routeRefresh",
11413 "advertised");
11414 else if (
11415 CHECK_FLAG(
11416 p->cap,
11417 PEER_CAP_REFRESH_NEW_RCV)
11418 || CHECK_FLAG(
11419 p->cap,
11420 PEER_CAP_REFRESH_OLD_RCV))
11421 json_object_string_add(
11422 json_cap,
11423 "routeRefresh",
11424 "received");
11425 }
11426
11427 /* Multiprotocol Extensions */
11428 json_object *json_multi = NULL;
11429 json_multi = json_object_new_object();
11430
05c7a1cc
QY
11431 FOREACH_AFI_SAFI (afi, safi) {
11432 if (p->afc_adv[afi][safi]
11433 || p->afc_recv[afi][safi]) {
11434 json_object *json_exten = NULL;
11435 json_exten =
11436 json_object_new_object();
11437
d62a17ae 11438 if (p->afc_adv[afi][safi]
05c7a1cc
QY
11439 && p->afc_recv[afi][safi])
11440 json_object_boolean_true_add(
11441 json_exten,
11442 "advertisedAndReceived");
11443 else if (p->afc_adv[afi][safi])
11444 json_object_boolean_true_add(
11445 json_exten,
11446 "advertised");
11447 else if (p->afc_recv[afi][safi])
11448 json_object_boolean_true_add(
11449 json_exten,
11450 "received");
d62a17ae 11451
05c7a1cc
QY
11452 json_object_object_add(
11453 json_multi,
5cb5f4d0
DD
11454 get_afi_safi_str(afi,
11455 safi,
11456 true),
05c7a1cc 11457 json_exten);
d62a17ae 11458 }
11459 }
11460 json_object_object_add(
11461 json_cap, "multiprotocolExtensions",
11462 json_multi);
11463
d77114b7 11464 /* Hostname capabilities */
60466a63 11465 json_object *json_hname = NULL;
d77114b7
MK
11466
11467 json_hname = json_object_new_object();
11468
11469 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11470 json_object_string_add(
60466a63
QY
11471 json_hname, "advHostName",
11472 bgp->peer_self->hostname
11473 ? bgp->peer_self
11474 ->hostname
d77114b7
MK
11475 : "n/a");
11476 json_object_string_add(
60466a63
QY
11477 json_hname, "advDomainName",
11478 bgp->peer_self->domainname
11479 ? bgp->peer_self
11480 ->domainname
d77114b7
MK
11481 : "n/a");
11482 }
11483
11484
11485 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11486 json_object_string_add(
60466a63
QY
11487 json_hname, "rcvHostName",
11488 p->hostname ? p->hostname
11489 : "n/a");
d77114b7 11490 json_object_string_add(
60466a63
QY
11491 json_hname, "rcvDomainName",
11492 p->domainname ? p->domainname
11493 : "n/a");
d77114b7
MK
11494 }
11495
60466a63 11496 json_object_object_add(json_cap, "hostName",
d77114b7
MK
11497 json_hname);
11498
d62a17ae 11499 /* Gracefull Restart */
11500 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11501 || CHECK_FLAG(p->cap,
11502 PEER_CAP_RESTART_ADV)) {
11503 if (CHECK_FLAG(p->cap,
11504 PEER_CAP_RESTART_ADV)
11505 && CHECK_FLAG(p->cap,
11506 PEER_CAP_RESTART_RCV))
11507 json_object_string_add(
11508 json_cap,
11509 "gracefulRestart",
11510 "advertisedAndReceived");
11511 else if (CHECK_FLAG(
11512 p->cap,
11513 PEER_CAP_RESTART_ADV))
11514 json_object_string_add(
11515 json_cap,
11516 "gracefulRestartCapability",
11517 "advertised");
11518 else if (CHECK_FLAG(
11519 p->cap,
11520 PEER_CAP_RESTART_RCV))
11521 json_object_string_add(
11522 json_cap,
11523 "gracefulRestartCapability",
11524 "received");
11525
11526 if (CHECK_FLAG(p->cap,
11527 PEER_CAP_RESTART_RCV)) {
11528 int restart_af_count = 0;
11529 json_object *json_restart =
11530 NULL;
11531 json_restart =
11532 json_object_new_object();
11533
11534 json_object_int_add(
11535 json_cap,
11536 "gracefulRestartRemoteTimerMsecs",
11537 p->v_gr_restart * 1000);
11538
05c7a1cc
QY
11539 FOREACH_AFI_SAFI (afi, safi) {
11540 if (CHECK_FLAG(
11541 p->af_cap
11542 [afi]
11543 [safi],
11544 PEER_CAP_RESTART_AF_RCV)) {
11545 json_object *
11546 json_sub =
11547 NULL;
11548 json_sub =
11549 json_object_new_object();
11550
d62a17ae 11551 if (CHECK_FLAG(
11552 p->af_cap
11553 [afi]
11554 [safi],
05c7a1cc
QY
11555 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11556 json_object_boolean_true_add(
11557 json_sub,
11558 "preserved");
11559 restart_af_count++;
11560 json_object_object_add(
11561 json_restart,
5cb5f4d0 11562 get_afi_safi_str(
05c7a1cc 11563 afi,
5cb5f4d0
DD
11564 safi,
11565 true),
05c7a1cc 11566 json_sub);
d62a17ae 11567 }
11568 }
11569 if (!restart_af_count) {
11570 json_object_string_add(
11571 json_cap,
11572 "addressFamiliesByPeer",
11573 "none");
11574 json_object_free(
11575 json_restart);
11576 } else
11577 json_object_object_add(
11578 json_cap,
11579 "addressFamiliesByPeer",
11580 json_restart);
11581 }
11582 }
11583 json_object_object_add(json_neigh,
11584 "neighborCapabilities",
11585 json_cap);
11586 } else {
11587 vty_out(vty, " Neighbor capabilities:\n");
11588
11589 /* AS4 */
11590 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11591 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11592 vty_out(vty, " 4 Byte AS:");
11593 if (CHECK_FLAG(p->cap,
11594 PEER_CAP_AS4_ADV))
11595 vty_out(vty, " advertised");
11596 if (CHECK_FLAG(p->cap,
11597 PEER_CAP_AS4_RCV))
11598 vty_out(vty, " %sreceived",
11599 CHECK_FLAG(
11600 p->cap,
11601 PEER_CAP_AS4_ADV)
11602 ? "and "
11603 : "");
11604 vty_out(vty, "\n");
11605 }
11606
11607 /* AddPath */
11608 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11609 || CHECK_FLAG(p->cap,
11610 PEER_CAP_ADDPATH_ADV)) {
11611 vty_out(vty, " AddPath:\n");
11612
05c7a1cc
QY
11613 FOREACH_AFI_SAFI (afi, safi) {
11614 if (CHECK_FLAG(
11615 p->af_cap[afi]
11616 [safi],
11617 PEER_CAP_ADDPATH_AF_TX_ADV)
11618 || CHECK_FLAG(
11619 p->af_cap[afi]
11620 [safi],
11621 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11622 vty_out(vty,
11623 " %s: TX ",
5cb5f4d0 11624 get_afi_safi_str(
05c7a1cc 11625 afi,
5cb5f4d0
DD
11626 safi,
11627 false));
05c7a1cc 11628
d62a17ae 11629 if (CHECK_FLAG(
11630 p->af_cap
11631 [afi]
11632 [safi],
05c7a1cc 11633 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 11634 vty_out(vty,
05c7a1cc 11635 "advertised %s",
5cb5f4d0 11636 get_afi_safi_str(
d62a17ae 11637 afi,
5cb5f4d0
DD
11638 safi,
11639 false));
d62a17ae 11640
05c7a1cc
QY
11641 if (CHECK_FLAG(
11642 p->af_cap
11643 [afi]
11644 [safi],
11645 PEER_CAP_ADDPATH_AF_TX_RCV))
11646 vty_out(vty,
11647 "%sreceived",
11648 CHECK_FLAG(
11649 p->af_cap
11650 [afi]
11651 [safi],
11652 PEER_CAP_ADDPATH_AF_TX_ADV)
11653 ? " and "
11654 : "");
d62a17ae 11655
05c7a1cc
QY
11656 vty_out(vty, "\n");
11657 }
d62a17ae 11658
05c7a1cc
QY
11659 if (CHECK_FLAG(
11660 p->af_cap[afi]
11661 [safi],
11662 PEER_CAP_ADDPATH_AF_RX_ADV)
11663 || CHECK_FLAG(
11664 p->af_cap[afi]
11665 [safi],
11666 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11667 vty_out(vty,
11668 " %s: RX ",
5cb5f4d0 11669 get_afi_safi_str(
05c7a1cc 11670 afi,
5cb5f4d0
DD
11671 safi,
11672 false));
d62a17ae 11673
11674 if (CHECK_FLAG(
11675 p->af_cap
11676 [afi]
11677 [safi],
05c7a1cc 11678 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 11679 vty_out(vty,
05c7a1cc 11680 "advertised %s",
5cb5f4d0 11681 get_afi_safi_str(
d62a17ae 11682 afi,
5cb5f4d0
DD
11683 safi,
11684 false));
d62a17ae 11685
05c7a1cc
QY
11686 if (CHECK_FLAG(
11687 p->af_cap
11688 [afi]
11689 [safi],
11690 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 11691 vty_out(vty,
05c7a1cc
QY
11692 "%sreceived",
11693 CHECK_FLAG(
11694 p->af_cap
11695 [afi]
11696 [safi],
11697 PEER_CAP_ADDPATH_AF_RX_ADV)
11698 ? " and "
11699 : "");
11700
11701 vty_out(vty, "\n");
d62a17ae 11702 }
05c7a1cc 11703 }
d62a17ae 11704 }
11705
11706 /* Dynamic */
11707 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11708 || CHECK_FLAG(p->cap,
11709 PEER_CAP_DYNAMIC_ADV)) {
11710 vty_out(vty, " Dynamic:");
11711 if (CHECK_FLAG(p->cap,
11712 PEER_CAP_DYNAMIC_ADV))
11713 vty_out(vty, " advertised");
11714 if (CHECK_FLAG(p->cap,
11715 PEER_CAP_DYNAMIC_RCV))
11716 vty_out(vty, " %sreceived",
11717 CHECK_FLAG(
11718 p->cap,
11719 PEER_CAP_DYNAMIC_ADV)
11720 ? "and "
11721 : "");
11722 vty_out(vty, "\n");
11723 }
11724
11725 /* Extended nexthop */
11726 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11727 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11728 vty_out(vty, " Extended nexthop:");
11729 if (CHECK_FLAG(p->cap,
11730 PEER_CAP_ENHE_ADV))
11731 vty_out(vty, " advertised");
11732 if (CHECK_FLAG(p->cap,
11733 PEER_CAP_ENHE_RCV))
11734 vty_out(vty, " %sreceived",
11735 CHECK_FLAG(
11736 p->cap,
11737 PEER_CAP_ENHE_ADV)
11738 ? "and "
11739 : "");
11740 vty_out(vty, "\n");
11741
11742 if (CHECK_FLAG(p->cap,
11743 PEER_CAP_ENHE_RCV)) {
11744 vty_out(vty,
11745 " Address families by peer:\n ");
11746 for (safi = SAFI_UNICAST;
11747 safi < SAFI_MAX; safi++)
11748 if (CHECK_FLAG(
11749 p->af_cap
11750 [AFI_IP]
11751 [safi],
11752 PEER_CAP_ENHE_AF_RCV))
11753 vty_out(vty,
11754 " %s\n",
5cb5f4d0 11755 get_afi_safi_str(
d62a17ae 11756 AFI_IP,
5cb5f4d0
DD
11757 safi,
11758 false));
d62a17ae 11759 }
11760 }
11761
11762 /* Route Refresh */
11763 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11764 || CHECK_FLAG(p->cap,
11765 PEER_CAP_REFRESH_NEW_RCV)
11766 || CHECK_FLAG(p->cap,
11767 PEER_CAP_REFRESH_OLD_RCV)) {
11768 vty_out(vty, " Route refresh:");
11769 if (CHECK_FLAG(p->cap,
11770 PEER_CAP_REFRESH_ADV))
11771 vty_out(vty, " advertised");
11772 if (CHECK_FLAG(p->cap,
11773 PEER_CAP_REFRESH_NEW_RCV)
11774 || CHECK_FLAG(
11775 p->cap,
11776 PEER_CAP_REFRESH_OLD_RCV))
11777 vty_out(vty, " %sreceived(%s)",
11778 CHECK_FLAG(
11779 p->cap,
11780 PEER_CAP_REFRESH_ADV)
11781 ? "and "
11782 : "",
11783 (CHECK_FLAG(
11784 p->cap,
11785 PEER_CAP_REFRESH_OLD_RCV)
11786 && CHECK_FLAG(
11787 p->cap,
11788 PEER_CAP_REFRESH_NEW_RCV))
11789 ? "old & new"
11790 : CHECK_FLAG(
11791 p->cap,
11792 PEER_CAP_REFRESH_OLD_RCV)
11793 ? "old"
11794 : "new");
11795
11796 vty_out(vty, "\n");
11797 }
11798
11799 /* Multiprotocol Extensions */
05c7a1cc
QY
11800 FOREACH_AFI_SAFI (afi, safi)
11801 if (p->afc_adv[afi][safi]
11802 || p->afc_recv[afi][safi]) {
11803 vty_out(vty,
11804 " Address Family %s:",
5cb5f4d0
DD
11805 get_afi_safi_str(
11806 afi,
11807 safi,
11808 false));
05c7a1cc 11809 if (p->afc_adv[afi][safi])
d62a17ae 11810 vty_out(vty,
05c7a1cc
QY
11811 " advertised");
11812 if (p->afc_recv[afi][safi])
11813 vty_out(vty,
11814 " %sreceived",
11815 p->afc_adv[afi]
11816 [safi]
11817 ? "and "
11818 : "");
11819 vty_out(vty, "\n");
11820 }
d62a17ae 11821
11822 /* Hostname capability */
60466a63 11823 vty_out(vty, " Hostname Capability:");
d77114b7
MK
11824
11825 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
11826 vty_out(vty,
11827 " advertised (name: %s,domain name: %s)",
60466a63
QY
11828 bgp->peer_self->hostname
11829 ? bgp->peer_self
11830 ->hostname
d77114b7 11831 : "n/a",
60466a63
QY
11832 bgp->peer_self->domainname
11833 ? bgp->peer_self
11834 ->domainname
d77114b7
MK
11835 : "n/a");
11836 } else {
11837 vty_out(vty, " not advertised");
d62a17ae 11838 }
11839
d77114b7 11840 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
11841 vty_out(vty,
11842 " received (name: %s,domain name: %s)",
60466a63
QY
11843 p->hostname ? p->hostname
11844 : "n/a",
11845 p->domainname ? p->domainname
11846 : "n/a");
d77114b7
MK
11847 } else {
11848 vty_out(vty, " not received");
11849 }
11850
11851 vty_out(vty, "\n");
11852
61bfbd51 11853 /* Graceful Restart */
d62a17ae 11854 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11855 || CHECK_FLAG(p->cap,
11856 PEER_CAP_RESTART_ADV)) {
11857 vty_out(vty,
61bfbd51 11858 " Graceful Restart Capability:");
d62a17ae 11859 if (CHECK_FLAG(p->cap,
11860 PEER_CAP_RESTART_ADV))
11861 vty_out(vty, " advertised");
11862 if (CHECK_FLAG(p->cap,
11863 PEER_CAP_RESTART_RCV))
11864 vty_out(vty, " %sreceived",
11865 CHECK_FLAG(
11866 p->cap,
11867 PEER_CAP_RESTART_ADV)
11868 ? "and "
11869 : "");
11870 vty_out(vty, "\n");
11871
11872 if (CHECK_FLAG(p->cap,
11873 PEER_CAP_RESTART_RCV)) {
11874 int restart_af_count = 0;
11875
11876 vty_out(vty,
11877 " Remote Restart timer is %d seconds\n",
11878 p->v_gr_restart);
11879 vty_out(vty,
11880 " Address families by peer:\n ");
11881
05c7a1cc
QY
11882 FOREACH_AFI_SAFI (afi, safi)
11883 if (CHECK_FLAG(
11884 p->af_cap
11885 [afi]
11886 [safi],
11887 PEER_CAP_RESTART_AF_RCV)) {
11888 vty_out(vty,
11889 "%s%s(%s)",
11890 restart_af_count
11891 ? ", "
11892 : "",
5cb5f4d0 11893 get_afi_safi_str(
05c7a1cc 11894 afi,
5cb5f4d0
DD
11895 safi,
11896 false),
05c7a1cc
QY
11897 CHECK_FLAG(
11898 p->af_cap
11899 [afi]
11900 [safi],
11901 PEER_CAP_RESTART_AF_PRESERVE_RCV)
11902 ? "preserved"
11903 : "not preserved");
11904 restart_af_count++;
11905 }
d62a17ae 11906 if (!restart_af_count)
11907 vty_out(vty, "none");
11908 vty_out(vty, "\n");
11909 }
2986cac2 11910 } /* Gracefull Restart */
d62a17ae 11911 }
11912 }
11913 }
11914
11915 /* graceful restart information */
d62a17ae 11916 json_object *json_grace = NULL;
11917 json_object *json_grace_send = NULL;
11918 json_object *json_grace_recv = NULL;
11919 int eor_send_af_count = 0;
11920 int eor_receive_af_count = 0;
11921
11922 if (use_json) {
11923 json_grace = json_object_new_object();
11924 json_grace_send = json_object_new_object();
11925 json_grace_recv = json_object_new_object();
11926
36235319
QY
11927 if ((p->status == Established)
11928 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
11929 FOREACH_AFI_SAFI (afi, safi) {
11930 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 11931 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
11932 json_object_boolean_true_add(
11933 json_grace_send,
5cb5f4d0
DD
11934 get_afi_safi_str(afi,
11935 safi,
11936 true));
05c7a1cc 11937 eor_send_af_count++;
d62a17ae 11938 }
11939 }
05c7a1cc
QY
11940 FOREACH_AFI_SAFI (afi, safi) {
11941 if (CHECK_FLAG(
36235319
QY
11942 p->af_sflags[afi][safi],
11943 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
11944 json_object_boolean_true_add(
11945 json_grace_recv,
5cb5f4d0
DD
11946 get_afi_safi_str(afi,
11947 safi,
11948 true));
05c7a1cc 11949 eor_receive_af_count++;
d62a17ae 11950 }
11951 }
11952 }
36235319
QY
11953 json_object_object_add(json_grace, "endOfRibSend",
11954 json_grace_send);
11955 json_object_object_add(json_grace, "endOfRibRecv",
11956 json_grace_recv);
d62a17ae 11957
d62a17ae 11958
11959 if (p->t_gr_restart)
11960 json_object_int_add(json_grace,
11961 "gracefulRestartTimerMsecs",
11962 thread_timer_remain_second(
11963 p->t_gr_restart)
11964 * 1000);
11965
11966 if (p->t_gr_stale)
11967 json_object_int_add(
11968 json_grace,
11969 "gracefulStalepathTimerMsecs",
11970 thread_timer_remain_second(
11971 p->t_gr_stale)
11972 * 1000);
2986cac2 11973 /* more gr info in new format */
11974 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 11975 json_grace);
d62a17ae 11976 json_object_object_add(
11977 json_neigh, "gracefulRestartInfo", json_grace);
11978 } else {
2089dd80 11979 vty_out(vty, " Graceful restart information:\n");
36235319
QY
11980 if ((p->status == Established)
11981 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11982
d62a17ae 11983 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
11984 FOREACH_AFI_SAFI (afi, safi) {
11985 if (CHECK_FLAG(p->af_sflags[afi][safi],
11986 PEER_STATUS_EOR_SEND)) {
11987 vty_out(vty, "%s%s",
11988 eor_send_af_count ? ", "
11989 : "",
36235319
QY
11990 get_afi_safi_str(
11991 afi, safi,
11992 false));
05c7a1cc 11993 eor_send_af_count++;
d62a17ae 11994 }
11995 }
11996 vty_out(vty, "\n");
11997 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
11998 FOREACH_AFI_SAFI (afi, safi) {
11999 if (CHECK_FLAG(
12000 p->af_sflags[afi][safi],
12001 PEER_STATUS_EOR_RECEIVED)) {
12002 vty_out(vty, "%s%s",
12003 eor_receive_af_count
12004 ? ", "
12005 : "",
5cb5f4d0
DD
12006 get_afi_safi_str(afi,
12007 safi,
12008 false));
05c7a1cc 12009 eor_receive_af_count++;
d62a17ae 12010 }
12011 }
12012 vty_out(vty, "\n");
12013 }
12014
12015 if (p->t_gr_restart)
12016 vty_out(vty,
12017 " The remaining time of restart timer is %ld\n",
12018 thread_timer_remain_second(
12019 p->t_gr_restart));
12020
12021 if (p->t_gr_stale)
12022 vty_out(vty,
12023 " The remaining time of stalepath timer is %ld\n",
12024 thread_timer_remain_second(
12025 p->t_gr_stale));
2986cac2 12026
12027 /* more gr info in new format */
12028 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 12029 }
2986cac2 12030
d62a17ae 12031 if (use_json) {
12032 json_object *json_stat = NULL;
12033 json_stat = json_object_new_object();
12034 /* Packet counts. */
43aa5965
QY
12035
12036 atomic_size_t outq_count, inq_count;
12037 outq_count = atomic_load_explicit(&p->obuf->count,
12038 memory_order_relaxed);
12039 inq_count = atomic_load_explicit(&p->ibuf->count,
12040 memory_order_relaxed);
12041
12042 json_object_int_add(json_stat, "depthInq",
12043 (unsigned long)inq_count);
d62a17ae 12044 json_object_int_add(json_stat, "depthOutq",
43aa5965 12045 (unsigned long)outq_count);
0112e9e0
QY
12046 json_object_int_add(json_stat, "opensSent",
12047 atomic_load_explicit(&p->open_out,
12048 memory_order_relaxed));
12049 json_object_int_add(json_stat, "opensRecv",
12050 atomic_load_explicit(&p->open_in,
12051 memory_order_relaxed));
d62a17ae 12052 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
12053 atomic_load_explicit(&p->notify_out,
12054 memory_order_relaxed));
d62a17ae 12055 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
12056 atomic_load_explicit(&p->notify_in,
12057 memory_order_relaxed));
12058 json_object_int_add(json_stat, "updatesSent",
12059 atomic_load_explicit(&p->update_out,
12060 memory_order_relaxed));
12061 json_object_int_add(json_stat, "updatesRecv",
12062 atomic_load_explicit(&p->update_in,
12063 memory_order_relaxed));
d62a17ae 12064 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
12065 atomic_load_explicit(&p->keepalive_out,
12066 memory_order_relaxed));
d62a17ae 12067 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
12068 atomic_load_explicit(&p->keepalive_in,
12069 memory_order_relaxed));
d62a17ae 12070 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
12071 atomic_load_explicit(&p->refresh_out,
12072 memory_order_relaxed));
d62a17ae 12073 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
12074 atomic_load_explicit(&p->refresh_in,
12075 memory_order_relaxed));
d62a17ae 12076 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
12077 atomic_load_explicit(&p->dynamic_cap_out,
12078 memory_order_relaxed));
d62a17ae 12079 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
12080 atomic_load_explicit(&p->dynamic_cap_in,
12081 memory_order_relaxed));
12082 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
12083 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 12084 json_object_object_add(json_neigh, "messageStats", json_stat);
12085 } else {
43aa5965
QY
12086 atomic_size_t outq_count, inq_count;
12087 outq_count = atomic_load_explicit(&p->obuf->count,
12088 memory_order_relaxed);
12089 inq_count = atomic_load_explicit(&p->ibuf->count,
12090 memory_order_relaxed);
12091
d62a17ae 12092 /* Packet counts. */
12093 vty_out(vty, " Message statistics:\n");
43aa5965
QY
12094 vty_out(vty, " Inq depth is %zu\n", inq_count);
12095 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 12096 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
12097 vty_out(vty, " Opens: %10d %10d\n",
12098 atomic_load_explicit(&p->open_out,
12099 memory_order_relaxed),
12100 atomic_load_explicit(&p->open_in,
12101 memory_order_relaxed));
12102 vty_out(vty, " Notifications: %10d %10d\n",
12103 atomic_load_explicit(&p->notify_out,
12104 memory_order_relaxed),
12105 atomic_load_explicit(&p->notify_in,
12106 memory_order_relaxed));
12107 vty_out(vty, " Updates: %10d %10d\n",
12108 atomic_load_explicit(&p->update_out,
12109 memory_order_relaxed),
12110 atomic_load_explicit(&p->update_in,
12111 memory_order_relaxed));
12112 vty_out(vty, " Keepalives: %10d %10d\n",
12113 atomic_load_explicit(&p->keepalive_out,
12114 memory_order_relaxed),
12115 atomic_load_explicit(&p->keepalive_in,
12116 memory_order_relaxed));
12117 vty_out(vty, " Route Refresh: %10d %10d\n",
12118 atomic_load_explicit(&p->refresh_out,
12119 memory_order_relaxed),
12120 atomic_load_explicit(&p->refresh_in,
12121 memory_order_relaxed));
d62a17ae 12122 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
12123 atomic_load_explicit(&p->dynamic_cap_out,
12124 memory_order_relaxed),
12125 atomic_load_explicit(&p->dynamic_cap_in,
12126 memory_order_relaxed));
12127 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
12128 PEER_TOTAL_RX(p));
d62a17ae 12129 }
12130
12131 if (use_json) {
12132 /* advertisement-interval */
12133 json_object_int_add(json_neigh,
12134 "minBtwnAdvertisementRunsTimerMsecs",
12135 p->v_routeadv * 1000);
12136
12137 /* Update-source. */
12138 if (p->update_if || p->update_source) {
12139 if (p->update_if)
12140 json_object_string_add(json_neigh,
12141 "updateSource",
12142 p->update_if);
12143 else if (p->update_source)
12144 json_object_string_add(
12145 json_neigh, "updateSource",
12146 sockunion2str(p->update_source, buf1,
12147 SU_ADDRSTRLEN));
12148 }
12149 } else {
12150 /* advertisement-interval */
12151 vty_out(vty,
12152 " Minimum time between advertisement runs is %d seconds\n",
12153 p->v_routeadv);
12154
12155 /* Update-source. */
12156 if (p->update_if || p->update_source) {
12157 vty_out(vty, " Update source is ");
12158 if (p->update_if)
12159 vty_out(vty, "%s", p->update_if);
12160 else if (p->update_source)
12161 vty_out(vty, "%s",
12162 sockunion2str(p->update_source, buf1,
12163 SU_ADDRSTRLEN));
12164 vty_out(vty, "\n");
12165 }
12166
12167 vty_out(vty, "\n");
12168 }
12169
12170 /* Address Family Information */
12171 json_object *json_hold = NULL;
12172
12173 if (use_json)
12174 json_hold = json_object_new_object();
12175
05c7a1cc
QY
12176 FOREACH_AFI_SAFI (afi, safi)
12177 if (p->afc[afi][safi])
12178 bgp_show_peer_afi(vty, p, afi, safi, use_json,
12179 json_hold);
d62a17ae 12180
12181 if (use_json) {
12182 json_object_object_add(json_neigh, "addressFamilyInfo",
12183 json_hold);
12184 json_object_int_add(json_neigh, "connectionsEstablished",
12185 p->established);
12186 json_object_int_add(json_neigh, "connectionsDropped",
12187 p->dropped);
12188 } else
12189 vty_out(vty, " Connections established %d; dropped %d\n",
12190 p->established, p->dropped);
12191
12192 if (!p->last_reset) {
12193 if (use_json)
12194 json_object_string_add(json_neigh, "lastReset",
12195 "never");
12196 else
12197 vty_out(vty, " Last reset never\n");
12198 } else {
12199 if (use_json) {
12200 time_t uptime;
a2700b50 12201 struct tm tm;
d62a17ae 12202
12203 uptime = bgp_clock();
12204 uptime -= p->resettime;
a2700b50
MS
12205 gmtime_r(&uptime, &tm);
12206
d62a17ae 12207 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
12208 (tm.tm_sec * 1000)
12209 + (tm.tm_min * 60000)
12210 + (tm.tm_hour * 3600000));
3577f1c5 12211 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 12212 } else {
12213 vty_out(vty, " Last reset %s, ",
12214 peer_uptime(p->resettime, timebuf,
12215 BGP_UPTIME_LEN, 0, NULL));
12216
3577f1c5 12217 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 12218 if (p->last_reset_cause_size) {
12219 msg = p->last_reset_cause;
12220 vty_out(vty,
12221 " Message received that caused BGP to send a NOTIFICATION:\n ");
12222 for (i = 1; i <= p->last_reset_cause_size;
12223 i++) {
12224 vty_out(vty, "%02X", *msg++);
12225
12226 if (i != p->last_reset_cause_size) {
12227 if (i % 16 == 0) {
12228 vty_out(vty, "\n ");
12229 } else if (i % 4 == 0) {
12230 vty_out(vty, " ");
12231 }
12232 }
12233 }
12234 vty_out(vty, "\n");
12235 }
12236 }
12237 }
12238
12239 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
12240 if (use_json)
12241 json_object_boolean_true_add(json_neigh,
12242 "prefixesConfigExceedMax");
12243 else
12244 vty_out(vty,
12245 " Peer had exceeded the max. no. of prefixes configured.\n");
12246
12247 if (p->t_pmax_restart) {
12248 if (use_json) {
12249 json_object_boolean_true_add(
12250 json_neigh, "reducePrefixNumFrom");
12251 json_object_int_add(json_neigh,
12252 "restartInTimerMsec",
12253 thread_timer_remain_second(
12254 p->t_pmax_restart)
12255 * 1000);
12256 } else
12257 vty_out(vty,
12258 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
12259 p->host, thread_timer_remain_second(
12260 p->t_pmax_restart));
d62a17ae 12261 } else {
12262 if (use_json)
12263 json_object_boolean_true_add(
12264 json_neigh,
12265 "reducePrefixNumAndClearIpBgp");
12266 else
12267 vty_out(vty,
12268 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
12269 p->host);
12270 }
12271 }
12272
12273 /* EBGP Multihop and GTSM */
12274 if (p->sort != BGP_PEER_IBGP) {
12275 if (use_json) {
e2521429 12276 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12277 json_object_int_add(json_neigh,
12278 "externalBgpNbrMaxHopsAway",
12279 p->gtsm_hops);
c8d6f0d6 12280 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12281 json_object_int_add(json_neigh,
12282 "externalBgpNbrMaxHopsAway",
12283 p->ttl);
12284 } else {
e2521429 12285 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12286 vty_out(vty,
12287 " External BGP neighbor may be up to %d hops away.\n",
12288 p->gtsm_hops);
c8d6f0d6 12289 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12290 vty_out(vty,
12291 " External BGP neighbor may be up to %d hops away.\n",
12292 p->ttl);
12293 }
12294 } else {
e2521429 12295 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 12296 if (use_json)
12297 json_object_int_add(json_neigh,
12298 "internalBgpNbrMaxHopsAway",
12299 p->gtsm_hops);
12300 else
12301 vty_out(vty,
12302 " Internal BGP neighbor may be up to %d hops away.\n",
12303 p->gtsm_hops);
12304 }
12305 }
12306
12307 /* Local address. */
12308 if (p->su_local) {
12309 if (use_json) {
12310 json_object_string_add(json_neigh, "hostLocal",
12311 sockunion2str(p->su_local, buf1,
12312 SU_ADDRSTRLEN));
12313 json_object_int_add(json_neigh, "portLocal",
12314 ntohs(p->su_local->sin.sin_port));
12315 } else
12316 vty_out(vty, "Local host: %s, Local port: %d\n",
12317 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
12318 ntohs(p->su_local->sin.sin_port));
12319 }
12320
12321 /* Remote address. */
12322 if (p->su_remote) {
12323 if (use_json) {
12324 json_object_string_add(json_neigh, "hostForeign",
12325 sockunion2str(p->su_remote, buf1,
12326 SU_ADDRSTRLEN));
12327 json_object_int_add(json_neigh, "portForeign",
12328 ntohs(p->su_remote->sin.sin_port));
12329 } else
12330 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12331 sockunion2str(p->su_remote, buf1,
12332 SU_ADDRSTRLEN),
12333 ntohs(p->su_remote->sin.sin_port));
12334 }
12335
12336 /* Nexthop display. */
12337 if (p->su_local) {
12338 if (use_json) {
12339 json_object_string_add(json_neigh, "nexthop",
12340 inet_ntop(AF_INET,
12341 &p->nexthop.v4, buf1,
12342 sizeof(buf1)));
12343 json_object_string_add(json_neigh, "nexthopGlobal",
12344 inet_ntop(AF_INET6,
12345 &p->nexthop.v6_global,
12346 buf1, sizeof(buf1)));
12347 json_object_string_add(json_neigh, "nexthopLocal",
12348 inet_ntop(AF_INET6,
12349 &p->nexthop.v6_local,
12350 buf1, sizeof(buf1)));
12351 if (p->shared_network)
12352 json_object_string_add(json_neigh,
12353 "bgpConnection",
12354 "sharedNetwork");
12355 else
12356 json_object_string_add(json_neigh,
12357 "bgpConnection",
12358 "nonSharedNetwork");
12359 } else {
12360 vty_out(vty, "Nexthop: %s\n",
12361 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12362 sizeof(buf1)));
12363 vty_out(vty, "Nexthop global: %s\n",
12364 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12365 sizeof(buf1)));
12366 vty_out(vty, "Nexthop local: %s\n",
12367 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12368 sizeof(buf1)));
12369 vty_out(vty, "BGP connection: %s\n",
12370 p->shared_network ? "shared network"
12371 : "non shared network");
12372 }
12373 }
12374
12375 /* Timer information. */
12376 if (use_json) {
12377 json_object_int_add(json_neigh, "connectRetryTimer",
12378 p->v_connect);
12379 if (p->status == Established && p->rtt)
12380 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12381 p->rtt);
12382 if (p->t_start)
12383 json_object_int_add(
12384 json_neigh, "nextStartTimerDueInMsecs",
12385 thread_timer_remain_second(p->t_start) * 1000);
12386 if (p->t_connect)
12387 json_object_int_add(
12388 json_neigh, "nextConnectTimerDueInMsecs",
12389 thread_timer_remain_second(p->t_connect)
12390 * 1000);
12391 if (p->t_routeadv) {
12392 json_object_int_add(json_neigh, "mraiInterval",
12393 p->v_routeadv);
12394 json_object_int_add(
12395 json_neigh, "mraiTimerExpireInMsecs",
12396 thread_timer_remain_second(p->t_routeadv)
12397 * 1000);
12398 }
12399 if (p->password)
12400 json_object_int_add(json_neigh, "authenticationEnabled",
12401 1);
12402
12403 if (p->t_read)
12404 json_object_string_add(json_neigh, "readThread", "on");
12405 else
12406 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
12407
12408 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 12409 json_object_string_add(json_neigh, "writeThread", "on");
12410 else
12411 json_object_string_add(json_neigh, "writeThread",
12412 "off");
12413 } else {
12414 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12415 p->v_connect);
12416 if (p->status == Established && p->rtt)
12417 vty_out(vty, "Estimated round trip time: %d ms\n",
12418 p->rtt);
12419 if (p->t_start)
12420 vty_out(vty, "Next start timer due in %ld seconds\n",
12421 thread_timer_remain_second(p->t_start));
12422 if (p->t_connect)
12423 vty_out(vty, "Next connect timer due in %ld seconds\n",
12424 thread_timer_remain_second(p->t_connect));
12425 if (p->t_routeadv)
12426 vty_out(vty,
12427 "MRAI (interval %u) timer expires in %ld seconds\n",
12428 p->v_routeadv,
12429 thread_timer_remain_second(p->t_routeadv));
12430 if (p->password)
12431 vty_out(vty, "Peer Authentication Enabled\n");
12432
cac9e917 12433 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
12434 p->t_read ? "on" : "off",
12435 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12436 ? "on"
cac9e917 12437 : "off", p->fd);
d62a17ae 12438 }
12439
12440 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12441 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12442 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12443
12444 if (!use_json)
12445 vty_out(vty, "\n");
12446
12447 /* BFD information. */
12448 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12449
12450 if (use_json) {
12451 if (p->conf_if) /* Configured interface name. */
12452 json_object_object_add(json, p->conf_if, json_neigh);
12453 else /* Configured IP address. */
12454 json_object_object_add(json, p->host, json_neigh);
12455 }
12456}
12457
36235319
QY
12458static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
12459 enum show_type type,
12460 union sockunion *su,
12461 const char *conf_if, afi_t afi,
74a630b6 12462 bool use_json)
2986cac2 12463{
12464 struct listnode *node, *nnode;
12465 struct peer *peer;
12466 int find = 0;
12467 safi_t safi = SAFI_UNICAST;
74a630b6 12468 json_object *json = NULL;
2986cac2 12469 json_object *json_neighbor = NULL;
12470
74a630b6
NT
12471 if (use_json) {
12472 json = json_object_new_object();
12473 json_neighbor = json_object_new_object();
12474 }
12475
2986cac2 12476 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12477
12478 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12479 continue;
12480
12481 if ((peer->afc[afi][safi]) == 0)
12482 continue;
12483
2ba1fe69 12484 if (type == show_all) {
2986cac2 12485 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 12486 json_neighbor);
2986cac2 12487
74a630b6 12488 if (use_json) {
13909c4f
DS
12489 json_object_object_add(json, peer->host,
12490 json_neighbor);
74a630b6
NT
12491 json_neighbor = NULL;
12492 }
2986cac2 12493
2ba1fe69 12494 } else if (type == show_peer) {
2986cac2 12495 if (conf_if) {
12496 if ((peer->conf_if
13909c4f
DS
12497 && !strcmp(peer->conf_if, conf_if))
12498 || (peer->hostname
2986cac2 12499 && !strcmp(peer->hostname, conf_if))) {
12500 find = 1;
13909c4f
DS
12501 bgp_show_peer_gr_status(vty, peer,
12502 use_json,
12503 json_neighbor);
2986cac2 12504 }
12505 } else {
12506 if (sockunion_same(&peer->su, su)) {
12507 find = 1;
13909c4f
DS
12508 bgp_show_peer_gr_status(vty, peer,
12509 use_json,
12510 json_neighbor);
2986cac2 12511 }
12512 }
13909c4f
DS
12513 if (use_json && find)
12514 json_object_object_add(json, peer->host,
12515 json_neighbor);
2986cac2 12516 }
12517
74a630b6
NT
12518 if (find) {
12519 json_neighbor = NULL;
2986cac2 12520 break;
74a630b6 12521 }
2986cac2 12522 }
12523
12524 if (type == show_peer && !find) {
12525 if (use_json)
13909c4f 12526 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 12527 else
12528 vty_out(vty, "%% No such neighbor\n");
12529 }
12530 if (use_json) {
13909c4f
DS
12531 vty_out(vty, "%s\n",
12532 json_object_to_json_string_ext(
12533 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
12534
12535 if (json_neighbor)
12536 json_object_free(json_neighbor);
12537 json_object_free(json);
2986cac2 12538 } else {
12539 vty_out(vty, "\n");
12540 }
12541
12542 return CMD_SUCCESS;
12543}
12544
d62a17ae 12545static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12546 enum show_type type, union sockunion *su,
9f049418 12547 const char *conf_if, bool use_json,
d62a17ae 12548 json_object *json)
12549{
12550 struct listnode *node, *nnode;
12551 struct peer *peer;
12552 int find = 0;
9f049418 12553 bool nbr_output = false;
d1927ebe
AS
12554 afi_t afi = AFI_MAX;
12555 safi_t safi = SAFI_MAX;
12556
12557 if (type == show_ipv4_peer || type == show_ipv4_all) {
12558 afi = AFI_IP;
12559 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12560 afi = AFI_IP6;
12561 }
d62a17ae 12562
12563 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12564 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12565 continue;
12566
12567 switch (type) {
12568 case show_all:
12569 bgp_show_peer(vty, peer, use_json, json);
9f049418 12570 nbr_output = true;
d62a17ae 12571 break;
12572 case show_peer:
12573 if (conf_if) {
12574 if ((peer->conf_if
12575 && !strcmp(peer->conf_if, conf_if))
12576 || (peer->hostname
12577 && !strcmp(peer->hostname, conf_if))) {
12578 find = 1;
12579 bgp_show_peer(vty, peer, use_json,
12580 json);
12581 }
12582 } else {
12583 if (sockunion_same(&peer->su, su)) {
12584 find = 1;
12585 bgp_show_peer(vty, peer, use_json,
12586 json);
12587 }
12588 }
12589 break;
d1927ebe
AS
12590 case show_ipv4_peer:
12591 case show_ipv6_peer:
12592 FOREACH_SAFI (safi) {
12593 if (peer->afc[afi][safi]) {
12594 if (conf_if) {
12595 if ((peer->conf_if
12596 && !strcmp(peer->conf_if, conf_if))
12597 || (peer->hostname
12598 && !strcmp(peer->hostname, conf_if))) {
12599 find = 1;
12600 bgp_show_peer(vty, peer, use_json,
12601 json);
12602 break;
12603 }
12604 } else {
12605 if (sockunion_same(&peer->su, su)) {
12606 find = 1;
12607 bgp_show_peer(vty, peer, use_json,
12608 json);
12609 break;
12610 }
12611 }
12612 }
12613 }
12614 break;
12615 case show_ipv4_all:
12616 case show_ipv6_all:
12617 FOREACH_SAFI (safi) {
12618 if (peer->afc[afi][safi]) {
12619 bgp_show_peer(vty, peer, use_json, json);
12620 nbr_output = true;
12621 break;
12622 }
12623 }
12624 break;
d62a17ae 12625 }
12626 }
12627
d1927ebe
AS
12628 if ((type == show_peer || type == show_ipv4_peer ||
12629 type == show_ipv6_peer) && !find) {
d62a17ae 12630 if (use_json)
12631 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12632 else
88b7d255 12633 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 12634 }
12635
d1927ebe
AS
12636 if (type != show_peer && type != show_ipv4_peer &&
12637 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 12638 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 12639
d62a17ae 12640 if (use_json) {
996c9314
LB
12641 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12642 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 12643 } else {
12644 vty_out(vty, "\n");
12645 }
12646
12647 return CMD_SUCCESS;
12648}
12649
36235319
QY
12650static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12651 enum show_type type,
12652 const char *ip_str,
12653 afi_t afi, bool use_json)
2986cac2 12654{
12655
12656 int ret;
12657 struct bgp *bgp;
12658 union sockunion su;
2986cac2 12659
12660 bgp = bgp_get_default();
12661
13909c4f
DS
12662 if (!bgp)
12663 return;
2986cac2 12664
13909c4f
DS
12665 if (!use_json)
12666 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12667 NULL);
2986cac2 12668
13909c4f
DS
12669 if (ip_str) {
12670 ret = str2sockunion(ip_str, &su);
12671 if (ret < 0)
13909c4f 12672 bgp_show_neighbor_graceful_restart(
74a630b6
NT
12673 vty, bgp, type, NULL, ip_str, afi, use_json);
12674 else
12675 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
12676 NULL, afi, use_json);
13909c4f
DS
12677 } else
12678 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 12679 afi, use_json);
2986cac2 12680}
12681
d62a17ae 12682static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
12683 enum show_type type,
12684 const char *ip_str,
9f049418 12685 bool use_json)
d62a17ae 12686{
0291c246
MK
12687 struct listnode *node, *nnode;
12688 struct bgp *bgp;
71aedaa3 12689 union sockunion su;
0291c246 12690 json_object *json = NULL;
71aedaa3 12691 int ret, is_first = 1;
9f049418 12692 bool nbr_output = false;
d62a17ae 12693
12694 if (use_json)
12695 vty_out(vty, "{\n");
12696
12697 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 12698 nbr_output = true;
d62a17ae 12699 if (use_json) {
12700 if (!(json = json_object_new_object())) {
af4c2728 12701 flog_err(
e50f7cfd 12702 EC_BGP_JSON_MEM_ERROR,
d62a17ae 12703 "Unable to allocate memory for JSON object");
12704 vty_out(vty,
12705 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12706 return;
12707 }
12708
12709 json_object_int_add(json, "vrfId",
12710 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
12711 ? -1
12712 : (int64_t)bgp->vrf_id);
d62a17ae 12713 json_object_string_add(
12714 json, "vrfName",
12715 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12716 ? VRF_DEFAULT_NAME
d62a17ae 12717 : bgp->name);
12718
12719 if (!is_first)
12720 vty_out(vty, ",\n");
12721 else
12722 is_first = 0;
12723
12724 vty_out(vty, "\"%s\":",
12725 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12726 ? VRF_DEFAULT_NAME
d62a17ae 12727 : bgp->name);
12728 } else {
12729 vty_out(vty, "\nInstance %s:\n",
12730 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12731 ? VRF_DEFAULT_NAME
d62a17ae 12732 : bgp->name);
12733 }
71aedaa3 12734
d1927ebe
AS
12735 if (type == show_peer || type == show_ipv4_peer ||
12736 type == show_ipv6_peer) {
71aedaa3
DS
12737 ret = str2sockunion(ip_str, &su);
12738 if (ret < 0)
12739 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12740 use_json, json);
12741 else
12742 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12743 use_json, json);
12744 } else {
d1927ebe 12745 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
12746 use_json, json);
12747 }
b77004d6 12748 json_object_free(json);
121067e9 12749 json = NULL;
d62a17ae 12750 }
12751
01cbfd04 12752 if (use_json) {
d62a17ae 12753 vty_out(vty, "}\n");
121067e9
DS
12754 if (json)
12755 json_object_free(json);
01cbfd04 12756 }
9f049418
DS
12757 else if (!nbr_output)
12758 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12759}
12760
12761static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
12762 enum show_type type, const char *ip_str,
9f049418 12763 bool use_json)
d62a17ae 12764{
12765 int ret;
12766 struct bgp *bgp;
12767 union sockunion su;
12768 json_object *json = NULL;
12769
12770 if (name) {
12771 if (strmatch(name, "all")) {
71aedaa3
DS
12772 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
12773 use_json);
d62a17ae 12774 return CMD_SUCCESS;
12775 } else {
12776 bgp = bgp_lookup_by_name(name);
12777 if (!bgp) {
12778 if (use_json) {
12779 json = json_object_new_object();
d62a17ae 12780 vty_out(vty, "%s\n",
12781 json_object_to_json_string_ext(
12782 json,
12783 JSON_C_TO_STRING_PRETTY));
12784 json_object_free(json);
12785 } else
12786 vty_out(vty,
9f049418 12787 "%% BGP instance not found\n");
d62a17ae 12788
12789 return CMD_WARNING;
12790 }
12791 }
12792 } else {
12793 bgp = bgp_get_default();
12794 }
12795
12796 if (bgp) {
12797 json = json_object_new_object();
12798 if (ip_str) {
12799 ret = str2sockunion(ip_str, &su);
12800 if (ret < 0)
12801 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12802 use_json, json);
12803 else
12804 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12805 use_json, json);
12806 } else {
12807 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
12808 json);
12809 }
12810 json_object_free(json);
ca61fd25
DS
12811 } else {
12812 if (use_json)
12813 vty_out(vty, "{}\n");
12814 else
12815 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12816 }
12817
12818 return CMD_SUCCESS;
4fb25c53
DW
12819}
12820
2986cac2 12821
12822
12823/* "show [ip] bgp neighbors graceful-restart" commands. */
12824DEFUN (show_ip_bgp_neighbors_gracrful_restart,
12825 show_ip_bgp_neighbors_graceful_restart_cmd,
12826 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
12827 SHOW_STR
12828 BGP_STR
12829 IP_STR
12830 IPV6_STR
12831 NEIGHBOR_STR
12832 "Neighbor to display information about\n"
12833 "Neighbor to display information about\n"
12834 "Neighbor on BGP configured interface\n"
12835 GR_SHOW
12836 JSON_STR)
12837{
12838 char *sh_arg = NULL;
12839 enum show_type sh_type;
12840 int idx = 0;
12841 afi_t afi = AFI_MAX;
2986cac2 12842 bool uj = use_json(argc, argv);
12843
36235319 12844 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 12845 afi = AFI_MAX;
12846
12847 idx++;
12848
12849 if (argv_find(argv, argc, "A.B.C.D", &idx)
12850 || argv_find(argv, argc, "X:X::X:X", &idx)
12851 || argv_find(argv, argc, "WORD", &idx)) {
12852 sh_type = show_peer;
12853 sh_arg = argv[idx]->arg;
12854 } else
12855 sh_type = show_all;
12856
12857 if (!argv_find(argv, argc, "graceful-restart", &idx))
12858 return CMD_SUCCESS;
12859
12860
36235319
QY
12861 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
12862 afi, uj);
2986cac2 12863}
12864
716b2d8a 12865/* "show [ip] bgp neighbors" commands. */
718e3744 12866DEFUN (show_ip_bgp_neighbors,
12867 show_ip_bgp_neighbors_cmd,
24345e82 12868 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 12869 SHOW_STR
12870 IP_STR
12871 BGP_STR
f2a8972b 12872 BGP_INSTANCE_HELP_STR
8c3deaae
QY
12873 "Address Family\n"
12874 "Address Family\n"
718e3744 12875 "Detailed information on TCP and BGP neighbor connections\n"
12876 "Neighbor to display information about\n"
a80beece 12877 "Neighbor to display information about\n"
91d37724 12878 "Neighbor on BGP configured interface\n"
9973d184 12879 JSON_STR)
718e3744 12880{
d62a17ae 12881 char *vrf = NULL;
12882 char *sh_arg = NULL;
12883 enum show_type sh_type;
d1927ebe 12884 afi_t afi = AFI_MAX;
718e3744 12885
9f049418 12886 bool uj = use_json(argc, argv);
718e3744 12887
d62a17ae 12888 int idx = 0;
718e3744 12889
9a8bdf1c
PG
12890 /* [<vrf> VIEWVRFNAME] */
12891 if (argv_find(argv, argc, "vrf", &idx)) {
12892 vrf = argv[idx + 1]->arg;
12893 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12894 vrf = NULL;
12895 } else if (argv_find(argv, argc, "view", &idx))
12896 /* [<view> VIEWVRFNAME] */
d62a17ae 12897 vrf = argv[idx + 1]->arg;
718e3744 12898
d62a17ae 12899 idx++;
d1927ebe
AS
12900
12901 if (argv_find(argv, argc, "ipv4", &idx)) {
12902 sh_type = show_ipv4_all;
12903 afi = AFI_IP;
12904 } else if (argv_find(argv, argc, "ipv6", &idx)) {
12905 sh_type = show_ipv6_all;
12906 afi = AFI_IP6;
12907 } else {
12908 sh_type = show_all;
12909 }
12910
d62a17ae 12911 if (argv_find(argv, argc, "A.B.C.D", &idx)
12912 || argv_find(argv, argc, "X:X::X:X", &idx)
12913 || argv_find(argv, argc, "WORD", &idx)) {
12914 sh_type = show_peer;
12915 sh_arg = argv[idx]->arg;
d1927ebe
AS
12916 }
12917
12918 if (sh_type == show_peer && afi == AFI_IP) {
12919 sh_type = show_ipv4_peer;
12920 } else if (sh_type == show_peer && afi == AFI_IP6) {
12921 sh_type = show_ipv6_peer;
12922 }
856ca177 12923
d62a17ae 12924 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 12925}
12926
716b2d8a 12927/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 12928 paths' and `show ip mbgp paths'. Those functions results are the
12929 same.*/
f412b39a 12930DEFUN (show_ip_bgp_paths,
718e3744 12931 show_ip_bgp_paths_cmd,
46f296b4 12932 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 12933 SHOW_STR
12934 IP_STR
12935 BGP_STR
46f296b4 12936 BGP_SAFI_HELP_STR
718e3744 12937 "Path information\n")
12938{
d62a17ae 12939 vty_out(vty, "Address Refcnt Path\n");
12940 aspath_print_all_vty(vty);
12941 return CMD_SUCCESS;
718e3744 12942}
12943
718e3744 12944#include "hash.h"
12945
e3b78da8 12946static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12947 struct vty *vty)
718e3744 12948{
d62a17ae 12949 struct community *com;
718e3744 12950
e3b78da8 12951 com = (struct community *)bucket->data;
3f65c5b1 12952 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 12953 community_str(com, false));
718e3744 12954}
12955
12956/* Show BGP's community internal data. */
f412b39a 12957DEFUN (show_ip_bgp_community_info,
718e3744 12958 show_ip_bgp_community_info_cmd,
bec37ba5 12959 "show [ip] bgp community-info",
718e3744 12960 SHOW_STR
12961 IP_STR
12962 BGP_STR
12963 "List all bgp community information\n")
12964{
d62a17ae 12965 vty_out(vty, "Address Refcnt Community\n");
718e3744 12966
d62a17ae 12967 hash_iterate(community_hash(),
e3b78da8 12968 (void (*)(struct hash_bucket *,
d62a17ae 12969 void *))community_show_all_iterator,
12970 vty);
718e3744 12971
d62a17ae 12972 return CMD_SUCCESS;
718e3744 12973}
12974
e3b78da8 12975static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12976 struct vty *vty)
57d187bc 12977{
d62a17ae 12978 struct lcommunity *lcom;
57d187bc 12979
e3b78da8 12980 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 12981 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 12982 lcommunity_str(lcom, false));
57d187bc
JS
12983}
12984
12985/* Show BGP's community internal data. */
12986DEFUN (show_ip_bgp_lcommunity_info,
12987 show_ip_bgp_lcommunity_info_cmd,
12988 "show ip bgp large-community-info",
12989 SHOW_STR
12990 IP_STR
12991 BGP_STR
12992 "List all bgp large-community information\n")
12993{
d62a17ae 12994 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 12995
d62a17ae 12996 hash_iterate(lcommunity_hash(),
e3b78da8 12997 (void (*)(struct hash_bucket *,
d62a17ae 12998 void *))lcommunity_show_all_iterator,
12999 vty);
57d187bc 13000
d62a17ae 13001 return CMD_SUCCESS;
57d187bc 13002}
2986cac2 13003/* Graceful Restart */
13004
13005static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
13006 struct bgp *bgp,
13007 bool use_json,
13008 json_object *json)
2986cac2 13009{
57d187bc
JS
13010
13011
2986cac2 13012 vty_out(vty, "\n%s", SHOW_GR_HEADER);
13013
7318ae88 13014 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 13015
13016 switch (bgp_global_gr_mode) {
13017
13018 case GLOBAL_HELPER:
13909c4f 13019 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 13020 break;
13021
13022 case GLOBAL_GR:
13909c4f 13023 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 13024 break;
13025
13026 case GLOBAL_DISABLE:
13909c4f 13027 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 13028 break;
13029
13030 case GLOBAL_INVALID:
2986cac2 13031 vty_out(vty,
2ba1fe69 13032 "Global BGP GR Mode Invalid\n");
2986cac2 13033 break;
13034 }
13035 vty_out(vty, "\n");
13036}
13037
36235319
QY
13038static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
13039 enum show_type type,
13040 const char *ip_str,
13041 afi_t afi, bool use_json)
2986cac2 13042{
13043 if ((afi == AFI_MAX) && (ip_str == NULL)) {
13044 afi = AFI_IP;
13045
13046 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
13047
36235319
QY
13048 bgp_show_neighbor_graceful_restart_vty(
13049 vty, type, ip_str, afi, use_json);
2986cac2 13050 afi++;
13051 }
13052 } else if (afi != AFI_MAX) {
36235319
QY
13053 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
13054 use_json);
2986cac2 13055 } else {
13056 return CMD_ERR_INCOMPLETE;
13057 }
13058
13059 return CMD_SUCCESS;
13060}
13061/* Graceful Restart */
13062
f412b39a 13063DEFUN (show_ip_bgp_attr_info,
718e3744 13064 show_ip_bgp_attr_info_cmd,
bec37ba5 13065 "show [ip] bgp attribute-info",
718e3744 13066 SHOW_STR
13067 IP_STR
13068 BGP_STR
13069 "List all bgp attribute information\n")
13070{
d62a17ae 13071 attr_show_all(vty);
13072 return CMD_SUCCESS;
718e3744 13073}
6b0655a2 13074
03915806
CS
13075static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
13076 afi_t afi, safi_t safi,
13077 bool use_json, json_object *json)
53089bec 13078{
13079 struct bgp *bgp;
13080 struct listnode *node;
13081 char *vname;
13082 char buf1[INET6_ADDRSTRLEN];
13083 char *ecom_str;
13084 vpn_policy_direction_t dir;
13085
03915806 13086 if (json) {
b46dfd20
DS
13087 json_object *json_import_vrfs = NULL;
13088 json_object *json_export_vrfs = NULL;
13089
b46dfd20
DS
13090 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13091
53089bec 13092 if (!bgp) {
b46dfd20
DS
13093 vty_out(vty, "%s\n",
13094 json_object_to_json_string_ext(
13095 json,
13096 JSON_C_TO_STRING_PRETTY));
13097 json_object_free(json);
13098
53089bec 13099 return CMD_WARNING;
13100 }
b46dfd20 13101
94d4c685
DS
13102 /* Provide context for the block */
13103 json_object_string_add(json, "vrf", name ? name : "default");
13104 json_object_string_add(json, "afiSafi",
5cb5f4d0 13105 get_afi_safi_str(afi, safi, true));
94d4c685 13106
b46dfd20
DS
13107 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13108 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
13109 json_object_string_add(json, "importFromVrfs", "none");
13110 json_object_string_add(json, "importRts", "none");
13111 } else {
6ce24e52
DS
13112 json_import_vrfs = json_object_new_array();
13113
b46dfd20
DS
13114 for (ALL_LIST_ELEMENTS_RO(
13115 bgp->vpn_policy[afi].import_vrf,
13116 node, vname))
13117 json_object_array_add(json_import_vrfs,
13118 json_object_new_string(vname));
13119
b20875ea
CS
13120 json_object_object_add(json, "importFromVrfs",
13121 json_import_vrfs);
b46dfd20 13122 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13123 if (bgp->vpn_policy[afi].rtlist[dir]) {
13124 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13125 bgp->vpn_policy[afi].rtlist[dir],
13126 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13127 json_object_string_add(json, "importRts",
13128 ecom_str);
13129 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13130 } else
13131 json_object_string_add(json, "importRts",
13132 "none");
b46dfd20
DS
13133 }
13134
13135 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13136 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
13137 json_object_string_add(json, "exportToVrfs", "none");
13138 json_object_string_add(json, "routeDistinguisher",
13139 "none");
13140 json_object_string_add(json, "exportRts", "none");
13141 } else {
6ce24e52
DS
13142 json_export_vrfs = json_object_new_array();
13143
b46dfd20
DS
13144 for (ALL_LIST_ELEMENTS_RO(
13145 bgp->vpn_policy[afi].export_vrf,
13146 node, vname))
13147 json_object_array_add(json_export_vrfs,
13148 json_object_new_string(vname));
13149 json_object_object_add(json, "exportToVrfs",
13150 json_export_vrfs);
13151 json_object_string_add(json, "routeDistinguisher",
13152 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13153 buf1, RD_ADDRSTRLEN));
13154
13155 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13156 if (bgp->vpn_policy[afi].rtlist[dir]) {
13157 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13158 bgp->vpn_policy[afi].rtlist[dir],
13159 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13160 json_object_string_add(json, "exportRts",
13161 ecom_str);
13162 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13163 } else
13164 json_object_string_add(json, "exportRts",
13165 "none");
b46dfd20
DS
13166 }
13167
03915806
CS
13168 if (use_json) {
13169 vty_out(vty, "%s\n",
13170 json_object_to_json_string_ext(json,
b46dfd20 13171 JSON_C_TO_STRING_PRETTY));
03915806
CS
13172 json_object_free(json);
13173 }
53089bec 13174 } else {
b46dfd20
DS
13175 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13176
53089bec 13177 if (!bgp) {
b46dfd20 13178 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 13179 return CMD_WARNING;
13180 }
53089bec 13181
b46dfd20
DS
13182 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13183 BGP_CONFIG_VRF_TO_VRF_IMPORT))
13184 vty_out(vty,
13185 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 13186 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13187 else {
13188 vty_out(vty,
13189 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 13190 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13191
13192 for (ALL_LIST_ELEMENTS_RO(
13193 bgp->vpn_policy[afi].import_vrf,
13194 node, vname))
13195 vty_out(vty, " %s\n", vname);
13196
13197 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13198 ecom_str = NULL;
13199 if (bgp->vpn_policy[afi].rtlist[dir]) {
13200 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13201 bgp->vpn_policy[afi].rtlist[dir],
13202 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 13203 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 13204
b20875ea
CS
13205 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13206 } else
13207 vty_out(vty, "Import RT(s):\n");
53089bec 13208 }
53089bec 13209
b46dfd20
DS
13210 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13211 BGP_CONFIG_VRF_TO_VRF_EXPORT))
13212 vty_out(vty,
13213 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 13214 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13215 else {
13216 vty_out(vty,
04c9077f 13217 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 13218 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13219
13220 for (ALL_LIST_ELEMENTS_RO(
13221 bgp->vpn_policy[afi].export_vrf,
13222 node, vname))
13223 vty_out(vty, " %s\n", vname);
13224
13225 vty_out(vty, "RD: %s\n",
13226 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13227 buf1, RD_ADDRSTRLEN));
13228
13229 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13230 if (bgp->vpn_policy[afi].rtlist[dir]) {
13231 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13232 bgp->vpn_policy[afi].rtlist[dir],
13233 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13234 vty_out(vty, "Export RT: %s\n", ecom_str);
13235 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13236 } else
13237 vty_out(vty, "Import RT(s):\n");
53089bec 13238 }
53089bec 13239 }
13240
13241 return CMD_SUCCESS;
13242}
13243
03915806
CS
13244static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
13245 safi_t safi, bool use_json)
13246{
13247 struct listnode *node, *nnode;
13248 struct bgp *bgp;
13249 char *vrf_name = NULL;
13250 json_object *json = NULL;
13251 json_object *json_vrf = NULL;
13252 json_object *json_vrfs = NULL;
13253
13254 if (use_json) {
13255 json = json_object_new_object();
13256 json_vrfs = json_object_new_object();
13257 }
13258
13259 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13260
13261 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
13262 vrf_name = bgp->name;
13263
13264 if (use_json) {
13265 json_vrf = json_object_new_object();
13266 } else {
13267 vty_out(vty, "\nInstance %s:\n",
13268 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13269 ? VRF_DEFAULT_NAME : bgp->name);
13270 }
13271 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
13272 if (use_json) {
13273 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13274 json_object_object_add(json_vrfs,
13275 VRF_DEFAULT_NAME, json_vrf);
13276 else
13277 json_object_object_add(json_vrfs, vrf_name,
13278 json_vrf);
13279 }
13280 }
13281
13282 if (use_json) {
13283 json_object_object_add(json, "vrfs", json_vrfs);
13284 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
13285 JSON_C_TO_STRING_PRETTY));
13286 json_object_free(json);
13287 }
13288
13289 return CMD_SUCCESS;
13290}
13291
53089bec 13292/* "show [ip] bgp route-leak" command. */
13293DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
13294 show_ip_bgp_route_leak_cmd,
13295 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
13296 SHOW_STR
13297 IP_STR
13298 BGP_STR
13299 BGP_INSTANCE_HELP_STR
13300 BGP_AFI_HELP_STR
13301 BGP_SAFI_HELP_STR
13302 "Route leaking information\n"
13303 JSON_STR)
53089bec 13304{
13305 char *vrf = NULL;
13306 afi_t afi = AFI_MAX;
13307 safi_t safi = SAFI_MAX;
13308
9f049418 13309 bool uj = use_json(argc, argv);
53089bec 13310 int idx = 0;
03915806 13311 json_object *json = NULL;
53089bec 13312
13313 /* show [ip] bgp */
13314 if (argv_find(argv, argc, "ip", &idx)) {
13315 afi = AFI_IP;
13316 safi = SAFI_UNICAST;
13317 }
13318 /* [vrf VIEWVRFNAME] */
13319 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
13320 vty_out(vty,
13321 "%% This command is not applicable to BGP views\n");
53089bec 13322 return CMD_WARNING;
13323 }
13324
9a8bdf1c
PG
13325 if (argv_find(argv, argc, "vrf", &idx)) {
13326 vrf = argv[idx + 1]->arg;
13327 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13328 vrf = NULL;
13329 }
53089bec 13330 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13331 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13332 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13333 }
13334
13335 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
13336 vty_out(vty,
13337 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 13338 return CMD_WARNING;
13339 }
13340
03915806
CS
13341 if (vrf && strmatch(vrf, "all"))
13342 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13343
13344 if (uj)
13345 json = json_object_new_object();
13346
13347 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 13348}
13349
d62a17ae 13350static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13351 safi_t safi)
f186de26 13352{
d62a17ae 13353 struct listnode *node, *nnode;
13354 struct bgp *bgp;
f186de26 13355
d62a17ae 13356 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13357 vty_out(vty, "\nInstance %s:\n",
13358 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13359 ? VRF_DEFAULT_NAME
d62a17ae 13360 : bgp->name);
13361 update_group_show(bgp, afi, safi, vty, 0);
13362 }
f186de26 13363}
13364
d62a17ae 13365static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13366 int safi, uint64_t subgrp_id)
4fb25c53 13367{
d62a17ae 13368 struct bgp *bgp;
4fb25c53 13369
d62a17ae 13370 if (name) {
13371 if (strmatch(name, "all")) {
13372 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13373 return CMD_SUCCESS;
13374 } else {
13375 bgp = bgp_lookup_by_name(name);
13376 }
13377 } else {
13378 bgp = bgp_get_default();
13379 }
4fb25c53 13380
d62a17ae 13381 if (bgp)
13382 update_group_show(bgp, afi, safi, vty, subgrp_id);
13383 return CMD_SUCCESS;
4fb25c53
DW
13384}
13385
8fe8a7f6
DS
13386DEFUN (show_ip_bgp_updgrps,
13387 show_ip_bgp_updgrps_cmd,
c1a44e43 13388 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 13389 SHOW_STR
13390 IP_STR
13391 BGP_STR
13392 BGP_INSTANCE_HELP_STR
c9e571b4 13393 BGP_AFI_HELP_STR
9bedbb1e 13394 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
13395 "Detailed info about dynamic update groups\n"
13396 "Specific subgroup to display detailed info for\n")
8386ac43 13397{
d62a17ae 13398 char *vrf = NULL;
13399 afi_t afi = AFI_IP6;
13400 safi_t safi = SAFI_UNICAST;
13401 uint64_t subgrp_id = 0;
13402
13403 int idx = 0;
13404
13405 /* show [ip] bgp */
13406 if (argv_find(argv, argc, "ip", &idx))
13407 afi = AFI_IP;
9a8bdf1c
PG
13408 /* [<vrf> VIEWVRFNAME] */
13409 if (argv_find(argv, argc, "vrf", &idx)) {
13410 vrf = argv[idx + 1]->arg;
13411 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13412 vrf = NULL;
13413 } else if (argv_find(argv, argc, "view", &idx))
13414 /* [<view> VIEWVRFNAME] */
13415 vrf = argv[idx + 1]->arg;
d62a17ae 13416 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13417 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13418 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13419 }
5bf15956 13420
d62a17ae 13421 /* get subgroup id, if provided */
13422 idx = argc - 1;
13423 if (argv[idx]->type == VARIABLE_TKN)
13424 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 13425
d62a17ae 13426 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
13427}
13428
f186de26 13429DEFUN (show_bgp_instance_all_ipv6_updgrps,
13430 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 13431 "show [ip] bgp <view|vrf> all update-groups",
f186de26 13432 SHOW_STR
716b2d8a 13433 IP_STR
f186de26 13434 BGP_STR
13435 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 13436 "Detailed info about dynamic update groups\n")
f186de26 13437{
d62a17ae 13438 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13439 return CMD_SUCCESS;
f186de26 13440}
13441
43d3f4fc
DS
13442DEFUN (show_bgp_l2vpn_evpn_updgrps,
13443 show_bgp_l2vpn_evpn_updgrps_cmd,
13444 "show [ip] bgp l2vpn evpn update-groups",
13445 SHOW_STR
13446 IP_STR
13447 BGP_STR
13448 "l2vpn address family\n"
13449 "evpn sub-address family\n"
13450 "Detailed info about dynamic update groups\n")
13451{
13452 char *vrf = NULL;
13453 uint64_t subgrp_id = 0;
13454
13455 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13456 return CMD_SUCCESS;
13457}
13458
5bf15956
DW
13459DEFUN (show_bgp_updgrps_stats,
13460 show_bgp_updgrps_stats_cmd,
716b2d8a 13461 "show [ip] bgp update-groups statistics",
3f9c7369 13462 SHOW_STR
716b2d8a 13463 IP_STR
3f9c7369 13464 BGP_STR
0c7b1b01 13465 "Detailed info about dynamic update groups\n"
3f9c7369
DS
13466 "Statistics\n")
13467{
d62a17ae 13468 struct bgp *bgp;
3f9c7369 13469
d62a17ae 13470 bgp = bgp_get_default();
13471 if (bgp)
13472 update_group_show_stats(bgp, vty);
3f9c7369 13473
d62a17ae 13474 return CMD_SUCCESS;
3f9c7369
DS
13475}
13476
8386ac43 13477DEFUN (show_bgp_instance_updgrps_stats,
13478 show_bgp_instance_updgrps_stats_cmd,
18c57037 13479 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 13480 SHOW_STR
716b2d8a 13481 IP_STR
8386ac43 13482 BGP_STR
13483 BGP_INSTANCE_HELP_STR
0c7b1b01 13484 "Detailed info about dynamic update groups\n"
8386ac43 13485 "Statistics\n")
13486{
d62a17ae 13487 int idx_word = 3;
13488 struct bgp *bgp;
8386ac43 13489
d62a17ae 13490 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13491 if (bgp)
13492 update_group_show_stats(bgp, vty);
8386ac43 13493
d62a17ae 13494 return CMD_SUCCESS;
8386ac43 13495}
13496
d62a17ae 13497static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13498 afi_t afi, safi_t safi,
13499 const char *what, uint64_t subgrp_id)
3f9c7369 13500{
d62a17ae 13501 struct bgp *bgp;
8386ac43 13502
d62a17ae 13503 if (name)
13504 bgp = bgp_lookup_by_name(name);
13505 else
13506 bgp = bgp_get_default();
8386ac43 13507
d62a17ae 13508 if (bgp) {
13509 if (!strcmp(what, "advertise-queue"))
13510 update_group_show_adj_queue(bgp, afi, safi, vty,
13511 subgrp_id);
13512 else if (!strcmp(what, "advertised-routes"))
13513 update_group_show_advertised(bgp, afi, safi, vty,
13514 subgrp_id);
13515 else if (!strcmp(what, "packet-queue"))
13516 update_group_show_packet_queue(bgp, afi, safi, vty,
13517 subgrp_id);
13518 }
3f9c7369
DS
13519}
13520
dc64bdec
QY
13521DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13522 show_ip_bgp_instance_updgrps_adj_s_cmd,
13523 "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",
13524 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13525 BGP_SAFI_HELP_STR
13526 "Detailed info about dynamic update groups\n"
13527 "Specific subgroup to display info for\n"
13528 "Advertisement queue\n"
13529 "Announced routes\n"
13530 "Packet queue\n")
3f9c7369 13531{
dc64bdec
QY
13532 uint64_t subgrp_id = 0;
13533 afi_t afiz;
13534 safi_t safiz;
13535 if (sgid)
13536 subgrp_id = strtoull(sgid, NULL, 10);
13537
13538 if (!ip && !afi)
13539 afiz = AFI_IP6;
13540 if (!ip && afi)
13541 afiz = bgp_vty_afi_from_str(afi);
13542 if (ip && !afi)
13543 afiz = AFI_IP;
13544 if (ip && afi) {
13545 afiz = bgp_vty_afi_from_str(afi);
13546 if (afiz != AFI_IP)
13547 vty_out(vty,
13548 "%% Cannot specify both 'ip' and 'ipv6'\n");
13549 return CMD_WARNING;
13550 }
d62a17ae 13551
dc64bdec 13552 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 13553
dc64bdec 13554 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 13555 return CMD_SUCCESS;
13556}
13557
d62a17ae 13558static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13559{
13560 struct listnode *node, *nnode;
13561 struct prefix *range;
13562 struct peer *conf;
13563 struct peer *peer;
13564 char buf[PREFIX2STR_BUFFER];
13565 afi_t afi;
13566 safi_t safi;
13567 const char *peer_status;
13568 const char *af_str;
13569 int lr_count;
13570 int dynamic;
13571 int af_cfgd;
13572
13573 conf = group->conf;
13574
13575 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 13576 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 13577 group->name, conf->as);
d62a17ae 13578 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 13579 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 13580 group->name, group->bgp->as);
d62a17ae 13581 } else {
13582 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13583 }
f14e6fdb 13584
d62a17ae 13585 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13586 vty_out(vty, " Peer-group type is internal\n");
13587 else
13588 vty_out(vty, " Peer-group type is external\n");
13589
13590 /* Display AFs configured. */
13591 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
13592 FOREACH_AFI_SAFI (afi, safi) {
13593 if (conf->afc[afi][safi]) {
13594 af_cfgd = 1;
5cb5f4d0 13595 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 13596 }
05c7a1cc 13597 }
d62a17ae 13598 if (!af_cfgd)
13599 vty_out(vty, " none\n");
13600 else
13601 vty_out(vty, "\n");
13602
13603 /* Display listen ranges (for dynamic neighbors), if any */
13604 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13605 if (afi == AFI_IP)
13606 af_str = "IPv4";
13607 else if (afi == AFI_IP6)
13608 af_str = "IPv6";
13609 else
13610 af_str = "???";
13611 lr_count = listcount(group->listen_range[afi]);
13612 if (lr_count) {
13613 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13614 af_str);
13615
13616
13617 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13618 nnode, range)) {
13619 prefix2str(range, buf, sizeof(buf));
13620 vty_out(vty, " %s\n", buf);
13621 }
13622 }
13623 }
f14e6fdb 13624
d62a17ae 13625 /* Display group members and their status */
13626 if (listcount(group->peer)) {
13627 vty_out(vty, " Peer-group members:\n");
13628 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
13629 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
13630 peer_status = "Idle (Admin)";
13631 else if (CHECK_FLAG(peer->sflags,
13632 PEER_STATUS_PREFIX_OVERFLOW))
13633 peer_status = "Idle (PfxCt)";
13634 else
13635 peer_status = lookup_msg(bgp_status_msg,
13636 peer->status, NULL);
13637
13638 dynamic = peer_dynamic_neighbor(peer);
13639 vty_out(vty, " %s %s %s \n", peer->host,
13640 dynamic ? "(dynamic)" : "", peer_status);
13641 }
13642 }
f14e6fdb 13643
d62a17ae 13644 return CMD_SUCCESS;
13645}
13646
ff9959b0
QY
13647static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13648 const char *group_name)
d62a17ae 13649{
ff9959b0 13650 struct bgp *bgp;
d62a17ae 13651 struct listnode *node, *nnode;
13652 struct peer_group *group;
ff9959b0
QY
13653 bool found = false;
13654
13655 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13656
13657 if (!bgp) {
9f049418 13658 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
13659 return CMD_WARNING;
13660 }
d62a17ae 13661
13662 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
13663 if (group_name) {
13664 if (strmatch(group->name, group_name)) {
d62a17ae 13665 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
13666 found = true;
13667 break;
d62a17ae 13668 }
ff9959b0
QY
13669 } else {
13670 bgp_show_one_peer_group(vty, group);
d62a17ae 13671 }
f14e6fdb 13672 }
f14e6fdb 13673
ff9959b0 13674 if (group_name && !found)
d62a17ae 13675 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 13676
d62a17ae 13677 return CMD_SUCCESS;
f14e6fdb
DS
13678}
13679
f14e6fdb
DS
13680DEFUN (show_ip_bgp_peer_groups,
13681 show_ip_bgp_peer_groups_cmd,
18c57037 13682 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
13683 SHOW_STR
13684 IP_STR
13685 BGP_STR
8386ac43 13686 BGP_INSTANCE_HELP_STR
d6e3c605
QY
13687 "Detailed information on BGP peer groups\n"
13688 "Peer group name\n")
f14e6fdb 13689{
d62a17ae 13690 char *vrf, *pg;
d62a17ae 13691 int idx = 0;
f14e6fdb 13692
a4d82a8a
PZ
13693 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13694 : NULL;
d62a17ae 13695 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 13696
ff9959b0 13697 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 13698}
3f9c7369 13699
d6e3c605 13700
718e3744 13701/* Redistribute VTY commands. */
13702
718e3744 13703DEFUN (bgp_redistribute_ipv4,
13704 bgp_redistribute_ipv4_cmd,
40d1cbfb 13705 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 13706 "Redistribute information from another routing protocol\n"
ab0181ee 13707 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 13708{
d62a17ae 13709 VTY_DECLVAR_CONTEXT(bgp, bgp);
13710 int idx_protocol = 1;
13711 int type;
718e3744 13712
d62a17ae 13713 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13714 if (type < 0) {
13715 vty_out(vty, "%% Invalid route type\n");
13716 return CMD_WARNING_CONFIG_FAILED;
13717 }
7f323236 13718
d62a17ae 13719 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13720 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 13721}
13722
d62a17ae 13723ALIAS_HIDDEN(
13724 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
13725 "redistribute " FRR_IP_REDIST_STR_BGPD,
13726 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 13727
718e3744 13728DEFUN (bgp_redistribute_ipv4_rmap,
13729 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 13730 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 13731 "Redistribute information from another routing protocol\n"
ab0181ee 13732 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13733 "Route map reference\n"
13734 "Pointer to route-map entries\n")
13735{
d62a17ae 13736 VTY_DECLVAR_CONTEXT(bgp, bgp);
13737 int idx_protocol = 1;
13738 int idx_word = 3;
13739 int type;
13740 struct bgp_redist *red;
e923dd62 13741 bool changed;
1de27621
DA
13742 struct route_map *route_map = route_map_lookup_warn_noexist(
13743 vty, argv[idx_word]->arg);
718e3744 13744
d62a17ae 13745 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13746 if (type < 0) {
13747 vty_out(vty, "%% Invalid route type\n");
13748 return CMD_WARNING_CONFIG_FAILED;
13749 }
718e3744 13750
d62a17ae 13751 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13752 changed =
13753 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13754 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 13755}
13756
d62a17ae 13757ALIAS_HIDDEN(
13758 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
13759 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13760 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13761 "Route map reference\n"
13762 "Pointer to route-map entries\n")
596c17ba 13763
718e3744 13764DEFUN (bgp_redistribute_ipv4_metric,
13765 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 13766 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13767 "Redistribute information from another routing protocol\n"
ab0181ee 13768 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13769 "Metric for redistributed routes\n"
13770 "Default metric\n")
13771{
d62a17ae 13772 VTY_DECLVAR_CONTEXT(bgp, bgp);
13773 int idx_protocol = 1;
13774 int idx_number = 3;
13775 int type;
d7c0a89a 13776 uint32_t metric;
d62a17ae 13777 struct bgp_redist *red;
e923dd62 13778 bool changed;
d62a17ae 13779
13780 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13781 if (type < 0) {
13782 vty_out(vty, "%% Invalid route type\n");
13783 return CMD_WARNING_CONFIG_FAILED;
13784 }
13785 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13786
13787 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13788 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13789 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13790}
13791
13792ALIAS_HIDDEN(
13793 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
13794 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13795 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13796 "Metric for redistributed routes\n"
13797 "Default metric\n")
596c17ba 13798
718e3744 13799DEFUN (bgp_redistribute_ipv4_rmap_metric,
13800 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 13801 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 13802 "Redistribute information from another routing protocol\n"
ab0181ee 13803 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13804 "Route map reference\n"
13805 "Pointer to route-map entries\n"
13806 "Metric for redistributed routes\n"
13807 "Default metric\n")
13808{
d62a17ae 13809 VTY_DECLVAR_CONTEXT(bgp, bgp);
13810 int idx_protocol = 1;
13811 int idx_word = 3;
13812 int idx_number = 5;
13813 int type;
d7c0a89a 13814 uint32_t metric;
d62a17ae 13815 struct bgp_redist *red;
e923dd62 13816 bool changed;
1de27621
DA
13817 struct route_map *route_map =
13818 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13819
13820 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13821 if (type < 0) {
13822 vty_out(vty, "%% Invalid route type\n");
13823 return CMD_WARNING_CONFIG_FAILED;
13824 }
13825 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13826
13827 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13828 changed =
13829 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13830 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13831 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13832}
13833
13834ALIAS_HIDDEN(
13835 bgp_redistribute_ipv4_rmap_metric,
13836 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
13837 "redistribute " FRR_IP_REDIST_STR_BGPD
13838 " route-map WORD metric (0-4294967295)",
13839 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13840 "Route map reference\n"
13841 "Pointer to route-map entries\n"
13842 "Metric for redistributed routes\n"
13843 "Default metric\n")
596c17ba 13844
718e3744 13845DEFUN (bgp_redistribute_ipv4_metric_rmap,
13846 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 13847 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 13848 "Redistribute information from another routing protocol\n"
ab0181ee 13849 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13850 "Metric for redistributed routes\n"
13851 "Default metric\n"
13852 "Route map reference\n"
13853 "Pointer to route-map entries\n")
13854{
d62a17ae 13855 VTY_DECLVAR_CONTEXT(bgp, bgp);
13856 int idx_protocol = 1;
13857 int idx_number = 3;
13858 int idx_word = 5;
13859 int type;
d7c0a89a 13860 uint32_t metric;
d62a17ae 13861 struct bgp_redist *red;
e923dd62 13862 bool changed;
1de27621
DA
13863 struct route_map *route_map =
13864 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13865
13866 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13867 if (type < 0) {
13868 vty_out(vty, "%% Invalid route type\n");
13869 return CMD_WARNING_CONFIG_FAILED;
13870 }
13871 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13872
13873 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13874 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
13875 changed |=
13876 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13877 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13878}
13879
13880ALIAS_HIDDEN(
13881 bgp_redistribute_ipv4_metric_rmap,
13882 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
13883 "redistribute " FRR_IP_REDIST_STR_BGPD
13884 " metric (0-4294967295) route-map WORD",
13885 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13886 "Metric for redistributed routes\n"
13887 "Default metric\n"
13888 "Route map reference\n"
13889 "Pointer to route-map entries\n")
596c17ba 13890
7c8ff89e
DS
13891DEFUN (bgp_redistribute_ipv4_ospf,
13892 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 13893 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
13894 "Redistribute information from another routing protocol\n"
13895 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13896 "Non-main Kernel Routing Table\n"
13897 "Instance ID/Table ID\n")
7c8ff89e 13898{
d62a17ae 13899 VTY_DECLVAR_CONTEXT(bgp, bgp);
13900 int idx_ospf_table = 1;
13901 int idx_number = 2;
d7c0a89a
QY
13902 unsigned short instance;
13903 unsigned short protocol;
7c8ff89e 13904
d62a17ae 13905 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 13906
d62a17ae 13907 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13908 protocol = ZEBRA_ROUTE_OSPF;
13909 else
13910 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 13911
d62a17ae 13912 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13913 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
13914}
13915
d62a17ae 13916ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
13917 "redistribute <ospf|table> (1-65535)",
13918 "Redistribute information from another routing protocol\n"
13919 "Open Shortest Path First (OSPFv2)\n"
13920 "Non-main Kernel Routing Table\n"
13921 "Instance ID/Table ID\n")
596c17ba 13922
7c8ff89e
DS
13923DEFUN (bgp_redistribute_ipv4_ospf_rmap,
13924 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 13925 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
13926 "Redistribute information from another routing protocol\n"
13927 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13928 "Non-main Kernel Routing Table\n"
13929 "Instance ID/Table ID\n"
7c8ff89e
DS
13930 "Route map reference\n"
13931 "Pointer to route-map entries\n")
13932{
d62a17ae 13933 VTY_DECLVAR_CONTEXT(bgp, bgp);
13934 int idx_ospf_table = 1;
13935 int idx_number = 2;
13936 int idx_word = 4;
13937 struct bgp_redist *red;
d7c0a89a 13938 unsigned short instance;
d62a17ae 13939 int protocol;
e923dd62 13940 bool changed;
1de27621
DA
13941 struct route_map *route_map =
13942 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13943
13944 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13945 protocol = ZEBRA_ROUTE_OSPF;
13946 else
13947 protocol = ZEBRA_ROUTE_TABLE;
13948
13949 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13950 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13951 changed =
13952 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13953 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13954}
13955
13956ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
13957 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
13958 "redistribute <ospf|table> (1-65535) route-map WORD",
13959 "Redistribute information from another routing protocol\n"
13960 "Open Shortest Path First (OSPFv2)\n"
13961 "Non-main Kernel Routing Table\n"
13962 "Instance ID/Table ID\n"
13963 "Route map reference\n"
13964 "Pointer to route-map entries\n")
596c17ba 13965
7c8ff89e
DS
13966DEFUN (bgp_redistribute_ipv4_ospf_metric,
13967 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 13968 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
13969 "Redistribute information from another routing protocol\n"
13970 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13971 "Non-main Kernel Routing Table\n"
13972 "Instance ID/Table ID\n"
7c8ff89e
DS
13973 "Metric for redistributed routes\n"
13974 "Default metric\n")
13975{
d62a17ae 13976 VTY_DECLVAR_CONTEXT(bgp, bgp);
13977 int idx_ospf_table = 1;
13978 int idx_number = 2;
13979 int idx_number_2 = 4;
d7c0a89a 13980 uint32_t metric;
d62a17ae 13981 struct bgp_redist *red;
d7c0a89a 13982 unsigned short instance;
d62a17ae 13983 int protocol;
e923dd62 13984 bool changed;
d62a17ae 13985
13986 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13987 protocol = ZEBRA_ROUTE_OSPF;
13988 else
13989 protocol = ZEBRA_ROUTE_TABLE;
13990
13991 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13992 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13993
13994 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13995 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13996 metric);
13997 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13998}
13999
14000ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
14001 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
14002 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14003 "Redistribute information from another routing protocol\n"
14004 "Open Shortest Path First (OSPFv2)\n"
14005 "Non-main Kernel Routing Table\n"
14006 "Instance ID/Table ID\n"
14007 "Metric for redistributed routes\n"
14008 "Default metric\n")
596c17ba 14009
7c8ff89e
DS
14010DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
14011 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 14012 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
14013 "Redistribute information from another routing protocol\n"
14014 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14015 "Non-main Kernel Routing Table\n"
14016 "Instance ID/Table ID\n"
7c8ff89e
DS
14017 "Route map reference\n"
14018 "Pointer to route-map entries\n"
14019 "Metric for redistributed routes\n"
14020 "Default metric\n")
14021{
d62a17ae 14022 VTY_DECLVAR_CONTEXT(bgp, bgp);
14023 int idx_ospf_table = 1;
14024 int idx_number = 2;
14025 int idx_word = 4;
14026 int idx_number_2 = 6;
d7c0a89a 14027 uint32_t metric;
d62a17ae 14028 struct bgp_redist *red;
d7c0a89a 14029 unsigned short instance;
d62a17ae 14030 int protocol;
e923dd62 14031 bool changed;
1de27621
DA
14032 struct route_map *route_map =
14033 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14034
14035 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14036 protocol = ZEBRA_ROUTE_OSPF;
14037 else
14038 protocol = ZEBRA_ROUTE_TABLE;
14039
14040 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14041 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14042
14043 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
14044 changed =
14045 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14046 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14047 metric);
14048 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14049}
14050
14051ALIAS_HIDDEN(
14052 bgp_redistribute_ipv4_ospf_rmap_metric,
14053 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
14054 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14055 "Redistribute information from another routing protocol\n"
14056 "Open Shortest Path First (OSPFv2)\n"
14057 "Non-main Kernel Routing Table\n"
14058 "Instance ID/Table ID\n"
14059 "Route map reference\n"
14060 "Pointer to route-map entries\n"
14061 "Metric for redistributed routes\n"
14062 "Default metric\n")
596c17ba 14063
7c8ff89e
DS
14064DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
14065 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 14066 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
14067 "Redistribute information from another routing protocol\n"
14068 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14069 "Non-main Kernel Routing Table\n"
14070 "Instance ID/Table ID\n"
7c8ff89e
DS
14071 "Metric for redistributed routes\n"
14072 "Default metric\n"
14073 "Route map reference\n"
14074 "Pointer to route-map entries\n")
14075{
d62a17ae 14076 VTY_DECLVAR_CONTEXT(bgp, bgp);
14077 int idx_ospf_table = 1;
14078 int idx_number = 2;
14079 int idx_number_2 = 4;
14080 int idx_word = 6;
d7c0a89a 14081 uint32_t metric;
d62a17ae 14082 struct bgp_redist *red;
d7c0a89a 14083 unsigned short instance;
d62a17ae 14084 int protocol;
e923dd62 14085 bool changed;
1de27621
DA
14086 struct route_map *route_map =
14087 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14088
14089 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14090 protocol = ZEBRA_ROUTE_OSPF;
14091 else
14092 protocol = ZEBRA_ROUTE_TABLE;
14093
14094 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14095 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14096
14097 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14098 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14099 metric);
1de27621
DA
14100 changed |=
14101 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14102 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14103}
14104
14105ALIAS_HIDDEN(
14106 bgp_redistribute_ipv4_ospf_metric_rmap,
14107 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
14108 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14109 "Redistribute information from another routing protocol\n"
14110 "Open Shortest Path First (OSPFv2)\n"
14111 "Non-main Kernel Routing Table\n"
14112 "Instance ID/Table ID\n"
14113 "Metric for redistributed routes\n"
14114 "Default metric\n"
14115 "Route map reference\n"
14116 "Pointer to route-map entries\n")
596c17ba 14117
7c8ff89e
DS
14118DEFUN (no_bgp_redistribute_ipv4_ospf,
14119 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 14120 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
14121 NO_STR
14122 "Redistribute information from another routing protocol\n"
14123 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 14124 "Non-main Kernel Routing Table\n"
31500417
DW
14125 "Instance ID/Table ID\n"
14126 "Metric for redistributed routes\n"
14127 "Default metric\n"
14128 "Route map reference\n"
14129 "Pointer to route-map entries\n")
7c8ff89e 14130{
d62a17ae 14131 VTY_DECLVAR_CONTEXT(bgp, bgp);
14132 int idx_ospf_table = 2;
14133 int idx_number = 3;
d7c0a89a 14134 unsigned short instance;
d62a17ae 14135 int protocol;
14136
14137 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14138 protocol = ZEBRA_ROUTE_OSPF;
14139 else
14140 protocol = ZEBRA_ROUTE_TABLE;
14141
14142 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14143 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
14144}
14145
14146ALIAS_HIDDEN(
14147 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 14148 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14149 NO_STR
14150 "Redistribute information from another routing protocol\n"
14151 "Open Shortest Path First (OSPFv2)\n"
14152 "Non-main Kernel Routing Table\n"
14153 "Instance ID/Table ID\n"
14154 "Metric for redistributed routes\n"
14155 "Default metric\n"
14156 "Route map reference\n"
14157 "Pointer to route-map entries\n")
596c17ba 14158
718e3744 14159DEFUN (no_bgp_redistribute_ipv4,
14160 no_bgp_redistribute_ipv4_cmd,
e27957c0 14161 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14162 NO_STR
14163 "Redistribute information from another routing protocol\n"
3b14d86e 14164 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
14165 "Metric for redistributed routes\n"
14166 "Default metric\n"
14167 "Route map reference\n"
14168 "Pointer to route-map entries\n")
718e3744 14169{
d62a17ae 14170 VTY_DECLVAR_CONTEXT(bgp, bgp);
14171 int idx_protocol = 2;
14172 int type;
14173
14174 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14175 if (type < 0) {
14176 vty_out(vty, "%% Invalid route type\n");
14177 return CMD_WARNING_CONFIG_FAILED;
14178 }
14179 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
14180}
14181
14182ALIAS_HIDDEN(
14183 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
14184 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 14185 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14186 NO_STR
14187 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14188 "Metric for redistributed routes\n"
14189 "Default metric\n"
14190 "Route map reference\n"
14191 "Pointer to route-map entries\n")
596c17ba 14192
718e3744 14193DEFUN (bgp_redistribute_ipv6,
14194 bgp_redistribute_ipv6_cmd,
40d1cbfb 14195 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 14196 "Redistribute information from another routing protocol\n"
ab0181ee 14197 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 14198{
d62a17ae 14199 VTY_DECLVAR_CONTEXT(bgp, bgp);
14200 int idx_protocol = 1;
14201 int type;
718e3744 14202
d62a17ae 14203 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14204 if (type < 0) {
14205 vty_out(vty, "%% Invalid route type\n");
14206 return CMD_WARNING_CONFIG_FAILED;
14207 }
718e3744 14208
d62a17ae 14209 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14210 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 14211}
14212
14213DEFUN (bgp_redistribute_ipv6_rmap,
14214 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 14215 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 14216 "Redistribute information from another routing protocol\n"
ab0181ee 14217 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14218 "Route map reference\n"
14219 "Pointer to route-map entries\n")
14220{
d62a17ae 14221 VTY_DECLVAR_CONTEXT(bgp, bgp);
14222 int idx_protocol = 1;
14223 int idx_word = 3;
14224 int type;
14225 struct bgp_redist *red;
e923dd62 14226 bool changed;
1de27621
DA
14227 struct route_map *route_map =
14228 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 14229
d62a17ae 14230 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14231 if (type < 0) {
14232 vty_out(vty, "%% Invalid route type\n");
14233 return CMD_WARNING_CONFIG_FAILED;
14234 }
718e3744 14235
d62a17ae 14236 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14237 changed =
14238 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14239 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14240}
14241
14242DEFUN (bgp_redistribute_ipv6_metric,
14243 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 14244 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 14245 "Redistribute information from another routing protocol\n"
ab0181ee 14246 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14247 "Metric for redistributed routes\n"
14248 "Default metric\n")
14249{
d62a17ae 14250 VTY_DECLVAR_CONTEXT(bgp, bgp);
14251 int idx_protocol = 1;
14252 int idx_number = 3;
14253 int type;
d7c0a89a 14254 uint32_t metric;
d62a17ae 14255 struct bgp_redist *red;
e923dd62 14256 bool changed;
d62a17ae 14257
14258 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14259 if (type < 0) {
14260 vty_out(vty, "%% Invalid route type\n");
14261 return CMD_WARNING_CONFIG_FAILED;
14262 }
14263 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14264
d62a17ae 14265 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14266 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
14267 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14268}
14269
14270DEFUN (bgp_redistribute_ipv6_rmap_metric,
14271 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 14272 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 14273 "Redistribute information from another routing protocol\n"
ab0181ee 14274 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14275 "Route map reference\n"
14276 "Pointer to route-map entries\n"
14277 "Metric for redistributed routes\n"
14278 "Default metric\n")
14279{
d62a17ae 14280 VTY_DECLVAR_CONTEXT(bgp, bgp);
14281 int idx_protocol = 1;
14282 int idx_word = 3;
14283 int idx_number = 5;
14284 int type;
d7c0a89a 14285 uint32_t metric;
d62a17ae 14286 struct bgp_redist *red;
e923dd62 14287 bool changed;
1de27621
DA
14288 struct route_map *route_map =
14289 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14290
14291 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14292 if (type < 0) {
14293 vty_out(vty, "%% Invalid route type\n");
14294 return CMD_WARNING_CONFIG_FAILED;
14295 }
14296 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14297
d62a17ae 14298 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14299 changed =
14300 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14301 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
14302 metric);
14303 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14304}
14305
14306DEFUN (bgp_redistribute_ipv6_metric_rmap,
14307 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 14308 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 14309 "Redistribute information from another routing protocol\n"
ab0181ee 14310 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14311 "Metric for redistributed routes\n"
14312 "Default metric\n"
14313 "Route map reference\n"
14314 "Pointer to route-map entries\n")
14315{
d62a17ae 14316 VTY_DECLVAR_CONTEXT(bgp, bgp);
14317 int idx_protocol = 1;
14318 int idx_number = 3;
14319 int idx_word = 5;
14320 int type;
d7c0a89a 14321 uint32_t metric;
d62a17ae 14322 struct bgp_redist *red;
e923dd62 14323 bool changed;
1de27621
DA
14324 struct route_map *route_map =
14325 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14326
14327 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14328 if (type < 0) {
14329 vty_out(vty, "%% Invalid route type\n");
14330 return CMD_WARNING_CONFIG_FAILED;
14331 }
14332 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14333
d62a17ae 14334 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14335 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14336 metric);
1de27621
DA
14337 changed |=
14338 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14339 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14340}
14341
14342DEFUN (no_bgp_redistribute_ipv6,
14343 no_bgp_redistribute_ipv6_cmd,
e27957c0 14344 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14345 NO_STR
14346 "Redistribute information from another routing protocol\n"
3b14d86e 14347 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
14348 "Metric for redistributed routes\n"
14349 "Default metric\n"
14350 "Route map reference\n"
14351 "Pointer to route-map entries\n")
718e3744 14352{
d62a17ae 14353 VTY_DECLVAR_CONTEXT(bgp, bgp);
14354 int idx_protocol = 2;
14355 int type;
718e3744 14356
d62a17ae 14357 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14358 if (type < 0) {
14359 vty_out(vty, "%% Invalid route type\n");
14360 return CMD_WARNING_CONFIG_FAILED;
14361 }
718e3744 14362
d62a17ae 14363 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14364}
14365
dd65f45e
DL
14366static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14367 afi_t afi, safi_t safi)
d62a17ae 14368{
14369 int i;
14370
14371 /* Unicast redistribution only. */
14372 if (safi != SAFI_UNICAST)
2b791107 14373 return;
d62a17ae 14374
14375 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14376 /* Redistribute BGP does not make sense. */
14377 if (i != ZEBRA_ROUTE_BGP) {
14378 struct list *red_list;
14379 struct listnode *node;
14380 struct bgp_redist *red;
14381
14382 red_list = bgp->redist[afi][i];
14383 if (!red_list)
14384 continue;
14385
14386 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 14387 /* "redistribute" configuration. */
14388 vty_out(vty, " redistribute %s",
14389 zebra_route_string(i));
14390 if (red->instance)
14391 vty_out(vty, " %d", red->instance);
14392 if (red->redist_metric_flag)
14393 vty_out(vty, " metric %u",
14394 red->redist_metric);
14395 if (red->rmap.name)
14396 vty_out(vty, " route-map %s",
14397 red->rmap.name);
14398 vty_out(vty, "\n");
14399 }
14400 }
14401 }
718e3744 14402}
6b0655a2 14403
dd65f45e
DL
14404/* peer-group helpers for config-write */
14405
14406static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14407{
14408 if (!peer_group_active(peer)) {
14409 if (CHECK_FLAG(peer->flags_invert, flag))
14410 return !CHECK_FLAG(peer->flags, flag);
14411 else
14412 return !!CHECK_FLAG(peer->flags, flag);
14413 }
14414
14415 return !!CHECK_FLAG(peer->flags_override, flag);
14416}
14417
14418static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14419 uint32_t flag)
14420{
14421 if (!peer_group_active(peer)) {
14422 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14423 return !peer_af_flag_check(peer, afi, safi, flag);
14424 else
14425 return !!peer_af_flag_check(peer, afi, safi, flag);
14426 }
14427
14428 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14429}
14430
14431static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14432 uint8_t type, int direct)
14433{
14434 struct bgp_filter *filter;
14435
14436 if (peer_group_active(peer))
14437 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14438 type);
14439
14440 filter = &peer->filter[afi][safi];
14441 switch (type) {
14442 case PEER_FT_DISTRIBUTE_LIST:
14443 return !!(filter->dlist[direct].name);
14444 case PEER_FT_FILTER_LIST:
14445 return !!(filter->aslist[direct].name);
14446 case PEER_FT_PREFIX_LIST:
14447 return !!(filter->plist[direct].name);
14448 case PEER_FT_ROUTE_MAP:
14449 return !!(filter->map[direct].name);
14450 case PEER_FT_UNSUPPRESS_MAP:
14451 return !!(filter->usmap.name);
14452 default:
14453 return false;
14454 }
14455}
14456
14457/* Return true if the addpath type is set for peer and different from
14458 * peer-group.
14459 */
3dc339cd
DA
14460static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
14461 safi_t safi)
dd65f45e
DL
14462{
14463 enum bgp_addpath_strat type, g_type;
14464
14465 type = peer->addpath_type[afi][safi];
14466
14467 if (type != BGP_ADDPATH_NONE) {
14468 if (peer_group_active(peer)) {
14469 g_type = peer->group->conf->addpath_type[afi][safi];
14470
14471 if (type != g_type)
3dc339cd 14472 return true;
dd65f45e 14473 else
3dc339cd 14474 return false;
dd65f45e
DL
14475 }
14476
3dc339cd 14477 return true;
dd65f45e
DL
14478 }
14479
3dc339cd 14480 return false;
dd65f45e
DL
14481}
14482
b9c7bc5a 14483/* This is part of the address-family block (unicast only) */
dd65f45e 14484static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
14485 afi_t afi)
14486{
b9c7bc5a 14487 int indent = 2;
ddb5b488 14488
8a066a70 14489 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
14490 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14491 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
14492 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14493 bgp->vpn_policy[afi]
bb4f6190 14494 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
14495 else
14496 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14497 bgp->vpn_policy[afi]
14498 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14499 }
12a844a5
DS
14500 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14501 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14502 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14503 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14504 return;
14505
e70e9f8e
PZ
14506 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14507 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14508
14509 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14510
14511 } else {
14512 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14513 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14514 bgp->vpn_policy[afi].tovpn_label);
14515 }
ddb5b488
PZ
14516 }
14517 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14518 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14519 char buf[RD_ADDRSTRLEN];
b9c7bc5a 14520 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
14521 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14522 sizeof(buf)));
14523 }
14524 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14525 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14526
14527 char buf[PREFIX_STRLEN];
14528 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14529 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14530 sizeof(buf))) {
14531
b9c7bc5a
PZ
14532 vty_out(vty, "%*snexthop vpn export %s\n",
14533 indent, "", buf);
ddb5b488
PZ
14534 }
14535 }
14536 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14537 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14538 && ecommunity_cmp(
14539 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14540 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14541
14542 char *b = ecommunity_ecom2str(
14543 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14544 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14545 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
14546 XFREE(MTYPE_ECOMMUNITY_STR, b);
14547 } else {
14548 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14549 char *b = ecommunity_ecom2str(
14550 bgp->vpn_policy[afi]
14551 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14552 ECOMMUNITY_FORMAT_ROUTE_MAP,
14553 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14554 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
14555 XFREE(MTYPE_ECOMMUNITY_STR, b);
14556 }
14557 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14558 char *b = ecommunity_ecom2str(
14559 bgp->vpn_policy[afi]
14560 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14561 ECOMMUNITY_FORMAT_ROUTE_MAP,
14562 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14563 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
14564 XFREE(MTYPE_ECOMMUNITY_STR, b);
14565 }
14566 }
bb4f6190
DS
14567
14568 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 14569 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
14570 bgp->vpn_policy[afi]
14571 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 14572
301ad80a
PG
14573 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14574 char *b = ecommunity_ecom2str(
14575 bgp->vpn_policy[afi]
14576 .import_redirect_rtlist,
14577 ECOMMUNITY_FORMAT_ROUTE_MAP,
14578 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 14579
301ad80a
PG
14580 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
14581 XFREE(MTYPE_ECOMMUNITY_STR, b);
14582 }
ddb5b488
PZ
14583}
14584
dd65f45e
DL
14585static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14586 afi_t afi, safi_t safi)
14587{
14588 struct bgp_filter *filter;
14589 char *addr;
14590
14591 addr = peer->host;
14592 filter = &peer->filter[afi][safi];
14593
14594 /* distribute-list. */
14595 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14596 FILTER_IN))
14597 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14598 filter->dlist[FILTER_IN].name);
14599
14600 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14601 FILTER_OUT))
14602 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14603 filter->dlist[FILTER_OUT].name);
14604
14605 /* prefix-list. */
14606 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14607 FILTER_IN))
14608 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14609 filter->plist[FILTER_IN].name);
14610
14611 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14612 FILTER_OUT))
14613 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14614 filter->plist[FILTER_OUT].name);
14615
14616 /* route-map. */
14617 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14618 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14619 filter->map[RMAP_IN].name);
14620
14621 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14622 RMAP_OUT))
14623 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14624 filter->map[RMAP_OUT].name);
14625
14626 /* unsuppress-map */
14627 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14628 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14629 filter->usmap.name);
14630
14631 /* filter-list. */
14632 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14633 FILTER_IN))
14634 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14635 filter->aslist[FILTER_IN].name);
14636
14637 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14638 FILTER_OUT))
14639 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14640 filter->aslist[FILTER_OUT].name);
14641}
14642
14643/* BGP peer configuration display function. */
14644static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14645 struct peer *peer)
14646{
14647 struct peer *g_peer = NULL;
14648 char buf[SU_ADDRSTRLEN];
14649 char *addr;
14650 int if_pg_printed = false;
14651 int if_ras_printed = false;
14652
14653 /* Skip dynamic neighbors. */
14654 if (peer_dynamic_neighbor(peer))
14655 return;
14656
14657 if (peer->conf_if)
14658 addr = peer->conf_if;
14659 else
14660 addr = peer->host;
14661
14662 /************************************
14663 ****** Global to the neighbor ******
14664 ************************************/
14665 if (peer->conf_if) {
14666 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14667 vty_out(vty, " neighbor %s interface v6only", addr);
14668 else
14669 vty_out(vty, " neighbor %s interface", addr);
14670
14671 if (peer_group_active(peer)) {
14672 vty_out(vty, " peer-group %s", peer->group->name);
14673 if_pg_printed = true;
14674 } else if (peer->as_type == AS_SPECIFIED) {
14675 vty_out(vty, " remote-as %u", peer->as);
14676 if_ras_printed = true;
14677 } else if (peer->as_type == AS_INTERNAL) {
14678 vty_out(vty, " remote-as internal");
14679 if_ras_printed = true;
14680 } else if (peer->as_type == AS_EXTERNAL) {
14681 vty_out(vty, " remote-as external");
14682 if_ras_printed = true;
14683 }
14684
14685 vty_out(vty, "\n");
14686 }
14687
14688 /* remote-as and peer-group */
14689 /* peer is a member of a peer-group */
14690 if (peer_group_active(peer)) {
14691 g_peer = peer->group->conf;
14692
14693 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14694 if (peer->as_type == AS_SPECIFIED) {
14695 vty_out(vty, " neighbor %s remote-as %u\n",
14696 addr, peer->as);
14697 } else if (peer->as_type == AS_INTERNAL) {
14698 vty_out(vty,
14699 " neighbor %s remote-as internal\n",
14700 addr);
14701 } else if (peer->as_type == AS_EXTERNAL) {
14702 vty_out(vty,
14703 " neighbor %s remote-as external\n",
14704 addr);
14705 }
14706 }
14707
14708 /* For swpX peers we displayed the peer-group
14709 * via 'neighbor swpX interface peer-group PGNAME' */
14710 if (!if_pg_printed)
14711 vty_out(vty, " neighbor %s peer-group %s\n", addr,
14712 peer->group->name);
14713 }
14714
14715 /* peer is NOT a member of a peer-group */
14716 else {
14717 /* peer is a peer-group, declare the peer-group */
14718 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
14719 vty_out(vty, " neighbor %s peer-group\n", addr);
14720 }
14721
14722 if (!if_ras_printed) {
14723 if (peer->as_type == AS_SPECIFIED) {
14724 vty_out(vty, " neighbor %s remote-as %u\n",
14725 addr, peer->as);
14726 } else if (peer->as_type == AS_INTERNAL) {
14727 vty_out(vty,
14728 " neighbor %s remote-as internal\n",
14729 addr);
14730 } else if (peer->as_type == AS_EXTERNAL) {
14731 vty_out(vty,
14732 " neighbor %s remote-as external\n",
14733 addr);
14734 }
14735 }
14736 }
14737
14738 /* local-as */
14739 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
14740 vty_out(vty, " neighbor %s local-as %u", addr,
14741 peer->change_local_as);
14742 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
14743 vty_out(vty, " no-prepend");
14744 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
14745 vty_out(vty, " replace-as");
14746 vty_out(vty, "\n");
14747 }
14748
14749 /* description */
14750 if (peer->desc) {
14751 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
14752 }
14753
14754 /* shutdown */
14755 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
14756 if (peer->tx_shutdown_message)
14757 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
14758 peer->tx_shutdown_message);
14759 else
14760 vty_out(vty, " neighbor %s shutdown\n", addr);
14761 }
14762
14763 /* bfd */
14764 if (peer->bfd_info) {
14765 if (!peer_group_active(peer) || !g_peer->bfd_info) {
14766 bgp_bfd_peer_config_write(vty, peer, addr);
14767 }
14768 }
14769
14770 /* password */
14771 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
14772 vty_out(vty, " neighbor %s password %s\n", addr,
14773 peer->password);
14774
14775 /* neighbor solo */
14776 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
14777 if (!peer_group_active(peer)) {
14778 vty_out(vty, " neighbor %s solo\n", addr);
14779 }
14780 }
14781
14782 /* BGP port */
14783 if (peer->port != BGP_PORT_DEFAULT) {
14784 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
14785 }
14786
14787 /* Local interface name */
14788 if (peer->ifname) {
14789 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
14790 }
14791
14792 /* passive */
14793 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
14794 vty_out(vty, " neighbor %s passive\n", addr);
14795
14796 /* ebgp-multihop */
14797 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
14798 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
14799 && peer->ttl == MAXTTL)) {
dd65f45e
DL
14800 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
14801 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
14802 peer->ttl);
14803 }
14804 }
14805
14806 /* ttl-security hops */
e2521429 14807 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
14808 if (!peer_group_active(peer)
14809 || g_peer->gtsm_hops != peer->gtsm_hops) {
14810 vty_out(vty, " neighbor %s ttl-security hops %d\n",
14811 addr, peer->gtsm_hops);
14812 }
14813 }
14814
14815 /* disable-connected-check */
14816 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
14817 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
14818
14819 /* enforce-first-as */
14820 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
14821 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
14822
14823 /* update-source */
14824 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
14825 if (peer->update_source)
14826 vty_out(vty, " neighbor %s update-source %s\n", addr,
14827 sockunion2str(peer->update_source, buf,
14828 SU_ADDRSTRLEN));
14829 else if (peer->update_if)
14830 vty_out(vty, " neighbor %s update-source %s\n", addr,
14831 peer->update_if);
14832 }
14833
14834 /* advertisement-interval */
14835 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
14836 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
14837 peer->routeadv);
14838
14839 /* timers */
14840 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
14841 vty_out(vty, " neighbor %s timers %u %u\n", addr,
14842 peer->keepalive, peer->holdtime);
14843
14844 /* timers connect */
14845 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
14846 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14847 peer->connect);
5d5393b9
DL
14848 /* need special-case handling for changed default values due to
14849 * config profile / version (because there is no "timers bgp connect"
14850 * command, we need to save this per-peer :/)
14851 */
14852 else if (!peer_group_active(peer) && !peer->connect &&
14853 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
14854 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14855 peer->bgp->default_connect_retry);
dd65f45e
DL
14856
14857 /* capability dynamic */
14858 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
14859 vty_out(vty, " neighbor %s capability dynamic\n", addr);
14860
14861 /* capability extended-nexthop */
14862 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
14863 if (!peer->conf_if) {
14864 if (CHECK_FLAG(peer->flags_invert,
14865 PEER_FLAG_CAPABILITY_ENHE))
14866 vty_out(vty,
14867 " no neighbor %s capability extended-nexthop\n",
14868 addr);
14869 else
14870 vty_out(vty,
14871 " neighbor %s capability extended-nexthop\n",
14872 addr);
14873 }
14874 }
14875
14876 /* dont-capability-negotiation */
14877 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
14878 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
14879
14880 /* override-capability */
14881 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
14882 vty_out(vty, " neighbor %s override-capability\n", addr);
14883
14884 /* strict-capability-match */
14885 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
14886 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
14887
14888 /* Sender side AS path loop detection. */
14889 if (peer->as_path_loop_detection)
14890 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
14891 addr);
cfd47646 14892
14893 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14894 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 14895
14896 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14897 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 14898 vty_out(vty,
14899 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
14900 } else if (CHECK_FLAG(
14901 peer->peer_gr_new_status_flag,
14902 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 14903 vty_out(vty,
14904 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
14905 } else if (
14906 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
14907 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
14908 && !(CHECK_FLAG(
14909 peer->peer_gr_new_status_flag,
14910 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
14911 vty_out(vty, " neighbor %s graceful-restart-disable\n",
14912 addr);
cfd47646 14913 }
14914 }
dd65f45e
DL
14915}
14916
14917/* BGP peer configuration display function. */
14918static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
14919 struct peer *peer, afi_t afi, safi_t safi)
14920{
14921 struct peer *g_peer = NULL;
14922 char *addr;
14923 bool flag_scomm, flag_secomm, flag_slcomm;
14924
14925 /* Skip dynamic neighbors. */
14926 if (peer_dynamic_neighbor(peer))
14927 return;
14928
14929 if (peer->conf_if)
14930 addr = peer->conf_if;
14931 else
14932 addr = peer->host;
14933
14934 /************************************
14935 ****** Per AF to the neighbor ******
14936 ************************************/
14937 if (peer_group_active(peer)) {
14938 g_peer = peer->group->conf;
14939
14940 /* If the peer-group is active but peer is not, print a 'no
14941 * activate' */
14942 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
14943 vty_out(vty, " no neighbor %s activate\n", addr);
14944 }
14945
14946 /* If the peer-group is not active but peer is, print an
14947 'activate' */
14948 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
14949 vty_out(vty, " neighbor %s activate\n", addr);
14950 }
14951 } else {
14952 if (peer->afc[afi][safi]) {
14953 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
14954 if (CHECK_FLAG(bgp->flags,
14955 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
14956 vty_out(vty, " neighbor %s activate\n",
14957 addr);
14958 }
14959 } else
14960 vty_out(vty, " neighbor %s activate\n", addr);
14961 } else {
14962 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
14963 if (!CHECK_FLAG(bgp->flags,
14964 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
14965 vty_out(vty,
14966 " no neighbor %s activate\n",
14967 addr);
14968 }
14969 }
14970 }
14971 }
14972
14973 /* addpath TX knobs */
14974 if (peergroup_af_addpath_check(peer, afi, safi)) {
14975 switch (peer->addpath_type[afi][safi]) {
14976 case BGP_ADDPATH_ALL:
14977 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
14978 addr);
14979 break;
14980 case BGP_ADDPATH_BEST_PER_AS:
14981 vty_out(vty,
14982 " neighbor %s addpath-tx-bestpath-per-AS\n",
14983 addr);
14984 break;
14985 case BGP_ADDPATH_MAX:
14986 case BGP_ADDPATH_NONE:
14987 break;
14988 }
14989 }
14990
14991 /* ORF capability. */
14992 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
14993 || peergroup_af_flag_check(peer, afi, safi,
14994 PEER_FLAG_ORF_PREFIX_RM)) {
14995 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
14996
14997 if (peergroup_af_flag_check(peer, afi, safi,
14998 PEER_FLAG_ORF_PREFIX_SM)
14999 && peergroup_af_flag_check(peer, afi, safi,
15000 PEER_FLAG_ORF_PREFIX_RM))
15001 vty_out(vty, " both");
15002 else if (peergroup_af_flag_check(peer, afi, safi,
15003 PEER_FLAG_ORF_PREFIX_SM))
15004 vty_out(vty, " send");
15005 else
15006 vty_out(vty, " receive");
15007 vty_out(vty, "\n");
15008 }
15009
dd65f45e
DL
15010 /* Route reflector client. */
15011 if (peergroup_af_flag_check(peer, afi, safi,
15012 PEER_FLAG_REFLECTOR_CLIENT)) {
15013 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
15014 }
15015
15016 /* next-hop-self force */
15017 if (peergroup_af_flag_check(peer, afi, safi,
15018 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
15019 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
15020 }
15021
15022 /* next-hop-self */
15023 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
15024 vty_out(vty, " neighbor %s next-hop-self\n", addr);
15025 }
15026
15027 /* remove-private-AS */
15028 if (peergroup_af_flag_check(peer, afi, safi,
15029 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
15030 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
15031 addr);
15032 }
15033
15034 else if (peergroup_af_flag_check(peer, afi, safi,
15035 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
15036 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
15037 addr);
15038 }
15039
15040 else if (peergroup_af_flag_check(peer, afi, safi,
15041 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
15042 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
15043 }
15044
15045 else if (peergroup_af_flag_check(peer, afi, safi,
15046 PEER_FLAG_REMOVE_PRIVATE_AS)) {
15047 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
15048 }
15049
15050 /* as-override */
15051 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
15052 vty_out(vty, " neighbor %s as-override\n", addr);
15053 }
15054
15055 /* send-community print. */
15056 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
15057 PEER_FLAG_SEND_COMMUNITY);
15058 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
15059 PEER_FLAG_SEND_EXT_COMMUNITY);
15060 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
15061 PEER_FLAG_SEND_LARGE_COMMUNITY);
15062
15063 if (flag_scomm && flag_secomm && flag_slcomm) {
15064 vty_out(vty, " no neighbor %s send-community all\n", addr);
15065 } else {
15066 if (flag_scomm)
15067 vty_out(vty, " no neighbor %s send-community\n", addr);
15068 if (flag_secomm)
15069 vty_out(vty,
15070 " no neighbor %s send-community extended\n",
15071 addr);
15072
15073 if (flag_slcomm)
15074 vty_out(vty, " no neighbor %s send-community large\n",
15075 addr);
15076 }
15077
15078 /* Default information */
15079 if (peergroup_af_flag_check(peer, afi, safi,
15080 PEER_FLAG_DEFAULT_ORIGINATE)) {
15081 vty_out(vty, " neighbor %s default-originate", addr);
15082
15083 if (peer->default_rmap[afi][safi].name)
15084 vty_out(vty, " route-map %s",
15085 peer->default_rmap[afi][safi].name);
15086
15087 vty_out(vty, "\n");
15088 }
15089
15090 /* Soft reconfiguration inbound. */
15091 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
15092 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
15093 addr);
15094 }
15095
15096 /* maximum-prefix. */
15097 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 15098 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
15099 peer->pmax[afi][safi]);
15100
15101 if (peer->pmax_threshold[afi][safi]
15102 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
15103 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
15104 if (peer_af_flag_check(peer, afi, safi,
15105 PEER_FLAG_MAX_PREFIX_WARNING))
15106 vty_out(vty, " warning-only");
15107 if (peer->pmax_restart[afi][safi])
15108 vty_out(vty, " restart %u",
15109 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
15110 if (peer_af_flag_check(peer, afi, safi,
15111 PEER_FLAG_MAX_PREFIX_FORCE))
15112 vty_out(vty, " force");
dd65f45e
DL
15113
15114 vty_out(vty, "\n");
15115 }
15116
fde246e8
DA
15117 /* maximum-prefix-out */
15118 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 15119 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
15120 addr, peer->pmax_out[afi][safi]);
15121
dd65f45e
DL
15122 /* Route server client. */
15123 if (peergroup_af_flag_check(peer, afi, safi,
15124 PEER_FLAG_RSERVER_CLIENT)) {
15125 vty_out(vty, " neighbor %s route-server-client\n", addr);
15126 }
15127
15128 /* Nexthop-local unchanged. */
15129 if (peergroup_af_flag_check(peer, afi, safi,
15130 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
15131 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
15132 }
15133
15134 /* allowas-in <1-10> */
15135 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
15136 if (peer_af_flag_check(peer, afi, safi,
15137 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
15138 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
15139 } else if (peer->allowas_in[afi][safi] == 3) {
15140 vty_out(vty, " neighbor %s allowas-in\n", addr);
15141 } else {
15142 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
15143 peer->allowas_in[afi][safi]);
15144 }
15145 }
15146
15147 /* weight */
15148 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
15149 vty_out(vty, " neighbor %s weight %lu\n", addr,
15150 peer->weight[afi][safi]);
15151
15152 /* Filter. */
15153 bgp_config_write_filter(vty, peer, afi, safi);
15154
15155 /* atribute-unchanged. */
15156 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
15157 || (safi != SAFI_EVPN
15158 && peer_af_flag_check(peer, afi, safi,
15159 PEER_FLAG_NEXTHOP_UNCHANGED))
15160 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
15161
15162 if (!peer_group_active(peer)
15163 || peergroup_af_flag_check(peer, afi, safi,
15164 PEER_FLAG_AS_PATH_UNCHANGED)
15165 || peergroup_af_flag_check(peer, afi, safi,
15166 PEER_FLAG_NEXTHOP_UNCHANGED)
15167 || peergroup_af_flag_check(peer, afi, safi,
15168 PEER_FLAG_MED_UNCHANGED)) {
15169
15170 vty_out(vty,
15171 " neighbor %s attribute-unchanged%s%s%s\n",
15172 addr,
15173 peer_af_flag_check(peer, afi, safi,
15174 PEER_FLAG_AS_PATH_UNCHANGED)
15175 ? " as-path"
15176 : "",
15177 peer_af_flag_check(peer, afi, safi,
15178 PEER_FLAG_NEXTHOP_UNCHANGED)
15179 ? " next-hop"
15180 : "",
15181 peer_af_flag_check(peer, afi, safi,
15182 PEER_FLAG_MED_UNCHANGED)
15183 ? " med"
15184 : "");
15185 }
15186 }
15187}
15188
15189/* Address family based peer configuration display. */
15190static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
15191 safi_t safi)
15192{
15193 struct peer *peer;
15194 struct peer_group *group;
15195 struct listnode *node, *nnode;
15196
15197
15198 vty_frame(vty, " !\n address-family ");
15199 if (afi == AFI_IP) {
15200 if (safi == SAFI_UNICAST)
15201 vty_frame(vty, "ipv4 unicast");
15202 else if (safi == SAFI_LABELED_UNICAST)
15203 vty_frame(vty, "ipv4 labeled-unicast");
15204 else if (safi == SAFI_MULTICAST)
15205 vty_frame(vty, "ipv4 multicast");
15206 else if (safi == SAFI_MPLS_VPN)
15207 vty_frame(vty, "ipv4 vpn");
15208 else if (safi == SAFI_ENCAP)
15209 vty_frame(vty, "ipv4 encap");
15210 else if (safi == SAFI_FLOWSPEC)
15211 vty_frame(vty, "ipv4 flowspec");
15212 } else if (afi == AFI_IP6) {
15213 if (safi == SAFI_UNICAST)
15214 vty_frame(vty, "ipv6 unicast");
15215 else if (safi == SAFI_LABELED_UNICAST)
15216 vty_frame(vty, "ipv6 labeled-unicast");
15217 else if (safi == SAFI_MULTICAST)
15218 vty_frame(vty, "ipv6 multicast");
15219 else if (safi == SAFI_MPLS_VPN)
15220 vty_frame(vty, "ipv6 vpn");
15221 else if (safi == SAFI_ENCAP)
15222 vty_frame(vty, "ipv6 encap");
15223 else if (safi == SAFI_FLOWSPEC)
15224 vty_frame(vty, "ipv6 flowspec");
15225 } else if (afi == AFI_L2VPN) {
15226 if (safi == SAFI_EVPN)
15227 vty_frame(vty, "l2vpn evpn");
15228 }
15229 vty_frame(vty, "\n");
15230
15231 bgp_config_write_distance(vty, bgp, afi, safi);
15232
15233 bgp_config_write_network(vty, bgp, afi, safi);
15234
15235 bgp_config_write_redistribute(vty, bgp, afi, safi);
15236
8a4e7fe6
DA
15237 /* BGP flag dampening. */
15238 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
15239 bgp_config_write_damp(vty, afi, safi);
15240
dd65f45e
DL
15241 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
15242 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
15243
15244 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15245 /* Skip dynamic neighbors. */
15246 if (peer_dynamic_neighbor(peer))
15247 continue;
15248
15249 /* Do not display doppelganger peers */
15250 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15251 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
15252 }
15253
15254 bgp_config_write_maxpaths(vty, bgp, afi, safi);
15255 bgp_config_write_table_map(vty, bgp, afi, safi);
15256
15257 if (safi == SAFI_EVPN)
15258 bgp_config_write_evpn_info(vty, bgp, afi, safi);
15259
15260 if (safi == SAFI_FLOWSPEC)
15261 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
15262
15263 if (safi == SAFI_UNICAST) {
15264 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
15265 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15266 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
15267
15268 vty_out(vty, " export vpn\n");
15269 }
15270 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15271 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
15272
15273 vty_out(vty, " import vpn\n");
15274 }
15275 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15276 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15277 char *name;
15278
15279 for (ALL_LIST_ELEMENTS_RO(
15280 bgp->vpn_policy[afi].import_vrf, node,
15281 name))
15282 vty_out(vty, " import vrf %s\n", name);
15283 }
15284 }
15285
15286 vty_endframe(vty, " exit-address-family\n");
15287}
15288
15289int bgp_config_write(struct vty *vty)
15290{
15291 struct bgp *bgp;
15292 struct peer_group *group;
15293 struct peer *peer;
15294 struct listnode *node, *nnode;
15295 struct listnode *mnode, *mnnode;
15296
15297 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
15298 vty_out(vty, "bgp route-map delay-timer %u\n",
15299 bm->rmap_update_timer);
15300
15301 /* BGP configuration. */
15302 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
15303
15304 /* skip all auto created vrf as they dont have user config */
15305 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
15306 continue;
15307
15308 /* Router bgp ASN */
15309 vty_out(vty, "router bgp %u", bgp->as);
15310
15311 if (bgp->name)
15312 vty_out(vty, " %s %s",
15313 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
15314 ? "view" : "vrf", bgp->name);
15315 vty_out(vty, "\n");
15316
15317 /* BGP fast-external-failover. */
15318 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
15319 vty_out(vty, " no bgp fast-external-failover\n");
15320
15321 /* BGP router ID. */
15322 if (bgp->router_id_static.s_addr != 0)
15323 vty_out(vty, " bgp router-id %s\n",
15324 inet_ntoa(bgp->router_id_static));
15325
15326 /* BGP log-neighbor-changes. */
892fedb6 15327 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 15328 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 15329 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
15330 CHECK_FLAG(bgp->flags,
15331 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
15332 ? ""
15333 : "no ");
15334
15335 /* BGP configuration. */
892fedb6 15336 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
15337 vty_out(vty, " bgp always-compare-med\n");
15338
15339 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
15340 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
15341 != SAVE_BGP_EBGP_REQUIRES_POLICY)
15342 vty_out(vty, " %sbgp ebgp-requires-policy\n",
15343 CHECK_FLAG(bgp->flags,
15344 BGP_FLAG_EBGP_REQUIRES_POLICY)
15345 ? ""
15346 : "no ");
dd65f45e
DL
15347
15348 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 15349 if (bgp->reject_as_sets)
dd65f45e
DL
15350 vty_out(vty, " bgp reject-as-sets\n");
15351
15352 /* BGP default ipv4-unicast. */
892fedb6 15353 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
15354 vty_out(vty, " no bgp default ipv4-unicast\n");
15355
15356 /* BGP default local-preference. */
15357 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15358 vty_out(vty, " bgp default local-preference %u\n",
15359 bgp->default_local_pref);
15360
15361 /* BGP default show-hostname */
892fedb6 15362 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 15363 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 15364 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 15365 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
15366 ? ""
15367 : "no ");
15368
aef999a2
DA
15369 /* BGP default show-nexthop-hostname */
15370 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15371 != SAVE_BGP_SHOW_HOSTNAME)
15372 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
15373 CHECK_FLAG(bgp->flags,
15374 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15375 ? ""
15376 : "no ");
15377
dd65f45e
DL
15378 /* BGP default subgroup-pkt-queue-max. */
15379 if (bgp->default_subgroup_pkt_queue_max
15380 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15381 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15382 bgp->default_subgroup_pkt_queue_max);
15383
15384 /* BGP client-to-client reflection. */
892fedb6 15385 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
15386 vty_out(vty, " no bgp client-to-client reflection\n");
15387
15388 /* BGP cluster ID. */
15389 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15390 vty_out(vty, " bgp cluster-id %s\n",
15391 inet_ntoa(bgp->cluster_id));
15392
15393 /* Disable ebgp connected nexthop check */
892fedb6 15394 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
15395 vty_out(vty,
15396 " bgp disable-ebgp-connected-route-check\n");
15397
15398 /* Confederation identifier*/
15399 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15400 vty_out(vty, " bgp confederation identifier %u\n",
15401 bgp->confed_id);
15402
15403 /* Confederation peer */
15404 if (bgp->confed_peers_cnt > 0) {
15405 int i;
15406
15407 vty_out(vty, " bgp confederation peers");
15408
15409 for (i = 0; i < bgp->confed_peers_cnt; i++)
15410 vty_out(vty, " %u", bgp->confed_peers[i]);
15411
15412 vty_out(vty, "\n");
15413 }
15414
15415 /* BGP deterministic-med. */
892fedb6 15416 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 15417 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 15418 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
15419 CHECK_FLAG(bgp->flags,
15420 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
15421 ? ""
15422 : "no ");
15423
15424 /* BGP update-delay. */
15425 bgp_config_write_update_delay(vty, bgp);
15426
15427 if (bgp->v_maxmed_onstartup
15428 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15429 vty_out(vty, " bgp max-med on-startup %u",
15430 bgp->v_maxmed_onstartup);
15431 if (bgp->maxmed_onstartup_value
15432 != BGP_MAXMED_VALUE_DEFAULT)
15433 vty_out(vty, " %u",
15434 bgp->maxmed_onstartup_value);
15435 vty_out(vty, "\n");
15436 }
15437 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15438 vty_out(vty, " bgp max-med administrative");
15439 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15440 vty_out(vty, " %u", bgp->maxmed_admin_value);
15441 vty_out(vty, "\n");
15442 }
15443
15444 /* write quanta */
15445 bgp_config_write_wpkt_quanta(vty, bgp);
15446 /* read quanta */
15447 bgp_config_write_rpkt_quanta(vty, bgp);
15448
15449 /* coalesce time */
15450 bgp_config_write_coalesce_time(vty, bgp);
15451
15452 /* BGP graceful-restart. */
15453 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15454 vty_out(vty,
15455 " bgp graceful-restart stalepath-time %u\n",
15456 bgp->stalepath_time);
cfd47646 15457
dd65f45e
DL
15458 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15459 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15460 bgp->restart_time);
cfd47646 15461
15462 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15463 vty_out(vty,
15464 " bgp graceful-restart select-defer-time %u\n",
15465 bgp->select_defer_time);
15466
15467 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
15468 vty_out(vty, " bgp graceful-restart\n");
15469
cfd47646 15470 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15471 vty_out(vty, " bgp graceful-restart-disable\n");
15472
dd65f45e 15473 /* BGP graceful-shutdown */
892fedb6 15474 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
dd65f45e
DL
15475 vty_out(vty, " bgp graceful-shutdown\n");
15476
15477 /* BGP graceful-restart Preserve State F bit. */
892fedb6 15478 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
15479 vty_out(vty,
15480 " bgp graceful-restart preserve-fw-state\n");
15481
dc95985f 15482 /* Stale timer for RIB */
15483 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15484 vty_out(vty,
15485 " bgp graceful-restart rib-stale-time %u\n",
15486 bgp->rib_stale_time);
15487
dd65f45e 15488 /* BGP bestpath method. */
892fedb6 15489 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 15490 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 15491 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
15492 vty_out(vty, " bgp bestpath as-path confed\n");
15493
892fedb6
DA
15494 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15495 if (CHECK_FLAG(bgp->flags,
15496 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
15497 vty_out(vty,
15498 " bgp bestpath as-path multipath-relax as-set\n");
15499 } else {
15500 vty_out(vty,
15501 " bgp bestpath as-path multipath-relax\n");
15502 }
15503 }
15504
892fedb6 15505 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
15506 vty_out(vty,
15507 " bgp route-reflector allow-outbound-policy\n");
15508 }
892fedb6 15509 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 15510 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
15511 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
15512 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 15513 vty_out(vty, " bgp bestpath med");
892fedb6 15514 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 15515 vty_out(vty, " confed");
892fedb6
DA
15516 if (CHECK_FLAG(bgp->flags,
15517 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
15518 vty_out(vty, " missing-as-worst");
15519 vty_out(vty, "\n");
15520 }
15521
f7e1c681 15522 /* Link bandwidth handling. */
15523 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
15524 vty_out(vty, " bgp bestpath bandwidth ignore\n");
15525 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
15526 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
15527 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
15528 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
15529
dd65f45e 15530 /* BGP network import check. */
892fedb6 15531 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 15532 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 15533 vty_out(vty, " %sbgp network import-check\n",
892fedb6 15534 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
15535 ? ""
15536 : "no ");
15537
15538 /* BGP timers configuration. */
5d5393b9
DL
15539 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15540 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
15541 vty_out(vty, " timers bgp %u %u\n",
15542 bgp->default_keepalive, bgp->default_holdtime);
15543
15544 /* peer-group */
15545 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15546 bgp_config_write_peer_global(vty, bgp, group->conf);
15547 }
15548
15549 /* Normal neighbor configuration. */
15550 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15551 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15552 bgp_config_write_peer_global(vty, bgp, peer);
15553 }
15554
15555 /* listen range and limit for dynamic BGP neighbors */
15556 bgp_config_write_listen(vty, bgp);
15557
15558 /*
15559 * BGP default autoshutdown neighbors
15560 *
15561 * This must be placed after any peer and peer-group
15562 * configuration, to avoid setting all peers to shutdown after
15563 * a daemon restart, which is undesired behavior. (see #2286)
15564 */
15565 if (bgp->autoshutdown)
15566 vty_out(vty, " bgp default shutdown\n");
15567
15568 /* IPv4 unicast configuration. */
15569 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15570
15571 /* IPv4 multicast configuration. */
15572 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15573
15574 /* IPv4 labeled-unicast configuration. */
15575 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15576
15577 /* IPv4 VPN configuration. */
15578 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15579
15580 /* ENCAPv4 configuration. */
15581 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15582
15583 /* FLOWSPEC v4 configuration. */
15584 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15585
15586 /* IPv6 unicast configuration. */
15587 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15588
15589 /* IPv6 multicast configuration. */
15590 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15591
15592 /* IPv6 labeled-unicast configuration. */
15593 bgp_config_write_family(vty, bgp, AFI_IP6,
15594 SAFI_LABELED_UNICAST);
15595
15596 /* IPv6 VPN configuration. */
15597 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15598
15599 /* ENCAPv6 configuration. */
15600 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15601
15602 /* FLOWSPEC v6 configuration. */
15603 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15604
15605 /* EVPN configuration. */
15606 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15607
15608 hook_call(bgp_inst_config_write, bgp, vty);
15609
49e5a4a0 15610#ifdef ENABLE_BGP_VNC
dd65f45e
DL
15611 bgp_rfapi_cfg_write(vty, bgp);
15612#endif
15613
15614 vty_out(vty, "!\n");
15615 }
15616 return 0;
15617}
15618
ddb5b488 15619
718e3744 15620/* BGP node structure. */
d62a17ae 15621static struct cmd_node bgp_node = {
f4b8291f 15622 .name = "bgp",
62b346ee 15623 .node = BGP_NODE,
24389580 15624 .parent_node = CONFIG_NODE,
62b346ee 15625 .prompt = "%s(config-router)# ",
612c2c15 15626 .config_write = bgp_config_write,
718e3744 15627};
15628
d62a17ae 15629static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 15630 .name = "bgp ipv4 unicast",
62b346ee 15631 .node = BGP_IPV4_NODE,
24389580 15632 .parent_node = BGP_NODE,
62b346ee 15633 .prompt = "%s(config-router-af)# ",
718e3744 15634};
15635
d62a17ae 15636static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 15637 .name = "bgp ipv4 multicast",
62b346ee 15638 .node = BGP_IPV4M_NODE,
24389580 15639 .parent_node = BGP_NODE,
62b346ee 15640 .prompt = "%s(config-router-af)# ",
718e3744 15641};
15642
d62a17ae 15643static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 15644 .name = "bgp ipv4 labeled unicast",
62b346ee 15645 .node = BGP_IPV4L_NODE,
24389580 15646 .parent_node = BGP_NODE,
62b346ee 15647 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
15648};
15649
d62a17ae 15650static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 15651 .name = "bgp ipv6",
62b346ee 15652 .node = BGP_IPV6_NODE,
24389580 15653 .parent_node = BGP_NODE,
62b346ee 15654 .prompt = "%s(config-router-af)# ",
718e3744 15655};
15656
d62a17ae 15657static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 15658 .name = "bgp ipv6 multicast",
62b346ee 15659 .node = BGP_IPV6M_NODE,
24389580 15660 .parent_node = BGP_NODE,
62b346ee 15661 .prompt = "%s(config-router-af)# ",
25ffbdc1 15662};
15663
d62a17ae 15664static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 15665 .name = "bgp ipv6 labeled unicast",
62b346ee 15666 .node = BGP_IPV6L_NODE,
24389580 15667 .parent_node = BGP_NODE,
62b346ee 15668 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
15669};
15670
62b346ee 15671static struct cmd_node bgp_vpnv4_node = {
f4b8291f 15672 .name = "bgp vpnv4",
62b346ee 15673 .node = BGP_VPNV4_NODE,
24389580 15674 .parent_node = BGP_NODE,
62b346ee 15675 .prompt = "%s(config-router-af)# ",
62b346ee 15676};
6b0655a2 15677
62b346ee 15678static struct cmd_node bgp_vpnv6_node = {
f4b8291f 15679 .name = "bgp vpnv6",
62b346ee 15680 .node = BGP_VPNV6_NODE,
24389580 15681 .parent_node = BGP_NODE,
62b346ee 15682 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 15683};
8ecd3266 15684
62b346ee 15685static struct cmd_node bgp_evpn_node = {
f4b8291f 15686 .name = "bgp evpn",
62b346ee 15687 .node = BGP_EVPN_NODE,
24389580 15688 .parent_node = BGP_NODE,
62b346ee 15689 .prompt = "%s(config-router-evpn)# ",
62b346ee 15690};
4e0b7b6d 15691
62b346ee 15692static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 15693 .name = "bgp evpn vni",
62b346ee 15694 .node = BGP_EVPN_VNI_NODE,
24389580 15695 .parent_node = BGP_EVPN_NODE,
62b346ee 15696 .prompt = "%s(config-router-af-vni)# ",
62b346ee 15697};
90e60aa7 15698
62b346ee 15699static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 15700 .name = "bgp ipv4 flowspec",
62b346ee 15701 .node = BGP_FLOWSPECV4_NODE,
24389580 15702 .parent_node = BGP_NODE,
62b346ee 15703 .prompt = "%s(config-router-af)# ",
62b346ee 15704};
7c40bf39 15705
62b346ee 15706static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 15707 .name = "bgp ipv6 flowspec",
62b346ee 15708 .node = BGP_FLOWSPECV6_NODE,
24389580 15709 .parent_node = BGP_NODE,
62b346ee 15710 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 15711};
7c40bf39 15712
d62a17ae 15713static void community_list_vty(void);
1f8ae70b 15714
d62a17ae 15715static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 15716{
d62a17ae 15717 struct bgp *bgp;
15718 struct peer *peer;
d62a17ae 15719 struct listnode *lnbgp, *lnpeer;
b8a815e5 15720
d62a17ae 15721 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15722 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
15723 /* only provide suggestions on the appropriate input
15724 * token type,
15725 * they'll otherwise show up multiple times */
15726 enum cmd_token_type match_type;
15727 char *name = peer->host;
d48ed3e0 15728
d62a17ae 15729 if (peer->conf_if) {
15730 match_type = VARIABLE_TKN;
15731 name = peer->conf_if;
15732 } else if (strchr(peer->host, ':'))
15733 match_type = IPV6_TKN;
15734 else
15735 match_type = IPV4_TKN;
d48ed3e0 15736
d62a17ae 15737 if (token->type != match_type)
15738 continue;
d48ed3e0 15739
d62a17ae 15740 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
15741 }
d62a17ae 15742 }
b8a815e5
DL
15743}
15744
15745static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 15746 {.varname = "neighbor", .completions = bgp_ac_neighbor},
15747 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 15748 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 15749 {.completions = NULL}};
15750
47a306a0
DS
15751static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
15752{
15753 struct bgp *bgp;
15754 struct peer_group *group;
15755 struct listnode *lnbgp, *lnpeer;
15756
15757 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15758 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
15759 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
15760 group->name));
15761 }
15762}
15763
15764static const struct cmd_variable_handler bgp_var_peergroup[] = {
15765 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
15766 {.completions = NULL} };
15767
d62a17ae 15768void bgp_vty_init(void)
15769{
15770 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 15771 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 15772
15773 /* Install bgp top node. */
612c2c15
DL
15774 install_node(&bgp_node);
15775 install_node(&bgp_ipv4_unicast_node);
15776 install_node(&bgp_ipv4_multicast_node);
15777 install_node(&bgp_ipv4_labeled_unicast_node);
15778 install_node(&bgp_ipv6_unicast_node);
15779 install_node(&bgp_ipv6_multicast_node);
15780 install_node(&bgp_ipv6_labeled_unicast_node);
15781 install_node(&bgp_vpnv4_node);
15782 install_node(&bgp_vpnv6_node);
15783 install_node(&bgp_evpn_node);
15784 install_node(&bgp_evpn_vni_node);
15785 install_node(&bgp_flowspecv4_node);
15786 install_node(&bgp_flowspecv6_node);
d62a17ae 15787
15788 /* Install default VTY commands to new nodes. */
15789 install_default(BGP_NODE);
15790 install_default(BGP_IPV4_NODE);
15791 install_default(BGP_IPV4M_NODE);
15792 install_default(BGP_IPV4L_NODE);
15793 install_default(BGP_IPV6_NODE);
15794 install_default(BGP_IPV6M_NODE);
15795 install_default(BGP_IPV6L_NODE);
15796 install_default(BGP_VPNV4_NODE);
15797 install_default(BGP_VPNV6_NODE);
7c40bf39 15798 install_default(BGP_FLOWSPECV4_NODE);
15799 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 15800 install_default(BGP_EVPN_NODE);
15801 install_default(BGP_EVPN_VNI_NODE);
15802
8029b216
AK
15803 /* "bgp local-mac" hidden commands. */
15804 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
15805 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
15806
d62a17ae 15807 /* bgp route-map delay-timer commands. */
15808 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
15809 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15810
15811 /* Dummy commands (Currently not supported) */
15812 install_element(BGP_NODE, &no_synchronization_cmd);
15813 install_element(BGP_NODE, &no_auto_summary_cmd);
15814
15815 /* "router bgp" commands. */
15816 install_element(CONFIG_NODE, &router_bgp_cmd);
15817
15818 /* "no router bgp" commands. */
15819 install_element(CONFIG_NODE, &no_router_bgp_cmd);
15820
15821 /* "bgp router-id" commands. */
15822 install_element(BGP_NODE, &bgp_router_id_cmd);
15823 install_element(BGP_NODE, &no_bgp_router_id_cmd);
15824
15825 /* "bgp cluster-id" commands. */
15826 install_element(BGP_NODE, &bgp_cluster_id_cmd);
15827 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
15828
15829 /* "bgp confederation" commands. */
15830 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
15831 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
15832
15833 /* "bgp confederation peers" commands. */
15834 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
15835 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
15836
15837 /* bgp max-med command */
15838 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
15839 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
15840 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
15841 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
15842 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
15843
15844 /* bgp disable-ebgp-connected-nh-check */
15845 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
15846 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
15847
15848 /* bgp update-delay command */
15849 install_element(BGP_NODE, &bgp_update_delay_cmd);
15850 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
15851 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
15852
15853 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 15854 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 15855
15856 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
15857 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
15858
15859 /* "maximum-paths" commands. */
15860 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
15861 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
15862 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
15863 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
15864 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
15865 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
15866 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
15867 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
15868 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
15869 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
15870 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15871 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
15872 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
15873 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15874 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
15875
39edabac
PG
15876 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
15877 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
15878 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
15879 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15880 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 15881 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
15882 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
15883 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
15884 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15885 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15886
15887 /* "timers bgp" commands. */
15888 install_element(BGP_NODE, &bgp_timers_cmd);
15889 install_element(BGP_NODE, &no_bgp_timers_cmd);
15890
15891 /* route-map delay-timer commands - per instance for backwards compat.
15892 */
15893 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
15894 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15895
15896 /* "bgp client-to-client reflection" commands */
15897 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
15898 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
15899
15900 /* "bgp always-compare-med" commands */
15901 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
15902 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
15903
9dac9fc8
DA
15904 /* bgp ebgp-requires-policy */
15905 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
15906 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
15907
fb29348a
DA
15908 /* bgp reject-as-sets */
15909 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
15910 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
15911
d62a17ae 15912 /* "bgp deterministic-med" commands */
15913 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
15914 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
15915
055679e9 15916 /* "bgp graceful-restart" command */
36235319
QY
15917 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
15918 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 15919
15920 /* "bgp graceful-restart-disable" command */
36235319
QY
15921 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
15922 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 15923
15924 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
15925 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
15926 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 15927
15928 /* "neighbor a:b:c:d graceful-restart-disable" command */
15929 install_element(BGP_NODE,
15930 &bgp_neighbor_graceful_restart_disable_set_cmd);
15931 install_element(BGP_NODE,
15932 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
15933
15934 /* "neighbor a:b:c:d graceful-restart-helper" command */
15935 install_element(BGP_NODE,
15936 &bgp_neighbor_graceful_restart_helper_set_cmd);
15937 install_element(BGP_NODE,
15938 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
15939
d62a17ae 15940 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
15941 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
15942 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
15943 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 15944 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 15945 install_element(BGP_NODE,
15946 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 15947 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
15948 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
15949
d6e3c15b 15950 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
15951 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 15952 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
15953 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 15954
7f323236
DW
15955 /* "bgp graceful-shutdown" commands */
15956 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
15957 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
15958
d62a17ae 15959 /* "bgp fast-external-failover" commands */
15960 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
15961 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
15962
d62a17ae 15963 /* "bgp bestpath compare-routerid" commands */
15964 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
15965 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
15966
15967 /* "bgp bestpath as-path ignore" commands */
15968 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
15969 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
15970
15971 /* "bgp bestpath as-path confed" commands */
15972 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
15973 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
15974
15975 /* "bgp bestpath as-path multipath-relax" commands */
15976 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
15977 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
15978
15979 /* "bgp log-neighbor-changes" commands */
15980 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
15981 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
15982
15983 /* "bgp bestpath med" commands */
15984 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
15985 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
15986
f7e1c681 15987 /* "bgp bestpath bandwidth" commands */
15988 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 15989 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 15990
d62a17ae 15991 /* "no bgp default ipv4-unicast" commands. */
15992 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
15993 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
15994
15995 /* "bgp network import-check" commands. */
15996 install_element(BGP_NODE, &bgp_network_import_check_cmd);
15997 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
15998 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
15999
16000 /* "bgp default local-preference" commands. */
16001 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
16002 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
16003
16004 /* bgp default show-hostname */
16005 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
16006 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
16007
aef999a2
DA
16008 /* bgp default show-nexthop-hostname */
16009 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
16010 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
16011
d62a17ae 16012 /* "bgp default subgroup-pkt-queue-max" commands. */
16013 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
16014 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
16015
16016 /* bgp ibgp-allow-policy-mods command */
16017 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
16018 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
16019
16020 /* "bgp listen limit" commands. */
16021 install_element(BGP_NODE, &bgp_listen_limit_cmd);
16022 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
16023
16024 /* "bgp listen range" commands. */
16025 install_element(BGP_NODE, &bgp_listen_range_cmd);
16026 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
16027
8175f54a 16028 /* "bgp default shutdown" command */
f26845f9
QY
16029 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
16030
d62a17ae 16031 /* "neighbor remote-as" commands. */
16032 install_element(BGP_NODE, &neighbor_remote_as_cmd);
16033 install_element(BGP_NODE, &neighbor_interface_config_cmd);
16034 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
16035 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
16036 install_element(BGP_NODE,
16037 &neighbor_interface_v6only_config_remote_as_cmd);
16038 install_element(BGP_NODE, &no_neighbor_cmd);
16039 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
16040
16041 /* "neighbor peer-group" commands. */
16042 install_element(BGP_NODE, &neighbor_peer_group_cmd);
16043 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
16044 install_element(BGP_NODE,
16045 &no_neighbor_interface_peer_group_remote_as_cmd);
16046
16047 /* "neighbor local-as" commands. */
16048 install_element(BGP_NODE, &neighbor_local_as_cmd);
16049 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
16050 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
16051 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
16052
16053 /* "neighbor solo" commands. */
16054 install_element(BGP_NODE, &neighbor_solo_cmd);
16055 install_element(BGP_NODE, &no_neighbor_solo_cmd);
16056
16057 /* "neighbor password" commands. */
16058 install_element(BGP_NODE, &neighbor_password_cmd);
16059 install_element(BGP_NODE, &no_neighbor_password_cmd);
16060
16061 /* "neighbor activate" commands. */
16062 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
16063 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
16064 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
16065 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
16066 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
16067 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
16068 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
16069 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
16070 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 16071 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
16072 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 16073 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
16074
16075 /* "no neighbor activate" commands. */
16076 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
16077 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
16078 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
16079 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
16080 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
16081 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
16082 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
16083 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
16084 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 16085 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
16086 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 16087 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
16088
16089 /* "neighbor peer-group" set commands. */
16090 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
16091 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16092 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
16093 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16094 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
16095 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
16096 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16097 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 16098 install_element(BGP_FLOWSPECV4_NODE,
16099 &neighbor_set_peer_group_hidden_cmd);
16100 install_element(BGP_FLOWSPECV6_NODE,
16101 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 16102
16103 /* "no neighbor peer-group unset" commands. */
16104 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
16105 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16106 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16107 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16108 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16109 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16110 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16111 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 16112 install_element(BGP_FLOWSPECV4_NODE,
16113 &no_neighbor_set_peer_group_hidden_cmd);
16114 install_element(BGP_FLOWSPECV6_NODE,
16115 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 16116
16117 /* "neighbor softreconfiguration inbound" commands.*/
16118 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
16119 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
16120 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
16121 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16122 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
16123 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16124 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
16125 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16126 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
16127 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16128 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
16129 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16130 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
16131 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16132 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
16133 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16134 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
16135 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 16136 install_element(BGP_FLOWSPECV4_NODE,
16137 &neighbor_soft_reconfiguration_cmd);
16138 install_element(BGP_FLOWSPECV4_NODE,
16139 &no_neighbor_soft_reconfiguration_cmd);
16140 install_element(BGP_FLOWSPECV6_NODE,
16141 &neighbor_soft_reconfiguration_cmd);
16142 install_element(BGP_FLOWSPECV6_NODE,
16143 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
16144 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
16145 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 16146
16147 /* "neighbor attribute-unchanged" commands. */
16148 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
16149 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
16150 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
16151 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
16152 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
16153 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
16154 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
16155 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
16156 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
16157 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
16158 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
16159 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
16160 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
16161 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
16162 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
16163 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
16164 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
16165 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
16166
16167 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
16168 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
16169
16170 /* "nexthop-local unchanged" commands */
16171 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
16172 install_element(BGP_IPV6_NODE,
16173 &no_neighbor_nexthop_local_unchanged_cmd);
16174
16175 /* "neighbor next-hop-self" commands. */
16176 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
16177 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
16178 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
16179 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
16180 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
16181 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
16182 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
16183 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
16184 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
16185 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
16186 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
16187 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
16188 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
16189 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
16190 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
16191 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
16192 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
16193 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
16194 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
16195 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 16196
16197 /* "neighbor next-hop-self force" commands. */
16198 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
16199 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
16200 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16201 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16202 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
16203 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16204 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16205 install_element(BGP_IPV4_NODE,
16206 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16207 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
16208 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16209 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16210 install_element(BGP_IPV4M_NODE,
16211 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16212 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
16213 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16214 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16215 install_element(BGP_IPV4L_NODE,
16216 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16217 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
16218 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16219 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16220 install_element(BGP_IPV6_NODE,
16221 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16222 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
16223 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16224 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16225 install_element(BGP_IPV6M_NODE,
16226 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16227 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
16228 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16229 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16230 install_element(BGP_IPV6L_NODE,
16231 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16232 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
16233 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16234 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16235 install_element(BGP_VPNV4_NODE,
16236 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16237 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
16238 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16239 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16240 install_element(BGP_VPNV6_NODE,
16241 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
16242 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
16243 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 16244
16245 /* "neighbor as-override" commands. */
16246 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
16247 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
16248 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
16249 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
16250 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
16251 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
16252 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
16253 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
16254 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
16255 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
16256 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
16257 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
16258 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
16259 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
16260 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
16261 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
16262 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
16263 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
16264
16265 /* "neighbor remove-private-AS" commands. */
16266 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
16267 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
16268 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
16269 install_element(BGP_NODE,
16270 &no_neighbor_remove_private_as_all_hidden_cmd);
16271 install_element(BGP_NODE,
16272 &neighbor_remove_private_as_replace_as_hidden_cmd);
16273 install_element(BGP_NODE,
16274 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
16275 install_element(BGP_NODE,
16276 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
16277 install_element(
16278 BGP_NODE,
16279 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
16280 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
16281 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
16282 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
16283 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16284 install_element(BGP_IPV4_NODE,
16285 &neighbor_remove_private_as_replace_as_cmd);
16286 install_element(BGP_IPV4_NODE,
16287 &no_neighbor_remove_private_as_replace_as_cmd);
16288 install_element(BGP_IPV4_NODE,
16289 &neighbor_remove_private_as_all_replace_as_cmd);
16290 install_element(BGP_IPV4_NODE,
16291 &no_neighbor_remove_private_as_all_replace_as_cmd);
16292 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
16293 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
16294 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
16295 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
16296 install_element(BGP_IPV4M_NODE,
16297 &neighbor_remove_private_as_replace_as_cmd);
16298 install_element(BGP_IPV4M_NODE,
16299 &no_neighbor_remove_private_as_replace_as_cmd);
16300 install_element(BGP_IPV4M_NODE,
16301 &neighbor_remove_private_as_all_replace_as_cmd);
16302 install_element(BGP_IPV4M_NODE,
16303 &no_neighbor_remove_private_as_all_replace_as_cmd);
16304 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
16305 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
16306 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
16307 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
16308 install_element(BGP_IPV4L_NODE,
16309 &neighbor_remove_private_as_replace_as_cmd);
16310 install_element(BGP_IPV4L_NODE,
16311 &no_neighbor_remove_private_as_replace_as_cmd);
16312 install_element(BGP_IPV4L_NODE,
16313 &neighbor_remove_private_as_all_replace_as_cmd);
16314 install_element(BGP_IPV4L_NODE,
16315 &no_neighbor_remove_private_as_all_replace_as_cmd);
16316 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
16317 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
16318 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
16319 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16320 install_element(BGP_IPV6_NODE,
16321 &neighbor_remove_private_as_replace_as_cmd);
16322 install_element(BGP_IPV6_NODE,
16323 &no_neighbor_remove_private_as_replace_as_cmd);
16324 install_element(BGP_IPV6_NODE,
16325 &neighbor_remove_private_as_all_replace_as_cmd);
16326 install_element(BGP_IPV6_NODE,
16327 &no_neighbor_remove_private_as_all_replace_as_cmd);
16328 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
16329 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
16330 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
16331 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
16332 install_element(BGP_IPV6M_NODE,
16333 &neighbor_remove_private_as_replace_as_cmd);
16334 install_element(BGP_IPV6M_NODE,
16335 &no_neighbor_remove_private_as_replace_as_cmd);
16336 install_element(BGP_IPV6M_NODE,
16337 &neighbor_remove_private_as_all_replace_as_cmd);
16338 install_element(BGP_IPV6M_NODE,
16339 &no_neighbor_remove_private_as_all_replace_as_cmd);
16340 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
16341 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
16342 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
16343 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
16344 install_element(BGP_IPV6L_NODE,
16345 &neighbor_remove_private_as_replace_as_cmd);
16346 install_element(BGP_IPV6L_NODE,
16347 &no_neighbor_remove_private_as_replace_as_cmd);
16348 install_element(BGP_IPV6L_NODE,
16349 &neighbor_remove_private_as_all_replace_as_cmd);
16350 install_element(BGP_IPV6L_NODE,
16351 &no_neighbor_remove_private_as_all_replace_as_cmd);
16352 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
16353 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
16354 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
16355 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16356 install_element(BGP_VPNV4_NODE,
16357 &neighbor_remove_private_as_replace_as_cmd);
16358 install_element(BGP_VPNV4_NODE,
16359 &no_neighbor_remove_private_as_replace_as_cmd);
16360 install_element(BGP_VPNV4_NODE,
16361 &neighbor_remove_private_as_all_replace_as_cmd);
16362 install_element(BGP_VPNV4_NODE,
16363 &no_neighbor_remove_private_as_all_replace_as_cmd);
16364 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
16365 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
16366 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
16367 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16368 install_element(BGP_VPNV6_NODE,
16369 &neighbor_remove_private_as_replace_as_cmd);
16370 install_element(BGP_VPNV6_NODE,
16371 &no_neighbor_remove_private_as_replace_as_cmd);
16372 install_element(BGP_VPNV6_NODE,
16373 &neighbor_remove_private_as_all_replace_as_cmd);
16374 install_element(BGP_VPNV6_NODE,
16375 &no_neighbor_remove_private_as_all_replace_as_cmd);
16376
16377 /* "neighbor send-community" commands.*/
16378 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
16379 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
16380 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
16381 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
16382 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
16383 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
16384 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
16385 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
16386 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
16387 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
16388 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
16389 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
16390 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
16391 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
16392 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
16393 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
16394 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
16395 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
16396 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
16397 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
16398 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
16399 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
16400 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
16401 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
16402 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
16403 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
16404 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
16405 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
16406 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
16407 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
16408 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
16409 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
16410 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
16411 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
16412 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
16413 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
16414
16415 /* "neighbor route-reflector" commands.*/
16416 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
16417 install_element(BGP_NODE,
16418 &no_neighbor_route_reflector_client_hidden_cmd);
16419 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
16420 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
16421 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
16422 install_element(BGP_IPV4M_NODE,
16423 &no_neighbor_route_reflector_client_cmd);
16424 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
16425 install_element(BGP_IPV4L_NODE,
16426 &no_neighbor_route_reflector_client_cmd);
16427 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
16428 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
16429 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
16430 install_element(BGP_IPV6M_NODE,
16431 &no_neighbor_route_reflector_client_cmd);
16432 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
16433 install_element(BGP_IPV6L_NODE,
16434 &no_neighbor_route_reflector_client_cmd);
16435 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
16436 install_element(BGP_VPNV4_NODE,
16437 &no_neighbor_route_reflector_client_cmd);
16438 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
16439 install_element(BGP_VPNV6_NODE,
16440 &no_neighbor_route_reflector_client_cmd);
7c40bf39 16441 install_element(BGP_FLOWSPECV4_NODE,
16442 &neighbor_route_reflector_client_cmd);
16443 install_element(BGP_FLOWSPECV4_NODE,
16444 &no_neighbor_route_reflector_client_cmd);
16445 install_element(BGP_FLOWSPECV6_NODE,
16446 &neighbor_route_reflector_client_cmd);
16447 install_element(BGP_FLOWSPECV6_NODE,
16448 &no_neighbor_route_reflector_client_cmd);
d62a17ae 16449 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
16450 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
16451
16452 /* "neighbor route-server" commands.*/
16453 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16454 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16455 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16456 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16457 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16458 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16459 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16460 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16461 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16462 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16463 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16464 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16465 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16466 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16467 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16468 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16469 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16470 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
16471 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16472 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 16473 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16474 install_element(BGP_FLOWSPECV4_NODE,
16475 &no_neighbor_route_server_client_cmd);
16476 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16477 install_element(BGP_FLOWSPECV6_NODE,
16478 &no_neighbor_route_server_client_cmd);
d62a17ae 16479
16480 /* "neighbor addpath-tx-all-paths" commands.*/
16481 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16482 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16483 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16484 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16485 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16486 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16487 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16488 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16489 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16490 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16491 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16492 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16493 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16494 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16495 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16496 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16497 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16498 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16499
16500 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16501 install_element(BGP_NODE,
16502 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16503 install_element(BGP_NODE,
16504 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16505 install_element(BGP_IPV4_NODE,
16506 &neighbor_addpath_tx_bestpath_per_as_cmd);
16507 install_element(BGP_IPV4_NODE,
16508 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16509 install_element(BGP_IPV4M_NODE,
16510 &neighbor_addpath_tx_bestpath_per_as_cmd);
16511 install_element(BGP_IPV4M_NODE,
16512 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16513 install_element(BGP_IPV4L_NODE,
16514 &neighbor_addpath_tx_bestpath_per_as_cmd);
16515 install_element(BGP_IPV4L_NODE,
16516 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16517 install_element(BGP_IPV6_NODE,
16518 &neighbor_addpath_tx_bestpath_per_as_cmd);
16519 install_element(BGP_IPV6_NODE,
16520 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16521 install_element(BGP_IPV6M_NODE,
16522 &neighbor_addpath_tx_bestpath_per_as_cmd);
16523 install_element(BGP_IPV6M_NODE,
16524 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16525 install_element(BGP_IPV6L_NODE,
16526 &neighbor_addpath_tx_bestpath_per_as_cmd);
16527 install_element(BGP_IPV6L_NODE,
16528 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16529 install_element(BGP_VPNV4_NODE,
16530 &neighbor_addpath_tx_bestpath_per_as_cmd);
16531 install_element(BGP_VPNV4_NODE,
16532 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16533 install_element(BGP_VPNV6_NODE,
16534 &neighbor_addpath_tx_bestpath_per_as_cmd);
16535 install_element(BGP_VPNV6_NODE,
16536 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16537
2b31007c
RZ
16538 /* "neighbor sender-as-path-loop-detection" commands. */
16539 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16540 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16541
d62a17ae 16542 /* "neighbor passive" commands. */
16543 install_element(BGP_NODE, &neighbor_passive_cmd);
16544 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16545
16546
16547 /* "neighbor shutdown" commands. */
16548 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16549 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16550 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16551 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
16552
16553 /* "neighbor capability extended-nexthop" commands.*/
16554 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16555 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16556
16557 /* "neighbor capability orf prefix-list" commands.*/
16558 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16559 install_element(BGP_NODE,
16560 &no_neighbor_capability_orf_prefix_hidden_cmd);
16561 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16562 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16563 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16564 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16565 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16566 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16567 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16568 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16569 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16570 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16571 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16572 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16573
16574 /* "neighbor capability dynamic" commands.*/
16575 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16576 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16577
16578 /* "neighbor dont-capability-negotiate" commands. */
16579 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16580 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16581
16582 /* "neighbor ebgp-multihop" commands. */
16583 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16584 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16585 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16586
16587 /* "neighbor disable-connected-check" commands. */
16588 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16589 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16590
47cbc09b
PM
16591 /* "neighbor enforce-first-as" commands. */
16592 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16593 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16594
d62a17ae 16595 /* "neighbor description" commands. */
16596 install_element(BGP_NODE, &neighbor_description_cmd);
16597 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 16598 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 16599
16600 /* "neighbor update-source" commands. "*/
16601 install_element(BGP_NODE, &neighbor_update_source_cmd);
16602 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16603
16604 /* "neighbor default-originate" commands. */
16605 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16606 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16607 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16608 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16609 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16610 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16611 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16612 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16613 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16614 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16615 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16616 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16617 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16618 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16619 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16620 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16621 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16622 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16623 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16624 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16625 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16626
16627 /* "neighbor port" commands. */
16628 install_element(BGP_NODE, &neighbor_port_cmd);
16629 install_element(BGP_NODE, &no_neighbor_port_cmd);
16630
16631 /* "neighbor weight" commands. */
16632 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16633 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16634
16635 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16636 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16637 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16638 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16639 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16640 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16641 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16642 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16643 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16644 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16645 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16646 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16647 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16648 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16649 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16650 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16651
16652 /* "neighbor override-capability" commands. */
16653 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16654 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16655
16656 /* "neighbor strict-capability-match" commands. */
16657 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16658 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16659
16660 /* "neighbor timers" commands. */
16661 install_element(BGP_NODE, &neighbor_timers_cmd);
16662 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16663
16664 /* "neighbor timers connect" commands. */
16665 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16666 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16667
16668 /* "neighbor advertisement-interval" commands. */
16669 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
16670 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
16671
16672 /* "neighbor interface" commands. */
16673 install_element(BGP_NODE, &neighbor_interface_cmd);
16674 install_element(BGP_NODE, &no_neighbor_interface_cmd);
16675
16676 /* "neighbor distribute" commands. */
16677 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
16678 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
16679 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
16680 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
16681 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
16682 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
16683 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
16684 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
16685 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
16686 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
16687 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
16688 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
16689 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
16690 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
16691 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
16692 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
16693 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
16694 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
16695
16696 /* "neighbor prefix-list" commands. */
16697 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
16698 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
16699 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
16700 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
16701 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
16702 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
16703 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
16704 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
16705 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
16706 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
16707 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
16708 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
16709 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
16710 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
16711 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
16712 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
16713 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
16714 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 16715 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
16716 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
16717 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
16718 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 16719
16720 /* "neighbor filter-list" commands. */
16721 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
16722 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
16723 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
16724 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
16725 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
16726 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
16727 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
16728 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
16729 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
16730 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
16731 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
16732 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
16733 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
16734 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
16735 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
16736 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
16737 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
16738 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 16739 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
16740 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
16741 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
16742 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 16743
16744 /* "neighbor route-map" commands. */
16745 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
16746 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
16747 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
16748 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
16749 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
16750 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
16751 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
16752 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
16753 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
16754 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
16755 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
16756 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
16757 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
16758 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
16759 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
16760 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
16761 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
16762 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 16763 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
16764 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
16765 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
16766 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
16767 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
16768 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 16769
16770 /* "neighbor unsuppress-map" commands. */
16771 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
16772 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
16773 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
16774 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
16775 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
16776 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
16777 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
16778 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
16779 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
16780 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
16781 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
16782 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
16783 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
16784 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
16785 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
16786 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
16787 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
16788 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
16789
fde246e8
DA
16790 /* neighbor maximum-prefix-out commands. */
16791 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
16792 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
16793 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
16794 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16795 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
16796 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16797 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
16798 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16799 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
16800 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16801 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
16802 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16803 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
16804 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16805 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
16806 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16807 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
16808 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16809
d62a17ae 16810 /* "neighbor maximum-prefix" commands. */
16811 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
16812 install_element(BGP_NODE,
16813 &neighbor_maximum_prefix_threshold_hidden_cmd);
16814 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
16815 install_element(BGP_NODE,
16816 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
16817 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
16818 install_element(BGP_NODE,
16819 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
16820 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
16821 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
16822 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16823 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16824 install_element(BGP_IPV4_NODE,
16825 &neighbor_maximum_prefix_threshold_warning_cmd);
16826 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16827 install_element(BGP_IPV4_NODE,
16828 &neighbor_maximum_prefix_threshold_restart_cmd);
16829 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
16830 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
16831 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16832 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
16833 install_element(BGP_IPV4M_NODE,
16834 &neighbor_maximum_prefix_threshold_warning_cmd);
16835 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
16836 install_element(BGP_IPV4M_NODE,
16837 &neighbor_maximum_prefix_threshold_restart_cmd);
16838 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
16839 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
16840 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16841 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
16842 install_element(BGP_IPV4L_NODE,
16843 &neighbor_maximum_prefix_threshold_warning_cmd);
16844 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
16845 install_element(BGP_IPV4L_NODE,
16846 &neighbor_maximum_prefix_threshold_restart_cmd);
16847 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
16848 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
16849 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16850 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16851 install_element(BGP_IPV6_NODE,
16852 &neighbor_maximum_prefix_threshold_warning_cmd);
16853 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16854 install_element(BGP_IPV6_NODE,
16855 &neighbor_maximum_prefix_threshold_restart_cmd);
16856 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
16857 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
16858 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16859 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
16860 install_element(BGP_IPV6M_NODE,
16861 &neighbor_maximum_prefix_threshold_warning_cmd);
16862 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
16863 install_element(BGP_IPV6M_NODE,
16864 &neighbor_maximum_prefix_threshold_restart_cmd);
16865 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
16866 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
16867 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16868 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
16869 install_element(BGP_IPV6L_NODE,
16870 &neighbor_maximum_prefix_threshold_warning_cmd);
16871 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
16872 install_element(BGP_IPV6L_NODE,
16873 &neighbor_maximum_prefix_threshold_restart_cmd);
16874 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
16875 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
16876 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16877 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16878 install_element(BGP_VPNV4_NODE,
16879 &neighbor_maximum_prefix_threshold_warning_cmd);
16880 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16881 install_element(BGP_VPNV4_NODE,
16882 &neighbor_maximum_prefix_threshold_restart_cmd);
16883 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
16884 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
16885 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16886 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16887 install_element(BGP_VPNV6_NODE,
16888 &neighbor_maximum_prefix_threshold_warning_cmd);
16889 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16890 install_element(BGP_VPNV6_NODE,
16891 &neighbor_maximum_prefix_threshold_restart_cmd);
16892 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
16893
16894 /* "neighbor allowas-in" */
16895 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
16896 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
16897 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
16898 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
16899 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
16900 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
16901 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
16902 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
16903 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
16904 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
16905 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
16906 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
16907 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
16908 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
16909 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
16910 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
16911 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
16912 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
16913 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
16914 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
16915
16916 /* address-family commands. */
16917 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
16918 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 16919#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 16920 install_element(BGP_NODE, &address_family_vpnv4_cmd);
16921 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 16922#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 16923
d62a17ae 16924 install_element(BGP_NODE, &address_family_evpn_cmd);
16925
16926 /* "exit-address-family" command. */
16927 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
16928 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
16929 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
16930 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
16931 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
16932 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
16933 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
16934 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 16935 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
16936 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 16937 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
16938
16939 /* "clear ip bgp commands" */
16940 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
16941
16942 /* clear ip bgp prefix */
16943 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
16944 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
16945 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
16946
16947 /* "show [ip] bgp summary" commands. */
16948 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 16949 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 16950 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 16951 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 16952 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
16953 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 16954 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
16955
16956 /* "show [ip] bgp neighbors" commands. */
16957 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
16958
36235319 16959 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 16960
d62a17ae 16961 /* "show [ip] bgp peer-group" commands. */
16962 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
16963
16964 /* "show [ip] bgp paths" commands. */
16965 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
16966
16967 /* "show [ip] bgp community" commands. */
16968 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
16969
16970 /* "show ip bgp large-community" commands. */
16971 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
16972 /* "show [ip] bgp attribute-info" commands. */
16973 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 16974 /* "show [ip] bgp route-leak" command */
16975 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 16976
16977 /* "redistribute" commands. */
16978 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
16979 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
16980 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
16981 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
16982 install_element(BGP_NODE,
16983 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
16984 install_element(BGP_NODE,
16985 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
16986 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
16987 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
16988 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
16989 install_element(BGP_NODE,
16990 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
16991 install_element(BGP_NODE,
16992 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
16993 install_element(BGP_NODE,
16994 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
16995 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
16996 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
16997 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
16998 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
16999 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
17000 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
17001 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
17002 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
17003 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
17004 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
17005 install_element(BGP_IPV4_NODE,
17006 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
17007 install_element(BGP_IPV4_NODE,
17008 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
17009 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
17010 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
17011 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
17012 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
17013 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
17014 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
17015
b9c7bc5a
PZ
17016 /* import|export vpn [route-map WORD] */
17017 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
17018 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 17019
12a844a5
DS
17020 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
17021 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
17022
d62a17ae 17023 /* ttl_security commands */
17024 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
17025 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
17026
17027 /* "show [ip] bgp memory" commands. */
17028 install_element(VIEW_NODE, &show_bgp_memory_cmd);
17029
acf71666
MK
17030 /* "show bgp martian next-hop" */
17031 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
17032
48ecf8f5
DS
17033 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
17034
d62a17ae 17035 /* "show [ip] bgp views" commands. */
17036 install_element(VIEW_NODE, &show_bgp_views_cmd);
17037
17038 /* "show [ip] bgp vrfs" commands. */
17039 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
17040
17041 /* Community-list. */
17042 community_list_vty();
ddb5b488
PZ
17043
17044 /* vpn-policy commands */
b9c7bc5a
PZ
17045 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
17046 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
17047 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
17048 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
17049 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
17050 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
17051 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
17052 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
17053 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
17054 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
17055 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
17056 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 17057
301ad80a
PG
17058 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
17059 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
17060
b9c7bc5a
PZ
17061 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
17062 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
17063 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
17064 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
17065 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
17066 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
17067 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
17068 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
17069 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
17070 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 17071}
6b0655a2 17072
718e3744 17073#include "memory.h"
17074#include "bgp_regex.h"
17075#include "bgp_clist.h"
17076#include "bgp_ecommunity.h"
17077
17078/* VTY functions. */
17079
17080/* Direction value to string conversion. */
d62a17ae 17081static const char *community_direct_str(int direct)
17082{
17083 switch (direct) {
17084 case COMMUNITY_DENY:
17085 return "deny";
17086 case COMMUNITY_PERMIT:
17087 return "permit";
17088 default:
17089 return "unknown";
17090 }
718e3744 17091}
17092
17093/* Display error string. */
d62a17ae 17094static void community_list_perror(struct vty *vty, int ret)
17095{
17096 switch (ret) {
17097 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
17098 vty_out(vty, "%% Can't find community-list\n");
17099 break;
17100 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
17101 vty_out(vty, "%% Malformed community-list value\n");
17102 break;
17103 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
17104 vty_out(vty,
17105 "%% Community name conflict, previously defined as standard community\n");
17106 break;
17107 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
17108 vty_out(vty,
17109 "%% Community name conflict, previously defined as expanded community\n");
17110 break;
17111 }
718e3744 17112}
17113
5bf15956
DW
17114/* "community-list" keyword help string. */
17115#define COMMUNITY_LIST_STR "Add a community list entry\n"
17116
7336e101
SP
17117/*community-list standard */
17118DEFUN (community_list_standard,
17119 bgp_community_list_standard_cmd,
2f8cc0e5 17120 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17121 BGP_STR
718e3744 17122 COMMUNITY_LIST_STR
17123 "Community list number (standard)\n"
5bf15956 17124 "Add an standard community-list entry\n"
718e3744 17125 "Community list name\n"
2f8cc0e5
DA
17126 "Sequence number of an entry\n"
17127 "Sequence number\n"
718e3744 17128 "Specify community to reject\n"
17129 "Specify community to accept\n"
17130 COMMUNITY_VAL_STR)
17131{
d62a17ae 17132 char *cl_name_or_number = NULL;
2f8cc0e5 17133 char *seq = NULL;
d62a17ae 17134 int direct = 0;
17135 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 17136 int idx = 0;
7336e101 17137
2f8cc0e5
DA
17138 argv_find(argv, argc, "(1-4294967295)", &idx);
17139 if (idx)
17140 seq = argv[idx]->arg;
17141
17142 idx = 0;
d62a17ae 17143 argv_find(argv, argc, "(1-99)", &idx);
17144 argv_find(argv, argc, "WORD", &idx);
17145 cl_name_or_number = argv[idx]->arg;
17146 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17147 : COMMUNITY_DENY;
17148 argv_find(argv, argc, "AA:NN", &idx);
17149 char *str = argv_concat(argv, argc, idx);
42f914d4 17150
2f8cc0e5
DA
17151 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17152 direct, style);
42f914d4 17153
d62a17ae 17154 XFREE(MTYPE_TMP, str);
42f914d4 17155
d62a17ae 17156 if (ret < 0) {
17157 /* Display error string. */
17158 community_list_perror(vty, ret);
17159 return CMD_WARNING_CONFIG_FAILED;
17160 }
42f914d4 17161
d62a17ae 17162 return CMD_SUCCESS;
718e3744 17163}
17164
7336e101
SP
17165DEFUN (no_community_list_standard_all,
17166 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 17167 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17168 NO_STR
17169 BGP_STR
17170 COMMUNITY_LIST_STR
17171 "Community list number (standard)\n"
17172 "Add an standard community-list entry\n"
17173 "Community list name\n"
2f8cc0e5
DA
17174 "Sequence number of an entry\n"
17175 "Sequence number\n"
7336e101
SP
17176 "Specify community to reject\n"
17177 "Specify community to accept\n"
17178 COMMUNITY_VAL_STR)
718e3744 17179{
d62a17ae 17180 char *cl_name_or_number = NULL;
174b5cb9 17181 char *str = NULL;
d62a17ae 17182 int direct = 0;
17183 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 17184 char *seq = NULL;
d62a17ae 17185 int idx = 0;
7336e101 17186
2f8cc0e5
DA
17187 argv_find(argv, argc, "(1-4294967295)", &idx);
17188 if (idx)
17189 seq = argv[idx]->arg;
17190
17191 idx = 0;
174b5cb9
DA
17192 argv_find(argv, argc, "permit", &idx);
17193 argv_find(argv, argc, "deny", &idx);
17194
17195 if (idx) {
17196 direct = argv_find(argv, argc, "permit", &idx)
17197 ? COMMUNITY_PERMIT
17198 : COMMUNITY_DENY;
17199
17200 idx = 0;
17201 argv_find(argv, argc, "AA:NN", &idx);
17202 str = argv_concat(argv, argc, idx);
17203 }
17204
17205 idx = 0;
d62a17ae 17206 argv_find(argv, argc, "(1-99)", &idx);
17207 argv_find(argv, argc, "WORD", &idx);
17208 cl_name_or_number = argv[idx]->arg;
42f914d4 17209
2f8cc0e5 17210 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17211 direct, style);
42f914d4 17212
d62a17ae 17213 XFREE(MTYPE_TMP, str);
daf9ddbb 17214
d62a17ae 17215 if (ret < 0) {
17216 community_list_perror(vty, ret);
17217 return CMD_WARNING_CONFIG_FAILED;
17218 }
42f914d4 17219
d62a17ae 17220 return CMD_SUCCESS;
718e3744 17221}
7336e101 17222
174b5cb9
DA
17223ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
17224 "no bgp community-list <(1-99)|standard WORD>",
17225 NO_STR BGP_STR COMMUNITY_LIST_STR
17226 "Community list number (standard)\n"
17227 "Add an standard community-list entry\n"
17228 "Community list name\n")
17229
7336e101
SP
17230/*community-list expanded */
17231DEFUN (community_list_expanded_all,
17232 bgp_community_list_expanded_all_cmd,
2f8cc0e5 17233 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17234 BGP_STR
17235 COMMUNITY_LIST_STR
718e3744 17236 "Community list number (expanded)\n"
5bf15956 17237 "Add an expanded community-list entry\n"
718e3744 17238 "Community list name\n"
2f8cc0e5
DA
17239 "Sequence number of an entry\n"
17240 "Sequence number\n"
718e3744 17241 "Specify community to reject\n"
17242 "Specify community to accept\n"
17243 COMMUNITY_VAL_STR)
17244{
d62a17ae 17245 char *cl_name_or_number = NULL;
2f8cc0e5 17246 char *seq = NULL;
d62a17ae 17247 int direct = 0;
17248 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17249 int idx = 0;
7b9a4750 17250
2f8cc0e5
DA
17251 argv_find(argv, argc, "(1-4294967295)", &idx);
17252 if (idx)
17253 seq = argv[idx]->arg;
17254
17255 idx = 0;
17256
d62a17ae 17257 argv_find(argv, argc, "(100-500)", &idx);
17258 argv_find(argv, argc, "WORD", &idx);
17259 cl_name_or_number = argv[idx]->arg;
17260 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17261 : COMMUNITY_DENY;
17262 argv_find(argv, argc, "AA:NN", &idx);
17263 char *str = argv_concat(argv, argc, idx);
42f914d4 17264
2f8cc0e5
DA
17265 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17266 direct, style);
42f914d4 17267
d62a17ae 17268 XFREE(MTYPE_TMP, str);
42f914d4 17269
d62a17ae 17270 if (ret < 0) {
17271 /* Display error string. */
17272 community_list_perror(vty, ret);
17273 return CMD_WARNING_CONFIG_FAILED;
17274 }
42f914d4 17275
d62a17ae 17276 return CMD_SUCCESS;
718e3744 17277}
17278
7336e101
SP
17279DEFUN (no_community_list_expanded_all,
17280 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 17281 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17282 NO_STR
17283 BGP_STR
17284 COMMUNITY_LIST_STR
17285 "Community list number (expanded)\n"
17286 "Add an expanded community-list entry\n"
17287 "Community list name\n"
2f8cc0e5
DA
17288 "Sequence number of an entry\n"
17289 "Sequence number\n"
7336e101
SP
17290 "Specify community to reject\n"
17291 "Specify community to accept\n"
17292 COMMUNITY_VAL_STR)
718e3744 17293{
d62a17ae 17294 char *cl_name_or_number = NULL;
2f8cc0e5 17295 char *seq = NULL;
174b5cb9 17296 char *str = NULL;
d62a17ae 17297 int direct = 0;
17298 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17299 int idx = 0;
174b5cb9 17300
2f8cc0e5
DA
17301 argv_find(argv, argc, "(1-4294967295)", &idx);
17302 if (idx)
17303 seq = argv[idx]->arg;
17304
17305 idx = 0;
174b5cb9
DA
17306 argv_find(argv, argc, "permit", &idx);
17307 argv_find(argv, argc, "deny", &idx);
17308
17309 if (idx) {
17310 direct = argv_find(argv, argc, "permit", &idx)
17311 ? COMMUNITY_PERMIT
17312 : COMMUNITY_DENY;
17313
17314 idx = 0;
17315 argv_find(argv, argc, "AA:NN", &idx);
17316 str = argv_concat(argv, argc, idx);
7336e101 17317 }
174b5cb9
DA
17318
17319 idx = 0;
d62a17ae 17320 argv_find(argv, argc, "(100-500)", &idx);
17321 argv_find(argv, argc, "WORD", &idx);
17322 cl_name_or_number = argv[idx]->arg;
42f914d4 17323
2f8cc0e5 17324 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17325 direct, style);
42f914d4 17326
d62a17ae 17327 XFREE(MTYPE_TMP, str);
daf9ddbb 17328
d62a17ae 17329 if (ret < 0) {
17330 community_list_perror(vty, ret);
17331 return CMD_WARNING_CONFIG_FAILED;
17332 }
42f914d4 17333
d62a17ae 17334 return CMD_SUCCESS;
718e3744 17335}
17336
174b5cb9
DA
17337ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
17338 "no bgp community-list <(100-500)|expanded WORD>",
17339 NO_STR IP_STR COMMUNITY_LIST_STR
17340 "Community list number (expanded)\n"
17341 "Add an expanded community-list entry\n"
17342 "Community list name\n")
17343
8d9b8ed9
PM
17344/* Return configuration string of community-list entry. */
17345static const char *community_list_config_str(struct community_entry *entry)
17346{
17347 const char *str;
17348
17349 if (entry->any)
17350 str = "";
17351 else {
17352 if (entry->style == COMMUNITY_LIST_STANDARD)
17353 str = community_str(entry->u.com, false);
17354 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
17355 str = lcommunity_str(entry->u.lcom, false);
17356 else
17357 str = entry->config;
17358 }
17359 return str;
17360}
17361
d62a17ae 17362static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 17363{
d62a17ae 17364 struct community_entry *entry;
718e3744 17365
d62a17ae 17366 for (entry = list->head; entry; entry = entry->next) {
17367 if (entry == list->head) {
17368 if (all_digit(list->name))
17369 vty_out(vty, "Community %s list %s\n",
17370 entry->style == COMMUNITY_LIST_STANDARD
17371 ? "standard"
17372 : "(expanded) access",
17373 list->name);
17374 else
17375 vty_out(vty, "Named Community %s list %s\n",
17376 entry->style == COMMUNITY_LIST_STANDARD
17377 ? "standard"
17378 : "expanded",
17379 list->name);
17380 }
17381 if (entry->any)
17382 vty_out(vty, " %s\n",
17383 community_direct_str(entry->direct));
17384 else
17385 vty_out(vty, " %s %s\n",
17386 community_direct_str(entry->direct),
8d9b8ed9 17387 community_list_config_str(entry));
d62a17ae 17388 }
718e3744 17389}
17390
7336e101
SP
17391DEFUN (show_community_list,
17392 show_bgp_community_list_cmd,
17393 "show bgp community-list",
718e3744 17394 SHOW_STR
7336e101 17395 BGP_STR
718e3744 17396 "List community-list\n")
17397{
d62a17ae 17398 struct community_list *list;
17399 struct community_list_master *cm;
718e3744 17400
d62a17ae 17401 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17402 if (!cm)
17403 return CMD_SUCCESS;
718e3744 17404
d62a17ae 17405 for (list = cm->num.head; list; list = list->next)
17406 community_list_show(vty, list);
718e3744 17407
d62a17ae 17408 for (list = cm->str.head; list; list = list->next)
17409 community_list_show(vty, list);
718e3744 17410
d62a17ae 17411 return CMD_SUCCESS;
718e3744 17412}
17413
7336e101
SP
17414DEFUN (show_community_list_arg,
17415 show_bgp_community_list_arg_cmd,
960b69b9 17416 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
17417 SHOW_STR
17418 BGP_STR
718e3744 17419 "List community-list\n"
17420 "Community-list number\n"
960b69b9 17421 "Community-list name\n"
17422 "Detailed information on community-list\n")
718e3744 17423{
d62a17ae 17424 int idx_comm_list = 3;
17425 struct community_list *list;
718e3744 17426
e237b0d2 17427 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17428 COMMUNITY_LIST_MASTER);
17429 if (!list) {
17430 vty_out(vty, "%% Can't find community-list\n");
17431 return CMD_WARNING;
17432 }
718e3744 17433
d62a17ae 17434 community_list_show(vty, list);
718e3744 17435
d62a17ae 17436 return CMD_SUCCESS;
718e3744 17437}
6b0655a2 17438
57d187bc
JS
17439/*
17440 * Large Community code.
17441 */
d62a17ae 17442static int lcommunity_list_set_vty(struct vty *vty, int argc,
17443 struct cmd_token **argv, int style,
17444 int reject_all_digit_name)
17445{
17446 int ret;
17447 int direct;
17448 char *str;
17449 int idx = 0;
17450 char *cl_name;
2f8cc0e5
DA
17451 char *seq = NULL;
17452
947073e3 17453 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 17454 seq = argv[idx]->arg;
d62a17ae 17455
2f8cc0e5 17456 idx = 0;
d62a17ae 17457 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17458 : COMMUNITY_DENY;
17459
17460 /* All digit name check. */
17461 idx = 0;
17462 argv_find(argv, argc, "WORD", &idx);
17463 argv_find(argv, argc, "(1-99)", &idx);
17464 argv_find(argv, argc, "(100-500)", &idx);
17465 cl_name = argv[idx]->arg;
17466 if (reject_all_digit_name && all_digit(cl_name)) {
17467 vty_out(vty, "%% Community name cannot have all digits\n");
17468 return CMD_WARNING_CONFIG_FAILED;
17469 }
17470
17471 idx = 0;
17472 argv_find(argv, argc, "AA:BB:CC", &idx);
17473 argv_find(argv, argc, "LINE", &idx);
17474 /* Concat community string argument. */
17475 if (idx)
17476 str = argv_concat(argv, argc, idx);
17477 else
17478 str = NULL;
17479
2f8cc0e5 17480 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 17481
17482 /* Free temporary community list string allocated by
17483 argv_concat(). */
0a22ddfb 17484 XFREE(MTYPE_TMP, str);
d62a17ae 17485
17486 if (ret < 0) {
17487 community_list_perror(vty, ret);
17488 return CMD_WARNING_CONFIG_FAILED;
17489 }
17490 return CMD_SUCCESS;
17491}
17492
17493static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17494 struct cmd_token **argv, int style)
17495{
17496 int ret;
17497 int direct = 0;
17498 char *str = NULL;
17499 int idx = 0;
2f8cc0e5 17500 char *seq = NULL;
d62a17ae 17501
947073e3 17502 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 17503 seq = argv[idx]->arg;
d62a17ae 17504
2f8cc0e5 17505 idx = 0;
d62a17ae 17506 argv_find(argv, argc, "permit", &idx);
17507 argv_find(argv, argc, "deny", &idx);
17508
17509 if (idx) {
17510 /* Check the list direct. */
17511 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17512 direct = COMMUNITY_PERMIT;
17513 else
17514 direct = COMMUNITY_DENY;
17515
17516 idx = 0;
17517 argv_find(argv, argc, "LINE", &idx);
17518 argv_find(argv, argc, "AA:AA:NN", &idx);
17519 /* Concat community string argument. */
17520 str = argv_concat(argv, argc, idx);
17521 }
17522
17523 idx = 0;
17524 argv_find(argv, argc, "(1-99)", &idx);
17525 argv_find(argv, argc, "(100-500)", &idx);
17526 argv_find(argv, argc, "WORD", &idx);
17527
17528 /* Unset community list. */
2f8cc0e5 17529 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 17530 style);
17531
17532 /* Free temporary community list string allocated by
17533 argv_concat(). */
0a22ddfb 17534 XFREE(MTYPE_TMP, str);
d62a17ae 17535
17536 if (ret < 0) {
17537 community_list_perror(vty, ret);
17538 return CMD_WARNING_CONFIG_FAILED;
17539 }
17540
17541 return CMD_SUCCESS;
57d187bc
JS
17542}
17543
17544/* "large-community-list" keyword help string. */
17545#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17546#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17547
7336e101
SP
17548DEFUN (lcommunity_list_standard,
17549 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17550 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17551 BGP_STR
17552 LCOMMUNITY_LIST_STR
17553 "Large Community list number (standard)\n"
2f8cc0e5
DA
17554 "Sequence number of an entry\n"
17555 "Sequence number\n"
7336e101
SP
17556 "Specify large community to reject\n"
17557 "Specify large community to accept\n"
17558 LCOMMUNITY_VAL_STR)
52951b63 17559{
d62a17ae 17560 return lcommunity_list_set_vty(vty, argc, argv,
17561 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
17562}
17563
7336e101
SP
17564DEFUN (lcommunity_list_expanded,
17565 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17566 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17567 BGP_STR
17568 LCOMMUNITY_LIST_STR
17569 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17570 "Sequence number of an entry\n"
17571 "Sequence number\n"
7336e101
SP
17572 "Specify large community to reject\n"
17573 "Specify large community to accept\n"
17574 "An ordered list as a regular-expression\n")
57d187bc 17575{
d62a17ae 17576 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17577 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
17578}
17579
7336e101
SP
17580DEFUN (lcommunity_list_name_standard,
17581 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17582 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17583 BGP_STR
17584 LCOMMUNITY_LIST_STR
17585 "Specify standard large-community-list\n"
17586 "Large Community list name\n"
2f8cc0e5
DA
17587 "Sequence number of an entry\n"
17588 "Sequence number\n"
7336e101
SP
17589 "Specify large community to reject\n"
17590 "Specify large community to accept\n"
17591 LCOMMUNITY_VAL_STR)
52951b63 17592{
d62a17ae 17593 return lcommunity_list_set_vty(vty, argc, argv,
17594 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
17595}
17596
7336e101
SP
17597DEFUN (lcommunity_list_name_expanded,
17598 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17599 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17600 BGP_STR
17601 LCOMMUNITY_LIST_STR
17602 "Specify expanded large-community-list\n"
17603 "Large Community list name\n"
2f8cc0e5
DA
17604 "Sequence number of an entry\n"
17605 "Sequence number\n"
7336e101
SP
17606 "Specify large community to reject\n"
17607 "Specify large community to accept\n"
17608 "An ordered list as a regular-expression\n")
57d187bc 17609{
d62a17ae 17610 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17611 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
17612}
17613
4378f57c
DA
17614DEFUN (no_lcommunity_list_all,
17615 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
17616 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17617 NO_STR
17618 BGP_STR
17619 LCOMMUNITY_LIST_STR
17620 "Large Community list number (standard)\n"
17621 "Large Community list number (expanded)\n"
17622 "Large Community list name\n")
57d187bc 17623{
7336e101
SP
17624 return lcommunity_list_unset_vty(vty, argc, argv,
17625 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17626}
17627
4378f57c
DA
17628DEFUN (no_lcommunity_list_name_standard_all,
17629 no_bgp_lcommunity_list_name_standard_all_cmd,
17630 "no bgp large-community-list standard WORD",
17631 NO_STR
17632 BGP_STR
17633 LCOMMUNITY_LIST_STR
17634 "Specify standard large-community-list\n"
17635 "Large Community list name\n")
17636{
17637 return lcommunity_list_unset_vty(vty, argc, argv,
17638 LARGE_COMMUNITY_LIST_STANDARD);
17639}
17640
7336e101
SP
17641DEFUN (no_lcommunity_list_name_expanded_all,
17642 no_bgp_lcommunity_list_name_expanded_all_cmd,
17643 "no bgp large-community-list expanded WORD",
17644 NO_STR
17645 BGP_STR
17646 LCOMMUNITY_LIST_STR
17647 "Specify expanded large-community-list\n"
17648 "Large Community list name\n")
57d187bc 17649{
d62a17ae 17650 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17651 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17652}
17653
7336e101
SP
17654DEFUN (no_lcommunity_list_standard,
17655 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17656 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17657 NO_STR
17658 BGP_STR
17659 LCOMMUNITY_LIST_STR
17660 "Large Community list number (standard)\n"
2f8cc0e5
DA
17661 "Sequence number of an entry\n"
17662 "Sequence number\n"
7336e101
SP
17663 "Specify large community to reject\n"
17664 "Specify large community to accept\n"
17665 LCOMMUNITY_VAL_STR)
57d187bc 17666{
d62a17ae 17667 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17668 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17669}
17670
7336e101
SP
17671DEFUN (no_lcommunity_list_expanded,
17672 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17673 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17674 NO_STR
17675 BGP_STR
17676 LCOMMUNITY_LIST_STR
17677 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17678 "Sequence number of an entry\n"
17679 "Sequence number\n"
7336e101
SP
17680 "Specify large community to reject\n"
17681 "Specify large community to accept\n"
17682 "An ordered list as a regular-expression\n")
57d187bc 17683{
d62a17ae 17684 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17685 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17686}
17687
7336e101
SP
17688DEFUN (no_lcommunity_list_name_standard,
17689 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17690 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17691 NO_STR
17692 BGP_STR
17693 LCOMMUNITY_LIST_STR
17694 "Specify standard large-community-list\n"
17695 "Large Community list name\n"
2f8cc0e5
DA
17696 "Sequence number of an entry\n"
17697 "Sequence number\n"
7336e101
SP
17698 "Specify large community to reject\n"
17699 "Specify large community to accept\n"
17700 LCOMMUNITY_VAL_STR)
57d187bc 17701{
d62a17ae 17702 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17703 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17704}
17705
7336e101
SP
17706DEFUN (no_lcommunity_list_name_expanded,
17707 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17708 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17709 NO_STR
17710 BGP_STR
17711 LCOMMUNITY_LIST_STR
17712 "Specify expanded large-community-list\n"
17713 "Large community list name\n"
2f8cc0e5
DA
17714 "Sequence number of an entry\n"
17715 "Sequence number\n"
7336e101
SP
17716 "Specify large community to reject\n"
17717 "Specify large community to accept\n"
17718 "An ordered list as a regular-expression\n")
57d187bc 17719{
d62a17ae 17720 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17721 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17722}
17723
d62a17ae 17724static void lcommunity_list_show(struct vty *vty, struct community_list *list)
17725{
17726 struct community_entry *entry;
17727
17728 for (entry = list->head; entry; entry = entry->next) {
17729 if (entry == list->head) {
17730 if (all_digit(list->name))
17731 vty_out(vty, "Large community %s list %s\n",
169b72c8 17732 entry->style ==
17733 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17734 ? "standard"
17735 : "(expanded) access",
17736 list->name);
17737 else
17738 vty_out(vty,
17739 "Named large community %s list %s\n",
169b72c8 17740 entry->style ==
17741 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17742 ? "standard"
17743 : "expanded",
17744 list->name);
17745 }
17746 if (entry->any)
17747 vty_out(vty, " %s\n",
17748 community_direct_str(entry->direct));
17749 else
17750 vty_out(vty, " %s %s\n",
17751 community_direct_str(entry->direct),
8d9b8ed9 17752 community_list_config_str(entry));
d62a17ae 17753 }
57d187bc
JS
17754}
17755
7336e101
SP
17756DEFUN (show_lcommunity_list,
17757 show_bgp_lcommunity_list_cmd,
17758 "show bgp large-community-list",
57d187bc 17759 SHOW_STR
7336e101 17760 BGP_STR
57d187bc
JS
17761 "List large-community list\n")
17762{
d62a17ae 17763 struct community_list *list;
17764 struct community_list_master *cm;
57d187bc 17765
d62a17ae 17766 cm = community_list_master_lookup(bgp_clist,
17767 LARGE_COMMUNITY_LIST_MASTER);
17768 if (!cm)
17769 return CMD_SUCCESS;
57d187bc 17770
d62a17ae 17771 for (list = cm->num.head; list; list = list->next)
17772 lcommunity_list_show(vty, list);
57d187bc 17773
d62a17ae 17774 for (list = cm->str.head; list; list = list->next)
17775 lcommunity_list_show(vty, list);
57d187bc 17776
d62a17ae 17777 return CMD_SUCCESS;
57d187bc
JS
17778}
17779
7336e101
SP
17780DEFUN (show_lcommunity_list_arg,
17781 show_bgp_lcommunity_list_arg_cmd,
960b69b9 17782 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
17783 SHOW_STR
17784 BGP_STR
57d187bc 17785 "List large-community list\n"
960b69b9 17786 "Large-community-list number\n"
17787 "Large-community-list name\n"
17788 "Detailed information on large-community-list\n")
57d187bc 17789{
d62a17ae 17790 struct community_list *list;
57d187bc 17791
e237b0d2 17792 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 17793 LARGE_COMMUNITY_LIST_MASTER);
17794 if (!list) {
960b69b9 17795 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 17796 return CMD_WARNING;
17797 }
57d187bc 17798
d62a17ae 17799 lcommunity_list_show(vty, list);
57d187bc 17800
d62a17ae 17801 return CMD_SUCCESS;
57d187bc
JS
17802}
17803
718e3744 17804/* "extcommunity-list" keyword help string. */
17805#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
17806#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
17807
7336e101
SP
17808DEFUN (extcommunity_list_standard,
17809 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 17810 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17811 BGP_STR
718e3744 17812 EXTCOMMUNITY_LIST_STR
17813 "Extended Community list number (standard)\n"
718e3744 17814 "Specify standard extcommunity-list\n"
5bf15956 17815 "Community list name\n"
2f8cc0e5
DA
17816 "Sequence number of an entry\n"
17817 "Sequence number\n"
718e3744 17818 "Specify community to reject\n"
17819 "Specify community to accept\n"
17820 EXTCOMMUNITY_VAL_STR)
17821{
d62a17ae 17822 int style = EXTCOMMUNITY_LIST_STANDARD;
17823 int direct = 0;
17824 char *cl_number_or_name = NULL;
2f8cc0e5 17825 char *seq = NULL;
42f914d4 17826
d62a17ae 17827 int idx = 0;
7b9a4750 17828
d62a17ae 17829 argv_find(argv, argc, "(1-99)", &idx);
17830 argv_find(argv, argc, "WORD", &idx);
17831 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 17832
409148f6 17833 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
17834 seq = argv[idx]->arg;
17835
d62a17ae 17836 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17837 : COMMUNITY_DENY;
17838 argv_find(argv, argc, "AA:NN", &idx);
17839 char *str = argv_concat(argv, argc, idx);
42f914d4 17840
2f8cc0e5 17841 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17842 direct, style);
42f914d4 17843
d62a17ae 17844 XFREE(MTYPE_TMP, str);
42f914d4 17845
d62a17ae 17846 if (ret < 0) {
17847 community_list_perror(vty, ret);
17848 return CMD_WARNING_CONFIG_FAILED;
17849 }
42f914d4 17850
d62a17ae 17851 return CMD_SUCCESS;
718e3744 17852}
17853
7336e101
SP
17854DEFUN (extcommunity_list_name_expanded,
17855 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 17856 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17857 BGP_STR
17858 EXTCOMMUNITY_LIST_STR
5bf15956 17859 "Extended Community list number (expanded)\n"
718e3744 17860 "Specify expanded extcommunity-list\n"
17861 "Extended Community list name\n"
2f8cc0e5
DA
17862 "Sequence number of an entry\n"
17863 "Sequence number\n"
718e3744 17864 "Specify community to reject\n"
17865 "Specify community to accept\n"
17866 "An ordered list as a regular-expression\n")
17867{
d62a17ae 17868 int style = EXTCOMMUNITY_LIST_EXPANDED;
17869 int direct = 0;
17870 char *cl_number_or_name = NULL;
2f8cc0e5 17871 char *seq = NULL;
d62a17ae 17872 int idx = 0;
7336e101 17873
d62a17ae 17874 argv_find(argv, argc, "(100-500)", &idx);
17875 argv_find(argv, argc, "WORD", &idx);
17876 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 17877
409148f6 17878 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
17879 seq = argv[idx]->arg;
17880
d62a17ae 17881 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17882 : COMMUNITY_DENY;
17883 argv_find(argv, argc, "LINE", &idx);
17884 char *str = argv_concat(argv, argc, idx);
42f914d4 17885
2f8cc0e5 17886 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17887 direct, style);
42f914d4 17888
d62a17ae 17889 XFREE(MTYPE_TMP, str);
42f914d4 17890
d62a17ae 17891 if (ret < 0) {
17892 community_list_perror(vty, ret);
17893 return CMD_WARNING_CONFIG_FAILED;
17894 }
42f914d4 17895
d62a17ae 17896 return CMD_SUCCESS;
718e3744 17897}
17898
7336e101
SP
17899DEFUN (no_extcommunity_list_standard_all,
17900 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 17901 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17902 NO_STR
17903 BGP_STR
17904 EXTCOMMUNITY_LIST_STR
813d4307 17905 "Extended Community list number (standard)\n"
718e3744 17906 "Specify standard extcommunity-list\n"
5bf15956 17907 "Community list name\n"
2f8cc0e5
DA
17908 "Sequence number of an entry\n"
17909 "Sequence number\n"
718e3744 17910 "Specify community to reject\n"
17911 "Specify community to accept\n"
17912 EXTCOMMUNITY_VAL_STR)
17913{
d62a17ae 17914 int style = EXTCOMMUNITY_LIST_STANDARD;
17915 int direct = 0;
17916 char *cl_number_or_name = NULL;
d4455c89 17917 char *str = NULL;
2f8cc0e5 17918 char *seq = NULL;
d62a17ae 17919 int idx = 0;
d4455c89 17920
409148f6 17921 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
17922 seq = argv[idx]->arg;
17923
17924 idx = 0;
d4455c89
DA
17925 argv_find(argv, argc, "permit", &idx);
17926 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
17927 if (idx) {
17928 direct = argv_find(argv, argc, "permit", &idx)
17929 ? COMMUNITY_PERMIT
17930 : COMMUNITY_DENY;
17931
17932 idx = 0;
17933 argv_find(argv, argc, "AA:NN", &idx);
17934 str = argv_concat(argv, argc, idx);
17935 }
17936
17937 idx = 0;
d62a17ae 17938 argv_find(argv, argc, "(1-99)", &idx);
17939 argv_find(argv, argc, "WORD", &idx);
17940 cl_number_or_name = argv[idx]->arg;
42f914d4 17941
d62a17ae 17942 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 17943 seq, direct, style);
42f914d4 17944
d62a17ae 17945 XFREE(MTYPE_TMP, str);
42f914d4 17946
d62a17ae 17947 if (ret < 0) {
17948 community_list_perror(vty, ret);
17949 return CMD_WARNING_CONFIG_FAILED;
17950 }
42f914d4 17951
d62a17ae 17952 return CMD_SUCCESS;
718e3744 17953}
17954
d4455c89
DA
17955ALIAS(no_extcommunity_list_standard_all,
17956 no_bgp_extcommunity_list_standard_all_list_cmd,
17957 "no bgp extcommunity-list <(1-99)|standard WORD>",
17958 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17959 "Extended Community list number (standard)\n"
17960 "Specify standard extcommunity-list\n"
17961 "Community list name\n")
17962
7336e101
SP
17963DEFUN (no_extcommunity_list_expanded_all,
17964 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 17965 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17966 NO_STR
17967 BGP_STR
17968 EXTCOMMUNITY_LIST_STR
718e3744 17969 "Extended Community list number (expanded)\n"
718e3744 17970 "Specify expanded extcommunity-list\n"
5bf15956 17971 "Extended Community list name\n"
2f8cc0e5
DA
17972 "Sequence number of an entry\n"
17973 "Sequence number\n"
718e3744 17974 "Specify community to reject\n"
17975 "Specify community to accept\n"
17976 "An ordered list as a regular-expression\n")
17977{
d62a17ae 17978 int style = EXTCOMMUNITY_LIST_EXPANDED;
17979 int direct = 0;
17980 char *cl_number_or_name = NULL;
d4455c89 17981 char *str = NULL;
2f8cc0e5 17982 char *seq = NULL;
d62a17ae 17983 int idx = 0;
d4455c89 17984
409148f6 17985 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
17986 seq = argv[idx]->arg;
17987
17988 idx = 0;
d4455c89
DA
17989 argv_find(argv, argc, "permit", &idx);
17990 argv_find(argv, argc, "deny", &idx);
17991
17992 if (idx) {
17993 direct = argv_find(argv, argc, "permit", &idx)
17994 ? COMMUNITY_PERMIT
17995 : COMMUNITY_DENY;
17996
17997 idx = 0;
17998 argv_find(argv, argc, "LINE", &idx);
17999 str = argv_concat(argv, argc, idx);
18000 }
18001
18002 idx = 0;
d62a17ae 18003 argv_find(argv, argc, "(100-500)", &idx);
18004 argv_find(argv, argc, "WORD", &idx);
18005 cl_number_or_name = argv[idx]->arg;
42f914d4 18006
d62a17ae 18007 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18008 seq, direct, style);
42f914d4 18009
d62a17ae 18010 XFREE(MTYPE_TMP, str);
42f914d4 18011
d62a17ae 18012 if (ret < 0) {
18013 community_list_perror(vty, ret);
18014 return CMD_WARNING_CONFIG_FAILED;
18015 }
42f914d4 18016
d62a17ae 18017 return CMD_SUCCESS;
718e3744 18018}
18019
d4455c89
DA
18020ALIAS(no_extcommunity_list_expanded_all,
18021 no_bgp_extcommunity_list_expanded_all_list_cmd,
18022 "no bgp extcommunity-list <(100-500)|expanded WORD>",
18023 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18024 "Extended Community list number (expanded)\n"
18025 "Specify expanded extcommunity-list\n"
18026 "Extended Community list name\n")
18027
d62a17ae 18028static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 18029{
d62a17ae 18030 struct community_entry *entry;
718e3744 18031
d62a17ae 18032 for (entry = list->head; entry; entry = entry->next) {
18033 if (entry == list->head) {
18034 if (all_digit(list->name))
18035 vty_out(vty, "Extended community %s list %s\n",
18036 entry->style == EXTCOMMUNITY_LIST_STANDARD
18037 ? "standard"
18038 : "(expanded) access",
18039 list->name);
18040 else
18041 vty_out(vty,
18042 "Named extended community %s list %s\n",
18043 entry->style == EXTCOMMUNITY_LIST_STANDARD
18044 ? "standard"
18045 : "expanded",
18046 list->name);
18047 }
18048 if (entry->any)
18049 vty_out(vty, " %s\n",
18050 community_direct_str(entry->direct));
18051 else
18052 vty_out(vty, " %s %s\n",
18053 community_direct_str(entry->direct),
8d9b8ed9 18054 community_list_config_str(entry));
d62a17ae 18055 }
718e3744 18056}
18057
7336e101
SP
18058DEFUN (show_extcommunity_list,
18059 show_bgp_extcommunity_list_cmd,
18060 "show bgp extcommunity-list",
718e3744 18061 SHOW_STR
7336e101 18062 BGP_STR
718e3744 18063 "List extended-community list\n")
18064{
d62a17ae 18065 struct community_list *list;
18066 struct community_list_master *cm;
718e3744 18067
d62a17ae 18068 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18069 if (!cm)
18070 return CMD_SUCCESS;
718e3744 18071
d62a17ae 18072 for (list = cm->num.head; list; list = list->next)
18073 extcommunity_list_show(vty, list);
718e3744 18074
d62a17ae 18075 for (list = cm->str.head; list; list = list->next)
18076 extcommunity_list_show(vty, list);
718e3744 18077
d62a17ae 18078 return CMD_SUCCESS;
718e3744 18079}
18080
7336e101
SP
18081DEFUN (show_extcommunity_list_arg,
18082 show_bgp_extcommunity_list_arg_cmd,
960b69b9 18083 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
18084 SHOW_STR
18085 BGP_STR
718e3744 18086 "List extended-community list\n"
18087 "Extcommunity-list number\n"
960b69b9 18088 "Extcommunity-list name\n"
18089 "Detailed information on extcommunity-list\n")
718e3744 18090{
d62a17ae 18091 int idx_comm_list = 3;
18092 struct community_list *list;
718e3744 18093
e237b0d2 18094 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18095 EXTCOMMUNITY_LIST_MASTER);
18096 if (!list) {
18097 vty_out(vty, "%% Can't find extcommunity-list\n");
18098 return CMD_WARNING;
18099 }
718e3744 18100
d62a17ae 18101 extcommunity_list_show(vty, list);
718e3744 18102
d62a17ae 18103 return CMD_SUCCESS;
718e3744 18104}
6b0655a2 18105
718e3744 18106/* Display community-list and extcommunity-list configuration. */
d62a17ae 18107static int community_list_config_write(struct vty *vty)
18108{
18109 struct community_list *list;
18110 struct community_entry *entry;
18111 struct community_list_master *cm;
18112 int write = 0;
18113
18114 /* Community-list. */
18115 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18116
18117 for (list = cm->num.head; list; list = list->next)
18118 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18119 vty_out(vty,
18120 "bgp community-list %s seq %" PRId64 " %s %s\n",
18121 list->name, entry->seq,
d62a17ae 18122 community_direct_str(entry->direct),
18123 community_list_config_str(entry));
18124 write++;
18125 }
18126 for (list = cm->str.head; list; list = list->next)
18127 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18128 vty_out(vty,
18129 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 18130 entry->style == COMMUNITY_LIST_STANDARD
18131 ? "standard"
18132 : "expanded",
2f8cc0e5
DA
18133 list->name, entry->seq,
18134 community_direct_str(entry->direct),
d62a17ae 18135 community_list_config_str(entry));
18136 write++;
18137 }
18138
18139 /* Extcommunity-list. */
18140 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18141
18142 for (list = cm->num.head; list; list = list->next)
18143 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18144 vty_out(vty,
18145 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
18146 list->name, entry->seq,
18147 community_direct_str(entry->direct),
d62a17ae 18148 community_list_config_str(entry));
18149 write++;
18150 }
18151 for (list = cm->str.head; list; list = list->next)
18152 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18153 vty_out(vty,
6cde4b45 18154 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 18155 entry->style == EXTCOMMUNITY_LIST_STANDARD
18156 ? "standard"
18157 : "expanded",
2f8cc0e5
DA
18158 list->name, entry->seq,
18159 community_direct_str(entry->direct),
d62a17ae 18160 community_list_config_str(entry));
18161 write++;
18162 }
18163
18164
18165 /* lcommunity-list. */
18166 cm = community_list_master_lookup(bgp_clist,
18167 LARGE_COMMUNITY_LIST_MASTER);
18168
18169 for (list = cm->num.head; list; list = list->next)
18170 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18171 vty_out(vty,
6cde4b45 18172 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
18173 list->name, entry->seq,
18174 community_direct_str(entry->direct),
d62a17ae 18175 community_list_config_str(entry));
18176 write++;
18177 }
18178 for (list = cm->str.head; list; list = list->next)
18179 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18180 vty_out(vty,
6cde4b45 18181 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 18182
d62a17ae 18183 entry->style == LARGE_COMMUNITY_LIST_STANDARD
18184 ? "standard"
18185 : "expanded",
2f8cc0e5 18186 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 18187 community_list_config_str(entry));
18188 write++;
18189 }
18190
18191 return write;
18192}
18193
612c2c15 18194static int community_list_config_write(struct vty *vty);
d62a17ae 18195static struct cmd_node community_list_node = {
f4b8291f 18196 .name = "community list",
62b346ee
DL
18197 .node = COMMUNITY_LIST_NODE,
18198 .prompt = "",
612c2c15 18199 .config_write = community_list_config_write,
718e3744 18200};
18201
d62a17ae 18202static void community_list_vty(void)
18203{
612c2c15 18204 install_node(&community_list_node);
d62a17ae 18205
18206 /* Community-list. */
7336e101
SP
18207 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
18208 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
18209 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 18210 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 18211 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 18212 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
18213 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
18214 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 18215
18216 /* Extcommunity-list. */
7336e101
SP
18217 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
18218 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
18219 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
18220 install_element(CONFIG_NODE,
18221 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 18222 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
18223 install_element(CONFIG_NODE,
18224 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
18225 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
18226 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 18227
18228 /* Large Community List */
7336e101 18229 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
18230 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
18231 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 18232 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
18233 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
18234 install_element(CONFIG_NODE,
18235 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
18236 install_element(CONFIG_NODE,
18237 &no_bgp_lcommunity_list_name_expanded_all_cmd);
18238 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
18239 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
18240 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
18241 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
18242 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
18243 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 18244}