]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
doc: Add rfc8654 to supported RFCs list
[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)
2adac256
DA
122FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
123 { .val_bool = false, .match_version = "< 7.6", },
124 { .val_bool = true },
125)
5d5393b9 126
dd65f45e
DL
127DEFINE_HOOK(bgp_inst_config_write,
128 (struct bgp *bgp, struct vty *vty),
129 (bgp, vty))
0d020cd6 130DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp))
718e3744 131
36235319
QY
132#define GR_NO_OPER \
133 "The Graceful Restart No Operation was executed as cmd same as previous one."
134#define GR_INVALID \
135 "The Graceful Restart command used is not valid at this moment."
d62a17ae 136static struct peer_group *listen_range_exists(struct bgp *bgp,
137 struct prefix *range, int exact);
138
055679e9 139/* Show BGP peer's information. */
140enum show_type {
141 show_all,
142 show_peer,
143 show_ipv4_all,
144 show_ipv6_all,
145 show_ipv4_peer,
146 show_ipv6_peer
147};
148
36235319
QY
149static struct peer_group *listen_range_exists(struct bgp *bgp,
150 struct prefix *range, int exact);
2986cac2 151
36235319
QY
152static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
153 struct bgp *bgp,
154 bool use_json,
155 json_object *json);
2986cac2 156
36235319
QY
157static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
158 enum show_type type,
159 const char *ip_str,
160 afi_t afi, bool use_json);
2986cac2 161
f4b8ec07
CS
162static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
163 char *base_xpath, int xpath_len,
164 char *abs_xpath);
165
d62a17ae 166static enum node_type bgp_node_type(afi_t afi, safi_t safi)
167{
168 switch (afi) {
169 case AFI_IP:
170 switch (safi) {
171 case SAFI_UNICAST:
172 return BGP_IPV4_NODE;
d62a17ae 173 case SAFI_MULTICAST:
174 return BGP_IPV4M_NODE;
d62a17ae 175 case SAFI_LABELED_UNICAST:
176 return BGP_IPV4L_NODE;
d62a17ae 177 case SAFI_MPLS_VPN:
178 return BGP_VPNV4_NODE;
7c40bf39 179 case SAFI_FLOWSPEC:
180 return BGP_FLOWSPECV4_NODE;
5c525538
RW
181 default:
182 /* not expected */
183 return BGP_IPV4_NODE;
d62a17ae 184 }
185 break;
186 case AFI_IP6:
187 switch (safi) {
188 case SAFI_UNICAST:
189 return BGP_IPV6_NODE;
d62a17ae 190 case SAFI_MULTICAST:
191 return BGP_IPV6M_NODE;
d62a17ae 192 case SAFI_LABELED_UNICAST:
193 return BGP_IPV6L_NODE;
d62a17ae 194 case SAFI_MPLS_VPN:
195 return BGP_VPNV6_NODE;
7c40bf39 196 case SAFI_FLOWSPEC:
197 return BGP_FLOWSPECV6_NODE;
5c525538
RW
198 default:
199 /* not expected */
200 return BGP_IPV4_NODE;
d62a17ae 201 }
202 break;
203 case AFI_L2VPN:
204 return BGP_EVPN_NODE;
b26f891d 205 case AFI_UNSPEC:
d62a17ae 206 case AFI_MAX:
207 // We should never be here but to clarify the switch statement..
208 return BGP_IPV4_NODE;
d62a17ae 209 }
210
211 // Impossible to happen
212 return BGP_IPV4_NODE;
f51bae9c 213}
20eb8864 214
5cb5f4d0
DD
215static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
216{
7d0d37de
DS
217 if (afi == AFI_IP) {
218 if (safi == SAFI_UNICAST)
219 return "IPv4 Unicast";
220 if (safi == SAFI_MULTICAST)
221 return "IPv4 Multicast";
222 if (safi == SAFI_LABELED_UNICAST)
223 return "IPv4 Labeled Unicast";
224 if (safi == SAFI_MPLS_VPN)
225 return "IPv4 VPN";
226 if (safi == SAFI_ENCAP)
227 return "IPv4 Encap";
228 if (safi == SAFI_FLOWSPEC)
229 return "IPv4 Flowspec";
230 } else if (afi == AFI_IP6) {
231 if (safi == SAFI_UNICAST)
232 return "IPv6 Unicast";
233 if (safi == SAFI_MULTICAST)
234 return "IPv6 Multicast";
235 if (safi == SAFI_LABELED_UNICAST)
236 return "IPv6 Labeled Unicast";
237 if (safi == SAFI_MPLS_VPN)
238 return "IPv6 VPN";
239 if (safi == SAFI_ENCAP)
240 return "IPv6 Encap";
241 if (safi == SAFI_FLOWSPEC)
242 return "IPv6 Flowspec";
243 } else if (afi == AFI_L2VPN) {
244 if (safi == SAFI_EVPN)
245 return "L2VPN EVPN";
246 }
247
248 return "Unknown";
5cb5f4d0
DD
249}
250
251/*
252 * Please note that we have intentionally camelCased
253 * the return strings here. So if you want
254 * to use this function, please ensure you
255 * are doing this within json output
256 */
257static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
258{
7d0d37de
DS
259 if (afi == AFI_IP) {
260 if (safi == SAFI_UNICAST)
261 return "ipv4Unicast";
262 if (safi == SAFI_MULTICAST)
263 return "ipv4Multicast";
264 if (safi == SAFI_LABELED_UNICAST)
265 return "ipv4LabeledUnicast";
266 if (safi == SAFI_MPLS_VPN)
267 return "ipv4Vpn";
268 if (safi == SAFI_ENCAP)
269 return "ipv4Encap";
270 if (safi == SAFI_FLOWSPEC)
271 return "ipv4Flowspec";
272 } else if (afi == AFI_IP6) {
273 if (safi == SAFI_UNICAST)
274 return "ipv6Unicast";
275 if (safi == SAFI_MULTICAST)
276 return "ipv6Multicast";
277 if (safi == SAFI_LABELED_UNICAST)
278 return "ipv6LabeledUnicast";
279 if (safi == SAFI_MPLS_VPN)
280 return "ipv6Vpn";
281 if (safi == SAFI_ENCAP)
282 return "ipv6Encap";
283 if (safi == SAFI_FLOWSPEC)
284 return "ipv6Flowspec";
285 } else if (afi == AFI_L2VPN) {
286 if (safi == SAFI_EVPN)
287 return "l2VpnEvpn";
288 }
289
290 return "Unknown";
5cb5f4d0
DD
291}
292
37a87b8f
CS
293/* return string maps to afi-safi specific container names
294 * defined in bgp yang file.
295 */
296const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
297{
7d0d37de
DS
298 if (afi == AFI_IP) {
299 if (safi == SAFI_UNICAST)
300 return "ipv4-unicast";
301 if (safi == SAFI_MULTICAST)
302 return "ipv4-multicast";
303 if (safi == SAFI_LABELED_UNICAST)
304 return "ipv4-labeled-unicast";
305 if (safi == SAFI_MPLS_VPN)
306 return "l3vpn-ipv4-unicast";
307 if (safi == SAFI_FLOWSPEC)
308 return "ipv4-flowspec";
309 } else if (afi == AFI_IP6) {
310 if (safi == SAFI_UNICAST)
311 return "ipv6-unicast";
312 if (safi == SAFI_MULTICAST)
313 return "ipv6-multicast";
314 if (safi == SAFI_LABELED_UNICAST)
315 return "ipv6-labeled-unicast";
316 if (safi == SAFI_MPLS_VPN)
317 return "l3vpn-ipv6-unicast";
318 if (safi == SAFI_FLOWSPEC)
319 return "ipv6-flowspec";
320 } else if (afi == AFI_L2VPN) {
321 if (safi == SAFI_EVPN)
322 return "l2vpn-evpn";
323 }
324
325 return "Unknown";
37a87b8f
CS
326}
327
718e3744 328/* Utility function to get address family from current node. */
d62a17ae 329afi_t bgp_node_afi(struct vty *vty)
330{
331 afi_t afi;
332 switch (vty->node) {
333 case BGP_IPV6_NODE:
334 case BGP_IPV6M_NODE:
335 case BGP_IPV6L_NODE:
336 case BGP_VPNV6_NODE:
7c40bf39 337 case BGP_FLOWSPECV6_NODE:
d62a17ae 338 afi = AFI_IP6;
339 break;
340 case BGP_EVPN_NODE:
341 afi = AFI_L2VPN;
342 break;
343 default:
344 afi = AFI_IP;
345 break;
346 }
347 return afi;
718e3744 348}
349
350/* Utility function to get subsequent address family from current
351 node. */
d62a17ae 352safi_t bgp_node_safi(struct vty *vty)
353{
354 safi_t safi;
355 switch (vty->node) {
356 case BGP_VPNV4_NODE:
357 case BGP_VPNV6_NODE:
358 safi = SAFI_MPLS_VPN;
359 break;
360 case BGP_IPV4M_NODE:
361 case BGP_IPV6M_NODE:
362 safi = SAFI_MULTICAST;
363 break;
364 case BGP_EVPN_NODE:
365 safi = SAFI_EVPN;
366 break;
367 case BGP_IPV4L_NODE:
368 case BGP_IPV6L_NODE:
369 safi = SAFI_LABELED_UNICAST;
370 break;
7c40bf39 371 case BGP_FLOWSPECV4_NODE:
372 case BGP_FLOWSPECV6_NODE:
373 safi = SAFI_FLOWSPEC;
374 break;
d62a17ae 375 default:
376 safi = SAFI_UNICAST;
377 break;
378 }
379 return safi;
718e3744 380}
381
55f91488
QY
382/**
383 * Converts an AFI in string form to afi_t
384 *
385 * @param afi string, one of
386 * - "ipv4"
387 * - "ipv6"
81cf0de5 388 * - "l2vpn"
55f91488
QY
389 * @return the corresponding afi_t
390 */
d62a17ae 391afi_t bgp_vty_afi_from_str(const char *afi_str)
392{
393 afi_t afi = AFI_MAX; /* unknown */
394 if (strmatch(afi_str, "ipv4"))
395 afi = AFI_IP;
396 else if (strmatch(afi_str, "ipv6"))
397 afi = AFI_IP6;
81cf0de5
CS
398 else if (strmatch(afi_str, "l2vpn"))
399 afi = AFI_L2VPN;
d62a17ae 400 return afi;
401}
402
403int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
404 afi_t *afi)
405{
406 int ret = 0;
407 if (argv_find(argv, argc, "ipv4", index)) {
408 ret = 1;
409 if (afi)
410 *afi = AFI_IP;
411 } else if (argv_find(argv, argc, "ipv6", index)) {
412 ret = 1;
413 if (afi)
414 *afi = AFI_IP6;
8688b3e7
DS
415 } else if (argv_find(argv, argc, "l2vpn", index)) {
416 ret = 1;
417 if (afi)
418 *afi = AFI_L2VPN;
d62a17ae 419 }
420 return ret;
46f296b4
LB
421}
422
375a2e67 423/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 424safi_t bgp_vty_safi_from_str(const char *safi_str)
425{
426 safi_t safi = SAFI_MAX; /* unknown */
427 if (strmatch(safi_str, "multicast"))
428 safi = SAFI_MULTICAST;
429 else if (strmatch(safi_str, "unicast"))
430 safi = SAFI_UNICAST;
431 else if (strmatch(safi_str, "vpn"))
432 safi = SAFI_MPLS_VPN;
81cf0de5
CS
433 else if (strmatch(safi_str, "evpn"))
434 safi = SAFI_EVPN;
d62a17ae 435 else if (strmatch(safi_str, "labeled-unicast"))
436 safi = SAFI_LABELED_UNICAST;
7c40bf39 437 else if (strmatch(safi_str, "flowspec"))
438 safi = SAFI_FLOWSPEC;
d62a17ae 439 return safi;
440}
441
442int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
443 safi_t *safi)
444{
445 int ret = 0;
446 if (argv_find(argv, argc, "unicast", index)) {
447 ret = 1;
448 if (safi)
449 *safi = SAFI_UNICAST;
450 } else if (argv_find(argv, argc, "multicast", index)) {
451 ret = 1;
452 if (safi)
453 *safi = SAFI_MULTICAST;
454 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
455 ret = 1;
456 if (safi)
457 *safi = SAFI_LABELED_UNICAST;
458 } else if (argv_find(argv, argc, "vpn", index)) {
459 ret = 1;
460 if (safi)
461 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
462 } else if (argv_find(argv, argc, "evpn", index)) {
463 ret = 1;
464 if (safi)
465 *safi = SAFI_EVPN;
7c40bf39 466 } else if (argv_find(argv, argc, "flowspec", index)) {
467 ret = 1;
468 if (safi)
469 *safi = SAFI_FLOWSPEC;
d62a17ae 470 }
471 return ret;
46f296b4
LB
472}
473
5d5393b9
DL
474int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
475 enum bgp_instance_type inst_type)
476{
477 int ret = bgp_get(bgp, as, name, inst_type);
478
479 if (ret == BGP_CREATED) {
480 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 481 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
482
483 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 484 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 485 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 486 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
487 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
488 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 489 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 490 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 491 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 492 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
493 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
494 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
495 if (DFLT_BGP_SUPPRESS_DUPLICATES)
496 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
5d5393b9
DL
497
498 ret = BGP_SUCCESS;
499 }
500 return ret;
501}
502
7eeee51e 503/*
f212a857 504 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 505 *
f212a857
DS
506 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
507 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
508 * to appropriate values for the calling function. This is to allow the
509 * calling function to make decisions appropriate for the show command
510 * that is being parsed.
511 *
512 * The show commands are generally of the form:
d62a17ae 513 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
514 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
515 *
516 * Since we use argv_find if the show command in particular doesn't have:
517 * [ip]
18c57037 518 * [<view|vrf> VIEWVRFNAME]
375a2e67 519 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
520 * The command parsing should still be ok.
521 *
522 * vty -> The vty for the command so we can output some useful data in
523 * the event of a parse error in the vrf.
524 * argv -> The command tokens
525 * argc -> How many command tokens we have
d62a17ae 526 * idx -> The current place in the command, generally should be 0 for this
527 * function
7eeee51e
DS
528 * afi -> The parsed afi if it was included in the show command, returned here
529 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 530 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 531 * use_json -> json is configured or not
7eeee51e
DS
532 *
533 * The function returns the correct location in the parse tree for the
534 * last token found.
0e37c258
DS
535 *
536 * Returns 0 for failure to parse correctly, else the idx position of where
537 * it found the last token.
7eeee51e 538 */
d62a17ae 539int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
540 struct cmd_token **argv, int argc,
541 int *idx, afi_t *afi, safi_t *safi,
9f049418 542 struct bgp **bgp, bool use_json)
d62a17ae 543{
544 char *vrf_name = NULL;
545
546 assert(afi);
547 assert(safi);
548 assert(bgp);
549
550 if (argv_find(argv, argc, "ip", idx))
551 *afi = AFI_IP;
552
9a8bdf1c 553 if (argv_find(argv, argc, "view", idx))
d62a17ae 554 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
555 else if (argv_find(argv, argc, "vrf", idx)) {
556 vrf_name = argv[*idx + 1]->arg;
557 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
558 vrf_name = NULL;
559 }
560 if (vrf_name) {
d62a17ae 561 if (strmatch(vrf_name, "all"))
562 *bgp = NULL;
563 else {
564 *bgp = bgp_lookup_by_name(vrf_name);
565 if (!*bgp) {
52e5b8c4
SP
566 if (use_json) {
567 json_object *json = NULL;
568 json = json_object_new_object();
569 json_object_string_add(
570 json, "warning",
571 "View/Vrf is unknown");
572 vty_out(vty, "%s\n",
573 json_object_to_json_string_ext(json,
574 JSON_C_TO_STRING_PRETTY));
575 json_object_free(json);
576 }
ca61fd25
DS
577 else
578 vty_out(vty, "View/Vrf %s is unknown\n",
579 vrf_name);
d62a17ae 580 *idx = 0;
581 return 0;
582 }
583 }
584 } else {
585 *bgp = bgp_get_default();
586 if (!*bgp) {
52e5b8c4
SP
587 if (use_json) {
588 json_object *json = NULL;
589 json = json_object_new_object();
590 json_object_string_add(
591 json, "warning",
592 "Default BGP instance not found");
593 vty_out(vty, "%s\n",
594 json_object_to_json_string_ext(json,
595 JSON_C_TO_STRING_PRETTY));
596 json_object_free(json);
597 }
ca61fd25
DS
598 else
599 vty_out(vty,
600 "Default BGP instance not found\n");
d62a17ae 601 *idx = 0;
602 return 0;
603 }
604 }
605
606 if (argv_find_and_parse_afi(argv, argc, idx, afi))
607 argv_find_and_parse_safi(argv, argc, idx, safi);
608
609 *idx += 1;
610 return *idx;
611}
612
f4b8ec07 613bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 614{
615 struct interface *ifp = NULL;
616
617 if (su->sa.sa_family == AF_INET)
618 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
619 else if (su->sa.sa_family == AF_INET6)
620 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
621 su->sin6.sin6_scope_id,
622 bgp->vrf_id);
623
624 if (ifp)
3dc339cd 625 return true;
d62a17ae 626
3dc339cd 627 return false;
718e3744 628}
629
718e3744 630/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
631/* This is used only for configuration, so disallow if attempted on
632 * a dynamic neighbor.
633 */
d62a17ae 634struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
635{
636 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
637 int ret;
638 union sockunion su;
639 struct peer *peer = NULL;
640 struct peer_group *group = NULL;
641
642 if (!bgp) {
643 return NULL;
644 }
645
646 ret = str2sockunion(peer_str, &su);
647 if (ret == 0) {
648 /* IP address, locate peer. */
649 peer = peer_lookup(bgp, &su);
650 } else {
651 /* Not IP, could match either peer configured on interface or a
652 * group. */
653 peer = peer_lookup_by_conf_if(bgp, peer_str);
654 if (!peer)
655 group = peer_group_lookup(bgp, peer_str);
656 }
657
658 if (peer) {
659 if (peer_dynamic_neighbor(peer)) {
660 vty_out(vty,
661 "%% Operation not allowed on a dynamic neighbor\n");
662 return NULL;
663 }
664
665 return peer;
666 }
667
668 if (group)
669 return group->conf;
670
671 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
672
673 return NULL;
674}
675
f4b8ec07
CS
676int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
677{
678 const char *str = NULL;
679
680 switch (ret) {
681 case BGP_ERR_INVALID_VALUE:
682 str = "Invalid value";
683 break;
684 case BGP_ERR_INVALID_FLAG:
685 str = "Invalid flag";
686 break;
687 case BGP_ERR_PEER_GROUP_SHUTDOWN:
688 str = "Peer-group has been shutdown. Activate the peer-group first";
689 break;
690 case BGP_ERR_PEER_FLAG_CONFLICT:
691 str = "Can't set override-capability and strict-capability-match at the same time";
692 break;
693 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
694 str = "Specify remote-as or peer-group remote AS first";
695 break;
696 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
697 str = "Cannot change the peer-group. Deconfigure first";
698 break;
699 case BGP_ERR_PEER_GROUP_MISMATCH:
700 str = "Peer is not a member of this peer-group";
701 break;
702 case BGP_ERR_PEER_FILTER_CONFLICT:
703 str = "Prefix/distribute list can not co-exist";
704 break;
705 case BGP_ERR_NOT_INTERNAL_PEER:
706 str = "Invalid command. Not an internal neighbor";
707 break;
708 case BGP_ERR_REMOVE_PRIVATE_AS:
709 str = "remove-private-AS cannot be configured for IBGP peers";
710 break;
711 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
712 str = "Local-AS allowed only for EBGP peers";
713 break;
714 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
715 str = "Cannot have local-as same as BGP AS number";
716 break;
717 case BGP_ERR_TCPSIG_FAILED:
718 str = "Error while applying TCP-Sig to session(s)";
719 break;
720 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
721 str = "ebgp-multihop and ttl-security cannot be configured together";
722 break;
723 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
724 str = "ttl-security only allowed for EBGP peers";
725 break;
726 case BGP_ERR_AS_OVERRIDE:
727 str = "as-override cannot be configured for IBGP peers";
728 break;
729 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
730 str = "Invalid limit for number of dynamic neighbors";
731 break;
732 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
733 str = "Dynamic neighbor listen range already exists";
734 break;
735 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
736 str = "Operation not allowed on a dynamic neighbor";
737 break;
738 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
739 str = "Operation not allowed on a directly connected neighbor";
740 break;
741 case BGP_ERR_PEER_SAFI_CONFLICT:
742 str = GR_INVALID;
743 break;
744 case BGP_ERR_GR_INVALID_CMD:
745 str = "The Graceful Restart command used is not valid at this moment.";
746 break;
747 case BGP_ERR_GR_OPERATION_FAILED:
748 str = "The Graceful Restart Operation failed due to an err.";
749 break;
750 case BGP_GR_NO_OPERATION:
751 str = GR_NO_OPER;
752 break;
753 case BGP_ERR_PEER_GROUP_MEMBER:
754 str = "Peer-group member cannot override remote-as of peer-group";
755 break;
756 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
757 str = "Peer-group members must be all internal or all external";
758 break;
759 }
760 if (str) {
761 snprintf(errmsg, errmsg_len, "%s", str);
762 return -1;
763 }
764
765 return 0;
766}
767
d62a17ae 768int bgp_vty_return(struct vty *vty, int ret)
769{
770 const char *str = NULL;
771
772 switch (ret) {
773 case BGP_ERR_INVALID_VALUE:
774 str = "Invalid value";
775 break;
776 case BGP_ERR_INVALID_FLAG:
777 str = "Invalid flag";
778 break;
779 case BGP_ERR_PEER_GROUP_SHUTDOWN:
780 str = "Peer-group has been shutdown. Activate the peer-group first";
781 break;
782 case BGP_ERR_PEER_FLAG_CONFLICT:
783 str = "Can't set override-capability and strict-capability-match at the same time";
784 break;
785 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
786 str = "Specify remote-as or peer-group remote AS first";
787 break;
788 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
789 str = "Cannot change the peer-group. Deconfigure first";
790 break;
791 case BGP_ERR_PEER_GROUP_MISMATCH:
792 str = "Peer is not a member of this peer-group";
793 break;
794 case BGP_ERR_PEER_FILTER_CONFLICT:
795 str = "Prefix/distribute list can not co-exist";
796 break;
797 case BGP_ERR_NOT_INTERNAL_PEER:
798 str = "Invalid command. Not an internal neighbor";
799 break;
800 case BGP_ERR_REMOVE_PRIVATE_AS:
801 str = "remove-private-AS cannot be configured for IBGP peers";
802 break;
803 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
804 str = "Local-AS allowed only for EBGP peers";
805 break;
806 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
807 str = "Cannot have local-as same as BGP AS number";
808 break;
809 case BGP_ERR_TCPSIG_FAILED:
810 str = "Error while applying TCP-Sig to session(s)";
811 break;
812 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
813 str = "ebgp-multihop and ttl-security cannot be configured together";
814 break;
815 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
816 str = "ttl-security only allowed for EBGP peers";
817 break;
818 case BGP_ERR_AS_OVERRIDE:
819 str = "as-override cannot be configured for IBGP peers";
820 break;
821 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
822 str = "Invalid limit for number of dynamic neighbors";
823 break;
824 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
825 str = "Dynamic neighbor listen range already exists";
826 break;
827 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
828 str = "Operation not allowed on a dynamic neighbor";
829 break;
830 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
831 str = "Operation not allowed on a directly connected neighbor";
832 break;
833 case BGP_ERR_PEER_SAFI_CONFLICT:
055679e9 834 str = GR_INVALID;
835 break;
836 case BGP_ERR_GR_INVALID_CMD:
837 str = "The Graceful Restart command used is not valid at this moment.";
838 break;
839 case BGP_ERR_GR_OPERATION_FAILED:
840 str = "The Graceful Restart Operation failed due to an err.";
841 break;
842 case BGP_GR_NO_OPERATION:
843 str = GR_NO_OPER;
d62a17ae 844 break;
845 }
846 if (str) {
847 vty_out(vty, "%% %s\n", str);
848 return CMD_WARNING_CONFIG_FAILED;
849 }
850 return CMD_SUCCESS;
718e3744 851}
852
7aafcaca 853/* BGP clear sort. */
d62a17ae 854enum clear_sort {
855 clear_all,
856 clear_peer,
857 clear_group,
858 clear_external,
859 clear_as
7aafcaca
DS
860};
861
ff8a8a7a
CS
862static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
863 int error, char *errmsg, size_t errmsg_len)
d62a17ae 864{
865 switch (error) {
866 case BGP_ERR_AF_UNCONFIGURED:
ff8a8a7a
CS
867 snprintf(errmsg, errmsg_len,
868 "%%BGP: Enable %s address family for the neighbor %s",
869 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 870 break;
871 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
ff8a8a7a
CS
872 snprintf(
873 errmsg, errmsg_len,
874 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
d62a17ae 875 peer->host);
876 break;
877 default:
878 break;
879 }
7aafcaca
DS
880}
881
dc912615 882static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 883 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
884{
885 int ret = 0;
2adac256 886 struct peer_af *paf;
dc912615
DS
887
888 /* if afi/.safi not specified, spin thru all of them */
889 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
890 afi_t tmp_afi;
891 safi_t tmp_safi;
892
893 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
2adac256
DA
894 paf = peer_af_find(peer, tmp_afi, tmp_safi);
895 if (paf && paf->subgroup)
896 SET_FLAG(paf->subgroup->sflags,
897 SUBGRP_STATUS_FORCE_UPDATES);
898
dc912615
DS
899 if (!peer->afc[tmp_afi][tmp_safi])
900 continue;
901
902 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 903 ret = peer_clear(peer, nnode);
dc912615
DS
904 else
905 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
906 stype);
907 }
908 /* if afi specified and safi not, spin thru safis on this afi */
909 } else if (safi == SAFI_UNSPEC) {
910 safi_t tmp_safi;
911
912 for (tmp_safi = SAFI_UNICAST;
913 tmp_safi < SAFI_MAX; tmp_safi++) {
914 if (!peer->afc[afi][tmp_safi])
915 continue;
916
2adac256
DA
917 paf = peer_af_find(peer, afi, tmp_safi);
918 if (paf && paf->subgroup)
919 SET_FLAG(paf->subgroup->sflags,
920 SUBGRP_STATUS_FORCE_UPDATES);
921
dc912615 922 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 923 ret = peer_clear(peer, nnode);
dc912615
DS
924 else
925 ret = peer_clear_soft(peer, afi,
926 tmp_safi, stype);
927 }
928 /* both afi/safi specified, let the caller know if not defined */
929 } else {
930 if (!peer->afc[afi][safi])
931 return 1;
932
2adac256
DA
933 paf = peer_af_find(peer, afi, safi);
934 if (paf && paf->subgroup)
935 SET_FLAG(paf->subgroup->sflags,
936 SUBGRP_STATUS_FORCE_UPDATES);
937
dc912615 938 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 939 ret = peer_clear(peer, nnode);
dc912615
DS
940 else
941 ret = peer_clear_soft(peer, afi, safi, stype);
942 }
943
944 return ret;
945}
946
7aafcaca 947/* `clear ip bgp' functions. */
ff8a8a7a 948static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 949 enum clear_sort sort, enum bgp_clear_type stype,
ff8a8a7a 950 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 951{
dc912615 952 int ret = 0;
3ae8bfa5 953 bool found = false;
d62a17ae 954 struct peer *peer;
dc95985f 955
956 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 957
958 /* Clear all neighbors. */
959 /*
960 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
961 * nodes on the BGP instance as that may get freed if it is a
962 * doppelganger
d62a17ae 963 */
964 if (sort == clear_all) {
965 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 966
967 bgp_peer_gr_flags_update(peer);
968
36235319 969 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 970 gr_router_detected = true;
971
c368171c 972 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 973 stype);
d62a17ae 974
975 if (ret < 0)
ff8a8a7a
CS
976 bgp_clear_vty_error(peer, afi, safi, ret,
977 errmsg, errmsg_len);
dc95985f 978 }
979
36235319
QY
980 if (gr_router_detected
981 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 982 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
983 } else if (!gr_router_detected
984 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 985 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 986 }
d62a17ae 987
988 /* This is to apply read-only mode on this clear. */
989 if (stype == BGP_CLEAR_SOFT_NONE)
990 bgp->update_delay_over = 0;
991
992 return CMD_SUCCESS;
7aafcaca
DS
993 }
994
3ae8bfa5 995 /* Clear specified neighbor. */
d62a17ae 996 if (sort == clear_peer) {
997 union sockunion su;
d62a17ae 998
999 /* Make sockunion for lookup. */
1000 ret = str2sockunion(arg, &su);
1001 if (ret < 0) {
1002 peer = peer_lookup_by_conf_if(bgp, arg);
1003 if (!peer) {
1004 peer = peer_lookup_by_hostname(bgp, arg);
1005 if (!peer) {
ff8a8a7a
CS
1006 snprintf(
1007 errmsg, errmsg_len,
1008 "Malformed address or name: %s",
d62a17ae 1009 arg);
1010 return CMD_WARNING;
1011 }
1012 }
1013 } else {
1014 peer = peer_lookup(bgp, &su);
1015 if (!peer) {
ff8a8a7a
CS
1016 snprintf(errmsg, errmsg_len,
1017 "%%BGP: Unknown neighbor - \"%s\"",
1018 arg);
d62a17ae 1019 return CMD_WARNING;
1020 }
1021 }
7aafcaca 1022
dc95985f 1023 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1024 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1025
dc912615
DS
1026 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1027
1028 /* if afi/safi not defined for this peer, let caller know */
1029 if (ret == 1)
3ae8bfa5 1030 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1031
d62a17ae 1032 if (ret < 0)
ff8a8a7a
CS
1033 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1034 errmsg_len);
7aafcaca 1035
d62a17ae 1036 return CMD_SUCCESS;
7aafcaca 1037 }
7aafcaca 1038
3ae8bfa5 1039 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1040 if (sort == clear_group) {
1041 struct peer_group *group;
7aafcaca 1042
d62a17ae 1043 group = peer_group_lookup(bgp, arg);
1044 if (!group) {
ff8a8a7a
CS
1045 snprintf(errmsg, errmsg_len,
1046 "%%BGP: No such peer-group %s", arg);
d62a17ae 1047 return CMD_WARNING;
1048 }
1049
1050 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1051 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1052
d62a17ae 1053 if (ret < 0)
ff8a8a7a
CS
1054 bgp_clear_vty_error(peer, afi, safi, ret,
1055 errmsg, errmsg_len);
3ae8bfa5
PM
1056 else
1057 found = true;
d62a17ae 1058 }
3ae8bfa5
PM
1059
1060 if (!found)
ff8a8a7a
CS
1061 snprintf(
1062 errmsg, errmsg_len,
1063 "%%BGP: No %s peer belonging to peer-group %s is configured",
5cb5f4d0 1064 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1065
d62a17ae 1066 return CMD_SUCCESS;
7aafcaca 1067 }
7aafcaca 1068
3ae8bfa5 1069 /* Clear all external (eBGP) neighbors. */
d62a17ae 1070 if (sort == clear_external) {
1071 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1072 if (peer->sort == BGP_PEER_IBGP)
1073 continue;
7aafcaca 1074
dc95985f 1075 bgp_peer_gr_flags_update(peer);
1076
36235319 1077 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1078 gr_router_detected = true;
dc95985f 1079
c368171c 1080 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1081
d62a17ae 1082 if (ret < 0)
ff8a8a7a
CS
1083 bgp_clear_vty_error(peer, afi, safi, ret,
1084 errmsg, errmsg_len);
3ae8bfa5
PM
1085 else
1086 found = true;
d62a17ae 1087 }
3ae8bfa5 1088
36235319
QY
1089 if (gr_router_detected
1090 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1091 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1092 } else if (!gr_router_detected
1093 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1094 bgp_zebra_send_capabilities(bgp, true);
1095 }
1096
3ae8bfa5 1097 if (!found)
ff8a8a7a
CS
1098 snprintf(errmsg, errmsg_len,
1099 "%%BGP: No external %s peer is configured",
1100 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1101
d62a17ae 1102 return CMD_SUCCESS;
1103 }
1104
3ae8bfa5 1105 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1106 if (sort == clear_as) {
3ae8bfa5 1107 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1108
1109 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1110 if (peer->as != as)
1111 continue;
1112
dc95985f 1113 bgp_peer_gr_flags_update(peer);
1114
36235319 1115 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1116 gr_router_detected = true;
dc95985f 1117
c368171c 1118 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1119
1120 if (ret < 0)
ff8a8a7a
CS
1121 bgp_clear_vty_error(peer, afi, safi, ret,
1122 errmsg, errmsg_len);
3ae8bfa5
PM
1123 else
1124 found = true;
d62a17ae 1125 }
3ae8bfa5 1126
36235319
QY
1127 if (gr_router_detected
1128 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1129 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1130 } else if (!gr_router_detected
1131 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1132 bgp_zebra_send_capabilities(bgp, true);
1133 }
1134
3ae8bfa5 1135 if (!found)
ff8a8a7a
CS
1136 snprintf(errmsg, errmsg_len,
1137 "%%BGP: No %s peer is configured with AS %s",
1138 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1139
d62a17ae 1140 return CMD_SUCCESS;
1141 }
1142
1143 return CMD_SUCCESS;
1144}
1145
ff8a8a7a
CS
1146static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1147 enum clear_sort sort, enum bgp_clear_type stype,
1148 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1149{
1150 struct bgp *bgp;
1151
1152 /* BGP structure lookup. */
1153 if (name) {
1154 bgp = bgp_lookup_by_name(name);
1155 if (bgp == NULL) {
ff8a8a7a
CS
1156 snprintf(errmsg, errmsg_len,
1157 "Can't find BGP instance %s", name);
d62a17ae 1158 return CMD_WARNING;
1159 }
1160 } else {
1161 bgp = bgp_get_default();
1162 if (bgp == NULL) {
ff8a8a7a
CS
1163 snprintf(errmsg, errmsg_len,
1164 "No BGP process is configured");
d62a17ae 1165 return CMD_WARNING;
1166 }
1167 }
1168
ff8a8a7a 1169 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
7aafcaca
DS
1170}
1171
1172/* clear soft inbound */
ff8a8a7a 1173int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1174{
99b3ebd3
NS
1175 afi_t afi;
1176 safi_t safi;
ff8a8a7a
CS
1177 int ret;
1178
1179 FOREACH_AFI_SAFI (afi, safi) {
1180 ret = bgp_clear_vty(name, afi, safi, clear_all,
1181 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1182 errmsg_len);
1183 if (ret != CMD_SUCCESS)
1184 return -1;
1185 }
99b3ebd3 1186
ff8a8a7a 1187 return 0;
7aafcaca
DS
1188}
1189
1190/* clear soft outbound */
ff8a8a7a 1191int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1192{
99b3ebd3
NS
1193 afi_t afi;
1194 safi_t safi;
ff8a8a7a 1195 int ret;
99b3ebd3 1196
ff8a8a7a
CS
1197 FOREACH_AFI_SAFI (afi, safi) {
1198 ret = bgp_clear_vty(name, afi, safi, clear_all,
1199 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1200 errmsg_len);
1201 if (ret != CMD_SUCCESS)
1202 return -1;
1203 }
1204
1205 return 0;
7aafcaca
DS
1206}
1207
1208
f787d7a0 1209#ifndef VTYSH_EXTRACT_PL
2e4c2296 1210#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1211#endif
1212
8029b216
AK
1213DEFUN_HIDDEN (bgp_local_mac,
1214 bgp_local_mac_cmd,
093e3f23 1215 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1216 BGP_STR
1217 "Local MAC config\n"
1218 "VxLAN Network Identifier\n"
1219 "VNI number\n"
1220 "local mac\n"
1221 "mac address\n"
1222 "mac-mobility sequence\n"
1223 "seq number\n")
1224{
1225 int rv;
1226 vni_t vni;
1227 struct ethaddr mac;
1228 struct ipaddr ip;
1229 uint32_t seq;
1230 struct bgp *bgp;
1231
1232 vni = strtoul(argv[3]->arg, NULL, 10);
1233 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1234 vty_out(vty, "%% Malformed MAC address\n");
1235 return CMD_WARNING;
1236 }
1237 memset(&ip, 0, sizeof(ip));
1238 seq = strtoul(argv[7]->arg, NULL, 10);
1239
1240 bgp = bgp_get_default();
1241 if (!bgp) {
1242 vty_out(vty, "Default BGP instance is not there\n");
1243 return CMD_WARNING;
1244 }
1245
b5e140c8
AK
1246 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1247 zero_esi);
8029b216
AK
1248 if (rv < 0) {
1249 vty_out(vty, "Internal error\n");
1250 return CMD_WARNING;
1251 }
1252
1253 return CMD_SUCCESS;
1254}
1255
1256DEFUN_HIDDEN (no_bgp_local_mac,
1257 no_bgp_local_mac_cmd,
093e3f23 1258 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1259 NO_STR
1260 BGP_STR
1261 "Local MAC config\n"
1262 "VxLAN Network Identifier\n"
1263 "VNI number\n"
1264 "local mac\n"
1265 "mac address\n")
1266{
1267 int rv;
1268 vni_t vni;
1269 struct ethaddr mac;
1270 struct ipaddr ip;
1271 struct bgp *bgp;
1272
1273 vni = strtoul(argv[4]->arg, NULL, 10);
1274 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1275 vty_out(vty, "%% Malformed MAC address\n");
1276 return CMD_WARNING;
1277 }
1278 memset(&ip, 0, sizeof(ip));
1279
1280 bgp = bgp_get_default();
1281 if (!bgp) {
1282 vty_out(vty, "Default BGP instance is not there\n");
1283 return CMD_WARNING;
1284 }
1285
ec0ab544 1286 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1287 if (rv < 0) {
1288 vty_out(vty, "Internal error\n");
1289 return CMD_WARNING;
1290 }
1291
1292 return CMD_SUCCESS;
1293}
1294
718e3744 1295DEFUN (no_synchronization,
1296 no_synchronization_cmd,
1297 "no synchronization",
1298 NO_STR
1299 "Perform IGP synchronization\n")
1300{
d62a17ae 1301 return CMD_SUCCESS;
718e3744 1302}
1303
1304DEFUN (no_auto_summary,
1305 no_auto_summary_cmd,
1306 "no auto-summary",
1307 NO_STR
1308 "Enable automatic network number summarization\n")
1309{
d62a17ae 1310 return CMD_SUCCESS;
718e3744 1311}
3d515fd9 1312
718e3744 1313/* "router bgp" commands. */
ff8a8a7a
CS
1314DEFUN_YANG_NOSH(router_bgp,
1315 router_bgp_cmd,
1316 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1317 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1318{
d62a17ae 1319 int idx_asn = 2;
1320 int idx_view_vrf = 3;
1321 int idx_vrf = 4;
ff8a8a7a 1322 int ret = CMD_SUCCESS;
d62a17ae 1323 as_t as;
1324 struct bgp *bgp;
1325 const char *name = NULL;
ff8a8a7a 1326 char as_str[12] = {'\0'};
d62a17ae 1327 enum bgp_instance_type inst_type;
ff8a8a7a 1328 char base_xpath[XPATH_MAXLEN];
d62a17ae 1329
1330 // "router bgp" without an ASN
1331 if (argc == 2) {
1332 // Pending: Make VRF option available for ASN less config
1333 bgp = bgp_get_default();
1334
1335 if (bgp == NULL) {
1336 vty_out(vty, "%% No BGP process is configured\n");
1337 return CMD_WARNING_CONFIG_FAILED;
1338 }
1339
1340 if (listcount(bm->bgp) > 1) {
996c9314 1341 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1342 return CMD_WARNING_CONFIG_FAILED;
1343 }
ff8a8a7a
CS
1344
1345 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
5ce106b7 1346 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
ff8a8a7a
CS
1347
1348 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1349 snprintf(as_str, 12, "%d", bgp->as);
87ce2564
CS
1350 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1351 as_str);
ff8a8a7a 1352 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1353 nb_cli_enqueue_change(vty,
1354 "./global/instance-type-view",
ff8a8a7a
CS
1355 NB_OP_MODIFY, "true");
1356 }
1357
a5ab756f 1358 nb_cli_pending_commit_check(vty);
ff8a8a7a
CS
1359 ret = nb_cli_apply_changes(vty, base_xpath);
1360 if (ret == CMD_SUCCESS) {
1361 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1362
1363 /*
1364 * For backward compatibility with old commands we still
1365 * need to use the qobj infrastructure.
1366 */
1367 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1368 }
1369 return ret;
d62a17ae 1370 }
1371
1372 // "router bgp X"
1373 else {
d62a17ae 1374
ff8a8a7a 1375 as = strtoul(argv[idx_asn]->arg, NULL, 10);
d62a17ae 1376 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1377 if (argc > 3) {
1378 name = argv[idx_vrf]->arg;
1379
9a8bdf1c
PG
1380 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1381 if (strmatch(name, VRF_DEFAULT_NAME))
1382 name = NULL;
1383 else
1384 inst_type = BGP_INSTANCE_TYPE_VRF;
ff8a8a7a 1385 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
d62a17ae 1386 inst_type = BGP_INSTANCE_TYPE_VIEW;
ff8a8a7a 1387 }
d62a17ae 1388 }
ff8a8a7a
CS
1389 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1390 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1391
1392 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
87ce2564 1393 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
ff8a8a7a
CS
1394 argv[idx_asn]->arg);
1395 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1396 nb_cli_enqueue_change(vty,
1397 "./global/instance-type-view",
ff8a8a7a 1398 NB_OP_MODIFY, "true");
d62a17ae 1399 }
1400
ff8a8a7a
CS
1401 nb_cli_pending_commit_check(vty);
1402 ret = nb_cli_apply_changes(vty, base_xpath);
1403 if (ret == CMD_SUCCESS) {
1404 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
3bd70bf8 1405
ff8a8a7a
CS
1406 /*
1407 * For backward compatibility with old commands we still
1408 * need to use the qobj infrastructure.
1409 */
1410 bgp = bgp_lookup(as, name);
1411 if (bgp)
1412 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1413 }
d62a17ae 1414 }
1415
ff8a8a7a 1416 return ret;
718e3744 1417}
1418
718e3744 1419/* "no router bgp" commands. */
ff8a8a7a
CS
1420DEFUN_YANG(no_router_bgp,
1421 no_router_bgp_cmd,
1422 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1423 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1424{
d62a17ae 1425 int idx_asn = 3;
1426 int idx_vrf = 5;
ff8a8a7a 1427 as_t as = 0;
d62a17ae 1428 struct bgp *bgp;
1429 const char *name = NULL;
ff8a8a7a 1430 char base_xpath[XPATH_MAXLEN];
4b63e358 1431 const struct lyd_node *bgp_glb_dnode;
718e3744 1432
d62a17ae 1433 // "no router bgp" without an ASN
1434 if (argc == 3) {
1435 // Pending: Make VRF option available for ASN less config
4b63e358
CS
1436 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1437 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
718e3744 1438
4b63e358
CS
1439 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1440 base_xpath);
1441 if (!bgp_glb_dnode) {
d62a17ae 1442 vty_out(vty, "%% No BGP process is configured\n");
1443 return CMD_WARNING_CONFIG_FAILED;
1444 }
7fb21a9f 1445
d62a17ae 1446 if (listcount(bm->bgp) > 1) {
996c9314 1447 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1448 return CMD_WARNING_CONFIG_FAILED;
1449 }
0b5131c9 1450
4b63e358
CS
1451 /* tcli mode bgp would not be set until apply stage. */
1452 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1453 if (!bgp)
1454 return CMD_SUCCESS;
1455
0b5131c9
MK
1456 if (bgp->l3vni) {
1457 vty_out(vty, "%% Please unconfigure l3vni %u",
1458 bgp->l3vni);
1459 return CMD_WARNING_CONFIG_FAILED;
1460 }
d62a17ae 1461 } else {
1462 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1463
d62a17ae 1464 if (argc > 4)
1465 name = argv[idx_vrf]->arg;
7fb21a9f 1466
d62a17ae 1467 /* Lookup bgp structure. */
1468 bgp = bgp_lookup(as, name);
1469 if (!bgp) {
1470 vty_out(vty, "%% Can't find BGP instance\n");
1471 return CMD_WARNING_CONFIG_FAILED;
1472 }
0b5131c9
MK
1473
1474 if (bgp->l3vni) {
dd5868c2 1475 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1476 bgp->l3vni);
1477 return CMD_WARNING_CONFIG_FAILED;
1478 }
dd5868c2
DS
1479
1480 /* Cannot delete default instance if vrf instances exist */
1481 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1482 struct listnode *node;
1483 struct bgp *tmp_bgp;
1484
1485 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
999e803f
PG
1486 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1487 continue;
1488 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1489 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1490 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1491 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1492 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1493 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1494 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1495 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1496 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1497 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1498 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1499 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1500 (bgp == bgp_get_evpn() &&
1501 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1502 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST) ||
1503 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1504 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST))) ||
1505 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
dd5868c2
DS
1506 vty_out(vty,
1507 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1508 return CMD_WARNING_CONFIG_FAILED;
1509 }
1510 }
1511 }
d62a17ae 1512 }
ff8a8a7a
CS
1513 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1514 "frr-bgp:bgp", "bgp",
1515 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
718e3744 1516
ff8a8a7a 1517 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
718e3744 1518
ff8a8a7a 1519 return nb_cli_apply_changes(vty, base_xpath);
718e3744 1520}
1521
ff8a8a7a
CS
1522void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1523 bool show_defaults)
1524{
1525 const struct lyd_node *vrf_dnode;
1526 const char *vrf_name;
1527 as_t as;
6b0655a2 1528
ff8a8a7a
CS
1529 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1530 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
5e42cb2f 1531 as = yang_dnode_get_uint32(dnode, "./global/local-as");
718e3744 1532
ff8a8a7a
CS
1533 vty_out(vty, "!\n");
1534 vty_out(vty, "router bgp %u", as);
1535 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1536 vty_out(vty, " vrf %s", vrf_name);
1537 vty_out(vty, "\n");
718e3744 1538}
1539
ff8a8a7a
CS
1540/* BGP router-id. */
1541
1542DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1543 BGP_STR
1544 "Override configured router identifier\n"
1545 "Manually configured router identifier\n")
718e3744 1546{
87ce2564
CS
1547 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1548 router_id_str);
718e3744 1549
ff8a8a7a
CS
1550 return nb_cli_apply_changes(vty, NULL);
1551}
718e3744 1552
ff8a8a7a
CS
1553DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1554 NO_STR BGP_STR
1555 "Override configured router identifier\n"
1556 "Manually configured router identifier\n")
1557{
87ce2564 1558 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
ff8a8a7a 1559 router_id_str ? router_id_str : NULL);
718e3744 1560
ff8a8a7a 1561 return nb_cli_apply_changes(vty, NULL);
718e3744 1562}
1563
ff8a8a7a
CS
1564void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1565 bool show_defaults)
1566{
1567 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1568}
6b0655a2 1569
9acb67cb
DS
1570DEFPY (bgp_global_suppress_fib_pending,
1571 bgp_global_suppress_fib_pending_cmd,
1572 "[no] bgp suppress-fib-pending",
1573 NO_STR
1574 BGP_STR
1575 "Advertise only routes that are programmed in kernel to peers globally\n")
1576{
1577 bm_wait_for_fib_set(!no);
1578
1579 return CMD_SUCCESS;
1580}
1581
c208c586
S
1582DEFPY (bgp_suppress_fib_pending,
1583 bgp_suppress_fib_pending_cmd,
1584 "[no] bgp suppress-fib-pending",
1585 NO_STR
1586 BGP_STR
1587 "Advertise only routes that are programmed in kernel to peers\n")
1588{
1589 VTY_DECLVAR_CONTEXT(bgp, bgp);
1590
1591 bgp_suppress_fib_pending_set(bgp, !no);
1592 return CMD_SUCCESS;
1593}
1594
1595
718e3744 1596/* BGP Cluster ID. */
ff8a8a7a
CS
1597DEFUN_YANG(bgp_cluster_id,
1598 bgp_cluster_id_cmd,
1599 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1600 BGP_STR
1601 "Configure Route-Reflector Cluster-id\n"
1602 "Route-Reflector Cluster-id in IP address format\n"
1603 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1604{
d62a17ae 1605 int idx_ipv4 = 2;
718e3744 1606
87ce2564
CS
1607 nb_cli_enqueue_change(
1608 vty, "./global/route-reflector/route-reflector-cluster-id",
1609 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1610
ff8a8a7a 1611 return nb_cli_apply_changes(vty, NULL);
718e3744 1612}
1613
ff8a8a7a
CS
1614DEFUN_YANG(no_bgp_cluster_id,
1615 no_bgp_cluster_id_cmd,
1616 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1617 NO_STR BGP_STR
1618 "Configure Route-Reflector Cluster-id\n"
1619 "Route-Reflector Cluster-id in IP address format\n"
1620 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1621{
87ce2564
CS
1622 nb_cli_enqueue_change(
1623 vty, "./global/route-reflector/route-reflector-cluster-id",
1624 NB_OP_DESTROY, NULL);
718e3744 1625
ff8a8a7a 1626 return nb_cli_apply_changes(vty, NULL);
718e3744 1627}
1628
c163f297
DS
1629DEFPY (bgp_norib,
1630 bgp_norib_cmd,
1631 "bgp no-rib",
1632 BGP_STR
1633 "Disable BGP route installation to RIB (Zebra)\n")
1634{
1635 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1636 vty_out(vty,
1637 "%% No-RIB option is already set, nothing to do here.\n");
1638 return CMD_SUCCESS;
1639 }
1640
1641 bgp_option_norib_set_runtime();
1642
1643 return CMD_SUCCESS;
1644}
1645
1646DEFPY (no_bgp_norib,
1647 no_bgp_norib_cmd,
1648 "no bgp no-rib",
1649 NO_STR
1650 BGP_STR
1651 "Disable BGP route installation to RIB (Zebra)\n")
1652{
1653 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1654 vty_out(vty,
1655 "%% No-RIB option is not set, nothing to do here.\n");
1656 return CMD_SUCCESS;
1657 }
1658
1659 bgp_option_norib_unset_runtime();
1660
1661 return CMD_SUCCESS;
1662}
1663
e46723a5
DS
1664DEFPY (no_bgp_send_extra_data,
1665 no_bgp_send_extra_data_cmd,
1666 "[no] bgp send-extra-data zebra",
1667 NO_STR
1668 BGP_STR
1669 "Extra data to Zebra for display/use\n"
1670 "To zebra\n")
1671{
ec0acb80
DA
1672 if (no)
1673 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1674 else
1675 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1676
1677 return CMD_SUCCESS;
1678}
1679
ff8a8a7a
CS
1680DEFUN_YANG(bgp_confederation_identifier,
1681 bgp_confederation_identifier_cmd,
1682 "bgp confederation identifier (1-4294967295)",
1683 "BGP specific commands\n"
1684 "AS confederation parameters\n"
1685 "AS number\n"
1686 "Set routing domain confederation AS\n")
718e3744 1687{
d62a17ae 1688 int idx_number = 3;
718e3744 1689
87ce2564
CS
1690 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1691 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1692
ff8a8a7a 1693 return nb_cli_apply_changes(vty, NULL);
718e3744 1694}
1695
ff8a8a7a
CS
1696DEFUN_YANG(no_bgp_confederation_identifier,
1697 no_bgp_confederation_identifier_cmd,
1698 "no bgp confederation identifier [(1-4294967295)]",
1699 NO_STR
1700 "BGP specific commands\n"
1701 "AS confederation parameters\n"
1702 "AS number\n"
1703 "Set routing domain confederation AS\n")
718e3744 1704{
87ce2564
CS
1705 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1706 NB_OP_DESTROY, NULL);
718e3744 1707
ff8a8a7a 1708 return nb_cli_apply_changes(vty, NULL);
718e3744 1709}
1710
ff8a8a7a
CS
1711void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1712 struct lyd_node *dnode,
1713 bool show_defaults)
1714{
1715 vty_out(vty, " bgp confederation identifier %u\n",
1716 yang_dnode_get_uint32(dnode, NULL));
1717}
1718
1719DEFUN_YANG(bgp_confederation_peers,
1720 bgp_confederation_peers_cmd,
1721 "bgp confederation peers (1-4294967295)...",
1722 "BGP specific commands\n"
1723 "AS confederation parameters\n"
1724 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1725{
d62a17ae 1726 int idx_asn = 3;
d62a17ae 1727 int i;
718e3744 1728
ff8a8a7a 1729 for (i = idx_asn; i < argc; i++)
87ce2564 1730 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1731 NB_OP_CREATE, argv[i]->arg);
718e3744 1732
ff8a8a7a 1733 return nb_cli_apply_changes(vty, NULL);
718e3744 1734}
1735
ff8a8a7a
CS
1736DEFUN_YANG(no_bgp_confederation_peers,
1737 no_bgp_confederation_peers_cmd,
1738 "no bgp confederation peers (1-4294967295)...",
1739 NO_STR
1740 "BGP specific commands\n"
1741 "AS confederation parameters\n"
1742 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1743{
d62a17ae 1744 int idx_asn = 4;
d62a17ae 1745 int i;
718e3744 1746
ff8a8a7a 1747 for (i = idx_asn; i < argc; i++)
87ce2564 1748 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1749 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1750
ff8a8a7a
CS
1751 return nb_cli_apply_changes(vty, NULL);
1752}
1753
1754void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1755 struct lyd_node *dnode,
1756 bool show_defaults)
1757{
1758 vty_out(vty, " bgp confederation peers %u \n",
1759 yang_dnode_get_uint32(dnode, NULL));
718e3744 1760}
6b0655a2 1761
5e242b0d
DS
1762/**
1763 * Central routine for maximum-paths configuration.
1764 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1765 * @set: 1 for setting values, 0 for removing the max-paths config.
1766 */
37a87b8f
CS
1767int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1768 int peer_type, uint16_t maxpaths, uint16_t options,
1769 int set, char *errmsg, size_t errmsg_len)
d62a17ae 1770{
d62a17ae 1771 int ret;
d62a17ae 1772
1773 if (set) {
d62a17ae 1774 if (maxpaths > multipath_num) {
37a87b8f
CS
1775 snprintf(
1776 errmsg, errmsg_len,
d62a17ae 1777 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1778 maxpaths, multipath_num);
1779 return CMD_WARNING_CONFIG_FAILED;
1780 }
1781 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1782 options);
1783 } else
1784 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1785
1786 if (ret < 0) {
37a87b8f
CS
1787 snprintf(
1788 errmsg, errmsg_len,
d62a17ae 1789 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1790 (set == 1) ? "" : "un",
1791 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1792 maxpaths, afi, safi);
1793 return CMD_WARNING_CONFIG_FAILED;
1794 }
1795
1796 bgp_recalculate_all_bestpaths(bgp);
1797
1798 return CMD_SUCCESS;
165b5fff
JB
1799}
1800
ff8a8a7a
CS
1801void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1802 bool show_defaults)
abc920f8 1803{
ff8a8a7a
CS
1804 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1805 uint32_t med_admin_val;
abc920f8 1806
ff8a8a7a
CS
1807 vty_out(vty, " bgp max-med administrative");
1808 if ((med_admin_val =
1809 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1810 != BGP_MAXMED_VALUE_DEFAULT)
1811 vty_out(vty, " %u", med_admin_val);
1812 vty_out(vty, "\n");
1813 }
abc920f8 1814
ff8a8a7a
CS
1815 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1816 uint32_t onstartup_val;
abc920f8 1817
ff8a8a7a
CS
1818 vty_out(vty, " bgp max-med on-startup %u",
1819 yang_dnode_get_uint32(dnode,
1820 "./max-med-onstart-up-time"));
1821 onstartup_val = yang_dnode_get_uint32(
1822 dnode, "./max-med-onstart-up-value");
1823 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1824 vty_out(vty, " %u", onstartup_val);
1825
1826 vty_out(vty, "\n");
1827 }
abc920f8
DS
1828}
1829
ff8a8a7a
CS
1830DEFUN_YANG(bgp_maxmed_admin,
1831 bgp_maxmed_admin_cmd,
1832 "bgp max-med administrative ",
1833 BGP_STR
1834 "Advertise routes with max-med\n"
1835 "Administratively applied, for an indefinite period\n")
1836{
87ce2564 1837 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1838 NB_OP_MODIFY, "true");
1839
1840 return nb_cli_apply_changes(vty, NULL);
1841}
1842
1843DEFUN_YANG(bgp_maxmed_admin_medv,
1844 bgp_maxmed_admin_medv_cmd,
1845 "bgp max-med administrative (0-4294967295)",
1846 BGP_STR
1847 "Advertise routes with max-med\n"
1848 "Administratively applied, for an indefinite period\n"
1849 "Max MED value to be used\n")
abc920f8 1850{
d62a17ae 1851 int idx_number = 3;
abc920f8 1852
87ce2564 1853 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1854 NB_OP_MODIFY, "true");
abc920f8 1855
87ce2564
CS
1856 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1857 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1858
ff8a8a7a 1859 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1860}
1861
ff8a8a7a
CS
1862DEFUN_YANG(no_bgp_maxmed_admin,
1863 no_bgp_maxmed_admin_cmd,
1864 "no bgp max-med administrative [(0-4294967295)]",
1865 NO_STR BGP_STR
1866 "Advertise routes with max-med\n"
1867 "Administratively applied, for an indefinite period\n"
1868 "Max MED value to be used\n")
abc920f8 1869{
87ce2564 1870 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1871 NB_OP_MODIFY, "false");
abc920f8 1872
87ce2564
CS
1873 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1874 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1875
1876 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1877}
1878
37a87b8f
CS
1879DEFUN_YANG (bgp_maxmed_onstartup,
1880 bgp_maxmed_onstartup_cmd,
1881 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1882 BGP_STR
1883 "Advertise routes with max-med\n"
1884 "Effective on a startup\n"
1885 "Time (seconds) period for max-med\n"
1886 "Max MED value to be used\n")
abc920f8 1887{
d62a17ae 1888 int idx = 0;
4668a151 1889
d62a17ae 1890 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1891 nb_cli_enqueue_change(vty,
1892 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1893 NB_OP_MODIFY, argv[idx]->arg);
1894
d62a17ae 1895 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1896 nb_cli_enqueue_change(
1897 vty, "./global/med-config/max-med-onstart-up-value",
1898 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1899 else
87ce2564
CS
1900 nb_cli_enqueue_change(
1901 vty, "./global/med-config/max-med-onstart-up-value",
1902 NB_OP_MODIFY, NULL);
abc920f8 1903
ff8a8a7a 1904 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1905}
1906
37a87b8f
CS
1907DEFUN_YANG (no_bgp_maxmed_onstartup,
1908 no_bgp_maxmed_onstartup_cmd,
1909 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1910 NO_STR BGP_STR
1911 "Advertise routes with max-med\n"
1912 "Effective on a startup\n"
1913 "Time (seconds) period for max-med\n"
1914 "Max MED value to be used\n")
abc920f8 1915{
87ce2564
CS
1916 nb_cli_enqueue_change(vty,
1917 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1918 NB_OP_DESTROY, NULL);
abc920f8 1919
87ce2564
CS
1920 nb_cli_enqueue_change(vty,
1921 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1922 NB_OP_MODIFY, NULL);
abc920f8 1923
ff8a8a7a 1924 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1925}
1926
d70583f7
D
1927static int bgp_global_update_delay_config_vty(struct vty *vty,
1928 uint16_t update_delay,
1929 uint16_t establish_wait)
1930{
1931 struct listnode *node, *nnode;
1932 struct bgp *bgp;
1933 bool vrf_cfg = false;
1934
1935 /*
1936 * See if update-delay is set per-vrf and warn user to delete it
1937 * Note that we only need to check this if this is the first time
1938 * setting the global config.
1939 */
1940 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1941 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1942 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1943 vty_out(vty,
1944 "%% update-delay configuration found in vrf %s\n",
1945 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1946 ? VRF_DEFAULT_NAME
1947 : bgp->name);
1948 vrf_cfg = true;
1949 }
1950 }
1951 }
1952
1953 if (vrf_cfg) {
1954 vty_out(vty,
1955 "%%Failed: global update-delay config not permitted\n");
1956 return CMD_WARNING;
1957 }
1958
1959 if (!establish_wait) { /* update-delay <delay> */
1960 bm->v_update_delay = update_delay;
1961 bm->v_establish_wait = bm->v_update_delay;
1962 } else {
1963 /* update-delay <delay> <establish-wait> */
1964 if (update_delay < establish_wait) {
1965 vty_out(vty,
1966 "%%Failed: update-delay less than the establish-wait!\n");
1967 return CMD_WARNING_CONFIG_FAILED;
1968 }
1969
1970 bm->v_update_delay = update_delay;
1971 bm->v_establish_wait = establish_wait;
1972 }
1973
1974 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1975 bgp->v_update_delay = bm->v_update_delay;
1976 bgp->v_establish_wait = bm->v_establish_wait;
1977 }
1978
1979 return CMD_SUCCESS;
1980}
1981
1982static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1983{
1984 struct listnode *node, *nnode;
1985 struct bgp *bgp;
1986
1987 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1988 bm->v_establish_wait = bm->v_update_delay;
1989
1990 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1991 bgp->v_update_delay = bm->v_update_delay;
1992 bgp->v_establish_wait = bm->v_establish_wait;
1993 }
1994
1995 return CMD_SUCCESS;
1996}
1997
1998static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1999 uint16_t establish_wait)
f188f2c4 2000{
d62a17ae 2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2002
d70583f7
D
2003 /* if configured globally, per-instance config is not allowed */
2004 if (bm->v_update_delay) {
2005 vty_out(vty,
2006 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2007 return CMD_WARNING_CONFIG_FAILED;
2008 }
2009
f188f2c4 2010
d70583f7 2011 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2012 {
2013 bgp->v_update_delay = update_delay;
2014 bgp->v_establish_wait = bgp->v_update_delay;
2015 return CMD_SUCCESS;
2016 }
f188f2c4 2017
d62a17ae 2018 /* update-delay <delay> <establish-wait> */
d62a17ae 2019 if (update_delay < establish_wait) {
2020 vty_out(vty,
2021 "%%Failed: update-delay less than the establish-wait!\n");
2022 return CMD_WARNING_CONFIG_FAILED;
2023 }
f188f2c4 2024
d62a17ae 2025 bgp->v_update_delay = update_delay;
2026 bgp->v_establish_wait = establish_wait;
f188f2c4 2027
d62a17ae 2028 return CMD_SUCCESS;
f188f2c4
DS
2029}
2030
d62a17ae 2031static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2032{
d62a17ae 2033 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2034
d70583f7
D
2035 /* If configured globally, cannot remove from one bgp instance */
2036 if (bm->v_update_delay) {
2037 vty_out(vty,
2038 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2039 return CMD_WARNING_CONFIG_FAILED;
2040 }
d62a17ae 2041 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2042 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2043
d62a17ae 2044 return CMD_SUCCESS;
f188f2c4
DS
2045}
2046
2b791107 2047void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2048{
d70583f7
D
2049 /* If configured globally, no need to display per-instance value */
2050 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2051 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2052 if (bgp->v_update_delay != bgp->v_establish_wait)
2053 vty_out(vty, " %d", bgp->v_establish_wait);
2054 vty_out(vty, "\n");
2055 }
f188f2c4
DS
2056}
2057
d70583f7
D
2058/* Global update-delay configuration */
2059DEFPY (bgp_global_update_delay,
2060 bgp_global_update_delay_cmd,
2061 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2062 BGP_STR
2063 "Force initial delay for best-path and updates for all bgp instances\n"
2064 "Max delay in seconds\n"
2065 "Establish wait in seconds\n")
2066{
2067 return bgp_global_update_delay_config_vty(vty, delay, wait);
2068}
f188f2c4 2069
d70583f7
D
2070/* Global update-delay deconfiguration */
2071DEFPY (no_bgp_global_update_delay,
2072 no_bgp_global_update_delay_cmd,
2073 "no bgp update-delay [(0-3600) [(1-3600)]]",
2074 NO_STR
2075 BGP_STR
f188f2c4 2076 "Force initial delay for best-path and updates\n"
d70583f7
D
2077 "Max delay in seconds\n"
2078 "Establish wait in seconds\n")
f188f2c4 2079{
d70583f7 2080 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2081}
2082
d70583f7
D
2083/* Update-delay configuration */
2084
2085DEFPY (bgp_update_delay,
2086 bgp_update_delay_cmd,
2087 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2088 "Force initial delay for best-path and updates\n"
d70583f7
D
2089 "Max delay in seconds\n"
2090 "Establish wait in seconds\n")
f188f2c4 2091{
d70583f7 2092 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2093}
2094
2095/* Update-delay deconfiguration */
d70583f7 2096DEFPY (no_bgp_update_delay,
f188f2c4 2097 no_bgp_update_delay_cmd,
838758ac
DW
2098 "no update-delay [(0-3600) [(1-3600)]]",
2099 NO_STR
f188f2c4 2100 "Force initial delay for best-path and updates\n"
d70583f7
D
2101 "Max delay in seconds\n"
2102 "Establish wait in seconds\n")
f188f2c4 2103{
d62a17ae 2104 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2105}
2106
5e242b0d 2107
ff8a8a7a 2108int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 2109{
8fa7732f
QY
2110 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2111 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2112
2113 return CMD_SUCCESS;
2114}
2115
ff8a8a7a 2116int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 2117{
8fa7732f
QY
2118 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2119 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2120
d62a17ae 2121 return CMD_SUCCESS;
cb1faec9
DS
2122}
2123
2b791107 2124void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2125{
555e09d4
QY
2126 uint32_t quanta =
2127 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2128 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2129 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2130}
2131
555e09d4
QY
2132void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2133{
2134 uint32_t quanta =
2135 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2136 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2137 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2138}
cb1faec9 2139
8fa7732f
QY
2140/* Packet quanta configuration
2141 *
2142 * XXX: The value set here controls the size of a stack buffer in the IO
2143 * thread. When changing these limits be careful to prevent stack overflow.
2144 *
2145 * Furthermore, the maximums used here should correspond to
2146 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2147 */
37a87b8f
CS
2148DEFPY_YANG (bgp_wpkt_quanta,
2149 bgp_wpkt_quanta_cmd,
2150 "[no] write-quanta (1-64)$quanta",
2151 NO_STR
2152 "How many packets to write to peer socket per run\n"
2153 "Number of packets\n")
ff8a8a7a
CS
2154{
2155 if (!no)
2156 nb_cli_enqueue_change(
2157 vty,
87ce2564 2158 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2159 NB_OP_MODIFY, quanta_str);
2160 else
2161 nb_cli_enqueue_change(
2162 vty,
87ce2564 2163 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2164 NB_OP_MODIFY, NULL);
2165
2166 return nb_cli_apply_changes(vty, NULL);
2167}
2168
37a87b8f
CS
2169DEFPY_YANG (bgp_rpkt_quanta,
2170 bgp_rpkt_quanta_cmd,
2171 "[no] read-quanta (1-10)$quanta",
2172 NO_STR
2173 "How many packets to read from peer socket per I/O cycle\n"
2174 "Number of packets\n")
ff8a8a7a
CS
2175{
2176 if (!no)
2177 nb_cli_enqueue_change(
2178 vty,
87ce2564 2179 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2180 NB_OP_MODIFY, quanta_str);
2181 else
2182 nb_cli_enqueue_change(
2183 vty,
87ce2564 2184 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2185 NB_OP_MODIFY, NULL);
cb1faec9 2186
ff8a8a7a 2187 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2188}
2189
2b791107 2190void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2191{
37a333fe 2192 if (!bgp->heuristic_coalesce)
d62a17ae 2193 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2194}
2195
ff8a8a7a
CS
2196void cli_show_router_global_update_group_config_coalesce_time(
2197 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2198{
ff8a8a7a
CS
2199 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2200}
2201
4668a151 2202
37a87b8f
CS
2203DEFUN_YANG (bgp_coalesce_time,
2204 bgp_coalesce_time_cmd,
2205 "coalesce-time (0-4294967295)",
2206 "Subgroup coalesce timer\n"
2207 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2208{
d62a17ae 2209 int idx = 0;
ff8a8a7a 2210
d62a17ae 2211 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2212 nb_cli_enqueue_change(
2213 vty, "./global/global-update-group-config/coalesce-time",
2214 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2215
2216 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2217}
2218
ff8a8a7a
CS
2219DEFUN_YANG(no_bgp_coalesce_time,
2220 no_bgp_coalesce_time_cmd,
2221 "no coalesce-time (0-4294967295)",
2222 NO_STR
2223 "Subgroup coalesce timer\n"
2224 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2225{
87ce2564
CS
2226 nb_cli_enqueue_change(
2227 vty, "./global/global-update-group-config/coalesce-time",
2228 NB_OP_MODIFY, NULL);
4668a151 2229
ff8a8a7a 2230 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2231}
2232
5e242b0d 2233/* Maximum-paths configuration */
37a87b8f
CS
2234DEFUN_YANG (bgp_maxpaths,
2235 bgp_maxpaths_cmd,
2236 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2237 "Forward packets over multiple paths\n"
2238 "Number of paths\n")
5e242b0d 2239{
d62a17ae 2240 int idx_number = 1;
37a87b8f
CS
2241 char base_xpath[XPATH_MAXLEN];
2242 afi_t afi;
2243 safi_t safi;
2244
2245 afi = bgp_node_afi(vty);
2246 safi = bgp_node_safi(vty);
2247
2248 snprintf(
2249 base_xpath, sizeof(base_xpath),
2250 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2251 yang_afi_safi_value2identity(afi, safi),
2252 bgp_afi_safi_get_container_str(afi, safi));
2253
2254 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2255 argv[idx_number]->arg);
2256
2257 return nb_cli_apply_changes(vty, NULL);
2258}
2259
2260void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2261 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2262{
2263 vty_out(vty, " maximum-paths %d\n",
2264 yang_dnode_get_uint16(dnode, NULL));
5e242b0d
DS
2265}
2266
d62a17ae 2267ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2268 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2269 "Forward packets over multiple paths\n"
2270 "Number of paths\n")
596c17ba 2271
37a87b8f
CS
2272DEFUN_YANG (bgp_maxpaths_ibgp,
2273 bgp_maxpaths_ibgp_cmd,
2274 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2275 "Forward packets over multiple paths\n"
2276 "iBGP-multipath\n"
2277 "Number of paths\n")
165b5fff 2278{
d62a17ae 2279 int idx_number = 2;
37a87b8f
CS
2280 char base_xpath[XPATH_MAXLEN];
2281 afi_t afi;
2282 safi_t safi;
2283
2284 afi = bgp_node_afi(vty);
2285 safi = bgp_node_safi(vty);
2286
2287 snprintf(
2288 base_xpath, sizeof(base_xpath),
2289 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2290 yang_afi_safi_value2identity(afi, safi),
2291 bgp_afi_safi_get_container_str(afi, safi));
2292
2293 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2294 argv[idx_number]->arg);
2295
2296 return nb_cli_apply_changes(vty, NULL);
5e242b0d 2297}
165b5fff 2298
d62a17ae 2299ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2300 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2301 "Forward packets over multiple paths\n"
2302 "iBGP-multipath\n"
2303 "Number of paths\n")
596c17ba 2304
37a87b8f
CS
2305DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2306 bgp_maxpaths_ibgp_cluster_cmd,
2307 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2308 "Forward packets over multiple paths\n"
2309 "iBGP-multipath\n"
2310 "Number of paths\n"
2311 "Match the cluster length\n")
5e242b0d 2312{
d62a17ae 2313 int idx_number = 2;
37a87b8f
CS
2314 char base_xpath[XPATH_MAXLEN];
2315 afi_t afi;
2316 safi_t safi;
2317
2318 afi = bgp_node_afi(vty);
2319 safi = bgp_node_safi(vty);
2320
2321 snprintf(
2322 base_xpath, sizeof(base_xpath),
2323 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2324 yang_afi_safi_value2identity(afi, safi),
2325 bgp_afi_safi_get_container_str(afi, safi));
2326
2327 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2328 argv[idx_number]->arg);
2329
2330 snprintf(
2331 base_xpath, sizeof(base_xpath),
2332 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2333 yang_afi_safi_value2identity(afi, safi),
2334 bgp_afi_safi_get_container_str(afi, safi));
2335
2336 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2337
2338 return nb_cli_apply_changes(vty, NULL);
2339}
2340
2341void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2342 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2343{
2344 vty_out(vty, " maximum-paths ibgp %d",
2345 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2346 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2347 vty_out(vty, " equal-cluster-length");
2348 vty_out(vty, "\n");
165b5fff
JB
2349}
2350
d62a17ae 2351ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2352 "maximum-paths ibgp " CMD_RANGE_STR(
2353 1, MULTIPATH_NUM) " equal-cluster-length",
2354 "Forward packets over multiple paths\n"
2355 "iBGP-multipath\n"
2356 "Number of paths\n"
2357 "Match the cluster length\n")
596c17ba 2358
37a87b8f
CS
2359DEFUN_YANG (no_bgp_maxpaths,
2360 no_bgp_maxpaths_cmd,
2361 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2362 NO_STR
2363 "Forward packets over multiple paths\n"
2364 "Number of paths\n")
165b5fff 2365{
37a87b8f
CS
2366 char base_xpath[XPATH_MAXLEN];
2367 afi_t afi;
2368 safi_t safi;
2369
2370 afi = bgp_node_afi(vty);
2371 safi = bgp_node_safi(vty);
2372
2373 snprintf(
2374 base_xpath, sizeof(base_xpath),
2375 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2376 yang_afi_safi_value2identity(afi, safi),
2377 bgp_afi_safi_get_container_str(afi, safi));
2378
2379 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2380
2381 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2382}
2383
d62a17ae 2384ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2385 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2386 "Forward packets over multiple paths\n"
2387 "Number of paths\n")
596c17ba 2388
37a87b8f
CS
2389DEFUN_YANG (no_bgp_maxpaths_ibgp,
2390 no_bgp_maxpaths_ibgp_cmd,
2391 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2392 NO_STR
2393 "Forward packets over multiple paths\n"
2394 "iBGP-multipath\n"
2395 "Number of paths\n"
2396 "Match the cluster length\n")
165b5fff 2397{
37a87b8f
CS
2398 char base_xpath[XPATH_MAXLEN];
2399 afi_t afi;
2400 safi_t safi;
2401
2402 afi = bgp_node_afi(vty);
2403 safi = bgp_node_safi(vty);
2404
2405 snprintf(
2406 base_xpath, sizeof(base_xpath),
2407 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2408 yang_afi_safi_value2identity(afi, safi),
2409 bgp_afi_safi_get_container_str(afi, safi));
2410
2411 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2412
2413 snprintf(
2414 base_xpath, sizeof(base_xpath),
2415 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2416 yang_afi_safi_value2identity(afi, safi),
2417 bgp_afi_safi_get_container_str(afi, safi));
2418
2419 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2420
2421 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2422}
2423
d62a17ae 2424ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2425 "no maximum-paths ibgp [" CMD_RANGE_STR(
2426 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2427 NO_STR
2428 "Forward packets over multiple paths\n"
2429 "iBGP-multipath\n"
2430 "Number of paths\n"
2431 "Match the cluster length\n")
596c17ba 2432
dd65f45e
DL
2433static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2434 afi_t afi, safi_t safi)
165b5fff 2435{
00908b7a 2436 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2437 vty_out(vty, " maximum-paths %d\n",
2438 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2439 }
165b5fff 2440
00908b7a 2441 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2442 vty_out(vty, " maximum-paths ibgp %d",
2443 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2444 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2445 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2446 vty_out(vty, " equal-cluster-length");
2447 vty_out(vty, "\n");
2448 }
165b5fff 2449}
6b0655a2 2450
718e3744 2451/* BGP timers. */
2452
37a87b8f
CS
2453DEFUN_YANG (bgp_timers,
2454 bgp_timers_cmd,
2455 "timers bgp (0-65535) (0-65535)",
2456 "Adjust routing timers\n"
2457 "BGP timers\n"
2458 "Keepalive interval\n"
2459 "Holdtime\n")
718e3744 2460{
d62a17ae 2461 int idx_number = 2;
2462 int idx_number_2 = 3;
718e3744 2463
87ce2564 2464 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2465 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2466 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2467 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2468
ff8a8a7a
CS
2469 return nb_cli_apply_changes(vty, NULL);
2470}
718e3744 2471
37a87b8f
CS
2472DEFUN_YANG (no_bgp_timers,
2473 no_bgp_timers_cmd,
2474 "no timers bgp [(0-65535) (0-65535)]",
2475 NO_STR
2476 "Adjust routing timers\n"
2477 "BGP timers\n"
2478 "Keepalive interval\n"
2479 "Holdtime\n")
ff8a8a7a 2480{
87ce2564 2481 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2482 NB_OP_DESTROY, NULL);
87ce2564 2483 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2484 NB_OP_DESTROY, NULL);
718e3744 2485
ff8a8a7a 2486 return nb_cli_apply_changes(vty, NULL);
718e3744 2487}
2488
ff8a8a7a
CS
2489void cli_show_router_bgp_route_reflector(struct vty *vty,
2490 struct lyd_node *dnode,
2491 bool show_defaults)
718e3744 2492{
ff8a8a7a
CS
2493 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2494 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2495
ff8a8a7a
CS
2496 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2497 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2498
2499 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2500 vty_out(vty, " bgp cluster-id %s\n",
2501 yang_dnode_get_string(dnode,
2502 "./route-reflector-cluster-id"));
718e3744 2503}
2504
ff8a8a7a
CS
2505DEFUN_YANG(bgp_client_to_client_reflection,
2506 bgp_client_to_client_reflection_cmd,
2507 "bgp client-to-client reflection",
2508 "BGP specific commands\n"
2509 "Configure client to client route reflection\n"
2510 "reflection of routes allowed\n")
2511{
87ce2564 2512 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2513 NB_OP_MODIFY, "false");
6b0655a2 2514
ff8a8a7a
CS
2515 return nb_cli_apply_changes(vty, NULL);
2516}
2517
2518DEFUN_YANG(no_bgp_client_to_client_reflection,
2519 no_bgp_client_to_client_reflection_cmd,
2520 "no bgp client-to-client reflection",
2521 NO_STR
2522 "BGP specific commands\n"
2523 "Configure client to client route reflection\n"
2524 "reflection of routes allowed\n")
718e3744 2525{
87ce2564 2526 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2527 NB_OP_MODIFY, "true");
7aafcaca 2528
ff8a8a7a 2529 return nb_cli_apply_changes(vty, NULL);
718e3744 2530}
2531
ff8a8a7a
CS
2532void cli_show_router_bgp_route_selection(struct vty *vty,
2533 struct lyd_node *dnode,
2534 bool show_defaults)
718e3744 2535{
7aafcaca 2536
ff8a8a7a
CS
2537 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2538 vty_out(vty, " bgp always-compare-med\n");
2539
2540 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2541 vty_out(vty, " bgp bestpath as-path ignore\n");
2542
2543 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2544 vty_out(vty, " bgp bestpath as-path confed\n");
2545
2546 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2547 vty_out(vty, " bgp bestpath compare-routerid\n");
2548
2549 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2550 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2551 vty_out(vty,
2552 " bgp bestpath as-path multipath-relax as-set\n");
2553 else
2554 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2555 }
2556
2557 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2558 vty_out(vty, " bgp deterministic-med\n");
2559
2560 if (yang_dnode_get_bool(dnode, "./confed-med")
2561 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2562 vty_out(vty, " bgp bestpath med");
2563 if (yang_dnode_get_bool(dnode, "./confed-med"))
2564 vty_out(vty, " confed");
2565 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2566 vty_out(vty, " missing-as-worst");
2567 vty_out(vty, "\n");
2568 }
718e3744 2569}
2570
2571/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2572DEFUN_YANG(bgp_always_compare_med,
2573 bgp_always_compare_med_cmd,
2574 "bgp always-compare-med",
2575 "BGP specific commands\n"
2576 "Allow comparing MED from different neighbors\n")
718e3744 2577{
87ce2564
CS
2578 nb_cli_enqueue_change(
2579 vty, "./global/route-selection-options/always-compare-med",
2580 NB_OP_MODIFY, "true");
7aafcaca 2581
ff8a8a7a 2582 return nb_cli_apply_changes(vty, NULL);
718e3744 2583}
2584
ff8a8a7a
CS
2585DEFUN_YANG(no_bgp_always_compare_med,
2586 no_bgp_always_compare_med_cmd,
2587 "no bgp always-compare-med",
2588 NO_STR
2589 "BGP specific commands\n"
2590 "Allow comparing MED from different neighbors\n")
718e3744 2591{
87ce2564
CS
2592 nb_cli_enqueue_change(
2593 vty, "./global/route-selection-options/always-compare-med",
2594 NB_OP_MODIFY, "false");
7aafcaca 2595
ff8a8a7a 2596 return nb_cli_apply_changes(vty, NULL);
718e3744 2597}
6b0655a2 2598
2adac256
DA
2599DEFUN_YANG(bgp_suppress_duplicates,
2600 bgp_suppress_duplicates_cmd,
2601 "bgp suppress-duplicates",
2602 "BGP specific commands\n"
2603 "Suppress duplicate updates if the route actually not changed\n")
2604{
2605 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2606 NB_OP_MODIFY, "true");
2607 return nb_cli_apply_changes(vty, NULL);
2608}
2609
2610DEFUN_YANG(no_bgp_suppress_duplicates,
2611 no_bgp_suppress_duplicates_cmd,
2612 "no bgp suppress-duplicates",
2613 NO_STR
2614 "BGP specific commands\n"
2615 "Suppress duplicate updates if the route actually not changed\n")
2616{
2617 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2618 NB_OP_MODIFY, "false");
2619 return nb_cli_apply_changes(vty, NULL);
2620}
2621
2622void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2623 struct lyd_node *dnode,
2624 bool show_defaults)
2625{
2626 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2627 vty_out(vty, " bgp suppress-duplicates\n");
2628}
2629
ff8a8a7a
CS
2630DEFUN_YANG(bgp_ebgp_requires_policy,
2631 bgp_ebgp_requires_policy_cmd,
2632 "bgp ebgp-requires-policy",
2633 "BGP specific commands\n"
2634 "Require in and out policy for eBGP peers (RFC8212)\n")
2635{
87ce2564
CS
2636 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2637 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2638 return nb_cli_apply_changes(vty, NULL);
2639}
9dac9fc8 2640
ff8a8a7a
CS
2641DEFUN_YANG(no_bgp_ebgp_requires_policy,
2642 no_bgp_ebgp_requires_policy_cmd,
2643 "no bgp ebgp-requires-policy",
2644 NO_STR
2645 "BGP specific commands\n"
2646 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2647{
87ce2564
CS
2648 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2649 NB_OP_MODIFY, "false");
ff8a8a7a 2650 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2651}
2652
ff8a8a7a
CS
2653void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2654 struct lyd_node *dnode,
2655 bool show_defaults)
9dac9fc8 2656{
ff8a8a7a
CS
2657 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2658 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2659}
2660
fb29348a
DA
2661DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2662 "bgp reject-as-sets",
2663 "BGP specific commands\n"
2664 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2665{
2666 VTY_DECLVAR_CONTEXT(bgp, bgp);
2667 struct listnode *node, *nnode;
2668 struct peer *peer;
2669
7f972cd8 2670 bgp->reject_as_sets = true;
fb29348a
DA
2671
2672 /* Reset existing BGP sessions to reject routes
2673 * with aspath containing AS_SET or AS_CONFED_SET.
2674 */
2675 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2676 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2677 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2678 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2679 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2680 }
2681 }
2682
2683 return CMD_SUCCESS;
2684}
2685
2686DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2687 "no bgp reject-as-sets",
2688 NO_STR
2689 "BGP specific commands\n"
2690 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2691{
2692 VTY_DECLVAR_CONTEXT(bgp, bgp);
2693 struct listnode *node, *nnode;
2694 struct peer *peer;
2695
7f972cd8 2696 bgp->reject_as_sets = false;
fb29348a
DA
2697
2698 /* Reset existing BGP sessions to reject routes
2699 * with aspath containing AS_SET or AS_CONFED_SET.
2700 */
2701 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2702 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2703 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2704 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2705 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2706 }
2707 }
2708
2709 return CMD_SUCCESS;
2710}
9dac9fc8 2711
718e3744 2712/* "bgp deterministic-med" configuration. */
ff8a8a7a 2713DEFUN_YANG (bgp_deterministic_med,
718e3744 2714 bgp_deterministic_med_cmd,
2715 "bgp deterministic-med",
2716 "BGP specific commands\n"
2717 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2718{
87ce2564
CS
2719 nb_cli_enqueue_change(
2720 vty, "./global/route-selection-options/deterministic-med",
2721 NB_OP_MODIFY, "true");
7aafcaca 2722
ff8a8a7a 2723 return nb_cli_apply_changes(vty, NULL);
718e3744 2724}
2725
ff8a8a7a 2726DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2727 no_bgp_deterministic_med_cmd,
2728 "no bgp deterministic-med",
2729 NO_STR
2730 "BGP specific commands\n"
2731 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2732{
87ce2564
CS
2733 nb_cli_enqueue_change(
2734 vty, "./global/route-selection-options/deterministic-med",
2735 NB_OP_MODIFY, "false");
d62a17ae 2736
ff8a8a7a 2737 return nb_cli_apply_changes(vty, NULL);
718e3744 2738}
538621f2 2739
055679e9 2740/* "bgp graceful-restart mode" configuration. */
538621f2 2741DEFUN (bgp_graceful_restart,
2ba1fe69 2742 bgp_graceful_restart_cmd,
2743 "bgp graceful-restart",
2744 "BGP specific commands\n"
2745 GR_CMD
055679e9 2746 )
538621f2 2747{
055679e9 2748 int ret = BGP_GR_FAILURE;
2749
2750 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2751 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2752
d62a17ae 2753 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2754
2755 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2756
36235319
QY
2757 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2758 ret);
5cce3f05 2759
055679e9 2760 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2761 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2762 vty_out(vty,
2763 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2764 return bgp_vty_return(vty, ret);
538621f2 2765}
2766
2767DEFUN (no_bgp_graceful_restart,
2ba1fe69 2768 no_bgp_graceful_restart_cmd,
2769 "no bgp graceful-restart",
2770 NO_STR
2771 "BGP specific commands\n"
2772 NO_GR_CMD
055679e9 2773 )
538621f2 2774{
d62a17ae 2775 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2776
2777 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2778 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2779
2780 int ret = BGP_GR_FAILURE;
2781
2782 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2783
36235319
QY
2784 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2785 ret);
5cce3f05 2786
055679e9 2787 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2788 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2789 vty_out(vty,
2790 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2791
2792 return bgp_vty_return(vty, ret);
538621f2 2793}
2794
93406d87 2795DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2796 bgp_graceful_restart_stalepath_time_cmd,
2797 "bgp graceful-restart stalepath-time (1-4095)",
2798 "BGP specific commands\n"
2799 "Graceful restart capability parameters\n"
2800 "Set the max time to hold onto restarting peer's stale paths\n"
2801 "Delay value (seconds)\n")
93406d87 2802{
d62a17ae 2803 VTY_DECLVAR_CONTEXT(bgp, bgp);
2804 int idx_number = 3;
d7c0a89a 2805 uint32_t stalepath;
93406d87 2806
d62a17ae 2807 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2808 bgp->stalepath_time = stalepath;
2809 return CMD_SUCCESS;
93406d87 2810}
2811
eb6f1b41 2812DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2813 bgp_graceful_restart_restart_time_cmd,
2814 "bgp graceful-restart restart-time (1-4095)",
2815 "BGP specific commands\n"
2816 "Graceful restart capability parameters\n"
2817 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2818 "Delay value (seconds)\n")
eb6f1b41 2819{
d62a17ae 2820 VTY_DECLVAR_CONTEXT(bgp, bgp);
2821 int idx_number = 3;
d7c0a89a 2822 uint32_t restart;
eb6f1b41 2823
d62a17ae 2824 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2825 bgp->restart_time = restart;
2826 return CMD_SUCCESS;
eb6f1b41
PG
2827}
2828
cfd47646 2829DEFUN (bgp_graceful_restart_select_defer_time,
2830 bgp_graceful_restart_select_defer_time_cmd,
2831 "bgp graceful-restart select-defer-time (0-3600)",
2832 "BGP specific commands\n"
2833 "Graceful restart capability parameters\n"
2834 "Set the time to defer the BGP route selection after restart\n"
2835 "Delay value (seconds, 0 - disable)\n")
2836{
2837 VTY_DECLVAR_CONTEXT(bgp, bgp);
2838 int idx_number = 3;
2839 uint32_t defer_time;
2840
2841 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2842 bgp->select_defer_time = defer_time;
2843 if (defer_time == 0)
892fedb6 2844 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2845 else
892fedb6 2846 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2847
2848 return CMD_SUCCESS;
2849}
2850
93406d87 2851DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2852 no_bgp_graceful_restart_stalepath_time_cmd,
2853 "no bgp graceful-restart stalepath-time [(1-4095)]",
2854 NO_STR
2855 "BGP specific commands\n"
2856 "Graceful restart capability parameters\n"
2857 "Set the max time to hold onto restarting peer's stale paths\n"
2858 "Delay value (seconds)\n")
93406d87 2859{
d62a17ae 2860 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2861
d62a17ae 2862 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2863 return CMD_SUCCESS;
93406d87 2864}
2865
eb6f1b41 2866DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2867 no_bgp_graceful_restart_restart_time_cmd,
2868 "no bgp graceful-restart restart-time [(1-4095)]",
2869 NO_STR
2870 "BGP specific commands\n"
2871 "Graceful restart capability parameters\n"
2872 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2873 "Delay value (seconds)\n")
eb6f1b41 2874{
d62a17ae 2875 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2876
d62a17ae 2877 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2878 return CMD_SUCCESS;
eb6f1b41
PG
2879}
2880
cfd47646 2881DEFUN (no_bgp_graceful_restart_select_defer_time,
2882 no_bgp_graceful_restart_select_defer_time_cmd,
2883 "no bgp graceful-restart select-defer-time [(0-3600)]",
2884 NO_STR
2885 "BGP specific commands\n"
2886 "Graceful restart capability parameters\n"
2887 "Set the time to defer the BGP route selection after restart\n"
2888 "Delay value (seconds)\n")
2889{
2890 VTY_DECLVAR_CONTEXT(bgp, bgp);
2891
2892 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2893 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2894
2895 return CMD_SUCCESS;
2896}
2897
43fc21b3 2898DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2899 bgp_graceful_restart_preserve_fw_cmd,
2900 "bgp graceful-restart preserve-fw-state",
2901 "BGP specific commands\n"
2902 "Graceful restart capability parameters\n"
2903 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2904{
d62a17ae 2905 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2906 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2907 return CMD_SUCCESS;
43fc21b3
JC
2908}
2909
2910DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2911 no_bgp_graceful_restart_preserve_fw_cmd,
2912 "no bgp graceful-restart preserve-fw-state",
2913 NO_STR
2914 "BGP specific commands\n"
2915 "Graceful restart capability parameters\n"
2916 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2917{
d62a17ae 2918 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2919 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2920 return CMD_SUCCESS;
43fc21b3
JC
2921}
2922
055679e9 2923DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2924 bgp_graceful_restart_disable_cmd,
2925 "bgp graceful-restart-disable",
2926 "BGP specific commands\n"
2927 GR_DISABLE)
055679e9 2928{
2929 int ret = BGP_GR_FAILURE;
2930
2931 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2932 zlog_debug(
2ba1fe69 2933 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2934
055679e9 2935 VTY_DECLVAR_CONTEXT(bgp, bgp);
2936
2937 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2938
dc95985f 2939 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2940 bgp->peer, ret);
5cce3f05 2941
055679e9 2942 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2943 zlog_debug(
2ba1fe69 2944 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2945 vty_out(vty,
2946 "Graceful restart configuration changed, reset all peers to take effect\n");
2947
055679e9 2948 return bgp_vty_return(vty, ret);
2949}
2950
2951DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2952 no_bgp_graceful_restart_disable_cmd,
2953 "no bgp graceful-restart-disable",
2954 NO_STR
2955 "BGP specific commands\n"
2956 NO_GR_DISABLE
055679e9 2957 )
2958{
2959 VTY_DECLVAR_CONTEXT(bgp, bgp);
2960
2961 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2962 zlog_debug(
2ba1fe69 2963 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2964
2965 int ret = BGP_GR_FAILURE;
2966
2967 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2968
36235319
QY
2969 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2970 ret);
5cce3f05 2971
055679e9 2972 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2973 zlog_debug(
2ba1fe69 2974 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2975 vty_out(vty,
2976 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2977
2978 return bgp_vty_return(vty, ret);
2979}
2980
2981DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2982 bgp_neighbor_graceful_restart_set_cmd,
2983 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2984 NEIGHBOR_STR
2985 NEIGHBOR_ADDR_STR2
2986 GR_NEIGHBOR_CMD
055679e9 2987 )
2988{
2989 int idx_peer = 1;
2990 struct peer *peer;
2991 int ret = BGP_GR_FAILURE;
2992
dc95985f 2993 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2994
055679e9 2995 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2996 zlog_debug(
2ba1fe69 2997 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2998
055679e9 2999 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3000 if (!peer)
3001 return CMD_WARNING_CONFIG_FAILED;
3002
3003 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3004
dc95985f 3005 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3006 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3007
3008 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3009 zlog_debug(
2ba1fe69 3010 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3011 vty_out(vty,
3012 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3013
3014 return bgp_vty_return(vty, ret);
3015}
3016
3017DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3018 no_bgp_neighbor_graceful_restart_set_cmd,
3019 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3020 NO_STR
3021 NEIGHBOR_STR
3022 NEIGHBOR_ADDR_STR2
3023 NO_GR_NEIGHBOR_CMD
055679e9 3024 )
3025{
3026 int idx_peer = 2;
3027 int ret = BGP_GR_FAILURE;
3028 struct peer *peer;
3029
dc95985f 3030 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3031
055679e9 3032 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3033 if (!peer)
3034 return CMD_WARNING_CONFIG_FAILED;
3035
3036 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3037 zlog_debug(
2ba1fe69 3038 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3039
3040 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3041
dc95985f 3042 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3043 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3044
3045 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3046 zlog_debug(
2ba1fe69 3047 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3048 vty_out(vty,
3049 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3050
3051 return bgp_vty_return(vty, ret);
3052}
3053
3054DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3055 bgp_neighbor_graceful_restart_helper_set_cmd,
3056 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3057 NEIGHBOR_STR
3058 NEIGHBOR_ADDR_STR2
3059 GR_NEIGHBOR_HELPER_CMD
055679e9 3060 )
3061{
3062 int idx_peer = 1;
3063 struct peer *peer;
3064 int ret = BGP_GR_FAILURE;
3065
dc95985f 3066 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3067
055679e9 3068 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3069 zlog_debug(
2ba1fe69 3070 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3071
055679e9 3072 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3073
055679e9 3074 if (!peer)
3075 return CMD_WARNING_CONFIG_FAILED;
3076
3077
3078 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3079
dc95985f 3080 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3081 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3082
055679e9 3083 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3084 zlog_debug(
2ba1fe69 3085 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3086 vty_out(vty,
3087 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3088
3089 return bgp_vty_return(vty, ret);
3090}
3091
3092DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3093 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3094 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3095 NO_STR
3096 NEIGHBOR_STR
3097 NEIGHBOR_ADDR_STR2
3098 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3099 )
3100{
3101 int idx_peer = 2;
3102 int ret = BGP_GR_FAILURE;
3103 struct peer *peer;
3104
dc95985f 3105 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3106
055679e9 3107 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3108 if (!peer)
3109 return CMD_WARNING_CONFIG_FAILED;
3110
3111 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3112 zlog_debug(
2ba1fe69 3113 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3114
36235319 3115 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3116
dc95985f 3117 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3118 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3119
3120 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3121 zlog_debug(
2ba1fe69 3122 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3123 vty_out(vty,
3124 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3125
3126 return bgp_vty_return(vty, ret);
3127}
3128
3129DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3130 bgp_neighbor_graceful_restart_disable_set_cmd,
3131 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3132 NEIGHBOR_STR
3133 NEIGHBOR_ADDR_STR2
3134 GR_NEIGHBOR_DISABLE_CMD
055679e9 3135 )
3136{
3137 int idx_peer = 1;
3138 struct peer *peer;
3139 int ret = BGP_GR_FAILURE;
3140
dc95985f 3141 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3142
055679e9 3143 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3144 zlog_debug(
2ba1fe69 3145 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3146
3147 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3148 if (!peer)
3149 return CMD_WARNING_CONFIG_FAILED;
3150
36235319 3151 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3152
3153 if (peer->bgp->t_startup)
3154 bgp_peer_gr_flags_update(peer);
3155
dc95985f 3156 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3157 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3158
055679e9 3159 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3160 zlog_debug(
2ba1fe69 3161 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3162 vty_out(vty,
3163 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3164
3165 return bgp_vty_return(vty, ret);
3166}
3167
3168DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3169 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3170 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3171 NO_STR
3172 NEIGHBOR_STR
3173 NEIGHBOR_ADDR_STR2
3174 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3175 )
3176{
3177 int idx_peer = 2;
3178 int ret = BGP_GR_FAILURE;
3179 struct peer *peer;
3180
dc95985f 3181 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3182
055679e9 3183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3184 if (!peer)
3185 return CMD_WARNING_CONFIG_FAILED;
3186
3187 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3188 zlog_debug(
2ba1fe69 3189 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3190
3191 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3192
dc95985f 3193 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3194 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3195
3196 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3197 zlog_debug(
2ba1fe69 3198 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3199 vty_out(vty,
3200 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3201
3202 return bgp_vty_return(vty, ret);
3203}
3204
d6e3c15b 3205DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3206 bgp_graceful_restart_disable_eor_cmd,
3207 "bgp graceful-restart disable-eor",
3208 "BGP specific commands\n"
3209 "Graceful restart configuration parameters\n"
3210 "Disable EOR Check\n")
3211{
3212 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3213 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3214
d6e3c15b 3215 return CMD_SUCCESS;
3216}
3217
3218DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3219 no_bgp_graceful_restart_disable_eor_cmd,
3220 "no bgp graceful-restart disable-eor",
3221 NO_STR
3222 "BGP specific commands\n"
3223 "Graceful restart configuration parameters\n"
3224 "Disable EOR Check\n")
3225{
3226 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3227 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3228
3229 return CMD_SUCCESS;
3230}
3231
3232DEFUN (bgp_graceful_restart_rib_stale_time,
3233 bgp_graceful_restart_rib_stale_time_cmd,
3234 "bgp graceful-restart rib-stale-time (1-3600)",
3235 "BGP specific commands\n"
3236 "Graceful restart configuration parameters\n"
3237 "Specify the stale route removal timer in rib\n"
3238 "Delay value (seconds)\n")
3239{
3240 VTY_DECLVAR_CONTEXT(bgp, bgp);
3241 int idx_number = 3;
3242 uint32_t stale_time;
3243
3244 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3245 bgp->rib_stale_time = stale_time;
3246 /* Send the stale timer update message to RIB */
3247 if (bgp_zebra_stale_timer_update(bgp))
3248 return CMD_WARNING;
3249
3250 return CMD_SUCCESS;
3251}
3252
3253DEFUN (no_bgp_graceful_restart_rib_stale_time,
3254 no_bgp_graceful_restart_rib_stale_time_cmd,
3255 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3256 NO_STR
3257 "BGP specific commands\n"
3258 "Graceful restart configuration parameters\n"
3259 "Specify the stale route removal timer in rib\n"
3260 "Delay value (seconds)\n")
3261{
3262 VTY_DECLVAR_CONTEXT(bgp, bgp);
3263
3264 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3265 /* Send the stale timer update message to RIB */
3266 if (bgp_zebra_stale_timer_update(bgp))
3267 return CMD_WARNING;
3268
d6e3c15b 3269 return CMD_SUCCESS;
3270}
3271
ff8a8a7a
CS
3272static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3273 char *errmsg,
3274 size_t errmsg_len)
05bd726c 3275{
3276 bgp_static_redo_import_check(bgp);
3277 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
3278 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3279 return -1;
3280 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3281 return -1;
3282
3283 return 0;
05bd726c 3284}
3285
3286static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3287{
3288 struct listnode *node, *nnode;
3289 struct bgp *bgp;
3290 bool vrf_cfg = false;
ff8a8a7a 3291 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3292
3293 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3294 return CMD_SUCCESS;
3295
3296 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3297 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3298 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3299 vty_out(vty,
3300 "%% graceful-shutdown configuration found in vrf %s\n",
3301 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3302 VRF_DEFAULT_NAME : bgp->name);
3303 vrf_cfg = true;
3304 }
3305 }
3306
3307 if (vrf_cfg) {
3308 vty_out(vty,
3309 "%%Failed: global graceful-shutdown not permitted\n");
3310 return CMD_WARNING;
3311 }
3312
3313 /* Set flag globally */
3314 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3315
3316 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3317 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3318 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3319 sizeof(errmsg))
3320 < 0)
3321 if (strlen(errmsg))
3322 vty_out(vty, "%s\n", errmsg);
3323 }
05bd726c 3324
3325 return CMD_SUCCESS;
3326}
3327
3328static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3329{
3330 struct listnode *node, *nnode;
3331 struct bgp *bgp;
ff8a8a7a 3332 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3333
3334 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3335 return CMD_SUCCESS;
3336
3337 /* Unset flag globally */
3338 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3339
3340 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3341 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3342 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3343 sizeof(errmsg))
3344 < 0)
3345 if (strlen(errmsg))
3346 vty_out(vty, "%s\n", errmsg);
3347 }
05bd726c 3348
3349 return CMD_SUCCESS;
3350}
3351
7f323236
DW
3352/* "bgp graceful-shutdown" configuration */
3353DEFUN (bgp_graceful_shutdown,
3354 bgp_graceful_shutdown_cmd,
3355 "bgp graceful-shutdown",
3356 BGP_STR
3357 "Graceful shutdown parameters\n")
3358{
05bd726c 3359 if (vty->node == CONFIG_NODE)
3360 return bgp_global_graceful_shutdown_config_vty(vty);
3361
87ce2564
CS
3362 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3363 NB_OP_MODIFY, "true");
7f323236 3364
ff8a8a7a 3365 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3366}
3367
ff8a8a7a 3368DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3369 no_bgp_graceful_shutdown_cmd,
3370 "no bgp graceful-shutdown",
3371 NO_STR
3372 BGP_STR
3373 "Graceful shutdown parameters\n")
3374{
05bd726c 3375 if (vty->node == CONFIG_NODE)
3376 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3377
87ce2564
CS
3378 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3379 NB_OP_MODIFY, "false");
05bd726c 3380
ff8a8a7a
CS
3381 return nb_cli_apply_changes(vty, NULL);
3382}
7f323236 3383
ff8a8a7a
CS
3384void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3385 struct lyd_node *dnode,
3386 bool show_defaults)
3387{
3388 if (yang_dnode_get_bool(dnode, NULL))
3389 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3390}
3391
718e3744 3392/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3393DEFUN_YANG (bgp_fast_external_failover,
718e3744 3394 bgp_fast_external_failover_cmd,
3395 "bgp fast-external-failover",
3396 BGP_STR
3397 "Immediately reset session if a link to a directly connected external peer goes down\n")
3398{
87ce2564
CS
3399 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3400 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3401
3402 return nb_cli_apply_changes(vty, NULL);
718e3744 3403}
3404
ff8a8a7a 3405DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3406 no_bgp_fast_external_failover_cmd,
3407 "no bgp fast-external-failover",
3408 NO_STR
3409 BGP_STR
3410 "Immediately reset session if a link to a directly connected external peer goes down\n")
3411{
87ce2564
CS
3412 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3413 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3414
3415 return nb_cli_apply_changes(vty, NULL);
3416}
3417
3418void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3419 struct lyd_node *dnode,
3420 bool show_defaults)
3421{
3422 if (!yang_dnode_get_bool(dnode, NULL))
3423 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3424}
6b0655a2 3425
718e3744 3426/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3427DEFUN_YANG(bgp_bestpath_compare_router_id,
3428 bgp_bestpath_compare_router_id_cmd,
3429 "bgp bestpath compare-routerid",
3430 "BGP specific commands\n"
3431 "Change the default bestpath selection\n"
3432 "Compare router-id for identical EBGP paths\n")
718e3744 3433{
ff8a8a7a 3434 nb_cli_enqueue_change(
87ce2564
CS
3435 vty,
3436 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3437 NB_OP_MODIFY, "true");
7aafcaca 3438
ff8a8a7a 3439 return nb_cli_apply_changes(vty, NULL);
718e3744 3440}
3441
ff8a8a7a
CS
3442DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3443 no_bgp_bestpath_compare_router_id_cmd,
3444 "no bgp bestpath compare-routerid",
3445 NO_STR
3446 "BGP specific commands\n"
3447 "Change the default bestpath selection\n"
3448 "Compare router-id for identical EBGP paths\n")
718e3744 3449{
ff8a8a7a 3450 nb_cli_enqueue_change(
87ce2564
CS
3451 vty,
3452 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3453 NB_OP_MODIFY, "false");
7aafcaca 3454
ff8a8a7a 3455 return nb_cli_apply_changes(vty, NULL);
718e3744 3456}
6b0655a2 3457
718e3744 3458/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3459DEFUN_YANG(bgp_bestpath_aspath_ignore,
3460 bgp_bestpath_aspath_ignore_cmd,
3461 "bgp bestpath as-path ignore",
3462 "BGP specific commands\n"
3463 "Change the default bestpath selection\n"
3464 "AS-path attribute\n"
3465 "Ignore as-path length in selecting a route\n")
718e3744 3466{
87ce2564
CS
3467 nb_cli_enqueue_change(
3468 vty, "./global/route-selection-options/ignore-as-path-length",
3469 NB_OP_MODIFY, "true");
7aafcaca 3470
ff8a8a7a 3471 return nb_cli_apply_changes(vty, NULL);
718e3744 3472}
3473
ff8a8a7a
CS
3474DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3475 no_bgp_bestpath_aspath_ignore_cmd,
3476 "no bgp bestpath as-path ignore",
3477 NO_STR
3478 "BGP specific commands\n"
3479 "Change the default bestpath selection\n"
3480 "AS-path attribute\n"
3481 "Ignore as-path length in selecting a route\n")
718e3744 3482{
87ce2564
CS
3483 nb_cli_enqueue_change(
3484 vty, "./global/route-selection-options/ignore-as-path-length",
3485 NB_OP_MODIFY, "false");
7aafcaca 3486
ff8a8a7a 3487 return nb_cli_apply_changes(vty, NULL);
718e3744 3488}
6b0655a2 3489
6811845b 3490/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3491DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3492 bgp_bestpath_aspath_confed_cmd,
3493 "bgp bestpath as-path confed",
3494 "BGP specific commands\n"
3495 "Change the default bestpath selection\n"
3496 "AS-path attribute\n"
3497 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3498{
87ce2564
CS
3499 nb_cli_enqueue_change(vty,
3500 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3501 NB_OP_MODIFY, "true");
7aafcaca 3502
ff8a8a7a 3503 return nb_cli_apply_changes(vty, NULL);
6811845b 3504}
3505
ff8a8a7a 3506DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3507 no_bgp_bestpath_aspath_confed_cmd,
3508 "no bgp bestpath as-path confed",
3509 NO_STR
3510 "BGP specific commands\n"
3511 "Change the default bestpath selection\n"
3512 "AS-path attribute\n"
3513 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3514{
87ce2564
CS
3515 nb_cli_enqueue_change(vty,
3516 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3517 NB_OP_MODIFY, "false");
7aafcaca 3518
ff8a8a7a 3519 return nb_cli_apply_changes(vty, NULL);
6811845b 3520}
6b0655a2 3521
2fdd455c 3522/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3523DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3524 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3525 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3526 "BGP specific commands\n"
3527 "Change the default bestpath selection\n"
3528 "AS-path attribute\n"
3529 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3530 "Generate an AS_SET\n"
16fc1eec
DS
3531 "Do not generate an AS_SET\n")
3532{
d62a17ae 3533 int idx = 0;
219178b6 3534
87ce2564
CS
3535 nb_cli_enqueue_change(
3536 vty, "./global/route-selection-options/allow-multiple-as",
3537 NB_OP_MODIFY, "true");
d62a17ae 3538 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3539 nb_cli_enqueue_change(
87ce2564
CS
3540 vty,
3541 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3542 NB_OP_MODIFY, "true");
d62a17ae 3543 else
ff8a8a7a 3544 nb_cli_enqueue_change(
87ce2564
CS
3545 vty,
3546 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3547 NB_OP_MODIFY, "false");
7aafcaca 3548
ff8a8a7a 3549 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3550}
3551
ff8a8a7a 3552DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3553 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3554 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3555 NO_STR
3556 "BGP specific commands\n"
3557 "Change the default bestpath selection\n"
3558 "AS-path attribute\n"
3559 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3560 "Generate an AS_SET\n"
16fc1eec
DS
3561 "Do not generate an AS_SET\n")
3562{
87ce2564
CS
3563 nb_cli_enqueue_change(
3564 vty, "./global/route-selection-options/allow-multiple-as",
3565 NB_OP_MODIFY, "false");
3566 nb_cli_enqueue_change(
3567 vty, "./global/route-selection-options/multi-path-as-set",
3568 NB_OP_MODIFY, "false");
7aafcaca 3569
ff8a8a7a 3570 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3571}
6b0655a2 3572
848973c7 3573/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3574DEFUN_YANG(bgp_log_neighbor_changes,
3575 bgp_log_neighbor_changes_cmd,
3576 "bgp log-neighbor-changes",
3577 "BGP specific commands\n"
3578 "Log neighbor up/down and reset reason\n")
848973c7 3579{
87ce2564
CS
3580 nb_cli_enqueue_change(
3581 vty, "./global/global-neighbor-config/log-neighbor-changes",
3582 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3583
3584 return nb_cli_apply_changes(vty, NULL);
848973c7 3585}
3586
ff8a8a7a
CS
3587DEFUN_YANG(no_bgp_log_neighbor_changes,
3588 no_bgp_log_neighbor_changes_cmd,
3589 "no bgp log-neighbor-changes",
3590 NO_STR
3591 "BGP specific commands\n"
3592 "Log neighbor up/down and reset reason\n")
848973c7 3593{
87ce2564
CS
3594 nb_cli_enqueue_change(
3595 vty, "./global/global-neighbor-config/log-neighbor-changes",
3596 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3597
3598 return nb_cli_apply_changes(vty, NULL);
848973c7 3599}
6b0655a2 3600
718e3744 3601/* "bgp bestpath med" configuration. */
ff8a8a7a 3602DEFUN_YANG (bgp_bestpath_med,
718e3744 3603 bgp_bestpath_med_cmd,
2d8c1a4d 3604 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3605 "BGP specific commands\n"
3606 "Change the default bestpath selection\n"
3607 "MED attribute\n"
3608 "Compare MED among confederation paths\n"
838758ac
DW
3609 "Treat missing MED as the least preferred one\n"
3610 "Treat missing MED as the least preferred one\n"
3611 "Compare MED among confederation paths\n")
718e3744 3612{
d62a17ae 3613 int idx = 0;
ff8a8a7a
CS
3614 bool confed = false;
3615 bool worst_med = false;
3616
3617
d62a17ae 3618 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3619 confed = true;
3620
87ce2564
CS
3621 nb_cli_enqueue_change(vty,
3622 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3623 NB_OP_MODIFY, confed ? "true" : "false");
3624
d62a17ae 3625 idx = 0;
3626 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3627 worst_med = true;
e52702f2 3628
87ce2564
CS
3629 nb_cli_enqueue_change(
3630 vty, "./global/route-selection-options/missing-as-worst-med",
3631 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3632
ff8a8a7a 3633 return nb_cli_apply_changes(vty, NULL);
718e3744 3634}
3635
ff8a8a7a 3636DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3637 no_bgp_bestpath_med_cmd,
2d8c1a4d 3638 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3639 NO_STR
3640 "BGP specific commands\n"
3641 "Change the default bestpath selection\n"
3642 "MED attribute\n"
3643 "Compare MED among confederation paths\n"
3a2d747c
QY
3644 "Treat missing MED as the least preferred one\n"
3645 "Treat missing MED as the least preferred one\n"
3646 "Compare MED among confederation paths\n")
718e3744 3647{
d62a17ae 3648 int idx = 0;
ff8a8a7a 3649
d62a17ae 3650 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3651 nb_cli_enqueue_change(
3652 vty, "./global/route-selection-options/confed-med",
3653 NB_OP_MODIFY, "false");
ff8a8a7a 3654
d62a17ae 3655 idx = 0;
3656 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3657 nb_cli_enqueue_change(
87ce2564
CS
3658 vty,
3659 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3660 NB_OP_MODIFY, "false");
718e3744 3661
ff8a8a7a 3662 return nb_cli_apply_changes(vty, NULL);
718e3744 3663}
3664
f7e1c681 3665/* "bgp bestpath bandwidth" configuration. */
3666DEFPY (bgp_bestpath_bw,
3667 bgp_bestpath_bw_cmd,
ad36d216 3668 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3669 "BGP specific commands\n"
3670 "Change the default bestpath selection\n"
3671 "Link Bandwidth attribute\n"
3672 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3673 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3674 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3675{
3676 VTY_DECLVAR_CONTEXT(bgp, bgp);
3677 afi_t afi;
3678 safi_t safi;
3679
ad36d216
DS
3680 if (!bw_cfg) {
3681 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3682 return CMD_ERR_INCOMPLETE;
f7e1c681 3683 }
ad36d216
DS
3684 if (!strcmp(bw_cfg, "ignore"))
3685 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3686 else if (!strcmp(bw_cfg, "skip-missing"))
3687 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3688 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3689 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3690 else
3691 return CMD_ERR_NO_MATCH;
f7e1c681 3692
3693 /* This config is used in route install, so redo that. */
3694 FOREACH_AFI_SAFI (afi, safi) {
3695 if (!bgp_fibupd_safi(safi))
3696 continue;
3697 bgp_zebra_announce_table(bgp, afi, safi);
3698 }
3699
3700 return CMD_SUCCESS;
3701}
3702
ad36d216
DS
3703DEFPY (no_bgp_bestpath_bw,
3704 no_bgp_bestpath_bw_cmd,
3705 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3706 NO_STR
3707 "BGP specific commands\n"
3708 "Change the default bestpath selection\n"
3709 "Link Bandwidth attribute\n"
3710 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3711 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3712 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3713{
3714 VTY_DECLVAR_CONTEXT(bgp, bgp);
3715 afi_t afi;
3716 safi_t safi;
3717
3718 bgp->lb_handling = BGP_LINK_BW_ECMP;
3719
3720 /* This config is used in route install, so redo that. */
3721 FOREACH_AFI_SAFI (afi, safi) {
3722 if (!bgp_fibupd_safi(safi))
3723 continue;
3724 bgp_zebra_announce_table(bgp, afi, safi);
3725 }
3726 return CMD_SUCCESS;
3727}
3728
718e3744 3729/* "no bgp default ipv4-unicast". */
3730DEFUN (no_bgp_default_ipv4_unicast,
3731 no_bgp_default_ipv4_unicast_cmd,
3732 "no bgp default ipv4-unicast",
3733 NO_STR
3734 "BGP specific commands\n"
3735 "Configure BGP defaults\n"
3736 "Activate ipv4-unicast for a peer by default\n")
3737{
d62a17ae 3738 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3739 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3740 return CMD_SUCCESS;
718e3744 3741}
3742
3743DEFUN (bgp_default_ipv4_unicast,
3744 bgp_default_ipv4_unicast_cmd,
3745 "bgp default ipv4-unicast",
3746 "BGP specific commands\n"
3747 "Configure BGP defaults\n"
3748 "Activate ipv4-unicast for a peer by default\n")
3749{
d62a17ae 3750 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3751 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3752 return CMD_SUCCESS;
718e3744 3753}
6b0655a2 3754
04b6bdc0 3755/* Display hostname in certain command outputs */
ff8a8a7a 3756DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3757 bgp_default_show_hostname_cmd,
3758 "bgp default show-hostname",
3759 "BGP specific commands\n"
3760 "Configure BGP defaults\n"
0437e105 3761 "Show hostname in certain command outputs\n")
04b6bdc0 3762{
87ce2564
CS
3763 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3764 "true");
ff8a8a7a
CS
3765
3766 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3767}
3768
ff8a8a7a
CS
3769DEFUN_YANG(no_bgp_default_show_hostname,
3770 no_bgp_default_show_hostname_cmd,
3771 "no bgp default show-hostname",
3772 NO_STR
3773 "BGP specific commands\n"
3774 "Configure BGP defaults\n"
3775 "Show hostname in certain command outputs\n")
04b6bdc0 3776{
87ce2564
CS
3777 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3778 "false");
ff8a8a7a
CS
3779
3780 return nb_cli_apply_changes(vty, NULL);
3781}
3782
3783void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3784 bool show_defaults)
3785{
3786 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3787 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3788}
3789
aef999a2 3790/* Display hostname in certain command outputs */
232c75cd
CS
3791DEFUN_YANG(bgp_default_show_nexthop_hostname,
3792 bgp_default_show_nexthop_hostname_cmd,
3793 "bgp default show-nexthop-hostname",
3794 "BGP specific commands\n"
3795 "Configure BGP defaults\n"
3796 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3797{
87ce2564
CS
3798 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3799 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3800
3801 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3802}
3803
3804DEFUN (no_bgp_default_show_nexthop_hostname,
3805 no_bgp_default_show_nexthop_hostname_cmd,
3806 "no bgp default show-nexthop-hostname",
3807 NO_STR
3808 "BGP specific commands\n"
3809 "Configure BGP defaults\n"
3810 "Show hostname for nexthop in certain command outputs\n")
3811{
87ce2564
CS
3812 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3813 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3814
3815 return nb_cli_apply_changes(vty, NULL);
3816}
3817
3818void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3819 struct lyd_node *dnode,
3820 bool show_defaults)
3821{
3822 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3823 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3824}
3825
8233ef81 3826/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3827DEFUN_YANG(bgp_network_import_check,
3828 bgp_network_import_check_cmd,
3829 "bgp network import-check",
3830 "BGP specific commands\n"
3831 "BGP network command\n"
3832 "Check BGP network route exists in IGP\n")
718e3744 3833{
87ce2564
CS
3834 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3835 "true");
078430f6 3836
ff8a8a7a 3837 return nb_cli_apply_changes(vty, NULL);
718e3744 3838}
3839
d62a17ae 3840ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3841 "bgp network import-check exact",
3842 "BGP specific commands\n"
3843 "BGP network command\n"
3844 "Check BGP network route exists in IGP\n"
3845 "Match route precisely\n")
8233ef81 3846
ff8a8a7a
CS
3847DEFUN_YANG(no_bgp_network_import_check,
3848 no_bgp_network_import_check_cmd,
3849 "no bgp network import-check",
3850 NO_STR
3851 "BGP specific commands\n"
3852 "BGP network command\n"
3853 "Check BGP network route exists in IGP\n")
718e3744 3854{
87ce2564
CS
3855 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3856 "false");
5623e905 3857
ff8a8a7a 3858 return nb_cli_apply_changes(vty, NULL);
718e3744 3859}
6b0655a2 3860
ff8a8a7a
CS
3861void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3862 bool show_defaults)
718e3744 3863{
ff8a8a7a
CS
3864 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3865 vty_out(vty, " bgp network import-check\n");
3866}
718e3744 3867
ff8a8a7a
CS
3868DEFUN_YANG(bgp_default_local_preference,
3869 bgp_default_local_preference_cmd,
3870 "bgp default local-preference (0-4294967295)",
3871 "BGP specific commands\n"
3872 "Configure BGP defaults\n"
3873 "local preference (higher=more preferred)\n"
3874 "Configure default local preference value\n")
3875{
3876 int idx_number = 3;
718e3744 3877
87ce2564 3878 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3879 argv[idx_number]->arg);
718e3744 3880
ff8a8a7a 3881 return nb_cli_apply_changes(vty, NULL);
718e3744 3882}
3883
ff8a8a7a
CS
3884DEFUN_YANG(no_bgp_default_local_preference,
3885 no_bgp_default_local_preference_cmd,
3886 "no bgp default local-preference [(0-4294967295)]",
3887 NO_STR
3888 "BGP specific commands\n"
3889 "Configure BGP defaults\n"
3890 "local preference (higher=more preferred)\n"
3891 "Configure default local preference value\n")
718e3744 3892{
87ce2564 3893 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 3894
ff8a8a7a 3895 return nb_cli_apply_changes(vty, NULL);
718e3744 3896}
3897
ff8a8a7a
CS
3898void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3899 bool show_defaults)
3900{
3901 vty_out(vty, " bgp default local-preference %u\n",
3902 yang_dnode_get_uint32(dnode, NULL));
3903}
6b0655a2 3904
ff8a8a7a
CS
3905
3906DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3907 bgp_default_subgroup_pkt_queue_max_cmd,
3908 "bgp default subgroup-pkt-queue-max (20-100)",
3909 "BGP specific commands\n"
3910 "Configure BGP defaults\n"
3911 "subgroup-pkt-queue-max\n"
3912 "Configure subgroup packet queue max\n")
8bd9d948 3913{
d62a17ae 3914 int idx_number = 3;
3f9c7369 3915
ff8a8a7a 3916 nb_cli_enqueue_change(
87ce2564
CS
3917 vty,
3918 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 3919 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 3920
ff8a8a7a 3921 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
3922}
3923
ff8a8a7a
CS
3924DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3925 no_bgp_default_subgroup_pkt_queue_max_cmd,
3926 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3927 NO_STR
3928 "BGP specific commands\n"
3929 "Configure BGP defaults\n"
3930 "subgroup-pkt-queue-max\n"
3931 "Configure subgroup packet queue max\n")
3f9c7369 3932{
ff8a8a7a 3933 nb_cli_enqueue_change(
87ce2564
CS
3934 vty,
3935 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
3936 NB_OP_MODIFY, NULL);
3937
3938 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3939}
3940
ff8a8a7a
CS
3941void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3942 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3943{
3944 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3945 yang_dnode_get_uint32(dnode, NULL));
3946}
813d4307 3947
ff8a8a7a
CS
3948DEFUN_YANG(bgp_rr_allow_outbound_policy,
3949 bgp_rr_allow_outbound_policy_cmd,
3950 "bgp route-reflector allow-outbound-policy",
3951 "BGP specific commands\n"
3952 "Allow modifications made by out route-map\n"
3953 "on ibgp neighbors\n")
8bd9d948 3954{
87ce2564
CS
3955 nb_cli_enqueue_change(vty,
3956 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 3957 NB_OP_MODIFY, "true");
8bd9d948 3958
ff8a8a7a
CS
3959 return nb_cli_apply_changes(vty, NULL);
3960}
8bd9d948 3961
ff8a8a7a
CS
3962DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3963 no_bgp_rr_allow_outbound_policy_cmd,
3964 "no bgp route-reflector allow-outbound-policy",
3965 NO_STR
3966 "BGP specific commands\n"
3967 "Allow modifications made by out route-map\n"
3968 "on ibgp neighbors\n")
3969{
87ce2564
CS
3970 nb_cli_enqueue_change(vty,
3971 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
3972 NB_OP_MODIFY, "false");
3973
3974 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3975}
3976
ff8a8a7a
CS
3977
3978void cli_show_router_global_neighbor_config(struct vty *vty,
3979 struct lyd_node *dnode,
3980 bool show_defaults)
8bd9d948 3981{
ff8a8a7a
CS
3982 uint32_t write_quanta, read_quanta;
3983
3984 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3985 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 3986
ff8a8a7a
CS
3987 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3988 uint32_t listen_limit = yang_dnode_get_uint32(
3989 dnode, "./dynamic-neighbors-limit");
3990 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 3991 }
8bd9d948 3992
ff8a8a7a
CS
3993 write_quanta = yang_dnode_get_uint32(
3994 dnode, "./packet-quanta-config/wpkt-quanta");
3995 if (write_quanta != BGP_WRITE_PACKET_MAX)
3996 vty_out(vty, " write-quanta %d\n", write_quanta);
3997
3998 read_quanta = yang_dnode_get_uint32(
3999 dnode, "./packet-quanta-config/rpkt-quanta");
4000
4001 if (read_quanta != BGP_READ_PACKET_MAX)
4002 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
4003}
4004
ff8a8a7a
CS
4005DEFUN_YANG(bgp_listen_limit,
4006 bgp_listen_limit_cmd,
4007 "bgp listen limit (1-5000)",
4008 "BGP specific commands\n"
4009 "BGP Dynamic Neighbors listen commands\n"
4010 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4011 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4012{
d62a17ae 4013 int idx_number = 3;
f14e6fdb 4014
ff8a8a7a 4015 nb_cli_enqueue_change(
87ce2564 4016 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 4017 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 4018
ff8a8a7a 4019 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4020}
4021
ff8a8a7a
CS
4022DEFUN_YANG(no_bgp_listen_limit,
4023 no_bgp_listen_limit_cmd,
4024 "no bgp listen limit [(1-5000)]",
4025 NO_STR
4026 "BGP specific commands\n"
4027 "BGP Dynamic Neighbors listen commands\n"
4028 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4029 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4030{
ff8a8a7a 4031 nb_cli_enqueue_change(
87ce2564 4032 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
4033 NB_OP_DESTROY, NULL);
4034
4035 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4036}
4037
4038
20eb8864 4039/*
4040 * Check if this listen range is already configured. Check for exact
4041 * match or overlap based on input.
4042 */
d62a17ae 4043static struct peer_group *listen_range_exists(struct bgp *bgp,
4044 struct prefix *range, int exact)
4045{
4046 struct listnode *node, *nnode;
4047 struct listnode *node1, *nnode1;
4048 struct peer_group *group;
4049 struct prefix *lr;
4050 afi_t afi;
4051 int match;
4052
4053 afi = family2afi(range->family);
4054 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4055 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4056 lr)) {
4057 if (exact)
4058 match = prefix_same(range, lr);
4059 else
4060 match = (prefix_match(range, lr)
4061 || prefix_match(lr, range));
4062 if (match)
4063 return group;
4064 }
4065 }
4066
4067 return NULL;
20eb8864 4068}
4069
f14e6fdb
DS
4070DEFUN (bgp_listen_range,
4071 bgp_listen_range_cmd,
d7b9898c 4072 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 4073 "BGP specific commands\n"
d7fa34c1
QY
4074 "Configure BGP dynamic neighbors listen range\n"
4075 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4076 NEIGHBOR_ADDR_STR
4077 "Member of the peer-group\n"
4078 "Peer-group name\n")
f14e6fdb 4079{
d62a17ae 4080 VTY_DECLVAR_CONTEXT(bgp, bgp);
4081 struct prefix range;
4082 struct peer_group *group, *existing_group;
4083 afi_t afi;
4084 int ret;
4085 int idx = 0;
4086
4087 argv_find(argv, argc, "A.B.C.D/M", &idx);
4088 argv_find(argv, argc, "X:X::X:X/M", &idx);
4089 char *prefix = argv[idx]->arg;
d7b9898c 4090 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4091 char *peergroup = argv[idx]->arg;
4092
4093 /* Convert IP prefix string to struct prefix. */
4094 ret = str2prefix(prefix, &range);
4095 if (!ret) {
4096 vty_out(vty, "%% Malformed listen range\n");
4097 return CMD_WARNING_CONFIG_FAILED;
4098 }
4099
4100 afi = family2afi(range.family);
4101
4102 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4103 vty_out(vty,
4104 "%% Malformed listen range (link-local address)\n");
4105 return CMD_WARNING_CONFIG_FAILED;
4106 }
4107
4108 apply_mask(&range);
4109
4110 /* Check if same listen range is already configured. */
4111 existing_group = listen_range_exists(bgp, &range, 1);
4112 if (existing_group) {
4113 if (strcmp(existing_group->name, peergroup) == 0)
4114 return CMD_SUCCESS;
4115 else {
4116 vty_out(vty,
4117 "%% Same listen range is attached to peer-group %s\n",
4118 existing_group->name);
4119 return CMD_WARNING_CONFIG_FAILED;
4120 }
4121 }
4122
4123 /* Check if an overlapping listen range exists. */
4124 if (listen_range_exists(bgp, &range, 0)) {
4125 vty_out(vty,
4126 "%% Listen range overlaps with existing listen range\n");
4127 return CMD_WARNING_CONFIG_FAILED;
4128 }
4129
4130 group = peer_group_lookup(bgp, peergroup);
4131 if (!group) {
4132 vty_out(vty, "%% Configure the peer-group first\n");
4133 return CMD_WARNING_CONFIG_FAILED;
4134 }
4135
4136 ret = peer_group_listen_range_add(group, &range);
4137 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4138}
4139
4140DEFUN (no_bgp_listen_range,
4141 no_bgp_listen_range_cmd,
d7b9898c 4142 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4143 NO_STR
f14e6fdb 4144 "BGP specific commands\n"
d7fa34c1
QY
4145 "Unconfigure BGP dynamic neighbors listen range\n"
4146 "Unconfigure BGP dynamic neighbors listen range\n"
4147 NEIGHBOR_ADDR_STR
4148 "Member of the peer-group\n"
4149 "Peer-group name\n")
f14e6fdb 4150{
d62a17ae 4151 VTY_DECLVAR_CONTEXT(bgp, bgp);
4152 struct prefix range;
4153 struct peer_group *group;
4154 afi_t afi;
4155 int ret;
4156 int idx = 0;
4157
4158 argv_find(argv, argc, "A.B.C.D/M", &idx);
4159 argv_find(argv, argc, "X:X::X:X/M", &idx);
4160 char *prefix = argv[idx]->arg;
21d88a71 4161 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4162 char *peergroup = argv[idx]->arg;
4163
4164 /* Convert IP prefix string to struct prefix. */
4165 ret = str2prefix(prefix, &range);
4166 if (!ret) {
4167 vty_out(vty, "%% Malformed listen range\n");
4168 return CMD_WARNING_CONFIG_FAILED;
4169 }
4170
4171 afi = family2afi(range.family);
4172
4173 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4174 vty_out(vty,
4175 "%% Malformed listen range (link-local address)\n");
4176 return CMD_WARNING_CONFIG_FAILED;
4177 }
4178
4179 apply_mask(&range);
4180
4181 group = peer_group_lookup(bgp, peergroup);
4182 if (!group) {
4183 vty_out(vty, "%% Peer-group does not exist\n");
4184 return CMD_WARNING_CONFIG_FAILED;
4185 }
4186
4187 ret = peer_group_listen_range_del(group, &range);
4188 return bgp_vty_return(vty, ret);
4189}
4190
2b791107 4191void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4192{
4193 struct peer_group *group;
4194 struct listnode *node, *nnode, *rnode, *nrnode;
4195 struct prefix *range;
4196 afi_t afi;
d62a17ae 4197
4198 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4199 vty_out(vty, " bgp listen limit %d\n",
4200 bgp->dynamic_neighbors_limit);
4201
4202 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4203 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4204 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4205 nrnode, range)) {
d62a17ae 4206 vty_out(vty,
2dbe669b
DA
4207 " bgp listen range %pFX peer-group %s\n",
4208 range, group->name);
d62a17ae 4209 }
4210 }
4211 }
f14e6fdb
DS
4212}
4213
4214
ff8a8a7a
CS
4215DEFUN_YANG(bgp_disable_connected_route_check,
4216 bgp_disable_connected_route_check_cmd,
4217 "bgp disable-ebgp-connected-route-check",
4218 "BGP specific commands\n"
4219 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4220{
87ce2564
CS
4221 nb_cli_enqueue_change(vty,
4222 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4223 NB_OP_MODIFY, "true");
7aafcaca 4224
ff8a8a7a 4225 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
4226}
4227
ff8a8a7a
CS
4228DEFUN_YANG(no_bgp_disable_connected_route_check,
4229 no_bgp_disable_connected_route_check_cmd,
4230 "no bgp disable-ebgp-connected-route-check",
4231 NO_STR
4232 "BGP specific commands\n"
4233 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4234{
87ce2564
CS
4235 nb_cli_enqueue_change(vty,
4236 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4237 NB_OP_MODIFY, "false");
d62a17ae 4238
ff8a8a7a 4239 return nb_cli_apply_changes(vty, NULL);
d62a17ae 4240}
4241
ff8a8a7a
CS
4242void cli_show_router_global_ebgp_multihop_connected_route_check(
4243 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4244{
4245 if (yang_dnode_get_bool(dnode, NULL))
4246 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4247}
d62a17ae 4248
ff8a8a7a
CS
4249DEFUN_YANG(bgp_default_shutdown,
4250 bgp_default_shutdown_cmd,
4251 "[no] bgp default shutdown",
4252 NO_STR BGP_STR
4253 "Configure BGP defaults\n"
4254 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4255{
87ce2564 4256 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4257 strmatch(argv[0]->text, "no") ? "false" : "true");
4258
4259 return nb_cli_apply_changes(vty, NULL);
4260}
4261
4262void cli_show_router_bgp_default_shutdown(struct vty *vty,
4263 struct lyd_node *dnode,
4264 bool show_defaults)
4265{
4266 if (yang_dnode_get_bool(dnode, NULL))
4267 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4268}
4269
736b68f3
DS
4270DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4271 BGP_STR
9ddf4b81 4272 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4273 "Add a shutdown message (RFC 8203)\n"
4274 "Shutdown message\n")
9cf59432 4275{
736b68f3 4276 char *msgstr = NULL;
8389c83a 4277
9cf59432
DS
4278 VTY_DECLVAR_CONTEXT(bgp, bgp);
4279
8389c83a 4280 if (argc > 3)
f80e35b6 4281 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4282
4283 bgp_shutdown_enable(bgp, msgstr);
4284 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4285
4286 return CMD_SUCCESS;
4287}
4288
736b68f3 4289DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4290 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4291{
4292 VTY_DECLVAR_CONTEXT(bgp, bgp);
4293
4294 bgp_shutdown_enable(bgp, NULL);
4295
4296 return CMD_SUCCESS;
4297}
8389c83a 4298
736b68f3 4299DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4300 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4301{
4302 VTY_DECLVAR_CONTEXT(bgp, bgp);
4303
4304 bgp_shutdown_disable(bgp);
4305
4306 return CMD_SUCCESS;
4307}
4308
9ddf4b81 4309ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4310 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4311 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4312 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4313
f4b8ec07
CS
4314DEFUN_YANG(neighbor_remote_as,
4315 neighbor_remote_as_cmd,
4316 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4317 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4318 "Specify a BGP neighbor\n" AS_STR
4319 "Internal BGP peer\n"
4320 "External BGP peer\n")
718e3744 4321{
d62a17ae 4322 int idx_peer = 1;
4323 int idx_remote_as = 3;
f4b8ec07
CS
4324 char base_xpath[XPATH_MAXLEN];
4325 char unnbr_xpath[XPATH_MAXLEN];
4326 char prgrp_xpath[XPATH_MAXLEN];
4327 union sockunion su;
4328 const char *as_type_str = "as-specified";
4329
4330 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4331 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4332 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4333
4334 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4335 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4336
4337 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4338 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4339 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4340 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4341 "%s%s", VTY_CURR_XPATH,
4342 prgrp_xpath + 1)) {
4343 snprintf(base_xpath, sizeof(base_xpath),
4344 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4345 "");
4346 } else {
4347 vty_out(vty,
4348 "%% Create the peer-group or interface first\n");
4349 return CMD_WARNING_CONFIG_FAILED;
4350 }
4351 } else {
4352 snprintf(base_xpath, sizeof(base_xpath),
4353 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4354 }
4355
4356 if (argv[idx_remote_as]->arg[0] == 'i') {
4357 as_type_str = "internal";
4358 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4359 as_type_str = "external";
4360 } else {
4361 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4362 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4363 }
4364 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4365 NB_OP_MODIFY, as_type_str);
4366
4367 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4368}
4369
f4b8ec07
CS
4370int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4371 safi_t safi, bool v6only,
4372 const char *peer_group_name, int as_type,
4373 as_t as, char *errmsg, size_t errmsg_len)
d62a17ae 4374{
d62a17ae 4375 struct peer *peer;
4376 struct peer_group *group;
4377 int ret = 0;
d62a17ae 4378
4379 group = peer_group_lookup(bgp, conf_if);
4380
4381 if (group) {
f4b8ec07
CS
4382 snprintf(errmsg, errmsg_len,
4383 "Name conflict with peer-group \n");
4384 return -1;
d62a17ae 4385 }
4386
4387 peer = peer_lookup_by_conf_if(bgp, conf_if);
4388 if (peer) {
f4b8ec07 4389 if (as_type != AS_UNSPECIFIED)
cc4d4ce8 4390 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 4391 afi, safi);
4392 } else {
892fedb6 4393 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 4394 && afi == AFI_IP && safi == SAFI_UNICAST)
4395 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4396 as_type, 0, 0, NULL);
4397 else
4398 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4399 as_type, afi, safi, NULL);
4400
4401 if (!peer) {
f4b8ec07
CS
4402 snprintf(errmsg, errmsg_len,
4403 "BGP failed to create peer\n");
4404 return -1;
d62a17ae 4405 }
4406
4407 if (v6only)
527de3dc 4408 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4409
4410 /* Request zebra to initiate IPv6 RAs on this interface. We do
4411 * this
4412 * any unnumbered peer in order to not worry about run-time
4413 * transitions
4414 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4415 * address
4416 * gets deleted later etc.)
4417 */
4418 if (peer->ifp)
4419 bgp_zebra_initiate_radv(bgp, peer);
4420 }
4421
4422 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4423 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4424 if (v6only)
527de3dc 4425 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4426 else
527de3dc 4427 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4428
4429 /* v6only flag changed. Reset bgp seesion */
4430 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4431 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4432 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4433 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4434 } else
4435 bgp_session_reset(peer);
4436 }
4437
9fb964de
PM
4438 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4439 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4440 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4441 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4442 }
d62a17ae 4443
4444 if (peer_group_name) {
4445 group = peer_group_lookup(bgp, peer_group_name);
4446 if (!group) {
f4b8ec07
CS
4447 snprintf(errmsg, errmsg_len,
4448 "Configure the peer-group first\n");
4449 return -1;
d62a17ae 4450 }
4451
8395c1f8 4452 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4453 }
4454
f4b8ec07 4455 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
a80beece
DS
4456}
4457
232c75cd
CS
4458DEFUN_YANG(neighbor_interface_config,
4459 neighbor_interface_config_cmd,
f4b8ec07
CS
4460 "neighbor WORD interface [peer-group PGNAME]",
4461 NEIGHBOR_STR
4462 "Interface name or neighbor tag\n"
4463 "Enable BGP on interface\n"
4464 "Member of the peer-group\n"
4465 "Peer-group name\n")
4c48cf63 4466{
d62a17ae 4467 int idx_word = 1;
4468 int idx_peer_group_word = 4;
f4b8ec07
CS
4469 char base_xpath[XPATH_MAXLEN];
4470
4471 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4472 argv[idx_word]->arg, "");
31500417 4473
f4b8ec07 4474 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4475 if (argc > idx_peer_group_word)
f4b8ec07
CS
4476 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4477 argv[idx_peer_group_word]->arg);
4478
4479 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4480}
4481
f4b8ec07
CS
4482DEFUN_YANG(neighbor_interface_config_v6only,
4483 neighbor_interface_config_v6only_cmd,
4484 "neighbor WORD interface v6only [peer-group PGNAME]",
4485 NEIGHBOR_STR
4486 "Interface name or neighbor tag\n"
4487 "Enable BGP on interface\n"
4488 "Enable BGP with v6 link-local only\n"
4489 "Member of the peer-group\n"
4490 "Peer-group name\n")
4c48cf63 4491{
d62a17ae 4492 int idx_word = 1;
4493 int idx_peer_group_word = 5;
f4b8ec07
CS
4494 char base_xpath[XPATH_MAXLEN];
4495
4496 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4497 argv[idx_word]->arg, "");
31500417 4498
f4b8ec07 4499 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4500 if (argc > idx_peer_group_word)
f4b8ec07
CS
4501 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4502 argv[idx_peer_group_word]->arg);
31500417 4503
f4b8ec07
CS
4504 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4505
4506 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4507}
4508
a80beece 4509
f4b8ec07
CS
4510DEFUN_YANG(
4511 neighbor_interface_config_remote_as,
4512 neighbor_interface_config_remote_as_cmd,
4513 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4514 NEIGHBOR_STR
4515 "Interface name or neighbor tag\n"
4516 "Enable BGP on interface\n"
4517 "Specify a BGP neighbor\n" AS_STR
4518 "Internal BGP peer\n"
4519 "External BGP peer\n")
b3a39dc5 4520{
d62a17ae 4521 int idx_word = 1;
4522 int idx_remote_as = 4;
f4b8ec07
CS
4523 char base_xpath[XPATH_MAXLEN];
4524 const char *as_type_str = "as-specified";
4525
4526 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4527 argv[idx_word]->arg, "");
4528
4529 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4530
4531 if (argv[idx_remote_as]->arg[0] == 'i') {
4532 as_type_str = "internal";
4533 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4534 as_type_str = "external";
4535 } else {
4536 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4537 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4538 }
4539 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4540 NB_OP_MODIFY, as_type_str);
4541
4542 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4543}
4544
f4b8ec07
CS
4545DEFUN_YANG(
4546 neighbor_interface_v6only_config_remote_as,
4547 neighbor_interface_v6only_config_remote_as_cmd,
4548 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4549 NEIGHBOR_STR
4550 "Interface name or neighbor tag\n"
4551 "Enable BGP with v6 link-local only\n"
4552 "Enable BGP on interface\n"
4553 "Specify a BGP neighbor\n" AS_STR
4554 "Internal BGP peer\n"
4555 "External BGP peer\n")
b3a39dc5 4556{
d62a17ae 4557 int idx_word = 1;
4558 int idx_remote_as = 5;
f4b8ec07
CS
4559 char base_xpath[XPATH_MAXLEN];
4560 const char *as_type_str = "as-specified";
4561
4562 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4563 argv[idx_word]->arg, "");
4564
4565 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4566
4567 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4568
4569 if (argv[idx_remote_as]->arg[0] == 'i') {
4570 as_type_str = "internal";
4571 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4572 as_type_str = "external";
4573 } else {
4574 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4575 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4576 }
4577 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4578 NB_OP_MODIFY, as_type_str);
4579
4580 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4581}
4582
f4b8ec07
CS
4583DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4584 "neighbor WORD peer-group",
4585 NEIGHBOR_STR
4586 "Interface name or neighbor tag\n"
4587 "Configure peer-group\n")
718e3744 4588{
f4b8ec07 4589 char base_xpath[XPATH_MAXLEN];
d62a17ae 4590 int idx_word = 1;
718e3744 4591
f4b8ec07
CS
4592 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4593 argv[idx_word]->arg, "");
718e3744 4594
f4b8ec07 4595 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 4596
f4b8ec07 4597 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4598}
4599
232c75cd
CS
4600DEFUN_YANG(no_neighbor,
4601 no_neighbor_cmd,
4602 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4603 NO_STR NEIGHBOR_STR
4604 NEIGHBOR_ADDR_STR2
4605 "Specify a BGP neighbor\n" AS_STR
4606 "Internal BGP peer\n"
4607 "External BGP peer\n")
718e3744 4608{
d62a17ae 4609 int idx_peer = 2;
f4b8ec07
CS
4610 char base_xpath[XPATH_MAXLEN];
4611 char num_xpath[XPATH_MAXLEN];
4612 char unnbr_xpath[XPATH_MAXLEN];
4613 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4614 union sockunion su;
d62a17ae 4615
f4b8ec07
CS
4616 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4617 snprintf(num_xpath, sizeof(num_xpath),
4618 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4619 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4620 VTY_CURR_XPATH, num_xpath + 1)) {
4621 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
d62a17ae 4622 }
f4b8ec07
CS
4623 } else {
4624 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4625 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4626
4627 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4628 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4629
4630 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4631 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4632 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4633 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4634 "%s%s", VTY_CURR_XPATH,
4635 prgrp_xpath + 1)) {
4636 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4e2786df 4637 } else {
f4b8ec07
CS
4638 vty_out(vty,
4639 "%% Create the peer-group or interface first\n");
d62a17ae 4640 return CMD_WARNING_CONFIG_FAILED;
4641 }
1ff9a340 4642 }
718e3744 4643
f4b8ec07
CS
4644 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4645
4646 return nb_cli_apply_changes(vty, NULL);
718e3744 4647}
4648
f4b8ec07
CS
4649DEFUN_YANG(no_neighbor_interface_config,
4650 no_neighbor_interface_config_cmd,
4651 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4652 NO_STR NEIGHBOR_STR
4653 "Interface name\n"
4654 "Configure BGP on interface\n"
4655 "Enable BGP with v6 link-local only\n"
4656 "Member of the peer-group\n"
4657 "Peer-group name\n"
4658 "Specify a BGP neighbor\n" AS_STR
4659 "Internal BGP peer\n"
4660 "External BGP peer\n")
a80beece 4661{
d62a17ae 4662 int idx_word = 2;
f4b8ec07 4663 char base_xpath[XPATH_MAXLEN];
d62a17ae 4664
f4b8ec07
CS
4665 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4666 argv[idx_word]->arg, "");
4667
4668 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4669
4670 return nb_cli_apply_changes(vty, base_xpath);
a80beece
DS
4671}
4672
f4b8ec07
CS
4673DEFUN_YANG(no_neighbor_peer_group,
4674 no_neighbor_peer_group_cmd,
4675 "no neighbor WORD peer-group",
4676 NO_STR NEIGHBOR_STR
4677 "Neighbor tag\n"
4678 "Configure peer-group\n")
718e3744 4679{
f4b8ec07 4680 char base_xpath[XPATH_MAXLEN];
d62a17ae 4681 int idx_word = 2;
718e3744 4682
f4b8ec07
CS
4683 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4684 argv[idx_word]->arg, "");
4685
4686 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4687
4688 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4689}
4690
f4b8ec07
CS
4691DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4692 no_neighbor_interface_peer_group_remote_as_cmd,
4693 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4694 NO_STR NEIGHBOR_STR
4695 "Interface name or neighbor tag\n"
4696 "Specify a BGP neighbor\n" AS_STR
4697 "Internal BGP peer\n"
4698 "External BGP peer\n")
718e3744 4699{
f4b8ec07
CS
4700 int idx_peer = 2;
4701 char base_xpath[XPATH_MAXLEN];
4702 char unnbr_xpath[XPATH_MAXLEN];
4703 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4704
f4b8ec07
CS
4705 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4706 argv[idx_peer]->arg, "");
d62a17ae 4707
f4b8ec07
CS
4708 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4709 argv[idx_peer]->arg, "");
4710
4711 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4712 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4713 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4714 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4715 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4716 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4717 } else {
d62a17ae 4718 vty_out(vty, "%% Create the peer-group or interface first\n");
4719 return CMD_WARNING_CONFIG_FAILED;
4720 }
f4b8ec07
CS
4721
4722 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4723 sizeof(base_xpath));
4724
4725 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4726
4727 return nb_cli_apply_changes(vty, NULL);
718e3744 4728}
6b0655a2 4729
f4b8ec07
CS
4730DEFUN_YANG(neighbor_local_as,
4731 neighbor_local_as_cmd,
4732 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4733 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4734 "Specify a local-as number\n"
4735 "AS number used as local AS\n")
718e3744 4736{
d62a17ae 4737 int idx_peer = 1;
4738 int idx_number = 3;
f4b8ec07 4739 char base_xpath[XPATH_MAXLEN];
718e3744 4740
f4b8ec07
CS
4741 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4742 sizeof(base_xpath), NULL)
4743 < 0)
d62a17ae 4744 return CMD_WARNING_CONFIG_FAILED;
718e3744 4745
f4b8ec07
CS
4746 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4747 argv[idx_number]->arg);
4748
4749 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4750}
4751
f4b8ec07
CS
4752DEFUN_YANG(
4753 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4754 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4755 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4756 "Specify a local-as number\n"
4757 "AS number used as local AS\n"
4758 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4759{
d62a17ae 4760 int idx_peer = 1;
4761 int idx_number = 3;
f4b8ec07 4762 char base_xpath[XPATH_MAXLEN];
718e3744 4763
f4b8ec07
CS
4764 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4765 sizeof(base_xpath), NULL)
4766 < 0)
d62a17ae 4767 return CMD_WARNING_CONFIG_FAILED;
718e3744 4768
f4b8ec07
CS
4769 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4770 argv[idx_number]->arg);
4771 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4772 "true");
4773
4774 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4775}
4776
f4b8ec07
CS
4777DEFUN_YANG(
4778 neighbor_local_as_no_prepend_replace_as,
4779 neighbor_local_as_no_prepend_replace_as_cmd,
4780 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4781 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4782 "Specify a local-as number\n"
4783 "AS number used as local AS\n"
4784 "Do not prepend local-as to updates from ebgp peers\n"
4785 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4786{
d62a17ae 4787 int idx_peer = 1;
4788 int idx_number = 3;
f4b8ec07 4789 char base_xpath[XPATH_MAXLEN];
9d3f9705 4790
f4b8ec07
CS
4791 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4792 sizeof(base_xpath), NULL)
4793 < 0)
d62a17ae 4794 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4795
f4b8ec07
CS
4796 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4797 argv[idx_number]->arg);
4798 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4799 "true");
4800 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4801 "true");
4802
4803 return nb_cli_apply_changes(vty, base_xpath);
9d3f9705
AC
4804}
4805
f4b8ec07
CS
4806DEFUN_YANG(no_neighbor_local_as,
4807 no_neighbor_local_as_cmd,
4808 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4809 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4810 "Specify a local-as number\n"
4811 "AS number used as local AS\n"
4812 "Do not prepend local-as to updates from ebgp peers\n"
4813 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4814{
d62a17ae 4815 int idx_peer = 2;
f4b8ec07 4816 char base_xpath[XPATH_MAXLEN];
718e3744 4817
f4b8ec07
CS
4818 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4819 sizeof(base_xpath), NULL)
4820 < 0)
d62a17ae 4821 return CMD_WARNING_CONFIG_FAILED;
718e3744 4822
f4b8ec07
CS
4823 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4824 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4825 "false");
4826 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4827 "false");
4828
4829 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4830}
4831
718e3744 4832
3f9c7369
DS
4833DEFUN (neighbor_solo,
4834 neighbor_solo_cmd,
9ccf14f7 4835 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4836 NEIGHBOR_STR
4837 NEIGHBOR_ADDR_STR2
4838 "Solo peer - part of its own update group\n")
4839{
d62a17ae 4840 int idx_peer = 1;
4841 struct peer *peer;
4842 int ret;
3f9c7369 4843
d62a17ae 4844 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4845 if (!peer)
4846 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4847
d62a17ae 4848 ret = update_group_adjust_soloness(peer, 1);
4849 return bgp_vty_return(vty, ret);
3f9c7369
DS
4850}
4851
4852DEFUN (no_neighbor_solo,
4853 no_neighbor_solo_cmd,
9ccf14f7 4854 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4855 NO_STR
4856 NEIGHBOR_STR
4857 NEIGHBOR_ADDR_STR2
4858 "Solo peer - part of its own update group\n")
4859{
d62a17ae 4860 int idx_peer = 2;
4861 struct peer *peer;
4862 int ret;
3f9c7369 4863
d62a17ae 4864 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4865 if (!peer)
4866 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4867
d62a17ae 4868 ret = update_group_adjust_soloness(peer, 0);
4869 return bgp_vty_return(vty, ret);
3f9c7369
DS
4870}
4871
f4b8ec07
CS
4872DEFUN_YANG(neighbor_password,
4873 neighbor_password_cmd,
4874 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4875 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4876 "Set a password\n"
4877 "The password\n")
0df7c91f 4878{
d62a17ae 4879 int idx_peer = 1;
4880 int idx_line = 3;
f4b8ec07 4881 char base_xpath[XPATH_MAXLEN];
0df7c91f 4882
f4b8ec07
CS
4883 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4884 sizeof(base_xpath), NULL)
4885 < 0)
d62a17ae 4886 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4887
f4b8ec07
CS
4888 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4889 argv[idx_line]->arg);
4890
4891 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f
PJ
4892}
4893
f4b8ec07
CS
4894DEFUN_YANG(no_neighbor_password,
4895 no_neighbor_password_cmd,
4896 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4897 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4898 "Set a password\n"
4899 "The password\n")
0df7c91f 4900{
d62a17ae 4901 int idx_peer = 2;
f4b8ec07 4902 char base_xpath[XPATH_MAXLEN];
0df7c91f 4903
f4b8ec07
CS
4904 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4905 sizeof(base_xpath), NULL)
4906 < 0)
d62a17ae 4907 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4908
f4b8ec07
CS
4909 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4910
4911 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f 4912}
6b0655a2 4913
f4b8ec07
CS
4914DEFUN_YANG(neighbor_activate,
4915 neighbor_activate_cmd,
4916 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4918 "Enable the Address Family for this Neighbor\n")
718e3744 4919{
d62a17ae 4920 int idx_peer = 1;
f4b8ec07 4921 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
4922 char af_xpath[XPATH_MAXLEN];
4923 afi_t afi = bgp_node_afi(vty);
4924 safi_t safi = bgp_node_safi(vty);
718e3744 4925
f4b8ec07
CS
4926 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4927 yang_afi_safi_value2identity(afi, safi));
555c8ab7
CS
4928 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4929 sizeof(base_xpath), af_xpath)
f4b8ec07 4930 < 0)
d62a17ae 4931 return CMD_WARNING_CONFIG_FAILED;
718e3744 4932
555c8ab7 4933 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
f4b8ec07
CS
4934
4935 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4936}
4937
d62a17ae 4938ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4939 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4941 "Enable the Address Family for this Neighbor\n")
596c17ba 4942
f4b8ec07
CS
4943DEFUN_YANG(no_neighbor_activate,
4944 no_neighbor_activate_cmd,
4945 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4946 NO_STR NEIGHBOR_STR
4947 NEIGHBOR_ADDR_STR2
4948 "Enable the Address Family for this Neighbor\n")
718e3744 4949{
d62a17ae 4950 int idx_peer = 2;
f4b8ec07
CS
4951 char base_xpath[XPATH_MAXLEN];
4952 char af_xpath[XPATH_MAXLEN];
4953 afi_t afi = bgp_node_afi(vty);
4954 safi_t safi = bgp_node_safi(vty);
718e3744 4955
f4b8ec07
CS
4956 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4957 yang_afi_safi_value2identity(afi, safi));
4958
4959 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4960 sizeof(base_xpath), af_xpath)
4961 < 0)
d62a17ae 4962 return CMD_WARNING_CONFIG_FAILED;
718e3744 4963
f4b8ec07
CS
4964 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4965
4966 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4967}
6b0655a2 4968
d62a17ae 4969ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4970 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4971 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4972 "Enable the Address Family for this Neighbor\n")
596c17ba 4973
2a059a54
DS
4974DEFUN (neighbor_set_peer_group,
4975 neighbor_set_peer_group_cmd,
4976 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4977 NEIGHBOR_STR
4978 NEIGHBOR_ADDR_STR2
4979 "Member of the peer-group\n"
4980 "Peer-group name\n")
718e3744 4981{
2a059a54 4982 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4983 int idx_peer = 1;
4984 int idx_word = 3;
2a059a54
DS
4985 int ret;
4986 as_t as;
4987 union sockunion su;
4988 struct peer *peer;
4989 struct peer_group *group;
d62a17ae 4990
2a059a54
DS
4991 ret = str2sockunion(argv[idx_peer]->arg, &su);
4992 if (ret < 0) {
4993 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4994 if (!peer) {
4995 vty_out(vty, "%% Malformed address or name: %s\n",
4996 argv[idx_peer]->arg);
4997 return CMD_WARNING_CONFIG_FAILED;
4998 }
4999 } else {
5000 if (peer_address_self_check(bgp, &su)) {
5001 vty_out(vty,
5002 "%% Can not configure the local system as neighbor\n");
5003 return CMD_WARNING_CONFIG_FAILED;
5004 }
5005
5006 /* Disallow for dynamic neighbor. */
5007 peer = peer_lookup(bgp, &su);
5008 if (peer && peer_dynamic_neighbor(peer)) {
5009 vty_out(vty,
5010 "%% Operation not allowed on a dynamic neighbor\n");
5011 return CMD_WARNING_CONFIG_FAILED;
5012 }
5013 }
5014
5015 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5016 if (!group) {
5017 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5018 return CMD_WARNING_CONFIG_FAILED;
2a059a54 5019 }
d62a17ae 5020
2a059a54 5021 ret = peer_group_bind(bgp, &su, peer, group, &as);
d62a17ae 5022
2a059a54
DS
5023 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5024 vty_out(vty,
5025 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5026 as);
5027 return CMD_WARNING_CONFIG_FAILED;
5028 }
5029
5030 return bgp_vty_return(vty, ret);
d62a17ae 5031}
5032
5033ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5034 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5035 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5036 "Member of the peer-group\n"
5037 "Peer-group name\n")
596c17ba 5038
f4b8ec07
CS
5039DEFUN_YANG (no_neighbor_set_peer_group,
5040 no_neighbor_set_peer_group_cmd,
2cbd181a 5041 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
f4b8ec07
CS
5042 NO_STR
5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "Member of the peer-group\n"
5046 "Peer-group name\n")
718e3744 5047{
d62a17ae 5048 int idx_peer = 2;
f4b8ec07 5049 char base_xpath[XPATH_MAXLEN];
d62a17ae 5050
f4b8ec07
CS
5051 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5052 sizeof(base_xpath), NULL)
5053 < 0)
d62a17ae 5054 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5055
f4b8ec07 5056 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
718e3744 5057
f4b8ec07 5058 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5059}
6b0655a2 5060
d62a17ae 5061ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
2cbd181a 5062 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
d62a17ae 5063 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5064 "Member of the peer-group\n"
5065 "Peer-group name\n")
596c17ba 5066
d62a17ae 5067static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5068 uint32_t flag, int set)
718e3744 5069{
d62a17ae 5070 int ret;
5071 struct peer *peer;
718e3744 5072
d62a17ae 5073 peer = peer_and_group_lookup_vty(vty, ip_str);
5074 if (!peer)
5075 return CMD_WARNING_CONFIG_FAILED;
718e3744 5076
7ebe625c
QY
5077 /*
5078 * If 'neighbor <interface>', then this is for directly connected peers,
5079 * we should not accept disable-connected-check.
5080 */
5081 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5082 vty_out(vty,
3efd0893 5083 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5084 ip_str);
5085 return CMD_WARNING_CONFIG_FAILED;
5086 }
5087
d62a17ae 5088 if (!set && flag == PEER_FLAG_SHUTDOWN)
5089 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5090
d62a17ae 5091 if (set)
5092 ret = peer_flag_set(peer, flag);
5093 else
5094 ret = peer_flag_unset(peer, flag);
718e3744 5095
d62a17ae 5096 return bgp_vty_return(vty, ret);
718e3744 5097}
5098
47cbc09b 5099static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5100{
d62a17ae 5101 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5102}
5103
d62a17ae 5104static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5105 uint32_t flag)
718e3744 5106{
d62a17ae 5107 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5108}
5109
f4b8ec07
CS
5110int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5111 uint32_t flag, bool set, char *errmsg,
5112 size_t errmsg_len)
5113{
5114 int ret;
5115
5116 /*
5117 * If 'neighbor <interface>', then this is for directly connected peers,
5118 * we should not accept disable-connected-check.
5119 */
5120 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5121 snprintf(
5122 errmsg, errmsg_len,
5123 "%s is directly connected peer, cannot accept disable-connected-check\n",
5124 ip_str);
5125 return -1;
5126 }
5127
5128 if (!set && flag == PEER_FLAG_SHUTDOWN)
5129 peer_tx_shutdown_message_unset(peer);
5130
5131 if (set)
5132 ret = peer_flag_set(peer, flag);
5133 else
5134 ret = peer_flag_unset(peer, flag);
5135
5136 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5137}
5138
718e3744 5139/* neighbor passive. */
f4b8ec07
CS
5140DEFUN_YANG(neighbor_passive,
5141 neighbor_passive_cmd,
5142 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5143 NEIGHBOR_STR
5144 NEIGHBOR_ADDR_STR2
5145 "Don't send open messages to this neighbor\n")
718e3744 5146{
d62a17ae 5147 int idx_peer = 1;
f4b8ec07
CS
5148 char base_xpath[XPATH_MAXLEN];
5149
5150 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5151 sizeof(base_xpath), NULL)
5152 < 0)
5153 return CMD_WARNING_CONFIG_FAILED;
5154
5155 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5156
5157 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5158}
5159
f4b8ec07
CS
5160DEFUN_YANG(no_neighbor_passive,
5161 no_neighbor_passive_cmd,
5162 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5163 NO_STR NEIGHBOR_STR
5164 NEIGHBOR_ADDR_STR2
5165 "Don't send open messages to this neighbor\n")
718e3744 5166{
d62a17ae 5167 int idx_peer = 2;
f4b8ec07
CS
5168 char base_xpath[XPATH_MAXLEN];
5169
5170 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5171 sizeof(base_xpath), NULL)
5172 < 0)
5173 return CMD_WARNING_CONFIG_FAILED;
5174
5175 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5176
5177 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5178}
6b0655a2 5179
718e3744 5180/* neighbor shutdown. */
f4b8ec07
CS
5181DEFUN_YANG(neighbor_shutdown_msg,
5182 neighbor_shutdown_msg_cmd,
5183 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5184 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5185 "Administratively shut down this neighbor\n"
5186 "Add a shutdown message (RFC 8203)\n"
5187 "Shutdown message\n")
718e3744 5188{
d62a17ae 5189 int idx_peer = 1;
f4b8ec07
CS
5190 char base_xpath[XPATH_MAXLEN];
5191
5192 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5193 sizeof(base_xpath), NULL)
5194 < 0)
5195 return CMD_WARNING_CONFIG_FAILED;
73d70fa6 5196
d62a17ae 5197 if (argc >= 5) {
d62a17ae 5198 char *message;
73d70fa6 5199
d62a17ae 5200 message = argv_concat(argv, argc, 4);
f4b8ec07
CS
5201 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5202 NB_OP_MODIFY, message);
d62a17ae 5203 }
73d70fa6 5204
f4b8ec07
CS
5205 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5206 "true");
5207
5208 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5209}
5210
232c75cd 5211ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5212 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5213 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5214 "Administratively shut down this neighbor\n")
73d70fa6 5215
f4b8ec07
CS
5216DEFUN_YANG(no_neighbor_shutdown_msg,
5217 no_neighbor_shutdown_msg_cmd,
5218 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5219 NO_STR NEIGHBOR_STR
5220 NEIGHBOR_ADDR_STR2
5221 "Administratively shut down this neighbor\n"
5222 "Remove a shutdown message (RFC 8203)\n"
5223 "Shutdown message\n")
718e3744 5224{
d62a17ae 5225 int idx_peer = 2;
f4b8ec07 5226 char base_xpath[XPATH_MAXLEN];
73d70fa6 5227
f4b8ec07
CS
5228 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5229 sizeof(base_xpath), NULL)
5230 < 0)
5231 return CMD_WARNING_CONFIG_FAILED;
5232
5233 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5234 "false");
5235
5236 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5237}
6b0655a2 5238
232c75cd 5239ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5240 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5241 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5242 "Administratively shut down this neighbor\n")
73d70fa6 5243
8336c896
DA
5244DEFUN(neighbor_shutdown_rtt,
5245 neighbor_shutdown_rtt_cmd,
5246 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5247 NEIGHBOR_STR
5248 NEIGHBOR_ADDR_STR2
5249 "Administratively shut down this neighbor\n"
5250 "Shutdown if round-trip-time is higher than expected\n"
5251 "Round-trip-time in milliseconds\n"
5252 "Specify the number of keepalives before shutdown\n"
5253 "The number of keepalives with higher RTT to shutdown\n")
5254{
5255 int idx_peer = 1;
5256 int idx_rtt = 4;
5257 int idx_count = 0;
5258 struct peer *peer;
5259
5260 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5261
5262 if (!peer)
5263 return CMD_WARNING_CONFIG_FAILED;
5264
5265 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5266
5267 if (argv_find(argv, argc, "count", &idx_count))
5268 peer->rtt_keepalive_conf =
5269 strtol(argv[idx_count + 1]->arg, NULL, 10);
5270
5271 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5272 PEER_FLAG_RTT_SHUTDOWN);
5273}
5274
5275DEFUN(no_neighbor_shutdown_rtt,
5276 no_neighbor_shutdown_rtt_cmd,
5277 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5278 NO_STR
5279 NEIGHBOR_STR
5280 NEIGHBOR_ADDR_STR2
5281 "Administratively shut down this neighbor\n"
5282 "Shutdown if round-trip-time is higher than expected\n"
5283 "Round-trip-time in milliseconds\n"
5284 "Specify the number of keepalives before shutdown\n"
5285 "The number of keepalives with higher RTT to shutdown\n")
5286{
5287 int idx_peer = 2;
5288 struct peer *peer;
5289
5290 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5291
5292 if (!peer)
5293 return CMD_WARNING_CONFIG_FAILED;
5294
5295 peer->rtt_expected = 0;
5296 peer->rtt_keepalive_conf = 1;
5297
5298 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5299 PEER_FLAG_RTT_SHUTDOWN);
5300}
5301
718e3744 5302/* neighbor capability dynamic. */
f4b8ec07
CS
5303DEFUN_YANG (neighbor_capability_dynamic,
5304 neighbor_capability_dynamic_cmd,
5305 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5306 NEIGHBOR_STR
5307 NEIGHBOR_ADDR_STR2
5308 "Advertise capability to the peer\n"
5309 "Advertise dynamic capability to this neighbor\n")
718e3744 5310{
d62a17ae 5311 int idx_peer = 1;
f4b8ec07
CS
5312 char base_xpath[XPATH_MAXLEN];
5313
5314 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5315 sizeof(base_xpath), NULL)
5316 < 0)
5317 return CMD_WARNING_CONFIG_FAILED;
5318
5319 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5320 NB_OP_MODIFY, "true");
5321
5322 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5323}
5324
f4b8ec07
CS
5325DEFUN_YANG (no_neighbor_capability_dynamic,
5326 no_neighbor_capability_dynamic_cmd,
5327 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5328 NO_STR
5329 NEIGHBOR_STR
5330 NEIGHBOR_ADDR_STR2
5331 "Advertise capability to the peer\n"
5332 "Advertise dynamic capability to this neighbor\n")
718e3744 5333{
d62a17ae 5334 int idx_peer = 2;
f4b8ec07
CS
5335 char base_xpath[XPATH_MAXLEN];
5336
5337 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5338 sizeof(base_xpath), NULL)
5339 < 0)
5340 return CMD_WARNING_CONFIG_FAILED;
5341
5342 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5343 NB_OP_MODIFY, "false");
5344
5345 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5346}
6b0655a2 5347
718e3744 5348/* neighbor dont-capability-negotiate */
5349DEFUN (neighbor_dont_capability_negotiate,
5350 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5351 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5352 NEIGHBOR_STR
5353 NEIGHBOR_ADDR_STR2
5354 "Do not perform capability negotiation\n")
5355{
d62a17ae 5356 int idx_peer = 1;
5357 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5358 PEER_FLAG_DONT_CAPABILITY);
718e3744 5359}
5360
5361DEFUN (no_neighbor_dont_capability_negotiate,
5362 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5363 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5364 NO_STR
5365 NEIGHBOR_STR
5366 NEIGHBOR_ADDR_STR2
5367 "Do not perform capability negotiation\n")
5368{
d62a17ae 5369 int idx_peer = 2;
5370 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5371 PEER_FLAG_DONT_CAPABILITY);
718e3744 5372}
6b0655a2 5373
8a92a8a0 5374/* neighbor capability extended next hop encoding */
f4b8ec07
CS
5375DEFUN_YANG (neighbor_capability_enhe,
5376 neighbor_capability_enhe_cmd,
5377 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5378 NEIGHBOR_STR
5379 NEIGHBOR_ADDR_STR2
5380 "Advertise capability to the peer\n"
5381 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5382{
d62a17ae 5383 int idx_peer = 1;
f4b8ec07
CS
5384 char base_xpath[XPATH_MAXLEN];
5385
5386 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5387 sizeof(base_xpath), NULL)
5388 < 0)
5389 return CMD_WARNING_CONFIG_FAILED;
5390
5391 nb_cli_enqueue_change(
5392 vty, "./capability-options/extended-nexthop-capability",
5393 NB_OP_MODIFY, "true");
5394
5395 return nb_cli_apply_changes(vty, base_xpath);
8a92a8a0
DS
5396}
5397
f4b8ec07
CS
5398DEFUN_YANG (no_neighbor_capability_enhe,
5399 no_neighbor_capability_enhe_cmd,
5400 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5401 NO_STR
5402 NEIGHBOR_STR
5403 NEIGHBOR_ADDR_STR2
5404 "Advertise capability to the peer\n"
5405 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5406{
d62a17ae 5407 int idx_peer = 2;
f4b8ec07
CS
5408 char base_xpath[XPATH_MAXLEN];
5409
5410 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5411 sizeof(base_xpath), NULL)
5412 < 0)
5413 return CMD_WARNING_CONFIG_FAILED;
5414
5415 nb_cli_enqueue_change(
5416 vty, "./capability-options/extended-nexthop-capability",
5417 NB_OP_MODIFY, "false");
5418
5419 return nb_cli_apply_changes(vty, base_xpath);
5420}
5421
5422int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5423 uint32_t flag, int set, char *errmsg,
5424 size_t errmsg_len)
5425{
5426 int ret;
5427
5428 if (set)
5429 ret = peer_af_flag_set(peer, afi, safi, flag);
5430 else
5431 ret = peer_af_flag_unset(peer, afi, safi, flag);
5432
5433 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
8a92a8a0
DS
5434}
5435
d62a17ae 5436static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5437 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5438 int set)
718e3744 5439{
d62a17ae 5440 int ret;
5441 struct peer *peer;
718e3744 5442
d62a17ae 5443 peer = peer_and_group_lookup_vty(vty, peer_str);
5444 if (!peer)
5445 return CMD_WARNING_CONFIG_FAILED;
718e3744 5446
d62a17ae 5447 if (set)
5448 ret = peer_af_flag_set(peer, afi, safi, flag);
5449 else
5450 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5451
d62a17ae 5452 return bgp_vty_return(vty, ret);
718e3744 5453}
5454
d62a17ae 5455static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5456 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5457{
d62a17ae 5458 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5459}
5460
d62a17ae 5461static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5462 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5463{
d62a17ae 5464 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5465}
6b0655a2 5466
718e3744 5467/* neighbor capability orf prefix-list. */
5468DEFUN (neighbor_capability_orf_prefix,
5469 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5470 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5471 NEIGHBOR_STR
5472 NEIGHBOR_ADDR_STR2
5473 "Advertise capability to the peer\n"
5474 "Advertise ORF capability to the peer\n"
5475 "Advertise prefixlist ORF capability to this neighbor\n"
5476 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5477 "Capability to RECEIVE the ORF from this neighbor\n"
5478 "Capability to SEND the ORF to this neighbor\n")
5479{
d62a17ae 5480 int idx_send_recv = 5;
db45f64d
DS
5481 char *peer_str = argv[1]->arg;
5482 struct peer *peer;
5483 afi_t afi = bgp_node_afi(vty);
5484 safi_t safi = bgp_node_safi(vty);
d62a17ae 5485
db45f64d
DS
5486 peer = peer_and_group_lookup_vty(vty, peer_str);
5487 if (!peer)
d62a17ae 5488 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5489
db45f64d
DS
5490 if (strmatch(argv[idx_send_recv]->text, "send"))
5491 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5492 PEER_FLAG_ORF_PREFIX_SM);
5493
5494 if (strmatch(argv[idx_send_recv]->text, "receive"))
5495 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5496 PEER_FLAG_ORF_PREFIX_RM);
5497
5498 if (strmatch(argv[idx_send_recv]->text, "both"))
5499 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5500 PEER_FLAG_ORF_PREFIX_SM)
5501 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5502 PEER_FLAG_ORF_PREFIX_RM);
5503
5504 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5505}
5506
5507ALIAS_HIDDEN(
5508 neighbor_capability_orf_prefix,
5509 neighbor_capability_orf_prefix_hidden_cmd,
5510 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5511 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5512 "Advertise capability to the peer\n"
5513 "Advertise ORF capability to the peer\n"
5514 "Advertise prefixlist ORF capability to this neighbor\n"
5515 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5516 "Capability to RECEIVE the ORF from this neighbor\n"
5517 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5518
718e3744 5519DEFUN (no_neighbor_capability_orf_prefix,
5520 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5521 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5522 NO_STR
5523 NEIGHBOR_STR
5524 NEIGHBOR_ADDR_STR2
5525 "Advertise capability to the peer\n"
5526 "Advertise ORF capability to the peer\n"
5527 "Advertise prefixlist ORF capability to this neighbor\n"
5528 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5529 "Capability to RECEIVE the ORF from this neighbor\n"
5530 "Capability to SEND the ORF to this neighbor\n")
5531{
d62a17ae 5532 int idx_send_recv = 6;
db45f64d
DS
5533 char *peer_str = argv[2]->arg;
5534 struct peer *peer;
5535 afi_t afi = bgp_node_afi(vty);
5536 safi_t safi = bgp_node_safi(vty);
d62a17ae 5537
db45f64d
DS
5538 peer = peer_and_group_lookup_vty(vty, peer_str);
5539 if (!peer)
d62a17ae 5540 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5541
db45f64d
DS
5542 if (strmatch(argv[idx_send_recv]->text, "send"))
5543 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5544 PEER_FLAG_ORF_PREFIX_SM);
5545
5546 if (strmatch(argv[idx_send_recv]->text, "receive"))
5547 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5548 PEER_FLAG_ORF_PREFIX_RM);
5549
5550 if (strmatch(argv[idx_send_recv]->text, "both"))
5551 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5552 PEER_FLAG_ORF_PREFIX_SM)
5553 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5554 PEER_FLAG_ORF_PREFIX_RM);
5555
5556 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5557}
5558
5559ALIAS_HIDDEN(
5560 no_neighbor_capability_orf_prefix,
5561 no_neighbor_capability_orf_prefix_hidden_cmd,
5562 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5563 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5564 "Advertise capability to the peer\n"
5565 "Advertise ORF capability to the peer\n"
5566 "Advertise prefixlist ORF capability to this neighbor\n"
5567 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5568 "Capability to RECEIVE the ORF from this neighbor\n"
5569 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5570
718e3744 5571/* neighbor next-hop-self. */
f4b8ec07
CS
5572DEFUN_YANG (neighbor_nexthop_self,
5573 neighbor_nexthop_self_cmd,
5574 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5575 NEIGHBOR_STR
5576 NEIGHBOR_ADDR_STR2
5577 "Disable the next hop calculation for this neighbor\n")
718e3744 5578{
d62a17ae 5579 int idx_peer = 1;
f4b8ec07
CS
5580 char base_xpath[XPATH_MAXLEN];
5581 char af_xpath[XPATH_MAXLEN];
5582 char attr_xpath[XPATH_MAXLEN];
5583 afi_t afi = bgp_node_afi(vty);
5584 safi_t safi = bgp_node_safi(vty);
5585
f4b8ec07
CS
5586 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5587 yang_afi_safi_value2identity(afi, safi));
5588
5589 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5590 sizeof(base_xpath), af_xpath)
5591 < 0)
5592 return CMD_WARNING_CONFIG_FAILED;
5593
5594 snprintf(attr_xpath, sizeof(attr_xpath),
5595 "./%s/nexthop-self/next-hop-self",
5596 bgp_afi_safi_get_container_str(afi, safi));
5597
5598 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5599
5600 return nb_cli_apply_changes(vty, base_xpath);
a538debe 5601}
9e7a53c1 5602
d62a17ae 5603ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5604 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5605 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5606 "Disable the next hop calculation for this neighbor\n")
596c17ba 5607
f4b8ec07
CS
5608/* neighbor next-hop-self. */
5609DEFUN_YANG(neighbor_nexthop_self_force,
5610 neighbor_nexthop_self_force_cmd,
5611 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5612 NEIGHBOR_STR
5613 NEIGHBOR_ADDR_STR2
5614 "Disable the next hop calculation for this neighbor\n"
5615 "Set the next hop to self for reflected routes\n")
5616{
5617 int idx_peer = 1;
5618 char base_xpath[XPATH_MAXLEN];
5619 char af_xpath[XPATH_MAXLEN];
5620 char attr_xpath[XPATH_MAXLEN];
5621 afi_t afi = bgp_node_afi(vty);
5622 safi_t safi = bgp_node_safi(vty);
5623
f4b8ec07
CS
5624 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5625 yang_afi_safi_value2identity(afi, safi));
5626
5627 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5628 sizeof(base_xpath), af_xpath)
5629 < 0)
5630 return CMD_WARNING_CONFIG_FAILED;
5631
5632 snprintf(attr_xpath, sizeof(attr_xpath),
5633 "./%s/nexthop-self/next-hop-self-force",
5634 bgp_afi_safi_get_container_str(afi, safi));
5635
5636 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5637
5638 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5639}
5640
d62a17ae 5641ALIAS_HIDDEN(neighbor_nexthop_self_force,
5642 neighbor_nexthop_self_force_hidden_cmd,
5643 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5644 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5645 "Disable the next hop calculation for this neighbor\n"
5646 "Set the next hop to self for reflected routes\n")
596c17ba 5647
1bc4e531
DA
5648ALIAS_HIDDEN(neighbor_nexthop_self_force,
5649 neighbor_nexthop_self_all_hidden_cmd,
5650 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5651 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5652 "Disable the next hop calculation for this neighbor\n"
5653 "Set the next hop to self for reflected routes\n")
5654
f4b8ec07
CS
5655DEFUN_YANG (no_neighbor_nexthop_self,
5656 no_neighbor_nexthop_self_cmd,
5657 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5658 NO_STR
5659 NEIGHBOR_STR
5660 NEIGHBOR_ADDR_STR2
5661 "Disable the next hop calculation for this neighbor\n")
718e3744 5662{
d62a17ae 5663 int idx_peer = 2;
f4b8ec07
CS
5664 char base_xpath[XPATH_MAXLEN];
5665 char af_xpath[XPATH_MAXLEN];
5666 char attr_xpath[XPATH_MAXLEN];
5667 afi_t afi = bgp_node_afi(vty);
5668 safi_t safi = bgp_node_safi(vty);
5669
5670 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5671 yang_afi_safi_value2identity(afi, safi));
5672
5673 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5674 sizeof(base_xpath), af_xpath)
5675 < 0)
5676 return CMD_WARNING_CONFIG_FAILED;
5677
5678 snprintf(attr_xpath, sizeof(attr_xpath),
5679 "./%s/nexthop-self/next-hop-self",
5680 bgp_afi_safi_get_container_str(afi, safi));
5681
5682 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5683
5684 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5685}
6b0655a2 5686
d62a17ae 5687ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5688 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5689 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5690 "Disable the next hop calculation for this neighbor\n")
596c17ba 5691
f4b8ec07
CS
5692DEFUN_YANG (no_neighbor_nexthop_self_force,
5693 no_neighbor_nexthop_self_force_cmd,
5694 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5695 NO_STR
5696 NEIGHBOR_STR
5697 NEIGHBOR_ADDR_STR2
5698 "Disable the next hop calculation for this neighbor\n"
5699 "Set the next hop to self for reflected routes\n")
88b8ed8d 5700{
d62a17ae 5701 int idx_peer = 2;
f4b8ec07
CS
5702 char base_xpath[XPATH_MAXLEN];
5703 char af_xpath[XPATH_MAXLEN];
5704 char attr_xpath[XPATH_MAXLEN];
5705 afi_t afi = bgp_node_afi(vty);
5706 safi_t safi = bgp_node_safi(vty);
5707
f4b8ec07
CS
5708 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5709 yang_afi_safi_value2identity(afi, safi));
5710
5711 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5712 sizeof(base_xpath), af_xpath)
5713 < 0)
5714 return CMD_WARNING_CONFIG_FAILED;
5715
5716 snprintf(attr_xpath, sizeof(attr_xpath),
5717 "./%s/nexthop-self/next-hop-self-force",
5718 bgp_afi_safi_get_container_str(afi, safi));
5719
5720 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5721
5722 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5723}
a538debe 5724
d62a17ae 5725ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5726 no_neighbor_nexthop_self_force_hidden_cmd,
5727 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5728 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5729 "Disable the next hop calculation for this neighbor\n"
5730 "Set the next hop to self for reflected routes\n")
596c17ba 5731
1bc4e531
DA
5732ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5733 no_neighbor_nexthop_self_all_hidden_cmd,
5734 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5735 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Disable the next hop calculation for this neighbor\n"
5737 "Set the next hop to self for reflected routes\n")
5738
c7122e14 5739/* neighbor as-override */
f4b8ec07
CS
5740DEFUN_YANG (neighbor_as_override,
5741 neighbor_as_override_cmd,
5742 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5743 NEIGHBOR_STR
5744 NEIGHBOR_ADDR_STR2
5745 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5746{
d62a17ae 5747 int idx_peer = 1;
f4b8ec07
CS
5748 char base_xpath[XPATH_MAXLEN];
5749 char af_xpath[XPATH_MAXLEN];
5750 char attr_xpath[XPATH_MAXLEN];
5751 afi_t afi = bgp_node_afi(vty);
5752 safi_t safi = bgp_node_safi(vty);
5753
5754 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5755 yang_afi_safi_value2identity(afi, safi));
5756
5757 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5758 sizeof(base_xpath), af_xpath)
5759 < 0)
5760 return CMD_WARNING_CONFIG_FAILED;
5761
5762 snprintf(attr_xpath, sizeof(attr_xpath),
5763 "./%s/as-path-options/replace-peer-as",
5764 bgp_afi_safi_get_container_str(afi, safi));
5765
5766 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5767
5768 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5769}
5770
d62a17ae 5771ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5772 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5773 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5774 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5775
f4b8ec07
CS
5776DEFUN_YANG (no_neighbor_as_override,
5777 no_neighbor_as_override_cmd,
5778 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5779 NO_STR
5780 NEIGHBOR_STR
5781 NEIGHBOR_ADDR_STR2
5782 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5783{
d62a17ae 5784 int idx_peer = 2;
f4b8ec07
CS
5785 char base_xpath[XPATH_MAXLEN];
5786 char af_xpath[XPATH_MAXLEN];
5787 char attr_xpath[XPATH_MAXLEN];
5788 afi_t afi = bgp_node_afi(vty);
5789 safi_t safi = bgp_node_safi(vty);
5790
5791 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5792 yang_afi_safi_value2identity(afi, safi));
5793
5794 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5795 sizeof(base_xpath), af_xpath)
5796 < 0)
5797 return CMD_WARNING_CONFIG_FAILED;
5798
5799 snprintf(attr_xpath, sizeof(attr_xpath),
5800 "./%s/as-path-options/replace-peer-as",
5801 bgp_afi_safi_get_container_str(afi, safi));
5802
5803 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5804
5805 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5806}
5807
d62a17ae 5808ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5809 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5810 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5811 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5812
718e3744 5813/* neighbor remove-private-AS. */
f4b8ec07
CS
5814DEFUN_YANG (neighbor_remove_private_as,
5815 neighbor_remove_private_as_cmd,
5816 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5817 NEIGHBOR_STR
5818 NEIGHBOR_ADDR_STR2
5819 "Remove private ASNs in outbound updates\n")
718e3744 5820{
d62a17ae 5821 int idx_peer = 1;
f4b8ec07
CS
5822 char base_xpath[XPATH_MAXLEN];
5823 char af_xpath[XPATH_MAXLEN];
5824 char attr_xpath[XPATH_MAXLEN];
5825 afi_t afi = bgp_node_afi(vty);
5826 safi_t safi = bgp_node_safi(vty);
5827
5828 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5829 yang_afi_safi_value2identity(afi, safi));
5830
5831 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5832 sizeof(base_xpath), af_xpath)
5833 < 0)
5834 return CMD_WARNING_CONFIG_FAILED;
5835
5836 snprintf(attr_xpath, sizeof(attr_xpath),
5837 "./%s/private-as/remove-private-as",
5838 bgp_afi_safi_get_container_str(afi, safi));
5839
5840 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5841
5842 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5843}
5844
d62a17ae 5845ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5846 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5847 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5848 "Remove private ASNs in outbound updates\n")
596c17ba 5849
f4b8ec07
CS
5850DEFUN_YANG (neighbor_remove_private_as_all,
5851 neighbor_remove_private_as_all_cmd,
5852 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5853 NEIGHBOR_STR
5854 NEIGHBOR_ADDR_STR2
5855 "Remove private ASNs in outbound updates\n"
5856 "Apply to all AS numbers\n")
5000f21c 5857{
d62a17ae 5858 int idx_peer = 1;
f4b8ec07
CS
5859 char base_xpath[XPATH_MAXLEN];
5860 char af_xpath[XPATH_MAXLEN];
5861 char attr_xpath[XPATH_MAXLEN];
5862 afi_t afi = bgp_node_afi(vty);
5863 safi_t safi = bgp_node_safi(vty);
5864
f4b8ec07
CS
5865 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5866 yang_afi_safi_value2identity(afi, safi));
5867
5868 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5869 sizeof(base_xpath), af_xpath)
5870 < 0)
5871 return CMD_WARNING_CONFIG_FAILED;
5872
5873 snprintf(attr_xpath, sizeof(attr_xpath),
5874 "./%s/private-as/remove-private-as-all",
5875 bgp_afi_safi_get_container_str(afi, safi));
5876
5877 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5878
5879 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5880}
5881
d62a17ae 5882ALIAS_HIDDEN(neighbor_remove_private_as_all,
5883 neighbor_remove_private_as_all_hidden_cmd,
5884 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5885 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5886 "Remove private ASNs in outbound updates\n"
5887 "Apply to all AS numbers")
596c17ba 5888
f4b8ec07
CS
5889DEFUN_YANG (neighbor_remove_private_as_replace_as,
5890 neighbor_remove_private_as_replace_as_cmd,
5891 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5892 NEIGHBOR_STR
5893 NEIGHBOR_ADDR_STR2
5894 "Remove private ASNs in outbound updates\n"
5895 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5896{
d62a17ae 5897 int idx_peer = 1;
f4b8ec07
CS
5898 char base_xpath[XPATH_MAXLEN];
5899 char af_xpath[XPATH_MAXLEN];
5900 char attr_xpath[XPATH_MAXLEN];
5901 afi_t afi = bgp_node_afi(vty);
5902 safi_t safi = bgp_node_safi(vty);
5903
f4b8ec07
CS
5904 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5905 yang_afi_safi_value2identity(afi, safi));
5906
5907 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5908 sizeof(base_xpath), af_xpath)
5909 < 0)
5910 return CMD_WARNING_CONFIG_FAILED;
5911
5912 snprintf(attr_xpath, sizeof(attr_xpath),
5913 "./%s/private-as/remove-private-as-replace",
5914 bgp_afi_safi_get_container_str(afi, safi));
5915
5916 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5917
5918 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5919}
5920
d62a17ae 5921ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5922 neighbor_remove_private_as_replace_as_hidden_cmd,
5923 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5925 "Remove private ASNs in outbound updates\n"
5926 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5927
f4b8ec07
CS
5928DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5929 neighbor_remove_private_as_all_replace_as_cmd,
5930 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5931 NEIGHBOR_STR
5932 NEIGHBOR_ADDR_STR2
5933 "Remove private ASNs in outbound updates\n"
5934 "Apply to all AS numbers\n"
5935 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5936{
d62a17ae 5937 int idx_peer = 1;
f4b8ec07
CS
5938 char base_xpath[XPATH_MAXLEN];
5939 char af_xpath[XPATH_MAXLEN];
5940 char attr_xpath[XPATH_MAXLEN];
5941 afi_t afi = bgp_node_afi(vty);
5942 safi_t safi = bgp_node_safi(vty);
5943
f4b8ec07
CS
5944 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5945 yang_afi_safi_value2identity(afi, safi));
5946
5947 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5948 sizeof(base_xpath), af_xpath)
5949 < 0)
5950 return CMD_WARNING_CONFIG_FAILED;
5951
5952 snprintf(attr_xpath, sizeof(attr_xpath),
5953 "./%s/private-as/remove-private-as-all-replace",
5954 bgp_afi_safi_get_container_str(afi, safi));
5955
5956 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5957
5958 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5959}
5960
d62a17ae 5961ALIAS_HIDDEN(
5962 neighbor_remove_private_as_all_replace_as,
5963 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5964 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5966 "Remove private ASNs in outbound updates\n"
5967 "Apply to all AS numbers\n"
5968 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5969
f4b8ec07
CS
5970DEFUN_YANG (no_neighbor_remove_private_as,
5971 no_neighbor_remove_private_as_cmd,
5972 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5973 NO_STR
5974 NEIGHBOR_STR
5975 NEIGHBOR_ADDR_STR2
5976 "Remove private ASNs in outbound updates\n")
718e3744 5977{
d62a17ae 5978 int idx_peer = 2;
f4b8ec07
CS
5979 char base_xpath[XPATH_MAXLEN];
5980 char af_xpath[XPATH_MAXLEN];
5981 char attr_xpath[XPATH_MAXLEN];
5982 afi_t afi = bgp_node_afi(vty);
5983 safi_t safi = bgp_node_safi(vty);
5984
5985 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5986 yang_afi_safi_value2identity(afi, safi));
5987
5988 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5989 sizeof(base_xpath), af_xpath)
5990 < 0)
5991 return CMD_WARNING_CONFIG_FAILED;
5992
5993 snprintf(attr_xpath, sizeof(attr_xpath),
5994 "./%s/private-as/remove-private-as",
5995 bgp_afi_safi_get_container_str(afi, safi));
5996
5997 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5998
5999 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6000}
6b0655a2 6001
d62a17ae 6002ALIAS_HIDDEN(no_neighbor_remove_private_as,
6003 no_neighbor_remove_private_as_hidden_cmd,
6004 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6005 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6006 "Remove private ASNs in outbound updates\n")
596c17ba 6007
f4b8ec07
CS
6008DEFUN_YANG (no_neighbor_remove_private_as_all,
6009 no_neighbor_remove_private_as_all_cmd,
6010 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6011 NO_STR
6012 NEIGHBOR_STR
6013 NEIGHBOR_ADDR_STR2
6014 "Remove private ASNs in outbound updates\n"
6015 "Apply to all AS numbers\n")
88b8ed8d 6016{
d62a17ae 6017 int idx_peer = 2;
f4b8ec07
CS
6018 char base_xpath[XPATH_MAXLEN];
6019 char af_xpath[XPATH_MAXLEN];
6020 char attr_xpath[XPATH_MAXLEN];
6021 afi_t afi = bgp_node_afi(vty);
6022 safi_t safi = bgp_node_safi(vty);
6023
f4b8ec07
CS
6024 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6025 yang_afi_safi_value2identity(afi, safi));
6026
6027 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6028 sizeof(base_xpath), af_xpath)
6029 < 0)
6030 return CMD_WARNING_CONFIG_FAILED;
6031
6032 snprintf(attr_xpath, sizeof(attr_xpath),
6033 "./%s/private-as/remove-private-as-all",
6034 bgp_afi_safi_get_container_str(afi, safi));
6035
6036 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6037
6038 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6039}
5000f21c 6040
d62a17ae 6041ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6042 no_neighbor_remove_private_as_all_hidden_cmd,
6043 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6044 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6045 "Remove private ASNs in outbound updates\n"
6046 "Apply to all AS numbers\n")
596c17ba 6047
f4b8ec07
CS
6048DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6049 no_neighbor_remove_private_as_replace_as_cmd,
6050 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6051 NO_STR
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "Remove private ASNs in outbound updates\n"
6055 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6056{
d62a17ae 6057 int idx_peer = 2;
f4b8ec07
CS
6058 char base_xpath[XPATH_MAXLEN];
6059 char af_xpath[XPATH_MAXLEN];
6060 char attr_xpath[XPATH_MAXLEN];
6061 afi_t afi = bgp_node_afi(vty);
6062 safi_t safi = bgp_node_safi(vty);
6063
f4b8ec07
CS
6064 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6065 yang_afi_safi_value2identity(afi, safi));
6066
6067 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6068 sizeof(base_xpath), af_xpath)
6069 < 0)
6070 return CMD_WARNING_CONFIG_FAILED;
6071
6072 snprintf(attr_xpath, sizeof(attr_xpath),
6073 "./%s/private-as/remove-private-as-replace",
6074 bgp_afi_safi_get_container_str(afi, safi));
6075
6076 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6077
6078 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6079}
5000f21c 6080
d62a17ae 6081ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6082 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6083 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6084 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6085 "Remove private ASNs in outbound updates\n"
6086 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6087
f4b8ec07
CS
6088DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6089 no_neighbor_remove_private_as_all_replace_as_cmd,
6090 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6091 NO_STR
6092 NEIGHBOR_STR
6093 NEIGHBOR_ADDR_STR2
6094 "Remove private ASNs in outbound updates\n"
6095 "Apply to all AS numbers\n"
6096 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6097{
d62a17ae 6098 int idx_peer = 2;
f4b8ec07
CS
6099 char base_xpath[XPATH_MAXLEN];
6100 char af_xpath[XPATH_MAXLEN];
6101 char attr_xpath[XPATH_MAXLEN];
6102 afi_t afi = bgp_node_afi(vty);
6103 safi_t safi = bgp_node_safi(vty);
6104
f4b8ec07
CS
6105 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6106 yang_afi_safi_value2identity(afi, safi));
6107
6108 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6109 sizeof(base_xpath), af_xpath)
6110 < 0)
6111 return CMD_WARNING_CONFIG_FAILED;
6112
6113 snprintf(attr_xpath, sizeof(attr_xpath),
6114 "./%s/private-as/remove-private-as-all-replace",
6115 bgp_afi_safi_get_container_str(afi, safi));
6116
6117 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6118
6119 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6120}
5000f21c 6121
d62a17ae 6122ALIAS_HIDDEN(
6123 no_neighbor_remove_private_as_all_replace_as,
6124 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6125 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6126 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6127 "Remove private ASNs in outbound updates\n"
6128 "Apply to all AS numbers\n"
6129 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6130
5000f21c 6131
718e3744 6132/* neighbor send-community. */
f4b8ec07
CS
6133DEFUN_YANG (neighbor_send_community,
6134 neighbor_send_community_cmd,
6135 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6136 NEIGHBOR_STR
6137 NEIGHBOR_ADDR_STR2
6138 "Send Community attribute to this neighbor\n")
718e3744 6139{
d62a17ae 6140 int idx_peer = 1;
27c05d4d 6141
d62a17ae 6142 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6143 bgp_node_safi(vty),
6144 PEER_FLAG_SEND_COMMUNITY);
718e3744 6145}
6146
d62a17ae 6147ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6148 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6150 "Send Community attribute to this neighbor\n")
596c17ba 6151
f4b8ec07
CS
6152DEFUN_YANG (no_neighbor_send_community,
6153 no_neighbor_send_community_cmd,
6154 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6155 NO_STR
6156 NEIGHBOR_STR
6157 NEIGHBOR_ADDR_STR2
6158 "Send Community attribute to this neighbor\n")
718e3744 6159{
d62a17ae 6160 int idx_peer = 2;
27c05d4d 6161
d62a17ae 6162 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6163 bgp_node_afi(vty), bgp_node_safi(vty),
6164 PEER_FLAG_SEND_COMMUNITY);
718e3744 6165}
6b0655a2 6166
d62a17ae 6167ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6168 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6169 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6170 "Send Community attribute to this neighbor\n")
596c17ba 6171
718e3744 6172/* neighbor send-community extended. */
f4b8ec07
CS
6173DEFUN_YANG (neighbor_send_community_type,
6174 neighbor_send_community_type_cmd,
6175 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6176 NEIGHBOR_STR
6177 NEIGHBOR_ADDR_STR2
6178 "Send Community attribute to this neighbor\n"
6179 "Send Standard and Extended Community attributes\n"
6180 "Send Standard, Large and Extended Community attributes\n"
6181 "Send Extended Community attributes\n"
6182 "Send Standard Community attributes\n"
6183 "Send Large Community attributes\n")
718e3744 6184{
27c05d4d 6185 const char *type = argv[argc - 1]->text;
db45f64d 6186 char *peer_str = argv[1]->arg;
f4b8ec07
CS
6187 char base_xpath[XPATH_MAXLEN];
6188 char af_xpath[XPATH_MAXLEN];
6189 char std_xpath[XPATH_MAXLEN];
6190 char ext_xpath[XPATH_MAXLEN];
6191 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6192 afi_t afi = bgp_node_afi(vty);
6193 safi_t safi = bgp_node_safi(vty);
d62a17ae 6194
f4b8ec07
CS
6195 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6196 yang_afi_safi_value2identity(afi, safi));
6197
6198 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6199 sizeof(base_xpath), af_xpath)
6200 < 0)
db45f64d 6201 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6202
f4b8ec07
CS
6203 if (strmatch(type, "standard")) {
6204 snprintf(std_xpath, sizeof(std_xpath),
6205 "./%s/send-community/send-community",
6206 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6207
f4b8ec07
CS
6208 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6209 }
db45f64d 6210
f4b8ec07
CS
6211 if (strmatch(type, "extended")) {
6212 snprintf(ext_xpath, sizeof(ext_xpath),
6213 "./%s/send-community/send-ext-community",
6214 bgp_afi_safi_get_container_str(afi, safi));
6215
6216 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6217 }
6218
6219 if (strmatch(type, "large")) {
6220 snprintf(lrg_xpath, sizeof(lrg_xpath),
6221 "./%s/send-community/send-large-community",
6222 bgp_afi_safi_get_container_str(afi, safi));
6223
6224 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6225 }
db45f64d
DS
6226
6227 if (strmatch(type, "both")) {
f4b8ec07
CS
6228 snprintf(std_xpath, sizeof(std_xpath),
6229 "./%s/send-community/send-community",
6230 bgp_afi_safi_get_container_str(afi, safi));
6231
6232 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6233
6234 snprintf(ext_xpath, sizeof(ext_xpath),
6235 "./%s/send-community/send-ext-community",
6236 bgp_afi_safi_get_container_str(afi, safi));
6237
6238 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
db45f64d 6239 }
f4b8ec07
CS
6240
6241 if (strmatch(type, "all")) {
6242 snprintf(std_xpath, sizeof(std_xpath),
6243 "./%s/send-community/send-community",
6244 bgp_afi_safi_get_container_str(afi, safi));
6245
6246 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6247
6248 snprintf(ext_xpath, sizeof(ext_xpath),
6249 "./%s/send-community/send-ext-community",
6250 bgp_afi_safi_get_container_str(afi, safi));
6251
6252 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6253
6254 snprintf(lrg_xpath, sizeof(lrg_xpath),
6255 "./%s/send-community/send-large-community",
6256 bgp_afi_safi_get_container_str(afi, safi));
6257
6258 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6259 }
6260
6261 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6262}
6263
6264ALIAS_HIDDEN(
6265 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6266 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6267 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6268 "Send Community attribute to this neighbor\n"
6269 "Send Standard and Extended Community attributes\n"
6270 "Send Standard, Large and Extended Community attributes\n"
6271 "Send Extended Community attributes\n"
6272 "Send Standard Community attributes\n"
6273 "Send Large Community attributes\n")
596c17ba 6274
f4b8ec07
CS
6275DEFUN_YANG (no_neighbor_send_community_type,
6276 no_neighbor_send_community_type_cmd,
6277 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6278 NO_STR
6279 NEIGHBOR_STR
6280 NEIGHBOR_ADDR_STR2
6281 "Send Community attribute to this neighbor\n"
6282 "Send Standard and Extended Community attributes\n"
6283 "Send Standard, Large and Extended Community attributes\n"
6284 "Send Extended Community attributes\n"
6285 "Send Standard Community attributes\n"
6286 "Send Large Community attributes\n")
718e3744 6287{
d62a17ae 6288 const char *type = argv[argc - 1]->text;
db45f64d 6289 char *peer_str = argv[2]->arg;
f4b8ec07
CS
6290 char base_xpath[XPATH_MAXLEN];
6291 char af_xpath[XPATH_MAXLEN];
6292 char std_xpath[XPATH_MAXLEN];
6293 char ext_xpath[XPATH_MAXLEN];
6294 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6295 afi_t afi = bgp_node_afi(vty);
6296 safi_t safi = bgp_node_safi(vty);
6297
f4b8ec07
CS
6298 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6299 yang_afi_safi_value2identity(afi, safi));
6300
6301 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6302 sizeof(base_xpath), af_xpath)
6303 < 0)
6304 return CMD_WARNING_CONFIG_FAILED;
6305
6306 if (strmatch(type, "standard")) {
6307 snprintf(std_xpath, sizeof(std_xpath),
6308 "./%s/send-community/send-community",
6309 bgp_afi_safi_get_container_str(afi, safi));
6310
6311 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6312 }
6313
6314 if (strmatch(type, "extended")) {
6315 snprintf(ext_xpath, sizeof(ext_xpath),
6316 "./%s/send-community/send-ext-community",
6317 bgp_afi_safi_get_container_str(afi, safi));
6318
6319 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6320 }
6321
6322 if (strmatch(type, "large")) {
6323 snprintf(lrg_xpath, sizeof(lrg_xpath),
6324 "./%s/send-community/send-large-community",
6325 bgp_afi_safi_get_container_str(afi, safi));
6326
6327 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6328 }
6329
6330 if (strmatch(type, "both")) {
6331 snprintf(std_xpath, sizeof(std_xpath),
6332 "./%s/send-community/send-community",
6333 bgp_afi_safi_get_container_str(afi, safi));
6334
6335 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6336
6337 snprintf(ext_xpath, sizeof(ext_xpath),
6338 "./%s/send-community/send-ext-community",
6339 bgp_afi_safi_get_container_str(afi, safi));
6340
6341 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6342 }
6343
6344 if (strmatch(type, "all")) {
6345 snprintf(std_xpath, sizeof(std_xpath),
6346 "./%s/send-community/send-community",
6347 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6348
f4b8ec07 6349 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
db45f64d 6350
f4b8ec07
CS
6351 snprintf(ext_xpath, sizeof(ext_xpath),
6352 "./%s/send-community/send-ext-community",
6353 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6354
f4b8ec07 6355 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
db45f64d 6356
f4b8ec07
CS
6357 snprintf(lrg_xpath, sizeof(lrg_xpath),
6358 "./%s/send-community/send-large-community",
6359 bgp_afi_safi_get_container_str(afi, safi));
d62a17ae 6360
f4b8ec07 6361 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
27c05d4d
PM
6362 }
6363
f4b8ec07 6364 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6365}
6366
6367ALIAS_HIDDEN(
6368 no_neighbor_send_community_type,
6369 no_neighbor_send_community_type_hidden_cmd,
6370 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6371 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6372 "Send Community attribute to this neighbor\n"
6373 "Send Standard and Extended Community attributes\n"
6374 "Send Standard, Large and Extended Community attributes\n"
6375 "Send Extended Community attributes\n"
6376 "Send Standard Community attributes\n"
6377 "Send Large Community attributes\n")
596c17ba 6378
718e3744 6379/* neighbor soft-reconfig. */
f4b8ec07
CS
6380DEFUN_YANG (neighbor_soft_reconfiguration,
6381 neighbor_soft_reconfiguration_cmd,
6382 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6383 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6384 "Per neighbor soft reconfiguration\n"
6385 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6386{
d62a17ae 6387 int idx_peer = 1;
f4b8ec07
CS
6388 char base_xpath[XPATH_MAXLEN];
6389 char af_xpath[XPATH_MAXLEN];
6390 char soft_xpath[XPATH_MAXLEN];
6391 afi_t afi = bgp_node_afi(vty);
6392 safi_t safi = bgp_node_safi(vty);
6393
f4b8ec07
CS
6394 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6395 yang_afi_safi_value2identity(afi, safi));
6396
6397 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6398 sizeof(base_xpath), af_xpath)
6399 < 0)
6400 return CMD_WARNING_CONFIG_FAILED;
6401
6402 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6403 bgp_afi_safi_get_container_str(afi, safi));
6404
6405 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6406
6407 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6408}
6409
d62a17ae 6410ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6411 neighbor_soft_reconfiguration_hidden_cmd,
6412 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6413 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6414 "Per neighbor soft reconfiguration\n"
6415 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6416
f4b8ec07
CS
6417DEFUN_YANG (no_neighbor_soft_reconfiguration,
6418 no_neighbor_soft_reconfiguration_cmd,
6419 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6420 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6421 "Per neighbor soft reconfiguration\n"
6422 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6423{
d62a17ae 6424 int idx_peer = 2;
f4b8ec07
CS
6425 char base_xpath[XPATH_MAXLEN];
6426 char af_xpath[XPATH_MAXLEN];
6427 char soft_xpath[XPATH_MAXLEN];
6428 afi_t afi = bgp_node_afi(vty);
6429 safi_t safi = bgp_node_safi(vty);
6430
6431 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6432 yang_afi_safi_value2identity(afi, safi));
6433
6434 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6435 bgp_afi_safi_get_container_str(afi, safi));
6436
6437 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6438 sizeof(base_xpath), af_xpath)
6439 < 0)
6440 return CMD_WARNING_CONFIG_FAILED;
6441
6442 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6443
6444 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6445}
6b0655a2 6446
d62a17ae 6447ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6448 no_neighbor_soft_reconfiguration_hidden_cmd,
6449 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6450 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6451 "Per neighbor soft reconfiguration\n"
6452 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6453
f4b8ec07
CS
6454DEFUN_YANG (neighbor_route_reflector_client,
6455 neighbor_route_reflector_client_cmd,
6456 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6457 NEIGHBOR_STR
6458 NEIGHBOR_ADDR_STR2
6459 "Configure a neighbor as Route Reflector client\n")
718e3744 6460{
d62a17ae 6461 int idx_peer = 1;
f4b8ec07
CS
6462 char base_xpath[XPATH_MAXLEN];
6463 char af_xpath[XPATH_MAXLEN];
6464 char attr_xpath[XPATH_MAXLEN];
6465 afi_t afi = bgp_node_afi(vty);
6466 safi_t safi = bgp_node_safi(vty);
718e3744 6467
f4b8ec07
CS
6468 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6469 yang_afi_safi_value2identity(afi, safi));
718e3744 6470
f4b8ec07
CS
6471 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6472 sizeof(base_xpath), af_xpath)
6473 < 0)
d62a17ae 6474 return CMD_WARNING_CONFIG_FAILED;
718e3744 6475
f4b8ec07
CS
6476 snprintf(attr_xpath, sizeof(attr_xpath),
6477 "./%s/route-reflector/route-reflector-client",
6478 bgp_afi_safi_get_container_str(afi, safi));
6479
6480 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6481
6482 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6483}
6484
d62a17ae 6485ALIAS_HIDDEN(neighbor_route_reflector_client,
6486 neighbor_route_reflector_client_hidden_cmd,
6487 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6488 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6489 "Configure a neighbor as Route Reflector client\n")
596c17ba 6490
f4b8ec07
CS
6491DEFUN_YANG (no_neighbor_route_reflector_client,
6492 no_neighbor_route_reflector_client_cmd,
6493 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6494 NO_STR
6495 NEIGHBOR_STR
6496 NEIGHBOR_ADDR_STR2
6497 "Configure a neighbor as Route Reflector client\n")
718e3744 6498{
d62a17ae 6499 int idx_peer = 2;
f4b8ec07
CS
6500 char base_xpath[XPATH_MAXLEN];
6501 char af_xpath[XPATH_MAXLEN];
6502 char attr_xpath[XPATH_MAXLEN];
6503 afi_t afi = bgp_node_afi(vty);
6504 safi_t safi = bgp_node_safi(vty);
6505
6506 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6507 yang_afi_safi_value2identity(afi, safi));
6508
6509 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6510 sizeof(base_xpath), af_xpath)
6511 < 0)
6512 return CMD_WARNING_CONFIG_FAILED;
6513
6514 snprintf(attr_xpath, sizeof(attr_xpath),
6515 "./%s/route-reflector/route-reflector-client",
6516 bgp_afi_safi_get_container_str(afi, safi));
6517
6518 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6519
6520 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6521}
6b0655a2 6522
d62a17ae 6523ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6524 no_neighbor_route_reflector_client_hidden_cmd,
6525 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6526 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6527 "Configure a neighbor as Route Reflector client\n")
596c17ba 6528
718e3744 6529/* neighbor route-server-client. */
f4b8ec07
CS
6530DEFUN_YANG (neighbor_route_server_client,
6531 neighbor_route_server_client_cmd,
6532 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6533 NEIGHBOR_STR
6534 NEIGHBOR_ADDR_STR2
6535 "Configure a neighbor as Route Server client\n")
718e3744 6536{
d62a17ae 6537 int idx_peer = 1;
f4b8ec07
CS
6538 char base_xpath[XPATH_MAXLEN];
6539 char af_xpath[XPATH_MAXLEN];
6540 char attr_xpath[XPATH_MAXLEN];
6541 afi_t afi = bgp_node_afi(vty);
6542 safi_t safi = bgp_node_safi(vty);
2a3d5731 6543
f4b8ec07
CS
6544 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6545 yang_afi_safi_value2identity(afi, safi));
6546
6547 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6548 sizeof(base_xpath), af_xpath)
6549 < 0)
d62a17ae 6550 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07
CS
6551
6552 snprintf(attr_xpath, sizeof(attr_xpath),
6553 "./%s/route-server/route-server-client",
6554 bgp_afi_safi_get_container_str(afi, safi));
6555
6556 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6557
6558 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6559}
6560
d62a17ae 6561ALIAS_HIDDEN(neighbor_route_server_client,
6562 neighbor_route_server_client_hidden_cmd,
6563 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6564 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6565 "Configure a neighbor as Route Server client\n")
596c17ba 6566
f4b8ec07
CS
6567DEFUN_YANG (no_neighbor_route_server_client,
6568 no_neighbor_route_server_client_cmd,
6569 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6570 NO_STR
6571 NEIGHBOR_STR
6572 NEIGHBOR_ADDR_STR2
6573 "Configure a neighbor as Route Server client\n")
fee0f4c6 6574{
d62a17ae 6575 int idx_peer = 2;
f4b8ec07
CS
6576 char base_xpath[XPATH_MAXLEN];
6577 char af_xpath[XPATH_MAXLEN];
6578 char attr_xpath[XPATH_MAXLEN];
6579 afi_t afi = bgp_node_afi(vty);
6580 safi_t safi = bgp_node_safi(vty);
6581
6582 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6583 yang_afi_safi_value2identity(afi, safi));
6584
6585 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6586 sizeof(base_xpath), af_xpath)
6587 < 0)
6588 return CMD_WARNING_CONFIG_FAILED;
6589
6590 snprintf(attr_xpath, sizeof(attr_xpath),
6591 "./%s/route-server/route-server-client",
6592 bgp_afi_safi_get_container_str(afi, safi));
6593
6594 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6595
6596 return nb_cli_apply_changes(vty, base_xpath);
fee0f4c6 6597}
6b0655a2 6598
d62a17ae 6599ALIAS_HIDDEN(no_neighbor_route_server_client,
6600 no_neighbor_route_server_client_hidden_cmd,
6601 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6602 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6603 "Configure a neighbor as Route Server client\n")
596c17ba 6604
fee0f4c6 6605DEFUN (neighbor_nexthop_local_unchanged,
6606 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6607 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6608 NEIGHBOR_STR
6609 NEIGHBOR_ADDR_STR2
6610 "Configure treatment of outgoing link-local nexthop attribute\n"
6611 "Leave link-local nexthop unchanged for this peer\n")
6612{
d62a17ae 6613 int idx_peer = 1;
6614 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6615 bgp_node_safi(vty),
6616 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6617}
6b0655a2 6618
fee0f4c6 6619DEFUN (no_neighbor_nexthop_local_unchanged,
6620 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6621 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6622 NO_STR
6623 NEIGHBOR_STR
6624 NEIGHBOR_ADDR_STR2
6625 "Configure treatment of outgoing link-local-nexthop attribute\n"
6626 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6627{
d62a17ae 6628 int idx_peer = 2;
6629 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6630 bgp_node_afi(vty), bgp_node_safi(vty),
6631 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6632}
6b0655a2 6633
f4b8ec07
CS
6634DEFUN_YANG (neighbor_attr_unchanged,
6635 neighbor_attr_unchanged_cmd,
6636 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6637 NEIGHBOR_STR
6638 NEIGHBOR_ADDR_STR2
6639 "BGP attribute is propagated unchanged to this neighbor\n"
6640 "As-path attribute\n"
6641 "Nexthop attribute\n"
6642 "Med attribute\n")
718e3744 6643{
d62a17ae 6644 int idx = 0;
8eeb0335 6645 char *peer_str = argv[1]->arg;
db45f64d
DS
6646 bool aspath = false;
6647 bool nexthop = false;
6648 bool med = false;
8eeb0335
DW
6649 afi_t afi = bgp_node_afi(vty);
6650 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6651 char base_xpath[XPATH_MAXLEN];
6652 char af_xpath[XPATH_MAXLEN];
6653 char as_xpath[XPATH_MAXLEN];
6654 char nxthop_xpath[XPATH_MAXLEN];
6655 char med_xpath[XPATH_MAXLEN];
8eeb0335 6656
f4b8ec07
CS
6657 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6658 yang_afi_safi_value2identity(afi, safi));
6659
6660 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6661 sizeof(base_xpath), af_xpath)
6662 < 0)
8eeb0335 6663 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6664
6665 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6666 aspath = true;
6667
d62a17ae 6668 idx = 0;
6669 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6670 nexthop = true;
6671
d62a17ae 6672 idx = 0;
6673 if (argv_find(argv, argc, "med", &idx))
db45f64d 6674 med = true;
d62a17ae 6675
f4b8ec07
CS
6676 snprintf(as_xpath, sizeof(as_xpath),
6677 "./%s/attr-unchanged/as-path-unchanged",
6678 bgp_afi_safi_get_container_str(afi, safi));
6679 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6680 "./%s/attr-unchanged/next-hop-unchanged",
6681 bgp_afi_safi_get_container_str(afi, safi));
6682 snprintf(med_xpath, sizeof(med_xpath),
6683 "./%s/attr-unchanged/med-unchanged",
6684 bgp_afi_safi_get_container_str(afi, safi));
6685
8eeb0335 6686 /* no flags means all of them! */
db45f64d 6687 if (!aspath && !nexthop && !med) {
f4b8ec07
CS
6688 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6689 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6690 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
8eeb0335 6691 } else {
f4b8ec07
CS
6692 if (!aspath)
6693 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6694 "false");
6695 else
6696 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6697 "true");
6698
6699 if (!nexthop)
6700 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6701 "false");
6702 else
6703 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6704 "true");
6705
6706 if (!med)
6707 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6708 "false");
6709 else
6710 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6711 "true");
d62a17ae 6712 }
6713
f4b8ec07 6714 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6715}
6716
6717ALIAS_HIDDEN(
6718 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6719 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6720 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6721 "BGP attribute is propagated unchanged to this neighbor\n"
6722 "As-path attribute\n"
6723 "Nexthop attribute\n"
6724 "Med attribute\n")
596c17ba 6725
f4b8ec07
CS
6726DEFUN_YANG (no_neighbor_attr_unchanged,
6727 no_neighbor_attr_unchanged_cmd,
6728 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6729 NO_STR
6730 NEIGHBOR_STR
6731 NEIGHBOR_ADDR_STR2
6732 "BGP attribute is propagated unchanged to this neighbor\n"
6733 "As-path attribute\n"
6734 "Nexthop attribute\n"
6735 "Med attribute\n")
718e3744 6736{
d62a17ae 6737 int idx = 0;
db45f64d 6738 char *peer_str = argv[2]->arg;
db45f64d
DS
6739 bool aspath = false;
6740 bool nexthop = false;
6741 bool med = false;
6742 afi_t afi = bgp_node_afi(vty);
6743 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6744 char base_xpath[XPATH_MAXLEN];
6745 char af_xpath[XPATH_MAXLEN];
6746 char as_xpath[XPATH_MAXLEN];
6747 char nxthop_xpath[XPATH_MAXLEN];
6748 char med_xpath[XPATH_MAXLEN];
db45f64d 6749
f4b8ec07
CS
6750 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6751 yang_afi_safi_value2identity(afi, safi));
6752
6753 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6754 sizeof(base_xpath), af_xpath)
6755 < 0)
db45f64d 6756 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6757
6758 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6759 aspath = true;
6760
d62a17ae 6761 idx = 0;
6762 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6763 nexthop = true;
6764
d62a17ae 6765 idx = 0;
6766 if (argv_find(argv, argc, "med", &idx))
db45f64d 6767 med = true;
d62a17ae 6768
f4b8ec07
CS
6769 snprintf(as_xpath, sizeof(as_xpath),
6770 "./%s/attr-unchanged/as-path-unchanged",
6771 bgp_afi_safi_get_container_str(afi, safi));
6772 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6773 "./%s/attr-unchanged/next-hop-unchanged",
6774 bgp_afi_safi_get_container_str(afi, safi));
6775 snprintf(med_xpath, sizeof(med_xpath),
6776 "./%s/attr-unchanged/med-unchanged",
6777 bgp_afi_safi_get_container_str(afi, safi));
6778
6779 /* no flags means all of them! */
6780 if (!aspath && !nexthop && !med) {
6781 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6782 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6783 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6784 }
db45f64d
DS
6785
6786 if (aspath)
f4b8ec07 6787 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
db45f64d
DS
6788
6789 if (nexthop)
f4b8ec07 6790 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
d62a17ae 6791
db45f64d 6792 if (med)
f4b8ec07 6793 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
db45f64d 6794
f4b8ec07 6795 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6796}
6797
6798ALIAS_HIDDEN(
6799 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6800 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6801 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6802 "BGP attribute is propagated unchanged to this neighbor\n"
6803 "As-path attribute\n"
6804 "Nexthop attribute\n"
6805 "Med attribute\n")
718e3744 6806
f4b8ec07
CS
6807/* neighbor ebgp-multihop. */
6808DEFUN_YANG (neighbor_ebgp_multihop,
6809 neighbor_ebgp_multihop_cmd,
6810 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6811 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6812 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6813{
f4b8ec07
CS
6814 int idx_peer = 1;
6815 char base_xpath[XPATH_MAXLEN];
718e3744 6816
f4b8ec07
CS
6817 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6818 sizeof(base_xpath), NULL)
6819 < 0)
d62a17ae 6820 return CMD_WARNING_CONFIG_FAILED;
718e3744 6821
f4b8ec07
CS
6822 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6823 "true");
718e3744 6824
f4b8ec07 6825 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6826}
6827
f4b8ec07
CS
6828DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6829 neighbor_ebgp_multihop_ttl_cmd,
6830 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6831 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6832 "Allow EBGP neighbors not on directly connected networks\n"
6833 "maximum hop count\n")
718e3744 6834{
f4b8ec07
CS
6835 int idx_peer = 1;
6836 int idx_number = 3;
6837 char base_xpath[XPATH_MAXLEN];
718e3744 6838
f4b8ec07
CS
6839 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6840 sizeof(base_xpath), NULL)
6841 < 0)
d62a17ae 6842 return CMD_WARNING_CONFIG_FAILED;
718e3744 6843
f4b8ec07
CS
6844 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6845 argv[idx_number]->arg);
718e3744 6846
f4b8ec07 6847 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6848}
6849
f4b8ec07
CS
6850DEFUN_YANG (no_neighbor_ebgp_multihop,
6851 no_neighbor_ebgp_multihop_cmd,
6852 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6853 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6854 "Allow EBGP neighbors not on directly connected networks\n"
6855 "maximum hop count\n")
718e3744 6856{
d62a17ae 6857 int idx_peer = 2;
f4b8ec07
CS
6858 char base_xpath[XPATH_MAXLEN];
6859
6860 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6861 sizeof(base_xpath), NULL)
6862 < 0)
6863 return CMD_WARNING_CONFIG_FAILED;
6864
6865 if (argc > 4)
6866 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6867 NB_OP_DESTROY, NULL);
6868 else
6869 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6870 NB_OP_MODIFY, "false");
6871
6872 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6873}
6874
6b0655a2 6875
6ffd2079 6876/* disable-connected-check */
f4b8ec07
CS
6877DEFUN_YANG (neighbor_disable_connected_check,
6878 neighbor_disable_connected_check_cmd,
6879 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6880 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6881 "one-hop away EBGP peer using loopback address\n"
6882 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6883{
d62a17ae 6884 int idx_peer = 1;
f4b8ec07
CS
6885 char base_xpath[XPATH_MAXLEN];
6886
6887 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6888 sizeof(base_xpath), NULL)
6889 < 0)
6890 return CMD_WARNING_CONFIG_FAILED;
6891
6892 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6893 NB_OP_MODIFY, "true");
6894
6895 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6896}
6897
f4b8ec07
CS
6898DEFUN_YANG (no_neighbor_disable_connected_check,
6899 no_neighbor_disable_connected_check_cmd,
6900 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6901 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6902 "one-hop away EBGP peer using loopback address\n"
6903 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6904{
d62a17ae 6905 int idx_peer = 2;
f4b8ec07
CS
6906 char base_xpath[XPATH_MAXLEN];
6907
6908 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6909 sizeof(base_xpath), NULL)
6910 < 0)
6911 return CMD_WARNING_CONFIG_FAILED;
6912
6913 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6914 NB_OP_MODIFY, "false");
6915
6916 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6917}
6918
47cbc09b
PM
6919
6920/* enforce-first-as */
f4b8ec07
CS
6921DEFUN_YANG (neighbor_enforce_first_as,
6922 neighbor_enforce_first_as_cmd,
6923 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6925 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6926{
6927 int idx_peer = 1;
f4b8ec07 6928 char base_xpath[XPATH_MAXLEN];
47cbc09b 6929
f4b8ec07
CS
6930 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6931 sizeof(base_xpath), NULL)
6932 < 0)
6933 return CMD_WARNING_CONFIG_FAILED;
6934
6935 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6936
6937 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6938}
6939
f4b8ec07
CS
6940DEFUN_YANG (no_neighbor_enforce_first_as,
6941 no_neighbor_enforce_first_as_cmd,
6942 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6943 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6944 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6945{
6946 int idx_peer = 2;
f4b8ec07 6947 char base_xpath[XPATH_MAXLEN];
47cbc09b 6948
f4b8ec07
CS
6949 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6950 sizeof(base_xpath), NULL)
6951 < 0)
6952 return CMD_WARNING_CONFIG_FAILED;
6953
6954 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6955
6956 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6957}
6958
f4b8ec07
CS
6959static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6960 char *base_xpath, int xpath_len,
6961 char *xpath)
6962{
6963 union sockunion su;
6964 char num_xpath[XPATH_MAXLEN];
6965 char unnbr_xpath[XPATH_MAXLEN];
6966 char prgrp_xpath[XPATH_MAXLEN];
6967
6968 if (str2sockunion(peer_str, &su) == 0) {
6969 snprintf(num_xpath, sizeof(num_xpath),
6970 "/neighbors/neighbor[remote-address='%s']", peer_str);
6971 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6972 VTY_CURR_XPATH, num_xpath)) {
6973 snprintf(base_xpath, xpath_len,
6974 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6975 xpath ? xpath : "");
6976 } else {
6977 vty_out(vty,
6978 "%% Specify remote-as or peer-group commands first\n");
6979 return -1;
6980 }
6981
6982 } else {
6983 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6984 "/neighbors/unnumbered-neighbor[interface='%s']",
6985 peer_str);
6986
6987 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6988 "/peer-groups/peer-group[peer-group-name='%s']",
6989 peer_str);
6990
6991 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6992 VTY_CURR_XPATH, unnbr_xpath)) {
6993 snprintf(base_xpath, xpath_len,
6994 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6995 xpath ? xpath : "");
6996 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6997 "%s%s", VTY_CURR_XPATH,
6998 prgrp_xpath)) {
6999 snprintf(base_xpath, xpath_len,
7000 FRR_BGP_PEER_GROUP_XPATH, peer_str,
7001 xpath ? xpath : "");
7002 } else {
7003 vty_out(vty,
7004 "%% Create the peer-group or interface first\n");
7005 return -1;
7006 }
7007 }
7008
7009 return 0;
7010}
47cbc09b 7011
f4b8ec07
CS
7012DEFUN_YANG (neighbor_description,
7013 neighbor_description_cmd,
7014 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7015 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7016 "Neighbor specific description\n"
7017 "Up to 80 characters describing this neighbor\n")
718e3744 7018{
d62a17ae 7019 int idx_peer = 1;
7020 int idx_line = 3;
f4b8ec07
CS
7021 int ret;
7022 char base_xpath[XPATH_MAXLEN];
d62a17ae 7023 char *str;
718e3744 7024
f4b8ec07
CS
7025 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7026 sizeof(base_xpath), NULL)
7027 < 0)
d62a17ae 7028 return CMD_WARNING_CONFIG_FAILED;
718e3744 7029
d62a17ae 7030 str = argv_concat(argv, argc, idx_line);
718e3744 7031
f4b8ec07
CS
7032 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7033
7034 ret = nb_cli_apply_changes(vty, base_xpath);
718e3744 7035
d62a17ae 7036 XFREE(MTYPE_TMP, str);
718e3744 7037
f4b8ec07 7038 return ret;
718e3744 7039}
7040
f4b8ec07
CS
7041DEFUN_YANG (no_neighbor_description,
7042 no_neighbor_description_cmd,
7043 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7044 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7045 "Neighbor specific description\n")
718e3744 7046{
d62a17ae 7047 int idx_peer = 2;
f4b8ec07
CS
7048 char base_xpath[XPATH_MAXLEN];
7049
7050 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7051 sizeof(base_xpath), NULL)
7052 < 0)
d62a17ae 7053 return CMD_WARNING_CONFIG_FAILED;
718e3744 7054
f4b8ec07 7055 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
718e3744 7056
f4b8ec07 7057 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7058}
7059
232c75cd 7060ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
7061 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7063 "Neighbor specific description\n"
7064 "Up to 80 characters describing this neighbor\n")
6b0655a2 7065
d62a17ae 7066#define BGP_UPDATE_SOURCE_HELP_STR \
7067 "IPv4 address\n" \
7068 "IPv6 address\n" \
7069 "Interface name (requires zebra to be running)\n"
369688c0 7070
f4b8ec07
CS
7071DEFUN_YANG (neighbor_update_source,
7072 neighbor_update_source_cmd,
7073 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7074 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7075 "Source of routing updates\n"
7076 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7077{
d62a17ae 7078 int idx_peer = 1;
7079 int idx_peer_2 = 3;
f4b8ec07
CS
7080 union sockunion su;
7081 char base_xpath[XPATH_MAXLEN];
7082
7083 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7084 sizeof(base_xpath), NULL)
7085 < 0)
7086 return CMD_WARNING_CONFIG_FAILED;
7087
f4b8ec07
CS
7088 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7089 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
d62a17ae 7090 argv[idx_peer_2]->arg);
f4b8ec07
CS
7091 else
7092 nb_cli_enqueue_change(vty, "./update-source/interface",
7093 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7094
7095 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7096}
7097
f4b8ec07
CS
7098DEFUN_YANG (no_neighbor_update_source,
7099 no_neighbor_update_source_cmd,
7100 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7101 NO_STR NEIGHBOR_STR
7102 NEIGHBOR_ADDR_STR2
7103 "Source of routing updates\n"
7104 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7105{
d62a17ae 7106 int idx_peer = 2;
f4b8ec07 7107 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
7108
7109 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7110 sizeof(base_xpath), NULL)
7111 < 0)
7112 return CMD_WARNING_CONFIG_FAILED;
7113
555c8ab7
CS
7114 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7115 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7116 NULL);
f4b8ec07
CS
7117
7118 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7119}
6b0655a2 7120
d62a17ae 7121static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7122 afi_t afi, safi_t safi,
7123 const char *rmap, int set)
718e3744 7124{
d62a17ae 7125 int ret;
7126 struct peer *peer;
80912664 7127 struct route_map *route_map = NULL;
718e3744 7128
d62a17ae 7129 peer = peer_and_group_lookup_vty(vty, peer_str);
7130 if (!peer)
7131 return CMD_WARNING_CONFIG_FAILED;
718e3744 7132
1de27621 7133 if (set) {
80912664
DS
7134 if (rmap)
7135 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7136 ret = peer_default_originate_set(peer, afi, safi,
7137 rmap, route_map);
7138 } else
d62a17ae 7139 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7140
d62a17ae 7141 return bgp_vty_return(vty, ret);
718e3744 7142}
7143
7144/* neighbor default-originate. */
7145DEFUN (neighbor_default_originate,
7146 neighbor_default_originate_cmd,
9ccf14f7 7147 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7148 NEIGHBOR_STR
7149 NEIGHBOR_ADDR_STR2
7150 "Originate default route to this neighbor\n")
7151{
d62a17ae 7152 int idx_peer = 1;
7153 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7154 bgp_node_afi(vty),
7155 bgp_node_safi(vty), NULL, 1);
718e3744 7156}
7157
d62a17ae 7158ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7159 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7160 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7161 "Originate default route to this neighbor\n")
596c17ba 7162
718e3744 7163DEFUN (neighbor_default_originate_rmap,
7164 neighbor_default_originate_rmap_cmd,
9ccf14f7 7165 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 7166 NEIGHBOR_STR
7167 NEIGHBOR_ADDR_STR2
7168 "Originate default route to this neighbor\n"
7169 "Route-map to specify criteria to originate default\n"
7170 "route-map name\n")
7171{
d62a17ae 7172 int idx_peer = 1;
7173 int idx_word = 4;
7174 return peer_default_originate_set_vty(
7175 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7176 argv[idx_word]->arg, 1);
718e3744 7177}
7178
d62a17ae 7179ALIAS_HIDDEN(
7180 neighbor_default_originate_rmap,
7181 neighbor_default_originate_rmap_hidden_cmd,
7182 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7183 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7184 "Originate default route to this neighbor\n"
7185 "Route-map to specify criteria to originate default\n"
7186 "route-map name\n")
596c17ba 7187
718e3744 7188DEFUN (no_neighbor_default_originate,
7189 no_neighbor_default_originate_cmd,
a636c635 7190 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 7191 NO_STR
7192 NEIGHBOR_STR
7193 NEIGHBOR_ADDR_STR2
a636c635
DW
7194 "Originate default route to this neighbor\n"
7195 "Route-map to specify criteria to originate default\n"
7196 "route-map name\n")
718e3744 7197{
d62a17ae 7198 int idx_peer = 2;
7199 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7200 bgp_node_afi(vty),
7201 bgp_node_safi(vty), NULL, 0);
718e3744 7202}
7203
d62a17ae 7204ALIAS_HIDDEN(
7205 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7206 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7208 "Originate default route to this neighbor\n"
7209 "Route-map to specify criteria to originate default\n"
7210 "route-map name\n")
596c17ba 7211
6b0655a2 7212
f418446b 7213/* Set specified peer's BGP port. */
f4b8ec07
CS
7214DEFUN_YANG (neighbor_port,
7215 neighbor_port_cmd,
7216 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7217 NEIGHBOR_STR
7218 NEIGHBOR_ADDR_STR
7219 "Neighbor's BGP port\n"
7220 "TCP port number\n")
718e3744 7221{
d62a17ae 7222 int idx_ip = 1;
7223 int idx_number = 3;
f4b8ec07 7224 char base_xpath[XPATH_MAXLEN];
718e3744 7225
f4b8ec07
CS
7226 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7227 argv[idx_ip]->arg, "");
718e3744 7228
f4b8ec07
CS
7229 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7230 argv[idx_number]->arg);
7231
7232 return nb_cli_apply_changes(vty, base_xpath);
7233}
6b0655a2 7234
f4b8ec07
CS
7235DEFUN_YANG (no_neighbor_port,
7236 no_neighbor_port_cmd,
7237 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7238 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7239 "Neighbor's BGP port\n"
7240 "TCP port number\n")
718e3744 7241{
f4b8ec07
CS
7242 int idx_ip = 2;
7243 char base_xpath[XPATH_MAXLEN];
718e3744 7244
f4b8ec07
CS
7245 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7246 argv[idx_ip]->arg, "");
718e3744 7247
f4b8ec07 7248 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
718e3744 7249
f4b8ec07 7250 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7251}
7252
f4b8ec07
CS
7253DEFUN_YANG (neighbor_weight,
7254 neighbor_weight_cmd,
7255 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7256 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7257 "Set default weight for routes from this neighbor\n"
7258 "default weight\n")
718e3744 7259{
f4b8ec07
CS
7260 int idx_peer = 1;
7261 int idx_number = 3;
7262 char base_xpath[XPATH_MAXLEN];
7263 char af_xpath[XPATH_MAXLEN];
7264 char attr_xpath[XPATH_MAXLEN];
7265 afi_t afi = bgp_node_afi(vty);
7266 safi_t safi = bgp_node_safi(vty);
718e3744 7267
f4b8ec07
CS
7268 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7269 yang_afi_safi_value2identity(afi, safi));
7270
7271 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7272 sizeof(base_xpath), af_xpath)
7273 < 0)
d62a17ae 7274 return CMD_WARNING_CONFIG_FAILED;
718e3744 7275
f4b8ec07
CS
7276 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7277 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7278
f4b8ec07
CS
7279 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7280 argv[idx_number]->arg);
7281
7282 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7283}
7284
d62a17ae 7285ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7286 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7287 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7288 "Set default weight for routes from this neighbor\n"
7289 "default weight\n")
596c17ba 7290
f4b8ec07
CS
7291DEFUN_YANG (no_neighbor_weight,
7292 no_neighbor_weight_cmd,
7293 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7294 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7295 "Set default weight for routes from this neighbor\n"
7296 "default weight\n")
718e3744 7297{
d62a17ae 7298 int idx_peer = 2;
f4b8ec07
CS
7299 char base_xpath[XPATH_MAXLEN];
7300 char af_xpath[XPATH_MAXLEN];
7301 char attr_xpath[XPATH_MAXLEN];
7302 afi_t afi = bgp_node_afi(vty);
7303 safi_t safi = bgp_node_safi(vty);
7304
7305 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7306 yang_afi_safi_value2identity(afi, safi));
7307
7308 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7309 sizeof(base_xpath), af_xpath)
7310 < 0)
7311 return CMD_WARNING_CONFIG_FAILED;
7312
7313 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7314 bgp_afi_safi_get_container_str(afi, safi));
7315
7316 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7317
7318 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7319}
7320
d62a17ae 7321ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7322 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7323 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7324 "Set default weight for routes from this neighbor\n"
7325 "default weight\n")
596c17ba 7326
6b0655a2 7327
718e3744 7328/* Override capability negotiation. */
8611c7f3
CS
7329DEFUN_YANG (neighbor_override_capability,
7330 neighbor_override_capability_cmd,
7331 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7332 NEIGHBOR_STR
7333 NEIGHBOR_ADDR_STR2
7334 "Override capability negotiation result\n")
718e3744 7335{
d62a17ae 7336 int idx_peer = 1;
8611c7f3
CS
7337 char base_xpath[XPATH_MAXLEN];
7338
7339 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7340 sizeof(base_xpath), NULL)
7341 < 0)
7342 return CMD_WARNING_CONFIG_FAILED;
7343
7344 nb_cli_enqueue_change(
7345 vty, "./capability-options/override-capability",
7346 NB_OP_MODIFY, "true");
7347
7348 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7349}
7350
8611c7f3
CS
7351DEFUN_YANG (no_neighbor_override_capability,
7352 no_neighbor_override_capability_cmd,
7353 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7354 NO_STR
7355 NEIGHBOR_STR
7356 NEIGHBOR_ADDR_STR2
7357 "Override capability negotiation result\n")
718e3744 7358{
d62a17ae 7359 int idx_peer = 2;
8611c7f3
CS
7360 char base_xpath[XPATH_MAXLEN];
7361
7362 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7363 sizeof(base_xpath), NULL)
7364 < 0)
7365 return CMD_WARNING_CONFIG_FAILED;
7366
7367 nb_cli_enqueue_change(
7368 vty, "./capability-options/override-capability",
7369 NB_OP_MODIFY, "false");
7370
7371 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7372}
6b0655a2 7373
8611c7f3
CS
7374DEFUN_YANG (neighbor_strict_capability,
7375 neighbor_strict_capability_cmd,
7376 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7377 NEIGHBOR_STR
7378 NEIGHBOR_ADDR_STR2
7379 "Strict capability negotiation match\n")
718e3744 7380{
9fb964de 7381 int idx_peer = 1;
8611c7f3 7382 char base_xpath[XPATH_MAXLEN];
9fb964de 7383
8611c7f3
CS
7384 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7385 sizeof(base_xpath), NULL)
7386 < 0)
7387 return CMD_WARNING_CONFIG_FAILED;
7388
7389 nb_cli_enqueue_change(
7390 vty, "./capability-options/strict-capability",
7391 NB_OP_MODIFY, "true");
7392
7393 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7394}
7395
8611c7f3
CS
7396DEFUN_YANG (no_neighbor_strict_capability,
7397 no_neighbor_strict_capability_cmd,
7398 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7399 NO_STR
7400 NEIGHBOR_STR
7401 NEIGHBOR_ADDR_STR2
7402 "Strict capability negotiation match\n")
718e3744 7403{
9fb964de 7404 int idx_peer = 2;
8611c7f3 7405 char base_xpath[XPATH_MAXLEN];
9fb964de 7406
8611c7f3
CS
7407 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7408 sizeof(base_xpath), NULL)
7409 < 0)
7410 return CMD_WARNING_CONFIG_FAILED;
7411
7412 nb_cli_enqueue_change(
7413 vty, "./capability-options/strict-capability",
7414 NB_OP_MODIFY, "false");
7415
7416 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7417}
6b0655a2 7418
f4b8ec07
CS
7419DEFUN_YANG (neighbor_timers,
7420 neighbor_timers_cmd,
7421 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7422 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7423 "BGP per neighbor timers\n"
7424 "Keepalive interval\n"
7425 "Holdtime\n")
718e3744 7426{
f4b8ec07
CS
7427 int idx_peer = 1;
7428 int idx_number = 3;
7429 int idx_number_2 = 4;
7430 char base_xpath[XPATH_MAXLEN];
718e3744 7431
f4b8ec07
CS
7432 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7433 sizeof(base_xpath), NULL)
7434 < 0)
d62a17ae 7435 return CMD_WARNING_CONFIG_FAILED;
718e3744 7436
f4b8ec07
CS
7437 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7438 argv[idx_number]->arg);
718e3744 7439
f4b8ec07
CS
7440 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7441 argv[idx_number_2]->arg);
718e3744 7442
f4b8ec07 7443 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7444}
6b0655a2 7445
f4b8ec07
CS
7446DEFUN_YANG (no_neighbor_timers,
7447 no_neighbor_timers_cmd,
7448 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7449 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7450 "BGP per neighbor timers\n"
7451 "Keepalive interval\n"
7452 "Holdtime\n")
718e3744 7453{
f4b8ec07
CS
7454 int idx_peer = 2;
7455 char base_xpath[XPATH_MAXLEN];
718e3744 7456
f4b8ec07
CS
7457 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7458 sizeof(base_xpath), NULL)
7459 < 0)
d62a17ae 7460 return CMD_WARNING_CONFIG_FAILED;
718e3744 7461
f4b8ec07 7462 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
718e3744 7463
f4b8ec07 7464 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
718e3744 7465
f4b8ec07 7466 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7467}
6b0655a2 7468
f4b8ec07
CS
7469DEFUN_YANG (neighbor_timers_connect,
7470 neighbor_timers_connect_cmd,
7471 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7472 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7473 "BGP per neighbor timers\n"
7474 "BGP connect timer\n"
7475 "Connect timer\n")
718e3744 7476{
f4b8ec07
CS
7477 int idx_peer = 1;
7478 int idx_number = 4;
7479 char base_xpath[XPATH_MAXLEN];
718e3744 7480
f4b8ec07
CS
7481 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7482 sizeof(base_xpath), NULL)
7483 < 0)
d62a17ae 7484 return CMD_WARNING_CONFIG_FAILED;
718e3744 7485
f4b8ec07
CS
7486 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7487 argv[idx_number]->arg);
718e3744 7488
f4b8ec07 7489 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7490}
7491
f4b8ec07
CS
7492DEFUN_YANG (no_neighbor_timers_connect,
7493 no_neighbor_timers_connect_cmd,
7494 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7495 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7496 "BGP per neighbor timers\n"
7497 "BGP connect timer\n"
7498 "Connect timer\n")
718e3744 7499{
f4b8ec07
CS
7500 int idx_peer = 2;
7501 char base_xpath[XPATH_MAXLEN];
718e3744 7502
f4b8ec07
CS
7503 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7504 sizeof(base_xpath), NULL)
7505 < 0)
d62a17ae 7506 return CMD_WARNING_CONFIG_FAILED;
718e3744 7507
f4b8ec07
CS
7508 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7509 NULL);
718e3744 7510
f4b8ec07 7511 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7512}
7513
d43114f3
DS
7514DEFPY (neighbor_timers_delayopen,
7515 neighbor_timers_delayopen_cmd,
7516 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7517 NEIGHBOR_STR
7518 NEIGHBOR_ADDR_STR2
7519 "BGP per neighbor timers\n"
7520 "RFC 4271 DelayOpenTimer\n"
7521 "DelayOpenTime timer interval\n")
7522{
7523 struct peer *peer;
7524
7525 peer = peer_and_group_lookup_vty(vty, neighbor);
7526 if (!peer)
7527 return CMD_WARNING_CONFIG_FAILED;
7528
7529 if (!interval) {
7530 if (peer_timers_delayopen_unset(peer))
7531 return CMD_WARNING_CONFIG_FAILED;
7532 } else {
7533 if (peer_timers_delayopen_set(peer, interval))
7534 return CMD_WARNING_CONFIG_FAILED;
7535 }
7536
7537 return CMD_SUCCESS;
7538}
7539
7540DEFPY (no_neighbor_timers_delayopen,
7541 no_neighbor_timers_delayopen_cmd,
7542 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7543 NO_STR
7544 NEIGHBOR_STR
7545 NEIGHBOR_ADDR_STR2
7546 "BGP per neighbor timers\n"
7547 "RFC 4271 DelayOpenTimer\n"
7548 "DelayOpenTime timer interval\n")
7549{
7550 struct peer *peer;
7551
7552 peer = peer_and_group_lookup_vty(vty, neighbor);
7553 if (!peer)
7554 return CMD_WARNING_CONFIG_FAILED;
7555
7556 if (peer_timers_delayopen_unset(peer))
7557 return CMD_WARNING_CONFIG_FAILED;
7558
7559 return CMD_SUCCESS;
7560}
7561
f4b8ec07
CS
7562DEFUN_YANG (neighbor_advertise_interval,
7563 neighbor_advertise_interval_cmd,
7564 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7565 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7566 "Minimum interval between sending BGP routing updates\n"
7567 "time in seconds\n")
718e3744 7568{
d62a17ae 7569 int idx_peer = 1;
f4b8ec07
CS
7570 int idx_number = 3;
7571 char base_xpath[XPATH_MAXLEN];
718e3744 7572
f4b8ec07
CS
7573 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7574 sizeof(base_xpath), NULL)
7575 < 0)
d62a17ae 7576 return CMD_WARNING_CONFIG_FAILED;
718e3744 7577
f4b8ec07
CS
7578 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7579 argv[idx_number]->arg);
718e3744 7580
f4b8ec07 7581 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7582}
7583
f4b8ec07
CS
7584DEFUN_YANG (no_neighbor_advertise_interval,
7585 no_neighbor_advertise_interval_cmd,
7586 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7587 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7588 "Minimum interval between sending BGP routing updates\n"
7589 "time in seconds\n")
718e3744 7590{
d62a17ae 7591 int idx_peer = 2;
f4b8ec07
CS
7592 char base_xpath[XPATH_MAXLEN];
7593
7594 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7595 sizeof(base_xpath), NULL)
7596 < 0)
7597 return CMD_WARNING_CONFIG_FAILED;
7598
7599 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7600 NULL);
7601
7602 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7603}
7604
6b0655a2 7605
518f0eb1
DS
7606/* Time to wait before processing route-map updates */
7607DEFUN (bgp_set_route_map_delay_timer,
7608 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7609 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7610 SET_STR
7611 "BGP route-map delay timer\n"
7612 "Time in secs to wait before processing route-map changes\n"
f414725f 7613 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7614{
d62a17ae 7615 int idx_number = 3;
d7c0a89a 7616 uint32_t rmap_delay_timer;
d62a17ae 7617
7618 if (argv[idx_number]->arg) {
7619 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7620 bm->rmap_update_timer = rmap_delay_timer;
7621
7622 /* if the dynamic update handling is being disabled, and a timer
7623 * is
7624 * running, stop the timer and act as if the timer has already
7625 * fired.
7626 */
7627 if (!rmap_delay_timer && bm->t_rmap_update) {
7628 BGP_TIMER_OFF(bm->t_rmap_update);
7629 thread_execute(bm->master, bgp_route_map_update_timer,
7630 NULL, 0);
7631 }
7632 return CMD_SUCCESS;
7633 } else {
7634 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7635 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7636 }
518f0eb1
DS
7637}
7638
7639DEFUN (no_bgp_set_route_map_delay_timer,
7640 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7641 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7642 NO_STR
3a2d747c 7643 BGP_STR
518f0eb1 7644 "Default BGP route-map delay timer\n"
8334fd5a
DW
7645 "Reset to default time to wait for processing route-map changes\n"
7646 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7647{
518f0eb1 7648
d62a17ae 7649 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7650
d62a17ae 7651 return CMD_SUCCESS;
518f0eb1
DS
7652}
7653
f4b8ec07
CS
7654DEFUN_YANG (neighbor_interface,
7655 neighbor_interface_cmd,
7656 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7657 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7658 "Interface\n"
7659 "Interface name\n")
718e3744 7660{
f4b8ec07
CS
7661 int idx_ip = 1;
7662 int idx_word = 3;
7663 char base_xpath[XPATH_MAXLEN];
718e3744 7664
f4b8ec07
CS
7665 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7666 argv[idx_ip]->arg, "");
718e3744 7667
f4b8ec07
CS
7668 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7669 argv[idx_word]->arg);
718e3744 7670
f4b8ec07 7671 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7672}
7673
f4b8ec07
CS
7674DEFUN_YANG (no_neighbor_interface,
7675 no_neighbor_interface_cmd,
7676 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7677 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7678 "Interface\n"
7679 "Interface name\n")
718e3744 7680{
d62a17ae 7681 int idx_peer = 2;
f4b8ec07
CS
7682 char base_xpath[XPATH_MAXLEN];
7683
7684 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7685 argv[idx_peer]->arg, "");
7686
7687 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7688
7689 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7690}
6b0655a2 7691
718e3744 7692DEFUN (neighbor_distribute_list,
7693 neighbor_distribute_list_cmd,
9ccf14f7 7694 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7695 NEIGHBOR_STR
7696 NEIGHBOR_ADDR_STR2
7697 "Filter updates to/from this neighbor\n"
7698 "IP access-list number\n"
7699 "IP access-list number (expanded range)\n"
7700 "IP Access-list name\n"
7701 "Filter incoming updates\n"
7702 "Filter outgoing updates\n")
7703{
d62a17ae 7704 int idx_peer = 1;
7705 int idx_acl = 3;
7706 int direct, ret;
7707 struct peer *peer;
a8206004 7708
d62a17ae 7709 const char *pstr = argv[idx_peer]->arg;
7710 const char *acl = argv[idx_acl]->arg;
7711 const char *inout = argv[argc - 1]->text;
a8206004 7712
d62a17ae 7713 peer = peer_and_group_lookup_vty(vty, pstr);
7714 if (!peer)
7715 return CMD_WARNING_CONFIG_FAILED;
a8206004 7716
d62a17ae 7717 /* Check filter direction. */
7718 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7719 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7720 direct, acl);
a8206004 7721
d62a17ae 7722 return bgp_vty_return(vty, ret);
718e3744 7723}
7724
d62a17ae 7725ALIAS_HIDDEN(
7726 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7727 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7728 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7729 "Filter updates to/from this neighbor\n"
7730 "IP access-list number\n"
7731 "IP access-list number (expanded range)\n"
7732 "IP Access-list name\n"
7733 "Filter incoming updates\n"
7734 "Filter outgoing updates\n")
596c17ba 7735
718e3744 7736DEFUN (no_neighbor_distribute_list,
7737 no_neighbor_distribute_list_cmd,
9ccf14f7 7738 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7739 NO_STR
7740 NEIGHBOR_STR
7741 NEIGHBOR_ADDR_STR2
7742 "Filter updates to/from this neighbor\n"
7743 "IP access-list number\n"
7744 "IP access-list number (expanded range)\n"
7745 "IP Access-list name\n"
7746 "Filter incoming updates\n"
7747 "Filter outgoing updates\n")
7748{
d62a17ae 7749 int idx_peer = 2;
7750 int direct, ret;
7751 struct peer *peer;
a8206004 7752
d62a17ae 7753 const char *pstr = argv[idx_peer]->arg;
7754 const char *inout = argv[argc - 1]->text;
a8206004 7755
d62a17ae 7756 peer = peer_and_group_lookup_vty(vty, pstr);
7757 if (!peer)
7758 return CMD_WARNING_CONFIG_FAILED;
a8206004 7759
d62a17ae 7760 /* Check filter direction. */
7761 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7762 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7763 direct);
a8206004 7764
d62a17ae 7765 return bgp_vty_return(vty, ret);
718e3744 7766}
6b0655a2 7767
d62a17ae 7768ALIAS_HIDDEN(
7769 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7770 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7771 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7772 "Filter updates to/from this neighbor\n"
7773 "IP access-list number\n"
7774 "IP access-list number (expanded range)\n"
7775 "IP Access-list name\n"
7776 "Filter incoming updates\n"
7777 "Filter outgoing updates\n")
596c17ba 7778
718e3744 7779/* Set prefix list to the peer. */
d9986d26
CS
7780DEFPY_YANG(
7781 neighbor_prefix_list, neighbor_prefix_list_cmd,
7782 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7784 "Filter updates to/from this neighbor\n"
7785 "Name of a prefix list\n"
7786 "Filter incoming updates\n"
7787 "Filter outgoing updates\n")
718e3744 7788{
d9986d26
CS
7789 char base_xpath[XPATH_MAXLEN];
7790 char af_xpath[XPATH_MAXLEN];
c6685575 7791 char plist_xpath[XPATH_MAXLEN];
d9986d26
CS
7792 afi_t afi = bgp_node_afi(vty);
7793 safi_t safi = bgp_node_safi(vty);
718e3744 7794
d9986d26
CS
7795 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7796 yang_afi_safi_value2identity(afi, safi));
7797 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7798 sizeof(base_xpath), af_xpath)
7799 < 0)
d62a17ae 7800 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7801
d9986d26
CS
7802 if (strmatch(direction, "in"))
7803 snprintf(plist_xpath, sizeof(plist_xpath),
7804 "./%s/filter-config/plist-import",
7805 bgp_afi_safi_get_container_str(afi, safi));
7806 else if (strmatch(direction, "out"))
7807 snprintf(plist_xpath, sizeof(plist_xpath),
7808 "./%s/filter-config/plist-export",
7809 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7810
d9986d26
CS
7811 if (!no)
7812 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7813 prefix_str);
7814 else
7815 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
718e3744 7816
d9986d26 7817 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7818}
7819
d62a17ae 7820ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7821 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7822 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7823 "Filter updates to/from this neighbor\n"
7824 "Name of a prefix list\n"
7825 "Filter incoming updates\n"
7826 "Filter outgoing updates\n")
596c17ba 7827
d62a17ae 7828static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7829 safi_t safi, const char *name_str,
7830 const char *direct_str)
718e3744 7831{
d62a17ae 7832 int ret;
7833 struct peer *peer;
7834 int direct = FILTER_IN;
718e3744 7835
d62a17ae 7836 peer = peer_and_group_lookup_vty(vty, ip_str);
7837 if (!peer)
7838 return CMD_WARNING_CONFIG_FAILED;
718e3744 7839
d62a17ae 7840 /* Check filter direction. */
7841 if (strncmp(direct_str, "i", 1) == 0)
7842 direct = FILTER_IN;
7843 else if (strncmp(direct_str, "o", 1) == 0)
7844 direct = FILTER_OUT;
718e3744 7845
d62a17ae 7846 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7847
d62a17ae 7848 return bgp_vty_return(vty, ret);
718e3744 7849}
7850
d62a17ae 7851static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7852 safi_t safi, const char *direct_str)
718e3744 7853{
d62a17ae 7854 int ret;
7855 struct peer *peer;
7856 int direct = FILTER_IN;
718e3744 7857
d62a17ae 7858 peer = peer_and_group_lookup_vty(vty, ip_str);
7859 if (!peer)
7860 return CMD_WARNING_CONFIG_FAILED;
718e3744 7861
d62a17ae 7862 /* Check filter direction. */
7863 if (strncmp(direct_str, "i", 1) == 0)
7864 direct = FILTER_IN;
7865 else if (strncmp(direct_str, "o", 1) == 0)
7866 direct = FILTER_OUT;
718e3744 7867
d62a17ae 7868 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7869
d62a17ae 7870 return bgp_vty_return(vty, ret);
718e3744 7871}
7872
7873DEFUN (neighbor_filter_list,
7874 neighbor_filter_list_cmd,
9ccf14f7 7875 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7876 NEIGHBOR_STR
7877 NEIGHBOR_ADDR_STR2
7878 "Establish BGP filters\n"
7879 "AS path access-list name\n"
7880 "Filter incoming routes\n"
7881 "Filter outgoing routes\n")
7882{
d62a17ae 7883 int idx_peer = 1;
7884 int idx_word = 3;
7885 int idx_in_out = 4;
7886 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7887 bgp_node_safi(vty), argv[idx_word]->arg,
7888 argv[idx_in_out]->arg);
718e3744 7889}
7890
d62a17ae 7891ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7892 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7894 "Establish BGP filters\n"
7895 "AS path access-list name\n"
7896 "Filter incoming routes\n"
7897 "Filter outgoing routes\n")
596c17ba 7898
718e3744 7899DEFUN (no_neighbor_filter_list,
7900 no_neighbor_filter_list_cmd,
9ccf14f7 7901 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7902 NO_STR
7903 NEIGHBOR_STR
7904 NEIGHBOR_ADDR_STR2
7905 "Establish BGP filters\n"
7906 "AS path access-list name\n"
7907 "Filter incoming routes\n"
7908 "Filter outgoing routes\n")
7909{
d62a17ae 7910 int idx_peer = 2;
7911 int idx_in_out = 5;
7912 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7913 bgp_node_afi(vty), bgp_node_safi(vty),
7914 argv[idx_in_out]->arg);
718e3744 7915}
6b0655a2 7916
d62a17ae 7917ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7918 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7919 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7920 "Establish BGP filters\n"
7921 "AS path access-list name\n"
7922 "Filter incoming routes\n"
7923 "Filter outgoing routes\n")
596c17ba 7924
7f7940e6
MK
7925/* Set advertise-map to the peer. */
7926static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7927 afi_t afi, safi_t safi,
cf2ad4d8
MK
7928 const char *advertise_str,
7929 const char *condition_str, bool condition,
7930 bool set)
7f7940e6
MK
7931{
7932 int ret = CMD_WARNING_CONFIG_FAILED;
7933 struct peer *peer;
7934 struct route_map *advertise_map;
7935 struct route_map *condition_map;
7936
7937 peer = peer_and_group_lookup_vty(vty, ip_str);
7938 if (!peer)
7939 return ret;
7940
7941 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7942 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7943
cf2ad4d8
MK
7944 if (set)
7945 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7946 advertise_map, condition_str,
7947 condition_map, condition);
7948 else
7949 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7950 advertise_map, condition_str,
7951 condition_map, condition);
7f7940e6
MK
7952
7953 return bgp_vty_return(vty, ret);
7954}
7955
cf2ad4d8 7956DEFPY (neighbor_advertise_map,
7f7940e6 7957 neighbor_advertise_map_cmd,
52b84062 7958 "[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 7959 NO_STR
7f7940e6
MK
7960 NEIGHBOR_STR
7961 NEIGHBOR_ADDR_STR2
7962 "Route-map to conditionally advertise routes\n"
7963 "Name of advertise map\n"
7964 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7965 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7966 "Name of the exist or non exist map\n")
7f7940e6 7967{
7f7940e6
MK
7968 bool condition = CONDITION_EXIST;
7969
52b84062 7970 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7971 condition = CONDITION_NON_EXIST;
7972
52b84062
MK
7973 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7974 bgp_node_safi(vty), advertise_str,
7975 condition_str, condition, !no);
7f7940e6
MK
7976}
7977
7978ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7979 "[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
7980 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7981 "Route-map to conditionally advertise routes\n"
7982 "Name of advertise map\n"
7983 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7984 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7985 "Name of the exist or non exist map\n")
7f7940e6 7986
718e3744 7987/* Set route-map to the peer. */
c6685575
CS
7988DEFPY_YANG(
7989 neighbor_route_map, neighbor_route_map_cmd,
7990 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
7991 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7992 "Apply route map to neighbor\n"
7993 "Name of route map\n"
7994 "Apply map to incoming routes\n"
7995 "Apply map to outbound routes\n")
718e3744 7996{
c6685575
CS
7997 char base_xpath[XPATH_MAXLEN];
7998 char af_xpath[XPATH_MAXLEN];
7999 char rmap_xpath[XPATH_MAXLEN];
8000 afi_t afi = bgp_node_afi(vty);
8001 safi_t safi = bgp_node_safi(vty);
718e3744 8002
c6685575
CS
8003 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8004 yang_afi_safi_value2identity(afi, safi));
8005 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
8006 sizeof(base_xpath), af_xpath)
8007 < 0)
d62a17ae 8008 return CMD_WARNING_CONFIG_FAILED;
718e3744 8009
c6685575
CS
8010 if (strmatch(direction, "in"))
8011 snprintf(rmap_xpath, sizeof(rmap_xpath),
8012 "./%s/filter-config/rmap-import",
8013 bgp_afi_safi_get_container_str(afi, safi));
8014 else if (strmatch(direction, "out"))
8015 snprintf(rmap_xpath, sizeof(rmap_xpath),
8016 "./%s/filter-config/rmap-export",
8017 bgp_afi_safi_get_container_str(afi, safi));
718e3744 8018
c6685575
CS
8019 if (!no) {
8020 if (!yang_dnode_exists(
8021 vty->candidate_config->dnode,
8022 "/frr-route-map:lib/route-map[name='%s']",
8023 rmap_str)) {
8024 if (vty_shell_serv(vty))
8025 vty_out(vty,
8026 "The route-map '%s' does not exist.\n",
8027 rmap_str);
8028 }
8029 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8030 } else
8031 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
718e3744 8032
c6685575 8033 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8034}
8035
718e3744 8036/* Set unsuppress-map to the peer. */
d62a17ae 8037static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8038 afi_t afi, safi_t safi,
8039 const char *name_str)
718e3744 8040{
d62a17ae 8041 int ret;
8042 struct peer *peer;
1de27621 8043 struct route_map *route_map;
718e3744 8044
d62a17ae 8045 peer = peer_and_group_lookup_vty(vty, ip_str);
8046 if (!peer)
8047 return CMD_WARNING_CONFIG_FAILED;
718e3744 8048
1de27621
DA
8049 route_map = route_map_lookup_warn_noexist(vty, name_str);
8050 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 8051
d62a17ae 8052 return bgp_vty_return(vty, ret);
718e3744 8053}
8054
8055/* Unset route-map from the peer. */
d62a17ae 8056static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8057 afi_t afi, safi_t safi)
718e3744 8058{
d62a17ae 8059 int ret;
8060 struct peer *peer;
718e3744 8061
d62a17ae 8062 peer = peer_and_group_lookup_vty(vty, ip_str);
8063 if (!peer)
8064 return CMD_WARNING_CONFIG_FAILED;
718e3744 8065
d62a17ae 8066 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8067
d62a17ae 8068 return bgp_vty_return(vty, ret);
718e3744 8069}
8070
8071DEFUN (neighbor_unsuppress_map,
8072 neighbor_unsuppress_map_cmd,
9ccf14f7 8073 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8074 NEIGHBOR_STR
8075 NEIGHBOR_ADDR_STR2
8076 "Route-map to selectively unsuppress suppressed routes\n"
8077 "Name of route map\n")
8078{
d62a17ae 8079 int idx_peer = 1;
8080 int idx_word = 3;
8081 return peer_unsuppress_map_set_vty(
8082 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8083 argv[idx_word]->arg);
718e3744 8084}
8085
d62a17ae 8086ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8087 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8088 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8089 "Route-map to selectively unsuppress suppressed routes\n"
8090 "Name of route map\n")
596c17ba 8091
718e3744 8092DEFUN (no_neighbor_unsuppress_map,
8093 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8094 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8095 NO_STR
8096 NEIGHBOR_STR
8097 NEIGHBOR_ADDR_STR2
8098 "Route-map to selectively unsuppress suppressed routes\n"
8099 "Name of route map\n")
8100{
d62a17ae 8101 int idx_peer = 2;
8102 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8103 bgp_node_afi(vty),
8104 bgp_node_safi(vty));
718e3744 8105}
6b0655a2 8106
d62a17ae 8107ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8108 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8109 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8110 "Route-map to selectively unsuppress suppressed routes\n"
8111 "Name of route map\n")
596c17ba 8112
fde246e8 8113/* Maximum number of prefix to be sent to the neighbor. */
232c75cd
CS
8114DEFUN_YANG(neighbor_maximum_prefix_out,
8115 neighbor_maximum_prefix_out_cmd,
8116 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8117 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8118 "Maximum number of prefixes to be sent to this peer\n"
8119 "Maximum no. of prefix limit\n")
fde246e8 8120{
04261dec
CS
8121 char base_xpath[XPATH_MAXLEN];
8122 char af_xpath[XPATH_MAXLEN];
8123 char attr_xpath[XPATH_MAXLEN];
fde246e8
DA
8124 int idx_peer = 1;
8125 int idx_number = 3;
fde246e8
DA
8126 afi_t afi = bgp_node_afi(vty);
8127 safi_t safi = bgp_node_safi(vty);
8128
04261dec
CS
8129 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8130 yang_afi_safi_value2identity(afi, safi));
8131 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8132 sizeof(base_xpath), af_xpath)
8133 < 0)
fde246e8
DA
8134 return CMD_WARNING_CONFIG_FAILED;
8135
04261dec
CS
8136 snprintf(attr_xpath, sizeof(attr_xpath),
8137 "/%s/prefix-limit/direction-list[direction='out']",
8138 bgp_afi_safi_get_container_str(afi, safi));
8139 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
fde246e8 8140
04261dec 8141 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
fde246e8 8142
04261dec
CS
8143 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8144 argv[idx_number]->arg);
8145
8146 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8147}
8148
232c75cd
CS
8149DEFUN_YANG(no_neighbor_maximum_prefix_out,
8150 no_neighbor_maximum_prefix_out_cmd,
8151 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8152 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8153 "Maximum number of prefixes to be sent to this peer\n")
fde246e8 8154{
04261dec
CS
8155 char base_xpath[XPATH_MAXLEN];
8156 char af_xpath[XPATH_MAXLEN];
8157 char attr_xpath[XPATH_MAXLEN];
fde246e8 8158 int idx_peer = 2;
fde246e8
DA
8159 afi_t afi = bgp_node_afi(vty);
8160 safi_t safi = bgp_node_safi(vty);
8161
04261dec
CS
8162 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8163 yang_afi_safi_value2identity(afi, safi));
8164 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8165 sizeof(base_xpath), af_xpath)
8166 < 0)
fde246e8
DA
8167 return CMD_WARNING_CONFIG_FAILED;
8168
04261dec
CS
8169 snprintf(attr_xpath, sizeof(attr_xpath),
8170 "/%s/prefix-limit/direction-list[direction='out']",
8171 bgp_afi_safi_get_container_str(afi, safi));
8172 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8173
8174 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
fde246e8 8175
04261dec 8176 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8177}
8178
9cbd06e0
DA
8179/* Maximum number of prefix configuration. Prefix count is different
8180 for each peer configuration. So this configuration can be set for
718e3744 8181 each peer configuration. */
232c75cd
CS
8182DEFUN_YANG(neighbor_maximum_prefix,
8183 neighbor_maximum_prefix_cmd,
8184 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8186 "Maximum number of prefix accept from this peer\n"
8187 "maximum no. of prefix limit\n"
8188 "Force checking all received routes not only accepted\n")
718e3744 8189{
d62a17ae 8190 int idx_peer = 1;
8191 int idx_number = 3;
9cbd06e0 8192 int idx_force = 0;
04261dec
CS
8193 char base_xpath[XPATH_MAXLEN];
8194 char af_xpath[XPATH_MAXLEN];
8195 char attr_xpath[XPATH_MAXLEN];
8196 afi_t afi = bgp_node_afi(vty);
8197 safi_t safi = bgp_node_safi(vty);
8198
8199 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8200 yang_afi_safi_value2identity(afi, safi));
8201 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8202 sizeof(base_xpath), af_xpath)
8203 < 0)
8204 return CMD_WARNING_CONFIG_FAILED;
8205
8206 snprintf(attr_xpath, sizeof(attr_xpath),
8207 "/%s/prefix-limit/direction-list[direction='in']",
8208 bgp_afi_safi_get_container_str(afi, safi));
8209 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8210
8211 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9cbd06e0 8212
04261dec
CS
8213 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8214 argv[idx_number]->arg);
9cbd06e0 8215 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8216 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8217 "true");
9cbd06e0 8218
04261dec 8219 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8220}
8221
d62a17ae 8222ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8223 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8224 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8225 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8226 "maximum no. of prefix limit\n"
8227 "Force checking all received routes not only accepted\n")
596c17ba 8228
232c75cd
CS
8229DEFUN_YANG(neighbor_maximum_prefix_threshold,
8230 neighbor_maximum_prefix_threshold_cmd,
8231 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8232 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8233 "Maximum number of prefix accept from this peer\n"
8234 "maximum no. of prefix limit\n"
8235 "Threshold value (%) at which to generate a warning msg\n"
8236 "Force checking all received routes not only accepted\n")
e0701b79 8237{
d62a17ae 8238 int idx_peer = 1;
8239 int idx_number = 3;
8240 int idx_number_2 = 4;
9cbd06e0 8241 int idx_force = 0;
04261dec
CS
8242 char base_xpath[XPATH_MAXLEN];
8243 char af_xpath[XPATH_MAXLEN];
8244 char attr_xpath[XPATH_MAXLEN];
8245 afi_t afi = bgp_node_afi(vty);
8246 safi_t safi = bgp_node_safi(vty);
8247
8248 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8249 yang_afi_safi_value2identity(afi, safi));
8250 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8251 sizeof(base_xpath), af_xpath)
8252 < 0)
8253 return CMD_WARNING_CONFIG_FAILED;
8254
8255 snprintf(attr_xpath, sizeof(attr_xpath),
8256 "/%s/prefix-limit/direction-list[direction='in']",
8257 bgp_afi_safi_get_container_str(afi, safi));
8258 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8259
8260 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8261
8262 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8263 argv[idx_number]->arg);
8264
8265 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8266 NB_OP_MODIFY, argv[idx_number_2]->arg);
9cbd06e0
DA
8267
8268 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8269 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8270 "true");
9cbd06e0 8271
04261dec 8272 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8273}
e0701b79 8274
d62a17ae 8275ALIAS_HIDDEN(
8276 neighbor_maximum_prefix_threshold,
8277 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8278 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8279 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8280 "Maximum number of prefix accept from this peer\n"
8281 "maximum no. of prefix limit\n"
9cbd06e0
DA
8282 "Threshold value (%) at which to generate a warning msg\n"
8283 "Force checking all received routes not only accepted\n")
596c17ba 8284
232c75cd
CS
8285DEFUN_YANG(neighbor_maximum_prefix_warning,
8286 neighbor_maximum_prefix_warning_cmd,
8287 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8289 "Maximum number of prefix accept from this peer\n"
8290 "maximum no. of prefix limit\n"
8291 "Only give warning message when limit is exceeded\n"
8292 "Force checking all received routes not only accepted\n")
718e3744 8293{
d62a17ae 8294 int idx_peer = 1;
8295 int idx_number = 3;
9cbd06e0 8296 int idx_force = 0;
04261dec
CS
8297 char base_xpath[XPATH_MAXLEN];
8298 char af_xpath[XPATH_MAXLEN];
8299 char attr_xpath[XPATH_MAXLEN];
8300 afi_t afi = bgp_node_afi(vty);
8301 safi_t safi = bgp_node_safi(vty);
8302
8303 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8304 yang_afi_safi_value2identity(afi, safi));
8305 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8306 sizeof(base_xpath), af_xpath)
8307 < 0)
8308 return CMD_WARNING_CONFIG_FAILED;
9cbd06e0 8309
04261dec
CS
8310 snprintf(attr_xpath, sizeof(attr_xpath),
8311 "/%s/prefix-limit/direction-list[direction='in']",
8312 bgp_afi_safi_get_container_str(afi, safi));
8313 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8314
8315 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8316
8317 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8318 argv[idx_number]->arg);
8319
8320 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8321 "true");
9cbd06e0 8322 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8323 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8324 "true");
9cbd06e0 8325
04261dec 8326 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8327}
8328
d62a17ae 8329ALIAS_HIDDEN(
8330 neighbor_maximum_prefix_warning,
8331 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8332 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8333 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8334 "Maximum number of prefix accept from this peer\n"
8335 "maximum no. of prefix limit\n"
9cbd06e0
DA
8336 "Only give warning message when limit is exceeded\n"
8337 "Force checking all received routes not only accepted\n")
596c17ba 8338
232c75cd
CS
8339DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8340 neighbor_maximum_prefix_threshold_warning_cmd,
8341 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8342 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8343 "Maximum number of prefix accept from this peer\n"
8344 "maximum no. of prefix limit\n"
8345 "Threshold value (%) at which to generate a warning msg\n"
8346 "Only give warning message when limit is exceeded\n"
8347 "Force checking all received routes not only accepted\n")
e0701b79 8348{
d62a17ae 8349 int idx_peer = 1;
8350 int idx_number = 3;
8351 int idx_number_2 = 4;
9cbd06e0 8352 int idx_force = 0;
04261dec
CS
8353 char base_xpath[XPATH_MAXLEN];
8354 char af_xpath[XPATH_MAXLEN];
8355 char attr_xpath[XPATH_MAXLEN];
8356 afi_t afi = bgp_node_afi(vty);
8357 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8358
04261dec
CS
8359 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8360 yang_afi_safi_value2identity(afi, safi));
8361 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8362 sizeof(base_xpath), af_xpath)
8363 < 0)
8364 return CMD_WARNING_CONFIG_FAILED;
8365
8366 snprintf(attr_xpath, sizeof(attr_xpath),
8367 "/%s/prefix-limit/direction-list[direction='in']",
8368 bgp_afi_safi_get_container_str(afi, safi));
8369 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8370
8371 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8372
8373 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8374 argv[idx_number]->arg);
8375 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8376 NB_OP_MODIFY, argv[idx_number_2]->arg);
8377 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8378 "true");
9cbd06e0 8379 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8380 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8381 "true");
9cbd06e0 8382
04261dec 8383 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8384}
8385
d62a17ae 8386ALIAS_HIDDEN(
8387 neighbor_maximum_prefix_threshold_warning,
8388 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8389 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8390 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8391 "Maximum number of prefix accept from this peer\n"
8392 "maximum no. of prefix limit\n"
8393 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8394 "Only give warning message when limit is exceeded\n"
8395 "Force checking all received routes not only accepted\n")
596c17ba 8396
232c75cd
CS
8397DEFUN_YANG(neighbor_maximum_prefix_restart,
8398 neighbor_maximum_prefix_restart_cmd,
8399 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8400 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8401 "Maximum number of prefix accept from this peer\n"
8402 "maximum no. of prefix limit\n"
8403 "Restart bgp connection after limit is exceeded\n"
8404 "Restart interval in minutes\n"
8405 "Force checking all received routes not only accepted\n")
0a486e5f 8406{
d62a17ae 8407 int idx_peer = 1;
8408 int idx_number = 3;
8409 int idx_number_2 = 5;
9cbd06e0 8410 int idx_force = 0;
04261dec
CS
8411 char base_xpath[XPATH_MAXLEN];
8412 char af_xpath[XPATH_MAXLEN];
8413 char attr_xpath[XPATH_MAXLEN];
8414 afi_t afi = bgp_node_afi(vty);
8415 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8416
04261dec
CS
8417 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8418 yang_afi_safi_value2identity(afi, safi));
8419 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8420 sizeof(base_xpath), af_xpath)
8421 < 0)
8422 return CMD_WARNING_CONFIG_FAILED;
8423
8424 snprintf(attr_xpath, sizeof(attr_xpath),
8425 "/%s/prefix-limit/direction-list[direction='in']",
8426 bgp_afi_safi_get_container_str(afi, safi));
8427 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8428
8429 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8430
8431 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8432 argv[idx_number]->arg);
8433 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8434 argv[idx_number_2]->arg);
9cbd06e0 8435 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8436 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8437 "true");
9cbd06e0 8438
04261dec 8439 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8440}
8441
d62a17ae 8442ALIAS_HIDDEN(
8443 neighbor_maximum_prefix_restart,
8444 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8445 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8446 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8447 "Maximum number of prefix accept from this peer\n"
8448 "maximum no. of prefix limit\n"
8449 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8450 "Restart interval in minutes\n"
8451 "Force checking all received routes not only accepted\n")
596c17ba 8452
232c75cd
CS
8453DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8454 neighbor_maximum_prefix_threshold_restart_cmd,
8455 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8456 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8457 "Maximum number of prefixes to accept from this peer\n"
8458 "maximum no. of prefix limit\n"
8459 "Threshold value (%) at which to generate a warning msg\n"
8460 "Restart bgp connection after limit is exceeded\n"
8461 "Restart interval in minutes\n"
8462 "Force checking all received routes not only accepted\n")
0a486e5f 8463{
d62a17ae 8464 int idx_peer = 1;
8465 int idx_number = 3;
8466 int idx_number_2 = 4;
8467 int idx_number_3 = 6;
9cbd06e0 8468 int idx_force = 0;
04261dec
CS
8469 char base_xpath[XPATH_MAXLEN];
8470 char af_xpath[XPATH_MAXLEN];
8471 char attr_xpath[XPATH_MAXLEN];
8472 afi_t afi = bgp_node_afi(vty);
8473 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8474
04261dec
CS
8475 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8476 yang_afi_safi_value2identity(afi, safi));
8477 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8478 sizeof(base_xpath), af_xpath)
8479 < 0)
8480 return CMD_WARNING_CONFIG_FAILED;
8481
8482 snprintf(attr_xpath, sizeof(attr_xpath),
8483 "/%s/prefix-limit/direction-list[direction='in']",
8484 bgp_afi_safi_get_container_str(afi, safi));
8485 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8486
8487 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8488
8489 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8490 argv[idx_number]->arg);
8491 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8492 NB_OP_MODIFY, argv[idx_number_2]->arg);
8493 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8494 argv[idx_number_3]->arg);
9cbd06e0 8495 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8496 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8497 "true");
9cbd06e0 8498
04261dec 8499 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 8500}
8501
8502ALIAS_HIDDEN(
8503 neighbor_maximum_prefix_threshold_restart,
8504 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8505 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8506 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8507 "Maximum number of prefixes to accept from this peer\n"
8508 "maximum no. of prefix limit\n"
8509 "Threshold value (%) at which to generate a warning msg\n"
8510 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8511 "Restart interval in minutes\n"
8512 "Force checking all received routes not only accepted\n")
596c17ba 8513
232c75cd
CS
8514DEFUN_YANG(no_neighbor_maximum_prefix,
8515 no_neighbor_maximum_prefix_cmd,
8516 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8517 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8518 "Maximum number of prefixes to accept from this peer\n"
8519 "maximum no. of prefix limit\n"
8520 "Threshold value (%) at which to generate a warning msg\n"
8521 "Restart bgp connection after limit is exceeded\n"
8522 "Restart interval in minutes\n"
8523 "Only give warning message when limit is exceeded\n"
8524 "Force checking all received routes not only accepted\n")
718e3744 8525{
d62a17ae 8526 int idx_peer = 2;
04261dec
CS
8527 char base_xpath[XPATH_MAXLEN];
8528 char af_xpath[XPATH_MAXLEN];
8529 char attr_xpath[XPATH_MAXLEN];
8530 afi_t afi = bgp_node_afi(vty);
8531 safi_t safi = bgp_node_safi(vty);
8532
8533 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8534 yang_afi_safi_value2identity(afi, safi));
8535 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8536 sizeof(base_xpath), af_xpath)
8537 < 0)
8538 return CMD_WARNING_CONFIG_FAILED;
8539
8540 snprintf(attr_xpath, sizeof(attr_xpath),
8541 "/%s/prefix-limit/direction-list[direction='in']",
8542 bgp_afi_safi_get_container_str(afi, safi));
8543 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8544
8545 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8546
8547 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8548}
e52702f2 8549
d62a17ae 8550ALIAS_HIDDEN(
8551 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8552 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8553 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8554 "Maximum number of prefixes to accept from this peer\n"
8555 "maximum no. of prefix limit\n"
8556 "Threshold value (%) at which to generate a warning msg\n"
8557 "Restart bgp connection after limit is exceeded\n"
8558 "Restart interval in minutes\n"
9cbd06e0
DA
8559 "Only give warning message when limit is exceeded\n"
8560 "Force checking all received routes not only accepted\n")
596c17ba 8561
718e3744 8562
718e3744 8563/* "neighbor allowas-in" */
8564DEFUN (neighbor_allowas_in,
8565 neighbor_allowas_in_cmd,
fd8503f5 8566 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8567 NEIGHBOR_STR
8568 NEIGHBOR_ADDR_STR2
31500417 8569 "Accept as-path with my AS present in it\n"
f79f7a7b 8570 "Number of occurrences of AS number\n"
fd8503f5 8571 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8572{
d62a17ae 8573 int idx_peer = 1;
8574 int idx_number_origin = 3;
8575 int ret;
8576 int origin = 0;
8577 struct peer *peer;
8578 int allow_num = 0;
8579
8580 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8581 if (!peer)
8582 return CMD_WARNING_CONFIG_FAILED;
8583
8584 if (argc <= idx_number_origin)
8585 allow_num = 3;
8586 else {
8587 if (argv[idx_number_origin]->type == WORD_TKN)
8588 origin = 1;
8589 else
8590 allow_num = atoi(argv[idx_number_origin]->arg);
8591 }
8592
8593 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8594 allow_num, origin);
8595
8596 return bgp_vty_return(vty, ret);
8597}
8598
8599ALIAS_HIDDEN(
8600 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8601 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8602 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8603 "Accept as-path with my AS present in it\n"
f79f7a7b 8604 "Number of occurrences of AS number\n"
d62a17ae 8605 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8606
718e3744 8607DEFUN (no_neighbor_allowas_in,
8608 no_neighbor_allowas_in_cmd,
fd8503f5 8609 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8610 NO_STR
8611 NEIGHBOR_STR
8612 NEIGHBOR_ADDR_STR2
8334fd5a 8613 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8614 "Number of occurrences of AS number\n"
fd8503f5 8615 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8616{
d62a17ae 8617 int idx_peer = 2;
8618 int ret;
8619 struct peer *peer;
718e3744 8620
d62a17ae 8621 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8622 if (!peer)
8623 return CMD_WARNING_CONFIG_FAILED;
718e3744 8624
d62a17ae 8625 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8626 bgp_node_safi(vty));
718e3744 8627
d62a17ae 8628 return bgp_vty_return(vty, ret);
718e3744 8629}
6b0655a2 8630
d62a17ae 8631ALIAS_HIDDEN(
8632 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8633 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8634 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8635 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8636 "Number of occurrences of AS number\n"
d62a17ae 8637 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8638
f4b8ec07
CS
8639DEFUN_YANG (neighbor_ttl_security,
8640 neighbor_ttl_security_cmd,
8641 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8642 NEIGHBOR_STR
8643 NEIGHBOR_ADDR_STR2
8644 "BGP ttl-security parameters\n"
8645 "Specify the maximum number of hops to the BGP peer\n"
8646 "Number of hops to BGP peer\n")
fa411a21 8647{
d62a17ae 8648 int idx_peer = 1;
8649 int idx_number = 4;
f4b8ec07 8650 char base_xpath[XPATH_MAXLEN];
d62a17ae 8651
f4b8ec07
CS
8652 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8653 sizeof(base_xpath), NULL)
8654 < 0)
d62a17ae 8655 return CMD_WARNING_CONFIG_FAILED;
8656
f4b8ec07
CS
8657 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8658 argv[idx_number]->arg);
7ebe625c 8659
f4b8ec07 8660 return nb_cli_apply_changes(vty, base_xpath);
fa411a21
NH
8661}
8662
232c75cd
CS
8663DEFUN_YANG(no_neighbor_ttl_security,
8664 no_neighbor_ttl_security_cmd,
8665 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8666 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8667 "BGP ttl-security parameters\n"
8668 "Specify the maximum number of hops to the BGP peer\n"
8669 "Number of hops to BGP peer\n")
fa411a21 8670{
d62a17ae 8671 int idx_peer = 2;
f4b8ec07 8672 char base_xpath[XPATH_MAXLEN];
fa411a21 8673
f4b8ec07
CS
8674 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8675 sizeof(base_xpath), NULL)
8676 < 0)
d62a17ae 8677 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8678
f4b8ec07
CS
8679 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8680
8681 return nb_cli_apply_changes(vty, base_xpath);
fa411a21 8682}
6b0655a2 8683
adbac85e
DW
8684DEFUN (neighbor_addpath_tx_all_paths,
8685 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8686 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8687 NEIGHBOR_STR
8688 NEIGHBOR_ADDR_STR2
8689 "Use addpath to advertise all paths to a neighbor\n")
8690{
d62a17ae 8691 int idx_peer = 1;
8692 struct peer *peer;
adbac85e 8693
d62a17ae 8694 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8695 if (!peer)
8696 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8697
dcc68b5e
MS
8698 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8699 BGP_ADDPATH_ALL);
8700 return CMD_SUCCESS;
adbac85e
DW
8701}
8702
d62a17ae 8703ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8704 neighbor_addpath_tx_all_paths_hidden_cmd,
8705 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8706 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8707 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8708
adbac85e
DW
8709DEFUN (no_neighbor_addpath_tx_all_paths,
8710 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8711 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8712 NO_STR
8713 NEIGHBOR_STR
8714 NEIGHBOR_ADDR_STR2
8715 "Use addpath to advertise all paths to a neighbor\n")
8716{
d62a17ae 8717 int idx_peer = 2;
dcc68b5e
MS
8718 struct peer *peer;
8719
8720 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8721 if (!peer)
8722 return CMD_WARNING_CONFIG_FAILED;
8723
8724 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8725 != BGP_ADDPATH_ALL) {
8726 vty_out(vty,
8727 "%% Peer not currently configured to transmit all paths.");
8728 return CMD_WARNING_CONFIG_FAILED;
8729 }
8730
8731 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8732 BGP_ADDPATH_NONE);
8733
8734 return CMD_SUCCESS;
adbac85e
DW
8735}
8736
d62a17ae 8737ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8738 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8739 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8741 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8742
06370dac
DW
8743DEFUN (neighbor_addpath_tx_bestpath_per_as,
8744 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8745 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8746 NEIGHBOR_STR
8747 NEIGHBOR_ADDR_STR2
8748 "Use addpath to advertise the bestpath per each neighboring AS\n")
8749{
d62a17ae 8750 int idx_peer = 1;
8751 struct peer *peer;
06370dac 8752
d62a17ae 8753 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8754 if (!peer)
8755 return CMD_WARNING_CONFIG_FAILED;
06370dac 8756
dcc68b5e
MS
8757 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8758 BGP_ADDPATH_BEST_PER_AS);
8759
8760 return CMD_SUCCESS;
06370dac
DW
8761}
8762
d62a17ae 8763ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8764 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8765 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8766 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8767 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8768
06370dac
DW
8769DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8770 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8771 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8772 NO_STR
8773 NEIGHBOR_STR
8774 NEIGHBOR_ADDR_STR2
8775 "Use addpath to advertise the bestpath per each neighboring AS\n")
8776{
d62a17ae 8777 int idx_peer = 2;
dcc68b5e
MS
8778 struct peer *peer;
8779
8780 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8781 if (!peer)
8782 return CMD_WARNING_CONFIG_FAILED;
8783
8784 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8785 != BGP_ADDPATH_BEST_PER_AS) {
8786 vty_out(vty,
8787 "%% Peer not currently configured to transmit all best path per as.");
8788 return CMD_WARNING_CONFIG_FAILED;
8789 }
8790
8791 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8792 BGP_ADDPATH_NONE);
8793
8794 return CMD_SUCCESS;
06370dac
DW
8795}
8796
d62a17ae 8797ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8798 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8799 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8800 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8801 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8802
2b31007c
RZ
8803DEFPY(
8804 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8805 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8806 NEIGHBOR_STR
8807 NEIGHBOR_ADDR_STR2
8808 "Detect AS loops before sending to neighbor\n")
8809{
8810 struct peer *peer;
8811
8812 peer = peer_and_group_lookup_vty(vty, neighbor);
8813 if (!peer)
8814 return CMD_WARNING_CONFIG_FAILED;
8815
8816 peer->as_path_loop_detection = true;
8817
8818 return CMD_SUCCESS;
8819}
8820
8821DEFPY(
8822 no_neighbor_aspath_loop_detection,
8823 no_neighbor_aspath_loop_detection_cmd,
8824 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8825 NO_STR
8826 NEIGHBOR_STR
8827 NEIGHBOR_ADDR_STR2
8828 "Detect AS loops before sending to neighbor\n")
8829{
8830 struct peer *peer;
8831
8832 peer = peer_and_group_lookup_vty(vty, neighbor);
8833 if (!peer)
8834 return CMD_WARNING_CONFIG_FAILED;
8835
8836 peer->as_path_loop_detection = false;
8837
8838 return CMD_SUCCESS;
8839}
8840
0221327c
DS
8841DEFPY(neighbor_damp,
8842 neighbor_damp_cmd,
8843 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8844 NEIGHBOR_STR
8845 NEIGHBOR_ADDR_STR2
8846 "Enable neighbor route-flap dampening\n"
8847 "Half-life time for the penalty\n"
8848 "Value to start reusing a route\n"
8849 "Value to start suppressing a route\n"
8850 "Maximum duration to suppress a stable route\n")
8851{
8852 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8853
8854 if (!peer)
8855 return CMD_WARNING_CONFIG_FAILED;
8856 if (!half)
8857 half = DEFAULT_HALF_LIFE;
8858 if (!reuse) {
8859 reuse = DEFAULT_REUSE;
8860 suppress = DEFAULT_SUPPRESS;
8861 max = half * 4;
8862 }
8863 if (suppress < reuse) {
8864 vty_out(vty,
8865 "Suppress value cannot be less than reuse value\n");
8866 return CMD_WARNING_CONFIG_FAILED;
8867 }
8868 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8869 half * 60, reuse, suppress, max * 60);
8870 return CMD_SUCCESS;
8871}
8872
8873DEFPY(no_neighbor_damp,
8874 no_neighbor_damp_cmd,
8875 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8876 NO_STR
8877 NEIGHBOR_STR
8878 NEIGHBOR_ADDR_STR2
8879 "Enable neighbor route-flap dampening\n"
8880 "Half-life time for the penalty\n"
8881 "Value to start reusing a route\n"
8882 "Value to start suppressing a route\n"
8883 "Maximum duration to suppress a stable route\n")
8884{
8885 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8886
8887 if (!peer)
8888 return CMD_WARNING_CONFIG_FAILED;
8889 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8890 return CMD_SUCCESS;
8891}
8892
8893DEFPY (show_ip_bgp_neighbor_damp_param,
8894 show_ip_bgp_neighbor_damp_param_cmd,
8895 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8896 SHOW_STR
8897 IP_STR
8898 BGP_STR
8899 BGP_AFI_HELP_STR
8900 "Address Family modifier\n"
8901 NEIGHBOR_STR
8902 NEIGHBOR_ADDR_STR2
8903 "Neighbor route-flap dampening information\n"
8904 "Display detail of configured dampening parameters\n"
8905 JSON_STR)
8906{
8907 bool use_json = false;
8908 int idx = 0;
8909 afi_t afi = AFI_IP;
8910 safi_t safi = SAFI_UNICAST;
8911 struct peer *peer;
8912
8913 if (argv_find(argv, argc, "ip", &idx))
8914 afi = AFI_IP;
8915 if (argv_find(argv, argc, "ipv4", &idx))
8916 afi = AFI_IP;
8917 if (argv_find(argv, argc, "ipv6", &idx))
8918 afi = AFI_IP6;
8919 peer = peer_and_group_lookup_vty(vty, neighbor);
8920 if (!peer)
8921 return CMD_WARNING;
8922 if (json)
8923 use_json = true;
8924 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
8925 return CMD_SUCCESS;
8926}
8927
b9c7bc5a 8928static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8929 struct ecommunity **list, bool is_rt6)
ddb5b488 8930{
b9c7bc5a
PZ
8931 struct ecommunity *ecom = NULL;
8932 struct ecommunity *ecomadd;
ddb5b488 8933
b9c7bc5a 8934 for (; argc; --argc, ++argv) {
9a659715
PG
8935 if (is_rt6)
8936 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8937 ECOMMUNITY_ROUTE_TARGET,
8938 0);
8939 else
8940 ecomadd = ecommunity_str2com(argv[0]->arg,
8941 ECOMMUNITY_ROUTE_TARGET,
8942 0);
b9c7bc5a
PZ
8943 if (!ecomadd) {
8944 vty_out(vty, "Malformed community-list value\n");
8945 if (ecom)
8946 ecommunity_free(&ecom);
8947 return CMD_WARNING_CONFIG_FAILED;
8948 }
ddb5b488 8949
b9c7bc5a
PZ
8950 if (ecom) {
8951 ecommunity_merge(ecom, ecomadd);
8952 ecommunity_free(&ecomadd);
8953 } else {
8954 ecom = ecomadd;
8955 }
8956 }
8957
8958 if (*list) {
8959 ecommunity_free(&*list);
ddb5b488 8960 }
b9c7bc5a
PZ
8961 *list = ecom;
8962
8963 return CMD_SUCCESS;
ddb5b488
PZ
8964}
8965
37a87b8f
CS
8966bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8967 bool v2vimport, char *errmsg, size_t errmsg_len)
8968{
8969 if (!v2vimport) {
8970 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8971 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8972 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8973 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8974 snprintf(
8975 errmsg, errmsg_len, "%s",
8976 "%% error: Please unconfigure import vrf commands before using vpn commands");
8977 return false;
8978 }
8979 } else {
8980 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8981 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8982 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8983 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8984 snprintf(
8985 errmsg, errmsg_len, "%s",
8986 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8987 return false;
8988 }
8989 }
8990 return true;
8991}
8992
0ca70ba5
DS
8993/*
8994 * v2vimport is true if we are handling a `import vrf ...` command
8995 */
8996static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8997{
0ca70ba5
DS
8998 afi_t afi;
8999
ddb5b488 9000 switch (vty->node) {
b9c7bc5a 9001 case BGP_IPV4_NODE:
0ca70ba5
DS
9002 afi = AFI_IP;
9003 break;
b9c7bc5a 9004 case BGP_IPV6_NODE:
0ca70ba5
DS
9005 afi = AFI_IP6;
9006 break;
ddb5b488
PZ
9007 default:
9008 vty_out(vty,
b9c7bc5a 9009 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 9010 return AFI_MAX;
ddb5b488 9011 }
69b07479 9012
0ca70ba5
DS
9013 if (!v2vimport) {
9014 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9015 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9016 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9017 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9018 vty_out(vty,
9019 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9020 return AFI_MAX;
9021 }
9022 } else {
9023 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9024 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9025 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9026 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9027 vty_out(vty,
9028 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9029 return AFI_MAX;
9030 }
9031 }
9032 return afi;
ddb5b488
PZ
9033}
9034
37a87b8f
CS
9035DEFPY_YANG(
9036 af_rd_vpn_export,
9037 af_rd_vpn_export_cmd,
9038 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9039 NO_STR
9040 "Specify route distinguisher\n"
9041 "Between current address-family and vpn\n"
9042 "For routes leaked from current address-family to vpn\n"
9043 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 9044{
37a87b8f 9045 char base_xpath[XPATH_MAXLEN];
ddb5b488 9046 afi_t afi;
37a87b8f 9047 safi_t safi;
b9c7bc5a 9048 int idx = 0;
b9c7bc5a 9049
37a87b8f
CS
9050 afi = bgp_node_afi(vty);
9051 safi = bgp_node_safi(vty);
ddb5b488 9052
37a87b8f
CS
9053 snprintf(
9054 base_xpath, sizeof(base_xpath),
9055 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9056 yang_afi_safi_value2identity(afi, safi),
9057 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9058
37a87b8f
CS
9059 if (argv_find(argv, argc, "no", &idx))
9060 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9061 else
9062 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
ddb5b488 9063
37a87b8f
CS
9064 return nb_cli_apply_changes(vty, base_xpath);
9065}
ddb5b488 9066
37a87b8f
CS
9067void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9068 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9069{
9070 int indent = 2;
69b07479 9071
37a87b8f
CS
9072 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9073 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9074}
9075
b9c7bc5a
PZ
9076ALIAS (af_rd_vpn_export,
9077 af_no_rd_vpn_export_cmd,
9078 "no rd vpn export",
ddb5b488 9079 NO_STR
b9c7bc5a
PZ
9080 "Specify route distinguisher\n"
9081 "Between current address-family and vpn\n"
9082 "For routes leaked from current address-family to vpn\n")
ddb5b488 9083
b9c7bc5a
PZ
9084DEFPY (af_label_vpn_export,
9085 af_label_vpn_export_cmd,
e70e9f8e 9086 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9087 NO_STR
ddb5b488 9088 "label value for VRF\n"
b9c7bc5a
PZ
9089 "Between current address-family and vpn\n"
9090 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9091 "Label Value <0-1048575>\n"
9092 "Automatically assign a label\n")
ddb5b488
PZ
9093{
9094 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9095 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9096 afi_t afi;
b9c7bc5a 9097 int idx = 0;
c6423c31 9098 bool yes = true;
b9c7bc5a
PZ
9099
9100 if (argv_find(argv, argc, "no", &idx))
c6423c31 9101 yes = false;
ddb5b488 9102
21a16cc2
PZ
9103 /* If "no ...", squash trailing parameter */
9104 if (!yes)
9105 label_auto = NULL;
9106
e70e9f8e
PZ
9107 if (yes) {
9108 if (!label_auto)
9109 label = label_val; /* parser should force unsigned */
9110 }
ddb5b488 9111
0ca70ba5 9112 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9113 if (afi == AFI_MAX)
9114 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9115
e70e9f8e 9116
69b07479
DS
9117 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9118 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9119 /* no change */
9120 return CMD_SUCCESS;
e70e9f8e 9121
69b07479
DS
9122 /*
9123 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9124 */
9125 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9126 bgp_get_default(), bgp);
9127
9128 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9129 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9130
9131 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9132
9133 /*
9134 * label has previously been automatically
9135 * assigned by labelpool: release it
9136 *
9137 * NB if tovpn_label == MPLS_LABEL_NONE it
9138 * means the automatic assignment is in flight
9139 * and therefore the labelpool callback must
9140 * detect that the auto label is not needed.
9141 */
9142
9143 bgp_lp_release(LP_TYPE_VRF,
9144 &bgp->vpn_policy[afi],
9145 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9146 }
69b07479
DS
9147 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9148 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9149 }
ddb5b488 9150
69b07479
DS
9151 bgp->vpn_policy[afi].tovpn_label = label;
9152 if (label_auto) {
9153 SET_FLAG(bgp->vpn_policy[afi].flags,
9154 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9155 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9156 vpn_leak_label_callback);
ddb5b488
PZ
9157 }
9158
69b07479
DS
9159 /* post-change: re-export vpn routes */
9160 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9161 bgp_get_default(), bgp);
9162
0d020cd6 9163 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9164 return CMD_SUCCESS;
9165}
9166
b9c7bc5a
PZ
9167ALIAS (af_label_vpn_export,
9168 af_no_label_vpn_export_cmd,
9169 "no label vpn export",
9170 NO_STR
9171 "label value for VRF\n"
9172 "Between current address-family and vpn\n"
9173 "For routes leaked from current address-family to vpn\n")
ddb5b488 9174
37a87b8f 9175DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 9176 af_nexthop_vpn_export_cmd,
8c85ca28 9177 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9178 NO_STR
ddb5b488 9179 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9180 "Between current address-family and vpn\n"
9181 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9182 "IPv4 prefix\n"
9183 "IPv6 prefix\n")
9184{
37a87b8f 9185 char base_xpath[XPATH_MAXLEN];
ddb5b488 9186 afi_t afi;
37a87b8f
CS
9187 safi_t safi;
9188 int idx = 0;
ddb5b488
PZ
9189 struct prefix p;
9190
8c85ca28
QY
9191 if (!no) {
9192 if (!nexthop_su) {
9193 vty_out(vty, "%% Nexthop required\n");
9194 return CMD_WARNING_CONFIG_FAILED;
9195 }
8c85ca28 9196 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9197 return CMD_WARNING_CONFIG_FAILED;
9198 }
ddb5b488 9199
37a87b8f
CS
9200 afi = bgp_node_afi(vty);
9201 safi = bgp_node_safi(vty);
ddb5b488 9202
37a87b8f
CS
9203 snprintf(
9204 base_xpath, sizeof(base_xpath),
9205 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9206 yang_afi_safi_value2identity(afi, safi),
9207 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9208
37a87b8f
CS
9209 if (argv_find(argv, argc, "no", &idx))
9210 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9211 else
9212 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9213 nexthop_su_str);
ddb5b488 9214
37a87b8f
CS
9215 return nb_cli_apply_changes(vty, base_xpath);
9216}
69b07479 9217
37a87b8f
CS
9218void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9219 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9220{
9221 int indent = 2;
9222
9223 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9224 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9225}
9226
b9c7bc5a 9227static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9228{
b9c7bc5a
PZ
9229 if (!strcmp(dstr, "import")) {
9230 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9231 } else if (!strcmp(dstr, "export")) {
9232 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9233 } else if (!strcmp(dstr, "both")) {
9234 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9235 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9236 } else {
9237 vty_out(vty, "%% direction parse error\n");
9238 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9239 }
ddb5b488
PZ
9240 return CMD_SUCCESS;
9241}
9242
b9c7bc5a
PZ
9243DEFPY (af_rt_vpn_imexport,
9244 af_rt_vpn_imexport_cmd,
9245 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9246 NO_STR
9247 "Specify route target list\n"
ddb5b488 9248 "Specify route target list\n"
b9c7bc5a
PZ
9249 "Between current address-family and vpn\n"
9250 "For routes leaked from vpn to current address-family: match any\n"
9251 "For routes leaked from current address-family to vpn: set\n"
9252 "both import: match any and export: set\n"
ddb5b488
PZ
9253 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9254{
9255 VTY_DECLVAR_CONTEXT(bgp, bgp);
9256 int ret;
9257 struct ecommunity *ecom = NULL;
9258 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
9259 vpn_policy_direction_t dir;
9260 afi_t afi;
9261 int idx = 0;
c6423c31 9262 bool yes = true;
ddb5b488 9263
b9c7bc5a 9264 if (argv_find(argv, argc, "no", &idx))
c6423c31 9265 yes = false;
b9c7bc5a 9266
0ca70ba5 9267 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9268 if (afi == AFI_MAX)
9269 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9270
b9c7bc5a 9271 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9272 if (ret != CMD_SUCCESS)
9273 return ret;
9274
b9c7bc5a
PZ
9275 if (yes) {
9276 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9277 vty_out(vty, "%% Missing RTLIST\n");
9278 return CMD_WARNING_CONFIG_FAILED;
9279 }
c6423c31 9280 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9281 if (ret != CMD_SUCCESS) {
9282 return ret;
9283 }
ddb5b488
PZ
9284 }
9285
69b07479
DS
9286 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9287 if (!dodir[dir])
ddb5b488 9288 continue;
ddb5b488 9289
69b07479 9290 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9291
69b07479
DS
9292 if (yes) {
9293 if (bgp->vpn_policy[afi].rtlist[dir])
9294 ecommunity_free(
9295 &bgp->vpn_policy[afi].rtlist[dir]);
9296 bgp->vpn_policy[afi].rtlist[dir] =
9297 ecommunity_dup(ecom);
9298 } else {
9299 if (bgp->vpn_policy[afi].rtlist[dir])
9300 ecommunity_free(
9301 &bgp->vpn_policy[afi].rtlist[dir]);
9302 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9303 }
69b07479
DS
9304
9305 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9306 }
69b07479 9307
d555f3e9
PZ
9308 if (ecom)
9309 ecommunity_free(&ecom);
ddb5b488
PZ
9310
9311 return CMD_SUCCESS;
9312}
9313
b9c7bc5a
PZ
9314ALIAS (af_rt_vpn_imexport,
9315 af_no_rt_vpn_imexport_cmd,
9316 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9317 NO_STR
9318 "Specify route target list\n"
b9c7bc5a
PZ
9319 "Specify route target list\n"
9320 "Between current address-family and vpn\n"
9321 "For routes leaked from vpn to current address-family\n"
9322 "For routes leaked from current address-family to vpn\n"
9323 "both import and export\n")
9324
37a87b8f 9325DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9326 af_route_map_vpn_imexport_cmd,
9327/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9328 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9329 NO_STR
ddb5b488 9330 "Specify route map\n"
b9c7bc5a
PZ
9331 "Between current address-family and vpn\n"
9332 "For routes leaked from vpn to current address-family\n"
9333 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9334 "name of route-map\n")
9335{
37a87b8f 9336 char base_xpath[XPATH_MAXLEN];
ddb5b488 9337 afi_t afi;
37a87b8f 9338 safi_t safi;
ddb5b488 9339 int idx = 0;
ddb5b488 9340
37a87b8f
CS
9341 afi = bgp_node_afi(vty);
9342 safi = bgp_node_safi(vty);
ddb5b488 9343
37a87b8f
CS
9344 snprintf(
9345 base_xpath, sizeof(base_xpath),
9346 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9347 yang_afi_safi_value2identity(afi, safi),
9348 bgp_afi_safi_get_container_str(afi, safi));
9349
9350 if (argv_find(argv, argc, "no", &idx)) {
9351 if (!strcmp(direction_str, "import"))
9352 nb_cli_enqueue_change(vty, "./rmap-import",
9353 NB_OP_DESTROY, NULL);
9354 else if (!strcmp(direction_str, "export"))
9355 nb_cli_enqueue_change(vty, "./rmap-export",
9356 NB_OP_DESTROY, NULL);
9357 } else {
9358 if (!strcmp(direction_str, "import"))
9359 nb_cli_enqueue_change(vty, "./rmap-import",
9360 NB_OP_MODIFY, rmap_str);
9361 if (!strcmp(direction_str, "export"))
9362 nb_cli_enqueue_change(vty, "./rmap-export",
9363 NB_OP_MODIFY, rmap_str);
9364 }
9365 return nb_cli_apply_changes(vty, base_xpath);
9366}
ddb5b488 9367
37a87b8f
CS
9368void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9369 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9370{
9371 int indent = 2;
ddb5b488 9372
37a87b8f
CS
9373 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9374 yang_dnode_get_string(dnode, NULL));
9375}
69b07479 9376
37a87b8f
CS
9377void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9378 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9379{
9380 int indent = 2;
ddb5b488 9381
37a87b8f
CS
9382 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9383 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9384}
9385
b9c7bc5a
PZ
9386ALIAS (af_route_map_vpn_imexport,
9387 af_no_route_map_vpn_imexport_cmd,
9388 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9389 NO_STR
9390 "Specify route map\n"
b9c7bc5a
PZ
9391 "Between current address-family and vpn\n"
9392 "For routes leaked from vpn to current address-family\n"
9393 "For routes leaked from current address-family to vpn\n")
9394
bb4f6190 9395DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9396 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9397 "Import routes from another VRF\n"
9398 "Vrf routes being filtered\n"
9399 "Specify route map\n"
9400 "name of route-map\n")
9401{
9402 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
9403 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9404 afi_t afi;
bb4f6190
DS
9405 struct bgp *bgp_default;
9406
0ca70ba5 9407 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9408 if (afi == AFI_MAX)
9409 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9410
9411 bgp_default = bgp_get_default();
9412 if (!bgp_default) {
9413 int32_t ret;
9414 as_t as = bgp->as;
9415
9416 /* Auto-create assuming the same AS */
5d5393b9
DL
9417 ret = bgp_get_vty(&bgp_default, &as, NULL,
9418 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9419
9420 if (ret) {
9421 vty_out(vty,
9422 "VRF default is not configured as a bgp instance\n");
9423 return CMD_WARNING;
9424 }
9425 }
9426
69b07479 9427 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9428
ae6a6fb4
DS
9429 if (bgp->vpn_policy[afi].rmap_name[dir])
9430 XFREE(MTYPE_ROUTE_MAP_NAME,
9431 bgp->vpn_policy[afi].rmap_name[dir]);
9432 bgp->vpn_policy[afi].rmap_name[dir] =
9433 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9434 bgp->vpn_policy[afi].rmap[dir] =
9435 route_map_lookup_warn_noexist(vty, rmap_str);
9436 if (!bgp->vpn_policy[afi].rmap[dir])
9437 return CMD_SUCCESS;
9438
9439 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9440 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9441
69b07479
DS
9442 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9443
bb4f6190
DS
9444 return CMD_SUCCESS;
9445}
9446
ae6a6fb4
DS
9447DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9448 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9449 NO_STR
9450 "Import routes from another VRF\n"
9451 "Vrf routes being filtered\n"
ae6a6fb4
DS
9452 "Specify route map\n"
9453 "name of route-map\n")
9454{
9455 VTY_DECLVAR_CONTEXT(bgp, bgp);
9456 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9457 afi_t afi;
9458
9459 afi = vpn_policy_getafi(vty, bgp, true);
9460 if (afi == AFI_MAX)
9461 return CMD_WARNING_CONFIG_FAILED;
9462
9463 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9464
9465 if (bgp->vpn_policy[afi].rmap_name[dir])
9466 XFREE(MTYPE_ROUTE_MAP_NAME,
9467 bgp->vpn_policy[afi].rmap_name[dir]);
9468 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9469 bgp->vpn_policy[afi].rmap[dir] = NULL;
9470
9471 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9472 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9473 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9474
9475 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9476
9477 return CMD_SUCCESS;
9478}
bb4f6190 9479
37a87b8f
CS
9480DEFPY_YANG(bgp_imexport_vrf,
9481 bgp_imexport_vrf_cmd,
9482 "[no] import vrf VIEWVRFNAME$import_name",
9483 NO_STR
9484 "Import routes from another VRF\n"
9485 "VRF to import from\n"
9486 "The name of the VRF\n")
12a844a5 9487{
37a87b8f 9488 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
9489 safi_t safi;
9490 afi_t afi;
37a87b8f 9491 int32_t idx = 0;
12a844a5 9492
867f0cca 9493 if (import_name == NULL) {
9494 vty_out(vty, "%% Missing import name\n");
9495 return CMD_WARNING;
9496 }
9497
ae6a6fb4
DS
9498 if (strcmp(import_name, "route-map") == 0) {
9499 vty_out(vty, "%% Must include route-map name\n");
9500 return CMD_WARNING;
9501 }
9502
37a87b8f 9503 afi = bgp_node_afi(vty);
12a844a5
DS
9504 safi = bgp_node_safi(vty);
9505
37a87b8f
CS
9506 snprintf(
9507 base_xpath, sizeof(base_xpath),
9508 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9509 yang_afi_safi_value2identity(afi, safi),
9510 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 9511
37a87b8f
CS
9512 if (argv_find(argv, argc, "no", &idx))
9513 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9514 else
9515 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 9516
37a87b8f
CS
9517 return nb_cli_apply_changes(vty, base_xpath);
9518}
12a844a5 9519
37a87b8f
CS
9520void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9521 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9522{
9523 vty_out(vty, " import vrf %s\n",
9524 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
9525}
9526
b9c7bc5a 9527/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 9528DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
9529 bgp_imexport_vpn_cmd,
9530 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9531 NO_STR
9532 "Import routes to this address-family\n"
9533 "Export routes from this address-family\n"
9534 "to/from default instance VPN RIB\n")
ddb5b488 9535{
37a87b8f 9536 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 9537 safi_t safi;
37a87b8f
CS
9538 afi_t afi;
9539 int32_t idx = 0;
ddb5b488 9540
b9c7bc5a
PZ
9541 afi = bgp_node_afi(vty);
9542 safi = bgp_node_safi(vty);
ddb5b488 9543
b9c7bc5a 9544 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
9545 snprintf(
9546 base_xpath, sizeof(base_xpath),
9547 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9548 yang_afi_safi_value2identity(afi, safi),
9549 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 9550 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
9551 snprintf(
9552 base_xpath, sizeof(base_xpath),
9553 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9554 yang_afi_safi_value2identity(afi, safi),
9555 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
9556 } else {
9557 vty_out(vty, "%% unknown direction %s\n", direction_str);
9558 return CMD_WARNING_CONFIG_FAILED;
9559 }
9560
37a87b8f
CS
9561 if (argv_find(argv, argc, "no", &idx))
9562 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9563 else
9564 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 9565
37a87b8f
CS
9566 return nb_cli_apply_changes(vty, base_xpath);
9567}
ddb5b488 9568
37a87b8f
CS
9569void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9570 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9571{
9572 if (yang_dnode_get_bool(dnode, NULL))
9573 vty_out(vty, " import vpn\n");
9574}
9575
9576void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9577 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9578{
9579 if (yang_dnode_get_bool(dnode, NULL))
9580 vty_out(vty, " export vpn\n");
ddb5b488
PZ
9581}
9582
301ad80a
PG
9583DEFPY (af_routetarget_import,
9584 af_routetarget_import_cmd,
9a659715 9585 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9586 NO_STR
9587 "Specify route target list\n"
9588 "Specify route target list\n"
9a659715
PG
9589 "Specify route target list\n"
9590 "Specify route target list\n"
301ad80a
PG
9591 "Flow-spec redirect type route target\n"
9592 "Import routes to this address-family\n"
9a659715 9593 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9594{
9595 VTY_DECLVAR_CONTEXT(bgp, bgp);
9596 int ret;
9597 struct ecommunity *ecom = NULL;
301ad80a 9598 afi_t afi;
9a659715 9599 int idx = 0, idx_unused = 0;
c6423c31
PG
9600 bool yes = true;
9601 bool rt6 = false;
301ad80a
PG
9602
9603 if (argv_find(argv, argc, "no", &idx))
c6423c31 9604 yes = false;
301ad80a 9605
9a659715
PG
9606 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9607 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9608 rt6 = true;
301ad80a 9609
0ca70ba5 9610 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9611 if (afi == AFI_MAX)
9612 return CMD_WARNING_CONFIG_FAILED;
9613
9a659715
PG
9614 if (rt6 && afi != AFI_IP6)
9615 return CMD_WARNING_CONFIG_FAILED;
9616
301ad80a
PG
9617 if (yes) {
9618 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9619 vty_out(vty, "%% Missing RTLIST\n");
9620 return CMD_WARNING_CONFIG_FAILED;
9621 }
9a659715 9622 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9623 if (ret != CMD_SUCCESS)
9624 return ret;
9625 }
69b07479
DS
9626
9627 if (yes) {
9628 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9629 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9630 .import_redirect_rtlist);
69b07479
DS
9631 bgp->vpn_policy[afi].import_redirect_rtlist =
9632 ecommunity_dup(ecom);
9633 } else {
9634 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9635 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9636 .import_redirect_rtlist);
69b07479 9637 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9638 }
69b07479 9639
301ad80a
PG
9640 if (ecom)
9641 ecommunity_free(&ecom);
9642
9643 return CMD_SUCCESS;
9644}
9645
37a87b8f
CS
9646void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9647 struct lyd_node *dnode,
9648 bool show_defaults)
9649{
9650 const char *af_name;
9651 afi_t afi;
9652 safi_t safi;
9653
9654 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9655 yang_afi_safi_identity2value(af_name, &afi, &safi);
9656
9657 vty_out(vty, " !\n address-family ");
9658 if (afi == AFI_IP) {
9659 if (safi == SAFI_UNICAST)
9660 vty_out(vty, "ipv4 unicast");
9661 else if (safi == SAFI_LABELED_UNICAST)
9662 vty_out(vty, "ipv4 labeled-unicast");
9663 else if (safi == SAFI_MULTICAST)
9664 vty_out(vty, "ipv4 multicast");
9665 else if (safi == SAFI_MPLS_VPN)
9666 vty_out(vty, "ipv4 vpn");
9667 else if (safi == SAFI_ENCAP)
9668 vty_out(vty, "ipv4 encap");
9669 else if (safi == SAFI_FLOWSPEC)
9670 vty_out(vty, "ipv4 flowspec");
9671 } else if (afi == AFI_IP6) {
9672 if (safi == SAFI_UNICAST)
9673 vty_out(vty, "ipv6 unicast");
9674 else if (safi == SAFI_LABELED_UNICAST)
9675 vty_out(vty, "ipv6 labeled-unicast");
9676 else if (safi == SAFI_MULTICAST)
9677 vty_out(vty, "ipv6 multicast");
9678 else if (safi == SAFI_MPLS_VPN)
9679 vty_out(vty, "ipv6 vpn");
9680 else if (safi == SAFI_ENCAP)
9681 vty_out(vty, "ipv6 encap");
9682 else if (safi == SAFI_FLOWSPEC)
9683 vty_out(vty, "ipv6 flowspec");
9684 } else if (afi == AFI_L2VPN) {
9685 if (safi == SAFI_EVPN)
9686 vty_out(vty, "l2vpn evpn");
9687 }
9688 vty_out(vty, "\n");
9689}
9690
505e5056 9691DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9692 address_family_ipv4_safi_cmd,
9693 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9694 "Enter Address Family command mode\n"
9695 "Address Family\n"
9696 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9697{
f51bae9c 9698
37a87b8f
CS
9699 safi_t safi = SAFI_UNICAST;
9700 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9701 const char *vrf_name = NULL;
9702
d62a17ae 9703 if (argc == 3) {
37a87b8f
CS
9704 safi = bgp_vty_safi_from_str(argv[2]->text);
9705
9706 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9707 VTY_CURR_XPATH);
9708 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9709 "control-plane-protocol");
9710 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9711
9712 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9713 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9714 && safi != SAFI_EVPN) {
31947174
MK
9715 vty_out(vty,
9716 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9717 return CMD_WARNING_CONFIG_FAILED;
9718 }
37a87b8f
CS
9719 }
9720 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 9721
d62a17ae 9722 return CMD_SUCCESS;
718e3744 9723}
9724
505e5056 9725DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9726 address_family_ipv6_safi_cmd,
9727 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9728 "Enter Address Family command mode\n"
9729 "Address Family\n"
9730 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9731{
37a87b8f
CS
9732 safi_t safi = SAFI_UNICAST;
9733 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9734 const char *vrf_name = NULL;
9735
d62a17ae 9736 if (argc == 3) {
37a87b8f
CS
9737 safi = bgp_vty_safi_from_str(argv[2]->text);
9738 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9739 VTY_CURR_XPATH);
9740 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9741 "control-plane-protocol");
9742 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9743
9744 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9745 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9746 && safi != SAFI_EVPN) {
31947174
MK
9747 vty_out(vty,
9748 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9749 return CMD_WARNING_CONFIG_FAILED;
9750 }
37a87b8f
CS
9751 }
9752 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 9753
d62a17ae 9754 return CMD_SUCCESS;
25ffbdc1 9755}
718e3744 9756
d6902373 9757#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9758DEFUN_NOSH (address_family_vpnv4,
718e3744 9759 address_family_vpnv4_cmd,
8334fd5a 9760 "address-family vpnv4 [unicast]",
718e3744 9761 "Enter Address Family command mode\n"
8c3deaae 9762 "Address Family\n"
3a2d747c 9763 "Address Family modifier\n")
718e3744 9764{
d62a17ae 9765 vty->node = BGP_VPNV4_NODE;
9766 return CMD_SUCCESS;
718e3744 9767}
9768
505e5056 9769DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9770 address_family_vpnv6_cmd,
8334fd5a 9771 "address-family vpnv6 [unicast]",
8ecd3266 9772 "Enter Address Family command mode\n"
8c3deaae 9773 "Address Family\n"
3a2d747c 9774 "Address Family modifier\n")
8ecd3266 9775{
d62a17ae 9776 vty->node = BGP_VPNV6_NODE;
9777 return CMD_SUCCESS;
8ecd3266 9778}
64e4a6c5 9779#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9780
505e5056 9781DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9782 address_family_evpn_cmd,
7111c1a0 9783 "address-family l2vpn evpn",
4e0b7b6d 9784 "Enter Address Family command mode\n"
7111c1a0
QY
9785 "Address Family\n"
9786 "Address Family modifier\n")
4e0b7b6d 9787{
2131d5cf 9788 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9789 vty->node = BGP_EVPN_NODE;
9790 return CMD_SUCCESS;
4e0b7b6d
PG
9791}
9792
505e5056 9793DEFUN_NOSH (exit_address_family,
718e3744 9794 exit_address_family_cmd,
9795 "exit-address-family",
9796 "Exit from Address Family configuration mode\n")
9797{
d62a17ae 9798 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9799 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9800 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9801 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9802 || vty->node == BGP_EVPN_NODE
9803 || vty->node == BGP_FLOWSPECV4_NODE
9804 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9805 vty->node = BGP_NODE;
9806 return CMD_SUCCESS;
718e3744 9807}
6b0655a2 9808
37a87b8f
CS
9809void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9810 struct lyd_node *dnode
9811 __attribute__((__unused__)))
9812{
9813 vty_out(vty, " exit-address-family\n");
9814}
9815
8ad7271d 9816/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9817static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9818 const char *ip_str, afi_t afi, safi_t safi,
9819 struct prefix_rd *prd)
9820{
9821 int ret;
9822 struct prefix match;
9bcb3eef
DS
9823 struct bgp_dest *dest;
9824 struct bgp_dest *rm;
d62a17ae 9825 struct bgp *bgp;
9826 struct bgp_table *table;
9827 struct bgp_table *rib;
9828
9829 /* BGP structure lookup. */
9830 if (view_name) {
9831 bgp = bgp_lookup_by_name(view_name);
9832 if (bgp == NULL) {
9833 vty_out(vty, "%% Can't find BGP instance %s\n",
9834 view_name);
9835 return CMD_WARNING;
9836 }
9837 } else {
9838 bgp = bgp_get_default();
9839 if (bgp == NULL) {
9840 vty_out(vty, "%% No BGP process is configured\n");
9841 return CMD_WARNING;
9842 }
9843 }
9844
9845 /* Check IP address argument. */
9846 ret = str2prefix(ip_str, &match);
9847 if (!ret) {
9848 vty_out(vty, "%% address is malformed\n");
9849 return CMD_WARNING;
9850 }
9851
9852 match.family = afi2family(afi);
9853 rib = bgp->rib[afi][safi];
9854
9855 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9856 for (dest = bgp_table_top(rib); dest;
9857 dest = bgp_route_next(dest)) {
9858 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9859
9bcb3eef 9860 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9861 continue;
9862
9bcb3eef 9863 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9864 if (table == NULL)
9865 continue;
9866
9867 if ((rm = bgp_node_match(table, &match)) != NULL) {
9868 const struct prefix *rm_p =
9bcb3eef 9869 bgp_dest_get_prefix(rm);
b54892e0
DS
9870
9871 if (rm_p->prefixlen == match.prefixlen) {
9872 SET_FLAG(rm->flags,
9873 BGP_NODE_USER_CLEAR);
9874 bgp_process(bgp, rm, afi, safi);
d62a17ae 9875 }
9bcb3eef 9876 bgp_dest_unlock_node(rm);
d62a17ae 9877 }
9878 }
9879 } else {
9bcb3eef
DS
9880 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9881 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9882
9bcb3eef
DS
9883 if (dest_p->prefixlen == match.prefixlen) {
9884 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9885 bgp_process(bgp, dest, afi, safi);
d62a17ae 9886 }
9bcb3eef 9887 bgp_dest_unlock_node(dest);
d62a17ae 9888 }
9889 }
9890
9891 return CMD_SUCCESS;
8ad7271d
DS
9892}
9893
b09b5ae0 9894/* one clear bgp command to rule them all */
718e3744 9895DEFUN (clear_ip_bgp_all,
9896 clear_ip_bgp_all_cmd,
453c92f6 9897 "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 9898 CLEAR_STR
9899 IP_STR
9900 BGP_STR
838758ac 9901 BGP_INSTANCE_HELP_STR
510afcd6 9902 BGP_AFI_HELP_STR
fd5e7b70 9903 "Address Family\n"
510afcd6 9904 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9905 "Address Family modifier\n"
b09b5ae0 9906 "Clear all peers\n"
453c92f6 9907 "BGP IPv4 neighbor to clear\n"
a80beece 9908 "BGP IPv6 neighbor to clear\n"
838758ac 9909 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9910 "Clear peers with the AS number\n"
9911 "Clear all external peers\n"
718e3744 9912 "Clear all members of peer-group\n"
b09b5ae0 9913 "BGP peer-group name\n"
b09b5ae0
DW
9914 BGP_SOFT_STR
9915 BGP_SOFT_IN_STR
b09b5ae0
DW
9916 BGP_SOFT_OUT_STR
9917 BGP_SOFT_IN_STR
9918 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9919 BGP_SOFT_OUT_STR)
718e3744 9920{
d62a17ae 9921 char *vrf = NULL;
9922
dc912615
DS
9923 afi_t afi = AFI_UNSPEC;
9924 safi_t safi = SAFI_UNSPEC;
d62a17ae 9925 enum clear_sort clr_sort = clear_peer;
9926 enum bgp_clear_type clr_type;
9927 char *clr_arg = NULL;
9928
9929 int idx = 0;
ff8a8a7a
CS
9930 char errmsg[BUFSIZ] = {'\0'};
9931 int ret;
d62a17ae 9932
9933 /* clear [ip] bgp */
9934 if (argv_find(argv, argc, "ip", &idx))
9935 afi = AFI_IP;
9936
9a8bdf1c
PG
9937 /* [<vrf> VIEWVRFNAME] */
9938 if (argv_find(argv, argc, "vrf", &idx)) {
9939 vrf = argv[idx + 1]->arg;
9940 idx += 2;
9941 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9942 vrf = NULL;
9943 } else if (argv_find(argv, argc, "view", &idx)) {
9944 /* [<view> VIEWVRFNAME] */
d62a17ae 9945 vrf = argv[idx + 1]->arg;
9946 idx += 2;
9947 }
d62a17ae 9948 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9949 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9950 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9951
d7b9898c 9952 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9953 if (argv_find(argv, argc, "*", &idx)) {
9954 clr_sort = clear_all;
9955 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9956 clr_sort = clear_peer;
9957 clr_arg = argv[idx]->arg;
9958 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9959 clr_sort = clear_peer;
9960 clr_arg = argv[idx]->arg;
9961 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9962 clr_sort = clear_group;
9963 idx++;
9964 clr_arg = argv[idx]->arg;
d7b9898c 9965 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9966 clr_sort = clear_peer;
9967 clr_arg = argv[idx]->arg;
8fa7d444
DS
9968 } else if (argv_find(argv, argc, "WORD", &idx)) {
9969 clr_sort = clear_peer;
9970 clr_arg = argv[idx]->arg;
d62a17ae 9971 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9972 clr_sort = clear_as;
9973 clr_arg = argv[idx]->arg;
9974 } else if (argv_find(argv, argc, "external", &idx)) {
9975 clr_sort = clear_external;
9976 }
9977
9978 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9979 if (argv_find(argv, argc, "soft", &idx)) {
9980 if (argv_find(argv, argc, "in", &idx)
9981 || argv_find(argv, argc, "out", &idx))
9982 clr_type = strmatch(argv[idx]->text, "in")
9983 ? BGP_CLEAR_SOFT_IN
9984 : BGP_CLEAR_SOFT_OUT;
9985 else
9986 clr_type = BGP_CLEAR_SOFT_BOTH;
9987 } else if (argv_find(argv, argc, "in", &idx)) {
9988 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9989 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9990 : BGP_CLEAR_SOFT_IN;
9991 } else if (argv_find(argv, argc, "out", &idx)) {
9992 clr_type = BGP_CLEAR_SOFT_OUT;
9993 } else
9994 clr_type = BGP_CLEAR_SOFT_NONE;
9995
ff8a8a7a
CS
9996 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9997 sizeof(errmsg));
9998 if (ret != NB_OK)
9999 vty_out(vty, "Error description: %s\n", errmsg);
10000
10001 return ret;
838758ac 10002}
01080f7c 10003
8ad7271d
DS
10004DEFUN (clear_ip_bgp_prefix,
10005 clear_ip_bgp_prefix_cmd,
18c57037 10006 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10007 CLEAR_STR
10008 IP_STR
10009 BGP_STR
838758ac 10010 BGP_INSTANCE_HELP_STR
8ad7271d 10011 "Clear bestpath and re-advertise\n"
0c7b1b01 10012 "IPv4 prefix\n")
8ad7271d 10013{
d62a17ae 10014 char *vrf = NULL;
10015 char *prefix = NULL;
8ad7271d 10016
d62a17ae 10017 int idx = 0;
01080f7c 10018
d62a17ae 10019 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10020 if (argv_find(argv, argc, "vrf", &idx)) {
10021 vrf = argv[idx + 1]->arg;
10022 idx += 2;
10023 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10024 vrf = NULL;
10025 } else if (argv_find(argv, argc, "view", &idx)) {
10026 /* [<view> VIEWVRFNAME] */
10027 vrf = argv[idx + 1]->arg;
10028 idx += 2;
10029 }
0c7b1b01 10030
d62a17ae 10031 prefix = argv[argc - 1]->arg;
8ad7271d 10032
d62a17ae 10033 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10034}
8ad7271d 10035
b09b5ae0
DW
10036DEFUN (clear_bgp_ipv6_safi_prefix,
10037 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10038 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10039 CLEAR_STR
3a2d747c 10040 IP_STR
718e3744 10041 BGP_STR
8c3deaae 10042 "Address Family\n"
46f296b4 10043 BGP_SAFI_HELP_STR
b09b5ae0 10044 "Clear bestpath and re-advertise\n"
0c7b1b01 10045 "IPv6 prefix\n")
718e3744 10046{
9b475e76
PG
10047 int idx_safi = 0;
10048 int idx_ipv6_prefix = 0;
10049 safi_t safi = SAFI_UNICAST;
10050 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10051 argv[idx_ipv6_prefix]->arg : NULL;
10052
10053 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10054 return bgp_clear_prefix(
9b475e76
PG
10055 vty, NULL, prefix, AFI_IP6,
10056 safi, NULL);
838758ac 10057}
01080f7c 10058
b09b5ae0
DW
10059DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10060 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10061 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10062 CLEAR_STR
3a2d747c 10063 IP_STR
718e3744 10064 BGP_STR
838758ac 10065 BGP_INSTANCE_HELP_STR
8c3deaae 10066 "Address Family\n"
46f296b4 10067 BGP_SAFI_HELP_STR
b09b5ae0 10068 "Clear bestpath and re-advertise\n"
0c7b1b01 10069 "IPv6 prefix\n")
718e3744 10070{
9b475e76 10071 int idx_safi = 0;
9a8bdf1c 10072 int idx_vrfview = 0;
9b475e76
PG
10073 int idx_ipv6_prefix = 0;
10074 safi_t safi = SAFI_UNICAST;
10075 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10076 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10077 char *vrfview = NULL;
9b475e76 10078
9a8bdf1c
PG
10079 /* [<view|vrf> VIEWVRFNAME] */
10080 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10081 vrfview = argv[idx_vrfview + 1]->arg;
10082 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10083 vrfview = NULL;
10084 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10085 /* [<view> VIEWVRFNAME] */
10086 vrfview = argv[idx_vrfview + 1]->arg;
10087 }
9b475e76
PG
10088 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10089
d62a17ae 10090 return bgp_clear_prefix(
9b475e76
PG
10091 vty, vrfview, prefix,
10092 AFI_IP6, safi, NULL);
718e3744 10093}
10094
b09b5ae0
DW
10095DEFUN (show_bgp_views,
10096 show_bgp_views_cmd,
d6e3c605 10097 "show [ip] bgp views",
b09b5ae0 10098 SHOW_STR
d6e3c605 10099 IP_STR
01080f7c 10100 BGP_STR
b09b5ae0 10101 "Show the defined BGP views\n")
01080f7c 10102{
d62a17ae 10103 struct list *inst = bm->bgp;
10104 struct listnode *node;
10105 struct bgp *bgp;
01080f7c 10106
d62a17ae 10107 vty_out(vty, "Defined BGP views:\n");
10108 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10109 /* Skip VRFs. */
10110 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10111 continue;
10112 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10113 bgp->as);
10114 }
e52702f2 10115
d62a17ae 10116 return CMD_SUCCESS;
e0081f70
ML
10117}
10118
8386ac43 10119DEFUN (show_bgp_vrfs,
10120 show_bgp_vrfs_cmd,
d6e3c605 10121 "show [ip] bgp vrfs [json]",
8386ac43 10122 SHOW_STR
d6e3c605 10123 IP_STR
8386ac43 10124 BGP_STR
10125 "Show BGP VRFs\n"
9973d184 10126 JSON_STR)
8386ac43 10127{
fe1dc5a3 10128 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10129 struct list *inst = bm->bgp;
10130 struct listnode *node;
10131 struct bgp *bgp;
9f049418 10132 bool uj = use_json(argc, argv);
d62a17ae 10133 json_object *json = NULL;
10134 json_object *json_vrfs = NULL;
10135 int count = 0;
d62a17ae 10136
d62a17ae 10137 if (uj) {
10138 json = json_object_new_object();
10139 json_vrfs = json_object_new_object();
10140 }
10141
10142 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10143 const char *name, *type;
10144 struct peer *peer;
7fe96307 10145 struct listnode *node2, *nnode2;
d62a17ae 10146 int peers_cfg, peers_estb;
10147 json_object *json_vrf = NULL;
d62a17ae 10148
10149 /* Skip Views. */
10150 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10151 continue;
10152
10153 count++;
efb4077a 10154 if (!uj && count == 1) {
fe1dc5a3 10155 vty_out(vty,
efb4077a 10156 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10157 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10158 "#PeersEstb", "Name");
10159 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10160 "L3-VNI", "RouterMAC", "Interface");
10161 }
d62a17ae 10162
10163 peers_cfg = peers_estb = 0;
10164 if (uj)
10165 json_vrf = json_object_new_object();
10166
10167
7fe96307 10168 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10169 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10170 continue;
10171 peers_cfg++;
10172 if (peer->status == Established)
10173 peers_estb++;
10174 }
10175
10176 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10177 name = VRF_DEFAULT_NAME;
d62a17ae 10178 type = "DFLT";
10179 } else {
10180 name = bgp->name;
10181 type = "VRF";
10182 }
10183
a8bf7d9c 10184
d62a17ae 10185 if (uj) {
a4d82a8a
PZ
10186 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10187 ? -1
10188 : (int64_t)bgp->vrf_id;
23d0a753
DA
10189 char buf[BUFSIZ] = {0};
10190
d62a17ae 10191 json_object_string_add(json_vrf, "type", type);
10192 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10193 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
10194 inet_ntop(AF_INET,
10195 &bgp->router_id, buf,
10196 sizeof(buf)));
d62a17ae 10197 json_object_int_add(json_vrf, "numConfiguredPeers",
10198 peers_cfg);
10199 json_object_int_add(json_vrf, "numEstablishedPeers",
10200 peers_estb);
10201
fe1dc5a3 10202 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10203 json_object_string_add(
10204 json_vrf, "rmac",
10205 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10206 json_object_string_add(json_vrf, "interface",
10207 ifindex2ifname(bgp->l3vni_svi_ifindex,
10208 bgp->vrf_id));
d62a17ae 10209 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10210 } else {
23d0a753 10211 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10212 type,
10213 bgp->vrf_id == VRF_UNKNOWN ? -1
10214 : (int)bgp->vrf_id,
23d0a753 10215 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10216 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10217 bgp->l3vni,
10218 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10219 ifindex2ifname(bgp->l3vni_svi_ifindex,
10220 bgp->vrf_id));
10221 }
d62a17ae 10222 }
10223
10224 if (uj) {
10225 json_object_object_add(json, "vrfs", json_vrfs);
10226
10227 json_object_int_add(json, "totalVrfs", count);
10228
996c9314
LB
10229 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10230 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10231 json_object_free(json);
10232 } else {
10233 if (count)
10234 vty_out(vty,
10235 "\nTotal number of VRFs (including default): %d\n",
10236 count);
10237 }
10238
10239 return CMD_SUCCESS;
8386ac43 10240}
10241
48ecf8f5
DS
10242DEFUN (show_bgp_mac_hash,
10243 show_bgp_mac_hash_cmd,
10244 "show bgp mac hash",
10245 SHOW_STR
10246 BGP_STR
10247 "Mac Address\n"
10248 "Mac Address database\n")
10249{
10250 bgp_mac_dump_table(vty);
10251
10252 return CMD_SUCCESS;
10253}
acf71666 10254
e3b78da8 10255static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10256{
0291c246 10257 struct vty *vty = (struct vty *)args;
e3b78da8 10258 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10259
23d0a753 10260 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10261}
10262
10263static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10264{
10265 vty_out(vty, "self nexthop database:\n");
af97a18b 10266 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10267
10268 vty_out(vty, "Tunnel-ip database:\n");
10269 hash_iterate(bgp->tip_hash,
e3b78da8 10270 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10271 vty);
10272}
10273
15c81ca4
DS
10274DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10275 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10276 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10277 "martian next-hops\n"
10278 "martian next-hop database\n")
acf71666 10279{
0291c246 10280 struct bgp *bgp = NULL;
15c81ca4 10281 int idx = 0;
9a8bdf1c
PG
10282 char *name = NULL;
10283
10284 /* [<vrf> VIEWVRFNAME] */
10285 if (argv_find(argv, argc, "vrf", &idx)) {
10286 name = argv[idx + 1]->arg;
10287 if (name && strmatch(name, VRF_DEFAULT_NAME))
10288 name = NULL;
10289 } else if (argv_find(argv, argc, "view", &idx))
10290 /* [<view> VIEWVRFNAME] */
10291 name = argv[idx + 1]->arg;
10292 if (name)
10293 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10294 else
10295 bgp = bgp_get_default();
acf71666 10296
acf71666
MK
10297 if (!bgp) {
10298 vty_out(vty, "%% No BGP process is configured\n");
10299 return CMD_WARNING;
10300 }
10301 bgp_show_martian_nexthops(vty, bgp);
10302
10303 return CMD_SUCCESS;
10304}
10305
f412b39a 10306DEFUN (show_bgp_memory,
4bf6a362 10307 show_bgp_memory_cmd,
7fa12b13 10308 "show [ip] bgp memory",
4bf6a362 10309 SHOW_STR
3a2d747c 10310 IP_STR
4bf6a362
PJ
10311 BGP_STR
10312 "Global BGP memory statistics\n")
10313{
d62a17ae 10314 char memstrbuf[MTYPE_MEMSTR_LEN];
10315 unsigned long count;
10316
10317 /* RIB related usage stats */
10318 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10319 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10320 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10321 count * sizeof(struct bgp_dest)));
d62a17ae 10322
10323 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10324 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10325 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10326 count * sizeof(struct bgp_path_info)));
d62a17ae 10327 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10328 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10329 count,
4b7e6066
DS
10330 mtype_memstr(
10331 memstrbuf, sizeof(memstrbuf),
10332 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10333
10334 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10335 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10336 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10337 count * sizeof(struct bgp_static)));
10338
10339 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10340 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10341 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10342 count * sizeof(struct bpacket)));
10343
10344 /* Adj-In/Out */
10345 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10346 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10347 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10348 count * sizeof(struct bgp_adj_in)));
10349 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10350 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10351 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10352 count * sizeof(struct bgp_adj_out)));
10353
10354 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10355 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10356 count,
10357 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10358 count * sizeof(struct bgp_nexthop_cache)));
10359
10360 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10361 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10362 count,
10363 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10364 count * sizeof(struct bgp_damp_info)));
10365
10366 /* Attributes */
10367 count = attr_count();
10368 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10369 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10370 count * sizeof(struct attr)));
10371
10372 if ((count = attr_unknown_count()))
10373 vty_out(vty, "%ld unknown attributes\n", count);
10374
10375 /* AS_PATH attributes */
10376 count = aspath_count();
10377 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10378 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10379 count * sizeof(struct aspath)));
10380
10381 count = mtype_stats_alloc(MTYPE_AS_SEG);
10382 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10383 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10384 count * sizeof(struct assegment)));
10385
10386 /* Other attributes */
10387 if ((count = community_count()))
10388 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10389 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10390 count * sizeof(struct community)));
d62a17ae 10391 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10392 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10393 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10394 count * sizeof(struct ecommunity)));
d62a17ae 10395 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10396 vty_out(vty,
10397 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10398 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10399 count * sizeof(struct lcommunity)));
d62a17ae 10400
10401 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10402 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10403 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10404 count * sizeof(struct cluster_list)));
10405
10406 /* Peer related usage */
10407 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10408 vty_out(vty, "%ld peers, using %s of memory\n", count,
10409 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10410 count * sizeof(struct peer)));
10411
10412 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10413 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10414 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10415 count * sizeof(struct peer_group)));
10416
10417 /* Other */
d62a17ae 10418 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10419 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10420 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10421 count * sizeof(regex_t)));
d62a17ae 10422 return CMD_SUCCESS;
4bf6a362 10423}
fee0f4c6 10424
57a9c8a8
DS
10425static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10426{
10427 json_object *bestpath = json_object_new_object();
10428
892fedb6 10429 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10430 json_object_string_add(bestpath, "asPath", "ignore");
10431
892fedb6 10432 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10433 json_object_string_add(bestpath, "asPath", "confed");
10434
892fedb6
DA
10435 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10436 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10437 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10438 "as-set");
10439 else
a4d82a8a 10440 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10441 "true");
10442 } else
a4d82a8a 10443 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10444
892fedb6 10445 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10446 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10447 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10448 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10449 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10450 json_object_string_add(bestpath, "med", "confed");
892fedb6 10451 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10452 json_object_string_add(bestpath, "med",
10453 "missing-as-worst");
10454 else
10455 json_object_string_add(bestpath, "med", "true");
10456 }
10457
10458 json_object_object_add(json, "bestPath", bestpath);
10459}
10460
3577f1c5
DD
10461/* Print the error code/subcode for why the peer is down */
10462static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10463 json_object *json_peer, bool use_json)
10464{
10465 const char *code_str;
10466 const char *subcode_str;
10467
10468 if (use_json) {
10469 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10470 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10471 char errorcodesubcode_hexstr[5];
10472 char errorcodesubcode_str[256];
10473
10474 code_str = bgp_notify_code_str(peer->notify.code);
10475 subcode_str = bgp_notify_subcode_str(
10476 peer->notify.code,
10477 peer->notify.subcode);
10478
772270f3
QY
10479 snprintf(errorcodesubcode_hexstr,
10480 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10481 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10482 json_object_string_add(json_peer,
10483 "lastErrorCodeSubcode",
10484 errorcodesubcode_hexstr);
10485 snprintf(errorcodesubcode_str, 255, "%s%s",
10486 code_str, subcode_str);
10487 json_object_string_add(json_peer,
10488 "lastNotificationReason",
10489 errorcodesubcode_str);
10490 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10491 && peer->notify.code == BGP_NOTIFY_CEASE
10492 && (peer->notify.subcode
10493 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10494 || peer->notify.subcode
10495 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10496 && peer->notify.length) {
10497 char msgbuf[1024];
10498 const char *msg_str;
10499
10500 msg_str = bgp_notify_admin_message(
10501 msgbuf, sizeof(msgbuf),
10502 (uint8_t *)peer->notify.data,
10503 peer->notify.length);
10504 if (msg_str)
10505 json_object_string_add(
10506 json_peer,
10507 "lastShutdownDescription",
10508 msg_str);
10509 }
10510
c258527b 10511 }
3577f1c5
DD
10512 json_object_string_add(json_peer, "lastResetDueTo",
10513 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10514 json_object_int_add(json_peer, "lastResetCode",
10515 peer->last_reset);
3577f1c5
DD
10516 } else {
10517 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10518 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10519 code_str = bgp_notify_code_str(peer->notify.code);
10520 subcode_str =
10521 bgp_notify_subcode_str(peer->notify.code,
10522 peer->notify.subcode);
10523 vty_out(vty, " Notification %s (%s%s)\n",
10524 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10525 ? "sent"
10526 : "received",
10527 code_str, subcode_str);
10528 } else {
e91c24c8 10529 vty_out(vty, " %s\n",
3577f1c5
DD
10530 peer_down_str[(int)peer->last_reset]);
10531 }
10532 }
10533}
10534
10535static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10536 safi_t safi)
10537{
10538 return ((peer->status != Established) ||
10539 !peer->afc_recv[afi][safi]);
10540}
10541
10542static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10543 struct peer *peer, json_object *json_peer,
10544 int max_neighbor_width, bool use_json)
10545{
10546 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10547 int len;
10548
10549 if (use_json) {
10550 if (peer_dynamic_neighbor(peer))
10551 json_object_boolean_true_add(json_peer,
10552 "dynamicPeer");
10553 if (peer->hostname)
10554 json_object_string_add(json_peer, "hostname",
10555 peer->hostname);
10556
10557 if (peer->domainname)
10558 json_object_string_add(json_peer, "domainname",
10559 peer->domainname);
10560 json_object_int_add(json_peer, "connectionsEstablished",
10561 peer->established);
10562 json_object_int_add(json_peer, "connectionsDropped",
10563 peer->dropped);
10564 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10565 use_json, json_peer);
10566 if (peer->status == Established)
10567 json_object_string_add(json_peer, "lastResetDueTo",
10568 "AFI/SAFI Not Negotiated");
10569 else
10570 bgp_show_peer_reset(NULL, peer, json_peer, true);
10571 } else {
10572 dn_flag[1] = '\0';
10573 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10574 if (peer->hostname
892fedb6 10575 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10576 len = vty_out(vty, "%s%s(%s)", dn_flag,
10577 peer->hostname, peer->host);
10578 else
10579 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10580
10581 /* pad the neighbor column with spaces */
10582 if (len < max_neighbor_width)
10583 vty_out(vty, "%*s", max_neighbor_width - len,
10584 " ");
e91c24c8 10585 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10586 peer->dropped,
10587 peer_uptime(peer->uptime, timebuf,
10588 BGP_UPTIME_LEN, 0, NULL));
10589 if (peer->status == Established)
10590 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10591 else
10592 bgp_show_peer_reset(vty, peer, NULL,
10593 false);
10594 }
10595}
c258527b 10596
cb75bb31
DA
10597/* If the peer's description includes whitespaces
10598 * then return the first occurrence. Also strip description
10599 * to the given size if needed.
10600 */
10601static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10602{
10603 static char stripped[BUFSIZ];
10604 char *pnt;
10605 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10606
10607 pnt = strchr(desc, ' ');
10608 if (pnt)
10609 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10610 : size;
10611
10612 strlcpy(stripped, desc, len + 1);
10613
10614 return stripped;
10615}
3577f1c5 10616
718e3744 10617/* Show BGP peer's summary information. */
d62a17ae 10618static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
85eeb029 10619 uint8_t show_flags)
d62a17ae 10620{
10621 struct peer *peer;
10622 struct listnode *node, *nnode;
10623 unsigned int count = 0, dn_count = 0;
10624 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10625 char neighbor_buf[VTY_BUFSIZ];
10626 int neighbor_col_default_width = 16;
3577f1c5 10627 int len, failed_count = 0;
d62a17ae 10628 int max_neighbor_width = 0;
10629 int pfx_rcd_safi;
3c13337d 10630 json_object *json = NULL;
d62a17ae 10631 json_object *json_peer = NULL;
10632 json_object *json_peers = NULL;
50e05855 10633 struct peer_af *paf;
d3ada366 10634 struct bgp_filter *filter;
85eeb029
DA
10635 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10636 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10637 bool show_established =
10638 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10639 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
d62a17ae 10640
10641 /* labeled-unicast routes are installed in the unicast table so in order
10642 * to
10643 * display the correct PfxRcd value we must look at SAFI_UNICAST
10644 */
3577f1c5 10645
d62a17ae 10646 if (safi == SAFI_LABELED_UNICAST)
10647 pfx_rcd_safi = SAFI_UNICAST;
10648 else
10649 pfx_rcd_safi = safi;
10650
10651 if (use_json) {
3c13337d 10652 json = json_object_new_object();
d62a17ae 10653 json_peers = json_object_new_object();
3577f1c5
DD
10654 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10655 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10656 continue;
10657
10658 if (peer->afc[afi][safi]) {
10659 /* See if we have at least a single failed peer */
10660 if (bgp_has_peer_failed(peer, afi, safi))
10661 failed_count++;
10662 count++;
10663 }
10664 if (peer_dynamic_neighbor(peer))
10665 dn_count++;
10666 }
c258527b 10667
d62a17ae 10668 } else {
10669 /* Loop over all neighbors that will be displayed to determine
10670 * how many
10671 * characters are needed for the Neighbor column
10672 */
10673 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10674 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10675 continue;
10676
10677 if (peer->afc[afi][safi]) {
10678 memset(dn_flag, '\0', sizeof(dn_flag));
10679 if (peer_dynamic_neighbor(peer))
10680 dn_flag[0] = '*';
10681
10682 if (peer->hostname
892fedb6
DA
10683 && CHECK_FLAG(bgp->flags,
10684 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10685 snprintf(neighbor_buf,
10686 sizeof(neighbor_buf),
10687 "%s%s(%s) ", dn_flag,
10688 peer->hostname, peer->host);
d62a17ae 10689 else
772270f3
QY
10690 snprintf(neighbor_buf,
10691 sizeof(neighbor_buf), "%s%s ",
10692 dn_flag, peer->host);
d62a17ae 10693
10694 len = strlen(neighbor_buf);
10695
10696 if (len > max_neighbor_width)
10697 max_neighbor_width = len;
c258527b 10698
3577f1c5
DD
10699 /* See if we have at least a single failed peer */
10700 if (bgp_has_peer_failed(peer, afi, safi))
10701 failed_count++;
10702 count++;
d62a17ae 10703 }
10704 }
f933309e 10705
d62a17ae 10706 /* Originally we displayed the Neighbor column as 16
10707 * characters wide so make that the default
10708 */
10709 if (max_neighbor_width < neighbor_col_default_width)
10710 max_neighbor_width = neighbor_col_default_width;
10711 }
f933309e 10712
3577f1c5
DD
10713 if (show_failed && !failed_count) {
10714 if (use_json) {
10715 json_object_int_add(json, "failedPeersCount", 0);
10716 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10717 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
10718
10719 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10720 json, JSON_C_TO_STRING_PRETTY));
10721 json_object_free(json);
10722 } else {
10723 vty_out(vty, "%% No failed BGP neighbors found\n");
10724 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10725 }
10726 return CMD_SUCCESS;
10727 }
c258527b 10728
3577f1c5 10729 count = 0; /* Reset the value as its used again */
d62a17ae 10730 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10731 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10732 continue;
10733
ea47320b
DL
10734 if (!peer->afc[afi][safi])
10735 continue;
d62a17ae 10736
ea47320b
DL
10737 if (!count) {
10738 unsigned long ents;
10739 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10740 int64_t vrf_id_ui;
d62a17ae 10741
a4d82a8a
PZ
10742 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10743 ? -1
10744 : (int64_t)bgp->vrf_id;
ea47320b
DL
10745
10746 /* Usage summary and header */
10747 if (use_json) {
23d0a753
DA
10748 char buf[BUFSIZ] = {0};
10749
ea47320b
DL
10750 json_object_string_add(
10751 json, "routerId",
23d0a753
DA
10752 inet_ntop(AF_INET, &bgp->router_id, buf,
10753 sizeof(buf)));
60466a63
QY
10754 json_object_int_add(json, "as", bgp->as);
10755 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10756 json_object_string_add(
10757 json, "vrfName",
10758 (bgp->inst_type
10759 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10760 ? VRF_DEFAULT_NAME
ea47320b
DL
10761 : bgp->name);
10762 } else {
10763 vty_out(vty,
23d0a753
DA
10764 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10765 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10766 bgp->vrf_id == VRF_UNKNOWN
10767 ? -1
10768 : (int)bgp->vrf_id);
ea47320b
DL
10769 vty_out(vty, "\n");
10770 }
d62a17ae 10771
ea47320b 10772 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10773 if (use_json) {
ea47320b 10774 json_object_int_add(
60466a63 10775 json, "updateDelayLimit",
ea47320b 10776 bgp->v_update_delay);
d62a17ae 10777
ea47320b
DL
10778 if (bgp->v_update_delay
10779 != bgp->v_establish_wait)
d62a17ae 10780 json_object_int_add(
10781 json,
ea47320b
DL
10782 "updateDelayEstablishWait",
10783 bgp->v_establish_wait);
d62a17ae 10784
60466a63 10785 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10786 json_object_string_add(
10787 json,
10788 "updateDelayFirstNeighbor",
10789 bgp->update_delay_begin_time);
10790 json_object_boolean_true_add(
10791 json,
10792 "updateDelayInProgress");
10793 } else {
10794 if (bgp->update_delay_over) {
d62a17ae 10795 json_object_string_add(
10796 json,
10797 "updateDelayFirstNeighbor",
10798 bgp->update_delay_begin_time);
ea47320b 10799 json_object_string_add(
d62a17ae 10800 json,
ea47320b
DL
10801 "updateDelayBestpathResumed",
10802 bgp->update_delay_end_time);
10803 json_object_string_add(
d62a17ae 10804 json,
ea47320b
DL
10805 "updateDelayZebraUpdateResume",
10806 bgp->update_delay_zebra_resume_time);
10807 json_object_string_add(
10808 json,
10809 "updateDelayPeerUpdateResume",
10810 bgp->update_delay_peers_resume_time);
d62a17ae 10811 }
ea47320b
DL
10812 }
10813 } else {
10814 vty_out(vty,
10815 "Read-only mode update-delay limit: %d seconds\n",
10816 bgp->v_update_delay);
10817 if (bgp->v_update_delay
10818 != bgp->v_establish_wait)
d62a17ae 10819 vty_out(vty,
ea47320b
DL
10820 " Establish wait: %d seconds\n",
10821 bgp->v_establish_wait);
d62a17ae 10822
60466a63 10823 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10824 vty_out(vty,
10825 " First neighbor established: %s\n",
10826 bgp->update_delay_begin_time);
10827 vty_out(vty,
10828 " Delay in progress\n");
10829 } else {
10830 if (bgp->update_delay_over) {
d62a17ae 10831 vty_out(vty,
10832 " First neighbor established: %s\n",
10833 bgp->update_delay_begin_time);
10834 vty_out(vty,
ea47320b
DL
10835 " Best-paths resumed: %s\n",
10836 bgp->update_delay_end_time);
10837 vty_out(vty,
10838 " zebra update resumed: %s\n",
10839 bgp->update_delay_zebra_resume_time);
10840 vty_out(vty,
10841 " peers update resumed: %s\n",
10842 bgp->update_delay_peers_resume_time);
d62a17ae 10843 }
10844 }
10845 }
ea47320b 10846 }
d62a17ae 10847
ea47320b
DL
10848 if (use_json) {
10849 if (bgp_maxmed_onstartup_configured(bgp)
10850 && bgp->maxmed_active)
10851 json_object_boolean_true_add(
60466a63 10852 json, "maxMedOnStartup");
ea47320b
DL
10853 if (bgp->v_maxmed_admin)
10854 json_object_boolean_true_add(
60466a63 10855 json, "maxMedAdministrative");
d62a17ae 10856
ea47320b
DL
10857 json_object_int_add(
10858 json, "tableVersion",
60466a63 10859 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10860
60466a63
QY
10861 ents = bgp_table_count(bgp->rib[afi][safi]);
10862 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10863 json_object_int_add(
10864 json, "ribMemory",
9bcb3eef 10865 ents * sizeof(struct bgp_dest));
d62a17ae 10866
210ec2a0 10867 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10868 json_object_int_add(json, "peerCount", ents);
10869 json_object_int_add(json, "peerMemory",
10870 ents * sizeof(struct peer));
d62a17ae 10871
ea47320b
DL
10872 if ((ents = listcount(bgp->group))) {
10873 json_object_int_add(
60466a63 10874 json, "peerGroupCount", ents);
ea47320b
DL
10875 json_object_int_add(
10876 json, "peerGroupMemory",
996c9314
LB
10877 ents * sizeof(struct
10878 peer_group));
ea47320b 10879 }
d62a17ae 10880
ea47320b
DL
10881 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10882 BGP_CONFIG_DAMPENING))
10883 json_object_boolean_true_add(
60466a63 10884 json, "dampeningEnabled");
ea47320b
DL
10885 } else {
10886 if (bgp_maxmed_onstartup_configured(bgp)
10887 && bgp->maxmed_active)
d62a17ae 10888 vty_out(vty,
ea47320b
DL
10889 "Max-med on-startup active\n");
10890 if (bgp->v_maxmed_admin)
d62a17ae 10891 vty_out(vty,
ea47320b 10892 "Max-med administrative active\n");
d62a17ae 10893
60466a63
QY
10894 vty_out(vty, "BGP table version %" PRIu64 "\n",
10895 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 10896
60466a63 10897 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
10898 vty_out(vty,
10899 "RIB entries %ld, using %s of memory\n",
10900 ents,
9bcb3eef
DS
10901 mtype_memstr(
10902 memstrbuf, sizeof(memstrbuf),
10903 ents
10904 * sizeof(struct
10905 bgp_dest)));
ea47320b
DL
10906
10907 /* Peer related usage */
210ec2a0 10908 ents = bgp->af_peer_count[afi][safi];
60466a63 10909 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
10910 ents,
10911 mtype_memstr(
60466a63
QY
10912 memstrbuf, sizeof(memstrbuf),
10913 ents * sizeof(struct peer)));
ea47320b
DL
10914
10915 if ((ents = listcount(bgp->group)))
d62a17ae 10916 vty_out(vty,
ea47320b 10917 "Peer groups %ld, using %s of memory\n",
d62a17ae 10918 ents,
10919 mtype_memstr(
10920 memstrbuf,
10921 sizeof(memstrbuf),
996c9314
LB
10922 ents * sizeof(struct
10923 peer_group)));
d62a17ae 10924
ea47320b
DL
10925 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10926 BGP_CONFIG_DAMPENING))
60466a63 10927 vty_out(vty, "Dampening enabled.\n");
ea47320b 10928 vty_out(vty, "\n");
d62a17ae 10929
ea47320b
DL
10930 /* Subtract 8 here because 'Neighbor' is
10931 * 8 characters */
10932 vty_out(vty, "Neighbor");
60466a63
QY
10933 vty_out(vty, "%*s", max_neighbor_width - 8,
10934 " ");
3577f1c5 10935 if (show_failed)
85eeb029
DA
10936 vty_out(vty,
10937 BGP_SHOW_SUMMARY_HEADER_FAILED);
3577f1c5
DD
10938 else
10939 vty_out(vty,
85eeb029
DA
10940 show_wide
10941 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10942 : BGP_SHOW_SUMMARY_HEADER_ALL);
d62a17ae 10943 }
ea47320b 10944 }
d62a17ae 10945
d55811cc 10946 paf = peer_af_find(peer, afi, safi);
d3ada366 10947 filter = &peer->filter[afi][safi];
db92d226 10948
ea47320b 10949 count++;
3577f1c5
DD
10950 /* Works for both failed & successful cases */
10951 if (peer_dynamic_neighbor(peer))
10952 dn_count++;
d62a17ae 10953
ea47320b 10954 if (use_json) {
3577f1c5
DD
10955 json_peer = NULL;
10956
10957 if (show_failed &&
10958 bgp_has_peer_failed(peer, afi, safi)) {
10959 json_peer = json_object_new_object();
10960 bgp_show_failed_summary(vty, bgp, peer,
10961 json_peer, 0, use_json);
10962 } else if (!show_failed) {
10b49f14
DA
10963 if (show_established
10964 && bgp_has_peer_failed(peer, afi, safi))
10965 continue;
10966
3577f1c5
DD
10967 json_peer = json_object_new_object();
10968 if (peer_dynamic_neighbor(peer)) {
10969 json_object_boolean_true_add(json_peer,
10970 "dynamicPeer");
10971 }
d62a17ae 10972
3577f1c5
DD
10973 if (peer->hostname)
10974 json_object_string_add(json_peer, "hostname",
10975 peer->hostname);
10976
10977 if (peer->domainname)
10978 json_object_string_add(json_peer, "domainname",
10979 peer->domainname);
10980
10981 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10982 json_object_int_add(
10983 json_peer, "localAs",
10984 peer->change_local_as
10985 ? peer->change_local_as
10986 : peer->local_as);
3577f1c5
DD
10987 json_object_int_add(json_peer, "version", 4);
10988 json_object_int_add(json_peer, "msgRcvd",
10989 PEER_TOTAL_RX(peer));
10990 json_object_int_add(json_peer, "msgSent",
10991 PEER_TOTAL_TX(peer));
10992
43aa5965
QY
10993 atomic_size_t outq_count, inq_count;
10994 outq_count = atomic_load_explicit(
10995 &peer->obuf->count,
10996 memory_order_relaxed);
10997 inq_count = atomic_load_explicit(
10998 &peer->ibuf->count,
10999 memory_order_relaxed);
11000
3577f1c5
DD
11001 json_object_int_add(json_peer, "tableVersion",
11002 peer->version[afi][safi]);
11003 json_object_int_add(json_peer, "outq",
43aa5965
QY
11004 outq_count);
11005 json_object_int_add(json_peer, "inq",
11006 inq_count);
3577f1c5
DD
11007 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11008 use_json, json_peer);
11009
3577f1c5
DD
11010 json_object_int_add(json_peer, "pfxRcd",
11011 peer->pcount[afi][pfx_rcd_safi]);
11012
3577f1c5 11013 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11014 json_object_int_add(
11015 json_peer, "pfxSnt",
11016 (PAF_SUBGRP(paf))->scount);
11017 else
11018 json_object_int_add(json_peer, "pfxSnt",
11019 0);
0e1f8ab5
DA
11020
11021 /* BGP FSM state */
cb9196e7 11022 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11023 || CHECK_FLAG(peer->bgp->flags,
11024 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11025 json_object_string_add(json_peer,
11026 "state",
3577f1c5
DD
11027 "Idle (Admin)");
11028 else if (peer->afc_recv[afi][safi])
11029 json_object_string_add(
0e1f8ab5
DA
11030 json_peer, "state",
11031 lookup_msg(bgp_status_msg,
11032 peer->status, NULL));
11033 else if (CHECK_FLAG(
11034 peer->sflags,
11035 PEER_STATUS_PREFIX_OVERFLOW))
11036 json_object_string_add(json_peer,
11037 "state",
3577f1c5
DD
11038 "Idle (PfxCt)");
11039 else
11040 json_object_string_add(
0e1f8ab5
DA
11041 json_peer, "state",
11042 lookup_msg(bgp_status_msg,
11043 peer->status, NULL));
11044
11045 /* BGP peer state */
11046 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11047 || CHECK_FLAG(peer->bgp->flags,
11048 BGP_FLAG_SHUTDOWN))
11049 json_object_string_add(json_peer,
11050 "peerState",
11051 "Admin");
11052 else if (CHECK_FLAG(
11053 peer->sflags,
11054 PEER_STATUS_PREFIX_OVERFLOW))
11055 json_object_string_add(json_peer,
11056 "peerState",
11057 "PfxCt");
11058 else if (CHECK_FLAG(peer->flags,
11059 PEER_FLAG_PASSIVE))
11060 json_object_string_add(json_peer,
11061 "peerState",
11062 "Passive");
11063 else if (CHECK_FLAG(peer->sflags,
11064 PEER_STATUS_NSF_WAIT))
11065 json_object_string_add(json_peer,
11066 "peerState",
11067 "NSF passive");
11068 else if (CHECK_FLAG(
11069 peer->bgp->flags,
11070 BGP_FLAG_EBGP_REQUIRES_POLICY)
11071 && (!bgp_inbound_policy_exists(peer,
11072 filter)
11073 || !bgp_outbound_policy_exists(
11074 peer, filter)))
11075 json_object_string_add(json_peer,
11076 "peerState",
11077 "Policy");
11078 else
11079 json_object_string_add(
11080 json_peer, "peerState", "OK");
11081
200116db
DD
11082 json_object_int_add(json_peer, "connectionsEstablished",
11083 peer->established);
11084 json_object_int_add(json_peer, "connectionsDropped",
11085 peer->dropped);
aa72bd7e
PG
11086 if (peer->desc)
11087 json_object_string_add(
11088 json_peer, "desc", peer->desc);
b4e9dcba 11089 }
3577f1c5
DD
11090 /* Avoid creating empty peer dicts in JSON */
11091 if (json_peer == NULL)
11092 continue;
ea47320b
DL
11093
11094 if (peer->conf_if)
60466a63 11095 json_object_string_add(json_peer, "idType",
ea47320b
DL
11096 "interface");
11097 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11098 json_object_string_add(json_peer, "idType",
11099 "ipv4");
ea47320b 11100 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11101 json_object_string_add(json_peer, "idType",
11102 "ipv6");
ea47320b
DL
11103 json_object_object_add(json_peers, peer->host,
11104 json_peer);
11105 } else {
3577f1c5
DD
11106 if (show_failed &&
11107 bgp_has_peer_failed(peer, afi, safi)) {
11108 bgp_show_failed_summary(vty, bgp, peer, NULL,
11109 max_neighbor_width,
11110 use_json);
11111 } else if (!show_failed) {
10b49f14
DA
11112 if (show_established
11113 && bgp_has_peer_failed(peer, afi, safi))
11114 continue;
11115
3577f1c5
DD
11116 memset(dn_flag, '\0', sizeof(dn_flag));
11117 if (peer_dynamic_neighbor(peer)) {
11118 dn_flag[0] = '*';
11119 }
d62a17ae 11120
3577f1c5 11121 if (peer->hostname
892fedb6
DA
11122 && CHECK_FLAG(bgp->flags,
11123 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11124 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11125 peer->hostname,
11126 peer->host);
d62a17ae 11127 else
3577f1c5
DD
11128 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11129
11130 /* pad the neighbor column with spaces */
11131 if (len < max_neighbor_width)
11132 vty_out(vty, "%*s", max_neighbor_width - len,
11133 " ");
11134
43aa5965
QY
11135 atomic_size_t outq_count, inq_count;
11136 outq_count = atomic_load_explicit(
11137 &peer->obuf->count,
11138 memory_order_relaxed);
11139 inq_count = atomic_load_explicit(
11140 &peer->ibuf->count,
11141 memory_order_relaxed);
11142
85eeb029
DA
11143 if (show_wide)
11144 vty_out(vty,
11145 "4 %10u %10u %9u %9u %8" PRIu64
11146 " %4zu %4zu %8s",
11147 peer->as,
11148 peer->change_local_as
11149 ? peer->change_local_as
11150 : peer->local_as,
11151 PEER_TOTAL_RX(peer),
11152 PEER_TOTAL_TX(peer),
11153 peer->version[afi][safi],
11154 inq_count, outq_count,
11155 peer_uptime(peer->uptime,
11156 timebuf,
11157 BGP_UPTIME_LEN, 0,
11158 NULL));
11159 else
11160 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11161 " %4zu %4zu %8s",
11162 peer->as, PEER_TOTAL_RX(peer),
11163 PEER_TOTAL_TX(peer),
11164 peer->version[afi][safi],
11165 inq_count, outq_count,
11166 peer_uptime(peer->uptime,
11167 timebuf,
11168 BGP_UPTIME_LEN, 0,
11169 NULL));
3577f1c5 11170
db92d226 11171 if (peer->status == Established) {
d3ada366
DA
11172 if (peer->afc_recv[afi][safi]) {
11173 if (CHECK_FLAG(
11174 bgp->flags,
11175 BGP_FLAG_EBGP_REQUIRES_POLICY)
11176 && !bgp_inbound_policy_exists(
11177 peer, filter))
11178 vty_out(vty, " %12s",
11179 "(Policy)");
11180 else
11181 vty_out(vty,
6cde4b45 11182 " %12u",
d3ada366
DA
11183 peer->pcount
11184 [afi]
11185 [pfx_rcd_safi]);
11186 } else {
749d0f27 11187 vty_out(vty, " NoNeg");
d3ada366 11188 }
db92d226 11189
d3ada366
DA
11190 if (paf && PAF_SUBGRP(paf)) {
11191 if (CHECK_FLAG(
11192 bgp->flags,
11193 BGP_FLAG_EBGP_REQUIRES_POLICY)
11194 && !bgp_outbound_policy_exists(
11195 peer, filter))
11196 vty_out(vty, " %8s",
11197 "(Policy)");
11198 else
11199 vty_out(vty,
6cde4b45 11200 " %8u",
d3ada366
DA
11201 (PAF_SUBGRP(
11202 paf))
11203 ->scount);
749d0f27
DA
11204 } else {
11205 vty_out(vty, " NoNeg");
d3ada366 11206 }
db92d226 11207 } else {
736b68f3
DS
11208 if (CHECK_FLAG(peer->flags,
11209 PEER_FLAG_SHUTDOWN)
11210 || CHECK_FLAG(peer->bgp->flags,
11211 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11212 vty_out(vty, " Idle (Admin)");
11213 else if (CHECK_FLAG(
11214 peer->sflags,
11215 PEER_STATUS_PREFIX_OVERFLOW))
11216 vty_out(vty, " Idle (PfxCt)");
11217 else
11218 vty_out(vty, " %12s",
11219 lookup_msg(bgp_status_msg,
11220 peer->status, NULL));
db92d226 11221
6cde4b45 11222 vty_out(vty, " %8u", 0);
3577f1c5 11223 }
aa72bd7e 11224 if (peer->desc)
cb75bb31
DA
11225 vty_out(vty, " %s",
11226 bgp_peer_description_stripped(
85eeb029
DA
11227 peer->desc,
11228 show_wide ? 64 : 20));
aa72bd7e
PG
11229 else
11230 vty_out(vty, " N/A");
3577f1c5 11231 vty_out(vty, "\n");
d62a17ae 11232 }
3577f1c5 11233
d62a17ae 11234 }
11235 }
f933309e 11236
d62a17ae 11237 if (use_json) {
11238 json_object_object_add(json, "peers", json_peers);
3577f1c5 11239 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 11240 json_object_int_add(json, "totalPeers", count);
11241 json_object_int_add(json, "dynamicPeers", dn_count);
11242
3577f1c5
DD
11243 if (!show_failed)
11244 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11245
996c9314
LB
11246 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11247 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11248 json_object_free(json);
11249 } else {
11250 if (count)
11251 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11252 else {
d6ceaca3 11253 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11254 get_afi_safi_str(afi, safi, false));
d62a17ae 11255 }
b05a1c8b 11256
d6ceaca3 11257 if (dn_count) {
d62a17ae 11258 vty_out(vty, "* - dynamic neighbor\n");
11259 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11260 dn_count, bgp->dynamic_neighbors_limit);
11261 }
11262 }
1ff9a340 11263
d62a17ae 11264 return CMD_SUCCESS;
718e3744 11265}
11266
d62a17ae 11267static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
85eeb029 11268 int safi, uint8_t show_flags)
d62a17ae 11269{
11270 int is_first = 1;
11271 int afi_wildcard = (afi == AFI_MAX);
11272 int safi_wildcard = (safi == SAFI_MAX);
11273 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11274 bool nbr_output = false;
85eeb029 11275 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11276
11277 if (use_json && is_wildcard)
11278 vty_out(vty, "{\n");
11279 if (afi_wildcard)
11280 afi = 1; /* AFI_IP */
11281 while (afi < AFI_MAX) {
11282 if (safi_wildcard)
11283 safi = 1; /* SAFI_UNICAST */
11284 while (safi < SAFI_MAX) {
318cac96 11285 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11286 nbr_output = true;
f86897b9 11287
d62a17ae 11288 if (is_wildcard) {
11289 /*
11290 * So limit output to those afi/safi
11291 * pairs that
11292 * actualy have something interesting in
11293 * them
11294 */
11295 if (use_json) {
d62a17ae 11296 if (!is_first)
11297 vty_out(vty, ",\n");
11298 else
11299 is_first = 0;
11300
11301 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11302 get_afi_safi_str(afi,
11303 safi,
11304 true));
d62a17ae 11305 } else {
11306 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
11307 get_afi_safi_str(afi,
11308 safi,
11309 false));
d62a17ae 11310 }
11311 }
10b49f14 11312 bgp_show_summary(vty, bgp, afi, safi,
85eeb029 11313 show_flags);
d62a17ae 11314 }
11315 safi++;
d62a17ae 11316 if (!safi_wildcard)
11317 safi = SAFI_MAX;
11318 }
11319 afi++;
ee851c8c 11320 if (!afi_wildcard)
d62a17ae 11321 afi = AFI_MAX;
11322 }
11323
11324 if (use_json && is_wildcard)
11325 vty_out(vty, "}\n");
ca61fd25
DS
11326 else if (!nbr_output) {
11327 if (use_json)
11328 vty_out(vty, "{}\n");
11329 else
11330 vty_out(vty, "%% No BGP neighbors found\n");
11331 }
d62a17ae 11332}
11333
11334static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
85eeb029 11335 safi_t safi, uint8_t show_flags)
d62a17ae 11336{
11337 struct listnode *node, *nnode;
11338 struct bgp *bgp;
d62a17ae 11339 int is_first = 1;
9f049418 11340 bool nbr_output = false;
85eeb029 11341 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11342
11343 if (use_json)
11344 vty_out(vty, "{\n");
11345
11346 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11347 nbr_output = true;
d62a17ae 11348 if (use_json) {
d62a17ae 11349 if (!is_first)
11350 vty_out(vty, ",\n");
11351 else
11352 is_first = 0;
11353
11354 vty_out(vty, "\"%s\":",
11355 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11356 ? VRF_DEFAULT_NAME
d62a17ae 11357 : bgp->name);
11358 } else {
11359 vty_out(vty, "\nInstance %s:\n",
11360 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11361 ? VRF_DEFAULT_NAME
d62a17ae 11362 : bgp->name);
11363 }
85eeb029 11364 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
d62a17ae 11365 }
11366
11367 if (use_json)
11368 vty_out(vty, "}\n");
9f049418
DS
11369 else if (!nbr_output)
11370 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11371}
11372
11373int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
85eeb029 11374 safi_t safi, uint8_t show_flags)
d62a17ae 11375{
11376 struct bgp *bgp;
85eeb029 11377 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11378
11379 if (name) {
11380 if (strmatch(name, "all")) {
85eeb029
DA
11381 bgp_show_all_instances_summary_vty(vty, afi, safi,
11382 show_flags);
d62a17ae 11383 return CMD_SUCCESS;
11384 } else {
11385 bgp = bgp_lookup_by_name(name);
11386
11387 if (!bgp) {
11388 if (use_json)
11389 vty_out(vty, "{}\n");
11390 else
11391 vty_out(vty,
ca61fd25 11392 "%% BGP instance not found\n");
d62a17ae 11393 return CMD_WARNING;
11394 }
11395
f86897b9 11396 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
85eeb029 11397 show_flags);
d62a17ae 11398 return CMD_SUCCESS;
11399 }
11400 }
11401
11402 bgp = bgp_get_default();
11403
11404 if (bgp)
85eeb029 11405 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
9f049418 11406 else {
ca61fd25
DS
11407 if (use_json)
11408 vty_out(vty, "{}\n");
11409 else
11410 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11411 return CMD_WARNING;
11412 }
d62a17ae 11413
11414 return CMD_SUCCESS;
4fb25c53
DW
11415}
11416
716b2d8a 11417/* `show [ip] bgp summary' commands. */
96f3485c 11418DEFPY (show_ip_bgp_summary,
718e3744 11419 show_ip_bgp_summary_cmd,
85eeb029 11420 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [wide] [json$uj]",
718e3744 11421 SHOW_STR
11422 IP_STR
11423 BGP_STR
8386ac43 11424 BGP_INSTANCE_HELP_STR
46f296b4 11425 BGP_AFI_HELP_STR
dd6bd0f1 11426 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 11427 "Display the entries for all address families\n"
b05a1c8b 11428 "Summary of BGP neighbor status\n"
10b49f14 11429 "Show only sessions in Established state\n"
3577f1c5 11430 "Show only sessions not in Established state\n"
85eeb029 11431 "Increase table width for longer output\n"
9973d184 11432 JSON_STR)
718e3744 11433{
d62a17ae 11434 char *vrf = NULL;
11435 afi_t afi = AFI_MAX;
11436 safi_t safi = SAFI_MAX;
85eeb029 11437 uint8_t show_flags = 0;
d62a17ae 11438
11439 int idx = 0;
11440
11441 /* show [ip] bgp */
96f3485c 11442 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11443 afi = AFI_IP;
9a8bdf1c
PG
11444 /* [<vrf> VIEWVRFNAME] */
11445 if (argv_find(argv, argc, "vrf", &idx)) {
11446 vrf = argv[idx + 1]->arg;
11447 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11448 vrf = NULL;
11449 } else if (argv_find(argv, argc, "view", &idx))
11450 /* [<view> VIEWVRFNAME] */
11451 vrf = argv[idx + 1]->arg;
d62a17ae 11452 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11453 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11454 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11455 }
11456
3577f1c5 11457 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11458 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11459
10b49f14 11460 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11461 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11462
11463 if (argv_find(argv, argc, "wide", &idx))
11464 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11465
11466 if (argv_find(argv, argc, "json", &idx))
11467 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11468
85eeb029 11469 return bgp_show_summary_vty(vty, vrf, afi, safi, show_flags);
d62a17ae 11470}
11471
5cb5f4d0 11472const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11473{
5cb5f4d0
DD
11474 if (for_json)
11475 return get_afi_safi_json_str(afi, safi);
d62a17ae 11476 else
5cb5f4d0 11477 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11478}
11479
d62a17ae 11480
11481static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11482 afi_t afi, safi_t safi,
d7c0a89a
QY
11483 uint16_t adv_smcap, uint16_t adv_rmcap,
11484 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11485 bool use_json, json_object *json_pref)
d62a17ae 11486{
11487 /* Send-Mode */
11488 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11489 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11490 if (use_json) {
11491 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11492 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11493 json_object_string_add(json_pref, "sendMode",
11494 "advertisedAndReceived");
11495 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11496 json_object_string_add(json_pref, "sendMode",
11497 "advertised");
11498 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11499 json_object_string_add(json_pref, "sendMode",
11500 "received");
11501 } else {
11502 vty_out(vty, " Send-mode: ");
11503 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11504 vty_out(vty, "advertised");
11505 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11506 vty_out(vty, "%sreceived",
11507 CHECK_FLAG(p->af_cap[afi][safi],
11508 adv_smcap)
11509 ? ", "
11510 : "");
11511 vty_out(vty, "\n");
11512 }
11513 }
11514
11515 /* Receive-Mode */
11516 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11517 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11518 if (use_json) {
11519 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11520 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11521 json_object_string_add(json_pref, "recvMode",
11522 "advertisedAndReceived");
11523 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11524 json_object_string_add(json_pref, "recvMode",
11525 "advertised");
11526 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11527 json_object_string_add(json_pref, "recvMode",
11528 "received");
11529 } else {
11530 vty_out(vty, " Receive-mode: ");
11531 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11532 vty_out(vty, "advertised");
11533 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11534 vty_out(vty, "%sreceived",
11535 CHECK_FLAG(p->af_cap[afi][safi],
11536 adv_rmcap)
11537 ? ", "
11538 : "");
11539 vty_out(vty, "\n");
11540 }
11541 }
11542}
11543
13909c4f
DS
11544static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11545 struct peer *p,
11546 bool use_json,
11547 json_object *json)
2986cac2 11548{
08c2d52a 11549 bool rbit_status = false;
2986cac2 11550
11551 if (!use_json)
a53ca37b 11552 vty_out(vty, "\n R bit: ");
2986cac2 11553
13909c4f
DS
11554 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11555 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11556 && (p->status == Established)) {
2986cac2 11557
11558 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11559 rbit_status = true;
2986cac2 11560 else
08c2d52a 11561 rbit_status = false;
2986cac2 11562 }
11563
11564 if (rbit_status) {
11565 if (use_json)
13909c4f 11566 json_object_boolean_true_add(json, "rBit");
2986cac2 11567 else
11568 vty_out(vty, "True\n");
11569 } else {
11570 if (use_json)
13909c4f 11571 json_object_boolean_false_add(json, "rBit");
2986cac2 11572 else
11573 vty_out(vty, "False\n");
11574 }
11575}
11576
13909c4f
DS
11577static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11578 struct peer *peer,
11579 bool use_json,
11580 json_object *json)
2986cac2 11581{
2bb5d39b 11582 const char *mode = "NotApplicable";
2986cac2 11583
11584 if (!use_json)
a53ca37b 11585 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11586
13909c4f
DS
11587 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11588 && (peer->status == Established)) {
2986cac2 11589
13909c4f
DS
11590 if ((peer->nsf_af_count == 0)
11591 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11592
2986cac2 11593 mode = "Disable";
11594
13909c4f
DS
11595 } else if (peer->nsf_af_count == 0
11596 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11597
2986cac2 11598 mode = "Helper";
11599
13909c4f
DS
11600 } else if (peer->nsf_af_count != 0
11601 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11602
2986cac2 11603 mode = "Restart";
2986cac2 11604 }
11605 }
11606
11607 if (use_json) {
13909c4f 11608 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11609 } else
11610 vty_out(vty, mode, "\n");
11611}
11612
13909c4f
DS
11613static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11614 struct peer *p,
11615 bool use_json,
11616 json_object *json)
2986cac2 11617{
11618 const char *mode = "Invalid";
11619
11620 if (!use_json)
a53ca37b 11621 vty_out(vty, " Local GR Mode: ");
2986cac2 11622
11623 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11624 mode = "Helper";
11625 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11626 mode = "Restart";
11627 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11628 mode = "Disable";
2ba1fe69 11629 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11630 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11631 mode = "Helper*";
11632 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11633 mode = "Restart*";
11634 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11635 mode = "Disable*";
11636 else
11637 mode = "Invalid*";
2ba1fe69 11638 }
2986cac2 11639
11640 if (use_json) {
13909c4f 11641 json_object_string_add(json, "localGrMode", mode);
2986cac2 11642 } else {
11643 vty_out(vty, mode, "\n");
11644 }
11645}
11646
13909c4f
DS
11647static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11648 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11649{
2ba1fe69 11650 afi_t afi;
11651 safi_t safi;
2986cac2 11652 json_object *json_afi_safi = NULL;
11653 json_object *json_timer = NULL;
11654 json_object *json_endofrib_status = NULL;
9e3b51a7 11655 bool eor_flag = false;
2986cac2 11656
11657 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11658 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
11659 if (!peer->afc[afi][safi])
11660 continue;
2986cac2 11661
13909c4f
DS
11662 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11663 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11664 continue;
9e3b51a7 11665
13909c4f
DS
11666 if (use_json) {
11667 json_afi_safi = json_object_new_object();
11668 json_endofrib_status = json_object_new_object();
11669 json_timer = json_object_new_object();
11670 }
2986cac2 11671
13909c4f
DS
11672 if (peer->eor_stime[afi][safi]
11673 >= peer->pkt_stime[afi][safi])
11674 eor_flag = true;
11675 else
11676 eor_flag = false;
2986cac2 11677
13909c4f 11678 if (!use_json) {
a53ca37b 11679 vty_out(vty, " %s:\n",
13909c4f 11680 get_afi_safi_str(afi, safi, false));
2986cac2 11681
a53ca37b 11682 vty_out(vty, " F bit: ");
698ba8d0 11683 }
2986cac2 11684
13909c4f
DS
11685 if (peer->nsf[afi][safi]
11686 && CHECK_FLAG(peer->af_cap[afi][safi],
11687 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11688
13909c4f
DS
11689 if (use_json) {
11690 json_object_boolean_true_add(
2986cac2 11691 json_afi_safi, "fBit");
13909c4f
DS
11692 } else
11693 vty_out(vty, "True\n");
11694 } else {
11695 if (use_json)
11696 json_object_boolean_false_add(
11697 json_afi_safi, "fBit");
11698 else
11699 vty_out(vty, "False\n");
11700 }
2986cac2 11701
13909c4f 11702 if (!use_json)
a53ca37b 11703 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11704
13909c4f
DS
11705 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11706 PEER_STATUS_EOR_SEND)) {
11707 if (use_json) {
11708 json_object_boolean_true_add(
2986cac2 11709 json_endofrib_status,
13909c4f 11710 "endOfRibSend");
9e3b51a7 11711
13909c4f
DS
11712 PRINT_EOR_JSON(eor_flag);
11713 } else {
11714 vty_out(vty, "Yes\n");
11715 vty_out(vty,
a53ca37b 11716 " End-of-RIB sent after update: ");
2986cac2 11717
13909c4f
DS
11718 PRINT_EOR(eor_flag);
11719 }
11720 } else {
11721 if (use_json) {
11722 json_object_boolean_false_add(
2986cac2 11723 json_endofrib_status,
13909c4f
DS
11724 "endOfRibSend");
11725 json_object_boolean_false_add(
9e3b51a7 11726 json_endofrib_status,
13909c4f
DS
11727 "endOfRibSentAfterUpdate");
11728 } else {
11729 vty_out(vty, "No\n");
11730 vty_out(vty,
a53ca37b 11731 " End-of-RIB sent after update: ");
13909c4f 11732 vty_out(vty, "No\n");
2986cac2 11733 }
13909c4f 11734 }
2986cac2 11735
a53ca37b
DA
11736 if (!use_json)
11737 vty_out(vty, " End-of-RIB received: ");
11738
11739 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11740 PEER_STATUS_EOR_RECEIVED)) {
11741 if (use_json)
11742 json_object_boolean_true_add(
11743 json_endofrib_status,
11744 "endOfRibRecv");
11745 else
11746 vty_out(vty, "Yes\n");
11747 } else {
11748 if (use_json)
11749 json_object_boolean_false_add(
11750 json_endofrib_status,
11751 "endOfRibRecv");
11752 else
11753 vty_out(vty, "No\n");
11754 }
11755
13909c4f
DS
11756 if (use_json) {
11757 json_object_int_add(json_timer,
11758 "stalePathTimer",
11759 peer->bgp->stalepath_time);
2986cac2 11760
13909c4f
DS
11761 if (peer->t_gr_stale != NULL) {
11762 json_object_int_add(
2986cac2 11763 json_timer,
11764 "stalePathTimerRemaining",
11765 thread_timer_remain_second(
13909c4f
DS
11766 peer->t_gr_stale));
11767 }
3a75afa4 11768
13909c4f
DS
11769 /* Display Configured Selection
11770 * Deferral only when when
11771 * Gr mode is enabled.
11772 */
11773 if (CHECK_FLAG(peer->flags,
11774 PEER_FLAG_GRACEFUL_RESTART)) {
11775 json_object_int_add(
3a75afa4 11776 json_timer,
2986cac2 11777 "selectionDeferralTimer",
11778 peer->bgp->stalepath_time);
13909c4f 11779 }
2986cac2 11780
13909c4f
DS
11781 if (peer->bgp->gr_info[afi][safi]
11782 .t_select_deferral
11783 != NULL) {
2986cac2 11784
13909c4f 11785 json_object_int_add(
2986cac2 11786 json_timer,
11787 "selectionDeferralTimerRemaining",
11788 thread_timer_remain_second(
13909c4f
DS
11789 peer->bgp
11790 ->gr_info[afi]
11791 [safi]
11792 .t_select_deferral));
11793 }
11794 } else {
a53ca37b 11795 vty_out(vty, " Timers:\n");
13909c4f 11796 vty_out(vty,
a53ca37b
DA
11797 " Configured Stale Path Time(sec): %u\n",
11798 peer->bgp->stalepath_time);
2986cac2 11799
a53ca37b 11800 if (peer->t_gr_stale != NULL)
2986cac2 11801 vty_out(vty,
a53ca37b 11802 " Stale Path Remaining(sec): %ld\n",
2986cac2 11803 thread_timer_remain_second(
13909c4f 11804 peer->t_gr_stale));
13909c4f
DS
11805 /* Display Configured Selection
11806 * Deferral only when when
11807 * Gr mode is enabled.
11808 */
11809 if (CHECK_FLAG(peer->flags,
a53ca37b 11810 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 11811 vty_out(vty,
a53ca37b 11812 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 11813 peer->bgp->select_defer_time);
2986cac2 11814
13909c4f
DS
11815 if (peer->bgp->gr_info[afi][safi]
11816 .t_select_deferral
a53ca37b 11817 != NULL)
13909c4f 11818 vty_out(vty,
a53ca37b 11819 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 11820 thread_timer_remain_second(
13909c4f
DS
11821 peer->bgp
11822 ->gr_info[afi]
11823 [safi]
11824 .t_select_deferral));
2986cac2 11825 }
13909c4f
DS
11826 if (use_json) {
11827 json_object_object_add(json_afi_safi,
11828 "endOfRibStatus",
11829 json_endofrib_status);
11830 json_object_object_add(json_afi_safi, "timers",
11831 json_timer);
11832 json_object_object_add(
11833 json, get_afi_safi_str(afi, safi, true),
11834 json_afi_safi);
11835 }
2986cac2 11836 }
11837 }
11838}
11839
36235319
QY
11840static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11841 struct peer *p,
11842 bool use_json,
11843 json_object *json)
2986cac2 11844{
11845 if (use_json) {
11846 json_object *json_timer = NULL;
11847
11848 json_timer = json_object_new_object();
11849
13909c4f
DS
11850 json_object_int_add(json_timer, "configuredRestartTimer",
11851 p->bgp->restart_time);
2986cac2 11852
13909c4f
DS
11853 json_object_int_add(json_timer, "receivedRestartTimer",
11854 p->v_gr_restart);
2986cac2 11855
13909c4f
DS
11856 if (p->t_gr_restart != NULL)
11857 json_object_int_add(
11858 json_timer, "restartTimerRemaining",
11859 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11860
11861 json_object_object_add(json, "timers", json_timer);
11862 } else {
11863
a53ca37b
DA
11864 vty_out(vty, " Timers:\n");
11865 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11866 p->bgp->restart_time);
2986cac2 11867
a53ca37b 11868 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11869 p->v_gr_restart);
11870 if (p->t_gr_restart != NULL)
a53ca37b 11871 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11872 thread_timer_remain_second(p->t_gr_restart));
36235319 11873 if (p->t_gr_restart != NULL) {
a53ca37b 11874 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11875 thread_timer_remain_second(p->t_gr_restart));
11876 }
2986cac2 11877 }
11878}
11879
11880static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11881 bool use_json, json_object *json)
2986cac2 11882{
11883 char buf[SU_ADDRSTRLEN] = {0};
11884 char dn_flag[2] = {0};
2b7165e7
QY
11885 /* '*' + v6 address of neighbor */
11886 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11887
2986cac2 11888 if (!p->conf_if && peer_dynamic_neighbor(p))
11889 dn_flag[0] = '*';
11890
11891 if (p->conf_if) {
11892 if (use_json)
13909c4f
DS
11893 json_object_string_add(
11894 json, "neighborAddr",
2986cac2 11895 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11896 ? "none"
11897 : sockunion2str(&p->su, buf,
11898 SU_ADDRSTRLEN));
2986cac2 11899 else
13909c4f 11900 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11901 BGP_PEER_SU_UNSPEC(p)
11902 ? "none"
11903 : sockunion2str(&p->su, buf,
11904 SU_ADDRSTRLEN));
11905 } else {
772270f3
QY
11906 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11907 p->host);
2986cac2 11908
11909 if (use_json)
36235319
QY
11910 json_object_string_add(json, "neighborAddr",
11911 neighborAddr);
2986cac2 11912 else
36235319 11913 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11914 }
11915
11916 /* more gr info in new format */
11917 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11918}
11919
d62a17ae 11920static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11921 safi_t safi, bool use_json,
d62a17ae 11922 json_object *json_neigh)
11923{
0291c246
MK
11924 struct bgp_filter *filter;
11925 struct peer_af *paf;
11926 char orf_pfx_name[BUFSIZ];
11927 int orf_pfx_count;
11928 json_object *json_af = NULL;
11929 json_object *json_prefA = NULL;
11930 json_object *json_prefB = NULL;
11931 json_object *json_addr = NULL;
fa36596c 11932 json_object *json_advmap = NULL;
d62a17ae 11933
11934 if (use_json) {
11935 json_addr = json_object_new_object();
11936 json_af = json_object_new_object();
11937 filter = &p->filter[afi][safi];
11938
11939 if (peer_group_active(p))
11940 json_object_string_add(json_addr, "peerGroupMember",
11941 p->group->name);
11942
11943 paf = peer_af_find(p, afi, safi);
11944 if (paf && PAF_SUBGRP(paf)) {
11945 json_object_int_add(json_addr, "updateGroupId",
11946 PAF_UPDGRP(paf)->id);
11947 json_object_int_add(json_addr, "subGroupId",
11948 PAF_SUBGRP(paf)->id);
11949 json_object_int_add(json_addr, "packetQueueLength",
11950 bpacket_queue_virtual_length(paf));
11951 }
11952
11953 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11954 || CHECK_FLAG(p->af_cap[afi][safi],
11955 PEER_CAP_ORF_PREFIX_SM_RCV)
11956 || CHECK_FLAG(p->af_cap[afi][safi],
11957 PEER_CAP_ORF_PREFIX_RM_ADV)
11958 || CHECK_FLAG(p->af_cap[afi][safi],
11959 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11960 json_object_int_add(json_af, "orfType",
11961 ORF_TYPE_PREFIX);
11962 json_prefA = json_object_new_object();
11963 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11964 PEER_CAP_ORF_PREFIX_SM_ADV,
11965 PEER_CAP_ORF_PREFIX_RM_ADV,
11966 PEER_CAP_ORF_PREFIX_SM_RCV,
11967 PEER_CAP_ORF_PREFIX_RM_RCV,
11968 use_json, json_prefA);
11969 json_object_object_add(json_af, "orfPrefixList",
11970 json_prefA);
11971 }
11972
11973 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11974 || CHECK_FLAG(p->af_cap[afi][safi],
11975 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11976 || CHECK_FLAG(p->af_cap[afi][safi],
11977 PEER_CAP_ORF_PREFIX_RM_ADV)
11978 || CHECK_FLAG(p->af_cap[afi][safi],
11979 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11980 json_object_int_add(json_af, "orfOldType",
11981 ORF_TYPE_PREFIX_OLD);
11982 json_prefB = json_object_new_object();
11983 bgp_show_peer_afi_orf_cap(
11984 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11985 PEER_CAP_ORF_PREFIX_RM_ADV,
11986 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11987 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11988 json_prefB);
11989 json_object_object_add(json_af, "orfOldPrefixList",
11990 json_prefB);
11991 }
11992
11993 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11994 || CHECK_FLAG(p->af_cap[afi][safi],
11995 PEER_CAP_ORF_PREFIX_SM_RCV)
11996 || CHECK_FLAG(p->af_cap[afi][safi],
11997 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11998 || CHECK_FLAG(p->af_cap[afi][safi],
11999 PEER_CAP_ORF_PREFIX_RM_ADV)
12000 || CHECK_FLAG(p->af_cap[afi][safi],
12001 PEER_CAP_ORF_PREFIX_RM_RCV)
12002 || CHECK_FLAG(p->af_cap[afi][safi],
12003 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12004 json_object_object_add(json_addr, "afDependentCap",
12005 json_af);
12006 else
12007 json_object_free(json_af);
12008
772270f3
QY
12009 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12010 p->host, afi, safi);
d62a17ae 12011 orf_pfx_count = prefix_bgp_show_prefix_list(
12012 NULL, afi, orf_pfx_name, use_json);
12013
12014 if (CHECK_FLAG(p->af_sflags[afi][safi],
12015 PEER_STATUS_ORF_PREFIX_SEND)
12016 || orf_pfx_count) {
12017 if (CHECK_FLAG(p->af_sflags[afi][safi],
12018 PEER_STATUS_ORF_PREFIX_SEND))
12019 json_object_boolean_true_add(json_neigh,
12020 "orfSent");
12021 if (orf_pfx_count)
12022 json_object_int_add(json_addr, "orfRecvCounter",
12023 orf_pfx_count);
12024 }
12025 if (CHECK_FLAG(p->af_sflags[afi][safi],
12026 PEER_STATUS_ORF_WAIT_REFRESH))
12027 json_object_string_add(
12028 json_addr, "orfFirstUpdate",
12029 "deferredUntilORFOrRouteRefreshRecvd");
12030
12031 if (CHECK_FLAG(p->af_flags[afi][safi],
12032 PEER_FLAG_REFLECTOR_CLIENT))
12033 json_object_boolean_true_add(json_addr,
12034 "routeReflectorClient");
12035 if (CHECK_FLAG(p->af_flags[afi][safi],
12036 PEER_FLAG_RSERVER_CLIENT))
12037 json_object_boolean_true_add(json_addr,
12038 "routeServerClient");
12039 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12040 json_object_boolean_true_add(json_addr,
12041 "inboundSoftConfigPermit");
12042
12043 if (CHECK_FLAG(p->af_flags[afi][safi],
12044 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12045 json_object_boolean_true_add(
12046 json_addr,
12047 "privateAsNumsAllReplacedInUpdatesToNbr");
12048 else if (CHECK_FLAG(p->af_flags[afi][safi],
12049 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12050 json_object_boolean_true_add(
12051 json_addr,
12052 "privateAsNumsReplacedInUpdatesToNbr");
12053 else if (CHECK_FLAG(p->af_flags[afi][safi],
12054 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12055 json_object_boolean_true_add(
12056 json_addr,
12057 "privateAsNumsAllRemovedInUpdatesToNbr");
12058 else if (CHECK_FLAG(p->af_flags[afi][safi],
12059 PEER_FLAG_REMOVE_PRIVATE_AS))
12060 json_object_boolean_true_add(
12061 json_addr,
12062 "privateAsNumsRemovedInUpdatesToNbr");
12063
dcc68b5e
MS
12064 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12065 json_object_boolean_true_add(
12066 json_addr,
12067 bgp_addpath_names(p->addpath_type[afi][safi])
12068 ->type_json_name);
d62a17ae 12069
12070 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12071 json_object_string_add(json_addr,
12072 "overrideASNsInOutboundUpdates",
12073 "ifAspathEqualRemoteAs");
12074
12075 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12076 || CHECK_FLAG(p->af_flags[afi][safi],
12077 PEER_FLAG_FORCE_NEXTHOP_SELF))
12078 json_object_boolean_true_add(json_addr,
12079 "routerAlwaysNextHop");
12080 if (CHECK_FLAG(p->af_flags[afi][safi],
12081 PEER_FLAG_AS_PATH_UNCHANGED))
12082 json_object_boolean_true_add(
12083 json_addr, "unchangedAsPathPropogatedToNbr");
12084 if (CHECK_FLAG(p->af_flags[afi][safi],
12085 PEER_FLAG_NEXTHOP_UNCHANGED))
12086 json_object_boolean_true_add(
12087 json_addr, "unchangedNextHopPropogatedToNbr");
12088 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12089 json_object_boolean_true_add(
12090 json_addr, "unchangedMedPropogatedToNbr");
12091 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12092 || CHECK_FLAG(p->af_flags[afi][safi],
12093 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12094 if (CHECK_FLAG(p->af_flags[afi][safi],
12095 PEER_FLAG_SEND_COMMUNITY)
12096 && CHECK_FLAG(p->af_flags[afi][safi],
12097 PEER_FLAG_SEND_EXT_COMMUNITY))
12098 json_object_string_add(json_addr,
12099 "commAttriSentToNbr",
12100 "extendedAndStandard");
12101 else if (CHECK_FLAG(p->af_flags[afi][safi],
12102 PEER_FLAG_SEND_EXT_COMMUNITY))
12103 json_object_string_add(json_addr,
12104 "commAttriSentToNbr",
12105 "extended");
12106 else
12107 json_object_string_add(json_addr,
12108 "commAttriSentToNbr",
12109 "standard");
12110 }
12111 if (CHECK_FLAG(p->af_flags[afi][safi],
12112 PEER_FLAG_DEFAULT_ORIGINATE)) {
12113 if (p->default_rmap[afi][safi].name)
12114 json_object_string_add(
12115 json_addr, "defaultRouteMap",
12116 p->default_rmap[afi][safi].name);
12117
12118 if (paf && PAF_SUBGRP(paf)
12119 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12120 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12121 json_object_boolean_true_add(json_addr,
12122 "defaultSent");
12123 else
12124 json_object_boolean_true_add(json_addr,
12125 "defaultNotSent");
12126 }
12127
dff8f48d 12128 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12129 if (is_evpn_enabled())
60466a63
QY
12130 json_object_boolean_true_add(
12131 json_addr, "advertiseAllVnis");
dff8f48d
MK
12132 }
12133
d62a17ae 12134 if (filter->plist[FILTER_IN].name
12135 || filter->dlist[FILTER_IN].name
12136 || filter->aslist[FILTER_IN].name
12137 || filter->map[RMAP_IN].name)
12138 json_object_boolean_true_add(json_addr,
12139 "inboundPathPolicyConfig");
12140 if (filter->plist[FILTER_OUT].name
12141 || filter->dlist[FILTER_OUT].name
12142 || filter->aslist[FILTER_OUT].name
12143 || filter->map[RMAP_OUT].name || filter->usmap.name)
12144 json_object_boolean_true_add(
12145 json_addr, "outboundPathPolicyConfig");
12146
12147 /* prefix-list */
12148 if (filter->plist[FILTER_IN].name)
12149 json_object_string_add(json_addr,
12150 "incomingUpdatePrefixFilterList",
12151 filter->plist[FILTER_IN].name);
12152 if (filter->plist[FILTER_OUT].name)
12153 json_object_string_add(json_addr,
12154 "outgoingUpdatePrefixFilterList",
12155 filter->plist[FILTER_OUT].name);
12156
12157 /* distribute-list */
12158 if (filter->dlist[FILTER_IN].name)
12159 json_object_string_add(
12160 json_addr, "incomingUpdateNetworkFilterList",
12161 filter->dlist[FILTER_IN].name);
12162 if (filter->dlist[FILTER_OUT].name)
12163 json_object_string_add(
12164 json_addr, "outgoingUpdateNetworkFilterList",
12165 filter->dlist[FILTER_OUT].name);
12166
12167 /* filter-list. */
12168 if (filter->aslist[FILTER_IN].name)
12169 json_object_string_add(json_addr,
12170 "incomingUpdateAsPathFilterList",
12171 filter->aslist[FILTER_IN].name);
12172 if (filter->aslist[FILTER_OUT].name)
12173 json_object_string_add(json_addr,
12174 "outgoingUpdateAsPathFilterList",
12175 filter->aslist[FILTER_OUT].name);
12176
12177 /* route-map. */
12178 if (filter->map[RMAP_IN].name)
12179 json_object_string_add(
12180 json_addr, "routeMapForIncomingAdvertisements",
12181 filter->map[RMAP_IN].name);
12182 if (filter->map[RMAP_OUT].name)
12183 json_object_string_add(
12184 json_addr, "routeMapForOutgoingAdvertisements",
12185 filter->map[RMAP_OUT].name);
12186
9dac9fc8 12187 /* ebgp-requires-policy (inbound) */
1d3fdccf 12188 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12189 && !bgp_inbound_policy_exists(p, filter))
12190 json_object_string_add(
12191 json_addr, "inboundEbgpRequiresPolicy",
12192 "Inbound updates discarded due to missing policy");
12193
12194 /* ebgp-requires-policy (outbound) */
1d3fdccf 12195 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12196 && (!bgp_outbound_policy_exists(p, filter)))
12197 json_object_string_add(
12198 json_addr, "outboundEbgpRequiresPolicy",
12199 "Outbound updates discarded due to missing policy");
12200
d62a17ae 12201 /* unsuppress-map */
12202 if (filter->usmap.name)
12203 json_object_string_add(json_addr,
12204 "selectiveUnsuppressRouteMap",
12205 filter->usmap.name);
12206
fa36596c
MK
12207 /* advertise-map */
12208 if (filter->advmap.aname) {
12209 json_advmap = json_object_new_object();
12210 json_object_string_add(json_advmap, "condition",
12211 filter->advmap.condition
12212 ? "EXIST"
12213 : "NON_EXIST");
12214 json_object_string_add(json_advmap, "conditionMap",
12215 filter->advmap.cname);
12216 json_object_string_add(json_advmap, "advertiseMap",
12217 filter->advmap.aname);
12218 json_object_string_add(json_advmap, "advertiseStatus",
12219 filter->advmap.update_type
12220 == ADVERTISE
12221 ? "Advertise"
12222 : "Withdraw");
12223 json_object_object_add(json_addr, "advertiseMap",
12224 json_advmap);
12225 }
12226
d62a17ae 12227 /* Receive prefix count */
12228 json_object_int_add(json_addr, "acceptedPrefixCounter",
12229 p->pcount[afi][safi]);
50e05855
AD
12230 if (paf && PAF_SUBGRP(paf))
12231 json_object_int_add(json_addr, "sentPrefixCounter",
12232 (PAF_SUBGRP(paf))->scount);
d62a17ae 12233
fde246e8
DA
12234 /* Maximum prefix */
12235 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12236 json_object_int_add(json_addr, "prefixOutAllowedMax",
12237 p->pmax_out[afi][safi]);
12238
d62a17ae 12239 /* Maximum prefix */
12240 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12241 json_object_int_add(json_addr, "prefixAllowedMax",
12242 p->pmax[afi][safi]);
12243 if (CHECK_FLAG(p->af_flags[afi][safi],
12244 PEER_FLAG_MAX_PREFIX_WARNING))
12245 json_object_boolean_true_add(
12246 json_addr, "prefixAllowedMaxWarning");
12247 json_object_int_add(json_addr,
12248 "prefixAllowedWarningThresh",
12249 p->pmax_threshold[afi][safi]);
12250 if (p->pmax_restart[afi][safi])
12251 json_object_int_add(
12252 json_addr,
12253 "prefixAllowedRestartIntervalMsecs",
12254 p->pmax_restart[afi][safi] * 60000);
12255 }
2986cac2 12256 json_object_object_add(json_neigh,
36235319 12257 get_afi_safi_str(afi, safi, true),
d62a17ae 12258 json_addr);
12259
12260 } else {
12261 filter = &p->filter[afi][safi];
12262
12263 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12264 get_afi_safi_str(afi, safi, false));
d62a17ae 12265
12266 if (peer_group_active(p))
12267 vty_out(vty, " %s peer-group member\n",
12268 p->group->name);
12269
12270 paf = peer_af_find(p, afi, safi);
12271 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12272 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12273 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12274 vty_out(vty, " Packet Queue length %d\n",
12275 bpacket_queue_virtual_length(paf));
12276 } else {
12277 vty_out(vty, " Not part of any update group\n");
12278 }
12279 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12280 || CHECK_FLAG(p->af_cap[afi][safi],
12281 PEER_CAP_ORF_PREFIX_SM_RCV)
12282 || CHECK_FLAG(p->af_cap[afi][safi],
12283 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12284 || CHECK_FLAG(p->af_cap[afi][safi],
12285 PEER_CAP_ORF_PREFIX_RM_ADV)
12286 || CHECK_FLAG(p->af_cap[afi][safi],
12287 PEER_CAP_ORF_PREFIX_RM_RCV)
12288 || CHECK_FLAG(p->af_cap[afi][safi],
12289 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12290 vty_out(vty, " AF-dependant capabilities:\n");
12291
12292 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12293 || CHECK_FLAG(p->af_cap[afi][safi],
12294 PEER_CAP_ORF_PREFIX_SM_RCV)
12295 || CHECK_FLAG(p->af_cap[afi][safi],
12296 PEER_CAP_ORF_PREFIX_RM_ADV)
12297 || CHECK_FLAG(p->af_cap[afi][safi],
12298 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12299 vty_out(vty,
12300 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12301 ORF_TYPE_PREFIX);
12302 bgp_show_peer_afi_orf_cap(
12303 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12304 PEER_CAP_ORF_PREFIX_RM_ADV,
12305 PEER_CAP_ORF_PREFIX_SM_RCV,
12306 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12307 }
12308 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12309 || CHECK_FLAG(p->af_cap[afi][safi],
12310 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12311 || CHECK_FLAG(p->af_cap[afi][safi],
12312 PEER_CAP_ORF_PREFIX_RM_ADV)
12313 || CHECK_FLAG(p->af_cap[afi][safi],
12314 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12315 vty_out(vty,
12316 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12317 ORF_TYPE_PREFIX_OLD);
12318 bgp_show_peer_afi_orf_cap(
12319 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12320 PEER_CAP_ORF_PREFIX_RM_ADV,
12321 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12322 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12323 }
12324
772270f3
QY
12325 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12326 p->host, afi, safi);
d62a17ae 12327 orf_pfx_count = prefix_bgp_show_prefix_list(
12328 NULL, afi, orf_pfx_name, use_json);
12329
12330 if (CHECK_FLAG(p->af_sflags[afi][safi],
12331 PEER_STATUS_ORF_PREFIX_SEND)
12332 || orf_pfx_count) {
12333 vty_out(vty, " Outbound Route Filter (ORF):");
12334 if (CHECK_FLAG(p->af_sflags[afi][safi],
12335 PEER_STATUS_ORF_PREFIX_SEND))
12336 vty_out(vty, " sent;");
12337 if (orf_pfx_count)
12338 vty_out(vty, " received (%d entries)",
12339 orf_pfx_count);
12340 vty_out(vty, "\n");
12341 }
12342 if (CHECK_FLAG(p->af_sflags[afi][safi],
12343 PEER_STATUS_ORF_WAIT_REFRESH))
12344 vty_out(vty,
12345 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12346
12347 if (CHECK_FLAG(p->af_flags[afi][safi],
12348 PEER_FLAG_REFLECTOR_CLIENT))
12349 vty_out(vty, " Route-Reflector Client\n");
12350 if (CHECK_FLAG(p->af_flags[afi][safi],
12351 PEER_FLAG_RSERVER_CLIENT))
12352 vty_out(vty, " Route-Server Client\n");
12353 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12354 vty_out(vty,
12355 " Inbound soft reconfiguration allowed\n");
12356
12357 if (CHECK_FLAG(p->af_flags[afi][safi],
12358 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12359 vty_out(vty,
12360 " Private AS numbers (all) replaced in updates to this neighbor\n");
12361 else if (CHECK_FLAG(p->af_flags[afi][safi],
12362 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12363 vty_out(vty,
12364 " Private AS numbers replaced in updates to this neighbor\n");
12365 else if (CHECK_FLAG(p->af_flags[afi][safi],
12366 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12367 vty_out(vty,
12368 " Private AS numbers (all) removed in updates to this neighbor\n");
12369 else if (CHECK_FLAG(p->af_flags[afi][safi],
12370 PEER_FLAG_REMOVE_PRIVATE_AS))
12371 vty_out(vty,
12372 " Private AS numbers removed in updates to this neighbor\n");
12373
dcc68b5e
MS
12374 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12375 vty_out(vty, " %s\n",
12376 bgp_addpath_names(p->addpath_type[afi][safi])
12377 ->human_description);
d62a17ae 12378
12379 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12380 vty_out(vty,
12381 " Override ASNs in outbound updates if aspath equals remote-as\n");
12382
12383 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12384 || CHECK_FLAG(p->af_flags[afi][safi],
12385 PEER_FLAG_FORCE_NEXTHOP_SELF))
12386 vty_out(vty, " NEXT_HOP is always this router\n");
12387 if (CHECK_FLAG(p->af_flags[afi][safi],
12388 PEER_FLAG_AS_PATH_UNCHANGED))
12389 vty_out(vty,
12390 " AS_PATH is propagated unchanged to this neighbor\n");
12391 if (CHECK_FLAG(p->af_flags[afi][safi],
12392 PEER_FLAG_NEXTHOP_UNCHANGED))
12393 vty_out(vty,
12394 " NEXT_HOP is propagated unchanged to this neighbor\n");
12395 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12396 vty_out(vty,
12397 " MED is propagated unchanged to this neighbor\n");
12398 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12399 || CHECK_FLAG(p->af_flags[afi][safi],
12400 PEER_FLAG_SEND_EXT_COMMUNITY)
12401 || CHECK_FLAG(p->af_flags[afi][safi],
12402 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12403 vty_out(vty,
12404 " Community attribute sent to this neighbor");
12405 if (CHECK_FLAG(p->af_flags[afi][safi],
12406 PEER_FLAG_SEND_COMMUNITY)
12407 && CHECK_FLAG(p->af_flags[afi][safi],
12408 PEER_FLAG_SEND_EXT_COMMUNITY)
12409 && CHECK_FLAG(p->af_flags[afi][safi],
12410 PEER_FLAG_SEND_LARGE_COMMUNITY))
12411 vty_out(vty, "(all)\n");
12412 else if (CHECK_FLAG(p->af_flags[afi][safi],
12413 PEER_FLAG_SEND_LARGE_COMMUNITY))
12414 vty_out(vty, "(large)\n");
12415 else if (CHECK_FLAG(p->af_flags[afi][safi],
12416 PEER_FLAG_SEND_EXT_COMMUNITY))
12417 vty_out(vty, "(extended)\n");
12418 else
12419 vty_out(vty, "(standard)\n");
12420 }
12421 if (CHECK_FLAG(p->af_flags[afi][safi],
12422 PEER_FLAG_DEFAULT_ORIGINATE)) {
12423 vty_out(vty, " Default information originate,");
12424
12425 if (p->default_rmap[afi][safi].name)
12426 vty_out(vty, " default route-map %s%s,",
12427 p->default_rmap[afi][safi].map ? "*"
12428 : "",
12429 p->default_rmap[afi][safi].name);
12430 if (paf && PAF_SUBGRP(paf)
12431 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12432 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12433 vty_out(vty, " default sent\n");
12434 else
12435 vty_out(vty, " default not sent\n");
12436 }
12437
dff8f48d
MK
12438 /* advertise-vni-all */
12439 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12440 if (is_evpn_enabled())
dff8f48d
MK
12441 vty_out(vty, " advertise-all-vni\n");
12442 }
12443
d62a17ae 12444 if (filter->plist[FILTER_IN].name
12445 || filter->dlist[FILTER_IN].name
12446 || filter->aslist[FILTER_IN].name
12447 || filter->map[RMAP_IN].name)
12448 vty_out(vty, " Inbound path policy configured\n");
12449 if (filter->plist[FILTER_OUT].name
12450 || filter->dlist[FILTER_OUT].name
12451 || filter->aslist[FILTER_OUT].name
12452 || filter->map[RMAP_OUT].name || filter->usmap.name)
12453 vty_out(vty, " Outbound path policy configured\n");
12454
12455 /* prefix-list */
12456 if (filter->plist[FILTER_IN].name)
12457 vty_out(vty,
12458 " Incoming update prefix filter list is %s%s\n",
12459 filter->plist[FILTER_IN].plist ? "*" : "",
12460 filter->plist[FILTER_IN].name);
12461 if (filter->plist[FILTER_OUT].name)
12462 vty_out(vty,
12463 " Outgoing update prefix filter list is %s%s\n",
12464 filter->plist[FILTER_OUT].plist ? "*" : "",
12465 filter->plist[FILTER_OUT].name);
12466
12467 /* distribute-list */
12468 if (filter->dlist[FILTER_IN].name)
12469 vty_out(vty,
12470 " Incoming update network filter list is %s%s\n",
12471 filter->dlist[FILTER_IN].alist ? "*" : "",
12472 filter->dlist[FILTER_IN].name);
12473 if (filter->dlist[FILTER_OUT].name)
12474 vty_out(vty,
12475 " Outgoing update network filter list is %s%s\n",
12476 filter->dlist[FILTER_OUT].alist ? "*" : "",
12477 filter->dlist[FILTER_OUT].name);
12478
12479 /* filter-list. */
12480 if (filter->aslist[FILTER_IN].name)
12481 vty_out(vty,
12482 " Incoming update AS path filter list is %s%s\n",
12483 filter->aslist[FILTER_IN].aslist ? "*" : "",
12484 filter->aslist[FILTER_IN].name);
12485 if (filter->aslist[FILTER_OUT].name)
12486 vty_out(vty,
12487 " Outgoing update AS path filter list is %s%s\n",
12488 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12489 filter->aslist[FILTER_OUT].name);
12490
12491 /* route-map. */
12492 if (filter->map[RMAP_IN].name)
12493 vty_out(vty,
12494 " Route map for incoming advertisements is %s%s\n",
12495 filter->map[RMAP_IN].map ? "*" : "",
12496 filter->map[RMAP_IN].name);
12497 if (filter->map[RMAP_OUT].name)
12498 vty_out(vty,
12499 " Route map for outgoing advertisements is %s%s\n",
12500 filter->map[RMAP_OUT].map ? "*" : "",
12501 filter->map[RMAP_OUT].name);
12502
9dac9fc8 12503 /* ebgp-requires-policy (inbound) */
1d3fdccf 12504 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12505 && !bgp_inbound_policy_exists(p, filter))
12506 vty_out(vty,
12507 " Inbound updates discarded due to missing policy\n");
12508
12509 /* ebgp-requires-policy (outbound) */
1d3fdccf 12510 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12511 && !bgp_outbound_policy_exists(p, filter))
12512 vty_out(vty,
12513 " Outbound updates discarded due to missing policy\n");
12514
d62a17ae 12515 /* unsuppress-map */
12516 if (filter->usmap.name)
12517 vty_out(vty,
12518 " Route map for selective unsuppress is %s%s\n",
12519 filter->usmap.map ? "*" : "",
12520 filter->usmap.name);
12521
7f7940e6
MK
12522 /* advertise-map */
12523 if (filter->advmap.aname && filter->advmap.cname)
12524 vty_out(vty,
12525 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12526 filter->advmap.condition ? "EXIST"
12527 : "NON_EXIST",
12528 filter->advmap.cmap ? "*" : "",
12529 filter->advmap.cname,
12530 filter->advmap.amap ? "*" : "",
12531 filter->advmap.aname,
fa36596c 12532 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12533 ? "Advertise"
12534 : "Withdraw");
7f7940e6 12535
d62a17ae 12536 /* Receive prefix count */
6cde4b45 12537 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12538 p->pcount[afi][safi]);
d62a17ae 12539
fde246e8
DA
12540 /* maximum-prefix-out */
12541 if (CHECK_FLAG(p->af_flags[afi][safi],
12542 PEER_FLAG_MAX_PREFIX_OUT))
12543 vty_out(vty,
6cde4b45 12544 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12545 p->pmax_out[afi][safi]);
12546
d62a17ae 12547 /* Maximum prefix */
12548 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12549 vty_out(vty,
6cde4b45 12550 " Maximum prefixes allowed %u%s\n",
d62a17ae 12551 p->pmax[afi][safi],
12552 CHECK_FLAG(p->af_flags[afi][safi],
12553 PEER_FLAG_MAX_PREFIX_WARNING)
12554 ? " (warning-only)"
12555 : "");
12556 vty_out(vty, " Threshold for warning message %d%%",
12557 p->pmax_threshold[afi][safi]);
12558 if (p->pmax_restart[afi][safi])
12559 vty_out(vty, ", restart interval %d min",
12560 p->pmax_restart[afi][safi]);
12561 vty_out(vty, "\n");
12562 }
12563
12564 vty_out(vty, "\n");
12565 }
12566}
12567
9f049418 12568static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12569 json_object *json)
718e3744 12570{
d62a17ae 12571 struct bgp *bgp;
12572 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12573 char timebuf[BGP_UPTIME_LEN];
12574 char dn_flag[2];
d62a17ae 12575 afi_t afi;
12576 safi_t safi;
d7c0a89a
QY
12577 uint16_t i;
12578 uint8_t *msg;
d62a17ae 12579 json_object *json_neigh = NULL;
12580 time_t epoch_tbuf;
718e3744 12581
d62a17ae 12582 bgp = p->bgp;
12583
12584 if (use_json)
12585 json_neigh = json_object_new_object();
12586
12587 memset(dn_flag, '\0', sizeof(dn_flag));
12588 if (!p->conf_if && peer_dynamic_neighbor(p))
12589 dn_flag[0] = '*';
12590
12591 if (!use_json) {
12592 if (p->conf_if) /* Configured interface name. */
12593 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12594 BGP_PEER_SU_UNSPEC(p)
12595 ? "None"
12596 : sockunion2str(&p->su, buf,
12597 SU_ADDRSTRLEN));
12598 else /* Configured IP address. */
12599 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12600 p->host);
12601 }
12602
12603 if (use_json) {
12604 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12605 json_object_string_add(json_neigh, "bgpNeighborAddr",
12606 "none");
12607 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12608 json_object_string_add(
12609 json_neigh, "bgpNeighborAddr",
12610 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12611
12612 json_object_int_add(json_neigh, "remoteAs", p->as);
12613
12614 if (p->change_local_as)
12615 json_object_int_add(json_neigh, "localAs",
12616 p->change_local_as);
12617 else
12618 json_object_int_add(json_neigh, "localAs", p->local_as);
12619
12620 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12621 json_object_boolean_true_add(json_neigh,
12622 "localAsNoPrepend");
12623
12624 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12625 json_object_boolean_true_add(json_neigh,
12626 "localAsReplaceAs");
12627 } else {
12628 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12629 || (p->as_type == AS_INTERNAL))
12630 vty_out(vty, "remote AS %u, ", p->as);
12631 else
12632 vty_out(vty, "remote AS Unspecified, ");
12633 vty_out(vty, "local AS %u%s%s, ",
12634 p->change_local_as ? p->change_local_as : p->local_as,
12635 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12636 ? " no-prepend"
12637 : "",
12638 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12639 ? " replace-as"
12640 : "");
12641 }
faa16034
DS
12642 /* peer type internal or confed-internal */
12643 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12644 if (use_json) {
12645 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12646 json_object_boolean_true_add(
12647 json_neigh, "nbrConfedInternalLink");
12648 else
12649 json_object_boolean_true_add(json_neigh,
12650 "nbrInternalLink");
12651 } else {
12652 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12653 vty_out(vty, "confed-internal link\n");
12654 else
12655 vty_out(vty, "internal link\n");
12656 }
faa16034
DS
12657 /* peer type external or confed-external */
12658 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12659 if (use_json) {
12660 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12661 json_object_boolean_true_add(
12662 json_neigh, "nbrConfedExternalLink");
12663 else
12664 json_object_boolean_true_add(json_neigh,
12665 "nbrExternalLink");
12666 } else {
12667 if (bgp_confederation_peers_check(bgp, p->as))
12668 vty_out(vty, "confed-external link\n");
12669 else
12670 vty_out(vty, "external link\n");
12671 }
faa16034
DS
12672 } else {
12673 if (use_json)
12674 json_object_boolean_true_add(json_neigh,
12675 "nbrUnspecifiedLink");
12676 else
12677 vty_out(vty, "unspecified link\n");
d62a17ae 12678 }
12679
12680 /* Description. */
12681 if (p->desc) {
12682 if (use_json)
12683 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12684 else
12685 vty_out(vty, " Description: %s\n", p->desc);
12686 }
12687
12688 if (p->hostname) {
12689 if (use_json) {
12690 if (p->hostname)
12691 json_object_string_add(json_neigh, "hostname",
12692 p->hostname);
12693
12694 if (p->domainname)
12695 json_object_string_add(json_neigh, "domainname",
12696 p->domainname);
12697 } else {
12698 if (p->domainname && (p->domainname[0] != '\0'))
12699 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12700 p->domainname);
12701 else
12702 vty_out(vty, "Hostname: %s\n", p->hostname);
12703 }
12704 }
12705
12706 /* Peer-group */
12707 if (p->group) {
12708 if (use_json) {
12709 json_object_string_add(json_neigh, "peerGroup",
12710 p->group->name);
12711
12712 if (dn_flag[0]) {
12713 struct prefix prefix, *range = NULL;
12714
0154d8ce
DS
12715 if (sockunion2hostprefix(&(p->su), &prefix))
12716 range = peer_group_lookup_dynamic_neighbor_range(
12717 p->group, &prefix);
d62a17ae 12718
12719 if (range) {
12720 prefix2str(range, buf1, sizeof(buf1));
12721 json_object_string_add(
12722 json_neigh,
12723 "peerSubnetRangeGroup", buf1);
12724 }
12725 }
12726 } else {
12727 vty_out(vty,
12728 " Member of peer-group %s for session parameters\n",
12729 p->group->name);
12730
12731 if (dn_flag[0]) {
12732 struct prefix prefix, *range = NULL;
12733
0154d8ce
DS
12734 if (sockunion2hostprefix(&(p->su), &prefix))
12735 range = peer_group_lookup_dynamic_neighbor_range(
12736 p->group, &prefix);
d62a17ae 12737
12738 if (range) {
d62a17ae 12739 vty_out(vty,
1b78780b
DL
12740 " Belongs to the subnet range group: %pFX\n",
12741 range);
d62a17ae 12742 }
12743 }
12744 }
12745 }
12746
12747 if (use_json) {
12748 /* Administrative shutdown. */
cb9196e7
DS
12749 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12750 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12751 json_object_boolean_true_add(json_neigh,
12752 "adminShutDown");
12753
12754 /* BGP Version. */
12755 json_object_int_add(json_neigh, "bgpVersion", 4);
12756 json_object_string_add(
12757 json_neigh, "remoteRouterId",
12758 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
12759 json_object_string_add(
12760 json_neigh, "localRouterId",
12761 inet_ntop(AF_INET, &bgp->router_id, buf1,
12762 sizeof(buf1)));
d62a17ae 12763
12764 /* Confederation */
12765 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12766 && bgp_confederation_peers_check(bgp, p->as))
12767 json_object_boolean_true_add(json_neigh,
12768 "nbrCommonAdmin");
12769
12770 /* Status. */
12771 json_object_string_add(
12772 json_neigh, "bgpState",
12773 lookup_msg(bgp_status_msg, p->status, NULL));
12774
12775 if (p->status == Established) {
12776 time_t uptime;
d62a17ae 12777
12778 uptime = bgp_clock();
12779 uptime -= p->uptime;
d62a17ae 12780 epoch_tbuf = time(NULL) - uptime;
12781
d3c7efed
DS
12782 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12783 uptime * 1000);
d62a17ae 12784 json_object_string_add(json_neigh, "bgpTimerUpString",
12785 peer_uptime(p->uptime, timebuf,
12786 BGP_UPTIME_LEN, 0,
12787 NULL));
12788 json_object_int_add(json_neigh,
12789 "bgpTimerUpEstablishedEpoch",
12790 epoch_tbuf);
12791 }
12792
12793 else if (p->status == Active) {
12794 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12795 json_object_string_add(json_neigh, "bgpStateIs",
12796 "passive");
12797 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12798 json_object_string_add(json_neigh, "bgpStateIs",
12799 "passiveNSF");
12800 }
12801
12802 /* read timer */
12803 time_t uptime;
a2700b50 12804 struct tm tm;
d62a17ae 12805
12806 uptime = bgp_clock();
12807 uptime -= p->readtime;
a2700b50
MS
12808 gmtime_r(&uptime, &tm);
12809
d62a17ae 12810 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12811 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12812 + (tm.tm_hour * 3600000));
d62a17ae 12813
12814 uptime = bgp_clock();
12815 uptime -= p->last_write;
a2700b50
MS
12816 gmtime_r(&uptime, &tm);
12817
d62a17ae 12818 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12819 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12820 + (tm.tm_hour * 3600000));
d62a17ae 12821
12822 uptime = bgp_clock();
12823 uptime -= p->update_time;
a2700b50
MS
12824 gmtime_r(&uptime, &tm);
12825
d62a17ae 12826 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12827 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12828 + (tm.tm_hour * 3600000));
d62a17ae 12829
12830 /* Configured timer values. */
12831 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12832 p->v_holdtime * 1000);
12833 json_object_int_add(json_neigh,
12834 "bgpTimerKeepAliveIntervalMsecs",
12835 p->v_keepalive * 1000);
d43114f3
DS
12836 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12837 json_object_int_add(json_neigh,
12838 "bgpTimerDelayOpenTimeMsecs",
12839 p->v_delayopen * 1000);
12840 }
12841
b90a8e13 12842 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12843 json_object_int_add(json_neigh,
12844 "bgpTimerConfiguredHoldTimeMsecs",
12845 p->holdtime * 1000);
12846 json_object_int_add(
12847 json_neigh,
12848 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12849 p->keepalive * 1000);
5d5393b9
DL
12850 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12851 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12852 json_object_int_add(json_neigh,
12853 "bgpTimerConfiguredHoldTimeMsecs",
12854 bgp->default_holdtime);
12855 json_object_int_add(
12856 json_neigh,
12857 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12858 bgp->default_keepalive);
d62a17ae 12859 }
12860 } else {
12861 /* Administrative shutdown. */
cb9196e7
DS
12862 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12863 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12864 vty_out(vty, " Administratively shut down\n");
12865
12866 /* BGP Version. */
12867 vty_out(vty, " BGP version 4");
0e38aeb4 12868 vty_out(vty, ", remote router ID %s",
d62a17ae 12869 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12870 vty_out(vty, ", local router ID %s\n",
12871 inet_ntop(AF_INET, &bgp->router_id, buf1,
12872 sizeof(buf1)));
d62a17ae 12873
12874 /* Confederation */
12875 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12876 && bgp_confederation_peers_check(bgp, p->as))
12877 vty_out(vty,
12878 " Neighbor under common administration\n");
12879
12880 /* Status. */
12881 vty_out(vty, " BGP state = %s",
12882 lookup_msg(bgp_status_msg, p->status, NULL));
12883
12884 if (p->status == Established)
12885 vty_out(vty, ", up for %8s",
12886 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12887 0, NULL));
12888
12889 else if (p->status == Active) {
12890 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12891 vty_out(vty, " (passive)");
12892 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12893 vty_out(vty, " (NSF passive)");
12894 }
12895 vty_out(vty, "\n");
12896
12897 /* read timer */
12898 vty_out(vty, " Last read %s",
12899 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12900 NULL));
12901 vty_out(vty, ", Last write %s\n",
12902 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12903 NULL));
12904
12905 /* Configured timer values. */
12906 vty_out(vty,
12907 " Hold time is %d, keepalive interval is %d seconds\n",
12908 p->v_holdtime, p->v_keepalive);
b90a8e13 12909 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12910 vty_out(vty, " Configured hold time is %d",
12911 p->holdtime);
12912 vty_out(vty, ", keepalive interval is %d seconds\n",
12913 p->keepalive);
5d5393b9
DL
12914 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12915 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12916 vty_out(vty, " Configured hold time is %d",
12917 bgp->default_holdtime);
12918 vty_out(vty, ", keepalive interval is %d seconds\n",
12919 bgp->default_keepalive);
d62a17ae 12920 }
d43114f3
DS
12921 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12922 vty_out(vty,
12923 " Configured DelayOpenTime is %d seconds\n",
12924 p->delayopen);
d62a17ae 12925 }
12926 /* Capability. */
12927 if (p->status == Established) {
12928 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12929 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12930 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12931 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12932 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12933 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12934 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12935 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12936 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12937 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12938 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12939 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 12940 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12941 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 12942 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12943 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 12944 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12945 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 12946 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12947 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12948 if (use_json) {
12949 json_object *json_cap = NULL;
12950
12951 json_cap = json_object_new_object();
12952
12953 /* AS4 */
12954 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12955 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12956 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12957 && CHECK_FLAG(p->cap,
12958 PEER_CAP_AS4_RCV))
12959 json_object_string_add(
12960 json_cap, "4byteAs",
12961 "advertisedAndReceived");
12962 else if (CHECK_FLAG(p->cap,
12963 PEER_CAP_AS4_ADV))
12964 json_object_string_add(
12965 json_cap, "4byteAs",
12966 "advertised");
12967 else if (CHECK_FLAG(p->cap,
12968 PEER_CAP_AS4_RCV))
12969 json_object_string_add(
12970 json_cap, "4byteAs",
12971 "received");
12972 }
12973
12974 /* AddPath */
12975 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12976 || CHECK_FLAG(p->cap,
12977 PEER_CAP_ADDPATH_ADV)) {
12978 json_object *json_add = NULL;
12979 const char *print_store;
12980
12981 json_add = json_object_new_object();
12982
05c7a1cc
QY
12983 FOREACH_AFI_SAFI (afi, safi) {
12984 json_object *json_sub = NULL;
12985 json_sub =
12986 json_object_new_object();
5cb5f4d0
DD
12987 print_store = get_afi_safi_str(
12988 afi, safi, true);
d62a17ae 12989
05c7a1cc
QY
12990 if (CHECK_FLAG(
12991 p->af_cap[afi]
12992 [safi],
12993 PEER_CAP_ADDPATH_AF_TX_ADV)
12994 || CHECK_FLAG(
12995 p->af_cap[afi]
12996 [safi],
12997 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 12998 if (CHECK_FLAG(
12999 p->af_cap
13000 [afi]
13001 [safi],
13002 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 13003 && CHECK_FLAG(
d62a17ae 13004 p->af_cap
13005 [afi]
13006 [safi],
05c7a1cc
QY
13007 PEER_CAP_ADDPATH_AF_TX_RCV))
13008 json_object_boolean_true_add(
13009 json_sub,
13010 "txAdvertisedAndReceived");
13011 else if (
13012 CHECK_FLAG(
13013 p->af_cap
13014 [afi]
13015 [safi],
13016 PEER_CAP_ADDPATH_AF_TX_ADV))
13017 json_object_boolean_true_add(
13018 json_sub,
13019 "txAdvertised");
13020 else if (
13021 CHECK_FLAG(
13022 p->af_cap
13023 [afi]
13024 [safi],
13025 PEER_CAP_ADDPATH_AF_TX_RCV))
13026 json_object_boolean_true_add(
13027 json_sub,
13028 "txReceived");
13029 }
d62a17ae 13030
05c7a1cc
QY
13031 if (CHECK_FLAG(
13032 p->af_cap[afi]
13033 [safi],
13034 PEER_CAP_ADDPATH_AF_RX_ADV)
13035 || CHECK_FLAG(
13036 p->af_cap[afi]
13037 [safi],
13038 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 13039 if (CHECK_FLAG(
13040 p->af_cap
13041 [afi]
13042 [safi],
13043 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 13044 && CHECK_FLAG(
d62a17ae 13045 p->af_cap
13046 [afi]
13047 [safi],
13048 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
13049 json_object_boolean_true_add(
13050 json_sub,
13051 "rxAdvertisedAndReceived");
13052 else if (
13053 CHECK_FLAG(
13054 p->af_cap
13055 [afi]
13056 [safi],
13057 PEER_CAP_ADDPATH_AF_RX_ADV))
13058 json_object_boolean_true_add(
13059 json_sub,
13060 "rxAdvertised");
13061 else if (
13062 CHECK_FLAG(
13063 p->af_cap
13064 [afi]
13065 [safi],
13066 PEER_CAP_ADDPATH_AF_RX_RCV))
13067 json_object_boolean_true_add(
13068 json_sub,
13069 "rxReceived");
d62a17ae 13070 }
13071
05c7a1cc
QY
13072 if (CHECK_FLAG(
13073 p->af_cap[afi]
13074 [safi],
13075 PEER_CAP_ADDPATH_AF_TX_ADV)
13076 || CHECK_FLAG(
13077 p->af_cap[afi]
13078 [safi],
13079 PEER_CAP_ADDPATH_AF_TX_RCV)
13080 || CHECK_FLAG(
13081 p->af_cap[afi]
13082 [safi],
13083 PEER_CAP_ADDPATH_AF_RX_ADV)
13084 || CHECK_FLAG(
13085 p->af_cap[afi]
13086 [safi],
13087 PEER_CAP_ADDPATH_AF_RX_RCV))
13088 json_object_object_add(
13089 json_add,
13090 print_store,
13091 json_sub);
13092 else
13093 json_object_free(
13094 json_sub);
13095 }
13096
d62a17ae 13097 json_object_object_add(
13098 json_cap, "addPath", json_add);
13099 }
13100
13101 /* Dynamic */
13102 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13103 || CHECK_FLAG(p->cap,
13104 PEER_CAP_DYNAMIC_ADV)) {
13105 if (CHECK_FLAG(p->cap,
13106 PEER_CAP_DYNAMIC_ADV)
13107 && CHECK_FLAG(p->cap,
13108 PEER_CAP_DYNAMIC_RCV))
13109 json_object_string_add(
13110 json_cap, "dynamic",
13111 "advertisedAndReceived");
13112 else if (CHECK_FLAG(
13113 p->cap,
13114 PEER_CAP_DYNAMIC_ADV))
13115 json_object_string_add(
13116 json_cap, "dynamic",
13117 "advertised");
13118 else if (CHECK_FLAG(
13119 p->cap,
13120 PEER_CAP_DYNAMIC_RCV))
13121 json_object_string_add(
13122 json_cap, "dynamic",
13123 "received");
13124 }
13125
13126 /* Extended nexthop */
13127 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13128 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13129 json_object *json_nxt = NULL;
13130 const char *print_store;
13131
13132
13133 if (CHECK_FLAG(p->cap,
13134 PEER_CAP_ENHE_ADV)
13135 && CHECK_FLAG(p->cap,
13136 PEER_CAP_ENHE_RCV))
13137 json_object_string_add(
13138 json_cap,
13139 "extendedNexthop",
13140 "advertisedAndReceived");
13141 else if (CHECK_FLAG(p->cap,
13142 PEER_CAP_ENHE_ADV))
13143 json_object_string_add(
13144 json_cap,
13145 "extendedNexthop",
13146 "advertised");
13147 else if (CHECK_FLAG(p->cap,
13148 PEER_CAP_ENHE_RCV))
13149 json_object_string_add(
13150 json_cap,
13151 "extendedNexthop",
13152 "received");
13153
13154 if (CHECK_FLAG(p->cap,
13155 PEER_CAP_ENHE_RCV)) {
13156 json_nxt =
13157 json_object_new_object();
13158
13159 for (safi = SAFI_UNICAST;
13160 safi < SAFI_MAX; safi++) {
13161 if (CHECK_FLAG(
13162 p->af_cap
13163 [AFI_IP]
13164 [safi],
13165 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 13166 print_store = get_afi_safi_str(
d62a17ae 13167 AFI_IP,
5cb5f4d0 13168 safi, true);
d62a17ae 13169 json_object_string_add(
13170 json_nxt,
13171 print_store,
54f29523 13172 "recieved"); /* misspelled for compatibility */
d62a17ae 13173 }
13174 }
13175 json_object_object_add(
13176 json_cap,
13177 "extendedNexthopFamililesByPeer",
13178 json_nxt);
13179 }
13180 }
13181
13182 /* Route Refresh */
13183 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13184 || CHECK_FLAG(p->cap,
13185 PEER_CAP_REFRESH_NEW_RCV)
13186 || CHECK_FLAG(p->cap,
13187 PEER_CAP_REFRESH_OLD_RCV)) {
13188 if (CHECK_FLAG(p->cap,
13189 PEER_CAP_REFRESH_ADV)
13190 && (CHECK_FLAG(
13191 p->cap,
13192 PEER_CAP_REFRESH_NEW_RCV)
13193 || CHECK_FLAG(
13194 p->cap,
13195 PEER_CAP_REFRESH_OLD_RCV))) {
13196 if (CHECK_FLAG(
13197 p->cap,
13198 PEER_CAP_REFRESH_OLD_RCV)
13199 && CHECK_FLAG(
13200 p->cap,
13201 PEER_CAP_REFRESH_NEW_RCV))
13202 json_object_string_add(
13203 json_cap,
13204 "routeRefresh",
13205 "advertisedAndReceivedOldNew");
13206 else {
13207 if (CHECK_FLAG(
13208 p->cap,
13209 PEER_CAP_REFRESH_OLD_RCV))
13210 json_object_string_add(
13211 json_cap,
13212 "routeRefresh",
13213 "advertisedAndReceivedOld");
13214 else
13215 json_object_string_add(
13216 json_cap,
13217 "routeRefresh",
13218 "advertisedAndReceivedNew");
13219 }
13220 } else if (
13221 CHECK_FLAG(
13222 p->cap,
13223 PEER_CAP_REFRESH_ADV))
13224 json_object_string_add(
13225 json_cap,
13226 "routeRefresh",
13227 "advertised");
13228 else if (
13229 CHECK_FLAG(
13230 p->cap,
13231 PEER_CAP_REFRESH_NEW_RCV)
13232 || CHECK_FLAG(
13233 p->cap,
13234 PEER_CAP_REFRESH_OLD_RCV))
13235 json_object_string_add(
13236 json_cap,
13237 "routeRefresh",
13238 "received");
13239 }
13240
9af52ccf
DA
13241 /* Enhanced Route Refresh */
13242 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13243 || CHECK_FLAG(p->cap,
13244 PEER_CAP_ENHANCED_RR_RCV)) {
13245 if (CHECK_FLAG(p->cap,
13246 PEER_CAP_ENHANCED_RR_ADV)
13247 && CHECK_FLAG(
13248 p->cap,
13249 PEER_CAP_ENHANCED_RR_RCV))
13250 json_object_string_add(
13251 json_cap,
13252 "enhancedRouteRefresh",
13253 "advertisedAndReceived");
13254 else if (
13255 CHECK_FLAG(
13256 p->cap,
13257 PEER_CAP_ENHANCED_RR_ADV))
13258 json_object_string_add(
13259 json_cap,
13260 "enhancedRouteRefresh",
13261 "advertised");
13262 else if (
13263 CHECK_FLAG(
13264 p->cap,
13265 PEER_CAP_ENHANCED_RR_RCV))
13266 json_object_string_add(
13267 json_cap,
13268 "enhancedRouteRefresh",
13269 "received");
13270 }
13271
d62a17ae 13272 /* Multiprotocol Extensions */
13273 json_object *json_multi = NULL;
13274 json_multi = json_object_new_object();
13275
05c7a1cc
QY
13276 FOREACH_AFI_SAFI (afi, safi) {
13277 if (p->afc_adv[afi][safi]
13278 || p->afc_recv[afi][safi]) {
13279 json_object *json_exten = NULL;
13280 json_exten =
13281 json_object_new_object();
13282
d62a17ae 13283 if (p->afc_adv[afi][safi]
05c7a1cc
QY
13284 && p->afc_recv[afi][safi])
13285 json_object_boolean_true_add(
13286 json_exten,
13287 "advertisedAndReceived");
13288 else if (p->afc_adv[afi][safi])
13289 json_object_boolean_true_add(
13290 json_exten,
13291 "advertised");
13292 else if (p->afc_recv[afi][safi])
13293 json_object_boolean_true_add(
13294 json_exten,
13295 "received");
d62a17ae 13296
05c7a1cc
QY
13297 json_object_object_add(
13298 json_multi,
5cb5f4d0
DD
13299 get_afi_safi_str(afi,
13300 safi,
13301 true),
05c7a1cc 13302 json_exten);
d62a17ae 13303 }
13304 }
13305 json_object_object_add(
13306 json_cap, "multiprotocolExtensions",
13307 json_multi);
13308
d77114b7 13309 /* Hostname capabilities */
60466a63 13310 json_object *json_hname = NULL;
d77114b7
MK
13311
13312 json_hname = json_object_new_object();
13313
13314 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13315 json_object_string_add(
60466a63
QY
13316 json_hname, "advHostName",
13317 bgp->peer_self->hostname
13318 ? bgp->peer_self
13319 ->hostname
d77114b7
MK
13320 : "n/a");
13321 json_object_string_add(
60466a63
QY
13322 json_hname, "advDomainName",
13323 bgp->peer_self->domainname
13324 ? bgp->peer_self
13325 ->domainname
d77114b7
MK
13326 : "n/a");
13327 }
13328
13329
13330 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13331 json_object_string_add(
60466a63
QY
13332 json_hname, "rcvHostName",
13333 p->hostname ? p->hostname
13334 : "n/a");
d77114b7 13335 json_object_string_add(
60466a63
QY
13336 json_hname, "rcvDomainName",
13337 p->domainname ? p->domainname
13338 : "n/a");
d77114b7
MK
13339 }
13340
60466a63 13341 json_object_object_add(json_cap, "hostName",
d77114b7
MK
13342 json_hname);
13343
d62a17ae 13344 /* Gracefull Restart */
13345 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13346 || CHECK_FLAG(p->cap,
13347 PEER_CAP_RESTART_ADV)) {
13348 if (CHECK_FLAG(p->cap,
13349 PEER_CAP_RESTART_ADV)
13350 && CHECK_FLAG(p->cap,
13351 PEER_CAP_RESTART_RCV))
13352 json_object_string_add(
13353 json_cap,
13354 "gracefulRestart",
13355 "advertisedAndReceived");
13356 else if (CHECK_FLAG(
13357 p->cap,
13358 PEER_CAP_RESTART_ADV))
13359 json_object_string_add(
13360 json_cap,
13361 "gracefulRestartCapability",
13362 "advertised");
13363 else if (CHECK_FLAG(
13364 p->cap,
13365 PEER_CAP_RESTART_RCV))
13366 json_object_string_add(
13367 json_cap,
13368 "gracefulRestartCapability",
13369 "received");
13370
13371 if (CHECK_FLAG(p->cap,
13372 PEER_CAP_RESTART_RCV)) {
13373 int restart_af_count = 0;
13374 json_object *json_restart =
13375 NULL;
13376 json_restart =
13377 json_object_new_object();
13378
13379 json_object_int_add(
13380 json_cap,
13381 "gracefulRestartRemoteTimerMsecs",
13382 p->v_gr_restart * 1000);
13383
05c7a1cc
QY
13384 FOREACH_AFI_SAFI (afi, safi) {
13385 if (CHECK_FLAG(
13386 p->af_cap
13387 [afi]
13388 [safi],
13389 PEER_CAP_RESTART_AF_RCV)) {
13390 json_object *
13391 json_sub =
13392 NULL;
13393 json_sub =
13394 json_object_new_object();
13395
d62a17ae 13396 if (CHECK_FLAG(
13397 p->af_cap
13398 [afi]
13399 [safi],
05c7a1cc
QY
13400 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13401 json_object_boolean_true_add(
13402 json_sub,
13403 "preserved");
13404 restart_af_count++;
13405 json_object_object_add(
13406 json_restart,
5cb5f4d0 13407 get_afi_safi_str(
05c7a1cc 13408 afi,
5cb5f4d0
DD
13409 safi,
13410 true),
05c7a1cc 13411 json_sub);
d62a17ae 13412 }
13413 }
13414 if (!restart_af_count) {
13415 json_object_string_add(
13416 json_cap,
13417 "addressFamiliesByPeer",
13418 "none");
13419 json_object_free(
13420 json_restart);
13421 } else
13422 json_object_object_add(
13423 json_cap,
13424 "addressFamiliesByPeer",
13425 json_restart);
13426 }
13427 }
13428 json_object_object_add(json_neigh,
13429 "neighborCapabilities",
13430 json_cap);
13431 } else {
13432 vty_out(vty, " Neighbor capabilities:\n");
13433
13434 /* AS4 */
13435 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13436 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13437 vty_out(vty, " 4 Byte AS:");
13438 if (CHECK_FLAG(p->cap,
13439 PEER_CAP_AS4_ADV))
13440 vty_out(vty, " advertised");
13441 if (CHECK_FLAG(p->cap,
13442 PEER_CAP_AS4_RCV))
13443 vty_out(vty, " %sreceived",
13444 CHECK_FLAG(
13445 p->cap,
13446 PEER_CAP_AS4_ADV)
13447 ? "and "
13448 : "");
13449 vty_out(vty, "\n");
13450 }
13451
13452 /* AddPath */
13453 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13454 || CHECK_FLAG(p->cap,
13455 PEER_CAP_ADDPATH_ADV)) {
13456 vty_out(vty, " AddPath:\n");
13457
05c7a1cc
QY
13458 FOREACH_AFI_SAFI (afi, safi) {
13459 if (CHECK_FLAG(
13460 p->af_cap[afi]
13461 [safi],
13462 PEER_CAP_ADDPATH_AF_TX_ADV)
13463 || CHECK_FLAG(
13464 p->af_cap[afi]
13465 [safi],
13466 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13467 vty_out(vty,
13468 " %s: TX ",
5cb5f4d0 13469 get_afi_safi_str(
05c7a1cc 13470 afi,
5cb5f4d0
DD
13471 safi,
13472 false));
05c7a1cc 13473
d62a17ae 13474 if (CHECK_FLAG(
13475 p->af_cap
13476 [afi]
13477 [safi],
05c7a1cc 13478 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 13479 vty_out(vty,
05c7a1cc 13480 "advertised %s",
5cb5f4d0 13481 get_afi_safi_str(
d62a17ae 13482 afi,
5cb5f4d0
DD
13483 safi,
13484 false));
d62a17ae 13485
05c7a1cc
QY
13486 if (CHECK_FLAG(
13487 p->af_cap
13488 [afi]
13489 [safi],
13490 PEER_CAP_ADDPATH_AF_TX_RCV))
13491 vty_out(vty,
13492 "%sreceived",
13493 CHECK_FLAG(
13494 p->af_cap
13495 [afi]
13496 [safi],
13497 PEER_CAP_ADDPATH_AF_TX_ADV)
13498 ? " and "
13499 : "");
d62a17ae 13500
05c7a1cc
QY
13501 vty_out(vty, "\n");
13502 }
d62a17ae 13503
05c7a1cc
QY
13504 if (CHECK_FLAG(
13505 p->af_cap[afi]
13506 [safi],
13507 PEER_CAP_ADDPATH_AF_RX_ADV)
13508 || CHECK_FLAG(
13509 p->af_cap[afi]
13510 [safi],
13511 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13512 vty_out(vty,
13513 " %s: RX ",
5cb5f4d0 13514 get_afi_safi_str(
05c7a1cc 13515 afi,
5cb5f4d0
DD
13516 safi,
13517 false));
d62a17ae 13518
13519 if (CHECK_FLAG(
13520 p->af_cap
13521 [afi]
13522 [safi],
05c7a1cc 13523 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 13524 vty_out(vty,
05c7a1cc 13525 "advertised %s",
5cb5f4d0 13526 get_afi_safi_str(
d62a17ae 13527 afi,
5cb5f4d0
DD
13528 safi,
13529 false));
d62a17ae 13530
05c7a1cc
QY
13531 if (CHECK_FLAG(
13532 p->af_cap
13533 [afi]
13534 [safi],
13535 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 13536 vty_out(vty,
05c7a1cc
QY
13537 "%sreceived",
13538 CHECK_FLAG(
13539 p->af_cap
13540 [afi]
13541 [safi],
13542 PEER_CAP_ADDPATH_AF_RX_ADV)
13543 ? " and "
13544 : "");
13545
13546 vty_out(vty, "\n");
d62a17ae 13547 }
05c7a1cc 13548 }
d62a17ae 13549 }
13550
13551 /* Dynamic */
13552 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13553 || CHECK_FLAG(p->cap,
13554 PEER_CAP_DYNAMIC_ADV)) {
13555 vty_out(vty, " Dynamic:");
13556 if (CHECK_FLAG(p->cap,
13557 PEER_CAP_DYNAMIC_ADV))
13558 vty_out(vty, " advertised");
13559 if (CHECK_FLAG(p->cap,
13560 PEER_CAP_DYNAMIC_RCV))
13561 vty_out(vty, " %sreceived",
13562 CHECK_FLAG(
13563 p->cap,
13564 PEER_CAP_DYNAMIC_ADV)
13565 ? "and "
13566 : "");
13567 vty_out(vty, "\n");
13568 }
13569
13570 /* Extended nexthop */
13571 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13572 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13573 vty_out(vty, " Extended nexthop:");
13574 if (CHECK_FLAG(p->cap,
13575 PEER_CAP_ENHE_ADV))
13576 vty_out(vty, " advertised");
13577 if (CHECK_FLAG(p->cap,
13578 PEER_CAP_ENHE_RCV))
13579 vty_out(vty, " %sreceived",
13580 CHECK_FLAG(
13581 p->cap,
13582 PEER_CAP_ENHE_ADV)
13583 ? "and "
13584 : "");
13585 vty_out(vty, "\n");
13586
13587 if (CHECK_FLAG(p->cap,
13588 PEER_CAP_ENHE_RCV)) {
13589 vty_out(vty,
13590 " Address families by peer:\n ");
13591 for (safi = SAFI_UNICAST;
13592 safi < SAFI_MAX; safi++)
13593 if (CHECK_FLAG(
13594 p->af_cap
13595 [AFI_IP]
13596 [safi],
13597 PEER_CAP_ENHE_AF_RCV))
13598 vty_out(vty,
13599 " %s\n",
5cb5f4d0 13600 get_afi_safi_str(
d62a17ae 13601 AFI_IP,
5cb5f4d0
DD
13602 safi,
13603 false));
d62a17ae 13604 }
13605 }
13606
13607 /* Route Refresh */
13608 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13609 || CHECK_FLAG(p->cap,
13610 PEER_CAP_REFRESH_NEW_RCV)
13611 || CHECK_FLAG(p->cap,
13612 PEER_CAP_REFRESH_OLD_RCV)) {
13613 vty_out(vty, " Route refresh:");
13614 if (CHECK_FLAG(p->cap,
13615 PEER_CAP_REFRESH_ADV))
13616 vty_out(vty, " advertised");
13617 if (CHECK_FLAG(p->cap,
13618 PEER_CAP_REFRESH_NEW_RCV)
13619 || CHECK_FLAG(
13620 p->cap,
13621 PEER_CAP_REFRESH_OLD_RCV))
13622 vty_out(vty, " %sreceived(%s)",
13623 CHECK_FLAG(
13624 p->cap,
13625 PEER_CAP_REFRESH_ADV)
13626 ? "and "
13627 : "",
13628 (CHECK_FLAG(
13629 p->cap,
13630 PEER_CAP_REFRESH_OLD_RCV)
13631 && CHECK_FLAG(
13632 p->cap,
13633 PEER_CAP_REFRESH_NEW_RCV))
13634 ? "old & new"
13635 : CHECK_FLAG(
13636 p->cap,
13637 PEER_CAP_REFRESH_OLD_RCV)
13638 ? "old"
13639 : "new");
13640
13641 vty_out(vty, "\n");
13642 }
13643
9af52ccf
DA
13644 /* Enhanced Route Refresh */
13645 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13646 || CHECK_FLAG(p->cap,
13647 PEER_CAP_ENHANCED_RR_RCV)) {
13648 vty_out(vty,
13649 " Enhanced Route Refresh:");
13650 if (CHECK_FLAG(
13651 p->cap,
13652 PEER_CAP_ENHANCED_RR_ADV))
13653 vty_out(vty, " advertised");
13654 if (CHECK_FLAG(
13655 p->cap,
13656 PEER_CAP_ENHANCED_RR_RCV))
13657 vty_out(vty, " %sreceived",
13658 CHECK_FLAG(
13659 p->cap,
13660 PEER_CAP_REFRESH_ADV)
13661 ? "and "
13662 : "");
13663 vty_out(vty, "\n");
13664 }
13665
d62a17ae 13666 /* Multiprotocol Extensions */
05c7a1cc
QY
13667 FOREACH_AFI_SAFI (afi, safi)
13668 if (p->afc_adv[afi][safi]
13669 || p->afc_recv[afi][safi]) {
13670 vty_out(vty,
13671 " Address Family %s:",
5cb5f4d0
DD
13672 get_afi_safi_str(
13673 afi,
13674 safi,
13675 false));
05c7a1cc 13676 if (p->afc_adv[afi][safi])
d62a17ae 13677 vty_out(vty,
05c7a1cc
QY
13678 " advertised");
13679 if (p->afc_recv[afi][safi])
13680 vty_out(vty,
13681 " %sreceived",
13682 p->afc_adv[afi]
13683 [safi]
13684 ? "and "
13685 : "");
13686 vty_out(vty, "\n");
13687 }
d62a17ae 13688
13689 /* Hostname capability */
60466a63 13690 vty_out(vty, " Hostname Capability:");
d77114b7
MK
13691
13692 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
13693 vty_out(vty,
13694 " advertised (name: %s,domain name: %s)",
60466a63
QY
13695 bgp->peer_self->hostname
13696 ? bgp->peer_self
13697 ->hostname
d77114b7 13698 : "n/a",
60466a63
QY
13699 bgp->peer_self->domainname
13700 ? bgp->peer_self
13701 ->domainname
d77114b7
MK
13702 : "n/a");
13703 } else {
13704 vty_out(vty, " not advertised");
d62a17ae 13705 }
13706
d77114b7 13707 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
13708 vty_out(vty,
13709 " received (name: %s,domain name: %s)",
60466a63
QY
13710 p->hostname ? p->hostname
13711 : "n/a",
13712 p->domainname ? p->domainname
13713 : "n/a");
d77114b7
MK
13714 } else {
13715 vty_out(vty, " not received");
13716 }
13717
13718 vty_out(vty, "\n");
13719
61bfbd51 13720 /* Graceful Restart */
d62a17ae 13721 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13722 || CHECK_FLAG(p->cap,
13723 PEER_CAP_RESTART_ADV)) {
13724 vty_out(vty,
61bfbd51 13725 " Graceful Restart Capability:");
d62a17ae 13726 if (CHECK_FLAG(p->cap,
13727 PEER_CAP_RESTART_ADV))
13728 vty_out(vty, " advertised");
13729 if (CHECK_FLAG(p->cap,
13730 PEER_CAP_RESTART_RCV))
13731 vty_out(vty, " %sreceived",
13732 CHECK_FLAG(
13733 p->cap,
13734 PEER_CAP_RESTART_ADV)
13735 ? "and "
13736 : "");
13737 vty_out(vty, "\n");
13738
13739 if (CHECK_FLAG(p->cap,
13740 PEER_CAP_RESTART_RCV)) {
13741 int restart_af_count = 0;
13742
13743 vty_out(vty,
13744 " Remote Restart timer is %d seconds\n",
13745 p->v_gr_restart);
13746 vty_out(vty,
13747 " Address families by peer:\n ");
13748
05c7a1cc
QY
13749 FOREACH_AFI_SAFI (afi, safi)
13750 if (CHECK_FLAG(
13751 p->af_cap
13752 [afi]
13753 [safi],
13754 PEER_CAP_RESTART_AF_RCV)) {
13755 vty_out(vty,
13756 "%s%s(%s)",
13757 restart_af_count
13758 ? ", "
13759 : "",
5cb5f4d0 13760 get_afi_safi_str(
05c7a1cc 13761 afi,
5cb5f4d0
DD
13762 safi,
13763 false),
05c7a1cc
QY
13764 CHECK_FLAG(
13765 p->af_cap
13766 [afi]
13767 [safi],
13768 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13769 ? "preserved"
13770 : "not preserved");
13771 restart_af_count++;
13772 }
d62a17ae 13773 if (!restart_af_count)
13774 vty_out(vty, "none");
13775 vty_out(vty, "\n");
13776 }
2986cac2 13777 } /* Gracefull Restart */
d62a17ae 13778 }
13779 }
13780 }
13781
13782 /* graceful restart information */
d62a17ae 13783 json_object *json_grace = NULL;
13784 json_object *json_grace_send = NULL;
13785 json_object *json_grace_recv = NULL;
13786 int eor_send_af_count = 0;
13787 int eor_receive_af_count = 0;
13788
13789 if (use_json) {
13790 json_grace = json_object_new_object();
13791 json_grace_send = json_object_new_object();
13792 json_grace_recv = json_object_new_object();
13793
36235319
QY
13794 if ((p->status == Established)
13795 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
13796 FOREACH_AFI_SAFI (afi, safi) {
13797 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 13798 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
13799 json_object_boolean_true_add(
13800 json_grace_send,
5cb5f4d0
DD
13801 get_afi_safi_str(afi,
13802 safi,
13803 true));
05c7a1cc 13804 eor_send_af_count++;
d62a17ae 13805 }
13806 }
05c7a1cc
QY
13807 FOREACH_AFI_SAFI (afi, safi) {
13808 if (CHECK_FLAG(
36235319
QY
13809 p->af_sflags[afi][safi],
13810 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
13811 json_object_boolean_true_add(
13812 json_grace_recv,
5cb5f4d0
DD
13813 get_afi_safi_str(afi,
13814 safi,
13815 true));
05c7a1cc 13816 eor_receive_af_count++;
d62a17ae 13817 }
13818 }
13819 }
36235319
QY
13820 json_object_object_add(json_grace, "endOfRibSend",
13821 json_grace_send);
13822 json_object_object_add(json_grace, "endOfRibRecv",
13823 json_grace_recv);
d62a17ae 13824
d62a17ae 13825
13826 if (p->t_gr_restart)
13827 json_object_int_add(json_grace,
13828 "gracefulRestartTimerMsecs",
13829 thread_timer_remain_second(
13830 p->t_gr_restart)
13831 * 1000);
13832
13833 if (p->t_gr_stale)
13834 json_object_int_add(
13835 json_grace,
13836 "gracefulStalepathTimerMsecs",
13837 thread_timer_remain_second(
13838 p->t_gr_stale)
13839 * 1000);
2986cac2 13840 /* more gr info in new format */
13841 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 13842 json_grace);
d62a17ae 13843 json_object_object_add(
13844 json_neigh, "gracefulRestartInfo", json_grace);
13845 } else {
2089dd80 13846 vty_out(vty, " Graceful restart information:\n");
36235319
QY
13847 if ((p->status == Established)
13848 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 13849
d62a17ae 13850 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
13851 FOREACH_AFI_SAFI (afi, safi) {
13852 if (CHECK_FLAG(p->af_sflags[afi][safi],
13853 PEER_STATUS_EOR_SEND)) {
13854 vty_out(vty, "%s%s",
13855 eor_send_af_count ? ", "
13856 : "",
36235319
QY
13857 get_afi_safi_str(
13858 afi, safi,
13859 false));
05c7a1cc 13860 eor_send_af_count++;
d62a17ae 13861 }
13862 }
13863 vty_out(vty, "\n");
13864 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
13865 FOREACH_AFI_SAFI (afi, safi) {
13866 if (CHECK_FLAG(
13867 p->af_sflags[afi][safi],
13868 PEER_STATUS_EOR_RECEIVED)) {
13869 vty_out(vty, "%s%s",
13870 eor_receive_af_count
13871 ? ", "
13872 : "",
5cb5f4d0
DD
13873 get_afi_safi_str(afi,
13874 safi,
13875 false));
05c7a1cc 13876 eor_receive_af_count++;
d62a17ae 13877 }
13878 }
13879 vty_out(vty, "\n");
13880 }
13881
13882 if (p->t_gr_restart)
13883 vty_out(vty,
13884 " The remaining time of restart timer is %ld\n",
13885 thread_timer_remain_second(
13886 p->t_gr_restart));
13887
13888 if (p->t_gr_stale)
13889 vty_out(vty,
13890 " The remaining time of stalepath timer is %ld\n",
13891 thread_timer_remain_second(
13892 p->t_gr_stale));
2986cac2 13893
13894 /* more gr info in new format */
13895 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 13896 }
2986cac2 13897
d62a17ae 13898 if (use_json) {
13899 json_object *json_stat = NULL;
13900 json_stat = json_object_new_object();
13901 /* Packet counts. */
43aa5965
QY
13902
13903 atomic_size_t outq_count, inq_count;
13904 outq_count = atomic_load_explicit(&p->obuf->count,
13905 memory_order_relaxed);
13906 inq_count = atomic_load_explicit(&p->ibuf->count,
13907 memory_order_relaxed);
13908
13909 json_object_int_add(json_stat, "depthInq",
13910 (unsigned long)inq_count);
d62a17ae 13911 json_object_int_add(json_stat, "depthOutq",
43aa5965 13912 (unsigned long)outq_count);
0112e9e0
QY
13913 json_object_int_add(json_stat, "opensSent",
13914 atomic_load_explicit(&p->open_out,
13915 memory_order_relaxed));
13916 json_object_int_add(json_stat, "opensRecv",
13917 atomic_load_explicit(&p->open_in,
13918 memory_order_relaxed));
d62a17ae 13919 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13920 atomic_load_explicit(&p->notify_out,
13921 memory_order_relaxed));
d62a17ae 13922 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13923 atomic_load_explicit(&p->notify_in,
13924 memory_order_relaxed));
13925 json_object_int_add(json_stat, "updatesSent",
13926 atomic_load_explicit(&p->update_out,
13927 memory_order_relaxed));
13928 json_object_int_add(json_stat, "updatesRecv",
13929 atomic_load_explicit(&p->update_in,
13930 memory_order_relaxed));
d62a17ae 13931 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13932 atomic_load_explicit(&p->keepalive_out,
13933 memory_order_relaxed));
d62a17ae 13934 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13935 atomic_load_explicit(&p->keepalive_in,
13936 memory_order_relaxed));
d62a17ae 13937 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13938 atomic_load_explicit(&p->refresh_out,
13939 memory_order_relaxed));
d62a17ae 13940 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13941 atomic_load_explicit(&p->refresh_in,
13942 memory_order_relaxed));
d62a17ae 13943 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13944 atomic_load_explicit(&p->dynamic_cap_out,
13945 memory_order_relaxed));
d62a17ae 13946 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13947 atomic_load_explicit(&p->dynamic_cap_in,
13948 memory_order_relaxed));
13949 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13950 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13951 json_object_object_add(json_neigh, "messageStats", json_stat);
13952 } else {
43aa5965
QY
13953 atomic_size_t outq_count, inq_count;
13954 outq_count = atomic_load_explicit(&p->obuf->count,
13955 memory_order_relaxed);
13956 inq_count = atomic_load_explicit(&p->ibuf->count,
13957 memory_order_relaxed);
13958
d62a17ae 13959 /* Packet counts. */
13960 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13961 vty_out(vty, " Inq depth is %zu\n", inq_count);
13962 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13963 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
13964 vty_out(vty, " Opens: %10d %10d\n",
13965 atomic_load_explicit(&p->open_out,
13966 memory_order_relaxed),
13967 atomic_load_explicit(&p->open_in,
13968 memory_order_relaxed));
13969 vty_out(vty, " Notifications: %10d %10d\n",
13970 atomic_load_explicit(&p->notify_out,
13971 memory_order_relaxed),
13972 atomic_load_explicit(&p->notify_in,
13973 memory_order_relaxed));
13974 vty_out(vty, " Updates: %10d %10d\n",
13975 atomic_load_explicit(&p->update_out,
13976 memory_order_relaxed),
13977 atomic_load_explicit(&p->update_in,
13978 memory_order_relaxed));
13979 vty_out(vty, " Keepalives: %10d %10d\n",
13980 atomic_load_explicit(&p->keepalive_out,
13981 memory_order_relaxed),
13982 atomic_load_explicit(&p->keepalive_in,
13983 memory_order_relaxed));
13984 vty_out(vty, " Route Refresh: %10d %10d\n",
13985 atomic_load_explicit(&p->refresh_out,
13986 memory_order_relaxed),
13987 atomic_load_explicit(&p->refresh_in,
13988 memory_order_relaxed));
d62a17ae 13989 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
13990 atomic_load_explicit(&p->dynamic_cap_out,
13991 memory_order_relaxed),
13992 atomic_load_explicit(&p->dynamic_cap_in,
13993 memory_order_relaxed));
13994 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13995 PEER_TOTAL_RX(p));
d62a17ae 13996 }
13997
13998 if (use_json) {
13999 /* advertisement-interval */
14000 json_object_int_add(json_neigh,
14001 "minBtwnAdvertisementRunsTimerMsecs",
14002 p->v_routeadv * 1000);
14003
14004 /* Update-source. */
14005 if (p->update_if || p->update_source) {
14006 if (p->update_if)
14007 json_object_string_add(json_neigh,
14008 "updateSource",
14009 p->update_if);
14010 else if (p->update_source)
14011 json_object_string_add(
14012 json_neigh, "updateSource",
14013 sockunion2str(p->update_source, buf1,
14014 SU_ADDRSTRLEN));
14015 }
14016 } else {
14017 /* advertisement-interval */
14018 vty_out(vty,
14019 " Minimum time between advertisement runs is %d seconds\n",
14020 p->v_routeadv);
14021
14022 /* Update-source. */
14023 if (p->update_if || p->update_source) {
14024 vty_out(vty, " Update source is ");
14025 if (p->update_if)
14026 vty_out(vty, "%s", p->update_if);
14027 else if (p->update_source)
14028 vty_out(vty, "%s",
14029 sockunion2str(p->update_source, buf1,
14030 SU_ADDRSTRLEN));
14031 vty_out(vty, "\n");
14032 }
14033
14034 vty_out(vty, "\n");
14035 }
14036
14037 /* Address Family Information */
14038 json_object *json_hold = NULL;
14039
14040 if (use_json)
14041 json_hold = json_object_new_object();
14042
05c7a1cc
QY
14043 FOREACH_AFI_SAFI (afi, safi)
14044 if (p->afc[afi][safi])
14045 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14046 json_hold);
d62a17ae 14047
14048 if (use_json) {
14049 json_object_object_add(json_neigh, "addressFamilyInfo",
14050 json_hold);
14051 json_object_int_add(json_neigh, "connectionsEstablished",
14052 p->established);
14053 json_object_int_add(json_neigh, "connectionsDropped",
14054 p->dropped);
14055 } else
14056 vty_out(vty, " Connections established %d; dropped %d\n",
14057 p->established, p->dropped);
14058
14059 if (!p->last_reset) {
14060 if (use_json)
14061 json_object_string_add(json_neigh, "lastReset",
14062 "never");
14063 else
14064 vty_out(vty, " Last reset never\n");
14065 } else {
14066 if (use_json) {
14067 time_t uptime;
a2700b50 14068 struct tm tm;
d62a17ae 14069
14070 uptime = bgp_clock();
14071 uptime -= p->resettime;
a2700b50
MS
14072 gmtime_r(&uptime, &tm);
14073
d62a17ae 14074 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14075 (tm.tm_sec * 1000)
14076 + (tm.tm_min * 60000)
14077 + (tm.tm_hour * 3600000));
3577f1c5 14078 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14079 } else {
14080 vty_out(vty, " Last reset %s, ",
14081 peer_uptime(p->resettime, timebuf,
14082 BGP_UPTIME_LEN, 0, NULL));
14083
3577f1c5 14084 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14085 if (p->last_reset_cause_size) {
14086 msg = p->last_reset_cause;
14087 vty_out(vty,
14088 " Message received that caused BGP to send a NOTIFICATION:\n ");
14089 for (i = 1; i <= p->last_reset_cause_size;
14090 i++) {
14091 vty_out(vty, "%02X", *msg++);
14092
14093 if (i != p->last_reset_cause_size) {
14094 if (i % 16 == 0) {
14095 vty_out(vty, "\n ");
14096 } else if (i % 4 == 0) {
14097 vty_out(vty, " ");
14098 }
14099 }
14100 }
14101 vty_out(vty, "\n");
14102 }
14103 }
14104 }
14105
14106 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14107 if (use_json)
14108 json_object_boolean_true_add(json_neigh,
14109 "prefixesConfigExceedMax");
14110 else
14111 vty_out(vty,
14112 " Peer had exceeded the max. no. of prefixes configured.\n");
14113
14114 if (p->t_pmax_restart) {
14115 if (use_json) {
14116 json_object_boolean_true_add(
14117 json_neigh, "reducePrefixNumFrom");
14118 json_object_int_add(json_neigh,
14119 "restartInTimerMsec",
14120 thread_timer_remain_second(
14121 p->t_pmax_restart)
14122 * 1000);
14123 } else
14124 vty_out(vty,
14125 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14126 p->host, thread_timer_remain_second(
14127 p->t_pmax_restart));
d62a17ae 14128 } else {
14129 if (use_json)
14130 json_object_boolean_true_add(
14131 json_neigh,
14132 "reducePrefixNumAndClearIpBgp");
14133 else
14134 vty_out(vty,
14135 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14136 p->host);
14137 }
14138 }
14139
14140 /* EBGP Multihop and GTSM */
14141 if (p->sort != BGP_PEER_IBGP) {
14142 if (use_json) {
e2521429 14143 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14144 json_object_int_add(json_neigh,
14145 "externalBgpNbrMaxHopsAway",
14146 p->gtsm_hops);
c8d6f0d6 14147 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14148 json_object_int_add(json_neigh,
14149 "externalBgpNbrMaxHopsAway",
14150 p->ttl);
14151 } else {
e2521429 14152 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14153 vty_out(vty,
14154 " External BGP neighbor may be up to %d hops away.\n",
14155 p->gtsm_hops);
c8d6f0d6 14156 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14157 vty_out(vty,
14158 " External BGP neighbor may be up to %d hops away.\n",
14159 p->ttl);
14160 }
14161 } else {
e2521429 14162 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 14163 if (use_json)
14164 json_object_int_add(json_neigh,
14165 "internalBgpNbrMaxHopsAway",
14166 p->gtsm_hops);
14167 else
14168 vty_out(vty,
14169 " Internal BGP neighbor may be up to %d hops away.\n",
14170 p->gtsm_hops);
14171 }
14172 }
14173
14174 /* Local address. */
14175 if (p->su_local) {
14176 if (use_json) {
14177 json_object_string_add(json_neigh, "hostLocal",
14178 sockunion2str(p->su_local, buf1,
14179 SU_ADDRSTRLEN));
14180 json_object_int_add(json_neigh, "portLocal",
14181 ntohs(p->su_local->sin.sin_port));
14182 } else
14183 vty_out(vty, "Local host: %s, Local port: %d\n",
14184 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14185 ntohs(p->su_local->sin.sin_port));
14186 }
14187
14188 /* Remote address. */
14189 if (p->su_remote) {
14190 if (use_json) {
14191 json_object_string_add(json_neigh, "hostForeign",
14192 sockunion2str(p->su_remote, buf1,
14193 SU_ADDRSTRLEN));
14194 json_object_int_add(json_neigh, "portForeign",
14195 ntohs(p->su_remote->sin.sin_port));
14196 } else
14197 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14198 sockunion2str(p->su_remote, buf1,
14199 SU_ADDRSTRLEN),
14200 ntohs(p->su_remote->sin.sin_port));
14201 }
14202
14203 /* Nexthop display. */
14204 if (p->su_local) {
14205 if (use_json) {
14206 json_object_string_add(json_neigh, "nexthop",
14207 inet_ntop(AF_INET,
14208 &p->nexthop.v4, buf1,
14209 sizeof(buf1)));
14210 json_object_string_add(json_neigh, "nexthopGlobal",
14211 inet_ntop(AF_INET6,
14212 &p->nexthop.v6_global,
14213 buf1, sizeof(buf1)));
14214 json_object_string_add(json_neigh, "nexthopLocal",
14215 inet_ntop(AF_INET6,
14216 &p->nexthop.v6_local,
14217 buf1, sizeof(buf1)));
14218 if (p->shared_network)
14219 json_object_string_add(json_neigh,
14220 "bgpConnection",
14221 "sharedNetwork");
14222 else
14223 json_object_string_add(json_neigh,
14224 "bgpConnection",
14225 "nonSharedNetwork");
14226 } else {
14227 vty_out(vty, "Nexthop: %s\n",
14228 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14229 sizeof(buf1)));
14230 vty_out(vty, "Nexthop global: %s\n",
14231 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14232 sizeof(buf1)));
14233 vty_out(vty, "Nexthop local: %s\n",
14234 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14235 sizeof(buf1)));
14236 vty_out(vty, "BGP connection: %s\n",
14237 p->shared_network ? "shared network"
14238 : "non shared network");
14239 }
14240 }
14241
14242 /* Timer information. */
14243 if (use_json) {
14244 json_object_int_add(json_neigh, "connectRetryTimer",
14245 p->v_connect);
14246 if (p->status == Established && p->rtt)
14247 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14248 p->rtt);
14249 if (p->t_start)
14250 json_object_int_add(
14251 json_neigh, "nextStartTimerDueInMsecs",
14252 thread_timer_remain_second(p->t_start) * 1000);
14253 if (p->t_connect)
14254 json_object_int_add(
14255 json_neigh, "nextConnectTimerDueInMsecs",
14256 thread_timer_remain_second(p->t_connect)
14257 * 1000);
14258 if (p->t_routeadv) {
14259 json_object_int_add(json_neigh, "mraiInterval",
14260 p->v_routeadv);
14261 json_object_int_add(
14262 json_neigh, "mraiTimerExpireInMsecs",
14263 thread_timer_remain_second(p->t_routeadv)
14264 * 1000);
14265 }
14266 if (p->password)
14267 json_object_int_add(json_neigh, "authenticationEnabled",
14268 1);
14269
14270 if (p->t_read)
14271 json_object_string_add(json_neigh, "readThread", "on");
14272 else
14273 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14274
14275 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14276 json_object_string_add(json_neigh, "writeThread", "on");
14277 else
14278 json_object_string_add(json_neigh, "writeThread",
14279 "off");
14280 } else {
14281 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14282 p->v_connect);
14283 if (p->status == Established && p->rtt)
14284 vty_out(vty, "Estimated round trip time: %d ms\n",
14285 p->rtt);
14286 if (p->t_start)
14287 vty_out(vty, "Next start timer due in %ld seconds\n",
14288 thread_timer_remain_second(p->t_start));
14289 if (p->t_connect)
14290 vty_out(vty, "Next connect timer due in %ld seconds\n",
14291 thread_timer_remain_second(p->t_connect));
14292 if (p->t_routeadv)
14293 vty_out(vty,
14294 "MRAI (interval %u) timer expires in %ld seconds\n",
14295 p->v_routeadv,
14296 thread_timer_remain_second(p->t_routeadv));
14297 if (p->password)
14298 vty_out(vty, "Peer Authentication Enabled\n");
14299
cac9e917 14300 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14301 p->t_read ? "on" : "off",
14302 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14303 ? "on"
cac9e917 14304 : "off", p->fd);
d62a17ae 14305 }
14306
14307 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14308 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14309 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14310
14311 if (!use_json)
14312 vty_out(vty, "\n");
14313
14314 /* BFD information. */
14315 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14316
14317 if (use_json) {
14318 if (p->conf_if) /* Configured interface name. */
14319 json_object_object_add(json, p->conf_if, json_neigh);
14320 else /* Configured IP address. */
14321 json_object_object_add(json, p->host, json_neigh);
14322 }
14323}
14324
36235319
QY
14325static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14326 enum show_type type,
14327 union sockunion *su,
14328 const char *conf_if, afi_t afi,
74a630b6 14329 bool use_json)
2986cac2 14330{
14331 struct listnode *node, *nnode;
14332 struct peer *peer;
14333 int find = 0;
14334 safi_t safi = SAFI_UNICAST;
74a630b6 14335 json_object *json = NULL;
2986cac2 14336 json_object *json_neighbor = NULL;
14337
74a630b6
NT
14338 if (use_json) {
14339 json = json_object_new_object();
14340 json_neighbor = json_object_new_object();
14341 }
14342
2986cac2 14343 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14344
14345 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14346 continue;
14347
14348 if ((peer->afc[afi][safi]) == 0)
14349 continue;
14350
2ba1fe69 14351 if (type == show_all) {
2986cac2 14352 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14353 json_neighbor);
2986cac2 14354
74a630b6 14355 if (use_json) {
13909c4f
DS
14356 json_object_object_add(json, peer->host,
14357 json_neighbor);
74a630b6
NT
14358 json_neighbor = NULL;
14359 }
2986cac2 14360
2ba1fe69 14361 } else if (type == show_peer) {
2986cac2 14362 if (conf_if) {
14363 if ((peer->conf_if
13909c4f
DS
14364 && !strcmp(peer->conf_if, conf_if))
14365 || (peer->hostname
2986cac2 14366 && !strcmp(peer->hostname, conf_if))) {
14367 find = 1;
13909c4f
DS
14368 bgp_show_peer_gr_status(vty, peer,
14369 use_json,
14370 json_neighbor);
2986cac2 14371 }
14372 } else {
14373 if (sockunion_same(&peer->su, su)) {
14374 find = 1;
13909c4f
DS
14375 bgp_show_peer_gr_status(vty, peer,
14376 use_json,
14377 json_neighbor);
2986cac2 14378 }
14379 }
13909c4f
DS
14380 if (use_json && find)
14381 json_object_object_add(json, peer->host,
14382 json_neighbor);
2986cac2 14383 }
14384
74a630b6
NT
14385 if (find) {
14386 json_neighbor = NULL;
2986cac2 14387 break;
74a630b6 14388 }
2986cac2 14389 }
14390
14391 if (type == show_peer && !find) {
14392 if (use_json)
13909c4f 14393 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14394 else
14395 vty_out(vty, "%% No such neighbor\n");
14396 }
14397 if (use_json) {
13909c4f
DS
14398 vty_out(vty, "%s\n",
14399 json_object_to_json_string_ext(
14400 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
14401
14402 if (json_neighbor)
14403 json_object_free(json_neighbor);
14404 json_object_free(json);
2986cac2 14405 } else {
14406 vty_out(vty, "\n");
14407 }
14408
14409 return CMD_SUCCESS;
14410}
14411
d62a17ae 14412static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14413 enum show_type type, union sockunion *su,
9f049418 14414 const char *conf_if, bool use_json,
d62a17ae 14415 json_object *json)
14416{
14417 struct listnode *node, *nnode;
14418 struct peer *peer;
14419 int find = 0;
9f049418 14420 bool nbr_output = false;
d1927ebe
AS
14421 afi_t afi = AFI_MAX;
14422 safi_t safi = SAFI_MAX;
14423
14424 if (type == show_ipv4_peer || type == show_ipv4_all) {
14425 afi = AFI_IP;
14426 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14427 afi = AFI_IP6;
14428 }
d62a17ae 14429
14430 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14431 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14432 continue;
14433
14434 switch (type) {
14435 case show_all:
14436 bgp_show_peer(vty, peer, use_json, json);
9f049418 14437 nbr_output = true;
d62a17ae 14438 break;
14439 case show_peer:
14440 if (conf_if) {
14441 if ((peer->conf_if
14442 && !strcmp(peer->conf_if, conf_if))
14443 || (peer->hostname
14444 && !strcmp(peer->hostname, conf_if))) {
14445 find = 1;
14446 bgp_show_peer(vty, peer, use_json,
14447 json);
14448 }
14449 } else {
14450 if (sockunion_same(&peer->su, su)) {
14451 find = 1;
14452 bgp_show_peer(vty, peer, use_json,
14453 json);
14454 }
14455 }
14456 break;
d1927ebe
AS
14457 case show_ipv4_peer:
14458 case show_ipv6_peer:
14459 FOREACH_SAFI (safi) {
14460 if (peer->afc[afi][safi]) {
14461 if (conf_if) {
14462 if ((peer->conf_if
14463 && !strcmp(peer->conf_if, conf_if))
14464 || (peer->hostname
14465 && !strcmp(peer->hostname, conf_if))) {
14466 find = 1;
14467 bgp_show_peer(vty, peer, use_json,
14468 json);
14469 break;
14470 }
14471 } else {
14472 if (sockunion_same(&peer->su, su)) {
14473 find = 1;
14474 bgp_show_peer(vty, peer, use_json,
14475 json);
14476 break;
14477 }
14478 }
14479 }
14480 }
14481 break;
14482 case show_ipv4_all:
14483 case show_ipv6_all:
14484 FOREACH_SAFI (safi) {
14485 if (peer->afc[afi][safi]) {
14486 bgp_show_peer(vty, peer, use_json, json);
14487 nbr_output = true;
14488 break;
14489 }
14490 }
14491 break;
d62a17ae 14492 }
14493 }
14494
d1927ebe
AS
14495 if ((type == show_peer || type == show_ipv4_peer ||
14496 type == show_ipv6_peer) && !find) {
d62a17ae 14497 if (use_json)
14498 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14499 else
88b7d255 14500 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14501 }
14502
d1927ebe
AS
14503 if (type != show_peer && type != show_ipv4_peer &&
14504 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14505 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14506
d62a17ae 14507 if (use_json) {
996c9314
LB
14508 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14509 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14510 } else {
14511 vty_out(vty, "\n");
14512 }
14513
14514 return CMD_SUCCESS;
14515}
14516
36235319
QY
14517static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14518 enum show_type type,
14519 const char *ip_str,
14520 afi_t afi, bool use_json)
2986cac2 14521{
14522
14523 int ret;
14524 struct bgp *bgp;
14525 union sockunion su;
2986cac2 14526
14527 bgp = bgp_get_default();
14528
13909c4f
DS
14529 if (!bgp)
14530 return;
2986cac2 14531
13909c4f
DS
14532 if (!use_json)
14533 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14534 NULL);
2986cac2 14535
13909c4f
DS
14536 if (ip_str) {
14537 ret = str2sockunion(ip_str, &su);
14538 if (ret < 0)
13909c4f 14539 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14540 vty, bgp, type, NULL, ip_str, afi, use_json);
14541 else
14542 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14543 NULL, afi, use_json);
13909c4f
DS
14544 } else
14545 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14546 afi, use_json);
2986cac2 14547}
14548
d62a17ae 14549static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14550 enum show_type type,
14551 const char *ip_str,
9f049418 14552 bool use_json)
d62a17ae 14553{
0291c246
MK
14554 struct listnode *node, *nnode;
14555 struct bgp *bgp;
71aedaa3 14556 union sockunion su;
0291c246 14557 json_object *json = NULL;
71aedaa3 14558 int ret, is_first = 1;
9f049418 14559 bool nbr_output = false;
d62a17ae 14560
14561 if (use_json)
14562 vty_out(vty, "{\n");
14563
14564 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14565 nbr_output = true;
d62a17ae 14566 if (use_json) {
14567 if (!(json = json_object_new_object())) {
af4c2728 14568 flog_err(
e50f7cfd 14569 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14570 "Unable to allocate memory for JSON object");
14571 vty_out(vty,
14572 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14573 return;
14574 }
14575
14576 json_object_int_add(json, "vrfId",
14577 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14578 ? -1
14579 : (int64_t)bgp->vrf_id);
d62a17ae 14580 json_object_string_add(
14581 json, "vrfName",
14582 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14583 ? VRF_DEFAULT_NAME
d62a17ae 14584 : bgp->name);
14585
14586 if (!is_first)
14587 vty_out(vty, ",\n");
14588 else
14589 is_first = 0;
14590
14591 vty_out(vty, "\"%s\":",
14592 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14593 ? VRF_DEFAULT_NAME
d62a17ae 14594 : bgp->name);
14595 } else {
14596 vty_out(vty, "\nInstance %s:\n",
14597 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14598 ? VRF_DEFAULT_NAME
d62a17ae 14599 : bgp->name);
14600 }
71aedaa3 14601
d1927ebe
AS
14602 if (type == show_peer || type == show_ipv4_peer ||
14603 type == show_ipv6_peer) {
71aedaa3
DS
14604 ret = str2sockunion(ip_str, &su);
14605 if (ret < 0)
14606 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14607 use_json, json);
14608 else
14609 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14610 use_json, json);
14611 } else {
d1927ebe 14612 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14613 use_json, json);
14614 }
b77004d6 14615 json_object_free(json);
121067e9 14616 json = NULL;
d62a17ae 14617 }
14618
3e78a6ce 14619 if (use_json)
d62a17ae 14620 vty_out(vty, "}\n");
9f049418
DS
14621 else if (!nbr_output)
14622 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14623}
14624
14625static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14626 enum show_type type, const char *ip_str,
9f049418 14627 bool use_json)
d62a17ae 14628{
14629 int ret;
14630 struct bgp *bgp;
14631 union sockunion su;
14632 json_object *json = NULL;
14633
14634 if (name) {
14635 if (strmatch(name, "all")) {
71aedaa3
DS
14636 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14637 use_json);
d62a17ae 14638 return CMD_SUCCESS;
14639 } else {
14640 bgp = bgp_lookup_by_name(name);
14641 if (!bgp) {
14642 if (use_json) {
14643 json = json_object_new_object();
d62a17ae 14644 vty_out(vty, "%s\n",
14645 json_object_to_json_string_ext(
14646 json,
14647 JSON_C_TO_STRING_PRETTY));
14648 json_object_free(json);
14649 } else
14650 vty_out(vty,
9f049418 14651 "%% BGP instance not found\n");
d62a17ae 14652
14653 return CMD_WARNING;
14654 }
14655 }
14656 } else {
14657 bgp = bgp_get_default();
14658 }
14659
14660 if (bgp) {
14661 json = json_object_new_object();
14662 if (ip_str) {
14663 ret = str2sockunion(ip_str, &su);
14664 if (ret < 0)
14665 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14666 use_json, json);
14667 else
14668 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14669 use_json, json);
14670 } else {
14671 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14672 json);
14673 }
14674 json_object_free(json);
ca61fd25
DS
14675 } else {
14676 if (use_json)
14677 vty_out(vty, "{}\n");
14678 else
14679 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14680 }
14681
14682 return CMD_SUCCESS;
4fb25c53
DW
14683}
14684
2986cac2 14685
14686
14687/* "show [ip] bgp neighbors graceful-restart" commands. */
14688DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14689 show_ip_bgp_neighbors_graceful_restart_cmd,
14690 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14691 SHOW_STR
14692 BGP_STR
14693 IP_STR
14694 IPV6_STR
14695 NEIGHBOR_STR
14696 "Neighbor to display information about\n"
14697 "Neighbor to display information about\n"
14698 "Neighbor on BGP configured interface\n"
14699 GR_SHOW
14700 JSON_STR)
14701{
14702 char *sh_arg = NULL;
14703 enum show_type sh_type;
14704 int idx = 0;
14705 afi_t afi = AFI_MAX;
2986cac2 14706 bool uj = use_json(argc, argv);
14707
36235319 14708 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14709 afi = AFI_MAX;
14710
14711 idx++;
14712
14713 if (argv_find(argv, argc, "A.B.C.D", &idx)
14714 || argv_find(argv, argc, "X:X::X:X", &idx)
14715 || argv_find(argv, argc, "WORD", &idx)) {
14716 sh_type = show_peer;
14717 sh_arg = argv[idx]->arg;
14718 } else
14719 sh_type = show_all;
14720
14721 if (!argv_find(argv, argc, "graceful-restart", &idx))
14722 return CMD_SUCCESS;
14723
14724
36235319
QY
14725 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14726 afi, uj);
2986cac2 14727}
14728
716b2d8a 14729/* "show [ip] bgp neighbors" commands. */
718e3744 14730DEFUN (show_ip_bgp_neighbors,
14731 show_ip_bgp_neighbors_cmd,
24345e82 14732 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14733 SHOW_STR
14734 IP_STR
14735 BGP_STR
f2a8972b 14736 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14737 "Address Family\n"
14738 "Address Family\n"
718e3744 14739 "Detailed information on TCP and BGP neighbor connections\n"
14740 "Neighbor to display information about\n"
a80beece 14741 "Neighbor to display information about\n"
91d37724 14742 "Neighbor on BGP configured interface\n"
9973d184 14743 JSON_STR)
718e3744 14744{
d62a17ae 14745 char *vrf = NULL;
14746 char *sh_arg = NULL;
14747 enum show_type sh_type;
d1927ebe 14748 afi_t afi = AFI_MAX;
718e3744 14749
9f049418 14750 bool uj = use_json(argc, argv);
718e3744 14751
d62a17ae 14752 int idx = 0;
718e3744 14753
9a8bdf1c
PG
14754 /* [<vrf> VIEWVRFNAME] */
14755 if (argv_find(argv, argc, "vrf", &idx)) {
14756 vrf = argv[idx + 1]->arg;
14757 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14758 vrf = NULL;
14759 } else if (argv_find(argv, argc, "view", &idx))
14760 /* [<view> VIEWVRFNAME] */
d62a17ae 14761 vrf = argv[idx + 1]->arg;
718e3744 14762
d62a17ae 14763 idx++;
d1927ebe
AS
14764
14765 if (argv_find(argv, argc, "ipv4", &idx)) {
14766 sh_type = show_ipv4_all;
14767 afi = AFI_IP;
14768 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14769 sh_type = show_ipv6_all;
14770 afi = AFI_IP6;
14771 } else {
14772 sh_type = show_all;
14773 }
14774
d62a17ae 14775 if (argv_find(argv, argc, "A.B.C.D", &idx)
14776 || argv_find(argv, argc, "X:X::X:X", &idx)
14777 || argv_find(argv, argc, "WORD", &idx)) {
14778 sh_type = show_peer;
14779 sh_arg = argv[idx]->arg;
d1927ebe
AS
14780 }
14781
14782 if (sh_type == show_peer && afi == AFI_IP) {
14783 sh_type = show_ipv4_peer;
14784 } else if (sh_type == show_peer && afi == AFI_IP6) {
14785 sh_type = show_ipv6_peer;
14786 }
856ca177 14787
d62a17ae 14788 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14789}
14790
716b2d8a 14791/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14792 paths' and `show ip mbgp paths'. Those functions results are the
14793 same.*/
f412b39a 14794DEFUN (show_ip_bgp_paths,
718e3744 14795 show_ip_bgp_paths_cmd,
46f296b4 14796 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14797 SHOW_STR
14798 IP_STR
14799 BGP_STR
46f296b4 14800 BGP_SAFI_HELP_STR
718e3744 14801 "Path information\n")
14802{
d62a17ae 14803 vty_out(vty, "Address Refcnt Path\n");
14804 aspath_print_all_vty(vty);
14805 return CMD_SUCCESS;
718e3744 14806}
14807
718e3744 14808#include "hash.h"
14809
e3b78da8 14810static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14811 struct vty *vty)
718e3744 14812{
d62a17ae 14813 struct community *com;
718e3744 14814
e3b78da8 14815 com = (struct community *)bucket->data;
3f65c5b1 14816 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14817 community_str(com, false));
718e3744 14818}
14819
14820/* Show BGP's community internal data. */
f412b39a 14821DEFUN (show_ip_bgp_community_info,
718e3744 14822 show_ip_bgp_community_info_cmd,
bec37ba5 14823 "show [ip] bgp community-info",
718e3744 14824 SHOW_STR
14825 IP_STR
14826 BGP_STR
14827 "List all bgp community information\n")
14828{
d62a17ae 14829 vty_out(vty, "Address Refcnt Community\n");
718e3744 14830
d62a17ae 14831 hash_iterate(community_hash(),
e3b78da8 14832 (void (*)(struct hash_bucket *,
d62a17ae 14833 void *))community_show_all_iterator,
14834 vty);
718e3744 14835
d62a17ae 14836 return CMD_SUCCESS;
718e3744 14837}
14838
e3b78da8 14839static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14840 struct vty *vty)
57d187bc 14841{
d62a17ae 14842 struct lcommunity *lcom;
57d187bc 14843
e3b78da8 14844 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14845 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14846 lcommunity_str(lcom, false));
57d187bc
JS
14847}
14848
14849/* Show BGP's community internal data. */
14850DEFUN (show_ip_bgp_lcommunity_info,
14851 show_ip_bgp_lcommunity_info_cmd,
14852 "show ip bgp large-community-info",
14853 SHOW_STR
14854 IP_STR
14855 BGP_STR
14856 "List all bgp large-community information\n")
14857{
d62a17ae 14858 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14859
d62a17ae 14860 hash_iterate(lcommunity_hash(),
e3b78da8 14861 (void (*)(struct hash_bucket *,
d62a17ae 14862 void *))lcommunity_show_all_iterator,
14863 vty);
57d187bc 14864
d62a17ae 14865 return CMD_SUCCESS;
57d187bc 14866}
2986cac2 14867/* Graceful Restart */
14868
14869static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14870 struct bgp *bgp,
14871 bool use_json,
14872 json_object *json)
2986cac2 14873{
57d187bc
JS
14874
14875
2986cac2 14876 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14877
7318ae88 14878 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14879
14880 switch (bgp_global_gr_mode) {
14881
14882 case GLOBAL_HELPER:
13909c4f 14883 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14884 break;
14885
14886 case GLOBAL_GR:
13909c4f 14887 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14888 break;
14889
14890 case GLOBAL_DISABLE:
13909c4f 14891 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14892 break;
14893
14894 case GLOBAL_INVALID:
2986cac2 14895 vty_out(vty,
2ba1fe69 14896 "Global BGP GR Mode Invalid\n");
2986cac2 14897 break;
14898 }
14899 vty_out(vty, "\n");
14900}
14901
36235319
QY
14902static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14903 enum show_type type,
14904 const char *ip_str,
14905 afi_t afi, bool use_json)
2986cac2 14906{
14907 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14908 afi = AFI_IP;
14909
14910 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14911
36235319
QY
14912 bgp_show_neighbor_graceful_restart_vty(
14913 vty, type, ip_str, afi, use_json);
2986cac2 14914 afi++;
14915 }
14916 } else if (afi != AFI_MAX) {
36235319
QY
14917 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14918 use_json);
2986cac2 14919 } else {
14920 return CMD_ERR_INCOMPLETE;
14921 }
14922
14923 return CMD_SUCCESS;
14924}
14925/* Graceful Restart */
14926
f412b39a 14927DEFUN (show_ip_bgp_attr_info,
718e3744 14928 show_ip_bgp_attr_info_cmd,
bec37ba5 14929 "show [ip] bgp attribute-info",
718e3744 14930 SHOW_STR
14931 IP_STR
14932 BGP_STR
14933 "List all bgp attribute information\n")
14934{
d62a17ae 14935 attr_show_all(vty);
14936 return CMD_SUCCESS;
718e3744 14937}
6b0655a2 14938
03915806
CS
14939static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14940 afi_t afi, safi_t safi,
14941 bool use_json, json_object *json)
53089bec 14942{
14943 struct bgp *bgp;
14944 struct listnode *node;
14945 char *vname;
14946 char buf1[INET6_ADDRSTRLEN];
14947 char *ecom_str;
14948 vpn_policy_direction_t dir;
14949
03915806 14950 if (json) {
b46dfd20
DS
14951 json_object *json_import_vrfs = NULL;
14952 json_object *json_export_vrfs = NULL;
14953
b46dfd20
DS
14954 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14955
53089bec 14956 if (!bgp) {
b46dfd20
DS
14957 vty_out(vty, "%s\n",
14958 json_object_to_json_string_ext(
14959 json,
14960 JSON_C_TO_STRING_PRETTY));
14961 json_object_free(json);
14962
53089bec 14963 return CMD_WARNING;
14964 }
b46dfd20 14965
94d4c685
DS
14966 /* Provide context for the block */
14967 json_object_string_add(json, "vrf", name ? name : "default");
14968 json_object_string_add(json, "afiSafi",
5cb5f4d0 14969 get_afi_safi_str(afi, safi, true));
94d4c685 14970
b46dfd20
DS
14971 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14972 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14973 json_object_string_add(json, "importFromVrfs", "none");
14974 json_object_string_add(json, "importRts", "none");
14975 } else {
6ce24e52
DS
14976 json_import_vrfs = json_object_new_array();
14977
b46dfd20
DS
14978 for (ALL_LIST_ELEMENTS_RO(
14979 bgp->vpn_policy[afi].import_vrf,
14980 node, vname))
14981 json_object_array_add(json_import_vrfs,
14982 json_object_new_string(vname));
14983
b20875ea
CS
14984 json_object_object_add(json, "importFromVrfs",
14985 json_import_vrfs);
b46dfd20 14986 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14987 if (bgp->vpn_policy[afi].rtlist[dir]) {
14988 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14989 bgp->vpn_policy[afi].rtlist[dir],
14990 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14991 json_object_string_add(json, "importRts",
14992 ecom_str);
14993 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14994 } else
14995 json_object_string_add(json, "importRts",
14996 "none");
b46dfd20
DS
14997 }
14998
14999 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15000 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15001 json_object_string_add(json, "exportToVrfs", "none");
15002 json_object_string_add(json, "routeDistinguisher",
15003 "none");
15004 json_object_string_add(json, "exportRts", "none");
15005 } else {
6ce24e52
DS
15006 json_export_vrfs = json_object_new_array();
15007
b46dfd20
DS
15008 for (ALL_LIST_ELEMENTS_RO(
15009 bgp->vpn_policy[afi].export_vrf,
15010 node, vname))
15011 json_object_array_add(json_export_vrfs,
15012 json_object_new_string(vname));
15013 json_object_object_add(json, "exportToVrfs",
15014 json_export_vrfs);
15015 json_object_string_add(json, "routeDistinguisher",
15016 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15017 buf1, RD_ADDRSTRLEN));
15018
15019 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15020 if (bgp->vpn_policy[afi].rtlist[dir]) {
15021 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15022 bgp->vpn_policy[afi].rtlist[dir],
15023 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15024 json_object_string_add(json, "exportRts",
15025 ecom_str);
15026 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15027 } else
15028 json_object_string_add(json, "exportRts",
15029 "none");
b46dfd20
DS
15030 }
15031
03915806
CS
15032 if (use_json) {
15033 vty_out(vty, "%s\n",
15034 json_object_to_json_string_ext(json,
b46dfd20 15035 JSON_C_TO_STRING_PRETTY));
03915806
CS
15036 json_object_free(json);
15037 }
53089bec 15038 } else {
b46dfd20
DS
15039 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15040
53089bec 15041 if (!bgp) {
b46dfd20 15042 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15043 return CMD_WARNING;
15044 }
53089bec 15045
b46dfd20
DS
15046 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15047 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15048 vty_out(vty,
15049 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15050 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15051 else {
15052 vty_out(vty,
15053 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15054 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15055
15056 for (ALL_LIST_ELEMENTS_RO(
15057 bgp->vpn_policy[afi].import_vrf,
15058 node, vname))
15059 vty_out(vty, " %s\n", vname);
15060
15061 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15062 ecom_str = NULL;
15063 if (bgp->vpn_policy[afi].rtlist[dir]) {
15064 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15065 bgp->vpn_policy[afi].rtlist[dir],
15066 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15067 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15068
b20875ea
CS
15069 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15070 } else
15071 vty_out(vty, "Import RT(s):\n");
53089bec 15072 }
53089bec 15073
b46dfd20
DS
15074 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15075 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15076 vty_out(vty,
15077 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15078 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15079 else {
15080 vty_out(vty,
04c9077f 15081 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15082 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15083
15084 for (ALL_LIST_ELEMENTS_RO(
15085 bgp->vpn_policy[afi].export_vrf,
15086 node, vname))
15087 vty_out(vty, " %s\n", vname);
15088
15089 vty_out(vty, "RD: %s\n",
15090 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15091 buf1, RD_ADDRSTRLEN));
15092
15093 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15094 if (bgp->vpn_policy[afi].rtlist[dir]) {
15095 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15096 bgp->vpn_policy[afi].rtlist[dir],
15097 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15098 vty_out(vty, "Export RT: %s\n", ecom_str);
15099 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15100 } else
15101 vty_out(vty, "Import RT(s):\n");
53089bec 15102 }
53089bec 15103 }
15104
15105 return CMD_SUCCESS;
15106}
15107
03915806
CS
15108static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15109 safi_t safi, bool use_json)
15110{
15111 struct listnode *node, *nnode;
15112 struct bgp *bgp;
15113 char *vrf_name = NULL;
15114 json_object *json = NULL;
15115 json_object *json_vrf = NULL;
15116 json_object *json_vrfs = NULL;
15117
15118 if (use_json) {
15119 json = json_object_new_object();
15120 json_vrfs = json_object_new_object();
15121 }
15122
15123 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15124
15125 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15126 vrf_name = bgp->name;
15127
15128 if (use_json) {
15129 json_vrf = json_object_new_object();
15130 } else {
15131 vty_out(vty, "\nInstance %s:\n",
15132 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15133 ? VRF_DEFAULT_NAME : bgp->name);
15134 }
15135 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15136 if (use_json) {
15137 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15138 json_object_object_add(json_vrfs,
15139 VRF_DEFAULT_NAME, json_vrf);
15140 else
15141 json_object_object_add(json_vrfs, vrf_name,
15142 json_vrf);
15143 }
15144 }
15145
15146 if (use_json) {
15147 json_object_object_add(json, "vrfs", json_vrfs);
15148 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15149 JSON_C_TO_STRING_PRETTY));
15150 json_object_free(json);
15151 }
15152
15153 return CMD_SUCCESS;
15154}
15155
53089bec 15156/* "show [ip] bgp route-leak" command. */
15157DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15158 show_ip_bgp_route_leak_cmd,
15159 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15160 SHOW_STR
15161 IP_STR
15162 BGP_STR
15163 BGP_INSTANCE_HELP_STR
15164 BGP_AFI_HELP_STR
15165 BGP_SAFI_HELP_STR
15166 "Route leaking information\n"
15167 JSON_STR)
53089bec 15168{
15169 char *vrf = NULL;
15170 afi_t afi = AFI_MAX;
15171 safi_t safi = SAFI_MAX;
15172
9f049418 15173 bool uj = use_json(argc, argv);
53089bec 15174 int idx = 0;
03915806 15175 json_object *json = NULL;
53089bec 15176
15177 /* show [ip] bgp */
15178 if (argv_find(argv, argc, "ip", &idx)) {
15179 afi = AFI_IP;
15180 safi = SAFI_UNICAST;
15181 }
15182 /* [vrf VIEWVRFNAME] */
15183 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15184 vty_out(vty,
15185 "%% This command is not applicable to BGP views\n");
53089bec 15186 return CMD_WARNING;
15187 }
15188
9a8bdf1c
PG
15189 if (argv_find(argv, argc, "vrf", &idx)) {
15190 vrf = argv[idx + 1]->arg;
15191 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15192 vrf = NULL;
15193 }
53089bec 15194 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15195 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15196 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15197 }
15198
15199 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15200 vty_out(vty,
15201 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15202 return CMD_WARNING;
15203 }
15204
03915806
CS
15205 if (vrf && strmatch(vrf, "all"))
15206 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15207
15208 if (uj)
15209 json = json_object_new_object();
15210
15211 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15212}
15213
d62a17ae 15214static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15215 safi_t safi)
f186de26 15216{
d62a17ae 15217 struct listnode *node, *nnode;
15218 struct bgp *bgp;
f186de26 15219
d62a17ae 15220 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15221 vty_out(vty, "\nInstance %s:\n",
15222 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15223 ? VRF_DEFAULT_NAME
d62a17ae 15224 : bgp->name);
15225 update_group_show(bgp, afi, safi, vty, 0);
15226 }
f186de26 15227}
15228
d62a17ae 15229static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15230 int safi, uint64_t subgrp_id)
4fb25c53 15231{
d62a17ae 15232 struct bgp *bgp;
4fb25c53 15233
d62a17ae 15234 if (name) {
15235 if (strmatch(name, "all")) {
15236 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15237 return CMD_SUCCESS;
15238 } else {
15239 bgp = bgp_lookup_by_name(name);
15240 }
15241 } else {
15242 bgp = bgp_get_default();
15243 }
4fb25c53 15244
d62a17ae 15245 if (bgp)
15246 update_group_show(bgp, afi, safi, vty, subgrp_id);
15247 return CMD_SUCCESS;
4fb25c53
DW
15248}
15249
8fe8a7f6
DS
15250DEFUN (show_ip_bgp_updgrps,
15251 show_ip_bgp_updgrps_cmd,
c1a44e43 15252 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15253 SHOW_STR
15254 IP_STR
15255 BGP_STR
15256 BGP_INSTANCE_HELP_STR
c9e571b4 15257 BGP_AFI_HELP_STR
9bedbb1e 15258 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15259 "Detailed info about dynamic update groups\n"
15260 "Specific subgroup to display detailed info for\n")
8386ac43 15261{
d62a17ae 15262 char *vrf = NULL;
15263 afi_t afi = AFI_IP6;
15264 safi_t safi = SAFI_UNICAST;
15265 uint64_t subgrp_id = 0;
15266
15267 int idx = 0;
15268
15269 /* show [ip] bgp */
15270 if (argv_find(argv, argc, "ip", &idx))
15271 afi = AFI_IP;
9a8bdf1c
PG
15272 /* [<vrf> VIEWVRFNAME] */
15273 if (argv_find(argv, argc, "vrf", &idx)) {
15274 vrf = argv[idx + 1]->arg;
15275 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15276 vrf = NULL;
15277 } else if (argv_find(argv, argc, "view", &idx))
15278 /* [<view> VIEWVRFNAME] */
15279 vrf = argv[idx + 1]->arg;
d62a17ae 15280 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15281 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15282 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15283 }
5bf15956 15284
d62a17ae 15285 /* get subgroup id, if provided */
15286 idx = argc - 1;
15287 if (argv[idx]->type == VARIABLE_TKN)
15288 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15289
d62a17ae 15290 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15291}
15292
f186de26 15293DEFUN (show_bgp_instance_all_ipv6_updgrps,
15294 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15295 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15296 SHOW_STR
716b2d8a 15297 IP_STR
f186de26 15298 BGP_STR
15299 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15300 "Detailed info about dynamic update groups\n")
f186de26 15301{
d62a17ae 15302 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15303 return CMD_SUCCESS;
f186de26 15304}
15305
43d3f4fc
DS
15306DEFUN (show_bgp_l2vpn_evpn_updgrps,
15307 show_bgp_l2vpn_evpn_updgrps_cmd,
15308 "show [ip] bgp l2vpn evpn update-groups",
15309 SHOW_STR
15310 IP_STR
15311 BGP_STR
15312 "l2vpn address family\n"
15313 "evpn sub-address family\n"
15314 "Detailed info about dynamic update groups\n")
15315{
15316 char *vrf = NULL;
15317 uint64_t subgrp_id = 0;
15318
15319 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15320 return CMD_SUCCESS;
15321}
15322
5bf15956
DW
15323DEFUN (show_bgp_updgrps_stats,
15324 show_bgp_updgrps_stats_cmd,
716b2d8a 15325 "show [ip] bgp update-groups statistics",
3f9c7369 15326 SHOW_STR
716b2d8a 15327 IP_STR
3f9c7369 15328 BGP_STR
0c7b1b01 15329 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15330 "Statistics\n")
15331{
d62a17ae 15332 struct bgp *bgp;
3f9c7369 15333
d62a17ae 15334 bgp = bgp_get_default();
15335 if (bgp)
15336 update_group_show_stats(bgp, vty);
3f9c7369 15337
d62a17ae 15338 return CMD_SUCCESS;
3f9c7369
DS
15339}
15340
8386ac43 15341DEFUN (show_bgp_instance_updgrps_stats,
15342 show_bgp_instance_updgrps_stats_cmd,
18c57037 15343 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15344 SHOW_STR
716b2d8a 15345 IP_STR
8386ac43 15346 BGP_STR
15347 BGP_INSTANCE_HELP_STR
0c7b1b01 15348 "Detailed info about dynamic update groups\n"
8386ac43 15349 "Statistics\n")
15350{
d62a17ae 15351 int idx_word = 3;
15352 struct bgp *bgp;
8386ac43 15353
d62a17ae 15354 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15355 if (bgp)
15356 update_group_show_stats(bgp, vty);
8386ac43 15357
d62a17ae 15358 return CMD_SUCCESS;
8386ac43 15359}
15360
d62a17ae 15361static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15362 afi_t afi, safi_t safi,
15363 const char *what, uint64_t subgrp_id)
3f9c7369 15364{
d62a17ae 15365 struct bgp *bgp;
8386ac43 15366
d62a17ae 15367 if (name)
15368 bgp = bgp_lookup_by_name(name);
15369 else
15370 bgp = bgp_get_default();
8386ac43 15371
d62a17ae 15372 if (bgp) {
15373 if (!strcmp(what, "advertise-queue"))
15374 update_group_show_adj_queue(bgp, afi, safi, vty,
15375 subgrp_id);
15376 else if (!strcmp(what, "advertised-routes"))
15377 update_group_show_advertised(bgp, afi, safi, vty,
15378 subgrp_id);
15379 else if (!strcmp(what, "packet-queue"))
15380 update_group_show_packet_queue(bgp, afi, safi, vty,
15381 subgrp_id);
15382 }
3f9c7369
DS
15383}
15384
dc64bdec
QY
15385DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15386 show_ip_bgp_instance_updgrps_adj_s_cmd,
15387 "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",
15388 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15389 BGP_SAFI_HELP_STR
15390 "Detailed info about dynamic update groups\n"
15391 "Specific subgroup to display info for\n"
15392 "Advertisement queue\n"
15393 "Announced routes\n"
15394 "Packet queue\n")
3f9c7369 15395{
dc64bdec
QY
15396 uint64_t subgrp_id = 0;
15397 afi_t afiz;
15398 safi_t safiz;
15399 if (sgid)
15400 subgrp_id = strtoull(sgid, NULL, 10);
15401
15402 if (!ip && !afi)
15403 afiz = AFI_IP6;
15404 if (!ip && afi)
15405 afiz = bgp_vty_afi_from_str(afi);
15406 if (ip && !afi)
15407 afiz = AFI_IP;
15408 if (ip && afi) {
15409 afiz = bgp_vty_afi_from_str(afi);
15410 if (afiz != AFI_IP)
15411 vty_out(vty,
15412 "%% Cannot specify both 'ip' and 'ipv6'\n");
15413 return CMD_WARNING;
15414 }
d62a17ae 15415
dc64bdec 15416 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15417
dc64bdec 15418 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15419 return CMD_SUCCESS;
15420}
15421
d62a17ae 15422static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15423{
15424 struct listnode *node, *nnode;
15425 struct prefix *range;
15426 struct peer *conf;
15427 struct peer *peer;
d62a17ae 15428 afi_t afi;
15429 safi_t safi;
15430 const char *peer_status;
15431 const char *af_str;
15432 int lr_count;
15433 int dynamic;
15434 int af_cfgd;
15435
15436 conf = group->conf;
15437
15438 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 15439 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 15440 group->name, conf->as);
d62a17ae 15441 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 15442 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 15443 group->name, group->bgp->as);
d62a17ae 15444 } else {
15445 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15446 }
f14e6fdb 15447
d62a17ae 15448 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15449 vty_out(vty, " Peer-group type is internal\n");
15450 else
15451 vty_out(vty, " Peer-group type is external\n");
15452
15453 /* Display AFs configured. */
15454 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
15455 FOREACH_AFI_SAFI (afi, safi) {
15456 if (conf->afc[afi][safi]) {
15457 af_cfgd = 1;
5cb5f4d0 15458 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 15459 }
05c7a1cc 15460 }
d62a17ae 15461 if (!af_cfgd)
15462 vty_out(vty, " none\n");
15463 else
15464 vty_out(vty, "\n");
15465
15466 /* Display listen ranges (for dynamic neighbors), if any */
15467 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15468 if (afi == AFI_IP)
15469 af_str = "IPv4";
15470 else if (afi == AFI_IP6)
15471 af_str = "IPv6";
15472 else
15473 af_str = "???";
15474 lr_count = listcount(group->listen_range[afi]);
15475 if (lr_count) {
15476 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15477 af_str);
15478
15479
15480 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
2dbe669b
DA
15481 nnode, range))
15482 vty_out(vty, " %pFX\n", range);
d62a17ae 15483 }
15484 }
f14e6fdb 15485
d62a17ae 15486 /* Display group members and their status */
15487 if (listcount(group->peer)) {
15488 vty_out(vty, " Peer-group members:\n");
15489 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15490 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15491 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15492 peer_status = "Idle (Admin)";
15493 else if (CHECK_FLAG(peer->sflags,
15494 PEER_STATUS_PREFIX_OVERFLOW))
15495 peer_status = "Idle (PfxCt)";
15496 else
15497 peer_status = lookup_msg(bgp_status_msg,
15498 peer->status, NULL);
15499
15500 dynamic = peer_dynamic_neighbor(peer);
15501 vty_out(vty, " %s %s %s \n", peer->host,
15502 dynamic ? "(dynamic)" : "", peer_status);
15503 }
15504 }
f14e6fdb 15505
d62a17ae 15506 return CMD_SUCCESS;
15507}
15508
ff9959b0
QY
15509static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15510 const char *group_name)
d62a17ae 15511{
ff9959b0 15512 struct bgp *bgp;
d62a17ae 15513 struct listnode *node, *nnode;
15514 struct peer_group *group;
ff9959b0
QY
15515 bool found = false;
15516
15517 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15518
15519 if (!bgp) {
9f049418 15520 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
15521 return CMD_WARNING;
15522 }
d62a17ae 15523
15524 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15525 if (group_name) {
15526 if (strmatch(group->name, group_name)) {
d62a17ae 15527 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
15528 found = true;
15529 break;
d62a17ae 15530 }
ff9959b0
QY
15531 } else {
15532 bgp_show_one_peer_group(vty, group);
d62a17ae 15533 }
f14e6fdb 15534 }
f14e6fdb 15535
ff9959b0 15536 if (group_name && !found)
d62a17ae 15537 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15538
d62a17ae 15539 return CMD_SUCCESS;
f14e6fdb
DS
15540}
15541
f14e6fdb
DS
15542DEFUN (show_ip_bgp_peer_groups,
15543 show_ip_bgp_peer_groups_cmd,
18c57037 15544 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
15545 SHOW_STR
15546 IP_STR
15547 BGP_STR
8386ac43 15548 BGP_INSTANCE_HELP_STR
d6e3c605
QY
15549 "Detailed information on BGP peer groups\n"
15550 "Peer group name\n")
f14e6fdb 15551{
d62a17ae 15552 char *vrf, *pg;
d62a17ae 15553 int idx = 0;
f14e6fdb 15554
a4d82a8a
PZ
15555 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15556 : NULL;
d62a17ae 15557 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15558
ff9959b0 15559 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 15560}
3f9c7369 15561
d6e3c605 15562
718e3744 15563/* Redistribute VTY commands. */
15564
37a87b8f
CS
15565DEFUN_YANG (bgp_redistribute_ipv4,
15566 bgp_redistribute_ipv4_cmd,
15567 "redistribute " FRR_IP_REDIST_STR_BGPD,
15568 "Redistribute information from another routing protocol\n"
15569 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15570{
d62a17ae 15571 int idx_protocol = 1;
37a87b8f 15572 char base_xpath[XPATH_MAXLEN];
718e3744 15573
37a87b8f
CS
15574 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15575 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15576 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15577 argv[idx_protocol]->text, "0");
15578
15579 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 15580
37a87b8f 15581 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15582}
15583
d62a17ae 15584ALIAS_HIDDEN(
15585 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15586 "redistribute " FRR_IP_REDIST_STR_BGPD,
15587 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15588
37a87b8f
CS
15589DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15590 bgp_redistribute_ipv4_rmap_cmd,
15591 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15592 "Redistribute information from another routing protocol\n"
15593 FRR_IP_REDIST_HELP_STR_BGPD
15594 "Route map reference\n"
15595 "Pointer to route-map entries\n")
718e3744 15596{
d62a17ae 15597 int idx_protocol = 1;
15598 int idx_word = 3;
37a87b8f
CS
15599 char base_xpath[XPATH_MAXLEN];
15600
15601 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15602 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15603 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15604 argv[idx_protocol]->text, "0");
718e3744 15605
37a87b8f
CS
15606 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15607 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15608 argv[idx_word]->arg);
15609
15610 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15611}
15612
d62a17ae 15613ALIAS_HIDDEN(
15614 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15615 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15616 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15617 "Route map reference\n"
15618 "Pointer to route-map entries\n")
596c17ba 15619
37a87b8f
CS
15620DEFUN_YANG (bgp_redistribute_ipv4_metric,
15621 bgp_redistribute_ipv4_metric_cmd,
15622 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15623 "Redistribute information from another routing protocol\n"
15624 FRR_IP_REDIST_HELP_STR_BGPD
15625 "Metric for redistributed routes\n"
15626 "Default metric\n")
718e3744 15627{
d62a17ae 15628 int idx_protocol = 1;
15629 int idx_number = 3;
37a87b8f
CS
15630 char base_xpath[XPATH_MAXLEN];
15631
15632 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15633 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15634 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15635 argv[idx_protocol]->text, "0");
d62a17ae 15636
37a87b8f
CS
15637 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15638 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15639 argv[idx_number]->arg);
15640
15641 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15642}
15643
15644ALIAS_HIDDEN(
15645 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15646 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15647 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15648 "Metric for redistributed routes\n"
15649 "Default metric\n")
596c17ba 15650
37a87b8f
CS
15651DEFUN_YANG(
15652 bgp_redistribute_ipv4_rmap_metric,
15653 bgp_redistribute_ipv4_rmap_metric_cmd,
15654 "redistribute " FRR_IP_REDIST_STR_BGPD
15655 " route-map WORD metric (0-4294967295)",
15656 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15657 "Route map reference\n"
15658 "Pointer to route-map entries\n"
15659 "Metric for redistributed routes\n"
15660 "Default metric\n")
718e3744 15661{
d62a17ae 15662 int idx_protocol = 1;
15663 int idx_word = 3;
15664 int idx_number = 5;
37a87b8f
CS
15665 char base_xpath[XPATH_MAXLEN];
15666
15667 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15668 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15669 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15670 argv[idx_protocol]->text, "0");
15671
15672 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15673 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15674 argv[idx_word]->arg);
15675 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15676 argv[idx_number]->arg);
d62a17ae 15677
37a87b8f 15678 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15679}
15680
15681ALIAS_HIDDEN(
15682 bgp_redistribute_ipv4_rmap_metric,
15683 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15684 "redistribute " FRR_IP_REDIST_STR_BGPD
15685 " route-map WORD metric (0-4294967295)",
15686 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15687 "Route map reference\n"
15688 "Pointer to route-map entries\n"
15689 "Metric for redistributed routes\n"
15690 "Default metric\n")
596c17ba 15691
37a87b8f
CS
15692DEFUN_YANG(
15693 bgp_redistribute_ipv4_metric_rmap,
15694 bgp_redistribute_ipv4_metric_rmap_cmd,
15695 "redistribute " FRR_IP_REDIST_STR_BGPD
15696 " metric (0-4294967295) route-map WORD",
15697 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15698 "Metric for redistributed routes\n"
15699 "Default metric\n"
15700 "Route map reference\n"
15701 "Pointer to route-map entries\n")
718e3744 15702{
d62a17ae 15703 int idx_protocol = 1;
d62a17ae 15704 int idx_word = 5;
37a87b8f
CS
15705 int idx_number = 3;
15706 char base_xpath[XPATH_MAXLEN];
15707
15708 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15709 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15710 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15711 argv[idx_protocol]->text, "0");
15712
15713 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15714 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15715 argv[idx_number]->arg);
15716 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15717 argv[idx_word]->arg);
d62a17ae 15718
37a87b8f 15719 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15720}
15721
15722ALIAS_HIDDEN(
15723 bgp_redistribute_ipv4_metric_rmap,
15724 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15725 "redistribute " FRR_IP_REDIST_STR_BGPD
15726 " metric (0-4294967295) route-map WORD",
15727 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15728 "Metric for redistributed routes\n"
15729 "Default metric\n"
15730 "Route map reference\n"
15731 "Pointer to route-map entries\n")
596c17ba 15732
37a87b8f
CS
15733DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15734 bgp_redistribute_ipv4_ospf_cmd,
15735 "redistribute <ospf|table> (1-65535)",
15736 "Redistribute information from another routing protocol\n"
15737 "Open Shortest Path First (OSPFv2)\n"
15738 "Non-main Kernel Routing Table\n"
15739 "Instance ID/Table ID\n")
7c8ff89e 15740{
37a87b8f 15741 int idx_protocol = 1;
d62a17ae 15742 int idx_number = 2;
37a87b8f 15743 char base_xpath[XPATH_MAXLEN];
7c8ff89e 15744
37a87b8f
CS
15745 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15746 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15747 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15748 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 15749
37a87b8f 15750 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 15751
37a87b8f 15752 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
15753}
15754
d62a17ae 15755ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15756 "redistribute <ospf|table> (1-65535)",
15757 "Redistribute information from another routing protocol\n"
15758 "Open Shortest Path First (OSPFv2)\n"
15759 "Non-main Kernel Routing Table\n"
15760 "Instance ID/Table ID\n")
596c17ba 15761
37a87b8f
CS
15762DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15763 bgp_redistribute_ipv4_ospf_rmap_cmd,
15764 "redistribute <ospf|table> (1-65535) route-map WORD",
15765 "Redistribute information from another routing protocol\n"
15766 "Open Shortest Path First (OSPFv2)\n"
15767 "Non-main Kernel Routing Table\n"
15768 "Instance ID/Table ID\n"
15769 "Route map reference\n"
15770 "Pointer to route-map entries\n")
7c8ff89e 15771{
37a87b8f 15772 int idx_protocol = 1;
d62a17ae 15773 int idx_number = 2;
15774 int idx_word = 4;
37a87b8f
CS
15775 char base_xpath[XPATH_MAXLEN];
15776
15777 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15778 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15779 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15780 argv[idx_protocol]->text, argv[idx_number]->arg);
15781
15782 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15783
15784 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15785 argv[idx_word]->arg);
d62a17ae 15786
37a87b8f 15787 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15788}
15789
15790ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15791 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15792 "redistribute <ospf|table> (1-65535) route-map WORD",
15793 "Redistribute information from another routing protocol\n"
15794 "Open Shortest Path First (OSPFv2)\n"
15795 "Non-main Kernel Routing Table\n"
15796 "Instance ID/Table ID\n"
15797 "Route map reference\n"
15798 "Pointer to route-map entries\n")
596c17ba 15799
37a87b8f
CS
15800DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15801 bgp_redistribute_ipv4_ospf_metric_cmd,
15802 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15803 "Redistribute information from another routing protocol\n"
15804 "Open Shortest Path First (OSPFv2)\n"
15805 "Non-main Kernel Routing Table\n"
15806 "Instance ID/Table ID\n"
15807 "Metric for redistributed routes\n"
15808 "Default metric\n")
7c8ff89e 15809{
37a87b8f 15810 int idx_protocol = 1;
d62a17ae 15811 int idx_number = 2;
15812 int idx_number_2 = 4;
37a87b8f
CS
15813 char base_xpath[XPATH_MAXLEN];
15814
15815 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15816 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15817 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15818 argv[idx_protocol]->text, argv[idx_number]->arg);
15819
15820 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15821
37a87b8f
CS
15822 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15823 argv[idx_number_2]->arg);
d62a17ae 15824
37a87b8f 15825 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15826}
15827
15828ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15829 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15830 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15831 "Redistribute information from another routing protocol\n"
15832 "Open Shortest Path First (OSPFv2)\n"
15833 "Non-main Kernel Routing Table\n"
15834 "Instance ID/Table ID\n"
15835 "Metric for redistributed routes\n"
15836 "Default metric\n")
596c17ba 15837
37a87b8f
CS
15838DEFUN_YANG(
15839 bgp_redistribute_ipv4_ospf_rmap_metric,
15840 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15841 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15842 "Redistribute information from another routing protocol\n"
15843 "Open Shortest Path First (OSPFv2)\n"
15844 "Non-main Kernel Routing Table\n"
15845 "Instance ID/Table ID\n"
15846 "Route map reference\n"
15847 "Pointer to route-map entries\n"
15848 "Metric for redistributed routes\n"
15849 "Default metric\n")
7c8ff89e 15850{
37a87b8f 15851 int idx_protocol = 1;
d62a17ae 15852 int idx_number = 2;
15853 int idx_word = 4;
15854 int idx_number_2 = 6;
37a87b8f
CS
15855 char base_xpath[XPATH_MAXLEN];
15856
15857 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15858 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15859 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15860 argv[idx_protocol]->text, argv[idx_number]->arg);
15861
15862 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15863
37a87b8f
CS
15864 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15865 argv[idx_word]->arg);
15866 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15867 argv[idx_number_2]->arg);
d62a17ae 15868
37a87b8f 15869 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15870}
15871
15872ALIAS_HIDDEN(
15873 bgp_redistribute_ipv4_ospf_rmap_metric,
15874 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15875 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15876 "Redistribute information from another routing protocol\n"
15877 "Open Shortest Path First (OSPFv2)\n"
15878 "Non-main Kernel Routing Table\n"
15879 "Instance ID/Table ID\n"
15880 "Route map reference\n"
15881 "Pointer to route-map entries\n"
15882 "Metric for redistributed routes\n"
15883 "Default metric\n")
596c17ba 15884
37a87b8f
CS
15885DEFUN_YANG(
15886 bgp_redistribute_ipv4_ospf_metric_rmap,
15887 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15888 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15889 "Redistribute information from another routing protocol\n"
15890 "Open Shortest Path First (OSPFv2)\n"
15891 "Non-main Kernel Routing Table\n"
15892 "Instance ID/Table ID\n"
15893 "Metric for redistributed routes\n"
15894 "Default metric\n"
15895 "Route map reference\n"
15896 "Pointer to route-map entries\n")
7c8ff89e 15897{
37a87b8f 15898 int idx_protocol = 1;
d62a17ae 15899 int idx_number = 2;
15900 int idx_number_2 = 4;
15901 int idx_word = 6;
37a87b8f
CS
15902 char base_xpath[XPATH_MAXLEN];
15903
15904 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15905 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15906 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15907 argv[idx_protocol]->text, argv[idx_number]->arg);
15908
15909 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15910
37a87b8f
CS
15911 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15912 argv[idx_number_2]->arg);
15913 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15914 argv[idx_word]->arg);
d62a17ae 15915
37a87b8f 15916 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15917}
15918
15919ALIAS_HIDDEN(
15920 bgp_redistribute_ipv4_ospf_metric_rmap,
15921 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15922 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15923 "Redistribute information from another routing protocol\n"
15924 "Open Shortest Path First (OSPFv2)\n"
15925 "Non-main Kernel Routing Table\n"
15926 "Instance ID/Table ID\n"
15927 "Metric for redistributed routes\n"
15928 "Default metric\n"
15929 "Route map reference\n"
15930 "Pointer to route-map entries\n")
596c17ba 15931
37a87b8f
CS
15932DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15933 no_bgp_redistribute_ipv4_ospf_cmd,
15934 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15935 NO_STR
15936 "Redistribute information from another routing protocol\n"
15937 "Open Shortest Path First (OSPFv2)\n"
15938 "Non-main Kernel Routing Table\n"
15939 "Instance ID/Table ID\n"
15940 "Metric for redistributed routes\n"
15941 "Default metric\n"
15942 "Route map reference\n"
15943 "Pointer to route-map entries\n")
7c8ff89e 15944{
37a87b8f 15945 int idx_protocol = 2;
d62a17ae 15946 int idx_number = 3;
37a87b8f 15947 char base_xpath[XPATH_MAXLEN];
d62a17ae 15948
37a87b8f
CS
15949 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15950 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15951 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15952 argv[idx_protocol]->text, argv[idx_number]->arg);
15953
15954 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 15955
37a87b8f 15956 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15957}
15958
15959ALIAS_HIDDEN(
15960 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15961 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15962 NO_STR
15963 "Redistribute information from another routing protocol\n"
15964 "Open Shortest Path First (OSPFv2)\n"
15965 "Non-main Kernel Routing Table\n"
15966 "Instance ID/Table ID\n"
15967 "Metric for redistributed routes\n"
15968 "Default metric\n"
15969 "Route map reference\n"
15970 "Pointer to route-map entries\n")
596c17ba 15971
37a87b8f
CS
15972DEFUN_YANG (no_bgp_redistribute_ipv4,
15973 no_bgp_redistribute_ipv4_cmd,
15974 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15975 NO_STR
15976 "Redistribute information from another routing protocol\n"
15977 FRR_IP_REDIST_HELP_STR_BGPD
15978 "Metric for redistributed routes\n"
15979 "Default metric\n"
15980 "Route map reference\n"
15981 "Pointer to route-map entries\n")
718e3744 15982{
d62a17ae 15983 int idx_protocol = 2;
37a87b8f 15984 char base_xpath[XPATH_MAXLEN];
d62a17ae 15985
37a87b8f
CS
15986 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15987 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15988 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15989 argv[idx_protocol]->text, "0");
15990
15991 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15992
15993 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15994}
15995
15996ALIAS_HIDDEN(
15997 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15998 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15999 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16000 NO_STR
16001 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16002 "Metric for redistributed routes\n"
16003 "Default metric\n"
16004 "Route map reference\n"
16005 "Pointer to route-map entries\n")
596c17ba 16006
37a87b8f
CS
16007DEFUN_YANG (bgp_redistribute_ipv6,
16008 bgp_redistribute_ipv6_cmd,
16009 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16010 "Redistribute information from another routing protocol\n"
16011 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16012{
d62a17ae 16013 int idx_protocol = 1;
37a87b8f 16014 char base_xpath[XPATH_MAXLEN];
718e3744 16015
37a87b8f
CS
16016 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16017 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16018 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16019 argv[idx_protocol]->text, "0");
16020
16021 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 16022
37a87b8f 16023 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16024}
16025
37a87b8f
CS
16026DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16027 bgp_redistribute_ipv6_rmap_cmd,
16028 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16029 "Redistribute information from another routing protocol\n"
16030 FRR_IP6_REDIST_HELP_STR_BGPD
16031 "Route map reference\n"
16032 "Pointer to route-map entries\n")
718e3744 16033{
d62a17ae 16034 int idx_protocol = 1;
16035 int idx_word = 3;
37a87b8f
CS
16036 char base_xpath[XPATH_MAXLEN];
16037
16038 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16039 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16040 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16041 argv[idx_protocol]->text, "0");
718e3744 16042
37a87b8f
CS
16043 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16044 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16045 argv[idx_word]->arg);
16046
16047 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16048}
16049
37a87b8f 16050DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 16051 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16052 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16053 "Redistribute information from another routing protocol\n"
ab0181ee 16054 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16055 "Metric for redistributed routes\n"
16056 "Default metric\n")
16057{
d62a17ae 16058 int idx_protocol = 1;
16059 int idx_number = 3;
37a87b8f
CS
16060 char base_xpath[XPATH_MAXLEN];
16061
16062 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16063 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16064 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16065 argv[idx_protocol]->text, "0");
718e3744 16066
37a87b8f
CS
16067 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16068 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16069 argv[idx_number]->arg);
16070
16071 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16072}
16073
37a87b8f
CS
16074DEFUN_YANG(
16075 bgp_redistribute_ipv6_rmap_metric,
16076 bgp_redistribute_ipv6_rmap_metric_cmd,
16077 "redistribute " FRR_IP6_REDIST_STR_BGPD
16078 " route-map WORD metric (0-4294967295)",
16079 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16080 "Route map reference\n"
16081 "Pointer to route-map entries\n"
16082 "Metric for redistributed routes\n"
16083 "Default metric\n")
718e3744 16084{
d62a17ae 16085 int idx_protocol = 1;
16086 int idx_word = 3;
16087 int idx_number = 5;
37a87b8f
CS
16088 char base_xpath[XPATH_MAXLEN];
16089
16090 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16091 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16092 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16093 argv[idx_protocol]->text, "0");
718e3744 16094
37a87b8f
CS
16095 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16096 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16097 argv[idx_word]->arg);
16098 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16099 argv[idx_number]->arg);
16100
16101 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16102}
16103
37a87b8f
CS
16104DEFUN_YANG(
16105 bgp_redistribute_ipv6_metric_rmap,
16106 bgp_redistribute_ipv6_metric_rmap_cmd,
16107 "redistribute " FRR_IP6_REDIST_STR_BGPD
16108 " metric (0-4294967295) route-map WORD",
16109 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16110 "Metric for redistributed routes\n"
16111 "Default metric\n"
16112 "Route map reference\n"
16113 "Pointer to route-map entries\n")
718e3744 16114{
d62a17ae 16115 int idx_protocol = 1;
d62a17ae 16116 int idx_word = 5;
37a87b8f
CS
16117 int idx_number = 3;
16118 char base_xpath[XPATH_MAXLEN];
16119
16120 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16121 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16122 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16123 argv[idx_protocol]->text, "0");
718e3744 16124
37a87b8f
CS
16125 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16126 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16127 argv[idx_number]->arg);
16128 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16129 argv[idx_word]->arg);
16130
16131 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16132}
16133
37a87b8f
CS
16134DEFUN_YANG(
16135 no_bgp_redistribute_ipv6,
16136 no_bgp_redistribute_ipv6_cmd,
16137 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16138 " [{metric (0-4294967295)|route-map WORD}]",
16139 NO_STR
16140 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16141 "Metric for redistributed routes\n"
16142 "Default metric\n"
16143 "Route map reference\n"
16144 "Pointer to route-map entries\n")
718e3744 16145{
d62a17ae 16146 int idx_protocol = 2;
37a87b8f 16147 char base_xpath[XPATH_MAXLEN];
718e3744 16148
37a87b8f
CS
16149 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16150 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16151 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16152 argv[idx_protocol]->text, "0");
16153
16154 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16155
16156 return nb_cli_apply_changes(vty, base_xpath);
16157}
718e3744 16158
37a87b8f
CS
16159void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16160 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16161{
16162 uint32_t instance = 0;
16163
16164 vty_out(vty, " redistribute %s",
16165 yang_dnode_get_string(dnode, "./route-type"));
16166 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16167 vty_out(vty, " %d", instance);
16168 if (yang_dnode_exists(dnode, "./metric"))
16169 vty_out(vty, " metric %u",
16170 yang_dnode_get_uint32(dnode, "./metric"));
16171 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16172 vty_out(vty, " route-map %s",
16173 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16174 vty_out(vty, "\n");
d62a17ae 16175}
16176
dd65f45e
DL
16177static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16178 afi_t afi, safi_t safi)
d62a17ae 16179{
16180 int i;
16181
16182 /* Unicast redistribution only. */
16183 if (safi != SAFI_UNICAST)
2b791107 16184 return;
d62a17ae 16185
16186 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16187 /* Redistribute BGP does not make sense. */
16188 if (i != ZEBRA_ROUTE_BGP) {
16189 struct list *red_list;
16190 struct listnode *node;
16191 struct bgp_redist *red;
16192
16193 red_list = bgp->redist[afi][i];
16194 if (!red_list)
16195 continue;
16196
16197 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16198 /* "redistribute" configuration. */
16199 vty_out(vty, " redistribute %s",
16200 zebra_route_string(i));
16201 if (red->instance)
16202 vty_out(vty, " %d", red->instance);
16203 if (red->redist_metric_flag)
16204 vty_out(vty, " metric %u",
16205 red->redist_metric);
16206 if (red->rmap.name)
16207 vty_out(vty, " route-map %s",
16208 red->rmap.name);
16209 vty_out(vty, "\n");
16210 }
16211 }
16212 }
718e3744 16213}
6b0655a2 16214
dd65f45e
DL
16215/* peer-group helpers for config-write */
16216
16217static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16218{
16219 if (!peer_group_active(peer)) {
16220 if (CHECK_FLAG(peer->flags_invert, flag))
16221 return !CHECK_FLAG(peer->flags, flag);
16222 else
16223 return !!CHECK_FLAG(peer->flags, flag);
16224 }
16225
16226 return !!CHECK_FLAG(peer->flags_override, flag);
16227}
16228
16229static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16230 uint32_t flag)
16231{
16232 if (!peer_group_active(peer)) {
16233 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16234 return !peer_af_flag_check(peer, afi, safi, flag);
16235 else
16236 return !!peer_af_flag_check(peer, afi, safi, flag);
16237 }
16238
16239 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16240}
16241
16242static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16243 uint8_t type, int direct)
16244{
16245 struct bgp_filter *filter;
16246
16247 if (peer_group_active(peer))
16248 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16249 type);
16250
16251 filter = &peer->filter[afi][safi];
16252 switch (type) {
16253 case PEER_FT_DISTRIBUTE_LIST:
16254 return !!(filter->dlist[direct].name);
16255 case PEER_FT_FILTER_LIST:
16256 return !!(filter->aslist[direct].name);
16257 case PEER_FT_PREFIX_LIST:
16258 return !!(filter->plist[direct].name);
16259 case PEER_FT_ROUTE_MAP:
16260 return !!(filter->map[direct].name);
16261 case PEER_FT_UNSUPPRESS_MAP:
16262 return !!(filter->usmap.name);
7f7940e6
MK
16263 case PEER_FT_ADVERTISE_MAP:
16264 return !!(filter->advmap.aname
16265 && ((filter->advmap.condition == direct)
16266 && filter->advmap.cname));
dd65f45e
DL
16267 default:
16268 return false;
16269 }
16270}
16271
16272/* Return true if the addpath type is set for peer and different from
16273 * peer-group.
16274 */
3dc339cd
DA
16275static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16276 safi_t safi)
dd65f45e
DL
16277{
16278 enum bgp_addpath_strat type, g_type;
16279
16280 type = peer->addpath_type[afi][safi];
16281
16282 if (type != BGP_ADDPATH_NONE) {
16283 if (peer_group_active(peer)) {
16284 g_type = peer->group->conf->addpath_type[afi][safi];
16285
16286 if (type != g_type)
3dc339cd 16287 return true;
dd65f45e 16288 else
3dc339cd 16289 return false;
dd65f45e
DL
16290 }
16291
3dc339cd 16292 return true;
dd65f45e
DL
16293 }
16294
3dc339cd 16295 return false;
dd65f45e
DL
16296}
16297
b9c7bc5a 16298/* This is part of the address-family block (unicast only) */
dd65f45e 16299static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16300 afi_t afi)
16301{
b9c7bc5a 16302 int indent = 2;
ddb5b488 16303
8a066a70 16304 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16305 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16306 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16307 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16308 bgp->vpn_policy[afi]
bb4f6190 16309 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16310 else
16311 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16312 bgp->vpn_policy[afi]
16313 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16314 }
12a844a5
DS
16315 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16316 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16317 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16318 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16319 return;
16320
e70e9f8e
PZ
16321 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16322 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16323
16324 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16325
16326 } else {
16327 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16328 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16329 bgp->vpn_policy[afi].tovpn_label);
16330 }
ddb5b488
PZ
16331 }
16332 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16333 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16334 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16335 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16336 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16337 sizeof(buf)));
16338 }
16339 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16340 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16341
16342 char buf[PREFIX_STRLEN];
16343 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16344 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16345 sizeof(buf))) {
16346
b9c7bc5a
PZ
16347 vty_out(vty, "%*snexthop vpn export %s\n",
16348 indent, "", buf);
ddb5b488
PZ
16349 }
16350 }
16351 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16352 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16353 && ecommunity_cmp(
16354 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16355 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16356
16357 char *b = ecommunity_ecom2str(
16358 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16359 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16360 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16361 XFREE(MTYPE_ECOMMUNITY_STR, b);
16362 } else {
16363 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16364 char *b = ecommunity_ecom2str(
16365 bgp->vpn_policy[afi]
16366 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16367 ECOMMUNITY_FORMAT_ROUTE_MAP,
16368 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16369 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16370 XFREE(MTYPE_ECOMMUNITY_STR, b);
16371 }
16372 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16373 char *b = ecommunity_ecom2str(
16374 bgp->vpn_policy[afi]
16375 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16376 ECOMMUNITY_FORMAT_ROUTE_MAP,
16377 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16378 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16379 XFREE(MTYPE_ECOMMUNITY_STR, b);
16380 }
16381 }
bb4f6190
DS
16382
16383 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16384 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16385 bgp->vpn_policy[afi]
16386 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16387
301ad80a
PG
16388 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16389 char *b = ecommunity_ecom2str(
16390 bgp->vpn_policy[afi]
16391 .import_redirect_rtlist,
16392 ECOMMUNITY_FORMAT_ROUTE_MAP,
16393 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16394
9a659715
PG
16395 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16396 != ECOMMUNITY_SIZE)
c6423c31 16397 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16398 indent, "", b);
16399 else
16400 vty_out(vty, "%*srt redirect import %s\n",
16401 indent, "", b);
301ad80a
PG
16402 XFREE(MTYPE_ECOMMUNITY_STR, b);
16403 }
ddb5b488
PZ
16404}
16405
dd65f45e
DL
16406static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16407 afi_t afi, safi_t safi)
16408{
16409 struct bgp_filter *filter;
16410 char *addr;
16411
16412 addr = peer->host;
16413 filter = &peer->filter[afi][safi];
16414
16415 /* distribute-list. */
16416 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16417 FILTER_IN))
16418 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16419 filter->dlist[FILTER_IN].name);
16420
16421 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16422 FILTER_OUT))
16423 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16424 filter->dlist[FILTER_OUT].name);
16425
16426 /* prefix-list. */
16427 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16428 FILTER_IN))
16429 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16430 filter->plist[FILTER_IN].name);
16431
16432 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16433 FILTER_OUT))
16434 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16435 filter->plist[FILTER_OUT].name);
16436
16437 /* route-map. */
16438 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16439 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16440 filter->map[RMAP_IN].name);
16441
16442 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16443 RMAP_OUT))
16444 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16445 filter->map[RMAP_OUT].name);
16446
16447 /* unsuppress-map */
16448 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16449 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16450 filter->usmap.name);
16451
7f7940e6
MK
16452 /* advertise-map : always applied in OUT direction*/
16453 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16454 CONDITION_NON_EXIST))
16455 vty_out(vty,
16456 " neighbor %s advertise-map %s non-exist-map %s\n",
16457 addr, filter->advmap.aname, filter->advmap.cname);
16458
16459 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16460 CONDITION_EXIST))
16461 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16462 addr, filter->advmap.aname, filter->advmap.cname);
16463
dd65f45e
DL
16464 /* filter-list. */
16465 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16466 FILTER_IN))
16467 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16468 filter->aslist[FILTER_IN].name);
16469
16470 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16471 FILTER_OUT))
16472 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16473 filter->aslist[FILTER_OUT].name);
16474}
16475
16476/* BGP peer configuration display function. */
16477static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16478 struct peer *peer)
16479{
16480 struct peer *g_peer = NULL;
16481 char buf[SU_ADDRSTRLEN];
16482 char *addr;
16483 int if_pg_printed = false;
16484 int if_ras_printed = false;
16485
16486 /* Skip dynamic neighbors. */
16487 if (peer_dynamic_neighbor(peer))
16488 return;
16489
16490 if (peer->conf_if)
16491 addr = peer->conf_if;
16492 else
16493 addr = peer->host;
16494
16495 /************************************
16496 ****** Global to the neighbor ******
16497 ************************************/
16498 if (peer->conf_if) {
16499 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16500 vty_out(vty, " neighbor %s interface v6only", addr);
16501 else
16502 vty_out(vty, " neighbor %s interface", addr);
16503
16504 if (peer_group_active(peer)) {
16505 vty_out(vty, " peer-group %s", peer->group->name);
16506 if_pg_printed = true;
16507 } else if (peer->as_type == AS_SPECIFIED) {
16508 vty_out(vty, " remote-as %u", peer->as);
16509 if_ras_printed = true;
16510 } else if (peer->as_type == AS_INTERNAL) {
16511 vty_out(vty, " remote-as internal");
16512 if_ras_printed = true;
16513 } else if (peer->as_type == AS_EXTERNAL) {
16514 vty_out(vty, " remote-as external");
16515 if_ras_printed = true;
16516 }
16517
16518 vty_out(vty, "\n");
16519 }
16520
16521 /* remote-as and peer-group */
16522 /* peer is a member of a peer-group */
16523 if (peer_group_active(peer)) {
16524 g_peer = peer->group->conf;
16525
16526 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16527 if (peer->as_type == AS_SPECIFIED) {
16528 vty_out(vty, " neighbor %s remote-as %u\n",
16529 addr, peer->as);
16530 } else if (peer->as_type == AS_INTERNAL) {
16531 vty_out(vty,
16532 " neighbor %s remote-as internal\n",
16533 addr);
16534 } else if (peer->as_type == AS_EXTERNAL) {
16535 vty_out(vty,
16536 " neighbor %s remote-as external\n",
16537 addr);
16538 }
16539 }
16540
16541 /* For swpX peers we displayed the peer-group
16542 * via 'neighbor swpX interface peer-group PGNAME' */
16543 if (!if_pg_printed)
16544 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16545 peer->group->name);
16546 }
16547
16548 /* peer is NOT a member of a peer-group */
16549 else {
16550 /* peer is a peer-group, declare the peer-group */
16551 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16552 vty_out(vty, " neighbor %s peer-group\n", addr);
16553 }
16554
16555 if (!if_ras_printed) {
16556 if (peer->as_type == AS_SPECIFIED) {
16557 vty_out(vty, " neighbor %s remote-as %u\n",
16558 addr, peer->as);
16559 } else if (peer->as_type == AS_INTERNAL) {
16560 vty_out(vty,
16561 " neighbor %s remote-as internal\n",
16562 addr);
16563 } else if (peer->as_type == AS_EXTERNAL) {
16564 vty_out(vty,
16565 " neighbor %s remote-as external\n",
16566 addr);
16567 }
16568 }
16569 }
16570
16571 /* local-as */
16572 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16573 vty_out(vty, " neighbor %s local-as %u", addr,
16574 peer->change_local_as);
16575 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16576 vty_out(vty, " no-prepend");
16577 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16578 vty_out(vty, " replace-as");
16579 vty_out(vty, "\n");
16580 }
16581
16582 /* description */
16583 if (peer->desc) {
16584 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16585 }
16586
16587 /* shutdown */
16588 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16589 if (peer->tx_shutdown_message)
16590 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16591 peer->tx_shutdown_message);
16592 else
16593 vty_out(vty, " neighbor %s shutdown\n", addr);
16594 }
16595
8336c896
DA
16596 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16597 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16598 peer->rtt_expected, peer->rtt_keepalive_conf);
16599
dd65f45e
DL
16600 /* bfd */
16601 if (peer->bfd_info) {
16602 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16603 bgp_bfd_peer_config_write(vty, peer, addr);
16604 }
16605 }
16606
16607 /* password */
16608 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16609 vty_out(vty, " neighbor %s password %s\n", addr,
16610 peer->password);
16611
16612 /* neighbor solo */
16613 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16614 if (!peer_group_active(peer)) {
16615 vty_out(vty, " neighbor %s solo\n", addr);
16616 }
16617 }
16618
16619 /* BGP port */
16620 if (peer->port != BGP_PORT_DEFAULT) {
16621 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16622 }
16623
16624 /* Local interface name */
16625 if (peer->ifname) {
16626 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16627 }
16628
16629 /* passive */
16630 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16631 vty_out(vty, " neighbor %s passive\n", addr);
16632
16633 /* ebgp-multihop */
16634 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16635 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16636 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16637 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16638 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16639 peer->ttl);
16640 }
16641 }
16642
16643 /* ttl-security hops */
e2521429 16644 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16645 if (!peer_group_active(peer)
16646 || g_peer->gtsm_hops != peer->gtsm_hops) {
16647 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16648 addr, peer->gtsm_hops);
16649 }
16650 }
16651
16652 /* disable-connected-check */
16653 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16654 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16655
16656 /* enforce-first-as */
16657 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16658 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16659
16660 /* update-source */
16661 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16662 if (peer->update_source)
16663 vty_out(vty, " neighbor %s update-source %s\n", addr,
16664 sockunion2str(peer->update_source, buf,
16665 SU_ADDRSTRLEN));
16666 else if (peer->update_if)
16667 vty_out(vty, " neighbor %s update-source %s\n", addr,
16668 peer->update_if);
16669 }
16670
16671 /* advertisement-interval */
16672 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16673 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16674 peer->routeadv);
16675
16676 /* timers */
16677 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16678 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16679 peer->keepalive, peer->holdtime);
16680
16681 /* timers connect */
16682 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16683 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16684 peer->connect);
5d5393b9
DL
16685 /* need special-case handling for changed default values due to
16686 * config profile / version (because there is no "timers bgp connect"
16687 * command, we need to save this per-peer :/)
16688 */
16689 else if (!peer_group_active(peer) && !peer->connect &&
16690 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16691 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16692 peer->bgp->default_connect_retry);
dd65f45e 16693
d43114f3
DS
16694 /* timers delayopen */
16695 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16696 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16697 peer->delayopen);
16698 /* Save config even though flag is not set if default values have been
16699 * changed
16700 */
16701 else if (!peer_group_active(peer) && !peer->delayopen
16702 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16703 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16704 peer->bgp->default_delayopen);
16705
dd65f45e
DL
16706 /* capability dynamic */
16707 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16708 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16709
16710 /* capability extended-nexthop */
16711 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16712 if (!peer->conf_if) {
16713 if (CHECK_FLAG(peer->flags_invert,
16714 PEER_FLAG_CAPABILITY_ENHE))
16715 vty_out(vty,
16716 " no neighbor %s capability extended-nexthop\n",
16717 addr);
16718 else
16719 vty_out(vty,
16720 " neighbor %s capability extended-nexthop\n",
16721 addr);
16722 }
16723 }
16724
16725 /* dont-capability-negotiation */
16726 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16727 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16728
16729 /* override-capability */
16730 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16731 vty_out(vty, " neighbor %s override-capability\n", addr);
16732
16733 /* strict-capability-match */
16734 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16735 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16736
16737 /* Sender side AS path loop detection. */
16738 if (peer->as_path_loop_detection)
16739 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16740 addr);
cfd47646 16741
16742 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16743 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16744
16745 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16746 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16747 vty_out(vty,
16748 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16749 } else if (CHECK_FLAG(
16750 peer->peer_gr_new_status_flag,
16751 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16752 vty_out(vty,
16753 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16754 } else if (
16755 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16756 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16757 && !(CHECK_FLAG(
16758 peer->peer_gr_new_status_flag,
16759 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16760 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16761 addr);
cfd47646 16762 }
16763 }
dd65f45e
DL
16764}
16765
16766/* BGP peer configuration display function. */
16767static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16768 struct peer *peer, afi_t afi, safi_t safi)
16769{
16770 struct peer *g_peer = NULL;
16771 char *addr;
16772 bool flag_scomm, flag_secomm, flag_slcomm;
16773
16774 /* Skip dynamic neighbors. */
16775 if (peer_dynamic_neighbor(peer))
16776 return;
16777
16778 if (peer->conf_if)
16779 addr = peer->conf_if;
16780 else
16781 addr = peer->host;
16782
16783 /************************************
16784 ****** Per AF to the neighbor ******
16785 ************************************/
16786 if (peer_group_active(peer)) {
16787 g_peer = peer->group->conf;
16788
16789 /* If the peer-group is active but peer is not, print a 'no
16790 * activate' */
16791 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16792 vty_out(vty, " no neighbor %s activate\n", addr);
16793 }
16794
16795 /* If the peer-group is not active but peer is, print an
16796 'activate' */
16797 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16798 vty_out(vty, " neighbor %s activate\n", addr);
16799 }
16800 } else {
16801 if (peer->afc[afi][safi]) {
16802 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16803 if (CHECK_FLAG(bgp->flags,
16804 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16805 vty_out(vty, " neighbor %s activate\n",
16806 addr);
16807 }
16808 } else
16809 vty_out(vty, " neighbor %s activate\n", addr);
16810 } else {
16811 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16812 if (!CHECK_FLAG(bgp->flags,
16813 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16814 vty_out(vty,
16815 " no neighbor %s activate\n",
16816 addr);
16817 }
16818 }
16819 }
16820 }
16821
16822 /* addpath TX knobs */
16823 if (peergroup_af_addpath_check(peer, afi, safi)) {
16824 switch (peer->addpath_type[afi][safi]) {
16825 case BGP_ADDPATH_ALL:
16826 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16827 addr);
16828 break;
16829 case BGP_ADDPATH_BEST_PER_AS:
16830 vty_out(vty,
16831 " neighbor %s addpath-tx-bestpath-per-AS\n",
16832 addr);
16833 break;
16834 case BGP_ADDPATH_MAX:
16835 case BGP_ADDPATH_NONE:
16836 break;
16837 }
16838 }
16839
16840 /* ORF capability. */
16841 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16842 || peergroup_af_flag_check(peer, afi, safi,
16843 PEER_FLAG_ORF_PREFIX_RM)) {
16844 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16845
16846 if (peergroup_af_flag_check(peer, afi, safi,
16847 PEER_FLAG_ORF_PREFIX_SM)
16848 && peergroup_af_flag_check(peer, afi, safi,
16849 PEER_FLAG_ORF_PREFIX_RM))
16850 vty_out(vty, " both");
16851 else if (peergroup_af_flag_check(peer, afi, safi,
16852 PEER_FLAG_ORF_PREFIX_SM))
16853 vty_out(vty, " send");
16854 else
16855 vty_out(vty, " receive");
16856 vty_out(vty, "\n");
16857 }
16858
dd65f45e
DL
16859 /* Route reflector client. */
16860 if (peergroup_af_flag_check(peer, afi, safi,
16861 PEER_FLAG_REFLECTOR_CLIENT)) {
16862 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16863 }
16864
16865 /* next-hop-self force */
16866 if (peergroup_af_flag_check(peer, afi, safi,
16867 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16868 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16869 }
16870
16871 /* next-hop-self */
16872 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16873 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16874 }
16875
16876 /* remove-private-AS */
16877 if (peergroup_af_flag_check(peer, afi, safi,
16878 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16879 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16880 addr);
16881 }
16882
16883 else if (peergroup_af_flag_check(peer, afi, safi,
16884 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16885 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16886 addr);
16887 }
16888
16889 else if (peergroup_af_flag_check(peer, afi, safi,
16890 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16891 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16892 }
16893
16894 else if (peergroup_af_flag_check(peer, afi, safi,
16895 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16896 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16897 }
16898
16899 /* as-override */
16900 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16901 vty_out(vty, " neighbor %s as-override\n", addr);
16902 }
16903
16904 /* send-community print. */
16905 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16906 PEER_FLAG_SEND_COMMUNITY);
16907 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16908 PEER_FLAG_SEND_EXT_COMMUNITY);
16909 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16910 PEER_FLAG_SEND_LARGE_COMMUNITY);
16911
16912 if (flag_scomm && flag_secomm && flag_slcomm) {
16913 vty_out(vty, " no neighbor %s send-community all\n", addr);
16914 } else {
16915 if (flag_scomm)
16916 vty_out(vty, " no neighbor %s send-community\n", addr);
16917 if (flag_secomm)
16918 vty_out(vty,
16919 " no neighbor %s send-community extended\n",
16920 addr);
16921
16922 if (flag_slcomm)
16923 vty_out(vty, " no neighbor %s send-community large\n",
16924 addr);
16925 }
16926
16927 /* Default information */
16928 if (peergroup_af_flag_check(peer, afi, safi,
16929 PEER_FLAG_DEFAULT_ORIGINATE)) {
16930 vty_out(vty, " neighbor %s default-originate", addr);
16931
16932 if (peer->default_rmap[afi][safi].name)
16933 vty_out(vty, " route-map %s",
16934 peer->default_rmap[afi][safi].name);
16935
16936 vty_out(vty, "\n");
16937 }
16938
16939 /* Soft reconfiguration inbound. */
16940 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16941 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16942 addr);
16943 }
16944
16945 /* maximum-prefix. */
16946 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16947 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16948 peer->pmax[afi][safi]);
16949
16950 if (peer->pmax_threshold[afi][safi]
16951 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16952 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16953 if (peer_af_flag_check(peer, afi, safi,
16954 PEER_FLAG_MAX_PREFIX_WARNING))
16955 vty_out(vty, " warning-only");
16956 if (peer->pmax_restart[afi][safi])
16957 vty_out(vty, " restart %u",
16958 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16959 if (peer_af_flag_check(peer, afi, safi,
16960 PEER_FLAG_MAX_PREFIX_FORCE))
16961 vty_out(vty, " force");
dd65f45e
DL
16962
16963 vty_out(vty, "\n");
16964 }
16965
fde246e8
DA
16966 /* maximum-prefix-out */
16967 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16968 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16969 addr, peer->pmax_out[afi][safi]);
16970
dd65f45e
DL
16971 /* Route server client. */
16972 if (peergroup_af_flag_check(peer, afi, safi,
16973 PEER_FLAG_RSERVER_CLIENT)) {
16974 vty_out(vty, " neighbor %s route-server-client\n", addr);
16975 }
16976
16977 /* Nexthop-local unchanged. */
16978 if (peergroup_af_flag_check(peer, afi, safi,
16979 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16980 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16981 }
16982
16983 /* allowas-in <1-10> */
16984 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16985 if (peer_af_flag_check(peer, afi, safi,
16986 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16987 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16988 } else if (peer->allowas_in[afi][safi] == 3) {
16989 vty_out(vty, " neighbor %s allowas-in\n", addr);
16990 } else {
16991 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16992 peer->allowas_in[afi][safi]);
16993 }
16994 }
16995
16996 /* weight */
16997 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16998 vty_out(vty, " neighbor %s weight %lu\n", addr,
16999 peer->weight[afi][safi]);
17000
17001 /* Filter. */
17002 bgp_config_write_filter(vty, peer, afi, safi);
17003
17004 /* atribute-unchanged. */
17005 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17006 || (safi != SAFI_EVPN
17007 && peer_af_flag_check(peer, afi, safi,
17008 PEER_FLAG_NEXTHOP_UNCHANGED))
17009 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17010
17011 if (!peer_group_active(peer)
17012 || peergroup_af_flag_check(peer, afi, safi,
17013 PEER_FLAG_AS_PATH_UNCHANGED)
17014 || peergroup_af_flag_check(peer, afi, safi,
17015 PEER_FLAG_NEXTHOP_UNCHANGED)
17016 || peergroup_af_flag_check(peer, afi, safi,
17017 PEER_FLAG_MED_UNCHANGED)) {
17018
17019 vty_out(vty,
17020 " neighbor %s attribute-unchanged%s%s%s\n",
17021 addr,
17022 peer_af_flag_check(peer, afi, safi,
17023 PEER_FLAG_AS_PATH_UNCHANGED)
17024 ? " as-path"
17025 : "",
17026 peer_af_flag_check(peer, afi, safi,
17027 PEER_FLAG_NEXTHOP_UNCHANGED)
17028 ? " next-hop"
17029 : "",
17030 peer_af_flag_check(peer, afi, safi,
17031 PEER_FLAG_MED_UNCHANGED)
17032 ? " med"
17033 : "");
17034 }
17035 }
17036}
17037
17038/* Address family based peer configuration display. */
17039static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17040 safi_t safi)
17041{
17042 struct peer *peer;
17043 struct peer_group *group;
17044 struct listnode *node, *nnode;
17045
17046
17047 vty_frame(vty, " !\n address-family ");
17048 if (afi == AFI_IP) {
17049 if (safi == SAFI_UNICAST)
17050 vty_frame(vty, "ipv4 unicast");
17051 else if (safi == SAFI_LABELED_UNICAST)
17052 vty_frame(vty, "ipv4 labeled-unicast");
17053 else if (safi == SAFI_MULTICAST)
17054 vty_frame(vty, "ipv4 multicast");
17055 else if (safi == SAFI_MPLS_VPN)
17056 vty_frame(vty, "ipv4 vpn");
17057 else if (safi == SAFI_ENCAP)
17058 vty_frame(vty, "ipv4 encap");
17059 else if (safi == SAFI_FLOWSPEC)
17060 vty_frame(vty, "ipv4 flowspec");
17061 } else if (afi == AFI_IP6) {
17062 if (safi == SAFI_UNICAST)
17063 vty_frame(vty, "ipv6 unicast");
17064 else if (safi == SAFI_LABELED_UNICAST)
17065 vty_frame(vty, "ipv6 labeled-unicast");
17066 else if (safi == SAFI_MULTICAST)
17067 vty_frame(vty, "ipv6 multicast");
17068 else if (safi == SAFI_MPLS_VPN)
17069 vty_frame(vty, "ipv6 vpn");
17070 else if (safi == SAFI_ENCAP)
17071 vty_frame(vty, "ipv6 encap");
17072 else if (safi == SAFI_FLOWSPEC)
17073 vty_frame(vty, "ipv6 flowspec");
17074 } else if (afi == AFI_L2VPN) {
17075 if (safi == SAFI_EVPN)
17076 vty_frame(vty, "l2vpn evpn");
17077 }
17078 vty_frame(vty, "\n");
17079
17080 bgp_config_write_distance(vty, bgp, afi, safi);
17081
17082 bgp_config_write_network(vty, bgp, afi, safi);
17083
17084 bgp_config_write_redistribute(vty, bgp, afi, safi);
17085
8a4e7fe6
DA
17086 /* BGP flag dampening. */
17087 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
0221327c
DS
17088 bgp_config_write_damp(vty, bgp, afi, safi);
17089 for (ALL_LIST_ELEMENTS_RO(bgp->group, node, group))
17090 if (peer_af_flag_check(group->conf, afi, safi,
17091 PEER_FLAG_CONFIG_DAMPENING))
17092 bgp_config_write_peer_damp(vty, group->conf, afi, safi);
17093 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer))
17094 if (peer_af_flag_check(peer, afi, safi,
17095 PEER_FLAG_CONFIG_DAMPENING))
17096 bgp_config_write_peer_damp(vty, peer, afi, safi);
8a4e7fe6 17097
dd65f45e
DL
17098 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17099 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17100
17101 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17102 /* Skip dynamic neighbors. */
17103 if (peer_dynamic_neighbor(peer))
17104 continue;
17105
17106 /* Do not display doppelganger peers */
17107 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17108 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17109 }
17110
17111 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17112 bgp_config_write_table_map(vty, bgp, afi, safi);
17113
17114 if (safi == SAFI_EVPN)
17115 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17116
17117 if (safi == SAFI_FLOWSPEC)
17118 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17119
17120 if (safi == SAFI_UNICAST) {
17121 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17122 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17123 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17124
17125 vty_out(vty, " export vpn\n");
17126 }
17127 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17128 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17129
17130 vty_out(vty, " import vpn\n");
17131 }
17132 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17133 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17134 char *name;
17135
17136 for (ALL_LIST_ELEMENTS_RO(
17137 bgp->vpn_policy[afi].import_vrf, node,
17138 name))
17139 vty_out(vty, " import vrf %s\n", name);
17140 }
17141 }
17142
17143 vty_endframe(vty, " exit-address-family\n");
17144}
17145
17146int bgp_config_write(struct vty *vty)
17147{
17148 struct bgp *bgp;
17149 struct peer_group *group;
17150 struct peer *peer;
17151 struct listnode *node, *nnode;
17152 struct listnode *mnode, *mnnode;
17153
17154 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17155 vty_out(vty, "bgp route-map delay-timer %u\n",
17156 bm->rmap_update_timer);
17157
d70583f7
D
17158 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17159 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17160 if (bm->v_update_delay != bm->v_establish_wait)
17161 vty_out(vty, " %d", bm->v_establish_wait);
17162 vty_out(vty, "\n");
17163 }
17164
9acb67cb
DS
17165 if (bm->wait_for_fib)
17166 vty_out(vty, "bgp suppress-fib-pending\n");
17167
05bd726c 17168 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17169 vty_out(vty, "bgp graceful-shutdown\n");
17170
c163f297
DS
17171 /* No-RIB (Zebra) option flag configuration */
17172 if (bgp_option_check(BGP_OPT_NO_FIB))
17173 vty_out(vty, "bgp no-rib\n");
17174
ec0acb80 17175 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
17176 vty_out(vty, "no bgp send-extra-data zebra\n");
17177
dd65f45e
DL
17178 /* BGP configuration. */
17179 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17180
17181 /* skip all auto created vrf as they dont have user config */
17182 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17183 continue;
17184
17185 /* Router bgp ASN */
17186 vty_out(vty, "router bgp %u", bgp->as);
17187
17188 if (bgp->name)
17189 vty_out(vty, " %s %s",
17190 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17191 ? "view" : "vrf", bgp->name);
17192 vty_out(vty, "\n");
17193
17194 /* BGP fast-external-failover. */
17195 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17196 vty_out(vty, " no bgp fast-external-failover\n");
17197
17198 /* BGP router ID. */
3a6290bd 17199 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17200 vty_out(vty, " bgp router-id %pI4\n",
17201 &bgp->router_id_static);
dd65f45e 17202
c208c586
S
17203 /* Suppress fib pending */
17204 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17205 vty_out(vty, " bgp suppress-fib-pending\n");
17206
dd65f45e 17207 /* BGP log-neighbor-changes. */
892fedb6 17208 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17209 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17210 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17211 CHECK_FLAG(bgp->flags,
17212 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17213 ? ""
17214 : "no ");
17215
17216 /* BGP configuration. */
892fedb6 17217 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17218 vty_out(vty, " bgp always-compare-med\n");
17219
17220 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17221 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17222 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17223 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17224 CHECK_FLAG(bgp->flags,
17225 BGP_FLAG_EBGP_REQUIRES_POLICY)
17226 ? ""
17227 : "no ");
dd65f45e
DL
17228
17229 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17230 if (bgp->reject_as_sets)
dd65f45e
DL
17231 vty_out(vty, " bgp reject-as-sets\n");
17232
2adac256
DA
17233 /* Suppress duplicate updates if the route actually not changed
17234 */
17235 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17236 != SAVE_BGP_SUPPRESS_DUPLICATES)
17237 vty_out(vty, " %sbgp suppress-duplicates\n",
17238 CHECK_FLAG(bgp->flags,
17239 BGP_FLAG_SUPPRESS_DUPLICATES)
17240 ? ""
17241 : "no ");
17242
dd65f45e 17243 /* BGP default ipv4-unicast. */
892fedb6 17244 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
17245 vty_out(vty, " no bgp default ipv4-unicast\n");
17246
17247 /* BGP default local-preference. */
17248 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17249 vty_out(vty, " bgp default local-preference %u\n",
17250 bgp->default_local_pref);
17251
17252 /* BGP default show-hostname */
892fedb6 17253 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17254 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17255 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17256 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17257 ? ""
17258 : "no ");
17259
aef999a2
DA
17260 /* BGP default show-nexthop-hostname */
17261 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17262 != SAVE_BGP_SHOW_HOSTNAME)
17263 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17264 CHECK_FLAG(bgp->flags,
17265 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17266 ? ""
17267 : "no ");
17268
dd65f45e
DL
17269 /* BGP default subgroup-pkt-queue-max. */
17270 if (bgp->default_subgroup_pkt_queue_max
17271 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17272 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17273 bgp->default_subgroup_pkt_queue_max);
17274
17275 /* BGP client-to-client reflection. */
892fedb6 17276 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17277 vty_out(vty, " no bgp client-to-client reflection\n");
17278
17279 /* BGP cluster ID. */
17280 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17281 vty_out(vty, " bgp cluster-id %pI4\n",
17282 &bgp->cluster_id);
dd65f45e
DL
17283
17284 /* Disable ebgp connected nexthop check */
892fedb6 17285 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17286 vty_out(vty,
17287 " bgp disable-ebgp-connected-route-check\n");
17288
17289 /* Confederation identifier*/
17290 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17291 vty_out(vty, " bgp confederation identifier %u\n",
17292 bgp->confed_id);
17293
17294 /* Confederation peer */
17295 if (bgp->confed_peers_cnt > 0) {
17296 int i;
17297
17298 vty_out(vty, " bgp confederation peers");
17299
17300 for (i = 0; i < bgp->confed_peers_cnt; i++)
17301 vty_out(vty, " %u", bgp->confed_peers[i]);
17302
17303 vty_out(vty, "\n");
17304 }
17305
17306 /* BGP deterministic-med. */
892fedb6 17307 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17308 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17309 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17310 CHECK_FLAG(bgp->flags,
17311 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17312 ? ""
17313 : "no ");
17314
17315 /* BGP update-delay. */
17316 bgp_config_write_update_delay(vty, bgp);
17317
17318 if (bgp->v_maxmed_onstartup
17319 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17320 vty_out(vty, " bgp max-med on-startup %u",
17321 bgp->v_maxmed_onstartup);
17322 if (bgp->maxmed_onstartup_value
17323 != BGP_MAXMED_VALUE_DEFAULT)
17324 vty_out(vty, " %u",
17325 bgp->maxmed_onstartup_value);
17326 vty_out(vty, "\n");
17327 }
17328 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17329 vty_out(vty, " bgp max-med administrative");
17330 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17331 vty_out(vty, " %u", bgp->maxmed_admin_value);
17332 vty_out(vty, "\n");
17333 }
17334
17335 /* write quanta */
17336 bgp_config_write_wpkt_quanta(vty, bgp);
17337 /* read quanta */
17338 bgp_config_write_rpkt_quanta(vty, bgp);
17339
17340 /* coalesce time */
17341 bgp_config_write_coalesce_time(vty, bgp);
17342
05bd726c 17343 /* BGP per-instance graceful-shutdown */
17344 /* BGP-wide settings and per-instance settings are mutually
17345 * exclusive.
17346 */
17347 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17348 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17349 vty_out(vty, " bgp graceful-shutdown\n");
17350
dd65f45e
DL
17351 /* BGP graceful-restart. */
17352 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17353 vty_out(vty,
17354 " bgp graceful-restart stalepath-time %u\n",
17355 bgp->stalepath_time);
cfd47646 17356
dd65f45e
DL
17357 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17358 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17359 bgp->restart_time);
cfd47646 17360
17361 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17362 vty_out(vty,
17363 " bgp graceful-restart select-defer-time %u\n",
17364 bgp->select_defer_time);
17365
17366 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17367 vty_out(vty, " bgp graceful-restart\n");
17368
cfd47646 17369 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17370 vty_out(vty, " bgp graceful-restart-disable\n");
17371
dd65f45e 17372 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17373 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17374 vty_out(vty,
17375 " bgp graceful-restart preserve-fw-state\n");
17376
dc95985f 17377 /* Stale timer for RIB */
17378 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17379 vty_out(vty,
17380 " bgp graceful-restart rib-stale-time %u\n",
17381 bgp->rib_stale_time);
17382
dd65f45e 17383 /* BGP bestpath method. */
892fedb6 17384 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17385 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17386 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17387 vty_out(vty, " bgp bestpath as-path confed\n");
17388
892fedb6
DA
17389 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17390 if (CHECK_FLAG(bgp->flags,
17391 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17392 vty_out(vty,
17393 " bgp bestpath as-path multipath-relax as-set\n");
17394 } else {
17395 vty_out(vty,
17396 " bgp bestpath as-path multipath-relax\n");
17397 }
17398 }
17399
892fedb6 17400 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17401 vty_out(vty,
17402 " bgp route-reflector allow-outbound-policy\n");
17403 }
892fedb6 17404 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17405 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17406 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17407 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17408 vty_out(vty, " bgp bestpath med");
892fedb6 17409 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17410 vty_out(vty, " confed");
892fedb6
DA
17411 if (CHECK_FLAG(bgp->flags,
17412 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17413 vty_out(vty, " missing-as-worst");
17414 vty_out(vty, "\n");
17415 }
17416
f7e1c681 17417 /* Link bandwidth handling. */
17418 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17419 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17420 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17421 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17422 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17423 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17424
dd65f45e 17425 /* BGP network import check. */
892fedb6 17426 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17427 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17428 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17429 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17430 ? ""
17431 : "no ");
17432
17433 /* BGP timers configuration. */
5d5393b9
DL
17434 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17435 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17436 vty_out(vty, " timers bgp %u %u\n",
17437 bgp->default_keepalive, bgp->default_holdtime);
17438
17439 /* peer-group */
17440 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17441 bgp_config_write_peer_global(vty, bgp, group->conf);
17442 }
17443
17444 /* Normal neighbor configuration. */
17445 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17446 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17447 bgp_config_write_peer_global(vty, bgp, peer);
17448 }
17449
17450 /* listen range and limit for dynamic BGP neighbors */
17451 bgp_config_write_listen(vty, bgp);
17452
17453 /*
17454 * BGP default autoshutdown neighbors
17455 *
17456 * This must be placed after any peer and peer-group
17457 * configuration, to avoid setting all peers to shutdown after
17458 * a daemon restart, which is undesired behavior. (see #2286)
17459 */
17460 if (bgp->autoshutdown)
17461 vty_out(vty, " bgp default shutdown\n");
17462
9cf59432
DS
17463 /* BGP instance administrative shutdown */
17464 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17465 vty_out(vty, " bgp shutdown\n");
17466
dd65f45e
DL
17467 /* IPv4 unicast configuration. */
17468 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17469
17470 /* IPv4 multicast configuration. */
17471 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17472
17473 /* IPv4 labeled-unicast configuration. */
17474 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17475
17476 /* IPv4 VPN configuration. */
17477 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17478
17479 /* ENCAPv4 configuration. */
17480 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17481
17482 /* FLOWSPEC v4 configuration. */
17483 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17484
17485 /* IPv6 unicast configuration. */
17486 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17487
17488 /* IPv6 multicast configuration. */
17489 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17490
17491 /* IPv6 labeled-unicast configuration. */
17492 bgp_config_write_family(vty, bgp, AFI_IP6,
17493 SAFI_LABELED_UNICAST);
17494
17495 /* IPv6 VPN configuration. */
17496 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17497
17498 /* ENCAPv6 configuration. */
17499 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17500
17501 /* FLOWSPEC v6 configuration. */
17502 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17503
17504 /* EVPN configuration. */
17505 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17506
17507 hook_call(bgp_inst_config_write, bgp, vty);
17508
49e5a4a0 17509#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17510 bgp_rfapi_cfg_write(vty, bgp);
17511#endif
17512
17513 vty_out(vty, "!\n");
17514 }
17515 return 0;
17516}
17517
ddb5b488 17518
718e3744 17519/* BGP node structure. */
d62a17ae 17520static struct cmd_node bgp_node = {
f4b8291f 17521 .name = "bgp",
62b346ee 17522 .node = BGP_NODE,
24389580 17523 .parent_node = CONFIG_NODE,
62b346ee 17524 .prompt = "%s(config-router)# ",
612c2c15 17525 .config_write = bgp_config_write,
718e3744 17526};
17527
d62a17ae 17528static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17529 .name = "bgp ipv4 unicast",
62b346ee 17530 .node = BGP_IPV4_NODE,
24389580 17531 .parent_node = BGP_NODE,
62b346ee 17532 .prompt = "%s(config-router-af)# ",
718e3744 17533};
17534
d62a17ae 17535static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17536 .name = "bgp ipv4 multicast",
62b346ee 17537 .node = BGP_IPV4M_NODE,
24389580 17538 .parent_node = BGP_NODE,
62b346ee 17539 .prompt = "%s(config-router-af)# ",
718e3744 17540};
17541
d62a17ae 17542static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17543 .name = "bgp ipv4 labeled unicast",
62b346ee 17544 .node = BGP_IPV4L_NODE,
24389580 17545 .parent_node = BGP_NODE,
62b346ee 17546 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17547};
17548
d62a17ae 17549static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 17550 .name = "bgp ipv6",
62b346ee 17551 .node = BGP_IPV6_NODE,
24389580 17552 .parent_node = BGP_NODE,
62b346ee 17553 .prompt = "%s(config-router-af)# ",
718e3744 17554};
17555
d62a17ae 17556static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17557 .name = "bgp ipv6 multicast",
62b346ee 17558 .node = BGP_IPV6M_NODE,
24389580 17559 .parent_node = BGP_NODE,
62b346ee 17560 .prompt = "%s(config-router-af)# ",
25ffbdc1 17561};
17562
d62a17ae 17563static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17564 .name = "bgp ipv6 labeled unicast",
62b346ee 17565 .node = BGP_IPV6L_NODE,
24389580 17566 .parent_node = BGP_NODE,
62b346ee 17567 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17568};
17569
62b346ee 17570static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17571 .name = "bgp vpnv4",
62b346ee 17572 .node = BGP_VPNV4_NODE,
24389580 17573 .parent_node = BGP_NODE,
62b346ee 17574 .prompt = "%s(config-router-af)# ",
62b346ee 17575};
6b0655a2 17576
62b346ee 17577static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17578 .name = "bgp vpnv6",
62b346ee 17579 .node = BGP_VPNV6_NODE,
24389580 17580 .parent_node = BGP_NODE,
62b346ee 17581 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17582};
8ecd3266 17583
62b346ee 17584static struct cmd_node bgp_evpn_node = {
f4b8291f 17585 .name = "bgp evpn",
62b346ee 17586 .node = BGP_EVPN_NODE,
24389580 17587 .parent_node = BGP_NODE,
62b346ee 17588 .prompt = "%s(config-router-evpn)# ",
62b346ee 17589};
4e0b7b6d 17590
62b346ee 17591static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17592 .name = "bgp evpn vni",
62b346ee 17593 .node = BGP_EVPN_VNI_NODE,
24389580 17594 .parent_node = BGP_EVPN_NODE,
62b346ee 17595 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17596};
90e60aa7 17597
62b346ee 17598static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17599 .name = "bgp ipv4 flowspec",
62b346ee 17600 .node = BGP_FLOWSPECV4_NODE,
24389580 17601 .parent_node = BGP_NODE,
62b346ee 17602 .prompt = "%s(config-router-af)# ",
62b346ee 17603};
7c40bf39 17604
62b346ee 17605static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17606 .name = "bgp ipv6 flowspec",
62b346ee 17607 .node = BGP_FLOWSPECV6_NODE,
24389580 17608 .parent_node = BGP_NODE,
62b346ee 17609 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17610};
7c40bf39 17611
d62a17ae 17612static void community_list_vty(void);
1f8ae70b 17613
d62a17ae 17614static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 17615{
d62a17ae 17616 struct bgp *bgp;
17617 struct peer *peer;
d62a17ae 17618 struct listnode *lnbgp, *lnpeer;
b8a815e5 17619
d62a17ae 17620 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17621 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17622 /* only provide suggestions on the appropriate input
17623 * token type,
17624 * they'll otherwise show up multiple times */
17625 enum cmd_token_type match_type;
17626 char *name = peer->host;
d48ed3e0 17627
d62a17ae 17628 if (peer->conf_if) {
17629 match_type = VARIABLE_TKN;
17630 name = peer->conf_if;
17631 } else if (strchr(peer->host, ':'))
17632 match_type = IPV6_TKN;
17633 else
17634 match_type = IPV4_TKN;
d48ed3e0 17635
d62a17ae 17636 if (token->type != match_type)
17637 continue;
d48ed3e0 17638
d62a17ae 17639 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17640 }
d62a17ae 17641 }
b8a815e5
DL
17642}
17643
17644static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17645 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17646 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17647 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17648 {.completions = NULL}};
17649
47a306a0
DS
17650static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17651{
17652 struct bgp *bgp;
17653 struct peer_group *group;
17654 struct listnode *lnbgp, *lnpeer;
17655
17656 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17657 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17658 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17659 group->name));
17660 }
17661}
17662
17663static const struct cmd_variable_handler bgp_var_peergroup[] = {
17664 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17665 {.completions = NULL} };
17666
d62a17ae 17667void bgp_vty_init(void)
17668{
17669 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17670 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17671
17672 /* Install bgp top node. */
612c2c15
DL
17673 install_node(&bgp_node);
17674 install_node(&bgp_ipv4_unicast_node);
17675 install_node(&bgp_ipv4_multicast_node);
17676 install_node(&bgp_ipv4_labeled_unicast_node);
17677 install_node(&bgp_ipv6_unicast_node);
17678 install_node(&bgp_ipv6_multicast_node);
17679 install_node(&bgp_ipv6_labeled_unicast_node);
17680 install_node(&bgp_vpnv4_node);
17681 install_node(&bgp_vpnv6_node);
17682 install_node(&bgp_evpn_node);
17683 install_node(&bgp_evpn_vni_node);
17684 install_node(&bgp_flowspecv4_node);
17685 install_node(&bgp_flowspecv6_node);
d62a17ae 17686
17687 /* Install default VTY commands to new nodes. */
17688 install_default(BGP_NODE);
17689 install_default(BGP_IPV4_NODE);
17690 install_default(BGP_IPV4M_NODE);
17691 install_default(BGP_IPV4L_NODE);
17692 install_default(BGP_IPV6_NODE);
17693 install_default(BGP_IPV6M_NODE);
17694 install_default(BGP_IPV6L_NODE);
17695 install_default(BGP_VPNV4_NODE);
17696 install_default(BGP_VPNV6_NODE);
7c40bf39 17697 install_default(BGP_FLOWSPECV4_NODE);
17698 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17699 install_default(BGP_EVPN_NODE);
17700 install_default(BGP_EVPN_VNI_NODE);
17701
8029b216
AK
17702 /* "bgp local-mac" hidden commands. */
17703 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17704 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17705
9acb67cb
DS
17706 /* "bgp suppress-fib-pending" global */
17707 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17708
d62a17ae 17709 /* bgp route-map delay-timer commands. */
17710 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17711 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17712
d70583f7
D
17713 /* global bgp update-delay command */
17714 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17715 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17716
05bd726c 17717 /* global bgp graceful-shutdown command */
17718 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17719 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17720
d62a17ae 17721 /* Dummy commands (Currently not supported) */
17722 install_element(BGP_NODE, &no_synchronization_cmd);
17723 install_element(BGP_NODE, &no_auto_summary_cmd);
17724
17725 /* "router bgp" commands. */
17726 install_element(CONFIG_NODE, &router_bgp_cmd);
17727
17728 /* "no router bgp" commands. */
17729 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17730
17731 /* "bgp router-id" commands. */
17732 install_element(BGP_NODE, &bgp_router_id_cmd);
17733 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17734
c208c586
S
17735 /* "bgp suppress-fib-pending" command */
17736 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17737
d62a17ae 17738 /* "bgp cluster-id" commands. */
17739 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17740 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17741
c163f297
DS
17742 /* "bgp no-rib" commands. */
17743 install_element(CONFIG_NODE, &bgp_norib_cmd);
17744 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17745
e46723a5
DS
17746 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17747
d62a17ae 17748 /* "bgp confederation" commands. */
17749 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17750 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17751
17752 /* "bgp confederation peers" commands. */
17753 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17754 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17755
17756 /* bgp max-med command */
17757 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17758 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17759 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17760 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17761 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17762
17763 /* bgp disable-ebgp-connected-nh-check */
17764 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17765 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17766
17767 /* bgp update-delay command */
17768 install_element(BGP_NODE, &bgp_update_delay_cmd);
17769 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17770
17771 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17772 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17773
17774 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17775 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17776
17777 /* "maximum-paths" commands. */
17778 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17779 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17780 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17781 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17782 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17783 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17784 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17785 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17786 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17787 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17788 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17789 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17790 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17791 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17792 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17793
39edabac
PG
17794 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17795 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17796 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17797 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17798 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17799 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17800 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17801 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17802 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17803 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17804
17805 /* "timers bgp" commands. */
17806 install_element(BGP_NODE, &bgp_timers_cmd);
17807 install_element(BGP_NODE, &no_bgp_timers_cmd);
17808
17809 /* route-map delay-timer commands - per instance for backwards compat.
17810 */
17811 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17812 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17813
17814 /* "bgp client-to-client reflection" commands */
17815 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17816 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17817
17818 /* "bgp always-compare-med" commands */
17819 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17820 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17821
9dac9fc8
DA
17822 /* bgp ebgp-requires-policy */
17823 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17824 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17825
2adac256
DA
17826 /* bgp suppress-duplicates */
17827 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17828 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17829
fb29348a
DA
17830 /* bgp reject-as-sets */
17831 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17832 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17833
d62a17ae 17834 /* "bgp deterministic-med" commands */
17835 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17836 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17837
055679e9 17838 /* "bgp graceful-restart" command */
36235319
QY
17839 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17840 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17841
17842 /* "bgp graceful-restart-disable" command */
36235319
QY
17843 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17844 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17845
17846 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17847 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17848 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17849
17850 /* "neighbor a:b:c:d graceful-restart-disable" command */
17851 install_element(BGP_NODE,
17852 &bgp_neighbor_graceful_restart_disable_set_cmd);
17853 install_element(BGP_NODE,
17854 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17855
17856 /* "neighbor a:b:c:d graceful-restart-helper" command */
17857 install_element(BGP_NODE,
17858 &bgp_neighbor_graceful_restart_helper_set_cmd);
17859 install_element(BGP_NODE,
17860 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17861
d62a17ae 17862 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17863 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17864 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17865 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17866 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17867 install_element(BGP_NODE,
17868 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17869 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17870 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17871
d6e3c15b 17872 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17873 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17874 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17875 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17876
7f323236
DW
17877 /* "bgp graceful-shutdown" commands */
17878 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17879 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17880
d62a17ae 17881 /* "bgp fast-external-failover" commands */
17882 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17883 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17884
d62a17ae 17885 /* "bgp bestpath compare-routerid" commands */
17886 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17887 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17888
17889 /* "bgp bestpath as-path ignore" commands */
17890 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17891 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17892
17893 /* "bgp bestpath as-path confed" commands */
17894 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17895 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17896
17897 /* "bgp bestpath as-path multipath-relax" commands */
17898 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17899 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17900
17901 /* "bgp log-neighbor-changes" commands */
17902 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17903 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17904
17905 /* "bgp bestpath med" commands */
17906 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17907 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17908
f7e1c681 17909 /* "bgp bestpath bandwidth" commands */
17910 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17911 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17912
d62a17ae 17913 /* "no bgp default ipv4-unicast" commands. */
17914 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17915 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17916
17917 /* "bgp network import-check" commands. */
17918 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17919 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17920 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17921
17922 /* "bgp default local-preference" commands. */
17923 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17924 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17925
17926 /* bgp default show-hostname */
17927 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17928 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17929
aef999a2
DA
17930 /* bgp default show-nexthop-hostname */
17931 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17932 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17933
d62a17ae 17934 /* "bgp default subgroup-pkt-queue-max" commands. */
17935 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17936 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17937
17938 /* bgp ibgp-allow-policy-mods command */
17939 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17940 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17941
17942 /* "bgp listen limit" commands. */
17943 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17944 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17945
17946 /* "bgp listen range" commands. */
17947 install_element(BGP_NODE, &bgp_listen_range_cmd);
17948 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17949
8175f54a 17950 /* "bgp default shutdown" command */
f26845f9 17951 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17952
17953 /* "bgp shutdown" commands */
17954 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17955 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17956 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17957 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17958
d62a17ae 17959 /* "neighbor remote-as" commands. */
17960 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17961 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17962 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17963 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17964 install_element(BGP_NODE,
17965 &neighbor_interface_v6only_config_remote_as_cmd);
17966 install_element(BGP_NODE, &no_neighbor_cmd);
17967 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17968
17969 /* "neighbor peer-group" commands. */
17970 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17971 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17972 install_element(BGP_NODE,
17973 &no_neighbor_interface_peer_group_remote_as_cmd);
17974
17975 /* "neighbor local-as" commands. */
17976 install_element(BGP_NODE, &neighbor_local_as_cmd);
17977 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17978 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17979 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17980
17981 /* "neighbor solo" commands. */
17982 install_element(BGP_NODE, &neighbor_solo_cmd);
17983 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17984
17985 /* "neighbor password" commands. */
17986 install_element(BGP_NODE, &neighbor_password_cmd);
17987 install_element(BGP_NODE, &no_neighbor_password_cmd);
17988
17989 /* "neighbor activate" commands. */
17990 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17991 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17992 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17993 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17994 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17995 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17996 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17997 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17998 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17999 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18000 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18001 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18002
18003 /* "no neighbor activate" commands. */
18004 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18005 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18006 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18007 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18008 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18009 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18010 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18011 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18012 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18013 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18014 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18015 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18016
18017 /* "neighbor peer-group" set commands. */
18018 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18019 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18020 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18021 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18022 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18023 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18024 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18025 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18026 install_element(BGP_FLOWSPECV4_NODE,
18027 &neighbor_set_peer_group_hidden_cmd);
18028 install_element(BGP_FLOWSPECV6_NODE,
18029 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18030
18031 /* "no neighbor peer-group unset" commands. */
18032 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18033 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18034 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18035 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18036 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18037 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18038 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18039 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18040 install_element(BGP_FLOWSPECV4_NODE,
18041 &no_neighbor_set_peer_group_hidden_cmd);
18042 install_element(BGP_FLOWSPECV6_NODE,
18043 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18044
18045 /* "neighbor softreconfiguration inbound" commands.*/
18046 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18047 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18048 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18049 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18050 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18051 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18052 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18053 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18054 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18055 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18056 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18057 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18058 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18059 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18060 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18061 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18062 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18063 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18064 install_element(BGP_FLOWSPECV4_NODE,
18065 &neighbor_soft_reconfiguration_cmd);
18066 install_element(BGP_FLOWSPECV4_NODE,
18067 &no_neighbor_soft_reconfiguration_cmd);
18068 install_element(BGP_FLOWSPECV6_NODE,
18069 &neighbor_soft_reconfiguration_cmd);
18070 install_element(BGP_FLOWSPECV6_NODE,
18071 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18072 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18073 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18074
18075 /* "neighbor attribute-unchanged" commands. */
18076 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18077 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18078 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18079 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18080 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18081 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18082 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18083 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18084 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18085 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18086 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18087 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18088 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18089 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18090 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18091 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18092 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18093 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18094
18095 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18096 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18097
b8ad84d2
PG
18098 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18099 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18100 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18101 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18102
d62a17ae 18103 /* "nexthop-local unchanged" commands */
18104 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18105 install_element(BGP_IPV6_NODE,
18106 &no_neighbor_nexthop_local_unchanged_cmd);
18107
18108 /* "neighbor next-hop-self" commands. */
18109 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18110 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18111 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18112 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18113 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18114 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18115 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18116 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18117 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18118 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18119 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18120 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18121 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18122 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18123 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18124 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18125 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18126 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18127 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18128 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18129
18130 /* "neighbor next-hop-self force" commands. */
18131 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18132 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18133 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18134 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18135 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18136 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18137 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18138 install_element(BGP_IPV4_NODE,
18139 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18140 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18141 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18142 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18143 install_element(BGP_IPV4M_NODE,
18144 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18145 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18146 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18147 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18148 install_element(BGP_IPV4L_NODE,
18149 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18150 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18151 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18152 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18153 install_element(BGP_IPV6_NODE,
18154 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18155 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18156 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18157 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18158 install_element(BGP_IPV6M_NODE,
18159 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18160 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18161 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18162 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18163 install_element(BGP_IPV6L_NODE,
18164 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18165 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18166 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18167 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18168 install_element(BGP_VPNV4_NODE,
18169 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18170 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18171 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18172 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18173 install_element(BGP_VPNV6_NODE,
18174 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18175 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18176 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18177
18178 /* "neighbor as-override" commands. */
18179 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18180 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18181 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18182 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18183 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18184 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18185 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18186 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18187 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18188 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18189 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18190 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18191 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18192 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18193 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18194 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18195 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18196 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18197
18198 /* "neighbor remove-private-AS" commands. */
18199 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18200 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18201 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18202 install_element(BGP_NODE,
18203 &no_neighbor_remove_private_as_all_hidden_cmd);
18204 install_element(BGP_NODE,
18205 &neighbor_remove_private_as_replace_as_hidden_cmd);
18206 install_element(BGP_NODE,
18207 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18208 install_element(BGP_NODE,
18209 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18210 install_element(
18211 BGP_NODE,
18212 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18213 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18214 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18215 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18216 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18217 install_element(BGP_IPV4_NODE,
18218 &neighbor_remove_private_as_replace_as_cmd);
18219 install_element(BGP_IPV4_NODE,
18220 &no_neighbor_remove_private_as_replace_as_cmd);
18221 install_element(BGP_IPV4_NODE,
18222 &neighbor_remove_private_as_all_replace_as_cmd);
18223 install_element(BGP_IPV4_NODE,
18224 &no_neighbor_remove_private_as_all_replace_as_cmd);
18225 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18226 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18227 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18228 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18229 install_element(BGP_IPV4M_NODE,
18230 &neighbor_remove_private_as_replace_as_cmd);
18231 install_element(BGP_IPV4M_NODE,
18232 &no_neighbor_remove_private_as_replace_as_cmd);
18233 install_element(BGP_IPV4M_NODE,
18234 &neighbor_remove_private_as_all_replace_as_cmd);
18235 install_element(BGP_IPV4M_NODE,
18236 &no_neighbor_remove_private_as_all_replace_as_cmd);
18237 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18238 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18239 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18240 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18241 install_element(BGP_IPV4L_NODE,
18242 &neighbor_remove_private_as_replace_as_cmd);
18243 install_element(BGP_IPV4L_NODE,
18244 &no_neighbor_remove_private_as_replace_as_cmd);
18245 install_element(BGP_IPV4L_NODE,
18246 &neighbor_remove_private_as_all_replace_as_cmd);
18247 install_element(BGP_IPV4L_NODE,
18248 &no_neighbor_remove_private_as_all_replace_as_cmd);
18249 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18250 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18251 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18252 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18253 install_element(BGP_IPV6_NODE,
18254 &neighbor_remove_private_as_replace_as_cmd);
18255 install_element(BGP_IPV6_NODE,
18256 &no_neighbor_remove_private_as_replace_as_cmd);
18257 install_element(BGP_IPV6_NODE,
18258 &neighbor_remove_private_as_all_replace_as_cmd);
18259 install_element(BGP_IPV6_NODE,
18260 &no_neighbor_remove_private_as_all_replace_as_cmd);
18261 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18262 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18263 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18264 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18265 install_element(BGP_IPV6M_NODE,
18266 &neighbor_remove_private_as_replace_as_cmd);
18267 install_element(BGP_IPV6M_NODE,
18268 &no_neighbor_remove_private_as_replace_as_cmd);
18269 install_element(BGP_IPV6M_NODE,
18270 &neighbor_remove_private_as_all_replace_as_cmd);
18271 install_element(BGP_IPV6M_NODE,
18272 &no_neighbor_remove_private_as_all_replace_as_cmd);
18273 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18274 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18275 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18276 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18277 install_element(BGP_IPV6L_NODE,
18278 &neighbor_remove_private_as_replace_as_cmd);
18279 install_element(BGP_IPV6L_NODE,
18280 &no_neighbor_remove_private_as_replace_as_cmd);
18281 install_element(BGP_IPV6L_NODE,
18282 &neighbor_remove_private_as_all_replace_as_cmd);
18283 install_element(BGP_IPV6L_NODE,
18284 &no_neighbor_remove_private_as_all_replace_as_cmd);
18285 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18286 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18287 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18288 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18289 install_element(BGP_VPNV4_NODE,
18290 &neighbor_remove_private_as_replace_as_cmd);
18291 install_element(BGP_VPNV4_NODE,
18292 &no_neighbor_remove_private_as_replace_as_cmd);
18293 install_element(BGP_VPNV4_NODE,
18294 &neighbor_remove_private_as_all_replace_as_cmd);
18295 install_element(BGP_VPNV4_NODE,
18296 &no_neighbor_remove_private_as_all_replace_as_cmd);
18297 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18298 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18299 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18300 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18301 install_element(BGP_VPNV6_NODE,
18302 &neighbor_remove_private_as_replace_as_cmd);
18303 install_element(BGP_VPNV6_NODE,
18304 &no_neighbor_remove_private_as_replace_as_cmd);
18305 install_element(BGP_VPNV6_NODE,
18306 &neighbor_remove_private_as_all_replace_as_cmd);
18307 install_element(BGP_VPNV6_NODE,
18308 &no_neighbor_remove_private_as_all_replace_as_cmd);
18309
18310 /* "neighbor send-community" commands.*/
18311 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18312 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18313 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18314 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18315 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18316 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18317 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18318 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18319 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18320 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18321 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18322 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18323 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18324 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18325 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18326 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18327 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18328 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18329 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18330 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18331 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18332 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18333 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18334 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18335 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18336 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18337 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18338 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18339 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18340 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18341 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18342 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18343 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18344 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18345 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18346 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18347
18348 /* "neighbor route-reflector" commands.*/
18349 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18350 install_element(BGP_NODE,
18351 &no_neighbor_route_reflector_client_hidden_cmd);
18352 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18353 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18354 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18355 install_element(BGP_IPV4M_NODE,
18356 &no_neighbor_route_reflector_client_cmd);
18357 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18358 install_element(BGP_IPV4L_NODE,
18359 &no_neighbor_route_reflector_client_cmd);
18360 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18361 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18362 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18363 install_element(BGP_IPV6M_NODE,
18364 &no_neighbor_route_reflector_client_cmd);
18365 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18366 install_element(BGP_IPV6L_NODE,
18367 &no_neighbor_route_reflector_client_cmd);
18368 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18369 install_element(BGP_VPNV4_NODE,
18370 &no_neighbor_route_reflector_client_cmd);
18371 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18372 install_element(BGP_VPNV6_NODE,
18373 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18374 install_element(BGP_FLOWSPECV4_NODE,
18375 &neighbor_route_reflector_client_cmd);
18376 install_element(BGP_FLOWSPECV4_NODE,
18377 &no_neighbor_route_reflector_client_cmd);
18378 install_element(BGP_FLOWSPECV6_NODE,
18379 &neighbor_route_reflector_client_cmd);
18380 install_element(BGP_FLOWSPECV6_NODE,
18381 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18382 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18383 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18384
18385 /* "neighbor route-server" commands.*/
18386 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18387 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18388 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18389 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18390 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18391 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18392 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18393 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18394 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18395 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18396 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18397 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18398 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18399 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18400 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18401 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18402 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18403 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18404 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18405 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18406 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18407 install_element(BGP_FLOWSPECV4_NODE,
18408 &no_neighbor_route_server_client_cmd);
18409 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18410 install_element(BGP_FLOWSPECV6_NODE,
18411 &no_neighbor_route_server_client_cmd);
d62a17ae 18412
18413 /* "neighbor addpath-tx-all-paths" commands.*/
18414 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18415 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18416 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18417 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18418 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18419 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18420 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18421 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18422 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18423 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18424 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18425 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18426 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18427 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18428 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18429 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18430 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18431 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18432
18433 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18434 install_element(BGP_NODE,
18435 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18436 install_element(BGP_NODE,
18437 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18438 install_element(BGP_IPV4_NODE,
18439 &neighbor_addpath_tx_bestpath_per_as_cmd);
18440 install_element(BGP_IPV4_NODE,
18441 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18442 install_element(BGP_IPV4M_NODE,
18443 &neighbor_addpath_tx_bestpath_per_as_cmd);
18444 install_element(BGP_IPV4M_NODE,
18445 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18446 install_element(BGP_IPV4L_NODE,
18447 &neighbor_addpath_tx_bestpath_per_as_cmd);
18448 install_element(BGP_IPV4L_NODE,
18449 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18450 install_element(BGP_IPV6_NODE,
18451 &neighbor_addpath_tx_bestpath_per_as_cmd);
18452 install_element(BGP_IPV6_NODE,
18453 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18454 install_element(BGP_IPV6M_NODE,
18455 &neighbor_addpath_tx_bestpath_per_as_cmd);
18456 install_element(BGP_IPV6M_NODE,
18457 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18458 install_element(BGP_IPV6L_NODE,
18459 &neighbor_addpath_tx_bestpath_per_as_cmd);
18460 install_element(BGP_IPV6L_NODE,
18461 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18462 install_element(BGP_VPNV4_NODE,
18463 &neighbor_addpath_tx_bestpath_per_as_cmd);
18464 install_element(BGP_VPNV4_NODE,
18465 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18466 install_element(BGP_VPNV6_NODE,
18467 &neighbor_addpath_tx_bestpath_per_as_cmd);
18468 install_element(BGP_VPNV6_NODE,
18469 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18470
2b31007c
RZ
18471 /* "neighbor sender-as-path-loop-detection" commands. */
18472 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18473 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18474
d62a17ae 18475 /* "neighbor passive" commands. */
18476 install_element(BGP_NODE, &neighbor_passive_cmd);
18477 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18478
18479
18480 /* "neighbor shutdown" commands. */
18481 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18482 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18483 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18484 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18485 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18486 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18487
18488 /* "neighbor capability extended-nexthop" commands.*/
18489 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18490 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18491
18492 /* "neighbor capability orf prefix-list" commands.*/
18493 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18494 install_element(BGP_NODE,
18495 &no_neighbor_capability_orf_prefix_hidden_cmd);
18496 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18497 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18498 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18499 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18500 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18501 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18502 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18503 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18504 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18505 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18506 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18507 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18508
18509 /* "neighbor capability dynamic" commands.*/
18510 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18511 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18512
18513 /* "neighbor dont-capability-negotiate" commands. */
18514 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18515 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18516
18517 /* "neighbor ebgp-multihop" commands. */
18518 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18519 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18520 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18521
18522 /* "neighbor disable-connected-check" commands. */
18523 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18524 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18525
47cbc09b
PM
18526 /* "neighbor enforce-first-as" commands. */
18527 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18528 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18529
d62a17ae 18530 /* "neighbor description" commands. */
18531 install_element(BGP_NODE, &neighbor_description_cmd);
18532 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18533 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18534
18535 /* "neighbor update-source" commands. "*/
18536 install_element(BGP_NODE, &neighbor_update_source_cmd);
18537 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18538
18539 /* "neighbor default-originate" commands. */
18540 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18541 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18542 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18543 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18544 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18545 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18546 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18547 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18548 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18549 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18550 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18551 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18552 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18553 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18554 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18555 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18556 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18557 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18558 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18559 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18560 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18561
18562 /* "neighbor port" commands. */
18563 install_element(BGP_NODE, &neighbor_port_cmd);
18564 install_element(BGP_NODE, &no_neighbor_port_cmd);
18565
18566 /* "neighbor weight" commands. */
18567 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18568 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18569
18570 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18571 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18572 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18573 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18574 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18575 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18576 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18577 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18578 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18579 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18580 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18581 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18582 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18583 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18584 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18585 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18586
18587 /* "neighbor override-capability" commands. */
18588 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18589 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18590
18591 /* "neighbor strict-capability-match" commands. */
18592 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18593 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18594
18595 /* "neighbor timers" commands. */
18596 install_element(BGP_NODE, &neighbor_timers_cmd);
18597 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18598
18599 /* "neighbor timers connect" commands. */
18600 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18601 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18602
d43114f3
DS
18603 /* "neighbor timers delayopen" commands. */
18604 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18605 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18606
d62a17ae 18607 /* "neighbor advertisement-interval" commands. */
18608 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18609 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18610
18611 /* "neighbor interface" commands. */
18612 install_element(BGP_NODE, &neighbor_interface_cmd);
18613 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18614
18615 /* "neighbor distribute" commands. */
18616 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18617 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18618 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18619 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18620 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18621 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18622 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18623 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18624 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18625 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18626 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18627 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18628 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18629 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18630 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18631 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18632 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18633 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18634
18635 /* "neighbor prefix-list" commands. */
18636 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
d62a17ae 18637 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18638 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18639 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18640 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18641 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18642 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18643 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18644 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
7c40bf39 18645 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
7c40bf39 18646 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18647
18648 /* "neighbor filter-list" commands. */
18649 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18650 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18651 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18652 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18653 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18654 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18655 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18656 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18657 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18658 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18659 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18660 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18661 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18662 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18663 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18664 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18665 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18666 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18667 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18668 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18669 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18670 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18671
18672 /* "neighbor route-map" commands. */
d62a17ae 18673 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
d62a17ae 18674 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
d62a17ae 18675 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
d62a17ae 18676 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
d62a17ae 18677 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
d62a17ae 18678 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
d62a17ae 18679 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
d62a17ae 18680 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
7c40bf39 18681 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
7c40bf39 18682 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
d37ba549 18683 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
d62a17ae 18684
18685 /* "neighbor unsuppress-map" commands. */
18686 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18687 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18688 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18689 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18690 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18691 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18692 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18693 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18694 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18695 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18696 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18697 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18698 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18699 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18700 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18701 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18702 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18703 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18704
7f7940e6
MK
18705 /* "neighbor advertise-map" commands. */
18706 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18707 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18708 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18709 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18710 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18711 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18712 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18713 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18714 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18715
fde246e8
DA
18716 /* neighbor maximum-prefix-out commands. */
18717 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18718 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18719 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18720 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18721 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18722 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18723 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18724 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18725 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18726 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18727 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18728 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18729 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18730 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18731 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18732 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18733 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18734 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18735
d62a17ae 18736 /* "neighbor maximum-prefix" commands. */
18737 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18738 install_element(BGP_NODE,
18739 &neighbor_maximum_prefix_threshold_hidden_cmd);
18740 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18741 install_element(BGP_NODE,
18742 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18743 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18744 install_element(BGP_NODE,
18745 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18746 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18747 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18748 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18749 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18750 install_element(BGP_IPV4_NODE,
18751 &neighbor_maximum_prefix_threshold_warning_cmd);
18752 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18753 install_element(BGP_IPV4_NODE,
18754 &neighbor_maximum_prefix_threshold_restart_cmd);
18755 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18756 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18757 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18758 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18759 install_element(BGP_IPV4M_NODE,
18760 &neighbor_maximum_prefix_threshold_warning_cmd);
18761 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18762 install_element(BGP_IPV4M_NODE,
18763 &neighbor_maximum_prefix_threshold_restart_cmd);
18764 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18765 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18766 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18767 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18768 install_element(BGP_IPV4L_NODE,
18769 &neighbor_maximum_prefix_threshold_warning_cmd);
18770 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18771 install_element(BGP_IPV4L_NODE,
18772 &neighbor_maximum_prefix_threshold_restart_cmd);
18773 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18774 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18775 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18776 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18777 install_element(BGP_IPV6_NODE,
18778 &neighbor_maximum_prefix_threshold_warning_cmd);
18779 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18780 install_element(BGP_IPV6_NODE,
18781 &neighbor_maximum_prefix_threshold_restart_cmd);
18782 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18783 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18784 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18785 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18786 install_element(BGP_IPV6M_NODE,
18787 &neighbor_maximum_prefix_threshold_warning_cmd);
18788 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18789 install_element(BGP_IPV6M_NODE,
18790 &neighbor_maximum_prefix_threshold_restart_cmd);
18791 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18792 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18793 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18794 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18795 install_element(BGP_IPV6L_NODE,
18796 &neighbor_maximum_prefix_threshold_warning_cmd);
18797 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18798 install_element(BGP_IPV6L_NODE,
18799 &neighbor_maximum_prefix_threshold_restart_cmd);
18800 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18801 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18802 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18803 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18804 install_element(BGP_VPNV4_NODE,
18805 &neighbor_maximum_prefix_threshold_warning_cmd);
18806 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18807 install_element(BGP_VPNV4_NODE,
18808 &neighbor_maximum_prefix_threshold_restart_cmd);
18809 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18810 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18811 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18812 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18813 install_element(BGP_VPNV6_NODE,
18814 &neighbor_maximum_prefix_threshold_warning_cmd);
18815 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18816 install_element(BGP_VPNV6_NODE,
18817 &neighbor_maximum_prefix_threshold_restart_cmd);
18818 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18819
18820 /* "neighbor allowas-in" */
18821 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18822 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18823 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18824 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18825 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18826 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18827 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18828 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18829 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18830 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18831 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18832 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18833 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18834 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18835 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18836 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18837 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18838 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18839 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18840 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18841
0221327c
DS
18842 /* "neighbor dampening" commands. */
18843 install_element(BGP_NODE, &neighbor_damp_cmd);
18844 install_element(BGP_NODE, &no_neighbor_damp_cmd);
18845 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
18846 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
18847 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
18848 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
18849 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
18850 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
18851 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
18852 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
18853 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
18854 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
18855 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
18856 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
18857 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
18858
d62a17ae 18859 /* address-family commands. */
18860 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18861 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18862#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18863 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18864 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18865#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18866
d62a17ae 18867 install_element(BGP_NODE, &address_family_evpn_cmd);
18868
18869 /* "exit-address-family" command. */
18870 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18871 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18872 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18873 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18874 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18875 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18876 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18877 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18878 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18879 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18880 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18881
18882 /* "clear ip bgp commands" */
18883 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18884
18885 /* clear ip bgp prefix */
18886 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18887 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18888 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18889
18890 /* "show [ip] bgp summary" commands. */
18891 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18892 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18893 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18894 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18895 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18896 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18897 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18898
18899 /* "show [ip] bgp neighbors" commands. */
18900 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18901
36235319 18902 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18903
d62a17ae 18904 /* "show [ip] bgp peer-group" commands. */
18905 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18906
18907 /* "show [ip] bgp paths" commands. */
18908 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18909
18910 /* "show [ip] bgp community" commands. */
18911 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18912
18913 /* "show ip bgp large-community" commands. */
18914 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18915 /* "show [ip] bgp attribute-info" commands. */
18916 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18917 /* "show [ip] bgp route-leak" command */
18918 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18919
18920 /* "redistribute" commands. */
18921 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18922 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18923 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18924 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18925 install_element(BGP_NODE,
18926 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18927 install_element(BGP_NODE,
18928 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18929 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18930 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18931 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18932 install_element(BGP_NODE,
18933 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18934 install_element(BGP_NODE,
18935 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18936 install_element(BGP_NODE,
18937 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18938 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18939 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18940 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18941 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18942 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18943 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18944 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18945 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18946 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18947 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18948 install_element(BGP_IPV4_NODE,
18949 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18950 install_element(BGP_IPV4_NODE,
18951 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18952 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18953 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18954 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18955 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18956 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18957 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18958
b9c7bc5a
PZ
18959 /* import|export vpn [route-map WORD] */
18960 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18961 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18962
12a844a5
DS
18963 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18964 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18965
d62a17ae 18966 /* ttl_security commands */
18967 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18968 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18969
18970 /* "show [ip] bgp memory" commands. */
18971 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18972
acf71666
MK
18973 /* "show bgp martian next-hop" */
18974 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18975
48ecf8f5
DS
18976 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18977
d62a17ae 18978 /* "show [ip] bgp views" commands. */
18979 install_element(VIEW_NODE, &show_bgp_views_cmd);
18980
18981 /* "show [ip] bgp vrfs" commands. */
18982 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18983
18984 /* Community-list. */
18985 community_list_vty();
ddb5b488
PZ
18986
18987 /* vpn-policy commands */
b9c7bc5a
PZ
18988 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18989 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18990 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18991 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18992 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18993 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18994 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18995 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18996 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18997 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18998 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18999 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 19000
301ad80a
PG
19001 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19002 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19003
b9c7bc5a
PZ
19004 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19005 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19006 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19007 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
19008 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19009 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19010 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19011 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19012 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19013 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 19014}
6b0655a2 19015
718e3744 19016#include "memory.h"
19017#include "bgp_regex.h"
19018#include "bgp_clist.h"
19019#include "bgp_ecommunity.h"
19020
19021/* VTY functions. */
19022
19023/* Direction value to string conversion. */
d62a17ae 19024static const char *community_direct_str(int direct)
19025{
19026 switch (direct) {
19027 case COMMUNITY_DENY:
19028 return "deny";
19029 case COMMUNITY_PERMIT:
19030 return "permit";
19031 default:
19032 return "unknown";
19033 }
718e3744 19034}
19035
19036/* Display error string. */
d62a17ae 19037static void community_list_perror(struct vty *vty, int ret)
19038{
19039 switch (ret) {
19040 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19041 vty_out(vty, "%% Can't find community-list\n");
19042 break;
19043 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19044 vty_out(vty, "%% Malformed community-list value\n");
19045 break;
19046 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19047 vty_out(vty,
19048 "%% Community name conflict, previously defined as standard community\n");
19049 break;
19050 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19051 vty_out(vty,
19052 "%% Community name conflict, previously defined as expanded community\n");
19053 break;
19054 }
718e3744 19055}
19056
5bf15956
DW
19057/* "community-list" keyword help string. */
19058#define COMMUNITY_LIST_STR "Add a community list entry\n"
19059
7336e101
SP
19060/*community-list standard */
19061DEFUN (community_list_standard,
19062 bgp_community_list_standard_cmd,
a08032fe 19063 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19064 BGP_STR
718e3744 19065 COMMUNITY_LIST_STR
19066 "Community list number (standard)\n"
5bf15956 19067 "Add an standard community-list entry\n"
718e3744 19068 "Community list name\n"
2f8cc0e5
DA
19069 "Sequence number of an entry\n"
19070 "Sequence number\n"
718e3744 19071 "Specify community to reject\n"
19072 "Specify community to accept\n"
19073 COMMUNITY_VAL_STR)
19074{
d62a17ae 19075 char *cl_name_or_number = NULL;
2f8cc0e5 19076 char *seq = NULL;
d62a17ae 19077 int direct = 0;
19078 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19079 int idx = 0;
7336e101 19080
a08032fe 19081 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19082 if (idx)
19083 seq = argv[idx]->arg;
19084
19085 idx = 0;
d62a17ae 19086 argv_find(argv, argc, "(1-99)", &idx);
19087 argv_find(argv, argc, "WORD", &idx);
19088 cl_name_or_number = argv[idx]->arg;
19089 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19090 : COMMUNITY_DENY;
19091 argv_find(argv, argc, "AA:NN", &idx);
19092 char *str = argv_concat(argv, argc, idx);
42f914d4 19093
2f8cc0e5
DA
19094 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19095 direct, style);
42f914d4 19096
d62a17ae 19097 XFREE(MTYPE_TMP, str);
42f914d4 19098
d62a17ae 19099 if (ret < 0) {
19100 /* Display error string. */
19101 community_list_perror(vty, ret);
19102 return CMD_WARNING_CONFIG_FAILED;
19103 }
42f914d4 19104
d62a17ae 19105 return CMD_SUCCESS;
718e3744 19106}
19107
7336e101
SP
19108DEFUN (no_community_list_standard_all,
19109 no_bgp_community_list_standard_all_cmd,
a08032fe 19110 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19111 NO_STR
19112 BGP_STR
19113 COMMUNITY_LIST_STR
19114 "Community list number (standard)\n"
19115 "Add an standard community-list entry\n"
19116 "Community list name\n"
2f8cc0e5
DA
19117 "Sequence number of an entry\n"
19118 "Sequence number\n"
7336e101
SP
19119 "Specify community to reject\n"
19120 "Specify community to accept\n"
19121 COMMUNITY_VAL_STR)
718e3744 19122{
d62a17ae 19123 char *cl_name_or_number = NULL;
174b5cb9 19124 char *str = NULL;
d62a17ae 19125 int direct = 0;
19126 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19127 char *seq = NULL;
d62a17ae 19128 int idx = 0;
7336e101 19129
a08032fe 19130 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19131 if (idx)
19132 seq = argv[idx]->arg;
19133
19134 idx = 0;
174b5cb9
DA
19135 argv_find(argv, argc, "permit", &idx);
19136 argv_find(argv, argc, "deny", &idx);
19137
19138 if (idx) {
19139 direct = argv_find(argv, argc, "permit", &idx)
19140 ? COMMUNITY_PERMIT
19141 : COMMUNITY_DENY;
19142
19143 idx = 0;
19144 argv_find(argv, argc, "AA:NN", &idx);
19145 str = argv_concat(argv, argc, idx);
19146 }
19147
19148 idx = 0;
d62a17ae 19149 argv_find(argv, argc, "(1-99)", &idx);
19150 argv_find(argv, argc, "WORD", &idx);
19151 cl_name_or_number = argv[idx]->arg;
42f914d4 19152
2f8cc0e5 19153 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19154 direct, style);
42f914d4 19155
d62a17ae 19156 XFREE(MTYPE_TMP, str);
daf9ddbb 19157
d62a17ae 19158 if (ret < 0) {
19159 community_list_perror(vty, ret);
19160 return CMD_WARNING_CONFIG_FAILED;
19161 }
42f914d4 19162
d62a17ae 19163 return CMD_SUCCESS;
718e3744 19164}
7336e101 19165
174b5cb9
DA
19166ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19167 "no bgp community-list <(1-99)|standard WORD>",
19168 NO_STR BGP_STR COMMUNITY_LIST_STR
19169 "Community list number (standard)\n"
19170 "Add an standard community-list entry\n"
19171 "Community list name\n")
19172
7336e101
SP
19173/*community-list expanded */
19174DEFUN (community_list_expanded_all,
19175 bgp_community_list_expanded_all_cmd,
a08032fe 19176 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19177 BGP_STR
19178 COMMUNITY_LIST_STR
718e3744 19179 "Community list number (expanded)\n"
5bf15956 19180 "Add an expanded community-list entry\n"
718e3744 19181 "Community list name\n"
2f8cc0e5
DA
19182 "Sequence number of an entry\n"
19183 "Sequence number\n"
718e3744 19184 "Specify community to reject\n"
19185 "Specify community to accept\n"
19186 COMMUNITY_VAL_STR)
19187{
d62a17ae 19188 char *cl_name_or_number = NULL;
2f8cc0e5 19189 char *seq = NULL;
d62a17ae 19190 int direct = 0;
19191 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19192 int idx = 0;
7b9a4750 19193
a08032fe 19194 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19195 if (idx)
19196 seq = argv[idx]->arg;
19197
19198 idx = 0;
19199
d62a17ae 19200 argv_find(argv, argc, "(100-500)", &idx);
19201 argv_find(argv, argc, "WORD", &idx);
19202 cl_name_or_number = argv[idx]->arg;
19203 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19204 : COMMUNITY_DENY;
19205 argv_find(argv, argc, "AA:NN", &idx);
19206 char *str = argv_concat(argv, argc, idx);
42f914d4 19207
2f8cc0e5
DA
19208 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19209 direct, style);
42f914d4 19210
d62a17ae 19211 XFREE(MTYPE_TMP, str);
42f914d4 19212
d62a17ae 19213 if (ret < 0) {
19214 /* Display error string. */
19215 community_list_perror(vty, ret);
19216 return CMD_WARNING_CONFIG_FAILED;
19217 }
42f914d4 19218
d62a17ae 19219 return CMD_SUCCESS;
718e3744 19220}
19221
7336e101
SP
19222DEFUN (no_community_list_expanded_all,
19223 no_bgp_community_list_expanded_all_cmd,
a08032fe 19224 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19225 NO_STR
19226 BGP_STR
19227 COMMUNITY_LIST_STR
19228 "Community list number (expanded)\n"
19229 "Add an expanded community-list entry\n"
19230 "Community list name\n"
2f8cc0e5
DA
19231 "Sequence number of an entry\n"
19232 "Sequence number\n"
7336e101
SP
19233 "Specify community to reject\n"
19234 "Specify community to accept\n"
19235 COMMUNITY_VAL_STR)
718e3744 19236{
d62a17ae 19237 char *cl_name_or_number = NULL;
2f8cc0e5 19238 char *seq = NULL;
174b5cb9 19239 char *str = NULL;
d62a17ae 19240 int direct = 0;
19241 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19242 int idx = 0;
174b5cb9 19243
a08032fe 19244 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19245 if (idx)
19246 seq = argv[idx]->arg;
19247
19248 idx = 0;
174b5cb9
DA
19249 argv_find(argv, argc, "permit", &idx);
19250 argv_find(argv, argc, "deny", &idx);
19251
19252 if (idx) {
19253 direct = argv_find(argv, argc, "permit", &idx)
19254 ? COMMUNITY_PERMIT
19255 : COMMUNITY_DENY;
19256
19257 idx = 0;
19258 argv_find(argv, argc, "AA:NN", &idx);
19259 str = argv_concat(argv, argc, idx);
7336e101 19260 }
174b5cb9
DA
19261
19262 idx = 0;
d62a17ae 19263 argv_find(argv, argc, "(100-500)", &idx);
19264 argv_find(argv, argc, "WORD", &idx);
19265 cl_name_or_number = argv[idx]->arg;
42f914d4 19266
2f8cc0e5 19267 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19268 direct, style);
42f914d4 19269
d62a17ae 19270 XFREE(MTYPE_TMP, str);
daf9ddbb 19271
d62a17ae 19272 if (ret < 0) {
19273 community_list_perror(vty, ret);
19274 return CMD_WARNING_CONFIG_FAILED;
19275 }
42f914d4 19276
d62a17ae 19277 return CMD_SUCCESS;
718e3744 19278}
19279
36d4bb44
EB
19280ALIAS(no_community_list_expanded_all,
19281 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 19282 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 19283 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19284 "Community list number (expanded)\n"
19285 "Add an expanded community-list entry\n"
19286 "Community list name\n")
19287
8d9b8ed9
PM
19288/* Return configuration string of community-list entry. */
19289static const char *community_list_config_str(struct community_entry *entry)
19290{
19291 const char *str;
19292
19293 if (entry->any)
19294 str = "";
19295 else {
19296 if (entry->style == COMMUNITY_LIST_STANDARD)
19297 str = community_str(entry->u.com, false);
19298 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19299 str = lcommunity_str(entry->u.lcom, false);
19300 else
19301 str = entry->config;
19302 }
19303 return str;
19304}
19305
d62a17ae 19306static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19307{
d62a17ae 19308 struct community_entry *entry;
718e3744 19309
d62a17ae 19310 for (entry = list->head; entry; entry = entry->next) {
19311 if (entry == list->head) {
19312 if (all_digit(list->name))
19313 vty_out(vty, "Community %s list %s\n",
19314 entry->style == COMMUNITY_LIST_STANDARD
19315 ? "standard"
19316 : "(expanded) access",
19317 list->name);
19318 else
19319 vty_out(vty, "Named Community %s list %s\n",
19320 entry->style == COMMUNITY_LIST_STANDARD
19321 ? "standard"
19322 : "expanded",
19323 list->name);
19324 }
19325 if (entry->any)
19326 vty_out(vty, " %s\n",
19327 community_direct_str(entry->direct));
19328 else
19329 vty_out(vty, " %s %s\n",
19330 community_direct_str(entry->direct),
8d9b8ed9 19331 community_list_config_str(entry));
d62a17ae 19332 }
718e3744 19333}
19334
7336e101
SP
19335DEFUN (show_community_list,
19336 show_bgp_community_list_cmd,
19337 "show bgp community-list",
718e3744 19338 SHOW_STR
7336e101 19339 BGP_STR
718e3744 19340 "List community-list\n")
19341{
d62a17ae 19342 struct community_list *list;
19343 struct community_list_master *cm;
718e3744 19344
d62a17ae 19345 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19346 if (!cm)
19347 return CMD_SUCCESS;
718e3744 19348
d62a17ae 19349 for (list = cm->num.head; list; list = list->next)
19350 community_list_show(vty, list);
718e3744 19351
d62a17ae 19352 for (list = cm->str.head; list; list = list->next)
19353 community_list_show(vty, list);
718e3744 19354
d62a17ae 19355 return CMD_SUCCESS;
718e3744 19356}
19357
7336e101
SP
19358DEFUN (show_community_list_arg,
19359 show_bgp_community_list_arg_cmd,
960b69b9 19360 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
19361 SHOW_STR
19362 BGP_STR
718e3744 19363 "List community-list\n"
19364 "Community-list number\n"
960b69b9 19365 "Community-list name\n"
19366 "Detailed information on community-list\n")
718e3744 19367{
d62a17ae 19368 int idx_comm_list = 3;
19369 struct community_list *list;
718e3744 19370
e237b0d2 19371 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19372 COMMUNITY_LIST_MASTER);
19373 if (!list) {
19374 vty_out(vty, "%% Can't find community-list\n");
19375 return CMD_WARNING;
19376 }
718e3744 19377
d62a17ae 19378 community_list_show(vty, list);
718e3744 19379
d62a17ae 19380 return CMD_SUCCESS;
718e3744 19381}
6b0655a2 19382
57d187bc
JS
19383/*
19384 * Large Community code.
19385 */
d62a17ae 19386static int lcommunity_list_set_vty(struct vty *vty, int argc,
19387 struct cmd_token **argv, int style,
19388 int reject_all_digit_name)
19389{
19390 int ret;
19391 int direct;
19392 char *str;
19393 int idx = 0;
19394 char *cl_name;
2f8cc0e5
DA
19395 char *seq = NULL;
19396
a08032fe 19397 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19398 seq = argv[idx]->arg;
d62a17ae 19399
2f8cc0e5 19400 idx = 0;
d62a17ae 19401 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19402 : COMMUNITY_DENY;
19403
19404 /* All digit name check. */
19405 idx = 0;
19406 argv_find(argv, argc, "WORD", &idx);
19407 argv_find(argv, argc, "(1-99)", &idx);
19408 argv_find(argv, argc, "(100-500)", &idx);
19409 cl_name = argv[idx]->arg;
19410 if (reject_all_digit_name && all_digit(cl_name)) {
19411 vty_out(vty, "%% Community name cannot have all digits\n");
19412 return CMD_WARNING_CONFIG_FAILED;
19413 }
19414
19415 idx = 0;
19416 argv_find(argv, argc, "AA:BB:CC", &idx);
19417 argv_find(argv, argc, "LINE", &idx);
19418 /* Concat community string argument. */
19419 if (idx)
19420 str = argv_concat(argv, argc, idx);
19421 else
19422 str = NULL;
19423
2f8cc0e5 19424 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19425
19426 /* Free temporary community list string allocated by
19427 argv_concat(). */
0a22ddfb 19428 XFREE(MTYPE_TMP, str);
d62a17ae 19429
19430 if (ret < 0) {
19431 community_list_perror(vty, ret);
19432 return CMD_WARNING_CONFIG_FAILED;
19433 }
19434 return CMD_SUCCESS;
19435}
19436
19437static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19438 struct cmd_token **argv, int style)
19439{
19440 int ret;
19441 int direct = 0;
19442 char *str = NULL;
19443 int idx = 0;
2f8cc0e5 19444 char *seq = NULL;
d62a17ae 19445
a08032fe 19446 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19447 seq = argv[idx]->arg;
d62a17ae 19448
2f8cc0e5 19449 idx = 0;
d62a17ae 19450 argv_find(argv, argc, "permit", &idx);
19451 argv_find(argv, argc, "deny", &idx);
19452
19453 if (idx) {
19454 /* Check the list direct. */
19455 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19456 direct = COMMUNITY_PERMIT;
19457 else
19458 direct = COMMUNITY_DENY;
19459
19460 idx = 0;
19461 argv_find(argv, argc, "LINE", &idx);
19462 argv_find(argv, argc, "AA:AA:NN", &idx);
19463 /* Concat community string argument. */
19464 str = argv_concat(argv, argc, idx);
19465 }
19466
19467 idx = 0;
19468 argv_find(argv, argc, "(1-99)", &idx);
19469 argv_find(argv, argc, "(100-500)", &idx);
19470 argv_find(argv, argc, "WORD", &idx);
19471
19472 /* Unset community list. */
2f8cc0e5 19473 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19474 style);
19475
19476 /* Free temporary community list string allocated by
19477 argv_concat(). */
0a22ddfb 19478 XFREE(MTYPE_TMP, str);
d62a17ae 19479
19480 if (ret < 0) {
19481 community_list_perror(vty, ret);
19482 return CMD_WARNING_CONFIG_FAILED;
19483 }
19484
19485 return CMD_SUCCESS;
57d187bc
JS
19486}
19487
19488/* "large-community-list" keyword help string. */
19489#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19490#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19491
7336e101
SP
19492DEFUN (lcommunity_list_standard,
19493 bgp_lcommunity_list_standard_cmd,
a08032fe 19494 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19495 BGP_STR
19496 LCOMMUNITY_LIST_STR
19497 "Large Community list number (standard)\n"
2f8cc0e5
DA
19498 "Sequence number of an entry\n"
19499 "Sequence number\n"
7336e101
SP
19500 "Specify large community to reject\n"
19501 "Specify large community to accept\n"
19502 LCOMMUNITY_VAL_STR)
52951b63 19503{
d62a17ae 19504 return lcommunity_list_set_vty(vty, argc, argv,
19505 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19506}
19507
7336e101
SP
19508DEFUN (lcommunity_list_expanded,
19509 bgp_lcommunity_list_expanded_cmd,
a08032fe 19510 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19511 BGP_STR
19512 LCOMMUNITY_LIST_STR
19513 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19514 "Sequence number of an entry\n"
19515 "Sequence number\n"
7336e101
SP
19516 "Specify large community to reject\n"
19517 "Specify large community to accept\n"
19518 "An ordered list as a regular-expression\n")
57d187bc 19519{
d62a17ae 19520 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19521 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19522}
19523
7336e101
SP
19524DEFUN (lcommunity_list_name_standard,
19525 bgp_lcommunity_list_name_standard_cmd,
a08032fe 19526 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19527 BGP_STR
19528 LCOMMUNITY_LIST_STR
19529 "Specify standard large-community-list\n"
19530 "Large Community list name\n"
2f8cc0e5
DA
19531 "Sequence number of an entry\n"
19532 "Sequence number\n"
7336e101
SP
19533 "Specify large community to reject\n"
19534 "Specify large community to accept\n"
19535 LCOMMUNITY_VAL_STR)
52951b63 19536{
d62a17ae 19537 return lcommunity_list_set_vty(vty, argc, argv,
19538 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19539}
19540
7336e101
SP
19541DEFUN (lcommunity_list_name_expanded,
19542 bgp_lcommunity_list_name_expanded_cmd,
a08032fe 19543 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19544 BGP_STR
19545 LCOMMUNITY_LIST_STR
19546 "Specify expanded large-community-list\n"
19547 "Large Community list name\n"
2f8cc0e5
DA
19548 "Sequence number of an entry\n"
19549 "Sequence number\n"
7336e101
SP
19550 "Specify large community to reject\n"
19551 "Specify large community to accept\n"
19552 "An ordered list as a regular-expression\n")
57d187bc 19553{
d62a17ae 19554 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19555 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19556}
19557
4378f57c
DA
19558DEFUN (no_lcommunity_list_all,
19559 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
19560 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19561 NO_STR
19562 BGP_STR
19563 LCOMMUNITY_LIST_STR
19564 "Large Community list number (standard)\n"
19565 "Large Community list number (expanded)\n"
19566 "Large Community list name\n")
57d187bc 19567{
7336e101
SP
19568 return lcommunity_list_unset_vty(vty, argc, argv,
19569 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19570}
19571
4378f57c
DA
19572DEFUN (no_lcommunity_list_name_standard_all,
19573 no_bgp_lcommunity_list_name_standard_all_cmd,
19574 "no bgp large-community-list standard WORD",
19575 NO_STR
19576 BGP_STR
19577 LCOMMUNITY_LIST_STR
19578 "Specify standard large-community-list\n"
19579 "Large Community list name\n")
19580{
19581 return lcommunity_list_unset_vty(vty, argc, argv,
19582 LARGE_COMMUNITY_LIST_STANDARD);
19583}
19584
7336e101
SP
19585DEFUN (no_lcommunity_list_name_expanded_all,
19586 no_bgp_lcommunity_list_name_expanded_all_cmd,
19587 "no bgp large-community-list expanded WORD",
19588 NO_STR
19589 BGP_STR
19590 LCOMMUNITY_LIST_STR
19591 "Specify expanded large-community-list\n"
19592 "Large Community list name\n")
57d187bc 19593{
d62a17ae 19594 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19595 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19596}
19597
7336e101
SP
19598DEFUN (no_lcommunity_list_standard,
19599 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19600 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19601 NO_STR
19602 BGP_STR
19603 LCOMMUNITY_LIST_STR
19604 "Large Community list number (standard)\n"
2f8cc0e5
DA
19605 "Sequence number of an entry\n"
19606 "Sequence number\n"
7336e101
SP
19607 "Specify large community to reject\n"
19608 "Specify large community to accept\n"
19609 LCOMMUNITY_VAL_STR)
57d187bc 19610{
d62a17ae 19611 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19612 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19613}
19614
7336e101
SP
19615DEFUN (no_lcommunity_list_expanded,
19616 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19617 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19618 NO_STR
19619 BGP_STR
19620 LCOMMUNITY_LIST_STR
19621 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19622 "Sequence number of an entry\n"
19623 "Sequence number\n"
7336e101
SP
19624 "Specify large community to reject\n"
19625 "Specify large community to accept\n"
19626 "An ordered list as a regular-expression\n")
57d187bc 19627{
d62a17ae 19628 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19629 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19630}
19631
7336e101
SP
19632DEFUN (no_lcommunity_list_name_standard,
19633 no_bgp_lcommunity_list_name_standard_cmd,
a08032fe 19634 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19635 NO_STR
19636 BGP_STR
19637 LCOMMUNITY_LIST_STR
19638 "Specify standard large-community-list\n"
19639 "Large Community list name\n"
2f8cc0e5
DA
19640 "Sequence number of an entry\n"
19641 "Sequence number\n"
7336e101
SP
19642 "Specify large community to reject\n"
19643 "Specify large community to accept\n"
19644 LCOMMUNITY_VAL_STR)
57d187bc 19645{
d62a17ae 19646 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19647 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19648}
19649
7336e101
SP
19650DEFUN (no_lcommunity_list_name_expanded,
19651 no_bgp_lcommunity_list_name_expanded_cmd,
a08032fe 19652 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19653 NO_STR
19654 BGP_STR
19655 LCOMMUNITY_LIST_STR
19656 "Specify expanded large-community-list\n"
19657 "Large community list name\n"
2f8cc0e5
DA
19658 "Sequence number of an entry\n"
19659 "Sequence number\n"
7336e101
SP
19660 "Specify large community to reject\n"
19661 "Specify large community to accept\n"
19662 "An ordered list as a regular-expression\n")
57d187bc 19663{
d62a17ae 19664 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19665 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19666}
19667
d62a17ae 19668static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19669{
19670 struct community_entry *entry;
19671
19672 for (entry = list->head; entry; entry = entry->next) {
19673 if (entry == list->head) {
19674 if (all_digit(list->name))
19675 vty_out(vty, "Large community %s list %s\n",
169b72c8 19676 entry->style ==
19677 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19678 ? "standard"
19679 : "(expanded) access",
19680 list->name);
19681 else
19682 vty_out(vty,
19683 "Named large community %s list %s\n",
169b72c8 19684 entry->style ==
19685 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19686 ? "standard"
19687 : "expanded",
19688 list->name);
19689 }
19690 if (entry->any)
19691 vty_out(vty, " %s\n",
19692 community_direct_str(entry->direct));
19693 else
19694 vty_out(vty, " %s %s\n",
19695 community_direct_str(entry->direct),
8d9b8ed9 19696 community_list_config_str(entry));
d62a17ae 19697 }
57d187bc
JS
19698}
19699
7336e101
SP
19700DEFUN (show_lcommunity_list,
19701 show_bgp_lcommunity_list_cmd,
19702 "show bgp large-community-list",
57d187bc 19703 SHOW_STR
7336e101 19704 BGP_STR
57d187bc
JS
19705 "List large-community list\n")
19706{
d62a17ae 19707 struct community_list *list;
19708 struct community_list_master *cm;
57d187bc 19709
d62a17ae 19710 cm = community_list_master_lookup(bgp_clist,
19711 LARGE_COMMUNITY_LIST_MASTER);
19712 if (!cm)
19713 return CMD_SUCCESS;
57d187bc 19714
d62a17ae 19715 for (list = cm->num.head; list; list = list->next)
19716 lcommunity_list_show(vty, list);
57d187bc 19717
d62a17ae 19718 for (list = cm->str.head; list; list = list->next)
19719 lcommunity_list_show(vty, list);
57d187bc 19720
d62a17ae 19721 return CMD_SUCCESS;
57d187bc
JS
19722}
19723
7336e101
SP
19724DEFUN (show_lcommunity_list_arg,
19725 show_bgp_lcommunity_list_arg_cmd,
960b69b9 19726 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
19727 SHOW_STR
19728 BGP_STR
57d187bc 19729 "List large-community list\n"
960b69b9 19730 "Large-community-list number\n"
19731 "Large-community-list name\n"
19732 "Detailed information on large-community-list\n")
57d187bc 19733{
d62a17ae 19734 struct community_list *list;
57d187bc 19735
e237b0d2 19736 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19737 LARGE_COMMUNITY_LIST_MASTER);
19738 if (!list) {
960b69b9 19739 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19740 return CMD_WARNING;
19741 }
57d187bc 19742
d62a17ae 19743 lcommunity_list_show(vty, list);
57d187bc 19744
d62a17ae 19745 return CMD_SUCCESS;
57d187bc
JS
19746}
19747
718e3744 19748/* "extcommunity-list" keyword help string. */
19749#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19750#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19751
7336e101
SP
19752DEFUN (extcommunity_list_standard,
19753 bgp_extcommunity_list_standard_cmd,
a08032fe 19754 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19755 BGP_STR
718e3744 19756 EXTCOMMUNITY_LIST_STR
19757 "Extended Community list number (standard)\n"
718e3744 19758 "Specify standard extcommunity-list\n"
5bf15956 19759 "Community list name\n"
2f8cc0e5
DA
19760 "Sequence number of an entry\n"
19761 "Sequence number\n"
718e3744 19762 "Specify community to reject\n"
19763 "Specify community to accept\n"
19764 EXTCOMMUNITY_VAL_STR)
19765{
d62a17ae 19766 int style = EXTCOMMUNITY_LIST_STANDARD;
19767 int direct = 0;
19768 char *cl_number_or_name = NULL;
2f8cc0e5 19769 char *seq = NULL;
42f914d4 19770
d62a17ae 19771 int idx = 0;
7b9a4750 19772
d62a17ae 19773 argv_find(argv, argc, "(1-99)", &idx);
19774 argv_find(argv, argc, "WORD", &idx);
19775 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19776
a08032fe 19777 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19778 seq = argv[idx]->arg;
19779
d62a17ae 19780 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19781 : COMMUNITY_DENY;
19782 argv_find(argv, argc, "AA:NN", &idx);
19783 char *str = argv_concat(argv, argc, idx);
42f914d4 19784
2f8cc0e5 19785 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19786 direct, style);
42f914d4 19787
d62a17ae 19788 XFREE(MTYPE_TMP, str);
42f914d4 19789
d62a17ae 19790 if (ret < 0) {
19791 community_list_perror(vty, ret);
19792 return CMD_WARNING_CONFIG_FAILED;
19793 }
42f914d4 19794
d62a17ae 19795 return CMD_SUCCESS;
718e3744 19796}
19797
7336e101
SP
19798DEFUN (extcommunity_list_name_expanded,
19799 bgp_extcommunity_list_name_expanded_cmd,
a08032fe 19800 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19801 BGP_STR
19802 EXTCOMMUNITY_LIST_STR
5bf15956 19803 "Extended Community list number (expanded)\n"
718e3744 19804 "Specify expanded extcommunity-list\n"
19805 "Extended Community list name\n"
2f8cc0e5
DA
19806 "Sequence number of an entry\n"
19807 "Sequence number\n"
718e3744 19808 "Specify community to reject\n"
19809 "Specify community to accept\n"
19810 "An ordered list as a regular-expression\n")
19811{
d62a17ae 19812 int style = EXTCOMMUNITY_LIST_EXPANDED;
19813 int direct = 0;
19814 char *cl_number_or_name = NULL;
2f8cc0e5 19815 char *seq = NULL;
d62a17ae 19816 int idx = 0;
7336e101 19817
d62a17ae 19818 argv_find(argv, argc, "(100-500)", &idx);
19819 argv_find(argv, argc, "WORD", &idx);
19820 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19821
a08032fe 19822 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19823 seq = argv[idx]->arg;
19824
d62a17ae 19825 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19826 : COMMUNITY_DENY;
19827 argv_find(argv, argc, "LINE", &idx);
19828 char *str = argv_concat(argv, argc, idx);
42f914d4 19829
2f8cc0e5 19830 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19831 direct, style);
42f914d4 19832
d62a17ae 19833 XFREE(MTYPE_TMP, str);
42f914d4 19834
d62a17ae 19835 if (ret < 0) {
19836 community_list_perror(vty, ret);
19837 return CMD_WARNING_CONFIG_FAILED;
19838 }
42f914d4 19839
d62a17ae 19840 return CMD_SUCCESS;
718e3744 19841}
19842
7336e101
SP
19843DEFUN (no_extcommunity_list_standard_all,
19844 no_bgp_extcommunity_list_standard_all_cmd,
a08032fe 19845 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19846 NO_STR
19847 BGP_STR
19848 EXTCOMMUNITY_LIST_STR
813d4307 19849 "Extended Community list number (standard)\n"
718e3744 19850 "Specify standard extcommunity-list\n"
5bf15956 19851 "Community list name\n"
2f8cc0e5
DA
19852 "Sequence number of an entry\n"
19853 "Sequence number\n"
718e3744 19854 "Specify community to reject\n"
19855 "Specify community to accept\n"
19856 EXTCOMMUNITY_VAL_STR)
19857{
d62a17ae 19858 int style = EXTCOMMUNITY_LIST_STANDARD;
19859 int direct = 0;
19860 char *cl_number_or_name = NULL;
d4455c89 19861 char *str = NULL;
2f8cc0e5 19862 char *seq = NULL;
d62a17ae 19863 int idx = 0;
d4455c89 19864
a08032fe 19865 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19866 seq = argv[idx]->arg;
19867
19868 idx = 0;
d4455c89
DA
19869 argv_find(argv, argc, "permit", &idx);
19870 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19871 if (idx) {
19872 direct = argv_find(argv, argc, "permit", &idx)
19873 ? COMMUNITY_PERMIT
19874 : COMMUNITY_DENY;
19875
19876 idx = 0;
19877 argv_find(argv, argc, "AA:NN", &idx);
19878 str = argv_concat(argv, argc, idx);
19879 }
19880
19881 idx = 0;
d62a17ae 19882 argv_find(argv, argc, "(1-99)", &idx);
19883 argv_find(argv, argc, "WORD", &idx);
19884 cl_number_or_name = argv[idx]->arg;
42f914d4 19885
d62a17ae 19886 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19887 seq, direct, style);
42f914d4 19888
d62a17ae 19889 XFREE(MTYPE_TMP, str);
42f914d4 19890
d62a17ae 19891 if (ret < 0) {
19892 community_list_perror(vty, ret);
19893 return CMD_WARNING_CONFIG_FAILED;
19894 }
42f914d4 19895
d62a17ae 19896 return CMD_SUCCESS;
718e3744 19897}
19898
d4455c89
DA
19899ALIAS(no_extcommunity_list_standard_all,
19900 no_bgp_extcommunity_list_standard_all_list_cmd,
19901 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 19902 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19903 "Extended Community list number (standard)\n"
19904 "Specify standard extcommunity-list\n"
19905 "Community list name\n")
19906
7336e101
SP
19907DEFUN (no_extcommunity_list_expanded_all,
19908 no_bgp_extcommunity_list_expanded_all_cmd,
a08032fe 19909 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19910 NO_STR
19911 BGP_STR
19912 EXTCOMMUNITY_LIST_STR
718e3744 19913 "Extended Community list number (expanded)\n"
718e3744 19914 "Specify expanded extcommunity-list\n"
5bf15956 19915 "Extended Community list name\n"
2f8cc0e5
DA
19916 "Sequence number of an entry\n"
19917 "Sequence number\n"
718e3744 19918 "Specify community to reject\n"
19919 "Specify community to accept\n"
19920 "An ordered list as a regular-expression\n")
19921{
d62a17ae 19922 int style = EXTCOMMUNITY_LIST_EXPANDED;
19923 int direct = 0;
19924 char *cl_number_or_name = NULL;
d4455c89 19925 char *str = NULL;
2f8cc0e5 19926 char *seq = NULL;
d62a17ae 19927 int idx = 0;
d4455c89 19928
a08032fe 19929 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19930 seq = argv[idx]->arg;
19931
19932 idx = 0;
d4455c89
DA
19933 argv_find(argv, argc, "permit", &idx);
19934 argv_find(argv, argc, "deny", &idx);
19935
19936 if (idx) {
19937 direct = argv_find(argv, argc, "permit", &idx)
19938 ? COMMUNITY_PERMIT
19939 : COMMUNITY_DENY;
19940
19941 idx = 0;
19942 argv_find(argv, argc, "LINE", &idx);
19943 str = argv_concat(argv, argc, idx);
19944 }
19945
19946 idx = 0;
d62a17ae 19947 argv_find(argv, argc, "(100-500)", &idx);
19948 argv_find(argv, argc, "WORD", &idx);
19949 cl_number_or_name = argv[idx]->arg;
42f914d4 19950
d62a17ae 19951 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19952 seq, direct, style);
42f914d4 19953
d62a17ae 19954 XFREE(MTYPE_TMP, str);
42f914d4 19955
d62a17ae 19956 if (ret < 0) {
19957 community_list_perror(vty, ret);
19958 return CMD_WARNING_CONFIG_FAILED;
19959 }
42f914d4 19960
d62a17ae 19961 return CMD_SUCCESS;
718e3744 19962}
19963
d4455c89
DA
19964ALIAS(no_extcommunity_list_expanded_all,
19965 no_bgp_extcommunity_list_expanded_all_list_cmd,
19966 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 19967 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19968 "Extended Community list number (expanded)\n"
19969 "Specify expanded extcommunity-list\n"
19970 "Extended Community list name\n")
19971
d62a17ae 19972static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19973{
d62a17ae 19974 struct community_entry *entry;
718e3744 19975
d62a17ae 19976 for (entry = list->head; entry; entry = entry->next) {
19977 if (entry == list->head) {
19978 if (all_digit(list->name))
19979 vty_out(vty, "Extended community %s list %s\n",
19980 entry->style == EXTCOMMUNITY_LIST_STANDARD
19981 ? "standard"
19982 : "(expanded) access",
19983 list->name);
19984 else
19985 vty_out(vty,
19986 "Named extended community %s list %s\n",
19987 entry->style == EXTCOMMUNITY_LIST_STANDARD
19988 ? "standard"
19989 : "expanded",
19990 list->name);
19991 }
19992 if (entry->any)
19993 vty_out(vty, " %s\n",
19994 community_direct_str(entry->direct));
19995 else
19996 vty_out(vty, " %s %s\n",
19997 community_direct_str(entry->direct),
8d9b8ed9 19998 community_list_config_str(entry));
d62a17ae 19999 }
718e3744 20000}
20001
7336e101
SP
20002DEFUN (show_extcommunity_list,
20003 show_bgp_extcommunity_list_cmd,
20004 "show bgp extcommunity-list",
718e3744 20005 SHOW_STR
7336e101 20006 BGP_STR
718e3744 20007 "List extended-community list\n")
20008{
d62a17ae 20009 struct community_list *list;
20010 struct community_list_master *cm;
718e3744 20011
d62a17ae 20012 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20013 if (!cm)
20014 return CMD_SUCCESS;
718e3744 20015
d62a17ae 20016 for (list = cm->num.head; list; list = list->next)
20017 extcommunity_list_show(vty, list);
718e3744 20018
d62a17ae 20019 for (list = cm->str.head; list; list = list->next)
20020 extcommunity_list_show(vty, list);
718e3744 20021
d62a17ae 20022 return CMD_SUCCESS;
718e3744 20023}
20024
7336e101
SP
20025DEFUN (show_extcommunity_list_arg,
20026 show_bgp_extcommunity_list_arg_cmd,
960b69b9 20027 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
20028 SHOW_STR
20029 BGP_STR
718e3744 20030 "List extended-community list\n"
20031 "Extcommunity-list number\n"
960b69b9 20032 "Extcommunity-list name\n"
20033 "Detailed information on extcommunity-list\n")
718e3744 20034{
d62a17ae 20035 int idx_comm_list = 3;
20036 struct community_list *list;
718e3744 20037
e237b0d2 20038 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20039 EXTCOMMUNITY_LIST_MASTER);
20040 if (!list) {
20041 vty_out(vty, "%% Can't find extcommunity-list\n");
20042 return CMD_WARNING;
20043 }
718e3744 20044
d62a17ae 20045 extcommunity_list_show(vty, list);
718e3744 20046
d62a17ae 20047 return CMD_SUCCESS;
718e3744 20048}
6b0655a2 20049
718e3744 20050/* Display community-list and extcommunity-list configuration. */
d62a17ae 20051static int community_list_config_write(struct vty *vty)
20052{
20053 struct community_list *list;
20054 struct community_entry *entry;
20055 struct community_list_master *cm;
20056 int write = 0;
20057
20058 /* Community-list. */
20059 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20060
20061 for (list = cm->num.head; list; list = list->next)
20062 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20063 vty_out(vty,
20064 "bgp community-list %s seq %" PRId64 " %s %s\n",
20065 list->name, entry->seq,
d62a17ae 20066 community_direct_str(entry->direct),
20067 community_list_config_str(entry));
20068 write++;
20069 }
20070 for (list = cm->str.head; list; list = list->next)
20071 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20072 vty_out(vty,
20073 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20074 entry->style == COMMUNITY_LIST_STANDARD
20075 ? "standard"
20076 : "expanded",
2f8cc0e5
DA
20077 list->name, entry->seq,
20078 community_direct_str(entry->direct),
d62a17ae 20079 community_list_config_str(entry));
20080 write++;
20081 }
20082
20083 /* Extcommunity-list. */
20084 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20085
20086 for (list = cm->num.head; list; list = list->next)
20087 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20088 vty_out(vty,
20089 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20090 list->name, entry->seq,
20091 community_direct_str(entry->direct),
d62a17ae 20092 community_list_config_str(entry));
20093 write++;
20094 }
20095 for (list = cm->str.head; list; list = list->next)
20096 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20097 vty_out(vty,
6cde4b45 20098 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20099 entry->style == EXTCOMMUNITY_LIST_STANDARD
20100 ? "standard"
20101 : "expanded",
2f8cc0e5
DA
20102 list->name, entry->seq,
20103 community_direct_str(entry->direct),
d62a17ae 20104 community_list_config_str(entry));
20105 write++;
20106 }
20107
20108
20109 /* lcommunity-list. */
20110 cm = community_list_master_lookup(bgp_clist,
20111 LARGE_COMMUNITY_LIST_MASTER);
20112
20113 for (list = cm->num.head; list; list = list->next)
20114 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20115 vty_out(vty,
6cde4b45 20116 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20117 list->name, entry->seq,
20118 community_direct_str(entry->direct),
d62a17ae 20119 community_list_config_str(entry));
20120 write++;
20121 }
20122 for (list = cm->str.head; list; list = list->next)
20123 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20124 vty_out(vty,
6cde4b45 20125 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20126
d62a17ae 20127 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20128 ? "standard"
20129 : "expanded",
2f8cc0e5 20130 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20131 community_list_config_str(entry));
20132 write++;
20133 }
20134
20135 return write;
20136}
20137
612c2c15 20138static int community_list_config_write(struct vty *vty);
d62a17ae 20139static struct cmd_node community_list_node = {
f4b8291f 20140 .name = "community list",
62b346ee
DL
20141 .node = COMMUNITY_LIST_NODE,
20142 .prompt = "",
612c2c15 20143 .config_write = community_list_config_write,
718e3744 20144};
20145
d62a17ae 20146static void community_list_vty(void)
20147{
612c2c15 20148 install_node(&community_list_node);
d62a17ae 20149
20150 /* Community-list. */
7336e101
SP
20151 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20152 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20153 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20154 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20155 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20156 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20157 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20158 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20159
20160 /* Extcommunity-list. */
7336e101
SP
20161 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20162 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20163 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20164 install_element(CONFIG_NODE,
20165 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20166 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20167 install_element(CONFIG_NODE,
20168 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20169 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20170 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20171
20172 /* Large Community List */
7336e101 20173 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20174 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20175 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20176 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20177 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20178 install_element(CONFIG_NODE,
20179 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20180 install_element(CONFIG_NODE,
20181 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20182 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20183 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20184 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20185 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20186 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20187 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 20188}