]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #8730 from idryzhov/staticd-distance
[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"
4ab46701 25#include "lib/sockopt.h"
5cb5f4d0 26#include "lib_errors.h"
ec0ab544 27#include "lib/zclient.h"
6f4eacf3 28#include "lib/printfrr.h"
718e3744 29#include "prefix.h"
30#include "plist.h"
31#include "buffer.h"
32#include "linklist.h"
33#include "stream.h"
34#include "thread.h"
35#include "log.h"
3b8b1855 36#include "memory.h"
1c0d8808 37#include "lib_vty.h"
4bf6a362 38#include "hash.h"
3f9c7369 39#include "queue.h"
039f3a34 40#include "filter.h"
5d5ba018 41#include "frrstr.h"
718e3744 42
43#include "bgpd/bgpd.h"
48ecf8f5 44#include "bgpd/bgp_attr_evpn.h"
4bf6a362 45#include "bgpd/bgp_advertise.h"
718e3744 46#include "bgpd/bgp_attr.h"
47#include "bgpd/bgp_aspath.h"
48#include "bgpd/bgp_community.h"
ed0e57e3 49#include "bgpd/bgp_community_alias.h"
4bf6a362 50#include "bgpd/bgp_ecommunity.h"
57d187bc 51#include "bgpd/bgp_lcommunity.h"
4bf6a362 52#include "bgpd/bgp_damp.h"
718e3744 53#include "bgpd/bgp_debug.h"
14454c9f 54#include "bgpd/bgp_errors.h"
e0701b79 55#include "bgpd/bgp_fsm.h"
4bf6a362 56#include "bgpd/bgp_nexthop.h"
718e3744 57#include "bgpd/bgp_open.h"
4bf6a362 58#include "bgpd/bgp_regex.h"
718e3744 59#include "bgpd/bgp_route.h"
c016b6c7 60#include "bgpd/bgp_mplsvpn.h"
718e3744 61#include "bgpd/bgp_zebra.h"
fee0f4c6 62#include "bgpd/bgp_table.h"
94f2b392 63#include "bgpd/bgp_vty.h"
165b5fff 64#include "bgpd/bgp_mpath.h"
cb1faec9 65#include "bgpd/bgp_packet.h"
3f9c7369 66#include "bgpd/bgp_updgrp.h"
c43ed2e4 67#include "bgpd/bgp_bfd.h"
555e09d4 68#include "bgpd/bgp_io.h"
94c2f693 69#include "bgpd/bgp_evpn.h"
dd65f45e 70#include "bgpd/bgp_evpn_vty.h"
b5e140c8 71#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 72#include "bgpd/bgp_addpath.h"
48ecf8f5 73#include "bgpd/bgp_mac.h"
dd65f45e 74#include "bgpd/bgp_flowspec.h"
49e5a4a0 75#ifdef ENABLE_BGP_VNC
dd65f45e
DL
76#include "bgpd/rfapi/bgp_rfapi_cfg.h"
77#endif
78
ff8a8a7a
CS
79#include "northbound.h"
80#include "northbound_cli.h"
81#include "bgpd/bgp_nb.h"
82
83
5d5393b9 84FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
85 {
86 .val_bool = false,
87 .match_profile = "traditional",
88 .match_version = "< 7.4",
89 },
90 { .val_bool = true },
67b0f40c 91);
5d5393b9 92FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
67b0f40c 95);
aef999a2
DA
96FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
67b0f40c 99);
5d5393b9 100FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
67b0f40c 103);
5d5393b9 104FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
105 { .val_bool = true, .match_profile = "datacenter", },
106 { .val_bool = false },
67b0f40c 107);
5d5393b9
DL
108FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
109 { .val_ulong = 10, .match_profile = "datacenter", },
110 { .val_ulong = 120 },
67b0f40c 111);
5d5393b9
DL
112FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
113 { .val_ulong = 9, .match_profile = "datacenter", },
114 { .val_ulong = 180 },
67b0f40c 115);
5d5393b9
DL
116FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
117 { .val_ulong = 3, .match_profile = "datacenter", },
118 { .val_ulong = 60 },
67b0f40c 119);
1d3fdccf
DA
120FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
121 { .val_bool = false, .match_profile = "datacenter", },
122 { .val_bool = false, .match_version = "< 7.4", },
123 { .val_bool = true },
67b0f40c 124);
2adac256
DA
125FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
126 { .val_bool = false, .match_version = "< 7.6", },
127 { .val_bool = true },
67b0f40c 128);
5d5393b9 129
dd65f45e
DL
130DEFINE_HOOK(bgp_inst_config_write,
131 (struct bgp *bgp, struct vty *vty),
8451921b
DL
132 (bgp, vty));
133DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
718e3744 134
d62a17ae 135static struct peer_group *listen_range_exists(struct bgp *bgp,
136 struct prefix *range, int exact);
137
055679e9 138/* Show BGP peer's information. */
139enum show_type {
140 show_all,
141 show_peer,
142 show_ipv4_all,
143 show_ipv6_all,
144 show_ipv4_peer,
145 show_ipv6_peer
146};
147
36235319
QY
148static struct peer_group *listen_range_exists(struct bgp *bgp,
149 struct prefix *range, int exact);
2986cac2 150
36235319
QY
151static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
152 struct bgp *bgp,
153 bool use_json,
154 json_object *json);
2986cac2 155
36235319
QY
156static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
157 enum show_type type,
158 const char *ip_str,
159 afi_t afi, bool use_json);
2986cac2 160
f4b8ec07
CS
161static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
162 char *base_xpath, int xpath_len,
163 char *abs_xpath);
164
d62a17ae 165static enum node_type bgp_node_type(afi_t afi, safi_t safi)
166{
167 switch (afi) {
168 case AFI_IP:
169 switch (safi) {
170 case SAFI_UNICAST:
171 return BGP_IPV4_NODE;
d62a17ae 172 case SAFI_MULTICAST:
173 return BGP_IPV4M_NODE;
d62a17ae 174 case SAFI_LABELED_UNICAST:
175 return BGP_IPV4L_NODE;
d62a17ae 176 case SAFI_MPLS_VPN:
177 return BGP_VPNV4_NODE;
7c40bf39 178 case SAFI_FLOWSPEC:
179 return BGP_FLOWSPECV4_NODE;
5c525538
RW
180 default:
181 /* not expected */
182 return BGP_IPV4_NODE;
d62a17ae 183 }
184 break;
185 case AFI_IP6:
186 switch (safi) {
187 case SAFI_UNICAST:
188 return BGP_IPV6_NODE;
d62a17ae 189 case SAFI_MULTICAST:
190 return BGP_IPV6M_NODE;
d62a17ae 191 case SAFI_LABELED_UNICAST:
192 return BGP_IPV6L_NODE;
d62a17ae 193 case SAFI_MPLS_VPN:
194 return BGP_VPNV6_NODE;
7c40bf39 195 case SAFI_FLOWSPEC:
196 return BGP_FLOWSPECV6_NODE;
5c525538
RW
197 default:
198 /* not expected */
199 return BGP_IPV4_NODE;
d62a17ae 200 }
201 break;
202 case AFI_L2VPN:
203 return BGP_EVPN_NODE;
b26f891d 204 case AFI_UNSPEC:
d62a17ae 205 case AFI_MAX:
206 // We should never be here but to clarify the switch statement..
207 return BGP_IPV4_NODE;
d62a17ae 208 }
209
210 // Impossible to happen
211 return BGP_IPV4_NODE;
f51bae9c 212}
20eb8864 213
5cb5f4d0
DD
214static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
215{
7d0d37de
DS
216 if (afi == AFI_IP) {
217 if (safi == SAFI_UNICAST)
218 return "IPv4 Unicast";
219 if (safi == SAFI_MULTICAST)
220 return "IPv4 Multicast";
221 if (safi == SAFI_LABELED_UNICAST)
222 return "IPv4 Labeled Unicast";
223 if (safi == SAFI_MPLS_VPN)
224 return "IPv4 VPN";
225 if (safi == SAFI_ENCAP)
226 return "IPv4 Encap";
227 if (safi == SAFI_FLOWSPEC)
228 return "IPv4 Flowspec";
229 } else if (afi == AFI_IP6) {
230 if (safi == SAFI_UNICAST)
231 return "IPv6 Unicast";
232 if (safi == SAFI_MULTICAST)
233 return "IPv6 Multicast";
234 if (safi == SAFI_LABELED_UNICAST)
235 return "IPv6 Labeled Unicast";
236 if (safi == SAFI_MPLS_VPN)
237 return "IPv6 VPN";
238 if (safi == SAFI_ENCAP)
239 return "IPv6 Encap";
240 if (safi == SAFI_FLOWSPEC)
241 return "IPv6 Flowspec";
242 } else if (afi == AFI_L2VPN) {
243 if (safi == SAFI_EVPN)
244 return "L2VPN EVPN";
245 }
246
247 return "Unknown";
5cb5f4d0
DD
248}
249
250/*
251 * Please note that we have intentionally camelCased
252 * the return strings here. So if you want
253 * to use this function, please ensure you
254 * are doing this within json output
255 */
256static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
257{
7d0d37de
DS
258 if (afi == AFI_IP) {
259 if (safi == SAFI_UNICAST)
260 return "ipv4Unicast";
261 if (safi == SAFI_MULTICAST)
262 return "ipv4Multicast";
263 if (safi == SAFI_LABELED_UNICAST)
264 return "ipv4LabeledUnicast";
265 if (safi == SAFI_MPLS_VPN)
266 return "ipv4Vpn";
267 if (safi == SAFI_ENCAP)
268 return "ipv4Encap";
269 if (safi == SAFI_FLOWSPEC)
270 return "ipv4Flowspec";
271 } else if (afi == AFI_IP6) {
272 if (safi == SAFI_UNICAST)
273 return "ipv6Unicast";
274 if (safi == SAFI_MULTICAST)
275 return "ipv6Multicast";
276 if (safi == SAFI_LABELED_UNICAST)
277 return "ipv6LabeledUnicast";
278 if (safi == SAFI_MPLS_VPN)
279 return "ipv6Vpn";
280 if (safi == SAFI_ENCAP)
281 return "ipv6Encap";
282 if (safi == SAFI_FLOWSPEC)
283 return "ipv6Flowspec";
284 } else if (afi == AFI_L2VPN) {
285 if (safi == SAFI_EVPN)
286 return "l2VpnEvpn";
287 }
288
289 return "Unknown";
5cb5f4d0
DD
290}
291
37a87b8f
CS
292/* return string maps to afi-safi specific container names
293 * defined in bgp yang file.
294 */
295const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
296{
7d0d37de
DS
297 if (afi == AFI_IP) {
298 if (safi == SAFI_UNICAST)
299 return "ipv4-unicast";
300 if (safi == SAFI_MULTICAST)
301 return "ipv4-multicast";
302 if (safi == SAFI_LABELED_UNICAST)
303 return "ipv4-labeled-unicast";
304 if (safi == SAFI_MPLS_VPN)
305 return "l3vpn-ipv4-unicast";
306 if (safi == SAFI_FLOWSPEC)
307 return "ipv4-flowspec";
308 } else if (afi == AFI_IP6) {
309 if (safi == SAFI_UNICAST)
310 return "ipv6-unicast";
311 if (safi == SAFI_MULTICAST)
312 return "ipv6-multicast";
313 if (safi == SAFI_LABELED_UNICAST)
314 return "ipv6-labeled-unicast";
315 if (safi == SAFI_MPLS_VPN)
316 return "l3vpn-ipv6-unicast";
317 if (safi == SAFI_FLOWSPEC)
318 return "ipv6-flowspec";
319 } else if (afi == AFI_L2VPN) {
320 if (safi == SAFI_EVPN)
321 return "l2vpn-evpn";
322 }
323
324 return "Unknown";
37a87b8f
CS
325}
326
718e3744 327/* Utility function to get address family from current node. */
d62a17ae 328afi_t bgp_node_afi(struct vty *vty)
329{
330 afi_t afi;
331 switch (vty->node) {
332 case BGP_IPV6_NODE:
333 case BGP_IPV6M_NODE:
334 case BGP_IPV6L_NODE:
335 case BGP_VPNV6_NODE:
7c40bf39 336 case BGP_FLOWSPECV6_NODE:
d62a17ae 337 afi = AFI_IP6;
338 break;
339 case BGP_EVPN_NODE:
340 afi = AFI_L2VPN;
341 break;
342 default:
343 afi = AFI_IP;
344 break;
345 }
346 return afi;
718e3744 347}
348
349/* Utility function to get subsequent address family from current
350 node. */
d62a17ae 351safi_t bgp_node_safi(struct vty *vty)
352{
353 safi_t safi;
354 switch (vty->node) {
355 case BGP_VPNV4_NODE:
356 case BGP_VPNV6_NODE:
357 safi = SAFI_MPLS_VPN;
358 break;
359 case BGP_IPV4M_NODE:
360 case BGP_IPV6M_NODE:
361 safi = SAFI_MULTICAST;
362 break;
363 case BGP_EVPN_NODE:
364 safi = SAFI_EVPN;
365 break;
366 case BGP_IPV4L_NODE:
367 case BGP_IPV6L_NODE:
368 safi = SAFI_LABELED_UNICAST;
369 break;
7c40bf39 370 case BGP_FLOWSPECV4_NODE:
371 case BGP_FLOWSPECV6_NODE:
372 safi = SAFI_FLOWSPEC;
373 break;
d62a17ae 374 default:
375 safi = SAFI_UNICAST;
376 break;
377 }
378 return safi;
718e3744 379}
380
55f91488
QY
381/**
382 * Converts an AFI in string form to afi_t
383 *
384 * @param afi string, one of
385 * - "ipv4"
386 * - "ipv6"
81cf0de5 387 * - "l2vpn"
55f91488
QY
388 * @return the corresponding afi_t
389 */
d62a17ae 390afi_t bgp_vty_afi_from_str(const char *afi_str)
391{
392 afi_t afi = AFI_MAX; /* unknown */
393 if (strmatch(afi_str, "ipv4"))
394 afi = AFI_IP;
395 else if (strmatch(afi_str, "ipv6"))
396 afi = AFI_IP6;
81cf0de5
CS
397 else if (strmatch(afi_str, "l2vpn"))
398 afi = AFI_L2VPN;
d62a17ae 399 return afi;
400}
401
402int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
403 afi_t *afi)
404{
405 int ret = 0;
406 if (argv_find(argv, argc, "ipv4", index)) {
407 ret = 1;
408 if (afi)
409 *afi = AFI_IP;
410 } else if (argv_find(argv, argc, "ipv6", index)) {
411 ret = 1;
412 if (afi)
413 *afi = AFI_IP6;
8688b3e7
DS
414 } else if (argv_find(argv, argc, "l2vpn", index)) {
415 ret = 1;
416 if (afi)
417 *afi = AFI_L2VPN;
d62a17ae 418 }
419 return ret;
46f296b4
LB
420}
421
375a2e67 422/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 423safi_t bgp_vty_safi_from_str(const char *safi_str)
424{
425 safi_t safi = SAFI_MAX; /* unknown */
426 if (strmatch(safi_str, "multicast"))
427 safi = SAFI_MULTICAST;
428 else if (strmatch(safi_str, "unicast"))
429 safi = SAFI_UNICAST;
430 else if (strmatch(safi_str, "vpn"))
431 safi = SAFI_MPLS_VPN;
81cf0de5
CS
432 else if (strmatch(safi_str, "evpn"))
433 safi = SAFI_EVPN;
d62a17ae 434 else if (strmatch(safi_str, "labeled-unicast"))
435 safi = SAFI_LABELED_UNICAST;
7c40bf39 436 else if (strmatch(safi_str, "flowspec"))
437 safi = SAFI_FLOWSPEC;
d62a17ae 438 return safi;
439}
440
441int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
442 safi_t *safi)
443{
444 int ret = 0;
445 if (argv_find(argv, argc, "unicast", index)) {
446 ret = 1;
447 if (safi)
448 *safi = SAFI_UNICAST;
449 } else if (argv_find(argv, argc, "multicast", index)) {
450 ret = 1;
451 if (safi)
452 *safi = SAFI_MULTICAST;
453 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
454 ret = 1;
455 if (safi)
456 *safi = SAFI_LABELED_UNICAST;
457 } else if (argv_find(argv, argc, "vpn", index)) {
458 ret = 1;
459 if (safi)
460 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
461 } else if (argv_find(argv, argc, "evpn", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_EVPN;
7c40bf39 465 } else if (argv_find(argv, argc, "flowspec", index)) {
466 ret = 1;
467 if (safi)
468 *safi = SAFI_FLOWSPEC;
d62a17ae 469 }
470 return ret;
46f296b4
LB
471}
472
5d5393b9
DL
473int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
474 enum bgp_instance_type inst_type)
475{
476 int ret = bgp_get(bgp, as, name, inst_type);
477
478 if (ret == BGP_CREATED) {
479 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 480 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
481
482 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 483 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 484 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 485 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
486 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
487 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 488 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 489 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 490 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 491 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
492 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
493 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
494 if (DFLT_BGP_SUPPRESS_DUPLICATES)
495 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
5d5393b9
DL
496
497 ret = BGP_SUCCESS;
498 }
499 return ret;
500}
501
7eeee51e 502/*
f212a857 503 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 504 *
f212a857
DS
505 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
506 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
507 * to appropriate values for the calling function. This is to allow the
508 * calling function to make decisions appropriate for the show command
509 * that is being parsed.
510 *
511 * The show commands are generally of the form:
d62a17ae 512 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
513 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
514 *
515 * Since we use argv_find if the show command in particular doesn't have:
516 * [ip]
18c57037 517 * [<view|vrf> VIEWVRFNAME]
375a2e67 518 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
519 * The command parsing should still be ok.
520 *
521 * vty -> The vty for the command so we can output some useful data in
522 * the event of a parse error in the vrf.
523 * argv -> The command tokens
524 * argc -> How many command tokens we have
d62a17ae 525 * idx -> The current place in the command, generally should be 0 for this
526 * function
7eeee51e
DS
527 * afi -> The parsed afi if it was included in the show command, returned here
528 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 529 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 530 * use_json -> json is configured or not
7eeee51e
DS
531 *
532 * The function returns the correct location in the parse tree for the
533 * last token found.
0e37c258
DS
534 *
535 * Returns 0 for failure to parse correctly, else the idx position of where
536 * it found the last token.
7eeee51e 537 */
d62a17ae 538int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
539 struct cmd_token **argv, int argc,
540 int *idx, afi_t *afi, safi_t *safi,
9f049418 541 struct bgp **bgp, bool use_json)
d62a17ae 542{
543 char *vrf_name = NULL;
544
545 assert(afi);
546 assert(safi);
547 assert(bgp);
548
549 if (argv_find(argv, argc, "ip", idx))
550 *afi = AFI_IP;
551
9a8bdf1c 552 if (argv_find(argv, argc, "view", idx))
d62a17ae 553 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
554 else if (argv_find(argv, argc, "vrf", idx)) {
555 vrf_name = argv[*idx + 1]->arg;
556 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
557 vrf_name = NULL;
558 }
559 if (vrf_name) {
d62a17ae 560 if (strmatch(vrf_name, "all"))
561 *bgp = NULL;
562 else {
563 *bgp = bgp_lookup_by_name(vrf_name);
564 if (!*bgp) {
52e5b8c4
SP
565 if (use_json) {
566 json_object *json = NULL;
567 json = json_object_new_object();
568 json_object_string_add(
569 json, "warning",
570 "View/Vrf is unknown");
571 vty_out(vty, "%s\n",
572 json_object_to_json_string_ext(json,
573 JSON_C_TO_STRING_PRETTY));
574 json_object_free(json);
575 }
ca61fd25
DS
576 else
577 vty_out(vty, "View/Vrf %s is unknown\n",
578 vrf_name);
d62a17ae 579 *idx = 0;
580 return 0;
581 }
582 }
583 } else {
584 *bgp = bgp_get_default();
585 if (!*bgp) {
52e5b8c4
SP
586 if (use_json) {
587 json_object *json = NULL;
588 json = json_object_new_object();
589 json_object_string_add(
590 json, "warning",
591 "Default BGP instance not found");
592 vty_out(vty, "%s\n",
593 json_object_to_json_string_ext(json,
594 JSON_C_TO_STRING_PRETTY));
595 json_object_free(json);
596 }
ca61fd25
DS
597 else
598 vty_out(vty,
599 "Default BGP instance not found\n");
d62a17ae 600 *idx = 0;
601 return 0;
602 }
603 }
604
605 if (argv_find_and_parse_afi(argv, argc, idx, afi))
606 argv_find_and_parse_safi(argv, argc, idx, safi);
607
608 *idx += 1;
609 return *idx;
610}
611
f4b8ec07 612bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 613{
614 struct interface *ifp = NULL;
615
616 if (su->sa.sa_family == AF_INET)
617 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
618 else if (su->sa.sa_family == AF_INET6)
619 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
620 su->sin6.sin6_scope_id,
621 bgp->vrf_id);
622
623 if (ifp)
3dc339cd 624 return true;
d62a17ae 625
3dc339cd 626 return false;
718e3744 627}
628
718e3744 629/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
630/* This is used only for configuration, so disallow if attempted on
631 * a dynamic neighbor.
632 */
d62a17ae 633struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
634{
635 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
636 int ret;
637 union sockunion su;
638 struct peer *peer = NULL;
639 struct peer_group *group = NULL;
640
641 if (!bgp) {
642 return NULL;
643 }
644
645 ret = str2sockunion(peer_str, &su);
646 if (ret == 0) {
647 /* IP address, locate peer. */
648 peer = peer_lookup(bgp, &su);
649 } else {
650 /* Not IP, could match either peer configured on interface or a
651 * group. */
652 peer = peer_lookup_by_conf_if(bgp, peer_str);
653 if (!peer)
654 group = peer_group_lookup(bgp, peer_str);
655 }
656
657 if (peer) {
658 if (peer_dynamic_neighbor(peer)) {
659 vty_out(vty,
660 "%% Operation not allowed on a dynamic neighbor\n");
661 return NULL;
662 }
663
664 return peer;
665 }
666
667 if (group)
668 return group->conf;
669
670 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
671
672 return NULL;
673}
674
f4b8ec07
CS
675int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
676{
677 const char *str = NULL;
678
679 switch (ret) {
680 case BGP_ERR_INVALID_VALUE:
681 str = "Invalid value";
682 break;
683 case BGP_ERR_INVALID_FLAG:
684 str = "Invalid flag";
685 break;
686 case BGP_ERR_PEER_GROUP_SHUTDOWN:
687 str = "Peer-group has been shutdown. Activate the peer-group first";
688 break;
689 case BGP_ERR_PEER_FLAG_CONFLICT:
690 str = "Can't set override-capability and strict-capability-match at the same time";
691 break;
692 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
693 str = "Specify remote-as or peer-group remote AS first";
694 break;
695 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
696 str = "Cannot change the peer-group. Deconfigure first";
697 break;
698 case BGP_ERR_PEER_GROUP_MISMATCH:
699 str = "Peer is not a member of this peer-group";
700 break;
701 case BGP_ERR_PEER_FILTER_CONFLICT:
702 str = "Prefix/distribute list can not co-exist";
703 break;
704 case BGP_ERR_NOT_INTERNAL_PEER:
705 str = "Invalid command. Not an internal neighbor";
706 break;
707 case BGP_ERR_REMOVE_PRIVATE_AS:
708 str = "remove-private-AS cannot be configured for IBGP peers";
709 break;
710 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
711 str = "Local-AS allowed only for EBGP peers";
712 break;
713 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
714 str = "Cannot have local-as same as BGP AS number";
715 break;
716 case BGP_ERR_TCPSIG_FAILED:
717 str = "Error while applying TCP-Sig to session(s)";
718 break;
719 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
720 str = "ebgp-multihop and ttl-security cannot be configured together";
721 break;
722 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
723 str = "ttl-security only allowed for EBGP peers";
724 break;
725 case BGP_ERR_AS_OVERRIDE:
726 str = "as-override cannot be configured for IBGP peers";
727 break;
728 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
729 str = "Invalid limit for number of dynamic neighbors";
730 break;
731 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
732 str = "Dynamic neighbor listen range already exists";
733 break;
734 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
735 str = "Operation not allowed on a dynamic neighbor";
736 break;
737 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
738 str = "Operation not allowed on a directly connected neighbor";
739 break;
740 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 741 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
f4b8ec07
CS
742 break;
743 case BGP_ERR_GR_INVALID_CMD:
744 str = "The Graceful Restart command used is not valid at this moment.";
745 break;
746 case BGP_ERR_GR_OPERATION_FAILED:
747 str = "The Graceful Restart Operation failed due to an err.";
748 break;
f4b8ec07
CS
749 case BGP_ERR_PEER_GROUP_MEMBER:
750 str = "Peer-group member cannot override remote-as of peer-group";
751 break;
752 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
753 str = "Peer-group members must be all internal or all external";
754 break;
755 }
756 if (str) {
757 snprintf(errmsg, errmsg_len, "%s", str);
758 return -1;
759 }
760
761 return 0;
762}
763
d62a17ae 764int bgp_vty_return(struct vty *vty, int ret)
765{
766 const char *str = NULL;
767
768 switch (ret) {
769 case BGP_ERR_INVALID_VALUE:
770 str = "Invalid value";
771 break;
772 case BGP_ERR_INVALID_FLAG:
773 str = "Invalid flag";
774 break;
775 case BGP_ERR_PEER_GROUP_SHUTDOWN:
776 str = "Peer-group has been shutdown. Activate the peer-group first";
777 break;
778 case BGP_ERR_PEER_FLAG_CONFLICT:
779 str = "Can't set override-capability and strict-capability-match at the same time";
780 break;
781 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
782 str = "Specify remote-as or peer-group remote AS first";
783 break;
784 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
785 str = "Cannot change the peer-group. Deconfigure first";
786 break;
787 case BGP_ERR_PEER_GROUP_MISMATCH:
788 str = "Peer is not a member of this peer-group";
789 break;
790 case BGP_ERR_PEER_FILTER_CONFLICT:
791 str = "Prefix/distribute list can not co-exist";
792 break;
793 case BGP_ERR_NOT_INTERNAL_PEER:
794 str = "Invalid command. Not an internal neighbor";
795 break;
796 case BGP_ERR_REMOVE_PRIVATE_AS:
797 str = "remove-private-AS cannot be configured for IBGP peers";
798 break;
799 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
800 str = "Local-AS allowed only for EBGP peers";
801 break;
802 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
803 str = "Cannot have local-as same as BGP AS number";
804 break;
805 case BGP_ERR_TCPSIG_FAILED:
806 str = "Error while applying TCP-Sig to session(s)";
807 break;
808 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
809 str = "ebgp-multihop and ttl-security cannot be configured together";
810 break;
811 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
812 str = "ttl-security only allowed for EBGP peers";
813 break;
814 case BGP_ERR_AS_OVERRIDE:
815 str = "as-override cannot be configured for IBGP peers";
816 break;
817 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
818 str = "Invalid limit for number of dynamic neighbors";
819 break;
820 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
821 str = "Dynamic neighbor listen range already exists";
822 break;
823 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
824 str = "Operation not allowed on a dynamic neighbor";
825 break;
826 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
827 str = "Operation not allowed on a directly connected neighbor";
828 break;
829 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 830 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 831 break;
832 case BGP_ERR_GR_INVALID_CMD:
833 str = "The Graceful Restart command used is not valid at this moment.";
834 break;
835 case BGP_ERR_GR_OPERATION_FAILED:
836 str = "The Graceful Restart Operation failed due to an err.";
837 break;
d62a17ae 838 }
839 if (str) {
840 vty_out(vty, "%% %s\n", str);
841 return CMD_WARNING_CONFIG_FAILED;
842 }
843 return CMD_SUCCESS;
718e3744 844}
845
7aafcaca 846/* BGP clear sort. */
d62a17ae 847enum clear_sort {
848 clear_all,
849 clear_peer,
850 clear_group,
851 clear_external,
852 clear_as
7aafcaca
DS
853};
854
ff8a8a7a
CS
855static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
856 int error, char *errmsg, size_t errmsg_len)
d62a17ae 857{
858 switch (error) {
859 case BGP_ERR_AF_UNCONFIGURED:
ff8a8a7a
CS
860 snprintf(errmsg, errmsg_len,
861 "%%BGP: Enable %s address family for the neighbor %s",
862 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 863 break;
864 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
ff8a8a7a
CS
865 snprintf(
866 errmsg, errmsg_len,
867 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
d62a17ae 868 peer->host);
869 break;
870 default:
871 break;
872 }
7aafcaca
DS
873}
874
dc912615 875static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 876 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
877{
878 int ret = 0;
2adac256 879 struct peer_af *paf;
dc912615
DS
880
881 /* if afi/.safi not specified, spin thru all of them */
882 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
883 afi_t tmp_afi;
884 safi_t tmp_safi;
885
886 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
2adac256
DA
887 paf = peer_af_find(peer, tmp_afi, tmp_safi);
888 if (paf && paf->subgroup)
889 SET_FLAG(paf->subgroup->sflags,
890 SUBGRP_STATUS_FORCE_UPDATES);
891
dc912615
DS
892 if (!peer->afc[tmp_afi][tmp_safi])
893 continue;
894
895 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 896 ret = peer_clear(peer, nnode);
dc912615
DS
897 else
898 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
899 stype);
900 }
901 /* if afi specified and safi not, spin thru safis on this afi */
902 } else if (safi == SAFI_UNSPEC) {
903 safi_t tmp_safi;
904
905 for (tmp_safi = SAFI_UNICAST;
906 tmp_safi < SAFI_MAX; tmp_safi++) {
907 if (!peer->afc[afi][tmp_safi])
908 continue;
909
2adac256
DA
910 paf = peer_af_find(peer, afi, tmp_safi);
911 if (paf && paf->subgroup)
912 SET_FLAG(paf->subgroup->sflags,
913 SUBGRP_STATUS_FORCE_UPDATES);
914
dc912615 915 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 916 ret = peer_clear(peer, nnode);
dc912615
DS
917 else
918 ret = peer_clear_soft(peer, afi,
919 tmp_safi, stype);
920 }
921 /* both afi/safi specified, let the caller know if not defined */
922 } else {
923 if (!peer->afc[afi][safi])
924 return 1;
925
2adac256
DA
926 paf = peer_af_find(peer, afi, safi);
927 if (paf && paf->subgroup)
928 SET_FLAG(paf->subgroup->sflags,
929 SUBGRP_STATUS_FORCE_UPDATES);
930
dc912615 931 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 932 ret = peer_clear(peer, nnode);
dc912615
DS
933 else
934 ret = peer_clear_soft(peer, afi, safi, stype);
935 }
936
937 return ret;
938}
939
7aafcaca 940/* `clear ip bgp' functions. */
ff8a8a7a 941static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 942 enum clear_sort sort, enum bgp_clear_type stype,
ff8a8a7a 943 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 944{
dc912615 945 int ret = 0;
3ae8bfa5 946 bool found = false;
d62a17ae 947 struct peer *peer;
dc95985f 948
949 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 950
951 /* Clear all neighbors. */
952 /*
953 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
954 * nodes on the BGP instance as that may get freed if it is a
955 * doppelganger
d62a17ae 956 */
957 if (sort == clear_all) {
958 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 959
960 bgp_peer_gr_flags_update(peer);
961
36235319 962 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 963 gr_router_detected = true;
964
c368171c 965 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 966 stype);
d62a17ae 967
968 if (ret < 0)
ff8a8a7a
CS
969 bgp_clear_vty_error(peer, afi, safi, ret,
970 errmsg, errmsg_len);
dc95985f 971 }
972
36235319
QY
973 if (gr_router_detected
974 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 975 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
976 } else if (!gr_router_detected
977 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 978 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 979 }
d62a17ae 980
981 /* This is to apply read-only mode on this clear. */
982 if (stype == BGP_CLEAR_SOFT_NONE)
983 bgp->update_delay_over = 0;
984
985 return CMD_SUCCESS;
7aafcaca
DS
986 }
987
3ae8bfa5 988 /* Clear specified neighbor. */
d62a17ae 989 if (sort == clear_peer) {
990 union sockunion su;
d62a17ae 991
992 /* Make sockunion for lookup. */
993 ret = str2sockunion(arg, &su);
994 if (ret < 0) {
995 peer = peer_lookup_by_conf_if(bgp, arg);
996 if (!peer) {
997 peer = peer_lookup_by_hostname(bgp, arg);
998 if (!peer) {
ff8a8a7a
CS
999 snprintf(
1000 errmsg, errmsg_len,
1001 "Malformed address or name: %s",
d62a17ae 1002 arg);
1003 return CMD_WARNING;
1004 }
1005 }
1006 } else {
1007 peer = peer_lookup(bgp, &su);
1008 if (!peer) {
ff8a8a7a
CS
1009 snprintf(errmsg, errmsg_len,
1010 "%%BGP: Unknown neighbor - \"%s\"",
1011 arg);
d62a17ae 1012 return CMD_WARNING;
1013 }
1014 }
7aafcaca 1015
dc95985f 1016 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1017 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1018
dc912615
DS
1019 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1020
1021 /* if afi/safi not defined for this peer, let caller know */
1022 if (ret == 1)
3ae8bfa5 1023 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1024
d62a17ae 1025 if (ret < 0)
ff8a8a7a
CS
1026 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1027 errmsg_len);
7aafcaca 1028
d62a17ae 1029 return CMD_SUCCESS;
7aafcaca 1030 }
7aafcaca 1031
3ae8bfa5 1032 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1033 if (sort == clear_group) {
1034 struct peer_group *group;
7aafcaca 1035
d62a17ae 1036 group = peer_group_lookup(bgp, arg);
1037 if (!group) {
ff8a8a7a
CS
1038 snprintf(errmsg, errmsg_len,
1039 "%%BGP: No such peer-group %s", arg);
d62a17ae 1040 return CMD_WARNING;
1041 }
1042
1043 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1044 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1045
d62a17ae 1046 if (ret < 0)
ff8a8a7a
CS
1047 bgp_clear_vty_error(peer, afi, safi, ret,
1048 errmsg, errmsg_len);
3ae8bfa5
PM
1049 else
1050 found = true;
d62a17ae 1051 }
3ae8bfa5
PM
1052
1053 if (!found)
ff8a8a7a
CS
1054 snprintf(
1055 errmsg, errmsg_len,
1056 "%%BGP: No %s peer belonging to peer-group %s is configured",
5cb5f4d0 1057 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1058
d62a17ae 1059 return CMD_SUCCESS;
7aafcaca 1060 }
7aafcaca 1061
3ae8bfa5 1062 /* Clear all external (eBGP) neighbors. */
d62a17ae 1063 if (sort == clear_external) {
1064 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1065 if (peer->sort == BGP_PEER_IBGP)
1066 continue;
7aafcaca 1067
dc95985f 1068 bgp_peer_gr_flags_update(peer);
1069
36235319 1070 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1071 gr_router_detected = true;
dc95985f 1072
c368171c 1073 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1074
d62a17ae 1075 if (ret < 0)
ff8a8a7a
CS
1076 bgp_clear_vty_error(peer, afi, safi, ret,
1077 errmsg, errmsg_len);
3ae8bfa5
PM
1078 else
1079 found = true;
d62a17ae 1080 }
3ae8bfa5 1081
36235319
QY
1082 if (gr_router_detected
1083 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1084 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1085 } else if (!gr_router_detected
1086 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1087 bgp_zebra_send_capabilities(bgp, true);
1088 }
1089
3ae8bfa5 1090 if (!found)
ff8a8a7a
CS
1091 snprintf(errmsg, errmsg_len,
1092 "%%BGP: No external %s peer is configured",
1093 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1094
d62a17ae 1095 return CMD_SUCCESS;
1096 }
1097
3ae8bfa5 1098 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1099 if (sort == clear_as) {
3ae8bfa5 1100 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1101
1102 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1103 if (peer->as != as)
1104 continue;
1105
dc95985f 1106 bgp_peer_gr_flags_update(peer);
1107
36235319 1108 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1109 gr_router_detected = true;
dc95985f 1110
c368171c 1111 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1112
1113 if (ret < 0)
ff8a8a7a
CS
1114 bgp_clear_vty_error(peer, afi, safi, ret,
1115 errmsg, errmsg_len);
3ae8bfa5
PM
1116 else
1117 found = true;
d62a17ae 1118 }
3ae8bfa5 1119
36235319
QY
1120 if (gr_router_detected
1121 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1122 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1123 } else if (!gr_router_detected
1124 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1125 bgp_zebra_send_capabilities(bgp, true);
1126 }
1127
3ae8bfa5 1128 if (!found)
ff8a8a7a
CS
1129 snprintf(errmsg, errmsg_len,
1130 "%%BGP: No %s peer is configured with AS %s",
1131 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1132
d62a17ae 1133 return CMD_SUCCESS;
1134 }
1135
1136 return CMD_SUCCESS;
1137}
1138
ff8a8a7a
CS
1139static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1140 enum clear_sort sort, enum bgp_clear_type stype,
1141 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1142{
1143 struct bgp *bgp;
1144
1145 /* BGP structure lookup. */
1146 if (name) {
1147 bgp = bgp_lookup_by_name(name);
1148 if (bgp == NULL) {
ff8a8a7a
CS
1149 snprintf(errmsg, errmsg_len,
1150 "Can't find BGP instance %s", name);
d62a17ae 1151 return CMD_WARNING;
1152 }
1153 } else {
1154 bgp = bgp_get_default();
1155 if (bgp == NULL) {
ff8a8a7a
CS
1156 snprintf(errmsg, errmsg_len,
1157 "No BGP process is configured");
d62a17ae 1158 return CMD_WARNING;
1159 }
1160 }
1161
ff8a8a7a 1162 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
7aafcaca
DS
1163}
1164
1165/* clear soft inbound */
ff8a8a7a 1166int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1167{
99b3ebd3
NS
1168 afi_t afi;
1169 safi_t safi;
ff8a8a7a
CS
1170 int ret;
1171
1172 FOREACH_AFI_SAFI (afi, safi) {
1173 ret = bgp_clear_vty(name, afi, safi, clear_all,
1174 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1175 errmsg_len);
1176 if (ret != CMD_SUCCESS)
1177 return -1;
1178 }
99b3ebd3 1179
ff8a8a7a 1180 return 0;
7aafcaca
DS
1181}
1182
1183/* clear soft outbound */
ff8a8a7a 1184int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1185{
99b3ebd3
NS
1186 afi_t afi;
1187 safi_t safi;
ff8a8a7a 1188 int ret;
99b3ebd3 1189
ff8a8a7a
CS
1190 FOREACH_AFI_SAFI (afi, safi) {
1191 ret = bgp_clear_vty(name, afi, safi, clear_all,
1192 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1193 errmsg_len);
1194 if (ret != CMD_SUCCESS)
1195 return -1;
1196 }
1197
1198 return 0;
7aafcaca
DS
1199}
1200
1201
f787d7a0 1202#ifndef VTYSH_EXTRACT_PL
2e4c2296 1203#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1204#endif
1205
8029b216
AK
1206DEFUN_HIDDEN (bgp_local_mac,
1207 bgp_local_mac_cmd,
093e3f23 1208 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1209 BGP_STR
1210 "Local MAC config\n"
1211 "VxLAN Network Identifier\n"
1212 "VNI number\n"
1213 "local mac\n"
1214 "mac address\n"
1215 "mac-mobility sequence\n"
1216 "seq number\n")
1217{
1218 int rv;
1219 vni_t vni;
1220 struct ethaddr mac;
1221 struct ipaddr ip;
1222 uint32_t seq;
1223 struct bgp *bgp;
1224
1225 vni = strtoul(argv[3]->arg, NULL, 10);
1226 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1227 vty_out(vty, "%% Malformed MAC address\n");
1228 return CMD_WARNING;
1229 }
1230 memset(&ip, 0, sizeof(ip));
1231 seq = strtoul(argv[7]->arg, NULL, 10);
1232
1233 bgp = bgp_get_default();
1234 if (!bgp) {
1235 vty_out(vty, "Default BGP instance is not there\n");
1236 return CMD_WARNING;
1237 }
1238
b5e140c8
AK
1239 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1240 zero_esi);
8029b216
AK
1241 if (rv < 0) {
1242 vty_out(vty, "Internal error\n");
1243 return CMD_WARNING;
1244 }
1245
1246 return CMD_SUCCESS;
1247}
1248
1249DEFUN_HIDDEN (no_bgp_local_mac,
1250 no_bgp_local_mac_cmd,
093e3f23 1251 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1252 NO_STR
1253 BGP_STR
1254 "Local MAC config\n"
1255 "VxLAN Network Identifier\n"
1256 "VNI number\n"
1257 "local mac\n"
1258 "mac address\n")
1259{
1260 int rv;
1261 vni_t vni;
1262 struct ethaddr mac;
1263 struct ipaddr ip;
1264 struct bgp *bgp;
1265
1266 vni = strtoul(argv[4]->arg, NULL, 10);
1267 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1268 vty_out(vty, "%% Malformed MAC address\n");
1269 return CMD_WARNING;
1270 }
1271 memset(&ip, 0, sizeof(ip));
1272
1273 bgp = bgp_get_default();
1274 if (!bgp) {
1275 vty_out(vty, "Default BGP instance is not there\n");
1276 return CMD_WARNING;
1277 }
1278
ec0ab544 1279 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1280 if (rv < 0) {
1281 vty_out(vty, "Internal error\n");
1282 return CMD_WARNING;
1283 }
1284
1285 return CMD_SUCCESS;
1286}
1287
718e3744 1288DEFUN (no_synchronization,
1289 no_synchronization_cmd,
1290 "no synchronization",
1291 NO_STR
1292 "Perform IGP synchronization\n")
1293{
d62a17ae 1294 return CMD_SUCCESS;
718e3744 1295}
1296
1297DEFUN (no_auto_summary,
1298 no_auto_summary_cmd,
1299 "no auto-summary",
1300 NO_STR
1301 "Enable automatic network number summarization\n")
1302{
d62a17ae 1303 return CMD_SUCCESS;
718e3744 1304}
3d515fd9 1305
718e3744 1306/* "router bgp" commands. */
ff8a8a7a
CS
1307DEFUN_YANG_NOSH(router_bgp,
1308 router_bgp_cmd,
1309 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1310 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1311{
d62a17ae 1312 int idx_asn = 2;
1313 int idx_view_vrf = 3;
1314 int idx_vrf = 4;
ff8a8a7a 1315 int ret = CMD_SUCCESS;
d62a17ae 1316 as_t as;
1317 struct bgp *bgp;
1318 const char *name = NULL;
1319 enum bgp_instance_type inst_type;
ff8a8a7a 1320 char base_xpath[XPATH_MAXLEN];
4062b455 1321 const struct lyd_node *bgp_glb_dnode;
d62a17ae 1322
1323 // "router bgp" without an ASN
1324 if (argc == 2) {
1325 // Pending: Make VRF option available for ASN less config
4062b455
IR
1326 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1327 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
d62a17ae 1328
4062b455
IR
1329 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1330 base_xpath);
1331 if (!bgp_glb_dnode) {
d62a17ae 1332 vty_out(vty, "%% No BGP process is configured\n");
1333 return CMD_WARNING_CONFIG_FAILED;
1334 }
1335
1336 if (listcount(bm->bgp) > 1) {
996c9314 1337 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1338 return CMD_WARNING_CONFIG_FAILED;
1339 }
ff8a8a7a 1340
4062b455 1341 as = yang_dnode_get_uint32(bgp_glb_dnode, "./global/local-as");
ff8a8a7a 1342
4062b455 1343 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
ff8a8a7a 1344
4062b455
IR
1345 /*
1346 * For backward compatibility with old commands we still
1347 * need to use the qobj infrastructure.
1348 */
1349 bgp = bgp_lookup(as, NULL);
1350 if (bgp)
ff8a8a7a 1351 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
4062b455
IR
1352
1353 return CMD_SUCCESS;
d62a17ae 1354 }
1355
1356 // "router bgp X"
1357 else {
d62a17ae 1358
ff8a8a7a 1359 as = strtoul(argv[idx_asn]->arg, NULL, 10);
d62a17ae 1360 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1361 if (argc > 3) {
1362 name = argv[idx_vrf]->arg;
1363
9a8bdf1c
PG
1364 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1365 if (strmatch(name, VRF_DEFAULT_NAME))
1366 name = NULL;
1367 else
1368 inst_type = BGP_INSTANCE_TYPE_VRF;
ff8a8a7a 1369 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
d62a17ae 1370 inst_type = BGP_INSTANCE_TYPE_VIEW;
ff8a8a7a 1371 }
d62a17ae 1372 }
ff8a8a7a
CS
1373 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1374 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1375
1376 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
87ce2564 1377 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
ff8a8a7a
CS
1378 argv[idx_asn]->arg);
1379 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1380 nb_cli_enqueue_change(vty,
1381 "./global/instance-type-view",
ff8a8a7a 1382 NB_OP_MODIFY, "true");
d3e36770
IR
1383 } else {
1384 nb_cli_enqueue_change(vty,
1385 "./global/instance-type-view",
1386 NB_OP_MODIFY, "false");
d62a17ae 1387 }
1388
ff8a8a7a
CS
1389 ret = nb_cli_apply_changes(vty, base_xpath);
1390 if (ret == CMD_SUCCESS) {
1391 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
3bd70bf8 1392
ff8a8a7a
CS
1393 /*
1394 * For backward compatibility with old commands we still
1395 * need to use the qobj infrastructure.
1396 */
ea1a5c00 1397 nb_cli_pending_commit_check(vty);
ff8a8a7a
CS
1398 bgp = bgp_lookup(as, name);
1399 if (bgp)
1400 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1401 }
d62a17ae 1402 }
1403
ff8a8a7a 1404 return ret;
718e3744 1405}
1406
718e3744 1407/* "no router bgp" commands. */
ff8a8a7a
CS
1408DEFUN_YANG(no_router_bgp,
1409 no_router_bgp_cmd,
1410 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1411 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1412{
d62a17ae 1413 int idx_vrf = 5;
d62a17ae 1414 const char *name = NULL;
ff8a8a7a 1415 char base_xpath[XPATH_MAXLEN];
4b63e358 1416 const struct lyd_node *bgp_glb_dnode;
718e3744 1417
d62a17ae 1418 // "no router bgp" without an ASN
1419 if (argc == 3) {
1420 // Pending: Make VRF option available for ASN less config
4b63e358
CS
1421 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1422 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
718e3744 1423
4b63e358
CS
1424 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1425 base_xpath);
1426 if (!bgp_glb_dnode) {
d62a17ae 1427 vty_out(vty, "%% No BGP process is configured\n");
1428 return CMD_WARNING_CONFIG_FAILED;
1429 }
7fb21a9f 1430
d62a17ae 1431 if (listcount(bm->bgp) > 1) {
996c9314 1432 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1433 return CMD_WARNING_CONFIG_FAILED;
1434 }
1435 } else {
d62a17ae 1436 if (argc > 4)
1437 name = argv[idx_vrf]->arg;
45d1d7c9
IR
1438 else
1439 name = VRF_DEFAULT_NAME;
7fb21a9f 1440
45d1d7c9
IR
1441 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1442 "frr-bgp:bgp", "bgp", name);
d62a17ae 1443 }
718e3744 1444
ff8a8a7a 1445 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
718e3744 1446
ff8a8a7a 1447 return nb_cli_apply_changes(vty, base_xpath);
718e3744 1448}
1449
ff8a8a7a
CS
1450void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1451 bool show_defaults)
1452{
1453 const struct lyd_node *vrf_dnode;
1454 const char *vrf_name;
1455 as_t as;
6b0655a2 1456
ff8a8a7a
CS
1457 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1458 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
5e42cb2f 1459 as = yang_dnode_get_uint32(dnode, "./global/local-as");
718e3744 1460
ff8a8a7a
CS
1461 vty_out(vty, "!\n");
1462 vty_out(vty, "router bgp %u", as);
1463 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1464 vty_out(vty, " vrf %s", vrf_name);
1465 vty_out(vty, "\n");
718e3744 1466}
1467
ff8a8a7a
CS
1468/* BGP router-id. */
1469
1470DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1471 BGP_STR
1472 "Override configured router identifier\n"
1473 "Manually configured router identifier\n")
718e3744 1474{
87ce2564
CS
1475 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1476 router_id_str);
718e3744 1477
ff8a8a7a
CS
1478 return nb_cli_apply_changes(vty, NULL);
1479}
718e3744 1480
ff8a8a7a
CS
1481DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1482 NO_STR BGP_STR
1483 "Override configured router identifier\n"
1484 "Manually configured router identifier\n")
1485{
87ce2564 1486 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
ff8a8a7a 1487 router_id_str ? router_id_str : NULL);
718e3744 1488
ff8a8a7a 1489 return nb_cli_apply_changes(vty, NULL);
718e3744 1490}
1491
ff8a8a7a
CS
1492void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1493 bool show_defaults)
1494{
1495 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1496}
6b0655a2 1497
ed0e57e3
DA
1498DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1499 "[no$no] bgp community alias WORD$community WORD$alias",
1500 NO_STR BGP_STR
1501 "Add community specific parameters\n"
1502 "Create an alias for a community\n"
1503 "Community (AA:BB or AA:BB:CC)\n"
1504 "Alias name\n")
1505{
1506 struct community_alias ca1;
1507 struct community_alias ca2;
1508 struct community_alias *lookup_community;
1509 struct community_alias *lookup_alias;
1510
1511 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1512 vty_out(vty, "Invalid community format\n");
1513 return CMD_WARNING;
1514 }
1515
1516 memset(&ca1, 0, sizeof(ca1));
1517 memset(&ca2, 0, sizeof(ca2));
1518 strlcpy(ca1.community, community, sizeof(ca1.community));
1519 strlcpy(ca1.alias, alias, sizeof(ca1.alias));
1520
1521 lookup_community = bgp_ca_community_lookup(&ca1);
1522 lookup_alias = bgp_ca_alias_lookup(&ca1);
1523
1524 if (no) {
1525 bgp_ca_alias_delete(&ca1);
1526 bgp_ca_community_delete(&ca1);
1527 } else {
1528 if (lookup_alias) {
1529 /* Lookup if community hash table has an item
1530 * with the same alias name.
1531 */
1532 strlcpy(ca2.community, lookup_alias->community,
1533 sizeof(ca2.community));
1534 if (bgp_ca_community_lookup(&ca2)) {
1535 vty_out(vty,
1536 "community (%s) already has this alias (%s)\n",
1537 lookup_alias->community,
1538 lookup_alias->alias);
1539 return CMD_WARNING;
1540 }
1541 bgp_ca_alias_delete(&ca1);
1542 }
1543
1544 if (lookup_community)
1545 bgp_ca_community_delete(&ca1);
1546
1547 bgp_ca_alias_insert(&ca1);
1548 bgp_ca_community_insert(&ca1);
1549 }
1550
1551 return CMD_SUCCESS;
1552}
1553
9acb67cb
DS
1554DEFPY (bgp_global_suppress_fib_pending,
1555 bgp_global_suppress_fib_pending_cmd,
1556 "[no] bgp suppress-fib-pending",
1557 NO_STR
1558 BGP_STR
1559 "Advertise only routes that are programmed in kernel to peers globally\n")
1560{
1561 bm_wait_for_fib_set(!no);
1562
1563 return CMD_SUCCESS;
1564}
1565
c208c586
S
1566DEFPY (bgp_suppress_fib_pending,
1567 bgp_suppress_fib_pending_cmd,
1568 "[no] bgp suppress-fib-pending",
1569 NO_STR
1570 BGP_STR
1571 "Advertise only routes that are programmed in kernel to peers\n")
1572{
1573 VTY_DECLVAR_CONTEXT(bgp, bgp);
1574
1575 bgp_suppress_fib_pending_set(bgp, !no);
1576 return CMD_SUCCESS;
1577}
1578
1579
718e3744 1580/* BGP Cluster ID. */
ff8a8a7a
CS
1581DEFUN_YANG(bgp_cluster_id,
1582 bgp_cluster_id_cmd,
1583 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1584 BGP_STR
1585 "Configure Route-Reflector Cluster-id\n"
1586 "Route-Reflector Cluster-id in IP address format\n"
1587 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1588{
d62a17ae 1589 int idx_ipv4 = 2;
718e3744 1590
87ce2564
CS
1591 nb_cli_enqueue_change(
1592 vty, "./global/route-reflector/route-reflector-cluster-id",
1593 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1594
ff8a8a7a 1595 return nb_cli_apply_changes(vty, NULL);
718e3744 1596}
1597
ff8a8a7a
CS
1598DEFUN_YANG(no_bgp_cluster_id,
1599 no_bgp_cluster_id_cmd,
1600 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1601 NO_STR BGP_STR
1602 "Configure Route-Reflector Cluster-id\n"
1603 "Route-Reflector Cluster-id in IP address format\n"
1604 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1605{
87ce2564
CS
1606 nb_cli_enqueue_change(
1607 vty, "./global/route-reflector/route-reflector-cluster-id",
1608 NB_OP_DESTROY, NULL);
718e3744 1609
ff8a8a7a 1610 return nb_cli_apply_changes(vty, NULL);
718e3744 1611}
1612
c163f297
DS
1613DEFPY (bgp_norib,
1614 bgp_norib_cmd,
1615 "bgp no-rib",
1616 BGP_STR
1617 "Disable BGP route installation to RIB (Zebra)\n")
1618{
1619 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1620 vty_out(vty,
1621 "%% No-RIB option is already set, nothing to do here.\n");
1622 return CMD_SUCCESS;
1623 }
1624
1625 bgp_option_norib_set_runtime();
1626
1627 return CMD_SUCCESS;
1628}
1629
1630DEFPY (no_bgp_norib,
1631 no_bgp_norib_cmd,
1632 "no bgp no-rib",
1633 NO_STR
1634 BGP_STR
1635 "Disable BGP route installation to RIB (Zebra)\n")
1636{
1637 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1638 vty_out(vty,
1639 "%% No-RIB option is not set, nothing to do here.\n");
1640 return CMD_SUCCESS;
1641 }
1642
1643 bgp_option_norib_unset_runtime();
1644
1645 return CMD_SUCCESS;
1646}
1647
e46723a5
DS
1648DEFPY (no_bgp_send_extra_data,
1649 no_bgp_send_extra_data_cmd,
1650 "[no] bgp send-extra-data zebra",
1651 NO_STR
1652 BGP_STR
1653 "Extra data to Zebra for display/use\n"
1654 "To zebra\n")
1655{
ec0acb80
DA
1656 if (no)
1657 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1658 else
1659 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1660
1661 return CMD_SUCCESS;
1662}
1663
ff8a8a7a
CS
1664DEFUN_YANG(bgp_confederation_identifier,
1665 bgp_confederation_identifier_cmd,
1666 "bgp confederation identifier (1-4294967295)",
1667 "BGP specific commands\n"
1668 "AS confederation parameters\n"
1669 "AS number\n"
1670 "Set routing domain confederation AS\n")
718e3744 1671{
d62a17ae 1672 int idx_number = 3;
718e3744 1673
87ce2564
CS
1674 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1675 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1676
ff8a8a7a 1677 return nb_cli_apply_changes(vty, NULL);
718e3744 1678}
1679
ff8a8a7a
CS
1680DEFUN_YANG(no_bgp_confederation_identifier,
1681 no_bgp_confederation_identifier_cmd,
1682 "no bgp confederation identifier [(1-4294967295)]",
1683 NO_STR
1684 "BGP specific commands\n"
1685 "AS confederation parameters\n"
1686 "AS number\n"
1687 "Set routing domain confederation AS\n")
718e3744 1688{
87ce2564
CS
1689 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1690 NB_OP_DESTROY, NULL);
718e3744 1691
ff8a8a7a 1692 return nb_cli_apply_changes(vty, NULL);
718e3744 1693}
1694
ff8a8a7a
CS
1695void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1696 struct lyd_node *dnode,
1697 bool show_defaults)
1698{
1699 vty_out(vty, " bgp confederation identifier %u\n",
1700 yang_dnode_get_uint32(dnode, NULL));
1701}
1702
1703DEFUN_YANG(bgp_confederation_peers,
1704 bgp_confederation_peers_cmd,
1705 "bgp confederation peers (1-4294967295)...",
1706 "BGP specific commands\n"
1707 "AS confederation parameters\n"
1708 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1709{
d62a17ae 1710 int idx_asn = 3;
d62a17ae 1711 int i;
718e3744 1712
ff8a8a7a 1713 for (i = idx_asn; i < argc; i++)
87ce2564 1714 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1715 NB_OP_CREATE, argv[i]->arg);
718e3744 1716
ff8a8a7a 1717 return nb_cli_apply_changes(vty, NULL);
718e3744 1718}
1719
ff8a8a7a
CS
1720DEFUN_YANG(no_bgp_confederation_peers,
1721 no_bgp_confederation_peers_cmd,
1722 "no bgp confederation peers (1-4294967295)...",
1723 NO_STR
1724 "BGP specific commands\n"
1725 "AS confederation parameters\n"
1726 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1727{
d62a17ae 1728 int idx_asn = 4;
d62a17ae 1729 int i;
718e3744 1730
ff8a8a7a 1731 for (i = idx_asn; i < argc; i++)
87ce2564 1732 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1733 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1734
ff8a8a7a
CS
1735 return nb_cli_apply_changes(vty, NULL);
1736}
1737
1738void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1739 struct lyd_node *dnode,
1740 bool show_defaults)
1741{
1742 vty_out(vty, " bgp confederation peers %u \n",
1743 yang_dnode_get_uint32(dnode, NULL));
718e3744 1744}
6b0655a2 1745
5e242b0d
DS
1746/**
1747 * Central routine for maximum-paths configuration.
1748 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1749 * @set: 1 for setting values, 0 for removing the max-paths config.
1750 */
37a87b8f
CS
1751int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1752 int peer_type, uint16_t maxpaths, uint16_t options,
1753 int set, char *errmsg, size_t errmsg_len)
d62a17ae 1754{
d62a17ae 1755 int ret;
d62a17ae 1756
1757 if (set) {
d62a17ae 1758 if (maxpaths > multipath_num) {
37a87b8f
CS
1759 snprintf(
1760 errmsg, errmsg_len,
d62a17ae 1761 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1762 maxpaths, multipath_num);
1763 return CMD_WARNING_CONFIG_FAILED;
1764 }
1765 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1766 options);
1767 } else
1768 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1769
1770 if (ret < 0) {
37a87b8f
CS
1771 snprintf(
1772 errmsg, errmsg_len,
d62a17ae 1773 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1774 (set == 1) ? "" : "un",
1775 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1776 maxpaths, afi, safi);
1777 return CMD_WARNING_CONFIG_FAILED;
1778 }
1779
1780 bgp_recalculate_all_bestpaths(bgp);
1781
1782 return CMD_SUCCESS;
165b5fff
JB
1783}
1784
ff8a8a7a
CS
1785void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1786 bool show_defaults)
abc920f8 1787{
ff8a8a7a
CS
1788 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1789 uint32_t med_admin_val;
abc920f8 1790
ff8a8a7a
CS
1791 vty_out(vty, " bgp max-med administrative");
1792 if ((med_admin_val =
1793 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1794 != BGP_MAXMED_VALUE_DEFAULT)
1795 vty_out(vty, " %u", med_admin_val);
1796 vty_out(vty, "\n");
1797 }
abc920f8 1798
ff8a8a7a
CS
1799 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1800 uint32_t onstartup_val;
abc920f8 1801
ff8a8a7a
CS
1802 vty_out(vty, " bgp max-med on-startup %u",
1803 yang_dnode_get_uint32(dnode,
1804 "./max-med-onstart-up-time"));
1805 onstartup_val = yang_dnode_get_uint32(
1806 dnode, "./max-med-onstart-up-value");
1807 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1808 vty_out(vty, " %u", onstartup_val);
1809
1810 vty_out(vty, "\n");
1811 }
abc920f8
DS
1812}
1813
ff8a8a7a
CS
1814DEFUN_YANG(bgp_maxmed_admin,
1815 bgp_maxmed_admin_cmd,
1816 "bgp max-med administrative ",
1817 BGP_STR
1818 "Advertise routes with max-med\n"
1819 "Administratively applied, for an indefinite period\n")
1820{
87ce2564 1821 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1822 NB_OP_MODIFY, "true");
1823
1824 return nb_cli_apply_changes(vty, NULL);
1825}
1826
1827DEFUN_YANG(bgp_maxmed_admin_medv,
1828 bgp_maxmed_admin_medv_cmd,
1829 "bgp max-med administrative (0-4294967295)",
1830 BGP_STR
1831 "Advertise routes with max-med\n"
1832 "Administratively applied, for an indefinite period\n"
1833 "Max MED value to be used\n")
abc920f8 1834{
d62a17ae 1835 int idx_number = 3;
abc920f8 1836
87ce2564 1837 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1838 NB_OP_MODIFY, "true");
abc920f8 1839
87ce2564
CS
1840 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1841 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1842
ff8a8a7a 1843 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1844}
1845
ff8a8a7a
CS
1846DEFUN_YANG(no_bgp_maxmed_admin,
1847 no_bgp_maxmed_admin_cmd,
1848 "no bgp max-med administrative [(0-4294967295)]",
1849 NO_STR BGP_STR
1850 "Advertise routes with max-med\n"
1851 "Administratively applied, for an indefinite period\n"
1852 "Max MED value to be used\n")
abc920f8 1853{
87ce2564 1854 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1855 NB_OP_MODIFY, "false");
abc920f8 1856
87ce2564
CS
1857 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1858 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1859
1860 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1861}
1862
37a87b8f
CS
1863DEFUN_YANG (bgp_maxmed_onstartup,
1864 bgp_maxmed_onstartup_cmd,
1865 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1866 BGP_STR
1867 "Advertise routes with max-med\n"
1868 "Effective on a startup\n"
1869 "Time (seconds) period for max-med\n"
1870 "Max MED value to be used\n")
abc920f8 1871{
d62a17ae 1872 int idx = 0;
4668a151 1873
d62a17ae 1874 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1875 nb_cli_enqueue_change(vty,
1876 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1877 NB_OP_MODIFY, argv[idx]->arg);
1878
d62a17ae 1879 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1880 nb_cli_enqueue_change(
1881 vty, "./global/med-config/max-med-onstart-up-value",
1882 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1883 else
87ce2564
CS
1884 nb_cli_enqueue_change(
1885 vty, "./global/med-config/max-med-onstart-up-value",
1886 NB_OP_MODIFY, NULL);
abc920f8 1887
ff8a8a7a 1888 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1889}
1890
37a87b8f
CS
1891DEFUN_YANG (no_bgp_maxmed_onstartup,
1892 no_bgp_maxmed_onstartup_cmd,
1893 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1894 NO_STR BGP_STR
1895 "Advertise routes with max-med\n"
1896 "Effective on a startup\n"
1897 "Time (seconds) period for max-med\n"
1898 "Max MED value to be used\n")
abc920f8 1899{
87ce2564
CS
1900 nb_cli_enqueue_change(vty,
1901 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1902 NB_OP_DESTROY, NULL);
abc920f8 1903
87ce2564
CS
1904 nb_cli_enqueue_change(vty,
1905 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1906 NB_OP_MODIFY, NULL);
abc920f8 1907
ff8a8a7a 1908 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1909}
1910
d70583f7
D
1911static int bgp_global_update_delay_config_vty(struct vty *vty,
1912 uint16_t update_delay,
1913 uint16_t establish_wait)
1914{
1915 struct listnode *node, *nnode;
1916 struct bgp *bgp;
1917 bool vrf_cfg = false;
1918
1919 /*
1920 * See if update-delay is set per-vrf and warn user to delete it
1921 * Note that we only need to check this if this is the first time
1922 * setting the global config.
1923 */
1924 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1925 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1926 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1927 vty_out(vty,
1928 "%% update-delay configuration found in vrf %s\n",
1929 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1930 ? VRF_DEFAULT_NAME
1931 : bgp->name);
1932 vrf_cfg = true;
1933 }
1934 }
1935 }
1936
1937 if (vrf_cfg) {
1938 vty_out(vty,
1939 "%%Failed: global update-delay config not permitted\n");
1940 return CMD_WARNING;
1941 }
1942
1943 if (!establish_wait) { /* update-delay <delay> */
1944 bm->v_update_delay = update_delay;
1945 bm->v_establish_wait = bm->v_update_delay;
1946 } else {
1947 /* update-delay <delay> <establish-wait> */
1948 if (update_delay < establish_wait) {
1949 vty_out(vty,
1950 "%%Failed: update-delay less than the establish-wait!\n");
1951 return CMD_WARNING_CONFIG_FAILED;
1952 }
1953
1954 bm->v_update_delay = update_delay;
1955 bm->v_establish_wait = establish_wait;
1956 }
1957
1958 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1959 bgp->v_update_delay = bm->v_update_delay;
1960 bgp->v_establish_wait = bm->v_establish_wait;
1961 }
1962
1963 return CMD_SUCCESS;
1964}
1965
1966static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1967{
1968 struct listnode *node, *nnode;
1969 struct bgp *bgp;
1970
1971 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1972 bm->v_establish_wait = bm->v_update_delay;
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_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1983 uint16_t establish_wait)
f188f2c4 1984{
d62a17ae 1985 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1986
d70583f7
D
1987 /* if configured globally, per-instance config is not allowed */
1988 if (bm->v_update_delay) {
1989 vty_out(vty,
1990 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1991 return CMD_WARNING_CONFIG_FAILED;
1992 }
1993
f188f2c4 1994
d70583f7 1995 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1996 {
1997 bgp->v_update_delay = update_delay;
1998 bgp->v_establish_wait = bgp->v_update_delay;
1999 return CMD_SUCCESS;
2000 }
f188f2c4 2001
d62a17ae 2002 /* update-delay <delay> <establish-wait> */
d62a17ae 2003 if (update_delay < establish_wait) {
2004 vty_out(vty,
2005 "%%Failed: update-delay less than the establish-wait!\n");
2006 return CMD_WARNING_CONFIG_FAILED;
2007 }
f188f2c4 2008
d62a17ae 2009 bgp->v_update_delay = update_delay;
2010 bgp->v_establish_wait = establish_wait;
f188f2c4 2011
d62a17ae 2012 return CMD_SUCCESS;
f188f2c4
DS
2013}
2014
d62a17ae 2015static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2016{
d62a17ae 2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2018
d70583f7
D
2019 /* If configured globally, cannot remove from one bgp instance */
2020 if (bm->v_update_delay) {
2021 vty_out(vty,
2022 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2023 return CMD_WARNING_CONFIG_FAILED;
2024 }
d62a17ae 2025 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2026 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2027
d62a17ae 2028 return CMD_SUCCESS;
f188f2c4
DS
2029}
2030
2b791107 2031void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2032{
d70583f7
D
2033 /* If configured globally, no need to display per-instance value */
2034 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2035 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2036 if (bgp->v_update_delay != bgp->v_establish_wait)
2037 vty_out(vty, " %d", bgp->v_establish_wait);
2038 vty_out(vty, "\n");
2039 }
f188f2c4
DS
2040}
2041
d70583f7
D
2042/* Global update-delay configuration */
2043DEFPY (bgp_global_update_delay,
2044 bgp_global_update_delay_cmd,
2045 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2046 BGP_STR
2047 "Force initial delay for best-path and updates for all bgp instances\n"
2048 "Max delay in seconds\n"
2049 "Establish wait in seconds\n")
2050{
2051 return bgp_global_update_delay_config_vty(vty, delay, wait);
2052}
f188f2c4 2053
d70583f7
D
2054/* Global update-delay deconfiguration */
2055DEFPY (no_bgp_global_update_delay,
2056 no_bgp_global_update_delay_cmd,
2057 "no bgp update-delay [(0-3600) [(1-3600)]]",
2058 NO_STR
2059 BGP_STR
f188f2c4 2060 "Force initial delay for best-path and updates\n"
d70583f7
D
2061 "Max delay in seconds\n"
2062 "Establish wait in seconds\n")
f188f2c4 2063{
d70583f7 2064 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2065}
2066
d70583f7
D
2067/* Update-delay configuration */
2068
2069DEFPY (bgp_update_delay,
2070 bgp_update_delay_cmd,
2071 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2072 "Force initial delay for best-path and updates\n"
d70583f7
D
2073 "Max delay in seconds\n"
2074 "Establish wait in seconds\n")
f188f2c4 2075{
d70583f7 2076 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2077}
2078
2079/* Update-delay deconfiguration */
d70583f7 2080DEFPY (no_bgp_update_delay,
f188f2c4 2081 no_bgp_update_delay_cmd,
838758ac
DW
2082 "no update-delay [(0-3600) [(1-3600)]]",
2083 NO_STR
f188f2c4 2084 "Force initial delay for best-path and updates\n"
d70583f7
D
2085 "Max delay in seconds\n"
2086 "Establish wait in seconds\n")
f188f2c4 2087{
d62a17ae 2088 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2089}
2090
5e242b0d 2091
ff8a8a7a 2092int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 2093{
8fa7732f
QY
2094 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2095 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2096
2097 return CMD_SUCCESS;
2098}
2099
ff8a8a7a 2100int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 2101{
8fa7732f
QY
2102 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2103 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2104
d62a17ae 2105 return CMD_SUCCESS;
cb1faec9
DS
2106}
2107
2b791107 2108void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2109{
555e09d4
QY
2110 uint32_t quanta =
2111 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2112 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2113 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2114}
2115
555e09d4
QY
2116void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2117{
2118 uint32_t quanta =
2119 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2120 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2121 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2122}
cb1faec9 2123
8fa7732f
QY
2124/* Packet quanta configuration
2125 *
2126 * XXX: The value set here controls the size of a stack buffer in the IO
2127 * thread. When changing these limits be careful to prevent stack overflow.
2128 *
2129 * Furthermore, the maximums used here should correspond to
2130 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2131 */
37a87b8f
CS
2132DEFPY_YANG (bgp_wpkt_quanta,
2133 bgp_wpkt_quanta_cmd,
2134 "[no] write-quanta (1-64)$quanta",
2135 NO_STR
2136 "How many packets to write to peer socket per run\n"
2137 "Number of packets\n")
ff8a8a7a
CS
2138{
2139 if (!no)
2140 nb_cli_enqueue_change(
2141 vty,
87ce2564 2142 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2143 NB_OP_MODIFY, quanta_str);
2144 else
2145 nb_cli_enqueue_change(
2146 vty,
87ce2564 2147 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2148 NB_OP_MODIFY, NULL);
2149
2150 return nb_cli_apply_changes(vty, NULL);
2151}
2152
37a87b8f
CS
2153DEFPY_YANG (bgp_rpkt_quanta,
2154 bgp_rpkt_quanta_cmd,
2155 "[no] read-quanta (1-10)$quanta",
2156 NO_STR
2157 "How many packets to read from peer socket per I/O cycle\n"
2158 "Number of packets\n")
ff8a8a7a
CS
2159{
2160 if (!no)
2161 nb_cli_enqueue_change(
2162 vty,
87ce2564 2163 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2164 NB_OP_MODIFY, quanta_str);
2165 else
2166 nb_cli_enqueue_change(
2167 vty,
87ce2564 2168 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2169 NB_OP_MODIFY, NULL);
cb1faec9 2170
ff8a8a7a 2171 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2172}
2173
2b791107 2174void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2175{
37a333fe 2176 if (!bgp->heuristic_coalesce)
d62a17ae 2177 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2178}
2179
ff8a8a7a
CS
2180void cli_show_router_global_update_group_config_coalesce_time(
2181 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2182{
ff8a8a7a
CS
2183 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2184}
2185
4668a151 2186
37a87b8f
CS
2187DEFUN_YANG (bgp_coalesce_time,
2188 bgp_coalesce_time_cmd,
2189 "coalesce-time (0-4294967295)",
2190 "Subgroup coalesce timer\n"
2191 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2192{
d62a17ae 2193 int idx = 0;
ff8a8a7a 2194
d62a17ae 2195 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2196 nb_cli_enqueue_change(
2197 vty, "./global/global-update-group-config/coalesce-time",
2198 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2199
2200 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2201}
2202
ff8a8a7a
CS
2203DEFUN_YANG(no_bgp_coalesce_time,
2204 no_bgp_coalesce_time_cmd,
2205 "no coalesce-time (0-4294967295)",
2206 NO_STR
2207 "Subgroup coalesce timer\n"
2208 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2209{
87ce2564
CS
2210 nb_cli_enqueue_change(
2211 vty, "./global/global-update-group-config/coalesce-time",
2212 NB_OP_MODIFY, NULL);
4668a151 2213
ff8a8a7a 2214 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2215}
2216
5e242b0d 2217/* Maximum-paths configuration */
37a87b8f
CS
2218DEFUN_YANG (bgp_maxpaths,
2219 bgp_maxpaths_cmd,
2220 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2221 "Forward packets over multiple paths\n"
2222 "Number of paths\n")
5e242b0d 2223{
d62a17ae 2224 int idx_number = 1;
37a87b8f
CS
2225 char base_xpath[XPATH_MAXLEN];
2226 afi_t afi;
2227 safi_t safi;
2228
2229 afi = bgp_node_afi(vty);
2230 safi = bgp_node_safi(vty);
2231
2232 snprintf(
2233 base_xpath, sizeof(base_xpath),
2234 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2235 yang_afi_safi_value2identity(afi, safi),
2236 bgp_afi_safi_get_container_str(afi, safi));
2237
2238 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2239 argv[idx_number]->arg);
2240
2241 return nb_cli_apply_changes(vty, NULL);
2242}
2243
2244void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2245 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2246{
2247 vty_out(vty, " maximum-paths %d\n",
2248 yang_dnode_get_uint16(dnode, NULL));
5e242b0d
DS
2249}
2250
d62a17ae 2251ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2252 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2253 "Forward packets over multiple paths\n"
2254 "Number of paths\n")
596c17ba 2255
37a87b8f
CS
2256DEFUN_YANG (bgp_maxpaths_ibgp,
2257 bgp_maxpaths_ibgp_cmd,
2258 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2259 "Forward packets over multiple paths\n"
2260 "iBGP-multipath\n"
2261 "Number of paths\n")
165b5fff 2262{
d62a17ae 2263 int idx_number = 2;
37a87b8f
CS
2264 char base_xpath[XPATH_MAXLEN];
2265 afi_t afi;
2266 safi_t safi;
2267
2268 afi = bgp_node_afi(vty);
2269 safi = bgp_node_safi(vty);
2270
2271 snprintf(
2272 base_xpath, sizeof(base_xpath),
2273 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2274 yang_afi_safi_value2identity(afi, safi),
2275 bgp_afi_safi_get_container_str(afi, safi));
2276
2277 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2278 argv[idx_number]->arg);
2279
2280 return nb_cli_apply_changes(vty, NULL);
5e242b0d 2281}
165b5fff 2282
d62a17ae 2283ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2284 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2285 "Forward packets over multiple paths\n"
2286 "iBGP-multipath\n"
2287 "Number of paths\n")
596c17ba 2288
37a87b8f
CS
2289DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2290 bgp_maxpaths_ibgp_cluster_cmd,
2291 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2292 "Forward packets over multiple paths\n"
2293 "iBGP-multipath\n"
2294 "Number of paths\n"
2295 "Match the cluster length\n")
5e242b0d 2296{
d62a17ae 2297 int idx_number = 2;
37a87b8f
CS
2298 char base_xpath[XPATH_MAXLEN];
2299 afi_t afi;
2300 safi_t safi;
2301
2302 afi = bgp_node_afi(vty);
2303 safi = bgp_node_safi(vty);
2304
2305 snprintf(
2306 base_xpath, sizeof(base_xpath),
2307 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2308 yang_afi_safi_value2identity(afi, safi),
2309 bgp_afi_safi_get_container_str(afi, safi));
2310
2311 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2312 argv[idx_number]->arg);
2313
2314 snprintf(
2315 base_xpath, sizeof(base_xpath),
2316 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2317 yang_afi_safi_value2identity(afi, safi),
2318 bgp_afi_safi_get_container_str(afi, safi));
2319
2320 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2321
2322 return nb_cli_apply_changes(vty, NULL);
2323}
2324
2325void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2326 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2327{
2328 vty_out(vty, " maximum-paths ibgp %d",
2329 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2330 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2331 vty_out(vty, " equal-cluster-length");
2332 vty_out(vty, "\n");
165b5fff
JB
2333}
2334
d62a17ae 2335ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2336 "maximum-paths ibgp " CMD_RANGE_STR(
2337 1, MULTIPATH_NUM) " equal-cluster-length",
2338 "Forward packets over multiple paths\n"
2339 "iBGP-multipath\n"
2340 "Number of paths\n"
2341 "Match the cluster length\n")
596c17ba 2342
37a87b8f
CS
2343DEFUN_YANG (no_bgp_maxpaths,
2344 no_bgp_maxpaths_cmd,
2345 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2346 NO_STR
2347 "Forward packets over multiple paths\n"
2348 "Number of paths\n")
165b5fff 2349{
37a87b8f
CS
2350 char base_xpath[XPATH_MAXLEN];
2351 afi_t afi;
2352 safi_t safi;
2353
2354 afi = bgp_node_afi(vty);
2355 safi = bgp_node_safi(vty);
2356
2357 snprintf(
2358 base_xpath, sizeof(base_xpath),
2359 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2360 yang_afi_safi_value2identity(afi, safi),
2361 bgp_afi_safi_get_container_str(afi, safi));
2362
2363 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2364
2365 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2366}
2367
d62a17ae 2368ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2369 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2370 "Forward packets over multiple paths\n"
2371 "Number of paths\n")
596c17ba 2372
37a87b8f
CS
2373DEFUN_YANG (no_bgp_maxpaths_ibgp,
2374 no_bgp_maxpaths_ibgp_cmd,
2375 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2376 NO_STR
2377 "Forward packets over multiple paths\n"
2378 "iBGP-multipath\n"
2379 "Number of paths\n"
2380 "Match the cluster length\n")
165b5fff 2381{
37a87b8f
CS
2382 char base_xpath[XPATH_MAXLEN];
2383 afi_t afi;
2384 safi_t safi;
2385
2386 afi = bgp_node_afi(vty);
2387 safi = bgp_node_safi(vty);
2388
2389 snprintf(
2390 base_xpath, sizeof(base_xpath),
2391 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2392 yang_afi_safi_value2identity(afi, safi),
2393 bgp_afi_safi_get_container_str(afi, safi));
2394
2395 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2396
2397 snprintf(
2398 base_xpath, sizeof(base_xpath),
2399 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2400 yang_afi_safi_value2identity(afi, safi),
2401 bgp_afi_safi_get_container_str(afi, safi));
2402
2403 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2404
2405 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2406}
2407
d62a17ae 2408ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2409 "no maximum-paths ibgp [" CMD_RANGE_STR(
2410 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2411 NO_STR
2412 "Forward packets over multiple paths\n"
2413 "iBGP-multipath\n"
2414 "Number of paths\n"
2415 "Match the cluster length\n")
596c17ba 2416
dd65f45e
DL
2417static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2418 afi_t afi, safi_t safi)
165b5fff 2419{
00908b7a 2420 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2421 vty_out(vty, " maximum-paths %d\n",
2422 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2423 }
165b5fff 2424
00908b7a 2425 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2426 vty_out(vty, " maximum-paths ibgp %d",
2427 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2428 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2429 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2430 vty_out(vty, " equal-cluster-length");
2431 vty_out(vty, "\n");
2432 }
165b5fff 2433}
6b0655a2 2434
718e3744 2435/* BGP timers. */
2436
37a87b8f
CS
2437DEFUN_YANG (bgp_timers,
2438 bgp_timers_cmd,
2439 "timers bgp (0-65535) (0-65535)",
2440 "Adjust routing timers\n"
2441 "BGP timers\n"
2442 "Keepalive interval\n"
2443 "Holdtime\n")
718e3744 2444{
d62a17ae 2445 int idx_number = 2;
2446 int idx_number_2 = 3;
718e3744 2447
87ce2564 2448 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2449 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2450 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2451 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2452
ff8a8a7a
CS
2453 return nb_cli_apply_changes(vty, NULL);
2454}
718e3744 2455
37a87b8f
CS
2456DEFUN_YANG (no_bgp_timers,
2457 no_bgp_timers_cmd,
2458 "no timers bgp [(0-65535) (0-65535)]",
2459 NO_STR
2460 "Adjust routing timers\n"
2461 "BGP timers\n"
2462 "Keepalive interval\n"
2463 "Holdtime\n")
ff8a8a7a 2464{
87ce2564 2465 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2466 NB_OP_DESTROY, NULL);
87ce2564 2467 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2468 NB_OP_DESTROY, NULL);
718e3744 2469
ff8a8a7a 2470 return nb_cli_apply_changes(vty, NULL);
718e3744 2471}
2472
ff8a8a7a
CS
2473void cli_show_router_bgp_route_reflector(struct vty *vty,
2474 struct lyd_node *dnode,
2475 bool show_defaults)
718e3744 2476{
ff8a8a7a
CS
2477 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2478 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2479
ff8a8a7a
CS
2480 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2481 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2482
2483 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2484 vty_out(vty, " bgp cluster-id %s\n",
2485 yang_dnode_get_string(dnode,
2486 "./route-reflector-cluster-id"));
718e3744 2487}
2488
ff8a8a7a
CS
2489DEFUN_YANG(bgp_client_to_client_reflection,
2490 bgp_client_to_client_reflection_cmd,
2491 "bgp client-to-client reflection",
2492 "BGP specific commands\n"
2493 "Configure client to client route reflection\n"
2494 "reflection of routes allowed\n")
2495{
87ce2564 2496 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2497 NB_OP_MODIFY, "false");
6b0655a2 2498
ff8a8a7a
CS
2499 return nb_cli_apply_changes(vty, NULL);
2500}
2501
2502DEFUN_YANG(no_bgp_client_to_client_reflection,
2503 no_bgp_client_to_client_reflection_cmd,
2504 "no bgp client-to-client reflection",
2505 NO_STR
2506 "BGP specific commands\n"
2507 "Configure client to client route reflection\n"
2508 "reflection of routes allowed\n")
718e3744 2509{
87ce2564 2510 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2511 NB_OP_MODIFY, "true");
7aafcaca 2512
ff8a8a7a 2513 return nb_cli_apply_changes(vty, NULL);
718e3744 2514}
2515
ff8a8a7a
CS
2516void cli_show_router_bgp_route_selection(struct vty *vty,
2517 struct lyd_node *dnode,
2518 bool show_defaults)
718e3744 2519{
7aafcaca 2520
ff8a8a7a
CS
2521 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2522 vty_out(vty, " bgp always-compare-med\n");
2523
2524 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2525 vty_out(vty, " bgp bestpath as-path ignore\n");
2526
2527 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2528 vty_out(vty, " bgp bestpath as-path confed\n");
2529
2530 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2531 vty_out(vty, " bgp bestpath compare-routerid\n");
2532
2533 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2534 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2535 vty_out(vty,
2536 " bgp bestpath as-path multipath-relax as-set\n");
2537 else
2538 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2539 }
2540
2541 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2542 vty_out(vty, " bgp deterministic-med\n");
2543
2544 if (yang_dnode_get_bool(dnode, "./confed-med")
2545 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2546 vty_out(vty, " bgp bestpath med");
2547 if (yang_dnode_get_bool(dnode, "./confed-med"))
2548 vty_out(vty, " confed");
2549 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2550 vty_out(vty, " missing-as-worst");
2551 vty_out(vty, "\n");
2552 }
718e3744 2553}
2554
2555/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2556DEFUN_YANG(bgp_always_compare_med,
2557 bgp_always_compare_med_cmd,
2558 "bgp always-compare-med",
2559 "BGP specific commands\n"
2560 "Allow comparing MED from different neighbors\n")
718e3744 2561{
87ce2564
CS
2562 nb_cli_enqueue_change(
2563 vty, "./global/route-selection-options/always-compare-med",
2564 NB_OP_MODIFY, "true");
7aafcaca 2565
ff8a8a7a 2566 return nb_cli_apply_changes(vty, NULL);
718e3744 2567}
2568
ff8a8a7a
CS
2569DEFUN_YANG(no_bgp_always_compare_med,
2570 no_bgp_always_compare_med_cmd,
2571 "no bgp always-compare-med",
2572 NO_STR
2573 "BGP specific commands\n"
2574 "Allow comparing MED from different neighbors\n")
718e3744 2575{
87ce2564
CS
2576 nb_cli_enqueue_change(
2577 vty, "./global/route-selection-options/always-compare-med",
2578 NB_OP_MODIFY, "false");
7aafcaca 2579
ff8a8a7a 2580 return nb_cli_apply_changes(vty, NULL);
718e3744 2581}
6b0655a2 2582
2adac256
DA
2583DEFUN_YANG(bgp_suppress_duplicates,
2584 bgp_suppress_duplicates_cmd,
2585 "bgp suppress-duplicates",
2586 "BGP specific commands\n"
2587 "Suppress duplicate updates if the route actually not changed\n")
2588{
2589 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2590 NB_OP_MODIFY, "true");
2591 return nb_cli_apply_changes(vty, NULL);
2592}
2593
2594DEFUN_YANG(no_bgp_suppress_duplicates,
2595 no_bgp_suppress_duplicates_cmd,
2596 "no bgp suppress-duplicates",
2597 NO_STR
2598 "BGP specific commands\n"
2599 "Suppress duplicate updates if the route actually not changed\n")
2600{
2601 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2602 NB_OP_MODIFY, "false");
2603 return nb_cli_apply_changes(vty, NULL);
2604}
2605
2606void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2607 struct lyd_node *dnode,
2608 bool show_defaults)
2609{
2610 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2611 vty_out(vty, " bgp suppress-duplicates\n");
2612}
2613
ff8a8a7a
CS
2614DEFUN_YANG(bgp_ebgp_requires_policy,
2615 bgp_ebgp_requires_policy_cmd,
2616 "bgp ebgp-requires-policy",
2617 "BGP specific commands\n"
2618 "Require in and out policy for eBGP peers (RFC8212)\n")
2619{
87ce2564
CS
2620 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2621 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2622 return nb_cli_apply_changes(vty, NULL);
2623}
9dac9fc8 2624
ff8a8a7a
CS
2625DEFUN_YANG(no_bgp_ebgp_requires_policy,
2626 no_bgp_ebgp_requires_policy_cmd,
2627 "no bgp ebgp-requires-policy",
2628 NO_STR
2629 "BGP specific commands\n"
2630 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2631{
87ce2564
CS
2632 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2633 NB_OP_MODIFY, "false");
ff8a8a7a 2634 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2635}
2636
ff8a8a7a
CS
2637void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2638 struct lyd_node *dnode,
2639 bool show_defaults)
9dac9fc8 2640{
ff8a8a7a
CS
2641 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2642 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2643}
2644
fb29348a
DA
2645DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2646 "bgp reject-as-sets",
2647 "BGP specific commands\n"
2648 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2649{
2650 VTY_DECLVAR_CONTEXT(bgp, bgp);
2651 struct listnode *node, *nnode;
2652 struct peer *peer;
2653
7f972cd8 2654 bgp->reject_as_sets = true;
fb29348a
DA
2655
2656 /* Reset existing BGP sessions to reject routes
2657 * with aspath containing AS_SET or AS_CONFED_SET.
2658 */
2659 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2660 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2661 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2662 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2663 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2664 }
2665 }
2666
2667 return CMD_SUCCESS;
2668}
2669
2670DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2671 "no bgp reject-as-sets",
2672 NO_STR
2673 "BGP specific commands\n"
2674 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2675{
2676 VTY_DECLVAR_CONTEXT(bgp, bgp);
2677 struct listnode *node, *nnode;
2678 struct peer *peer;
2679
7f972cd8 2680 bgp->reject_as_sets = false;
fb29348a
DA
2681
2682 /* Reset existing BGP sessions to reject routes
2683 * with aspath containing AS_SET or AS_CONFED_SET.
2684 */
2685 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2686 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2687 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2688 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2689 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2690 }
2691 }
2692
2693 return CMD_SUCCESS;
2694}
9dac9fc8 2695
718e3744 2696/* "bgp deterministic-med" configuration. */
ff8a8a7a 2697DEFUN_YANG (bgp_deterministic_med,
718e3744 2698 bgp_deterministic_med_cmd,
2699 "bgp deterministic-med",
2700 "BGP specific commands\n"
2701 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2702{
87ce2564
CS
2703 nb_cli_enqueue_change(
2704 vty, "./global/route-selection-options/deterministic-med",
2705 NB_OP_MODIFY, "true");
7aafcaca 2706
ff8a8a7a 2707 return nb_cli_apply_changes(vty, NULL);
718e3744 2708}
2709
ff8a8a7a 2710DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2711 no_bgp_deterministic_med_cmd,
2712 "no bgp deterministic-med",
2713 NO_STR
2714 "BGP specific commands\n"
2715 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2716{
87ce2564
CS
2717 nb_cli_enqueue_change(
2718 vty, "./global/route-selection-options/deterministic-med",
2719 NB_OP_MODIFY, "false");
d62a17ae 2720
ff8a8a7a 2721 return nb_cli_apply_changes(vty, NULL);
718e3744 2722}
538621f2 2723
055679e9 2724/* "bgp graceful-restart mode" configuration. */
538621f2 2725DEFUN (bgp_graceful_restart,
2ba1fe69 2726 bgp_graceful_restart_cmd,
2727 "bgp graceful-restart",
2728 "BGP specific commands\n"
2729 GR_CMD
055679e9 2730 )
538621f2 2731{
055679e9 2732 int ret = BGP_GR_FAILURE;
2733
2734 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2735 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2736
d62a17ae 2737 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2738
2739 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2740
36235319
QY
2741 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2742 ret);
5cce3f05 2743
055679e9 2744 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2745 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2746 vty_out(vty,
2747 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2748 return bgp_vty_return(vty, ret);
538621f2 2749}
2750
2751DEFUN (no_bgp_graceful_restart,
2ba1fe69 2752 no_bgp_graceful_restart_cmd,
2753 "no bgp graceful-restart",
2754 NO_STR
2755 "BGP specific commands\n"
2756 NO_GR_CMD
055679e9 2757 )
538621f2 2758{
d62a17ae 2759 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2760
2761 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2762 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2763
2764 int ret = BGP_GR_FAILURE;
2765
2766 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2767
36235319
QY
2768 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2769 ret);
5cce3f05 2770
055679e9 2771 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2772 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2773 vty_out(vty,
2774 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2775
2776 return bgp_vty_return(vty, ret);
538621f2 2777}
2778
93406d87 2779DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2780 bgp_graceful_restart_stalepath_time_cmd,
2781 "bgp graceful-restart stalepath-time (1-4095)",
2782 "BGP specific commands\n"
2783 "Graceful restart capability parameters\n"
2784 "Set the max time to hold onto restarting peer's stale paths\n"
2785 "Delay value (seconds)\n")
93406d87 2786{
d62a17ae 2787 VTY_DECLVAR_CONTEXT(bgp, bgp);
2788 int idx_number = 3;
d7c0a89a 2789 uint32_t stalepath;
93406d87 2790
d62a17ae 2791 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2792 bgp->stalepath_time = stalepath;
2793 return CMD_SUCCESS;
93406d87 2794}
2795
eb6f1b41 2796DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2797 bgp_graceful_restart_restart_time_cmd,
2798 "bgp graceful-restart restart-time (1-4095)",
2799 "BGP specific commands\n"
2800 "Graceful restart capability parameters\n"
2801 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2802 "Delay value (seconds)\n")
eb6f1b41 2803{
d62a17ae 2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805 int idx_number = 3;
d7c0a89a 2806 uint32_t restart;
eb6f1b41 2807
d62a17ae 2808 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2809 bgp->restart_time = restart;
2810 return CMD_SUCCESS;
eb6f1b41
PG
2811}
2812
cfd47646 2813DEFUN (bgp_graceful_restart_select_defer_time,
2814 bgp_graceful_restart_select_defer_time_cmd,
2815 "bgp graceful-restart select-defer-time (0-3600)",
2816 "BGP specific commands\n"
2817 "Graceful restart capability parameters\n"
2818 "Set the time to defer the BGP route selection after restart\n"
2819 "Delay value (seconds, 0 - disable)\n")
2820{
2821 VTY_DECLVAR_CONTEXT(bgp, bgp);
2822 int idx_number = 3;
2823 uint32_t defer_time;
2824
2825 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2826 bgp->select_defer_time = defer_time;
2827 if (defer_time == 0)
892fedb6 2828 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2829 else
892fedb6 2830 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2831
2832 return CMD_SUCCESS;
2833}
2834
93406d87 2835DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2836 no_bgp_graceful_restart_stalepath_time_cmd,
2837 "no bgp graceful-restart stalepath-time [(1-4095)]",
2838 NO_STR
2839 "BGP specific commands\n"
2840 "Graceful restart capability parameters\n"
2841 "Set the max time to hold onto restarting peer's stale paths\n"
2842 "Delay value (seconds)\n")
93406d87 2843{
d62a17ae 2844 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2845
d62a17ae 2846 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2847 return CMD_SUCCESS;
93406d87 2848}
2849
eb6f1b41 2850DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2851 no_bgp_graceful_restart_restart_time_cmd,
2852 "no bgp graceful-restart restart-time [(1-4095)]",
2853 NO_STR
2854 "BGP specific commands\n"
2855 "Graceful restart capability parameters\n"
2856 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2857 "Delay value (seconds)\n")
eb6f1b41 2858{
d62a17ae 2859 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2860
d62a17ae 2861 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2862 return CMD_SUCCESS;
eb6f1b41
PG
2863}
2864
cfd47646 2865DEFUN (no_bgp_graceful_restart_select_defer_time,
2866 no_bgp_graceful_restart_select_defer_time_cmd,
2867 "no bgp graceful-restart select-defer-time [(0-3600)]",
2868 NO_STR
2869 "BGP specific commands\n"
2870 "Graceful restart capability parameters\n"
2871 "Set the time to defer the BGP route selection after restart\n"
2872 "Delay value (seconds)\n")
2873{
2874 VTY_DECLVAR_CONTEXT(bgp, bgp);
2875
2876 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2877 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2878
2879 return CMD_SUCCESS;
2880}
2881
43fc21b3 2882DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2883 bgp_graceful_restart_preserve_fw_cmd,
2884 "bgp graceful-restart preserve-fw-state",
2885 "BGP specific commands\n"
2886 "Graceful restart capability parameters\n"
2887 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2888{
d62a17ae 2889 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2890 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2891 return CMD_SUCCESS;
43fc21b3
JC
2892}
2893
2894DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2895 no_bgp_graceful_restart_preserve_fw_cmd,
2896 "no bgp graceful-restart preserve-fw-state",
2897 NO_STR
2898 "BGP specific commands\n"
2899 "Graceful restart capability parameters\n"
2900 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2901{
d62a17ae 2902 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2903 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2904 return CMD_SUCCESS;
43fc21b3
JC
2905}
2906
055679e9 2907DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2908 bgp_graceful_restart_disable_cmd,
2909 "bgp graceful-restart-disable",
2910 "BGP specific commands\n"
2911 GR_DISABLE)
055679e9 2912{
2913 int ret = BGP_GR_FAILURE;
2914
2915 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2916 zlog_debug(
2ba1fe69 2917 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2918
055679e9 2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
2920
2921 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2922
dc95985f 2923 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2924 bgp->peer, ret);
5cce3f05 2925
055679e9 2926 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2927 zlog_debug(
2ba1fe69 2928 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2929 vty_out(vty,
2930 "Graceful restart configuration changed, reset all peers to take effect\n");
2931
055679e9 2932 return bgp_vty_return(vty, ret);
2933}
2934
2935DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2936 no_bgp_graceful_restart_disable_cmd,
2937 "no bgp graceful-restart-disable",
2938 NO_STR
2939 "BGP specific commands\n"
2940 NO_GR_DISABLE
055679e9 2941 )
2942{
2943 VTY_DECLVAR_CONTEXT(bgp, bgp);
2944
2945 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2946 zlog_debug(
2ba1fe69 2947 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2948
2949 int ret = BGP_GR_FAILURE;
2950
2951 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2952
36235319
QY
2953 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2954 ret);
5cce3f05 2955
055679e9 2956 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2957 zlog_debug(
2ba1fe69 2958 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2959 vty_out(vty,
2960 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2961
2962 return bgp_vty_return(vty, ret);
2963}
2964
2965DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2966 bgp_neighbor_graceful_restart_set_cmd,
2967 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2968 NEIGHBOR_STR
2969 NEIGHBOR_ADDR_STR2
2970 GR_NEIGHBOR_CMD
055679e9 2971 )
2972{
2973 int idx_peer = 1;
2974 struct peer *peer;
2975 int ret = BGP_GR_FAILURE;
2976
dc95985f 2977 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2978
055679e9 2979 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2980 zlog_debug(
2ba1fe69 2981 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2982
055679e9 2983 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2984 if (!peer)
2985 return CMD_WARNING_CONFIG_FAILED;
2986
2987 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2988
dc95985f 2989 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2990 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2991
2992 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2993 zlog_debug(
2ba1fe69 2994 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2995 vty_out(vty,
2996 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2997
2998 return bgp_vty_return(vty, ret);
2999}
3000
3001DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3002 no_bgp_neighbor_graceful_restart_set_cmd,
3003 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3004 NO_STR
3005 NEIGHBOR_STR
3006 NEIGHBOR_ADDR_STR2
3007 NO_GR_NEIGHBOR_CMD
055679e9 3008 )
3009{
3010 int idx_peer = 2;
3011 int ret = BGP_GR_FAILURE;
3012 struct peer *peer;
3013
dc95985f 3014 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3015
055679e9 3016 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3017 if (!peer)
3018 return CMD_WARNING_CONFIG_FAILED;
3019
3020 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3021 zlog_debug(
2ba1fe69 3022 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3023
3024 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3025
dc95985f 3026 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3027 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3028
3029 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3030 zlog_debug(
2ba1fe69 3031 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3032 vty_out(vty,
3033 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3034
3035 return bgp_vty_return(vty, ret);
3036}
3037
3038DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3039 bgp_neighbor_graceful_restart_helper_set_cmd,
3040 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3041 NEIGHBOR_STR
3042 NEIGHBOR_ADDR_STR2
3043 GR_NEIGHBOR_HELPER_CMD
055679e9 3044 )
3045{
3046 int idx_peer = 1;
3047 struct peer *peer;
3048 int ret = BGP_GR_FAILURE;
3049
dc95985f 3050 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3051
055679e9 3052 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3053 zlog_debug(
2ba1fe69 3054 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3055
055679e9 3056 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3057
055679e9 3058 if (!peer)
3059 return CMD_WARNING_CONFIG_FAILED;
3060
3061
3062 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3063
dc95985f 3064 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3065 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3066
055679e9 3067 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3068 zlog_debug(
2ba1fe69 3069 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3070 vty_out(vty,
3071 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3072
3073 return bgp_vty_return(vty, ret);
3074}
3075
3076DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3077 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3078 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3079 NO_STR
3080 NEIGHBOR_STR
3081 NEIGHBOR_ADDR_STR2
3082 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3083 )
3084{
3085 int idx_peer = 2;
3086 int ret = BGP_GR_FAILURE;
3087 struct peer *peer;
3088
dc95985f 3089 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3090
055679e9 3091 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3092 if (!peer)
3093 return CMD_WARNING_CONFIG_FAILED;
3094
3095 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3096 zlog_debug(
2ba1fe69 3097 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3098
36235319 3099 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3100
dc95985f 3101 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3102 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3103
3104 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3105 zlog_debug(
2ba1fe69 3106 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3107 vty_out(vty,
3108 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3109
3110 return bgp_vty_return(vty, ret);
3111}
3112
3113DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3114 bgp_neighbor_graceful_restart_disable_set_cmd,
3115 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3116 NEIGHBOR_STR
3117 NEIGHBOR_ADDR_STR2
3118 GR_NEIGHBOR_DISABLE_CMD
055679e9 3119 )
3120{
3121 int idx_peer = 1;
3122 struct peer *peer;
3123 int ret = BGP_GR_FAILURE;
3124
dc95985f 3125 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3126
055679e9 3127 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3128 zlog_debug(
2ba1fe69 3129 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3130
3131 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3132 if (!peer)
3133 return CMD_WARNING_CONFIG_FAILED;
3134
36235319 3135 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3136
3137 if (peer->bgp->t_startup)
3138 bgp_peer_gr_flags_update(peer);
3139
dc95985f 3140 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3141 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3142
055679e9 3143 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3144 zlog_debug(
2ba1fe69 3145 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3146 vty_out(vty,
3147 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3148
3149 return bgp_vty_return(vty, ret);
3150}
3151
3152DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3153 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3154 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3155 NO_STR
3156 NEIGHBOR_STR
3157 NEIGHBOR_ADDR_STR2
3158 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3159 )
3160{
3161 int idx_peer = 2;
3162 int ret = BGP_GR_FAILURE;
3163 struct peer *peer;
3164
dc95985f 3165 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3166
055679e9 3167 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3168 if (!peer)
3169 return CMD_WARNING_CONFIG_FAILED;
3170
3171 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3172 zlog_debug(
2ba1fe69 3173 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3174
3175 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3176
dc95985f 3177 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3178 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3179
3180 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3181 zlog_debug(
2ba1fe69 3182 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3183 vty_out(vty,
3184 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3185
3186 return bgp_vty_return(vty, ret);
3187}
3188
d6e3c15b 3189DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3190 bgp_graceful_restart_disable_eor_cmd,
3191 "bgp graceful-restart disable-eor",
3192 "BGP specific commands\n"
3193 "Graceful restart configuration parameters\n"
3194 "Disable EOR Check\n")
3195{
3196 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3197 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3198
d6e3c15b 3199 return CMD_SUCCESS;
3200}
3201
3202DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3203 no_bgp_graceful_restart_disable_eor_cmd,
3204 "no bgp graceful-restart disable-eor",
3205 NO_STR
3206 "BGP specific commands\n"
3207 "Graceful restart configuration parameters\n"
3208 "Disable EOR Check\n")
3209{
3210 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3211 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3212
3213 return CMD_SUCCESS;
3214}
3215
3216DEFUN (bgp_graceful_restart_rib_stale_time,
3217 bgp_graceful_restart_rib_stale_time_cmd,
3218 "bgp graceful-restart rib-stale-time (1-3600)",
3219 "BGP specific commands\n"
3220 "Graceful restart configuration parameters\n"
3221 "Specify the stale route removal timer in rib\n"
3222 "Delay value (seconds)\n")
3223{
3224 VTY_DECLVAR_CONTEXT(bgp, bgp);
3225 int idx_number = 3;
3226 uint32_t stale_time;
3227
3228 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3229 bgp->rib_stale_time = stale_time;
3230 /* Send the stale timer update message to RIB */
3231 if (bgp_zebra_stale_timer_update(bgp))
3232 return CMD_WARNING;
3233
3234 return CMD_SUCCESS;
3235}
3236
3237DEFUN (no_bgp_graceful_restart_rib_stale_time,
3238 no_bgp_graceful_restart_rib_stale_time_cmd,
3239 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3240 NO_STR
3241 "BGP specific commands\n"
3242 "Graceful restart configuration parameters\n"
3243 "Specify the stale route removal timer in rib\n"
3244 "Delay value (seconds)\n")
3245{
3246 VTY_DECLVAR_CONTEXT(bgp, bgp);
3247
3248 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3249 /* Send the stale timer update message to RIB */
3250 if (bgp_zebra_stale_timer_update(bgp))
3251 return CMD_WARNING;
3252
d6e3c15b 3253 return CMD_SUCCESS;
3254}
3255
ff8a8a7a
CS
3256static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3257 char *errmsg,
3258 size_t errmsg_len)
05bd726c 3259{
3260 bgp_static_redo_import_check(bgp);
3261 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
3262 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3263 return -1;
3264 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3265 return -1;
3266
3267 return 0;
05bd726c 3268}
3269
3270static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3271{
3272 struct listnode *node, *nnode;
3273 struct bgp *bgp;
3274 bool vrf_cfg = false;
ff8a8a7a 3275 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3276
3277 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3278 return CMD_SUCCESS;
3279
3280 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3281 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3282 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3283 vty_out(vty,
3284 "%% graceful-shutdown configuration found in vrf %s\n",
3285 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3286 VRF_DEFAULT_NAME : bgp->name);
3287 vrf_cfg = true;
3288 }
3289 }
3290
3291 if (vrf_cfg) {
3292 vty_out(vty,
3293 "%%Failed: global graceful-shutdown not permitted\n");
3294 return CMD_WARNING;
3295 }
3296
3297 /* Set flag globally */
3298 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3299
3300 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3301 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3302 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3303 sizeof(errmsg))
3304 < 0)
3305 if (strlen(errmsg))
3306 vty_out(vty, "%s\n", errmsg);
3307 }
05bd726c 3308
3309 return CMD_SUCCESS;
3310}
3311
3312static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3313{
3314 struct listnode *node, *nnode;
3315 struct bgp *bgp;
ff8a8a7a 3316 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3317
3318 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3319 return CMD_SUCCESS;
3320
3321 /* Unset flag globally */
3322 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3323
3324 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3325 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3326 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3327 sizeof(errmsg))
3328 < 0)
3329 if (strlen(errmsg))
3330 vty_out(vty, "%s\n", errmsg);
3331 }
05bd726c 3332
3333 return CMD_SUCCESS;
3334}
3335
7f323236
DW
3336/* "bgp graceful-shutdown" configuration */
3337DEFUN (bgp_graceful_shutdown,
3338 bgp_graceful_shutdown_cmd,
3339 "bgp graceful-shutdown",
3340 BGP_STR
3341 "Graceful shutdown parameters\n")
3342{
05bd726c 3343 if (vty->node == CONFIG_NODE)
3344 return bgp_global_graceful_shutdown_config_vty(vty);
3345
87ce2564
CS
3346 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3347 NB_OP_MODIFY, "true");
7f323236 3348
ff8a8a7a 3349 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3350}
3351
ff8a8a7a 3352DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3353 no_bgp_graceful_shutdown_cmd,
3354 "no bgp graceful-shutdown",
3355 NO_STR
3356 BGP_STR
3357 "Graceful shutdown parameters\n")
3358{
05bd726c 3359 if (vty->node == CONFIG_NODE)
3360 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3361
87ce2564
CS
3362 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3363 NB_OP_MODIFY, "false");
05bd726c 3364
ff8a8a7a
CS
3365 return nb_cli_apply_changes(vty, NULL);
3366}
7f323236 3367
ff8a8a7a
CS
3368void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3369 struct lyd_node *dnode,
3370 bool show_defaults)
3371{
3372 if (yang_dnode_get_bool(dnode, NULL))
3373 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3374}
3375
718e3744 3376/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3377DEFUN_YANG (bgp_fast_external_failover,
718e3744 3378 bgp_fast_external_failover_cmd,
3379 "bgp fast-external-failover",
3380 BGP_STR
3381 "Immediately reset session if a link to a directly connected external peer goes down\n")
3382{
87ce2564
CS
3383 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3384 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3385
3386 return nb_cli_apply_changes(vty, NULL);
718e3744 3387}
3388
ff8a8a7a 3389DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3390 no_bgp_fast_external_failover_cmd,
3391 "no bgp fast-external-failover",
3392 NO_STR
3393 BGP_STR
3394 "Immediately reset session if a link to a directly connected external peer goes down\n")
3395{
87ce2564
CS
3396 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3397 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3398
3399 return nb_cli_apply_changes(vty, NULL);
3400}
3401
3402void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3403 struct lyd_node *dnode,
3404 bool show_defaults)
3405{
3406 if (!yang_dnode_get_bool(dnode, NULL))
3407 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3408}
6b0655a2 3409
718e3744 3410/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3411DEFUN_YANG(bgp_bestpath_compare_router_id,
3412 bgp_bestpath_compare_router_id_cmd,
3413 "bgp bestpath compare-routerid",
3414 "BGP specific commands\n"
3415 "Change the default bestpath selection\n"
3416 "Compare router-id for identical EBGP paths\n")
718e3744 3417{
ff8a8a7a 3418 nb_cli_enqueue_change(
87ce2564
CS
3419 vty,
3420 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3421 NB_OP_MODIFY, "true");
7aafcaca 3422
ff8a8a7a 3423 return nb_cli_apply_changes(vty, NULL);
718e3744 3424}
3425
ff8a8a7a
CS
3426DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3427 no_bgp_bestpath_compare_router_id_cmd,
3428 "no bgp bestpath compare-routerid",
3429 NO_STR
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, "false");
7aafcaca 3438
ff8a8a7a 3439 return nb_cli_apply_changes(vty, NULL);
718e3744 3440}
6b0655a2 3441
718e3744 3442/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3443DEFUN_YANG(bgp_bestpath_aspath_ignore,
3444 bgp_bestpath_aspath_ignore_cmd,
3445 "bgp bestpath as-path ignore",
3446 "BGP specific commands\n"
3447 "Change the default bestpath selection\n"
3448 "AS-path attribute\n"
3449 "Ignore as-path length in selecting a route\n")
718e3744 3450{
87ce2564
CS
3451 nb_cli_enqueue_change(
3452 vty, "./global/route-selection-options/ignore-as-path-length",
3453 NB_OP_MODIFY, "true");
7aafcaca 3454
ff8a8a7a 3455 return nb_cli_apply_changes(vty, NULL);
718e3744 3456}
3457
ff8a8a7a
CS
3458DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3459 no_bgp_bestpath_aspath_ignore_cmd,
3460 "no bgp bestpath as-path ignore",
3461 NO_STR
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, "false");
7aafcaca 3470
ff8a8a7a 3471 return nb_cli_apply_changes(vty, NULL);
718e3744 3472}
6b0655a2 3473
6811845b 3474/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3475DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3476 bgp_bestpath_aspath_confed_cmd,
3477 "bgp bestpath as-path confed",
3478 "BGP specific commands\n"
3479 "Change the default bestpath selection\n"
3480 "AS-path attribute\n"
3481 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3482{
87ce2564
CS
3483 nb_cli_enqueue_change(vty,
3484 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3485 NB_OP_MODIFY, "true");
7aafcaca 3486
ff8a8a7a 3487 return nb_cli_apply_changes(vty, NULL);
6811845b 3488}
3489
ff8a8a7a 3490DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3491 no_bgp_bestpath_aspath_confed_cmd,
3492 "no bgp bestpath as-path confed",
3493 NO_STR
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, "false");
7aafcaca 3502
ff8a8a7a 3503 return nb_cli_apply_changes(vty, NULL);
6811845b 3504}
6b0655a2 3505
2fdd455c 3506/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3507DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3508 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3509 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3510 "BGP specific commands\n"
3511 "Change the default bestpath selection\n"
3512 "AS-path attribute\n"
3513 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3514 "Generate an AS_SET\n"
16fc1eec
DS
3515 "Do not generate an AS_SET\n")
3516{
d62a17ae 3517 int idx = 0;
219178b6 3518
87ce2564
CS
3519 nb_cli_enqueue_change(
3520 vty, "./global/route-selection-options/allow-multiple-as",
3521 NB_OP_MODIFY, "true");
d62a17ae 3522 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3523 nb_cli_enqueue_change(
87ce2564
CS
3524 vty,
3525 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3526 NB_OP_MODIFY, "true");
d62a17ae 3527 else
ff8a8a7a 3528 nb_cli_enqueue_change(
87ce2564
CS
3529 vty,
3530 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3531 NB_OP_MODIFY, "false");
7aafcaca 3532
ff8a8a7a 3533 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3534}
3535
ff8a8a7a 3536DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3537 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3538 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3539 NO_STR
3540 "BGP specific commands\n"
3541 "Change the default bestpath selection\n"
3542 "AS-path attribute\n"
3543 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3544 "Generate an AS_SET\n"
16fc1eec
DS
3545 "Do not generate an AS_SET\n")
3546{
87ce2564
CS
3547 nb_cli_enqueue_change(
3548 vty, "./global/route-selection-options/allow-multiple-as",
3549 NB_OP_MODIFY, "false");
3550 nb_cli_enqueue_change(
3551 vty, "./global/route-selection-options/multi-path-as-set",
3552 NB_OP_MODIFY, "false");
7aafcaca 3553
ff8a8a7a 3554 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3555}
6b0655a2 3556
ee88563a
JM
3557/* "bgp bestpath peer-type multipath-relax" configuration. */
3558DEFUN(bgp_bestpath_peer_type_multipath_relax,
3559 bgp_bestpath_peer_type_multipath_relax_cmd,
3560 "bgp bestpath peer-type multipath-relax",
3561 BGP_STR
3562 "Change the default bestpath selection\n"
3563 "Peer type\n"
3564 "Allow load sharing across routes learned from different peer types\n")
3565{
3566 VTY_DECLVAR_CONTEXT(bgp, bgp);
3567 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3568 bgp_recalculate_all_bestpaths(bgp);
3569
3570 return CMD_SUCCESS;
3571}
3572
3573DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3574 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3575 "no bgp bestpath peer-type multipath-relax",
3576 NO_STR BGP_STR
3577 "Change the default bestpath selection\n"
3578 "Peer type\n"
3579 "Allow load sharing across routes learned from different peer types\n")
3580{
3581 VTY_DECLVAR_CONTEXT(bgp, bgp);
3582 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3583 bgp_recalculate_all_bestpaths(bgp);
3584
3585 return CMD_SUCCESS;
3586}
3587
848973c7 3588/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3589DEFUN_YANG(bgp_log_neighbor_changes,
3590 bgp_log_neighbor_changes_cmd,
3591 "bgp log-neighbor-changes",
3592 "BGP specific commands\n"
3593 "Log neighbor up/down and reset reason\n")
848973c7 3594{
87ce2564
CS
3595 nb_cli_enqueue_change(
3596 vty, "./global/global-neighbor-config/log-neighbor-changes",
3597 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3598
3599 return nb_cli_apply_changes(vty, NULL);
848973c7 3600}
3601
ff8a8a7a
CS
3602DEFUN_YANG(no_bgp_log_neighbor_changes,
3603 no_bgp_log_neighbor_changes_cmd,
3604 "no bgp log-neighbor-changes",
3605 NO_STR
3606 "BGP specific commands\n"
3607 "Log neighbor up/down and reset reason\n")
848973c7 3608{
87ce2564
CS
3609 nb_cli_enqueue_change(
3610 vty, "./global/global-neighbor-config/log-neighbor-changes",
3611 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3612
3613 return nb_cli_apply_changes(vty, NULL);
848973c7 3614}
6b0655a2 3615
718e3744 3616/* "bgp bestpath med" configuration. */
ff8a8a7a 3617DEFUN_YANG (bgp_bestpath_med,
718e3744 3618 bgp_bestpath_med_cmd,
2d8c1a4d 3619 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3620 "BGP specific commands\n"
3621 "Change the default bestpath selection\n"
3622 "MED attribute\n"
3623 "Compare MED among confederation paths\n"
838758ac
DW
3624 "Treat missing MED as the least preferred one\n"
3625 "Treat missing MED as the least preferred one\n"
3626 "Compare MED among confederation paths\n")
718e3744 3627{
d62a17ae 3628 int idx = 0;
ff8a8a7a
CS
3629 bool confed = false;
3630 bool worst_med = false;
3631
3632
d62a17ae 3633 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3634 confed = true;
3635
87ce2564
CS
3636 nb_cli_enqueue_change(vty,
3637 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3638 NB_OP_MODIFY, confed ? "true" : "false");
3639
d62a17ae 3640 idx = 0;
3641 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3642 worst_med = true;
e52702f2 3643
87ce2564
CS
3644 nb_cli_enqueue_change(
3645 vty, "./global/route-selection-options/missing-as-worst-med",
3646 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3647
ff8a8a7a 3648 return nb_cli_apply_changes(vty, NULL);
718e3744 3649}
3650
ff8a8a7a 3651DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3652 no_bgp_bestpath_med_cmd,
2d8c1a4d 3653 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3654 NO_STR
3655 "BGP specific commands\n"
3656 "Change the default bestpath selection\n"
3657 "MED attribute\n"
3658 "Compare MED among confederation paths\n"
3a2d747c
QY
3659 "Treat missing MED as the least preferred one\n"
3660 "Treat missing MED as the least preferred one\n"
3661 "Compare MED among confederation paths\n")
718e3744 3662{
d62a17ae 3663 int idx = 0;
ff8a8a7a 3664
d62a17ae 3665 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3666 nb_cli_enqueue_change(
3667 vty, "./global/route-selection-options/confed-med",
3668 NB_OP_MODIFY, "false");
ff8a8a7a 3669
d62a17ae 3670 idx = 0;
3671 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3672 nb_cli_enqueue_change(
87ce2564
CS
3673 vty,
3674 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3675 NB_OP_MODIFY, "false");
718e3744 3676
ff8a8a7a 3677 return nb_cli_apply_changes(vty, NULL);
718e3744 3678}
3679
f7e1c681 3680/* "bgp bestpath bandwidth" configuration. */
3681DEFPY (bgp_bestpath_bw,
3682 bgp_bestpath_bw_cmd,
ad36d216 3683 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3684 "BGP specific commands\n"
3685 "Change the default bestpath selection\n"
3686 "Link Bandwidth attribute\n"
3687 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3688 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3689 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3690{
3691 VTY_DECLVAR_CONTEXT(bgp, bgp);
3692 afi_t afi;
3693 safi_t safi;
3694
ad36d216
DS
3695 if (!bw_cfg) {
3696 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3697 return CMD_ERR_INCOMPLETE;
f7e1c681 3698 }
ad36d216
DS
3699 if (!strcmp(bw_cfg, "ignore"))
3700 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3701 else if (!strcmp(bw_cfg, "skip-missing"))
3702 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3703 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3704 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3705 else
3706 return CMD_ERR_NO_MATCH;
f7e1c681 3707
3708 /* This config is used in route install, so redo that. */
3709 FOREACH_AFI_SAFI (afi, safi) {
3710 if (!bgp_fibupd_safi(safi))
3711 continue;
3712 bgp_zebra_announce_table(bgp, afi, safi);
3713 }
3714
3715 return CMD_SUCCESS;
3716}
3717
ad36d216
DS
3718DEFPY (no_bgp_bestpath_bw,
3719 no_bgp_bestpath_bw_cmd,
3720 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3721 NO_STR
3722 "BGP specific commands\n"
3723 "Change the default bestpath selection\n"
3724 "Link Bandwidth attribute\n"
3725 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3726 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3727 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3728{
3729 VTY_DECLVAR_CONTEXT(bgp, bgp);
3730 afi_t afi;
3731 safi_t safi;
3732
3733 bgp->lb_handling = BGP_LINK_BW_ECMP;
3734
3735 /* This config is used in route install, so redo that. */
3736 FOREACH_AFI_SAFI (afi, safi) {
3737 if (!bgp_fibupd_safi(safi))
3738 continue;
3739 bgp_zebra_announce_table(bgp, afi, safi);
3740 }
3741 return CMD_SUCCESS;
3742}
3743
e84c59af
DA
3744/* "no bgp default ipv6-unicast". */
3745DEFUN(no_bgp_default_ipv6_unicast, no_bgp_default_ipv6_unicast_cmd,
3746 "no bgp default ipv6-unicast", NO_STR
3747 "BGP specific commands\n"
3748 "Configure BGP defaults\n"
3749 "Activate ipv6-unicast for a peer by default\n")
3750{
3751 VTY_DECLVAR_CONTEXT(bgp, bgp);
3752 UNSET_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6);
3753 return CMD_SUCCESS;
3754}
3755
3756DEFUN(bgp_default_ipv6_unicast, bgp_default_ipv6_unicast_cmd,
3757 "bgp default ipv6-unicast",
3758 "BGP specific commands\n"
3759 "Configure BGP defaults\n"
3760 "Activate ipv6-unicast for a peer by default\n")
3761{
3762 VTY_DECLVAR_CONTEXT(bgp, bgp);
3763 SET_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6);
3764 return CMD_SUCCESS;
3765}
3766
718e3744 3767/* "no bgp default ipv4-unicast". */
3768DEFUN (no_bgp_default_ipv4_unicast,
3769 no_bgp_default_ipv4_unicast_cmd,
3770 "no bgp default ipv4-unicast",
3771 NO_STR
3772 "BGP specific commands\n"
3773 "Configure BGP defaults\n"
3774 "Activate ipv4-unicast for a peer by default\n")
3775{
d62a17ae 3776 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3777 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3778 return CMD_SUCCESS;
718e3744 3779}
3780
3781DEFUN (bgp_default_ipv4_unicast,
3782 bgp_default_ipv4_unicast_cmd,
3783 "bgp default ipv4-unicast",
3784 "BGP specific commands\n"
3785 "Configure BGP defaults\n"
3786 "Activate ipv4-unicast for a peer by default\n")
3787{
d62a17ae 3788 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3789 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3790 return CMD_SUCCESS;
718e3744 3791}
6b0655a2 3792
04b6bdc0 3793/* Display hostname in certain command outputs */
ff8a8a7a 3794DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3795 bgp_default_show_hostname_cmd,
3796 "bgp default show-hostname",
3797 "BGP specific commands\n"
3798 "Configure BGP defaults\n"
0437e105 3799 "Show hostname in certain command outputs\n")
04b6bdc0 3800{
87ce2564
CS
3801 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3802 "true");
ff8a8a7a
CS
3803
3804 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3805}
3806
ff8a8a7a
CS
3807DEFUN_YANG(no_bgp_default_show_hostname,
3808 no_bgp_default_show_hostname_cmd,
3809 "no bgp default show-hostname",
3810 NO_STR
3811 "BGP specific commands\n"
3812 "Configure BGP defaults\n"
3813 "Show hostname in certain command outputs\n")
04b6bdc0 3814{
87ce2564
CS
3815 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3816 "false");
ff8a8a7a
CS
3817
3818 return nb_cli_apply_changes(vty, NULL);
3819}
3820
3821void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3822 bool show_defaults)
3823{
3824 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3825 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3826}
3827
aef999a2 3828/* Display hostname in certain command outputs */
232c75cd
CS
3829DEFUN_YANG(bgp_default_show_nexthop_hostname,
3830 bgp_default_show_nexthop_hostname_cmd,
3831 "bgp default show-nexthop-hostname",
3832 "BGP specific commands\n"
3833 "Configure BGP defaults\n"
3834 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3835{
87ce2564
CS
3836 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3837 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3838
3839 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3840}
3841
3842DEFUN (no_bgp_default_show_nexthop_hostname,
3843 no_bgp_default_show_nexthop_hostname_cmd,
3844 "no bgp default show-nexthop-hostname",
3845 NO_STR
3846 "BGP specific commands\n"
3847 "Configure BGP defaults\n"
3848 "Show hostname for nexthop in certain command outputs\n")
3849{
87ce2564
CS
3850 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3851 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3852
3853 return nb_cli_apply_changes(vty, NULL);
3854}
3855
3856void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3857 struct lyd_node *dnode,
3858 bool show_defaults)
3859{
3860 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3861 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3862}
3863
8233ef81 3864/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3865DEFUN_YANG(bgp_network_import_check,
3866 bgp_network_import_check_cmd,
3867 "bgp network import-check",
3868 "BGP specific commands\n"
3869 "BGP network command\n"
3870 "Check BGP network route exists in IGP\n")
718e3744 3871{
87ce2564
CS
3872 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3873 "true");
078430f6 3874
ff8a8a7a 3875 return nb_cli_apply_changes(vty, NULL);
718e3744 3876}
3877
d62a17ae 3878ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3879 "bgp network import-check exact",
3880 "BGP specific commands\n"
3881 "BGP network command\n"
3882 "Check BGP network route exists in IGP\n"
3883 "Match route precisely\n")
8233ef81 3884
ff8a8a7a
CS
3885DEFUN_YANG(no_bgp_network_import_check,
3886 no_bgp_network_import_check_cmd,
3887 "no bgp network import-check",
3888 NO_STR
3889 "BGP specific commands\n"
3890 "BGP network command\n"
3891 "Check BGP network route exists in IGP\n")
718e3744 3892{
87ce2564
CS
3893 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3894 "false");
5623e905 3895
ff8a8a7a 3896 return nb_cli_apply_changes(vty, NULL);
718e3744 3897}
6b0655a2 3898
ff8a8a7a
CS
3899void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3900 bool show_defaults)
718e3744 3901{
ff8a8a7a
CS
3902 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3903 vty_out(vty, " bgp network import-check\n");
3904}
718e3744 3905
ff8a8a7a
CS
3906DEFUN_YANG(bgp_default_local_preference,
3907 bgp_default_local_preference_cmd,
3908 "bgp default local-preference (0-4294967295)",
3909 "BGP specific commands\n"
3910 "Configure BGP defaults\n"
3911 "local preference (higher=more preferred)\n"
3912 "Configure default local preference value\n")
3913{
3914 int idx_number = 3;
718e3744 3915
87ce2564 3916 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3917 argv[idx_number]->arg);
718e3744 3918
ff8a8a7a 3919 return nb_cli_apply_changes(vty, NULL);
718e3744 3920}
3921
ff8a8a7a
CS
3922DEFUN_YANG(no_bgp_default_local_preference,
3923 no_bgp_default_local_preference_cmd,
3924 "no bgp default local-preference [(0-4294967295)]",
3925 NO_STR
3926 "BGP specific commands\n"
3927 "Configure BGP defaults\n"
3928 "local preference (higher=more preferred)\n"
3929 "Configure default local preference value\n")
718e3744 3930{
87ce2564 3931 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 3932
ff8a8a7a 3933 return nb_cli_apply_changes(vty, NULL);
718e3744 3934}
3935
ff8a8a7a
CS
3936void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3937 bool show_defaults)
3938{
3939 vty_out(vty, " bgp default local-preference %u\n",
3940 yang_dnode_get_uint32(dnode, NULL));
3941}
6b0655a2 3942
ff8a8a7a
CS
3943
3944DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3945 bgp_default_subgroup_pkt_queue_max_cmd,
3946 "bgp default subgroup-pkt-queue-max (20-100)",
3947 "BGP specific commands\n"
3948 "Configure BGP defaults\n"
3949 "subgroup-pkt-queue-max\n"
3950 "Configure subgroup packet queue max\n")
8bd9d948 3951{
d62a17ae 3952 int idx_number = 3;
3f9c7369 3953
ff8a8a7a 3954 nb_cli_enqueue_change(
87ce2564
CS
3955 vty,
3956 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 3957 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 3958
ff8a8a7a 3959 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
3960}
3961
ff8a8a7a
CS
3962DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3963 no_bgp_default_subgroup_pkt_queue_max_cmd,
3964 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3965 NO_STR
3966 "BGP specific commands\n"
3967 "Configure BGP defaults\n"
3968 "subgroup-pkt-queue-max\n"
3969 "Configure subgroup packet queue max\n")
3f9c7369 3970{
ff8a8a7a 3971 nb_cli_enqueue_change(
87ce2564
CS
3972 vty,
3973 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
3974 NB_OP_MODIFY, NULL);
3975
3976 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3977}
3978
ff8a8a7a
CS
3979void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3980 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3981{
3982 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3983 yang_dnode_get_uint32(dnode, NULL));
3984}
813d4307 3985
ff8a8a7a
CS
3986DEFUN_YANG(bgp_rr_allow_outbound_policy,
3987 bgp_rr_allow_outbound_policy_cmd,
3988 "bgp route-reflector allow-outbound-policy",
3989 "BGP specific commands\n"
3990 "Allow modifications made by out route-map\n"
3991 "on ibgp neighbors\n")
8bd9d948 3992{
87ce2564
CS
3993 nb_cli_enqueue_change(vty,
3994 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 3995 NB_OP_MODIFY, "true");
8bd9d948 3996
ff8a8a7a
CS
3997 return nb_cli_apply_changes(vty, NULL);
3998}
8bd9d948 3999
ff8a8a7a
CS
4000DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
4001 no_bgp_rr_allow_outbound_policy_cmd,
4002 "no bgp route-reflector allow-outbound-policy",
4003 NO_STR
4004 "BGP specific commands\n"
4005 "Allow modifications made by out route-map\n"
4006 "on ibgp neighbors\n")
4007{
87ce2564
CS
4008 nb_cli_enqueue_change(vty,
4009 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
4010 NB_OP_MODIFY, "false");
4011
4012 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
4013}
4014
ff8a8a7a
CS
4015
4016void cli_show_router_global_neighbor_config(struct vty *vty,
4017 struct lyd_node *dnode,
4018 bool show_defaults)
8bd9d948 4019{
ff8a8a7a
CS
4020 uint32_t write_quanta, read_quanta;
4021
4022 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
4023 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 4024
ff8a8a7a
CS
4025 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
4026 uint32_t listen_limit = yang_dnode_get_uint32(
4027 dnode, "./dynamic-neighbors-limit");
4028 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 4029 }
8bd9d948 4030
ff8a8a7a
CS
4031 write_quanta = yang_dnode_get_uint32(
4032 dnode, "./packet-quanta-config/wpkt-quanta");
4033 if (write_quanta != BGP_WRITE_PACKET_MAX)
4034 vty_out(vty, " write-quanta %d\n", write_quanta);
4035
4036 read_quanta = yang_dnode_get_uint32(
4037 dnode, "./packet-quanta-config/rpkt-quanta");
4038
4039 if (read_quanta != BGP_READ_PACKET_MAX)
4040 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
4041}
4042
ff8a8a7a
CS
4043DEFUN_YANG(bgp_listen_limit,
4044 bgp_listen_limit_cmd,
5b1b6b8b 4045 "bgp listen limit (1-65535)",
ff8a8a7a
CS
4046 "BGP specific commands\n"
4047 "BGP Dynamic Neighbors listen commands\n"
4048 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4049 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4050{
d62a17ae 4051 int idx_number = 3;
f14e6fdb 4052
ff8a8a7a 4053 nb_cli_enqueue_change(
87ce2564 4054 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 4055 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 4056
ff8a8a7a 4057 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4058}
4059
ff8a8a7a
CS
4060DEFUN_YANG(no_bgp_listen_limit,
4061 no_bgp_listen_limit_cmd,
5b1b6b8b 4062 "no bgp listen limit [(1-65535)]",
ff8a8a7a
CS
4063 NO_STR
4064 "BGP specific commands\n"
4065 "BGP Dynamic Neighbors listen commands\n"
4066 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4067 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4068{
ff8a8a7a 4069 nb_cli_enqueue_change(
87ce2564 4070 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
4071 NB_OP_DESTROY, NULL);
4072
4073 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4074}
4075
4076
20eb8864 4077/*
4078 * Check if this listen range is already configured. Check for exact
4079 * match or overlap based on input.
4080 */
d62a17ae 4081static struct peer_group *listen_range_exists(struct bgp *bgp,
4082 struct prefix *range, int exact)
4083{
4084 struct listnode *node, *nnode;
4085 struct listnode *node1, *nnode1;
4086 struct peer_group *group;
4087 struct prefix *lr;
4088 afi_t afi;
4089 int match;
4090
4091 afi = family2afi(range->family);
4092 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4093 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4094 lr)) {
4095 if (exact)
4096 match = prefix_same(range, lr);
4097 else
4098 match = (prefix_match(range, lr)
4099 || prefix_match(lr, range));
4100 if (match)
4101 return group;
4102 }
4103 }
4104
4105 return NULL;
20eb8864 4106}
4107
f14e6fdb
DS
4108DEFUN (bgp_listen_range,
4109 bgp_listen_range_cmd,
d7b9898c 4110 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 4111 "BGP specific commands\n"
d7fa34c1
QY
4112 "Configure BGP dynamic neighbors listen range\n"
4113 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4114 NEIGHBOR_ADDR_STR
4115 "Member of the peer-group\n"
4116 "Peer-group name\n")
f14e6fdb 4117{
d62a17ae 4118 VTY_DECLVAR_CONTEXT(bgp, bgp);
4119 struct prefix range;
4120 struct peer_group *group, *existing_group;
4121 afi_t afi;
4122 int ret;
4123 int idx = 0;
4124
4125 argv_find(argv, argc, "A.B.C.D/M", &idx);
4126 argv_find(argv, argc, "X:X::X:X/M", &idx);
4127 char *prefix = argv[idx]->arg;
d7b9898c 4128 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4129 char *peergroup = argv[idx]->arg;
4130
4131 /* Convert IP prefix string to struct prefix. */
4132 ret = str2prefix(prefix, &range);
4133 if (!ret) {
4134 vty_out(vty, "%% Malformed listen range\n");
4135 return CMD_WARNING_CONFIG_FAILED;
4136 }
4137
4138 afi = family2afi(range.family);
4139
4140 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4141 vty_out(vty,
4142 "%% Malformed listen range (link-local address)\n");
4143 return CMD_WARNING_CONFIG_FAILED;
4144 }
4145
4146 apply_mask(&range);
4147
4148 /* Check if same listen range is already configured. */
4149 existing_group = listen_range_exists(bgp, &range, 1);
4150 if (existing_group) {
4151 if (strcmp(existing_group->name, peergroup) == 0)
4152 return CMD_SUCCESS;
4153 else {
4154 vty_out(vty,
4155 "%% Same listen range is attached to peer-group %s\n",
4156 existing_group->name);
4157 return CMD_WARNING_CONFIG_FAILED;
4158 }
4159 }
4160
4161 /* Check if an overlapping listen range exists. */
4162 if (listen_range_exists(bgp, &range, 0)) {
4163 vty_out(vty,
4164 "%% Listen range overlaps with existing listen range\n");
4165 return CMD_WARNING_CONFIG_FAILED;
4166 }
4167
4168 group = peer_group_lookup(bgp, peergroup);
4169 if (!group) {
4170 vty_out(vty, "%% Configure the peer-group first\n");
4171 return CMD_WARNING_CONFIG_FAILED;
4172 }
4173
4174 ret = peer_group_listen_range_add(group, &range);
4175 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4176}
4177
4178DEFUN (no_bgp_listen_range,
4179 no_bgp_listen_range_cmd,
d7b9898c 4180 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4181 NO_STR
f14e6fdb 4182 "BGP specific commands\n"
d7fa34c1
QY
4183 "Unconfigure BGP dynamic neighbors listen range\n"
4184 "Unconfigure BGP dynamic neighbors listen range\n"
4185 NEIGHBOR_ADDR_STR
4186 "Member of the peer-group\n"
4187 "Peer-group name\n")
f14e6fdb 4188{
d62a17ae 4189 VTY_DECLVAR_CONTEXT(bgp, bgp);
4190 struct prefix range;
4191 struct peer_group *group;
4192 afi_t afi;
4193 int ret;
4194 int idx = 0;
4195
4196 argv_find(argv, argc, "A.B.C.D/M", &idx);
4197 argv_find(argv, argc, "X:X::X:X/M", &idx);
4198 char *prefix = argv[idx]->arg;
21d88a71 4199 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4200 char *peergroup = argv[idx]->arg;
4201
4202 /* Convert IP prefix string to struct prefix. */
4203 ret = str2prefix(prefix, &range);
4204 if (!ret) {
4205 vty_out(vty, "%% Malformed listen range\n");
4206 return CMD_WARNING_CONFIG_FAILED;
4207 }
4208
4209 afi = family2afi(range.family);
4210
4211 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4212 vty_out(vty,
4213 "%% Malformed listen range (link-local address)\n");
4214 return CMD_WARNING_CONFIG_FAILED;
4215 }
4216
4217 apply_mask(&range);
4218
4219 group = peer_group_lookup(bgp, peergroup);
4220 if (!group) {
4221 vty_out(vty, "%% Peer-group does not exist\n");
4222 return CMD_WARNING_CONFIG_FAILED;
4223 }
4224
4225 ret = peer_group_listen_range_del(group, &range);
4226 return bgp_vty_return(vty, ret);
4227}
4228
2b791107 4229void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4230{
4231 struct peer_group *group;
4232 struct listnode *node, *nnode, *rnode, *nrnode;
4233 struct prefix *range;
4234 afi_t afi;
d62a17ae 4235
4236 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4237 vty_out(vty, " bgp listen limit %d\n",
4238 bgp->dynamic_neighbors_limit);
4239
4240 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4241 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4242 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4243 nrnode, range)) {
d62a17ae 4244 vty_out(vty,
2dbe669b
DA
4245 " bgp listen range %pFX peer-group %s\n",
4246 range, group->name);
d62a17ae 4247 }
4248 }
4249 }
f14e6fdb
DS
4250}
4251
4252
ff8a8a7a
CS
4253DEFUN_YANG(bgp_disable_connected_route_check,
4254 bgp_disable_connected_route_check_cmd,
4255 "bgp disable-ebgp-connected-route-check",
4256 "BGP specific commands\n"
4257 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4258{
87ce2564
CS
4259 nb_cli_enqueue_change(vty,
4260 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4261 NB_OP_MODIFY, "true");
7aafcaca 4262
ff8a8a7a 4263 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
4264}
4265
ff8a8a7a
CS
4266DEFUN_YANG(no_bgp_disable_connected_route_check,
4267 no_bgp_disable_connected_route_check_cmd,
4268 "no bgp disable-ebgp-connected-route-check",
4269 NO_STR
4270 "BGP specific commands\n"
4271 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4272{
87ce2564
CS
4273 nb_cli_enqueue_change(vty,
4274 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4275 NB_OP_MODIFY, "false");
d62a17ae 4276
ff8a8a7a 4277 return nb_cli_apply_changes(vty, NULL);
d62a17ae 4278}
4279
ff8a8a7a
CS
4280void cli_show_router_global_ebgp_multihop_connected_route_check(
4281 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4282{
4283 if (yang_dnode_get_bool(dnode, NULL))
4284 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4285}
d62a17ae 4286
ff8a8a7a
CS
4287DEFUN_YANG(bgp_default_shutdown,
4288 bgp_default_shutdown_cmd,
4289 "[no] bgp default shutdown",
4290 NO_STR BGP_STR
4291 "Configure BGP defaults\n"
4292 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4293{
87ce2564 4294 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4295 strmatch(argv[0]->text, "no") ? "false" : "true");
4296
4297 return nb_cli_apply_changes(vty, NULL);
4298}
4299
4300void cli_show_router_bgp_default_shutdown(struct vty *vty,
4301 struct lyd_node *dnode,
4302 bool show_defaults)
4303{
4304 if (yang_dnode_get_bool(dnode, NULL))
4305 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4306}
4307
736b68f3
DS
4308DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4309 BGP_STR
9ddf4b81 4310 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4311 "Add a shutdown message (RFC 8203)\n"
4312 "Shutdown message\n")
9cf59432 4313{
736b68f3 4314 char *msgstr = NULL;
8389c83a 4315
9cf59432
DS
4316 VTY_DECLVAR_CONTEXT(bgp, bgp);
4317
8389c83a 4318 if (argc > 3)
f80e35b6 4319 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4320
4321 bgp_shutdown_enable(bgp, msgstr);
4322 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4323
4324 return CMD_SUCCESS;
4325}
4326
736b68f3 4327DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4328 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4329{
4330 VTY_DECLVAR_CONTEXT(bgp, bgp);
4331
4332 bgp_shutdown_enable(bgp, NULL);
4333
4334 return CMD_SUCCESS;
4335}
8389c83a 4336
736b68f3 4337DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4338 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4339{
4340 VTY_DECLVAR_CONTEXT(bgp, bgp);
4341
4342 bgp_shutdown_disable(bgp);
4343
4344 return CMD_SUCCESS;
4345}
4346
9ddf4b81 4347ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4348 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4349 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4350 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4351
f4b8ec07
CS
4352DEFUN_YANG(neighbor_remote_as,
4353 neighbor_remote_as_cmd,
4354 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4355 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4356 "Specify a BGP neighbor\n" AS_STR
4357 "Internal BGP peer\n"
4358 "External BGP peer\n")
718e3744 4359{
d62a17ae 4360 int idx_peer = 1;
4361 int idx_remote_as = 3;
f4b8ec07
CS
4362 char base_xpath[XPATH_MAXLEN];
4363 char unnbr_xpath[XPATH_MAXLEN];
4364 char prgrp_xpath[XPATH_MAXLEN];
4365 union sockunion su;
4366 const char *as_type_str = "as-specified";
4367
4368 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4369 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4370 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4371
4372 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4373 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4374
3bb513c3
CH
4375 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4376 VTY_CURR_XPATH, unnbr_xpath + 1)) {
f4b8ec07 4377 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
3bb513c3
CH
4378 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4379 "%s%s", VTY_CURR_XPATH,
4380 prgrp_xpath + 1)) {
f4b8ec07
CS
4381 snprintf(base_xpath, sizeof(base_xpath),
4382 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4383 "");
4384 } else {
4385 vty_out(vty,
4386 "%% Create the peer-group or interface first\n");
4387 return CMD_WARNING_CONFIG_FAILED;
4388 }
4389 } else {
4390 snprintf(base_xpath, sizeof(base_xpath),
4391 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4392 }
4393
4394 if (argv[idx_remote_as]->arg[0] == 'i') {
4395 as_type_str = "internal";
4396 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4397 as_type_str = "external";
4398 } else {
4399 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4400 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4401 }
4402 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4403 NB_OP_MODIFY, as_type_str);
4404
4405 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4406}
4407
e84c59af
DA
4408int peer_conf_interface_create(struct bgp *bgp, const char *conf_if,
4409 bool v6only, const char *peer_group_name,
4410 int as_type, as_t as, char *errmsg,
4411 size_t errmsg_len)
d62a17ae 4412{
d62a17ae 4413 struct peer *peer;
4414 struct peer_group *group;
4415 int ret = 0;
d62a17ae 4416
4417 group = peer_group_lookup(bgp, conf_if);
4418
4419 if (group) {
f4b8ec07
CS
4420 snprintf(errmsg, errmsg_len,
4421 "Name conflict with peer-group \n");
4422 return -1;
d62a17ae 4423 }
4424
4425 peer = peer_lookup_by_conf_if(bgp, conf_if);
4426 if (peer) {
f4b8ec07 4427 if (as_type != AS_UNSPECIFIED)
e84c59af 4428 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4429 } else {
e84c59af
DA
4430 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4431 NULL);
d62a17ae 4432
4433 if (!peer) {
f4b8ec07
CS
4434 snprintf(errmsg, errmsg_len,
4435 "BGP failed to create peer\n");
4436 return -1;
d62a17ae 4437 }
4438
4439 if (v6only)
527de3dc 4440 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4441
4442 /* Request zebra to initiate IPv6 RAs on this interface. We do
4443 * this
4444 * any unnumbered peer in order to not worry about run-time
4445 * transitions
4446 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4447 * address
4448 * gets deleted later etc.)
4449 */
4450 if (peer->ifp)
4451 bgp_zebra_initiate_radv(bgp, peer);
4452 }
4453
4454 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4455 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4456 if (v6only)
527de3dc 4457 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4458 else
527de3dc 4459 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4460
4461 /* v6only flag changed. Reset bgp seesion */
4462 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4463 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4464 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4465 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4466 } else
4467 bgp_session_reset(peer);
4468 }
4469
9fb964de
PM
4470 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4471 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4472 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4473 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4474 }
d62a17ae 4475
4476 if (peer_group_name) {
4477 group = peer_group_lookup(bgp, peer_group_name);
4478 if (!group) {
f4b8ec07
CS
4479 snprintf(errmsg, errmsg_len,
4480 "Configure the peer-group first\n");
4481 return -1;
d62a17ae 4482 }
4483
8395c1f8 4484 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4485 }
4486
f4b8ec07 4487 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
a80beece
DS
4488}
4489
232c75cd
CS
4490DEFUN_YANG(neighbor_interface_config,
4491 neighbor_interface_config_cmd,
f4b8ec07
CS
4492 "neighbor WORD interface [peer-group PGNAME]",
4493 NEIGHBOR_STR
4494 "Interface name or neighbor tag\n"
4495 "Enable BGP on interface\n"
4496 "Member of the peer-group\n"
4497 "Peer-group name\n")
4c48cf63 4498{
d62a17ae 4499 int idx_word = 1;
4500 int idx_peer_group_word = 4;
f4b8ec07
CS
4501 char base_xpath[XPATH_MAXLEN];
4502
4503 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4504 argv[idx_word]->arg, "");
31500417 4505
f4b8ec07 4506 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4507 if (argc > idx_peer_group_word)
f4b8ec07
CS
4508 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4509 argv[idx_peer_group_word]->arg);
4510
4511 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4512}
4513
f4b8ec07
CS
4514DEFUN_YANG(neighbor_interface_config_v6only,
4515 neighbor_interface_config_v6only_cmd,
4516 "neighbor WORD interface v6only [peer-group PGNAME]",
4517 NEIGHBOR_STR
4518 "Interface name or neighbor tag\n"
4519 "Enable BGP on interface\n"
4520 "Enable BGP with v6 link-local only\n"
4521 "Member of the peer-group\n"
4522 "Peer-group name\n")
4c48cf63 4523{
d62a17ae 4524 int idx_word = 1;
4525 int idx_peer_group_word = 5;
f4b8ec07
CS
4526 char base_xpath[XPATH_MAXLEN];
4527
4528 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4529 argv[idx_word]->arg, "");
31500417 4530
f4b8ec07 4531 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4532 if (argc > idx_peer_group_word)
f4b8ec07
CS
4533 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4534 argv[idx_peer_group_word]->arg);
31500417 4535
f4b8ec07
CS
4536 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4537
4538 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4539}
4540
a80beece 4541
f4b8ec07
CS
4542DEFUN_YANG(
4543 neighbor_interface_config_remote_as,
4544 neighbor_interface_config_remote_as_cmd,
4545 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4546 NEIGHBOR_STR
4547 "Interface name or neighbor tag\n"
4548 "Enable BGP on interface\n"
4549 "Specify a BGP neighbor\n" AS_STR
4550 "Internal BGP peer\n"
4551 "External BGP peer\n")
b3a39dc5 4552{
d62a17ae 4553 int idx_word = 1;
4554 int idx_remote_as = 4;
f4b8ec07
CS
4555 char base_xpath[XPATH_MAXLEN];
4556 const char *as_type_str = "as-specified";
4557
4558 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4559 argv[idx_word]->arg, "");
4560
4561 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4562
4563 if (argv[idx_remote_as]->arg[0] == 'i') {
4564 as_type_str = "internal";
4565 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4566 as_type_str = "external";
4567 } else {
4568 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4569 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4570 }
4571 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4572 NB_OP_MODIFY, as_type_str);
4573
4574 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4575}
4576
f4b8ec07
CS
4577DEFUN_YANG(
4578 neighbor_interface_v6only_config_remote_as,
4579 neighbor_interface_v6only_config_remote_as_cmd,
4580 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4581 NEIGHBOR_STR
4582 "Interface name or neighbor tag\n"
4583 "Enable BGP with v6 link-local only\n"
4584 "Enable BGP on interface\n"
4585 "Specify a BGP neighbor\n" AS_STR
4586 "Internal BGP peer\n"
4587 "External BGP peer\n")
b3a39dc5 4588{
d62a17ae 4589 int idx_word = 1;
4590 int idx_remote_as = 5;
f4b8ec07
CS
4591 char base_xpath[XPATH_MAXLEN];
4592 const char *as_type_str = "as-specified";
4593
4594 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4595 argv[idx_word]->arg, "");
4596
4597 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4598
4599 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4600
4601 if (argv[idx_remote_as]->arg[0] == 'i') {
4602 as_type_str = "internal";
4603 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4604 as_type_str = "external";
4605 } else {
4606 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4607 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4608 }
4609 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4610 NB_OP_MODIFY, as_type_str);
4611
4612 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4613}
4614
f4b8ec07
CS
4615DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4616 "neighbor WORD peer-group",
4617 NEIGHBOR_STR
4618 "Interface name or neighbor tag\n"
4619 "Configure peer-group\n")
718e3744 4620{
f4b8ec07 4621 char base_xpath[XPATH_MAXLEN];
d62a17ae 4622 int idx_word = 1;
718e3744 4623
f4b8ec07
CS
4624 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4625 argv[idx_word]->arg, "");
718e3744 4626
f4b8ec07 4627 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 4628
f4b8ec07 4629 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4630}
4631
232c75cd
CS
4632DEFUN_YANG(no_neighbor,
4633 no_neighbor_cmd,
4634 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4635 NO_STR NEIGHBOR_STR
4636 NEIGHBOR_ADDR_STR2
4637 "Specify a BGP neighbor\n" AS_STR
4638 "Internal BGP peer\n"
4639 "External BGP peer\n")
718e3744 4640{
d62a17ae 4641 int idx_peer = 2;
f4b8ec07
CS
4642 char base_xpath[XPATH_MAXLEN];
4643 char num_xpath[XPATH_MAXLEN];
4644 char unnbr_xpath[XPATH_MAXLEN];
4645 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4646 union sockunion su;
d62a17ae 4647
f4b8ec07
CS
4648 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4649 snprintf(num_xpath, sizeof(num_xpath),
4650 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
3bb513c3
CH
4651 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4652 VTY_CURR_XPATH, num_xpath + 1)) {
f4b8ec07 4653 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
d62a17ae 4654 }
f4b8ec07
CS
4655 } else {
4656 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4657 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4658
4659 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4660 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4661
3bb513c3
CH
4662 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4663 VTY_CURR_XPATH, unnbr_xpath + 1)) {
f4b8ec07 4664 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
3bb513c3
CH
4665 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4666 "%s%s", VTY_CURR_XPATH,
4667 prgrp_xpath + 1)) {
f4b8ec07 4668 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4e2786df 4669 } else {
f4b8ec07
CS
4670 vty_out(vty,
4671 "%% Create the peer-group or interface first\n");
d62a17ae 4672 return CMD_WARNING_CONFIG_FAILED;
4673 }
1ff9a340 4674 }
718e3744 4675
f4b8ec07
CS
4676 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4677
4678 return nb_cli_apply_changes(vty, NULL);
718e3744 4679}
4680
f4b8ec07
CS
4681DEFUN_YANG(no_neighbor_interface_config,
4682 no_neighbor_interface_config_cmd,
4683 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4684 NO_STR NEIGHBOR_STR
4685 "Interface name\n"
4686 "Configure BGP on interface\n"
4687 "Enable BGP with v6 link-local only\n"
4688 "Member of the peer-group\n"
4689 "Peer-group name\n"
4690 "Specify a BGP neighbor\n" AS_STR
4691 "Internal BGP peer\n"
4692 "External BGP peer\n")
a80beece 4693{
d62a17ae 4694 int idx_word = 2;
f4b8ec07 4695 char base_xpath[XPATH_MAXLEN];
d62a17ae 4696
f4b8ec07
CS
4697 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4698 argv[idx_word]->arg, "");
4699
4700 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4701
4702 return nb_cli_apply_changes(vty, base_xpath);
a80beece
DS
4703}
4704
f4b8ec07
CS
4705DEFUN_YANG(no_neighbor_peer_group,
4706 no_neighbor_peer_group_cmd,
4707 "no neighbor WORD peer-group",
4708 NO_STR NEIGHBOR_STR
4709 "Neighbor tag\n"
4710 "Configure peer-group\n")
718e3744 4711{
f4b8ec07 4712 char base_xpath[XPATH_MAXLEN];
d62a17ae 4713 int idx_word = 2;
718e3744 4714
f4b8ec07
CS
4715 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4716 argv[idx_word]->arg, "");
4717
4718 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4719
4720 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4721}
4722
f4b8ec07
CS
4723DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4724 no_neighbor_interface_peer_group_remote_as_cmd,
4725 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4726 NO_STR NEIGHBOR_STR
4727 "Interface name or neighbor tag\n"
4728 "Specify a BGP neighbor\n" AS_STR
4729 "Internal BGP peer\n"
4730 "External BGP peer\n")
718e3744 4731{
f4b8ec07
CS
4732 int idx_peer = 2;
4733 char base_xpath[XPATH_MAXLEN];
4734 char unnbr_xpath[XPATH_MAXLEN];
4735 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4736
f4b8ec07
CS
4737 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4738 argv[idx_peer]->arg, "");
d62a17ae 4739
f4b8ec07
CS
4740 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4741 argv[idx_peer]->arg, "");
4742
3bb513c3
CH
4743 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4744 VTY_CURR_XPATH, unnbr_xpath + 1)) {
f4b8ec07 4745 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
3bb513c3
CH
4746 } else if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4747 VTY_CURR_XPATH, prgrp_xpath + 1)) {
f4b8ec07
CS
4748 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4749 } else {
d62a17ae 4750 vty_out(vty, "%% Create the peer-group or interface first\n");
4751 return CMD_WARNING_CONFIG_FAILED;
4752 }
f4b8ec07
CS
4753
4754 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4755 sizeof(base_xpath));
4756
4757 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4758
4759 return nb_cli_apply_changes(vty, NULL);
718e3744 4760}
6b0655a2 4761
f4b8ec07
CS
4762DEFUN_YANG(neighbor_local_as,
4763 neighbor_local_as_cmd,
4764 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4765 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4766 "Specify a local-as number\n"
4767 "AS number used as local AS\n")
718e3744 4768{
d62a17ae 4769 int idx_peer = 1;
4770 int idx_number = 3;
f4b8ec07 4771 char base_xpath[XPATH_MAXLEN];
718e3744 4772
f4b8ec07
CS
4773 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4774 sizeof(base_xpath), NULL)
4775 < 0)
d62a17ae 4776 return CMD_WARNING_CONFIG_FAILED;
718e3744 4777
f4b8ec07
CS
4778 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4779 argv[idx_number]->arg);
4780
4781 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4782}
4783
f4b8ec07
CS
4784DEFUN_YANG(
4785 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4786 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4787 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4788 "Specify a local-as number\n"
4789 "AS number used as local AS\n"
4790 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4791{
d62a17ae 4792 int idx_peer = 1;
4793 int idx_number = 3;
f4b8ec07 4794 char base_xpath[XPATH_MAXLEN];
718e3744 4795
f4b8ec07
CS
4796 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4797 sizeof(base_xpath), NULL)
4798 < 0)
d62a17ae 4799 return CMD_WARNING_CONFIG_FAILED;
718e3744 4800
f4b8ec07
CS
4801 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4802 argv[idx_number]->arg);
4803 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4804 "true");
4805
4806 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4807}
4808
f4b8ec07
CS
4809DEFUN_YANG(
4810 neighbor_local_as_no_prepend_replace_as,
4811 neighbor_local_as_no_prepend_replace_as_cmd,
4812 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4813 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4814 "Specify a local-as number\n"
4815 "AS number used as local AS\n"
4816 "Do not prepend local-as to updates from ebgp peers\n"
4817 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4818{
d62a17ae 4819 int idx_peer = 1;
4820 int idx_number = 3;
f4b8ec07 4821 char base_xpath[XPATH_MAXLEN];
9d3f9705 4822
f4b8ec07
CS
4823 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4824 sizeof(base_xpath), NULL)
4825 < 0)
d62a17ae 4826 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4827
f4b8ec07
CS
4828 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4829 argv[idx_number]->arg);
4830 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4831 "true");
ba51dd26 4832 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
f4b8ec07
CS
4833 "true");
4834
4835 return nb_cli_apply_changes(vty, base_xpath);
9d3f9705
AC
4836}
4837
f4b8ec07
CS
4838DEFUN_YANG(no_neighbor_local_as,
4839 no_neighbor_local_as_cmd,
4840 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4841 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4842 "Specify a local-as number\n"
4843 "AS number used as local AS\n"
4844 "Do not prepend local-as to updates from ebgp peers\n"
4845 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4846{
d62a17ae 4847 int idx_peer = 2;
f4b8ec07 4848 char base_xpath[XPATH_MAXLEN];
718e3744 4849
f4b8ec07
CS
4850 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4851 sizeof(base_xpath), NULL)
4852 < 0)
d62a17ae 4853 return CMD_WARNING_CONFIG_FAILED;
718e3744 4854
f4b8ec07
CS
4855 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4856 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4857 "false");
ba51dd26 4858 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
f4b8ec07
CS
4859 "false");
4860
4861 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4862}
4863
718e3744 4864
3f9c7369
DS
4865DEFUN (neighbor_solo,
4866 neighbor_solo_cmd,
9ccf14f7 4867 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4868 NEIGHBOR_STR
4869 NEIGHBOR_ADDR_STR2
4870 "Solo peer - part of its own update group\n")
4871{
d62a17ae 4872 int idx_peer = 1;
4873 struct peer *peer;
4874 int ret;
3f9c7369 4875
d62a17ae 4876 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4877 if (!peer)
4878 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4879
d62a17ae 4880 ret = update_group_adjust_soloness(peer, 1);
4881 return bgp_vty_return(vty, ret);
3f9c7369
DS
4882}
4883
4884DEFUN (no_neighbor_solo,
4885 no_neighbor_solo_cmd,
9ccf14f7 4886 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4887 NO_STR
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
4890 "Solo peer - part of its own update group\n")
4891{
d62a17ae 4892 int idx_peer = 2;
4893 struct peer *peer;
4894 int ret;
3f9c7369 4895
d62a17ae 4896 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4897 if (!peer)
4898 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4899
d62a17ae 4900 ret = update_group_adjust_soloness(peer, 0);
4901 return bgp_vty_return(vty, ret);
3f9c7369
DS
4902}
4903
f4b8ec07
CS
4904DEFUN_YANG(neighbor_password,
4905 neighbor_password_cmd,
4906 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4908 "Set a password\n"
4909 "The password\n")
0df7c91f 4910{
d62a17ae 4911 int idx_peer = 1;
4912 int idx_line = 3;
f4b8ec07 4913 char base_xpath[XPATH_MAXLEN];
0df7c91f 4914
f4b8ec07
CS
4915 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4916 sizeof(base_xpath), NULL)
4917 < 0)
d62a17ae 4918 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4919
f4b8ec07
CS
4920 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4921 argv[idx_line]->arg);
4922
4923 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f
PJ
4924}
4925
f4b8ec07
CS
4926DEFUN_YANG(no_neighbor_password,
4927 no_neighbor_password_cmd,
4928 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4929 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4930 "Set a password\n"
4931 "The password\n")
0df7c91f 4932{
d62a17ae 4933 int idx_peer = 2;
f4b8ec07 4934 char base_xpath[XPATH_MAXLEN];
0df7c91f 4935
f4b8ec07
CS
4936 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4937 sizeof(base_xpath), NULL)
4938 < 0)
d62a17ae 4939 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4940
f4b8ec07
CS
4941 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4942
4943 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f 4944}
6b0655a2 4945
f4b8ec07
CS
4946DEFUN_YANG(neighbor_activate,
4947 neighbor_activate_cmd,
4948 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4950 "Enable the Address Family for this Neighbor\n")
718e3744 4951{
d62a17ae 4952 int idx_peer = 1;
f4b8ec07 4953 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
4954 char af_xpath[XPATH_MAXLEN];
4955 afi_t afi = bgp_node_afi(vty);
4956 safi_t safi = bgp_node_safi(vty);
718e3744 4957
f4b8ec07
CS
4958 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4959 yang_afi_safi_value2identity(afi, safi));
555c8ab7
CS
4960 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4961 sizeof(base_xpath), af_xpath)
f4b8ec07 4962 < 0)
d62a17ae 4963 return CMD_WARNING_CONFIG_FAILED;
718e3744 4964
555c8ab7 4965 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
f4b8ec07
CS
4966
4967 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4968}
4969
d62a17ae 4970ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4971 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4972 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4973 "Enable the Address Family for this Neighbor\n")
596c17ba 4974
f4b8ec07
CS
4975DEFUN_YANG(no_neighbor_activate,
4976 no_neighbor_activate_cmd,
4977 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4978 NO_STR NEIGHBOR_STR
4979 NEIGHBOR_ADDR_STR2
4980 "Enable the Address Family for this Neighbor\n")
718e3744 4981{
d62a17ae 4982 int idx_peer = 2;
f4b8ec07
CS
4983 char base_xpath[XPATH_MAXLEN];
4984 char af_xpath[XPATH_MAXLEN];
4985 afi_t afi = bgp_node_afi(vty);
4986 safi_t safi = bgp_node_safi(vty);
718e3744 4987
f4b8ec07
CS
4988 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4989 yang_afi_safi_value2identity(afi, safi));
4990
4991 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4992 sizeof(base_xpath), af_xpath)
4993 < 0)
d62a17ae 4994 return CMD_WARNING_CONFIG_FAILED;
718e3744 4995
f4b8ec07
CS
4996 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4997
4998 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4999}
6b0655a2 5000
d62a17ae 5001ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5002 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5003 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5004 "Enable the Address Family for this Neighbor\n")
596c17ba 5005
2a059a54
DS
5006DEFUN (neighbor_set_peer_group,
5007 neighbor_set_peer_group_cmd,
5008 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5009 NEIGHBOR_STR
5010 NEIGHBOR_ADDR_STR2
5011 "Member of the peer-group\n"
5012 "Peer-group name\n")
718e3744 5013{
2a059a54 5014 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5015 int idx_peer = 1;
5016 int idx_word = 3;
2a059a54
DS
5017 int ret;
5018 as_t as;
5019 union sockunion su;
5020 struct peer *peer;
5021 struct peer_group *group;
d62a17ae 5022
2a059a54
DS
5023 ret = str2sockunion(argv[idx_peer]->arg, &su);
5024 if (ret < 0) {
5025 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5026 if (!peer) {
5027 vty_out(vty, "%% Malformed address or name: %s\n",
5028 argv[idx_peer]->arg);
5029 return CMD_WARNING_CONFIG_FAILED;
5030 }
5031 } else {
5032 if (peer_address_self_check(bgp, &su)) {
5033 vty_out(vty,
5034 "%% Can not configure the local system as neighbor\n");
5035 return CMD_WARNING_CONFIG_FAILED;
5036 }
5037
5038 /* Disallow for dynamic neighbor. */
5039 peer = peer_lookup(bgp, &su);
5040 if (peer && peer_dynamic_neighbor(peer)) {
5041 vty_out(vty,
5042 "%% Operation not allowed on a dynamic neighbor\n");
5043 return CMD_WARNING_CONFIG_FAILED;
5044 }
5045 }
5046
5047 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5048 if (!group) {
5049 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5050 return CMD_WARNING_CONFIG_FAILED;
2a059a54 5051 }
d62a17ae 5052
2a059a54 5053 ret = peer_group_bind(bgp, &su, peer, group, &as);
d62a17ae 5054
2a059a54
DS
5055 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5056 vty_out(vty,
5057 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5058 as);
5059 return CMD_WARNING_CONFIG_FAILED;
5060 }
5061
5062 return bgp_vty_return(vty, ret);
d62a17ae 5063}
5064
5065ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5066 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5067 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5068 "Member of the peer-group\n"
5069 "Peer-group name\n")
596c17ba 5070
f4b8ec07
CS
5071DEFUN_YANG (no_neighbor_set_peer_group,
5072 no_neighbor_set_peer_group_cmd,
71cc0c88 5073 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
f4b8ec07
CS
5074 NO_STR
5075 NEIGHBOR_STR
5076 NEIGHBOR_ADDR_STR2
5077 "Member of the peer-group\n"
5078 "Peer-group name\n")
718e3744 5079{
d62a17ae 5080 int idx_peer = 2;
f4b8ec07 5081 char base_xpath[XPATH_MAXLEN];
d62a17ae 5082
f4b8ec07
CS
5083 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5084 sizeof(base_xpath), NULL)
5085 < 0)
d62a17ae 5086 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5087
f4b8ec07 5088 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
718e3744 5089
f4b8ec07 5090 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5091}
6b0655a2 5092
d62a17ae 5093ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5094 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5095 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5096 "Member of the peer-group\n"
5097 "Peer-group name\n")
596c17ba 5098
d62a17ae 5099static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5100 uint32_t flag, int set)
718e3744 5101{
d62a17ae 5102 int ret;
5103 struct peer *peer;
718e3744 5104
d62a17ae 5105 peer = peer_and_group_lookup_vty(vty, ip_str);
5106 if (!peer)
5107 return CMD_WARNING_CONFIG_FAILED;
718e3744 5108
7ebe625c
QY
5109 /*
5110 * If 'neighbor <interface>', then this is for directly connected peers,
5111 * we should not accept disable-connected-check.
5112 */
5113 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5114 vty_out(vty,
3efd0893 5115 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5116 ip_str);
5117 return CMD_WARNING_CONFIG_FAILED;
5118 }
5119
d62a17ae 5120 if (!set && flag == PEER_FLAG_SHUTDOWN)
5121 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5122
d62a17ae 5123 if (set)
5124 ret = peer_flag_set(peer, flag);
5125 else
5126 ret = peer_flag_unset(peer, flag);
718e3744 5127
d62a17ae 5128 return bgp_vty_return(vty, ret);
718e3744 5129}
5130
47cbc09b 5131static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5132{
d62a17ae 5133 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5134}
5135
d62a17ae 5136static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5137 uint32_t flag)
718e3744 5138{
d62a17ae 5139 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5140}
5141
f4b8ec07
CS
5142int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5143 uint32_t flag, bool set, char *errmsg,
5144 size_t errmsg_len)
5145{
5146 int ret;
5147
5148 /*
5149 * If 'neighbor <interface>', then this is for directly connected peers,
5150 * we should not accept disable-connected-check.
5151 */
5152 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5153 snprintf(
5154 errmsg, errmsg_len,
5155 "%s is directly connected peer, cannot accept disable-connected-check\n",
5156 ip_str);
5157 return -1;
5158 }
5159
5160 if (!set && flag == PEER_FLAG_SHUTDOWN)
5161 peer_tx_shutdown_message_unset(peer);
5162
5163 if (set)
5164 ret = peer_flag_set(peer, flag);
5165 else
5166 ret = peer_flag_unset(peer, flag);
5167
5168 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5169}
5170
718e3744 5171/* neighbor passive. */
f4b8ec07
CS
5172DEFUN_YANG(neighbor_passive,
5173 neighbor_passive_cmd,
5174 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5175 NEIGHBOR_STR
5176 NEIGHBOR_ADDR_STR2
5177 "Don't send open messages to this neighbor\n")
718e3744 5178{
d62a17ae 5179 int idx_peer = 1;
f4b8ec07
CS
5180 char base_xpath[XPATH_MAXLEN];
5181
5182 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5183 sizeof(base_xpath), NULL)
5184 < 0)
5185 return CMD_WARNING_CONFIG_FAILED;
5186
5187 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5188
5189 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5190}
5191
f4b8ec07
CS
5192DEFUN_YANG(no_neighbor_passive,
5193 no_neighbor_passive_cmd,
5194 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5195 NO_STR NEIGHBOR_STR
5196 NEIGHBOR_ADDR_STR2
5197 "Don't send open messages to this neighbor\n")
718e3744 5198{
d62a17ae 5199 int idx_peer = 2;
f4b8ec07
CS
5200 char base_xpath[XPATH_MAXLEN];
5201
5202 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5203 sizeof(base_xpath), NULL)
5204 < 0)
5205 return CMD_WARNING_CONFIG_FAILED;
5206
5207 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5208
5209 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5210}
6b0655a2 5211
718e3744 5212/* neighbor shutdown. */
f4b8ec07
CS
5213DEFUN_YANG(neighbor_shutdown_msg,
5214 neighbor_shutdown_msg_cmd,
5215 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5216 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5217 "Administratively shut down this neighbor\n"
5218 "Add a shutdown message (RFC 8203)\n"
5219 "Shutdown message\n")
718e3744 5220{
d62a17ae 5221 int idx_peer = 1;
f4b8ec07
CS
5222 char base_xpath[XPATH_MAXLEN];
5223
5224 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5225 sizeof(base_xpath), NULL)
5226 < 0)
5227 return CMD_WARNING_CONFIG_FAILED;
73d70fa6 5228
d62a17ae 5229 if (argc >= 5) {
d62a17ae 5230 char *message;
73d70fa6 5231
d62a17ae 5232 message = argv_concat(argv, argc, 4);
f4b8ec07
CS
5233 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5234 NB_OP_MODIFY, message);
d62a17ae 5235 }
73d70fa6 5236
f4b8ec07
CS
5237 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5238 "true");
5239
5240 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5241}
5242
232c75cd 5243ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5244 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5246 "Administratively shut down this neighbor\n")
73d70fa6 5247
f4b8ec07
CS
5248DEFUN_YANG(no_neighbor_shutdown_msg,
5249 no_neighbor_shutdown_msg_cmd,
5250 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5251 NO_STR NEIGHBOR_STR
5252 NEIGHBOR_ADDR_STR2
5253 "Administratively shut down this neighbor\n"
5254 "Remove a shutdown message (RFC 8203)\n"
5255 "Shutdown message\n")
718e3744 5256{
d62a17ae 5257 int idx_peer = 2;
f4b8ec07 5258 char base_xpath[XPATH_MAXLEN];
73d70fa6 5259
f4b8ec07
CS
5260 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5261 sizeof(base_xpath), NULL)
5262 < 0)
5263 return CMD_WARNING_CONFIG_FAILED;
5264
5265 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5266 "false");
5267
5268 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5269}
6b0655a2 5270
232c75cd 5271ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5272 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5273 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5274 "Administratively shut down this neighbor\n")
73d70fa6 5275
8336c896
DA
5276DEFUN(neighbor_shutdown_rtt,
5277 neighbor_shutdown_rtt_cmd,
5278 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
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 = 1;
5288 int idx_rtt = 4;
5289 int idx_count = 0;
5290 struct peer *peer;
5291
5292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5293
5294 if (!peer)
5295 return CMD_WARNING_CONFIG_FAILED;
5296
5297 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5298
5299 if (argv_find(argv, argc, "count", &idx_count))
5300 peer->rtt_keepalive_conf =
5301 strtol(argv[idx_count + 1]->arg, NULL, 10);
5302
5303 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5304 PEER_FLAG_RTT_SHUTDOWN);
5305}
5306
5307DEFUN(no_neighbor_shutdown_rtt,
5308 no_neighbor_shutdown_rtt_cmd,
5309 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5310 NO_STR
5311 NEIGHBOR_STR
5312 NEIGHBOR_ADDR_STR2
5313 "Administratively shut down this neighbor\n"
5314 "Shutdown if round-trip-time is higher than expected\n"
5315 "Round-trip-time in milliseconds\n"
5316 "Specify the number of keepalives before shutdown\n"
5317 "The number of keepalives with higher RTT to shutdown\n")
5318{
5319 int idx_peer = 2;
5320 struct peer *peer;
5321
5322 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5323
5324 if (!peer)
5325 return CMD_WARNING_CONFIG_FAILED;
5326
5327 peer->rtt_expected = 0;
5328 peer->rtt_keepalive_conf = 1;
5329
5330 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5331 PEER_FLAG_RTT_SHUTDOWN);
5332}
5333
718e3744 5334/* neighbor capability dynamic. */
f4b8ec07
CS
5335DEFUN_YANG (neighbor_capability_dynamic,
5336 neighbor_capability_dynamic_cmd,
5337 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5338 NEIGHBOR_STR
5339 NEIGHBOR_ADDR_STR2
5340 "Advertise capability to the peer\n"
5341 "Advertise dynamic capability to this neighbor\n")
718e3744 5342{
d62a17ae 5343 int idx_peer = 1;
f4b8ec07
CS
5344 char base_xpath[XPATH_MAXLEN];
5345
5346 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5347 sizeof(base_xpath), NULL)
5348 < 0)
5349 return CMD_WARNING_CONFIG_FAILED;
5350
5351 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5352 NB_OP_MODIFY, "true");
5353
5354 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5355}
5356
f4b8ec07
CS
5357DEFUN_YANG (no_neighbor_capability_dynamic,
5358 no_neighbor_capability_dynamic_cmd,
5359 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5360 NO_STR
5361 NEIGHBOR_STR
5362 NEIGHBOR_ADDR_STR2
5363 "Advertise capability to the peer\n"
5364 "Advertise dynamic capability to this neighbor\n")
718e3744 5365{
d62a17ae 5366 int idx_peer = 2;
f4b8ec07
CS
5367 char base_xpath[XPATH_MAXLEN];
5368
5369 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5370 sizeof(base_xpath), NULL)
5371 < 0)
5372 return CMD_WARNING_CONFIG_FAILED;
5373
5374 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5375 NB_OP_MODIFY, "false");
5376
5377 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5378}
6b0655a2 5379
718e3744 5380/* neighbor dont-capability-negotiate */
5381DEFUN (neighbor_dont_capability_negotiate,
5382 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5383 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5384 NEIGHBOR_STR
5385 NEIGHBOR_ADDR_STR2
5386 "Do not perform capability negotiation\n")
5387{
d62a17ae 5388 int idx_peer = 1;
5389 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5390 PEER_FLAG_DONT_CAPABILITY);
718e3744 5391}
5392
5393DEFUN (no_neighbor_dont_capability_negotiate,
5394 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5395 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5396 NO_STR
5397 NEIGHBOR_STR
5398 NEIGHBOR_ADDR_STR2
5399 "Do not perform capability negotiation\n")
5400{
d62a17ae 5401 int idx_peer = 2;
5402 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5403 PEER_FLAG_DONT_CAPABILITY);
718e3744 5404}
6b0655a2 5405
8a92a8a0 5406/* neighbor capability extended next hop encoding */
f4b8ec07
CS
5407DEFUN_YANG (neighbor_capability_enhe,
5408 neighbor_capability_enhe_cmd,
5409 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5410 NEIGHBOR_STR
5411 NEIGHBOR_ADDR_STR2
5412 "Advertise capability to the peer\n"
5413 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5414{
d62a17ae 5415 int idx_peer = 1;
f4b8ec07
CS
5416 char base_xpath[XPATH_MAXLEN];
5417
5418 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5419 sizeof(base_xpath), NULL)
5420 < 0)
5421 return CMD_WARNING_CONFIG_FAILED;
5422
5423 nb_cli_enqueue_change(
5424 vty, "./capability-options/extended-nexthop-capability",
5425 NB_OP_MODIFY, "true");
5426
5427 return nb_cli_apply_changes(vty, base_xpath);
8a92a8a0
DS
5428}
5429
f4b8ec07
CS
5430DEFUN_YANG (no_neighbor_capability_enhe,
5431 no_neighbor_capability_enhe_cmd,
5432 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5433 NO_STR
5434 NEIGHBOR_STR
5435 NEIGHBOR_ADDR_STR2
5436 "Advertise capability to the peer\n"
5437 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5438{
d62a17ae 5439 int idx_peer = 2;
f4b8ec07
CS
5440 char base_xpath[XPATH_MAXLEN];
5441
5442 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5443 sizeof(base_xpath), NULL)
5444 < 0)
5445 return CMD_WARNING_CONFIG_FAILED;
5446
5447 nb_cli_enqueue_change(
5448 vty, "./capability-options/extended-nexthop-capability",
5449 NB_OP_MODIFY, "false");
5450
5451 return nb_cli_apply_changes(vty, base_xpath);
5452}
5453
5454int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5455 uint32_t flag, int set, char *errmsg,
5456 size_t errmsg_len)
5457{
5458 int ret;
5459
5460 if (set)
5461 ret = peer_af_flag_set(peer, afi, safi, flag);
5462 else
5463 ret = peer_af_flag_unset(peer, afi, safi, flag);
5464
5465 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
8a92a8a0
DS
5466}
5467
d62a17ae 5468static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5469 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5470 int set)
718e3744 5471{
d62a17ae 5472 int ret;
5473 struct peer *peer;
718e3744 5474
d62a17ae 5475 peer = peer_and_group_lookup_vty(vty, peer_str);
5476 if (!peer)
5477 return CMD_WARNING_CONFIG_FAILED;
718e3744 5478
d62a17ae 5479 if (set)
5480 ret = peer_af_flag_set(peer, afi, safi, flag);
5481 else
5482 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5483
d62a17ae 5484 return bgp_vty_return(vty, ret);
718e3744 5485}
5486
d62a17ae 5487static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5488 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5489{
d62a17ae 5490 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5491}
5492
d62a17ae 5493static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5494 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5495{
d62a17ae 5496 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5497}
6b0655a2 5498
718e3744 5499/* neighbor capability orf prefix-list. */
5500DEFUN (neighbor_capability_orf_prefix,
5501 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5502 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5503 NEIGHBOR_STR
5504 NEIGHBOR_ADDR_STR2
5505 "Advertise capability to the peer\n"
5506 "Advertise ORF capability to the peer\n"
5507 "Advertise prefixlist ORF capability to this neighbor\n"
5508 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5509 "Capability to RECEIVE the ORF from this neighbor\n"
5510 "Capability to SEND the ORF to this neighbor\n")
5511{
d62a17ae 5512 int idx_send_recv = 5;
db45f64d
DS
5513 char *peer_str = argv[1]->arg;
5514 struct peer *peer;
5515 afi_t afi = bgp_node_afi(vty);
5516 safi_t safi = bgp_node_safi(vty);
d62a17ae 5517
db45f64d
DS
5518 peer = peer_and_group_lookup_vty(vty, peer_str);
5519 if (!peer)
d62a17ae 5520 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5521
db45f64d
DS
5522 if (strmatch(argv[idx_send_recv]->text, "send"))
5523 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5524 PEER_FLAG_ORF_PREFIX_SM);
5525
5526 if (strmatch(argv[idx_send_recv]->text, "receive"))
5527 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5528 PEER_FLAG_ORF_PREFIX_RM);
5529
5530 if (strmatch(argv[idx_send_recv]->text, "both"))
5531 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5532 PEER_FLAG_ORF_PREFIX_SM)
5533 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5534 PEER_FLAG_ORF_PREFIX_RM);
5535
5536 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5537}
5538
5539ALIAS_HIDDEN(
5540 neighbor_capability_orf_prefix,
5541 neighbor_capability_orf_prefix_hidden_cmd,
5542 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5543 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5544 "Advertise capability to the peer\n"
5545 "Advertise ORF capability to the peer\n"
5546 "Advertise prefixlist ORF capability to this neighbor\n"
5547 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5548 "Capability to RECEIVE the ORF from this neighbor\n"
5549 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5550
718e3744 5551DEFUN (no_neighbor_capability_orf_prefix,
5552 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5553 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5554 NO_STR
5555 NEIGHBOR_STR
5556 NEIGHBOR_ADDR_STR2
5557 "Advertise capability to the peer\n"
5558 "Advertise ORF capability to the peer\n"
5559 "Advertise prefixlist ORF capability to this neighbor\n"
5560 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5561 "Capability to RECEIVE the ORF from this neighbor\n"
5562 "Capability to SEND the ORF to this neighbor\n")
5563{
d62a17ae 5564 int idx_send_recv = 6;
db45f64d
DS
5565 char *peer_str = argv[2]->arg;
5566 struct peer *peer;
5567 afi_t afi = bgp_node_afi(vty);
5568 safi_t safi = bgp_node_safi(vty);
d62a17ae 5569
db45f64d
DS
5570 peer = peer_and_group_lookup_vty(vty, peer_str);
5571 if (!peer)
d62a17ae 5572 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5573
db45f64d
DS
5574 if (strmatch(argv[idx_send_recv]->text, "send"))
5575 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5576 PEER_FLAG_ORF_PREFIX_SM);
5577
5578 if (strmatch(argv[idx_send_recv]->text, "receive"))
5579 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5580 PEER_FLAG_ORF_PREFIX_RM);
5581
5582 if (strmatch(argv[idx_send_recv]->text, "both"))
5583 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5584 PEER_FLAG_ORF_PREFIX_SM)
5585 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5586 PEER_FLAG_ORF_PREFIX_RM);
5587
5588 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5589}
5590
5591ALIAS_HIDDEN(
5592 no_neighbor_capability_orf_prefix,
5593 no_neighbor_capability_orf_prefix_hidden_cmd,
5594 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5595 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5596 "Advertise capability to the peer\n"
5597 "Advertise ORF capability to the peer\n"
5598 "Advertise prefixlist ORF capability to this neighbor\n"
5599 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5600 "Capability to RECEIVE the ORF from this neighbor\n"
5601 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5602
718e3744 5603/* neighbor next-hop-self. */
f4b8ec07
CS
5604DEFUN_YANG (neighbor_nexthop_self,
5605 neighbor_nexthop_self_cmd,
5606 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5607 NEIGHBOR_STR
5608 NEIGHBOR_ADDR_STR2
5609 "Disable the next hop calculation for this neighbor\n")
718e3744 5610{
d62a17ae 5611 int idx_peer = 1;
f4b8ec07
CS
5612 char base_xpath[XPATH_MAXLEN];
5613 char af_xpath[XPATH_MAXLEN];
5614 char attr_xpath[XPATH_MAXLEN];
5615 afi_t afi = bgp_node_afi(vty);
5616 safi_t safi = bgp_node_safi(vty);
5617
f4b8ec07
CS
5618 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5619 yang_afi_safi_value2identity(afi, safi));
5620
5621 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5622 sizeof(base_xpath), af_xpath)
5623 < 0)
5624 return CMD_WARNING_CONFIG_FAILED;
5625
5626 snprintf(attr_xpath, sizeof(attr_xpath),
5627 "./%s/nexthop-self/next-hop-self",
5628 bgp_afi_safi_get_container_str(afi, safi));
5629
5630 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5631
5632 return nb_cli_apply_changes(vty, base_xpath);
a538debe 5633}
9e7a53c1 5634
d62a17ae 5635ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5636 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5637 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5638 "Disable the next hop calculation for this neighbor\n")
596c17ba 5639
f4b8ec07
CS
5640/* neighbor next-hop-self. */
5641DEFUN_YANG(neighbor_nexthop_self_force,
5642 neighbor_nexthop_self_force_cmd,
5643 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5644 NEIGHBOR_STR
5645 NEIGHBOR_ADDR_STR2
5646 "Disable the next hop calculation for this neighbor\n"
5647 "Set the next hop to self for reflected routes\n")
5648{
5649 int idx_peer = 1;
5650 char base_xpath[XPATH_MAXLEN];
5651 char af_xpath[XPATH_MAXLEN];
5652 char attr_xpath[XPATH_MAXLEN];
5653 afi_t afi = bgp_node_afi(vty);
5654 safi_t safi = bgp_node_safi(vty);
5655
f4b8ec07
CS
5656 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5657 yang_afi_safi_value2identity(afi, safi));
5658
5659 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5660 sizeof(base_xpath), af_xpath)
5661 < 0)
5662 return CMD_WARNING_CONFIG_FAILED;
5663
5664 snprintf(attr_xpath, sizeof(attr_xpath),
5665 "./%s/nexthop-self/next-hop-self-force",
5666 bgp_afi_safi_get_container_str(afi, safi));
5667
5668 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5669
5670 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5671}
5672
d62a17ae 5673ALIAS_HIDDEN(neighbor_nexthop_self_force,
5674 neighbor_nexthop_self_force_hidden_cmd,
5675 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5676 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5677 "Disable the next hop calculation for this neighbor\n"
5678 "Set the next hop to self for reflected routes\n")
596c17ba 5679
1bc4e531
DA
5680ALIAS_HIDDEN(neighbor_nexthop_self_force,
5681 neighbor_nexthop_self_all_hidden_cmd,
5682 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5683 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5684 "Disable the next hop calculation for this neighbor\n"
5685 "Set the next hop to self for reflected routes\n")
5686
f4b8ec07
CS
5687DEFUN_YANG (no_neighbor_nexthop_self,
5688 no_neighbor_nexthop_self_cmd,
5689 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5690 NO_STR
5691 NEIGHBOR_STR
5692 NEIGHBOR_ADDR_STR2
5693 "Disable the next hop calculation for this neighbor\n")
718e3744 5694{
d62a17ae 5695 int idx_peer = 2;
f4b8ec07
CS
5696 char base_xpath[XPATH_MAXLEN];
5697 char af_xpath[XPATH_MAXLEN];
5698 char attr_xpath[XPATH_MAXLEN];
5699 afi_t afi = bgp_node_afi(vty);
5700 safi_t safi = bgp_node_safi(vty);
5701
5702 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5703 yang_afi_safi_value2identity(afi, safi));
5704
5705 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5706 sizeof(base_xpath), af_xpath)
5707 < 0)
5708 return CMD_WARNING_CONFIG_FAILED;
5709
5710 snprintf(attr_xpath, sizeof(attr_xpath),
5711 "./%s/nexthop-self/next-hop-self",
5712 bgp_afi_safi_get_container_str(afi, safi));
5713
5714 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5715
5716 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5717}
6b0655a2 5718
d62a17ae 5719ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5720 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5721 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5722 "Disable the next hop calculation for this neighbor\n")
596c17ba 5723
f4b8ec07
CS
5724DEFUN_YANG (no_neighbor_nexthop_self_force,
5725 no_neighbor_nexthop_self_force_cmd,
5726 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5727 NO_STR
5728 NEIGHBOR_STR
5729 NEIGHBOR_ADDR_STR2
5730 "Disable the next hop calculation for this neighbor\n"
5731 "Set the next hop to self for reflected routes\n")
88b8ed8d 5732{
d62a17ae 5733 int idx_peer = 2;
f4b8ec07
CS
5734 char base_xpath[XPATH_MAXLEN];
5735 char af_xpath[XPATH_MAXLEN];
5736 char attr_xpath[XPATH_MAXLEN];
5737 afi_t afi = bgp_node_afi(vty);
5738 safi_t safi = bgp_node_safi(vty);
5739
f4b8ec07
CS
5740 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5741 yang_afi_safi_value2identity(afi, safi));
5742
5743 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5744 sizeof(base_xpath), af_xpath)
5745 < 0)
5746 return CMD_WARNING_CONFIG_FAILED;
5747
5748 snprintf(attr_xpath, sizeof(attr_xpath),
5749 "./%s/nexthop-self/next-hop-self-force",
5750 bgp_afi_safi_get_container_str(afi, safi));
5751
5752 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5753
5754 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5755}
a538debe 5756
d62a17ae 5757ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5758 no_neighbor_nexthop_self_force_hidden_cmd,
5759 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5760 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5761 "Disable the next hop calculation for this neighbor\n"
5762 "Set the next hop to self for reflected routes\n")
596c17ba 5763
1bc4e531
DA
5764ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5765 no_neighbor_nexthop_self_all_hidden_cmd,
5766 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5767 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5768 "Disable the next hop calculation for this neighbor\n"
5769 "Set the next hop to self for reflected routes\n")
5770
c7122e14 5771/* neighbor as-override */
f4b8ec07
CS
5772DEFUN_YANG (neighbor_as_override,
5773 neighbor_as_override_cmd,
5774 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5775 NEIGHBOR_STR
5776 NEIGHBOR_ADDR_STR2
5777 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5778{
d62a17ae 5779 int idx_peer = 1;
f4b8ec07
CS
5780 char base_xpath[XPATH_MAXLEN];
5781 char af_xpath[XPATH_MAXLEN];
5782 char attr_xpath[XPATH_MAXLEN];
5783 afi_t afi = bgp_node_afi(vty);
5784 safi_t safi = bgp_node_safi(vty);
5785
5786 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5787 yang_afi_safi_value2identity(afi, safi));
5788
5789 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5790 sizeof(base_xpath), af_xpath)
5791 < 0)
5792 return CMD_WARNING_CONFIG_FAILED;
5793
5794 snprintf(attr_xpath, sizeof(attr_xpath),
5795 "./%s/as-path-options/replace-peer-as",
5796 bgp_afi_safi_get_container_str(afi, safi));
5797
5798 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5799
5800 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5801}
5802
d62a17ae 5803ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5804 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5806 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5807
f4b8ec07
CS
5808DEFUN_YANG (no_neighbor_as_override,
5809 no_neighbor_as_override_cmd,
5810 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5811 NO_STR
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5815{
d62a17ae 5816 int idx_peer = 2;
f4b8ec07
CS
5817 char base_xpath[XPATH_MAXLEN];
5818 char af_xpath[XPATH_MAXLEN];
5819 char attr_xpath[XPATH_MAXLEN];
5820 afi_t afi = bgp_node_afi(vty);
5821 safi_t safi = bgp_node_safi(vty);
5822
5823 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5824 yang_afi_safi_value2identity(afi, safi));
5825
5826 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5827 sizeof(base_xpath), af_xpath)
5828 < 0)
5829 return CMD_WARNING_CONFIG_FAILED;
5830
5831 snprintf(attr_xpath, sizeof(attr_xpath),
5832 "./%s/as-path-options/replace-peer-as",
5833 bgp_afi_safi_get_container_str(afi, safi));
5834
5835 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5836
5837 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5838}
5839
d62a17ae 5840ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5841 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5842 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5844
718e3744 5845/* neighbor remove-private-AS. */
f4b8ec07
CS
5846DEFUN_YANG (neighbor_remove_private_as,
5847 neighbor_remove_private_as_cmd,
5848 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5849 NEIGHBOR_STR
5850 NEIGHBOR_ADDR_STR2
5851 "Remove private ASNs in outbound updates\n")
718e3744 5852{
d62a17ae 5853 int idx_peer = 1;
f4b8ec07
CS
5854 char base_xpath[XPATH_MAXLEN];
5855 char af_xpath[XPATH_MAXLEN];
5856 char attr_xpath[XPATH_MAXLEN];
5857 afi_t afi = bgp_node_afi(vty);
5858 safi_t safi = bgp_node_safi(vty);
5859
5860 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5861 yang_afi_safi_value2identity(afi, safi));
5862
5863 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5864 sizeof(base_xpath), af_xpath)
5865 < 0)
5866 return CMD_WARNING_CONFIG_FAILED;
5867
5868 snprintf(attr_xpath, sizeof(attr_xpath),
5869 "./%s/private-as/remove-private-as",
5870 bgp_afi_safi_get_container_str(afi, safi));
5871
5872 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5873
5874 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5875}
5876
d62a17ae 5877ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5878 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5880 "Remove private ASNs in outbound updates\n")
596c17ba 5881
f4b8ec07
CS
5882DEFUN_YANG (neighbor_remove_private_as_all,
5883 neighbor_remove_private_as_all_cmd,
5884 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5885 NEIGHBOR_STR
5886 NEIGHBOR_ADDR_STR2
5887 "Remove private ASNs in outbound updates\n"
5888 "Apply to all AS numbers\n")
5000f21c 5889{
d62a17ae 5890 int idx_peer = 1;
f4b8ec07
CS
5891 char base_xpath[XPATH_MAXLEN];
5892 char af_xpath[XPATH_MAXLEN];
5893 char attr_xpath[XPATH_MAXLEN];
5894 afi_t afi = bgp_node_afi(vty);
5895 safi_t safi = bgp_node_safi(vty);
5896
f4b8ec07
CS
5897 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5898 yang_afi_safi_value2identity(afi, safi));
5899
5900 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5901 sizeof(base_xpath), af_xpath)
5902 < 0)
5903 return CMD_WARNING_CONFIG_FAILED;
5904
5905 snprintf(attr_xpath, sizeof(attr_xpath),
5906 "./%s/private-as/remove-private-as-all",
5907 bgp_afi_safi_get_container_str(afi, safi));
5908
5909 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5910
5911 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5912}
5913
d62a17ae 5914ALIAS_HIDDEN(neighbor_remove_private_as_all,
5915 neighbor_remove_private_as_all_hidden_cmd,
5916 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5918 "Remove private ASNs in outbound updates\n"
5919 "Apply to all AS numbers")
596c17ba 5920
f4b8ec07
CS
5921DEFUN_YANG (neighbor_remove_private_as_replace_as,
5922 neighbor_remove_private_as_replace_as_cmd,
5923 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5924 NEIGHBOR_STR
5925 NEIGHBOR_ADDR_STR2
5926 "Remove private ASNs in outbound updates\n"
5927 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5928{
d62a17ae 5929 int idx_peer = 1;
f4b8ec07
CS
5930 char base_xpath[XPATH_MAXLEN];
5931 char af_xpath[XPATH_MAXLEN];
5932 char attr_xpath[XPATH_MAXLEN];
5933 afi_t afi = bgp_node_afi(vty);
5934 safi_t safi = bgp_node_safi(vty);
5935
f4b8ec07
CS
5936 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5937 yang_afi_safi_value2identity(afi, safi));
5938
5939 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5940 sizeof(base_xpath), af_xpath)
5941 < 0)
5942 return CMD_WARNING_CONFIG_FAILED;
5943
5944 snprintf(attr_xpath, sizeof(attr_xpath),
5945 "./%s/private-as/remove-private-as-replace",
5946 bgp_afi_safi_get_container_str(afi, safi));
5947
5948 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5949
5950 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5951}
5952
d62a17ae 5953ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5954 neighbor_remove_private_as_replace_as_hidden_cmd,
5955 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n"
5958 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5959
f4b8ec07
CS
5960DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5961 neighbor_remove_private_as_all_replace_as_cmd,
5962 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5963 NEIGHBOR_STR
5964 NEIGHBOR_ADDR_STR2
5965 "Remove private ASNs in outbound updates\n"
5966 "Apply to all AS numbers\n"
5967 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5968{
d62a17ae 5969 int idx_peer = 1;
f4b8ec07
CS
5970 char base_xpath[XPATH_MAXLEN];
5971 char af_xpath[XPATH_MAXLEN];
5972 char attr_xpath[XPATH_MAXLEN];
5973 afi_t afi = bgp_node_afi(vty);
5974 safi_t safi = bgp_node_safi(vty);
5975
f4b8ec07
CS
5976 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5977 yang_afi_safi_value2identity(afi, safi));
5978
5979 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5980 sizeof(base_xpath), af_xpath)
5981 < 0)
5982 return CMD_WARNING_CONFIG_FAILED;
5983
5984 snprintf(attr_xpath, sizeof(attr_xpath),
5985 "./%s/private-as/remove-private-as-all-replace",
5986 bgp_afi_safi_get_container_str(afi, safi));
5987
5988 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5989
5990 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5991}
5992
d62a17ae 5993ALIAS_HIDDEN(
5994 neighbor_remove_private_as_all_replace_as,
5995 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5996 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5998 "Remove private ASNs in outbound updates\n"
5999 "Apply to all AS numbers\n"
6000 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6001
f4b8ec07
CS
6002DEFUN_YANG (no_neighbor_remove_private_as,
6003 no_neighbor_remove_private_as_cmd,
6004 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6005 NO_STR
6006 NEIGHBOR_STR
6007 NEIGHBOR_ADDR_STR2
6008 "Remove private ASNs in outbound updates\n")
718e3744 6009{
d62a17ae 6010 int idx_peer = 2;
f4b8ec07
CS
6011 char base_xpath[XPATH_MAXLEN];
6012 char af_xpath[XPATH_MAXLEN];
6013 char attr_xpath[XPATH_MAXLEN];
6014 afi_t afi = bgp_node_afi(vty);
6015 safi_t safi = bgp_node_safi(vty);
6016
6017 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6018 yang_afi_safi_value2identity(afi, safi));
6019
6020 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6021 sizeof(base_xpath), af_xpath)
6022 < 0)
6023 return CMD_WARNING_CONFIG_FAILED;
6024
6025 snprintf(attr_xpath, sizeof(attr_xpath),
6026 "./%s/private-as/remove-private-as",
6027 bgp_afi_safi_get_container_str(afi, safi));
6028
6029 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6030
6031 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6032}
6b0655a2 6033
d62a17ae 6034ALIAS_HIDDEN(no_neighbor_remove_private_as,
6035 no_neighbor_remove_private_as_hidden_cmd,
6036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6037 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6038 "Remove private ASNs in outbound updates\n")
596c17ba 6039
f4b8ec07
CS
6040DEFUN_YANG (no_neighbor_remove_private_as_all,
6041 no_neighbor_remove_private_as_all_cmd,
6042 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6043 NO_STR
6044 NEIGHBOR_STR
6045 NEIGHBOR_ADDR_STR2
6046 "Remove private ASNs in outbound updates\n"
6047 "Apply to all AS numbers\n")
88b8ed8d 6048{
d62a17ae 6049 int idx_peer = 2;
f4b8ec07
CS
6050 char base_xpath[XPATH_MAXLEN];
6051 char af_xpath[XPATH_MAXLEN];
6052 char attr_xpath[XPATH_MAXLEN];
6053 afi_t afi = bgp_node_afi(vty);
6054 safi_t safi = bgp_node_safi(vty);
6055
f4b8ec07
CS
6056 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6057 yang_afi_safi_value2identity(afi, safi));
6058
6059 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6060 sizeof(base_xpath), af_xpath)
6061 < 0)
6062 return CMD_WARNING_CONFIG_FAILED;
6063
6064 snprintf(attr_xpath, sizeof(attr_xpath),
6065 "./%s/private-as/remove-private-as-all",
6066 bgp_afi_safi_get_container_str(afi, safi));
6067
6068 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6069
6070 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6071}
5000f21c 6072
d62a17ae 6073ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6074 no_neighbor_remove_private_as_all_hidden_cmd,
6075 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6076 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6077 "Remove private ASNs in outbound updates\n"
6078 "Apply to all AS numbers\n")
596c17ba 6079
f4b8ec07
CS
6080DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6081 no_neighbor_remove_private_as_replace_as_cmd,
6082 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6083 NO_STR
6084 NEIGHBOR_STR
6085 NEIGHBOR_ADDR_STR2
6086 "Remove private ASNs in outbound updates\n"
6087 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6088{
d62a17ae 6089 int idx_peer = 2;
f4b8ec07
CS
6090 char base_xpath[XPATH_MAXLEN];
6091 char af_xpath[XPATH_MAXLEN];
6092 char attr_xpath[XPATH_MAXLEN];
6093 afi_t afi = bgp_node_afi(vty);
6094 safi_t safi = bgp_node_safi(vty);
6095
f4b8ec07
CS
6096 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6097 yang_afi_safi_value2identity(afi, safi));
6098
6099 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6100 sizeof(base_xpath), af_xpath)
6101 < 0)
6102 return CMD_WARNING_CONFIG_FAILED;
6103
6104 snprintf(attr_xpath, sizeof(attr_xpath),
6105 "./%s/private-as/remove-private-as-replace",
6106 bgp_afi_safi_get_container_str(afi, safi));
6107
6108 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6109
6110 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6111}
5000f21c 6112
d62a17ae 6113ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6114 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6115 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6116 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6117 "Remove private ASNs in outbound updates\n"
6118 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6119
f4b8ec07
CS
6120DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6121 no_neighbor_remove_private_as_all_replace_as_cmd,
6122 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6123 NO_STR
6124 NEIGHBOR_STR
6125 NEIGHBOR_ADDR_STR2
6126 "Remove private ASNs in outbound updates\n"
6127 "Apply to all AS numbers\n"
6128 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6129{
d62a17ae 6130 int idx_peer = 2;
f4b8ec07
CS
6131 char base_xpath[XPATH_MAXLEN];
6132 char af_xpath[XPATH_MAXLEN];
6133 char attr_xpath[XPATH_MAXLEN];
6134 afi_t afi = bgp_node_afi(vty);
6135 safi_t safi = bgp_node_safi(vty);
6136
f4b8ec07
CS
6137 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6138 yang_afi_safi_value2identity(afi, safi));
6139
6140 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6141 sizeof(base_xpath), af_xpath)
6142 < 0)
6143 return CMD_WARNING_CONFIG_FAILED;
6144
6145 snprintf(attr_xpath, sizeof(attr_xpath),
6146 "./%s/private-as/remove-private-as-all-replace",
6147 bgp_afi_safi_get_container_str(afi, safi));
6148
6149 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6150
6151 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6152}
5000f21c 6153
d62a17ae 6154ALIAS_HIDDEN(
6155 no_neighbor_remove_private_as_all_replace_as,
6156 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6157 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6158 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6159 "Remove private ASNs in outbound updates\n"
6160 "Apply to all AS numbers\n"
6161 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6162
5000f21c 6163
718e3744 6164/* neighbor send-community. */
f4b8ec07
CS
6165DEFUN_YANG (neighbor_send_community,
6166 neighbor_send_community_cmd,
6167 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6168 NEIGHBOR_STR
6169 NEIGHBOR_ADDR_STR2
6170 "Send Community attribute to this neighbor\n")
718e3744 6171{
d62a17ae 6172 int idx_peer = 1;
e48a9a90
CS
6173 char *peer_str = argv[idx_peer]->arg;
6174 char base_xpath[XPATH_MAXLEN];
6175 char af_xpath[XPATH_MAXLEN];
6176 char std_xpath[XPATH_MAXLEN];
6177 afi_t afi = bgp_node_afi(vty);
6178 safi_t safi = bgp_node_safi(vty);
27c05d4d 6179
e48a9a90
CS
6180 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6181 yang_afi_safi_value2identity(afi, safi));
6182
6183 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6184 sizeof(base_xpath), af_xpath)
6185 < 0)
6186 return CMD_WARNING_CONFIG_FAILED;
6187
6188 snprintf(std_xpath, sizeof(std_xpath),
6189 "./%s/send-community/send-community",
6190 bgp_afi_safi_get_container_str(afi, safi));
6191
6192 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6193
6194 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6195}
6196
d62a17ae 6197ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6198 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6199 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6200 "Send Community attribute to this neighbor\n")
596c17ba 6201
f4b8ec07
CS
6202DEFUN_YANG (no_neighbor_send_community,
6203 no_neighbor_send_community_cmd,
6204 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6205 NO_STR
6206 NEIGHBOR_STR
6207 NEIGHBOR_ADDR_STR2
6208 "Send Community attribute to this neighbor\n")
718e3744 6209{
d62a17ae 6210 int idx_peer = 2;
e48a9a90
CS
6211 char *peer_str = argv[idx_peer]->arg;
6212 char base_xpath[XPATH_MAXLEN];
6213 char af_xpath[XPATH_MAXLEN];
6214 char std_xpath[XPATH_MAXLEN];
6215 afi_t afi = bgp_node_afi(vty);
6216 safi_t safi = bgp_node_safi(vty);
27c05d4d 6217
e48a9a90
CS
6218 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6219 yang_afi_safi_value2identity(afi, safi));
6220
6221 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6222 sizeof(base_xpath), af_xpath)
6223 < 0)
6224 return CMD_WARNING_CONFIG_FAILED;
6225
6226 snprintf(std_xpath, sizeof(std_xpath),
6227 "./%s/send-community/send-community",
6228 bgp_afi_safi_get_container_str(afi, safi));
6229
6230 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6231
6232 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6233}
6b0655a2 6234
d62a17ae 6235ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6236 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6237 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6238 "Send Community attribute to this neighbor\n")
596c17ba 6239
718e3744 6240/* neighbor send-community extended. */
f4b8ec07
CS
6241DEFUN_YANG (neighbor_send_community_type,
6242 neighbor_send_community_type_cmd,
6243 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6244 NEIGHBOR_STR
6245 NEIGHBOR_ADDR_STR2
6246 "Send Community attribute to this neighbor\n"
6247 "Send Standard and Extended Community attributes\n"
6248 "Send Standard, Large and Extended Community attributes\n"
6249 "Send Extended Community attributes\n"
6250 "Send Standard Community attributes\n"
6251 "Send Large Community attributes\n")
718e3744 6252{
27c05d4d 6253 const char *type = argv[argc - 1]->text;
db45f64d 6254 char *peer_str = argv[1]->arg;
f4b8ec07
CS
6255 char base_xpath[XPATH_MAXLEN];
6256 char af_xpath[XPATH_MAXLEN];
6257 char std_xpath[XPATH_MAXLEN];
6258 char ext_xpath[XPATH_MAXLEN];
6259 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6260 afi_t afi = bgp_node_afi(vty);
6261 safi_t safi = bgp_node_safi(vty);
d62a17ae 6262
f4b8ec07
CS
6263 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6264 yang_afi_safi_value2identity(afi, safi));
6265
6266 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6267 sizeof(base_xpath), af_xpath)
6268 < 0)
db45f64d 6269 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6270
f4b8ec07
CS
6271 if (strmatch(type, "standard")) {
6272 snprintf(std_xpath, sizeof(std_xpath),
6273 "./%s/send-community/send-community",
6274 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6275
f4b8ec07
CS
6276 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6277 }
db45f64d 6278
f4b8ec07
CS
6279 if (strmatch(type, "extended")) {
6280 snprintf(ext_xpath, sizeof(ext_xpath),
6281 "./%s/send-community/send-ext-community",
6282 bgp_afi_safi_get_container_str(afi, safi));
6283
6284 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6285 }
6286
6287 if (strmatch(type, "large")) {
6288 snprintf(lrg_xpath, sizeof(lrg_xpath),
6289 "./%s/send-community/send-large-community",
6290 bgp_afi_safi_get_container_str(afi, safi));
6291
6292 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6293 }
db45f64d
DS
6294
6295 if (strmatch(type, "both")) {
f4b8ec07
CS
6296 snprintf(std_xpath, sizeof(std_xpath),
6297 "./%s/send-community/send-community",
6298 bgp_afi_safi_get_container_str(afi, safi));
6299
6300 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6301
6302 snprintf(ext_xpath, sizeof(ext_xpath),
6303 "./%s/send-community/send-ext-community",
6304 bgp_afi_safi_get_container_str(afi, safi));
6305
6306 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
db45f64d 6307 }
f4b8ec07
CS
6308
6309 if (strmatch(type, "all")) {
6310 snprintf(std_xpath, sizeof(std_xpath),
6311 "./%s/send-community/send-community",
6312 bgp_afi_safi_get_container_str(afi, safi));
6313
6314 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6315
6316 snprintf(ext_xpath, sizeof(ext_xpath),
6317 "./%s/send-community/send-ext-community",
6318 bgp_afi_safi_get_container_str(afi, safi));
6319
6320 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6321
6322 snprintf(lrg_xpath, sizeof(lrg_xpath),
6323 "./%s/send-community/send-large-community",
6324 bgp_afi_safi_get_container_str(afi, safi));
6325
6326 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6327 }
6328
6329 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6330}
6331
6332ALIAS_HIDDEN(
6333 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6334 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6335 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6336 "Send Community attribute to this neighbor\n"
6337 "Send Standard and Extended Community attributes\n"
6338 "Send Standard, Large and Extended Community attributes\n"
6339 "Send Extended Community attributes\n"
6340 "Send Standard Community attributes\n"
6341 "Send Large Community attributes\n")
596c17ba 6342
f4b8ec07
CS
6343DEFUN_YANG (no_neighbor_send_community_type,
6344 no_neighbor_send_community_type_cmd,
6345 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6346 NO_STR
6347 NEIGHBOR_STR
6348 NEIGHBOR_ADDR_STR2
6349 "Send Community attribute to this neighbor\n"
6350 "Send Standard and Extended Community attributes\n"
6351 "Send Standard, Large and Extended Community attributes\n"
6352 "Send Extended Community attributes\n"
6353 "Send Standard Community attributes\n"
6354 "Send Large Community attributes\n")
718e3744 6355{
d62a17ae 6356 const char *type = argv[argc - 1]->text;
db45f64d 6357 char *peer_str = argv[2]->arg;
f4b8ec07
CS
6358 char base_xpath[XPATH_MAXLEN];
6359 char af_xpath[XPATH_MAXLEN];
6360 char std_xpath[XPATH_MAXLEN];
6361 char ext_xpath[XPATH_MAXLEN];
6362 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6363 afi_t afi = bgp_node_afi(vty);
6364 safi_t safi = bgp_node_safi(vty);
6365
f4b8ec07
CS
6366 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6367 yang_afi_safi_value2identity(afi, safi));
6368
6369 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6370 sizeof(base_xpath), af_xpath)
6371 < 0)
6372 return CMD_WARNING_CONFIG_FAILED;
6373
6374 if (strmatch(type, "standard")) {
6375 snprintf(std_xpath, sizeof(std_xpath),
6376 "./%s/send-community/send-community",
6377 bgp_afi_safi_get_container_str(afi, safi));
6378
6379 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6380 }
6381
6382 if (strmatch(type, "extended")) {
6383 snprintf(ext_xpath, sizeof(ext_xpath),
6384 "./%s/send-community/send-ext-community",
6385 bgp_afi_safi_get_container_str(afi, safi));
6386
6387 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6388 }
6389
6390 if (strmatch(type, "large")) {
6391 snprintf(lrg_xpath, sizeof(lrg_xpath),
6392 "./%s/send-community/send-large-community",
6393 bgp_afi_safi_get_container_str(afi, safi));
6394
6395 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6396 }
6397
6398 if (strmatch(type, "both")) {
6399 snprintf(std_xpath, sizeof(std_xpath),
6400 "./%s/send-community/send-community",
6401 bgp_afi_safi_get_container_str(afi, safi));
6402
6403 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6404
6405 snprintf(ext_xpath, sizeof(ext_xpath),
6406 "./%s/send-community/send-ext-community",
6407 bgp_afi_safi_get_container_str(afi, safi));
6408
6409 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6410 }
6411
6412 if (strmatch(type, "all")) {
6413 snprintf(std_xpath, sizeof(std_xpath),
6414 "./%s/send-community/send-community",
6415 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6416
f4b8ec07 6417 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
db45f64d 6418
f4b8ec07
CS
6419 snprintf(ext_xpath, sizeof(ext_xpath),
6420 "./%s/send-community/send-ext-community",
6421 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6422
f4b8ec07 6423 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
db45f64d 6424
f4b8ec07
CS
6425 snprintf(lrg_xpath, sizeof(lrg_xpath),
6426 "./%s/send-community/send-large-community",
6427 bgp_afi_safi_get_container_str(afi, safi));
d62a17ae 6428
f4b8ec07 6429 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
27c05d4d
PM
6430 }
6431
f4b8ec07 6432 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6433}
6434
6435ALIAS_HIDDEN(
6436 no_neighbor_send_community_type,
6437 no_neighbor_send_community_type_hidden_cmd,
6438 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6439 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6440 "Send Community attribute to this neighbor\n"
6441 "Send Standard and Extended Community attributes\n"
6442 "Send Standard, Large and Extended Community attributes\n"
6443 "Send Extended Community attributes\n"
6444 "Send Standard Community attributes\n"
6445 "Send Large Community attributes\n")
596c17ba 6446
718e3744 6447/* neighbor soft-reconfig. */
f4b8ec07
CS
6448DEFUN_YANG (neighbor_soft_reconfiguration,
6449 neighbor_soft_reconfiguration_cmd,
6450 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6451 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6452 "Per neighbor soft reconfiguration\n"
6453 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6454{
d62a17ae 6455 int idx_peer = 1;
f4b8ec07
CS
6456 char base_xpath[XPATH_MAXLEN];
6457 char af_xpath[XPATH_MAXLEN];
6458 char soft_xpath[XPATH_MAXLEN];
6459 afi_t afi = bgp_node_afi(vty);
6460 safi_t safi = bgp_node_safi(vty);
6461
f4b8ec07
CS
6462 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6463 yang_afi_safi_value2identity(afi, safi));
6464
6465 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6466 sizeof(base_xpath), af_xpath)
6467 < 0)
6468 return CMD_WARNING_CONFIG_FAILED;
6469
6470 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6471 bgp_afi_safi_get_container_str(afi, safi));
6472
6473 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6474
6475 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6476}
6477
d62a17ae 6478ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6479 neighbor_soft_reconfiguration_hidden_cmd,
6480 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6481 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6482 "Per neighbor soft reconfiguration\n"
6483 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6484
f4b8ec07
CS
6485DEFUN_YANG (no_neighbor_soft_reconfiguration,
6486 no_neighbor_soft_reconfiguration_cmd,
6487 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6488 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6489 "Per neighbor soft reconfiguration\n"
6490 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6491{
d62a17ae 6492 int idx_peer = 2;
f4b8ec07
CS
6493 char base_xpath[XPATH_MAXLEN];
6494 char af_xpath[XPATH_MAXLEN];
6495 char soft_xpath[XPATH_MAXLEN];
6496 afi_t afi = bgp_node_afi(vty);
6497 safi_t safi = bgp_node_safi(vty);
6498
6499 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6500 yang_afi_safi_value2identity(afi, safi));
6501
6502 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6503 bgp_afi_safi_get_container_str(afi, safi));
6504
6505 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6506 sizeof(base_xpath), af_xpath)
6507 < 0)
6508 return CMD_WARNING_CONFIG_FAILED;
6509
6510 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6511
6512 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6513}
6b0655a2 6514
d62a17ae 6515ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6516 no_neighbor_soft_reconfiguration_hidden_cmd,
6517 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6518 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6519 "Per neighbor soft reconfiguration\n"
6520 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6521
f4b8ec07
CS
6522DEFUN_YANG (neighbor_route_reflector_client,
6523 neighbor_route_reflector_client_cmd,
6524 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6525 NEIGHBOR_STR
6526 NEIGHBOR_ADDR_STR2
6527 "Configure a neighbor as Route Reflector client\n")
718e3744 6528{
d62a17ae 6529 int idx_peer = 1;
f4b8ec07
CS
6530 char base_xpath[XPATH_MAXLEN];
6531 char af_xpath[XPATH_MAXLEN];
6532 char attr_xpath[XPATH_MAXLEN];
6533 afi_t afi = bgp_node_afi(vty);
6534 safi_t safi = bgp_node_safi(vty);
718e3744 6535
f4b8ec07
CS
6536 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6537 yang_afi_safi_value2identity(afi, safi));
718e3744 6538
f4b8ec07
CS
6539 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6540 sizeof(base_xpath), af_xpath)
6541 < 0)
d62a17ae 6542 return CMD_WARNING_CONFIG_FAILED;
718e3744 6543
f4b8ec07
CS
6544 snprintf(attr_xpath, sizeof(attr_xpath),
6545 "./%s/route-reflector/route-reflector-client",
6546 bgp_afi_safi_get_container_str(afi, safi));
6547
6548 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6549
6550 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6551}
6552
d62a17ae 6553ALIAS_HIDDEN(neighbor_route_reflector_client,
6554 neighbor_route_reflector_client_hidden_cmd,
6555 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6556 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6557 "Configure a neighbor as Route Reflector client\n")
596c17ba 6558
f4b8ec07
CS
6559DEFUN_YANG (no_neighbor_route_reflector_client,
6560 no_neighbor_route_reflector_client_cmd,
6561 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6562 NO_STR
6563 NEIGHBOR_STR
6564 NEIGHBOR_ADDR_STR2
6565 "Configure a neighbor as Route Reflector client\n")
718e3744 6566{
d62a17ae 6567 int idx_peer = 2;
f4b8ec07
CS
6568 char base_xpath[XPATH_MAXLEN];
6569 char af_xpath[XPATH_MAXLEN];
6570 char attr_xpath[XPATH_MAXLEN];
6571 afi_t afi = bgp_node_afi(vty);
6572 safi_t safi = bgp_node_safi(vty);
6573
6574 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6575 yang_afi_safi_value2identity(afi, safi));
6576
6577 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6578 sizeof(base_xpath), af_xpath)
6579 < 0)
6580 return CMD_WARNING_CONFIG_FAILED;
6581
6582 snprintf(attr_xpath, sizeof(attr_xpath),
6583 "./%s/route-reflector/route-reflector-client",
6584 bgp_afi_safi_get_container_str(afi, safi));
6585
6586 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6587
6588 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6589}
6b0655a2 6590
d62a17ae 6591ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6592 no_neighbor_route_reflector_client_hidden_cmd,
6593 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6594 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6595 "Configure a neighbor as Route Reflector client\n")
596c17ba 6596
718e3744 6597/* neighbor route-server-client. */
f4b8ec07
CS
6598DEFUN_YANG (neighbor_route_server_client,
6599 neighbor_route_server_client_cmd,
6600 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6601 NEIGHBOR_STR
6602 NEIGHBOR_ADDR_STR2
6603 "Configure a neighbor as Route Server client\n")
718e3744 6604{
d62a17ae 6605 int idx_peer = 1;
f4b8ec07
CS
6606 char base_xpath[XPATH_MAXLEN];
6607 char af_xpath[XPATH_MAXLEN];
6608 char attr_xpath[XPATH_MAXLEN];
6609 afi_t afi = bgp_node_afi(vty);
6610 safi_t safi = bgp_node_safi(vty);
2a3d5731 6611
f4b8ec07
CS
6612 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6613 yang_afi_safi_value2identity(afi, safi));
6614
6615 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6616 sizeof(base_xpath), af_xpath)
6617 < 0)
d62a17ae 6618 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07
CS
6619
6620 snprintf(attr_xpath, sizeof(attr_xpath),
6621 "./%s/route-server/route-server-client",
6622 bgp_afi_safi_get_container_str(afi, safi));
6623
6624 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6625
6626 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6627}
6628
d62a17ae 6629ALIAS_HIDDEN(neighbor_route_server_client,
6630 neighbor_route_server_client_hidden_cmd,
6631 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6632 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6633 "Configure a neighbor as Route Server client\n")
596c17ba 6634
f4b8ec07
CS
6635DEFUN_YANG (no_neighbor_route_server_client,
6636 no_neighbor_route_server_client_cmd,
6637 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6638 NO_STR
6639 NEIGHBOR_STR
6640 NEIGHBOR_ADDR_STR2
6641 "Configure a neighbor as Route Server client\n")
fee0f4c6 6642{
d62a17ae 6643 int idx_peer = 2;
f4b8ec07
CS
6644 char base_xpath[XPATH_MAXLEN];
6645 char af_xpath[XPATH_MAXLEN];
6646 char attr_xpath[XPATH_MAXLEN];
6647 afi_t afi = bgp_node_afi(vty);
6648 safi_t safi = bgp_node_safi(vty);
6649
6650 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6651 yang_afi_safi_value2identity(afi, safi));
6652
6653 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6654 sizeof(base_xpath), af_xpath)
6655 < 0)
6656 return CMD_WARNING_CONFIG_FAILED;
6657
6658 snprintf(attr_xpath, sizeof(attr_xpath),
6659 "./%s/route-server/route-server-client",
6660 bgp_afi_safi_get_container_str(afi, safi));
6661
6662 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6663
6664 return nb_cli_apply_changes(vty, base_xpath);
fee0f4c6 6665}
6b0655a2 6666
d62a17ae 6667ALIAS_HIDDEN(no_neighbor_route_server_client,
6668 no_neighbor_route_server_client_hidden_cmd,
6669 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6670 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6671 "Configure a neighbor as Route Server client\n")
596c17ba 6672
fee0f4c6 6673DEFUN (neighbor_nexthop_local_unchanged,
6674 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6675 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6676 NEIGHBOR_STR
6677 NEIGHBOR_ADDR_STR2
6678 "Configure treatment of outgoing link-local nexthop attribute\n"
6679 "Leave link-local nexthop unchanged for this peer\n")
6680{
d62a17ae 6681 int idx_peer = 1;
6682 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6683 bgp_node_safi(vty),
6684 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6685}
6b0655a2 6686
fee0f4c6 6687DEFUN (no_neighbor_nexthop_local_unchanged,
6688 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6689 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6690 NO_STR
6691 NEIGHBOR_STR
6692 NEIGHBOR_ADDR_STR2
6693 "Configure treatment of outgoing link-local-nexthop attribute\n"
6694 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6695{
d62a17ae 6696 int idx_peer = 2;
6697 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6698 bgp_node_afi(vty), bgp_node_safi(vty),
6699 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6700}
6b0655a2 6701
f4b8ec07
CS
6702DEFUN_YANG (neighbor_attr_unchanged,
6703 neighbor_attr_unchanged_cmd,
6704 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6705 NEIGHBOR_STR
6706 NEIGHBOR_ADDR_STR2
6707 "BGP attribute is propagated unchanged to this neighbor\n"
6708 "As-path attribute\n"
6709 "Nexthop attribute\n"
6710 "Med attribute\n")
718e3744 6711{
d62a17ae 6712 int idx = 0;
8eeb0335 6713 char *peer_str = argv[1]->arg;
db45f64d
DS
6714 bool aspath = false;
6715 bool nexthop = false;
6716 bool med = false;
8eeb0335
DW
6717 afi_t afi = bgp_node_afi(vty);
6718 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6719 char base_xpath[XPATH_MAXLEN];
6720 char af_xpath[XPATH_MAXLEN];
6721 char as_xpath[XPATH_MAXLEN];
6722 char nxthop_xpath[XPATH_MAXLEN];
6723 char med_xpath[XPATH_MAXLEN];
8eeb0335 6724
f4b8ec07
CS
6725 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6726 yang_afi_safi_value2identity(afi, safi));
6727
6728 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6729 sizeof(base_xpath), af_xpath)
6730 < 0)
8eeb0335 6731 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6732
6733 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6734 aspath = true;
6735
d62a17ae 6736 idx = 0;
6737 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6738 nexthop = true;
6739
d62a17ae 6740 idx = 0;
6741 if (argv_find(argv, argc, "med", &idx))
db45f64d 6742 med = true;
d62a17ae 6743
f4b8ec07
CS
6744 snprintf(as_xpath, sizeof(as_xpath),
6745 "./%s/attr-unchanged/as-path-unchanged",
6746 bgp_afi_safi_get_container_str(afi, safi));
6747 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6748 "./%s/attr-unchanged/next-hop-unchanged",
6749 bgp_afi_safi_get_container_str(afi, safi));
6750 snprintf(med_xpath, sizeof(med_xpath),
6751 "./%s/attr-unchanged/med-unchanged",
6752 bgp_afi_safi_get_container_str(afi, safi));
6753
8eeb0335 6754 /* no flags means all of them! */
db45f64d 6755 if (!aspath && !nexthop && !med) {
f4b8ec07
CS
6756 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6757 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6758 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
8eeb0335 6759 } else {
f4b8ec07
CS
6760 if (!aspath)
6761 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6762 "false");
6763 else
6764 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6765 "true");
6766
6767 if (!nexthop)
6768 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6769 "false");
6770 else
6771 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6772 "true");
6773
6774 if (!med)
6775 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6776 "false");
6777 else
6778 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6779 "true");
d62a17ae 6780 }
6781
f4b8ec07 6782 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6783}
6784
6785ALIAS_HIDDEN(
6786 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6787 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6788 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6789 "BGP attribute is propagated unchanged to this neighbor\n"
6790 "As-path attribute\n"
6791 "Nexthop attribute\n"
6792 "Med attribute\n")
596c17ba 6793
f4b8ec07
CS
6794DEFUN_YANG (no_neighbor_attr_unchanged,
6795 no_neighbor_attr_unchanged_cmd,
6796 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6797 NO_STR
6798 NEIGHBOR_STR
6799 NEIGHBOR_ADDR_STR2
6800 "BGP attribute is propagated unchanged to this neighbor\n"
6801 "As-path attribute\n"
6802 "Nexthop attribute\n"
6803 "Med attribute\n")
718e3744 6804{
d62a17ae 6805 int idx = 0;
db45f64d 6806 char *peer_str = argv[2]->arg;
db45f64d
DS
6807 bool aspath = false;
6808 bool nexthop = false;
6809 bool med = false;
6810 afi_t afi = bgp_node_afi(vty);
6811 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6812 char base_xpath[XPATH_MAXLEN];
6813 char af_xpath[XPATH_MAXLEN];
6814 char as_xpath[XPATH_MAXLEN];
6815 char nxthop_xpath[XPATH_MAXLEN];
6816 char med_xpath[XPATH_MAXLEN];
db45f64d 6817
f4b8ec07
CS
6818 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6819 yang_afi_safi_value2identity(afi, safi));
6820
6821 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6822 sizeof(base_xpath), af_xpath)
6823 < 0)
db45f64d 6824 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6825
6826 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6827 aspath = true;
6828
d62a17ae 6829 idx = 0;
6830 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6831 nexthop = true;
6832
d62a17ae 6833 idx = 0;
6834 if (argv_find(argv, argc, "med", &idx))
db45f64d 6835 med = true;
d62a17ae 6836
f4b8ec07
CS
6837 snprintf(as_xpath, sizeof(as_xpath),
6838 "./%s/attr-unchanged/as-path-unchanged",
6839 bgp_afi_safi_get_container_str(afi, safi));
6840 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6841 "./%s/attr-unchanged/next-hop-unchanged",
6842 bgp_afi_safi_get_container_str(afi, safi));
6843 snprintf(med_xpath, sizeof(med_xpath),
6844 "./%s/attr-unchanged/med-unchanged",
6845 bgp_afi_safi_get_container_str(afi, safi));
6846
6847 /* no flags means all of them! */
6848 if (!aspath && !nexthop && !med) {
6849 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6850 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6851 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6852 }
db45f64d
DS
6853
6854 if (aspath)
f4b8ec07 6855 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
db45f64d
DS
6856
6857 if (nexthop)
f4b8ec07 6858 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
d62a17ae 6859
db45f64d 6860 if (med)
f4b8ec07 6861 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
db45f64d 6862
f4b8ec07 6863 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6864}
6865
6866ALIAS_HIDDEN(
6867 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6868 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6869 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6870 "BGP attribute is propagated unchanged to this neighbor\n"
6871 "As-path attribute\n"
6872 "Nexthop attribute\n"
6873 "Med attribute\n")
718e3744 6874
f4b8ec07
CS
6875/* neighbor ebgp-multihop. */
6876DEFUN_YANG (neighbor_ebgp_multihop,
6877 neighbor_ebgp_multihop_cmd,
6878 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6880 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6881{
f4b8ec07
CS
6882 int idx_peer = 1;
6883 char base_xpath[XPATH_MAXLEN];
718e3744 6884
f4b8ec07
CS
6885 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6886 sizeof(base_xpath), NULL)
6887 < 0)
d62a17ae 6888 return CMD_WARNING_CONFIG_FAILED;
718e3744 6889
f4b8ec07
CS
6890 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6891 "true");
718e3744 6892
f4b8ec07 6893 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6894}
6895
f4b8ec07
CS
6896DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6897 neighbor_ebgp_multihop_ttl_cmd,
6898 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6899 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6900 "Allow EBGP neighbors not on directly connected networks\n"
6901 "maximum hop count\n")
718e3744 6902{
f4b8ec07
CS
6903 int idx_peer = 1;
6904 int idx_number = 3;
6905 char base_xpath[XPATH_MAXLEN];
718e3744 6906
f4b8ec07
CS
6907 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6908 sizeof(base_xpath), NULL)
6909 < 0)
d62a17ae 6910 return CMD_WARNING_CONFIG_FAILED;
718e3744 6911
f4b8ec07
CS
6912 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6913 argv[idx_number]->arg);
718e3744 6914
f4b8ec07 6915 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6916}
6917
f4b8ec07
CS
6918DEFUN_YANG (no_neighbor_ebgp_multihop,
6919 no_neighbor_ebgp_multihop_cmd,
6920 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6921 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6922 "Allow EBGP neighbors not on directly connected networks\n"
6923 "maximum hop count\n")
718e3744 6924{
d62a17ae 6925 int idx_peer = 2;
f4b8ec07
CS
6926 char base_xpath[XPATH_MAXLEN];
6927
6928 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6929 sizeof(base_xpath), NULL)
6930 < 0)
6931 return CMD_WARNING_CONFIG_FAILED;
6932
6933 if (argc > 4)
6934 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6935 NB_OP_DESTROY, NULL);
6936 else
6937 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6938 NB_OP_MODIFY, "false");
6939
6940 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6941}
6942
6b0655a2 6943
6ffd2079 6944/* disable-connected-check */
f4b8ec07
CS
6945DEFUN_YANG (neighbor_disable_connected_check,
6946 neighbor_disable_connected_check_cmd,
6947 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6948 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6949 "one-hop away EBGP peer using loopback address\n"
6950 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6951{
d62a17ae 6952 int idx_peer = 1;
f4b8ec07
CS
6953 char base_xpath[XPATH_MAXLEN];
6954
6955 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6956 sizeof(base_xpath), NULL)
6957 < 0)
6958 return CMD_WARNING_CONFIG_FAILED;
6959
6960 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6961 NB_OP_MODIFY, "true");
6962
6963 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6964}
6965
f4b8ec07
CS
6966DEFUN_YANG (no_neighbor_disable_connected_check,
6967 no_neighbor_disable_connected_check_cmd,
6968 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6969 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6970 "one-hop away EBGP peer using loopback address\n"
6971 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6972{
d62a17ae 6973 int idx_peer = 2;
f4b8ec07
CS
6974 char base_xpath[XPATH_MAXLEN];
6975
6976 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6977 sizeof(base_xpath), NULL)
6978 < 0)
6979 return CMD_WARNING_CONFIG_FAILED;
6980
6981 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6982 NB_OP_MODIFY, "false");
6983
6984 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6985}
6986
47cbc09b
PM
6987
6988/* enforce-first-as */
f4b8ec07
CS
6989DEFUN_YANG (neighbor_enforce_first_as,
6990 neighbor_enforce_first_as_cmd,
6991 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6993 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6994{
6995 int idx_peer = 1;
f4b8ec07 6996 char base_xpath[XPATH_MAXLEN];
47cbc09b 6997
f4b8ec07
CS
6998 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6999 sizeof(base_xpath), NULL)
7000 < 0)
7001 return CMD_WARNING_CONFIG_FAILED;
7002
7003 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
7004
7005 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
7006}
7007
f4b8ec07
CS
7008DEFUN_YANG (no_neighbor_enforce_first_as,
7009 no_neighbor_enforce_first_as_cmd,
7010 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
7011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7012 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
7013{
7014 int idx_peer = 2;
f4b8ec07 7015 char base_xpath[XPATH_MAXLEN];
47cbc09b 7016
f4b8ec07
CS
7017 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7018 sizeof(base_xpath), NULL)
7019 < 0)
7020 return CMD_WARNING_CONFIG_FAILED;
7021
7022 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
7023
7024 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
7025}
7026
f4b8ec07
CS
7027static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
7028 char *base_xpath, int xpath_len,
7029 char *xpath)
7030{
7031 union sockunion su;
7032 char num_xpath[XPATH_MAXLEN];
7033 char unnbr_xpath[XPATH_MAXLEN];
7034 char prgrp_xpath[XPATH_MAXLEN];
7035
7036 if (str2sockunion(peer_str, &su) == 0) {
7037 snprintf(num_xpath, sizeof(num_xpath),
7038 "/neighbors/neighbor[remote-address='%s']", peer_str);
3bb513c3
CH
7039 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7040 VTY_CURR_XPATH, num_xpath)) {
f4b8ec07
CS
7041 snprintf(base_xpath, xpath_len,
7042 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
7043 xpath ? xpath : "");
7044 } else {
7045 vty_out(vty,
7046 "%% Specify remote-as or peer-group commands first\n");
7047 return -1;
7048 }
7049
7050 } else {
7051 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
7052 "/neighbors/unnumbered-neighbor[interface='%s']",
7053 peer_str);
7054
7055 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
7056 "/peer-groups/peer-group[peer-group-name='%s']",
7057 peer_str);
7058
3bb513c3
CH
7059 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7060 VTY_CURR_XPATH, unnbr_xpath)) {
f4b8ec07
CS
7061 snprintf(base_xpath, xpath_len,
7062 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
7063 xpath ? xpath : "");
3bb513c3
CH
7064 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
7065 "%s%s", VTY_CURR_XPATH,
7066 prgrp_xpath)) {
f4b8ec07
CS
7067 snprintf(base_xpath, xpath_len,
7068 FRR_BGP_PEER_GROUP_XPATH, peer_str,
7069 xpath ? xpath : "");
7070 } else {
7071 vty_out(vty,
7072 "%% Create the peer-group or interface first\n");
7073 return -1;
7074 }
7075 }
7076
7077 return 0;
7078}
47cbc09b 7079
f4b8ec07
CS
7080DEFUN_YANG (neighbor_description,
7081 neighbor_description_cmd,
7082 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7083 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7084 "Neighbor specific description\n"
7085 "Up to 80 characters describing this neighbor\n")
718e3744 7086{
d62a17ae 7087 int idx_peer = 1;
7088 int idx_line = 3;
f4b8ec07
CS
7089 int ret;
7090 char base_xpath[XPATH_MAXLEN];
d62a17ae 7091 char *str;
718e3744 7092
f4b8ec07
CS
7093 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7094 sizeof(base_xpath), NULL)
7095 < 0)
d62a17ae 7096 return CMD_WARNING_CONFIG_FAILED;
718e3744 7097
d62a17ae 7098 str = argv_concat(argv, argc, idx_line);
718e3744 7099
f4b8ec07
CS
7100 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7101
7102 ret = nb_cli_apply_changes(vty, base_xpath);
718e3744 7103
d62a17ae 7104 XFREE(MTYPE_TMP, str);
718e3744 7105
f4b8ec07 7106 return ret;
718e3744 7107}
7108
f4b8ec07
CS
7109DEFUN_YANG (no_neighbor_description,
7110 no_neighbor_description_cmd,
7111 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7112 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7113 "Neighbor specific description\n")
718e3744 7114{
d62a17ae 7115 int idx_peer = 2;
f4b8ec07
CS
7116 char base_xpath[XPATH_MAXLEN];
7117
7118 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7119 sizeof(base_xpath), NULL)
7120 < 0)
d62a17ae 7121 return CMD_WARNING_CONFIG_FAILED;
718e3744 7122
f4b8ec07 7123 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
718e3744 7124
f4b8ec07 7125 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7126}
7127
232c75cd 7128ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
7129 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7130 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7131 "Neighbor specific description\n"
7132 "Up to 80 characters describing this neighbor\n")
6b0655a2 7133
d62a17ae 7134#define BGP_UPDATE_SOURCE_HELP_STR \
7135 "IPv4 address\n" \
7136 "IPv6 address\n" \
7137 "Interface name (requires zebra to be running)\n"
369688c0 7138
f4b8ec07
CS
7139DEFUN_YANG (neighbor_update_source,
7140 neighbor_update_source_cmd,
7141 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7142 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7143 "Source of routing updates\n"
7144 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7145{
d62a17ae 7146 int idx_peer = 1;
7147 int idx_peer_2 = 3;
f4b8ec07
CS
7148 union sockunion su;
7149 char base_xpath[XPATH_MAXLEN];
7150
7151 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7152 sizeof(base_xpath), NULL)
7153 < 0)
7154 return CMD_WARNING_CONFIG_FAILED;
7155
f4b8ec07
CS
7156 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7157 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
d62a17ae 7158 argv[idx_peer_2]->arg);
f4b8ec07
CS
7159 else
7160 nb_cli_enqueue_change(vty, "./update-source/interface",
7161 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7162
7163 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7164}
7165
f4b8ec07
CS
7166DEFUN_YANG (no_neighbor_update_source,
7167 no_neighbor_update_source_cmd,
7168 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7169 NO_STR NEIGHBOR_STR
7170 NEIGHBOR_ADDR_STR2
7171 "Source of routing updates\n"
7172 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7173{
d62a17ae 7174 int idx_peer = 2;
f4b8ec07 7175 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
7176
7177 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7178 sizeof(base_xpath), NULL)
7179 < 0)
7180 return CMD_WARNING_CONFIG_FAILED;
7181
555c8ab7
CS
7182 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7183 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7184 NULL);
f4b8ec07
CS
7185
7186 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7187}
6b0655a2 7188
d62a17ae 7189static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7190 afi_t afi, safi_t safi,
7191 const char *rmap, int set)
718e3744 7192{
d62a17ae 7193 int ret;
7194 struct peer *peer;
80912664 7195 struct route_map *route_map = NULL;
718e3744 7196
d62a17ae 7197 peer = peer_and_group_lookup_vty(vty, peer_str);
7198 if (!peer)
7199 return CMD_WARNING_CONFIG_FAILED;
718e3744 7200
1de27621 7201 if (set) {
80912664
DS
7202 if (rmap)
7203 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7204 ret = peer_default_originate_set(peer, afi, safi,
7205 rmap, route_map);
7206 } else
d62a17ae 7207 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7208
d62a17ae 7209 return bgp_vty_return(vty, ret);
718e3744 7210}
7211
7212/* neighbor default-originate. */
7213DEFUN (neighbor_default_originate,
7214 neighbor_default_originate_cmd,
9ccf14f7 7215 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7216 NEIGHBOR_STR
7217 NEIGHBOR_ADDR_STR2
7218 "Originate default route to this neighbor\n")
7219{
d62a17ae 7220 int idx_peer = 1;
7221 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7222 bgp_node_afi(vty),
7223 bgp_node_safi(vty), NULL, 1);
718e3744 7224}
7225
d62a17ae 7226ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7227 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7228 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7229 "Originate default route to this neighbor\n")
596c17ba 7230
718e3744 7231DEFUN (neighbor_default_originate_rmap,
7232 neighbor_default_originate_rmap_cmd,
9ccf14f7 7233 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 7234 NEIGHBOR_STR
7235 NEIGHBOR_ADDR_STR2
7236 "Originate default route to this neighbor\n"
7237 "Route-map to specify criteria to originate default\n"
7238 "route-map name\n")
7239{
d62a17ae 7240 int idx_peer = 1;
7241 int idx_word = 4;
7242 return peer_default_originate_set_vty(
7243 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7244 argv[idx_word]->arg, 1);
718e3744 7245}
7246
d62a17ae 7247ALIAS_HIDDEN(
7248 neighbor_default_originate_rmap,
7249 neighbor_default_originate_rmap_hidden_cmd,
7250 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7251 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7252 "Originate default route to this neighbor\n"
7253 "Route-map to specify criteria to originate default\n"
7254 "route-map name\n")
596c17ba 7255
718e3744 7256DEFUN (no_neighbor_default_originate,
7257 no_neighbor_default_originate_cmd,
a636c635 7258 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 7259 NO_STR
7260 NEIGHBOR_STR
7261 NEIGHBOR_ADDR_STR2
a636c635
DW
7262 "Originate default route to this neighbor\n"
7263 "Route-map to specify criteria to originate default\n"
7264 "route-map name\n")
718e3744 7265{
d62a17ae 7266 int idx_peer = 2;
7267 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7268 bgp_node_afi(vty),
7269 bgp_node_safi(vty), NULL, 0);
718e3744 7270}
7271
d62a17ae 7272ALIAS_HIDDEN(
7273 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7274 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7275 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7276 "Originate default route to this neighbor\n"
7277 "Route-map to specify criteria to originate default\n"
7278 "route-map name\n")
596c17ba 7279
6b0655a2 7280
f418446b 7281/* Set specified peer's BGP port. */
f4b8ec07
CS
7282DEFUN_YANG (neighbor_port,
7283 neighbor_port_cmd,
7284 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7285 NEIGHBOR_STR
7286 NEIGHBOR_ADDR_STR
7287 "Neighbor's BGP port\n"
7288 "TCP port number\n")
718e3744 7289{
d62a17ae 7290 int idx_ip = 1;
7291 int idx_number = 3;
f4b8ec07 7292 char base_xpath[XPATH_MAXLEN];
718e3744 7293
f4b8ec07
CS
7294 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7295 argv[idx_ip]->arg, "");
718e3744 7296
f4b8ec07
CS
7297 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7298 argv[idx_number]->arg);
7299
7300 return nb_cli_apply_changes(vty, base_xpath);
7301}
6b0655a2 7302
f4b8ec07
CS
7303DEFUN_YANG (no_neighbor_port,
7304 no_neighbor_port_cmd,
7305 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7306 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7307 "Neighbor's BGP port\n"
7308 "TCP port number\n")
718e3744 7309{
f4b8ec07
CS
7310 int idx_ip = 2;
7311 char base_xpath[XPATH_MAXLEN];
718e3744 7312
f4b8ec07
CS
7313 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7314 argv[idx_ip]->arg, "");
718e3744 7315
f4b8ec07 7316 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
718e3744 7317
f4b8ec07 7318 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7319}
7320
f4b8ec07
CS
7321DEFUN_YANG (neighbor_weight,
7322 neighbor_weight_cmd,
7323 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7324 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7325 "Set default weight for routes from this neighbor\n"
7326 "default weight\n")
718e3744 7327{
f4b8ec07
CS
7328 int idx_peer = 1;
7329 int idx_number = 3;
7330 char base_xpath[XPATH_MAXLEN];
7331 char af_xpath[XPATH_MAXLEN];
7332 char attr_xpath[XPATH_MAXLEN];
7333 afi_t afi = bgp_node_afi(vty);
7334 safi_t safi = bgp_node_safi(vty);
718e3744 7335
f4b8ec07
CS
7336 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7337 yang_afi_safi_value2identity(afi, safi));
7338
7339 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7340 sizeof(base_xpath), af_xpath)
7341 < 0)
d62a17ae 7342 return CMD_WARNING_CONFIG_FAILED;
718e3744 7343
f4b8ec07
CS
7344 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7345 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7346
f4b8ec07
CS
7347 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7348 argv[idx_number]->arg);
7349
7350 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7351}
7352
d62a17ae 7353ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7354 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7355 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7356 "Set default weight for routes from this neighbor\n"
7357 "default weight\n")
596c17ba 7358
f4b8ec07
CS
7359DEFUN_YANG (no_neighbor_weight,
7360 no_neighbor_weight_cmd,
7361 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7362 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7363 "Set default weight for routes from this neighbor\n"
7364 "default weight\n")
718e3744 7365{
d62a17ae 7366 int idx_peer = 2;
f4b8ec07
CS
7367 char base_xpath[XPATH_MAXLEN];
7368 char af_xpath[XPATH_MAXLEN];
7369 char attr_xpath[XPATH_MAXLEN];
7370 afi_t afi = bgp_node_afi(vty);
7371 safi_t safi = bgp_node_safi(vty);
7372
7373 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7374 yang_afi_safi_value2identity(afi, safi));
7375
7376 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7377 sizeof(base_xpath), af_xpath)
7378 < 0)
7379 return CMD_WARNING_CONFIG_FAILED;
7380
7381 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7382 bgp_afi_safi_get_container_str(afi, safi));
7383
7384 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7385
7386 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7387}
7388
d62a17ae 7389ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7390 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7391 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7392 "Set default weight for routes from this neighbor\n"
7393 "default weight\n")
596c17ba 7394
6b0655a2 7395
718e3744 7396/* Override capability negotiation. */
8611c7f3
CS
7397DEFUN_YANG (neighbor_override_capability,
7398 neighbor_override_capability_cmd,
7399 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7400 NEIGHBOR_STR
7401 NEIGHBOR_ADDR_STR2
7402 "Override capability negotiation result\n")
718e3744 7403{
d62a17ae 7404 int idx_peer = 1;
8611c7f3
CS
7405 char base_xpath[XPATH_MAXLEN];
7406
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/override-capability",
7414 NB_OP_MODIFY, "true");
7415
7416 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7417}
7418
8611c7f3
CS
7419DEFUN_YANG (no_neighbor_override_capability,
7420 no_neighbor_override_capability_cmd,
7421 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7422 NO_STR
7423 NEIGHBOR_STR
7424 NEIGHBOR_ADDR_STR2
7425 "Override capability negotiation result\n")
718e3744 7426{
d62a17ae 7427 int idx_peer = 2;
8611c7f3
CS
7428 char base_xpath[XPATH_MAXLEN];
7429
7430 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7431 sizeof(base_xpath), NULL)
7432 < 0)
7433 return CMD_WARNING_CONFIG_FAILED;
7434
7435 nb_cli_enqueue_change(
7436 vty, "./capability-options/override-capability",
7437 NB_OP_MODIFY, "false");
7438
7439 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7440}
6b0655a2 7441
8611c7f3
CS
7442DEFUN_YANG (neighbor_strict_capability,
7443 neighbor_strict_capability_cmd,
7444 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7445 NEIGHBOR_STR
7446 NEIGHBOR_ADDR_STR2
7447 "Strict capability negotiation match\n")
718e3744 7448{
9fb964de 7449 int idx_peer = 1;
8611c7f3 7450 char base_xpath[XPATH_MAXLEN];
9fb964de 7451
8611c7f3
CS
7452 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7453 sizeof(base_xpath), NULL)
7454 < 0)
7455 return CMD_WARNING_CONFIG_FAILED;
7456
7457 nb_cli_enqueue_change(
7458 vty, "./capability-options/strict-capability",
7459 NB_OP_MODIFY, "true");
7460
7461 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7462}
7463
8611c7f3
CS
7464DEFUN_YANG (no_neighbor_strict_capability,
7465 no_neighbor_strict_capability_cmd,
7466 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7467 NO_STR
7468 NEIGHBOR_STR
7469 NEIGHBOR_ADDR_STR2
7470 "Strict capability negotiation match\n")
718e3744 7471{
9fb964de 7472 int idx_peer = 2;
8611c7f3 7473 char base_xpath[XPATH_MAXLEN];
9fb964de 7474
8611c7f3
CS
7475 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7476 sizeof(base_xpath), NULL)
7477 < 0)
7478 return CMD_WARNING_CONFIG_FAILED;
7479
7480 nb_cli_enqueue_change(
7481 vty, "./capability-options/strict-capability",
7482 NB_OP_MODIFY, "false");
7483
7484 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7485}
6b0655a2 7486
f4b8ec07
CS
7487DEFUN_YANG (neighbor_timers,
7488 neighbor_timers_cmd,
7489 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7490 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7491 "BGP per neighbor timers\n"
7492 "Keepalive interval\n"
7493 "Holdtime\n")
718e3744 7494{
f4b8ec07
CS
7495 int idx_peer = 1;
7496 int idx_number = 3;
7497 int idx_number_2 = 4;
7498 char base_xpath[XPATH_MAXLEN];
718e3744 7499
f4b8ec07
CS
7500 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7501 sizeof(base_xpath), NULL)
7502 < 0)
d62a17ae 7503 return CMD_WARNING_CONFIG_FAILED;
718e3744 7504
f4b8ec07
CS
7505 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7506 argv[idx_number]->arg);
718e3744 7507
f4b8ec07
CS
7508 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7509 argv[idx_number_2]->arg);
718e3744 7510
f4b8ec07 7511 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7512}
6b0655a2 7513
f4b8ec07
CS
7514DEFUN_YANG (no_neighbor_timers,
7515 no_neighbor_timers_cmd,
7516 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7517 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7518 "BGP per neighbor timers\n"
7519 "Keepalive interval\n"
7520 "Holdtime\n")
718e3744 7521{
f4b8ec07
CS
7522 int idx_peer = 2;
7523 char base_xpath[XPATH_MAXLEN];
718e3744 7524
f4b8ec07
CS
7525 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7526 sizeof(base_xpath), NULL)
7527 < 0)
d62a17ae 7528 return CMD_WARNING_CONFIG_FAILED;
718e3744 7529
f4b8ec07 7530 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
718e3744 7531
f4b8ec07 7532 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
718e3744 7533
f4b8ec07 7534 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7535}
6b0655a2 7536
f4b8ec07
CS
7537DEFUN_YANG (neighbor_timers_connect,
7538 neighbor_timers_connect_cmd,
7539 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7540 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7541 "BGP per neighbor timers\n"
7542 "BGP connect timer\n"
7543 "Connect timer\n")
718e3744 7544{
f4b8ec07
CS
7545 int idx_peer = 1;
7546 int idx_number = 4;
7547 char base_xpath[XPATH_MAXLEN];
718e3744 7548
f4b8ec07
CS
7549 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7550 sizeof(base_xpath), NULL)
7551 < 0)
d62a17ae 7552 return CMD_WARNING_CONFIG_FAILED;
718e3744 7553
f4b8ec07
CS
7554 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7555 argv[idx_number]->arg);
718e3744 7556
f4b8ec07 7557 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7558}
7559
f4b8ec07
CS
7560DEFUN_YANG (no_neighbor_timers_connect,
7561 no_neighbor_timers_connect_cmd,
7562 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7563 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7564 "BGP per neighbor timers\n"
7565 "BGP connect timer\n"
7566 "Connect timer\n")
718e3744 7567{
f4b8ec07
CS
7568 int idx_peer = 2;
7569 char base_xpath[XPATH_MAXLEN];
718e3744 7570
f4b8ec07
CS
7571 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7572 sizeof(base_xpath), NULL)
7573 < 0)
d62a17ae 7574 return CMD_WARNING_CONFIG_FAILED;
718e3744 7575
f4b8ec07
CS
7576 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7577 NULL);
718e3744 7578
f4b8ec07 7579 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7580}
7581
d43114f3
DS
7582DEFPY (neighbor_timers_delayopen,
7583 neighbor_timers_delayopen_cmd,
7584 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7585 NEIGHBOR_STR
7586 NEIGHBOR_ADDR_STR2
7587 "BGP per neighbor timers\n"
7588 "RFC 4271 DelayOpenTimer\n"
7589 "DelayOpenTime timer interval\n")
7590{
7591 struct peer *peer;
7592
7593 peer = peer_and_group_lookup_vty(vty, neighbor);
7594 if (!peer)
7595 return CMD_WARNING_CONFIG_FAILED;
7596
7597 if (!interval) {
7598 if (peer_timers_delayopen_unset(peer))
7599 return CMD_WARNING_CONFIG_FAILED;
7600 } else {
7601 if (peer_timers_delayopen_set(peer, interval))
7602 return CMD_WARNING_CONFIG_FAILED;
7603 }
7604
7605 return CMD_SUCCESS;
7606}
7607
7608DEFPY (no_neighbor_timers_delayopen,
7609 no_neighbor_timers_delayopen_cmd,
7610 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7611 NO_STR
7612 NEIGHBOR_STR
7613 NEIGHBOR_ADDR_STR2
7614 "BGP per neighbor timers\n"
7615 "RFC 4271 DelayOpenTimer\n"
7616 "DelayOpenTime timer interval\n")
7617{
7618 struct peer *peer;
7619
7620 peer = peer_and_group_lookup_vty(vty, neighbor);
7621 if (!peer)
7622 return CMD_WARNING_CONFIG_FAILED;
7623
7624 if (peer_timers_delayopen_unset(peer))
7625 return CMD_WARNING_CONFIG_FAILED;
7626
7627 return CMD_SUCCESS;
7628}
7629
f4b8ec07
CS
7630DEFUN_YANG (neighbor_advertise_interval,
7631 neighbor_advertise_interval_cmd,
7632 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7633 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7634 "Minimum interval between sending BGP routing updates\n"
7635 "time in seconds\n")
718e3744 7636{
d62a17ae 7637 int idx_peer = 1;
f4b8ec07
CS
7638 int idx_number = 3;
7639 char base_xpath[XPATH_MAXLEN];
718e3744 7640
f4b8ec07
CS
7641 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7642 sizeof(base_xpath), NULL)
7643 < 0)
d62a17ae 7644 return CMD_WARNING_CONFIG_FAILED;
718e3744 7645
f4b8ec07
CS
7646 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7647 argv[idx_number]->arg);
718e3744 7648
f4b8ec07 7649 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7650}
7651
f4b8ec07
CS
7652DEFUN_YANG (no_neighbor_advertise_interval,
7653 no_neighbor_advertise_interval_cmd,
7654 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7655 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7656 "Minimum interval between sending BGP routing updates\n"
7657 "time in seconds\n")
718e3744 7658{
d62a17ae 7659 int idx_peer = 2;
f4b8ec07
CS
7660 char base_xpath[XPATH_MAXLEN];
7661
7662 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7663 sizeof(base_xpath), NULL)
7664 < 0)
7665 return CMD_WARNING_CONFIG_FAILED;
7666
7667 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7668 NULL);
7669
7670 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7671}
7672
6b0655a2 7673
518f0eb1
DS
7674/* Time to wait before processing route-map updates */
7675DEFUN (bgp_set_route_map_delay_timer,
7676 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7677 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7678 SET_STR
7679 "BGP route-map delay timer\n"
7680 "Time in secs to wait before processing route-map changes\n"
f414725f 7681 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7682{
d62a17ae 7683 int idx_number = 3;
d7c0a89a 7684 uint32_t rmap_delay_timer;
d62a17ae 7685
7686 if (argv[idx_number]->arg) {
7687 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7688 bm->rmap_update_timer = rmap_delay_timer;
7689
7690 /* if the dynamic update handling is being disabled, and a timer
7691 * is
7692 * running, stop the timer and act as if the timer has already
7693 * fired.
7694 */
7695 if (!rmap_delay_timer && bm->t_rmap_update) {
7696 BGP_TIMER_OFF(bm->t_rmap_update);
7697 thread_execute(bm->master, bgp_route_map_update_timer,
7698 NULL, 0);
7699 }
7700 return CMD_SUCCESS;
7701 } else {
7702 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7703 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7704 }
518f0eb1
DS
7705}
7706
7707DEFUN (no_bgp_set_route_map_delay_timer,
7708 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7709 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7710 NO_STR
3a2d747c 7711 BGP_STR
518f0eb1 7712 "Default BGP route-map delay timer\n"
8334fd5a
DW
7713 "Reset to default time to wait for processing route-map changes\n"
7714 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7715{
518f0eb1 7716
d62a17ae 7717 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7718
d62a17ae 7719 return CMD_SUCCESS;
518f0eb1
DS
7720}
7721
f4b8ec07
CS
7722DEFUN_YANG (neighbor_interface,
7723 neighbor_interface_cmd,
7724 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7725 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7726 "Interface\n"
7727 "Interface name\n")
718e3744 7728{
f4b8ec07
CS
7729 int idx_ip = 1;
7730 int idx_word = 3;
7731 char base_xpath[XPATH_MAXLEN];
718e3744 7732
f4b8ec07
CS
7733 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7734 argv[idx_ip]->arg, "");
718e3744 7735
f4b8ec07
CS
7736 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7737 argv[idx_word]->arg);
718e3744 7738
f4b8ec07 7739 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7740}
7741
f4b8ec07
CS
7742DEFUN_YANG (no_neighbor_interface,
7743 no_neighbor_interface_cmd,
7744 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7746 "Interface\n"
7747 "Interface name\n")
718e3744 7748{
d62a17ae 7749 int idx_peer = 2;
f4b8ec07
CS
7750 char base_xpath[XPATH_MAXLEN];
7751
7752 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7753 argv[idx_peer]->arg, "");
7754
7755 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7756
7757 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7758}
6b0655a2 7759
718e3744 7760DEFUN (neighbor_distribute_list,
7761 neighbor_distribute_list_cmd,
9ccf14f7 7762 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7763 NEIGHBOR_STR
7764 NEIGHBOR_ADDR_STR2
7765 "Filter updates to/from this neighbor\n"
7766 "IP access-list number\n"
7767 "IP access-list number (expanded range)\n"
7768 "IP Access-list name\n"
7769 "Filter incoming updates\n"
7770 "Filter outgoing updates\n")
7771{
d62a17ae 7772 int idx_peer = 1;
7773 int idx_acl = 3;
7774 int direct, ret;
7775 struct peer *peer;
a8206004 7776
d62a17ae 7777 const char *pstr = argv[idx_peer]->arg;
7778 const char *acl = argv[idx_acl]->arg;
7779 const char *inout = argv[argc - 1]->text;
a8206004 7780
d62a17ae 7781 peer = peer_and_group_lookup_vty(vty, pstr);
7782 if (!peer)
7783 return CMD_WARNING_CONFIG_FAILED;
a8206004 7784
d62a17ae 7785 /* Check filter direction. */
7786 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7787 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7788 direct, acl);
a8206004 7789
d62a17ae 7790 return bgp_vty_return(vty, ret);
718e3744 7791}
7792
d62a17ae 7793ALIAS_HIDDEN(
7794 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7795 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7796 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7797 "Filter updates to/from this neighbor\n"
7798 "IP access-list number\n"
7799 "IP access-list number (expanded range)\n"
7800 "IP Access-list name\n"
7801 "Filter incoming updates\n"
7802 "Filter outgoing updates\n")
596c17ba 7803
718e3744 7804DEFUN (no_neighbor_distribute_list,
7805 no_neighbor_distribute_list_cmd,
9ccf14f7 7806 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7807 NO_STR
7808 NEIGHBOR_STR
7809 NEIGHBOR_ADDR_STR2
7810 "Filter updates to/from this neighbor\n"
7811 "IP access-list number\n"
7812 "IP access-list number (expanded range)\n"
7813 "IP Access-list name\n"
7814 "Filter incoming updates\n"
7815 "Filter outgoing updates\n")
7816{
d62a17ae 7817 int idx_peer = 2;
7818 int direct, ret;
7819 struct peer *peer;
a8206004 7820
d62a17ae 7821 const char *pstr = argv[idx_peer]->arg;
7822 const char *inout = argv[argc - 1]->text;
a8206004 7823
d62a17ae 7824 peer = peer_and_group_lookup_vty(vty, pstr);
7825 if (!peer)
7826 return CMD_WARNING_CONFIG_FAILED;
a8206004 7827
d62a17ae 7828 /* Check filter direction. */
7829 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7830 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7831 direct);
a8206004 7832
d62a17ae 7833 return bgp_vty_return(vty, ret);
718e3744 7834}
6b0655a2 7835
d62a17ae 7836ALIAS_HIDDEN(
7837 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7838 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7839 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7840 "Filter updates to/from this neighbor\n"
7841 "IP access-list number\n"
7842 "IP access-list number (expanded range)\n"
7843 "IP Access-list name\n"
7844 "Filter incoming updates\n"
7845 "Filter outgoing updates\n")
596c17ba 7846
718e3744 7847/* Set prefix list to the peer. */
d9986d26
CS
7848DEFPY_YANG(
7849 neighbor_prefix_list, neighbor_prefix_list_cmd,
7850 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7851 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7852 "Filter updates to/from this neighbor\n"
7853 "Name of a prefix list\n"
7854 "Filter incoming updates\n"
7855 "Filter outgoing updates\n")
718e3744 7856{
d9986d26
CS
7857 char base_xpath[XPATH_MAXLEN];
7858 char af_xpath[XPATH_MAXLEN];
c6685575 7859 char plist_xpath[XPATH_MAXLEN];
d9986d26
CS
7860 afi_t afi = bgp_node_afi(vty);
7861 safi_t safi = bgp_node_safi(vty);
718e3744 7862
d9986d26
CS
7863 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7864 yang_afi_safi_value2identity(afi, safi));
7865 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7866 sizeof(base_xpath), af_xpath)
7867 < 0)
d62a17ae 7868 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7869
d9986d26
CS
7870 if (strmatch(direction, "in"))
7871 snprintf(plist_xpath, sizeof(plist_xpath),
7872 "./%s/filter-config/plist-import",
7873 bgp_afi_safi_get_container_str(afi, safi));
7874 else if (strmatch(direction, "out"))
7875 snprintf(plist_xpath, sizeof(plist_xpath),
7876 "./%s/filter-config/plist-export",
7877 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7878
d9986d26
CS
7879 if (!no)
7880 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7881 prefix_str);
7882 else
7883 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
718e3744 7884
d9986d26 7885 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7886}
7887
d62a17ae 7888ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7889 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7891 "Filter updates to/from this neighbor\n"
7892 "Name of a prefix list\n"
7893 "Filter incoming updates\n"
7894 "Filter outgoing updates\n")
596c17ba 7895
d62a17ae 7896static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7897 safi_t safi, const char *name_str,
7898 const char *direct_str)
718e3744 7899{
d62a17ae 7900 int ret;
7901 struct peer *peer;
7902 int direct = FILTER_IN;
718e3744 7903
d62a17ae 7904 peer = peer_and_group_lookup_vty(vty, ip_str);
7905 if (!peer)
7906 return CMD_WARNING_CONFIG_FAILED;
718e3744 7907
d62a17ae 7908 /* Check filter direction. */
7909 if (strncmp(direct_str, "i", 1) == 0)
7910 direct = FILTER_IN;
7911 else if (strncmp(direct_str, "o", 1) == 0)
7912 direct = FILTER_OUT;
718e3744 7913
d62a17ae 7914 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7915
d62a17ae 7916 return bgp_vty_return(vty, ret);
718e3744 7917}
7918
d62a17ae 7919static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7920 safi_t safi, const char *direct_str)
718e3744 7921{
d62a17ae 7922 int ret;
7923 struct peer *peer;
7924 int direct = FILTER_IN;
718e3744 7925
d62a17ae 7926 peer = peer_and_group_lookup_vty(vty, ip_str);
7927 if (!peer)
7928 return CMD_WARNING_CONFIG_FAILED;
718e3744 7929
d62a17ae 7930 /* Check filter direction. */
7931 if (strncmp(direct_str, "i", 1) == 0)
7932 direct = FILTER_IN;
7933 else if (strncmp(direct_str, "o", 1) == 0)
7934 direct = FILTER_OUT;
718e3744 7935
d62a17ae 7936 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7937
d62a17ae 7938 return bgp_vty_return(vty, ret);
718e3744 7939}
7940
7941DEFUN (neighbor_filter_list,
7942 neighbor_filter_list_cmd,
9ccf14f7 7943 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7944 NEIGHBOR_STR
7945 NEIGHBOR_ADDR_STR2
7946 "Establish BGP filters\n"
7947 "AS path access-list name\n"
7948 "Filter incoming routes\n"
7949 "Filter outgoing routes\n")
7950{
d62a17ae 7951 int idx_peer = 1;
7952 int idx_word = 3;
7953 int idx_in_out = 4;
7954 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7955 bgp_node_safi(vty), argv[idx_word]->arg,
7956 argv[idx_in_out]->arg);
718e3744 7957}
7958
d62a17ae 7959ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7960 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7962 "Establish BGP filters\n"
7963 "AS path access-list name\n"
7964 "Filter incoming routes\n"
7965 "Filter outgoing routes\n")
596c17ba 7966
718e3744 7967DEFUN (no_neighbor_filter_list,
7968 no_neighbor_filter_list_cmd,
9ccf14f7 7969 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7970 NO_STR
7971 NEIGHBOR_STR
7972 NEIGHBOR_ADDR_STR2
7973 "Establish BGP filters\n"
7974 "AS path access-list name\n"
7975 "Filter incoming routes\n"
7976 "Filter outgoing routes\n")
7977{
d62a17ae 7978 int idx_peer = 2;
7979 int idx_in_out = 5;
7980 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7981 bgp_node_afi(vty), bgp_node_safi(vty),
7982 argv[idx_in_out]->arg);
718e3744 7983}
6b0655a2 7984
d62a17ae 7985ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7986 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7987 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7988 "Establish BGP filters\n"
7989 "AS path access-list name\n"
7990 "Filter incoming routes\n"
7991 "Filter outgoing routes\n")
596c17ba 7992
7f7940e6
MK
7993/* Set advertise-map to the peer. */
7994static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7995 afi_t afi, safi_t safi,
cf2ad4d8
MK
7996 const char *advertise_str,
7997 const char *condition_str, bool condition,
7998 bool set)
7f7940e6
MK
7999{
8000 int ret = CMD_WARNING_CONFIG_FAILED;
8001 struct peer *peer;
8002 struct route_map *advertise_map;
8003 struct route_map *condition_map;
8004
8005 peer = peer_and_group_lookup_vty(vty, ip_str);
8006 if (!peer)
8007 return ret;
8008
8009 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
8010 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
8011
cf2ad4d8
MK
8012 if (set)
8013 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
8014 advertise_map, condition_str,
8015 condition_map, condition);
8016 else
8017 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
8018 advertise_map, condition_str,
8019 condition_map, condition);
7f7940e6
MK
8020
8021 return bgp_vty_return(vty, ret);
8022}
8023
cf2ad4d8 8024DEFPY (neighbor_advertise_map,
7f7940e6 8025 neighbor_advertise_map_cmd,
52b84062 8026 "[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 8027 NO_STR
7f7940e6
MK
8028 NEIGHBOR_STR
8029 NEIGHBOR_ADDR_STR2
8030 "Route-map to conditionally advertise routes\n"
8031 "Name of advertise map\n"
8032 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 8033 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 8034 "Name of the exist or non exist map\n")
7f7940e6 8035{
7f7940e6
MK
8036 bool condition = CONDITION_EXIST;
8037
52b84062 8038 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
8039 condition = CONDITION_NON_EXIST;
8040
52b84062
MK
8041 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
8042 bgp_node_safi(vty), advertise_str,
8043 condition_str, condition, !no);
7f7940e6
MK
8044}
8045
8046ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 8047 "[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
8048 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8049 "Route-map to conditionally advertise routes\n"
8050 "Name of advertise map\n"
8051 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 8052 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 8053 "Name of the exist or non exist map\n")
7f7940e6 8054
718e3744 8055/* Set route-map to the peer. */
c6685575
CS
8056DEFPY_YANG(
8057 neighbor_route_map, neighbor_route_map_cmd,
8058 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
8059 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8060 "Apply route map to neighbor\n"
8061 "Name of route map\n"
8062 "Apply map to incoming routes\n"
8063 "Apply map to outbound routes\n")
718e3744 8064{
c6685575
CS
8065 char base_xpath[XPATH_MAXLEN];
8066 char af_xpath[XPATH_MAXLEN];
8067 char rmap_xpath[XPATH_MAXLEN];
8068 afi_t afi = bgp_node_afi(vty);
8069 safi_t safi = bgp_node_safi(vty);
718e3744 8070
c6685575
CS
8071 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8072 yang_afi_safi_value2identity(afi, safi));
8073 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
8074 sizeof(base_xpath), af_xpath)
8075 < 0)
d62a17ae 8076 return CMD_WARNING_CONFIG_FAILED;
718e3744 8077
c6685575
CS
8078 if (strmatch(direction, "in"))
8079 snprintf(rmap_xpath, sizeof(rmap_xpath),
8080 "./%s/filter-config/rmap-import",
8081 bgp_afi_safi_get_container_str(afi, safi));
8082 else if (strmatch(direction, "out"))
8083 snprintf(rmap_xpath, sizeof(rmap_xpath),
8084 "./%s/filter-config/rmap-export",
8085 bgp_afi_safi_get_container_str(afi, safi));
718e3744 8086
c6685575 8087 if (!no) {
3bb513c3 8088 if (!yang_dnode_existsf(
c6685575
CS
8089 vty->candidate_config->dnode,
8090 "/frr-route-map:lib/route-map[name='%s']",
8091 rmap_str)) {
8092 if (vty_shell_serv(vty))
8093 vty_out(vty,
8094 "The route-map '%s' does not exist.\n",
8095 rmap_str);
8096 }
8097 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8098 } else
8099 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
718e3744 8100
c6685575 8101 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8102}
8103
718e3744 8104/* Set unsuppress-map to the peer. */
d62a17ae 8105static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8106 afi_t afi, safi_t safi,
8107 const char *name_str)
718e3744 8108{
d62a17ae 8109 int ret;
8110 struct peer *peer;
1de27621 8111 struct route_map *route_map;
718e3744 8112
d62a17ae 8113 peer = peer_and_group_lookup_vty(vty, ip_str);
8114 if (!peer)
8115 return CMD_WARNING_CONFIG_FAILED;
718e3744 8116
1de27621
DA
8117 route_map = route_map_lookup_warn_noexist(vty, name_str);
8118 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 8119
d62a17ae 8120 return bgp_vty_return(vty, ret);
718e3744 8121}
8122
8123/* Unset route-map from the peer. */
d62a17ae 8124static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8125 afi_t afi, safi_t safi)
718e3744 8126{
d62a17ae 8127 int ret;
8128 struct peer *peer;
718e3744 8129
d62a17ae 8130 peer = peer_and_group_lookup_vty(vty, ip_str);
8131 if (!peer)
8132 return CMD_WARNING_CONFIG_FAILED;
718e3744 8133
d62a17ae 8134 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8135
d62a17ae 8136 return bgp_vty_return(vty, ret);
718e3744 8137}
8138
8139DEFUN (neighbor_unsuppress_map,
8140 neighbor_unsuppress_map_cmd,
9ccf14f7 8141 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8142 NEIGHBOR_STR
8143 NEIGHBOR_ADDR_STR2
8144 "Route-map to selectively unsuppress suppressed routes\n"
8145 "Name of route map\n")
8146{
d62a17ae 8147 int idx_peer = 1;
8148 int idx_word = 3;
8149 return peer_unsuppress_map_set_vty(
8150 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8151 argv[idx_word]->arg);
718e3744 8152}
8153
d62a17ae 8154ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8155 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8156 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8157 "Route-map to selectively unsuppress suppressed routes\n"
8158 "Name of route map\n")
596c17ba 8159
718e3744 8160DEFUN (no_neighbor_unsuppress_map,
8161 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8162 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8163 NO_STR
8164 NEIGHBOR_STR
8165 NEIGHBOR_ADDR_STR2
8166 "Route-map to selectively unsuppress suppressed routes\n"
8167 "Name of route map\n")
8168{
d62a17ae 8169 int idx_peer = 2;
8170 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8171 bgp_node_afi(vty),
8172 bgp_node_safi(vty));
718e3744 8173}
6b0655a2 8174
d62a17ae 8175ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8176 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8177 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8178 "Route-map to selectively unsuppress suppressed routes\n"
8179 "Name of route map\n")
596c17ba 8180
fde246e8 8181/* Maximum number of prefix to be sent to the neighbor. */
232c75cd
CS
8182DEFUN_YANG(neighbor_maximum_prefix_out,
8183 neighbor_maximum_prefix_out_cmd,
8184 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8186 "Maximum number of prefixes to be sent to this peer\n"
8187 "Maximum no. of prefix limit\n")
fde246e8 8188{
04261dec
CS
8189 char base_xpath[XPATH_MAXLEN];
8190 char af_xpath[XPATH_MAXLEN];
8191 char attr_xpath[XPATH_MAXLEN];
fde246e8
DA
8192 int idx_peer = 1;
8193 int idx_number = 3;
fde246e8
DA
8194 afi_t afi = bgp_node_afi(vty);
8195 safi_t safi = bgp_node_safi(vty);
8196
04261dec
CS
8197 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8198 yang_afi_safi_value2identity(afi, safi));
8199 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8200 sizeof(base_xpath), af_xpath)
8201 < 0)
fde246e8
DA
8202 return CMD_WARNING_CONFIG_FAILED;
8203
04261dec
CS
8204 snprintf(attr_xpath, sizeof(attr_xpath),
8205 "/%s/prefix-limit/direction-list[direction='out']",
8206 bgp_afi_safi_get_container_str(afi, safi));
8207 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
fde246e8 8208
04261dec 8209 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
fde246e8 8210
04261dec
CS
8211 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8212 argv[idx_number]->arg);
8213
8214 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8215}
8216
232c75cd
CS
8217DEFUN_YANG(no_neighbor_maximum_prefix_out,
8218 no_neighbor_maximum_prefix_out_cmd,
8219 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8220 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8221 "Maximum number of prefixes to be sent to this peer\n")
fde246e8 8222{
04261dec
CS
8223 char base_xpath[XPATH_MAXLEN];
8224 char af_xpath[XPATH_MAXLEN];
8225 char attr_xpath[XPATH_MAXLEN];
fde246e8 8226 int idx_peer = 2;
fde246e8
DA
8227 afi_t afi = bgp_node_afi(vty);
8228 safi_t safi = bgp_node_safi(vty);
8229
04261dec
CS
8230 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8231 yang_afi_safi_value2identity(afi, safi));
8232 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8233 sizeof(base_xpath), af_xpath)
8234 < 0)
fde246e8
DA
8235 return CMD_WARNING_CONFIG_FAILED;
8236
04261dec
CS
8237 snprintf(attr_xpath, sizeof(attr_xpath),
8238 "/%s/prefix-limit/direction-list[direction='out']",
8239 bgp_afi_safi_get_container_str(afi, safi));
8240 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8241
8242 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
fde246e8 8243
04261dec 8244 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8245}
8246
9cbd06e0
DA
8247/* Maximum number of prefix configuration. Prefix count is different
8248 for each peer configuration. So this configuration can be set for
718e3744 8249 each peer configuration. */
232c75cd
CS
8250DEFUN_YANG(neighbor_maximum_prefix,
8251 neighbor_maximum_prefix_cmd,
8252 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8253 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8254 "Maximum number of prefix accept from this peer\n"
8255 "maximum no. of prefix limit\n"
8256 "Force checking all received routes not only accepted\n")
718e3744 8257{
d62a17ae 8258 int idx_peer = 1;
8259 int idx_number = 3;
9cbd06e0 8260 int idx_force = 0;
04261dec
CS
8261 char base_xpath[XPATH_MAXLEN];
8262 char af_xpath[XPATH_MAXLEN];
8263 char attr_xpath[XPATH_MAXLEN];
8264 afi_t afi = bgp_node_afi(vty);
8265 safi_t safi = bgp_node_safi(vty);
8266
8267 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8268 yang_afi_safi_value2identity(afi, safi));
8269 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8270 sizeof(base_xpath), af_xpath)
8271 < 0)
8272 return CMD_WARNING_CONFIG_FAILED;
8273
8274 snprintf(attr_xpath, sizeof(attr_xpath),
8275 "/%s/prefix-limit/direction-list[direction='in']",
8276 bgp_afi_safi_get_container_str(afi, safi));
8277 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8278
8279 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9cbd06e0 8280
04261dec
CS
8281 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8282 argv[idx_number]->arg);
9cbd06e0 8283 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8284 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8285 "true");
9cbd06e0 8286
04261dec 8287 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8288}
8289
d62a17ae 8290ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8291 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8292 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8293 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8294 "maximum no. of prefix limit\n"
8295 "Force checking all received routes not only accepted\n")
596c17ba 8296
232c75cd
CS
8297DEFUN_YANG(neighbor_maximum_prefix_threshold,
8298 neighbor_maximum_prefix_threshold_cmd,
8299 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8300 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8301 "Maximum number of prefix accept from this peer\n"
8302 "maximum no. of prefix limit\n"
8303 "Threshold value (%) at which to generate a warning msg\n"
8304 "Force checking all received routes not only accepted\n")
e0701b79 8305{
d62a17ae 8306 int idx_peer = 1;
8307 int idx_number = 3;
8308 int idx_number_2 = 4;
9cbd06e0 8309 int idx_force = 0;
04261dec
CS
8310 char base_xpath[XPATH_MAXLEN];
8311 char af_xpath[XPATH_MAXLEN];
8312 char attr_xpath[XPATH_MAXLEN];
8313 afi_t afi = bgp_node_afi(vty);
8314 safi_t safi = bgp_node_safi(vty);
8315
8316 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8317 yang_afi_safi_value2identity(afi, safi));
8318 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8319 sizeof(base_xpath), af_xpath)
8320 < 0)
8321 return CMD_WARNING_CONFIG_FAILED;
8322
8323 snprintf(attr_xpath, sizeof(attr_xpath),
8324 "/%s/prefix-limit/direction-list[direction='in']",
8325 bgp_afi_safi_get_container_str(afi, safi));
8326 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8327
8328 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8329
8330 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8331 argv[idx_number]->arg);
8332
8333 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8334 NB_OP_MODIFY, argv[idx_number_2]->arg);
9cbd06e0
DA
8335
8336 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8337 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8338 "true");
9cbd06e0 8339
04261dec 8340 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8341}
e0701b79 8342
d62a17ae 8343ALIAS_HIDDEN(
8344 neighbor_maximum_prefix_threshold,
8345 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8346 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8347 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8348 "Maximum number of prefix accept from this peer\n"
8349 "maximum no. of prefix limit\n"
9cbd06e0
DA
8350 "Threshold value (%) at which to generate a warning msg\n"
8351 "Force checking all received routes not only accepted\n")
596c17ba 8352
232c75cd
CS
8353DEFUN_YANG(neighbor_maximum_prefix_warning,
8354 neighbor_maximum_prefix_warning_cmd,
8355 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8356 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8357 "Maximum number of prefix accept from this peer\n"
8358 "maximum no. of prefix limit\n"
8359 "Only give warning message when limit is exceeded\n"
8360 "Force checking all received routes not only accepted\n")
718e3744 8361{
d62a17ae 8362 int idx_peer = 1;
8363 int idx_number = 3;
9cbd06e0 8364 int idx_force = 0;
04261dec
CS
8365 char base_xpath[XPATH_MAXLEN];
8366 char af_xpath[XPATH_MAXLEN];
8367 char attr_xpath[XPATH_MAXLEN];
8368 afi_t afi = bgp_node_afi(vty);
8369 safi_t safi = bgp_node_safi(vty);
8370
8371 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8372 yang_afi_safi_value2identity(afi, safi));
8373 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8374 sizeof(base_xpath), af_xpath)
8375 < 0)
8376 return CMD_WARNING_CONFIG_FAILED;
9cbd06e0 8377
04261dec
CS
8378 snprintf(attr_xpath, sizeof(attr_xpath),
8379 "/%s/prefix-limit/direction-list[direction='in']",
8380 bgp_afi_safi_get_container_str(afi, safi));
8381 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8382
8383 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8384
8385 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8386 argv[idx_number]->arg);
8387
8388 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8389 "true");
9cbd06e0 8390 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8391 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8392 "true");
9cbd06e0 8393
04261dec 8394 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8395}
8396
d62a17ae 8397ALIAS_HIDDEN(
8398 neighbor_maximum_prefix_warning,
8399 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8400 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8401 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8402 "Maximum number of prefix accept from this peer\n"
8403 "maximum no. of prefix limit\n"
9cbd06e0
DA
8404 "Only give warning message when limit is exceeded\n"
8405 "Force checking all received routes not only accepted\n")
596c17ba 8406
232c75cd
CS
8407DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8408 neighbor_maximum_prefix_threshold_warning_cmd,
8409 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8410 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8411 "Maximum number of prefix accept from this peer\n"
8412 "maximum no. of prefix limit\n"
8413 "Threshold value (%) at which to generate a warning msg\n"
8414 "Only give warning message when limit is exceeded\n"
8415 "Force checking all received routes not only accepted\n")
e0701b79 8416{
d62a17ae 8417 int idx_peer = 1;
8418 int idx_number = 3;
8419 int idx_number_2 = 4;
9cbd06e0 8420 int idx_force = 0;
04261dec
CS
8421 char base_xpath[XPATH_MAXLEN];
8422 char af_xpath[XPATH_MAXLEN];
8423 char attr_xpath[XPATH_MAXLEN];
8424 afi_t afi = bgp_node_afi(vty);
8425 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8426
04261dec
CS
8427 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8428 yang_afi_safi_value2identity(afi, safi));
8429 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8430 sizeof(base_xpath), af_xpath)
8431 < 0)
8432 return CMD_WARNING_CONFIG_FAILED;
8433
8434 snprintf(attr_xpath, sizeof(attr_xpath),
8435 "/%s/prefix-limit/direction-list[direction='in']",
8436 bgp_afi_safi_get_container_str(afi, safi));
8437 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8438
8439 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8440
8441 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8442 argv[idx_number]->arg);
8443 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8444 NB_OP_MODIFY, argv[idx_number_2]->arg);
8445 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8446 "true");
9cbd06e0 8447 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8448 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8449 "true");
9cbd06e0 8450
04261dec 8451 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8452}
8453
d62a17ae 8454ALIAS_HIDDEN(
8455 neighbor_maximum_prefix_threshold_warning,
8456 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8457 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8459 "Maximum number of prefix accept from this peer\n"
8460 "maximum no. of prefix limit\n"
8461 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8462 "Only give warning message when limit is exceeded\n"
8463 "Force checking all received routes not only accepted\n")
596c17ba 8464
232c75cd
CS
8465DEFUN_YANG(neighbor_maximum_prefix_restart,
8466 neighbor_maximum_prefix_restart_cmd,
8467 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8468 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8469 "Maximum number of prefix accept from this peer\n"
8470 "maximum no. of prefix limit\n"
8471 "Restart bgp connection after limit is exceeded\n"
8472 "Restart interval in minutes\n"
8473 "Force checking all received routes not only accepted\n")
0a486e5f 8474{
d62a17ae 8475 int idx_peer = 1;
8476 int idx_number = 3;
8477 int idx_number_2 = 5;
9cbd06e0 8478 int idx_force = 0;
04261dec
CS
8479 char base_xpath[XPATH_MAXLEN];
8480 char af_xpath[XPATH_MAXLEN];
8481 char attr_xpath[XPATH_MAXLEN];
8482 afi_t afi = bgp_node_afi(vty);
8483 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8484
04261dec
CS
8485 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8486 yang_afi_safi_value2identity(afi, safi));
8487 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8488 sizeof(base_xpath), af_xpath)
8489 < 0)
8490 return CMD_WARNING_CONFIG_FAILED;
8491
8492 snprintf(attr_xpath, sizeof(attr_xpath),
8493 "/%s/prefix-limit/direction-list[direction='in']",
8494 bgp_afi_safi_get_container_str(afi, safi));
8495 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8496
8497 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8498
8499 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8500 argv[idx_number]->arg);
8501 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8502 argv[idx_number_2]->arg);
9cbd06e0 8503 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8504 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8505 "true");
9cbd06e0 8506
04261dec 8507 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8508}
8509
d62a17ae 8510ALIAS_HIDDEN(
8511 neighbor_maximum_prefix_restart,
8512 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8513 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8514 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8515 "Maximum number of prefix accept from this peer\n"
8516 "maximum no. of prefix limit\n"
8517 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8518 "Restart interval in minutes\n"
8519 "Force checking all received routes not only accepted\n")
596c17ba 8520
232c75cd
CS
8521DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8522 neighbor_maximum_prefix_threshold_restart_cmd,
8523 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8524 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8525 "Maximum number of prefixes to accept from this peer\n"
8526 "maximum no. of prefix limit\n"
8527 "Threshold value (%) at which to generate a warning msg\n"
8528 "Restart bgp connection after limit is exceeded\n"
8529 "Restart interval in minutes\n"
8530 "Force checking all received routes not only accepted\n")
0a486e5f 8531{
d62a17ae 8532 int idx_peer = 1;
8533 int idx_number = 3;
8534 int idx_number_2 = 4;
8535 int idx_number_3 = 6;
9cbd06e0 8536 int idx_force = 0;
04261dec
CS
8537 char base_xpath[XPATH_MAXLEN];
8538 char af_xpath[XPATH_MAXLEN];
8539 char attr_xpath[XPATH_MAXLEN];
8540 afi_t afi = bgp_node_afi(vty);
8541 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8542
04261dec
CS
8543 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8544 yang_afi_safi_value2identity(afi, safi));
8545 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8546 sizeof(base_xpath), af_xpath)
8547 < 0)
8548 return CMD_WARNING_CONFIG_FAILED;
8549
8550 snprintf(attr_xpath, sizeof(attr_xpath),
8551 "/%s/prefix-limit/direction-list[direction='in']",
8552 bgp_afi_safi_get_container_str(afi, safi));
8553 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8554
8555 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8556
8557 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8558 argv[idx_number]->arg);
8559 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8560 NB_OP_MODIFY, argv[idx_number_2]->arg);
8561 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8562 argv[idx_number_3]->arg);
9cbd06e0 8563 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8564 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8565 "true");
9cbd06e0 8566
04261dec 8567 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 8568}
8569
8570ALIAS_HIDDEN(
8571 neighbor_maximum_prefix_threshold_restart,
8572 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8573 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8574 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8575 "Maximum number of prefixes to accept from this peer\n"
8576 "maximum no. of prefix limit\n"
8577 "Threshold value (%) at which to generate a warning msg\n"
8578 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8579 "Restart interval in minutes\n"
8580 "Force checking all received routes not only accepted\n")
596c17ba 8581
232c75cd
CS
8582DEFUN_YANG(no_neighbor_maximum_prefix,
8583 no_neighbor_maximum_prefix_cmd,
8584 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8585 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8586 "Maximum number of prefixes to accept from this peer\n"
8587 "maximum no. of prefix limit\n"
8588 "Threshold value (%) at which to generate a warning msg\n"
8589 "Restart bgp connection after limit is exceeded\n"
8590 "Restart interval in minutes\n"
8591 "Only give warning message when limit is exceeded\n"
8592 "Force checking all received routes not only accepted\n")
718e3744 8593{
d62a17ae 8594 int idx_peer = 2;
04261dec
CS
8595 char base_xpath[XPATH_MAXLEN];
8596 char af_xpath[XPATH_MAXLEN];
8597 char attr_xpath[XPATH_MAXLEN];
8598 afi_t afi = bgp_node_afi(vty);
8599 safi_t safi = bgp_node_safi(vty);
8600
8601 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8602 yang_afi_safi_value2identity(afi, safi));
8603 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8604 sizeof(base_xpath), af_xpath)
8605 < 0)
8606 return CMD_WARNING_CONFIG_FAILED;
8607
8608 snprintf(attr_xpath, sizeof(attr_xpath),
8609 "/%s/prefix-limit/direction-list[direction='in']",
8610 bgp_afi_safi_get_container_str(afi, safi));
8611 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8612
8613 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8614
8615 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8616}
e52702f2 8617
d62a17ae 8618ALIAS_HIDDEN(
8619 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8620 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8621 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8622 "Maximum number of prefixes to accept from this peer\n"
8623 "maximum no. of prefix limit\n"
8624 "Threshold value (%) at which to generate a warning msg\n"
8625 "Restart bgp connection after limit is exceeded\n"
8626 "Restart interval in minutes\n"
9cbd06e0
DA
8627 "Only give warning message when limit is exceeded\n"
8628 "Force checking all received routes not only accepted\n")
596c17ba 8629
718e3744 8630
718e3744 8631/* "neighbor allowas-in" */
8632DEFUN (neighbor_allowas_in,
8633 neighbor_allowas_in_cmd,
fd8503f5 8634 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8635 NEIGHBOR_STR
8636 NEIGHBOR_ADDR_STR2
31500417 8637 "Accept as-path with my AS present in it\n"
f79f7a7b 8638 "Number of occurrences of AS number\n"
fd8503f5 8639 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8640{
d62a17ae 8641 int idx_peer = 1;
8642 int idx_number_origin = 3;
8643 int ret;
8644 int origin = 0;
8645 struct peer *peer;
8646 int allow_num = 0;
8647
8648 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8649 if (!peer)
8650 return CMD_WARNING_CONFIG_FAILED;
8651
8652 if (argc <= idx_number_origin)
8653 allow_num = 3;
8654 else {
8655 if (argv[idx_number_origin]->type == WORD_TKN)
8656 origin = 1;
8657 else
8658 allow_num = atoi(argv[idx_number_origin]->arg);
8659 }
8660
8661 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8662 allow_num, origin);
8663
8664 return bgp_vty_return(vty, ret);
8665}
8666
8667ALIAS_HIDDEN(
8668 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8669 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8671 "Accept as-path with my AS present in it\n"
f79f7a7b 8672 "Number of occurrences of AS number\n"
d62a17ae 8673 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8674
718e3744 8675DEFUN (no_neighbor_allowas_in,
8676 no_neighbor_allowas_in_cmd,
fd8503f5 8677 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8678 NO_STR
8679 NEIGHBOR_STR
8680 NEIGHBOR_ADDR_STR2
8334fd5a 8681 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8682 "Number of occurrences of AS number\n"
fd8503f5 8683 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8684{
d62a17ae 8685 int idx_peer = 2;
8686 int ret;
8687 struct peer *peer;
718e3744 8688
d62a17ae 8689 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8690 if (!peer)
8691 return CMD_WARNING_CONFIG_FAILED;
718e3744 8692
d62a17ae 8693 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8694 bgp_node_safi(vty));
718e3744 8695
d62a17ae 8696 return bgp_vty_return(vty, ret);
718e3744 8697}
6b0655a2 8698
d62a17ae 8699ALIAS_HIDDEN(
8700 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8701 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8702 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8703 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8704 "Number of occurrences of AS number\n"
d62a17ae 8705 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8706
f4b8ec07
CS
8707DEFUN_YANG (neighbor_ttl_security,
8708 neighbor_ttl_security_cmd,
8709 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8710 NEIGHBOR_STR
8711 NEIGHBOR_ADDR_STR2
8712 "BGP ttl-security parameters\n"
8713 "Specify the maximum number of hops to the BGP peer\n"
8714 "Number of hops to BGP peer\n")
fa411a21 8715{
d62a17ae 8716 int idx_peer = 1;
8717 int idx_number = 4;
f4b8ec07 8718 char base_xpath[XPATH_MAXLEN];
d62a17ae 8719
f4b8ec07
CS
8720 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8721 sizeof(base_xpath), NULL)
8722 < 0)
d62a17ae 8723 return CMD_WARNING_CONFIG_FAILED;
8724
f4b8ec07
CS
8725 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8726 argv[idx_number]->arg);
7ebe625c 8727
f4b8ec07 8728 return nb_cli_apply_changes(vty, base_xpath);
fa411a21
NH
8729}
8730
232c75cd
CS
8731DEFUN_YANG(no_neighbor_ttl_security,
8732 no_neighbor_ttl_security_cmd,
8733 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8734 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8735 "BGP ttl-security parameters\n"
8736 "Specify the maximum number of hops to the BGP peer\n"
8737 "Number of hops to BGP peer\n")
fa411a21 8738{
d62a17ae 8739 int idx_peer = 2;
f4b8ec07 8740 char base_xpath[XPATH_MAXLEN];
fa411a21 8741
f4b8ec07
CS
8742 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8743 sizeof(base_xpath), NULL)
8744 < 0)
d62a17ae 8745 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8746
f4b8ec07
CS
8747 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8748
8749 return nb_cli_apply_changes(vty, base_xpath);
fa411a21 8750}
6b0655a2 8751
adbac85e
DW
8752DEFUN (neighbor_addpath_tx_all_paths,
8753 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8754 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8755 NEIGHBOR_STR
8756 NEIGHBOR_ADDR_STR2
8757 "Use addpath to advertise all paths to a neighbor\n")
8758{
d62a17ae 8759 int idx_peer = 1;
8760 struct peer *peer;
adbac85e 8761
d62a17ae 8762 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8763 if (!peer)
8764 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8765
dcc68b5e
MS
8766 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8767 BGP_ADDPATH_ALL);
8768 return CMD_SUCCESS;
adbac85e
DW
8769}
8770
d62a17ae 8771ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8772 neighbor_addpath_tx_all_paths_hidden_cmd,
8773 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8774 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8775 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8776
adbac85e
DW
8777DEFUN (no_neighbor_addpath_tx_all_paths,
8778 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8779 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8780 NO_STR
8781 NEIGHBOR_STR
8782 NEIGHBOR_ADDR_STR2
8783 "Use addpath to advertise all paths to a neighbor\n")
8784{
d62a17ae 8785 int idx_peer = 2;
dcc68b5e
MS
8786 struct peer *peer;
8787
8788 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8789 if (!peer)
8790 return CMD_WARNING_CONFIG_FAILED;
8791
8792 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8793 != BGP_ADDPATH_ALL) {
8794 vty_out(vty,
8795 "%% Peer not currently configured to transmit all paths.");
8796 return CMD_WARNING_CONFIG_FAILED;
8797 }
8798
8799 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8800 BGP_ADDPATH_NONE);
8801
8802 return CMD_SUCCESS;
adbac85e
DW
8803}
8804
d62a17ae 8805ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8806 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8807 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8808 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8809 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8810
06370dac
DW
8811DEFUN (neighbor_addpath_tx_bestpath_per_as,
8812 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8813 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8814 NEIGHBOR_STR
8815 NEIGHBOR_ADDR_STR2
8816 "Use addpath to advertise the bestpath per each neighboring AS\n")
8817{
d62a17ae 8818 int idx_peer = 1;
8819 struct peer *peer;
06370dac 8820
d62a17ae 8821 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8822 if (!peer)
8823 return CMD_WARNING_CONFIG_FAILED;
06370dac 8824
dcc68b5e
MS
8825 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8826 BGP_ADDPATH_BEST_PER_AS);
8827
8828 return CMD_SUCCESS;
06370dac
DW
8829}
8830
d62a17ae 8831ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8832 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8833 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8834 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8835 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8836
06370dac
DW
8837DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8838 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8839 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8840 NO_STR
8841 NEIGHBOR_STR
8842 NEIGHBOR_ADDR_STR2
8843 "Use addpath to advertise the bestpath per each neighboring AS\n")
8844{
d62a17ae 8845 int idx_peer = 2;
dcc68b5e
MS
8846 struct peer *peer;
8847
8848 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8849 if (!peer)
8850 return CMD_WARNING_CONFIG_FAILED;
8851
8852 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8853 != BGP_ADDPATH_BEST_PER_AS) {
8854 vty_out(vty,
8855 "%% Peer not currently configured to transmit all best path per as.");
8856 return CMD_WARNING_CONFIG_FAILED;
8857 }
8858
8859 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8860 BGP_ADDPATH_NONE);
8861
8862 return CMD_SUCCESS;
06370dac
DW
8863}
8864
d62a17ae 8865ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8866 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8867 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8868 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8869 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8870
2b31007c
RZ
8871DEFPY(
8872 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8873 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8874 NEIGHBOR_STR
8875 NEIGHBOR_ADDR_STR2
8876 "Detect AS loops before sending to neighbor\n")
8877{
8878 struct peer *peer;
8879
8880 peer = peer_and_group_lookup_vty(vty, neighbor);
8881 if (!peer)
8882 return CMD_WARNING_CONFIG_FAILED;
8883
8884 peer->as_path_loop_detection = true;
8885
8886 return CMD_SUCCESS;
8887}
8888
8889DEFPY(
8890 no_neighbor_aspath_loop_detection,
8891 no_neighbor_aspath_loop_detection_cmd,
8892 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8893 NO_STR
8894 NEIGHBOR_STR
8895 NEIGHBOR_ADDR_STR2
8896 "Detect AS loops before sending to neighbor\n")
8897{
8898 struct peer *peer;
8899
8900 peer = peer_and_group_lookup_vty(vty, neighbor);
8901 if (!peer)
8902 return CMD_WARNING_CONFIG_FAILED;
8903
8904 peer->as_path_loop_detection = false;
8905
8906 return CMD_SUCCESS;
8907}
8908
0221327c
DS
8909DEFPY(neighbor_damp,
8910 neighbor_damp_cmd,
8911 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8912 NEIGHBOR_STR
8913 NEIGHBOR_ADDR_STR2
8914 "Enable neighbor route-flap dampening\n"
8915 "Half-life time for the penalty\n"
8916 "Value to start reusing a route\n"
8917 "Value to start suppressing a route\n"
8918 "Maximum duration to suppress a stable route\n")
8919{
8920 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8921
8922 if (!peer)
8923 return CMD_WARNING_CONFIG_FAILED;
8924 if (!half)
8925 half = DEFAULT_HALF_LIFE;
8926 if (!reuse) {
8927 reuse = DEFAULT_REUSE;
8928 suppress = DEFAULT_SUPPRESS;
8929 max = half * 4;
8930 }
8931 if (suppress < reuse) {
8932 vty_out(vty,
8933 "Suppress value cannot be less than reuse value\n");
8934 return CMD_WARNING_CONFIG_FAILED;
8935 }
8936 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8937 half * 60, reuse, suppress, max * 60);
8938 return CMD_SUCCESS;
8939}
8940
8941DEFPY(no_neighbor_damp,
8942 no_neighbor_damp_cmd,
8943 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8944 NO_STR
8945 NEIGHBOR_STR
8946 NEIGHBOR_ADDR_STR2
8947 "Enable neighbor route-flap dampening\n"
8948 "Half-life time for the penalty\n"
8949 "Value to start reusing a route\n"
8950 "Value to start suppressing a route\n"
8951 "Maximum duration to suppress a stable route\n")
8952{
8953 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8954
8955 if (!peer)
8956 return CMD_WARNING_CONFIG_FAILED;
8957 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8958 return CMD_SUCCESS;
8959}
8960
8961DEFPY (show_ip_bgp_neighbor_damp_param,
8962 show_ip_bgp_neighbor_damp_param_cmd,
8963 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8964 SHOW_STR
8965 IP_STR
8966 BGP_STR
8967 BGP_AFI_HELP_STR
8968 "Address Family modifier\n"
8969 NEIGHBOR_STR
8970 NEIGHBOR_ADDR_STR2
8971 "Neighbor route-flap dampening information\n"
8972 "Display detail of configured dampening parameters\n"
8973 JSON_STR)
8974{
8975 bool use_json = false;
8976 int idx = 0;
8977 afi_t afi = AFI_IP;
8978 safi_t safi = SAFI_UNICAST;
8979 struct peer *peer;
8980
8981 if (argv_find(argv, argc, "ip", &idx))
8982 afi = AFI_IP;
8983 if (argv_find(argv, argc, "ipv4", &idx))
8984 afi = AFI_IP;
8985 if (argv_find(argv, argc, "ipv6", &idx))
8986 afi = AFI_IP6;
8987 peer = peer_and_group_lookup_vty(vty, neighbor);
8988 if (!peer)
8989 return CMD_WARNING;
8990 if (json)
8991 use_json = true;
8992 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
8993 return CMD_SUCCESS;
8994}
8995
b9c7bc5a 8996static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8997 struct ecommunity **list, bool is_rt6)
ddb5b488 8998{
b9c7bc5a
PZ
8999 struct ecommunity *ecom = NULL;
9000 struct ecommunity *ecomadd;
ddb5b488 9001
b9c7bc5a 9002 for (; argc; --argc, ++argv) {
9a659715
PG
9003 if (is_rt6)
9004 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
9005 ECOMMUNITY_ROUTE_TARGET,
9006 0);
9007 else
9008 ecomadd = ecommunity_str2com(argv[0]->arg,
9009 ECOMMUNITY_ROUTE_TARGET,
9010 0);
b9c7bc5a
PZ
9011 if (!ecomadd) {
9012 vty_out(vty, "Malformed community-list value\n");
9013 if (ecom)
9014 ecommunity_free(&ecom);
9015 return CMD_WARNING_CONFIG_FAILED;
9016 }
ddb5b488 9017
b9c7bc5a
PZ
9018 if (ecom) {
9019 ecommunity_merge(ecom, ecomadd);
9020 ecommunity_free(&ecomadd);
9021 } else {
9022 ecom = ecomadd;
9023 }
9024 }
9025
9026 if (*list) {
9027 ecommunity_free(&*list);
ddb5b488 9028 }
b9c7bc5a
PZ
9029 *list = ecom;
9030
9031 return CMD_SUCCESS;
ddb5b488
PZ
9032}
9033
37a87b8f
CS
9034bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
9035 bool v2vimport, char *errmsg, size_t errmsg_len)
9036{
9037 if (!v2vimport) {
9038 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9039 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9040 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9041 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9042 snprintf(
9043 errmsg, errmsg_len, "%s",
9044 "%% error: Please unconfigure import vrf commands before using vpn commands");
9045 return false;
9046 }
9047 } else {
9048 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9049 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9050 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9051 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9052 snprintf(
9053 errmsg, errmsg_len, "%s",
9054 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
9055 return false;
9056 }
9057 }
9058 return true;
9059}
9060
0ca70ba5
DS
9061/*
9062 * v2vimport is true if we are handling a `import vrf ...` command
9063 */
9064static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 9065{
0ca70ba5
DS
9066 afi_t afi;
9067
ddb5b488 9068 switch (vty->node) {
b9c7bc5a 9069 case BGP_IPV4_NODE:
0ca70ba5
DS
9070 afi = AFI_IP;
9071 break;
b9c7bc5a 9072 case BGP_IPV6_NODE:
0ca70ba5
DS
9073 afi = AFI_IP6;
9074 break;
ddb5b488
PZ
9075 default:
9076 vty_out(vty,
b9c7bc5a 9077 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 9078 return AFI_MAX;
ddb5b488 9079 }
69b07479 9080
0ca70ba5
DS
9081 if (!v2vimport) {
9082 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9083 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9084 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9085 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9086 vty_out(vty,
9087 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9088 return AFI_MAX;
9089 }
9090 } else {
9091 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9092 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9093 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9094 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9095 vty_out(vty,
9096 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9097 return AFI_MAX;
9098 }
9099 }
9100 return afi;
ddb5b488
PZ
9101}
9102
37a87b8f
CS
9103DEFPY_YANG(
9104 af_rd_vpn_export,
9105 af_rd_vpn_export_cmd,
9106 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9107 NO_STR
9108 "Specify route distinguisher\n"
9109 "Between current address-family and vpn\n"
9110 "For routes leaked from current address-family to vpn\n"
9111 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 9112{
37a87b8f 9113 char base_xpath[XPATH_MAXLEN];
ddb5b488 9114 afi_t afi;
37a87b8f 9115 safi_t safi;
b9c7bc5a 9116 int idx = 0;
b9c7bc5a 9117
37a87b8f
CS
9118 afi = bgp_node_afi(vty);
9119 safi = bgp_node_safi(vty);
ddb5b488 9120
37a87b8f
CS
9121 snprintf(
9122 base_xpath, sizeof(base_xpath),
9123 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9124 yang_afi_safi_value2identity(afi, safi),
9125 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9126
37a87b8f
CS
9127 if (argv_find(argv, argc, "no", &idx))
9128 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9129 else
9130 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
ddb5b488 9131
37a87b8f
CS
9132 return nb_cli_apply_changes(vty, base_xpath);
9133}
ddb5b488 9134
37a87b8f
CS
9135void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9136 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9137{
9138 int indent = 2;
69b07479 9139
37a87b8f
CS
9140 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9141 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9142}
9143
b9c7bc5a
PZ
9144ALIAS (af_rd_vpn_export,
9145 af_no_rd_vpn_export_cmd,
9146 "no rd vpn export",
ddb5b488 9147 NO_STR
b9c7bc5a
PZ
9148 "Specify route distinguisher\n"
9149 "Between current address-family and vpn\n"
9150 "For routes leaked from current address-family to vpn\n")
ddb5b488 9151
b9c7bc5a
PZ
9152DEFPY (af_label_vpn_export,
9153 af_label_vpn_export_cmd,
e70e9f8e 9154 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9155 NO_STR
ddb5b488 9156 "label value for VRF\n"
b9c7bc5a
PZ
9157 "Between current address-family and vpn\n"
9158 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9159 "Label Value <0-1048575>\n"
9160 "Automatically assign a label\n")
ddb5b488
PZ
9161{
9162 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9163 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9164 afi_t afi;
b9c7bc5a 9165 int idx = 0;
c6423c31 9166 bool yes = true;
b9c7bc5a
PZ
9167
9168 if (argv_find(argv, argc, "no", &idx))
c6423c31 9169 yes = false;
ddb5b488 9170
21a16cc2
PZ
9171 /* If "no ...", squash trailing parameter */
9172 if (!yes)
9173 label_auto = NULL;
9174
e70e9f8e
PZ
9175 if (yes) {
9176 if (!label_auto)
9177 label = label_val; /* parser should force unsigned */
9178 }
ddb5b488 9179
0ca70ba5 9180 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9181 if (afi == AFI_MAX)
9182 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9183
e70e9f8e 9184
69b07479
DS
9185 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9186 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9187 /* no change */
9188 return CMD_SUCCESS;
e70e9f8e 9189
69b07479
DS
9190 /*
9191 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9192 */
9193 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9194 bgp_get_default(), bgp);
9195
9196 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9197 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9198
9199 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9200
9201 /*
9202 * label has previously been automatically
9203 * assigned by labelpool: release it
9204 *
9205 * NB if tovpn_label == MPLS_LABEL_NONE it
9206 * means the automatic assignment is in flight
9207 * and therefore the labelpool callback must
9208 * detect that the auto label is not needed.
9209 */
9210
9211 bgp_lp_release(LP_TYPE_VRF,
9212 &bgp->vpn_policy[afi],
9213 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9214 }
69b07479
DS
9215 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9216 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9217 }
ddb5b488 9218
69b07479
DS
9219 bgp->vpn_policy[afi].tovpn_label = label;
9220 if (label_auto) {
9221 SET_FLAG(bgp->vpn_policy[afi].flags,
9222 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9223 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9224 vpn_leak_label_callback);
ddb5b488
PZ
9225 }
9226
69b07479
DS
9227 /* post-change: re-export vpn routes */
9228 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9229 bgp_get_default(), bgp);
9230
0d020cd6 9231 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9232 return CMD_SUCCESS;
9233}
9234
b9c7bc5a
PZ
9235ALIAS (af_label_vpn_export,
9236 af_no_label_vpn_export_cmd,
9237 "no label vpn export",
9238 NO_STR
9239 "label value for VRF\n"
9240 "Between current address-family and vpn\n"
9241 "For routes leaked from current address-family to vpn\n")
ddb5b488 9242
37a87b8f 9243DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 9244 af_nexthop_vpn_export_cmd,
8c85ca28 9245 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9246 NO_STR
ddb5b488 9247 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9248 "Between current address-family and vpn\n"
9249 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9250 "IPv4 prefix\n"
9251 "IPv6 prefix\n")
9252{
37a87b8f 9253 char base_xpath[XPATH_MAXLEN];
ddb5b488 9254 afi_t afi;
37a87b8f
CS
9255 safi_t safi;
9256 int idx = 0;
ddb5b488
PZ
9257 struct prefix p;
9258
8c85ca28
QY
9259 if (!no) {
9260 if (!nexthop_su) {
9261 vty_out(vty, "%% Nexthop required\n");
9262 return CMD_WARNING_CONFIG_FAILED;
9263 }
8c85ca28 9264 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9265 return CMD_WARNING_CONFIG_FAILED;
9266 }
ddb5b488 9267
37a87b8f
CS
9268 afi = bgp_node_afi(vty);
9269 safi = bgp_node_safi(vty);
ddb5b488 9270
37a87b8f
CS
9271 snprintf(
9272 base_xpath, sizeof(base_xpath),
9273 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9274 yang_afi_safi_value2identity(afi, safi),
9275 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9276
37a87b8f
CS
9277 if (argv_find(argv, argc, "no", &idx))
9278 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9279 else
9280 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9281 nexthop_su_str);
ddb5b488 9282
37a87b8f
CS
9283 return nb_cli_apply_changes(vty, base_xpath);
9284}
69b07479 9285
37a87b8f
CS
9286void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9287 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9288{
9289 int indent = 2;
9290
9291 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9292 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9293}
9294
b9c7bc5a 9295static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9296{
b9c7bc5a
PZ
9297 if (!strcmp(dstr, "import")) {
9298 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9299 } else if (!strcmp(dstr, "export")) {
9300 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9301 } else if (!strcmp(dstr, "both")) {
9302 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9303 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9304 } else {
9305 vty_out(vty, "%% direction parse error\n");
9306 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9307 }
ddb5b488
PZ
9308 return CMD_SUCCESS;
9309}
9310
b9c7bc5a
PZ
9311DEFPY (af_rt_vpn_imexport,
9312 af_rt_vpn_imexport_cmd,
9313 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9314 NO_STR
9315 "Specify route target list\n"
ddb5b488 9316 "Specify route target list\n"
b9c7bc5a
PZ
9317 "Between current address-family and vpn\n"
9318 "For routes leaked from vpn to current address-family: match any\n"
9319 "For routes leaked from current address-family to vpn: set\n"
9320 "both import: match any and export: set\n"
ddb5b488
PZ
9321 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9322{
9323 VTY_DECLVAR_CONTEXT(bgp, bgp);
9324 int ret;
9325 struct ecommunity *ecom = NULL;
9326 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
9327 vpn_policy_direction_t dir;
9328 afi_t afi;
9329 int idx = 0;
c6423c31 9330 bool yes = true;
ddb5b488 9331
b9c7bc5a 9332 if (argv_find(argv, argc, "no", &idx))
c6423c31 9333 yes = false;
b9c7bc5a 9334
0ca70ba5 9335 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9336 if (afi == AFI_MAX)
9337 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9338
b9c7bc5a 9339 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9340 if (ret != CMD_SUCCESS)
9341 return ret;
9342
b9c7bc5a
PZ
9343 if (yes) {
9344 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9345 vty_out(vty, "%% Missing RTLIST\n");
9346 return CMD_WARNING_CONFIG_FAILED;
9347 }
c6423c31 9348 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9349 if (ret != CMD_SUCCESS) {
9350 return ret;
9351 }
ddb5b488
PZ
9352 }
9353
69b07479
DS
9354 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9355 if (!dodir[dir])
ddb5b488 9356 continue;
ddb5b488 9357
69b07479 9358 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9359
69b07479
DS
9360 if (yes) {
9361 if (bgp->vpn_policy[afi].rtlist[dir])
9362 ecommunity_free(
9363 &bgp->vpn_policy[afi].rtlist[dir]);
9364 bgp->vpn_policy[afi].rtlist[dir] =
9365 ecommunity_dup(ecom);
9366 } else {
9367 if (bgp->vpn_policy[afi].rtlist[dir])
9368 ecommunity_free(
9369 &bgp->vpn_policy[afi].rtlist[dir]);
9370 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9371 }
69b07479
DS
9372
9373 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9374 }
69b07479 9375
d555f3e9
PZ
9376 if (ecom)
9377 ecommunity_free(&ecom);
ddb5b488
PZ
9378
9379 return CMD_SUCCESS;
9380}
9381
b9c7bc5a
PZ
9382ALIAS (af_rt_vpn_imexport,
9383 af_no_rt_vpn_imexport_cmd,
9384 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9385 NO_STR
9386 "Specify route target list\n"
b9c7bc5a
PZ
9387 "Specify route target list\n"
9388 "Between current address-family and vpn\n"
9389 "For routes leaked from vpn to current address-family\n"
9390 "For routes leaked from current address-family to vpn\n"
9391 "both import and export\n")
9392
37a87b8f 9393DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9394 af_route_map_vpn_imexport_cmd,
9395/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9396 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9397 NO_STR
ddb5b488 9398 "Specify route map\n"
b9c7bc5a
PZ
9399 "Between current address-family and vpn\n"
9400 "For routes leaked from vpn to current address-family\n"
9401 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9402 "name of route-map\n")
9403{
37a87b8f 9404 char base_xpath[XPATH_MAXLEN];
ddb5b488 9405 afi_t afi;
37a87b8f 9406 safi_t safi;
ddb5b488 9407 int idx = 0;
ddb5b488 9408
37a87b8f
CS
9409 afi = bgp_node_afi(vty);
9410 safi = bgp_node_safi(vty);
ddb5b488 9411
37a87b8f
CS
9412 snprintf(
9413 base_xpath, sizeof(base_xpath),
9414 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9415 yang_afi_safi_value2identity(afi, safi),
9416 bgp_afi_safi_get_container_str(afi, safi));
9417
9418 if (argv_find(argv, argc, "no", &idx)) {
9419 if (!strcmp(direction_str, "import"))
9420 nb_cli_enqueue_change(vty, "./rmap-import",
9421 NB_OP_DESTROY, NULL);
9422 else if (!strcmp(direction_str, "export"))
9423 nb_cli_enqueue_change(vty, "./rmap-export",
9424 NB_OP_DESTROY, NULL);
9425 } else {
9426 if (!strcmp(direction_str, "import"))
9427 nb_cli_enqueue_change(vty, "./rmap-import",
9428 NB_OP_MODIFY, rmap_str);
9429 if (!strcmp(direction_str, "export"))
9430 nb_cli_enqueue_change(vty, "./rmap-export",
9431 NB_OP_MODIFY, rmap_str);
9432 }
9433 return nb_cli_apply_changes(vty, base_xpath);
9434}
ddb5b488 9435
37a87b8f
CS
9436void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9437 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9438{
9439 int indent = 2;
ddb5b488 9440
37a87b8f
CS
9441 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9442 yang_dnode_get_string(dnode, NULL));
9443}
69b07479 9444
37a87b8f
CS
9445void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9446 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9447{
9448 int indent = 2;
ddb5b488 9449
37a87b8f
CS
9450 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9451 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9452}
9453
b9c7bc5a
PZ
9454ALIAS (af_route_map_vpn_imexport,
9455 af_no_route_map_vpn_imexport_cmd,
9456 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9457 NO_STR
9458 "Specify route map\n"
b9c7bc5a
PZ
9459 "Between current address-family and vpn\n"
9460 "For routes leaked from vpn to current address-family\n"
9461 "For routes leaked from current address-family to vpn\n")
9462
bb4f6190 9463DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9464 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9465 "Import routes from another VRF\n"
9466 "Vrf routes being filtered\n"
9467 "Specify route map\n"
9468 "name of route-map\n")
9469{
9470 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
9471 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9472 afi_t afi;
bb4f6190
DS
9473 struct bgp *bgp_default;
9474
0ca70ba5 9475 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9476 if (afi == AFI_MAX)
9477 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9478
9479 bgp_default = bgp_get_default();
9480 if (!bgp_default) {
9481 int32_t ret;
9482 as_t as = bgp->as;
9483
9484 /* Auto-create assuming the same AS */
5d5393b9
DL
9485 ret = bgp_get_vty(&bgp_default, &as, NULL,
9486 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9487
9488 if (ret) {
9489 vty_out(vty,
9490 "VRF default is not configured as a bgp instance\n");
9491 return CMD_WARNING;
9492 }
9493 }
9494
69b07479 9495 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9496
ae6a6fb4
DS
9497 if (bgp->vpn_policy[afi].rmap_name[dir])
9498 XFREE(MTYPE_ROUTE_MAP_NAME,
9499 bgp->vpn_policy[afi].rmap_name[dir]);
9500 bgp->vpn_policy[afi].rmap_name[dir] =
9501 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9502 bgp->vpn_policy[afi].rmap[dir] =
9503 route_map_lookup_warn_noexist(vty, rmap_str);
9504 if (!bgp->vpn_policy[afi].rmap[dir])
9505 return CMD_SUCCESS;
9506
9507 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9508 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9509
69b07479
DS
9510 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9511
bb4f6190
DS
9512 return CMD_SUCCESS;
9513}
9514
ae6a6fb4
DS
9515DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9516 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9517 NO_STR
9518 "Import routes from another VRF\n"
9519 "Vrf routes being filtered\n"
ae6a6fb4
DS
9520 "Specify route map\n"
9521 "name of route-map\n")
9522{
9523 VTY_DECLVAR_CONTEXT(bgp, bgp);
9524 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9525 afi_t afi;
9526
9527 afi = vpn_policy_getafi(vty, bgp, true);
9528 if (afi == AFI_MAX)
9529 return CMD_WARNING_CONFIG_FAILED;
9530
9531 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9532
9533 if (bgp->vpn_policy[afi].rmap_name[dir])
9534 XFREE(MTYPE_ROUTE_MAP_NAME,
9535 bgp->vpn_policy[afi].rmap_name[dir]);
9536 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9537 bgp->vpn_policy[afi].rmap[dir] = NULL;
9538
9539 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9540 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9541 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9542
9543 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9544
9545 return CMD_SUCCESS;
9546}
bb4f6190 9547
37a87b8f
CS
9548DEFPY_YANG(bgp_imexport_vrf,
9549 bgp_imexport_vrf_cmd,
9550 "[no] import vrf VIEWVRFNAME$import_name",
9551 NO_STR
9552 "Import routes from another VRF\n"
9553 "VRF to import from\n"
9554 "The name of the VRF\n")
12a844a5 9555{
37a87b8f 9556 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
9557 safi_t safi;
9558 afi_t afi;
37a87b8f 9559 int32_t idx = 0;
12a844a5 9560
867f0cca 9561 if (import_name == NULL) {
9562 vty_out(vty, "%% Missing import name\n");
9563 return CMD_WARNING;
9564 }
9565
ae6a6fb4
DS
9566 if (strcmp(import_name, "route-map") == 0) {
9567 vty_out(vty, "%% Must include route-map name\n");
9568 return CMD_WARNING;
9569 }
9570
37a87b8f 9571 afi = bgp_node_afi(vty);
12a844a5
DS
9572 safi = bgp_node_safi(vty);
9573
37a87b8f
CS
9574 snprintf(
9575 base_xpath, sizeof(base_xpath),
9576 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9577 yang_afi_safi_value2identity(afi, safi),
9578 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 9579
37a87b8f
CS
9580 if (argv_find(argv, argc, "no", &idx))
9581 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9582 else
9583 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 9584
37a87b8f
CS
9585 return nb_cli_apply_changes(vty, base_xpath);
9586}
12a844a5 9587
37a87b8f
CS
9588void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9589 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9590{
9591 vty_out(vty, " import vrf %s\n",
9592 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
9593}
9594
b9c7bc5a 9595/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 9596DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
9597 bgp_imexport_vpn_cmd,
9598 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9599 NO_STR
9600 "Import routes to this address-family\n"
9601 "Export routes from this address-family\n"
9602 "to/from default instance VPN RIB\n")
ddb5b488 9603{
37a87b8f 9604 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 9605 safi_t safi;
37a87b8f
CS
9606 afi_t afi;
9607 int32_t idx = 0;
ddb5b488 9608
b9c7bc5a
PZ
9609 afi = bgp_node_afi(vty);
9610 safi = bgp_node_safi(vty);
ddb5b488 9611
b9c7bc5a 9612 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
9613 snprintf(
9614 base_xpath, sizeof(base_xpath),
9615 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9616 yang_afi_safi_value2identity(afi, safi),
9617 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 9618 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
9619 snprintf(
9620 base_xpath, sizeof(base_xpath),
9621 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9622 yang_afi_safi_value2identity(afi, safi),
9623 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
9624 } else {
9625 vty_out(vty, "%% unknown direction %s\n", direction_str);
9626 return CMD_WARNING_CONFIG_FAILED;
9627 }
9628
37a87b8f
CS
9629 if (argv_find(argv, argc, "no", &idx))
9630 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9631 else
9632 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 9633
37a87b8f
CS
9634 return nb_cli_apply_changes(vty, base_xpath);
9635}
ddb5b488 9636
37a87b8f
CS
9637void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9638 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9639{
9640 if (yang_dnode_get_bool(dnode, NULL))
9641 vty_out(vty, " import vpn\n");
9642}
9643
9644void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9645 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9646{
9647 if (yang_dnode_get_bool(dnode, NULL))
9648 vty_out(vty, " export vpn\n");
ddb5b488
PZ
9649}
9650
301ad80a
PG
9651DEFPY (af_routetarget_import,
9652 af_routetarget_import_cmd,
9a659715 9653 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9654 NO_STR
9655 "Specify route target list\n"
9656 "Specify route target list\n"
9a659715
PG
9657 "Specify route target list\n"
9658 "Specify route target list\n"
301ad80a
PG
9659 "Flow-spec redirect type route target\n"
9660 "Import routes to this address-family\n"
9a659715 9661 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9662{
9663 VTY_DECLVAR_CONTEXT(bgp, bgp);
9664 int ret;
9665 struct ecommunity *ecom = NULL;
301ad80a 9666 afi_t afi;
9a659715 9667 int idx = 0, idx_unused = 0;
c6423c31
PG
9668 bool yes = true;
9669 bool rt6 = false;
301ad80a
PG
9670
9671 if (argv_find(argv, argc, "no", &idx))
c6423c31 9672 yes = false;
301ad80a 9673
9a659715
PG
9674 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9675 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9676 rt6 = true;
301ad80a 9677
0ca70ba5 9678 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9679 if (afi == AFI_MAX)
9680 return CMD_WARNING_CONFIG_FAILED;
9681
9a659715
PG
9682 if (rt6 && afi != AFI_IP6)
9683 return CMD_WARNING_CONFIG_FAILED;
9684
301ad80a
PG
9685 if (yes) {
9686 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9687 vty_out(vty, "%% Missing RTLIST\n");
9688 return CMD_WARNING_CONFIG_FAILED;
9689 }
9a659715 9690 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9691 if (ret != CMD_SUCCESS)
9692 return ret;
9693 }
69b07479
DS
9694
9695 if (yes) {
9696 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9697 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9698 .import_redirect_rtlist);
69b07479
DS
9699 bgp->vpn_policy[afi].import_redirect_rtlist =
9700 ecommunity_dup(ecom);
9701 } else {
9702 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9703 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9704 .import_redirect_rtlist);
69b07479 9705 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9706 }
69b07479 9707
301ad80a
PG
9708 if (ecom)
9709 ecommunity_free(&ecom);
9710
9711 return CMD_SUCCESS;
9712}
9713
37a87b8f
CS
9714void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9715 struct lyd_node *dnode,
9716 bool show_defaults)
9717{
9718 const char *af_name;
9719 afi_t afi;
9720 safi_t safi;
9721
9722 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9723 yang_afi_safi_identity2value(af_name, &afi, &safi);
9724
9725 vty_out(vty, " !\n address-family ");
9726 if (afi == AFI_IP) {
9727 if (safi == SAFI_UNICAST)
9728 vty_out(vty, "ipv4 unicast");
9729 else if (safi == SAFI_LABELED_UNICAST)
9730 vty_out(vty, "ipv4 labeled-unicast");
9731 else if (safi == SAFI_MULTICAST)
9732 vty_out(vty, "ipv4 multicast");
9733 else if (safi == SAFI_MPLS_VPN)
9734 vty_out(vty, "ipv4 vpn");
9735 else if (safi == SAFI_ENCAP)
9736 vty_out(vty, "ipv4 encap");
9737 else if (safi == SAFI_FLOWSPEC)
9738 vty_out(vty, "ipv4 flowspec");
9739 } else if (afi == AFI_IP6) {
9740 if (safi == SAFI_UNICAST)
9741 vty_out(vty, "ipv6 unicast");
9742 else if (safi == SAFI_LABELED_UNICAST)
9743 vty_out(vty, "ipv6 labeled-unicast");
9744 else if (safi == SAFI_MULTICAST)
9745 vty_out(vty, "ipv6 multicast");
9746 else if (safi == SAFI_MPLS_VPN)
9747 vty_out(vty, "ipv6 vpn");
9748 else if (safi == SAFI_ENCAP)
9749 vty_out(vty, "ipv6 encap");
9750 else if (safi == SAFI_FLOWSPEC)
9751 vty_out(vty, "ipv6 flowspec");
9752 } else if (afi == AFI_L2VPN) {
9753 if (safi == SAFI_EVPN)
9754 vty_out(vty, "l2vpn evpn");
9755 }
9756 vty_out(vty, "\n");
9757}
9758
505e5056 9759DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9760 address_family_ipv4_safi_cmd,
9761 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9762 "Enter Address Family command mode\n"
9763 "Address Family\n"
9764 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9765{
f51bae9c 9766
37a87b8f
CS
9767 safi_t safi = SAFI_UNICAST;
9768 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9769 const char *vrf_name = NULL;
9770
d62a17ae 9771 if (argc == 3) {
37a87b8f
CS
9772 safi = bgp_vty_safi_from_str(argv[2]->text);
9773
9774 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9775 VTY_CURR_XPATH);
9776 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9777 "control-plane-protocol");
9778 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9779
9780 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9781 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9782 && safi != SAFI_EVPN) {
31947174
MK
9783 vty_out(vty,
9784 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9785 return CMD_WARNING_CONFIG_FAILED;
9786 }
37a87b8f
CS
9787 }
9788 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 9789
d62a17ae 9790 return CMD_SUCCESS;
718e3744 9791}
9792
505e5056 9793DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9794 address_family_ipv6_safi_cmd,
9795 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9796 "Enter Address Family command mode\n"
9797 "Address Family\n"
9798 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9799{
37a87b8f
CS
9800 safi_t safi = SAFI_UNICAST;
9801 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9802 const char *vrf_name = NULL;
9803
d62a17ae 9804 if (argc == 3) {
37a87b8f
CS
9805 safi = bgp_vty_safi_from_str(argv[2]->text);
9806 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9807 VTY_CURR_XPATH);
9808 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9809 "control-plane-protocol");
9810 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9811
9812 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9813 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9814 && safi != SAFI_EVPN) {
31947174
MK
9815 vty_out(vty,
9816 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9817 return CMD_WARNING_CONFIG_FAILED;
9818 }
37a87b8f
CS
9819 }
9820 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 9821
d62a17ae 9822 return CMD_SUCCESS;
25ffbdc1 9823}
718e3744 9824
d6902373 9825#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9826DEFUN_NOSH (address_family_vpnv4,
718e3744 9827 address_family_vpnv4_cmd,
8334fd5a 9828 "address-family vpnv4 [unicast]",
718e3744 9829 "Enter Address Family command mode\n"
8c3deaae 9830 "Address Family\n"
3a2d747c 9831 "Address Family modifier\n")
718e3744 9832{
d62a17ae 9833 vty->node = BGP_VPNV4_NODE;
9834 return CMD_SUCCESS;
718e3744 9835}
9836
505e5056 9837DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9838 address_family_vpnv6_cmd,
8334fd5a 9839 "address-family vpnv6 [unicast]",
8ecd3266 9840 "Enter Address Family command mode\n"
8c3deaae 9841 "Address Family\n"
3a2d747c 9842 "Address Family modifier\n")
8ecd3266 9843{
d62a17ae 9844 vty->node = BGP_VPNV6_NODE;
9845 return CMD_SUCCESS;
8ecd3266 9846}
64e4a6c5 9847#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9848
505e5056 9849DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9850 address_family_evpn_cmd,
7111c1a0 9851 "address-family l2vpn evpn",
4e0b7b6d 9852 "Enter Address Family command mode\n"
7111c1a0
QY
9853 "Address Family\n"
9854 "Address Family modifier\n")
4e0b7b6d 9855{
2131d5cf 9856 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9857 vty->node = BGP_EVPN_NODE;
9858 return CMD_SUCCESS;
4e0b7b6d
PG
9859}
9860
505e5056 9861DEFUN_NOSH (exit_address_family,
718e3744 9862 exit_address_family_cmd,
9863 "exit-address-family",
9864 "Exit from Address Family configuration mode\n")
9865{
d62a17ae 9866 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9867 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9868 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9869 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9870 || vty->node == BGP_EVPN_NODE
9871 || vty->node == BGP_FLOWSPECV4_NODE
9872 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9873 vty->node = BGP_NODE;
9874 return CMD_SUCCESS;
718e3744 9875}
6b0655a2 9876
37a87b8f
CS
9877void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9878 struct lyd_node *dnode
9879 __attribute__((__unused__)))
9880{
9881 vty_out(vty, " exit-address-family\n");
9882}
9883
8ad7271d 9884/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9885static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9886 const char *ip_str, afi_t afi, safi_t safi,
9887 struct prefix_rd *prd)
9888{
9889 int ret;
9890 struct prefix match;
9bcb3eef
DS
9891 struct bgp_dest *dest;
9892 struct bgp_dest *rm;
d62a17ae 9893 struct bgp *bgp;
9894 struct bgp_table *table;
9895 struct bgp_table *rib;
9896
9897 /* BGP structure lookup. */
9898 if (view_name) {
9899 bgp = bgp_lookup_by_name(view_name);
9900 if (bgp == NULL) {
9901 vty_out(vty, "%% Can't find BGP instance %s\n",
9902 view_name);
9903 return CMD_WARNING;
9904 }
9905 } else {
9906 bgp = bgp_get_default();
9907 if (bgp == NULL) {
9908 vty_out(vty, "%% No BGP process is configured\n");
9909 return CMD_WARNING;
9910 }
9911 }
9912
9913 /* Check IP address argument. */
9914 ret = str2prefix(ip_str, &match);
9915 if (!ret) {
9916 vty_out(vty, "%% address is malformed\n");
9917 return CMD_WARNING;
9918 }
9919
9920 match.family = afi2family(afi);
9921 rib = bgp->rib[afi][safi];
9922
9923 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9924 for (dest = bgp_table_top(rib); dest;
9925 dest = bgp_route_next(dest)) {
9926 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9927
9bcb3eef 9928 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9929 continue;
9930
9bcb3eef 9931 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9932 if (table == NULL)
9933 continue;
9934
9935 if ((rm = bgp_node_match(table, &match)) != NULL) {
9936 const struct prefix *rm_p =
9bcb3eef 9937 bgp_dest_get_prefix(rm);
b54892e0
DS
9938
9939 if (rm_p->prefixlen == match.prefixlen) {
9940 SET_FLAG(rm->flags,
9941 BGP_NODE_USER_CLEAR);
9942 bgp_process(bgp, rm, afi, safi);
d62a17ae 9943 }
9bcb3eef 9944 bgp_dest_unlock_node(rm);
d62a17ae 9945 }
9946 }
9947 } else {
9bcb3eef
DS
9948 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9949 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9950
9bcb3eef
DS
9951 if (dest_p->prefixlen == match.prefixlen) {
9952 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9953 bgp_process(bgp, dest, afi, safi);
d62a17ae 9954 }
9bcb3eef 9955 bgp_dest_unlock_node(dest);
d62a17ae 9956 }
9957 }
9958
9959 return CMD_SUCCESS;
8ad7271d
DS
9960}
9961
b09b5ae0 9962/* one clear bgp command to rule them all */
718e3744 9963DEFUN (clear_ip_bgp_all,
9964 clear_ip_bgp_all_cmd,
453c92f6 9965 "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 9966 CLEAR_STR
9967 IP_STR
9968 BGP_STR
838758ac 9969 BGP_INSTANCE_HELP_STR
510afcd6 9970 BGP_AFI_HELP_STR
fd5e7b70 9971 "Address Family\n"
510afcd6 9972 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9973 "Address Family modifier\n"
b09b5ae0 9974 "Clear all peers\n"
453c92f6 9975 "BGP IPv4 neighbor to clear\n"
a80beece 9976 "BGP IPv6 neighbor to clear\n"
838758ac 9977 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9978 "Clear peers with the AS number\n"
9979 "Clear all external peers\n"
718e3744 9980 "Clear all members of peer-group\n"
b09b5ae0 9981 "BGP peer-group name\n"
b09b5ae0
DW
9982 BGP_SOFT_STR
9983 BGP_SOFT_IN_STR
b09b5ae0
DW
9984 BGP_SOFT_OUT_STR
9985 BGP_SOFT_IN_STR
9986 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9987 BGP_SOFT_OUT_STR)
718e3744 9988{
d62a17ae 9989 char *vrf = NULL;
9990
dc912615
DS
9991 afi_t afi = AFI_UNSPEC;
9992 safi_t safi = SAFI_UNSPEC;
d62a17ae 9993 enum clear_sort clr_sort = clear_peer;
9994 enum bgp_clear_type clr_type;
9995 char *clr_arg = NULL;
9996
9997 int idx = 0;
ff8a8a7a
CS
9998 char errmsg[BUFSIZ] = {'\0'};
9999 int ret;
d62a17ae 10000
10001 /* clear [ip] bgp */
10002 if (argv_find(argv, argc, "ip", &idx))
10003 afi = AFI_IP;
10004
9a8bdf1c
PG
10005 /* [<vrf> VIEWVRFNAME] */
10006 if (argv_find(argv, argc, "vrf", &idx)) {
10007 vrf = argv[idx + 1]->arg;
10008 idx += 2;
10009 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10010 vrf = NULL;
10011 } else if (argv_find(argv, argc, "view", &idx)) {
10012 /* [<view> VIEWVRFNAME] */
d62a17ae 10013 vrf = argv[idx + 1]->arg;
10014 idx += 2;
10015 }
d62a17ae 10016 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10017 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10018 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10019
d7b9898c 10020 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 10021 if (argv_find(argv, argc, "*", &idx)) {
10022 clr_sort = clear_all;
10023 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10024 clr_sort = clear_peer;
10025 clr_arg = argv[idx]->arg;
10026 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10027 clr_sort = clear_peer;
10028 clr_arg = argv[idx]->arg;
10029 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10030 clr_sort = clear_group;
10031 idx++;
10032 clr_arg = argv[idx]->arg;
d7b9898c 10033 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10034 clr_sort = clear_peer;
10035 clr_arg = argv[idx]->arg;
8fa7d444
DS
10036 } else if (argv_find(argv, argc, "WORD", &idx)) {
10037 clr_sort = clear_peer;
10038 clr_arg = argv[idx]->arg;
d62a17ae 10039 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10040 clr_sort = clear_as;
10041 clr_arg = argv[idx]->arg;
10042 } else if (argv_find(argv, argc, "external", &idx)) {
10043 clr_sort = clear_external;
10044 }
10045
10046 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
10047 if (argv_find(argv, argc, "soft", &idx)) {
10048 if (argv_find(argv, argc, "in", &idx)
10049 || argv_find(argv, argc, "out", &idx))
10050 clr_type = strmatch(argv[idx]->text, "in")
10051 ? BGP_CLEAR_SOFT_IN
10052 : BGP_CLEAR_SOFT_OUT;
10053 else
10054 clr_type = BGP_CLEAR_SOFT_BOTH;
10055 } else if (argv_find(argv, argc, "in", &idx)) {
10056 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10057 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10058 : BGP_CLEAR_SOFT_IN;
10059 } else if (argv_find(argv, argc, "out", &idx)) {
10060 clr_type = BGP_CLEAR_SOFT_OUT;
10061 } else
10062 clr_type = BGP_CLEAR_SOFT_NONE;
10063
ff8a8a7a
CS
10064 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
10065 sizeof(errmsg));
10066 if (ret != NB_OK)
10067 vty_out(vty, "Error description: %s\n", errmsg);
10068
10069 return ret;
838758ac 10070}
01080f7c 10071
8ad7271d
DS
10072DEFUN (clear_ip_bgp_prefix,
10073 clear_ip_bgp_prefix_cmd,
18c57037 10074 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10075 CLEAR_STR
10076 IP_STR
10077 BGP_STR
838758ac 10078 BGP_INSTANCE_HELP_STR
8ad7271d 10079 "Clear bestpath and re-advertise\n"
0c7b1b01 10080 "IPv4 prefix\n")
8ad7271d 10081{
d62a17ae 10082 char *vrf = NULL;
10083 char *prefix = NULL;
8ad7271d 10084
d62a17ae 10085 int idx = 0;
01080f7c 10086
d62a17ae 10087 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10088 if (argv_find(argv, argc, "vrf", &idx)) {
10089 vrf = argv[idx + 1]->arg;
10090 idx += 2;
10091 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10092 vrf = NULL;
10093 } else if (argv_find(argv, argc, "view", &idx)) {
10094 /* [<view> VIEWVRFNAME] */
10095 vrf = argv[idx + 1]->arg;
10096 idx += 2;
10097 }
0c7b1b01 10098
d62a17ae 10099 prefix = argv[argc - 1]->arg;
8ad7271d 10100
d62a17ae 10101 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10102}
8ad7271d 10103
b09b5ae0
DW
10104DEFUN (clear_bgp_ipv6_safi_prefix,
10105 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10106 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10107 CLEAR_STR
3a2d747c 10108 IP_STR
718e3744 10109 BGP_STR
8c3deaae 10110 "Address Family\n"
46f296b4 10111 BGP_SAFI_HELP_STR
b09b5ae0 10112 "Clear bestpath and re-advertise\n"
0c7b1b01 10113 "IPv6 prefix\n")
718e3744 10114{
9b475e76
PG
10115 int idx_safi = 0;
10116 int idx_ipv6_prefix = 0;
10117 safi_t safi = SAFI_UNICAST;
10118 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10119 argv[idx_ipv6_prefix]->arg : NULL;
10120
10121 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10122 return bgp_clear_prefix(
9b475e76
PG
10123 vty, NULL, prefix, AFI_IP6,
10124 safi, NULL);
838758ac 10125}
01080f7c 10126
b09b5ae0
DW
10127DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10128 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10129 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10130 CLEAR_STR
3a2d747c 10131 IP_STR
718e3744 10132 BGP_STR
838758ac 10133 BGP_INSTANCE_HELP_STR
8c3deaae 10134 "Address Family\n"
46f296b4 10135 BGP_SAFI_HELP_STR
b09b5ae0 10136 "Clear bestpath and re-advertise\n"
0c7b1b01 10137 "IPv6 prefix\n")
718e3744 10138{
9b475e76 10139 int idx_safi = 0;
9a8bdf1c 10140 int idx_vrfview = 0;
9b475e76
PG
10141 int idx_ipv6_prefix = 0;
10142 safi_t safi = SAFI_UNICAST;
10143 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10144 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10145 char *vrfview = NULL;
9b475e76 10146
9a8bdf1c
PG
10147 /* [<view|vrf> VIEWVRFNAME] */
10148 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10149 vrfview = argv[idx_vrfview + 1]->arg;
10150 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10151 vrfview = NULL;
10152 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10153 /* [<view> VIEWVRFNAME] */
10154 vrfview = argv[idx_vrfview + 1]->arg;
10155 }
9b475e76
PG
10156 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10157
d62a17ae 10158 return bgp_clear_prefix(
9b475e76
PG
10159 vty, vrfview, prefix,
10160 AFI_IP6, safi, NULL);
718e3744 10161}
10162
b09b5ae0
DW
10163DEFUN (show_bgp_views,
10164 show_bgp_views_cmd,
d6e3c605 10165 "show [ip] bgp views",
b09b5ae0 10166 SHOW_STR
d6e3c605 10167 IP_STR
01080f7c 10168 BGP_STR
b09b5ae0 10169 "Show the defined BGP views\n")
01080f7c 10170{
d62a17ae 10171 struct list *inst = bm->bgp;
10172 struct listnode *node;
10173 struct bgp *bgp;
01080f7c 10174
d62a17ae 10175 vty_out(vty, "Defined BGP views:\n");
10176 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10177 /* Skip VRFs. */
10178 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10179 continue;
10180 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10181 bgp->as);
10182 }
e52702f2 10183
d62a17ae 10184 return CMD_SUCCESS;
e0081f70
ML
10185}
10186
8386ac43 10187DEFUN (show_bgp_vrfs,
10188 show_bgp_vrfs_cmd,
d6e3c605 10189 "show [ip] bgp vrfs [json]",
8386ac43 10190 SHOW_STR
d6e3c605 10191 IP_STR
8386ac43 10192 BGP_STR
10193 "Show BGP VRFs\n"
9973d184 10194 JSON_STR)
8386ac43 10195{
fe1dc5a3 10196 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10197 struct list *inst = bm->bgp;
10198 struct listnode *node;
10199 struct bgp *bgp;
9f049418 10200 bool uj = use_json(argc, argv);
d62a17ae 10201 json_object *json = NULL;
10202 json_object *json_vrfs = NULL;
10203 int count = 0;
d62a17ae 10204
d62a17ae 10205 if (uj) {
10206 json = json_object_new_object();
10207 json_vrfs = json_object_new_object();
10208 }
10209
10210 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10211 const char *name, *type;
10212 struct peer *peer;
7fe96307 10213 struct listnode *node2, *nnode2;
d62a17ae 10214 int peers_cfg, peers_estb;
10215 json_object *json_vrf = NULL;
d62a17ae 10216
10217 /* Skip Views. */
10218 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10219 continue;
10220
10221 count++;
efb4077a 10222 if (!uj && count == 1) {
fe1dc5a3 10223 vty_out(vty,
efb4077a 10224 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10225 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10226 "#PeersEstb", "Name");
10227 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10228 "L3-VNI", "RouterMAC", "Interface");
10229 }
d62a17ae 10230
10231 peers_cfg = peers_estb = 0;
10232 if (uj)
10233 json_vrf = json_object_new_object();
10234
10235
7fe96307 10236 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10237 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10238 continue;
10239 peers_cfg++;
10240 if (peer->status == Established)
10241 peers_estb++;
10242 }
10243
10244 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10245 name = VRF_DEFAULT_NAME;
d62a17ae 10246 type = "DFLT";
10247 } else {
10248 name = bgp->name;
10249 type = "VRF";
10250 }
10251
a8bf7d9c 10252
d62a17ae 10253 if (uj) {
a4d82a8a
PZ
10254 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10255 ? -1
10256 : (int64_t)bgp->vrf_id;
23d0a753
DA
10257 char buf[BUFSIZ] = {0};
10258
d62a17ae 10259 json_object_string_add(json_vrf, "type", type);
10260 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10261 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
10262 inet_ntop(AF_INET,
10263 &bgp->router_id, buf,
10264 sizeof(buf)));
d62a17ae 10265 json_object_int_add(json_vrf, "numConfiguredPeers",
10266 peers_cfg);
10267 json_object_int_add(json_vrf, "numEstablishedPeers",
10268 peers_estb);
10269
fe1dc5a3 10270 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10271 json_object_string_add(
10272 json_vrf, "rmac",
10273 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10274 json_object_string_add(json_vrf, "interface",
10275 ifindex2ifname(bgp->l3vni_svi_ifindex,
10276 bgp->vrf_id));
d62a17ae 10277 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10278 } else {
23d0a753 10279 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10280 type,
10281 bgp->vrf_id == VRF_UNKNOWN ? -1
10282 : (int)bgp->vrf_id,
23d0a753 10283 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10284 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10285 bgp->l3vni,
10286 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10287 ifindex2ifname(bgp->l3vni_svi_ifindex,
10288 bgp->vrf_id));
10289 }
d62a17ae 10290 }
10291
10292 if (uj) {
10293 json_object_object_add(json, "vrfs", json_vrfs);
10294
10295 json_object_int_add(json, "totalVrfs", count);
10296
996c9314
LB
10297 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10298 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10299 json_object_free(json);
10300 } else {
10301 if (count)
10302 vty_out(vty,
10303 "\nTotal number of VRFs (including default): %d\n",
10304 count);
10305 }
10306
10307 return CMD_SUCCESS;
8386ac43 10308}
10309
48ecf8f5
DS
10310DEFUN (show_bgp_mac_hash,
10311 show_bgp_mac_hash_cmd,
10312 "show bgp mac hash",
10313 SHOW_STR
10314 BGP_STR
10315 "Mac Address\n"
10316 "Mac Address database\n")
10317{
10318 bgp_mac_dump_table(vty);
10319
10320 return CMD_SUCCESS;
10321}
acf71666 10322
e3b78da8 10323static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10324{
0291c246 10325 struct vty *vty = (struct vty *)args;
e3b78da8 10326 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10327
23d0a753 10328 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10329}
10330
10331static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10332{
10333 vty_out(vty, "self nexthop database:\n");
af97a18b 10334 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10335
10336 vty_out(vty, "Tunnel-ip database:\n");
10337 hash_iterate(bgp->tip_hash,
e3b78da8 10338 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10339 vty);
10340}
10341
15c81ca4
DS
10342DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10343 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10344 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10345 "martian next-hops\n"
10346 "martian next-hop database\n")
acf71666 10347{
0291c246 10348 struct bgp *bgp = NULL;
15c81ca4 10349 int idx = 0;
9a8bdf1c
PG
10350 char *name = NULL;
10351
10352 /* [<vrf> VIEWVRFNAME] */
10353 if (argv_find(argv, argc, "vrf", &idx)) {
10354 name = argv[idx + 1]->arg;
10355 if (name && strmatch(name, VRF_DEFAULT_NAME))
10356 name = NULL;
10357 } else if (argv_find(argv, argc, "view", &idx))
10358 /* [<view> VIEWVRFNAME] */
10359 name = argv[idx + 1]->arg;
10360 if (name)
10361 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10362 else
10363 bgp = bgp_get_default();
acf71666 10364
acf71666
MK
10365 if (!bgp) {
10366 vty_out(vty, "%% No BGP process is configured\n");
10367 return CMD_WARNING;
10368 }
10369 bgp_show_martian_nexthops(vty, bgp);
10370
10371 return CMD_SUCCESS;
10372}
10373
f412b39a 10374DEFUN (show_bgp_memory,
4bf6a362 10375 show_bgp_memory_cmd,
7fa12b13 10376 "show [ip] bgp memory",
4bf6a362 10377 SHOW_STR
3a2d747c 10378 IP_STR
4bf6a362
PJ
10379 BGP_STR
10380 "Global BGP memory statistics\n")
10381{
d62a17ae 10382 char memstrbuf[MTYPE_MEMSTR_LEN];
10383 unsigned long count;
10384
10385 /* RIB related usage stats */
10386 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10387 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10388 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10389 count * sizeof(struct bgp_dest)));
d62a17ae 10390
10391 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10392 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10393 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10394 count * sizeof(struct bgp_path_info)));
d62a17ae 10395 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10396 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10397 count,
4b7e6066
DS
10398 mtype_memstr(
10399 memstrbuf, sizeof(memstrbuf),
10400 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10401
10402 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10403 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10404 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10405 count * sizeof(struct bgp_static)));
10406
10407 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10408 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10409 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10410 count * sizeof(struct bpacket)));
10411
10412 /* Adj-In/Out */
10413 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10414 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10415 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10416 count * sizeof(struct bgp_adj_in)));
10417 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10418 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10419 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10420 count * sizeof(struct bgp_adj_out)));
10421
10422 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10423 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10424 count,
10425 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10426 count * sizeof(struct bgp_nexthop_cache)));
10427
10428 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10429 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10430 count,
10431 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10432 count * sizeof(struct bgp_damp_info)));
10433
10434 /* Attributes */
10435 count = attr_count();
10436 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10437 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10438 count * sizeof(struct attr)));
10439
10440 if ((count = attr_unknown_count()))
10441 vty_out(vty, "%ld unknown attributes\n", count);
10442
10443 /* AS_PATH attributes */
10444 count = aspath_count();
10445 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10446 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10447 count * sizeof(struct aspath)));
10448
10449 count = mtype_stats_alloc(MTYPE_AS_SEG);
10450 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10451 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10452 count * sizeof(struct assegment)));
10453
10454 /* Other attributes */
10455 if ((count = community_count()))
10456 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10457 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10458 count * sizeof(struct community)));
d62a17ae 10459 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10460 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10461 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10462 count * sizeof(struct ecommunity)));
d62a17ae 10463 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10464 vty_out(vty,
10465 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10466 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10467 count * sizeof(struct lcommunity)));
d62a17ae 10468
10469 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10470 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10471 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10472 count * sizeof(struct cluster_list)));
10473
10474 /* Peer related usage */
10475 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10476 vty_out(vty, "%ld peers, using %s of memory\n", count,
10477 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10478 count * sizeof(struct peer)));
10479
10480 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10481 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10482 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10483 count * sizeof(struct peer_group)));
10484
10485 /* Other */
d62a17ae 10486 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10487 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10488 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10489 count * sizeof(regex_t)));
d62a17ae 10490 return CMD_SUCCESS;
4bf6a362 10491}
fee0f4c6 10492
57a9c8a8
DS
10493static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10494{
10495 json_object *bestpath = json_object_new_object();
10496
892fedb6 10497 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10498 json_object_string_add(bestpath, "asPath", "ignore");
10499
892fedb6 10500 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10501 json_object_string_add(bestpath, "asPath", "confed");
10502
892fedb6
DA
10503 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10504 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10505 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10506 "as-set");
10507 else
a4d82a8a 10508 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10509 "true");
10510 } else
a4d82a8a 10511 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10512
ee88563a
JM
10513 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10514 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10515
892fedb6 10516 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10517 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10518 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10519 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10520 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10521 json_object_string_add(bestpath, "med", "confed");
892fedb6 10522 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10523 json_object_string_add(bestpath, "med",
10524 "missing-as-worst");
10525 else
10526 json_object_string_add(bestpath, "med", "true");
10527 }
10528
10529 json_object_object_add(json, "bestPath", bestpath);
10530}
10531
3577f1c5
DD
10532/* Print the error code/subcode for why the peer is down */
10533static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10534 json_object *json_peer, bool use_json)
10535{
10536 const char *code_str;
10537 const char *subcode_str;
10538
10539 if (use_json) {
10540 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10541 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10542 char errorcodesubcode_hexstr[5];
10543 char errorcodesubcode_str[256];
10544
10545 code_str = bgp_notify_code_str(peer->notify.code);
10546 subcode_str = bgp_notify_subcode_str(
10547 peer->notify.code,
10548 peer->notify.subcode);
10549
772270f3
QY
10550 snprintf(errorcodesubcode_hexstr,
10551 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10552 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10553 json_object_string_add(json_peer,
10554 "lastErrorCodeSubcode",
10555 errorcodesubcode_hexstr);
10556 snprintf(errorcodesubcode_str, 255, "%s%s",
10557 code_str, subcode_str);
10558 json_object_string_add(json_peer,
10559 "lastNotificationReason",
10560 errorcodesubcode_str);
10561 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10562 && peer->notify.code == BGP_NOTIFY_CEASE
10563 && (peer->notify.subcode
10564 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10565 || peer->notify.subcode
10566 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10567 && peer->notify.length) {
10568 char msgbuf[1024];
10569 const char *msg_str;
10570
10571 msg_str = bgp_notify_admin_message(
10572 msgbuf, sizeof(msgbuf),
10573 (uint8_t *)peer->notify.data,
10574 peer->notify.length);
10575 if (msg_str)
10576 json_object_string_add(
10577 json_peer,
10578 "lastShutdownDescription",
10579 msg_str);
10580 }
10581
c258527b 10582 }
3577f1c5
DD
10583 json_object_string_add(json_peer, "lastResetDueTo",
10584 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10585 json_object_int_add(json_peer, "lastResetCode",
10586 peer->last_reset);
3577f1c5
DD
10587 } else {
10588 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10589 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10590 code_str = bgp_notify_code_str(peer->notify.code);
10591 subcode_str =
10592 bgp_notify_subcode_str(peer->notify.code,
10593 peer->notify.subcode);
10594 vty_out(vty, " Notification %s (%s%s)\n",
10595 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10596 ? "sent"
10597 : "received",
10598 code_str, subcode_str);
10599 } else {
e91c24c8 10600 vty_out(vty, " %s\n",
3577f1c5
DD
10601 peer_down_str[(int)peer->last_reset]);
10602 }
10603 }
10604}
10605
10606static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10607 safi_t safi)
10608{
10609 return ((peer->status != Established) ||
10610 !peer->afc_recv[afi][safi]);
10611}
10612
10613static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10614 struct peer *peer, json_object *json_peer,
10615 int max_neighbor_width, bool use_json)
10616{
10617 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10618 int len;
10619
10620 if (use_json) {
10621 if (peer_dynamic_neighbor(peer))
10622 json_object_boolean_true_add(json_peer,
10623 "dynamicPeer");
10624 if (peer->hostname)
10625 json_object_string_add(json_peer, "hostname",
10626 peer->hostname);
10627
10628 if (peer->domainname)
10629 json_object_string_add(json_peer, "domainname",
10630 peer->domainname);
10631 json_object_int_add(json_peer, "connectionsEstablished",
10632 peer->established);
10633 json_object_int_add(json_peer, "connectionsDropped",
10634 peer->dropped);
10635 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10636 use_json, json_peer);
10637 if (peer->status == Established)
10638 json_object_string_add(json_peer, "lastResetDueTo",
10639 "AFI/SAFI Not Negotiated");
10640 else
10641 bgp_show_peer_reset(NULL, peer, json_peer, true);
10642 } else {
10643 dn_flag[1] = '\0';
10644 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10645 if (peer->hostname
892fedb6 10646 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10647 len = vty_out(vty, "%s%s(%s)", dn_flag,
10648 peer->hostname, peer->host);
10649 else
10650 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10651
10652 /* pad the neighbor column with spaces */
10653 if (len < max_neighbor_width)
10654 vty_out(vty, "%*s", max_neighbor_width - len,
10655 " ");
e91c24c8 10656 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10657 peer->dropped,
10658 peer_uptime(peer->uptime, timebuf,
10659 BGP_UPTIME_LEN, 0, NULL));
10660 if (peer->status == Established)
10661 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10662 else
10663 bgp_show_peer_reset(vty, peer, NULL,
10664 false);
10665 }
10666}
c258527b 10667
cb75bb31
DA
10668/* If the peer's description includes whitespaces
10669 * then return the first occurrence. Also strip description
10670 * to the given size if needed.
10671 */
10672static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10673{
10674 static char stripped[BUFSIZ];
10675 char *pnt;
10676 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10677
10678 pnt = strchr(desc, ' ');
10679 if (pnt)
10680 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10681 : size;
10682
10683 strlcpy(stripped, desc, len + 1);
10684
10685 return stripped;
10686}
3577f1c5 10687
718e3744 10688/* Show BGP peer's summary information. */
d62a17ae 10689static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
85eeb029 10690 uint8_t show_flags)
d62a17ae 10691{
10692 struct peer *peer;
10693 struct listnode *node, *nnode;
10694 unsigned int count = 0, dn_count = 0;
10695 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10696 char neighbor_buf[VTY_BUFSIZ];
10697 int neighbor_col_default_width = 16;
3577f1c5 10698 int len, failed_count = 0;
d62a17ae 10699 int max_neighbor_width = 0;
10700 int pfx_rcd_safi;
3c13337d 10701 json_object *json = NULL;
d62a17ae 10702 json_object *json_peer = NULL;
10703 json_object *json_peers = NULL;
50e05855 10704 struct peer_af *paf;
d3ada366 10705 struct bgp_filter *filter;
85eeb029
DA
10706 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10707 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10708 bool show_established =
10709 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10710 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
d62a17ae 10711
10712 /* labeled-unicast routes are installed in the unicast table so in order
10713 * to
10714 * display the correct PfxRcd value we must look at SAFI_UNICAST
10715 */
3577f1c5 10716
d62a17ae 10717 if (safi == SAFI_LABELED_UNICAST)
10718 pfx_rcd_safi = SAFI_UNICAST;
10719 else
10720 pfx_rcd_safi = safi;
10721
10722 if (use_json) {
3c13337d 10723 json = json_object_new_object();
d62a17ae 10724 json_peers = json_object_new_object();
3577f1c5
DD
10725 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10726 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10727 continue;
10728
10729 if (peer->afc[afi][safi]) {
10730 /* See if we have at least a single failed peer */
10731 if (bgp_has_peer_failed(peer, afi, safi))
10732 failed_count++;
10733 count++;
10734 }
10735 if (peer_dynamic_neighbor(peer))
10736 dn_count++;
10737 }
c258527b 10738
d62a17ae 10739 } else {
10740 /* Loop over all neighbors that will be displayed to determine
10741 * how many
10742 * characters are needed for the Neighbor column
10743 */
10744 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10745 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10746 continue;
10747
10748 if (peer->afc[afi][safi]) {
10749 memset(dn_flag, '\0', sizeof(dn_flag));
10750 if (peer_dynamic_neighbor(peer))
10751 dn_flag[0] = '*';
10752
10753 if (peer->hostname
892fedb6
DA
10754 && CHECK_FLAG(bgp->flags,
10755 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10756 snprintf(neighbor_buf,
10757 sizeof(neighbor_buf),
10758 "%s%s(%s) ", dn_flag,
10759 peer->hostname, peer->host);
d62a17ae 10760 else
772270f3
QY
10761 snprintf(neighbor_buf,
10762 sizeof(neighbor_buf), "%s%s ",
10763 dn_flag, peer->host);
d62a17ae 10764
10765 len = strlen(neighbor_buf);
10766
10767 if (len > max_neighbor_width)
10768 max_neighbor_width = len;
c258527b 10769
3577f1c5
DD
10770 /* See if we have at least a single failed peer */
10771 if (bgp_has_peer_failed(peer, afi, safi))
10772 failed_count++;
10773 count++;
d62a17ae 10774 }
10775 }
f933309e 10776
d62a17ae 10777 /* Originally we displayed the Neighbor column as 16
10778 * characters wide so make that the default
10779 */
10780 if (max_neighbor_width < neighbor_col_default_width)
10781 max_neighbor_width = neighbor_col_default_width;
10782 }
f933309e 10783
3577f1c5
DD
10784 if (show_failed && !failed_count) {
10785 if (use_json) {
10786 json_object_int_add(json, "failedPeersCount", 0);
10787 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10788 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
10789
10790 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10791 json, JSON_C_TO_STRING_PRETTY));
10792 json_object_free(json);
10793 } else {
10794 vty_out(vty, "%% No failed BGP neighbors found\n");
10795 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10796 }
10797 return CMD_SUCCESS;
10798 }
c258527b 10799
3577f1c5 10800 count = 0; /* Reset the value as its used again */
d62a17ae 10801 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10802 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10803 continue;
10804
ea47320b
DL
10805 if (!peer->afc[afi][safi])
10806 continue;
d62a17ae 10807
ea47320b
DL
10808 if (!count) {
10809 unsigned long ents;
10810 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10811 int64_t vrf_id_ui;
d62a17ae 10812
a4d82a8a
PZ
10813 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10814 ? -1
10815 : (int64_t)bgp->vrf_id;
ea47320b
DL
10816
10817 /* Usage summary and header */
10818 if (use_json) {
23d0a753
DA
10819 char buf[BUFSIZ] = {0};
10820
ea47320b
DL
10821 json_object_string_add(
10822 json, "routerId",
23d0a753
DA
10823 inet_ntop(AF_INET, &bgp->router_id, buf,
10824 sizeof(buf)));
60466a63
QY
10825 json_object_int_add(json, "as", bgp->as);
10826 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10827 json_object_string_add(
10828 json, "vrfName",
10829 (bgp->inst_type
10830 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10831 ? VRF_DEFAULT_NAME
ea47320b
DL
10832 : bgp->name);
10833 } else {
10834 vty_out(vty,
23d0a753
DA
10835 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10836 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10837 bgp->vrf_id == VRF_UNKNOWN
10838 ? -1
10839 : (int)bgp->vrf_id);
ea47320b
DL
10840 vty_out(vty, "\n");
10841 }
d62a17ae 10842
ea47320b 10843 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10844 if (use_json) {
ea47320b 10845 json_object_int_add(
60466a63 10846 json, "updateDelayLimit",
ea47320b 10847 bgp->v_update_delay);
d62a17ae 10848
ea47320b
DL
10849 if (bgp->v_update_delay
10850 != bgp->v_establish_wait)
d62a17ae 10851 json_object_int_add(
10852 json,
ea47320b
DL
10853 "updateDelayEstablishWait",
10854 bgp->v_establish_wait);
d62a17ae 10855
60466a63 10856 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10857 json_object_string_add(
10858 json,
10859 "updateDelayFirstNeighbor",
10860 bgp->update_delay_begin_time);
10861 json_object_boolean_true_add(
10862 json,
10863 "updateDelayInProgress");
10864 } else {
10865 if (bgp->update_delay_over) {
d62a17ae 10866 json_object_string_add(
10867 json,
10868 "updateDelayFirstNeighbor",
10869 bgp->update_delay_begin_time);
ea47320b 10870 json_object_string_add(
d62a17ae 10871 json,
ea47320b
DL
10872 "updateDelayBestpathResumed",
10873 bgp->update_delay_end_time);
10874 json_object_string_add(
d62a17ae 10875 json,
ea47320b
DL
10876 "updateDelayZebraUpdateResume",
10877 bgp->update_delay_zebra_resume_time);
10878 json_object_string_add(
10879 json,
10880 "updateDelayPeerUpdateResume",
10881 bgp->update_delay_peers_resume_time);
d62a17ae 10882 }
ea47320b
DL
10883 }
10884 } else {
10885 vty_out(vty,
10886 "Read-only mode update-delay limit: %d seconds\n",
10887 bgp->v_update_delay);
10888 if (bgp->v_update_delay
10889 != bgp->v_establish_wait)
d62a17ae 10890 vty_out(vty,
ea47320b
DL
10891 " Establish wait: %d seconds\n",
10892 bgp->v_establish_wait);
d62a17ae 10893
60466a63 10894 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10895 vty_out(vty,
10896 " First neighbor established: %s\n",
10897 bgp->update_delay_begin_time);
10898 vty_out(vty,
10899 " Delay in progress\n");
10900 } else {
10901 if (bgp->update_delay_over) {
d62a17ae 10902 vty_out(vty,
10903 " First neighbor established: %s\n",
10904 bgp->update_delay_begin_time);
10905 vty_out(vty,
ea47320b
DL
10906 " Best-paths resumed: %s\n",
10907 bgp->update_delay_end_time);
10908 vty_out(vty,
10909 " zebra update resumed: %s\n",
10910 bgp->update_delay_zebra_resume_time);
10911 vty_out(vty,
10912 " peers update resumed: %s\n",
10913 bgp->update_delay_peers_resume_time);
d62a17ae 10914 }
10915 }
10916 }
ea47320b 10917 }
d62a17ae 10918
ea47320b
DL
10919 if (use_json) {
10920 if (bgp_maxmed_onstartup_configured(bgp)
10921 && bgp->maxmed_active)
10922 json_object_boolean_true_add(
60466a63 10923 json, "maxMedOnStartup");
ea47320b
DL
10924 if (bgp->v_maxmed_admin)
10925 json_object_boolean_true_add(
60466a63 10926 json, "maxMedAdministrative");
d62a17ae 10927
ea47320b
DL
10928 json_object_int_add(
10929 json, "tableVersion",
60466a63 10930 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10931
60466a63
QY
10932 ents = bgp_table_count(bgp->rib[afi][safi]);
10933 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10934 json_object_int_add(
10935 json, "ribMemory",
9bcb3eef 10936 ents * sizeof(struct bgp_dest));
d62a17ae 10937
210ec2a0 10938 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10939 json_object_int_add(json, "peerCount", ents);
10940 json_object_int_add(json, "peerMemory",
10941 ents * sizeof(struct peer));
d62a17ae 10942
ea47320b
DL
10943 if ((ents = listcount(bgp->group))) {
10944 json_object_int_add(
60466a63 10945 json, "peerGroupCount", ents);
ea47320b
DL
10946 json_object_int_add(
10947 json, "peerGroupMemory",
996c9314
LB
10948 ents * sizeof(struct
10949 peer_group));
ea47320b 10950 }
d62a17ae 10951
ea47320b
DL
10952 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10953 BGP_CONFIG_DAMPENING))
10954 json_object_boolean_true_add(
60466a63 10955 json, "dampeningEnabled");
ea47320b
DL
10956 } else {
10957 if (bgp_maxmed_onstartup_configured(bgp)
10958 && bgp->maxmed_active)
d62a17ae 10959 vty_out(vty,
ea47320b
DL
10960 "Max-med on-startup active\n");
10961 if (bgp->v_maxmed_admin)
d62a17ae 10962 vty_out(vty,
ea47320b 10963 "Max-med administrative active\n");
d62a17ae 10964
60466a63
QY
10965 vty_out(vty, "BGP table version %" PRIu64 "\n",
10966 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 10967
60466a63 10968 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
10969 vty_out(vty,
10970 "RIB entries %ld, using %s of memory\n",
10971 ents,
9bcb3eef
DS
10972 mtype_memstr(
10973 memstrbuf, sizeof(memstrbuf),
10974 ents
10975 * sizeof(struct
10976 bgp_dest)));
ea47320b
DL
10977
10978 /* Peer related usage */
210ec2a0 10979 ents = bgp->af_peer_count[afi][safi];
60466a63 10980 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
10981 ents,
10982 mtype_memstr(
60466a63
QY
10983 memstrbuf, sizeof(memstrbuf),
10984 ents * sizeof(struct peer)));
ea47320b
DL
10985
10986 if ((ents = listcount(bgp->group)))
d62a17ae 10987 vty_out(vty,
ea47320b 10988 "Peer groups %ld, using %s of memory\n",
d62a17ae 10989 ents,
10990 mtype_memstr(
10991 memstrbuf,
10992 sizeof(memstrbuf),
996c9314
LB
10993 ents * sizeof(struct
10994 peer_group)));
d62a17ae 10995
ea47320b
DL
10996 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10997 BGP_CONFIG_DAMPENING))
60466a63 10998 vty_out(vty, "Dampening enabled.\n");
ea47320b 10999 vty_out(vty, "\n");
d62a17ae 11000
ea47320b
DL
11001 /* Subtract 8 here because 'Neighbor' is
11002 * 8 characters */
11003 vty_out(vty, "Neighbor");
60466a63
QY
11004 vty_out(vty, "%*s", max_neighbor_width - 8,
11005 " ");
3577f1c5 11006 if (show_failed)
85eeb029
DA
11007 vty_out(vty,
11008 BGP_SHOW_SUMMARY_HEADER_FAILED);
3577f1c5
DD
11009 else
11010 vty_out(vty,
85eeb029
DA
11011 show_wide
11012 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11013 : BGP_SHOW_SUMMARY_HEADER_ALL);
d62a17ae 11014 }
ea47320b 11015 }
d62a17ae 11016
d55811cc 11017 paf = peer_af_find(peer, afi, safi);
d3ada366 11018 filter = &peer->filter[afi][safi];
db92d226 11019
ea47320b 11020 count++;
3577f1c5
DD
11021 /* Works for both failed & successful cases */
11022 if (peer_dynamic_neighbor(peer))
11023 dn_count++;
d62a17ae 11024
ea47320b 11025 if (use_json) {
3577f1c5
DD
11026 json_peer = NULL;
11027
11028 if (show_failed &&
11029 bgp_has_peer_failed(peer, afi, safi)) {
11030 json_peer = json_object_new_object();
11031 bgp_show_failed_summary(vty, bgp, peer,
11032 json_peer, 0, use_json);
11033 } else if (!show_failed) {
10b49f14
DA
11034 if (show_established
11035 && bgp_has_peer_failed(peer, afi, safi))
11036 continue;
11037
3577f1c5
DD
11038 json_peer = json_object_new_object();
11039 if (peer_dynamic_neighbor(peer)) {
11040 json_object_boolean_true_add(json_peer,
11041 "dynamicPeer");
11042 }
d62a17ae 11043
3577f1c5
DD
11044 if (peer->hostname)
11045 json_object_string_add(json_peer, "hostname",
11046 peer->hostname);
11047
11048 if (peer->domainname)
11049 json_object_string_add(json_peer, "domainname",
11050 peer->domainname);
11051
11052 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
11053 json_object_int_add(
11054 json_peer, "localAs",
11055 peer->change_local_as
11056 ? peer->change_local_as
11057 : peer->local_as);
3577f1c5
DD
11058 json_object_int_add(json_peer, "version", 4);
11059 json_object_int_add(json_peer, "msgRcvd",
11060 PEER_TOTAL_RX(peer));
11061 json_object_int_add(json_peer, "msgSent",
11062 PEER_TOTAL_TX(peer));
11063
43aa5965
QY
11064 atomic_size_t outq_count, inq_count;
11065 outq_count = atomic_load_explicit(
11066 &peer->obuf->count,
11067 memory_order_relaxed);
11068 inq_count = atomic_load_explicit(
11069 &peer->ibuf->count,
11070 memory_order_relaxed);
11071
3577f1c5
DD
11072 json_object_int_add(json_peer, "tableVersion",
11073 peer->version[afi][safi]);
11074 json_object_int_add(json_peer, "outq",
43aa5965
QY
11075 outq_count);
11076 json_object_int_add(json_peer, "inq",
11077 inq_count);
3577f1c5
DD
11078 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11079 use_json, json_peer);
11080
3577f1c5
DD
11081 json_object_int_add(json_peer, "pfxRcd",
11082 peer->pcount[afi][pfx_rcd_safi]);
11083
3577f1c5 11084 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11085 json_object_int_add(
11086 json_peer, "pfxSnt",
11087 (PAF_SUBGRP(paf))->scount);
11088 else
11089 json_object_int_add(json_peer, "pfxSnt",
11090 0);
0e1f8ab5
DA
11091
11092 /* BGP FSM state */
cb9196e7 11093 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11094 || CHECK_FLAG(peer->bgp->flags,
11095 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11096 json_object_string_add(json_peer,
11097 "state",
3577f1c5
DD
11098 "Idle (Admin)");
11099 else if (peer->afc_recv[afi][safi])
11100 json_object_string_add(
0e1f8ab5
DA
11101 json_peer, "state",
11102 lookup_msg(bgp_status_msg,
11103 peer->status, NULL));
11104 else if (CHECK_FLAG(
11105 peer->sflags,
11106 PEER_STATUS_PREFIX_OVERFLOW))
11107 json_object_string_add(json_peer,
11108 "state",
3577f1c5
DD
11109 "Idle (PfxCt)");
11110 else
11111 json_object_string_add(
0e1f8ab5
DA
11112 json_peer, "state",
11113 lookup_msg(bgp_status_msg,
11114 peer->status, NULL));
11115
11116 /* BGP peer state */
11117 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11118 || CHECK_FLAG(peer->bgp->flags,
11119 BGP_FLAG_SHUTDOWN))
11120 json_object_string_add(json_peer,
11121 "peerState",
11122 "Admin");
11123 else if (CHECK_FLAG(
11124 peer->sflags,
11125 PEER_STATUS_PREFIX_OVERFLOW))
11126 json_object_string_add(json_peer,
11127 "peerState",
11128 "PfxCt");
11129 else if (CHECK_FLAG(peer->flags,
11130 PEER_FLAG_PASSIVE))
11131 json_object_string_add(json_peer,
11132 "peerState",
11133 "Passive");
11134 else if (CHECK_FLAG(peer->sflags,
11135 PEER_STATUS_NSF_WAIT))
11136 json_object_string_add(json_peer,
11137 "peerState",
11138 "NSF passive");
11139 else if (CHECK_FLAG(
11140 peer->bgp->flags,
11141 BGP_FLAG_EBGP_REQUIRES_POLICY)
11142 && (!bgp_inbound_policy_exists(peer,
11143 filter)
11144 || !bgp_outbound_policy_exists(
11145 peer, filter)))
11146 json_object_string_add(json_peer,
11147 "peerState",
11148 "Policy");
11149 else
11150 json_object_string_add(
11151 json_peer, "peerState", "OK");
11152
200116db
DD
11153 json_object_int_add(json_peer, "connectionsEstablished",
11154 peer->established);
11155 json_object_int_add(json_peer, "connectionsDropped",
11156 peer->dropped);
aa72bd7e
PG
11157 if (peer->desc)
11158 json_object_string_add(
11159 json_peer, "desc", peer->desc);
b4e9dcba 11160 }
3577f1c5
DD
11161 /* Avoid creating empty peer dicts in JSON */
11162 if (json_peer == NULL)
11163 continue;
ea47320b
DL
11164
11165 if (peer->conf_if)
60466a63 11166 json_object_string_add(json_peer, "idType",
ea47320b
DL
11167 "interface");
11168 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11169 json_object_string_add(json_peer, "idType",
11170 "ipv4");
ea47320b 11171 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11172 json_object_string_add(json_peer, "idType",
11173 "ipv6");
ea47320b
DL
11174 json_object_object_add(json_peers, peer->host,
11175 json_peer);
11176 } else {
3577f1c5
DD
11177 if (show_failed &&
11178 bgp_has_peer_failed(peer, afi, safi)) {
11179 bgp_show_failed_summary(vty, bgp, peer, NULL,
11180 max_neighbor_width,
11181 use_json);
11182 } else if (!show_failed) {
10b49f14
DA
11183 if (show_established
11184 && bgp_has_peer_failed(peer, afi, safi))
11185 continue;
11186
3577f1c5
DD
11187 memset(dn_flag, '\0', sizeof(dn_flag));
11188 if (peer_dynamic_neighbor(peer)) {
11189 dn_flag[0] = '*';
11190 }
d62a17ae 11191
3577f1c5 11192 if (peer->hostname
892fedb6
DA
11193 && CHECK_FLAG(bgp->flags,
11194 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11195 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11196 peer->hostname,
11197 peer->host);
d62a17ae 11198 else
3577f1c5
DD
11199 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11200
11201 /* pad the neighbor column with spaces */
11202 if (len < max_neighbor_width)
11203 vty_out(vty, "%*s", max_neighbor_width - len,
11204 " ");
11205
43aa5965
QY
11206 atomic_size_t outq_count, inq_count;
11207 outq_count = atomic_load_explicit(
11208 &peer->obuf->count,
11209 memory_order_relaxed);
11210 inq_count = atomic_load_explicit(
11211 &peer->ibuf->count,
11212 memory_order_relaxed);
11213
85eeb029
DA
11214 if (show_wide)
11215 vty_out(vty,
11216 "4 %10u %10u %9u %9u %8" PRIu64
11217 " %4zu %4zu %8s",
11218 peer->as,
11219 peer->change_local_as
11220 ? peer->change_local_as
11221 : peer->local_as,
11222 PEER_TOTAL_RX(peer),
11223 PEER_TOTAL_TX(peer),
11224 peer->version[afi][safi],
11225 inq_count, outq_count,
11226 peer_uptime(peer->uptime,
11227 timebuf,
11228 BGP_UPTIME_LEN, 0,
11229 NULL));
11230 else
11231 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11232 " %4zu %4zu %8s",
11233 peer->as, PEER_TOTAL_RX(peer),
11234 PEER_TOTAL_TX(peer),
11235 peer->version[afi][safi],
11236 inq_count, outq_count,
11237 peer_uptime(peer->uptime,
11238 timebuf,
11239 BGP_UPTIME_LEN, 0,
11240 NULL));
3577f1c5 11241
db92d226 11242 if (peer->status == Established) {
d3ada366
DA
11243 if (peer->afc_recv[afi][safi]) {
11244 if (CHECK_FLAG(
11245 bgp->flags,
11246 BGP_FLAG_EBGP_REQUIRES_POLICY)
11247 && !bgp_inbound_policy_exists(
11248 peer, filter))
11249 vty_out(vty, " %12s",
11250 "(Policy)");
11251 else
11252 vty_out(vty,
6cde4b45 11253 " %12u",
d3ada366
DA
11254 peer->pcount
11255 [afi]
11256 [pfx_rcd_safi]);
11257 } else {
749d0f27 11258 vty_out(vty, " NoNeg");
d3ada366 11259 }
db92d226 11260
d3ada366
DA
11261 if (paf && PAF_SUBGRP(paf)) {
11262 if (CHECK_FLAG(
11263 bgp->flags,
11264 BGP_FLAG_EBGP_REQUIRES_POLICY)
11265 && !bgp_outbound_policy_exists(
11266 peer, filter))
11267 vty_out(vty, " %8s",
11268 "(Policy)");
11269 else
11270 vty_out(vty,
6cde4b45 11271 " %8u",
d3ada366
DA
11272 (PAF_SUBGRP(
11273 paf))
11274 ->scount);
749d0f27
DA
11275 } else {
11276 vty_out(vty, " NoNeg");
d3ada366 11277 }
db92d226 11278 } else {
736b68f3
DS
11279 if (CHECK_FLAG(peer->flags,
11280 PEER_FLAG_SHUTDOWN)
11281 || CHECK_FLAG(peer->bgp->flags,
11282 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11283 vty_out(vty, " Idle (Admin)");
11284 else if (CHECK_FLAG(
11285 peer->sflags,
11286 PEER_STATUS_PREFIX_OVERFLOW))
11287 vty_out(vty, " Idle (PfxCt)");
11288 else
11289 vty_out(vty, " %12s",
11290 lookup_msg(bgp_status_msg,
11291 peer->status, NULL));
db92d226 11292
6cde4b45 11293 vty_out(vty, " %8u", 0);
3577f1c5 11294 }
aa72bd7e 11295 if (peer->desc)
cb75bb31
DA
11296 vty_out(vty, " %s",
11297 bgp_peer_description_stripped(
85eeb029
DA
11298 peer->desc,
11299 show_wide ? 64 : 20));
aa72bd7e
PG
11300 else
11301 vty_out(vty, " N/A");
3577f1c5 11302 vty_out(vty, "\n");
d62a17ae 11303 }
3577f1c5 11304
d62a17ae 11305 }
11306 }
f933309e 11307
d62a17ae 11308 if (use_json) {
11309 json_object_object_add(json, "peers", json_peers);
3577f1c5 11310 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 11311 json_object_int_add(json, "totalPeers", count);
11312 json_object_int_add(json, "dynamicPeers", dn_count);
11313
3577f1c5
DD
11314 if (!show_failed)
11315 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11316
996c9314
LB
11317 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11318 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11319 json_object_free(json);
11320 } else {
11321 if (count)
11322 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11323 else {
d6ceaca3 11324 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11325 get_afi_safi_str(afi, safi, false));
d62a17ae 11326 }
b05a1c8b 11327
d6ceaca3 11328 if (dn_count) {
d62a17ae 11329 vty_out(vty, "* - dynamic neighbor\n");
11330 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11331 dn_count, bgp->dynamic_neighbors_limit);
11332 }
11333 }
1ff9a340 11334
d62a17ae 11335 return CMD_SUCCESS;
718e3744 11336}
11337
d62a17ae 11338static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
85eeb029 11339 int safi, uint8_t show_flags)
d62a17ae 11340{
11341 int is_first = 1;
11342 int afi_wildcard = (afi == AFI_MAX);
11343 int safi_wildcard = (safi == SAFI_MAX);
11344 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11345 bool nbr_output = false;
85eeb029 11346 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11347
11348 if (use_json && is_wildcard)
11349 vty_out(vty, "{\n");
11350 if (afi_wildcard)
11351 afi = 1; /* AFI_IP */
11352 while (afi < AFI_MAX) {
11353 if (safi_wildcard)
11354 safi = 1; /* SAFI_UNICAST */
11355 while (safi < SAFI_MAX) {
318cac96 11356 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11357 nbr_output = true;
f86897b9 11358
d62a17ae 11359 if (is_wildcard) {
11360 /*
11361 * So limit output to those afi/safi
11362 * pairs that
11363 * actualy have something interesting in
11364 * them
11365 */
11366 if (use_json) {
d62a17ae 11367 if (!is_first)
11368 vty_out(vty, ",\n");
11369 else
11370 is_first = 0;
11371
11372 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11373 get_afi_safi_str(afi,
11374 safi,
11375 true));
d62a17ae 11376 } else {
11377 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
11378 get_afi_safi_str(afi,
11379 safi,
11380 false));
d62a17ae 11381 }
11382 }
10b49f14 11383 bgp_show_summary(vty, bgp, afi, safi,
85eeb029 11384 show_flags);
d62a17ae 11385 }
11386 safi++;
d62a17ae 11387 if (!safi_wildcard)
11388 safi = SAFI_MAX;
11389 }
11390 afi++;
ee851c8c 11391 if (!afi_wildcard)
d62a17ae 11392 afi = AFI_MAX;
11393 }
11394
11395 if (use_json && is_wildcard)
11396 vty_out(vty, "}\n");
ca61fd25
DS
11397 else if (!nbr_output) {
11398 if (use_json)
11399 vty_out(vty, "{}\n");
11400 else
11401 vty_out(vty, "%% No BGP neighbors found\n");
11402 }
d62a17ae 11403}
11404
11405static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
85eeb029 11406 safi_t safi, uint8_t show_flags)
d62a17ae 11407{
11408 struct listnode *node, *nnode;
11409 struct bgp *bgp;
d62a17ae 11410 int is_first = 1;
9f049418 11411 bool nbr_output = false;
85eeb029 11412 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11413
11414 if (use_json)
11415 vty_out(vty, "{\n");
11416
11417 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11418 nbr_output = true;
d62a17ae 11419 if (use_json) {
d62a17ae 11420 if (!is_first)
11421 vty_out(vty, ",\n");
11422 else
11423 is_first = 0;
11424
11425 vty_out(vty, "\"%s\":",
11426 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11427 ? VRF_DEFAULT_NAME
d62a17ae 11428 : bgp->name);
11429 } else {
11430 vty_out(vty, "\nInstance %s:\n",
11431 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11432 ? VRF_DEFAULT_NAME
d62a17ae 11433 : bgp->name);
11434 }
85eeb029 11435 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
d62a17ae 11436 }
11437
11438 if (use_json)
11439 vty_out(vty, "}\n");
9f049418
DS
11440 else if (!nbr_output)
11441 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11442}
11443
11444int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
85eeb029 11445 safi_t safi, uint8_t show_flags)
d62a17ae 11446{
11447 struct bgp *bgp;
85eeb029 11448 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11449
11450 if (name) {
11451 if (strmatch(name, "all")) {
85eeb029
DA
11452 bgp_show_all_instances_summary_vty(vty, afi, safi,
11453 show_flags);
d62a17ae 11454 return CMD_SUCCESS;
11455 } else {
11456 bgp = bgp_lookup_by_name(name);
11457
11458 if (!bgp) {
11459 if (use_json)
11460 vty_out(vty, "{}\n");
11461 else
11462 vty_out(vty,
ca61fd25 11463 "%% BGP instance not found\n");
d62a17ae 11464 return CMD_WARNING;
11465 }
11466
f86897b9 11467 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
85eeb029 11468 show_flags);
d62a17ae 11469 return CMD_SUCCESS;
11470 }
11471 }
11472
11473 bgp = bgp_get_default();
11474
11475 if (bgp)
85eeb029 11476 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
9f049418 11477 else {
ca61fd25
DS
11478 if (use_json)
11479 vty_out(vty, "{}\n");
11480 else
11481 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11482 return CMD_WARNING;
11483 }
d62a17ae 11484
11485 return CMD_SUCCESS;
4fb25c53
DW
11486}
11487
716b2d8a 11488/* `show [ip] bgp summary' commands. */
96f3485c 11489DEFPY (show_ip_bgp_summary,
718e3744 11490 show_ip_bgp_summary_cmd,
85eeb029 11491 "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 11492 SHOW_STR
11493 IP_STR
11494 BGP_STR
8386ac43 11495 BGP_INSTANCE_HELP_STR
46f296b4 11496 BGP_AFI_HELP_STR
dd6bd0f1 11497 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 11498 "Display the entries for all address families\n"
b05a1c8b 11499 "Summary of BGP neighbor status\n"
10b49f14 11500 "Show only sessions in Established state\n"
3577f1c5 11501 "Show only sessions not in Established state\n"
85eeb029 11502 "Increase table width for longer output\n"
9973d184 11503 JSON_STR)
718e3744 11504{
d62a17ae 11505 char *vrf = NULL;
11506 afi_t afi = AFI_MAX;
11507 safi_t safi = SAFI_MAX;
85eeb029 11508 uint8_t show_flags = 0;
d62a17ae 11509
11510 int idx = 0;
11511
11512 /* show [ip] bgp */
96f3485c 11513 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11514 afi = AFI_IP;
9a8bdf1c
PG
11515 /* [<vrf> VIEWVRFNAME] */
11516 if (argv_find(argv, argc, "vrf", &idx)) {
11517 vrf = argv[idx + 1]->arg;
11518 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11519 vrf = NULL;
11520 } else if (argv_find(argv, argc, "view", &idx))
11521 /* [<view> VIEWVRFNAME] */
11522 vrf = argv[idx + 1]->arg;
d62a17ae 11523 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11524 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11525 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11526 }
11527
3577f1c5 11528 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11529 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11530
10b49f14 11531 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11532 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11533
11534 if (argv_find(argv, argc, "wide", &idx))
11535 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11536
11537 if (argv_find(argv, argc, "json", &idx))
11538 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11539
85eeb029 11540 return bgp_show_summary_vty(vty, vrf, afi, safi, show_flags);
d62a17ae 11541}
11542
5cb5f4d0 11543const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11544{
5cb5f4d0
DD
11545 if (for_json)
11546 return get_afi_safi_json_str(afi, safi);
d62a17ae 11547 else
5cb5f4d0 11548 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11549}
11550
d62a17ae 11551
11552static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11553 afi_t afi, safi_t safi,
d7c0a89a
QY
11554 uint16_t adv_smcap, uint16_t adv_rmcap,
11555 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11556 bool use_json, json_object *json_pref)
d62a17ae 11557{
11558 /* Send-Mode */
11559 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11560 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11561 if (use_json) {
11562 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11563 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11564 json_object_string_add(json_pref, "sendMode",
11565 "advertisedAndReceived");
11566 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11567 json_object_string_add(json_pref, "sendMode",
11568 "advertised");
11569 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11570 json_object_string_add(json_pref, "sendMode",
11571 "received");
11572 } else {
11573 vty_out(vty, " Send-mode: ");
11574 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11575 vty_out(vty, "advertised");
11576 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11577 vty_out(vty, "%sreceived",
11578 CHECK_FLAG(p->af_cap[afi][safi],
11579 adv_smcap)
11580 ? ", "
11581 : "");
11582 vty_out(vty, "\n");
11583 }
11584 }
11585
11586 /* Receive-Mode */
11587 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11588 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11589 if (use_json) {
11590 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11591 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11592 json_object_string_add(json_pref, "recvMode",
11593 "advertisedAndReceived");
11594 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11595 json_object_string_add(json_pref, "recvMode",
11596 "advertised");
11597 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11598 json_object_string_add(json_pref, "recvMode",
11599 "received");
11600 } else {
11601 vty_out(vty, " Receive-mode: ");
11602 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11603 vty_out(vty, "advertised");
11604 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11605 vty_out(vty, "%sreceived",
11606 CHECK_FLAG(p->af_cap[afi][safi],
11607 adv_rmcap)
11608 ? ", "
11609 : "");
11610 vty_out(vty, "\n");
11611 }
11612 }
11613}
11614
13909c4f
DS
11615static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11616 struct peer *p,
11617 bool use_json,
11618 json_object *json)
2986cac2 11619{
08c2d52a 11620 bool rbit_status = false;
2986cac2 11621
11622 if (!use_json)
a53ca37b 11623 vty_out(vty, "\n R bit: ");
2986cac2 11624
13909c4f
DS
11625 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11626 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11627 && (p->status == Established)) {
2986cac2 11628
11629 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11630 rbit_status = true;
2986cac2 11631 else
08c2d52a 11632 rbit_status = false;
2986cac2 11633 }
11634
11635 if (rbit_status) {
11636 if (use_json)
13909c4f 11637 json_object_boolean_true_add(json, "rBit");
2986cac2 11638 else
11639 vty_out(vty, "True\n");
11640 } else {
11641 if (use_json)
13909c4f 11642 json_object_boolean_false_add(json, "rBit");
2986cac2 11643 else
11644 vty_out(vty, "False\n");
11645 }
11646}
11647
13909c4f
DS
11648static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11649 struct peer *peer,
11650 bool use_json,
11651 json_object *json)
2986cac2 11652{
2bb5d39b 11653 const char *mode = "NotApplicable";
2986cac2 11654
11655 if (!use_json)
a53ca37b 11656 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11657
13909c4f
DS
11658 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11659 && (peer->status == Established)) {
2986cac2 11660
13909c4f
DS
11661 if ((peer->nsf_af_count == 0)
11662 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11663
2986cac2 11664 mode = "Disable";
11665
13909c4f
DS
11666 } else if (peer->nsf_af_count == 0
11667 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11668
2986cac2 11669 mode = "Helper";
11670
13909c4f
DS
11671 } else if (peer->nsf_af_count != 0
11672 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11673
2986cac2 11674 mode = "Restart";
2986cac2 11675 }
11676 }
11677
11678 if (use_json) {
13909c4f 11679 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11680 } else
11681 vty_out(vty, mode, "\n");
11682}
11683
13909c4f
DS
11684static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11685 struct peer *p,
11686 bool use_json,
11687 json_object *json)
2986cac2 11688{
11689 const char *mode = "Invalid";
11690
11691 if (!use_json)
a53ca37b 11692 vty_out(vty, " Local GR Mode: ");
2986cac2 11693
11694 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11695 mode = "Helper";
11696 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11697 mode = "Restart";
11698 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11699 mode = "Disable";
2ba1fe69 11700 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11701 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11702 mode = "Helper*";
11703 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11704 mode = "Restart*";
11705 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11706 mode = "Disable*";
11707 else
11708 mode = "Invalid*";
2ba1fe69 11709 }
2986cac2 11710
11711 if (use_json) {
13909c4f 11712 json_object_string_add(json, "localGrMode", mode);
2986cac2 11713 } else {
11714 vty_out(vty, mode, "\n");
11715 }
11716}
11717
13909c4f
DS
11718static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11719 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11720{
2ba1fe69 11721 afi_t afi;
11722 safi_t safi;
2986cac2 11723 json_object *json_afi_safi = NULL;
11724 json_object *json_timer = NULL;
11725 json_object *json_endofrib_status = NULL;
9e3b51a7 11726 bool eor_flag = false;
2986cac2 11727
11728 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11729 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
11730 if (!peer->afc[afi][safi])
11731 continue;
2986cac2 11732
13909c4f
DS
11733 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11734 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11735 continue;
9e3b51a7 11736
13909c4f
DS
11737 if (use_json) {
11738 json_afi_safi = json_object_new_object();
11739 json_endofrib_status = json_object_new_object();
11740 json_timer = json_object_new_object();
11741 }
2986cac2 11742
13909c4f
DS
11743 if (peer->eor_stime[afi][safi]
11744 >= peer->pkt_stime[afi][safi])
11745 eor_flag = true;
11746 else
11747 eor_flag = false;
2986cac2 11748
13909c4f 11749 if (!use_json) {
a53ca37b 11750 vty_out(vty, " %s:\n",
13909c4f 11751 get_afi_safi_str(afi, safi, false));
2986cac2 11752
a53ca37b 11753 vty_out(vty, " F bit: ");
698ba8d0 11754 }
2986cac2 11755
13909c4f
DS
11756 if (peer->nsf[afi][safi]
11757 && CHECK_FLAG(peer->af_cap[afi][safi],
11758 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11759
13909c4f
DS
11760 if (use_json) {
11761 json_object_boolean_true_add(
2986cac2 11762 json_afi_safi, "fBit");
13909c4f
DS
11763 } else
11764 vty_out(vty, "True\n");
11765 } else {
11766 if (use_json)
11767 json_object_boolean_false_add(
11768 json_afi_safi, "fBit");
11769 else
11770 vty_out(vty, "False\n");
11771 }
2986cac2 11772
13909c4f 11773 if (!use_json)
a53ca37b 11774 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11775
13909c4f
DS
11776 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11777 PEER_STATUS_EOR_SEND)) {
11778 if (use_json) {
11779 json_object_boolean_true_add(
2986cac2 11780 json_endofrib_status,
13909c4f 11781 "endOfRibSend");
9e3b51a7 11782
13909c4f
DS
11783 PRINT_EOR_JSON(eor_flag);
11784 } else {
11785 vty_out(vty, "Yes\n");
11786 vty_out(vty,
a53ca37b 11787 " End-of-RIB sent after update: ");
2986cac2 11788
13909c4f
DS
11789 PRINT_EOR(eor_flag);
11790 }
11791 } else {
11792 if (use_json) {
11793 json_object_boolean_false_add(
2986cac2 11794 json_endofrib_status,
13909c4f
DS
11795 "endOfRibSend");
11796 json_object_boolean_false_add(
9e3b51a7 11797 json_endofrib_status,
13909c4f
DS
11798 "endOfRibSentAfterUpdate");
11799 } else {
11800 vty_out(vty, "No\n");
11801 vty_out(vty,
a53ca37b 11802 " End-of-RIB sent after update: ");
13909c4f 11803 vty_out(vty, "No\n");
2986cac2 11804 }
13909c4f 11805 }
2986cac2 11806
a53ca37b
DA
11807 if (!use_json)
11808 vty_out(vty, " End-of-RIB received: ");
11809
11810 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11811 PEER_STATUS_EOR_RECEIVED)) {
11812 if (use_json)
11813 json_object_boolean_true_add(
11814 json_endofrib_status,
11815 "endOfRibRecv");
11816 else
11817 vty_out(vty, "Yes\n");
11818 } else {
11819 if (use_json)
11820 json_object_boolean_false_add(
11821 json_endofrib_status,
11822 "endOfRibRecv");
11823 else
11824 vty_out(vty, "No\n");
11825 }
11826
13909c4f
DS
11827 if (use_json) {
11828 json_object_int_add(json_timer,
11829 "stalePathTimer",
11830 peer->bgp->stalepath_time);
2986cac2 11831
13909c4f
DS
11832 if (peer->t_gr_stale != NULL) {
11833 json_object_int_add(
2986cac2 11834 json_timer,
11835 "stalePathTimerRemaining",
11836 thread_timer_remain_second(
13909c4f
DS
11837 peer->t_gr_stale));
11838 }
3a75afa4 11839
13909c4f
DS
11840 /* Display Configured Selection
11841 * Deferral only when when
11842 * Gr mode is enabled.
11843 */
11844 if (CHECK_FLAG(peer->flags,
11845 PEER_FLAG_GRACEFUL_RESTART)) {
11846 json_object_int_add(
3a75afa4 11847 json_timer,
2986cac2 11848 "selectionDeferralTimer",
11849 peer->bgp->stalepath_time);
13909c4f 11850 }
2986cac2 11851
13909c4f
DS
11852 if (peer->bgp->gr_info[afi][safi]
11853 .t_select_deferral
11854 != NULL) {
2986cac2 11855
13909c4f 11856 json_object_int_add(
2986cac2 11857 json_timer,
11858 "selectionDeferralTimerRemaining",
11859 thread_timer_remain_second(
13909c4f
DS
11860 peer->bgp
11861 ->gr_info[afi]
11862 [safi]
11863 .t_select_deferral));
11864 }
11865 } else {
a53ca37b 11866 vty_out(vty, " Timers:\n");
13909c4f 11867 vty_out(vty,
a53ca37b
DA
11868 " Configured Stale Path Time(sec): %u\n",
11869 peer->bgp->stalepath_time);
2986cac2 11870
a53ca37b 11871 if (peer->t_gr_stale != NULL)
2986cac2 11872 vty_out(vty,
a53ca37b 11873 " Stale Path Remaining(sec): %ld\n",
2986cac2 11874 thread_timer_remain_second(
13909c4f 11875 peer->t_gr_stale));
13909c4f
DS
11876 /* Display Configured Selection
11877 * Deferral only when when
11878 * Gr mode is enabled.
11879 */
11880 if (CHECK_FLAG(peer->flags,
a53ca37b 11881 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 11882 vty_out(vty,
a53ca37b 11883 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 11884 peer->bgp->select_defer_time);
2986cac2 11885
13909c4f
DS
11886 if (peer->bgp->gr_info[afi][safi]
11887 .t_select_deferral
a53ca37b 11888 != NULL)
13909c4f 11889 vty_out(vty,
a53ca37b 11890 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 11891 thread_timer_remain_second(
13909c4f
DS
11892 peer->bgp
11893 ->gr_info[afi]
11894 [safi]
11895 .t_select_deferral));
2986cac2 11896 }
13909c4f
DS
11897 if (use_json) {
11898 json_object_object_add(json_afi_safi,
11899 "endOfRibStatus",
11900 json_endofrib_status);
11901 json_object_object_add(json_afi_safi, "timers",
11902 json_timer);
11903 json_object_object_add(
11904 json, get_afi_safi_str(afi, safi, true),
11905 json_afi_safi);
11906 }
2986cac2 11907 }
11908 }
11909}
11910
36235319
QY
11911static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11912 struct peer *p,
11913 bool use_json,
11914 json_object *json)
2986cac2 11915{
11916 if (use_json) {
11917 json_object *json_timer = NULL;
11918
11919 json_timer = json_object_new_object();
11920
13909c4f
DS
11921 json_object_int_add(json_timer, "configuredRestartTimer",
11922 p->bgp->restart_time);
2986cac2 11923
13909c4f
DS
11924 json_object_int_add(json_timer, "receivedRestartTimer",
11925 p->v_gr_restart);
2986cac2 11926
13909c4f
DS
11927 if (p->t_gr_restart != NULL)
11928 json_object_int_add(
11929 json_timer, "restartTimerRemaining",
11930 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11931
11932 json_object_object_add(json, "timers", json_timer);
11933 } else {
11934
a53ca37b
DA
11935 vty_out(vty, " Timers:\n");
11936 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11937 p->bgp->restart_time);
2986cac2 11938
a53ca37b 11939 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11940 p->v_gr_restart);
11941 if (p->t_gr_restart != NULL)
a53ca37b 11942 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11943 thread_timer_remain_second(p->t_gr_restart));
36235319 11944 if (p->t_gr_restart != NULL) {
a53ca37b 11945 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11946 thread_timer_remain_second(p->t_gr_restart));
11947 }
2986cac2 11948 }
11949}
11950
11951static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11952 bool use_json, json_object *json)
2986cac2 11953{
11954 char buf[SU_ADDRSTRLEN] = {0};
11955 char dn_flag[2] = {0};
2b7165e7
QY
11956 /* '*' + v6 address of neighbor */
11957 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11958
2986cac2 11959 if (!p->conf_if && peer_dynamic_neighbor(p))
11960 dn_flag[0] = '*';
11961
11962 if (p->conf_if) {
11963 if (use_json)
13909c4f
DS
11964 json_object_string_add(
11965 json, "neighborAddr",
2986cac2 11966 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11967 ? "none"
11968 : sockunion2str(&p->su, buf,
11969 SU_ADDRSTRLEN));
2986cac2 11970 else
13909c4f 11971 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11972 BGP_PEER_SU_UNSPEC(p)
11973 ? "none"
11974 : sockunion2str(&p->su, buf,
11975 SU_ADDRSTRLEN));
11976 } else {
772270f3
QY
11977 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11978 p->host);
2986cac2 11979
11980 if (use_json)
36235319
QY
11981 json_object_string_add(json, "neighborAddr",
11982 neighborAddr);
2986cac2 11983 else
36235319 11984 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11985 }
11986
11987 /* more gr info in new format */
11988 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11989}
11990
d62a17ae 11991static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11992 safi_t safi, bool use_json,
d62a17ae 11993 json_object *json_neigh)
11994{
0291c246
MK
11995 struct bgp_filter *filter;
11996 struct peer_af *paf;
11997 char orf_pfx_name[BUFSIZ];
11998 int orf_pfx_count;
11999 json_object *json_af = NULL;
12000 json_object *json_prefA = NULL;
12001 json_object *json_prefB = NULL;
12002 json_object *json_addr = NULL;
fa36596c 12003 json_object *json_advmap = NULL;
d62a17ae 12004
12005 if (use_json) {
12006 json_addr = json_object_new_object();
12007 json_af = json_object_new_object();
12008 filter = &p->filter[afi][safi];
12009
12010 if (peer_group_active(p))
12011 json_object_string_add(json_addr, "peerGroupMember",
12012 p->group->name);
12013
12014 paf = peer_af_find(p, afi, safi);
12015 if (paf && PAF_SUBGRP(paf)) {
12016 json_object_int_add(json_addr, "updateGroupId",
12017 PAF_UPDGRP(paf)->id);
12018 json_object_int_add(json_addr, "subGroupId",
12019 PAF_SUBGRP(paf)->id);
12020 json_object_int_add(json_addr, "packetQueueLength",
12021 bpacket_queue_virtual_length(paf));
12022 }
12023
12024 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12025 || CHECK_FLAG(p->af_cap[afi][safi],
12026 PEER_CAP_ORF_PREFIX_SM_RCV)
12027 || CHECK_FLAG(p->af_cap[afi][safi],
12028 PEER_CAP_ORF_PREFIX_RM_ADV)
12029 || CHECK_FLAG(p->af_cap[afi][safi],
12030 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12031 json_object_int_add(json_af, "orfType",
12032 ORF_TYPE_PREFIX);
12033 json_prefA = json_object_new_object();
12034 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12035 PEER_CAP_ORF_PREFIX_SM_ADV,
12036 PEER_CAP_ORF_PREFIX_RM_ADV,
12037 PEER_CAP_ORF_PREFIX_SM_RCV,
12038 PEER_CAP_ORF_PREFIX_RM_RCV,
12039 use_json, json_prefA);
12040 json_object_object_add(json_af, "orfPrefixList",
12041 json_prefA);
12042 }
12043
12044 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12045 || CHECK_FLAG(p->af_cap[afi][safi],
12046 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12047 || CHECK_FLAG(p->af_cap[afi][safi],
12048 PEER_CAP_ORF_PREFIX_RM_ADV)
12049 || CHECK_FLAG(p->af_cap[afi][safi],
12050 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12051 json_object_int_add(json_af, "orfOldType",
12052 ORF_TYPE_PREFIX_OLD);
12053 json_prefB = json_object_new_object();
12054 bgp_show_peer_afi_orf_cap(
12055 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12056 PEER_CAP_ORF_PREFIX_RM_ADV,
12057 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12058 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12059 json_prefB);
12060 json_object_object_add(json_af, "orfOldPrefixList",
12061 json_prefB);
12062 }
12063
12064 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12065 || CHECK_FLAG(p->af_cap[afi][safi],
12066 PEER_CAP_ORF_PREFIX_SM_RCV)
12067 || CHECK_FLAG(p->af_cap[afi][safi],
12068 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12069 || CHECK_FLAG(p->af_cap[afi][safi],
12070 PEER_CAP_ORF_PREFIX_RM_ADV)
12071 || CHECK_FLAG(p->af_cap[afi][safi],
12072 PEER_CAP_ORF_PREFIX_RM_RCV)
12073 || CHECK_FLAG(p->af_cap[afi][safi],
12074 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12075 json_object_object_add(json_addr, "afDependentCap",
12076 json_af);
12077 else
12078 json_object_free(json_af);
12079
772270f3
QY
12080 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12081 p->host, afi, safi);
d62a17ae 12082 orf_pfx_count = prefix_bgp_show_prefix_list(
12083 NULL, afi, orf_pfx_name, use_json);
12084
12085 if (CHECK_FLAG(p->af_sflags[afi][safi],
12086 PEER_STATUS_ORF_PREFIX_SEND)
12087 || orf_pfx_count) {
12088 if (CHECK_FLAG(p->af_sflags[afi][safi],
12089 PEER_STATUS_ORF_PREFIX_SEND))
12090 json_object_boolean_true_add(json_neigh,
12091 "orfSent");
12092 if (orf_pfx_count)
12093 json_object_int_add(json_addr, "orfRecvCounter",
12094 orf_pfx_count);
12095 }
12096 if (CHECK_FLAG(p->af_sflags[afi][safi],
12097 PEER_STATUS_ORF_WAIT_REFRESH))
12098 json_object_string_add(
12099 json_addr, "orfFirstUpdate",
12100 "deferredUntilORFOrRouteRefreshRecvd");
12101
12102 if (CHECK_FLAG(p->af_flags[afi][safi],
12103 PEER_FLAG_REFLECTOR_CLIENT))
12104 json_object_boolean_true_add(json_addr,
12105 "routeReflectorClient");
12106 if (CHECK_FLAG(p->af_flags[afi][safi],
12107 PEER_FLAG_RSERVER_CLIENT))
12108 json_object_boolean_true_add(json_addr,
12109 "routeServerClient");
12110 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12111 json_object_boolean_true_add(json_addr,
12112 "inboundSoftConfigPermit");
12113
12114 if (CHECK_FLAG(p->af_flags[afi][safi],
12115 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12116 json_object_boolean_true_add(
12117 json_addr,
12118 "privateAsNumsAllReplacedInUpdatesToNbr");
12119 else if (CHECK_FLAG(p->af_flags[afi][safi],
12120 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12121 json_object_boolean_true_add(
12122 json_addr,
12123 "privateAsNumsReplacedInUpdatesToNbr");
12124 else if (CHECK_FLAG(p->af_flags[afi][safi],
12125 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12126 json_object_boolean_true_add(
12127 json_addr,
12128 "privateAsNumsAllRemovedInUpdatesToNbr");
12129 else if (CHECK_FLAG(p->af_flags[afi][safi],
12130 PEER_FLAG_REMOVE_PRIVATE_AS))
12131 json_object_boolean_true_add(
12132 json_addr,
12133 "privateAsNumsRemovedInUpdatesToNbr");
12134
dcc68b5e
MS
12135 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12136 json_object_boolean_true_add(
12137 json_addr,
12138 bgp_addpath_names(p->addpath_type[afi][safi])
12139 ->type_json_name);
d62a17ae 12140
12141 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12142 json_object_string_add(json_addr,
12143 "overrideASNsInOutboundUpdates",
12144 "ifAspathEqualRemoteAs");
12145
12146 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12147 || CHECK_FLAG(p->af_flags[afi][safi],
12148 PEER_FLAG_FORCE_NEXTHOP_SELF))
12149 json_object_boolean_true_add(json_addr,
12150 "routerAlwaysNextHop");
12151 if (CHECK_FLAG(p->af_flags[afi][safi],
12152 PEER_FLAG_AS_PATH_UNCHANGED))
12153 json_object_boolean_true_add(
12154 json_addr, "unchangedAsPathPropogatedToNbr");
12155 if (CHECK_FLAG(p->af_flags[afi][safi],
12156 PEER_FLAG_NEXTHOP_UNCHANGED))
12157 json_object_boolean_true_add(
12158 json_addr, "unchangedNextHopPropogatedToNbr");
12159 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12160 json_object_boolean_true_add(
12161 json_addr, "unchangedMedPropogatedToNbr");
12162 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12163 || CHECK_FLAG(p->af_flags[afi][safi],
12164 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12165 if (CHECK_FLAG(p->af_flags[afi][safi],
12166 PEER_FLAG_SEND_COMMUNITY)
12167 && CHECK_FLAG(p->af_flags[afi][safi],
12168 PEER_FLAG_SEND_EXT_COMMUNITY))
12169 json_object_string_add(json_addr,
12170 "commAttriSentToNbr",
12171 "extendedAndStandard");
12172 else if (CHECK_FLAG(p->af_flags[afi][safi],
12173 PEER_FLAG_SEND_EXT_COMMUNITY))
12174 json_object_string_add(json_addr,
12175 "commAttriSentToNbr",
12176 "extended");
12177 else
12178 json_object_string_add(json_addr,
12179 "commAttriSentToNbr",
12180 "standard");
12181 }
12182 if (CHECK_FLAG(p->af_flags[afi][safi],
12183 PEER_FLAG_DEFAULT_ORIGINATE)) {
12184 if (p->default_rmap[afi][safi].name)
12185 json_object_string_add(
12186 json_addr, "defaultRouteMap",
12187 p->default_rmap[afi][safi].name);
12188
12189 if (paf && PAF_SUBGRP(paf)
12190 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12191 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12192 json_object_boolean_true_add(json_addr,
12193 "defaultSent");
12194 else
12195 json_object_boolean_true_add(json_addr,
12196 "defaultNotSent");
12197 }
12198
dff8f48d 12199 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12200 if (is_evpn_enabled())
60466a63
QY
12201 json_object_boolean_true_add(
12202 json_addr, "advertiseAllVnis");
dff8f48d
MK
12203 }
12204
d62a17ae 12205 if (filter->plist[FILTER_IN].name
12206 || filter->dlist[FILTER_IN].name
12207 || filter->aslist[FILTER_IN].name
12208 || filter->map[RMAP_IN].name)
12209 json_object_boolean_true_add(json_addr,
12210 "inboundPathPolicyConfig");
12211 if (filter->plist[FILTER_OUT].name
12212 || filter->dlist[FILTER_OUT].name
12213 || filter->aslist[FILTER_OUT].name
12214 || filter->map[RMAP_OUT].name || filter->usmap.name)
12215 json_object_boolean_true_add(
12216 json_addr, "outboundPathPolicyConfig");
12217
12218 /* prefix-list */
12219 if (filter->plist[FILTER_IN].name)
12220 json_object_string_add(json_addr,
12221 "incomingUpdatePrefixFilterList",
12222 filter->plist[FILTER_IN].name);
12223 if (filter->plist[FILTER_OUT].name)
12224 json_object_string_add(json_addr,
12225 "outgoingUpdatePrefixFilterList",
12226 filter->plist[FILTER_OUT].name);
12227
12228 /* distribute-list */
12229 if (filter->dlist[FILTER_IN].name)
12230 json_object_string_add(
12231 json_addr, "incomingUpdateNetworkFilterList",
12232 filter->dlist[FILTER_IN].name);
12233 if (filter->dlist[FILTER_OUT].name)
12234 json_object_string_add(
12235 json_addr, "outgoingUpdateNetworkFilterList",
12236 filter->dlist[FILTER_OUT].name);
12237
12238 /* filter-list. */
12239 if (filter->aslist[FILTER_IN].name)
12240 json_object_string_add(json_addr,
12241 "incomingUpdateAsPathFilterList",
12242 filter->aslist[FILTER_IN].name);
12243 if (filter->aslist[FILTER_OUT].name)
12244 json_object_string_add(json_addr,
12245 "outgoingUpdateAsPathFilterList",
12246 filter->aslist[FILTER_OUT].name);
12247
12248 /* route-map. */
12249 if (filter->map[RMAP_IN].name)
12250 json_object_string_add(
12251 json_addr, "routeMapForIncomingAdvertisements",
12252 filter->map[RMAP_IN].name);
12253 if (filter->map[RMAP_OUT].name)
12254 json_object_string_add(
12255 json_addr, "routeMapForOutgoingAdvertisements",
12256 filter->map[RMAP_OUT].name);
12257
9dac9fc8 12258 /* ebgp-requires-policy (inbound) */
1d3fdccf 12259 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12260 && !bgp_inbound_policy_exists(p, filter))
12261 json_object_string_add(
12262 json_addr, "inboundEbgpRequiresPolicy",
12263 "Inbound updates discarded due to missing policy");
12264
12265 /* ebgp-requires-policy (outbound) */
1d3fdccf 12266 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12267 && (!bgp_outbound_policy_exists(p, filter)))
12268 json_object_string_add(
12269 json_addr, "outboundEbgpRequiresPolicy",
12270 "Outbound updates discarded due to missing policy");
12271
d62a17ae 12272 /* unsuppress-map */
12273 if (filter->usmap.name)
12274 json_object_string_add(json_addr,
12275 "selectiveUnsuppressRouteMap",
12276 filter->usmap.name);
12277
fa36596c
MK
12278 /* advertise-map */
12279 if (filter->advmap.aname) {
12280 json_advmap = json_object_new_object();
12281 json_object_string_add(json_advmap, "condition",
12282 filter->advmap.condition
12283 ? "EXIST"
12284 : "NON_EXIST");
12285 json_object_string_add(json_advmap, "conditionMap",
12286 filter->advmap.cname);
12287 json_object_string_add(json_advmap, "advertiseMap",
12288 filter->advmap.aname);
12289 json_object_string_add(json_advmap, "advertiseStatus",
12290 filter->advmap.update_type
12291 == ADVERTISE
12292 ? "Advertise"
12293 : "Withdraw");
12294 json_object_object_add(json_addr, "advertiseMap",
12295 json_advmap);
12296 }
12297
d62a17ae 12298 /* Receive prefix count */
12299 json_object_int_add(json_addr, "acceptedPrefixCounter",
12300 p->pcount[afi][safi]);
50e05855
AD
12301 if (paf && PAF_SUBGRP(paf))
12302 json_object_int_add(json_addr, "sentPrefixCounter",
12303 (PAF_SUBGRP(paf))->scount);
d62a17ae 12304
fde246e8
DA
12305 /* Maximum prefix */
12306 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12307 json_object_int_add(json_addr, "prefixOutAllowedMax",
12308 p->pmax_out[afi][safi]);
12309
d62a17ae 12310 /* Maximum prefix */
12311 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12312 json_object_int_add(json_addr, "prefixAllowedMax",
12313 p->pmax[afi][safi]);
12314 if (CHECK_FLAG(p->af_flags[afi][safi],
12315 PEER_FLAG_MAX_PREFIX_WARNING))
12316 json_object_boolean_true_add(
12317 json_addr, "prefixAllowedMaxWarning");
12318 json_object_int_add(json_addr,
12319 "prefixAllowedWarningThresh",
12320 p->pmax_threshold[afi][safi]);
12321 if (p->pmax_restart[afi][safi])
12322 json_object_int_add(
12323 json_addr,
12324 "prefixAllowedRestartIntervalMsecs",
12325 p->pmax_restart[afi][safi] * 60000);
12326 }
2986cac2 12327 json_object_object_add(json_neigh,
36235319 12328 get_afi_safi_str(afi, safi, true),
d62a17ae 12329 json_addr);
12330
12331 } else {
12332 filter = &p->filter[afi][safi];
12333
12334 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12335 get_afi_safi_str(afi, safi, false));
d62a17ae 12336
12337 if (peer_group_active(p))
12338 vty_out(vty, " %s peer-group member\n",
12339 p->group->name);
12340
12341 paf = peer_af_find(p, afi, safi);
12342 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12343 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12344 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12345 vty_out(vty, " Packet Queue length %d\n",
12346 bpacket_queue_virtual_length(paf));
12347 } else {
12348 vty_out(vty, " Not part of any update group\n");
12349 }
12350 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12351 || CHECK_FLAG(p->af_cap[afi][safi],
12352 PEER_CAP_ORF_PREFIX_SM_RCV)
12353 || CHECK_FLAG(p->af_cap[afi][safi],
12354 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12355 || CHECK_FLAG(p->af_cap[afi][safi],
12356 PEER_CAP_ORF_PREFIX_RM_ADV)
12357 || CHECK_FLAG(p->af_cap[afi][safi],
12358 PEER_CAP_ORF_PREFIX_RM_RCV)
12359 || CHECK_FLAG(p->af_cap[afi][safi],
12360 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12361 vty_out(vty, " AF-dependant capabilities:\n");
12362
12363 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12364 || CHECK_FLAG(p->af_cap[afi][safi],
12365 PEER_CAP_ORF_PREFIX_SM_RCV)
12366 || CHECK_FLAG(p->af_cap[afi][safi],
12367 PEER_CAP_ORF_PREFIX_RM_ADV)
12368 || CHECK_FLAG(p->af_cap[afi][safi],
12369 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12370 vty_out(vty,
12371 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12372 ORF_TYPE_PREFIX);
12373 bgp_show_peer_afi_orf_cap(
12374 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12375 PEER_CAP_ORF_PREFIX_RM_ADV,
12376 PEER_CAP_ORF_PREFIX_SM_RCV,
12377 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12378 }
12379 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12380 || CHECK_FLAG(p->af_cap[afi][safi],
12381 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12382 || CHECK_FLAG(p->af_cap[afi][safi],
12383 PEER_CAP_ORF_PREFIX_RM_ADV)
12384 || CHECK_FLAG(p->af_cap[afi][safi],
12385 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12386 vty_out(vty,
12387 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12388 ORF_TYPE_PREFIX_OLD);
12389 bgp_show_peer_afi_orf_cap(
12390 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12391 PEER_CAP_ORF_PREFIX_RM_ADV,
12392 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12393 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12394 }
12395
772270f3
QY
12396 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12397 p->host, afi, safi);
d62a17ae 12398 orf_pfx_count = prefix_bgp_show_prefix_list(
12399 NULL, afi, orf_pfx_name, use_json);
12400
12401 if (CHECK_FLAG(p->af_sflags[afi][safi],
12402 PEER_STATUS_ORF_PREFIX_SEND)
12403 || orf_pfx_count) {
12404 vty_out(vty, " Outbound Route Filter (ORF):");
12405 if (CHECK_FLAG(p->af_sflags[afi][safi],
12406 PEER_STATUS_ORF_PREFIX_SEND))
12407 vty_out(vty, " sent;");
12408 if (orf_pfx_count)
12409 vty_out(vty, " received (%d entries)",
12410 orf_pfx_count);
12411 vty_out(vty, "\n");
12412 }
12413 if (CHECK_FLAG(p->af_sflags[afi][safi],
12414 PEER_STATUS_ORF_WAIT_REFRESH))
12415 vty_out(vty,
12416 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12417
12418 if (CHECK_FLAG(p->af_flags[afi][safi],
12419 PEER_FLAG_REFLECTOR_CLIENT))
12420 vty_out(vty, " Route-Reflector Client\n");
12421 if (CHECK_FLAG(p->af_flags[afi][safi],
12422 PEER_FLAG_RSERVER_CLIENT))
12423 vty_out(vty, " Route-Server Client\n");
12424 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12425 vty_out(vty,
12426 " Inbound soft reconfiguration allowed\n");
12427
12428 if (CHECK_FLAG(p->af_flags[afi][safi],
12429 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12430 vty_out(vty,
12431 " Private AS numbers (all) replaced in updates to this neighbor\n");
12432 else if (CHECK_FLAG(p->af_flags[afi][safi],
12433 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12434 vty_out(vty,
12435 " Private AS numbers replaced in updates to this neighbor\n");
12436 else if (CHECK_FLAG(p->af_flags[afi][safi],
12437 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12438 vty_out(vty,
12439 " Private AS numbers (all) removed in updates to this neighbor\n");
12440 else if (CHECK_FLAG(p->af_flags[afi][safi],
12441 PEER_FLAG_REMOVE_PRIVATE_AS))
12442 vty_out(vty,
12443 " Private AS numbers removed in updates to this neighbor\n");
12444
dcc68b5e
MS
12445 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12446 vty_out(vty, " %s\n",
12447 bgp_addpath_names(p->addpath_type[afi][safi])
12448 ->human_description);
d62a17ae 12449
12450 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12451 vty_out(vty,
12452 " Override ASNs in outbound updates if aspath equals remote-as\n");
12453
12454 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12455 || CHECK_FLAG(p->af_flags[afi][safi],
12456 PEER_FLAG_FORCE_NEXTHOP_SELF))
12457 vty_out(vty, " NEXT_HOP is always this router\n");
12458 if (CHECK_FLAG(p->af_flags[afi][safi],
12459 PEER_FLAG_AS_PATH_UNCHANGED))
12460 vty_out(vty,
12461 " AS_PATH is propagated unchanged to this neighbor\n");
12462 if (CHECK_FLAG(p->af_flags[afi][safi],
12463 PEER_FLAG_NEXTHOP_UNCHANGED))
12464 vty_out(vty,
12465 " NEXT_HOP is propagated unchanged to this neighbor\n");
12466 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12467 vty_out(vty,
12468 " MED is propagated unchanged to this neighbor\n");
12469 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12470 || CHECK_FLAG(p->af_flags[afi][safi],
12471 PEER_FLAG_SEND_EXT_COMMUNITY)
12472 || CHECK_FLAG(p->af_flags[afi][safi],
12473 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12474 vty_out(vty,
12475 " Community attribute sent to this neighbor");
12476 if (CHECK_FLAG(p->af_flags[afi][safi],
12477 PEER_FLAG_SEND_COMMUNITY)
12478 && CHECK_FLAG(p->af_flags[afi][safi],
12479 PEER_FLAG_SEND_EXT_COMMUNITY)
12480 && CHECK_FLAG(p->af_flags[afi][safi],
12481 PEER_FLAG_SEND_LARGE_COMMUNITY))
12482 vty_out(vty, "(all)\n");
12483 else if (CHECK_FLAG(p->af_flags[afi][safi],
12484 PEER_FLAG_SEND_LARGE_COMMUNITY))
12485 vty_out(vty, "(large)\n");
12486 else if (CHECK_FLAG(p->af_flags[afi][safi],
12487 PEER_FLAG_SEND_EXT_COMMUNITY))
12488 vty_out(vty, "(extended)\n");
12489 else
12490 vty_out(vty, "(standard)\n");
12491 }
12492 if (CHECK_FLAG(p->af_flags[afi][safi],
12493 PEER_FLAG_DEFAULT_ORIGINATE)) {
12494 vty_out(vty, " Default information originate,");
12495
12496 if (p->default_rmap[afi][safi].name)
12497 vty_out(vty, " default route-map %s%s,",
12498 p->default_rmap[afi][safi].map ? "*"
12499 : "",
12500 p->default_rmap[afi][safi].name);
12501 if (paf && PAF_SUBGRP(paf)
12502 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12503 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12504 vty_out(vty, " default sent\n");
12505 else
12506 vty_out(vty, " default not sent\n");
12507 }
12508
dff8f48d
MK
12509 /* advertise-vni-all */
12510 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12511 if (is_evpn_enabled())
dff8f48d
MK
12512 vty_out(vty, " advertise-all-vni\n");
12513 }
12514
d62a17ae 12515 if (filter->plist[FILTER_IN].name
12516 || filter->dlist[FILTER_IN].name
12517 || filter->aslist[FILTER_IN].name
12518 || filter->map[RMAP_IN].name)
12519 vty_out(vty, " Inbound path policy configured\n");
12520 if (filter->plist[FILTER_OUT].name
12521 || filter->dlist[FILTER_OUT].name
12522 || filter->aslist[FILTER_OUT].name
12523 || filter->map[RMAP_OUT].name || filter->usmap.name)
12524 vty_out(vty, " Outbound path policy configured\n");
12525
12526 /* prefix-list */
12527 if (filter->plist[FILTER_IN].name)
12528 vty_out(vty,
12529 " Incoming update prefix filter list is %s%s\n",
12530 filter->plist[FILTER_IN].plist ? "*" : "",
12531 filter->plist[FILTER_IN].name);
12532 if (filter->plist[FILTER_OUT].name)
12533 vty_out(vty,
12534 " Outgoing update prefix filter list is %s%s\n",
12535 filter->plist[FILTER_OUT].plist ? "*" : "",
12536 filter->plist[FILTER_OUT].name);
12537
12538 /* distribute-list */
12539 if (filter->dlist[FILTER_IN].name)
12540 vty_out(vty,
12541 " Incoming update network filter list is %s%s\n",
12542 filter->dlist[FILTER_IN].alist ? "*" : "",
12543 filter->dlist[FILTER_IN].name);
12544 if (filter->dlist[FILTER_OUT].name)
12545 vty_out(vty,
12546 " Outgoing update network filter list is %s%s\n",
12547 filter->dlist[FILTER_OUT].alist ? "*" : "",
12548 filter->dlist[FILTER_OUT].name);
12549
12550 /* filter-list. */
12551 if (filter->aslist[FILTER_IN].name)
12552 vty_out(vty,
12553 " Incoming update AS path filter list is %s%s\n",
12554 filter->aslist[FILTER_IN].aslist ? "*" : "",
12555 filter->aslist[FILTER_IN].name);
12556 if (filter->aslist[FILTER_OUT].name)
12557 vty_out(vty,
12558 " Outgoing update AS path filter list is %s%s\n",
12559 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12560 filter->aslist[FILTER_OUT].name);
12561
12562 /* route-map. */
12563 if (filter->map[RMAP_IN].name)
12564 vty_out(vty,
12565 " Route map for incoming advertisements is %s%s\n",
12566 filter->map[RMAP_IN].map ? "*" : "",
12567 filter->map[RMAP_IN].name);
12568 if (filter->map[RMAP_OUT].name)
12569 vty_out(vty,
12570 " Route map for outgoing advertisements is %s%s\n",
12571 filter->map[RMAP_OUT].map ? "*" : "",
12572 filter->map[RMAP_OUT].name);
12573
9dac9fc8 12574 /* ebgp-requires-policy (inbound) */
1d3fdccf 12575 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12576 && !bgp_inbound_policy_exists(p, filter))
12577 vty_out(vty,
12578 " Inbound updates discarded due to missing policy\n");
12579
12580 /* ebgp-requires-policy (outbound) */
1d3fdccf 12581 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12582 && !bgp_outbound_policy_exists(p, filter))
12583 vty_out(vty,
12584 " Outbound updates discarded due to missing policy\n");
12585
d62a17ae 12586 /* unsuppress-map */
12587 if (filter->usmap.name)
12588 vty_out(vty,
12589 " Route map for selective unsuppress is %s%s\n",
12590 filter->usmap.map ? "*" : "",
12591 filter->usmap.name);
12592
7f7940e6
MK
12593 /* advertise-map */
12594 if (filter->advmap.aname && filter->advmap.cname)
12595 vty_out(vty,
12596 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12597 filter->advmap.condition ? "EXIST"
12598 : "NON_EXIST",
12599 filter->advmap.cmap ? "*" : "",
12600 filter->advmap.cname,
12601 filter->advmap.amap ? "*" : "",
12602 filter->advmap.aname,
fa36596c 12603 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12604 ? "Advertise"
12605 : "Withdraw");
7f7940e6 12606
d62a17ae 12607 /* Receive prefix count */
6cde4b45 12608 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12609 p->pcount[afi][safi]);
d62a17ae 12610
fde246e8
DA
12611 /* maximum-prefix-out */
12612 if (CHECK_FLAG(p->af_flags[afi][safi],
12613 PEER_FLAG_MAX_PREFIX_OUT))
12614 vty_out(vty,
6cde4b45 12615 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12616 p->pmax_out[afi][safi]);
12617
d62a17ae 12618 /* Maximum prefix */
12619 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12620 vty_out(vty,
6cde4b45 12621 " Maximum prefixes allowed %u%s\n",
d62a17ae 12622 p->pmax[afi][safi],
12623 CHECK_FLAG(p->af_flags[afi][safi],
12624 PEER_FLAG_MAX_PREFIX_WARNING)
12625 ? " (warning-only)"
12626 : "");
12627 vty_out(vty, " Threshold for warning message %d%%",
12628 p->pmax_threshold[afi][safi]);
12629 if (p->pmax_restart[afi][safi])
12630 vty_out(vty, ", restart interval %d min",
12631 p->pmax_restart[afi][safi]);
12632 vty_out(vty, "\n");
12633 }
12634
12635 vty_out(vty, "\n");
12636 }
12637}
12638
9f049418 12639static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12640 json_object *json)
718e3744 12641{
d62a17ae 12642 struct bgp *bgp;
12643 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12644 char timebuf[BGP_UPTIME_LEN];
12645 char dn_flag[2];
d62a17ae 12646 afi_t afi;
12647 safi_t safi;
d7c0a89a
QY
12648 uint16_t i;
12649 uint8_t *msg;
d62a17ae 12650 json_object *json_neigh = NULL;
12651 time_t epoch_tbuf;
4ab46701 12652 uint32_t sync_tcp_mss;
718e3744 12653
d62a17ae 12654 bgp = p->bgp;
12655
12656 if (use_json)
12657 json_neigh = json_object_new_object();
12658
12659 memset(dn_flag, '\0', sizeof(dn_flag));
12660 if (!p->conf_if && peer_dynamic_neighbor(p))
12661 dn_flag[0] = '*';
12662
12663 if (!use_json) {
12664 if (p->conf_if) /* Configured interface name. */
12665 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12666 BGP_PEER_SU_UNSPEC(p)
12667 ? "None"
12668 : sockunion2str(&p->su, buf,
12669 SU_ADDRSTRLEN));
12670 else /* Configured IP address. */
12671 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12672 p->host);
12673 }
12674
12675 if (use_json) {
12676 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12677 json_object_string_add(json_neigh, "bgpNeighborAddr",
12678 "none");
12679 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12680 json_object_string_add(
12681 json_neigh, "bgpNeighborAddr",
12682 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12683
12684 json_object_int_add(json_neigh, "remoteAs", p->as);
12685
12686 if (p->change_local_as)
12687 json_object_int_add(json_neigh, "localAs",
12688 p->change_local_as);
12689 else
12690 json_object_int_add(json_neigh, "localAs", p->local_as);
12691
12692 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12693 json_object_boolean_true_add(json_neigh,
12694 "localAsNoPrepend");
12695
12696 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12697 json_object_boolean_true_add(json_neigh,
12698 "localAsReplaceAs");
12699 } else {
12700 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12701 || (p->as_type == AS_INTERNAL))
12702 vty_out(vty, "remote AS %u, ", p->as);
12703 else
12704 vty_out(vty, "remote AS Unspecified, ");
12705 vty_out(vty, "local AS %u%s%s, ",
12706 p->change_local_as ? p->change_local_as : p->local_as,
12707 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12708 ? " no-prepend"
12709 : "",
12710 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12711 ? " replace-as"
12712 : "");
12713 }
faa16034
DS
12714 /* peer type internal or confed-internal */
12715 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12716 if (use_json) {
12717 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12718 json_object_boolean_true_add(
12719 json_neigh, "nbrConfedInternalLink");
12720 else
12721 json_object_boolean_true_add(json_neigh,
12722 "nbrInternalLink");
12723 } else {
12724 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12725 vty_out(vty, "confed-internal link\n");
12726 else
12727 vty_out(vty, "internal link\n");
12728 }
faa16034
DS
12729 /* peer type external or confed-external */
12730 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12731 if (use_json) {
12732 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12733 json_object_boolean_true_add(
12734 json_neigh, "nbrConfedExternalLink");
12735 else
12736 json_object_boolean_true_add(json_neigh,
12737 "nbrExternalLink");
12738 } else {
12739 if (bgp_confederation_peers_check(bgp, p->as))
12740 vty_out(vty, "confed-external link\n");
12741 else
12742 vty_out(vty, "external link\n");
12743 }
faa16034
DS
12744 } else {
12745 if (use_json)
12746 json_object_boolean_true_add(json_neigh,
12747 "nbrUnspecifiedLink");
12748 else
12749 vty_out(vty, "unspecified link\n");
d62a17ae 12750 }
12751
12752 /* Description. */
12753 if (p->desc) {
12754 if (use_json)
12755 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12756 else
12757 vty_out(vty, " Description: %s\n", p->desc);
12758 }
12759
12760 if (p->hostname) {
12761 if (use_json) {
12762 if (p->hostname)
12763 json_object_string_add(json_neigh, "hostname",
12764 p->hostname);
12765
12766 if (p->domainname)
12767 json_object_string_add(json_neigh, "domainname",
12768 p->domainname);
12769 } else {
12770 if (p->domainname && (p->domainname[0] != '\0'))
12771 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12772 p->domainname);
12773 else
12774 vty_out(vty, "Hostname: %s\n", p->hostname);
12775 }
12776 }
12777
12778 /* Peer-group */
12779 if (p->group) {
12780 if (use_json) {
12781 json_object_string_add(json_neigh, "peerGroup",
12782 p->group->name);
12783
12784 if (dn_flag[0]) {
12785 struct prefix prefix, *range = NULL;
12786
0154d8ce
DS
12787 if (sockunion2hostprefix(&(p->su), &prefix))
12788 range = peer_group_lookup_dynamic_neighbor_range(
12789 p->group, &prefix);
d62a17ae 12790
12791 if (range) {
12792 prefix2str(range, buf1, sizeof(buf1));
12793 json_object_string_add(
12794 json_neigh,
12795 "peerSubnetRangeGroup", buf1);
12796 }
12797 }
12798 } else {
12799 vty_out(vty,
12800 " Member of peer-group %s for session parameters\n",
12801 p->group->name);
12802
12803 if (dn_flag[0]) {
12804 struct prefix prefix, *range = NULL;
12805
0154d8ce
DS
12806 if (sockunion2hostprefix(&(p->su), &prefix))
12807 range = peer_group_lookup_dynamic_neighbor_range(
12808 p->group, &prefix);
d62a17ae 12809
12810 if (range) {
d62a17ae 12811 vty_out(vty,
1b78780b
DL
12812 " Belongs to the subnet range group: %pFX\n",
12813 range);
d62a17ae 12814 }
12815 }
12816 }
12817 }
12818
12819 if (use_json) {
12820 /* Administrative shutdown. */
cb9196e7
DS
12821 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12822 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12823 json_object_boolean_true_add(json_neigh,
12824 "adminShutDown");
12825
12826 /* BGP Version. */
12827 json_object_int_add(json_neigh, "bgpVersion", 4);
12828 json_object_string_add(
12829 json_neigh, "remoteRouterId",
12830 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
12831 json_object_string_add(
12832 json_neigh, "localRouterId",
12833 inet_ntop(AF_INET, &bgp->router_id, buf1,
12834 sizeof(buf1)));
d62a17ae 12835
12836 /* Confederation */
12837 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12838 && bgp_confederation_peers_check(bgp, p->as))
12839 json_object_boolean_true_add(json_neigh,
12840 "nbrCommonAdmin");
12841
12842 /* Status. */
12843 json_object_string_add(
12844 json_neigh, "bgpState",
12845 lookup_msg(bgp_status_msg, p->status, NULL));
12846
12847 if (p->status == Established) {
12848 time_t uptime;
d62a17ae 12849
12850 uptime = bgp_clock();
12851 uptime -= p->uptime;
d62a17ae 12852 epoch_tbuf = time(NULL) - uptime;
12853
d3c7efed
DS
12854 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12855 uptime * 1000);
d62a17ae 12856 json_object_string_add(json_neigh, "bgpTimerUpString",
12857 peer_uptime(p->uptime, timebuf,
12858 BGP_UPTIME_LEN, 0,
12859 NULL));
12860 json_object_int_add(json_neigh,
12861 "bgpTimerUpEstablishedEpoch",
12862 epoch_tbuf);
12863 }
12864
12865 else if (p->status == Active) {
12866 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12867 json_object_string_add(json_neigh, "bgpStateIs",
12868 "passive");
12869 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12870 json_object_string_add(json_neigh, "bgpStateIs",
12871 "passiveNSF");
12872 }
12873
12874 /* read timer */
12875 time_t uptime;
a2700b50 12876 struct tm tm;
d62a17ae 12877
12878 uptime = bgp_clock();
12879 uptime -= p->readtime;
a2700b50
MS
12880 gmtime_r(&uptime, &tm);
12881
d62a17ae 12882 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12883 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12884 + (tm.tm_hour * 3600000));
d62a17ae 12885
12886 uptime = bgp_clock();
12887 uptime -= p->last_write;
a2700b50
MS
12888 gmtime_r(&uptime, &tm);
12889
d62a17ae 12890 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12891 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12892 + (tm.tm_hour * 3600000));
d62a17ae 12893
12894 uptime = bgp_clock();
12895 uptime -= p->update_time;
a2700b50
MS
12896 gmtime_r(&uptime, &tm);
12897
d62a17ae 12898 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12899 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12900 + (tm.tm_hour * 3600000));
d62a17ae 12901
12902 /* Configured timer values. */
12903 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12904 p->v_holdtime * 1000);
12905 json_object_int_add(json_neigh,
12906 "bgpTimerKeepAliveIntervalMsecs",
12907 p->v_keepalive * 1000);
d43114f3
DS
12908 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12909 json_object_int_add(json_neigh,
12910 "bgpTimerDelayOpenTimeMsecs",
12911 p->v_delayopen * 1000);
12912 }
12913
4ab46701
AR
12914 /* Configured and Synced tcp-mss value for peer */
12915 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12916 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12917 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12918 p->tcp_mss);
12919 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12920 sync_tcp_mss);
12921 }
12922
b90a8e13 12923 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12924 json_object_int_add(json_neigh,
12925 "bgpTimerConfiguredHoldTimeMsecs",
12926 p->holdtime * 1000);
12927 json_object_int_add(
12928 json_neigh,
12929 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12930 p->keepalive * 1000);
5d5393b9
DL
12931 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12932 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12933 json_object_int_add(json_neigh,
12934 "bgpTimerConfiguredHoldTimeMsecs",
12935 bgp->default_holdtime);
12936 json_object_int_add(
12937 json_neigh,
12938 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12939 bgp->default_keepalive);
d62a17ae 12940 }
12941 } else {
12942 /* Administrative shutdown. */
cb9196e7
DS
12943 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12944 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12945 vty_out(vty, " Administratively shut down\n");
12946
12947 /* BGP Version. */
12948 vty_out(vty, " BGP version 4");
0e38aeb4 12949 vty_out(vty, ", remote router ID %s",
d62a17ae 12950 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12951 vty_out(vty, ", local router ID %s\n",
12952 inet_ntop(AF_INET, &bgp->router_id, buf1,
12953 sizeof(buf1)));
d62a17ae 12954
12955 /* Confederation */
12956 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12957 && bgp_confederation_peers_check(bgp, p->as))
12958 vty_out(vty,
12959 " Neighbor under common administration\n");
12960
12961 /* Status. */
12962 vty_out(vty, " BGP state = %s",
12963 lookup_msg(bgp_status_msg, p->status, NULL));
12964
12965 if (p->status == Established)
12966 vty_out(vty, ", up for %8s",
12967 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12968 0, NULL));
12969
12970 else if (p->status == Active) {
12971 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12972 vty_out(vty, " (passive)");
12973 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12974 vty_out(vty, " (NSF passive)");
12975 }
12976 vty_out(vty, "\n");
12977
12978 /* read timer */
12979 vty_out(vty, " Last read %s",
12980 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12981 NULL));
12982 vty_out(vty, ", Last write %s\n",
12983 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12984 NULL));
12985
12986 /* Configured timer values. */
12987 vty_out(vty,
12988 " Hold time is %d, keepalive interval is %d seconds\n",
12989 p->v_holdtime, p->v_keepalive);
b90a8e13 12990 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12991 vty_out(vty, " Configured hold time is %d",
12992 p->holdtime);
12993 vty_out(vty, ", keepalive interval is %d seconds\n",
12994 p->keepalive);
5d5393b9
DL
12995 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12996 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12997 vty_out(vty, " Configured hold time is %d",
12998 bgp->default_holdtime);
12999 vty_out(vty, ", keepalive interval is %d seconds\n",
13000 bgp->default_keepalive);
d62a17ae 13001 }
d43114f3
DS
13002 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13003 vty_out(vty,
13004 " Configured DelayOpenTime is %d seconds\n",
13005 p->delayopen);
4ab46701
AR
13006
13007 /* Configured and synced tcp-mss value for peer */
13008 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13009 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13010 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13011 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13012 }
d62a17ae 13013 }
13014 /* Capability. */
13015 if (p->status == Established) {
13016 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
13017 || p->afc_recv[AFI_IP][SAFI_UNICAST]
13018 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
13019 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
13020 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
13021 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
13022 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
13023 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
13024 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
13025 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
13026 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
13027 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 13028 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
13029 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 13030 || p->afc_adv[AFI_IP][SAFI_ENCAP]
13031 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 13032 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
13033 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 13034 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
13035 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
13036 if (use_json) {
13037 json_object *json_cap = NULL;
13038
13039 json_cap = json_object_new_object();
13040
13041 /* AS4 */
13042 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13043 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13044 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
13045 && CHECK_FLAG(p->cap,
13046 PEER_CAP_AS4_RCV))
13047 json_object_string_add(
13048 json_cap, "4byteAs",
13049 "advertisedAndReceived");
13050 else if (CHECK_FLAG(p->cap,
13051 PEER_CAP_AS4_ADV))
13052 json_object_string_add(
13053 json_cap, "4byteAs",
13054 "advertised");
13055 else if (CHECK_FLAG(p->cap,
13056 PEER_CAP_AS4_RCV))
13057 json_object_string_add(
13058 json_cap, "4byteAs",
13059 "received");
13060 }
13061
ef56aee4
DA
13062 /* Extended Message Support */
13063 if (CHECK_FLAG(p->cap,
13064 PEER_CAP_EXTENDED_MESSAGE_ADV)
13065 && CHECK_FLAG(
13066 p->cap,
13067 PEER_CAP_EXTENDED_MESSAGE_RCV))
13068 json_object_string_add(
13069 json_cap, "extendedMessage",
13070 "advertisedAndReceived");
13071 else if (CHECK_FLAG(
13072 p->cap,
13073 PEER_CAP_EXTENDED_MESSAGE_ADV))
13074 json_object_string_add(
13075 json_cap, "extendedMessage",
13076 "advertised");
13077 else if (CHECK_FLAG(
13078 p->cap,
13079 PEER_CAP_EXTENDED_MESSAGE_RCV))
13080 json_object_string_add(
13081 json_cap, "extendedMessage",
13082 "received");
13083
d62a17ae 13084 /* AddPath */
13085 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13086 || CHECK_FLAG(p->cap,
13087 PEER_CAP_ADDPATH_ADV)) {
13088 json_object *json_add = NULL;
13089 const char *print_store;
13090
13091 json_add = json_object_new_object();
13092
05c7a1cc
QY
13093 FOREACH_AFI_SAFI (afi, safi) {
13094 json_object *json_sub = NULL;
13095 json_sub =
13096 json_object_new_object();
5cb5f4d0
DD
13097 print_store = get_afi_safi_str(
13098 afi, safi, true);
d62a17ae 13099
05c7a1cc
QY
13100 if (CHECK_FLAG(
13101 p->af_cap[afi]
13102 [safi],
13103 PEER_CAP_ADDPATH_AF_TX_ADV)
13104 || CHECK_FLAG(
13105 p->af_cap[afi]
13106 [safi],
13107 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 13108 if (CHECK_FLAG(
13109 p->af_cap
13110 [afi]
13111 [safi],
13112 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 13113 && CHECK_FLAG(
d62a17ae 13114 p->af_cap
13115 [afi]
13116 [safi],
05c7a1cc
QY
13117 PEER_CAP_ADDPATH_AF_TX_RCV))
13118 json_object_boolean_true_add(
13119 json_sub,
13120 "txAdvertisedAndReceived");
13121 else if (
13122 CHECK_FLAG(
13123 p->af_cap
13124 [afi]
13125 [safi],
13126 PEER_CAP_ADDPATH_AF_TX_ADV))
13127 json_object_boolean_true_add(
13128 json_sub,
13129 "txAdvertised");
13130 else if (
13131 CHECK_FLAG(
13132 p->af_cap
13133 [afi]
13134 [safi],
13135 PEER_CAP_ADDPATH_AF_TX_RCV))
13136 json_object_boolean_true_add(
13137 json_sub,
13138 "txReceived");
13139 }
d62a17ae 13140
05c7a1cc
QY
13141 if (CHECK_FLAG(
13142 p->af_cap[afi]
13143 [safi],
13144 PEER_CAP_ADDPATH_AF_RX_ADV)
13145 || CHECK_FLAG(
13146 p->af_cap[afi]
13147 [safi],
13148 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 13149 if (CHECK_FLAG(
13150 p->af_cap
13151 [afi]
13152 [safi],
13153 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 13154 && CHECK_FLAG(
d62a17ae 13155 p->af_cap
13156 [afi]
13157 [safi],
13158 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
13159 json_object_boolean_true_add(
13160 json_sub,
13161 "rxAdvertisedAndReceived");
13162 else if (
13163 CHECK_FLAG(
13164 p->af_cap
13165 [afi]
13166 [safi],
13167 PEER_CAP_ADDPATH_AF_RX_ADV))
13168 json_object_boolean_true_add(
13169 json_sub,
13170 "rxAdvertised");
13171 else if (
13172 CHECK_FLAG(
13173 p->af_cap
13174 [afi]
13175 [safi],
13176 PEER_CAP_ADDPATH_AF_RX_RCV))
13177 json_object_boolean_true_add(
13178 json_sub,
13179 "rxReceived");
d62a17ae 13180 }
13181
05c7a1cc
QY
13182 if (CHECK_FLAG(
13183 p->af_cap[afi]
13184 [safi],
13185 PEER_CAP_ADDPATH_AF_TX_ADV)
13186 || CHECK_FLAG(
13187 p->af_cap[afi]
13188 [safi],
13189 PEER_CAP_ADDPATH_AF_TX_RCV)
13190 || CHECK_FLAG(
13191 p->af_cap[afi]
13192 [safi],
13193 PEER_CAP_ADDPATH_AF_RX_ADV)
13194 || CHECK_FLAG(
13195 p->af_cap[afi]
13196 [safi],
13197 PEER_CAP_ADDPATH_AF_RX_RCV))
13198 json_object_object_add(
13199 json_add,
13200 print_store,
13201 json_sub);
13202 else
13203 json_object_free(
13204 json_sub);
13205 }
13206
d62a17ae 13207 json_object_object_add(
13208 json_cap, "addPath", json_add);
13209 }
13210
13211 /* Dynamic */
13212 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13213 || CHECK_FLAG(p->cap,
13214 PEER_CAP_DYNAMIC_ADV)) {
13215 if (CHECK_FLAG(p->cap,
13216 PEER_CAP_DYNAMIC_ADV)
13217 && CHECK_FLAG(p->cap,
13218 PEER_CAP_DYNAMIC_RCV))
13219 json_object_string_add(
13220 json_cap, "dynamic",
13221 "advertisedAndReceived");
13222 else if (CHECK_FLAG(
13223 p->cap,
13224 PEER_CAP_DYNAMIC_ADV))
13225 json_object_string_add(
13226 json_cap, "dynamic",
13227 "advertised");
13228 else if (CHECK_FLAG(
13229 p->cap,
13230 PEER_CAP_DYNAMIC_RCV))
13231 json_object_string_add(
13232 json_cap, "dynamic",
13233 "received");
13234 }
13235
13236 /* Extended nexthop */
13237 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13238 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13239 json_object *json_nxt = NULL;
13240 const char *print_store;
13241
13242
13243 if (CHECK_FLAG(p->cap,
13244 PEER_CAP_ENHE_ADV)
13245 && CHECK_FLAG(p->cap,
13246 PEER_CAP_ENHE_RCV))
13247 json_object_string_add(
13248 json_cap,
13249 "extendedNexthop",
13250 "advertisedAndReceived");
13251 else if (CHECK_FLAG(p->cap,
13252 PEER_CAP_ENHE_ADV))
13253 json_object_string_add(
13254 json_cap,
13255 "extendedNexthop",
13256 "advertised");
13257 else if (CHECK_FLAG(p->cap,
13258 PEER_CAP_ENHE_RCV))
13259 json_object_string_add(
13260 json_cap,
13261 "extendedNexthop",
13262 "received");
13263
13264 if (CHECK_FLAG(p->cap,
13265 PEER_CAP_ENHE_RCV)) {
13266 json_nxt =
13267 json_object_new_object();
13268
13269 for (safi = SAFI_UNICAST;
13270 safi < SAFI_MAX; safi++) {
13271 if (CHECK_FLAG(
13272 p->af_cap
13273 [AFI_IP]
13274 [safi],
13275 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 13276 print_store = get_afi_safi_str(
d62a17ae 13277 AFI_IP,
5cb5f4d0 13278 safi, true);
d62a17ae 13279 json_object_string_add(
13280 json_nxt,
13281 print_store,
54f29523 13282 "recieved"); /* misspelled for compatibility */
d62a17ae 13283 }
13284 }
13285 json_object_object_add(
13286 json_cap,
13287 "extendedNexthopFamililesByPeer",
13288 json_nxt);
13289 }
13290 }
13291
13292 /* Route Refresh */
13293 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13294 || CHECK_FLAG(p->cap,
13295 PEER_CAP_REFRESH_NEW_RCV)
13296 || CHECK_FLAG(p->cap,
13297 PEER_CAP_REFRESH_OLD_RCV)) {
13298 if (CHECK_FLAG(p->cap,
13299 PEER_CAP_REFRESH_ADV)
13300 && (CHECK_FLAG(
13301 p->cap,
13302 PEER_CAP_REFRESH_NEW_RCV)
13303 || CHECK_FLAG(
13304 p->cap,
13305 PEER_CAP_REFRESH_OLD_RCV))) {
13306 if (CHECK_FLAG(
13307 p->cap,
13308 PEER_CAP_REFRESH_OLD_RCV)
13309 && CHECK_FLAG(
13310 p->cap,
13311 PEER_CAP_REFRESH_NEW_RCV))
13312 json_object_string_add(
13313 json_cap,
13314 "routeRefresh",
13315 "advertisedAndReceivedOldNew");
13316 else {
13317 if (CHECK_FLAG(
13318 p->cap,
13319 PEER_CAP_REFRESH_OLD_RCV))
13320 json_object_string_add(
13321 json_cap,
13322 "routeRefresh",
13323 "advertisedAndReceivedOld");
13324 else
13325 json_object_string_add(
13326 json_cap,
13327 "routeRefresh",
13328 "advertisedAndReceivedNew");
13329 }
13330 } else if (
13331 CHECK_FLAG(
13332 p->cap,
13333 PEER_CAP_REFRESH_ADV))
13334 json_object_string_add(
13335 json_cap,
13336 "routeRefresh",
13337 "advertised");
13338 else if (
13339 CHECK_FLAG(
13340 p->cap,
13341 PEER_CAP_REFRESH_NEW_RCV)
13342 || CHECK_FLAG(
13343 p->cap,
13344 PEER_CAP_REFRESH_OLD_RCV))
13345 json_object_string_add(
13346 json_cap,
13347 "routeRefresh",
13348 "received");
13349 }
13350
9af52ccf
DA
13351 /* Enhanced Route Refresh */
13352 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13353 || CHECK_FLAG(p->cap,
13354 PEER_CAP_ENHANCED_RR_RCV)) {
13355 if (CHECK_FLAG(p->cap,
13356 PEER_CAP_ENHANCED_RR_ADV)
13357 && CHECK_FLAG(
13358 p->cap,
13359 PEER_CAP_ENHANCED_RR_RCV))
13360 json_object_string_add(
13361 json_cap,
13362 "enhancedRouteRefresh",
13363 "advertisedAndReceived");
13364 else if (
13365 CHECK_FLAG(
13366 p->cap,
13367 PEER_CAP_ENHANCED_RR_ADV))
13368 json_object_string_add(
13369 json_cap,
13370 "enhancedRouteRefresh",
13371 "advertised");
13372 else if (
13373 CHECK_FLAG(
13374 p->cap,
13375 PEER_CAP_ENHANCED_RR_RCV))
13376 json_object_string_add(
13377 json_cap,
13378 "enhancedRouteRefresh",
13379 "received");
13380 }
13381
d62a17ae 13382 /* Multiprotocol Extensions */
13383 json_object *json_multi = NULL;
13384 json_multi = json_object_new_object();
13385
05c7a1cc
QY
13386 FOREACH_AFI_SAFI (afi, safi) {
13387 if (p->afc_adv[afi][safi]
13388 || p->afc_recv[afi][safi]) {
13389 json_object *json_exten = NULL;
13390 json_exten =
13391 json_object_new_object();
13392
d62a17ae 13393 if (p->afc_adv[afi][safi]
05c7a1cc
QY
13394 && p->afc_recv[afi][safi])
13395 json_object_boolean_true_add(
13396 json_exten,
13397 "advertisedAndReceived");
13398 else if (p->afc_adv[afi][safi])
13399 json_object_boolean_true_add(
13400 json_exten,
13401 "advertised");
13402 else if (p->afc_recv[afi][safi])
13403 json_object_boolean_true_add(
13404 json_exten,
13405 "received");
d62a17ae 13406
05c7a1cc
QY
13407 json_object_object_add(
13408 json_multi,
5cb5f4d0
DD
13409 get_afi_safi_str(afi,
13410 safi,
13411 true),
05c7a1cc 13412 json_exten);
d62a17ae 13413 }
13414 }
13415 json_object_object_add(
13416 json_cap, "multiprotocolExtensions",
13417 json_multi);
13418
d77114b7 13419 /* Hostname capabilities */
60466a63 13420 json_object *json_hname = NULL;
d77114b7
MK
13421
13422 json_hname = json_object_new_object();
13423
13424 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13425 json_object_string_add(
60466a63
QY
13426 json_hname, "advHostName",
13427 bgp->peer_self->hostname
13428 ? bgp->peer_self
13429 ->hostname
d77114b7
MK
13430 : "n/a");
13431 json_object_string_add(
60466a63
QY
13432 json_hname, "advDomainName",
13433 bgp->peer_self->domainname
13434 ? bgp->peer_self
13435 ->domainname
d77114b7
MK
13436 : "n/a");
13437 }
13438
13439
13440 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13441 json_object_string_add(
60466a63
QY
13442 json_hname, "rcvHostName",
13443 p->hostname ? p->hostname
13444 : "n/a");
d77114b7 13445 json_object_string_add(
60466a63
QY
13446 json_hname, "rcvDomainName",
13447 p->domainname ? p->domainname
13448 : "n/a");
d77114b7
MK
13449 }
13450
60466a63 13451 json_object_object_add(json_cap, "hostName",
d77114b7
MK
13452 json_hname);
13453
d62a17ae 13454 /* Gracefull Restart */
13455 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13456 || CHECK_FLAG(p->cap,
13457 PEER_CAP_RESTART_ADV)) {
13458 if (CHECK_FLAG(p->cap,
13459 PEER_CAP_RESTART_ADV)
13460 && CHECK_FLAG(p->cap,
13461 PEER_CAP_RESTART_RCV))
13462 json_object_string_add(
13463 json_cap,
13464 "gracefulRestart",
13465 "advertisedAndReceived");
13466 else if (CHECK_FLAG(
13467 p->cap,
13468 PEER_CAP_RESTART_ADV))
13469 json_object_string_add(
13470 json_cap,
13471 "gracefulRestartCapability",
13472 "advertised");
13473 else if (CHECK_FLAG(
13474 p->cap,
13475 PEER_CAP_RESTART_RCV))
13476 json_object_string_add(
13477 json_cap,
13478 "gracefulRestartCapability",
13479 "received");
13480
13481 if (CHECK_FLAG(p->cap,
13482 PEER_CAP_RESTART_RCV)) {
13483 int restart_af_count = 0;
13484 json_object *json_restart =
13485 NULL;
13486 json_restart =
13487 json_object_new_object();
13488
13489 json_object_int_add(
13490 json_cap,
13491 "gracefulRestartRemoteTimerMsecs",
13492 p->v_gr_restart * 1000);
13493
05c7a1cc
QY
13494 FOREACH_AFI_SAFI (afi, safi) {
13495 if (CHECK_FLAG(
13496 p->af_cap
13497 [afi]
13498 [safi],
13499 PEER_CAP_RESTART_AF_RCV)) {
13500 json_object *
13501 json_sub =
13502 NULL;
13503 json_sub =
13504 json_object_new_object();
13505
d62a17ae 13506 if (CHECK_FLAG(
13507 p->af_cap
13508 [afi]
13509 [safi],
05c7a1cc
QY
13510 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13511 json_object_boolean_true_add(
13512 json_sub,
13513 "preserved");
13514 restart_af_count++;
13515 json_object_object_add(
13516 json_restart,
5cb5f4d0 13517 get_afi_safi_str(
05c7a1cc 13518 afi,
5cb5f4d0
DD
13519 safi,
13520 true),
05c7a1cc 13521 json_sub);
d62a17ae 13522 }
13523 }
13524 if (!restart_af_count) {
13525 json_object_string_add(
13526 json_cap,
13527 "addressFamiliesByPeer",
13528 "none");
13529 json_object_free(
13530 json_restart);
13531 } else
13532 json_object_object_add(
13533 json_cap,
13534 "addressFamiliesByPeer",
13535 json_restart);
13536 }
13537 }
13538 json_object_object_add(json_neigh,
13539 "neighborCapabilities",
13540 json_cap);
13541 } else {
13542 vty_out(vty, " Neighbor capabilities:\n");
13543
13544 /* AS4 */
13545 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13546 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13547 vty_out(vty, " 4 Byte AS:");
13548 if (CHECK_FLAG(p->cap,
13549 PEER_CAP_AS4_ADV))
13550 vty_out(vty, " advertised");
13551 if (CHECK_FLAG(p->cap,
13552 PEER_CAP_AS4_RCV))
13553 vty_out(vty, " %sreceived",
13554 CHECK_FLAG(
13555 p->cap,
13556 PEER_CAP_AS4_ADV)
13557 ? "and "
13558 : "");
13559 vty_out(vty, "\n");
13560 }
13561
ef56aee4
DA
13562 /* Extended Message Support */
13563 if (CHECK_FLAG(p->cap,
13564 PEER_CAP_EXTENDED_MESSAGE_RCV)
13565 || CHECK_FLAG(
13566 p->cap,
13567 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13568 vty_out(vty, " Extended Message:");
13569 if (CHECK_FLAG(
13570 p->cap,
13571 PEER_CAP_EXTENDED_MESSAGE_ADV))
13572 vty_out(vty, " advertised");
13573 if (CHECK_FLAG(
13574 p->cap,
13575 PEER_CAP_EXTENDED_MESSAGE_RCV))
13576 vty_out(vty, " %sreceived",
13577 CHECK_FLAG(
13578 p->cap,
13579 PEER_CAP_EXTENDED_MESSAGE_ADV)
13580 ? "and "
13581 : "");
13582 vty_out(vty, "\n");
13583 }
13584
d62a17ae 13585 /* AddPath */
13586 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13587 || CHECK_FLAG(p->cap,
13588 PEER_CAP_ADDPATH_ADV)) {
13589 vty_out(vty, " AddPath:\n");
13590
05c7a1cc
QY
13591 FOREACH_AFI_SAFI (afi, safi) {
13592 if (CHECK_FLAG(
13593 p->af_cap[afi]
13594 [safi],
13595 PEER_CAP_ADDPATH_AF_TX_ADV)
13596 || CHECK_FLAG(
13597 p->af_cap[afi]
13598 [safi],
13599 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13600 vty_out(vty,
13601 " %s: TX ",
5cb5f4d0 13602 get_afi_safi_str(
05c7a1cc 13603 afi,
5cb5f4d0
DD
13604 safi,
13605 false));
05c7a1cc 13606
d62a17ae 13607 if (CHECK_FLAG(
13608 p->af_cap
13609 [afi]
13610 [safi],
05c7a1cc 13611 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 13612 vty_out(vty,
05c7a1cc 13613 "advertised %s",
5cb5f4d0 13614 get_afi_safi_str(
d62a17ae 13615 afi,
5cb5f4d0
DD
13616 safi,
13617 false));
d62a17ae 13618
05c7a1cc
QY
13619 if (CHECK_FLAG(
13620 p->af_cap
13621 [afi]
13622 [safi],
13623 PEER_CAP_ADDPATH_AF_TX_RCV))
13624 vty_out(vty,
13625 "%sreceived",
13626 CHECK_FLAG(
13627 p->af_cap
13628 [afi]
13629 [safi],
13630 PEER_CAP_ADDPATH_AF_TX_ADV)
13631 ? " and "
13632 : "");
d62a17ae 13633
05c7a1cc
QY
13634 vty_out(vty, "\n");
13635 }
d62a17ae 13636
05c7a1cc
QY
13637 if (CHECK_FLAG(
13638 p->af_cap[afi]
13639 [safi],
13640 PEER_CAP_ADDPATH_AF_RX_ADV)
13641 || CHECK_FLAG(
13642 p->af_cap[afi]
13643 [safi],
13644 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13645 vty_out(vty,
13646 " %s: RX ",
5cb5f4d0 13647 get_afi_safi_str(
05c7a1cc 13648 afi,
5cb5f4d0
DD
13649 safi,
13650 false));
d62a17ae 13651
13652 if (CHECK_FLAG(
13653 p->af_cap
13654 [afi]
13655 [safi],
05c7a1cc 13656 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 13657 vty_out(vty,
05c7a1cc 13658 "advertised %s",
5cb5f4d0 13659 get_afi_safi_str(
d62a17ae 13660 afi,
5cb5f4d0
DD
13661 safi,
13662 false));
d62a17ae 13663
05c7a1cc
QY
13664 if (CHECK_FLAG(
13665 p->af_cap
13666 [afi]
13667 [safi],
13668 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 13669 vty_out(vty,
05c7a1cc
QY
13670 "%sreceived",
13671 CHECK_FLAG(
13672 p->af_cap
13673 [afi]
13674 [safi],
13675 PEER_CAP_ADDPATH_AF_RX_ADV)
13676 ? " and "
13677 : "");
13678
13679 vty_out(vty, "\n");
d62a17ae 13680 }
05c7a1cc 13681 }
d62a17ae 13682 }
13683
13684 /* Dynamic */
13685 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13686 || CHECK_FLAG(p->cap,
13687 PEER_CAP_DYNAMIC_ADV)) {
13688 vty_out(vty, " Dynamic:");
13689 if (CHECK_FLAG(p->cap,
13690 PEER_CAP_DYNAMIC_ADV))
13691 vty_out(vty, " advertised");
13692 if (CHECK_FLAG(p->cap,
13693 PEER_CAP_DYNAMIC_RCV))
13694 vty_out(vty, " %sreceived",
13695 CHECK_FLAG(
13696 p->cap,
13697 PEER_CAP_DYNAMIC_ADV)
13698 ? "and "
13699 : "");
13700 vty_out(vty, "\n");
13701 }
13702
13703 /* Extended nexthop */
13704 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13705 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13706 vty_out(vty, " Extended nexthop:");
13707 if (CHECK_FLAG(p->cap,
13708 PEER_CAP_ENHE_ADV))
13709 vty_out(vty, " advertised");
13710 if (CHECK_FLAG(p->cap,
13711 PEER_CAP_ENHE_RCV))
13712 vty_out(vty, " %sreceived",
13713 CHECK_FLAG(
13714 p->cap,
13715 PEER_CAP_ENHE_ADV)
13716 ? "and "
13717 : "");
13718 vty_out(vty, "\n");
13719
13720 if (CHECK_FLAG(p->cap,
13721 PEER_CAP_ENHE_RCV)) {
13722 vty_out(vty,
13723 " Address families by peer:\n ");
13724 for (safi = SAFI_UNICAST;
13725 safi < SAFI_MAX; safi++)
13726 if (CHECK_FLAG(
13727 p->af_cap
13728 [AFI_IP]
13729 [safi],
13730 PEER_CAP_ENHE_AF_RCV))
13731 vty_out(vty,
13732 " %s\n",
5cb5f4d0 13733 get_afi_safi_str(
d62a17ae 13734 AFI_IP,
5cb5f4d0
DD
13735 safi,
13736 false));
d62a17ae 13737 }
13738 }
13739
13740 /* Route Refresh */
13741 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13742 || CHECK_FLAG(p->cap,
13743 PEER_CAP_REFRESH_NEW_RCV)
13744 || CHECK_FLAG(p->cap,
13745 PEER_CAP_REFRESH_OLD_RCV)) {
13746 vty_out(vty, " Route refresh:");
13747 if (CHECK_FLAG(p->cap,
13748 PEER_CAP_REFRESH_ADV))
13749 vty_out(vty, " advertised");
13750 if (CHECK_FLAG(p->cap,
13751 PEER_CAP_REFRESH_NEW_RCV)
13752 || CHECK_FLAG(
13753 p->cap,
13754 PEER_CAP_REFRESH_OLD_RCV))
13755 vty_out(vty, " %sreceived(%s)",
13756 CHECK_FLAG(
13757 p->cap,
13758 PEER_CAP_REFRESH_ADV)
13759 ? "and "
13760 : "",
13761 (CHECK_FLAG(
13762 p->cap,
13763 PEER_CAP_REFRESH_OLD_RCV)
13764 && CHECK_FLAG(
13765 p->cap,
13766 PEER_CAP_REFRESH_NEW_RCV))
13767 ? "old & new"
13768 : CHECK_FLAG(
13769 p->cap,
13770 PEER_CAP_REFRESH_OLD_RCV)
13771 ? "old"
13772 : "new");
13773
13774 vty_out(vty, "\n");
13775 }
13776
9af52ccf
DA
13777 /* Enhanced Route Refresh */
13778 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13779 || CHECK_FLAG(p->cap,
13780 PEER_CAP_ENHANCED_RR_RCV)) {
13781 vty_out(vty,
13782 " Enhanced Route Refresh:");
13783 if (CHECK_FLAG(
13784 p->cap,
13785 PEER_CAP_ENHANCED_RR_ADV))
13786 vty_out(vty, " advertised");
13787 if (CHECK_FLAG(
13788 p->cap,
13789 PEER_CAP_ENHANCED_RR_RCV))
13790 vty_out(vty, " %sreceived",
13791 CHECK_FLAG(
13792 p->cap,
13793 PEER_CAP_REFRESH_ADV)
13794 ? "and "
13795 : "");
13796 vty_out(vty, "\n");
13797 }
13798
d62a17ae 13799 /* Multiprotocol Extensions */
05c7a1cc
QY
13800 FOREACH_AFI_SAFI (afi, safi)
13801 if (p->afc_adv[afi][safi]
13802 || p->afc_recv[afi][safi]) {
13803 vty_out(vty,
13804 " Address Family %s:",
5cb5f4d0
DD
13805 get_afi_safi_str(
13806 afi,
13807 safi,
13808 false));
05c7a1cc 13809 if (p->afc_adv[afi][safi])
d62a17ae 13810 vty_out(vty,
05c7a1cc
QY
13811 " advertised");
13812 if (p->afc_recv[afi][safi])
13813 vty_out(vty,
13814 " %sreceived",
13815 p->afc_adv[afi]
13816 [safi]
13817 ? "and "
13818 : "");
13819 vty_out(vty, "\n");
13820 }
d62a17ae 13821
13822 /* Hostname capability */
60466a63 13823 vty_out(vty, " Hostname Capability:");
d77114b7
MK
13824
13825 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
13826 vty_out(vty,
13827 " advertised (name: %s,domain name: %s)",
60466a63
QY
13828 bgp->peer_self->hostname
13829 ? bgp->peer_self
13830 ->hostname
d77114b7 13831 : "n/a",
60466a63
QY
13832 bgp->peer_self->domainname
13833 ? bgp->peer_self
13834 ->domainname
d77114b7
MK
13835 : "n/a");
13836 } else {
13837 vty_out(vty, " not advertised");
d62a17ae 13838 }
13839
d77114b7 13840 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
13841 vty_out(vty,
13842 " received (name: %s,domain name: %s)",
60466a63
QY
13843 p->hostname ? p->hostname
13844 : "n/a",
13845 p->domainname ? p->domainname
13846 : "n/a");
d77114b7
MK
13847 } else {
13848 vty_out(vty, " not received");
13849 }
13850
13851 vty_out(vty, "\n");
13852
61bfbd51 13853 /* Graceful Restart */
d62a17ae 13854 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13855 || CHECK_FLAG(p->cap,
13856 PEER_CAP_RESTART_ADV)) {
13857 vty_out(vty,
61bfbd51 13858 " Graceful Restart Capability:");
d62a17ae 13859 if (CHECK_FLAG(p->cap,
13860 PEER_CAP_RESTART_ADV))
13861 vty_out(vty, " advertised");
13862 if (CHECK_FLAG(p->cap,
13863 PEER_CAP_RESTART_RCV))
13864 vty_out(vty, " %sreceived",
13865 CHECK_FLAG(
13866 p->cap,
13867 PEER_CAP_RESTART_ADV)
13868 ? "and "
13869 : "");
13870 vty_out(vty, "\n");
13871
13872 if (CHECK_FLAG(p->cap,
13873 PEER_CAP_RESTART_RCV)) {
13874 int restart_af_count = 0;
13875
13876 vty_out(vty,
13877 " Remote Restart timer is %d seconds\n",
13878 p->v_gr_restart);
13879 vty_out(vty,
13880 " Address families by peer:\n ");
13881
05c7a1cc
QY
13882 FOREACH_AFI_SAFI (afi, safi)
13883 if (CHECK_FLAG(
13884 p->af_cap
13885 [afi]
13886 [safi],
13887 PEER_CAP_RESTART_AF_RCV)) {
13888 vty_out(vty,
13889 "%s%s(%s)",
13890 restart_af_count
13891 ? ", "
13892 : "",
5cb5f4d0 13893 get_afi_safi_str(
05c7a1cc 13894 afi,
5cb5f4d0
DD
13895 safi,
13896 false),
05c7a1cc
QY
13897 CHECK_FLAG(
13898 p->af_cap
13899 [afi]
13900 [safi],
13901 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13902 ? "preserved"
13903 : "not preserved");
13904 restart_af_count++;
13905 }
d62a17ae 13906 if (!restart_af_count)
13907 vty_out(vty, "none");
13908 vty_out(vty, "\n");
13909 }
2986cac2 13910 } /* Gracefull Restart */
d62a17ae 13911 }
13912 }
13913 }
13914
13915 /* graceful restart information */
d62a17ae 13916 json_object *json_grace = NULL;
13917 json_object *json_grace_send = NULL;
13918 json_object *json_grace_recv = NULL;
13919 int eor_send_af_count = 0;
13920 int eor_receive_af_count = 0;
13921
13922 if (use_json) {
13923 json_grace = json_object_new_object();
13924 json_grace_send = json_object_new_object();
13925 json_grace_recv = json_object_new_object();
13926
36235319
QY
13927 if ((p->status == Established)
13928 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
13929 FOREACH_AFI_SAFI (afi, safi) {
13930 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 13931 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
13932 json_object_boolean_true_add(
13933 json_grace_send,
5cb5f4d0
DD
13934 get_afi_safi_str(afi,
13935 safi,
13936 true));
05c7a1cc 13937 eor_send_af_count++;
d62a17ae 13938 }
13939 }
05c7a1cc
QY
13940 FOREACH_AFI_SAFI (afi, safi) {
13941 if (CHECK_FLAG(
36235319
QY
13942 p->af_sflags[afi][safi],
13943 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
13944 json_object_boolean_true_add(
13945 json_grace_recv,
5cb5f4d0
DD
13946 get_afi_safi_str(afi,
13947 safi,
13948 true));
05c7a1cc 13949 eor_receive_af_count++;
d62a17ae 13950 }
13951 }
13952 }
36235319
QY
13953 json_object_object_add(json_grace, "endOfRibSend",
13954 json_grace_send);
13955 json_object_object_add(json_grace, "endOfRibRecv",
13956 json_grace_recv);
d62a17ae 13957
d62a17ae 13958
13959 if (p->t_gr_restart)
13960 json_object_int_add(json_grace,
13961 "gracefulRestartTimerMsecs",
13962 thread_timer_remain_second(
13963 p->t_gr_restart)
13964 * 1000);
13965
13966 if (p->t_gr_stale)
13967 json_object_int_add(
13968 json_grace,
13969 "gracefulStalepathTimerMsecs",
13970 thread_timer_remain_second(
13971 p->t_gr_stale)
13972 * 1000);
2986cac2 13973 /* more gr info in new format */
13974 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 13975 json_grace);
d62a17ae 13976 json_object_object_add(
13977 json_neigh, "gracefulRestartInfo", json_grace);
13978 } else {
2089dd80 13979 vty_out(vty, " Graceful restart information:\n");
36235319
QY
13980 if ((p->status == Established)
13981 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 13982
d62a17ae 13983 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
13984 FOREACH_AFI_SAFI (afi, safi) {
13985 if (CHECK_FLAG(p->af_sflags[afi][safi],
13986 PEER_STATUS_EOR_SEND)) {
13987 vty_out(vty, "%s%s",
13988 eor_send_af_count ? ", "
13989 : "",
36235319
QY
13990 get_afi_safi_str(
13991 afi, safi,
13992 false));
05c7a1cc 13993 eor_send_af_count++;
d62a17ae 13994 }
13995 }
13996 vty_out(vty, "\n");
13997 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
13998 FOREACH_AFI_SAFI (afi, safi) {
13999 if (CHECK_FLAG(
14000 p->af_sflags[afi][safi],
14001 PEER_STATUS_EOR_RECEIVED)) {
14002 vty_out(vty, "%s%s",
14003 eor_receive_af_count
14004 ? ", "
14005 : "",
5cb5f4d0
DD
14006 get_afi_safi_str(afi,
14007 safi,
14008 false));
05c7a1cc 14009 eor_receive_af_count++;
d62a17ae 14010 }
14011 }
14012 vty_out(vty, "\n");
14013 }
14014
14015 if (p->t_gr_restart)
14016 vty_out(vty,
14017 " The remaining time of restart timer is %ld\n",
14018 thread_timer_remain_second(
14019 p->t_gr_restart));
14020
14021 if (p->t_gr_stale)
14022 vty_out(vty,
14023 " The remaining time of stalepath timer is %ld\n",
14024 thread_timer_remain_second(
14025 p->t_gr_stale));
2986cac2 14026
14027 /* more gr info in new format */
14028 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 14029 }
2986cac2 14030
d62a17ae 14031 if (use_json) {
14032 json_object *json_stat = NULL;
14033 json_stat = json_object_new_object();
14034 /* Packet counts. */
43aa5965
QY
14035
14036 atomic_size_t outq_count, inq_count;
14037 outq_count = atomic_load_explicit(&p->obuf->count,
14038 memory_order_relaxed);
14039 inq_count = atomic_load_explicit(&p->ibuf->count,
14040 memory_order_relaxed);
14041
14042 json_object_int_add(json_stat, "depthInq",
14043 (unsigned long)inq_count);
d62a17ae 14044 json_object_int_add(json_stat, "depthOutq",
43aa5965 14045 (unsigned long)outq_count);
0112e9e0
QY
14046 json_object_int_add(json_stat, "opensSent",
14047 atomic_load_explicit(&p->open_out,
14048 memory_order_relaxed));
14049 json_object_int_add(json_stat, "opensRecv",
14050 atomic_load_explicit(&p->open_in,
14051 memory_order_relaxed));
d62a17ae 14052 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14053 atomic_load_explicit(&p->notify_out,
14054 memory_order_relaxed));
d62a17ae 14055 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14056 atomic_load_explicit(&p->notify_in,
14057 memory_order_relaxed));
14058 json_object_int_add(json_stat, "updatesSent",
14059 atomic_load_explicit(&p->update_out,
14060 memory_order_relaxed));
14061 json_object_int_add(json_stat, "updatesRecv",
14062 atomic_load_explicit(&p->update_in,
14063 memory_order_relaxed));
d62a17ae 14064 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14065 atomic_load_explicit(&p->keepalive_out,
14066 memory_order_relaxed));
d62a17ae 14067 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14068 atomic_load_explicit(&p->keepalive_in,
14069 memory_order_relaxed));
d62a17ae 14070 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14071 atomic_load_explicit(&p->refresh_out,
14072 memory_order_relaxed));
d62a17ae 14073 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14074 atomic_load_explicit(&p->refresh_in,
14075 memory_order_relaxed));
d62a17ae 14076 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14077 atomic_load_explicit(&p->dynamic_cap_out,
14078 memory_order_relaxed));
d62a17ae 14079 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14080 atomic_load_explicit(&p->dynamic_cap_in,
14081 memory_order_relaxed));
14082 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14083 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14084 json_object_object_add(json_neigh, "messageStats", json_stat);
14085 } else {
43aa5965
QY
14086 atomic_size_t outq_count, inq_count;
14087 outq_count = atomic_load_explicit(&p->obuf->count,
14088 memory_order_relaxed);
14089 inq_count = atomic_load_explicit(&p->ibuf->count,
14090 memory_order_relaxed);
14091
d62a17ae 14092 /* Packet counts. */
14093 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14094 vty_out(vty, " Inq depth is %zu\n", inq_count);
14095 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14096 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
14097 vty_out(vty, " Opens: %10d %10d\n",
14098 atomic_load_explicit(&p->open_out,
14099 memory_order_relaxed),
14100 atomic_load_explicit(&p->open_in,
14101 memory_order_relaxed));
14102 vty_out(vty, " Notifications: %10d %10d\n",
14103 atomic_load_explicit(&p->notify_out,
14104 memory_order_relaxed),
14105 atomic_load_explicit(&p->notify_in,
14106 memory_order_relaxed));
14107 vty_out(vty, " Updates: %10d %10d\n",
14108 atomic_load_explicit(&p->update_out,
14109 memory_order_relaxed),
14110 atomic_load_explicit(&p->update_in,
14111 memory_order_relaxed));
14112 vty_out(vty, " Keepalives: %10d %10d\n",
14113 atomic_load_explicit(&p->keepalive_out,
14114 memory_order_relaxed),
14115 atomic_load_explicit(&p->keepalive_in,
14116 memory_order_relaxed));
14117 vty_out(vty, " Route Refresh: %10d %10d\n",
14118 atomic_load_explicit(&p->refresh_out,
14119 memory_order_relaxed),
14120 atomic_load_explicit(&p->refresh_in,
14121 memory_order_relaxed));
d62a17ae 14122 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
14123 atomic_load_explicit(&p->dynamic_cap_out,
14124 memory_order_relaxed),
14125 atomic_load_explicit(&p->dynamic_cap_in,
14126 memory_order_relaxed));
14127 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
14128 PEER_TOTAL_RX(p));
d62a17ae 14129 }
14130
14131 if (use_json) {
14132 /* advertisement-interval */
14133 json_object_int_add(json_neigh,
14134 "minBtwnAdvertisementRunsTimerMsecs",
14135 p->v_routeadv * 1000);
14136
14137 /* Update-source. */
14138 if (p->update_if || p->update_source) {
14139 if (p->update_if)
14140 json_object_string_add(json_neigh,
14141 "updateSource",
14142 p->update_if);
14143 else if (p->update_source)
14144 json_object_string_add(
14145 json_neigh, "updateSource",
14146 sockunion2str(p->update_source, buf1,
14147 SU_ADDRSTRLEN));
14148 }
14149 } else {
14150 /* advertisement-interval */
14151 vty_out(vty,
14152 " Minimum time between advertisement runs is %d seconds\n",
14153 p->v_routeadv);
14154
14155 /* Update-source. */
14156 if (p->update_if || p->update_source) {
14157 vty_out(vty, " Update source is ");
14158 if (p->update_if)
14159 vty_out(vty, "%s", p->update_if);
14160 else if (p->update_source)
14161 vty_out(vty, "%s",
14162 sockunion2str(p->update_source, buf1,
14163 SU_ADDRSTRLEN));
14164 vty_out(vty, "\n");
14165 }
14166
14167 vty_out(vty, "\n");
14168 }
14169
14170 /* Address Family Information */
14171 json_object *json_hold = NULL;
14172
14173 if (use_json)
14174 json_hold = json_object_new_object();
14175
05c7a1cc
QY
14176 FOREACH_AFI_SAFI (afi, safi)
14177 if (p->afc[afi][safi])
14178 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14179 json_hold);
d62a17ae 14180
14181 if (use_json) {
14182 json_object_object_add(json_neigh, "addressFamilyInfo",
14183 json_hold);
14184 json_object_int_add(json_neigh, "connectionsEstablished",
14185 p->established);
14186 json_object_int_add(json_neigh, "connectionsDropped",
14187 p->dropped);
14188 } else
14189 vty_out(vty, " Connections established %d; dropped %d\n",
14190 p->established, p->dropped);
14191
14192 if (!p->last_reset) {
14193 if (use_json)
14194 json_object_string_add(json_neigh, "lastReset",
14195 "never");
14196 else
14197 vty_out(vty, " Last reset never\n");
14198 } else {
14199 if (use_json) {
14200 time_t uptime;
a2700b50 14201 struct tm tm;
d62a17ae 14202
14203 uptime = bgp_clock();
14204 uptime -= p->resettime;
a2700b50
MS
14205 gmtime_r(&uptime, &tm);
14206
d62a17ae 14207 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14208 (tm.tm_sec * 1000)
14209 + (tm.tm_min * 60000)
14210 + (tm.tm_hour * 3600000));
3577f1c5 14211 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14212 } else {
14213 vty_out(vty, " Last reset %s, ",
14214 peer_uptime(p->resettime, timebuf,
14215 BGP_UPTIME_LEN, 0, NULL));
14216
3577f1c5 14217 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14218 if (p->last_reset_cause_size) {
14219 msg = p->last_reset_cause;
14220 vty_out(vty,
14221 " Message received that caused BGP to send a NOTIFICATION:\n ");
14222 for (i = 1; i <= p->last_reset_cause_size;
14223 i++) {
14224 vty_out(vty, "%02X", *msg++);
14225
14226 if (i != p->last_reset_cause_size) {
14227 if (i % 16 == 0) {
14228 vty_out(vty, "\n ");
14229 } else if (i % 4 == 0) {
14230 vty_out(vty, " ");
14231 }
14232 }
14233 }
14234 vty_out(vty, "\n");
14235 }
14236 }
14237 }
14238
14239 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14240 if (use_json)
14241 json_object_boolean_true_add(json_neigh,
14242 "prefixesConfigExceedMax");
14243 else
14244 vty_out(vty,
14245 " Peer had exceeded the max. no. of prefixes configured.\n");
14246
14247 if (p->t_pmax_restart) {
14248 if (use_json) {
14249 json_object_boolean_true_add(
14250 json_neigh, "reducePrefixNumFrom");
14251 json_object_int_add(json_neigh,
14252 "restartInTimerMsec",
14253 thread_timer_remain_second(
14254 p->t_pmax_restart)
14255 * 1000);
14256 } else
14257 vty_out(vty,
14258 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14259 p->host, thread_timer_remain_second(
14260 p->t_pmax_restart));
d62a17ae 14261 } else {
14262 if (use_json)
14263 json_object_boolean_true_add(
14264 json_neigh,
14265 "reducePrefixNumAndClearIpBgp");
14266 else
14267 vty_out(vty,
14268 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14269 p->host);
14270 }
14271 }
14272
14273 /* EBGP Multihop and GTSM */
14274 if (p->sort != BGP_PEER_IBGP) {
14275 if (use_json) {
e2521429 14276 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14277 json_object_int_add(json_neigh,
14278 "externalBgpNbrMaxHopsAway",
14279 p->gtsm_hops);
c8d6f0d6 14280 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14281 json_object_int_add(json_neigh,
14282 "externalBgpNbrMaxHopsAway",
14283 p->ttl);
14284 } else {
e2521429 14285 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14286 vty_out(vty,
14287 " External BGP neighbor may be up to %d hops away.\n",
14288 p->gtsm_hops);
c8d6f0d6 14289 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14290 vty_out(vty,
14291 " External BGP neighbor may be up to %d hops away.\n",
14292 p->ttl);
14293 }
14294 } else {
e2521429 14295 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 14296 if (use_json)
14297 json_object_int_add(json_neigh,
14298 "internalBgpNbrMaxHopsAway",
14299 p->gtsm_hops);
14300 else
14301 vty_out(vty,
14302 " Internal BGP neighbor may be up to %d hops away.\n",
14303 p->gtsm_hops);
14304 }
14305 }
14306
14307 /* Local address. */
14308 if (p->su_local) {
14309 if (use_json) {
14310 json_object_string_add(json_neigh, "hostLocal",
14311 sockunion2str(p->su_local, buf1,
14312 SU_ADDRSTRLEN));
14313 json_object_int_add(json_neigh, "portLocal",
14314 ntohs(p->su_local->sin.sin_port));
14315 } else
14316 vty_out(vty, "Local host: %s, Local port: %d\n",
14317 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14318 ntohs(p->su_local->sin.sin_port));
14319 }
14320
14321 /* Remote address. */
14322 if (p->su_remote) {
14323 if (use_json) {
14324 json_object_string_add(json_neigh, "hostForeign",
14325 sockunion2str(p->su_remote, buf1,
14326 SU_ADDRSTRLEN));
14327 json_object_int_add(json_neigh, "portForeign",
14328 ntohs(p->su_remote->sin.sin_port));
14329 } else
14330 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14331 sockunion2str(p->su_remote, buf1,
14332 SU_ADDRSTRLEN),
14333 ntohs(p->su_remote->sin.sin_port));
14334 }
14335
14336 /* Nexthop display. */
14337 if (p->su_local) {
14338 if (use_json) {
14339 json_object_string_add(json_neigh, "nexthop",
14340 inet_ntop(AF_INET,
14341 &p->nexthop.v4, buf1,
14342 sizeof(buf1)));
14343 json_object_string_add(json_neigh, "nexthopGlobal",
14344 inet_ntop(AF_INET6,
14345 &p->nexthop.v6_global,
14346 buf1, sizeof(buf1)));
14347 json_object_string_add(json_neigh, "nexthopLocal",
14348 inet_ntop(AF_INET6,
14349 &p->nexthop.v6_local,
14350 buf1, sizeof(buf1)));
14351 if (p->shared_network)
14352 json_object_string_add(json_neigh,
14353 "bgpConnection",
14354 "sharedNetwork");
14355 else
14356 json_object_string_add(json_neigh,
14357 "bgpConnection",
14358 "nonSharedNetwork");
14359 } else {
14360 vty_out(vty, "Nexthop: %s\n",
14361 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14362 sizeof(buf1)));
14363 vty_out(vty, "Nexthop global: %s\n",
14364 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14365 sizeof(buf1)));
14366 vty_out(vty, "Nexthop local: %s\n",
14367 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14368 sizeof(buf1)));
14369 vty_out(vty, "BGP connection: %s\n",
14370 p->shared_network ? "shared network"
14371 : "non shared network");
14372 }
14373 }
14374
14375 /* Timer information. */
14376 if (use_json) {
14377 json_object_int_add(json_neigh, "connectRetryTimer",
14378 p->v_connect);
14379 if (p->status == Established && p->rtt)
14380 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14381 p->rtt);
14382 if (p->t_start)
14383 json_object_int_add(
14384 json_neigh, "nextStartTimerDueInMsecs",
14385 thread_timer_remain_second(p->t_start) * 1000);
14386 if (p->t_connect)
14387 json_object_int_add(
14388 json_neigh, "nextConnectTimerDueInMsecs",
14389 thread_timer_remain_second(p->t_connect)
14390 * 1000);
14391 if (p->t_routeadv) {
14392 json_object_int_add(json_neigh, "mraiInterval",
14393 p->v_routeadv);
14394 json_object_int_add(
14395 json_neigh, "mraiTimerExpireInMsecs",
14396 thread_timer_remain_second(p->t_routeadv)
14397 * 1000);
14398 }
14399 if (p->password)
14400 json_object_int_add(json_neigh, "authenticationEnabled",
14401 1);
14402
14403 if (p->t_read)
14404 json_object_string_add(json_neigh, "readThread", "on");
14405 else
14406 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14407
14408 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14409 json_object_string_add(json_neigh, "writeThread", "on");
14410 else
14411 json_object_string_add(json_neigh, "writeThread",
14412 "off");
14413 } else {
14414 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14415 p->v_connect);
14416 if (p->status == Established && p->rtt)
14417 vty_out(vty, "Estimated round trip time: %d ms\n",
14418 p->rtt);
14419 if (p->t_start)
14420 vty_out(vty, "Next start timer due in %ld seconds\n",
14421 thread_timer_remain_second(p->t_start));
14422 if (p->t_connect)
14423 vty_out(vty, "Next connect timer due in %ld seconds\n",
14424 thread_timer_remain_second(p->t_connect));
14425 if (p->t_routeadv)
14426 vty_out(vty,
14427 "MRAI (interval %u) timer expires in %ld seconds\n",
14428 p->v_routeadv,
14429 thread_timer_remain_second(p->t_routeadv));
14430 if (p->password)
14431 vty_out(vty, "Peer Authentication Enabled\n");
14432
cac9e917 14433 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14434 p->t_read ? "on" : "off",
14435 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14436 ? "on"
cac9e917 14437 : "off", p->fd);
d62a17ae 14438 }
14439
14440 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14441 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14442 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14443
14444 if (!use_json)
14445 vty_out(vty, "\n");
14446
14447 /* BFD information. */
21bfce98
RZ
14448 if (p->bfd_config)
14449 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14450
14451 if (use_json) {
14452 if (p->conf_if) /* Configured interface name. */
14453 json_object_object_add(json, p->conf_if, json_neigh);
14454 else /* Configured IP address. */
14455 json_object_object_add(json, p->host, json_neigh);
14456 }
14457}
14458
36235319
QY
14459static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14460 enum show_type type,
14461 union sockunion *su,
14462 const char *conf_if, afi_t afi,
74a630b6 14463 bool use_json)
2986cac2 14464{
14465 struct listnode *node, *nnode;
14466 struct peer *peer;
14467 int find = 0;
14468 safi_t safi = SAFI_UNICAST;
74a630b6 14469 json_object *json = NULL;
2986cac2 14470 json_object *json_neighbor = NULL;
14471
74a630b6
NT
14472 if (use_json) {
14473 json = json_object_new_object();
14474 json_neighbor = json_object_new_object();
14475 }
14476
2986cac2 14477 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14478
14479 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14480 continue;
14481
14482 if ((peer->afc[afi][safi]) == 0)
14483 continue;
14484
2ba1fe69 14485 if (type == show_all) {
2986cac2 14486 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14487 json_neighbor);
2986cac2 14488
74a630b6 14489 if (use_json) {
13909c4f
DS
14490 json_object_object_add(json, peer->host,
14491 json_neighbor);
74a630b6
NT
14492 json_neighbor = NULL;
14493 }
2986cac2 14494
2ba1fe69 14495 } else if (type == show_peer) {
2986cac2 14496 if (conf_if) {
14497 if ((peer->conf_if
13909c4f
DS
14498 && !strcmp(peer->conf_if, conf_if))
14499 || (peer->hostname
2986cac2 14500 && !strcmp(peer->hostname, conf_if))) {
14501 find = 1;
13909c4f
DS
14502 bgp_show_peer_gr_status(vty, peer,
14503 use_json,
14504 json_neighbor);
2986cac2 14505 }
14506 } else {
14507 if (sockunion_same(&peer->su, su)) {
14508 find = 1;
13909c4f
DS
14509 bgp_show_peer_gr_status(vty, peer,
14510 use_json,
14511 json_neighbor);
2986cac2 14512 }
14513 }
13909c4f
DS
14514 if (use_json && find)
14515 json_object_object_add(json, peer->host,
14516 json_neighbor);
2986cac2 14517 }
14518
74a630b6
NT
14519 if (find) {
14520 json_neighbor = NULL;
2986cac2 14521 break;
74a630b6 14522 }
2986cac2 14523 }
14524
14525 if (type == show_peer && !find) {
14526 if (use_json)
13909c4f 14527 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14528 else
14529 vty_out(vty, "%% No such neighbor\n");
14530 }
14531 if (use_json) {
13909c4f
DS
14532 vty_out(vty, "%s\n",
14533 json_object_to_json_string_ext(
14534 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
14535
14536 if (json_neighbor)
14537 json_object_free(json_neighbor);
14538 json_object_free(json);
2986cac2 14539 } else {
14540 vty_out(vty, "\n");
14541 }
14542
14543 return CMD_SUCCESS;
14544}
14545
d62a17ae 14546static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14547 enum show_type type, union sockunion *su,
9f049418 14548 const char *conf_if, bool use_json,
d62a17ae 14549 json_object *json)
14550{
14551 struct listnode *node, *nnode;
14552 struct peer *peer;
14553 int find = 0;
9f049418 14554 bool nbr_output = false;
d1927ebe
AS
14555 afi_t afi = AFI_MAX;
14556 safi_t safi = SAFI_MAX;
14557
14558 if (type == show_ipv4_peer || type == show_ipv4_all) {
14559 afi = AFI_IP;
14560 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14561 afi = AFI_IP6;
14562 }
d62a17ae 14563
14564 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14565 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14566 continue;
14567
14568 switch (type) {
14569 case show_all:
14570 bgp_show_peer(vty, peer, use_json, json);
9f049418 14571 nbr_output = true;
d62a17ae 14572 break;
14573 case show_peer:
14574 if (conf_if) {
14575 if ((peer->conf_if
14576 && !strcmp(peer->conf_if, conf_if))
14577 || (peer->hostname
14578 && !strcmp(peer->hostname, conf_if))) {
14579 find = 1;
14580 bgp_show_peer(vty, peer, use_json,
14581 json);
14582 }
14583 } else {
14584 if (sockunion_same(&peer->su, su)) {
14585 find = 1;
14586 bgp_show_peer(vty, peer, use_json,
14587 json);
14588 }
14589 }
14590 break;
d1927ebe
AS
14591 case show_ipv4_peer:
14592 case show_ipv6_peer:
14593 FOREACH_SAFI (safi) {
14594 if (peer->afc[afi][safi]) {
14595 if (conf_if) {
14596 if ((peer->conf_if
14597 && !strcmp(peer->conf_if, conf_if))
14598 || (peer->hostname
14599 && !strcmp(peer->hostname, conf_if))) {
14600 find = 1;
14601 bgp_show_peer(vty, peer, use_json,
14602 json);
14603 break;
14604 }
14605 } else {
14606 if (sockunion_same(&peer->su, su)) {
14607 find = 1;
14608 bgp_show_peer(vty, peer, use_json,
14609 json);
14610 break;
14611 }
14612 }
14613 }
14614 }
14615 break;
14616 case show_ipv4_all:
14617 case show_ipv6_all:
14618 FOREACH_SAFI (safi) {
14619 if (peer->afc[afi][safi]) {
14620 bgp_show_peer(vty, peer, use_json, json);
14621 nbr_output = true;
14622 break;
14623 }
14624 }
14625 break;
d62a17ae 14626 }
14627 }
14628
d1927ebe
AS
14629 if ((type == show_peer || type == show_ipv4_peer ||
14630 type == show_ipv6_peer) && !find) {
d62a17ae 14631 if (use_json)
14632 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14633 else
88b7d255 14634 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14635 }
14636
d1927ebe
AS
14637 if (type != show_peer && type != show_ipv4_peer &&
14638 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14639 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14640
d62a17ae 14641 if (use_json) {
996c9314
LB
14642 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14643 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14644 } else {
14645 vty_out(vty, "\n");
14646 }
14647
14648 return CMD_SUCCESS;
14649}
14650
36235319
QY
14651static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14652 enum show_type type,
14653 const char *ip_str,
14654 afi_t afi, bool use_json)
2986cac2 14655{
14656
14657 int ret;
14658 struct bgp *bgp;
14659 union sockunion su;
2986cac2 14660
14661 bgp = bgp_get_default();
14662
13909c4f
DS
14663 if (!bgp)
14664 return;
2986cac2 14665
13909c4f
DS
14666 if (!use_json)
14667 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14668 NULL);
2986cac2 14669
13909c4f
DS
14670 if (ip_str) {
14671 ret = str2sockunion(ip_str, &su);
14672 if (ret < 0)
13909c4f 14673 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14674 vty, bgp, type, NULL, ip_str, afi, use_json);
14675 else
14676 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14677 NULL, afi, use_json);
13909c4f
DS
14678 } else
14679 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14680 afi, use_json);
2986cac2 14681}
14682
d62a17ae 14683static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14684 enum show_type type,
14685 const char *ip_str,
9f049418 14686 bool use_json)
d62a17ae 14687{
0291c246
MK
14688 struct listnode *node, *nnode;
14689 struct bgp *bgp;
71aedaa3 14690 union sockunion su;
0291c246 14691 json_object *json = NULL;
71aedaa3 14692 int ret, is_first = 1;
9f049418 14693 bool nbr_output = false;
d62a17ae 14694
14695 if (use_json)
14696 vty_out(vty, "{\n");
14697
14698 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14699 nbr_output = true;
d62a17ae 14700 if (use_json) {
14701 if (!(json = json_object_new_object())) {
af4c2728 14702 flog_err(
e50f7cfd 14703 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14704 "Unable to allocate memory for JSON object");
14705 vty_out(vty,
14706 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14707 return;
14708 }
14709
14710 json_object_int_add(json, "vrfId",
14711 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14712 ? -1
14713 : (int64_t)bgp->vrf_id);
d62a17ae 14714 json_object_string_add(
14715 json, "vrfName",
14716 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14717 ? VRF_DEFAULT_NAME
d62a17ae 14718 : bgp->name);
14719
14720 if (!is_first)
14721 vty_out(vty, ",\n");
14722 else
14723 is_first = 0;
14724
14725 vty_out(vty, "\"%s\":",
14726 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14727 ? VRF_DEFAULT_NAME
d62a17ae 14728 : bgp->name);
14729 } else {
14730 vty_out(vty, "\nInstance %s:\n",
14731 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14732 ? VRF_DEFAULT_NAME
d62a17ae 14733 : bgp->name);
14734 }
71aedaa3 14735
d1927ebe
AS
14736 if (type == show_peer || type == show_ipv4_peer ||
14737 type == show_ipv6_peer) {
71aedaa3
DS
14738 ret = str2sockunion(ip_str, &su);
14739 if (ret < 0)
14740 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14741 use_json, json);
14742 else
14743 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14744 use_json, json);
14745 } else {
d1927ebe 14746 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14747 use_json, json);
14748 }
b77004d6 14749 json_object_free(json);
121067e9 14750 json = NULL;
d62a17ae 14751 }
14752
3e78a6ce 14753 if (use_json)
d62a17ae 14754 vty_out(vty, "}\n");
9f049418
DS
14755 else if (!nbr_output)
14756 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14757}
14758
14759static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14760 enum show_type type, const char *ip_str,
9f049418 14761 bool use_json)
d62a17ae 14762{
14763 int ret;
14764 struct bgp *bgp;
14765 union sockunion su;
14766 json_object *json = NULL;
14767
14768 if (name) {
14769 if (strmatch(name, "all")) {
71aedaa3
DS
14770 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14771 use_json);
d62a17ae 14772 return CMD_SUCCESS;
14773 } else {
14774 bgp = bgp_lookup_by_name(name);
14775 if (!bgp) {
14776 if (use_json) {
14777 json = json_object_new_object();
d62a17ae 14778 vty_out(vty, "%s\n",
14779 json_object_to_json_string_ext(
14780 json,
14781 JSON_C_TO_STRING_PRETTY));
14782 json_object_free(json);
14783 } else
14784 vty_out(vty,
9f049418 14785 "%% BGP instance not found\n");
d62a17ae 14786
14787 return CMD_WARNING;
14788 }
14789 }
14790 } else {
14791 bgp = bgp_get_default();
14792 }
14793
14794 if (bgp) {
14795 json = json_object_new_object();
14796 if (ip_str) {
14797 ret = str2sockunion(ip_str, &su);
14798 if (ret < 0)
14799 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14800 use_json, json);
14801 else
14802 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14803 use_json, json);
14804 } else {
14805 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14806 json);
14807 }
14808 json_object_free(json);
ca61fd25
DS
14809 } else {
14810 if (use_json)
14811 vty_out(vty, "{}\n");
14812 else
14813 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14814 }
14815
14816 return CMD_SUCCESS;
4fb25c53
DW
14817}
14818
2986cac2 14819
14820
14821/* "show [ip] bgp neighbors graceful-restart" commands. */
14822DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14823 show_ip_bgp_neighbors_graceful_restart_cmd,
14824 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14825 SHOW_STR
14826 BGP_STR
14827 IP_STR
14828 IPV6_STR
14829 NEIGHBOR_STR
14830 "Neighbor to display information about\n"
14831 "Neighbor to display information about\n"
14832 "Neighbor on BGP configured interface\n"
14833 GR_SHOW
14834 JSON_STR)
14835{
14836 char *sh_arg = NULL;
14837 enum show_type sh_type;
14838 int idx = 0;
14839 afi_t afi = AFI_MAX;
2986cac2 14840 bool uj = use_json(argc, argv);
14841
36235319 14842 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14843 afi = AFI_MAX;
14844
14845 idx++;
14846
14847 if (argv_find(argv, argc, "A.B.C.D", &idx)
14848 || argv_find(argv, argc, "X:X::X:X", &idx)
14849 || argv_find(argv, argc, "WORD", &idx)) {
14850 sh_type = show_peer;
14851 sh_arg = argv[idx]->arg;
14852 } else
14853 sh_type = show_all;
14854
14855 if (!argv_find(argv, argc, "graceful-restart", &idx))
14856 return CMD_SUCCESS;
14857
14858
36235319
QY
14859 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14860 afi, uj);
2986cac2 14861}
14862
716b2d8a 14863/* "show [ip] bgp neighbors" commands. */
718e3744 14864DEFUN (show_ip_bgp_neighbors,
14865 show_ip_bgp_neighbors_cmd,
24345e82 14866 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14867 SHOW_STR
14868 IP_STR
14869 BGP_STR
f2a8972b 14870 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14871 "Address Family\n"
14872 "Address Family\n"
718e3744 14873 "Detailed information on TCP and BGP neighbor connections\n"
14874 "Neighbor to display information about\n"
a80beece 14875 "Neighbor to display information about\n"
91d37724 14876 "Neighbor on BGP configured interface\n"
9973d184 14877 JSON_STR)
718e3744 14878{
d62a17ae 14879 char *vrf = NULL;
14880 char *sh_arg = NULL;
14881 enum show_type sh_type;
d1927ebe 14882 afi_t afi = AFI_MAX;
718e3744 14883
9f049418 14884 bool uj = use_json(argc, argv);
718e3744 14885
d62a17ae 14886 int idx = 0;
718e3744 14887
9a8bdf1c
PG
14888 /* [<vrf> VIEWVRFNAME] */
14889 if (argv_find(argv, argc, "vrf", &idx)) {
14890 vrf = argv[idx + 1]->arg;
14891 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14892 vrf = NULL;
14893 } else if (argv_find(argv, argc, "view", &idx))
14894 /* [<view> VIEWVRFNAME] */
d62a17ae 14895 vrf = argv[idx + 1]->arg;
718e3744 14896
d62a17ae 14897 idx++;
d1927ebe
AS
14898
14899 if (argv_find(argv, argc, "ipv4", &idx)) {
14900 sh_type = show_ipv4_all;
14901 afi = AFI_IP;
14902 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14903 sh_type = show_ipv6_all;
14904 afi = AFI_IP6;
14905 } else {
14906 sh_type = show_all;
14907 }
14908
d62a17ae 14909 if (argv_find(argv, argc, "A.B.C.D", &idx)
14910 || argv_find(argv, argc, "X:X::X:X", &idx)
14911 || argv_find(argv, argc, "WORD", &idx)) {
14912 sh_type = show_peer;
14913 sh_arg = argv[idx]->arg;
d1927ebe
AS
14914 }
14915
14916 if (sh_type == show_peer && afi == AFI_IP) {
14917 sh_type = show_ipv4_peer;
14918 } else if (sh_type == show_peer && afi == AFI_IP6) {
14919 sh_type = show_ipv6_peer;
14920 }
856ca177 14921
d62a17ae 14922 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14923}
14924
716b2d8a 14925/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14926 paths' and `show ip mbgp paths'. Those functions results are the
14927 same.*/
f412b39a 14928DEFUN (show_ip_bgp_paths,
718e3744 14929 show_ip_bgp_paths_cmd,
46f296b4 14930 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14931 SHOW_STR
14932 IP_STR
14933 BGP_STR
46f296b4 14934 BGP_SAFI_HELP_STR
718e3744 14935 "Path information\n")
14936{
d62a17ae 14937 vty_out(vty, "Address Refcnt Path\n");
14938 aspath_print_all_vty(vty);
14939 return CMD_SUCCESS;
718e3744 14940}
14941
718e3744 14942#include "hash.h"
14943
e3b78da8 14944static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14945 struct vty *vty)
718e3744 14946{
d62a17ae 14947 struct community *com;
718e3744 14948
e3b78da8 14949 com = (struct community *)bucket->data;
3f65c5b1 14950 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14951 community_str(com, false));
718e3744 14952}
14953
14954/* Show BGP's community internal data. */
f412b39a 14955DEFUN (show_ip_bgp_community_info,
718e3744 14956 show_ip_bgp_community_info_cmd,
bec37ba5 14957 "show [ip] bgp community-info",
718e3744 14958 SHOW_STR
14959 IP_STR
14960 BGP_STR
14961 "List all bgp community information\n")
14962{
d62a17ae 14963 vty_out(vty, "Address Refcnt Community\n");
718e3744 14964
d62a17ae 14965 hash_iterate(community_hash(),
e3b78da8 14966 (void (*)(struct hash_bucket *,
d62a17ae 14967 void *))community_show_all_iterator,
14968 vty);
718e3744 14969
d62a17ae 14970 return CMD_SUCCESS;
718e3744 14971}
14972
e3b78da8 14973static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14974 struct vty *vty)
57d187bc 14975{
d62a17ae 14976 struct lcommunity *lcom;
57d187bc 14977
e3b78da8 14978 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14979 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14980 lcommunity_str(lcom, false));
57d187bc
JS
14981}
14982
14983/* Show BGP's community internal data. */
14984DEFUN (show_ip_bgp_lcommunity_info,
14985 show_ip_bgp_lcommunity_info_cmd,
14986 "show ip bgp large-community-info",
14987 SHOW_STR
14988 IP_STR
14989 BGP_STR
14990 "List all bgp large-community information\n")
14991{
d62a17ae 14992 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14993
d62a17ae 14994 hash_iterate(lcommunity_hash(),
e3b78da8 14995 (void (*)(struct hash_bucket *,
d62a17ae 14996 void *))lcommunity_show_all_iterator,
14997 vty);
57d187bc 14998
d62a17ae 14999 return CMD_SUCCESS;
57d187bc 15000}
2986cac2 15001/* Graceful Restart */
15002
15003static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
15004 struct bgp *bgp,
15005 bool use_json,
15006 json_object *json)
2986cac2 15007{
57d187bc
JS
15008
15009
2986cac2 15010 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15011
7318ae88 15012 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15013
15014 switch (bgp_global_gr_mode) {
15015
15016 case GLOBAL_HELPER:
13909c4f 15017 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15018 break;
15019
15020 case GLOBAL_GR:
13909c4f 15021 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15022 break;
15023
15024 case GLOBAL_DISABLE:
13909c4f 15025 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15026 break;
15027
15028 case GLOBAL_INVALID:
2986cac2 15029 vty_out(vty,
2ba1fe69 15030 "Global BGP GR Mode Invalid\n");
2986cac2 15031 break;
15032 }
15033 vty_out(vty, "\n");
15034}
15035
36235319
QY
15036static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15037 enum show_type type,
15038 const char *ip_str,
15039 afi_t afi, bool use_json)
2986cac2 15040{
15041 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15042 afi = AFI_IP;
15043
15044 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15045
36235319
QY
15046 bgp_show_neighbor_graceful_restart_vty(
15047 vty, type, ip_str, afi, use_json);
2986cac2 15048 afi++;
15049 }
15050 } else if (afi != AFI_MAX) {
36235319
QY
15051 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15052 use_json);
2986cac2 15053 } else {
15054 return CMD_ERR_INCOMPLETE;
15055 }
15056
15057 return CMD_SUCCESS;
15058}
15059/* Graceful Restart */
15060
f412b39a 15061DEFUN (show_ip_bgp_attr_info,
718e3744 15062 show_ip_bgp_attr_info_cmd,
bec37ba5 15063 "show [ip] bgp attribute-info",
718e3744 15064 SHOW_STR
15065 IP_STR
15066 BGP_STR
15067 "List all bgp attribute information\n")
15068{
d62a17ae 15069 attr_show_all(vty);
15070 return CMD_SUCCESS;
718e3744 15071}
6b0655a2 15072
03915806
CS
15073static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15074 afi_t afi, safi_t safi,
15075 bool use_json, json_object *json)
53089bec 15076{
15077 struct bgp *bgp;
15078 struct listnode *node;
15079 char *vname;
15080 char buf1[INET6_ADDRSTRLEN];
15081 char *ecom_str;
15082 vpn_policy_direction_t dir;
15083
03915806 15084 if (json) {
b46dfd20
DS
15085 json_object *json_import_vrfs = NULL;
15086 json_object *json_export_vrfs = NULL;
15087
b46dfd20
DS
15088 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15089
53089bec 15090 if (!bgp) {
b46dfd20
DS
15091 vty_out(vty, "%s\n",
15092 json_object_to_json_string_ext(
15093 json,
15094 JSON_C_TO_STRING_PRETTY));
15095 json_object_free(json);
15096
53089bec 15097 return CMD_WARNING;
15098 }
b46dfd20 15099
94d4c685
DS
15100 /* Provide context for the block */
15101 json_object_string_add(json, "vrf", name ? name : "default");
15102 json_object_string_add(json, "afiSafi",
5cb5f4d0 15103 get_afi_safi_str(afi, safi, true));
94d4c685 15104
b46dfd20
DS
15105 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15106 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15107 json_object_string_add(json, "importFromVrfs", "none");
15108 json_object_string_add(json, "importRts", "none");
15109 } else {
6ce24e52
DS
15110 json_import_vrfs = json_object_new_array();
15111
b46dfd20
DS
15112 for (ALL_LIST_ELEMENTS_RO(
15113 bgp->vpn_policy[afi].import_vrf,
15114 node, vname))
15115 json_object_array_add(json_import_vrfs,
15116 json_object_new_string(vname));
15117
b20875ea
CS
15118 json_object_object_add(json, "importFromVrfs",
15119 json_import_vrfs);
b46dfd20 15120 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15121 if (bgp->vpn_policy[afi].rtlist[dir]) {
15122 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15123 bgp->vpn_policy[afi].rtlist[dir],
15124 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15125 json_object_string_add(json, "importRts",
15126 ecom_str);
15127 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15128 } else
15129 json_object_string_add(json, "importRts",
15130 "none");
b46dfd20
DS
15131 }
15132
15133 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15134 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15135 json_object_string_add(json, "exportToVrfs", "none");
15136 json_object_string_add(json, "routeDistinguisher",
15137 "none");
15138 json_object_string_add(json, "exportRts", "none");
15139 } else {
6ce24e52
DS
15140 json_export_vrfs = json_object_new_array();
15141
b46dfd20
DS
15142 for (ALL_LIST_ELEMENTS_RO(
15143 bgp->vpn_policy[afi].export_vrf,
15144 node, vname))
15145 json_object_array_add(json_export_vrfs,
15146 json_object_new_string(vname));
15147 json_object_object_add(json, "exportToVrfs",
15148 json_export_vrfs);
15149 json_object_string_add(json, "routeDistinguisher",
15150 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15151 buf1, RD_ADDRSTRLEN));
15152
15153 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15154 if (bgp->vpn_policy[afi].rtlist[dir]) {
15155 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15156 bgp->vpn_policy[afi].rtlist[dir],
15157 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15158 json_object_string_add(json, "exportRts",
15159 ecom_str);
15160 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15161 } else
15162 json_object_string_add(json, "exportRts",
15163 "none");
b46dfd20
DS
15164 }
15165
03915806
CS
15166 if (use_json) {
15167 vty_out(vty, "%s\n",
15168 json_object_to_json_string_ext(json,
b46dfd20 15169 JSON_C_TO_STRING_PRETTY));
03915806
CS
15170 json_object_free(json);
15171 }
53089bec 15172 } else {
b46dfd20
DS
15173 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15174
53089bec 15175 if (!bgp) {
b46dfd20 15176 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15177 return CMD_WARNING;
15178 }
53089bec 15179
b46dfd20
DS
15180 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15181 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15182 vty_out(vty,
15183 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15184 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15185 else {
15186 vty_out(vty,
15187 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15188 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15189
15190 for (ALL_LIST_ELEMENTS_RO(
15191 bgp->vpn_policy[afi].import_vrf,
15192 node, vname))
15193 vty_out(vty, " %s\n", vname);
15194
15195 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15196 ecom_str = NULL;
15197 if (bgp->vpn_policy[afi].rtlist[dir]) {
15198 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15199 bgp->vpn_policy[afi].rtlist[dir],
15200 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15201 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15202
b20875ea
CS
15203 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15204 } else
15205 vty_out(vty, "Import RT(s):\n");
53089bec 15206 }
53089bec 15207
b46dfd20
DS
15208 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15209 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15210 vty_out(vty,
15211 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15212 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15213 else {
15214 vty_out(vty,
04c9077f 15215 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15216 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15217
15218 for (ALL_LIST_ELEMENTS_RO(
15219 bgp->vpn_policy[afi].export_vrf,
15220 node, vname))
15221 vty_out(vty, " %s\n", vname);
15222
15223 vty_out(vty, "RD: %s\n",
15224 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15225 buf1, RD_ADDRSTRLEN));
15226
15227 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15228 if (bgp->vpn_policy[afi].rtlist[dir]) {
15229 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15230 bgp->vpn_policy[afi].rtlist[dir],
15231 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15232 vty_out(vty, "Export RT: %s\n", ecom_str);
15233 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15234 } else
15235 vty_out(vty, "Import RT(s):\n");
53089bec 15236 }
53089bec 15237 }
15238
15239 return CMD_SUCCESS;
15240}
15241
03915806
CS
15242static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15243 safi_t safi, bool use_json)
15244{
15245 struct listnode *node, *nnode;
15246 struct bgp *bgp;
15247 char *vrf_name = NULL;
15248 json_object *json = NULL;
15249 json_object *json_vrf = NULL;
15250 json_object *json_vrfs = NULL;
15251
15252 if (use_json) {
15253 json = json_object_new_object();
15254 json_vrfs = json_object_new_object();
15255 }
15256
15257 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15258
15259 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15260 vrf_name = bgp->name;
15261
15262 if (use_json) {
15263 json_vrf = json_object_new_object();
15264 } else {
15265 vty_out(vty, "\nInstance %s:\n",
15266 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15267 ? VRF_DEFAULT_NAME : bgp->name);
15268 }
15269 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15270 if (use_json) {
15271 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15272 json_object_object_add(json_vrfs,
15273 VRF_DEFAULT_NAME, json_vrf);
15274 else
15275 json_object_object_add(json_vrfs, vrf_name,
15276 json_vrf);
15277 }
15278 }
15279
15280 if (use_json) {
15281 json_object_object_add(json, "vrfs", json_vrfs);
15282 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15283 JSON_C_TO_STRING_PRETTY));
15284 json_object_free(json);
15285 }
15286
15287 return CMD_SUCCESS;
15288}
15289
53089bec 15290/* "show [ip] bgp route-leak" command. */
15291DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15292 show_ip_bgp_route_leak_cmd,
15293 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15294 SHOW_STR
15295 IP_STR
15296 BGP_STR
15297 BGP_INSTANCE_HELP_STR
15298 BGP_AFI_HELP_STR
15299 BGP_SAFI_HELP_STR
15300 "Route leaking information\n"
15301 JSON_STR)
53089bec 15302{
15303 char *vrf = NULL;
15304 afi_t afi = AFI_MAX;
15305 safi_t safi = SAFI_MAX;
15306
9f049418 15307 bool uj = use_json(argc, argv);
53089bec 15308 int idx = 0;
03915806 15309 json_object *json = NULL;
53089bec 15310
15311 /* show [ip] bgp */
15312 if (argv_find(argv, argc, "ip", &idx)) {
15313 afi = AFI_IP;
15314 safi = SAFI_UNICAST;
15315 }
15316 /* [vrf VIEWVRFNAME] */
15317 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15318 vty_out(vty,
15319 "%% This command is not applicable to BGP views\n");
53089bec 15320 return CMD_WARNING;
15321 }
15322
9a8bdf1c
PG
15323 if (argv_find(argv, argc, "vrf", &idx)) {
15324 vrf = argv[idx + 1]->arg;
15325 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15326 vrf = NULL;
15327 }
53089bec 15328 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15329 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15330 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15331 }
15332
15333 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15334 vty_out(vty,
15335 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15336 return CMD_WARNING;
15337 }
15338
03915806
CS
15339 if (vrf && strmatch(vrf, "all"))
15340 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15341
15342 if (uj)
15343 json = json_object_new_object();
15344
15345 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15346}
15347
d62a17ae 15348static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15349 safi_t safi)
f186de26 15350{
d62a17ae 15351 struct listnode *node, *nnode;
15352 struct bgp *bgp;
f186de26 15353
d62a17ae 15354 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15355 vty_out(vty, "\nInstance %s:\n",
15356 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15357 ? VRF_DEFAULT_NAME
d62a17ae 15358 : bgp->name);
15359 update_group_show(bgp, afi, safi, vty, 0);
15360 }
f186de26 15361}
15362
d62a17ae 15363static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15364 int safi, uint64_t subgrp_id)
4fb25c53 15365{
d62a17ae 15366 struct bgp *bgp;
4fb25c53 15367
d62a17ae 15368 if (name) {
15369 if (strmatch(name, "all")) {
15370 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15371 return CMD_SUCCESS;
15372 } else {
15373 bgp = bgp_lookup_by_name(name);
15374 }
15375 } else {
15376 bgp = bgp_get_default();
15377 }
4fb25c53 15378
d62a17ae 15379 if (bgp)
15380 update_group_show(bgp, afi, safi, vty, subgrp_id);
15381 return CMD_SUCCESS;
4fb25c53
DW
15382}
15383
8fe8a7f6
DS
15384DEFUN (show_ip_bgp_updgrps,
15385 show_ip_bgp_updgrps_cmd,
c1a44e43 15386 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15387 SHOW_STR
15388 IP_STR
15389 BGP_STR
15390 BGP_INSTANCE_HELP_STR
c9e571b4 15391 BGP_AFI_HELP_STR
9bedbb1e 15392 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15393 "Detailed info about dynamic update groups\n"
15394 "Specific subgroup to display detailed info for\n")
8386ac43 15395{
d62a17ae 15396 char *vrf = NULL;
15397 afi_t afi = AFI_IP6;
15398 safi_t safi = SAFI_UNICAST;
15399 uint64_t subgrp_id = 0;
15400
15401 int idx = 0;
15402
15403 /* show [ip] bgp */
15404 if (argv_find(argv, argc, "ip", &idx))
15405 afi = AFI_IP;
9a8bdf1c
PG
15406 /* [<vrf> VIEWVRFNAME] */
15407 if (argv_find(argv, argc, "vrf", &idx)) {
15408 vrf = argv[idx + 1]->arg;
15409 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15410 vrf = NULL;
15411 } else if (argv_find(argv, argc, "view", &idx))
15412 /* [<view> VIEWVRFNAME] */
15413 vrf = argv[idx + 1]->arg;
d62a17ae 15414 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15415 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15416 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15417 }
5bf15956 15418
d62a17ae 15419 /* get subgroup id, if provided */
15420 idx = argc - 1;
15421 if (argv[idx]->type == VARIABLE_TKN)
15422 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15423
d62a17ae 15424 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15425}
15426
f186de26 15427DEFUN (show_bgp_instance_all_ipv6_updgrps,
15428 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15429 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15430 SHOW_STR
716b2d8a 15431 IP_STR
f186de26 15432 BGP_STR
15433 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15434 "Detailed info about dynamic update groups\n")
f186de26 15435{
d62a17ae 15436 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15437 return CMD_SUCCESS;
f186de26 15438}
15439
43d3f4fc
DS
15440DEFUN (show_bgp_l2vpn_evpn_updgrps,
15441 show_bgp_l2vpn_evpn_updgrps_cmd,
15442 "show [ip] bgp l2vpn evpn update-groups",
15443 SHOW_STR
15444 IP_STR
15445 BGP_STR
15446 "l2vpn address family\n"
15447 "evpn sub-address family\n"
15448 "Detailed info about dynamic update groups\n")
15449{
15450 char *vrf = NULL;
15451 uint64_t subgrp_id = 0;
15452
15453 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15454 return CMD_SUCCESS;
15455}
15456
5bf15956
DW
15457DEFUN (show_bgp_updgrps_stats,
15458 show_bgp_updgrps_stats_cmd,
716b2d8a 15459 "show [ip] bgp update-groups statistics",
3f9c7369 15460 SHOW_STR
716b2d8a 15461 IP_STR
3f9c7369 15462 BGP_STR
0c7b1b01 15463 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15464 "Statistics\n")
15465{
d62a17ae 15466 struct bgp *bgp;
3f9c7369 15467
d62a17ae 15468 bgp = bgp_get_default();
15469 if (bgp)
15470 update_group_show_stats(bgp, vty);
3f9c7369 15471
d62a17ae 15472 return CMD_SUCCESS;
3f9c7369
DS
15473}
15474
8386ac43 15475DEFUN (show_bgp_instance_updgrps_stats,
15476 show_bgp_instance_updgrps_stats_cmd,
18c57037 15477 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15478 SHOW_STR
716b2d8a 15479 IP_STR
8386ac43 15480 BGP_STR
15481 BGP_INSTANCE_HELP_STR
0c7b1b01 15482 "Detailed info about dynamic update groups\n"
8386ac43 15483 "Statistics\n")
15484{
d62a17ae 15485 int idx_word = 3;
15486 struct bgp *bgp;
8386ac43 15487
d62a17ae 15488 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15489 if (bgp)
15490 update_group_show_stats(bgp, vty);
8386ac43 15491
d62a17ae 15492 return CMD_SUCCESS;
8386ac43 15493}
15494
d62a17ae 15495static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15496 afi_t afi, safi_t safi,
15497 const char *what, uint64_t subgrp_id)
3f9c7369 15498{
d62a17ae 15499 struct bgp *bgp;
8386ac43 15500
d62a17ae 15501 if (name)
15502 bgp = bgp_lookup_by_name(name);
15503 else
15504 bgp = bgp_get_default();
8386ac43 15505
d62a17ae 15506 if (bgp) {
15507 if (!strcmp(what, "advertise-queue"))
15508 update_group_show_adj_queue(bgp, afi, safi, vty,
15509 subgrp_id);
15510 else if (!strcmp(what, "advertised-routes"))
15511 update_group_show_advertised(bgp, afi, safi, vty,
15512 subgrp_id);
15513 else if (!strcmp(what, "packet-queue"))
15514 update_group_show_packet_queue(bgp, afi, safi, vty,
15515 subgrp_id);
15516 }
3f9c7369
DS
15517}
15518
dc64bdec
QY
15519DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15520 show_ip_bgp_instance_updgrps_adj_s_cmd,
15521 "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",
15522 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15523 BGP_SAFI_HELP_STR
15524 "Detailed info about dynamic update groups\n"
15525 "Specific subgroup to display info for\n"
15526 "Advertisement queue\n"
15527 "Announced routes\n"
15528 "Packet queue\n")
3f9c7369 15529{
dc64bdec
QY
15530 uint64_t subgrp_id = 0;
15531 afi_t afiz;
15532 safi_t safiz;
15533 if (sgid)
15534 subgrp_id = strtoull(sgid, NULL, 10);
15535
15536 if (!ip && !afi)
15537 afiz = AFI_IP6;
15538 if (!ip && afi)
15539 afiz = bgp_vty_afi_from_str(afi);
15540 if (ip && !afi)
15541 afiz = AFI_IP;
15542 if (ip && afi) {
15543 afiz = bgp_vty_afi_from_str(afi);
15544 if (afiz != AFI_IP)
15545 vty_out(vty,
15546 "%% Cannot specify both 'ip' and 'ipv6'\n");
15547 return CMD_WARNING;
15548 }
d62a17ae 15549
dc64bdec 15550 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15551
dc64bdec 15552 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15553 return CMD_SUCCESS;
15554}
15555
6f4eacf3
DA
15556static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15557 json_object *json)
d62a17ae 15558{
15559 struct listnode *node, *nnode;
15560 struct prefix *range;
15561 struct peer *conf;
15562 struct peer *peer;
d62a17ae 15563 afi_t afi;
15564 safi_t safi;
15565 const char *peer_status;
d62a17ae 15566 int lr_count;
15567 int dynamic;
6f4eacf3
DA
15568 bool af_cfgd;
15569 json_object *json_peer_group = NULL;
15570 json_object *json_peer_group_afc = NULL;
15571 json_object *json_peer_group_members = NULL;
15572 json_object *json_peer_group_dynamic = NULL;
15573 json_object *json_peer_group_dynamic_af = NULL;
15574 json_object *json_peer_group_ranges = NULL;
d62a17ae 15575
15576 conf = group->conf;
15577
6f4eacf3
DA
15578 if (json) {
15579 json_peer_group = json_object_new_object();
15580 json_peer_group_afc = json_object_new_array();
15581 }
15582
d62a17ae 15583 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15584 if (json)
15585 json_object_int_add(json_peer_group, "remoteAs",
15586 conf->as);
15587 else
15588 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15589 group->name, conf->as);
d62a17ae 15590 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15591 if (json)
15592 json_object_int_add(json_peer_group, "remoteAs",
15593 group->bgp->as);
15594 else
15595 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15596 group->name, group->bgp->as);
d62a17ae 15597 } else {
6f4eacf3
DA
15598 if (!json)
15599 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15600 }
f14e6fdb 15601
6f4eacf3
DA
15602 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15603 if (json)
15604 json_object_string_add(json_peer_group, "type",
15605 "internal");
15606 else
15607 vty_out(vty, " Peer-group type is internal\n");
15608 } else {
15609 if (json)
15610 json_object_string_add(json_peer_group, "type",
15611 "external");
15612 else
15613 vty_out(vty, " Peer-group type is external\n");
15614 }
d62a17ae 15615
15616 /* Display AFs configured. */
6f4eacf3
DA
15617 if (!json)
15618 vty_out(vty, " Configured address-families:");
15619
05c7a1cc
QY
15620 FOREACH_AFI_SAFI (afi, safi) {
15621 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15622 af_cfgd = true;
15623 if (json)
15624 json_object_array_add(
15625 json_peer_group_afc,
15626 json_object_new_string(get_afi_safi_str(
15627 afi, safi, false)));
15628 else
15629 vty_out(vty, " %s;",
15630 get_afi_safi_str(afi, safi, false));
d62a17ae 15631 }
05c7a1cc 15632 }
6f4eacf3
DA
15633
15634 if (json) {
15635 json_object_object_add(json_peer_group,
15636 "addressFamiliesConfigured",
15637 json_peer_group_afc);
15638 } else {
15639 if (!af_cfgd)
15640 vty_out(vty, " none\n");
15641 else
15642 vty_out(vty, "\n");
15643 }
d62a17ae 15644
15645 /* Display listen ranges (for dynamic neighbors), if any */
15646 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15647 lr_count = listcount(group->listen_range[afi]);
15648 if (lr_count) {
6f4eacf3
DA
15649 if (json) {
15650 if (!json_peer_group_dynamic)
15651 json_peer_group_dynamic =
15652 json_object_new_object();
15653
15654 json_peer_group_dynamic_af =
15655 json_object_new_object();
15656 json_peer_group_ranges =
15657 json_object_new_array();
15658 json_object_int_add(json_peer_group_dynamic_af,
15659 "count", lr_count);
15660 } else {
15661 vty_out(vty, " %d %s listen range(s)\n",
15662 lr_count, afi2str(afi));
15663 }
d62a17ae 15664
15665 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15666 nnode, range)) {
15667 if (json) {
15668 char buf[BUFSIZ];
15669
15670 snprintfrr(buf, sizeof(buf), "%pFX",
15671 range);
15672
15673 json_object_array_add(
15674 json_peer_group_ranges,
15675 json_object_new_string(buf));
15676 } else {
15677 vty_out(vty, " %pFX\n", range);
15678 }
15679 }
15680
15681 if (json) {
15682 json_object_object_add(
15683 json_peer_group_dynamic_af, "ranges",
15684 json_peer_group_ranges);
15685
15686 json_object_object_add(
15687 json_peer_group_dynamic, afi2str(afi),
15688 json_peer_group_dynamic_af);
15689 }
d62a17ae 15690 }
15691 }
f14e6fdb 15692
6f4eacf3
DA
15693 if (json_peer_group_dynamic)
15694 json_object_object_add(json_peer_group, "dynamicRanges",
15695 json_peer_group_dynamic);
15696
d62a17ae 15697 /* Display group members and their status */
15698 if (listcount(group->peer)) {
6f4eacf3
DA
15699 if (json)
15700 json_peer_group_members = json_object_new_object();
15701 else
15702 vty_out(vty, " Peer-group members:\n");
d62a17ae 15703 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15704 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15705 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15706 peer_status = "Idle (Admin)";
15707 else if (CHECK_FLAG(peer->sflags,
15708 PEER_STATUS_PREFIX_OVERFLOW))
15709 peer_status = "Idle (PfxCt)";
15710 else
15711 peer_status = lookup_msg(bgp_status_msg,
15712 peer->status, NULL);
15713
15714 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15715
15716 if (json) {
15717 json_object *json_peer_group_member =
15718 json_object_new_object();
15719
15720 json_object_string_add(json_peer_group_member,
15721 "status", peer_status);
15722
15723 if (dynamic)
15724 json_object_boolean_true_add(
15725 json_peer_group_member,
15726 "dynamic");
15727
15728 json_object_object_add(json_peer_group_members,
15729 peer->host,
15730 json_peer_group_member);
15731 } else {
15732 vty_out(vty, " %s %s %s \n", peer->host,
15733 dynamic ? "(dynamic)" : "",
15734 peer_status);
15735 }
d62a17ae 15736 }
6f4eacf3
DA
15737 if (json)
15738 json_object_object_add(json_peer_group, "members",
15739 json_peer_group_members);
d62a17ae 15740 }
f14e6fdb 15741
6f4eacf3
DA
15742 if (json)
15743 json_object_object_add(json, group->name, json_peer_group);
15744
d62a17ae 15745 return CMD_SUCCESS;
15746}
15747
ff9959b0 15748static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15749 const char *group_name, bool uj)
d62a17ae 15750{
ff9959b0 15751 struct bgp *bgp;
d62a17ae 15752 struct listnode *node, *nnode;
15753 struct peer_group *group;
ff9959b0 15754 bool found = false;
6f4eacf3
DA
15755 json_object *json = NULL;
15756
15757 if (uj)
15758 json = json_object_new_object();
ff9959b0
QY
15759
15760 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15761
15762 if (!bgp) {
6f4eacf3
DA
15763 if (uj) {
15764 vty_out(vty, "%s\n",
15765 json_object_to_json_string_ext(
15766 json, JSON_C_TO_STRING_PRETTY));
15767 json_object_free(json);
15768 } else {
15769 vty_out(vty, "%% BGP instance not found\n");
15770 }
15771
ff9959b0
QY
15772 return CMD_WARNING;
15773 }
d62a17ae 15774
15775 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15776 if (group_name) {
15777 if (strmatch(group->name, group_name)) {
6f4eacf3 15778 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15779 found = true;
15780 break;
d62a17ae 15781 }
ff9959b0 15782 } else {
6f4eacf3 15783 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15784 }
f14e6fdb 15785 }
f14e6fdb 15786
6f4eacf3 15787 if (group_name && !found && !uj)
d62a17ae 15788 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15789
6f4eacf3
DA
15790 if (uj) {
15791 vty_out(vty, "%s\n",
15792 json_object_to_json_string_ext(
15793 json, JSON_C_TO_STRING_PRETTY));
15794 json_object_free(json);
15795 }
15796
d62a17ae 15797 return CMD_SUCCESS;
f14e6fdb
DS
15798}
15799
6f4eacf3
DA
15800DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15801 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15802 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15803 "Detailed information on BGP peer groups\n"
15804 "Peer group name\n" JSON_STR)
f14e6fdb 15805{
d62a17ae 15806 char *vrf, *pg;
d62a17ae 15807 int idx = 0;
6f4eacf3 15808 bool uj = use_json(argc, argv);
f14e6fdb 15809
a4d82a8a
PZ
15810 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15811 : NULL;
d62a17ae 15812 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15813
6f4eacf3 15814 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15815}
3f9c7369 15816
d6e3c605 15817
718e3744 15818/* Redistribute VTY commands. */
15819
37a87b8f
CS
15820DEFUN_YANG (bgp_redistribute_ipv4,
15821 bgp_redistribute_ipv4_cmd,
15822 "redistribute " FRR_IP_REDIST_STR_BGPD,
15823 "Redistribute information from another routing protocol\n"
15824 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15825{
d62a17ae 15826 int idx_protocol = 1;
37a87b8f 15827 char base_xpath[XPATH_MAXLEN];
718e3744 15828
37a87b8f
CS
15829 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15830 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15831 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15832 argv[idx_protocol]->text, "0");
15833
15834 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 15835
37a87b8f 15836 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15837}
15838
d62a17ae 15839ALIAS_HIDDEN(
15840 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15841 "redistribute " FRR_IP_REDIST_STR_BGPD,
15842 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15843
37a87b8f
CS
15844DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15845 bgp_redistribute_ipv4_rmap_cmd,
15846 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15847 "Redistribute information from another routing protocol\n"
15848 FRR_IP_REDIST_HELP_STR_BGPD
15849 "Route map reference\n"
15850 "Pointer to route-map entries\n")
718e3744 15851{
d62a17ae 15852 int idx_protocol = 1;
15853 int idx_word = 3;
37a87b8f
CS
15854 char base_xpath[XPATH_MAXLEN];
15855
15856 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15857 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15858 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15859 argv[idx_protocol]->text, "0");
718e3744 15860
37a87b8f
CS
15861 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15862 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15863 argv[idx_word]->arg);
15864
15865 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15866}
15867
d62a17ae 15868ALIAS_HIDDEN(
15869 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15870 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15871 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15872 "Route map reference\n"
15873 "Pointer to route-map entries\n")
596c17ba 15874
37a87b8f
CS
15875DEFUN_YANG (bgp_redistribute_ipv4_metric,
15876 bgp_redistribute_ipv4_metric_cmd,
15877 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15878 "Redistribute information from another routing protocol\n"
15879 FRR_IP_REDIST_HELP_STR_BGPD
15880 "Metric for redistributed routes\n"
15881 "Default metric\n")
718e3744 15882{
d62a17ae 15883 int idx_protocol = 1;
15884 int idx_number = 3;
37a87b8f
CS
15885 char base_xpath[XPATH_MAXLEN];
15886
15887 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15888 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15889 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15890 argv[idx_protocol]->text, "0");
d62a17ae 15891
37a87b8f
CS
15892 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15893 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15894 argv[idx_number]->arg);
15895
15896 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15897}
15898
15899ALIAS_HIDDEN(
15900 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15901 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15902 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15903 "Metric for redistributed routes\n"
15904 "Default metric\n")
596c17ba 15905
37a87b8f
CS
15906DEFUN_YANG(
15907 bgp_redistribute_ipv4_rmap_metric,
15908 bgp_redistribute_ipv4_rmap_metric_cmd,
15909 "redistribute " FRR_IP_REDIST_STR_BGPD
15910 " route-map WORD metric (0-4294967295)",
15911 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15912 "Route map reference\n"
15913 "Pointer to route-map entries\n"
15914 "Metric for redistributed routes\n"
15915 "Default metric\n")
718e3744 15916{
d62a17ae 15917 int idx_protocol = 1;
15918 int idx_word = 3;
15919 int idx_number = 5;
37a87b8f
CS
15920 char base_xpath[XPATH_MAXLEN];
15921
15922 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15923 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15924 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15925 argv[idx_protocol]->text, "0");
15926
15927 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15928 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15929 argv[idx_word]->arg);
15930 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15931 argv[idx_number]->arg);
d62a17ae 15932
37a87b8f 15933 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15934}
15935
15936ALIAS_HIDDEN(
15937 bgp_redistribute_ipv4_rmap_metric,
15938 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15939 "redistribute " FRR_IP_REDIST_STR_BGPD
15940 " route-map WORD metric (0-4294967295)",
15941 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15942 "Route map reference\n"
15943 "Pointer to route-map entries\n"
15944 "Metric for redistributed routes\n"
15945 "Default metric\n")
596c17ba 15946
37a87b8f
CS
15947DEFUN_YANG(
15948 bgp_redistribute_ipv4_metric_rmap,
15949 bgp_redistribute_ipv4_metric_rmap_cmd,
15950 "redistribute " FRR_IP_REDIST_STR_BGPD
15951 " metric (0-4294967295) route-map WORD",
15952 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15953 "Metric for redistributed routes\n"
15954 "Default metric\n"
15955 "Route map reference\n"
15956 "Pointer to route-map entries\n")
718e3744 15957{
d62a17ae 15958 int idx_protocol = 1;
d62a17ae 15959 int idx_word = 5;
37a87b8f
CS
15960 int idx_number = 3;
15961 char base_xpath[XPATH_MAXLEN];
15962
15963 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15964 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15965 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15966 argv[idx_protocol]->text, "0");
15967
15968 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15969 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15970 argv[idx_number]->arg);
15971 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15972 argv[idx_word]->arg);
d62a17ae 15973
37a87b8f 15974 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15975}
15976
15977ALIAS_HIDDEN(
15978 bgp_redistribute_ipv4_metric_rmap,
15979 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15980 "redistribute " FRR_IP_REDIST_STR_BGPD
15981 " metric (0-4294967295) route-map WORD",
15982 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15983 "Metric for redistributed routes\n"
15984 "Default metric\n"
15985 "Route map reference\n"
15986 "Pointer to route-map entries\n")
596c17ba 15987
37a87b8f
CS
15988DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15989 bgp_redistribute_ipv4_ospf_cmd,
15990 "redistribute <ospf|table> (1-65535)",
15991 "Redistribute information from another routing protocol\n"
15992 "Open Shortest Path First (OSPFv2)\n"
15993 "Non-main Kernel Routing Table\n"
15994 "Instance ID/Table ID\n")
7c8ff89e 15995{
37a87b8f 15996 int idx_protocol = 1;
d62a17ae 15997 int idx_number = 2;
37a87b8f 15998 char base_xpath[XPATH_MAXLEN];
7c8ff89e 15999
37a87b8f
CS
16000 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16001 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16002 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16003 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 16004
37a87b8f 16005 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 16006
37a87b8f 16007 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
16008}
16009
d62a17ae 16010ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16011 "redistribute <ospf|table> (1-65535)",
16012 "Redistribute information from another routing protocol\n"
16013 "Open Shortest Path First (OSPFv2)\n"
16014 "Non-main Kernel Routing Table\n"
16015 "Instance ID/Table ID\n")
596c17ba 16016
37a87b8f
CS
16017DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
16018 bgp_redistribute_ipv4_ospf_rmap_cmd,
16019 "redistribute <ospf|table> (1-65535) route-map WORD",
16020 "Redistribute information from another routing protocol\n"
16021 "Open Shortest Path First (OSPFv2)\n"
16022 "Non-main Kernel Routing Table\n"
16023 "Instance ID/Table ID\n"
16024 "Route map reference\n"
16025 "Pointer to route-map entries\n")
7c8ff89e 16026{
37a87b8f 16027 int idx_protocol = 1;
d62a17ae 16028 int idx_number = 2;
16029 int idx_word = 4;
37a87b8f
CS
16030 char base_xpath[XPATH_MAXLEN];
16031
16032 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16033 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16034 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16035 argv[idx_protocol]->text, argv[idx_number]->arg);
16036
16037 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16038
16039 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16040 argv[idx_word]->arg);
d62a17ae 16041
37a87b8f 16042 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16043}
16044
16045ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16046 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16047 "redistribute <ospf|table> (1-65535) route-map WORD",
16048 "Redistribute information from another routing protocol\n"
16049 "Open Shortest Path First (OSPFv2)\n"
16050 "Non-main Kernel Routing Table\n"
16051 "Instance ID/Table ID\n"
16052 "Route map reference\n"
16053 "Pointer to route-map entries\n")
596c17ba 16054
37a87b8f
CS
16055DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
16056 bgp_redistribute_ipv4_ospf_metric_cmd,
16057 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16058 "Redistribute information from another routing protocol\n"
16059 "Open Shortest Path First (OSPFv2)\n"
16060 "Non-main Kernel Routing Table\n"
16061 "Instance ID/Table ID\n"
16062 "Metric for redistributed routes\n"
16063 "Default metric\n")
7c8ff89e 16064{
37a87b8f 16065 int idx_protocol = 1;
d62a17ae 16066 int idx_number = 2;
16067 int idx_number_2 = 4;
37a87b8f
CS
16068 char base_xpath[XPATH_MAXLEN];
16069
16070 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16071 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16072 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16073 argv[idx_protocol]->text, argv[idx_number]->arg);
16074
16075 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16076
37a87b8f
CS
16077 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16078 argv[idx_number_2]->arg);
d62a17ae 16079
37a87b8f 16080 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16081}
16082
16083ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16084 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16085 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16086 "Redistribute information from another routing protocol\n"
16087 "Open Shortest Path First (OSPFv2)\n"
16088 "Non-main Kernel Routing Table\n"
16089 "Instance ID/Table ID\n"
16090 "Metric for redistributed routes\n"
16091 "Default metric\n")
596c17ba 16092
37a87b8f
CS
16093DEFUN_YANG(
16094 bgp_redistribute_ipv4_ospf_rmap_metric,
16095 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16096 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16097 "Redistribute information from another routing protocol\n"
16098 "Open Shortest Path First (OSPFv2)\n"
16099 "Non-main Kernel Routing Table\n"
16100 "Instance ID/Table ID\n"
16101 "Route map reference\n"
16102 "Pointer to route-map entries\n"
16103 "Metric for redistributed routes\n"
16104 "Default metric\n")
7c8ff89e 16105{
37a87b8f 16106 int idx_protocol = 1;
d62a17ae 16107 int idx_number = 2;
16108 int idx_word = 4;
16109 int idx_number_2 = 6;
37a87b8f
CS
16110 char base_xpath[XPATH_MAXLEN];
16111
16112 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16113 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16114 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16115 argv[idx_protocol]->text, argv[idx_number]->arg);
16116
16117 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16118
37a87b8f
CS
16119 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16120 argv[idx_word]->arg);
16121 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16122 argv[idx_number_2]->arg);
d62a17ae 16123
37a87b8f 16124 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16125}
16126
16127ALIAS_HIDDEN(
16128 bgp_redistribute_ipv4_ospf_rmap_metric,
16129 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16130 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16131 "Redistribute information from another routing protocol\n"
16132 "Open Shortest Path First (OSPFv2)\n"
16133 "Non-main Kernel Routing Table\n"
16134 "Instance ID/Table ID\n"
16135 "Route map reference\n"
16136 "Pointer to route-map entries\n"
16137 "Metric for redistributed routes\n"
16138 "Default metric\n")
596c17ba 16139
37a87b8f
CS
16140DEFUN_YANG(
16141 bgp_redistribute_ipv4_ospf_metric_rmap,
16142 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16143 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16144 "Redistribute information from another routing protocol\n"
16145 "Open Shortest Path First (OSPFv2)\n"
16146 "Non-main Kernel Routing Table\n"
16147 "Instance ID/Table ID\n"
16148 "Metric for redistributed routes\n"
16149 "Default metric\n"
16150 "Route map reference\n"
16151 "Pointer to route-map entries\n")
7c8ff89e 16152{
37a87b8f 16153 int idx_protocol = 1;
d62a17ae 16154 int idx_number = 2;
16155 int idx_number_2 = 4;
16156 int idx_word = 6;
37a87b8f
CS
16157 char base_xpath[XPATH_MAXLEN];
16158
16159 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16160 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16161 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16162 argv[idx_protocol]->text, argv[idx_number]->arg);
16163
16164 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16165
37a87b8f
CS
16166 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16167 argv[idx_number_2]->arg);
16168 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16169 argv[idx_word]->arg);
d62a17ae 16170
37a87b8f 16171 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16172}
16173
16174ALIAS_HIDDEN(
16175 bgp_redistribute_ipv4_ospf_metric_rmap,
16176 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16177 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16178 "Redistribute information from another routing protocol\n"
16179 "Open Shortest Path First (OSPFv2)\n"
16180 "Non-main Kernel Routing Table\n"
16181 "Instance ID/Table ID\n"
16182 "Metric for redistributed routes\n"
16183 "Default metric\n"
16184 "Route map reference\n"
16185 "Pointer to route-map entries\n")
596c17ba 16186
37a87b8f
CS
16187DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
16188 no_bgp_redistribute_ipv4_ospf_cmd,
16189 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16190 NO_STR
16191 "Redistribute information from another routing protocol\n"
16192 "Open Shortest Path First (OSPFv2)\n"
16193 "Non-main Kernel Routing Table\n"
16194 "Instance ID/Table ID\n"
16195 "Metric for redistributed routes\n"
16196 "Default metric\n"
16197 "Route map reference\n"
16198 "Pointer to route-map entries\n")
7c8ff89e 16199{
37a87b8f 16200 int idx_protocol = 2;
d62a17ae 16201 int idx_number = 3;
37a87b8f 16202 char base_xpath[XPATH_MAXLEN];
d62a17ae 16203
37a87b8f
CS
16204 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16205 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16206 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16207 argv[idx_protocol]->text, argv[idx_number]->arg);
16208
16209 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 16210
37a87b8f 16211 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16212}
16213
16214ALIAS_HIDDEN(
16215 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 16216 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16217 NO_STR
16218 "Redistribute information from another routing protocol\n"
16219 "Open Shortest Path First (OSPFv2)\n"
16220 "Non-main Kernel Routing Table\n"
16221 "Instance ID/Table ID\n"
16222 "Metric for redistributed routes\n"
16223 "Default metric\n"
16224 "Route map reference\n"
16225 "Pointer to route-map entries\n")
596c17ba 16226
37a87b8f
CS
16227DEFUN_YANG (no_bgp_redistribute_ipv4,
16228 no_bgp_redistribute_ipv4_cmd,
16229 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16230 NO_STR
16231 "Redistribute information from another routing protocol\n"
16232 FRR_IP_REDIST_HELP_STR_BGPD
16233 "Metric for redistributed routes\n"
16234 "Default metric\n"
16235 "Route map reference\n"
16236 "Pointer to route-map entries\n")
718e3744 16237{
d62a17ae 16238 int idx_protocol = 2;
37a87b8f 16239 char base_xpath[XPATH_MAXLEN];
d62a17ae 16240
37a87b8f
CS
16241 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16242 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16243 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16244 argv[idx_protocol]->text, "0");
16245
16246 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16247
16248 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16249}
16250
16251ALIAS_HIDDEN(
16252 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16253 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 16254 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16255 NO_STR
16256 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16257 "Metric for redistributed routes\n"
16258 "Default metric\n"
16259 "Route map reference\n"
16260 "Pointer to route-map entries\n")
596c17ba 16261
37a87b8f
CS
16262DEFUN_YANG (bgp_redistribute_ipv6,
16263 bgp_redistribute_ipv6_cmd,
16264 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16265 "Redistribute information from another routing protocol\n"
16266 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16267{
d62a17ae 16268 int idx_protocol = 1;
37a87b8f 16269 char base_xpath[XPATH_MAXLEN];
718e3744 16270
37a87b8f
CS
16271 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16272 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16273 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16274 argv[idx_protocol]->text, "0");
16275
16276 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 16277
37a87b8f 16278 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16279}
16280
37a87b8f
CS
16281DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16282 bgp_redistribute_ipv6_rmap_cmd,
16283 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16284 "Redistribute information from another routing protocol\n"
16285 FRR_IP6_REDIST_HELP_STR_BGPD
16286 "Route map reference\n"
16287 "Pointer to route-map entries\n")
718e3744 16288{
d62a17ae 16289 int idx_protocol = 1;
16290 int idx_word = 3;
37a87b8f
CS
16291 char base_xpath[XPATH_MAXLEN];
16292
16293 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16294 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16295 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16296 argv[idx_protocol]->text, "0");
718e3744 16297
37a87b8f
CS
16298 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16299 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16300 argv[idx_word]->arg);
16301
16302 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16303}
16304
37a87b8f 16305DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 16306 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16307 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16308 "Redistribute information from another routing protocol\n"
ab0181ee 16309 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16310 "Metric for redistributed routes\n"
16311 "Default metric\n")
16312{
d62a17ae 16313 int idx_protocol = 1;
16314 int idx_number = 3;
37a87b8f
CS
16315 char base_xpath[XPATH_MAXLEN];
16316
16317 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16318 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16319 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16320 argv[idx_protocol]->text, "0");
718e3744 16321
37a87b8f
CS
16322 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16323 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16324 argv[idx_number]->arg);
16325
16326 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16327}
16328
37a87b8f
CS
16329DEFUN_YANG(
16330 bgp_redistribute_ipv6_rmap_metric,
16331 bgp_redistribute_ipv6_rmap_metric_cmd,
16332 "redistribute " FRR_IP6_REDIST_STR_BGPD
16333 " route-map WORD metric (0-4294967295)",
16334 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16335 "Route map reference\n"
16336 "Pointer to route-map entries\n"
16337 "Metric for redistributed routes\n"
16338 "Default metric\n")
718e3744 16339{
d62a17ae 16340 int idx_protocol = 1;
16341 int idx_word = 3;
16342 int idx_number = 5;
37a87b8f
CS
16343 char base_xpath[XPATH_MAXLEN];
16344
16345 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16346 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16347 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16348 argv[idx_protocol]->text, "0");
718e3744 16349
37a87b8f
CS
16350 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16351 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16352 argv[idx_word]->arg);
16353 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16354 argv[idx_number]->arg);
16355
16356 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16357}
16358
37a87b8f
CS
16359DEFUN_YANG(
16360 bgp_redistribute_ipv6_metric_rmap,
16361 bgp_redistribute_ipv6_metric_rmap_cmd,
16362 "redistribute " FRR_IP6_REDIST_STR_BGPD
16363 " metric (0-4294967295) route-map WORD",
16364 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16365 "Metric for redistributed routes\n"
16366 "Default metric\n"
16367 "Route map reference\n"
16368 "Pointer to route-map entries\n")
718e3744 16369{
d62a17ae 16370 int idx_protocol = 1;
d62a17ae 16371 int idx_word = 5;
37a87b8f
CS
16372 int idx_number = 3;
16373 char base_xpath[XPATH_MAXLEN];
16374
16375 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16376 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16377 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16378 argv[idx_protocol]->text, "0");
718e3744 16379
37a87b8f
CS
16380 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16381 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16382 argv[idx_number]->arg);
16383 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16384 argv[idx_word]->arg);
16385
16386 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16387}
16388
37a87b8f
CS
16389DEFUN_YANG(
16390 no_bgp_redistribute_ipv6,
16391 no_bgp_redistribute_ipv6_cmd,
16392 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16393 " [{metric (0-4294967295)|route-map WORD}]",
16394 NO_STR
16395 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16396 "Metric for redistributed routes\n"
16397 "Default metric\n"
16398 "Route map reference\n"
16399 "Pointer to route-map entries\n")
718e3744 16400{
d62a17ae 16401 int idx_protocol = 2;
37a87b8f 16402 char base_xpath[XPATH_MAXLEN];
718e3744 16403
37a87b8f
CS
16404 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16405 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16406 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16407 argv[idx_protocol]->text, "0");
16408
16409 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16410
16411 return nb_cli_apply_changes(vty, base_xpath);
16412}
718e3744 16413
37a87b8f
CS
16414void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16415 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16416{
16417 uint32_t instance = 0;
16418
16419 vty_out(vty, " redistribute %s",
16420 yang_dnode_get_string(dnode, "./route-type"));
16421 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16422 vty_out(vty, " %d", instance);
16423 if (yang_dnode_exists(dnode, "./metric"))
16424 vty_out(vty, " metric %u",
16425 yang_dnode_get_uint32(dnode, "./metric"));
16426 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16427 vty_out(vty, " route-map %s",
16428 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16429 vty_out(vty, "\n");
d62a17ae 16430}
16431
4ab46701
AR
16432/* Neighbor update tcp-mss. */
16433static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16434 const char *tcp_mss_str)
16435{
16436 struct peer *peer;
16437 uint32_t tcp_mss_val = 0;
16438
16439 peer = peer_and_group_lookup_vty(vty, peer_str);
16440 if (!peer)
16441 return CMD_WARNING_CONFIG_FAILED;
16442
16443 if (tcp_mss_str) {
16444 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16445 peer_tcp_mss_set(peer, tcp_mss_val);
16446 } else {
16447 peer_tcp_mss_unset(peer);
16448 }
16449
16450 return CMD_SUCCESS;
16451}
16452
16453DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16454 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16455 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16456 "TCP max segment size\n"
16457 "TCP MSS value\n")
16458{
16459 int peer_index = 1;
16460 int mss_index = 3;
16461
16462 vty_out(vty,
16463 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16464 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16465 argv[mss_index]->arg);
16466}
16467
16468DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16469 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16470 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16471 "TCP max segment size\n"
16472 "TCP MSS value\n")
16473{
16474 int peer_index = 2;
16475
16476 vty_out(vty,
16477 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16478 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16479}
16480
dd65f45e
DL
16481static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16482 afi_t afi, safi_t safi)
d62a17ae 16483{
16484 int i;
16485
16486 /* Unicast redistribution only. */
16487 if (safi != SAFI_UNICAST)
2b791107 16488 return;
d62a17ae 16489
16490 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16491 /* Redistribute BGP does not make sense. */
16492 if (i != ZEBRA_ROUTE_BGP) {
16493 struct list *red_list;
16494 struct listnode *node;
16495 struct bgp_redist *red;
16496
16497 red_list = bgp->redist[afi][i];
16498 if (!red_list)
16499 continue;
16500
16501 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16502 /* "redistribute" configuration. */
16503 vty_out(vty, " redistribute %s",
16504 zebra_route_string(i));
16505 if (red->instance)
16506 vty_out(vty, " %d", red->instance);
16507 if (red->redist_metric_flag)
16508 vty_out(vty, " metric %u",
16509 red->redist_metric);
16510 if (red->rmap.name)
16511 vty_out(vty, " route-map %s",
16512 red->rmap.name);
16513 vty_out(vty, "\n");
16514 }
16515 }
16516 }
718e3744 16517}
6b0655a2 16518
dd65f45e
DL
16519/* peer-group helpers for config-write */
16520
16521static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16522{
16523 if (!peer_group_active(peer)) {
16524 if (CHECK_FLAG(peer->flags_invert, flag))
16525 return !CHECK_FLAG(peer->flags, flag);
16526 else
16527 return !!CHECK_FLAG(peer->flags, flag);
16528 }
16529
16530 return !!CHECK_FLAG(peer->flags_override, flag);
16531}
16532
16533static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16534 uint32_t flag)
16535{
16536 if (!peer_group_active(peer)) {
16537 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16538 return !peer_af_flag_check(peer, afi, safi, flag);
16539 else
16540 return !!peer_af_flag_check(peer, afi, safi, flag);
16541 }
16542
16543 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16544}
16545
16546static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16547 uint8_t type, int direct)
16548{
16549 struct bgp_filter *filter;
16550
16551 if (peer_group_active(peer))
16552 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16553 type);
16554
16555 filter = &peer->filter[afi][safi];
16556 switch (type) {
16557 case PEER_FT_DISTRIBUTE_LIST:
16558 return !!(filter->dlist[direct].name);
16559 case PEER_FT_FILTER_LIST:
16560 return !!(filter->aslist[direct].name);
16561 case PEER_FT_PREFIX_LIST:
16562 return !!(filter->plist[direct].name);
16563 case PEER_FT_ROUTE_MAP:
16564 return !!(filter->map[direct].name);
16565 case PEER_FT_UNSUPPRESS_MAP:
16566 return !!(filter->usmap.name);
7f7940e6
MK
16567 case PEER_FT_ADVERTISE_MAP:
16568 return !!(filter->advmap.aname
16569 && ((filter->advmap.condition == direct)
16570 && filter->advmap.cname));
dd65f45e
DL
16571 default:
16572 return false;
16573 }
16574}
16575
16576/* Return true if the addpath type is set for peer and different from
16577 * peer-group.
16578 */
3dc339cd
DA
16579static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16580 safi_t safi)
dd65f45e
DL
16581{
16582 enum bgp_addpath_strat type, g_type;
16583
16584 type = peer->addpath_type[afi][safi];
16585
16586 if (type != BGP_ADDPATH_NONE) {
16587 if (peer_group_active(peer)) {
16588 g_type = peer->group->conf->addpath_type[afi][safi];
16589
16590 if (type != g_type)
3dc339cd 16591 return true;
dd65f45e 16592 else
3dc339cd 16593 return false;
dd65f45e
DL
16594 }
16595
3dc339cd 16596 return true;
dd65f45e
DL
16597 }
16598
3dc339cd 16599 return false;
dd65f45e
DL
16600}
16601
b9c7bc5a 16602/* This is part of the address-family block (unicast only) */
dd65f45e 16603static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16604 afi_t afi)
16605{
b9c7bc5a 16606 int indent = 2;
ddb5b488 16607
8a066a70 16608 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16609 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16610 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16611 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16612 bgp->vpn_policy[afi]
bb4f6190 16613 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16614 else
16615 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16616 bgp->vpn_policy[afi]
16617 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16618 }
12a844a5
DS
16619 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16620 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16621 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16622 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16623 return;
16624
e70e9f8e
PZ
16625 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16626 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16627
16628 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16629
16630 } else {
16631 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16632 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16633 bgp->vpn_policy[afi].tovpn_label);
16634 }
ddb5b488
PZ
16635 }
16636 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16637 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16638 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16639 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16640 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16641 sizeof(buf)));
16642 }
16643 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16644 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16645
16646 char buf[PREFIX_STRLEN];
16647 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16648 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16649 sizeof(buf))) {
16650
b9c7bc5a
PZ
16651 vty_out(vty, "%*snexthop vpn export %s\n",
16652 indent, "", buf);
ddb5b488
PZ
16653 }
16654 }
16655 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16656 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16657 && ecommunity_cmp(
16658 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16659 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16660
16661 char *b = ecommunity_ecom2str(
16662 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16663 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16664 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16665 XFREE(MTYPE_ECOMMUNITY_STR, b);
16666 } else {
16667 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16668 char *b = ecommunity_ecom2str(
16669 bgp->vpn_policy[afi]
16670 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16671 ECOMMUNITY_FORMAT_ROUTE_MAP,
16672 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16673 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16674 XFREE(MTYPE_ECOMMUNITY_STR, b);
16675 }
16676 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16677 char *b = ecommunity_ecom2str(
16678 bgp->vpn_policy[afi]
16679 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16680 ECOMMUNITY_FORMAT_ROUTE_MAP,
16681 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16682 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16683 XFREE(MTYPE_ECOMMUNITY_STR, b);
16684 }
16685 }
bb4f6190
DS
16686
16687 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16688 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16689 bgp->vpn_policy[afi]
16690 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16691
301ad80a
PG
16692 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16693 char *b = ecommunity_ecom2str(
16694 bgp->vpn_policy[afi]
16695 .import_redirect_rtlist,
16696 ECOMMUNITY_FORMAT_ROUTE_MAP,
16697 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16698
9a659715
PG
16699 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16700 != ECOMMUNITY_SIZE)
c6423c31 16701 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16702 indent, "", b);
16703 else
16704 vty_out(vty, "%*srt redirect import %s\n",
16705 indent, "", b);
301ad80a
PG
16706 XFREE(MTYPE_ECOMMUNITY_STR, b);
16707 }
ddb5b488
PZ
16708}
16709
dd65f45e
DL
16710static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16711 afi_t afi, safi_t safi)
16712{
16713 struct bgp_filter *filter;
16714 char *addr;
16715
16716 addr = peer->host;
16717 filter = &peer->filter[afi][safi];
16718
16719 /* distribute-list. */
16720 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16721 FILTER_IN))
16722 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16723 filter->dlist[FILTER_IN].name);
16724
16725 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16726 FILTER_OUT))
16727 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16728 filter->dlist[FILTER_OUT].name);
16729
16730 /* prefix-list. */
16731 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16732 FILTER_IN))
16733 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16734 filter->plist[FILTER_IN].name);
16735
16736 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16737 FILTER_OUT))
16738 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16739 filter->plist[FILTER_OUT].name);
16740
16741 /* route-map. */
16742 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16743 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16744 filter->map[RMAP_IN].name);
16745
16746 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16747 RMAP_OUT))
16748 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16749 filter->map[RMAP_OUT].name);
16750
16751 /* unsuppress-map */
16752 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16753 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16754 filter->usmap.name);
16755
7f7940e6
MK
16756 /* advertise-map : always applied in OUT direction*/
16757 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16758 CONDITION_NON_EXIST))
16759 vty_out(vty,
16760 " neighbor %s advertise-map %s non-exist-map %s\n",
16761 addr, filter->advmap.aname, filter->advmap.cname);
16762
16763 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16764 CONDITION_EXIST))
16765 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16766 addr, filter->advmap.aname, filter->advmap.cname);
16767
dd65f45e
DL
16768 /* filter-list. */
16769 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16770 FILTER_IN))
16771 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16772 filter->aslist[FILTER_IN].name);
16773
16774 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16775 FILTER_OUT))
16776 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16777 filter->aslist[FILTER_OUT].name);
16778}
16779
16780/* BGP peer configuration display function. */
16781static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16782 struct peer *peer)
16783{
16784 struct peer *g_peer = NULL;
16785 char buf[SU_ADDRSTRLEN];
16786 char *addr;
16787 int if_pg_printed = false;
16788 int if_ras_printed = false;
16789
16790 /* Skip dynamic neighbors. */
16791 if (peer_dynamic_neighbor(peer))
16792 return;
16793
16794 if (peer->conf_if)
16795 addr = peer->conf_if;
16796 else
16797 addr = peer->host;
16798
16799 /************************************
16800 ****** Global to the neighbor ******
16801 ************************************/
16802 if (peer->conf_if) {
16803 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16804 vty_out(vty, " neighbor %s interface v6only", addr);
16805 else
16806 vty_out(vty, " neighbor %s interface", addr);
16807
16808 if (peer_group_active(peer)) {
16809 vty_out(vty, " peer-group %s", peer->group->name);
16810 if_pg_printed = true;
16811 } else if (peer->as_type == AS_SPECIFIED) {
16812 vty_out(vty, " remote-as %u", peer->as);
16813 if_ras_printed = true;
16814 } else if (peer->as_type == AS_INTERNAL) {
16815 vty_out(vty, " remote-as internal");
16816 if_ras_printed = true;
16817 } else if (peer->as_type == AS_EXTERNAL) {
16818 vty_out(vty, " remote-as external");
16819 if_ras_printed = true;
16820 }
16821
16822 vty_out(vty, "\n");
16823 }
16824
16825 /* remote-as and peer-group */
16826 /* peer is a member of a peer-group */
16827 if (peer_group_active(peer)) {
16828 g_peer = peer->group->conf;
16829
16830 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16831 if (peer->as_type == AS_SPECIFIED) {
16832 vty_out(vty, " neighbor %s remote-as %u\n",
16833 addr, peer->as);
16834 } else if (peer->as_type == AS_INTERNAL) {
16835 vty_out(vty,
16836 " neighbor %s remote-as internal\n",
16837 addr);
16838 } else if (peer->as_type == AS_EXTERNAL) {
16839 vty_out(vty,
16840 " neighbor %s remote-as external\n",
16841 addr);
16842 }
16843 }
16844
16845 /* For swpX peers we displayed the peer-group
16846 * via 'neighbor swpX interface peer-group PGNAME' */
16847 if (!if_pg_printed)
16848 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16849 peer->group->name);
16850 }
16851
16852 /* peer is NOT a member of a peer-group */
16853 else {
16854 /* peer is a peer-group, declare the peer-group */
16855 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16856 vty_out(vty, " neighbor %s peer-group\n", addr);
16857 }
16858
16859 if (!if_ras_printed) {
16860 if (peer->as_type == AS_SPECIFIED) {
16861 vty_out(vty, " neighbor %s remote-as %u\n",
16862 addr, peer->as);
16863 } else if (peer->as_type == AS_INTERNAL) {
16864 vty_out(vty,
16865 " neighbor %s remote-as internal\n",
16866 addr);
16867 } else if (peer->as_type == AS_EXTERNAL) {
16868 vty_out(vty,
16869 " neighbor %s remote-as external\n",
16870 addr);
16871 }
16872 }
16873 }
16874
16875 /* local-as */
16876 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16877 vty_out(vty, " neighbor %s local-as %u", addr,
16878 peer->change_local_as);
16879 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16880 vty_out(vty, " no-prepend");
16881 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16882 vty_out(vty, " replace-as");
16883 vty_out(vty, "\n");
16884 }
16885
16886 /* description */
16887 if (peer->desc) {
16888 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16889 }
16890
16891 /* shutdown */
16892 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16893 if (peer->tx_shutdown_message)
16894 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16895 peer->tx_shutdown_message);
16896 else
16897 vty_out(vty, " neighbor %s shutdown\n", addr);
16898 }
16899
8336c896
DA
16900 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16901 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16902 peer->rtt_expected, peer->rtt_keepalive_conf);
16903
dd65f45e 16904 /* bfd */
21bfce98
RZ
16905 if (peer->bfd_config)
16906 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16907
16908 /* password */
16909 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16910 vty_out(vty, " neighbor %s password %s\n", addr,
16911 peer->password);
16912
16913 /* neighbor solo */
16914 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16915 if (!peer_group_active(peer)) {
16916 vty_out(vty, " neighbor %s solo\n", addr);
16917 }
16918 }
16919
16920 /* BGP port */
16921 if (peer->port != BGP_PORT_DEFAULT) {
16922 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16923 }
16924
16925 /* Local interface name */
16926 if (peer->ifname) {
16927 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16928 }
16929
4ab46701
AR
16930 /* TCP max segment size */
16931 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16932 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16933
dd65f45e
DL
16934 /* passive */
16935 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16936 vty_out(vty, " neighbor %s passive\n", addr);
16937
16938 /* ebgp-multihop */
16939 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16940 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16941 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16942 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16943 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16944 peer->ttl);
16945 }
16946 }
16947
16948 /* ttl-security hops */
e2521429 16949 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16950 if (!peer_group_active(peer)
16951 || g_peer->gtsm_hops != peer->gtsm_hops) {
16952 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16953 addr, peer->gtsm_hops);
16954 }
16955 }
16956
16957 /* disable-connected-check */
16958 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16959 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16960
16961 /* enforce-first-as */
16962 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16963 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16964
16965 /* update-source */
16966 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16967 if (peer->update_source)
16968 vty_out(vty, " neighbor %s update-source %s\n", addr,
16969 sockunion2str(peer->update_source, buf,
16970 SU_ADDRSTRLEN));
16971 else if (peer->update_if)
16972 vty_out(vty, " neighbor %s update-source %s\n", addr,
16973 peer->update_if);
16974 }
16975
16976 /* advertisement-interval */
16977 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16978 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16979 peer->routeadv);
16980
16981 /* timers */
16982 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16983 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16984 peer->keepalive, peer->holdtime);
16985
16986 /* timers connect */
16987 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16988 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16989 peer->connect);
5d5393b9
DL
16990 /* need special-case handling for changed default values due to
16991 * config profile / version (because there is no "timers bgp connect"
16992 * command, we need to save this per-peer :/)
16993 */
16994 else if (!peer_group_active(peer) && !peer->connect &&
16995 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16996 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16997 peer->bgp->default_connect_retry);
dd65f45e 16998
d43114f3
DS
16999 /* timers delayopen */
17000 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17001 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17002 peer->delayopen);
17003 /* Save config even though flag is not set if default values have been
17004 * changed
17005 */
17006 else if (!peer_group_active(peer) && !peer->delayopen
17007 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17008 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17009 peer->bgp->default_delayopen);
17010
dd65f45e
DL
17011 /* capability dynamic */
17012 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17013 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17014
17015 /* capability extended-nexthop */
17016 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17017 if (!peer->conf_if) {
17018 if (CHECK_FLAG(peer->flags_invert,
17019 PEER_FLAG_CAPABILITY_ENHE))
17020 vty_out(vty,
17021 " no neighbor %s capability extended-nexthop\n",
17022 addr);
17023 else
17024 vty_out(vty,
17025 " neighbor %s capability extended-nexthop\n",
17026 addr);
17027 }
17028 }
17029
17030 /* dont-capability-negotiation */
17031 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17032 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17033
17034 /* override-capability */
17035 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17036 vty_out(vty, " neighbor %s override-capability\n", addr);
17037
17038 /* strict-capability-match */
17039 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17040 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17041
17042 /* Sender side AS path loop detection. */
17043 if (peer->as_path_loop_detection)
17044 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17045 addr);
cfd47646 17046
17047 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17048 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17049
17050 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17051 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17052 vty_out(vty,
17053 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17054 } else if (CHECK_FLAG(
17055 peer->peer_gr_new_status_flag,
17056 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17057 vty_out(vty,
17058 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17059 } else if (
17060 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17061 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17062 && !(CHECK_FLAG(
17063 peer->peer_gr_new_status_flag,
17064 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17065 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17066 addr);
cfd47646 17067 }
17068 }
dd65f45e
DL
17069}
17070
17071/* BGP peer configuration display function. */
17072static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17073 struct peer *peer, afi_t afi, safi_t safi)
17074{
17075 struct peer *g_peer = NULL;
17076 char *addr;
17077 bool flag_scomm, flag_secomm, flag_slcomm;
17078
17079 /* Skip dynamic neighbors. */
17080 if (peer_dynamic_neighbor(peer))
17081 return;
17082
17083 if (peer->conf_if)
17084 addr = peer->conf_if;
17085 else
17086 addr = peer->host;
17087
17088 /************************************
17089 ****** Per AF to the neighbor ******
17090 ************************************/
17091 if (peer_group_active(peer)) {
17092 g_peer = peer->group->conf;
17093
17094 /* If the peer-group is active but peer is not, print a 'no
17095 * activate' */
17096 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17097 vty_out(vty, " no neighbor %s activate\n", addr);
17098 }
17099
17100 /* If the peer-group is not active but peer is, print an
17101 'activate' */
17102 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17103 vty_out(vty, " neighbor %s activate\n", addr);
17104 }
17105 } else {
17106 if (peer->afc[afi][safi]) {
e84c59af
DA
17107 if ((afi == AFI_IP || afi == AFI_IP6)
17108 && safi == SAFI_UNICAST) {
17109 if (afi == AFI_IP
17110 && CHECK_FLAG(bgp->flags,
17111 BGP_FLAG_NO_DEFAULT_IPV4)) {
17112 vty_out(vty, " neighbor %s activate\n",
17113 addr);
17114 } else if (afi == AFI_IP6
17115 && !CHECK_FLAG(
17116 bgp->flags,
17117 BGP_FLAG_DEFAULT_IPV6)) {
dd65f45e
DL
17118 vty_out(vty, " neighbor %s activate\n",
17119 addr);
17120 }
e84c59af 17121 } else {
dd65f45e 17122 vty_out(vty, " neighbor %s activate\n", addr);
e84c59af 17123 }
dd65f45e 17124 } else {
e84c59af
DA
17125 if ((afi == AFI_IP || afi == AFI_IP6)
17126 && safi == SAFI_UNICAST) {
17127 if (afi == AFI_IP
17128 && !CHECK_FLAG(bgp->flags,
17129 BGP_FLAG_NO_DEFAULT_IPV4)) {
17130 vty_out(vty,
17131 " no neighbor %s activate\n",
17132 addr);
17133 } else if (afi == AFI_IP6
17134 && CHECK_FLAG(
17135 bgp->flags,
17136 BGP_FLAG_DEFAULT_IPV6)) {
dd65f45e
DL
17137 vty_out(vty,
17138 " no neighbor %s activate\n",
17139 addr);
17140 }
17141 }
17142 }
17143 }
17144
17145 /* addpath TX knobs */
17146 if (peergroup_af_addpath_check(peer, afi, safi)) {
17147 switch (peer->addpath_type[afi][safi]) {
17148 case BGP_ADDPATH_ALL:
17149 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17150 addr);
17151 break;
17152 case BGP_ADDPATH_BEST_PER_AS:
17153 vty_out(vty,
17154 " neighbor %s addpath-tx-bestpath-per-AS\n",
17155 addr);
17156 break;
17157 case BGP_ADDPATH_MAX:
17158 case BGP_ADDPATH_NONE:
17159 break;
17160 }
17161 }
17162
17163 /* ORF capability. */
17164 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17165 || peergroup_af_flag_check(peer, afi, safi,
17166 PEER_FLAG_ORF_PREFIX_RM)) {
17167 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17168
17169 if (peergroup_af_flag_check(peer, afi, safi,
17170 PEER_FLAG_ORF_PREFIX_SM)
17171 && peergroup_af_flag_check(peer, afi, safi,
17172 PEER_FLAG_ORF_PREFIX_RM))
17173 vty_out(vty, " both");
17174 else if (peergroup_af_flag_check(peer, afi, safi,
17175 PEER_FLAG_ORF_PREFIX_SM))
17176 vty_out(vty, " send");
17177 else
17178 vty_out(vty, " receive");
17179 vty_out(vty, "\n");
17180 }
17181
dd65f45e
DL
17182 /* Route reflector client. */
17183 if (peergroup_af_flag_check(peer, afi, safi,
17184 PEER_FLAG_REFLECTOR_CLIENT)) {
17185 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17186 }
17187
17188 /* next-hop-self force */
17189 if (peergroup_af_flag_check(peer, afi, safi,
17190 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17191 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17192 }
17193
17194 /* next-hop-self */
17195 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17196 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17197 }
17198
17199 /* remove-private-AS */
17200 if (peergroup_af_flag_check(peer, afi, safi,
17201 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17202 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17203 addr);
17204 }
17205
17206 else if (peergroup_af_flag_check(peer, afi, safi,
17207 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17208 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17209 addr);
17210 }
17211
17212 else if (peergroup_af_flag_check(peer, afi, safi,
17213 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17214 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17215 }
17216
17217 else if (peergroup_af_flag_check(peer, afi, safi,
17218 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17219 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17220 }
17221
17222 /* as-override */
17223 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17224 vty_out(vty, " neighbor %s as-override\n", addr);
17225 }
17226
17227 /* send-community print. */
17228 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17229 PEER_FLAG_SEND_COMMUNITY);
17230 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17231 PEER_FLAG_SEND_EXT_COMMUNITY);
17232 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17233 PEER_FLAG_SEND_LARGE_COMMUNITY);
17234
17235 if (flag_scomm && flag_secomm && flag_slcomm) {
17236 vty_out(vty, " no neighbor %s send-community all\n", addr);
17237 } else {
17238 if (flag_scomm)
17239 vty_out(vty, " no neighbor %s send-community\n", addr);
17240 if (flag_secomm)
17241 vty_out(vty,
17242 " no neighbor %s send-community extended\n",
17243 addr);
17244
17245 if (flag_slcomm)
17246 vty_out(vty, " no neighbor %s send-community large\n",
17247 addr);
17248 }
17249
17250 /* Default information */
17251 if (peergroup_af_flag_check(peer, afi, safi,
17252 PEER_FLAG_DEFAULT_ORIGINATE)) {
17253 vty_out(vty, " neighbor %s default-originate", addr);
17254
17255 if (peer->default_rmap[afi][safi].name)
17256 vty_out(vty, " route-map %s",
17257 peer->default_rmap[afi][safi].name);
17258
17259 vty_out(vty, "\n");
17260 }
17261
17262 /* Soft reconfiguration inbound. */
17263 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17264 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17265 addr);
17266 }
17267
17268 /* maximum-prefix. */
17269 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17270 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17271 peer->pmax[afi][safi]);
17272
17273 if (peer->pmax_threshold[afi][safi]
17274 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17275 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17276 if (peer_af_flag_check(peer, afi, safi,
17277 PEER_FLAG_MAX_PREFIX_WARNING))
17278 vty_out(vty, " warning-only");
17279 if (peer->pmax_restart[afi][safi])
17280 vty_out(vty, " restart %u",
17281 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17282 if (peer_af_flag_check(peer, afi, safi,
17283 PEER_FLAG_MAX_PREFIX_FORCE))
17284 vty_out(vty, " force");
dd65f45e
DL
17285
17286 vty_out(vty, "\n");
17287 }
17288
fde246e8
DA
17289 /* maximum-prefix-out */
17290 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17291 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17292 addr, peer->pmax_out[afi][safi]);
17293
dd65f45e
DL
17294 /* Route server client. */
17295 if (peergroup_af_flag_check(peer, afi, safi,
17296 PEER_FLAG_RSERVER_CLIENT)) {
17297 vty_out(vty, " neighbor %s route-server-client\n", addr);
17298 }
17299
17300 /* Nexthop-local unchanged. */
17301 if (peergroup_af_flag_check(peer, afi, safi,
17302 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17303 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17304 }
17305
17306 /* allowas-in <1-10> */
17307 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17308 if (peer_af_flag_check(peer, afi, safi,
17309 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17310 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17311 } else if (peer->allowas_in[afi][safi] == 3) {
17312 vty_out(vty, " neighbor %s allowas-in\n", addr);
17313 } else {
17314 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17315 peer->allowas_in[afi][safi]);
17316 }
17317 }
17318
17319 /* weight */
17320 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17321 vty_out(vty, " neighbor %s weight %lu\n", addr,
17322 peer->weight[afi][safi]);
17323
17324 /* Filter. */
17325 bgp_config_write_filter(vty, peer, afi, safi);
17326
17327 /* atribute-unchanged. */
17328 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17329 || (safi != SAFI_EVPN
17330 && peer_af_flag_check(peer, afi, safi,
17331 PEER_FLAG_NEXTHOP_UNCHANGED))
17332 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17333
17334 if (!peer_group_active(peer)
17335 || peergroup_af_flag_check(peer, afi, safi,
17336 PEER_FLAG_AS_PATH_UNCHANGED)
17337 || peergroup_af_flag_check(peer, afi, safi,
17338 PEER_FLAG_NEXTHOP_UNCHANGED)
17339 || peergroup_af_flag_check(peer, afi, safi,
17340 PEER_FLAG_MED_UNCHANGED)) {
17341
17342 vty_out(vty,
17343 " neighbor %s attribute-unchanged%s%s%s\n",
17344 addr,
17345 peer_af_flag_check(peer, afi, safi,
17346 PEER_FLAG_AS_PATH_UNCHANGED)
17347 ? " as-path"
17348 : "",
17349 peer_af_flag_check(peer, afi, safi,
17350 PEER_FLAG_NEXTHOP_UNCHANGED)
17351 ? " next-hop"
17352 : "",
17353 peer_af_flag_check(peer, afi, safi,
17354 PEER_FLAG_MED_UNCHANGED)
17355 ? " med"
17356 : "");
17357 }
17358 }
39d8dd2d
DS
17359
17360 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_CONFIG_DAMPENING))
17361 bgp_config_write_peer_damp(vty, peer, afi, safi);
dd65f45e
DL
17362}
17363
17364/* Address family based peer configuration display. */
17365static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17366 safi_t safi)
17367{
17368 struct peer *peer;
17369 struct peer_group *group;
17370 struct listnode *node, *nnode;
17371
17372
17373 vty_frame(vty, " !\n address-family ");
17374 if (afi == AFI_IP) {
17375 if (safi == SAFI_UNICAST)
17376 vty_frame(vty, "ipv4 unicast");
17377 else if (safi == SAFI_LABELED_UNICAST)
17378 vty_frame(vty, "ipv4 labeled-unicast");
17379 else if (safi == SAFI_MULTICAST)
17380 vty_frame(vty, "ipv4 multicast");
17381 else if (safi == SAFI_MPLS_VPN)
17382 vty_frame(vty, "ipv4 vpn");
17383 else if (safi == SAFI_ENCAP)
17384 vty_frame(vty, "ipv4 encap");
17385 else if (safi == SAFI_FLOWSPEC)
17386 vty_frame(vty, "ipv4 flowspec");
17387 } else if (afi == AFI_IP6) {
17388 if (safi == SAFI_UNICAST)
17389 vty_frame(vty, "ipv6 unicast");
17390 else if (safi == SAFI_LABELED_UNICAST)
17391 vty_frame(vty, "ipv6 labeled-unicast");
17392 else if (safi == SAFI_MULTICAST)
17393 vty_frame(vty, "ipv6 multicast");
17394 else if (safi == SAFI_MPLS_VPN)
17395 vty_frame(vty, "ipv6 vpn");
17396 else if (safi == SAFI_ENCAP)
17397 vty_frame(vty, "ipv6 encap");
17398 else if (safi == SAFI_FLOWSPEC)
17399 vty_frame(vty, "ipv6 flowspec");
17400 } else if (afi == AFI_L2VPN) {
17401 if (safi == SAFI_EVPN)
17402 vty_frame(vty, "l2vpn evpn");
17403 }
17404 vty_frame(vty, "\n");
17405
17406 bgp_config_write_distance(vty, bgp, afi, safi);
17407
17408 bgp_config_write_network(vty, bgp, afi, safi);
17409
17410 bgp_config_write_redistribute(vty, bgp, afi, safi);
17411
8a4e7fe6
DA
17412 /* BGP flag dampening. */
17413 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
0221327c 17414 bgp_config_write_damp(vty, bgp, afi, safi);
8a4e7fe6 17415
dd65f45e
DL
17416 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17417 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17418
17419 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17420 /* Do not display doppelganger peers */
17421 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17422 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17423 }
17424
17425 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17426 bgp_config_write_table_map(vty, bgp, afi, safi);
17427
17428 if (safi == SAFI_EVPN)
17429 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17430
17431 if (safi == SAFI_FLOWSPEC)
17432 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17433
17434 if (safi == SAFI_UNICAST) {
17435 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17436 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17437 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17438
17439 vty_out(vty, " export vpn\n");
17440 }
17441 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17442 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17443
17444 vty_out(vty, " import vpn\n");
17445 }
17446 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17447 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17448 char *name;
17449
17450 for (ALL_LIST_ELEMENTS_RO(
17451 bgp->vpn_policy[afi].import_vrf, node,
17452 name))
17453 vty_out(vty, " import vrf %s\n", name);
17454 }
17455 }
17456
17457 vty_endframe(vty, " exit-address-family\n");
17458}
17459
17460int bgp_config_write(struct vty *vty)
17461{
17462 struct bgp *bgp;
17463 struct peer_group *group;
17464 struct peer *peer;
17465 struct listnode *node, *nnode;
17466 struct listnode *mnode, *mnnode;
17467
17468 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17469 vty_out(vty, "bgp route-map delay-timer %u\n",
17470 bm->rmap_update_timer);
17471
d70583f7
D
17472 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17473 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17474 if (bm->v_update_delay != bm->v_establish_wait)
17475 vty_out(vty, " %d", bm->v_establish_wait);
17476 vty_out(vty, "\n");
17477 }
17478
9acb67cb
DS
17479 if (bm->wait_for_fib)
17480 vty_out(vty, "bgp suppress-fib-pending\n");
17481
05bd726c 17482 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17483 vty_out(vty, "bgp graceful-shutdown\n");
17484
c163f297
DS
17485 /* No-RIB (Zebra) option flag configuration */
17486 if (bgp_option_check(BGP_OPT_NO_FIB))
17487 vty_out(vty, "bgp no-rib\n");
17488
ec0acb80 17489 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
17490 vty_out(vty, "no bgp send-extra-data zebra\n");
17491
dd65f45e
DL
17492 /* BGP configuration. */
17493 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17494
17495 /* skip all auto created vrf as they dont have user config */
17496 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17497 continue;
17498
17499 /* Router bgp ASN */
17500 vty_out(vty, "router bgp %u", bgp->as);
17501
17502 if (bgp->name)
17503 vty_out(vty, " %s %s",
17504 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17505 ? "view" : "vrf", bgp->name);
17506 vty_out(vty, "\n");
17507
17508 /* BGP fast-external-failover. */
17509 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17510 vty_out(vty, " no bgp fast-external-failover\n");
17511
17512 /* BGP router ID. */
3a6290bd 17513 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17514 vty_out(vty, " bgp router-id %pI4\n",
17515 &bgp->router_id_static);
dd65f45e 17516
c208c586
S
17517 /* Suppress fib pending */
17518 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17519 vty_out(vty, " bgp suppress-fib-pending\n");
17520
dd65f45e 17521 /* BGP log-neighbor-changes. */
892fedb6 17522 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17523 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17524 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17525 CHECK_FLAG(bgp->flags,
17526 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17527 ? ""
17528 : "no ");
17529
17530 /* BGP configuration. */
892fedb6 17531 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17532 vty_out(vty, " bgp always-compare-med\n");
17533
17534 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17535 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17536 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17537 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17538 CHECK_FLAG(bgp->flags,
17539 BGP_FLAG_EBGP_REQUIRES_POLICY)
17540 ? ""
17541 : "no ");
dd65f45e
DL
17542
17543 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17544 if (bgp->reject_as_sets)
dd65f45e
DL
17545 vty_out(vty, " bgp reject-as-sets\n");
17546
2adac256
DA
17547 /* Suppress duplicate updates if the route actually not changed
17548 */
17549 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17550 != SAVE_BGP_SUPPRESS_DUPLICATES)
17551 vty_out(vty, " %sbgp suppress-duplicates\n",
17552 CHECK_FLAG(bgp->flags,
17553 BGP_FLAG_SUPPRESS_DUPLICATES)
17554 ? ""
17555 : "no ");
17556
dd65f45e 17557 /* BGP default ipv4-unicast. */
892fedb6 17558 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
17559 vty_out(vty, " no bgp default ipv4-unicast\n");
17560
e84c59af
DA
17561 /* BGP default ipv6-unicast. */
17562 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6))
17563 vty_out(vty, " bgp default ipv6-unicast\n");
17564
dd65f45e
DL
17565 /* BGP default local-preference. */
17566 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17567 vty_out(vty, " bgp default local-preference %u\n",
17568 bgp->default_local_pref);
17569
17570 /* BGP default show-hostname */
892fedb6 17571 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17572 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17573 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17574 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17575 ? ""
17576 : "no ");
17577
aef999a2
DA
17578 /* BGP default show-nexthop-hostname */
17579 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17580 != SAVE_BGP_SHOW_HOSTNAME)
17581 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17582 CHECK_FLAG(bgp->flags,
17583 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17584 ? ""
17585 : "no ");
17586
dd65f45e
DL
17587 /* BGP default subgroup-pkt-queue-max. */
17588 if (bgp->default_subgroup_pkt_queue_max
17589 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17590 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17591 bgp->default_subgroup_pkt_queue_max);
17592
17593 /* BGP client-to-client reflection. */
892fedb6 17594 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17595 vty_out(vty, " no bgp client-to-client reflection\n");
17596
17597 /* BGP cluster ID. */
17598 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17599 vty_out(vty, " bgp cluster-id %pI4\n",
17600 &bgp->cluster_id);
dd65f45e
DL
17601
17602 /* Disable ebgp connected nexthop check */
892fedb6 17603 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17604 vty_out(vty,
17605 " bgp disable-ebgp-connected-route-check\n");
17606
17607 /* Confederation identifier*/
17608 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17609 vty_out(vty, " bgp confederation identifier %u\n",
17610 bgp->confed_id);
17611
17612 /* Confederation peer */
17613 if (bgp->confed_peers_cnt > 0) {
17614 int i;
17615
17616 vty_out(vty, " bgp confederation peers");
17617
17618 for (i = 0; i < bgp->confed_peers_cnt; i++)
17619 vty_out(vty, " %u", bgp->confed_peers[i]);
17620
17621 vty_out(vty, "\n");
17622 }
17623
17624 /* BGP deterministic-med. */
892fedb6 17625 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17626 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17627 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17628 CHECK_FLAG(bgp->flags,
17629 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17630 ? ""
17631 : "no ");
17632
17633 /* BGP update-delay. */
17634 bgp_config_write_update_delay(vty, bgp);
17635
17636 if (bgp->v_maxmed_onstartup
17637 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17638 vty_out(vty, " bgp max-med on-startup %u",
17639 bgp->v_maxmed_onstartup);
17640 if (bgp->maxmed_onstartup_value
17641 != BGP_MAXMED_VALUE_DEFAULT)
17642 vty_out(vty, " %u",
17643 bgp->maxmed_onstartup_value);
17644 vty_out(vty, "\n");
17645 }
17646 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17647 vty_out(vty, " bgp max-med administrative");
17648 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17649 vty_out(vty, " %u", bgp->maxmed_admin_value);
17650 vty_out(vty, "\n");
17651 }
17652
17653 /* write quanta */
17654 bgp_config_write_wpkt_quanta(vty, bgp);
17655 /* read quanta */
17656 bgp_config_write_rpkt_quanta(vty, bgp);
17657
17658 /* coalesce time */
17659 bgp_config_write_coalesce_time(vty, bgp);
17660
05bd726c 17661 /* BGP per-instance graceful-shutdown */
17662 /* BGP-wide settings and per-instance settings are mutually
17663 * exclusive.
17664 */
17665 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17666 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17667 vty_out(vty, " bgp graceful-shutdown\n");
17668
dd65f45e
DL
17669 /* BGP graceful-restart. */
17670 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17671 vty_out(vty,
17672 " bgp graceful-restart stalepath-time %u\n",
17673 bgp->stalepath_time);
cfd47646 17674
dd65f45e
DL
17675 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17676 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17677 bgp->restart_time);
cfd47646 17678
17679 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17680 vty_out(vty,
17681 " bgp graceful-restart select-defer-time %u\n",
17682 bgp->select_defer_time);
17683
17684 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17685 vty_out(vty, " bgp graceful-restart\n");
17686
cfd47646 17687 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17688 vty_out(vty, " bgp graceful-restart-disable\n");
17689
dd65f45e 17690 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17691 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17692 vty_out(vty,
17693 " bgp graceful-restart preserve-fw-state\n");
17694
dc95985f 17695 /* Stale timer for RIB */
17696 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17697 vty_out(vty,
17698 " bgp graceful-restart rib-stale-time %u\n",
17699 bgp->rib_stale_time);
17700
dd65f45e 17701 /* BGP bestpath method. */
892fedb6 17702 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17703 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17704 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17705 vty_out(vty, " bgp bestpath as-path confed\n");
17706
892fedb6
DA
17707 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17708 if (CHECK_FLAG(bgp->flags,
17709 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17710 vty_out(vty,
17711 " bgp bestpath as-path multipath-relax as-set\n");
17712 } else {
17713 vty_out(vty,
17714 " bgp bestpath as-path multipath-relax\n");
17715 }
17716 }
17717
892fedb6 17718 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17719 vty_out(vty,
17720 " bgp route-reflector allow-outbound-policy\n");
17721 }
892fedb6 17722 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17723 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17724 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17725 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17726 vty_out(vty, " bgp bestpath med");
892fedb6 17727 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17728 vty_out(vty, " confed");
892fedb6
DA
17729 if (CHECK_FLAG(bgp->flags,
17730 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17731 vty_out(vty, " missing-as-worst");
17732 vty_out(vty, "\n");
17733 }
17734
ee88563a
JM
17735 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17736 vty_out(vty,
17737 " bgp bestpath peer-type multipath-relax\n");
17738
f7e1c681 17739 /* Link bandwidth handling. */
17740 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17741 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17742 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17743 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17744 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17745 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17746
dd65f45e 17747 /* BGP network import check. */
892fedb6 17748 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17749 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17750 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17751 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17752 ? ""
17753 : "no ");
17754
17755 /* BGP timers configuration. */
5d5393b9 17756 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17757 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17758 vty_out(vty, " timers bgp %u %u\n",
17759 bgp->default_keepalive, bgp->default_holdtime);
17760
17761 /* peer-group */
17762 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17763 bgp_config_write_peer_global(vty, bgp, group->conf);
17764 }
17765
17766 /* Normal neighbor configuration. */
17767 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17768 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17769 bgp_config_write_peer_global(vty, bgp, peer);
17770 }
17771
17772 /* listen range and limit for dynamic BGP neighbors */
17773 bgp_config_write_listen(vty, bgp);
17774
17775 /*
17776 * BGP default autoshutdown neighbors
17777 *
17778 * This must be placed after any peer and peer-group
17779 * configuration, to avoid setting all peers to shutdown after
17780 * a daemon restart, which is undesired behavior. (see #2286)
17781 */
17782 if (bgp->autoshutdown)
17783 vty_out(vty, " bgp default shutdown\n");
17784
9cf59432
DS
17785 /* BGP instance administrative shutdown */
17786 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17787 vty_out(vty, " bgp shutdown\n");
17788
dd65f45e
DL
17789 /* IPv4 unicast configuration. */
17790 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17791
17792 /* IPv4 multicast configuration. */
17793 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17794
17795 /* IPv4 labeled-unicast configuration. */
17796 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17797
17798 /* IPv4 VPN configuration. */
17799 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17800
17801 /* ENCAPv4 configuration. */
17802 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17803
17804 /* FLOWSPEC v4 configuration. */
17805 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17806
17807 /* IPv6 unicast configuration. */
17808 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17809
17810 /* IPv6 multicast configuration. */
17811 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17812
17813 /* IPv6 labeled-unicast configuration. */
17814 bgp_config_write_family(vty, bgp, AFI_IP6,
17815 SAFI_LABELED_UNICAST);
17816
17817 /* IPv6 VPN configuration. */
17818 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17819
17820 /* ENCAPv6 configuration. */
17821 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17822
17823 /* FLOWSPEC v6 configuration. */
17824 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17825
17826 /* EVPN configuration. */
17827 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17828
17829 hook_call(bgp_inst_config_write, bgp, vty);
17830
49e5a4a0 17831#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17832 bgp_rfapi_cfg_write(vty, bgp);
17833#endif
17834
17835 vty_out(vty, "!\n");
17836 }
17837 return 0;
17838}
17839
ddb5b488 17840
718e3744 17841/* BGP node structure. */
d62a17ae 17842static struct cmd_node bgp_node = {
f4b8291f 17843 .name = "bgp",
62b346ee 17844 .node = BGP_NODE,
24389580 17845 .parent_node = CONFIG_NODE,
62b346ee 17846 .prompt = "%s(config-router)# ",
612c2c15 17847 .config_write = bgp_config_write,
718e3744 17848};
17849
d62a17ae 17850static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17851 .name = "bgp ipv4 unicast",
62b346ee 17852 .node = BGP_IPV4_NODE,
24389580 17853 .parent_node = BGP_NODE,
62b346ee 17854 .prompt = "%s(config-router-af)# ",
718e3744 17855};
17856
d62a17ae 17857static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17858 .name = "bgp ipv4 multicast",
62b346ee 17859 .node = BGP_IPV4M_NODE,
24389580 17860 .parent_node = BGP_NODE,
62b346ee 17861 .prompt = "%s(config-router-af)# ",
718e3744 17862};
17863
d62a17ae 17864static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17865 .name = "bgp ipv4 labeled unicast",
62b346ee 17866 .node = BGP_IPV4L_NODE,
24389580 17867 .parent_node = BGP_NODE,
62b346ee 17868 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17869};
17870
d62a17ae 17871static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 17872 .name = "bgp ipv6",
62b346ee 17873 .node = BGP_IPV6_NODE,
24389580 17874 .parent_node = BGP_NODE,
62b346ee 17875 .prompt = "%s(config-router-af)# ",
718e3744 17876};
17877
d62a17ae 17878static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17879 .name = "bgp ipv6 multicast",
62b346ee 17880 .node = BGP_IPV6M_NODE,
24389580 17881 .parent_node = BGP_NODE,
62b346ee 17882 .prompt = "%s(config-router-af)# ",
25ffbdc1 17883};
17884
d62a17ae 17885static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17886 .name = "bgp ipv6 labeled unicast",
62b346ee 17887 .node = BGP_IPV6L_NODE,
24389580 17888 .parent_node = BGP_NODE,
62b346ee 17889 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17890};
17891
62b346ee 17892static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17893 .name = "bgp vpnv4",
62b346ee 17894 .node = BGP_VPNV4_NODE,
24389580 17895 .parent_node = BGP_NODE,
62b346ee 17896 .prompt = "%s(config-router-af)# ",
62b346ee 17897};
6b0655a2 17898
62b346ee 17899static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17900 .name = "bgp vpnv6",
62b346ee 17901 .node = BGP_VPNV6_NODE,
24389580 17902 .parent_node = BGP_NODE,
62b346ee 17903 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17904};
8ecd3266 17905
62b346ee 17906static struct cmd_node bgp_evpn_node = {
f4b8291f 17907 .name = "bgp evpn",
62b346ee 17908 .node = BGP_EVPN_NODE,
24389580 17909 .parent_node = BGP_NODE,
62b346ee 17910 .prompt = "%s(config-router-evpn)# ",
62b346ee 17911};
4e0b7b6d 17912
62b346ee 17913static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17914 .name = "bgp evpn vni",
62b346ee 17915 .node = BGP_EVPN_VNI_NODE,
24389580 17916 .parent_node = BGP_EVPN_NODE,
62b346ee 17917 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17918};
90e60aa7 17919
62b346ee 17920static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17921 .name = "bgp ipv4 flowspec",
62b346ee 17922 .node = BGP_FLOWSPECV4_NODE,
24389580 17923 .parent_node = BGP_NODE,
62b346ee 17924 .prompt = "%s(config-router-af)# ",
62b346ee 17925};
7c40bf39 17926
62b346ee 17927static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17928 .name = "bgp ipv6 flowspec",
62b346ee 17929 .node = BGP_FLOWSPECV6_NODE,
24389580 17930 .parent_node = BGP_NODE,
62b346ee 17931 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17932};
7c40bf39 17933
d62a17ae 17934static void community_list_vty(void);
1f8ae70b 17935
d62a17ae 17936static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 17937{
d62a17ae 17938 struct bgp *bgp;
17939 struct peer *peer;
d62a17ae 17940 struct listnode *lnbgp, *lnpeer;
b8a815e5 17941
d62a17ae 17942 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17943 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17944 /* only provide suggestions on the appropriate input
17945 * token type,
17946 * they'll otherwise show up multiple times */
17947 enum cmd_token_type match_type;
17948 char *name = peer->host;
d48ed3e0 17949
d62a17ae 17950 if (peer->conf_if) {
17951 match_type = VARIABLE_TKN;
17952 name = peer->conf_if;
17953 } else if (strchr(peer->host, ':'))
17954 match_type = IPV6_TKN;
17955 else
17956 match_type = IPV4_TKN;
d48ed3e0 17957
d62a17ae 17958 if (token->type != match_type)
17959 continue;
d48ed3e0 17960
d62a17ae 17961 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17962 }
d62a17ae 17963 }
b8a815e5
DL
17964}
17965
17966static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17967 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17968 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17969 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17970 {.completions = NULL}};
17971
47a306a0
DS
17972static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17973{
17974 struct bgp *bgp;
17975 struct peer_group *group;
17976 struct listnode *lnbgp, *lnpeer;
17977
17978 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17979 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17980 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17981 group->name));
17982 }
17983}
17984
17985static const struct cmd_variable_handler bgp_var_peergroup[] = {
17986 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17987 {.completions = NULL} };
17988
d62a17ae 17989void bgp_vty_init(void)
17990{
17991 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17992 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17993
17994 /* Install bgp top node. */
612c2c15
DL
17995 install_node(&bgp_node);
17996 install_node(&bgp_ipv4_unicast_node);
17997 install_node(&bgp_ipv4_multicast_node);
17998 install_node(&bgp_ipv4_labeled_unicast_node);
17999 install_node(&bgp_ipv6_unicast_node);
18000 install_node(&bgp_ipv6_multicast_node);
18001 install_node(&bgp_ipv6_labeled_unicast_node);
18002 install_node(&bgp_vpnv4_node);
18003 install_node(&bgp_vpnv6_node);
18004 install_node(&bgp_evpn_node);
18005 install_node(&bgp_evpn_vni_node);
18006 install_node(&bgp_flowspecv4_node);
18007 install_node(&bgp_flowspecv6_node);
d62a17ae 18008
18009 /* Install default VTY commands to new nodes. */
18010 install_default(BGP_NODE);
18011 install_default(BGP_IPV4_NODE);
18012 install_default(BGP_IPV4M_NODE);
18013 install_default(BGP_IPV4L_NODE);
18014 install_default(BGP_IPV6_NODE);
18015 install_default(BGP_IPV6M_NODE);
18016 install_default(BGP_IPV6L_NODE);
18017 install_default(BGP_VPNV4_NODE);
18018 install_default(BGP_VPNV6_NODE);
7c40bf39 18019 install_default(BGP_FLOWSPECV4_NODE);
18020 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18021 install_default(BGP_EVPN_NODE);
18022 install_default(BGP_EVPN_VNI_NODE);
18023
8029b216
AK
18024 /* "bgp local-mac" hidden commands. */
18025 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18026 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18027
9acb67cb
DS
18028 /* "bgp suppress-fib-pending" global */
18029 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18030
d62a17ae 18031 /* bgp route-map delay-timer commands. */
18032 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18033 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18034
d70583f7
D
18035 /* global bgp update-delay command */
18036 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18037 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18038
05bd726c 18039 /* global bgp graceful-shutdown command */
18040 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18041 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18042
d62a17ae 18043 /* Dummy commands (Currently not supported) */
18044 install_element(BGP_NODE, &no_synchronization_cmd);
18045 install_element(BGP_NODE, &no_auto_summary_cmd);
18046
18047 /* "router bgp" commands. */
18048 install_element(CONFIG_NODE, &router_bgp_cmd);
18049
18050 /* "no router bgp" commands. */
18051 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18052
18053 /* "bgp router-id" commands. */
18054 install_element(BGP_NODE, &bgp_router_id_cmd);
18055 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18056
c208c586
S
18057 /* "bgp suppress-fib-pending" command */
18058 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18059
d62a17ae 18060 /* "bgp cluster-id" commands. */
18061 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18062 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18063
c163f297
DS
18064 /* "bgp no-rib" commands. */
18065 install_element(CONFIG_NODE, &bgp_norib_cmd);
18066 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18067
e46723a5
DS
18068 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18069
d62a17ae 18070 /* "bgp confederation" commands. */
18071 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18072 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18073
18074 /* "bgp confederation peers" commands. */
18075 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18076 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18077
18078 /* bgp max-med command */
18079 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18080 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18081 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18082 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18083 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18084
18085 /* bgp disable-ebgp-connected-nh-check */
18086 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18087 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18088
18089 /* bgp update-delay command */
18090 install_element(BGP_NODE, &bgp_update_delay_cmd);
18091 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 18092
18093 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 18094 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 18095
18096 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18097 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18098
18099 /* "maximum-paths" commands. */
18100 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18101 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18102 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18103 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18104 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18105 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18106 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18107 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18108 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18109 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18110 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18111 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18112 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18113 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18114 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18115
39edabac
PG
18116 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18117 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18118 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18119 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18120 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 18121 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18122 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18123 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18124 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18125 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18126
18127 /* "timers bgp" commands. */
18128 install_element(BGP_NODE, &bgp_timers_cmd);
18129 install_element(BGP_NODE, &no_bgp_timers_cmd);
18130
18131 /* route-map delay-timer commands - per instance for backwards compat.
18132 */
18133 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18134 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18135
18136 /* "bgp client-to-client reflection" commands */
18137 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18138 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18139
18140 /* "bgp always-compare-med" commands */
18141 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18142 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18143
9dac9fc8
DA
18144 /* bgp ebgp-requires-policy */
18145 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18146 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18147
2adac256
DA
18148 /* bgp suppress-duplicates */
18149 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18150 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18151
fb29348a
DA
18152 /* bgp reject-as-sets */
18153 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18154 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18155
d62a17ae 18156 /* "bgp deterministic-med" commands */
18157 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18158 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18159
055679e9 18160 /* "bgp graceful-restart" command */
36235319
QY
18161 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18162 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 18163
18164 /* "bgp graceful-restart-disable" command */
36235319
QY
18165 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18166 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 18167
18168 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
18169 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18170 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 18171
18172 /* "neighbor a:b:c:d graceful-restart-disable" command */
18173 install_element(BGP_NODE,
18174 &bgp_neighbor_graceful_restart_disable_set_cmd);
18175 install_element(BGP_NODE,
18176 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18177
18178 /* "neighbor a:b:c:d graceful-restart-helper" command */
18179 install_element(BGP_NODE,
18180 &bgp_neighbor_graceful_restart_helper_set_cmd);
18181 install_element(BGP_NODE,
18182 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18183
d62a17ae 18184 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18185 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18186 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18187 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 18188 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 18189 install_element(BGP_NODE,
18190 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 18191 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18192 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18193
d6e3c15b 18194 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18195 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 18196 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18197 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 18198
7f323236
DW
18199 /* "bgp graceful-shutdown" commands */
18200 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18201 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18202
d62a17ae 18203 /* "bgp fast-external-failover" commands */
18204 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18205 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18206
d62a17ae 18207 /* "bgp bestpath compare-routerid" commands */
18208 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18209 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18210
18211 /* "bgp bestpath as-path ignore" commands */
18212 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18213 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18214
18215 /* "bgp bestpath as-path confed" commands */
18216 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18217 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18218
18219 /* "bgp bestpath as-path multipath-relax" commands */
18220 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18221 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18222
ee88563a
JM
18223 /* "bgp bestpath peer-type multipath-relax" commands */
18224 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18225 install_element(BGP_NODE,
18226 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18227
d62a17ae 18228 /* "bgp log-neighbor-changes" commands */
18229 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18230 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18231
18232 /* "bgp bestpath med" commands */
18233 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18234 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18235
f7e1c681 18236 /* "bgp bestpath bandwidth" commands */
18237 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18238 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18239
d62a17ae 18240 /* "no bgp default ipv4-unicast" commands. */
18241 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
18242 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
18243
e84c59af
DA
18244 /* "no bgp default ipv6-unicast" commands. */
18245 install_element(BGP_NODE, &no_bgp_default_ipv6_unicast_cmd);
18246 install_element(BGP_NODE, &bgp_default_ipv6_unicast_cmd);
18247
d62a17ae 18248 /* "bgp network import-check" commands. */
18249 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18250 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18251 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18252
18253 /* "bgp default local-preference" commands. */
18254 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18255 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18256
18257 /* bgp default show-hostname */
18258 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18259 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18260
aef999a2
DA
18261 /* bgp default show-nexthop-hostname */
18262 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18263 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18264
d62a17ae 18265 /* "bgp default subgroup-pkt-queue-max" commands. */
18266 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18267 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18268
18269 /* bgp ibgp-allow-policy-mods command */
18270 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18271 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18272
18273 /* "bgp listen limit" commands. */
18274 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18275 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18276
18277 /* "bgp listen range" commands. */
18278 install_element(BGP_NODE, &bgp_listen_range_cmd);
18279 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18280
8175f54a 18281 /* "bgp default shutdown" command */
f26845f9 18282 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18283
18284 /* "bgp shutdown" commands */
18285 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18286 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18287 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18288 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18289
d62a17ae 18290 /* "neighbor remote-as" commands. */
18291 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18292 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18293 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18294 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18295 install_element(BGP_NODE,
18296 &neighbor_interface_v6only_config_remote_as_cmd);
18297 install_element(BGP_NODE, &no_neighbor_cmd);
18298 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18299
18300 /* "neighbor peer-group" commands. */
18301 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18302 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18303 install_element(BGP_NODE,
18304 &no_neighbor_interface_peer_group_remote_as_cmd);
18305
18306 /* "neighbor local-as" commands. */
18307 install_element(BGP_NODE, &neighbor_local_as_cmd);
18308 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18309 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18310 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18311
18312 /* "neighbor solo" commands. */
18313 install_element(BGP_NODE, &neighbor_solo_cmd);
18314 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18315
18316 /* "neighbor password" commands. */
18317 install_element(BGP_NODE, &neighbor_password_cmd);
18318 install_element(BGP_NODE, &no_neighbor_password_cmd);
18319
18320 /* "neighbor activate" commands. */
18321 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18322 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18323 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18324 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18325 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18326 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18327 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18328 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18329 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 18330 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18331 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18332 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18333
18334 /* "no neighbor activate" commands. */
18335 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18336 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18337 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18338 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18339 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18340 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18341 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18342 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18343 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18344 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18345 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18346 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18347
18348 /* "neighbor peer-group" set commands. */
18349 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18350 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18351 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18352 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18353 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18354 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18355 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18356 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18357 install_element(BGP_FLOWSPECV4_NODE,
18358 &neighbor_set_peer_group_hidden_cmd);
18359 install_element(BGP_FLOWSPECV6_NODE,
18360 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18361
18362 /* "no neighbor peer-group unset" commands. */
18363 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18364 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18365 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18366 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18367 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18368 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18369 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18370 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18371 install_element(BGP_FLOWSPECV4_NODE,
18372 &no_neighbor_set_peer_group_hidden_cmd);
18373 install_element(BGP_FLOWSPECV6_NODE,
18374 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18375
18376 /* "neighbor softreconfiguration inbound" commands.*/
18377 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18378 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18379 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18380 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18381 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18382 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18383 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18384 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18385 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18386 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18387 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18388 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18389 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18390 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18391 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18392 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18393 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18394 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18395 install_element(BGP_FLOWSPECV4_NODE,
18396 &neighbor_soft_reconfiguration_cmd);
18397 install_element(BGP_FLOWSPECV4_NODE,
18398 &no_neighbor_soft_reconfiguration_cmd);
18399 install_element(BGP_FLOWSPECV6_NODE,
18400 &neighbor_soft_reconfiguration_cmd);
18401 install_element(BGP_FLOWSPECV6_NODE,
18402 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18403 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18404 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18405
18406 /* "neighbor attribute-unchanged" commands. */
18407 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18408 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18409 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18410 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18411 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18412 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18413 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18414 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18415 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18416 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18417 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18418 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18419 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18420 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18421 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18422 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18423 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18424 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18425
18426 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18427 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18428
b8ad84d2
PG
18429 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18430 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18431 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18432 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18433
d62a17ae 18434 /* "nexthop-local unchanged" commands */
18435 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18436 install_element(BGP_IPV6_NODE,
18437 &no_neighbor_nexthop_local_unchanged_cmd);
18438
18439 /* "neighbor next-hop-self" commands. */
18440 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18441 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18442 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18443 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18444 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18445 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18446 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18447 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18448 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18449 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18450 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18451 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18452 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18453 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18454 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18455 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18456 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18457 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18458 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18459 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18460
18461 /* "neighbor next-hop-self force" commands. */
18462 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18463 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18464 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18465 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18466 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18467 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18468 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18469 install_element(BGP_IPV4_NODE,
18470 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18471 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18472 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18473 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18474 install_element(BGP_IPV4M_NODE,
18475 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18476 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18477 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18478 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18479 install_element(BGP_IPV4L_NODE,
18480 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18481 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18482 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18483 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18484 install_element(BGP_IPV6_NODE,
18485 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18486 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18487 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18488 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18489 install_element(BGP_IPV6M_NODE,
18490 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18491 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18492 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18493 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18494 install_element(BGP_IPV6L_NODE,
18495 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18496 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18497 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18498 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18499 install_element(BGP_VPNV4_NODE,
18500 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18501 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18502 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18503 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18504 install_element(BGP_VPNV6_NODE,
18505 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18506 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18507 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18508
18509 /* "neighbor as-override" commands. */
18510 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18511 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18512 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18513 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18514 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18515 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18516 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18517 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18518 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18519 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18520 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18521 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18522 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18523 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18524 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18525 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18526 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18527 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18528
18529 /* "neighbor remove-private-AS" commands. */
18530 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18531 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18532 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18533 install_element(BGP_NODE,
18534 &no_neighbor_remove_private_as_all_hidden_cmd);
18535 install_element(BGP_NODE,
18536 &neighbor_remove_private_as_replace_as_hidden_cmd);
18537 install_element(BGP_NODE,
18538 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18539 install_element(BGP_NODE,
18540 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18541 install_element(
18542 BGP_NODE,
18543 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18544 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18545 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18546 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18547 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18548 install_element(BGP_IPV4_NODE,
18549 &neighbor_remove_private_as_replace_as_cmd);
18550 install_element(BGP_IPV4_NODE,
18551 &no_neighbor_remove_private_as_replace_as_cmd);
18552 install_element(BGP_IPV4_NODE,
18553 &neighbor_remove_private_as_all_replace_as_cmd);
18554 install_element(BGP_IPV4_NODE,
18555 &no_neighbor_remove_private_as_all_replace_as_cmd);
18556 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18557 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18558 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18559 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18560 install_element(BGP_IPV4M_NODE,
18561 &neighbor_remove_private_as_replace_as_cmd);
18562 install_element(BGP_IPV4M_NODE,
18563 &no_neighbor_remove_private_as_replace_as_cmd);
18564 install_element(BGP_IPV4M_NODE,
18565 &neighbor_remove_private_as_all_replace_as_cmd);
18566 install_element(BGP_IPV4M_NODE,
18567 &no_neighbor_remove_private_as_all_replace_as_cmd);
18568 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18569 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18570 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18571 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18572 install_element(BGP_IPV4L_NODE,
18573 &neighbor_remove_private_as_replace_as_cmd);
18574 install_element(BGP_IPV4L_NODE,
18575 &no_neighbor_remove_private_as_replace_as_cmd);
18576 install_element(BGP_IPV4L_NODE,
18577 &neighbor_remove_private_as_all_replace_as_cmd);
18578 install_element(BGP_IPV4L_NODE,
18579 &no_neighbor_remove_private_as_all_replace_as_cmd);
18580 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18581 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18582 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18583 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18584 install_element(BGP_IPV6_NODE,
18585 &neighbor_remove_private_as_replace_as_cmd);
18586 install_element(BGP_IPV6_NODE,
18587 &no_neighbor_remove_private_as_replace_as_cmd);
18588 install_element(BGP_IPV6_NODE,
18589 &neighbor_remove_private_as_all_replace_as_cmd);
18590 install_element(BGP_IPV6_NODE,
18591 &no_neighbor_remove_private_as_all_replace_as_cmd);
18592 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18593 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18594 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18595 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18596 install_element(BGP_IPV6M_NODE,
18597 &neighbor_remove_private_as_replace_as_cmd);
18598 install_element(BGP_IPV6M_NODE,
18599 &no_neighbor_remove_private_as_replace_as_cmd);
18600 install_element(BGP_IPV6M_NODE,
18601 &neighbor_remove_private_as_all_replace_as_cmd);
18602 install_element(BGP_IPV6M_NODE,
18603 &no_neighbor_remove_private_as_all_replace_as_cmd);
18604 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18605 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18606 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18607 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18608 install_element(BGP_IPV6L_NODE,
18609 &neighbor_remove_private_as_replace_as_cmd);
18610 install_element(BGP_IPV6L_NODE,
18611 &no_neighbor_remove_private_as_replace_as_cmd);
18612 install_element(BGP_IPV6L_NODE,
18613 &neighbor_remove_private_as_all_replace_as_cmd);
18614 install_element(BGP_IPV6L_NODE,
18615 &no_neighbor_remove_private_as_all_replace_as_cmd);
18616 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18617 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18618 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18619 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18620 install_element(BGP_VPNV4_NODE,
18621 &neighbor_remove_private_as_replace_as_cmd);
18622 install_element(BGP_VPNV4_NODE,
18623 &no_neighbor_remove_private_as_replace_as_cmd);
18624 install_element(BGP_VPNV4_NODE,
18625 &neighbor_remove_private_as_all_replace_as_cmd);
18626 install_element(BGP_VPNV4_NODE,
18627 &no_neighbor_remove_private_as_all_replace_as_cmd);
18628 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18629 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18630 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18631 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18632 install_element(BGP_VPNV6_NODE,
18633 &neighbor_remove_private_as_replace_as_cmd);
18634 install_element(BGP_VPNV6_NODE,
18635 &no_neighbor_remove_private_as_replace_as_cmd);
18636 install_element(BGP_VPNV6_NODE,
18637 &neighbor_remove_private_as_all_replace_as_cmd);
18638 install_element(BGP_VPNV6_NODE,
18639 &no_neighbor_remove_private_as_all_replace_as_cmd);
18640
18641 /* "neighbor send-community" commands.*/
18642 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18643 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18644 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18645 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18646 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18647 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18648 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18649 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18650 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18651 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18652 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18653 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18654 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18655 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18656 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18657 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18658 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18659 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18660 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18661 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18662 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18663 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18664 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18665 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18666 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18667 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18668 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18669 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18670 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18671 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18672 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18673 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18674 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18675 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18676 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18677 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18678
18679 /* "neighbor route-reflector" commands.*/
18680 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18681 install_element(BGP_NODE,
18682 &no_neighbor_route_reflector_client_hidden_cmd);
18683 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18684 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18685 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18686 install_element(BGP_IPV4M_NODE,
18687 &no_neighbor_route_reflector_client_cmd);
18688 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18689 install_element(BGP_IPV4L_NODE,
18690 &no_neighbor_route_reflector_client_cmd);
18691 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18692 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18693 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18694 install_element(BGP_IPV6M_NODE,
18695 &no_neighbor_route_reflector_client_cmd);
18696 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18697 install_element(BGP_IPV6L_NODE,
18698 &no_neighbor_route_reflector_client_cmd);
18699 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18700 install_element(BGP_VPNV4_NODE,
18701 &no_neighbor_route_reflector_client_cmd);
18702 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18703 install_element(BGP_VPNV6_NODE,
18704 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18705 install_element(BGP_FLOWSPECV4_NODE,
18706 &neighbor_route_reflector_client_cmd);
18707 install_element(BGP_FLOWSPECV4_NODE,
18708 &no_neighbor_route_reflector_client_cmd);
18709 install_element(BGP_FLOWSPECV6_NODE,
18710 &neighbor_route_reflector_client_cmd);
18711 install_element(BGP_FLOWSPECV6_NODE,
18712 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18713 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18714 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18715
18716 /* "neighbor route-server" commands.*/
18717 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18718 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18719 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18720 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18721 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18722 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18723 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18724 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18725 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18726 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18727 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18728 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18729 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18730 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18731 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18732 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18733 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18734 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18735 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18736 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18737 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18738 install_element(BGP_FLOWSPECV4_NODE,
18739 &no_neighbor_route_server_client_cmd);
18740 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18741 install_element(BGP_FLOWSPECV6_NODE,
18742 &no_neighbor_route_server_client_cmd);
d62a17ae 18743
18744 /* "neighbor addpath-tx-all-paths" commands.*/
18745 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18746 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18747 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18748 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18749 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18750 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18751 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18752 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18753 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18754 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18755 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18756 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18757 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18758 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18759 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18760 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18761 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18762 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18763
18764 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18765 install_element(BGP_NODE,
18766 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18767 install_element(BGP_NODE,
18768 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18769 install_element(BGP_IPV4_NODE,
18770 &neighbor_addpath_tx_bestpath_per_as_cmd);
18771 install_element(BGP_IPV4_NODE,
18772 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18773 install_element(BGP_IPV4M_NODE,
18774 &neighbor_addpath_tx_bestpath_per_as_cmd);
18775 install_element(BGP_IPV4M_NODE,
18776 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18777 install_element(BGP_IPV4L_NODE,
18778 &neighbor_addpath_tx_bestpath_per_as_cmd);
18779 install_element(BGP_IPV4L_NODE,
18780 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18781 install_element(BGP_IPV6_NODE,
18782 &neighbor_addpath_tx_bestpath_per_as_cmd);
18783 install_element(BGP_IPV6_NODE,
18784 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18785 install_element(BGP_IPV6M_NODE,
18786 &neighbor_addpath_tx_bestpath_per_as_cmd);
18787 install_element(BGP_IPV6M_NODE,
18788 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18789 install_element(BGP_IPV6L_NODE,
18790 &neighbor_addpath_tx_bestpath_per_as_cmd);
18791 install_element(BGP_IPV6L_NODE,
18792 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18793 install_element(BGP_VPNV4_NODE,
18794 &neighbor_addpath_tx_bestpath_per_as_cmd);
18795 install_element(BGP_VPNV4_NODE,
18796 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18797 install_element(BGP_VPNV6_NODE,
18798 &neighbor_addpath_tx_bestpath_per_as_cmd);
18799 install_element(BGP_VPNV6_NODE,
18800 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18801
2b31007c
RZ
18802 /* "neighbor sender-as-path-loop-detection" commands. */
18803 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18804 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18805
d62a17ae 18806 /* "neighbor passive" commands. */
18807 install_element(BGP_NODE, &neighbor_passive_cmd);
18808 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18809
18810
18811 /* "neighbor shutdown" commands. */
18812 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18813 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18814 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18815 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18816 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18817 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18818
18819 /* "neighbor capability extended-nexthop" commands.*/
18820 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18821 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18822
18823 /* "neighbor capability orf prefix-list" commands.*/
18824 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18825 install_element(BGP_NODE,
18826 &no_neighbor_capability_orf_prefix_hidden_cmd);
18827 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18828 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18829 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18830 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18831 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18832 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18833 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18834 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18835 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18836 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18837 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18838 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18839
18840 /* "neighbor capability dynamic" commands.*/
18841 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18842 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18843
18844 /* "neighbor dont-capability-negotiate" commands. */
18845 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18846 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18847
18848 /* "neighbor ebgp-multihop" commands. */
18849 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18850 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18851 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18852
18853 /* "neighbor disable-connected-check" commands. */
18854 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18855 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18856
47cbc09b
PM
18857 /* "neighbor enforce-first-as" commands. */
18858 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18859 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18860
d62a17ae 18861 /* "neighbor description" commands. */
18862 install_element(BGP_NODE, &neighbor_description_cmd);
18863 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18864 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18865
18866 /* "neighbor update-source" commands. "*/
18867 install_element(BGP_NODE, &neighbor_update_source_cmd);
18868 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18869
18870 /* "neighbor default-originate" commands. */
18871 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18872 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18873 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18874 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18875 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18876 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18877 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18878 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18879 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18880 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18881 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18882 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18883 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18884 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18885 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18886 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18887 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18888 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18889 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18890 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18891 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18892
18893 /* "neighbor port" commands. */
18894 install_element(BGP_NODE, &neighbor_port_cmd);
18895 install_element(BGP_NODE, &no_neighbor_port_cmd);
18896
18897 /* "neighbor weight" commands. */
18898 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18899 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18900
18901 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18902 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18903 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18904 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18905 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18906 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18907 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18908 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18909 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18910 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18911 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18912 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18913 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18914 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18915 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18916 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18917
18918 /* "neighbor override-capability" commands. */
18919 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18920 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18921
18922 /* "neighbor strict-capability-match" commands. */
18923 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18924 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18925
18926 /* "neighbor timers" commands. */
18927 install_element(BGP_NODE, &neighbor_timers_cmd);
18928 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18929
18930 /* "neighbor timers connect" commands. */
18931 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18932 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18933
d43114f3
DS
18934 /* "neighbor timers delayopen" commands. */
18935 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18936 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18937
d62a17ae 18938 /* "neighbor advertisement-interval" commands. */
18939 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18940 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18941
18942 /* "neighbor interface" commands. */
18943 install_element(BGP_NODE, &neighbor_interface_cmd);
18944 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18945
18946 /* "neighbor distribute" commands. */
18947 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18948 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18949 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18950 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18951 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18952 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18953 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18954 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18955 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18956 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18957 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18958 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18959 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18960 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18961 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18962 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18963 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18964 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18965
18966 /* "neighbor prefix-list" commands. */
18967 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
d62a17ae 18968 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18969 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18970 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18971 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18972 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18973 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18974 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18975 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
7c40bf39 18976 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
7c40bf39 18977 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 18978
18979 /* "neighbor filter-list" commands. */
18980 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18981 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18982 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18983 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18984 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18985 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18986 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18987 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18988 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18989 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18990 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18991 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18992 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18993 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18994 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18995 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18996 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18997 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18998 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18999 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19000 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19001 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 19002
19003 /* "neighbor route-map" commands. */
d62a17ae 19004 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
d62a17ae 19005 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
d62a17ae 19006 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
d62a17ae 19007 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
d62a17ae 19008 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
d62a17ae 19009 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
d62a17ae 19010 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
d62a17ae 19011 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
7c40bf39 19012 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
7c40bf39 19013 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
d37ba549 19014 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
d62a17ae 19015
19016 /* "neighbor unsuppress-map" commands. */
19017 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19018 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19019 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19020 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19021 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19022 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19023 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19024 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19025 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19026 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19027 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19028 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19029 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19030 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19031 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19032 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19033 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19034 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19035
7f7940e6
MK
19036 /* "neighbor advertise-map" commands. */
19037 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 19038 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19039 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19040 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19041 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19042 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19043 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19044 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19045 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19046
fde246e8
DA
19047 /* neighbor maximum-prefix-out commands. */
19048 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19049 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19050 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19051 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19052 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19053 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19054 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19055 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19056 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19057 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19058 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19059 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19060 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19061 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19062 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19063 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19064 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19065 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19066
d62a17ae 19067 /* "neighbor maximum-prefix" commands. */
19068 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19069 install_element(BGP_NODE,
19070 &neighbor_maximum_prefix_threshold_hidden_cmd);
19071 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19072 install_element(BGP_NODE,
19073 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19074 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19075 install_element(BGP_NODE,
19076 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19077 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19078 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19079 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19080 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19081 install_element(BGP_IPV4_NODE,
19082 &neighbor_maximum_prefix_threshold_warning_cmd);
19083 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19084 install_element(BGP_IPV4_NODE,
19085 &neighbor_maximum_prefix_threshold_restart_cmd);
19086 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19087 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19088 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19089 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19090 install_element(BGP_IPV4M_NODE,
19091 &neighbor_maximum_prefix_threshold_warning_cmd);
19092 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19093 install_element(BGP_IPV4M_NODE,
19094 &neighbor_maximum_prefix_threshold_restart_cmd);
19095 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19096 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19097 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19098 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19099 install_element(BGP_IPV4L_NODE,
19100 &neighbor_maximum_prefix_threshold_warning_cmd);
19101 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19102 install_element(BGP_IPV4L_NODE,
19103 &neighbor_maximum_prefix_threshold_restart_cmd);
19104 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19105 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19106 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19107 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19108 install_element(BGP_IPV6_NODE,
19109 &neighbor_maximum_prefix_threshold_warning_cmd);
19110 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19111 install_element(BGP_IPV6_NODE,
19112 &neighbor_maximum_prefix_threshold_restart_cmd);
19113 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19114 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19115 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19116 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19117 install_element(BGP_IPV6M_NODE,
19118 &neighbor_maximum_prefix_threshold_warning_cmd);
19119 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19120 install_element(BGP_IPV6M_NODE,
19121 &neighbor_maximum_prefix_threshold_restart_cmd);
19122 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19123 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19124 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19125 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19126 install_element(BGP_IPV6L_NODE,
19127 &neighbor_maximum_prefix_threshold_warning_cmd);
19128 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19129 install_element(BGP_IPV6L_NODE,
19130 &neighbor_maximum_prefix_threshold_restart_cmd);
19131 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19132 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19133 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19134 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19135 install_element(BGP_VPNV4_NODE,
19136 &neighbor_maximum_prefix_threshold_warning_cmd);
19137 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19138 install_element(BGP_VPNV4_NODE,
19139 &neighbor_maximum_prefix_threshold_restart_cmd);
19140 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19141 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19142 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19143 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19144 install_element(BGP_VPNV6_NODE,
19145 &neighbor_maximum_prefix_threshold_warning_cmd);
19146 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19147 install_element(BGP_VPNV6_NODE,
19148 &neighbor_maximum_prefix_threshold_restart_cmd);
19149 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19150
19151 /* "neighbor allowas-in" */
19152 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19153 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19154 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19155 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19156 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19157 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19158 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19159 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19160 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19161 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19162 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19163 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19164 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19165 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19166 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19167 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19168 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19169 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19170 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19171 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19172
0221327c
DS
19173 /* "neighbor dampening" commands. */
19174 install_element(BGP_NODE, &neighbor_damp_cmd);
19175 install_element(BGP_NODE, &no_neighbor_damp_cmd);
19176 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
19177 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
19178 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
19179 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
19180 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
19181 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
19182 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
19183 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
19184 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
19185 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
19186 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
19187 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
19188 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
19189
d62a17ae 19190 /* address-family commands. */
19191 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19192 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 19193#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 19194 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19195 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 19196#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 19197
d62a17ae 19198 install_element(BGP_NODE, &address_family_evpn_cmd);
19199
19200 /* "exit-address-family" command. */
19201 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19202 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19203 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19204 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19205 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19206 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19207 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19208 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 19209 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19210 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 19211 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19212
19213 /* "clear ip bgp commands" */
19214 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19215
19216 /* clear ip bgp prefix */
19217 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19218 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19219 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19220
19221 /* "show [ip] bgp summary" commands. */
19222 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 19223 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 19224 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 19225 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 19226 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19227 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 19228 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19229
19230 /* "show [ip] bgp neighbors" commands. */
19231 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19232
36235319 19233 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 19234
d62a17ae 19235 /* "show [ip] bgp peer-group" commands. */
19236 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19237
19238 /* "show [ip] bgp paths" commands. */
19239 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19240
19241 /* "show [ip] bgp community" commands. */
19242 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19243
19244 /* "show ip bgp large-community" commands. */
19245 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19246 /* "show [ip] bgp attribute-info" commands. */
19247 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 19248 /* "show [ip] bgp route-leak" command */
19249 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 19250
19251 /* "redistribute" commands. */
19252 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19253 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19254 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19255 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19256 install_element(BGP_NODE,
19257 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19258 install_element(BGP_NODE,
19259 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19260 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19261 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19262 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19263 install_element(BGP_NODE,
19264 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19265 install_element(BGP_NODE,
19266 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19267 install_element(BGP_NODE,
19268 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19269 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19270 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19271 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19272 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19273 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19274 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19275 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19276 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19277 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19278 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19279 install_element(BGP_IPV4_NODE,
19280 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19281 install_element(BGP_IPV4_NODE,
19282 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19283 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19284 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19285 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19286 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19287 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19288 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19289
b9c7bc5a
PZ
19290 /* import|export vpn [route-map WORD] */
19291 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19292 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 19293
12a844a5
DS
19294 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19295 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19296
d62a17ae 19297 /* ttl_security commands */
19298 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19299 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19300
19301 /* "show [ip] bgp memory" commands. */
19302 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19303
acf71666
MK
19304 /* "show bgp martian next-hop" */
19305 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19306
48ecf8f5
DS
19307 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19308
d62a17ae 19309 /* "show [ip] bgp views" commands. */
19310 install_element(VIEW_NODE, &show_bgp_views_cmd);
19311
19312 /* "show [ip] bgp vrfs" commands. */
19313 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19314
19315 /* Community-list. */
19316 community_list_vty();
ddb5b488 19317
ed0e57e3
DA
19318 community_alias_vty();
19319
ddb5b488 19320 /* vpn-policy commands */
b9c7bc5a
PZ
19321 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19322 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19323 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19324 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19325 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19326 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19327 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19328 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19329 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19330 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
19331 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19332 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 19333
301ad80a
PG
19334 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19335 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19336
b9c7bc5a
PZ
19337 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19338 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19339 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19340 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
19341 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19342 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19343 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19344 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19345 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19346 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
19347
19348 /* tcp-mss command */
19349 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19350 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
718e3744 19351}
6b0655a2 19352
718e3744 19353#include "memory.h"
19354#include "bgp_regex.h"
19355#include "bgp_clist.h"
19356#include "bgp_ecommunity.h"
19357
19358/* VTY functions. */
19359
19360/* Direction value to string conversion. */
d62a17ae 19361static const char *community_direct_str(int direct)
19362{
19363 switch (direct) {
19364 case COMMUNITY_DENY:
19365 return "deny";
19366 case COMMUNITY_PERMIT:
19367 return "permit";
19368 default:
19369 return "unknown";
19370 }
718e3744 19371}
19372
19373/* Display error string. */
d62a17ae 19374static void community_list_perror(struct vty *vty, int ret)
19375{
19376 switch (ret) {
19377 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19378 vty_out(vty, "%% Can't find community-list\n");
19379 break;
19380 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19381 vty_out(vty, "%% Malformed community-list value\n");
19382 break;
19383 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19384 vty_out(vty,
19385 "%% Community name conflict, previously defined as standard community\n");
19386 break;
19387 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19388 vty_out(vty,
19389 "%% Community name conflict, previously defined as expanded community\n");
19390 break;
19391 }
718e3744 19392}
19393
5bf15956
DW
19394/* "community-list" keyword help string. */
19395#define COMMUNITY_LIST_STR "Add a community list entry\n"
19396
7336e101
SP
19397/*community-list standard */
19398DEFUN (community_list_standard,
19399 bgp_community_list_standard_cmd,
a08032fe 19400 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19401 BGP_STR
718e3744 19402 COMMUNITY_LIST_STR
19403 "Community list number (standard)\n"
5bf15956 19404 "Add an standard community-list entry\n"
718e3744 19405 "Community list name\n"
2f8cc0e5
DA
19406 "Sequence number of an entry\n"
19407 "Sequence number\n"
718e3744 19408 "Specify community to reject\n"
19409 "Specify community to accept\n"
19410 COMMUNITY_VAL_STR)
19411{
d62a17ae 19412 char *cl_name_or_number = NULL;
2f8cc0e5 19413 char *seq = NULL;
d62a17ae 19414 int direct = 0;
19415 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19416 int idx = 0;
7336e101 19417
a08032fe 19418 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19419 if (idx)
19420 seq = argv[idx]->arg;
19421
19422 idx = 0;
d62a17ae 19423 argv_find(argv, argc, "(1-99)", &idx);
19424 argv_find(argv, argc, "WORD", &idx);
19425 cl_name_or_number = argv[idx]->arg;
19426 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19427 : COMMUNITY_DENY;
19428 argv_find(argv, argc, "AA:NN", &idx);
19429 char *str = argv_concat(argv, argc, idx);
42f914d4 19430
2f8cc0e5
DA
19431 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19432 direct, style);
42f914d4 19433
d62a17ae 19434 XFREE(MTYPE_TMP, str);
42f914d4 19435
d62a17ae 19436 if (ret < 0) {
19437 /* Display error string. */
19438 community_list_perror(vty, ret);
19439 return CMD_WARNING_CONFIG_FAILED;
19440 }
42f914d4 19441
d62a17ae 19442 return CMD_SUCCESS;
718e3744 19443}
19444
7336e101
SP
19445DEFUN (no_community_list_standard_all,
19446 no_bgp_community_list_standard_all_cmd,
a08032fe 19447 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19448 NO_STR
19449 BGP_STR
19450 COMMUNITY_LIST_STR
19451 "Community list number (standard)\n"
19452 "Add an standard community-list entry\n"
19453 "Community list name\n"
2f8cc0e5
DA
19454 "Sequence number of an entry\n"
19455 "Sequence number\n"
7336e101
SP
19456 "Specify community to reject\n"
19457 "Specify community to accept\n"
19458 COMMUNITY_VAL_STR)
718e3744 19459{
d62a17ae 19460 char *cl_name_or_number = NULL;
174b5cb9 19461 char *str = NULL;
d62a17ae 19462 int direct = 0;
19463 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19464 char *seq = NULL;
d62a17ae 19465 int idx = 0;
7336e101 19466
a08032fe 19467 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19468 if (idx)
19469 seq = argv[idx]->arg;
19470
19471 idx = 0;
174b5cb9
DA
19472 argv_find(argv, argc, "permit", &idx);
19473 argv_find(argv, argc, "deny", &idx);
19474
19475 if (idx) {
19476 direct = argv_find(argv, argc, "permit", &idx)
19477 ? COMMUNITY_PERMIT
19478 : COMMUNITY_DENY;
19479
19480 idx = 0;
19481 argv_find(argv, argc, "AA:NN", &idx);
19482 str = argv_concat(argv, argc, idx);
19483 }
19484
19485 idx = 0;
d62a17ae 19486 argv_find(argv, argc, "(1-99)", &idx);
19487 argv_find(argv, argc, "WORD", &idx);
19488 cl_name_or_number = argv[idx]->arg;
42f914d4 19489
2f8cc0e5 19490 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19491 direct, style);
42f914d4 19492
d62a17ae 19493 XFREE(MTYPE_TMP, str);
daf9ddbb 19494
d62a17ae 19495 if (ret < 0) {
19496 community_list_perror(vty, ret);
19497 return CMD_WARNING_CONFIG_FAILED;
19498 }
42f914d4 19499
d62a17ae 19500 return CMD_SUCCESS;
718e3744 19501}
7336e101 19502
174b5cb9
DA
19503ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19504 "no bgp community-list <(1-99)|standard WORD>",
19505 NO_STR BGP_STR COMMUNITY_LIST_STR
19506 "Community list number (standard)\n"
19507 "Add an standard community-list entry\n"
19508 "Community list name\n")
19509
7336e101
SP
19510/*community-list expanded */
19511DEFUN (community_list_expanded_all,
19512 bgp_community_list_expanded_all_cmd,
a08032fe 19513 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19514 BGP_STR
19515 COMMUNITY_LIST_STR
718e3744 19516 "Community list number (expanded)\n"
5bf15956 19517 "Add an expanded community-list entry\n"
718e3744 19518 "Community list name\n"
2f8cc0e5
DA
19519 "Sequence number of an entry\n"
19520 "Sequence number\n"
718e3744 19521 "Specify community to reject\n"
19522 "Specify community to accept\n"
19523 COMMUNITY_VAL_STR)
19524{
d62a17ae 19525 char *cl_name_or_number = NULL;
2f8cc0e5 19526 char *seq = NULL;
d62a17ae 19527 int direct = 0;
19528 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19529 int idx = 0;
7b9a4750 19530
a08032fe 19531 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19532 if (idx)
19533 seq = argv[idx]->arg;
19534
19535 idx = 0;
19536
d62a17ae 19537 argv_find(argv, argc, "(100-500)", &idx);
19538 argv_find(argv, argc, "WORD", &idx);
19539 cl_name_or_number = argv[idx]->arg;
19540 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19541 : COMMUNITY_DENY;
19542 argv_find(argv, argc, "AA:NN", &idx);
19543 char *str = argv_concat(argv, argc, idx);
42f914d4 19544
2f8cc0e5
DA
19545 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19546 direct, style);
42f914d4 19547
d62a17ae 19548 XFREE(MTYPE_TMP, str);
42f914d4 19549
d62a17ae 19550 if (ret < 0) {
19551 /* Display error string. */
19552 community_list_perror(vty, ret);
19553 return CMD_WARNING_CONFIG_FAILED;
19554 }
42f914d4 19555
d62a17ae 19556 return CMD_SUCCESS;
718e3744 19557}
19558
7336e101
SP
19559DEFUN (no_community_list_expanded_all,
19560 no_bgp_community_list_expanded_all_cmd,
a08032fe 19561 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19562 NO_STR
19563 BGP_STR
19564 COMMUNITY_LIST_STR
19565 "Community list number (expanded)\n"
19566 "Add an expanded community-list entry\n"
19567 "Community list name\n"
2f8cc0e5
DA
19568 "Sequence number of an entry\n"
19569 "Sequence number\n"
7336e101
SP
19570 "Specify community to reject\n"
19571 "Specify community to accept\n"
19572 COMMUNITY_VAL_STR)
718e3744 19573{
d62a17ae 19574 char *cl_name_or_number = NULL;
2f8cc0e5 19575 char *seq = NULL;
174b5cb9 19576 char *str = NULL;
d62a17ae 19577 int direct = 0;
19578 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19579 int idx = 0;
174b5cb9 19580
a08032fe 19581 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19582 if (idx)
19583 seq = argv[idx]->arg;
19584
19585 idx = 0;
174b5cb9
DA
19586 argv_find(argv, argc, "permit", &idx);
19587 argv_find(argv, argc, "deny", &idx);
19588
19589 if (idx) {
19590 direct = argv_find(argv, argc, "permit", &idx)
19591 ? COMMUNITY_PERMIT
19592 : COMMUNITY_DENY;
19593
19594 idx = 0;
19595 argv_find(argv, argc, "AA:NN", &idx);
19596 str = argv_concat(argv, argc, idx);
7336e101 19597 }
174b5cb9
DA
19598
19599 idx = 0;
d62a17ae 19600 argv_find(argv, argc, "(100-500)", &idx);
19601 argv_find(argv, argc, "WORD", &idx);
19602 cl_name_or_number = argv[idx]->arg;
42f914d4 19603
2f8cc0e5 19604 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19605 direct, style);
42f914d4 19606
d62a17ae 19607 XFREE(MTYPE_TMP, str);
daf9ddbb 19608
d62a17ae 19609 if (ret < 0) {
19610 community_list_perror(vty, ret);
19611 return CMD_WARNING_CONFIG_FAILED;
19612 }
42f914d4 19613
d62a17ae 19614 return CMD_SUCCESS;
718e3744 19615}
19616
36d4bb44
EB
19617ALIAS(no_community_list_expanded_all,
19618 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 19619 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 19620 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19621 "Community list number (expanded)\n"
19622 "Add an expanded community-list entry\n"
19623 "Community list name\n")
19624
8d9b8ed9
PM
19625/* Return configuration string of community-list entry. */
19626static const char *community_list_config_str(struct community_entry *entry)
19627{
19628 const char *str;
19629
19630 if (entry->any)
19631 str = "";
19632 else {
19633 if (entry->style == COMMUNITY_LIST_STANDARD)
19634 str = community_str(entry->u.com, false);
19635 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19636 str = lcommunity_str(entry->u.lcom, false);
19637 else
19638 str = entry->config;
19639 }
19640 return str;
19641}
19642
d62a17ae 19643static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19644{
d62a17ae 19645 struct community_entry *entry;
718e3744 19646
d62a17ae 19647 for (entry = list->head; entry; entry = entry->next) {
19648 if (entry == list->head) {
19649 if (all_digit(list->name))
19650 vty_out(vty, "Community %s list %s\n",
19651 entry->style == COMMUNITY_LIST_STANDARD
19652 ? "standard"
19653 : "(expanded) access",
19654 list->name);
19655 else
19656 vty_out(vty, "Named Community %s list %s\n",
19657 entry->style == COMMUNITY_LIST_STANDARD
19658 ? "standard"
19659 : "expanded",
19660 list->name);
19661 }
19662 if (entry->any)
19663 vty_out(vty, " %s\n",
19664 community_direct_str(entry->direct));
19665 else
19666 vty_out(vty, " %s %s\n",
19667 community_direct_str(entry->direct),
8d9b8ed9 19668 community_list_config_str(entry));
d62a17ae 19669 }
718e3744 19670}
19671
7336e101
SP
19672DEFUN (show_community_list,
19673 show_bgp_community_list_cmd,
19674 "show bgp community-list",
718e3744 19675 SHOW_STR
7336e101 19676 BGP_STR
718e3744 19677 "List community-list\n")
19678{
d62a17ae 19679 struct community_list *list;
19680 struct community_list_master *cm;
718e3744 19681
d62a17ae 19682 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19683 if (!cm)
19684 return CMD_SUCCESS;
718e3744 19685
d62a17ae 19686 for (list = cm->num.head; list; list = list->next)
19687 community_list_show(vty, list);
718e3744 19688
d62a17ae 19689 for (list = cm->str.head; list; list = list->next)
19690 community_list_show(vty, list);
718e3744 19691
d62a17ae 19692 return CMD_SUCCESS;
718e3744 19693}
19694
7336e101
SP
19695DEFUN (show_community_list_arg,
19696 show_bgp_community_list_arg_cmd,
960b69b9 19697 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
19698 SHOW_STR
19699 BGP_STR
718e3744 19700 "List community-list\n"
19701 "Community-list number\n"
960b69b9 19702 "Community-list name\n"
19703 "Detailed information on community-list\n")
718e3744 19704{
d62a17ae 19705 int idx_comm_list = 3;
19706 struct community_list *list;
718e3744 19707
e237b0d2 19708 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19709 COMMUNITY_LIST_MASTER);
19710 if (!list) {
19711 vty_out(vty, "%% Can't find community-list\n");
19712 return CMD_WARNING;
19713 }
718e3744 19714
d62a17ae 19715 community_list_show(vty, list);
718e3744 19716
d62a17ae 19717 return CMD_SUCCESS;
718e3744 19718}
6b0655a2 19719
57d187bc
JS
19720/*
19721 * Large Community code.
19722 */
d62a17ae 19723static int lcommunity_list_set_vty(struct vty *vty, int argc,
19724 struct cmd_token **argv, int style,
19725 int reject_all_digit_name)
19726{
19727 int ret;
19728 int direct;
19729 char *str;
19730 int idx = 0;
19731 char *cl_name;
2f8cc0e5
DA
19732 char *seq = NULL;
19733
a08032fe 19734 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19735 seq = argv[idx]->arg;
d62a17ae 19736
2f8cc0e5 19737 idx = 0;
d62a17ae 19738 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19739 : COMMUNITY_DENY;
19740
19741 /* All digit name check. */
19742 idx = 0;
19743 argv_find(argv, argc, "WORD", &idx);
19744 argv_find(argv, argc, "(1-99)", &idx);
19745 argv_find(argv, argc, "(100-500)", &idx);
19746 cl_name = argv[idx]->arg;
19747 if (reject_all_digit_name && all_digit(cl_name)) {
19748 vty_out(vty, "%% Community name cannot have all digits\n");
19749 return CMD_WARNING_CONFIG_FAILED;
19750 }
19751
19752 idx = 0;
19753 argv_find(argv, argc, "AA:BB:CC", &idx);
19754 argv_find(argv, argc, "LINE", &idx);
19755 /* Concat community string argument. */
19756 if (idx)
19757 str = argv_concat(argv, argc, idx);
19758 else
19759 str = NULL;
19760
2f8cc0e5 19761 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19762
19763 /* Free temporary community list string allocated by
19764 argv_concat(). */
0a22ddfb 19765 XFREE(MTYPE_TMP, str);
d62a17ae 19766
19767 if (ret < 0) {
19768 community_list_perror(vty, ret);
19769 return CMD_WARNING_CONFIG_FAILED;
19770 }
19771 return CMD_SUCCESS;
19772}
19773
19774static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19775 struct cmd_token **argv, int style)
19776{
19777 int ret;
19778 int direct = 0;
19779 char *str = NULL;
19780 int idx = 0;
2f8cc0e5 19781 char *seq = NULL;
d62a17ae 19782
a08032fe 19783 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19784 seq = argv[idx]->arg;
d62a17ae 19785
2f8cc0e5 19786 idx = 0;
d62a17ae 19787 argv_find(argv, argc, "permit", &idx);
19788 argv_find(argv, argc, "deny", &idx);
19789
19790 if (idx) {
19791 /* Check the list direct. */
19792 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19793 direct = COMMUNITY_PERMIT;
19794 else
19795 direct = COMMUNITY_DENY;
19796
19797 idx = 0;
19798 argv_find(argv, argc, "LINE", &idx);
19799 argv_find(argv, argc, "AA:AA:NN", &idx);
19800 /* Concat community string argument. */
19801 str = argv_concat(argv, argc, idx);
19802 }
19803
19804 idx = 0;
19805 argv_find(argv, argc, "(1-99)", &idx);
19806 argv_find(argv, argc, "(100-500)", &idx);
19807 argv_find(argv, argc, "WORD", &idx);
19808
19809 /* Unset community list. */
2f8cc0e5 19810 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19811 style);
19812
19813 /* Free temporary community list string allocated by
19814 argv_concat(). */
0a22ddfb 19815 XFREE(MTYPE_TMP, str);
d62a17ae 19816
19817 if (ret < 0) {
19818 community_list_perror(vty, ret);
19819 return CMD_WARNING_CONFIG_FAILED;
19820 }
19821
19822 return CMD_SUCCESS;
57d187bc
JS
19823}
19824
19825/* "large-community-list" keyword help string. */
19826#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19827#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19828
7336e101
SP
19829DEFUN (lcommunity_list_standard,
19830 bgp_lcommunity_list_standard_cmd,
a08032fe 19831 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19832 BGP_STR
19833 LCOMMUNITY_LIST_STR
19834 "Large Community list number (standard)\n"
2f8cc0e5
DA
19835 "Sequence number of an entry\n"
19836 "Sequence number\n"
7336e101
SP
19837 "Specify large community to reject\n"
19838 "Specify large community to accept\n"
19839 LCOMMUNITY_VAL_STR)
52951b63 19840{
d62a17ae 19841 return lcommunity_list_set_vty(vty, argc, argv,
19842 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19843}
19844
7336e101
SP
19845DEFUN (lcommunity_list_expanded,
19846 bgp_lcommunity_list_expanded_cmd,
a08032fe 19847 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19848 BGP_STR
19849 LCOMMUNITY_LIST_STR
19850 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19851 "Sequence number of an entry\n"
19852 "Sequence number\n"
7336e101
SP
19853 "Specify large community to reject\n"
19854 "Specify large community to accept\n"
19855 "An ordered list as a regular-expression\n")
57d187bc 19856{
d62a17ae 19857 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19858 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19859}
19860
7336e101
SP
19861DEFUN (lcommunity_list_name_standard,
19862 bgp_lcommunity_list_name_standard_cmd,
a08032fe 19863 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19864 BGP_STR
19865 LCOMMUNITY_LIST_STR
19866 "Specify standard large-community-list\n"
19867 "Large Community list name\n"
2f8cc0e5
DA
19868 "Sequence number of an entry\n"
19869 "Sequence number\n"
7336e101
SP
19870 "Specify large community to reject\n"
19871 "Specify large community to accept\n"
19872 LCOMMUNITY_VAL_STR)
52951b63 19873{
d62a17ae 19874 return lcommunity_list_set_vty(vty, argc, argv,
19875 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19876}
19877
7336e101
SP
19878DEFUN (lcommunity_list_name_expanded,
19879 bgp_lcommunity_list_name_expanded_cmd,
a08032fe 19880 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19881 BGP_STR
19882 LCOMMUNITY_LIST_STR
19883 "Specify expanded large-community-list\n"
19884 "Large Community list name\n"
2f8cc0e5
DA
19885 "Sequence number of an entry\n"
19886 "Sequence number\n"
7336e101
SP
19887 "Specify large community to reject\n"
19888 "Specify large community to accept\n"
19889 "An ordered list as a regular-expression\n")
57d187bc 19890{
d62a17ae 19891 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19892 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19893}
19894
4378f57c
DA
19895DEFUN (no_lcommunity_list_all,
19896 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
19897 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19898 NO_STR
19899 BGP_STR
19900 LCOMMUNITY_LIST_STR
19901 "Large Community list number (standard)\n"
19902 "Large Community list number (expanded)\n"
19903 "Large Community list name\n")
57d187bc 19904{
7336e101
SP
19905 return lcommunity_list_unset_vty(vty, argc, argv,
19906 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19907}
19908
4378f57c
DA
19909DEFUN (no_lcommunity_list_name_standard_all,
19910 no_bgp_lcommunity_list_name_standard_all_cmd,
19911 "no bgp large-community-list standard WORD",
19912 NO_STR
19913 BGP_STR
19914 LCOMMUNITY_LIST_STR
19915 "Specify standard large-community-list\n"
19916 "Large Community list name\n")
19917{
19918 return lcommunity_list_unset_vty(vty, argc, argv,
19919 LARGE_COMMUNITY_LIST_STANDARD);
19920}
19921
7336e101
SP
19922DEFUN (no_lcommunity_list_name_expanded_all,
19923 no_bgp_lcommunity_list_name_expanded_all_cmd,
19924 "no bgp large-community-list expanded WORD",
19925 NO_STR
19926 BGP_STR
19927 LCOMMUNITY_LIST_STR
19928 "Specify expanded large-community-list\n"
19929 "Large Community list name\n")
57d187bc 19930{
d62a17ae 19931 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19932 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19933}
19934
7336e101
SP
19935DEFUN (no_lcommunity_list_standard,
19936 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19937 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19938 NO_STR
19939 BGP_STR
19940 LCOMMUNITY_LIST_STR
19941 "Large Community list number (standard)\n"
2f8cc0e5
DA
19942 "Sequence number of an entry\n"
19943 "Sequence number\n"
7336e101
SP
19944 "Specify large community to reject\n"
19945 "Specify large community to accept\n"
19946 LCOMMUNITY_VAL_STR)
57d187bc 19947{
d62a17ae 19948 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19949 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19950}
19951
7336e101
SP
19952DEFUN (no_lcommunity_list_expanded,
19953 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19954 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19955 NO_STR
19956 BGP_STR
19957 LCOMMUNITY_LIST_STR
19958 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19959 "Sequence number of an entry\n"
19960 "Sequence number\n"
7336e101
SP
19961 "Specify large community to reject\n"
19962 "Specify large community to accept\n"
19963 "An ordered list as a regular-expression\n")
57d187bc 19964{
d62a17ae 19965 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19966 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19967}
19968
7336e101
SP
19969DEFUN (no_lcommunity_list_name_standard,
19970 no_bgp_lcommunity_list_name_standard_cmd,
a08032fe 19971 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19972 NO_STR
19973 BGP_STR
19974 LCOMMUNITY_LIST_STR
19975 "Specify standard large-community-list\n"
19976 "Large Community list name\n"
2f8cc0e5
DA
19977 "Sequence number of an entry\n"
19978 "Sequence number\n"
7336e101
SP
19979 "Specify large community to reject\n"
19980 "Specify large community to accept\n"
19981 LCOMMUNITY_VAL_STR)
57d187bc 19982{
d62a17ae 19983 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19984 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19985}
19986
7336e101
SP
19987DEFUN (no_lcommunity_list_name_expanded,
19988 no_bgp_lcommunity_list_name_expanded_cmd,
a08032fe 19989 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19990 NO_STR
19991 BGP_STR
19992 LCOMMUNITY_LIST_STR
19993 "Specify expanded large-community-list\n"
19994 "Large community list name\n"
2f8cc0e5
DA
19995 "Sequence number of an entry\n"
19996 "Sequence number\n"
7336e101
SP
19997 "Specify large community to reject\n"
19998 "Specify large community to accept\n"
19999 "An ordered list as a regular-expression\n")
57d187bc 20000{
d62a17ae 20001 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20002 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20003}
20004
d62a17ae 20005static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20006{
20007 struct community_entry *entry;
20008
20009 for (entry = list->head; entry; entry = entry->next) {
20010 if (entry == list->head) {
20011 if (all_digit(list->name))
20012 vty_out(vty, "Large community %s list %s\n",
169b72c8 20013 entry->style ==
20014 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20015 ? "standard"
20016 : "(expanded) access",
20017 list->name);
20018 else
20019 vty_out(vty,
20020 "Named large community %s list %s\n",
169b72c8 20021 entry->style ==
20022 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20023 ? "standard"
20024 : "expanded",
20025 list->name);
20026 }
20027 if (entry->any)
20028 vty_out(vty, " %s\n",
20029 community_direct_str(entry->direct));
20030 else
20031 vty_out(vty, " %s %s\n",
20032 community_direct_str(entry->direct),
8d9b8ed9 20033 community_list_config_str(entry));
d62a17ae 20034 }
57d187bc
JS
20035}
20036
7336e101
SP
20037DEFUN (show_lcommunity_list,
20038 show_bgp_lcommunity_list_cmd,
20039 "show bgp large-community-list",
57d187bc 20040 SHOW_STR
7336e101 20041 BGP_STR
57d187bc
JS
20042 "List large-community list\n")
20043{
d62a17ae 20044 struct community_list *list;
20045 struct community_list_master *cm;
57d187bc 20046
d62a17ae 20047 cm = community_list_master_lookup(bgp_clist,
20048 LARGE_COMMUNITY_LIST_MASTER);
20049 if (!cm)
20050 return CMD_SUCCESS;
57d187bc 20051
d62a17ae 20052 for (list = cm->num.head; list; list = list->next)
20053 lcommunity_list_show(vty, list);
57d187bc 20054
d62a17ae 20055 for (list = cm->str.head; list; list = list->next)
20056 lcommunity_list_show(vty, list);
57d187bc 20057
d62a17ae 20058 return CMD_SUCCESS;
57d187bc
JS
20059}
20060
7336e101
SP
20061DEFUN (show_lcommunity_list_arg,
20062 show_bgp_lcommunity_list_arg_cmd,
960b69b9 20063 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
20064 SHOW_STR
20065 BGP_STR
57d187bc 20066 "List large-community list\n"
960b69b9 20067 "Large-community-list number\n"
20068 "Large-community-list name\n"
20069 "Detailed information on large-community-list\n")
57d187bc 20070{
d62a17ae 20071 struct community_list *list;
57d187bc 20072
e237b0d2 20073 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 20074 LARGE_COMMUNITY_LIST_MASTER);
20075 if (!list) {
960b69b9 20076 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 20077 return CMD_WARNING;
20078 }
57d187bc 20079
d62a17ae 20080 lcommunity_list_show(vty, list);
57d187bc 20081
d62a17ae 20082 return CMD_SUCCESS;
57d187bc
JS
20083}
20084
718e3744 20085/* "extcommunity-list" keyword help string. */
20086#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20087#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20088
7336e101
SP
20089DEFUN (extcommunity_list_standard,
20090 bgp_extcommunity_list_standard_cmd,
a08032fe 20091 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20092 BGP_STR
718e3744 20093 EXTCOMMUNITY_LIST_STR
20094 "Extended Community list number (standard)\n"
718e3744 20095 "Specify standard extcommunity-list\n"
5bf15956 20096 "Community list name\n"
2f8cc0e5
DA
20097 "Sequence number of an entry\n"
20098 "Sequence number\n"
718e3744 20099 "Specify community to reject\n"
20100 "Specify community to accept\n"
20101 EXTCOMMUNITY_VAL_STR)
20102{
d62a17ae 20103 int style = EXTCOMMUNITY_LIST_STANDARD;
20104 int direct = 0;
20105 char *cl_number_or_name = NULL;
2f8cc0e5 20106 char *seq = NULL;
42f914d4 20107
d62a17ae 20108 int idx = 0;
7b9a4750 20109
d62a17ae 20110 argv_find(argv, argc, "(1-99)", &idx);
20111 argv_find(argv, argc, "WORD", &idx);
20112 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20113
a08032fe 20114 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20115 seq = argv[idx]->arg;
20116
d62a17ae 20117 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20118 : COMMUNITY_DENY;
20119 argv_find(argv, argc, "AA:NN", &idx);
20120 char *str = argv_concat(argv, argc, idx);
42f914d4 20121
2f8cc0e5 20122 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20123 direct, style);
42f914d4 20124
d62a17ae 20125 XFREE(MTYPE_TMP, str);
42f914d4 20126
d62a17ae 20127 if (ret < 0) {
20128 community_list_perror(vty, ret);
20129 return CMD_WARNING_CONFIG_FAILED;
20130 }
42f914d4 20131
d62a17ae 20132 return CMD_SUCCESS;
718e3744 20133}
20134
7336e101
SP
20135DEFUN (extcommunity_list_name_expanded,
20136 bgp_extcommunity_list_name_expanded_cmd,
a08032fe 20137 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20138 BGP_STR
20139 EXTCOMMUNITY_LIST_STR
5bf15956 20140 "Extended Community list number (expanded)\n"
718e3744 20141 "Specify expanded extcommunity-list\n"
20142 "Extended Community list name\n"
2f8cc0e5
DA
20143 "Sequence number of an entry\n"
20144 "Sequence number\n"
718e3744 20145 "Specify community to reject\n"
20146 "Specify community to accept\n"
20147 "An ordered list as a regular-expression\n")
20148{
d62a17ae 20149 int style = EXTCOMMUNITY_LIST_EXPANDED;
20150 int direct = 0;
20151 char *cl_number_or_name = NULL;
2f8cc0e5 20152 char *seq = NULL;
d62a17ae 20153 int idx = 0;
7336e101 20154
d62a17ae 20155 argv_find(argv, argc, "(100-500)", &idx);
20156 argv_find(argv, argc, "WORD", &idx);
20157 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20158
a08032fe 20159 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20160 seq = argv[idx]->arg;
20161
d62a17ae 20162 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20163 : COMMUNITY_DENY;
20164 argv_find(argv, argc, "LINE", &idx);
20165 char *str = argv_concat(argv, argc, idx);
42f914d4 20166
2f8cc0e5 20167 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20168 direct, style);
42f914d4 20169
d62a17ae 20170 XFREE(MTYPE_TMP, str);
42f914d4 20171
d62a17ae 20172 if (ret < 0) {
20173 community_list_perror(vty, ret);
20174 return CMD_WARNING_CONFIG_FAILED;
20175 }
42f914d4 20176
d62a17ae 20177 return CMD_SUCCESS;
718e3744 20178}
20179
7336e101
SP
20180DEFUN (no_extcommunity_list_standard_all,
20181 no_bgp_extcommunity_list_standard_all_cmd,
a08032fe 20182 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20183 NO_STR
20184 BGP_STR
20185 EXTCOMMUNITY_LIST_STR
813d4307 20186 "Extended Community list number (standard)\n"
718e3744 20187 "Specify standard extcommunity-list\n"
5bf15956 20188 "Community list name\n"
2f8cc0e5
DA
20189 "Sequence number of an entry\n"
20190 "Sequence number\n"
718e3744 20191 "Specify community to reject\n"
20192 "Specify community to accept\n"
20193 EXTCOMMUNITY_VAL_STR)
20194{
d62a17ae 20195 int style = EXTCOMMUNITY_LIST_STANDARD;
20196 int direct = 0;
20197 char *cl_number_or_name = NULL;
d4455c89 20198 char *str = NULL;
2f8cc0e5 20199 char *seq = NULL;
d62a17ae 20200 int idx = 0;
d4455c89 20201
a08032fe 20202 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20203 seq = argv[idx]->arg;
20204
20205 idx = 0;
d4455c89
DA
20206 argv_find(argv, argc, "permit", &idx);
20207 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
20208 if (idx) {
20209 direct = argv_find(argv, argc, "permit", &idx)
20210 ? COMMUNITY_PERMIT
20211 : COMMUNITY_DENY;
20212
20213 idx = 0;
20214 argv_find(argv, argc, "AA:NN", &idx);
20215 str = argv_concat(argv, argc, idx);
20216 }
20217
20218 idx = 0;
d62a17ae 20219 argv_find(argv, argc, "(1-99)", &idx);
20220 argv_find(argv, argc, "WORD", &idx);
20221 cl_number_or_name = argv[idx]->arg;
42f914d4 20222
d62a17ae 20223 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20224 seq, direct, style);
42f914d4 20225
d62a17ae 20226 XFREE(MTYPE_TMP, str);
42f914d4 20227
d62a17ae 20228 if (ret < 0) {
20229 community_list_perror(vty, ret);
20230 return CMD_WARNING_CONFIG_FAILED;
20231 }
42f914d4 20232
d62a17ae 20233 return CMD_SUCCESS;
718e3744 20234}
20235
d4455c89
DA
20236ALIAS(no_extcommunity_list_standard_all,
20237 no_bgp_extcommunity_list_standard_all_list_cmd,
20238 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 20239 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20240 "Extended Community list number (standard)\n"
20241 "Specify standard extcommunity-list\n"
20242 "Community list name\n")
20243
7336e101
SP
20244DEFUN (no_extcommunity_list_expanded_all,
20245 no_bgp_extcommunity_list_expanded_all_cmd,
a08032fe 20246 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20247 NO_STR
20248 BGP_STR
20249 EXTCOMMUNITY_LIST_STR
718e3744 20250 "Extended Community list number (expanded)\n"
718e3744 20251 "Specify expanded extcommunity-list\n"
5bf15956 20252 "Extended Community list name\n"
2f8cc0e5
DA
20253 "Sequence number of an entry\n"
20254 "Sequence number\n"
718e3744 20255 "Specify community to reject\n"
20256 "Specify community to accept\n"
20257 "An ordered list as a regular-expression\n")
20258{
d62a17ae 20259 int style = EXTCOMMUNITY_LIST_EXPANDED;
20260 int direct = 0;
20261 char *cl_number_or_name = NULL;
d4455c89 20262 char *str = NULL;
2f8cc0e5 20263 char *seq = NULL;
d62a17ae 20264 int idx = 0;
d4455c89 20265
a08032fe 20266 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20267 seq = argv[idx]->arg;
20268
20269 idx = 0;
d4455c89
DA
20270 argv_find(argv, argc, "permit", &idx);
20271 argv_find(argv, argc, "deny", &idx);
20272
20273 if (idx) {
20274 direct = argv_find(argv, argc, "permit", &idx)
20275 ? COMMUNITY_PERMIT
20276 : COMMUNITY_DENY;
20277
20278 idx = 0;
20279 argv_find(argv, argc, "LINE", &idx);
20280 str = argv_concat(argv, argc, idx);
20281 }
20282
20283 idx = 0;
d62a17ae 20284 argv_find(argv, argc, "(100-500)", &idx);
20285 argv_find(argv, argc, "WORD", &idx);
20286 cl_number_or_name = argv[idx]->arg;
42f914d4 20287
d62a17ae 20288 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20289 seq, direct, style);
42f914d4 20290
d62a17ae 20291 XFREE(MTYPE_TMP, str);
42f914d4 20292
d62a17ae 20293 if (ret < 0) {
20294 community_list_perror(vty, ret);
20295 return CMD_WARNING_CONFIG_FAILED;
20296 }
42f914d4 20297
d62a17ae 20298 return CMD_SUCCESS;
718e3744 20299}
20300
d4455c89
DA
20301ALIAS(no_extcommunity_list_expanded_all,
20302 no_bgp_extcommunity_list_expanded_all_list_cmd,
20303 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 20304 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20305 "Extended Community list number (expanded)\n"
20306 "Specify expanded extcommunity-list\n"
20307 "Extended Community list name\n")
20308
d62a17ae 20309static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 20310{
d62a17ae 20311 struct community_entry *entry;
718e3744 20312
d62a17ae 20313 for (entry = list->head; entry; entry = entry->next) {
20314 if (entry == list->head) {
20315 if (all_digit(list->name))
20316 vty_out(vty, "Extended community %s list %s\n",
20317 entry->style == EXTCOMMUNITY_LIST_STANDARD
20318 ? "standard"
20319 : "(expanded) access",
20320 list->name);
20321 else
20322 vty_out(vty,
20323 "Named extended community %s list %s\n",
20324 entry->style == EXTCOMMUNITY_LIST_STANDARD
20325 ? "standard"
20326 : "expanded",
20327 list->name);
20328 }
20329 if (entry->any)
20330 vty_out(vty, " %s\n",
20331 community_direct_str(entry->direct));
20332 else
20333 vty_out(vty, " %s %s\n",
20334 community_direct_str(entry->direct),
8d9b8ed9 20335 community_list_config_str(entry));
d62a17ae 20336 }
718e3744 20337}
20338
7336e101
SP
20339DEFUN (show_extcommunity_list,
20340 show_bgp_extcommunity_list_cmd,
20341 "show bgp extcommunity-list",
718e3744 20342 SHOW_STR
7336e101 20343 BGP_STR
718e3744 20344 "List extended-community list\n")
20345{
d62a17ae 20346 struct community_list *list;
20347 struct community_list_master *cm;
718e3744 20348
d62a17ae 20349 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20350 if (!cm)
20351 return CMD_SUCCESS;
718e3744 20352
d62a17ae 20353 for (list = cm->num.head; list; list = list->next)
20354 extcommunity_list_show(vty, list);
718e3744 20355
d62a17ae 20356 for (list = cm->str.head; list; list = list->next)
20357 extcommunity_list_show(vty, list);
718e3744 20358
d62a17ae 20359 return CMD_SUCCESS;
718e3744 20360}
20361
7336e101
SP
20362DEFUN (show_extcommunity_list_arg,
20363 show_bgp_extcommunity_list_arg_cmd,
960b69b9 20364 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
20365 SHOW_STR
20366 BGP_STR
718e3744 20367 "List extended-community list\n"
20368 "Extcommunity-list number\n"
960b69b9 20369 "Extcommunity-list name\n"
20370 "Detailed information on extcommunity-list\n")
718e3744 20371{
d62a17ae 20372 int idx_comm_list = 3;
20373 struct community_list *list;
718e3744 20374
e237b0d2 20375 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20376 EXTCOMMUNITY_LIST_MASTER);
20377 if (!list) {
20378 vty_out(vty, "%% Can't find extcommunity-list\n");
20379 return CMD_WARNING;
20380 }
718e3744 20381
d62a17ae 20382 extcommunity_list_show(vty, list);
718e3744 20383
d62a17ae 20384 return CMD_SUCCESS;
718e3744 20385}
6b0655a2 20386
718e3744 20387/* Display community-list and extcommunity-list configuration. */
d62a17ae 20388static int community_list_config_write(struct vty *vty)
20389{
20390 struct community_list *list;
20391 struct community_entry *entry;
20392 struct community_list_master *cm;
20393 int write = 0;
20394
20395 /* Community-list. */
20396 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20397
20398 for (list = cm->num.head; list; list = list->next)
20399 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20400 vty_out(vty,
20401 "bgp community-list %s seq %" PRId64 " %s %s\n",
20402 list->name, entry->seq,
d62a17ae 20403 community_direct_str(entry->direct),
20404 community_list_config_str(entry));
20405 write++;
20406 }
20407 for (list = cm->str.head; list; list = list->next)
20408 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20409 vty_out(vty,
20410 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20411 entry->style == COMMUNITY_LIST_STANDARD
20412 ? "standard"
20413 : "expanded",
2f8cc0e5
DA
20414 list->name, entry->seq,
20415 community_direct_str(entry->direct),
d62a17ae 20416 community_list_config_str(entry));
20417 write++;
20418 }
20419
20420 /* Extcommunity-list. */
20421 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20422
20423 for (list = cm->num.head; list; list = list->next)
20424 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20425 vty_out(vty,
20426 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20427 list->name, entry->seq,
20428 community_direct_str(entry->direct),
d62a17ae 20429 community_list_config_str(entry));
20430 write++;
20431 }
20432 for (list = cm->str.head; list; list = list->next)
20433 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20434 vty_out(vty,
6cde4b45 20435 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20436 entry->style == EXTCOMMUNITY_LIST_STANDARD
20437 ? "standard"
20438 : "expanded",
2f8cc0e5
DA
20439 list->name, entry->seq,
20440 community_direct_str(entry->direct),
d62a17ae 20441 community_list_config_str(entry));
20442 write++;
20443 }
20444
20445
20446 /* lcommunity-list. */
20447 cm = community_list_master_lookup(bgp_clist,
20448 LARGE_COMMUNITY_LIST_MASTER);
20449
20450 for (list = cm->num.head; list; list = list->next)
20451 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20452 vty_out(vty,
6cde4b45 20453 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20454 list->name, entry->seq,
20455 community_direct_str(entry->direct),
d62a17ae 20456 community_list_config_str(entry));
20457 write++;
20458 }
20459 for (list = cm->str.head; list; list = list->next)
20460 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20461 vty_out(vty,
6cde4b45 20462 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20463
d62a17ae 20464 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20465 ? "standard"
20466 : "expanded",
2f8cc0e5 20467 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20468 community_list_config_str(entry));
20469 write++;
20470 }
20471
20472 return write;
20473}
20474
612c2c15 20475static int community_list_config_write(struct vty *vty);
d62a17ae 20476static struct cmd_node community_list_node = {
f4b8291f 20477 .name = "community list",
62b346ee
DL
20478 .node = COMMUNITY_LIST_NODE,
20479 .prompt = "",
612c2c15 20480 .config_write = community_list_config_write,
718e3744 20481};
20482
d62a17ae 20483static void community_list_vty(void)
20484{
612c2c15 20485 install_node(&community_list_node);
d62a17ae 20486
20487 /* Community-list. */
7336e101
SP
20488 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20489 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20490 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20491 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20492 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20493 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20494 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20495 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20496
20497 /* Extcommunity-list. */
7336e101
SP
20498 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20499 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20500 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20501 install_element(CONFIG_NODE,
20502 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20503 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20504 install_element(CONFIG_NODE,
20505 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20506 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20507 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20508
20509 /* Large Community List */
7336e101 20510 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20511 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20512 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20513 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20514 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20515 install_element(CONFIG_NODE,
20516 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20517 install_element(CONFIG_NODE,
20518 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20519 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20520 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20521 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20522 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20523 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20524 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 20525}
ed0e57e3
DA
20526
20527static struct cmd_node community_alias_node = {
20528 .name = "community alias",
20529 .node = COMMUNITY_ALIAS_NODE,
20530 .prompt = "",
20531 .config_write = bgp_community_alias_write,
20532};
20533
20534void community_alias_vty(void)
20535{
20536 install_node(&community_alias_node);
20537
20538 /* Community-list. */
20539 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20540}