]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
lib: add flowspec safi to identitiy ref parsing
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
5cb5f4d0 25#include "lib_errors.h"
ec0ab544 26#include "lib/zclient.h"
718e3744 27#include "prefix.h"
28#include "plist.h"
29#include "buffer.h"
30#include "linklist.h"
31#include "stream.h"
32#include "thread.h"
33#include "log.h"
3b8b1855 34#include "memory.h"
1c0d8808 35#include "lib_vty.h"
4bf6a362 36#include "hash.h"
3f9c7369 37#include "queue.h"
039f3a34 38#include "filter.h"
5d5ba018 39#include "frrstr.h"
718e3744 40
41#include "bgpd/bgpd.h"
48ecf8f5 42#include "bgpd/bgp_attr_evpn.h"
4bf6a362 43#include "bgpd/bgp_advertise.h"
718e3744 44#include "bgpd/bgp_attr.h"
45#include "bgpd/bgp_aspath.h"
46#include "bgpd/bgp_community.h"
4bf6a362 47#include "bgpd/bgp_ecommunity.h"
57d187bc 48#include "bgpd/bgp_lcommunity.h"
4bf6a362 49#include "bgpd/bgp_damp.h"
718e3744 50#include "bgpd/bgp_debug.h"
14454c9f 51#include "bgpd/bgp_errors.h"
e0701b79 52#include "bgpd/bgp_fsm.h"
4bf6a362 53#include "bgpd/bgp_nexthop.h"
718e3744 54#include "bgpd/bgp_open.h"
4bf6a362 55#include "bgpd/bgp_regex.h"
718e3744 56#include "bgpd/bgp_route.h"
c016b6c7 57#include "bgpd/bgp_mplsvpn.h"
718e3744 58#include "bgpd/bgp_zebra.h"
fee0f4c6 59#include "bgpd/bgp_table.h"
94f2b392 60#include "bgpd/bgp_vty.h"
165b5fff 61#include "bgpd/bgp_mpath.h"
cb1faec9 62#include "bgpd/bgp_packet.h"
3f9c7369 63#include "bgpd/bgp_updgrp.h"
c43ed2e4 64#include "bgpd/bgp_bfd.h"
555e09d4 65#include "bgpd/bgp_io.h"
94c2f693 66#include "bgpd/bgp_evpn.h"
dd65f45e 67#include "bgpd/bgp_evpn_vty.h"
b5e140c8 68#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 69#include "bgpd/bgp_addpath.h"
48ecf8f5 70#include "bgpd/bgp_mac.h"
dd65f45e 71#include "bgpd/bgp_flowspec.h"
49e5a4a0 72#ifdef ENABLE_BGP_VNC
dd65f45e
DL
73#include "bgpd/rfapi/bgp_rfapi_cfg.h"
74#endif
75
ff8a8a7a
CS
76#include "northbound.h"
77#include "northbound_cli.h"
78#include "bgpd/bgp_nb.h"
79
80
5d5393b9 81FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
5d5393b9
DL
88)
89FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
5d5393b9 92)
aef999a2
DA
93FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96)
5d5393b9 97FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
5d5393b9
DL
100)
101FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
5d5393b9
DL
104)
105FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108)
109FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112)
113FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
116)
1d3fdccf
DA
117FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
121)
5d5393b9 122
dd65f45e
DL
123DEFINE_HOOK(bgp_inst_config_write,
124 (struct bgp *bgp, struct vty *vty),
125 (bgp, vty))
718e3744 126
36235319
QY
127#define GR_NO_OPER \
128 "The Graceful Restart No Operation was executed as cmd same as previous one."
129#define GR_INVALID \
130 "The Graceful Restart command used is not valid at this moment."
d62a17ae 131static struct peer_group *listen_range_exists(struct bgp *bgp,
132 struct prefix *range, int exact);
133
055679e9 134/* Show BGP peer's information. */
135enum show_type {
136 show_all,
137 show_peer,
138 show_ipv4_all,
139 show_ipv6_all,
140 show_ipv4_peer,
141 show_ipv6_peer
142};
143
36235319
QY
144static struct peer_group *listen_range_exists(struct bgp *bgp,
145 struct prefix *range, int exact);
2986cac2 146
36235319
QY
147static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
148 struct bgp *bgp,
149 bool use_json,
150 json_object *json);
2986cac2 151
36235319
QY
152static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
153 enum show_type type,
154 const char *ip_str,
155 afi_t afi, bool use_json);
2986cac2 156
d62a17ae 157static enum node_type bgp_node_type(afi_t afi, safi_t safi)
158{
159 switch (afi) {
160 case AFI_IP:
161 switch (safi) {
162 case SAFI_UNICAST:
163 return BGP_IPV4_NODE;
d62a17ae 164 case SAFI_MULTICAST:
165 return BGP_IPV4M_NODE;
d62a17ae 166 case SAFI_LABELED_UNICAST:
167 return BGP_IPV4L_NODE;
d62a17ae 168 case SAFI_MPLS_VPN:
169 return BGP_VPNV4_NODE;
7c40bf39 170 case SAFI_FLOWSPEC:
171 return BGP_FLOWSPECV4_NODE;
5c525538
RW
172 default:
173 /* not expected */
174 return BGP_IPV4_NODE;
d62a17ae 175 }
176 break;
177 case AFI_IP6:
178 switch (safi) {
179 case SAFI_UNICAST:
180 return BGP_IPV6_NODE;
d62a17ae 181 case SAFI_MULTICAST:
182 return BGP_IPV6M_NODE;
d62a17ae 183 case SAFI_LABELED_UNICAST:
184 return BGP_IPV6L_NODE;
d62a17ae 185 case SAFI_MPLS_VPN:
186 return BGP_VPNV6_NODE;
7c40bf39 187 case SAFI_FLOWSPEC:
188 return BGP_FLOWSPECV6_NODE;
5c525538
RW
189 default:
190 /* not expected */
191 return BGP_IPV4_NODE;
d62a17ae 192 }
193 break;
194 case AFI_L2VPN:
195 return BGP_EVPN_NODE;
b26f891d 196 case AFI_UNSPEC:
d62a17ae 197 case AFI_MAX:
198 // We should never be here but to clarify the switch statement..
199 return BGP_IPV4_NODE;
d62a17ae 200 }
201
202 // Impossible to happen
203 return BGP_IPV4_NODE;
f51bae9c 204}
20eb8864 205
5cb5f4d0
DD
206static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
207{
208 if (afi == AFI_IP && safi == SAFI_UNICAST)
209 return "IPv4 Unicast";
210 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
211 return "IPv4 Multicast";
212 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
213 return "IPv4 Labeled Unicast";
214 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
215 return "IPv4 VPN";
216 else if (afi == AFI_IP && safi == SAFI_ENCAP)
217 return "IPv4 Encap";
218 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
219 return "IPv4 Flowspec";
220 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
221 return "IPv6 Unicast";
222 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
223 return "IPv6 Multicast";
224 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
225 return "IPv6 Labeled Unicast";
226 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
227 return "IPv6 VPN";
228 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
229 return "IPv6 Encap";
230 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
231 return "IPv6 Flowspec";
232 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
233 return "L2VPN EVPN";
8e5509b0 234 else
5cb5f4d0 235 return "Unknown";
5cb5f4d0
DD
236}
237
238/*
239 * Please note that we have intentionally camelCased
240 * the return strings here. So if you want
241 * to use this function, please ensure you
242 * are doing this within json output
243 */
244static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
245{
246 if (afi == AFI_IP && safi == SAFI_UNICAST)
247 return "ipv4Unicast";
248 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
249 return "ipv4Multicast";
250 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
251 return "ipv4LabeledUnicast";
252 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
253 return "ipv4Vpn";
254 else if (afi == AFI_IP && safi == SAFI_ENCAP)
255 return "ipv4Encap";
256 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
257 return "ipv4Flowspec";
258 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
259 return "ipv6Unicast";
260 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
261 return "ipv6Multicast";
262 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
263 return "ipv6LabeledUnicast";
264 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
265 return "ipv6Vpn";
266 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
267 return "ipv6Encap";
268 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
269 return "ipv6Flowspec";
270 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
271 return "l2VpnEvpn";
8e5509b0 272 else
5cb5f4d0 273 return "Unknown";
5cb5f4d0
DD
274}
275
37a87b8f
CS
276/* return string maps to afi-safi specific container names
277 * defined in bgp yang file.
278 */
279const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
280{
281 if (afi == AFI_IP && safi == SAFI_UNICAST)
282 return "ipv4-unicast";
283 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
284 return "ipv4-multicast";
285 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
286 return "ipv4-labeled-unicast";
287 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
288 return "l3vpn-ipv4-unicast";
289 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
290 return "ipv4-flowspec";
291 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
292 return "ipv6-unicast";
293 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
294 return "ipv6-multicast";
295 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
296 return "ipv6-labeled-unicast";
297 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
298 return "l3vpn-ipv6-unicast";
299 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
300 return "ipv6-flowspec";
301 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
302 return "l2vpn-evpn";
303 else
304 return "Unknown";
305}
306
718e3744 307/* Utility function to get address family from current node. */
d62a17ae 308afi_t bgp_node_afi(struct vty *vty)
309{
310 afi_t afi;
311 switch (vty->node) {
312 case BGP_IPV6_NODE:
313 case BGP_IPV6M_NODE:
314 case BGP_IPV6L_NODE:
315 case BGP_VPNV6_NODE:
7c40bf39 316 case BGP_FLOWSPECV6_NODE:
d62a17ae 317 afi = AFI_IP6;
318 break;
319 case BGP_EVPN_NODE:
320 afi = AFI_L2VPN;
321 break;
322 default:
323 afi = AFI_IP;
324 break;
325 }
326 return afi;
718e3744 327}
328
329/* Utility function to get subsequent address family from current
330 node. */
d62a17ae 331safi_t bgp_node_safi(struct vty *vty)
332{
333 safi_t safi;
334 switch (vty->node) {
335 case BGP_VPNV4_NODE:
336 case BGP_VPNV6_NODE:
337 safi = SAFI_MPLS_VPN;
338 break;
339 case BGP_IPV4M_NODE:
340 case BGP_IPV6M_NODE:
341 safi = SAFI_MULTICAST;
342 break;
343 case BGP_EVPN_NODE:
344 safi = SAFI_EVPN;
345 break;
346 case BGP_IPV4L_NODE:
347 case BGP_IPV6L_NODE:
348 safi = SAFI_LABELED_UNICAST;
349 break;
7c40bf39 350 case BGP_FLOWSPECV4_NODE:
351 case BGP_FLOWSPECV6_NODE:
352 safi = SAFI_FLOWSPEC;
353 break;
d62a17ae 354 default:
355 safi = SAFI_UNICAST;
356 break;
357 }
358 return safi;
718e3744 359}
360
55f91488
QY
361/**
362 * Converts an AFI in string form to afi_t
363 *
364 * @param afi string, one of
365 * - "ipv4"
366 * - "ipv6"
81cf0de5 367 * - "l2vpn"
55f91488
QY
368 * @return the corresponding afi_t
369 */
d62a17ae 370afi_t bgp_vty_afi_from_str(const char *afi_str)
371{
372 afi_t afi = AFI_MAX; /* unknown */
373 if (strmatch(afi_str, "ipv4"))
374 afi = AFI_IP;
375 else if (strmatch(afi_str, "ipv6"))
376 afi = AFI_IP6;
81cf0de5
CS
377 else if (strmatch(afi_str, "l2vpn"))
378 afi = AFI_L2VPN;
d62a17ae 379 return afi;
380}
381
382int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
383 afi_t *afi)
384{
385 int ret = 0;
386 if (argv_find(argv, argc, "ipv4", index)) {
387 ret = 1;
388 if (afi)
389 *afi = AFI_IP;
390 } else if (argv_find(argv, argc, "ipv6", index)) {
391 ret = 1;
392 if (afi)
393 *afi = AFI_IP6;
8688b3e7
DS
394 } else if (argv_find(argv, argc, "l2vpn", index)) {
395 ret = 1;
396 if (afi)
397 *afi = AFI_L2VPN;
d62a17ae 398 }
399 return ret;
46f296b4
LB
400}
401
375a2e67 402/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 403safi_t bgp_vty_safi_from_str(const char *safi_str)
404{
405 safi_t safi = SAFI_MAX; /* unknown */
406 if (strmatch(safi_str, "multicast"))
407 safi = SAFI_MULTICAST;
408 else if (strmatch(safi_str, "unicast"))
409 safi = SAFI_UNICAST;
410 else if (strmatch(safi_str, "vpn"))
411 safi = SAFI_MPLS_VPN;
81cf0de5
CS
412 else if (strmatch(safi_str, "evpn"))
413 safi = SAFI_EVPN;
d62a17ae 414 else if (strmatch(safi_str, "labeled-unicast"))
415 safi = SAFI_LABELED_UNICAST;
7c40bf39 416 else if (strmatch(safi_str, "flowspec"))
417 safi = SAFI_FLOWSPEC;
d62a17ae 418 return safi;
419}
420
421int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
422 safi_t *safi)
423{
424 int ret = 0;
425 if (argv_find(argv, argc, "unicast", index)) {
426 ret = 1;
427 if (safi)
428 *safi = SAFI_UNICAST;
429 } else if (argv_find(argv, argc, "multicast", index)) {
430 ret = 1;
431 if (safi)
432 *safi = SAFI_MULTICAST;
433 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
434 ret = 1;
435 if (safi)
436 *safi = SAFI_LABELED_UNICAST;
437 } else if (argv_find(argv, argc, "vpn", index)) {
438 ret = 1;
439 if (safi)
440 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
441 } else if (argv_find(argv, argc, "evpn", index)) {
442 ret = 1;
443 if (safi)
444 *safi = SAFI_EVPN;
7c40bf39 445 } else if (argv_find(argv, argc, "flowspec", index)) {
446 ret = 1;
447 if (safi)
448 *safi = SAFI_FLOWSPEC;
d62a17ae 449 }
450 return ret;
46f296b4
LB
451}
452
5d5393b9
DL
453int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
454 enum bgp_instance_type inst_type)
455{
456 int ret = bgp_get(bgp, as, name, inst_type);
457
458 if (ret == BGP_CREATED) {
459 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
460 DFLT_BGP_CONNECT_RETRY);
461
462 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 463 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 464 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 465 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
466 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
467 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 468 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 469 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 470 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 471 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
472 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
473 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
5d5393b9
DL
474
475 ret = BGP_SUCCESS;
476 }
477 return ret;
478}
479
7eeee51e 480/*
f212a857 481 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 482 *
f212a857
DS
483 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
484 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
485 * to appropriate values for the calling function. This is to allow the
486 * calling function to make decisions appropriate for the show command
487 * that is being parsed.
488 *
489 * The show commands are generally of the form:
d62a17ae 490 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
491 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
492 *
493 * Since we use argv_find if the show command in particular doesn't have:
494 * [ip]
18c57037 495 * [<view|vrf> VIEWVRFNAME]
375a2e67 496 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
497 * The command parsing should still be ok.
498 *
499 * vty -> The vty for the command so we can output some useful data in
500 * the event of a parse error in the vrf.
501 * argv -> The command tokens
502 * argc -> How many command tokens we have
d62a17ae 503 * idx -> The current place in the command, generally should be 0 for this
504 * function
7eeee51e
DS
505 * afi -> The parsed afi if it was included in the show command, returned here
506 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 507 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 508 * use_json -> json is configured or not
7eeee51e
DS
509 *
510 * The function returns the correct location in the parse tree for the
511 * last token found.
0e37c258
DS
512 *
513 * Returns 0 for failure to parse correctly, else the idx position of where
514 * it found the last token.
7eeee51e 515 */
d62a17ae 516int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
517 struct cmd_token **argv, int argc,
518 int *idx, afi_t *afi, safi_t *safi,
9f049418 519 struct bgp **bgp, bool use_json)
d62a17ae 520{
521 char *vrf_name = NULL;
522
523 assert(afi);
524 assert(safi);
525 assert(bgp);
526
527 if (argv_find(argv, argc, "ip", idx))
528 *afi = AFI_IP;
529
9a8bdf1c 530 if (argv_find(argv, argc, "view", idx))
d62a17ae 531 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
532 else if (argv_find(argv, argc, "vrf", idx)) {
533 vrf_name = argv[*idx + 1]->arg;
534 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
535 vrf_name = NULL;
536 }
537 if (vrf_name) {
d62a17ae 538 if (strmatch(vrf_name, "all"))
539 *bgp = NULL;
540 else {
541 *bgp = bgp_lookup_by_name(vrf_name);
542 if (!*bgp) {
52e5b8c4
SP
543 if (use_json) {
544 json_object *json = NULL;
545 json = json_object_new_object();
546 json_object_string_add(
547 json, "warning",
548 "View/Vrf is unknown");
549 vty_out(vty, "%s\n",
550 json_object_to_json_string_ext(json,
551 JSON_C_TO_STRING_PRETTY));
552 json_object_free(json);
553 }
ca61fd25
DS
554 else
555 vty_out(vty, "View/Vrf %s is unknown\n",
556 vrf_name);
d62a17ae 557 *idx = 0;
558 return 0;
559 }
560 }
561 } else {
562 *bgp = bgp_get_default();
563 if (!*bgp) {
52e5b8c4
SP
564 if (use_json) {
565 json_object *json = NULL;
566 json = json_object_new_object();
567 json_object_string_add(
568 json, "warning",
569 "Default BGP instance not found");
570 vty_out(vty, "%s\n",
571 json_object_to_json_string_ext(json,
572 JSON_C_TO_STRING_PRETTY));
573 json_object_free(json);
574 }
ca61fd25
DS
575 else
576 vty_out(vty,
577 "Default BGP instance not found\n");
d62a17ae 578 *idx = 0;
579 return 0;
580 }
581 }
582
583 if (argv_find_and_parse_afi(argv, argc, idx, afi))
584 argv_find_and_parse_safi(argv, argc, idx, safi);
585
586 *idx += 1;
587 return *idx;
588}
589
3dc339cd 590static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 591{
592 struct interface *ifp = NULL;
593
594 if (su->sa.sa_family == AF_INET)
595 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
596 else if (su->sa.sa_family == AF_INET6)
597 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
598 su->sin6.sin6_scope_id,
599 bgp->vrf_id);
600
601 if (ifp)
3dc339cd 602 return true;
d62a17ae 603
3dc339cd 604 return false;
718e3744 605}
606
607/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
608/* This is used only for configuration, so disallow if attempted on
609 * a dynamic neighbor.
610 */
d62a17ae 611static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
612{
613 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
614 int ret;
615 union sockunion su;
616 struct peer *peer;
617
618 if (!bgp) {
619 return NULL;
620 }
621
622 ret = str2sockunion(ip_str, &su);
623 if (ret < 0) {
624 peer = peer_lookup_by_conf_if(bgp, ip_str);
625 if (!peer) {
626 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
627 == NULL) {
628 vty_out(vty,
629 "%% Malformed address or name: %s\n",
630 ip_str);
631 return NULL;
632 }
633 }
634 } else {
635 peer = peer_lookup(bgp, &su);
636 if (!peer) {
637 vty_out(vty,
638 "%% Specify remote-as or peer-group commands first\n");
639 return NULL;
640 }
641 if (peer_dynamic_neighbor(peer)) {
642 vty_out(vty,
643 "%% Operation not allowed on a dynamic neighbor\n");
644 return NULL;
645 }
646 }
647 return peer;
718e3744 648}
649
650/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
651/* This is used only for configuration, so disallow if attempted on
652 * a dynamic neighbor.
653 */
d62a17ae 654struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
655{
656 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
657 int ret;
658 union sockunion su;
659 struct peer *peer = NULL;
660 struct peer_group *group = NULL;
661
662 if (!bgp) {
663 return NULL;
664 }
665
666 ret = str2sockunion(peer_str, &su);
667 if (ret == 0) {
668 /* IP address, locate peer. */
669 peer = peer_lookup(bgp, &su);
670 } else {
671 /* Not IP, could match either peer configured on interface or a
672 * group. */
673 peer = peer_lookup_by_conf_if(bgp, peer_str);
674 if (!peer)
675 group = peer_group_lookup(bgp, peer_str);
676 }
677
678 if (peer) {
679 if (peer_dynamic_neighbor(peer)) {
680 vty_out(vty,
681 "%% Operation not allowed on a dynamic neighbor\n");
682 return NULL;
683 }
684
685 return peer;
686 }
687
688 if (group)
689 return group->conf;
690
691 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
692
693 return NULL;
694}
695
696int bgp_vty_return(struct vty *vty, int ret)
697{
698 const char *str = NULL;
699
700 switch (ret) {
701 case BGP_ERR_INVALID_VALUE:
702 str = "Invalid value";
703 break;
704 case BGP_ERR_INVALID_FLAG:
705 str = "Invalid flag";
706 break;
707 case BGP_ERR_PEER_GROUP_SHUTDOWN:
708 str = "Peer-group has been shutdown. Activate the peer-group first";
709 break;
710 case BGP_ERR_PEER_FLAG_CONFLICT:
711 str = "Can't set override-capability and strict-capability-match at the same time";
712 break;
713 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
714 str = "Specify remote-as or peer-group remote AS first";
715 break;
716 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
717 str = "Cannot change the peer-group. Deconfigure first";
718 break;
719 case BGP_ERR_PEER_GROUP_MISMATCH:
720 str = "Peer is not a member of this peer-group";
721 break;
722 case BGP_ERR_PEER_FILTER_CONFLICT:
723 str = "Prefix/distribute list can not co-exist";
724 break;
725 case BGP_ERR_NOT_INTERNAL_PEER:
726 str = "Invalid command. Not an internal neighbor";
727 break;
728 case BGP_ERR_REMOVE_PRIVATE_AS:
729 str = "remove-private-AS cannot be configured for IBGP peers";
730 break;
731 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
732 str = "Local-AS allowed only for EBGP peers";
733 break;
734 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
735 str = "Cannot have local-as same as BGP AS number";
736 break;
737 case BGP_ERR_TCPSIG_FAILED:
738 str = "Error while applying TCP-Sig to session(s)";
739 break;
740 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
741 str = "ebgp-multihop and ttl-security cannot be configured together";
742 break;
743 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
744 str = "ttl-security only allowed for EBGP peers";
745 break;
746 case BGP_ERR_AS_OVERRIDE:
747 str = "as-override cannot be configured for IBGP peers";
748 break;
749 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
750 str = "Invalid limit for number of dynamic neighbors";
751 break;
752 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
753 str = "Dynamic neighbor listen range already exists";
754 break;
755 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
756 str = "Operation not allowed on a dynamic neighbor";
757 break;
758 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
759 str = "Operation not allowed on a directly connected neighbor";
760 break;
761 case BGP_ERR_PEER_SAFI_CONFLICT:
055679e9 762 str = GR_INVALID;
763 break;
764 case BGP_ERR_GR_INVALID_CMD:
765 str = "The Graceful Restart command used is not valid at this moment.";
766 break;
767 case BGP_ERR_GR_OPERATION_FAILED:
768 str = "The Graceful Restart Operation failed due to an err.";
769 break;
770 case BGP_GR_NO_OPERATION:
771 str = GR_NO_OPER;
d62a17ae 772 break;
773 }
774 if (str) {
775 vty_out(vty, "%% %s\n", str);
776 return CMD_WARNING_CONFIG_FAILED;
777 }
778 return CMD_SUCCESS;
718e3744 779}
780
7aafcaca 781/* BGP clear sort. */
d62a17ae 782enum clear_sort {
783 clear_all,
784 clear_peer,
785 clear_group,
786 clear_external,
787 clear_as
7aafcaca
DS
788};
789
ff8a8a7a
CS
790static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
791 int error, char *errmsg, size_t errmsg_len)
d62a17ae 792{
793 switch (error) {
794 case BGP_ERR_AF_UNCONFIGURED:
ff8a8a7a
CS
795 snprintf(errmsg, errmsg_len,
796 "%%BGP: Enable %s address family for the neighbor %s",
797 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 798 break;
799 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
ff8a8a7a
CS
800 snprintf(
801 errmsg, errmsg_len,
802 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
d62a17ae 803 peer->host);
804 break;
805 default:
806 break;
807 }
7aafcaca
DS
808}
809
dc912615 810static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 811 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
812{
813 int ret = 0;
814
815 /* if afi/.safi not specified, spin thru all of them */
816 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
817 afi_t tmp_afi;
818 safi_t tmp_safi;
819
820 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
821 if (!peer->afc[tmp_afi][tmp_safi])
822 continue;
823
824 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 825 ret = peer_clear(peer, nnode);
dc912615
DS
826 else
827 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
828 stype);
829 }
830 /* if afi specified and safi not, spin thru safis on this afi */
831 } else if (safi == SAFI_UNSPEC) {
832 safi_t tmp_safi;
833
834 for (tmp_safi = SAFI_UNICAST;
835 tmp_safi < SAFI_MAX; tmp_safi++) {
836 if (!peer->afc[afi][tmp_safi])
837 continue;
838
839 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 840 ret = peer_clear(peer, nnode);
dc912615
DS
841 else
842 ret = peer_clear_soft(peer, afi,
843 tmp_safi, stype);
844 }
845 /* both afi/safi specified, let the caller know if not defined */
846 } else {
847 if (!peer->afc[afi][safi])
848 return 1;
849
850 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 851 ret = peer_clear(peer, nnode);
dc912615
DS
852 else
853 ret = peer_clear_soft(peer, afi, safi, stype);
854 }
855
856 return ret;
857}
858
7aafcaca 859/* `clear ip bgp' functions. */
ff8a8a7a 860static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 861 enum clear_sort sort, enum bgp_clear_type stype,
ff8a8a7a 862 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 863{
dc912615 864 int ret = 0;
3ae8bfa5 865 bool found = false;
d62a17ae 866 struct peer *peer;
dc95985f 867
868 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 869
870 /* Clear all neighbors. */
871 /*
872 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
873 * nodes on the BGP instance as that may get freed if it is a
874 * doppelganger
d62a17ae 875 */
876 if (sort == clear_all) {
877 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 878
879 bgp_peer_gr_flags_update(peer);
880
36235319 881 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 882 gr_router_detected = true;
883
c368171c 884 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 885 stype);
d62a17ae 886
887 if (ret < 0)
ff8a8a7a
CS
888 bgp_clear_vty_error(peer, afi, safi, ret,
889 errmsg, errmsg_len);
dc95985f 890 }
891
36235319
QY
892 if (gr_router_detected
893 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 894 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
895 } else if (!gr_router_detected
896 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 897 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 898 }
d62a17ae 899
900 /* This is to apply read-only mode on this clear. */
901 if (stype == BGP_CLEAR_SOFT_NONE)
902 bgp->update_delay_over = 0;
903
904 return CMD_SUCCESS;
7aafcaca
DS
905 }
906
3ae8bfa5 907 /* Clear specified neighbor. */
d62a17ae 908 if (sort == clear_peer) {
909 union sockunion su;
d62a17ae 910
911 /* Make sockunion for lookup. */
912 ret = str2sockunion(arg, &su);
913 if (ret < 0) {
914 peer = peer_lookup_by_conf_if(bgp, arg);
915 if (!peer) {
916 peer = peer_lookup_by_hostname(bgp, arg);
917 if (!peer) {
ff8a8a7a
CS
918 snprintf(
919 errmsg, errmsg_len,
920 "Malformed address or name: %s",
d62a17ae 921 arg);
922 return CMD_WARNING;
923 }
924 }
925 } else {
926 peer = peer_lookup(bgp, &su);
927 if (!peer) {
ff8a8a7a
CS
928 snprintf(errmsg, errmsg_len,
929 "%%BGP: Unknown neighbor - \"%s\"",
930 arg);
d62a17ae 931 return CMD_WARNING;
932 }
933 }
7aafcaca 934
dc95985f 935 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
936 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
937
dc912615
DS
938 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
939
940 /* if afi/safi not defined for this peer, let caller know */
941 if (ret == 1)
3ae8bfa5 942 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 943
d62a17ae 944 if (ret < 0)
ff8a8a7a
CS
945 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
946 errmsg_len);
7aafcaca 947
d62a17ae 948 return CMD_SUCCESS;
7aafcaca 949 }
7aafcaca 950
3ae8bfa5 951 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 952 if (sort == clear_group) {
953 struct peer_group *group;
7aafcaca 954
d62a17ae 955 group = peer_group_lookup(bgp, arg);
956 if (!group) {
ff8a8a7a
CS
957 snprintf(errmsg, errmsg_len,
958 "%%BGP: No such peer-group %s", arg);
d62a17ae 959 return CMD_WARNING;
960 }
961
962 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 963 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 964
d62a17ae 965 if (ret < 0)
ff8a8a7a
CS
966 bgp_clear_vty_error(peer, afi, safi, ret,
967 errmsg, errmsg_len);
3ae8bfa5
PM
968 else
969 found = true;
d62a17ae 970 }
3ae8bfa5
PM
971
972 if (!found)
ff8a8a7a
CS
973 snprintf(
974 errmsg, errmsg_len,
975 "%%BGP: No %s peer belonging to peer-group %s is configured",
5cb5f4d0 976 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 977
d62a17ae 978 return CMD_SUCCESS;
7aafcaca 979 }
7aafcaca 980
3ae8bfa5 981 /* Clear all external (eBGP) neighbors. */
d62a17ae 982 if (sort == clear_external) {
983 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
984 if (peer->sort == BGP_PEER_IBGP)
985 continue;
7aafcaca 986
dc95985f 987 bgp_peer_gr_flags_update(peer);
988
36235319 989 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 990 gr_router_detected = true;
dc95985f 991
c368171c 992 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 993
d62a17ae 994 if (ret < 0)
ff8a8a7a
CS
995 bgp_clear_vty_error(peer, afi, safi, ret,
996 errmsg, errmsg_len);
3ae8bfa5
PM
997 else
998 found = true;
d62a17ae 999 }
3ae8bfa5 1000
36235319
QY
1001 if (gr_router_detected
1002 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1003 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1004 } else if (!gr_router_detected
1005 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1006 bgp_zebra_send_capabilities(bgp, true);
1007 }
1008
3ae8bfa5 1009 if (!found)
ff8a8a7a
CS
1010 snprintf(errmsg, errmsg_len,
1011 "%%BGP: No external %s peer is configured",
1012 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1013
d62a17ae 1014 return CMD_SUCCESS;
1015 }
1016
3ae8bfa5 1017 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1018 if (sort == clear_as) {
3ae8bfa5 1019 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1020
1021 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1022 if (peer->as != as)
1023 continue;
1024
dc95985f 1025 bgp_peer_gr_flags_update(peer);
1026
36235319 1027 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1028 gr_router_detected = true;
dc95985f 1029
c368171c 1030 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1031
1032 if (ret < 0)
ff8a8a7a
CS
1033 bgp_clear_vty_error(peer, afi, safi, ret,
1034 errmsg, errmsg_len);
3ae8bfa5
PM
1035 else
1036 found = true;
d62a17ae 1037 }
3ae8bfa5 1038
36235319
QY
1039 if (gr_router_detected
1040 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1041 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1042 } else if (!gr_router_detected
1043 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1044 bgp_zebra_send_capabilities(bgp, true);
1045 }
1046
3ae8bfa5 1047 if (!found)
ff8a8a7a
CS
1048 snprintf(errmsg, errmsg_len,
1049 "%%BGP: No %s peer is configured with AS %s",
1050 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1051
d62a17ae 1052 return CMD_SUCCESS;
1053 }
1054
1055 return CMD_SUCCESS;
1056}
1057
ff8a8a7a
CS
1058static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1059 enum clear_sort sort, enum bgp_clear_type stype,
1060 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1061{
1062 struct bgp *bgp;
1063
1064 /* BGP structure lookup. */
1065 if (name) {
1066 bgp = bgp_lookup_by_name(name);
1067 if (bgp == NULL) {
ff8a8a7a
CS
1068 snprintf(errmsg, errmsg_len,
1069 "Can't find BGP instance %s", name);
d62a17ae 1070 return CMD_WARNING;
1071 }
1072 } else {
1073 bgp = bgp_get_default();
1074 if (bgp == NULL) {
ff8a8a7a
CS
1075 snprintf(errmsg, errmsg_len,
1076 "No BGP process is configured");
d62a17ae 1077 return CMD_WARNING;
1078 }
1079 }
1080
ff8a8a7a 1081 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
7aafcaca
DS
1082}
1083
1084/* clear soft inbound */
ff8a8a7a 1085int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1086{
99b3ebd3
NS
1087 afi_t afi;
1088 safi_t safi;
ff8a8a7a
CS
1089 int ret;
1090
1091 FOREACH_AFI_SAFI (afi, safi) {
1092 ret = bgp_clear_vty(name, afi, safi, clear_all,
1093 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1094 errmsg_len);
1095 if (ret != CMD_SUCCESS)
1096 return -1;
1097 }
99b3ebd3 1098
ff8a8a7a 1099 return 0;
7aafcaca
DS
1100}
1101
1102/* clear soft outbound */
ff8a8a7a 1103int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1104{
99b3ebd3
NS
1105 afi_t afi;
1106 safi_t safi;
ff8a8a7a 1107 int ret;
99b3ebd3 1108
ff8a8a7a
CS
1109 FOREACH_AFI_SAFI (afi, safi) {
1110 ret = bgp_clear_vty(name, afi, safi, clear_all,
1111 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1112 errmsg_len);
1113 if (ret != CMD_SUCCESS)
1114 return -1;
1115 }
1116
1117 return 0;
7aafcaca
DS
1118}
1119
1120
f787d7a0 1121#ifndef VTYSH_EXTRACT_PL
2e4c2296 1122#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1123#endif
1124
8029b216
AK
1125DEFUN_HIDDEN (bgp_local_mac,
1126 bgp_local_mac_cmd,
093e3f23 1127 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1128 BGP_STR
1129 "Local MAC config\n"
1130 "VxLAN Network Identifier\n"
1131 "VNI number\n"
1132 "local mac\n"
1133 "mac address\n"
1134 "mac-mobility sequence\n"
1135 "seq number\n")
1136{
1137 int rv;
1138 vni_t vni;
1139 struct ethaddr mac;
1140 struct ipaddr ip;
1141 uint32_t seq;
1142 struct bgp *bgp;
1143
1144 vni = strtoul(argv[3]->arg, NULL, 10);
1145 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1146 vty_out(vty, "%% Malformed MAC address\n");
1147 return CMD_WARNING;
1148 }
1149 memset(&ip, 0, sizeof(ip));
1150 seq = strtoul(argv[7]->arg, NULL, 10);
1151
1152 bgp = bgp_get_default();
1153 if (!bgp) {
1154 vty_out(vty, "Default BGP instance is not there\n");
1155 return CMD_WARNING;
1156 }
1157
b5e140c8
AK
1158 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1159 zero_esi);
8029b216
AK
1160 if (rv < 0) {
1161 vty_out(vty, "Internal error\n");
1162 return CMD_WARNING;
1163 }
1164
1165 return CMD_SUCCESS;
1166}
1167
1168DEFUN_HIDDEN (no_bgp_local_mac,
1169 no_bgp_local_mac_cmd,
093e3f23 1170 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1171 NO_STR
1172 BGP_STR
1173 "Local MAC config\n"
1174 "VxLAN Network Identifier\n"
1175 "VNI number\n"
1176 "local mac\n"
1177 "mac address\n")
1178{
1179 int rv;
1180 vni_t vni;
1181 struct ethaddr mac;
1182 struct ipaddr ip;
1183 struct bgp *bgp;
1184
1185 vni = strtoul(argv[4]->arg, NULL, 10);
1186 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1187 vty_out(vty, "%% Malformed MAC address\n");
1188 return CMD_WARNING;
1189 }
1190 memset(&ip, 0, sizeof(ip));
1191
1192 bgp = bgp_get_default();
1193 if (!bgp) {
1194 vty_out(vty, "Default BGP instance is not there\n");
1195 return CMD_WARNING;
1196 }
1197
ec0ab544 1198 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1199 if (rv < 0) {
1200 vty_out(vty, "Internal error\n");
1201 return CMD_WARNING;
1202 }
1203
1204 return CMD_SUCCESS;
1205}
1206
718e3744 1207DEFUN (no_synchronization,
1208 no_synchronization_cmd,
1209 "no synchronization",
1210 NO_STR
1211 "Perform IGP synchronization\n")
1212{
d62a17ae 1213 return CMD_SUCCESS;
718e3744 1214}
1215
1216DEFUN (no_auto_summary,
1217 no_auto_summary_cmd,
1218 "no auto-summary",
1219 NO_STR
1220 "Enable automatic network number summarization\n")
1221{
d62a17ae 1222 return CMD_SUCCESS;
718e3744 1223}
3d515fd9 1224
718e3744 1225/* "router bgp" commands. */
ff8a8a7a
CS
1226DEFUN_YANG_NOSH(router_bgp,
1227 router_bgp_cmd,
1228 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1229 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1230{
d62a17ae 1231 int idx_asn = 2;
1232 int idx_view_vrf = 3;
1233 int idx_vrf = 4;
ff8a8a7a 1234 int ret = CMD_SUCCESS;
d62a17ae 1235 as_t as;
1236 struct bgp *bgp;
1237 const char *name = NULL;
ff8a8a7a 1238 char as_str[12] = {'\0'};
d62a17ae 1239 enum bgp_instance_type inst_type;
ff8a8a7a 1240 char base_xpath[XPATH_MAXLEN];
d62a17ae 1241
1242 // "router bgp" without an ASN
1243 if (argc == 2) {
1244 // Pending: Make VRF option available for ASN less config
1245 bgp = bgp_get_default();
1246
1247 if (bgp == NULL) {
1248 vty_out(vty, "%% No BGP process is configured\n");
1249 return CMD_WARNING_CONFIG_FAILED;
1250 }
1251
1252 if (listcount(bm->bgp) > 1) {
996c9314 1253 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1254 return CMD_WARNING_CONFIG_FAILED;
1255 }
ff8a8a7a
CS
1256
1257 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
5ce106b7 1258 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
ff8a8a7a
CS
1259
1260 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1261 snprintf(as_str, 12, "%d", bgp->as);
87ce2564
CS
1262 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1263 as_str);
ff8a8a7a 1264 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1265 nb_cli_enqueue_change(vty,
1266 "./global/instance-type-view",
ff8a8a7a
CS
1267 NB_OP_MODIFY, "true");
1268 }
1269
a5ab756f 1270 nb_cli_pending_commit_check(vty);
ff8a8a7a
CS
1271 ret = nb_cli_apply_changes(vty, base_xpath);
1272 if (ret == CMD_SUCCESS) {
1273 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1274
1275 /*
1276 * For backward compatibility with old commands we still
1277 * need to use the qobj infrastructure.
1278 */
1279 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1280 }
1281 return ret;
d62a17ae 1282 }
1283
1284 // "router bgp X"
1285 else {
d62a17ae 1286
ff8a8a7a 1287 as = strtoul(argv[idx_asn]->arg, NULL, 10);
d62a17ae 1288 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1289 if (argc > 3) {
1290 name = argv[idx_vrf]->arg;
1291
9a8bdf1c
PG
1292 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1293 if (strmatch(name, VRF_DEFAULT_NAME))
1294 name = NULL;
1295 else
1296 inst_type = BGP_INSTANCE_TYPE_VRF;
ff8a8a7a 1297 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
d62a17ae 1298 inst_type = BGP_INSTANCE_TYPE_VIEW;
ff8a8a7a 1299 }
d62a17ae 1300 }
ff8a8a7a
CS
1301 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1302 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1303
1304 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
87ce2564 1305 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
ff8a8a7a
CS
1306 argv[idx_asn]->arg);
1307 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1308 nb_cli_enqueue_change(vty,
1309 "./global/instance-type-view",
ff8a8a7a 1310 NB_OP_MODIFY, "true");
d62a17ae 1311 }
1312
ff8a8a7a
CS
1313 nb_cli_pending_commit_check(vty);
1314 ret = nb_cli_apply_changes(vty, base_xpath);
1315 if (ret == CMD_SUCCESS) {
1316 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
3bd70bf8 1317
ff8a8a7a
CS
1318 /*
1319 * For backward compatibility with old commands we still
1320 * need to use the qobj infrastructure.
1321 */
1322 bgp = bgp_lookup(as, name);
1323 if (bgp)
1324 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1325 }
d62a17ae 1326 }
1327
ff8a8a7a 1328 return ret;
718e3744 1329}
1330
718e3744 1331/* "no router bgp" commands. */
ff8a8a7a
CS
1332DEFUN_YANG(no_router_bgp,
1333 no_router_bgp_cmd,
1334 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1335 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1336{
d62a17ae 1337 int idx_asn = 3;
1338 int idx_vrf = 5;
ff8a8a7a 1339 as_t as = 0;
d62a17ae 1340 struct bgp *bgp;
1341 const char *name = NULL;
ff8a8a7a 1342 char base_xpath[XPATH_MAXLEN];
4b63e358 1343 const struct lyd_node *bgp_glb_dnode;
718e3744 1344
d62a17ae 1345 // "no router bgp" without an ASN
1346 if (argc == 3) {
1347 // Pending: Make VRF option available for ASN less config
4b63e358
CS
1348 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1349 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
718e3744 1350
4b63e358
CS
1351 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1352 base_xpath);
1353 if (!bgp_glb_dnode) {
d62a17ae 1354 vty_out(vty, "%% No BGP process is configured\n");
1355 return CMD_WARNING_CONFIG_FAILED;
1356 }
7fb21a9f 1357
d62a17ae 1358 if (listcount(bm->bgp) > 1) {
996c9314 1359 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1360 return CMD_WARNING_CONFIG_FAILED;
1361 }
0b5131c9 1362
4b63e358
CS
1363 /* tcli mode bgp would not be set until apply stage. */
1364 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1365 if (!bgp)
1366 return CMD_SUCCESS;
1367
0b5131c9
MK
1368 if (bgp->l3vni) {
1369 vty_out(vty, "%% Please unconfigure l3vni %u",
1370 bgp->l3vni);
1371 return CMD_WARNING_CONFIG_FAILED;
1372 }
d62a17ae 1373 } else {
1374 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1375
d62a17ae 1376 if (argc > 4)
1377 name = argv[idx_vrf]->arg;
7fb21a9f 1378
d62a17ae 1379 /* Lookup bgp structure. */
1380 bgp = bgp_lookup(as, name);
1381 if (!bgp) {
1382 vty_out(vty, "%% Can't find BGP instance\n");
1383 return CMD_WARNING_CONFIG_FAILED;
1384 }
0b5131c9
MK
1385
1386 if (bgp->l3vni) {
dd5868c2 1387 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1388 bgp->l3vni);
1389 return CMD_WARNING_CONFIG_FAILED;
1390 }
dd5868c2
DS
1391
1392 /* Cannot delete default instance if vrf instances exist */
1393 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1394 struct listnode *node;
1395 struct bgp *tmp_bgp;
1396
1397 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1398 if (tmp_bgp->inst_type
1399 == BGP_INSTANCE_TYPE_VRF) {
1400 vty_out(vty,
1401 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1402 return CMD_WARNING_CONFIG_FAILED;
1403 }
1404 }
1405 }
d62a17ae 1406 }
ff8a8a7a
CS
1407 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1408 "frr-bgp:bgp", "bgp",
1409 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
718e3744 1410
ff8a8a7a 1411 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
718e3744 1412
ff8a8a7a 1413 return nb_cli_apply_changes(vty, base_xpath);
718e3744 1414}
1415
ff8a8a7a
CS
1416void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1417 bool show_defaults)
1418{
1419 const struct lyd_node *vrf_dnode;
1420 const char *vrf_name;
1421 as_t as;
6b0655a2 1422
ff8a8a7a
CS
1423 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1424 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
5e42cb2f 1425 as = yang_dnode_get_uint32(dnode, "./global/local-as");
718e3744 1426
ff8a8a7a
CS
1427 vty_out(vty, "!\n");
1428 vty_out(vty, "router bgp %u", as);
1429 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1430 vty_out(vty, " vrf %s", vrf_name);
1431 vty_out(vty, "\n");
718e3744 1432}
1433
ff8a8a7a
CS
1434/* BGP router-id. */
1435
1436DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1437 BGP_STR
1438 "Override configured router identifier\n"
1439 "Manually configured router identifier\n")
718e3744 1440{
87ce2564
CS
1441 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1442 router_id_str);
718e3744 1443
ff8a8a7a
CS
1444 return nb_cli_apply_changes(vty, NULL);
1445}
718e3744 1446
ff8a8a7a
CS
1447DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1448 NO_STR BGP_STR
1449 "Override configured router identifier\n"
1450 "Manually configured router identifier\n")
1451{
87ce2564 1452 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
ff8a8a7a 1453 router_id_str ? router_id_str : NULL);
718e3744 1454
ff8a8a7a 1455 return nb_cli_apply_changes(vty, NULL);
718e3744 1456}
1457
ff8a8a7a
CS
1458void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1459 bool show_defaults)
1460{
1461 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1462}
6b0655a2 1463
718e3744 1464/* BGP Cluster ID. */
ff8a8a7a
CS
1465DEFUN_YANG(bgp_cluster_id,
1466 bgp_cluster_id_cmd,
1467 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1468 BGP_STR
1469 "Configure Route-Reflector Cluster-id\n"
1470 "Route-Reflector Cluster-id in IP address format\n"
1471 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1472{
d62a17ae 1473 int idx_ipv4 = 2;
718e3744 1474
87ce2564
CS
1475 nb_cli_enqueue_change(
1476 vty, "./global/route-reflector/route-reflector-cluster-id",
1477 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1478
ff8a8a7a 1479 return nb_cli_apply_changes(vty, NULL);
718e3744 1480}
1481
ff8a8a7a
CS
1482DEFUN_YANG(no_bgp_cluster_id,
1483 no_bgp_cluster_id_cmd,
1484 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1485 NO_STR BGP_STR
1486 "Configure Route-Reflector Cluster-id\n"
1487 "Route-Reflector Cluster-id in IP address format\n"
1488 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1489{
87ce2564
CS
1490 nb_cli_enqueue_change(
1491 vty, "./global/route-reflector/route-reflector-cluster-id",
1492 NB_OP_DESTROY, NULL);
718e3744 1493
ff8a8a7a 1494 return nb_cli_apply_changes(vty, NULL);
718e3744 1495}
1496
c163f297
DS
1497DEFPY (bgp_norib,
1498 bgp_norib_cmd,
1499 "bgp no-rib",
1500 BGP_STR
1501 "Disable BGP route installation to RIB (Zebra)\n")
1502{
1503 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1504 vty_out(vty,
1505 "%% No-RIB option is already set, nothing to do here.\n");
1506 return CMD_SUCCESS;
1507 }
1508
1509 bgp_option_norib_set_runtime();
1510
1511 return CMD_SUCCESS;
1512}
1513
1514DEFPY (no_bgp_norib,
1515 no_bgp_norib_cmd,
1516 "no bgp no-rib",
1517 NO_STR
1518 BGP_STR
1519 "Disable BGP route installation to RIB (Zebra)\n")
1520{
1521 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1522 vty_out(vty,
1523 "%% No-RIB option is not set, nothing to do here.\n");
1524 return CMD_SUCCESS;
1525 }
1526
1527 bgp_option_norib_unset_runtime();
1528
1529 return CMD_SUCCESS;
1530}
1531
ff8a8a7a
CS
1532DEFUN_YANG(bgp_confederation_identifier,
1533 bgp_confederation_identifier_cmd,
1534 "bgp confederation identifier (1-4294967295)",
1535 "BGP specific commands\n"
1536 "AS confederation parameters\n"
1537 "AS number\n"
1538 "Set routing domain confederation AS\n")
718e3744 1539{
d62a17ae 1540 int idx_number = 3;
718e3744 1541
87ce2564
CS
1542 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1543 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1544
ff8a8a7a 1545 return nb_cli_apply_changes(vty, NULL);
718e3744 1546}
1547
ff8a8a7a
CS
1548DEFUN_YANG(no_bgp_confederation_identifier,
1549 no_bgp_confederation_identifier_cmd,
1550 "no bgp confederation identifier [(1-4294967295)]",
1551 NO_STR
1552 "BGP specific commands\n"
1553 "AS confederation parameters\n"
1554 "AS number\n"
1555 "Set routing domain confederation AS\n")
718e3744 1556{
87ce2564
CS
1557 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1558 NB_OP_DESTROY, NULL);
718e3744 1559
ff8a8a7a 1560 return nb_cli_apply_changes(vty, NULL);
718e3744 1561}
1562
ff8a8a7a
CS
1563void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1564 struct lyd_node *dnode,
1565 bool show_defaults)
1566{
1567 vty_out(vty, " bgp confederation identifier %u\n",
1568 yang_dnode_get_uint32(dnode, NULL));
1569}
1570
1571DEFUN_YANG(bgp_confederation_peers,
1572 bgp_confederation_peers_cmd,
1573 "bgp confederation peers (1-4294967295)...",
1574 "BGP specific commands\n"
1575 "AS confederation parameters\n"
1576 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1577{
d62a17ae 1578 int idx_asn = 3;
d62a17ae 1579 int i;
718e3744 1580
ff8a8a7a 1581 for (i = idx_asn; i < argc; i++)
87ce2564 1582 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1583 NB_OP_CREATE, argv[i]->arg);
718e3744 1584
ff8a8a7a 1585 return nb_cli_apply_changes(vty, NULL);
718e3744 1586}
1587
ff8a8a7a
CS
1588DEFUN_YANG(no_bgp_confederation_peers,
1589 no_bgp_confederation_peers_cmd,
1590 "no bgp confederation peers (1-4294967295)...",
1591 NO_STR
1592 "BGP specific commands\n"
1593 "AS confederation parameters\n"
1594 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1595{
d62a17ae 1596 int idx_asn = 4;
d62a17ae 1597 int i;
718e3744 1598
ff8a8a7a 1599 for (i = idx_asn; i < argc; i++)
87ce2564 1600 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1601 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1602
ff8a8a7a
CS
1603 return nb_cli_apply_changes(vty, NULL);
1604}
1605
1606void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1607 struct lyd_node *dnode,
1608 bool show_defaults)
1609{
1610 vty_out(vty, " bgp confederation peers %u \n",
1611 yang_dnode_get_uint32(dnode, NULL));
718e3744 1612}
6b0655a2 1613
5e242b0d
DS
1614/**
1615 * Central routine for maximum-paths configuration.
1616 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1617 * @set: 1 for setting values, 0 for removing the max-paths config.
1618 */
37a87b8f
CS
1619int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1620 int peer_type, uint16_t maxpaths, uint16_t options,
1621 int set, char *errmsg, size_t errmsg_len)
d62a17ae 1622{
d62a17ae 1623 int ret;
d62a17ae 1624
1625 if (set) {
d62a17ae 1626 if (maxpaths > multipath_num) {
37a87b8f
CS
1627 snprintf(
1628 errmsg, errmsg_len,
d62a17ae 1629 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1630 maxpaths, multipath_num);
1631 return CMD_WARNING_CONFIG_FAILED;
1632 }
1633 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1634 options);
1635 } else
1636 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1637
1638 if (ret < 0) {
37a87b8f
CS
1639 snprintf(
1640 errmsg, errmsg_len,
d62a17ae 1641 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1642 (set == 1) ? "" : "un",
1643 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1644 maxpaths, afi, safi);
1645 return CMD_WARNING_CONFIG_FAILED;
1646 }
1647
1648 bgp_recalculate_all_bestpaths(bgp);
1649
1650 return CMD_SUCCESS;
165b5fff
JB
1651}
1652
ff8a8a7a
CS
1653void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1654 bool show_defaults)
abc920f8 1655{
ff8a8a7a
CS
1656 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1657 uint32_t med_admin_val;
abc920f8 1658
ff8a8a7a
CS
1659 vty_out(vty, " bgp max-med administrative");
1660 if ((med_admin_val =
1661 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1662 != BGP_MAXMED_VALUE_DEFAULT)
1663 vty_out(vty, " %u", med_admin_val);
1664 vty_out(vty, "\n");
1665 }
abc920f8 1666
ff8a8a7a
CS
1667 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1668 uint32_t onstartup_val;
abc920f8 1669
ff8a8a7a
CS
1670 vty_out(vty, " bgp max-med on-startup %u",
1671 yang_dnode_get_uint32(dnode,
1672 "./max-med-onstart-up-time"));
1673 onstartup_val = yang_dnode_get_uint32(
1674 dnode, "./max-med-onstart-up-value");
1675 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1676 vty_out(vty, " %u", onstartup_val);
1677
1678 vty_out(vty, "\n");
1679 }
abc920f8
DS
1680}
1681
ff8a8a7a
CS
1682DEFUN_YANG(bgp_maxmed_admin,
1683 bgp_maxmed_admin_cmd,
1684 "bgp max-med administrative ",
1685 BGP_STR
1686 "Advertise routes with max-med\n"
1687 "Administratively applied, for an indefinite period\n")
1688{
87ce2564 1689 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1690 NB_OP_MODIFY, "true");
1691
1692 return nb_cli_apply_changes(vty, NULL);
1693}
1694
1695DEFUN_YANG(bgp_maxmed_admin_medv,
1696 bgp_maxmed_admin_medv_cmd,
1697 "bgp max-med administrative (0-4294967295)",
1698 BGP_STR
1699 "Advertise routes with max-med\n"
1700 "Administratively applied, for an indefinite period\n"
1701 "Max MED value to be used\n")
abc920f8 1702{
d62a17ae 1703 int idx_number = 3;
abc920f8 1704
87ce2564 1705 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1706 NB_OP_MODIFY, "true");
abc920f8 1707
87ce2564
CS
1708 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1709 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1710
ff8a8a7a 1711 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1712}
1713
ff8a8a7a
CS
1714DEFUN_YANG(no_bgp_maxmed_admin,
1715 no_bgp_maxmed_admin_cmd,
1716 "no bgp max-med administrative [(0-4294967295)]",
1717 NO_STR BGP_STR
1718 "Advertise routes with max-med\n"
1719 "Administratively applied, for an indefinite period\n"
1720 "Max MED value to be used\n")
abc920f8 1721{
87ce2564 1722 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1723 NB_OP_MODIFY, "false");
abc920f8 1724
87ce2564
CS
1725 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1726 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1727
1728 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1729}
1730
37a87b8f
CS
1731DEFUN_YANG (bgp_maxmed_onstartup,
1732 bgp_maxmed_onstartup_cmd,
1733 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1734 BGP_STR
1735 "Advertise routes with max-med\n"
1736 "Effective on a startup\n"
1737 "Time (seconds) period for max-med\n"
1738 "Max MED value to be used\n")
abc920f8 1739{
d62a17ae 1740 int idx = 0;
4668a151 1741
d62a17ae 1742 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1743 nb_cli_enqueue_change(vty,
1744 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1745 NB_OP_MODIFY, argv[idx]->arg);
1746
d62a17ae 1747 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1748 nb_cli_enqueue_change(
1749 vty, "./global/med-config/max-med-onstart-up-value",
1750 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1751 else
87ce2564
CS
1752 nb_cli_enqueue_change(
1753 vty, "./global/med-config/max-med-onstart-up-value",
1754 NB_OP_MODIFY, NULL);
abc920f8 1755
ff8a8a7a 1756 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1757}
1758
37a87b8f
CS
1759DEFUN_YANG (no_bgp_maxmed_onstartup,
1760 no_bgp_maxmed_onstartup_cmd,
1761 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1762 NO_STR BGP_STR
1763 "Advertise routes with max-med\n"
1764 "Effective on a startup\n"
1765 "Time (seconds) period for max-med\n"
1766 "Max MED value to be used\n")
abc920f8 1767{
87ce2564
CS
1768 nb_cli_enqueue_change(vty,
1769 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1770 NB_OP_DESTROY, NULL);
abc920f8 1771
87ce2564
CS
1772 nb_cli_enqueue_change(vty,
1773 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1774 NB_OP_MODIFY, NULL);
abc920f8 1775
ff8a8a7a 1776 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1777}
1778
d70583f7
D
1779static int bgp_global_update_delay_config_vty(struct vty *vty,
1780 uint16_t update_delay,
1781 uint16_t establish_wait)
1782{
1783 struct listnode *node, *nnode;
1784 struct bgp *bgp;
1785 bool vrf_cfg = false;
1786
1787 /*
1788 * See if update-delay is set per-vrf and warn user to delete it
1789 * Note that we only need to check this if this is the first time
1790 * setting the global config.
1791 */
1792 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1793 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1794 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1795 vty_out(vty,
1796 "%% update-delay configuration found in vrf %s\n",
1797 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1798 ? VRF_DEFAULT_NAME
1799 : bgp->name);
1800 vrf_cfg = true;
1801 }
1802 }
1803 }
1804
1805 if (vrf_cfg) {
1806 vty_out(vty,
1807 "%%Failed: global update-delay config not permitted\n");
1808 return CMD_WARNING;
1809 }
1810
1811 if (!establish_wait) { /* update-delay <delay> */
1812 bm->v_update_delay = update_delay;
1813 bm->v_establish_wait = bm->v_update_delay;
1814 } else {
1815 /* update-delay <delay> <establish-wait> */
1816 if (update_delay < establish_wait) {
1817 vty_out(vty,
1818 "%%Failed: update-delay less than the establish-wait!\n");
1819 return CMD_WARNING_CONFIG_FAILED;
1820 }
1821
1822 bm->v_update_delay = update_delay;
1823 bm->v_establish_wait = establish_wait;
1824 }
1825
1826 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1827 bgp->v_update_delay = bm->v_update_delay;
1828 bgp->v_establish_wait = bm->v_establish_wait;
1829 }
1830
1831 return CMD_SUCCESS;
1832}
1833
1834static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1835{
1836 struct listnode *node, *nnode;
1837 struct bgp *bgp;
1838
1839 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1840 bm->v_establish_wait = bm->v_update_delay;
1841
1842 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1843 bgp->v_update_delay = bm->v_update_delay;
1844 bgp->v_establish_wait = bm->v_establish_wait;
1845 }
1846
1847 return CMD_SUCCESS;
1848}
1849
1850static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1851 uint16_t establish_wait)
f188f2c4 1852{
d62a17ae 1853 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1854
d70583f7
D
1855 /* if configured globally, per-instance config is not allowed */
1856 if (bm->v_update_delay) {
1857 vty_out(vty,
1858 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1859 return CMD_WARNING_CONFIG_FAILED;
1860 }
1861
f188f2c4 1862
d70583f7 1863 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1864 {
1865 bgp->v_update_delay = update_delay;
1866 bgp->v_establish_wait = bgp->v_update_delay;
1867 return CMD_SUCCESS;
1868 }
f188f2c4 1869
d62a17ae 1870 /* update-delay <delay> <establish-wait> */
d62a17ae 1871 if (update_delay < establish_wait) {
1872 vty_out(vty,
1873 "%%Failed: update-delay less than the establish-wait!\n");
1874 return CMD_WARNING_CONFIG_FAILED;
1875 }
f188f2c4 1876
d62a17ae 1877 bgp->v_update_delay = update_delay;
1878 bgp->v_establish_wait = establish_wait;
f188f2c4 1879
d62a17ae 1880 return CMD_SUCCESS;
f188f2c4
DS
1881}
1882
d62a17ae 1883static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1884{
d62a17ae 1885 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1886
d70583f7
D
1887 /* If configured globally, cannot remove from one bgp instance */
1888 if (bm->v_update_delay) {
1889 vty_out(vty,
1890 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
1891 return CMD_WARNING_CONFIG_FAILED;
1892 }
d62a17ae 1893 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1894 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1895
d62a17ae 1896 return CMD_SUCCESS;
f188f2c4
DS
1897}
1898
2b791107 1899void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1900{
d70583f7
D
1901 /* If configured globally, no need to display per-instance value */
1902 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 1903 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1904 if (bgp->v_update_delay != bgp->v_establish_wait)
1905 vty_out(vty, " %d", bgp->v_establish_wait);
1906 vty_out(vty, "\n");
1907 }
f188f2c4
DS
1908}
1909
d70583f7
D
1910/* Global update-delay configuration */
1911DEFPY (bgp_global_update_delay,
1912 bgp_global_update_delay_cmd,
1913 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
1914 BGP_STR
1915 "Force initial delay for best-path and updates for all bgp instances\n"
1916 "Max delay in seconds\n"
1917 "Establish wait in seconds\n")
1918{
1919 return bgp_global_update_delay_config_vty(vty, delay, wait);
1920}
f188f2c4 1921
d70583f7
D
1922/* Global update-delay deconfiguration */
1923DEFPY (no_bgp_global_update_delay,
1924 no_bgp_global_update_delay_cmd,
1925 "no bgp update-delay [(0-3600) [(1-3600)]]",
1926 NO_STR
1927 BGP_STR
f188f2c4 1928 "Force initial delay for best-path and updates\n"
d70583f7
D
1929 "Max delay in seconds\n"
1930 "Establish wait in seconds\n")
f188f2c4 1931{
d70583f7 1932 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
1933}
1934
d70583f7
D
1935/* Update-delay configuration */
1936
1937DEFPY (bgp_update_delay,
1938 bgp_update_delay_cmd,
1939 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 1940 "Force initial delay for best-path and updates\n"
d70583f7
D
1941 "Max delay in seconds\n"
1942 "Establish wait in seconds\n")
f188f2c4 1943{
d70583f7 1944 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
1945}
1946
1947/* Update-delay deconfiguration */
d70583f7 1948DEFPY (no_bgp_update_delay,
f188f2c4 1949 no_bgp_update_delay_cmd,
838758ac
DW
1950 "no update-delay [(0-3600) [(1-3600)]]",
1951 NO_STR
f188f2c4 1952 "Force initial delay for best-path and updates\n"
d70583f7
D
1953 "Max delay in seconds\n"
1954 "Establish wait in seconds\n")
f188f2c4 1955{
d62a17ae 1956 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1957}
1958
5e242b0d 1959
ff8a8a7a 1960int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 1961{
8fa7732f
QY
1962 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1963 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
1964
1965 return CMD_SUCCESS;
1966}
1967
ff8a8a7a 1968int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 1969{
8fa7732f
QY
1970 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1971 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 1972
d62a17ae 1973 return CMD_SUCCESS;
cb1faec9
DS
1974}
1975
2b791107 1976void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1977{
555e09d4
QY
1978 uint32_t quanta =
1979 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1980 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1981 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1982}
1983
555e09d4
QY
1984void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1985{
1986 uint32_t quanta =
1987 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1988 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1989 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1990}
cb1faec9 1991
8fa7732f
QY
1992/* Packet quanta configuration
1993 *
1994 * XXX: The value set here controls the size of a stack buffer in the IO
1995 * thread. When changing these limits be careful to prevent stack overflow.
1996 *
1997 * Furthermore, the maximums used here should correspond to
1998 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1999 */
37a87b8f
CS
2000DEFPY_YANG (bgp_wpkt_quanta,
2001 bgp_wpkt_quanta_cmd,
2002 "[no] write-quanta (1-64)$quanta",
2003 NO_STR
2004 "How many packets to write to peer socket per run\n"
2005 "Number of packets\n")
ff8a8a7a
CS
2006{
2007 if (!no)
2008 nb_cli_enqueue_change(
2009 vty,
87ce2564 2010 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2011 NB_OP_MODIFY, quanta_str);
2012 else
2013 nb_cli_enqueue_change(
2014 vty,
87ce2564 2015 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2016 NB_OP_MODIFY, NULL);
2017
2018 return nb_cli_apply_changes(vty, NULL);
2019}
2020
37a87b8f
CS
2021DEFPY_YANG (bgp_rpkt_quanta,
2022 bgp_rpkt_quanta_cmd,
2023 "[no] read-quanta (1-10)$quanta",
2024 NO_STR
2025 "How many packets to read from peer socket per I/O cycle\n"
2026 "Number of packets\n")
ff8a8a7a
CS
2027{
2028 if (!no)
2029 nb_cli_enqueue_change(
2030 vty,
87ce2564 2031 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2032 NB_OP_MODIFY, quanta_str);
2033 else
2034 nb_cli_enqueue_change(
2035 vty,
87ce2564 2036 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2037 NB_OP_MODIFY, NULL);
cb1faec9 2038
ff8a8a7a 2039 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2040}
2041
2b791107 2042void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2043{
37a333fe 2044 if (!bgp->heuristic_coalesce)
d62a17ae 2045 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2046}
2047
ff8a8a7a
CS
2048void cli_show_router_global_update_group_config_coalesce_time(
2049 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2050{
ff8a8a7a
CS
2051 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2052}
2053
4668a151 2054
37a87b8f
CS
2055DEFUN_YANG (bgp_coalesce_time,
2056 bgp_coalesce_time_cmd,
2057 "coalesce-time (0-4294967295)",
2058 "Subgroup coalesce timer\n"
2059 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2060{
d62a17ae 2061 int idx = 0;
ff8a8a7a 2062
d62a17ae 2063 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2064 nb_cli_enqueue_change(
2065 vty, "./global/global-update-group-config/coalesce-time",
2066 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2067
2068 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2069}
2070
ff8a8a7a
CS
2071DEFUN_YANG(no_bgp_coalesce_time,
2072 no_bgp_coalesce_time_cmd,
2073 "no coalesce-time (0-4294967295)",
2074 NO_STR
2075 "Subgroup coalesce timer\n"
2076 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2077{
87ce2564
CS
2078 nb_cli_enqueue_change(
2079 vty, "./global/global-update-group-config/coalesce-time",
2080 NB_OP_MODIFY, NULL);
4668a151 2081
ff8a8a7a 2082 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2083}
2084
5e242b0d 2085/* Maximum-paths configuration */
37a87b8f
CS
2086DEFUN_YANG (bgp_maxpaths,
2087 bgp_maxpaths_cmd,
2088 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2089 "Forward packets over multiple paths\n"
2090 "Number of paths\n")
5e242b0d 2091{
d62a17ae 2092 int idx_number = 1;
37a87b8f
CS
2093 char base_xpath[XPATH_MAXLEN];
2094 afi_t afi;
2095 safi_t safi;
2096
2097 afi = bgp_node_afi(vty);
2098 safi = bgp_node_safi(vty);
2099
2100 snprintf(
2101 base_xpath, sizeof(base_xpath),
2102 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2103 yang_afi_safi_value2identity(afi, safi),
2104 bgp_afi_safi_get_container_str(afi, safi));
2105
2106 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2107 argv[idx_number]->arg);
2108
2109 return nb_cli_apply_changes(vty, NULL);
2110}
2111
2112void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2113 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2114{
2115 vty_out(vty, " maximum-paths %d\n",
2116 yang_dnode_get_uint16(dnode, NULL));
5e242b0d
DS
2117}
2118
d62a17ae 2119ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2120 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2121 "Forward packets over multiple paths\n"
2122 "Number of paths\n")
596c17ba 2123
37a87b8f
CS
2124DEFUN_YANG (bgp_maxpaths_ibgp,
2125 bgp_maxpaths_ibgp_cmd,
2126 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2127 "Forward packets over multiple paths\n"
2128 "iBGP-multipath\n"
2129 "Number of paths\n")
165b5fff 2130{
d62a17ae 2131 int idx_number = 2;
37a87b8f
CS
2132 char base_xpath[XPATH_MAXLEN];
2133 afi_t afi;
2134 safi_t safi;
2135
2136 afi = bgp_node_afi(vty);
2137 safi = bgp_node_safi(vty);
2138
2139 snprintf(
2140 base_xpath, sizeof(base_xpath),
2141 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2142 yang_afi_safi_value2identity(afi, safi),
2143 bgp_afi_safi_get_container_str(afi, safi));
2144
2145 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2146 argv[idx_number]->arg);
2147
2148 return nb_cli_apply_changes(vty, NULL);
5e242b0d 2149}
165b5fff 2150
d62a17ae 2151ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2152 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2153 "Forward packets over multiple paths\n"
2154 "iBGP-multipath\n"
2155 "Number of paths\n")
596c17ba 2156
37a87b8f
CS
2157DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2158 bgp_maxpaths_ibgp_cluster_cmd,
2159 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2160 "Forward packets over multiple paths\n"
2161 "iBGP-multipath\n"
2162 "Number of paths\n"
2163 "Match the cluster length\n")
5e242b0d 2164{
d62a17ae 2165 int idx_number = 2;
37a87b8f
CS
2166 char base_xpath[XPATH_MAXLEN];
2167 afi_t afi;
2168 safi_t safi;
2169
2170 afi = bgp_node_afi(vty);
2171 safi = bgp_node_safi(vty);
2172
2173 snprintf(
2174 base_xpath, sizeof(base_xpath),
2175 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2176 yang_afi_safi_value2identity(afi, safi),
2177 bgp_afi_safi_get_container_str(afi, safi));
2178
2179 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2180 argv[idx_number]->arg);
2181
2182 snprintf(
2183 base_xpath, sizeof(base_xpath),
2184 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2185 yang_afi_safi_value2identity(afi, safi),
2186 bgp_afi_safi_get_container_str(afi, safi));
2187
2188 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2189
2190 return nb_cli_apply_changes(vty, NULL);
2191}
2192
2193void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2194 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2195{
2196 vty_out(vty, " maximum-paths ibgp %d",
2197 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2198 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2199 vty_out(vty, " equal-cluster-length");
2200 vty_out(vty, "\n");
165b5fff
JB
2201}
2202
d62a17ae 2203ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2204 "maximum-paths ibgp " CMD_RANGE_STR(
2205 1, MULTIPATH_NUM) " equal-cluster-length",
2206 "Forward packets over multiple paths\n"
2207 "iBGP-multipath\n"
2208 "Number of paths\n"
2209 "Match the cluster length\n")
596c17ba 2210
37a87b8f
CS
2211DEFUN_YANG (no_bgp_maxpaths,
2212 no_bgp_maxpaths_cmd,
2213 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2214 NO_STR
2215 "Forward packets over multiple paths\n"
2216 "Number of paths\n")
165b5fff 2217{
37a87b8f
CS
2218 char base_xpath[XPATH_MAXLEN];
2219 afi_t afi;
2220 safi_t safi;
2221
2222 afi = bgp_node_afi(vty);
2223 safi = bgp_node_safi(vty);
2224
2225 snprintf(
2226 base_xpath, sizeof(base_xpath),
2227 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2228 yang_afi_safi_value2identity(afi, safi),
2229 bgp_afi_safi_get_container_str(afi, safi));
2230
2231 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2232
2233 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2234}
2235
d62a17ae 2236ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2237 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2238 "Forward packets over multiple paths\n"
2239 "Number of paths\n")
596c17ba 2240
37a87b8f
CS
2241DEFUN_YANG (no_bgp_maxpaths_ibgp,
2242 no_bgp_maxpaths_ibgp_cmd,
2243 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2244 NO_STR
2245 "Forward packets over multiple paths\n"
2246 "iBGP-multipath\n"
2247 "Number of paths\n"
2248 "Match the cluster length\n")
165b5fff 2249{
37a87b8f
CS
2250 char base_xpath[XPATH_MAXLEN];
2251 afi_t afi;
2252 safi_t safi;
2253
2254 afi = bgp_node_afi(vty);
2255 safi = bgp_node_safi(vty);
2256
2257 snprintf(
2258 base_xpath, sizeof(base_xpath),
2259 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2260 yang_afi_safi_value2identity(afi, safi),
2261 bgp_afi_safi_get_container_str(afi, safi));
2262
2263 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2264
2265 snprintf(
2266 base_xpath, sizeof(base_xpath),
2267 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2268 yang_afi_safi_value2identity(afi, safi),
2269 bgp_afi_safi_get_container_str(afi, safi));
2270
2271 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2272
2273 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2274}
2275
d62a17ae 2276ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2277 "no maximum-paths ibgp [" CMD_RANGE_STR(
2278 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2279 NO_STR
2280 "Forward packets over multiple paths\n"
2281 "iBGP-multipath\n"
2282 "Number of paths\n"
2283 "Match the cluster length\n")
596c17ba 2284
dd65f45e
DL
2285static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2286 afi_t afi, safi_t safi)
165b5fff 2287{
d62a17ae 2288 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 2289 vty_out(vty, " maximum-paths %d\n",
2290 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2291 }
165b5fff 2292
d62a17ae 2293 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 2294 vty_out(vty, " maximum-paths ibgp %d",
2295 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2296 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2297 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2298 vty_out(vty, " equal-cluster-length");
2299 vty_out(vty, "\n");
2300 }
165b5fff 2301}
6b0655a2 2302
718e3744 2303/* BGP timers. */
2304
37a87b8f
CS
2305DEFUN_YANG (bgp_timers,
2306 bgp_timers_cmd,
2307 "timers bgp (0-65535) (0-65535)",
2308 "Adjust routing timers\n"
2309 "BGP timers\n"
2310 "Keepalive interval\n"
2311 "Holdtime\n")
718e3744 2312{
d62a17ae 2313 int idx_number = 2;
2314 int idx_number_2 = 3;
718e3744 2315
87ce2564 2316 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2317 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2318 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2319 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2320
ff8a8a7a
CS
2321 return nb_cli_apply_changes(vty, NULL);
2322}
718e3744 2323
37a87b8f
CS
2324DEFUN_YANG (no_bgp_timers,
2325 no_bgp_timers_cmd,
2326 "no timers bgp [(0-65535) (0-65535)]",
2327 NO_STR
2328 "Adjust routing timers\n"
2329 "BGP timers\n"
2330 "Keepalive interval\n"
2331 "Holdtime\n")
ff8a8a7a 2332{
87ce2564 2333 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2334 NB_OP_DESTROY, NULL);
87ce2564 2335 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2336 NB_OP_DESTROY, NULL);
718e3744 2337
ff8a8a7a 2338 return nb_cli_apply_changes(vty, NULL);
718e3744 2339}
2340
ff8a8a7a
CS
2341void cli_show_router_bgp_route_reflector(struct vty *vty,
2342 struct lyd_node *dnode,
2343 bool show_defaults)
718e3744 2344{
ff8a8a7a
CS
2345 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2346 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2347
ff8a8a7a
CS
2348 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2349 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2350
2351 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2352 vty_out(vty, " bgp cluster-id %s\n",
2353 yang_dnode_get_string(dnode,
2354 "./route-reflector-cluster-id"));
718e3744 2355}
2356
ff8a8a7a
CS
2357DEFUN_YANG(bgp_client_to_client_reflection,
2358 bgp_client_to_client_reflection_cmd,
2359 "bgp client-to-client reflection",
2360 "BGP specific commands\n"
2361 "Configure client to client route reflection\n"
2362 "reflection of routes allowed\n")
2363{
87ce2564 2364 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2365 NB_OP_MODIFY, "false");
6b0655a2 2366
ff8a8a7a
CS
2367 return nb_cli_apply_changes(vty, NULL);
2368}
2369
2370DEFUN_YANG(no_bgp_client_to_client_reflection,
2371 no_bgp_client_to_client_reflection_cmd,
2372 "no bgp client-to-client reflection",
2373 NO_STR
2374 "BGP specific commands\n"
2375 "Configure client to client route reflection\n"
2376 "reflection of routes allowed\n")
718e3744 2377{
87ce2564 2378 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2379 NB_OP_MODIFY, "true");
7aafcaca 2380
ff8a8a7a 2381 return nb_cli_apply_changes(vty, NULL);
718e3744 2382}
2383
ff8a8a7a
CS
2384void cli_show_router_bgp_route_selection(struct vty *vty,
2385 struct lyd_node *dnode,
2386 bool show_defaults)
718e3744 2387{
7aafcaca 2388
ff8a8a7a
CS
2389 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2390 vty_out(vty, " bgp always-compare-med\n");
2391
2392 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2393 vty_out(vty, " bgp bestpath as-path ignore\n");
2394
2395 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2396 vty_out(vty, " bgp bestpath as-path confed\n");
2397
2398 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2399 vty_out(vty, " bgp bestpath compare-routerid\n");
2400
2401 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2402 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2403 vty_out(vty,
2404 " bgp bestpath as-path multipath-relax as-set\n");
2405 else
2406 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2407 }
2408
2409 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2410 vty_out(vty, " bgp deterministic-med\n");
2411
2412 if (yang_dnode_get_bool(dnode, "./confed-med")
2413 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2414 vty_out(vty, " bgp bestpath med");
2415 if (yang_dnode_get_bool(dnode, "./confed-med"))
2416 vty_out(vty, " confed");
2417 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2418 vty_out(vty, " missing-as-worst");
2419 vty_out(vty, "\n");
2420 }
718e3744 2421}
2422
2423/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2424DEFUN_YANG(bgp_always_compare_med,
2425 bgp_always_compare_med_cmd,
2426 "bgp always-compare-med",
2427 "BGP specific commands\n"
2428 "Allow comparing MED from different neighbors\n")
718e3744 2429{
87ce2564
CS
2430 nb_cli_enqueue_change(
2431 vty, "./global/route-selection-options/always-compare-med",
2432 NB_OP_MODIFY, "true");
7aafcaca 2433
ff8a8a7a 2434 return nb_cli_apply_changes(vty, NULL);
718e3744 2435}
2436
ff8a8a7a
CS
2437DEFUN_YANG(no_bgp_always_compare_med,
2438 no_bgp_always_compare_med_cmd,
2439 "no bgp always-compare-med",
2440 NO_STR
2441 "BGP specific commands\n"
2442 "Allow comparing MED from different neighbors\n")
718e3744 2443{
87ce2564
CS
2444 nb_cli_enqueue_change(
2445 vty, "./global/route-selection-options/always-compare-med",
2446 NB_OP_MODIFY, "false");
7aafcaca 2447
ff8a8a7a 2448 return nb_cli_apply_changes(vty, NULL);
718e3744 2449}
6b0655a2 2450
ff8a8a7a
CS
2451DEFUN_YANG(bgp_ebgp_requires_policy,
2452 bgp_ebgp_requires_policy_cmd,
2453 "bgp ebgp-requires-policy",
2454 "BGP specific commands\n"
2455 "Require in and out policy for eBGP peers (RFC8212)\n")
2456{
87ce2564
CS
2457 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2458 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2459 return nb_cli_apply_changes(vty, NULL);
2460}
9dac9fc8 2461
ff8a8a7a
CS
2462DEFUN_YANG(no_bgp_ebgp_requires_policy,
2463 no_bgp_ebgp_requires_policy_cmd,
2464 "no bgp ebgp-requires-policy",
2465 NO_STR
2466 "BGP specific commands\n"
2467 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2468{
87ce2564
CS
2469 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2470 NB_OP_MODIFY, "false");
ff8a8a7a 2471 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2472}
2473
ff8a8a7a
CS
2474void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2475 struct lyd_node *dnode,
2476 bool show_defaults)
9dac9fc8 2477{
ff8a8a7a
CS
2478 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2479 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2480}
2481
fb29348a
DA
2482DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2483 "bgp reject-as-sets",
2484 "BGP specific commands\n"
2485 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2486{
2487 VTY_DECLVAR_CONTEXT(bgp, bgp);
2488 struct listnode *node, *nnode;
2489 struct peer *peer;
2490
7f972cd8 2491 bgp->reject_as_sets = true;
fb29348a
DA
2492
2493 /* Reset existing BGP sessions to reject routes
2494 * with aspath containing AS_SET or AS_CONFED_SET.
2495 */
2496 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2497 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2498 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2499 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2500 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2501 }
2502 }
2503
2504 return CMD_SUCCESS;
2505}
2506
2507DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2508 "no bgp reject-as-sets",
2509 NO_STR
2510 "BGP specific commands\n"
2511 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2512{
2513 VTY_DECLVAR_CONTEXT(bgp, bgp);
2514 struct listnode *node, *nnode;
2515 struct peer *peer;
2516
7f972cd8 2517 bgp->reject_as_sets = false;
fb29348a
DA
2518
2519 /* Reset existing BGP sessions to reject routes
2520 * with aspath containing AS_SET or AS_CONFED_SET.
2521 */
2522 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2523 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2524 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2525 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2526 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2527 }
2528 }
2529
2530 return CMD_SUCCESS;
2531}
9dac9fc8 2532
718e3744 2533/* "bgp deterministic-med" configuration. */
ff8a8a7a 2534DEFUN_YANG (bgp_deterministic_med,
718e3744 2535 bgp_deterministic_med_cmd,
2536 "bgp deterministic-med",
2537 "BGP specific commands\n"
2538 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2539{
87ce2564
CS
2540 nb_cli_enqueue_change(
2541 vty, "./global/route-selection-options/deterministic-med",
2542 NB_OP_MODIFY, "true");
7aafcaca 2543
ff8a8a7a 2544 return nb_cli_apply_changes(vty, NULL);
718e3744 2545}
2546
ff8a8a7a 2547DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2548 no_bgp_deterministic_med_cmd,
2549 "no bgp deterministic-med",
2550 NO_STR
2551 "BGP specific commands\n"
2552 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2553{
87ce2564
CS
2554 nb_cli_enqueue_change(
2555 vty, "./global/route-selection-options/deterministic-med",
2556 NB_OP_MODIFY, "false");
d62a17ae 2557
ff8a8a7a 2558 return nb_cli_apply_changes(vty, NULL);
718e3744 2559}
538621f2 2560
055679e9 2561/* "bgp graceful-restart mode" configuration. */
538621f2 2562DEFUN (bgp_graceful_restart,
2ba1fe69 2563 bgp_graceful_restart_cmd,
2564 "bgp graceful-restart",
2565 "BGP specific commands\n"
2566 GR_CMD
055679e9 2567 )
538621f2 2568{
055679e9 2569 int ret = BGP_GR_FAILURE;
2570
2571 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2572 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2573
d62a17ae 2574 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2575
2576 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2577
36235319
QY
2578 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2579 ret);
5cce3f05 2580
055679e9 2581 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2582 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2583 vty_out(vty,
2584 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2585 return bgp_vty_return(vty, ret);
538621f2 2586}
2587
2588DEFUN (no_bgp_graceful_restart,
2ba1fe69 2589 no_bgp_graceful_restart_cmd,
2590 "no bgp graceful-restart",
2591 NO_STR
2592 "BGP specific commands\n"
2593 NO_GR_CMD
055679e9 2594 )
538621f2 2595{
d62a17ae 2596 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2597
2598 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2599 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2600
2601 int ret = BGP_GR_FAILURE;
2602
2603 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2604
36235319
QY
2605 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2606 ret);
5cce3f05 2607
055679e9 2608 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2609 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2610 vty_out(vty,
2611 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2612
2613 return bgp_vty_return(vty, ret);
538621f2 2614}
2615
93406d87 2616DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2617 bgp_graceful_restart_stalepath_time_cmd,
2618 "bgp graceful-restart stalepath-time (1-4095)",
2619 "BGP specific commands\n"
2620 "Graceful restart capability parameters\n"
2621 "Set the max time to hold onto restarting peer's stale paths\n"
2622 "Delay value (seconds)\n")
93406d87 2623{
d62a17ae 2624 VTY_DECLVAR_CONTEXT(bgp, bgp);
2625 int idx_number = 3;
d7c0a89a 2626 uint32_t stalepath;
93406d87 2627
d62a17ae 2628 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2629 bgp->stalepath_time = stalepath;
2630 return CMD_SUCCESS;
93406d87 2631}
2632
eb6f1b41 2633DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2634 bgp_graceful_restart_restart_time_cmd,
2635 "bgp graceful-restart restart-time (1-4095)",
2636 "BGP specific commands\n"
2637 "Graceful restart capability parameters\n"
2638 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2639 "Delay value (seconds)\n")
eb6f1b41 2640{
d62a17ae 2641 VTY_DECLVAR_CONTEXT(bgp, bgp);
2642 int idx_number = 3;
d7c0a89a 2643 uint32_t restart;
eb6f1b41 2644
d62a17ae 2645 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2646 bgp->restart_time = restart;
2647 return CMD_SUCCESS;
eb6f1b41
PG
2648}
2649
cfd47646 2650DEFUN (bgp_graceful_restart_select_defer_time,
2651 bgp_graceful_restart_select_defer_time_cmd,
2652 "bgp graceful-restart select-defer-time (0-3600)",
2653 "BGP specific commands\n"
2654 "Graceful restart capability parameters\n"
2655 "Set the time to defer the BGP route selection after restart\n"
2656 "Delay value (seconds, 0 - disable)\n")
2657{
2658 VTY_DECLVAR_CONTEXT(bgp, bgp);
2659 int idx_number = 3;
2660 uint32_t defer_time;
2661
2662 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2663 bgp->select_defer_time = defer_time;
2664 if (defer_time == 0)
892fedb6 2665 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2666 else
892fedb6 2667 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2668
2669 return CMD_SUCCESS;
2670}
2671
93406d87 2672DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2673 no_bgp_graceful_restart_stalepath_time_cmd,
2674 "no bgp graceful-restart stalepath-time [(1-4095)]",
2675 NO_STR
2676 "BGP specific commands\n"
2677 "Graceful restart capability parameters\n"
2678 "Set the max time to hold onto restarting peer's stale paths\n"
2679 "Delay value (seconds)\n")
93406d87 2680{
d62a17ae 2681 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2682
d62a17ae 2683 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2684 return CMD_SUCCESS;
93406d87 2685}
2686
eb6f1b41 2687DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2688 no_bgp_graceful_restart_restart_time_cmd,
2689 "no bgp graceful-restart restart-time [(1-4095)]",
2690 NO_STR
2691 "BGP specific commands\n"
2692 "Graceful restart capability parameters\n"
2693 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2694 "Delay value (seconds)\n")
eb6f1b41 2695{
d62a17ae 2696 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2697
d62a17ae 2698 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2699 return CMD_SUCCESS;
eb6f1b41
PG
2700}
2701
cfd47646 2702DEFUN (no_bgp_graceful_restart_select_defer_time,
2703 no_bgp_graceful_restart_select_defer_time_cmd,
2704 "no bgp graceful-restart select-defer-time [(0-3600)]",
2705 NO_STR
2706 "BGP specific commands\n"
2707 "Graceful restart capability parameters\n"
2708 "Set the time to defer the BGP route selection after restart\n"
2709 "Delay value (seconds)\n")
2710{
2711 VTY_DECLVAR_CONTEXT(bgp, bgp);
2712
2713 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2714 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2715
2716 return CMD_SUCCESS;
2717}
2718
43fc21b3 2719DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2720 bgp_graceful_restart_preserve_fw_cmd,
2721 "bgp graceful-restart preserve-fw-state",
2722 "BGP specific commands\n"
2723 "Graceful restart capability parameters\n"
2724 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2725{
d62a17ae 2726 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2727 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2728 return CMD_SUCCESS;
43fc21b3
JC
2729}
2730
2731DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2732 no_bgp_graceful_restart_preserve_fw_cmd,
2733 "no bgp graceful-restart preserve-fw-state",
2734 NO_STR
2735 "BGP specific commands\n"
2736 "Graceful restart capability parameters\n"
2737 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2738{
d62a17ae 2739 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2740 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2741 return CMD_SUCCESS;
43fc21b3
JC
2742}
2743
055679e9 2744DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2745 bgp_graceful_restart_disable_cmd,
2746 "bgp graceful-restart-disable",
2747 "BGP specific commands\n"
2748 GR_DISABLE)
055679e9 2749{
2750 int ret = BGP_GR_FAILURE;
2751
2752 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2753 zlog_debug(
2ba1fe69 2754 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2755
055679e9 2756 VTY_DECLVAR_CONTEXT(bgp, bgp);
2757
2758 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2759
dc95985f 2760 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2761 bgp->peer, ret);
5cce3f05 2762
055679e9 2763 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2764 zlog_debug(
2ba1fe69 2765 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2766 vty_out(vty,
2767 "Graceful restart configuration changed, reset all peers to take effect\n");
2768
055679e9 2769 return bgp_vty_return(vty, ret);
2770}
2771
2772DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2773 no_bgp_graceful_restart_disable_cmd,
2774 "no bgp graceful-restart-disable",
2775 NO_STR
2776 "BGP specific commands\n"
2777 NO_GR_DISABLE
055679e9 2778 )
2779{
2780 VTY_DECLVAR_CONTEXT(bgp, bgp);
2781
2782 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2783 zlog_debug(
2ba1fe69 2784 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2785
2786 int ret = BGP_GR_FAILURE;
2787
2788 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2789
36235319
QY
2790 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2791 ret);
5cce3f05 2792
055679e9 2793 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2794 zlog_debug(
2ba1fe69 2795 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2796 vty_out(vty,
2797 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2798
2799 return bgp_vty_return(vty, ret);
2800}
2801
2802DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2803 bgp_neighbor_graceful_restart_set_cmd,
2804 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2805 NEIGHBOR_STR
2806 NEIGHBOR_ADDR_STR2
2807 GR_NEIGHBOR_CMD
055679e9 2808 )
2809{
2810 int idx_peer = 1;
2811 struct peer *peer;
2812 int ret = BGP_GR_FAILURE;
2813
dc95985f 2814 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2815
055679e9 2816 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2817 zlog_debug(
2ba1fe69 2818 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2819
055679e9 2820 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2821 if (!peer)
2822 return CMD_WARNING_CONFIG_FAILED;
2823
2824 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2825
dc95985f 2826 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2827 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2828
2829 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2830 zlog_debug(
2ba1fe69 2831 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2832 vty_out(vty,
2833 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2834
2835 return bgp_vty_return(vty, ret);
2836}
2837
2838DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2839 no_bgp_neighbor_graceful_restart_set_cmd,
2840 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2841 NO_STR
2842 NEIGHBOR_STR
2843 NEIGHBOR_ADDR_STR2
2844 NO_GR_NEIGHBOR_CMD
055679e9 2845 )
2846{
2847 int idx_peer = 2;
2848 int ret = BGP_GR_FAILURE;
2849 struct peer *peer;
2850
dc95985f 2851 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2852
055679e9 2853 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2854 if (!peer)
2855 return CMD_WARNING_CONFIG_FAILED;
2856
2857 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2858 zlog_debug(
2ba1fe69 2859 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2860
2861 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2862
dc95985f 2863 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2864 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2865
2866 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2867 zlog_debug(
2ba1fe69 2868 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2869 vty_out(vty,
2870 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2871
2872 return bgp_vty_return(vty, ret);
2873}
2874
2875DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2876 bgp_neighbor_graceful_restart_helper_set_cmd,
2877 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2878 NEIGHBOR_STR
2879 NEIGHBOR_ADDR_STR2
2880 GR_NEIGHBOR_HELPER_CMD
055679e9 2881 )
2882{
2883 int idx_peer = 1;
2884 struct peer *peer;
2885 int ret = BGP_GR_FAILURE;
2886
dc95985f 2887 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2888
055679e9 2889 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2890 zlog_debug(
2ba1fe69 2891 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2892
055679e9 2893 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2894
055679e9 2895 if (!peer)
2896 return CMD_WARNING_CONFIG_FAILED;
2897
2898
2899 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2900
dc95985f 2901 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2902 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2903
055679e9 2904 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2905 zlog_debug(
2ba1fe69 2906 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2907 vty_out(vty,
2908 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2909
2910 return bgp_vty_return(vty, ret);
2911}
2912
2913DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2914 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2915 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2916 NO_STR
2917 NEIGHBOR_STR
2918 NEIGHBOR_ADDR_STR2
2919 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2920 )
2921{
2922 int idx_peer = 2;
2923 int ret = BGP_GR_FAILURE;
2924 struct peer *peer;
2925
dc95985f 2926 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2927
055679e9 2928 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2929 if (!peer)
2930 return CMD_WARNING_CONFIG_FAILED;
2931
2932 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2933 zlog_debug(
2ba1fe69 2934 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 2935
36235319 2936 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 2937
dc95985f 2938 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2939 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2940
2941 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2942 zlog_debug(
2ba1fe69 2943 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2944 vty_out(vty,
2945 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2946
2947 return bgp_vty_return(vty, ret);
2948}
2949
2950DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 2951 bgp_neighbor_graceful_restart_disable_set_cmd,
2952 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2953 NEIGHBOR_STR
2954 NEIGHBOR_ADDR_STR2
2955 GR_NEIGHBOR_DISABLE_CMD
055679e9 2956 )
2957{
2958 int idx_peer = 1;
2959 struct peer *peer;
2960 int ret = BGP_GR_FAILURE;
2961
dc95985f 2962 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2963
055679e9 2964 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2965 zlog_debug(
2ba1fe69 2966 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2967
2968 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2969 if (!peer)
2970 return CMD_WARNING_CONFIG_FAILED;
2971
36235319 2972 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 2973
2974 if (peer->bgp->t_startup)
2975 bgp_peer_gr_flags_update(peer);
2976
dc95985f 2977 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2978 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2979
055679e9 2980 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2981 zlog_debug(
2ba1fe69 2982 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2983 vty_out(vty,
2984 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2985
2986 return bgp_vty_return(vty, ret);
2987}
2988
2989DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 2990 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2991 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2992 NO_STR
2993 NEIGHBOR_STR
2994 NEIGHBOR_ADDR_STR2
2995 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 2996 )
2997{
2998 int idx_peer = 2;
2999 int ret = BGP_GR_FAILURE;
3000 struct peer *peer;
3001
dc95985f 3002 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3003
055679e9 3004 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3005 if (!peer)
3006 return CMD_WARNING_CONFIG_FAILED;
3007
3008 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3009 zlog_debug(
2ba1fe69 3010 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3011
3012 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3013
dc95985f 3014 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3015 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3016
3017 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3018 zlog_debug(
2ba1fe69 3019 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3020 vty_out(vty,
3021 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3022
3023 return bgp_vty_return(vty, ret);
3024}
3025
d6e3c15b 3026DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3027 bgp_graceful_restart_disable_eor_cmd,
3028 "bgp graceful-restart disable-eor",
3029 "BGP specific commands\n"
3030 "Graceful restart configuration parameters\n"
3031 "Disable EOR Check\n")
3032{
3033 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3034 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3035
d6e3c15b 3036 return CMD_SUCCESS;
3037}
3038
3039DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3040 no_bgp_graceful_restart_disable_eor_cmd,
3041 "no bgp graceful-restart disable-eor",
3042 NO_STR
3043 "BGP specific commands\n"
3044 "Graceful restart configuration parameters\n"
3045 "Disable EOR Check\n")
3046{
3047 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3048 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3049
3050 return CMD_SUCCESS;
3051}
3052
3053DEFUN (bgp_graceful_restart_rib_stale_time,
3054 bgp_graceful_restart_rib_stale_time_cmd,
3055 "bgp graceful-restart rib-stale-time (1-3600)",
3056 "BGP specific commands\n"
3057 "Graceful restart configuration parameters\n"
3058 "Specify the stale route removal timer in rib\n"
3059 "Delay value (seconds)\n")
3060{
3061 VTY_DECLVAR_CONTEXT(bgp, bgp);
3062 int idx_number = 3;
3063 uint32_t stale_time;
3064
3065 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3066 bgp->rib_stale_time = stale_time;
3067 /* Send the stale timer update message to RIB */
3068 if (bgp_zebra_stale_timer_update(bgp))
3069 return CMD_WARNING;
3070
3071 return CMD_SUCCESS;
3072}
3073
3074DEFUN (no_bgp_graceful_restart_rib_stale_time,
3075 no_bgp_graceful_restart_rib_stale_time_cmd,
3076 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3077 NO_STR
3078 "BGP specific commands\n"
3079 "Graceful restart configuration parameters\n"
3080 "Specify the stale route removal timer in rib\n"
3081 "Delay value (seconds)\n")
3082{
3083 VTY_DECLVAR_CONTEXT(bgp, bgp);
3084
3085 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3086 /* Send the stale timer update message to RIB */
3087 if (bgp_zebra_stale_timer_update(bgp))
3088 return CMD_WARNING;
3089
d6e3c15b 3090 return CMD_SUCCESS;
3091}
3092
ff8a8a7a
CS
3093static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3094 char *errmsg,
3095 size_t errmsg_len)
05bd726c 3096{
3097 bgp_static_redo_import_check(bgp);
3098 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
3099 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3100 return -1;
3101 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3102 return -1;
3103
3104 return 0;
05bd726c 3105}
3106
3107static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3108{
3109 struct listnode *node, *nnode;
3110 struct bgp *bgp;
3111 bool vrf_cfg = false;
ff8a8a7a 3112 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3113
3114 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3115 return CMD_SUCCESS;
3116
3117 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3118 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3119 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3120 vty_out(vty,
3121 "%% graceful-shutdown configuration found in vrf %s\n",
3122 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3123 VRF_DEFAULT_NAME : bgp->name);
3124 vrf_cfg = true;
3125 }
3126 }
3127
3128 if (vrf_cfg) {
3129 vty_out(vty,
3130 "%%Failed: global graceful-shutdown not permitted\n");
3131 return CMD_WARNING;
3132 }
3133
3134 /* Set flag globally */
3135 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3136
3137 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3138 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3139 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3140 sizeof(errmsg))
3141 < 0)
3142 if (strlen(errmsg))
3143 vty_out(vty, "%s\n", errmsg);
3144 }
05bd726c 3145
3146 return CMD_SUCCESS;
3147}
3148
3149static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3150{
3151 struct listnode *node, *nnode;
3152 struct bgp *bgp;
ff8a8a7a 3153 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3154
3155 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3156 return CMD_SUCCESS;
3157
3158 /* Unset flag globally */
3159 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3160
3161 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3162 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3163 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3164 sizeof(errmsg))
3165 < 0)
3166 if (strlen(errmsg))
3167 vty_out(vty, "%s\n", errmsg);
3168 }
05bd726c 3169
3170 return CMD_SUCCESS;
3171}
3172
7f323236
DW
3173/* "bgp graceful-shutdown" configuration */
3174DEFUN (bgp_graceful_shutdown,
3175 bgp_graceful_shutdown_cmd,
3176 "bgp graceful-shutdown",
3177 BGP_STR
3178 "Graceful shutdown parameters\n")
3179{
05bd726c 3180 if (vty->node == CONFIG_NODE)
3181 return bgp_global_graceful_shutdown_config_vty(vty);
3182
87ce2564
CS
3183 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3184 NB_OP_MODIFY, "true");
7f323236 3185
ff8a8a7a 3186 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3187}
3188
ff8a8a7a 3189DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3190 no_bgp_graceful_shutdown_cmd,
3191 "no bgp graceful-shutdown",
3192 NO_STR
3193 BGP_STR
3194 "Graceful shutdown parameters\n")
3195{
05bd726c 3196 if (vty->node == CONFIG_NODE)
3197 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3198
87ce2564
CS
3199 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3200 NB_OP_MODIFY, "false");
05bd726c 3201
ff8a8a7a
CS
3202 return nb_cli_apply_changes(vty, NULL);
3203}
7f323236 3204
ff8a8a7a
CS
3205void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3206 struct lyd_node *dnode,
3207 bool show_defaults)
3208{
3209 if (yang_dnode_get_bool(dnode, NULL))
3210 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3211}
3212
718e3744 3213/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3214DEFUN_YANG (bgp_fast_external_failover,
718e3744 3215 bgp_fast_external_failover_cmd,
3216 "bgp fast-external-failover",
3217 BGP_STR
3218 "Immediately reset session if a link to a directly connected external peer goes down\n")
3219{
87ce2564
CS
3220 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3221 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3222
3223 return nb_cli_apply_changes(vty, NULL);
718e3744 3224}
3225
ff8a8a7a 3226DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3227 no_bgp_fast_external_failover_cmd,
3228 "no bgp fast-external-failover",
3229 NO_STR
3230 BGP_STR
3231 "Immediately reset session if a link to a directly connected external peer goes down\n")
3232{
87ce2564
CS
3233 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3234 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3235
3236 return nb_cli_apply_changes(vty, NULL);
3237}
3238
3239void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3240 struct lyd_node *dnode,
3241 bool show_defaults)
3242{
3243 if (!yang_dnode_get_bool(dnode, NULL))
3244 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3245}
6b0655a2 3246
718e3744 3247/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3248DEFUN_YANG(bgp_bestpath_compare_router_id,
3249 bgp_bestpath_compare_router_id_cmd,
3250 "bgp bestpath compare-routerid",
3251 "BGP specific commands\n"
3252 "Change the default bestpath selection\n"
3253 "Compare router-id for identical EBGP paths\n")
718e3744 3254{
ff8a8a7a 3255 nb_cli_enqueue_change(
87ce2564
CS
3256 vty,
3257 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3258 NB_OP_MODIFY, "true");
7aafcaca 3259
ff8a8a7a 3260 return nb_cli_apply_changes(vty, NULL);
718e3744 3261}
3262
ff8a8a7a
CS
3263DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3264 no_bgp_bestpath_compare_router_id_cmd,
3265 "no bgp bestpath compare-routerid",
3266 NO_STR
3267 "BGP specific commands\n"
3268 "Change the default bestpath selection\n"
3269 "Compare router-id for identical EBGP paths\n")
718e3744 3270{
ff8a8a7a 3271 nb_cli_enqueue_change(
87ce2564
CS
3272 vty,
3273 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3274 NB_OP_MODIFY, "false");
7aafcaca 3275
ff8a8a7a 3276 return nb_cli_apply_changes(vty, NULL);
718e3744 3277}
6b0655a2 3278
718e3744 3279/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3280DEFUN_YANG(bgp_bestpath_aspath_ignore,
3281 bgp_bestpath_aspath_ignore_cmd,
3282 "bgp bestpath as-path ignore",
3283 "BGP specific commands\n"
3284 "Change the default bestpath selection\n"
3285 "AS-path attribute\n"
3286 "Ignore as-path length in selecting a route\n")
718e3744 3287{
87ce2564
CS
3288 nb_cli_enqueue_change(
3289 vty, "./global/route-selection-options/ignore-as-path-length",
3290 NB_OP_MODIFY, "true");
7aafcaca 3291
ff8a8a7a 3292 return nb_cli_apply_changes(vty, NULL);
718e3744 3293}
3294
ff8a8a7a
CS
3295DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3296 no_bgp_bestpath_aspath_ignore_cmd,
3297 "no bgp bestpath as-path ignore",
3298 NO_STR
3299 "BGP specific commands\n"
3300 "Change the default bestpath selection\n"
3301 "AS-path attribute\n"
3302 "Ignore as-path length in selecting a route\n")
718e3744 3303{
87ce2564
CS
3304 nb_cli_enqueue_change(
3305 vty, "./global/route-selection-options/ignore-as-path-length",
3306 NB_OP_MODIFY, "false");
7aafcaca 3307
ff8a8a7a 3308 return nb_cli_apply_changes(vty, NULL);
718e3744 3309}
6b0655a2 3310
6811845b 3311/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3312DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3313 bgp_bestpath_aspath_confed_cmd,
3314 "bgp bestpath as-path confed",
3315 "BGP specific commands\n"
3316 "Change the default bestpath selection\n"
3317 "AS-path attribute\n"
3318 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3319{
87ce2564
CS
3320 nb_cli_enqueue_change(vty,
3321 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3322 NB_OP_MODIFY, "true");
7aafcaca 3323
ff8a8a7a 3324 return nb_cli_apply_changes(vty, NULL);
6811845b 3325}
3326
ff8a8a7a 3327DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3328 no_bgp_bestpath_aspath_confed_cmd,
3329 "no bgp bestpath as-path confed",
3330 NO_STR
3331 "BGP specific commands\n"
3332 "Change the default bestpath selection\n"
3333 "AS-path attribute\n"
3334 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3335{
87ce2564
CS
3336 nb_cli_enqueue_change(vty,
3337 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3338 NB_OP_MODIFY, "false");
7aafcaca 3339
ff8a8a7a 3340 return nb_cli_apply_changes(vty, NULL);
6811845b 3341}
6b0655a2 3342
2fdd455c 3343/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3344DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3345 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3346 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3347 "BGP specific commands\n"
3348 "Change the default bestpath selection\n"
3349 "AS-path attribute\n"
3350 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3351 "Generate an AS_SET\n"
16fc1eec
DS
3352 "Do not generate an AS_SET\n")
3353{
d62a17ae 3354 int idx = 0;
219178b6 3355
87ce2564
CS
3356 nb_cli_enqueue_change(
3357 vty, "./global/route-selection-options/allow-multiple-as",
3358 NB_OP_MODIFY, "true");
d62a17ae 3359 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3360 nb_cli_enqueue_change(
87ce2564
CS
3361 vty,
3362 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3363 NB_OP_MODIFY, "true");
d62a17ae 3364 else
ff8a8a7a 3365 nb_cli_enqueue_change(
87ce2564
CS
3366 vty,
3367 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3368 NB_OP_MODIFY, "false");
7aafcaca 3369
ff8a8a7a 3370 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3371}
3372
ff8a8a7a 3373DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3374 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3375 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3376 NO_STR
3377 "BGP specific commands\n"
3378 "Change the default bestpath selection\n"
3379 "AS-path attribute\n"
3380 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3381 "Generate an AS_SET\n"
16fc1eec
DS
3382 "Do not generate an AS_SET\n")
3383{
87ce2564
CS
3384 nb_cli_enqueue_change(
3385 vty, "./global/route-selection-options/allow-multiple-as",
3386 NB_OP_MODIFY, "false");
3387 nb_cli_enqueue_change(
3388 vty, "./global/route-selection-options/multi-path-as-set",
3389 NB_OP_MODIFY, "false");
7aafcaca 3390
ff8a8a7a 3391 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3392}
6b0655a2 3393
848973c7 3394/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3395DEFUN_YANG(bgp_log_neighbor_changes,
3396 bgp_log_neighbor_changes_cmd,
3397 "bgp log-neighbor-changes",
3398 "BGP specific commands\n"
3399 "Log neighbor up/down and reset reason\n")
848973c7 3400{
87ce2564
CS
3401 nb_cli_enqueue_change(
3402 vty, "./global/global-neighbor-config/log-neighbor-changes",
3403 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3404
3405 return nb_cli_apply_changes(vty, NULL);
848973c7 3406}
3407
ff8a8a7a
CS
3408DEFUN_YANG(no_bgp_log_neighbor_changes,
3409 no_bgp_log_neighbor_changes_cmd,
3410 "no bgp log-neighbor-changes",
3411 NO_STR
3412 "BGP specific commands\n"
3413 "Log neighbor up/down and reset reason\n")
848973c7 3414{
87ce2564
CS
3415 nb_cli_enqueue_change(
3416 vty, "./global/global-neighbor-config/log-neighbor-changes",
3417 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3418
3419 return nb_cli_apply_changes(vty, NULL);
848973c7 3420}
6b0655a2 3421
718e3744 3422/* "bgp bestpath med" configuration. */
ff8a8a7a 3423DEFUN_YANG (bgp_bestpath_med,
718e3744 3424 bgp_bestpath_med_cmd,
2d8c1a4d 3425 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3426 "BGP specific commands\n"
3427 "Change the default bestpath selection\n"
3428 "MED attribute\n"
3429 "Compare MED among confederation paths\n"
838758ac
DW
3430 "Treat missing MED as the least preferred one\n"
3431 "Treat missing MED as the least preferred one\n"
3432 "Compare MED among confederation paths\n")
718e3744 3433{
d62a17ae 3434 int idx = 0;
ff8a8a7a
CS
3435 bool confed = false;
3436 bool worst_med = false;
3437
3438
d62a17ae 3439 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3440 confed = true;
3441
87ce2564
CS
3442 nb_cli_enqueue_change(vty,
3443 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3444 NB_OP_MODIFY, confed ? "true" : "false");
3445
d62a17ae 3446 idx = 0;
3447 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3448 worst_med = true;
e52702f2 3449
87ce2564
CS
3450 nb_cli_enqueue_change(
3451 vty, "./global/route-selection-options/missing-as-worst-med",
3452 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3453
ff8a8a7a 3454 return nb_cli_apply_changes(vty, NULL);
718e3744 3455}
3456
ff8a8a7a 3457DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3458 no_bgp_bestpath_med_cmd,
2d8c1a4d 3459 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3460 NO_STR
3461 "BGP specific commands\n"
3462 "Change the default bestpath selection\n"
3463 "MED attribute\n"
3464 "Compare MED among confederation paths\n"
3a2d747c
QY
3465 "Treat missing MED as the least preferred one\n"
3466 "Treat missing MED as the least preferred one\n"
3467 "Compare MED among confederation paths\n")
718e3744 3468{
d62a17ae 3469 int idx = 0;
ff8a8a7a 3470
d62a17ae 3471 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3472 nb_cli_enqueue_change(
3473 vty, "./global/route-selection-options/confed-med",
3474 NB_OP_MODIFY, "false");
ff8a8a7a 3475
d62a17ae 3476 idx = 0;
3477 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3478 nb_cli_enqueue_change(
87ce2564
CS
3479 vty,
3480 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3481 NB_OP_MODIFY, "false");
718e3744 3482
ff8a8a7a 3483 return nb_cli_apply_changes(vty, NULL);
718e3744 3484}
3485
f7e1c681 3486/* "bgp bestpath bandwidth" configuration. */
3487DEFPY (bgp_bestpath_bw,
3488 bgp_bestpath_bw_cmd,
ad36d216 3489 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3490 "BGP specific commands\n"
3491 "Change the default bestpath selection\n"
3492 "Link Bandwidth attribute\n"
3493 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3494 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3495 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3496{
3497 VTY_DECLVAR_CONTEXT(bgp, bgp);
3498 afi_t afi;
3499 safi_t safi;
3500
ad36d216
DS
3501 if (!bw_cfg) {
3502 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3503 return CMD_ERR_INCOMPLETE;
f7e1c681 3504 }
ad36d216
DS
3505 if (!strcmp(bw_cfg, "ignore"))
3506 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3507 else if (!strcmp(bw_cfg, "skip-missing"))
3508 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3509 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3510 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3511 else
3512 return CMD_ERR_NO_MATCH;
f7e1c681 3513
3514 /* This config is used in route install, so redo that. */
3515 FOREACH_AFI_SAFI (afi, safi) {
3516 if (!bgp_fibupd_safi(safi))
3517 continue;
3518 bgp_zebra_announce_table(bgp, afi, safi);
3519 }
3520
3521 return CMD_SUCCESS;
3522}
3523
ad36d216
DS
3524DEFPY (no_bgp_bestpath_bw,
3525 no_bgp_bestpath_bw_cmd,
3526 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3527 NO_STR
3528 "BGP specific commands\n"
3529 "Change the default bestpath selection\n"
3530 "Link Bandwidth attribute\n"
3531 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3532 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3533 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3534{
3535 VTY_DECLVAR_CONTEXT(bgp, bgp);
3536 afi_t afi;
3537 safi_t safi;
3538
3539 bgp->lb_handling = BGP_LINK_BW_ECMP;
3540
3541 /* This config is used in route install, so redo that. */
3542 FOREACH_AFI_SAFI (afi, safi) {
3543 if (!bgp_fibupd_safi(safi))
3544 continue;
3545 bgp_zebra_announce_table(bgp, afi, safi);
3546 }
3547 return CMD_SUCCESS;
3548}
3549
718e3744 3550/* "no bgp default ipv4-unicast". */
3551DEFUN (no_bgp_default_ipv4_unicast,
3552 no_bgp_default_ipv4_unicast_cmd,
3553 "no bgp default ipv4-unicast",
3554 NO_STR
3555 "BGP specific commands\n"
3556 "Configure BGP defaults\n"
3557 "Activate ipv4-unicast for a peer by default\n")
3558{
d62a17ae 3559 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3560 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3561 return CMD_SUCCESS;
718e3744 3562}
3563
3564DEFUN (bgp_default_ipv4_unicast,
3565 bgp_default_ipv4_unicast_cmd,
3566 "bgp default ipv4-unicast",
3567 "BGP specific commands\n"
3568 "Configure BGP defaults\n"
3569 "Activate ipv4-unicast for a peer by default\n")
3570{
d62a17ae 3571 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3572 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3573 return CMD_SUCCESS;
718e3744 3574}
6b0655a2 3575
04b6bdc0 3576/* Display hostname in certain command outputs */
ff8a8a7a 3577DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3578 bgp_default_show_hostname_cmd,
3579 "bgp default show-hostname",
3580 "BGP specific commands\n"
3581 "Configure BGP defaults\n"
0437e105 3582 "Show hostname in certain command outputs\n")
04b6bdc0 3583{
87ce2564
CS
3584 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3585 "true");
ff8a8a7a
CS
3586
3587 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3588}
3589
ff8a8a7a
CS
3590DEFUN_YANG(no_bgp_default_show_hostname,
3591 no_bgp_default_show_hostname_cmd,
3592 "no bgp default show-hostname",
3593 NO_STR
3594 "BGP specific commands\n"
3595 "Configure BGP defaults\n"
3596 "Show hostname in certain command outputs\n")
04b6bdc0 3597{
87ce2564
CS
3598 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3599 "false");
ff8a8a7a
CS
3600
3601 return nb_cli_apply_changes(vty, NULL);
3602}
3603
3604void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3605 bool show_defaults)
3606{
3607 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3608 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3609}
3610
aef999a2
DA
3611/* Display hostname in certain command outputs */
3612DEFUN (bgp_default_show_nexthop_hostname,
3613 bgp_default_show_nexthop_hostname_cmd,
3614 "bgp default show-nexthop-hostname",
3615 "BGP specific commands\n"
3616 "Configure BGP defaults\n"
3617 "Show hostname for nexthop in certain command outputs\n")
3618{
87ce2564
CS
3619 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3620 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3621
3622 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3623}
3624
3625DEFUN (no_bgp_default_show_nexthop_hostname,
3626 no_bgp_default_show_nexthop_hostname_cmd,
3627 "no bgp default show-nexthop-hostname",
3628 NO_STR
3629 "BGP specific commands\n"
3630 "Configure BGP defaults\n"
3631 "Show hostname for nexthop in certain command outputs\n")
3632{
87ce2564
CS
3633 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3634 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3635
3636 return nb_cli_apply_changes(vty, NULL);
3637}
3638
3639void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3640 struct lyd_node *dnode,
3641 bool show_defaults)
3642{
3643 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3644 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3645}
3646
8233ef81 3647/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3648DEFUN_YANG(bgp_network_import_check,
3649 bgp_network_import_check_cmd,
3650 "bgp network import-check",
3651 "BGP specific commands\n"
3652 "BGP network command\n"
3653 "Check BGP network route exists in IGP\n")
718e3744 3654{
87ce2564
CS
3655 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3656 "true");
078430f6 3657
ff8a8a7a 3658 return nb_cli_apply_changes(vty, NULL);
718e3744 3659}
3660
d62a17ae 3661ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3662 "bgp network import-check exact",
3663 "BGP specific commands\n"
3664 "BGP network command\n"
3665 "Check BGP network route exists in IGP\n"
3666 "Match route precisely\n")
8233ef81 3667
ff8a8a7a
CS
3668DEFUN_YANG(no_bgp_network_import_check,
3669 no_bgp_network_import_check_cmd,
3670 "no bgp network import-check",
3671 NO_STR
3672 "BGP specific commands\n"
3673 "BGP network command\n"
3674 "Check BGP network route exists in IGP\n")
718e3744 3675{
87ce2564
CS
3676 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3677 "false");
5623e905 3678
ff8a8a7a 3679 return nb_cli_apply_changes(vty, NULL);
718e3744 3680}
6b0655a2 3681
ff8a8a7a
CS
3682void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3683 bool show_defaults)
718e3744 3684{
ff8a8a7a
CS
3685 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3686 vty_out(vty, " bgp network import-check\n");
3687}
718e3744 3688
ff8a8a7a
CS
3689DEFUN_YANG(bgp_default_local_preference,
3690 bgp_default_local_preference_cmd,
3691 "bgp default local-preference (0-4294967295)",
3692 "BGP specific commands\n"
3693 "Configure BGP defaults\n"
3694 "local preference (higher=more preferred)\n"
3695 "Configure default local preference value\n")
3696{
3697 int idx_number = 3;
718e3744 3698
87ce2564 3699 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3700 argv[idx_number]->arg);
718e3744 3701
ff8a8a7a 3702 return nb_cli_apply_changes(vty, NULL);
718e3744 3703}
3704
ff8a8a7a
CS
3705DEFUN_YANG(no_bgp_default_local_preference,
3706 no_bgp_default_local_preference_cmd,
3707 "no bgp default local-preference [(0-4294967295)]",
3708 NO_STR
3709 "BGP specific commands\n"
3710 "Configure BGP defaults\n"
3711 "local preference (higher=more preferred)\n"
3712 "Configure default local preference value\n")
718e3744 3713{
87ce2564 3714 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 3715
ff8a8a7a 3716 return nb_cli_apply_changes(vty, NULL);
718e3744 3717}
3718
ff8a8a7a
CS
3719void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3720 bool show_defaults)
3721{
3722 vty_out(vty, " bgp default local-preference %u\n",
3723 yang_dnode_get_uint32(dnode, NULL));
3724}
6b0655a2 3725
ff8a8a7a
CS
3726
3727DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3728 bgp_default_subgroup_pkt_queue_max_cmd,
3729 "bgp default subgroup-pkt-queue-max (20-100)",
3730 "BGP specific commands\n"
3731 "Configure BGP defaults\n"
3732 "subgroup-pkt-queue-max\n"
3733 "Configure subgroup packet queue max\n")
8bd9d948 3734{
d62a17ae 3735 int idx_number = 3;
3f9c7369 3736
ff8a8a7a 3737 nb_cli_enqueue_change(
87ce2564
CS
3738 vty,
3739 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 3740 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 3741
ff8a8a7a 3742 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
3743}
3744
ff8a8a7a
CS
3745DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3746 no_bgp_default_subgroup_pkt_queue_max_cmd,
3747 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3748 NO_STR
3749 "BGP specific commands\n"
3750 "Configure BGP defaults\n"
3751 "subgroup-pkt-queue-max\n"
3752 "Configure subgroup packet queue max\n")
3f9c7369 3753{
ff8a8a7a 3754 nb_cli_enqueue_change(
87ce2564
CS
3755 vty,
3756 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
3757 NB_OP_MODIFY, NULL);
3758
3759 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3760}
3761
ff8a8a7a
CS
3762void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3763 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3764{
3765 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3766 yang_dnode_get_uint32(dnode, NULL));
3767}
813d4307 3768
ff8a8a7a
CS
3769DEFUN_YANG(bgp_rr_allow_outbound_policy,
3770 bgp_rr_allow_outbound_policy_cmd,
3771 "bgp route-reflector allow-outbound-policy",
3772 "BGP specific commands\n"
3773 "Allow modifications made by out route-map\n"
3774 "on ibgp neighbors\n")
8bd9d948 3775{
87ce2564
CS
3776 nb_cli_enqueue_change(vty,
3777 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 3778 NB_OP_MODIFY, "true");
8bd9d948 3779
ff8a8a7a
CS
3780 return nb_cli_apply_changes(vty, NULL);
3781}
8bd9d948 3782
ff8a8a7a
CS
3783DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3784 no_bgp_rr_allow_outbound_policy_cmd,
3785 "no bgp route-reflector allow-outbound-policy",
3786 NO_STR
3787 "BGP specific commands\n"
3788 "Allow modifications made by out route-map\n"
3789 "on ibgp neighbors\n")
3790{
87ce2564
CS
3791 nb_cli_enqueue_change(vty,
3792 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
3793 NB_OP_MODIFY, "false");
3794
3795 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3796}
3797
ff8a8a7a
CS
3798
3799void cli_show_router_global_neighbor_config(struct vty *vty,
3800 struct lyd_node *dnode,
3801 bool show_defaults)
8bd9d948 3802{
ff8a8a7a
CS
3803 uint32_t write_quanta, read_quanta;
3804
3805 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3806 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 3807
ff8a8a7a
CS
3808 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3809 uint32_t listen_limit = yang_dnode_get_uint32(
3810 dnode, "./dynamic-neighbors-limit");
3811 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 3812 }
8bd9d948 3813
ff8a8a7a
CS
3814 write_quanta = yang_dnode_get_uint32(
3815 dnode, "./packet-quanta-config/wpkt-quanta");
3816 if (write_quanta != BGP_WRITE_PACKET_MAX)
3817 vty_out(vty, " write-quanta %d\n", write_quanta);
3818
3819 read_quanta = yang_dnode_get_uint32(
3820 dnode, "./packet-quanta-config/rpkt-quanta");
3821
3822 if (read_quanta != BGP_READ_PACKET_MAX)
3823 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
3824}
3825
ff8a8a7a
CS
3826DEFUN_YANG(bgp_listen_limit,
3827 bgp_listen_limit_cmd,
3828 "bgp listen limit (1-5000)",
3829 "BGP specific commands\n"
3830 "BGP Dynamic Neighbors listen commands\n"
3831 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3832 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3833{
d62a17ae 3834 int idx_number = 3;
f14e6fdb 3835
ff8a8a7a 3836 nb_cli_enqueue_change(
87ce2564 3837 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 3838 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 3839
ff8a8a7a 3840 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3841}
3842
ff8a8a7a
CS
3843DEFUN_YANG(no_bgp_listen_limit,
3844 no_bgp_listen_limit_cmd,
3845 "no bgp listen limit [(1-5000)]",
3846 NO_STR
3847 "BGP specific commands\n"
3848 "BGP Dynamic Neighbors listen commands\n"
3849 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3850 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3851{
ff8a8a7a 3852 nb_cli_enqueue_change(
87ce2564 3853 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
3854 NB_OP_DESTROY, NULL);
3855
3856 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3857}
3858
3859
20eb8864 3860/*
3861 * Check if this listen range is already configured. Check for exact
3862 * match or overlap based on input.
3863 */
d62a17ae 3864static struct peer_group *listen_range_exists(struct bgp *bgp,
3865 struct prefix *range, int exact)
3866{
3867 struct listnode *node, *nnode;
3868 struct listnode *node1, *nnode1;
3869 struct peer_group *group;
3870 struct prefix *lr;
3871 afi_t afi;
3872 int match;
3873
3874 afi = family2afi(range->family);
3875 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3876 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3877 lr)) {
3878 if (exact)
3879 match = prefix_same(range, lr);
3880 else
3881 match = (prefix_match(range, lr)
3882 || prefix_match(lr, range));
3883 if (match)
3884 return group;
3885 }
3886 }
3887
3888 return NULL;
20eb8864 3889}
3890
f14e6fdb
DS
3891DEFUN (bgp_listen_range,
3892 bgp_listen_range_cmd,
d7b9898c 3893 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3894 "BGP specific commands\n"
d7fa34c1
QY
3895 "Configure BGP dynamic neighbors listen range\n"
3896 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3897 NEIGHBOR_ADDR_STR
3898 "Member of the peer-group\n"
3899 "Peer-group name\n")
f14e6fdb 3900{
d62a17ae 3901 VTY_DECLVAR_CONTEXT(bgp, bgp);
3902 struct prefix range;
3903 struct peer_group *group, *existing_group;
3904 afi_t afi;
3905 int ret;
3906 int idx = 0;
3907
3908 argv_find(argv, argc, "A.B.C.D/M", &idx);
3909 argv_find(argv, argc, "X:X::X:X/M", &idx);
3910 char *prefix = argv[idx]->arg;
d7b9898c 3911 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3912 char *peergroup = argv[idx]->arg;
3913
3914 /* Convert IP prefix string to struct prefix. */
3915 ret = str2prefix(prefix, &range);
3916 if (!ret) {
3917 vty_out(vty, "%% Malformed listen range\n");
3918 return CMD_WARNING_CONFIG_FAILED;
3919 }
3920
3921 afi = family2afi(range.family);
3922
3923 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3924 vty_out(vty,
3925 "%% Malformed listen range (link-local address)\n");
3926 return CMD_WARNING_CONFIG_FAILED;
3927 }
3928
3929 apply_mask(&range);
3930
3931 /* Check if same listen range is already configured. */
3932 existing_group = listen_range_exists(bgp, &range, 1);
3933 if (existing_group) {
3934 if (strcmp(existing_group->name, peergroup) == 0)
3935 return CMD_SUCCESS;
3936 else {
3937 vty_out(vty,
3938 "%% Same listen range is attached to peer-group %s\n",
3939 existing_group->name);
3940 return CMD_WARNING_CONFIG_FAILED;
3941 }
3942 }
3943
3944 /* Check if an overlapping listen range exists. */
3945 if (listen_range_exists(bgp, &range, 0)) {
3946 vty_out(vty,
3947 "%% Listen range overlaps with existing listen range\n");
3948 return CMD_WARNING_CONFIG_FAILED;
3949 }
3950
3951 group = peer_group_lookup(bgp, peergroup);
3952 if (!group) {
3953 vty_out(vty, "%% Configure the peer-group first\n");
3954 return CMD_WARNING_CONFIG_FAILED;
3955 }
3956
3957 ret = peer_group_listen_range_add(group, &range);
3958 return bgp_vty_return(vty, ret);
f14e6fdb
DS
3959}
3960
3961DEFUN (no_bgp_listen_range,
3962 no_bgp_listen_range_cmd,
d7b9898c 3963 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 3964 NO_STR
f14e6fdb 3965 "BGP specific commands\n"
d7fa34c1
QY
3966 "Unconfigure BGP dynamic neighbors listen range\n"
3967 "Unconfigure BGP dynamic neighbors listen range\n"
3968 NEIGHBOR_ADDR_STR
3969 "Member of the peer-group\n"
3970 "Peer-group name\n")
f14e6fdb 3971{
d62a17ae 3972 VTY_DECLVAR_CONTEXT(bgp, bgp);
3973 struct prefix range;
3974 struct peer_group *group;
3975 afi_t afi;
3976 int ret;
3977 int idx = 0;
3978
3979 argv_find(argv, argc, "A.B.C.D/M", &idx);
3980 argv_find(argv, argc, "X:X::X:X/M", &idx);
3981 char *prefix = argv[idx]->arg;
21d88a71 3982 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3983 char *peergroup = argv[idx]->arg;
3984
3985 /* Convert IP prefix string to struct prefix. */
3986 ret = str2prefix(prefix, &range);
3987 if (!ret) {
3988 vty_out(vty, "%% Malformed listen range\n");
3989 return CMD_WARNING_CONFIG_FAILED;
3990 }
3991
3992 afi = family2afi(range.family);
3993
3994 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3995 vty_out(vty,
3996 "%% Malformed listen range (link-local address)\n");
3997 return CMD_WARNING_CONFIG_FAILED;
3998 }
3999
4000 apply_mask(&range);
4001
4002 group = peer_group_lookup(bgp, peergroup);
4003 if (!group) {
4004 vty_out(vty, "%% Peer-group does not exist\n");
4005 return CMD_WARNING_CONFIG_FAILED;
4006 }
4007
4008 ret = peer_group_listen_range_del(group, &range);
4009 return bgp_vty_return(vty, ret);
4010}
4011
2b791107 4012void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4013{
4014 struct peer_group *group;
4015 struct listnode *node, *nnode, *rnode, *nrnode;
4016 struct prefix *range;
4017 afi_t afi;
d62a17ae 4018
4019 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4020 vty_out(vty, " bgp listen limit %d\n",
4021 bgp->dynamic_neighbors_limit);
4022
4023 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4024 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4025 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4026 nrnode, range)) {
d62a17ae 4027 vty_out(vty,
2dbe669b
DA
4028 " bgp listen range %pFX peer-group %s\n",
4029 range, group->name);
d62a17ae 4030 }
4031 }
4032 }
f14e6fdb
DS
4033}
4034
4035
ff8a8a7a
CS
4036DEFUN_YANG(bgp_disable_connected_route_check,
4037 bgp_disable_connected_route_check_cmd,
4038 "bgp disable-ebgp-connected-route-check",
4039 "BGP specific commands\n"
4040 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4041{
87ce2564
CS
4042 nb_cli_enqueue_change(vty,
4043 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4044 NB_OP_MODIFY, "true");
7aafcaca 4045
ff8a8a7a 4046 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
4047}
4048
ff8a8a7a
CS
4049DEFUN_YANG(no_bgp_disable_connected_route_check,
4050 no_bgp_disable_connected_route_check_cmd,
4051 "no bgp disable-ebgp-connected-route-check",
4052 NO_STR
4053 "BGP specific commands\n"
4054 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4055{
87ce2564
CS
4056 nb_cli_enqueue_change(vty,
4057 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4058 NB_OP_MODIFY, "false");
d62a17ae 4059
ff8a8a7a 4060 return nb_cli_apply_changes(vty, NULL);
d62a17ae 4061}
4062
ff8a8a7a
CS
4063void cli_show_router_global_ebgp_multihop_connected_route_check(
4064 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4065{
4066 if (yang_dnode_get_bool(dnode, NULL))
4067 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4068}
d62a17ae 4069
4070static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4071 const char *as_str, afi_t afi, safi_t safi)
4072{
4073 VTY_DECLVAR_CONTEXT(bgp, bgp);
4074 int ret;
4075 as_t as;
4076 int as_type = AS_SPECIFIED;
4077 union sockunion su;
4078
4079 if (as_str[0] == 'i') {
4080 as = 0;
4081 as_type = AS_INTERNAL;
4082 } else if (as_str[0] == 'e') {
4083 as = 0;
4084 as_type = AS_EXTERNAL;
4085 } else {
4086 /* Get AS number. */
4087 as = strtoul(as_str, NULL, 10);
4088 }
4089
390485fd 4090 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 4091 ret = str2sockunion(peer_str, &su);
4092 if (ret < 0) {
390485fd
DS
4093 struct peer *peer;
4094
4095 /* Check if existing interface peer */
4096 peer = peer_lookup_by_conf_if(bgp, peer_str);
4097
d62a17ae 4098 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
4099 safi);
390485fd
DS
4100
4101 /* if not interface peer, check peer-group settings */
4102 if (ret < 0 && !peer) {
d62a17ae 4103 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4104 if (ret < 0) {
4105 vty_out(vty,
390485fd 4106 "%% Create the peer-group or interface first\n");
d62a17ae 4107 return CMD_WARNING_CONFIG_FAILED;
4108 }
4109 return CMD_SUCCESS;
4110 }
4111 } else {
4112 if (peer_address_self_check(bgp, &su)) {
4113 vty_out(vty,
4114 "%% Can not configure the local system as neighbor\n");
4115 return CMD_WARNING_CONFIG_FAILED;
4116 }
4117 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
4118 }
4119
4120 /* This peer belongs to peer group. */
4121 switch (ret) {
4122 case BGP_ERR_PEER_GROUP_MEMBER:
4123 vty_out(vty,
faa16034 4124 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 4125 return CMD_WARNING_CONFIG_FAILED;
4126 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
4127 vty_out(vty,
faa16034 4128 "%% Peer-group members must be all internal or all external\n");
d62a17ae 4129 return CMD_WARNING_CONFIG_FAILED;
4130 }
4131 return bgp_vty_return(vty, ret);
718e3744 4132}
4133
ff8a8a7a
CS
4134DEFUN_YANG(bgp_default_shutdown,
4135 bgp_default_shutdown_cmd,
4136 "[no] bgp default shutdown",
4137 NO_STR BGP_STR
4138 "Configure BGP defaults\n"
4139 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4140{
87ce2564 4141 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4142 strmatch(argv[0]->text, "no") ? "false" : "true");
4143
4144 return nb_cli_apply_changes(vty, NULL);
4145}
4146
4147void cli_show_router_bgp_default_shutdown(struct vty *vty,
4148 struct lyd_node *dnode,
4149 bool show_defaults)
4150{
4151 if (yang_dnode_get_bool(dnode, NULL))
4152 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4153}
4154
736b68f3
DS
4155DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4156 BGP_STR
9ddf4b81 4157 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4158 "Add a shutdown message (RFC 8203)\n"
4159 "Shutdown message\n")
9cf59432 4160{
736b68f3 4161 char *msgstr = NULL;
8389c83a 4162
9cf59432
DS
4163 VTY_DECLVAR_CONTEXT(bgp, bgp);
4164
8389c83a 4165 if (argc > 3)
f80e35b6 4166 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4167
4168 bgp_shutdown_enable(bgp, msgstr);
4169 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4170
4171 return CMD_SUCCESS;
4172}
4173
736b68f3 4174DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4175 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4176{
4177 VTY_DECLVAR_CONTEXT(bgp, bgp);
4178
4179 bgp_shutdown_enable(bgp, NULL);
4180
4181 return CMD_SUCCESS;
4182}
8389c83a 4183
736b68f3 4184DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4185 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4186{
4187 VTY_DECLVAR_CONTEXT(bgp, bgp);
4188
4189 bgp_shutdown_disable(bgp);
4190
4191 return CMD_SUCCESS;
4192}
4193
9ddf4b81 4194ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4195 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4196 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4197 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4198
718e3744 4199DEFUN (neighbor_remote_as,
4200 neighbor_remote_as_cmd,
3a2d747c 4201 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 4202 NEIGHBOR_STR
4203 NEIGHBOR_ADDR_STR2
4204 "Specify a BGP neighbor\n"
d7fa34c1 4205 AS_STR
3a2d747c
QY
4206 "Internal BGP peer\n"
4207 "External BGP peer\n")
718e3744 4208{
d62a17ae 4209 int idx_peer = 1;
4210 int idx_remote_as = 3;
4211 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4212 argv[idx_remote_as]->arg, AFI_IP,
4213 SAFI_UNICAST);
4214}
4215
4216static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4217 afi_t afi, safi_t safi, int v6only,
4218 const char *peer_group_name,
4219 const char *as_str)
4220{
4221 VTY_DECLVAR_CONTEXT(bgp, bgp);
4222 as_t as = 0;
4223 int as_type = AS_UNSPECIFIED;
4224 struct peer *peer;
4225 struct peer_group *group;
4226 int ret = 0;
4227 union sockunion su;
4228
4229 group = peer_group_lookup(bgp, conf_if);
4230
4231 if (group) {
4232 vty_out(vty, "%% Name conflict with peer-group \n");
4233 return CMD_WARNING_CONFIG_FAILED;
4234 }
4235
4236 if (as_str) {
4237 if (as_str[0] == 'i') {
4238 as_type = AS_INTERNAL;
4239 } else if (as_str[0] == 'e') {
4240 as_type = AS_EXTERNAL;
4241 } else {
4242 /* Get AS number. */
4243 as = strtoul(as_str, NULL, 10);
4244 as_type = AS_SPECIFIED;
4245 }
4246 }
4247
4248 peer = peer_lookup_by_conf_if(bgp, conf_if);
4249 if (peer) {
4250 if (as_str)
cc4d4ce8 4251 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 4252 afi, safi);
4253 } else {
892fedb6 4254 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 4255 && afi == AFI_IP && safi == SAFI_UNICAST)
4256 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4257 as_type, 0, 0, NULL);
4258 else
4259 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4260 as_type, afi, safi, NULL);
4261
4262 if (!peer) {
4263 vty_out(vty, "%% BGP failed to create peer\n");
4264 return CMD_WARNING_CONFIG_FAILED;
4265 }
4266
4267 if (v6only)
527de3dc 4268 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4269
4270 /* Request zebra to initiate IPv6 RAs on this interface. We do
4271 * this
4272 * any unnumbered peer in order to not worry about run-time
4273 * transitions
4274 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4275 * address
4276 * gets deleted later etc.)
4277 */
4278 if (peer->ifp)
4279 bgp_zebra_initiate_radv(bgp, peer);
4280 }
4281
4282 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4283 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4284 if (v6only)
527de3dc 4285 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4286 else
527de3dc 4287 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4288
4289 /* v6only flag changed. Reset bgp seesion */
4290 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4291 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4292 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4293 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4294 } else
4295 bgp_session_reset(peer);
4296 }
4297
9fb964de
PM
4298 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4299 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4300 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4301 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4302 }
d62a17ae 4303
4304 if (peer_group_name) {
4305 group = peer_group_lookup(bgp, peer_group_name);
4306 if (!group) {
4307 vty_out(vty, "%% Configure the peer-group first\n");
4308 return CMD_WARNING_CONFIG_FAILED;
4309 }
4310
4311 ret = peer_group_bind(bgp, &su, peer, group, &as);
4312 }
4313
4314 return bgp_vty_return(vty, ret);
a80beece
DS
4315}
4316
4c48cf63
DW
4317DEFUN (neighbor_interface_config,
4318 neighbor_interface_config_cmd,
d7b9898c 4319 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
4320 NEIGHBOR_STR
4321 "Interface name or neighbor tag\n"
31500417
DW
4322 "Enable BGP on interface\n"
4323 "Member of the peer-group\n"
16cedbb0 4324 "Peer-group name\n")
4c48cf63 4325{
d62a17ae 4326 int idx_word = 1;
4327 int idx_peer_group_word = 4;
31500417 4328
d62a17ae 4329 if (argc > idx_peer_group_word)
4330 return peer_conf_interface_get(
4331 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
4332 argv[idx_peer_group_word]->arg, NULL);
4333 else
4334 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4335 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
4336}
4337
4c48cf63
DW
4338DEFUN (neighbor_interface_config_v6only,
4339 neighbor_interface_config_v6only_cmd,
d7b9898c 4340 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
4341 NEIGHBOR_STR
4342 "Interface name or neighbor tag\n"
4343 "Enable BGP on interface\n"
31500417
DW
4344 "Enable BGP with v6 link-local only\n"
4345 "Member of the peer-group\n"
16cedbb0 4346 "Peer-group name\n")
4c48cf63 4347{
d62a17ae 4348 int idx_word = 1;
4349 int idx_peer_group_word = 5;
31500417 4350
d62a17ae 4351 if (argc > idx_peer_group_word)
4352 return peer_conf_interface_get(
4353 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
4354 argv[idx_peer_group_word]->arg, NULL);
31500417 4355
d62a17ae 4356 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4357 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
4358}
4359
a80beece 4360
b3a39dc5
DD
4361DEFUN (neighbor_interface_config_remote_as,
4362 neighbor_interface_config_remote_as_cmd,
3a2d747c 4363 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
4364 NEIGHBOR_STR
4365 "Interface name or neighbor tag\n"
4366 "Enable BGP on interface\n"
3a2d747c 4367 "Specify a BGP neighbor\n"
d7fa34c1 4368 AS_STR
3a2d747c
QY
4369 "Internal BGP peer\n"
4370 "External BGP peer\n")
b3a39dc5 4371{
d62a17ae 4372 int idx_word = 1;
4373 int idx_remote_as = 4;
4374 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4375 SAFI_UNICAST, 0, NULL,
4376 argv[idx_remote_as]->arg);
b3a39dc5
DD
4377}
4378
4379DEFUN (neighbor_interface_v6only_config_remote_as,
4380 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 4381 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
4382 NEIGHBOR_STR
4383 "Interface name or neighbor tag\n"
3a2d747c 4384 "Enable BGP with v6 link-local only\n"
b3a39dc5 4385 "Enable BGP on interface\n"
3a2d747c 4386 "Specify a BGP neighbor\n"
d7fa34c1 4387 AS_STR
3a2d747c
QY
4388 "Internal BGP peer\n"
4389 "External BGP peer\n")
b3a39dc5 4390{
d62a17ae 4391 int idx_word = 1;
4392 int idx_remote_as = 5;
4393 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4394 SAFI_UNICAST, 1, NULL,
4395 argv[idx_remote_as]->arg);
b3a39dc5
DD
4396}
4397
718e3744 4398DEFUN (neighbor_peer_group,
4399 neighbor_peer_group_cmd,
4400 "neighbor WORD peer-group",
4401 NEIGHBOR_STR
a80beece 4402 "Interface name or neighbor tag\n"
718e3744 4403 "Configure peer-group\n")
4404{
d62a17ae 4405 VTY_DECLVAR_CONTEXT(bgp, bgp);
4406 int idx_word = 1;
4407 struct peer *peer;
4408 struct peer_group *group;
718e3744 4409
d62a17ae 4410 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4411 if (peer) {
4412 vty_out(vty, "%% Name conflict with interface: \n");
4413 return CMD_WARNING_CONFIG_FAILED;
4414 }
718e3744 4415
d62a17ae 4416 group = peer_group_get(bgp, argv[idx_word]->arg);
4417 if (!group) {
4418 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4419 return CMD_WARNING_CONFIG_FAILED;
4420 }
718e3744 4421
d62a17ae 4422 return CMD_SUCCESS;
718e3744 4423}
4424
4425DEFUN (no_neighbor,
4426 no_neighbor_cmd,
dab8cd00 4427 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 4428 NO_STR
4429 NEIGHBOR_STR
3a2d747c
QY
4430 NEIGHBOR_ADDR_STR2
4431 "Specify a BGP neighbor\n"
4432 AS_STR
4433 "Internal BGP peer\n"
4434 "External BGP peer\n")
718e3744 4435{
d62a17ae 4436 VTY_DECLVAR_CONTEXT(bgp, bgp);
4437 int idx_peer = 2;
4438 int ret;
4439 union sockunion su;
4440 struct peer_group *group;
4441 struct peer *peer;
4442 struct peer *other;
4443
4444 ret = str2sockunion(argv[idx_peer]->arg, &su);
4445 if (ret < 0) {
4446 /* look up for neighbor by interface name config. */
4447 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4448 if (peer) {
4449 /* Request zebra to terminate IPv6 RAs on this
4450 * interface. */
4451 if (peer->ifp)
4452 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 4453 peer_notify_unconfig(peer);
d62a17ae 4454 peer_delete(peer);
4455 return CMD_SUCCESS;
4456 }
f14e6fdb 4457
d62a17ae 4458 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4e2786df
DA
4459 if (group) {
4460 peer_group_notify_unconfig(group);
d62a17ae 4461 peer_group_delete(group);
4e2786df 4462 } else {
d62a17ae 4463 vty_out(vty, "%% Create the peer-group first\n");
4464 return CMD_WARNING_CONFIG_FAILED;
4465 }
4466 } else {
4467 peer = peer_lookup(bgp, &su);
4468 if (peer) {
4469 if (peer_dynamic_neighbor(peer)) {
4470 vty_out(vty,
4471 "%% Operation not allowed on a dynamic neighbor\n");
4472 return CMD_WARNING_CONFIG_FAILED;
4473 }
4474
4475 other = peer->doppelganger;
b3a3290e
DS
4476
4477 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4478 bgp_zebra_terminate_radv(peer->bgp, peer);
4479
4e2786df 4480 peer_notify_unconfig(peer);
d62a17ae 4481 peer_delete(peer);
4e2786df
DA
4482 if (other && other->status != Deleted) {
4483 peer_notify_unconfig(other);
d62a17ae 4484 peer_delete(other);
4e2786df 4485 }
d62a17ae 4486 }
1ff9a340 4487 }
718e3744 4488
d62a17ae 4489 return CMD_SUCCESS;
718e3744 4490}
4491
a80beece
DS
4492DEFUN (no_neighbor_interface_config,
4493 no_neighbor_interface_config_cmd,
d7b9898c 4494 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
4495 NO_STR
4496 NEIGHBOR_STR
4497 "Interface name\n"
31500417
DW
4498 "Configure BGP on interface\n"
4499 "Enable BGP with v6 link-local only\n"
4500 "Member of the peer-group\n"
16cedbb0 4501 "Peer-group name\n"
3a2d747c
QY
4502 "Specify a BGP neighbor\n"
4503 AS_STR
4504 "Internal BGP peer\n"
4505 "External BGP peer\n")
a80beece 4506{
d62a17ae 4507 VTY_DECLVAR_CONTEXT(bgp, bgp);
4508 int idx_word = 2;
4509 struct peer *peer;
4510
4511 /* look up for neighbor by interface name config. */
4512 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4513 if (peer) {
4514 /* Request zebra to terminate IPv6 RAs on this interface. */
4515 if (peer->ifp)
4516 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 4517 peer_notify_unconfig(peer);
d62a17ae 4518 peer_delete(peer);
4519 } else {
4520 vty_out(vty, "%% Create the bgp interface first\n");
4521 return CMD_WARNING_CONFIG_FAILED;
4522 }
4523 return CMD_SUCCESS;
a80beece
DS
4524}
4525
718e3744 4526DEFUN (no_neighbor_peer_group,
4527 no_neighbor_peer_group_cmd,
4528 "no neighbor WORD peer-group",
4529 NO_STR
4530 NEIGHBOR_STR
4531 "Neighbor tag\n"
4532 "Configure peer-group\n")
4533{
d62a17ae 4534 VTY_DECLVAR_CONTEXT(bgp, bgp);
4535 int idx_word = 2;
4536 struct peer_group *group;
718e3744 4537
d62a17ae 4538 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4e2786df
DA
4539 if (group) {
4540 peer_group_notify_unconfig(group);
d62a17ae 4541 peer_group_delete(group);
4e2786df 4542 } else {
d62a17ae 4543 vty_out(vty, "%% Create the peer-group first\n");
4544 return CMD_WARNING_CONFIG_FAILED;
4545 }
4546 return CMD_SUCCESS;
718e3744 4547}
4548
a80beece
DS
4549DEFUN (no_neighbor_interface_peer_group_remote_as,
4550 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 4551 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 4552 NO_STR
4553 NEIGHBOR_STR
a80beece 4554 "Interface name or neighbor tag\n"
718e3744 4555 "Specify a BGP neighbor\n"
3a2d747c
QY
4556 AS_STR
4557 "Internal BGP peer\n"
4558 "External BGP peer\n")
718e3744 4559{
d62a17ae 4560 VTY_DECLVAR_CONTEXT(bgp, bgp);
4561 int idx_word = 2;
4562 struct peer_group *group;
4563 struct peer *peer;
4564
4565 /* look up for neighbor by interface name config. */
4566 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4567 if (peer) {
390485fd 4568 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 4569 return CMD_SUCCESS;
4570 }
4571
4572 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4573 if (group)
4574 peer_group_remote_as_delete(group);
4575 else {
4576 vty_out(vty, "%% Create the peer-group or interface first\n");
4577 return CMD_WARNING_CONFIG_FAILED;
4578 }
4579 return CMD_SUCCESS;
718e3744 4580}
6b0655a2 4581
718e3744 4582DEFUN (neighbor_local_as,
4583 neighbor_local_as_cmd,
9ccf14f7 4584 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 4585 NEIGHBOR_STR
4586 NEIGHBOR_ADDR_STR2
4587 "Specify a local-as number\n"
4588 "AS number used as local AS\n")
4589{
d62a17ae 4590 int idx_peer = 1;
4591 int idx_number = 3;
4592 struct peer *peer;
4593 int ret;
4594 as_t as;
718e3744 4595
d62a17ae 4596 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4597 if (!peer)
4598 return CMD_WARNING_CONFIG_FAILED;
718e3744 4599
d62a17ae 4600 as = strtoul(argv[idx_number]->arg, NULL, 10);
4601 ret = peer_local_as_set(peer, as, 0, 0);
4602 return bgp_vty_return(vty, ret);
718e3744 4603}
4604
4605DEFUN (neighbor_local_as_no_prepend,
4606 neighbor_local_as_no_prepend_cmd,
9ccf14f7 4607 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 4608 NEIGHBOR_STR
4609 NEIGHBOR_ADDR_STR2
4610 "Specify a local-as number\n"
4611 "AS number used as local AS\n"
4612 "Do not prepend local-as to updates from ebgp peers\n")
4613{
d62a17ae 4614 int idx_peer = 1;
4615 int idx_number = 3;
4616 struct peer *peer;
4617 int ret;
4618 as_t as;
718e3744 4619
d62a17ae 4620 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4621 if (!peer)
4622 return CMD_WARNING_CONFIG_FAILED;
718e3744 4623
d62a17ae 4624 as = strtoul(argv[idx_number]->arg, NULL, 10);
4625 ret = peer_local_as_set(peer, as, 1, 0);
4626 return bgp_vty_return(vty, ret);
718e3744 4627}
4628
9d3f9705
AC
4629DEFUN (neighbor_local_as_no_prepend_replace_as,
4630 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 4631 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
4632 NEIGHBOR_STR
4633 NEIGHBOR_ADDR_STR2
4634 "Specify a local-as number\n"
4635 "AS number used as local AS\n"
4636 "Do not prepend local-as to updates from ebgp peers\n"
4637 "Do not prepend local-as to updates from ibgp peers\n")
4638{
d62a17ae 4639 int idx_peer = 1;
4640 int idx_number = 3;
4641 struct peer *peer;
4642 int ret;
4643 as_t as;
9d3f9705 4644
d62a17ae 4645 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4646 if (!peer)
4647 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4648
d62a17ae 4649 as = strtoul(argv[idx_number]->arg, NULL, 10);
4650 ret = peer_local_as_set(peer, as, 1, 1);
4651 return bgp_vty_return(vty, ret);
9d3f9705
AC
4652}
4653
718e3744 4654DEFUN (no_neighbor_local_as,
4655 no_neighbor_local_as_cmd,
a636c635 4656 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 4657 NO_STR
4658 NEIGHBOR_STR
4659 NEIGHBOR_ADDR_STR2
a636c635
DW
4660 "Specify a local-as number\n"
4661 "AS number used as local AS\n"
4662 "Do not prepend local-as to updates from ebgp peers\n"
4663 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4664{
d62a17ae 4665 int idx_peer = 2;
4666 struct peer *peer;
4667 int ret;
718e3744 4668
d62a17ae 4669 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4670 if (!peer)
4671 return CMD_WARNING_CONFIG_FAILED;
718e3744 4672
d62a17ae 4673 ret = peer_local_as_unset(peer);
4674 return bgp_vty_return(vty, ret);
718e3744 4675}
4676
718e3744 4677
3f9c7369
DS
4678DEFUN (neighbor_solo,
4679 neighbor_solo_cmd,
9ccf14f7 4680 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4681 NEIGHBOR_STR
4682 NEIGHBOR_ADDR_STR2
4683 "Solo peer - part of its own update group\n")
4684{
d62a17ae 4685 int idx_peer = 1;
4686 struct peer *peer;
4687 int ret;
3f9c7369 4688
d62a17ae 4689 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4690 if (!peer)
4691 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4692
d62a17ae 4693 ret = update_group_adjust_soloness(peer, 1);
4694 return bgp_vty_return(vty, ret);
3f9c7369
DS
4695}
4696
4697DEFUN (no_neighbor_solo,
4698 no_neighbor_solo_cmd,
9ccf14f7 4699 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4700 NO_STR
4701 NEIGHBOR_STR
4702 NEIGHBOR_ADDR_STR2
4703 "Solo peer - part of its own update group\n")
4704{
d62a17ae 4705 int idx_peer = 2;
4706 struct peer *peer;
4707 int ret;
3f9c7369 4708
d62a17ae 4709 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4710 if (!peer)
4711 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4712
d62a17ae 4713 ret = update_group_adjust_soloness(peer, 0);
4714 return bgp_vty_return(vty, ret);
3f9c7369
DS
4715}
4716
0df7c91f
PJ
4717DEFUN (neighbor_password,
4718 neighbor_password_cmd,
9ccf14f7 4719 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
4720 NEIGHBOR_STR
4721 NEIGHBOR_ADDR_STR2
4722 "Set a password\n"
4723 "The password\n")
4724{
d62a17ae 4725 int idx_peer = 1;
4726 int idx_line = 3;
4727 struct peer *peer;
4728 int ret;
0df7c91f 4729
d62a17ae 4730 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4731 if (!peer)
4732 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4733
d62a17ae 4734 ret = peer_password_set(peer, argv[idx_line]->arg);
4735 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4736}
4737
4738DEFUN (no_neighbor_password,
4739 no_neighbor_password_cmd,
a636c635 4740 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
4741 NO_STR
4742 NEIGHBOR_STR
4743 NEIGHBOR_ADDR_STR2
16cedbb0
QY
4744 "Set a password\n"
4745 "The password\n")
0df7c91f 4746{
d62a17ae 4747 int idx_peer = 2;
4748 struct peer *peer;
4749 int ret;
0df7c91f 4750
d62a17ae 4751 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4752 if (!peer)
4753 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4754
d62a17ae 4755 ret = peer_password_unset(peer);
4756 return bgp_vty_return(vty, ret);
0df7c91f 4757}
6b0655a2 4758
718e3744 4759DEFUN (neighbor_activate,
4760 neighbor_activate_cmd,
9ccf14f7 4761 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4762 NEIGHBOR_STR
4763 NEIGHBOR_ADDR_STR2
4764 "Enable the Address Family for this Neighbor\n")
4765{
d62a17ae 4766 int idx_peer = 1;
4767 int ret;
4768 struct peer *peer;
718e3744 4769
d62a17ae 4770 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4771 if (!peer)
4772 return CMD_WARNING_CONFIG_FAILED;
718e3744 4773
d62a17ae 4774 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4775 return bgp_vty_return(vty, ret);
718e3744 4776}
4777
d62a17ae 4778ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4779 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4780 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4781 "Enable the Address Family for this Neighbor\n")
596c17ba 4782
718e3744 4783DEFUN (no_neighbor_activate,
4784 no_neighbor_activate_cmd,
9ccf14f7 4785 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4786 NO_STR
4787 NEIGHBOR_STR
4788 NEIGHBOR_ADDR_STR2
4789 "Enable the Address Family for this Neighbor\n")
4790{
d62a17ae 4791 int idx_peer = 2;
4792 int ret;
4793 struct peer *peer;
718e3744 4794
d62a17ae 4795 /* Lookup peer. */
4796 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4797 if (!peer)
4798 return CMD_WARNING_CONFIG_FAILED;
718e3744 4799
d62a17ae 4800 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4801 return bgp_vty_return(vty, ret);
718e3744 4802}
6b0655a2 4803
d62a17ae 4804ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4805 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4806 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4807 "Enable the Address Family for this Neighbor\n")
596c17ba 4808
718e3744 4809DEFUN (neighbor_set_peer_group,
4810 neighbor_set_peer_group_cmd,
d7b9898c 4811 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4812 NEIGHBOR_STR
a80beece 4813 NEIGHBOR_ADDR_STR2
718e3744 4814 "Member of the peer-group\n"
16cedbb0 4815 "Peer-group name\n")
718e3744 4816{
d62a17ae 4817 VTY_DECLVAR_CONTEXT(bgp, bgp);
4818 int idx_peer = 1;
4819 int idx_word = 3;
4820 int ret;
4821 as_t as;
4822 union sockunion su;
4823 struct peer *peer;
4824 struct peer_group *group;
4825
d62a17ae 4826 ret = str2sockunion(argv[idx_peer]->arg, &su);
4827 if (ret < 0) {
4828 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4829 if (!peer) {
4830 vty_out(vty, "%% Malformed address or name: %s\n",
4831 argv[idx_peer]->arg);
4832 return CMD_WARNING_CONFIG_FAILED;
4833 }
4834 } else {
4835 if (peer_address_self_check(bgp, &su)) {
4836 vty_out(vty,
4837 "%% Can not configure the local system as neighbor\n");
4838 return CMD_WARNING_CONFIG_FAILED;
4839 }
4840
4841 /* Disallow for dynamic neighbor. */
4842 peer = peer_lookup(bgp, &su);
4843 if (peer && peer_dynamic_neighbor(peer)) {
4844 vty_out(vty,
4845 "%% Operation not allowed on a dynamic neighbor\n");
4846 return CMD_WARNING_CONFIG_FAILED;
4847 }
4848 }
4849
4850 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4851 if (!group) {
4852 vty_out(vty, "%% Configure the peer-group first\n");
4853 return CMD_WARNING_CONFIG_FAILED;
4854 }
4855
4856 ret = peer_group_bind(bgp, &su, peer, group, &as);
4857
4858 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4859 vty_out(vty,
4860 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4861 as);
4862 return CMD_WARNING_CONFIG_FAILED;
4863 }
4864
4865 return bgp_vty_return(vty, ret);
4866}
4867
4868ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4869 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4870 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4871 "Member of the peer-group\n"
4872 "Peer-group name\n")
596c17ba 4873
718e3744 4874DEFUN (no_neighbor_set_peer_group,
4875 no_neighbor_set_peer_group_cmd,
d7b9898c 4876 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4877 NO_STR
4878 NEIGHBOR_STR
a80beece 4879 NEIGHBOR_ADDR_STR2
718e3744 4880 "Member of the peer-group\n"
16cedbb0 4881 "Peer-group name\n")
718e3744 4882{
d62a17ae 4883 VTY_DECLVAR_CONTEXT(bgp, bgp);
4884 int idx_peer = 2;
4885 int idx_word = 4;
4886 int ret;
4887 struct peer *peer;
4888 struct peer_group *group;
4889
4890 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4891 if (!peer)
4892 return CMD_WARNING_CONFIG_FAILED;
4893
4894 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4895 if (!group) {
4896 vty_out(vty, "%% Configure the peer-group first\n");
4897 return CMD_WARNING_CONFIG_FAILED;
4898 }
718e3744 4899
b3a3290e
DS
4900 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4901 bgp_zebra_terminate_radv(peer->bgp, peer);
4902
4e2786df 4903 peer_notify_unconfig(peer);
827ed707 4904 ret = peer_delete(peer);
718e3744 4905
d62a17ae 4906 return bgp_vty_return(vty, ret);
718e3744 4907}
6b0655a2 4908
d62a17ae 4909ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4910 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4911 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4912 "Member of the peer-group\n"
4913 "Peer-group name\n")
596c17ba 4914
d62a17ae 4915static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4916 uint32_t flag, int set)
718e3744 4917{
d62a17ae 4918 int ret;
4919 struct peer *peer;
718e3744 4920
d62a17ae 4921 peer = peer_and_group_lookup_vty(vty, ip_str);
4922 if (!peer)
4923 return CMD_WARNING_CONFIG_FAILED;
718e3744 4924
7ebe625c
QY
4925 /*
4926 * If 'neighbor <interface>', then this is for directly connected peers,
4927 * we should not accept disable-connected-check.
4928 */
4929 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4930 vty_out(vty,
3efd0893 4931 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
4932 ip_str);
4933 return CMD_WARNING_CONFIG_FAILED;
4934 }
4935
d62a17ae 4936 if (!set && flag == PEER_FLAG_SHUTDOWN)
4937 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4938
d62a17ae 4939 if (set)
4940 ret = peer_flag_set(peer, flag);
4941 else
4942 ret = peer_flag_unset(peer, flag);
718e3744 4943
d62a17ae 4944 return bgp_vty_return(vty, ret);
718e3744 4945}
4946
47cbc09b 4947static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4948{
d62a17ae 4949 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4950}
4951
d62a17ae 4952static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4953 uint32_t flag)
718e3744 4954{
d62a17ae 4955 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4956}
4957
4958/* neighbor passive. */
4959DEFUN (neighbor_passive,
4960 neighbor_passive_cmd,
9ccf14f7 4961 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4962 NEIGHBOR_STR
4963 NEIGHBOR_ADDR_STR2
4964 "Don't send open messages to this neighbor\n")
4965{
d62a17ae 4966 int idx_peer = 1;
4967 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4968}
4969
4970DEFUN (no_neighbor_passive,
4971 no_neighbor_passive_cmd,
9ccf14f7 4972 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4973 NO_STR
4974 NEIGHBOR_STR
4975 NEIGHBOR_ADDR_STR2
4976 "Don't send open messages to this neighbor\n")
4977{
d62a17ae 4978 int idx_peer = 2;
4979 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4980}
6b0655a2 4981
718e3744 4982/* neighbor shutdown. */
73d70fa6
DL
4983DEFUN (neighbor_shutdown_msg,
4984 neighbor_shutdown_msg_cmd,
4985 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 4986 NEIGHBOR_STR
4987 NEIGHBOR_ADDR_STR2
73d70fa6 4988 "Administratively shut down this neighbor\n"
70335e0a 4989 "Add a shutdown message (RFC 8203)\n"
73d70fa6 4990 "Shutdown message\n")
718e3744 4991{
d62a17ae 4992 int idx_peer = 1;
73d70fa6 4993
d62a17ae 4994 if (argc >= 5) {
4995 struct peer *peer =
4996 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4997 char *message;
73d70fa6 4998
d62a17ae 4999 if (!peer)
5000 return CMD_WARNING_CONFIG_FAILED;
5001 message = argv_concat(argv, argc, 4);
5002 peer_tx_shutdown_message_set(peer, message);
5003 XFREE(MTYPE_TMP, message);
5004 }
73d70fa6 5005
d62a17ae 5006 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5007}
5008
d62a17ae 5009ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5010 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5011 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5012 "Administratively shut down this neighbor\n")
73d70fa6
DL
5013
5014DEFUN (no_neighbor_shutdown_msg,
5015 no_neighbor_shutdown_msg_cmd,
5016 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5017 NO_STR
5018 NEIGHBOR_STR
5019 NEIGHBOR_ADDR_STR2
5020 "Administratively shut down this neighbor\n"
70335e0a 5021 "Remove a shutdown message (RFC 8203)\n"
73d70fa6 5022 "Shutdown message\n")
718e3744 5023{
d62a17ae 5024 int idx_peer = 2;
73d70fa6 5025
d62a17ae 5026 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5027 PEER_FLAG_SHUTDOWN);
718e3744 5028}
6b0655a2 5029
d62a17ae 5030ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5031 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5032 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5033 "Administratively shut down this neighbor\n")
73d70fa6 5034
8336c896
DA
5035DEFUN(neighbor_shutdown_rtt,
5036 neighbor_shutdown_rtt_cmd,
5037 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5038 NEIGHBOR_STR
5039 NEIGHBOR_ADDR_STR2
5040 "Administratively shut down this neighbor\n"
5041 "Shutdown if round-trip-time is higher than expected\n"
5042 "Round-trip-time in milliseconds\n"
5043 "Specify the number of keepalives before shutdown\n"
5044 "The number of keepalives with higher RTT to shutdown\n")
5045{
5046 int idx_peer = 1;
5047 int idx_rtt = 4;
5048 int idx_count = 0;
5049 struct peer *peer;
5050
5051 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5052
5053 if (!peer)
5054 return CMD_WARNING_CONFIG_FAILED;
5055
5056 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5057
5058 if (argv_find(argv, argc, "count", &idx_count))
5059 peer->rtt_keepalive_conf =
5060 strtol(argv[idx_count + 1]->arg, NULL, 10);
5061
5062 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5063 PEER_FLAG_RTT_SHUTDOWN);
5064}
5065
5066DEFUN(no_neighbor_shutdown_rtt,
5067 no_neighbor_shutdown_rtt_cmd,
5068 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5069 NO_STR
5070 NEIGHBOR_STR
5071 NEIGHBOR_ADDR_STR2
5072 "Administratively shut down this neighbor\n"
5073 "Shutdown if round-trip-time is higher than expected\n"
5074 "Round-trip-time in milliseconds\n"
5075 "Specify the number of keepalives before shutdown\n"
5076 "The number of keepalives with higher RTT to shutdown\n")
5077{
5078 int idx_peer = 2;
5079 struct peer *peer;
5080
5081 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5082
5083 if (!peer)
5084 return CMD_WARNING_CONFIG_FAILED;
5085
5086 peer->rtt_expected = 0;
5087 peer->rtt_keepalive_conf = 1;
5088
5089 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5090 PEER_FLAG_RTT_SHUTDOWN);
5091}
5092
718e3744 5093/* neighbor capability dynamic. */
5094DEFUN (neighbor_capability_dynamic,
5095 neighbor_capability_dynamic_cmd,
9ccf14f7 5096 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 5097 NEIGHBOR_STR
5098 NEIGHBOR_ADDR_STR2
5099 "Advertise capability to the peer\n"
5100 "Advertise dynamic capability to this neighbor\n")
5101{
d62a17ae 5102 int idx_peer = 1;
5103 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5104 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5105}
5106
5107DEFUN (no_neighbor_capability_dynamic,
5108 no_neighbor_capability_dynamic_cmd,
9ccf14f7 5109 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 5110 NO_STR
5111 NEIGHBOR_STR
5112 NEIGHBOR_ADDR_STR2
5113 "Advertise capability to the peer\n"
5114 "Advertise dynamic capability to this neighbor\n")
5115{
d62a17ae 5116 int idx_peer = 2;
5117 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5118 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5119}
6b0655a2 5120
718e3744 5121/* neighbor dont-capability-negotiate */
5122DEFUN (neighbor_dont_capability_negotiate,
5123 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5124 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5125 NEIGHBOR_STR
5126 NEIGHBOR_ADDR_STR2
5127 "Do not perform capability negotiation\n")
5128{
d62a17ae 5129 int idx_peer = 1;
5130 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5131 PEER_FLAG_DONT_CAPABILITY);
718e3744 5132}
5133
5134DEFUN (no_neighbor_dont_capability_negotiate,
5135 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5136 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5137 NO_STR
5138 NEIGHBOR_STR
5139 NEIGHBOR_ADDR_STR2
5140 "Do not perform capability negotiation\n")
5141{
d62a17ae 5142 int idx_peer = 2;
5143 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5144 PEER_FLAG_DONT_CAPABILITY);
718e3744 5145}
6b0655a2 5146
8a92a8a0
DS
5147/* neighbor capability extended next hop encoding */
5148DEFUN (neighbor_capability_enhe,
5149 neighbor_capability_enhe_cmd,
9ccf14f7 5150 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
5151 NEIGHBOR_STR
5152 NEIGHBOR_ADDR_STR2
5153 "Advertise capability to the peer\n"
5154 "Advertise extended next-hop capability to the peer\n")
5155{
d62a17ae 5156 int idx_peer = 1;
5157 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5158 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5159}
5160
5161DEFUN (no_neighbor_capability_enhe,
5162 no_neighbor_capability_enhe_cmd,
9ccf14f7 5163 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
5164 NO_STR
5165 NEIGHBOR_STR
5166 NEIGHBOR_ADDR_STR2
5167 "Advertise capability to the peer\n"
5168 "Advertise extended next-hop capability to the peer\n")
5169{
d62a17ae 5170 int idx_peer = 2;
5171 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5172 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5173}
5174
d62a17ae 5175static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5176 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5177 int set)
718e3744 5178{
d62a17ae 5179 int ret;
5180 struct peer *peer;
718e3744 5181
d62a17ae 5182 peer = peer_and_group_lookup_vty(vty, peer_str);
5183 if (!peer)
5184 return CMD_WARNING_CONFIG_FAILED;
718e3744 5185
d62a17ae 5186 if (set)
5187 ret = peer_af_flag_set(peer, afi, safi, flag);
5188 else
5189 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5190
d62a17ae 5191 return bgp_vty_return(vty, ret);
718e3744 5192}
5193
d62a17ae 5194static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5195 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5196{
d62a17ae 5197 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5198}
5199
d62a17ae 5200static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5201 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5202{
d62a17ae 5203 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5204}
6b0655a2 5205
718e3744 5206/* neighbor capability orf prefix-list. */
5207DEFUN (neighbor_capability_orf_prefix,
5208 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5209 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5210 NEIGHBOR_STR
5211 NEIGHBOR_ADDR_STR2
5212 "Advertise capability to the peer\n"
5213 "Advertise ORF capability to the peer\n"
5214 "Advertise prefixlist ORF capability to this neighbor\n"
5215 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5216 "Capability to RECEIVE the ORF from this neighbor\n"
5217 "Capability to SEND the ORF to this neighbor\n")
5218{
d62a17ae 5219 int idx_send_recv = 5;
db45f64d
DS
5220 char *peer_str = argv[1]->arg;
5221 struct peer *peer;
5222 afi_t afi = bgp_node_afi(vty);
5223 safi_t safi = bgp_node_safi(vty);
d62a17ae 5224
db45f64d
DS
5225 peer = peer_and_group_lookup_vty(vty, peer_str);
5226 if (!peer)
d62a17ae 5227 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5228
db45f64d
DS
5229 if (strmatch(argv[idx_send_recv]->text, "send"))
5230 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5231 PEER_FLAG_ORF_PREFIX_SM);
5232
5233 if (strmatch(argv[idx_send_recv]->text, "receive"))
5234 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5235 PEER_FLAG_ORF_PREFIX_RM);
5236
5237 if (strmatch(argv[idx_send_recv]->text, "both"))
5238 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5239 PEER_FLAG_ORF_PREFIX_SM)
5240 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5241 PEER_FLAG_ORF_PREFIX_RM);
5242
5243 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5244}
5245
5246ALIAS_HIDDEN(
5247 neighbor_capability_orf_prefix,
5248 neighbor_capability_orf_prefix_hidden_cmd,
5249 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5250 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5251 "Advertise capability to the peer\n"
5252 "Advertise ORF capability to the peer\n"
5253 "Advertise prefixlist ORF capability to this neighbor\n"
5254 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5255 "Capability to RECEIVE the ORF from this neighbor\n"
5256 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5257
718e3744 5258DEFUN (no_neighbor_capability_orf_prefix,
5259 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5260 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5261 NO_STR
5262 NEIGHBOR_STR
5263 NEIGHBOR_ADDR_STR2
5264 "Advertise capability to the peer\n"
5265 "Advertise ORF capability to the peer\n"
5266 "Advertise prefixlist ORF capability to this neighbor\n"
5267 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5268 "Capability to RECEIVE the ORF from this neighbor\n"
5269 "Capability to SEND the ORF to this neighbor\n")
5270{
d62a17ae 5271 int idx_send_recv = 6;
db45f64d
DS
5272 char *peer_str = argv[2]->arg;
5273 struct peer *peer;
5274 afi_t afi = bgp_node_afi(vty);
5275 safi_t safi = bgp_node_safi(vty);
d62a17ae 5276
db45f64d
DS
5277 peer = peer_and_group_lookup_vty(vty, peer_str);
5278 if (!peer)
d62a17ae 5279 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5280
db45f64d
DS
5281 if (strmatch(argv[idx_send_recv]->text, "send"))
5282 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5283 PEER_FLAG_ORF_PREFIX_SM);
5284
5285 if (strmatch(argv[idx_send_recv]->text, "receive"))
5286 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5287 PEER_FLAG_ORF_PREFIX_RM);
5288
5289 if (strmatch(argv[idx_send_recv]->text, "both"))
5290 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5291 PEER_FLAG_ORF_PREFIX_SM)
5292 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5293 PEER_FLAG_ORF_PREFIX_RM);
5294
5295 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5296}
5297
5298ALIAS_HIDDEN(
5299 no_neighbor_capability_orf_prefix,
5300 no_neighbor_capability_orf_prefix_hidden_cmd,
5301 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5302 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5303 "Advertise capability to the peer\n"
5304 "Advertise ORF capability to the peer\n"
5305 "Advertise prefixlist ORF capability to this neighbor\n"
5306 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5307 "Capability to RECEIVE the ORF from this neighbor\n"
5308 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5309
718e3744 5310/* neighbor next-hop-self. */
5311DEFUN (neighbor_nexthop_self,
5312 neighbor_nexthop_self_cmd,
9ccf14f7 5313 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 5314 NEIGHBOR_STR
5315 NEIGHBOR_ADDR_STR2
a538debe 5316 "Disable the next hop calculation for this neighbor\n")
718e3744 5317{
d62a17ae 5318 int idx_peer = 1;
5319 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5320 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5321}
9e7a53c1 5322
d62a17ae 5323ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5324 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5325 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5326 "Disable the next hop calculation for this neighbor\n")
596c17ba 5327
a538debe
DS
5328/* neighbor next-hop-self. */
5329DEFUN (neighbor_nexthop_self_force,
5330 neighbor_nexthop_self_force_cmd,
9ccf14f7 5331 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
5332 NEIGHBOR_STR
5333 NEIGHBOR_ADDR_STR2
5334 "Disable the next hop calculation for this neighbor\n"
5335 "Set the next hop to self for reflected routes\n")
5336{
d62a17ae 5337 int idx_peer = 1;
5338 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5339 bgp_node_safi(vty),
5340 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5341}
5342
d62a17ae 5343ALIAS_HIDDEN(neighbor_nexthop_self_force,
5344 neighbor_nexthop_self_force_hidden_cmd,
5345 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5346 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5347 "Disable the next hop calculation for this neighbor\n"
5348 "Set the next hop to self for reflected routes\n")
596c17ba 5349
1bc4e531
DA
5350ALIAS_HIDDEN(neighbor_nexthop_self_force,
5351 neighbor_nexthop_self_all_hidden_cmd,
5352 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5354 "Disable the next hop calculation for this neighbor\n"
5355 "Set the next hop to self for reflected routes\n")
5356
718e3744 5357DEFUN (no_neighbor_nexthop_self,
5358 no_neighbor_nexthop_self_cmd,
9ccf14f7 5359 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 5360 NO_STR
5361 NEIGHBOR_STR
5362 NEIGHBOR_ADDR_STR2
a538debe 5363 "Disable the next hop calculation for this neighbor\n")
718e3744 5364{
d62a17ae 5365 int idx_peer = 2;
5366 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5367 bgp_node_afi(vty), bgp_node_safi(vty),
5368 PEER_FLAG_NEXTHOP_SELF);
718e3744 5369}
6b0655a2 5370
d62a17ae 5371ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5372 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5373 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5374 "Disable the next hop calculation for this neighbor\n")
596c17ba 5375
88b8ed8d 5376DEFUN (no_neighbor_nexthop_self_force,
a538debe 5377 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 5378 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
5379 NO_STR
5380 NEIGHBOR_STR
5381 NEIGHBOR_ADDR_STR2
5382 "Disable the next hop calculation for this neighbor\n"
5383 "Set the next hop to self for reflected routes\n")
88b8ed8d 5384{
d62a17ae 5385 int idx_peer = 2;
5386 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5387 bgp_node_afi(vty), bgp_node_safi(vty),
5388 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5389}
a538debe 5390
d62a17ae 5391ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5392 no_neighbor_nexthop_self_force_hidden_cmd,
5393 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5394 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5395 "Disable the next hop calculation for this neighbor\n"
5396 "Set the next hop to self for reflected routes\n")
596c17ba 5397
1bc4e531
DA
5398ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5399 no_neighbor_nexthop_self_all_hidden_cmd,
5400 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5401 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5402 "Disable the next hop calculation for this neighbor\n"
5403 "Set the next hop to self for reflected routes\n")
5404
c7122e14
DS
5405/* neighbor as-override */
5406DEFUN (neighbor_as_override,
5407 neighbor_as_override_cmd,
9ccf14f7 5408 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
5409 NEIGHBOR_STR
5410 NEIGHBOR_ADDR_STR2
5411 "Override ASNs in outbound updates if aspath equals remote-as\n")
5412{
d62a17ae 5413 int idx_peer = 1;
5414 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5415 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5416}
5417
d62a17ae 5418ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5419 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5420 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5421 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5422
c7122e14
DS
5423DEFUN (no_neighbor_as_override,
5424 no_neighbor_as_override_cmd,
9ccf14f7 5425 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
5426 NO_STR
5427 NEIGHBOR_STR
5428 NEIGHBOR_ADDR_STR2
5429 "Override ASNs in outbound updates if aspath equals remote-as\n")
5430{
d62a17ae 5431 int idx_peer = 2;
5432 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5433 bgp_node_afi(vty), bgp_node_safi(vty),
5434 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5435}
5436
d62a17ae 5437ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5438 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5439 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5440 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5441
718e3744 5442/* neighbor remove-private-AS. */
5443DEFUN (neighbor_remove_private_as,
5444 neighbor_remove_private_as_cmd,
9ccf14f7 5445 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 5446 NEIGHBOR_STR
5447 NEIGHBOR_ADDR_STR2
5000f21c 5448 "Remove private ASNs in outbound updates\n")
718e3744 5449{
d62a17ae 5450 int idx_peer = 1;
5451 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5452 bgp_node_safi(vty),
5453 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5454}
5455
d62a17ae 5456ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5457 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5459 "Remove private ASNs in outbound updates\n")
596c17ba 5460
5000f21c
DS
5461DEFUN (neighbor_remove_private_as_all,
5462 neighbor_remove_private_as_all_cmd,
9ccf14f7 5463 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
5464 NEIGHBOR_STR
5465 NEIGHBOR_ADDR_STR2
5466 "Remove private ASNs in outbound updates\n"
efd7904e 5467 "Apply to all AS numbers\n")
5000f21c 5468{
d62a17ae 5469 int idx_peer = 1;
5470 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5471 bgp_node_safi(vty),
5472 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5473}
5474
d62a17ae 5475ALIAS_HIDDEN(neighbor_remove_private_as_all,
5476 neighbor_remove_private_as_all_hidden_cmd,
5477 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5478 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5479 "Remove private ASNs in outbound updates\n"
5480 "Apply to all AS numbers")
596c17ba 5481
5000f21c
DS
5482DEFUN (neighbor_remove_private_as_replace_as,
5483 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 5484 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
5485 NEIGHBOR_STR
5486 NEIGHBOR_ADDR_STR2
5487 "Remove private ASNs in outbound updates\n"
5488 "Replace private ASNs with our ASN in outbound updates\n")
5489{
d62a17ae 5490 int idx_peer = 1;
5491 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5492 bgp_node_safi(vty),
5493 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5494}
5495
d62a17ae 5496ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5497 neighbor_remove_private_as_replace_as_hidden_cmd,
5498 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5499 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5500 "Remove private ASNs in outbound updates\n"
5501 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5502
5000f21c
DS
5503DEFUN (neighbor_remove_private_as_all_replace_as,
5504 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 5505 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
5506 NEIGHBOR_STR
5507 NEIGHBOR_ADDR_STR2
5508 "Remove private ASNs in outbound updates\n"
16cedbb0 5509 "Apply to all AS numbers\n"
5000f21c
DS
5510 "Replace private ASNs with our ASN in outbound updates\n")
5511{
d62a17ae 5512 int idx_peer = 1;
5513 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5514 bgp_node_safi(vty),
5515 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5516}
5517
d62a17ae 5518ALIAS_HIDDEN(
5519 neighbor_remove_private_as_all_replace_as,
5520 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5521 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5522 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5523 "Remove private ASNs in outbound updates\n"
5524 "Apply to all AS numbers\n"
5525 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5526
718e3744 5527DEFUN (no_neighbor_remove_private_as,
5528 no_neighbor_remove_private_as_cmd,
9ccf14f7 5529 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 5530 NO_STR
5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5000f21c 5533 "Remove private ASNs in outbound updates\n")
718e3744 5534{
d62a17ae 5535 int idx_peer = 2;
5536 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5537 bgp_node_afi(vty), bgp_node_safi(vty),
5538 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5539}
6b0655a2 5540
d62a17ae 5541ALIAS_HIDDEN(no_neighbor_remove_private_as,
5542 no_neighbor_remove_private_as_hidden_cmd,
5543 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5544 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5545 "Remove private ASNs in outbound updates\n")
596c17ba 5546
88b8ed8d 5547DEFUN (no_neighbor_remove_private_as_all,
5000f21c 5548 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 5549 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
5550 NO_STR
5551 NEIGHBOR_STR
5552 NEIGHBOR_ADDR_STR2
5553 "Remove private ASNs in outbound updates\n"
16cedbb0 5554 "Apply to all AS numbers\n")
88b8ed8d 5555{
d62a17ae 5556 int idx_peer = 2;
5557 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5558 bgp_node_afi(vty), bgp_node_safi(vty),
5559 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5560}
5000f21c 5561
d62a17ae 5562ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5563 no_neighbor_remove_private_as_all_hidden_cmd,
5564 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5565 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5566 "Remove private ASNs in outbound updates\n"
5567 "Apply to all AS numbers\n")
596c17ba 5568
88b8ed8d 5569DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 5570 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 5571 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
5572 NO_STR
5573 NEIGHBOR_STR
5574 NEIGHBOR_ADDR_STR2
5575 "Remove private ASNs in outbound updates\n"
5576 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5577{
d62a17ae 5578 int idx_peer = 2;
5579 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5580 bgp_node_afi(vty), bgp_node_safi(vty),
5581 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5582}
5000f21c 5583
d62a17ae 5584ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5585 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5586 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5587 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5588 "Remove private ASNs in outbound updates\n"
5589 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5590
88b8ed8d 5591DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 5592 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 5593 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
5594 NO_STR
5595 NEIGHBOR_STR
5596 NEIGHBOR_ADDR_STR2
5597 "Remove private ASNs in outbound updates\n"
16cedbb0 5598 "Apply to all AS numbers\n"
5000f21c 5599 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5600{
d62a17ae 5601 int idx_peer = 2;
5602 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5603 bgp_node_afi(vty), bgp_node_safi(vty),
5604 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5605}
5000f21c 5606
d62a17ae 5607ALIAS_HIDDEN(
5608 no_neighbor_remove_private_as_all_replace_as,
5609 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5610 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5611 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5612 "Remove private ASNs in outbound updates\n"
5613 "Apply to all AS numbers\n"
5614 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5615
5000f21c 5616
718e3744 5617/* neighbor send-community. */
5618DEFUN (neighbor_send_community,
5619 neighbor_send_community_cmd,
9ccf14f7 5620 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 5621 NEIGHBOR_STR
5622 NEIGHBOR_ADDR_STR2
5623 "Send Community attribute to this neighbor\n")
5624{
d62a17ae 5625 int idx_peer = 1;
27c05d4d 5626
d62a17ae 5627 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5628 bgp_node_safi(vty),
5629 PEER_FLAG_SEND_COMMUNITY);
718e3744 5630}
5631
d62a17ae 5632ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5633 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5634 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5635 "Send Community attribute to this neighbor\n")
596c17ba 5636
718e3744 5637DEFUN (no_neighbor_send_community,
5638 no_neighbor_send_community_cmd,
9ccf14f7 5639 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 5640 NO_STR
5641 NEIGHBOR_STR
5642 NEIGHBOR_ADDR_STR2
5643 "Send Community attribute to this neighbor\n")
5644{
d62a17ae 5645 int idx_peer = 2;
27c05d4d 5646
d62a17ae 5647 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5648 bgp_node_afi(vty), bgp_node_safi(vty),
5649 PEER_FLAG_SEND_COMMUNITY);
718e3744 5650}
6b0655a2 5651
d62a17ae 5652ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5653 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5654 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5655 "Send Community attribute to this neighbor\n")
596c17ba 5656
718e3744 5657/* neighbor send-community extended. */
5658DEFUN (neighbor_send_community_type,
5659 neighbor_send_community_type_cmd,
57d187bc 5660 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5661 NEIGHBOR_STR
5662 NEIGHBOR_ADDR_STR2
5663 "Send Community attribute to this neighbor\n"
5664 "Send Standard and Extended Community attributes\n"
57d187bc 5665 "Send Standard, Large and Extended Community attributes\n"
718e3744 5666 "Send Extended Community attributes\n"
57d187bc
JS
5667 "Send Standard Community attributes\n"
5668 "Send Large Community attributes\n")
718e3744 5669{
27c05d4d 5670 const char *type = argv[argc - 1]->text;
db45f64d
DS
5671 char *peer_str = argv[1]->arg;
5672 struct peer *peer;
5673 afi_t afi = bgp_node_afi(vty);
5674 safi_t safi = bgp_node_safi(vty);
d62a17ae 5675
db45f64d
DS
5676 peer = peer_and_group_lookup_vty(vty, peer_str);
5677 if (!peer)
5678 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5679
db45f64d
DS
5680 if (strmatch(type, "standard"))
5681 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5682 PEER_FLAG_SEND_COMMUNITY);
5683
5684 if (strmatch(type, "extended"))
5685 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5686 PEER_FLAG_SEND_EXT_COMMUNITY);
5687
5688 if (strmatch(type, "large"))
5689 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5690 PEER_FLAG_SEND_LARGE_COMMUNITY);
5691
5692 if (strmatch(type, "both")) {
5693 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5694 PEER_FLAG_SEND_COMMUNITY)
5695 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5696 PEER_FLAG_SEND_EXT_COMMUNITY);
5697 }
5698 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5699 PEER_FLAG_SEND_COMMUNITY)
5700 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5701 PEER_FLAG_SEND_EXT_COMMUNITY)
5702 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5703 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5704}
5705
5706ALIAS_HIDDEN(
5707 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5708 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5709 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5710 "Send Community attribute to this neighbor\n"
5711 "Send Standard and Extended Community attributes\n"
5712 "Send Standard, Large and Extended Community attributes\n"
5713 "Send Extended Community attributes\n"
5714 "Send Standard Community attributes\n"
5715 "Send Large Community attributes\n")
596c17ba 5716
718e3744 5717DEFUN (no_neighbor_send_community_type,
5718 no_neighbor_send_community_type_cmd,
57d187bc 5719 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5720 NO_STR
5721 NEIGHBOR_STR
5722 NEIGHBOR_ADDR_STR2
5723 "Send Community attribute to this neighbor\n"
5724 "Send Standard and Extended Community attributes\n"
57d187bc 5725 "Send Standard, Large and Extended Community attributes\n"
718e3744 5726 "Send Extended Community attributes\n"
57d187bc
JS
5727 "Send Standard Community attributes\n"
5728 "Send Large Community attributes\n")
718e3744 5729{
d62a17ae 5730 const char *type = argv[argc - 1]->text;
db45f64d
DS
5731 char *peer_str = argv[2]->arg;
5732 struct peer *peer;
5733 afi_t afi = bgp_node_afi(vty);
5734 safi_t safi = bgp_node_safi(vty);
5735
5736 peer = peer_and_group_lookup_vty(vty, peer_str);
5737 if (!peer)
5738 return CMD_WARNING_CONFIG_FAILED;
5739
5740 if (strmatch(type, "standard"))
5741 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5742 PEER_FLAG_SEND_COMMUNITY);
5743
5744 if (strmatch(type, "extended"))
5745 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5746 PEER_FLAG_SEND_EXT_COMMUNITY);
5747
5748 if (strmatch(type, "large"))
5749 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5750 PEER_FLAG_SEND_LARGE_COMMUNITY);
5751
5752 if (strmatch(type, "both")) {
d62a17ae 5753
db45f64d
DS
5754 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5755 PEER_FLAG_SEND_COMMUNITY)
5756 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5757 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5758 }
5759
db45f64d
DS
5760 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5761 PEER_FLAG_SEND_COMMUNITY)
5762 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5763 PEER_FLAG_SEND_EXT_COMMUNITY)
5764 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5765 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5766}
5767
5768ALIAS_HIDDEN(
5769 no_neighbor_send_community_type,
5770 no_neighbor_send_community_type_hidden_cmd,
5771 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5772 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5773 "Send Community attribute to this neighbor\n"
5774 "Send Standard and Extended Community attributes\n"
5775 "Send Standard, Large and Extended Community attributes\n"
5776 "Send Extended Community attributes\n"
5777 "Send Standard Community attributes\n"
5778 "Send Large Community attributes\n")
596c17ba 5779
718e3744 5780/* neighbor soft-reconfig. */
5781DEFUN (neighbor_soft_reconfiguration,
5782 neighbor_soft_reconfiguration_cmd,
9ccf14f7 5783 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5784 NEIGHBOR_STR
5785 NEIGHBOR_ADDR_STR2
5786 "Per neighbor soft reconfiguration\n"
5787 "Allow inbound soft reconfiguration for this neighbor\n")
5788{
d62a17ae 5789 int idx_peer = 1;
5790 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5791 bgp_node_safi(vty),
5792 PEER_FLAG_SOFT_RECONFIG);
718e3744 5793}
5794
d62a17ae 5795ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5796 neighbor_soft_reconfiguration_hidden_cmd,
5797 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5798 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5799 "Per neighbor soft reconfiguration\n"
5800 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5801
718e3744 5802DEFUN (no_neighbor_soft_reconfiguration,
5803 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 5804 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5805 NO_STR
5806 NEIGHBOR_STR
5807 NEIGHBOR_ADDR_STR2
5808 "Per neighbor soft reconfiguration\n"
5809 "Allow inbound soft reconfiguration for this neighbor\n")
5810{
d62a17ae 5811 int idx_peer = 2;
5812 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5813 bgp_node_afi(vty), bgp_node_safi(vty),
5814 PEER_FLAG_SOFT_RECONFIG);
718e3744 5815}
6b0655a2 5816
d62a17ae 5817ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5818 no_neighbor_soft_reconfiguration_hidden_cmd,
5819 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5820 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5821 "Per neighbor soft reconfiguration\n"
5822 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5823
718e3744 5824DEFUN (neighbor_route_reflector_client,
5825 neighbor_route_reflector_client_cmd,
9ccf14f7 5826 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5827 NEIGHBOR_STR
5828 NEIGHBOR_ADDR_STR2
5829 "Configure a neighbor as Route Reflector client\n")
5830{
d62a17ae 5831 int idx_peer = 1;
5832 struct peer *peer;
718e3744 5833
5834
d62a17ae 5835 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5836 if (!peer)
5837 return CMD_WARNING_CONFIG_FAILED;
718e3744 5838
d62a17ae 5839 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5840 bgp_node_safi(vty),
5841 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5842}
5843
d62a17ae 5844ALIAS_HIDDEN(neighbor_route_reflector_client,
5845 neighbor_route_reflector_client_hidden_cmd,
5846 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5847 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5848 "Configure a neighbor as Route Reflector client\n")
596c17ba 5849
718e3744 5850DEFUN (no_neighbor_route_reflector_client,
5851 no_neighbor_route_reflector_client_cmd,
9ccf14f7 5852 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5853 NO_STR
5854 NEIGHBOR_STR
5855 NEIGHBOR_ADDR_STR2
5856 "Configure a neighbor as Route Reflector client\n")
5857{
d62a17ae 5858 int idx_peer = 2;
5859 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5860 bgp_node_afi(vty), bgp_node_safi(vty),
5861 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5862}
6b0655a2 5863
d62a17ae 5864ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5865 no_neighbor_route_reflector_client_hidden_cmd,
5866 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5867 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5868 "Configure a neighbor as Route Reflector client\n")
596c17ba 5869
718e3744 5870/* neighbor route-server-client. */
5871DEFUN (neighbor_route_server_client,
5872 neighbor_route_server_client_cmd,
9ccf14f7 5873 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5874 NEIGHBOR_STR
5875 NEIGHBOR_ADDR_STR2
5876 "Configure a neighbor as Route Server client\n")
5877{
d62a17ae 5878 int idx_peer = 1;
5879 struct peer *peer;
2a3d5731 5880
d62a17ae 5881 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5882 if (!peer)
5883 return CMD_WARNING_CONFIG_FAILED;
5884 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5885 bgp_node_safi(vty),
5886 PEER_FLAG_RSERVER_CLIENT);
718e3744 5887}
5888
d62a17ae 5889ALIAS_HIDDEN(neighbor_route_server_client,
5890 neighbor_route_server_client_hidden_cmd,
5891 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5892 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5893 "Configure a neighbor as Route Server client\n")
596c17ba 5894
718e3744 5895DEFUN (no_neighbor_route_server_client,
5896 no_neighbor_route_server_client_cmd,
9ccf14f7 5897 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5898 NO_STR
5899 NEIGHBOR_STR
5900 NEIGHBOR_ADDR_STR2
5901 "Configure a neighbor as Route Server client\n")
fee0f4c6 5902{
d62a17ae 5903 int idx_peer = 2;
5904 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5905 bgp_node_afi(vty), bgp_node_safi(vty),
5906 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5907}
6b0655a2 5908
d62a17ae 5909ALIAS_HIDDEN(no_neighbor_route_server_client,
5910 no_neighbor_route_server_client_hidden_cmd,
5911 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5912 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5913 "Configure a neighbor as Route Server client\n")
596c17ba 5914
fee0f4c6 5915DEFUN (neighbor_nexthop_local_unchanged,
5916 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5917 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5918 NEIGHBOR_STR
5919 NEIGHBOR_ADDR_STR2
5920 "Configure treatment of outgoing link-local nexthop attribute\n"
5921 "Leave link-local nexthop unchanged for this peer\n")
5922{
d62a17ae 5923 int idx_peer = 1;
5924 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5925 bgp_node_safi(vty),
5926 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 5927}
6b0655a2 5928
fee0f4c6 5929DEFUN (no_neighbor_nexthop_local_unchanged,
5930 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5931 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5932 NO_STR
5933 NEIGHBOR_STR
5934 NEIGHBOR_ADDR_STR2
5935 "Configure treatment of outgoing link-local-nexthop attribute\n"
5936 "Leave link-local nexthop unchanged for this peer\n")
718e3744 5937{
d62a17ae 5938 int idx_peer = 2;
5939 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5940 bgp_node_afi(vty), bgp_node_safi(vty),
5941 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 5942}
6b0655a2 5943
718e3744 5944DEFUN (neighbor_attr_unchanged,
5945 neighbor_attr_unchanged_cmd,
a8206004 5946 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 5947 NEIGHBOR_STR
5948 NEIGHBOR_ADDR_STR2
5949 "BGP attribute is propagated unchanged to this neighbor\n"
5950 "As-path attribute\n"
5951 "Nexthop attribute\n"
a8206004 5952 "Med attribute\n")
718e3744 5953{
d62a17ae 5954 int idx = 0;
8eeb0335
DW
5955 char *peer_str = argv[1]->arg;
5956 struct peer *peer;
db45f64d
DS
5957 bool aspath = false;
5958 bool nexthop = false;
5959 bool med = false;
8eeb0335
DW
5960 afi_t afi = bgp_node_afi(vty);
5961 safi_t safi = bgp_node_safi(vty);
db45f64d 5962 int ret = 0;
8eeb0335
DW
5963
5964 peer = peer_and_group_lookup_vty(vty, peer_str);
5965 if (!peer)
5966 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5967
5968 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5969 aspath = true;
5970
d62a17ae 5971 idx = 0;
5972 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5973 nexthop = true;
5974
d62a17ae 5975 idx = 0;
5976 if (argv_find(argv, argc, "med", &idx))
db45f64d 5977 med = true;
d62a17ae 5978
8eeb0335 5979 /* no flags means all of them! */
db45f64d
DS
5980 if (!aspath && !nexthop && !med) {
5981 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
5982 PEER_FLAG_AS_PATH_UNCHANGED);
5983 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5984 PEER_FLAG_NEXTHOP_UNCHANGED);
5985 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5986 PEER_FLAG_MED_UNCHANGED);
8eeb0335 5987 } else {
db45f64d
DS
5988 if (!aspath) {
5989 if (peer_af_flag_check(peer, afi, safi,
5990 PEER_FLAG_AS_PATH_UNCHANGED)) {
5991 ret |= peer_af_flag_unset_vty(
5992 vty, peer_str, afi, safi,
5993 PEER_FLAG_AS_PATH_UNCHANGED);
5994 }
5995 } else
5996 ret |= peer_af_flag_set_vty(
5997 vty, peer_str, afi, safi,
5998 PEER_FLAG_AS_PATH_UNCHANGED);
5999
6000 if (!nexthop) {
6001 if (peer_af_flag_check(peer, afi, safi,
6002 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6003 ret |= peer_af_flag_unset_vty(
6004 vty, peer_str, afi, safi,
6005 PEER_FLAG_NEXTHOP_UNCHANGED);
6006 }
6007 } else
6008 ret |= peer_af_flag_set_vty(
6009 vty, peer_str, afi, safi,
6010 PEER_FLAG_NEXTHOP_UNCHANGED);
6011
6012 if (!med) {
6013 if (peer_af_flag_check(peer, afi, safi,
6014 PEER_FLAG_MED_UNCHANGED)) {
6015 ret |= peer_af_flag_unset_vty(
6016 vty, peer_str, afi, safi,
6017 PEER_FLAG_MED_UNCHANGED);
6018 }
6019 } else
6020 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6021 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6022 }
6023
db45f64d 6024 return ret;
d62a17ae 6025}
6026
6027ALIAS_HIDDEN(
6028 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6029 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6031 "BGP attribute is propagated unchanged to this neighbor\n"
6032 "As-path attribute\n"
6033 "Nexthop attribute\n"
6034 "Med attribute\n")
596c17ba 6035
718e3744 6036DEFUN (no_neighbor_attr_unchanged,
6037 no_neighbor_attr_unchanged_cmd,
a8206004 6038 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 6039 NO_STR
718e3744 6040 NEIGHBOR_STR
6041 NEIGHBOR_ADDR_STR2
31500417
DW
6042 "BGP attribute is propagated unchanged to this neighbor\n"
6043 "As-path attribute\n"
40e718b5 6044 "Nexthop attribute\n"
a8206004 6045 "Med attribute\n")
718e3744 6046{
d62a17ae 6047 int idx = 0;
db45f64d
DS
6048 char *peer_str = argv[2]->arg;
6049 struct peer *peer;
6050 bool aspath = false;
6051 bool nexthop = false;
6052 bool med = false;
6053 afi_t afi = bgp_node_afi(vty);
6054 safi_t safi = bgp_node_safi(vty);
6055 int ret = 0;
6056
6057 peer = peer_and_group_lookup_vty(vty, peer_str);
6058 if (!peer)
6059 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6060
6061 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6062 aspath = true;
6063
d62a17ae 6064 idx = 0;
6065 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6066 nexthop = true;
6067
d62a17ae 6068 idx = 0;
6069 if (argv_find(argv, argc, "med", &idx))
db45f64d 6070 med = true;
d62a17ae 6071
db45f64d
DS
6072 if (!aspath && !nexthop && !med) // no flags means all of them!
6073 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6074 PEER_FLAG_AS_PATH_UNCHANGED)
6075 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6076 PEER_FLAG_NEXTHOP_UNCHANGED)
6077 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6078 PEER_FLAG_MED_UNCHANGED);
6079
6080 if (aspath)
6081 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6082 PEER_FLAG_AS_PATH_UNCHANGED);
6083
6084 if (nexthop)
6085 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6086 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6087
db45f64d
DS
6088 if (med)
6089 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6090 PEER_FLAG_MED_UNCHANGED);
6091
6092 return ret;
d62a17ae 6093}
6094
6095ALIAS_HIDDEN(
6096 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6098 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6099 "BGP attribute is propagated unchanged to this neighbor\n"
6100 "As-path attribute\n"
6101 "Nexthop attribute\n"
6102 "Med attribute\n")
718e3744 6103
718e3744 6104/* EBGP multihop configuration. */
d62a17ae 6105static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6106 const char *ttl_str)
718e3744 6107{
d62a17ae 6108 struct peer *peer;
6109 unsigned int ttl;
718e3744 6110
d62a17ae 6111 peer = peer_and_group_lookup_vty(vty, ip_str);
6112 if (!peer)
6113 return CMD_WARNING_CONFIG_FAILED;
718e3744 6114
d62a17ae 6115 if (peer->conf_if)
6116 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 6117
d62a17ae 6118 if (!ttl_str)
6119 ttl = MAXTTL;
6120 else
6121 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6122
d62a17ae 6123 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6124}
6125
d62a17ae 6126static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6127{
d62a17ae 6128 struct peer *peer;
718e3744 6129
d62a17ae 6130 peer = peer_and_group_lookup_vty(vty, ip_str);
6131 if (!peer)
6132 return CMD_WARNING_CONFIG_FAILED;
718e3744 6133
d62a17ae 6134 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6135}
6136
6137/* neighbor ebgp-multihop. */
6138DEFUN (neighbor_ebgp_multihop,
6139 neighbor_ebgp_multihop_cmd,
9ccf14f7 6140 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 6141 NEIGHBOR_STR
6142 NEIGHBOR_ADDR_STR2
6143 "Allow EBGP neighbors not on directly connected networks\n")
6144{
d62a17ae 6145 int idx_peer = 1;
6146 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6147}
6148
6149DEFUN (neighbor_ebgp_multihop_ttl,
6150 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 6151 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 6152 NEIGHBOR_STR
6153 NEIGHBOR_ADDR_STR2
6154 "Allow EBGP neighbors not on directly connected networks\n"
6155 "maximum hop count\n")
6156{
d62a17ae 6157 int idx_peer = 1;
6158 int idx_number = 3;
6159 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6160 argv[idx_number]->arg);
718e3744 6161}
6162
6163DEFUN (no_neighbor_ebgp_multihop,
6164 no_neighbor_ebgp_multihop_cmd,
a636c635 6165 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 6166 NO_STR
6167 NEIGHBOR_STR
6168 NEIGHBOR_ADDR_STR2
a636c635
DW
6169 "Allow EBGP neighbors not on directly connected networks\n"
6170 "maximum hop count\n")
718e3744 6171{
d62a17ae 6172 int idx_peer = 2;
6173 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6174}
6175
6b0655a2 6176
6ffd2079 6177/* disable-connected-check */
6178DEFUN (neighbor_disable_connected_check,
6179 neighbor_disable_connected_check_cmd,
7ebe625c 6180 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 6181 NEIGHBOR_STR
7ebe625c 6182 NEIGHBOR_ADDR_STR2
a636c635
DW
6183 "one-hop away EBGP peer using loopback address\n"
6184 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6185{
d62a17ae 6186 int idx_peer = 1;
6187 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6188 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6189}
6190
6191DEFUN (no_neighbor_disable_connected_check,
6192 no_neighbor_disable_connected_check_cmd,
7ebe625c 6193 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 6194 NO_STR
6195 NEIGHBOR_STR
7ebe625c 6196 NEIGHBOR_ADDR_STR2
a636c635
DW
6197 "one-hop away EBGP peer using loopback address\n"
6198 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6199{
d62a17ae 6200 int idx_peer = 2;
6201 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6202 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6203}
6204
47cbc09b
PM
6205
6206/* enforce-first-as */
6207DEFUN (neighbor_enforce_first_as,
6208 neighbor_enforce_first_as_cmd,
6209 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6210 NEIGHBOR_STR
6211 NEIGHBOR_ADDR_STR2
6212 "Enforce the first AS for EBGP routes\n")
6213{
6214 int idx_peer = 1;
6215
6216 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6217 PEER_FLAG_ENFORCE_FIRST_AS);
6218}
6219
6220DEFUN (no_neighbor_enforce_first_as,
6221 no_neighbor_enforce_first_as_cmd,
6222 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6223 NO_STR
6224 NEIGHBOR_STR
6225 NEIGHBOR_ADDR_STR2
6226 "Enforce the first AS for EBGP routes\n")
6227{
6228 int idx_peer = 2;
6229
6230 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6231 PEER_FLAG_ENFORCE_FIRST_AS);
6232}
6233
6234
718e3744 6235DEFUN (neighbor_description,
6236 neighbor_description_cmd,
e961923c 6237 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 6238 NEIGHBOR_STR
6239 NEIGHBOR_ADDR_STR2
6240 "Neighbor specific description\n"
6241 "Up to 80 characters describing this neighbor\n")
6242{
d62a17ae 6243 int idx_peer = 1;
6244 int idx_line = 3;
6245 struct peer *peer;
6246 char *str;
718e3744 6247
d62a17ae 6248 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6249 if (!peer)
6250 return CMD_WARNING_CONFIG_FAILED;
718e3744 6251
d62a17ae 6252 str = argv_concat(argv, argc, idx_line);
718e3744 6253
d62a17ae 6254 peer_description_set(peer, str);
718e3744 6255
d62a17ae 6256 XFREE(MTYPE_TMP, str);
718e3744 6257
d62a17ae 6258 return CMD_SUCCESS;
718e3744 6259}
6260
6261DEFUN (no_neighbor_description,
6262 no_neighbor_description_cmd,
a14810f4 6263 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 6264 NO_STR
6265 NEIGHBOR_STR
6266 NEIGHBOR_ADDR_STR2
a14810f4 6267 "Neighbor specific description\n")
718e3744 6268{
d62a17ae 6269 int idx_peer = 2;
6270 struct peer *peer;
718e3744 6271
d62a17ae 6272 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6273 if (!peer)
6274 return CMD_WARNING_CONFIG_FAILED;
718e3744 6275
d62a17ae 6276 peer_description_unset(peer);
718e3744 6277
d62a17ae 6278 return CMD_SUCCESS;
718e3744 6279}
6280
a14810f4
PM
6281ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6282 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6283 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6284 "Neighbor specific description\n"
6285 "Up to 80 characters describing this neighbor\n")
6b0655a2 6286
718e3744 6287/* Neighbor update-source. */
d62a17ae 6288static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6289 const char *source_str)
6290{
6291 struct peer *peer;
6292 struct prefix p;
a14810f4 6293 union sockunion su;
d62a17ae 6294
6295 peer = peer_and_group_lookup_vty(vty, peer_str);
6296 if (!peer)
6297 return CMD_WARNING_CONFIG_FAILED;
6298
6299 if (peer->conf_if)
6300 return CMD_WARNING;
6301
6302 if (source_str) {
a14810f4 6303 if (str2sockunion(source_str, &su) == 0)
d62a17ae 6304 peer_update_source_addr_set(peer, &su);
6305 else {
6306 if (str2prefix(source_str, &p)) {
6307 vty_out(vty,
6308 "%% Invalid update-source, remove prefix length \n");
6309 return CMD_WARNING_CONFIG_FAILED;
6310 } else
6311 peer_update_source_if_set(peer, source_str);
6312 }
6313 } else
6314 peer_update_source_unset(peer);
6315
6316 return CMD_SUCCESS;
6317}
6318
6319#define BGP_UPDATE_SOURCE_HELP_STR \
6320 "IPv4 address\n" \
6321 "IPv6 address\n" \
6322 "Interface name (requires zebra to be running)\n"
369688c0 6323
718e3744 6324DEFUN (neighbor_update_source,
6325 neighbor_update_source_cmd,
9ccf14f7 6326 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 6327 NEIGHBOR_STR
6328 NEIGHBOR_ADDR_STR2
6329 "Source of routing updates\n"
369688c0 6330 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6331{
d62a17ae 6332 int idx_peer = 1;
6333 int idx_peer_2 = 3;
6334 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6335 argv[idx_peer_2]->arg);
718e3744 6336}
6337
6338DEFUN (no_neighbor_update_source,
6339 no_neighbor_update_source_cmd,
c7178fe7 6340 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 6341 NO_STR
6342 NEIGHBOR_STR
6343 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
6344 "Source of routing updates\n"
6345 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6346{
d62a17ae 6347 int idx_peer = 2;
6348 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6349}
6b0655a2 6350
d62a17ae 6351static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6352 afi_t afi, safi_t safi,
6353 const char *rmap, int set)
718e3744 6354{
d62a17ae 6355 int ret;
6356 struct peer *peer;
80912664 6357 struct route_map *route_map = NULL;
718e3744 6358
d62a17ae 6359 peer = peer_and_group_lookup_vty(vty, peer_str);
6360 if (!peer)
6361 return CMD_WARNING_CONFIG_FAILED;
718e3744 6362
1de27621 6363 if (set) {
80912664
DS
6364 if (rmap)
6365 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6366 ret = peer_default_originate_set(peer, afi, safi,
6367 rmap, route_map);
6368 } else
d62a17ae 6369 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6370
d62a17ae 6371 return bgp_vty_return(vty, ret);
718e3744 6372}
6373
6374/* neighbor default-originate. */
6375DEFUN (neighbor_default_originate,
6376 neighbor_default_originate_cmd,
9ccf14f7 6377 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6378 NEIGHBOR_STR
6379 NEIGHBOR_ADDR_STR2
6380 "Originate default route to this neighbor\n")
6381{
d62a17ae 6382 int idx_peer = 1;
6383 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6384 bgp_node_afi(vty),
6385 bgp_node_safi(vty), NULL, 1);
718e3744 6386}
6387
d62a17ae 6388ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6389 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6390 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6391 "Originate default route to this neighbor\n")
596c17ba 6392
718e3744 6393DEFUN (neighbor_default_originate_rmap,
6394 neighbor_default_originate_rmap_cmd,
9ccf14f7 6395 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6396 NEIGHBOR_STR
6397 NEIGHBOR_ADDR_STR2
6398 "Originate default route to this neighbor\n"
6399 "Route-map to specify criteria to originate default\n"
6400 "route-map name\n")
6401{
d62a17ae 6402 int idx_peer = 1;
6403 int idx_word = 4;
6404 return peer_default_originate_set_vty(
6405 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6406 argv[idx_word]->arg, 1);
718e3744 6407}
6408
d62a17ae 6409ALIAS_HIDDEN(
6410 neighbor_default_originate_rmap,
6411 neighbor_default_originate_rmap_hidden_cmd,
6412 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6413 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6414 "Originate default route to this neighbor\n"
6415 "Route-map to specify criteria to originate default\n"
6416 "route-map name\n")
596c17ba 6417
718e3744 6418DEFUN (no_neighbor_default_originate,
6419 no_neighbor_default_originate_cmd,
a636c635 6420 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6421 NO_STR
6422 NEIGHBOR_STR
6423 NEIGHBOR_ADDR_STR2
a636c635
DW
6424 "Originate default route to this neighbor\n"
6425 "Route-map to specify criteria to originate default\n"
6426 "route-map name\n")
718e3744 6427{
d62a17ae 6428 int idx_peer = 2;
6429 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6430 bgp_node_afi(vty),
6431 bgp_node_safi(vty), NULL, 0);
718e3744 6432}
6433
d62a17ae 6434ALIAS_HIDDEN(
6435 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6436 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6437 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6438 "Originate default route to this neighbor\n"
6439 "Route-map to specify criteria to originate default\n"
6440 "route-map name\n")
596c17ba 6441
6b0655a2 6442
718e3744 6443/* Set neighbor's BGP port. */
d62a17ae 6444static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6445 const char *port_str)
6446{
6447 struct peer *peer;
d7c0a89a 6448 uint16_t port;
d62a17ae 6449 struct servent *sp;
6450
6451 peer = peer_lookup_vty(vty, ip_str);
6452 if (!peer)
6453 return CMD_WARNING_CONFIG_FAILED;
6454
6455 if (!port_str) {
6456 sp = getservbyname("bgp", "tcp");
6457 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6458 } else {
6459 port = strtoul(port_str, NULL, 10);
6460 }
718e3744 6461
d62a17ae 6462 peer_port_set(peer, port);
718e3744 6463
d62a17ae 6464 return CMD_SUCCESS;
718e3744 6465}
6466
f418446b 6467/* Set specified peer's BGP port. */
718e3744 6468DEFUN (neighbor_port,
6469 neighbor_port_cmd,
9ccf14f7 6470 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 6471 NEIGHBOR_STR
6472 NEIGHBOR_ADDR_STR
6473 "Neighbor's BGP port\n"
6474 "TCP port number\n")
6475{
d62a17ae 6476 int idx_ip = 1;
6477 int idx_number = 3;
6478 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6479 argv[idx_number]->arg);
718e3744 6480}
6481
6482DEFUN (no_neighbor_port,
6483 no_neighbor_port_cmd,
9ccf14f7 6484 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 6485 NO_STR
6486 NEIGHBOR_STR
6487 NEIGHBOR_ADDR_STR
8334fd5a
DW
6488 "Neighbor's BGP port\n"
6489 "TCP port number\n")
718e3744 6490{
d62a17ae 6491 int idx_ip = 2;
6492 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 6493}
6494
6b0655a2 6495
718e3744 6496/* neighbor weight. */
d62a17ae 6497static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6498 safi_t safi, const char *weight_str)
718e3744 6499{
d62a17ae 6500 int ret;
6501 struct peer *peer;
6502 unsigned long weight;
718e3744 6503
d62a17ae 6504 peer = peer_and_group_lookup_vty(vty, ip_str);
6505 if (!peer)
6506 return CMD_WARNING_CONFIG_FAILED;
718e3744 6507
d62a17ae 6508 weight = strtoul(weight_str, NULL, 10);
718e3744 6509
d62a17ae 6510 ret = peer_weight_set(peer, afi, safi, weight);
6511 return bgp_vty_return(vty, ret);
718e3744 6512}
6513
d62a17ae 6514static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6515 safi_t safi)
718e3744 6516{
d62a17ae 6517 int ret;
6518 struct peer *peer;
718e3744 6519
d62a17ae 6520 peer = peer_and_group_lookup_vty(vty, ip_str);
6521 if (!peer)
6522 return CMD_WARNING_CONFIG_FAILED;
718e3744 6523
d62a17ae 6524 ret = peer_weight_unset(peer, afi, safi);
6525 return bgp_vty_return(vty, ret);
718e3744 6526}
6527
6528DEFUN (neighbor_weight,
6529 neighbor_weight_cmd,
9ccf14f7 6530 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 6531 NEIGHBOR_STR
6532 NEIGHBOR_ADDR_STR2
6533 "Set default weight for routes from this neighbor\n"
6534 "default weight\n")
6535{
d62a17ae 6536 int idx_peer = 1;
6537 int idx_number = 3;
6538 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6539 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6540}
6541
d62a17ae 6542ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6543 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6544 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6545 "Set default weight for routes from this neighbor\n"
6546 "default weight\n")
596c17ba 6547
718e3744 6548DEFUN (no_neighbor_weight,
6549 no_neighbor_weight_cmd,
9ccf14f7 6550 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 6551 NO_STR
6552 NEIGHBOR_STR
6553 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6554 "Set default weight for routes from this neighbor\n"
6555 "default weight\n")
718e3744 6556{
d62a17ae 6557 int idx_peer = 2;
6558 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6559 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6560}
6561
d62a17ae 6562ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6563 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6564 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6565 "Set default weight for routes from this neighbor\n"
6566 "default weight\n")
596c17ba 6567
6b0655a2 6568
718e3744 6569/* Override capability negotiation. */
6570DEFUN (neighbor_override_capability,
6571 neighbor_override_capability_cmd,
9ccf14f7 6572 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 6573 NEIGHBOR_STR
6574 NEIGHBOR_ADDR_STR2
6575 "Override capability negotiation result\n")
6576{
d62a17ae 6577 int idx_peer = 1;
6578 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6579 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6580}
6581
6582DEFUN (no_neighbor_override_capability,
6583 no_neighbor_override_capability_cmd,
9ccf14f7 6584 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 6585 NO_STR
6586 NEIGHBOR_STR
6587 NEIGHBOR_ADDR_STR2
6588 "Override capability negotiation result\n")
6589{
d62a17ae 6590 int idx_peer = 2;
6591 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6592 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6593}
6b0655a2 6594
718e3744 6595DEFUN (neighbor_strict_capability,
6596 neighbor_strict_capability_cmd,
9fb964de 6597 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 6598 NEIGHBOR_STR
9fb964de 6599 NEIGHBOR_ADDR_STR2
718e3744 6600 "Strict capability negotiation match\n")
6601{
9fb964de
PM
6602 int idx_peer = 1;
6603
6604 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 6605 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6606}
6607
6608DEFUN (no_neighbor_strict_capability,
6609 no_neighbor_strict_capability_cmd,
9fb964de 6610 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 6611 NO_STR
6612 NEIGHBOR_STR
9fb964de 6613 NEIGHBOR_ADDR_STR2
718e3744 6614 "Strict capability negotiation match\n")
6615{
9fb964de
PM
6616 int idx_peer = 2;
6617
6618 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 6619 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6620}
6b0655a2 6621
d62a17ae 6622static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6623 const char *keep_str, const char *hold_str)
718e3744 6624{
d62a17ae 6625 int ret;
6626 struct peer *peer;
d7c0a89a
QY
6627 uint32_t keepalive;
6628 uint32_t holdtime;
718e3744 6629
d62a17ae 6630 peer = peer_and_group_lookup_vty(vty, ip_str);
6631 if (!peer)
6632 return CMD_WARNING_CONFIG_FAILED;
718e3744 6633
d62a17ae 6634 keepalive = strtoul(keep_str, NULL, 10);
6635 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6636
d62a17ae 6637 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6638
d62a17ae 6639 return bgp_vty_return(vty, ret);
718e3744 6640}
6b0655a2 6641
d62a17ae 6642static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6643{
d62a17ae 6644 int ret;
6645 struct peer *peer;
718e3744 6646
d62a17ae 6647 peer = peer_and_group_lookup_vty(vty, ip_str);
6648 if (!peer)
6649 return CMD_WARNING_CONFIG_FAILED;
718e3744 6650
d62a17ae 6651 ret = peer_timers_unset(peer);
718e3744 6652
d62a17ae 6653 return bgp_vty_return(vty, ret);
718e3744 6654}
6655
6656DEFUN (neighbor_timers,
6657 neighbor_timers_cmd,
9ccf14f7 6658 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 6659 NEIGHBOR_STR
6660 NEIGHBOR_ADDR_STR2
6661 "BGP per neighbor timers\n"
6662 "Keepalive interval\n"
6663 "Holdtime\n")
6664{
d62a17ae 6665 int idx_peer = 1;
6666 int idx_number = 3;
6667 int idx_number_2 = 4;
6668 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6669 argv[idx_number]->arg,
6670 argv[idx_number_2]->arg);
718e3744 6671}
6672
6673DEFUN (no_neighbor_timers,
6674 no_neighbor_timers_cmd,
9ccf14f7 6675 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 6676 NO_STR
6677 NEIGHBOR_STR
6678 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6679 "BGP per neighbor timers\n"
6680 "Keepalive interval\n"
6681 "Holdtime\n")
718e3744 6682{
d62a17ae 6683 int idx_peer = 2;
6684 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6685}
6b0655a2 6686
813d4307 6687
d62a17ae 6688static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6689 const char *time_str)
718e3744 6690{
d62a17ae 6691 int ret;
6692 struct peer *peer;
d7c0a89a 6693 uint32_t connect;
718e3744 6694
d62a17ae 6695 peer = peer_and_group_lookup_vty(vty, ip_str);
6696 if (!peer)
6697 return CMD_WARNING_CONFIG_FAILED;
718e3744 6698
d62a17ae 6699 connect = strtoul(time_str, NULL, 10);
718e3744 6700
d62a17ae 6701 ret = peer_timers_connect_set(peer, connect);
718e3744 6702
d62a17ae 6703 return bgp_vty_return(vty, ret);
718e3744 6704}
6705
d62a17ae 6706static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6707{
d62a17ae 6708 int ret;
6709 struct peer *peer;
718e3744 6710
d62a17ae 6711 peer = peer_and_group_lookup_vty(vty, ip_str);
6712 if (!peer)
6713 return CMD_WARNING_CONFIG_FAILED;
718e3744 6714
d62a17ae 6715 ret = peer_timers_connect_unset(peer);
718e3744 6716
d62a17ae 6717 return bgp_vty_return(vty, ret);
718e3744 6718}
6719
6720DEFUN (neighbor_timers_connect,
6721 neighbor_timers_connect_cmd,
9ccf14f7 6722 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 6723 NEIGHBOR_STR
966f821c 6724 NEIGHBOR_ADDR_STR2
718e3744 6725 "BGP per neighbor timers\n"
6726 "BGP connect timer\n"
6727 "Connect timer\n")
6728{
d62a17ae 6729 int idx_peer = 1;
6730 int idx_number = 4;
6731 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6732 argv[idx_number]->arg);
718e3744 6733}
6734
6735DEFUN (no_neighbor_timers_connect,
6736 no_neighbor_timers_connect_cmd,
9ccf14f7 6737 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 6738 NO_STR
6739 NEIGHBOR_STR
966f821c 6740 NEIGHBOR_ADDR_STR2
718e3744 6741 "BGP per neighbor timers\n"
8334fd5a
DW
6742 "BGP connect timer\n"
6743 "Connect timer\n")
718e3744 6744{
d62a17ae 6745 int idx_peer = 2;
6746 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6747}
6748
6b0655a2 6749
d62a17ae 6750static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6751 const char *time_str, int set)
718e3744 6752{
d62a17ae 6753 int ret;
6754 struct peer *peer;
d7c0a89a 6755 uint32_t routeadv = 0;
718e3744 6756
d62a17ae 6757 peer = peer_and_group_lookup_vty(vty, ip_str);
6758 if (!peer)
6759 return CMD_WARNING_CONFIG_FAILED;
718e3744 6760
d62a17ae 6761 if (time_str)
6762 routeadv = strtoul(time_str, NULL, 10);
718e3744 6763
d62a17ae 6764 if (set)
6765 ret = peer_advertise_interval_set(peer, routeadv);
6766 else
6767 ret = peer_advertise_interval_unset(peer);
718e3744 6768
d62a17ae 6769 return bgp_vty_return(vty, ret);
718e3744 6770}
6771
6772DEFUN (neighbor_advertise_interval,
6773 neighbor_advertise_interval_cmd,
9ccf14f7 6774 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 6775 NEIGHBOR_STR
966f821c 6776 NEIGHBOR_ADDR_STR2
718e3744 6777 "Minimum interval between sending BGP routing updates\n"
6778 "time in seconds\n")
6779{
d62a17ae 6780 int idx_peer = 1;
6781 int idx_number = 3;
6782 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6783 argv[idx_number]->arg, 1);
718e3744 6784}
6785
6786DEFUN (no_neighbor_advertise_interval,
6787 no_neighbor_advertise_interval_cmd,
9ccf14f7 6788 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 6789 NO_STR
6790 NEIGHBOR_STR
966f821c 6791 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6792 "Minimum interval between sending BGP routing updates\n"
6793 "time in seconds\n")
718e3744 6794{
d62a17ae 6795 int idx_peer = 2;
6796 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6797}
6798
6b0655a2 6799
518f0eb1
DS
6800/* Time to wait before processing route-map updates */
6801DEFUN (bgp_set_route_map_delay_timer,
6802 bgp_set_route_map_delay_timer_cmd,
6147e2c6 6803 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
6804 SET_STR
6805 "BGP route-map delay timer\n"
6806 "Time in secs to wait before processing route-map changes\n"
f414725f 6807 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6808{
d62a17ae 6809 int idx_number = 3;
d7c0a89a 6810 uint32_t rmap_delay_timer;
d62a17ae 6811
6812 if (argv[idx_number]->arg) {
6813 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6814 bm->rmap_update_timer = rmap_delay_timer;
6815
6816 /* if the dynamic update handling is being disabled, and a timer
6817 * is
6818 * running, stop the timer and act as if the timer has already
6819 * fired.
6820 */
6821 if (!rmap_delay_timer && bm->t_rmap_update) {
6822 BGP_TIMER_OFF(bm->t_rmap_update);
6823 thread_execute(bm->master, bgp_route_map_update_timer,
6824 NULL, 0);
6825 }
6826 return CMD_SUCCESS;
6827 } else {
6828 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6829 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 6830 }
518f0eb1
DS
6831}
6832
6833DEFUN (no_bgp_set_route_map_delay_timer,
6834 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 6835 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 6836 NO_STR
3a2d747c 6837 BGP_STR
518f0eb1 6838 "Default BGP route-map delay timer\n"
8334fd5a
DW
6839 "Reset to default time to wait for processing route-map changes\n"
6840 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6841{
518f0eb1 6842
d62a17ae 6843 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 6844
d62a17ae 6845 return CMD_SUCCESS;
518f0eb1
DS
6846}
6847
718e3744 6848/* neighbor interface */
d62a17ae 6849static int peer_interface_vty(struct vty *vty, const char *ip_str,
6850 const char *str)
718e3744 6851{
d62a17ae 6852 struct peer *peer;
718e3744 6853
d62a17ae 6854 peer = peer_lookup_vty(vty, ip_str);
6855 if (!peer || peer->conf_if) {
6856 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6857 return CMD_WARNING_CONFIG_FAILED;
6858 }
718e3744 6859
d62a17ae 6860 if (str)
6861 peer_interface_set(peer, str);
6862 else
6863 peer_interface_unset(peer);
718e3744 6864
d62a17ae 6865 return CMD_SUCCESS;
718e3744 6866}
6867
6868DEFUN (neighbor_interface,
6869 neighbor_interface_cmd,
9ccf14f7 6870 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 6871 NEIGHBOR_STR
6872 NEIGHBOR_ADDR_STR
6873 "Interface\n"
6874 "Interface name\n")
6875{
d62a17ae 6876 int idx_ip = 1;
6877 int idx_word = 3;
6878 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 6879}
6880
6881DEFUN (no_neighbor_interface,
6882 no_neighbor_interface_cmd,
9ccf14f7 6883 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 6884 NO_STR
6885 NEIGHBOR_STR
16cedbb0 6886 NEIGHBOR_ADDR_STR2
718e3744 6887 "Interface\n"
6888 "Interface name\n")
6889{
d62a17ae 6890 int idx_peer = 2;
6891 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6892}
6b0655a2 6893
718e3744 6894DEFUN (neighbor_distribute_list,
6895 neighbor_distribute_list_cmd,
9ccf14f7 6896 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6897 NEIGHBOR_STR
6898 NEIGHBOR_ADDR_STR2
6899 "Filter updates to/from this neighbor\n"
6900 "IP access-list number\n"
6901 "IP access-list number (expanded range)\n"
6902 "IP Access-list name\n"
6903 "Filter incoming updates\n"
6904 "Filter outgoing updates\n")
6905{
d62a17ae 6906 int idx_peer = 1;
6907 int idx_acl = 3;
6908 int direct, ret;
6909 struct peer *peer;
a8206004 6910
d62a17ae 6911 const char *pstr = argv[idx_peer]->arg;
6912 const char *acl = argv[idx_acl]->arg;
6913 const char *inout = argv[argc - 1]->text;
a8206004 6914
d62a17ae 6915 peer = peer_and_group_lookup_vty(vty, pstr);
6916 if (!peer)
6917 return CMD_WARNING_CONFIG_FAILED;
a8206004 6918
d62a17ae 6919 /* Check filter direction. */
6920 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6921 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6922 direct, acl);
a8206004 6923
d62a17ae 6924 return bgp_vty_return(vty, ret);
718e3744 6925}
6926
d62a17ae 6927ALIAS_HIDDEN(
6928 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6929 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6930 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6931 "Filter updates to/from this neighbor\n"
6932 "IP access-list number\n"
6933 "IP access-list number (expanded range)\n"
6934 "IP Access-list name\n"
6935 "Filter incoming updates\n"
6936 "Filter outgoing updates\n")
596c17ba 6937
718e3744 6938DEFUN (no_neighbor_distribute_list,
6939 no_neighbor_distribute_list_cmd,
9ccf14f7 6940 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6941 NO_STR
6942 NEIGHBOR_STR
6943 NEIGHBOR_ADDR_STR2
6944 "Filter updates to/from this neighbor\n"
6945 "IP access-list number\n"
6946 "IP access-list number (expanded range)\n"
6947 "IP Access-list name\n"
6948 "Filter incoming updates\n"
6949 "Filter outgoing updates\n")
6950{
d62a17ae 6951 int idx_peer = 2;
6952 int direct, ret;
6953 struct peer *peer;
a8206004 6954
d62a17ae 6955 const char *pstr = argv[idx_peer]->arg;
6956 const char *inout = argv[argc - 1]->text;
a8206004 6957
d62a17ae 6958 peer = peer_and_group_lookup_vty(vty, pstr);
6959 if (!peer)
6960 return CMD_WARNING_CONFIG_FAILED;
a8206004 6961
d62a17ae 6962 /* Check filter direction. */
6963 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6964 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6965 direct);
a8206004 6966
d62a17ae 6967 return bgp_vty_return(vty, ret);
718e3744 6968}
6b0655a2 6969
d62a17ae 6970ALIAS_HIDDEN(
6971 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6972 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6974 "Filter updates to/from this neighbor\n"
6975 "IP access-list number\n"
6976 "IP access-list number (expanded range)\n"
6977 "IP Access-list name\n"
6978 "Filter incoming updates\n"
6979 "Filter outgoing updates\n")
596c17ba 6980
718e3744 6981/* Set prefix list to the peer. */
d62a17ae 6982static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6983 afi_t afi, safi_t safi,
6984 const char *name_str,
6985 const char *direct_str)
718e3744 6986{
d62a17ae 6987 int ret;
d62a17ae 6988 int direct = FILTER_IN;
cf9ac8bf 6989 struct peer *peer;
718e3744 6990
d62a17ae 6991 peer = peer_and_group_lookup_vty(vty, ip_str);
6992 if (!peer)
6993 return CMD_WARNING_CONFIG_FAILED;
718e3744 6994
d62a17ae 6995 /* Check filter direction. */
6996 if (strncmp(direct_str, "i", 1) == 0)
6997 direct = FILTER_IN;
6998 else if (strncmp(direct_str, "o", 1) == 0)
6999 direct = FILTER_OUT;
718e3744 7000
d62a17ae 7001 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7002
d62a17ae 7003 return bgp_vty_return(vty, ret);
718e3744 7004}
7005
d62a17ae 7006static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7007 afi_t afi, safi_t safi,
7008 const char *direct_str)
718e3744 7009{
d62a17ae 7010 int ret;
7011 struct peer *peer;
7012 int direct = FILTER_IN;
718e3744 7013
d62a17ae 7014 peer = peer_and_group_lookup_vty(vty, ip_str);
7015 if (!peer)
7016 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7017
d62a17ae 7018 /* Check filter direction. */
7019 if (strncmp(direct_str, "i", 1) == 0)
7020 direct = FILTER_IN;
7021 else if (strncmp(direct_str, "o", 1) == 0)
7022 direct = FILTER_OUT;
718e3744 7023
d62a17ae 7024 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 7025
d62a17ae 7026 return bgp_vty_return(vty, ret);
718e3744 7027}
7028
7029DEFUN (neighbor_prefix_list,
7030 neighbor_prefix_list_cmd,
9ccf14f7 7031 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 7032 NEIGHBOR_STR
7033 NEIGHBOR_ADDR_STR2
7034 "Filter updates to/from this neighbor\n"
7035 "Name of a prefix list\n"
7036 "Filter incoming updates\n"
7037 "Filter outgoing updates\n")
7038{
d62a17ae 7039 int idx_peer = 1;
7040 int idx_word = 3;
7041 int idx_in_out = 4;
7042 return peer_prefix_list_set_vty(
7043 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7044 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7045}
7046
d62a17ae 7047ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7048 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7049 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7050 "Filter updates to/from this neighbor\n"
7051 "Name of a prefix list\n"
7052 "Filter incoming updates\n"
7053 "Filter outgoing updates\n")
596c17ba 7054
718e3744 7055DEFUN (no_neighbor_prefix_list,
7056 no_neighbor_prefix_list_cmd,
9ccf14f7 7057 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 7058 NO_STR
7059 NEIGHBOR_STR
7060 NEIGHBOR_ADDR_STR2
7061 "Filter updates to/from this neighbor\n"
7062 "Name of a prefix list\n"
7063 "Filter incoming updates\n"
7064 "Filter outgoing updates\n")
7065{
d62a17ae 7066 int idx_peer = 2;
7067 int idx_in_out = 5;
7068 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7069 bgp_node_afi(vty), bgp_node_safi(vty),
7070 argv[idx_in_out]->arg);
718e3744 7071}
6b0655a2 7072
d62a17ae 7073ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7074 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7075 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7076 "Filter updates to/from this neighbor\n"
7077 "Name of a prefix list\n"
7078 "Filter incoming updates\n"
7079 "Filter outgoing updates\n")
596c17ba 7080
d62a17ae 7081static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7082 safi_t safi, const char *name_str,
7083 const char *direct_str)
718e3744 7084{
d62a17ae 7085 int ret;
7086 struct peer *peer;
7087 int direct = FILTER_IN;
718e3744 7088
d62a17ae 7089 peer = peer_and_group_lookup_vty(vty, ip_str);
7090 if (!peer)
7091 return CMD_WARNING_CONFIG_FAILED;
718e3744 7092
d62a17ae 7093 /* Check filter direction. */
7094 if (strncmp(direct_str, "i", 1) == 0)
7095 direct = FILTER_IN;
7096 else if (strncmp(direct_str, "o", 1) == 0)
7097 direct = FILTER_OUT;
718e3744 7098
d62a17ae 7099 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7100
d62a17ae 7101 return bgp_vty_return(vty, ret);
718e3744 7102}
7103
d62a17ae 7104static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7105 safi_t safi, const char *direct_str)
718e3744 7106{
d62a17ae 7107 int ret;
7108 struct peer *peer;
7109 int direct = FILTER_IN;
718e3744 7110
d62a17ae 7111 peer = peer_and_group_lookup_vty(vty, ip_str);
7112 if (!peer)
7113 return CMD_WARNING_CONFIG_FAILED;
718e3744 7114
d62a17ae 7115 /* Check filter direction. */
7116 if (strncmp(direct_str, "i", 1) == 0)
7117 direct = FILTER_IN;
7118 else if (strncmp(direct_str, "o", 1) == 0)
7119 direct = FILTER_OUT;
718e3744 7120
d62a17ae 7121 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7122
d62a17ae 7123 return bgp_vty_return(vty, ret);
718e3744 7124}
7125
7126DEFUN (neighbor_filter_list,
7127 neighbor_filter_list_cmd,
9ccf14f7 7128 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7129 NEIGHBOR_STR
7130 NEIGHBOR_ADDR_STR2
7131 "Establish BGP filters\n"
7132 "AS path access-list name\n"
7133 "Filter incoming routes\n"
7134 "Filter outgoing routes\n")
7135{
d62a17ae 7136 int idx_peer = 1;
7137 int idx_word = 3;
7138 int idx_in_out = 4;
7139 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7140 bgp_node_safi(vty), argv[idx_word]->arg,
7141 argv[idx_in_out]->arg);
718e3744 7142}
7143
d62a17ae 7144ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7145 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7146 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7147 "Establish BGP filters\n"
7148 "AS path access-list name\n"
7149 "Filter incoming routes\n"
7150 "Filter outgoing routes\n")
596c17ba 7151
718e3744 7152DEFUN (no_neighbor_filter_list,
7153 no_neighbor_filter_list_cmd,
9ccf14f7 7154 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7155 NO_STR
7156 NEIGHBOR_STR
7157 NEIGHBOR_ADDR_STR2
7158 "Establish BGP filters\n"
7159 "AS path access-list name\n"
7160 "Filter incoming routes\n"
7161 "Filter outgoing routes\n")
7162{
d62a17ae 7163 int idx_peer = 2;
7164 int idx_in_out = 5;
7165 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7166 bgp_node_afi(vty), bgp_node_safi(vty),
7167 argv[idx_in_out]->arg);
718e3744 7168}
6b0655a2 7169
d62a17ae 7170ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7171 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7172 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7173 "Establish BGP filters\n"
7174 "AS path access-list name\n"
7175 "Filter incoming routes\n"
7176 "Filter outgoing routes\n")
596c17ba 7177
7f7940e6
MK
7178/* Set advertise-map to the peer. */
7179static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7180 afi_t afi, safi_t safi,
cf2ad4d8
MK
7181 const char *advertise_str,
7182 const char *condition_str, bool condition,
7183 bool set)
7f7940e6
MK
7184{
7185 int ret = CMD_WARNING_CONFIG_FAILED;
7186 struct peer *peer;
7187 struct route_map *advertise_map;
7188 struct route_map *condition_map;
7189
7190 peer = peer_and_group_lookup_vty(vty, ip_str);
7191 if (!peer)
7192 return ret;
7193
7194 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7195 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7196
cf2ad4d8
MK
7197 if (set)
7198 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7199 advertise_map, condition_str,
7200 condition_map, condition);
7201 else
7202 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7203 advertise_map, condition_str,
7204 condition_map, condition);
7f7940e6
MK
7205
7206 return bgp_vty_return(vty, ret);
7207}
7208
cf2ad4d8 7209DEFPY (neighbor_advertise_map,
7f7940e6 7210 neighbor_advertise_map_cmd,
52b84062 7211 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
cf2ad4d8 7212 NO_STR
7f7940e6
MK
7213 NEIGHBOR_STR
7214 NEIGHBOR_ADDR_STR2
7215 "Route-map to conditionally advertise routes\n"
7216 "Name of advertise map\n"
7217 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7218 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7219 "Name of the exist or non exist map\n")
7f7940e6 7220{
7f7940e6
MK
7221 bool condition = CONDITION_EXIST;
7222
52b84062 7223 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7224 condition = CONDITION_NON_EXIST;
7225
52b84062
MK
7226 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7227 bgp_node_safi(vty), advertise_str,
7228 condition_str, condition, !no);
7f7940e6
MK
7229}
7230
7231ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7232 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
7f7940e6
MK
7233 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7234 "Route-map to conditionally advertise routes\n"
7235 "Name of advertise map\n"
7236 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7237 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7238 "Name of the exist or non exist map\n")
7f7940e6 7239
718e3744 7240/* Set route-map to the peer. */
d62a17ae 7241static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7242 afi_t afi, safi_t safi, const char *name_str,
7243 const char *direct_str)
718e3744 7244{
d62a17ae 7245 int ret;
7246 struct peer *peer;
7247 int direct = RMAP_IN;
1de27621 7248 struct route_map *route_map;
718e3744 7249
d62a17ae 7250 peer = peer_and_group_lookup_vty(vty, ip_str);
7251 if (!peer)
7252 return CMD_WARNING_CONFIG_FAILED;
718e3744 7253
d62a17ae 7254 /* Check filter direction. */
7255 if (strncmp(direct_str, "in", 2) == 0)
7256 direct = RMAP_IN;
7257 else if (strncmp(direct_str, "o", 1) == 0)
7258 direct = RMAP_OUT;
718e3744 7259
1de27621
DA
7260 route_map = route_map_lookup_warn_noexist(vty, name_str);
7261 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7262
d62a17ae 7263 return bgp_vty_return(vty, ret);
718e3744 7264}
7265
d62a17ae 7266static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7267 afi_t afi, safi_t safi,
7268 const char *direct_str)
718e3744 7269{
d62a17ae 7270 int ret;
7271 struct peer *peer;
7272 int direct = RMAP_IN;
718e3744 7273
d62a17ae 7274 peer = peer_and_group_lookup_vty(vty, ip_str);
7275 if (!peer)
7276 return CMD_WARNING_CONFIG_FAILED;
718e3744 7277
d62a17ae 7278 /* Check filter direction. */
7279 if (strncmp(direct_str, "in", 2) == 0)
7280 direct = RMAP_IN;
7281 else if (strncmp(direct_str, "o", 1) == 0)
7282 direct = RMAP_OUT;
718e3744 7283
d62a17ae 7284 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 7285
d62a17ae 7286 return bgp_vty_return(vty, ret);
718e3744 7287}
7288
7289DEFUN (neighbor_route_map,
7290 neighbor_route_map_cmd,
9ccf14f7 7291 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7292 NEIGHBOR_STR
7293 NEIGHBOR_ADDR_STR2
7294 "Apply route map to neighbor\n"
7295 "Name of route map\n"
7296 "Apply map to incoming routes\n"
2a3d5731 7297 "Apply map to outbound routes\n")
718e3744 7298{
d62a17ae 7299 int idx_peer = 1;
7300 int idx_word = 3;
7301 int idx_in_out = 4;
7302 return peer_route_map_set_vty(
7303 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7304 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7305}
7306
d62a17ae 7307ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7308 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7309 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7310 "Apply route map to neighbor\n"
7311 "Name of route map\n"
7312 "Apply map to incoming routes\n"
7313 "Apply map to outbound routes\n")
596c17ba 7314
718e3744 7315DEFUN (no_neighbor_route_map,
7316 no_neighbor_route_map_cmd,
9ccf14f7 7317 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7318 NO_STR
7319 NEIGHBOR_STR
7320 NEIGHBOR_ADDR_STR2
7321 "Apply route map to neighbor\n"
7322 "Name of route map\n"
7323 "Apply map to incoming routes\n"
2a3d5731 7324 "Apply map to outbound routes\n")
718e3744 7325{
d62a17ae 7326 int idx_peer = 2;
7327 int idx_in_out = 5;
7328 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7329 bgp_node_afi(vty), bgp_node_safi(vty),
7330 argv[idx_in_out]->arg);
718e3744 7331}
6b0655a2 7332
d62a17ae 7333ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7334 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7335 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7336 "Apply route map to neighbor\n"
7337 "Name of route map\n"
7338 "Apply map to incoming routes\n"
7339 "Apply map to outbound routes\n")
596c17ba 7340
718e3744 7341/* Set unsuppress-map to the peer. */
d62a17ae 7342static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7343 afi_t afi, safi_t safi,
7344 const char *name_str)
718e3744 7345{
d62a17ae 7346 int ret;
7347 struct peer *peer;
1de27621 7348 struct route_map *route_map;
718e3744 7349
d62a17ae 7350 peer = peer_and_group_lookup_vty(vty, ip_str);
7351 if (!peer)
7352 return CMD_WARNING_CONFIG_FAILED;
718e3744 7353
1de27621
DA
7354 route_map = route_map_lookup_warn_noexist(vty, name_str);
7355 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7356
d62a17ae 7357 return bgp_vty_return(vty, ret);
718e3744 7358}
7359
7360/* Unset route-map from the peer. */
d62a17ae 7361static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7362 afi_t afi, safi_t safi)
718e3744 7363{
d62a17ae 7364 int ret;
7365 struct peer *peer;
718e3744 7366
d62a17ae 7367 peer = peer_and_group_lookup_vty(vty, ip_str);
7368 if (!peer)
7369 return CMD_WARNING_CONFIG_FAILED;
718e3744 7370
d62a17ae 7371 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7372
d62a17ae 7373 return bgp_vty_return(vty, ret);
718e3744 7374}
7375
7376DEFUN (neighbor_unsuppress_map,
7377 neighbor_unsuppress_map_cmd,
9ccf14f7 7378 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7379 NEIGHBOR_STR
7380 NEIGHBOR_ADDR_STR2
7381 "Route-map to selectively unsuppress suppressed routes\n"
7382 "Name of route map\n")
7383{
d62a17ae 7384 int idx_peer = 1;
7385 int idx_word = 3;
7386 return peer_unsuppress_map_set_vty(
7387 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7388 argv[idx_word]->arg);
718e3744 7389}
7390
d62a17ae 7391ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7392 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7393 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7394 "Route-map to selectively unsuppress suppressed routes\n"
7395 "Name of route map\n")
596c17ba 7396
718e3744 7397DEFUN (no_neighbor_unsuppress_map,
7398 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7399 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7400 NO_STR
7401 NEIGHBOR_STR
7402 NEIGHBOR_ADDR_STR2
7403 "Route-map to selectively unsuppress suppressed routes\n"
7404 "Name of route map\n")
7405{
d62a17ae 7406 int idx_peer = 2;
7407 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7408 bgp_node_afi(vty),
7409 bgp_node_safi(vty));
718e3744 7410}
6b0655a2 7411
d62a17ae 7412ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7413 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7414 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7415 "Route-map to selectively unsuppress suppressed routes\n"
7416 "Name of route map\n")
596c17ba 7417
d62a17ae 7418static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7419 afi_t afi, safi_t safi,
7420 const char *num_str,
7421 const char *threshold_str, int warning,
9cbd06e0
DA
7422 const char *restart_str,
7423 const char *force_str)
718e3744 7424{
d62a17ae 7425 int ret;
7426 struct peer *peer;
d7c0a89a
QY
7427 uint32_t max;
7428 uint8_t threshold;
7429 uint16_t restart;
718e3744 7430
d62a17ae 7431 peer = peer_and_group_lookup_vty(vty, ip_str);
7432 if (!peer)
7433 return CMD_WARNING_CONFIG_FAILED;
718e3744 7434
d62a17ae 7435 max = strtoul(num_str, NULL, 10);
7436 if (threshold_str)
7437 threshold = atoi(threshold_str);
7438 else
7439 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 7440
d62a17ae 7441 if (restart_str)
7442 restart = atoi(restart_str);
7443 else
7444 restart = 0;
0a486e5f 7445
d62a17ae 7446 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
9cbd06e0 7447 restart, force_str ? true : false);
718e3744 7448
d62a17ae 7449 return bgp_vty_return(vty, ret);
718e3744 7450}
7451
d62a17ae 7452static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7453 afi_t afi, safi_t safi)
718e3744 7454{
d62a17ae 7455 int ret;
7456 struct peer *peer;
718e3744 7457
d62a17ae 7458 peer = peer_and_group_lookup_vty(vty, ip_str);
7459 if (!peer)
7460 return CMD_WARNING_CONFIG_FAILED;
718e3744 7461
d62a17ae 7462 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 7463
d62a17ae 7464 return bgp_vty_return(vty, ret);
718e3744 7465}
7466
fde246e8
DA
7467/* Maximum number of prefix to be sent to the neighbor. */
7468DEFUN(neighbor_maximum_prefix_out,
7469 neighbor_maximum_prefix_out_cmd,
7470 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7471 NEIGHBOR_STR
7472 NEIGHBOR_ADDR_STR2
7473 "Maximum number of prefixes to be sent to this peer\n"
7474 "Maximum no. of prefix limit\n")
7475{
7476 int idx_peer = 1;
7477 int idx_number = 3;
7478 struct peer *peer;
7479 uint32_t max;
7480 afi_t afi = bgp_node_afi(vty);
7481 safi_t safi = bgp_node_safi(vty);
7482
7483 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7484 if (!peer)
7485 return CMD_WARNING_CONFIG_FAILED;
7486
7487 max = strtoul(argv[idx_number]->arg, NULL, 10);
7488
7489 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7490 peer->pmax_out[afi][safi] = max;
7491
7492 return CMD_SUCCESS;
7493}
7494
7495DEFUN(no_neighbor_maximum_prefix_out,
7496 no_neighbor_maximum_prefix_out_cmd,
7497 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7498 NO_STR
7499 NEIGHBOR_STR
7500 NEIGHBOR_ADDR_STR2
7501 "Maximum number of prefixes to be sent to this peer\n")
7502{
7503 int idx_peer = 2;
7504 struct peer *peer;
7505 afi_t afi = bgp_node_afi(vty);
7506 safi_t safi = bgp_node_safi(vty);
7507
7508 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7509 if (!peer)
7510 return CMD_WARNING_CONFIG_FAILED;
7511
ae00326a 7512 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
fde246e8
DA
7513 peer->pmax_out[afi][safi] = 0;
7514
7515 return CMD_SUCCESS;
7516}
7517
9cbd06e0
DA
7518/* Maximum number of prefix configuration. Prefix count is different
7519 for each peer configuration. So this configuration can be set for
718e3744 7520 each peer configuration. */
7521DEFUN (neighbor_maximum_prefix,
7522 neighbor_maximum_prefix_cmd,
9cbd06e0 7523 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
718e3744 7524 NEIGHBOR_STR
7525 NEIGHBOR_ADDR_STR2
7526 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7527 "maximum no. of prefix limit\n"
7528 "Force checking all received routes not only accepted\n")
718e3744 7529{
d62a17ae 7530 int idx_peer = 1;
7531 int idx_number = 3;
9cbd06e0
DA
7532 int idx_force = 0;
7533 char *force = NULL;
7534
7535 if (argv_find(argv, argc, "force", &idx_force))
7536 force = argv[idx_force]->arg;
7537
d62a17ae 7538 return peer_maximum_prefix_set_vty(
7539 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7540 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7541}
7542
d62a17ae 7543ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7544 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7545 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7546 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7547 "maximum no. of prefix limit\n"
7548 "Force checking all received routes not only accepted\n")
596c17ba 7549
e0701b79 7550DEFUN (neighbor_maximum_prefix_threshold,
7551 neighbor_maximum_prefix_threshold_cmd,
9cbd06e0 7552 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
e0701b79 7553 NEIGHBOR_STR
7554 NEIGHBOR_ADDR_STR2
7555 "Maximum number of prefix accept from this peer\n"
7556 "maximum no. of prefix limit\n"
9cbd06e0
DA
7557 "Threshold value (%) at which to generate a warning msg\n"
7558 "Force checking all received routes not only accepted\n")
e0701b79 7559{
d62a17ae 7560 int idx_peer = 1;
7561 int idx_number = 3;
7562 int idx_number_2 = 4;
9cbd06e0
DA
7563 int idx_force = 0;
7564 char *force = NULL;
7565
7566 if (argv_find(argv, argc, "force", &idx_force))
7567 force = argv[idx_force]->arg;
7568
d62a17ae 7569 return peer_maximum_prefix_set_vty(
7570 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7571 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7572}
e0701b79 7573
d62a17ae 7574ALIAS_HIDDEN(
7575 neighbor_maximum_prefix_threshold,
7576 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7577 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7578 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7579 "Maximum number of prefix accept from this peer\n"
7580 "maximum no. of prefix limit\n"
9cbd06e0
DA
7581 "Threshold value (%) at which to generate a warning msg\n"
7582 "Force checking all received routes not only accepted\n")
596c17ba 7583
718e3744 7584DEFUN (neighbor_maximum_prefix_warning,
7585 neighbor_maximum_prefix_warning_cmd,
9cbd06e0 7586 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
718e3744 7587 NEIGHBOR_STR
7588 NEIGHBOR_ADDR_STR2
7589 "Maximum number of prefix accept from this peer\n"
7590 "maximum no. of prefix limit\n"
9cbd06e0
DA
7591 "Only give warning message when limit is exceeded\n"
7592 "Force checking all received routes not only accepted\n")
718e3744 7593{
d62a17ae 7594 int idx_peer = 1;
7595 int idx_number = 3;
9cbd06e0
DA
7596 int idx_force = 0;
7597 char *force = NULL;
7598
7599 if (argv_find(argv, argc, "force", &idx_force))
7600 force = argv[idx_force]->arg;
7601
d62a17ae 7602 return peer_maximum_prefix_set_vty(
7603 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7604 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7605}
7606
d62a17ae 7607ALIAS_HIDDEN(
7608 neighbor_maximum_prefix_warning,
7609 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7610 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7611 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7612 "Maximum number of prefix accept from this peer\n"
7613 "maximum no. of prefix limit\n"
9cbd06e0
DA
7614 "Only give warning message when limit is exceeded\n"
7615 "Force checking all received routes not only accepted\n")
596c17ba 7616
e0701b79 7617DEFUN (neighbor_maximum_prefix_threshold_warning,
7618 neighbor_maximum_prefix_threshold_warning_cmd,
9cbd06e0 7619 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
e0701b79 7620 NEIGHBOR_STR
7621 NEIGHBOR_ADDR_STR2
7622 "Maximum number of prefix accept from this peer\n"
7623 "maximum no. of prefix limit\n"
7624 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7625 "Only give warning message when limit is exceeded\n"
7626 "Force checking all received routes not only accepted\n")
e0701b79 7627{
d62a17ae 7628 int idx_peer = 1;
7629 int idx_number = 3;
7630 int idx_number_2 = 4;
9cbd06e0
DA
7631 int idx_force = 0;
7632 char *force = NULL;
7633
7634 if (argv_find(argv, argc, "force", &idx_force))
7635 force = argv[idx_force]->arg;
7636
d62a17ae 7637 return peer_maximum_prefix_set_vty(
7638 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7639 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7640}
7641
d62a17ae 7642ALIAS_HIDDEN(
7643 neighbor_maximum_prefix_threshold_warning,
7644 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7645 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7646 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7647 "Maximum number of prefix accept from this peer\n"
7648 "maximum no. of prefix limit\n"
7649 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7650 "Only give warning message when limit is exceeded\n"
7651 "Force checking all received routes not only accepted\n")
596c17ba 7652
0a486e5f 7653DEFUN (neighbor_maximum_prefix_restart,
7654 neighbor_maximum_prefix_restart_cmd,
9cbd06e0 7655 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
0a486e5f 7656 NEIGHBOR_STR
7657 NEIGHBOR_ADDR_STR2
7658 "Maximum number of prefix accept from this peer\n"
7659 "maximum no. of prefix limit\n"
7660 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7661 "Restart interval in minutes\n"
7662 "Force checking all received routes not only accepted\n")
0a486e5f 7663{
d62a17ae 7664 int idx_peer = 1;
7665 int idx_number = 3;
7666 int idx_number_2 = 5;
9cbd06e0
DA
7667 int idx_force = 0;
7668 char *force = NULL;
7669
7670 if (argv_find(argv, argc, "force", &idx_force))
7671 force = argv[idx_force]->arg;
7672
d62a17ae 7673 return peer_maximum_prefix_set_vty(
7674 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7675 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7676}
7677
d62a17ae 7678ALIAS_HIDDEN(
7679 neighbor_maximum_prefix_restart,
7680 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7681 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7682 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7683 "Maximum number of prefix accept from this peer\n"
7684 "maximum no. of prefix limit\n"
7685 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7686 "Restart interval in minutes\n"
7687 "Force checking all received routes not only accepted\n")
596c17ba 7688
0a486e5f 7689DEFUN (neighbor_maximum_prefix_threshold_restart,
7690 neighbor_maximum_prefix_threshold_restart_cmd,
9cbd06e0 7691 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
0a486e5f 7692 NEIGHBOR_STR
7693 NEIGHBOR_ADDR_STR2
16cedbb0 7694 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 7695 "maximum no. of prefix limit\n"
7696 "Threshold value (%) at which to generate a warning msg\n"
7697 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7698 "Restart interval in minutes\n"
7699 "Force checking all received routes not only accepted\n")
0a486e5f 7700{
d62a17ae 7701 int idx_peer = 1;
7702 int idx_number = 3;
7703 int idx_number_2 = 4;
7704 int idx_number_3 = 6;
9cbd06e0
DA
7705 int idx_force = 0;
7706 char *force = NULL;
7707
7708 if (argv_find(argv, argc, "force", &idx_force))
7709 force = argv[idx_force]->arg;
7710
d62a17ae 7711 return peer_maximum_prefix_set_vty(
7712 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7713 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
9cbd06e0 7714 argv[idx_number_3]->arg, force);
d62a17ae 7715}
7716
7717ALIAS_HIDDEN(
7718 neighbor_maximum_prefix_threshold_restart,
7719 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7720 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7721 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7722 "Maximum number of prefixes to accept from this peer\n"
7723 "maximum no. of prefix limit\n"
7724 "Threshold value (%) at which to generate a warning msg\n"
7725 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7726 "Restart interval in minutes\n"
7727 "Force checking all received routes not only accepted\n")
596c17ba 7728
718e3744 7729DEFUN (no_neighbor_maximum_prefix,
7730 no_neighbor_maximum_prefix_cmd,
9cbd06e0 7731 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
718e3744 7732 NO_STR
7733 NEIGHBOR_STR
7734 NEIGHBOR_ADDR_STR2
16cedbb0 7735 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
7736 "maximum no. of prefix limit\n"
7737 "Threshold value (%) at which to generate a warning msg\n"
7738 "Restart bgp connection after limit is exceeded\n"
16cedbb0 7739 "Restart interval in minutes\n"
9cbd06e0
DA
7740 "Only give warning message when limit is exceeded\n"
7741 "Force checking all received routes not only accepted\n")
718e3744 7742{
d62a17ae 7743 int idx_peer = 2;
7744 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7745 bgp_node_afi(vty),
7746 bgp_node_safi(vty));
718e3744 7747}
e52702f2 7748
d62a17ae 7749ALIAS_HIDDEN(
7750 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7751 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7752 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7753 "Maximum number of prefixes to accept from this peer\n"
7754 "maximum no. of prefix limit\n"
7755 "Threshold value (%) at which to generate a warning msg\n"
7756 "Restart bgp connection after limit is exceeded\n"
7757 "Restart interval in minutes\n"
9cbd06e0
DA
7758 "Only give warning message when limit is exceeded\n"
7759 "Force checking all received routes not only accepted\n")
596c17ba 7760
718e3744 7761
718e3744 7762/* "neighbor allowas-in" */
7763DEFUN (neighbor_allowas_in,
7764 neighbor_allowas_in_cmd,
fd8503f5 7765 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7766 NEIGHBOR_STR
7767 NEIGHBOR_ADDR_STR2
31500417 7768 "Accept as-path with my AS present in it\n"
f79f7a7b 7769 "Number of occurrences of AS number\n"
fd8503f5 7770 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7771{
d62a17ae 7772 int idx_peer = 1;
7773 int idx_number_origin = 3;
7774 int ret;
7775 int origin = 0;
7776 struct peer *peer;
7777 int allow_num = 0;
7778
7779 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7780 if (!peer)
7781 return CMD_WARNING_CONFIG_FAILED;
7782
7783 if (argc <= idx_number_origin)
7784 allow_num = 3;
7785 else {
7786 if (argv[idx_number_origin]->type == WORD_TKN)
7787 origin = 1;
7788 else
7789 allow_num = atoi(argv[idx_number_origin]->arg);
7790 }
7791
7792 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7793 allow_num, origin);
7794
7795 return bgp_vty_return(vty, ret);
7796}
7797
7798ALIAS_HIDDEN(
7799 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7800 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7801 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7802 "Accept as-path with my AS present in it\n"
f79f7a7b 7803 "Number of occurrences of AS number\n"
d62a17ae 7804 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7805
718e3744 7806DEFUN (no_neighbor_allowas_in,
7807 no_neighbor_allowas_in_cmd,
fd8503f5 7808 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7809 NO_STR
7810 NEIGHBOR_STR
7811 NEIGHBOR_ADDR_STR2
8334fd5a 7812 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7813 "Number of occurrences of AS number\n"
fd8503f5 7814 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7815{
d62a17ae 7816 int idx_peer = 2;
7817 int ret;
7818 struct peer *peer;
718e3744 7819
d62a17ae 7820 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7821 if (!peer)
7822 return CMD_WARNING_CONFIG_FAILED;
718e3744 7823
d62a17ae 7824 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
7825 bgp_node_safi(vty));
718e3744 7826
d62a17ae 7827 return bgp_vty_return(vty, ret);
718e3744 7828}
6b0655a2 7829
d62a17ae 7830ALIAS_HIDDEN(
7831 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
7832 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7833 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7834 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7835 "Number of occurrences of AS number\n"
d62a17ae 7836 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7837
fa411a21
NH
7838DEFUN (neighbor_ttl_security,
7839 neighbor_ttl_security_cmd,
7ebe625c 7840 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 7841 NEIGHBOR_STR
7ebe625c 7842 NEIGHBOR_ADDR_STR2
16cedbb0 7843 "BGP ttl-security parameters\n"
d7fa34c1
QY
7844 "Specify the maximum number of hops to the BGP peer\n"
7845 "Number of hops to BGP peer\n")
fa411a21 7846{
d62a17ae 7847 int idx_peer = 1;
7848 int idx_number = 4;
7849 struct peer *peer;
7850 int gtsm_hops;
7851
7852 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7853 if (!peer)
7854 return CMD_WARNING_CONFIG_FAILED;
7855
7856 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
7857
7ebe625c
QY
7858 /*
7859 * If 'neighbor swpX', then this is for directly connected peers,
7860 * we should not accept a ttl-security hops value greater than 1.
7861 */
e2521429 7862 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7ebe625c
QY
7863 vty_out(vty,
7864 "%s is directly connected peer, hops cannot exceed 1\n",
7865 argv[idx_peer]->arg);
7866 return CMD_WARNING_CONFIG_FAILED;
7867 }
7868
d62a17ae 7869 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
7870}
7871
7872DEFUN (no_neighbor_ttl_security,
7873 no_neighbor_ttl_security_cmd,
7ebe625c 7874 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
7875 NO_STR
7876 NEIGHBOR_STR
7ebe625c 7877 NEIGHBOR_ADDR_STR2
16cedbb0 7878 "BGP ttl-security parameters\n"
3a2d747c
QY
7879 "Specify the maximum number of hops to the BGP peer\n"
7880 "Number of hops to BGP peer\n")
fa411a21 7881{
d62a17ae 7882 int idx_peer = 2;
7883 struct peer *peer;
fa411a21 7884
d62a17ae 7885 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7886 if (!peer)
7887 return CMD_WARNING_CONFIG_FAILED;
fa411a21 7888
d62a17ae 7889 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 7890}
6b0655a2 7891
adbac85e
DW
7892DEFUN (neighbor_addpath_tx_all_paths,
7893 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7894 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7895 NEIGHBOR_STR
7896 NEIGHBOR_ADDR_STR2
7897 "Use addpath to advertise all paths to a neighbor\n")
7898{
d62a17ae 7899 int idx_peer = 1;
7900 struct peer *peer;
adbac85e 7901
d62a17ae 7902 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7903 if (!peer)
7904 return CMD_WARNING_CONFIG_FAILED;
adbac85e 7905
dcc68b5e
MS
7906 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7907 BGP_ADDPATH_ALL);
7908 return CMD_SUCCESS;
adbac85e
DW
7909}
7910
d62a17ae 7911ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
7912 neighbor_addpath_tx_all_paths_hidden_cmd,
7913 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7914 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7915 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7916
adbac85e
DW
7917DEFUN (no_neighbor_addpath_tx_all_paths,
7918 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7919 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7920 NO_STR
7921 NEIGHBOR_STR
7922 NEIGHBOR_ADDR_STR2
7923 "Use addpath to advertise all paths to a neighbor\n")
7924{
d62a17ae 7925 int idx_peer = 2;
dcc68b5e
MS
7926 struct peer *peer;
7927
7928 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7929 if (!peer)
7930 return CMD_WARNING_CONFIG_FAILED;
7931
7932 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7933 != BGP_ADDPATH_ALL) {
7934 vty_out(vty,
7935 "%% Peer not currently configured to transmit all paths.");
7936 return CMD_WARNING_CONFIG_FAILED;
7937 }
7938
7939 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7940 BGP_ADDPATH_NONE);
7941
7942 return CMD_SUCCESS;
adbac85e
DW
7943}
7944
d62a17ae 7945ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7946 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7947 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7948 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7949 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7950
06370dac
DW
7951DEFUN (neighbor_addpath_tx_bestpath_per_as,
7952 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7953 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7954 NEIGHBOR_STR
7955 NEIGHBOR_ADDR_STR2
7956 "Use addpath to advertise the bestpath per each neighboring AS\n")
7957{
d62a17ae 7958 int idx_peer = 1;
7959 struct peer *peer;
06370dac 7960
d62a17ae 7961 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7962 if (!peer)
7963 return CMD_WARNING_CONFIG_FAILED;
06370dac 7964
dcc68b5e
MS
7965 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7966 BGP_ADDPATH_BEST_PER_AS);
7967
7968 return CMD_SUCCESS;
06370dac
DW
7969}
7970
d62a17ae 7971ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7972 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7973 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7975 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7976
06370dac
DW
7977DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7978 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7979 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7980 NO_STR
7981 NEIGHBOR_STR
7982 NEIGHBOR_ADDR_STR2
7983 "Use addpath to advertise the bestpath per each neighboring AS\n")
7984{
d62a17ae 7985 int idx_peer = 2;
dcc68b5e
MS
7986 struct peer *peer;
7987
7988 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7989 if (!peer)
7990 return CMD_WARNING_CONFIG_FAILED;
7991
7992 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7993 != BGP_ADDPATH_BEST_PER_AS) {
7994 vty_out(vty,
7995 "%% Peer not currently configured to transmit all best path per as.");
7996 return CMD_WARNING_CONFIG_FAILED;
7997 }
7998
7999 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8000 BGP_ADDPATH_NONE);
8001
8002 return CMD_SUCCESS;
06370dac
DW
8003}
8004
d62a17ae 8005ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8006 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8007 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8008 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8009 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8010
2b31007c
RZ
8011DEFPY(
8012 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8013 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8014 NEIGHBOR_STR
8015 NEIGHBOR_ADDR_STR2
8016 "Detect AS loops before sending to neighbor\n")
8017{
8018 struct peer *peer;
8019
8020 peer = peer_and_group_lookup_vty(vty, neighbor);
8021 if (!peer)
8022 return CMD_WARNING_CONFIG_FAILED;
8023
8024 peer->as_path_loop_detection = true;
8025
8026 return CMD_SUCCESS;
8027}
8028
8029DEFPY(
8030 no_neighbor_aspath_loop_detection,
8031 no_neighbor_aspath_loop_detection_cmd,
8032 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8033 NO_STR
8034 NEIGHBOR_STR
8035 NEIGHBOR_ADDR_STR2
8036 "Detect AS loops before sending to neighbor\n")
8037{
8038 struct peer *peer;
8039
8040 peer = peer_and_group_lookup_vty(vty, neighbor);
8041 if (!peer)
8042 return CMD_WARNING_CONFIG_FAILED;
8043
8044 peer->as_path_loop_detection = false;
8045
8046 return CMD_SUCCESS;
8047}
8048
b9c7bc5a 8049static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8050 struct ecommunity **list, bool is_rt6)
ddb5b488 8051{
b9c7bc5a
PZ
8052 struct ecommunity *ecom = NULL;
8053 struct ecommunity *ecomadd;
ddb5b488 8054
b9c7bc5a 8055 for (; argc; --argc, ++argv) {
9a659715
PG
8056 if (is_rt6)
8057 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8058 ECOMMUNITY_ROUTE_TARGET,
8059 0);
8060 else
8061 ecomadd = ecommunity_str2com(argv[0]->arg,
8062 ECOMMUNITY_ROUTE_TARGET,
8063 0);
b9c7bc5a
PZ
8064 if (!ecomadd) {
8065 vty_out(vty, "Malformed community-list value\n");
8066 if (ecom)
8067 ecommunity_free(&ecom);
8068 return CMD_WARNING_CONFIG_FAILED;
8069 }
ddb5b488 8070
b9c7bc5a
PZ
8071 if (ecom) {
8072 ecommunity_merge(ecom, ecomadd);
8073 ecommunity_free(&ecomadd);
8074 } else {
8075 ecom = ecomadd;
8076 }
8077 }
8078
8079 if (*list) {
8080 ecommunity_free(&*list);
ddb5b488 8081 }
b9c7bc5a
PZ
8082 *list = ecom;
8083
8084 return CMD_SUCCESS;
ddb5b488
PZ
8085}
8086
37a87b8f
CS
8087bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8088 bool v2vimport, char *errmsg, size_t errmsg_len)
8089{
8090 if (!v2vimport) {
8091 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8092 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8093 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8094 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8095 snprintf(
8096 errmsg, errmsg_len, "%s",
8097 "%% error: Please unconfigure import vrf commands before using vpn commands");
8098 return false;
8099 }
8100 } else {
8101 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8102 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8103 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8104 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8105 snprintf(
8106 errmsg, errmsg_len, "%s",
8107 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8108 return false;
8109 }
8110 }
8111 return true;
8112}
8113
0ca70ba5
DS
8114/*
8115 * v2vimport is true if we are handling a `import vrf ...` command
8116 */
8117static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8118{
0ca70ba5
DS
8119 afi_t afi;
8120
ddb5b488 8121 switch (vty->node) {
b9c7bc5a 8122 case BGP_IPV4_NODE:
0ca70ba5
DS
8123 afi = AFI_IP;
8124 break;
b9c7bc5a 8125 case BGP_IPV6_NODE:
0ca70ba5
DS
8126 afi = AFI_IP6;
8127 break;
ddb5b488
PZ
8128 default:
8129 vty_out(vty,
b9c7bc5a 8130 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8131 return AFI_MAX;
ddb5b488 8132 }
69b07479 8133
0ca70ba5
DS
8134 if (!v2vimport) {
8135 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8136 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8137 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8138 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8139 vty_out(vty,
8140 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8141 return AFI_MAX;
8142 }
8143 } else {
8144 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8145 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8146 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8147 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8148 vty_out(vty,
8149 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8150 return AFI_MAX;
8151 }
8152 }
8153 return afi;
ddb5b488
PZ
8154}
8155
37a87b8f
CS
8156DEFPY_YANG(
8157 af_rd_vpn_export,
8158 af_rd_vpn_export_cmd,
8159 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8160 NO_STR
8161 "Specify route distinguisher\n"
8162 "Between current address-family and vpn\n"
8163 "For routes leaked from current address-family to vpn\n"
8164 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8165{
37a87b8f 8166 char base_xpath[XPATH_MAXLEN];
ddb5b488 8167 afi_t afi;
37a87b8f 8168 safi_t safi;
b9c7bc5a 8169 int idx = 0;
b9c7bc5a 8170
37a87b8f
CS
8171 afi = bgp_node_afi(vty);
8172 safi = bgp_node_safi(vty);
ddb5b488 8173
37a87b8f
CS
8174 snprintf(
8175 base_xpath, sizeof(base_xpath),
8176 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
8177 yang_afi_safi_value2identity(afi, safi),
8178 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 8179
37a87b8f
CS
8180 if (argv_find(argv, argc, "no", &idx))
8181 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
8182 else
8183 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
ddb5b488 8184
37a87b8f
CS
8185 return nb_cli_apply_changes(vty, base_xpath);
8186}
ddb5b488 8187
37a87b8f
CS
8188void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
8189 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8190{
8191 int indent = 2;
69b07479 8192
37a87b8f
CS
8193 vty_out(vty, "%*srd vpn export %s\n", indent, "",
8194 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
8195}
8196
b9c7bc5a
PZ
8197ALIAS (af_rd_vpn_export,
8198 af_no_rd_vpn_export_cmd,
8199 "no rd vpn export",
ddb5b488 8200 NO_STR
b9c7bc5a
PZ
8201 "Specify route distinguisher\n"
8202 "Between current address-family and vpn\n"
8203 "For routes leaked from current address-family to vpn\n")
ddb5b488 8204
b9c7bc5a
PZ
8205DEFPY (af_label_vpn_export,
8206 af_label_vpn_export_cmd,
e70e9f8e 8207 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8208 NO_STR
ddb5b488 8209 "label value for VRF\n"
b9c7bc5a
PZ
8210 "Between current address-family and vpn\n"
8211 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8212 "Label Value <0-1048575>\n"
8213 "Automatically assign a label\n")
ddb5b488
PZ
8214{
8215 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8216 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8217 afi_t afi;
b9c7bc5a 8218 int idx = 0;
c6423c31 8219 bool yes = true;
b9c7bc5a
PZ
8220
8221 if (argv_find(argv, argc, "no", &idx))
c6423c31 8222 yes = false;
ddb5b488 8223
21a16cc2
PZ
8224 /* If "no ...", squash trailing parameter */
8225 if (!yes)
8226 label_auto = NULL;
8227
e70e9f8e
PZ
8228 if (yes) {
8229 if (!label_auto)
8230 label = label_val; /* parser should force unsigned */
8231 }
ddb5b488 8232
0ca70ba5 8233 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8234 if (afi == AFI_MAX)
8235 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8236
e70e9f8e 8237
69b07479
DS
8238 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8239 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8240 /* no change */
8241 return CMD_SUCCESS;
e70e9f8e 8242
69b07479
DS
8243 /*
8244 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8245 */
8246 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8247 bgp_get_default(), bgp);
8248
8249 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8250 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8251
8252 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8253
8254 /*
8255 * label has previously been automatically
8256 * assigned by labelpool: release it
8257 *
8258 * NB if tovpn_label == MPLS_LABEL_NONE it
8259 * means the automatic assignment is in flight
8260 * and therefore the labelpool callback must
8261 * detect that the auto label is not needed.
8262 */
8263
8264 bgp_lp_release(LP_TYPE_VRF,
8265 &bgp->vpn_policy[afi],
8266 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8267 }
69b07479
DS
8268 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8269 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8270 }
ddb5b488 8271
69b07479
DS
8272 bgp->vpn_policy[afi].tovpn_label = label;
8273 if (label_auto) {
8274 SET_FLAG(bgp->vpn_policy[afi].flags,
8275 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8276 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8277 vpn_leak_label_callback);
ddb5b488
PZ
8278 }
8279
69b07479
DS
8280 /* post-change: re-export vpn routes */
8281 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8282 bgp_get_default(), bgp);
8283
ddb5b488
PZ
8284 return CMD_SUCCESS;
8285}
8286
b9c7bc5a
PZ
8287ALIAS (af_label_vpn_export,
8288 af_no_label_vpn_export_cmd,
8289 "no label vpn export",
8290 NO_STR
8291 "label value for VRF\n"
8292 "Between current address-family and vpn\n"
8293 "For routes leaked from current address-family to vpn\n")
ddb5b488 8294
37a87b8f 8295DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 8296 af_nexthop_vpn_export_cmd,
8c85ca28 8297 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8298 NO_STR
ddb5b488 8299 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8300 "Between current address-family and vpn\n"
8301 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8302 "IPv4 prefix\n"
8303 "IPv6 prefix\n")
8304{
37a87b8f 8305 char base_xpath[XPATH_MAXLEN];
ddb5b488 8306 afi_t afi;
37a87b8f
CS
8307 safi_t safi;
8308 int idx = 0;
ddb5b488
PZ
8309 struct prefix p;
8310
8c85ca28
QY
8311 if (!no) {
8312 if (!nexthop_su) {
8313 vty_out(vty, "%% Nexthop required\n");
8314 return CMD_WARNING_CONFIG_FAILED;
8315 }
8c85ca28 8316 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8317 return CMD_WARNING_CONFIG_FAILED;
8318 }
ddb5b488 8319
37a87b8f
CS
8320 afi = bgp_node_afi(vty);
8321 safi = bgp_node_safi(vty);
ddb5b488 8322
37a87b8f
CS
8323 snprintf(
8324 base_xpath, sizeof(base_xpath),
8325 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
8326 yang_afi_safi_value2identity(afi, safi),
8327 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 8328
37a87b8f
CS
8329 if (argv_find(argv, argc, "no", &idx))
8330 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
8331 else
8332 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
8333 nexthop_su_str);
ddb5b488 8334
37a87b8f
CS
8335 return nb_cli_apply_changes(vty, base_xpath);
8336}
69b07479 8337
37a87b8f
CS
8338void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
8339 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8340{
8341 int indent = 2;
8342
8343 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
8344 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
8345}
8346
b9c7bc5a 8347static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8348{
b9c7bc5a
PZ
8349 if (!strcmp(dstr, "import")) {
8350 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8351 } else if (!strcmp(dstr, "export")) {
8352 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8353 } else if (!strcmp(dstr, "both")) {
8354 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8355 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8356 } else {
8357 vty_out(vty, "%% direction parse error\n");
8358 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8359 }
ddb5b488
PZ
8360 return CMD_SUCCESS;
8361}
8362
b9c7bc5a
PZ
8363DEFPY (af_rt_vpn_imexport,
8364 af_rt_vpn_imexport_cmd,
8365 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8366 NO_STR
8367 "Specify route target list\n"
ddb5b488 8368 "Specify route target list\n"
b9c7bc5a
PZ
8369 "Between current address-family and vpn\n"
8370 "For routes leaked from vpn to current address-family: match any\n"
8371 "For routes leaked from current address-family to vpn: set\n"
8372 "both import: match any and export: set\n"
ddb5b488
PZ
8373 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8374{
8375 VTY_DECLVAR_CONTEXT(bgp, bgp);
8376 int ret;
8377 struct ecommunity *ecom = NULL;
8378 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8379 vpn_policy_direction_t dir;
8380 afi_t afi;
8381 int idx = 0;
c6423c31 8382 bool yes = true;
ddb5b488 8383
b9c7bc5a 8384 if (argv_find(argv, argc, "no", &idx))
c6423c31 8385 yes = false;
b9c7bc5a 8386
0ca70ba5 8387 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8388 if (afi == AFI_MAX)
8389 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8390
b9c7bc5a 8391 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8392 if (ret != CMD_SUCCESS)
8393 return ret;
8394
b9c7bc5a
PZ
8395 if (yes) {
8396 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8397 vty_out(vty, "%% Missing RTLIST\n");
8398 return CMD_WARNING_CONFIG_FAILED;
8399 }
c6423c31 8400 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8401 if (ret != CMD_SUCCESS) {
8402 return ret;
8403 }
ddb5b488
PZ
8404 }
8405
69b07479
DS
8406 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8407 if (!dodir[dir])
ddb5b488 8408 continue;
ddb5b488 8409
69b07479 8410 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8411
69b07479
DS
8412 if (yes) {
8413 if (bgp->vpn_policy[afi].rtlist[dir])
8414 ecommunity_free(
8415 &bgp->vpn_policy[afi].rtlist[dir]);
8416 bgp->vpn_policy[afi].rtlist[dir] =
8417 ecommunity_dup(ecom);
8418 } else {
8419 if (bgp->vpn_policy[afi].rtlist[dir])
8420 ecommunity_free(
8421 &bgp->vpn_policy[afi].rtlist[dir]);
8422 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8423 }
69b07479
DS
8424
8425 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8426 }
69b07479 8427
d555f3e9
PZ
8428 if (ecom)
8429 ecommunity_free(&ecom);
ddb5b488
PZ
8430
8431 return CMD_SUCCESS;
8432}
8433
b9c7bc5a
PZ
8434ALIAS (af_rt_vpn_imexport,
8435 af_no_rt_vpn_imexport_cmd,
8436 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8437 NO_STR
8438 "Specify route target list\n"
b9c7bc5a
PZ
8439 "Specify route target list\n"
8440 "Between current address-family and vpn\n"
8441 "For routes leaked from vpn to current address-family\n"
8442 "For routes leaked from current address-family to vpn\n"
8443 "both import and export\n")
8444
37a87b8f 8445DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
8446 af_route_map_vpn_imexport_cmd,
8447/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8448 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8449 NO_STR
ddb5b488 8450 "Specify route map\n"
b9c7bc5a
PZ
8451 "Between current address-family and vpn\n"
8452 "For routes leaked from vpn to current address-family\n"
8453 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8454 "name of route-map\n")
8455{
37a87b8f 8456 char base_xpath[XPATH_MAXLEN];
ddb5b488 8457 afi_t afi;
37a87b8f 8458 safi_t safi;
ddb5b488 8459 int idx = 0;
ddb5b488 8460
37a87b8f
CS
8461 afi = bgp_node_afi(vty);
8462 safi = bgp_node_safi(vty);
ddb5b488 8463
37a87b8f
CS
8464 snprintf(
8465 base_xpath, sizeof(base_xpath),
8466 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
8467 yang_afi_safi_value2identity(afi, safi),
8468 bgp_afi_safi_get_container_str(afi, safi));
8469
8470 if (argv_find(argv, argc, "no", &idx)) {
8471 if (!strcmp(direction_str, "import"))
8472 nb_cli_enqueue_change(vty, "./rmap-import",
8473 NB_OP_DESTROY, NULL);
8474 else if (!strcmp(direction_str, "export"))
8475 nb_cli_enqueue_change(vty, "./rmap-export",
8476 NB_OP_DESTROY, NULL);
8477 } else {
8478 if (!strcmp(direction_str, "import"))
8479 nb_cli_enqueue_change(vty, "./rmap-import",
8480 NB_OP_MODIFY, rmap_str);
8481 if (!strcmp(direction_str, "export"))
8482 nb_cli_enqueue_change(vty, "./rmap-export",
8483 NB_OP_MODIFY, rmap_str);
8484 }
8485 return nb_cli_apply_changes(vty, base_xpath);
8486}
ddb5b488 8487
37a87b8f
CS
8488void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
8489 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8490{
8491 int indent = 2;
ddb5b488 8492
37a87b8f
CS
8493 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
8494 yang_dnode_get_string(dnode, NULL));
8495}
69b07479 8496
37a87b8f
CS
8497void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
8498 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8499{
8500 int indent = 2;
ddb5b488 8501
37a87b8f
CS
8502 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
8503 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
8504}
8505
b9c7bc5a
PZ
8506ALIAS (af_route_map_vpn_imexport,
8507 af_no_route_map_vpn_imexport_cmd,
8508 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8509 NO_STR
8510 "Specify route map\n"
b9c7bc5a
PZ
8511 "Between current address-family and vpn\n"
8512 "For routes leaked from vpn to current address-family\n"
8513 "For routes leaked from current address-family to vpn\n")
8514
bb4f6190 8515DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8516 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8517 "Import routes from another VRF\n"
8518 "Vrf routes being filtered\n"
8519 "Specify route map\n"
8520 "name of route-map\n")
8521{
8522 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8523 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8524 afi_t afi;
bb4f6190
DS
8525 struct bgp *bgp_default;
8526
0ca70ba5 8527 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8528 if (afi == AFI_MAX)
8529 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8530
8531 bgp_default = bgp_get_default();
8532 if (!bgp_default) {
8533 int32_t ret;
8534 as_t as = bgp->as;
8535
8536 /* Auto-create assuming the same AS */
5d5393b9
DL
8537 ret = bgp_get_vty(&bgp_default, &as, NULL,
8538 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8539
8540 if (ret) {
8541 vty_out(vty,
8542 "VRF default is not configured as a bgp instance\n");
8543 return CMD_WARNING;
8544 }
8545 }
8546
69b07479 8547 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8548
ae6a6fb4
DS
8549 if (bgp->vpn_policy[afi].rmap_name[dir])
8550 XFREE(MTYPE_ROUTE_MAP_NAME,
8551 bgp->vpn_policy[afi].rmap_name[dir]);
8552 bgp->vpn_policy[afi].rmap_name[dir] =
8553 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8554 bgp->vpn_policy[afi].rmap[dir] =
8555 route_map_lookup_warn_noexist(vty, rmap_str);
8556 if (!bgp->vpn_policy[afi].rmap[dir])
8557 return CMD_SUCCESS;
8558
8559 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8560 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8561
69b07479
DS
8562 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8563
bb4f6190
DS
8564 return CMD_SUCCESS;
8565}
8566
ae6a6fb4
DS
8567DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8568 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8569 NO_STR
8570 "Import routes from another VRF\n"
8571 "Vrf routes being filtered\n"
ae6a6fb4
DS
8572 "Specify route map\n"
8573 "name of route-map\n")
8574{
8575 VTY_DECLVAR_CONTEXT(bgp, bgp);
8576 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8577 afi_t afi;
8578
8579 afi = vpn_policy_getafi(vty, bgp, true);
8580 if (afi == AFI_MAX)
8581 return CMD_WARNING_CONFIG_FAILED;
8582
8583 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8584
8585 if (bgp->vpn_policy[afi].rmap_name[dir])
8586 XFREE(MTYPE_ROUTE_MAP_NAME,
8587 bgp->vpn_policy[afi].rmap_name[dir]);
8588 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8589 bgp->vpn_policy[afi].rmap[dir] = NULL;
8590
8591 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8592 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8593 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8594
8595 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8596
8597 return CMD_SUCCESS;
8598}
bb4f6190 8599
37a87b8f
CS
8600DEFPY_YANG(bgp_imexport_vrf,
8601 bgp_imexport_vrf_cmd,
8602 "[no] import vrf VIEWVRFNAME$import_name",
8603 NO_STR
8604 "Import routes from another VRF\n"
8605 "VRF to import from\n"
8606 "The name of the VRF\n")
12a844a5 8607{
37a87b8f 8608 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
8609 safi_t safi;
8610 afi_t afi;
37a87b8f 8611 int32_t idx = 0;
12a844a5 8612
867f0cca 8613 if (import_name == NULL) {
8614 vty_out(vty, "%% Missing import name\n");
8615 return CMD_WARNING;
8616 }
8617
ae6a6fb4
DS
8618 if (strcmp(import_name, "route-map") == 0) {
8619 vty_out(vty, "%% Must include route-map name\n");
8620 return CMD_WARNING;
8621 }
8622
37a87b8f 8623 afi = bgp_node_afi(vty);
12a844a5
DS
8624 safi = bgp_node_safi(vty);
8625
37a87b8f
CS
8626 snprintf(
8627 base_xpath, sizeof(base_xpath),
8628 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
8629 yang_afi_safi_value2identity(afi, safi),
8630 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 8631
37a87b8f
CS
8632 if (argv_find(argv, argc, "no", &idx))
8633 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8634 else
8635 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 8636
37a87b8f
CS
8637 return nb_cli_apply_changes(vty, base_xpath);
8638}
12a844a5 8639
37a87b8f
CS
8640void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
8641 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8642{
8643 vty_out(vty, " import vrf %s\n",
8644 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
8645}
8646
b9c7bc5a 8647/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 8648DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
8649 bgp_imexport_vpn_cmd,
8650 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
8651 NO_STR
8652 "Import routes to this address-family\n"
8653 "Export routes from this address-family\n"
8654 "to/from default instance VPN RIB\n")
ddb5b488 8655{
37a87b8f 8656 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 8657 safi_t safi;
37a87b8f
CS
8658 afi_t afi;
8659 int32_t idx = 0;
ddb5b488 8660
b9c7bc5a
PZ
8661 afi = bgp_node_afi(vty);
8662 safi = bgp_node_safi(vty);
ddb5b488 8663
b9c7bc5a 8664 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
8665 snprintf(
8666 base_xpath, sizeof(base_xpath),
8667 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
8668 yang_afi_safi_value2identity(afi, safi),
8669 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 8670 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
8671 snprintf(
8672 base_xpath, sizeof(base_xpath),
8673 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
8674 yang_afi_safi_value2identity(afi, safi),
8675 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
8676 } else {
8677 vty_out(vty, "%% unknown direction %s\n", direction_str);
8678 return CMD_WARNING_CONFIG_FAILED;
8679 }
8680
37a87b8f
CS
8681 if (argv_find(argv, argc, "no", &idx))
8682 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8683 else
8684 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 8685
37a87b8f
CS
8686 return nb_cli_apply_changes(vty, base_xpath);
8687}
ddb5b488 8688
37a87b8f
CS
8689void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
8690 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8691{
8692 if (yang_dnode_get_bool(dnode, NULL))
8693 vty_out(vty, " import vpn\n");
8694}
8695
8696void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
8697 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8698{
8699 if (yang_dnode_get_bool(dnode, NULL))
8700 vty_out(vty, " export vpn\n");
ddb5b488
PZ
8701}
8702
301ad80a
PG
8703DEFPY (af_routetarget_import,
8704 af_routetarget_import_cmd,
9a659715 8705 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
8706 NO_STR
8707 "Specify route target list\n"
8708 "Specify route target list\n"
9a659715
PG
8709 "Specify route target list\n"
8710 "Specify route target list\n"
301ad80a
PG
8711 "Flow-spec redirect type route target\n"
8712 "Import routes to this address-family\n"
9a659715 8713 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
8714{
8715 VTY_DECLVAR_CONTEXT(bgp, bgp);
8716 int ret;
8717 struct ecommunity *ecom = NULL;
301ad80a 8718 afi_t afi;
9a659715 8719 int idx = 0, idx_unused = 0;
c6423c31
PG
8720 bool yes = true;
8721 bool rt6 = false;
301ad80a
PG
8722
8723 if (argv_find(argv, argc, "no", &idx))
c6423c31 8724 yes = false;
301ad80a 8725
9a659715
PG
8726 if (argv_find(argv, argc, "rt6", &idx_unused) ||
8727 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 8728 rt6 = true;
301ad80a 8729
0ca70ba5 8730 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8731 if (afi == AFI_MAX)
8732 return CMD_WARNING_CONFIG_FAILED;
8733
9a659715
PG
8734 if (rt6 && afi != AFI_IP6)
8735 return CMD_WARNING_CONFIG_FAILED;
8736
301ad80a
PG
8737 if (yes) {
8738 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8739 vty_out(vty, "%% Missing RTLIST\n");
8740 return CMD_WARNING_CONFIG_FAILED;
8741 }
9a659715 8742 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
8743 if (ret != CMD_SUCCESS)
8744 return ret;
8745 }
69b07479
DS
8746
8747 if (yes) {
8748 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8749 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8750 .import_redirect_rtlist);
69b07479
DS
8751 bgp->vpn_policy[afi].import_redirect_rtlist =
8752 ecommunity_dup(ecom);
8753 } else {
8754 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8755 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8756 .import_redirect_rtlist);
69b07479 8757 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 8758 }
69b07479 8759
301ad80a
PG
8760 if (ecom)
8761 ecommunity_free(&ecom);
8762
8763 return CMD_SUCCESS;
8764}
8765
37a87b8f
CS
8766void cli_show_bgp_global_afi_safi_header(struct vty *vty,
8767 struct lyd_node *dnode,
8768 bool show_defaults)
8769{
8770 const char *af_name;
8771 afi_t afi;
8772 safi_t safi;
8773
8774 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
8775 yang_afi_safi_identity2value(af_name, &afi, &safi);
8776
8777 vty_out(vty, " !\n address-family ");
8778 if (afi == AFI_IP) {
8779 if (safi == SAFI_UNICAST)
8780 vty_out(vty, "ipv4 unicast");
8781 else if (safi == SAFI_LABELED_UNICAST)
8782 vty_out(vty, "ipv4 labeled-unicast");
8783 else if (safi == SAFI_MULTICAST)
8784 vty_out(vty, "ipv4 multicast");
8785 else if (safi == SAFI_MPLS_VPN)
8786 vty_out(vty, "ipv4 vpn");
8787 else if (safi == SAFI_ENCAP)
8788 vty_out(vty, "ipv4 encap");
8789 else if (safi == SAFI_FLOWSPEC)
8790 vty_out(vty, "ipv4 flowspec");
8791 } else if (afi == AFI_IP6) {
8792 if (safi == SAFI_UNICAST)
8793 vty_out(vty, "ipv6 unicast");
8794 else if (safi == SAFI_LABELED_UNICAST)
8795 vty_out(vty, "ipv6 labeled-unicast");
8796 else if (safi == SAFI_MULTICAST)
8797 vty_out(vty, "ipv6 multicast");
8798 else if (safi == SAFI_MPLS_VPN)
8799 vty_out(vty, "ipv6 vpn");
8800 else if (safi == SAFI_ENCAP)
8801 vty_out(vty, "ipv6 encap");
8802 else if (safi == SAFI_FLOWSPEC)
8803 vty_out(vty, "ipv6 flowspec");
8804 } else if (afi == AFI_L2VPN) {
8805 if (safi == SAFI_EVPN)
8806 vty_out(vty, "l2vpn evpn");
8807 }
8808 vty_out(vty, "\n");
8809}
8810
505e5056 8811DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 8812 address_family_ipv4_safi_cmd,
8813 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8814 "Enter Address Family command mode\n"
8815 "Address Family\n"
8816 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 8817{
f51bae9c 8818
37a87b8f
CS
8819 safi_t safi = SAFI_UNICAST;
8820 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
8821 const char *vrf_name = NULL;
8822
d62a17ae 8823 if (argc == 3) {
37a87b8f
CS
8824 safi = bgp_vty_safi_from_str(argv[2]->text);
8825
8826 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
8827 VTY_CURR_XPATH);
8828 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
8829 "control-plane-protocol");
8830 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
8831
8832 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 8833 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8834 && safi != SAFI_EVPN) {
31947174
MK
8835 vty_out(vty,
8836 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8837 return CMD_WARNING_CONFIG_FAILED;
8838 }
37a87b8f
CS
8839 }
8840 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 8841
d62a17ae 8842 return CMD_SUCCESS;
718e3744 8843}
8844
505e5056 8845DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 8846 address_family_ipv6_safi_cmd,
8847 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8848 "Enter Address Family command mode\n"
8849 "Address Family\n"
8850 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 8851{
37a87b8f
CS
8852 safi_t safi = SAFI_UNICAST;
8853 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
8854 const char *vrf_name = NULL;
8855
d62a17ae 8856 if (argc == 3) {
37a87b8f
CS
8857 safi = bgp_vty_safi_from_str(argv[2]->text);
8858 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
8859 VTY_CURR_XPATH);
8860 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
8861 "control-plane-protocol");
8862 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
8863
8864 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 8865 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8866 && safi != SAFI_EVPN) {
31947174
MK
8867 vty_out(vty,
8868 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8869 return CMD_WARNING_CONFIG_FAILED;
8870 }
37a87b8f
CS
8871 }
8872 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 8873
d62a17ae 8874 return CMD_SUCCESS;
25ffbdc1 8875}
718e3744 8876
d6902373 8877#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 8878DEFUN_NOSH (address_family_vpnv4,
718e3744 8879 address_family_vpnv4_cmd,
8334fd5a 8880 "address-family vpnv4 [unicast]",
718e3744 8881 "Enter Address Family command mode\n"
8c3deaae 8882 "Address Family\n"
3a2d747c 8883 "Address Family modifier\n")
718e3744 8884{
d62a17ae 8885 vty->node = BGP_VPNV4_NODE;
8886 return CMD_SUCCESS;
718e3744 8887}
8888
505e5056 8889DEFUN_NOSH (address_family_vpnv6,
8ecd3266 8890 address_family_vpnv6_cmd,
8334fd5a 8891 "address-family vpnv6 [unicast]",
8ecd3266 8892 "Enter Address Family command mode\n"
8c3deaae 8893 "Address Family\n"
3a2d747c 8894 "Address Family modifier\n")
8ecd3266 8895{
d62a17ae 8896 vty->node = BGP_VPNV6_NODE;
8897 return CMD_SUCCESS;
8ecd3266 8898}
64e4a6c5 8899#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 8900
505e5056 8901DEFUN_NOSH (address_family_evpn,
4e0b7b6d 8902 address_family_evpn_cmd,
7111c1a0 8903 "address-family l2vpn evpn",
4e0b7b6d 8904 "Enter Address Family command mode\n"
7111c1a0
QY
8905 "Address Family\n"
8906 "Address Family modifier\n")
4e0b7b6d 8907{
2131d5cf 8908 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8909 vty->node = BGP_EVPN_NODE;
8910 return CMD_SUCCESS;
4e0b7b6d
PG
8911}
8912
505e5056 8913DEFUN_NOSH (exit_address_family,
718e3744 8914 exit_address_family_cmd,
8915 "exit-address-family",
8916 "Exit from Address Family configuration mode\n")
8917{
d62a17ae 8918 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
8919 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
8920 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
8921 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
8922 || vty->node == BGP_EVPN_NODE
8923 || vty->node == BGP_FLOWSPECV4_NODE
8924 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 8925 vty->node = BGP_NODE;
8926 return CMD_SUCCESS;
718e3744 8927}
6b0655a2 8928
37a87b8f
CS
8929void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
8930 struct lyd_node *dnode
8931 __attribute__((__unused__)))
8932{
8933 vty_out(vty, " exit-address-family\n");
8934}
8935
8ad7271d 8936/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 8937static int bgp_clear_prefix(struct vty *vty, const char *view_name,
8938 const char *ip_str, afi_t afi, safi_t safi,
8939 struct prefix_rd *prd)
8940{
8941 int ret;
8942 struct prefix match;
9bcb3eef
DS
8943 struct bgp_dest *dest;
8944 struct bgp_dest *rm;
d62a17ae 8945 struct bgp *bgp;
8946 struct bgp_table *table;
8947 struct bgp_table *rib;
8948
8949 /* BGP structure lookup. */
8950 if (view_name) {
8951 bgp = bgp_lookup_by_name(view_name);
8952 if (bgp == NULL) {
8953 vty_out(vty, "%% Can't find BGP instance %s\n",
8954 view_name);
8955 return CMD_WARNING;
8956 }
8957 } else {
8958 bgp = bgp_get_default();
8959 if (bgp == NULL) {
8960 vty_out(vty, "%% No BGP process is configured\n");
8961 return CMD_WARNING;
8962 }
8963 }
8964
8965 /* Check IP address argument. */
8966 ret = str2prefix(ip_str, &match);
8967 if (!ret) {
8968 vty_out(vty, "%% address is malformed\n");
8969 return CMD_WARNING;
8970 }
8971
8972 match.family = afi2family(afi);
8973 rib = bgp->rib[afi][safi];
8974
8975 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
8976 for (dest = bgp_table_top(rib); dest;
8977 dest = bgp_route_next(dest)) {
8978 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8979
9bcb3eef 8980 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 8981 continue;
8982
9bcb3eef 8983 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
8984 if (table == NULL)
8985 continue;
8986
8987 if ((rm = bgp_node_match(table, &match)) != NULL) {
8988 const struct prefix *rm_p =
9bcb3eef 8989 bgp_dest_get_prefix(rm);
b54892e0
DS
8990
8991 if (rm_p->prefixlen == match.prefixlen) {
8992 SET_FLAG(rm->flags,
8993 BGP_NODE_USER_CLEAR);
8994 bgp_process(bgp, rm, afi, safi);
d62a17ae 8995 }
9bcb3eef 8996 bgp_dest_unlock_node(rm);
d62a17ae 8997 }
8998 }
8999 } else {
9bcb3eef
DS
9000 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9001 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9002
9bcb3eef
DS
9003 if (dest_p->prefixlen == match.prefixlen) {
9004 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9005 bgp_process(bgp, dest, afi, safi);
d62a17ae 9006 }
9bcb3eef 9007 bgp_dest_unlock_node(dest);
d62a17ae 9008 }
9009 }
9010
9011 return CMD_SUCCESS;
8ad7271d
DS
9012}
9013
b09b5ae0 9014/* one clear bgp command to rule them all */
718e3744 9015DEFUN (clear_ip_bgp_all,
9016 clear_ip_bgp_all_cmd,
453c92f6 9017 "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 9018 CLEAR_STR
9019 IP_STR
9020 BGP_STR
838758ac 9021 BGP_INSTANCE_HELP_STR
510afcd6 9022 BGP_AFI_HELP_STR
fd5e7b70 9023 "Address Family\n"
510afcd6 9024 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9025 "Address Family modifier\n"
b09b5ae0 9026 "Clear all peers\n"
453c92f6 9027 "BGP IPv4 neighbor to clear\n"
a80beece 9028 "BGP IPv6 neighbor to clear\n"
838758ac 9029 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9030 "Clear peers with the AS number\n"
9031 "Clear all external peers\n"
718e3744 9032 "Clear all members of peer-group\n"
b09b5ae0 9033 "BGP peer-group name\n"
b09b5ae0
DW
9034 BGP_SOFT_STR
9035 BGP_SOFT_IN_STR
b09b5ae0
DW
9036 BGP_SOFT_OUT_STR
9037 BGP_SOFT_IN_STR
9038 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9039 BGP_SOFT_OUT_STR)
718e3744 9040{
d62a17ae 9041 char *vrf = NULL;
9042
dc912615
DS
9043 afi_t afi = AFI_UNSPEC;
9044 safi_t safi = SAFI_UNSPEC;
d62a17ae 9045 enum clear_sort clr_sort = clear_peer;
9046 enum bgp_clear_type clr_type;
9047 char *clr_arg = NULL;
9048
9049 int idx = 0;
ff8a8a7a
CS
9050 char errmsg[BUFSIZ] = {'\0'};
9051 int ret;
d62a17ae 9052
9053 /* clear [ip] bgp */
9054 if (argv_find(argv, argc, "ip", &idx))
9055 afi = AFI_IP;
9056
9a8bdf1c
PG
9057 /* [<vrf> VIEWVRFNAME] */
9058 if (argv_find(argv, argc, "vrf", &idx)) {
9059 vrf = argv[idx + 1]->arg;
9060 idx += 2;
9061 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9062 vrf = NULL;
9063 } else if (argv_find(argv, argc, "view", &idx)) {
9064 /* [<view> VIEWVRFNAME] */
d62a17ae 9065 vrf = argv[idx + 1]->arg;
9066 idx += 2;
9067 }
d62a17ae 9068 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9069 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9070 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9071
d7b9898c 9072 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9073 if (argv_find(argv, argc, "*", &idx)) {
9074 clr_sort = clear_all;
9075 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9076 clr_sort = clear_peer;
9077 clr_arg = argv[idx]->arg;
9078 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9079 clr_sort = clear_peer;
9080 clr_arg = argv[idx]->arg;
9081 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9082 clr_sort = clear_group;
9083 idx++;
9084 clr_arg = argv[idx]->arg;
d7b9898c 9085 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9086 clr_sort = clear_peer;
9087 clr_arg = argv[idx]->arg;
8fa7d444
DS
9088 } else if (argv_find(argv, argc, "WORD", &idx)) {
9089 clr_sort = clear_peer;
9090 clr_arg = argv[idx]->arg;
d62a17ae 9091 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9092 clr_sort = clear_as;
9093 clr_arg = argv[idx]->arg;
9094 } else if (argv_find(argv, argc, "external", &idx)) {
9095 clr_sort = clear_external;
9096 }
9097
9098 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9099 if (argv_find(argv, argc, "soft", &idx)) {
9100 if (argv_find(argv, argc, "in", &idx)
9101 || argv_find(argv, argc, "out", &idx))
9102 clr_type = strmatch(argv[idx]->text, "in")
9103 ? BGP_CLEAR_SOFT_IN
9104 : BGP_CLEAR_SOFT_OUT;
9105 else
9106 clr_type = BGP_CLEAR_SOFT_BOTH;
9107 } else if (argv_find(argv, argc, "in", &idx)) {
9108 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9109 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9110 : BGP_CLEAR_SOFT_IN;
9111 } else if (argv_find(argv, argc, "out", &idx)) {
9112 clr_type = BGP_CLEAR_SOFT_OUT;
9113 } else
9114 clr_type = BGP_CLEAR_SOFT_NONE;
9115
ff8a8a7a
CS
9116 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9117 sizeof(errmsg));
9118 if (ret != NB_OK)
9119 vty_out(vty, "Error description: %s\n", errmsg);
9120
9121 return ret;
838758ac 9122}
01080f7c 9123
8ad7271d
DS
9124DEFUN (clear_ip_bgp_prefix,
9125 clear_ip_bgp_prefix_cmd,
18c57037 9126 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9127 CLEAR_STR
9128 IP_STR
9129 BGP_STR
838758ac 9130 BGP_INSTANCE_HELP_STR
8ad7271d 9131 "Clear bestpath and re-advertise\n"
0c7b1b01 9132 "IPv4 prefix\n")
8ad7271d 9133{
d62a17ae 9134 char *vrf = NULL;
9135 char *prefix = NULL;
8ad7271d 9136
d62a17ae 9137 int idx = 0;
01080f7c 9138
d62a17ae 9139 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9140 if (argv_find(argv, argc, "vrf", &idx)) {
9141 vrf = argv[idx + 1]->arg;
9142 idx += 2;
9143 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9144 vrf = NULL;
9145 } else if (argv_find(argv, argc, "view", &idx)) {
9146 /* [<view> VIEWVRFNAME] */
9147 vrf = argv[idx + 1]->arg;
9148 idx += 2;
9149 }
0c7b1b01 9150
d62a17ae 9151 prefix = argv[argc - 1]->arg;
8ad7271d 9152
d62a17ae 9153 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9154}
8ad7271d 9155
b09b5ae0
DW
9156DEFUN (clear_bgp_ipv6_safi_prefix,
9157 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9158 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9159 CLEAR_STR
3a2d747c 9160 IP_STR
718e3744 9161 BGP_STR
8c3deaae 9162 "Address Family\n"
46f296b4 9163 BGP_SAFI_HELP_STR
b09b5ae0 9164 "Clear bestpath and re-advertise\n"
0c7b1b01 9165 "IPv6 prefix\n")
718e3744 9166{
9b475e76
PG
9167 int idx_safi = 0;
9168 int idx_ipv6_prefix = 0;
9169 safi_t safi = SAFI_UNICAST;
9170 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9171 argv[idx_ipv6_prefix]->arg : NULL;
9172
9173 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9174 return bgp_clear_prefix(
9b475e76
PG
9175 vty, NULL, prefix, AFI_IP6,
9176 safi, NULL);
838758ac 9177}
01080f7c 9178
b09b5ae0
DW
9179DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9180 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9181 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9182 CLEAR_STR
3a2d747c 9183 IP_STR
718e3744 9184 BGP_STR
838758ac 9185 BGP_INSTANCE_HELP_STR
8c3deaae 9186 "Address Family\n"
46f296b4 9187 BGP_SAFI_HELP_STR
b09b5ae0 9188 "Clear bestpath and re-advertise\n"
0c7b1b01 9189 "IPv6 prefix\n")
718e3744 9190{
9b475e76 9191 int idx_safi = 0;
9a8bdf1c 9192 int idx_vrfview = 0;
9b475e76
PG
9193 int idx_ipv6_prefix = 0;
9194 safi_t safi = SAFI_UNICAST;
9195 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9196 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9197 char *vrfview = NULL;
9b475e76 9198
9a8bdf1c
PG
9199 /* [<view|vrf> VIEWVRFNAME] */
9200 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9201 vrfview = argv[idx_vrfview + 1]->arg;
9202 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9203 vrfview = NULL;
9204 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9205 /* [<view> VIEWVRFNAME] */
9206 vrfview = argv[idx_vrfview + 1]->arg;
9207 }
9b475e76
PG
9208 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9209
d62a17ae 9210 return bgp_clear_prefix(
9b475e76
PG
9211 vty, vrfview, prefix,
9212 AFI_IP6, safi, NULL);
718e3744 9213}
9214
b09b5ae0
DW
9215DEFUN (show_bgp_views,
9216 show_bgp_views_cmd,
d6e3c605 9217 "show [ip] bgp views",
b09b5ae0 9218 SHOW_STR
d6e3c605 9219 IP_STR
01080f7c 9220 BGP_STR
b09b5ae0 9221 "Show the defined BGP views\n")
01080f7c 9222{
d62a17ae 9223 struct list *inst = bm->bgp;
9224 struct listnode *node;
9225 struct bgp *bgp;
01080f7c 9226
d62a17ae 9227 vty_out(vty, "Defined BGP views:\n");
9228 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9229 /* Skip VRFs. */
9230 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9231 continue;
9232 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9233 bgp->as);
9234 }
e52702f2 9235
d62a17ae 9236 return CMD_SUCCESS;
e0081f70
ML
9237}
9238
8386ac43 9239DEFUN (show_bgp_vrfs,
9240 show_bgp_vrfs_cmd,
d6e3c605 9241 "show [ip] bgp vrfs [json]",
8386ac43 9242 SHOW_STR
d6e3c605 9243 IP_STR
8386ac43 9244 BGP_STR
9245 "Show BGP VRFs\n"
9973d184 9246 JSON_STR)
8386ac43 9247{
fe1dc5a3 9248 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9249 struct list *inst = bm->bgp;
9250 struct listnode *node;
9251 struct bgp *bgp;
9f049418 9252 bool uj = use_json(argc, argv);
d62a17ae 9253 json_object *json = NULL;
9254 json_object *json_vrfs = NULL;
9255 int count = 0;
d62a17ae 9256
d62a17ae 9257 if (uj) {
9258 json = json_object_new_object();
9259 json_vrfs = json_object_new_object();
9260 }
9261
9262 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9263 const char *name, *type;
9264 struct peer *peer;
7fe96307 9265 struct listnode *node2, *nnode2;
d62a17ae 9266 int peers_cfg, peers_estb;
9267 json_object *json_vrf = NULL;
d62a17ae 9268
9269 /* Skip Views. */
9270 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9271 continue;
9272
9273 count++;
efb4077a 9274 if (!uj && count == 1) {
fe1dc5a3 9275 vty_out(vty,
efb4077a 9276 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9277 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9278 "#PeersEstb", "Name");
9279 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9280 "L3-VNI", "RouterMAC", "Interface");
9281 }
d62a17ae 9282
9283 peers_cfg = peers_estb = 0;
9284 if (uj)
9285 json_vrf = json_object_new_object();
9286
9287
7fe96307 9288 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9289 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9290 continue;
9291 peers_cfg++;
9292 if (peer->status == Established)
9293 peers_estb++;
9294 }
9295
9296 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9297 name = VRF_DEFAULT_NAME;
d62a17ae 9298 type = "DFLT";
9299 } else {
9300 name = bgp->name;
9301 type = "VRF";
9302 }
9303
a8bf7d9c 9304
d62a17ae 9305 if (uj) {
a4d82a8a
PZ
9306 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9307 ? -1
9308 : (int64_t)bgp->vrf_id;
23d0a753
DA
9309 char buf[BUFSIZ] = {0};
9310
d62a17ae 9311 json_object_string_add(json_vrf, "type", type);
9312 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9313 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
9314 inet_ntop(AF_INET,
9315 &bgp->router_id, buf,
9316 sizeof(buf)));
d62a17ae 9317 json_object_int_add(json_vrf, "numConfiguredPeers",
9318 peers_cfg);
9319 json_object_int_add(json_vrf, "numEstablishedPeers",
9320 peers_estb);
9321
fe1dc5a3 9322 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9323 json_object_string_add(
9324 json_vrf, "rmac",
9325 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9326 json_object_string_add(json_vrf, "interface",
9327 ifindex2ifname(bgp->l3vni_svi_ifindex,
9328 bgp->vrf_id));
d62a17ae 9329 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9330 } else {
23d0a753 9331 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9332 type,
9333 bgp->vrf_id == VRF_UNKNOWN ? -1
9334 : (int)bgp->vrf_id,
23d0a753 9335 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9336 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9337 bgp->l3vni,
9338 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9339 ifindex2ifname(bgp->l3vni_svi_ifindex,
9340 bgp->vrf_id));
9341 }
d62a17ae 9342 }
9343
9344 if (uj) {
9345 json_object_object_add(json, "vrfs", json_vrfs);
9346
9347 json_object_int_add(json, "totalVrfs", count);
9348
996c9314
LB
9349 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9350 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9351 json_object_free(json);
9352 } else {
9353 if (count)
9354 vty_out(vty,
9355 "\nTotal number of VRFs (including default): %d\n",
9356 count);
9357 }
9358
9359 return CMD_SUCCESS;
8386ac43 9360}
9361
48ecf8f5
DS
9362DEFUN (show_bgp_mac_hash,
9363 show_bgp_mac_hash_cmd,
9364 "show bgp mac hash",
9365 SHOW_STR
9366 BGP_STR
9367 "Mac Address\n"
9368 "Mac Address database\n")
9369{
9370 bgp_mac_dump_table(vty);
9371
9372 return CMD_SUCCESS;
9373}
acf71666 9374
e3b78da8 9375static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9376{
0291c246 9377 struct vty *vty = (struct vty *)args;
e3b78da8 9378 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9379
23d0a753 9380 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9381}
9382
9383static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9384{
9385 vty_out(vty, "self nexthop database:\n");
af97a18b 9386 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9387
9388 vty_out(vty, "Tunnel-ip database:\n");
9389 hash_iterate(bgp->tip_hash,
e3b78da8 9390 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9391 vty);
9392}
9393
15c81ca4
DS
9394DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9395 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9396 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9397 "martian next-hops\n"
9398 "martian next-hop database\n")
acf71666 9399{
0291c246 9400 struct bgp *bgp = NULL;
15c81ca4 9401 int idx = 0;
9a8bdf1c
PG
9402 char *name = NULL;
9403
9404 /* [<vrf> VIEWVRFNAME] */
9405 if (argv_find(argv, argc, "vrf", &idx)) {
9406 name = argv[idx + 1]->arg;
9407 if (name && strmatch(name, VRF_DEFAULT_NAME))
9408 name = NULL;
9409 } else if (argv_find(argv, argc, "view", &idx))
9410 /* [<view> VIEWVRFNAME] */
9411 name = argv[idx + 1]->arg;
9412 if (name)
9413 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9414 else
9415 bgp = bgp_get_default();
acf71666 9416
acf71666
MK
9417 if (!bgp) {
9418 vty_out(vty, "%% No BGP process is configured\n");
9419 return CMD_WARNING;
9420 }
9421 bgp_show_martian_nexthops(vty, bgp);
9422
9423 return CMD_SUCCESS;
9424}
9425
f412b39a 9426DEFUN (show_bgp_memory,
4bf6a362 9427 show_bgp_memory_cmd,
7fa12b13 9428 "show [ip] bgp memory",
4bf6a362 9429 SHOW_STR
3a2d747c 9430 IP_STR
4bf6a362
PJ
9431 BGP_STR
9432 "Global BGP memory statistics\n")
9433{
d62a17ae 9434 char memstrbuf[MTYPE_MEMSTR_LEN];
9435 unsigned long count;
9436
9437 /* RIB related usage stats */
9438 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9439 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9440 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9441 count * sizeof(struct bgp_dest)));
d62a17ae 9442
9443 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9444 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9445 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9446 count * sizeof(struct bgp_path_info)));
d62a17ae 9447 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9448 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9449 count,
4b7e6066
DS
9450 mtype_memstr(
9451 memstrbuf, sizeof(memstrbuf),
9452 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9453
9454 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9455 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9456 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9457 count * sizeof(struct bgp_static)));
9458
9459 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9460 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9461 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9462 count * sizeof(struct bpacket)));
9463
9464 /* Adj-In/Out */
9465 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9466 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9467 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9468 count * sizeof(struct bgp_adj_in)));
9469 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9470 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9471 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9472 count * sizeof(struct bgp_adj_out)));
9473
9474 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9475 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9476 count,
9477 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9478 count * sizeof(struct bgp_nexthop_cache)));
9479
9480 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9481 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9482 count,
9483 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9484 count * sizeof(struct bgp_damp_info)));
9485
9486 /* Attributes */
9487 count = attr_count();
9488 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9489 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9490 count * sizeof(struct attr)));
9491
9492 if ((count = attr_unknown_count()))
9493 vty_out(vty, "%ld unknown attributes\n", count);
9494
9495 /* AS_PATH attributes */
9496 count = aspath_count();
9497 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9498 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9499 count * sizeof(struct aspath)));
9500
9501 count = mtype_stats_alloc(MTYPE_AS_SEG);
9502 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9503 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9504 count * sizeof(struct assegment)));
9505
9506 /* Other attributes */
9507 if ((count = community_count()))
9508 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9509 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9510 count * sizeof(struct community)));
d62a17ae 9511 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9512 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9513 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9514 count * sizeof(struct ecommunity)));
d62a17ae 9515 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9516 vty_out(vty,
9517 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9518 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9519 count * sizeof(struct lcommunity)));
d62a17ae 9520
9521 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9522 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9523 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9524 count * sizeof(struct cluster_list)));
9525
9526 /* Peer related usage */
9527 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9528 vty_out(vty, "%ld peers, using %s of memory\n", count,
9529 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9530 count * sizeof(struct peer)));
9531
9532 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9533 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9534 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9535 count * sizeof(struct peer_group)));
9536
9537 /* Other */
d62a17ae 9538 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9539 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9540 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9541 count * sizeof(regex_t)));
d62a17ae 9542 return CMD_SUCCESS;
4bf6a362 9543}
fee0f4c6 9544
57a9c8a8
DS
9545static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9546{
9547 json_object *bestpath = json_object_new_object();
9548
892fedb6 9549 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9550 json_object_string_add(bestpath, "asPath", "ignore");
9551
892fedb6 9552 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9553 json_object_string_add(bestpath, "asPath", "confed");
9554
892fedb6
DA
9555 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9556 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9557 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9558 "as-set");
9559 else
a4d82a8a 9560 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9561 "true");
9562 } else
a4d82a8a 9563 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9564
892fedb6 9565 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9566 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9567 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9568 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9569 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9570 json_object_string_add(bestpath, "med", "confed");
892fedb6 9571 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
9572 json_object_string_add(bestpath, "med",
9573 "missing-as-worst");
9574 else
9575 json_object_string_add(bestpath, "med", "true");
9576 }
9577
9578 json_object_object_add(json, "bestPath", bestpath);
9579}
9580
3577f1c5
DD
9581/* Print the error code/subcode for why the peer is down */
9582static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9583 json_object *json_peer, bool use_json)
9584{
9585 const char *code_str;
9586 const char *subcode_str;
9587
9588 if (use_json) {
9589 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9590 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9591 char errorcodesubcode_hexstr[5];
9592 char errorcodesubcode_str[256];
9593
9594 code_str = bgp_notify_code_str(peer->notify.code);
9595 subcode_str = bgp_notify_subcode_str(
9596 peer->notify.code,
9597 peer->notify.subcode);
9598
772270f3
QY
9599 snprintf(errorcodesubcode_hexstr,
9600 sizeof(errorcodesubcode_hexstr), "%02X%02X",
9601 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
9602 json_object_string_add(json_peer,
9603 "lastErrorCodeSubcode",
9604 errorcodesubcode_hexstr);
9605 snprintf(errorcodesubcode_str, 255, "%s%s",
9606 code_str, subcode_str);
9607 json_object_string_add(json_peer,
9608 "lastNotificationReason",
9609 errorcodesubcode_str);
9610 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9611 && peer->notify.code == BGP_NOTIFY_CEASE
9612 && (peer->notify.subcode
9613 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9614 || peer->notify.subcode
9615 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9616 && peer->notify.length) {
9617 char msgbuf[1024];
9618 const char *msg_str;
9619
9620 msg_str = bgp_notify_admin_message(
9621 msgbuf, sizeof(msgbuf),
9622 (uint8_t *)peer->notify.data,
9623 peer->notify.length);
9624 if (msg_str)
9625 json_object_string_add(
9626 json_peer,
9627 "lastShutdownDescription",
9628 msg_str);
9629 }
9630
c258527b 9631 }
3577f1c5
DD
9632 json_object_string_add(json_peer, "lastResetDueTo",
9633 peer_down_str[(int)peer->last_reset]);
05912a17
DD
9634 json_object_int_add(json_peer, "lastResetCode",
9635 peer->last_reset);
3577f1c5
DD
9636 } else {
9637 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9638 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9639 code_str = bgp_notify_code_str(peer->notify.code);
9640 subcode_str =
9641 bgp_notify_subcode_str(peer->notify.code,
9642 peer->notify.subcode);
9643 vty_out(vty, " Notification %s (%s%s)\n",
9644 peer->last_reset == PEER_DOWN_NOTIFY_SEND
9645 ? "sent"
9646 : "received",
9647 code_str, subcode_str);
9648 } else {
e91c24c8 9649 vty_out(vty, " %s\n",
3577f1c5
DD
9650 peer_down_str[(int)peer->last_reset]);
9651 }
9652 }
9653}
9654
9655static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
9656 safi_t safi)
9657{
9658 return ((peer->status != Established) ||
9659 !peer->afc_recv[afi][safi]);
9660}
9661
9662static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
9663 struct peer *peer, json_object *json_peer,
9664 int max_neighbor_width, bool use_json)
9665{
9666 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9667 int len;
9668
9669 if (use_json) {
9670 if (peer_dynamic_neighbor(peer))
9671 json_object_boolean_true_add(json_peer,
9672 "dynamicPeer");
9673 if (peer->hostname)
9674 json_object_string_add(json_peer, "hostname",
9675 peer->hostname);
9676
9677 if (peer->domainname)
9678 json_object_string_add(json_peer, "domainname",
9679 peer->domainname);
9680 json_object_int_add(json_peer, "connectionsEstablished",
9681 peer->established);
9682 json_object_int_add(json_peer, "connectionsDropped",
9683 peer->dropped);
9684 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9685 use_json, json_peer);
9686 if (peer->status == Established)
9687 json_object_string_add(json_peer, "lastResetDueTo",
9688 "AFI/SAFI Not Negotiated");
9689 else
9690 bgp_show_peer_reset(NULL, peer, json_peer, true);
9691 } else {
9692 dn_flag[1] = '\0';
9693 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
9694 if (peer->hostname
892fedb6 9695 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
9696 len = vty_out(vty, "%s%s(%s)", dn_flag,
9697 peer->hostname, peer->host);
9698 else
9699 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9700
9701 /* pad the neighbor column with spaces */
9702 if (len < max_neighbor_width)
9703 vty_out(vty, "%*s", max_neighbor_width - len,
9704 " ");
e91c24c8 9705 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
9706 peer->dropped,
9707 peer_uptime(peer->uptime, timebuf,
9708 BGP_UPTIME_LEN, 0, NULL));
9709 if (peer->status == Established)
9710 vty_out(vty, " AFI/SAFI Not Negotiated\n");
9711 else
9712 bgp_show_peer_reset(vty, peer, NULL,
9713 false);
9714 }
9715}
c258527b 9716
3577f1c5 9717
718e3744 9718/* Show BGP peer's summary information. */
d62a17ae 9719static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10b49f14
DA
9720 bool show_failed, bool show_established,
9721 bool use_json)
d62a17ae 9722{
9723 struct peer *peer;
9724 struct listnode *node, *nnode;
9725 unsigned int count = 0, dn_count = 0;
9726 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9727 char neighbor_buf[VTY_BUFSIZ];
9728 int neighbor_col_default_width = 16;
3577f1c5 9729 int len, failed_count = 0;
d62a17ae 9730 int max_neighbor_width = 0;
9731 int pfx_rcd_safi;
3c13337d 9732 json_object *json = NULL;
d62a17ae 9733 json_object *json_peer = NULL;
9734 json_object *json_peers = NULL;
50e05855 9735 struct peer_af *paf;
d3ada366 9736 struct bgp_filter *filter;
d62a17ae 9737
9738 /* labeled-unicast routes are installed in the unicast table so in order
9739 * to
9740 * display the correct PfxRcd value we must look at SAFI_UNICAST
9741 */
3577f1c5 9742
d62a17ae 9743 if (safi == SAFI_LABELED_UNICAST)
9744 pfx_rcd_safi = SAFI_UNICAST;
9745 else
9746 pfx_rcd_safi = safi;
9747
9748 if (use_json) {
3c13337d 9749 json = json_object_new_object();
d62a17ae 9750 json_peers = json_object_new_object();
3577f1c5
DD
9751 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9752 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9753 continue;
9754
9755 if (peer->afc[afi][safi]) {
9756 /* See if we have at least a single failed peer */
9757 if (bgp_has_peer_failed(peer, afi, safi))
9758 failed_count++;
9759 count++;
9760 }
9761 if (peer_dynamic_neighbor(peer))
9762 dn_count++;
9763 }
c258527b 9764
d62a17ae 9765 } else {
9766 /* Loop over all neighbors that will be displayed to determine
9767 * how many
9768 * characters are needed for the Neighbor column
9769 */
9770 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9771 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9772 continue;
9773
9774 if (peer->afc[afi][safi]) {
9775 memset(dn_flag, '\0', sizeof(dn_flag));
9776 if (peer_dynamic_neighbor(peer))
9777 dn_flag[0] = '*';
9778
9779 if (peer->hostname
892fedb6
DA
9780 && CHECK_FLAG(bgp->flags,
9781 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
9782 snprintf(neighbor_buf,
9783 sizeof(neighbor_buf),
9784 "%s%s(%s) ", dn_flag,
9785 peer->hostname, peer->host);
d62a17ae 9786 else
772270f3
QY
9787 snprintf(neighbor_buf,
9788 sizeof(neighbor_buf), "%s%s ",
9789 dn_flag, peer->host);
d62a17ae 9790
9791 len = strlen(neighbor_buf);
9792
9793 if (len > max_neighbor_width)
9794 max_neighbor_width = len;
c258527b 9795
3577f1c5
DD
9796 /* See if we have at least a single failed peer */
9797 if (bgp_has_peer_failed(peer, afi, safi))
9798 failed_count++;
9799 count++;
d62a17ae 9800 }
9801 }
f933309e 9802
d62a17ae 9803 /* Originally we displayed the Neighbor column as 16
9804 * characters wide so make that the default
9805 */
9806 if (max_neighbor_width < neighbor_col_default_width)
9807 max_neighbor_width = neighbor_col_default_width;
9808 }
f933309e 9809
3577f1c5
DD
9810 if (show_failed && !failed_count) {
9811 if (use_json) {
9812 json_object_int_add(json, "failedPeersCount", 0);
9813 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 9814 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
9815
9816 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9817 json, JSON_C_TO_STRING_PRETTY));
9818 json_object_free(json);
9819 } else {
9820 vty_out(vty, "%% No failed BGP neighbors found\n");
9821 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9822 }
9823 return CMD_SUCCESS;
9824 }
c258527b 9825
3577f1c5 9826 count = 0; /* Reset the value as its used again */
d62a17ae 9827 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9828 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9829 continue;
9830
ea47320b
DL
9831 if (!peer->afc[afi][safi])
9832 continue;
d62a17ae 9833
ea47320b
DL
9834 if (!count) {
9835 unsigned long ents;
9836 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 9837 int64_t vrf_id_ui;
d62a17ae 9838
a4d82a8a
PZ
9839 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9840 ? -1
9841 : (int64_t)bgp->vrf_id;
ea47320b
DL
9842
9843 /* Usage summary and header */
9844 if (use_json) {
23d0a753
DA
9845 char buf[BUFSIZ] = {0};
9846
ea47320b
DL
9847 json_object_string_add(
9848 json, "routerId",
23d0a753
DA
9849 inet_ntop(AF_INET, &bgp->router_id, buf,
9850 sizeof(buf)));
60466a63
QY
9851 json_object_int_add(json, "as", bgp->as);
9852 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
9853 json_object_string_add(
9854 json, "vrfName",
9855 (bgp->inst_type
9856 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9857 ? VRF_DEFAULT_NAME
ea47320b
DL
9858 : bgp->name);
9859 } else {
9860 vty_out(vty,
23d0a753
DA
9861 "BGP router identifier %pI4, local AS number %u vrf-id %d",
9862 &bgp->router_id, bgp->as,
a4d82a8a
PZ
9863 bgp->vrf_id == VRF_UNKNOWN
9864 ? -1
9865 : (int)bgp->vrf_id);
ea47320b
DL
9866 vty_out(vty, "\n");
9867 }
d62a17ae 9868
ea47320b 9869 if (bgp_update_delay_configured(bgp)) {
d62a17ae 9870 if (use_json) {
ea47320b 9871 json_object_int_add(
60466a63 9872 json, "updateDelayLimit",
ea47320b 9873 bgp->v_update_delay);
d62a17ae 9874
ea47320b
DL
9875 if (bgp->v_update_delay
9876 != bgp->v_establish_wait)
d62a17ae 9877 json_object_int_add(
9878 json,
ea47320b
DL
9879 "updateDelayEstablishWait",
9880 bgp->v_establish_wait);
d62a17ae 9881
60466a63 9882 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9883 json_object_string_add(
9884 json,
9885 "updateDelayFirstNeighbor",
9886 bgp->update_delay_begin_time);
9887 json_object_boolean_true_add(
9888 json,
9889 "updateDelayInProgress");
9890 } else {
9891 if (bgp->update_delay_over) {
d62a17ae 9892 json_object_string_add(
9893 json,
9894 "updateDelayFirstNeighbor",
9895 bgp->update_delay_begin_time);
ea47320b 9896 json_object_string_add(
d62a17ae 9897 json,
ea47320b
DL
9898 "updateDelayBestpathResumed",
9899 bgp->update_delay_end_time);
9900 json_object_string_add(
d62a17ae 9901 json,
ea47320b
DL
9902 "updateDelayZebraUpdateResume",
9903 bgp->update_delay_zebra_resume_time);
9904 json_object_string_add(
9905 json,
9906 "updateDelayPeerUpdateResume",
9907 bgp->update_delay_peers_resume_time);
d62a17ae 9908 }
ea47320b
DL
9909 }
9910 } else {
9911 vty_out(vty,
9912 "Read-only mode update-delay limit: %d seconds\n",
9913 bgp->v_update_delay);
9914 if (bgp->v_update_delay
9915 != bgp->v_establish_wait)
d62a17ae 9916 vty_out(vty,
ea47320b
DL
9917 " Establish wait: %d seconds\n",
9918 bgp->v_establish_wait);
d62a17ae 9919
60466a63 9920 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9921 vty_out(vty,
9922 " First neighbor established: %s\n",
9923 bgp->update_delay_begin_time);
9924 vty_out(vty,
9925 " Delay in progress\n");
9926 } else {
9927 if (bgp->update_delay_over) {
d62a17ae 9928 vty_out(vty,
9929 " First neighbor established: %s\n",
9930 bgp->update_delay_begin_time);
9931 vty_out(vty,
ea47320b
DL
9932 " Best-paths resumed: %s\n",
9933 bgp->update_delay_end_time);
9934 vty_out(vty,
9935 " zebra update resumed: %s\n",
9936 bgp->update_delay_zebra_resume_time);
9937 vty_out(vty,
9938 " peers update resumed: %s\n",
9939 bgp->update_delay_peers_resume_time);
d62a17ae 9940 }
9941 }
9942 }
ea47320b 9943 }
d62a17ae 9944
ea47320b
DL
9945 if (use_json) {
9946 if (bgp_maxmed_onstartup_configured(bgp)
9947 && bgp->maxmed_active)
9948 json_object_boolean_true_add(
60466a63 9949 json, "maxMedOnStartup");
ea47320b
DL
9950 if (bgp->v_maxmed_admin)
9951 json_object_boolean_true_add(
60466a63 9952 json, "maxMedAdministrative");
d62a17ae 9953
ea47320b
DL
9954 json_object_int_add(
9955 json, "tableVersion",
60466a63 9956 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 9957
60466a63
QY
9958 ents = bgp_table_count(bgp->rib[afi][safi]);
9959 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
9960 json_object_int_add(
9961 json, "ribMemory",
9bcb3eef 9962 ents * sizeof(struct bgp_dest));
d62a17ae 9963
210ec2a0 9964 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
9965 json_object_int_add(json, "peerCount", ents);
9966 json_object_int_add(json, "peerMemory",
9967 ents * sizeof(struct peer));
d62a17ae 9968
ea47320b
DL
9969 if ((ents = listcount(bgp->group))) {
9970 json_object_int_add(
60466a63 9971 json, "peerGroupCount", ents);
ea47320b
DL
9972 json_object_int_add(
9973 json, "peerGroupMemory",
996c9314
LB
9974 ents * sizeof(struct
9975 peer_group));
ea47320b 9976 }
d62a17ae 9977
ea47320b
DL
9978 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9979 BGP_CONFIG_DAMPENING))
9980 json_object_boolean_true_add(
60466a63 9981 json, "dampeningEnabled");
ea47320b
DL
9982 } else {
9983 if (bgp_maxmed_onstartup_configured(bgp)
9984 && bgp->maxmed_active)
d62a17ae 9985 vty_out(vty,
ea47320b
DL
9986 "Max-med on-startup active\n");
9987 if (bgp->v_maxmed_admin)
d62a17ae 9988 vty_out(vty,
ea47320b 9989 "Max-med administrative active\n");
d62a17ae 9990
60466a63
QY
9991 vty_out(vty, "BGP table version %" PRIu64 "\n",
9992 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 9993
60466a63 9994 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
9995 vty_out(vty,
9996 "RIB entries %ld, using %s of memory\n",
9997 ents,
9bcb3eef
DS
9998 mtype_memstr(
9999 memstrbuf, sizeof(memstrbuf),
10000 ents
10001 * sizeof(struct
10002 bgp_dest)));
ea47320b
DL
10003
10004 /* Peer related usage */
210ec2a0 10005 ents = bgp->af_peer_count[afi][safi];
60466a63 10006 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
10007 ents,
10008 mtype_memstr(
60466a63
QY
10009 memstrbuf, sizeof(memstrbuf),
10010 ents * sizeof(struct peer)));
ea47320b
DL
10011
10012 if ((ents = listcount(bgp->group)))
d62a17ae 10013 vty_out(vty,
ea47320b 10014 "Peer groups %ld, using %s of memory\n",
d62a17ae 10015 ents,
10016 mtype_memstr(
10017 memstrbuf,
10018 sizeof(memstrbuf),
996c9314
LB
10019 ents * sizeof(struct
10020 peer_group)));
d62a17ae 10021
ea47320b
DL
10022 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10023 BGP_CONFIG_DAMPENING))
60466a63 10024 vty_out(vty, "Dampening enabled.\n");
ea47320b 10025 vty_out(vty, "\n");
d62a17ae 10026
ea47320b
DL
10027 /* Subtract 8 here because 'Neighbor' is
10028 * 8 characters */
10029 vty_out(vty, "Neighbor");
60466a63
QY
10030 vty_out(vty, "%*s", max_neighbor_width - 8,
10031 " ");
3577f1c5
DD
10032 if (show_failed)
10033 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
10034 else
10035 vty_out(vty,
db92d226 10036 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
d62a17ae 10037 }
ea47320b 10038 }
d62a17ae 10039
d55811cc 10040 paf = peer_af_find(peer, afi, safi);
d3ada366 10041 filter = &peer->filter[afi][safi];
db92d226 10042
ea47320b 10043 count++;
3577f1c5
DD
10044 /* Works for both failed & successful cases */
10045 if (peer_dynamic_neighbor(peer))
10046 dn_count++;
d62a17ae 10047
ea47320b 10048 if (use_json) {
3577f1c5
DD
10049 json_peer = NULL;
10050
10051 if (show_failed &&
10052 bgp_has_peer_failed(peer, afi, safi)) {
10053 json_peer = json_object_new_object();
10054 bgp_show_failed_summary(vty, bgp, peer,
10055 json_peer, 0, use_json);
10056 } else if (!show_failed) {
10b49f14
DA
10057 if (show_established
10058 && bgp_has_peer_failed(peer, afi, safi))
10059 continue;
10060
3577f1c5
DD
10061 json_peer = json_object_new_object();
10062 if (peer_dynamic_neighbor(peer)) {
10063 json_object_boolean_true_add(json_peer,
10064 "dynamicPeer");
10065 }
d62a17ae 10066
3577f1c5
DD
10067 if (peer->hostname)
10068 json_object_string_add(json_peer, "hostname",
10069 peer->hostname);
10070
10071 if (peer->domainname)
10072 json_object_string_add(json_peer, "domainname",
10073 peer->domainname);
10074
10075 json_object_int_add(json_peer, "remoteAs", peer->as);
10076 json_object_int_add(json_peer, "version", 4);
10077 json_object_int_add(json_peer, "msgRcvd",
10078 PEER_TOTAL_RX(peer));
10079 json_object_int_add(json_peer, "msgSent",
10080 PEER_TOTAL_TX(peer));
10081
43aa5965
QY
10082 atomic_size_t outq_count, inq_count;
10083 outq_count = atomic_load_explicit(
10084 &peer->obuf->count,
10085 memory_order_relaxed);
10086 inq_count = atomic_load_explicit(
10087 &peer->ibuf->count,
10088 memory_order_relaxed);
10089
3577f1c5
DD
10090 json_object_int_add(json_peer, "tableVersion",
10091 peer->version[afi][safi]);
10092 json_object_int_add(json_peer, "outq",
43aa5965
QY
10093 outq_count);
10094 json_object_int_add(json_peer, "inq",
10095 inq_count);
3577f1c5
DD
10096 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10097 use_json, json_peer);
10098
3577f1c5
DD
10099 json_object_int_add(json_peer, "pfxRcd",
10100 peer->pcount[afi][pfx_rcd_safi]);
10101
3577f1c5
DD
10102 if (paf && PAF_SUBGRP(paf))
10103 json_object_int_add(json_peer,
10104 "pfxSnt",
10105 (PAF_SUBGRP(paf))->scount);
cb9196e7 10106 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10107 || CHECK_FLAG(peer->bgp->flags,
10108 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10109 json_object_string_add(json_peer, "state",
10110 "Idle (Admin)");
10111 else if (peer->afc_recv[afi][safi])
10112 json_object_string_add(
10113 json_peer, "state",
10114 lookup_msg(bgp_status_msg, peer->status,
10115 NULL));
10116 else if (CHECK_FLAG(peer->sflags,
10117 PEER_STATUS_PREFIX_OVERFLOW))
10118 json_object_string_add(json_peer, "state",
10119 "Idle (PfxCt)");
10120 else
10121 json_object_string_add(
10122 json_peer, "state",
10123 lookup_msg(bgp_status_msg, peer->status,
10124 NULL));
200116db
DD
10125 json_object_int_add(json_peer, "connectionsEstablished",
10126 peer->established);
10127 json_object_int_add(json_peer, "connectionsDropped",
10128 peer->dropped);
b4e9dcba 10129 }
3577f1c5
DD
10130 /* Avoid creating empty peer dicts in JSON */
10131 if (json_peer == NULL)
10132 continue;
ea47320b
DL
10133
10134 if (peer->conf_if)
60466a63 10135 json_object_string_add(json_peer, "idType",
ea47320b
DL
10136 "interface");
10137 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10138 json_object_string_add(json_peer, "idType",
10139 "ipv4");
ea47320b 10140 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10141 json_object_string_add(json_peer, "idType",
10142 "ipv6");
ea47320b
DL
10143 json_object_object_add(json_peers, peer->host,
10144 json_peer);
10145 } else {
3577f1c5
DD
10146 if (show_failed &&
10147 bgp_has_peer_failed(peer, afi, safi)) {
10148 bgp_show_failed_summary(vty, bgp, peer, NULL,
10149 max_neighbor_width,
10150 use_json);
10151 } else if (!show_failed) {
10b49f14
DA
10152 if (show_established
10153 && bgp_has_peer_failed(peer, afi, safi))
10154 continue;
10155
3577f1c5
DD
10156 memset(dn_flag, '\0', sizeof(dn_flag));
10157 if (peer_dynamic_neighbor(peer)) {
10158 dn_flag[0] = '*';
10159 }
d62a17ae 10160
3577f1c5 10161 if (peer->hostname
892fedb6
DA
10162 && CHECK_FLAG(bgp->flags,
10163 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10164 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10165 peer->hostname,
10166 peer->host);
d62a17ae 10167 else
3577f1c5
DD
10168 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10169
10170 /* pad the neighbor column with spaces */
10171 if (len < max_neighbor_width)
10172 vty_out(vty, "%*s", max_neighbor_width - len,
10173 " ");
10174
43aa5965
QY
10175 atomic_size_t outq_count, inq_count;
10176 outq_count = atomic_load_explicit(
10177 &peer->obuf->count,
10178 memory_order_relaxed);
10179 inq_count = atomic_load_explicit(
10180 &peer->ibuf->count,
10181 memory_order_relaxed);
10182
566bdaf6 10183 vty_out(vty,
6cde4b45 10184 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
3577f1c5 10185 peer->as, PEER_TOTAL_RX(peer),
566bdaf6 10186 PEER_TOTAL_TX(peer),
43aa5965
QY
10187 peer->version[afi][safi], inq_count,
10188 outq_count,
3577f1c5
DD
10189 peer_uptime(peer->uptime, timebuf,
10190 BGP_UPTIME_LEN, 0, NULL));
10191
db92d226 10192 if (peer->status == Established) {
d3ada366
DA
10193 if (peer->afc_recv[afi][safi]) {
10194 if (CHECK_FLAG(
10195 bgp->flags,
10196 BGP_FLAG_EBGP_REQUIRES_POLICY)
10197 && !bgp_inbound_policy_exists(
10198 peer, filter))
10199 vty_out(vty, " %12s",
10200 "(Policy)");
10201 else
10202 vty_out(vty,
6cde4b45 10203 " %12u",
d3ada366
DA
10204 peer->pcount
10205 [afi]
10206 [pfx_rcd_safi]);
10207 } else {
3577f1c5 10208 vty_out(vty, " NoNeg");
d3ada366 10209 }
db92d226 10210
d3ada366
DA
10211 if (paf && PAF_SUBGRP(paf)) {
10212 if (CHECK_FLAG(
10213 bgp->flags,
10214 BGP_FLAG_EBGP_REQUIRES_POLICY)
10215 && !bgp_outbound_policy_exists(
10216 peer, filter))
10217 vty_out(vty, " %8s",
10218 "(Policy)");
10219 else
10220 vty_out(vty,
6cde4b45 10221 " %8u",
d3ada366
DA
10222 (PAF_SUBGRP(
10223 paf))
10224 ->scount);
10225 }
db92d226 10226 } else {
736b68f3
DS
10227 if (CHECK_FLAG(peer->flags,
10228 PEER_FLAG_SHUTDOWN)
10229 || CHECK_FLAG(peer->bgp->flags,
10230 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10231 vty_out(vty, " Idle (Admin)");
10232 else if (CHECK_FLAG(
10233 peer->sflags,
10234 PEER_STATUS_PREFIX_OVERFLOW))
10235 vty_out(vty, " Idle (PfxCt)");
10236 else
10237 vty_out(vty, " %12s",
10238 lookup_msg(bgp_status_msg,
10239 peer->status, NULL));
db92d226 10240
6cde4b45 10241 vty_out(vty, " %8u", 0);
3577f1c5
DD
10242 }
10243 vty_out(vty, "\n");
d62a17ae 10244 }
3577f1c5 10245
d62a17ae 10246 }
10247 }
f933309e 10248
d62a17ae 10249 if (use_json) {
10250 json_object_object_add(json, "peers", json_peers);
3577f1c5 10251 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 10252 json_object_int_add(json, "totalPeers", count);
10253 json_object_int_add(json, "dynamicPeers", dn_count);
10254
3577f1c5
DD
10255 if (!show_failed)
10256 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10257
996c9314
LB
10258 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10259 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10260 json_object_free(json);
10261 } else {
10262 if (count)
10263 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10264 else {
d6ceaca3 10265 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10266 get_afi_safi_str(afi, safi, false));
d62a17ae 10267 }
b05a1c8b 10268
d6ceaca3 10269 if (dn_count) {
d62a17ae 10270 vty_out(vty, "* - dynamic neighbor\n");
10271 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10272 dn_count, bgp->dynamic_neighbors_limit);
10273 }
10274 }
1ff9a340 10275
d62a17ae 10276 return CMD_SUCCESS;
718e3744 10277}
10278
d62a17ae 10279static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10b49f14
DA
10280 int safi, bool show_failed,
10281 bool show_established, bool use_json)
d62a17ae 10282{
10283 int is_first = 1;
10284 int afi_wildcard = (afi == AFI_MAX);
10285 int safi_wildcard = (safi == SAFI_MAX);
10286 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10287 bool nbr_output = false;
d62a17ae 10288
10289 if (use_json && is_wildcard)
10290 vty_out(vty, "{\n");
10291 if (afi_wildcard)
10292 afi = 1; /* AFI_IP */
10293 while (afi < AFI_MAX) {
10294 if (safi_wildcard)
10295 safi = 1; /* SAFI_UNICAST */
10296 while (safi < SAFI_MAX) {
318cac96 10297 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10298 nbr_output = true;
f86897b9 10299
d62a17ae 10300 if (is_wildcard) {
10301 /*
10302 * So limit output to those afi/safi
10303 * pairs that
10304 * actualy have something interesting in
10305 * them
10306 */
10307 if (use_json) {
d62a17ae 10308 if (!is_first)
10309 vty_out(vty, ",\n");
10310 else
10311 is_first = 0;
10312
10313 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10314 get_afi_safi_str(afi,
10315 safi,
10316 true));
d62a17ae 10317 } else {
10318 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
10319 get_afi_safi_str(afi,
10320 safi,
10321 false));
d62a17ae 10322 }
10323 }
10b49f14
DA
10324 bgp_show_summary(vty, bgp, afi, safi,
10325 show_failed, show_established,
3577f1c5 10326 use_json);
d62a17ae 10327 }
10328 safi++;
d62a17ae 10329 if (!safi_wildcard)
10330 safi = SAFI_MAX;
10331 }
10332 afi++;
ee851c8c 10333 if (!afi_wildcard)
d62a17ae 10334 afi = AFI_MAX;
10335 }
10336
10337 if (use_json && is_wildcard)
10338 vty_out(vty, "}\n");
ca61fd25
DS
10339 else if (!nbr_output) {
10340 if (use_json)
10341 vty_out(vty, "{}\n");
10342 else
10343 vty_out(vty, "%% No BGP neighbors found\n");
10344 }
d62a17ae 10345}
10346
10347static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5 10348 safi_t safi, bool show_failed,
10b49f14 10349 bool show_established,
3577f1c5 10350 bool use_json)
d62a17ae 10351{
10352 struct listnode *node, *nnode;
10353 struct bgp *bgp;
d62a17ae 10354 int is_first = 1;
9f049418 10355 bool nbr_output = false;
d62a17ae 10356
10357 if (use_json)
10358 vty_out(vty, "{\n");
10359
10360 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10361 nbr_output = true;
d62a17ae 10362 if (use_json) {
d62a17ae 10363 if (!is_first)
10364 vty_out(vty, ",\n");
10365 else
10366 is_first = 0;
10367
10368 vty_out(vty, "\"%s\":",
10369 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10370 ? VRF_DEFAULT_NAME
d62a17ae 10371 : bgp->name);
10372 } else {
10373 vty_out(vty, "\nInstance %s:\n",
10374 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10375 ? VRF_DEFAULT_NAME
d62a17ae 10376 : bgp->name);
10377 }
3577f1c5 10378 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 10379 show_established, use_json);
d62a17ae 10380 }
10381
10382 if (use_json)
10383 vty_out(vty, "}\n");
9f049418
DS
10384 else if (!nbr_output)
10385 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10386}
10387
10388int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10b49f14
DA
10389 safi_t safi, bool show_failed, bool show_established,
10390 bool use_json)
d62a17ae 10391{
10392 struct bgp *bgp;
10393
10394 if (name) {
10395 if (strmatch(name, "all")) {
10b49f14
DA
10396 bgp_show_all_instances_summary_vty(
10397 vty, afi, safi, show_failed, show_established,
10398 use_json);
d62a17ae 10399 return CMD_SUCCESS;
10400 } else {
10401 bgp = bgp_lookup_by_name(name);
10402
10403 if (!bgp) {
10404 if (use_json)
10405 vty_out(vty, "{}\n");
10406 else
10407 vty_out(vty,
ca61fd25 10408 "%% BGP instance not found\n");
d62a17ae 10409 return CMD_WARNING;
10410 }
10411
f86897b9 10412 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
10b49f14
DA
10413 show_failed, show_established,
10414 use_json);
d62a17ae 10415 return CMD_SUCCESS;
10416 }
10417 }
10418
10419 bgp = bgp_get_default();
10420
10421 if (bgp)
3577f1c5 10422 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 10423 show_established, use_json);
9f049418 10424 else {
ca61fd25
DS
10425 if (use_json)
10426 vty_out(vty, "{}\n");
10427 else
10428 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
10429 return CMD_WARNING;
10430 }
d62a17ae 10431
10432 return CMD_SUCCESS;
4fb25c53
DW
10433}
10434
716b2d8a 10435/* `show [ip] bgp summary' commands. */
96f3485c 10436DEFPY (show_ip_bgp_summary,
718e3744 10437 show_ip_bgp_summary_cmd,
96f3485c 10438 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
718e3744 10439 SHOW_STR
10440 IP_STR
10441 BGP_STR
8386ac43 10442 BGP_INSTANCE_HELP_STR
46f296b4 10443 BGP_AFI_HELP_STR
dd6bd0f1 10444 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 10445 "Display the entries for all address families\n"
b05a1c8b 10446 "Summary of BGP neighbor status\n"
10b49f14 10447 "Show only sessions in Established state\n"
3577f1c5 10448 "Show only sessions not in Established state\n"
9973d184 10449 JSON_STR)
718e3744 10450{
d62a17ae 10451 char *vrf = NULL;
10452 afi_t afi = AFI_MAX;
10453 safi_t safi = SAFI_MAX;
3577f1c5 10454 bool show_failed = false;
10b49f14 10455 bool show_established = false;
d62a17ae 10456
10457 int idx = 0;
10458
10459 /* show [ip] bgp */
96f3485c 10460 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 10461 afi = AFI_IP;
9a8bdf1c
PG
10462 /* [<vrf> VIEWVRFNAME] */
10463 if (argv_find(argv, argc, "vrf", &idx)) {
10464 vrf = argv[idx + 1]->arg;
10465 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10466 vrf = NULL;
10467 } else if (argv_find(argv, argc, "view", &idx))
10468 /* [<view> VIEWVRFNAME] */
10469 vrf = argv[idx + 1]->arg;
d62a17ae 10470 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10471 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10472 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10473 }
10474
3577f1c5
DD
10475 if (argv_find(argv, argc, "failed", &idx))
10476 show_failed = true;
10b49f14
DA
10477 if (argv_find(argv, argc, "established", &idx))
10478 show_established = true;
3577f1c5 10479
10b49f14
DA
10480 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
10481 show_established, uj);
d62a17ae 10482}
10483
5cb5f4d0 10484const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 10485{
5cb5f4d0
DD
10486 if (for_json)
10487 return get_afi_safi_json_str(afi, safi);
d62a17ae 10488 else
5cb5f4d0 10489 return get_afi_safi_vty_str(afi, safi);
27162734
LB
10490}
10491
d62a17ae 10492
10493static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
10494 afi_t afi, safi_t safi,
d7c0a89a
QY
10495 uint16_t adv_smcap, uint16_t adv_rmcap,
10496 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 10497 bool use_json, json_object *json_pref)
d62a17ae 10498{
10499 /* Send-Mode */
10500 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10501 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
10502 if (use_json) {
10503 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10504 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10505 json_object_string_add(json_pref, "sendMode",
10506 "advertisedAndReceived");
10507 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10508 json_object_string_add(json_pref, "sendMode",
10509 "advertised");
10510 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10511 json_object_string_add(json_pref, "sendMode",
10512 "received");
10513 } else {
10514 vty_out(vty, " Send-mode: ");
10515 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10516 vty_out(vty, "advertised");
10517 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10518 vty_out(vty, "%sreceived",
10519 CHECK_FLAG(p->af_cap[afi][safi],
10520 adv_smcap)
10521 ? ", "
10522 : "");
10523 vty_out(vty, "\n");
10524 }
10525 }
10526
10527 /* Receive-Mode */
10528 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10529 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
10530 if (use_json) {
10531 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10532 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10533 json_object_string_add(json_pref, "recvMode",
10534 "advertisedAndReceived");
10535 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10536 json_object_string_add(json_pref, "recvMode",
10537 "advertised");
10538 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10539 json_object_string_add(json_pref, "recvMode",
10540 "received");
10541 } else {
10542 vty_out(vty, " Receive-mode: ");
10543 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10544 vty_out(vty, "advertised");
10545 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10546 vty_out(vty, "%sreceived",
10547 CHECK_FLAG(p->af_cap[afi][safi],
10548 adv_rmcap)
10549 ? ", "
10550 : "");
10551 vty_out(vty, "\n");
10552 }
10553 }
10554}
10555
13909c4f
DS
10556static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
10557 struct peer *p,
10558 bool use_json,
10559 json_object *json)
2986cac2 10560{
08c2d52a 10561 bool rbit_status = false;
2986cac2 10562
10563 if (!use_json)
a53ca37b 10564 vty_out(vty, "\n R bit: ");
2986cac2 10565
13909c4f
DS
10566 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
10567 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
10568 && (p->status == Established)) {
2986cac2 10569
10570 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 10571 rbit_status = true;
2986cac2 10572 else
08c2d52a 10573 rbit_status = false;
2986cac2 10574 }
10575
10576 if (rbit_status) {
10577 if (use_json)
13909c4f 10578 json_object_boolean_true_add(json, "rBit");
2986cac2 10579 else
10580 vty_out(vty, "True\n");
10581 } else {
10582 if (use_json)
13909c4f 10583 json_object_boolean_false_add(json, "rBit");
2986cac2 10584 else
10585 vty_out(vty, "False\n");
10586 }
10587}
10588
13909c4f
DS
10589static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
10590 struct peer *peer,
10591 bool use_json,
10592 json_object *json)
2986cac2 10593{
2bb5d39b 10594 const char *mode = "NotApplicable";
2986cac2 10595
10596 if (!use_json)
a53ca37b 10597 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 10598
13909c4f
DS
10599 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10600 && (peer->status == Established)) {
2986cac2 10601
13909c4f
DS
10602 if ((peer->nsf_af_count == 0)
10603 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10604
2986cac2 10605 mode = "Disable";
10606
13909c4f
DS
10607 } else if (peer->nsf_af_count == 0
10608 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10609
2986cac2 10610 mode = "Helper";
10611
13909c4f
DS
10612 } else if (peer->nsf_af_count != 0
10613 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10614
2986cac2 10615 mode = "Restart";
2986cac2 10616 }
10617 }
10618
10619 if (use_json) {
13909c4f 10620 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 10621 } else
10622 vty_out(vty, mode, "\n");
10623}
10624
13909c4f
DS
10625static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
10626 struct peer *p,
10627 bool use_json,
10628 json_object *json)
2986cac2 10629{
10630 const char *mode = "Invalid";
10631
10632 if (!use_json)
a53ca37b 10633 vty_out(vty, " Local GR Mode: ");
2986cac2 10634
10635 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
10636 mode = "Helper";
10637 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
10638 mode = "Restart";
10639 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
10640 mode = "Disable";
2ba1fe69 10641 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 10642 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
10643 mode = "Helper*";
10644 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
10645 mode = "Restart*";
10646 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
10647 mode = "Disable*";
10648 else
10649 mode = "Invalid*";
2ba1fe69 10650 }
2986cac2 10651
10652 if (use_json) {
13909c4f 10653 json_object_string_add(json, "localGrMode", mode);
2986cac2 10654 } else {
10655 vty_out(vty, mode, "\n");
10656 }
10657}
10658
13909c4f
DS
10659static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
10660 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 10661{
2ba1fe69 10662 afi_t afi;
10663 safi_t safi;
2986cac2 10664 json_object *json_afi_safi = NULL;
10665 json_object *json_timer = NULL;
10666 json_object *json_endofrib_status = NULL;
9e3b51a7 10667 bool eor_flag = false;
2986cac2 10668
10669 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10670 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
10671 if (!peer->afc[afi][safi])
10672 continue;
2986cac2 10673
13909c4f
DS
10674 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10675 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
10676 continue;
9e3b51a7 10677
13909c4f
DS
10678 if (use_json) {
10679 json_afi_safi = json_object_new_object();
10680 json_endofrib_status = json_object_new_object();
10681 json_timer = json_object_new_object();
10682 }
2986cac2 10683
13909c4f
DS
10684 if (peer->eor_stime[afi][safi]
10685 >= peer->pkt_stime[afi][safi])
10686 eor_flag = true;
10687 else
10688 eor_flag = false;
2986cac2 10689
13909c4f 10690 if (!use_json) {
a53ca37b 10691 vty_out(vty, " %s:\n",
13909c4f 10692 get_afi_safi_str(afi, safi, false));
2986cac2 10693
a53ca37b 10694 vty_out(vty, " F bit: ");
698ba8d0 10695 }
2986cac2 10696
13909c4f
DS
10697 if (peer->nsf[afi][safi]
10698 && CHECK_FLAG(peer->af_cap[afi][safi],
10699 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 10700
13909c4f
DS
10701 if (use_json) {
10702 json_object_boolean_true_add(
2986cac2 10703 json_afi_safi, "fBit");
13909c4f
DS
10704 } else
10705 vty_out(vty, "True\n");
10706 } else {
10707 if (use_json)
10708 json_object_boolean_false_add(
10709 json_afi_safi, "fBit");
10710 else
10711 vty_out(vty, "False\n");
10712 }
2986cac2 10713
13909c4f 10714 if (!use_json)
a53ca37b 10715 vty_out(vty, " End-of-RIB sent: ");
2986cac2 10716
13909c4f
DS
10717 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10718 PEER_STATUS_EOR_SEND)) {
10719 if (use_json) {
10720 json_object_boolean_true_add(
2986cac2 10721 json_endofrib_status,
13909c4f 10722 "endOfRibSend");
9e3b51a7 10723
13909c4f
DS
10724 PRINT_EOR_JSON(eor_flag);
10725 } else {
10726 vty_out(vty, "Yes\n");
10727 vty_out(vty,
a53ca37b 10728 " End-of-RIB sent after update: ");
2986cac2 10729
13909c4f
DS
10730 PRINT_EOR(eor_flag);
10731 }
10732 } else {
10733 if (use_json) {
10734 json_object_boolean_false_add(
2986cac2 10735 json_endofrib_status,
13909c4f
DS
10736 "endOfRibSend");
10737 json_object_boolean_false_add(
9e3b51a7 10738 json_endofrib_status,
13909c4f
DS
10739 "endOfRibSentAfterUpdate");
10740 } else {
10741 vty_out(vty, "No\n");
10742 vty_out(vty,
a53ca37b 10743 " End-of-RIB sent after update: ");
13909c4f 10744 vty_out(vty, "No\n");
2986cac2 10745 }
13909c4f 10746 }
2986cac2 10747
a53ca37b
DA
10748 if (!use_json)
10749 vty_out(vty, " End-of-RIB received: ");
10750
10751 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10752 PEER_STATUS_EOR_RECEIVED)) {
10753 if (use_json)
10754 json_object_boolean_true_add(
10755 json_endofrib_status,
10756 "endOfRibRecv");
10757 else
10758 vty_out(vty, "Yes\n");
10759 } else {
10760 if (use_json)
10761 json_object_boolean_false_add(
10762 json_endofrib_status,
10763 "endOfRibRecv");
10764 else
10765 vty_out(vty, "No\n");
10766 }
10767
13909c4f
DS
10768 if (use_json) {
10769 json_object_int_add(json_timer,
10770 "stalePathTimer",
10771 peer->bgp->stalepath_time);
2986cac2 10772
13909c4f
DS
10773 if (peer->t_gr_stale != NULL) {
10774 json_object_int_add(
2986cac2 10775 json_timer,
10776 "stalePathTimerRemaining",
10777 thread_timer_remain_second(
13909c4f
DS
10778 peer->t_gr_stale));
10779 }
3a75afa4 10780
13909c4f
DS
10781 /* Display Configured Selection
10782 * Deferral only when when
10783 * Gr mode is enabled.
10784 */
10785 if (CHECK_FLAG(peer->flags,
10786 PEER_FLAG_GRACEFUL_RESTART)) {
10787 json_object_int_add(
3a75afa4 10788 json_timer,
2986cac2 10789 "selectionDeferralTimer",
10790 peer->bgp->stalepath_time);
13909c4f 10791 }
2986cac2 10792
13909c4f
DS
10793 if (peer->bgp->gr_info[afi][safi]
10794 .t_select_deferral
10795 != NULL) {
2986cac2 10796
13909c4f 10797 json_object_int_add(
2986cac2 10798 json_timer,
10799 "selectionDeferralTimerRemaining",
10800 thread_timer_remain_second(
13909c4f
DS
10801 peer->bgp
10802 ->gr_info[afi]
10803 [safi]
10804 .t_select_deferral));
10805 }
10806 } else {
a53ca37b 10807 vty_out(vty, " Timers:\n");
13909c4f 10808 vty_out(vty,
a53ca37b
DA
10809 " Configured Stale Path Time(sec): %u\n",
10810 peer->bgp->stalepath_time);
2986cac2 10811
a53ca37b 10812 if (peer->t_gr_stale != NULL)
2986cac2 10813 vty_out(vty,
a53ca37b 10814 " Stale Path Remaining(sec): %ld\n",
2986cac2 10815 thread_timer_remain_second(
13909c4f 10816 peer->t_gr_stale));
13909c4f
DS
10817 /* Display Configured Selection
10818 * Deferral only when when
10819 * Gr mode is enabled.
10820 */
10821 if (CHECK_FLAG(peer->flags,
a53ca37b 10822 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 10823 vty_out(vty,
a53ca37b 10824 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 10825 peer->bgp->select_defer_time);
2986cac2 10826
13909c4f
DS
10827 if (peer->bgp->gr_info[afi][safi]
10828 .t_select_deferral
a53ca37b 10829 != NULL)
13909c4f 10830 vty_out(vty,
a53ca37b 10831 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 10832 thread_timer_remain_second(
13909c4f
DS
10833 peer->bgp
10834 ->gr_info[afi]
10835 [safi]
10836 .t_select_deferral));
2986cac2 10837 }
13909c4f
DS
10838 if (use_json) {
10839 json_object_object_add(json_afi_safi,
10840 "endOfRibStatus",
10841 json_endofrib_status);
10842 json_object_object_add(json_afi_safi, "timers",
10843 json_timer);
10844 json_object_object_add(
10845 json, get_afi_safi_str(afi, safi, true),
10846 json_afi_safi);
10847 }
2986cac2 10848 }
10849 }
10850}
10851
36235319
QY
10852static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
10853 struct peer *p,
10854 bool use_json,
10855 json_object *json)
2986cac2 10856{
10857 if (use_json) {
10858 json_object *json_timer = NULL;
10859
10860 json_timer = json_object_new_object();
10861
13909c4f
DS
10862 json_object_int_add(json_timer, "configuredRestartTimer",
10863 p->bgp->restart_time);
2986cac2 10864
13909c4f
DS
10865 json_object_int_add(json_timer, "receivedRestartTimer",
10866 p->v_gr_restart);
2986cac2 10867
13909c4f
DS
10868 if (p->t_gr_restart != NULL)
10869 json_object_int_add(
10870 json_timer, "restartTimerRemaining",
10871 thread_timer_remain_second(p->t_gr_restart));
2986cac2 10872
10873 json_object_object_add(json, "timers", json_timer);
10874 } else {
10875
a53ca37b
DA
10876 vty_out(vty, " Timers:\n");
10877 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 10878 p->bgp->restart_time);
2986cac2 10879
a53ca37b 10880 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
10881 p->v_gr_restart);
10882 if (p->t_gr_restart != NULL)
a53ca37b 10883 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 10884 thread_timer_remain_second(p->t_gr_restart));
36235319 10885 if (p->t_gr_restart != NULL) {
a53ca37b 10886 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
10887 thread_timer_remain_second(p->t_gr_restart));
10888 }
2986cac2 10889 }
10890}
10891
10892static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 10893 bool use_json, json_object *json)
2986cac2 10894{
10895 char buf[SU_ADDRSTRLEN] = {0};
10896 char dn_flag[2] = {0};
2b7165e7
QY
10897 /* '*' + v6 address of neighbor */
10898 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 10899
2986cac2 10900 if (!p->conf_if && peer_dynamic_neighbor(p))
10901 dn_flag[0] = '*';
10902
10903 if (p->conf_if) {
10904 if (use_json)
13909c4f
DS
10905 json_object_string_add(
10906 json, "neighborAddr",
2986cac2 10907 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
10908 ? "none"
10909 : sockunion2str(&p->su, buf,
10910 SU_ADDRSTRLEN));
2986cac2 10911 else
13909c4f 10912 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 10913 BGP_PEER_SU_UNSPEC(p)
10914 ? "none"
10915 : sockunion2str(&p->su, buf,
10916 SU_ADDRSTRLEN));
10917 } else {
772270f3
QY
10918 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
10919 p->host);
2986cac2 10920
10921 if (use_json)
36235319
QY
10922 json_object_string_add(json, "neighborAddr",
10923 neighborAddr);
2986cac2 10924 else
36235319 10925 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 10926 }
10927
10928 /* more gr info in new format */
10929 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
10930}
10931
d62a17ae 10932static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 10933 safi_t safi, bool use_json,
d62a17ae 10934 json_object *json_neigh)
10935{
0291c246
MK
10936 struct bgp_filter *filter;
10937 struct peer_af *paf;
10938 char orf_pfx_name[BUFSIZ];
10939 int orf_pfx_count;
10940 json_object *json_af = NULL;
10941 json_object *json_prefA = NULL;
10942 json_object *json_prefB = NULL;
10943 json_object *json_addr = NULL;
fa36596c 10944 json_object *json_advmap = NULL;
d62a17ae 10945
10946 if (use_json) {
10947 json_addr = json_object_new_object();
10948 json_af = json_object_new_object();
10949 filter = &p->filter[afi][safi];
10950
10951 if (peer_group_active(p))
10952 json_object_string_add(json_addr, "peerGroupMember",
10953 p->group->name);
10954
10955 paf = peer_af_find(p, afi, safi);
10956 if (paf && PAF_SUBGRP(paf)) {
10957 json_object_int_add(json_addr, "updateGroupId",
10958 PAF_UPDGRP(paf)->id);
10959 json_object_int_add(json_addr, "subGroupId",
10960 PAF_SUBGRP(paf)->id);
10961 json_object_int_add(json_addr, "packetQueueLength",
10962 bpacket_queue_virtual_length(paf));
10963 }
10964
10965 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10966 || CHECK_FLAG(p->af_cap[afi][safi],
10967 PEER_CAP_ORF_PREFIX_SM_RCV)
10968 || CHECK_FLAG(p->af_cap[afi][safi],
10969 PEER_CAP_ORF_PREFIX_RM_ADV)
10970 || CHECK_FLAG(p->af_cap[afi][safi],
10971 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10972 json_object_int_add(json_af, "orfType",
10973 ORF_TYPE_PREFIX);
10974 json_prefA = json_object_new_object();
10975 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
10976 PEER_CAP_ORF_PREFIX_SM_ADV,
10977 PEER_CAP_ORF_PREFIX_RM_ADV,
10978 PEER_CAP_ORF_PREFIX_SM_RCV,
10979 PEER_CAP_ORF_PREFIX_RM_RCV,
10980 use_json, json_prefA);
10981 json_object_object_add(json_af, "orfPrefixList",
10982 json_prefA);
10983 }
10984
10985 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10986 || CHECK_FLAG(p->af_cap[afi][safi],
10987 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10988 || CHECK_FLAG(p->af_cap[afi][safi],
10989 PEER_CAP_ORF_PREFIX_RM_ADV)
10990 || CHECK_FLAG(p->af_cap[afi][safi],
10991 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10992 json_object_int_add(json_af, "orfOldType",
10993 ORF_TYPE_PREFIX_OLD);
10994 json_prefB = json_object_new_object();
10995 bgp_show_peer_afi_orf_cap(
10996 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10997 PEER_CAP_ORF_PREFIX_RM_ADV,
10998 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10999 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11000 json_prefB);
11001 json_object_object_add(json_af, "orfOldPrefixList",
11002 json_prefB);
11003 }
11004
11005 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11006 || CHECK_FLAG(p->af_cap[afi][safi],
11007 PEER_CAP_ORF_PREFIX_SM_RCV)
11008 || CHECK_FLAG(p->af_cap[afi][safi],
11009 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11010 || CHECK_FLAG(p->af_cap[afi][safi],
11011 PEER_CAP_ORF_PREFIX_RM_ADV)
11012 || CHECK_FLAG(p->af_cap[afi][safi],
11013 PEER_CAP_ORF_PREFIX_RM_RCV)
11014 || CHECK_FLAG(p->af_cap[afi][safi],
11015 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11016 json_object_object_add(json_addr, "afDependentCap",
11017 json_af);
11018 else
11019 json_object_free(json_af);
11020
772270f3
QY
11021 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11022 p->host, afi, safi);
d62a17ae 11023 orf_pfx_count = prefix_bgp_show_prefix_list(
11024 NULL, afi, orf_pfx_name, use_json);
11025
11026 if (CHECK_FLAG(p->af_sflags[afi][safi],
11027 PEER_STATUS_ORF_PREFIX_SEND)
11028 || orf_pfx_count) {
11029 if (CHECK_FLAG(p->af_sflags[afi][safi],
11030 PEER_STATUS_ORF_PREFIX_SEND))
11031 json_object_boolean_true_add(json_neigh,
11032 "orfSent");
11033 if (orf_pfx_count)
11034 json_object_int_add(json_addr, "orfRecvCounter",
11035 orf_pfx_count);
11036 }
11037 if (CHECK_FLAG(p->af_sflags[afi][safi],
11038 PEER_STATUS_ORF_WAIT_REFRESH))
11039 json_object_string_add(
11040 json_addr, "orfFirstUpdate",
11041 "deferredUntilORFOrRouteRefreshRecvd");
11042
11043 if (CHECK_FLAG(p->af_flags[afi][safi],
11044 PEER_FLAG_REFLECTOR_CLIENT))
11045 json_object_boolean_true_add(json_addr,
11046 "routeReflectorClient");
11047 if (CHECK_FLAG(p->af_flags[afi][safi],
11048 PEER_FLAG_RSERVER_CLIENT))
11049 json_object_boolean_true_add(json_addr,
11050 "routeServerClient");
11051 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11052 json_object_boolean_true_add(json_addr,
11053 "inboundSoftConfigPermit");
11054
11055 if (CHECK_FLAG(p->af_flags[afi][safi],
11056 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11057 json_object_boolean_true_add(
11058 json_addr,
11059 "privateAsNumsAllReplacedInUpdatesToNbr");
11060 else if (CHECK_FLAG(p->af_flags[afi][safi],
11061 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11062 json_object_boolean_true_add(
11063 json_addr,
11064 "privateAsNumsReplacedInUpdatesToNbr");
11065 else if (CHECK_FLAG(p->af_flags[afi][safi],
11066 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11067 json_object_boolean_true_add(
11068 json_addr,
11069 "privateAsNumsAllRemovedInUpdatesToNbr");
11070 else if (CHECK_FLAG(p->af_flags[afi][safi],
11071 PEER_FLAG_REMOVE_PRIVATE_AS))
11072 json_object_boolean_true_add(
11073 json_addr,
11074 "privateAsNumsRemovedInUpdatesToNbr");
11075
dcc68b5e
MS
11076 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11077 json_object_boolean_true_add(
11078 json_addr,
11079 bgp_addpath_names(p->addpath_type[afi][safi])
11080 ->type_json_name);
d62a17ae 11081
11082 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11083 json_object_string_add(json_addr,
11084 "overrideASNsInOutboundUpdates",
11085 "ifAspathEqualRemoteAs");
11086
11087 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11088 || CHECK_FLAG(p->af_flags[afi][safi],
11089 PEER_FLAG_FORCE_NEXTHOP_SELF))
11090 json_object_boolean_true_add(json_addr,
11091 "routerAlwaysNextHop");
11092 if (CHECK_FLAG(p->af_flags[afi][safi],
11093 PEER_FLAG_AS_PATH_UNCHANGED))
11094 json_object_boolean_true_add(
11095 json_addr, "unchangedAsPathPropogatedToNbr");
11096 if (CHECK_FLAG(p->af_flags[afi][safi],
11097 PEER_FLAG_NEXTHOP_UNCHANGED))
11098 json_object_boolean_true_add(
11099 json_addr, "unchangedNextHopPropogatedToNbr");
11100 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11101 json_object_boolean_true_add(
11102 json_addr, "unchangedMedPropogatedToNbr");
11103 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11104 || CHECK_FLAG(p->af_flags[afi][safi],
11105 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11106 if (CHECK_FLAG(p->af_flags[afi][safi],
11107 PEER_FLAG_SEND_COMMUNITY)
11108 && CHECK_FLAG(p->af_flags[afi][safi],
11109 PEER_FLAG_SEND_EXT_COMMUNITY))
11110 json_object_string_add(json_addr,
11111 "commAttriSentToNbr",
11112 "extendedAndStandard");
11113 else if (CHECK_FLAG(p->af_flags[afi][safi],
11114 PEER_FLAG_SEND_EXT_COMMUNITY))
11115 json_object_string_add(json_addr,
11116 "commAttriSentToNbr",
11117 "extended");
11118 else
11119 json_object_string_add(json_addr,
11120 "commAttriSentToNbr",
11121 "standard");
11122 }
11123 if (CHECK_FLAG(p->af_flags[afi][safi],
11124 PEER_FLAG_DEFAULT_ORIGINATE)) {
11125 if (p->default_rmap[afi][safi].name)
11126 json_object_string_add(
11127 json_addr, "defaultRouteMap",
11128 p->default_rmap[afi][safi].name);
11129
11130 if (paf && PAF_SUBGRP(paf)
11131 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11132 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11133 json_object_boolean_true_add(json_addr,
11134 "defaultSent");
11135 else
11136 json_object_boolean_true_add(json_addr,
11137 "defaultNotSent");
11138 }
11139
dff8f48d 11140 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11141 if (is_evpn_enabled())
60466a63
QY
11142 json_object_boolean_true_add(
11143 json_addr, "advertiseAllVnis");
dff8f48d
MK
11144 }
11145
d62a17ae 11146 if (filter->plist[FILTER_IN].name
11147 || filter->dlist[FILTER_IN].name
11148 || filter->aslist[FILTER_IN].name
11149 || filter->map[RMAP_IN].name)
11150 json_object_boolean_true_add(json_addr,
11151 "inboundPathPolicyConfig");
11152 if (filter->plist[FILTER_OUT].name
11153 || filter->dlist[FILTER_OUT].name
11154 || filter->aslist[FILTER_OUT].name
11155 || filter->map[RMAP_OUT].name || filter->usmap.name)
11156 json_object_boolean_true_add(
11157 json_addr, "outboundPathPolicyConfig");
11158
11159 /* prefix-list */
11160 if (filter->plist[FILTER_IN].name)
11161 json_object_string_add(json_addr,
11162 "incomingUpdatePrefixFilterList",
11163 filter->plist[FILTER_IN].name);
11164 if (filter->plist[FILTER_OUT].name)
11165 json_object_string_add(json_addr,
11166 "outgoingUpdatePrefixFilterList",
11167 filter->plist[FILTER_OUT].name);
11168
11169 /* distribute-list */
11170 if (filter->dlist[FILTER_IN].name)
11171 json_object_string_add(
11172 json_addr, "incomingUpdateNetworkFilterList",
11173 filter->dlist[FILTER_IN].name);
11174 if (filter->dlist[FILTER_OUT].name)
11175 json_object_string_add(
11176 json_addr, "outgoingUpdateNetworkFilterList",
11177 filter->dlist[FILTER_OUT].name);
11178
11179 /* filter-list. */
11180 if (filter->aslist[FILTER_IN].name)
11181 json_object_string_add(json_addr,
11182 "incomingUpdateAsPathFilterList",
11183 filter->aslist[FILTER_IN].name);
11184 if (filter->aslist[FILTER_OUT].name)
11185 json_object_string_add(json_addr,
11186 "outgoingUpdateAsPathFilterList",
11187 filter->aslist[FILTER_OUT].name);
11188
11189 /* route-map. */
11190 if (filter->map[RMAP_IN].name)
11191 json_object_string_add(
11192 json_addr, "routeMapForIncomingAdvertisements",
11193 filter->map[RMAP_IN].name);
11194 if (filter->map[RMAP_OUT].name)
11195 json_object_string_add(
11196 json_addr, "routeMapForOutgoingAdvertisements",
11197 filter->map[RMAP_OUT].name);
11198
9dac9fc8 11199 /* ebgp-requires-policy (inbound) */
1d3fdccf 11200 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11201 && !bgp_inbound_policy_exists(p, filter))
11202 json_object_string_add(
11203 json_addr, "inboundEbgpRequiresPolicy",
11204 "Inbound updates discarded due to missing policy");
11205
11206 /* ebgp-requires-policy (outbound) */
1d3fdccf 11207 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11208 && (!bgp_outbound_policy_exists(p, filter)))
11209 json_object_string_add(
11210 json_addr, "outboundEbgpRequiresPolicy",
11211 "Outbound updates discarded due to missing policy");
11212
d62a17ae 11213 /* unsuppress-map */
11214 if (filter->usmap.name)
11215 json_object_string_add(json_addr,
11216 "selectiveUnsuppressRouteMap",
11217 filter->usmap.name);
11218
fa36596c
MK
11219 /* advertise-map */
11220 if (filter->advmap.aname) {
11221 json_advmap = json_object_new_object();
11222 json_object_string_add(json_advmap, "condition",
11223 filter->advmap.condition
11224 ? "EXIST"
11225 : "NON_EXIST");
11226 json_object_string_add(json_advmap, "conditionMap",
11227 filter->advmap.cname);
11228 json_object_string_add(json_advmap, "advertiseMap",
11229 filter->advmap.aname);
11230 json_object_string_add(json_advmap, "advertiseStatus",
11231 filter->advmap.update_type
11232 == ADVERTISE
11233 ? "Advertise"
11234 : "Withdraw");
11235 json_object_object_add(json_addr, "advertiseMap",
11236 json_advmap);
11237 }
11238
d62a17ae 11239 /* Receive prefix count */
11240 json_object_int_add(json_addr, "acceptedPrefixCounter",
11241 p->pcount[afi][safi]);
50e05855
AD
11242 if (paf && PAF_SUBGRP(paf))
11243 json_object_int_add(json_addr, "sentPrefixCounter",
11244 (PAF_SUBGRP(paf))->scount);
d62a17ae 11245
fde246e8
DA
11246 /* Maximum prefix */
11247 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11248 json_object_int_add(json_addr, "prefixOutAllowedMax",
11249 p->pmax_out[afi][safi]);
11250
d62a17ae 11251 /* Maximum prefix */
11252 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11253 json_object_int_add(json_addr, "prefixAllowedMax",
11254 p->pmax[afi][safi]);
11255 if (CHECK_FLAG(p->af_flags[afi][safi],
11256 PEER_FLAG_MAX_PREFIX_WARNING))
11257 json_object_boolean_true_add(
11258 json_addr, "prefixAllowedMaxWarning");
11259 json_object_int_add(json_addr,
11260 "prefixAllowedWarningThresh",
11261 p->pmax_threshold[afi][safi]);
11262 if (p->pmax_restart[afi][safi])
11263 json_object_int_add(
11264 json_addr,
11265 "prefixAllowedRestartIntervalMsecs",
11266 p->pmax_restart[afi][safi] * 60000);
11267 }
2986cac2 11268 json_object_object_add(json_neigh,
36235319 11269 get_afi_safi_str(afi, safi, true),
d62a17ae 11270 json_addr);
11271
11272 } else {
11273 filter = &p->filter[afi][safi];
11274
11275 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11276 get_afi_safi_str(afi, safi, false));
d62a17ae 11277
11278 if (peer_group_active(p))
11279 vty_out(vty, " %s peer-group member\n",
11280 p->group->name);
11281
11282 paf = peer_af_find(p, afi, safi);
11283 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11284 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11285 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11286 vty_out(vty, " Packet Queue length %d\n",
11287 bpacket_queue_virtual_length(paf));
11288 } else {
11289 vty_out(vty, " Not part of any update group\n");
11290 }
11291 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11292 || CHECK_FLAG(p->af_cap[afi][safi],
11293 PEER_CAP_ORF_PREFIX_SM_RCV)
11294 || CHECK_FLAG(p->af_cap[afi][safi],
11295 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11296 || CHECK_FLAG(p->af_cap[afi][safi],
11297 PEER_CAP_ORF_PREFIX_RM_ADV)
11298 || CHECK_FLAG(p->af_cap[afi][safi],
11299 PEER_CAP_ORF_PREFIX_RM_RCV)
11300 || CHECK_FLAG(p->af_cap[afi][safi],
11301 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11302 vty_out(vty, " AF-dependant capabilities:\n");
11303
11304 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11305 || CHECK_FLAG(p->af_cap[afi][safi],
11306 PEER_CAP_ORF_PREFIX_SM_RCV)
11307 || CHECK_FLAG(p->af_cap[afi][safi],
11308 PEER_CAP_ORF_PREFIX_RM_ADV)
11309 || CHECK_FLAG(p->af_cap[afi][safi],
11310 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11311 vty_out(vty,
11312 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11313 ORF_TYPE_PREFIX);
11314 bgp_show_peer_afi_orf_cap(
11315 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11316 PEER_CAP_ORF_PREFIX_RM_ADV,
11317 PEER_CAP_ORF_PREFIX_SM_RCV,
11318 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11319 }
11320 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11321 || CHECK_FLAG(p->af_cap[afi][safi],
11322 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11323 || CHECK_FLAG(p->af_cap[afi][safi],
11324 PEER_CAP_ORF_PREFIX_RM_ADV)
11325 || CHECK_FLAG(p->af_cap[afi][safi],
11326 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11327 vty_out(vty,
11328 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11329 ORF_TYPE_PREFIX_OLD);
11330 bgp_show_peer_afi_orf_cap(
11331 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11332 PEER_CAP_ORF_PREFIX_RM_ADV,
11333 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11334 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11335 }
11336
772270f3
QY
11337 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11338 p->host, afi, safi);
d62a17ae 11339 orf_pfx_count = prefix_bgp_show_prefix_list(
11340 NULL, afi, orf_pfx_name, use_json);
11341
11342 if (CHECK_FLAG(p->af_sflags[afi][safi],
11343 PEER_STATUS_ORF_PREFIX_SEND)
11344 || orf_pfx_count) {
11345 vty_out(vty, " Outbound Route Filter (ORF):");
11346 if (CHECK_FLAG(p->af_sflags[afi][safi],
11347 PEER_STATUS_ORF_PREFIX_SEND))
11348 vty_out(vty, " sent;");
11349 if (orf_pfx_count)
11350 vty_out(vty, " received (%d entries)",
11351 orf_pfx_count);
11352 vty_out(vty, "\n");
11353 }
11354 if (CHECK_FLAG(p->af_sflags[afi][safi],
11355 PEER_STATUS_ORF_WAIT_REFRESH))
11356 vty_out(vty,
11357 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
11358
11359 if (CHECK_FLAG(p->af_flags[afi][safi],
11360 PEER_FLAG_REFLECTOR_CLIENT))
11361 vty_out(vty, " Route-Reflector Client\n");
11362 if (CHECK_FLAG(p->af_flags[afi][safi],
11363 PEER_FLAG_RSERVER_CLIENT))
11364 vty_out(vty, " Route-Server Client\n");
11365 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11366 vty_out(vty,
11367 " Inbound soft reconfiguration allowed\n");
11368
11369 if (CHECK_FLAG(p->af_flags[afi][safi],
11370 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11371 vty_out(vty,
11372 " Private AS numbers (all) replaced in updates to this neighbor\n");
11373 else if (CHECK_FLAG(p->af_flags[afi][safi],
11374 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11375 vty_out(vty,
11376 " Private AS numbers replaced in updates to this neighbor\n");
11377 else if (CHECK_FLAG(p->af_flags[afi][safi],
11378 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11379 vty_out(vty,
11380 " Private AS numbers (all) removed in updates to this neighbor\n");
11381 else if (CHECK_FLAG(p->af_flags[afi][safi],
11382 PEER_FLAG_REMOVE_PRIVATE_AS))
11383 vty_out(vty,
11384 " Private AS numbers removed in updates to this neighbor\n");
11385
dcc68b5e
MS
11386 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11387 vty_out(vty, " %s\n",
11388 bgp_addpath_names(p->addpath_type[afi][safi])
11389 ->human_description);
d62a17ae 11390
11391 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11392 vty_out(vty,
11393 " Override ASNs in outbound updates if aspath equals remote-as\n");
11394
11395 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11396 || CHECK_FLAG(p->af_flags[afi][safi],
11397 PEER_FLAG_FORCE_NEXTHOP_SELF))
11398 vty_out(vty, " NEXT_HOP is always this router\n");
11399 if (CHECK_FLAG(p->af_flags[afi][safi],
11400 PEER_FLAG_AS_PATH_UNCHANGED))
11401 vty_out(vty,
11402 " AS_PATH is propagated unchanged to this neighbor\n");
11403 if (CHECK_FLAG(p->af_flags[afi][safi],
11404 PEER_FLAG_NEXTHOP_UNCHANGED))
11405 vty_out(vty,
11406 " NEXT_HOP is propagated unchanged to this neighbor\n");
11407 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11408 vty_out(vty,
11409 " MED is propagated unchanged to this neighbor\n");
11410 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11411 || CHECK_FLAG(p->af_flags[afi][safi],
11412 PEER_FLAG_SEND_EXT_COMMUNITY)
11413 || CHECK_FLAG(p->af_flags[afi][safi],
11414 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
11415 vty_out(vty,
11416 " Community attribute sent to this neighbor");
11417 if (CHECK_FLAG(p->af_flags[afi][safi],
11418 PEER_FLAG_SEND_COMMUNITY)
11419 && CHECK_FLAG(p->af_flags[afi][safi],
11420 PEER_FLAG_SEND_EXT_COMMUNITY)
11421 && CHECK_FLAG(p->af_flags[afi][safi],
11422 PEER_FLAG_SEND_LARGE_COMMUNITY))
11423 vty_out(vty, "(all)\n");
11424 else if (CHECK_FLAG(p->af_flags[afi][safi],
11425 PEER_FLAG_SEND_LARGE_COMMUNITY))
11426 vty_out(vty, "(large)\n");
11427 else if (CHECK_FLAG(p->af_flags[afi][safi],
11428 PEER_FLAG_SEND_EXT_COMMUNITY))
11429 vty_out(vty, "(extended)\n");
11430 else
11431 vty_out(vty, "(standard)\n");
11432 }
11433 if (CHECK_FLAG(p->af_flags[afi][safi],
11434 PEER_FLAG_DEFAULT_ORIGINATE)) {
11435 vty_out(vty, " Default information originate,");
11436
11437 if (p->default_rmap[afi][safi].name)
11438 vty_out(vty, " default route-map %s%s,",
11439 p->default_rmap[afi][safi].map ? "*"
11440 : "",
11441 p->default_rmap[afi][safi].name);
11442 if (paf && PAF_SUBGRP(paf)
11443 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11444 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11445 vty_out(vty, " default sent\n");
11446 else
11447 vty_out(vty, " default not sent\n");
11448 }
11449
dff8f48d
MK
11450 /* advertise-vni-all */
11451 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11452 if (is_evpn_enabled())
dff8f48d
MK
11453 vty_out(vty, " advertise-all-vni\n");
11454 }
11455
d62a17ae 11456 if (filter->plist[FILTER_IN].name
11457 || filter->dlist[FILTER_IN].name
11458 || filter->aslist[FILTER_IN].name
11459 || filter->map[RMAP_IN].name)
11460 vty_out(vty, " Inbound path policy configured\n");
11461 if (filter->plist[FILTER_OUT].name
11462 || filter->dlist[FILTER_OUT].name
11463 || filter->aslist[FILTER_OUT].name
11464 || filter->map[RMAP_OUT].name || filter->usmap.name)
11465 vty_out(vty, " Outbound path policy configured\n");
11466
11467 /* prefix-list */
11468 if (filter->plist[FILTER_IN].name)
11469 vty_out(vty,
11470 " Incoming update prefix filter list is %s%s\n",
11471 filter->plist[FILTER_IN].plist ? "*" : "",
11472 filter->plist[FILTER_IN].name);
11473 if (filter->plist[FILTER_OUT].name)
11474 vty_out(vty,
11475 " Outgoing update prefix filter list is %s%s\n",
11476 filter->plist[FILTER_OUT].plist ? "*" : "",
11477 filter->plist[FILTER_OUT].name);
11478
11479 /* distribute-list */
11480 if (filter->dlist[FILTER_IN].name)
11481 vty_out(vty,
11482 " Incoming update network filter list is %s%s\n",
11483 filter->dlist[FILTER_IN].alist ? "*" : "",
11484 filter->dlist[FILTER_IN].name);
11485 if (filter->dlist[FILTER_OUT].name)
11486 vty_out(vty,
11487 " Outgoing update network filter list is %s%s\n",
11488 filter->dlist[FILTER_OUT].alist ? "*" : "",
11489 filter->dlist[FILTER_OUT].name);
11490
11491 /* filter-list. */
11492 if (filter->aslist[FILTER_IN].name)
11493 vty_out(vty,
11494 " Incoming update AS path filter list is %s%s\n",
11495 filter->aslist[FILTER_IN].aslist ? "*" : "",
11496 filter->aslist[FILTER_IN].name);
11497 if (filter->aslist[FILTER_OUT].name)
11498 vty_out(vty,
11499 " Outgoing update AS path filter list is %s%s\n",
11500 filter->aslist[FILTER_OUT].aslist ? "*" : "",
11501 filter->aslist[FILTER_OUT].name);
11502
11503 /* route-map. */
11504 if (filter->map[RMAP_IN].name)
11505 vty_out(vty,
11506 " Route map for incoming advertisements is %s%s\n",
11507 filter->map[RMAP_IN].map ? "*" : "",
11508 filter->map[RMAP_IN].name);
11509 if (filter->map[RMAP_OUT].name)
11510 vty_out(vty,
11511 " Route map for outgoing advertisements is %s%s\n",
11512 filter->map[RMAP_OUT].map ? "*" : "",
11513 filter->map[RMAP_OUT].name);
11514
9dac9fc8 11515 /* ebgp-requires-policy (inbound) */
1d3fdccf 11516 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11517 && !bgp_inbound_policy_exists(p, filter))
11518 vty_out(vty,
11519 " Inbound updates discarded due to missing policy\n");
11520
11521 /* ebgp-requires-policy (outbound) */
1d3fdccf 11522 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11523 && !bgp_outbound_policy_exists(p, filter))
11524 vty_out(vty,
11525 " Outbound updates discarded due to missing policy\n");
11526
d62a17ae 11527 /* unsuppress-map */
11528 if (filter->usmap.name)
11529 vty_out(vty,
11530 " Route map for selective unsuppress is %s%s\n",
11531 filter->usmap.map ? "*" : "",
11532 filter->usmap.name);
11533
7f7940e6
MK
11534 /* advertise-map */
11535 if (filter->advmap.aname && filter->advmap.cname)
11536 vty_out(vty,
11537 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
11538 filter->advmap.condition ? "EXIST"
11539 : "NON_EXIST",
11540 filter->advmap.cmap ? "*" : "",
11541 filter->advmap.cname,
11542 filter->advmap.amap ? "*" : "",
11543 filter->advmap.aname,
fa36596c 11544 filter->advmap.update_type == ADVERTISE
c385f82a
MK
11545 ? "Advertise"
11546 : "Withdraw");
7f7940e6 11547
d62a17ae 11548 /* Receive prefix count */
6cde4b45 11549 vty_out(vty, " %u accepted prefixes\n",
a0a87037 11550 p->pcount[afi][safi]);
d62a17ae 11551
fde246e8
DA
11552 /* maximum-prefix-out */
11553 if (CHECK_FLAG(p->af_flags[afi][safi],
11554 PEER_FLAG_MAX_PREFIX_OUT))
11555 vty_out(vty,
6cde4b45 11556 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
11557 p->pmax_out[afi][safi]);
11558
d62a17ae 11559 /* Maximum prefix */
11560 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 11561 vty_out(vty,
6cde4b45 11562 " Maximum prefixes allowed %u%s\n",
d62a17ae 11563 p->pmax[afi][safi],
11564 CHECK_FLAG(p->af_flags[afi][safi],
11565 PEER_FLAG_MAX_PREFIX_WARNING)
11566 ? " (warning-only)"
11567 : "");
11568 vty_out(vty, " Threshold for warning message %d%%",
11569 p->pmax_threshold[afi][safi]);
11570 if (p->pmax_restart[afi][safi])
11571 vty_out(vty, ", restart interval %d min",
11572 p->pmax_restart[afi][safi]);
11573 vty_out(vty, "\n");
11574 }
11575
11576 vty_out(vty, "\n");
11577 }
11578}
11579
9f049418 11580static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 11581 json_object *json)
718e3744 11582{
d62a17ae 11583 struct bgp *bgp;
11584 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
11585 char timebuf[BGP_UPTIME_LEN];
11586 char dn_flag[2];
d62a17ae 11587 afi_t afi;
11588 safi_t safi;
d7c0a89a
QY
11589 uint16_t i;
11590 uint8_t *msg;
d62a17ae 11591 json_object *json_neigh = NULL;
11592 time_t epoch_tbuf;
718e3744 11593
d62a17ae 11594 bgp = p->bgp;
11595
11596 if (use_json)
11597 json_neigh = json_object_new_object();
11598
11599 memset(dn_flag, '\0', sizeof(dn_flag));
11600 if (!p->conf_if && peer_dynamic_neighbor(p))
11601 dn_flag[0] = '*';
11602
11603 if (!use_json) {
11604 if (p->conf_if) /* Configured interface name. */
11605 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
11606 BGP_PEER_SU_UNSPEC(p)
11607 ? "None"
11608 : sockunion2str(&p->su, buf,
11609 SU_ADDRSTRLEN));
11610 else /* Configured IP address. */
11611 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
11612 p->host);
11613 }
11614
11615 if (use_json) {
11616 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
11617 json_object_string_add(json_neigh, "bgpNeighborAddr",
11618 "none");
11619 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
11620 json_object_string_add(
11621 json_neigh, "bgpNeighborAddr",
11622 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
11623
11624 json_object_int_add(json_neigh, "remoteAs", p->as);
11625
11626 if (p->change_local_as)
11627 json_object_int_add(json_neigh, "localAs",
11628 p->change_local_as);
11629 else
11630 json_object_int_add(json_neigh, "localAs", p->local_as);
11631
11632 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
11633 json_object_boolean_true_add(json_neigh,
11634 "localAsNoPrepend");
11635
11636 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
11637 json_object_boolean_true_add(json_neigh,
11638 "localAsReplaceAs");
11639 } else {
11640 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
11641 || (p->as_type == AS_INTERNAL))
11642 vty_out(vty, "remote AS %u, ", p->as);
11643 else
11644 vty_out(vty, "remote AS Unspecified, ");
11645 vty_out(vty, "local AS %u%s%s, ",
11646 p->change_local_as ? p->change_local_as : p->local_as,
11647 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
11648 ? " no-prepend"
11649 : "",
11650 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
11651 ? " replace-as"
11652 : "");
11653 }
faa16034
DS
11654 /* peer type internal or confed-internal */
11655 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 11656 if (use_json) {
11657 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11658 json_object_boolean_true_add(
11659 json_neigh, "nbrConfedInternalLink");
11660 else
11661 json_object_boolean_true_add(json_neigh,
11662 "nbrInternalLink");
11663 } else {
11664 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11665 vty_out(vty, "confed-internal link\n");
11666 else
11667 vty_out(vty, "internal link\n");
11668 }
faa16034
DS
11669 /* peer type external or confed-external */
11670 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 11671 if (use_json) {
11672 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11673 json_object_boolean_true_add(
11674 json_neigh, "nbrConfedExternalLink");
11675 else
11676 json_object_boolean_true_add(json_neigh,
11677 "nbrExternalLink");
11678 } else {
11679 if (bgp_confederation_peers_check(bgp, p->as))
11680 vty_out(vty, "confed-external link\n");
11681 else
11682 vty_out(vty, "external link\n");
11683 }
faa16034
DS
11684 } else {
11685 if (use_json)
11686 json_object_boolean_true_add(json_neigh,
11687 "nbrUnspecifiedLink");
11688 else
11689 vty_out(vty, "unspecified link\n");
d62a17ae 11690 }
11691
11692 /* Description. */
11693 if (p->desc) {
11694 if (use_json)
11695 json_object_string_add(json_neigh, "nbrDesc", p->desc);
11696 else
11697 vty_out(vty, " Description: %s\n", p->desc);
11698 }
11699
11700 if (p->hostname) {
11701 if (use_json) {
11702 if (p->hostname)
11703 json_object_string_add(json_neigh, "hostname",
11704 p->hostname);
11705
11706 if (p->domainname)
11707 json_object_string_add(json_neigh, "domainname",
11708 p->domainname);
11709 } else {
11710 if (p->domainname && (p->domainname[0] != '\0'))
11711 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
11712 p->domainname);
11713 else
11714 vty_out(vty, "Hostname: %s\n", p->hostname);
11715 }
11716 }
11717
11718 /* Peer-group */
11719 if (p->group) {
11720 if (use_json) {
11721 json_object_string_add(json_neigh, "peerGroup",
11722 p->group->name);
11723
11724 if (dn_flag[0]) {
11725 struct prefix prefix, *range = NULL;
11726
11727 sockunion2hostprefix(&(p->su), &prefix);
11728 range = peer_group_lookup_dynamic_neighbor_range(
11729 p->group, &prefix);
11730
11731 if (range) {
11732 prefix2str(range, buf1, sizeof(buf1));
11733 json_object_string_add(
11734 json_neigh,
11735 "peerSubnetRangeGroup", buf1);
11736 }
11737 }
11738 } else {
11739 vty_out(vty,
11740 " Member of peer-group %s for session parameters\n",
11741 p->group->name);
11742
11743 if (dn_flag[0]) {
11744 struct prefix prefix, *range = NULL;
11745
11746 sockunion2hostprefix(&(p->su), &prefix);
11747 range = peer_group_lookup_dynamic_neighbor_range(
11748 p->group, &prefix);
11749
11750 if (range) {
d62a17ae 11751 vty_out(vty,
1b78780b
DL
11752 " Belongs to the subnet range group: %pFX\n",
11753 range);
d62a17ae 11754 }
11755 }
11756 }
11757 }
11758
11759 if (use_json) {
11760 /* Administrative shutdown. */
cb9196e7
DS
11761 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11762 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 11763 json_object_boolean_true_add(json_neigh,
11764 "adminShutDown");
11765
11766 /* BGP Version. */
11767 json_object_int_add(json_neigh, "bgpVersion", 4);
11768 json_object_string_add(
11769 json_neigh, "remoteRouterId",
11770 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
11771 json_object_string_add(
11772 json_neigh, "localRouterId",
11773 inet_ntop(AF_INET, &bgp->router_id, buf1,
11774 sizeof(buf1)));
d62a17ae 11775
11776 /* Confederation */
11777 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11778 && bgp_confederation_peers_check(bgp, p->as))
11779 json_object_boolean_true_add(json_neigh,
11780 "nbrCommonAdmin");
11781
11782 /* Status. */
11783 json_object_string_add(
11784 json_neigh, "bgpState",
11785 lookup_msg(bgp_status_msg, p->status, NULL));
11786
11787 if (p->status == Established) {
11788 time_t uptime;
d62a17ae 11789
11790 uptime = bgp_clock();
11791 uptime -= p->uptime;
d62a17ae 11792 epoch_tbuf = time(NULL) - uptime;
11793
d3c7efed
DS
11794 json_object_int_add(json_neigh, "bgpTimerUpMsec",
11795 uptime * 1000);
d62a17ae 11796 json_object_string_add(json_neigh, "bgpTimerUpString",
11797 peer_uptime(p->uptime, timebuf,
11798 BGP_UPTIME_LEN, 0,
11799 NULL));
11800 json_object_int_add(json_neigh,
11801 "bgpTimerUpEstablishedEpoch",
11802 epoch_tbuf);
11803 }
11804
11805 else if (p->status == Active) {
11806 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11807 json_object_string_add(json_neigh, "bgpStateIs",
11808 "passive");
11809 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11810 json_object_string_add(json_neigh, "bgpStateIs",
11811 "passiveNSF");
11812 }
11813
11814 /* read timer */
11815 time_t uptime;
a2700b50 11816 struct tm tm;
d62a17ae 11817
11818 uptime = bgp_clock();
11819 uptime -= p->readtime;
a2700b50
MS
11820 gmtime_r(&uptime, &tm);
11821
d62a17ae 11822 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
11823 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11824 + (tm.tm_hour * 3600000));
d62a17ae 11825
11826 uptime = bgp_clock();
11827 uptime -= p->last_write;
a2700b50
MS
11828 gmtime_r(&uptime, &tm);
11829
d62a17ae 11830 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
11831 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11832 + (tm.tm_hour * 3600000));
d62a17ae 11833
11834 uptime = bgp_clock();
11835 uptime -= p->update_time;
a2700b50
MS
11836 gmtime_r(&uptime, &tm);
11837
d62a17ae 11838 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
11839 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11840 + (tm.tm_hour * 3600000));
d62a17ae 11841
11842 /* Configured timer values. */
11843 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
11844 p->v_holdtime * 1000);
11845 json_object_int_add(json_neigh,
11846 "bgpTimerKeepAliveIntervalMsecs",
11847 p->v_keepalive * 1000);
b90a8e13 11848 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11849 json_object_int_add(json_neigh,
11850 "bgpTimerConfiguredHoldTimeMsecs",
11851 p->holdtime * 1000);
11852 json_object_int_add(
11853 json_neigh,
11854 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11855 p->keepalive * 1000);
5d5393b9
DL
11856 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11857 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11858 json_object_int_add(json_neigh,
11859 "bgpTimerConfiguredHoldTimeMsecs",
11860 bgp->default_holdtime);
11861 json_object_int_add(
11862 json_neigh,
11863 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11864 bgp->default_keepalive);
d62a17ae 11865 }
11866 } else {
11867 /* Administrative shutdown. */
cb9196e7
DS
11868 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11869 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 11870 vty_out(vty, " Administratively shut down\n");
11871
11872 /* BGP Version. */
11873 vty_out(vty, " BGP version 4");
0e38aeb4 11874 vty_out(vty, ", remote router ID %s",
d62a17ae 11875 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
11876 vty_out(vty, ", local router ID %s\n",
11877 inet_ntop(AF_INET, &bgp->router_id, buf1,
11878 sizeof(buf1)));
d62a17ae 11879
11880 /* Confederation */
11881 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11882 && bgp_confederation_peers_check(bgp, p->as))
11883 vty_out(vty,
11884 " Neighbor under common administration\n");
11885
11886 /* Status. */
11887 vty_out(vty, " BGP state = %s",
11888 lookup_msg(bgp_status_msg, p->status, NULL));
11889
11890 if (p->status == Established)
11891 vty_out(vty, ", up for %8s",
11892 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
11893 0, NULL));
11894
11895 else if (p->status == Active) {
11896 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11897 vty_out(vty, " (passive)");
11898 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11899 vty_out(vty, " (NSF passive)");
11900 }
11901 vty_out(vty, "\n");
11902
11903 /* read timer */
11904 vty_out(vty, " Last read %s",
11905 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
11906 NULL));
11907 vty_out(vty, ", Last write %s\n",
11908 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
11909 NULL));
11910
11911 /* Configured timer values. */
11912 vty_out(vty,
11913 " Hold time is %d, keepalive interval is %d seconds\n",
11914 p->v_holdtime, p->v_keepalive);
b90a8e13 11915 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11916 vty_out(vty, " Configured hold time is %d",
11917 p->holdtime);
11918 vty_out(vty, ", keepalive interval is %d seconds\n",
11919 p->keepalive);
5d5393b9
DL
11920 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11921 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11922 vty_out(vty, " Configured hold time is %d",
11923 bgp->default_holdtime);
11924 vty_out(vty, ", keepalive interval is %d seconds\n",
11925 bgp->default_keepalive);
d62a17ae 11926 }
11927 }
11928 /* Capability. */
11929 if (p->status == Established) {
11930 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
11931 || p->afc_recv[AFI_IP][SAFI_UNICAST]
11932 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
11933 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
11934 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
11935 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
11936 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
11937 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
11938 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
11939 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
11940 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
11941 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 11942 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
11943 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 11944 || p->afc_adv[AFI_IP][SAFI_ENCAP]
11945 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 11946 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
11947 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 11948 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
11949 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
11950 if (use_json) {
11951 json_object *json_cap = NULL;
11952
11953 json_cap = json_object_new_object();
11954
11955 /* AS4 */
11956 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11957 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11958 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
11959 && CHECK_FLAG(p->cap,
11960 PEER_CAP_AS4_RCV))
11961 json_object_string_add(
11962 json_cap, "4byteAs",
11963 "advertisedAndReceived");
11964 else if (CHECK_FLAG(p->cap,
11965 PEER_CAP_AS4_ADV))
11966 json_object_string_add(
11967 json_cap, "4byteAs",
11968 "advertised");
11969 else if (CHECK_FLAG(p->cap,
11970 PEER_CAP_AS4_RCV))
11971 json_object_string_add(
11972 json_cap, "4byteAs",
11973 "received");
11974 }
11975
11976 /* AddPath */
11977 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11978 || CHECK_FLAG(p->cap,
11979 PEER_CAP_ADDPATH_ADV)) {
11980 json_object *json_add = NULL;
11981 const char *print_store;
11982
11983 json_add = json_object_new_object();
11984
05c7a1cc
QY
11985 FOREACH_AFI_SAFI (afi, safi) {
11986 json_object *json_sub = NULL;
11987 json_sub =
11988 json_object_new_object();
5cb5f4d0
DD
11989 print_store = get_afi_safi_str(
11990 afi, safi, true);
d62a17ae 11991
05c7a1cc
QY
11992 if (CHECK_FLAG(
11993 p->af_cap[afi]
11994 [safi],
11995 PEER_CAP_ADDPATH_AF_TX_ADV)
11996 || CHECK_FLAG(
11997 p->af_cap[afi]
11998 [safi],
11999 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 12000 if (CHECK_FLAG(
12001 p->af_cap
12002 [afi]
12003 [safi],
12004 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 12005 && CHECK_FLAG(
d62a17ae 12006 p->af_cap
12007 [afi]
12008 [safi],
05c7a1cc
QY
12009 PEER_CAP_ADDPATH_AF_TX_RCV))
12010 json_object_boolean_true_add(
12011 json_sub,
12012 "txAdvertisedAndReceived");
12013 else if (
12014 CHECK_FLAG(
12015 p->af_cap
12016 [afi]
12017 [safi],
12018 PEER_CAP_ADDPATH_AF_TX_ADV))
12019 json_object_boolean_true_add(
12020 json_sub,
12021 "txAdvertised");
12022 else if (
12023 CHECK_FLAG(
12024 p->af_cap
12025 [afi]
12026 [safi],
12027 PEER_CAP_ADDPATH_AF_TX_RCV))
12028 json_object_boolean_true_add(
12029 json_sub,
12030 "txReceived");
12031 }
d62a17ae 12032
05c7a1cc
QY
12033 if (CHECK_FLAG(
12034 p->af_cap[afi]
12035 [safi],
12036 PEER_CAP_ADDPATH_AF_RX_ADV)
12037 || CHECK_FLAG(
12038 p->af_cap[afi]
12039 [safi],
12040 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 12041 if (CHECK_FLAG(
12042 p->af_cap
12043 [afi]
12044 [safi],
12045 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 12046 && CHECK_FLAG(
d62a17ae 12047 p->af_cap
12048 [afi]
12049 [safi],
12050 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
12051 json_object_boolean_true_add(
12052 json_sub,
12053 "rxAdvertisedAndReceived");
12054 else if (
12055 CHECK_FLAG(
12056 p->af_cap
12057 [afi]
12058 [safi],
12059 PEER_CAP_ADDPATH_AF_RX_ADV))
12060 json_object_boolean_true_add(
12061 json_sub,
12062 "rxAdvertised");
12063 else if (
12064 CHECK_FLAG(
12065 p->af_cap
12066 [afi]
12067 [safi],
12068 PEER_CAP_ADDPATH_AF_RX_RCV))
12069 json_object_boolean_true_add(
12070 json_sub,
12071 "rxReceived");
d62a17ae 12072 }
12073
05c7a1cc
QY
12074 if (CHECK_FLAG(
12075 p->af_cap[afi]
12076 [safi],
12077 PEER_CAP_ADDPATH_AF_TX_ADV)
12078 || CHECK_FLAG(
12079 p->af_cap[afi]
12080 [safi],
12081 PEER_CAP_ADDPATH_AF_TX_RCV)
12082 || CHECK_FLAG(
12083 p->af_cap[afi]
12084 [safi],
12085 PEER_CAP_ADDPATH_AF_RX_ADV)
12086 || CHECK_FLAG(
12087 p->af_cap[afi]
12088 [safi],
12089 PEER_CAP_ADDPATH_AF_RX_RCV))
12090 json_object_object_add(
12091 json_add,
12092 print_store,
12093 json_sub);
12094 else
12095 json_object_free(
12096 json_sub);
12097 }
12098
d62a17ae 12099 json_object_object_add(
12100 json_cap, "addPath", json_add);
12101 }
12102
12103 /* Dynamic */
12104 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12105 || CHECK_FLAG(p->cap,
12106 PEER_CAP_DYNAMIC_ADV)) {
12107 if (CHECK_FLAG(p->cap,
12108 PEER_CAP_DYNAMIC_ADV)
12109 && CHECK_FLAG(p->cap,
12110 PEER_CAP_DYNAMIC_RCV))
12111 json_object_string_add(
12112 json_cap, "dynamic",
12113 "advertisedAndReceived");
12114 else if (CHECK_FLAG(
12115 p->cap,
12116 PEER_CAP_DYNAMIC_ADV))
12117 json_object_string_add(
12118 json_cap, "dynamic",
12119 "advertised");
12120 else if (CHECK_FLAG(
12121 p->cap,
12122 PEER_CAP_DYNAMIC_RCV))
12123 json_object_string_add(
12124 json_cap, "dynamic",
12125 "received");
12126 }
12127
12128 /* Extended nexthop */
12129 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12130 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12131 json_object *json_nxt = NULL;
12132 const char *print_store;
12133
12134
12135 if (CHECK_FLAG(p->cap,
12136 PEER_CAP_ENHE_ADV)
12137 && CHECK_FLAG(p->cap,
12138 PEER_CAP_ENHE_RCV))
12139 json_object_string_add(
12140 json_cap,
12141 "extendedNexthop",
12142 "advertisedAndReceived");
12143 else if (CHECK_FLAG(p->cap,
12144 PEER_CAP_ENHE_ADV))
12145 json_object_string_add(
12146 json_cap,
12147 "extendedNexthop",
12148 "advertised");
12149 else if (CHECK_FLAG(p->cap,
12150 PEER_CAP_ENHE_RCV))
12151 json_object_string_add(
12152 json_cap,
12153 "extendedNexthop",
12154 "received");
12155
12156 if (CHECK_FLAG(p->cap,
12157 PEER_CAP_ENHE_RCV)) {
12158 json_nxt =
12159 json_object_new_object();
12160
12161 for (safi = SAFI_UNICAST;
12162 safi < SAFI_MAX; safi++) {
12163 if (CHECK_FLAG(
12164 p->af_cap
12165 [AFI_IP]
12166 [safi],
12167 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 12168 print_store = get_afi_safi_str(
d62a17ae 12169 AFI_IP,
5cb5f4d0 12170 safi, true);
d62a17ae 12171 json_object_string_add(
12172 json_nxt,
12173 print_store,
54f29523 12174 "recieved"); /* misspelled for compatibility */
d62a17ae 12175 }
12176 }
12177 json_object_object_add(
12178 json_cap,
12179 "extendedNexthopFamililesByPeer",
12180 json_nxt);
12181 }
12182 }
12183
12184 /* Route Refresh */
12185 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12186 || CHECK_FLAG(p->cap,
12187 PEER_CAP_REFRESH_NEW_RCV)
12188 || CHECK_FLAG(p->cap,
12189 PEER_CAP_REFRESH_OLD_RCV)) {
12190 if (CHECK_FLAG(p->cap,
12191 PEER_CAP_REFRESH_ADV)
12192 && (CHECK_FLAG(
12193 p->cap,
12194 PEER_CAP_REFRESH_NEW_RCV)
12195 || CHECK_FLAG(
12196 p->cap,
12197 PEER_CAP_REFRESH_OLD_RCV))) {
12198 if (CHECK_FLAG(
12199 p->cap,
12200 PEER_CAP_REFRESH_OLD_RCV)
12201 && CHECK_FLAG(
12202 p->cap,
12203 PEER_CAP_REFRESH_NEW_RCV))
12204 json_object_string_add(
12205 json_cap,
12206 "routeRefresh",
12207 "advertisedAndReceivedOldNew");
12208 else {
12209 if (CHECK_FLAG(
12210 p->cap,
12211 PEER_CAP_REFRESH_OLD_RCV))
12212 json_object_string_add(
12213 json_cap,
12214 "routeRefresh",
12215 "advertisedAndReceivedOld");
12216 else
12217 json_object_string_add(
12218 json_cap,
12219 "routeRefresh",
12220 "advertisedAndReceivedNew");
12221 }
12222 } else if (
12223 CHECK_FLAG(
12224 p->cap,
12225 PEER_CAP_REFRESH_ADV))
12226 json_object_string_add(
12227 json_cap,
12228 "routeRefresh",
12229 "advertised");
12230 else if (
12231 CHECK_FLAG(
12232 p->cap,
12233 PEER_CAP_REFRESH_NEW_RCV)
12234 || CHECK_FLAG(
12235 p->cap,
12236 PEER_CAP_REFRESH_OLD_RCV))
12237 json_object_string_add(
12238 json_cap,
12239 "routeRefresh",
12240 "received");
12241 }
12242
12243 /* Multiprotocol Extensions */
12244 json_object *json_multi = NULL;
12245 json_multi = json_object_new_object();
12246
05c7a1cc
QY
12247 FOREACH_AFI_SAFI (afi, safi) {
12248 if (p->afc_adv[afi][safi]
12249 || p->afc_recv[afi][safi]) {
12250 json_object *json_exten = NULL;
12251 json_exten =
12252 json_object_new_object();
12253
d62a17ae 12254 if (p->afc_adv[afi][safi]
05c7a1cc
QY
12255 && p->afc_recv[afi][safi])
12256 json_object_boolean_true_add(
12257 json_exten,
12258 "advertisedAndReceived");
12259 else if (p->afc_adv[afi][safi])
12260 json_object_boolean_true_add(
12261 json_exten,
12262 "advertised");
12263 else if (p->afc_recv[afi][safi])
12264 json_object_boolean_true_add(
12265 json_exten,
12266 "received");
d62a17ae 12267
05c7a1cc
QY
12268 json_object_object_add(
12269 json_multi,
5cb5f4d0
DD
12270 get_afi_safi_str(afi,
12271 safi,
12272 true),
05c7a1cc 12273 json_exten);
d62a17ae 12274 }
12275 }
12276 json_object_object_add(
12277 json_cap, "multiprotocolExtensions",
12278 json_multi);
12279
d77114b7 12280 /* Hostname capabilities */
60466a63 12281 json_object *json_hname = NULL;
d77114b7
MK
12282
12283 json_hname = json_object_new_object();
12284
12285 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12286 json_object_string_add(
60466a63
QY
12287 json_hname, "advHostName",
12288 bgp->peer_self->hostname
12289 ? bgp->peer_self
12290 ->hostname
d77114b7
MK
12291 : "n/a");
12292 json_object_string_add(
60466a63
QY
12293 json_hname, "advDomainName",
12294 bgp->peer_self->domainname
12295 ? bgp->peer_self
12296 ->domainname
d77114b7
MK
12297 : "n/a");
12298 }
12299
12300
12301 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12302 json_object_string_add(
60466a63
QY
12303 json_hname, "rcvHostName",
12304 p->hostname ? p->hostname
12305 : "n/a");
d77114b7 12306 json_object_string_add(
60466a63
QY
12307 json_hname, "rcvDomainName",
12308 p->domainname ? p->domainname
12309 : "n/a");
d77114b7
MK
12310 }
12311
60466a63 12312 json_object_object_add(json_cap, "hostName",
d77114b7
MK
12313 json_hname);
12314
d62a17ae 12315 /* Gracefull Restart */
12316 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12317 || CHECK_FLAG(p->cap,
12318 PEER_CAP_RESTART_ADV)) {
12319 if (CHECK_FLAG(p->cap,
12320 PEER_CAP_RESTART_ADV)
12321 && CHECK_FLAG(p->cap,
12322 PEER_CAP_RESTART_RCV))
12323 json_object_string_add(
12324 json_cap,
12325 "gracefulRestart",
12326 "advertisedAndReceived");
12327 else if (CHECK_FLAG(
12328 p->cap,
12329 PEER_CAP_RESTART_ADV))
12330 json_object_string_add(
12331 json_cap,
12332 "gracefulRestartCapability",
12333 "advertised");
12334 else if (CHECK_FLAG(
12335 p->cap,
12336 PEER_CAP_RESTART_RCV))
12337 json_object_string_add(
12338 json_cap,
12339 "gracefulRestartCapability",
12340 "received");
12341
12342 if (CHECK_FLAG(p->cap,
12343 PEER_CAP_RESTART_RCV)) {
12344 int restart_af_count = 0;
12345 json_object *json_restart =
12346 NULL;
12347 json_restart =
12348 json_object_new_object();
12349
12350 json_object_int_add(
12351 json_cap,
12352 "gracefulRestartRemoteTimerMsecs",
12353 p->v_gr_restart * 1000);
12354
05c7a1cc
QY
12355 FOREACH_AFI_SAFI (afi, safi) {
12356 if (CHECK_FLAG(
12357 p->af_cap
12358 [afi]
12359 [safi],
12360 PEER_CAP_RESTART_AF_RCV)) {
12361 json_object *
12362 json_sub =
12363 NULL;
12364 json_sub =
12365 json_object_new_object();
12366
d62a17ae 12367 if (CHECK_FLAG(
12368 p->af_cap
12369 [afi]
12370 [safi],
05c7a1cc
QY
12371 PEER_CAP_RESTART_AF_PRESERVE_RCV))
12372 json_object_boolean_true_add(
12373 json_sub,
12374 "preserved");
12375 restart_af_count++;
12376 json_object_object_add(
12377 json_restart,
5cb5f4d0 12378 get_afi_safi_str(
05c7a1cc 12379 afi,
5cb5f4d0
DD
12380 safi,
12381 true),
05c7a1cc 12382 json_sub);
d62a17ae 12383 }
12384 }
12385 if (!restart_af_count) {
12386 json_object_string_add(
12387 json_cap,
12388 "addressFamiliesByPeer",
12389 "none");
12390 json_object_free(
12391 json_restart);
12392 } else
12393 json_object_object_add(
12394 json_cap,
12395 "addressFamiliesByPeer",
12396 json_restart);
12397 }
12398 }
12399 json_object_object_add(json_neigh,
12400 "neighborCapabilities",
12401 json_cap);
12402 } else {
12403 vty_out(vty, " Neighbor capabilities:\n");
12404
12405 /* AS4 */
12406 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12407 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12408 vty_out(vty, " 4 Byte AS:");
12409 if (CHECK_FLAG(p->cap,
12410 PEER_CAP_AS4_ADV))
12411 vty_out(vty, " advertised");
12412 if (CHECK_FLAG(p->cap,
12413 PEER_CAP_AS4_RCV))
12414 vty_out(vty, " %sreceived",
12415 CHECK_FLAG(
12416 p->cap,
12417 PEER_CAP_AS4_ADV)
12418 ? "and "
12419 : "");
12420 vty_out(vty, "\n");
12421 }
12422
12423 /* AddPath */
12424 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12425 || CHECK_FLAG(p->cap,
12426 PEER_CAP_ADDPATH_ADV)) {
12427 vty_out(vty, " AddPath:\n");
12428
05c7a1cc
QY
12429 FOREACH_AFI_SAFI (afi, safi) {
12430 if (CHECK_FLAG(
12431 p->af_cap[afi]
12432 [safi],
12433 PEER_CAP_ADDPATH_AF_TX_ADV)
12434 || CHECK_FLAG(
12435 p->af_cap[afi]
12436 [safi],
12437 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12438 vty_out(vty,
12439 " %s: TX ",
5cb5f4d0 12440 get_afi_safi_str(
05c7a1cc 12441 afi,
5cb5f4d0
DD
12442 safi,
12443 false));
05c7a1cc 12444
d62a17ae 12445 if (CHECK_FLAG(
12446 p->af_cap
12447 [afi]
12448 [safi],
05c7a1cc 12449 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 12450 vty_out(vty,
05c7a1cc 12451 "advertised %s",
5cb5f4d0 12452 get_afi_safi_str(
d62a17ae 12453 afi,
5cb5f4d0
DD
12454 safi,
12455 false));
d62a17ae 12456
05c7a1cc
QY
12457 if (CHECK_FLAG(
12458 p->af_cap
12459 [afi]
12460 [safi],
12461 PEER_CAP_ADDPATH_AF_TX_RCV))
12462 vty_out(vty,
12463 "%sreceived",
12464 CHECK_FLAG(
12465 p->af_cap
12466 [afi]
12467 [safi],
12468 PEER_CAP_ADDPATH_AF_TX_ADV)
12469 ? " and "
12470 : "");
d62a17ae 12471
05c7a1cc
QY
12472 vty_out(vty, "\n");
12473 }
d62a17ae 12474
05c7a1cc
QY
12475 if (CHECK_FLAG(
12476 p->af_cap[afi]
12477 [safi],
12478 PEER_CAP_ADDPATH_AF_RX_ADV)
12479 || CHECK_FLAG(
12480 p->af_cap[afi]
12481 [safi],
12482 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12483 vty_out(vty,
12484 " %s: RX ",
5cb5f4d0 12485 get_afi_safi_str(
05c7a1cc 12486 afi,
5cb5f4d0
DD
12487 safi,
12488 false));
d62a17ae 12489
12490 if (CHECK_FLAG(
12491 p->af_cap
12492 [afi]
12493 [safi],
05c7a1cc 12494 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 12495 vty_out(vty,
05c7a1cc 12496 "advertised %s",
5cb5f4d0 12497 get_afi_safi_str(
d62a17ae 12498 afi,
5cb5f4d0
DD
12499 safi,
12500 false));
d62a17ae 12501
05c7a1cc
QY
12502 if (CHECK_FLAG(
12503 p->af_cap
12504 [afi]
12505 [safi],
12506 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 12507 vty_out(vty,
05c7a1cc
QY
12508 "%sreceived",
12509 CHECK_FLAG(
12510 p->af_cap
12511 [afi]
12512 [safi],
12513 PEER_CAP_ADDPATH_AF_RX_ADV)
12514 ? " and "
12515 : "");
12516
12517 vty_out(vty, "\n");
d62a17ae 12518 }
05c7a1cc 12519 }
d62a17ae 12520 }
12521
12522 /* Dynamic */
12523 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12524 || CHECK_FLAG(p->cap,
12525 PEER_CAP_DYNAMIC_ADV)) {
12526 vty_out(vty, " Dynamic:");
12527 if (CHECK_FLAG(p->cap,
12528 PEER_CAP_DYNAMIC_ADV))
12529 vty_out(vty, " advertised");
12530 if (CHECK_FLAG(p->cap,
12531 PEER_CAP_DYNAMIC_RCV))
12532 vty_out(vty, " %sreceived",
12533 CHECK_FLAG(
12534 p->cap,
12535 PEER_CAP_DYNAMIC_ADV)
12536 ? "and "
12537 : "");
12538 vty_out(vty, "\n");
12539 }
12540
12541 /* Extended nexthop */
12542 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12543 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12544 vty_out(vty, " Extended nexthop:");
12545 if (CHECK_FLAG(p->cap,
12546 PEER_CAP_ENHE_ADV))
12547 vty_out(vty, " advertised");
12548 if (CHECK_FLAG(p->cap,
12549 PEER_CAP_ENHE_RCV))
12550 vty_out(vty, " %sreceived",
12551 CHECK_FLAG(
12552 p->cap,
12553 PEER_CAP_ENHE_ADV)
12554 ? "and "
12555 : "");
12556 vty_out(vty, "\n");
12557
12558 if (CHECK_FLAG(p->cap,
12559 PEER_CAP_ENHE_RCV)) {
12560 vty_out(vty,
12561 " Address families by peer:\n ");
12562 for (safi = SAFI_UNICAST;
12563 safi < SAFI_MAX; safi++)
12564 if (CHECK_FLAG(
12565 p->af_cap
12566 [AFI_IP]
12567 [safi],
12568 PEER_CAP_ENHE_AF_RCV))
12569 vty_out(vty,
12570 " %s\n",
5cb5f4d0 12571 get_afi_safi_str(
d62a17ae 12572 AFI_IP,
5cb5f4d0
DD
12573 safi,
12574 false));
d62a17ae 12575 }
12576 }
12577
12578 /* Route Refresh */
12579 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12580 || CHECK_FLAG(p->cap,
12581 PEER_CAP_REFRESH_NEW_RCV)
12582 || CHECK_FLAG(p->cap,
12583 PEER_CAP_REFRESH_OLD_RCV)) {
12584 vty_out(vty, " Route refresh:");
12585 if (CHECK_FLAG(p->cap,
12586 PEER_CAP_REFRESH_ADV))
12587 vty_out(vty, " advertised");
12588 if (CHECK_FLAG(p->cap,
12589 PEER_CAP_REFRESH_NEW_RCV)
12590 || CHECK_FLAG(
12591 p->cap,
12592 PEER_CAP_REFRESH_OLD_RCV))
12593 vty_out(vty, " %sreceived(%s)",
12594 CHECK_FLAG(
12595 p->cap,
12596 PEER_CAP_REFRESH_ADV)
12597 ? "and "
12598 : "",
12599 (CHECK_FLAG(
12600 p->cap,
12601 PEER_CAP_REFRESH_OLD_RCV)
12602 && CHECK_FLAG(
12603 p->cap,
12604 PEER_CAP_REFRESH_NEW_RCV))
12605 ? "old & new"
12606 : CHECK_FLAG(
12607 p->cap,
12608 PEER_CAP_REFRESH_OLD_RCV)
12609 ? "old"
12610 : "new");
12611
12612 vty_out(vty, "\n");
12613 }
12614
12615 /* Multiprotocol Extensions */
05c7a1cc
QY
12616 FOREACH_AFI_SAFI (afi, safi)
12617 if (p->afc_adv[afi][safi]
12618 || p->afc_recv[afi][safi]) {
12619 vty_out(vty,
12620 " Address Family %s:",
5cb5f4d0
DD
12621 get_afi_safi_str(
12622 afi,
12623 safi,
12624 false));
05c7a1cc 12625 if (p->afc_adv[afi][safi])
d62a17ae 12626 vty_out(vty,
05c7a1cc
QY
12627 " advertised");
12628 if (p->afc_recv[afi][safi])
12629 vty_out(vty,
12630 " %sreceived",
12631 p->afc_adv[afi]
12632 [safi]
12633 ? "and "
12634 : "");
12635 vty_out(vty, "\n");
12636 }
d62a17ae 12637
12638 /* Hostname capability */
60466a63 12639 vty_out(vty, " Hostname Capability:");
d77114b7
MK
12640
12641 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
12642 vty_out(vty,
12643 " advertised (name: %s,domain name: %s)",
60466a63
QY
12644 bgp->peer_self->hostname
12645 ? bgp->peer_self
12646 ->hostname
d77114b7 12647 : "n/a",
60466a63
QY
12648 bgp->peer_self->domainname
12649 ? bgp->peer_self
12650 ->domainname
d77114b7
MK
12651 : "n/a");
12652 } else {
12653 vty_out(vty, " not advertised");
d62a17ae 12654 }
12655
d77114b7 12656 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
12657 vty_out(vty,
12658 " received (name: %s,domain name: %s)",
60466a63
QY
12659 p->hostname ? p->hostname
12660 : "n/a",
12661 p->domainname ? p->domainname
12662 : "n/a");
d77114b7
MK
12663 } else {
12664 vty_out(vty, " not received");
12665 }
12666
12667 vty_out(vty, "\n");
12668
61bfbd51 12669 /* Graceful Restart */
d62a17ae 12670 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12671 || CHECK_FLAG(p->cap,
12672 PEER_CAP_RESTART_ADV)) {
12673 vty_out(vty,
61bfbd51 12674 " Graceful Restart Capability:");
d62a17ae 12675 if (CHECK_FLAG(p->cap,
12676 PEER_CAP_RESTART_ADV))
12677 vty_out(vty, " advertised");
12678 if (CHECK_FLAG(p->cap,
12679 PEER_CAP_RESTART_RCV))
12680 vty_out(vty, " %sreceived",
12681 CHECK_FLAG(
12682 p->cap,
12683 PEER_CAP_RESTART_ADV)
12684 ? "and "
12685 : "");
12686 vty_out(vty, "\n");
12687
12688 if (CHECK_FLAG(p->cap,
12689 PEER_CAP_RESTART_RCV)) {
12690 int restart_af_count = 0;
12691
12692 vty_out(vty,
12693 " Remote Restart timer is %d seconds\n",
12694 p->v_gr_restart);
12695 vty_out(vty,
12696 " Address families by peer:\n ");
12697
05c7a1cc
QY
12698 FOREACH_AFI_SAFI (afi, safi)
12699 if (CHECK_FLAG(
12700 p->af_cap
12701 [afi]
12702 [safi],
12703 PEER_CAP_RESTART_AF_RCV)) {
12704 vty_out(vty,
12705 "%s%s(%s)",
12706 restart_af_count
12707 ? ", "
12708 : "",
5cb5f4d0 12709 get_afi_safi_str(
05c7a1cc 12710 afi,
5cb5f4d0
DD
12711 safi,
12712 false),
05c7a1cc
QY
12713 CHECK_FLAG(
12714 p->af_cap
12715 [afi]
12716 [safi],
12717 PEER_CAP_RESTART_AF_PRESERVE_RCV)
12718 ? "preserved"
12719 : "not preserved");
12720 restart_af_count++;
12721 }
d62a17ae 12722 if (!restart_af_count)
12723 vty_out(vty, "none");
12724 vty_out(vty, "\n");
12725 }
2986cac2 12726 } /* Gracefull Restart */
d62a17ae 12727 }
12728 }
12729 }
12730
12731 /* graceful restart information */
d62a17ae 12732 json_object *json_grace = NULL;
12733 json_object *json_grace_send = NULL;
12734 json_object *json_grace_recv = NULL;
12735 int eor_send_af_count = 0;
12736 int eor_receive_af_count = 0;
12737
12738 if (use_json) {
12739 json_grace = json_object_new_object();
12740 json_grace_send = json_object_new_object();
12741 json_grace_recv = json_object_new_object();
12742
36235319
QY
12743 if ((p->status == Established)
12744 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
12745 FOREACH_AFI_SAFI (afi, safi) {
12746 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 12747 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
12748 json_object_boolean_true_add(
12749 json_grace_send,
5cb5f4d0
DD
12750 get_afi_safi_str(afi,
12751 safi,
12752 true));
05c7a1cc 12753 eor_send_af_count++;
d62a17ae 12754 }
12755 }
05c7a1cc
QY
12756 FOREACH_AFI_SAFI (afi, safi) {
12757 if (CHECK_FLAG(
36235319
QY
12758 p->af_sflags[afi][safi],
12759 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
12760 json_object_boolean_true_add(
12761 json_grace_recv,
5cb5f4d0
DD
12762 get_afi_safi_str(afi,
12763 safi,
12764 true));
05c7a1cc 12765 eor_receive_af_count++;
d62a17ae 12766 }
12767 }
12768 }
36235319
QY
12769 json_object_object_add(json_grace, "endOfRibSend",
12770 json_grace_send);
12771 json_object_object_add(json_grace, "endOfRibRecv",
12772 json_grace_recv);
d62a17ae 12773
d62a17ae 12774
12775 if (p->t_gr_restart)
12776 json_object_int_add(json_grace,
12777 "gracefulRestartTimerMsecs",
12778 thread_timer_remain_second(
12779 p->t_gr_restart)
12780 * 1000);
12781
12782 if (p->t_gr_stale)
12783 json_object_int_add(
12784 json_grace,
12785 "gracefulStalepathTimerMsecs",
12786 thread_timer_remain_second(
12787 p->t_gr_stale)
12788 * 1000);
2986cac2 12789 /* more gr info in new format */
12790 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 12791 json_grace);
d62a17ae 12792 json_object_object_add(
12793 json_neigh, "gracefulRestartInfo", json_grace);
12794 } else {
2089dd80 12795 vty_out(vty, " Graceful restart information:\n");
36235319
QY
12796 if ((p->status == Established)
12797 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12798
d62a17ae 12799 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
12800 FOREACH_AFI_SAFI (afi, safi) {
12801 if (CHECK_FLAG(p->af_sflags[afi][safi],
12802 PEER_STATUS_EOR_SEND)) {
12803 vty_out(vty, "%s%s",
12804 eor_send_af_count ? ", "
12805 : "",
36235319
QY
12806 get_afi_safi_str(
12807 afi, safi,
12808 false));
05c7a1cc 12809 eor_send_af_count++;
d62a17ae 12810 }
12811 }
12812 vty_out(vty, "\n");
12813 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
12814 FOREACH_AFI_SAFI (afi, safi) {
12815 if (CHECK_FLAG(
12816 p->af_sflags[afi][safi],
12817 PEER_STATUS_EOR_RECEIVED)) {
12818 vty_out(vty, "%s%s",
12819 eor_receive_af_count
12820 ? ", "
12821 : "",
5cb5f4d0
DD
12822 get_afi_safi_str(afi,
12823 safi,
12824 false));
05c7a1cc 12825 eor_receive_af_count++;
d62a17ae 12826 }
12827 }
12828 vty_out(vty, "\n");
12829 }
12830
12831 if (p->t_gr_restart)
12832 vty_out(vty,
12833 " The remaining time of restart timer is %ld\n",
12834 thread_timer_remain_second(
12835 p->t_gr_restart));
12836
12837 if (p->t_gr_stale)
12838 vty_out(vty,
12839 " The remaining time of stalepath timer is %ld\n",
12840 thread_timer_remain_second(
12841 p->t_gr_stale));
2986cac2 12842
12843 /* more gr info in new format */
12844 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 12845 }
2986cac2 12846
d62a17ae 12847 if (use_json) {
12848 json_object *json_stat = NULL;
12849 json_stat = json_object_new_object();
12850 /* Packet counts. */
43aa5965
QY
12851
12852 atomic_size_t outq_count, inq_count;
12853 outq_count = atomic_load_explicit(&p->obuf->count,
12854 memory_order_relaxed);
12855 inq_count = atomic_load_explicit(&p->ibuf->count,
12856 memory_order_relaxed);
12857
12858 json_object_int_add(json_stat, "depthInq",
12859 (unsigned long)inq_count);
d62a17ae 12860 json_object_int_add(json_stat, "depthOutq",
43aa5965 12861 (unsigned long)outq_count);
0112e9e0
QY
12862 json_object_int_add(json_stat, "opensSent",
12863 atomic_load_explicit(&p->open_out,
12864 memory_order_relaxed));
12865 json_object_int_add(json_stat, "opensRecv",
12866 atomic_load_explicit(&p->open_in,
12867 memory_order_relaxed));
d62a17ae 12868 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
12869 atomic_load_explicit(&p->notify_out,
12870 memory_order_relaxed));
d62a17ae 12871 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
12872 atomic_load_explicit(&p->notify_in,
12873 memory_order_relaxed));
12874 json_object_int_add(json_stat, "updatesSent",
12875 atomic_load_explicit(&p->update_out,
12876 memory_order_relaxed));
12877 json_object_int_add(json_stat, "updatesRecv",
12878 atomic_load_explicit(&p->update_in,
12879 memory_order_relaxed));
d62a17ae 12880 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
12881 atomic_load_explicit(&p->keepalive_out,
12882 memory_order_relaxed));
d62a17ae 12883 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
12884 atomic_load_explicit(&p->keepalive_in,
12885 memory_order_relaxed));
d62a17ae 12886 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
12887 atomic_load_explicit(&p->refresh_out,
12888 memory_order_relaxed));
d62a17ae 12889 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
12890 atomic_load_explicit(&p->refresh_in,
12891 memory_order_relaxed));
d62a17ae 12892 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
12893 atomic_load_explicit(&p->dynamic_cap_out,
12894 memory_order_relaxed));
d62a17ae 12895 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
12896 atomic_load_explicit(&p->dynamic_cap_in,
12897 memory_order_relaxed));
12898 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
12899 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 12900 json_object_object_add(json_neigh, "messageStats", json_stat);
12901 } else {
43aa5965
QY
12902 atomic_size_t outq_count, inq_count;
12903 outq_count = atomic_load_explicit(&p->obuf->count,
12904 memory_order_relaxed);
12905 inq_count = atomic_load_explicit(&p->ibuf->count,
12906 memory_order_relaxed);
12907
d62a17ae 12908 /* Packet counts. */
12909 vty_out(vty, " Message statistics:\n");
43aa5965
QY
12910 vty_out(vty, " Inq depth is %zu\n", inq_count);
12911 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 12912 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
12913 vty_out(vty, " Opens: %10d %10d\n",
12914 atomic_load_explicit(&p->open_out,
12915 memory_order_relaxed),
12916 atomic_load_explicit(&p->open_in,
12917 memory_order_relaxed));
12918 vty_out(vty, " Notifications: %10d %10d\n",
12919 atomic_load_explicit(&p->notify_out,
12920 memory_order_relaxed),
12921 atomic_load_explicit(&p->notify_in,
12922 memory_order_relaxed));
12923 vty_out(vty, " Updates: %10d %10d\n",
12924 atomic_load_explicit(&p->update_out,
12925 memory_order_relaxed),
12926 atomic_load_explicit(&p->update_in,
12927 memory_order_relaxed));
12928 vty_out(vty, " Keepalives: %10d %10d\n",
12929 atomic_load_explicit(&p->keepalive_out,
12930 memory_order_relaxed),
12931 atomic_load_explicit(&p->keepalive_in,
12932 memory_order_relaxed));
12933 vty_out(vty, " Route Refresh: %10d %10d\n",
12934 atomic_load_explicit(&p->refresh_out,
12935 memory_order_relaxed),
12936 atomic_load_explicit(&p->refresh_in,
12937 memory_order_relaxed));
d62a17ae 12938 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
12939 atomic_load_explicit(&p->dynamic_cap_out,
12940 memory_order_relaxed),
12941 atomic_load_explicit(&p->dynamic_cap_in,
12942 memory_order_relaxed));
12943 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
12944 PEER_TOTAL_RX(p));
d62a17ae 12945 }
12946
12947 if (use_json) {
12948 /* advertisement-interval */
12949 json_object_int_add(json_neigh,
12950 "minBtwnAdvertisementRunsTimerMsecs",
12951 p->v_routeadv * 1000);
12952
12953 /* Update-source. */
12954 if (p->update_if || p->update_source) {
12955 if (p->update_if)
12956 json_object_string_add(json_neigh,
12957 "updateSource",
12958 p->update_if);
12959 else if (p->update_source)
12960 json_object_string_add(
12961 json_neigh, "updateSource",
12962 sockunion2str(p->update_source, buf1,
12963 SU_ADDRSTRLEN));
12964 }
12965 } else {
12966 /* advertisement-interval */
12967 vty_out(vty,
12968 " Minimum time between advertisement runs is %d seconds\n",
12969 p->v_routeadv);
12970
12971 /* Update-source. */
12972 if (p->update_if || p->update_source) {
12973 vty_out(vty, " Update source is ");
12974 if (p->update_if)
12975 vty_out(vty, "%s", p->update_if);
12976 else if (p->update_source)
12977 vty_out(vty, "%s",
12978 sockunion2str(p->update_source, buf1,
12979 SU_ADDRSTRLEN));
12980 vty_out(vty, "\n");
12981 }
12982
12983 vty_out(vty, "\n");
12984 }
12985
12986 /* Address Family Information */
12987 json_object *json_hold = NULL;
12988
12989 if (use_json)
12990 json_hold = json_object_new_object();
12991
05c7a1cc
QY
12992 FOREACH_AFI_SAFI (afi, safi)
12993 if (p->afc[afi][safi])
12994 bgp_show_peer_afi(vty, p, afi, safi, use_json,
12995 json_hold);
d62a17ae 12996
12997 if (use_json) {
12998 json_object_object_add(json_neigh, "addressFamilyInfo",
12999 json_hold);
13000 json_object_int_add(json_neigh, "connectionsEstablished",
13001 p->established);
13002 json_object_int_add(json_neigh, "connectionsDropped",
13003 p->dropped);
13004 } else
13005 vty_out(vty, " Connections established %d; dropped %d\n",
13006 p->established, p->dropped);
13007
13008 if (!p->last_reset) {
13009 if (use_json)
13010 json_object_string_add(json_neigh, "lastReset",
13011 "never");
13012 else
13013 vty_out(vty, " Last reset never\n");
13014 } else {
13015 if (use_json) {
13016 time_t uptime;
a2700b50 13017 struct tm tm;
d62a17ae 13018
13019 uptime = bgp_clock();
13020 uptime -= p->resettime;
a2700b50
MS
13021 gmtime_r(&uptime, &tm);
13022
d62a17ae 13023 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13024 (tm.tm_sec * 1000)
13025 + (tm.tm_min * 60000)
13026 + (tm.tm_hour * 3600000));
3577f1c5 13027 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13028 } else {
13029 vty_out(vty, " Last reset %s, ",
13030 peer_uptime(p->resettime, timebuf,
13031 BGP_UPTIME_LEN, 0, NULL));
13032
3577f1c5 13033 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13034 if (p->last_reset_cause_size) {
13035 msg = p->last_reset_cause;
13036 vty_out(vty,
13037 " Message received that caused BGP to send a NOTIFICATION:\n ");
13038 for (i = 1; i <= p->last_reset_cause_size;
13039 i++) {
13040 vty_out(vty, "%02X", *msg++);
13041
13042 if (i != p->last_reset_cause_size) {
13043 if (i % 16 == 0) {
13044 vty_out(vty, "\n ");
13045 } else if (i % 4 == 0) {
13046 vty_out(vty, " ");
13047 }
13048 }
13049 }
13050 vty_out(vty, "\n");
13051 }
13052 }
13053 }
13054
13055 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13056 if (use_json)
13057 json_object_boolean_true_add(json_neigh,
13058 "prefixesConfigExceedMax");
13059 else
13060 vty_out(vty,
13061 " Peer had exceeded the max. no. of prefixes configured.\n");
13062
13063 if (p->t_pmax_restart) {
13064 if (use_json) {
13065 json_object_boolean_true_add(
13066 json_neigh, "reducePrefixNumFrom");
13067 json_object_int_add(json_neigh,
13068 "restartInTimerMsec",
13069 thread_timer_remain_second(
13070 p->t_pmax_restart)
13071 * 1000);
13072 } else
13073 vty_out(vty,
13074 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13075 p->host, thread_timer_remain_second(
13076 p->t_pmax_restart));
d62a17ae 13077 } else {
13078 if (use_json)
13079 json_object_boolean_true_add(
13080 json_neigh,
13081 "reducePrefixNumAndClearIpBgp");
13082 else
13083 vty_out(vty,
13084 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13085 p->host);
13086 }
13087 }
13088
13089 /* EBGP Multihop and GTSM */
13090 if (p->sort != BGP_PEER_IBGP) {
13091 if (use_json) {
e2521429 13092 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13093 json_object_int_add(json_neigh,
13094 "externalBgpNbrMaxHopsAway",
13095 p->gtsm_hops);
c8d6f0d6 13096 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13097 json_object_int_add(json_neigh,
13098 "externalBgpNbrMaxHopsAway",
13099 p->ttl);
13100 } else {
e2521429 13101 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13102 vty_out(vty,
13103 " External BGP neighbor may be up to %d hops away.\n",
13104 p->gtsm_hops);
c8d6f0d6 13105 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13106 vty_out(vty,
13107 " External BGP neighbor may be up to %d hops away.\n",
13108 p->ttl);
13109 }
13110 } else {
e2521429 13111 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13112 if (use_json)
13113 json_object_int_add(json_neigh,
13114 "internalBgpNbrMaxHopsAway",
13115 p->gtsm_hops);
13116 else
13117 vty_out(vty,
13118 " Internal BGP neighbor may be up to %d hops away.\n",
13119 p->gtsm_hops);
13120 }
13121 }
13122
13123 /* Local address. */
13124 if (p->su_local) {
13125 if (use_json) {
13126 json_object_string_add(json_neigh, "hostLocal",
13127 sockunion2str(p->su_local, buf1,
13128 SU_ADDRSTRLEN));
13129 json_object_int_add(json_neigh, "portLocal",
13130 ntohs(p->su_local->sin.sin_port));
13131 } else
13132 vty_out(vty, "Local host: %s, Local port: %d\n",
13133 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13134 ntohs(p->su_local->sin.sin_port));
13135 }
13136
13137 /* Remote address. */
13138 if (p->su_remote) {
13139 if (use_json) {
13140 json_object_string_add(json_neigh, "hostForeign",
13141 sockunion2str(p->su_remote, buf1,
13142 SU_ADDRSTRLEN));
13143 json_object_int_add(json_neigh, "portForeign",
13144 ntohs(p->su_remote->sin.sin_port));
13145 } else
13146 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13147 sockunion2str(p->su_remote, buf1,
13148 SU_ADDRSTRLEN),
13149 ntohs(p->su_remote->sin.sin_port));
13150 }
13151
13152 /* Nexthop display. */
13153 if (p->su_local) {
13154 if (use_json) {
13155 json_object_string_add(json_neigh, "nexthop",
13156 inet_ntop(AF_INET,
13157 &p->nexthop.v4, buf1,
13158 sizeof(buf1)));
13159 json_object_string_add(json_neigh, "nexthopGlobal",
13160 inet_ntop(AF_INET6,
13161 &p->nexthop.v6_global,
13162 buf1, sizeof(buf1)));
13163 json_object_string_add(json_neigh, "nexthopLocal",
13164 inet_ntop(AF_INET6,
13165 &p->nexthop.v6_local,
13166 buf1, sizeof(buf1)));
13167 if (p->shared_network)
13168 json_object_string_add(json_neigh,
13169 "bgpConnection",
13170 "sharedNetwork");
13171 else
13172 json_object_string_add(json_neigh,
13173 "bgpConnection",
13174 "nonSharedNetwork");
13175 } else {
13176 vty_out(vty, "Nexthop: %s\n",
13177 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13178 sizeof(buf1)));
13179 vty_out(vty, "Nexthop global: %s\n",
13180 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13181 sizeof(buf1)));
13182 vty_out(vty, "Nexthop local: %s\n",
13183 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13184 sizeof(buf1)));
13185 vty_out(vty, "BGP connection: %s\n",
13186 p->shared_network ? "shared network"
13187 : "non shared network");
13188 }
13189 }
13190
13191 /* Timer information. */
13192 if (use_json) {
13193 json_object_int_add(json_neigh, "connectRetryTimer",
13194 p->v_connect);
13195 if (p->status == Established && p->rtt)
13196 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13197 p->rtt);
13198 if (p->t_start)
13199 json_object_int_add(
13200 json_neigh, "nextStartTimerDueInMsecs",
13201 thread_timer_remain_second(p->t_start) * 1000);
13202 if (p->t_connect)
13203 json_object_int_add(
13204 json_neigh, "nextConnectTimerDueInMsecs",
13205 thread_timer_remain_second(p->t_connect)
13206 * 1000);
13207 if (p->t_routeadv) {
13208 json_object_int_add(json_neigh, "mraiInterval",
13209 p->v_routeadv);
13210 json_object_int_add(
13211 json_neigh, "mraiTimerExpireInMsecs",
13212 thread_timer_remain_second(p->t_routeadv)
13213 * 1000);
13214 }
13215 if (p->password)
13216 json_object_int_add(json_neigh, "authenticationEnabled",
13217 1);
13218
13219 if (p->t_read)
13220 json_object_string_add(json_neigh, "readThread", "on");
13221 else
13222 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
13223
13224 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 13225 json_object_string_add(json_neigh, "writeThread", "on");
13226 else
13227 json_object_string_add(json_neigh, "writeThread",
13228 "off");
13229 } else {
13230 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13231 p->v_connect);
13232 if (p->status == Established && p->rtt)
13233 vty_out(vty, "Estimated round trip time: %d ms\n",
13234 p->rtt);
13235 if (p->t_start)
13236 vty_out(vty, "Next start timer due in %ld seconds\n",
13237 thread_timer_remain_second(p->t_start));
13238 if (p->t_connect)
13239 vty_out(vty, "Next connect timer due in %ld seconds\n",
13240 thread_timer_remain_second(p->t_connect));
13241 if (p->t_routeadv)
13242 vty_out(vty,
13243 "MRAI (interval %u) timer expires in %ld seconds\n",
13244 p->v_routeadv,
13245 thread_timer_remain_second(p->t_routeadv));
13246 if (p->password)
13247 vty_out(vty, "Peer Authentication Enabled\n");
13248
cac9e917 13249 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
13250 p->t_read ? "on" : "off",
13251 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13252 ? "on"
cac9e917 13253 : "off", p->fd);
d62a17ae 13254 }
13255
13256 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13257 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13258 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13259
13260 if (!use_json)
13261 vty_out(vty, "\n");
13262
13263 /* BFD information. */
13264 bgp_bfd_show_info(vty, p, use_json, json_neigh);
13265
13266 if (use_json) {
13267 if (p->conf_if) /* Configured interface name. */
13268 json_object_object_add(json, p->conf_if, json_neigh);
13269 else /* Configured IP address. */
13270 json_object_object_add(json, p->host, json_neigh);
13271 }
13272}
13273
36235319
QY
13274static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13275 enum show_type type,
13276 union sockunion *su,
13277 const char *conf_if, afi_t afi,
74a630b6 13278 bool use_json)
2986cac2 13279{
13280 struct listnode *node, *nnode;
13281 struct peer *peer;
13282 int find = 0;
13283 safi_t safi = SAFI_UNICAST;
74a630b6 13284 json_object *json = NULL;
2986cac2 13285 json_object *json_neighbor = NULL;
13286
74a630b6
NT
13287 if (use_json) {
13288 json = json_object_new_object();
13289 json_neighbor = json_object_new_object();
13290 }
13291
2986cac2 13292 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13293
13294 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13295 continue;
13296
13297 if ((peer->afc[afi][safi]) == 0)
13298 continue;
13299
2ba1fe69 13300 if (type == show_all) {
2986cac2 13301 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 13302 json_neighbor);
2986cac2 13303
74a630b6 13304 if (use_json) {
13909c4f
DS
13305 json_object_object_add(json, peer->host,
13306 json_neighbor);
74a630b6
NT
13307 json_neighbor = NULL;
13308 }
2986cac2 13309
2ba1fe69 13310 } else if (type == show_peer) {
2986cac2 13311 if (conf_if) {
13312 if ((peer->conf_if
13909c4f
DS
13313 && !strcmp(peer->conf_if, conf_if))
13314 || (peer->hostname
2986cac2 13315 && !strcmp(peer->hostname, conf_if))) {
13316 find = 1;
13909c4f
DS
13317 bgp_show_peer_gr_status(vty, peer,
13318 use_json,
13319 json_neighbor);
2986cac2 13320 }
13321 } else {
13322 if (sockunion_same(&peer->su, su)) {
13323 find = 1;
13909c4f
DS
13324 bgp_show_peer_gr_status(vty, peer,
13325 use_json,
13326 json_neighbor);
2986cac2 13327 }
13328 }
13909c4f
DS
13329 if (use_json && find)
13330 json_object_object_add(json, peer->host,
13331 json_neighbor);
2986cac2 13332 }
13333
74a630b6
NT
13334 if (find) {
13335 json_neighbor = NULL;
2986cac2 13336 break;
74a630b6 13337 }
2986cac2 13338 }
13339
13340 if (type == show_peer && !find) {
13341 if (use_json)
13909c4f 13342 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 13343 else
13344 vty_out(vty, "%% No such neighbor\n");
13345 }
13346 if (use_json) {
13909c4f
DS
13347 vty_out(vty, "%s\n",
13348 json_object_to_json_string_ext(
13349 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
13350
13351 if (json_neighbor)
13352 json_object_free(json_neighbor);
13353 json_object_free(json);
2986cac2 13354 } else {
13355 vty_out(vty, "\n");
13356 }
13357
13358 return CMD_SUCCESS;
13359}
13360
d62a17ae 13361static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
13362 enum show_type type, union sockunion *su,
9f049418 13363 const char *conf_if, bool use_json,
d62a17ae 13364 json_object *json)
13365{
13366 struct listnode *node, *nnode;
13367 struct peer *peer;
13368 int find = 0;
9f049418 13369 bool nbr_output = false;
d1927ebe
AS
13370 afi_t afi = AFI_MAX;
13371 safi_t safi = SAFI_MAX;
13372
13373 if (type == show_ipv4_peer || type == show_ipv4_all) {
13374 afi = AFI_IP;
13375 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
13376 afi = AFI_IP6;
13377 }
d62a17ae 13378
13379 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13380 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13381 continue;
13382
13383 switch (type) {
13384 case show_all:
13385 bgp_show_peer(vty, peer, use_json, json);
9f049418 13386 nbr_output = true;
d62a17ae 13387 break;
13388 case show_peer:
13389 if (conf_if) {
13390 if ((peer->conf_if
13391 && !strcmp(peer->conf_if, conf_if))
13392 || (peer->hostname
13393 && !strcmp(peer->hostname, conf_if))) {
13394 find = 1;
13395 bgp_show_peer(vty, peer, use_json,
13396 json);
13397 }
13398 } else {
13399 if (sockunion_same(&peer->su, su)) {
13400 find = 1;
13401 bgp_show_peer(vty, peer, use_json,
13402 json);
13403 }
13404 }
13405 break;
d1927ebe
AS
13406 case show_ipv4_peer:
13407 case show_ipv6_peer:
13408 FOREACH_SAFI (safi) {
13409 if (peer->afc[afi][safi]) {
13410 if (conf_if) {
13411 if ((peer->conf_if
13412 && !strcmp(peer->conf_if, conf_if))
13413 || (peer->hostname
13414 && !strcmp(peer->hostname, conf_if))) {
13415 find = 1;
13416 bgp_show_peer(vty, peer, use_json,
13417 json);
13418 break;
13419 }
13420 } else {
13421 if (sockunion_same(&peer->su, su)) {
13422 find = 1;
13423 bgp_show_peer(vty, peer, use_json,
13424 json);
13425 break;
13426 }
13427 }
13428 }
13429 }
13430 break;
13431 case show_ipv4_all:
13432 case show_ipv6_all:
13433 FOREACH_SAFI (safi) {
13434 if (peer->afc[afi][safi]) {
13435 bgp_show_peer(vty, peer, use_json, json);
13436 nbr_output = true;
13437 break;
13438 }
13439 }
13440 break;
d62a17ae 13441 }
13442 }
13443
d1927ebe
AS
13444 if ((type == show_peer || type == show_ipv4_peer ||
13445 type == show_ipv6_peer) && !find) {
d62a17ae 13446 if (use_json)
13447 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
13448 else
88b7d255 13449 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 13450 }
13451
d1927ebe
AS
13452 if (type != show_peer && type != show_ipv4_peer &&
13453 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 13454 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 13455
d62a17ae 13456 if (use_json) {
996c9314
LB
13457 vty_out(vty, "%s\n", json_object_to_json_string_ext(
13458 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 13459 } else {
13460 vty_out(vty, "\n");
13461 }
13462
13463 return CMD_SUCCESS;
13464}
13465
36235319
QY
13466static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
13467 enum show_type type,
13468 const char *ip_str,
13469 afi_t afi, bool use_json)
2986cac2 13470{
13471
13472 int ret;
13473 struct bgp *bgp;
13474 union sockunion su;
2986cac2 13475
13476 bgp = bgp_get_default();
13477
13909c4f
DS
13478 if (!bgp)
13479 return;
2986cac2 13480
13909c4f
DS
13481 if (!use_json)
13482 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
13483 NULL);
2986cac2 13484
13909c4f
DS
13485 if (ip_str) {
13486 ret = str2sockunion(ip_str, &su);
13487 if (ret < 0)
13909c4f 13488 bgp_show_neighbor_graceful_restart(
74a630b6
NT
13489 vty, bgp, type, NULL, ip_str, afi, use_json);
13490 else
13491 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
13492 NULL, afi, use_json);
13909c4f
DS
13493 } else
13494 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 13495 afi, use_json);
2986cac2 13496}
13497
d62a17ae 13498static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
13499 enum show_type type,
13500 const char *ip_str,
9f049418 13501 bool use_json)
d62a17ae 13502{
0291c246
MK
13503 struct listnode *node, *nnode;
13504 struct bgp *bgp;
71aedaa3 13505 union sockunion su;
0291c246 13506 json_object *json = NULL;
71aedaa3 13507 int ret, is_first = 1;
9f049418 13508 bool nbr_output = false;
d62a17ae 13509
13510 if (use_json)
13511 vty_out(vty, "{\n");
13512
13513 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 13514 nbr_output = true;
d62a17ae 13515 if (use_json) {
13516 if (!(json = json_object_new_object())) {
af4c2728 13517 flog_err(
e50f7cfd 13518 EC_BGP_JSON_MEM_ERROR,
d62a17ae 13519 "Unable to allocate memory for JSON object");
13520 vty_out(vty,
13521 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
13522 return;
13523 }
13524
13525 json_object_int_add(json, "vrfId",
13526 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
13527 ? -1
13528 : (int64_t)bgp->vrf_id);
d62a17ae 13529 json_object_string_add(
13530 json, "vrfName",
13531 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13532 ? VRF_DEFAULT_NAME
d62a17ae 13533 : bgp->name);
13534
13535 if (!is_first)
13536 vty_out(vty, ",\n");
13537 else
13538 is_first = 0;
13539
13540 vty_out(vty, "\"%s\":",
13541 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13542 ? VRF_DEFAULT_NAME
d62a17ae 13543 : bgp->name);
13544 } else {
13545 vty_out(vty, "\nInstance %s:\n",
13546 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13547 ? VRF_DEFAULT_NAME
d62a17ae 13548 : bgp->name);
13549 }
71aedaa3 13550
d1927ebe
AS
13551 if (type == show_peer || type == show_ipv4_peer ||
13552 type == show_ipv6_peer) {
71aedaa3
DS
13553 ret = str2sockunion(ip_str, &su);
13554 if (ret < 0)
13555 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13556 use_json, json);
13557 else
13558 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13559 use_json, json);
13560 } else {
d1927ebe 13561 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
13562 use_json, json);
13563 }
b77004d6 13564 json_object_free(json);
121067e9 13565 json = NULL;
d62a17ae 13566 }
13567
3e78a6ce 13568 if (use_json)
d62a17ae 13569 vty_out(vty, "}\n");
9f049418
DS
13570 else if (!nbr_output)
13571 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 13572}
13573
13574static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
13575 enum show_type type, const char *ip_str,
9f049418 13576 bool use_json)
d62a17ae 13577{
13578 int ret;
13579 struct bgp *bgp;
13580 union sockunion su;
13581 json_object *json = NULL;
13582
13583 if (name) {
13584 if (strmatch(name, "all")) {
71aedaa3
DS
13585 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
13586 use_json);
d62a17ae 13587 return CMD_SUCCESS;
13588 } else {
13589 bgp = bgp_lookup_by_name(name);
13590 if (!bgp) {
13591 if (use_json) {
13592 json = json_object_new_object();
d62a17ae 13593 vty_out(vty, "%s\n",
13594 json_object_to_json_string_ext(
13595 json,
13596 JSON_C_TO_STRING_PRETTY));
13597 json_object_free(json);
13598 } else
13599 vty_out(vty,
9f049418 13600 "%% BGP instance not found\n");
d62a17ae 13601
13602 return CMD_WARNING;
13603 }
13604 }
13605 } else {
13606 bgp = bgp_get_default();
13607 }
13608
13609 if (bgp) {
13610 json = json_object_new_object();
13611 if (ip_str) {
13612 ret = str2sockunion(ip_str, &su);
13613 if (ret < 0)
13614 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13615 use_json, json);
13616 else
13617 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13618 use_json, json);
13619 } else {
13620 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
13621 json);
13622 }
13623 json_object_free(json);
ca61fd25
DS
13624 } else {
13625 if (use_json)
13626 vty_out(vty, "{}\n");
13627 else
13628 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 13629 }
13630
13631 return CMD_SUCCESS;
4fb25c53
DW
13632}
13633
2986cac2 13634
13635
13636/* "show [ip] bgp neighbors graceful-restart" commands. */
13637DEFUN (show_ip_bgp_neighbors_gracrful_restart,
13638 show_ip_bgp_neighbors_graceful_restart_cmd,
13639 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
13640 SHOW_STR
13641 BGP_STR
13642 IP_STR
13643 IPV6_STR
13644 NEIGHBOR_STR
13645 "Neighbor to display information about\n"
13646 "Neighbor to display information about\n"
13647 "Neighbor on BGP configured interface\n"
13648 GR_SHOW
13649 JSON_STR)
13650{
13651 char *sh_arg = NULL;
13652 enum show_type sh_type;
13653 int idx = 0;
13654 afi_t afi = AFI_MAX;
2986cac2 13655 bool uj = use_json(argc, argv);
13656
36235319 13657 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 13658 afi = AFI_MAX;
13659
13660 idx++;
13661
13662 if (argv_find(argv, argc, "A.B.C.D", &idx)
13663 || argv_find(argv, argc, "X:X::X:X", &idx)
13664 || argv_find(argv, argc, "WORD", &idx)) {
13665 sh_type = show_peer;
13666 sh_arg = argv[idx]->arg;
13667 } else
13668 sh_type = show_all;
13669
13670 if (!argv_find(argv, argc, "graceful-restart", &idx))
13671 return CMD_SUCCESS;
13672
13673
36235319
QY
13674 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
13675 afi, uj);
2986cac2 13676}
13677
716b2d8a 13678/* "show [ip] bgp neighbors" commands. */
718e3744 13679DEFUN (show_ip_bgp_neighbors,
13680 show_ip_bgp_neighbors_cmd,
24345e82 13681 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 13682 SHOW_STR
13683 IP_STR
13684 BGP_STR
f2a8972b 13685 BGP_INSTANCE_HELP_STR
8c3deaae
QY
13686 "Address Family\n"
13687 "Address Family\n"
718e3744 13688 "Detailed information on TCP and BGP neighbor connections\n"
13689 "Neighbor to display information about\n"
a80beece 13690 "Neighbor to display information about\n"
91d37724 13691 "Neighbor on BGP configured interface\n"
9973d184 13692 JSON_STR)
718e3744 13693{
d62a17ae 13694 char *vrf = NULL;
13695 char *sh_arg = NULL;
13696 enum show_type sh_type;
d1927ebe 13697 afi_t afi = AFI_MAX;
718e3744 13698
9f049418 13699 bool uj = use_json(argc, argv);
718e3744 13700
d62a17ae 13701 int idx = 0;
718e3744 13702
9a8bdf1c
PG
13703 /* [<vrf> VIEWVRFNAME] */
13704 if (argv_find(argv, argc, "vrf", &idx)) {
13705 vrf = argv[idx + 1]->arg;
13706 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13707 vrf = NULL;
13708 } else if (argv_find(argv, argc, "view", &idx))
13709 /* [<view> VIEWVRFNAME] */
d62a17ae 13710 vrf = argv[idx + 1]->arg;
718e3744 13711
d62a17ae 13712 idx++;
d1927ebe
AS
13713
13714 if (argv_find(argv, argc, "ipv4", &idx)) {
13715 sh_type = show_ipv4_all;
13716 afi = AFI_IP;
13717 } else if (argv_find(argv, argc, "ipv6", &idx)) {
13718 sh_type = show_ipv6_all;
13719 afi = AFI_IP6;
13720 } else {
13721 sh_type = show_all;
13722 }
13723
d62a17ae 13724 if (argv_find(argv, argc, "A.B.C.D", &idx)
13725 || argv_find(argv, argc, "X:X::X:X", &idx)
13726 || argv_find(argv, argc, "WORD", &idx)) {
13727 sh_type = show_peer;
13728 sh_arg = argv[idx]->arg;
d1927ebe
AS
13729 }
13730
13731 if (sh_type == show_peer && afi == AFI_IP) {
13732 sh_type = show_ipv4_peer;
13733 } else if (sh_type == show_peer && afi == AFI_IP6) {
13734 sh_type = show_ipv6_peer;
13735 }
856ca177 13736
d62a17ae 13737 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 13738}
13739
716b2d8a 13740/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 13741 paths' and `show ip mbgp paths'. Those functions results are the
13742 same.*/
f412b39a 13743DEFUN (show_ip_bgp_paths,
718e3744 13744 show_ip_bgp_paths_cmd,
46f296b4 13745 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 13746 SHOW_STR
13747 IP_STR
13748 BGP_STR
46f296b4 13749 BGP_SAFI_HELP_STR
718e3744 13750 "Path information\n")
13751{
d62a17ae 13752 vty_out(vty, "Address Refcnt Path\n");
13753 aspath_print_all_vty(vty);
13754 return CMD_SUCCESS;
718e3744 13755}
13756
718e3744 13757#include "hash.h"
13758
e3b78da8 13759static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 13760 struct vty *vty)
718e3744 13761{
d62a17ae 13762 struct community *com;
718e3744 13763
e3b78da8 13764 com = (struct community *)bucket->data;
3f65c5b1 13765 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 13766 community_str(com, false));
718e3744 13767}
13768
13769/* Show BGP's community internal data. */
f412b39a 13770DEFUN (show_ip_bgp_community_info,
718e3744 13771 show_ip_bgp_community_info_cmd,
bec37ba5 13772 "show [ip] bgp community-info",
718e3744 13773 SHOW_STR
13774 IP_STR
13775 BGP_STR
13776 "List all bgp community information\n")
13777{
d62a17ae 13778 vty_out(vty, "Address Refcnt Community\n");
718e3744 13779
d62a17ae 13780 hash_iterate(community_hash(),
e3b78da8 13781 (void (*)(struct hash_bucket *,
d62a17ae 13782 void *))community_show_all_iterator,
13783 vty);
718e3744 13784
d62a17ae 13785 return CMD_SUCCESS;
718e3744 13786}
13787
e3b78da8 13788static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 13789 struct vty *vty)
57d187bc 13790{
d62a17ae 13791 struct lcommunity *lcom;
57d187bc 13792
e3b78da8 13793 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 13794 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 13795 lcommunity_str(lcom, false));
57d187bc
JS
13796}
13797
13798/* Show BGP's community internal data. */
13799DEFUN (show_ip_bgp_lcommunity_info,
13800 show_ip_bgp_lcommunity_info_cmd,
13801 "show ip bgp large-community-info",
13802 SHOW_STR
13803 IP_STR
13804 BGP_STR
13805 "List all bgp large-community information\n")
13806{
d62a17ae 13807 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 13808
d62a17ae 13809 hash_iterate(lcommunity_hash(),
e3b78da8 13810 (void (*)(struct hash_bucket *,
d62a17ae 13811 void *))lcommunity_show_all_iterator,
13812 vty);
57d187bc 13813
d62a17ae 13814 return CMD_SUCCESS;
57d187bc 13815}
2986cac2 13816/* Graceful Restart */
13817
13818static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
13819 struct bgp *bgp,
13820 bool use_json,
13821 json_object *json)
2986cac2 13822{
57d187bc
JS
13823
13824
2986cac2 13825 vty_out(vty, "\n%s", SHOW_GR_HEADER);
13826
7318ae88 13827 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 13828
13829 switch (bgp_global_gr_mode) {
13830
13831 case GLOBAL_HELPER:
13909c4f 13832 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 13833 break;
13834
13835 case GLOBAL_GR:
13909c4f 13836 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 13837 break;
13838
13839 case GLOBAL_DISABLE:
13909c4f 13840 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 13841 break;
13842
13843 case GLOBAL_INVALID:
2986cac2 13844 vty_out(vty,
2ba1fe69 13845 "Global BGP GR Mode Invalid\n");
2986cac2 13846 break;
13847 }
13848 vty_out(vty, "\n");
13849}
13850
36235319
QY
13851static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
13852 enum show_type type,
13853 const char *ip_str,
13854 afi_t afi, bool use_json)
2986cac2 13855{
13856 if ((afi == AFI_MAX) && (ip_str == NULL)) {
13857 afi = AFI_IP;
13858
13859 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
13860
36235319
QY
13861 bgp_show_neighbor_graceful_restart_vty(
13862 vty, type, ip_str, afi, use_json);
2986cac2 13863 afi++;
13864 }
13865 } else if (afi != AFI_MAX) {
36235319
QY
13866 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
13867 use_json);
2986cac2 13868 } else {
13869 return CMD_ERR_INCOMPLETE;
13870 }
13871
13872 return CMD_SUCCESS;
13873}
13874/* Graceful Restart */
13875
f412b39a 13876DEFUN (show_ip_bgp_attr_info,
718e3744 13877 show_ip_bgp_attr_info_cmd,
bec37ba5 13878 "show [ip] bgp attribute-info",
718e3744 13879 SHOW_STR
13880 IP_STR
13881 BGP_STR
13882 "List all bgp attribute information\n")
13883{
d62a17ae 13884 attr_show_all(vty);
13885 return CMD_SUCCESS;
718e3744 13886}
6b0655a2 13887
03915806
CS
13888static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
13889 afi_t afi, safi_t safi,
13890 bool use_json, json_object *json)
53089bec 13891{
13892 struct bgp *bgp;
13893 struct listnode *node;
13894 char *vname;
13895 char buf1[INET6_ADDRSTRLEN];
13896 char *ecom_str;
13897 vpn_policy_direction_t dir;
13898
03915806 13899 if (json) {
b46dfd20
DS
13900 json_object *json_import_vrfs = NULL;
13901 json_object *json_export_vrfs = NULL;
13902
b46dfd20
DS
13903 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13904
53089bec 13905 if (!bgp) {
b46dfd20
DS
13906 vty_out(vty, "%s\n",
13907 json_object_to_json_string_ext(
13908 json,
13909 JSON_C_TO_STRING_PRETTY));
13910 json_object_free(json);
13911
53089bec 13912 return CMD_WARNING;
13913 }
b46dfd20 13914
94d4c685
DS
13915 /* Provide context for the block */
13916 json_object_string_add(json, "vrf", name ? name : "default");
13917 json_object_string_add(json, "afiSafi",
5cb5f4d0 13918 get_afi_safi_str(afi, safi, true));
94d4c685 13919
b46dfd20
DS
13920 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13921 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
13922 json_object_string_add(json, "importFromVrfs", "none");
13923 json_object_string_add(json, "importRts", "none");
13924 } else {
6ce24e52
DS
13925 json_import_vrfs = json_object_new_array();
13926
b46dfd20
DS
13927 for (ALL_LIST_ELEMENTS_RO(
13928 bgp->vpn_policy[afi].import_vrf,
13929 node, vname))
13930 json_object_array_add(json_import_vrfs,
13931 json_object_new_string(vname));
13932
b20875ea
CS
13933 json_object_object_add(json, "importFromVrfs",
13934 json_import_vrfs);
b46dfd20 13935 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13936 if (bgp->vpn_policy[afi].rtlist[dir]) {
13937 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13938 bgp->vpn_policy[afi].rtlist[dir],
13939 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13940 json_object_string_add(json, "importRts",
13941 ecom_str);
13942 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13943 } else
13944 json_object_string_add(json, "importRts",
13945 "none");
b46dfd20
DS
13946 }
13947
13948 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13949 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
13950 json_object_string_add(json, "exportToVrfs", "none");
13951 json_object_string_add(json, "routeDistinguisher",
13952 "none");
13953 json_object_string_add(json, "exportRts", "none");
13954 } else {
6ce24e52
DS
13955 json_export_vrfs = json_object_new_array();
13956
b46dfd20
DS
13957 for (ALL_LIST_ELEMENTS_RO(
13958 bgp->vpn_policy[afi].export_vrf,
13959 node, vname))
13960 json_object_array_add(json_export_vrfs,
13961 json_object_new_string(vname));
13962 json_object_object_add(json, "exportToVrfs",
13963 json_export_vrfs);
13964 json_object_string_add(json, "routeDistinguisher",
13965 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13966 buf1, RD_ADDRSTRLEN));
13967
13968 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13969 if (bgp->vpn_policy[afi].rtlist[dir]) {
13970 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13971 bgp->vpn_policy[afi].rtlist[dir],
13972 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13973 json_object_string_add(json, "exportRts",
13974 ecom_str);
13975 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13976 } else
13977 json_object_string_add(json, "exportRts",
13978 "none");
b46dfd20
DS
13979 }
13980
03915806
CS
13981 if (use_json) {
13982 vty_out(vty, "%s\n",
13983 json_object_to_json_string_ext(json,
b46dfd20 13984 JSON_C_TO_STRING_PRETTY));
03915806
CS
13985 json_object_free(json);
13986 }
53089bec 13987 } else {
b46dfd20
DS
13988 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13989
53089bec 13990 if (!bgp) {
b46dfd20 13991 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 13992 return CMD_WARNING;
13993 }
53089bec 13994
b46dfd20
DS
13995 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13996 BGP_CONFIG_VRF_TO_VRF_IMPORT))
13997 vty_out(vty,
13998 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 13999 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14000 else {
14001 vty_out(vty,
14002 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14003 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14004
14005 for (ALL_LIST_ELEMENTS_RO(
14006 bgp->vpn_policy[afi].import_vrf,
14007 node, vname))
14008 vty_out(vty, " %s\n", vname);
14009
14010 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14011 ecom_str = NULL;
14012 if (bgp->vpn_policy[afi].rtlist[dir]) {
14013 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14014 bgp->vpn_policy[afi].rtlist[dir],
14015 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14016 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14017
b20875ea
CS
14018 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14019 } else
14020 vty_out(vty, "Import RT(s):\n");
53089bec 14021 }
53089bec 14022
b46dfd20
DS
14023 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14024 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14025 vty_out(vty,
14026 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14027 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14028 else {
14029 vty_out(vty,
04c9077f 14030 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14031 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14032
14033 for (ALL_LIST_ELEMENTS_RO(
14034 bgp->vpn_policy[afi].export_vrf,
14035 node, vname))
14036 vty_out(vty, " %s\n", vname);
14037
14038 vty_out(vty, "RD: %s\n",
14039 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14040 buf1, RD_ADDRSTRLEN));
14041
14042 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14043 if (bgp->vpn_policy[afi].rtlist[dir]) {
14044 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14045 bgp->vpn_policy[afi].rtlist[dir],
14046 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14047 vty_out(vty, "Export RT: %s\n", ecom_str);
14048 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14049 } else
14050 vty_out(vty, "Import RT(s):\n");
53089bec 14051 }
53089bec 14052 }
14053
14054 return CMD_SUCCESS;
14055}
14056
03915806
CS
14057static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14058 safi_t safi, bool use_json)
14059{
14060 struct listnode *node, *nnode;
14061 struct bgp *bgp;
14062 char *vrf_name = NULL;
14063 json_object *json = NULL;
14064 json_object *json_vrf = NULL;
14065 json_object *json_vrfs = NULL;
14066
14067 if (use_json) {
14068 json = json_object_new_object();
14069 json_vrfs = json_object_new_object();
14070 }
14071
14072 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14073
14074 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14075 vrf_name = bgp->name;
14076
14077 if (use_json) {
14078 json_vrf = json_object_new_object();
14079 } else {
14080 vty_out(vty, "\nInstance %s:\n",
14081 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14082 ? VRF_DEFAULT_NAME : bgp->name);
14083 }
14084 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14085 if (use_json) {
14086 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14087 json_object_object_add(json_vrfs,
14088 VRF_DEFAULT_NAME, json_vrf);
14089 else
14090 json_object_object_add(json_vrfs, vrf_name,
14091 json_vrf);
14092 }
14093 }
14094
14095 if (use_json) {
14096 json_object_object_add(json, "vrfs", json_vrfs);
14097 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
14098 JSON_C_TO_STRING_PRETTY));
14099 json_object_free(json);
14100 }
14101
14102 return CMD_SUCCESS;
14103}
14104
53089bec 14105/* "show [ip] bgp route-leak" command. */
14106DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14107 show_ip_bgp_route_leak_cmd,
14108 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14109 SHOW_STR
14110 IP_STR
14111 BGP_STR
14112 BGP_INSTANCE_HELP_STR
14113 BGP_AFI_HELP_STR
14114 BGP_SAFI_HELP_STR
14115 "Route leaking information\n"
14116 JSON_STR)
53089bec 14117{
14118 char *vrf = NULL;
14119 afi_t afi = AFI_MAX;
14120 safi_t safi = SAFI_MAX;
14121
9f049418 14122 bool uj = use_json(argc, argv);
53089bec 14123 int idx = 0;
03915806 14124 json_object *json = NULL;
53089bec 14125
14126 /* show [ip] bgp */
14127 if (argv_find(argv, argc, "ip", &idx)) {
14128 afi = AFI_IP;
14129 safi = SAFI_UNICAST;
14130 }
14131 /* [vrf VIEWVRFNAME] */
14132 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14133 vty_out(vty,
14134 "%% This command is not applicable to BGP views\n");
53089bec 14135 return CMD_WARNING;
14136 }
14137
9a8bdf1c
PG
14138 if (argv_find(argv, argc, "vrf", &idx)) {
14139 vrf = argv[idx + 1]->arg;
14140 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14141 vrf = NULL;
14142 }
53089bec 14143 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14144 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14145 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14146 }
14147
14148 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14149 vty_out(vty,
14150 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14151 return CMD_WARNING;
14152 }
14153
03915806
CS
14154 if (vrf && strmatch(vrf, "all"))
14155 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14156
14157 if (uj)
14158 json = json_object_new_object();
14159
14160 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14161}
14162
d62a17ae 14163static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14164 safi_t safi)
f186de26 14165{
d62a17ae 14166 struct listnode *node, *nnode;
14167 struct bgp *bgp;
f186de26 14168
d62a17ae 14169 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14170 vty_out(vty, "\nInstance %s:\n",
14171 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14172 ? VRF_DEFAULT_NAME
d62a17ae 14173 : bgp->name);
14174 update_group_show(bgp, afi, safi, vty, 0);
14175 }
f186de26 14176}
14177
d62a17ae 14178static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14179 int safi, uint64_t subgrp_id)
4fb25c53 14180{
d62a17ae 14181 struct bgp *bgp;
4fb25c53 14182
d62a17ae 14183 if (name) {
14184 if (strmatch(name, "all")) {
14185 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14186 return CMD_SUCCESS;
14187 } else {
14188 bgp = bgp_lookup_by_name(name);
14189 }
14190 } else {
14191 bgp = bgp_get_default();
14192 }
4fb25c53 14193
d62a17ae 14194 if (bgp)
14195 update_group_show(bgp, afi, safi, vty, subgrp_id);
14196 return CMD_SUCCESS;
4fb25c53
DW
14197}
14198
8fe8a7f6
DS
14199DEFUN (show_ip_bgp_updgrps,
14200 show_ip_bgp_updgrps_cmd,
c1a44e43 14201 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14202 SHOW_STR
14203 IP_STR
14204 BGP_STR
14205 BGP_INSTANCE_HELP_STR
c9e571b4 14206 BGP_AFI_HELP_STR
9bedbb1e 14207 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14208 "Detailed info about dynamic update groups\n"
14209 "Specific subgroup to display detailed info for\n")
8386ac43 14210{
d62a17ae 14211 char *vrf = NULL;
14212 afi_t afi = AFI_IP6;
14213 safi_t safi = SAFI_UNICAST;
14214 uint64_t subgrp_id = 0;
14215
14216 int idx = 0;
14217
14218 /* show [ip] bgp */
14219 if (argv_find(argv, argc, "ip", &idx))
14220 afi = AFI_IP;
9a8bdf1c
PG
14221 /* [<vrf> VIEWVRFNAME] */
14222 if (argv_find(argv, argc, "vrf", &idx)) {
14223 vrf = argv[idx + 1]->arg;
14224 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14225 vrf = NULL;
14226 } else if (argv_find(argv, argc, "view", &idx))
14227 /* [<view> VIEWVRFNAME] */
14228 vrf = argv[idx + 1]->arg;
d62a17ae 14229 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14230 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14231 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14232 }
5bf15956 14233
d62a17ae 14234 /* get subgroup id, if provided */
14235 idx = argc - 1;
14236 if (argv[idx]->type == VARIABLE_TKN)
14237 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 14238
d62a17ae 14239 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
14240}
14241
f186de26 14242DEFUN (show_bgp_instance_all_ipv6_updgrps,
14243 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 14244 "show [ip] bgp <view|vrf> all update-groups",
f186de26 14245 SHOW_STR
716b2d8a 14246 IP_STR
f186de26 14247 BGP_STR
14248 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 14249 "Detailed info about dynamic update groups\n")
f186de26 14250{
d62a17ae 14251 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14252 return CMD_SUCCESS;
f186de26 14253}
14254
43d3f4fc
DS
14255DEFUN (show_bgp_l2vpn_evpn_updgrps,
14256 show_bgp_l2vpn_evpn_updgrps_cmd,
14257 "show [ip] bgp l2vpn evpn update-groups",
14258 SHOW_STR
14259 IP_STR
14260 BGP_STR
14261 "l2vpn address family\n"
14262 "evpn sub-address family\n"
14263 "Detailed info about dynamic update groups\n")
14264{
14265 char *vrf = NULL;
14266 uint64_t subgrp_id = 0;
14267
14268 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14269 return CMD_SUCCESS;
14270}
14271
5bf15956
DW
14272DEFUN (show_bgp_updgrps_stats,
14273 show_bgp_updgrps_stats_cmd,
716b2d8a 14274 "show [ip] bgp update-groups statistics",
3f9c7369 14275 SHOW_STR
716b2d8a 14276 IP_STR
3f9c7369 14277 BGP_STR
0c7b1b01 14278 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14279 "Statistics\n")
14280{
d62a17ae 14281 struct bgp *bgp;
3f9c7369 14282
d62a17ae 14283 bgp = bgp_get_default();
14284 if (bgp)
14285 update_group_show_stats(bgp, vty);
3f9c7369 14286
d62a17ae 14287 return CMD_SUCCESS;
3f9c7369
DS
14288}
14289
8386ac43 14290DEFUN (show_bgp_instance_updgrps_stats,
14291 show_bgp_instance_updgrps_stats_cmd,
18c57037 14292 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14293 SHOW_STR
716b2d8a 14294 IP_STR
8386ac43 14295 BGP_STR
14296 BGP_INSTANCE_HELP_STR
0c7b1b01 14297 "Detailed info about dynamic update groups\n"
8386ac43 14298 "Statistics\n")
14299{
d62a17ae 14300 int idx_word = 3;
14301 struct bgp *bgp;
8386ac43 14302
d62a17ae 14303 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14304 if (bgp)
14305 update_group_show_stats(bgp, vty);
8386ac43 14306
d62a17ae 14307 return CMD_SUCCESS;
8386ac43 14308}
14309
d62a17ae 14310static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14311 afi_t afi, safi_t safi,
14312 const char *what, uint64_t subgrp_id)
3f9c7369 14313{
d62a17ae 14314 struct bgp *bgp;
8386ac43 14315
d62a17ae 14316 if (name)
14317 bgp = bgp_lookup_by_name(name);
14318 else
14319 bgp = bgp_get_default();
8386ac43 14320
d62a17ae 14321 if (bgp) {
14322 if (!strcmp(what, "advertise-queue"))
14323 update_group_show_adj_queue(bgp, afi, safi, vty,
14324 subgrp_id);
14325 else if (!strcmp(what, "advertised-routes"))
14326 update_group_show_advertised(bgp, afi, safi, vty,
14327 subgrp_id);
14328 else if (!strcmp(what, "packet-queue"))
14329 update_group_show_packet_queue(bgp, afi, safi, vty,
14330 subgrp_id);
14331 }
3f9c7369
DS
14332}
14333
dc64bdec
QY
14334DEFPY(show_ip_bgp_instance_updgrps_adj_s,
14335 show_ip_bgp_instance_updgrps_adj_s_cmd,
14336 "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",
14337 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
14338 BGP_SAFI_HELP_STR
14339 "Detailed info about dynamic update groups\n"
14340 "Specific subgroup to display info for\n"
14341 "Advertisement queue\n"
14342 "Announced routes\n"
14343 "Packet queue\n")
3f9c7369 14344{
dc64bdec
QY
14345 uint64_t subgrp_id = 0;
14346 afi_t afiz;
14347 safi_t safiz;
14348 if (sgid)
14349 subgrp_id = strtoull(sgid, NULL, 10);
14350
14351 if (!ip && !afi)
14352 afiz = AFI_IP6;
14353 if (!ip && afi)
14354 afiz = bgp_vty_afi_from_str(afi);
14355 if (ip && !afi)
14356 afiz = AFI_IP;
14357 if (ip && afi) {
14358 afiz = bgp_vty_afi_from_str(afi);
14359 if (afiz != AFI_IP)
14360 vty_out(vty,
14361 "%% Cannot specify both 'ip' and 'ipv6'\n");
14362 return CMD_WARNING;
14363 }
d62a17ae 14364
dc64bdec 14365 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 14366
dc64bdec 14367 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 14368 return CMD_SUCCESS;
14369}
14370
d62a17ae 14371static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
14372{
14373 struct listnode *node, *nnode;
14374 struct prefix *range;
14375 struct peer *conf;
14376 struct peer *peer;
d62a17ae 14377 afi_t afi;
14378 safi_t safi;
14379 const char *peer_status;
14380 const char *af_str;
14381 int lr_count;
14382 int dynamic;
14383 int af_cfgd;
14384
14385 conf = group->conf;
14386
14387 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 14388 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 14389 group->name, conf->as);
d62a17ae 14390 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 14391 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 14392 group->name, group->bgp->as);
d62a17ae 14393 } else {
14394 vty_out(vty, "\nBGP peer-group %s\n", group->name);
14395 }
f14e6fdb 14396
d62a17ae 14397 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
14398 vty_out(vty, " Peer-group type is internal\n");
14399 else
14400 vty_out(vty, " Peer-group type is external\n");
14401
14402 /* Display AFs configured. */
14403 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
14404 FOREACH_AFI_SAFI (afi, safi) {
14405 if (conf->afc[afi][safi]) {
14406 af_cfgd = 1;
5cb5f4d0 14407 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 14408 }
05c7a1cc 14409 }
d62a17ae 14410 if (!af_cfgd)
14411 vty_out(vty, " none\n");
14412 else
14413 vty_out(vty, "\n");
14414
14415 /* Display listen ranges (for dynamic neighbors), if any */
14416 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
14417 if (afi == AFI_IP)
14418 af_str = "IPv4";
14419 else if (afi == AFI_IP6)
14420 af_str = "IPv6";
14421 else
14422 af_str = "???";
14423 lr_count = listcount(group->listen_range[afi]);
14424 if (lr_count) {
14425 vty_out(vty, " %d %s listen range(s)\n", lr_count,
14426 af_str);
14427
14428
14429 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
2dbe669b
DA
14430 nnode, range))
14431 vty_out(vty, " %pFX\n", range);
d62a17ae 14432 }
14433 }
f14e6fdb 14434
d62a17ae 14435 /* Display group members and their status */
14436 if (listcount(group->peer)) {
14437 vty_out(vty, " Peer-group members:\n");
14438 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
14439 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
14440 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 14441 peer_status = "Idle (Admin)";
14442 else if (CHECK_FLAG(peer->sflags,
14443 PEER_STATUS_PREFIX_OVERFLOW))
14444 peer_status = "Idle (PfxCt)";
14445 else
14446 peer_status = lookup_msg(bgp_status_msg,
14447 peer->status, NULL);
14448
14449 dynamic = peer_dynamic_neighbor(peer);
14450 vty_out(vty, " %s %s %s \n", peer->host,
14451 dynamic ? "(dynamic)" : "", peer_status);
14452 }
14453 }
f14e6fdb 14454
d62a17ae 14455 return CMD_SUCCESS;
14456}
14457
ff9959b0
QY
14458static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
14459 const char *group_name)
d62a17ae 14460{
ff9959b0 14461 struct bgp *bgp;
d62a17ae 14462 struct listnode *node, *nnode;
14463 struct peer_group *group;
ff9959b0
QY
14464 bool found = false;
14465
14466 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14467
14468 if (!bgp) {
9f049418 14469 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
14470 return CMD_WARNING;
14471 }
d62a17ae 14472
14473 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
14474 if (group_name) {
14475 if (strmatch(group->name, group_name)) {
d62a17ae 14476 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
14477 found = true;
14478 break;
d62a17ae 14479 }
ff9959b0
QY
14480 } else {
14481 bgp_show_one_peer_group(vty, group);
d62a17ae 14482 }
f14e6fdb 14483 }
f14e6fdb 14484
ff9959b0 14485 if (group_name && !found)
d62a17ae 14486 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 14487
d62a17ae 14488 return CMD_SUCCESS;
f14e6fdb
DS
14489}
14490
f14e6fdb
DS
14491DEFUN (show_ip_bgp_peer_groups,
14492 show_ip_bgp_peer_groups_cmd,
18c57037 14493 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
14494 SHOW_STR
14495 IP_STR
14496 BGP_STR
8386ac43 14497 BGP_INSTANCE_HELP_STR
d6e3c605
QY
14498 "Detailed information on BGP peer groups\n"
14499 "Peer group name\n")
f14e6fdb 14500{
d62a17ae 14501 char *vrf, *pg;
d62a17ae 14502 int idx = 0;
f14e6fdb 14503
a4d82a8a
PZ
14504 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
14505 : NULL;
d62a17ae 14506 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 14507
ff9959b0 14508 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 14509}
3f9c7369 14510
d6e3c605 14511
718e3744 14512/* Redistribute VTY commands. */
14513
37a87b8f
CS
14514DEFUN_YANG (bgp_redistribute_ipv4,
14515 bgp_redistribute_ipv4_cmd,
14516 "redistribute " FRR_IP_REDIST_STR_BGPD,
14517 "Redistribute information from another routing protocol\n"
14518 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 14519{
d62a17ae 14520 int idx_protocol = 1;
37a87b8f 14521 char base_xpath[XPATH_MAXLEN];
718e3744 14522
37a87b8f
CS
14523 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14524 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14525 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14526 argv[idx_protocol]->text, "0");
14527
14528 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 14529
37a87b8f 14530 return nb_cli_apply_changes(vty, base_xpath);
718e3744 14531}
14532
d62a17ae 14533ALIAS_HIDDEN(
14534 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
14535 "redistribute " FRR_IP_REDIST_STR_BGPD,
14536 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 14537
37a87b8f
CS
14538DEFUN_YANG (bgp_redistribute_ipv4_rmap,
14539 bgp_redistribute_ipv4_rmap_cmd,
14540 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
14541 "Redistribute information from another routing protocol\n"
14542 FRR_IP_REDIST_HELP_STR_BGPD
14543 "Route map reference\n"
14544 "Pointer to route-map entries\n")
718e3744 14545{
d62a17ae 14546 int idx_protocol = 1;
14547 int idx_word = 3;
37a87b8f
CS
14548 char base_xpath[XPATH_MAXLEN];
14549
14550 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14551 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14552 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14553 argv[idx_protocol]->text, "0");
718e3744 14554
37a87b8f
CS
14555 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
14556 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
14557 argv[idx_word]->arg);
14558
14559 return nb_cli_apply_changes(vty, base_xpath);
718e3744 14560}
14561
d62a17ae 14562ALIAS_HIDDEN(
14563 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
14564 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
14565 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14566 "Route map reference\n"
14567 "Pointer to route-map entries\n")
596c17ba 14568
37a87b8f
CS
14569DEFUN_YANG (bgp_redistribute_ipv4_metric,
14570 bgp_redistribute_ipv4_metric_cmd,
14571 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
14572 "Redistribute information from another routing protocol\n"
14573 FRR_IP_REDIST_HELP_STR_BGPD
14574 "Metric for redistributed routes\n"
14575 "Default metric\n")
718e3744 14576{
d62a17ae 14577 int idx_protocol = 1;
14578 int idx_number = 3;
37a87b8f
CS
14579 char base_xpath[XPATH_MAXLEN];
14580
14581 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14582 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14583 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14584 argv[idx_protocol]->text, "0");
d62a17ae 14585
37a87b8f
CS
14586 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
14587 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
14588 argv[idx_number]->arg);
14589
14590 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 14591}
14592
14593ALIAS_HIDDEN(
14594 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
14595 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
14596 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14597 "Metric for redistributed routes\n"
14598 "Default metric\n")
596c17ba 14599
37a87b8f
CS
14600DEFUN_YANG(
14601 bgp_redistribute_ipv4_rmap_metric,
14602 bgp_redistribute_ipv4_rmap_metric_cmd,
14603 "redistribute " FRR_IP_REDIST_STR_BGPD
14604 " route-map WORD metric (0-4294967295)",
14605 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14606 "Route map reference\n"
14607 "Pointer to route-map entries\n"
14608 "Metric for redistributed routes\n"
14609 "Default metric\n")
718e3744 14610{
d62a17ae 14611 int idx_protocol = 1;
14612 int idx_word = 3;
14613 int idx_number = 5;
37a87b8f
CS
14614 char base_xpath[XPATH_MAXLEN];
14615
14616 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14617 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14618 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14619 argv[idx_protocol]->text, "0");
14620
14621 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
14622 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
14623 argv[idx_word]->arg);
14624 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
14625 argv[idx_number]->arg);
d62a17ae 14626
37a87b8f 14627 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 14628}
14629
14630ALIAS_HIDDEN(
14631 bgp_redistribute_ipv4_rmap_metric,
14632 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
14633 "redistribute " FRR_IP_REDIST_STR_BGPD
14634 " route-map WORD metric (0-4294967295)",
14635 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14636 "Route map reference\n"
14637 "Pointer to route-map entries\n"
14638 "Metric for redistributed routes\n"
14639 "Default metric\n")
596c17ba 14640
37a87b8f
CS
14641DEFUN_YANG(
14642 bgp_redistribute_ipv4_metric_rmap,
14643 bgp_redistribute_ipv4_metric_rmap_cmd,
14644 "redistribute " FRR_IP_REDIST_STR_BGPD
14645 " metric (0-4294967295) route-map WORD",
14646 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14647 "Metric for redistributed routes\n"
14648 "Default metric\n"
14649 "Route map reference\n"
14650 "Pointer to route-map entries\n")
718e3744 14651{
d62a17ae 14652 int idx_protocol = 1;
d62a17ae 14653 int idx_word = 5;
37a87b8f
CS
14654 int idx_number = 3;
14655 char base_xpath[XPATH_MAXLEN];
14656
14657 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14658 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14659 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14660 argv[idx_protocol]->text, "0");
14661
14662 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
14663 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
14664 argv[idx_number]->arg);
14665 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
14666 argv[idx_word]->arg);
d62a17ae 14667
37a87b8f 14668 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 14669}
14670
14671ALIAS_HIDDEN(
14672 bgp_redistribute_ipv4_metric_rmap,
14673 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
14674 "redistribute " FRR_IP_REDIST_STR_BGPD
14675 " metric (0-4294967295) route-map WORD",
14676 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14677 "Metric for redistributed routes\n"
14678 "Default metric\n"
14679 "Route map reference\n"
14680 "Pointer to route-map entries\n")
596c17ba 14681
37a87b8f
CS
14682DEFUN_YANG (bgp_redistribute_ipv4_ospf,
14683 bgp_redistribute_ipv4_ospf_cmd,
14684 "redistribute <ospf|table> (1-65535)",
14685 "Redistribute information from another routing protocol\n"
14686 "Open Shortest Path First (OSPFv2)\n"
14687 "Non-main Kernel Routing Table\n"
14688 "Instance ID/Table ID\n")
7c8ff89e 14689{
37a87b8f 14690 int idx_protocol = 1;
d62a17ae 14691 int idx_number = 2;
37a87b8f 14692 char base_xpath[XPATH_MAXLEN];
7c8ff89e 14693
37a87b8f
CS
14694 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14695 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14696 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14697 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 14698
37a87b8f 14699 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 14700
37a87b8f 14701 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
14702}
14703
d62a17ae 14704ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
14705 "redistribute <ospf|table> (1-65535)",
14706 "Redistribute information from another routing protocol\n"
14707 "Open Shortest Path First (OSPFv2)\n"
14708 "Non-main Kernel Routing Table\n"
14709 "Instance ID/Table ID\n")
596c17ba 14710
37a87b8f
CS
14711DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
14712 bgp_redistribute_ipv4_ospf_rmap_cmd,
14713 "redistribute <ospf|table> (1-65535) route-map WORD",
14714 "Redistribute information from another routing protocol\n"
14715 "Open Shortest Path First (OSPFv2)\n"
14716 "Non-main Kernel Routing Table\n"
14717 "Instance ID/Table ID\n"
14718 "Route map reference\n"
14719 "Pointer to route-map entries\n")
7c8ff89e 14720{
37a87b8f 14721 int idx_protocol = 1;
d62a17ae 14722 int idx_number = 2;
14723 int idx_word = 4;
37a87b8f
CS
14724 char base_xpath[XPATH_MAXLEN];
14725
14726 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14727 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14728 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14729 argv[idx_protocol]->text, argv[idx_number]->arg);
14730
14731 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
14732
14733 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
14734 argv[idx_word]->arg);
d62a17ae 14735
37a87b8f 14736 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 14737}
14738
14739ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
14740 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
14741 "redistribute <ospf|table> (1-65535) route-map WORD",
14742 "Redistribute information from another routing protocol\n"
14743 "Open Shortest Path First (OSPFv2)\n"
14744 "Non-main Kernel Routing Table\n"
14745 "Instance ID/Table ID\n"
14746 "Route map reference\n"
14747 "Pointer to route-map entries\n")
596c17ba 14748
37a87b8f
CS
14749DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
14750 bgp_redistribute_ipv4_ospf_metric_cmd,
14751 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14752 "Redistribute information from another routing protocol\n"
14753 "Open Shortest Path First (OSPFv2)\n"
14754 "Non-main Kernel Routing Table\n"
14755 "Instance ID/Table ID\n"
14756 "Metric for redistributed routes\n"
14757 "Default metric\n")
7c8ff89e 14758{
37a87b8f 14759 int idx_protocol = 1;
d62a17ae 14760 int idx_number = 2;
14761 int idx_number_2 = 4;
37a87b8f
CS
14762 char base_xpath[XPATH_MAXLEN];
14763
14764 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14765 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14766 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14767 argv[idx_protocol]->text, argv[idx_number]->arg);
14768
14769 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 14770
37a87b8f
CS
14771 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
14772 argv[idx_number_2]->arg);
d62a17ae 14773
37a87b8f 14774 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 14775}
14776
14777ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
14778 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
14779 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14780 "Redistribute information from another routing protocol\n"
14781 "Open Shortest Path First (OSPFv2)\n"
14782 "Non-main Kernel Routing Table\n"
14783 "Instance ID/Table ID\n"
14784 "Metric for redistributed routes\n"
14785 "Default metric\n")
596c17ba 14786
37a87b8f
CS
14787DEFUN_YANG(
14788 bgp_redistribute_ipv4_ospf_rmap_metric,
14789 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
14790 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14791 "Redistribute information from another routing protocol\n"
14792 "Open Shortest Path First (OSPFv2)\n"
14793 "Non-main Kernel Routing Table\n"
14794 "Instance ID/Table ID\n"
14795 "Route map reference\n"
14796 "Pointer to route-map entries\n"
14797 "Metric for redistributed routes\n"
14798 "Default metric\n")
7c8ff89e 14799{
37a87b8f 14800 int idx_protocol = 1;
d62a17ae 14801 int idx_number = 2;
14802 int idx_word = 4;
14803 int idx_number_2 = 6;
37a87b8f
CS
14804 char base_xpath[XPATH_MAXLEN];
14805
14806 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14807 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14808 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14809 argv[idx_protocol]->text, argv[idx_number]->arg);
14810
14811 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 14812
37a87b8f
CS
14813 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
14814 argv[idx_word]->arg);
14815 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
14816 argv[idx_number_2]->arg);
d62a17ae 14817
37a87b8f 14818 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 14819}
14820
14821ALIAS_HIDDEN(
14822 bgp_redistribute_ipv4_ospf_rmap_metric,
14823 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
14824 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14825 "Redistribute information from another routing protocol\n"
14826 "Open Shortest Path First (OSPFv2)\n"
14827 "Non-main Kernel Routing Table\n"
14828 "Instance ID/Table ID\n"
14829 "Route map reference\n"
14830 "Pointer to route-map entries\n"
14831 "Metric for redistributed routes\n"
14832 "Default metric\n")
596c17ba 14833
37a87b8f
CS
14834DEFUN_YANG(
14835 bgp_redistribute_ipv4_ospf_metric_rmap,
14836 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
14837 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14838 "Redistribute information from another routing protocol\n"
14839 "Open Shortest Path First (OSPFv2)\n"
14840 "Non-main Kernel Routing Table\n"
14841 "Instance ID/Table ID\n"
14842 "Metric for redistributed routes\n"
14843 "Default metric\n"
14844 "Route map reference\n"
14845 "Pointer to route-map entries\n")
7c8ff89e 14846{
37a87b8f 14847 int idx_protocol = 1;
d62a17ae 14848 int idx_number = 2;
14849 int idx_number_2 = 4;
14850 int idx_word = 6;
37a87b8f
CS
14851 char base_xpath[XPATH_MAXLEN];
14852
14853 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14854 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14855 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14856 argv[idx_protocol]->text, argv[idx_number]->arg);
14857
14858 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 14859
37a87b8f
CS
14860 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
14861 argv[idx_number_2]->arg);
14862 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
14863 argv[idx_word]->arg);
d62a17ae 14864
37a87b8f 14865 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 14866}
14867
14868ALIAS_HIDDEN(
14869 bgp_redistribute_ipv4_ospf_metric_rmap,
14870 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
14871 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14872 "Redistribute information from another routing protocol\n"
14873 "Open Shortest Path First (OSPFv2)\n"
14874 "Non-main Kernel Routing Table\n"
14875 "Instance ID/Table ID\n"
14876 "Metric for redistributed routes\n"
14877 "Default metric\n"
14878 "Route map reference\n"
14879 "Pointer to route-map entries\n")
596c17ba 14880
37a87b8f
CS
14881DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
14882 no_bgp_redistribute_ipv4_ospf_cmd,
14883 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
14884 NO_STR
14885 "Redistribute information from another routing protocol\n"
14886 "Open Shortest Path First (OSPFv2)\n"
14887 "Non-main Kernel Routing Table\n"
14888 "Instance ID/Table ID\n"
14889 "Metric for redistributed routes\n"
14890 "Default metric\n"
14891 "Route map reference\n"
14892 "Pointer to route-map entries\n")
7c8ff89e 14893{
37a87b8f 14894 int idx_protocol = 2;
d62a17ae 14895 int idx_number = 3;
37a87b8f 14896 char base_xpath[XPATH_MAXLEN];
d62a17ae 14897
37a87b8f
CS
14898 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14899 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14900 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14901 argv[idx_protocol]->text, argv[idx_number]->arg);
14902
14903 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 14904
37a87b8f 14905 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 14906}
14907
14908ALIAS_HIDDEN(
14909 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 14910 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14911 NO_STR
14912 "Redistribute information from another routing protocol\n"
14913 "Open Shortest Path First (OSPFv2)\n"
14914 "Non-main Kernel Routing Table\n"
14915 "Instance ID/Table ID\n"
14916 "Metric for redistributed routes\n"
14917 "Default metric\n"
14918 "Route map reference\n"
14919 "Pointer to route-map entries\n")
596c17ba 14920
37a87b8f
CS
14921DEFUN_YANG (no_bgp_redistribute_ipv4,
14922 no_bgp_redistribute_ipv4_cmd,
14923 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
14924 NO_STR
14925 "Redistribute information from another routing protocol\n"
14926 FRR_IP_REDIST_HELP_STR_BGPD
14927 "Metric for redistributed routes\n"
14928 "Default metric\n"
14929 "Route map reference\n"
14930 "Pointer to route-map entries\n")
718e3744 14931{
d62a17ae 14932 int idx_protocol = 2;
37a87b8f 14933 char base_xpath[XPATH_MAXLEN];
d62a17ae 14934
37a87b8f
CS
14935 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14936 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
14937 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
14938 argv[idx_protocol]->text, "0");
14939
14940 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
14941
14942 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 14943}
14944
14945ALIAS_HIDDEN(
14946 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
14947 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 14948 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14949 NO_STR
14950 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14951 "Metric for redistributed routes\n"
14952 "Default metric\n"
14953 "Route map reference\n"
14954 "Pointer to route-map entries\n")
596c17ba 14955
37a87b8f
CS
14956DEFUN_YANG (bgp_redistribute_ipv6,
14957 bgp_redistribute_ipv6_cmd,
14958 "redistribute " FRR_IP6_REDIST_STR_BGPD,
14959 "Redistribute information from another routing protocol\n"
14960 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 14961{
d62a17ae 14962 int idx_protocol = 1;
37a87b8f 14963 char base_xpath[XPATH_MAXLEN];
718e3744 14964
37a87b8f
CS
14965 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14966 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
14967 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
14968 argv[idx_protocol]->text, "0");
14969
14970 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 14971
37a87b8f 14972 return nb_cli_apply_changes(vty, base_xpath);
718e3744 14973}
14974
37a87b8f
CS
14975DEFUN_YANG (bgp_redistribute_ipv6_rmap,
14976 bgp_redistribute_ipv6_rmap_cmd,
14977 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
14978 "Redistribute information from another routing protocol\n"
14979 FRR_IP6_REDIST_HELP_STR_BGPD
14980 "Route map reference\n"
14981 "Pointer to route-map entries\n")
718e3744 14982{
d62a17ae 14983 int idx_protocol = 1;
14984 int idx_word = 3;
37a87b8f
CS
14985 char base_xpath[XPATH_MAXLEN];
14986
14987 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
14988 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
14989 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
14990 argv[idx_protocol]->text, "0");
718e3744 14991
37a87b8f
CS
14992 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
14993 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
14994 argv[idx_word]->arg);
14995
14996 return nb_cli_apply_changes(vty, base_xpath);
718e3744 14997}
14998
37a87b8f 14999DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 15000 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15001 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15002 "Redistribute information from another routing protocol\n"
ab0181ee 15003 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15004 "Metric for redistributed routes\n"
15005 "Default metric\n")
15006{
d62a17ae 15007 int idx_protocol = 1;
15008 int idx_number = 3;
37a87b8f
CS
15009 char base_xpath[XPATH_MAXLEN];
15010
15011 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15012 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15013 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15014 argv[idx_protocol]->text, "0");
718e3744 15015
37a87b8f
CS
15016 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15017 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15018 argv[idx_number]->arg);
15019
15020 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15021}
15022
37a87b8f
CS
15023DEFUN_YANG(
15024 bgp_redistribute_ipv6_rmap_metric,
15025 bgp_redistribute_ipv6_rmap_metric_cmd,
15026 "redistribute " FRR_IP6_REDIST_STR_BGPD
15027 " route-map WORD metric (0-4294967295)",
15028 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15029 "Route map reference\n"
15030 "Pointer to route-map entries\n"
15031 "Metric for redistributed routes\n"
15032 "Default metric\n")
718e3744 15033{
d62a17ae 15034 int idx_protocol = 1;
15035 int idx_word = 3;
15036 int idx_number = 5;
37a87b8f
CS
15037 char base_xpath[XPATH_MAXLEN];
15038
15039 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15040 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15041 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15042 argv[idx_protocol]->text, "0");
718e3744 15043
37a87b8f
CS
15044 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15045 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15046 argv[idx_word]->arg);
15047 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15048 argv[idx_number]->arg);
15049
15050 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15051}
15052
37a87b8f
CS
15053DEFUN_YANG(
15054 bgp_redistribute_ipv6_metric_rmap,
15055 bgp_redistribute_ipv6_metric_rmap_cmd,
15056 "redistribute " FRR_IP6_REDIST_STR_BGPD
15057 " metric (0-4294967295) route-map WORD",
15058 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15059 "Metric for redistributed routes\n"
15060 "Default metric\n"
15061 "Route map reference\n"
15062 "Pointer to route-map entries\n")
718e3744 15063{
d62a17ae 15064 int idx_protocol = 1;
d62a17ae 15065 int idx_word = 5;
37a87b8f
CS
15066 int idx_number = 3;
15067 char base_xpath[XPATH_MAXLEN];
15068
15069 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15070 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15071 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15072 argv[idx_protocol]->text, "0");
718e3744 15073
37a87b8f
CS
15074 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15075 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15076 argv[idx_number]->arg);
15077 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15078 argv[idx_word]->arg);
15079
15080 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15081}
15082
37a87b8f
CS
15083DEFUN_YANG(
15084 no_bgp_redistribute_ipv6,
15085 no_bgp_redistribute_ipv6_cmd,
15086 "no redistribute " FRR_IP6_REDIST_STR_BGPD
15087 " [{metric (0-4294967295)|route-map WORD}]",
15088 NO_STR
15089 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15090 "Metric for redistributed routes\n"
15091 "Default metric\n"
15092 "Route map reference\n"
15093 "Pointer to route-map entries\n")
718e3744 15094{
d62a17ae 15095 int idx_protocol = 2;
37a87b8f 15096 char base_xpath[XPATH_MAXLEN];
718e3744 15097
37a87b8f
CS
15098 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15099 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15100 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15101 argv[idx_protocol]->text, "0");
15102
15103 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15104
15105 return nb_cli_apply_changes(vty, base_xpath);
15106}
718e3744 15107
37a87b8f
CS
15108void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
15109 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
15110{
15111 uint32_t instance = 0;
15112
15113 vty_out(vty, " redistribute %s",
15114 yang_dnode_get_string(dnode, "./route-type"));
15115 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
15116 vty_out(vty, " %d", instance);
15117 if (yang_dnode_exists(dnode, "./metric"))
15118 vty_out(vty, " metric %u",
15119 yang_dnode_get_uint32(dnode, "./metric"));
15120 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
15121 vty_out(vty, " route-map %s",
15122 yang_dnode_get_string(dnode, "./rmap-policy-import"));
15123 vty_out(vty, "\n");
d62a17ae 15124}
15125
dd65f45e
DL
15126static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15127 afi_t afi, safi_t safi)
d62a17ae 15128{
15129 int i;
15130
15131 /* Unicast redistribution only. */
15132 if (safi != SAFI_UNICAST)
2b791107 15133 return;
d62a17ae 15134
15135 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
15136 /* Redistribute BGP does not make sense. */
15137 if (i != ZEBRA_ROUTE_BGP) {
15138 struct list *red_list;
15139 struct listnode *node;
15140 struct bgp_redist *red;
15141
15142 red_list = bgp->redist[afi][i];
15143 if (!red_list)
15144 continue;
15145
15146 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 15147 /* "redistribute" configuration. */
15148 vty_out(vty, " redistribute %s",
15149 zebra_route_string(i));
15150 if (red->instance)
15151 vty_out(vty, " %d", red->instance);
15152 if (red->redist_metric_flag)
15153 vty_out(vty, " metric %u",
15154 red->redist_metric);
15155 if (red->rmap.name)
15156 vty_out(vty, " route-map %s",
15157 red->rmap.name);
15158 vty_out(vty, "\n");
15159 }
15160 }
15161 }
718e3744 15162}
6b0655a2 15163
dd65f45e
DL
15164/* peer-group helpers for config-write */
15165
15166static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
15167{
15168 if (!peer_group_active(peer)) {
15169 if (CHECK_FLAG(peer->flags_invert, flag))
15170 return !CHECK_FLAG(peer->flags, flag);
15171 else
15172 return !!CHECK_FLAG(peer->flags, flag);
15173 }
15174
15175 return !!CHECK_FLAG(peer->flags_override, flag);
15176}
15177
15178static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
15179 uint32_t flag)
15180{
15181 if (!peer_group_active(peer)) {
15182 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
15183 return !peer_af_flag_check(peer, afi, safi, flag);
15184 else
15185 return !!peer_af_flag_check(peer, afi, safi, flag);
15186 }
15187
15188 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
15189}
15190
15191static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
15192 uint8_t type, int direct)
15193{
15194 struct bgp_filter *filter;
15195
15196 if (peer_group_active(peer))
15197 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
15198 type);
15199
15200 filter = &peer->filter[afi][safi];
15201 switch (type) {
15202 case PEER_FT_DISTRIBUTE_LIST:
15203 return !!(filter->dlist[direct].name);
15204 case PEER_FT_FILTER_LIST:
15205 return !!(filter->aslist[direct].name);
15206 case PEER_FT_PREFIX_LIST:
15207 return !!(filter->plist[direct].name);
15208 case PEER_FT_ROUTE_MAP:
15209 return !!(filter->map[direct].name);
15210 case PEER_FT_UNSUPPRESS_MAP:
15211 return !!(filter->usmap.name);
7f7940e6
MK
15212 case PEER_FT_ADVERTISE_MAP:
15213 return !!(filter->advmap.aname
15214 && ((filter->advmap.condition == direct)
15215 && filter->advmap.cname));
dd65f45e
DL
15216 default:
15217 return false;
15218 }
15219}
15220
15221/* Return true if the addpath type is set for peer and different from
15222 * peer-group.
15223 */
3dc339cd
DA
15224static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
15225 safi_t safi)
dd65f45e
DL
15226{
15227 enum bgp_addpath_strat type, g_type;
15228
15229 type = peer->addpath_type[afi][safi];
15230
15231 if (type != BGP_ADDPATH_NONE) {
15232 if (peer_group_active(peer)) {
15233 g_type = peer->group->conf->addpath_type[afi][safi];
15234
15235 if (type != g_type)
3dc339cd 15236 return true;
dd65f45e 15237 else
3dc339cd 15238 return false;
dd65f45e
DL
15239 }
15240
3dc339cd 15241 return true;
dd65f45e
DL
15242 }
15243
3dc339cd 15244 return false;
dd65f45e
DL
15245}
15246
b9c7bc5a 15247/* This is part of the address-family block (unicast only) */
dd65f45e 15248static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
15249 afi_t afi)
15250{
b9c7bc5a 15251 int indent = 2;
ddb5b488 15252
8a066a70 15253 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
15254 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15255 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
15256 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
15257 bgp->vpn_policy[afi]
bb4f6190 15258 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
15259 else
15260 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
15261 bgp->vpn_policy[afi]
15262 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
15263 }
12a844a5
DS
15264 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15265 BGP_CONFIG_VRF_TO_VRF_IMPORT)
15266 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15267 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15268 return;
15269
e70e9f8e
PZ
15270 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15271 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
15272
15273 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
15274
15275 } else {
15276 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
15277 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
15278 bgp->vpn_policy[afi].tovpn_label);
15279 }
ddb5b488
PZ
15280 }
15281 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15282 BGP_VPN_POLICY_TOVPN_RD_SET)) {
15283 char buf[RD_ADDRSTRLEN];
b9c7bc5a 15284 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
15285 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
15286 sizeof(buf)));
15287 }
15288 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15289 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
15290
15291 char buf[PREFIX_STRLEN];
15292 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
15293 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
15294 sizeof(buf))) {
15295
b9c7bc5a
PZ
15296 vty_out(vty, "%*snexthop vpn export %s\n",
15297 indent, "", buf);
ddb5b488
PZ
15298 }
15299 }
15300 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
15301 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
15302 && ecommunity_cmp(
15303 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
15304 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
15305
15306 char *b = ecommunity_ecom2str(
15307 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
15308 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 15309 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
15310 XFREE(MTYPE_ECOMMUNITY_STR, b);
15311 } else {
15312 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
15313 char *b = ecommunity_ecom2str(
15314 bgp->vpn_policy[afi]
15315 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
15316 ECOMMUNITY_FORMAT_ROUTE_MAP,
15317 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 15318 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
15319 XFREE(MTYPE_ECOMMUNITY_STR, b);
15320 }
15321 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
15322 char *b = ecommunity_ecom2str(
15323 bgp->vpn_policy[afi]
15324 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
15325 ECOMMUNITY_FORMAT_ROUTE_MAP,
15326 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 15327 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
15328 XFREE(MTYPE_ECOMMUNITY_STR, b);
15329 }
15330 }
bb4f6190
DS
15331
15332 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 15333 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
15334 bgp->vpn_policy[afi]
15335 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 15336
301ad80a
PG
15337 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
15338 char *b = ecommunity_ecom2str(
15339 bgp->vpn_policy[afi]
15340 .import_redirect_rtlist,
15341 ECOMMUNITY_FORMAT_ROUTE_MAP,
15342 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 15343
9a659715
PG
15344 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
15345 != ECOMMUNITY_SIZE)
c6423c31 15346 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
15347 indent, "", b);
15348 else
15349 vty_out(vty, "%*srt redirect import %s\n",
15350 indent, "", b);
301ad80a
PG
15351 XFREE(MTYPE_ECOMMUNITY_STR, b);
15352 }
ddb5b488
PZ
15353}
15354
dd65f45e
DL
15355static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
15356 afi_t afi, safi_t safi)
15357{
15358 struct bgp_filter *filter;
15359 char *addr;
15360
15361 addr = peer->host;
15362 filter = &peer->filter[afi][safi];
15363
15364 /* distribute-list. */
15365 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
15366 FILTER_IN))
15367 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
15368 filter->dlist[FILTER_IN].name);
15369
15370 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
15371 FILTER_OUT))
15372 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
15373 filter->dlist[FILTER_OUT].name);
15374
15375 /* prefix-list. */
15376 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
15377 FILTER_IN))
15378 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
15379 filter->plist[FILTER_IN].name);
15380
15381 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
15382 FILTER_OUT))
15383 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
15384 filter->plist[FILTER_OUT].name);
15385
15386 /* route-map. */
15387 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
15388 vty_out(vty, " neighbor %s route-map %s in\n", addr,
15389 filter->map[RMAP_IN].name);
15390
15391 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
15392 RMAP_OUT))
15393 vty_out(vty, " neighbor %s route-map %s out\n", addr,
15394 filter->map[RMAP_OUT].name);
15395
15396 /* unsuppress-map */
15397 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
15398 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
15399 filter->usmap.name);
15400
7f7940e6
MK
15401 /* advertise-map : always applied in OUT direction*/
15402 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
15403 CONDITION_NON_EXIST))
15404 vty_out(vty,
15405 " neighbor %s advertise-map %s non-exist-map %s\n",
15406 addr, filter->advmap.aname, filter->advmap.cname);
15407
15408 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
15409 CONDITION_EXIST))
15410 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
15411 addr, filter->advmap.aname, filter->advmap.cname);
15412
dd65f45e
DL
15413 /* filter-list. */
15414 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
15415 FILTER_IN))
15416 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
15417 filter->aslist[FILTER_IN].name);
15418
15419 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
15420 FILTER_OUT))
15421 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
15422 filter->aslist[FILTER_OUT].name);
15423}
15424
15425/* BGP peer configuration display function. */
15426static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
15427 struct peer *peer)
15428{
15429 struct peer *g_peer = NULL;
15430 char buf[SU_ADDRSTRLEN];
15431 char *addr;
15432 int if_pg_printed = false;
15433 int if_ras_printed = false;
15434
15435 /* Skip dynamic neighbors. */
15436 if (peer_dynamic_neighbor(peer))
15437 return;
15438
15439 if (peer->conf_if)
15440 addr = peer->conf_if;
15441 else
15442 addr = peer->host;
15443
15444 /************************************
15445 ****** Global to the neighbor ******
15446 ************************************/
15447 if (peer->conf_if) {
15448 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
15449 vty_out(vty, " neighbor %s interface v6only", addr);
15450 else
15451 vty_out(vty, " neighbor %s interface", addr);
15452
15453 if (peer_group_active(peer)) {
15454 vty_out(vty, " peer-group %s", peer->group->name);
15455 if_pg_printed = true;
15456 } else if (peer->as_type == AS_SPECIFIED) {
15457 vty_out(vty, " remote-as %u", peer->as);
15458 if_ras_printed = true;
15459 } else if (peer->as_type == AS_INTERNAL) {
15460 vty_out(vty, " remote-as internal");
15461 if_ras_printed = true;
15462 } else if (peer->as_type == AS_EXTERNAL) {
15463 vty_out(vty, " remote-as external");
15464 if_ras_printed = true;
15465 }
15466
15467 vty_out(vty, "\n");
15468 }
15469
15470 /* remote-as and peer-group */
15471 /* peer is a member of a peer-group */
15472 if (peer_group_active(peer)) {
15473 g_peer = peer->group->conf;
15474
15475 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
15476 if (peer->as_type == AS_SPECIFIED) {
15477 vty_out(vty, " neighbor %s remote-as %u\n",
15478 addr, peer->as);
15479 } else if (peer->as_type == AS_INTERNAL) {
15480 vty_out(vty,
15481 " neighbor %s remote-as internal\n",
15482 addr);
15483 } else if (peer->as_type == AS_EXTERNAL) {
15484 vty_out(vty,
15485 " neighbor %s remote-as external\n",
15486 addr);
15487 }
15488 }
15489
15490 /* For swpX peers we displayed the peer-group
15491 * via 'neighbor swpX interface peer-group PGNAME' */
15492 if (!if_pg_printed)
15493 vty_out(vty, " neighbor %s peer-group %s\n", addr,
15494 peer->group->name);
15495 }
15496
15497 /* peer is NOT a member of a peer-group */
15498 else {
15499 /* peer is a peer-group, declare the peer-group */
15500 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
15501 vty_out(vty, " neighbor %s peer-group\n", addr);
15502 }
15503
15504 if (!if_ras_printed) {
15505 if (peer->as_type == AS_SPECIFIED) {
15506 vty_out(vty, " neighbor %s remote-as %u\n",
15507 addr, peer->as);
15508 } else if (peer->as_type == AS_INTERNAL) {
15509 vty_out(vty,
15510 " neighbor %s remote-as internal\n",
15511 addr);
15512 } else if (peer->as_type == AS_EXTERNAL) {
15513 vty_out(vty,
15514 " neighbor %s remote-as external\n",
15515 addr);
15516 }
15517 }
15518 }
15519
15520 /* local-as */
15521 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
15522 vty_out(vty, " neighbor %s local-as %u", addr,
15523 peer->change_local_as);
15524 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
15525 vty_out(vty, " no-prepend");
15526 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
15527 vty_out(vty, " replace-as");
15528 vty_out(vty, "\n");
15529 }
15530
15531 /* description */
15532 if (peer->desc) {
15533 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
15534 }
15535
15536 /* shutdown */
15537 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
15538 if (peer->tx_shutdown_message)
15539 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
15540 peer->tx_shutdown_message);
15541 else
15542 vty_out(vty, " neighbor %s shutdown\n", addr);
15543 }
15544
8336c896
DA
15545 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
15546 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
15547 peer->rtt_expected, peer->rtt_keepalive_conf);
15548
dd65f45e
DL
15549 /* bfd */
15550 if (peer->bfd_info) {
15551 if (!peer_group_active(peer) || !g_peer->bfd_info) {
15552 bgp_bfd_peer_config_write(vty, peer, addr);
15553 }
15554 }
15555
15556 /* password */
15557 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
15558 vty_out(vty, " neighbor %s password %s\n", addr,
15559 peer->password);
15560
15561 /* neighbor solo */
15562 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
15563 if (!peer_group_active(peer)) {
15564 vty_out(vty, " neighbor %s solo\n", addr);
15565 }
15566 }
15567
15568 /* BGP port */
15569 if (peer->port != BGP_PORT_DEFAULT) {
15570 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
15571 }
15572
15573 /* Local interface name */
15574 if (peer->ifname) {
15575 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
15576 }
15577
15578 /* passive */
15579 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
15580 vty_out(vty, " neighbor %s passive\n", addr);
15581
15582 /* ebgp-multihop */
15583 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
15584 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
15585 && peer->ttl == MAXTTL)) {
dd65f45e
DL
15586 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
15587 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
15588 peer->ttl);
15589 }
15590 }
15591
15592 /* ttl-security hops */
e2521429 15593 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
15594 if (!peer_group_active(peer)
15595 || g_peer->gtsm_hops != peer->gtsm_hops) {
15596 vty_out(vty, " neighbor %s ttl-security hops %d\n",
15597 addr, peer->gtsm_hops);
15598 }
15599 }
15600
15601 /* disable-connected-check */
15602 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
15603 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
15604
15605 /* enforce-first-as */
15606 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
15607 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
15608
15609 /* update-source */
15610 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
15611 if (peer->update_source)
15612 vty_out(vty, " neighbor %s update-source %s\n", addr,
15613 sockunion2str(peer->update_source, buf,
15614 SU_ADDRSTRLEN));
15615 else if (peer->update_if)
15616 vty_out(vty, " neighbor %s update-source %s\n", addr,
15617 peer->update_if);
15618 }
15619
15620 /* advertisement-interval */
15621 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
15622 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
15623 peer->routeadv);
15624
15625 /* timers */
15626 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
15627 vty_out(vty, " neighbor %s timers %u %u\n", addr,
15628 peer->keepalive, peer->holdtime);
15629
15630 /* timers connect */
15631 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
15632 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15633 peer->connect);
5d5393b9
DL
15634 /* need special-case handling for changed default values due to
15635 * config profile / version (because there is no "timers bgp connect"
15636 * command, we need to save this per-peer :/)
15637 */
15638 else if (!peer_group_active(peer) && !peer->connect &&
15639 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
15640 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15641 peer->bgp->default_connect_retry);
dd65f45e
DL
15642
15643 /* capability dynamic */
15644 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
15645 vty_out(vty, " neighbor %s capability dynamic\n", addr);
15646
15647 /* capability extended-nexthop */
15648 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
15649 if (!peer->conf_if) {
15650 if (CHECK_FLAG(peer->flags_invert,
15651 PEER_FLAG_CAPABILITY_ENHE))
15652 vty_out(vty,
15653 " no neighbor %s capability extended-nexthop\n",
15654 addr);
15655 else
15656 vty_out(vty,
15657 " neighbor %s capability extended-nexthop\n",
15658 addr);
15659 }
15660 }
15661
15662 /* dont-capability-negotiation */
15663 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
15664 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
15665
15666 /* override-capability */
15667 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
15668 vty_out(vty, " neighbor %s override-capability\n", addr);
15669
15670 /* strict-capability-match */
15671 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
15672 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
15673
15674 /* Sender side AS path loop detection. */
15675 if (peer->as_path_loop_detection)
15676 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
15677 addr);
cfd47646 15678
15679 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 15680 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 15681
15682 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 15683 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 15684 vty_out(vty,
15685 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
15686 } else if (CHECK_FLAG(
15687 peer->peer_gr_new_status_flag,
15688 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 15689 vty_out(vty,
15690 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
15691 } else if (
15692 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
15693 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
15694 && !(CHECK_FLAG(
15695 peer->peer_gr_new_status_flag,
15696 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
15697 vty_out(vty, " neighbor %s graceful-restart-disable\n",
15698 addr);
cfd47646 15699 }
15700 }
dd65f45e
DL
15701}
15702
15703/* BGP peer configuration display function. */
15704static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
15705 struct peer *peer, afi_t afi, safi_t safi)
15706{
15707 struct peer *g_peer = NULL;
15708 char *addr;
15709 bool flag_scomm, flag_secomm, flag_slcomm;
15710
15711 /* Skip dynamic neighbors. */
15712 if (peer_dynamic_neighbor(peer))
15713 return;
15714
15715 if (peer->conf_if)
15716 addr = peer->conf_if;
15717 else
15718 addr = peer->host;
15719
15720 /************************************
15721 ****** Per AF to the neighbor ******
15722 ************************************/
15723 if (peer_group_active(peer)) {
15724 g_peer = peer->group->conf;
15725
15726 /* If the peer-group is active but peer is not, print a 'no
15727 * activate' */
15728 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
15729 vty_out(vty, " no neighbor %s activate\n", addr);
15730 }
15731
15732 /* If the peer-group is not active but peer is, print an
15733 'activate' */
15734 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
15735 vty_out(vty, " neighbor %s activate\n", addr);
15736 }
15737 } else {
15738 if (peer->afc[afi][safi]) {
15739 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
15740 if (CHECK_FLAG(bgp->flags,
15741 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
15742 vty_out(vty, " neighbor %s activate\n",
15743 addr);
15744 }
15745 } else
15746 vty_out(vty, " neighbor %s activate\n", addr);
15747 } else {
15748 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
15749 if (!CHECK_FLAG(bgp->flags,
15750 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
15751 vty_out(vty,
15752 " no neighbor %s activate\n",
15753 addr);
15754 }
15755 }
15756 }
15757 }
15758
15759 /* addpath TX knobs */
15760 if (peergroup_af_addpath_check(peer, afi, safi)) {
15761 switch (peer->addpath_type[afi][safi]) {
15762 case BGP_ADDPATH_ALL:
15763 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
15764 addr);
15765 break;
15766 case BGP_ADDPATH_BEST_PER_AS:
15767 vty_out(vty,
15768 " neighbor %s addpath-tx-bestpath-per-AS\n",
15769 addr);
15770 break;
15771 case BGP_ADDPATH_MAX:
15772 case BGP_ADDPATH_NONE:
15773 break;
15774 }
15775 }
15776
15777 /* ORF capability. */
15778 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
15779 || peergroup_af_flag_check(peer, afi, safi,
15780 PEER_FLAG_ORF_PREFIX_RM)) {
15781 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
15782
15783 if (peergroup_af_flag_check(peer, afi, safi,
15784 PEER_FLAG_ORF_PREFIX_SM)
15785 && peergroup_af_flag_check(peer, afi, safi,
15786 PEER_FLAG_ORF_PREFIX_RM))
15787 vty_out(vty, " both");
15788 else if (peergroup_af_flag_check(peer, afi, safi,
15789 PEER_FLAG_ORF_PREFIX_SM))
15790 vty_out(vty, " send");
15791 else
15792 vty_out(vty, " receive");
15793 vty_out(vty, "\n");
15794 }
15795
dd65f45e
DL
15796 /* Route reflector client. */
15797 if (peergroup_af_flag_check(peer, afi, safi,
15798 PEER_FLAG_REFLECTOR_CLIENT)) {
15799 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
15800 }
15801
15802 /* next-hop-self force */
15803 if (peergroup_af_flag_check(peer, afi, safi,
15804 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
15805 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
15806 }
15807
15808 /* next-hop-self */
15809 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
15810 vty_out(vty, " neighbor %s next-hop-self\n", addr);
15811 }
15812
15813 /* remove-private-AS */
15814 if (peergroup_af_flag_check(peer, afi, safi,
15815 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
15816 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
15817 addr);
15818 }
15819
15820 else if (peergroup_af_flag_check(peer, afi, safi,
15821 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
15822 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
15823 addr);
15824 }
15825
15826 else if (peergroup_af_flag_check(peer, afi, safi,
15827 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
15828 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
15829 }
15830
15831 else if (peergroup_af_flag_check(peer, afi, safi,
15832 PEER_FLAG_REMOVE_PRIVATE_AS)) {
15833 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
15834 }
15835
15836 /* as-override */
15837 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
15838 vty_out(vty, " neighbor %s as-override\n", addr);
15839 }
15840
15841 /* send-community print. */
15842 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
15843 PEER_FLAG_SEND_COMMUNITY);
15844 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
15845 PEER_FLAG_SEND_EXT_COMMUNITY);
15846 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
15847 PEER_FLAG_SEND_LARGE_COMMUNITY);
15848
15849 if (flag_scomm && flag_secomm && flag_slcomm) {
15850 vty_out(vty, " no neighbor %s send-community all\n", addr);
15851 } else {
15852 if (flag_scomm)
15853 vty_out(vty, " no neighbor %s send-community\n", addr);
15854 if (flag_secomm)
15855 vty_out(vty,
15856 " no neighbor %s send-community extended\n",
15857 addr);
15858
15859 if (flag_slcomm)
15860 vty_out(vty, " no neighbor %s send-community large\n",
15861 addr);
15862 }
15863
15864 /* Default information */
15865 if (peergroup_af_flag_check(peer, afi, safi,
15866 PEER_FLAG_DEFAULT_ORIGINATE)) {
15867 vty_out(vty, " neighbor %s default-originate", addr);
15868
15869 if (peer->default_rmap[afi][safi].name)
15870 vty_out(vty, " route-map %s",
15871 peer->default_rmap[afi][safi].name);
15872
15873 vty_out(vty, "\n");
15874 }
15875
15876 /* Soft reconfiguration inbound. */
15877 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
15878 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
15879 addr);
15880 }
15881
15882 /* maximum-prefix. */
15883 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 15884 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
15885 peer->pmax[afi][safi]);
15886
15887 if (peer->pmax_threshold[afi][safi]
15888 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
15889 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
15890 if (peer_af_flag_check(peer, afi, safi,
15891 PEER_FLAG_MAX_PREFIX_WARNING))
15892 vty_out(vty, " warning-only");
15893 if (peer->pmax_restart[afi][safi])
15894 vty_out(vty, " restart %u",
15895 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
15896 if (peer_af_flag_check(peer, afi, safi,
15897 PEER_FLAG_MAX_PREFIX_FORCE))
15898 vty_out(vty, " force");
dd65f45e
DL
15899
15900 vty_out(vty, "\n");
15901 }
15902
fde246e8
DA
15903 /* maximum-prefix-out */
15904 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 15905 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
15906 addr, peer->pmax_out[afi][safi]);
15907
dd65f45e
DL
15908 /* Route server client. */
15909 if (peergroup_af_flag_check(peer, afi, safi,
15910 PEER_FLAG_RSERVER_CLIENT)) {
15911 vty_out(vty, " neighbor %s route-server-client\n", addr);
15912 }
15913
15914 /* Nexthop-local unchanged. */
15915 if (peergroup_af_flag_check(peer, afi, safi,
15916 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
15917 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
15918 }
15919
15920 /* allowas-in <1-10> */
15921 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
15922 if (peer_af_flag_check(peer, afi, safi,
15923 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
15924 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
15925 } else if (peer->allowas_in[afi][safi] == 3) {
15926 vty_out(vty, " neighbor %s allowas-in\n", addr);
15927 } else {
15928 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
15929 peer->allowas_in[afi][safi]);
15930 }
15931 }
15932
15933 /* weight */
15934 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
15935 vty_out(vty, " neighbor %s weight %lu\n", addr,
15936 peer->weight[afi][safi]);
15937
15938 /* Filter. */
15939 bgp_config_write_filter(vty, peer, afi, safi);
15940
15941 /* atribute-unchanged. */
15942 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
15943 || (safi != SAFI_EVPN
15944 && peer_af_flag_check(peer, afi, safi,
15945 PEER_FLAG_NEXTHOP_UNCHANGED))
15946 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
15947
15948 if (!peer_group_active(peer)
15949 || peergroup_af_flag_check(peer, afi, safi,
15950 PEER_FLAG_AS_PATH_UNCHANGED)
15951 || peergroup_af_flag_check(peer, afi, safi,
15952 PEER_FLAG_NEXTHOP_UNCHANGED)
15953 || peergroup_af_flag_check(peer, afi, safi,
15954 PEER_FLAG_MED_UNCHANGED)) {
15955
15956 vty_out(vty,
15957 " neighbor %s attribute-unchanged%s%s%s\n",
15958 addr,
15959 peer_af_flag_check(peer, afi, safi,
15960 PEER_FLAG_AS_PATH_UNCHANGED)
15961 ? " as-path"
15962 : "",
15963 peer_af_flag_check(peer, afi, safi,
15964 PEER_FLAG_NEXTHOP_UNCHANGED)
15965 ? " next-hop"
15966 : "",
15967 peer_af_flag_check(peer, afi, safi,
15968 PEER_FLAG_MED_UNCHANGED)
15969 ? " med"
15970 : "");
15971 }
15972 }
15973}
15974
15975/* Address family based peer configuration display. */
15976static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
15977 safi_t safi)
15978{
15979 struct peer *peer;
15980 struct peer_group *group;
15981 struct listnode *node, *nnode;
15982
15983
15984 vty_frame(vty, " !\n address-family ");
15985 if (afi == AFI_IP) {
15986 if (safi == SAFI_UNICAST)
15987 vty_frame(vty, "ipv4 unicast");
15988 else if (safi == SAFI_LABELED_UNICAST)
15989 vty_frame(vty, "ipv4 labeled-unicast");
15990 else if (safi == SAFI_MULTICAST)
15991 vty_frame(vty, "ipv4 multicast");
15992 else if (safi == SAFI_MPLS_VPN)
15993 vty_frame(vty, "ipv4 vpn");
15994 else if (safi == SAFI_ENCAP)
15995 vty_frame(vty, "ipv4 encap");
15996 else if (safi == SAFI_FLOWSPEC)
15997 vty_frame(vty, "ipv4 flowspec");
15998 } else if (afi == AFI_IP6) {
15999 if (safi == SAFI_UNICAST)
16000 vty_frame(vty, "ipv6 unicast");
16001 else if (safi == SAFI_LABELED_UNICAST)
16002 vty_frame(vty, "ipv6 labeled-unicast");
16003 else if (safi == SAFI_MULTICAST)
16004 vty_frame(vty, "ipv6 multicast");
16005 else if (safi == SAFI_MPLS_VPN)
16006 vty_frame(vty, "ipv6 vpn");
16007 else if (safi == SAFI_ENCAP)
16008 vty_frame(vty, "ipv6 encap");
16009 else if (safi == SAFI_FLOWSPEC)
16010 vty_frame(vty, "ipv6 flowspec");
16011 } else if (afi == AFI_L2VPN) {
16012 if (safi == SAFI_EVPN)
16013 vty_frame(vty, "l2vpn evpn");
16014 }
16015 vty_frame(vty, "\n");
16016
16017 bgp_config_write_distance(vty, bgp, afi, safi);
16018
16019 bgp_config_write_network(vty, bgp, afi, safi);
16020
16021 bgp_config_write_redistribute(vty, bgp, afi, safi);
16022
8a4e7fe6
DA
16023 /* BGP flag dampening. */
16024 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
16025 bgp_config_write_damp(vty, afi, safi);
16026
dd65f45e
DL
16027 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16028 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16029
16030 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16031 /* Skip dynamic neighbors. */
16032 if (peer_dynamic_neighbor(peer))
16033 continue;
16034
16035 /* Do not display doppelganger peers */
16036 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16037 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16038 }
16039
16040 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16041 bgp_config_write_table_map(vty, bgp, afi, safi);
16042
16043 if (safi == SAFI_EVPN)
16044 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16045
16046 if (safi == SAFI_FLOWSPEC)
16047 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16048
16049 if (safi == SAFI_UNICAST) {
16050 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16051 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16052 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16053
16054 vty_out(vty, " export vpn\n");
16055 }
16056 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16057 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16058
16059 vty_out(vty, " import vpn\n");
16060 }
16061 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16062 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16063 char *name;
16064
16065 for (ALL_LIST_ELEMENTS_RO(
16066 bgp->vpn_policy[afi].import_vrf, node,
16067 name))
16068 vty_out(vty, " import vrf %s\n", name);
16069 }
16070 }
16071
16072 vty_endframe(vty, " exit-address-family\n");
16073}
16074
16075int bgp_config_write(struct vty *vty)
16076{
16077 struct bgp *bgp;
16078 struct peer_group *group;
16079 struct peer *peer;
16080 struct listnode *node, *nnode;
16081 struct listnode *mnode, *mnnode;
16082
16083 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16084 vty_out(vty, "bgp route-map delay-timer %u\n",
16085 bm->rmap_update_timer);
16086
d70583f7
D
16087 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16088 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16089 if (bm->v_update_delay != bm->v_establish_wait)
16090 vty_out(vty, " %d", bm->v_establish_wait);
16091 vty_out(vty, "\n");
16092 }
16093
05bd726c 16094 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16095 vty_out(vty, "bgp graceful-shutdown\n");
16096
c163f297
DS
16097 /* No-RIB (Zebra) option flag configuration */
16098 if (bgp_option_check(BGP_OPT_NO_FIB))
16099 vty_out(vty, "bgp no-rib\n");
16100
dd65f45e
DL
16101 /* BGP configuration. */
16102 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
16103
16104 /* skip all auto created vrf as they dont have user config */
16105 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
16106 continue;
16107
16108 /* Router bgp ASN */
16109 vty_out(vty, "router bgp %u", bgp->as);
16110
16111 if (bgp->name)
16112 vty_out(vty, " %s %s",
16113 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
16114 ? "view" : "vrf", bgp->name);
16115 vty_out(vty, "\n");
16116
16117 /* BGP fast-external-failover. */
16118 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
16119 vty_out(vty, " no bgp fast-external-failover\n");
16120
16121 /* BGP router ID. */
16122 if (bgp->router_id_static.s_addr != 0)
23d0a753
DA
16123 vty_out(vty, " bgp router-id %pI4\n",
16124 &bgp->router_id_static);
dd65f45e
DL
16125
16126 /* BGP log-neighbor-changes. */
892fedb6 16127 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 16128 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 16129 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
16130 CHECK_FLAG(bgp->flags,
16131 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
16132 ? ""
16133 : "no ");
16134
16135 /* BGP configuration. */
892fedb6 16136 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
16137 vty_out(vty, " bgp always-compare-med\n");
16138
16139 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
16140 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
16141 != SAVE_BGP_EBGP_REQUIRES_POLICY)
16142 vty_out(vty, " %sbgp ebgp-requires-policy\n",
16143 CHECK_FLAG(bgp->flags,
16144 BGP_FLAG_EBGP_REQUIRES_POLICY)
16145 ? ""
16146 : "no ");
dd65f45e
DL
16147
16148 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 16149 if (bgp->reject_as_sets)
dd65f45e
DL
16150 vty_out(vty, " bgp reject-as-sets\n");
16151
16152 /* BGP default ipv4-unicast. */
892fedb6 16153 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
16154 vty_out(vty, " no bgp default ipv4-unicast\n");
16155
16156 /* BGP default local-preference. */
16157 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
16158 vty_out(vty, " bgp default local-preference %u\n",
16159 bgp->default_local_pref);
16160
16161 /* BGP default show-hostname */
892fedb6 16162 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 16163 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 16164 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 16165 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
16166 ? ""
16167 : "no ");
16168
aef999a2
DA
16169 /* BGP default show-nexthop-hostname */
16170 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16171 != SAVE_BGP_SHOW_HOSTNAME)
16172 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
16173 CHECK_FLAG(bgp->flags,
16174 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16175 ? ""
16176 : "no ");
16177
dd65f45e
DL
16178 /* BGP default subgroup-pkt-queue-max. */
16179 if (bgp->default_subgroup_pkt_queue_max
16180 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
16181 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
16182 bgp->default_subgroup_pkt_queue_max);
16183
16184 /* BGP client-to-client reflection. */
892fedb6 16185 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
16186 vty_out(vty, " no bgp client-to-client reflection\n");
16187
16188 /* BGP cluster ID. */
16189 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
16190 vty_out(vty, " bgp cluster-id %pI4\n",
16191 &bgp->cluster_id);
dd65f45e
DL
16192
16193 /* Disable ebgp connected nexthop check */
892fedb6 16194 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
16195 vty_out(vty,
16196 " bgp disable-ebgp-connected-route-check\n");
16197
16198 /* Confederation identifier*/
16199 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
16200 vty_out(vty, " bgp confederation identifier %u\n",
16201 bgp->confed_id);
16202
16203 /* Confederation peer */
16204 if (bgp->confed_peers_cnt > 0) {
16205 int i;
16206
16207 vty_out(vty, " bgp confederation peers");
16208
16209 for (i = 0; i < bgp->confed_peers_cnt; i++)
16210 vty_out(vty, " %u", bgp->confed_peers[i]);
16211
16212 vty_out(vty, "\n");
16213 }
16214
16215 /* BGP deterministic-med. */
892fedb6 16216 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 16217 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 16218 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
16219 CHECK_FLAG(bgp->flags,
16220 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
16221 ? ""
16222 : "no ");
16223
16224 /* BGP update-delay. */
16225 bgp_config_write_update_delay(vty, bgp);
16226
16227 if (bgp->v_maxmed_onstartup
16228 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
16229 vty_out(vty, " bgp max-med on-startup %u",
16230 bgp->v_maxmed_onstartup);
16231 if (bgp->maxmed_onstartup_value
16232 != BGP_MAXMED_VALUE_DEFAULT)
16233 vty_out(vty, " %u",
16234 bgp->maxmed_onstartup_value);
16235 vty_out(vty, "\n");
16236 }
16237 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
16238 vty_out(vty, " bgp max-med administrative");
16239 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
16240 vty_out(vty, " %u", bgp->maxmed_admin_value);
16241 vty_out(vty, "\n");
16242 }
16243
16244 /* write quanta */
16245 bgp_config_write_wpkt_quanta(vty, bgp);
16246 /* read quanta */
16247 bgp_config_write_rpkt_quanta(vty, bgp);
16248
16249 /* coalesce time */
16250 bgp_config_write_coalesce_time(vty, bgp);
16251
05bd726c 16252 /* BGP per-instance graceful-shutdown */
16253 /* BGP-wide settings and per-instance settings are mutually
16254 * exclusive.
16255 */
16256 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16257 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
16258 vty_out(vty, " bgp graceful-shutdown\n");
16259
dd65f45e
DL
16260 /* BGP graceful-restart. */
16261 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
16262 vty_out(vty,
16263 " bgp graceful-restart stalepath-time %u\n",
16264 bgp->stalepath_time);
cfd47646 16265
dd65f45e
DL
16266 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
16267 vty_out(vty, " bgp graceful-restart restart-time %u\n",
16268 bgp->restart_time);
cfd47646 16269
16270 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
16271 vty_out(vty,
16272 " bgp graceful-restart select-defer-time %u\n",
16273 bgp->select_defer_time);
16274
16275 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
16276 vty_out(vty, " bgp graceful-restart\n");
16277
cfd47646 16278 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
16279 vty_out(vty, " bgp graceful-restart-disable\n");
16280
dd65f45e 16281 /* BGP graceful-restart Preserve State F bit. */
892fedb6 16282 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
16283 vty_out(vty,
16284 " bgp graceful-restart preserve-fw-state\n");
16285
dc95985f 16286 /* Stale timer for RIB */
16287 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
16288 vty_out(vty,
16289 " bgp graceful-restart rib-stale-time %u\n",
16290 bgp->rib_stale_time);
16291
dd65f45e 16292 /* BGP bestpath method. */
892fedb6 16293 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 16294 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 16295 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
16296 vty_out(vty, " bgp bestpath as-path confed\n");
16297
892fedb6
DA
16298 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
16299 if (CHECK_FLAG(bgp->flags,
16300 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
16301 vty_out(vty,
16302 " bgp bestpath as-path multipath-relax as-set\n");
16303 } else {
16304 vty_out(vty,
16305 " bgp bestpath as-path multipath-relax\n");
16306 }
16307 }
16308
892fedb6 16309 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
16310 vty_out(vty,
16311 " bgp route-reflector allow-outbound-policy\n");
16312 }
892fedb6 16313 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 16314 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
16315 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
16316 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 16317 vty_out(vty, " bgp bestpath med");
892fedb6 16318 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 16319 vty_out(vty, " confed");
892fedb6
DA
16320 if (CHECK_FLAG(bgp->flags,
16321 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
16322 vty_out(vty, " missing-as-worst");
16323 vty_out(vty, "\n");
16324 }
16325
f7e1c681 16326 /* Link bandwidth handling. */
16327 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
16328 vty_out(vty, " bgp bestpath bandwidth ignore\n");
16329 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
16330 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
16331 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
16332 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
16333
dd65f45e 16334 /* BGP network import check. */
892fedb6 16335 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 16336 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 16337 vty_out(vty, " %sbgp network import-check\n",
892fedb6 16338 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
16339 ? ""
16340 : "no ");
16341
16342 /* BGP timers configuration. */
5d5393b9
DL
16343 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
16344 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
16345 vty_out(vty, " timers bgp %u %u\n",
16346 bgp->default_keepalive, bgp->default_holdtime);
16347
16348 /* peer-group */
16349 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16350 bgp_config_write_peer_global(vty, bgp, group->conf);
16351 }
16352
16353 /* Normal neighbor configuration. */
16354 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16355 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16356 bgp_config_write_peer_global(vty, bgp, peer);
16357 }
16358
16359 /* listen range and limit for dynamic BGP neighbors */
16360 bgp_config_write_listen(vty, bgp);
16361
16362 /*
16363 * BGP default autoshutdown neighbors
16364 *
16365 * This must be placed after any peer and peer-group
16366 * configuration, to avoid setting all peers to shutdown after
16367 * a daemon restart, which is undesired behavior. (see #2286)
16368 */
16369 if (bgp->autoshutdown)
16370 vty_out(vty, " bgp default shutdown\n");
16371
9cf59432
DS
16372 /* BGP instance administrative shutdown */
16373 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
16374 vty_out(vty, " bgp shutdown\n");
16375
dd65f45e
DL
16376 /* IPv4 unicast configuration. */
16377 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
16378
16379 /* IPv4 multicast configuration. */
16380 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
16381
16382 /* IPv4 labeled-unicast configuration. */
16383 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
16384
16385 /* IPv4 VPN configuration. */
16386 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
16387
16388 /* ENCAPv4 configuration. */
16389 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
16390
16391 /* FLOWSPEC v4 configuration. */
16392 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
16393
16394 /* IPv6 unicast configuration. */
16395 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
16396
16397 /* IPv6 multicast configuration. */
16398 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
16399
16400 /* IPv6 labeled-unicast configuration. */
16401 bgp_config_write_family(vty, bgp, AFI_IP6,
16402 SAFI_LABELED_UNICAST);
16403
16404 /* IPv6 VPN configuration. */
16405 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
16406
16407 /* ENCAPv6 configuration. */
16408 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
16409
16410 /* FLOWSPEC v6 configuration. */
16411 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
16412
16413 /* EVPN configuration. */
16414 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
16415
16416 hook_call(bgp_inst_config_write, bgp, vty);
16417
49e5a4a0 16418#ifdef ENABLE_BGP_VNC
dd65f45e
DL
16419 bgp_rfapi_cfg_write(vty, bgp);
16420#endif
16421
16422 vty_out(vty, "!\n");
16423 }
16424 return 0;
16425}
16426
ddb5b488 16427
718e3744 16428/* BGP node structure. */
d62a17ae 16429static struct cmd_node bgp_node = {
f4b8291f 16430 .name = "bgp",
62b346ee 16431 .node = BGP_NODE,
24389580 16432 .parent_node = CONFIG_NODE,
62b346ee 16433 .prompt = "%s(config-router)# ",
612c2c15 16434 .config_write = bgp_config_write,
718e3744 16435};
16436
d62a17ae 16437static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 16438 .name = "bgp ipv4 unicast",
62b346ee 16439 .node = BGP_IPV4_NODE,
24389580 16440 .parent_node = BGP_NODE,
62b346ee 16441 .prompt = "%s(config-router-af)# ",
718e3744 16442};
16443
d62a17ae 16444static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 16445 .name = "bgp ipv4 multicast",
62b346ee 16446 .node = BGP_IPV4M_NODE,
24389580 16447 .parent_node = BGP_NODE,
62b346ee 16448 .prompt = "%s(config-router-af)# ",
718e3744 16449};
16450
d62a17ae 16451static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 16452 .name = "bgp ipv4 labeled unicast",
62b346ee 16453 .node = BGP_IPV4L_NODE,
24389580 16454 .parent_node = BGP_NODE,
62b346ee 16455 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
16456};
16457
d62a17ae 16458static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 16459 .name = "bgp ipv6",
62b346ee 16460 .node = BGP_IPV6_NODE,
24389580 16461 .parent_node = BGP_NODE,
62b346ee 16462 .prompt = "%s(config-router-af)# ",
718e3744 16463};
16464
d62a17ae 16465static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 16466 .name = "bgp ipv6 multicast",
62b346ee 16467 .node = BGP_IPV6M_NODE,
24389580 16468 .parent_node = BGP_NODE,
62b346ee 16469 .prompt = "%s(config-router-af)# ",
25ffbdc1 16470};
16471
d62a17ae 16472static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 16473 .name = "bgp ipv6 labeled unicast",
62b346ee 16474 .node = BGP_IPV6L_NODE,
24389580 16475 .parent_node = BGP_NODE,
62b346ee 16476 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
16477};
16478
62b346ee 16479static struct cmd_node bgp_vpnv4_node = {
f4b8291f 16480 .name = "bgp vpnv4",
62b346ee 16481 .node = BGP_VPNV4_NODE,
24389580 16482 .parent_node = BGP_NODE,
62b346ee 16483 .prompt = "%s(config-router-af)# ",
62b346ee 16484};
6b0655a2 16485
62b346ee 16486static struct cmd_node bgp_vpnv6_node = {
f4b8291f 16487 .name = "bgp vpnv6",
62b346ee 16488 .node = BGP_VPNV6_NODE,
24389580 16489 .parent_node = BGP_NODE,
62b346ee 16490 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 16491};
8ecd3266 16492
62b346ee 16493static struct cmd_node bgp_evpn_node = {
f4b8291f 16494 .name = "bgp evpn",
62b346ee 16495 .node = BGP_EVPN_NODE,
24389580 16496 .parent_node = BGP_NODE,
62b346ee 16497 .prompt = "%s(config-router-evpn)# ",
62b346ee 16498};
4e0b7b6d 16499
62b346ee 16500static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 16501 .name = "bgp evpn vni",
62b346ee 16502 .node = BGP_EVPN_VNI_NODE,
24389580 16503 .parent_node = BGP_EVPN_NODE,
62b346ee 16504 .prompt = "%s(config-router-af-vni)# ",
62b346ee 16505};
90e60aa7 16506
62b346ee 16507static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 16508 .name = "bgp ipv4 flowspec",
62b346ee 16509 .node = BGP_FLOWSPECV4_NODE,
24389580 16510 .parent_node = BGP_NODE,
62b346ee 16511 .prompt = "%s(config-router-af)# ",
62b346ee 16512};
7c40bf39 16513
62b346ee 16514static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 16515 .name = "bgp ipv6 flowspec",
62b346ee 16516 .node = BGP_FLOWSPECV6_NODE,
24389580 16517 .parent_node = BGP_NODE,
62b346ee 16518 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 16519};
7c40bf39 16520
d62a17ae 16521static void community_list_vty(void);
1f8ae70b 16522
d62a17ae 16523static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 16524{
d62a17ae 16525 struct bgp *bgp;
16526 struct peer *peer;
d62a17ae 16527 struct listnode *lnbgp, *lnpeer;
b8a815e5 16528
d62a17ae 16529 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16530 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
16531 /* only provide suggestions on the appropriate input
16532 * token type,
16533 * they'll otherwise show up multiple times */
16534 enum cmd_token_type match_type;
16535 char *name = peer->host;
d48ed3e0 16536
d62a17ae 16537 if (peer->conf_if) {
16538 match_type = VARIABLE_TKN;
16539 name = peer->conf_if;
16540 } else if (strchr(peer->host, ':'))
16541 match_type = IPV6_TKN;
16542 else
16543 match_type = IPV4_TKN;
d48ed3e0 16544
d62a17ae 16545 if (token->type != match_type)
16546 continue;
d48ed3e0 16547
d62a17ae 16548 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
16549 }
d62a17ae 16550 }
b8a815e5
DL
16551}
16552
16553static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 16554 {.varname = "neighbor", .completions = bgp_ac_neighbor},
16555 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 16556 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 16557 {.completions = NULL}};
16558
47a306a0
DS
16559static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
16560{
16561 struct bgp *bgp;
16562 struct peer_group *group;
16563 struct listnode *lnbgp, *lnpeer;
16564
16565 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16566 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
16567 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
16568 group->name));
16569 }
16570}
16571
16572static const struct cmd_variable_handler bgp_var_peergroup[] = {
16573 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
16574 {.completions = NULL} };
16575
d62a17ae 16576void bgp_vty_init(void)
16577{
16578 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 16579 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 16580
16581 /* Install bgp top node. */
612c2c15
DL
16582 install_node(&bgp_node);
16583 install_node(&bgp_ipv4_unicast_node);
16584 install_node(&bgp_ipv4_multicast_node);
16585 install_node(&bgp_ipv4_labeled_unicast_node);
16586 install_node(&bgp_ipv6_unicast_node);
16587 install_node(&bgp_ipv6_multicast_node);
16588 install_node(&bgp_ipv6_labeled_unicast_node);
16589 install_node(&bgp_vpnv4_node);
16590 install_node(&bgp_vpnv6_node);
16591 install_node(&bgp_evpn_node);
16592 install_node(&bgp_evpn_vni_node);
16593 install_node(&bgp_flowspecv4_node);
16594 install_node(&bgp_flowspecv6_node);
d62a17ae 16595
16596 /* Install default VTY commands to new nodes. */
16597 install_default(BGP_NODE);
16598 install_default(BGP_IPV4_NODE);
16599 install_default(BGP_IPV4M_NODE);
16600 install_default(BGP_IPV4L_NODE);
16601 install_default(BGP_IPV6_NODE);
16602 install_default(BGP_IPV6M_NODE);
16603 install_default(BGP_IPV6L_NODE);
16604 install_default(BGP_VPNV4_NODE);
16605 install_default(BGP_VPNV6_NODE);
7c40bf39 16606 install_default(BGP_FLOWSPECV4_NODE);
16607 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 16608 install_default(BGP_EVPN_NODE);
16609 install_default(BGP_EVPN_VNI_NODE);
16610
8029b216
AK
16611 /* "bgp local-mac" hidden commands. */
16612 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
16613 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
16614
d62a17ae 16615 /* bgp route-map delay-timer commands. */
16616 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
16617 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16618
d70583f7
D
16619 /* global bgp update-delay command */
16620 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
16621 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
16622
05bd726c 16623 /* global bgp graceful-shutdown command */
16624 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
16625 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
16626
d62a17ae 16627 /* Dummy commands (Currently not supported) */
16628 install_element(BGP_NODE, &no_synchronization_cmd);
16629 install_element(BGP_NODE, &no_auto_summary_cmd);
16630
16631 /* "router bgp" commands. */
16632 install_element(CONFIG_NODE, &router_bgp_cmd);
16633
16634 /* "no router bgp" commands. */
16635 install_element(CONFIG_NODE, &no_router_bgp_cmd);
16636
16637 /* "bgp router-id" commands. */
16638 install_element(BGP_NODE, &bgp_router_id_cmd);
16639 install_element(BGP_NODE, &no_bgp_router_id_cmd);
16640
16641 /* "bgp cluster-id" commands. */
16642 install_element(BGP_NODE, &bgp_cluster_id_cmd);
16643 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
16644
c163f297
DS
16645 /* "bgp no-rib" commands. */
16646 install_element(CONFIG_NODE, &bgp_norib_cmd);
16647 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
16648
d62a17ae 16649 /* "bgp confederation" commands. */
16650 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
16651 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
16652
16653 /* "bgp confederation peers" commands. */
16654 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
16655 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
16656
16657 /* bgp max-med command */
16658 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
16659 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
16660 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
16661 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
16662 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
16663
16664 /* bgp disable-ebgp-connected-nh-check */
16665 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
16666 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
16667
16668 /* bgp update-delay command */
16669 install_element(BGP_NODE, &bgp_update_delay_cmd);
16670 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 16671
16672 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 16673 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 16674
16675 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
16676 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
16677
16678 /* "maximum-paths" commands. */
16679 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
16680 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
16681 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
16682 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
16683 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
16684 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
16685 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
16686 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
16687 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
16688 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
16689 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16690 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
16691 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
16692 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16693 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
16694
39edabac
PG
16695 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
16696 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
16697 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
16698 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16699 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 16700 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
16701 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
16702 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
16703 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16704 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
16705
16706 /* "timers bgp" commands. */
16707 install_element(BGP_NODE, &bgp_timers_cmd);
16708 install_element(BGP_NODE, &no_bgp_timers_cmd);
16709
16710 /* route-map delay-timer commands - per instance for backwards compat.
16711 */
16712 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
16713 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16714
16715 /* "bgp client-to-client reflection" commands */
16716 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
16717 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
16718
16719 /* "bgp always-compare-med" commands */
16720 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
16721 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
16722
9dac9fc8
DA
16723 /* bgp ebgp-requires-policy */
16724 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
16725 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
16726
fb29348a
DA
16727 /* bgp reject-as-sets */
16728 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
16729 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
16730
d62a17ae 16731 /* "bgp deterministic-med" commands */
16732 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
16733 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
16734
055679e9 16735 /* "bgp graceful-restart" command */
36235319
QY
16736 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
16737 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 16738
16739 /* "bgp graceful-restart-disable" command */
36235319
QY
16740 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
16741 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 16742
16743 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
16744 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
16745 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 16746
16747 /* "neighbor a:b:c:d graceful-restart-disable" command */
16748 install_element(BGP_NODE,
16749 &bgp_neighbor_graceful_restart_disable_set_cmd);
16750 install_element(BGP_NODE,
16751 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
16752
16753 /* "neighbor a:b:c:d graceful-restart-helper" command */
16754 install_element(BGP_NODE,
16755 &bgp_neighbor_graceful_restart_helper_set_cmd);
16756 install_element(BGP_NODE,
16757 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
16758
d62a17ae 16759 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
16760 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
16761 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
16762 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 16763 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 16764 install_element(BGP_NODE,
16765 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 16766 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
16767 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
16768
d6e3c15b 16769 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
16770 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 16771 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
16772 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 16773
7f323236
DW
16774 /* "bgp graceful-shutdown" commands */
16775 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
16776 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
16777
d62a17ae 16778 /* "bgp fast-external-failover" commands */
16779 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
16780 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
16781
d62a17ae 16782 /* "bgp bestpath compare-routerid" commands */
16783 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
16784 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
16785
16786 /* "bgp bestpath as-path ignore" commands */
16787 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
16788 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
16789
16790 /* "bgp bestpath as-path confed" commands */
16791 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
16792 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
16793
16794 /* "bgp bestpath as-path multipath-relax" commands */
16795 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
16796 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
16797
16798 /* "bgp log-neighbor-changes" commands */
16799 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
16800 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
16801
16802 /* "bgp bestpath med" commands */
16803 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
16804 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
16805
f7e1c681 16806 /* "bgp bestpath bandwidth" commands */
16807 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 16808 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 16809
d62a17ae 16810 /* "no bgp default ipv4-unicast" commands. */
16811 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
16812 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
16813
16814 /* "bgp network import-check" commands. */
16815 install_element(BGP_NODE, &bgp_network_import_check_cmd);
16816 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
16817 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
16818
16819 /* "bgp default local-preference" commands. */
16820 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
16821 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
16822
16823 /* bgp default show-hostname */
16824 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
16825 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
16826
aef999a2
DA
16827 /* bgp default show-nexthop-hostname */
16828 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
16829 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
16830
d62a17ae 16831 /* "bgp default subgroup-pkt-queue-max" commands. */
16832 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
16833 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
16834
16835 /* bgp ibgp-allow-policy-mods command */
16836 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
16837 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
16838
16839 /* "bgp listen limit" commands. */
16840 install_element(BGP_NODE, &bgp_listen_limit_cmd);
16841 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
16842
16843 /* "bgp listen range" commands. */
16844 install_element(BGP_NODE, &bgp_listen_range_cmd);
16845 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
16846
8175f54a 16847 /* "bgp default shutdown" command */
f26845f9 16848 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
16849
16850 /* "bgp shutdown" commands */
16851 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 16852 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 16853 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 16854 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 16855
d62a17ae 16856 /* "neighbor remote-as" commands. */
16857 install_element(BGP_NODE, &neighbor_remote_as_cmd);
16858 install_element(BGP_NODE, &neighbor_interface_config_cmd);
16859 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
16860 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
16861 install_element(BGP_NODE,
16862 &neighbor_interface_v6only_config_remote_as_cmd);
16863 install_element(BGP_NODE, &no_neighbor_cmd);
16864 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
16865
16866 /* "neighbor peer-group" commands. */
16867 install_element(BGP_NODE, &neighbor_peer_group_cmd);
16868 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
16869 install_element(BGP_NODE,
16870 &no_neighbor_interface_peer_group_remote_as_cmd);
16871
16872 /* "neighbor local-as" commands. */
16873 install_element(BGP_NODE, &neighbor_local_as_cmd);
16874 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
16875 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
16876 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
16877
16878 /* "neighbor solo" commands. */
16879 install_element(BGP_NODE, &neighbor_solo_cmd);
16880 install_element(BGP_NODE, &no_neighbor_solo_cmd);
16881
16882 /* "neighbor password" commands. */
16883 install_element(BGP_NODE, &neighbor_password_cmd);
16884 install_element(BGP_NODE, &no_neighbor_password_cmd);
16885
16886 /* "neighbor activate" commands. */
16887 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
16888 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
16889 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
16890 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
16891 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
16892 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
16893 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
16894 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
16895 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 16896 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
16897 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 16898 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
16899
16900 /* "no neighbor activate" commands. */
16901 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
16902 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
16903 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
16904 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
16905 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
16906 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
16907 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
16908 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
16909 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 16910 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
16911 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 16912 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
16913
16914 /* "neighbor peer-group" set commands. */
16915 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
16916 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16917 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
16918 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16919 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
16920 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
16921 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16922 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 16923 install_element(BGP_FLOWSPECV4_NODE,
16924 &neighbor_set_peer_group_hidden_cmd);
16925 install_element(BGP_FLOWSPECV6_NODE,
16926 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 16927
16928 /* "no neighbor peer-group unset" commands. */
16929 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
16930 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16931 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16932 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16933 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16934 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16935 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16936 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 16937 install_element(BGP_FLOWSPECV4_NODE,
16938 &no_neighbor_set_peer_group_hidden_cmd);
16939 install_element(BGP_FLOWSPECV6_NODE,
16940 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 16941
16942 /* "neighbor softreconfiguration inbound" commands.*/
16943 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
16944 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
16945 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
16946 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16947 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
16948 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16949 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
16950 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16951 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
16952 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16953 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
16954 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16955 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
16956 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16957 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
16958 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16959 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
16960 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 16961 install_element(BGP_FLOWSPECV4_NODE,
16962 &neighbor_soft_reconfiguration_cmd);
16963 install_element(BGP_FLOWSPECV4_NODE,
16964 &no_neighbor_soft_reconfiguration_cmd);
16965 install_element(BGP_FLOWSPECV6_NODE,
16966 &neighbor_soft_reconfiguration_cmd);
16967 install_element(BGP_FLOWSPECV6_NODE,
16968 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
16969 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
16970 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 16971
16972 /* "neighbor attribute-unchanged" commands. */
16973 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
16974 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
16975 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
16976 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
16977 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
16978 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
16979 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
16980 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
16981 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
16982 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
16983 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
16984 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
16985 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
16986 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
16987 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
16988 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
16989 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
16990 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
16991
16992 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
16993 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
16994
16995 /* "nexthop-local unchanged" commands */
16996 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
16997 install_element(BGP_IPV6_NODE,
16998 &no_neighbor_nexthop_local_unchanged_cmd);
16999
17000 /* "neighbor next-hop-self" commands. */
17001 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
17002 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
17003 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
17004 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
17005 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
17006 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
17007 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
17008 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
17009 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
17010 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
17011 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
17012 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
17013 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
17014 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
17015 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
17016 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
17017 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
17018 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
17019 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
17020 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 17021
17022 /* "neighbor next-hop-self force" commands. */
17023 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
17024 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
17025 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17026 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17027 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
17028 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17029 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17030 install_element(BGP_IPV4_NODE,
17031 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17032 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
17033 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17034 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17035 install_element(BGP_IPV4M_NODE,
17036 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17037 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
17038 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17039 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17040 install_element(BGP_IPV4L_NODE,
17041 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17042 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
17043 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17044 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17045 install_element(BGP_IPV6_NODE,
17046 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17047 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
17048 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17049 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17050 install_element(BGP_IPV6M_NODE,
17051 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17052 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
17053 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17054 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17055 install_element(BGP_IPV6L_NODE,
17056 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17057 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
17058 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17059 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17060 install_element(BGP_VPNV4_NODE,
17061 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17062 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
17063 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17064 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17065 install_element(BGP_VPNV6_NODE,
17066 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
17067 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
17068 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 17069
17070 /* "neighbor as-override" commands. */
17071 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
17072 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
17073 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
17074 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
17075 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
17076 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
17077 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
17078 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
17079 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
17080 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
17081 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
17082 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
17083 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
17084 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
17085 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
17086 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
17087 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
17088 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
17089
17090 /* "neighbor remove-private-AS" commands. */
17091 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
17092 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
17093 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
17094 install_element(BGP_NODE,
17095 &no_neighbor_remove_private_as_all_hidden_cmd);
17096 install_element(BGP_NODE,
17097 &neighbor_remove_private_as_replace_as_hidden_cmd);
17098 install_element(BGP_NODE,
17099 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
17100 install_element(BGP_NODE,
17101 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
17102 install_element(
17103 BGP_NODE,
17104 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
17105 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
17106 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
17107 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
17108 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17109 install_element(BGP_IPV4_NODE,
17110 &neighbor_remove_private_as_replace_as_cmd);
17111 install_element(BGP_IPV4_NODE,
17112 &no_neighbor_remove_private_as_replace_as_cmd);
17113 install_element(BGP_IPV4_NODE,
17114 &neighbor_remove_private_as_all_replace_as_cmd);
17115 install_element(BGP_IPV4_NODE,
17116 &no_neighbor_remove_private_as_all_replace_as_cmd);
17117 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
17118 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
17119 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
17120 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
17121 install_element(BGP_IPV4M_NODE,
17122 &neighbor_remove_private_as_replace_as_cmd);
17123 install_element(BGP_IPV4M_NODE,
17124 &no_neighbor_remove_private_as_replace_as_cmd);
17125 install_element(BGP_IPV4M_NODE,
17126 &neighbor_remove_private_as_all_replace_as_cmd);
17127 install_element(BGP_IPV4M_NODE,
17128 &no_neighbor_remove_private_as_all_replace_as_cmd);
17129 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
17130 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
17131 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
17132 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
17133 install_element(BGP_IPV4L_NODE,
17134 &neighbor_remove_private_as_replace_as_cmd);
17135 install_element(BGP_IPV4L_NODE,
17136 &no_neighbor_remove_private_as_replace_as_cmd);
17137 install_element(BGP_IPV4L_NODE,
17138 &neighbor_remove_private_as_all_replace_as_cmd);
17139 install_element(BGP_IPV4L_NODE,
17140 &no_neighbor_remove_private_as_all_replace_as_cmd);
17141 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
17142 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
17143 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
17144 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
17145 install_element(BGP_IPV6_NODE,
17146 &neighbor_remove_private_as_replace_as_cmd);
17147 install_element(BGP_IPV6_NODE,
17148 &no_neighbor_remove_private_as_replace_as_cmd);
17149 install_element(BGP_IPV6_NODE,
17150 &neighbor_remove_private_as_all_replace_as_cmd);
17151 install_element(BGP_IPV6_NODE,
17152 &no_neighbor_remove_private_as_all_replace_as_cmd);
17153 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
17154 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
17155 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
17156 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
17157 install_element(BGP_IPV6M_NODE,
17158 &neighbor_remove_private_as_replace_as_cmd);
17159 install_element(BGP_IPV6M_NODE,
17160 &no_neighbor_remove_private_as_replace_as_cmd);
17161 install_element(BGP_IPV6M_NODE,
17162 &neighbor_remove_private_as_all_replace_as_cmd);
17163 install_element(BGP_IPV6M_NODE,
17164 &no_neighbor_remove_private_as_all_replace_as_cmd);
17165 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
17166 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
17167 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
17168 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
17169 install_element(BGP_IPV6L_NODE,
17170 &neighbor_remove_private_as_replace_as_cmd);
17171 install_element(BGP_IPV6L_NODE,
17172 &no_neighbor_remove_private_as_replace_as_cmd);
17173 install_element(BGP_IPV6L_NODE,
17174 &neighbor_remove_private_as_all_replace_as_cmd);
17175 install_element(BGP_IPV6L_NODE,
17176 &no_neighbor_remove_private_as_all_replace_as_cmd);
17177 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
17178 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
17179 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
17180 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17181 install_element(BGP_VPNV4_NODE,
17182 &neighbor_remove_private_as_replace_as_cmd);
17183 install_element(BGP_VPNV4_NODE,
17184 &no_neighbor_remove_private_as_replace_as_cmd);
17185 install_element(BGP_VPNV4_NODE,
17186 &neighbor_remove_private_as_all_replace_as_cmd);
17187 install_element(BGP_VPNV4_NODE,
17188 &no_neighbor_remove_private_as_all_replace_as_cmd);
17189 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
17190 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
17191 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
17192 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
17193 install_element(BGP_VPNV6_NODE,
17194 &neighbor_remove_private_as_replace_as_cmd);
17195 install_element(BGP_VPNV6_NODE,
17196 &no_neighbor_remove_private_as_replace_as_cmd);
17197 install_element(BGP_VPNV6_NODE,
17198 &neighbor_remove_private_as_all_replace_as_cmd);
17199 install_element(BGP_VPNV6_NODE,
17200 &no_neighbor_remove_private_as_all_replace_as_cmd);
17201
17202 /* "neighbor send-community" commands.*/
17203 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
17204 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
17205 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
17206 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
17207 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
17208 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
17209 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
17210 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
17211 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
17212 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
17213 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
17214 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
17215 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
17216 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
17217 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
17218 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
17219 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
17220 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
17221 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
17222 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
17223 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
17224 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
17225 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
17226 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
17227 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
17228 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
17229 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
17230 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
17231 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
17232 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
17233 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
17234 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
17235 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
17236 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
17237 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
17238 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
17239
17240 /* "neighbor route-reflector" commands.*/
17241 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
17242 install_element(BGP_NODE,
17243 &no_neighbor_route_reflector_client_hidden_cmd);
17244 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
17245 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
17246 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
17247 install_element(BGP_IPV4M_NODE,
17248 &no_neighbor_route_reflector_client_cmd);
17249 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
17250 install_element(BGP_IPV4L_NODE,
17251 &no_neighbor_route_reflector_client_cmd);
17252 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
17253 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
17254 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
17255 install_element(BGP_IPV6M_NODE,
17256 &no_neighbor_route_reflector_client_cmd);
17257 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
17258 install_element(BGP_IPV6L_NODE,
17259 &no_neighbor_route_reflector_client_cmd);
17260 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
17261 install_element(BGP_VPNV4_NODE,
17262 &no_neighbor_route_reflector_client_cmd);
17263 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
17264 install_element(BGP_VPNV6_NODE,
17265 &no_neighbor_route_reflector_client_cmd);
7c40bf39 17266 install_element(BGP_FLOWSPECV4_NODE,
17267 &neighbor_route_reflector_client_cmd);
17268 install_element(BGP_FLOWSPECV4_NODE,
17269 &no_neighbor_route_reflector_client_cmd);
17270 install_element(BGP_FLOWSPECV6_NODE,
17271 &neighbor_route_reflector_client_cmd);
17272 install_element(BGP_FLOWSPECV6_NODE,
17273 &no_neighbor_route_reflector_client_cmd);
d62a17ae 17274 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
17275 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
17276
17277 /* "neighbor route-server" commands.*/
17278 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
17279 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
17280 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
17281 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
17282 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
17283 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
17284 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
17285 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
17286 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
17287 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
17288 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
17289 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
17290 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
17291 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
17292 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
17293 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
17294 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
17295 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
17296 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
17297 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 17298 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
17299 install_element(BGP_FLOWSPECV4_NODE,
17300 &no_neighbor_route_server_client_cmd);
17301 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
17302 install_element(BGP_FLOWSPECV6_NODE,
17303 &no_neighbor_route_server_client_cmd);
d62a17ae 17304
17305 /* "neighbor addpath-tx-all-paths" commands.*/
17306 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
17307 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
17308 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
17309 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17310 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
17311 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17312 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
17313 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17314 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
17315 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17316 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
17317 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17318 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
17319 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17320 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
17321 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17322 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
17323 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17324
17325 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
17326 install_element(BGP_NODE,
17327 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
17328 install_element(BGP_NODE,
17329 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
17330 install_element(BGP_IPV4_NODE,
17331 &neighbor_addpath_tx_bestpath_per_as_cmd);
17332 install_element(BGP_IPV4_NODE,
17333 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17334 install_element(BGP_IPV4M_NODE,
17335 &neighbor_addpath_tx_bestpath_per_as_cmd);
17336 install_element(BGP_IPV4M_NODE,
17337 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17338 install_element(BGP_IPV4L_NODE,
17339 &neighbor_addpath_tx_bestpath_per_as_cmd);
17340 install_element(BGP_IPV4L_NODE,
17341 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17342 install_element(BGP_IPV6_NODE,
17343 &neighbor_addpath_tx_bestpath_per_as_cmd);
17344 install_element(BGP_IPV6_NODE,
17345 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17346 install_element(BGP_IPV6M_NODE,
17347 &neighbor_addpath_tx_bestpath_per_as_cmd);
17348 install_element(BGP_IPV6M_NODE,
17349 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17350 install_element(BGP_IPV6L_NODE,
17351 &neighbor_addpath_tx_bestpath_per_as_cmd);
17352 install_element(BGP_IPV6L_NODE,
17353 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17354 install_element(BGP_VPNV4_NODE,
17355 &neighbor_addpath_tx_bestpath_per_as_cmd);
17356 install_element(BGP_VPNV4_NODE,
17357 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17358 install_element(BGP_VPNV6_NODE,
17359 &neighbor_addpath_tx_bestpath_per_as_cmd);
17360 install_element(BGP_VPNV6_NODE,
17361 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17362
2b31007c
RZ
17363 /* "neighbor sender-as-path-loop-detection" commands. */
17364 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
17365 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
17366
d62a17ae 17367 /* "neighbor passive" commands. */
17368 install_element(BGP_NODE, &neighbor_passive_cmd);
17369 install_element(BGP_NODE, &no_neighbor_passive_cmd);
17370
17371
17372 /* "neighbor shutdown" commands. */
17373 install_element(BGP_NODE, &neighbor_shutdown_cmd);
17374 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
17375 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
17376 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
17377 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
17378 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 17379
17380 /* "neighbor capability extended-nexthop" commands.*/
17381 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
17382 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
17383
17384 /* "neighbor capability orf prefix-list" commands.*/
17385 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
17386 install_element(BGP_NODE,
17387 &no_neighbor_capability_orf_prefix_hidden_cmd);
17388 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
17389 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
17390 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
17391 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
17392 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
17393 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
17394 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
17395 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
17396 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
17397 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
17398 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
17399 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
17400
17401 /* "neighbor capability dynamic" commands.*/
17402 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
17403 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
17404
17405 /* "neighbor dont-capability-negotiate" commands. */
17406 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
17407 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
17408
17409 /* "neighbor ebgp-multihop" commands. */
17410 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
17411 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
17412 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
17413
17414 /* "neighbor disable-connected-check" commands. */
17415 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
17416 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
17417
47cbc09b
PM
17418 /* "neighbor enforce-first-as" commands. */
17419 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
17420 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
17421
d62a17ae 17422 /* "neighbor description" commands. */
17423 install_element(BGP_NODE, &neighbor_description_cmd);
17424 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 17425 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 17426
17427 /* "neighbor update-source" commands. "*/
17428 install_element(BGP_NODE, &neighbor_update_source_cmd);
17429 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
17430
17431 /* "neighbor default-originate" commands. */
17432 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
17433 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
17434 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
17435 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
17436 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
17437 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
17438 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
17439 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
17440 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
17441 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
17442 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
17443 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
17444 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
17445 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
17446 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
17447 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
17448 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
17449 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
17450 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
17451 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
17452 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
17453
17454 /* "neighbor port" commands. */
17455 install_element(BGP_NODE, &neighbor_port_cmd);
17456 install_element(BGP_NODE, &no_neighbor_port_cmd);
17457
17458 /* "neighbor weight" commands. */
17459 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
17460 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
17461
17462 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
17463 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
17464 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
17465 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
17466 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
17467 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
17468 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
17469 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
17470 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
17471 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
17472 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
17473 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
17474 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
17475 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
17476 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
17477 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
17478
17479 /* "neighbor override-capability" commands. */
17480 install_element(BGP_NODE, &neighbor_override_capability_cmd);
17481 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
17482
17483 /* "neighbor strict-capability-match" commands. */
17484 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
17485 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
17486
17487 /* "neighbor timers" commands. */
17488 install_element(BGP_NODE, &neighbor_timers_cmd);
17489 install_element(BGP_NODE, &no_neighbor_timers_cmd);
17490
17491 /* "neighbor timers connect" commands. */
17492 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
17493 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
17494
17495 /* "neighbor advertisement-interval" commands. */
17496 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
17497 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
17498
17499 /* "neighbor interface" commands. */
17500 install_element(BGP_NODE, &neighbor_interface_cmd);
17501 install_element(BGP_NODE, &no_neighbor_interface_cmd);
17502
17503 /* "neighbor distribute" commands. */
17504 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
17505 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
17506 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
17507 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
17508 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
17509 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
17510 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
17511 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
17512 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
17513 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
17514 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
17515 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
17516 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
17517 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
17518 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
17519 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
17520 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
17521 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
17522
17523 /* "neighbor prefix-list" commands. */
17524 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
17525 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
17526 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
17527 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
17528 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
17529 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
17530 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
17531 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
17532 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
17533 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
17534 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
17535 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
17536 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
17537 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
17538 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
17539 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
17540 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
17541 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 17542 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
17543 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
17544 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
17545 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 17546
17547 /* "neighbor filter-list" commands. */
17548 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
17549 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
17550 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
17551 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
17552 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
17553 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
17554 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
17555 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
17556 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
17557 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
17558 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
17559 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
17560 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
17561 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
17562 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
17563 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
17564 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
17565 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 17566 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
17567 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
17568 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
17569 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 17570
17571 /* "neighbor route-map" commands. */
17572 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
17573 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
17574 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
17575 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
17576 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
17577 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
17578 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
17579 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
17580 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
17581 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
17582 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
17583 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
17584 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
17585 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
17586 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
17587 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
17588 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
17589 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 17590 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
17591 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
17592 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
17593 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
17594 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
17595 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 17596
17597 /* "neighbor unsuppress-map" commands. */
17598 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
17599 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
17600 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
17601 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
17602 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
17603 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
17604 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
17605 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
17606 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
17607 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
17608 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
17609 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
17610 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
17611 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
17612 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
17613 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
17614 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
17615 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
17616
7f7940e6
MK
17617 /* "neighbor advertise-map" commands. */
17618 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 17619 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 17620 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 17621 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 17622 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 17623 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 17624 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 17625 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 17626 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 17627
fde246e8
DA
17628 /* neighbor maximum-prefix-out commands. */
17629 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
17630 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
17631 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
17632 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17633 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
17634 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17635 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
17636 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17637 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
17638 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17639 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
17640 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17641 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
17642 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17643 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
17644 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17645 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
17646 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17647
d62a17ae 17648 /* "neighbor maximum-prefix" commands. */
17649 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
17650 install_element(BGP_NODE,
17651 &neighbor_maximum_prefix_threshold_hidden_cmd);
17652 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
17653 install_element(BGP_NODE,
17654 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
17655 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
17656 install_element(BGP_NODE,
17657 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
17658 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
17659 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
17660 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17661 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17662 install_element(BGP_IPV4_NODE,
17663 &neighbor_maximum_prefix_threshold_warning_cmd);
17664 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17665 install_element(BGP_IPV4_NODE,
17666 &neighbor_maximum_prefix_threshold_restart_cmd);
17667 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
17668 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
17669 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17670 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
17671 install_element(BGP_IPV4M_NODE,
17672 &neighbor_maximum_prefix_threshold_warning_cmd);
17673 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
17674 install_element(BGP_IPV4M_NODE,
17675 &neighbor_maximum_prefix_threshold_restart_cmd);
17676 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
17677 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
17678 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17679 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
17680 install_element(BGP_IPV4L_NODE,
17681 &neighbor_maximum_prefix_threshold_warning_cmd);
17682 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
17683 install_element(BGP_IPV4L_NODE,
17684 &neighbor_maximum_prefix_threshold_restart_cmd);
17685 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
17686 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
17687 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17688 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17689 install_element(BGP_IPV6_NODE,
17690 &neighbor_maximum_prefix_threshold_warning_cmd);
17691 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17692 install_element(BGP_IPV6_NODE,
17693 &neighbor_maximum_prefix_threshold_restart_cmd);
17694 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
17695 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
17696 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17697 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
17698 install_element(BGP_IPV6M_NODE,
17699 &neighbor_maximum_prefix_threshold_warning_cmd);
17700 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
17701 install_element(BGP_IPV6M_NODE,
17702 &neighbor_maximum_prefix_threshold_restart_cmd);
17703 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
17704 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
17705 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17706 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
17707 install_element(BGP_IPV6L_NODE,
17708 &neighbor_maximum_prefix_threshold_warning_cmd);
17709 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
17710 install_element(BGP_IPV6L_NODE,
17711 &neighbor_maximum_prefix_threshold_restart_cmd);
17712 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
17713 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
17714 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17715 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17716 install_element(BGP_VPNV4_NODE,
17717 &neighbor_maximum_prefix_threshold_warning_cmd);
17718 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17719 install_element(BGP_VPNV4_NODE,
17720 &neighbor_maximum_prefix_threshold_restart_cmd);
17721 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
17722 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
17723 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17724 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17725 install_element(BGP_VPNV6_NODE,
17726 &neighbor_maximum_prefix_threshold_warning_cmd);
17727 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17728 install_element(BGP_VPNV6_NODE,
17729 &neighbor_maximum_prefix_threshold_restart_cmd);
17730 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
17731
17732 /* "neighbor allowas-in" */
17733 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
17734 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
17735 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
17736 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
17737 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
17738 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
17739 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
17740 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
17741 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
17742 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
17743 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
17744 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
17745 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
17746 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
17747 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
17748 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
17749 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
17750 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
17751 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
17752 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
17753
17754 /* address-family commands. */
17755 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
17756 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 17757#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 17758 install_element(BGP_NODE, &address_family_vpnv4_cmd);
17759 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 17760#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 17761
d62a17ae 17762 install_element(BGP_NODE, &address_family_evpn_cmd);
17763
17764 /* "exit-address-family" command. */
17765 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
17766 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
17767 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
17768 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
17769 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
17770 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
17771 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
17772 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 17773 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
17774 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 17775 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
17776
17777 /* "clear ip bgp commands" */
17778 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
17779
17780 /* clear ip bgp prefix */
17781 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
17782 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
17783 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
17784
17785 /* "show [ip] bgp summary" commands. */
17786 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 17787 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 17788 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 17789 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 17790 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
17791 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 17792 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
17793
17794 /* "show [ip] bgp neighbors" commands. */
17795 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
17796
36235319 17797 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 17798
d62a17ae 17799 /* "show [ip] bgp peer-group" commands. */
17800 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
17801
17802 /* "show [ip] bgp paths" commands. */
17803 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
17804
17805 /* "show [ip] bgp community" commands. */
17806 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
17807
17808 /* "show ip bgp large-community" commands. */
17809 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
17810 /* "show [ip] bgp attribute-info" commands. */
17811 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 17812 /* "show [ip] bgp route-leak" command */
17813 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 17814
17815 /* "redistribute" commands. */
17816 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
17817 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
17818 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
17819 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
17820 install_element(BGP_NODE,
17821 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
17822 install_element(BGP_NODE,
17823 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
17824 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
17825 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
17826 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
17827 install_element(BGP_NODE,
17828 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
17829 install_element(BGP_NODE,
17830 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
17831 install_element(BGP_NODE,
17832 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
17833 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
17834 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
17835 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
17836 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
17837 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
17838 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
17839 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
17840 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
17841 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
17842 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
17843 install_element(BGP_IPV4_NODE,
17844 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
17845 install_element(BGP_IPV4_NODE,
17846 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
17847 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
17848 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
17849 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
17850 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
17851 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
17852 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
17853
b9c7bc5a
PZ
17854 /* import|export vpn [route-map WORD] */
17855 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
17856 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 17857
12a844a5
DS
17858 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
17859 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
17860
d62a17ae 17861 /* ttl_security commands */
17862 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
17863 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
17864
17865 /* "show [ip] bgp memory" commands. */
17866 install_element(VIEW_NODE, &show_bgp_memory_cmd);
17867
acf71666
MK
17868 /* "show bgp martian next-hop" */
17869 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
17870
48ecf8f5
DS
17871 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
17872
d62a17ae 17873 /* "show [ip] bgp views" commands. */
17874 install_element(VIEW_NODE, &show_bgp_views_cmd);
17875
17876 /* "show [ip] bgp vrfs" commands. */
17877 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
17878
17879 /* Community-list. */
17880 community_list_vty();
ddb5b488
PZ
17881
17882 /* vpn-policy commands */
b9c7bc5a
PZ
17883 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
17884 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
17885 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
17886 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
17887 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
17888 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
17889 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
17890 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
17891 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
17892 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
17893 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
17894 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 17895
301ad80a
PG
17896 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
17897 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
17898
b9c7bc5a
PZ
17899 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
17900 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
17901 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
17902 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
17903 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
17904 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
17905 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
17906 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
17907 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
17908 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 17909}
6b0655a2 17910
718e3744 17911#include "memory.h"
17912#include "bgp_regex.h"
17913#include "bgp_clist.h"
17914#include "bgp_ecommunity.h"
17915
17916/* VTY functions. */
17917
17918/* Direction value to string conversion. */
d62a17ae 17919static const char *community_direct_str(int direct)
17920{
17921 switch (direct) {
17922 case COMMUNITY_DENY:
17923 return "deny";
17924 case COMMUNITY_PERMIT:
17925 return "permit";
17926 default:
17927 return "unknown";
17928 }
718e3744 17929}
17930
17931/* Display error string. */
d62a17ae 17932static void community_list_perror(struct vty *vty, int ret)
17933{
17934 switch (ret) {
17935 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
17936 vty_out(vty, "%% Can't find community-list\n");
17937 break;
17938 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
17939 vty_out(vty, "%% Malformed community-list value\n");
17940 break;
17941 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
17942 vty_out(vty,
17943 "%% Community name conflict, previously defined as standard community\n");
17944 break;
17945 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
17946 vty_out(vty,
17947 "%% Community name conflict, previously defined as expanded community\n");
17948 break;
17949 }
718e3744 17950}
17951
5bf15956
DW
17952/* "community-list" keyword help string. */
17953#define COMMUNITY_LIST_STR "Add a community list entry\n"
17954
7336e101
SP
17955/*community-list standard */
17956DEFUN (community_list_standard,
17957 bgp_community_list_standard_cmd,
2f8cc0e5 17958 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17959 BGP_STR
718e3744 17960 COMMUNITY_LIST_STR
17961 "Community list number (standard)\n"
5bf15956 17962 "Add an standard community-list entry\n"
718e3744 17963 "Community list name\n"
2f8cc0e5
DA
17964 "Sequence number of an entry\n"
17965 "Sequence number\n"
718e3744 17966 "Specify community to reject\n"
17967 "Specify community to accept\n"
17968 COMMUNITY_VAL_STR)
17969{
d62a17ae 17970 char *cl_name_or_number = NULL;
2f8cc0e5 17971 char *seq = NULL;
d62a17ae 17972 int direct = 0;
17973 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 17974 int idx = 0;
7336e101 17975
2f8cc0e5
DA
17976 argv_find(argv, argc, "(1-4294967295)", &idx);
17977 if (idx)
17978 seq = argv[idx]->arg;
17979
17980 idx = 0;
d62a17ae 17981 argv_find(argv, argc, "(1-99)", &idx);
17982 argv_find(argv, argc, "WORD", &idx);
17983 cl_name_or_number = argv[idx]->arg;
17984 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17985 : COMMUNITY_DENY;
17986 argv_find(argv, argc, "AA:NN", &idx);
17987 char *str = argv_concat(argv, argc, idx);
42f914d4 17988
2f8cc0e5
DA
17989 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17990 direct, style);
42f914d4 17991
d62a17ae 17992 XFREE(MTYPE_TMP, str);
42f914d4 17993
d62a17ae 17994 if (ret < 0) {
17995 /* Display error string. */
17996 community_list_perror(vty, ret);
17997 return CMD_WARNING_CONFIG_FAILED;
17998 }
42f914d4 17999
d62a17ae 18000 return CMD_SUCCESS;
718e3744 18001}
18002
7336e101
SP
18003DEFUN (no_community_list_standard_all,
18004 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 18005 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18006 NO_STR
18007 BGP_STR
18008 COMMUNITY_LIST_STR
18009 "Community list number (standard)\n"
18010 "Add an standard community-list entry\n"
18011 "Community list name\n"
2f8cc0e5
DA
18012 "Sequence number of an entry\n"
18013 "Sequence number\n"
7336e101
SP
18014 "Specify community to reject\n"
18015 "Specify community to accept\n"
18016 COMMUNITY_VAL_STR)
718e3744 18017{
d62a17ae 18018 char *cl_name_or_number = NULL;
174b5cb9 18019 char *str = NULL;
d62a17ae 18020 int direct = 0;
18021 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 18022 char *seq = NULL;
d62a17ae 18023 int idx = 0;
7336e101 18024
2f8cc0e5
DA
18025 argv_find(argv, argc, "(1-4294967295)", &idx);
18026 if (idx)
18027 seq = argv[idx]->arg;
18028
18029 idx = 0;
174b5cb9
DA
18030 argv_find(argv, argc, "permit", &idx);
18031 argv_find(argv, argc, "deny", &idx);
18032
18033 if (idx) {
18034 direct = argv_find(argv, argc, "permit", &idx)
18035 ? COMMUNITY_PERMIT
18036 : COMMUNITY_DENY;
18037
18038 idx = 0;
18039 argv_find(argv, argc, "AA:NN", &idx);
18040 str = argv_concat(argv, argc, idx);
18041 }
18042
18043 idx = 0;
d62a17ae 18044 argv_find(argv, argc, "(1-99)", &idx);
18045 argv_find(argv, argc, "WORD", &idx);
18046 cl_name_or_number = argv[idx]->arg;
42f914d4 18047
2f8cc0e5 18048 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 18049 direct, style);
42f914d4 18050
d62a17ae 18051 XFREE(MTYPE_TMP, str);
daf9ddbb 18052
d62a17ae 18053 if (ret < 0) {
18054 community_list_perror(vty, ret);
18055 return CMD_WARNING_CONFIG_FAILED;
18056 }
42f914d4 18057
d62a17ae 18058 return CMD_SUCCESS;
718e3744 18059}
7336e101 18060
174b5cb9
DA
18061ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
18062 "no bgp community-list <(1-99)|standard WORD>",
18063 NO_STR BGP_STR COMMUNITY_LIST_STR
18064 "Community list number (standard)\n"
18065 "Add an standard community-list entry\n"
18066 "Community list name\n")
18067
7336e101
SP
18068/*community-list expanded */
18069DEFUN (community_list_expanded_all,
18070 bgp_community_list_expanded_all_cmd,
2f8cc0e5 18071 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18072 BGP_STR
18073 COMMUNITY_LIST_STR
718e3744 18074 "Community list number (expanded)\n"
5bf15956 18075 "Add an expanded community-list entry\n"
718e3744 18076 "Community list name\n"
2f8cc0e5
DA
18077 "Sequence number of an entry\n"
18078 "Sequence number\n"
718e3744 18079 "Specify community to reject\n"
18080 "Specify community to accept\n"
18081 COMMUNITY_VAL_STR)
18082{
d62a17ae 18083 char *cl_name_or_number = NULL;
2f8cc0e5 18084 char *seq = NULL;
d62a17ae 18085 int direct = 0;
18086 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 18087 int idx = 0;
7b9a4750 18088
2f8cc0e5
DA
18089 argv_find(argv, argc, "(1-4294967295)", &idx);
18090 if (idx)
18091 seq = argv[idx]->arg;
18092
18093 idx = 0;
18094
d62a17ae 18095 argv_find(argv, argc, "(100-500)", &idx);
18096 argv_find(argv, argc, "WORD", &idx);
18097 cl_name_or_number = argv[idx]->arg;
18098 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18099 : COMMUNITY_DENY;
18100 argv_find(argv, argc, "AA:NN", &idx);
18101 char *str = argv_concat(argv, argc, idx);
42f914d4 18102
2f8cc0e5
DA
18103 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18104 direct, style);
42f914d4 18105
d62a17ae 18106 XFREE(MTYPE_TMP, str);
42f914d4 18107
d62a17ae 18108 if (ret < 0) {
18109 /* Display error string. */
18110 community_list_perror(vty, ret);
18111 return CMD_WARNING_CONFIG_FAILED;
18112 }
42f914d4 18113
d62a17ae 18114 return CMD_SUCCESS;
718e3744 18115}
18116
7336e101
SP
18117DEFUN (no_community_list_expanded_all,
18118 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 18119 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18120 NO_STR
18121 BGP_STR
18122 COMMUNITY_LIST_STR
18123 "Community list number (expanded)\n"
18124 "Add an expanded community-list entry\n"
18125 "Community list name\n"
2f8cc0e5
DA
18126 "Sequence number of an entry\n"
18127 "Sequence number\n"
7336e101
SP
18128 "Specify community to reject\n"
18129 "Specify community to accept\n"
18130 COMMUNITY_VAL_STR)
718e3744 18131{
d62a17ae 18132 char *cl_name_or_number = NULL;
2f8cc0e5 18133 char *seq = NULL;
174b5cb9 18134 char *str = NULL;
d62a17ae 18135 int direct = 0;
18136 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 18137 int idx = 0;
174b5cb9 18138
2f8cc0e5
DA
18139 argv_find(argv, argc, "(1-4294967295)", &idx);
18140 if (idx)
18141 seq = argv[idx]->arg;
18142
18143 idx = 0;
174b5cb9
DA
18144 argv_find(argv, argc, "permit", &idx);
18145 argv_find(argv, argc, "deny", &idx);
18146
18147 if (idx) {
18148 direct = argv_find(argv, argc, "permit", &idx)
18149 ? COMMUNITY_PERMIT
18150 : COMMUNITY_DENY;
18151
18152 idx = 0;
18153 argv_find(argv, argc, "AA:NN", &idx);
18154 str = argv_concat(argv, argc, idx);
7336e101 18155 }
174b5cb9
DA
18156
18157 idx = 0;
d62a17ae 18158 argv_find(argv, argc, "(100-500)", &idx);
18159 argv_find(argv, argc, "WORD", &idx);
18160 cl_name_or_number = argv[idx]->arg;
42f914d4 18161
2f8cc0e5 18162 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 18163 direct, style);
42f914d4 18164
d62a17ae 18165 XFREE(MTYPE_TMP, str);
daf9ddbb 18166
d62a17ae 18167 if (ret < 0) {
18168 community_list_perror(vty, ret);
18169 return CMD_WARNING_CONFIG_FAILED;
18170 }
42f914d4 18171
d62a17ae 18172 return CMD_SUCCESS;
718e3744 18173}
18174
36d4bb44
EB
18175ALIAS(no_community_list_expanded_all,
18176 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 18177 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 18178 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
18179 "Community list number (expanded)\n"
18180 "Add an expanded community-list entry\n"
18181 "Community list name\n")
18182
8d9b8ed9
PM
18183/* Return configuration string of community-list entry. */
18184static const char *community_list_config_str(struct community_entry *entry)
18185{
18186 const char *str;
18187
18188 if (entry->any)
18189 str = "";
18190 else {
18191 if (entry->style == COMMUNITY_LIST_STANDARD)
18192 str = community_str(entry->u.com, false);
18193 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
18194 str = lcommunity_str(entry->u.lcom, false);
18195 else
18196 str = entry->config;
18197 }
18198 return str;
18199}
18200
d62a17ae 18201static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 18202{
d62a17ae 18203 struct community_entry *entry;
718e3744 18204
d62a17ae 18205 for (entry = list->head; entry; entry = entry->next) {
18206 if (entry == list->head) {
18207 if (all_digit(list->name))
18208 vty_out(vty, "Community %s list %s\n",
18209 entry->style == COMMUNITY_LIST_STANDARD
18210 ? "standard"
18211 : "(expanded) access",
18212 list->name);
18213 else
18214 vty_out(vty, "Named Community %s list %s\n",
18215 entry->style == COMMUNITY_LIST_STANDARD
18216 ? "standard"
18217 : "expanded",
18218 list->name);
18219 }
18220 if (entry->any)
18221 vty_out(vty, " %s\n",
18222 community_direct_str(entry->direct));
18223 else
18224 vty_out(vty, " %s %s\n",
18225 community_direct_str(entry->direct),
8d9b8ed9 18226 community_list_config_str(entry));
d62a17ae 18227 }
718e3744 18228}
18229
7336e101
SP
18230DEFUN (show_community_list,
18231 show_bgp_community_list_cmd,
18232 "show bgp community-list",
718e3744 18233 SHOW_STR
7336e101 18234 BGP_STR
718e3744 18235 "List community-list\n")
18236{
d62a17ae 18237 struct community_list *list;
18238 struct community_list_master *cm;
718e3744 18239
d62a17ae 18240 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18241 if (!cm)
18242 return CMD_SUCCESS;
718e3744 18243
d62a17ae 18244 for (list = cm->num.head; list; list = list->next)
18245 community_list_show(vty, list);
718e3744 18246
d62a17ae 18247 for (list = cm->str.head; list; list = list->next)
18248 community_list_show(vty, list);
718e3744 18249
d62a17ae 18250 return CMD_SUCCESS;
718e3744 18251}
18252
7336e101
SP
18253DEFUN (show_community_list_arg,
18254 show_bgp_community_list_arg_cmd,
960b69b9 18255 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
18256 SHOW_STR
18257 BGP_STR
718e3744 18258 "List community-list\n"
18259 "Community-list number\n"
960b69b9 18260 "Community-list name\n"
18261 "Detailed information on community-list\n")
718e3744 18262{
d62a17ae 18263 int idx_comm_list = 3;
18264 struct community_list *list;
718e3744 18265
e237b0d2 18266 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18267 COMMUNITY_LIST_MASTER);
18268 if (!list) {
18269 vty_out(vty, "%% Can't find community-list\n");
18270 return CMD_WARNING;
18271 }
718e3744 18272
d62a17ae 18273 community_list_show(vty, list);
718e3744 18274
d62a17ae 18275 return CMD_SUCCESS;
718e3744 18276}
6b0655a2 18277
57d187bc
JS
18278/*
18279 * Large Community code.
18280 */
d62a17ae 18281static int lcommunity_list_set_vty(struct vty *vty, int argc,
18282 struct cmd_token **argv, int style,
18283 int reject_all_digit_name)
18284{
18285 int ret;
18286 int direct;
18287 char *str;
18288 int idx = 0;
18289 char *cl_name;
2f8cc0e5
DA
18290 char *seq = NULL;
18291
947073e3 18292 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 18293 seq = argv[idx]->arg;
d62a17ae 18294
2f8cc0e5 18295 idx = 0;
d62a17ae 18296 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18297 : COMMUNITY_DENY;
18298
18299 /* All digit name check. */
18300 idx = 0;
18301 argv_find(argv, argc, "WORD", &idx);
18302 argv_find(argv, argc, "(1-99)", &idx);
18303 argv_find(argv, argc, "(100-500)", &idx);
18304 cl_name = argv[idx]->arg;
18305 if (reject_all_digit_name && all_digit(cl_name)) {
18306 vty_out(vty, "%% Community name cannot have all digits\n");
18307 return CMD_WARNING_CONFIG_FAILED;
18308 }
18309
18310 idx = 0;
18311 argv_find(argv, argc, "AA:BB:CC", &idx);
18312 argv_find(argv, argc, "LINE", &idx);
18313 /* Concat community string argument. */
18314 if (idx)
18315 str = argv_concat(argv, argc, idx);
18316 else
18317 str = NULL;
18318
2f8cc0e5 18319 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 18320
18321 /* Free temporary community list string allocated by
18322 argv_concat(). */
0a22ddfb 18323 XFREE(MTYPE_TMP, str);
d62a17ae 18324
18325 if (ret < 0) {
18326 community_list_perror(vty, ret);
18327 return CMD_WARNING_CONFIG_FAILED;
18328 }
18329 return CMD_SUCCESS;
18330}
18331
18332static int lcommunity_list_unset_vty(struct vty *vty, int argc,
18333 struct cmd_token **argv, int style)
18334{
18335 int ret;
18336 int direct = 0;
18337 char *str = NULL;
18338 int idx = 0;
2f8cc0e5 18339 char *seq = NULL;
d62a17ae 18340
947073e3 18341 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 18342 seq = argv[idx]->arg;
d62a17ae 18343
2f8cc0e5 18344 idx = 0;
d62a17ae 18345 argv_find(argv, argc, "permit", &idx);
18346 argv_find(argv, argc, "deny", &idx);
18347
18348 if (idx) {
18349 /* Check the list direct. */
18350 if (strncmp(argv[idx]->arg, "p", 1) == 0)
18351 direct = COMMUNITY_PERMIT;
18352 else
18353 direct = COMMUNITY_DENY;
18354
18355 idx = 0;
18356 argv_find(argv, argc, "LINE", &idx);
18357 argv_find(argv, argc, "AA:AA:NN", &idx);
18358 /* Concat community string argument. */
18359 str = argv_concat(argv, argc, idx);
18360 }
18361
18362 idx = 0;
18363 argv_find(argv, argc, "(1-99)", &idx);
18364 argv_find(argv, argc, "(100-500)", &idx);
18365 argv_find(argv, argc, "WORD", &idx);
18366
18367 /* Unset community list. */
2f8cc0e5 18368 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 18369 style);
18370
18371 /* Free temporary community list string allocated by
18372 argv_concat(). */
0a22ddfb 18373 XFREE(MTYPE_TMP, str);
d62a17ae 18374
18375 if (ret < 0) {
18376 community_list_perror(vty, ret);
18377 return CMD_WARNING_CONFIG_FAILED;
18378 }
18379
18380 return CMD_SUCCESS;
57d187bc
JS
18381}
18382
18383/* "large-community-list" keyword help string. */
18384#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
18385#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
18386
7336e101
SP
18387DEFUN (lcommunity_list_standard,
18388 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 18389 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
18390 BGP_STR
18391 LCOMMUNITY_LIST_STR
18392 "Large Community list number (standard)\n"
2f8cc0e5
DA
18393 "Sequence number of an entry\n"
18394 "Sequence number\n"
7336e101
SP
18395 "Specify large community to reject\n"
18396 "Specify large community to accept\n"
18397 LCOMMUNITY_VAL_STR)
52951b63 18398{
d62a17ae 18399 return lcommunity_list_set_vty(vty, argc, argv,
18400 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
18401}
18402
7336e101
SP
18403DEFUN (lcommunity_list_expanded,
18404 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 18405 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18406 BGP_STR
18407 LCOMMUNITY_LIST_STR
18408 "Large Community list number (expanded)\n"
2f8cc0e5
DA
18409 "Sequence number of an entry\n"
18410 "Sequence number\n"
7336e101
SP
18411 "Specify large community to reject\n"
18412 "Specify large community to accept\n"
18413 "An ordered list as a regular-expression\n")
57d187bc 18414{
d62a17ae 18415 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 18416 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
18417}
18418
7336e101
SP
18419DEFUN (lcommunity_list_name_standard,
18420 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 18421 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
18422 BGP_STR
18423 LCOMMUNITY_LIST_STR
18424 "Specify standard large-community-list\n"
18425 "Large Community list name\n"
2f8cc0e5
DA
18426 "Sequence number of an entry\n"
18427 "Sequence number\n"
7336e101
SP
18428 "Specify large community to reject\n"
18429 "Specify large community to accept\n"
18430 LCOMMUNITY_VAL_STR)
52951b63 18431{
d62a17ae 18432 return lcommunity_list_set_vty(vty, argc, argv,
18433 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
18434}
18435
7336e101
SP
18436DEFUN (lcommunity_list_name_expanded,
18437 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 18438 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18439 BGP_STR
18440 LCOMMUNITY_LIST_STR
18441 "Specify expanded large-community-list\n"
18442 "Large Community list name\n"
2f8cc0e5
DA
18443 "Sequence number of an entry\n"
18444 "Sequence number\n"
7336e101
SP
18445 "Specify large community to reject\n"
18446 "Specify large community to accept\n"
18447 "An ordered list as a regular-expression\n")
57d187bc 18448{
d62a17ae 18449 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 18450 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
18451}
18452
4378f57c
DA
18453DEFUN (no_lcommunity_list_all,
18454 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
18455 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
18456 NO_STR
18457 BGP_STR
18458 LCOMMUNITY_LIST_STR
18459 "Large Community list number (standard)\n"
18460 "Large Community list number (expanded)\n"
18461 "Large Community list name\n")
57d187bc 18462{
7336e101
SP
18463 return lcommunity_list_unset_vty(vty, argc, argv,
18464 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18465}
18466
4378f57c
DA
18467DEFUN (no_lcommunity_list_name_standard_all,
18468 no_bgp_lcommunity_list_name_standard_all_cmd,
18469 "no bgp large-community-list standard WORD",
18470 NO_STR
18471 BGP_STR
18472 LCOMMUNITY_LIST_STR
18473 "Specify standard large-community-list\n"
18474 "Large Community list name\n")
18475{
18476 return lcommunity_list_unset_vty(vty, argc, argv,
18477 LARGE_COMMUNITY_LIST_STANDARD);
18478}
18479
7336e101
SP
18480DEFUN (no_lcommunity_list_name_expanded_all,
18481 no_bgp_lcommunity_list_name_expanded_all_cmd,
18482 "no bgp large-community-list expanded WORD",
18483 NO_STR
18484 BGP_STR
18485 LCOMMUNITY_LIST_STR
18486 "Specify expanded large-community-list\n"
18487 "Large Community list name\n")
57d187bc 18488{
d62a17ae 18489 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18490 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18491}
18492
7336e101
SP
18493DEFUN (no_lcommunity_list_standard,
18494 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 18495 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
18496 NO_STR
18497 BGP_STR
18498 LCOMMUNITY_LIST_STR
18499 "Large Community list number (standard)\n"
2f8cc0e5
DA
18500 "Sequence number of an entry\n"
18501 "Sequence number\n"
7336e101
SP
18502 "Specify large community to reject\n"
18503 "Specify large community to accept\n"
18504 LCOMMUNITY_VAL_STR)
57d187bc 18505{
d62a17ae 18506 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18507 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18508}
18509
7336e101
SP
18510DEFUN (no_lcommunity_list_expanded,
18511 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 18512 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18513 NO_STR
18514 BGP_STR
18515 LCOMMUNITY_LIST_STR
18516 "Large Community list number (expanded)\n"
2f8cc0e5
DA
18517 "Sequence number of an entry\n"
18518 "Sequence number\n"
7336e101
SP
18519 "Specify large community to reject\n"
18520 "Specify large community to accept\n"
18521 "An ordered list as a regular-expression\n")
57d187bc 18522{
d62a17ae 18523 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18524 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18525}
18526
7336e101
SP
18527DEFUN (no_lcommunity_list_name_standard,
18528 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 18529 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
18530 NO_STR
18531 BGP_STR
18532 LCOMMUNITY_LIST_STR
18533 "Specify standard large-community-list\n"
18534 "Large Community list name\n"
2f8cc0e5
DA
18535 "Sequence number of an entry\n"
18536 "Sequence number\n"
7336e101
SP
18537 "Specify large community to reject\n"
18538 "Specify large community to accept\n"
18539 LCOMMUNITY_VAL_STR)
57d187bc 18540{
d62a17ae 18541 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18542 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18543}
18544
7336e101
SP
18545DEFUN (no_lcommunity_list_name_expanded,
18546 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 18547 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18548 NO_STR
18549 BGP_STR
18550 LCOMMUNITY_LIST_STR
18551 "Specify expanded large-community-list\n"
18552 "Large community list name\n"
2f8cc0e5
DA
18553 "Sequence number of an entry\n"
18554 "Sequence number\n"
7336e101
SP
18555 "Specify large community to reject\n"
18556 "Specify large community to accept\n"
18557 "An ordered list as a regular-expression\n")
57d187bc 18558{
d62a17ae 18559 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18560 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18561}
18562
d62a17ae 18563static void lcommunity_list_show(struct vty *vty, struct community_list *list)
18564{
18565 struct community_entry *entry;
18566
18567 for (entry = list->head; entry; entry = entry->next) {
18568 if (entry == list->head) {
18569 if (all_digit(list->name))
18570 vty_out(vty, "Large community %s list %s\n",
169b72c8 18571 entry->style ==
18572 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 18573 ? "standard"
18574 : "(expanded) access",
18575 list->name);
18576 else
18577 vty_out(vty,
18578 "Named large community %s list %s\n",
169b72c8 18579 entry->style ==
18580 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 18581 ? "standard"
18582 : "expanded",
18583 list->name);
18584 }
18585 if (entry->any)
18586 vty_out(vty, " %s\n",
18587 community_direct_str(entry->direct));
18588 else
18589 vty_out(vty, " %s %s\n",
18590 community_direct_str(entry->direct),
8d9b8ed9 18591 community_list_config_str(entry));
d62a17ae 18592 }
57d187bc
JS
18593}
18594
7336e101
SP
18595DEFUN (show_lcommunity_list,
18596 show_bgp_lcommunity_list_cmd,
18597 "show bgp large-community-list",
57d187bc 18598 SHOW_STR
7336e101 18599 BGP_STR
57d187bc
JS
18600 "List large-community list\n")
18601{
d62a17ae 18602 struct community_list *list;
18603 struct community_list_master *cm;
57d187bc 18604
d62a17ae 18605 cm = community_list_master_lookup(bgp_clist,
18606 LARGE_COMMUNITY_LIST_MASTER);
18607 if (!cm)
18608 return CMD_SUCCESS;
57d187bc 18609
d62a17ae 18610 for (list = cm->num.head; list; list = list->next)
18611 lcommunity_list_show(vty, list);
57d187bc 18612
d62a17ae 18613 for (list = cm->str.head; list; list = list->next)
18614 lcommunity_list_show(vty, list);
57d187bc 18615
d62a17ae 18616 return CMD_SUCCESS;
57d187bc
JS
18617}
18618
7336e101
SP
18619DEFUN (show_lcommunity_list_arg,
18620 show_bgp_lcommunity_list_arg_cmd,
960b69b9 18621 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
18622 SHOW_STR
18623 BGP_STR
57d187bc 18624 "List large-community list\n"
960b69b9 18625 "Large-community-list number\n"
18626 "Large-community-list name\n"
18627 "Detailed information on large-community-list\n")
57d187bc 18628{
d62a17ae 18629 struct community_list *list;
57d187bc 18630
e237b0d2 18631 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 18632 LARGE_COMMUNITY_LIST_MASTER);
18633 if (!list) {
960b69b9 18634 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 18635 return CMD_WARNING;
18636 }
57d187bc 18637
d62a17ae 18638 lcommunity_list_show(vty, list);
57d187bc 18639
d62a17ae 18640 return CMD_SUCCESS;
57d187bc
JS
18641}
18642
718e3744 18643/* "extcommunity-list" keyword help string. */
18644#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
18645#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
18646
7336e101
SP
18647DEFUN (extcommunity_list_standard,
18648 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 18649 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 18650 BGP_STR
718e3744 18651 EXTCOMMUNITY_LIST_STR
18652 "Extended Community list number (standard)\n"
718e3744 18653 "Specify standard extcommunity-list\n"
5bf15956 18654 "Community list name\n"
2f8cc0e5
DA
18655 "Sequence number of an entry\n"
18656 "Sequence number\n"
718e3744 18657 "Specify community to reject\n"
18658 "Specify community to accept\n"
18659 EXTCOMMUNITY_VAL_STR)
18660{
d62a17ae 18661 int style = EXTCOMMUNITY_LIST_STANDARD;
18662 int direct = 0;
18663 char *cl_number_or_name = NULL;
2f8cc0e5 18664 char *seq = NULL;
42f914d4 18665
d62a17ae 18666 int idx = 0;
7b9a4750 18667
d62a17ae 18668 argv_find(argv, argc, "(1-99)", &idx);
18669 argv_find(argv, argc, "WORD", &idx);
18670 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 18671
409148f6 18672 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18673 seq = argv[idx]->arg;
18674
d62a17ae 18675 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18676 : COMMUNITY_DENY;
18677 argv_find(argv, argc, "AA:NN", &idx);
18678 char *str = argv_concat(argv, argc, idx);
42f914d4 18679
2f8cc0e5 18680 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 18681 direct, style);
42f914d4 18682
d62a17ae 18683 XFREE(MTYPE_TMP, str);
42f914d4 18684
d62a17ae 18685 if (ret < 0) {
18686 community_list_perror(vty, ret);
18687 return CMD_WARNING_CONFIG_FAILED;
18688 }
42f914d4 18689
d62a17ae 18690 return CMD_SUCCESS;
718e3744 18691}
18692
7336e101
SP
18693DEFUN (extcommunity_list_name_expanded,
18694 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 18695 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18696 BGP_STR
18697 EXTCOMMUNITY_LIST_STR
5bf15956 18698 "Extended Community list number (expanded)\n"
718e3744 18699 "Specify expanded extcommunity-list\n"
18700 "Extended Community list name\n"
2f8cc0e5
DA
18701 "Sequence number of an entry\n"
18702 "Sequence number\n"
718e3744 18703 "Specify community to reject\n"
18704 "Specify community to accept\n"
18705 "An ordered list as a regular-expression\n")
18706{
d62a17ae 18707 int style = EXTCOMMUNITY_LIST_EXPANDED;
18708 int direct = 0;
18709 char *cl_number_or_name = NULL;
2f8cc0e5 18710 char *seq = NULL;
d62a17ae 18711 int idx = 0;
7336e101 18712
d62a17ae 18713 argv_find(argv, argc, "(100-500)", &idx);
18714 argv_find(argv, argc, "WORD", &idx);
18715 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 18716
409148f6 18717 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18718 seq = argv[idx]->arg;
18719
d62a17ae 18720 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18721 : COMMUNITY_DENY;
18722 argv_find(argv, argc, "LINE", &idx);
18723 char *str = argv_concat(argv, argc, idx);
42f914d4 18724
2f8cc0e5 18725 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 18726 direct, style);
42f914d4 18727
d62a17ae 18728 XFREE(MTYPE_TMP, str);
42f914d4 18729
d62a17ae 18730 if (ret < 0) {
18731 community_list_perror(vty, ret);
18732 return CMD_WARNING_CONFIG_FAILED;
18733 }
42f914d4 18734
d62a17ae 18735 return CMD_SUCCESS;
718e3744 18736}
18737
7336e101
SP
18738DEFUN (no_extcommunity_list_standard_all,
18739 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 18740 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18741 NO_STR
18742 BGP_STR
18743 EXTCOMMUNITY_LIST_STR
813d4307 18744 "Extended Community list number (standard)\n"
718e3744 18745 "Specify standard extcommunity-list\n"
5bf15956 18746 "Community list name\n"
2f8cc0e5
DA
18747 "Sequence number of an entry\n"
18748 "Sequence number\n"
718e3744 18749 "Specify community to reject\n"
18750 "Specify community to accept\n"
18751 EXTCOMMUNITY_VAL_STR)
18752{
d62a17ae 18753 int style = EXTCOMMUNITY_LIST_STANDARD;
18754 int direct = 0;
18755 char *cl_number_or_name = NULL;
d4455c89 18756 char *str = NULL;
2f8cc0e5 18757 char *seq = NULL;
d62a17ae 18758 int idx = 0;
d4455c89 18759
409148f6 18760 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18761 seq = argv[idx]->arg;
18762
18763 idx = 0;
d4455c89
DA
18764 argv_find(argv, argc, "permit", &idx);
18765 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
18766 if (idx) {
18767 direct = argv_find(argv, argc, "permit", &idx)
18768 ? COMMUNITY_PERMIT
18769 : COMMUNITY_DENY;
18770
18771 idx = 0;
18772 argv_find(argv, argc, "AA:NN", &idx);
18773 str = argv_concat(argv, argc, idx);
18774 }
18775
18776 idx = 0;
d62a17ae 18777 argv_find(argv, argc, "(1-99)", &idx);
18778 argv_find(argv, argc, "WORD", &idx);
18779 cl_number_or_name = argv[idx]->arg;
42f914d4 18780
d62a17ae 18781 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18782 seq, direct, style);
42f914d4 18783
d62a17ae 18784 XFREE(MTYPE_TMP, str);
42f914d4 18785
d62a17ae 18786 if (ret < 0) {
18787 community_list_perror(vty, ret);
18788 return CMD_WARNING_CONFIG_FAILED;
18789 }
42f914d4 18790
d62a17ae 18791 return CMD_SUCCESS;
718e3744 18792}
18793
d4455c89
DA
18794ALIAS(no_extcommunity_list_standard_all,
18795 no_bgp_extcommunity_list_standard_all_list_cmd,
18796 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 18797 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
18798 "Extended Community list number (standard)\n"
18799 "Specify standard extcommunity-list\n"
18800 "Community list name\n")
18801
7336e101
SP
18802DEFUN (no_extcommunity_list_expanded_all,
18803 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 18804 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18805 NO_STR
18806 BGP_STR
18807 EXTCOMMUNITY_LIST_STR
718e3744 18808 "Extended Community list number (expanded)\n"
718e3744 18809 "Specify expanded extcommunity-list\n"
5bf15956 18810 "Extended Community list name\n"
2f8cc0e5
DA
18811 "Sequence number of an entry\n"
18812 "Sequence number\n"
718e3744 18813 "Specify community to reject\n"
18814 "Specify community to accept\n"
18815 "An ordered list as a regular-expression\n")
18816{
d62a17ae 18817 int style = EXTCOMMUNITY_LIST_EXPANDED;
18818 int direct = 0;
18819 char *cl_number_or_name = NULL;
d4455c89 18820 char *str = NULL;
2f8cc0e5 18821 char *seq = NULL;
d62a17ae 18822 int idx = 0;
d4455c89 18823
409148f6 18824 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18825 seq = argv[idx]->arg;
18826
18827 idx = 0;
d4455c89
DA
18828 argv_find(argv, argc, "permit", &idx);
18829 argv_find(argv, argc, "deny", &idx);
18830
18831 if (idx) {
18832 direct = argv_find(argv, argc, "permit", &idx)
18833 ? COMMUNITY_PERMIT
18834 : COMMUNITY_DENY;
18835
18836 idx = 0;
18837 argv_find(argv, argc, "LINE", &idx);
18838 str = argv_concat(argv, argc, idx);
18839 }
18840
18841 idx = 0;
d62a17ae 18842 argv_find(argv, argc, "(100-500)", &idx);
18843 argv_find(argv, argc, "WORD", &idx);
18844 cl_number_or_name = argv[idx]->arg;
42f914d4 18845
d62a17ae 18846 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18847 seq, direct, style);
42f914d4 18848
d62a17ae 18849 XFREE(MTYPE_TMP, str);
42f914d4 18850
d62a17ae 18851 if (ret < 0) {
18852 community_list_perror(vty, ret);
18853 return CMD_WARNING_CONFIG_FAILED;
18854 }
42f914d4 18855
d62a17ae 18856 return CMD_SUCCESS;
718e3744 18857}
18858
d4455c89
DA
18859ALIAS(no_extcommunity_list_expanded_all,
18860 no_bgp_extcommunity_list_expanded_all_list_cmd,
18861 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 18862 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
18863 "Extended Community list number (expanded)\n"
18864 "Specify expanded extcommunity-list\n"
18865 "Extended Community list name\n")
18866
d62a17ae 18867static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 18868{
d62a17ae 18869 struct community_entry *entry;
718e3744 18870
d62a17ae 18871 for (entry = list->head; entry; entry = entry->next) {
18872 if (entry == list->head) {
18873 if (all_digit(list->name))
18874 vty_out(vty, "Extended community %s list %s\n",
18875 entry->style == EXTCOMMUNITY_LIST_STANDARD
18876 ? "standard"
18877 : "(expanded) access",
18878 list->name);
18879 else
18880 vty_out(vty,
18881 "Named extended community %s list %s\n",
18882 entry->style == EXTCOMMUNITY_LIST_STANDARD
18883 ? "standard"
18884 : "expanded",
18885 list->name);
18886 }
18887 if (entry->any)
18888 vty_out(vty, " %s\n",
18889 community_direct_str(entry->direct));
18890 else
18891 vty_out(vty, " %s %s\n",
18892 community_direct_str(entry->direct),
8d9b8ed9 18893 community_list_config_str(entry));
d62a17ae 18894 }
718e3744 18895}
18896
7336e101
SP
18897DEFUN (show_extcommunity_list,
18898 show_bgp_extcommunity_list_cmd,
18899 "show bgp extcommunity-list",
718e3744 18900 SHOW_STR
7336e101 18901 BGP_STR
718e3744 18902 "List extended-community list\n")
18903{
d62a17ae 18904 struct community_list *list;
18905 struct community_list_master *cm;
718e3744 18906
d62a17ae 18907 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18908 if (!cm)
18909 return CMD_SUCCESS;
718e3744 18910
d62a17ae 18911 for (list = cm->num.head; list; list = list->next)
18912 extcommunity_list_show(vty, list);
718e3744 18913
d62a17ae 18914 for (list = cm->str.head; list; list = list->next)
18915 extcommunity_list_show(vty, list);
718e3744 18916
d62a17ae 18917 return CMD_SUCCESS;
718e3744 18918}
18919
7336e101
SP
18920DEFUN (show_extcommunity_list_arg,
18921 show_bgp_extcommunity_list_arg_cmd,
960b69b9 18922 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
18923 SHOW_STR
18924 BGP_STR
718e3744 18925 "List extended-community list\n"
18926 "Extcommunity-list number\n"
960b69b9 18927 "Extcommunity-list name\n"
18928 "Detailed information on extcommunity-list\n")
718e3744 18929{
d62a17ae 18930 int idx_comm_list = 3;
18931 struct community_list *list;
718e3744 18932
e237b0d2 18933 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18934 EXTCOMMUNITY_LIST_MASTER);
18935 if (!list) {
18936 vty_out(vty, "%% Can't find extcommunity-list\n");
18937 return CMD_WARNING;
18938 }
718e3744 18939
d62a17ae 18940 extcommunity_list_show(vty, list);
718e3744 18941
d62a17ae 18942 return CMD_SUCCESS;
718e3744 18943}
6b0655a2 18944
718e3744 18945/* Display community-list and extcommunity-list configuration. */
d62a17ae 18946static int community_list_config_write(struct vty *vty)
18947{
18948 struct community_list *list;
18949 struct community_entry *entry;
18950 struct community_list_master *cm;
18951 int write = 0;
18952
18953 /* Community-list. */
18954 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18955
18956 for (list = cm->num.head; list; list = list->next)
18957 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18958 vty_out(vty,
18959 "bgp community-list %s seq %" PRId64 " %s %s\n",
18960 list->name, entry->seq,
d62a17ae 18961 community_direct_str(entry->direct),
18962 community_list_config_str(entry));
18963 write++;
18964 }
18965 for (list = cm->str.head; list; list = list->next)
18966 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18967 vty_out(vty,
18968 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 18969 entry->style == COMMUNITY_LIST_STANDARD
18970 ? "standard"
18971 : "expanded",
2f8cc0e5
DA
18972 list->name, entry->seq,
18973 community_direct_str(entry->direct),
d62a17ae 18974 community_list_config_str(entry));
18975 write++;
18976 }
18977
18978 /* Extcommunity-list. */
18979 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18980
18981 for (list = cm->num.head; list; list = list->next)
18982 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18983 vty_out(vty,
18984 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
18985 list->name, entry->seq,
18986 community_direct_str(entry->direct),
d62a17ae 18987 community_list_config_str(entry));
18988 write++;
18989 }
18990 for (list = cm->str.head; list; list = list->next)
18991 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18992 vty_out(vty,
6cde4b45 18993 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 18994 entry->style == EXTCOMMUNITY_LIST_STANDARD
18995 ? "standard"
18996 : "expanded",
2f8cc0e5
DA
18997 list->name, entry->seq,
18998 community_direct_str(entry->direct),
d62a17ae 18999 community_list_config_str(entry));
19000 write++;
19001 }
19002
19003
19004 /* lcommunity-list. */
19005 cm = community_list_master_lookup(bgp_clist,
19006 LARGE_COMMUNITY_LIST_MASTER);
19007
19008 for (list = cm->num.head; list; list = list->next)
19009 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19010 vty_out(vty,
6cde4b45 19011 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
19012 list->name, entry->seq,
19013 community_direct_str(entry->direct),
d62a17ae 19014 community_list_config_str(entry));
19015 write++;
19016 }
19017 for (list = cm->str.head; list; list = list->next)
19018 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19019 vty_out(vty,
6cde4b45 19020 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 19021
d62a17ae 19022 entry->style == LARGE_COMMUNITY_LIST_STANDARD
19023 ? "standard"
19024 : "expanded",
2f8cc0e5 19025 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 19026 community_list_config_str(entry));
19027 write++;
19028 }
19029
19030 return write;
19031}
19032
612c2c15 19033static int community_list_config_write(struct vty *vty);
d62a17ae 19034static struct cmd_node community_list_node = {
f4b8291f 19035 .name = "community list",
62b346ee
DL
19036 .node = COMMUNITY_LIST_NODE,
19037 .prompt = "",
612c2c15 19038 .config_write = community_list_config_write,
718e3744 19039};
19040
d62a17ae 19041static void community_list_vty(void)
19042{
612c2c15 19043 install_node(&community_list_node);
d62a17ae 19044
19045 /* Community-list. */
7336e101
SP
19046 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
19047 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
19048 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 19049 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 19050 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 19051 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
19052 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
19053 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 19054
19055 /* Extcommunity-list. */
7336e101
SP
19056 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
19057 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
19058 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
19059 install_element(CONFIG_NODE,
19060 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 19061 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
19062 install_element(CONFIG_NODE,
19063 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
19064 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
19065 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 19066
19067 /* Large Community List */
7336e101 19068 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
19069 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
19070 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 19071 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
19072 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
19073 install_element(CONFIG_NODE,
19074 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
19075 install_element(CONFIG_NODE,
19076 &no_bgp_lcommunity_list_name_expanded_all_cmd);
19077 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
19078 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
19079 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
19080 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
19081 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
19082 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 19083}