]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #6237 from ton31337/fix/show_hostname_in_bgp
[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"
dcc68b5e 68#include "bgpd/bgp_addpath.h"
48ecf8f5 69#include "bgpd/bgp_mac.h"
dd65f45e 70#include "bgpd/bgp_flowspec.h"
49e5a4a0 71#ifdef ENABLE_BGP_VNC
dd65f45e
DL
72#include "bgpd/rfapi/bgp_rfapi_cfg.h"
73#endif
74
5d5393b9 75FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
4c1458b5
DL
76 { .val_bool = true, .match_profile = "datacenter", },
77 { .val_bool = false },
5d5393b9
DL
78)
79FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
80 { .val_bool = true, .match_profile = "datacenter", },
81 { .val_bool = false },
5d5393b9
DL
82)
83FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
84 { .val_bool = true, .match_profile = "datacenter", },
85 { .val_bool = false },
5d5393b9
DL
86)
87FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
88 { .val_bool = true, .match_profile = "datacenter", },
89 { .val_bool = false },
5d5393b9
DL
90)
91FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
92 { .val_ulong = 10, .match_profile = "datacenter", },
93 { .val_ulong = 120 },
94)
95FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
96 { .val_ulong = 9, .match_profile = "datacenter", },
97 { .val_ulong = 180 },
98)
99FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
100 { .val_ulong = 3, .match_profile = "datacenter", },
101 { .val_ulong = 60 },
102)
103
dd65f45e
DL
104DEFINE_HOOK(bgp_inst_config_write,
105 (struct bgp *bgp, struct vty *vty),
106 (bgp, vty))
718e3744 107
36235319
QY
108#define GR_NO_OPER \
109 "The Graceful Restart No Operation was executed as cmd same as previous one."
110#define GR_INVALID \
111 "The Graceful Restart command used is not valid at this moment."
d62a17ae 112static struct peer_group *listen_range_exists(struct bgp *bgp,
113 struct prefix *range, int exact);
114
055679e9 115/* Show BGP peer's information. */
116enum show_type {
117 show_all,
118 show_peer,
119 show_ipv4_all,
120 show_ipv6_all,
121 show_ipv4_peer,
122 show_ipv6_peer
123};
124
36235319
QY
125static struct peer_group *listen_range_exists(struct bgp *bgp,
126 struct prefix *range, int exact);
2986cac2 127
36235319
QY
128static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
129 struct bgp *bgp,
130 bool use_json,
131 json_object *json);
2986cac2 132
36235319
QY
133static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
134 enum show_type type,
135 const char *ip_str,
136 afi_t afi, bool use_json);
2986cac2 137
d62a17ae 138static enum node_type bgp_node_type(afi_t afi, safi_t safi)
139{
140 switch (afi) {
141 case AFI_IP:
142 switch (safi) {
143 case SAFI_UNICAST:
144 return BGP_IPV4_NODE;
d62a17ae 145 case SAFI_MULTICAST:
146 return BGP_IPV4M_NODE;
d62a17ae 147 case SAFI_LABELED_UNICAST:
148 return BGP_IPV4L_NODE;
d62a17ae 149 case SAFI_MPLS_VPN:
150 return BGP_VPNV4_NODE;
7c40bf39 151 case SAFI_FLOWSPEC:
152 return BGP_FLOWSPECV4_NODE;
5c525538
RW
153 default:
154 /* not expected */
155 return BGP_IPV4_NODE;
d62a17ae 156 }
157 break;
158 case AFI_IP6:
159 switch (safi) {
160 case SAFI_UNICAST:
161 return BGP_IPV6_NODE;
d62a17ae 162 case SAFI_MULTICAST:
163 return BGP_IPV6M_NODE;
d62a17ae 164 case SAFI_LABELED_UNICAST:
165 return BGP_IPV6L_NODE;
d62a17ae 166 case SAFI_MPLS_VPN:
167 return BGP_VPNV6_NODE;
7c40bf39 168 case SAFI_FLOWSPEC:
169 return BGP_FLOWSPECV6_NODE;
5c525538
RW
170 default:
171 /* not expected */
172 return BGP_IPV4_NODE;
d62a17ae 173 }
174 break;
175 case AFI_L2VPN:
176 return BGP_EVPN_NODE;
b26f891d 177 case AFI_UNSPEC:
d62a17ae 178 case AFI_MAX:
179 // We should never be here but to clarify the switch statement..
180 return BGP_IPV4_NODE;
d62a17ae 181 }
182
183 // Impossible to happen
184 return BGP_IPV4_NODE;
f51bae9c 185}
20eb8864 186
5cb5f4d0
DD
187static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
188{
189 if (afi == AFI_IP && safi == SAFI_UNICAST)
190 return "IPv4 Unicast";
191 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
192 return "IPv4 Multicast";
193 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
194 return "IPv4 Labeled Unicast";
195 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
196 return "IPv4 VPN";
197 else if (afi == AFI_IP && safi == SAFI_ENCAP)
198 return "IPv4 Encap";
199 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
200 return "IPv4 Flowspec";
201 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
202 return "IPv6 Unicast";
203 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
204 return "IPv6 Multicast";
205 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
206 return "IPv6 Labeled Unicast";
207 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
208 return "IPv6 VPN";
209 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
210 return "IPv6 Encap";
211 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
212 return "IPv6 Flowspec";
213 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
214 return "L2VPN EVPN";
8e5509b0 215 else
5cb5f4d0 216 return "Unknown";
5cb5f4d0
DD
217}
218
219/*
220 * Please note that we have intentionally camelCased
221 * the return strings here. So if you want
222 * to use this function, please ensure you
223 * are doing this within json output
224 */
225static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
226{
227 if (afi == AFI_IP && safi == SAFI_UNICAST)
228 return "ipv4Unicast";
229 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
230 return "ipv4Multicast";
231 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
232 return "ipv4LabeledUnicast";
233 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
234 return "ipv4Vpn";
235 else if (afi == AFI_IP && safi == SAFI_ENCAP)
236 return "ipv4Encap";
237 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
238 return "ipv4Flowspec";
239 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
240 return "ipv6Unicast";
241 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
242 return "ipv6Multicast";
243 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
244 return "ipv6LabeledUnicast";
245 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
246 return "ipv6Vpn";
247 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
248 return "ipv6Encap";
249 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
250 return "ipv6Flowspec";
251 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
252 return "l2VpnEvpn";
8e5509b0 253 else
5cb5f4d0 254 return "Unknown";
5cb5f4d0
DD
255}
256
718e3744 257/* Utility function to get address family from current node. */
d62a17ae 258afi_t bgp_node_afi(struct vty *vty)
259{
260 afi_t afi;
261 switch (vty->node) {
262 case BGP_IPV6_NODE:
263 case BGP_IPV6M_NODE:
264 case BGP_IPV6L_NODE:
265 case BGP_VPNV6_NODE:
7c40bf39 266 case BGP_FLOWSPECV6_NODE:
d62a17ae 267 afi = AFI_IP6;
268 break;
269 case BGP_EVPN_NODE:
270 afi = AFI_L2VPN;
271 break;
272 default:
273 afi = AFI_IP;
274 break;
275 }
276 return afi;
718e3744 277}
278
279/* Utility function to get subsequent address family from current
280 node. */
d62a17ae 281safi_t bgp_node_safi(struct vty *vty)
282{
283 safi_t safi;
284 switch (vty->node) {
285 case BGP_VPNV4_NODE:
286 case BGP_VPNV6_NODE:
287 safi = SAFI_MPLS_VPN;
288 break;
289 case BGP_IPV4M_NODE:
290 case BGP_IPV6M_NODE:
291 safi = SAFI_MULTICAST;
292 break;
293 case BGP_EVPN_NODE:
294 safi = SAFI_EVPN;
295 break;
296 case BGP_IPV4L_NODE:
297 case BGP_IPV6L_NODE:
298 safi = SAFI_LABELED_UNICAST;
299 break;
7c40bf39 300 case BGP_FLOWSPECV4_NODE:
301 case BGP_FLOWSPECV6_NODE:
302 safi = SAFI_FLOWSPEC;
303 break;
d62a17ae 304 default:
305 safi = SAFI_UNICAST;
306 break;
307 }
308 return safi;
718e3744 309}
310
55f91488
QY
311/**
312 * Converts an AFI in string form to afi_t
313 *
314 * @param afi string, one of
315 * - "ipv4"
316 * - "ipv6"
81cf0de5 317 * - "l2vpn"
55f91488
QY
318 * @return the corresponding afi_t
319 */
d62a17ae 320afi_t bgp_vty_afi_from_str(const char *afi_str)
321{
322 afi_t afi = AFI_MAX; /* unknown */
323 if (strmatch(afi_str, "ipv4"))
324 afi = AFI_IP;
325 else if (strmatch(afi_str, "ipv6"))
326 afi = AFI_IP6;
81cf0de5
CS
327 else if (strmatch(afi_str, "l2vpn"))
328 afi = AFI_L2VPN;
d62a17ae 329 return afi;
330}
331
332int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
333 afi_t *afi)
334{
335 int ret = 0;
336 if (argv_find(argv, argc, "ipv4", index)) {
337 ret = 1;
338 if (afi)
339 *afi = AFI_IP;
340 } else if (argv_find(argv, argc, "ipv6", index)) {
341 ret = 1;
342 if (afi)
343 *afi = AFI_IP6;
8688b3e7
DS
344 } else if (argv_find(argv, argc, "l2vpn", index)) {
345 ret = 1;
346 if (afi)
347 *afi = AFI_L2VPN;
d62a17ae 348 }
349 return ret;
46f296b4
LB
350}
351
375a2e67 352/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 353safi_t bgp_vty_safi_from_str(const char *safi_str)
354{
355 safi_t safi = SAFI_MAX; /* unknown */
356 if (strmatch(safi_str, "multicast"))
357 safi = SAFI_MULTICAST;
358 else if (strmatch(safi_str, "unicast"))
359 safi = SAFI_UNICAST;
360 else if (strmatch(safi_str, "vpn"))
361 safi = SAFI_MPLS_VPN;
81cf0de5
CS
362 else if (strmatch(safi_str, "evpn"))
363 safi = SAFI_EVPN;
d62a17ae 364 else if (strmatch(safi_str, "labeled-unicast"))
365 safi = SAFI_LABELED_UNICAST;
7c40bf39 366 else if (strmatch(safi_str, "flowspec"))
367 safi = SAFI_FLOWSPEC;
d62a17ae 368 return safi;
369}
370
371int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
372 safi_t *safi)
373{
374 int ret = 0;
375 if (argv_find(argv, argc, "unicast", index)) {
376 ret = 1;
377 if (safi)
378 *safi = SAFI_UNICAST;
379 } else if (argv_find(argv, argc, "multicast", index)) {
380 ret = 1;
381 if (safi)
382 *safi = SAFI_MULTICAST;
383 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
384 ret = 1;
385 if (safi)
386 *safi = SAFI_LABELED_UNICAST;
387 } else if (argv_find(argv, argc, "vpn", index)) {
388 ret = 1;
389 if (safi)
390 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
391 } else if (argv_find(argv, argc, "evpn", index)) {
392 ret = 1;
393 if (safi)
394 *safi = SAFI_EVPN;
7c40bf39 395 } else if (argv_find(argv, argc, "flowspec", index)) {
396 ret = 1;
397 if (safi)
398 *safi = SAFI_FLOWSPEC;
d62a17ae 399 }
400 return ret;
46f296b4
LB
401}
402
5d5393b9
DL
403int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
404 enum bgp_instance_type inst_type)
405{
406 int ret = bgp_get(bgp, as, name, inst_type);
407
408 if (ret == BGP_CREATED) {
409 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
410 DFLT_BGP_CONNECT_RETRY);
411
412 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 413 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 414 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 415 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
5d5393b9 416 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 417 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 418 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 419 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
5d5393b9
DL
420
421 ret = BGP_SUCCESS;
422 }
423 return ret;
424}
425
7eeee51e 426/*
f212a857 427 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 428 *
f212a857
DS
429 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
430 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
431 * to appropriate values for the calling function. This is to allow the
432 * calling function to make decisions appropriate for the show command
433 * that is being parsed.
434 *
435 * The show commands are generally of the form:
d62a17ae 436 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
437 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
438 *
439 * Since we use argv_find if the show command in particular doesn't have:
440 * [ip]
18c57037 441 * [<view|vrf> VIEWVRFNAME]
375a2e67 442 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
443 * The command parsing should still be ok.
444 *
445 * vty -> The vty for the command so we can output some useful data in
446 * the event of a parse error in the vrf.
447 * argv -> The command tokens
448 * argc -> How many command tokens we have
d62a17ae 449 * idx -> The current place in the command, generally should be 0 for this
450 * function
7eeee51e
DS
451 * afi -> The parsed afi if it was included in the show command, returned here
452 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 453 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 454 * use_json -> json is configured or not
7eeee51e
DS
455 *
456 * The function returns the correct location in the parse tree for the
457 * last token found.
0e37c258
DS
458 *
459 * Returns 0 for failure to parse correctly, else the idx position of where
460 * it found the last token.
7eeee51e 461 */
d62a17ae 462int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
463 struct cmd_token **argv, int argc,
464 int *idx, afi_t *afi, safi_t *safi,
9f049418 465 struct bgp **bgp, bool use_json)
d62a17ae 466{
467 char *vrf_name = NULL;
468
469 assert(afi);
470 assert(safi);
471 assert(bgp);
472
473 if (argv_find(argv, argc, "ip", idx))
474 *afi = AFI_IP;
475
9a8bdf1c 476 if (argv_find(argv, argc, "view", idx))
d62a17ae 477 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
478 else if (argv_find(argv, argc, "vrf", idx)) {
479 vrf_name = argv[*idx + 1]->arg;
480 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
481 vrf_name = NULL;
482 }
483 if (vrf_name) {
d62a17ae 484 if (strmatch(vrf_name, "all"))
485 *bgp = NULL;
486 else {
487 *bgp = bgp_lookup_by_name(vrf_name);
488 if (!*bgp) {
52e5b8c4
SP
489 if (use_json) {
490 json_object *json = NULL;
491 json = json_object_new_object();
492 json_object_string_add(
493 json, "warning",
494 "View/Vrf is unknown");
495 vty_out(vty, "%s\n",
496 json_object_to_json_string_ext(json,
497 JSON_C_TO_STRING_PRETTY));
498 json_object_free(json);
499 }
ca61fd25
DS
500 else
501 vty_out(vty, "View/Vrf %s is unknown\n",
502 vrf_name);
d62a17ae 503 *idx = 0;
504 return 0;
505 }
506 }
507 } else {
508 *bgp = bgp_get_default();
509 if (!*bgp) {
52e5b8c4
SP
510 if (use_json) {
511 json_object *json = NULL;
512 json = json_object_new_object();
513 json_object_string_add(
514 json, "warning",
515 "Default BGP instance not found");
516 vty_out(vty, "%s\n",
517 json_object_to_json_string_ext(json,
518 JSON_C_TO_STRING_PRETTY));
519 json_object_free(json);
520 }
ca61fd25
DS
521 else
522 vty_out(vty,
523 "Default BGP instance not found\n");
d62a17ae 524 *idx = 0;
525 return 0;
526 }
527 }
528
529 if (argv_find_and_parse_afi(argv, argc, idx, afi))
530 argv_find_and_parse_safi(argv, argc, idx, safi);
531
532 *idx += 1;
533 return *idx;
534}
535
3dc339cd 536static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 537{
538 struct interface *ifp = NULL;
539
540 if (su->sa.sa_family == AF_INET)
541 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
542 else if (su->sa.sa_family == AF_INET6)
543 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
544 su->sin6.sin6_scope_id,
545 bgp->vrf_id);
546
547 if (ifp)
3dc339cd 548 return true;
d62a17ae 549
3dc339cd 550 return false;
718e3744 551}
552
553/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
554/* This is used only for configuration, so disallow if attempted on
555 * a dynamic neighbor.
556 */
d62a17ae 557static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
558{
559 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
560 int ret;
561 union sockunion su;
562 struct peer *peer;
563
564 if (!bgp) {
565 return NULL;
566 }
567
568 ret = str2sockunion(ip_str, &su);
569 if (ret < 0) {
570 peer = peer_lookup_by_conf_if(bgp, ip_str);
571 if (!peer) {
572 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
573 == NULL) {
574 vty_out(vty,
575 "%% Malformed address or name: %s\n",
576 ip_str);
577 return NULL;
578 }
579 }
580 } else {
581 peer = peer_lookup(bgp, &su);
582 if (!peer) {
583 vty_out(vty,
584 "%% Specify remote-as or peer-group commands first\n");
585 return NULL;
586 }
587 if (peer_dynamic_neighbor(peer)) {
588 vty_out(vty,
589 "%% Operation not allowed on a dynamic neighbor\n");
590 return NULL;
591 }
592 }
593 return peer;
718e3744 594}
595
596/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
597/* This is used only for configuration, so disallow if attempted on
598 * a dynamic neighbor.
599 */
d62a17ae 600struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
601{
602 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
603 int ret;
604 union sockunion su;
605 struct peer *peer = NULL;
606 struct peer_group *group = NULL;
607
608 if (!bgp) {
609 return NULL;
610 }
611
612 ret = str2sockunion(peer_str, &su);
613 if (ret == 0) {
614 /* IP address, locate peer. */
615 peer = peer_lookup(bgp, &su);
616 } else {
617 /* Not IP, could match either peer configured on interface or a
618 * group. */
619 peer = peer_lookup_by_conf_if(bgp, peer_str);
620 if (!peer)
621 group = peer_group_lookup(bgp, peer_str);
622 }
623
624 if (peer) {
625 if (peer_dynamic_neighbor(peer)) {
626 vty_out(vty,
627 "%% Operation not allowed on a dynamic neighbor\n");
628 return NULL;
629 }
630
631 return peer;
632 }
633
634 if (group)
635 return group->conf;
636
637 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
638
639 return NULL;
640}
641
642int bgp_vty_return(struct vty *vty, int ret)
643{
644 const char *str = NULL;
645
646 switch (ret) {
647 case BGP_ERR_INVALID_VALUE:
648 str = "Invalid value";
649 break;
650 case BGP_ERR_INVALID_FLAG:
651 str = "Invalid flag";
652 break;
653 case BGP_ERR_PEER_GROUP_SHUTDOWN:
654 str = "Peer-group has been shutdown. Activate the peer-group first";
655 break;
656 case BGP_ERR_PEER_FLAG_CONFLICT:
657 str = "Can't set override-capability and strict-capability-match at the same time";
658 break;
659 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
660 str = "Specify remote-as or peer-group remote AS first";
661 break;
662 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
663 str = "Cannot change the peer-group. Deconfigure first";
664 break;
665 case BGP_ERR_PEER_GROUP_MISMATCH:
666 str = "Peer is not a member of this peer-group";
667 break;
668 case BGP_ERR_PEER_FILTER_CONFLICT:
669 str = "Prefix/distribute list can not co-exist";
670 break;
671 case BGP_ERR_NOT_INTERNAL_PEER:
672 str = "Invalid command. Not an internal neighbor";
673 break;
674 case BGP_ERR_REMOVE_PRIVATE_AS:
675 str = "remove-private-AS cannot be configured for IBGP peers";
676 break;
677 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
678 str = "Local-AS allowed only for EBGP peers";
679 break;
680 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
681 str = "Cannot have local-as same as BGP AS number";
682 break;
683 case BGP_ERR_TCPSIG_FAILED:
684 str = "Error while applying TCP-Sig to session(s)";
685 break;
686 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
687 str = "ebgp-multihop and ttl-security cannot be configured together";
688 break;
689 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
690 str = "ttl-security only allowed for EBGP peers";
691 break;
692 case BGP_ERR_AS_OVERRIDE:
693 str = "as-override cannot be configured for IBGP peers";
694 break;
695 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
696 str = "Invalid limit for number of dynamic neighbors";
697 break;
698 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
699 str = "Dynamic neighbor listen range already exists";
700 break;
701 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
702 str = "Operation not allowed on a dynamic neighbor";
703 break;
704 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
705 str = "Operation not allowed on a directly connected neighbor";
706 break;
707 case BGP_ERR_PEER_SAFI_CONFLICT:
055679e9 708 str = GR_INVALID;
709 break;
710 case BGP_ERR_GR_INVALID_CMD:
711 str = "The Graceful Restart command used is not valid at this moment.";
712 break;
713 case BGP_ERR_GR_OPERATION_FAILED:
714 str = "The Graceful Restart Operation failed due to an err.";
715 break;
716 case BGP_GR_NO_OPERATION:
717 str = GR_NO_OPER;
d62a17ae 718 break;
719 }
720 if (str) {
721 vty_out(vty, "%% %s\n", str);
722 return CMD_WARNING_CONFIG_FAILED;
723 }
724 return CMD_SUCCESS;
718e3744 725}
726
7aafcaca 727/* BGP clear sort. */
d62a17ae 728enum clear_sort {
729 clear_all,
730 clear_peer,
731 clear_group,
732 clear_external,
733 clear_as
7aafcaca
DS
734};
735
d62a17ae 736static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
737 safi_t safi, int error)
738{
739 switch (error) {
740 case BGP_ERR_AF_UNCONFIGURED:
741 vty_out(vty,
742 "%%BGP: Enable %s address family for the neighbor %s\n",
5cb5f4d0 743 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 744 break;
745 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
746 vty_out(vty,
747 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
748 peer->host);
749 break;
750 default:
751 break;
752 }
7aafcaca
DS
753}
754
dc912615 755static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 756 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
757{
758 int ret = 0;
759
760 /* if afi/.safi not specified, spin thru all of them */
761 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
762 afi_t tmp_afi;
763 safi_t tmp_safi;
764
765 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
766 if (!peer->afc[tmp_afi][tmp_safi])
767 continue;
768
769 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 770 ret = peer_clear(peer, nnode);
dc912615
DS
771 else
772 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
773 stype);
774 }
775 /* if afi specified and safi not, spin thru safis on this afi */
776 } else if (safi == SAFI_UNSPEC) {
777 safi_t tmp_safi;
778
779 for (tmp_safi = SAFI_UNICAST;
780 tmp_safi < SAFI_MAX; tmp_safi++) {
781 if (!peer->afc[afi][tmp_safi])
782 continue;
783
784 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 785 ret = peer_clear(peer, nnode);
dc912615
DS
786 else
787 ret = peer_clear_soft(peer, afi,
788 tmp_safi, stype);
789 }
790 /* both afi/safi specified, let the caller know if not defined */
791 } else {
792 if (!peer->afc[afi][safi])
793 return 1;
794
795 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 796 ret = peer_clear(peer, nnode);
dc912615
DS
797 else
798 ret = peer_clear_soft(peer, afi, safi, stype);
799 }
800
801 return ret;
802}
803
7aafcaca 804/* `clear ip bgp' functions. */
d62a17ae 805static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
806 enum clear_sort sort, enum bgp_clear_type stype,
807 const char *arg)
808{
dc912615 809 int ret = 0;
3ae8bfa5 810 bool found = false;
d62a17ae 811 struct peer *peer;
dc95985f 812
813 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 814
815 /* Clear all neighbors. */
816 /*
817 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
818 * nodes on the BGP instance as that may get freed if it is a
819 * doppelganger
d62a17ae 820 */
821 if (sort == clear_all) {
822 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 823
824 bgp_peer_gr_flags_update(peer);
825
36235319 826 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 827 gr_router_detected = true;
828
c368171c 829 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 830 stype);
d62a17ae 831
832 if (ret < 0)
833 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 834 }
835
36235319
QY
836 if (gr_router_detected
837 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 838 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
839 } else if (!gr_router_detected
840 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 841 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 842 }
d62a17ae 843
844 /* This is to apply read-only mode on this clear. */
845 if (stype == BGP_CLEAR_SOFT_NONE)
846 bgp->update_delay_over = 0;
847
848 return CMD_SUCCESS;
7aafcaca
DS
849 }
850
3ae8bfa5 851 /* Clear specified neighbor. */
d62a17ae 852 if (sort == clear_peer) {
853 union sockunion su;
d62a17ae 854
855 /* Make sockunion for lookup. */
856 ret = str2sockunion(arg, &su);
857 if (ret < 0) {
858 peer = peer_lookup_by_conf_if(bgp, arg);
859 if (!peer) {
860 peer = peer_lookup_by_hostname(bgp, arg);
861 if (!peer) {
862 vty_out(vty,
863 "Malformed address or name: %s\n",
864 arg);
865 return CMD_WARNING;
866 }
867 }
868 } else {
869 peer = peer_lookup(bgp, &su);
870 if (!peer) {
871 vty_out(vty,
872 "%%BGP: Unknown neighbor - \"%s\"\n",
873 arg);
874 return CMD_WARNING;
875 }
876 }
7aafcaca 877
dc95985f 878 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
879 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
880
dc912615
DS
881 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
882
883 /* if afi/safi not defined for this peer, let caller know */
884 if (ret == 1)
3ae8bfa5 885 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 886
d62a17ae 887 if (ret < 0)
888 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 889
d62a17ae 890 return CMD_SUCCESS;
7aafcaca 891 }
7aafcaca 892
3ae8bfa5 893 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 894 if (sort == clear_group) {
895 struct peer_group *group;
7aafcaca 896
d62a17ae 897 group = peer_group_lookup(bgp, arg);
898 if (!group) {
899 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
900 return CMD_WARNING;
901 }
902
903 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 904 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 905
d62a17ae 906 if (ret < 0)
907 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
908 else
909 found = true;
d62a17ae 910 }
3ae8bfa5
PM
911
912 if (!found)
913 vty_out(vty,
914 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 915 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 916
d62a17ae 917 return CMD_SUCCESS;
7aafcaca 918 }
7aafcaca 919
3ae8bfa5 920 /* Clear all external (eBGP) neighbors. */
d62a17ae 921 if (sort == clear_external) {
922 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
923 if (peer->sort == BGP_PEER_IBGP)
924 continue;
7aafcaca 925
dc95985f 926 bgp_peer_gr_flags_update(peer);
927
36235319 928 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 929 gr_router_detected = true;
dc95985f 930
c368171c 931 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 932
d62a17ae 933 if (ret < 0)
934 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
935 else
936 found = true;
d62a17ae 937 }
3ae8bfa5 938
36235319
QY
939 if (gr_router_detected
940 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 941 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
942 } else if (!gr_router_detected
943 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 944 bgp_zebra_send_capabilities(bgp, true);
945 }
946
3ae8bfa5
PM
947 if (!found)
948 vty_out(vty,
949 "%%BGP: No external %s peer is configured\n",
5cb5f4d0 950 get_afi_safi_str(afi, safi, false));
3ae8bfa5 951
d62a17ae 952 return CMD_SUCCESS;
953 }
954
3ae8bfa5 955 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 956 if (sort == clear_as) {
3ae8bfa5 957 as_t as = strtoul(arg, NULL, 10);
d62a17ae 958
959 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
960 if (peer->as != as)
961 continue;
962
dc95985f 963 bgp_peer_gr_flags_update(peer);
964
36235319 965 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 966 gr_router_detected = true;
dc95985f 967
c368171c 968 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 969
970 if (ret < 0)
971 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
972 else
973 found = true;
d62a17ae 974 }
3ae8bfa5 975
36235319
QY
976 if (gr_router_detected
977 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 978 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
979 } else if (!gr_router_detected
980 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 981 bgp_zebra_send_capabilities(bgp, true);
982 }
983
3ae8bfa5 984 if (!found)
d62a17ae 985 vty_out(vty,
3ae8bfa5 986 "%%BGP: No %s peer is configured with AS %s\n",
5cb5f4d0 987 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 988
d62a17ae 989 return CMD_SUCCESS;
990 }
991
992 return CMD_SUCCESS;
993}
994
995static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
996 safi_t safi, enum clear_sort sort,
997 enum bgp_clear_type stype, const char *arg)
998{
999 struct bgp *bgp;
1000
1001 /* BGP structure lookup. */
1002 if (name) {
1003 bgp = bgp_lookup_by_name(name);
1004 if (bgp == NULL) {
1005 vty_out(vty, "Can't find BGP instance %s\n", name);
1006 return CMD_WARNING;
1007 }
1008 } else {
1009 bgp = bgp_get_default();
1010 if (bgp == NULL) {
1011 vty_out(vty, "No BGP process is configured\n");
1012 return CMD_WARNING;
1013 }
1014 }
1015
1016 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1017}
1018
1019/* clear soft inbound */
d62a17ae 1020static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1021{
99b3ebd3
NS
1022 afi_t afi;
1023 safi_t safi;
1024
1025 FOREACH_AFI_SAFI (afi, safi)
1026 bgp_clear_vty(vty, name, afi, safi, clear_all,
1027 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1028}
1029
1030/* clear soft outbound */
d62a17ae 1031static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1032{
99b3ebd3
NS
1033 afi_t afi;
1034 safi_t safi;
1035
1036 FOREACH_AFI_SAFI (afi, safi)
1037 bgp_clear_vty(vty, name, afi, safi, clear_all,
1038 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1039}
1040
1041
f787d7a0 1042#ifndef VTYSH_EXTRACT_PL
2e4c2296 1043#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1044#endif
1045
8029b216
AK
1046DEFUN_HIDDEN (bgp_local_mac,
1047 bgp_local_mac_cmd,
093e3f23 1048 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1049 BGP_STR
1050 "Local MAC config\n"
1051 "VxLAN Network Identifier\n"
1052 "VNI number\n"
1053 "local mac\n"
1054 "mac address\n"
1055 "mac-mobility sequence\n"
1056 "seq number\n")
1057{
1058 int rv;
1059 vni_t vni;
1060 struct ethaddr mac;
1061 struct ipaddr ip;
1062 uint32_t seq;
1063 struct bgp *bgp;
1064
1065 vni = strtoul(argv[3]->arg, NULL, 10);
1066 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1067 vty_out(vty, "%% Malformed MAC address\n");
1068 return CMD_WARNING;
1069 }
1070 memset(&ip, 0, sizeof(ip));
1071 seq = strtoul(argv[7]->arg, NULL, 10);
1072
1073 bgp = bgp_get_default();
1074 if (!bgp) {
1075 vty_out(vty, "Default BGP instance is not there\n");
1076 return CMD_WARNING;
1077 }
1078
1079 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
1080 if (rv < 0) {
1081 vty_out(vty, "Internal error\n");
1082 return CMD_WARNING;
1083 }
1084
1085 return CMD_SUCCESS;
1086}
1087
1088DEFUN_HIDDEN (no_bgp_local_mac,
1089 no_bgp_local_mac_cmd,
093e3f23 1090 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1091 NO_STR
1092 BGP_STR
1093 "Local MAC config\n"
1094 "VxLAN Network Identifier\n"
1095 "VNI number\n"
1096 "local mac\n"
1097 "mac address\n")
1098{
1099 int rv;
1100 vni_t vni;
1101 struct ethaddr mac;
1102 struct ipaddr ip;
1103 struct bgp *bgp;
1104
1105 vni = strtoul(argv[4]->arg, NULL, 10);
1106 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1107 vty_out(vty, "%% Malformed MAC address\n");
1108 return CMD_WARNING;
1109 }
1110 memset(&ip, 0, sizeof(ip));
1111
1112 bgp = bgp_get_default();
1113 if (!bgp) {
1114 vty_out(vty, "Default BGP instance is not there\n");
1115 return CMD_WARNING;
1116 }
1117
ec0ab544 1118 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1119 if (rv < 0) {
1120 vty_out(vty, "Internal error\n");
1121 return CMD_WARNING;
1122 }
1123
1124 return CMD_SUCCESS;
1125}
1126
718e3744 1127DEFUN (no_synchronization,
1128 no_synchronization_cmd,
1129 "no synchronization",
1130 NO_STR
1131 "Perform IGP synchronization\n")
1132{
d62a17ae 1133 return CMD_SUCCESS;
718e3744 1134}
1135
1136DEFUN (no_auto_summary,
1137 no_auto_summary_cmd,
1138 "no auto-summary",
1139 NO_STR
1140 "Enable automatic network number summarization\n")
1141{
d62a17ae 1142 return CMD_SUCCESS;
718e3744 1143}
3d515fd9 1144
718e3744 1145/* "router bgp" commands. */
505e5056 1146DEFUN_NOSH (router_bgp,
f412b39a 1147 router_bgp_cmd,
2ed9fe4a 1148 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1149 ROUTER_STR
1150 BGP_STR
31500417
DW
1151 AS_STR
1152 BGP_INSTANCE_HELP_STR)
718e3744 1153{
d62a17ae 1154 int idx_asn = 2;
1155 int idx_view_vrf = 3;
1156 int idx_vrf = 4;
ecec9495 1157 int is_new_bgp = 0;
d62a17ae 1158 int ret;
1159 as_t as;
1160 struct bgp *bgp;
1161 const char *name = NULL;
1162 enum bgp_instance_type inst_type;
1163
1164 // "router bgp" without an ASN
1165 if (argc == 2) {
1166 // Pending: Make VRF option available for ASN less config
1167 bgp = bgp_get_default();
1168
1169 if (bgp == NULL) {
1170 vty_out(vty, "%% No BGP process is configured\n");
1171 return CMD_WARNING_CONFIG_FAILED;
1172 }
1173
1174 if (listcount(bm->bgp) > 1) {
996c9314 1175 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1176 return CMD_WARNING_CONFIG_FAILED;
1177 }
1178 }
1179
1180 // "router bgp X"
1181 else {
1182 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1183
1184 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1185 if (argc > 3) {
1186 name = argv[idx_vrf]->arg;
1187
9a8bdf1c
PG
1188 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1189 if (strmatch(name, VRF_DEFAULT_NAME))
1190 name = NULL;
1191 else
1192 inst_type = BGP_INSTANCE_TYPE_VRF;
1193 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1194 inst_type = BGP_INSTANCE_TYPE_VIEW;
1195 }
1196
ecec9495
AD
1197 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1198 is_new_bgp = (bgp_lookup(as, name) == NULL);
1199
5d5393b9 1200 ret = bgp_get_vty(&bgp, &as, name, inst_type);
d62a17ae 1201 switch (ret) {
d62a17ae 1202 case BGP_ERR_AS_MISMATCH:
1203 vty_out(vty, "BGP is already running; AS is %u\n", as);
1204 return CMD_WARNING_CONFIG_FAILED;
1205 case BGP_ERR_INSTANCE_MISMATCH:
1206 vty_out(vty,
1207 "BGP instance name and AS number mismatch\n");
1208 vty_out(vty,
1209 "BGP instance is already running; AS is %u\n",
1210 as);
1211 return CMD_WARNING_CONFIG_FAILED;
1212 }
1213
3bd70bf8
PZ
1214 /*
1215 * If we just instantiated the default instance, complete
1216 * any pending VRF-VPN leaking that was configured via
1217 * earlier "router bgp X vrf FOO" blocks.
1218 */
ecec9495 1219 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1220 vpn_leak_postchange_all();
1221
48381346
CS
1222 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1223 bgp_vpn_leak_export(bgp);
d62a17ae 1224 /* Pending: handle when user tries to change a view to vrf n vv.
1225 */
1226 }
1227
0b5131c9
MK
1228 /* unset the auto created flag as the user config is now present */
1229 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1230 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1231
1232 return CMD_SUCCESS;
718e3744 1233}
1234
718e3744 1235/* "no router bgp" commands. */
1236DEFUN (no_router_bgp,
1237 no_router_bgp_cmd,
2ed9fe4a 1238 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1239 NO_STR
1240 ROUTER_STR
1241 BGP_STR
31500417
DW
1242 AS_STR
1243 BGP_INSTANCE_HELP_STR)
718e3744 1244{
d62a17ae 1245 int idx_asn = 3;
1246 int idx_vrf = 5;
1247 as_t as;
1248 struct bgp *bgp;
1249 const char *name = NULL;
718e3744 1250
d62a17ae 1251 // "no router bgp" without an ASN
1252 if (argc == 3) {
1253 // Pending: Make VRF option available for ASN less config
1254 bgp = bgp_get_default();
718e3744 1255
d62a17ae 1256 if (bgp == NULL) {
1257 vty_out(vty, "%% No BGP process is configured\n");
1258 return CMD_WARNING_CONFIG_FAILED;
1259 }
7fb21a9f 1260
d62a17ae 1261 if (listcount(bm->bgp) > 1) {
996c9314 1262 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1263 return CMD_WARNING_CONFIG_FAILED;
1264 }
0b5131c9
MK
1265
1266 if (bgp->l3vni) {
1267 vty_out(vty, "%% Please unconfigure l3vni %u",
1268 bgp->l3vni);
1269 return CMD_WARNING_CONFIG_FAILED;
1270 }
d62a17ae 1271 } else {
1272 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1273
d62a17ae 1274 if (argc > 4)
1275 name = argv[idx_vrf]->arg;
7fb21a9f 1276
d62a17ae 1277 /* Lookup bgp structure. */
1278 bgp = bgp_lookup(as, name);
1279 if (!bgp) {
1280 vty_out(vty, "%% Can't find BGP instance\n");
1281 return CMD_WARNING_CONFIG_FAILED;
1282 }
0b5131c9
MK
1283
1284 if (bgp->l3vni) {
dd5868c2 1285 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1286 bgp->l3vni);
1287 return CMD_WARNING_CONFIG_FAILED;
1288 }
dd5868c2
DS
1289
1290 /* Cannot delete default instance if vrf instances exist */
1291 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1292 struct listnode *node;
1293 struct bgp *tmp_bgp;
1294
1295 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1296 if (tmp_bgp->inst_type
1297 == BGP_INSTANCE_TYPE_VRF) {
1298 vty_out(vty,
1299 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1300 return CMD_WARNING_CONFIG_FAILED;
1301 }
1302 }
1303 }
d62a17ae 1304 }
718e3744 1305
9ecf931b
CS
1306 if (bgp_vpn_leak_unimport(bgp, vty))
1307 return CMD_WARNING_CONFIG_FAILED;
1308
d62a17ae 1309 bgp_delete(bgp);
718e3744 1310
d62a17ae 1311 return CMD_SUCCESS;
718e3744 1312}
1313
6b0655a2 1314
718e3744 1315/* BGP router-id. */
1316
f787d7a0 1317DEFPY (bgp_router_id,
718e3744 1318 bgp_router_id_cmd,
1319 "bgp router-id A.B.C.D",
1320 BGP_STR
1321 "Override configured router identifier\n"
1322 "Manually configured router identifier\n")
1323{
d62a17ae 1324 VTY_DECLVAR_CONTEXT(bgp, bgp);
1325 bgp_router_id_static_set(bgp, router_id);
1326 return CMD_SUCCESS;
718e3744 1327}
1328
f787d7a0 1329DEFPY (no_bgp_router_id,
718e3744 1330 no_bgp_router_id_cmd,
31500417 1331 "no bgp router-id [A.B.C.D]",
718e3744 1332 NO_STR
1333 BGP_STR
31500417
DW
1334 "Override configured router identifier\n"
1335 "Manually configured router identifier\n")
718e3744 1336{
d62a17ae 1337 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1338
d62a17ae 1339 if (router_id_str) {
1340 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1341 vty_out(vty, "%% BGP router-id doesn't match\n");
1342 return CMD_WARNING_CONFIG_FAILED;
1343 }
e018c7cc 1344 }
718e3744 1345
d62a17ae 1346 router_id.s_addr = 0;
1347 bgp_router_id_static_set(bgp, router_id);
718e3744 1348
d62a17ae 1349 return CMD_SUCCESS;
718e3744 1350}
1351
6b0655a2 1352
718e3744 1353/* BGP Cluster ID. */
718e3744 1354DEFUN (bgp_cluster_id,
1355 bgp_cluster_id_cmd,
838758ac 1356 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1357 BGP_STR
1358 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1359 "Route-Reflector Cluster-id in IP address format\n"
1360 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1361{
d62a17ae 1362 VTY_DECLVAR_CONTEXT(bgp, bgp);
1363 int idx_ipv4 = 2;
1364 int ret;
1365 struct in_addr cluster;
718e3744 1366
d62a17ae 1367 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1368 if (!ret) {
1369 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1370 return CMD_WARNING_CONFIG_FAILED;
1371 }
718e3744 1372
d62a17ae 1373 bgp_cluster_id_set(bgp, &cluster);
1374 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1375
d62a17ae 1376 return CMD_SUCCESS;
718e3744 1377}
1378
718e3744 1379DEFUN (no_bgp_cluster_id,
1380 no_bgp_cluster_id_cmd,
c7178fe7 1381 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1382 NO_STR
1383 BGP_STR
838758ac
DW
1384 "Configure Route-Reflector Cluster-id\n"
1385 "Route-Reflector Cluster-id in IP address format\n"
1386 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1387{
d62a17ae 1388 VTY_DECLVAR_CONTEXT(bgp, bgp);
1389 bgp_cluster_id_unset(bgp);
1390 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1391
d62a17ae 1392 return CMD_SUCCESS;
718e3744 1393}
1394
718e3744 1395DEFUN (bgp_confederation_identifier,
1396 bgp_confederation_identifier_cmd,
9ccf14f7 1397 "bgp confederation identifier (1-4294967295)",
718e3744 1398 "BGP specific commands\n"
1399 "AS confederation parameters\n"
1400 "AS number\n"
1401 "Set routing domain confederation AS\n")
1402{
d62a17ae 1403 VTY_DECLVAR_CONTEXT(bgp, bgp);
1404 int idx_number = 3;
1405 as_t as;
718e3744 1406
d62a17ae 1407 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1408
d62a17ae 1409 bgp_confederation_id_set(bgp, as);
718e3744 1410
d62a17ae 1411 return CMD_SUCCESS;
718e3744 1412}
1413
1414DEFUN (no_bgp_confederation_identifier,
1415 no_bgp_confederation_identifier_cmd,
838758ac 1416 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1417 NO_STR
1418 "BGP specific commands\n"
1419 "AS confederation parameters\n"
3a2d747c
QY
1420 "AS number\n"
1421 "Set routing domain confederation AS\n")
718e3744 1422{
d62a17ae 1423 VTY_DECLVAR_CONTEXT(bgp, bgp);
1424 bgp_confederation_id_unset(bgp);
718e3744 1425
d62a17ae 1426 return CMD_SUCCESS;
718e3744 1427}
1428
718e3744 1429DEFUN (bgp_confederation_peers,
1430 bgp_confederation_peers_cmd,
12dcf78e 1431 "bgp confederation peers (1-4294967295)...",
718e3744 1432 "BGP specific commands\n"
1433 "AS confederation parameters\n"
1434 "Peer ASs in BGP confederation\n"
1435 AS_STR)
1436{
d62a17ae 1437 VTY_DECLVAR_CONTEXT(bgp, bgp);
1438 int idx_asn = 3;
1439 as_t as;
1440 int i;
718e3744 1441
d62a17ae 1442 for (i = idx_asn; i < argc; i++) {
1443 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1444
d62a17ae 1445 if (bgp->as == as) {
1446 vty_out(vty,
1447 "%% Local member-AS not allowed in confed peer list\n");
1448 continue;
1449 }
718e3744 1450
d62a17ae 1451 bgp_confederation_peers_add(bgp, as);
1452 }
1453 return CMD_SUCCESS;
718e3744 1454}
1455
1456DEFUN (no_bgp_confederation_peers,
1457 no_bgp_confederation_peers_cmd,
e83a9414 1458 "no bgp confederation peers (1-4294967295)...",
718e3744 1459 NO_STR
1460 "BGP specific commands\n"
1461 "AS confederation parameters\n"
1462 "Peer ASs in BGP confederation\n"
1463 AS_STR)
1464{
d62a17ae 1465 VTY_DECLVAR_CONTEXT(bgp, bgp);
1466 int idx_asn = 4;
1467 as_t as;
1468 int i;
718e3744 1469
d62a17ae 1470 for (i = idx_asn; i < argc; i++) {
1471 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1472
d62a17ae 1473 bgp_confederation_peers_remove(bgp, as);
1474 }
1475 return CMD_SUCCESS;
718e3744 1476}
6b0655a2 1477
5e242b0d
DS
1478/**
1479 * Central routine for maximum-paths configuration.
1480 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1481 * @set: 1 for setting values, 0 for removing the max-paths config.
1482 */
d62a17ae 1483static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1484 const char *mpaths, uint16_t options,
d62a17ae 1485 int set)
1486{
1487 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1488 uint16_t maxpaths = 0;
d62a17ae 1489 int ret;
1490 afi_t afi;
1491 safi_t safi;
1492
1493 afi = bgp_node_afi(vty);
1494 safi = bgp_node_safi(vty);
1495
1496 if (set) {
1497 maxpaths = strtol(mpaths, NULL, 10);
1498 if (maxpaths > multipath_num) {
1499 vty_out(vty,
1500 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1501 maxpaths, multipath_num);
1502 return CMD_WARNING_CONFIG_FAILED;
1503 }
1504 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1505 options);
1506 } else
1507 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1508
1509 if (ret < 0) {
1510 vty_out(vty,
1511 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1512 (set == 1) ? "" : "un",
1513 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1514 maxpaths, afi, safi);
1515 return CMD_WARNING_CONFIG_FAILED;
1516 }
1517
1518 bgp_recalculate_all_bestpaths(bgp);
1519
1520 return CMD_SUCCESS;
165b5fff
JB
1521}
1522
abc920f8
DS
1523DEFUN (bgp_maxmed_admin,
1524 bgp_maxmed_admin_cmd,
1525 "bgp max-med administrative ",
1526 BGP_STR
1527 "Advertise routes with max-med\n"
1528 "Administratively applied, for an indefinite period\n")
1529{
d62a17ae 1530 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1531
d62a17ae 1532 bgp->v_maxmed_admin = 1;
1533 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1534
d62a17ae 1535 bgp_maxmed_update(bgp);
abc920f8 1536
d62a17ae 1537 return CMD_SUCCESS;
abc920f8
DS
1538}
1539
1540DEFUN (bgp_maxmed_admin_medv,
1541 bgp_maxmed_admin_medv_cmd,
4668a151 1542 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1543 BGP_STR
1544 "Advertise routes with max-med\n"
1545 "Administratively applied, for an indefinite period\n"
1546 "Max MED value to be used\n")
1547{
d62a17ae 1548 VTY_DECLVAR_CONTEXT(bgp, bgp);
1549 int idx_number = 3;
abc920f8 1550
d62a17ae 1551 bgp->v_maxmed_admin = 1;
1552 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1553
d62a17ae 1554 bgp_maxmed_update(bgp);
abc920f8 1555
d62a17ae 1556 return CMD_SUCCESS;
abc920f8
DS
1557}
1558
1559DEFUN (no_bgp_maxmed_admin,
1560 no_bgp_maxmed_admin_cmd,
4668a151 1561 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1562 NO_STR
1563 BGP_STR
1564 "Advertise routes with max-med\n"
838758ac
DW
1565 "Administratively applied, for an indefinite period\n"
1566 "Max MED value to be used\n")
abc920f8 1567{
d62a17ae 1568 VTY_DECLVAR_CONTEXT(bgp, bgp);
1569 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1570 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1571 bgp_maxmed_update(bgp);
abc920f8 1572
d62a17ae 1573 return CMD_SUCCESS;
abc920f8
DS
1574}
1575
abc920f8
DS
1576DEFUN (bgp_maxmed_onstartup,
1577 bgp_maxmed_onstartup_cmd,
4668a151 1578 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1579 BGP_STR
1580 "Advertise routes with max-med\n"
1581 "Effective on a startup\n"
1582 "Time (seconds) period for max-med\n"
1583 "Max MED value to be used\n")
1584{
d62a17ae 1585 VTY_DECLVAR_CONTEXT(bgp, bgp);
1586 int idx = 0;
4668a151 1587
d62a17ae 1588 argv_find(argv, argc, "(5-86400)", &idx);
1589 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1590 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1591 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1592 else
1593 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1594
d62a17ae 1595 bgp_maxmed_update(bgp);
abc920f8 1596
d62a17ae 1597 return CMD_SUCCESS;
abc920f8
DS
1598}
1599
1600DEFUN (no_bgp_maxmed_onstartup,
1601 no_bgp_maxmed_onstartup_cmd,
4668a151 1602 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1603 NO_STR
1604 BGP_STR
1605 "Advertise routes with max-med\n"
838758ac
DW
1606 "Effective on a startup\n"
1607 "Time (seconds) period for max-med\n"
1608 "Max MED value to be used\n")
abc920f8 1609{
d62a17ae 1610 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1611
d62a17ae 1612 /* Cancel max-med onstartup if its on */
1613 if (bgp->t_maxmed_onstartup) {
1614 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1615 bgp->maxmed_onstartup_over = 1;
1616 }
abc920f8 1617
d62a17ae 1618 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1619 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1620
d62a17ae 1621 bgp_maxmed_update(bgp);
abc920f8 1622
d62a17ae 1623 return CMD_SUCCESS;
abc920f8
DS
1624}
1625
d62a17ae 1626static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1627 const char *wait)
f188f2c4 1628{
d62a17ae 1629 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1630 uint16_t update_delay;
1631 uint16_t establish_wait;
f188f2c4 1632
d62a17ae 1633 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1634
d62a17ae 1635 if (!wait) /* update-delay <delay> */
1636 {
1637 bgp->v_update_delay = update_delay;
1638 bgp->v_establish_wait = bgp->v_update_delay;
1639 return CMD_SUCCESS;
1640 }
f188f2c4 1641
d62a17ae 1642 /* update-delay <delay> <establish-wait> */
1643 establish_wait = atoi(wait);
1644 if (update_delay < establish_wait) {
1645 vty_out(vty,
1646 "%%Failed: update-delay less than the establish-wait!\n");
1647 return CMD_WARNING_CONFIG_FAILED;
1648 }
f188f2c4 1649
d62a17ae 1650 bgp->v_update_delay = update_delay;
1651 bgp->v_establish_wait = establish_wait;
f188f2c4 1652
d62a17ae 1653 return CMD_SUCCESS;
f188f2c4
DS
1654}
1655
d62a17ae 1656static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1657{
d62a17ae 1658 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1659
d62a17ae 1660 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1661 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1662
d62a17ae 1663 return CMD_SUCCESS;
f188f2c4
DS
1664}
1665
2b791107 1666void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1667{
d62a17ae 1668 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1669 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1670 if (bgp->v_update_delay != bgp->v_establish_wait)
1671 vty_out(vty, " %d", bgp->v_establish_wait);
1672 vty_out(vty, "\n");
1673 }
f188f2c4
DS
1674}
1675
1676
1677/* Update-delay configuration */
1678DEFUN (bgp_update_delay,
1679 bgp_update_delay_cmd,
6147e2c6 1680 "update-delay (0-3600)",
f188f2c4
DS
1681 "Force initial delay for best-path and updates\n"
1682 "Seconds\n")
1683{
d62a17ae 1684 int idx_number = 1;
1685 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1686}
1687
1688DEFUN (bgp_update_delay_establish_wait,
1689 bgp_update_delay_establish_wait_cmd,
6147e2c6 1690 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1691 "Force initial delay for best-path and updates\n"
1692 "Seconds\n"
f188f2c4
DS
1693 "Seconds\n")
1694{
d62a17ae 1695 int idx_number = 1;
1696 int idx_number_2 = 2;
1697 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1698 argv[idx_number_2]->arg);
f188f2c4
DS
1699}
1700
1701/* Update-delay deconfiguration */
1702DEFUN (no_bgp_update_delay,
1703 no_bgp_update_delay_cmd,
838758ac
DW
1704 "no update-delay [(0-3600) [(1-3600)]]",
1705 NO_STR
f188f2c4 1706 "Force initial delay for best-path and updates\n"
838758ac 1707 "Seconds\n"
7111c1a0 1708 "Seconds\n")
f188f2c4 1709{
d62a17ae 1710 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1711}
1712
5e242b0d 1713
8fa7732f
QY
1714static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1715 bool set)
cb1faec9 1716{
d62a17ae 1717 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1718
8fa7732f
QY
1719 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1720 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
1721
1722 return CMD_SUCCESS;
1723}
1724
8fa7732f
QY
1725static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1726 bool set)
555e09d4
QY
1727{
1728 VTY_DECLVAR_CONTEXT(bgp, bgp);
1729
8fa7732f
QY
1730 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1731 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 1732
d62a17ae 1733 return CMD_SUCCESS;
cb1faec9
DS
1734}
1735
2b791107 1736void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1737{
555e09d4
QY
1738 uint32_t quanta =
1739 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1740 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1741 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1742}
1743
555e09d4
QY
1744void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1745{
1746 uint32_t quanta =
1747 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1748 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1749 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1750}
cb1faec9 1751
8fa7732f
QY
1752/* Packet quanta configuration
1753 *
1754 * XXX: The value set here controls the size of a stack buffer in the IO
1755 * thread. When changing these limits be careful to prevent stack overflow.
1756 *
1757 * Furthermore, the maximums used here should correspond to
1758 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1759 */
1760DEFPY (bgp_wpkt_quanta,
cb1faec9 1761 bgp_wpkt_quanta_cmd,
8fa7732f 1762 "[no] write-quanta (1-64)$quanta",
d7fa34c1 1763 NO_STR
8fa7732f 1764 "How many packets to write to peer socket per run\n"
cb1faec9
DS
1765 "Number of packets\n")
1766{
8fa7732f 1767 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
cb1faec9
DS
1768}
1769
8fa7732f 1770DEFPY (bgp_rpkt_quanta,
555e09d4 1771 bgp_rpkt_quanta_cmd,
8fa7732f 1772 "[no] read-quanta (1-10)$quanta",
555e09d4
QY
1773 NO_STR
1774 "How many packets to read from peer socket per I/O cycle\n"
1775 "Number of packets\n")
1776{
8fa7732f 1777 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
1778}
1779
2b791107 1780void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1781{
37a333fe 1782 if (!bgp->heuristic_coalesce)
d62a17ae 1783 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1784}
1785
1786
1787DEFUN (bgp_coalesce_time,
1788 bgp_coalesce_time_cmd,
6147e2c6 1789 "coalesce-time (0-4294967295)",
3f9c7369
DS
1790 "Subgroup coalesce timer\n"
1791 "Subgroup coalesce timer value (in ms)\n")
1792{
d62a17ae 1793 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1794
d62a17ae 1795 int idx = 0;
1796 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1797 bgp->heuristic_coalesce = false;
d62a17ae 1798 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1799 return CMD_SUCCESS;
3f9c7369
DS
1800}
1801
1802DEFUN (no_bgp_coalesce_time,
1803 no_bgp_coalesce_time_cmd,
6147e2c6 1804 "no coalesce-time (0-4294967295)",
3a2d747c 1805 NO_STR
3f9c7369
DS
1806 "Subgroup coalesce timer\n"
1807 "Subgroup coalesce timer value (in ms)\n")
1808{
d62a17ae 1809 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1810
37a333fe 1811 bgp->heuristic_coalesce = true;
d62a17ae 1812 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1813 return CMD_SUCCESS;
3f9c7369
DS
1814}
1815
5e242b0d
DS
1816/* Maximum-paths configuration */
1817DEFUN (bgp_maxpaths,
1818 bgp_maxpaths_cmd,
6319fd63 1819 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1820 "Forward packets over multiple paths\n"
1821 "Number of paths\n")
1822{
d62a17ae 1823 int idx_number = 1;
1824 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1825 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1826}
1827
d62a17ae 1828ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1829 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1830 "Forward packets over multiple paths\n"
1831 "Number of paths\n")
596c17ba 1832
165b5fff
JB
1833DEFUN (bgp_maxpaths_ibgp,
1834 bgp_maxpaths_ibgp_cmd,
6319fd63 1835 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1836 "Forward packets over multiple paths\n"
1837 "iBGP-multipath\n"
1838 "Number of paths\n")
1839{
d62a17ae 1840 int idx_number = 2;
1841 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1842 argv[idx_number]->arg, 0, 1);
5e242b0d 1843}
165b5fff 1844
d62a17ae 1845ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1846 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1847 "Forward packets over multiple paths\n"
1848 "iBGP-multipath\n"
1849 "Number of paths\n")
596c17ba 1850
5e242b0d
DS
1851DEFUN (bgp_maxpaths_ibgp_cluster,
1852 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1853 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1854 "Forward packets over multiple paths\n"
1855 "iBGP-multipath\n"
1856 "Number of paths\n"
1857 "Match the cluster length\n")
1858{
d62a17ae 1859 int idx_number = 2;
1860 return bgp_maxpaths_config_vty(
1861 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1862 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1863}
1864
d62a17ae 1865ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1866 "maximum-paths ibgp " CMD_RANGE_STR(
1867 1, MULTIPATH_NUM) " equal-cluster-length",
1868 "Forward packets over multiple paths\n"
1869 "iBGP-multipath\n"
1870 "Number of paths\n"
1871 "Match the cluster length\n")
596c17ba 1872
165b5fff
JB
1873DEFUN (no_bgp_maxpaths,
1874 no_bgp_maxpaths_cmd,
6319fd63 1875 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1876 NO_STR
1877 "Forward packets over multiple paths\n"
1878 "Number of paths\n")
1879{
d62a17ae 1880 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1881}
1882
d62a17ae 1883ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1884 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1885 "Forward packets over multiple paths\n"
1886 "Number of paths\n")
596c17ba 1887
165b5fff
JB
1888DEFUN (no_bgp_maxpaths_ibgp,
1889 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1890 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1891 NO_STR
1892 "Forward packets over multiple paths\n"
1893 "iBGP-multipath\n"
838758ac
DW
1894 "Number of paths\n"
1895 "Match the cluster length\n")
165b5fff 1896{
d62a17ae 1897 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1898}
1899
d62a17ae 1900ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1901 "no maximum-paths ibgp [" CMD_RANGE_STR(
1902 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1903 NO_STR
1904 "Forward packets over multiple paths\n"
1905 "iBGP-multipath\n"
1906 "Number of paths\n"
1907 "Match the cluster length\n")
596c17ba 1908
dd65f45e
DL
1909static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
1910 afi_t afi, safi_t safi)
165b5fff 1911{
d62a17ae 1912 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1913 vty_out(vty, " maximum-paths %d\n",
1914 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1915 }
165b5fff 1916
d62a17ae 1917 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1918 vty_out(vty, " maximum-paths ibgp %d",
1919 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1920 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1921 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1922 vty_out(vty, " equal-cluster-length");
1923 vty_out(vty, "\n");
1924 }
165b5fff 1925}
6b0655a2 1926
718e3744 1927/* BGP timers. */
1928
1929DEFUN (bgp_timers,
1930 bgp_timers_cmd,
6147e2c6 1931 "timers bgp (0-65535) (0-65535)",
718e3744 1932 "Adjust routing timers\n"
1933 "BGP timers\n"
1934 "Keepalive interval\n"
1935 "Holdtime\n")
1936{
d62a17ae 1937 VTY_DECLVAR_CONTEXT(bgp, bgp);
1938 int idx_number = 2;
1939 int idx_number_2 = 3;
1940 unsigned long keepalive = 0;
1941 unsigned long holdtime = 0;
718e3744 1942
d62a17ae 1943 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1944 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1945
d62a17ae 1946 /* Holdtime value check. */
1947 if (holdtime < 3 && holdtime != 0) {
1948 vty_out(vty,
1949 "%% hold time value must be either 0 or greater than 3\n");
1950 return CMD_WARNING_CONFIG_FAILED;
1951 }
718e3744 1952
5d5393b9 1953 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY);
718e3744 1954
d62a17ae 1955 return CMD_SUCCESS;
718e3744 1956}
1957
1958DEFUN (no_bgp_timers,
1959 no_bgp_timers_cmd,
838758ac 1960 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1961 NO_STR
1962 "Adjust routing timers\n"
838758ac
DW
1963 "BGP timers\n"
1964 "Keepalive interval\n"
1965 "Holdtime\n")
718e3744 1966{
d62a17ae 1967 VTY_DECLVAR_CONTEXT(bgp, bgp);
5d5393b9
DL
1968 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
1969 DFLT_BGP_CONNECT_RETRY);
718e3744 1970
d62a17ae 1971 return CMD_SUCCESS;
718e3744 1972}
1973
6b0655a2 1974
718e3744 1975DEFUN (bgp_client_to_client_reflection,
1976 bgp_client_to_client_reflection_cmd,
1977 "bgp client-to-client reflection",
1978 "BGP specific commands\n"
1979 "Configure client to client route reflection\n"
1980 "reflection of routes allowed\n")
1981{
d62a17ae 1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 1983 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
d62a17ae 1984 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1985
d62a17ae 1986 return CMD_SUCCESS;
718e3744 1987}
1988
1989DEFUN (no_bgp_client_to_client_reflection,
1990 no_bgp_client_to_client_reflection_cmd,
1991 "no bgp client-to-client reflection",
1992 NO_STR
1993 "BGP specific commands\n"
1994 "Configure client to client route reflection\n"
1995 "reflection of routes allowed\n")
1996{
d62a17ae 1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 1998 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
d62a17ae 1999 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2000
d62a17ae 2001 return CMD_SUCCESS;
718e3744 2002}
2003
2004/* "bgp always-compare-med" configuration. */
2005DEFUN (bgp_always_compare_med,
2006 bgp_always_compare_med_cmd,
2007 "bgp always-compare-med",
2008 "BGP specific commands\n"
2009 "Allow comparing MED from different neighbors\n")
2010{
d62a17ae 2011 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2012 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
d62a17ae 2013 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2014
d62a17ae 2015 return CMD_SUCCESS;
718e3744 2016}
2017
2018DEFUN (no_bgp_always_compare_med,
2019 no_bgp_always_compare_med_cmd,
2020 "no bgp always-compare-med",
2021 NO_STR
2022 "BGP specific commands\n"
2023 "Allow comparing MED from different neighbors\n")
2024{
d62a17ae 2025 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2026 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
d62a17ae 2027 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2028
d62a17ae 2029 return CMD_SUCCESS;
718e3744 2030}
6b0655a2 2031
9dac9fc8
DA
2032
2033DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2034 "bgp ebgp-requires-policy",
2035 "BGP specific commands\n"
2036 "Require in and out policy for eBGP peers (RFC8212)\n")
2037{
2038 VTY_DECLVAR_CONTEXT(bgp, bgp);
2039 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
2040 return CMD_SUCCESS;
2041}
2042
2043DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2044 "no bgp ebgp-requires-policy",
2045 NO_STR
2046 "BGP specific commands\n"
2047 "Require in and out policy for eBGP peers (RFC8212)\n")
2048{
2049 VTY_DECLVAR_CONTEXT(bgp, bgp);
2050 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
2051 return CMD_SUCCESS;
2052}
2053
fb29348a
DA
2054DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2055 "bgp reject-as-sets",
2056 "BGP specific commands\n"
2057 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2058{
2059 VTY_DECLVAR_CONTEXT(bgp, bgp);
2060 struct listnode *node, *nnode;
2061 struct peer *peer;
2062
2063 bgp->reject_as_sets = BGP_REJECT_AS_SETS_ENABLED;
2064
2065 /* Reset existing BGP sessions to reject routes
2066 * with aspath containing AS_SET or AS_CONFED_SET.
2067 */
2068 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2069 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2070 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2071 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2072 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2073 }
2074 }
2075
2076 return CMD_SUCCESS;
2077}
2078
2079DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2080 "no bgp reject-as-sets",
2081 NO_STR
2082 "BGP specific commands\n"
2083 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2084{
2085 VTY_DECLVAR_CONTEXT(bgp, bgp);
2086 struct listnode *node, *nnode;
2087 struct peer *peer;
2088
2089 bgp->reject_as_sets = BGP_REJECT_AS_SETS_DISABLED;
2090
2091 /* Reset existing BGP sessions to reject routes
2092 * with aspath containing AS_SET or AS_CONFED_SET.
2093 */
2094 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2095 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2096 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2097 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2098 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2099 }
2100 }
2101
2102 return CMD_SUCCESS;
2103}
9dac9fc8 2104
718e3744 2105/* "bgp deterministic-med" configuration. */
2106DEFUN (bgp_deterministic_med,
2107 bgp_deterministic_med_cmd,
2108 "bgp deterministic-med",
2109 "BGP specific commands\n"
2110 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2111{
d62a17ae 2112 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 2113
892fedb6
DA
2114 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2115 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
d62a17ae 2116 bgp_recalculate_all_bestpaths(bgp);
2117 }
7aafcaca 2118
d62a17ae 2119 return CMD_SUCCESS;
718e3744 2120}
2121
2122DEFUN (no_bgp_deterministic_med,
2123 no_bgp_deterministic_med_cmd,
2124 "no bgp deterministic-med",
2125 NO_STR
2126 "BGP specific commands\n"
2127 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2128{
d62a17ae 2129 VTY_DECLVAR_CONTEXT(bgp, bgp);
2130 int bestpath_per_as_used;
2131 afi_t afi;
2132 safi_t safi;
2133 struct peer *peer;
2134 struct listnode *node, *nnode;
2135
892fedb6 2136 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
d62a17ae 2137 bestpath_per_as_used = 0;
2138
2139 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 2140 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
2141 if (bgp_addpath_dmed_required(
2142 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
2143 bestpath_per_as_used = 1;
2144 break;
2145 }
d62a17ae 2146
2147 if (bestpath_per_as_used)
2148 break;
2149 }
2150
2151 if (bestpath_per_as_used) {
2152 vty_out(vty,
2153 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2154 return CMD_WARNING_CONFIG_FAILED;
2155 } else {
892fedb6 2156 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
d62a17ae 2157 bgp_recalculate_all_bestpaths(bgp);
2158 }
2159 }
2160
2161 return CMD_SUCCESS;
718e3744 2162}
538621f2 2163
055679e9 2164/* "bgp graceful-restart mode" configuration. */
538621f2 2165DEFUN (bgp_graceful_restart,
2ba1fe69 2166 bgp_graceful_restart_cmd,
2167 "bgp graceful-restart",
2168 "BGP specific commands\n"
2169 GR_CMD
055679e9 2170 )
538621f2 2171{
055679e9 2172 int ret = BGP_GR_FAILURE;
2173
2174 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2175 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2176
d62a17ae 2177 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2178
2179 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2180
36235319
QY
2181 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2182 ret);
5cce3f05 2183
055679e9 2184 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2185 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2186 vty_out(vty,
2187 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2188 return bgp_vty_return(vty, ret);
538621f2 2189}
2190
2191DEFUN (no_bgp_graceful_restart,
2ba1fe69 2192 no_bgp_graceful_restart_cmd,
2193 "no bgp graceful-restart",
2194 NO_STR
2195 "BGP specific commands\n"
2196 NO_GR_CMD
055679e9 2197 )
538621f2 2198{
d62a17ae 2199 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2200
2201 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2202 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2203
2204 int ret = BGP_GR_FAILURE;
2205
2206 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2207
36235319
QY
2208 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2209 ret);
5cce3f05 2210
055679e9 2211 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2212 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2213 vty_out(vty,
2214 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2215
2216 return bgp_vty_return(vty, ret);
538621f2 2217}
2218
93406d87 2219DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2220 bgp_graceful_restart_stalepath_time_cmd,
2221 "bgp graceful-restart stalepath-time (1-4095)",
2222 "BGP specific commands\n"
2223 "Graceful restart capability parameters\n"
2224 "Set the max time to hold onto restarting peer's stale paths\n"
2225 "Delay value (seconds)\n")
93406d87 2226{
d62a17ae 2227 VTY_DECLVAR_CONTEXT(bgp, bgp);
2228 int idx_number = 3;
d7c0a89a 2229 uint32_t stalepath;
93406d87 2230
d62a17ae 2231 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2232 bgp->stalepath_time = stalepath;
2233 return CMD_SUCCESS;
93406d87 2234}
2235
eb6f1b41 2236DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2237 bgp_graceful_restart_restart_time_cmd,
2238 "bgp graceful-restart restart-time (1-4095)",
2239 "BGP specific commands\n"
2240 "Graceful restart capability parameters\n"
2241 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2242 "Delay value (seconds)\n")
eb6f1b41 2243{
d62a17ae 2244 VTY_DECLVAR_CONTEXT(bgp, bgp);
2245 int idx_number = 3;
d7c0a89a 2246 uint32_t restart;
eb6f1b41 2247
d62a17ae 2248 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2249 bgp->restart_time = restart;
2250 return CMD_SUCCESS;
eb6f1b41
PG
2251}
2252
cfd47646 2253DEFUN (bgp_graceful_restart_select_defer_time,
2254 bgp_graceful_restart_select_defer_time_cmd,
2255 "bgp graceful-restart select-defer-time (0-3600)",
2256 "BGP specific commands\n"
2257 "Graceful restart capability parameters\n"
2258 "Set the time to defer the BGP route selection after restart\n"
2259 "Delay value (seconds, 0 - disable)\n")
2260{
2261 VTY_DECLVAR_CONTEXT(bgp, bgp);
2262 int idx_number = 3;
2263 uint32_t defer_time;
2264
2265 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2266 bgp->select_defer_time = defer_time;
2267 if (defer_time == 0)
892fedb6 2268 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2269 else
892fedb6 2270 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2271
2272 return CMD_SUCCESS;
2273}
2274
93406d87 2275DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2276 no_bgp_graceful_restart_stalepath_time_cmd,
2277 "no bgp graceful-restart stalepath-time [(1-4095)]",
2278 NO_STR
2279 "BGP specific commands\n"
2280 "Graceful restart capability parameters\n"
2281 "Set the max time to hold onto restarting peer's stale paths\n"
2282 "Delay value (seconds)\n")
93406d87 2283{
d62a17ae 2284 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2285
d62a17ae 2286 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2287 return CMD_SUCCESS;
93406d87 2288}
2289
eb6f1b41 2290DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2291 no_bgp_graceful_restart_restart_time_cmd,
2292 "no bgp graceful-restart restart-time [(1-4095)]",
2293 NO_STR
2294 "BGP specific commands\n"
2295 "Graceful restart capability parameters\n"
2296 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2297 "Delay value (seconds)\n")
eb6f1b41 2298{
d62a17ae 2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2300
d62a17ae 2301 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2302 return CMD_SUCCESS;
eb6f1b41
PG
2303}
2304
cfd47646 2305DEFUN (no_bgp_graceful_restart_select_defer_time,
2306 no_bgp_graceful_restart_select_defer_time_cmd,
2307 "no bgp graceful-restart select-defer-time [(0-3600)]",
2308 NO_STR
2309 "BGP specific commands\n"
2310 "Graceful restart capability parameters\n"
2311 "Set the time to defer the BGP route selection after restart\n"
2312 "Delay value (seconds)\n")
2313{
2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
2315
2316 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2317 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2318
2319 return CMD_SUCCESS;
2320}
2321
43fc21b3 2322DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2323 bgp_graceful_restart_preserve_fw_cmd,
2324 "bgp graceful-restart preserve-fw-state",
2325 "BGP specific commands\n"
2326 "Graceful restart capability parameters\n"
2327 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2328{
d62a17ae 2329 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2330 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2331 return CMD_SUCCESS;
43fc21b3
JC
2332}
2333
2334DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2335 no_bgp_graceful_restart_preserve_fw_cmd,
2336 "no bgp graceful-restart preserve-fw-state",
2337 NO_STR
2338 "BGP specific commands\n"
2339 "Graceful restart capability parameters\n"
2340 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2341{
d62a17ae 2342 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2343 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2344 return CMD_SUCCESS;
43fc21b3
JC
2345}
2346
055679e9 2347DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2348 bgp_graceful_restart_disable_cmd,
2349 "bgp graceful-restart-disable",
2350 "BGP specific commands\n"
2351 GR_DISABLE)
055679e9 2352{
2353 int ret = BGP_GR_FAILURE;
2354
2355 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2356 zlog_debug(
2ba1fe69 2357 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2358
055679e9 2359 VTY_DECLVAR_CONTEXT(bgp, bgp);
2360
2361 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2362
dc95985f 2363 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2364 bgp->peer, ret);
5cce3f05 2365
055679e9 2366 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2367 zlog_debug(
2ba1fe69 2368 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2369 vty_out(vty,
2370 "Graceful restart configuration changed, reset all peers to take effect\n");
2371
055679e9 2372 return bgp_vty_return(vty, ret);
2373}
2374
2375DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2376 no_bgp_graceful_restart_disable_cmd,
2377 "no bgp graceful-restart-disable",
2378 NO_STR
2379 "BGP specific commands\n"
2380 NO_GR_DISABLE
055679e9 2381 )
2382{
2383 VTY_DECLVAR_CONTEXT(bgp, bgp);
2384
2385 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2386 zlog_debug(
2ba1fe69 2387 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2388
2389 int ret = BGP_GR_FAILURE;
2390
2391 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2392
36235319
QY
2393 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2394 ret);
5cce3f05 2395
055679e9 2396 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2397 zlog_debug(
2ba1fe69 2398 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2399 vty_out(vty,
2400 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2401
2402 return bgp_vty_return(vty, ret);
2403}
2404
2405DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2406 bgp_neighbor_graceful_restart_set_cmd,
2407 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2408 NEIGHBOR_STR
2409 NEIGHBOR_ADDR_STR2
2410 GR_NEIGHBOR_CMD
055679e9 2411 )
2412{
2413 int idx_peer = 1;
2414 struct peer *peer;
2415 int ret = BGP_GR_FAILURE;
2416
dc95985f 2417 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2418
055679e9 2419 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2420 zlog_debug(
2ba1fe69 2421 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2422
055679e9 2423 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2424 if (!peer)
2425 return CMD_WARNING_CONFIG_FAILED;
2426
2427 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2428
dc95985f 2429 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2430 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2431
2432 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2433 zlog_debug(
2ba1fe69 2434 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2435 vty_out(vty,
2436 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2437
2438 return bgp_vty_return(vty, ret);
2439}
2440
2441DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2442 no_bgp_neighbor_graceful_restart_set_cmd,
2443 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2444 NO_STR
2445 NEIGHBOR_STR
2446 NEIGHBOR_ADDR_STR2
2447 NO_GR_NEIGHBOR_CMD
055679e9 2448 )
2449{
2450 int idx_peer = 2;
2451 int ret = BGP_GR_FAILURE;
2452 struct peer *peer;
2453
dc95985f 2454 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2455
055679e9 2456 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2457 if (!peer)
2458 return CMD_WARNING_CONFIG_FAILED;
2459
2460 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2461 zlog_debug(
2ba1fe69 2462 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2463
2464 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2465
dc95985f 2466 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2467 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2468
2469 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2470 zlog_debug(
2ba1fe69 2471 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2472 vty_out(vty,
2473 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2474
2475 return bgp_vty_return(vty, ret);
2476}
2477
2478DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2479 bgp_neighbor_graceful_restart_helper_set_cmd,
2480 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2481 NEIGHBOR_STR
2482 NEIGHBOR_ADDR_STR2
2483 GR_NEIGHBOR_HELPER_CMD
055679e9 2484 )
2485{
2486 int idx_peer = 1;
2487 struct peer *peer;
2488 int ret = BGP_GR_FAILURE;
2489
dc95985f 2490 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2491
055679e9 2492 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2493 zlog_debug(
2ba1fe69 2494 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2495
055679e9 2496 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2497
055679e9 2498 if (!peer)
2499 return CMD_WARNING_CONFIG_FAILED;
2500
2501
2502 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2503
dc95985f 2504 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2505 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2506
055679e9 2507 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2508 zlog_debug(
2ba1fe69 2509 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2510 vty_out(vty,
2511 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2512
2513 return bgp_vty_return(vty, ret);
2514}
2515
2516DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2517 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2518 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2519 NO_STR
2520 NEIGHBOR_STR
2521 NEIGHBOR_ADDR_STR2
2522 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2523 )
2524{
2525 int idx_peer = 2;
2526 int ret = BGP_GR_FAILURE;
2527 struct peer *peer;
2528
dc95985f 2529 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2530
055679e9 2531 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2532 if (!peer)
2533 return CMD_WARNING_CONFIG_FAILED;
2534
2535 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2536 zlog_debug(
2ba1fe69 2537 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 2538
36235319 2539 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 2540
dc95985f 2541 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2542 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2543
2544 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2545 zlog_debug(
2ba1fe69 2546 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2547 vty_out(vty,
2548 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2549
2550 return bgp_vty_return(vty, ret);
2551}
2552
2553DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 2554 bgp_neighbor_graceful_restart_disable_set_cmd,
2555 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2556 NEIGHBOR_STR
2557 NEIGHBOR_ADDR_STR2
2558 GR_NEIGHBOR_DISABLE_CMD
055679e9 2559 )
2560{
2561 int idx_peer = 1;
2562 struct peer *peer;
2563 int ret = BGP_GR_FAILURE;
2564
dc95985f 2565 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2566
055679e9 2567 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2568 zlog_debug(
2ba1fe69 2569 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2570
2571 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2572 if (!peer)
2573 return CMD_WARNING_CONFIG_FAILED;
2574
36235319 2575 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 2576
2577 if (peer->bgp->t_startup)
2578 bgp_peer_gr_flags_update(peer);
2579
dc95985f 2580 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2581 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2582
055679e9 2583 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2584 zlog_debug(
2ba1fe69 2585 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2586 vty_out(vty,
2587 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2588
2589 return bgp_vty_return(vty, ret);
2590}
2591
2592DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 2593 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2594 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2595 NO_STR
2596 NEIGHBOR_STR
2597 NEIGHBOR_ADDR_STR2
2598 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 2599 )
2600{
2601 int idx_peer = 2;
2602 int ret = BGP_GR_FAILURE;
2603 struct peer *peer;
2604
dc95985f 2605 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2606
055679e9 2607 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2608 if (!peer)
2609 return CMD_WARNING_CONFIG_FAILED;
2610
2611 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2612 zlog_debug(
2ba1fe69 2613 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2614
2615 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2616
dc95985f 2617 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2618 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2619
2620 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2621 zlog_debug(
2ba1fe69 2622 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2623 vty_out(vty,
2624 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2625
2626 return bgp_vty_return(vty, ret);
2627}
2628
d6e3c15b 2629DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2630 bgp_graceful_restart_disable_eor_cmd,
2631 "bgp graceful-restart disable-eor",
2632 "BGP specific commands\n"
2633 "Graceful restart configuration parameters\n"
2634 "Disable EOR Check\n")
2635{
2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2637 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2638
d6e3c15b 2639 return CMD_SUCCESS;
2640}
2641
2642DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2643 no_bgp_graceful_restart_disable_eor_cmd,
2644 "no bgp graceful-restart disable-eor",
2645 NO_STR
2646 "BGP specific commands\n"
2647 "Graceful restart configuration parameters\n"
2648 "Disable EOR Check\n")
2649{
2650 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2651 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2652
2653 return CMD_SUCCESS;
2654}
2655
2656DEFUN (bgp_graceful_restart_rib_stale_time,
2657 bgp_graceful_restart_rib_stale_time_cmd,
2658 "bgp graceful-restart rib-stale-time (1-3600)",
2659 "BGP specific commands\n"
2660 "Graceful restart configuration parameters\n"
2661 "Specify the stale route removal timer in rib\n"
2662 "Delay value (seconds)\n")
2663{
2664 VTY_DECLVAR_CONTEXT(bgp, bgp);
2665 int idx_number = 3;
2666 uint32_t stale_time;
2667
2668 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2669 bgp->rib_stale_time = stale_time;
2670 /* Send the stale timer update message to RIB */
2671 if (bgp_zebra_stale_timer_update(bgp))
2672 return CMD_WARNING;
2673
2674 return CMD_SUCCESS;
2675}
2676
2677DEFUN (no_bgp_graceful_restart_rib_stale_time,
2678 no_bgp_graceful_restart_rib_stale_time_cmd,
2679 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2680 NO_STR
2681 "BGP specific commands\n"
2682 "Graceful restart configuration parameters\n"
2683 "Specify the stale route removal timer in rib\n"
2684 "Delay value (seconds)\n")
2685{
2686 VTY_DECLVAR_CONTEXT(bgp, bgp);
2687
2688 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
2689 /* Send the stale timer update message to RIB */
2690 if (bgp_zebra_stale_timer_update(bgp))
2691 return CMD_WARNING;
2692
d6e3c15b 2693 return CMD_SUCCESS;
2694}
2695
7f323236
DW
2696/* "bgp graceful-shutdown" configuration */
2697DEFUN (bgp_graceful_shutdown,
2698 bgp_graceful_shutdown_cmd,
2699 "bgp graceful-shutdown",
2700 BGP_STR
2701 "Graceful shutdown parameters\n")
2702{
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704
892fedb6
DA
2705 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2706 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
7f323236
DW
2707 bgp_static_redo_import_check(bgp);
2708 bgp_redistribute_redo(bgp);
2709 bgp_clear_star_soft_out(vty, bgp->name);
2710 bgp_clear_star_soft_in(vty, bgp->name);
2711 }
2712
2713 return CMD_SUCCESS;
2714}
2715
2716DEFUN (no_bgp_graceful_shutdown,
2717 no_bgp_graceful_shutdown_cmd,
2718 "no bgp graceful-shutdown",
2719 NO_STR
2720 BGP_STR
2721 "Graceful shutdown parameters\n")
2722{
2723 VTY_DECLVAR_CONTEXT(bgp, bgp);
2724
892fedb6
DA
2725 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2726 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
7f323236
DW
2727 bgp_static_redo_import_check(bgp);
2728 bgp_redistribute_redo(bgp);
2729 bgp_clear_star_soft_out(vty, bgp->name);
2730 bgp_clear_star_soft_in(vty, bgp->name);
2731 }
2732
2733 return CMD_SUCCESS;
2734}
2735
718e3744 2736/* "bgp fast-external-failover" configuration. */
2737DEFUN (bgp_fast_external_failover,
2738 bgp_fast_external_failover_cmd,
2739 "bgp fast-external-failover",
2740 BGP_STR
2741 "Immediately reset session if a link to a directly connected external peer goes down\n")
2742{
d62a17ae 2743 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2744 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
d62a17ae 2745 return CMD_SUCCESS;
718e3744 2746}
2747
2748DEFUN (no_bgp_fast_external_failover,
2749 no_bgp_fast_external_failover_cmd,
2750 "no bgp fast-external-failover",
2751 NO_STR
2752 BGP_STR
2753 "Immediately reset session if a link to a directly connected external peer goes down\n")
2754{
d62a17ae 2755 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2756 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
d62a17ae 2757 return CMD_SUCCESS;
718e3744 2758}
6b0655a2 2759
718e3744 2760/* "bgp bestpath compare-routerid" configuration. */
2761DEFUN (bgp_bestpath_compare_router_id,
2762 bgp_bestpath_compare_router_id_cmd,
2763 "bgp bestpath compare-routerid",
2764 "BGP specific commands\n"
2765 "Change the default bestpath selection\n"
2766 "Compare router-id for identical EBGP paths\n")
2767{
d62a17ae 2768 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2769 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
d62a17ae 2770 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2771
d62a17ae 2772 return CMD_SUCCESS;
718e3744 2773}
2774
2775DEFUN (no_bgp_bestpath_compare_router_id,
2776 no_bgp_bestpath_compare_router_id_cmd,
2777 "no bgp bestpath compare-routerid",
2778 NO_STR
2779 "BGP specific commands\n"
2780 "Change the default bestpath selection\n"
2781 "Compare router-id for identical EBGP paths\n")
2782{
d62a17ae 2783 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2784 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
d62a17ae 2785 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2786
d62a17ae 2787 return CMD_SUCCESS;
718e3744 2788}
6b0655a2 2789
718e3744 2790/* "bgp bestpath as-path ignore" configuration. */
2791DEFUN (bgp_bestpath_aspath_ignore,
2792 bgp_bestpath_aspath_ignore_cmd,
2793 "bgp bestpath as-path ignore",
2794 "BGP specific commands\n"
2795 "Change the default bestpath selection\n"
2796 "AS-path attribute\n"
2797 "Ignore as-path length in selecting a route\n")
2798{
d62a17ae 2799 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2800 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
d62a17ae 2801 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2802
d62a17ae 2803 return CMD_SUCCESS;
718e3744 2804}
2805
2806DEFUN (no_bgp_bestpath_aspath_ignore,
2807 no_bgp_bestpath_aspath_ignore_cmd,
2808 "no bgp bestpath as-path ignore",
2809 NO_STR
2810 "BGP specific commands\n"
2811 "Change the default bestpath selection\n"
2812 "AS-path attribute\n"
2813 "Ignore as-path length in selecting a route\n")
2814{
d62a17ae 2815 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2816 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
d62a17ae 2817 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2818
d62a17ae 2819 return CMD_SUCCESS;
718e3744 2820}
6b0655a2 2821
6811845b 2822/* "bgp bestpath as-path confed" configuration. */
2823DEFUN (bgp_bestpath_aspath_confed,
2824 bgp_bestpath_aspath_confed_cmd,
2825 "bgp bestpath as-path confed",
2826 "BGP specific commands\n"
2827 "Change the default bestpath selection\n"
2828 "AS-path attribute\n"
2829 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2830{
d62a17ae 2831 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2832 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
d62a17ae 2833 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2834
d62a17ae 2835 return CMD_SUCCESS;
6811845b 2836}
2837
2838DEFUN (no_bgp_bestpath_aspath_confed,
2839 no_bgp_bestpath_aspath_confed_cmd,
2840 "no bgp bestpath as-path confed",
2841 NO_STR
2842 "BGP specific commands\n"
2843 "Change the default bestpath selection\n"
2844 "AS-path attribute\n"
2845 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2846{
d62a17ae 2847 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2848 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
d62a17ae 2849 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2850
d62a17ae 2851 return CMD_SUCCESS;
6811845b 2852}
6b0655a2 2853
2fdd455c
PM
2854/* "bgp bestpath as-path multipath-relax" configuration. */
2855DEFUN (bgp_bestpath_aspath_multipath_relax,
2856 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2857 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2858 "BGP specific commands\n"
2859 "Change the default bestpath selection\n"
2860 "AS-path attribute\n"
2861 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2862 "Generate an AS_SET\n"
16fc1eec
DS
2863 "Do not generate an AS_SET\n")
2864{
d62a17ae 2865 VTY_DECLVAR_CONTEXT(bgp, bgp);
2866 int idx = 0;
892fedb6 2867 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2868
d62a17ae 2869 /* no-as-set is now the default behavior so we can silently
2870 * ignore it */
2871 if (argv_find(argv, argc, "as-set", &idx))
892fedb6 2872 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 2873 else
892fedb6 2874 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2875
d62a17ae 2876 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2877
d62a17ae 2878 return CMD_SUCCESS;
16fc1eec
DS
2879}
2880
219178b6
DW
2881DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2882 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2883 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2884 NO_STR
2885 "BGP specific commands\n"
2886 "Change the default bestpath selection\n"
2887 "AS-path attribute\n"
2888 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2889 "Generate an AS_SET\n"
16fc1eec
DS
2890 "Do not generate an AS_SET\n")
2891{
d62a17ae 2892 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
2893 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2894 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 2895 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2896
d62a17ae 2897 return CMD_SUCCESS;
2fdd455c 2898}
6b0655a2 2899
848973c7 2900/* "bgp log-neighbor-changes" configuration. */
2901DEFUN (bgp_log_neighbor_changes,
2902 bgp_log_neighbor_changes_cmd,
2903 "bgp log-neighbor-changes",
2904 "BGP specific commands\n"
2905 "Log neighbor up/down and reset reason\n")
2906{
d62a17ae 2907 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2908 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
d62a17ae 2909 return CMD_SUCCESS;
848973c7 2910}
2911
2912DEFUN (no_bgp_log_neighbor_changes,
2913 no_bgp_log_neighbor_changes_cmd,
2914 "no bgp log-neighbor-changes",
2915 NO_STR
2916 "BGP specific commands\n"
2917 "Log neighbor up/down and reset reason\n")
2918{
d62a17ae 2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2920 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
d62a17ae 2921 return CMD_SUCCESS;
848973c7 2922}
6b0655a2 2923
718e3744 2924/* "bgp bestpath med" configuration. */
2925DEFUN (bgp_bestpath_med,
2926 bgp_bestpath_med_cmd,
2d8c1a4d 2927 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2928 "BGP specific commands\n"
2929 "Change the default bestpath selection\n"
2930 "MED attribute\n"
2931 "Compare MED among confederation paths\n"
838758ac
DW
2932 "Treat missing MED as the least preferred one\n"
2933 "Treat missing MED as the least preferred one\n"
2934 "Compare MED among confederation paths\n")
718e3744 2935{
d62a17ae 2936 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2937
d62a17ae 2938 int idx = 0;
2939 if (argv_find(argv, argc, "confed", &idx))
892fedb6 2940 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 2941 idx = 0;
2942 if (argv_find(argv, argc, "missing-as-worst", &idx))
892fedb6 2943 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2944
d62a17ae 2945 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2946
d62a17ae 2947 return CMD_SUCCESS;
718e3744 2948}
2949
718e3744 2950DEFUN (no_bgp_bestpath_med,
2951 no_bgp_bestpath_med_cmd,
2d8c1a4d 2952 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2953 NO_STR
2954 "BGP specific commands\n"
2955 "Change the default bestpath selection\n"
2956 "MED attribute\n"
2957 "Compare MED among confederation paths\n"
3a2d747c
QY
2958 "Treat missing MED as the least preferred one\n"
2959 "Treat missing MED as the least preferred one\n"
2960 "Compare MED among confederation paths\n")
718e3744 2961{
d62a17ae 2962 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2963
d62a17ae 2964 int idx = 0;
2965 if (argv_find(argv, argc, "confed", &idx))
892fedb6 2966 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 2967 idx = 0;
2968 if (argv_find(argv, argc, "missing-as-worst", &idx))
892fedb6 2969 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2970
d62a17ae 2971 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2972
d62a17ae 2973 return CMD_SUCCESS;
718e3744 2974}
2975
f7e1c681 2976/* "bgp bestpath bandwidth" configuration. */
2977DEFPY (bgp_bestpath_bw,
2978 bgp_bestpath_bw_cmd,
2979 "[no$no] bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
2980 NO_STR
2981 "BGP specific commands\n"
2982 "Change the default bestpath selection\n"
2983 "Link Bandwidth attribute\n"
2984 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
2985 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
2986 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
2987{
2988 VTY_DECLVAR_CONTEXT(bgp, bgp);
2989 afi_t afi;
2990 safi_t safi;
2991
2992 if (no) {
2993 bgp->lb_handling = BGP_LINK_BW_ECMP;
2994 } else {
2995 if (!bw_cfg) {
2996 vty_out(vty, "%% Bandwidth configuration must be specified\n");
2997 return CMD_ERR_INCOMPLETE;
2998 }
2999 if (!strcmp(bw_cfg, "ignore"))
3000 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3001 else if (!strcmp(bw_cfg, "skip-missing"))
3002 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3003 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3004 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3005 else
3006 return CMD_ERR_NO_MATCH;
3007 }
3008
3009 /* This config is used in route install, so redo that. */
3010 FOREACH_AFI_SAFI (afi, safi) {
3011 if (!bgp_fibupd_safi(safi))
3012 continue;
3013 bgp_zebra_announce_table(bgp, afi, safi);
3014 }
3015
3016 return CMD_SUCCESS;
3017}
3018
718e3744 3019/* "no bgp default ipv4-unicast". */
3020DEFUN (no_bgp_default_ipv4_unicast,
3021 no_bgp_default_ipv4_unicast_cmd,
3022 "no bgp default ipv4-unicast",
3023 NO_STR
3024 "BGP specific commands\n"
3025 "Configure BGP defaults\n"
3026 "Activate ipv4-unicast for a peer by default\n")
3027{
d62a17ae 3028 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3029 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3030 return CMD_SUCCESS;
718e3744 3031}
3032
3033DEFUN (bgp_default_ipv4_unicast,
3034 bgp_default_ipv4_unicast_cmd,
3035 "bgp default ipv4-unicast",
3036 "BGP specific commands\n"
3037 "Configure BGP defaults\n"
3038 "Activate ipv4-unicast for a peer by default\n")
3039{
d62a17ae 3040 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3041 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3042 return CMD_SUCCESS;
718e3744 3043}
6b0655a2 3044
04b6bdc0
DW
3045/* Display hostname in certain command outputs */
3046DEFUN (bgp_default_show_hostname,
3047 bgp_default_show_hostname_cmd,
3048 "bgp default show-hostname",
3049 "BGP specific commands\n"
3050 "Configure BGP defaults\n"
0437e105 3051 "Show hostname in certain command outputs\n")
04b6bdc0 3052{
d62a17ae 3053 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3054 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
d62a17ae 3055 return CMD_SUCCESS;
04b6bdc0
DW
3056}
3057
3058DEFUN (no_bgp_default_show_hostname,
3059 no_bgp_default_show_hostname_cmd,
3060 "no bgp default show-hostname",
3061 NO_STR
3062 "BGP specific commands\n"
3063 "Configure BGP defaults\n"
0437e105 3064 "Show hostname in certain command outputs\n")
04b6bdc0 3065{
d62a17ae 3066 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3067 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
d62a17ae 3068 return CMD_SUCCESS;
04b6bdc0
DW
3069}
3070
8233ef81 3071/* "bgp network import-check" configuration. */
718e3744 3072DEFUN (bgp_network_import_check,
3073 bgp_network_import_check_cmd,
5623e905 3074 "bgp network import-check",
718e3744 3075 "BGP specific commands\n"
3076 "BGP network command\n"
5623e905 3077 "Check BGP network route exists in IGP\n")
718e3744 3078{
d62a17ae 3079 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
3080 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3081 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
d62a17ae 3082 bgp_static_redo_import_check(bgp);
3083 }
078430f6 3084
d62a17ae 3085 return CMD_SUCCESS;
718e3744 3086}
3087
d62a17ae 3088ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3089 "bgp network import-check exact",
3090 "BGP specific commands\n"
3091 "BGP network command\n"
3092 "Check BGP network route exists in IGP\n"
3093 "Match route precisely\n")
8233ef81 3094
718e3744 3095DEFUN (no_bgp_network_import_check,
3096 no_bgp_network_import_check_cmd,
5623e905 3097 "no bgp network import-check",
718e3744 3098 NO_STR
3099 "BGP specific commands\n"
3100 "BGP network command\n"
3101 "Check BGP network route exists in IGP\n")
3102{
d62a17ae 3103 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
3104 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3105 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
d62a17ae 3106 bgp_static_redo_import_check(bgp);
3107 }
5623e905 3108
d62a17ae 3109 return CMD_SUCCESS;
718e3744 3110}
6b0655a2 3111
718e3744 3112DEFUN (bgp_default_local_preference,
3113 bgp_default_local_preference_cmd,
6147e2c6 3114 "bgp default local-preference (0-4294967295)",
718e3744 3115 "BGP specific commands\n"
3116 "Configure BGP defaults\n"
3117 "local preference (higher=more preferred)\n"
3118 "Configure default local preference value\n")
3119{
d62a17ae 3120 VTY_DECLVAR_CONTEXT(bgp, bgp);
3121 int idx_number = 3;
d7c0a89a 3122 uint32_t local_pref;
718e3744 3123
d62a17ae 3124 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3125
d62a17ae 3126 bgp_default_local_preference_set(bgp, local_pref);
3127 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3128
d62a17ae 3129 return CMD_SUCCESS;
718e3744 3130}
3131
3132DEFUN (no_bgp_default_local_preference,
3133 no_bgp_default_local_preference_cmd,
838758ac 3134 "no bgp default local-preference [(0-4294967295)]",
718e3744 3135 NO_STR
3136 "BGP specific commands\n"
3137 "Configure BGP defaults\n"
838758ac
DW
3138 "local preference (higher=more preferred)\n"
3139 "Configure default local preference value\n")
718e3744 3140{
d62a17ae 3141 VTY_DECLVAR_CONTEXT(bgp, bgp);
3142 bgp_default_local_preference_unset(bgp);
3143 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3144
d62a17ae 3145 return CMD_SUCCESS;
718e3744 3146}
3147
6b0655a2 3148
3f9c7369
DS
3149DEFUN (bgp_default_subgroup_pkt_queue_max,
3150 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 3151 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
3152 "BGP specific commands\n"
3153 "Configure BGP defaults\n"
3154 "subgroup-pkt-queue-max\n"
3155 "Configure subgroup packet queue max\n")
8bd9d948 3156{
d62a17ae 3157 VTY_DECLVAR_CONTEXT(bgp, bgp);
3158 int idx_number = 3;
d7c0a89a 3159 uint32_t max_size;
8bd9d948 3160
d62a17ae 3161 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3162
d62a17ae 3163 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 3164
d62a17ae 3165 return CMD_SUCCESS;
3f9c7369
DS
3166}
3167
3168DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3169 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 3170 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
3171 NO_STR
3172 "BGP specific commands\n"
3173 "Configure BGP defaults\n"
838758ac
DW
3174 "subgroup-pkt-queue-max\n"
3175 "Configure subgroup packet queue max\n")
3f9c7369 3176{
d62a17ae 3177 VTY_DECLVAR_CONTEXT(bgp, bgp);
3178 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3179 return CMD_SUCCESS;
8bd9d948
DS
3180}
3181
813d4307 3182
8bd9d948
DS
3183DEFUN (bgp_rr_allow_outbound_policy,
3184 bgp_rr_allow_outbound_policy_cmd,
3185 "bgp route-reflector allow-outbound-policy",
3186 "BGP specific commands\n"
3187 "Allow modifications made by out route-map\n"
3188 "on ibgp neighbors\n")
3189{
d62a17ae 3190 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3191
892fedb6
DA
3192 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3193 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
d62a17ae 3194 update_group_announce_rrclients(bgp);
3195 bgp_clear_star_soft_out(vty, bgp->name);
3196 }
8bd9d948 3197
d62a17ae 3198 return CMD_SUCCESS;
8bd9d948
DS
3199}
3200
3201DEFUN (no_bgp_rr_allow_outbound_policy,
3202 no_bgp_rr_allow_outbound_policy_cmd,
3203 "no bgp route-reflector allow-outbound-policy",
3204 NO_STR
3205 "BGP specific commands\n"
3206 "Allow modifications made by out route-map\n"
3207 "on ibgp neighbors\n")
3208{
d62a17ae 3209 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3210
892fedb6
DA
3211 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3212 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
d62a17ae 3213 update_group_announce_rrclients(bgp);
3214 bgp_clear_star_soft_out(vty, bgp->name);
3215 }
8bd9d948 3216
d62a17ae 3217 return CMD_SUCCESS;
8bd9d948
DS
3218}
3219
f14e6fdb
DS
3220DEFUN (bgp_listen_limit,
3221 bgp_listen_limit_cmd,
9ccf14f7 3222 "bgp listen limit (1-5000)",
f14e6fdb 3223 "BGP specific commands\n"
1601a46f 3224 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3225 "Maximum number of BGP Dynamic Neighbors that can be created\n"
f14e6fdb
DS
3226 "Configure Dynamic Neighbors listen limit value\n")
3227{
d62a17ae 3228 VTY_DECLVAR_CONTEXT(bgp, bgp);
3229 int idx_number = 3;
3230 int listen_limit;
f14e6fdb 3231
d62a17ae 3232 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3233
d62a17ae 3234 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3235
d62a17ae 3236 return CMD_SUCCESS;
f14e6fdb
DS
3237}
3238
3239DEFUN (no_bgp_listen_limit,
3240 no_bgp_listen_limit_cmd,
838758ac 3241 "no bgp listen limit [(1-5000)]",
1601a46f 3242 NO_STR
f14e6fdb 3243 "BGP specific commands\n"
1601a46f 3244 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3245 "Maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac 3246 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3247{
d62a17ae 3248 VTY_DECLVAR_CONTEXT(bgp, bgp);
3249 bgp_listen_limit_unset(bgp);
3250 return CMD_SUCCESS;
f14e6fdb
DS
3251}
3252
3253
20eb8864 3254/*
3255 * Check if this listen range is already configured. Check for exact
3256 * match or overlap based on input.
3257 */
d62a17ae 3258static struct peer_group *listen_range_exists(struct bgp *bgp,
3259 struct prefix *range, int exact)
3260{
3261 struct listnode *node, *nnode;
3262 struct listnode *node1, *nnode1;
3263 struct peer_group *group;
3264 struct prefix *lr;
3265 afi_t afi;
3266 int match;
3267
3268 afi = family2afi(range->family);
3269 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3270 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3271 lr)) {
3272 if (exact)
3273 match = prefix_same(range, lr);
3274 else
3275 match = (prefix_match(range, lr)
3276 || prefix_match(lr, range));
3277 if (match)
3278 return group;
3279 }
3280 }
3281
3282 return NULL;
20eb8864 3283}
3284
f14e6fdb
DS
3285DEFUN (bgp_listen_range,
3286 bgp_listen_range_cmd,
d7b9898c 3287 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3288 "BGP specific commands\n"
d7fa34c1
QY
3289 "Configure BGP dynamic neighbors listen range\n"
3290 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3291 NEIGHBOR_ADDR_STR
3292 "Member of the peer-group\n"
3293 "Peer-group name\n")
f14e6fdb 3294{
d62a17ae 3295 VTY_DECLVAR_CONTEXT(bgp, bgp);
3296 struct prefix range;
3297 struct peer_group *group, *existing_group;
3298 afi_t afi;
3299 int ret;
3300 int idx = 0;
3301
3302 argv_find(argv, argc, "A.B.C.D/M", &idx);
3303 argv_find(argv, argc, "X:X::X:X/M", &idx);
3304 char *prefix = argv[idx]->arg;
d7b9898c 3305 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3306 char *peergroup = argv[idx]->arg;
3307
3308 /* Convert IP prefix string to struct prefix. */
3309 ret = str2prefix(prefix, &range);
3310 if (!ret) {
3311 vty_out(vty, "%% Malformed listen range\n");
3312 return CMD_WARNING_CONFIG_FAILED;
3313 }
3314
3315 afi = family2afi(range.family);
3316
3317 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3318 vty_out(vty,
3319 "%% Malformed listen range (link-local address)\n");
3320 return CMD_WARNING_CONFIG_FAILED;
3321 }
3322
3323 apply_mask(&range);
3324
3325 /* Check if same listen range is already configured. */
3326 existing_group = listen_range_exists(bgp, &range, 1);
3327 if (existing_group) {
3328 if (strcmp(existing_group->name, peergroup) == 0)
3329 return CMD_SUCCESS;
3330 else {
3331 vty_out(vty,
3332 "%% Same listen range is attached to peer-group %s\n",
3333 existing_group->name);
3334 return CMD_WARNING_CONFIG_FAILED;
3335 }
3336 }
3337
3338 /* Check if an overlapping listen range exists. */
3339 if (listen_range_exists(bgp, &range, 0)) {
3340 vty_out(vty,
3341 "%% Listen range overlaps with existing listen range\n");
3342 return CMD_WARNING_CONFIG_FAILED;
3343 }
3344
3345 group = peer_group_lookup(bgp, peergroup);
3346 if (!group) {
3347 vty_out(vty, "%% Configure the peer-group first\n");
3348 return CMD_WARNING_CONFIG_FAILED;
3349 }
3350
3351 ret = peer_group_listen_range_add(group, &range);
3352 return bgp_vty_return(vty, ret);
f14e6fdb
DS
3353}
3354
3355DEFUN (no_bgp_listen_range,
3356 no_bgp_listen_range_cmd,
d7b9898c 3357 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 3358 NO_STR
f14e6fdb 3359 "BGP specific commands\n"
d7fa34c1
QY
3360 "Unconfigure BGP dynamic neighbors listen range\n"
3361 "Unconfigure BGP dynamic neighbors listen range\n"
3362 NEIGHBOR_ADDR_STR
3363 "Member of the peer-group\n"
3364 "Peer-group name\n")
f14e6fdb 3365{
d62a17ae 3366 VTY_DECLVAR_CONTEXT(bgp, bgp);
3367 struct prefix range;
3368 struct peer_group *group;
3369 afi_t afi;
3370 int ret;
3371 int idx = 0;
3372
3373 argv_find(argv, argc, "A.B.C.D/M", &idx);
3374 argv_find(argv, argc, "X:X::X:X/M", &idx);
3375 char *prefix = argv[idx]->arg;
21d88a71 3376 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3377 char *peergroup = argv[idx]->arg;
3378
3379 /* Convert IP prefix string to struct prefix. */
3380 ret = str2prefix(prefix, &range);
3381 if (!ret) {
3382 vty_out(vty, "%% Malformed listen range\n");
3383 return CMD_WARNING_CONFIG_FAILED;
3384 }
3385
3386 afi = family2afi(range.family);
3387
3388 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3389 vty_out(vty,
3390 "%% Malformed listen range (link-local address)\n");
3391 return CMD_WARNING_CONFIG_FAILED;
3392 }
3393
3394 apply_mask(&range);
3395
3396 group = peer_group_lookup(bgp, peergroup);
3397 if (!group) {
3398 vty_out(vty, "%% Peer-group does not exist\n");
3399 return CMD_WARNING_CONFIG_FAILED;
3400 }
3401
3402 ret = peer_group_listen_range_del(group, &range);
3403 return bgp_vty_return(vty, ret);
3404}
3405
2b791107 3406void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 3407{
3408 struct peer_group *group;
3409 struct listnode *node, *nnode, *rnode, *nrnode;
3410 struct prefix *range;
3411 afi_t afi;
3412 char buf[PREFIX2STR_BUFFER];
3413
3414 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3415 vty_out(vty, " bgp listen limit %d\n",
3416 bgp->dynamic_neighbors_limit);
3417
3418 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3419 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3420 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3421 nrnode, range)) {
3422 prefix2str(range, buf, sizeof(buf));
3423 vty_out(vty,
3424 " bgp listen range %s peer-group %s\n",
3425 buf, group->name);
3426 }
3427 }
3428 }
f14e6fdb
DS
3429}
3430
3431
907f92c8
DS
3432DEFUN (bgp_disable_connected_route_check,
3433 bgp_disable_connected_route_check_cmd,
3434 "bgp disable-ebgp-connected-route-check",
3435 "BGP specific commands\n"
3436 "Disable checking if nexthop is connected on ebgp sessions\n")
3437{
d62a17ae 3438 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3439 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
d62a17ae 3440 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3441
d62a17ae 3442 return CMD_SUCCESS;
907f92c8
DS
3443}
3444
3445DEFUN (no_bgp_disable_connected_route_check,
3446 no_bgp_disable_connected_route_check_cmd,
3447 "no bgp disable-ebgp-connected-route-check",
3448 NO_STR
3449 "BGP specific commands\n"
3450 "Disable checking if nexthop is connected on ebgp sessions\n")
3451{
d62a17ae 3452 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3453 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
d62a17ae 3454 bgp_clear_star_soft_in(vty, bgp->name);
3455
3456 return CMD_SUCCESS;
3457}
3458
3459
3460static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3461 const char *as_str, afi_t afi, safi_t safi)
3462{
3463 VTY_DECLVAR_CONTEXT(bgp, bgp);
3464 int ret;
3465 as_t as;
3466 int as_type = AS_SPECIFIED;
3467 union sockunion su;
3468
3469 if (as_str[0] == 'i') {
3470 as = 0;
3471 as_type = AS_INTERNAL;
3472 } else if (as_str[0] == 'e') {
3473 as = 0;
3474 as_type = AS_EXTERNAL;
3475 } else {
3476 /* Get AS number. */
3477 as = strtoul(as_str, NULL, 10);
3478 }
3479
390485fd 3480 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 3481 ret = str2sockunion(peer_str, &su);
3482 if (ret < 0) {
390485fd
DS
3483 struct peer *peer;
3484
3485 /* Check if existing interface peer */
3486 peer = peer_lookup_by_conf_if(bgp, peer_str);
3487
d62a17ae 3488 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3489 safi);
390485fd
DS
3490
3491 /* if not interface peer, check peer-group settings */
3492 if (ret < 0 && !peer) {
d62a17ae 3493 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3494 if (ret < 0) {
3495 vty_out(vty,
390485fd 3496 "%% Create the peer-group or interface first\n");
d62a17ae 3497 return CMD_WARNING_CONFIG_FAILED;
3498 }
3499 return CMD_SUCCESS;
3500 }
3501 } else {
3502 if (peer_address_self_check(bgp, &su)) {
3503 vty_out(vty,
3504 "%% Can not configure the local system as neighbor\n");
3505 return CMD_WARNING_CONFIG_FAILED;
3506 }
3507 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3508 }
3509
3510 /* This peer belongs to peer group. */
3511 switch (ret) {
3512 case BGP_ERR_PEER_GROUP_MEMBER:
3513 vty_out(vty,
faa16034 3514 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 3515 return CMD_WARNING_CONFIG_FAILED;
3516 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3517 vty_out(vty,
faa16034 3518 "%% Peer-group members must be all internal or all external\n");
d62a17ae 3519 return CMD_WARNING_CONFIG_FAILED;
3520 }
3521 return bgp_vty_return(vty, ret);
718e3744 3522}
3523
f26845f9
QY
3524DEFUN (bgp_default_shutdown,
3525 bgp_default_shutdown_cmd,
3526 "[no] bgp default shutdown",
3527 NO_STR
3528 BGP_STR
3529 "Configure BGP defaults\n"
b012cbe2 3530 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
3531{
3532 VTY_DECLVAR_CONTEXT(bgp, bgp);
3533 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
3534 return CMD_SUCCESS;
3535}
3536
718e3744 3537DEFUN (neighbor_remote_as,
3538 neighbor_remote_as_cmd,
3a2d747c 3539 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 3540 NEIGHBOR_STR
3541 NEIGHBOR_ADDR_STR2
3542 "Specify a BGP neighbor\n"
d7fa34c1 3543 AS_STR
3a2d747c
QY
3544 "Internal BGP peer\n"
3545 "External BGP peer\n")
718e3744 3546{
d62a17ae 3547 int idx_peer = 1;
3548 int idx_remote_as = 3;
3549 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
3550 argv[idx_remote_as]->arg, AFI_IP,
3551 SAFI_UNICAST);
3552}
3553
3554static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
3555 afi_t afi, safi_t safi, int v6only,
3556 const char *peer_group_name,
3557 const char *as_str)
3558{
3559 VTY_DECLVAR_CONTEXT(bgp, bgp);
3560 as_t as = 0;
3561 int as_type = AS_UNSPECIFIED;
3562 struct peer *peer;
3563 struct peer_group *group;
3564 int ret = 0;
3565 union sockunion su;
3566
3567 group = peer_group_lookup(bgp, conf_if);
3568
3569 if (group) {
3570 vty_out(vty, "%% Name conflict with peer-group \n");
3571 return CMD_WARNING_CONFIG_FAILED;
3572 }
3573
3574 if (as_str) {
3575 if (as_str[0] == 'i') {
3576 as_type = AS_INTERNAL;
3577 } else if (as_str[0] == 'e') {
3578 as_type = AS_EXTERNAL;
3579 } else {
3580 /* Get AS number. */
3581 as = strtoul(as_str, NULL, 10);
3582 as_type = AS_SPECIFIED;
3583 }
3584 }
3585
3586 peer = peer_lookup_by_conf_if(bgp, conf_if);
3587 if (peer) {
3588 if (as_str)
cc4d4ce8 3589 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 3590 afi, safi);
3591 } else {
892fedb6 3592 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 3593 && afi == AFI_IP && safi == SAFI_UNICAST)
3594 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3595 as_type, 0, 0, NULL);
3596 else
3597 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3598 as_type, afi, safi, NULL);
3599
3600 if (!peer) {
3601 vty_out(vty, "%% BGP failed to create peer\n");
3602 return CMD_WARNING_CONFIG_FAILED;
3603 }
3604
3605 if (v6only)
527de3dc 3606 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3607
3608 /* Request zebra to initiate IPv6 RAs on this interface. We do
3609 * this
3610 * any unnumbered peer in order to not worry about run-time
3611 * transitions
3612 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3613 * address
3614 * gets deleted later etc.)
3615 */
3616 if (peer->ifp)
3617 bgp_zebra_initiate_radv(bgp, peer);
3618 }
3619
3620 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3621 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3622 if (v6only)
527de3dc 3623 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3624 else
527de3dc 3625 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3626
3627 /* v6only flag changed. Reset bgp seesion */
3628 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3629 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3630 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3631 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3632 } else
3633 bgp_session_reset(peer);
3634 }
3635
9fb964de
PM
3636 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3637 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3638 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 3639 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 3640 }
d62a17ae 3641
3642 if (peer_group_name) {
3643 group = peer_group_lookup(bgp, peer_group_name);
3644 if (!group) {
3645 vty_out(vty, "%% Configure the peer-group first\n");
3646 return CMD_WARNING_CONFIG_FAILED;
3647 }
3648
3649 ret = peer_group_bind(bgp, &su, peer, group, &as);
3650 }
3651
3652 return bgp_vty_return(vty, ret);
a80beece
DS
3653}
3654
4c48cf63
DW
3655DEFUN (neighbor_interface_config,
3656 neighbor_interface_config_cmd,
d7b9898c 3657 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
3658 NEIGHBOR_STR
3659 "Interface name or neighbor tag\n"
31500417
DW
3660 "Enable BGP on interface\n"
3661 "Member of the peer-group\n"
16cedbb0 3662 "Peer-group name\n")
4c48cf63 3663{
d62a17ae 3664 int idx_word = 1;
3665 int idx_peer_group_word = 4;
31500417 3666
d62a17ae 3667 if (argc > idx_peer_group_word)
3668 return peer_conf_interface_get(
3669 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3670 argv[idx_peer_group_word]->arg, NULL);
3671 else
3672 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3673 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3674}
3675
4c48cf63
DW
3676DEFUN (neighbor_interface_config_v6only,
3677 neighbor_interface_config_v6only_cmd,
d7b9898c 3678 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
3679 NEIGHBOR_STR
3680 "Interface name or neighbor tag\n"
3681 "Enable BGP on interface\n"
31500417
DW
3682 "Enable BGP with v6 link-local only\n"
3683 "Member of the peer-group\n"
16cedbb0 3684 "Peer-group name\n")
4c48cf63 3685{
d62a17ae 3686 int idx_word = 1;
3687 int idx_peer_group_word = 5;
31500417 3688
d62a17ae 3689 if (argc > idx_peer_group_word)
3690 return peer_conf_interface_get(
3691 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3692 argv[idx_peer_group_word]->arg, NULL);
31500417 3693
d62a17ae 3694 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3695 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3696}
3697
a80beece 3698
b3a39dc5
DD
3699DEFUN (neighbor_interface_config_remote_as,
3700 neighbor_interface_config_remote_as_cmd,
3a2d747c 3701 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3702 NEIGHBOR_STR
3703 "Interface name or neighbor tag\n"
3704 "Enable BGP on interface\n"
3a2d747c 3705 "Specify a BGP neighbor\n"
d7fa34c1 3706 AS_STR
3a2d747c
QY
3707 "Internal BGP peer\n"
3708 "External BGP peer\n")
b3a39dc5 3709{
d62a17ae 3710 int idx_word = 1;
3711 int idx_remote_as = 4;
3712 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3713 SAFI_UNICAST, 0, NULL,
3714 argv[idx_remote_as]->arg);
b3a39dc5
DD
3715}
3716
3717DEFUN (neighbor_interface_v6only_config_remote_as,
3718 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3719 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3720 NEIGHBOR_STR
3721 "Interface name or neighbor tag\n"
3a2d747c 3722 "Enable BGP with v6 link-local only\n"
b3a39dc5 3723 "Enable BGP on interface\n"
3a2d747c 3724 "Specify a BGP neighbor\n"
d7fa34c1 3725 AS_STR
3a2d747c
QY
3726 "Internal BGP peer\n"
3727 "External BGP peer\n")
b3a39dc5 3728{
d62a17ae 3729 int idx_word = 1;
3730 int idx_remote_as = 5;
3731 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3732 SAFI_UNICAST, 1, NULL,
3733 argv[idx_remote_as]->arg);
b3a39dc5
DD
3734}
3735
718e3744 3736DEFUN (neighbor_peer_group,
3737 neighbor_peer_group_cmd,
3738 "neighbor WORD peer-group",
3739 NEIGHBOR_STR
a80beece 3740 "Interface name or neighbor tag\n"
718e3744 3741 "Configure peer-group\n")
3742{
d62a17ae 3743 VTY_DECLVAR_CONTEXT(bgp, bgp);
3744 int idx_word = 1;
3745 struct peer *peer;
3746 struct peer_group *group;
718e3744 3747
d62a17ae 3748 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3749 if (peer) {
3750 vty_out(vty, "%% Name conflict with interface: \n");
3751 return CMD_WARNING_CONFIG_FAILED;
3752 }
718e3744 3753
d62a17ae 3754 group = peer_group_get(bgp, argv[idx_word]->arg);
3755 if (!group) {
3756 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3757 return CMD_WARNING_CONFIG_FAILED;
3758 }
718e3744 3759
d62a17ae 3760 return CMD_SUCCESS;
718e3744 3761}
3762
3763DEFUN (no_neighbor,
3764 no_neighbor_cmd,
dab8cd00 3765 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3766 NO_STR
3767 NEIGHBOR_STR
3a2d747c
QY
3768 NEIGHBOR_ADDR_STR2
3769 "Specify a BGP neighbor\n"
3770 AS_STR
3771 "Internal BGP peer\n"
3772 "External BGP peer\n")
718e3744 3773{
d62a17ae 3774 VTY_DECLVAR_CONTEXT(bgp, bgp);
3775 int idx_peer = 2;
3776 int ret;
3777 union sockunion su;
3778 struct peer_group *group;
3779 struct peer *peer;
3780 struct peer *other;
3781
3782 ret = str2sockunion(argv[idx_peer]->arg, &su);
3783 if (ret < 0) {
3784 /* look up for neighbor by interface name config. */
3785 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3786 if (peer) {
3787 /* Request zebra to terminate IPv6 RAs on this
3788 * interface. */
3789 if (peer->ifp)
3790 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3791 peer_notify_unconfig(peer);
d62a17ae 3792 peer_delete(peer);
3793 return CMD_SUCCESS;
3794 }
f14e6fdb 3795
d62a17ae 3796 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4e2786df
DA
3797 if (group) {
3798 peer_group_notify_unconfig(group);
d62a17ae 3799 peer_group_delete(group);
4e2786df 3800 } else {
d62a17ae 3801 vty_out(vty, "%% Create the peer-group first\n");
3802 return CMD_WARNING_CONFIG_FAILED;
3803 }
3804 } else {
3805 peer = peer_lookup(bgp, &su);
3806 if (peer) {
3807 if (peer_dynamic_neighbor(peer)) {
3808 vty_out(vty,
3809 "%% Operation not allowed on a dynamic neighbor\n");
3810 return CMD_WARNING_CONFIG_FAILED;
3811 }
3812
3813 other = peer->doppelganger;
4e2786df 3814 peer_notify_unconfig(peer);
d62a17ae 3815 peer_delete(peer);
4e2786df
DA
3816 if (other && other->status != Deleted) {
3817 peer_notify_unconfig(other);
d62a17ae 3818 peer_delete(other);
4e2786df 3819 }
d62a17ae 3820 }
1ff9a340 3821 }
718e3744 3822
d62a17ae 3823 return CMD_SUCCESS;
718e3744 3824}
3825
a80beece
DS
3826DEFUN (no_neighbor_interface_config,
3827 no_neighbor_interface_config_cmd,
d7b9898c 3828 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3829 NO_STR
3830 NEIGHBOR_STR
3831 "Interface name\n"
31500417
DW
3832 "Configure BGP on interface\n"
3833 "Enable BGP with v6 link-local only\n"
3834 "Member of the peer-group\n"
16cedbb0 3835 "Peer-group name\n"
3a2d747c
QY
3836 "Specify a BGP neighbor\n"
3837 AS_STR
3838 "Internal BGP peer\n"
3839 "External BGP peer\n")
a80beece 3840{
d62a17ae 3841 VTY_DECLVAR_CONTEXT(bgp, bgp);
3842 int idx_word = 2;
3843 struct peer *peer;
3844
3845 /* look up for neighbor by interface name config. */
3846 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3847 if (peer) {
3848 /* Request zebra to terminate IPv6 RAs on this interface. */
3849 if (peer->ifp)
3850 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3851 peer_notify_unconfig(peer);
d62a17ae 3852 peer_delete(peer);
3853 } else {
3854 vty_out(vty, "%% Create the bgp interface first\n");
3855 return CMD_WARNING_CONFIG_FAILED;
3856 }
3857 return CMD_SUCCESS;
a80beece
DS
3858}
3859
718e3744 3860DEFUN (no_neighbor_peer_group,
3861 no_neighbor_peer_group_cmd,
3862 "no neighbor WORD peer-group",
3863 NO_STR
3864 NEIGHBOR_STR
3865 "Neighbor tag\n"
3866 "Configure peer-group\n")
3867{
d62a17ae 3868 VTY_DECLVAR_CONTEXT(bgp, bgp);
3869 int idx_word = 2;
3870 struct peer_group *group;
718e3744 3871
d62a17ae 3872 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4e2786df
DA
3873 if (group) {
3874 peer_group_notify_unconfig(group);
d62a17ae 3875 peer_group_delete(group);
4e2786df 3876 } else {
d62a17ae 3877 vty_out(vty, "%% Create the peer-group first\n");
3878 return CMD_WARNING_CONFIG_FAILED;
3879 }
3880 return CMD_SUCCESS;
718e3744 3881}
3882
a80beece
DS
3883DEFUN (no_neighbor_interface_peer_group_remote_as,
3884 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3885 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3886 NO_STR
3887 NEIGHBOR_STR
a80beece 3888 "Interface name or neighbor tag\n"
718e3744 3889 "Specify a BGP neighbor\n"
3a2d747c
QY
3890 AS_STR
3891 "Internal BGP peer\n"
3892 "External BGP peer\n")
718e3744 3893{
d62a17ae 3894 VTY_DECLVAR_CONTEXT(bgp, bgp);
3895 int idx_word = 2;
3896 struct peer_group *group;
3897 struct peer *peer;
3898
3899 /* look up for neighbor by interface name config. */
3900 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3901 if (peer) {
390485fd 3902 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 3903 return CMD_SUCCESS;
3904 }
3905
3906 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3907 if (group)
3908 peer_group_remote_as_delete(group);
3909 else {
3910 vty_out(vty, "%% Create the peer-group or interface first\n");
3911 return CMD_WARNING_CONFIG_FAILED;
3912 }
3913 return CMD_SUCCESS;
718e3744 3914}
6b0655a2 3915
718e3744 3916DEFUN (neighbor_local_as,
3917 neighbor_local_as_cmd,
9ccf14f7 3918 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3919 NEIGHBOR_STR
3920 NEIGHBOR_ADDR_STR2
3921 "Specify a local-as number\n"
3922 "AS number used as local AS\n")
3923{
d62a17ae 3924 int idx_peer = 1;
3925 int idx_number = 3;
3926 struct peer *peer;
3927 int ret;
3928 as_t as;
718e3744 3929
d62a17ae 3930 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3931 if (!peer)
3932 return CMD_WARNING_CONFIG_FAILED;
718e3744 3933
d62a17ae 3934 as = strtoul(argv[idx_number]->arg, NULL, 10);
3935 ret = peer_local_as_set(peer, as, 0, 0);
3936 return bgp_vty_return(vty, ret);
718e3744 3937}
3938
3939DEFUN (neighbor_local_as_no_prepend,
3940 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3941 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3942 NEIGHBOR_STR
3943 NEIGHBOR_ADDR_STR2
3944 "Specify a local-as number\n"
3945 "AS number used as local AS\n"
3946 "Do not prepend local-as to updates from ebgp peers\n")
3947{
d62a17ae 3948 int idx_peer = 1;
3949 int idx_number = 3;
3950 struct peer *peer;
3951 int ret;
3952 as_t as;
718e3744 3953
d62a17ae 3954 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3955 if (!peer)
3956 return CMD_WARNING_CONFIG_FAILED;
718e3744 3957
d62a17ae 3958 as = strtoul(argv[idx_number]->arg, NULL, 10);
3959 ret = peer_local_as_set(peer, as, 1, 0);
3960 return bgp_vty_return(vty, ret);
718e3744 3961}
3962
9d3f9705
AC
3963DEFUN (neighbor_local_as_no_prepend_replace_as,
3964 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3965 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3966 NEIGHBOR_STR
3967 NEIGHBOR_ADDR_STR2
3968 "Specify a local-as number\n"
3969 "AS number used as local AS\n"
3970 "Do not prepend local-as to updates from ebgp peers\n"
3971 "Do not prepend local-as to updates from ibgp peers\n")
3972{
d62a17ae 3973 int idx_peer = 1;
3974 int idx_number = 3;
3975 struct peer *peer;
3976 int ret;
3977 as_t as;
9d3f9705 3978
d62a17ae 3979 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3980 if (!peer)
3981 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3982
d62a17ae 3983 as = strtoul(argv[idx_number]->arg, NULL, 10);
3984 ret = peer_local_as_set(peer, as, 1, 1);
3985 return bgp_vty_return(vty, ret);
9d3f9705
AC
3986}
3987
718e3744 3988DEFUN (no_neighbor_local_as,
3989 no_neighbor_local_as_cmd,
a636c635 3990 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3991 NO_STR
3992 NEIGHBOR_STR
3993 NEIGHBOR_ADDR_STR2
a636c635
DW
3994 "Specify a local-as number\n"
3995 "AS number used as local AS\n"
3996 "Do not prepend local-as to updates from ebgp peers\n"
3997 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3998{
d62a17ae 3999 int idx_peer = 2;
4000 struct peer *peer;
4001 int ret;
718e3744 4002
d62a17ae 4003 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4004 if (!peer)
4005 return CMD_WARNING_CONFIG_FAILED;
718e3744 4006
d62a17ae 4007 ret = peer_local_as_unset(peer);
4008 return bgp_vty_return(vty, ret);
718e3744 4009}
4010
718e3744 4011
3f9c7369
DS
4012DEFUN (neighbor_solo,
4013 neighbor_solo_cmd,
9ccf14f7 4014 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4015 NEIGHBOR_STR
4016 NEIGHBOR_ADDR_STR2
4017 "Solo peer - part of its own update group\n")
4018{
d62a17ae 4019 int idx_peer = 1;
4020 struct peer *peer;
4021 int ret;
3f9c7369 4022
d62a17ae 4023 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4024 if (!peer)
4025 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4026
d62a17ae 4027 ret = update_group_adjust_soloness(peer, 1);
4028 return bgp_vty_return(vty, ret);
3f9c7369
DS
4029}
4030
4031DEFUN (no_neighbor_solo,
4032 no_neighbor_solo_cmd,
9ccf14f7 4033 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4034 NO_STR
4035 NEIGHBOR_STR
4036 NEIGHBOR_ADDR_STR2
4037 "Solo peer - part of its own update group\n")
4038{
d62a17ae 4039 int idx_peer = 2;
4040 struct peer *peer;
4041 int ret;
3f9c7369 4042
d62a17ae 4043 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4044 if (!peer)
4045 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4046
d62a17ae 4047 ret = update_group_adjust_soloness(peer, 0);
4048 return bgp_vty_return(vty, ret);
3f9c7369
DS
4049}
4050
0df7c91f
PJ
4051DEFUN (neighbor_password,
4052 neighbor_password_cmd,
9ccf14f7 4053 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
4054 NEIGHBOR_STR
4055 NEIGHBOR_ADDR_STR2
4056 "Set a password\n"
4057 "The password\n")
4058{
d62a17ae 4059 int idx_peer = 1;
4060 int idx_line = 3;
4061 struct peer *peer;
4062 int ret;
0df7c91f 4063
d62a17ae 4064 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4065 if (!peer)
4066 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4067
d62a17ae 4068 ret = peer_password_set(peer, argv[idx_line]->arg);
4069 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4070}
4071
4072DEFUN (no_neighbor_password,
4073 no_neighbor_password_cmd,
a636c635 4074 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
4075 NO_STR
4076 NEIGHBOR_STR
4077 NEIGHBOR_ADDR_STR2
16cedbb0
QY
4078 "Set a password\n"
4079 "The password\n")
0df7c91f 4080{
d62a17ae 4081 int idx_peer = 2;
4082 struct peer *peer;
4083 int ret;
0df7c91f 4084
d62a17ae 4085 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4086 if (!peer)
4087 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4088
d62a17ae 4089 ret = peer_password_unset(peer);
4090 return bgp_vty_return(vty, ret);
0df7c91f 4091}
6b0655a2 4092
718e3744 4093DEFUN (neighbor_activate,
4094 neighbor_activate_cmd,
9ccf14f7 4095 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4096 NEIGHBOR_STR
4097 NEIGHBOR_ADDR_STR2
4098 "Enable the Address Family for this Neighbor\n")
4099{
d62a17ae 4100 int idx_peer = 1;
4101 int ret;
4102 struct peer *peer;
718e3744 4103
d62a17ae 4104 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4105 if (!peer)
4106 return CMD_WARNING_CONFIG_FAILED;
718e3744 4107
d62a17ae 4108 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4109 return bgp_vty_return(vty, ret);
718e3744 4110}
4111
d62a17ae 4112ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4113 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4114 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4115 "Enable the Address Family for this Neighbor\n")
596c17ba 4116
718e3744 4117DEFUN (no_neighbor_activate,
4118 no_neighbor_activate_cmd,
9ccf14f7 4119 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4120 NO_STR
4121 NEIGHBOR_STR
4122 NEIGHBOR_ADDR_STR2
4123 "Enable the Address Family for this Neighbor\n")
4124{
d62a17ae 4125 int idx_peer = 2;
4126 int ret;
4127 struct peer *peer;
718e3744 4128
d62a17ae 4129 /* Lookup peer. */
4130 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4131 if (!peer)
4132 return CMD_WARNING_CONFIG_FAILED;
718e3744 4133
d62a17ae 4134 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4135 return bgp_vty_return(vty, ret);
718e3744 4136}
6b0655a2 4137
d62a17ae 4138ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4139 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4140 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4141 "Enable the Address Family for this Neighbor\n")
596c17ba 4142
718e3744 4143DEFUN (neighbor_set_peer_group,
4144 neighbor_set_peer_group_cmd,
d7b9898c 4145 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4146 NEIGHBOR_STR
a80beece 4147 NEIGHBOR_ADDR_STR2
718e3744 4148 "Member of the peer-group\n"
16cedbb0 4149 "Peer-group name\n")
718e3744 4150{
d62a17ae 4151 VTY_DECLVAR_CONTEXT(bgp, bgp);
4152 int idx_peer = 1;
4153 int idx_word = 3;
4154 int ret;
4155 as_t as;
4156 union sockunion su;
4157 struct peer *peer;
4158 struct peer_group *group;
4159
d62a17ae 4160 ret = str2sockunion(argv[idx_peer]->arg, &su);
4161 if (ret < 0) {
4162 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4163 if (!peer) {
4164 vty_out(vty, "%% Malformed address or name: %s\n",
4165 argv[idx_peer]->arg);
4166 return CMD_WARNING_CONFIG_FAILED;
4167 }
4168 } else {
4169 if (peer_address_self_check(bgp, &su)) {
4170 vty_out(vty,
4171 "%% Can not configure the local system as neighbor\n");
4172 return CMD_WARNING_CONFIG_FAILED;
4173 }
4174
4175 /* Disallow for dynamic neighbor. */
4176 peer = peer_lookup(bgp, &su);
4177 if (peer && peer_dynamic_neighbor(peer)) {
4178 vty_out(vty,
4179 "%% Operation not allowed on a dynamic neighbor\n");
4180 return CMD_WARNING_CONFIG_FAILED;
4181 }
4182 }
4183
4184 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4185 if (!group) {
4186 vty_out(vty, "%% Configure the peer-group first\n");
4187 return CMD_WARNING_CONFIG_FAILED;
4188 }
4189
4190 ret = peer_group_bind(bgp, &su, peer, group, &as);
4191
4192 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4193 vty_out(vty,
4194 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4195 as);
4196 return CMD_WARNING_CONFIG_FAILED;
4197 }
4198
4199 return bgp_vty_return(vty, ret);
4200}
4201
4202ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4203 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4204 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4205 "Member of the peer-group\n"
4206 "Peer-group name\n")
596c17ba 4207
718e3744 4208DEFUN (no_neighbor_set_peer_group,
4209 no_neighbor_set_peer_group_cmd,
d7b9898c 4210 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4211 NO_STR
4212 NEIGHBOR_STR
a80beece 4213 NEIGHBOR_ADDR_STR2
718e3744 4214 "Member of the peer-group\n"
16cedbb0 4215 "Peer-group name\n")
718e3744 4216{
d62a17ae 4217 VTY_DECLVAR_CONTEXT(bgp, bgp);
4218 int idx_peer = 2;
4219 int idx_word = 4;
4220 int ret;
4221 struct peer *peer;
4222 struct peer_group *group;
4223
4224 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4225 if (!peer)
4226 return CMD_WARNING_CONFIG_FAILED;
4227
4228 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4229 if (!group) {
4230 vty_out(vty, "%% Configure the peer-group first\n");
4231 return CMD_WARNING_CONFIG_FAILED;
4232 }
718e3744 4233
4e2786df 4234 peer_notify_unconfig(peer);
827ed707 4235 ret = peer_delete(peer);
718e3744 4236
d62a17ae 4237 return bgp_vty_return(vty, ret);
718e3744 4238}
6b0655a2 4239
d62a17ae 4240ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4241 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4242 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4243 "Member of the peer-group\n"
4244 "Peer-group name\n")
596c17ba 4245
d62a17ae 4246static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4247 uint32_t flag, int set)
718e3744 4248{
d62a17ae 4249 int ret;
4250 struct peer *peer;
718e3744 4251
d62a17ae 4252 peer = peer_and_group_lookup_vty(vty, ip_str);
4253 if (!peer)
4254 return CMD_WARNING_CONFIG_FAILED;
718e3744 4255
7ebe625c
QY
4256 /*
4257 * If 'neighbor <interface>', then this is for directly connected peers,
4258 * we should not accept disable-connected-check.
4259 */
4260 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4261 vty_out(vty,
4262 "%s is directly connected peer, cannot accept disable-"
4263 "connected-check\n",
4264 ip_str);
4265 return CMD_WARNING_CONFIG_FAILED;
4266 }
4267
d62a17ae 4268 if (!set && flag == PEER_FLAG_SHUTDOWN)
4269 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4270
d62a17ae 4271 if (set)
4272 ret = peer_flag_set(peer, flag);
4273 else
4274 ret = peer_flag_unset(peer, flag);
718e3744 4275
d62a17ae 4276 return bgp_vty_return(vty, ret);
718e3744 4277}
4278
47cbc09b 4279static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4280{
d62a17ae 4281 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4282}
4283
d62a17ae 4284static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4285 uint32_t flag)
718e3744 4286{
d62a17ae 4287 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4288}
4289
4290/* neighbor passive. */
4291DEFUN (neighbor_passive,
4292 neighbor_passive_cmd,
9ccf14f7 4293 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4294 NEIGHBOR_STR
4295 NEIGHBOR_ADDR_STR2
4296 "Don't send open messages to this neighbor\n")
4297{
d62a17ae 4298 int idx_peer = 1;
4299 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4300}
4301
4302DEFUN (no_neighbor_passive,
4303 no_neighbor_passive_cmd,
9ccf14f7 4304 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4305 NO_STR
4306 NEIGHBOR_STR
4307 NEIGHBOR_ADDR_STR2
4308 "Don't send open messages to this neighbor\n")
4309{
d62a17ae 4310 int idx_peer = 2;
4311 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4312}
6b0655a2 4313
718e3744 4314/* neighbor shutdown. */
73d70fa6
DL
4315DEFUN (neighbor_shutdown_msg,
4316 neighbor_shutdown_msg_cmd,
4317 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 4318 NEIGHBOR_STR
4319 NEIGHBOR_ADDR_STR2
73d70fa6
DL
4320 "Administratively shut down this neighbor\n"
4321 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
4322 "Shutdown message\n")
718e3744 4323{
d62a17ae 4324 int idx_peer = 1;
73d70fa6 4325
d62a17ae 4326 if (argc >= 5) {
4327 struct peer *peer =
4328 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4329 char *message;
73d70fa6 4330
d62a17ae 4331 if (!peer)
4332 return CMD_WARNING_CONFIG_FAILED;
4333 message = argv_concat(argv, argc, 4);
4334 peer_tx_shutdown_message_set(peer, message);
4335 XFREE(MTYPE_TMP, message);
4336 }
73d70fa6 4337
d62a17ae 4338 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 4339}
4340
d62a17ae 4341ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4342 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4343 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4344 "Administratively shut down this neighbor\n")
73d70fa6
DL
4345
4346DEFUN (no_neighbor_shutdown_msg,
4347 no_neighbor_shutdown_msg_cmd,
4348 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4349 NO_STR
4350 NEIGHBOR_STR
4351 NEIGHBOR_ADDR_STR2
4352 "Administratively shut down this neighbor\n"
4353 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
4354 "Shutdown message\n")
718e3744 4355{
d62a17ae 4356 int idx_peer = 2;
73d70fa6 4357
d62a17ae 4358 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4359 PEER_FLAG_SHUTDOWN);
718e3744 4360}
6b0655a2 4361
d62a17ae 4362ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4363 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4364 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4365 "Administratively shut down this neighbor\n")
73d70fa6 4366
718e3744 4367/* neighbor capability dynamic. */
4368DEFUN (neighbor_capability_dynamic,
4369 neighbor_capability_dynamic_cmd,
9ccf14f7 4370 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4371 NEIGHBOR_STR
4372 NEIGHBOR_ADDR_STR2
4373 "Advertise capability to the peer\n"
4374 "Advertise dynamic capability to this neighbor\n")
4375{
d62a17ae 4376 int idx_peer = 1;
4377 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4378 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4379}
4380
4381DEFUN (no_neighbor_capability_dynamic,
4382 no_neighbor_capability_dynamic_cmd,
9ccf14f7 4383 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4384 NO_STR
4385 NEIGHBOR_STR
4386 NEIGHBOR_ADDR_STR2
4387 "Advertise capability to the peer\n"
4388 "Advertise dynamic capability to this neighbor\n")
4389{
d62a17ae 4390 int idx_peer = 2;
4391 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4392 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4393}
6b0655a2 4394
718e3744 4395/* neighbor dont-capability-negotiate */
4396DEFUN (neighbor_dont_capability_negotiate,
4397 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4398 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4399 NEIGHBOR_STR
4400 NEIGHBOR_ADDR_STR2
4401 "Do not perform capability negotiation\n")
4402{
d62a17ae 4403 int idx_peer = 1;
4404 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4405 PEER_FLAG_DONT_CAPABILITY);
718e3744 4406}
4407
4408DEFUN (no_neighbor_dont_capability_negotiate,
4409 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4410 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4411 NO_STR
4412 NEIGHBOR_STR
4413 NEIGHBOR_ADDR_STR2
4414 "Do not perform capability negotiation\n")
4415{
d62a17ae 4416 int idx_peer = 2;
4417 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4418 PEER_FLAG_DONT_CAPABILITY);
718e3744 4419}
6b0655a2 4420
8a92a8a0
DS
4421/* neighbor capability extended next hop encoding */
4422DEFUN (neighbor_capability_enhe,
4423 neighbor_capability_enhe_cmd,
9ccf14f7 4424 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4425 NEIGHBOR_STR
4426 NEIGHBOR_ADDR_STR2
4427 "Advertise capability to the peer\n"
4428 "Advertise extended next-hop capability to the peer\n")
4429{
d62a17ae 4430 int idx_peer = 1;
4431 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4432 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4433}
4434
4435DEFUN (no_neighbor_capability_enhe,
4436 no_neighbor_capability_enhe_cmd,
9ccf14f7 4437 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4438 NO_STR
4439 NEIGHBOR_STR
4440 NEIGHBOR_ADDR_STR2
4441 "Advertise capability to the peer\n"
4442 "Advertise extended next-hop capability to the peer\n")
4443{
d62a17ae 4444 int idx_peer = 2;
4445 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4446 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4447}
4448
d62a17ae 4449static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4450 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 4451 int set)
718e3744 4452{
d62a17ae 4453 int ret;
4454 struct peer *peer;
718e3744 4455
d62a17ae 4456 peer = peer_and_group_lookup_vty(vty, peer_str);
4457 if (!peer)
4458 return CMD_WARNING_CONFIG_FAILED;
718e3744 4459
d62a17ae 4460 if (set)
4461 ret = peer_af_flag_set(peer, afi, safi, flag);
4462 else
4463 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 4464
d62a17ae 4465 return bgp_vty_return(vty, ret);
718e3744 4466}
4467
d62a17ae 4468static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4469 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4470{
d62a17ae 4471 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 4472}
4473
d62a17ae 4474static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4475 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4476{
d62a17ae 4477 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 4478}
6b0655a2 4479
718e3744 4480/* neighbor capability orf prefix-list. */
4481DEFUN (neighbor_capability_orf_prefix,
4482 neighbor_capability_orf_prefix_cmd,
9ccf14f7 4483 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4484 NEIGHBOR_STR
4485 NEIGHBOR_ADDR_STR2
4486 "Advertise capability to the peer\n"
4487 "Advertise ORF capability to the peer\n"
4488 "Advertise prefixlist ORF capability to this neighbor\n"
4489 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4490 "Capability to RECEIVE the ORF from this neighbor\n"
4491 "Capability to SEND the ORF to this neighbor\n")
4492{
d62a17ae 4493 int idx_peer = 1;
4494 int idx_send_recv = 5;
d7c0a89a 4495 uint16_t flag = 0;
d62a17ae 4496
4497 if (strmatch(argv[idx_send_recv]->text, "send"))
4498 flag = PEER_FLAG_ORF_PREFIX_SM;
4499 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4500 flag = PEER_FLAG_ORF_PREFIX_RM;
4501 else if (strmatch(argv[idx_send_recv]->text, "both"))
4502 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4503 else {
4504 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4505 return CMD_WARNING_CONFIG_FAILED;
4506 }
4507
4508 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4509 bgp_node_safi(vty), flag);
4510}
4511
4512ALIAS_HIDDEN(
4513 neighbor_capability_orf_prefix,
4514 neighbor_capability_orf_prefix_hidden_cmd,
4515 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4516 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4517 "Advertise capability to the peer\n"
4518 "Advertise ORF capability to the peer\n"
4519 "Advertise prefixlist ORF capability to this neighbor\n"
4520 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4521 "Capability to RECEIVE the ORF from this neighbor\n"
4522 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4523
718e3744 4524DEFUN (no_neighbor_capability_orf_prefix,
4525 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 4526 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4527 NO_STR
4528 NEIGHBOR_STR
4529 NEIGHBOR_ADDR_STR2
4530 "Advertise capability to the peer\n"
4531 "Advertise ORF capability to the peer\n"
4532 "Advertise prefixlist ORF capability to this neighbor\n"
4533 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4534 "Capability to RECEIVE the ORF from this neighbor\n"
4535 "Capability to SEND the ORF to this neighbor\n")
4536{
d62a17ae 4537 int idx_peer = 2;
4538 int idx_send_recv = 6;
d7c0a89a 4539 uint16_t flag = 0;
d62a17ae 4540
4541 if (strmatch(argv[idx_send_recv]->text, "send"))
4542 flag = PEER_FLAG_ORF_PREFIX_SM;
4543 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4544 flag = PEER_FLAG_ORF_PREFIX_RM;
4545 else if (strmatch(argv[idx_send_recv]->text, "both"))
4546 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4547 else {
4548 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4549 return CMD_WARNING_CONFIG_FAILED;
4550 }
4551
4552 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4553 bgp_node_afi(vty), bgp_node_safi(vty),
4554 flag);
4555}
4556
4557ALIAS_HIDDEN(
4558 no_neighbor_capability_orf_prefix,
4559 no_neighbor_capability_orf_prefix_hidden_cmd,
4560 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4561 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4562 "Advertise capability to the peer\n"
4563 "Advertise ORF capability to the peer\n"
4564 "Advertise prefixlist ORF capability to this neighbor\n"
4565 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4566 "Capability to RECEIVE the ORF from this neighbor\n"
4567 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4568
718e3744 4569/* neighbor next-hop-self. */
4570DEFUN (neighbor_nexthop_self,
4571 neighbor_nexthop_self_cmd,
9ccf14f7 4572 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4573 NEIGHBOR_STR
4574 NEIGHBOR_ADDR_STR2
a538debe 4575 "Disable the next hop calculation for this neighbor\n")
718e3744 4576{
d62a17ae 4577 int idx_peer = 1;
4578 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4579 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 4580}
9e7a53c1 4581
d62a17ae 4582ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
4583 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4584 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4585 "Disable the next hop calculation for this neighbor\n")
596c17ba 4586
a538debe
DS
4587/* neighbor next-hop-self. */
4588DEFUN (neighbor_nexthop_self_force,
4589 neighbor_nexthop_self_force_cmd,
9ccf14f7 4590 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4591 NEIGHBOR_STR
4592 NEIGHBOR_ADDR_STR2
4593 "Disable the next hop calculation for this neighbor\n"
4594 "Set the next hop to self for reflected routes\n")
4595{
d62a17ae 4596 int idx_peer = 1;
4597 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4598 bgp_node_safi(vty),
4599 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 4600}
4601
d62a17ae 4602ALIAS_HIDDEN(neighbor_nexthop_self_force,
4603 neighbor_nexthop_self_force_hidden_cmd,
4604 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4605 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4606 "Disable the next hop calculation for this neighbor\n"
4607 "Set the next hop to self for reflected routes\n")
596c17ba 4608
1bc4e531
DA
4609ALIAS_HIDDEN(neighbor_nexthop_self_force,
4610 neighbor_nexthop_self_all_hidden_cmd,
4611 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4612 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4613 "Disable the next hop calculation for this neighbor\n"
4614 "Set the next hop to self for reflected routes\n")
4615
718e3744 4616DEFUN (no_neighbor_nexthop_self,
4617 no_neighbor_nexthop_self_cmd,
9ccf14f7 4618 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4619 NO_STR
4620 NEIGHBOR_STR
4621 NEIGHBOR_ADDR_STR2
a538debe 4622 "Disable the next hop calculation for this neighbor\n")
718e3744 4623{
d62a17ae 4624 int idx_peer = 2;
4625 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4626 bgp_node_afi(vty), bgp_node_safi(vty),
4627 PEER_FLAG_NEXTHOP_SELF);
718e3744 4628}
6b0655a2 4629
d62a17ae 4630ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4631 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4632 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4633 "Disable the next hop calculation for this neighbor\n")
596c17ba 4634
88b8ed8d 4635DEFUN (no_neighbor_nexthop_self_force,
a538debe 4636 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 4637 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4638 NO_STR
4639 NEIGHBOR_STR
4640 NEIGHBOR_ADDR_STR2
4641 "Disable the next hop calculation for this neighbor\n"
4642 "Set the next hop to self for reflected routes\n")
88b8ed8d 4643{
d62a17ae 4644 int idx_peer = 2;
4645 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4646 bgp_node_afi(vty), bgp_node_safi(vty),
4647 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 4648}
a538debe 4649
d62a17ae 4650ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4651 no_neighbor_nexthop_self_force_hidden_cmd,
4652 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4653 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4654 "Disable the next hop calculation for this neighbor\n"
4655 "Set the next hop to self for reflected routes\n")
596c17ba 4656
1bc4e531
DA
4657ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4658 no_neighbor_nexthop_self_all_hidden_cmd,
4659 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4660 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4661 "Disable the next hop calculation for this neighbor\n"
4662 "Set the next hop to self for reflected routes\n")
4663
c7122e14
DS
4664/* neighbor as-override */
4665DEFUN (neighbor_as_override,
4666 neighbor_as_override_cmd,
9ccf14f7 4667 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4668 NEIGHBOR_STR
4669 NEIGHBOR_ADDR_STR2
4670 "Override ASNs in outbound updates if aspath equals remote-as\n")
4671{
d62a17ae 4672 int idx_peer = 1;
4673 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4674 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4675}
4676
d62a17ae 4677ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4678 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4679 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4680 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4681
c7122e14
DS
4682DEFUN (no_neighbor_as_override,
4683 no_neighbor_as_override_cmd,
9ccf14f7 4684 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4685 NO_STR
4686 NEIGHBOR_STR
4687 NEIGHBOR_ADDR_STR2
4688 "Override ASNs in outbound updates if aspath equals remote-as\n")
4689{
d62a17ae 4690 int idx_peer = 2;
4691 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4692 bgp_node_afi(vty), bgp_node_safi(vty),
4693 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4694}
4695
d62a17ae 4696ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4697 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4698 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4699 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4700
718e3744 4701/* neighbor remove-private-AS. */
4702DEFUN (neighbor_remove_private_as,
4703 neighbor_remove_private_as_cmd,
9ccf14f7 4704 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4705 NEIGHBOR_STR
4706 NEIGHBOR_ADDR_STR2
5000f21c 4707 "Remove private ASNs in outbound updates\n")
718e3744 4708{
d62a17ae 4709 int idx_peer = 1;
4710 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4711 bgp_node_safi(vty),
4712 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4713}
4714
d62a17ae 4715ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4716 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4717 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4718 "Remove private ASNs in outbound updates\n")
596c17ba 4719
5000f21c
DS
4720DEFUN (neighbor_remove_private_as_all,
4721 neighbor_remove_private_as_all_cmd,
9ccf14f7 4722 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "Remove private ASNs in outbound updates\n"
efd7904e 4726 "Apply to all AS numbers\n")
5000f21c 4727{
d62a17ae 4728 int idx_peer = 1;
4729 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4730 bgp_node_safi(vty),
4731 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4732}
4733
d62a17ae 4734ALIAS_HIDDEN(neighbor_remove_private_as_all,
4735 neighbor_remove_private_as_all_hidden_cmd,
4736 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4737 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4738 "Remove private ASNs in outbound updates\n"
4739 "Apply to all AS numbers")
596c17ba 4740
5000f21c
DS
4741DEFUN (neighbor_remove_private_as_replace_as,
4742 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4743 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4744 NEIGHBOR_STR
4745 NEIGHBOR_ADDR_STR2
4746 "Remove private ASNs in outbound updates\n"
4747 "Replace private ASNs with our ASN in outbound updates\n")
4748{
d62a17ae 4749 int idx_peer = 1;
4750 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4751 bgp_node_safi(vty),
4752 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4753}
4754
d62a17ae 4755ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4756 neighbor_remove_private_as_replace_as_hidden_cmd,
4757 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4758 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4759 "Remove private ASNs in outbound updates\n"
4760 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4761
5000f21c
DS
4762DEFUN (neighbor_remove_private_as_all_replace_as,
4763 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4764 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4765 NEIGHBOR_STR
4766 NEIGHBOR_ADDR_STR2
4767 "Remove private ASNs in outbound updates\n"
16cedbb0 4768 "Apply to all AS numbers\n"
5000f21c
DS
4769 "Replace private ASNs with our ASN in outbound updates\n")
4770{
d62a17ae 4771 int idx_peer = 1;
4772 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4773 bgp_node_safi(vty),
4774 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4775}
4776
d62a17ae 4777ALIAS_HIDDEN(
4778 neighbor_remove_private_as_all_replace_as,
4779 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4780 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4781 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4782 "Remove private ASNs in outbound updates\n"
4783 "Apply to all AS numbers\n"
4784 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4785
718e3744 4786DEFUN (no_neighbor_remove_private_as,
4787 no_neighbor_remove_private_as_cmd,
9ccf14f7 4788 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4789 NO_STR
4790 NEIGHBOR_STR
4791 NEIGHBOR_ADDR_STR2
5000f21c 4792 "Remove private ASNs in outbound updates\n")
718e3744 4793{
d62a17ae 4794 int idx_peer = 2;
4795 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4796 bgp_node_afi(vty), bgp_node_safi(vty),
4797 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4798}
6b0655a2 4799
d62a17ae 4800ALIAS_HIDDEN(no_neighbor_remove_private_as,
4801 no_neighbor_remove_private_as_hidden_cmd,
4802 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4803 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4804 "Remove private ASNs in outbound updates\n")
596c17ba 4805
88b8ed8d 4806DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4807 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4808 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4809 NO_STR
4810 NEIGHBOR_STR
4811 NEIGHBOR_ADDR_STR2
4812 "Remove private ASNs in outbound updates\n"
16cedbb0 4813 "Apply to all AS numbers\n")
88b8ed8d 4814{
d62a17ae 4815 int idx_peer = 2;
4816 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4817 bgp_node_afi(vty), bgp_node_safi(vty),
4818 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4819}
5000f21c 4820
d62a17ae 4821ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4822 no_neighbor_remove_private_as_all_hidden_cmd,
4823 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4824 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4825 "Remove private ASNs in outbound updates\n"
4826 "Apply to all AS numbers\n")
596c17ba 4827
88b8ed8d 4828DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4829 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4830 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4831 NO_STR
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Remove private ASNs in outbound updates\n"
4835 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4836{
d62a17ae 4837 int idx_peer = 2;
4838 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4839 bgp_node_afi(vty), bgp_node_safi(vty),
4840 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4841}
5000f21c 4842
d62a17ae 4843ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4844 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4845 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4846 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4847 "Remove private ASNs in outbound updates\n"
4848 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4849
88b8ed8d 4850DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4851 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4852 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4853 NO_STR
4854 NEIGHBOR_STR
4855 NEIGHBOR_ADDR_STR2
4856 "Remove private ASNs in outbound updates\n"
16cedbb0 4857 "Apply to all AS numbers\n"
5000f21c 4858 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4859{
d62a17ae 4860 int idx_peer = 2;
4861 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4862 bgp_node_afi(vty), bgp_node_safi(vty),
4863 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4864}
5000f21c 4865
d62a17ae 4866ALIAS_HIDDEN(
4867 no_neighbor_remove_private_as_all_replace_as,
4868 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4869 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4870 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4871 "Remove private ASNs in outbound updates\n"
4872 "Apply to all AS numbers\n"
4873 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4874
5000f21c 4875
718e3744 4876/* neighbor send-community. */
4877DEFUN (neighbor_send_community,
4878 neighbor_send_community_cmd,
9ccf14f7 4879 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4880 NEIGHBOR_STR
4881 NEIGHBOR_ADDR_STR2
4882 "Send Community attribute to this neighbor\n")
4883{
d62a17ae 4884 int idx_peer = 1;
27c05d4d 4885
d62a17ae 4886 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4887 bgp_node_safi(vty),
4888 PEER_FLAG_SEND_COMMUNITY);
718e3744 4889}
4890
d62a17ae 4891ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4892 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4894 "Send Community attribute to this neighbor\n")
596c17ba 4895
718e3744 4896DEFUN (no_neighbor_send_community,
4897 no_neighbor_send_community_cmd,
9ccf14f7 4898 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4899 NO_STR
4900 NEIGHBOR_STR
4901 NEIGHBOR_ADDR_STR2
4902 "Send Community attribute to this neighbor\n")
4903{
d62a17ae 4904 int idx_peer = 2;
27c05d4d 4905
d62a17ae 4906 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4907 bgp_node_afi(vty), bgp_node_safi(vty),
4908 PEER_FLAG_SEND_COMMUNITY);
718e3744 4909}
6b0655a2 4910
d62a17ae 4911ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4912 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4913 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4914 "Send Community attribute to this neighbor\n")
596c17ba 4915
718e3744 4916/* neighbor send-community extended. */
4917DEFUN (neighbor_send_community_type,
4918 neighbor_send_community_type_cmd,
57d187bc 4919 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
4922 "Send Community attribute to this neighbor\n"
4923 "Send Standard and Extended Community attributes\n"
57d187bc 4924 "Send Standard, Large and Extended Community attributes\n"
718e3744 4925 "Send Extended Community attributes\n"
57d187bc
JS
4926 "Send Standard Community attributes\n"
4927 "Send Large Community attributes\n")
718e3744 4928{
27c05d4d 4929 int idx_peer = 1;
d7c0a89a 4930 uint32_t flag = 0;
27c05d4d 4931 const char *type = argv[argc - 1]->text;
d62a17ae 4932
27c05d4d 4933 if (strmatch(type, "standard")) {
d62a17ae 4934 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4935 } else if (strmatch(type, "extended")) {
d62a17ae 4936 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4937 } else if (strmatch(type, "large")) {
d62a17ae 4938 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4939 } else if (strmatch(type, "both")) {
d62a17ae 4940 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4941 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4942 } else { /* if (strmatch(type, "all")) */
d62a17ae 4943 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4944 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4945 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4946 }
4947
27c05d4d 4948 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4949 bgp_node_safi(vty), flag);
4950}
4951
4952ALIAS_HIDDEN(
4953 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4954 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4955 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4956 "Send Community attribute to this neighbor\n"
4957 "Send Standard and Extended Community attributes\n"
4958 "Send Standard, Large and Extended Community attributes\n"
4959 "Send Extended Community attributes\n"
4960 "Send Standard Community attributes\n"
4961 "Send Large Community attributes\n")
596c17ba 4962
718e3744 4963DEFUN (no_neighbor_send_community_type,
4964 no_neighbor_send_community_type_cmd,
57d187bc 4965 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4966 NO_STR
4967 NEIGHBOR_STR
4968 NEIGHBOR_ADDR_STR2
4969 "Send Community attribute to this neighbor\n"
4970 "Send Standard and Extended Community attributes\n"
57d187bc 4971 "Send Standard, Large and Extended Community attributes\n"
718e3744 4972 "Send Extended Community attributes\n"
57d187bc
JS
4973 "Send Standard Community attributes\n"
4974 "Send Large Community attributes\n")
718e3744 4975{
d62a17ae 4976 int idx_peer = 2;
27c05d4d 4977 uint32_t flag = 0;
d62a17ae 4978 const char *type = argv[argc - 1]->text;
4979
27c05d4d
PM
4980 if (strmatch(type, "standard")) {
4981 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4982 } else if (strmatch(type, "extended")) {
4983 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4984 } else if (strmatch(type, "large")) {
4985 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4986 } else if (strmatch(type, "both")) {
4987 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4988 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4989 } else { /* if (strmatch(type, "all")) */
4990 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4991 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4992 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4993 }
4994
4995 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4996 bgp_node_afi(vty), bgp_node_safi(vty),
4997 flag);
d62a17ae 4998}
4999
5000ALIAS_HIDDEN(
5001 no_neighbor_send_community_type,
5002 no_neighbor_send_community_type_hidden_cmd,
5003 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5004 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5005 "Send Community attribute to this neighbor\n"
5006 "Send Standard and Extended Community attributes\n"
5007 "Send Standard, Large and Extended Community attributes\n"
5008 "Send Extended Community attributes\n"
5009 "Send Standard Community attributes\n"
5010 "Send Large Community attributes\n")
596c17ba 5011
718e3744 5012/* neighbor soft-reconfig. */
5013DEFUN (neighbor_soft_reconfiguration,
5014 neighbor_soft_reconfiguration_cmd,
9ccf14f7 5015 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5016 NEIGHBOR_STR
5017 NEIGHBOR_ADDR_STR2
5018 "Per neighbor soft reconfiguration\n"
5019 "Allow inbound soft reconfiguration for this neighbor\n")
5020{
d62a17ae 5021 int idx_peer = 1;
5022 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5023 bgp_node_safi(vty),
5024 PEER_FLAG_SOFT_RECONFIG);
718e3744 5025}
5026
d62a17ae 5027ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5028 neighbor_soft_reconfiguration_hidden_cmd,
5029 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5031 "Per neighbor soft reconfiguration\n"
5032 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5033
718e3744 5034DEFUN (no_neighbor_soft_reconfiguration,
5035 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 5036 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5037 NO_STR
5038 NEIGHBOR_STR
5039 NEIGHBOR_ADDR_STR2
5040 "Per neighbor soft reconfiguration\n"
5041 "Allow inbound soft reconfiguration for this neighbor\n")
5042{
d62a17ae 5043 int idx_peer = 2;
5044 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5045 bgp_node_afi(vty), bgp_node_safi(vty),
5046 PEER_FLAG_SOFT_RECONFIG);
718e3744 5047}
6b0655a2 5048
d62a17ae 5049ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5050 no_neighbor_soft_reconfiguration_hidden_cmd,
5051 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5052 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5053 "Per neighbor soft reconfiguration\n"
5054 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5055
718e3744 5056DEFUN (neighbor_route_reflector_client,
5057 neighbor_route_reflector_client_cmd,
9ccf14f7 5058 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5059 NEIGHBOR_STR
5060 NEIGHBOR_ADDR_STR2
5061 "Configure a neighbor as Route Reflector client\n")
5062{
d62a17ae 5063 int idx_peer = 1;
5064 struct peer *peer;
718e3744 5065
5066
d62a17ae 5067 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5068 if (!peer)
5069 return CMD_WARNING_CONFIG_FAILED;
718e3744 5070
d62a17ae 5071 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5072 bgp_node_safi(vty),
5073 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5074}
5075
d62a17ae 5076ALIAS_HIDDEN(neighbor_route_reflector_client,
5077 neighbor_route_reflector_client_hidden_cmd,
5078 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5079 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5080 "Configure a neighbor as Route Reflector client\n")
596c17ba 5081
718e3744 5082DEFUN (no_neighbor_route_reflector_client,
5083 no_neighbor_route_reflector_client_cmd,
9ccf14f7 5084 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5085 NO_STR
5086 NEIGHBOR_STR
5087 NEIGHBOR_ADDR_STR2
5088 "Configure a neighbor as Route Reflector client\n")
5089{
d62a17ae 5090 int idx_peer = 2;
5091 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5092 bgp_node_afi(vty), bgp_node_safi(vty),
5093 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5094}
6b0655a2 5095
d62a17ae 5096ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5097 no_neighbor_route_reflector_client_hidden_cmd,
5098 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5099 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5100 "Configure a neighbor as Route Reflector client\n")
596c17ba 5101
718e3744 5102/* neighbor route-server-client. */
5103DEFUN (neighbor_route_server_client,
5104 neighbor_route_server_client_cmd,
9ccf14f7 5105 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5106 NEIGHBOR_STR
5107 NEIGHBOR_ADDR_STR2
5108 "Configure a neighbor as Route Server client\n")
5109{
d62a17ae 5110 int idx_peer = 1;
5111 struct peer *peer;
2a3d5731 5112
d62a17ae 5113 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5114 if (!peer)
5115 return CMD_WARNING_CONFIG_FAILED;
5116 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5117 bgp_node_safi(vty),
5118 PEER_FLAG_RSERVER_CLIENT);
718e3744 5119}
5120
d62a17ae 5121ALIAS_HIDDEN(neighbor_route_server_client,
5122 neighbor_route_server_client_hidden_cmd,
5123 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5124 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5125 "Configure a neighbor as Route Server client\n")
596c17ba 5126
718e3744 5127DEFUN (no_neighbor_route_server_client,
5128 no_neighbor_route_server_client_cmd,
9ccf14f7 5129 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5130 NO_STR
5131 NEIGHBOR_STR
5132 NEIGHBOR_ADDR_STR2
5133 "Configure a neighbor as Route Server client\n")
fee0f4c6 5134{
d62a17ae 5135 int idx_peer = 2;
5136 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5137 bgp_node_afi(vty), bgp_node_safi(vty),
5138 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5139}
6b0655a2 5140
d62a17ae 5141ALIAS_HIDDEN(no_neighbor_route_server_client,
5142 no_neighbor_route_server_client_hidden_cmd,
5143 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5144 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5145 "Configure a neighbor as Route Server client\n")
596c17ba 5146
fee0f4c6 5147DEFUN (neighbor_nexthop_local_unchanged,
5148 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5149 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5150 NEIGHBOR_STR
5151 NEIGHBOR_ADDR_STR2
5152 "Configure treatment of outgoing link-local nexthop attribute\n"
5153 "Leave link-local nexthop unchanged for this peer\n")
5154{
d62a17ae 5155 int idx_peer = 1;
5156 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5157 bgp_node_safi(vty),
5158 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 5159}
6b0655a2 5160
fee0f4c6 5161DEFUN (no_neighbor_nexthop_local_unchanged,
5162 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5163 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5164 NO_STR
5165 NEIGHBOR_STR
5166 NEIGHBOR_ADDR_STR2
5167 "Configure treatment of outgoing link-local-nexthop attribute\n"
5168 "Leave link-local nexthop unchanged for this peer\n")
718e3744 5169{
d62a17ae 5170 int idx_peer = 2;
5171 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5172 bgp_node_afi(vty), bgp_node_safi(vty),
5173 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 5174}
6b0655a2 5175
718e3744 5176DEFUN (neighbor_attr_unchanged,
5177 neighbor_attr_unchanged_cmd,
a8206004 5178 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 5179 NEIGHBOR_STR
5180 NEIGHBOR_ADDR_STR2
5181 "BGP attribute is propagated unchanged to this neighbor\n"
5182 "As-path attribute\n"
5183 "Nexthop attribute\n"
a8206004 5184 "Med attribute\n")
718e3744 5185{
d62a17ae 5186 int idx = 0;
8eeb0335
DW
5187 char *peer_str = argv[1]->arg;
5188 struct peer *peer;
d7c0a89a 5189 uint16_t flags = 0;
8eeb0335
DW
5190 afi_t afi = bgp_node_afi(vty);
5191 safi_t safi = bgp_node_safi(vty);
5192
5193 peer = peer_and_group_lookup_vty(vty, peer_str);
5194 if (!peer)
5195 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5196
5197 if (argv_find(argv, argc, "as-path", &idx))
5198 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5199 idx = 0;
5200 if (argv_find(argv, argc, "next-hop", &idx))
5201 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5202 idx = 0;
5203 if (argv_find(argv, argc, "med", &idx))
5204 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5205
8eeb0335
DW
5206 /* no flags means all of them! */
5207 if (!flags) {
d62a17ae 5208 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5209 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5210 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 5211 } else {
a4d82a8a
PZ
5212 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
5213 && peer_af_flag_check(peer, afi, safi,
5214 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
5215 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5216 PEER_FLAG_AS_PATH_UNCHANGED);
5217 }
5218
a4d82a8a
PZ
5219 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
5220 && peer_af_flag_check(peer, afi, safi,
5221 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
5222 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5223 PEER_FLAG_NEXTHOP_UNCHANGED);
5224 }
5225
a4d82a8a
PZ
5226 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
5227 && peer_af_flag_check(peer, afi, safi,
5228 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
5229 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5230 PEER_FLAG_MED_UNCHANGED);
5231 }
d62a17ae 5232 }
5233
8eeb0335 5234 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 5235}
5236
5237ALIAS_HIDDEN(
5238 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5239 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5240 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5241 "BGP attribute is propagated unchanged to this neighbor\n"
5242 "As-path attribute\n"
5243 "Nexthop attribute\n"
5244 "Med attribute\n")
596c17ba 5245
718e3744 5246DEFUN (no_neighbor_attr_unchanged,
5247 no_neighbor_attr_unchanged_cmd,
a8206004 5248 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 5249 NO_STR
718e3744 5250 NEIGHBOR_STR
5251 NEIGHBOR_ADDR_STR2
31500417
DW
5252 "BGP attribute is propagated unchanged to this neighbor\n"
5253 "As-path attribute\n"
40e718b5 5254 "Nexthop attribute\n"
a8206004 5255 "Med attribute\n")
718e3744 5256{
d62a17ae 5257 int idx = 0;
5258 char *peer = argv[2]->arg;
d7c0a89a 5259 uint16_t flags = 0;
d62a17ae 5260
5261 if (argv_find(argv, argc, "as-path", &idx))
5262 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5263 idx = 0;
5264 if (argv_find(argv, argc, "next-hop", &idx))
5265 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5266 idx = 0;
5267 if (argv_find(argv, argc, "med", &idx))
5268 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5269
5270 if (!flags) // no flags means all of them!
5271 {
5272 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5273 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5274 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5275 }
5276
5277 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
5278 bgp_node_safi(vty), flags);
5279}
5280
5281ALIAS_HIDDEN(
5282 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5283 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5284 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5285 "BGP attribute is propagated unchanged to this neighbor\n"
5286 "As-path attribute\n"
5287 "Nexthop attribute\n"
5288 "Med attribute\n")
718e3744 5289
718e3744 5290/* EBGP multihop configuration. */
d62a17ae 5291static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5292 const char *ttl_str)
718e3744 5293{
d62a17ae 5294 struct peer *peer;
5295 unsigned int ttl;
718e3744 5296
d62a17ae 5297 peer = peer_and_group_lookup_vty(vty, ip_str);
5298 if (!peer)
5299 return CMD_WARNING_CONFIG_FAILED;
718e3744 5300
d62a17ae 5301 if (peer->conf_if)
5302 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 5303
d62a17ae 5304 if (!ttl_str)
5305 ttl = MAXTTL;
5306 else
5307 ttl = strtoul(ttl_str, NULL, 10);
718e3744 5308
d62a17ae 5309 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 5310}
5311
d62a17ae 5312static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5313{
d62a17ae 5314 struct peer *peer;
718e3744 5315
d62a17ae 5316 peer = peer_and_group_lookup_vty(vty, ip_str);
5317 if (!peer)
5318 return CMD_WARNING_CONFIG_FAILED;
718e3744 5319
d62a17ae 5320 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 5321}
5322
5323/* neighbor ebgp-multihop. */
5324DEFUN (neighbor_ebgp_multihop,
5325 neighbor_ebgp_multihop_cmd,
9ccf14f7 5326 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 5327 NEIGHBOR_STR
5328 NEIGHBOR_ADDR_STR2
5329 "Allow EBGP neighbors not on directly connected networks\n")
5330{
d62a17ae 5331 int idx_peer = 1;
5332 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5333}
5334
5335DEFUN (neighbor_ebgp_multihop_ttl,
5336 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 5337 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 5338 NEIGHBOR_STR
5339 NEIGHBOR_ADDR_STR2
5340 "Allow EBGP neighbors not on directly connected networks\n"
5341 "maximum hop count\n")
5342{
d62a17ae 5343 int idx_peer = 1;
5344 int idx_number = 3;
5345 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
5346 argv[idx_number]->arg);
718e3744 5347}
5348
5349DEFUN (no_neighbor_ebgp_multihop,
5350 no_neighbor_ebgp_multihop_cmd,
a636c635 5351 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 5352 NO_STR
5353 NEIGHBOR_STR
5354 NEIGHBOR_ADDR_STR2
a636c635
DW
5355 "Allow EBGP neighbors not on directly connected networks\n"
5356 "maximum hop count\n")
718e3744 5357{
d62a17ae 5358 int idx_peer = 2;
5359 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5360}
5361
6b0655a2 5362
6ffd2079 5363/* disable-connected-check */
5364DEFUN (neighbor_disable_connected_check,
5365 neighbor_disable_connected_check_cmd,
7ebe625c 5366 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5367 NEIGHBOR_STR
7ebe625c 5368 NEIGHBOR_ADDR_STR2
a636c635
DW
5369 "one-hop away EBGP peer using loopback address\n"
5370 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5371{
d62a17ae 5372 int idx_peer = 1;
5373 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5374 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5375}
5376
5377DEFUN (no_neighbor_disable_connected_check,
5378 no_neighbor_disable_connected_check_cmd,
7ebe625c 5379 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5380 NO_STR
5381 NEIGHBOR_STR
7ebe625c 5382 NEIGHBOR_ADDR_STR2
a636c635
DW
5383 "one-hop away EBGP peer using loopback address\n"
5384 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5385{
d62a17ae 5386 int idx_peer = 2;
5387 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5388 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5389}
5390
47cbc09b
PM
5391
5392/* enforce-first-as */
5393DEFUN (neighbor_enforce_first_as,
5394 neighbor_enforce_first_as_cmd,
5395 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5396 NEIGHBOR_STR
5397 NEIGHBOR_ADDR_STR2
5398 "Enforce the first AS for EBGP routes\n")
5399{
5400 int idx_peer = 1;
5401
5402 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5403 PEER_FLAG_ENFORCE_FIRST_AS);
5404}
5405
5406DEFUN (no_neighbor_enforce_first_as,
5407 no_neighbor_enforce_first_as_cmd,
5408 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5409 NO_STR
5410 NEIGHBOR_STR
5411 NEIGHBOR_ADDR_STR2
5412 "Enforce the first AS for EBGP routes\n")
5413{
5414 int idx_peer = 2;
5415
5416 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5417 PEER_FLAG_ENFORCE_FIRST_AS);
5418}
5419
5420
718e3744 5421DEFUN (neighbor_description,
5422 neighbor_description_cmd,
e961923c 5423 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 5424 NEIGHBOR_STR
5425 NEIGHBOR_ADDR_STR2
5426 "Neighbor specific description\n"
5427 "Up to 80 characters describing this neighbor\n")
5428{
d62a17ae 5429 int idx_peer = 1;
5430 int idx_line = 3;
5431 struct peer *peer;
5432 char *str;
718e3744 5433
d62a17ae 5434 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5435 if (!peer)
5436 return CMD_WARNING_CONFIG_FAILED;
718e3744 5437
d62a17ae 5438 str = argv_concat(argv, argc, idx_line);
718e3744 5439
d62a17ae 5440 peer_description_set(peer, str);
718e3744 5441
d62a17ae 5442 XFREE(MTYPE_TMP, str);
718e3744 5443
d62a17ae 5444 return CMD_SUCCESS;
718e3744 5445}
5446
5447DEFUN (no_neighbor_description,
5448 no_neighbor_description_cmd,
a14810f4 5449 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 5450 NO_STR
5451 NEIGHBOR_STR
5452 NEIGHBOR_ADDR_STR2
a14810f4 5453 "Neighbor specific description\n")
718e3744 5454{
d62a17ae 5455 int idx_peer = 2;
5456 struct peer *peer;
718e3744 5457
d62a17ae 5458 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5459 if (!peer)
5460 return CMD_WARNING_CONFIG_FAILED;
718e3744 5461
d62a17ae 5462 peer_description_unset(peer);
718e3744 5463
d62a17ae 5464 return CMD_SUCCESS;
718e3744 5465}
5466
a14810f4
PM
5467ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
5468 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5469 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5470 "Neighbor specific description\n"
5471 "Up to 80 characters describing this neighbor\n")
6b0655a2 5472
718e3744 5473/* Neighbor update-source. */
d62a17ae 5474static int peer_update_source_vty(struct vty *vty, const char *peer_str,
5475 const char *source_str)
5476{
5477 struct peer *peer;
5478 struct prefix p;
a14810f4 5479 union sockunion su;
d62a17ae 5480
5481 peer = peer_and_group_lookup_vty(vty, peer_str);
5482 if (!peer)
5483 return CMD_WARNING_CONFIG_FAILED;
5484
5485 if (peer->conf_if)
5486 return CMD_WARNING;
5487
5488 if (source_str) {
a14810f4 5489 if (str2sockunion(source_str, &su) == 0)
d62a17ae 5490 peer_update_source_addr_set(peer, &su);
5491 else {
5492 if (str2prefix(source_str, &p)) {
5493 vty_out(vty,
5494 "%% Invalid update-source, remove prefix length \n");
5495 return CMD_WARNING_CONFIG_FAILED;
5496 } else
5497 peer_update_source_if_set(peer, source_str);
5498 }
5499 } else
5500 peer_update_source_unset(peer);
5501
5502 return CMD_SUCCESS;
5503}
5504
5505#define BGP_UPDATE_SOURCE_HELP_STR \
5506 "IPv4 address\n" \
5507 "IPv6 address\n" \
5508 "Interface name (requires zebra to be running)\n"
369688c0 5509
718e3744 5510DEFUN (neighbor_update_source,
5511 neighbor_update_source_cmd,
9ccf14f7 5512 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 5513 NEIGHBOR_STR
5514 NEIGHBOR_ADDR_STR2
5515 "Source of routing updates\n"
369688c0 5516 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5517{
d62a17ae 5518 int idx_peer = 1;
5519 int idx_peer_2 = 3;
5520 return peer_update_source_vty(vty, argv[idx_peer]->arg,
5521 argv[idx_peer_2]->arg);
718e3744 5522}
5523
5524DEFUN (no_neighbor_update_source,
5525 no_neighbor_update_source_cmd,
c7178fe7 5526 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 5527 NO_STR
5528 NEIGHBOR_STR
5529 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
5530 "Source of routing updates\n"
5531 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5532{
d62a17ae 5533 int idx_peer = 2;
5534 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5535}
6b0655a2 5536
d62a17ae 5537static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
5538 afi_t afi, safi_t safi,
5539 const char *rmap, int set)
718e3744 5540{
d62a17ae 5541 int ret;
5542 struct peer *peer;
80912664 5543 struct route_map *route_map = NULL;
718e3744 5544
d62a17ae 5545 peer = peer_and_group_lookup_vty(vty, peer_str);
5546 if (!peer)
5547 return CMD_WARNING_CONFIG_FAILED;
718e3744 5548
1de27621 5549 if (set) {
80912664
DS
5550 if (rmap)
5551 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
5552 ret = peer_default_originate_set(peer, afi, safi,
5553 rmap, route_map);
5554 } else
d62a17ae 5555 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 5556
d62a17ae 5557 return bgp_vty_return(vty, ret);
718e3744 5558}
5559
5560/* neighbor default-originate. */
5561DEFUN (neighbor_default_originate,
5562 neighbor_default_originate_cmd,
9ccf14f7 5563 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 5564 NEIGHBOR_STR
5565 NEIGHBOR_ADDR_STR2
5566 "Originate default route to this neighbor\n")
5567{
d62a17ae 5568 int idx_peer = 1;
5569 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5570 bgp_node_afi(vty),
5571 bgp_node_safi(vty), NULL, 1);
718e3744 5572}
5573
d62a17ae 5574ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
5575 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5576 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5577 "Originate default route to this neighbor\n")
596c17ba 5578
718e3744 5579DEFUN (neighbor_default_originate_rmap,
5580 neighbor_default_originate_rmap_cmd,
9ccf14f7 5581 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 5582 NEIGHBOR_STR
5583 NEIGHBOR_ADDR_STR2
5584 "Originate default route to this neighbor\n"
5585 "Route-map to specify criteria to originate default\n"
5586 "route-map name\n")
5587{
d62a17ae 5588 int idx_peer = 1;
5589 int idx_word = 4;
5590 return peer_default_originate_set_vty(
5591 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5592 argv[idx_word]->arg, 1);
718e3744 5593}
5594
d62a17ae 5595ALIAS_HIDDEN(
5596 neighbor_default_originate_rmap,
5597 neighbor_default_originate_rmap_hidden_cmd,
5598 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5599 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5600 "Originate default route to this neighbor\n"
5601 "Route-map to specify criteria to originate default\n"
5602 "route-map name\n")
596c17ba 5603
718e3744 5604DEFUN (no_neighbor_default_originate,
5605 no_neighbor_default_originate_cmd,
a636c635 5606 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 5607 NO_STR
5608 NEIGHBOR_STR
5609 NEIGHBOR_ADDR_STR2
a636c635
DW
5610 "Originate default route to this neighbor\n"
5611 "Route-map to specify criteria to originate default\n"
5612 "route-map name\n")
718e3744 5613{
d62a17ae 5614 int idx_peer = 2;
5615 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5616 bgp_node_afi(vty),
5617 bgp_node_safi(vty), NULL, 0);
718e3744 5618}
5619
d62a17ae 5620ALIAS_HIDDEN(
5621 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5622 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5623 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5624 "Originate default route to this neighbor\n"
5625 "Route-map to specify criteria to originate default\n"
5626 "route-map name\n")
596c17ba 5627
6b0655a2 5628
718e3744 5629/* Set neighbor's BGP port. */
d62a17ae 5630static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5631 const char *port_str)
5632{
5633 struct peer *peer;
d7c0a89a 5634 uint16_t port;
d62a17ae 5635 struct servent *sp;
5636
5637 peer = peer_lookup_vty(vty, ip_str);
5638 if (!peer)
5639 return CMD_WARNING_CONFIG_FAILED;
5640
5641 if (!port_str) {
5642 sp = getservbyname("bgp", "tcp");
5643 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5644 } else {
5645 port = strtoul(port_str, NULL, 10);
5646 }
718e3744 5647
d62a17ae 5648 peer_port_set(peer, port);
718e3744 5649
d62a17ae 5650 return CMD_SUCCESS;
718e3744 5651}
5652
f418446b 5653/* Set specified peer's BGP port. */
718e3744 5654DEFUN (neighbor_port,
5655 neighbor_port_cmd,
9ccf14f7 5656 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR
5659 "Neighbor's BGP port\n"
5660 "TCP port number\n")
5661{
d62a17ae 5662 int idx_ip = 1;
5663 int idx_number = 3;
5664 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5665 argv[idx_number]->arg);
718e3744 5666}
5667
5668DEFUN (no_neighbor_port,
5669 no_neighbor_port_cmd,
9ccf14f7 5670 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 5671 NO_STR
5672 NEIGHBOR_STR
5673 NEIGHBOR_ADDR_STR
8334fd5a
DW
5674 "Neighbor's BGP port\n"
5675 "TCP port number\n")
718e3744 5676{
d62a17ae 5677 int idx_ip = 2;
5678 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 5679}
5680
6b0655a2 5681
718e3744 5682/* neighbor weight. */
d62a17ae 5683static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5684 safi_t safi, const char *weight_str)
718e3744 5685{
d62a17ae 5686 int ret;
5687 struct peer *peer;
5688 unsigned long weight;
718e3744 5689
d62a17ae 5690 peer = peer_and_group_lookup_vty(vty, ip_str);
5691 if (!peer)
5692 return CMD_WARNING_CONFIG_FAILED;
718e3744 5693
d62a17ae 5694 weight = strtoul(weight_str, NULL, 10);
718e3744 5695
d62a17ae 5696 ret = peer_weight_set(peer, afi, safi, weight);
5697 return bgp_vty_return(vty, ret);
718e3744 5698}
5699
d62a17ae 5700static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5701 safi_t safi)
718e3744 5702{
d62a17ae 5703 int ret;
5704 struct peer *peer;
718e3744 5705
d62a17ae 5706 peer = peer_and_group_lookup_vty(vty, ip_str);
5707 if (!peer)
5708 return CMD_WARNING_CONFIG_FAILED;
718e3744 5709
d62a17ae 5710 ret = peer_weight_unset(peer, afi, safi);
5711 return bgp_vty_return(vty, ret);
718e3744 5712}
5713
5714DEFUN (neighbor_weight,
5715 neighbor_weight_cmd,
9ccf14f7 5716 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5717 NEIGHBOR_STR
5718 NEIGHBOR_ADDR_STR2
5719 "Set default weight for routes from this neighbor\n"
5720 "default weight\n")
5721{
d62a17ae 5722 int idx_peer = 1;
5723 int idx_number = 3;
5724 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5725 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5726}
5727
d62a17ae 5728ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5729 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5730 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5731 "Set default weight for routes from this neighbor\n"
5732 "default weight\n")
596c17ba 5733
718e3744 5734DEFUN (no_neighbor_weight,
5735 no_neighbor_weight_cmd,
9ccf14f7 5736 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5737 NO_STR
5738 NEIGHBOR_STR
5739 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5740 "Set default weight for routes from this neighbor\n"
5741 "default weight\n")
718e3744 5742{
d62a17ae 5743 int idx_peer = 2;
5744 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5745 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5746}
5747
d62a17ae 5748ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5749 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5750 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5751 "Set default weight for routes from this neighbor\n"
5752 "default weight\n")
596c17ba 5753
6b0655a2 5754
718e3744 5755/* Override capability negotiation. */
5756DEFUN (neighbor_override_capability,
5757 neighbor_override_capability_cmd,
9ccf14f7 5758 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5759 NEIGHBOR_STR
5760 NEIGHBOR_ADDR_STR2
5761 "Override capability negotiation result\n")
5762{
d62a17ae 5763 int idx_peer = 1;
5764 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5765 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5766}
5767
5768DEFUN (no_neighbor_override_capability,
5769 no_neighbor_override_capability_cmd,
9ccf14f7 5770 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5771 NO_STR
5772 NEIGHBOR_STR
5773 NEIGHBOR_ADDR_STR2
5774 "Override capability negotiation result\n")
5775{
d62a17ae 5776 int idx_peer = 2;
5777 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5778 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5779}
6b0655a2 5780
718e3744 5781DEFUN (neighbor_strict_capability,
5782 neighbor_strict_capability_cmd,
9fb964de 5783 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5784 NEIGHBOR_STR
9fb964de 5785 NEIGHBOR_ADDR_STR2
718e3744 5786 "Strict capability negotiation match\n")
5787{
9fb964de
PM
5788 int idx_peer = 1;
5789
5790 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5791 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5792}
5793
5794DEFUN (no_neighbor_strict_capability,
5795 no_neighbor_strict_capability_cmd,
9fb964de 5796 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5797 NO_STR
5798 NEIGHBOR_STR
9fb964de 5799 NEIGHBOR_ADDR_STR2
718e3744 5800 "Strict capability negotiation match\n")
5801{
9fb964de
PM
5802 int idx_peer = 2;
5803
5804 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5805 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5806}
6b0655a2 5807
d62a17ae 5808static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5809 const char *keep_str, const char *hold_str)
718e3744 5810{
d62a17ae 5811 int ret;
5812 struct peer *peer;
d7c0a89a
QY
5813 uint32_t keepalive;
5814 uint32_t holdtime;
718e3744 5815
d62a17ae 5816 peer = peer_and_group_lookup_vty(vty, ip_str);
5817 if (!peer)
5818 return CMD_WARNING_CONFIG_FAILED;
718e3744 5819
d62a17ae 5820 keepalive = strtoul(keep_str, NULL, 10);
5821 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5822
d62a17ae 5823 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5824
d62a17ae 5825 return bgp_vty_return(vty, ret);
718e3744 5826}
6b0655a2 5827
d62a17ae 5828static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5829{
d62a17ae 5830 int ret;
5831 struct peer *peer;
718e3744 5832
d62a17ae 5833 peer = peer_and_group_lookup_vty(vty, ip_str);
5834 if (!peer)
5835 return CMD_WARNING_CONFIG_FAILED;
718e3744 5836
d62a17ae 5837 ret = peer_timers_unset(peer);
718e3744 5838
d62a17ae 5839 return bgp_vty_return(vty, ret);
718e3744 5840}
5841
5842DEFUN (neighbor_timers,
5843 neighbor_timers_cmd,
9ccf14f7 5844 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5845 NEIGHBOR_STR
5846 NEIGHBOR_ADDR_STR2
5847 "BGP per neighbor timers\n"
5848 "Keepalive interval\n"
5849 "Holdtime\n")
5850{
d62a17ae 5851 int idx_peer = 1;
5852 int idx_number = 3;
5853 int idx_number_2 = 4;
5854 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5855 argv[idx_number]->arg,
5856 argv[idx_number_2]->arg);
718e3744 5857}
5858
5859DEFUN (no_neighbor_timers,
5860 no_neighbor_timers_cmd,
9ccf14f7 5861 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5862 NO_STR
5863 NEIGHBOR_STR
5864 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5865 "BGP per neighbor timers\n"
5866 "Keepalive interval\n"
5867 "Holdtime\n")
718e3744 5868{
d62a17ae 5869 int idx_peer = 2;
5870 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5871}
6b0655a2 5872
813d4307 5873
d62a17ae 5874static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5875 const char *time_str)
718e3744 5876{
d62a17ae 5877 int ret;
5878 struct peer *peer;
d7c0a89a 5879 uint32_t connect;
718e3744 5880
d62a17ae 5881 peer = peer_and_group_lookup_vty(vty, ip_str);
5882 if (!peer)
5883 return CMD_WARNING_CONFIG_FAILED;
718e3744 5884
d62a17ae 5885 connect = strtoul(time_str, NULL, 10);
718e3744 5886
d62a17ae 5887 ret = peer_timers_connect_set(peer, connect);
718e3744 5888
d62a17ae 5889 return bgp_vty_return(vty, ret);
718e3744 5890}
5891
d62a17ae 5892static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5893{
d62a17ae 5894 int ret;
5895 struct peer *peer;
718e3744 5896
d62a17ae 5897 peer = peer_and_group_lookup_vty(vty, ip_str);
5898 if (!peer)
5899 return CMD_WARNING_CONFIG_FAILED;
718e3744 5900
d62a17ae 5901 ret = peer_timers_connect_unset(peer);
718e3744 5902
d62a17ae 5903 return bgp_vty_return(vty, ret);
718e3744 5904}
5905
5906DEFUN (neighbor_timers_connect,
5907 neighbor_timers_connect_cmd,
9ccf14f7 5908 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5909 NEIGHBOR_STR
966f821c 5910 NEIGHBOR_ADDR_STR2
718e3744 5911 "BGP per neighbor timers\n"
5912 "BGP connect timer\n"
5913 "Connect timer\n")
5914{
d62a17ae 5915 int idx_peer = 1;
5916 int idx_number = 4;
5917 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5918 argv[idx_number]->arg);
718e3744 5919}
5920
5921DEFUN (no_neighbor_timers_connect,
5922 no_neighbor_timers_connect_cmd,
9ccf14f7 5923 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5924 NO_STR
5925 NEIGHBOR_STR
966f821c 5926 NEIGHBOR_ADDR_STR2
718e3744 5927 "BGP per neighbor timers\n"
8334fd5a
DW
5928 "BGP connect timer\n"
5929 "Connect timer\n")
718e3744 5930{
d62a17ae 5931 int idx_peer = 2;
5932 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5933}
5934
6b0655a2 5935
d62a17ae 5936static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5937 const char *time_str, int set)
718e3744 5938{
d62a17ae 5939 int ret;
5940 struct peer *peer;
d7c0a89a 5941 uint32_t routeadv = 0;
718e3744 5942
d62a17ae 5943 peer = peer_and_group_lookup_vty(vty, ip_str);
5944 if (!peer)
5945 return CMD_WARNING_CONFIG_FAILED;
718e3744 5946
d62a17ae 5947 if (time_str)
5948 routeadv = strtoul(time_str, NULL, 10);
718e3744 5949
d62a17ae 5950 if (set)
5951 ret = peer_advertise_interval_set(peer, routeadv);
5952 else
5953 ret = peer_advertise_interval_unset(peer);
718e3744 5954
d62a17ae 5955 return bgp_vty_return(vty, ret);
718e3744 5956}
5957
5958DEFUN (neighbor_advertise_interval,
5959 neighbor_advertise_interval_cmd,
9ccf14f7 5960 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5961 NEIGHBOR_STR
966f821c 5962 NEIGHBOR_ADDR_STR2
718e3744 5963 "Minimum interval between sending BGP routing updates\n"
5964 "time in seconds\n")
5965{
d62a17ae 5966 int idx_peer = 1;
5967 int idx_number = 3;
5968 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5969 argv[idx_number]->arg, 1);
718e3744 5970}
5971
5972DEFUN (no_neighbor_advertise_interval,
5973 no_neighbor_advertise_interval_cmd,
9ccf14f7 5974 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5975 NO_STR
5976 NEIGHBOR_STR
966f821c 5977 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5978 "Minimum interval between sending BGP routing updates\n"
5979 "time in seconds\n")
718e3744 5980{
d62a17ae 5981 int idx_peer = 2;
5982 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5983}
5984
6b0655a2 5985
518f0eb1
DS
5986/* Time to wait before processing route-map updates */
5987DEFUN (bgp_set_route_map_delay_timer,
5988 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5989 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5990 SET_STR
5991 "BGP route-map delay timer\n"
5992 "Time in secs to wait before processing route-map changes\n"
f414725f 5993 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5994{
d62a17ae 5995 int idx_number = 3;
d7c0a89a 5996 uint32_t rmap_delay_timer;
d62a17ae 5997
5998 if (argv[idx_number]->arg) {
5999 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6000 bm->rmap_update_timer = rmap_delay_timer;
6001
6002 /* if the dynamic update handling is being disabled, and a timer
6003 * is
6004 * running, stop the timer and act as if the timer has already
6005 * fired.
6006 */
6007 if (!rmap_delay_timer && bm->t_rmap_update) {
6008 BGP_TIMER_OFF(bm->t_rmap_update);
6009 thread_execute(bm->master, bgp_route_map_update_timer,
6010 NULL, 0);
6011 }
6012 return CMD_SUCCESS;
6013 } else {
6014 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6015 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 6016 }
518f0eb1
DS
6017}
6018
6019DEFUN (no_bgp_set_route_map_delay_timer,
6020 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 6021 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 6022 NO_STR
3a2d747c 6023 BGP_STR
518f0eb1 6024 "Default BGP route-map delay timer\n"
8334fd5a
DW
6025 "Reset to default time to wait for processing route-map changes\n"
6026 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6027{
518f0eb1 6028
d62a17ae 6029 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 6030
d62a17ae 6031 return CMD_SUCCESS;
518f0eb1
DS
6032}
6033
f414725f 6034
718e3744 6035/* neighbor interface */
d62a17ae 6036static int peer_interface_vty(struct vty *vty, const char *ip_str,
6037 const char *str)
718e3744 6038{
d62a17ae 6039 struct peer *peer;
718e3744 6040
d62a17ae 6041 peer = peer_lookup_vty(vty, ip_str);
6042 if (!peer || peer->conf_if) {
6043 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6044 return CMD_WARNING_CONFIG_FAILED;
6045 }
718e3744 6046
d62a17ae 6047 if (str)
6048 peer_interface_set(peer, str);
6049 else
6050 peer_interface_unset(peer);
718e3744 6051
d62a17ae 6052 return CMD_SUCCESS;
718e3744 6053}
6054
6055DEFUN (neighbor_interface,
6056 neighbor_interface_cmd,
9ccf14f7 6057 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 6058 NEIGHBOR_STR
6059 NEIGHBOR_ADDR_STR
6060 "Interface\n"
6061 "Interface name\n")
6062{
d62a17ae 6063 int idx_ip = 1;
6064 int idx_word = 3;
6065 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 6066}
6067
6068DEFUN (no_neighbor_interface,
6069 no_neighbor_interface_cmd,
9ccf14f7 6070 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 6071 NO_STR
6072 NEIGHBOR_STR
16cedbb0 6073 NEIGHBOR_ADDR_STR2
718e3744 6074 "Interface\n"
6075 "Interface name\n")
6076{
d62a17ae 6077 int idx_peer = 2;
6078 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6079}
6b0655a2 6080
718e3744 6081DEFUN (neighbor_distribute_list,
6082 neighbor_distribute_list_cmd,
9ccf14f7 6083 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6084 NEIGHBOR_STR
6085 NEIGHBOR_ADDR_STR2
6086 "Filter updates to/from this neighbor\n"
6087 "IP access-list number\n"
6088 "IP access-list number (expanded range)\n"
6089 "IP Access-list name\n"
6090 "Filter incoming updates\n"
6091 "Filter outgoing updates\n")
6092{
d62a17ae 6093 int idx_peer = 1;
6094 int idx_acl = 3;
6095 int direct, ret;
6096 struct peer *peer;
a8206004 6097
d62a17ae 6098 const char *pstr = argv[idx_peer]->arg;
6099 const char *acl = argv[idx_acl]->arg;
6100 const char *inout = argv[argc - 1]->text;
a8206004 6101
d62a17ae 6102 peer = peer_and_group_lookup_vty(vty, pstr);
6103 if (!peer)
6104 return CMD_WARNING_CONFIG_FAILED;
a8206004 6105
d62a17ae 6106 /* Check filter direction. */
6107 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6108 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6109 direct, acl);
a8206004 6110
d62a17ae 6111 return bgp_vty_return(vty, ret);
718e3744 6112}
6113
d62a17ae 6114ALIAS_HIDDEN(
6115 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6116 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6117 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6118 "Filter updates to/from this neighbor\n"
6119 "IP access-list number\n"
6120 "IP access-list number (expanded range)\n"
6121 "IP Access-list name\n"
6122 "Filter incoming updates\n"
6123 "Filter outgoing updates\n")
596c17ba 6124
718e3744 6125DEFUN (no_neighbor_distribute_list,
6126 no_neighbor_distribute_list_cmd,
9ccf14f7 6127 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6128 NO_STR
6129 NEIGHBOR_STR
6130 NEIGHBOR_ADDR_STR2
6131 "Filter updates to/from this neighbor\n"
6132 "IP access-list number\n"
6133 "IP access-list number (expanded range)\n"
6134 "IP Access-list name\n"
6135 "Filter incoming updates\n"
6136 "Filter outgoing updates\n")
6137{
d62a17ae 6138 int idx_peer = 2;
6139 int direct, ret;
6140 struct peer *peer;
a8206004 6141
d62a17ae 6142 const char *pstr = argv[idx_peer]->arg;
6143 const char *inout = argv[argc - 1]->text;
a8206004 6144
d62a17ae 6145 peer = peer_and_group_lookup_vty(vty, pstr);
6146 if (!peer)
6147 return CMD_WARNING_CONFIG_FAILED;
a8206004 6148
d62a17ae 6149 /* Check filter direction. */
6150 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6151 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6152 direct);
a8206004 6153
d62a17ae 6154 return bgp_vty_return(vty, ret);
718e3744 6155}
6b0655a2 6156
d62a17ae 6157ALIAS_HIDDEN(
6158 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6159 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6160 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6161 "Filter updates to/from this neighbor\n"
6162 "IP access-list number\n"
6163 "IP access-list number (expanded range)\n"
6164 "IP Access-list name\n"
6165 "Filter incoming updates\n"
6166 "Filter outgoing updates\n")
596c17ba 6167
718e3744 6168/* Set prefix list to the peer. */
d62a17ae 6169static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6170 afi_t afi, safi_t safi,
6171 const char *name_str,
6172 const char *direct_str)
718e3744 6173{
d62a17ae 6174 int ret;
d62a17ae 6175 int direct = FILTER_IN;
cf9ac8bf 6176 struct peer *peer;
718e3744 6177
d62a17ae 6178 peer = peer_and_group_lookup_vty(vty, ip_str);
6179 if (!peer)
6180 return CMD_WARNING_CONFIG_FAILED;
718e3744 6181
d62a17ae 6182 /* Check filter direction. */
6183 if (strncmp(direct_str, "i", 1) == 0)
6184 direct = FILTER_IN;
6185 else if (strncmp(direct_str, "o", 1) == 0)
6186 direct = FILTER_OUT;
718e3744 6187
d62a17ae 6188 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 6189
d62a17ae 6190 return bgp_vty_return(vty, ret);
718e3744 6191}
6192
d62a17ae 6193static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6194 afi_t afi, safi_t safi,
6195 const char *direct_str)
718e3744 6196{
d62a17ae 6197 int ret;
6198 struct peer *peer;
6199 int direct = FILTER_IN;
718e3744 6200
d62a17ae 6201 peer = peer_and_group_lookup_vty(vty, ip_str);
6202 if (!peer)
6203 return CMD_WARNING_CONFIG_FAILED;
e52702f2 6204
d62a17ae 6205 /* Check filter direction. */
6206 if (strncmp(direct_str, "i", 1) == 0)
6207 direct = FILTER_IN;
6208 else if (strncmp(direct_str, "o", 1) == 0)
6209 direct = FILTER_OUT;
718e3744 6210
d62a17ae 6211 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 6212
d62a17ae 6213 return bgp_vty_return(vty, ret);
718e3744 6214}
6215
6216DEFUN (neighbor_prefix_list,
6217 neighbor_prefix_list_cmd,
9ccf14f7 6218 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6219 NEIGHBOR_STR
6220 NEIGHBOR_ADDR_STR2
6221 "Filter updates to/from this neighbor\n"
6222 "Name of a prefix list\n"
6223 "Filter incoming updates\n"
6224 "Filter outgoing updates\n")
6225{
d62a17ae 6226 int idx_peer = 1;
6227 int idx_word = 3;
6228 int idx_in_out = 4;
6229 return peer_prefix_list_set_vty(
6230 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6231 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6232}
6233
d62a17ae 6234ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6235 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6236 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6237 "Filter updates to/from this neighbor\n"
6238 "Name of a prefix list\n"
6239 "Filter incoming updates\n"
6240 "Filter outgoing updates\n")
596c17ba 6241
718e3744 6242DEFUN (no_neighbor_prefix_list,
6243 no_neighbor_prefix_list_cmd,
9ccf14f7 6244 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6245 NO_STR
6246 NEIGHBOR_STR
6247 NEIGHBOR_ADDR_STR2
6248 "Filter updates to/from this neighbor\n"
6249 "Name of a prefix list\n"
6250 "Filter incoming updates\n"
6251 "Filter outgoing updates\n")
6252{
d62a17ae 6253 int idx_peer = 2;
6254 int idx_in_out = 5;
6255 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6256 bgp_node_afi(vty), bgp_node_safi(vty),
6257 argv[idx_in_out]->arg);
718e3744 6258}
6b0655a2 6259
d62a17ae 6260ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6261 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6262 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6263 "Filter updates to/from this neighbor\n"
6264 "Name of a prefix list\n"
6265 "Filter incoming updates\n"
6266 "Filter outgoing updates\n")
596c17ba 6267
d62a17ae 6268static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6269 safi_t safi, const char *name_str,
6270 const char *direct_str)
718e3744 6271{
d62a17ae 6272 int ret;
6273 struct peer *peer;
6274 int direct = FILTER_IN;
718e3744 6275
d62a17ae 6276 peer = peer_and_group_lookup_vty(vty, ip_str);
6277 if (!peer)
6278 return CMD_WARNING_CONFIG_FAILED;
718e3744 6279
d62a17ae 6280 /* Check filter direction. */
6281 if (strncmp(direct_str, "i", 1) == 0)
6282 direct = FILTER_IN;
6283 else if (strncmp(direct_str, "o", 1) == 0)
6284 direct = FILTER_OUT;
718e3744 6285
d62a17ae 6286 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 6287
d62a17ae 6288 return bgp_vty_return(vty, ret);
718e3744 6289}
6290
d62a17ae 6291static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6292 safi_t safi, const char *direct_str)
718e3744 6293{
d62a17ae 6294 int ret;
6295 struct peer *peer;
6296 int direct = FILTER_IN;
718e3744 6297
d62a17ae 6298 peer = peer_and_group_lookup_vty(vty, ip_str);
6299 if (!peer)
6300 return CMD_WARNING_CONFIG_FAILED;
718e3744 6301
d62a17ae 6302 /* Check filter direction. */
6303 if (strncmp(direct_str, "i", 1) == 0)
6304 direct = FILTER_IN;
6305 else if (strncmp(direct_str, "o", 1) == 0)
6306 direct = FILTER_OUT;
718e3744 6307
d62a17ae 6308 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 6309
d62a17ae 6310 return bgp_vty_return(vty, ret);
718e3744 6311}
6312
6313DEFUN (neighbor_filter_list,
6314 neighbor_filter_list_cmd,
9ccf14f7 6315 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6316 NEIGHBOR_STR
6317 NEIGHBOR_ADDR_STR2
6318 "Establish BGP filters\n"
6319 "AS path access-list name\n"
6320 "Filter incoming routes\n"
6321 "Filter outgoing routes\n")
6322{
d62a17ae 6323 int idx_peer = 1;
6324 int idx_word = 3;
6325 int idx_in_out = 4;
6326 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6327 bgp_node_safi(vty), argv[idx_word]->arg,
6328 argv[idx_in_out]->arg);
718e3744 6329}
6330
d62a17ae 6331ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
6332 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6333 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6334 "Establish BGP filters\n"
6335 "AS path access-list name\n"
6336 "Filter incoming routes\n"
6337 "Filter outgoing routes\n")
596c17ba 6338
718e3744 6339DEFUN (no_neighbor_filter_list,
6340 no_neighbor_filter_list_cmd,
9ccf14f7 6341 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6342 NO_STR
6343 NEIGHBOR_STR
6344 NEIGHBOR_ADDR_STR2
6345 "Establish BGP filters\n"
6346 "AS path access-list name\n"
6347 "Filter incoming routes\n"
6348 "Filter outgoing routes\n")
6349{
d62a17ae 6350 int idx_peer = 2;
6351 int idx_in_out = 5;
6352 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
6353 bgp_node_afi(vty), bgp_node_safi(vty),
6354 argv[idx_in_out]->arg);
718e3744 6355}
6b0655a2 6356
d62a17ae 6357ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
6358 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6359 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6360 "Establish BGP filters\n"
6361 "AS path access-list name\n"
6362 "Filter incoming routes\n"
6363 "Filter outgoing routes\n")
596c17ba 6364
718e3744 6365/* Set route-map to the peer. */
d62a17ae 6366static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
6367 afi_t afi, safi_t safi, const char *name_str,
6368 const char *direct_str)
718e3744 6369{
d62a17ae 6370 int ret;
6371 struct peer *peer;
6372 int direct = RMAP_IN;
1de27621 6373 struct route_map *route_map;
718e3744 6374
d62a17ae 6375 peer = peer_and_group_lookup_vty(vty, ip_str);
6376 if (!peer)
6377 return CMD_WARNING_CONFIG_FAILED;
718e3744 6378
d62a17ae 6379 /* Check filter direction. */
6380 if (strncmp(direct_str, "in", 2) == 0)
6381 direct = RMAP_IN;
6382 else if (strncmp(direct_str, "o", 1) == 0)
6383 direct = RMAP_OUT;
718e3744 6384
1de27621
DA
6385 route_map = route_map_lookup_warn_noexist(vty, name_str);
6386 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 6387
d62a17ae 6388 return bgp_vty_return(vty, ret);
718e3744 6389}
6390
d62a17ae 6391static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
6392 afi_t afi, safi_t safi,
6393 const char *direct_str)
718e3744 6394{
d62a17ae 6395 int ret;
6396 struct peer *peer;
6397 int direct = RMAP_IN;
718e3744 6398
d62a17ae 6399 peer = peer_and_group_lookup_vty(vty, ip_str);
6400 if (!peer)
6401 return CMD_WARNING_CONFIG_FAILED;
718e3744 6402
d62a17ae 6403 /* Check filter direction. */
6404 if (strncmp(direct_str, "in", 2) == 0)
6405 direct = RMAP_IN;
6406 else if (strncmp(direct_str, "o", 1) == 0)
6407 direct = RMAP_OUT;
718e3744 6408
d62a17ae 6409 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 6410
d62a17ae 6411 return bgp_vty_return(vty, ret);
718e3744 6412}
6413
6414DEFUN (neighbor_route_map,
6415 neighbor_route_map_cmd,
9ccf14f7 6416 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6417 NEIGHBOR_STR
6418 NEIGHBOR_ADDR_STR2
6419 "Apply route map to neighbor\n"
6420 "Name of route map\n"
6421 "Apply map to incoming routes\n"
2a3d5731 6422 "Apply map to outbound routes\n")
718e3744 6423{
d62a17ae 6424 int idx_peer = 1;
6425 int idx_word = 3;
6426 int idx_in_out = 4;
6427 return peer_route_map_set_vty(
6428 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6429 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6430}
6431
d62a17ae 6432ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
6433 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6434 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6435 "Apply route map to neighbor\n"
6436 "Name of route map\n"
6437 "Apply map to incoming routes\n"
6438 "Apply map to outbound routes\n")
596c17ba 6439
718e3744 6440DEFUN (no_neighbor_route_map,
6441 no_neighbor_route_map_cmd,
9ccf14f7 6442 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6443 NO_STR
6444 NEIGHBOR_STR
6445 NEIGHBOR_ADDR_STR2
6446 "Apply route map to neighbor\n"
6447 "Name of route map\n"
6448 "Apply map to incoming routes\n"
2a3d5731 6449 "Apply map to outbound routes\n")
718e3744 6450{
d62a17ae 6451 int idx_peer = 2;
6452 int idx_in_out = 5;
6453 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
6454 bgp_node_afi(vty), bgp_node_safi(vty),
6455 argv[idx_in_out]->arg);
718e3744 6456}
6b0655a2 6457
d62a17ae 6458ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
6459 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6460 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6461 "Apply route map to neighbor\n"
6462 "Name of route map\n"
6463 "Apply map to incoming routes\n"
6464 "Apply map to outbound routes\n")
596c17ba 6465
718e3744 6466/* Set unsuppress-map to the peer. */
d62a17ae 6467static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
6468 afi_t afi, safi_t safi,
6469 const char *name_str)
718e3744 6470{
d62a17ae 6471 int ret;
6472 struct peer *peer;
1de27621 6473 struct route_map *route_map;
718e3744 6474
d62a17ae 6475 peer = peer_and_group_lookup_vty(vty, ip_str);
6476 if (!peer)
6477 return CMD_WARNING_CONFIG_FAILED;
718e3744 6478
1de27621
DA
6479 route_map = route_map_lookup_warn_noexist(vty, name_str);
6480 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 6481
d62a17ae 6482 return bgp_vty_return(vty, ret);
718e3744 6483}
6484
6485/* Unset route-map from the peer. */
d62a17ae 6486static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
6487 afi_t afi, safi_t safi)
718e3744 6488{
d62a17ae 6489 int ret;
6490 struct peer *peer;
718e3744 6491
d62a17ae 6492 peer = peer_and_group_lookup_vty(vty, ip_str);
6493 if (!peer)
6494 return CMD_WARNING_CONFIG_FAILED;
718e3744 6495
d62a17ae 6496 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 6497
d62a17ae 6498 return bgp_vty_return(vty, ret);
718e3744 6499}
6500
6501DEFUN (neighbor_unsuppress_map,
6502 neighbor_unsuppress_map_cmd,
9ccf14f7 6503 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6504 NEIGHBOR_STR
6505 NEIGHBOR_ADDR_STR2
6506 "Route-map to selectively unsuppress suppressed routes\n"
6507 "Name of route map\n")
6508{
d62a17ae 6509 int idx_peer = 1;
6510 int idx_word = 3;
6511 return peer_unsuppress_map_set_vty(
6512 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6513 argv[idx_word]->arg);
718e3744 6514}
6515
d62a17ae 6516ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
6517 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6518 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6519 "Route-map to selectively unsuppress suppressed routes\n"
6520 "Name of route map\n")
596c17ba 6521
718e3744 6522DEFUN (no_neighbor_unsuppress_map,
6523 no_neighbor_unsuppress_map_cmd,
9ccf14f7 6524 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6525 NO_STR
6526 NEIGHBOR_STR
6527 NEIGHBOR_ADDR_STR2
6528 "Route-map to selectively unsuppress suppressed routes\n"
6529 "Name of route map\n")
6530{
d62a17ae 6531 int idx_peer = 2;
6532 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
6533 bgp_node_afi(vty),
6534 bgp_node_safi(vty));
718e3744 6535}
6b0655a2 6536
d62a17ae 6537ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
6538 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6539 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6540 "Route-map to selectively unsuppress suppressed routes\n"
6541 "Name of route map\n")
596c17ba 6542
d62a17ae 6543static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
6544 afi_t afi, safi_t safi,
6545 const char *num_str,
6546 const char *threshold_str, int warning,
6547 const char *restart_str)
718e3744 6548{
d62a17ae 6549 int ret;
6550 struct peer *peer;
d7c0a89a
QY
6551 uint32_t max;
6552 uint8_t threshold;
6553 uint16_t restart;
718e3744 6554
d62a17ae 6555 peer = peer_and_group_lookup_vty(vty, ip_str);
6556 if (!peer)
6557 return CMD_WARNING_CONFIG_FAILED;
718e3744 6558
d62a17ae 6559 max = strtoul(num_str, NULL, 10);
6560 if (threshold_str)
6561 threshold = atoi(threshold_str);
6562 else
6563 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 6564
d62a17ae 6565 if (restart_str)
6566 restart = atoi(restart_str);
6567 else
6568 restart = 0;
0a486e5f 6569
d62a17ae 6570 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
6571 restart);
718e3744 6572
d62a17ae 6573 return bgp_vty_return(vty, ret);
718e3744 6574}
6575
d62a17ae 6576static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
6577 afi_t afi, safi_t safi)
718e3744 6578{
d62a17ae 6579 int ret;
6580 struct peer *peer;
718e3744 6581
d62a17ae 6582 peer = peer_and_group_lookup_vty(vty, ip_str);
6583 if (!peer)
6584 return CMD_WARNING_CONFIG_FAILED;
718e3744 6585
d62a17ae 6586 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 6587
d62a17ae 6588 return bgp_vty_return(vty, ret);
718e3744 6589}
6590
fde246e8
DA
6591/* Maximum number of prefix to be sent to the neighbor. */
6592DEFUN(neighbor_maximum_prefix_out,
6593 neighbor_maximum_prefix_out_cmd,
6594 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
6595 NEIGHBOR_STR
6596 NEIGHBOR_ADDR_STR2
6597 "Maximum number of prefixes to be sent to this peer\n"
6598 "Maximum no. of prefix limit\n")
6599{
6600 int idx_peer = 1;
6601 int idx_number = 3;
6602 struct peer *peer;
6603 uint32_t max;
6604 afi_t afi = bgp_node_afi(vty);
6605 safi_t safi = bgp_node_safi(vty);
6606
6607 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6608 if (!peer)
6609 return CMD_WARNING_CONFIG_FAILED;
6610
6611 max = strtoul(argv[idx_number]->arg, NULL, 10);
6612
6613 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
6614 peer->pmax_out[afi][safi] = max;
6615
6616 return CMD_SUCCESS;
6617}
6618
6619DEFUN(no_neighbor_maximum_prefix_out,
6620 no_neighbor_maximum_prefix_out_cmd,
6621 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
6622 NO_STR
6623 NEIGHBOR_STR
6624 NEIGHBOR_ADDR_STR2
6625 "Maximum number of prefixes to be sent to this peer\n")
6626{
6627 int idx_peer = 2;
6628 struct peer *peer;
6629 afi_t afi = bgp_node_afi(vty);
6630 safi_t safi = bgp_node_safi(vty);
6631
6632 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6633 if (!peer)
6634 return CMD_WARNING_CONFIG_FAILED;
6635
ae00326a 6636 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
fde246e8
DA
6637 peer->pmax_out[afi][safi] = 0;
6638
6639 return CMD_SUCCESS;
6640}
6641
718e3744 6642/* Maximum number of prefix configuration. prefix count is different
6643 for each peer configuration. So this configuration can be set for
6644 each peer configuration. */
6645DEFUN (neighbor_maximum_prefix,
6646 neighbor_maximum_prefix_cmd,
9ccf14f7 6647 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 6648 NEIGHBOR_STR
6649 NEIGHBOR_ADDR_STR2
6650 "Maximum number of prefix accept from this peer\n"
6651 "maximum no. of prefix limit\n")
6652{
d62a17ae 6653 int idx_peer = 1;
6654 int idx_number = 3;
6655 return peer_maximum_prefix_set_vty(
6656 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6657 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 6658}
6659
d62a17ae 6660ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
6661 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6662 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6663 "Maximum number of prefix accept from this peer\n"
6664 "maximum no. of prefix limit\n")
596c17ba 6665
e0701b79 6666DEFUN (neighbor_maximum_prefix_threshold,
6667 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 6668 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 6669 NEIGHBOR_STR
6670 NEIGHBOR_ADDR_STR2
6671 "Maximum number of prefix accept from this peer\n"
6672 "maximum no. of prefix limit\n"
6673 "Threshold value (%) at which to generate a warning msg\n")
6674{
d62a17ae 6675 int idx_peer = 1;
6676 int idx_number = 3;
6677 int idx_number_2 = 4;
6678 return peer_maximum_prefix_set_vty(
6679 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6680 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 6681}
e0701b79 6682
d62a17ae 6683ALIAS_HIDDEN(
6684 neighbor_maximum_prefix_threshold,
6685 neighbor_maximum_prefix_threshold_hidden_cmd,
6686 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6687 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6688 "Maximum number of prefix accept from this peer\n"
6689 "maximum no. of prefix limit\n"
6690 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 6691
718e3744 6692DEFUN (neighbor_maximum_prefix_warning,
6693 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 6694 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 6695 NEIGHBOR_STR
6696 NEIGHBOR_ADDR_STR2
6697 "Maximum number of prefix accept from this peer\n"
6698 "maximum no. of prefix limit\n"
6699 "Only give warning message when limit is exceeded\n")
6700{
d62a17ae 6701 int idx_peer = 1;
6702 int idx_number = 3;
6703 return peer_maximum_prefix_set_vty(
6704 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6705 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 6706}
6707
d62a17ae 6708ALIAS_HIDDEN(
6709 neighbor_maximum_prefix_warning,
6710 neighbor_maximum_prefix_warning_hidden_cmd,
6711 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6712 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6713 "Maximum number of prefix accept from this peer\n"
6714 "maximum no. of prefix limit\n"
6715 "Only give warning message when limit is exceeded\n")
596c17ba 6716
e0701b79 6717DEFUN (neighbor_maximum_prefix_threshold_warning,
6718 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 6719 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 6720 NEIGHBOR_STR
6721 NEIGHBOR_ADDR_STR2
6722 "Maximum number of prefix accept from this peer\n"
6723 "maximum no. of prefix limit\n"
6724 "Threshold value (%) at which to generate a warning msg\n"
6725 "Only give warning message when limit is exceeded\n")
6726{
d62a17ae 6727 int idx_peer = 1;
6728 int idx_number = 3;
6729 int idx_number_2 = 4;
6730 return peer_maximum_prefix_set_vty(
6731 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6732 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 6733}
6734
d62a17ae 6735ALIAS_HIDDEN(
6736 neighbor_maximum_prefix_threshold_warning,
6737 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6738 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6739 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6740 "Maximum number of prefix accept from this peer\n"
6741 "maximum no. of prefix limit\n"
6742 "Threshold value (%) at which to generate a warning msg\n"
6743 "Only give warning message when limit is exceeded\n")
596c17ba 6744
0a486e5f 6745DEFUN (neighbor_maximum_prefix_restart,
6746 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6747 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6748 NEIGHBOR_STR
6749 NEIGHBOR_ADDR_STR2
6750 "Maximum number of prefix accept from this peer\n"
6751 "maximum no. of prefix limit\n"
6752 "Restart bgp connection after limit is exceeded\n"
efd7904e 6753 "Restart interval in minutes\n")
0a486e5f 6754{
d62a17ae 6755 int idx_peer = 1;
6756 int idx_number = 3;
6757 int idx_number_2 = 5;
6758 return peer_maximum_prefix_set_vty(
6759 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6760 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6761}
6762
d62a17ae 6763ALIAS_HIDDEN(
6764 neighbor_maximum_prefix_restart,
6765 neighbor_maximum_prefix_restart_hidden_cmd,
6766 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6767 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6768 "Maximum number of prefix accept from this peer\n"
6769 "maximum no. of prefix limit\n"
6770 "Restart bgp connection after limit is exceeded\n"
efd7904e 6771 "Restart interval in minutes\n")
596c17ba 6772
0a486e5f 6773DEFUN (neighbor_maximum_prefix_threshold_restart,
6774 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6775 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6776 NEIGHBOR_STR
6777 NEIGHBOR_ADDR_STR2
16cedbb0 6778 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6779 "maximum no. of prefix limit\n"
6780 "Threshold value (%) at which to generate a warning msg\n"
6781 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6782 "Restart interval in minutes\n")
0a486e5f 6783{
d62a17ae 6784 int idx_peer = 1;
6785 int idx_number = 3;
6786 int idx_number_2 = 4;
6787 int idx_number_3 = 6;
6788 return peer_maximum_prefix_set_vty(
6789 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6790 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6791 argv[idx_number_3]->arg);
6792}
6793
6794ALIAS_HIDDEN(
6795 neighbor_maximum_prefix_threshold_restart,
6796 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6797 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6798 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6799 "Maximum number of prefixes to accept from this peer\n"
6800 "maximum no. of prefix limit\n"
6801 "Threshold value (%) at which to generate a warning msg\n"
6802 "Restart bgp connection after limit is exceeded\n"
6803 "Restart interval in minutes\n")
596c17ba 6804
718e3744 6805DEFUN (no_neighbor_maximum_prefix,
6806 no_neighbor_maximum_prefix_cmd,
d04c479d 6807 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6808 NO_STR
6809 NEIGHBOR_STR
6810 NEIGHBOR_ADDR_STR2
16cedbb0 6811 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6812 "maximum no. of prefix limit\n"
6813 "Threshold value (%) at which to generate a warning msg\n"
6814 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6815 "Restart interval in minutes\n"
31500417 6816 "Only give warning message when limit is exceeded\n")
718e3744 6817{
d62a17ae 6818 int idx_peer = 2;
6819 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6820 bgp_node_afi(vty),
6821 bgp_node_safi(vty));
718e3744 6822}
e52702f2 6823
d62a17ae 6824ALIAS_HIDDEN(
6825 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6826 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6828 "Maximum number of prefixes to accept from this peer\n"
6829 "maximum no. of prefix limit\n"
6830 "Threshold value (%) at which to generate a warning msg\n"
6831 "Restart bgp connection after limit is exceeded\n"
6832 "Restart interval in minutes\n"
6833 "Only give warning message when limit is exceeded\n")
596c17ba 6834
718e3744 6835
718e3744 6836/* "neighbor allowas-in" */
6837DEFUN (neighbor_allowas_in,
6838 neighbor_allowas_in_cmd,
fd8503f5 6839 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6840 NEIGHBOR_STR
6841 NEIGHBOR_ADDR_STR2
31500417 6842 "Accept as-path with my AS present in it\n"
f79f7a7b 6843 "Number of occurrences of AS number\n"
fd8503f5 6844 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6845{
d62a17ae 6846 int idx_peer = 1;
6847 int idx_number_origin = 3;
6848 int ret;
6849 int origin = 0;
6850 struct peer *peer;
6851 int allow_num = 0;
6852
6853 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6854 if (!peer)
6855 return CMD_WARNING_CONFIG_FAILED;
6856
6857 if (argc <= idx_number_origin)
6858 allow_num = 3;
6859 else {
6860 if (argv[idx_number_origin]->type == WORD_TKN)
6861 origin = 1;
6862 else
6863 allow_num = atoi(argv[idx_number_origin]->arg);
6864 }
6865
6866 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6867 allow_num, origin);
6868
6869 return bgp_vty_return(vty, ret);
6870}
6871
6872ALIAS_HIDDEN(
6873 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6874 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6875 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6876 "Accept as-path with my AS present in it\n"
f79f7a7b 6877 "Number of occurrences of AS number\n"
d62a17ae 6878 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6879
718e3744 6880DEFUN (no_neighbor_allowas_in,
6881 no_neighbor_allowas_in_cmd,
fd8503f5 6882 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6883 NO_STR
6884 NEIGHBOR_STR
6885 NEIGHBOR_ADDR_STR2
8334fd5a 6886 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6887 "Number of occurrences of AS number\n"
fd8503f5 6888 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6889{
d62a17ae 6890 int idx_peer = 2;
6891 int ret;
6892 struct peer *peer;
718e3744 6893
d62a17ae 6894 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6895 if (!peer)
6896 return CMD_WARNING_CONFIG_FAILED;
718e3744 6897
d62a17ae 6898 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6899 bgp_node_safi(vty));
718e3744 6900
d62a17ae 6901 return bgp_vty_return(vty, ret);
718e3744 6902}
6b0655a2 6903
d62a17ae 6904ALIAS_HIDDEN(
6905 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6906 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6907 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6908 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6909 "Number of occurrences of AS number\n"
d62a17ae 6910 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6911
fa411a21
NH
6912DEFUN (neighbor_ttl_security,
6913 neighbor_ttl_security_cmd,
7ebe625c 6914 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6915 NEIGHBOR_STR
7ebe625c 6916 NEIGHBOR_ADDR_STR2
16cedbb0 6917 "BGP ttl-security parameters\n"
d7fa34c1
QY
6918 "Specify the maximum number of hops to the BGP peer\n"
6919 "Number of hops to BGP peer\n")
fa411a21 6920{
d62a17ae 6921 int idx_peer = 1;
6922 int idx_number = 4;
6923 struct peer *peer;
6924 int gtsm_hops;
6925
6926 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6927 if (!peer)
6928 return CMD_WARNING_CONFIG_FAILED;
6929
6930 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6931
7ebe625c
QY
6932 /*
6933 * If 'neighbor swpX', then this is for directly connected peers,
6934 * we should not accept a ttl-security hops value greater than 1.
6935 */
e2521429 6936 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7ebe625c
QY
6937 vty_out(vty,
6938 "%s is directly connected peer, hops cannot exceed 1\n",
6939 argv[idx_peer]->arg);
6940 return CMD_WARNING_CONFIG_FAILED;
6941 }
6942
d62a17ae 6943 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6944}
6945
6946DEFUN (no_neighbor_ttl_security,
6947 no_neighbor_ttl_security_cmd,
7ebe625c 6948 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6949 NO_STR
6950 NEIGHBOR_STR
7ebe625c 6951 NEIGHBOR_ADDR_STR2
16cedbb0 6952 "BGP ttl-security parameters\n"
3a2d747c
QY
6953 "Specify the maximum number of hops to the BGP peer\n"
6954 "Number of hops to BGP peer\n")
fa411a21 6955{
d62a17ae 6956 int idx_peer = 2;
6957 struct peer *peer;
fa411a21 6958
d62a17ae 6959 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6960 if (!peer)
6961 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6962
d62a17ae 6963 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6964}
6b0655a2 6965
adbac85e
DW
6966DEFUN (neighbor_addpath_tx_all_paths,
6967 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6968 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6969 NEIGHBOR_STR
6970 NEIGHBOR_ADDR_STR2
6971 "Use addpath to advertise all paths to a neighbor\n")
6972{
d62a17ae 6973 int idx_peer = 1;
6974 struct peer *peer;
adbac85e 6975
d62a17ae 6976 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6977 if (!peer)
6978 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6979
dcc68b5e
MS
6980 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6981 BGP_ADDPATH_ALL);
6982 return CMD_SUCCESS;
adbac85e
DW
6983}
6984
d62a17ae 6985ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6986 neighbor_addpath_tx_all_paths_hidden_cmd,
6987 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6988 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6989 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6990
adbac85e
DW
6991DEFUN (no_neighbor_addpath_tx_all_paths,
6992 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6993 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6994 NO_STR
6995 NEIGHBOR_STR
6996 NEIGHBOR_ADDR_STR2
6997 "Use addpath to advertise all paths to a neighbor\n")
6998{
d62a17ae 6999 int idx_peer = 2;
dcc68b5e
MS
7000 struct peer *peer;
7001
7002 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7003 if (!peer)
7004 return CMD_WARNING_CONFIG_FAILED;
7005
7006 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7007 != BGP_ADDPATH_ALL) {
7008 vty_out(vty,
7009 "%% Peer not currently configured to transmit all paths.");
7010 return CMD_WARNING_CONFIG_FAILED;
7011 }
7012
7013 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7014 BGP_ADDPATH_NONE);
7015
7016 return CMD_SUCCESS;
adbac85e
DW
7017}
7018
d62a17ae 7019ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7020 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7021 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7022 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7023 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7024
06370dac
DW
7025DEFUN (neighbor_addpath_tx_bestpath_per_as,
7026 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7027 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7028 NEIGHBOR_STR
7029 NEIGHBOR_ADDR_STR2
7030 "Use addpath to advertise the bestpath per each neighboring AS\n")
7031{
d62a17ae 7032 int idx_peer = 1;
7033 struct peer *peer;
06370dac 7034
d62a17ae 7035 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7036 if (!peer)
7037 return CMD_WARNING_CONFIG_FAILED;
06370dac 7038
dcc68b5e
MS
7039 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7040 BGP_ADDPATH_BEST_PER_AS);
7041
7042 return CMD_SUCCESS;
06370dac
DW
7043}
7044
d62a17ae 7045ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7046 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7047 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7048 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7049 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7050
06370dac
DW
7051DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7052 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7053 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7054 NO_STR
7055 NEIGHBOR_STR
7056 NEIGHBOR_ADDR_STR2
7057 "Use addpath to advertise the bestpath per each neighboring AS\n")
7058{
d62a17ae 7059 int idx_peer = 2;
dcc68b5e
MS
7060 struct peer *peer;
7061
7062 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7063 if (!peer)
7064 return CMD_WARNING_CONFIG_FAILED;
7065
7066 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7067 != BGP_ADDPATH_BEST_PER_AS) {
7068 vty_out(vty,
7069 "%% Peer not currently configured to transmit all best path per as.");
7070 return CMD_WARNING_CONFIG_FAILED;
7071 }
7072
7073 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7074 BGP_ADDPATH_NONE);
7075
7076 return CMD_SUCCESS;
06370dac
DW
7077}
7078
d62a17ae 7079ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7080 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7081 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7082 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7083 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7084
2b31007c
RZ
7085DEFPY(
7086 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7087 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7088 NEIGHBOR_STR
7089 NEIGHBOR_ADDR_STR2
7090 "Detect AS loops before sending to neighbor\n")
7091{
7092 struct peer *peer;
7093
7094 peer = peer_and_group_lookup_vty(vty, neighbor);
7095 if (!peer)
7096 return CMD_WARNING_CONFIG_FAILED;
7097
7098 peer->as_path_loop_detection = true;
7099
7100 return CMD_SUCCESS;
7101}
7102
7103DEFPY(
7104 no_neighbor_aspath_loop_detection,
7105 no_neighbor_aspath_loop_detection_cmd,
7106 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7107 NO_STR
7108 NEIGHBOR_STR
7109 NEIGHBOR_ADDR_STR2
7110 "Detect AS loops before sending to neighbor\n")
7111{
7112 struct peer *peer;
7113
7114 peer = peer_and_group_lookup_vty(vty, neighbor);
7115 if (!peer)
7116 return CMD_WARNING_CONFIG_FAILED;
7117
7118 peer->as_path_loop_detection = false;
7119
7120 return CMD_SUCCESS;
7121}
7122
b9c7bc5a
PZ
7123static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
7124 struct ecommunity **list)
ddb5b488 7125{
b9c7bc5a
PZ
7126 struct ecommunity *ecom = NULL;
7127 struct ecommunity *ecomadd;
ddb5b488 7128
b9c7bc5a 7129 for (; argc; --argc, ++argv) {
ddb5b488 7130
b9c7bc5a
PZ
7131 ecomadd = ecommunity_str2com(argv[0]->arg,
7132 ECOMMUNITY_ROUTE_TARGET, 0);
7133 if (!ecomadd) {
7134 vty_out(vty, "Malformed community-list value\n");
7135 if (ecom)
7136 ecommunity_free(&ecom);
7137 return CMD_WARNING_CONFIG_FAILED;
7138 }
ddb5b488 7139
b9c7bc5a
PZ
7140 if (ecom) {
7141 ecommunity_merge(ecom, ecomadd);
7142 ecommunity_free(&ecomadd);
7143 } else {
7144 ecom = ecomadd;
7145 }
7146 }
7147
7148 if (*list) {
7149 ecommunity_free(&*list);
ddb5b488 7150 }
b9c7bc5a
PZ
7151 *list = ecom;
7152
7153 return CMD_SUCCESS;
ddb5b488
PZ
7154}
7155
0ca70ba5
DS
7156/*
7157 * v2vimport is true if we are handling a `import vrf ...` command
7158 */
7159static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 7160{
0ca70ba5
DS
7161 afi_t afi;
7162
ddb5b488 7163 switch (vty->node) {
b9c7bc5a 7164 case BGP_IPV4_NODE:
0ca70ba5
DS
7165 afi = AFI_IP;
7166 break;
b9c7bc5a 7167 case BGP_IPV6_NODE:
0ca70ba5
DS
7168 afi = AFI_IP6;
7169 break;
ddb5b488
PZ
7170 default:
7171 vty_out(vty,
b9c7bc5a 7172 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 7173 return AFI_MAX;
ddb5b488 7174 }
69b07479 7175
0ca70ba5
DS
7176 if (!v2vimport) {
7177 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7178 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7179 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7180 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7181 vty_out(vty,
7182 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7183 return AFI_MAX;
7184 }
7185 } else {
7186 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7187 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7188 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7189 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7190 vty_out(vty,
7191 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7192 return AFI_MAX;
7193 }
7194 }
7195 return afi;
ddb5b488
PZ
7196}
7197
b9c7bc5a
PZ
7198DEFPY (af_rd_vpn_export,
7199 af_rd_vpn_export_cmd,
7200 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7201 NO_STR
ddb5b488 7202 "Specify route distinguisher\n"
b9c7bc5a
PZ
7203 "Between current address-family and vpn\n"
7204 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7205 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7206{
7207 VTY_DECLVAR_CONTEXT(bgp, bgp);
7208 struct prefix_rd prd;
7209 int ret;
ddb5b488 7210 afi_t afi;
b9c7bc5a
PZ
7211 int idx = 0;
7212 int yes = 1;
ddb5b488 7213
b9c7bc5a 7214 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7215 yes = 0;
b9c7bc5a
PZ
7216
7217 if (yes) {
7218 ret = str2prefix_rd(rd_str, &prd);
7219 if (!ret) {
7220 vty_out(vty, "%% Malformed rd\n");
7221 return CMD_WARNING_CONFIG_FAILED;
7222 }
ddb5b488
PZ
7223 }
7224
0ca70ba5 7225 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7226 if (afi == AFI_MAX)
7227 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7228
69b07479
DS
7229 /*
7230 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7231 */
7232 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7233 bgp_get_default(), bgp);
ddb5b488 7234
69b07479
DS
7235 if (yes) {
7236 bgp->vpn_policy[afi].tovpn_rd = prd;
7237 SET_FLAG(bgp->vpn_policy[afi].flags,
7238 BGP_VPN_POLICY_TOVPN_RD_SET);
7239 } else {
7240 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7241 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
7242 }
7243
69b07479
DS
7244 /* post-change: re-export vpn routes */
7245 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7246 bgp_get_default(), bgp);
7247
ddb5b488
PZ
7248 return CMD_SUCCESS;
7249}
7250
b9c7bc5a
PZ
7251ALIAS (af_rd_vpn_export,
7252 af_no_rd_vpn_export_cmd,
7253 "no rd vpn export",
ddb5b488 7254 NO_STR
b9c7bc5a
PZ
7255 "Specify route distinguisher\n"
7256 "Between current address-family and vpn\n"
7257 "For routes leaked from current address-family to vpn\n")
ddb5b488 7258
b9c7bc5a
PZ
7259DEFPY (af_label_vpn_export,
7260 af_label_vpn_export_cmd,
e70e9f8e 7261 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 7262 NO_STR
ddb5b488 7263 "label value for VRF\n"
b9c7bc5a
PZ
7264 "Between current address-family and vpn\n"
7265 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
7266 "Label Value <0-1048575>\n"
7267 "Automatically assign a label\n")
ddb5b488
PZ
7268{
7269 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7270 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 7271 afi_t afi;
b9c7bc5a
PZ
7272 int idx = 0;
7273 int yes = 1;
7274
7275 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7276 yes = 0;
ddb5b488 7277
21a16cc2
PZ
7278 /* If "no ...", squash trailing parameter */
7279 if (!yes)
7280 label_auto = NULL;
7281
e70e9f8e
PZ
7282 if (yes) {
7283 if (!label_auto)
7284 label = label_val; /* parser should force unsigned */
7285 }
ddb5b488 7286
0ca70ba5 7287 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7288 if (afi == AFI_MAX)
7289 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 7290
e70e9f8e 7291
69b07479
DS
7292 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7293 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
7294 /* no change */
7295 return CMD_SUCCESS;
e70e9f8e 7296
69b07479
DS
7297 /*
7298 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7299 */
7300 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7301 bgp_get_default(), bgp);
7302
7303 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7304 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
7305
7306 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
7307
7308 /*
7309 * label has previously been automatically
7310 * assigned by labelpool: release it
7311 *
7312 * NB if tovpn_label == MPLS_LABEL_NONE it
7313 * means the automatic assignment is in flight
7314 * and therefore the labelpool callback must
7315 * detect that the auto label is not needed.
7316 */
7317
7318 bgp_lp_release(LP_TYPE_VRF,
7319 &bgp->vpn_policy[afi],
7320 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 7321 }
69b07479
DS
7322 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7323 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7324 }
ddb5b488 7325
69b07479
DS
7326 bgp->vpn_policy[afi].tovpn_label = label;
7327 if (label_auto) {
7328 SET_FLAG(bgp->vpn_policy[afi].flags,
7329 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7330 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
7331 vpn_leak_label_callback);
ddb5b488
PZ
7332 }
7333
69b07479
DS
7334 /* post-change: re-export vpn routes */
7335 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7336 bgp_get_default(), bgp);
7337
ddb5b488
PZ
7338 return CMD_SUCCESS;
7339}
7340
b9c7bc5a
PZ
7341ALIAS (af_label_vpn_export,
7342 af_no_label_vpn_export_cmd,
7343 "no label vpn export",
7344 NO_STR
7345 "label value for VRF\n"
7346 "Between current address-family and vpn\n"
7347 "For routes leaked from current address-family to vpn\n")
ddb5b488 7348
b9c7bc5a
PZ
7349DEFPY (af_nexthop_vpn_export,
7350 af_nexthop_vpn_export_cmd,
8c85ca28 7351 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 7352 NO_STR
ddb5b488 7353 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
7354 "Between current address-family and vpn\n"
7355 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7356 "IPv4 prefix\n"
7357 "IPv6 prefix\n")
7358{
7359 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 7360 afi_t afi;
ddb5b488
PZ
7361 struct prefix p;
7362
8c85ca28
QY
7363 if (!no) {
7364 if (!nexthop_su) {
7365 vty_out(vty, "%% Nexthop required\n");
7366 return CMD_WARNING_CONFIG_FAILED;
7367 }
b9c7bc5a 7368
8c85ca28 7369 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
7370 return CMD_WARNING_CONFIG_FAILED;
7371 }
ddb5b488 7372
0ca70ba5 7373 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7374 if (afi == AFI_MAX)
7375 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7376
69b07479
DS
7377 /*
7378 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7379 */
7380 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7381 bgp_get_default(), bgp);
ddb5b488 7382
8c85ca28 7383 if (!no) {
69b07479
DS
7384 bgp->vpn_policy[afi].tovpn_nexthop = p;
7385 SET_FLAG(bgp->vpn_policy[afi].flags,
7386 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7387 } else {
7388 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7389 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
7390 }
7391
69b07479
DS
7392 /* post-change: re-export vpn routes */
7393 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7394 bgp_get_default(), bgp);
7395
ddb5b488
PZ
7396 return CMD_SUCCESS;
7397}
7398
b9c7bc5a 7399static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 7400{
b9c7bc5a
PZ
7401 if (!strcmp(dstr, "import")) {
7402 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7403 } else if (!strcmp(dstr, "export")) {
7404 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7405 } else if (!strcmp(dstr, "both")) {
7406 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7407 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7408 } else {
7409 vty_out(vty, "%% direction parse error\n");
7410 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7411 }
ddb5b488
PZ
7412 return CMD_SUCCESS;
7413}
7414
b9c7bc5a
PZ
7415DEFPY (af_rt_vpn_imexport,
7416 af_rt_vpn_imexport_cmd,
7417 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
7418 NO_STR
7419 "Specify route target list\n"
ddb5b488 7420 "Specify route target list\n"
b9c7bc5a
PZ
7421 "Between current address-family and vpn\n"
7422 "For routes leaked from vpn to current address-family: match any\n"
7423 "For routes leaked from current address-family to vpn: set\n"
7424 "both import: match any and export: set\n"
ddb5b488
PZ
7425 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7426{
7427 VTY_DECLVAR_CONTEXT(bgp, bgp);
7428 int ret;
7429 struct ecommunity *ecom = NULL;
7430 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7431 vpn_policy_direction_t dir;
7432 afi_t afi;
7433 int idx = 0;
b9c7bc5a 7434 int yes = 1;
ddb5b488 7435
b9c7bc5a 7436 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7437 yes = 0;
b9c7bc5a 7438
0ca70ba5 7439 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7440 if (afi == AFI_MAX)
7441 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7442
b9c7bc5a 7443 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7444 if (ret != CMD_SUCCESS)
7445 return ret;
7446
b9c7bc5a
PZ
7447 if (yes) {
7448 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7449 vty_out(vty, "%% Missing RTLIST\n");
7450 return CMD_WARNING_CONFIG_FAILED;
7451 }
7452 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7453 if (ret != CMD_SUCCESS) {
7454 return ret;
7455 }
ddb5b488
PZ
7456 }
7457
69b07479
DS
7458 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7459 if (!dodir[dir])
ddb5b488 7460 continue;
ddb5b488 7461
69b07479 7462 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7463
69b07479
DS
7464 if (yes) {
7465 if (bgp->vpn_policy[afi].rtlist[dir])
7466 ecommunity_free(
7467 &bgp->vpn_policy[afi].rtlist[dir]);
7468 bgp->vpn_policy[afi].rtlist[dir] =
7469 ecommunity_dup(ecom);
7470 } else {
7471 if (bgp->vpn_policy[afi].rtlist[dir])
7472 ecommunity_free(
7473 &bgp->vpn_policy[afi].rtlist[dir]);
7474 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 7475 }
69b07479
DS
7476
7477 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7478 }
69b07479 7479
d555f3e9
PZ
7480 if (ecom)
7481 ecommunity_free(&ecom);
ddb5b488
PZ
7482
7483 return CMD_SUCCESS;
7484}
7485
b9c7bc5a
PZ
7486ALIAS (af_rt_vpn_imexport,
7487 af_no_rt_vpn_imexport_cmd,
7488 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
7489 NO_STR
7490 "Specify route target list\n"
b9c7bc5a
PZ
7491 "Specify route target list\n"
7492 "Between current address-family and vpn\n"
7493 "For routes leaked from vpn to current address-family\n"
7494 "For routes leaked from current address-family to vpn\n"
7495 "both import and export\n")
7496
7497DEFPY (af_route_map_vpn_imexport,
7498 af_route_map_vpn_imexport_cmd,
7499/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
7500 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
7501 NO_STR
ddb5b488 7502 "Specify route map\n"
b9c7bc5a
PZ
7503 "Between current address-family and vpn\n"
7504 "For routes leaked from vpn to current address-family\n"
7505 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7506 "name of route-map\n")
7507{
7508 VTY_DECLVAR_CONTEXT(bgp, bgp);
7509 int ret;
7510 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7511 vpn_policy_direction_t dir;
7512 afi_t afi;
ddb5b488 7513 int idx = 0;
b9c7bc5a 7514 int yes = 1;
ddb5b488 7515
b9c7bc5a 7516 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7517 yes = 0;
b9c7bc5a 7518
0ca70ba5 7519 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7520 if (afi == AFI_MAX)
7521 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7522
b9c7bc5a 7523 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7524 if (ret != CMD_SUCCESS)
7525 return ret;
7526
69b07479
DS
7527 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7528 if (!dodir[dir])
ddb5b488 7529 continue;
ddb5b488 7530
69b07479 7531 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7532
69b07479
DS
7533 if (yes) {
7534 if (bgp->vpn_policy[afi].rmap_name[dir])
7535 XFREE(MTYPE_ROUTE_MAP_NAME,
7536 bgp->vpn_policy[afi].rmap_name[dir]);
7537 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
7538 MTYPE_ROUTE_MAP_NAME, rmap_str);
7539 bgp->vpn_policy[afi].rmap[dir] =
1de27621 7540 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
7541 if (!bgp->vpn_policy[afi].rmap[dir])
7542 return CMD_SUCCESS;
7543 } else {
7544 if (bgp->vpn_policy[afi].rmap_name[dir])
7545 XFREE(MTYPE_ROUTE_MAP_NAME,
7546 bgp->vpn_policy[afi].rmap_name[dir]);
7547 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7548 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 7549 }
69b07479
DS
7550
7551 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
7552 }
7553
7554 return CMD_SUCCESS;
7555}
7556
b9c7bc5a
PZ
7557ALIAS (af_route_map_vpn_imexport,
7558 af_no_route_map_vpn_imexport_cmd,
7559 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
7560 NO_STR
7561 "Specify route map\n"
b9c7bc5a
PZ
7562 "Between current address-family and vpn\n"
7563 "For routes leaked from vpn to current address-family\n"
7564 "For routes leaked from current address-family to vpn\n")
7565
bb4f6190 7566DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 7567 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
7568 "Import routes from another VRF\n"
7569 "Vrf routes being filtered\n"
7570 "Specify route map\n"
7571 "name of route-map\n")
7572{
7573 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
7574 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7575 afi_t afi;
bb4f6190
DS
7576 struct bgp *bgp_default;
7577
0ca70ba5 7578 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
7579 if (afi == AFI_MAX)
7580 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
7581
7582 bgp_default = bgp_get_default();
7583 if (!bgp_default) {
7584 int32_t ret;
7585 as_t as = bgp->as;
7586
7587 /* Auto-create assuming the same AS */
5d5393b9
DL
7588 ret = bgp_get_vty(&bgp_default, &as, NULL,
7589 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
7590
7591 if (ret) {
7592 vty_out(vty,
7593 "VRF default is not configured as a bgp instance\n");
7594 return CMD_WARNING;
7595 }
7596 }
7597
69b07479 7598 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 7599
ae6a6fb4
DS
7600 if (bgp->vpn_policy[afi].rmap_name[dir])
7601 XFREE(MTYPE_ROUTE_MAP_NAME,
7602 bgp->vpn_policy[afi].rmap_name[dir]);
7603 bgp->vpn_policy[afi].rmap_name[dir] =
7604 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
7605 bgp->vpn_policy[afi].rmap[dir] =
7606 route_map_lookup_warn_noexist(vty, rmap_str);
7607 if (!bgp->vpn_policy[afi].rmap[dir])
7608 return CMD_SUCCESS;
7609
7610 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7611 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 7612
69b07479
DS
7613 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7614
bb4f6190
DS
7615 return CMD_SUCCESS;
7616}
7617
ae6a6fb4
DS
7618DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
7619 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
7620 NO_STR
7621 "Import routes from another VRF\n"
7622 "Vrf routes being filtered\n"
ae6a6fb4
DS
7623 "Specify route map\n"
7624 "name of route-map\n")
7625{
7626 VTY_DECLVAR_CONTEXT(bgp, bgp);
7627 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7628 afi_t afi;
7629
7630 afi = vpn_policy_getafi(vty, bgp, true);
7631 if (afi == AFI_MAX)
7632 return CMD_WARNING_CONFIG_FAILED;
7633
7634 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7635
7636 if (bgp->vpn_policy[afi].rmap_name[dir])
7637 XFREE(MTYPE_ROUTE_MAP_NAME,
7638 bgp->vpn_policy[afi].rmap_name[dir]);
7639 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7640 bgp->vpn_policy[afi].rmap[dir] = NULL;
7641
7642 if (bgp->vpn_policy[afi].import_vrf->count == 0)
7643 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7644 BGP_CONFIG_VRF_TO_VRF_IMPORT);
7645
7646 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7647
7648 return CMD_SUCCESS;
7649}
bb4f6190 7650
4d1b335c
DA
7651DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7652 "[no] import vrf VIEWVRFNAME$import_name",
7653 NO_STR
7654 "Import routes from another VRF\n"
7655 "VRF to import from\n"
7656 "The name of the VRF\n")
12a844a5
DS
7657{
7658 VTY_DECLVAR_CONTEXT(bgp, bgp);
7659 struct listnode *node;
79ef8664
DS
7660 struct bgp *vrf_bgp, *bgp_default;
7661 int32_t ret = 0;
7662 as_t as = bgp->as;
12a844a5
DS
7663 bool remove = false;
7664 int32_t idx = 0;
7665 char *vname;
a8dadcf6 7666 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
7667 safi_t safi;
7668 afi_t afi;
7669
867f0cca 7670 if (import_name == NULL) {
7671 vty_out(vty, "%% Missing import name\n");
7672 return CMD_WARNING;
7673 }
7674
ae6a6fb4
DS
7675 if (strcmp(import_name, "route-map") == 0) {
7676 vty_out(vty, "%% Must include route-map name\n");
7677 return CMD_WARNING;
7678 }
7679
12a844a5
DS
7680 if (argv_find(argv, argc, "no", &idx))
7681 remove = true;
7682
0ca70ba5
DS
7683 afi = vpn_policy_getafi(vty, bgp, true);
7684 if (afi == AFI_MAX)
7685 return CMD_WARNING_CONFIG_FAILED;
7686
12a844a5
DS
7687 safi = bgp_node_safi(vty);
7688
25679caa 7689 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 7690 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
7691 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7692 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7693 remove ? "unimport" : "import", import_name);
7694 return CMD_WARNING;
7695 }
7696
79ef8664
DS
7697 bgp_default = bgp_get_default();
7698 if (!bgp_default) {
7699 /* Auto-create assuming the same AS */
5d5393b9
DL
7700 ret = bgp_get_vty(&bgp_default, &as, NULL,
7701 BGP_INSTANCE_TYPE_DEFAULT);
79ef8664
DS
7702
7703 if (ret) {
7704 vty_out(vty,
7705 "VRF default is not configured as a bgp instance\n");
7706 return CMD_WARNING;
7707 }
7708 }
7709
12a844a5
DS
7710 vrf_bgp = bgp_lookup_by_name(import_name);
7711 if (!vrf_bgp) {
5742e42b 7712 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
7713 vrf_bgp = bgp_default;
7714 else
0fb8d6e6 7715 /* Auto-create assuming the same AS */
5d5393b9 7716 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 7717
6e2c7fe6 7718 if (ret) {
020a3f60
DS
7719 vty_out(vty,
7720 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
7721 import_name);
7722 return CMD_WARNING;
7723 }
12a844a5
DS
7724 }
7725
12a844a5 7726 if (remove) {
44338987 7727 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 7728 } else {
44338987 7729 /* Already importing from "import_vrf"? */
12a844a5
DS
7730 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7731 vname)) {
7732 if (strcmp(vname, import_name) == 0)
7733 return CMD_WARNING;
7734 }
7735
44338987 7736 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
7737 }
7738
7739 return CMD_SUCCESS;
7740}
7741
b9c7bc5a
PZ
7742/* This command is valid only in a bgp vrf instance or the default instance */
7743DEFPY (bgp_imexport_vpn,
7744 bgp_imexport_vpn_cmd,
7745 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
7746 NO_STR
7747 "Import routes to this address-family\n"
7748 "Export routes from this address-family\n"
7749 "to/from default instance VPN RIB\n")
ddb5b488
PZ
7750{
7751 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7752 int previous_state;
ddb5b488 7753 afi_t afi;
b9c7bc5a 7754 safi_t safi;
ddb5b488 7755 int idx = 0;
b9c7bc5a
PZ
7756 int yes = 1;
7757 int flag;
7758 vpn_policy_direction_t dir;
ddb5b488 7759
b9c7bc5a 7760 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7761 yes = 0;
ddb5b488 7762
b9c7bc5a
PZ
7763 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7764 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7765
b9c7bc5a
PZ
7766 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7767 return CMD_WARNING_CONFIG_FAILED;
7768 }
ddb5b488 7769
b9c7bc5a
PZ
7770 afi = bgp_node_afi(vty);
7771 safi = bgp_node_safi(vty);
7772 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7773 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7774 return CMD_WARNING_CONFIG_FAILED;
7775 }
ddb5b488 7776
b9c7bc5a
PZ
7777 if (!strcmp(direction_str, "import")) {
7778 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7779 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7780 } else if (!strcmp(direction_str, "export")) {
7781 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7782 dir = BGP_VPN_POLICY_DIR_TOVPN;
7783 } else {
7784 vty_out(vty, "%% unknown direction %s\n", direction_str);
7785 return CMD_WARNING_CONFIG_FAILED;
7786 }
7787
7788 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7789
b9c7bc5a
PZ
7790 if (yes) {
7791 SET_FLAG(bgp->af_flags[afi][safi], flag);
7792 if (!previous_state) {
7793 /* trigger export current vrf */
ddb5b488
PZ
7794 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7795 }
b9c7bc5a
PZ
7796 } else {
7797 if (previous_state) {
7798 /* trigger un-export current vrf */
7799 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7800 }
7801 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7802 }
7803
7804 return CMD_SUCCESS;
7805}
7806
301ad80a
PG
7807DEFPY (af_routetarget_import,
7808 af_routetarget_import_cmd,
7809 "[no] <rt|route-target> redirect import RTLIST...",
7810 NO_STR
7811 "Specify route target list\n"
7812 "Specify route target list\n"
7813 "Flow-spec redirect type route target\n"
7814 "Import routes to this address-family\n"
7815 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7816{
7817 VTY_DECLVAR_CONTEXT(bgp, bgp);
7818 int ret;
7819 struct ecommunity *ecom = NULL;
301ad80a
PG
7820 afi_t afi;
7821 int idx = 0;
7822 int yes = 1;
7823
7824 if (argv_find(argv, argc, "no", &idx))
7825 yes = 0;
7826
0ca70ba5 7827 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7828 if (afi == AFI_MAX)
7829 return CMD_WARNING_CONFIG_FAILED;
7830
301ad80a
PG
7831 if (yes) {
7832 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7833 vty_out(vty, "%% Missing RTLIST\n");
7834 return CMD_WARNING_CONFIG_FAILED;
7835 }
7836 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7837 if (ret != CMD_SUCCESS)
7838 return ret;
7839 }
69b07479
DS
7840
7841 if (yes) {
7842 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7843 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7844 .import_redirect_rtlist);
69b07479
DS
7845 bgp->vpn_policy[afi].import_redirect_rtlist =
7846 ecommunity_dup(ecom);
7847 } else {
7848 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7849 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7850 .import_redirect_rtlist);
69b07479 7851 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7852 }
69b07479 7853
301ad80a
PG
7854 if (ecom)
7855 ecommunity_free(&ecom);
7856
7857 return CMD_SUCCESS;
7858}
7859
505e5056 7860DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7861 address_family_ipv4_safi_cmd,
7862 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7863 "Enter Address Family command mode\n"
7864 "Address Family\n"
7865 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7866{
f51bae9c 7867
d62a17ae 7868 if (argc == 3) {
2131d5cf 7869 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7870 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7871 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7872 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7873 && safi != SAFI_EVPN) {
31947174
MK
7874 vty_out(vty,
7875 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7876 return CMD_WARNING_CONFIG_FAILED;
7877 }
d62a17ae 7878 vty->node = bgp_node_type(AFI_IP, safi);
7879 } else
7880 vty->node = BGP_IPV4_NODE;
718e3744 7881
d62a17ae 7882 return CMD_SUCCESS;
718e3744 7883}
7884
505e5056 7885DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7886 address_family_ipv6_safi_cmd,
7887 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7888 "Enter Address Family command mode\n"
7889 "Address Family\n"
7890 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7891{
d62a17ae 7892 if (argc == 3) {
2131d5cf 7893 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7894 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7895 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7896 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7897 && safi != SAFI_EVPN) {
31947174
MK
7898 vty_out(vty,
7899 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7900 return CMD_WARNING_CONFIG_FAILED;
7901 }
d62a17ae 7902 vty->node = bgp_node_type(AFI_IP6, safi);
7903 } else
7904 vty->node = BGP_IPV6_NODE;
25ffbdc1 7905
d62a17ae 7906 return CMD_SUCCESS;
25ffbdc1 7907}
718e3744 7908
d6902373 7909#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7910DEFUN_NOSH (address_family_vpnv4,
718e3744 7911 address_family_vpnv4_cmd,
8334fd5a 7912 "address-family vpnv4 [unicast]",
718e3744 7913 "Enter Address Family command mode\n"
8c3deaae 7914 "Address Family\n"
3a2d747c 7915 "Address Family modifier\n")
718e3744 7916{
d62a17ae 7917 vty->node = BGP_VPNV4_NODE;
7918 return CMD_SUCCESS;
718e3744 7919}
7920
505e5056 7921DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7922 address_family_vpnv6_cmd,
8334fd5a 7923 "address-family vpnv6 [unicast]",
8ecd3266 7924 "Enter Address Family command mode\n"
8c3deaae 7925 "Address Family\n"
3a2d747c 7926 "Address Family modifier\n")
8ecd3266 7927{
d62a17ae 7928 vty->node = BGP_VPNV6_NODE;
7929 return CMD_SUCCESS;
8ecd3266 7930}
64e4a6c5 7931#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 7932
505e5056 7933DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7934 address_family_evpn_cmd,
7111c1a0 7935 "address-family l2vpn evpn",
4e0b7b6d 7936 "Enter Address Family command mode\n"
7111c1a0
QY
7937 "Address Family\n"
7938 "Address Family modifier\n")
4e0b7b6d 7939{
2131d5cf 7940 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7941 vty->node = BGP_EVPN_NODE;
7942 return CMD_SUCCESS;
4e0b7b6d
PG
7943}
7944
505e5056 7945DEFUN_NOSH (exit_address_family,
718e3744 7946 exit_address_family_cmd,
7947 "exit-address-family",
7948 "Exit from Address Family configuration mode\n")
7949{
d62a17ae 7950 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7951 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7952 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7953 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7954 || vty->node == BGP_EVPN_NODE
7955 || vty->node == BGP_FLOWSPECV4_NODE
7956 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7957 vty->node = BGP_NODE;
7958 return CMD_SUCCESS;
718e3744 7959}
6b0655a2 7960
8ad7271d 7961/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7962static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7963 const char *ip_str, afi_t afi, safi_t safi,
7964 struct prefix_rd *prd)
7965{
7966 int ret;
7967 struct prefix match;
7968 struct bgp_node *rn;
7969 struct bgp_node *rm;
7970 struct bgp *bgp;
7971 struct bgp_table *table;
7972 struct bgp_table *rib;
7973
7974 /* BGP structure lookup. */
7975 if (view_name) {
7976 bgp = bgp_lookup_by_name(view_name);
7977 if (bgp == NULL) {
7978 vty_out(vty, "%% Can't find BGP instance %s\n",
7979 view_name);
7980 return CMD_WARNING;
7981 }
7982 } else {
7983 bgp = bgp_get_default();
7984 if (bgp == NULL) {
7985 vty_out(vty, "%% No BGP process is configured\n");
7986 return CMD_WARNING;
7987 }
7988 }
7989
7990 /* Check IP address argument. */
7991 ret = str2prefix(ip_str, &match);
7992 if (!ret) {
7993 vty_out(vty, "%% address is malformed\n");
7994 return CMD_WARNING;
7995 }
7996
7997 match.family = afi2family(afi);
7998 rib = bgp->rib[afi][safi];
7999
8000 if (safi == SAFI_MPLS_VPN) {
8001 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
b54892e0
DS
8002 const struct prefix *rn_p = bgp_node_get_prefix(rn);
8003
8004 if (prd && memcmp(rn_p->u.val, prd->val, 8) != 0)
d62a17ae 8005 continue;
8006
67009e22 8007 table = bgp_node_get_bgp_table_info(rn);
b54892e0
DS
8008 if (table == NULL)
8009 continue;
8010
8011 if ((rm = bgp_node_match(table, &match)) != NULL) {
8012 const struct prefix *rm_p =
8013 bgp_node_get_prefix(rm);
8014
8015 if (rm_p->prefixlen == match.prefixlen) {
8016 SET_FLAG(rm->flags,
8017 BGP_NODE_USER_CLEAR);
8018 bgp_process(bgp, rm, afi, safi);
d62a17ae 8019 }
b54892e0 8020 bgp_unlock_node(rm);
d62a17ae 8021 }
8022 }
8023 } else {
8024 if ((rn = bgp_node_match(rib, &match)) != NULL) {
b54892e0
DS
8025 const struct prefix *rn_p = bgp_node_get_prefix(rn);
8026
8027 if (rn_p->prefixlen == match.prefixlen) {
d62a17ae 8028 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
8029 bgp_process(bgp, rn, afi, safi);
8030 }
8031 bgp_unlock_node(rn);
8032 }
8033 }
8034
8035 return CMD_SUCCESS;
8ad7271d
DS
8036}
8037
b09b5ae0 8038/* one clear bgp command to rule them all */
718e3744 8039DEFUN (clear_ip_bgp_all,
8040 clear_ip_bgp_all_cmd,
453c92f6 8041 "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 8042 CLEAR_STR
8043 IP_STR
8044 BGP_STR
838758ac 8045 BGP_INSTANCE_HELP_STR
510afcd6 8046 BGP_AFI_HELP_STR
fd5e7b70 8047 "Address Family\n"
510afcd6 8048 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 8049 "Address Family modifier\n"
b09b5ae0 8050 "Clear all peers\n"
453c92f6 8051 "BGP IPv4 neighbor to clear\n"
a80beece 8052 "BGP IPv6 neighbor to clear\n"
838758ac 8053 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
8054 "Clear peers with the AS number\n"
8055 "Clear all external peers\n"
718e3744 8056 "Clear all members of peer-group\n"
b09b5ae0 8057 "BGP peer-group name\n"
b09b5ae0
DW
8058 BGP_SOFT_STR
8059 BGP_SOFT_IN_STR
b09b5ae0
DW
8060 BGP_SOFT_OUT_STR
8061 BGP_SOFT_IN_STR
8062 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 8063 BGP_SOFT_OUT_STR)
718e3744 8064{
d62a17ae 8065 char *vrf = NULL;
8066
dc912615
DS
8067 afi_t afi = AFI_UNSPEC;
8068 safi_t safi = SAFI_UNSPEC;
d62a17ae 8069 enum clear_sort clr_sort = clear_peer;
8070 enum bgp_clear_type clr_type;
8071 char *clr_arg = NULL;
8072
8073 int idx = 0;
8074
8075 /* clear [ip] bgp */
8076 if (argv_find(argv, argc, "ip", &idx))
8077 afi = AFI_IP;
8078
9a8bdf1c
PG
8079 /* [<vrf> VIEWVRFNAME] */
8080 if (argv_find(argv, argc, "vrf", &idx)) {
8081 vrf = argv[idx + 1]->arg;
8082 idx += 2;
8083 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8084 vrf = NULL;
8085 } else if (argv_find(argv, argc, "view", &idx)) {
8086 /* [<view> VIEWVRFNAME] */
d62a17ae 8087 vrf = argv[idx + 1]->arg;
8088 idx += 2;
8089 }
d62a17ae 8090 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8091 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8092 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8093
d7b9898c 8094 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 8095 if (argv_find(argv, argc, "*", &idx)) {
8096 clr_sort = clear_all;
8097 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8098 clr_sort = clear_peer;
8099 clr_arg = argv[idx]->arg;
8100 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8101 clr_sort = clear_peer;
8102 clr_arg = argv[idx]->arg;
8103 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8104 clr_sort = clear_group;
8105 idx++;
8106 clr_arg = argv[idx]->arg;
d7b9898c 8107 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 8108 clr_sort = clear_peer;
8109 clr_arg = argv[idx]->arg;
8fa7d444
DS
8110 } else if (argv_find(argv, argc, "WORD", &idx)) {
8111 clr_sort = clear_peer;
8112 clr_arg = argv[idx]->arg;
d62a17ae 8113 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8114 clr_sort = clear_as;
8115 clr_arg = argv[idx]->arg;
8116 } else if (argv_find(argv, argc, "external", &idx)) {
8117 clr_sort = clear_external;
8118 }
8119
8120 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8121 if (argv_find(argv, argc, "soft", &idx)) {
8122 if (argv_find(argv, argc, "in", &idx)
8123 || argv_find(argv, argc, "out", &idx))
8124 clr_type = strmatch(argv[idx]->text, "in")
8125 ? BGP_CLEAR_SOFT_IN
8126 : BGP_CLEAR_SOFT_OUT;
8127 else
8128 clr_type = BGP_CLEAR_SOFT_BOTH;
8129 } else if (argv_find(argv, argc, "in", &idx)) {
8130 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8131 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8132 : BGP_CLEAR_SOFT_IN;
8133 } else if (argv_find(argv, argc, "out", &idx)) {
8134 clr_type = BGP_CLEAR_SOFT_OUT;
8135 } else
8136 clr_type = BGP_CLEAR_SOFT_NONE;
8137
8138 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 8139}
01080f7c 8140
8ad7271d
DS
8141DEFUN (clear_ip_bgp_prefix,
8142 clear_ip_bgp_prefix_cmd,
18c57037 8143 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
8144 CLEAR_STR
8145 IP_STR
8146 BGP_STR
838758ac 8147 BGP_INSTANCE_HELP_STR
8ad7271d 8148 "Clear bestpath and re-advertise\n"
0c7b1b01 8149 "IPv4 prefix\n")
8ad7271d 8150{
d62a17ae 8151 char *vrf = NULL;
8152 char *prefix = NULL;
8ad7271d 8153
d62a17ae 8154 int idx = 0;
01080f7c 8155
d62a17ae 8156 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
8157 if (argv_find(argv, argc, "vrf", &idx)) {
8158 vrf = argv[idx + 1]->arg;
8159 idx += 2;
8160 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8161 vrf = NULL;
8162 } else if (argv_find(argv, argc, "view", &idx)) {
8163 /* [<view> VIEWVRFNAME] */
8164 vrf = argv[idx + 1]->arg;
8165 idx += 2;
8166 }
0c7b1b01 8167
d62a17ae 8168 prefix = argv[argc - 1]->arg;
8ad7271d 8169
d62a17ae 8170 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 8171}
8ad7271d 8172
b09b5ae0
DW
8173DEFUN (clear_bgp_ipv6_safi_prefix,
8174 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 8175 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8176 CLEAR_STR
3a2d747c 8177 IP_STR
718e3744 8178 BGP_STR
8c3deaae 8179 "Address Family\n"
46f296b4 8180 BGP_SAFI_HELP_STR
b09b5ae0 8181 "Clear bestpath and re-advertise\n"
0c7b1b01 8182 "IPv6 prefix\n")
718e3744 8183{
9b475e76
PG
8184 int idx_safi = 0;
8185 int idx_ipv6_prefix = 0;
8186 safi_t safi = SAFI_UNICAST;
8187 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8188 argv[idx_ipv6_prefix]->arg : NULL;
8189
8190 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 8191 return bgp_clear_prefix(
9b475e76
PG
8192 vty, NULL, prefix, AFI_IP6,
8193 safi, NULL);
838758ac 8194}
01080f7c 8195
b09b5ae0
DW
8196DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8197 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 8198 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8199 CLEAR_STR
3a2d747c 8200 IP_STR
718e3744 8201 BGP_STR
838758ac 8202 BGP_INSTANCE_HELP_STR
8c3deaae 8203 "Address Family\n"
46f296b4 8204 BGP_SAFI_HELP_STR
b09b5ae0 8205 "Clear bestpath and re-advertise\n"
0c7b1b01 8206 "IPv6 prefix\n")
718e3744 8207{
9b475e76 8208 int idx_safi = 0;
9a8bdf1c 8209 int idx_vrfview = 0;
9b475e76
PG
8210 int idx_ipv6_prefix = 0;
8211 safi_t safi = SAFI_UNICAST;
8212 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8213 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 8214 char *vrfview = NULL;
9b475e76 8215
9a8bdf1c
PG
8216 /* [<view|vrf> VIEWVRFNAME] */
8217 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8218 vrfview = argv[idx_vrfview + 1]->arg;
8219 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8220 vrfview = NULL;
8221 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8222 /* [<view> VIEWVRFNAME] */
8223 vrfview = argv[idx_vrfview + 1]->arg;
8224 }
9b475e76
PG
8225 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8226
d62a17ae 8227 return bgp_clear_prefix(
9b475e76
PG
8228 vty, vrfview, prefix,
8229 AFI_IP6, safi, NULL);
718e3744 8230}
8231
b09b5ae0
DW
8232DEFUN (show_bgp_views,
8233 show_bgp_views_cmd,
d6e3c605 8234 "show [ip] bgp views",
b09b5ae0 8235 SHOW_STR
d6e3c605 8236 IP_STR
01080f7c 8237 BGP_STR
b09b5ae0 8238 "Show the defined BGP views\n")
01080f7c 8239{
d62a17ae 8240 struct list *inst = bm->bgp;
8241 struct listnode *node;
8242 struct bgp *bgp;
01080f7c 8243
d62a17ae 8244 vty_out(vty, "Defined BGP views:\n");
8245 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8246 /* Skip VRFs. */
8247 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
8248 continue;
8249 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
8250 bgp->as);
8251 }
e52702f2 8252
d62a17ae 8253 return CMD_SUCCESS;
e0081f70
ML
8254}
8255
8386ac43 8256DEFUN (show_bgp_vrfs,
8257 show_bgp_vrfs_cmd,
d6e3c605 8258 "show [ip] bgp vrfs [json]",
8386ac43 8259 SHOW_STR
d6e3c605 8260 IP_STR
8386ac43 8261 BGP_STR
8262 "Show BGP VRFs\n"
9973d184 8263 JSON_STR)
8386ac43 8264{
fe1dc5a3 8265 char buf[ETHER_ADDR_STRLEN];
d62a17ae 8266 struct list *inst = bm->bgp;
8267 struct listnode *node;
8268 struct bgp *bgp;
9f049418 8269 bool uj = use_json(argc, argv);
d62a17ae 8270 json_object *json = NULL;
8271 json_object *json_vrfs = NULL;
8272 int count = 0;
d62a17ae 8273
d62a17ae 8274 if (uj) {
8275 json = json_object_new_object();
8276 json_vrfs = json_object_new_object();
8277 }
8278
8279 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8280 const char *name, *type;
8281 struct peer *peer;
7fe96307 8282 struct listnode *node2, *nnode2;
d62a17ae 8283 int peers_cfg, peers_estb;
8284 json_object *json_vrf = NULL;
d62a17ae 8285
8286 /* Skip Views. */
8287 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
8288 continue;
8289
8290 count++;
efb4077a 8291 if (!uj && count == 1) {
fe1dc5a3 8292 vty_out(vty,
efb4077a 8293 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 8294 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
8295 "#PeersEstb", "Name");
8296 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
8297 "L3-VNI", "RouterMAC", "Interface");
8298 }
d62a17ae 8299
8300 peers_cfg = peers_estb = 0;
8301 if (uj)
8302 json_vrf = json_object_new_object();
8303
8304
7fe96307 8305 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 8306 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8307 continue;
8308 peers_cfg++;
8309 if (peer->status == Established)
8310 peers_estb++;
8311 }
8312
8313 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 8314 name = VRF_DEFAULT_NAME;
d62a17ae 8315 type = "DFLT";
8316 } else {
8317 name = bgp->name;
8318 type = "VRF";
8319 }
8320
a8bf7d9c 8321
d62a17ae 8322 if (uj) {
a4d82a8a
PZ
8323 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8324 ? -1
8325 : (int64_t)bgp->vrf_id;
d62a17ae 8326 json_object_string_add(json_vrf, "type", type);
8327 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8328 json_object_string_add(json_vrf, "routerId",
8329 inet_ntoa(bgp->router_id));
8330 json_object_int_add(json_vrf, "numConfiguredPeers",
8331 peers_cfg);
8332 json_object_int_add(json_vrf, "numEstablishedPeers",
8333 peers_estb);
8334
fe1dc5a3 8335 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
8336 json_object_string_add(
8337 json_vrf, "rmac",
8338 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
8339 json_object_string_add(json_vrf, "interface",
8340 ifindex2ifname(bgp->l3vni_svi_ifindex,
8341 bgp->vrf_id));
d62a17ae 8342 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 8343 } else {
fe1dc5a3 8344 vty_out(vty,
efb4077a 8345 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
8346 type,
8347 bgp->vrf_id == VRF_UNKNOWN ? -1
8348 : (int)bgp->vrf_id,
8349 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
8350 peers_estb, name);
8351 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
8352 bgp->l3vni,
8353 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
8354 ifindex2ifname(bgp->l3vni_svi_ifindex,
8355 bgp->vrf_id));
8356 }
d62a17ae 8357 }
8358
8359 if (uj) {
8360 json_object_object_add(json, "vrfs", json_vrfs);
8361
8362 json_object_int_add(json, "totalVrfs", count);
8363
996c9314
LB
8364 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8365 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8366 json_object_free(json);
8367 } else {
8368 if (count)
8369 vty_out(vty,
8370 "\nTotal number of VRFs (including default): %d\n",
8371 count);
8372 }
8373
8374 return CMD_SUCCESS;
8386ac43 8375}
8376
48ecf8f5
DS
8377DEFUN (show_bgp_mac_hash,
8378 show_bgp_mac_hash_cmd,
8379 "show bgp mac hash",
8380 SHOW_STR
8381 BGP_STR
8382 "Mac Address\n"
8383 "Mac Address database\n")
8384{
8385 bgp_mac_dump_table(vty);
8386
8387 return CMD_SUCCESS;
8388}
acf71666 8389
e3b78da8 8390static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 8391{
0291c246 8392 struct vty *vty = (struct vty *)args;
e3b78da8 8393 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 8394
60466a63 8395 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
8396 tip->refcnt);
8397}
8398
8399static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
8400{
8401 vty_out(vty, "self nexthop database:\n");
af97a18b 8402 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
8403
8404 vty_out(vty, "Tunnel-ip database:\n");
8405 hash_iterate(bgp->tip_hash,
e3b78da8 8406 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
8407 vty);
8408}
8409
15c81ca4
DS
8410DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
8411 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
8412 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
8413 "martian next-hops\n"
8414 "martian next-hop database\n")
acf71666 8415{
0291c246 8416 struct bgp *bgp = NULL;
15c81ca4 8417 int idx = 0;
9a8bdf1c
PG
8418 char *name = NULL;
8419
8420 /* [<vrf> VIEWVRFNAME] */
8421 if (argv_find(argv, argc, "vrf", &idx)) {
8422 name = argv[idx + 1]->arg;
8423 if (name && strmatch(name, VRF_DEFAULT_NAME))
8424 name = NULL;
8425 } else if (argv_find(argv, argc, "view", &idx))
8426 /* [<view> VIEWVRFNAME] */
8427 name = argv[idx + 1]->arg;
8428 if (name)
8429 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
8430 else
8431 bgp = bgp_get_default();
acf71666 8432
acf71666
MK
8433 if (!bgp) {
8434 vty_out(vty, "%% No BGP process is configured\n");
8435 return CMD_WARNING;
8436 }
8437 bgp_show_martian_nexthops(vty, bgp);
8438
8439 return CMD_SUCCESS;
8440}
8441
f412b39a 8442DEFUN (show_bgp_memory,
4bf6a362 8443 show_bgp_memory_cmd,
7fa12b13 8444 "show [ip] bgp memory",
4bf6a362 8445 SHOW_STR
3a2d747c 8446 IP_STR
4bf6a362
PJ
8447 BGP_STR
8448 "Global BGP memory statistics\n")
8449{
d62a17ae 8450 char memstrbuf[MTYPE_MEMSTR_LEN];
8451 unsigned long count;
8452
8453 /* RIB related usage stats */
8454 count = mtype_stats_alloc(MTYPE_BGP_NODE);
8455 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
8456 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8457 count * sizeof(struct bgp_node)));
8458
8459 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
8460 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
8461 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 8462 count * sizeof(struct bgp_path_info)));
d62a17ae 8463 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
8464 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
8465 count,
4b7e6066
DS
8466 mtype_memstr(
8467 memstrbuf, sizeof(memstrbuf),
8468 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 8469
8470 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
8471 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
8472 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8473 count * sizeof(struct bgp_static)));
8474
8475 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
8476 vty_out(vty, "%ld Packets, using %s of memory\n", count,
8477 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8478 count * sizeof(struct bpacket)));
8479
8480 /* Adj-In/Out */
8481 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
8482 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
8483 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8484 count * sizeof(struct bgp_adj_in)));
8485 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
8486 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
8487 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8488 count * sizeof(struct bgp_adj_out)));
8489
8490 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
8491 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
8492 count,
8493 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8494 count * sizeof(struct bgp_nexthop_cache)));
8495
8496 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
8497 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
8498 count,
8499 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8500 count * sizeof(struct bgp_damp_info)));
8501
8502 /* Attributes */
8503 count = attr_count();
8504 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
8505 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8506 count * sizeof(struct attr)));
8507
8508 if ((count = attr_unknown_count()))
8509 vty_out(vty, "%ld unknown attributes\n", count);
8510
8511 /* AS_PATH attributes */
8512 count = aspath_count();
8513 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
8514 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8515 count * sizeof(struct aspath)));
8516
8517 count = mtype_stats_alloc(MTYPE_AS_SEG);
8518 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
8519 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8520 count * sizeof(struct assegment)));
8521
8522 /* Other attributes */
8523 if ((count = community_count()))
8524 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8525 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8526 count * sizeof(struct community)));
d62a17ae 8527 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
8528 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8529 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8530 count * sizeof(struct ecommunity)));
d62a17ae 8531 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
8532 vty_out(vty,
8533 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
8534 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8535 count * sizeof(struct lcommunity)));
d62a17ae 8536
8537 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
8538 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
8539 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8540 count * sizeof(struct cluster_list)));
8541
8542 /* Peer related usage */
8543 count = mtype_stats_alloc(MTYPE_BGP_PEER);
8544 vty_out(vty, "%ld peers, using %s of memory\n", count,
8545 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8546 count * sizeof(struct peer)));
8547
8548 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
8549 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
8550 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8551 count * sizeof(struct peer_group)));
8552
8553 /* Other */
d62a17ae 8554 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
8555 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
8556 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8557 count * sizeof(regex_t)));
d62a17ae 8558 return CMD_SUCCESS;
4bf6a362 8559}
fee0f4c6 8560
57a9c8a8
DS
8561static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
8562{
8563 json_object *bestpath = json_object_new_object();
8564
892fedb6 8565 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
8566 json_object_string_add(bestpath, "asPath", "ignore");
8567
892fedb6 8568 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
8569 json_object_string_add(bestpath, "asPath", "confed");
8570
892fedb6
DA
8571 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
8572 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 8573 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8574 "as-set");
8575 else
a4d82a8a 8576 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8577 "true");
8578 } else
a4d82a8a 8579 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 8580
892fedb6 8581 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 8582 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
8583 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
8584 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
8585 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 8586 json_object_string_add(bestpath, "med", "confed");
892fedb6 8587 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
8588 json_object_string_add(bestpath, "med",
8589 "missing-as-worst");
8590 else
8591 json_object_string_add(bestpath, "med", "true");
8592 }
8593
8594 json_object_object_add(json, "bestPath", bestpath);
8595}
8596
3577f1c5
DD
8597/* Print the error code/subcode for why the peer is down */
8598static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
8599 json_object *json_peer, bool use_json)
8600{
8601 const char *code_str;
8602 const char *subcode_str;
8603
8604 if (use_json) {
8605 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8606 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8607 char errorcodesubcode_hexstr[5];
8608 char errorcodesubcode_str[256];
8609
8610 code_str = bgp_notify_code_str(peer->notify.code);
8611 subcode_str = bgp_notify_subcode_str(
8612 peer->notify.code,
8613 peer->notify.subcode);
8614
8615 sprintf(errorcodesubcode_hexstr, "%02X%02X",
8616 peer->notify.code, peer->notify.subcode);
8617 json_object_string_add(json_peer,
8618 "lastErrorCodeSubcode",
8619 errorcodesubcode_hexstr);
8620 snprintf(errorcodesubcode_str, 255, "%s%s",
8621 code_str, subcode_str);
8622 json_object_string_add(json_peer,
8623 "lastNotificationReason",
8624 errorcodesubcode_str);
8625 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8626 && peer->notify.code == BGP_NOTIFY_CEASE
8627 && (peer->notify.subcode
8628 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8629 || peer->notify.subcode
8630 == BGP_NOTIFY_CEASE_ADMIN_RESET)
8631 && peer->notify.length) {
8632 char msgbuf[1024];
8633 const char *msg_str;
8634
8635 msg_str = bgp_notify_admin_message(
8636 msgbuf, sizeof(msgbuf),
8637 (uint8_t *)peer->notify.data,
8638 peer->notify.length);
8639 if (msg_str)
8640 json_object_string_add(
8641 json_peer,
8642 "lastShutdownDescription",
8643 msg_str);
8644 }
8645
c258527b 8646 }
3577f1c5
DD
8647 json_object_string_add(json_peer, "lastResetDueTo",
8648 peer_down_str[(int)peer->last_reset]);
05912a17
DD
8649 json_object_int_add(json_peer, "lastResetCode",
8650 peer->last_reset);
3577f1c5
DD
8651 } else {
8652 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8653 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8654 code_str = bgp_notify_code_str(peer->notify.code);
8655 subcode_str =
8656 bgp_notify_subcode_str(peer->notify.code,
8657 peer->notify.subcode);
8658 vty_out(vty, " Notification %s (%s%s)\n",
8659 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8660 ? "sent"
8661 : "received",
8662 code_str, subcode_str);
8663 } else {
e91c24c8 8664 vty_out(vty, " %s\n",
3577f1c5
DD
8665 peer_down_str[(int)peer->last_reset]);
8666 }
8667 }
8668}
8669
8670static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8671 safi_t safi)
8672{
8673 return ((peer->status != Established) ||
8674 !peer->afc_recv[afi][safi]);
8675}
8676
8677static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8678 struct peer *peer, json_object *json_peer,
8679 int max_neighbor_width, bool use_json)
8680{
8681 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8682 int len;
8683
8684 if (use_json) {
8685 if (peer_dynamic_neighbor(peer))
8686 json_object_boolean_true_add(json_peer,
8687 "dynamicPeer");
8688 if (peer->hostname)
8689 json_object_string_add(json_peer, "hostname",
8690 peer->hostname);
8691
8692 if (peer->domainname)
8693 json_object_string_add(json_peer, "domainname",
8694 peer->domainname);
8695 json_object_int_add(json_peer, "connectionsEstablished",
8696 peer->established);
8697 json_object_int_add(json_peer, "connectionsDropped",
8698 peer->dropped);
8699 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8700 use_json, json_peer);
8701 if (peer->status == Established)
8702 json_object_string_add(json_peer, "lastResetDueTo",
8703 "AFI/SAFI Not Negotiated");
8704 else
8705 bgp_show_peer_reset(NULL, peer, json_peer, true);
8706 } else {
8707 dn_flag[1] = '\0';
8708 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8709 if (peer->hostname
892fedb6 8710 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
8711 len = vty_out(vty, "%s%s(%s)", dn_flag,
8712 peer->hostname, peer->host);
8713 else
8714 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8715
8716 /* pad the neighbor column with spaces */
8717 if (len < max_neighbor_width)
8718 vty_out(vty, "%*s", max_neighbor_width - len,
8719 " ");
e91c24c8 8720 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
8721 peer->dropped,
8722 peer_uptime(peer->uptime, timebuf,
8723 BGP_UPTIME_LEN, 0, NULL));
8724 if (peer->status == Established)
8725 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8726 else
8727 bgp_show_peer_reset(vty, peer, NULL,
8728 false);
8729 }
8730}
c258527b 8731
3577f1c5 8732
718e3744 8733/* Show BGP peer's summary information. */
d62a17ae 8734static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
3577f1c5 8735 bool show_failed, bool use_json)
d62a17ae 8736{
8737 struct peer *peer;
8738 struct listnode *node, *nnode;
8739 unsigned int count = 0, dn_count = 0;
8740 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8741 char neighbor_buf[VTY_BUFSIZ];
8742 int neighbor_col_default_width = 16;
3577f1c5 8743 int len, failed_count = 0;
d62a17ae 8744 int max_neighbor_width = 0;
8745 int pfx_rcd_safi;
3c13337d 8746 json_object *json = NULL;
d62a17ae 8747 json_object *json_peer = NULL;
8748 json_object *json_peers = NULL;
50e05855 8749 struct peer_af *paf;
d62a17ae 8750
8751 /* labeled-unicast routes are installed in the unicast table so in order
8752 * to
8753 * display the correct PfxRcd value we must look at SAFI_UNICAST
8754 */
3577f1c5 8755
d62a17ae 8756 if (safi == SAFI_LABELED_UNICAST)
8757 pfx_rcd_safi = SAFI_UNICAST;
8758 else
8759 pfx_rcd_safi = safi;
8760
8761 if (use_json) {
3c13337d 8762 json = json_object_new_object();
d62a17ae 8763 json_peers = json_object_new_object();
3577f1c5
DD
8764 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8765 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8766 continue;
8767
8768 if (peer->afc[afi][safi]) {
8769 /* See if we have at least a single failed peer */
8770 if (bgp_has_peer_failed(peer, afi, safi))
8771 failed_count++;
8772 count++;
8773 }
8774 if (peer_dynamic_neighbor(peer))
8775 dn_count++;
8776 }
c258527b 8777
d62a17ae 8778 } else {
8779 /* Loop over all neighbors that will be displayed to determine
8780 * how many
8781 * characters are needed for the Neighbor column
8782 */
8783 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8784 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8785 continue;
8786
8787 if (peer->afc[afi][safi]) {
8788 memset(dn_flag, '\0', sizeof(dn_flag));
8789 if (peer_dynamic_neighbor(peer))
8790 dn_flag[0] = '*';
8791
8792 if (peer->hostname
892fedb6
DA
8793 && CHECK_FLAG(bgp->flags,
8794 BGP_FLAG_SHOW_HOSTNAME))
d62a17ae 8795 sprintf(neighbor_buf, "%s%s(%s) ",
8796 dn_flag, peer->hostname,
8797 peer->host);
8798 else
8799 sprintf(neighbor_buf, "%s%s ", dn_flag,
8800 peer->host);
8801
8802 len = strlen(neighbor_buf);
8803
8804 if (len > max_neighbor_width)
8805 max_neighbor_width = len;
c258527b 8806
3577f1c5
DD
8807 /* See if we have at least a single failed peer */
8808 if (bgp_has_peer_failed(peer, afi, safi))
8809 failed_count++;
8810 count++;
d62a17ae 8811 }
8812 }
f933309e 8813
d62a17ae 8814 /* Originally we displayed the Neighbor column as 16
8815 * characters wide so make that the default
8816 */
8817 if (max_neighbor_width < neighbor_col_default_width)
8818 max_neighbor_width = neighbor_col_default_width;
8819 }
f933309e 8820
3577f1c5
DD
8821 if (show_failed && !failed_count) {
8822 if (use_json) {
8823 json_object_int_add(json, "failedPeersCount", 0);
8824 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 8825 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
8826
8827 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8828 json, JSON_C_TO_STRING_PRETTY));
8829 json_object_free(json);
8830 } else {
8831 vty_out(vty, "%% No failed BGP neighbors found\n");
8832 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8833 }
8834 return CMD_SUCCESS;
8835 }
c258527b 8836
3577f1c5 8837 count = 0; /* Reset the value as its used again */
d62a17ae 8838 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8839 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8840 continue;
8841
ea47320b
DL
8842 if (!peer->afc[afi][safi])
8843 continue;
d62a17ae 8844
ea47320b
DL
8845 if (!count) {
8846 unsigned long ents;
8847 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 8848 int64_t vrf_id_ui;
d62a17ae 8849
a4d82a8a
PZ
8850 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8851 ? -1
8852 : (int64_t)bgp->vrf_id;
ea47320b
DL
8853
8854 /* Usage summary and header */
8855 if (use_json) {
8856 json_object_string_add(
8857 json, "routerId",
8858 inet_ntoa(bgp->router_id));
60466a63
QY
8859 json_object_int_add(json, "as", bgp->as);
8860 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
8861 json_object_string_add(
8862 json, "vrfName",
8863 (bgp->inst_type
8864 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8865 ? VRF_DEFAULT_NAME
ea47320b
DL
8866 : bgp->name);
8867 } else {
8868 vty_out(vty,
8869 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 8870 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
8871 bgp->vrf_id == VRF_UNKNOWN
8872 ? -1
8873 : (int)bgp->vrf_id);
ea47320b
DL
8874 vty_out(vty, "\n");
8875 }
d62a17ae 8876
ea47320b 8877 if (bgp_update_delay_configured(bgp)) {
d62a17ae 8878 if (use_json) {
ea47320b 8879 json_object_int_add(
60466a63 8880 json, "updateDelayLimit",
ea47320b 8881 bgp->v_update_delay);
d62a17ae 8882
ea47320b
DL
8883 if (bgp->v_update_delay
8884 != bgp->v_establish_wait)
d62a17ae 8885 json_object_int_add(
8886 json,
ea47320b
DL
8887 "updateDelayEstablishWait",
8888 bgp->v_establish_wait);
d62a17ae 8889
60466a63 8890 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8891 json_object_string_add(
8892 json,
8893 "updateDelayFirstNeighbor",
8894 bgp->update_delay_begin_time);
8895 json_object_boolean_true_add(
8896 json,
8897 "updateDelayInProgress");
8898 } else {
8899 if (bgp->update_delay_over) {
d62a17ae 8900 json_object_string_add(
8901 json,
8902 "updateDelayFirstNeighbor",
8903 bgp->update_delay_begin_time);
ea47320b 8904 json_object_string_add(
d62a17ae 8905 json,
ea47320b
DL
8906 "updateDelayBestpathResumed",
8907 bgp->update_delay_end_time);
8908 json_object_string_add(
d62a17ae 8909 json,
ea47320b
DL
8910 "updateDelayZebraUpdateResume",
8911 bgp->update_delay_zebra_resume_time);
8912 json_object_string_add(
8913 json,
8914 "updateDelayPeerUpdateResume",
8915 bgp->update_delay_peers_resume_time);
d62a17ae 8916 }
ea47320b
DL
8917 }
8918 } else {
8919 vty_out(vty,
8920 "Read-only mode update-delay limit: %d seconds\n",
8921 bgp->v_update_delay);
8922 if (bgp->v_update_delay
8923 != bgp->v_establish_wait)
d62a17ae 8924 vty_out(vty,
ea47320b
DL
8925 " Establish wait: %d seconds\n",
8926 bgp->v_establish_wait);
d62a17ae 8927
60466a63 8928 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8929 vty_out(vty,
8930 " First neighbor established: %s\n",
8931 bgp->update_delay_begin_time);
8932 vty_out(vty,
8933 " Delay in progress\n");
8934 } else {
8935 if (bgp->update_delay_over) {
d62a17ae 8936 vty_out(vty,
8937 " First neighbor established: %s\n",
8938 bgp->update_delay_begin_time);
8939 vty_out(vty,
ea47320b
DL
8940 " Best-paths resumed: %s\n",
8941 bgp->update_delay_end_time);
8942 vty_out(vty,
8943 " zebra update resumed: %s\n",
8944 bgp->update_delay_zebra_resume_time);
8945 vty_out(vty,
8946 " peers update resumed: %s\n",
8947 bgp->update_delay_peers_resume_time);
d62a17ae 8948 }
8949 }
8950 }
ea47320b 8951 }
d62a17ae 8952
ea47320b
DL
8953 if (use_json) {
8954 if (bgp_maxmed_onstartup_configured(bgp)
8955 && bgp->maxmed_active)
8956 json_object_boolean_true_add(
60466a63 8957 json, "maxMedOnStartup");
ea47320b
DL
8958 if (bgp->v_maxmed_admin)
8959 json_object_boolean_true_add(
60466a63 8960 json, "maxMedAdministrative");
d62a17ae 8961
ea47320b
DL
8962 json_object_int_add(
8963 json, "tableVersion",
60466a63 8964 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 8965
60466a63
QY
8966 ents = bgp_table_count(bgp->rib[afi][safi]);
8967 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
8968 json_object_int_add(
8969 json, "ribMemory",
8970 ents * sizeof(struct bgp_node));
d62a17ae 8971
210ec2a0 8972 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
8973 json_object_int_add(json, "peerCount", ents);
8974 json_object_int_add(json, "peerMemory",
8975 ents * sizeof(struct peer));
d62a17ae 8976
ea47320b
DL
8977 if ((ents = listcount(bgp->group))) {
8978 json_object_int_add(
60466a63 8979 json, "peerGroupCount", ents);
ea47320b
DL
8980 json_object_int_add(
8981 json, "peerGroupMemory",
996c9314
LB
8982 ents * sizeof(struct
8983 peer_group));
ea47320b 8984 }
d62a17ae 8985
ea47320b
DL
8986 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8987 BGP_CONFIG_DAMPENING))
8988 json_object_boolean_true_add(
60466a63 8989 json, "dampeningEnabled");
ea47320b
DL
8990 } else {
8991 if (bgp_maxmed_onstartup_configured(bgp)
8992 && bgp->maxmed_active)
d62a17ae 8993 vty_out(vty,
ea47320b
DL
8994 "Max-med on-startup active\n");
8995 if (bgp->v_maxmed_admin)
d62a17ae 8996 vty_out(vty,
ea47320b 8997 "Max-med administrative active\n");
d62a17ae 8998
60466a63
QY
8999 vty_out(vty, "BGP table version %" PRIu64 "\n",
9000 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 9001
60466a63 9002 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
9003 vty_out(vty,
9004 "RIB entries %ld, using %s of memory\n",
9005 ents,
996c9314
LB
9006 mtype_memstr(memstrbuf,
9007 sizeof(memstrbuf),
9008 ents * sizeof(struct
9009 bgp_node)));
ea47320b
DL
9010
9011 /* Peer related usage */
210ec2a0 9012 ents = bgp->af_peer_count[afi][safi];
60466a63 9013 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
9014 ents,
9015 mtype_memstr(
60466a63
QY
9016 memstrbuf, sizeof(memstrbuf),
9017 ents * sizeof(struct peer)));
ea47320b
DL
9018
9019 if ((ents = listcount(bgp->group)))
d62a17ae 9020 vty_out(vty,
ea47320b 9021 "Peer groups %ld, using %s of memory\n",
d62a17ae 9022 ents,
9023 mtype_memstr(
9024 memstrbuf,
9025 sizeof(memstrbuf),
996c9314
LB
9026 ents * sizeof(struct
9027 peer_group)));
d62a17ae 9028
ea47320b
DL
9029 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9030 BGP_CONFIG_DAMPENING))
60466a63 9031 vty_out(vty, "Dampening enabled.\n");
ea47320b 9032 vty_out(vty, "\n");
d62a17ae 9033
ea47320b
DL
9034 /* Subtract 8 here because 'Neighbor' is
9035 * 8 characters */
9036 vty_out(vty, "Neighbor");
60466a63
QY
9037 vty_out(vty, "%*s", max_neighbor_width - 8,
9038 " ");
3577f1c5
DD
9039 if (show_failed)
9040 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
9041 else
9042 vty_out(vty,
bed8d78b 9043 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 9044 }
ea47320b 9045 }
d62a17ae 9046
ea47320b 9047 count++;
3577f1c5
DD
9048 /* Works for both failed & successful cases */
9049 if (peer_dynamic_neighbor(peer))
9050 dn_count++;
d62a17ae 9051
ea47320b 9052 if (use_json) {
3577f1c5
DD
9053 json_peer = NULL;
9054
9055 if (show_failed &&
9056 bgp_has_peer_failed(peer, afi, safi)) {
9057 json_peer = json_object_new_object();
9058 bgp_show_failed_summary(vty, bgp, peer,
9059 json_peer, 0, use_json);
9060 } else if (!show_failed) {
9061 json_peer = json_object_new_object();
9062 if (peer_dynamic_neighbor(peer)) {
9063 json_object_boolean_true_add(json_peer,
9064 "dynamicPeer");
9065 }
d62a17ae 9066
3577f1c5
DD
9067 if (peer->hostname)
9068 json_object_string_add(json_peer, "hostname",
9069 peer->hostname);
9070
9071 if (peer->domainname)
9072 json_object_string_add(json_peer, "domainname",
9073 peer->domainname);
9074
9075 json_object_int_add(json_peer, "remoteAs", peer->as);
9076 json_object_int_add(json_peer, "version", 4);
9077 json_object_int_add(json_peer, "msgRcvd",
9078 PEER_TOTAL_RX(peer));
9079 json_object_int_add(json_peer, "msgSent",
9080 PEER_TOTAL_TX(peer));
9081
43aa5965
QY
9082 atomic_size_t outq_count, inq_count;
9083 outq_count = atomic_load_explicit(
9084 &peer->obuf->count,
9085 memory_order_relaxed);
9086 inq_count = atomic_load_explicit(
9087 &peer->ibuf->count,
9088 memory_order_relaxed);
9089
3577f1c5
DD
9090 json_object_int_add(json_peer, "tableVersion",
9091 peer->version[afi][safi]);
9092 json_object_int_add(json_peer, "outq",
43aa5965
QY
9093 outq_count);
9094 json_object_int_add(json_peer, "inq",
9095 inq_count);
3577f1c5
DD
9096 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9097 use_json, json_peer);
9098
3577f1c5
DD
9099 json_object_int_add(json_peer, "pfxRcd",
9100 peer->pcount[afi][pfx_rcd_safi]);
9101
9102 paf = peer_af_find(peer, afi, pfx_rcd_safi);
9103 if (paf && PAF_SUBGRP(paf))
9104 json_object_int_add(json_peer,
9105 "pfxSnt",
9106 (PAF_SUBGRP(paf))->scount);
9107 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9108 json_object_string_add(json_peer, "state",
9109 "Idle (Admin)");
9110 else if (peer->afc_recv[afi][safi])
9111 json_object_string_add(
9112 json_peer, "state",
9113 lookup_msg(bgp_status_msg, peer->status,
9114 NULL));
9115 else if (CHECK_FLAG(peer->sflags,
9116 PEER_STATUS_PREFIX_OVERFLOW))
9117 json_object_string_add(json_peer, "state",
9118 "Idle (PfxCt)");
9119 else
9120 json_object_string_add(
9121 json_peer, "state",
9122 lookup_msg(bgp_status_msg, peer->status,
9123 NULL));
200116db
DD
9124 json_object_int_add(json_peer, "connectionsEstablished",
9125 peer->established);
9126 json_object_int_add(json_peer, "connectionsDropped",
9127 peer->dropped);
b4e9dcba 9128 }
3577f1c5
DD
9129 /* Avoid creating empty peer dicts in JSON */
9130 if (json_peer == NULL)
9131 continue;
ea47320b
DL
9132
9133 if (peer->conf_if)
60466a63 9134 json_object_string_add(json_peer, "idType",
ea47320b
DL
9135 "interface");
9136 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
9137 json_object_string_add(json_peer, "idType",
9138 "ipv4");
ea47320b 9139 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
9140 json_object_string_add(json_peer, "idType",
9141 "ipv6");
ea47320b
DL
9142 json_object_object_add(json_peers, peer->host,
9143 json_peer);
9144 } else {
3577f1c5
DD
9145 if (show_failed &&
9146 bgp_has_peer_failed(peer, afi, safi)) {
9147 bgp_show_failed_summary(vty, bgp, peer, NULL,
9148 max_neighbor_width,
9149 use_json);
9150 } else if (!show_failed) {
9151 memset(dn_flag, '\0', sizeof(dn_flag));
9152 if (peer_dynamic_neighbor(peer)) {
9153 dn_flag[0] = '*';
9154 }
d62a17ae 9155
3577f1c5 9156 if (peer->hostname
892fedb6
DA
9157 && CHECK_FLAG(bgp->flags,
9158 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 9159 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
9160 peer->hostname,
9161 peer->host);
d62a17ae 9162 else
3577f1c5
DD
9163 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9164
9165 /* pad the neighbor column with spaces */
9166 if (len < max_neighbor_width)
9167 vty_out(vty, "%*s", max_neighbor_width - len,
9168 " ");
9169
43aa5965
QY
9170 atomic_size_t outq_count, inq_count;
9171 outq_count = atomic_load_explicit(
9172 &peer->obuf->count,
9173 memory_order_relaxed);
9174 inq_count = atomic_load_explicit(
9175 &peer->ibuf->count,
9176 memory_order_relaxed);
9177
566bdaf6 9178 vty_out(vty,
43aa5965
QY
9179 "4 %10u %9u %9u %8" PRIu64
9180 " %4zu %4zu %8s",
3577f1c5 9181 peer->as, PEER_TOTAL_RX(peer),
566bdaf6 9182 PEER_TOTAL_TX(peer),
43aa5965
QY
9183 peer->version[afi][safi], inq_count,
9184 outq_count,
3577f1c5
DD
9185 peer_uptime(peer->uptime, timebuf,
9186 BGP_UPTIME_LEN, 0, NULL));
9187
9188 if (peer->status == Established)
9189 if (peer->afc_recv[afi][safi])
a0a87037
DA
9190 vty_out(vty, " %12" PRIu32,
9191 peer->pcount
9192 [afi]
9193 [pfx_rcd_safi]);
3577f1c5
DD
9194 else
9195 vty_out(vty, " NoNeg");
9196 else {
9197 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9198 vty_out(vty, " Idle (Admin)");
9199 else if (CHECK_FLAG(
9200 peer->sflags,
9201 PEER_STATUS_PREFIX_OVERFLOW))
9202 vty_out(vty, " Idle (PfxCt)");
9203 else
9204 vty_out(vty, " %12s",
9205 lookup_msg(bgp_status_msg,
9206 peer->status, NULL));
9207 }
9208 vty_out(vty, "\n");
d62a17ae 9209 }
3577f1c5 9210
d62a17ae 9211 }
9212 }
f933309e 9213
d62a17ae 9214 if (use_json) {
9215 json_object_object_add(json, "peers", json_peers);
3577f1c5 9216 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 9217 json_object_int_add(json, "totalPeers", count);
9218 json_object_int_add(json, "dynamicPeers", dn_count);
9219
3577f1c5
DD
9220 if (!show_failed)
9221 bgp_show_bestpath_json(bgp, json);
57a9c8a8 9222
996c9314
LB
9223 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9224 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9225 json_object_free(json);
9226 } else {
9227 if (count)
9228 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9229 else {
d6ceaca3 9230 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 9231 get_afi_safi_str(afi, safi, false));
d62a17ae 9232 }
b05a1c8b 9233
d6ceaca3 9234 if (dn_count) {
d62a17ae 9235 vty_out(vty, "* - dynamic neighbor\n");
9236 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
9237 dn_count, bgp->dynamic_neighbors_limit);
9238 }
9239 }
1ff9a340 9240
d62a17ae 9241 return CMD_SUCCESS;
718e3744 9242}
9243
d62a17ae 9244static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
3577f1c5 9245 int safi, bool show_failed, bool use_json)
d62a17ae 9246{
9247 int is_first = 1;
9248 int afi_wildcard = (afi == AFI_MAX);
9249 int safi_wildcard = (safi == SAFI_MAX);
9250 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 9251 bool nbr_output = false;
d62a17ae 9252
9253 if (use_json && is_wildcard)
9254 vty_out(vty, "{\n");
9255 if (afi_wildcard)
9256 afi = 1; /* AFI_IP */
9257 while (afi < AFI_MAX) {
9258 if (safi_wildcard)
9259 safi = 1; /* SAFI_UNICAST */
9260 while (safi < SAFI_MAX) {
318cac96 9261 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 9262 nbr_output = true;
f86897b9 9263
d62a17ae 9264 if (is_wildcard) {
9265 /*
9266 * So limit output to those afi/safi
9267 * pairs that
9268 * actualy have something interesting in
9269 * them
9270 */
9271 if (use_json) {
d62a17ae 9272 if (!is_first)
9273 vty_out(vty, ",\n");
9274 else
9275 is_first = 0;
9276
9277 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
9278 get_afi_safi_str(afi,
9279 safi,
9280 true));
d62a17ae 9281 } else {
9282 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
9283 get_afi_safi_str(afi,
9284 safi,
9285 false));
d62a17ae 9286 }
9287 }
3577f1c5
DD
9288 bgp_show_summary(vty, bgp, afi, safi, show_failed,
9289 use_json);
d62a17ae 9290 }
9291 safi++;
d62a17ae 9292 if (!safi_wildcard)
9293 safi = SAFI_MAX;
9294 }
9295 afi++;
ee851c8c 9296 if (!afi_wildcard)
d62a17ae 9297 afi = AFI_MAX;
9298 }
9299
9300 if (use_json && is_wildcard)
9301 vty_out(vty, "}\n");
ca61fd25
DS
9302 else if (!nbr_output) {
9303 if (use_json)
9304 vty_out(vty, "{}\n");
9305 else
9306 vty_out(vty, "%% No BGP neighbors found\n");
9307 }
d62a17ae 9308}
9309
9310static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5
DD
9311 safi_t safi, bool show_failed,
9312 bool use_json)
d62a17ae 9313{
9314 struct listnode *node, *nnode;
9315 struct bgp *bgp;
d62a17ae 9316 int is_first = 1;
9f049418 9317 bool nbr_output = false;
d62a17ae 9318
9319 if (use_json)
9320 vty_out(vty, "{\n");
9321
9322 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 9323 nbr_output = true;
d62a17ae 9324 if (use_json) {
d62a17ae 9325 if (!is_first)
9326 vty_out(vty, ",\n");
9327 else
9328 is_first = 0;
9329
9330 vty_out(vty, "\"%s\":",
9331 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9332 ? VRF_DEFAULT_NAME
d62a17ae 9333 : bgp->name);
9334 } else {
9335 vty_out(vty, "\nInstance %s:\n",
9336 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9337 ? VRF_DEFAULT_NAME
d62a17ae 9338 : bgp->name);
9339 }
3577f1c5
DD
9340 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9341 use_json);
d62a17ae 9342 }
9343
9344 if (use_json)
9345 vty_out(vty, "}\n");
9f049418
DS
9346 else if (!nbr_output)
9347 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 9348}
9349
9350int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
3577f1c5 9351 safi_t safi, bool show_failed, bool use_json)
d62a17ae 9352{
9353 struct bgp *bgp;
9354
9355 if (name) {
9356 if (strmatch(name, "all")) {
9357 bgp_show_all_instances_summary_vty(vty, afi, safi,
3577f1c5 9358 show_failed,
d62a17ae 9359 use_json);
9360 return CMD_SUCCESS;
9361 } else {
9362 bgp = bgp_lookup_by_name(name);
9363
9364 if (!bgp) {
9365 if (use_json)
9366 vty_out(vty, "{}\n");
9367 else
9368 vty_out(vty,
ca61fd25 9369 "%% BGP instance not found\n");
d62a17ae 9370 return CMD_WARNING;
9371 }
9372
f86897b9 9373 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
3577f1c5 9374 show_failed, use_json);
d62a17ae 9375 return CMD_SUCCESS;
9376 }
9377 }
9378
9379 bgp = bgp_get_default();
9380
9381 if (bgp)
3577f1c5
DD
9382 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9383 use_json);
9f049418 9384 else {
ca61fd25
DS
9385 if (use_json)
9386 vty_out(vty, "{}\n");
9387 else
9388 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
9389 return CMD_WARNING;
9390 }
d62a17ae 9391
9392 return CMD_SUCCESS;
4fb25c53
DW
9393}
9394
716b2d8a 9395/* `show [ip] bgp summary' commands. */
47fc97cc 9396DEFUN (show_ip_bgp_summary,
718e3744 9397 show_ip_bgp_summary_cmd,
3577f1c5 9398 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
718e3744 9399 SHOW_STR
9400 IP_STR
9401 BGP_STR
8386ac43 9402 BGP_INSTANCE_HELP_STR
46f296b4 9403 BGP_AFI_HELP_STR
dd6bd0f1 9404 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 9405 "Summary of BGP neighbor status\n"
3577f1c5 9406 "Show only sessions not in Established state\n"
9973d184 9407 JSON_STR)
718e3744 9408{
d62a17ae 9409 char *vrf = NULL;
9410 afi_t afi = AFI_MAX;
9411 safi_t safi = SAFI_MAX;
3577f1c5 9412 bool show_failed = false;
d62a17ae 9413
9414 int idx = 0;
9415
9416 /* show [ip] bgp */
9417 if (argv_find(argv, argc, "ip", &idx))
9418 afi = AFI_IP;
9a8bdf1c
PG
9419 /* [<vrf> VIEWVRFNAME] */
9420 if (argv_find(argv, argc, "vrf", &idx)) {
9421 vrf = argv[idx + 1]->arg;
9422 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9423 vrf = NULL;
9424 } else if (argv_find(argv, argc, "view", &idx))
9425 /* [<view> VIEWVRFNAME] */
9426 vrf = argv[idx + 1]->arg;
d62a17ae 9427 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9428 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
9429 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9430 }
9431
3577f1c5
DD
9432 if (argv_find(argv, argc, "failed", &idx))
9433 show_failed = true;
9434
9f049418 9435 bool uj = use_json(argc, argv);
d62a17ae 9436
3577f1c5 9437 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
d62a17ae 9438}
9439
5cb5f4d0 9440const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 9441{
5cb5f4d0
DD
9442 if (for_json)
9443 return get_afi_safi_json_str(afi, safi);
d62a17ae 9444 else
5cb5f4d0 9445 return get_afi_safi_vty_str(afi, safi);
27162734
LB
9446}
9447
d62a17ae 9448
9449static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
9450 afi_t afi, safi_t safi,
d7c0a89a
QY
9451 uint16_t adv_smcap, uint16_t adv_rmcap,
9452 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 9453 bool use_json, json_object *json_pref)
d62a17ae 9454{
9455 /* Send-Mode */
9456 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9457 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
9458 if (use_json) {
9459 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9460 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9461 json_object_string_add(json_pref, "sendMode",
9462 "advertisedAndReceived");
9463 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9464 json_object_string_add(json_pref, "sendMode",
9465 "advertised");
9466 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9467 json_object_string_add(json_pref, "sendMode",
9468 "received");
9469 } else {
9470 vty_out(vty, " Send-mode: ");
9471 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9472 vty_out(vty, "advertised");
9473 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9474 vty_out(vty, "%sreceived",
9475 CHECK_FLAG(p->af_cap[afi][safi],
9476 adv_smcap)
9477 ? ", "
9478 : "");
9479 vty_out(vty, "\n");
9480 }
9481 }
9482
9483 /* Receive-Mode */
9484 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9485 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
9486 if (use_json) {
9487 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9488 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9489 json_object_string_add(json_pref, "recvMode",
9490 "advertisedAndReceived");
9491 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9492 json_object_string_add(json_pref, "recvMode",
9493 "advertised");
9494 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9495 json_object_string_add(json_pref, "recvMode",
9496 "received");
9497 } else {
9498 vty_out(vty, " Receive-mode: ");
9499 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9500 vty_out(vty, "advertised");
9501 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9502 vty_out(vty, "%sreceived",
9503 CHECK_FLAG(p->af_cap[afi][safi],
9504 adv_rmcap)
9505 ? ", "
9506 : "");
9507 vty_out(vty, "\n");
9508 }
9509 }
9510}
9511
13909c4f
DS
9512static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
9513 struct peer *p,
9514 bool use_json,
9515 json_object *json)
2986cac2 9516{
08c2d52a 9517 bool rbit_status = false;
2986cac2 9518
9519 if (!use_json)
a53ca37b 9520 vty_out(vty, "\n R bit: ");
2986cac2 9521
13909c4f
DS
9522 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
9523 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
9524 && (p->status == Established)) {
2986cac2 9525
9526 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 9527 rbit_status = true;
2986cac2 9528 else
08c2d52a 9529 rbit_status = false;
2986cac2 9530 }
9531
9532 if (rbit_status) {
9533 if (use_json)
13909c4f 9534 json_object_boolean_true_add(json, "rBit");
2986cac2 9535 else
9536 vty_out(vty, "True\n");
9537 } else {
9538 if (use_json)
13909c4f 9539 json_object_boolean_false_add(json, "rBit");
2986cac2 9540 else
9541 vty_out(vty, "False\n");
9542 }
9543}
9544
13909c4f
DS
9545static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
9546 struct peer *peer,
9547 bool use_json,
9548 json_object *json)
2986cac2 9549{
2bb5d39b 9550 const char *mode = "NotApplicable";
2986cac2 9551
9552 if (!use_json)
a53ca37b 9553 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 9554
13909c4f
DS
9555 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9556 && (peer->status == Established)) {
2986cac2 9557
13909c4f
DS
9558 if ((peer->nsf_af_count == 0)
9559 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9560
2986cac2 9561 mode = "Disable";
9562
13909c4f
DS
9563 } else if (peer->nsf_af_count == 0
9564 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9565
2986cac2 9566 mode = "Helper";
9567
13909c4f
DS
9568 } else if (peer->nsf_af_count != 0
9569 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9570
2986cac2 9571 mode = "Restart";
2986cac2 9572 }
9573 }
9574
9575 if (use_json) {
13909c4f 9576 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 9577 } else
9578 vty_out(vty, mode, "\n");
9579}
9580
13909c4f
DS
9581static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
9582 struct peer *p,
9583 bool use_json,
9584 json_object *json)
2986cac2 9585{
9586 const char *mode = "Invalid";
9587
9588 if (!use_json)
a53ca37b 9589 vty_out(vty, " Local GR Mode: ");
2986cac2 9590
9591 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
9592 mode = "Helper";
9593 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
9594 mode = "Restart";
9595 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
9596 mode = "Disable";
2ba1fe69 9597 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 9598 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
9599 mode = "Helper*";
9600 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
9601 mode = "Restart*";
9602 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
9603 mode = "Disable*";
9604 else
9605 mode = "Invalid*";
2ba1fe69 9606 }
2986cac2 9607
9608 if (use_json) {
13909c4f 9609 json_object_string_add(json, "localGrMode", mode);
2986cac2 9610 } else {
9611 vty_out(vty, mode, "\n");
9612 }
9613}
9614
13909c4f
DS
9615static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
9616 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 9617{
2ba1fe69 9618 afi_t afi;
9619 safi_t safi;
2986cac2 9620 json_object *json_afi_safi = NULL;
9621 json_object *json_timer = NULL;
9622 json_object *json_endofrib_status = NULL;
9e3b51a7 9623 bool eor_flag = false;
2986cac2 9624
9625 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9626 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
9627 if (!peer->afc[afi][safi])
9628 continue;
2986cac2 9629
13909c4f
DS
9630 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9631 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
9632 continue;
9e3b51a7 9633
13909c4f
DS
9634 if (use_json) {
9635 json_afi_safi = json_object_new_object();
9636 json_endofrib_status = json_object_new_object();
9637 json_timer = json_object_new_object();
9638 }
2986cac2 9639
13909c4f
DS
9640 if (peer->eor_stime[afi][safi]
9641 >= peer->pkt_stime[afi][safi])
9642 eor_flag = true;
9643 else
9644 eor_flag = false;
2986cac2 9645
13909c4f 9646 if (!use_json) {
a53ca37b 9647 vty_out(vty, " %s:\n",
13909c4f 9648 get_afi_safi_str(afi, safi, false));
2986cac2 9649
a53ca37b 9650 vty_out(vty, " F bit: ");
698ba8d0 9651 }
2986cac2 9652
13909c4f
DS
9653 if (peer->nsf[afi][safi]
9654 && CHECK_FLAG(peer->af_cap[afi][safi],
9655 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 9656
13909c4f
DS
9657 if (use_json) {
9658 json_object_boolean_true_add(
2986cac2 9659 json_afi_safi, "fBit");
13909c4f
DS
9660 } else
9661 vty_out(vty, "True\n");
9662 } else {
9663 if (use_json)
9664 json_object_boolean_false_add(
9665 json_afi_safi, "fBit");
9666 else
9667 vty_out(vty, "False\n");
9668 }
2986cac2 9669
13909c4f 9670 if (!use_json)
a53ca37b 9671 vty_out(vty, " End-of-RIB sent: ");
2986cac2 9672
13909c4f
DS
9673 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9674 PEER_STATUS_EOR_SEND)) {
9675 if (use_json) {
9676 json_object_boolean_true_add(
2986cac2 9677 json_endofrib_status,
13909c4f 9678 "endOfRibSend");
9e3b51a7 9679
13909c4f
DS
9680 PRINT_EOR_JSON(eor_flag);
9681 } else {
9682 vty_out(vty, "Yes\n");
9683 vty_out(vty,
a53ca37b 9684 " End-of-RIB sent after update: ");
2986cac2 9685
13909c4f
DS
9686 PRINT_EOR(eor_flag);
9687 }
9688 } else {
9689 if (use_json) {
9690 json_object_boolean_false_add(
2986cac2 9691 json_endofrib_status,
13909c4f
DS
9692 "endOfRibSend");
9693 json_object_boolean_false_add(
9e3b51a7 9694 json_endofrib_status,
13909c4f
DS
9695 "endOfRibSentAfterUpdate");
9696 } else {
9697 vty_out(vty, "No\n");
9698 vty_out(vty,
a53ca37b 9699 " End-of-RIB sent after update: ");
13909c4f 9700 vty_out(vty, "No\n");
2986cac2 9701 }
13909c4f 9702 }
2986cac2 9703
a53ca37b
DA
9704 if (!use_json)
9705 vty_out(vty, " End-of-RIB received: ");
9706
9707 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9708 PEER_STATUS_EOR_RECEIVED)) {
9709 if (use_json)
9710 json_object_boolean_true_add(
9711 json_endofrib_status,
9712 "endOfRibRecv");
9713 else
9714 vty_out(vty, "Yes\n");
9715 } else {
9716 if (use_json)
9717 json_object_boolean_false_add(
9718 json_endofrib_status,
9719 "endOfRibRecv");
9720 else
9721 vty_out(vty, "No\n");
9722 }
9723
13909c4f
DS
9724 if (use_json) {
9725 json_object_int_add(json_timer,
9726 "stalePathTimer",
9727 peer->bgp->stalepath_time);
2986cac2 9728
13909c4f
DS
9729 if (peer->t_gr_stale != NULL) {
9730 json_object_int_add(
2986cac2 9731 json_timer,
9732 "stalePathTimerRemaining",
9733 thread_timer_remain_second(
13909c4f
DS
9734 peer->t_gr_stale));
9735 }
3a75afa4 9736
13909c4f
DS
9737 /* Display Configured Selection
9738 * Deferral only when when
9739 * Gr mode is enabled.
9740 */
9741 if (CHECK_FLAG(peer->flags,
9742 PEER_FLAG_GRACEFUL_RESTART)) {
9743 json_object_int_add(
3a75afa4 9744 json_timer,
2986cac2 9745 "selectionDeferralTimer",
9746 peer->bgp->stalepath_time);
13909c4f 9747 }
2986cac2 9748
13909c4f
DS
9749 if (peer->bgp->gr_info[afi][safi]
9750 .t_select_deferral
9751 != NULL) {
2986cac2 9752
13909c4f 9753 json_object_int_add(
2986cac2 9754 json_timer,
9755 "selectionDeferralTimerRemaining",
9756 thread_timer_remain_second(
13909c4f
DS
9757 peer->bgp
9758 ->gr_info[afi]
9759 [safi]
9760 .t_select_deferral));
9761 }
9762 } else {
a53ca37b 9763 vty_out(vty, " Timers:\n");
13909c4f 9764 vty_out(vty,
a53ca37b
DA
9765 " Configured Stale Path Time(sec): %u\n",
9766 peer->bgp->stalepath_time);
2986cac2 9767
a53ca37b 9768 if (peer->t_gr_stale != NULL)
2986cac2 9769 vty_out(vty,
a53ca37b 9770 " Stale Path Remaining(sec): %ld\n",
2986cac2 9771 thread_timer_remain_second(
13909c4f 9772 peer->t_gr_stale));
13909c4f
DS
9773 /* Display Configured Selection
9774 * Deferral only when when
9775 * Gr mode is enabled.
9776 */
9777 if (CHECK_FLAG(peer->flags,
a53ca37b 9778 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 9779 vty_out(vty,
a53ca37b 9780 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 9781 peer->bgp->select_defer_time);
2986cac2 9782
13909c4f
DS
9783 if (peer->bgp->gr_info[afi][safi]
9784 .t_select_deferral
a53ca37b 9785 != NULL)
13909c4f 9786 vty_out(vty,
a53ca37b 9787 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 9788 thread_timer_remain_second(
13909c4f
DS
9789 peer->bgp
9790 ->gr_info[afi]
9791 [safi]
9792 .t_select_deferral));
2986cac2 9793 }
13909c4f
DS
9794 if (use_json) {
9795 json_object_object_add(json_afi_safi,
9796 "endOfRibStatus",
9797 json_endofrib_status);
9798 json_object_object_add(json_afi_safi, "timers",
9799 json_timer);
9800 json_object_object_add(
9801 json, get_afi_safi_str(afi, safi, true),
9802 json_afi_safi);
9803 }
2986cac2 9804 }
9805 }
9806}
9807
36235319
QY
9808static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
9809 struct peer *p,
9810 bool use_json,
9811 json_object *json)
2986cac2 9812{
9813 if (use_json) {
9814 json_object *json_timer = NULL;
9815
9816 json_timer = json_object_new_object();
9817
13909c4f
DS
9818 json_object_int_add(json_timer, "configuredRestartTimer",
9819 p->bgp->restart_time);
2986cac2 9820
13909c4f
DS
9821 json_object_int_add(json_timer, "receivedRestartTimer",
9822 p->v_gr_restart);
2986cac2 9823
13909c4f
DS
9824 if (p->t_gr_restart != NULL)
9825 json_object_int_add(
9826 json_timer, "restartTimerRemaining",
9827 thread_timer_remain_second(p->t_gr_restart));
2986cac2 9828
9829 json_object_object_add(json, "timers", json_timer);
9830 } else {
9831
a53ca37b
DA
9832 vty_out(vty, " Timers:\n");
9833 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 9834 p->bgp->restart_time);
2986cac2 9835
a53ca37b 9836 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
9837 p->v_gr_restart);
9838 if (p->t_gr_restart != NULL)
a53ca37b 9839 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 9840 thread_timer_remain_second(p->t_gr_restart));
36235319 9841 if (p->t_gr_restart != NULL) {
a53ca37b 9842 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
9843 thread_timer_remain_second(p->t_gr_restart));
9844 }
2986cac2 9845 }
9846}
9847
9848static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 9849 bool use_json, json_object *json)
2986cac2 9850{
9851 char buf[SU_ADDRSTRLEN] = {0};
9852 char dn_flag[2] = {0};
9853 char neighborAddr[INET6_ADDRSTRLEN] = {0};
9854
2986cac2 9855 if (!p->conf_if && peer_dynamic_neighbor(p))
9856 dn_flag[0] = '*';
9857
9858 if (p->conf_if) {
9859 if (use_json)
13909c4f
DS
9860 json_object_string_add(
9861 json, "neighborAddr",
2986cac2 9862 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
9863 ? "none"
9864 : sockunion2str(&p->su, buf,
9865 SU_ADDRSTRLEN));
2986cac2 9866 else
13909c4f 9867 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 9868 BGP_PEER_SU_UNSPEC(p)
9869 ? "none"
9870 : sockunion2str(&p->su, buf,
9871 SU_ADDRSTRLEN));
9872 } else {
9873 sprintf(neighborAddr, "%s%s", dn_flag, p->host);
9874
9875 if (use_json)
36235319
QY
9876 json_object_string_add(json, "neighborAddr",
9877 neighborAddr);
2986cac2 9878 else
36235319 9879 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 9880 }
9881
9882 /* more gr info in new format */
9883 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
9884}
9885
d62a17ae 9886static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 9887 safi_t safi, bool use_json,
d62a17ae 9888 json_object *json_neigh)
9889{
0291c246
MK
9890 struct bgp_filter *filter;
9891 struct peer_af *paf;
9892 char orf_pfx_name[BUFSIZ];
9893 int orf_pfx_count;
9894 json_object *json_af = NULL;
9895 json_object *json_prefA = NULL;
9896 json_object *json_prefB = NULL;
9897 json_object *json_addr = NULL;
d62a17ae 9898
9899 if (use_json) {
9900 json_addr = json_object_new_object();
9901 json_af = json_object_new_object();
9902 filter = &p->filter[afi][safi];
9903
9904 if (peer_group_active(p))
9905 json_object_string_add(json_addr, "peerGroupMember",
9906 p->group->name);
9907
9908 paf = peer_af_find(p, afi, safi);
9909 if (paf && PAF_SUBGRP(paf)) {
9910 json_object_int_add(json_addr, "updateGroupId",
9911 PAF_UPDGRP(paf)->id);
9912 json_object_int_add(json_addr, "subGroupId",
9913 PAF_SUBGRP(paf)->id);
9914 json_object_int_add(json_addr, "packetQueueLength",
9915 bpacket_queue_virtual_length(paf));
9916 }
9917
9918 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9919 || CHECK_FLAG(p->af_cap[afi][safi],
9920 PEER_CAP_ORF_PREFIX_SM_RCV)
9921 || CHECK_FLAG(p->af_cap[afi][safi],
9922 PEER_CAP_ORF_PREFIX_RM_ADV)
9923 || CHECK_FLAG(p->af_cap[afi][safi],
9924 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9925 json_object_int_add(json_af, "orfType",
9926 ORF_TYPE_PREFIX);
9927 json_prefA = json_object_new_object();
9928 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
9929 PEER_CAP_ORF_PREFIX_SM_ADV,
9930 PEER_CAP_ORF_PREFIX_RM_ADV,
9931 PEER_CAP_ORF_PREFIX_SM_RCV,
9932 PEER_CAP_ORF_PREFIX_RM_RCV,
9933 use_json, json_prefA);
9934 json_object_object_add(json_af, "orfPrefixList",
9935 json_prefA);
9936 }
9937
9938 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9939 || CHECK_FLAG(p->af_cap[afi][safi],
9940 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9941 || CHECK_FLAG(p->af_cap[afi][safi],
9942 PEER_CAP_ORF_PREFIX_RM_ADV)
9943 || CHECK_FLAG(p->af_cap[afi][safi],
9944 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9945 json_object_int_add(json_af, "orfOldType",
9946 ORF_TYPE_PREFIX_OLD);
9947 json_prefB = json_object_new_object();
9948 bgp_show_peer_afi_orf_cap(
9949 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9950 PEER_CAP_ORF_PREFIX_RM_ADV,
9951 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9952 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
9953 json_prefB);
9954 json_object_object_add(json_af, "orfOldPrefixList",
9955 json_prefB);
9956 }
9957
9958 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9959 || CHECK_FLAG(p->af_cap[afi][safi],
9960 PEER_CAP_ORF_PREFIX_SM_RCV)
9961 || CHECK_FLAG(p->af_cap[afi][safi],
9962 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9963 || CHECK_FLAG(p->af_cap[afi][safi],
9964 PEER_CAP_ORF_PREFIX_RM_ADV)
9965 || CHECK_FLAG(p->af_cap[afi][safi],
9966 PEER_CAP_ORF_PREFIX_RM_RCV)
9967 || CHECK_FLAG(p->af_cap[afi][safi],
9968 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9969 json_object_object_add(json_addr, "afDependentCap",
9970 json_af);
9971 else
9972 json_object_free(json_af);
9973
9974 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9975 orf_pfx_count = prefix_bgp_show_prefix_list(
9976 NULL, afi, orf_pfx_name, use_json);
9977
9978 if (CHECK_FLAG(p->af_sflags[afi][safi],
9979 PEER_STATUS_ORF_PREFIX_SEND)
9980 || orf_pfx_count) {
9981 if (CHECK_FLAG(p->af_sflags[afi][safi],
9982 PEER_STATUS_ORF_PREFIX_SEND))
9983 json_object_boolean_true_add(json_neigh,
9984 "orfSent");
9985 if (orf_pfx_count)
9986 json_object_int_add(json_addr, "orfRecvCounter",
9987 orf_pfx_count);
9988 }
9989 if (CHECK_FLAG(p->af_sflags[afi][safi],
9990 PEER_STATUS_ORF_WAIT_REFRESH))
9991 json_object_string_add(
9992 json_addr, "orfFirstUpdate",
9993 "deferredUntilORFOrRouteRefreshRecvd");
9994
9995 if (CHECK_FLAG(p->af_flags[afi][safi],
9996 PEER_FLAG_REFLECTOR_CLIENT))
9997 json_object_boolean_true_add(json_addr,
9998 "routeReflectorClient");
9999 if (CHECK_FLAG(p->af_flags[afi][safi],
10000 PEER_FLAG_RSERVER_CLIENT))
10001 json_object_boolean_true_add(json_addr,
10002 "routeServerClient");
10003 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10004 json_object_boolean_true_add(json_addr,
10005 "inboundSoftConfigPermit");
10006
10007 if (CHECK_FLAG(p->af_flags[afi][safi],
10008 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10009 json_object_boolean_true_add(
10010 json_addr,
10011 "privateAsNumsAllReplacedInUpdatesToNbr");
10012 else if (CHECK_FLAG(p->af_flags[afi][safi],
10013 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10014 json_object_boolean_true_add(
10015 json_addr,
10016 "privateAsNumsReplacedInUpdatesToNbr");
10017 else if (CHECK_FLAG(p->af_flags[afi][safi],
10018 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10019 json_object_boolean_true_add(
10020 json_addr,
10021 "privateAsNumsAllRemovedInUpdatesToNbr");
10022 else if (CHECK_FLAG(p->af_flags[afi][safi],
10023 PEER_FLAG_REMOVE_PRIVATE_AS))
10024 json_object_boolean_true_add(
10025 json_addr,
10026 "privateAsNumsRemovedInUpdatesToNbr");
10027
dcc68b5e
MS
10028 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10029 json_object_boolean_true_add(
10030 json_addr,
10031 bgp_addpath_names(p->addpath_type[afi][safi])
10032 ->type_json_name);
d62a17ae 10033
10034 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10035 json_object_string_add(json_addr,
10036 "overrideASNsInOutboundUpdates",
10037 "ifAspathEqualRemoteAs");
10038
10039 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10040 || CHECK_FLAG(p->af_flags[afi][safi],
10041 PEER_FLAG_FORCE_NEXTHOP_SELF))
10042 json_object_boolean_true_add(json_addr,
10043 "routerAlwaysNextHop");
10044 if (CHECK_FLAG(p->af_flags[afi][safi],
10045 PEER_FLAG_AS_PATH_UNCHANGED))
10046 json_object_boolean_true_add(
10047 json_addr, "unchangedAsPathPropogatedToNbr");
10048 if (CHECK_FLAG(p->af_flags[afi][safi],
10049 PEER_FLAG_NEXTHOP_UNCHANGED))
10050 json_object_boolean_true_add(
10051 json_addr, "unchangedNextHopPropogatedToNbr");
10052 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10053 json_object_boolean_true_add(
10054 json_addr, "unchangedMedPropogatedToNbr");
10055 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10056 || CHECK_FLAG(p->af_flags[afi][safi],
10057 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10058 if (CHECK_FLAG(p->af_flags[afi][safi],
10059 PEER_FLAG_SEND_COMMUNITY)
10060 && CHECK_FLAG(p->af_flags[afi][safi],
10061 PEER_FLAG_SEND_EXT_COMMUNITY))
10062 json_object_string_add(json_addr,
10063 "commAttriSentToNbr",
10064 "extendedAndStandard");
10065 else if (CHECK_FLAG(p->af_flags[afi][safi],
10066 PEER_FLAG_SEND_EXT_COMMUNITY))
10067 json_object_string_add(json_addr,
10068 "commAttriSentToNbr",
10069 "extended");
10070 else
10071 json_object_string_add(json_addr,
10072 "commAttriSentToNbr",
10073 "standard");
10074 }
10075 if (CHECK_FLAG(p->af_flags[afi][safi],
10076 PEER_FLAG_DEFAULT_ORIGINATE)) {
10077 if (p->default_rmap[afi][safi].name)
10078 json_object_string_add(
10079 json_addr, "defaultRouteMap",
10080 p->default_rmap[afi][safi].name);
10081
10082 if (paf && PAF_SUBGRP(paf)
10083 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10084 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10085 json_object_boolean_true_add(json_addr,
10086 "defaultSent");
10087 else
10088 json_object_boolean_true_add(json_addr,
10089 "defaultNotSent");
10090 }
10091
dff8f48d 10092 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10093 if (is_evpn_enabled())
60466a63
QY
10094 json_object_boolean_true_add(
10095 json_addr, "advertiseAllVnis");
dff8f48d
MK
10096 }
10097
d62a17ae 10098 if (filter->plist[FILTER_IN].name
10099 || filter->dlist[FILTER_IN].name
10100 || filter->aslist[FILTER_IN].name
10101 || filter->map[RMAP_IN].name)
10102 json_object_boolean_true_add(json_addr,
10103 "inboundPathPolicyConfig");
10104 if (filter->plist[FILTER_OUT].name
10105 || filter->dlist[FILTER_OUT].name
10106 || filter->aslist[FILTER_OUT].name
10107 || filter->map[RMAP_OUT].name || filter->usmap.name)
10108 json_object_boolean_true_add(
10109 json_addr, "outboundPathPolicyConfig");
10110
10111 /* prefix-list */
10112 if (filter->plist[FILTER_IN].name)
10113 json_object_string_add(json_addr,
10114 "incomingUpdatePrefixFilterList",
10115 filter->plist[FILTER_IN].name);
10116 if (filter->plist[FILTER_OUT].name)
10117 json_object_string_add(json_addr,
10118 "outgoingUpdatePrefixFilterList",
10119 filter->plist[FILTER_OUT].name);
10120
10121 /* distribute-list */
10122 if (filter->dlist[FILTER_IN].name)
10123 json_object_string_add(
10124 json_addr, "incomingUpdateNetworkFilterList",
10125 filter->dlist[FILTER_IN].name);
10126 if (filter->dlist[FILTER_OUT].name)
10127 json_object_string_add(
10128 json_addr, "outgoingUpdateNetworkFilterList",
10129 filter->dlist[FILTER_OUT].name);
10130
10131 /* filter-list. */
10132 if (filter->aslist[FILTER_IN].name)
10133 json_object_string_add(json_addr,
10134 "incomingUpdateAsPathFilterList",
10135 filter->aslist[FILTER_IN].name);
10136 if (filter->aslist[FILTER_OUT].name)
10137 json_object_string_add(json_addr,
10138 "outgoingUpdateAsPathFilterList",
10139 filter->aslist[FILTER_OUT].name);
10140
10141 /* route-map. */
10142 if (filter->map[RMAP_IN].name)
10143 json_object_string_add(
10144 json_addr, "routeMapForIncomingAdvertisements",
10145 filter->map[RMAP_IN].name);
10146 if (filter->map[RMAP_OUT].name)
10147 json_object_string_add(
10148 json_addr, "routeMapForOutgoingAdvertisements",
10149 filter->map[RMAP_OUT].name);
10150
9dac9fc8
DA
10151 /* ebgp-requires-policy (inbound) */
10152 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10153 && !bgp_inbound_policy_exists(p, filter))
10154 json_object_string_add(
10155 json_addr, "inboundEbgpRequiresPolicy",
10156 "Inbound updates discarded due to missing policy");
10157
10158 /* ebgp-requires-policy (outbound) */
10159 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10160 && (!bgp_outbound_policy_exists(p, filter)))
10161 json_object_string_add(
10162 json_addr, "outboundEbgpRequiresPolicy",
10163 "Outbound updates discarded due to missing policy");
10164
d62a17ae 10165 /* unsuppress-map */
10166 if (filter->usmap.name)
10167 json_object_string_add(json_addr,
10168 "selectiveUnsuppressRouteMap",
10169 filter->usmap.name);
10170
10171 /* Receive prefix count */
10172 json_object_int_add(json_addr, "acceptedPrefixCounter",
10173 p->pcount[afi][safi]);
50e05855
AD
10174 if (paf && PAF_SUBGRP(paf))
10175 json_object_int_add(json_addr, "sentPrefixCounter",
10176 (PAF_SUBGRP(paf))->scount);
d62a17ae 10177
fde246e8
DA
10178 /* Maximum prefix */
10179 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10180 json_object_int_add(json_addr, "prefixOutAllowedMax",
10181 p->pmax_out[afi][safi]);
10182
d62a17ae 10183 /* Maximum prefix */
10184 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10185 json_object_int_add(json_addr, "prefixAllowedMax",
10186 p->pmax[afi][safi]);
10187 if (CHECK_FLAG(p->af_flags[afi][safi],
10188 PEER_FLAG_MAX_PREFIX_WARNING))
10189 json_object_boolean_true_add(
10190 json_addr, "prefixAllowedMaxWarning");
10191 json_object_int_add(json_addr,
10192 "prefixAllowedWarningThresh",
10193 p->pmax_threshold[afi][safi]);
10194 if (p->pmax_restart[afi][safi])
10195 json_object_int_add(
10196 json_addr,
10197 "prefixAllowedRestartIntervalMsecs",
10198 p->pmax_restart[afi][safi] * 60000);
10199 }
2986cac2 10200 json_object_object_add(json_neigh,
36235319 10201 get_afi_safi_str(afi, safi, true),
d62a17ae 10202 json_addr);
10203
10204 } else {
10205 filter = &p->filter[afi][safi];
10206
10207 vty_out(vty, " For address family: %s\n",
5cb5f4d0 10208 get_afi_safi_str(afi, safi, false));
d62a17ae 10209
10210 if (peer_group_active(p))
10211 vty_out(vty, " %s peer-group member\n",
10212 p->group->name);
10213
10214 paf = peer_af_find(p, afi, safi);
10215 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
10216 vty_out(vty, " Update group %" PRIu64
10217 ", subgroup %" PRIu64 "\n",
d62a17ae 10218 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10219 vty_out(vty, " Packet Queue length %d\n",
10220 bpacket_queue_virtual_length(paf));
10221 } else {
10222 vty_out(vty, " Not part of any update group\n");
10223 }
10224 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10225 || CHECK_FLAG(p->af_cap[afi][safi],
10226 PEER_CAP_ORF_PREFIX_SM_RCV)
10227 || CHECK_FLAG(p->af_cap[afi][safi],
10228 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10229 || CHECK_FLAG(p->af_cap[afi][safi],
10230 PEER_CAP_ORF_PREFIX_RM_ADV)
10231 || CHECK_FLAG(p->af_cap[afi][safi],
10232 PEER_CAP_ORF_PREFIX_RM_RCV)
10233 || CHECK_FLAG(p->af_cap[afi][safi],
10234 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10235 vty_out(vty, " AF-dependant capabilities:\n");
10236
10237 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10238 || CHECK_FLAG(p->af_cap[afi][safi],
10239 PEER_CAP_ORF_PREFIX_SM_RCV)
10240 || CHECK_FLAG(p->af_cap[afi][safi],
10241 PEER_CAP_ORF_PREFIX_RM_ADV)
10242 || CHECK_FLAG(p->af_cap[afi][safi],
10243 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10244 vty_out(vty,
10245 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10246 ORF_TYPE_PREFIX);
10247 bgp_show_peer_afi_orf_cap(
10248 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10249 PEER_CAP_ORF_PREFIX_RM_ADV,
10250 PEER_CAP_ORF_PREFIX_SM_RCV,
10251 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10252 }
10253 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10254 || CHECK_FLAG(p->af_cap[afi][safi],
10255 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10256 || CHECK_FLAG(p->af_cap[afi][safi],
10257 PEER_CAP_ORF_PREFIX_RM_ADV)
10258 || CHECK_FLAG(p->af_cap[afi][safi],
10259 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10260 vty_out(vty,
10261 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10262 ORF_TYPE_PREFIX_OLD);
10263 bgp_show_peer_afi_orf_cap(
10264 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10265 PEER_CAP_ORF_PREFIX_RM_ADV,
10266 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10267 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10268 }
10269
10270 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
10271 orf_pfx_count = prefix_bgp_show_prefix_list(
10272 NULL, afi, orf_pfx_name, use_json);
10273
10274 if (CHECK_FLAG(p->af_sflags[afi][safi],
10275 PEER_STATUS_ORF_PREFIX_SEND)
10276 || orf_pfx_count) {
10277 vty_out(vty, " Outbound Route Filter (ORF):");
10278 if (CHECK_FLAG(p->af_sflags[afi][safi],
10279 PEER_STATUS_ORF_PREFIX_SEND))
10280 vty_out(vty, " sent;");
10281 if (orf_pfx_count)
10282 vty_out(vty, " received (%d entries)",
10283 orf_pfx_count);
10284 vty_out(vty, "\n");
10285 }
10286 if (CHECK_FLAG(p->af_sflags[afi][safi],
10287 PEER_STATUS_ORF_WAIT_REFRESH))
10288 vty_out(vty,
10289 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10290
10291 if (CHECK_FLAG(p->af_flags[afi][safi],
10292 PEER_FLAG_REFLECTOR_CLIENT))
10293 vty_out(vty, " Route-Reflector Client\n");
10294 if (CHECK_FLAG(p->af_flags[afi][safi],
10295 PEER_FLAG_RSERVER_CLIENT))
10296 vty_out(vty, " Route-Server Client\n");
10297 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10298 vty_out(vty,
10299 " Inbound soft reconfiguration allowed\n");
10300
10301 if (CHECK_FLAG(p->af_flags[afi][safi],
10302 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10303 vty_out(vty,
10304 " Private AS numbers (all) replaced in updates to this neighbor\n");
10305 else if (CHECK_FLAG(p->af_flags[afi][safi],
10306 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10307 vty_out(vty,
10308 " Private AS numbers replaced in updates to this neighbor\n");
10309 else if (CHECK_FLAG(p->af_flags[afi][safi],
10310 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10311 vty_out(vty,
10312 " Private AS numbers (all) removed in updates to this neighbor\n");
10313 else if (CHECK_FLAG(p->af_flags[afi][safi],
10314 PEER_FLAG_REMOVE_PRIVATE_AS))
10315 vty_out(vty,
10316 " Private AS numbers removed in updates to this neighbor\n");
10317
dcc68b5e
MS
10318 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10319 vty_out(vty, " %s\n",
10320 bgp_addpath_names(p->addpath_type[afi][safi])
10321 ->human_description);
d62a17ae 10322
10323 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10324 vty_out(vty,
10325 " Override ASNs in outbound updates if aspath equals remote-as\n");
10326
10327 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10328 || CHECK_FLAG(p->af_flags[afi][safi],
10329 PEER_FLAG_FORCE_NEXTHOP_SELF))
10330 vty_out(vty, " NEXT_HOP is always this router\n");
10331 if (CHECK_FLAG(p->af_flags[afi][safi],
10332 PEER_FLAG_AS_PATH_UNCHANGED))
10333 vty_out(vty,
10334 " AS_PATH is propagated unchanged to this neighbor\n");
10335 if (CHECK_FLAG(p->af_flags[afi][safi],
10336 PEER_FLAG_NEXTHOP_UNCHANGED))
10337 vty_out(vty,
10338 " NEXT_HOP is propagated unchanged to this neighbor\n");
10339 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10340 vty_out(vty,
10341 " MED is propagated unchanged to this neighbor\n");
10342 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10343 || CHECK_FLAG(p->af_flags[afi][safi],
10344 PEER_FLAG_SEND_EXT_COMMUNITY)
10345 || CHECK_FLAG(p->af_flags[afi][safi],
10346 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10347 vty_out(vty,
10348 " Community attribute sent to this neighbor");
10349 if (CHECK_FLAG(p->af_flags[afi][safi],
10350 PEER_FLAG_SEND_COMMUNITY)
10351 && CHECK_FLAG(p->af_flags[afi][safi],
10352 PEER_FLAG_SEND_EXT_COMMUNITY)
10353 && CHECK_FLAG(p->af_flags[afi][safi],
10354 PEER_FLAG_SEND_LARGE_COMMUNITY))
10355 vty_out(vty, "(all)\n");
10356 else if (CHECK_FLAG(p->af_flags[afi][safi],
10357 PEER_FLAG_SEND_LARGE_COMMUNITY))
10358 vty_out(vty, "(large)\n");
10359 else if (CHECK_FLAG(p->af_flags[afi][safi],
10360 PEER_FLAG_SEND_EXT_COMMUNITY))
10361 vty_out(vty, "(extended)\n");
10362 else
10363 vty_out(vty, "(standard)\n");
10364 }
10365 if (CHECK_FLAG(p->af_flags[afi][safi],
10366 PEER_FLAG_DEFAULT_ORIGINATE)) {
10367 vty_out(vty, " Default information originate,");
10368
10369 if (p->default_rmap[afi][safi].name)
10370 vty_out(vty, " default route-map %s%s,",
10371 p->default_rmap[afi][safi].map ? "*"
10372 : "",
10373 p->default_rmap[afi][safi].name);
10374 if (paf && PAF_SUBGRP(paf)
10375 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10376 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10377 vty_out(vty, " default sent\n");
10378 else
10379 vty_out(vty, " default not sent\n");
10380 }
10381
dff8f48d
MK
10382 /* advertise-vni-all */
10383 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10384 if (is_evpn_enabled())
dff8f48d
MK
10385 vty_out(vty, " advertise-all-vni\n");
10386 }
10387
d62a17ae 10388 if (filter->plist[FILTER_IN].name
10389 || filter->dlist[FILTER_IN].name
10390 || filter->aslist[FILTER_IN].name
10391 || filter->map[RMAP_IN].name)
10392 vty_out(vty, " Inbound path policy configured\n");
10393 if (filter->plist[FILTER_OUT].name
10394 || filter->dlist[FILTER_OUT].name
10395 || filter->aslist[FILTER_OUT].name
10396 || filter->map[RMAP_OUT].name || filter->usmap.name)
10397 vty_out(vty, " Outbound path policy configured\n");
10398
10399 /* prefix-list */
10400 if (filter->plist[FILTER_IN].name)
10401 vty_out(vty,
10402 " Incoming update prefix filter list is %s%s\n",
10403 filter->plist[FILTER_IN].plist ? "*" : "",
10404 filter->plist[FILTER_IN].name);
10405 if (filter->plist[FILTER_OUT].name)
10406 vty_out(vty,
10407 " Outgoing update prefix filter list is %s%s\n",
10408 filter->plist[FILTER_OUT].plist ? "*" : "",
10409 filter->plist[FILTER_OUT].name);
10410
10411 /* distribute-list */
10412 if (filter->dlist[FILTER_IN].name)
10413 vty_out(vty,
10414 " Incoming update network filter list is %s%s\n",
10415 filter->dlist[FILTER_IN].alist ? "*" : "",
10416 filter->dlist[FILTER_IN].name);
10417 if (filter->dlist[FILTER_OUT].name)
10418 vty_out(vty,
10419 " Outgoing update network filter list is %s%s\n",
10420 filter->dlist[FILTER_OUT].alist ? "*" : "",
10421 filter->dlist[FILTER_OUT].name);
10422
10423 /* filter-list. */
10424 if (filter->aslist[FILTER_IN].name)
10425 vty_out(vty,
10426 " Incoming update AS path filter list is %s%s\n",
10427 filter->aslist[FILTER_IN].aslist ? "*" : "",
10428 filter->aslist[FILTER_IN].name);
10429 if (filter->aslist[FILTER_OUT].name)
10430 vty_out(vty,
10431 " Outgoing update AS path filter list is %s%s\n",
10432 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10433 filter->aslist[FILTER_OUT].name);
10434
10435 /* route-map. */
10436 if (filter->map[RMAP_IN].name)
10437 vty_out(vty,
10438 " Route map for incoming advertisements is %s%s\n",
10439 filter->map[RMAP_IN].map ? "*" : "",
10440 filter->map[RMAP_IN].name);
10441 if (filter->map[RMAP_OUT].name)
10442 vty_out(vty,
10443 " Route map for outgoing advertisements is %s%s\n",
10444 filter->map[RMAP_OUT].map ? "*" : "",
10445 filter->map[RMAP_OUT].name);
10446
9dac9fc8
DA
10447 /* ebgp-requires-policy (inbound) */
10448 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10449 && !bgp_inbound_policy_exists(p, filter))
10450 vty_out(vty,
10451 " Inbound updates discarded due to missing policy\n");
10452
10453 /* ebgp-requires-policy (outbound) */
10454 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10455 && !bgp_outbound_policy_exists(p, filter))
10456 vty_out(vty,
10457 " Outbound updates discarded due to missing policy\n");
10458
d62a17ae 10459 /* unsuppress-map */
10460 if (filter->usmap.name)
10461 vty_out(vty,
10462 " Route map for selective unsuppress is %s%s\n",
10463 filter->usmap.map ? "*" : "",
10464 filter->usmap.name);
10465
10466 /* Receive prefix count */
a0a87037
DA
10467 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
10468 p->pcount[afi][safi]);
d62a17ae 10469
fde246e8
DA
10470 /* maximum-prefix-out */
10471 if (CHECK_FLAG(p->af_flags[afi][safi],
10472 PEER_FLAG_MAX_PREFIX_OUT))
10473 vty_out(vty,
10474 " Maximum allowed prefixes sent %" PRIu32 "\n",
10475 p->pmax_out[afi][safi]);
10476
d62a17ae 10477 /* Maximum prefix */
10478 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037
DA
10479 vty_out(vty,
10480 " Maximum prefixes allowed %" PRIu32 "%s\n",
d62a17ae 10481 p->pmax[afi][safi],
10482 CHECK_FLAG(p->af_flags[afi][safi],
10483 PEER_FLAG_MAX_PREFIX_WARNING)
10484 ? " (warning-only)"
10485 : "");
10486 vty_out(vty, " Threshold for warning message %d%%",
10487 p->pmax_threshold[afi][safi]);
10488 if (p->pmax_restart[afi][safi])
10489 vty_out(vty, ", restart interval %d min",
10490 p->pmax_restart[afi][safi]);
10491 vty_out(vty, "\n");
10492 }
10493
10494 vty_out(vty, "\n");
10495 }
10496}
10497
9f049418 10498static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 10499 json_object *json)
718e3744 10500{
d62a17ae 10501 struct bgp *bgp;
10502 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
10503 char timebuf[BGP_UPTIME_LEN];
10504 char dn_flag[2];
d62a17ae 10505 afi_t afi;
10506 safi_t safi;
d7c0a89a
QY
10507 uint16_t i;
10508 uint8_t *msg;
d62a17ae 10509 json_object *json_neigh = NULL;
10510 time_t epoch_tbuf;
718e3744 10511
d62a17ae 10512 bgp = p->bgp;
10513
10514 if (use_json)
10515 json_neigh = json_object_new_object();
10516
10517 memset(dn_flag, '\0', sizeof(dn_flag));
10518 if (!p->conf_if && peer_dynamic_neighbor(p))
10519 dn_flag[0] = '*';
10520
10521 if (!use_json) {
10522 if (p->conf_if) /* Configured interface name. */
10523 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
10524 BGP_PEER_SU_UNSPEC(p)
10525 ? "None"
10526 : sockunion2str(&p->su, buf,
10527 SU_ADDRSTRLEN));
10528 else /* Configured IP address. */
10529 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
10530 p->host);
10531 }
10532
10533 if (use_json) {
10534 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
10535 json_object_string_add(json_neigh, "bgpNeighborAddr",
10536 "none");
10537 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
10538 json_object_string_add(
10539 json_neigh, "bgpNeighborAddr",
10540 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
10541
10542 json_object_int_add(json_neigh, "remoteAs", p->as);
10543
10544 if (p->change_local_as)
10545 json_object_int_add(json_neigh, "localAs",
10546 p->change_local_as);
10547 else
10548 json_object_int_add(json_neigh, "localAs", p->local_as);
10549
10550 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
10551 json_object_boolean_true_add(json_neigh,
10552 "localAsNoPrepend");
10553
10554 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
10555 json_object_boolean_true_add(json_neigh,
10556 "localAsReplaceAs");
10557 } else {
10558 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
10559 || (p->as_type == AS_INTERNAL))
10560 vty_out(vty, "remote AS %u, ", p->as);
10561 else
10562 vty_out(vty, "remote AS Unspecified, ");
10563 vty_out(vty, "local AS %u%s%s, ",
10564 p->change_local_as ? p->change_local_as : p->local_as,
10565 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
10566 ? " no-prepend"
10567 : "",
10568 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
10569 ? " replace-as"
10570 : "");
10571 }
faa16034
DS
10572 /* peer type internal or confed-internal */
10573 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 10574 if (use_json) {
10575 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10576 json_object_boolean_true_add(
10577 json_neigh, "nbrConfedInternalLink");
10578 else
10579 json_object_boolean_true_add(json_neigh,
10580 "nbrInternalLink");
10581 } else {
10582 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10583 vty_out(vty, "confed-internal link\n");
10584 else
10585 vty_out(vty, "internal link\n");
10586 }
faa16034
DS
10587 /* peer type external or confed-external */
10588 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 10589 if (use_json) {
10590 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10591 json_object_boolean_true_add(
10592 json_neigh, "nbrConfedExternalLink");
10593 else
10594 json_object_boolean_true_add(json_neigh,
10595 "nbrExternalLink");
10596 } else {
10597 if (bgp_confederation_peers_check(bgp, p->as))
10598 vty_out(vty, "confed-external link\n");
10599 else
10600 vty_out(vty, "external link\n");
10601 }
faa16034
DS
10602 } else {
10603 if (use_json)
10604 json_object_boolean_true_add(json_neigh,
10605 "nbrUnspecifiedLink");
10606 else
10607 vty_out(vty, "unspecified link\n");
d62a17ae 10608 }
10609
10610 /* Description. */
10611 if (p->desc) {
10612 if (use_json)
10613 json_object_string_add(json_neigh, "nbrDesc", p->desc);
10614 else
10615 vty_out(vty, " Description: %s\n", p->desc);
10616 }
10617
10618 if (p->hostname) {
10619 if (use_json) {
10620 if (p->hostname)
10621 json_object_string_add(json_neigh, "hostname",
10622 p->hostname);
10623
10624 if (p->domainname)
10625 json_object_string_add(json_neigh, "domainname",
10626 p->domainname);
10627 } else {
10628 if (p->domainname && (p->domainname[0] != '\0'))
10629 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
10630 p->domainname);
10631 else
10632 vty_out(vty, "Hostname: %s\n", p->hostname);
10633 }
10634 }
10635
10636 /* Peer-group */
10637 if (p->group) {
10638 if (use_json) {
10639 json_object_string_add(json_neigh, "peerGroup",
10640 p->group->name);
10641
10642 if (dn_flag[0]) {
10643 struct prefix prefix, *range = NULL;
10644
10645 sockunion2hostprefix(&(p->su), &prefix);
10646 range = peer_group_lookup_dynamic_neighbor_range(
10647 p->group, &prefix);
10648
10649 if (range) {
10650 prefix2str(range, buf1, sizeof(buf1));
10651 json_object_string_add(
10652 json_neigh,
10653 "peerSubnetRangeGroup", buf1);
10654 }
10655 }
10656 } else {
10657 vty_out(vty,
10658 " Member of peer-group %s for session parameters\n",
10659 p->group->name);
10660
10661 if (dn_flag[0]) {
10662 struct prefix prefix, *range = NULL;
10663
10664 sockunion2hostprefix(&(p->su), &prefix);
10665 range = peer_group_lookup_dynamic_neighbor_range(
10666 p->group, &prefix);
10667
10668 if (range) {
10669 prefix2str(range, buf1, sizeof(buf1));
10670 vty_out(vty,
10671 " Belongs to the subnet range group: %s\n",
10672 buf1);
10673 }
10674 }
10675 }
10676 }
10677
10678 if (use_json) {
10679 /* Administrative shutdown. */
10680 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10681 json_object_boolean_true_add(json_neigh,
10682 "adminShutDown");
10683
10684 /* BGP Version. */
10685 json_object_int_add(json_neigh, "bgpVersion", 4);
10686 json_object_string_add(
10687 json_neigh, "remoteRouterId",
10688 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
10689 json_object_string_add(
10690 json_neigh, "localRouterId",
10691 inet_ntop(AF_INET, &bgp->router_id, buf1,
10692 sizeof(buf1)));
d62a17ae 10693
10694 /* Confederation */
10695 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10696 && bgp_confederation_peers_check(bgp, p->as))
10697 json_object_boolean_true_add(json_neigh,
10698 "nbrCommonAdmin");
10699
10700 /* Status. */
10701 json_object_string_add(
10702 json_neigh, "bgpState",
10703 lookup_msg(bgp_status_msg, p->status, NULL));
10704
10705 if (p->status == Established) {
10706 time_t uptime;
d62a17ae 10707
10708 uptime = bgp_clock();
10709 uptime -= p->uptime;
d62a17ae 10710 epoch_tbuf = time(NULL) - uptime;
10711
d3c7efed
DS
10712 json_object_int_add(json_neigh, "bgpTimerUpMsec",
10713 uptime * 1000);
d62a17ae 10714 json_object_string_add(json_neigh, "bgpTimerUpString",
10715 peer_uptime(p->uptime, timebuf,
10716 BGP_UPTIME_LEN, 0,
10717 NULL));
10718 json_object_int_add(json_neigh,
10719 "bgpTimerUpEstablishedEpoch",
10720 epoch_tbuf);
10721 }
10722
10723 else if (p->status == Active) {
10724 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10725 json_object_string_add(json_neigh, "bgpStateIs",
10726 "passive");
10727 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10728 json_object_string_add(json_neigh, "bgpStateIs",
10729 "passiveNSF");
10730 }
10731
10732 /* read timer */
10733 time_t uptime;
a2700b50 10734 struct tm tm;
d62a17ae 10735
10736 uptime = bgp_clock();
10737 uptime -= p->readtime;
a2700b50
MS
10738 gmtime_r(&uptime, &tm);
10739
d62a17ae 10740 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
10741 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
10742 + (tm.tm_hour * 3600000));
d62a17ae 10743
10744 uptime = bgp_clock();
10745 uptime -= p->last_write;
a2700b50
MS
10746 gmtime_r(&uptime, &tm);
10747
d62a17ae 10748 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
10749 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
10750 + (tm.tm_hour * 3600000));
d62a17ae 10751
10752 uptime = bgp_clock();
10753 uptime -= p->update_time;
a2700b50
MS
10754 gmtime_r(&uptime, &tm);
10755
d62a17ae 10756 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
10757 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
10758 + (tm.tm_hour * 3600000));
d62a17ae 10759
10760 /* Configured timer values. */
10761 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
10762 p->v_holdtime * 1000);
10763 json_object_int_add(json_neigh,
10764 "bgpTimerKeepAliveIntervalMsecs",
10765 p->v_keepalive * 1000);
b90a8e13 10766 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 10767 json_object_int_add(json_neigh,
10768 "bgpTimerConfiguredHoldTimeMsecs",
10769 p->holdtime * 1000);
10770 json_object_int_add(
10771 json_neigh,
10772 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10773 p->keepalive * 1000);
5d5393b9
DL
10774 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10775 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
10776 json_object_int_add(json_neigh,
10777 "bgpTimerConfiguredHoldTimeMsecs",
10778 bgp->default_holdtime);
10779 json_object_int_add(
10780 json_neigh,
10781 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10782 bgp->default_keepalive);
d62a17ae 10783 }
10784 } else {
10785 /* Administrative shutdown. */
10786 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10787 vty_out(vty, " Administratively shut down\n");
10788
10789 /* BGP Version. */
10790 vty_out(vty, " BGP version 4");
0e38aeb4 10791 vty_out(vty, ", remote router ID %s",
d62a17ae 10792 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
10793 vty_out(vty, ", local router ID %s\n",
10794 inet_ntop(AF_INET, &bgp->router_id, buf1,
10795 sizeof(buf1)));
d62a17ae 10796
10797 /* Confederation */
10798 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10799 && bgp_confederation_peers_check(bgp, p->as))
10800 vty_out(vty,
10801 " Neighbor under common administration\n");
10802
10803 /* Status. */
10804 vty_out(vty, " BGP state = %s",
10805 lookup_msg(bgp_status_msg, p->status, NULL));
10806
10807 if (p->status == Established)
10808 vty_out(vty, ", up for %8s",
10809 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
10810 0, NULL));
10811
10812 else if (p->status == Active) {
10813 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10814 vty_out(vty, " (passive)");
10815 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10816 vty_out(vty, " (NSF passive)");
10817 }
10818 vty_out(vty, "\n");
10819
10820 /* read timer */
10821 vty_out(vty, " Last read %s",
10822 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
10823 NULL));
10824 vty_out(vty, ", Last write %s\n",
10825 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
10826 NULL));
10827
10828 /* Configured timer values. */
10829 vty_out(vty,
10830 " Hold time is %d, keepalive interval is %d seconds\n",
10831 p->v_holdtime, p->v_keepalive);
b90a8e13 10832 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 10833 vty_out(vty, " Configured hold time is %d",
10834 p->holdtime);
10835 vty_out(vty, ", keepalive interval is %d seconds\n",
10836 p->keepalive);
5d5393b9
DL
10837 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10838 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
10839 vty_out(vty, " Configured hold time is %d",
10840 bgp->default_holdtime);
10841 vty_out(vty, ", keepalive interval is %d seconds\n",
10842 bgp->default_keepalive);
d62a17ae 10843 }
10844 }
10845 /* Capability. */
10846 if (p->status == Established) {
10847 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
10848 || p->afc_recv[AFI_IP][SAFI_UNICAST]
10849 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
10850 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
10851 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
10852 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
10853 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
10854 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
10855 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
10856 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
10857 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
10858 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 10859 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
10860 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 10861 || p->afc_adv[AFI_IP][SAFI_ENCAP]
10862 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 10863 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
10864 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 10865 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
10866 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
10867 if (use_json) {
10868 json_object *json_cap = NULL;
10869
10870 json_cap = json_object_new_object();
10871
10872 /* AS4 */
10873 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10874 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10875 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
10876 && CHECK_FLAG(p->cap,
10877 PEER_CAP_AS4_RCV))
10878 json_object_string_add(
10879 json_cap, "4byteAs",
10880 "advertisedAndReceived");
10881 else if (CHECK_FLAG(p->cap,
10882 PEER_CAP_AS4_ADV))
10883 json_object_string_add(
10884 json_cap, "4byteAs",
10885 "advertised");
10886 else if (CHECK_FLAG(p->cap,
10887 PEER_CAP_AS4_RCV))
10888 json_object_string_add(
10889 json_cap, "4byteAs",
10890 "received");
10891 }
10892
10893 /* AddPath */
10894 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10895 || CHECK_FLAG(p->cap,
10896 PEER_CAP_ADDPATH_ADV)) {
10897 json_object *json_add = NULL;
10898 const char *print_store;
10899
10900 json_add = json_object_new_object();
10901
05c7a1cc
QY
10902 FOREACH_AFI_SAFI (afi, safi) {
10903 json_object *json_sub = NULL;
10904 json_sub =
10905 json_object_new_object();
5cb5f4d0
DD
10906 print_store = get_afi_safi_str(
10907 afi, safi, true);
d62a17ae 10908
05c7a1cc
QY
10909 if (CHECK_FLAG(
10910 p->af_cap[afi]
10911 [safi],
10912 PEER_CAP_ADDPATH_AF_TX_ADV)
10913 || CHECK_FLAG(
10914 p->af_cap[afi]
10915 [safi],
10916 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 10917 if (CHECK_FLAG(
10918 p->af_cap
10919 [afi]
10920 [safi],
10921 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 10922 && CHECK_FLAG(
d62a17ae 10923 p->af_cap
10924 [afi]
10925 [safi],
05c7a1cc
QY
10926 PEER_CAP_ADDPATH_AF_TX_RCV))
10927 json_object_boolean_true_add(
10928 json_sub,
10929 "txAdvertisedAndReceived");
10930 else if (
10931 CHECK_FLAG(
10932 p->af_cap
10933 [afi]
10934 [safi],
10935 PEER_CAP_ADDPATH_AF_TX_ADV))
10936 json_object_boolean_true_add(
10937 json_sub,
10938 "txAdvertised");
10939 else if (
10940 CHECK_FLAG(
10941 p->af_cap
10942 [afi]
10943 [safi],
10944 PEER_CAP_ADDPATH_AF_TX_RCV))
10945 json_object_boolean_true_add(
10946 json_sub,
10947 "txReceived");
10948 }
d62a17ae 10949
05c7a1cc
QY
10950 if (CHECK_FLAG(
10951 p->af_cap[afi]
10952 [safi],
10953 PEER_CAP_ADDPATH_AF_RX_ADV)
10954 || CHECK_FLAG(
10955 p->af_cap[afi]
10956 [safi],
10957 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 10958 if (CHECK_FLAG(
10959 p->af_cap
10960 [afi]
10961 [safi],
10962 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 10963 && CHECK_FLAG(
d62a17ae 10964 p->af_cap
10965 [afi]
10966 [safi],
10967 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
10968 json_object_boolean_true_add(
10969 json_sub,
10970 "rxAdvertisedAndReceived");
10971 else if (
10972 CHECK_FLAG(
10973 p->af_cap
10974 [afi]
10975 [safi],
10976 PEER_CAP_ADDPATH_AF_RX_ADV))
10977 json_object_boolean_true_add(
10978 json_sub,
10979 "rxAdvertised");
10980 else if (
10981 CHECK_FLAG(
10982 p->af_cap
10983 [afi]
10984 [safi],
10985 PEER_CAP_ADDPATH_AF_RX_RCV))
10986 json_object_boolean_true_add(
10987 json_sub,
10988 "rxReceived");
d62a17ae 10989 }
10990
05c7a1cc
QY
10991 if (CHECK_FLAG(
10992 p->af_cap[afi]
10993 [safi],
10994 PEER_CAP_ADDPATH_AF_TX_ADV)
10995 || CHECK_FLAG(
10996 p->af_cap[afi]
10997 [safi],
10998 PEER_CAP_ADDPATH_AF_TX_RCV)
10999 || CHECK_FLAG(
11000 p->af_cap[afi]
11001 [safi],
11002 PEER_CAP_ADDPATH_AF_RX_ADV)
11003 || CHECK_FLAG(
11004 p->af_cap[afi]
11005 [safi],
11006 PEER_CAP_ADDPATH_AF_RX_RCV))
11007 json_object_object_add(
11008 json_add,
11009 print_store,
11010 json_sub);
11011 else
11012 json_object_free(
11013 json_sub);
11014 }
11015
d62a17ae 11016 json_object_object_add(
11017 json_cap, "addPath", json_add);
11018 }
11019
11020 /* Dynamic */
11021 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11022 || CHECK_FLAG(p->cap,
11023 PEER_CAP_DYNAMIC_ADV)) {
11024 if (CHECK_FLAG(p->cap,
11025 PEER_CAP_DYNAMIC_ADV)
11026 && CHECK_FLAG(p->cap,
11027 PEER_CAP_DYNAMIC_RCV))
11028 json_object_string_add(
11029 json_cap, "dynamic",
11030 "advertisedAndReceived");
11031 else if (CHECK_FLAG(
11032 p->cap,
11033 PEER_CAP_DYNAMIC_ADV))
11034 json_object_string_add(
11035 json_cap, "dynamic",
11036 "advertised");
11037 else if (CHECK_FLAG(
11038 p->cap,
11039 PEER_CAP_DYNAMIC_RCV))
11040 json_object_string_add(
11041 json_cap, "dynamic",
11042 "received");
11043 }
11044
11045 /* Extended nexthop */
11046 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11047 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11048 json_object *json_nxt = NULL;
11049 const char *print_store;
11050
11051
11052 if (CHECK_FLAG(p->cap,
11053 PEER_CAP_ENHE_ADV)
11054 && CHECK_FLAG(p->cap,
11055 PEER_CAP_ENHE_RCV))
11056 json_object_string_add(
11057 json_cap,
11058 "extendedNexthop",
11059 "advertisedAndReceived");
11060 else if (CHECK_FLAG(p->cap,
11061 PEER_CAP_ENHE_ADV))
11062 json_object_string_add(
11063 json_cap,
11064 "extendedNexthop",
11065 "advertised");
11066 else if (CHECK_FLAG(p->cap,
11067 PEER_CAP_ENHE_RCV))
11068 json_object_string_add(
11069 json_cap,
11070 "extendedNexthop",
11071 "received");
11072
11073 if (CHECK_FLAG(p->cap,
11074 PEER_CAP_ENHE_RCV)) {
11075 json_nxt =
11076 json_object_new_object();
11077
11078 for (safi = SAFI_UNICAST;
11079 safi < SAFI_MAX; safi++) {
11080 if (CHECK_FLAG(
11081 p->af_cap
11082 [AFI_IP]
11083 [safi],
11084 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 11085 print_store = get_afi_safi_str(
d62a17ae 11086 AFI_IP,
5cb5f4d0 11087 safi, true);
d62a17ae 11088 json_object_string_add(
11089 json_nxt,
11090 print_store,
54f29523 11091 "recieved"); /* misspelled for compatibility */
d62a17ae 11092 }
11093 }
11094 json_object_object_add(
11095 json_cap,
11096 "extendedNexthopFamililesByPeer",
11097 json_nxt);
11098 }
11099 }
11100
11101 /* Route Refresh */
11102 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11103 || CHECK_FLAG(p->cap,
11104 PEER_CAP_REFRESH_NEW_RCV)
11105 || CHECK_FLAG(p->cap,
11106 PEER_CAP_REFRESH_OLD_RCV)) {
11107 if (CHECK_FLAG(p->cap,
11108 PEER_CAP_REFRESH_ADV)
11109 && (CHECK_FLAG(
11110 p->cap,
11111 PEER_CAP_REFRESH_NEW_RCV)
11112 || CHECK_FLAG(
11113 p->cap,
11114 PEER_CAP_REFRESH_OLD_RCV))) {
11115 if (CHECK_FLAG(
11116 p->cap,
11117 PEER_CAP_REFRESH_OLD_RCV)
11118 && CHECK_FLAG(
11119 p->cap,
11120 PEER_CAP_REFRESH_NEW_RCV))
11121 json_object_string_add(
11122 json_cap,
11123 "routeRefresh",
11124 "advertisedAndReceivedOldNew");
11125 else {
11126 if (CHECK_FLAG(
11127 p->cap,
11128 PEER_CAP_REFRESH_OLD_RCV))
11129 json_object_string_add(
11130 json_cap,
11131 "routeRefresh",
11132 "advertisedAndReceivedOld");
11133 else
11134 json_object_string_add(
11135 json_cap,
11136 "routeRefresh",
11137 "advertisedAndReceivedNew");
11138 }
11139 } else if (
11140 CHECK_FLAG(
11141 p->cap,
11142 PEER_CAP_REFRESH_ADV))
11143 json_object_string_add(
11144 json_cap,
11145 "routeRefresh",
11146 "advertised");
11147 else if (
11148 CHECK_FLAG(
11149 p->cap,
11150 PEER_CAP_REFRESH_NEW_RCV)
11151 || CHECK_FLAG(
11152 p->cap,
11153 PEER_CAP_REFRESH_OLD_RCV))
11154 json_object_string_add(
11155 json_cap,
11156 "routeRefresh",
11157 "received");
11158 }
11159
11160 /* Multiprotocol Extensions */
11161 json_object *json_multi = NULL;
11162 json_multi = json_object_new_object();
11163
05c7a1cc
QY
11164 FOREACH_AFI_SAFI (afi, safi) {
11165 if (p->afc_adv[afi][safi]
11166 || p->afc_recv[afi][safi]) {
11167 json_object *json_exten = NULL;
11168 json_exten =
11169 json_object_new_object();
11170
d62a17ae 11171 if (p->afc_adv[afi][safi]
05c7a1cc
QY
11172 && p->afc_recv[afi][safi])
11173 json_object_boolean_true_add(
11174 json_exten,
11175 "advertisedAndReceived");
11176 else if (p->afc_adv[afi][safi])
11177 json_object_boolean_true_add(
11178 json_exten,
11179 "advertised");
11180 else if (p->afc_recv[afi][safi])
11181 json_object_boolean_true_add(
11182 json_exten,
11183 "received");
d62a17ae 11184
05c7a1cc
QY
11185 json_object_object_add(
11186 json_multi,
5cb5f4d0
DD
11187 get_afi_safi_str(afi,
11188 safi,
11189 true),
05c7a1cc 11190 json_exten);
d62a17ae 11191 }
11192 }
11193 json_object_object_add(
11194 json_cap, "multiprotocolExtensions",
11195 json_multi);
11196
d77114b7 11197 /* Hostname capabilities */
60466a63 11198 json_object *json_hname = NULL;
d77114b7
MK
11199
11200 json_hname = json_object_new_object();
11201
11202 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11203 json_object_string_add(
60466a63
QY
11204 json_hname, "advHostName",
11205 bgp->peer_self->hostname
11206 ? bgp->peer_self
11207 ->hostname
d77114b7
MK
11208 : "n/a");
11209 json_object_string_add(
60466a63
QY
11210 json_hname, "advDomainName",
11211 bgp->peer_self->domainname
11212 ? bgp->peer_self
11213 ->domainname
d77114b7
MK
11214 : "n/a");
11215 }
11216
11217
11218 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11219 json_object_string_add(
60466a63
QY
11220 json_hname, "rcvHostName",
11221 p->hostname ? p->hostname
11222 : "n/a");
d77114b7 11223 json_object_string_add(
60466a63
QY
11224 json_hname, "rcvDomainName",
11225 p->domainname ? p->domainname
11226 : "n/a");
d77114b7
MK
11227 }
11228
60466a63 11229 json_object_object_add(json_cap, "hostName",
d77114b7
MK
11230 json_hname);
11231
d62a17ae 11232 /* Gracefull Restart */
11233 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11234 || CHECK_FLAG(p->cap,
11235 PEER_CAP_RESTART_ADV)) {
11236 if (CHECK_FLAG(p->cap,
11237 PEER_CAP_RESTART_ADV)
11238 && CHECK_FLAG(p->cap,
11239 PEER_CAP_RESTART_RCV))
11240 json_object_string_add(
11241 json_cap,
11242 "gracefulRestart",
11243 "advertisedAndReceived");
11244 else if (CHECK_FLAG(
11245 p->cap,
11246 PEER_CAP_RESTART_ADV))
11247 json_object_string_add(
11248 json_cap,
11249 "gracefulRestartCapability",
11250 "advertised");
11251 else if (CHECK_FLAG(
11252 p->cap,
11253 PEER_CAP_RESTART_RCV))
11254 json_object_string_add(
11255 json_cap,
11256 "gracefulRestartCapability",
11257 "received");
11258
11259 if (CHECK_FLAG(p->cap,
11260 PEER_CAP_RESTART_RCV)) {
11261 int restart_af_count = 0;
11262 json_object *json_restart =
11263 NULL;
11264 json_restart =
11265 json_object_new_object();
11266
11267 json_object_int_add(
11268 json_cap,
11269 "gracefulRestartRemoteTimerMsecs",
11270 p->v_gr_restart * 1000);
11271
05c7a1cc
QY
11272 FOREACH_AFI_SAFI (afi, safi) {
11273 if (CHECK_FLAG(
11274 p->af_cap
11275 [afi]
11276 [safi],
11277 PEER_CAP_RESTART_AF_RCV)) {
11278 json_object *
11279 json_sub =
11280 NULL;
11281 json_sub =
11282 json_object_new_object();
11283
d62a17ae 11284 if (CHECK_FLAG(
11285 p->af_cap
11286 [afi]
11287 [safi],
05c7a1cc
QY
11288 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11289 json_object_boolean_true_add(
11290 json_sub,
11291 "preserved");
11292 restart_af_count++;
11293 json_object_object_add(
11294 json_restart,
5cb5f4d0 11295 get_afi_safi_str(
05c7a1cc 11296 afi,
5cb5f4d0
DD
11297 safi,
11298 true),
05c7a1cc 11299 json_sub);
d62a17ae 11300 }
11301 }
11302 if (!restart_af_count) {
11303 json_object_string_add(
11304 json_cap,
11305 "addressFamiliesByPeer",
11306 "none");
11307 json_object_free(
11308 json_restart);
11309 } else
11310 json_object_object_add(
11311 json_cap,
11312 "addressFamiliesByPeer",
11313 json_restart);
11314 }
11315 }
11316 json_object_object_add(json_neigh,
11317 "neighborCapabilities",
11318 json_cap);
11319 } else {
11320 vty_out(vty, " Neighbor capabilities:\n");
11321
11322 /* AS4 */
11323 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11324 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11325 vty_out(vty, " 4 Byte AS:");
11326 if (CHECK_FLAG(p->cap,
11327 PEER_CAP_AS4_ADV))
11328 vty_out(vty, " advertised");
11329 if (CHECK_FLAG(p->cap,
11330 PEER_CAP_AS4_RCV))
11331 vty_out(vty, " %sreceived",
11332 CHECK_FLAG(
11333 p->cap,
11334 PEER_CAP_AS4_ADV)
11335 ? "and "
11336 : "");
11337 vty_out(vty, "\n");
11338 }
11339
11340 /* AddPath */
11341 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11342 || CHECK_FLAG(p->cap,
11343 PEER_CAP_ADDPATH_ADV)) {
11344 vty_out(vty, " AddPath:\n");
11345
05c7a1cc
QY
11346 FOREACH_AFI_SAFI (afi, safi) {
11347 if (CHECK_FLAG(
11348 p->af_cap[afi]
11349 [safi],
11350 PEER_CAP_ADDPATH_AF_TX_ADV)
11351 || CHECK_FLAG(
11352 p->af_cap[afi]
11353 [safi],
11354 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11355 vty_out(vty,
11356 " %s: TX ",
5cb5f4d0 11357 get_afi_safi_str(
05c7a1cc 11358 afi,
5cb5f4d0
DD
11359 safi,
11360 false));
05c7a1cc 11361
d62a17ae 11362 if (CHECK_FLAG(
11363 p->af_cap
11364 [afi]
11365 [safi],
05c7a1cc 11366 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 11367 vty_out(vty,
05c7a1cc 11368 "advertised %s",
5cb5f4d0 11369 get_afi_safi_str(
d62a17ae 11370 afi,
5cb5f4d0
DD
11371 safi,
11372 false));
d62a17ae 11373
05c7a1cc
QY
11374 if (CHECK_FLAG(
11375 p->af_cap
11376 [afi]
11377 [safi],
11378 PEER_CAP_ADDPATH_AF_TX_RCV))
11379 vty_out(vty,
11380 "%sreceived",
11381 CHECK_FLAG(
11382 p->af_cap
11383 [afi]
11384 [safi],
11385 PEER_CAP_ADDPATH_AF_TX_ADV)
11386 ? " and "
11387 : "");
d62a17ae 11388
05c7a1cc
QY
11389 vty_out(vty, "\n");
11390 }
d62a17ae 11391
05c7a1cc
QY
11392 if (CHECK_FLAG(
11393 p->af_cap[afi]
11394 [safi],
11395 PEER_CAP_ADDPATH_AF_RX_ADV)
11396 || CHECK_FLAG(
11397 p->af_cap[afi]
11398 [safi],
11399 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11400 vty_out(vty,
11401 " %s: RX ",
5cb5f4d0 11402 get_afi_safi_str(
05c7a1cc 11403 afi,
5cb5f4d0
DD
11404 safi,
11405 false));
d62a17ae 11406
11407 if (CHECK_FLAG(
11408 p->af_cap
11409 [afi]
11410 [safi],
05c7a1cc 11411 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 11412 vty_out(vty,
05c7a1cc 11413 "advertised %s",
5cb5f4d0 11414 get_afi_safi_str(
d62a17ae 11415 afi,
5cb5f4d0
DD
11416 safi,
11417 false));
d62a17ae 11418
05c7a1cc
QY
11419 if (CHECK_FLAG(
11420 p->af_cap
11421 [afi]
11422 [safi],
11423 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 11424 vty_out(vty,
05c7a1cc
QY
11425 "%sreceived",
11426 CHECK_FLAG(
11427 p->af_cap
11428 [afi]
11429 [safi],
11430 PEER_CAP_ADDPATH_AF_RX_ADV)
11431 ? " and "
11432 : "");
11433
11434 vty_out(vty, "\n");
d62a17ae 11435 }
05c7a1cc 11436 }
d62a17ae 11437 }
11438
11439 /* Dynamic */
11440 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11441 || CHECK_FLAG(p->cap,
11442 PEER_CAP_DYNAMIC_ADV)) {
11443 vty_out(vty, " Dynamic:");
11444 if (CHECK_FLAG(p->cap,
11445 PEER_CAP_DYNAMIC_ADV))
11446 vty_out(vty, " advertised");
11447 if (CHECK_FLAG(p->cap,
11448 PEER_CAP_DYNAMIC_RCV))
11449 vty_out(vty, " %sreceived",
11450 CHECK_FLAG(
11451 p->cap,
11452 PEER_CAP_DYNAMIC_ADV)
11453 ? "and "
11454 : "");
11455 vty_out(vty, "\n");
11456 }
11457
11458 /* Extended nexthop */
11459 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11460 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11461 vty_out(vty, " Extended nexthop:");
11462 if (CHECK_FLAG(p->cap,
11463 PEER_CAP_ENHE_ADV))
11464 vty_out(vty, " advertised");
11465 if (CHECK_FLAG(p->cap,
11466 PEER_CAP_ENHE_RCV))
11467 vty_out(vty, " %sreceived",
11468 CHECK_FLAG(
11469 p->cap,
11470 PEER_CAP_ENHE_ADV)
11471 ? "and "
11472 : "");
11473 vty_out(vty, "\n");
11474
11475 if (CHECK_FLAG(p->cap,
11476 PEER_CAP_ENHE_RCV)) {
11477 vty_out(vty,
11478 " Address families by peer:\n ");
11479 for (safi = SAFI_UNICAST;
11480 safi < SAFI_MAX; safi++)
11481 if (CHECK_FLAG(
11482 p->af_cap
11483 [AFI_IP]
11484 [safi],
11485 PEER_CAP_ENHE_AF_RCV))
11486 vty_out(vty,
11487 " %s\n",
5cb5f4d0 11488 get_afi_safi_str(
d62a17ae 11489 AFI_IP,
5cb5f4d0
DD
11490 safi,
11491 false));
d62a17ae 11492 }
11493 }
11494
11495 /* Route Refresh */
11496 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11497 || CHECK_FLAG(p->cap,
11498 PEER_CAP_REFRESH_NEW_RCV)
11499 || CHECK_FLAG(p->cap,
11500 PEER_CAP_REFRESH_OLD_RCV)) {
11501 vty_out(vty, " Route refresh:");
11502 if (CHECK_FLAG(p->cap,
11503 PEER_CAP_REFRESH_ADV))
11504 vty_out(vty, " advertised");
11505 if (CHECK_FLAG(p->cap,
11506 PEER_CAP_REFRESH_NEW_RCV)
11507 || CHECK_FLAG(
11508 p->cap,
11509 PEER_CAP_REFRESH_OLD_RCV))
11510 vty_out(vty, " %sreceived(%s)",
11511 CHECK_FLAG(
11512 p->cap,
11513 PEER_CAP_REFRESH_ADV)
11514 ? "and "
11515 : "",
11516 (CHECK_FLAG(
11517 p->cap,
11518 PEER_CAP_REFRESH_OLD_RCV)
11519 && CHECK_FLAG(
11520 p->cap,
11521 PEER_CAP_REFRESH_NEW_RCV))
11522 ? "old & new"
11523 : CHECK_FLAG(
11524 p->cap,
11525 PEER_CAP_REFRESH_OLD_RCV)
11526 ? "old"
11527 : "new");
11528
11529 vty_out(vty, "\n");
11530 }
11531
11532 /* Multiprotocol Extensions */
05c7a1cc
QY
11533 FOREACH_AFI_SAFI (afi, safi)
11534 if (p->afc_adv[afi][safi]
11535 || p->afc_recv[afi][safi]) {
11536 vty_out(vty,
11537 " Address Family %s:",
5cb5f4d0
DD
11538 get_afi_safi_str(
11539 afi,
11540 safi,
11541 false));
05c7a1cc 11542 if (p->afc_adv[afi][safi])
d62a17ae 11543 vty_out(vty,
05c7a1cc
QY
11544 " advertised");
11545 if (p->afc_recv[afi][safi])
11546 vty_out(vty,
11547 " %sreceived",
11548 p->afc_adv[afi]
11549 [safi]
11550 ? "and "
11551 : "");
11552 vty_out(vty, "\n");
11553 }
d62a17ae 11554
11555 /* Hostname capability */
60466a63 11556 vty_out(vty, " Hostname Capability:");
d77114b7
MK
11557
11558 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
11559 vty_out(vty,
11560 " advertised (name: %s,domain name: %s)",
60466a63
QY
11561 bgp->peer_self->hostname
11562 ? bgp->peer_self
11563 ->hostname
d77114b7 11564 : "n/a",
60466a63
QY
11565 bgp->peer_self->domainname
11566 ? bgp->peer_self
11567 ->domainname
d77114b7
MK
11568 : "n/a");
11569 } else {
11570 vty_out(vty, " not advertised");
d62a17ae 11571 }
11572
d77114b7 11573 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
11574 vty_out(vty,
11575 " received (name: %s,domain name: %s)",
60466a63
QY
11576 p->hostname ? p->hostname
11577 : "n/a",
11578 p->domainname ? p->domainname
11579 : "n/a");
d77114b7
MK
11580 } else {
11581 vty_out(vty, " not received");
11582 }
11583
11584 vty_out(vty, "\n");
11585
61bfbd51 11586 /* Graceful Restart */
d62a17ae 11587 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11588 || CHECK_FLAG(p->cap,
11589 PEER_CAP_RESTART_ADV)) {
11590 vty_out(vty,
61bfbd51 11591 " Graceful Restart Capability:");
d62a17ae 11592 if (CHECK_FLAG(p->cap,
11593 PEER_CAP_RESTART_ADV))
11594 vty_out(vty, " advertised");
11595 if (CHECK_FLAG(p->cap,
11596 PEER_CAP_RESTART_RCV))
11597 vty_out(vty, " %sreceived",
11598 CHECK_FLAG(
11599 p->cap,
11600 PEER_CAP_RESTART_ADV)
11601 ? "and "
11602 : "");
11603 vty_out(vty, "\n");
11604
11605 if (CHECK_FLAG(p->cap,
11606 PEER_CAP_RESTART_RCV)) {
11607 int restart_af_count = 0;
11608
11609 vty_out(vty,
11610 " Remote Restart timer is %d seconds\n",
11611 p->v_gr_restart);
11612 vty_out(vty,
11613 " Address families by peer:\n ");
11614
05c7a1cc
QY
11615 FOREACH_AFI_SAFI (afi, safi)
11616 if (CHECK_FLAG(
11617 p->af_cap
11618 [afi]
11619 [safi],
11620 PEER_CAP_RESTART_AF_RCV)) {
11621 vty_out(vty,
11622 "%s%s(%s)",
11623 restart_af_count
11624 ? ", "
11625 : "",
5cb5f4d0 11626 get_afi_safi_str(
05c7a1cc 11627 afi,
5cb5f4d0
DD
11628 safi,
11629 false),
05c7a1cc
QY
11630 CHECK_FLAG(
11631 p->af_cap
11632 [afi]
11633 [safi],
11634 PEER_CAP_RESTART_AF_PRESERVE_RCV)
11635 ? "preserved"
11636 : "not preserved");
11637 restart_af_count++;
11638 }
d62a17ae 11639 if (!restart_af_count)
11640 vty_out(vty, "none");
11641 vty_out(vty, "\n");
11642 }
2986cac2 11643 } /* Gracefull Restart */
d62a17ae 11644 }
11645 }
11646 }
11647
11648 /* graceful restart information */
d62a17ae 11649 json_object *json_grace = NULL;
11650 json_object *json_grace_send = NULL;
11651 json_object *json_grace_recv = NULL;
11652 int eor_send_af_count = 0;
11653 int eor_receive_af_count = 0;
11654
11655 if (use_json) {
11656 json_grace = json_object_new_object();
11657 json_grace_send = json_object_new_object();
11658 json_grace_recv = json_object_new_object();
11659
36235319
QY
11660 if ((p->status == Established)
11661 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
11662 FOREACH_AFI_SAFI (afi, safi) {
11663 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 11664 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
11665 json_object_boolean_true_add(
11666 json_grace_send,
5cb5f4d0
DD
11667 get_afi_safi_str(afi,
11668 safi,
11669 true));
05c7a1cc 11670 eor_send_af_count++;
d62a17ae 11671 }
11672 }
05c7a1cc
QY
11673 FOREACH_AFI_SAFI (afi, safi) {
11674 if (CHECK_FLAG(
36235319
QY
11675 p->af_sflags[afi][safi],
11676 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
11677 json_object_boolean_true_add(
11678 json_grace_recv,
5cb5f4d0
DD
11679 get_afi_safi_str(afi,
11680 safi,
11681 true));
05c7a1cc 11682 eor_receive_af_count++;
d62a17ae 11683 }
11684 }
11685 }
36235319
QY
11686 json_object_object_add(json_grace, "endOfRibSend",
11687 json_grace_send);
11688 json_object_object_add(json_grace, "endOfRibRecv",
11689 json_grace_recv);
d62a17ae 11690
d62a17ae 11691
11692 if (p->t_gr_restart)
11693 json_object_int_add(json_grace,
11694 "gracefulRestartTimerMsecs",
11695 thread_timer_remain_second(
11696 p->t_gr_restart)
11697 * 1000);
11698
11699 if (p->t_gr_stale)
11700 json_object_int_add(
11701 json_grace,
11702 "gracefulStalepathTimerMsecs",
11703 thread_timer_remain_second(
11704 p->t_gr_stale)
11705 * 1000);
2986cac2 11706 /* more gr info in new format */
11707 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 11708 json_grace);
d62a17ae 11709 json_object_object_add(
11710 json_neigh, "gracefulRestartInfo", json_grace);
11711 } else {
2089dd80 11712 vty_out(vty, " Graceful restart information:\n");
36235319
QY
11713 if ((p->status == Established)
11714 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11715
d62a17ae 11716 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
11717 FOREACH_AFI_SAFI (afi, safi) {
11718 if (CHECK_FLAG(p->af_sflags[afi][safi],
11719 PEER_STATUS_EOR_SEND)) {
11720 vty_out(vty, "%s%s",
11721 eor_send_af_count ? ", "
11722 : "",
36235319
QY
11723 get_afi_safi_str(
11724 afi, safi,
11725 false));
05c7a1cc 11726 eor_send_af_count++;
d62a17ae 11727 }
11728 }
11729 vty_out(vty, "\n");
11730 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
11731 FOREACH_AFI_SAFI (afi, safi) {
11732 if (CHECK_FLAG(
11733 p->af_sflags[afi][safi],
11734 PEER_STATUS_EOR_RECEIVED)) {
11735 vty_out(vty, "%s%s",
11736 eor_receive_af_count
11737 ? ", "
11738 : "",
5cb5f4d0
DD
11739 get_afi_safi_str(afi,
11740 safi,
11741 false));
05c7a1cc 11742 eor_receive_af_count++;
d62a17ae 11743 }
11744 }
11745 vty_out(vty, "\n");
11746 }
11747
11748 if (p->t_gr_restart)
11749 vty_out(vty,
11750 " The remaining time of restart timer is %ld\n",
11751 thread_timer_remain_second(
11752 p->t_gr_restart));
11753
11754 if (p->t_gr_stale)
11755 vty_out(vty,
11756 " The remaining time of stalepath timer is %ld\n",
11757 thread_timer_remain_second(
11758 p->t_gr_stale));
2986cac2 11759
11760 /* more gr info in new format */
11761 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 11762 }
2986cac2 11763
d62a17ae 11764 if (use_json) {
11765 json_object *json_stat = NULL;
11766 json_stat = json_object_new_object();
11767 /* Packet counts. */
43aa5965
QY
11768
11769 atomic_size_t outq_count, inq_count;
11770 outq_count = atomic_load_explicit(&p->obuf->count,
11771 memory_order_relaxed);
11772 inq_count = atomic_load_explicit(&p->ibuf->count,
11773 memory_order_relaxed);
11774
11775 json_object_int_add(json_stat, "depthInq",
11776 (unsigned long)inq_count);
d62a17ae 11777 json_object_int_add(json_stat, "depthOutq",
43aa5965 11778 (unsigned long)outq_count);
0112e9e0
QY
11779 json_object_int_add(json_stat, "opensSent",
11780 atomic_load_explicit(&p->open_out,
11781 memory_order_relaxed));
11782 json_object_int_add(json_stat, "opensRecv",
11783 atomic_load_explicit(&p->open_in,
11784 memory_order_relaxed));
d62a17ae 11785 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
11786 atomic_load_explicit(&p->notify_out,
11787 memory_order_relaxed));
d62a17ae 11788 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
11789 atomic_load_explicit(&p->notify_in,
11790 memory_order_relaxed));
11791 json_object_int_add(json_stat, "updatesSent",
11792 atomic_load_explicit(&p->update_out,
11793 memory_order_relaxed));
11794 json_object_int_add(json_stat, "updatesRecv",
11795 atomic_load_explicit(&p->update_in,
11796 memory_order_relaxed));
d62a17ae 11797 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
11798 atomic_load_explicit(&p->keepalive_out,
11799 memory_order_relaxed));
d62a17ae 11800 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
11801 atomic_load_explicit(&p->keepalive_in,
11802 memory_order_relaxed));
d62a17ae 11803 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
11804 atomic_load_explicit(&p->refresh_out,
11805 memory_order_relaxed));
d62a17ae 11806 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
11807 atomic_load_explicit(&p->refresh_in,
11808 memory_order_relaxed));
d62a17ae 11809 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
11810 atomic_load_explicit(&p->dynamic_cap_out,
11811 memory_order_relaxed));
d62a17ae 11812 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
11813 atomic_load_explicit(&p->dynamic_cap_in,
11814 memory_order_relaxed));
11815 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
11816 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 11817 json_object_object_add(json_neigh, "messageStats", json_stat);
11818 } else {
43aa5965
QY
11819 atomic_size_t outq_count, inq_count;
11820 outq_count = atomic_load_explicit(&p->obuf->count,
11821 memory_order_relaxed);
11822 inq_count = atomic_load_explicit(&p->ibuf->count,
11823 memory_order_relaxed);
11824
d62a17ae 11825 /* Packet counts. */
11826 vty_out(vty, " Message statistics:\n");
43aa5965
QY
11827 vty_out(vty, " Inq depth is %zu\n", inq_count);
11828 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 11829 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
11830 vty_out(vty, " Opens: %10d %10d\n",
11831 atomic_load_explicit(&p->open_out,
11832 memory_order_relaxed),
11833 atomic_load_explicit(&p->open_in,
11834 memory_order_relaxed));
11835 vty_out(vty, " Notifications: %10d %10d\n",
11836 atomic_load_explicit(&p->notify_out,
11837 memory_order_relaxed),
11838 atomic_load_explicit(&p->notify_in,
11839 memory_order_relaxed));
11840 vty_out(vty, " Updates: %10d %10d\n",
11841 atomic_load_explicit(&p->update_out,
11842 memory_order_relaxed),
11843 atomic_load_explicit(&p->update_in,
11844 memory_order_relaxed));
11845 vty_out(vty, " Keepalives: %10d %10d\n",
11846 atomic_load_explicit(&p->keepalive_out,
11847 memory_order_relaxed),
11848 atomic_load_explicit(&p->keepalive_in,
11849 memory_order_relaxed));
11850 vty_out(vty, " Route Refresh: %10d %10d\n",
11851 atomic_load_explicit(&p->refresh_out,
11852 memory_order_relaxed),
11853 atomic_load_explicit(&p->refresh_in,
11854 memory_order_relaxed));
d62a17ae 11855 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
11856 atomic_load_explicit(&p->dynamic_cap_out,
11857 memory_order_relaxed),
11858 atomic_load_explicit(&p->dynamic_cap_in,
11859 memory_order_relaxed));
11860 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
11861 PEER_TOTAL_RX(p));
d62a17ae 11862 }
11863
11864 if (use_json) {
11865 /* advertisement-interval */
11866 json_object_int_add(json_neigh,
11867 "minBtwnAdvertisementRunsTimerMsecs",
11868 p->v_routeadv * 1000);
11869
11870 /* Update-source. */
11871 if (p->update_if || p->update_source) {
11872 if (p->update_if)
11873 json_object_string_add(json_neigh,
11874 "updateSource",
11875 p->update_if);
11876 else if (p->update_source)
11877 json_object_string_add(
11878 json_neigh, "updateSource",
11879 sockunion2str(p->update_source, buf1,
11880 SU_ADDRSTRLEN));
11881 }
11882 } else {
11883 /* advertisement-interval */
11884 vty_out(vty,
11885 " Minimum time between advertisement runs is %d seconds\n",
11886 p->v_routeadv);
11887
11888 /* Update-source. */
11889 if (p->update_if || p->update_source) {
11890 vty_out(vty, " Update source is ");
11891 if (p->update_if)
11892 vty_out(vty, "%s", p->update_if);
11893 else if (p->update_source)
11894 vty_out(vty, "%s",
11895 sockunion2str(p->update_source, buf1,
11896 SU_ADDRSTRLEN));
11897 vty_out(vty, "\n");
11898 }
11899
11900 vty_out(vty, "\n");
11901 }
11902
11903 /* Address Family Information */
11904 json_object *json_hold = NULL;
11905
11906 if (use_json)
11907 json_hold = json_object_new_object();
11908
05c7a1cc
QY
11909 FOREACH_AFI_SAFI (afi, safi)
11910 if (p->afc[afi][safi])
11911 bgp_show_peer_afi(vty, p, afi, safi, use_json,
11912 json_hold);
d62a17ae 11913
11914 if (use_json) {
11915 json_object_object_add(json_neigh, "addressFamilyInfo",
11916 json_hold);
11917 json_object_int_add(json_neigh, "connectionsEstablished",
11918 p->established);
11919 json_object_int_add(json_neigh, "connectionsDropped",
11920 p->dropped);
11921 } else
11922 vty_out(vty, " Connections established %d; dropped %d\n",
11923 p->established, p->dropped);
11924
11925 if (!p->last_reset) {
11926 if (use_json)
11927 json_object_string_add(json_neigh, "lastReset",
11928 "never");
11929 else
11930 vty_out(vty, " Last reset never\n");
11931 } else {
11932 if (use_json) {
11933 time_t uptime;
a2700b50 11934 struct tm tm;
d62a17ae 11935
11936 uptime = bgp_clock();
11937 uptime -= p->resettime;
a2700b50
MS
11938 gmtime_r(&uptime, &tm);
11939
d62a17ae 11940 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
11941 (tm.tm_sec * 1000)
11942 + (tm.tm_min * 60000)
11943 + (tm.tm_hour * 3600000));
3577f1c5 11944 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 11945 } else {
11946 vty_out(vty, " Last reset %s, ",
11947 peer_uptime(p->resettime, timebuf,
11948 BGP_UPTIME_LEN, 0, NULL));
11949
3577f1c5 11950 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 11951 if (p->last_reset_cause_size) {
11952 msg = p->last_reset_cause;
11953 vty_out(vty,
11954 " Message received that caused BGP to send a NOTIFICATION:\n ");
11955 for (i = 1; i <= p->last_reset_cause_size;
11956 i++) {
11957 vty_out(vty, "%02X", *msg++);
11958
11959 if (i != p->last_reset_cause_size) {
11960 if (i % 16 == 0) {
11961 vty_out(vty, "\n ");
11962 } else if (i % 4 == 0) {
11963 vty_out(vty, " ");
11964 }
11965 }
11966 }
11967 vty_out(vty, "\n");
11968 }
11969 }
11970 }
11971
11972 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
11973 if (use_json)
11974 json_object_boolean_true_add(json_neigh,
11975 "prefixesConfigExceedMax");
11976 else
11977 vty_out(vty,
11978 " Peer had exceeded the max. no. of prefixes configured.\n");
11979
11980 if (p->t_pmax_restart) {
11981 if (use_json) {
11982 json_object_boolean_true_add(
11983 json_neigh, "reducePrefixNumFrom");
11984 json_object_int_add(json_neigh,
11985 "restartInTimerMsec",
11986 thread_timer_remain_second(
11987 p->t_pmax_restart)
11988 * 1000);
11989 } else
11990 vty_out(vty,
11991 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
11992 p->host, thread_timer_remain_second(
11993 p->t_pmax_restart));
d62a17ae 11994 } else {
11995 if (use_json)
11996 json_object_boolean_true_add(
11997 json_neigh,
11998 "reducePrefixNumAndClearIpBgp");
11999 else
12000 vty_out(vty,
12001 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
12002 p->host);
12003 }
12004 }
12005
12006 /* EBGP Multihop and GTSM */
12007 if (p->sort != BGP_PEER_IBGP) {
12008 if (use_json) {
e2521429 12009 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12010 json_object_int_add(json_neigh,
12011 "externalBgpNbrMaxHopsAway",
12012 p->gtsm_hops);
c8d6f0d6 12013 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12014 json_object_int_add(json_neigh,
12015 "externalBgpNbrMaxHopsAway",
12016 p->ttl);
12017 } else {
e2521429 12018 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12019 vty_out(vty,
12020 " External BGP neighbor may be up to %d hops away.\n",
12021 p->gtsm_hops);
c8d6f0d6 12022 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12023 vty_out(vty,
12024 " External BGP neighbor may be up to %d hops away.\n",
12025 p->ttl);
12026 }
12027 } else {
e2521429 12028 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 12029 if (use_json)
12030 json_object_int_add(json_neigh,
12031 "internalBgpNbrMaxHopsAway",
12032 p->gtsm_hops);
12033 else
12034 vty_out(vty,
12035 " Internal BGP neighbor may be up to %d hops away.\n",
12036 p->gtsm_hops);
12037 }
12038 }
12039
12040 /* Local address. */
12041 if (p->su_local) {
12042 if (use_json) {
12043 json_object_string_add(json_neigh, "hostLocal",
12044 sockunion2str(p->su_local, buf1,
12045 SU_ADDRSTRLEN));
12046 json_object_int_add(json_neigh, "portLocal",
12047 ntohs(p->su_local->sin.sin_port));
12048 } else
12049 vty_out(vty, "Local host: %s, Local port: %d\n",
12050 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
12051 ntohs(p->su_local->sin.sin_port));
12052 }
12053
12054 /* Remote address. */
12055 if (p->su_remote) {
12056 if (use_json) {
12057 json_object_string_add(json_neigh, "hostForeign",
12058 sockunion2str(p->su_remote, buf1,
12059 SU_ADDRSTRLEN));
12060 json_object_int_add(json_neigh, "portForeign",
12061 ntohs(p->su_remote->sin.sin_port));
12062 } else
12063 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12064 sockunion2str(p->su_remote, buf1,
12065 SU_ADDRSTRLEN),
12066 ntohs(p->su_remote->sin.sin_port));
12067 }
12068
12069 /* Nexthop display. */
12070 if (p->su_local) {
12071 if (use_json) {
12072 json_object_string_add(json_neigh, "nexthop",
12073 inet_ntop(AF_INET,
12074 &p->nexthop.v4, buf1,
12075 sizeof(buf1)));
12076 json_object_string_add(json_neigh, "nexthopGlobal",
12077 inet_ntop(AF_INET6,
12078 &p->nexthop.v6_global,
12079 buf1, sizeof(buf1)));
12080 json_object_string_add(json_neigh, "nexthopLocal",
12081 inet_ntop(AF_INET6,
12082 &p->nexthop.v6_local,
12083 buf1, sizeof(buf1)));
12084 if (p->shared_network)
12085 json_object_string_add(json_neigh,
12086 "bgpConnection",
12087 "sharedNetwork");
12088 else
12089 json_object_string_add(json_neigh,
12090 "bgpConnection",
12091 "nonSharedNetwork");
12092 } else {
12093 vty_out(vty, "Nexthop: %s\n",
12094 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12095 sizeof(buf1)));
12096 vty_out(vty, "Nexthop global: %s\n",
12097 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12098 sizeof(buf1)));
12099 vty_out(vty, "Nexthop local: %s\n",
12100 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12101 sizeof(buf1)));
12102 vty_out(vty, "BGP connection: %s\n",
12103 p->shared_network ? "shared network"
12104 : "non shared network");
12105 }
12106 }
12107
12108 /* Timer information. */
12109 if (use_json) {
12110 json_object_int_add(json_neigh, "connectRetryTimer",
12111 p->v_connect);
12112 if (p->status == Established && p->rtt)
12113 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12114 p->rtt);
12115 if (p->t_start)
12116 json_object_int_add(
12117 json_neigh, "nextStartTimerDueInMsecs",
12118 thread_timer_remain_second(p->t_start) * 1000);
12119 if (p->t_connect)
12120 json_object_int_add(
12121 json_neigh, "nextConnectTimerDueInMsecs",
12122 thread_timer_remain_second(p->t_connect)
12123 * 1000);
12124 if (p->t_routeadv) {
12125 json_object_int_add(json_neigh, "mraiInterval",
12126 p->v_routeadv);
12127 json_object_int_add(
12128 json_neigh, "mraiTimerExpireInMsecs",
12129 thread_timer_remain_second(p->t_routeadv)
12130 * 1000);
12131 }
12132 if (p->password)
12133 json_object_int_add(json_neigh, "authenticationEnabled",
12134 1);
12135
12136 if (p->t_read)
12137 json_object_string_add(json_neigh, "readThread", "on");
12138 else
12139 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
12140
12141 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 12142 json_object_string_add(json_neigh, "writeThread", "on");
12143 else
12144 json_object_string_add(json_neigh, "writeThread",
12145 "off");
12146 } else {
12147 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12148 p->v_connect);
12149 if (p->status == Established && p->rtt)
12150 vty_out(vty, "Estimated round trip time: %d ms\n",
12151 p->rtt);
12152 if (p->t_start)
12153 vty_out(vty, "Next start timer due in %ld seconds\n",
12154 thread_timer_remain_second(p->t_start));
12155 if (p->t_connect)
12156 vty_out(vty, "Next connect timer due in %ld seconds\n",
12157 thread_timer_remain_second(p->t_connect));
12158 if (p->t_routeadv)
12159 vty_out(vty,
12160 "MRAI (interval %u) timer expires in %ld seconds\n",
12161 p->v_routeadv,
12162 thread_timer_remain_second(p->t_routeadv));
12163 if (p->password)
12164 vty_out(vty, "Peer Authentication Enabled\n");
12165
cac9e917 12166 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
12167 p->t_read ? "on" : "off",
12168 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12169 ? "on"
cac9e917 12170 : "off", p->fd);
d62a17ae 12171 }
12172
12173 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12174 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12175 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12176
12177 if (!use_json)
12178 vty_out(vty, "\n");
12179
12180 /* BFD information. */
12181 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12182
12183 if (use_json) {
12184 if (p->conf_if) /* Configured interface name. */
12185 json_object_object_add(json, p->conf_if, json_neigh);
12186 else /* Configured IP address. */
12187 json_object_object_add(json, p->host, json_neigh);
12188 }
12189}
12190
36235319
QY
12191static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
12192 enum show_type type,
12193 union sockunion *su,
12194 const char *conf_if, afi_t afi,
74a630b6 12195 bool use_json)
2986cac2 12196{
12197 struct listnode *node, *nnode;
12198 struct peer *peer;
12199 int find = 0;
12200 safi_t safi = SAFI_UNICAST;
74a630b6 12201 json_object *json = NULL;
2986cac2 12202 json_object *json_neighbor = NULL;
12203
74a630b6
NT
12204 if (use_json) {
12205 json = json_object_new_object();
12206 json_neighbor = json_object_new_object();
12207 }
12208
2986cac2 12209 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12210
12211 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12212 continue;
12213
12214 if ((peer->afc[afi][safi]) == 0)
12215 continue;
12216
2ba1fe69 12217 if (type == show_all) {
2986cac2 12218 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 12219 json_neighbor);
2986cac2 12220
74a630b6 12221 if (use_json) {
13909c4f
DS
12222 json_object_object_add(json, peer->host,
12223 json_neighbor);
74a630b6
NT
12224 json_neighbor = NULL;
12225 }
2986cac2 12226
2ba1fe69 12227 } else if (type == show_peer) {
2986cac2 12228 if (conf_if) {
12229 if ((peer->conf_if
13909c4f
DS
12230 && !strcmp(peer->conf_if, conf_if))
12231 || (peer->hostname
2986cac2 12232 && !strcmp(peer->hostname, conf_if))) {
12233 find = 1;
13909c4f
DS
12234 bgp_show_peer_gr_status(vty, peer,
12235 use_json,
12236 json_neighbor);
2986cac2 12237 }
12238 } else {
12239 if (sockunion_same(&peer->su, su)) {
12240 find = 1;
13909c4f
DS
12241 bgp_show_peer_gr_status(vty, peer,
12242 use_json,
12243 json_neighbor);
2986cac2 12244 }
12245 }
13909c4f
DS
12246 if (use_json && find)
12247 json_object_object_add(json, peer->host,
12248 json_neighbor);
2986cac2 12249 }
12250
74a630b6
NT
12251 if (find) {
12252 json_neighbor = NULL;
2986cac2 12253 break;
74a630b6 12254 }
2986cac2 12255 }
12256
12257 if (type == show_peer && !find) {
12258 if (use_json)
13909c4f 12259 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 12260 else
12261 vty_out(vty, "%% No such neighbor\n");
12262 }
12263 if (use_json) {
13909c4f
DS
12264 vty_out(vty, "%s\n",
12265 json_object_to_json_string_ext(
12266 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
12267
12268 if (json_neighbor)
12269 json_object_free(json_neighbor);
12270 json_object_free(json);
2986cac2 12271 } else {
12272 vty_out(vty, "\n");
12273 }
12274
12275 return CMD_SUCCESS;
12276}
12277
d62a17ae 12278static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12279 enum show_type type, union sockunion *su,
9f049418 12280 const char *conf_if, bool use_json,
d62a17ae 12281 json_object *json)
12282{
12283 struct listnode *node, *nnode;
12284 struct peer *peer;
12285 int find = 0;
9f049418 12286 bool nbr_output = false;
d1927ebe
AS
12287 afi_t afi = AFI_MAX;
12288 safi_t safi = SAFI_MAX;
12289
12290 if (type == show_ipv4_peer || type == show_ipv4_all) {
12291 afi = AFI_IP;
12292 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12293 afi = AFI_IP6;
12294 }
d62a17ae 12295
12296 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12297 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12298 continue;
12299
12300 switch (type) {
12301 case show_all:
12302 bgp_show_peer(vty, peer, use_json, json);
9f049418 12303 nbr_output = true;
d62a17ae 12304 break;
12305 case show_peer:
12306 if (conf_if) {
12307 if ((peer->conf_if
12308 && !strcmp(peer->conf_if, conf_if))
12309 || (peer->hostname
12310 && !strcmp(peer->hostname, conf_if))) {
12311 find = 1;
12312 bgp_show_peer(vty, peer, use_json,
12313 json);
12314 }
12315 } else {
12316 if (sockunion_same(&peer->su, su)) {
12317 find = 1;
12318 bgp_show_peer(vty, peer, use_json,
12319 json);
12320 }
12321 }
12322 break;
d1927ebe
AS
12323 case show_ipv4_peer:
12324 case show_ipv6_peer:
12325 FOREACH_SAFI (safi) {
12326 if (peer->afc[afi][safi]) {
12327 if (conf_if) {
12328 if ((peer->conf_if
12329 && !strcmp(peer->conf_if, conf_if))
12330 || (peer->hostname
12331 && !strcmp(peer->hostname, conf_if))) {
12332 find = 1;
12333 bgp_show_peer(vty, peer, use_json,
12334 json);
12335 break;
12336 }
12337 } else {
12338 if (sockunion_same(&peer->su, su)) {
12339 find = 1;
12340 bgp_show_peer(vty, peer, use_json,
12341 json);
12342 break;
12343 }
12344 }
12345 }
12346 }
12347 break;
12348 case show_ipv4_all:
12349 case show_ipv6_all:
12350 FOREACH_SAFI (safi) {
12351 if (peer->afc[afi][safi]) {
12352 bgp_show_peer(vty, peer, use_json, json);
12353 nbr_output = true;
12354 break;
12355 }
12356 }
12357 break;
d62a17ae 12358 }
12359 }
12360
d1927ebe
AS
12361 if ((type == show_peer || type == show_ipv4_peer ||
12362 type == show_ipv6_peer) && !find) {
d62a17ae 12363 if (use_json)
12364 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12365 else
88b7d255 12366 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 12367 }
12368
d1927ebe
AS
12369 if (type != show_peer && type != show_ipv4_peer &&
12370 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 12371 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 12372
d62a17ae 12373 if (use_json) {
996c9314
LB
12374 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12375 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 12376 } else {
12377 vty_out(vty, "\n");
12378 }
12379
12380 return CMD_SUCCESS;
12381}
12382
36235319
QY
12383static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12384 enum show_type type,
12385 const char *ip_str,
12386 afi_t afi, bool use_json)
2986cac2 12387{
12388
12389 int ret;
12390 struct bgp *bgp;
12391 union sockunion su;
2986cac2 12392
12393 bgp = bgp_get_default();
12394
13909c4f
DS
12395 if (!bgp)
12396 return;
2986cac2 12397
13909c4f
DS
12398 if (!use_json)
12399 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12400 NULL);
2986cac2 12401
13909c4f
DS
12402 if (ip_str) {
12403 ret = str2sockunion(ip_str, &su);
12404 if (ret < 0)
13909c4f 12405 bgp_show_neighbor_graceful_restart(
74a630b6
NT
12406 vty, bgp, type, NULL, ip_str, afi, use_json);
12407 else
12408 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
12409 NULL, afi, use_json);
13909c4f
DS
12410 } else
12411 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 12412 afi, use_json);
2986cac2 12413}
12414
d62a17ae 12415static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
12416 enum show_type type,
12417 const char *ip_str,
9f049418 12418 bool use_json)
d62a17ae 12419{
0291c246
MK
12420 struct listnode *node, *nnode;
12421 struct bgp *bgp;
71aedaa3 12422 union sockunion su;
0291c246 12423 json_object *json = NULL;
71aedaa3 12424 int ret, is_first = 1;
9f049418 12425 bool nbr_output = false;
d62a17ae 12426
12427 if (use_json)
12428 vty_out(vty, "{\n");
12429
12430 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 12431 nbr_output = true;
d62a17ae 12432 if (use_json) {
12433 if (!(json = json_object_new_object())) {
af4c2728 12434 flog_err(
e50f7cfd 12435 EC_BGP_JSON_MEM_ERROR,
d62a17ae 12436 "Unable to allocate memory for JSON object");
12437 vty_out(vty,
12438 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12439 return;
12440 }
12441
12442 json_object_int_add(json, "vrfId",
12443 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
12444 ? -1
12445 : (int64_t)bgp->vrf_id);
d62a17ae 12446 json_object_string_add(
12447 json, "vrfName",
12448 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12449 ? VRF_DEFAULT_NAME
d62a17ae 12450 : bgp->name);
12451
12452 if (!is_first)
12453 vty_out(vty, ",\n");
12454 else
12455 is_first = 0;
12456
12457 vty_out(vty, "\"%s\":",
12458 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12459 ? VRF_DEFAULT_NAME
d62a17ae 12460 : bgp->name);
12461 } else {
12462 vty_out(vty, "\nInstance %s:\n",
12463 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12464 ? VRF_DEFAULT_NAME
d62a17ae 12465 : bgp->name);
12466 }
71aedaa3 12467
d1927ebe
AS
12468 if (type == show_peer || type == show_ipv4_peer ||
12469 type == show_ipv6_peer) {
71aedaa3
DS
12470 ret = str2sockunion(ip_str, &su);
12471 if (ret < 0)
12472 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12473 use_json, json);
12474 else
12475 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12476 use_json, json);
12477 } else {
d1927ebe 12478 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
12479 use_json, json);
12480 }
b77004d6 12481 json_object_free(json);
d62a17ae 12482 }
12483
01cbfd04 12484 if (use_json) {
d62a17ae 12485 vty_out(vty, "}\n");
01cbfd04
QY
12486 json_object_free(json);
12487 }
9f049418
DS
12488 else if (!nbr_output)
12489 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12490}
12491
12492static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
12493 enum show_type type, const char *ip_str,
9f049418 12494 bool use_json)
d62a17ae 12495{
12496 int ret;
12497 struct bgp *bgp;
12498 union sockunion su;
12499 json_object *json = NULL;
12500
12501 if (name) {
12502 if (strmatch(name, "all")) {
71aedaa3
DS
12503 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
12504 use_json);
d62a17ae 12505 return CMD_SUCCESS;
12506 } else {
12507 bgp = bgp_lookup_by_name(name);
12508 if (!bgp) {
12509 if (use_json) {
12510 json = json_object_new_object();
d62a17ae 12511 vty_out(vty, "%s\n",
12512 json_object_to_json_string_ext(
12513 json,
12514 JSON_C_TO_STRING_PRETTY));
12515 json_object_free(json);
12516 } else
12517 vty_out(vty,
9f049418 12518 "%% BGP instance not found\n");
d62a17ae 12519
12520 return CMD_WARNING;
12521 }
12522 }
12523 } else {
12524 bgp = bgp_get_default();
12525 }
12526
12527 if (bgp) {
12528 json = json_object_new_object();
12529 if (ip_str) {
12530 ret = str2sockunion(ip_str, &su);
12531 if (ret < 0)
12532 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12533 use_json, json);
12534 else
12535 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12536 use_json, json);
12537 } else {
12538 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
12539 json);
12540 }
12541 json_object_free(json);
ca61fd25
DS
12542 } else {
12543 if (use_json)
12544 vty_out(vty, "{}\n");
12545 else
12546 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12547 }
12548
12549 return CMD_SUCCESS;
4fb25c53
DW
12550}
12551
2986cac2 12552
12553
12554/* "show [ip] bgp neighbors graceful-restart" commands. */
12555DEFUN (show_ip_bgp_neighbors_gracrful_restart,
12556 show_ip_bgp_neighbors_graceful_restart_cmd,
12557 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
12558 SHOW_STR
12559 BGP_STR
12560 IP_STR
12561 IPV6_STR
12562 NEIGHBOR_STR
12563 "Neighbor to display information about\n"
12564 "Neighbor to display information about\n"
12565 "Neighbor on BGP configured interface\n"
12566 GR_SHOW
12567 JSON_STR)
12568{
12569 char *sh_arg = NULL;
12570 enum show_type sh_type;
12571 int idx = 0;
12572 afi_t afi = AFI_MAX;
2986cac2 12573 bool uj = use_json(argc, argv);
12574
36235319 12575 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 12576 afi = AFI_MAX;
12577
12578 idx++;
12579
12580 if (argv_find(argv, argc, "A.B.C.D", &idx)
12581 || argv_find(argv, argc, "X:X::X:X", &idx)
12582 || argv_find(argv, argc, "WORD", &idx)) {
12583 sh_type = show_peer;
12584 sh_arg = argv[idx]->arg;
12585 } else
12586 sh_type = show_all;
12587
12588 if (!argv_find(argv, argc, "graceful-restart", &idx))
12589 return CMD_SUCCESS;
12590
12591
36235319
QY
12592 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
12593 afi, uj);
2986cac2 12594}
12595
716b2d8a 12596/* "show [ip] bgp neighbors" commands. */
718e3744 12597DEFUN (show_ip_bgp_neighbors,
12598 show_ip_bgp_neighbors_cmd,
24345e82 12599 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 12600 SHOW_STR
12601 IP_STR
12602 BGP_STR
f2a8972b 12603 BGP_INSTANCE_HELP_STR
8c3deaae
QY
12604 "Address Family\n"
12605 "Address Family\n"
718e3744 12606 "Detailed information on TCP and BGP neighbor connections\n"
12607 "Neighbor to display information about\n"
a80beece 12608 "Neighbor to display information about\n"
91d37724 12609 "Neighbor on BGP configured interface\n"
9973d184 12610 JSON_STR)
718e3744 12611{
d62a17ae 12612 char *vrf = NULL;
12613 char *sh_arg = NULL;
12614 enum show_type sh_type;
d1927ebe 12615 afi_t afi = AFI_MAX;
718e3744 12616
9f049418 12617 bool uj = use_json(argc, argv);
718e3744 12618
d62a17ae 12619 int idx = 0;
718e3744 12620
9a8bdf1c
PG
12621 /* [<vrf> VIEWVRFNAME] */
12622 if (argv_find(argv, argc, "vrf", &idx)) {
12623 vrf = argv[idx + 1]->arg;
12624 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12625 vrf = NULL;
12626 } else if (argv_find(argv, argc, "view", &idx))
12627 /* [<view> VIEWVRFNAME] */
d62a17ae 12628 vrf = argv[idx + 1]->arg;
718e3744 12629
d62a17ae 12630 idx++;
d1927ebe
AS
12631
12632 if (argv_find(argv, argc, "ipv4", &idx)) {
12633 sh_type = show_ipv4_all;
12634 afi = AFI_IP;
12635 } else if (argv_find(argv, argc, "ipv6", &idx)) {
12636 sh_type = show_ipv6_all;
12637 afi = AFI_IP6;
12638 } else {
12639 sh_type = show_all;
12640 }
12641
d62a17ae 12642 if (argv_find(argv, argc, "A.B.C.D", &idx)
12643 || argv_find(argv, argc, "X:X::X:X", &idx)
12644 || argv_find(argv, argc, "WORD", &idx)) {
12645 sh_type = show_peer;
12646 sh_arg = argv[idx]->arg;
d1927ebe
AS
12647 }
12648
12649 if (sh_type == show_peer && afi == AFI_IP) {
12650 sh_type = show_ipv4_peer;
12651 } else if (sh_type == show_peer && afi == AFI_IP6) {
12652 sh_type = show_ipv6_peer;
12653 }
856ca177 12654
d62a17ae 12655 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 12656}
12657
716b2d8a 12658/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 12659 paths' and `show ip mbgp paths'. Those functions results are the
12660 same.*/
f412b39a 12661DEFUN (show_ip_bgp_paths,
718e3744 12662 show_ip_bgp_paths_cmd,
46f296b4 12663 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 12664 SHOW_STR
12665 IP_STR
12666 BGP_STR
46f296b4 12667 BGP_SAFI_HELP_STR
718e3744 12668 "Path information\n")
12669{
d62a17ae 12670 vty_out(vty, "Address Refcnt Path\n");
12671 aspath_print_all_vty(vty);
12672 return CMD_SUCCESS;
718e3744 12673}
12674
718e3744 12675#include "hash.h"
12676
e3b78da8 12677static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12678 struct vty *vty)
718e3744 12679{
d62a17ae 12680 struct community *com;
718e3744 12681
e3b78da8 12682 com = (struct community *)bucket->data;
3f65c5b1 12683 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 12684 community_str(com, false));
718e3744 12685}
12686
12687/* Show BGP's community internal data. */
f412b39a 12688DEFUN (show_ip_bgp_community_info,
718e3744 12689 show_ip_bgp_community_info_cmd,
bec37ba5 12690 "show [ip] bgp community-info",
718e3744 12691 SHOW_STR
12692 IP_STR
12693 BGP_STR
12694 "List all bgp community information\n")
12695{
d62a17ae 12696 vty_out(vty, "Address Refcnt Community\n");
718e3744 12697
d62a17ae 12698 hash_iterate(community_hash(),
e3b78da8 12699 (void (*)(struct hash_bucket *,
d62a17ae 12700 void *))community_show_all_iterator,
12701 vty);
718e3744 12702
d62a17ae 12703 return CMD_SUCCESS;
718e3744 12704}
12705
e3b78da8 12706static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12707 struct vty *vty)
57d187bc 12708{
d62a17ae 12709 struct lcommunity *lcom;
57d187bc 12710
e3b78da8 12711 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 12712 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 12713 lcommunity_str(lcom, false));
57d187bc
JS
12714}
12715
12716/* Show BGP's community internal data. */
12717DEFUN (show_ip_bgp_lcommunity_info,
12718 show_ip_bgp_lcommunity_info_cmd,
12719 "show ip bgp large-community-info",
12720 SHOW_STR
12721 IP_STR
12722 BGP_STR
12723 "List all bgp large-community information\n")
12724{
d62a17ae 12725 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 12726
d62a17ae 12727 hash_iterate(lcommunity_hash(),
e3b78da8 12728 (void (*)(struct hash_bucket *,
d62a17ae 12729 void *))lcommunity_show_all_iterator,
12730 vty);
57d187bc 12731
d62a17ae 12732 return CMD_SUCCESS;
57d187bc 12733}
2986cac2 12734/* Graceful Restart */
12735
12736static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
12737 struct bgp *bgp,
12738 bool use_json,
12739 json_object *json)
2986cac2 12740{
57d187bc
JS
12741
12742
2986cac2 12743 vty_out(vty, "\n%s", SHOW_GR_HEADER);
12744
7318ae88 12745 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 12746
12747 switch (bgp_global_gr_mode) {
12748
12749 case GLOBAL_HELPER:
13909c4f 12750 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 12751 break;
12752
12753 case GLOBAL_GR:
13909c4f 12754 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 12755 break;
12756
12757 case GLOBAL_DISABLE:
13909c4f 12758 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 12759 break;
12760
12761 case GLOBAL_INVALID:
2986cac2 12762 vty_out(vty,
2ba1fe69 12763 "Global BGP GR Mode Invalid\n");
2986cac2 12764 break;
12765 }
12766 vty_out(vty, "\n");
12767}
12768
36235319
QY
12769static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
12770 enum show_type type,
12771 const char *ip_str,
12772 afi_t afi, bool use_json)
2986cac2 12773{
12774 if ((afi == AFI_MAX) && (ip_str == NULL)) {
12775 afi = AFI_IP;
12776
12777 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
12778
36235319
QY
12779 bgp_show_neighbor_graceful_restart_vty(
12780 vty, type, ip_str, afi, use_json);
2986cac2 12781 afi++;
12782 }
12783 } else if (afi != AFI_MAX) {
36235319
QY
12784 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
12785 use_json);
2986cac2 12786 } else {
12787 return CMD_ERR_INCOMPLETE;
12788 }
12789
12790 return CMD_SUCCESS;
12791}
12792/* Graceful Restart */
12793
f412b39a 12794DEFUN (show_ip_bgp_attr_info,
718e3744 12795 show_ip_bgp_attr_info_cmd,
bec37ba5 12796 "show [ip] bgp attribute-info",
718e3744 12797 SHOW_STR
12798 IP_STR
12799 BGP_STR
12800 "List all bgp attribute information\n")
12801{
d62a17ae 12802 attr_show_all(vty);
12803 return CMD_SUCCESS;
718e3744 12804}
6b0655a2 12805
03915806
CS
12806static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
12807 afi_t afi, safi_t safi,
12808 bool use_json, json_object *json)
53089bec 12809{
12810 struct bgp *bgp;
12811 struct listnode *node;
12812 char *vname;
12813 char buf1[INET6_ADDRSTRLEN];
12814 char *ecom_str;
12815 vpn_policy_direction_t dir;
12816
03915806 12817 if (json) {
b46dfd20
DS
12818 json_object *json_import_vrfs = NULL;
12819 json_object *json_export_vrfs = NULL;
12820
b46dfd20
DS
12821 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12822
53089bec 12823 if (!bgp) {
b46dfd20
DS
12824 vty_out(vty, "%s\n",
12825 json_object_to_json_string_ext(
12826 json,
12827 JSON_C_TO_STRING_PRETTY));
12828 json_object_free(json);
12829
53089bec 12830 return CMD_WARNING;
12831 }
b46dfd20 12832
94d4c685
DS
12833 /* Provide context for the block */
12834 json_object_string_add(json, "vrf", name ? name : "default");
12835 json_object_string_add(json, "afiSafi",
5cb5f4d0 12836 get_afi_safi_str(afi, safi, true));
94d4c685 12837
b46dfd20
DS
12838 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12839 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
12840 json_object_string_add(json, "importFromVrfs", "none");
12841 json_object_string_add(json, "importRts", "none");
12842 } else {
6ce24e52
DS
12843 json_import_vrfs = json_object_new_array();
12844
b46dfd20
DS
12845 for (ALL_LIST_ELEMENTS_RO(
12846 bgp->vpn_policy[afi].import_vrf,
12847 node, vname))
12848 json_object_array_add(json_import_vrfs,
12849 json_object_new_string(vname));
12850
b20875ea
CS
12851 json_object_object_add(json, "importFromVrfs",
12852 json_import_vrfs);
b46dfd20 12853 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
12854 if (bgp->vpn_policy[afi].rtlist[dir]) {
12855 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12856 bgp->vpn_policy[afi].rtlist[dir],
12857 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12858 json_object_string_add(json, "importRts",
12859 ecom_str);
12860 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12861 } else
12862 json_object_string_add(json, "importRts",
12863 "none");
b46dfd20
DS
12864 }
12865
12866 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12867 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
12868 json_object_string_add(json, "exportToVrfs", "none");
12869 json_object_string_add(json, "routeDistinguisher",
12870 "none");
12871 json_object_string_add(json, "exportRts", "none");
12872 } else {
6ce24e52
DS
12873 json_export_vrfs = json_object_new_array();
12874
b46dfd20
DS
12875 for (ALL_LIST_ELEMENTS_RO(
12876 bgp->vpn_policy[afi].export_vrf,
12877 node, vname))
12878 json_object_array_add(json_export_vrfs,
12879 json_object_new_string(vname));
12880 json_object_object_add(json, "exportToVrfs",
12881 json_export_vrfs);
12882 json_object_string_add(json, "routeDistinguisher",
12883 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12884 buf1, RD_ADDRSTRLEN));
12885
12886 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
12887 if (bgp->vpn_policy[afi].rtlist[dir]) {
12888 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12889 bgp->vpn_policy[afi].rtlist[dir],
12890 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12891 json_object_string_add(json, "exportRts",
12892 ecom_str);
12893 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12894 } else
12895 json_object_string_add(json, "exportRts",
12896 "none");
b46dfd20
DS
12897 }
12898
03915806
CS
12899 if (use_json) {
12900 vty_out(vty, "%s\n",
12901 json_object_to_json_string_ext(json,
b46dfd20 12902 JSON_C_TO_STRING_PRETTY));
03915806
CS
12903 json_object_free(json);
12904 }
53089bec 12905 } else {
b46dfd20
DS
12906 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12907
53089bec 12908 if (!bgp) {
b46dfd20 12909 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 12910 return CMD_WARNING;
12911 }
53089bec 12912
b46dfd20
DS
12913 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12914 BGP_CONFIG_VRF_TO_VRF_IMPORT))
12915 vty_out(vty,
12916 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 12917 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12918 else {
12919 vty_out(vty,
12920 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 12921 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12922
12923 for (ALL_LIST_ELEMENTS_RO(
12924 bgp->vpn_policy[afi].import_vrf,
12925 node, vname))
12926 vty_out(vty, " %s\n", vname);
12927
12928 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
12929 ecom_str = NULL;
12930 if (bgp->vpn_policy[afi].rtlist[dir]) {
12931 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12932 bgp->vpn_policy[afi].rtlist[dir],
12933 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 12934 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 12935
b20875ea
CS
12936 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12937 } else
12938 vty_out(vty, "Import RT(s):\n");
53089bec 12939 }
53089bec 12940
b46dfd20
DS
12941 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12942 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12943 vty_out(vty,
12944 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 12945 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12946 else {
12947 vty_out(vty,
04c9077f 12948 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 12949 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12950
12951 for (ALL_LIST_ELEMENTS_RO(
12952 bgp->vpn_policy[afi].export_vrf,
12953 node, vname))
12954 vty_out(vty, " %s\n", vname);
12955
12956 vty_out(vty, "RD: %s\n",
12957 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12958 buf1, RD_ADDRSTRLEN));
12959
12960 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
12961 if (bgp->vpn_policy[afi].rtlist[dir]) {
12962 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12963 bgp->vpn_policy[afi].rtlist[dir],
12964 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12965 vty_out(vty, "Export RT: %s\n", ecom_str);
12966 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12967 } else
12968 vty_out(vty, "Import RT(s):\n");
53089bec 12969 }
53089bec 12970 }
12971
12972 return CMD_SUCCESS;
12973}
12974
03915806
CS
12975static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
12976 safi_t safi, bool use_json)
12977{
12978 struct listnode *node, *nnode;
12979 struct bgp *bgp;
12980 char *vrf_name = NULL;
12981 json_object *json = NULL;
12982 json_object *json_vrf = NULL;
12983 json_object *json_vrfs = NULL;
12984
12985 if (use_json) {
12986 json = json_object_new_object();
12987 json_vrfs = json_object_new_object();
12988 }
12989
12990 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12991
12992 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
12993 vrf_name = bgp->name;
12994
12995 if (use_json) {
12996 json_vrf = json_object_new_object();
12997 } else {
12998 vty_out(vty, "\nInstance %s:\n",
12999 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13000 ? VRF_DEFAULT_NAME : bgp->name);
13001 }
13002 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
13003 if (use_json) {
13004 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13005 json_object_object_add(json_vrfs,
13006 VRF_DEFAULT_NAME, json_vrf);
13007 else
13008 json_object_object_add(json_vrfs, vrf_name,
13009 json_vrf);
13010 }
13011 }
13012
13013 if (use_json) {
13014 json_object_object_add(json, "vrfs", json_vrfs);
13015 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
13016 JSON_C_TO_STRING_PRETTY));
13017 json_object_free(json);
13018 }
13019
13020 return CMD_SUCCESS;
13021}
13022
53089bec 13023/* "show [ip] bgp route-leak" command. */
13024DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
13025 show_ip_bgp_route_leak_cmd,
13026 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
13027 SHOW_STR
13028 IP_STR
13029 BGP_STR
13030 BGP_INSTANCE_HELP_STR
13031 BGP_AFI_HELP_STR
13032 BGP_SAFI_HELP_STR
13033 "Route leaking information\n"
13034 JSON_STR)
53089bec 13035{
13036 char *vrf = NULL;
13037 afi_t afi = AFI_MAX;
13038 safi_t safi = SAFI_MAX;
13039
9f049418 13040 bool uj = use_json(argc, argv);
53089bec 13041 int idx = 0;
03915806 13042 json_object *json = NULL;
53089bec 13043
13044 /* show [ip] bgp */
13045 if (argv_find(argv, argc, "ip", &idx)) {
13046 afi = AFI_IP;
13047 safi = SAFI_UNICAST;
13048 }
13049 /* [vrf VIEWVRFNAME] */
13050 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
13051 vty_out(vty,
13052 "%% This command is not applicable to BGP views\n");
53089bec 13053 return CMD_WARNING;
13054 }
13055
9a8bdf1c
PG
13056 if (argv_find(argv, argc, "vrf", &idx)) {
13057 vrf = argv[idx + 1]->arg;
13058 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13059 vrf = NULL;
13060 }
53089bec 13061 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13062 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13063 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13064 }
13065
13066 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
13067 vty_out(vty,
13068 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 13069 return CMD_WARNING;
13070 }
13071
03915806
CS
13072 if (vrf && strmatch(vrf, "all"))
13073 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13074
13075 if (uj)
13076 json = json_object_new_object();
13077
13078 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 13079}
13080
d62a17ae 13081static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13082 safi_t safi)
f186de26 13083{
d62a17ae 13084 struct listnode *node, *nnode;
13085 struct bgp *bgp;
f186de26 13086
d62a17ae 13087 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13088 vty_out(vty, "\nInstance %s:\n",
13089 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13090 ? VRF_DEFAULT_NAME
d62a17ae 13091 : bgp->name);
13092 update_group_show(bgp, afi, safi, vty, 0);
13093 }
f186de26 13094}
13095
d62a17ae 13096static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13097 int safi, uint64_t subgrp_id)
4fb25c53 13098{
d62a17ae 13099 struct bgp *bgp;
4fb25c53 13100
d62a17ae 13101 if (name) {
13102 if (strmatch(name, "all")) {
13103 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13104 return CMD_SUCCESS;
13105 } else {
13106 bgp = bgp_lookup_by_name(name);
13107 }
13108 } else {
13109 bgp = bgp_get_default();
13110 }
4fb25c53 13111
d62a17ae 13112 if (bgp)
13113 update_group_show(bgp, afi, safi, vty, subgrp_id);
13114 return CMD_SUCCESS;
4fb25c53
DW
13115}
13116
8fe8a7f6
DS
13117DEFUN (show_ip_bgp_updgrps,
13118 show_ip_bgp_updgrps_cmd,
c1a44e43 13119 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 13120 SHOW_STR
13121 IP_STR
13122 BGP_STR
13123 BGP_INSTANCE_HELP_STR
c9e571b4 13124 BGP_AFI_HELP_STR
9bedbb1e 13125 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
13126 "Detailed info about dynamic update groups\n"
13127 "Specific subgroup to display detailed info for\n")
8386ac43 13128{
d62a17ae 13129 char *vrf = NULL;
13130 afi_t afi = AFI_IP6;
13131 safi_t safi = SAFI_UNICAST;
13132 uint64_t subgrp_id = 0;
13133
13134 int idx = 0;
13135
13136 /* show [ip] bgp */
13137 if (argv_find(argv, argc, "ip", &idx))
13138 afi = AFI_IP;
9a8bdf1c
PG
13139 /* [<vrf> VIEWVRFNAME] */
13140 if (argv_find(argv, argc, "vrf", &idx)) {
13141 vrf = argv[idx + 1]->arg;
13142 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13143 vrf = NULL;
13144 } else if (argv_find(argv, argc, "view", &idx))
13145 /* [<view> VIEWVRFNAME] */
13146 vrf = argv[idx + 1]->arg;
d62a17ae 13147 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13148 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13149 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13150 }
5bf15956 13151
d62a17ae 13152 /* get subgroup id, if provided */
13153 idx = argc - 1;
13154 if (argv[idx]->type == VARIABLE_TKN)
13155 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 13156
d62a17ae 13157 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
13158}
13159
f186de26 13160DEFUN (show_bgp_instance_all_ipv6_updgrps,
13161 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 13162 "show [ip] bgp <view|vrf> all update-groups",
f186de26 13163 SHOW_STR
716b2d8a 13164 IP_STR
f186de26 13165 BGP_STR
13166 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 13167 "Detailed info about dynamic update groups\n")
f186de26 13168{
d62a17ae 13169 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13170 return CMD_SUCCESS;
f186de26 13171}
13172
43d3f4fc
DS
13173DEFUN (show_bgp_l2vpn_evpn_updgrps,
13174 show_bgp_l2vpn_evpn_updgrps_cmd,
13175 "show [ip] bgp l2vpn evpn update-groups",
13176 SHOW_STR
13177 IP_STR
13178 BGP_STR
13179 "l2vpn address family\n"
13180 "evpn sub-address family\n"
13181 "Detailed info about dynamic update groups\n")
13182{
13183 char *vrf = NULL;
13184 uint64_t subgrp_id = 0;
13185
13186 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13187 return CMD_SUCCESS;
13188}
13189
5bf15956
DW
13190DEFUN (show_bgp_updgrps_stats,
13191 show_bgp_updgrps_stats_cmd,
716b2d8a 13192 "show [ip] bgp update-groups statistics",
3f9c7369 13193 SHOW_STR
716b2d8a 13194 IP_STR
3f9c7369 13195 BGP_STR
0c7b1b01 13196 "Detailed info about dynamic update groups\n"
3f9c7369
DS
13197 "Statistics\n")
13198{
d62a17ae 13199 struct bgp *bgp;
3f9c7369 13200
d62a17ae 13201 bgp = bgp_get_default();
13202 if (bgp)
13203 update_group_show_stats(bgp, vty);
3f9c7369 13204
d62a17ae 13205 return CMD_SUCCESS;
3f9c7369
DS
13206}
13207
8386ac43 13208DEFUN (show_bgp_instance_updgrps_stats,
13209 show_bgp_instance_updgrps_stats_cmd,
18c57037 13210 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 13211 SHOW_STR
716b2d8a 13212 IP_STR
8386ac43 13213 BGP_STR
13214 BGP_INSTANCE_HELP_STR
0c7b1b01 13215 "Detailed info about dynamic update groups\n"
8386ac43 13216 "Statistics\n")
13217{
d62a17ae 13218 int idx_word = 3;
13219 struct bgp *bgp;
8386ac43 13220
d62a17ae 13221 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13222 if (bgp)
13223 update_group_show_stats(bgp, vty);
8386ac43 13224
d62a17ae 13225 return CMD_SUCCESS;
8386ac43 13226}
13227
d62a17ae 13228static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13229 afi_t afi, safi_t safi,
13230 const char *what, uint64_t subgrp_id)
3f9c7369 13231{
d62a17ae 13232 struct bgp *bgp;
8386ac43 13233
d62a17ae 13234 if (name)
13235 bgp = bgp_lookup_by_name(name);
13236 else
13237 bgp = bgp_get_default();
8386ac43 13238
d62a17ae 13239 if (bgp) {
13240 if (!strcmp(what, "advertise-queue"))
13241 update_group_show_adj_queue(bgp, afi, safi, vty,
13242 subgrp_id);
13243 else if (!strcmp(what, "advertised-routes"))
13244 update_group_show_advertised(bgp, afi, safi, vty,
13245 subgrp_id);
13246 else if (!strcmp(what, "packet-queue"))
13247 update_group_show_packet_queue(bgp, afi, safi, vty,
13248 subgrp_id);
13249 }
3f9c7369
DS
13250}
13251
dc64bdec
QY
13252DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13253 show_ip_bgp_instance_updgrps_adj_s_cmd,
13254 "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",
13255 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13256 BGP_SAFI_HELP_STR
13257 "Detailed info about dynamic update groups\n"
13258 "Specific subgroup to display info for\n"
13259 "Advertisement queue\n"
13260 "Announced routes\n"
13261 "Packet queue\n")
3f9c7369 13262{
dc64bdec
QY
13263 uint64_t subgrp_id = 0;
13264 afi_t afiz;
13265 safi_t safiz;
13266 if (sgid)
13267 subgrp_id = strtoull(sgid, NULL, 10);
13268
13269 if (!ip && !afi)
13270 afiz = AFI_IP6;
13271 if (!ip && afi)
13272 afiz = bgp_vty_afi_from_str(afi);
13273 if (ip && !afi)
13274 afiz = AFI_IP;
13275 if (ip && afi) {
13276 afiz = bgp_vty_afi_from_str(afi);
13277 if (afiz != AFI_IP)
13278 vty_out(vty,
13279 "%% Cannot specify both 'ip' and 'ipv6'\n");
13280 return CMD_WARNING;
13281 }
d62a17ae 13282
dc64bdec 13283 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 13284
dc64bdec 13285 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 13286 return CMD_SUCCESS;
13287}
13288
d62a17ae 13289static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13290{
13291 struct listnode *node, *nnode;
13292 struct prefix *range;
13293 struct peer *conf;
13294 struct peer *peer;
13295 char buf[PREFIX2STR_BUFFER];
13296 afi_t afi;
13297 safi_t safi;
13298 const char *peer_status;
13299 const char *af_str;
13300 int lr_count;
13301 int dynamic;
13302 int af_cfgd;
13303
13304 conf = group->conf;
13305
13306 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
13307 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13308 group->name, conf->as);
d62a17ae 13309 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
13310 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13311 group->name, group->bgp->as);
d62a17ae 13312 } else {
13313 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13314 }
f14e6fdb 13315
d62a17ae 13316 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13317 vty_out(vty, " Peer-group type is internal\n");
13318 else
13319 vty_out(vty, " Peer-group type is external\n");
13320
13321 /* Display AFs configured. */
13322 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
13323 FOREACH_AFI_SAFI (afi, safi) {
13324 if (conf->afc[afi][safi]) {
13325 af_cfgd = 1;
5cb5f4d0 13326 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 13327 }
05c7a1cc 13328 }
d62a17ae 13329 if (!af_cfgd)
13330 vty_out(vty, " none\n");
13331 else
13332 vty_out(vty, "\n");
13333
13334 /* Display listen ranges (for dynamic neighbors), if any */
13335 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13336 if (afi == AFI_IP)
13337 af_str = "IPv4";
13338 else if (afi == AFI_IP6)
13339 af_str = "IPv6";
13340 else
13341 af_str = "???";
13342 lr_count = listcount(group->listen_range[afi]);
13343 if (lr_count) {
13344 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13345 af_str);
13346
13347
13348 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13349 nnode, range)) {
13350 prefix2str(range, buf, sizeof(buf));
13351 vty_out(vty, " %s\n", buf);
13352 }
13353 }
13354 }
f14e6fdb 13355
d62a17ae 13356 /* Display group members and their status */
13357 if (listcount(group->peer)) {
13358 vty_out(vty, " Peer-group members:\n");
13359 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
13360 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
13361 peer_status = "Idle (Admin)";
13362 else if (CHECK_FLAG(peer->sflags,
13363 PEER_STATUS_PREFIX_OVERFLOW))
13364 peer_status = "Idle (PfxCt)";
13365 else
13366 peer_status = lookup_msg(bgp_status_msg,
13367 peer->status, NULL);
13368
13369 dynamic = peer_dynamic_neighbor(peer);
13370 vty_out(vty, " %s %s %s \n", peer->host,
13371 dynamic ? "(dynamic)" : "", peer_status);
13372 }
13373 }
f14e6fdb 13374
d62a17ae 13375 return CMD_SUCCESS;
13376}
13377
ff9959b0
QY
13378static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13379 const char *group_name)
d62a17ae 13380{
ff9959b0 13381 struct bgp *bgp;
d62a17ae 13382 struct listnode *node, *nnode;
13383 struct peer_group *group;
ff9959b0
QY
13384 bool found = false;
13385
13386 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13387
13388 if (!bgp) {
9f049418 13389 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
13390 return CMD_WARNING;
13391 }
d62a17ae 13392
13393 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
13394 if (group_name) {
13395 if (strmatch(group->name, group_name)) {
d62a17ae 13396 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
13397 found = true;
13398 break;
d62a17ae 13399 }
ff9959b0
QY
13400 } else {
13401 bgp_show_one_peer_group(vty, group);
d62a17ae 13402 }
f14e6fdb 13403 }
f14e6fdb 13404
ff9959b0 13405 if (group_name && !found)
d62a17ae 13406 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 13407
d62a17ae 13408 return CMD_SUCCESS;
f14e6fdb
DS
13409}
13410
f14e6fdb
DS
13411DEFUN (show_ip_bgp_peer_groups,
13412 show_ip_bgp_peer_groups_cmd,
18c57037 13413 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
13414 SHOW_STR
13415 IP_STR
13416 BGP_STR
8386ac43 13417 BGP_INSTANCE_HELP_STR
d6e3c605
QY
13418 "Detailed information on BGP peer groups\n"
13419 "Peer group name\n")
f14e6fdb 13420{
d62a17ae 13421 char *vrf, *pg;
d62a17ae 13422 int idx = 0;
f14e6fdb 13423
a4d82a8a
PZ
13424 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13425 : NULL;
d62a17ae 13426 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 13427
ff9959b0 13428 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 13429}
3f9c7369 13430
d6e3c605 13431
718e3744 13432/* Redistribute VTY commands. */
13433
718e3744 13434DEFUN (bgp_redistribute_ipv4,
13435 bgp_redistribute_ipv4_cmd,
40d1cbfb 13436 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 13437 "Redistribute information from another routing protocol\n"
ab0181ee 13438 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 13439{
d62a17ae 13440 VTY_DECLVAR_CONTEXT(bgp, bgp);
13441 int idx_protocol = 1;
13442 int type;
718e3744 13443
d62a17ae 13444 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13445 if (type < 0) {
13446 vty_out(vty, "%% Invalid route type\n");
13447 return CMD_WARNING_CONFIG_FAILED;
13448 }
7f323236 13449
d62a17ae 13450 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13451 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 13452}
13453
d62a17ae 13454ALIAS_HIDDEN(
13455 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
13456 "redistribute " FRR_IP_REDIST_STR_BGPD,
13457 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 13458
718e3744 13459DEFUN (bgp_redistribute_ipv4_rmap,
13460 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 13461 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 13462 "Redistribute information from another routing protocol\n"
ab0181ee 13463 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13464 "Route map reference\n"
13465 "Pointer to route-map entries\n")
13466{
d62a17ae 13467 VTY_DECLVAR_CONTEXT(bgp, bgp);
13468 int idx_protocol = 1;
13469 int idx_word = 3;
13470 int type;
13471 struct bgp_redist *red;
e923dd62 13472 bool changed;
1de27621
DA
13473 struct route_map *route_map = route_map_lookup_warn_noexist(
13474 vty, argv[idx_word]->arg);
718e3744 13475
d62a17ae 13476 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13477 if (type < 0) {
13478 vty_out(vty, "%% Invalid route type\n");
13479 return CMD_WARNING_CONFIG_FAILED;
13480 }
718e3744 13481
d62a17ae 13482 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13483 changed =
13484 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13485 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 13486}
13487
d62a17ae 13488ALIAS_HIDDEN(
13489 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
13490 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13491 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13492 "Route map reference\n"
13493 "Pointer to route-map entries\n")
596c17ba 13494
718e3744 13495DEFUN (bgp_redistribute_ipv4_metric,
13496 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 13497 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13498 "Redistribute information from another routing protocol\n"
ab0181ee 13499 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13500 "Metric for redistributed routes\n"
13501 "Default metric\n")
13502{
d62a17ae 13503 VTY_DECLVAR_CONTEXT(bgp, bgp);
13504 int idx_protocol = 1;
13505 int idx_number = 3;
13506 int type;
d7c0a89a 13507 uint32_t metric;
d62a17ae 13508 struct bgp_redist *red;
e923dd62 13509 bool changed;
d62a17ae 13510
13511 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13512 if (type < 0) {
13513 vty_out(vty, "%% Invalid route type\n");
13514 return CMD_WARNING_CONFIG_FAILED;
13515 }
13516 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13517
13518 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13519 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13520 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13521}
13522
13523ALIAS_HIDDEN(
13524 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
13525 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13526 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13527 "Metric for redistributed routes\n"
13528 "Default metric\n")
596c17ba 13529
718e3744 13530DEFUN (bgp_redistribute_ipv4_rmap_metric,
13531 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 13532 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 13533 "Redistribute information from another routing protocol\n"
ab0181ee 13534 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13535 "Route map reference\n"
13536 "Pointer to route-map entries\n"
13537 "Metric for redistributed routes\n"
13538 "Default metric\n")
13539{
d62a17ae 13540 VTY_DECLVAR_CONTEXT(bgp, bgp);
13541 int idx_protocol = 1;
13542 int idx_word = 3;
13543 int idx_number = 5;
13544 int type;
d7c0a89a 13545 uint32_t metric;
d62a17ae 13546 struct bgp_redist *red;
e923dd62 13547 bool changed;
1de27621
DA
13548 struct route_map *route_map =
13549 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13550
13551 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13552 if (type < 0) {
13553 vty_out(vty, "%% Invalid route type\n");
13554 return CMD_WARNING_CONFIG_FAILED;
13555 }
13556 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13557
13558 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13559 changed =
13560 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13561 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13562 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13563}
13564
13565ALIAS_HIDDEN(
13566 bgp_redistribute_ipv4_rmap_metric,
13567 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
13568 "redistribute " FRR_IP_REDIST_STR_BGPD
13569 " route-map WORD metric (0-4294967295)",
13570 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13571 "Route map reference\n"
13572 "Pointer to route-map entries\n"
13573 "Metric for redistributed routes\n"
13574 "Default metric\n")
596c17ba 13575
718e3744 13576DEFUN (bgp_redistribute_ipv4_metric_rmap,
13577 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 13578 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 13579 "Redistribute information from another routing protocol\n"
ab0181ee 13580 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13581 "Metric for redistributed routes\n"
13582 "Default metric\n"
13583 "Route map reference\n"
13584 "Pointer to route-map entries\n")
13585{
d62a17ae 13586 VTY_DECLVAR_CONTEXT(bgp, bgp);
13587 int idx_protocol = 1;
13588 int idx_number = 3;
13589 int idx_word = 5;
13590 int type;
d7c0a89a 13591 uint32_t metric;
d62a17ae 13592 struct bgp_redist *red;
e923dd62 13593 bool changed;
1de27621
DA
13594 struct route_map *route_map =
13595 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13596
13597 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13598 if (type < 0) {
13599 vty_out(vty, "%% Invalid route type\n");
13600 return CMD_WARNING_CONFIG_FAILED;
13601 }
13602 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13603
13604 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13605 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
13606 changed |=
13607 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13608 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13609}
13610
13611ALIAS_HIDDEN(
13612 bgp_redistribute_ipv4_metric_rmap,
13613 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
13614 "redistribute " FRR_IP_REDIST_STR_BGPD
13615 " metric (0-4294967295) route-map WORD",
13616 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13617 "Metric for redistributed routes\n"
13618 "Default metric\n"
13619 "Route map reference\n"
13620 "Pointer to route-map entries\n")
596c17ba 13621
7c8ff89e
DS
13622DEFUN (bgp_redistribute_ipv4_ospf,
13623 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 13624 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
13625 "Redistribute information from another routing protocol\n"
13626 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13627 "Non-main Kernel Routing Table\n"
13628 "Instance ID/Table ID\n")
7c8ff89e 13629{
d62a17ae 13630 VTY_DECLVAR_CONTEXT(bgp, bgp);
13631 int idx_ospf_table = 1;
13632 int idx_number = 2;
d7c0a89a
QY
13633 unsigned short instance;
13634 unsigned short protocol;
7c8ff89e 13635
d62a17ae 13636 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 13637
d62a17ae 13638 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13639 protocol = ZEBRA_ROUTE_OSPF;
13640 else
13641 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 13642
d62a17ae 13643 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13644 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
13645}
13646
d62a17ae 13647ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
13648 "redistribute <ospf|table> (1-65535)",
13649 "Redistribute information from another routing protocol\n"
13650 "Open Shortest Path First (OSPFv2)\n"
13651 "Non-main Kernel Routing Table\n"
13652 "Instance ID/Table ID\n")
596c17ba 13653
7c8ff89e
DS
13654DEFUN (bgp_redistribute_ipv4_ospf_rmap,
13655 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 13656 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
13657 "Redistribute information from another routing protocol\n"
13658 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13659 "Non-main Kernel Routing Table\n"
13660 "Instance ID/Table ID\n"
7c8ff89e
DS
13661 "Route map reference\n"
13662 "Pointer to route-map entries\n")
13663{
d62a17ae 13664 VTY_DECLVAR_CONTEXT(bgp, bgp);
13665 int idx_ospf_table = 1;
13666 int idx_number = 2;
13667 int idx_word = 4;
13668 struct bgp_redist *red;
d7c0a89a 13669 unsigned short instance;
d62a17ae 13670 int protocol;
e923dd62 13671 bool changed;
1de27621
DA
13672 struct route_map *route_map =
13673 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13674
13675 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13676 protocol = ZEBRA_ROUTE_OSPF;
13677 else
13678 protocol = ZEBRA_ROUTE_TABLE;
13679
13680 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13681 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13682 changed =
13683 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13684 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13685}
13686
13687ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
13688 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
13689 "redistribute <ospf|table> (1-65535) route-map WORD",
13690 "Redistribute information from another routing protocol\n"
13691 "Open Shortest Path First (OSPFv2)\n"
13692 "Non-main Kernel Routing Table\n"
13693 "Instance ID/Table ID\n"
13694 "Route map reference\n"
13695 "Pointer to route-map entries\n")
596c17ba 13696
7c8ff89e
DS
13697DEFUN (bgp_redistribute_ipv4_ospf_metric,
13698 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 13699 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
13700 "Redistribute information from another routing protocol\n"
13701 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13702 "Non-main Kernel Routing Table\n"
13703 "Instance ID/Table ID\n"
7c8ff89e
DS
13704 "Metric for redistributed routes\n"
13705 "Default metric\n")
13706{
d62a17ae 13707 VTY_DECLVAR_CONTEXT(bgp, bgp);
13708 int idx_ospf_table = 1;
13709 int idx_number = 2;
13710 int idx_number_2 = 4;
d7c0a89a 13711 uint32_t metric;
d62a17ae 13712 struct bgp_redist *red;
d7c0a89a 13713 unsigned short instance;
d62a17ae 13714 int protocol;
e923dd62 13715 bool changed;
d62a17ae 13716
13717 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13718 protocol = ZEBRA_ROUTE_OSPF;
13719 else
13720 protocol = ZEBRA_ROUTE_TABLE;
13721
13722 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13723 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13724
13725 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13726 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13727 metric);
13728 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13729}
13730
13731ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
13732 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
13733 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
13734 "Redistribute information from another routing protocol\n"
13735 "Open Shortest Path First (OSPFv2)\n"
13736 "Non-main Kernel Routing Table\n"
13737 "Instance ID/Table ID\n"
13738 "Metric for redistributed routes\n"
13739 "Default metric\n")
596c17ba 13740
7c8ff89e
DS
13741DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
13742 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 13743 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
13744 "Redistribute information from another routing protocol\n"
13745 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13746 "Non-main Kernel Routing Table\n"
13747 "Instance ID/Table ID\n"
7c8ff89e
DS
13748 "Route map reference\n"
13749 "Pointer to route-map entries\n"
13750 "Metric for redistributed routes\n"
13751 "Default metric\n")
13752{
d62a17ae 13753 VTY_DECLVAR_CONTEXT(bgp, bgp);
13754 int idx_ospf_table = 1;
13755 int idx_number = 2;
13756 int idx_word = 4;
13757 int idx_number_2 = 6;
d7c0a89a 13758 uint32_t metric;
d62a17ae 13759 struct bgp_redist *red;
d7c0a89a 13760 unsigned short instance;
d62a17ae 13761 int protocol;
e923dd62 13762 bool changed;
1de27621
DA
13763 struct route_map *route_map =
13764 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13765
13766 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13767 protocol = ZEBRA_ROUTE_OSPF;
13768 else
13769 protocol = ZEBRA_ROUTE_TABLE;
13770
13771 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13772 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13773
13774 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13775 changed =
13776 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13777 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13778 metric);
13779 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13780}
13781
13782ALIAS_HIDDEN(
13783 bgp_redistribute_ipv4_ospf_rmap_metric,
13784 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
13785 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
13786 "Redistribute information from another routing protocol\n"
13787 "Open Shortest Path First (OSPFv2)\n"
13788 "Non-main Kernel Routing Table\n"
13789 "Instance ID/Table ID\n"
13790 "Route map reference\n"
13791 "Pointer to route-map entries\n"
13792 "Metric for redistributed routes\n"
13793 "Default metric\n")
596c17ba 13794
7c8ff89e
DS
13795DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
13796 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 13797 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
13798 "Redistribute information from another routing protocol\n"
13799 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13800 "Non-main Kernel Routing Table\n"
13801 "Instance ID/Table ID\n"
7c8ff89e
DS
13802 "Metric for redistributed routes\n"
13803 "Default metric\n"
13804 "Route map reference\n"
13805 "Pointer to route-map entries\n")
13806{
d62a17ae 13807 VTY_DECLVAR_CONTEXT(bgp, bgp);
13808 int idx_ospf_table = 1;
13809 int idx_number = 2;
13810 int idx_number_2 = 4;
13811 int idx_word = 6;
d7c0a89a 13812 uint32_t metric;
d62a17ae 13813 struct bgp_redist *red;
d7c0a89a 13814 unsigned short instance;
d62a17ae 13815 int protocol;
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 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13821 protocol = ZEBRA_ROUTE_OSPF;
13822 else
13823 protocol = ZEBRA_ROUTE_TABLE;
13824
13825 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13826 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13827
13828 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13829 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13830 metric);
1de27621
DA
13831 changed |=
13832 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13833 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13834}
13835
13836ALIAS_HIDDEN(
13837 bgp_redistribute_ipv4_ospf_metric_rmap,
13838 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
13839 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
13840 "Redistribute information from another routing protocol\n"
13841 "Open Shortest Path First (OSPFv2)\n"
13842 "Non-main Kernel Routing Table\n"
13843 "Instance ID/Table ID\n"
13844 "Metric for redistributed routes\n"
13845 "Default metric\n"
13846 "Route map reference\n"
13847 "Pointer to route-map entries\n")
596c17ba 13848
7c8ff89e
DS
13849DEFUN (no_bgp_redistribute_ipv4_ospf,
13850 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 13851 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
13852 NO_STR
13853 "Redistribute information from another routing protocol\n"
13854 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 13855 "Non-main Kernel Routing Table\n"
31500417
DW
13856 "Instance ID/Table ID\n"
13857 "Metric for redistributed routes\n"
13858 "Default metric\n"
13859 "Route map reference\n"
13860 "Pointer to route-map entries\n")
7c8ff89e 13861{
d62a17ae 13862 VTY_DECLVAR_CONTEXT(bgp, bgp);
13863 int idx_ospf_table = 2;
13864 int idx_number = 3;
d7c0a89a 13865 unsigned short instance;
d62a17ae 13866 int protocol;
13867
13868 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13869 protocol = ZEBRA_ROUTE_OSPF;
13870 else
13871 protocol = ZEBRA_ROUTE_TABLE;
13872
13873 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13874 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
13875}
13876
13877ALIAS_HIDDEN(
13878 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 13879 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 13880 NO_STR
13881 "Redistribute information from another routing protocol\n"
13882 "Open Shortest Path First (OSPFv2)\n"
13883 "Non-main Kernel Routing Table\n"
13884 "Instance ID/Table ID\n"
13885 "Metric for redistributed routes\n"
13886 "Default metric\n"
13887 "Route map reference\n"
13888 "Pointer to route-map entries\n")
596c17ba 13889
718e3744 13890DEFUN (no_bgp_redistribute_ipv4,
13891 no_bgp_redistribute_ipv4_cmd,
e27957c0 13892 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 13893 NO_STR
13894 "Redistribute information from another routing protocol\n"
3b14d86e 13895 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
13896 "Metric for redistributed routes\n"
13897 "Default metric\n"
13898 "Route map reference\n"
13899 "Pointer to route-map entries\n")
718e3744 13900{
d62a17ae 13901 VTY_DECLVAR_CONTEXT(bgp, bgp);
13902 int idx_protocol = 2;
13903 int type;
13904
13905 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13906 if (type < 0) {
13907 vty_out(vty, "%% Invalid route type\n");
13908 return CMD_WARNING_CONFIG_FAILED;
13909 }
13910 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
13911}
13912
13913ALIAS_HIDDEN(
13914 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
13915 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 13916 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 13917 NO_STR
13918 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13919 "Metric for redistributed routes\n"
13920 "Default metric\n"
13921 "Route map reference\n"
13922 "Pointer to route-map entries\n")
596c17ba 13923
718e3744 13924DEFUN (bgp_redistribute_ipv6,
13925 bgp_redistribute_ipv6_cmd,
40d1cbfb 13926 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 13927 "Redistribute information from another routing protocol\n"
ab0181ee 13928 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 13929{
d62a17ae 13930 VTY_DECLVAR_CONTEXT(bgp, bgp);
13931 int idx_protocol = 1;
13932 int type;
718e3744 13933
d62a17ae 13934 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13935 if (type < 0) {
13936 vty_out(vty, "%% Invalid route type\n");
13937 return CMD_WARNING_CONFIG_FAILED;
13938 }
718e3744 13939
d62a17ae 13940 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 13941 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 13942}
13943
13944DEFUN (bgp_redistribute_ipv6_rmap,
13945 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 13946 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 13947 "Redistribute information from another routing protocol\n"
ab0181ee 13948 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13949 "Route map reference\n"
13950 "Pointer to route-map entries\n")
13951{
d62a17ae 13952 VTY_DECLVAR_CONTEXT(bgp, bgp);
13953 int idx_protocol = 1;
13954 int idx_word = 3;
13955 int type;
13956 struct bgp_redist *red;
e923dd62 13957 bool changed;
1de27621
DA
13958 struct route_map *route_map =
13959 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 13960
d62a17ae 13961 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13962 if (type < 0) {
13963 vty_out(vty, "%% Invalid route type\n");
13964 return CMD_WARNING_CONFIG_FAILED;
13965 }
718e3744 13966
d62a17ae 13967 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
13968 changed =
13969 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13970 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13971}
13972
13973DEFUN (bgp_redistribute_ipv6_metric,
13974 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 13975 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13976 "Redistribute information from another routing protocol\n"
ab0181ee 13977 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13978 "Metric for redistributed routes\n"
13979 "Default metric\n")
13980{
d62a17ae 13981 VTY_DECLVAR_CONTEXT(bgp, bgp);
13982 int idx_protocol = 1;
13983 int idx_number = 3;
13984 int type;
d7c0a89a 13985 uint32_t metric;
d62a17ae 13986 struct bgp_redist *red;
e923dd62 13987 bool changed;
d62a17ae 13988
13989 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13990 if (type < 0) {
13991 vty_out(vty, "%% Invalid route type\n");
13992 return CMD_WARNING_CONFIG_FAILED;
13993 }
13994 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 13995
d62a17ae 13996 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 13997 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
13998 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13999}
14000
14001DEFUN (bgp_redistribute_ipv6_rmap_metric,
14002 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 14003 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 14004 "Redistribute information from another routing protocol\n"
ab0181ee 14005 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14006 "Route map reference\n"
14007 "Pointer to route-map entries\n"
14008 "Metric for redistributed routes\n"
14009 "Default metric\n")
14010{
d62a17ae 14011 VTY_DECLVAR_CONTEXT(bgp, bgp);
14012 int idx_protocol = 1;
14013 int idx_word = 3;
14014 int idx_number = 5;
14015 int type;
d7c0a89a 14016 uint32_t metric;
d62a17ae 14017 struct bgp_redist *red;
e923dd62 14018 bool changed;
1de27621
DA
14019 struct route_map *route_map =
14020 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14021
14022 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14023 if (type < 0) {
14024 vty_out(vty, "%% Invalid route type\n");
14025 return CMD_WARNING_CONFIG_FAILED;
14026 }
14027 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14028
d62a17ae 14029 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14030 changed =
14031 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14032 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
14033 metric);
14034 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14035}
14036
14037DEFUN (bgp_redistribute_ipv6_metric_rmap,
14038 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 14039 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 14040 "Redistribute information from another routing protocol\n"
ab0181ee 14041 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14042 "Metric for redistributed routes\n"
14043 "Default metric\n"
14044 "Route map reference\n"
14045 "Pointer to route-map entries\n")
14046{
d62a17ae 14047 VTY_DECLVAR_CONTEXT(bgp, bgp);
14048 int idx_protocol = 1;
14049 int idx_number = 3;
14050 int idx_word = 5;
14051 int type;
d7c0a89a 14052 uint32_t metric;
d62a17ae 14053 struct bgp_redist *red;
e923dd62 14054 bool changed;
1de27621
DA
14055 struct route_map *route_map =
14056 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14057
14058 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14059 if (type < 0) {
14060 vty_out(vty, "%% Invalid route type\n");
14061 return CMD_WARNING_CONFIG_FAILED;
14062 }
14063 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14064
d62a17ae 14065 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14066 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14067 metric);
1de27621
DA
14068 changed |=
14069 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14070 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14071}
14072
14073DEFUN (no_bgp_redistribute_ipv6,
14074 no_bgp_redistribute_ipv6_cmd,
e27957c0 14075 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14076 NO_STR
14077 "Redistribute information from another routing protocol\n"
3b14d86e 14078 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
14079 "Metric for redistributed routes\n"
14080 "Default metric\n"
14081 "Route map reference\n"
14082 "Pointer to route-map entries\n")
718e3744 14083{
d62a17ae 14084 VTY_DECLVAR_CONTEXT(bgp, bgp);
14085 int idx_protocol = 2;
14086 int type;
718e3744 14087
d62a17ae 14088 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14089 if (type < 0) {
14090 vty_out(vty, "%% Invalid route type\n");
14091 return CMD_WARNING_CONFIG_FAILED;
14092 }
718e3744 14093
d62a17ae 14094 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14095}
14096
dd65f45e
DL
14097static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14098 afi_t afi, safi_t safi)
d62a17ae 14099{
14100 int i;
14101
14102 /* Unicast redistribution only. */
14103 if (safi != SAFI_UNICAST)
2b791107 14104 return;
d62a17ae 14105
14106 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14107 /* Redistribute BGP does not make sense. */
14108 if (i != ZEBRA_ROUTE_BGP) {
14109 struct list *red_list;
14110 struct listnode *node;
14111 struct bgp_redist *red;
14112
14113 red_list = bgp->redist[afi][i];
14114 if (!red_list)
14115 continue;
14116
14117 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 14118 /* "redistribute" configuration. */
14119 vty_out(vty, " redistribute %s",
14120 zebra_route_string(i));
14121 if (red->instance)
14122 vty_out(vty, " %d", red->instance);
14123 if (red->redist_metric_flag)
14124 vty_out(vty, " metric %u",
14125 red->redist_metric);
14126 if (red->rmap.name)
14127 vty_out(vty, " route-map %s",
14128 red->rmap.name);
14129 vty_out(vty, "\n");
14130 }
14131 }
14132 }
718e3744 14133}
6b0655a2 14134
dd65f45e
DL
14135/* peer-group helpers for config-write */
14136
14137static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14138{
14139 if (!peer_group_active(peer)) {
14140 if (CHECK_FLAG(peer->flags_invert, flag))
14141 return !CHECK_FLAG(peer->flags, flag);
14142 else
14143 return !!CHECK_FLAG(peer->flags, flag);
14144 }
14145
14146 return !!CHECK_FLAG(peer->flags_override, flag);
14147}
14148
14149static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14150 uint32_t flag)
14151{
14152 if (!peer_group_active(peer)) {
14153 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14154 return !peer_af_flag_check(peer, afi, safi, flag);
14155 else
14156 return !!peer_af_flag_check(peer, afi, safi, flag);
14157 }
14158
14159 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14160}
14161
14162static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14163 uint8_t type, int direct)
14164{
14165 struct bgp_filter *filter;
14166
14167 if (peer_group_active(peer))
14168 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14169 type);
14170
14171 filter = &peer->filter[afi][safi];
14172 switch (type) {
14173 case PEER_FT_DISTRIBUTE_LIST:
14174 return !!(filter->dlist[direct].name);
14175 case PEER_FT_FILTER_LIST:
14176 return !!(filter->aslist[direct].name);
14177 case PEER_FT_PREFIX_LIST:
14178 return !!(filter->plist[direct].name);
14179 case PEER_FT_ROUTE_MAP:
14180 return !!(filter->map[direct].name);
14181 case PEER_FT_UNSUPPRESS_MAP:
14182 return !!(filter->usmap.name);
14183 default:
14184 return false;
14185 }
14186}
14187
14188/* Return true if the addpath type is set for peer and different from
14189 * peer-group.
14190 */
3dc339cd
DA
14191static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
14192 safi_t safi)
dd65f45e
DL
14193{
14194 enum bgp_addpath_strat type, g_type;
14195
14196 type = peer->addpath_type[afi][safi];
14197
14198 if (type != BGP_ADDPATH_NONE) {
14199 if (peer_group_active(peer)) {
14200 g_type = peer->group->conf->addpath_type[afi][safi];
14201
14202 if (type != g_type)
3dc339cd 14203 return true;
dd65f45e 14204 else
3dc339cd 14205 return false;
dd65f45e
DL
14206 }
14207
3dc339cd 14208 return true;
dd65f45e
DL
14209 }
14210
3dc339cd 14211 return false;
dd65f45e
DL
14212}
14213
b9c7bc5a 14214/* This is part of the address-family block (unicast only) */
dd65f45e 14215static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
14216 afi_t afi)
14217{
b9c7bc5a 14218 int indent = 2;
ddb5b488 14219
8a066a70 14220 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
14221 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14222 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
14223 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14224 bgp->vpn_policy[afi]
bb4f6190 14225 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
14226 else
14227 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14228 bgp->vpn_policy[afi]
14229 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14230 }
12a844a5
DS
14231 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14232 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14233 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14234 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14235 return;
14236
e70e9f8e
PZ
14237 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14238 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14239
14240 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14241
14242 } else {
14243 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14244 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14245 bgp->vpn_policy[afi].tovpn_label);
14246 }
ddb5b488
PZ
14247 }
14248 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14249 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14250 char buf[RD_ADDRSTRLEN];
b9c7bc5a 14251 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
14252 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14253 sizeof(buf)));
14254 }
14255 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14256 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14257
14258 char buf[PREFIX_STRLEN];
14259 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14260 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14261 sizeof(buf))) {
14262
b9c7bc5a
PZ
14263 vty_out(vty, "%*snexthop vpn export %s\n",
14264 indent, "", buf);
ddb5b488
PZ
14265 }
14266 }
14267 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14268 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14269 && ecommunity_cmp(
14270 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14271 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14272
14273 char *b = ecommunity_ecom2str(
14274 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14275 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14276 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
14277 XFREE(MTYPE_ECOMMUNITY_STR, b);
14278 } else {
14279 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14280 char *b = ecommunity_ecom2str(
14281 bgp->vpn_policy[afi]
14282 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14283 ECOMMUNITY_FORMAT_ROUTE_MAP,
14284 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14285 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
14286 XFREE(MTYPE_ECOMMUNITY_STR, b);
14287 }
14288 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14289 char *b = ecommunity_ecom2str(
14290 bgp->vpn_policy[afi]
14291 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14292 ECOMMUNITY_FORMAT_ROUTE_MAP,
14293 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14294 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
14295 XFREE(MTYPE_ECOMMUNITY_STR, b);
14296 }
14297 }
bb4f6190
DS
14298
14299 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 14300 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
14301 bgp->vpn_policy[afi]
14302 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 14303
301ad80a
PG
14304 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14305 char *b = ecommunity_ecom2str(
14306 bgp->vpn_policy[afi]
14307 .import_redirect_rtlist,
14308 ECOMMUNITY_FORMAT_ROUTE_MAP,
14309 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 14310
301ad80a
PG
14311 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
14312 XFREE(MTYPE_ECOMMUNITY_STR, b);
14313 }
ddb5b488
PZ
14314}
14315
dd65f45e
DL
14316static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14317 afi_t afi, safi_t safi)
14318{
14319 struct bgp_filter *filter;
14320 char *addr;
14321
14322 addr = peer->host;
14323 filter = &peer->filter[afi][safi];
14324
14325 /* distribute-list. */
14326 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14327 FILTER_IN))
14328 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14329 filter->dlist[FILTER_IN].name);
14330
14331 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14332 FILTER_OUT))
14333 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14334 filter->dlist[FILTER_OUT].name);
14335
14336 /* prefix-list. */
14337 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14338 FILTER_IN))
14339 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14340 filter->plist[FILTER_IN].name);
14341
14342 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14343 FILTER_OUT))
14344 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14345 filter->plist[FILTER_OUT].name);
14346
14347 /* route-map. */
14348 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14349 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14350 filter->map[RMAP_IN].name);
14351
14352 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14353 RMAP_OUT))
14354 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14355 filter->map[RMAP_OUT].name);
14356
14357 /* unsuppress-map */
14358 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14359 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14360 filter->usmap.name);
14361
14362 /* filter-list. */
14363 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14364 FILTER_IN))
14365 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14366 filter->aslist[FILTER_IN].name);
14367
14368 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14369 FILTER_OUT))
14370 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14371 filter->aslist[FILTER_OUT].name);
14372}
14373
14374/* BGP peer configuration display function. */
14375static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14376 struct peer *peer)
14377{
14378 struct peer *g_peer = NULL;
14379 char buf[SU_ADDRSTRLEN];
14380 char *addr;
14381 int if_pg_printed = false;
14382 int if_ras_printed = false;
14383
14384 /* Skip dynamic neighbors. */
14385 if (peer_dynamic_neighbor(peer))
14386 return;
14387
14388 if (peer->conf_if)
14389 addr = peer->conf_if;
14390 else
14391 addr = peer->host;
14392
14393 /************************************
14394 ****** Global to the neighbor ******
14395 ************************************/
14396 if (peer->conf_if) {
14397 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14398 vty_out(vty, " neighbor %s interface v6only", addr);
14399 else
14400 vty_out(vty, " neighbor %s interface", addr);
14401
14402 if (peer_group_active(peer)) {
14403 vty_out(vty, " peer-group %s", peer->group->name);
14404 if_pg_printed = true;
14405 } else if (peer->as_type == AS_SPECIFIED) {
14406 vty_out(vty, " remote-as %u", peer->as);
14407 if_ras_printed = true;
14408 } else if (peer->as_type == AS_INTERNAL) {
14409 vty_out(vty, " remote-as internal");
14410 if_ras_printed = true;
14411 } else if (peer->as_type == AS_EXTERNAL) {
14412 vty_out(vty, " remote-as external");
14413 if_ras_printed = true;
14414 }
14415
14416 vty_out(vty, "\n");
14417 }
14418
14419 /* remote-as and peer-group */
14420 /* peer is a member of a peer-group */
14421 if (peer_group_active(peer)) {
14422 g_peer = peer->group->conf;
14423
14424 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14425 if (peer->as_type == AS_SPECIFIED) {
14426 vty_out(vty, " neighbor %s remote-as %u\n",
14427 addr, peer->as);
14428 } else if (peer->as_type == AS_INTERNAL) {
14429 vty_out(vty,
14430 " neighbor %s remote-as internal\n",
14431 addr);
14432 } else if (peer->as_type == AS_EXTERNAL) {
14433 vty_out(vty,
14434 " neighbor %s remote-as external\n",
14435 addr);
14436 }
14437 }
14438
14439 /* For swpX peers we displayed the peer-group
14440 * via 'neighbor swpX interface peer-group PGNAME' */
14441 if (!if_pg_printed)
14442 vty_out(vty, " neighbor %s peer-group %s\n", addr,
14443 peer->group->name);
14444 }
14445
14446 /* peer is NOT a member of a peer-group */
14447 else {
14448 /* peer is a peer-group, declare the peer-group */
14449 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
14450 vty_out(vty, " neighbor %s peer-group\n", addr);
14451 }
14452
14453 if (!if_ras_printed) {
14454 if (peer->as_type == AS_SPECIFIED) {
14455 vty_out(vty, " neighbor %s remote-as %u\n",
14456 addr, peer->as);
14457 } else if (peer->as_type == AS_INTERNAL) {
14458 vty_out(vty,
14459 " neighbor %s remote-as internal\n",
14460 addr);
14461 } else if (peer->as_type == AS_EXTERNAL) {
14462 vty_out(vty,
14463 " neighbor %s remote-as external\n",
14464 addr);
14465 }
14466 }
14467 }
14468
14469 /* local-as */
14470 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
14471 vty_out(vty, " neighbor %s local-as %u", addr,
14472 peer->change_local_as);
14473 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
14474 vty_out(vty, " no-prepend");
14475 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
14476 vty_out(vty, " replace-as");
14477 vty_out(vty, "\n");
14478 }
14479
14480 /* description */
14481 if (peer->desc) {
14482 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
14483 }
14484
14485 /* shutdown */
14486 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
14487 if (peer->tx_shutdown_message)
14488 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
14489 peer->tx_shutdown_message);
14490 else
14491 vty_out(vty, " neighbor %s shutdown\n", addr);
14492 }
14493
14494 /* bfd */
14495 if (peer->bfd_info) {
14496 if (!peer_group_active(peer) || !g_peer->bfd_info) {
14497 bgp_bfd_peer_config_write(vty, peer, addr);
14498 }
14499 }
14500
14501 /* password */
14502 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
14503 vty_out(vty, " neighbor %s password %s\n", addr,
14504 peer->password);
14505
14506 /* neighbor solo */
14507 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
14508 if (!peer_group_active(peer)) {
14509 vty_out(vty, " neighbor %s solo\n", addr);
14510 }
14511 }
14512
14513 /* BGP port */
14514 if (peer->port != BGP_PORT_DEFAULT) {
14515 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
14516 }
14517
14518 /* Local interface name */
14519 if (peer->ifname) {
14520 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
14521 }
14522
14523 /* passive */
14524 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
14525 vty_out(vty, " neighbor %s passive\n", addr);
14526
14527 /* ebgp-multihop */
14528 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
14529 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
14530 && peer->ttl == MAXTTL)) {
dd65f45e
DL
14531 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
14532 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
14533 peer->ttl);
14534 }
14535 }
14536
14537 /* ttl-security hops */
e2521429 14538 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
14539 if (!peer_group_active(peer)
14540 || g_peer->gtsm_hops != peer->gtsm_hops) {
14541 vty_out(vty, " neighbor %s ttl-security hops %d\n",
14542 addr, peer->gtsm_hops);
14543 }
14544 }
14545
14546 /* disable-connected-check */
14547 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
14548 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
14549
14550 /* enforce-first-as */
14551 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
14552 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
14553
14554 /* update-source */
14555 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
14556 if (peer->update_source)
14557 vty_out(vty, " neighbor %s update-source %s\n", addr,
14558 sockunion2str(peer->update_source, buf,
14559 SU_ADDRSTRLEN));
14560 else if (peer->update_if)
14561 vty_out(vty, " neighbor %s update-source %s\n", addr,
14562 peer->update_if);
14563 }
14564
14565 /* advertisement-interval */
14566 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
14567 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
14568 peer->routeadv);
14569
14570 /* timers */
14571 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
14572 vty_out(vty, " neighbor %s timers %u %u\n", addr,
14573 peer->keepalive, peer->holdtime);
14574
14575 /* timers connect */
14576 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
14577 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14578 peer->connect);
5d5393b9
DL
14579 /* need special-case handling for changed default values due to
14580 * config profile / version (because there is no "timers bgp connect"
14581 * command, we need to save this per-peer :/)
14582 */
14583 else if (!peer_group_active(peer) && !peer->connect &&
14584 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
14585 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14586 peer->bgp->default_connect_retry);
dd65f45e
DL
14587
14588 /* capability dynamic */
14589 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
14590 vty_out(vty, " neighbor %s capability dynamic\n", addr);
14591
14592 /* capability extended-nexthop */
14593 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
14594 if (!peer->conf_if) {
14595 if (CHECK_FLAG(peer->flags_invert,
14596 PEER_FLAG_CAPABILITY_ENHE))
14597 vty_out(vty,
14598 " no neighbor %s capability extended-nexthop\n",
14599 addr);
14600 else
14601 vty_out(vty,
14602 " neighbor %s capability extended-nexthop\n",
14603 addr);
14604 }
14605 }
14606
14607 /* dont-capability-negotiation */
14608 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
14609 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
14610
14611 /* override-capability */
14612 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
14613 vty_out(vty, " neighbor %s override-capability\n", addr);
14614
14615 /* strict-capability-match */
14616 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
14617 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
14618
14619 /* Sender side AS path loop detection. */
14620 if (peer->as_path_loop_detection)
14621 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
14622 addr);
cfd47646 14623
14624 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14625 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 14626
14627 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14628 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 14629 vty_out(vty,
14630 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
14631 } else if (CHECK_FLAG(
14632 peer->peer_gr_new_status_flag,
14633 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 14634 vty_out(vty,
14635 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
14636 } else if (
14637 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
14638 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
14639 && !(CHECK_FLAG(
14640 peer->peer_gr_new_status_flag,
14641 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
14642 vty_out(vty, " neighbor %s graceful-restart-disable\n",
14643 addr);
cfd47646 14644 }
14645 }
dd65f45e
DL
14646}
14647
14648/* BGP peer configuration display function. */
14649static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
14650 struct peer *peer, afi_t afi, safi_t safi)
14651{
14652 struct peer *g_peer = NULL;
14653 char *addr;
14654 bool flag_scomm, flag_secomm, flag_slcomm;
14655
14656 /* Skip dynamic neighbors. */
14657 if (peer_dynamic_neighbor(peer))
14658 return;
14659
14660 if (peer->conf_if)
14661 addr = peer->conf_if;
14662 else
14663 addr = peer->host;
14664
14665 /************************************
14666 ****** Per AF to the neighbor ******
14667 ************************************/
14668 if (peer_group_active(peer)) {
14669 g_peer = peer->group->conf;
14670
14671 /* If the peer-group is active but peer is not, print a 'no
14672 * activate' */
14673 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
14674 vty_out(vty, " no neighbor %s activate\n", addr);
14675 }
14676
14677 /* If the peer-group is not active but peer is, print an
14678 'activate' */
14679 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
14680 vty_out(vty, " neighbor %s activate\n", addr);
14681 }
14682 } else {
14683 if (peer->afc[afi][safi]) {
14684 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
14685 if (CHECK_FLAG(bgp->flags,
14686 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
14687 vty_out(vty, " neighbor %s activate\n",
14688 addr);
14689 }
14690 } else
14691 vty_out(vty, " neighbor %s activate\n", addr);
14692 } else {
14693 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
14694 if (!CHECK_FLAG(bgp->flags,
14695 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
14696 vty_out(vty,
14697 " no neighbor %s activate\n",
14698 addr);
14699 }
14700 }
14701 }
14702 }
14703
14704 /* addpath TX knobs */
14705 if (peergroup_af_addpath_check(peer, afi, safi)) {
14706 switch (peer->addpath_type[afi][safi]) {
14707 case BGP_ADDPATH_ALL:
14708 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
14709 addr);
14710 break;
14711 case BGP_ADDPATH_BEST_PER_AS:
14712 vty_out(vty,
14713 " neighbor %s addpath-tx-bestpath-per-AS\n",
14714 addr);
14715 break;
14716 case BGP_ADDPATH_MAX:
14717 case BGP_ADDPATH_NONE:
14718 break;
14719 }
14720 }
14721
14722 /* ORF capability. */
14723 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
14724 || peergroup_af_flag_check(peer, afi, safi,
14725 PEER_FLAG_ORF_PREFIX_RM)) {
14726 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
14727
14728 if (peergroup_af_flag_check(peer, afi, safi,
14729 PEER_FLAG_ORF_PREFIX_SM)
14730 && peergroup_af_flag_check(peer, afi, safi,
14731 PEER_FLAG_ORF_PREFIX_RM))
14732 vty_out(vty, " both");
14733 else if (peergroup_af_flag_check(peer, afi, safi,
14734 PEER_FLAG_ORF_PREFIX_SM))
14735 vty_out(vty, " send");
14736 else
14737 vty_out(vty, " receive");
14738 vty_out(vty, "\n");
14739 }
14740
14741 /* BGP flag dampening. */
14742 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14743 BGP_CONFIG_DAMPENING))
14744 bgp_config_write_damp(vty, afi, safi);
14745
14746 /* Route reflector client. */
14747 if (peergroup_af_flag_check(peer, afi, safi,
14748 PEER_FLAG_REFLECTOR_CLIENT)) {
14749 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
14750 }
14751
14752 /* next-hop-self force */
14753 if (peergroup_af_flag_check(peer, afi, safi,
14754 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
14755 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
14756 }
14757
14758 /* next-hop-self */
14759 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
14760 vty_out(vty, " neighbor %s next-hop-self\n", addr);
14761 }
14762
14763 /* remove-private-AS */
14764 if (peergroup_af_flag_check(peer, afi, safi,
14765 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
14766 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
14767 addr);
14768 }
14769
14770 else if (peergroup_af_flag_check(peer, afi, safi,
14771 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
14772 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
14773 addr);
14774 }
14775
14776 else if (peergroup_af_flag_check(peer, afi, safi,
14777 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
14778 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
14779 }
14780
14781 else if (peergroup_af_flag_check(peer, afi, safi,
14782 PEER_FLAG_REMOVE_PRIVATE_AS)) {
14783 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
14784 }
14785
14786 /* as-override */
14787 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
14788 vty_out(vty, " neighbor %s as-override\n", addr);
14789 }
14790
14791 /* send-community print. */
14792 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
14793 PEER_FLAG_SEND_COMMUNITY);
14794 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
14795 PEER_FLAG_SEND_EXT_COMMUNITY);
14796 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
14797 PEER_FLAG_SEND_LARGE_COMMUNITY);
14798
14799 if (flag_scomm && flag_secomm && flag_slcomm) {
14800 vty_out(vty, " no neighbor %s send-community all\n", addr);
14801 } else {
14802 if (flag_scomm)
14803 vty_out(vty, " no neighbor %s send-community\n", addr);
14804 if (flag_secomm)
14805 vty_out(vty,
14806 " no neighbor %s send-community extended\n",
14807 addr);
14808
14809 if (flag_slcomm)
14810 vty_out(vty, " no neighbor %s send-community large\n",
14811 addr);
14812 }
14813
14814 /* Default information */
14815 if (peergroup_af_flag_check(peer, afi, safi,
14816 PEER_FLAG_DEFAULT_ORIGINATE)) {
14817 vty_out(vty, " neighbor %s default-originate", addr);
14818
14819 if (peer->default_rmap[afi][safi].name)
14820 vty_out(vty, " route-map %s",
14821 peer->default_rmap[afi][safi].name);
14822
14823 vty_out(vty, "\n");
14824 }
14825
14826 /* Soft reconfiguration inbound. */
14827 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
14828 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
14829 addr);
14830 }
14831
14832 /* maximum-prefix. */
14833 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
14834 vty_out(vty, " neighbor %s maximum-prefix %" PRIu32, addr,
14835 peer->pmax[afi][safi]);
14836
14837 if (peer->pmax_threshold[afi][safi]
14838 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
14839 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
14840 if (peer_af_flag_check(peer, afi, safi,
14841 PEER_FLAG_MAX_PREFIX_WARNING))
14842 vty_out(vty, " warning-only");
14843 if (peer->pmax_restart[afi][safi])
14844 vty_out(vty, " restart %u",
14845 peer->pmax_restart[afi][safi]);
14846
14847 vty_out(vty, "\n");
14848 }
14849
fde246e8
DA
14850 /* maximum-prefix-out */
14851 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
14852 vty_out(vty, " neighbor %s maximum-prefix-out %" PRIu32 "\n",
14853 addr, peer->pmax_out[afi][safi]);
14854
dd65f45e
DL
14855 /* Route server client. */
14856 if (peergroup_af_flag_check(peer, afi, safi,
14857 PEER_FLAG_RSERVER_CLIENT)) {
14858 vty_out(vty, " neighbor %s route-server-client\n", addr);
14859 }
14860
14861 /* Nexthop-local unchanged. */
14862 if (peergroup_af_flag_check(peer, afi, safi,
14863 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
14864 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
14865 }
14866
14867 /* allowas-in <1-10> */
14868 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
14869 if (peer_af_flag_check(peer, afi, safi,
14870 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
14871 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
14872 } else if (peer->allowas_in[afi][safi] == 3) {
14873 vty_out(vty, " neighbor %s allowas-in\n", addr);
14874 } else {
14875 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
14876 peer->allowas_in[afi][safi]);
14877 }
14878 }
14879
14880 /* weight */
14881 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
14882 vty_out(vty, " neighbor %s weight %lu\n", addr,
14883 peer->weight[afi][safi]);
14884
14885 /* Filter. */
14886 bgp_config_write_filter(vty, peer, afi, safi);
14887
14888 /* atribute-unchanged. */
14889 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
14890 || (safi != SAFI_EVPN
14891 && peer_af_flag_check(peer, afi, safi,
14892 PEER_FLAG_NEXTHOP_UNCHANGED))
14893 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
14894
14895 if (!peer_group_active(peer)
14896 || peergroup_af_flag_check(peer, afi, safi,
14897 PEER_FLAG_AS_PATH_UNCHANGED)
14898 || peergroup_af_flag_check(peer, afi, safi,
14899 PEER_FLAG_NEXTHOP_UNCHANGED)
14900 || peergroup_af_flag_check(peer, afi, safi,
14901 PEER_FLAG_MED_UNCHANGED)) {
14902
14903 vty_out(vty,
14904 " neighbor %s attribute-unchanged%s%s%s\n",
14905 addr,
14906 peer_af_flag_check(peer, afi, safi,
14907 PEER_FLAG_AS_PATH_UNCHANGED)
14908 ? " as-path"
14909 : "",
14910 peer_af_flag_check(peer, afi, safi,
14911 PEER_FLAG_NEXTHOP_UNCHANGED)
14912 ? " next-hop"
14913 : "",
14914 peer_af_flag_check(peer, afi, safi,
14915 PEER_FLAG_MED_UNCHANGED)
14916 ? " med"
14917 : "");
14918 }
14919 }
14920}
14921
14922/* Address family based peer configuration display. */
14923static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
14924 safi_t safi)
14925{
14926 struct peer *peer;
14927 struct peer_group *group;
14928 struct listnode *node, *nnode;
14929
14930
14931 vty_frame(vty, " !\n address-family ");
14932 if (afi == AFI_IP) {
14933 if (safi == SAFI_UNICAST)
14934 vty_frame(vty, "ipv4 unicast");
14935 else if (safi == SAFI_LABELED_UNICAST)
14936 vty_frame(vty, "ipv4 labeled-unicast");
14937 else if (safi == SAFI_MULTICAST)
14938 vty_frame(vty, "ipv4 multicast");
14939 else if (safi == SAFI_MPLS_VPN)
14940 vty_frame(vty, "ipv4 vpn");
14941 else if (safi == SAFI_ENCAP)
14942 vty_frame(vty, "ipv4 encap");
14943 else if (safi == SAFI_FLOWSPEC)
14944 vty_frame(vty, "ipv4 flowspec");
14945 } else if (afi == AFI_IP6) {
14946 if (safi == SAFI_UNICAST)
14947 vty_frame(vty, "ipv6 unicast");
14948 else if (safi == SAFI_LABELED_UNICAST)
14949 vty_frame(vty, "ipv6 labeled-unicast");
14950 else if (safi == SAFI_MULTICAST)
14951 vty_frame(vty, "ipv6 multicast");
14952 else if (safi == SAFI_MPLS_VPN)
14953 vty_frame(vty, "ipv6 vpn");
14954 else if (safi == SAFI_ENCAP)
14955 vty_frame(vty, "ipv6 encap");
14956 else if (safi == SAFI_FLOWSPEC)
14957 vty_frame(vty, "ipv6 flowspec");
14958 } else if (afi == AFI_L2VPN) {
14959 if (safi == SAFI_EVPN)
14960 vty_frame(vty, "l2vpn evpn");
14961 }
14962 vty_frame(vty, "\n");
14963
14964 bgp_config_write_distance(vty, bgp, afi, safi);
14965
14966 bgp_config_write_network(vty, bgp, afi, safi);
14967
14968 bgp_config_write_redistribute(vty, bgp, afi, safi);
14969
14970 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
14971 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
14972
14973 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14974 /* Skip dynamic neighbors. */
14975 if (peer_dynamic_neighbor(peer))
14976 continue;
14977
14978 /* Do not display doppelganger peers */
14979 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14980 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
14981 }
14982
14983 bgp_config_write_maxpaths(vty, bgp, afi, safi);
14984 bgp_config_write_table_map(vty, bgp, afi, safi);
14985
14986 if (safi == SAFI_EVPN)
14987 bgp_config_write_evpn_info(vty, bgp, afi, safi);
14988
14989 if (safi == SAFI_FLOWSPEC)
14990 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
14991
14992 if (safi == SAFI_UNICAST) {
14993 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
14994 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14995 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
14996
14997 vty_out(vty, " export vpn\n");
14998 }
14999 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15000 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
15001
15002 vty_out(vty, " import vpn\n");
15003 }
15004 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15005 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15006 char *name;
15007
15008 for (ALL_LIST_ELEMENTS_RO(
15009 bgp->vpn_policy[afi].import_vrf, node,
15010 name))
15011 vty_out(vty, " import vrf %s\n", name);
15012 }
15013 }
15014
15015 vty_endframe(vty, " exit-address-family\n");
15016}
15017
15018int bgp_config_write(struct vty *vty)
15019{
15020 struct bgp *bgp;
15021 struct peer_group *group;
15022 struct peer *peer;
15023 struct listnode *node, *nnode;
15024 struct listnode *mnode, *mnnode;
15025
15026 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
15027 vty_out(vty, "bgp route-map delay-timer %u\n",
15028 bm->rmap_update_timer);
15029
15030 /* BGP configuration. */
15031 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
15032
15033 /* skip all auto created vrf as they dont have user config */
15034 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
15035 continue;
15036
15037 /* Router bgp ASN */
15038 vty_out(vty, "router bgp %u", bgp->as);
15039
15040 if (bgp->name)
15041 vty_out(vty, " %s %s",
15042 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
15043 ? "view" : "vrf", bgp->name);
15044 vty_out(vty, "\n");
15045
15046 /* BGP fast-external-failover. */
15047 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
15048 vty_out(vty, " no bgp fast-external-failover\n");
15049
15050 /* BGP router ID. */
15051 if (bgp->router_id_static.s_addr != 0)
15052 vty_out(vty, " bgp router-id %s\n",
15053 inet_ntoa(bgp->router_id_static));
15054
15055 /* BGP log-neighbor-changes. */
892fedb6 15056 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 15057 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 15058 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
15059 CHECK_FLAG(bgp->flags,
15060 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
15061 ? ""
15062 : "no ");
15063
15064 /* BGP configuration. */
892fedb6 15065 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
15066 vty_out(vty, " bgp always-compare-med\n");
15067
15068 /* RFC8212 default eBGP policy. */
15069 if (bgp->ebgp_requires_policy
15070 == DEFAULT_EBGP_POLICY_ENABLED)
15071 vty_out(vty, " bgp ebgp-requires-policy\n");
15072
15073 /* draft-ietf-idr-deprecate-as-set-confed-set */
15074 if (bgp->reject_as_sets == BGP_REJECT_AS_SETS_ENABLED)
15075 vty_out(vty, " bgp reject-as-sets\n");
15076
15077 /* BGP default ipv4-unicast. */
892fedb6 15078 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
15079 vty_out(vty, " no bgp default ipv4-unicast\n");
15080
15081 /* BGP default local-preference. */
15082 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15083 vty_out(vty, " bgp default local-preference %u\n",
15084 bgp->default_local_pref);
15085
15086 /* BGP default show-hostname */
892fedb6 15087 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 15088 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 15089 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 15090 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
15091 ? ""
15092 : "no ");
15093
15094 /* BGP default subgroup-pkt-queue-max. */
15095 if (bgp->default_subgroup_pkt_queue_max
15096 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15097 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15098 bgp->default_subgroup_pkt_queue_max);
15099
15100 /* BGP client-to-client reflection. */
892fedb6 15101 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
15102 vty_out(vty, " no bgp client-to-client reflection\n");
15103
15104 /* BGP cluster ID. */
15105 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15106 vty_out(vty, " bgp cluster-id %s\n",
15107 inet_ntoa(bgp->cluster_id));
15108
15109 /* Disable ebgp connected nexthop check */
892fedb6 15110 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
15111 vty_out(vty,
15112 " bgp disable-ebgp-connected-route-check\n");
15113
15114 /* Confederation identifier*/
15115 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15116 vty_out(vty, " bgp confederation identifier %u\n",
15117 bgp->confed_id);
15118
15119 /* Confederation peer */
15120 if (bgp->confed_peers_cnt > 0) {
15121 int i;
15122
15123 vty_out(vty, " bgp confederation peers");
15124
15125 for (i = 0; i < bgp->confed_peers_cnt; i++)
15126 vty_out(vty, " %u", bgp->confed_peers[i]);
15127
15128 vty_out(vty, "\n");
15129 }
15130
15131 /* BGP deterministic-med. */
892fedb6 15132 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 15133 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 15134 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
15135 CHECK_FLAG(bgp->flags,
15136 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
15137 ? ""
15138 : "no ");
15139
15140 /* BGP update-delay. */
15141 bgp_config_write_update_delay(vty, bgp);
15142
15143 if (bgp->v_maxmed_onstartup
15144 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15145 vty_out(vty, " bgp max-med on-startup %u",
15146 bgp->v_maxmed_onstartup);
15147 if (bgp->maxmed_onstartup_value
15148 != BGP_MAXMED_VALUE_DEFAULT)
15149 vty_out(vty, " %u",
15150 bgp->maxmed_onstartup_value);
15151 vty_out(vty, "\n");
15152 }
15153 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15154 vty_out(vty, " bgp max-med administrative");
15155 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15156 vty_out(vty, " %u", bgp->maxmed_admin_value);
15157 vty_out(vty, "\n");
15158 }
15159
15160 /* write quanta */
15161 bgp_config_write_wpkt_quanta(vty, bgp);
15162 /* read quanta */
15163 bgp_config_write_rpkt_quanta(vty, bgp);
15164
15165 /* coalesce time */
15166 bgp_config_write_coalesce_time(vty, bgp);
15167
15168 /* BGP graceful-restart. */
15169 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15170 vty_out(vty,
15171 " bgp graceful-restart stalepath-time %u\n",
15172 bgp->stalepath_time);
cfd47646 15173
dd65f45e
DL
15174 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15175 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15176 bgp->restart_time);
cfd47646 15177
15178 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15179 vty_out(vty,
15180 " bgp graceful-restart select-defer-time %u\n",
15181 bgp->select_defer_time);
15182
15183 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
15184 vty_out(vty, " bgp graceful-restart\n");
15185
cfd47646 15186 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15187 vty_out(vty, " bgp graceful-restart-disable\n");
15188
dd65f45e 15189 /* BGP graceful-shutdown */
892fedb6 15190 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
dd65f45e
DL
15191 vty_out(vty, " bgp graceful-shutdown\n");
15192
15193 /* BGP graceful-restart Preserve State F bit. */
892fedb6 15194 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
15195 vty_out(vty,
15196 " bgp graceful-restart preserve-fw-state\n");
15197
dc95985f 15198 /* Stale timer for RIB */
15199 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15200 vty_out(vty,
15201 " bgp graceful-restart rib-stale-time %u\n",
15202 bgp->rib_stale_time);
15203
dd65f45e 15204 /* BGP bestpath method. */
892fedb6 15205 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 15206 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 15207 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
15208 vty_out(vty, " bgp bestpath as-path confed\n");
15209
892fedb6
DA
15210 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15211 if (CHECK_FLAG(bgp->flags,
15212 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
15213 vty_out(vty,
15214 " bgp bestpath as-path multipath-relax as-set\n");
15215 } else {
15216 vty_out(vty,
15217 " bgp bestpath as-path multipath-relax\n");
15218 }
15219 }
15220
892fedb6 15221 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
15222 vty_out(vty,
15223 " bgp route-reflector allow-outbound-policy\n");
15224 }
892fedb6 15225 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 15226 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
15227 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
15228 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 15229 vty_out(vty, " bgp bestpath med");
892fedb6 15230 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 15231 vty_out(vty, " confed");
892fedb6
DA
15232 if (CHECK_FLAG(bgp->flags,
15233 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
15234 vty_out(vty, " missing-as-worst");
15235 vty_out(vty, "\n");
15236 }
15237
f7e1c681 15238 /* Link bandwidth handling. */
15239 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
15240 vty_out(vty, " bgp bestpath bandwidth ignore\n");
15241 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
15242 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
15243 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
15244 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
15245
dd65f45e 15246 /* BGP network import check. */
892fedb6 15247 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 15248 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 15249 vty_out(vty, " %sbgp network import-check\n",
892fedb6 15250 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
15251 ? ""
15252 : "no ");
15253
15254 /* BGP timers configuration. */
5d5393b9
DL
15255 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15256 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
15257 vty_out(vty, " timers bgp %u %u\n",
15258 bgp->default_keepalive, bgp->default_holdtime);
15259
15260 /* peer-group */
15261 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15262 bgp_config_write_peer_global(vty, bgp, group->conf);
15263 }
15264
15265 /* Normal neighbor configuration. */
15266 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15267 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15268 bgp_config_write_peer_global(vty, bgp, peer);
15269 }
15270
15271 /* listen range and limit for dynamic BGP neighbors */
15272 bgp_config_write_listen(vty, bgp);
15273
15274 /*
15275 * BGP default autoshutdown neighbors
15276 *
15277 * This must be placed after any peer and peer-group
15278 * configuration, to avoid setting all peers to shutdown after
15279 * a daemon restart, which is undesired behavior. (see #2286)
15280 */
15281 if (bgp->autoshutdown)
15282 vty_out(vty, " bgp default shutdown\n");
15283
15284 /* IPv4 unicast configuration. */
15285 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15286
15287 /* IPv4 multicast configuration. */
15288 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15289
15290 /* IPv4 labeled-unicast configuration. */
15291 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15292
15293 /* IPv4 VPN configuration. */
15294 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15295
15296 /* ENCAPv4 configuration. */
15297 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15298
15299 /* FLOWSPEC v4 configuration. */
15300 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15301
15302 /* IPv6 unicast configuration. */
15303 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15304
15305 /* IPv6 multicast configuration. */
15306 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15307
15308 /* IPv6 labeled-unicast configuration. */
15309 bgp_config_write_family(vty, bgp, AFI_IP6,
15310 SAFI_LABELED_UNICAST);
15311
15312 /* IPv6 VPN configuration. */
15313 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15314
15315 /* ENCAPv6 configuration. */
15316 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15317
15318 /* FLOWSPEC v6 configuration. */
15319 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15320
15321 /* EVPN configuration. */
15322 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15323
15324 hook_call(bgp_inst_config_write, bgp, vty);
15325
49e5a4a0 15326#ifdef ENABLE_BGP_VNC
dd65f45e
DL
15327 bgp_rfapi_cfg_write(vty, bgp);
15328#endif
15329
15330 vty_out(vty, "!\n");
15331 }
15332 return 0;
15333}
15334
ddb5b488 15335
718e3744 15336/* BGP node structure. */
d62a17ae 15337static struct cmd_node bgp_node = {
9d303b37 15338 BGP_NODE, "%s(config-router)# ", 1,
718e3744 15339};
15340
d62a17ae 15341static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 15342 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 15343};
15344
d62a17ae 15345static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 15346 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 15347};
15348
d62a17ae 15349static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 15350 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
15351};
15352
d62a17ae 15353static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 15354 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 15355};
15356
d62a17ae 15357static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 15358 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 15359};
15360
d62a17ae 15361static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 15362 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
15363};
15364
d62a17ae 15365static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
15366 "%s(config-router-af)# ", 1};
6b0655a2 15367
d62a17ae 15368static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
15369 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 15370
d62a17ae 15371static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
15372 "%s(config-router-evpn)# ", 1};
4e0b7b6d 15373
d62a17ae 15374static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
15375 "%s(config-router-af-vni)# ", 1};
90e60aa7 15376
7c40bf39 15377static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
15378 "%s(config-router-af)# ", 1};
15379
15380static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
15381 "%s(config-router-af-vpnv6)# ", 1};
15382
d62a17ae 15383static void community_list_vty(void);
1f8ae70b 15384
d62a17ae 15385static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 15386{
d62a17ae 15387 struct bgp *bgp;
15388 struct peer *peer;
d62a17ae 15389 struct listnode *lnbgp, *lnpeer;
b8a815e5 15390
d62a17ae 15391 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15392 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
15393 /* only provide suggestions on the appropriate input
15394 * token type,
15395 * they'll otherwise show up multiple times */
15396 enum cmd_token_type match_type;
15397 char *name = peer->host;
d48ed3e0 15398
d62a17ae 15399 if (peer->conf_if) {
15400 match_type = VARIABLE_TKN;
15401 name = peer->conf_if;
15402 } else if (strchr(peer->host, ':'))
15403 match_type = IPV6_TKN;
15404 else
15405 match_type = IPV4_TKN;
d48ed3e0 15406
d62a17ae 15407 if (token->type != match_type)
15408 continue;
d48ed3e0 15409
d62a17ae 15410 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
15411 }
d62a17ae 15412 }
b8a815e5
DL
15413}
15414
15415static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 15416 {.varname = "neighbor", .completions = bgp_ac_neighbor},
15417 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 15418 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 15419 {.completions = NULL}};
15420
47a306a0
DS
15421static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
15422{
15423 struct bgp *bgp;
15424 struct peer_group *group;
15425 struct listnode *lnbgp, *lnpeer;
15426
15427 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15428 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
15429 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
15430 group->name));
15431 }
15432}
15433
15434static const struct cmd_variable_handler bgp_var_peergroup[] = {
15435 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
15436 {.completions = NULL} };
15437
d62a17ae 15438void bgp_vty_init(void)
15439{
15440 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 15441 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 15442
15443 /* Install bgp top node. */
15444 install_node(&bgp_node, bgp_config_write);
15445 install_node(&bgp_ipv4_unicast_node, NULL);
15446 install_node(&bgp_ipv4_multicast_node, NULL);
15447 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
15448 install_node(&bgp_ipv6_unicast_node, NULL);
15449 install_node(&bgp_ipv6_multicast_node, NULL);
15450 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
15451 install_node(&bgp_vpnv4_node, NULL);
15452 install_node(&bgp_vpnv6_node, NULL);
15453 install_node(&bgp_evpn_node, NULL);
15454 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 15455 install_node(&bgp_flowspecv4_node, NULL);
15456 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 15457
15458 /* Install default VTY commands to new nodes. */
15459 install_default(BGP_NODE);
15460 install_default(BGP_IPV4_NODE);
15461 install_default(BGP_IPV4M_NODE);
15462 install_default(BGP_IPV4L_NODE);
15463 install_default(BGP_IPV6_NODE);
15464 install_default(BGP_IPV6M_NODE);
15465 install_default(BGP_IPV6L_NODE);
15466 install_default(BGP_VPNV4_NODE);
15467 install_default(BGP_VPNV6_NODE);
7c40bf39 15468 install_default(BGP_FLOWSPECV4_NODE);
15469 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 15470 install_default(BGP_EVPN_NODE);
15471 install_default(BGP_EVPN_VNI_NODE);
15472
8029b216
AK
15473 /* "bgp local-mac" hidden commands. */
15474 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
15475 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
15476
d62a17ae 15477 /* bgp route-map delay-timer commands. */
15478 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
15479 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15480
15481 /* Dummy commands (Currently not supported) */
15482 install_element(BGP_NODE, &no_synchronization_cmd);
15483 install_element(BGP_NODE, &no_auto_summary_cmd);
15484
15485 /* "router bgp" commands. */
15486 install_element(CONFIG_NODE, &router_bgp_cmd);
15487
15488 /* "no router bgp" commands. */
15489 install_element(CONFIG_NODE, &no_router_bgp_cmd);
15490
15491 /* "bgp router-id" commands. */
15492 install_element(BGP_NODE, &bgp_router_id_cmd);
15493 install_element(BGP_NODE, &no_bgp_router_id_cmd);
15494
15495 /* "bgp cluster-id" commands. */
15496 install_element(BGP_NODE, &bgp_cluster_id_cmd);
15497 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
15498
15499 /* "bgp confederation" commands. */
15500 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
15501 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
15502
15503 /* "bgp confederation peers" commands. */
15504 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
15505 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
15506
15507 /* bgp max-med command */
15508 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
15509 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
15510 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
15511 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
15512 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
15513
15514 /* bgp disable-ebgp-connected-nh-check */
15515 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
15516 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
15517
15518 /* bgp update-delay command */
15519 install_element(BGP_NODE, &bgp_update_delay_cmd);
15520 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
15521 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
15522
15523 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 15524 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 15525
15526 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
15527 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
15528
15529 /* "maximum-paths" commands. */
15530 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
15531 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
15532 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
15533 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
15534 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
15535 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
15536 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
15537 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
15538 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
15539 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
15540 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15541 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
15542 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
15543 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15544 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
15545
15546 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
15547 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
15548 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
15549 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15550 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15551
15552 /* "timers bgp" commands. */
15553 install_element(BGP_NODE, &bgp_timers_cmd);
15554 install_element(BGP_NODE, &no_bgp_timers_cmd);
15555
15556 /* route-map delay-timer commands - per instance for backwards compat.
15557 */
15558 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
15559 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15560
15561 /* "bgp client-to-client reflection" commands */
15562 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
15563 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
15564
15565 /* "bgp always-compare-med" commands */
15566 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
15567 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
15568
9dac9fc8
DA
15569 /* bgp ebgp-requires-policy */
15570 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
15571 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
15572
fb29348a
DA
15573 /* bgp reject-as-sets */
15574 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
15575 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
15576
d62a17ae 15577 /* "bgp deterministic-med" commands */
15578 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
15579 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
15580
055679e9 15581 /* "bgp graceful-restart" command */
36235319
QY
15582 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
15583 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 15584
15585 /* "bgp graceful-restart-disable" command */
36235319
QY
15586 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
15587 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 15588
15589 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
15590 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
15591 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 15592
15593 /* "neighbor a:b:c:d graceful-restart-disable" command */
15594 install_element(BGP_NODE,
15595 &bgp_neighbor_graceful_restart_disable_set_cmd);
15596 install_element(BGP_NODE,
15597 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
15598
15599 /* "neighbor a:b:c:d graceful-restart-helper" command */
15600 install_element(BGP_NODE,
15601 &bgp_neighbor_graceful_restart_helper_set_cmd);
15602 install_element(BGP_NODE,
15603 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
15604
d62a17ae 15605 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
15606 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
15607 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
15608 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 15609 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 15610 install_element(BGP_NODE,
15611 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 15612 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
15613 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
15614
d6e3c15b 15615 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
15616 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 15617 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
15618 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 15619
7f323236
DW
15620 /* "bgp graceful-shutdown" commands */
15621 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
15622 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
15623
d62a17ae 15624 /* "bgp fast-external-failover" commands */
15625 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
15626 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
15627
d62a17ae 15628 /* "bgp bestpath compare-routerid" commands */
15629 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
15630 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
15631
15632 /* "bgp bestpath as-path ignore" commands */
15633 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
15634 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
15635
15636 /* "bgp bestpath as-path confed" commands */
15637 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
15638 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
15639
15640 /* "bgp bestpath as-path multipath-relax" commands */
15641 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
15642 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
15643
15644 /* "bgp log-neighbor-changes" commands */
15645 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
15646 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
15647
15648 /* "bgp bestpath med" commands */
15649 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
15650 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
15651
f7e1c681 15652 /* "bgp bestpath bandwidth" commands */
15653 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
15654
d62a17ae 15655 /* "no bgp default ipv4-unicast" commands. */
15656 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
15657 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
15658
15659 /* "bgp network import-check" commands. */
15660 install_element(BGP_NODE, &bgp_network_import_check_cmd);
15661 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
15662 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
15663
15664 /* "bgp default local-preference" commands. */
15665 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
15666 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
15667
15668 /* bgp default show-hostname */
15669 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
15670 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
15671
15672 /* "bgp default subgroup-pkt-queue-max" commands. */
15673 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
15674 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
15675
15676 /* bgp ibgp-allow-policy-mods command */
15677 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
15678 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
15679
15680 /* "bgp listen limit" commands. */
15681 install_element(BGP_NODE, &bgp_listen_limit_cmd);
15682 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
15683
15684 /* "bgp listen range" commands. */
15685 install_element(BGP_NODE, &bgp_listen_range_cmd);
15686 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
15687
8175f54a 15688 /* "bgp default shutdown" command */
f26845f9
QY
15689 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
15690
d62a17ae 15691 /* "neighbor remote-as" commands. */
15692 install_element(BGP_NODE, &neighbor_remote_as_cmd);
15693 install_element(BGP_NODE, &neighbor_interface_config_cmd);
15694 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
15695 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
15696 install_element(BGP_NODE,
15697 &neighbor_interface_v6only_config_remote_as_cmd);
15698 install_element(BGP_NODE, &no_neighbor_cmd);
15699 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
15700
15701 /* "neighbor peer-group" commands. */
15702 install_element(BGP_NODE, &neighbor_peer_group_cmd);
15703 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
15704 install_element(BGP_NODE,
15705 &no_neighbor_interface_peer_group_remote_as_cmd);
15706
15707 /* "neighbor local-as" commands. */
15708 install_element(BGP_NODE, &neighbor_local_as_cmd);
15709 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
15710 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
15711 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
15712
15713 /* "neighbor solo" commands. */
15714 install_element(BGP_NODE, &neighbor_solo_cmd);
15715 install_element(BGP_NODE, &no_neighbor_solo_cmd);
15716
15717 /* "neighbor password" commands. */
15718 install_element(BGP_NODE, &neighbor_password_cmd);
15719 install_element(BGP_NODE, &no_neighbor_password_cmd);
15720
15721 /* "neighbor activate" commands. */
15722 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
15723 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
15724 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
15725 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
15726 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
15727 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
15728 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
15729 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
15730 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 15731 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
15732 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 15733 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
15734
15735 /* "no neighbor activate" commands. */
15736 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
15737 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
15738 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
15739 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
15740 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
15741 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
15742 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
15743 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
15744 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 15745 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
15746 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 15747 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
15748
15749 /* "neighbor peer-group" set commands. */
15750 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
15751 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15752 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
15753 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
15754 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
15755 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
15756 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15757 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 15758 install_element(BGP_FLOWSPECV4_NODE,
15759 &neighbor_set_peer_group_hidden_cmd);
15760 install_element(BGP_FLOWSPECV6_NODE,
15761 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 15762
15763 /* "no neighbor peer-group unset" commands. */
15764 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
15765 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15766 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15767 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15768 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15769 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15770 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15771 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 15772 install_element(BGP_FLOWSPECV4_NODE,
15773 &no_neighbor_set_peer_group_hidden_cmd);
15774 install_element(BGP_FLOWSPECV6_NODE,
15775 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 15776
15777 /* "neighbor softreconfiguration inbound" commands.*/
15778 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
15779 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
15780 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
15781 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15782 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
15783 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15784 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
15785 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15786 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
15787 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
15788 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
15789 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15790 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
15791 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15792 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
15793 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15794 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
15795 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 15796 install_element(BGP_FLOWSPECV4_NODE,
15797 &neighbor_soft_reconfiguration_cmd);
15798 install_element(BGP_FLOWSPECV4_NODE,
15799 &no_neighbor_soft_reconfiguration_cmd);
15800 install_element(BGP_FLOWSPECV6_NODE,
15801 &neighbor_soft_reconfiguration_cmd);
15802 install_element(BGP_FLOWSPECV6_NODE,
15803 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
15804 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
15805 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 15806
15807 /* "neighbor attribute-unchanged" commands. */
15808 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
15809 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
15810 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
15811 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
15812 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
15813 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
15814 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
15815 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
15816 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
15817 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
15818 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
15819 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
15820 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
15821 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
15822 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
15823 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
15824 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
15825 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
15826
15827 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
15828 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
15829
15830 /* "nexthop-local unchanged" commands */
15831 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
15832 install_element(BGP_IPV6_NODE,
15833 &no_neighbor_nexthop_local_unchanged_cmd);
15834
15835 /* "neighbor next-hop-self" commands. */
15836 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
15837 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
15838 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
15839 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
15840 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
15841 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
15842 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
15843 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
15844 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
15845 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
15846 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
15847 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
15848 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
15849 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
15850 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
15851 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
15852 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
15853 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
15854 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
15855 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 15856
15857 /* "neighbor next-hop-self force" commands. */
15858 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
15859 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
15860 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15861 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15862 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
15863 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15864 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15865 install_element(BGP_IPV4_NODE,
15866 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15867 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
15868 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15869 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15870 install_element(BGP_IPV4M_NODE,
15871 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15872 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
15873 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15874 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15875 install_element(BGP_IPV4L_NODE,
15876 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15877 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
15878 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15879 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15880 install_element(BGP_IPV6_NODE,
15881 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15882 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
15883 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15884 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15885 install_element(BGP_IPV6M_NODE,
15886 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15887 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
15888 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15889 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15890 install_element(BGP_IPV6L_NODE,
15891 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15892 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
15893 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15894 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15895 install_element(BGP_VPNV4_NODE,
15896 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15897 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
15898 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15899 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15900 install_element(BGP_VPNV6_NODE,
15901 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15902
15903 /* "neighbor as-override" commands. */
15904 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
15905 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
15906 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
15907 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
15908 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
15909 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
15910 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
15911 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
15912 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
15913 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
15914 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
15915 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
15916 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
15917 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
15918 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
15919 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
15920 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
15921 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
15922
15923 /* "neighbor remove-private-AS" commands. */
15924 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
15925 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
15926 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
15927 install_element(BGP_NODE,
15928 &no_neighbor_remove_private_as_all_hidden_cmd);
15929 install_element(BGP_NODE,
15930 &neighbor_remove_private_as_replace_as_hidden_cmd);
15931 install_element(BGP_NODE,
15932 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
15933 install_element(BGP_NODE,
15934 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
15935 install_element(
15936 BGP_NODE,
15937 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
15938 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
15939 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
15940 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
15941 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15942 install_element(BGP_IPV4_NODE,
15943 &neighbor_remove_private_as_replace_as_cmd);
15944 install_element(BGP_IPV4_NODE,
15945 &no_neighbor_remove_private_as_replace_as_cmd);
15946 install_element(BGP_IPV4_NODE,
15947 &neighbor_remove_private_as_all_replace_as_cmd);
15948 install_element(BGP_IPV4_NODE,
15949 &no_neighbor_remove_private_as_all_replace_as_cmd);
15950 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
15951 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
15952 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
15953 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
15954 install_element(BGP_IPV4M_NODE,
15955 &neighbor_remove_private_as_replace_as_cmd);
15956 install_element(BGP_IPV4M_NODE,
15957 &no_neighbor_remove_private_as_replace_as_cmd);
15958 install_element(BGP_IPV4M_NODE,
15959 &neighbor_remove_private_as_all_replace_as_cmd);
15960 install_element(BGP_IPV4M_NODE,
15961 &no_neighbor_remove_private_as_all_replace_as_cmd);
15962 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
15963 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
15964 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
15965 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
15966 install_element(BGP_IPV4L_NODE,
15967 &neighbor_remove_private_as_replace_as_cmd);
15968 install_element(BGP_IPV4L_NODE,
15969 &no_neighbor_remove_private_as_replace_as_cmd);
15970 install_element(BGP_IPV4L_NODE,
15971 &neighbor_remove_private_as_all_replace_as_cmd);
15972 install_element(BGP_IPV4L_NODE,
15973 &no_neighbor_remove_private_as_all_replace_as_cmd);
15974 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
15975 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
15976 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
15977 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15978 install_element(BGP_IPV6_NODE,
15979 &neighbor_remove_private_as_replace_as_cmd);
15980 install_element(BGP_IPV6_NODE,
15981 &no_neighbor_remove_private_as_replace_as_cmd);
15982 install_element(BGP_IPV6_NODE,
15983 &neighbor_remove_private_as_all_replace_as_cmd);
15984 install_element(BGP_IPV6_NODE,
15985 &no_neighbor_remove_private_as_all_replace_as_cmd);
15986 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
15987 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
15988 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
15989 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
15990 install_element(BGP_IPV6M_NODE,
15991 &neighbor_remove_private_as_replace_as_cmd);
15992 install_element(BGP_IPV6M_NODE,
15993 &no_neighbor_remove_private_as_replace_as_cmd);
15994 install_element(BGP_IPV6M_NODE,
15995 &neighbor_remove_private_as_all_replace_as_cmd);
15996 install_element(BGP_IPV6M_NODE,
15997 &no_neighbor_remove_private_as_all_replace_as_cmd);
15998 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
15999 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
16000 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
16001 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
16002 install_element(BGP_IPV6L_NODE,
16003 &neighbor_remove_private_as_replace_as_cmd);
16004 install_element(BGP_IPV6L_NODE,
16005 &no_neighbor_remove_private_as_replace_as_cmd);
16006 install_element(BGP_IPV6L_NODE,
16007 &neighbor_remove_private_as_all_replace_as_cmd);
16008 install_element(BGP_IPV6L_NODE,
16009 &no_neighbor_remove_private_as_all_replace_as_cmd);
16010 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
16011 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
16012 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
16013 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16014 install_element(BGP_VPNV4_NODE,
16015 &neighbor_remove_private_as_replace_as_cmd);
16016 install_element(BGP_VPNV4_NODE,
16017 &no_neighbor_remove_private_as_replace_as_cmd);
16018 install_element(BGP_VPNV4_NODE,
16019 &neighbor_remove_private_as_all_replace_as_cmd);
16020 install_element(BGP_VPNV4_NODE,
16021 &no_neighbor_remove_private_as_all_replace_as_cmd);
16022 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
16023 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
16024 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
16025 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16026 install_element(BGP_VPNV6_NODE,
16027 &neighbor_remove_private_as_replace_as_cmd);
16028 install_element(BGP_VPNV6_NODE,
16029 &no_neighbor_remove_private_as_replace_as_cmd);
16030 install_element(BGP_VPNV6_NODE,
16031 &neighbor_remove_private_as_all_replace_as_cmd);
16032 install_element(BGP_VPNV6_NODE,
16033 &no_neighbor_remove_private_as_all_replace_as_cmd);
16034
16035 /* "neighbor send-community" commands.*/
16036 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
16037 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
16038 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
16039 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
16040 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
16041 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
16042 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
16043 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
16044 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
16045 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
16046 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
16047 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
16048 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
16049 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
16050 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
16051 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
16052 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
16053 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
16054 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
16055 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
16056 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
16057 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
16058 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
16059 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
16060 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
16061 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
16062 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
16063 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
16064 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
16065 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
16066 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
16067 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
16068 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
16069 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
16070 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
16071 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
16072
16073 /* "neighbor route-reflector" commands.*/
16074 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
16075 install_element(BGP_NODE,
16076 &no_neighbor_route_reflector_client_hidden_cmd);
16077 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
16078 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
16079 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
16080 install_element(BGP_IPV4M_NODE,
16081 &no_neighbor_route_reflector_client_cmd);
16082 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
16083 install_element(BGP_IPV4L_NODE,
16084 &no_neighbor_route_reflector_client_cmd);
16085 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
16086 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
16087 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
16088 install_element(BGP_IPV6M_NODE,
16089 &no_neighbor_route_reflector_client_cmd);
16090 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
16091 install_element(BGP_IPV6L_NODE,
16092 &no_neighbor_route_reflector_client_cmd);
16093 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
16094 install_element(BGP_VPNV4_NODE,
16095 &no_neighbor_route_reflector_client_cmd);
16096 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
16097 install_element(BGP_VPNV6_NODE,
16098 &no_neighbor_route_reflector_client_cmd);
7c40bf39 16099 install_element(BGP_FLOWSPECV4_NODE,
16100 &neighbor_route_reflector_client_cmd);
16101 install_element(BGP_FLOWSPECV4_NODE,
16102 &no_neighbor_route_reflector_client_cmd);
16103 install_element(BGP_FLOWSPECV6_NODE,
16104 &neighbor_route_reflector_client_cmd);
16105 install_element(BGP_FLOWSPECV6_NODE,
16106 &no_neighbor_route_reflector_client_cmd);
d62a17ae 16107 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
16108 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
16109
16110 /* "neighbor route-server" commands.*/
16111 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16112 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16113 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16114 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16115 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16116 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16117 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16118 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16119 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16120 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16121 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16122 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16123 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16124 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16125 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16126 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16127 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16128 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
16129 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16130 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 16131 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16132 install_element(BGP_FLOWSPECV4_NODE,
16133 &no_neighbor_route_server_client_cmd);
16134 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16135 install_element(BGP_FLOWSPECV6_NODE,
16136 &no_neighbor_route_server_client_cmd);
d62a17ae 16137
16138 /* "neighbor addpath-tx-all-paths" commands.*/
16139 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16140 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16141 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16142 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16143 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16144 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16145 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16146 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16147 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16148 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16149 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16150 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16151 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16152 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16153 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16154 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16155 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16156 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16157
16158 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16159 install_element(BGP_NODE,
16160 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16161 install_element(BGP_NODE,
16162 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16163 install_element(BGP_IPV4_NODE,
16164 &neighbor_addpath_tx_bestpath_per_as_cmd);
16165 install_element(BGP_IPV4_NODE,
16166 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16167 install_element(BGP_IPV4M_NODE,
16168 &neighbor_addpath_tx_bestpath_per_as_cmd);
16169 install_element(BGP_IPV4M_NODE,
16170 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16171 install_element(BGP_IPV4L_NODE,
16172 &neighbor_addpath_tx_bestpath_per_as_cmd);
16173 install_element(BGP_IPV4L_NODE,
16174 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16175 install_element(BGP_IPV6_NODE,
16176 &neighbor_addpath_tx_bestpath_per_as_cmd);
16177 install_element(BGP_IPV6_NODE,
16178 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16179 install_element(BGP_IPV6M_NODE,
16180 &neighbor_addpath_tx_bestpath_per_as_cmd);
16181 install_element(BGP_IPV6M_NODE,
16182 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16183 install_element(BGP_IPV6L_NODE,
16184 &neighbor_addpath_tx_bestpath_per_as_cmd);
16185 install_element(BGP_IPV6L_NODE,
16186 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16187 install_element(BGP_VPNV4_NODE,
16188 &neighbor_addpath_tx_bestpath_per_as_cmd);
16189 install_element(BGP_VPNV4_NODE,
16190 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16191 install_element(BGP_VPNV6_NODE,
16192 &neighbor_addpath_tx_bestpath_per_as_cmd);
16193 install_element(BGP_VPNV6_NODE,
16194 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16195
2b31007c
RZ
16196 /* "neighbor sender-as-path-loop-detection" commands. */
16197 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16198 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16199
d62a17ae 16200 /* "neighbor passive" commands. */
16201 install_element(BGP_NODE, &neighbor_passive_cmd);
16202 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16203
16204
16205 /* "neighbor shutdown" commands. */
16206 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16207 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16208 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16209 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
16210
16211 /* "neighbor capability extended-nexthop" commands.*/
16212 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16213 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16214
16215 /* "neighbor capability orf prefix-list" commands.*/
16216 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16217 install_element(BGP_NODE,
16218 &no_neighbor_capability_orf_prefix_hidden_cmd);
16219 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16220 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16221 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16222 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16223 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16224 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16225 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16226 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16227 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16228 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16229 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16230 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16231
16232 /* "neighbor capability dynamic" commands.*/
16233 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16234 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16235
16236 /* "neighbor dont-capability-negotiate" commands. */
16237 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16238 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16239
16240 /* "neighbor ebgp-multihop" commands. */
16241 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16242 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16243 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16244
16245 /* "neighbor disable-connected-check" commands. */
16246 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16247 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16248
47cbc09b
PM
16249 /* "neighbor enforce-first-as" commands. */
16250 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16251 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16252
d62a17ae 16253 /* "neighbor description" commands. */
16254 install_element(BGP_NODE, &neighbor_description_cmd);
16255 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 16256 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 16257
16258 /* "neighbor update-source" commands. "*/
16259 install_element(BGP_NODE, &neighbor_update_source_cmd);
16260 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16261
16262 /* "neighbor default-originate" commands. */
16263 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16264 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16265 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16266 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16267 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16268 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16269 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16270 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16271 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16272 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16273 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16274 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16275 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16276 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16277 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16278 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16279 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16280 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16281 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16282 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16283 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16284
16285 /* "neighbor port" commands. */
16286 install_element(BGP_NODE, &neighbor_port_cmd);
16287 install_element(BGP_NODE, &no_neighbor_port_cmd);
16288
16289 /* "neighbor weight" commands. */
16290 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16291 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16292
16293 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16294 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16295 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16296 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16297 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16298 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16299 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16300 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16301 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16302 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16303 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16304 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16305 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16306 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16307 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16308 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16309
16310 /* "neighbor override-capability" commands. */
16311 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16312 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16313
16314 /* "neighbor strict-capability-match" commands. */
16315 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16316 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16317
16318 /* "neighbor timers" commands. */
16319 install_element(BGP_NODE, &neighbor_timers_cmd);
16320 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16321
16322 /* "neighbor timers connect" commands. */
16323 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16324 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16325
16326 /* "neighbor advertisement-interval" commands. */
16327 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
16328 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
16329
16330 /* "neighbor interface" commands. */
16331 install_element(BGP_NODE, &neighbor_interface_cmd);
16332 install_element(BGP_NODE, &no_neighbor_interface_cmd);
16333
16334 /* "neighbor distribute" commands. */
16335 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
16336 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
16337 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
16338 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
16339 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
16340 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
16341 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
16342 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
16343 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
16344 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
16345 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
16346 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
16347 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
16348 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
16349 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
16350 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
16351 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
16352 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
16353
16354 /* "neighbor prefix-list" commands. */
16355 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
16356 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
16357 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
16358 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
16359 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
16360 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
16361 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
16362 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
16363 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
16364 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
16365 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
16366 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
16367 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
16368 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
16369 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
16370 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
16371 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
16372 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 16373 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
16374 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
16375 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
16376 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 16377
16378 /* "neighbor filter-list" commands. */
16379 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
16380 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
16381 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
16382 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
16383 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
16384 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
16385 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
16386 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
16387 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
16388 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
16389 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
16390 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
16391 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
16392 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
16393 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
16394 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
16395 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
16396 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 16397 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
16398 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
16399 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
16400 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 16401
16402 /* "neighbor route-map" commands. */
16403 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
16404 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
16405 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
16406 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
16407 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
16408 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
16409 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
16410 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
16411 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
16412 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
16413 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
16414 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
16415 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
16416 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
16417 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
16418 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
16419 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
16420 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 16421 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
16422 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
16423 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
16424 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
16425 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
16426 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 16427
16428 /* "neighbor unsuppress-map" commands. */
16429 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
16430 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
16431 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
16432 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
16433 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
16434 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
16435 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
16436 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
16437 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
16438 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
16439 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
16440 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
16441 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
16442 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
16443 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
16444 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
16445 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
16446 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
16447
fde246e8
DA
16448 /* neighbor maximum-prefix-out commands. */
16449 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
16450 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
16451 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
16452 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16453 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
16454 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16455 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
16456 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16457 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
16458 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16459 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
16460 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16461 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
16462 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16463 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
16464 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16465 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
16466 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16467
d62a17ae 16468 /* "neighbor maximum-prefix" commands. */
16469 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
16470 install_element(BGP_NODE,
16471 &neighbor_maximum_prefix_threshold_hidden_cmd);
16472 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
16473 install_element(BGP_NODE,
16474 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
16475 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
16476 install_element(BGP_NODE,
16477 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
16478 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
16479 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
16480 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16481 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16482 install_element(BGP_IPV4_NODE,
16483 &neighbor_maximum_prefix_threshold_warning_cmd);
16484 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16485 install_element(BGP_IPV4_NODE,
16486 &neighbor_maximum_prefix_threshold_restart_cmd);
16487 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
16488 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
16489 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16490 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
16491 install_element(BGP_IPV4M_NODE,
16492 &neighbor_maximum_prefix_threshold_warning_cmd);
16493 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
16494 install_element(BGP_IPV4M_NODE,
16495 &neighbor_maximum_prefix_threshold_restart_cmd);
16496 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
16497 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
16498 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16499 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
16500 install_element(BGP_IPV4L_NODE,
16501 &neighbor_maximum_prefix_threshold_warning_cmd);
16502 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
16503 install_element(BGP_IPV4L_NODE,
16504 &neighbor_maximum_prefix_threshold_restart_cmd);
16505 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
16506 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
16507 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16508 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16509 install_element(BGP_IPV6_NODE,
16510 &neighbor_maximum_prefix_threshold_warning_cmd);
16511 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16512 install_element(BGP_IPV6_NODE,
16513 &neighbor_maximum_prefix_threshold_restart_cmd);
16514 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
16515 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
16516 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16517 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
16518 install_element(BGP_IPV6M_NODE,
16519 &neighbor_maximum_prefix_threshold_warning_cmd);
16520 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
16521 install_element(BGP_IPV6M_NODE,
16522 &neighbor_maximum_prefix_threshold_restart_cmd);
16523 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
16524 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
16525 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16526 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
16527 install_element(BGP_IPV6L_NODE,
16528 &neighbor_maximum_prefix_threshold_warning_cmd);
16529 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
16530 install_element(BGP_IPV6L_NODE,
16531 &neighbor_maximum_prefix_threshold_restart_cmd);
16532 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
16533 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
16534 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16535 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16536 install_element(BGP_VPNV4_NODE,
16537 &neighbor_maximum_prefix_threshold_warning_cmd);
16538 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16539 install_element(BGP_VPNV4_NODE,
16540 &neighbor_maximum_prefix_threshold_restart_cmd);
16541 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
16542 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
16543 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16544 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16545 install_element(BGP_VPNV6_NODE,
16546 &neighbor_maximum_prefix_threshold_warning_cmd);
16547 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16548 install_element(BGP_VPNV6_NODE,
16549 &neighbor_maximum_prefix_threshold_restart_cmd);
16550 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
16551
16552 /* "neighbor allowas-in" */
16553 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
16554 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
16555 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
16556 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
16557 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
16558 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
16559 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
16560 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
16561 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
16562 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
16563 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
16564 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
16565 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
16566 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
16567 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
16568 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
16569 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
16570 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
16571 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
16572 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
16573
16574 /* address-family commands. */
16575 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
16576 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 16577#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 16578 install_element(BGP_NODE, &address_family_vpnv4_cmd);
16579 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 16580#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 16581
d62a17ae 16582 install_element(BGP_NODE, &address_family_evpn_cmd);
16583
16584 /* "exit-address-family" command. */
16585 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
16586 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
16587 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
16588 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
16589 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
16590 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
16591 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
16592 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 16593 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
16594 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 16595 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
16596
16597 /* "clear ip bgp commands" */
16598 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
16599
16600 /* clear ip bgp prefix */
16601 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
16602 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
16603 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
16604
16605 /* "show [ip] bgp summary" commands. */
16606 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 16607 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 16608 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 16609 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 16610 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
16611 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 16612 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
16613
16614 /* "show [ip] bgp neighbors" commands. */
16615 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
16616
36235319 16617 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 16618
d62a17ae 16619 /* "show [ip] bgp peer-group" commands. */
16620 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
16621
16622 /* "show [ip] bgp paths" commands. */
16623 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
16624
16625 /* "show [ip] bgp community" commands. */
16626 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
16627
16628 /* "show ip bgp large-community" commands. */
16629 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
16630 /* "show [ip] bgp attribute-info" commands. */
16631 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 16632 /* "show [ip] bgp route-leak" command */
16633 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 16634
16635 /* "redistribute" commands. */
16636 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
16637 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
16638 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
16639 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
16640 install_element(BGP_NODE,
16641 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
16642 install_element(BGP_NODE,
16643 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
16644 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
16645 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
16646 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
16647 install_element(BGP_NODE,
16648 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
16649 install_element(BGP_NODE,
16650 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
16651 install_element(BGP_NODE,
16652 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
16653 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
16654 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
16655 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
16656 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
16657 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
16658 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
16659 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
16660 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
16661 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
16662 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
16663 install_element(BGP_IPV4_NODE,
16664 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
16665 install_element(BGP_IPV4_NODE,
16666 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
16667 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
16668 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
16669 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
16670 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
16671 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
16672 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
16673
b9c7bc5a
PZ
16674 /* import|export vpn [route-map WORD] */
16675 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
16676 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 16677
12a844a5
DS
16678 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
16679 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
16680
d62a17ae 16681 /* ttl_security commands */
16682 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
16683 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
16684
16685 /* "show [ip] bgp memory" commands. */
16686 install_element(VIEW_NODE, &show_bgp_memory_cmd);
16687
acf71666
MK
16688 /* "show bgp martian next-hop" */
16689 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
16690
48ecf8f5
DS
16691 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
16692
d62a17ae 16693 /* "show [ip] bgp views" commands. */
16694 install_element(VIEW_NODE, &show_bgp_views_cmd);
16695
16696 /* "show [ip] bgp vrfs" commands. */
16697 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
16698
16699 /* Community-list. */
16700 community_list_vty();
ddb5b488
PZ
16701
16702 /* vpn-policy commands */
b9c7bc5a
PZ
16703 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
16704 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
16705 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
16706 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
16707 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
16708 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
16709 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
16710 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
16711 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
16712 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
16713 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
16714 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 16715
301ad80a
PG
16716 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
16717 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
16718
b9c7bc5a
PZ
16719 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
16720 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
16721 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
16722 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
16723 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
16724 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
16725 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
16726 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
16727 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
16728 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 16729}
6b0655a2 16730
718e3744 16731#include "memory.h"
16732#include "bgp_regex.h"
16733#include "bgp_clist.h"
16734#include "bgp_ecommunity.h"
16735
16736/* VTY functions. */
16737
16738/* Direction value to string conversion. */
d62a17ae 16739static const char *community_direct_str(int direct)
16740{
16741 switch (direct) {
16742 case COMMUNITY_DENY:
16743 return "deny";
16744 case COMMUNITY_PERMIT:
16745 return "permit";
16746 default:
16747 return "unknown";
16748 }
718e3744 16749}
16750
16751/* Display error string. */
d62a17ae 16752static void community_list_perror(struct vty *vty, int ret)
16753{
16754 switch (ret) {
16755 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
16756 vty_out(vty, "%% Can't find community-list\n");
16757 break;
16758 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
16759 vty_out(vty, "%% Malformed community-list value\n");
16760 break;
16761 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
16762 vty_out(vty,
16763 "%% Community name conflict, previously defined as standard community\n");
16764 break;
16765 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
16766 vty_out(vty,
16767 "%% Community name conflict, previously defined as expanded community\n");
16768 break;
16769 }
718e3744 16770}
16771
5bf15956
DW
16772/* "community-list" keyword help string. */
16773#define COMMUNITY_LIST_STR "Add a community list entry\n"
16774
7336e101
SP
16775/*community-list standard */
16776DEFUN (community_list_standard,
16777 bgp_community_list_standard_cmd,
2f8cc0e5 16778 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 16779 BGP_STR
718e3744 16780 COMMUNITY_LIST_STR
16781 "Community list number (standard)\n"
5bf15956 16782 "Add an standard community-list entry\n"
718e3744 16783 "Community list name\n"
2f8cc0e5
DA
16784 "Sequence number of an entry\n"
16785 "Sequence number\n"
718e3744 16786 "Specify community to reject\n"
16787 "Specify community to accept\n"
16788 COMMUNITY_VAL_STR)
16789{
d62a17ae 16790 char *cl_name_or_number = NULL;
2f8cc0e5 16791 char *seq = NULL;
d62a17ae 16792 int direct = 0;
16793 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 16794 int idx = 0;
7336e101 16795
2f8cc0e5
DA
16796 argv_find(argv, argc, "(1-4294967295)", &idx);
16797 if (idx)
16798 seq = argv[idx]->arg;
16799
16800 idx = 0;
d62a17ae 16801 argv_find(argv, argc, "(1-99)", &idx);
16802 argv_find(argv, argc, "WORD", &idx);
16803 cl_name_or_number = argv[idx]->arg;
16804 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16805 : COMMUNITY_DENY;
16806 argv_find(argv, argc, "AA:NN", &idx);
16807 char *str = argv_concat(argv, argc, idx);
42f914d4 16808
2f8cc0e5
DA
16809 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16810 direct, style);
42f914d4 16811
d62a17ae 16812 XFREE(MTYPE_TMP, str);
42f914d4 16813
d62a17ae 16814 if (ret < 0) {
16815 /* Display error string. */
16816 community_list_perror(vty, ret);
16817 return CMD_WARNING_CONFIG_FAILED;
16818 }
42f914d4 16819
d62a17ae 16820 return CMD_SUCCESS;
718e3744 16821}
16822
7336e101
SP
16823DEFUN (no_community_list_standard_all,
16824 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 16825 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
16826 NO_STR
16827 BGP_STR
16828 COMMUNITY_LIST_STR
16829 "Community list number (standard)\n"
16830 "Add an standard community-list entry\n"
16831 "Community list name\n"
2f8cc0e5
DA
16832 "Sequence number of an entry\n"
16833 "Sequence number\n"
7336e101
SP
16834 "Specify community to reject\n"
16835 "Specify community to accept\n"
16836 COMMUNITY_VAL_STR)
718e3744 16837{
d62a17ae 16838 char *cl_name_or_number = NULL;
174b5cb9 16839 char *str = NULL;
d62a17ae 16840 int direct = 0;
16841 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 16842 char *seq = NULL;
d62a17ae 16843 int idx = 0;
7336e101 16844
2f8cc0e5
DA
16845 argv_find(argv, argc, "(1-4294967295)", &idx);
16846 if (idx)
16847 seq = argv[idx]->arg;
16848
16849 idx = 0;
174b5cb9
DA
16850 argv_find(argv, argc, "permit", &idx);
16851 argv_find(argv, argc, "deny", &idx);
16852
16853 if (idx) {
16854 direct = argv_find(argv, argc, "permit", &idx)
16855 ? COMMUNITY_PERMIT
16856 : COMMUNITY_DENY;
16857
16858 idx = 0;
16859 argv_find(argv, argc, "AA:NN", &idx);
16860 str = argv_concat(argv, argc, idx);
16861 }
16862
16863 idx = 0;
d62a17ae 16864 argv_find(argv, argc, "(1-99)", &idx);
16865 argv_find(argv, argc, "WORD", &idx);
16866 cl_name_or_number = argv[idx]->arg;
42f914d4 16867
2f8cc0e5 16868 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 16869 direct, style);
42f914d4 16870
d62a17ae 16871 XFREE(MTYPE_TMP, str);
daf9ddbb 16872
d62a17ae 16873 if (ret < 0) {
16874 community_list_perror(vty, ret);
16875 return CMD_WARNING_CONFIG_FAILED;
16876 }
42f914d4 16877
d62a17ae 16878 return CMD_SUCCESS;
718e3744 16879}
7336e101 16880
174b5cb9
DA
16881ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
16882 "no bgp community-list <(1-99)|standard WORD>",
16883 NO_STR BGP_STR COMMUNITY_LIST_STR
16884 "Community list number (standard)\n"
16885 "Add an standard community-list entry\n"
16886 "Community list name\n")
16887
7336e101
SP
16888/*community-list expanded */
16889DEFUN (community_list_expanded_all,
16890 bgp_community_list_expanded_all_cmd,
2f8cc0e5 16891 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
16892 BGP_STR
16893 COMMUNITY_LIST_STR
718e3744 16894 "Community list number (expanded)\n"
5bf15956 16895 "Add an expanded community-list entry\n"
718e3744 16896 "Community list name\n"
2f8cc0e5
DA
16897 "Sequence number of an entry\n"
16898 "Sequence number\n"
718e3744 16899 "Specify community to reject\n"
16900 "Specify community to accept\n"
16901 COMMUNITY_VAL_STR)
16902{
d62a17ae 16903 char *cl_name_or_number = NULL;
2f8cc0e5 16904 char *seq = NULL;
d62a17ae 16905 int direct = 0;
16906 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 16907 int idx = 0;
7b9a4750 16908
2f8cc0e5
DA
16909 argv_find(argv, argc, "(1-4294967295)", &idx);
16910 if (idx)
16911 seq = argv[idx]->arg;
16912
16913 idx = 0;
16914
d62a17ae 16915 argv_find(argv, argc, "(100-500)", &idx);
16916 argv_find(argv, argc, "WORD", &idx);
16917 cl_name_or_number = argv[idx]->arg;
16918 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16919 : COMMUNITY_DENY;
16920 argv_find(argv, argc, "AA:NN", &idx);
16921 char *str = argv_concat(argv, argc, idx);
42f914d4 16922
2f8cc0e5
DA
16923 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16924 direct, style);
42f914d4 16925
d62a17ae 16926 XFREE(MTYPE_TMP, str);
42f914d4 16927
d62a17ae 16928 if (ret < 0) {
16929 /* Display error string. */
16930 community_list_perror(vty, ret);
16931 return CMD_WARNING_CONFIG_FAILED;
16932 }
42f914d4 16933
d62a17ae 16934 return CMD_SUCCESS;
718e3744 16935}
16936
7336e101
SP
16937DEFUN (no_community_list_expanded_all,
16938 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 16939 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
16940 NO_STR
16941 BGP_STR
16942 COMMUNITY_LIST_STR
16943 "Community list number (expanded)\n"
16944 "Add an expanded community-list entry\n"
16945 "Community list name\n"
2f8cc0e5
DA
16946 "Sequence number of an entry\n"
16947 "Sequence number\n"
7336e101
SP
16948 "Specify community to reject\n"
16949 "Specify community to accept\n"
16950 COMMUNITY_VAL_STR)
718e3744 16951{
d62a17ae 16952 char *cl_name_or_number = NULL;
2f8cc0e5 16953 char *seq = NULL;
174b5cb9 16954 char *str = NULL;
d62a17ae 16955 int direct = 0;
16956 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 16957 int idx = 0;
174b5cb9 16958
2f8cc0e5
DA
16959 argv_find(argv, argc, "(1-4294967295)", &idx);
16960 if (idx)
16961 seq = argv[idx]->arg;
16962
16963 idx = 0;
174b5cb9
DA
16964 argv_find(argv, argc, "permit", &idx);
16965 argv_find(argv, argc, "deny", &idx);
16966
16967 if (idx) {
16968 direct = argv_find(argv, argc, "permit", &idx)
16969 ? COMMUNITY_PERMIT
16970 : COMMUNITY_DENY;
16971
16972 idx = 0;
16973 argv_find(argv, argc, "AA:NN", &idx);
16974 str = argv_concat(argv, argc, idx);
7336e101 16975 }
174b5cb9
DA
16976
16977 idx = 0;
d62a17ae 16978 argv_find(argv, argc, "(100-500)", &idx);
16979 argv_find(argv, argc, "WORD", &idx);
16980 cl_name_or_number = argv[idx]->arg;
42f914d4 16981
2f8cc0e5 16982 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 16983 direct, style);
42f914d4 16984
d62a17ae 16985 XFREE(MTYPE_TMP, str);
daf9ddbb 16986
d62a17ae 16987 if (ret < 0) {
16988 community_list_perror(vty, ret);
16989 return CMD_WARNING_CONFIG_FAILED;
16990 }
42f914d4 16991
d62a17ae 16992 return CMD_SUCCESS;
718e3744 16993}
16994
174b5cb9
DA
16995ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
16996 "no bgp community-list <(100-500)|expanded WORD>",
16997 NO_STR IP_STR COMMUNITY_LIST_STR
16998 "Community list number (expanded)\n"
16999 "Add an expanded community-list entry\n"
17000 "Community list name\n")
17001
8d9b8ed9
PM
17002/* Return configuration string of community-list entry. */
17003static const char *community_list_config_str(struct community_entry *entry)
17004{
17005 const char *str;
17006
17007 if (entry->any)
17008 str = "";
17009 else {
17010 if (entry->style == COMMUNITY_LIST_STANDARD)
17011 str = community_str(entry->u.com, false);
17012 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
17013 str = lcommunity_str(entry->u.lcom, false);
17014 else
17015 str = entry->config;
17016 }
17017 return str;
17018}
17019
d62a17ae 17020static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 17021{
d62a17ae 17022 struct community_entry *entry;
718e3744 17023
d62a17ae 17024 for (entry = list->head; entry; entry = entry->next) {
17025 if (entry == list->head) {
17026 if (all_digit(list->name))
17027 vty_out(vty, "Community %s list %s\n",
17028 entry->style == COMMUNITY_LIST_STANDARD
17029 ? "standard"
17030 : "(expanded) access",
17031 list->name);
17032 else
17033 vty_out(vty, "Named Community %s list %s\n",
17034 entry->style == COMMUNITY_LIST_STANDARD
17035 ? "standard"
17036 : "expanded",
17037 list->name);
17038 }
17039 if (entry->any)
17040 vty_out(vty, " %s\n",
17041 community_direct_str(entry->direct));
17042 else
17043 vty_out(vty, " %s %s\n",
17044 community_direct_str(entry->direct),
8d9b8ed9 17045 community_list_config_str(entry));
d62a17ae 17046 }
718e3744 17047}
17048
7336e101
SP
17049DEFUN (show_community_list,
17050 show_bgp_community_list_cmd,
17051 "show bgp community-list",
718e3744 17052 SHOW_STR
7336e101 17053 BGP_STR
718e3744 17054 "List community-list\n")
17055{
d62a17ae 17056 struct community_list *list;
17057 struct community_list_master *cm;
718e3744 17058
d62a17ae 17059 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17060 if (!cm)
17061 return CMD_SUCCESS;
718e3744 17062
d62a17ae 17063 for (list = cm->num.head; list; list = list->next)
17064 community_list_show(vty, list);
718e3744 17065
d62a17ae 17066 for (list = cm->str.head; list; list = list->next)
17067 community_list_show(vty, list);
718e3744 17068
d62a17ae 17069 return CMD_SUCCESS;
718e3744 17070}
17071
7336e101
SP
17072DEFUN (show_community_list_arg,
17073 show_bgp_community_list_arg_cmd,
960b69b9 17074 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
17075 SHOW_STR
17076 BGP_STR
718e3744 17077 "List community-list\n"
17078 "Community-list number\n"
960b69b9 17079 "Community-list name\n"
17080 "Detailed information on community-list\n")
718e3744 17081{
d62a17ae 17082 int idx_comm_list = 3;
17083 struct community_list *list;
718e3744 17084
e237b0d2 17085 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17086 COMMUNITY_LIST_MASTER);
17087 if (!list) {
17088 vty_out(vty, "%% Can't find community-list\n");
17089 return CMD_WARNING;
17090 }
718e3744 17091
d62a17ae 17092 community_list_show(vty, list);
718e3744 17093
d62a17ae 17094 return CMD_SUCCESS;
718e3744 17095}
6b0655a2 17096
57d187bc
JS
17097/*
17098 * Large Community code.
17099 */
d62a17ae 17100static int lcommunity_list_set_vty(struct vty *vty, int argc,
17101 struct cmd_token **argv, int style,
17102 int reject_all_digit_name)
17103{
17104 int ret;
17105 int direct;
17106 char *str;
17107 int idx = 0;
17108 char *cl_name;
2f8cc0e5
DA
17109 char *seq = NULL;
17110
17111 argv_find(argv, argc, "(1-4294967295)", &idx);
17112 if (idx)
17113 seq = argv[idx]->arg;
d62a17ae 17114
2f8cc0e5 17115 idx = 0;
d62a17ae 17116 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17117 : COMMUNITY_DENY;
17118
17119 /* All digit name check. */
17120 idx = 0;
17121 argv_find(argv, argc, "WORD", &idx);
17122 argv_find(argv, argc, "(1-99)", &idx);
17123 argv_find(argv, argc, "(100-500)", &idx);
17124 cl_name = argv[idx]->arg;
17125 if (reject_all_digit_name && all_digit(cl_name)) {
17126 vty_out(vty, "%% Community name cannot have all digits\n");
17127 return CMD_WARNING_CONFIG_FAILED;
17128 }
17129
17130 idx = 0;
17131 argv_find(argv, argc, "AA:BB:CC", &idx);
17132 argv_find(argv, argc, "LINE", &idx);
17133 /* Concat community string argument. */
17134 if (idx)
17135 str = argv_concat(argv, argc, idx);
17136 else
17137 str = NULL;
17138
2f8cc0e5 17139 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 17140
17141 /* Free temporary community list string allocated by
17142 argv_concat(). */
0a22ddfb 17143 XFREE(MTYPE_TMP, str);
d62a17ae 17144
17145 if (ret < 0) {
17146 community_list_perror(vty, ret);
17147 return CMD_WARNING_CONFIG_FAILED;
17148 }
17149 return CMD_SUCCESS;
17150}
17151
17152static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17153 struct cmd_token **argv, int style)
17154{
17155 int ret;
17156 int direct = 0;
17157 char *str = NULL;
17158 int idx = 0;
2f8cc0e5 17159 char *seq = NULL;
d62a17ae 17160
2f8cc0e5
DA
17161 argv_find(argv, argc, "(1-4294967295)", &idx);
17162 if (idx)
17163 seq = argv[idx]->arg;
d62a17ae 17164
2f8cc0e5 17165 idx = 0;
d62a17ae 17166 argv_find(argv, argc, "permit", &idx);
17167 argv_find(argv, argc, "deny", &idx);
17168
17169 if (idx) {
17170 /* Check the list direct. */
17171 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17172 direct = COMMUNITY_PERMIT;
17173 else
17174 direct = COMMUNITY_DENY;
17175
17176 idx = 0;
17177 argv_find(argv, argc, "LINE", &idx);
17178 argv_find(argv, argc, "AA:AA:NN", &idx);
17179 /* Concat community string argument. */
17180 str = argv_concat(argv, argc, idx);
17181 }
17182
17183 idx = 0;
17184 argv_find(argv, argc, "(1-99)", &idx);
17185 argv_find(argv, argc, "(100-500)", &idx);
17186 argv_find(argv, argc, "WORD", &idx);
17187
17188 /* Unset community list. */
2f8cc0e5 17189 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 17190 style);
17191
17192 /* Free temporary community list string allocated by
17193 argv_concat(). */
0a22ddfb 17194 XFREE(MTYPE_TMP, str);
d62a17ae 17195
17196 if (ret < 0) {
17197 community_list_perror(vty, ret);
17198 return CMD_WARNING_CONFIG_FAILED;
17199 }
17200
17201 return CMD_SUCCESS;
57d187bc
JS
17202}
17203
17204/* "large-community-list" keyword help string. */
17205#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17206#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17207
7336e101
SP
17208DEFUN (lcommunity_list_standard,
17209 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17210 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17211 BGP_STR
17212 LCOMMUNITY_LIST_STR
17213 "Large Community list number (standard)\n"
2f8cc0e5
DA
17214 "Sequence number of an entry\n"
17215 "Sequence number\n"
7336e101
SP
17216 "Specify large community to reject\n"
17217 "Specify large community to accept\n"
17218 LCOMMUNITY_VAL_STR)
52951b63 17219{
d62a17ae 17220 return lcommunity_list_set_vty(vty, argc, argv,
17221 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
17222}
17223
7336e101
SP
17224DEFUN (lcommunity_list_expanded,
17225 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17226 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17227 BGP_STR
17228 LCOMMUNITY_LIST_STR
17229 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17230 "Sequence number of an entry\n"
17231 "Sequence number\n"
7336e101
SP
17232 "Specify large community to reject\n"
17233 "Specify large community to accept\n"
17234 "An ordered list as a regular-expression\n")
57d187bc 17235{
d62a17ae 17236 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17237 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
17238}
17239
7336e101
SP
17240DEFUN (lcommunity_list_name_standard,
17241 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17242 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17243 BGP_STR
17244 LCOMMUNITY_LIST_STR
17245 "Specify standard large-community-list\n"
17246 "Large Community list name\n"
2f8cc0e5
DA
17247 "Sequence number of an entry\n"
17248 "Sequence number\n"
7336e101
SP
17249 "Specify large community to reject\n"
17250 "Specify large community to accept\n"
17251 LCOMMUNITY_VAL_STR)
52951b63 17252{
d62a17ae 17253 return lcommunity_list_set_vty(vty, argc, argv,
17254 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
17255}
17256
7336e101
SP
17257DEFUN (lcommunity_list_name_expanded,
17258 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17259 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17260 BGP_STR
17261 LCOMMUNITY_LIST_STR
17262 "Specify expanded large-community-list\n"
17263 "Large Community list name\n"
2f8cc0e5
DA
17264 "Sequence number of an entry\n"
17265 "Sequence number\n"
7336e101
SP
17266 "Specify large community to reject\n"
17267 "Specify large community to accept\n"
17268 "An ordered list as a regular-expression\n")
57d187bc 17269{
d62a17ae 17270 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17271 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
17272}
17273
4378f57c
DA
17274DEFUN (no_lcommunity_list_all,
17275 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
17276 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17277 NO_STR
17278 BGP_STR
17279 LCOMMUNITY_LIST_STR
17280 "Large Community list number (standard)\n"
17281 "Large Community list number (expanded)\n"
17282 "Large Community list name\n")
57d187bc 17283{
7336e101
SP
17284 return lcommunity_list_unset_vty(vty, argc, argv,
17285 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17286}
17287
4378f57c
DA
17288DEFUN (no_lcommunity_list_name_standard_all,
17289 no_bgp_lcommunity_list_name_standard_all_cmd,
17290 "no bgp large-community-list standard WORD",
17291 NO_STR
17292 BGP_STR
17293 LCOMMUNITY_LIST_STR
17294 "Specify standard large-community-list\n"
17295 "Large Community list name\n")
17296{
17297 return lcommunity_list_unset_vty(vty, argc, argv,
17298 LARGE_COMMUNITY_LIST_STANDARD);
17299}
17300
7336e101
SP
17301DEFUN (no_lcommunity_list_name_expanded_all,
17302 no_bgp_lcommunity_list_name_expanded_all_cmd,
17303 "no bgp large-community-list expanded WORD",
17304 NO_STR
17305 BGP_STR
17306 LCOMMUNITY_LIST_STR
17307 "Specify expanded large-community-list\n"
17308 "Large Community list name\n")
57d187bc 17309{
d62a17ae 17310 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17311 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17312}
17313
7336e101
SP
17314DEFUN (no_lcommunity_list_standard,
17315 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17316 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17317 NO_STR
17318 BGP_STR
17319 LCOMMUNITY_LIST_STR
17320 "Large Community list number (standard)\n"
2f8cc0e5
DA
17321 "Sequence number of an entry\n"
17322 "Sequence number\n"
7336e101
SP
17323 "Specify large community to reject\n"
17324 "Specify large community to accept\n"
17325 LCOMMUNITY_VAL_STR)
57d187bc 17326{
d62a17ae 17327 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17328 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17329}
17330
7336e101
SP
17331DEFUN (no_lcommunity_list_expanded,
17332 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17333 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17334 NO_STR
17335 BGP_STR
17336 LCOMMUNITY_LIST_STR
17337 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17338 "Sequence number of an entry\n"
17339 "Sequence number\n"
7336e101
SP
17340 "Specify large community to reject\n"
17341 "Specify large community to accept\n"
17342 "An ordered list as a regular-expression\n")
57d187bc 17343{
d62a17ae 17344 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17345 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17346}
17347
7336e101
SP
17348DEFUN (no_lcommunity_list_name_standard,
17349 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17350 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17351 NO_STR
17352 BGP_STR
17353 LCOMMUNITY_LIST_STR
17354 "Specify standard large-community-list\n"
17355 "Large Community list name\n"
2f8cc0e5
DA
17356 "Sequence number of an entry\n"
17357 "Sequence number\n"
7336e101
SP
17358 "Specify large community to reject\n"
17359 "Specify large community to accept\n"
17360 LCOMMUNITY_VAL_STR)
57d187bc 17361{
d62a17ae 17362 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17363 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17364}
17365
7336e101
SP
17366DEFUN (no_lcommunity_list_name_expanded,
17367 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17368 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17369 NO_STR
17370 BGP_STR
17371 LCOMMUNITY_LIST_STR
17372 "Specify expanded large-community-list\n"
17373 "Large community list name\n"
2f8cc0e5
DA
17374 "Sequence number of an entry\n"
17375 "Sequence number\n"
7336e101
SP
17376 "Specify large community to reject\n"
17377 "Specify large community to accept\n"
17378 "An ordered list as a regular-expression\n")
57d187bc 17379{
d62a17ae 17380 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17381 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17382}
17383
d62a17ae 17384static void lcommunity_list_show(struct vty *vty, struct community_list *list)
17385{
17386 struct community_entry *entry;
17387
17388 for (entry = list->head; entry; entry = entry->next) {
17389 if (entry == list->head) {
17390 if (all_digit(list->name))
17391 vty_out(vty, "Large community %s list %s\n",
169b72c8 17392 entry->style ==
17393 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17394 ? "standard"
17395 : "(expanded) access",
17396 list->name);
17397 else
17398 vty_out(vty,
17399 "Named large community %s list %s\n",
169b72c8 17400 entry->style ==
17401 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17402 ? "standard"
17403 : "expanded",
17404 list->name);
17405 }
17406 if (entry->any)
17407 vty_out(vty, " %s\n",
17408 community_direct_str(entry->direct));
17409 else
17410 vty_out(vty, " %s %s\n",
17411 community_direct_str(entry->direct),
8d9b8ed9 17412 community_list_config_str(entry));
d62a17ae 17413 }
57d187bc
JS
17414}
17415
7336e101
SP
17416DEFUN (show_lcommunity_list,
17417 show_bgp_lcommunity_list_cmd,
17418 "show bgp large-community-list",
57d187bc 17419 SHOW_STR
7336e101 17420 BGP_STR
57d187bc
JS
17421 "List large-community list\n")
17422{
d62a17ae 17423 struct community_list *list;
17424 struct community_list_master *cm;
57d187bc 17425
d62a17ae 17426 cm = community_list_master_lookup(bgp_clist,
17427 LARGE_COMMUNITY_LIST_MASTER);
17428 if (!cm)
17429 return CMD_SUCCESS;
57d187bc 17430
d62a17ae 17431 for (list = cm->num.head; list; list = list->next)
17432 lcommunity_list_show(vty, list);
57d187bc 17433
d62a17ae 17434 for (list = cm->str.head; list; list = list->next)
17435 lcommunity_list_show(vty, list);
57d187bc 17436
d62a17ae 17437 return CMD_SUCCESS;
57d187bc
JS
17438}
17439
7336e101
SP
17440DEFUN (show_lcommunity_list_arg,
17441 show_bgp_lcommunity_list_arg_cmd,
960b69b9 17442 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
17443 SHOW_STR
17444 BGP_STR
57d187bc 17445 "List large-community list\n"
960b69b9 17446 "Large-community-list number\n"
17447 "Large-community-list name\n"
17448 "Detailed information on large-community-list\n")
57d187bc 17449{
d62a17ae 17450 struct community_list *list;
57d187bc 17451
e237b0d2 17452 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 17453 LARGE_COMMUNITY_LIST_MASTER);
17454 if (!list) {
960b69b9 17455 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 17456 return CMD_WARNING;
17457 }
57d187bc 17458
d62a17ae 17459 lcommunity_list_show(vty, list);
57d187bc 17460
d62a17ae 17461 return CMD_SUCCESS;
57d187bc
JS
17462}
17463
718e3744 17464/* "extcommunity-list" keyword help string. */
17465#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
17466#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
17467
7336e101
SP
17468DEFUN (extcommunity_list_standard,
17469 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 17470 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17471 BGP_STR
718e3744 17472 EXTCOMMUNITY_LIST_STR
17473 "Extended Community list number (standard)\n"
718e3744 17474 "Specify standard extcommunity-list\n"
5bf15956 17475 "Community list name\n"
2f8cc0e5
DA
17476 "Sequence number of an entry\n"
17477 "Sequence number\n"
718e3744 17478 "Specify community to reject\n"
17479 "Specify community to accept\n"
17480 EXTCOMMUNITY_VAL_STR)
17481{
d62a17ae 17482 int style = EXTCOMMUNITY_LIST_STANDARD;
17483 int direct = 0;
17484 char *cl_number_or_name = NULL;
2f8cc0e5 17485 char *seq = NULL;
42f914d4 17486
d62a17ae 17487 int idx = 0;
7b9a4750 17488
d62a17ae 17489 argv_find(argv, argc, "(1-99)", &idx);
17490 argv_find(argv, argc, "WORD", &idx);
17491 cl_number_or_name = argv[idx]->arg;
2f8cc0e5
DA
17492
17493 argv_find(argv, argc, "(1-4294967295)", &idx);
17494 if (idx)
17495 seq = argv[idx]->arg;
17496
d62a17ae 17497 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17498 : COMMUNITY_DENY;
17499 argv_find(argv, argc, "AA:NN", &idx);
17500 char *str = argv_concat(argv, argc, idx);
42f914d4 17501
2f8cc0e5 17502 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17503 direct, style);
42f914d4 17504
d62a17ae 17505 XFREE(MTYPE_TMP, str);
42f914d4 17506
d62a17ae 17507 if (ret < 0) {
17508 community_list_perror(vty, ret);
17509 return CMD_WARNING_CONFIG_FAILED;
17510 }
42f914d4 17511
d62a17ae 17512 return CMD_SUCCESS;
718e3744 17513}
17514
7336e101
SP
17515DEFUN (extcommunity_list_name_expanded,
17516 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 17517 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17518 BGP_STR
17519 EXTCOMMUNITY_LIST_STR
5bf15956 17520 "Extended Community list number (expanded)\n"
718e3744 17521 "Specify expanded extcommunity-list\n"
17522 "Extended Community list name\n"
2f8cc0e5
DA
17523 "Sequence number of an entry\n"
17524 "Sequence number\n"
718e3744 17525 "Specify community to reject\n"
17526 "Specify community to accept\n"
17527 "An ordered list as a regular-expression\n")
17528{
d62a17ae 17529 int style = EXTCOMMUNITY_LIST_EXPANDED;
17530 int direct = 0;
17531 char *cl_number_or_name = NULL;
2f8cc0e5 17532 char *seq = NULL;
d62a17ae 17533 int idx = 0;
7336e101 17534
d62a17ae 17535 argv_find(argv, argc, "(100-500)", &idx);
17536 argv_find(argv, argc, "WORD", &idx);
17537 cl_number_or_name = argv[idx]->arg;
2f8cc0e5
DA
17538
17539 argv_find(argv, argc, "(1-4294967295)", &idx);
17540 if (idx)
17541 seq = argv[idx]->arg;
17542
d62a17ae 17543 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17544 : COMMUNITY_DENY;
17545 argv_find(argv, argc, "LINE", &idx);
17546 char *str = argv_concat(argv, argc, idx);
42f914d4 17547
2f8cc0e5 17548 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17549 direct, style);
42f914d4 17550
d62a17ae 17551 XFREE(MTYPE_TMP, str);
42f914d4 17552
d62a17ae 17553 if (ret < 0) {
17554 community_list_perror(vty, ret);
17555 return CMD_WARNING_CONFIG_FAILED;
17556 }
42f914d4 17557
d62a17ae 17558 return CMD_SUCCESS;
718e3744 17559}
17560
7336e101
SP
17561DEFUN (no_extcommunity_list_standard_all,
17562 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 17563 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17564 NO_STR
17565 BGP_STR
17566 EXTCOMMUNITY_LIST_STR
813d4307 17567 "Extended Community list number (standard)\n"
718e3744 17568 "Specify standard extcommunity-list\n"
5bf15956 17569 "Community list name\n"
2f8cc0e5
DA
17570 "Sequence number of an entry\n"
17571 "Sequence number\n"
718e3744 17572 "Specify community to reject\n"
17573 "Specify community to accept\n"
17574 EXTCOMMUNITY_VAL_STR)
17575{
d62a17ae 17576 int style = EXTCOMMUNITY_LIST_STANDARD;
17577 int direct = 0;
17578 char *cl_number_or_name = NULL;
d4455c89 17579 char *str = NULL;
2f8cc0e5 17580 char *seq = NULL;
d62a17ae 17581 int idx = 0;
d4455c89 17582
2f8cc0e5
DA
17583 argv_find(argv, argc, "(1-4294967295)", &idx);
17584 if (idx)
17585 seq = argv[idx]->arg;
17586
17587 idx = 0;
d4455c89
DA
17588 argv_find(argv, argc, "permit", &idx);
17589 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
17590 if (idx) {
17591 direct = argv_find(argv, argc, "permit", &idx)
17592 ? COMMUNITY_PERMIT
17593 : COMMUNITY_DENY;
17594
17595 idx = 0;
17596 argv_find(argv, argc, "AA:NN", &idx);
17597 str = argv_concat(argv, argc, idx);
17598 }
17599
17600 idx = 0;
d62a17ae 17601 argv_find(argv, argc, "(1-99)", &idx);
17602 argv_find(argv, argc, "WORD", &idx);
17603 cl_number_or_name = argv[idx]->arg;
42f914d4 17604
d62a17ae 17605 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 17606 seq, direct, style);
42f914d4 17607
d62a17ae 17608 XFREE(MTYPE_TMP, str);
42f914d4 17609
d62a17ae 17610 if (ret < 0) {
17611 community_list_perror(vty, ret);
17612 return CMD_WARNING_CONFIG_FAILED;
17613 }
42f914d4 17614
d62a17ae 17615 return CMD_SUCCESS;
718e3744 17616}
17617
d4455c89
DA
17618ALIAS(no_extcommunity_list_standard_all,
17619 no_bgp_extcommunity_list_standard_all_list_cmd,
17620 "no bgp extcommunity-list <(1-99)|standard WORD>",
17621 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17622 "Extended Community list number (standard)\n"
17623 "Specify standard extcommunity-list\n"
17624 "Community list name\n")
17625
7336e101
SP
17626DEFUN (no_extcommunity_list_expanded_all,
17627 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 17628 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17629 NO_STR
17630 BGP_STR
17631 EXTCOMMUNITY_LIST_STR
718e3744 17632 "Extended Community list number (expanded)\n"
718e3744 17633 "Specify expanded extcommunity-list\n"
5bf15956 17634 "Extended Community list name\n"
2f8cc0e5
DA
17635 "Sequence number of an entry\n"
17636 "Sequence number\n"
718e3744 17637 "Specify community to reject\n"
17638 "Specify community to accept\n"
17639 "An ordered list as a regular-expression\n")
17640{
d62a17ae 17641 int style = EXTCOMMUNITY_LIST_EXPANDED;
17642 int direct = 0;
17643 char *cl_number_or_name = NULL;
d4455c89 17644 char *str = NULL;
2f8cc0e5 17645 char *seq = NULL;
d62a17ae 17646 int idx = 0;
d4455c89 17647
2f8cc0e5
DA
17648 argv_find(argv, argc, "(1-4294967295)", &idx);
17649 if (idx)
17650 seq = argv[idx]->arg;
17651
17652 idx = 0;
d4455c89
DA
17653 argv_find(argv, argc, "permit", &idx);
17654 argv_find(argv, argc, "deny", &idx);
17655
17656 if (idx) {
17657 direct = argv_find(argv, argc, "permit", &idx)
17658 ? COMMUNITY_PERMIT
17659 : COMMUNITY_DENY;
17660
17661 idx = 0;
17662 argv_find(argv, argc, "LINE", &idx);
17663 str = argv_concat(argv, argc, idx);
17664 }
17665
17666 idx = 0;
d62a17ae 17667 argv_find(argv, argc, "(100-500)", &idx);
17668 argv_find(argv, argc, "WORD", &idx);
17669 cl_number_or_name = argv[idx]->arg;
42f914d4 17670
d62a17ae 17671 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 17672 seq, direct, style);
42f914d4 17673
d62a17ae 17674 XFREE(MTYPE_TMP, str);
42f914d4 17675
d62a17ae 17676 if (ret < 0) {
17677 community_list_perror(vty, ret);
17678 return CMD_WARNING_CONFIG_FAILED;
17679 }
42f914d4 17680
d62a17ae 17681 return CMD_SUCCESS;
718e3744 17682}
17683
d4455c89
DA
17684ALIAS(no_extcommunity_list_expanded_all,
17685 no_bgp_extcommunity_list_expanded_all_list_cmd,
17686 "no bgp extcommunity-list <(100-500)|expanded WORD>",
17687 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17688 "Extended Community list number (expanded)\n"
17689 "Specify expanded extcommunity-list\n"
17690 "Extended Community list name\n")
17691
d62a17ae 17692static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 17693{
d62a17ae 17694 struct community_entry *entry;
718e3744 17695
d62a17ae 17696 for (entry = list->head; entry; entry = entry->next) {
17697 if (entry == list->head) {
17698 if (all_digit(list->name))
17699 vty_out(vty, "Extended community %s list %s\n",
17700 entry->style == EXTCOMMUNITY_LIST_STANDARD
17701 ? "standard"
17702 : "(expanded) access",
17703 list->name);
17704 else
17705 vty_out(vty,
17706 "Named extended community %s list %s\n",
17707 entry->style == EXTCOMMUNITY_LIST_STANDARD
17708 ? "standard"
17709 : "expanded",
17710 list->name);
17711 }
17712 if (entry->any)
17713 vty_out(vty, " %s\n",
17714 community_direct_str(entry->direct));
17715 else
17716 vty_out(vty, " %s %s\n",
17717 community_direct_str(entry->direct),
8d9b8ed9 17718 community_list_config_str(entry));
d62a17ae 17719 }
718e3744 17720}
17721
7336e101
SP
17722DEFUN (show_extcommunity_list,
17723 show_bgp_extcommunity_list_cmd,
17724 "show bgp extcommunity-list",
718e3744 17725 SHOW_STR
7336e101 17726 BGP_STR
718e3744 17727 "List extended-community list\n")
17728{
d62a17ae 17729 struct community_list *list;
17730 struct community_list_master *cm;
718e3744 17731
d62a17ae 17732 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17733 if (!cm)
17734 return CMD_SUCCESS;
718e3744 17735
d62a17ae 17736 for (list = cm->num.head; list; list = list->next)
17737 extcommunity_list_show(vty, list);
718e3744 17738
d62a17ae 17739 for (list = cm->str.head; list; list = list->next)
17740 extcommunity_list_show(vty, list);
718e3744 17741
d62a17ae 17742 return CMD_SUCCESS;
718e3744 17743}
17744
7336e101
SP
17745DEFUN (show_extcommunity_list_arg,
17746 show_bgp_extcommunity_list_arg_cmd,
960b69b9 17747 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
17748 SHOW_STR
17749 BGP_STR
718e3744 17750 "List extended-community list\n"
17751 "Extcommunity-list number\n"
960b69b9 17752 "Extcommunity-list name\n"
17753 "Detailed information on extcommunity-list\n")
718e3744 17754{
d62a17ae 17755 int idx_comm_list = 3;
17756 struct community_list *list;
718e3744 17757
e237b0d2 17758 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17759 EXTCOMMUNITY_LIST_MASTER);
17760 if (!list) {
17761 vty_out(vty, "%% Can't find extcommunity-list\n");
17762 return CMD_WARNING;
17763 }
718e3744 17764
d62a17ae 17765 extcommunity_list_show(vty, list);
718e3744 17766
d62a17ae 17767 return CMD_SUCCESS;
718e3744 17768}
6b0655a2 17769
718e3744 17770/* Display community-list and extcommunity-list configuration. */
d62a17ae 17771static int community_list_config_write(struct vty *vty)
17772{
17773 struct community_list *list;
17774 struct community_entry *entry;
17775 struct community_list_master *cm;
17776 int write = 0;
17777
17778 /* Community-list. */
17779 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17780
17781 for (list = cm->num.head; list; list = list->next)
17782 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17783 vty_out(vty,
17784 "bgp community-list %s seq %" PRId64 " %s %s\n",
17785 list->name, entry->seq,
d62a17ae 17786 community_direct_str(entry->direct),
17787 community_list_config_str(entry));
17788 write++;
17789 }
17790 for (list = cm->str.head; list; list = list->next)
17791 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17792 vty_out(vty,
17793 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 17794 entry->style == COMMUNITY_LIST_STANDARD
17795 ? "standard"
17796 : "expanded",
2f8cc0e5
DA
17797 list->name, entry->seq,
17798 community_direct_str(entry->direct),
d62a17ae 17799 community_list_config_str(entry));
17800 write++;
17801 }
17802
17803 /* Extcommunity-list. */
17804 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17805
17806 for (list = cm->num.head; list; list = list->next)
17807 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17808 vty_out(vty,
17809 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
17810 list->name, entry->seq,
17811 community_direct_str(entry->direct),
d62a17ae 17812 community_list_config_str(entry));
17813 write++;
17814 }
17815 for (list = cm->str.head; list; list = list->next)
17816 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17817 vty_out(vty,
17818 "bgp extcommunity-list %s %s seq %" PRId64
17819 " %s %s\n",
d62a17ae 17820 entry->style == EXTCOMMUNITY_LIST_STANDARD
17821 ? "standard"
17822 : "expanded",
2f8cc0e5
DA
17823 list->name, entry->seq,
17824 community_direct_str(entry->direct),
d62a17ae 17825 community_list_config_str(entry));
17826 write++;
17827 }
17828
17829
17830 /* lcommunity-list. */
17831 cm = community_list_master_lookup(bgp_clist,
17832 LARGE_COMMUNITY_LIST_MASTER);
17833
17834 for (list = cm->num.head; list; list = list->next)
17835 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17836 vty_out(vty,
17837 "bgp large-community-list %s seq %" PRId64
17838 " %s %s\n",
17839 list->name, entry->seq,
17840 community_direct_str(entry->direct),
d62a17ae 17841 community_list_config_str(entry));
17842 write++;
17843 }
17844 for (list = cm->str.head; list; list = list->next)
17845 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17846 vty_out(vty,
17847 "bgp large-community-list %s %s seq %" PRId64
17848 " %s %s\n",
17849
d62a17ae 17850 entry->style == LARGE_COMMUNITY_LIST_STANDARD
17851 ? "standard"
17852 : "expanded",
2f8cc0e5 17853 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 17854 community_list_config_str(entry));
17855 write++;
17856 }
17857
17858 return write;
17859}
17860
17861static struct cmd_node community_list_node = {
17862 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 17863};
17864
d62a17ae 17865static void community_list_vty(void)
17866{
17867 install_node(&community_list_node, community_list_config_write);
17868
17869 /* Community-list. */
7336e101
SP
17870 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
17871 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
17872 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 17873 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 17874 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 17875 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
17876 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
17877 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 17878
17879 /* Extcommunity-list. */
7336e101
SP
17880 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
17881 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
17882 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
17883 install_element(CONFIG_NODE,
17884 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 17885 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
17886 install_element(CONFIG_NODE,
17887 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
17888 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
17889 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 17890
17891 /* Large Community List */
7336e101 17892 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
17893 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
17894 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 17895 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
17896 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
17897 install_element(CONFIG_NODE,
17898 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
17899 install_element(CONFIG_NODE,
17900 &no_bgp_lcommunity_list_name_expanded_all_cmd);
17901 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
17902 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
17903 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
17904 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
17905 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
17906 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 17907}