]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd, zebra: Add ability for bgp to send AS-Path information to zebra
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
5cb5f4d0 25#include "lib_errors.h"
ec0ab544 26#include "lib/zclient.h"
718e3744 27#include "prefix.h"
28#include "plist.h"
29#include "buffer.h"
30#include "linklist.h"
31#include "stream.h"
32#include "thread.h"
33#include "log.h"
3b8b1855 34#include "memory.h"
1c0d8808 35#include "lib_vty.h"
4bf6a362 36#include "hash.h"
3f9c7369 37#include "queue.h"
039f3a34 38#include "filter.h"
5d5ba018 39#include "frrstr.h"
718e3744 40
41#include "bgpd/bgpd.h"
48ecf8f5 42#include "bgpd/bgp_attr_evpn.h"
4bf6a362 43#include "bgpd/bgp_advertise.h"
718e3744 44#include "bgpd/bgp_attr.h"
45#include "bgpd/bgp_aspath.h"
46#include "bgpd/bgp_community.h"
4bf6a362 47#include "bgpd/bgp_ecommunity.h"
57d187bc 48#include "bgpd/bgp_lcommunity.h"
4bf6a362 49#include "bgpd/bgp_damp.h"
718e3744 50#include "bgpd/bgp_debug.h"
14454c9f 51#include "bgpd/bgp_errors.h"
e0701b79 52#include "bgpd/bgp_fsm.h"
4bf6a362 53#include "bgpd/bgp_nexthop.h"
718e3744 54#include "bgpd/bgp_open.h"
4bf6a362 55#include "bgpd/bgp_regex.h"
718e3744 56#include "bgpd/bgp_route.h"
c016b6c7 57#include "bgpd/bgp_mplsvpn.h"
718e3744 58#include "bgpd/bgp_zebra.h"
fee0f4c6 59#include "bgpd/bgp_table.h"
94f2b392 60#include "bgpd/bgp_vty.h"
165b5fff 61#include "bgpd/bgp_mpath.h"
cb1faec9 62#include "bgpd/bgp_packet.h"
3f9c7369 63#include "bgpd/bgp_updgrp.h"
c43ed2e4 64#include "bgpd/bgp_bfd.h"
555e09d4 65#include "bgpd/bgp_io.h"
94c2f693 66#include "bgpd/bgp_evpn.h"
dd65f45e 67#include "bgpd/bgp_evpn_vty.h"
b5e140c8 68#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 69#include "bgpd/bgp_addpath.h"
48ecf8f5 70#include "bgpd/bgp_mac.h"
dd65f45e 71#include "bgpd/bgp_flowspec.h"
49e5a4a0 72#ifdef ENABLE_BGP_VNC
dd65f45e
DL
73#include "bgpd/rfapi/bgp_rfapi_cfg.h"
74#endif
75
ff8a8a7a
CS
76#include "northbound.h"
77#include "northbound_cli.h"
78#include "bgpd/bgp_nb.h"
79
80
5d5393b9 81FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
5d5393b9
DL
88)
89FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
5d5393b9 92)
aef999a2
DA
93FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96)
5d5393b9 97FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
5d5393b9
DL
100)
101FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
5d5393b9
DL
104)
105FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108)
109FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112)
113FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
116)
1d3fdccf
DA
117FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
121)
5d5393b9 122
dd65f45e
DL
123DEFINE_HOOK(bgp_inst_config_write,
124 (struct bgp *bgp, struct vty *vty),
125 (bgp, vty))
718e3744 126
36235319
QY
127#define GR_NO_OPER \
128 "The Graceful Restart No Operation was executed as cmd same as previous one."
129#define GR_INVALID \
130 "The Graceful Restart command used is not valid at this moment."
d62a17ae 131static struct peer_group *listen_range_exists(struct bgp *bgp,
132 struct prefix *range, int exact);
133
055679e9 134/* Show BGP peer's information. */
135enum show_type {
136 show_all,
137 show_peer,
138 show_ipv4_all,
139 show_ipv6_all,
140 show_ipv4_peer,
141 show_ipv6_peer
142};
143
36235319
QY
144static struct peer_group *listen_range_exists(struct bgp *bgp,
145 struct prefix *range, int exact);
2986cac2 146
36235319
QY
147static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
148 struct bgp *bgp,
149 bool use_json,
150 json_object *json);
2986cac2 151
36235319
QY
152static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
153 enum show_type type,
154 const char *ip_str,
155 afi_t afi, bool use_json);
2986cac2 156
f4b8ec07
CS
157static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
158 char *base_xpath, int xpath_len,
159 char *abs_xpath);
160
d62a17ae 161static enum node_type bgp_node_type(afi_t afi, safi_t safi)
162{
163 switch (afi) {
164 case AFI_IP:
165 switch (safi) {
166 case SAFI_UNICAST:
167 return BGP_IPV4_NODE;
d62a17ae 168 case SAFI_MULTICAST:
169 return BGP_IPV4M_NODE;
d62a17ae 170 case SAFI_LABELED_UNICAST:
171 return BGP_IPV4L_NODE;
d62a17ae 172 case SAFI_MPLS_VPN:
173 return BGP_VPNV4_NODE;
7c40bf39 174 case SAFI_FLOWSPEC:
175 return BGP_FLOWSPECV4_NODE;
5c525538
RW
176 default:
177 /* not expected */
178 return BGP_IPV4_NODE;
d62a17ae 179 }
180 break;
181 case AFI_IP6:
182 switch (safi) {
183 case SAFI_UNICAST:
184 return BGP_IPV6_NODE;
d62a17ae 185 case SAFI_MULTICAST:
186 return BGP_IPV6M_NODE;
d62a17ae 187 case SAFI_LABELED_UNICAST:
188 return BGP_IPV6L_NODE;
d62a17ae 189 case SAFI_MPLS_VPN:
190 return BGP_VPNV6_NODE;
7c40bf39 191 case SAFI_FLOWSPEC:
192 return BGP_FLOWSPECV6_NODE;
5c525538
RW
193 default:
194 /* not expected */
195 return BGP_IPV4_NODE;
d62a17ae 196 }
197 break;
198 case AFI_L2VPN:
199 return BGP_EVPN_NODE;
b26f891d 200 case AFI_UNSPEC:
d62a17ae 201 case AFI_MAX:
202 // We should never be here but to clarify the switch statement..
203 return BGP_IPV4_NODE;
d62a17ae 204 }
205
206 // Impossible to happen
207 return BGP_IPV4_NODE;
f51bae9c 208}
20eb8864 209
5cb5f4d0
DD
210static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
211{
212 if (afi == AFI_IP && safi == SAFI_UNICAST)
213 return "IPv4 Unicast";
214 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
215 return "IPv4 Multicast";
216 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
217 return "IPv4 Labeled Unicast";
218 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
219 return "IPv4 VPN";
220 else if (afi == AFI_IP && safi == SAFI_ENCAP)
221 return "IPv4 Encap";
222 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
223 return "IPv4 Flowspec";
224 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
225 return "IPv6 Unicast";
226 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
227 return "IPv6 Multicast";
228 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
229 return "IPv6 Labeled Unicast";
230 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
231 return "IPv6 VPN";
232 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
233 return "IPv6 Encap";
234 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
235 return "IPv6 Flowspec";
236 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
237 return "L2VPN EVPN";
8e5509b0 238 else
5cb5f4d0 239 return "Unknown";
5cb5f4d0
DD
240}
241
242/*
243 * Please note that we have intentionally camelCased
244 * the return strings here. So if you want
245 * to use this function, please ensure you
246 * are doing this within json output
247 */
248static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
249{
250 if (afi == AFI_IP && safi == SAFI_UNICAST)
251 return "ipv4Unicast";
252 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
253 return "ipv4Multicast";
254 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
255 return "ipv4LabeledUnicast";
256 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
257 return "ipv4Vpn";
258 else if (afi == AFI_IP && safi == SAFI_ENCAP)
259 return "ipv4Encap";
260 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
261 return "ipv4Flowspec";
262 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
263 return "ipv6Unicast";
264 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
265 return "ipv6Multicast";
266 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
267 return "ipv6LabeledUnicast";
268 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
269 return "ipv6Vpn";
270 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
271 return "ipv6Encap";
272 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
273 return "ipv6Flowspec";
274 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
275 return "l2VpnEvpn";
8e5509b0 276 else
5cb5f4d0 277 return "Unknown";
5cb5f4d0
DD
278}
279
37a87b8f
CS
280/* return string maps to afi-safi specific container names
281 * defined in bgp yang file.
282 */
283const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
284{
285 if (afi == AFI_IP && safi == SAFI_UNICAST)
286 return "ipv4-unicast";
287 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
288 return "ipv4-multicast";
289 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
290 return "ipv4-labeled-unicast";
291 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
292 return "l3vpn-ipv4-unicast";
293 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
294 return "ipv4-flowspec";
295 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
296 return "ipv6-unicast";
297 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
298 return "ipv6-multicast";
299 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
300 return "ipv6-labeled-unicast";
301 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
302 return "l3vpn-ipv6-unicast";
303 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
304 return "ipv6-flowspec";
305 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
306 return "l2vpn-evpn";
307 else
308 return "Unknown";
309}
310
718e3744 311/* Utility function to get address family from current node. */
d62a17ae 312afi_t bgp_node_afi(struct vty *vty)
313{
314 afi_t afi;
315 switch (vty->node) {
316 case BGP_IPV6_NODE:
317 case BGP_IPV6M_NODE:
318 case BGP_IPV6L_NODE:
319 case BGP_VPNV6_NODE:
7c40bf39 320 case BGP_FLOWSPECV6_NODE:
d62a17ae 321 afi = AFI_IP6;
322 break;
323 case BGP_EVPN_NODE:
324 afi = AFI_L2VPN;
325 break;
326 default:
327 afi = AFI_IP;
328 break;
329 }
330 return afi;
718e3744 331}
332
333/* Utility function to get subsequent address family from current
334 node. */
d62a17ae 335safi_t bgp_node_safi(struct vty *vty)
336{
337 safi_t safi;
338 switch (vty->node) {
339 case BGP_VPNV4_NODE:
340 case BGP_VPNV6_NODE:
341 safi = SAFI_MPLS_VPN;
342 break;
343 case BGP_IPV4M_NODE:
344 case BGP_IPV6M_NODE:
345 safi = SAFI_MULTICAST;
346 break;
347 case BGP_EVPN_NODE:
348 safi = SAFI_EVPN;
349 break;
350 case BGP_IPV4L_NODE:
351 case BGP_IPV6L_NODE:
352 safi = SAFI_LABELED_UNICAST;
353 break;
7c40bf39 354 case BGP_FLOWSPECV4_NODE:
355 case BGP_FLOWSPECV6_NODE:
356 safi = SAFI_FLOWSPEC;
357 break;
d62a17ae 358 default:
359 safi = SAFI_UNICAST;
360 break;
361 }
362 return safi;
718e3744 363}
364
55f91488
QY
365/**
366 * Converts an AFI in string form to afi_t
367 *
368 * @param afi string, one of
369 * - "ipv4"
370 * - "ipv6"
81cf0de5 371 * - "l2vpn"
55f91488
QY
372 * @return the corresponding afi_t
373 */
d62a17ae 374afi_t bgp_vty_afi_from_str(const char *afi_str)
375{
376 afi_t afi = AFI_MAX; /* unknown */
377 if (strmatch(afi_str, "ipv4"))
378 afi = AFI_IP;
379 else if (strmatch(afi_str, "ipv6"))
380 afi = AFI_IP6;
81cf0de5
CS
381 else if (strmatch(afi_str, "l2vpn"))
382 afi = AFI_L2VPN;
d62a17ae 383 return afi;
384}
385
386int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
387 afi_t *afi)
388{
389 int ret = 0;
390 if (argv_find(argv, argc, "ipv4", index)) {
391 ret = 1;
392 if (afi)
393 *afi = AFI_IP;
394 } else if (argv_find(argv, argc, "ipv6", index)) {
395 ret = 1;
396 if (afi)
397 *afi = AFI_IP6;
8688b3e7
DS
398 } else if (argv_find(argv, argc, "l2vpn", index)) {
399 ret = 1;
400 if (afi)
401 *afi = AFI_L2VPN;
d62a17ae 402 }
403 return ret;
46f296b4
LB
404}
405
375a2e67 406/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 407safi_t bgp_vty_safi_from_str(const char *safi_str)
408{
409 safi_t safi = SAFI_MAX; /* unknown */
410 if (strmatch(safi_str, "multicast"))
411 safi = SAFI_MULTICAST;
412 else if (strmatch(safi_str, "unicast"))
413 safi = SAFI_UNICAST;
414 else if (strmatch(safi_str, "vpn"))
415 safi = SAFI_MPLS_VPN;
81cf0de5
CS
416 else if (strmatch(safi_str, "evpn"))
417 safi = SAFI_EVPN;
d62a17ae 418 else if (strmatch(safi_str, "labeled-unicast"))
419 safi = SAFI_LABELED_UNICAST;
7c40bf39 420 else if (strmatch(safi_str, "flowspec"))
421 safi = SAFI_FLOWSPEC;
d62a17ae 422 return safi;
423}
424
425int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
426 safi_t *safi)
427{
428 int ret = 0;
429 if (argv_find(argv, argc, "unicast", index)) {
430 ret = 1;
431 if (safi)
432 *safi = SAFI_UNICAST;
433 } else if (argv_find(argv, argc, "multicast", index)) {
434 ret = 1;
435 if (safi)
436 *safi = SAFI_MULTICAST;
437 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
438 ret = 1;
439 if (safi)
440 *safi = SAFI_LABELED_UNICAST;
441 } else if (argv_find(argv, argc, "vpn", index)) {
442 ret = 1;
443 if (safi)
444 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
445 } else if (argv_find(argv, argc, "evpn", index)) {
446 ret = 1;
447 if (safi)
448 *safi = SAFI_EVPN;
7c40bf39 449 } else if (argv_find(argv, argc, "flowspec", index)) {
450 ret = 1;
451 if (safi)
452 *safi = SAFI_FLOWSPEC;
d62a17ae 453 }
454 return ret;
46f296b4
LB
455}
456
5d5393b9
DL
457int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
458 enum bgp_instance_type inst_type)
459{
460 int ret = bgp_get(bgp, as, name, inst_type);
461
462 if (ret == BGP_CREATED) {
463 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 464 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
465
466 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 467 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 468 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 469 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
470 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
471 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 472 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 473 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 474 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 475 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
476 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
477 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
5d5393b9
DL
478
479 ret = BGP_SUCCESS;
480 }
481 return ret;
482}
483
7eeee51e 484/*
f212a857 485 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 486 *
f212a857
DS
487 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
488 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
489 * to appropriate values for the calling function. This is to allow the
490 * calling function to make decisions appropriate for the show command
491 * that is being parsed.
492 *
493 * The show commands are generally of the form:
d62a17ae 494 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
495 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
496 *
497 * Since we use argv_find if the show command in particular doesn't have:
498 * [ip]
18c57037 499 * [<view|vrf> VIEWVRFNAME]
375a2e67 500 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
501 * The command parsing should still be ok.
502 *
503 * vty -> The vty for the command so we can output some useful data in
504 * the event of a parse error in the vrf.
505 * argv -> The command tokens
506 * argc -> How many command tokens we have
d62a17ae 507 * idx -> The current place in the command, generally should be 0 for this
508 * function
7eeee51e
DS
509 * afi -> The parsed afi if it was included in the show command, returned here
510 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 511 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 512 * use_json -> json is configured or not
7eeee51e
DS
513 *
514 * The function returns the correct location in the parse tree for the
515 * last token found.
0e37c258
DS
516 *
517 * Returns 0 for failure to parse correctly, else the idx position of where
518 * it found the last token.
7eeee51e 519 */
d62a17ae 520int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
521 struct cmd_token **argv, int argc,
522 int *idx, afi_t *afi, safi_t *safi,
9f049418 523 struct bgp **bgp, bool use_json)
d62a17ae 524{
525 char *vrf_name = NULL;
526
527 assert(afi);
528 assert(safi);
529 assert(bgp);
530
531 if (argv_find(argv, argc, "ip", idx))
532 *afi = AFI_IP;
533
9a8bdf1c 534 if (argv_find(argv, argc, "view", idx))
d62a17ae 535 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
536 else if (argv_find(argv, argc, "vrf", idx)) {
537 vrf_name = argv[*idx + 1]->arg;
538 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
539 vrf_name = NULL;
540 }
541 if (vrf_name) {
d62a17ae 542 if (strmatch(vrf_name, "all"))
543 *bgp = NULL;
544 else {
545 *bgp = bgp_lookup_by_name(vrf_name);
546 if (!*bgp) {
52e5b8c4
SP
547 if (use_json) {
548 json_object *json = NULL;
549 json = json_object_new_object();
550 json_object_string_add(
551 json, "warning",
552 "View/Vrf is unknown");
553 vty_out(vty, "%s\n",
554 json_object_to_json_string_ext(json,
555 JSON_C_TO_STRING_PRETTY));
556 json_object_free(json);
557 }
ca61fd25
DS
558 else
559 vty_out(vty, "View/Vrf %s is unknown\n",
560 vrf_name);
d62a17ae 561 *idx = 0;
562 return 0;
563 }
564 }
565 } else {
566 *bgp = bgp_get_default();
567 if (!*bgp) {
52e5b8c4
SP
568 if (use_json) {
569 json_object *json = NULL;
570 json = json_object_new_object();
571 json_object_string_add(
572 json, "warning",
573 "Default BGP instance not found");
574 vty_out(vty, "%s\n",
575 json_object_to_json_string_ext(json,
576 JSON_C_TO_STRING_PRETTY));
577 json_object_free(json);
578 }
ca61fd25
DS
579 else
580 vty_out(vty,
581 "Default BGP instance not found\n");
d62a17ae 582 *idx = 0;
583 return 0;
584 }
585 }
586
587 if (argv_find_and_parse_afi(argv, argc, idx, afi))
588 argv_find_and_parse_safi(argv, argc, idx, safi);
589
590 *idx += 1;
591 return *idx;
592}
593
f4b8ec07 594bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 595{
596 struct interface *ifp = NULL;
597
598 if (su->sa.sa_family == AF_INET)
599 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
600 else if (su->sa.sa_family == AF_INET6)
601 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
602 su->sin6.sin6_scope_id,
603 bgp->vrf_id);
604
605 if (ifp)
3dc339cd 606 return true;
d62a17ae 607
3dc339cd 608 return false;
718e3744 609}
610
718e3744 611/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
612/* This is used only for configuration, so disallow if attempted on
613 * a dynamic neighbor.
614 */
d62a17ae 615struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
616{
617 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
618 int ret;
619 union sockunion su;
620 struct peer *peer = NULL;
621 struct peer_group *group = NULL;
622
623 if (!bgp) {
624 return NULL;
625 }
626
627 ret = str2sockunion(peer_str, &su);
628 if (ret == 0) {
629 /* IP address, locate peer. */
630 peer = peer_lookup(bgp, &su);
631 } else {
632 /* Not IP, could match either peer configured on interface or a
633 * group. */
634 peer = peer_lookup_by_conf_if(bgp, peer_str);
635 if (!peer)
636 group = peer_group_lookup(bgp, peer_str);
637 }
638
639 if (peer) {
640 if (peer_dynamic_neighbor(peer)) {
641 vty_out(vty,
642 "%% Operation not allowed on a dynamic neighbor\n");
643 return NULL;
644 }
645
646 return peer;
647 }
648
649 if (group)
650 return group->conf;
651
652 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
653
654 return NULL;
655}
656
f4b8ec07
CS
657int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
658{
659 const char *str = NULL;
660
661 switch (ret) {
662 case BGP_ERR_INVALID_VALUE:
663 str = "Invalid value";
664 break;
665 case BGP_ERR_INVALID_FLAG:
666 str = "Invalid flag";
667 break;
668 case BGP_ERR_PEER_GROUP_SHUTDOWN:
669 str = "Peer-group has been shutdown. Activate the peer-group first";
670 break;
671 case BGP_ERR_PEER_FLAG_CONFLICT:
672 str = "Can't set override-capability and strict-capability-match at the same time";
673 break;
674 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
675 str = "Specify remote-as or peer-group remote AS first";
676 break;
677 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
678 str = "Cannot change the peer-group. Deconfigure first";
679 break;
680 case BGP_ERR_PEER_GROUP_MISMATCH:
681 str = "Peer is not a member of this peer-group";
682 break;
683 case BGP_ERR_PEER_FILTER_CONFLICT:
684 str = "Prefix/distribute list can not co-exist";
685 break;
686 case BGP_ERR_NOT_INTERNAL_PEER:
687 str = "Invalid command. Not an internal neighbor";
688 break;
689 case BGP_ERR_REMOVE_PRIVATE_AS:
690 str = "remove-private-AS cannot be configured for IBGP peers";
691 break;
692 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
693 str = "Local-AS allowed only for EBGP peers";
694 break;
695 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
696 str = "Cannot have local-as same as BGP AS number";
697 break;
698 case BGP_ERR_TCPSIG_FAILED:
699 str = "Error while applying TCP-Sig to session(s)";
700 break;
701 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
702 str = "ebgp-multihop and ttl-security cannot be configured together";
703 break;
704 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
705 str = "ttl-security only allowed for EBGP peers";
706 break;
707 case BGP_ERR_AS_OVERRIDE:
708 str = "as-override cannot be configured for IBGP peers";
709 break;
710 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
711 str = "Invalid limit for number of dynamic neighbors";
712 break;
713 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
714 str = "Dynamic neighbor listen range already exists";
715 break;
716 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
717 str = "Operation not allowed on a dynamic neighbor";
718 break;
719 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
720 str = "Operation not allowed on a directly connected neighbor";
721 break;
722 case BGP_ERR_PEER_SAFI_CONFLICT:
723 str = GR_INVALID;
724 break;
725 case BGP_ERR_GR_INVALID_CMD:
726 str = "The Graceful Restart command used is not valid at this moment.";
727 break;
728 case BGP_ERR_GR_OPERATION_FAILED:
729 str = "The Graceful Restart Operation failed due to an err.";
730 break;
731 case BGP_GR_NO_OPERATION:
732 str = GR_NO_OPER;
733 break;
734 case BGP_ERR_PEER_GROUP_MEMBER:
735 str = "Peer-group member cannot override remote-as of peer-group";
736 break;
737 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
738 str = "Peer-group members must be all internal or all external";
739 break;
740 }
741 if (str) {
742 snprintf(errmsg, errmsg_len, "%s", str);
743 return -1;
744 }
745
746 return 0;
747}
748
d62a17ae 749int bgp_vty_return(struct vty *vty, int ret)
750{
751 const char *str = NULL;
752
753 switch (ret) {
754 case BGP_ERR_INVALID_VALUE:
755 str = "Invalid value";
756 break;
757 case BGP_ERR_INVALID_FLAG:
758 str = "Invalid flag";
759 break;
760 case BGP_ERR_PEER_GROUP_SHUTDOWN:
761 str = "Peer-group has been shutdown. Activate the peer-group first";
762 break;
763 case BGP_ERR_PEER_FLAG_CONFLICT:
764 str = "Can't set override-capability and strict-capability-match at the same time";
765 break;
766 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
767 str = "Specify remote-as or peer-group remote AS first";
768 break;
769 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
770 str = "Cannot change the peer-group. Deconfigure first";
771 break;
772 case BGP_ERR_PEER_GROUP_MISMATCH:
773 str = "Peer is not a member of this peer-group";
774 break;
775 case BGP_ERR_PEER_FILTER_CONFLICT:
776 str = "Prefix/distribute list can not co-exist";
777 break;
778 case BGP_ERR_NOT_INTERNAL_PEER:
779 str = "Invalid command. Not an internal neighbor";
780 break;
781 case BGP_ERR_REMOVE_PRIVATE_AS:
782 str = "remove-private-AS cannot be configured for IBGP peers";
783 break;
784 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
785 str = "Local-AS allowed only for EBGP peers";
786 break;
787 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
788 str = "Cannot have local-as same as BGP AS number";
789 break;
790 case BGP_ERR_TCPSIG_FAILED:
791 str = "Error while applying TCP-Sig to session(s)";
792 break;
793 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
794 str = "ebgp-multihop and ttl-security cannot be configured together";
795 break;
796 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
797 str = "ttl-security only allowed for EBGP peers";
798 break;
799 case BGP_ERR_AS_OVERRIDE:
800 str = "as-override cannot be configured for IBGP peers";
801 break;
802 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
803 str = "Invalid limit for number of dynamic neighbors";
804 break;
805 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
806 str = "Dynamic neighbor listen range already exists";
807 break;
808 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
809 str = "Operation not allowed on a dynamic neighbor";
810 break;
811 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
812 str = "Operation not allowed on a directly connected neighbor";
813 break;
814 case BGP_ERR_PEER_SAFI_CONFLICT:
055679e9 815 str = GR_INVALID;
816 break;
817 case BGP_ERR_GR_INVALID_CMD:
818 str = "The Graceful Restart command used is not valid at this moment.";
819 break;
820 case BGP_ERR_GR_OPERATION_FAILED:
821 str = "The Graceful Restart Operation failed due to an err.";
822 break;
823 case BGP_GR_NO_OPERATION:
824 str = GR_NO_OPER;
d62a17ae 825 break;
826 }
827 if (str) {
828 vty_out(vty, "%% %s\n", str);
829 return CMD_WARNING_CONFIG_FAILED;
830 }
831 return CMD_SUCCESS;
718e3744 832}
833
7aafcaca 834/* BGP clear sort. */
d62a17ae 835enum clear_sort {
836 clear_all,
837 clear_peer,
838 clear_group,
839 clear_external,
840 clear_as
7aafcaca
DS
841};
842
ff8a8a7a
CS
843static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
844 int error, char *errmsg, size_t errmsg_len)
d62a17ae 845{
846 switch (error) {
847 case BGP_ERR_AF_UNCONFIGURED:
ff8a8a7a
CS
848 snprintf(errmsg, errmsg_len,
849 "%%BGP: Enable %s address family for the neighbor %s",
850 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 851 break;
852 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
ff8a8a7a
CS
853 snprintf(
854 errmsg, errmsg_len,
855 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
d62a17ae 856 peer->host);
857 break;
858 default:
859 break;
860 }
7aafcaca
DS
861}
862
dc912615 863static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 864 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
865{
866 int ret = 0;
867
868 /* if afi/.safi not specified, spin thru all of them */
869 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
870 afi_t tmp_afi;
871 safi_t tmp_safi;
872
873 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
874 if (!peer->afc[tmp_afi][tmp_safi])
875 continue;
876
877 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 878 ret = peer_clear(peer, nnode);
dc912615
DS
879 else
880 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
881 stype);
882 }
883 /* if afi specified and safi not, spin thru safis on this afi */
884 } else if (safi == SAFI_UNSPEC) {
885 safi_t tmp_safi;
886
887 for (tmp_safi = SAFI_UNICAST;
888 tmp_safi < SAFI_MAX; tmp_safi++) {
889 if (!peer->afc[afi][tmp_safi])
890 continue;
891
892 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 893 ret = peer_clear(peer, nnode);
dc912615
DS
894 else
895 ret = peer_clear_soft(peer, afi,
896 tmp_safi, stype);
897 }
898 /* both afi/safi specified, let the caller know if not defined */
899 } else {
900 if (!peer->afc[afi][safi])
901 return 1;
902
903 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 904 ret = peer_clear(peer, nnode);
dc912615
DS
905 else
906 ret = peer_clear_soft(peer, afi, safi, stype);
907 }
908
909 return ret;
910}
911
7aafcaca 912/* `clear ip bgp' functions. */
ff8a8a7a 913static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 914 enum clear_sort sort, enum bgp_clear_type stype,
ff8a8a7a 915 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 916{
dc912615 917 int ret = 0;
3ae8bfa5 918 bool found = false;
d62a17ae 919 struct peer *peer;
dc95985f 920
921 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 922
923 /* Clear all neighbors. */
924 /*
925 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
926 * nodes on the BGP instance as that may get freed if it is a
927 * doppelganger
d62a17ae 928 */
929 if (sort == clear_all) {
930 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 931
932 bgp_peer_gr_flags_update(peer);
933
36235319 934 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 935 gr_router_detected = true;
936
c368171c 937 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 938 stype);
d62a17ae 939
940 if (ret < 0)
ff8a8a7a
CS
941 bgp_clear_vty_error(peer, afi, safi, ret,
942 errmsg, errmsg_len);
dc95985f 943 }
944
36235319
QY
945 if (gr_router_detected
946 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 947 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
948 } else if (!gr_router_detected
949 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 950 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 951 }
d62a17ae 952
953 /* This is to apply read-only mode on this clear. */
954 if (stype == BGP_CLEAR_SOFT_NONE)
955 bgp->update_delay_over = 0;
956
957 return CMD_SUCCESS;
7aafcaca
DS
958 }
959
3ae8bfa5 960 /* Clear specified neighbor. */
d62a17ae 961 if (sort == clear_peer) {
962 union sockunion su;
d62a17ae 963
964 /* Make sockunion for lookup. */
965 ret = str2sockunion(arg, &su);
966 if (ret < 0) {
967 peer = peer_lookup_by_conf_if(bgp, arg);
968 if (!peer) {
969 peer = peer_lookup_by_hostname(bgp, arg);
970 if (!peer) {
ff8a8a7a
CS
971 snprintf(
972 errmsg, errmsg_len,
973 "Malformed address or name: %s",
d62a17ae 974 arg);
975 return CMD_WARNING;
976 }
977 }
978 } else {
979 peer = peer_lookup(bgp, &su);
980 if (!peer) {
ff8a8a7a
CS
981 snprintf(errmsg, errmsg_len,
982 "%%BGP: Unknown neighbor - \"%s\"",
983 arg);
d62a17ae 984 return CMD_WARNING;
985 }
986 }
7aafcaca 987
dc95985f 988 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
989 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
990
dc912615
DS
991 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
992
993 /* if afi/safi not defined for this peer, let caller know */
994 if (ret == 1)
3ae8bfa5 995 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 996
d62a17ae 997 if (ret < 0)
ff8a8a7a
CS
998 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
999 errmsg_len);
7aafcaca 1000
d62a17ae 1001 return CMD_SUCCESS;
7aafcaca 1002 }
7aafcaca 1003
3ae8bfa5 1004 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1005 if (sort == clear_group) {
1006 struct peer_group *group;
7aafcaca 1007
d62a17ae 1008 group = peer_group_lookup(bgp, arg);
1009 if (!group) {
ff8a8a7a
CS
1010 snprintf(errmsg, errmsg_len,
1011 "%%BGP: No such peer-group %s", arg);
d62a17ae 1012 return CMD_WARNING;
1013 }
1014
1015 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1016 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1017
d62a17ae 1018 if (ret < 0)
ff8a8a7a
CS
1019 bgp_clear_vty_error(peer, afi, safi, ret,
1020 errmsg, errmsg_len);
3ae8bfa5
PM
1021 else
1022 found = true;
d62a17ae 1023 }
3ae8bfa5
PM
1024
1025 if (!found)
ff8a8a7a
CS
1026 snprintf(
1027 errmsg, errmsg_len,
1028 "%%BGP: No %s peer belonging to peer-group %s is configured",
5cb5f4d0 1029 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1030
d62a17ae 1031 return CMD_SUCCESS;
7aafcaca 1032 }
7aafcaca 1033
3ae8bfa5 1034 /* Clear all external (eBGP) neighbors. */
d62a17ae 1035 if (sort == clear_external) {
1036 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1037 if (peer->sort == BGP_PEER_IBGP)
1038 continue;
7aafcaca 1039
dc95985f 1040 bgp_peer_gr_flags_update(peer);
1041
36235319 1042 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1043 gr_router_detected = true;
dc95985f 1044
c368171c 1045 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1046
d62a17ae 1047 if (ret < 0)
ff8a8a7a
CS
1048 bgp_clear_vty_error(peer, afi, safi, ret,
1049 errmsg, errmsg_len);
3ae8bfa5
PM
1050 else
1051 found = true;
d62a17ae 1052 }
3ae8bfa5 1053
36235319
QY
1054 if (gr_router_detected
1055 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1056 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1057 } else if (!gr_router_detected
1058 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1059 bgp_zebra_send_capabilities(bgp, true);
1060 }
1061
3ae8bfa5 1062 if (!found)
ff8a8a7a
CS
1063 snprintf(errmsg, errmsg_len,
1064 "%%BGP: No external %s peer is configured",
1065 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1066
d62a17ae 1067 return CMD_SUCCESS;
1068 }
1069
3ae8bfa5 1070 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1071 if (sort == clear_as) {
3ae8bfa5 1072 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1073
1074 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1075 if (peer->as != as)
1076 continue;
1077
dc95985f 1078 bgp_peer_gr_flags_update(peer);
1079
36235319 1080 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1081 gr_router_detected = true;
dc95985f 1082
c368171c 1083 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1084
1085 if (ret < 0)
ff8a8a7a
CS
1086 bgp_clear_vty_error(peer, afi, safi, ret,
1087 errmsg, errmsg_len);
3ae8bfa5
PM
1088 else
1089 found = true;
d62a17ae 1090 }
3ae8bfa5 1091
36235319
QY
1092 if (gr_router_detected
1093 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1094 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1095 } else if (!gr_router_detected
1096 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1097 bgp_zebra_send_capabilities(bgp, true);
1098 }
1099
3ae8bfa5 1100 if (!found)
ff8a8a7a
CS
1101 snprintf(errmsg, errmsg_len,
1102 "%%BGP: No %s peer is configured with AS %s",
1103 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1104
d62a17ae 1105 return CMD_SUCCESS;
1106 }
1107
1108 return CMD_SUCCESS;
1109}
1110
ff8a8a7a
CS
1111static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1112 enum clear_sort sort, enum bgp_clear_type stype,
1113 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1114{
1115 struct bgp *bgp;
1116
1117 /* BGP structure lookup. */
1118 if (name) {
1119 bgp = bgp_lookup_by_name(name);
1120 if (bgp == NULL) {
ff8a8a7a
CS
1121 snprintf(errmsg, errmsg_len,
1122 "Can't find BGP instance %s", name);
d62a17ae 1123 return CMD_WARNING;
1124 }
1125 } else {
1126 bgp = bgp_get_default();
1127 if (bgp == NULL) {
ff8a8a7a
CS
1128 snprintf(errmsg, errmsg_len,
1129 "No BGP process is configured");
d62a17ae 1130 return CMD_WARNING;
1131 }
1132 }
1133
ff8a8a7a 1134 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
7aafcaca
DS
1135}
1136
1137/* clear soft inbound */
ff8a8a7a 1138int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1139{
99b3ebd3
NS
1140 afi_t afi;
1141 safi_t safi;
ff8a8a7a
CS
1142 int ret;
1143
1144 FOREACH_AFI_SAFI (afi, safi) {
1145 ret = bgp_clear_vty(name, afi, safi, clear_all,
1146 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1147 errmsg_len);
1148 if (ret != CMD_SUCCESS)
1149 return -1;
1150 }
99b3ebd3 1151
ff8a8a7a 1152 return 0;
7aafcaca
DS
1153}
1154
1155/* clear soft outbound */
ff8a8a7a 1156int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1157{
99b3ebd3
NS
1158 afi_t afi;
1159 safi_t safi;
ff8a8a7a 1160 int ret;
99b3ebd3 1161
ff8a8a7a
CS
1162 FOREACH_AFI_SAFI (afi, safi) {
1163 ret = bgp_clear_vty(name, afi, safi, clear_all,
1164 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1165 errmsg_len);
1166 if (ret != CMD_SUCCESS)
1167 return -1;
1168 }
1169
1170 return 0;
7aafcaca
DS
1171}
1172
1173
f787d7a0 1174#ifndef VTYSH_EXTRACT_PL
2e4c2296 1175#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1176#endif
1177
8029b216
AK
1178DEFUN_HIDDEN (bgp_local_mac,
1179 bgp_local_mac_cmd,
093e3f23 1180 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1181 BGP_STR
1182 "Local MAC config\n"
1183 "VxLAN Network Identifier\n"
1184 "VNI number\n"
1185 "local mac\n"
1186 "mac address\n"
1187 "mac-mobility sequence\n"
1188 "seq number\n")
1189{
1190 int rv;
1191 vni_t vni;
1192 struct ethaddr mac;
1193 struct ipaddr ip;
1194 uint32_t seq;
1195 struct bgp *bgp;
1196
1197 vni = strtoul(argv[3]->arg, NULL, 10);
1198 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1199 vty_out(vty, "%% Malformed MAC address\n");
1200 return CMD_WARNING;
1201 }
1202 memset(&ip, 0, sizeof(ip));
1203 seq = strtoul(argv[7]->arg, NULL, 10);
1204
1205 bgp = bgp_get_default();
1206 if (!bgp) {
1207 vty_out(vty, "Default BGP instance is not there\n");
1208 return CMD_WARNING;
1209 }
1210
b5e140c8
AK
1211 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1212 zero_esi);
8029b216
AK
1213 if (rv < 0) {
1214 vty_out(vty, "Internal error\n");
1215 return CMD_WARNING;
1216 }
1217
1218 return CMD_SUCCESS;
1219}
1220
1221DEFUN_HIDDEN (no_bgp_local_mac,
1222 no_bgp_local_mac_cmd,
093e3f23 1223 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1224 NO_STR
1225 BGP_STR
1226 "Local MAC config\n"
1227 "VxLAN Network Identifier\n"
1228 "VNI number\n"
1229 "local mac\n"
1230 "mac address\n")
1231{
1232 int rv;
1233 vni_t vni;
1234 struct ethaddr mac;
1235 struct ipaddr ip;
1236 struct bgp *bgp;
1237
1238 vni = strtoul(argv[4]->arg, NULL, 10);
1239 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1240 vty_out(vty, "%% Malformed MAC address\n");
1241 return CMD_WARNING;
1242 }
1243 memset(&ip, 0, sizeof(ip));
1244
1245 bgp = bgp_get_default();
1246 if (!bgp) {
1247 vty_out(vty, "Default BGP instance is not there\n");
1248 return CMD_WARNING;
1249 }
1250
ec0ab544 1251 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1252 if (rv < 0) {
1253 vty_out(vty, "Internal error\n");
1254 return CMD_WARNING;
1255 }
1256
1257 return CMD_SUCCESS;
1258}
1259
718e3744 1260DEFUN (no_synchronization,
1261 no_synchronization_cmd,
1262 "no synchronization",
1263 NO_STR
1264 "Perform IGP synchronization\n")
1265{
d62a17ae 1266 return CMD_SUCCESS;
718e3744 1267}
1268
1269DEFUN (no_auto_summary,
1270 no_auto_summary_cmd,
1271 "no auto-summary",
1272 NO_STR
1273 "Enable automatic network number summarization\n")
1274{
d62a17ae 1275 return CMD_SUCCESS;
718e3744 1276}
3d515fd9 1277
718e3744 1278/* "router bgp" commands. */
ff8a8a7a
CS
1279DEFUN_YANG_NOSH(router_bgp,
1280 router_bgp_cmd,
1281 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1282 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1283{
d62a17ae 1284 int idx_asn = 2;
1285 int idx_view_vrf = 3;
1286 int idx_vrf = 4;
ff8a8a7a 1287 int ret = CMD_SUCCESS;
d62a17ae 1288 as_t as;
1289 struct bgp *bgp;
1290 const char *name = NULL;
ff8a8a7a 1291 char as_str[12] = {'\0'};
d62a17ae 1292 enum bgp_instance_type inst_type;
ff8a8a7a 1293 char base_xpath[XPATH_MAXLEN];
d62a17ae 1294
1295 // "router bgp" without an ASN
1296 if (argc == 2) {
1297 // Pending: Make VRF option available for ASN less config
1298 bgp = bgp_get_default();
1299
1300 if (bgp == NULL) {
1301 vty_out(vty, "%% No BGP process is configured\n");
1302 return CMD_WARNING_CONFIG_FAILED;
1303 }
1304
1305 if (listcount(bm->bgp) > 1) {
996c9314 1306 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1307 return CMD_WARNING_CONFIG_FAILED;
1308 }
ff8a8a7a
CS
1309
1310 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
5ce106b7 1311 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
ff8a8a7a
CS
1312
1313 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1314 snprintf(as_str, 12, "%d", bgp->as);
87ce2564
CS
1315 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1316 as_str);
ff8a8a7a 1317 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1318 nb_cli_enqueue_change(vty,
1319 "./global/instance-type-view",
ff8a8a7a
CS
1320 NB_OP_MODIFY, "true");
1321 }
1322
a5ab756f 1323 nb_cli_pending_commit_check(vty);
ff8a8a7a
CS
1324 ret = nb_cli_apply_changes(vty, base_xpath);
1325 if (ret == CMD_SUCCESS) {
1326 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1327
1328 /*
1329 * For backward compatibility with old commands we still
1330 * need to use the qobj infrastructure.
1331 */
1332 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1333 }
1334 return ret;
d62a17ae 1335 }
1336
1337 // "router bgp X"
1338 else {
d62a17ae 1339
ff8a8a7a 1340 as = strtoul(argv[idx_asn]->arg, NULL, 10);
d62a17ae 1341 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1342 if (argc > 3) {
1343 name = argv[idx_vrf]->arg;
1344
9a8bdf1c
PG
1345 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1346 if (strmatch(name, VRF_DEFAULT_NAME))
1347 name = NULL;
1348 else
1349 inst_type = BGP_INSTANCE_TYPE_VRF;
ff8a8a7a 1350 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
d62a17ae 1351 inst_type = BGP_INSTANCE_TYPE_VIEW;
ff8a8a7a 1352 }
d62a17ae 1353 }
ff8a8a7a
CS
1354 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1355 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1356
1357 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
87ce2564 1358 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
ff8a8a7a
CS
1359 argv[idx_asn]->arg);
1360 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1361 nb_cli_enqueue_change(vty,
1362 "./global/instance-type-view",
ff8a8a7a 1363 NB_OP_MODIFY, "true");
d62a17ae 1364 }
1365
ff8a8a7a
CS
1366 nb_cli_pending_commit_check(vty);
1367 ret = nb_cli_apply_changes(vty, base_xpath);
1368 if (ret == CMD_SUCCESS) {
1369 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
3bd70bf8 1370
ff8a8a7a
CS
1371 /*
1372 * For backward compatibility with old commands we still
1373 * need to use the qobj infrastructure.
1374 */
1375 bgp = bgp_lookup(as, name);
1376 if (bgp)
1377 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1378 }
d62a17ae 1379 }
1380
ff8a8a7a 1381 return ret;
718e3744 1382}
1383
718e3744 1384/* "no router bgp" commands. */
ff8a8a7a
CS
1385DEFUN_YANG(no_router_bgp,
1386 no_router_bgp_cmd,
1387 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1388 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1389{
d62a17ae 1390 int idx_asn = 3;
1391 int idx_vrf = 5;
ff8a8a7a 1392 as_t as = 0;
d62a17ae 1393 struct bgp *bgp;
1394 const char *name = NULL;
ff8a8a7a 1395 char base_xpath[XPATH_MAXLEN];
4b63e358 1396 const struct lyd_node *bgp_glb_dnode;
718e3744 1397
d62a17ae 1398 // "no router bgp" without an ASN
1399 if (argc == 3) {
1400 // Pending: Make VRF option available for ASN less config
4b63e358
CS
1401 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1402 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
718e3744 1403
4b63e358
CS
1404 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1405 base_xpath);
1406 if (!bgp_glb_dnode) {
d62a17ae 1407 vty_out(vty, "%% No BGP process is configured\n");
1408 return CMD_WARNING_CONFIG_FAILED;
1409 }
7fb21a9f 1410
d62a17ae 1411 if (listcount(bm->bgp) > 1) {
996c9314 1412 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1413 return CMD_WARNING_CONFIG_FAILED;
1414 }
0b5131c9 1415
4b63e358
CS
1416 /* tcli mode bgp would not be set until apply stage. */
1417 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1418 if (!bgp)
1419 return CMD_SUCCESS;
1420
0b5131c9
MK
1421 if (bgp->l3vni) {
1422 vty_out(vty, "%% Please unconfigure l3vni %u",
1423 bgp->l3vni);
1424 return CMD_WARNING_CONFIG_FAILED;
1425 }
d62a17ae 1426 } else {
1427 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1428
d62a17ae 1429 if (argc > 4)
1430 name = argv[idx_vrf]->arg;
7fb21a9f 1431
d62a17ae 1432 /* Lookup bgp structure. */
1433 bgp = bgp_lookup(as, name);
1434 if (!bgp) {
1435 vty_out(vty, "%% Can't find BGP instance\n");
1436 return CMD_WARNING_CONFIG_FAILED;
1437 }
0b5131c9
MK
1438
1439 if (bgp->l3vni) {
dd5868c2 1440 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1441 bgp->l3vni);
1442 return CMD_WARNING_CONFIG_FAILED;
1443 }
dd5868c2
DS
1444
1445 /* Cannot delete default instance if vrf instances exist */
1446 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1447 struct listnode *node;
1448 struct bgp *tmp_bgp;
1449
1450 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1451 if (tmp_bgp->inst_type
1452 == BGP_INSTANCE_TYPE_VRF) {
1453 vty_out(vty,
1454 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1455 return CMD_WARNING_CONFIG_FAILED;
1456 }
1457 }
1458 }
d62a17ae 1459 }
ff8a8a7a
CS
1460 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1461 "frr-bgp:bgp", "bgp",
1462 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
718e3744 1463
ff8a8a7a 1464 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
718e3744 1465
ff8a8a7a 1466 return nb_cli_apply_changes(vty, base_xpath);
718e3744 1467}
1468
ff8a8a7a
CS
1469void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1470 bool show_defaults)
1471{
1472 const struct lyd_node *vrf_dnode;
1473 const char *vrf_name;
1474 as_t as;
6b0655a2 1475
ff8a8a7a
CS
1476 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1477 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
5e42cb2f 1478 as = yang_dnode_get_uint32(dnode, "./global/local-as");
718e3744 1479
ff8a8a7a
CS
1480 vty_out(vty, "!\n");
1481 vty_out(vty, "router bgp %u", as);
1482 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1483 vty_out(vty, " vrf %s", vrf_name);
1484 vty_out(vty, "\n");
718e3744 1485}
1486
ff8a8a7a
CS
1487/* BGP router-id. */
1488
1489DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1490 BGP_STR
1491 "Override configured router identifier\n"
1492 "Manually configured router identifier\n")
718e3744 1493{
87ce2564
CS
1494 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1495 router_id_str);
718e3744 1496
ff8a8a7a
CS
1497 return nb_cli_apply_changes(vty, NULL);
1498}
718e3744 1499
ff8a8a7a
CS
1500DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1501 NO_STR BGP_STR
1502 "Override configured router identifier\n"
1503 "Manually configured router identifier\n")
1504{
87ce2564 1505 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
ff8a8a7a 1506 router_id_str ? router_id_str : NULL);
718e3744 1507
ff8a8a7a 1508 return nb_cli_apply_changes(vty, NULL);
718e3744 1509}
1510
ff8a8a7a
CS
1511void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1512 bool show_defaults)
1513{
1514 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1515}
6b0655a2 1516
c208c586
S
1517DEFPY (bgp_suppress_fib_pending,
1518 bgp_suppress_fib_pending_cmd,
1519 "[no] bgp suppress-fib-pending",
1520 NO_STR
1521 BGP_STR
1522 "Advertise only routes that are programmed in kernel to peers\n")
1523{
1524 VTY_DECLVAR_CONTEXT(bgp, bgp);
1525
1526 bgp_suppress_fib_pending_set(bgp, !no);
1527 return CMD_SUCCESS;
1528}
1529
1530
718e3744 1531/* BGP Cluster ID. */
ff8a8a7a
CS
1532DEFUN_YANG(bgp_cluster_id,
1533 bgp_cluster_id_cmd,
1534 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1535 BGP_STR
1536 "Configure Route-Reflector Cluster-id\n"
1537 "Route-Reflector Cluster-id in IP address format\n"
1538 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1539{
d62a17ae 1540 int idx_ipv4 = 2;
718e3744 1541
87ce2564
CS
1542 nb_cli_enqueue_change(
1543 vty, "./global/route-reflector/route-reflector-cluster-id",
1544 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1545
ff8a8a7a 1546 return nb_cli_apply_changes(vty, NULL);
718e3744 1547}
1548
ff8a8a7a
CS
1549DEFUN_YANG(no_bgp_cluster_id,
1550 no_bgp_cluster_id_cmd,
1551 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1552 NO_STR BGP_STR
1553 "Configure Route-Reflector Cluster-id\n"
1554 "Route-Reflector Cluster-id in IP address format\n"
1555 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1556{
87ce2564
CS
1557 nb_cli_enqueue_change(
1558 vty, "./global/route-reflector/route-reflector-cluster-id",
1559 NB_OP_DESTROY, NULL);
718e3744 1560
ff8a8a7a 1561 return nb_cli_apply_changes(vty, NULL);
718e3744 1562}
1563
c163f297
DS
1564DEFPY (bgp_norib,
1565 bgp_norib_cmd,
1566 "bgp no-rib",
1567 BGP_STR
1568 "Disable BGP route installation to RIB (Zebra)\n")
1569{
1570 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1571 vty_out(vty,
1572 "%% No-RIB option is already set, nothing to do here.\n");
1573 return CMD_SUCCESS;
1574 }
1575
1576 bgp_option_norib_set_runtime();
1577
1578 return CMD_SUCCESS;
1579}
1580
1581DEFPY (no_bgp_norib,
1582 no_bgp_norib_cmd,
1583 "no bgp no-rib",
1584 NO_STR
1585 BGP_STR
1586 "Disable BGP route installation to RIB (Zebra)\n")
1587{
1588 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1589 vty_out(vty,
1590 "%% No-RIB option is not set, nothing to do here.\n");
1591 return CMD_SUCCESS;
1592 }
1593
1594 bgp_option_norib_unset_runtime();
1595
1596 return CMD_SUCCESS;
1597}
1598
e46723a5
DS
1599DEFPY (no_bgp_send_extra_data,
1600 no_bgp_send_extra_data_cmd,
1601 "[no] bgp send-extra-data zebra",
1602 NO_STR
1603 BGP_STR
1604 "Extra data to Zebra for display/use\n"
1605 "To zebra\n")
1606{
1607 bgp_option_send_extra_data(!!no);
1608
1609 return CMD_SUCCESS;
1610}
1611
ff8a8a7a
CS
1612DEFUN_YANG(bgp_confederation_identifier,
1613 bgp_confederation_identifier_cmd,
1614 "bgp confederation identifier (1-4294967295)",
1615 "BGP specific commands\n"
1616 "AS confederation parameters\n"
1617 "AS number\n"
1618 "Set routing domain confederation AS\n")
718e3744 1619{
d62a17ae 1620 int idx_number = 3;
718e3744 1621
87ce2564
CS
1622 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1623 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1624
ff8a8a7a 1625 return nb_cli_apply_changes(vty, NULL);
718e3744 1626}
1627
ff8a8a7a
CS
1628DEFUN_YANG(no_bgp_confederation_identifier,
1629 no_bgp_confederation_identifier_cmd,
1630 "no bgp confederation identifier [(1-4294967295)]",
1631 NO_STR
1632 "BGP specific commands\n"
1633 "AS confederation parameters\n"
1634 "AS number\n"
1635 "Set routing domain confederation AS\n")
718e3744 1636{
87ce2564
CS
1637 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1638 NB_OP_DESTROY, NULL);
718e3744 1639
ff8a8a7a 1640 return nb_cli_apply_changes(vty, NULL);
718e3744 1641}
1642
ff8a8a7a
CS
1643void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1644 struct lyd_node *dnode,
1645 bool show_defaults)
1646{
1647 vty_out(vty, " bgp confederation identifier %u\n",
1648 yang_dnode_get_uint32(dnode, NULL));
1649}
1650
1651DEFUN_YANG(bgp_confederation_peers,
1652 bgp_confederation_peers_cmd,
1653 "bgp confederation peers (1-4294967295)...",
1654 "BGP specific commands\n"
1655 "AS confederation parameters\n"
1656 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1657{
d62a17ae 1658 int idx_asn = 3;
d62a17ae 1659 int i;
718e3744 1660
ff8a8a7a 1661 for (i = idx_asn; i < argc; i++)
87ce2564 1662 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1663 NB_OP_CREATE, argv[i]->arg);
718e3744 1664
ff8a8a7a 1665 return nb_cli_apply_changes(vty, NULL);
718e3744 1666}
1667
ff8a8a7a
CS
1668DEFUN_YANG(no_bgp_confederation_peers,
1669 no_bgp_confederation_peers_cmd,
1670 "no bgp confederation peers (1-4294967295)...",
1671 NO_STR
1672 "BGP specific commands\n"
1673 "AS confederation parameters\n"
1674 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1675{
d62a17ae 1676 int idx_asn = 4;
d62a17ae 1677 int i;
718e3744 1678
ff8a8a7a 1679 for (i = idx_asn; i < argc; i++)
87ce2564 1680 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1681 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1682
ff8a8a7a
CS
1683 return nb_cli_apply_changes(vty, NULL);
1684}
1685
1686void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1687 struct lyd_node *dnode,
1688 bool show_defaults)
1689{
1690 vty_out(vty, " bgp confederation peers %u \n",
1691 yang_dnode_get_uint32(dnode, NULL));
718e3744 1692}
6b0655a2 1693
5e242b0d
DS
1694/**
1695 * Central routine for maximum-paths configuration.
1696 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1697 * @set: 1 for setting values, 0 for removing the max-paths config.
1698 */
37a87b8f
CS
1699int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1700 int peer_type, uint16_t maxpaths, uint16_t options,
1701 int set, char *errmsg, size_t errmsg_len)
d62a17ae 1702{
d62a17ae 1703 int ret;
d62a17ae 1704
1705 if (set) {
d62a17ae 1706 if (maxpaths > multipath_num) {
37a87b8f
CS
1707 snprintf(
1708 errmsg, errmsg_len,
d62a17ae 1709 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1710 maxpaths, multipath_num);
1711 return CMD_WARNING_CONFIG_FAILED;
1712 }
1713 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1714 options);
1715 } else
1716 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1717
1718 if (ret < 0) {
37a87b8f
CS
1719 snprintf(
1720 errmsg, errmsg_len,
d62a17ae 1721 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1722 (set == 1) ? "" : "un",
1723 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1724 maxpaths, afi, safi);
1725 return CMD_WARNING_CONFIG_FAILED;
1726 }
1727
1728 bgp_recalculate_all_bestpaths(bgp);
1729
1730 return CMD_SUCCESS;
165b5fff
JB
1731}
1732
ff8a8a7a
CS
1733void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1734 bool show_defaults)
abc920f8 1735{
ff8a8a7a
CS
1736 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1737 uint32_t med_admin_val;
abc920f8 1738
ff8a8a7a
CS
1739 vty_out(vty, " bgp max-med administrative");
1740 if ((med_admin_val =
1741 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1742 != BGP_MAXMED_VALUE_DEFAULT)
1743 vty_out(vty, " %u", med_admin_val);
1744 vty_out(vty, "\n");
1745 }
abc920f8 1746
ff8a8a7a
CS
1747 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1748 uint32_t onstartup_val;
abc920f8 1749
ff8a8a7a
CS
1750 vty_out(vty, " bgp max-med on-startup %u",
1751 yang_dnode_get_uint32(dnode,
1752 "./max-med-onstart-up-time"));
1753 onstartup_val = yang_dnode_get_uint32(
1754 dnode, "./max-med-onstart-up-value");
1755 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1756 vty_out(vty, " %u", onstartup_val);
1757
1758 vty_out(vty, "\n");
1759 }
abc920f8
DS
1760}
1761
ff8a8a7a
CS
1762DEFUN_YANG(bgp_maxmed_admin,
1763 bgp_maxmed_admin_cmd,
1764 "bgp max-med administrative ",
1765 BGP_STR
1766 "Advertise routes with max-med\n"
1767 "Administratively applied, for an indefinite period\n")
1768{
87ce2564 1769 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1770 NB_OP_MODIFY, "true");
1771
1772 return nb_cli_apply_changes(vty, NULL);
1773}
1774
1775DEFUN_YANG(bgp_maxmed_admin_medv,
1776 bgp_maxmed_admin_medv_cmd,
1777 "bgp max-med administrative (0-4294967295)",
1778 BGP_STR
1779 "Advertise routes with max-med\n"
1780 "Administratively applied, for an indefinite period\n"
1781 "Max MED value to be used\n")
abc920f8 1782{
d62a17ae 1783 int idx_number = 3;
abc920f8 1784
87ce2564 1785 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1786 NB_OP_MODIFY, "true");
abc920f8 1787
87ce2564
CS
1788 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1789 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1790
ff8a8a7a 1791 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1792}
1793
ff8a8a7a
CS
1794DEFUN_YANG(no_bgp_maxmed_admin,
1795 no_bgp_maxmed_admin_cmd,
1796 "no bgp max-med administrative [(0-4294967295)]",
1797 NO_STR BGP_STR
1798 "Advertise routes with max-med\n"
1799 "Administratively applied, for an indefinite period\n"
1800 "Max MED value to be used\n")
abc920f8 1801{
87ce2564 1802 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1803 NB_OP_MODIFY, "false");
abc920f8 1804
87ce2564
CS
1805 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1806 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1807
1808 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1809}
1810
37a87b8f
CS
1811DEFUN_YANG (bgp_maxmed_onstartup,
1812 bgp_maxmed_onstartup_cmd,
1813 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1814 BGP_STR
1815 "Advertise routes with max-med\n"
1816 "Effective on a startup\n"
1817 "Time (seconds) period for max-med\n"
1818 "Max MED value to be used\n")
abc920f8 1819{
d62a17ae 1820 int idx = 0;
4668a151 1821
d62a17ae 1822 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1823 nb_cli_enqueue_change(vty,
1824 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1825 NB_OP_MODIFY, argv[idx]->arg);
1826
d62a17ae 1827 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1828 nb_cli_enqueue_change(
1829 vty, "./global/med-config/max-med-onstart-up-value",
1830 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1831 else
87ce2564
CS
1832 nb_cli_enqueue_change(
1833 vty, "./global/med-config/max-med-onstart-up-value",
1834 NB_OP_MODIFY, NULL);
abc920f8 1835
ff8a8a7a 1836 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1837}
1838
37a87b8f
CS
1839DEFUN_YANG (no_bgp_maxmed_onstartup,
1840 no_bgp_maxmed_onstartup_cmd,
1841 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1842 NO_STR BGP_STR
1843 "Advertise routes with max-med\n"
1844 "Effective on a startup\n"
1845 "Time (seconds) period for max-med\n"
1846 "Max MED value to be used\n")
abc920f8 1847{
87ce2564
CS
1848 nb_cli_enqueue_change(vty,
1849 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1850 NB_OP_DESTROY, NULL);
abc920f8 1851
87ce2564
CS
1852 nb_cli_enqueue_change(vty,
1853 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1854 NB_OP_MODIFY, NULL);
abc920f8 1855
ff8a8a7a 1856 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1857}
1858
d70583f7
D
1859static int bgp_global_update_delay_config_vty(struct vty *vty,
1860 uint16_t update_delay,
1861 uint16_t establish_wait)
1862{
1863 struct listnode *node, *nnode;
1864 struct bgp *bgp;
1865 bool vrf_cfg = false;
1866
1867 /*
1868 * See if update-delay is set per-vrf and warn user to delete it
1869 * Note that we only need to check this if this is the first time
1870 * setting the global config.
1871 */
1872 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1873 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1874 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1875 vty_out(vty,
1876 "%% update-delay configuration found in vrf %s\n",
1877 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1878 ? VRF_DEFAULT_NAME
1879 : bgp->name);
1880 vrf_cfg = true;
1881 }
1882 }
1883 }
1884
1885 if (vrf_cfg) {
1886 vty_out(vty,
1887 "%%Failed: global update-delay config not permitted\n");
1888 return CMD_WARNING;
1889 }
1890
1891 if (!establish_wait) { /* update-delay <delay> */
1892 bm->v_update_delay = update_delay;
1893 bm->v_establish_wait = bm->v_update_delay;
1894 } else {
1895 /* update-delay <delay> <establish-wait> */
1896 if (update_delay < establish_wait) {
1897 vty_out(vty,
1898 "%%Failed: update-delay less than the establish-wait!\n");
1899 return CMD_WARNING_CONFIG_FAILED;
1900 }
1901
1902 bm->v_update_delay = update_delay;
1903 bm->v_establish_wait = establish_wait;
1904 }
1905
1906 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1907 bgp->v_update_delay = bm->v_update_delay;
1908 bgp->v_establish_wait = bm->v_establish_wait;
1909 }
1910
1911 return CMD_SUCCESS;
1912}
1913
1914static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1915{
1916 struct listnode *node, *nnode;
1917 struct bgp *bgp;
1918
1919 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1920 bm->v_establish_wait = bm->v_update_delay;
1921
1922 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1923 bgp->v_update_delay = bm->v_update_delay;
1924 bgp->v_establish_wait = bm->v_establish_wait;
1925 }
1926
1927 return CMD_SUCCESS;
1928}
1929
1930static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1931 uint16_t establish_wait)
f188f2c4 1932{
d62a17ae 1933 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1934
d70583f7
D
1935 /* if configured globally, per-instance config is not allowed */
1936 if (bm->v_update_delay) {
1937 vty_out(vty,
1938 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1939 return CMD_WARNING_CONFIG_FAILED;
1940 }
1941
f188f2c4 1942
d70583f7 1943 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1944 {
1945 bgp->v_update_delay = update_delay;
1946 bgp->v_establish_wait = bgp->v_update_delay;
1947 return CMD_SUCCESS;
1948 }
f188f2c4 1949
d62a17ae 1950 /* update-delay <delay> <establish-wait> */
d62a17ae 1951 if (update_delay < establish_wait) {
1952 vty_out(vty,
1953 "%%Failed: update-delay less than the establish-wait!\n");
1954 return CMD_WARNING_CONFIG_FAILED;
1955 }
f188f2c4 1956
d62a17ae 1957 bgp->v_update_delay = update_delay;
1958 bgp->v_establish_wait = establish_wait;
f188f2c4 1959
d62a17ae 1960 return CMD_SUCCESS;
f188f2c4
DS
1961}
1962
d62a17ae 1963static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1964{
d62a17ae 1965 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1966
d70583f7
D
1967 /* If configured globally, cannot remove from one bgp instance */
1968 if (bm->v_update_delay) {
1969 vty_out(vty,
1970 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
1971 return CMD_WARNING_CONFIG_FAILED;
1972 }
d62a17ae 1973 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1974 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1975
d62a17ae 1976 return CMD_SUCCESS;
f188f2c4
DS
1977}
1978
2b791107 1979void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1980{
d70583f7
D
1981 /* If configured globally, no need to display per-instance value */
1982 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 1983 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1984 if (bgp->v_update_delay != bgp->v_establish_wait)
1985 vty_out(vty, " %d", bgp->v_establish_wait);
1986 vty_out(vty, "\n");
1987 }
f188f2c4
DS
1988}
1989
d70583f7
D
1990/* Global update-delay configuration */
1991DEFPY (bgp_global_update_delay,
1992 bgp_global_update_delay_cmd,
1993 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
1994 BGP_STR
1995 "Force initial delay for best-path and updates for all bgp instances\n"
1996 "Max delay in seconds\n"
1997 "Establish wait in seconds\n")
1998{
1999 return bgp_global_update_delay_config_vty(vty, delay, wait);
2000}
f188f2c4 2001
d70583f7
D
2002/* Global update-delay deconfiguration */
2003DEFPY (no_bgp_global_update_delay,
2004 no_bgp_global_update_delay_cmd,
2005 "no bgp update-delay [(0-3600) [(1-3600)]]",
2006 NO_STR
2007 BGP_STR
f188f2c4 2008 "Force initial delay for best-path and updates\n"
d70583f7
D
2009 "Max delay in seconds\n"
2010 "Establish wait in seconds\n")
f188f2c4 2011{
d70583f7 2012 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2013}
2014
d70583f7
D
2015/* Update-delay configuration */
2016
2017DEFPY (bgp_update_delay,
2018 bgp_update_delay_cmd,
2019 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2020 "Force initial delay for best-path and updates\n"
d70583f7
D
2021 "Max delay in seconds\n"
2022 "Establish wait in seconds\n")
f188f2c4 2023{
d70583f7 2024 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2025}
2026
2027/* Update-delay deconfiguration */
d70583f7 2028DEFPY (no_bgp_update_delay,
f188f2c4 2029 no_bgp_update_delay_cmd,
838758ac
DW
2030 "no update-delay [(0-3600) [(1-3600)]]",
2031 NO_STR
f188f2c4 2032 "Force initial delay for best-path and updates\n"
d70583f7
D
2033 "Max delay in seconds\n"
2034 "Establish wait in seconds\n")
f188f2c4 2035{
d62a17ae 2036 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2037}
2038
5e242b0d 2039
ff8a8a7a 2040int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 2041{
8fa7732f
QY
2042 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2043 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2044
2045 return CMD_SUCCESS;
2046}
2047
ff8a8a7a 2048int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 2049{
8fa7732f
QY
2050 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2051 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2052
d62a17ae 2053 return CMD_SUCCESS;
cb1faec9
DS
2054}
2055
2b791107 2056void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2057{
555e09d4
QY
2058 uint32_t quanta =
2059 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2060 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2061 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2062}
2063
555e09d4
QY
2064void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2065{
2066 uint32_t quanta =
2067 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2068 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2069 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2070}
cb1faec9 2071
8fa7732f
QY
2072/* Packet quanta configuration
2073 *
2074 * XXX: The value set here controls the size of a stack buffer in the IO
2075 * thread. When changing these limits be careful to prevent stack overflow.
2076 *
2077 * Furthermore, the maximums used here should correspond to
2078 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2079 */
37a87b8f
CS
2080DEFPY_YANG (bgp_wpkt_quanta,
2081 bgp_wpkt_quanta_cmd,
2082 "[no] write-quanta (1-64)$quanta",
2083 NO_STR
2084 "How many packets to write to peer socket per run\n"
2085 "Number of packets\n")
ff8a8a7a
CS
2086{
2087 if (!no)
2088 nb_cli_enqueue_change(
2089 vty,
87ce2564 2090 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2091 NB_OP_MODIFY, quanta_str);
2092 else
2093 nb_cli_enqueue_change(
2094 vty,
87ce2564 2095 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2096 NB_OP_MODIFY, NULL);
2097
2098 return nb_cli_apply_changes(vty, NULL);
2099}
2100
37a87b8f
CS
2101DEFPY_YANG (bgp_rpkt_quanta,
2102 bgp_rpkt_quanta_cmd,
2103 "[no] read-quanta (1-10)$quanta",
2104 NO_STR
2105 "How many packets to read from peer socket per I/O cycle\n"
2106 "Number of packets\n")
ff8a8a7a
CS
2107{
2108 if (!no)
2109 nb_cli_enqueue_change(
2110 vty,
87ce2564 2111 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2112 NB_OP_MODIFY, quanta_str);
2113 else
2114 nb_cli_enqueue_change(
2115 vty,
87ce2564 2116 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2117 NB_OP_MODIFY, NULL);
cb1faec9 2118
ff8a8a7a 2119 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2120}
2121
2b791107 2122void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2123{
37a333fe 2124 if (!bgp->heuristic_coalesce)
d62a17ae 2125 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2126}
2127
ff8a8a7a
CS
2128void cli_show_router_global_update_group_config_coalesce_time(
2129 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2130{
ff8a8a7a
CS
2131 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2132}
2133
4668a151 2134
37a87b8f
CS
2135DEFUN_YANG (bgp_coalesce_time,
2136 bgp_coalesce_time_cmd,
2137 "coalesce-time (0-4294967295)",
2138 "Subgroup coalesce timer\n"
2139 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2140{
d62a17ae 2141 int idx = 0;
ff8a8a7a 2142
d62a17ae 2143 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2144 nb_cli_enqueue_change(
2145 vty, "./global/global-update-group-config/coalesce-time",
2146 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2147
2148 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2149}
2150
ff8a8a7a
CS
2151DEFUN_YANG(no_bgp_coalesce_time,
2152 no_bgp_coalesce_time_cmd,
2153 "no coalesce-time (0-4294967295)",
2154 NO_STR
2155 "Subgroup coalesce timer\n"
2156 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2157{
87ce2564
CS
2158 nb_cli_enqueue_change(
2159 vty, "./global/global-update-group-config/coalesce-time",
2160 NB_OP_MODIFY, NULL);
4668a151 2161
ff8a8a7a 2162 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2163}
2164
5e242b0d 2165/* Maximum-paths configuration */
37a87b8f
CS
2166DEFUN_YANG (bgp_maxpaths,
2167 bgp_maxpaths_cmd,
2168 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2169 "Forward packets over multiple paths\n"
2170 "Number of paths\n")
5e242b0d 2171{
d62a17ae 2172 int idx_number = 1;
37a87b8f
CS
2173 char base_xpath[XPATH_MAXLEN];
2174 afi_t afi;
2175 safi_t safi;
2176
2177 afi = bgp_node_afi(vty);
2178 safi = bgp_node_safi(vty);
2179
2180 snprintf(
2181 base_xpath, sizeof(base_xpath),
2182 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2183 yang_afi_safi_value2identity(afi, safi),
2184 bgp_afi_safi_get_container_str(afi, safi));
2185
2186 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2187 argv[idx_number]->arg);
2188
2189 return nb_cli_apply_changes(vty, NULL);
2190}
2191
2192void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2193 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2194{
2195 vty_out(vty, " maximum-paths %d\n",
2196 yang_dnode_get_uint16(dnode, NULL));
5e242b0d
DS
2197}
2198
d62a17ae 2199ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2200 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2201 "Forward packets over multiple paths\n"
2202 "Number of paths\n")
596c17ba 2203
37a87b8f
CS
2204DEFUN_YANG (bgp_maxpaths_ibgp,
2205 bgp_maxpaths_ibgp_cmd,
2206 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2207 "Forward packets over multiple paths\n"
2208 "iBGP-multipath\n"
2209 "Number of paths\n")
165b5fff 2210{
d62a17ae 2211 int idx_number = 2;
37a87b8f
CS
2212 char base_xpath[XPATH_MAXLEN];
2213 afi_t afi;
2214 safi_t safi;
2215
2216 afi = bgp_node_afi(vty);
2217 safi = bgp_node_safi(vty);
2218
2219 snprintf(
2220 base_xpath, sizeof(base_xpath),
2221 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2222 yang_afi_safi_value2identity(afi, safi),
2223 bgp_afi_safi_get_container_str(afi, safi));
2224
2225 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2226 argv[idx_number]->arg);
2227
2228 return nb_cli_apply_changes(vty, NULL);
5e242b0d 2229}
165b5fff 2230
d62a17ae 2231ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2232 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2233 "Forward packets over multiple paths\n"
2234 "iBGP-multipath\n"
2235 "Number of paths\n")
596c17ba 2236
37a87b8f
CS
2237DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2238 bgp_maxpaths_ibgp_cluster_cmd,
2239 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2240 "Forward packets over multiple paths\n"
2241 "iBGP-multipath\n"
2242 "Number of paths\n"
2243 "Match the cluster length\n")
5e242b0d 2244{
d62a17ae 2245 int idx_number = 2;
37a87b8f
CS
2246 char base_xpath[XPATH_MAXLEN];
2247 afi_t afi;
2248 safi_t safi;
2249
2250 afi = bgp_node_afi(vty);
2251 safi = bgp_node_safi(vty);
2252
2253 snprintf(
2254 base_xpath, sizeof(base_xpath),
2255 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2256 yang_afi_safi_value2identity(afi, safi),
2257 bgp_afi_safi_get_container_str(afi, safi));
2258
2259 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2260 argv[idx_number]->arg);
2261
2262 snprintf(
2263 base_xpath, sizeof(base_xpath),
2264 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2265 yang_afi_safi_value2identity(afi, safi),
2266 bgp_afi_safi_get_container_str(afi, safi));
2267
2268 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2269
2270 return nb_cli_apply_changes(vty, NULL);
2271}
2272
2273void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2274 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2275{
2276 vty_out(vty, " maximum-paths ibgp %d",
2277 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2278 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2279 vty_out(vty, " equal-cluster-length");
2280 vty_out(vty, "\n");
165b5fff
JB
2281}
2282
d62a17ae 2283ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2284 "maximum-paths ibgp " CMD_RANGE_STR(
2285 1, MULTIPATH_NUM) " equal-cluster-length",
2286 "Forward packets over multiple paths\n"
2287 "iBGP-multipath\n"
2288 "Number of paths\n"
2289 "Match the cluster length\n")
596c17ba 2290
37a87b8f
CS
2291DEFUN_YANG (no_bgp_maxpaths,
2292 no_bgp_maxpaths_cmd,
2293 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2294 NO_STR
2295 "Forward packets over multiple paths\n"
2296 "Number of paths\n")
165b5fff 2297{
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/ebgp/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, NULL);
2312
2313 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2314}
2315
d62a17ae 2316ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2317 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2318 "Forward packets over multiple paths\n"
2319 "Number of paths\n")
596c17ba 2320
37a87b8f
CS
2321DEFUN_YANG (no_bgp_maxpaths_ibgp,
2322 no_bgp_maxpaths_ibgp_cmd,
2323 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2324 NO_STR
2325 "Forward packets over multiple paths\n"
2326 "iBGP-multipath\n"
2327 "Number of paths\n"
2328 "Match the cluster length\n")
165b5fff 2329{
37a87b8f
CS
2330 char base_xpath[XPATH_MAXLEN];
2331 afi_t afi;
2332 safi_t safi;
2333
2334 afi = bgp_node_afi(vty);
2335 safi = bgp_node_safi(vty);
2336
2337 snprintf(
2338 base_xpath, sizeof(base_xpath),
2339 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2340 yang_afi_safi_value2identity(afi, safi),
2341 bgp_afi_safi_get_container_str(afi, safi));
2342
2343 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2344
2345 snprintf(
2346 base_xpath, sizeof(base_xpath),
2347 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2348 yang_afi_safi_value2identity(afi, safi),
2349 bgp_afi_safi_get_container_str(afi, safi));
2350
2351 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2352
2353 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2354}
2355
d62a17ae 2356ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2357 "no maximum-paths ibgp [" CMD_RANGE_STR(
2358 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2359 NO_STR
2360 "Forward packets over multiple paths\n"
2361 "iBGP-multipath\n"
2362 "Number of paths\n"
2363 "Match the cluster length\n")
596c17ba 2364
dd65f45e
DL
2365static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2366 afi_t afi, safi_t safi)
165b5fff 2367{
00908b7a 2368 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2369 vty_out(vty, " maximum-paths %d\n",
2370 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2371 }
165b5fff 2372
00908b7a 2373 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2374 vty_out(vty, " maximum-paths ibgp %d",
2375 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2376 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2377 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2378 vty_out(vty, " equal-cluster-length");
2379 vty_out(vty, "\n");
2380 }
165b5fff 2381}
6b0655a2 2382
718e3744 2383/* BGP timers. */
2384
37a87b8f
CS
2385DEFUN_YANG (bgp_timers,
2386 bgp_timers_cmd,
2387 "timers bgp (0-65535) (0-65535)",
2388 "Adjust routing timers\n"
2389 "BGP timers\n"
2390 "Keepalive interval\n"
2391 "Holdtime\n")
718e3744 2392{
d62a17ae 2393 int idx_number = 2;
2394 int idx_number_2 = 3;
718e3744 2395
87ce2564 2396 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2397 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2398 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2399 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2400
ff8a8a7a
CS
2401 return nb_cli_apply_changes(vty, NULL);
2402}
718e3744 2403
37a87b8f
CS
2404DEFUN_YANG (no_bgp_timers,
2405 no_bgp_timers_cmd,
2406 "no timers bgp [(0-65535) (0-65535)]",
2407 NO_STR
2408 "Adjust routing timers\n"
2409 "BGP timers\n"
2410 "Keepalive interval\n"
2411 "Holdtime\n")
ff8a8a7a 2412{
87ce2564 2413 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2414 NB_OP_DESTROY, NULL);
87ce2564 2415 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2416 NB_OP_DESTROY, NULL);
718e3744 2417
ff8a8a7a 2418 return nb_cli_apply_changes(vty, NULL);
718e3744 2419}
2420
ff8a8a7a
CS
2421void cli_show_router_bgp_route_reflector(struct vty *vty,
2422 struct lyd_node *dnode,
2423 bool show_defaults)
718e3744 2424{
ff8a8a7a
CS
2425 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2426 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2427
ff8a8a7a
CS
2428 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2429 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2430
2431 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2432 vty_out(vty, " bgp cluster-id %s\n",
2433 yang_dnode_get_string(dnode,
2434 "./route-reflector-cluster-id"));
718e3744 2435}
2436
ff8a8a7a
CS
2437DEFUN_YANG(bgp_client_to_client_reflection,
2438 bgp_client_to_client_reflection_cmd,
2439 "bgp client-to-client reflection",
2440 "BGP specific commands\n"
2441 "Configure client to client route reflection\n"
2442 "reflection of routes allowed\n")
2443{
87ce2564 2444 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2445 NB_OP_MODIFY, "false");
6b0655a2 2446
ff8a8a7a
CS
2447 return nb_cli_apply_changes(vty, NULL);
2448}
2449
2450DEFUN_YANG(no_bgp_client_to_client_reflection,
2451 no_bgp_client_to_client_reflection_cmd,
2452 "no bgp client-to-client reflection",
2453 NO_STR
2454 "BGP specific commands\n"
2455 "Configure client to client route reflection\n"
2456 "reflection of routes allowed\n")
718e3744 2457{
87ce2564 2458 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2459 NB_OP_MODIFY, "true");
7aafcaca 2460
ff8a8a7a 2461 return nb_cli_apply_changes(vty, NULL);
718e3744 2462}
2463
ff8a8a7a
CS
2464void cli_show_router_bgp_route_selection(struct vty *vty,
2465 struct lyd_node *dnode,
2466 bool show_defaults)
718e3744 2467{
7aafcaca 2468
ff8a8a7a
CS
2469 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2470 vty_out(vty, " bgp always-compare-med\n");
2471
2472 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2473 vty_out(vty, " bgp bestpath as-path ignore\n");
2474
2475 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2476 vty_out(vty, " bgp bestpath as-path confed\n");
2477
2478 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2479 vty_out(vty, " bgp bestpath compare-routerid\n");
2480
2481 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2482 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2483 vty_out(vty,
2484 " bgp bestpath as-path multipath-relax as-set\n");
2485 else
2486 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2487 }
2488
2489 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2490 vty_out(vty, " bgp deterministic-med\n");
2491
2492 if (yang_dnode_get_bool(dnode, "./confed-med")
2493 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2494 vty_out(vty, " bgp bestpath med");
2495 if (yang_dnode_get_bool(dnode, "./confed-med"))
2496 vty_out(vty, " confed");
2497 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2498 vty_out(vty, " missing-as-worst");
2499 vty_out(vty, "\n");
2500 }
718e3744 2501}
2502
2503/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2504DEFUN_YANG(bgp_always_compare_med,
2505 bgp_always_compare_med_cmd,
2506 "bgp always-compare-med",
2507 "BGP specific commands\n"
2508 "Allow comparing MED from different neighbors\n")
718e3744 2509{
87ce2564
CS
2510 nb_cli_enqueue_change(
2511 vty, "./global/route-selection-options/always-compare-med",
2512 NB_OP_MODIFY, "true");
7aafcaca 2513
ff8a8a7a 2514 return nb_cli_apply_changes(vty, NULL);
718e3744 2515}
2516
ff8a8a7a
CS
2517DEFUN_YANG(no_bgp_always_compare_med,
2518 no_bgp_always_compare_med_cmd,
2519 "no bgp always-compare-med",
2520 NO_STR
2521 "BGP specific commands\n"
2522 "Allow comparing MED from different neighbors\n")
718e3744 2523{
87ce2564
CS
2524 nb_cli_enqueue_change(
2525 vty, "./global/route-selection-options/always-compare-med",
2526 NB_OP_MODIFY, "false");
7aafcaca 2527
ff8a8a7a 2528 return nb_cli_apply_changes(vty, NULL);
718e3744 2529}
6b0655a2 2530
ff8a8a7a
CS
2531DEFUN_YANG(bgp_ebgp_requires_policy,
2532 bgp_ebgp_requires_policy_cmd,
2533 "bgp ebgp-requires-policy",
2534 "BGP specific commands\n"
2535 "Require in and out policy for eBGP peers (RFC8212)\n")
2536{
87ce2564
CS
2537 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2538 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2539 return nb_cli_apply_changes(vty, NULL);
2540}
9dac9fc8 2541
ff8a8a7a
CS
2542DEFUN_YANG(no_bgp_ebgp_requires_policy,
2543 no_bgp_ebgp_requires_policy_cmd,
2544 "no bgp ebgp-requires-policy",
2545 NO_STR
2546 "BGP specific commands\n"
2547 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2548{
87ce2564
CS
2549 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2550 NB_OP_MODIFY, "false");
ff8a8a7a 2551 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2552}
2553
ff8a8a7a
CS
2554void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2555 struct lyd_node *dnode,
2556 bool show_defaults)
9dac9fc8 2557{
ff8a8a7a
CS
2558 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2559 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2560}
2561
fb29348a
DA
2562DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2563 "bgp reject-as-sets",
2564 "BGP specific commands\n"
2565 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2566{
2567 VTY_DECLVAR_CONTEXT(bgp, bgp);
2568 struct listnode *node, *nnode;
2569 struct peer *peer;
2570
7f972cd8 2571 bgp->reject_as_sets = true;
fb29348a
DA
2572
2573 /* Reset existing BGP sessions to reject routes
2574 * with aspath containing AS_SET or AS_CONFED_SET.
2575 */
2576 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2577 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2578 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2579 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2580 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2581 }
2582 }
2583
2584 return CMD_SUCCESS;
2585}
2586
2587DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2588 "no bgp reject-as-sets",
2589 NO_STR
2590 "BGP specific commands\n"
2591 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2592{
2593 VTY_DECLVAR_CONTEXT(bgp, bgp);
2594 struct listnode *node, *nnode;
2595 struct peer *peer;
2596
7f972cd8 2597 bgp->reject_as_sets = false;
fb29348a
DA
2598
2599 /* Reset existing BGP sessions to reject routes
2600 * with aspath containing AS_SET or AS_CONFED_SET.
2601 */
2602 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2603 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2604 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2605 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2606 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2607 }
2608 }
2609
2610 return CMD_SUCCESS;
2611}
9dac9fc8 2612
718e3744 2613/* "bgp deterministic-med" configuration. */
ff8a8a7a 2614DEFUN_YANG (bgp_deterministic_med,
718e3744 2615 bgp_deterministic_med_cmd,
2616 "bgp deterministic-med",
2617 "BGP specific commands\n"
2618 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2619{
87ce2564
CS
2620 nb_cli_enqueue_change(
2621 vty, "./global/route-selection-options/deterministic-med",
2622 NB_OP_MODIFY, "true");
7aafcaca 2623
ff8a8a7a 2624 return nb_cli_apply_changes(vty, NULL);
718e3744 2625}
2626
ff8a8a7a 2627DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2628 no_bgp_deterministic_med_cmd,
2629 "no bgp deterministic-med",
2630 NO_STR
2631 "BGP specific commands\n"
2632 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2633{
87ce2564
CS
2634 nb_cli_enqueue_change(
2635 vty, "./global/route-selection-options/deterministic-med",
2636 NB_OP_MODIFY, "false");
d62a17ae 2637
ff8a8a7a 2638 return nb_cli_apply_changes(vty, NULL);
718e3744 2639}
538621f2 2640
055679e9 2641/* "bgp graceful-restart mode" configuration. */
538621f2 2642DEFUN (bgp_graceful_restart,
2ba1fe69 2643 bgp_graceful_restart_cmd,
2644 "bgp graceful-restart",
2645 "BGP specific commands\n"
2646 GR_CMD
055679e9 2647 )
538621f2 2648{
055679e9 2649 int ret = BGP_GR_FAILURE;
2650
2651 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2652 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2653
d62a17ae 2654 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2655
2656 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2657
36235319
QY
2658 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2659 ret);
5cce3f05 2660
055679e9 2661 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2662 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2663 vty_out(vty,
2664 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2665 return bgp_vty_return(vty, ret);
538621f2 2666}
2667
2668DEFUN (no_bgp_graceful_restart,
2ba1fe69 2669 no_bgp_graceful_restart_cmd,
2670 "no bgp graceful-restart",
2671 NO_STR
2672 "BGP specific commands\n"
2673 NO_GR_CMD
055679e9 2674 )
538621f2 2675{
d62a17ae 2676 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2677
2678 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2679 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2680
2681 int ret = BGP_GR_FAILURE;
2682
2683 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2684
36235319
QY
2685 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2686 ret);
5cce3f05 2687
055679e9 2688 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2689 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2690 vty_out(vty,
2691 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2692
2693 return bgp_vty_return(vty, ret);
538621f2 2694}
2695
93406d87 2696DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2697 bgp_graceful_restart_stalepath_time_cmd,
2698 "bgp graceful-restart stalepath-time (1-4095)",
2699 "BGP specific commands\n"
2700 "Graceful restart capability parameters\n"
2701 "Set the max time to hold onto restarting peer's stale paths\n"
2702 "Delay value (seconds)\n")
93406d87 2703{
d62a17ae 2704 VTY_DECLVAR_CONTEXT(bgp, bgp);
2705 int idx_number = 3;
d7c0a89a 2706 uint32_t stalepath;
93406d87 2707
d62a17ae 2708 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2709 bgp->stalepath_time = stalepath;
2710 return CMD_SUCCESS;
93406d87 2711}
2712
eb6f1b41 2713DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2714 bgp_graceful_restart_restart_time_cmd,
2715 "bgp graceful-restart restart-time (1-4095)",
2716 "BGP specific commands\n"
2717 "Graceful restart capability parameters\n"
2718 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2719 "Delay value (seconds)\n")
eb6f1b41 2720{
d62a17ae 2721 VTY_DECLVAR_CONTEXT(bgp, bgp);
2722 int idx_number = 3;
d7c0a89a 2723 uint32_t restart;
eb6f1b41 2724
d62a17ae 2725 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2726 bgp->restart_time = restart;
2727 return CMD_SUCCESS;
eb6f1b41
PG
2728}
2729
cfd47646 2730DEFUN (bgp_graceful_restart_select_defer_time,
2731 bgp_graceful_restart_select_defer_time_cmd,
2732 "bgp graceful-restart select-defer-time (0-3600)",
2733 "BGP specific commands\n"
2734 "Graceful restart capability parameters\n"
2735 "Set the time to defer the BGP route selection after restart\n"
2736 "Delay value (seconds, 0 - disable)\n")
2737{
2738 VTY_DECLVAR_CONTEXT(bgp, bgp);
2739 int idx_number = 3;
2740 uint32_t defer_time;
2741
2742 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2743 bgp->select_defer_time = defer_time;
2744 if (defer_time == 0)
892fedb6 2745 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2746 else
892fedb6 2747 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2748
2749 return CMD_SUCCESS;
2750}
2751
93406d87 2752DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2753 no_bgp_graceful_restart_stalepath_time_cmd,
2754 "no bgp graceful-restart stalepath-time [(1-4095)]",
2755 NO_STR
2756 "BGP specific commands\n"
2757 "Graceful restart capability parameters\n"
2758 "Set the max time to hold onto restarting peer's stale paths\n"
2759 "Delay value (seconds)\n")
93406d87 2760{
d62a17ae 2761 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2762
d62a17ae 2763 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2764 return CMD_SUCCESS;
93406d87 2765}
2766
eb6f1b41 2767DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2768 no_bgp_graceful_restart_restart_time_cmd,
2769 "no bgp graceful-restart restart-time [(1-4095)]",
2770 NO_STR
2771 "BGP specific commands\n"
2772 "Graceful restart capability parameters\n"
2773 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2774 "Delay value (seconds)\n")
eb6f1b41 2775{
d62a17ae 2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2777
d62a17ae 2778 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2779 return CMD_SUCCESS;
eb6f1b41
PG
2780}
2781
cfd47646 2782DEFUN (no_bgp_graceful_restart_select_defer_time,
2783 no_bgp_graceful_restart_select_defer_time_cmd,
2784 "no bgp graceful-restart select-defer-time [(0-3600)]",
2785 NO_STR
2786 "BGP specific commands\n"
2787 "Graceful restart capability parameters\n"
2788 "Set the time to defer the BGP route selection after restart\n"
2789 "Delay value (seconds)\n")
2790{
2791 VTY_DECLVAR_CONTEXT(bgp, bgp);
2792
2793 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2794 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2795
2796 return CMD_SUCCESS;
2797}
2798
43fc21b3 2799DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2800 bgp_graceful_restart_preserve_fw_cmd,
2801 "bgp graceful-restart preserve-fw-state",
2802 "BGP specific commands\n"
2803 "Graceful restart capability parameters\n"
2804 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2805{
d62a17ae 2806 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2807 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2808 return CMD_SUCCESS;
43fc21b3
JC
2809}
2810
2811DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2812 no_bgp_graceful_restart_preserve_fw_cmd,
2813 "no bgp graceful-restart preserve-fw-state",
2814 NO_STR
2815 "BGP specific commands\n"
2816 "Graceful restart capability parameters\n"
2817 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2818{
d62a17ae 2819 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2820 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2821 return CMD_SUCCESS;
43fc21b3
JC
2822}
2823
055679e9 2824DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2825 bgp_graceful_restart_disable_cmd,
2826 "bgp graceful-restart-disable",
2827 "BGP specific commands\n"
2828 GR_DISABLE)
055679e9 2829{
2830 int ret = BGP_GR_FAILURE;
2831
2832 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2833 zlog_debug(
2ba1fe69 2834 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2835
055679e9 2836 VTY_DECLVAR_CONTEXT(bgp, bgp);
2837
2838 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2839
dc95985f 2840 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2841 bgp->peer, ret);
5cce3f05 2842
055679e9 2843 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2844 zlog_debug(
2ba1fe69 2845 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2846 vty_out(vty,
2847 "Graceful restart configuration changed, reset all peers to take effect\n");
2848
055679e9 2849 return bgp_vty_return(vty, ret);
2850}
2851
2852DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2853 no_bgp_graceful_restart_disable_cmd,
2854 "no bgp graceful-restart-disable",
2855 NO_STR
2856 "BGP specific commands\n"
2857 NO_GR_DISABLE
055679e9 2858 )
2859{
2860 VTY_DECLVAR_CONTEXT(bgp, bgp);
2861
2862 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2863 zlog_debug(
2ba1fe69 2864 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2865
2866 int ret = BGP_GR_FAILURE;
2867
2868 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2869
36235319
QY
2870 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2871 ret);
5cce3f05 2872
055679e9 2873 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2874 zlog_debug(
2ba1fe69 2875 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2876 vty_out(vty,
2877 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2878
2879 return bgp_vty_return(vty, ret);
2880}
2881
2882DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2883 bgp_neighbor_graceful_restart_set_cmd,
2884 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2885 NEIGHBOR_STR
2886 NEIGHBOR_ADDR_STR2
2887 GR_NEIGHBOR_CMD
055679e9 2888 )
2889{
2890 int idx_peer = 1;
2891 struct peer *peer;
2892 int ret = BGP_GR_FAILURE;
2893
dc95985f 2894 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2895
055679e9 2896 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2897 zlog_debug(
2ba1fe69 2898 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2899
055679e9 2900 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2901 if (!peer)
2902 return CMD_WARNING_CONFIG_FAILED;
2903
2904 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2905
dc95985f 2906 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2907 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2908
2909 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2910 zlog_debug(
2ba1fe69 2911 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2912 vty_out(vty,
2913 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2914
2915 return bgp_vty_return(vty, ret);
2916}
2917
2918DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2919 no_bgp_neighbor_graceful_restart_set_cmd,
2920 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2921 NO_STR
2922 NEIGHBOR_STR
2923 NEIGHBOR_ADDR_STR2
2924 NO_GR_NEIGHBOR_CMD
055679e9 2925 )
2926{
2927 int idx_peer = 2;
2928 int ret = BGP_GR_FAILURE;
2929 struct peer *peer;
2930
dc95985f 2931 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2932
055679e9 2933 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2934 if (!peer)
2935 return CMD_WARNING_CONFIG_FAILED;
2936
2937 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2938 zlog_debug(
2ba1fe69 2939 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2940
2941 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2942
dc95985f 2943 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2944 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2945
2946 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2947 zlog_debug(
2ba1fe69 2948 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2949 vty_out(vty,
2950 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2951
2952 return bgp_vty_return(vty, ret);
2953}
2954
2955DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2956 bgp_neighbor_graceful_restart_helper_set_cmd,
2957 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2958 NEIGHBOR_STR
2959 NEIGHBOR_ADDR_STR2
2960 GR_NEIGHBOR_HELPER_CMD
055679e9 2961 )
2962{
2963 int idx_peer = 1;
2964 struct peer *peer;
2965 int ret = BGP_GR_FAILURE;
2966
dc95985f 2967 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2968
055679e9 2969 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2970 zlog_debug(
2ba1fe69 2971 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2972
055679e9 2973 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2974
055679e9 2975 if (!peer)
2976 return CMD_WARNING_CONFIG_FAILED;
2977
2978
2979 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2980
dc95985f 2981 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2982 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2983
055679e9 2984 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2985 zlog_debug(
2ba1fe69 2986 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2987 vty_out(vty,
2988 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2989
2990 return bgp_vty_return(vty, ret);
2991}
2992
2993DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2994 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2995 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2996 NO_STR
2997 NEIGHBOR_STR
2998 NEIGHBOR_ADDR_STR2
2999 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3000 )
3001{
3002 int idx_peer = 2;
3003 int ret = BGP_GR_FAILURE;
3004 struct peer *peer;
3005
dc95985f 3006 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3007
055679e9 3008 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3009 if (!peer)
3010 return CMD_WARNING_CONFIG_FAILED;
3011
3012 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3013 zlog_debug(
2ba1fe69 3014 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3015
36235319 3016 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3017
dc95985f 3018 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3019 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3020
3021 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3022 zlog_debug(
2ba1fe69 3023 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3024 vty_out(vty,
3025 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3026
3027 return bgp_vty_return(vty, ret);
3028}
3029
3030DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3031 bgp_neighbor_graceful_restart_disable_set_cmd,
3032 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3033 NEIGHBOR_STR
3034 NEIGHBOR_ADDR_STR2
3035 GR_NEIGHBOR_DISABLE_CMD
055679e9 3036 )
3037{
3038 int idx_peer = 1;
3039 struct peer *peer;
3040 int ret = BGP_GR_FAILURE;
3041
dc95985f 3042 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3043
055679e9 3044 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3045 zlog_debug(
2ba1fe69 3046 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3047
3048 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3049 if (!peer)
3050 return CMD_WARNING_CONFIG_FAILED;
3051
36235319 3052 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3053
3054 if (peer->bgp->t_startup)
3055 bgp_peer_gr_flags_update(peer);
3056
dc95985f 3057 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3058 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3059
055679e9 3060 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3061 zlog_debug(
2ba1fe69 3062 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3063 vty_out(vty,
3064 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3065
3066 return bgp_vty_return(vty, ret);
3067}
3068
3069DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3070 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3071 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3072 NO_STR
3073 NEIGHBOR_STR
3074 NEIGHBOR_ADDR_STR2
3075 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3076 )
3077{
3078 int idx_peer = 2;
3079 int ret = BGP_GR_FAILURE;
3080 struct peer *peer;
3081
dc95985f 3082 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3083
055679e9 3084 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3085 if (!peer)
3086 return CMD_WARNING_CONFIG_FAILED;
3087
3088 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3089 zlog_debug(
2ba1fe69 3090 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3091
3092 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3093
dc95985f 3094 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3095 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3096
3097 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3098 zlog_debug(
2ba1fe69 3099 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3100 vty_out(vty,
3101 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3102
3103 return bgp_vty_return(vty, ret);
3104}
3105
d6e3c15b 3106DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3107 bgp_graceful_restart_disable_eor_cmd,
3108 "bgp graceful-restart disable-eor",
3109 "BGP specific commands\n"
3110 "Graceful restart configuration parameters\n"
3111 "Disable EOR Check\n")
3112{
3113 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3114 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3115
d6e3c15b 3116 return CMD_SUCCESS;
3117}
3118
3119DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3120 no_bgp_graceful_restart_disable_eor_cmd,
3121 "no bgp graceful-restart disable-eor",
3122 NO_STR
3123 "BGP specific commands\n"
3124 "Graceful restart configuration parameters\n"
3125 "Disable EOR Check\n")
3126{
3127 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3128 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3129
3130 return CMD_SUCCESS;
3131}
3132
3133DEFUN (bgp_graceful_restart_rib_stale_time,
3134 bgp_graceful_restart_rib_stale_time_cmd,
3135 "bgp graceful-restart rib-stale-time (1-3600)",
3136 "BGP specific commands\n"
3137 "Graceful restart configuration parameters\n"
3138 "Specify the stale route removal timer in rib\n"
3139 "Delay value (seconds)\n")
3140{
3141 VTY_DECLVAR_CONTEXT(bgp, bgp);
3142 int idx_number = 3;
3143 uint32_t stale_time;
3144
3145 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3146 bgp->rib_stale_time = stale_time;
3147 /* Send the stale timer update message to RIB */
3148 if (bgp_zebra_stale_timer_update(bgp))
3149 return CMD_WARNING;
3150
3151 return CMD_SUCCESS;
3152}
3153
3154DEFUN (no_bgp_graceful_restart_rib_stale_time,
3155 no_bgp_graceful_restart_rib_stale_time_cmd,
3156 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3157 NO_STR
3158 "BGP specific commands\n"
3159 "Graceful restart configuration parameters\n"
3160 "Specify the stale route removal timer in rib\n"
3161 "Delay value (seconds)\n")
3162{
3163 VTY_DECLVAR_CONTEXT(bgp, bgp);
3164
3165 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3166 /* Send the stale timer update message to RIB */
3167 if (bgp_zebra_stale_timer_update(bgp))
3168 return CMD_WARNING;
3169
d6e3c15b 3170 return CMD_SUCCESS;
3171}
3172
ff8a8a7a
CS
3173static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3174 char *errmsg,
3175 size_t errmsg_len)
05bd726c 3176{
3177 bgp_static_redo_import_check(bgp);
3178 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
3179 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3180 return -1;
3181 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3182 return -1;
3183
3184 return 0;
05bd726c 3185}
3186
3187static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3188{
3189 struct listnode *node, *nnode;
3190 struct bgp *bgp;
3191 bool vrf_cfg = false;
ff8a8a7a 3192 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3193
3194 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3195 return CMD_SUCCESS;
3196
3197 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3198 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3199 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3200 vty_out(vty,
3201 "%% graceful-shutdown configuration found in vrf %s\n",
3202 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3203 VRF_DEFAULT_NAME : bgp->name);
3204 vrf_cfg = true;
3205 }
3206 }
3207
3208 if (vrf_cfg) {
3209 vty_out(vty,
3210 "%%Failed: global graceful-shutdown not permitted\n");
3211 return CMD_WARNING;
3212 }
3213
3214 /* Set flag globally */
3215 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3216
3217 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3218 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3219 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3220 sizeof(errmsg))
3221 < 0)
3222 if (strlen(errmsg))
3223 vty_out(vty, "%s\n", errmsg);
3224 }
05bd726c 3225
3226 return CMD_SUCCESS;
3227}
3228
3229static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3230{
3231 struct listnode *node, *nnode;
3232 struct bgp *bgp;
ff8a8a7a 3233 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3234
3235 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3236 return CMD_SUCCESS;
3237
3238 /* Unset flag globally */
3239 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3240
3241 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3242 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3243 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3244 sizeof(errmsg))
3245 < 0)
3246 if (strlen(errmsg))
3247 vty_out(vty, "%s\n", errmsg);
3248 }
05bd726c 3249
3250 return CMD_SUCCESS;
3251}
3252
7f323236
DW
3253/* "bgp graceful-shutdown" configuration */
3254DEFUN (bgp_graceful_shutdown,
3255 bgp_graceful_shutdown_cmd,
3256 "bgp graceful-shutdown",
3257 BGP_STR
3258 "Graceful shutdown parameters\n")
3259{
05bd726c 3260 if (vty->node == CONFIG_NODE)
3261 return bgp_global_graceful_shutdown_config_vty(vty);
3262
87ce2564
CS
3263 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3264 NB_OP_MODIFY, "true");
7f323236 3265
ff8a8a7a 3266 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3267}
3268
ff8a8a7a 3269DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3270 no_bgp_graceful_shutdown_cmd,
3271 "no bgp graceful-shutdown",
3272 NO_STR
3273 BGP_STR
3274 "Graceful shutdown parameters\n")
3275{
05bd726c 3276 if (vty->node == CONFIG_NODE)
3277 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3278
87ce2564
CS
3279 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3280 NB_OP_MODIFY, "false");
05bd726c 3281
ff8a8a7a
CS
3282 return nb_cli_apply_changes(vty, NULL);
3283}
7f323236 3284
ff8a8a7a
CS
3285void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3286 struct lyd_node *dnode,
3287 bool show_defaults)
3288{
3289 if (yang_dnode_get_bool(dnode, NULL))
3290 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3291}
3292
718e3744 3293/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3294DEFUN_YANG (bgp_fast_external_failover,
718e3744 3295 bgp_fast_external_failover_cmd,
3296 "bgp fast-external-failover",
3297 BGP_STR
3298 "Immediately reset session if a link to a directly connected external peer goes down\n")
3299{
87ce2564
CS
3300 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3301 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3302
3303 return nb_cli_apply_changes(vty, NULL);
718e3744 3304}
3305
ff8a8a7a 3306DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3307 no_bgp_fast_external_failover_cmd,
3308 "no bgp fast-external-failover",
3309 NO_STR
3310 BGP_STR
3311 "Immediately reset session if a link to a directly connected external peer goes down\n")
3312{
87ce2564
CS
3313 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3314 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3315
3316 return nb_cli_apply_changes(vty, NULL);
3317}
3318
3319void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3320 struct lyd_node *dnode,
3321 bool show_defaults)
3322{
3323 if (!yang_dnode_get_bool(dnode, NULL))
3324 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3325}
6b0655a2 3326
718e3744 3327/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3328DEFUN_YANG(bgp_bestpath_compare_router_id,
3329 bgp_bestpath_compare_router_id_cmd,
3330 "bgp bestpath compare-routerid",
3331 "BGP specific commands\n"
3332 "Change the default bestpath selection\n"
3333 "Compare router-id for identical EBGP paths\n")
718e3744 3334{
ff8a8a7a 3335 nb_cli_enqueue_change(
87ce2564
CS
3336 vty,
3337 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3338 NB_OP_MODIFY, "true");
7aafcaca 3339
ff8a8a7a 3340 return nb_cli_apply_changes(vty, NULL);
718e3744 3341}
3342
ff8a8a7a
CS
3343DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3344 no_bgp_bestpath_compare_router_id_cmd,
3345 "no bgp bestpath compare-routerid",
3346 NO_STR
3347 "BGP specific commands\n"
3348 "Change the default bestpath selection\n"
3349 "Compare router-id for identical EBGP paths\n")
718e3744 3350{
ff8a8a7a 3351 nb_cli_enqueue_change(
87ce2564
CS
3352 vty,
3353 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3354 NB_OP_MODIFY, "false");
7aafcaca 3355
ff8a8a7a 3356 return nb_cli_apply_changes(vty, NULL);
718e3744 3357}
6b0655a2 3358
718e3744 3359/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3360DEFUN_YANG(bgp_bestpath_aspath_ignore,
3361 bgp_bestpath_aspath_ignore_cmd,
3362 "bgp bestpath as-path ignore",
3363 "BGP specific commands\n"
3364 "Change the default bestpath selection\n"
3365 "AS-path attribute\n"
3366 "Ignore as-path length in selecting a route\n")
718e3744 3367{
87ce2564
CS
3368 nb_cli_enqueue_change(
3369 vty, "./global/route-selection-options/ignore-as-path-length",
3370 NB_OP_MODIFY, "true");
7aafcaca 3371
ff8a8a7a 3372 return nb_cli_apply_changes(vty, NULL);
718e3744 3373}
3374
ff8a8a7a
CS
3375DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3376 no_bgp_bestpath_aspath_ignore_cmd,
3377 "no bgp bestpath as-path ignore",
3378 NO_STR
3379 "BGP specific commands\n"
3380 "Change the default bestpath selection\n"
3381 "AS-path attribute\n"
3382 "Ignore as-path length in selecting a route\n")
718e3744 3383{
87ce2564
CS
3384 nb_cli_enqueue_change(
3385 vty, "./global/route-selection-options/ignore-as-path-length",
3386 NB_OP_MODIFY, "false");
7aafcaca 3387
ff8a8a7a 3388 return nb_cli_apply_changes(vty, NULL);
718e3744 3389}
6b0655a2 3390
6811845b 3391/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3392DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3393 bgp_bestpath_aspath_confed_cmd,
3394 "bgp bestpath as-path confed",
3395 "BGP specific commands\n"
3396 "Change the default bestpath selection\n"
3397 "AS-path attribute\n"
3398 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3399{
87ce2564
CS
3400 nb_cli_enqueue_change(vty,
3401 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3402 NB_OP_MODIFY, "true");
7aafcaca 3403
ff8a8a7a 3404 return nb_cli_apply_changes(vty, NULL);
6811845b 3405}
3406
ff8a8a7a 3407DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3408 no_bgp_bestpath_aspath_confed_cmd,
3409 "no bgp bestpath as-path confed",
3410 NO_STR
3411 "BGP specific commands\n"
3412 "Change the default bestpath selection\n"
3413 "AS-path attribute\n"
3414 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3415{
87ce2564
CS
3416 nb_cli_enqueue_change(vty,
3417 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3418 NB_OP_MODIFY, "false");
7aafcaca 3419
ff8a8a7a 3420 return nb_cli_apply_changes(vty, NULL);
6811845b 3421}
6b0655a2 3422
2fdd455c 3423/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3424DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3425 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3426 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3427 "BGP specific commands\n"
3428 "Change the default bestpath selection\n"
3429 "AS-path attribute\n"
3430 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3431 "Generate an AS_SET\n"
16fc1eec
DS
3432 "Do not generate an AS_SET\n")
3433{
d62a17ae 3434 int idx = 0;
219178b6 3435
87ce2564
CS
3436 nb_cli_enqueue_change(
3437 vty, "./global/route-selection-options/allow-multiple-as",
3438 NB_OP_MODIFY, "true");
d62a17ae 3439 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3440 nb_cli_enqueue_change(
87ce2564
CS
3441 vty,
3442 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3443 NB_OP_MODIFY, "true");
d62a17ae 3444 else
ff8a8a7a 3445 nb_cli_enqueue_change(
87ce2564
CS
3446 vty,
3447 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3448 NB_OP_MODIFY, "false");
7aafcaca 3449
ff8a8a7a 3450 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3451}
3452
ff8a8a7a 3453DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3454 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3455 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3456 NO_STR
3457 "BGP specific commands\n"
3458 "Change the default bestpath selection\n"
3459 "AS-path attribute\n"
3460 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3461 "Generate an AS_SET\n"
16fc1eec
DS
3462 "Do not generate an AS_SET\n")
3463{
87ce2564
CS
3464 nb_cli_enqueue_change(
3465 vty, "./global/route-selection-options/allow-multiple-as",
3466 NB_OP_MODIFY, "false");
3467 nb_cli_enqueue_change(
3468 vty, "./global/route-selection-options/multi-path-as-set",
3469 NB_OP_MODIFY, "false");
7aafcaca 3470
ff8a8a7a 3471 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3472}
6b0655a2 3473
848973c7 3474/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3475DEFUN_YANG(bgp_log_neighbor_changes,
3476 bgp_log_neighbor_changes_cmd,
3477 "bgp log-neighbor-changes",
3478 "BGP specific commands\n"
3479 "Log neighbor up/down and reset reason\n")
848973c7 3480{
87ce2564
CS
3481 nb_cli_enqueue_change(
3482 vty, "./global/global-neighbor-config/log-neighbor-changes",
3483 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3484
3485 return nb_cli_apply_changes(vty, NULL);
848973c7 3486}
3487
ff8a8a7a
CS
3488DEFUN_YANG(no_bgp_log_neighbor_changes,
3489 no_bgp_log_neighbor_changes_cmd,
3490 "no bgp log-neighbor-changes",
3491 NO_STR
3492 "BGP specific commands\n"
3493 "Log neighbor up/down and reset reason\n")
848973c7 3494{
87ce2564
CS
3495 nb_cli_enqueue_change(
3496 vty, "./global/global-neighbor-config/log-neighbor-changes",
3497 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3498
3499 return nb_cli_apply_changes(vty, NULL);
848973c7 3500}
6b0655a2 3501
718e3744 3502/* "bgp bestpath med" configuration. */
ff8a8a7a 3503DEFUN_YANG (bgp_bestpath_med,
718e3744 3504 bgp_bestpath_med_cmd,
2d8c1a4d 3505 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3506 "BGP specific commands\n"
3507 "Change the default bestpath selection\n"
3508 "MED attribute\n"
3509 "Compare MED among confederation paths\n"
838758ac
DW
3510 "Treat missing MED as the least preferred one\n"
3511 "Treat missing MED as the least preferred one\n"
3512 "Compare MED among confederation paths\n")
718e3744 3513{
d62a17ae 3514 int idx = 0;
ff8a8a7a
CS
3515 bool confed = false;
3516 bool worst_med = false;
3517
3518
d62a17ae 3519 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3520 confed = true;
3521
87ce2564
CS
3522 nb_cli_enqueue_change(vty,
3523 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3524 NB_OP_MODIFY, confed ? "true" : "false");
3525
d62a17ae 3526 idx = 0;
3527 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3528 worst_med = true;
e52702f2 3529
87ce2564
CS
3530 nb_cli_enqueue_change(
3531 vty, "./global/route-selection-options/missing-as-worst-med",
3532 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3533
ff8a8a7a 3534 return nb_cli_apply_changes(vty, NULL);
718e3744 3535}
3536
ff8a8a7a 3537DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3538 no_bgp_bestpath_med_cmd,
2d8c1a4d 3539 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3540 NO_STR
3541 "BGP specific commands\n"
3542 "Change the default bestpath selection\n"
3543 "MED attribute\n"
3544 "Compare MED among confederation paths\n"
3a2d747c
QY
3545 "Treat missing MED as the least preferred one\n"
3546 "Treat missing MED as the least preferred one\n"
3547 "Compare MED among confederation paths\n")
718e3744 3548{
d62a17ae 3549 int idx = 0;
ff8a8a7a 3550
d62a17ae 3551 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3552 nb_cli_enqueue_change(
3553 vty, "./global/route-selection-options/confed-med",
3554 NB_OP_MODIFY, "false");
ff8a8a7a 3555
d62a17ae 3556 idx = 0;
3557 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3558 nb_cli_enqueue_change(
87ce2564
CS
3559 vty,
3560 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3561 NB_OP_MODIFY, "false");
718e3744 3562
ff8a8a7a 3563 return nb_cli_apply_changes(vty, NULL);
718e3744 3564}
3565
f7e1c681 3566/* "bgp bestpath bandwidth" configuration. */
3567DEFPY (bgp_bestpath_bw,
3568 bgp_bestpath_bw_cmd,
ad36d216 3569 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3570 "BGP specific commands\n"
3571 "Change the default bestpath selection\n"
3572 "Link Bandwidth attribute\n"
3573 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3574 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3575 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3576{
3577 VTY_DECLVAR_CONTEXT(bgp, bgp);
3578 afi_t afi;
3579 safi_t safi;
3580
ad36d216
DS
3581 if (!bw_cfg) {
3582 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3583 return CMD_ERR_INCOMPLETE;
f7e1c681 3584 }
ad36d216
DS
3585 if (!strcmp(bw_cfg, "ignore"))
3586 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3587 else if (!strcmp(bw_cfg, "skip-missing"))
3588 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3589 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3590 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3591 else
3592 return CMD_ERR_NO_MATCH;
f7e1c681 3593
3594 /* This config is used in route install, so redo that. */
3595 FOREACH_AFI_SAFI (afi, safi) {
3596 if (!bgp_fibupd_safi(safi))
3597 continue;
3598 bgp_zebra_announce_table(bgp, afi, safi);
3599 }
3600
3601 return CMD_SUCCESS;
3602}
3603
ad36d216
DS
3604DEFPY (no_bgp_bestpath_bw,
3605 no_bgp_bestpath_bw_cmd,
3606 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3607 NO_STR
3608 "BGP specific commands\n"
3609 "Change the default bestpath selection\n"
3610 "Link Bandwidth attribute\n"
3611 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3612 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3613 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3614{
3615 VTY_DECLVAR_CONTEXT(bgp, bgp);
3616 afi_t afi;
3617 safi_t safi;
3618
3619 bgp->lb_handling = BGP_LINK_BW_ECMP;
3620
3621 /* This config is used in route install, so redo that. */
3622 FOREACH_AFI_SAFI (afi, safi) {
3623 if (!bgp_fibupd_safi(safi))
3624 continue;
3625 bgp_zebra_announce_table(bgp, afi, safi);
3626 }
3627 return CMD_SUCCESS;
3628}
3629
718e3744 3630/* "no bgp default ipv4-unicast". */
3631DEFUN (no_bgp_default_ipv4_unicast,
3632 no_bgp_default_ipv4_unicast_cmd,
3633 "no bgp default ipv4-unicast",
3634 NO_STR
3635 "BGP specific commands\n"
3636 "Configure BGP defaults\n"
3637 "Activate ipv4-unicast for a peer by default\n")
3638{
d62a17ae 3639 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3640 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3641 return CMD_SUCCESS;
718e3744 3642}
3643
3644DEFUN (bgp_default_ipv4_unicast,
3645 bgp_default_ipv4_unicast_cmd,
3646 "bgp default ipv4-unicast",
3647 "BGP specific commands\n"
3648 "Configure BGP defaults\n"
3649 "Activate ipv4-unicast for a peer by default\n")
3650{
d62a17ae 3651 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3652 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3653 return CMD_SUCCESS;
718e3744 3654}
6b0655a2 3655
04b6bdc0 3656/* Display hostname in certain command outputs */
ff8a8a7a 3657DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3658 bgp_default_show_hostname_cmd,
3659 "bgp default show-hostname",
3660 "BGP specific commands\n"
3661 "Configure BGP defaults\n"
0437e105 3662 "Show hostname in certain command outputs\n")
04b6bdc0 3663{
87ce2564
CS
3664 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3665 "true");
ff8a8a7a
CS
3666
3667 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3668}
3669
ff8a8a7a
CS
3670DEFUN_YANG(no_bgp_default_show_hostname,
3671 no_bgp_default_show_hostname_cmd,
3672 "no bgp default show-hostname",
3673 NO_STR
3674 "BGP specific commands\n"
3675 "Configure BGP defaults\n"
3676 "Show hostname in certain command outputs\n")
04b6bdc0 3677{
87ce2564
CS
3678 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3679 "false");
ff8a8a7a
CS
3680
3681 return nb_cli_apply_changes(vty, NULL);
3682}
3683
3684void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3685 bool show_defaults)
3686{
3687 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3688 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3689}
3690
aef999a2 3691/* Display hostname in certain command outputs */
232c75cd
CS
3692DEFUN_YANG(bgp_default_show_nexthop_hostname,
3693 bgp_default_show_nexthop_hostname_cmd,
3694 "bgp default show-nexthop-hostname",
3695 "BGP specific commands\n"
3696 "Configure BGP defaults\n"
3697 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3698{
87ce2564
CS
3699 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3700 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3701
3702 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3703}
3704
3705DEFUN (no_bgp_default_show_nexthop_hostname,
3706 no_bgp_default_show_nexthop_hostname_cmd,
3707 "no bgp default show-nexthop-hostname",
3708 NO_STR
3709 "BGP specific commands\n"
3710 "Configure BGP defaults\n"
3711 "Show hostname for nexthop in certain command outputs\n")
3712{
87ce2564
CS
3713 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3714 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3715
3716 return nb_cli_apply_changes(vty, NULL);
3717}
3718
3719void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3720 struct lyd_node *dnode,
3721 bool show_defaults)
3722{
3723 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3724 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3725}
3726
8233ef81 3727/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3728DEFUN_YANG(bgp_network_import_check,
3729 bgp_network_import_check_cmd,
3730 "bgp network import-check",
3731 "BGP specific commands\n"
3732 "BGP network command\n"
3733 "Check BGP network route exists in IGP\n")
718e3744 3734{
87ce2564
CS
3735 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3736 "true");
078430f6 3737
ff8a8a7a 3738 return nb_cli_apply_changes(vty, NULL);
718e3744 3739}
3740
d62a17ae 3741ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3742 "bgp network import-check exact",
3743 "BGP specific commands\n"
3744 "BGP network command\n"
3745 "Check BGP network route exists in IGP\n"
3746 "Match route precisely\n")
8233ef81 3747
ff8a8a7a
CS
3748DEFUN_YANG(no_bgp_network_import_check,
3749 no_bgp_network_import_check_cmd,
3750 "no bgp network import-check",
3751 NO_STR
3752 "BGP specific commands\n"
3753 "BGP network command\n"
3754 "Check BGP network route exists in IGP\n")
718e3744 3755{
87ce2564
CS
3756 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3757 "false");
5623e905 3758
ff8a8a7a 3759 return nb_cli_apply_changes(vty, NULL);
718e3744 3760}
6b0655a2 3761
ff8a8a7a
CS
3762void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3763 bool show_defaults)
718e3744 3764{
ff8a8a7a
CS
3765 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3766 vty_out(vty, " bgp network import-check\n");
3767}
718e3744 3768
ff8a8a7a
CS
3769DEFUN_YANG(bgp_default_local_preference,
3770 bgp_default_local_preference_cmd,
3771 "bgp default local-preference (0-4294967295)",
3772 "BGP specific commands\n"
3773 "Configure BGP defaults\n"
3774 "local preference (higher=more preferred)\n"
3775 "Configure default local preference value\n")
3776{
3777 int idx_number = 3;
718e3744 3778
87ce2564 3779 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3780 argv[idx_number]->arg);
718e3744 3781
ff8a8a7a 3782 return nb_cli_apply_changes(vty, NULL);
718e3744 3783}
3784
ff8a8a7a
CS
3785DEFUN_YANG(no_bgp_default_local_preference,
3786 no_bgp_default_local_preference_cmd,
3787 "no bgp default local-preference [(0-4294967295)]",
3788 NO_STR
3789 "BGP specific commands\n"
3790 "Configure BGP defaults\n"
3791 "local preference (higher=more preferred)\n"
3792 "Configure default local preference value\n")
718e3744 3793{
87ce2564 3794 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 3795
ff8a8a7a 3796 return nb_cli_apply_changes(vty, NULL);
718e3744 3797}
3798
ff8a8a7a
CS
3799void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3800 bool show_defaults)
3801{
3802 vty_out(vty, " bgp default local-preference %u\n",
3803 yang_dnode_get_uint32(dnode, NULL));
3804}
6b0655a2 3805
ff8a8a7a
CS
3806
3807DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3808 bgp_default_subgroup_pkt_queue_max_cmd,
3809 "bgp default subgroup-pkt-queue-max (20-100)",
3810 "BGP specific commands\n"
3811 "Configure BGP defaults\n"
3812 "subgroup-pkt-queue-max\n"
3813 "Configure subgroup packet queue max\n")
8bd9d948 3814{
d62a17ae 3815 int idx_number = 3;
3f9c7369 3816
ff8a8a7a 3817 nb_cli_enqueue_change(
87ce2564
CS
3818 vty,
3819 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 3820 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 3821
ff8a8a7a 3822 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
3823}
3824
ff8a8a7a
CS
3825DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3826 no_bgp_default_subgroup_pkt_queue_max_cmd,
3827 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3828 NO_STR
3829 "BGP specific commands\n"
3830 "Configure BGP defaults\n"
3831 "subgroup-pkt-queue-max\n"
3832 "Configure subgroup packet queue max\n")
3f9c7369 3833{
ff8a8a7a 3834 nb_cli_enqueue_change(
87ce2564
CS
3835 vty,
3836 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
3837 NB_OP_MODIFY, NULL);
3838
3839 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3840}
3841
ff8a8a7a
CS
3842void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3843 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3844{
3845 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3846 yang_dnode_get_uint32(dnode, NULL));
3847}
813d4307 3848
ff8a8a7a
CS
3849DEFUN_YANG(bgp_rr_allow_outbound_policy,
3850 bgp_rr_allow_outbound_policy_cmd,
3851 "bgp route-reflector allow-outbound-policy",
3852 "BGP specific commands\n"
3853 "Allow modifications made by out route-map\n"
3854 "on ibgp neighbors\n")
8bd9d948 3855{
87ce2564
CS
3856 nb_cli_enqueue_change(vty,
3857 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 3858 NB_OP_MODIFY, "true");
8bd9d948 3859
ff8a8a7a
CS
3860 return nb_cli_apply_changes(vty, NULL);
3861}
8bd9d948 3862
ff8a8a7a
CS
3863DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3864 no_bgp_rr_allow_outbound_policy_cmd,
3865 "no bgp route-reflector allow-outbound-policy",
3866 NO_STR
3867 "BGP specific commands\n"
3868 "Allow modifications made by out route-map\n"
3869 "on ibgp neighbors\n")
3870{
87ce2564
CS
3871 nb_cli_enqueue_change(vty,
3872 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
3873 NB_OP_MODIFY, "false");
3874
3875 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3876}
3877
ff8a8a7a
CS
3878
3879void cli_show_router_global_neighbor_config(struct vty *vty,
3880 struct lyd_node *dnode,
3881 bool show_defaults)
8bd9d948 3882{
ff8a8a7a
CS
3883 uint32_t write_quanta, read_quanta;
3884
3885 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3886 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 3887
ff8a8a7a
CS
3888 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3889 uint32_t listen_limit = yang_dnode_get_uint32(
3890 dnode, "./dynamic-neighbors-limit");
3891 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 3892 }
8bd9d948 3893
ff8a8a7a
CS
3894 write_quanta = yang_dnode_get_uint32(
3895 dnode, "./packet-quanta-config/wpkt-quanta");
3896 if (write_quanta != BGP_WRITE_PACKET_MAX)
3897 vty_out(vty, " write-quanta %d\n", write_quanta);
3898
3899 read_quanta = yang_dnode_get_uint32(
3900 dnode, "./packet-quanta-config/rpkt-quanta");
3901
3902 if (read_quanta != BGP_READ_PACKET_MAX)
3903 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
3904}
3905
ff8a8a7a
CS
3906DEFUN_YANG(bgp_listen_limit,
3907 bgp_listen_limit_cmd,
3908 "bgp listen limit (1-5000)",
3909 "BGP specific commands\n"
3910 "BGP Dynamic Neighbors listen commands\n"
3911 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3912 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3913{
d62a17ae 3914 int idx_number = 3;
f14e6fdb 3915
ff8a8a7a 3916 nb_cli_enqueue_change(
87ce2564 3917 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 3918 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 3919
ff8a8a7a 3920 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3921}
3922
ff8a8a7a
CS
3923DEFUN_YANG(no_bgp_listen_limit,
3924 no_bgp_listen_limit_cmd,
3925 "no bgp listen limit [(1-5000)]",
3926 NO_STR
3927 "BGP specific commands\n"
3928 "BGP Dynamic Neighbors listen commands\n"
3929 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3930 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3931{
ff8a8a7a 3932 nb_cli_enqueue_change(
87ce2564 3933 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
3934 NB_OP_DESTROY, NULL);
3935
3936 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3937}
3938
3939
20eb8864 3940/*
3941 * Check if this listen range is already configured. Check for exact
3942 * match or overlap based on input.
3943 */
d62a17ae 3944static struct peer_group *listen_range_exists(struct bgp *bgp,
3945 struct prefix *range, int exact)
3946{
3947 struct listnode *node, *nnode;
3948 struct listnode *node1, *nnode1;
3949 struct peer_group *group;
3950 struct prefix *lr;
3951 afi_t afi;
3952 int match;
3953
3954 afi = family2afi(range->family);
3955 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3956 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3957 lr)) {
3958 if (exact)
3959 match = prefix_same(range, lr);
3960 else
3961 match = (prefix_match(range, lr)
3962 || prefix_match(lr, range));
3963 if (match)
3964 return group;
3965 }
3966 }
3967
3968 return NULL;
20eb8864 3969}
3970
f14e6fdb
DS
3971DEFUN (bgp_listen_range,
3972 bgp_listen_range_cmd,
d7b9898c 3973 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3974 "BGP specific commands\n"
d7fa34c1
QY
3975 "Configure BGP dynamic neighbors listen range\n"
3976 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3977 NEIGHBOR_ADDR_STR
3978 "Member of the peer-group\n"
3979 "Peer-group name\n")
f14e6fdb 3980{
d62a17ae 3981 VTY_DECLVAR_CONTEXT(bgp, bgp);
3982 struct prefix range;
3983 struct peer_group *group, *existing_group;
3984 afi_t afi;
3985 int ret;
3986 int idx = 0;
3987
3988 argv_find(argv, argc, "A.B.C.D/M", &idx);
3989 argv_find(argv, argc, "X:X::X:X/M", &idx);
3990 char *prefix = argv[idx]->arg;
d7b9898c 3991 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3992 char *peergroup = argv[idx]->arg;
3993
3994 /* Convert IP prefix string to struct prefix. */
3995 ret = str2prefix(prefix, &range);
3996 if (!ret) {
3997 vty_out(vty, "%% Malformed listen range\n");
3998 return CMD_WARNING_CONFIG_FAILED;
3999 }
4000
4001 afi = family2afi(range.family);
4002
4003 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4004 vty_out(vty,
4005 "%% Malformed listen range (link-local address)\n");
4006 return CMD_WARNING_CONFIG_FAILED;
4007 }
4008
4009 apply_mask(&range);
4010
4011 /* Check if same listen range is already configured. */
4012 existing_group = listen_range_exists(bgp, &range, 1);
4013 if (existing_group) {
4014 if (strcmp(existing_group->name, peergroup) == 0)
4015 return CMD_SUCCESS;
4016 else {
4017 vty_out(vty,
4018 "%% Same listen range is attached to peer-group %s\n",
4019 existing_group->name);
4020 return CMD_WARNING_CONFIG_FAILED;
4021 }
4022 }
4023
4024 /* Check if an overlapping listen range exists. */
4025 if (listen_range_exists(bgp, &range, 0)) {
4026 vty_out(vty,
4027 "%% Listen range overlaps with existing listen range\n");
4028 return CMD_WARNING_CONFIG_FAILED;
4029 }
4030
4031 group = peer_group_lookup(bgp, peergroup);
4032 if (!group) {
4033 vty_out(vty, "%% Configure the peer-group first\n");
4034 return CMD_WARNING_CONFIG_FAILED;
4035 }
4036
4037 ret = peer_group_listen_range_add(group, &range);
4038 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4039}
4040
4041DEFUN (no_bgp_listen_range,
4042 no_bgp_listen_range_cmd,
d7b9898c 4043 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4044 NO_STR
f14e6fdb 4045 "BGP specific commands\n"
d7fa34c1
QY
4046 "Unconfigure BGP dynamic neighbors listen range\n"
4047 "Unconfigure BGP dynamic neighbors listen range\n"
4048 NEIGHBOR_ADDR_STR
4049 "Member of the peer-group\n"
4050 "Peer-group name\n")
f14e6fdb 4051{
d62a17ae 4052 VTY_DECLVAR_CONTEXT(bgp, bgp);
4053 struct prefix range;
4054 struct peer_group *group;
4055 afi_t afi;
4056 int ret;
4057 int idx = 0;
4058
4059 argv_find(argv, argc, "A.B.C.D/M", &idx);
4060 argv_find(argv, argc, "X:X::X:X/M", &idx);
4061 char *prefix = argv[idx]->arg;
21d88a71 4062 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4063 char *peergroup = argv[idx]->arg;
4064
4065 /* Convert IP prefix string to struct prefix. */
4066 ret = str2prefix(prefix, &range);
4067 if (!ret) {
4068 vty_out(vty, "%% Malformed listen range\n");
4069 return CMD_WARNING_CONFIG_FAILED;
4070 }
4071
4072 afi = family2afi(range.family);
4073
4074 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4075 vty_out(vty,
4076 "%% Malformed listen range (link-local address)\n");
4077 return CMD_WARNING_CONFIG_FAILED;
4078 }
4079
4080 apply_mask(&range);
4081
4082 group = peer_group_lookup(bgp, peergroup);
4083 if (!group) {
4084 vty_out(vty, "%% Peer-group does not exist\n");
4085 return CMD_WARNING_CONFIG_FAILED;
4086 }
4087
4088 ret = peer_group_listen_range_del(group, &range);
4089 return bgp_vty_return(vty, ret);
4090}
4091
2b791107 4092void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4093{
4094 struct peer_group *group;
4095 struct listnode *node, *nnode, *rnode, *nrnode;
4096 struct prefix *range;
4097 afi_t afi;
d62a17ae 4098
4099 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4100 vty_out(vty, " bgp listen limit %d\n",
4101 bgp->dynamic_neighbors_limit);
4102
4103 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4104 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4105 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4106 nrnode, range)) {
d62a17ae 4107 vty_out(vty,
2dbe669b
DA
4108 " bgp listen range %pFX peer-group %s\n",
4109 range, group->name);
d62a17ae 4110 }
4111 }
4112 }
f14e6fdb
DS
4113}
4114
4115
ff8a8a7a
CS
4116DEFUN_YANG(bgp_disable_connected_route_check,
4117 bgp_disable_connected_route_check_cmd,
4118 "bgp disable-ebgp-connected-route-check",
4119 "BGP specific commands\n"
4120 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4121{
87ce2564
CS
4122 nb_cli_enqueue_change(vty,
4123 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4124 NB_OP_MODIFY, "true");
7aafcaca 4125
ff8a8a7a 4126 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
4127}
4128
ff8a8a7a
CS
4129DEFUN_YANG(no_bgp_disable_connected_route_check,
4130 no_bgp_disable_connected_route_check_cmd,
4131 "no bgp disable-ebgp-connected-route-check",
4132 NO_STR
4133 "BGP specific commands\n"
4134 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4135{
87ce2564
CS
4136 nb_cli_enqueue_change(vty,
4137 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4138 NB_OP_MODIFY, "false");
d62a17ae 4139
ff8a8a7a 4140 return nb_cli_apply_changes(vty, NULL);
d62a17ae 4141}
4142
ff8a8a7a
CS
4143void cli_show_router_global_ebgp_multihop_connected_route_check(
4144 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4145{
4146 if (yang_dnode_get_bool(dnode, NULL))
4147 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4148}
d62a17ae 4149
ff8a8a7a
CS
4150DEFUN_YANG(bgp_default_shutdown,
4151 bgp_default_shutdown_cmd,
4152 "[no] bgp default shutdown",
4153 NO_STR BGP_STR
4154 "Configure BGP defaults\n"
4155 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4156{
87ce2564 4157 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4158 strmatch(argv[0]->text, "no") ? "false" : "true");
4159
4160 return nb_cli_apply_changes(vty, NULL);
4161}
4162
4163void cli_show_router_bgp_default_shutdown(struct vty *vty,
4164 struct lyd_node *dnode,
4165 bool show_defaults)
4166{
4167 if (yang_dnode_get_bool(dnode, NULL))
4168 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4169}
4170
736b68f3
DS
4171DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4172 BGP_STR
9ddf4b81 4173 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4174 "Add a shutdown message (RFC 8203)\n"
4175 "Shutdown message\n")
9cf59432 4176{
736b68f3 4177 char *msgstr = NULL;
8389c83a 4178
9cf59432
DS
4179 VTY_DECLVAR_CONTEXT(bgp, bgp);
4180
8389c83a 4181 if (argc > 3)
f80e35b6 4182 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4183
4184 bgp_shutdown_enable(bgp, msgstr);
4185 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4186
4187 return CMD_SUCCESS;
4188}
4189
736b68f3 4190DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4191 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4192{
4193 VTY_DECLVAR_CONTEXT(bgp, bgp);
4194
4195 bgp_shutdown_enable(bgp, NULL);
4196
4197 return CMD_SUCCESS;
4198}
8389c83a 4199
736b68f3 4200DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4201 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4202{
4203 VTY_DECLVAR_CONTEXT(bgp, bgp);
4204
4205 bgp_shutdown_disable(bgp);
4206
4207 return CMD_SUCCESS;
4208}
4209
9ddf4b81 4210ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4211 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4212 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4213 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4214
f4b8ec07
CS
4215DEFUN_YANG(neighbor_remote_as,
4216 neighbor_remote_as_cmd,
4217 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4218 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4219 "Specify a BGP neighbor\n" AS_STR
4220 "Internal BGP peer\n"
4221 "External BGP peer\n")
718e3744 4222{
d62a17ae 4223 int idx_peer = 1;
4224 int idx_remote_as = 3;
f4b8ec07
CS
4225 char base_xpath[XPATH_MAXLEN];
4226 char unnbr_xpath[XPATH_MAXLEN];
4227 char prgrp_xpath[XPATH_MAXLEN];
4228 union sockunion su;
4229 const char *as_type_str = "as-specified";
4230
4231 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4232 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4233 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4234
4235 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4236 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4237
4238 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4239 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4240 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4241 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4242 "%s%s", VTY_CURR_XPATH,
4243 prgrp_xpath + 1)) {
4244 snprintf(base_xpath, sizeof(base_xpath),
4245 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4246 "");
4247 } else {
4248 vty_out(vty,
4249 "%% Create the peer-group or interface first\n");
4250 return CMD_WARNING_CONFIG_FAILED;
4251 }
4252 } else {
4253 snprintf(base_xpath, sizeof(base_xpath),
4254 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4255 }
4256
4257 if (argv[idx_remote_as]->arg[0] == 'i') {
4258 as_type_str = "internal";
4259 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4260 as_type_str = "external";
4261 } else {
4262 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4263 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4264 }
4265 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4266 NB_OP_MODIFY, as_type_str);
4267
4268 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4269}
4270
f4b8ec07
CS
4271int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4272 safi_t safi, bool v6only,
4273 const char *peer_group_name, int as_type,
4274 as_t as, char *errmsg, size_t errmsg_len)
d62a17ae 4275{
d62a17ae 4276 struct peer *peer;
4277 struct peer_group *group;
4278 int ret = 0;
d62a17ae 4279
4280 group = peer_group_lookup(bgp, conf_if);
4281
4282 if (group) {
f4b8ec07
CS
4283 snprintf(errmsg, errmsg_len,
4284 "Name conflict with peer-group \n");
4285 return -1;
d62a17ae 4286 }
4287
4288 peer = peer_lookup_by_conf_if(bgp, conf_if);
4289 if (peer) {
f4b8ec07 4290 if (as_type != AS_UNSPECIFIED)
cc4d4ce8 4291 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 4292 afi, safi);
4293 } else {
892fedb6 4294 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 4295 && afi == AFI_IP && safi == SAFI_UNICAST)
4296 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4297 as_type, 0, 0, NULL);
4298 else
4299 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4300 as_type, afi, safi, NULL);
4301
4302 if (!peer) {
f4b8ec07
CS
4303 snprintf(errmsg, errmsg_len,
4304 "BGP failed to create peer\n");
4305 return -1;
d62a17ae 4306 }
4307
4308 if (v6only)
527de3dc 4309 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4310
4311 /* Request zebra to initiate IPv6 RAs on this interface. We do
4312 * this
4313 * any unnumbered peer in order to not worry about run-time
4314 * transitions
4315 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4316 * address
4317 * gets deleted later etc.)
4318 */
4319 if (peer->ifp)
4320 bgp_zebra_initiate_radv(bgp, peer);
4321 }
4322
4323 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4324 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4325 if (v6only)
527de3dc 4326 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4327 else
527de3dc 4328 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4329
4330 /* v6only flag changed. Reset bgp seesion */
4331 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4332 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4333 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4334 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4335 } else
4336 bgp_session_reset(peer);
4337 }
4338
9fb964de
PM
4339 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4340 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4341 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4342 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4343 }
d62a17ae 4344
4345 if (peer_group_name) {
4346 group = peer_group_lookup(bgp, peer_group_name);
4347 if (!group) {
f4b8ec07
CS
4348 snprintf(errmsg, errmsg_len,
4349 "Configure the peer-group first\n");
4350 return -1;
d62a17ae 4351 }
4352
8395c1f8 4353 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4354 }
4355
f4b8ec07 4356 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
a80beece
DS
4357}
4358
232c75cd
CS
4359DEFUN_YANG(neighbor_interface_config,
4360 neighbor_interface_config_cmd,
f4b8ec07
CS
4361 "neighbor WORD interface [peer-group PGNAME]",
4362 NEIGHBOR_STR
4363 "Interface name or neighbor tag\n"
4364 "Enable BGP on interface\n"
4365 "Member of the peer-group\n"
4366 "Peer-group name\n")
4c48cf63 4367{
d62a17ae 4368 int idx_word = 1;
4369 int idx_peer_group_word = 4;
f4b8ec07
CS
4370 char base_xpath[XPATH_MAXLEN];
4371
4372 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4373 argv[idx_word]->arg, "");
31500417 4374
f4b8ec07 4375 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4376 if (argc > idx_peer_group_word)
f4b8ec07
CS
4377 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4378 argv[idx_peer_group_word]->arg);
4379
4380 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4381}
4382
f4b8ec07
CS
4383DEFUN_YANG(neighbor_interface_config_v6only,
4384 neighbor_interface_config_v6only_cmd,
4385 "neighbor WORD interface v6only [peer-group PGNAME]",
4386 NEIGHBOR_STR
4387 "Interface name or neighbor tag\n"
4388 "Enable BGP on interface\n"
4389 "Enable BGP with v6 link-local only\n"
4390 "Member of the peer-group\n"
4391 "Peer-group name\n")
4c48cf63 4392{
d62a17ae 4393 int idx_word = 1;
4394 int idx_peer_group_word = 5;
f4b8ec07
CS
4395 char base_xpath[XPATH_MAXLEN];
4396
4397 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4398 argv[idx_word]->arg, "");
31500417 4399
f4b8ec07 4400 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4401 if (argc > idx_peer_group_word)
f4b8ec07
CS
4402 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4403 argv[idx_peer_group_word]->arg);
31500417 4404
f4b8ec07
CS
4405 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4406
4407 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4408}
4409
a80beece 4410
f4b8ec07
CS
4411DEFUN_YANG(
4412 neighbor_interface_config_remote_as,
4413 neighbor_interface_config_remote_as_cmd,
4414 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4415 NEIGHBOR_STR
4416 "Interface name or neighbor tag\n"
4417 "Enable BGP on interface\n"
4418 "Specify a BGP neighbor\n" AS_STR
4419 "Internal BGP peer\n"
4420 "External BGP peer\n")
b3a39dc5 4421{
d62a17ae 4422 int idx_word = 1;
4423 int idx_remote_as = 4;
f4b8ec07
CS
4424 char base_xpath[XPATH_MAXLEN];
4425 const char *as_type_str = "as-specified";
4426
4427 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4428 argv[idx_word]->arg, "");
4429
4430 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4431
4432 if (argv[idx_remote_as]->arg[0] == 'i') {
4433 as_type_str = "internal";
4434 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4435 as_type_str = "external";
4436 } else {
4437 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4438 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4439 }
4440 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4441 NB_OP_MODIFY, as_type_str);
4442
4443 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4444}
4445
f4b8ec07
CS
4446DEFUN_YANG(
4447 neighbor_interface_v6only_config_remote_as,
4448 neighbor_interface_v6only_config_remote_as_cmd,
4449 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4450 NEIGHBOR_STR
4451 "Interface name or neighbor tag\n"
4452 "Enable BGP with v6 link-local only\n"
4453 "Enable BGP on interface\n"
4454 "Specify a BGP neighbor\n" AS_STR
4455 "Internal BGP peer\n"
4456 "External BGP peer\n")
b3a39dc5 4457{
d62a17ae 4458 int idx_word = 1;
4459 int idx_remote_as = 5;
f4b8ec07
CS
4460 char base_xpath[XPATH_MAXLEN];
4461 const char *as_type_str = "as-specified";
4462
4463 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4464 argv[idx_word]->arg, "");
4465
4466 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4467
4468 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4469
4470 if (argv[idx_remote_as]->arg[0] == 'i') {
4471 as_type_str = "internal";
4472 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4473 as_type_str = "external";
4474 } else {
4475 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4476 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4477 }
4478 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4479 NB_OP_MODIFY, as_type_str);
4480
4481 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4482}
4483
f4b8ec07
CS
4484DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4485 "neighbor WORD peer-group",
4486 NEIGHBOR_STR
4487 "Interface name or neighbor tag\n"
4488 "Configure peer-group\n")
718e3744 4489{
f4b8ec07 4490 char base_xpath[XPATH_MAXLEN];
d62a17ae 4491 int idx_word = 1;
718e3744 4492
f4b8ec07
CS
4493 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4494 argv[idx_word]->arg, "");
718e3744 4495
f4b8ec07 4496 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 4497
f4b8ec07 4498 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4499}
4500
232c75cd
CS
4501DEFUN_YANG(no_neighbor,
4502 no_neighbor_cmd,
4503 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4504 NO_STR NEIGHBOR_STR
4505 NEIGHBOR_ADDR_STR2
4506 "Specify a BGP neighbor\n" AS_STR
4507 "Internal BGP peer\n"
4508 "External BGP peer\n")
718e3744 4509{
d62a17ae 4510 int idx_peer = 2;
f4b8ec07
CS
4511 char base_xpath[XPATH_MAXLEN];
4512 char num_xpath[XPATH_MAXLEN];
4513 char unnbr_xpath[XPATH_MAXLEN];
4514 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4515 union sockunion su;
d62a17ae 4516
f4b8ec07
CS
4517 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4518 snprintf(num_xpath, sizeof(num_xpath),
4519 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4520 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4521 VTY_CURR_XPATH, num_xpath + 1)) {
4522 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
d62a17ae 4523 }
f4b8ec07
CS
4524 } else {
4525 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4526 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4527
4528 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4529 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4530
4531 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4532 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4533 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4534 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4535 "%s%s", VTY_CURR_XPATH,
4536 prgrp_xpath + 1)) {
4537 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4e2786df 4538 } else {
f4b8ec07
CS
4539 vty_out(vty,
4540 "%% Create the peer-group or interface first\n");
d62a17ae 4541 return CMD_WARNING_CONFIG_FAILED;
4542 }
1ff9a340 4543 }
718e3744 4544
f4b8ec07
CS
4545 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4546
4547 return nb_cli_apply_changes(vty, NULL);
718e3744 4548}
4549
f4b8ec07
CS
4550DEFUN_YANG(no_neighbor_interface_config,
4551 no_neighbor_interface_config_cmd,
4552 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4553 NO_STR NEIGHBOR_STR
4554 "Interface name\n"
4555 "Configure BGP on interface\n"
4556 "Enable BGP with v6 link-local only\n"
4557 "Member of the peer-group\n"
4558 "Peer-group name\n"
4559 "Specify a BGP neighbor\n" AS_STR
4560 "Internal BGP peer\n"
4561 "External BGP peer\n")
a80beece 4562{
d62a17ae 4563 int idx_word = 2;
f4b8ec07 4564 char base_xpath[XPATH_MAXLEN];
d62a17ae 4565
f4b8ec07
CS
4566 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4567 argv[idx_word]->arg, "");
4568
4569 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4570
4571 return nb_cli_apply_changes(vty, base_xpath);
a80beece
DS
4572}
4573
f4b8ec07
CS
4574DEFUN_YANG(no_neighbor_peer_group,
4575 no_neighbor_peer_group_cmd,
4576 "no neighbor WORD peer-group",
4577 NO_STR NEIGHBOR_STR
4578 "Neighbor tag\n"
4579 "Configure peer-group\n")
718e3744 4580{
f4b8ec07 4581 char base_xpath[XPATH_MAXLEN];
d62a17ae 4582 int idx_word = 2;
718e3744 4583
f4b8ec07
CS
4584 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4585 argv[idx_word]->arg, "");
4586
4587 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4588
4589 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4590}
4591
f4b8ec07
CS
4592DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4593 no_neighbor_interface_peer_group_remote_as_cmd,
4594 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4595 NO_STR NEIGHBOR_STR
4596 "Interface name or neighbor tag\n"
4597 "Specify a BGP neighbor\n" AS_STR
4598 "Internal BGP peer\n"
4599 "External BGP peer\n")
718e3744 4600{
f4b8ec07
CS
4601 int idx_peer = 2;
4602 char base_xpath[XPATH_MAXLEN];
4603 char unnbr_xpath[XPATH_MAXLEN];
4604 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4605
f4b8ec07
CS
4606 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4607 argv[idx_peer]->arg, "");
d62a17ae 4608
f4b8ec07
CS
4609 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4610 argv[idx_peer]->arg, "");
4611
4612 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4613 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4614 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4615 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4616 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4617 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4618 } else {
d62a17ae 4619 vty_out(vty, "%% Create the peer-group or interface first\n");
4620 return CMD_WARNING_CONFIG_FAILED;
4621 }
f4b8ec07
CS
4622
4623 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4624 sizeof(base_xpath));
4625
4626 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4627
4628 return nb_cli_apply_changes(vty, NULL);
718e3744 4629}
6b0655a2 4630
f4b8ec07
CS
4631DEFUN_YANG(neighbor_local_as,
4632 neighbor_local_as_cmd,
4633 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4634 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4635 "Specify a local-as number\n"
4636 "AS number used as local AS\n")
718e3744 4637{
d62a17ae 4638 int idx_peer = 1;
4639 int idx_number = 3;
f4b8ec07 4640 char base_xpath[XPATH_MAXLEN];
718e3744 4641
f4b8ec07
CS
4642 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4643 sizeof(base_xpath), NULL)
4644 < 0)
d62a17ae 4645 return CMD_WARNING_CONFIG_FAILED;
718e3744 4646
f4b8ec07
CS
4647 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4648 argv[idx_number]->arg);
4649
4650 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4651}
4652
f4b8ec07
CS
4653DEFUN_YANG(
4654 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4655 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4656 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4657 "Specify a local-as number\n"
4658 "AS number used as local AS\n"
4659 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4660{
d62a17ae 4661 int idx_peer = 1;
4662 int idx_number = 3;
f4b8ec07 4663 char base_xpath[XPATH_MAXLEN];
718e3744 4664
f4b8ec07
CS
4665 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4666 sizeof(base_xpath), NULL)
4667 < 0)
d62a17ae 4668 return CMD_WARNING_CONFIG_FAILED;
718e3744 4669
f4b8ec07
CS
4670 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4671 argv[idx_number]->arg);
4672 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4673 "true");
4674
4675 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4676}
4677
f4b8ec07
CS
4678DEFUN_YANG(
4679 neighbor_local_as_no_prepend_replace_as,
4680 neighbor_local_as_no_prepend_replace_as_cmd,
4681 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4682 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4683 "Specify a local-as number\n"
4684 "AS number used as local AS\n"
4685 "Do not prepend local-as to updates from ebgp peers\n"
4686 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4687{
d62a17ae 4688 int idx_peer = 1;
4689 int idx_number = 3;
f4b8ec07 4690 char base_xpath[XPATH_MAXLEN];
9d3f9705 4691
f4b8ec07
CS
4692 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4693 sizeof(base_xpath), NULL)
4694 < 0)
d62a17ae 4695 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4696
f4b8ec07
CS
4697 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4698 argv[idx_number]->arg);
4699 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4700 "true");
4701 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4702 "true");
4703
4704 return nb_cli_apply_changes(vty, base_xpath);
9d3f9705
AC
4705}
4706
f4b8ec07
CS
4707DEFUN_YANG(no_neighbor_local_as,
4708 no_neighbor_local_as_cmd,
4709 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4710 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4711 "Specify a local-as number\n"
4712 "AS number used as local AS\n"
4713 "Do not prepend local-as to updates from ebgp peers\n"
4714 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4715{
d62a17ae 4716 int idx_peer = 2;
f4b8ec07 4717 char base_xpath[XPATH_MAXLEN];
718e3744 4718
f4b8ec07
CS
4719 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4720 sizeof(base_xpath), NULL)
4721 < 0)
d62a17ae 4722 return CMD_WARNING_CONFIG_FAILED;
718e3744 4723
f4b8ec07
CS
4724 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4725 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4726 "false");
4727 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4728 "false");
4729
4730 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4731}
4732
718e3744 4733
3f9c7369
DS
4734DEFUN (neighbor_solo,
4735 neighbor_solo_cmd,
9ccf14f7 4736 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4737 NEIGHBOR_STR
4738 NEIGHBOR_ADDR_STR2
4739 "Solo peer - part of its own update group\n")
4740{
d62a17ae 4741 int idx_peer = 1;
4742 struct peer *peer;
4743 int ret;
3f9c7369 4744
d62a17ae 4745 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4746 if (!peer)
4747 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4748
d62a17ae 4749 ret = update_group_adjust_soloness(peer, 1);
4750 return bgp_vty_return(vty, ret);
3f9c7369
DS
4751}
4752
4753DEFUN (no_neighbor_solo,
4754 no_neighbor_solo_cmd,
9ccf14f7 4755 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4756 NO_STR
4757 NEIGHBOR_STR
4758 NEIGHBOR_ADDR_STR2
4759 "Solo peer - part of its own update group\n")
4760{
d62a17ae 4761 int idx_peer = 2;
4762 struct peer *peer;
4763 int ret;
3f9c7369 4764
d62a17ae 4765 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4766 if (!peer)
4767 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4768
d62a17ae 4769 ret = update_group_adjust_soloness(peer, 0);
4770 return bgp_vty_return(vty, ret);
3f9c7369
DS
4771}
4772
f4b8ec07
CS
4773DEFUN_YANG(neighbor_password,
4774 neighbor_password_cmd,
4775 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4776 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4777 "Set a password\n"
4778 "The password\n")
0df7c91f 4779{
d62a17ae 4780 int idx_peer = 1;
4781 int idx_line = 3;
f4b8ec07 4782 char base_xpath[XPATH_MAXLEN];
0df7c91f 4783
f4b8ec07
CS
4784 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4785 sizeof(base_xpath), NULL)
4786 < 0)
d62a17ae 4787 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4788
f4b8ec07
CS
4789 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4790 argv[idx_line]->arg);
4791
4792 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f
PJ
4793}
4794
f4b8ec07
CS
4795DEFUN_YANG(no_neighbor_password,
4796 no_neighbor_password_cmd,
4797 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4798 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4799 "Set a password\n"
4800 "The password\n")
0df7c91f 4801{
d62a17ae 4802 int idx_peer = 2;
f4b8ec07 4803 char base_xpath[XPATH_MAXLEN];
0df7c91f 4804
f4b8ec07
CS
4805 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4806 sizeof(base_xpath), NULL)
4807 < 0)
d62a17ae 4808 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4809
f4b8ec07
CS
4810 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4811
4812 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f 4813}
6b0655a2 4814
f4b8ec07
CS
4815DEFUN_YANG(neighbor_activate,
4816 neighbor_activate_cmd,
4817 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4818 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4819 "Enable the Address Family for this Neighbor\n")
718e3744 4820{
d62a17ae 4821 int idx_peer = 1;
f4b8ec07 4822 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
4823 char af_xpath[XPATH_MAXLEN];
4824 afi_t afi = bgp_node_afi(vty);
4825 safi_t safi = bgp_node_safi(vty);
718e3744 4826
f4b8ec07
CS
4827 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4828 yang_afi_safi_value2identity(afi, safi));
555c8ab7
CS
4829 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4830 sizeof(base_xpath), af_xpath)
f4b8ec07 4831 < 0)
d62a17ae 4832 return CMD_WARNING_CONFIG_FAILED;
718e3744 4833
555c8ab7 4834 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
f4b8ec07
CS
4835
4836 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4837}
4838
d62a17ae 4839ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4840 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4841 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4842 "Enable the Address Family for this Neighbor\n")
596c17ba 4843
f4b8ec07
CS
4844DEFUN_YANG(no_neighbor_activate,
4845 no_neighbor_activate_cmd,
4846 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4847 NO_STR NEIGHBOR_STR
4848 NEIGHBOR_ADDR_STR2
4849 "Enable the Address Family for this Neighbor\n")
718e3744 4850{
d62a17ae 4851 int idx_peer = 2;
f4b8ec07
CS
4852 char base_xpath[XPATH_MAXLEN];
4853 char af_xpath[XPATH_MAXLEN];
4854 afi_t afi = bgp_node_afi(vty);
4855 safi_t safi = bgp_node_safi(vty);
718e3744 4856
f4b8ec07
CS
4857 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4858 yang_afi_safi_value2identity(afi, safi));
4859
4860 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4861 sizeof(base_xpath), af_xpath)
4862 < 0)
d62a17ae 4863 return CMD_WARNING_CONFIG_FAILED;
718e3744 4864
f4b8ec07
CS
4865 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4866
4867 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4868}
6b0655a2 4869
d62a17ae 4870ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4871 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4872 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4873 "Enable the Address Family for this Neighbor\n")
596c17ba 4874
f4b8ec07
CS
4875DEFUN_YANG (neighbor_set_peer_group,
4876 neighbor_set_peer_group_cmd,
4877 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4878 NEIGHBOR_STR
4879 NEIGHBOR_ADDR_STR2
4880 "Member of the peer-group\n"
4881 "Peer-group name\n")
718e3744 4882{
d62a17ae 4883 int idx_peer = 1;
4884 int idx_word = 3;
f4b8ec07 4885 char base_xpath[XPATH_MAXLEN];
d62a17ae 4886
f4b8ec07
CS
4887 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4888 sizeof(base_xpath), NULL)
4889 < 0)
d62a17ae 4890 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4891
f4b8ec07
CS
4892 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4893 argv[idx_word]->arg);
d62a17ae 4894
f4b8ec07 4895 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4896}
4897
4898ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4899 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4900 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4901 "Member of the peer-group\n"
4902 "Peer-group name\n")
596c17ba 4903
f4b8ec07
CS
4904DEFUN_YANG (no_neighbor_set_peer_group,
4905 no_neighbor_set_peer_group_cmd,
4906 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4907 NO_STR
4908 NEIGHBOR_STR
4909 NEIGHBOR_ADDR_STR2
4910 "Member of the peer-group\n"
4911 "Peer-group name\n")
718e3744 4912{
d62a17ae 4913 int idx_peer = 2;
f4b8ec07 4914 char base_xpath[XPATH_MAXLEN];
d62a17ae 4915
f4b8ec07
CS
4916 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4917 sizeof(base_xpath), NULL)
4918 < 0)
d62a17ae 4919 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 4920
f4b8ec07 4921 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
718e3744 4922
f4b8ec07 4923 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4924}
6b0655a2 4925
d62a17ae 4926ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4927 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4928 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4929 "Member of the peer-group\n"
4930 "Peer-group name\n")
596c17ba 4931
d62a17ae 4932static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4933 uint32_t flag, int set)
718e3744 4934{
d62a17ae 4935 int ret;
4936 struct peer *peer;
718e3744 4937
d62a17ae 4938 peer = peer_and_group_lookup_vty(vty, ip_str);
4939 if (!peer)
4940 return CMD_WARNING_CONFIG_FAILED;
718e3744 4941
7ebe625c
QY
4942 /*
4943 * If 'neighbor <interface>', then this is for directly connected peers,
4944 * we should not accept disable-connected-check.
4945 */
4946 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4947 vty_out(vty,
3efd0893 4948 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
4949 ip_str);
4950 return CMD_WARNING_CONFIG_FAILED;
4951 }
4952
d62a17ae 4953 if (!set && flag == PEER_FLAG_SHUTDOWN)
4954 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4955
d62a17ae 4956 if (set)
4957 ret = peer_flag_set(peer, flag);
4958 else
4959 ret = peer_flag_unset(peer, flag);
718e3744 4960
d62a17ae 4961 return bgp_vty_return(vty, ret);
718e3744 4962}
4963
47cbc09b 4964static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4965{
d62a17ae 4966 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4967}
4968
d62a17ae 4969static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4970 uint32_t flag)
718e3744 4971{
d62a17ae 4972 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4973}
4974
f4b8ec07
CS
4975int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
4976 uint32_t flag, bool set, char *errmsg,
4977 size_t errmsg_len)
4978{
4979 int ret;
4980
4981 /*
4982 * If 'neighbor <interface>', then this is for directly connected peers,
4983 * we should not accept disable-connected-check.
4984 */
4985 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4986 snprintf(
4987 errmsg, errmsg_len,
4988 "%s is directly connected peer, cannot accept disable-connected-check\n",
4989 ip_str);
4990 return -1;
4991 }
4992
4993 if (!set && flag == PEER_FLAG_SHUTDOWN)
4994 peer_tx_shutdown_message_unset(peer);
4995
4996 if (set)
4997 ret = peer_flag_set(peer, flag);
4998 else
4999 ret = peer_flag_unset(peer, flag);
5000
5001 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5002}
5003
718e3744 5004/* neighbor passive. */
f4b8ec07
CS
5005DEFUN_YANG(neighbor_passive,
5006 neighbor_passive_cmd,
5007 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5008 NEIGHBOR_STR
5009 NEIGHBOR_ADDR_STR2
5010 "Don't send open messages to this neighbor\n")
718e3744 5011{
d62a17ae 5012 int idx_peer = 1;
f4b8ec07
CS
5013 char base_xpath[XPATH_MAXLEN];
5014
5015 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5016 sizeof(base_xpath), NULL)
5017 < 0)
5018 return CMD_WARNING_CONFIG_FAILED;
5019
5020 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5021
5022 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5023}
5024
f4b8ec07
CS
5025DEFUN_YANG(no_neighbor_passive,
5026 no_neighbor_passive_cmd,
5027 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5028 NO_STR NEIGHBOR_STR
5029 NEIGHBOR_ADDR_STR2
5030 "Don't send open messages to this neighbor\n")
718e3744 5031{
d62a17ae 5032 int idx_peer = 2;
f4b8ec07
CS
5033 char base_xpath[XPATH_MAXLEN];
5034
5035 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5036 sizeof(base_xpath), NULL)
5037 < 0)
5038 return CMD_WARNING_CONFIG_FAILED;
5039
5040 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5041
5042 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5043}
6b0655a2 5044
718e3744 5045/* neighbor shutdown. */
f4b8ec07
CS
5046DEFUN_YANG(neighbor_shutdown_msg,
5047 neighbor_shutdown_msg_cmd,
5048 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5049 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5050 "Administratively shut down this neighbor\n"
5051 "Add a shutdown message (RFC 8203)\n"
5052 "Shutdown message\n")
718e3744 5053{
d62a17ae 5054 int idx_peer = 1;
f4b8ec07
CS
5055 char base_xpath[XPATH_MAXLEN];
5056
5057 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5058 sizeof(base_xpath), NULL)
5059 < 0)
5060 return CMD_WARNING_CONFIG_FAILED;
73d70fa6 5061
d62a17ae 5062 if (argc >= 5) {
d62a17ae 5063 char *message;
73d70fa6 5064
d62a17ae 5065 message = argv_concat(argv, argc, 4);
f4b8ec07
CS
5066 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5067 NB_OP_MODIFY, message);
d62a17ae 5068 }
73d70fa6 5069
f4b8ec07
CS
5070 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5071 "true");
5072
5073 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5074}
5075
232c75cd 5076ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5077 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5078 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5079 "Administratively shut down this neighbor\n")
73d70fa6 5080
f4b8ec07
CS
5081DEFUN_YANG(no_neighbor_shutdown_msg,
5082 no_neighbor_shutdown_msg_cmd,
5083 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5084 NO_STR NEIGHBOR_STR
5085 NEIGHBOR_ADDR_STR2
5086 "Administratively shut down this neighbor\n"
5087 "Remove a shutdown message (RFC 8203)\n"
5088 "Shutdown message\n")
718e3744 5089{
d62a17ae 5090 int idx_peer = 2;
f4b8ec07 5091 char base_xpath[XPATH_MAXLEN];
73d70fa6 5092
f4b8ec07
CS
5093 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5094 sizeof(base_xpath), NULL)
5095 < 0)
5096 return CMD_WARNING_CONFIG_FAILED;
5097
5098 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5099 "false");
5100
5101 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5102}
6b0655a2 5103
232c75cd 5104ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5105 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5107 "Administratively shut down this neighbor\n")
73d70fa6 5108
8336c896
DA
5109DEFUN(neighbor_shutdown_rtt,
5110 neighbor_shutdown_rtt_cmd,
5111 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5112 NEIGHBOR_STR
5113 NEIGHBOR_ADDR_STR2
5114 "Administratively shut down this neighbor\n"
5115 "Shutdown if round-trip-time is higher than expected\n"
5116 "Round-trip-time in milliseconds\n"
5117 "Specify the number of keepalives before shutdown\n"
5118 "The number of keepalives with higher RTT to shutdown\n")
5119{
5120 int idx_peer = 1;
5121 int idx_rtt = 4;
5122 int idx_count = 0;
5123 struct peer *peer;
5124
5125 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5126
5127 if (!peer)
5128 return CMD_WARNING_CONFIG_FAILED;
5129
5130 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5131
5132 if (argv_find(argv, argc, "count", &idx_count))
5133 peer->rtt_keepalive_conf =
5134 strtol(argv[idx_count + 1]->arg, NULL, 10);
5135
5136 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5137 PEER_FLAG_RTT_SHUTDOWN);
5138}
5139
5140DEFUN(no_neighbor_shutdown_rtt,
5141 no_neighbor_shutdown_rtt_cmd,
5142 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5143 NO_STR
5144 NEIGHBOR_STR
5145 NEIGHBOR_ADDR_STR2
5146 "Administratively shut down this neighbor\n"
5147 "Shutdown if round-trip-time is higher than expected\n"
5148 "Round-trip-time in milliseconds\n"
5149 "Specify the number of keepalives before shutdown\n"
5150 "The number of keepalives with higher RTT to shutdown\n")
5151{
5152 int idx_peer = 2;
5153 struct peer *peer;
5154
5155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5156
5157 if (!peer)
5158 return CMD_WARNING_CONFIG_FAILED;
5159
5160 peer->rtt_expected = 0;
5161 peer->rtt_keepalive_conf = 1;
5162
5163 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5164 PEER_FLAG_RTT_SHUTDOWN);
5165}
5166
718e3744 5167/* neighbor capability dynamic. */
f4b8ec07
CS
5168DEFUN_YANG (neighbor_capability_dynamic,
5169 neighbor_capability_dynamic_cmd,
5170 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5171 NEIGHBOR_STR
5172 NEIGHBOR_ADDR_STR2
5173 "Advertise capability to the peer\n"
5174 "Advertise dynamic capability to this neighbor\n")
718e3744 5175{
d62a17ae 5176 int idx_peer = 1;
f4b8ec07
CS
5177 char base_xpath[XPATH_MAXLEN];
5178
5179 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5180 sizeof(base_xpath), NULL)
5181 < 0)
5182 return CMD_WARNING_CONFIG_FAILED;
5183
5184 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5185 NB_OP_MODIFY, "true");
5186
5187 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5188}
5189
f4b8ec07
CS
5190DEFUN_YANG (no_neighbor_capability_dynamic,
5191 no_neighbor_capability_dynamic_cmd,
5192 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5193 NO_STR
5194 NEIGHBOR_STR
5195 NEIGHBOR_ADDR_STR2
5196 "Advertise capability to the peer\n"
5197 "Advertise dynamic capability 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, "./capability-options/dynamic-capability",
5208 NB_OP_MODIFY, "false");
5209
5210 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5211}
6b0655a2 5212
718e3744 5213/* neighbor dont-capability-negotiate */
5214DEFUN (neighbor_dont_capability_negotiate,
5215 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5216 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5217 NEIGHBOR_STR
5218 NEIGHBOR_ADDR_STR2
5219 "Do not perform capability negotiation\n")
5220{
d62a17ae 5221 int idx_peer = 1;
5222 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5223 PEER_FLAG_DONT_CAPABILITY);
718e3744 5224}
5225
5226DEFUN (no_neighbor_dont_capability_negotiate,
5227 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5228 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5229 NO_STR
5230 NEIGHBOR_STR
5231 NEIGHBOR_ADDR_STR2
5232 "Do not perform capability negotiation\n")
5233{
d62a17ae 5234 int idx_peer = 2;
5235 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5236 PEER_FLAG_DONT_CAPABILITY);
718e3744 5237}
6b0655a2 5238
8a92a8a0 5239/* neighbor capability extended next hop encoding */
f4b8ec07
CS
5240DEFUN_YANG (neighbor_capability_enhe,
5241 neighbor_capability_enhe_cmd,
5242 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5243 NEIGHBOR_STR
5244 NEIGHBOR_ADDR_STR2
5245 "Advertise capability to the peer\n"
5246 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5247{
d62a17ae 5248 int idx_peer = 1;
f4b8ec07
CS
5249 char base_xpath[XPATH_MAXLEN];
5250
5251 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5252 sizeof(base_xpath), NULL)
5253 < 0)
5254 return CMD_WARNING_CONFIG_FAILED;
5255
5256 nb_cli_enqueue_change(
5257 vty, "./capability-options/extended-nexthop-capability",
5258 NB_OP_MODIFY, "true");
5259
5260 return nb_cli_apply_changes(vty, base_xpath);
8a92a8a0
DS
5261}
5262
f4b8ec07
CS
5263DEFUN_YANG (no_neighbor_capability_enhe,
5264 no_neighbor_capability_enhe_cmd,
5265 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5266 NO_STR
5267 NEIGHBOR_STR
5268 NEIGHBOR_ADDR_STR2
5269 "Advertise capability to the peer\n"
5270 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5271{
d62a17ae 5272 int idx_peer = 2;
f4b8ec07
CS
5273 char base_xpath[XPATH_MAXLEN];
5274
5275 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5276 sizeof(base_xpath), NULL)
5277 < 0)
5278 return CMD_WARNING_CONFIG_FAILED;
5279
5280 nb_cli_enqueue_change(
5281 vty, "./capability-options/extended-nexthop-capability",
5282 NB_OP_MODIFY, "false");
5283
5284 return nb_cli_apply_changes(vty, base_xpath);
5285}
5286
5287int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5288 uint32_t flag, int set, char *errmsg,
5289 size_t errmsg_len)
5290{
5291 int ret;
5292
5293 if (set)
5294 ret = peer_af_flag_set(peer, afi, safi, flag);
5295 else
5296 ret = peer_af_flag_unset(peer, afi, safi, flag);
5297
5298 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
8a92a8a0
DS
5299}
5300
d62a17ae 5301static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5302 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5303 int set)
718e3744 5304{
d62a17ae 5305 int ret;
5306 struct peer *peer;
718e3744 5307
d62a17ae 5308 peer = peer_and_group_lookup_vty(vty, peer_str);
5309 if (!peer)
5310 return CMD_WARNING_CONFIG_FAILED;
718e3744 5311
d62a17ae 5312 if (set)
5313 ret = peer_af_flag_set(peer, afi, safi, flag);
5314 else
5315 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5316
d62a17ae 5317 return bgp_vty_return(vty, ret);
718e3744 5318}
5319
d62a17ae 5320static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5321 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5322{
d62a17ae 5323 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5324}
5325
d62a17ae 5326static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5327 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5328{
d62a17ae 5329 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5330}
6b0655a2 5331
718e3744 5332/* neighbor capability orf prefix-list. */
5333DEFUN (neighbor_capability_orf_prefix,
5334 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5335 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5336 NEIGHBOR_STR
5337 NEIGHBOR_ADDR_STR2
5338 "Advertise capability to the peer\n"
5339 "Advertise ORF capability to the peer\n"
5340 "Advertise prefixlist ORF capability to this neighbor\n"
5341 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5342 "Capability to RECEIVE the ORF from this neighbor\n"
5343 "Capability to SEND the ORF to this neighbor\n")
5344{
d62a17ae 5345 int idx_send_recv = 5;
db45f64d
DS
5346 char *peer_str = argv[1]->arg;
5347 struct peer *peer;
5348 afi_t afi = bgp_node_afi(vty);
5349 safi_t safi = bgp_node_safi(vty);
d62a17ae 5350
db45f64d
DS
5351 peer = peer_and_group_lookup_vty(vty, peer_str);
5352 if (!peer)
d62a17ae 5353 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5354
db45f64d
DS
5355 if (strmatch(argv[idx_send_recv]->text, "send"))
5356 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5357 PEER_FLAG_ORF_PREFIX_SM);
5358
5359 if (strmatch(argv[idx_send_recv]->text, "receive"))
5360 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5361 PEER_FLAG_ORF_PREFIX_RM);
5362
5363 if (strmatch(argv[idx_send_recv]->text, "both"))
5364 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5365 PEER_FLAG_ORF_PREFIX_SM)
5366 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5367 PEER_FLAG_ORF_PREFIX_RM);
5368
5369 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5370}
5371
5372ALIAS_HIDDEN(
5373 neighbor_capability_orf_prefix,
5374 neighbor_capability_orf_prefix_hidden_cmd,
5375 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5376 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5377 "Advertise capability to the peer\n"
5378 "Advertise ORF capability to the peer\n"
5379 "Advertise prefixlist ORF capability to this neighbor\n"
5380 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5381 "Capability to RECEIVE the ORF from this neighbor\n"
5382 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5383
718e3744 5384DEFUN (no_neighbor_capability_orf_prefix,
5385 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5386 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5387 NO_STR
5388 NEIGHBOR_STR
5389 NEIGHBOR_ADDR_STR2
5390 "Advertise capability to the peer\n"
5391 "Advertise ORF capability to the peer\n"
5392 "Advertise prefixlist ORF capability to this neighbor\n"
5393 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5394 "Capability to RECEIVE the ORF from this neighbor\n"
5395 "Capability to SEND the ORF to this neighbor\n")
5396{
d62a17ae 5397 int idx_send_recv = 6;
db45f64d
DS
5398 char *peer_str = argv[2]->arg;
5399 struct peer *peer;
5400 afi_t afi = bgp_node_afi(vty);
5401 safi_t safi = bgp_node_safi(vty);
d62a17ae 5402
db45f64d
DS
5403 peer = peer_and_group_lookup_vty(vty, peer_str);
5404 if (!peer)
d62a17ae 5405 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5406
db45f64d
DS
5407 if (strmatch(argv[idx_send_recv]->text, "send"))
5408 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5409 PEER_FLAG_ORF_PREFIX_SM);
5410
5411 if (strmatch(argv[idx_send_recv]->text, "receive"))
5412 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5413 PEER_FLAG_ORF_PREFIX_RM);
5414
5415 if (strmatch(argv[idx_send_recv]->text, "both"))
5416 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5417 PEER_FLAG_ORF_PREFIX_SM)
5418 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5419 PEER_FLAG_ORF_PREFIX_RM);
5420
5421 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5422}
5423
5424ALIAS_HIDDEN(
5425 no_neighbor_capability_orf_prefix,
5426 no_neighbor_capability_orf_prefix_hidden_cmd,
5427 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5428 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5429 "Advertise capability to the peer\n"
5430 "Advertise ORF capability to the peer\n"
5431 "Advertise prefixlist ORF capability to this neighbor\n"
5432 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5433 "Capability to RECEIVE the ORF from this neighbor\n"
5434 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5435
718e3744 5436/* neighbor next-hop-self. */
f4b8ec07
CS
5437DEFUN_YANG (neighbor_nexthop_self,
5438 neighbor_nexthop_self_cmd,
5439 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5440 NEIGHBOR_STR
5441 NEIGHBOR_ADDR_STR2
5442 "Disable the next hop calculation for this neighbor\n")
718e3744 5443{
d62a17ae 5444 int idx_peer = 1;
f4b8ec07
CS
5445 char base_xpath[XPATH_MAXLEN];
5446 char af_xpath[XPATH_MAXLEN];
5447 char attr_xpath[XPATH_MAXLEN];
5448 afi_t afi = bgp_node_afi(vty);
5449 safi_t safi = bgp_node_safi(vty);
5450
5451
5452 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5453 yang_afi_safi_value2identity(afi, safi));
5454
5455 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5456 sizeof(base_xpath), af_xpath)
5457 < 0)
5458 return CMD_WARNING_CONFIG_FAILED;
5459
5460 snprintf(attr_xpath, sizeof(attr_xpath),
5461 "./%s/nexthop-self/next-hop-self",
5462 bgp_afi_safi_get_container_str(afi, safi));
5463
5464 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5465
5466 return nb_cli_apply_changes(vty, base_xpath);
a538debe 5467}
9e7a53c1 5468
d62a17ae 5469ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5470 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5471 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5472 "Disable the next hop calculation for this neighbor\n")
596c17ba 5473
f4b8ec07
CS
5474/* neighbor next-hop-self. */
5475DEFUN_YANG(neighbor_nexthop_self_force,
5476 neighbor_nexthop_self_force_cmd,
5477 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5478 NEIGHBOR_STR
5479 NEIGHBOR_ADDR_STR2
5480 "Disable the next hop calculation for this neighbor\n"
5481 "Set the next hop to self for reflected routes\n")
5482{
5483 int idx_peer = 1;
5484 char base_xpath[XPATH_MAXLEN];
5485 char af_xpath[XPATH_MAXLEN];
5486 char attr_xpath[XPATH_MAXLEN];
5487 afi_t afi = bgp_node_afi(vty);
5488 safi_t safi = bgp_node_safi(vty);
5489
5490
5491 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5492 yang_afi_safi_value2identity(afi, safi));
5493
5494 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5495 sizeof(base_xpath), af_xpath)
5496 < 0)
5497 return CMD_WARNING_CONFIG_FAILED;
5498
5499 snprintf(attr_xpath, sizeof(attr_xpath),
5500 "./%s/nexthop-self/next-hop-self-force",
5501 bgp_afi_safi_get_container_str(afi, safi));
5502
5503 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5504
5505 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5506}
5507
d62a17ae 5508ALIAS_HIDDEN(neighbor_nexthop_self_force,
5509 neighbor_nexthop_self_force_hidden_cmd,
5510 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5511 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5512 "Disable the next hop calculation for this neighbor\n"
5513 "Set the next hop to self for reflected routes\n")
596c17ba 5514
1bc4e531
DA
5515ALIAS_HIDDEN(neighbor_nexthop_self_force,
5516 neighbor_nexthop_self_all_hidden_cmd,
5517 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5518 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5519 "Disable the next hop calculation for this neighbor\n"
5520 "Set the next hop to self for reflected routes\n")
5521
f4b8ec07
CS
5522DEFUN_YANG (no_neighbor_nexthop_self,
5523 no_neighbor_nexthop_self_cmd,
5524 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5525 NO_STR
5526 NEIGHBOR_STR
5527 NEIGHBOR_ADDR_STR2
5528 "Disable the next hop calculation for this neighbor\n")
718e3744 5529{
d62a17ae 5530 int idx_peer = 2;
f4b8ec07
CS
5531 char base_xpath[XPATH_MAXLEN];
5532 char af_xpath[XPATH_MAXLEN];
5533 char attr_xpath[XPATH_MAXLEN];
5534 afi_t afi = bgp_node_afi(vty);
5535 safi_t safi = bgp_node_safi(vty);
5536
5537 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5538 yang_afi_safi_value2identity(afi, safi));
5539
5540 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5541 sizeof(base_xpath), af_xpath)
5542 < 0)
5543 return CMD_WARNING_CONFIG_FAILED;
5544
5545 snprintf(attr_xpath, sizeof(attr_xpath),
5546 "./%s/nexthop-self/next-hop-self",
5547 bgp_afi_safi_get_container_str(afi, safi));
5548
5549 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5550
5551 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5552}
6b0655a2 5553
d62a17ae 5554ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5555 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5556 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5557 "Disable the next hop calculation for this neighbor\n")
596c17ba 5558
f4b8ec07
CS
5559DEFUN_YANG (no_neighbor_nexthop_self_force,
5560 no_neighbor_nexthop_self_force_cmd,
5561 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5562 NO_STR
5563 NEIGHBOR_STR
5564 NEIGHBOR_ADDR_STR2
5565 "Disable the next hop calculation for this neighbor\n"
5566 "Set the next hop to self for reflected routes\n")
88b8ed8d 5567{
d62a17ae 5568 int idx_peer = 2;
f4b8ec07
CS
5569 char base_xpath[XPATH_MAXLEN];
5570 char af_xpath[XPATH_MAXLEN];
5571 char attr_xpath[XPATH_MAXLEN];
5572 afi_t afi = bgp_node_afi(vty);
5573 safi_t safi = bgp_node_safi(vty);
5574
5575
5576 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5577 yang_afi_safi_value2identity(afi, safi));
5578
5579 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5580 sizeof(base_xpath), af_xpath)
5581 < 0)
5582 return CMD_WARNING_CONFIG_FAILED;
5583
5584 snprintf(attr_xpath, sizeof(attr_xpath),
5585 "./%s/nexthop-self/next-hop-self-force",
5586 bgp_afi_safi_get_container_str(afi, safi));
5587
5588 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5589
5590 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5591}
a538debe 5592
d62a17ae 5593ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5594 no_neighbor_nexthop_self_force_hidden_cmd,
5595 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5596 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5597 "Disable the next hop calculation for this neighbor\n"
5598 "Set the next hop to self for reflected routes\n")
596c17ba 5599
1bc4e531
DA
5600ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5601 no_neighbor_nexthop_self_all_hidden_cmd,
5602 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5603 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5604 "Disable the next hop calculation for this neighbor\n"
5605 "Set the next hop to self for reflected routes\n")
5606
c7122e14 5607/* neighbor as-override */
f4b8ec07
CS
5608DEFUN_YANG (neighbor_as_override,
5609 neighbor_as_override_cmd,
5610 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5611 NEIGHBOR_STR
5612 NEIGHBOR_ADDR_STR2
5613 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5614{
d62a17ae 5615 int idx_peer = 1;
f4b8ec07
CS
5616 char base_xpath[XPATH_MAXLEN];
5617 char af_xpath[XPATH_MAXLEN];
5618 char attr_xpath[XPATH_MAXLEN];
5619 afi_t afi = bgp_node_afi(vty);
5620 safi_t safi = bgp_node_safi(vty);
5621
5622 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5623 yang_afi_safi_value2identity(afi, safi));
5624
5625 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5626 sizeof(base_xpath), af_xpath)
5627 < 0)
5628 return CMD_WARNING_CONFIG_FAILED;
5629
5630 snprintf(attr_xpath, sizeof(attr_xpath),
5631 "./%s/as-path-options/replace-peer-as",
5632 bgp_afi_safi_get_container_str(afi, safi));
5633
5634 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5635
5636 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5637}
5638
d62a17ae 5639ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5641 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5642 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5643
f4b8ec07
CS
5644DEFUN_YANG (no_neighbor_as_override,
5645 no_neighbor_as_override_cmd,
5646 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5647 NO_STR
5648 NEIGHBOR_STR
5649 NEIGHBOR_ADDR_STR2
5650 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5651{
d62a17ae 5652 int idx_peer = 2;
f4b8ec07
CS
5653 char base_xpath[XPATH_MAXLEN];
5654 char af_xpath[XPATH_MAXLEN];
5655 char attr_xpath[XPATH_MAXLEN];
5656 afi_t afi = bgp_node_afi(vty);
5657 safi_t safi = bgp_node_safi(vty);
5658
5659 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5660 yang_afi_safi_value2identity(afi, safi));
5661
5662 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5663 sizeof(base_xpath), af_xpath)
5664 < 0)
5665 return CMD_WARNING_CONFIG_FAILED;
5666
5667 snprintf(attr_xpath, sizeof(attr_xpath),
5668 "./%s/as-path-options/replace-peer-as",
5669 bgp_afi_safi_get_container_str(afi, safi));
5670
5671 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5672
5673 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5674}
5675
d62a17ae 5676ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5677 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5678 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5679 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5680
718e3744 5681/* neighbor remove-private-AS. */
f4b8ec07
CS
5682DEFUN_YANG (neighbor_remove_private_as,
5683 neighbor_remove_private_as_cmd,
5684 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5685 NEIGHBOR_STR
5686 NEIGHBOR_ADDR_STR2
5687 "Remove private ASNs in outbound updates\n")
718e3744 5688{
d62a17ae 5689 int idx_peer = 1;
f4b8ec07
CS
5690 char base_xpath[XPATH_MAXLEN];
5691 char af_xpath[XPATH_MAXLEN];
5692 char attr_xpath[XPATH_MAXLEN];
5693 afi_t afi = bgp_node_afi(vty);
5694 safi_t safi = bgp_node_safi(vty);
5695
5696 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5697 yang_afi_safi_value2identity(afi, safi));
5698
5699 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5700 sizeof(base_xpath), af_xpath)
5701 < 0)
5702 return CMD_WARNING_CONFIG_FAILED;
5703
5704 snprintf(attr_xpath, sizeof(attr_xpath),
5705 "./%s/private-as/remove-private-as",
5706 bgp_afi_safi_get_container_str(afi, safi));
5707
5708 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5709
5710 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5711}
5712
d62a17ae 5713ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5714 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5715 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5716 "Remove private ASNs in outbound updates\n")
596c17ba 5717
f4b8ec07
CS
5718DEFUN_YANG (neighbor_remove_private_as_all,
5719 neighbor_remove_private_as_all_cmd,
5720 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5721 NEIGHBOR_STR
5722 NEIGHBOR_ADDR_STR2
5723 "Remove private ASNs in outbound updates\n"
5724 "Apply to all AS numbers\n")
5000f21c 5725{
d62a17ae 5726 int idx_peer = 1;
f4b8ec07
CS
5727 char base_xpath[XPATH_MAXLEN];
5728 char af_xpath[XPATH_MAXLEN];
5729 char attr_xpath[XPATH_MAXLEN];
5730 afi_t afi = bgp_node_afi(vty);
5731 safi_t safi = bgp_node_safi(vty);
5732
5733
5734 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5735 yang_afi_safi_value2identity(afi, safi));
5736
5737 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5738 sizeof(base_xpath), af_xpath)
5739 < 0)
5740 return CMD_WARNING_CONFIG_FAILED;
5741
5742 snprintf(attr_xpath, sizeof(attr_xpath),
5743 "./%s/private-as/remove-private-as-all",
5744 bgp_afi_safi_get_container_str(afi, safi));
5745
5746 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5747
5748 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5749}
5750
d62a17ae 5751ALIAS_HIDDEN(neighbor_remove_private_as_all,
5752 neighbor_remove_private_as_all_hidden_cmd,
5753 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5754 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5755 "Remove private ASNs in outbound updates\n"
5756 "Apply to all AS numbers")
596c17ba 5757
f4b8ec07
CS
5758DEFUN_YANG (neighbor_remove_private_as_replace_as,
5759 neighbor_remove_private_as_replace_as_cmd,
5760 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5761 NEIGHBOR_STR
5762 NEIGHBOR_ADDR_STR2
5763 "Remove private ASNs in outbound updates\n"
5764 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5765{
d62a17ae 5766 int idx_peer = 1;
f4b8ec07
CS
5767 char base_xpath[XPATH_MAXLEN];
5768 char af_xpath[XPATH_MAXLEN];
5769 char attr_xpath[XPATH_MAXLEN];
5770 afi_t afi = bgp_node_afi(vty);
5771 safi_t safi = bgp_node_safi(vty);
5772
5773
5774 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5775 yang_afi_safi_value2identity(afi, safi));
5776
5777 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5778 sizeof(base_xpath), af_xpath)
5779 < 0)
5780 return CMD_WARNING_CONFIG_FAILED;
5781
5782 snprintf(attr_xpath, sizeof(attr_xpath),
5783 "./%s/private-as/remove-private-as-replace",
5784 bgp_afi_safi_get_container_str(afi, safi));
5785
5786 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5787
5788 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5789}
5790
d62a17ae 5791ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5792 neighbor_remove_private_as_replace_as_hidden_cmd,
5793 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5794 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5795 "Remove private ASNs in outbound updates\n"
5796 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5797
f4b8ec07
CS
5798DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5799 neighbor_remove_private_as_all_replace_as_cmd,
5800 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5801 NEIGHBOR_STR
5802 NEIGHBOR_ADDR_STR2
5803 "Remove private ASNs in outbound updates\n"
5804 "Apply to all AS numbers\n"
5805 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5806{
d62a17ae 5807 int idx_peer = 1;
f4b8ec07
CS
5808 char base_xpath[XPATH_MAXLEN];
5809 char af_xpath[XPATH_MAXLEN];
5810 char attr_xpath[XPATH_MAXLEN];
5811 afi_t afi = bgp_node_afi(vty);
5812 safi_t safi = bgp_node_safi(vty);
5813
5814
5815 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5816 yang_afi_safi_value2identity(afi, safi));
5817
5818 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5819 sizeof(base_xpath), af_xpath)
5820 < 0)
5821 return CMD_WARNING_CONFIG_FAILED;
5822
5823 snprintf(attr_xpath, sizeof(attr_xpath),
5824 "./%s/private-as/remove-private-as-all-replace",
5825 bgp_afi_safi_get_container_str(afi, safi));
5826
5827 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5828
5829 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5830}
5831
d62a17ae 5832ALIAS_HIDDEN(
5833 neighbor_remove_private_as_all_replace_as,
5834 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5835 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5836 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5837 "Remove private ASNs in outbound updates\n"
5838 "Apply to all AS numbers\n"
5839 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5840
f4b8ec07
CS
5841DEFUN_YANG (no_neighbor_remove_private_as,
5842 no_neighbor_remove_private_as_cmd,
5843 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5844 NO_STR
5845 NEIGHBOR_STR
5846 NEIGHBOR_ADDR_STR2
5847 "Remove private ASNs in outbound updates\n")
718e3744 5848{
d62a17ae 5849 int idx_peer = 2;
f4b8ec07
CS
5850 char base_xpath[XPATH_MAXLEN];
5851 char af_xpath[XPATH_MAXLEN];
5852 char attr_xpath[XPATH_MAXLEN];
5853 afi_t afi = bgp_node_afi(vty);
5854 safi_t safi = bgp_node_safi(vty);
5855
5856 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5857 yang_afi_safi_value2identity(afi, safi));
5858
5859 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5860 sizeof(base_xpath), af_xpath)
5861 < 0)
5862 return CMD_WARNING_CONFIG_FAILED;
5863
5864 snprintf(attr_xpath, sizeof(attr_xpath),
5865 "./%s/private-as/remove-private-as",
5866 bgp_afi_safi_get_container_str(afi, safi));
5867
5868 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5869
5870 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5871}
6b0655a2 5872
d62a17ae 5873ALIAS_HIDDEN(no_neighbor_remove_private_as,
5874 no_neighbor_remove_private_as_hidden_cmd,
5875 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5876 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5877 "Remove private ASNs in outbound updates\n")
596c17ba 5878
f4b8ec07
CS
5879DEFUN_YANG (no_neighbor_remove_private_as_all,
5880 no_neighbor_remove_private_as_all_cmd,
5881 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5882 NO_STR
5883 NEIGHBOR_STR
5884 NEIGHBOR_ADDR_STR2
5885 "Remove private ASNs in outbound updates\n"
5886 "Apply to all AS numbers\n")
88b8ed8d 5887{
d62a17ae 5888 int idx_peer = 2;
f4b8ec07
CS
5889 char base_xpath[XPATH_MAXLEN];
5890 char af_xpath[XPATH_MAXLEN];
5891 char attr_xpath[XPATH_MAXLEN];
5892 afi_t afi = bgp_node_afi(vty);
5893 safi_t safi = bgp_node_safi(vty);
5894
5895
5896 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5897 yang_afi_safi_value2identity(afi, safi));
5898
5899 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5900 sizeof(base_xpath), af_xpath)
5901 < 0)
5902 return CMD_WARNING_CONFIG_FAILED;
5903
5904 snprintf(attr_xpath, sizeof(attr_xpath),
5905 "./%s/private-as/remove-private-as-all",
5906 bgp_afi_safi_get_container_str(afi, safi));
5907
5908 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5909
5910 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5911}
5000f21c 5912
d62a17ae 5913ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5914 no_neighbor_remove_private_as_all_hidden_cmd,
5915 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5916 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5917 "Remove private ASNs in outbound updates\n"
5918 "Apply to all AS numbers\n")
596c17ba 5919
f4b8ec07
CS
5920DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
5921 no_neighbor_remove_private_as_replace_as_cmd,
5922 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5923 NO_STR
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")
88b8ed8d 5928{
d62a17ae 5929 int idx_peer = 2;
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
5936
5937 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5938 yang_afi_safi_value2identity(afi, safi));
5939
5940 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5941 sizeof(base_xpath), af_xpath)
5942 < 0)
5943 return CMD_WARNING_CONFIG_FAILED;
5944
5945 snprintf(attr_xpath, sizeof(attr_xpath),
5946 "./%s/private-as/remove-private-as-replace",
5947 bgp_afi_safi_get_container_str(afi, safi));
5948
5949 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5950
5951 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5952}
5000f21c 5953
d62a17ae 5954ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5955 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5956 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5957 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5958 "Remove private ASNs in outbound updates\n"
5959 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5960
f4b8ec07
CS
5961DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
5962 no_neighbor_remove_private_as_all_replace_as_cmd,
5963 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5964 NO_STR
5965 NEIGHBOR_STR
5966 NEIGHBOR_ADDR_STR2
5967 "Remove private ASNs in outbound updates\n"
5968 "Apply to all AS numbers\n"
5969 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5970{
d62a17ae 5971 int idx_peer = 2;
f4b8ec07
CS
5972 char base_xpath[XPATH_MAXLEN];
5973 char af_xpath[XPATH_MAXLEN];
5974 char attr_xpath[XPATH_MAXLEN];
5975 afi_t afi = bgp_node_afi(vty);
5976 safi_t safi = bgp_node_safi(vty);
5977
5978
5979 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5980 yang_afi_safi_value2identity(afi, safi));
5981
5982 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5983 sizeof(base_xpath), af_xpath)
5984 < 0)
5985 return CMD_WARNING_CONFIG_FAILED;
5986
5987 snprintf(attr_xpath, sizeof(attr_xpath),
5988 "./%s/private-as/remove-private-as-all-replace",
5989 bgp_afi_safi_get_container_str(afi, safi));
5990
5991 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5992
5993 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5994}
5000f21c 5995
d62a17ae 5996ALIAS_HIDDEN(
5997 no_neighbor_remove_private_as_all_replace_as,
5998 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5999 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6000 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6001 "Remove private ASNs in outbound updates\n"
6002 "Apply to all AS numbers\n"
6003 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6004
5000f21c 6005
718e3744 6006/* neighbor send-community. */
f4b8ec07
CS
6007DEFUN_YANG (neighbor_send_community,
6008 neighbor_send_community_cmd,
6009 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6010 NEIGHBOR_STR
6011 NEIGHBOR_ADDR_STR2
6012 "Send Community attribute to this neighbor\n")
718e3744 6013{
d62a17ae 6014 int idx_peer = 1;
27c05d4d 6015
d62a17ae 6016 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6017 bgp_node_safi(vty),
6018 PEER_FLAG_SEND_COMMUNITY);
718e3744 6019}
6020
d62a17ae 6021ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6022 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6023 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6024 "Send Community attribute to this neighbor\n")
596c17ba 6025
f4b8ec07
CS
6026DEFUN_YANG (no_neighbor_send_community,
6027 no_neighbor_send_community_cmd,
6028 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6029 NO_STR
6030 NEIGHBOR_STR
6031 NEIGHBOR_ADDR_STR2
6032 "Send Community attribute to this neighbor\n")
718e3744 6033{
d62a17ae 6034 int idx_peer = 2;
27c05d4d 6035
d62a17ae 6036 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6037 bgp_node_afi(vty), bgp_node_safi(vty),
6038 PEER_FLAG_SEND_COMMUNITY);
718e3744 6039}
6b0655a2 6040
d62a17ae 6041ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6042 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6043 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6044 "Send Community attribute to this neighbor\n")
596c17ba 6045
718e3744 6046/* neighbor send-community extended. */
f4b8ec07
CS
6047DEFUN_YANG (neighbor_send_community_type,
6048 neighbor_send_community_type_cmd,
6049 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6050 NEIGHBOR_STR
6051 NEIGHBOR_ADDR_STR2
6052 "Send Community attribute to this neighbor\n"
6053 "Send Standard and Extended Community attributes\n"
6054 "Send Standard, Large and Extended Community attributes\n"
6055 "Send Extended Community attributes\n"
6056 "Send Standard Community attributes\n"
6057 "Send Large Community attributes\n")
718e3744 6058{
27c05d4d 6059 const char *type = argv[argc - 1]->text;
db45f64d 6060 char *peer_str = argv[1]->arg;
f4b8ec07
CS
6061 char base_xpath[XPATH_MAXLEN];
6062 char af_xpath[XPATH_MAXLEN];
6063 char std_xpath[XPATH_MAXLEN];
6064 char ext_xpath[XPATH_MAXLEN];
6065 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6066 afi_t afi = bgp_node_afi(vty);
6067 safi_t safi = bgp_node_safi(vty);
d62a17ae 6068
f4b8ec07
CS
6069 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6070 yang_afi_safi_value2identity(afi, safi));
6071
6072 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6073 sizeof(base_xpath), af_xpath)
6074 < 0)
db45f64d 6075 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6076
f4b8ec07
CS
6077 if (strmatch(type, "standard")) {
6078 snprintf(std_xpath, sizeof(std_xpath),
6079 "./%s/send-community/send-community",
6080 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6081
f4b8ec07
CS
6082 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6083 }
db45f64d 6084
f4b8ec07
CS
6085 if (strmatch(type, "extended")) {
6086 snprintf(ext_xpath, sizeof(ext_xpath),
6087 "./%s/send-community/send-ext-community",
6088 bgp_afi_safi_get_container_str(afi, safi));
6089
6090 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6091 }
6092
6093 if (strmatch(type, "large")) {
6094 snprintf(lrg_xpath, sizeof(lrg_xpath),
6095 "./%s/send-community/send-large-community",
6096 bgp_afi_safi_get_container_str(afi, safi));
6097
6098 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6099 }
db45f64d
DS
6100
6101 if (strmatch(type, "both")) {
f4b8ec07
CS
6102 snprintf(std_xpath, sizeof(std_xpath),
6103 "./%s/send-community/send-community",
6104 bgp_afi_safi_get_container_str(afi, safi));
6105
6106 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6107
6108 snprintf(ext_xpath, sizeof(ext_xpath),
6109 "./%s/send-community/send-ext-community",
6110 bgp_afi_safi_get_container_str(afi, safi));
6111
6112 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
db45f64d 6113 }
f4b8ec07
CS
6114
6115 if (strmatch(type, "all")) {
6116 snprintf(std_xpath, sizeof(std_xpath),
6117 "./%s/send-community/send-community",
6118 bgp_afi_safi_get_container_str(afi, safi));
6119
6120 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6121
6122 snprintf(ext_xpath, sizeof(ext_xpath),
6123 "./%s/send-community/send-ext-community",
6124 bgp_afi_safi_get_container_str(afi, safi));
6125
6126 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6127
6128 snprintf(lrg_xpath, sizeof(lrg_xpath),
6129 "./%s/send-community/send-large-community",
6130 bgp_afi_safi_get_container_str(afi, safi));
6131
6132 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6133 }
6134
6135 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6136}
6137
6138ALIAS_HIDDEN(
6139 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6140 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6141 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6142 "Send Community attribute to this neighbor\n"
6143 "Send Standard and Extended Community attributes\n"
6144 "Send Standard, Large and Extended Community attributes\n"
6145 "Send Extended Community attributes\n"
6146 "Send Standard Community attributes\n"
6147 "Send Large Community attributes\n")
596c17ba 6148
f4b8ec07
CS
6149DEFUN_YANG (no_neighbor_send_community_type,
6150 no_neighbor_send_community_type_cmd,
6151 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6152 NO_STR
6153 NEIGHBOR_STR
6154 NEIGHBOR_ADDR_STR2
6155 "Send Community attribute to this neighbor\n"
6156 "Send Standard and Extended Community attributes\n"
6157 "Send Standard, Large and Extended Community attributes\n"
6158 "Send Extended Community attributes\n"
6159 "Send Standard Community attributes\n"
6160 "Send Large Community attributes\n")
718e3744 6161{
d62a17ae 6162 const char *type = argv[argc - 1]->text;
db45f64d 6163 char *peer_str = argv[2]->arg;
f4b8ec07
CS
6164 char base_xpath[XPATH_MAXLEN];
6165 char af_xpath[XPATH_MAXLEN];
6166 char std_xpath[XPATH_MAXLEN];
6167 char ext_xpath[XPATH_MAXLEN];
6168 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6169 afi_t afi = bgp_node_afi(vty);
6170 safi_t safi = bgp_node_safi(vty);
6171
f4b8ec07
CS
6172 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6173 yang_afi_safi_value2identity(afi, safi));
6174
6175 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6176 sizeof(base_xpath), af_xpath)
6177 < 0)
6178 return CMD_WARNING_CONFIG_FAILED;
6179
6180 if (strmatch(type, "standard")) {
6181 snprintf(std_xpath, sizeof(std_xpath),
6182 "./%s/send-community/send-community",
6183 bgp_afi_safi_get_container_str(afi, safi));
6184
6185 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6186 }
6187
6188 if (strmatch(type, "extended")) {
6189 snprintf(ext_xpath, sizeof(ext_xpath),
6190 "./%s/send-community/send-ext-community",
6191 bgp_afi_safi_get_container_str(afi, safi));
6192
6193 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6194 }
6195
6196 if (strmatch(type, "large")) {
6197 snprintf(lrg_xpath, sizeof(lrg_xpath),
6198 "./%s/send-community/send-large-community",
6199 bgp_afi_safi_get_container_str(afi, safi));
6200
6201 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6202 }
6203
6204 if (strmatch(type, "both")) {
6205 snprintf(std_xpath, sizeof(std_xpath),
6206 "./%s/send-community/send-community",
6207 bgp_afi_safi_get_container_str(afi, safi));
6208
6209 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6210
6211 snprintf(ext_xpath, sizeof(ext_xpath),
6212 "./%s/send-community/send-ext-community",
6213 bgp_afi_safi_get_container_str(afi, safi));
6214
6215 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6216 }
6217
6218 if (strmatch(type, "all")) {
6219 snprintf(std_xpath, sizeof(std_xpath),
6220 "./%s/send-community/send-community",
6221 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6222
f4b8ec07 6223 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
db45f64d 6224
f4b8ec07
CS
6225 snprintf(ext_xpath, sizeof(ext_xpath),
6226 "./%s/send-community/send-ext-community",
6227 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6228
f4b8ec07 6229 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
db45f64d 6230
f4b8ec07
CS
6231 snprintf(lrg_xpath, sizeof(lrg_xpath),
6232 "./%s/send-community/send-large-community",
6233 bgp_afi_safi_get_container_str(afi, safi));
d62a17ae 6234
f4b8ec07 6235 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
27c05d4d
PM
6236 }
6237
f4b8ec07 6238 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6239}
6240
6241ALIAS_HIDDEN(
6242 no_neighbor_send_community_type,
6243 no_neighbor_send_community_type_hidden_cmd,
6244 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6245 NO_STR NEIGHBOR_STR 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")
596c17ba 6252
718e3744 6253/* neighbor soft-reconfig. */
f4b8ec07
CS
6254DEFUN_YANG (neighbor_soft_reconfiguration,
6255 neighbor_soft_reconfiguration_cmd,
6256 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6257 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6258 "Per neighbor soft reconfiguration\n"
6259 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6260{
d62a17ae 6261 int idx_peer = 1;
f4b8ec07
CS
6262 char base_xpath[XPATH_MAXLEN];
6263 char af_xpath[XPATH_MAXLEN];
6264 char soft_xpath[XPATH_MAXLEN];
6265 afi_t afi = bgp_node_afi(vty);
6266 safi_t safi = bgp_node_safi(vty);
6267
6268
6269 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6270 yang_afi_safi_value2identity(afi, safi));
6271
6272 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6273 sizeof(base_xpath), af_xpath)
6274 < 0)
6275 return CMD_WARNING_CONFIG_FAILED;
6276
6277 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6278 bgp_afi_safi_get_container_str(afi, safi));
6279
6280 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6281
6282 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6283}
6284
d62a17ae 6285ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6286 neighbor_soft_reconfiguration_hidden_cmd,
6287 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6289 "Per neighbor soft reconfiguration\n"
6290 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6291
f4b8ec07
CS
6292DEFUN_YANG (no_neighbor_soft_reconfiguration,
6293 no_neighbor_soft_reconfiguration_cmd,
6294 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6295 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6296 "Per neighbor soft reconfiguration\n"
6297 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6298{
d62a17ae 6299 int idx_peer = 2;
f4b8ec07
CS
6300 char base_xpath[XPATH_MAXLEN];
6301 char af_xpath[XPATH_MAXLEN];
6302 char soft_xpath[XPATH_MAXLEN];
6303 afi_t afi = bgp_node_afi(vty);
6304 safi_t safi = bgp_node_safi(vty);
6305
6306 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6307 yang_afi_safi_value2identity(afi, safi));
6308
6309 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6310 bgp_afi_safi_get_container_str(afi, safi));
6311
6312 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6313 sizeof(base_xpath), af_xpath)
6314 < 0)
6315 return CMD_WARNING_CONFIG_FAILED;
6316
6317 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6318
6319 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6320}
6b0655a2 6321
d62a17ae 6322ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6323 no_neighbor_soft_reconfiguration_hidden_cmd,
6324 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6325 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6326 "Per neighbor soft reconfiguration\n"
6327 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6328
f4b8ec07
CS
6329DEFUN_YANG (neighbor_route_reflector_client,
6330 neighbor_route_reflector_client_cmd,
6331 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6332 NEIGHBOR_STR
6333 NEIGHBOR_ADDR_STR2
6334 "Configure a neighbor as Route Reflector client\n")
718e3744 6335{
d62a17ae 6336 int idx_peer = 1;
f4b8ec07
CS
6337 char base_xpath[XPATH_MAXLEN];
6338 char af_xpath[XPATH_MAXLEN];
6339 char attr_xpath[XPATH_MAXLEN];
6340 afi_t afi = bgp_node_afi(vty);
6341 safi_t safi = bgp_node_safi(vty);
718e3744 6342
f4b8ec07
CS
6343 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6344 yang_afi_safi_value2identity(afi, safi));
718e3744 6345
f4b8ec07
CS
6346 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6347 sizeof(base_xpath), af_xpath)
6348 < 0)
d62a17ae 6349 return CMD_WARNING_CONFIG_FAILED;
718e3744 6350
f4b8ec07
CS
6351 snprintf(attr_xpath, sizeof(attr_xpath),
6352 "./%s/route-reflector/route-reflector-client",
6353 bgp_afi_safi_get_container_str(afi, safi));
6354
6355 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6356
6357 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6358}
6359
d62a17ae 6360ALIAS_HIDDEN(neighbor_route_reflector_client,
6361 neighbor_route_reflector_client_hidden_cmd,
6362 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6363 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6364 "Configure a neighbor as Route Reflector client\n")
596c17ba 6365
f4b8ec07
CS
6366DEFUN_YANG (no_neighbor_route_reflector_client,
6367 no_neighbor_route_reflector_client_cmd,
6368 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6369 NO_STR
6370 NEIGHBOR_STR
6371 NEIGHBOR_ADDR_STR2
6372 "Configure a neighbor as Route Reflector client\n")
718e3744 6373{
d62a17ae 6374 int idx_peer = 2;
f4b8ec07
CS
6375 char base_xpath[XPATH_MAXLEN];
6376 char af_xpath[XPATH_MAXLEN];
6377 char attr_xpath[XPATH_MAXLEN];
6378 afi_t afi = bgp_node_afi(vty);
6379 safi_t safi = bgp_node_safi(vty);
6380
6381 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6382 yang_afi_safi_value2identity(afi, safi));
6383
6384 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6385 sizeof(base_xpath), af_xpath)
6386 < 0)
6387 return CMD_WARNING_CONFIG_FAILED;
6388
6389 snprintf(attr_xpath, sizeof(attr_xpath),
6390 "./%s/route-reflector/route-reflector-client",
6391 bgp_afi_safi_get_container_str(afi, safi));
6392
6393 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6394
6395 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6396}
6b0655a2 6397
d62a17ae 6398ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6399 no_neighbor_route_reflector_client_hidden_cmd,
6400 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6401 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6402 "Configure a neighbor as Route Reflector client\n")
596c17ba 6403
718e3744 6404/* neighbor route-server-client. */
f4b8ec07
CS
6405DEFUN_YANG (neighbor_route_server_client,
6406 neighbor_route_server_client_cmd,
6407 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6408 NEIGHBOR_STR
6409 NEIGHBOR_ADDR_STR2
6410 "Configure a neighbor as Route Server client\n")
718e3744 6411{
d62a17ae 6412 int idx_peer = 1;
f4b8ec07
CS
6413 char base_xpath[XPATH_MAXLEN];
6414 char af_xpath[XPATH_MAXLEN];
6415 char attr_xpath[XPATH_MAXLEN];
6416 afi_t afi = bgp_node_afi(vty);
6417 safi_t safi = bgp_node_safi(vty);
2a3d5731 6418
f4b8ec07
CS
6419 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6420 yang_afi_safi_value2identity(afi, safi));
6421
6422 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6423 sizeof(base_xpath), af_xpath)
6424 < 0)
d62a17ae 6425 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07
CS
6426
6427 snprintf(attr_xpath, sizeof(attr_xpath),
6428 "./%s/route-server/route-server-client",
6429 bgp_afi_safi_get_container_str(afi, safi));
6430
6431 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6432
6433 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6434}
6435
d62a17ae 6436ALIAS_HIDDEN(neighbor_route_server_client,
6437 neighbor_route_server_client_hidden_cmd,
6438 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6439 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6440 "Configure a neighbor as Route Server client\n")
596c17ba 6441
f4b8ec07
CS
6442DEFUN_YANG (no_neighbor_route_server_client,
6443 no_neighbor_route_server_client_cmd,
6444 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6445 NO_STR
6446 NEIGHBOR_STR
6447 NEIGHBOR_ADDR_STR2
6448 "Configure a neighbor as Route Server client\n")
fee0f4c6 6449{
d62a17ae 6450 int idx_peer = 2;
f4b8ec07
CS
6451 char base_xpath[XPATH_MAXLEN];
6452 char af_xpath[XPATH_MAXLEN];
6453 char attr_xpath[XPATH_MAXLEN];
6454 afi_t afi = bgp_node_afi(vty);
6455 safi_t safi = bgp_node_safi(vty);
6456
6457 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6458 yang_afi_safi_value2identity(afi, safi));
6459
6460 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6461 sizeof(base_xpath), af_xpath)
6462 < 0)
6463 return CMD_WARNING_CONFIG_FAILED;
6464
6465 snprintf(attr_xpath, sizeof(attr_xpath),
6466 "./%s/route-server/route-server-client",
6467 bgp_afi_safi_get_container_str(afi, safi));
6468
6469 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6470
6471 return nb_cli_apply_changes(vty, base_xpath);
fee0f4c6 6472}
6b0655a2 6473
d62a17ae 6474ALIAS_HIDDEN(no_neighbor_route_server_client,
6475 no_neighbor_route_server_client_hidden_cmd,
6476 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6477 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6478 "Configure a neighbor as Route Server client\n")
596c17ba 6479
fee0f4c6 6480DEFUN (neighbor_nexthop_local_unchanged,
6481 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6482 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6483 NEIGHBOR_STR
6484 NEIGHBOR_ADDR_STR2
6485 "Configure treatment of outgoing link-local nexthop attribute\n"
6486 "Leave link-local nexthop unchanged for this peer\n")
6487{
d62a17ae 6488 int idx_peer = 1;
6489 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6490 bgp_node_safi(vty),
6491 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6492}
6b0655a2 6493
fee0f4c6 6494DEFUN (no_neighbor_nexthop_local_unchanged,
6495 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6496 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6497 NO_STR
6498 NEIGHBOR_STR
6499 NEIGHBOR_ADDR_STR2
6500 "Configure treatment of outgoing link-local-nexthop attribute\n"
6501 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6502{
d62a17ae 6503 int idx_peer = 2;
6504 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6505 bgp_node_afi(vty), bgp_node_safi(vty),
6506 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6507}
6b0655a2 6508
f4b8ec07
CS
6509DEFUN_YANG (neighbor_attr_unchanged,
6510 neighbor_attr_unchanged_cmd,
6511 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6512 NEIGHBOR_STR
6513 NEIGHBOR_ADDR_STR2
6514 "BGP attribute is propagated unchanged to this neighbor\n"
6515 "As-path attribute\n"
6516 "Nexthop attribute\n"
6517 "Med attribute\n")
718e3744 6518{
d62a17ae 6519 int idx = 0;
8eeb0335 6520 char *peer_str = argv[1]->arg;
db45f64d
DS
6521 bool aspath = false;
6522 bool nexthop = false;
6523 bool med = false;
8eeb0335
DW
6524 afi_t afi = bgp_node_afi(vty);
6525 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6526 char base_xpath[XPATH_MAXLEN];
6527 char af_xpath[XPATH_MAXLEN];
6528 char as_xpath[XPATH_MAXLEN];
6529 char nxthop_xpath[XPATH_MAXLEN];
6530 char med_xpath[XPATH_MAXLEN];
8eeb0335 6531
f4b8ec07
CS
6532 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6533 yang_afi_safi_value2identity(afi, safi));
6534
6535 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6536 sizeof(base_xpath), af_xpath)
6537 < 0)
8eeb0335 6538 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6539
6540 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6541 aspath = true;
6542
d62a17ae 6543 idx = 0;
6544 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6545 nexthop = true;
6546
d62a17ae 6547 idx = 0;
6548 if (argv_find(argv, argc, "med", &idx))
db45f64d 6549 med = true;
d62a17ae 6550
f4b8ec07
CS
6551 snprintf(as_xpath, sizeof(as_xpath),
6552 "./%s/attr-unchanged/as-path-unchanged",
6553 bgp_afi_safi_get_container_str(afi, safi));
6554 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6555 "./%s/attr-unchanged/next-hop-unchanged",
6556 bgp_afi_safi_get_container_str(afi, safi));
6557 snprintf(med_xpath, sizeof(med_xpath),
6558 "./%s/attr-unchanged/med-unchanged",
6559 bgp_afi_safi_get_container_str(afi, safi));
6560
8eeb0335 6561 /* no flags means all of them! */
db45f64d 6562 if (!aspath && !nexthop && !med) {
f4b8ec07
CS
6563 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6564 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6565 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
8eeb0335 6566 } else {
f4b8ec07
CS
6567 if (!aspath)
6568 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6569 "false");
6570 else
6571 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6572 "true");
6573
6574 if (!nexthop)
6575 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6576 "false");
6577 else
6578 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6579 "true");
6580
6581 if (!med)
6582 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6583 "false");
6584 else
6585 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6586 "true");
d62a17ae 6587 }
6588
f4b8ec07 6589 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6590}
6591
6592ALIAS_HIDDEN(
6593 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6594 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6595 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6596 "BGP attribute is propagated unchanged to this neighbor\n"
6597 "As-path attribute\n"
6598 "Nexthop attribute\n"
6599 "Med attribute\n")
596c17ba 6600
f4b8ec07
CS
6601DEFUN_YANG (no_neighbor_attr_unchanged,
6602 no_neighbor_attr_unchanged_cmd,
6603 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6604 NO_STR
6605 NEIGHBOR_STR
6606 NEIGHBOR_ADDR_STR2
6607 "BGP attribute is propagated unchanged to this neighbor\n"
6608 "As-path attribute\n"
6609 "Nexthop attribute\n"
6610 "Med attribute\n")
718e3744 6611{
d62a17ae 6612 int idx = 0;
db45f64d 6613 char *peer_str = argv[2]->arg;
db45f64d
DS
6614 bool aspath = false;
6615 bool nexthop = false;
6616 bool med = false;
6617 afi_t afi = bgp_node_afi(vty);
6618 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6619 char base_xpath[XPATH_MAXLEN];
6620 char af_xpath[XPATH_MAXLEN];
6621 char as_xpath[XPATH_MAXLEN];
6622 char nxthop_xpath[XPATH_MAXLEN];
6623 char med_xpath[XPATH_MAXLEN];
db45f64d 6624
f4b8ec07
CS
6625 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6626 yang_afi_safi_value2identity(afi, safi));
6627
6628 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6629 sizeof(base_xpath), af_xpath)
6630 < 0)
db45f64d 6631 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6632
6633 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6634 aspath = true;
6635
d62a17ae 6636 idx = 0;
6637 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6638 nexthop = true;
6639
d62a17ae 6640 idx = 0;
6641 if (argv_find(argv, argc, "med", &idx))
db45f64d 6642 med = true;
d62a17ae 6643
f4b8ec07
CS
6644 snprintf(as_xpath, sizeof(as_xpath),
6645 "./%s/attr-unchanged/as-path-unchanged",
6646 bgp_afi_safi_get_container_str(afi, safi));
6647 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6648 "./%s/attr-unchanged/next-hop-unchanged",
6649 bgp_afi_safi_get_container_str(afi, safi));
6650 snprintf(med_xpath, sizeof(med_xpath),
6651 "./%s/attr-unchanged/med-unchanged",
6652 bgp_afi_safi_get_container_str(afi, safi));
6653
6654 /* no flags means all of them! */
6655 if (!aspath && !nexthop && !med) {
6656 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6657 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6658 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6659 }
db45f64d
DS
6660
6661 if (aspath)
f4b8ec07 6662 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
db45f64d
DS
6663
6664 if (nexthop)
f4b8ec07 6665 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
d62a17ae 6666
db45f64d 6667 if (med)
f4b8ec07 6668 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
db45f64d 6669
f4b8ec07 6670 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6671}
6672
6673ALIAS_HIDDEN(
6674 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6675 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6676 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6677 "BGP attribute is propagated unchanged to this neighbor\n"
6678 "As-path attribute\n"
6679 "Nexthop attribute\n"
6680 "Med attribute\n")
718e3744 6681
f4b8ec07
CS
6682/* neighbor ebgp-multihop. */
6683DEFUN_YANG (neighbor_ebgp_multihop,
6684 neighbor_ebgp_multihop_cmd,
6685 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6686 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6687 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6688{
f4b8ec07
CS
6689 int idx_peer = 1;
6690 char base_xpath[XPATH_MAXLEN];
718e3744 6691
f4b8ec07
CS
6692 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6693 sizeof(base_xpath), NULL)
6694 < 0)
d62a17ae 6695 return CMD_WARNING_CONFIG_FAILED;
718e3744 6696
f4b8ec07
CS
6697 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6698 "true");
718e3744 6699
f4b8ec07 6700 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6701}
6702
f4b8ec07
CS
6703DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6704 neighbor_ebgp_multihop_ttl_cmd,
6705 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6706 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6707 "Allow EBGP neighbors not on directly connected networks\n"
6708 "maximum hop count\n")
718e3744 6709{
f4b8ec07
CS
6710 int idx_peer = 1;
6711 int idx_number = 3;
6712 char base_xpath[XPATH_MAXLEN];
718e3744 6713
f4b8ec07
CS
6714 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6715 sizeof(base_xpath), NULL)
6716 < 0)
d62a17ae 6717 return CMD_WARNING_CONFIG_FAILED;
718e3744 6718
f4b8ec07
CS
6719 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6720 argv[idx_number]->arg);
718e3744 6721
f4b8ec07 6722 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6723}
6724
f4b8ec07
CS
6725DEFUN_YANG (no_neighbor_ebgp_multihop,
6726 no_neighbor_ebgp_multihop_cmd,
6727 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6728 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6729 "Allow EBGP neighbors not on directly connected networks\n"
6730 "maximum hop count\n")
718e3744 6731{
d62a17ae 6732 int idx_peer = 2;
f4b8ec07
CS
6733 char base_xpath[XPATH_MAXLEN];
6734
6735 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6736 sizeof(base_xpath), NULL)
6737 < 0)
6738 return CMD_WARNING_CONFIG_FAILED;
6739
6740 if (argc > 4)
6741 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6742 NB_OP_DESTROY, NULL);
6743 else
6744 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6745 NB_OP_MODIFY, "false");
6746
6747 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6748}
6749
6b0655a2 6750
6ffd2079 6751/* disable-connected-check */
f4b8ec07
CS
6752DEFUN_YANG (neighbor_disable_connected_check,
6753 neighbor_disable_connected_check_cmd,
6754 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6755 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6756 "one-hop away EBGP peer using loopback address\n"
6757 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6758{
d62a17ae 6759 int idx_peer = 1;
f4b8ec07
CS
6760 char base_xpath[XPATH_MAXLEN];
6761
6762 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6763 sizeof(base_xpath), NULL)
6764 < 0)
6765 return CMD_WARNING_CONFIG_FAILED;
6766
6767 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6768 NB_OP_MODIFY, "true");
6769
6770 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6771}
6772
f4b8ec07
CS
6773DEFUN_YANG (no_neighbor_disable_connected_check,
6774 no_neighbor_disable_connected_check_cmd,
6775 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6776 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6777 "one-hop away EBGP peer using loopback address\n"
6778 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6779{
d62a17ae 6780 int idx_peer = 2;
f4b8ec07
CS
6781 char base_xpath[XPATH_MAXLEN];
6782
6783 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6784 sizeof(base_xpath), NULL)
6785 < 0)
6786 return CMD_WARNING_CONFIG_FAILED;
6787
6788 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6789 NB_OP_MODIFY, "false");
6790
6791 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6792}
6793
47cbc09b
PM
6794
6795/* enforce-first-as */
f4b8ec07
CS
6796DEFUN_YANG (neighbor_enforce_first_as,
6797 neighbor_enforce_first_as_cmd,
6798 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6800 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6801{
6802 int idx_peer = 1;
f4b8ec07 6803 char base_xpath[XPATH_MAXLEN];
47cbc09b 6804
f4b8ec07
CS
6805 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6806 sizeof(base_xpath), NULL)
6807 < 0)
6808 return CMD_WARNING_CONFIG_FAILED;
6809
6810 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6811
6812 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6813}
6814
f4b8ec07
CS
6815DEFUN_YANG (no_neighbor_enforce_first_as,
6816 no_neighbor_enforce_first_as_cmd,
6817 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6818 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6819 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6820{
6821 int idx_peer = 2;
f4b8ec07 6822 char base_xpath[XPATH_MAXLEN];
47cbc09b 6823
f4b8ec07
CS
6824 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6825 sizeof(base_xpath), NULL)
6826 < 0)
6827 return CMD_WARNING_CONFIG_FAILED;
6828
6829 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6830
6831 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6832}
6833
f4b8ec07
CS
6834static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6835 char *base_xpath, int xpath_len,
6836 char *xpath)
6837{
6838 union sockunion su;
6839 char num_xpath[XPATH_MAXLEN];
6840 char unnbr_xpath[XPATH_MAXLEN];
6841 char prgrp_xpath[XPATH_MAXLEN];
6842
6843 if (str2sockunion(peer_str, &su) == 0) {
6844 snprintf(num_xpath, sizeof(num_xpath),
6845 "/neighbors/neighbor[remote-address='%s']", peer_str);
6846 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6847 VTY_CURR_XPATH, num_xpath)) {
6848 snprintf(base_xpath, xpath_len,
6849 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6850 xpath ? xpath : "");
6851 } else {
6852 vty_out(vty,
6853 "%% Specify remote-as or peer-group commands first\n");
6854 return -1;
6855 }
6856
6857 } else {
6858 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6859 "/neighbors/unnumbered-neighbor[interface='%s']",
6860 peer_str);
6861
6862 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6863 "/peer-groups/peer-group[peer-group-name='%s']",
6864 peer_str);
6865
6866 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6867 VTY_CURR_XPATH, unnbr_xpath)) {
6868 snprintf(base_xpath, xpath_len,
6869 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6870 xpath ? xpath : "");
6871 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6872 "%s%s", VTY_CURR_XPATH,
6873 prgrp_xpath)) {
6874 snprintf(base_xpath, xpath_len,
6875 FRR_BGP_PEER_GROUP_XPATH, peer_str,
6876 xpath ? xpath : "");
6877 } else {
6878 vty_out(vty,
6879 "%% Create the peer-group or interface first\n");
6880 return -1;
6881 }
6882 }
6883
6884 return 0;
6885}
47cbc09b 6886
f4b8ec07
CS
6887DEFUN_YANG (neighbor_description,
6888 neighbor_description_cmd,
6889 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6891 "Neighbor specific description\n"
6892 "Up to 80 characters describing this neighbor\n")
718e3744 6893{
d62a17ae 6894 int idx_peer = 1;
6895 int idx_line = 3;
f4b8ec07
CS
6896 int ret;
6897 char base_xpath[XPATH_MAXLEN];
d62a17ae 6898 char *str;
718e3744 6899
f4b8ec07
CS
6900 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6901 sizeof(base_xpath), NULL)
6902 < 0)
d62a17ae 6903 return CMD_WARNING_CONFIG_FAILED;
718e3744 6904
d62a17ae 6905 str = argv_concat(argv, argc, idx_line);
718e3744 6906
f4b8ec07
CS
6907 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
6908
6909 ret = nb_cli_apply_changes(vty, base_xpath);
718e3744 6910
d62a17ae 6911 XFREE(MTYPE_TMP, str);
718e3744 6912
f4b8ec07 6913 return ret;
718e3744 6914}
6915
f4b8ec07
CS
6916DEFUN_YANG (no_neighbor_description,
6917 no_neighbor_description_cmd,
6918 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6919 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6920 "Neighbor specific description\n")
718e3744 6921{
d62a17ae 6922 int idx_peer = 2;
f4b8ec07
CS
6923 char base_xpath[XPATH_MAXLEN];
6924
6925 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6926 sizeof(base_xpath), NULL)
6927 < 0)
d62a17ae 6928 return CMD_WARNING_CONFIG_FAILED;
718e3744 6929
f4b8ec07 6930 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
718e3744 6931
f4b8ec07 6932 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6933}
6934
232c75cd 6935ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6936 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6937 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6938 "Neighbor specific description\n"
6939 "Up to 80 characters describing this neighbor\n")
6b0655a2 6940
d62a17ae 6941#define BGP_UPDATE_SOURCE_HELP_STR \
6942 "IPv4 address\n" \
6943 "IPv6 address\n" \
6944 "Interface name (requires zebra to be running)\n"
369688c0 6945
f4b8ec07
CS
6946DEFUN_YANG (neighbor_update_source,
6947 neighbor_update_source_cmd,
6948 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6950 "Source of routing updates\n"
6951 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6952{
d62a17ae 6953 int idx_peer = 1;
6954 int idx_peer_2 = 3;
f4b8ec07
CS
6955 union sockunion su;
6956 char base_xpath[XPATH_MAXLEN];
6957
6958 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6959 sizeof(base_xpath), NULL)
6960 < 0)
6961 return CMD_WARNING_CONFIG_FAILED;
6962
f4b8ec07
CS
6963 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
6964 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
d62a17ae 6965 argv[idx_peer_2]->arg);
f4b8ec07
CS
6966 else
6967 nb_cli_enqueue_change(vty, "./update-source/interface",
6968 NB_OP_MODIFY, argv[idx_peer_2]->arg);
6969
6970 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6971}
6972
f4b8ec07
CS
6973DEFUN_YANG (no_neighbor_update_source,
6974 no_neighbor_update_source_cmd,
6975 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6976 NO_STR NEIGHBOR_STR
6977 NEIGHBOR_ADDR_STR2
6978 "Source of routing updates\n"
6979 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6980{
d62a17ae 6981 int idx_peer = 2;
f4b8ec07 6982 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
6983
6984 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6985 sizeof(base_xpath), NULL)
6986 < 0)
6987 return CMD_WARNING_CONFIG_FAILED;
6988
555c8ab7
CS
6989 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
6990 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
6991 NULL);
f4b8ec07
CS
6992
6993 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6994}
6b0655a2 6995
d62a17ae 6996static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6997 afi_t afi, safi_t safi,
6998 const char *rmap, int set)
718e3744 6999{
d62a17ae 7000 int ret;
7001 struct peer *peer;
80912664 7002 struct route_map *route_map = NULL;
718e3744 7003
d62a17ae 7004 peer = peer_and_group_lookup_vty(vty, peer_str);
7005 if (!peer)
7006 return CMD_WARNING_CONFIG_FAILED;
718e3744 7007
1de27621 7008 if (set) {
80912664
DS
7009 if (rmap)
7010 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7011 ret = peer_default_originate_set(peer, afi, safi,
7012 rmap, route_map);
7013 } else
d62a17ae 7014 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7015
d62a17ae 7016 return bgp_vty_return(vty, ret);
718e3744 7017}
7018
7019/* neighbor default-originate. */
7020DEFUN (neighbor_default_originate,
7021 neighbor_default_originate_cmd,
9ccf14f7 7022 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7023 NEIGHBOR_STR
7024 NEIGHBOR_ADDR_STR2
7025 "Originate default route to this neighbor\n")
7026{
d62a17ae 7027 int idx_peer = 1;
7028 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7029 bgp_node_afi(vty),
7030 bgp_node_safi(vty), NULL, 1);
718e3744 7031}
7032
d62a17ae 7033ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7034 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7035 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7036 "Originate default route to this neighbor\n")
596c17ba 7037
718e3744 7038DEFUN (neighbor_default_originate_rmap,
7039 neighbor_default_originate_rmap_cmd,
9ccf14f7 7040 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 7041 NEIGHBOR_STR
7042 NEIGHBOR_ADDR_STR2
7043 "Originate default route to this neighbor\n"
7044 "Route-map to specify criteria to originate default\n"
7045 "route-map name\n")
7046{
d62a17ae 7047 int idx_peer = 1;
7048 int idx_word = 4;
7049 return peer_default_originate_set_vty(
7050 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7051 argv[idx_word]->arg, 1);
718e3744 7052}
7053
d62a17ae 7054ALIAS_HIDDEN(
7055 neighbor_default_originate_rmap,
7056 neighbor_default_originate_rmap_hidden_cmd,
7057 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7058 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7059 "Originate default route to this neighbor\n"
7060 "Route-map to specify criteria to originate default\n"
7061 "route-map name\n")
596c17ba 7062
718e3744 7063DEFUN (no_neighbor_default_originate,
7064 no_neighbor_default_originate_cmd,
a636c635 7065 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 7066 NO_STR
7067 NEIGHBOR_STR
7068 NEIGHBOR_ADDR_STR2
a636c635
DW
7069 "Originate default route to this neighbor\n"
7070 "Route-map to specify criteria to originate default\n"
7071 "route-map name\n")
718e3744 7072{
d62a17ae 7073 int idx_peer = 2;
7074 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7075 bgp_node_afi(vty),
7076 bgp_node_safi(vty), NULL, 0);
718e3744 7077}
7078
d62a17ae 7079ALIAS_HIDDEN(
7080 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7081 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7082 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7083 "Originate default route to this neighbor\n"
7084 "Route-map to specify criteria to originate default\n"
7085 "route-map name\n")
596c17ba 7086
6b0655a2 7087
f418446b 7088/* Set specified peer's BGP port. */
f4b8ec07
CS
7089DEFUN_YANG (neighbor_port,
7090 neighbor_port_cmd,
7091 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7092 NEIGHBOR_STR
7093 NEIGHBOR_ADDR_STR
7094 "Neighbor's BGP port\n"
7095 "TCP port number\n")
718e3744 7096{
d62a17ae 7097 int idx_ip = 1;
7098 int idx_number = 3;
f4b8ec07 7099 char base_xpath[XPATH_MAXLEN];
718e3744 7100
f4b8ec07
CS
7101 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7102 argv[idx_ip]->arg, "");
718e3744 7103
f4b8ec07
CS
7104 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7105 argv[idx_number]->arg);
7106
7107 return nb_cli_apply_changes(vty, base_xpath);
7108}
6b0655a2 7109
f4b8ec07
CS
7110DEFUN_YANG (no_neighbor_port,
7111 no_neighbor_port_cmd,
7112 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7113 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7114 "Neighbor's BGP port\n"
7115 "TCP port number\n")
718e3744 7116{
f4b8ec07
CS
7117 int idx_ip = 2;
7118 char base_xpath[XPATH_MAXLEN];
718e3744 7119
f4b8ec07
CS
7120 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7121 argv[idx_ip]->arg, "");
718e3744 7122
f4b8ec07 7123 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
718e3744 7124
f4b8ec07 7125 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7126}
7127
f4b8ec07
CS
7128DEFUN_YANG (neighbor_weight,
7129 neighbor_weight_cmd,
7130 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7132 "Set default weight for routes from this neighbor\n"
7133 "default weight\n")
718e3744 7134{
f4b8ec07
CS
7135 int idx_peer = 1;
7136 int idx_number = 3;
7137 char base_xpath[XPATH_MAXLEN];
7138 char af_xpath[XPATH_MAXLEN];
7139 char attr_xpath[XPATH_MAXLEN];
7140 afi_t afi = bgp_node_afi(vty);
7141 safi_t safi = bgp_node_safi(vty);
718e3744 7142
f4b8ec07
CS
7143 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7144 yang_afi_safi_value2identity(afi, safi));
7145
7146 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7147 sizeof(base_xpath), af_xpath)
7148 < 0)
d62a17ae 7149 return CMD_WARNING_CONFIG_FAILED;
718e3744 7150
f4b8ec07
CS
7151 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7152 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7153
f4b8ec07
CS
7154 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7155 argv[idx_number]->arg);
7156
7157 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7158}
7159
d62a17ae 7160ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7161 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7162 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7163 "Set default weight for routes from this neighbor\n"
7164 "default weight\n")
596c17ba 7165
f4b8ec07
CS
7166DEFUN_YANG (no_neighbor_weight,
7167 no_neighbor_weight_cmd,
7168 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7169 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7170 "Set default weight for routes from this neighbor\n"
7171 "default weight\n")
718e3744 7172{
d62a17ae 7173 int idx_peer = 2;
f4b8ec07
CS
7174 char base_xpath[XPATH_MAXLEN];
7175 char af_xpath[XPATH_MAXLEN];
7176 char attr_xpath[XPATH_MAXLEN];
7177 afi_t afi = bgp_node_afi(vty);
7178 safi_t safi = bgp_node_safi(vty);
7179
7180 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7181 yang_afi_safi_value2identity(afi, safi));
7182
7183 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7184 sizeof(base_xpath), af_xpath)
7185 < 0)
7186 return CMD_WARNING_CONFIG_FAILED;
7187
7188 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7189 bgp_afi_safi_get_container_str(afi, safi));
7190
7191 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7192
7193 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7194}
7195
d62a17ae 7196ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7197 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7198 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7199 "Set default weight for routes from this neighbor\n"
7200 "default weight\n")
596c17ba 7201
6b0655a2 7202
718e3744 7203/* Override capability negotiation. */
8611c7f3
CS
7204DEFUN_YANG (neighbor_override_capability,
7205 neighbor_override_capability_cmd,
7206 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7207 NEIGHBOR_STR
7208 NEIGHBOR_ADDR_STR2
7209 "Override capability negotiation result\n")
718e3744 7210{
d62a17ae 7211 int idx_peer = 1;
8611c7f3
CS
7212 char base_xpath[XPATH_MAXLEN];
7213
7214 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7215 sizeof(base_xpath), NULL)
7216 < 0)
7217 return CMD_WARNING_CONFIG_FAILED;
7218
7219 nb_cli_enqueue_change(
7220 vty, "./capability-options/override-capability",
7221 NB_OP_MODIFY, "true");
7222
7223 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7224}
7225
8611c7f3
CS
7226DEFUN_YANG (no_neighbor_override_capability,
7227 no_neighbor_override_capability_cmd,
7228 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7229 NO_STR
7230 NEIGHBOR_STR
7231 NEIGHBOR_ADDR_STR2
7232 "Override capability negotiation result\n")
718e3744 7233{
d62a17ae 7234 int idx_peer = 2;
8611c7f3
CS
7235 char base_xpath[XPATH_MAXLEN];
7236
7237 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7238 sizeof(base_xpath), NULL)
7239 < 0)
7240 return CMD_WARNING_CONFIG_FAILED;
7241
7242 nb_cli_enqueue_change(
7243 vty, "./capability-options/override-capability",
7244 NB_OP_MODIFY, "false");
7245
7246 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7247}
6b0655a2 7248
8611c7f3
CS
7249DEFUN_YANG (neighbor_strict_capability,
7250 neighbor_strict_capability_cmd,
7251 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7252 NEIGHBOR_STR
7253 NEIGHBOR_ADDR_STR2
7254 "Strict capability negotiation match\n")
718e3744 7255{
9fb964de 7256 int idx_peer = 1;
8611c7f3 7257 char base_xpath[XPATH_MAXLEN];
9fb964de 7258
8611c7f3
CS
7259 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7260 sizeof(base_xpath), NULL)
7261 < 0)
7262 return CMD_WARNING_CONFIG_FAILED;
7263
7264 nb_cli_enqueue_change(
7265 vty, "./capability-options/strict-capability",
7266 NB_OP_MODIFY, "true");
7267
7268 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7269}
7270
8611c7f3
CS
7271DEFUN_YANG (no_neighbor_strict_capability,
7272 no_neighbor_strict_capability_cmd,
7273 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7274 NO_STR
7275 NEIGHBOR_STR
7276 NEIGHBOR_ADDR_STR2
7277 "Strict capability negotiation match\n")
718e3744 7278{
9fb964de 7279 int idx_peer = 2;
8611c7f3 7280 char base_xpath[XPATH_MAXLEN];
9fb964de 7281
8611c7f3
CS
7282 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7283 sizeof(base_xpath), NULL)
7284 < 0)
7285 return CMD_WARNING_CONFIG_FAILED;
7286
7287 nb_cli_enqueue_change(
7288 vty, "./capability-options/strict-capability",
7289 NB_OP_MODIFY, "false");
7290
7291 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7292}
6b0655a2 7293
f4b8ec07
CS
7294DEFUN_YANG (neighbor_timers,
7295 neighbor_timers_cmd,
7296 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7297 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7298 "BGP per neighbor timers\n"
7299 "Keepalive interval\n"
7300 "Holdtime\n")
718e3744 7301{
f4b8ec07
CS
7302 int idx_peer = 1;
7303 int idx_number = 3;
7304 int idx_number_2 = 4;
7305 char base_xpath[XPATH_MAXLEN];
718e3744 7306
f4b8ec07
CS
7307 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7308 sizeof(base_xpath), NULL)
7309 < 0)
d62a17ae 7310 return CMD_WARNING_CONFIG_FAILED;
718e3744 7311
f4b8ec07
CS
7312 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7313 argv[idx_number]->arg);
718e3744 7314
f4b8ec07
CS
7315 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7316 argv[idx_number_2]->arg);
718e3744 7317
f4b8ec07 7318 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7319}
6b0655a2 7320
f4b8ec07
CS
7321DEFUN_YANG (no_neighbor_timers,
7322 no_neighbor_timers_cmd,
7323 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7324 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7325 "BGP per neighbor timers\n"
7326 "Keepalive interval\n"
7327 "Holdtime\n")
718e3744 7328{
f4b8ec07
CS
7329 int idx_peer = 2;
7330 char base_xpath[XPATH_MAXLEN];
718e3744 7331
f4b8ec07
CS
7332 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7333 sizeof(base_xpath), NULL)
7334 < 0)
d62a17ae 7335 return CMD_WARNING_CONFIG_FAILED;
718e3744 7336
f4b8ec07 7337 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
718e3744 7338
f4b8ec07 7339 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
718e3744 7340
f4b8ec07 7341 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7342}
6b0655a2 7343
f4b8ec07
CS
7344DEFUN_YANG (neighbor_timers_connect,
7345 neighbor_timers_connect_cmd,
7346 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7347 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7348 "BGP per neighbor timers\n"
7349 "BGP connect timer\n"
7350 "Connect timer\n")
718e3744 7351{
f4b8ec07
CS
7352 int idx_peer = 1;
7353 int idx_number = 4;
7354 char base_xpath[XPATH_MAXLEN];
718e3744 7355
f4b8ec07
CS
7356 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7357 sizeof(base_xpath), NULL)
7358 < 0)
d62a17ae 7359 return CMD_WARNING_CONFIG_FAILED;
718e3744 7360
f4b8ec07
CS
7361 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7362 argv[idx_number]->arg);
718e3744 7363
f4b8ec07 7364 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7365}
7366
f4b8ec07
CS
7367DEFUN_YANG (no_neighbor_timers_connect,
7368 no_neighbor_timers_connect_cmd,
7369 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7370 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7371 "BGP per neighbor timers\n"
7372 "BGP connect timer\n"
7373 "Connect timer\n")
718e3744 7374{
f4b8ec07
CS
7375 int idx_peer = 2;
7376 char base_xpath[XPATH_MAXLEN];
718e3744 7377
f4b8ec07
CS
7378 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7379 sizeof(base_xpath), NULL)
7380 < 0)
d62a17ae 7381 return CMD_WARNING_CONFIG_FAILED;
718e3744 7382
f4b8ec07
CS
7383 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7384 NULL);
718e3744 7385
f4b8ec07 7386 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7387}
7388
d43114f3
DS
7389DEFPY (neighbor_timers_delayopen,
7390 neighbor_timers_delayopen_cmd,
7391 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7392 NEIGHBOR_STR
7393 NEIGHBOR_ADDR_STR2
7394 "BGP per neighbor timers\n"
7395 "RFC 4271 DelayOpenTimer\n"
7396 "DelayOpenTime timer interval\n")
7397{
7398 struct peer *peer;
7399
7400 peer = peer_and_group_lookup_vty(vty, neighbor);
7401 if (!peer)
7402 return CMD_WARNING_CONFIG_FAILED;
7403
7404 if (!interval) {
7405 if (peer_timers_delayopen_unset(peer))
7406 return CMD_WARNING_CONFIG_FAILED;
7407 } else {
7408 if (peer_timers_delayopen_set(peer, interval))
7409 return CMD_WARNING_CONFIG_FAILED;
7410 }
7411
7412 return CMD_SUCCESS;
7413}
7414
7415DEFPY (no_neighbor_timers_delayopen,
7416 no_neighbor_timers_delayopen_cmd,
7417 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7418 NO_STR
7419 NEIGHBOR_STR
7420 NEIGHBOR_ADDR_STR2
7421 "BGP per neighbor timers\n"
7422 "RFC 4271 DelayOpenTimer\n"
7423 "DelayOpenTime timer interval\n")
7424{
7425 struct peer *peer;
7426
7427 peer = peer_and_group_lookup_vty(vty, neighbor);
7428 if (!peer)
7429 return CMD_WARNING_CONFIG_FAILED;
7430
7431 if (peer_timers_delayopen_unset(peer))
7432 return CMD_WARNING_CONFIG_FAILED;
7433
7434 return CMD_SUCCESS;
7435}
7436
f4b8ec07
CS
7437DEFUN_YANG (neighbor_advertise_interval,
7438 neighbor_advertise_interval_cmd,
7439 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7440 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7441 "Minimum interval between sending BGP routing updates\n"
7442 "time in seconds\n")
718e3744 7443{
d62a17ae 7444 int idx_peer = 1;
f4b8ec07
CS
7445 int idx_number = 3;
7446 char base_xpath[XPATH_MAXLEN];
718e3744 7447
f4b8ec07
CS
7448 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7449 sizeof(base_xpath), NULL)
7450 < 0)
d62a17ae 7451 return CMD_WARNING_CONFIG_FAILED;
718e3744 7452
f4b8ec07
CS
7453 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7454 argv[idx_number]->arg);
718e3744 7455
f4b8ec07 7456 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7457}
7458
f4b8ec07
CS
7459DEFUN_YANG (no_neighbor_advertise_interval,
7460 no_neighbor_advertise_interval_cmd,
7461 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7462 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7463 "Minimum interval between sending BGP routing updates\n"
7464 "time in seconds\n")
718e3744 7465{
d62a17ae 7466 int idx_peer = 2;
f4b8ec07
CS
7467 char base_xpath[XPATH_MAXLEN];
7468
7469 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7470 sizeof(base_xpath), NULL)
7471 < 0)
7472 return CMD_WARNING_CONFIG_FAILED;
7473
7474 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7475 NULL);
7476
7477 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7478}
7479
6b0655a2 7480
518f0eb1
DS
7481/* Time to wait before processing route-map updates */
7482DEFUN (bgp_set_route_map_delay_timer,
7483 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7484 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7485 SET_STR
7486 "BGP route-map delay timer\n"
7487 "Time in secs to wait before processing route-map changes\n"
f414725f 7488 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7489{
d62a17ae 7490 int idx_number = 3;
d7c0a89a 7491 uint32_t rmap_delay_timer;
d62a17ae 7492
7493 if (argv[idx_number]->arg) {
7494 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7495 bm->rmap_update_timer = rmap_delay_timer;
7496
7497 /* if the dynamic update handling is being disabled, and a timer
7498 * is
7499 * running, stop the timer and act as if the timer has already
7500 * fired.
7501 */
7502 if (!rmap_delay_timer && bm->t_rmap_update) {
7503 BGP_TIMER_OFF(bm->t_rmap_update);
7504 thread_execute(bm->master, bgp_route_map_update_timer,
7505 NULL, 0);
7506 }
7507 return CMD_SUCCESS;
7508 } else {
7509 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7510 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7511 }
518f0eb1
DS
7512}
7513
7514DEFUN (no_bgp_set_route_map_delay_timer,
7515 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7516 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7517 NO_STR
3a2d747c 7518 BGP_STR
518f0eb1 7519 "Default BGP route-map delay timer\n"
8334fd5a
DW
7520 "Reset to default time to wait for processing route-map changes\n"
7521 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7522{
518f0eb1 7523
d62a17ae 7524 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7525
d62a17ae 7526 return CMD_SUCCESS;
518f0eb1
DS
7527}
7528
f4b8ec07
CS
7529DEFUN_YANG (neighbor_interface,
7530 neighbor_interface_cmd,
7531 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7532 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7533 "Interface\n"
7534 "Interface name\n")
718e3744 7535{
f4b8ec07
CS
7536 int idx_ip = 1;
7537 int idx_word = 3;
7538 char base_xpath[XPATH_MAXLEN];
718e3744 7539
f4b8ec07
CS
7540 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7541 argv[idx_ip]->arg, "");
718e3744 7542
f4b8ec07
CS
7543 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7544 argv[idx_word]->arg);
718e3744 7545
f4b8ec07 7546 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7547}
7548
f4b8ec07
CS
7549DEFUN_YANG (no_neighbor_interface,
7550 no_neighbor_interface_cmd,
7551 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7552 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7553 "Interface\n"
7554 "Interface name\n")
718e3744 7555{
d62a17ae 7556 int idx_peer = 2;
f4b8ec07
CS
7557 char base_xpath[XPATH_MAXLEN];
7558
7559 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7560 argv[idx_peer]->arg, "");
7561
7562 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7563
7564 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7565}
6b0655a2 7566
718e3744 7567DEFUN (neighbor_distribute_list,
7568 neighbor_distribute_list_cmd,
9ccf14f7 7569 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7570 NEIGHBOR_STR
7571 NEIGHBOR_ADDR_STR2
7572 "Filter updates to/from this neighbor\n"
7573 "IP access-list number\n"
7574 "IP access-list number (expanded range)\n"
7575 "IP Access-list name\n"
7576 "Filter incoming updates\n"
7577 "Filter outgoing updates\n")
7578{
d62a17ae 7579 int idx_peer = 1;
7580 int idx_acl = 3;
7581 int direct, ret;
7582 struct peer *peer;
a8206004 7583
d62a17ae 7584 const char *pstr = argv[idx_peer]->arg;
7585 const char *acl = argv[idx_acl]->arg;
7586 const char *inout = argv[argc - 1]->text;
a8206004 7587
d62a17ae 7588 peer = peer_and_group_lookup_vty(vty, pstr);
7589 if (!peer)
7590 return CMD_WARNING_CONFIG_FAILED;
a8206004 7591
d62a17ae 7592 /* Check filter direction. */
7593 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7594 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7595 direct, acl);
a8206004 7596
d62a17ae 7597 return bgp_vty_return(vty, ret);
718e3744 7598}
7599
d62a17ae 7600ALIAS_HIDDEN(
7601 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7602 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7603 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7604 "Filter updates to/from this neighbor\n"
7605 "IP access-list number\n"
7606 "IP access-list number (expanded range)\n"
7607 "IP Access-list name\n"
7608 "Filter incoming updates\n"
7609 "Filter outgoing updates\n")
596c17ba 7610
718e3744 7611DEFUN (no_neighbor_distribute_list,
7612 no_neighbor_distribute_list_cmd,
9ccf14f7 7613 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7614 NO_STR
7615 NEIGHBOR_STR
7616 NEIGHBOR_ADDR_STR2
7617 "Filter updates to/from this neighbor\n"
7618 "IP access-list number\n"
7619 "IP access-list number (expanded range)\n"
7620 "IP Access-list name\n"
7621 "Filter incoming updates\n"
7622 "Filter outgoing updates\n")
7623{
d62a17ae 7624 int idx_peer = 2;
7625 int direct, ret;
7626 struct peer *peer;
a8206004 7627
d62a17ae 7628 const char *pstr = argv[idx_peer]->arg;
7629 const char *inout = argv[argc - 1]->text;
a8206004 7630
d62a17ae 7631 peer = peer_and_group_lookup_vty(vty, pstr);
7632 if (!peer)
7633 return CMD_WARNING_CONFIG_FAILED;
a8206004 7634
d62a17ae 7635 /* Check filter direction. */
7636 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7637 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7638 direct);
a8206004 7639
d62a17ae 7640 return bgp_vty_return(vty, ret);
718e3744 7641}
6b0655a2 7642
d62a17ae 7643ALIAS_HIDDEN(
7644 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7645 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7646 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7647 "Filter updates to/from this neighbor\n"
7648 "IP access-list number\n"
7649 "IP access-list number (expanded range)\n"
7650 "IP Access-list name\n"
7651 "Filter incoming updates\n"
7652 "Filter outgoing updates\n")
596c17ba 7653
718e3744 7654/* Set prefix list to the peer. */
d62a17ae 7655static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7656 afi_t afi, safi_t safi,
7657 const char *name_str,
7658 const char *direct_str)
718e3744 7659{
d62a17ae 7660 int ret;
d62a17ae 7661 int direct = FILTER_IN;
cf9ac8bf 7662 struct peer *peer;
718e3744 7663
d62a17ae 7664 peer = peer_and_group_lookup_vty(vty, ip_str);
7665 if (!peer)
7666 return CMD_WARNING_CONFIG_FAILED;
718e3744 7667
d62a17ae 7668 /* Check filter direction. */
7669 if (strncmp(direct_str, "i", 1) == 0)
7670 direct = FILTER_IN;
7671 else if (strncmp(direct_str, "o", 1) == 0)
7672 direct = FILTER_OUT;
718e3744 7673
d62a17ae 7674 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7675
d62a17ae 7676 return bgp_vty_return(vty, ret);
718e3744 7677}
7678
d62a17ae 7679static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7680 afi_t afi, safi_t safi,
7681 const char *direct_str)
718e3744 7682{
d62a17ae 7683 int ret;
7684 struct peer *peer;
7685 int direct = FILTER_IN;
718e3744 7686
d62a17ae 7687 peer = peer_and_group_lookup_vty(vty, ip_str);
7688 if (!peer)
7689 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7690
d62a17ae 7691 /* Check filter direction. */
7692 if (strncmp(direct_str, "i", 1) == 0)
7693 direct = FILTER_IN;
7694 else if (strncmp(direct_str, "o", 1) == 0)
7695 direct = FILTER_OUT;
718e3744 7696
d62a17ae 7697 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 7698
d62a17ae 7699 return bgp_vty_return(vty, ret);
718e3744 7700}
7701
7702DEFUN (neighbor_prefix_list,
7703 neighbor_prefix_list_cmd,
9ccf14f7 7704 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 7705 NEIGHBOR_STR
7706 NEIGHBOR_ADDR_STR2
7707 "Filter updates to/from this neighbor\n"
7708 "Name of a prefix list\n"
7709 "Filter incoming updates\n"
7710 "Filter outgoing updates\n")
7711{
d62a17ae 7712 int idx_peer = 1;
7713 int idx_word = 3;
7714 int idx_in_out = 4;
7715 return peer_prefix_list_set_vty(
7716 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7717 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7718}
7719
d62a17ae 7720ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7721 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7722 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7723 "Filter updates to/from this neighbor\n"
7724 "Name of a prefix list\n"
7725 "Filter incoming updates\n"
7726 "Filter outgoing updates\n")
596c17ba 7727
718e3744 7728DEFUN (no_neighbor_prefix_list,
7729 no_neighbor_prefix_list_cmd,
9ccf14f7 7730 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 7731 NO_STR
7732 NEIGHBOR_STR
7733 NEIGHBOR_ADDR_STR2
7734 "Filter updates to/from this neighbor\n"
7735 "Name of a prefix list\n"
7736 "Filter incoming updates\n"
7737 "Filter outgoing updates\n")
7738{
d62a17ae 7739 int idx_peer = 2;
7740 int idx_in_out = 5;
7741 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7742 bgp_node_afi(vty), bgp_node_safi(vty),
7743 argv[idx_in_out]->arg);
718e3744 7744}
6b0655a2 7745
d62a17ae 7746ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7747 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7748 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7749 "Filter updates to/from this neighbor\n"
7750 "Name of a prefix list\n"
7751 "Filter incoming updates\n"
7752 "Filter outgoing updates\n")
596c17ba 7753
d62a17ae 7754static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7755 safi_t safi, const char *name_str,
7756 const char *direct_str)
718e3744 7757{
d62a17ae 7758 int ret;
7759 struct peer *peer;
7760 int direct = FILTER_IN;
718e3744 7761
d62a17ae 7762 peer = peer_and_group_lookup_vty(vty, ip_str);
7763 if (!peer)
7764 return CMD_WARNING_CONFIG_FAILED;
718e3744 7765
d62a17ae 7766 /* Check filter direction. */
7767 if (strncmp(direct_str, "i", 1) == 0)
7768 direct = FILTER_IN;
7769 else if (strncmp(direct_str, "o", 1) == 0)
7770 direct = FILTER_OUT;
718e3744 7771
d62a17ae 7772 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7773
d62a17ae 7774 return bgp_vty_return(vty, ret);
718e3744 7775}
7776
d62a17ae 7777static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7778 safi_t safi, const char *direct_str)
718e3744 7779{
d62a17ae 7780 int ret;
7781 struct peer *peer;
7782 int direct = FILTER_IN;
718e3744 7783
d62a17ae 7784 peer = peer_and_group_lookup_vty(vty, ip_str);
7785 if (!peer)
7786 return CMD_WARNING_CONFIG_FAILED;
718e3744 7787
d62a17ae 7788 /* Check filter direction. */
7789 if (strncmp(direct_str, "i", 1) == 0)
7790 direct = FILTER_IN;
7791 else if (strncmp(direct_str, "o", 1) == 0)
7792 direct = FILTER_OUT;
718e3744 7793
d62a17ae 7794 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7795
d62a17ae 7796 return bgp_vty_return(vty, ret);
718e3744 7797}
7798
7799DEFUN (neighbor_filter_list,
7800 neighbor_filter_list_cmd,
9ccf14f7 7801 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7802 NEIGHBOR_STR
7803 NEIGHBOR_ADDR_STR2
7804 "Establish BGP filters\n"
7805 "AS path access-list name\n"
7806 "Filter incoming routes\n"
7807 "Filter outgoing routes\n")
7808{
d62a17ae 7809 int idx_peer = 1;
7810 int idx_word = 3;
7811 int idx_in_out = 4;
7812 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7813 bgp_node_safi(vty), argv[idx_word]->arg,
7814 argv[idx_in_out]->arg);
718e3744 7815}
7816
d62a17ae 7817ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7818 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7819 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7820 "Establish BGP filters\n"
7821 "AS path access-list name\n"
7822 "Filter incoming routes\n"
7823 "Filter outgoing routes\n")
596c17ba 7824
718e3744 7825DEFUN (no_neighbor_filter_list,
7826 no_neighbor_filter_list_cmd,
9ccf14f7 7827 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7828 NO_STR
7829 NEIGHBOR_STR
7830 NEIGHBOR_ADDR_STR2
7831 "Establish BGP filters\n"
7832 "AS path access-list name\n"
7833 "Filter incoming routes\n"
7834 "Filter outgoing routes\n")
7835{
d62a17ae 7836 int idx_peer = 2;
7837 int idx_in_out = 5;
7838 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7839 bgp_node_afi(vty), bgp_node_safi(vty),
7840 argv[idx_in_out]->arg);
718e3744 7841}
6b0655a2 7842
d62a17ae 7843ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7844 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7845 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7846 "Establish BGP filters\n"
7847 "AS path access-list name\n"
7848 "Filter incoming routes\n"
7849 "Filter outgoing routes\n")
596c17ba 7850
7f7940e6
MK
7851/* Set advertise-map to the peer. */
7852static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7853 afi_t afi, safi_t safi,
cf2ad4d8
MK
7854 const char *advertise_str,
7855 const char *condition_str, bool condition,
7856 bool set)
7f7940e6
MK
7857{
7858 int ret = CMD_WARNING_CONFIG_FAILED;
7859 struct peer *peer;
7860 struct route_map *advertise_map;
7861 struct route_map *condition_map;
7862
7863 peer = peer_and_group_lookup_vty(vty, ip_str);
7864 if (!peer)
7865 return ret;
7866
7867 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7868 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7869
cf2ad4d8
MK
7870 if (set)
7871 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7872 advertise_map, condition_str,
7873 condition_map, condition);
7874 else
7875 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7876 advertise_map, condition_str,
7877 condition_map, condition);
7f7940e6
MK
7878
7879 return bgp_vty_return(vty, ret);
7880}
7881
cf2ad4d8 7882DEFPY (neighbor_advertise_map,
7f7940e6 7883 neighbor_advertise_map_cmd,
52b84062 7884 "[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 7885 NO_STR
7f7940e6
MK
7886 NEIGHBOR_STR
7887 NEIGHBOR_ADDR_STR2
7888 "Route-map to conditionally advertise routes\n"
7889 "Name of advertise map\n"
7890 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7891 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7892 "Name of the exist or non exist map\n")
7f7940e6 7893{
7f7940e6
MK
7894 bool condition = CONDITION_EXIST;
7895
52b84062 7896 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7897 condition = CONDITION_NON_EXIST;
7898
52b84062
MK
7899 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7900 bgp_node_safi(vty), advertise_str,
7901 condition_str, condition, !no);
7f7940e6
MK
7902}
7903
7904ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7905 "[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
7906 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7907 "Route-map to conditionally advertise routes\n"
7908 "Name of advertise map\n"
7909 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7910 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7911 "Name of the exist or non exist map\n")
7f7940e6 7912
718e3744 7913/* Set route-map to the peer. */
d62a17ae 7914static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7915 afi_t afi, safi_t safi, const char *name_str,
7916 const char *direct_str)
718e3744 7917{
d62a17ae 7918 int ret;
7919 struct peer *peer;
7920 int direct = RMAP_IN;
1de27621 7921 struct route_map *route_map;
718e3744 7922
d62a17ae 7923 peer = peer_and_group_lookup_vty(vty, ip_str);
7924 if (!peer)
7925 return CMD_WARNING_CONFIG_FAILED;
718e3744 7926
d62a17ae 7927 /* Check filter direction. */
7928 if (strncmp(direct_str, "in", 2) == 0)
7929 direct = RMAP_IN;
7930 else if (strncmp(direct_str, "o", 1) == 0)
7931 direct = RMAP_OUT;
718e3744 7932
1de27621
DA
7933 route_map = route_map_lookup_warn_noexist(vty, name_str);
7934 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7935
d62a17ae 7936 return bgp_vty_return(vty, ret);
718e3744 7937}
7938
d62a17ae 7939static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7940 afi_t afi, safi_t safi,
7941 const char *direct_str)
718e3744 7942{
d62a17ae 7943 int ret;
7944 struct peer *peer;
7945 int direct = RMAP_IN;
718e3744 7946
d62a17ae 7947 peer = peer_and_group_lookup_vty(vty, ip_str);
7948 if (!peer)
7949 return CMD_WARNING_CONFIG_FAILED;
718e3744 7950
d62a17ae 7951 /* Check filter direction. */
7952 if (strncmp(direct_str, "in", 2) == 0)
7953 direct = RMAP_IN;
7954 else if (strncmp(direct_str, "o", 1) == 0)
7955 direct = RMAP_OUT;
718e3744 7956
d62a17ae 7957 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 7958
d62a17ae 7959 return bgp_vty_return(vty, ret);
718e3744 7960}
7961
7962DEFUN (neighbor_route_map,
7963 neighbor_route_map_cmd,
9ccf14f7 7964 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7965 NEIGHBOR_STR
7966 NEIGHBOR_ADDR_STR2
7967 "Apply route map to neighbor\n"
7968 "Name of route map\n"
7969 "Apply map to incoming routes\n"
2a3d5731 7970 "Apply map to outbound routes\n")
718e3744 7971{
d62a17ae 7972 int idx_peer = 1;
7973 int idx_word = 3;
7974 int idx_in_out = 4;
7975 return peer_route_map_set_vty(
7976 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7977 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7978}
7979
d62a17ae 7980ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7981 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7982 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7983 "Apply route map to neighbor\n"
7984 "Name of route map\n"
7985 "Apply map to incoming routes\n"
7986 "Apply map to outbound routes\n")
596c17ba 7987
718e3744 7988DEFUN (no_neighbor_route_map,
7989 no_neighbor_route_map_cmd,
9ccf14f7 7990 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7991 NO_STR
7992 NEIGHBOR_STR
7993 NEIGHBOR_ADDR_STR2
7994 "Apply route map to neighbor\n"
7995 "Name of route map\n"
7996 "Apply map to incoming routes\n"
2a3d5731 7997 "Apply map to outbound routes\n")
718e3744 7998{
d62a17ae 7999 int idx_peer = 2;
8000 int idx_in_out = 5;
8001 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
8002 bgp_node_afi(vty), bgp_node_safi(vty),
8003 argv[idx_in_out]->arg);
718e3744 8004}
6b0655a2 8005
d62a17ae 8006ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
8007 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
8008 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8009 "Apply route map to neighbor\n"
8010 "Name of route map\n"
8011 "Apply map to incoming routes\n"
8012 "Apply map to outbound routes\n")
596c17ba 8013
718e3744 8014/* Set unsuppress-map to the peer. */
d62a17ae 8015static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8016 afi_t afi, safi_t safi,
8017 const char *name_str)
718e3744 8018{
d62a17ae 8019 int ret;
8020 struct peer *peer;
1de27621 8021 struct route_map *route_map;
718e3744 8022
d62a17ae 8023 peer = peer_and_group_lookup_vty(vty, ip_str);
8024 if (!peer)
8025 return CMD_WARNING_CONFIG_FAILED;
718e3744 8026
1de27621
DA
8027 route_map = route_map_lookup_warn_noexist(vty, name_str);
8028 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 8029
d62a17ae 8030 return bgp_vty_return(vty, ret);
718e3744 8031}
8032
8033/* Unset route-map from the peer. */
d62a17ae 8034static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8035 afi_t afi, safi_t safi)
718e3744 8036{
d62a17ae 8037 int ret;
8038 struct peer *peer;
718e3744 8039
d62a17ae 8040 peer = peer_and_group_lookup_vty(vty, ip_str);
8041 if (!peer)
8042 return CMD_WARNING_CONFIG_FAILED;
718e3744 8043
d62a17ae 8044 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8045
d62a17ae 8046 return bgp_vty_return(vty, ret);
718e3744 8047}
8048
8049DEFUN (neighbor_unsuppress_map,
8050 neighbor_unsuppress_map_cmd,
9ccf14f7 8051 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8052 NEIGHBOR_STR
8053 NEIGHBOR_ADDR_STR2
8054 "Route-map to selectively unsuppress suppressed routes\n"
8055 "Name of route map\n")
8056{
d62a17ae 8057 int idx_peer = 1;
8058 int idx_word = 3;
8059 return peer_unsuppress_map_set_vty(
8060 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8061 argv[idx_word]->arg);
718e3744 8062}
8063
d62a17ae 8064ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8065 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8066 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8067 "Route-map to selectively unsuppress suppressed routes\n"
8068 "Name of route map\n")
596c17ba 8069
718e3744 8070DEFUN (no_neighbor_unsuppress_map,
8071 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8072 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8073 NO_STR
8074 NEIGHBOR_STR
8075 NEIGHBOR_ADDR_STR2
8076 "Route-map to selectively unsuppress suppressed routes\n"
8077 "Name of route map\n")
8078{
d62a17ae 8079 int idx_peer = 2;
8080 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8081 bgp_node_afi(vty),
8082 bgp_node_safi(vty));
718e3744 8083}
6b0655a2 8084
d62a17ae 8085ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8086 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8087 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8088 "Route-map to selectively unsuppress suppressed routes\n"
8089 "Name of route map\n")
596c17ba 8090
fde246e8 8091/* Maximum number of prefix to be sent to the neighbor. */
232c75cd
CS
8092DEFUN_YANG(neighbor_maximum_prefix_out,
8093 neighbor_maximum_prefix_out_cmd,
8094 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8096 "Maximum number of prefixes to be sent to this peer\n"
8097 "Maximum no. of prefix limit\n")
fde246e8 8098{
04261dec
CS
8099 char base_xpath[XPATH_MAXLEN];
8100 char af_xpath[XPATH_MAXLEN];
8101 char attr_xpath[XPATH_MAXLEN];
fde246e8
DA
8102 int idx_peer = 1;
8103 int idx_number = 3;
fde246e8
DA
8104 afi_t afi = bgp_node_afi(vty);
8105 safi_t safi = bgp_node_safi(vty);
8106
04261dec
CS
8107 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8108 yang_afi_safi_value2identity(afi, safi));
8109 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8110 sizeof(base_xpath), af_xpath)
8111 < 0)
fde246e8
DA
8112 return CMD_WARNING_CONFIG_FAILED;
8113
04261dec
CS
8114 snprintf(attr_xpath, sizeof(attr_xpath),
8115 "/%s/prefix-limit/direction-list[direction='out']",
8116 bgp_afi_safi_get_container_str(afi, safi));
8117 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
fde246e8 8118
04261dec 8119 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
fde246e8 8120
04261dec
CS
8121 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8122 argv[idx_number]->arg);
8123
8124 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8125}
8126
232c75cd
CS
8127DEFUN_YANG(no_neighbor_maximum_prefix_out,
8128 no_neighbor_maximum_prefix_out_cmd,
8129 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8130 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8131 "Maximum number of prefixes to be sent to this peer\n")
fde246e8 8132{
04261dec
CS
8133 char base_xpath[XPATH_MAXLEN];
8134 char af_xpath[XPATH_MAXLEN];
8135 char attr_xpath[XPATH_MAXLEN];
fde246e8 8136 int idx_peer = 2;
fde246e8
DA
8137 afi_t afi = bgp_node_afi(vty);
8138 safi_t safi = bgp_node_safi(vty);
8139
04261dec
CS
8140 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8141 yang_afi_safi_value2identity(afi, safi));
8142 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8143 sizeof(base_xpath), af_xpath)
8144 < 0)
fde246e8
DA
8145 return CMD_WARNING_CONFIG_FAILED;
8146
04261dec
CS
8147 snprintf(attr_xpath, sizeof(attr_xpath),
8148 "/%s/prefix-limit/direction-list[direction='out']",
8149 bgp_afi_safi_get_container_str(afi, safi));
8150 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8151
8152 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
fde246e8 8153
04261dec 8154 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8155}
8156
9cbd06e0
DA
8157/* Maximum number of prefix configuration. Prefix count is different
8158 for each peer configuration. So this configuration can be set for
718e3744 8159 each peer configuration. */
232c75cd
CS
8160DEFUN_YANG(neighbor_maximum_prefix,
8161 neighbor_maximum_prefix_cmd,
8162 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8163 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8164 "Maximum number of prefix accept from this peer\n"
8165 "maximum no. of prefix limit\n"
8166 "Force checking all received routes not only accepted\n")
718e3744 8167{
d62a17ae 8168 int idx_peer = 1;
8169 int idx_number = 3;
9cbd06e0 8170 int idx_force = 0;
04261dec
CS
8171 char base_xpath[XPATH_MAXLEN];
8172 char af_xpath[XPATH_MAXLEN];
8173 char attr_xpath[XPATH_MAXLEN];
8174 afi_t afi = bgp_node_afi(vty);
8175 safi_t safi = bgp_node_safi(vty);
8176
8177 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8178 yang_afi_safi_value2identity(afi, safi));
8179 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8180 sizeof(base_xpath), af_xpath)
8181 < 0)
8182 return CMD_WARNING_CONFIG_FAILED;
8183
8184 snprintf(attr_xpath, sizeof(attr_xpath),
8185 "/%s/prefix-limit/direction-list[direction='in']",
8186 bgp_afi_safi_get_container_str(afi, safi));
8187 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8188
8189 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9cbd06e0 8190
04261dec
CS
8191 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8192 argv[idx_number]->arg);
9cbd06e0 8193 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8194 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8195 "true");
9cbd06e0 8196
04261dec 8197 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8198}
8199
d62a17ae 8200ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8201 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8202 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8203 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8204 "maximum no. of prefix limit\n"
8205 "Force checking all received routes not only accepted\n")
596c17ba 8206
232c75cd
CS
8207DEFUN_YANG(neighbor_maximum_prefix_threshold,
8208 neighbor_maximum_prefix_threshold_cmd,
8209 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8210 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8211 "Maximum number of prefix accept from this peer\n"
8212 "maximum no. of prefix limit\n"
8213 "Threshold value (%) at which to generate a warning msg\n"
8214 "Force checking all received routes not only accepted\n")
e0701b79 8215{
d62a17ae 8216 int idx_peer = 1;
8217 int idx_number = 3;
8218 int idx_number_2 = 4;
9cbd06e0 8219 int idx_force = 0;
04261dec
CS
8220 char base_xpath[XPATH_MAXLEN];
8221 char af_xpath[XPATH_MAXLEN];
8222 char attr_xpath[XPATH_MAXLEN];
8223 afi_t afi = bgp_node_afi(vty);
8224 safi_t safi = bgp_node_safi(vty);
8225
8226 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8227 yang_afi_safi_value2identity(afi, safi));
8228 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8229 sizeof(base_xpath), af_xpath)
8230 < 0)
8231 return CMD_WARNING_CONFIG_FAILED;
8232
8233 snprintf(attr_xpath, sizeof(attr_xpath),
8234 "/%s/prefix-limit/direction-list[direction='in']",
8235 bgp_afi_safi_get_container_str(afi, safi));
8236 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8237
8238 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8239
8240 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8241 argv[idx_number]->arg);
8242
8243 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8244 NB_OP_MODIFY, argv[idx_number_2]->arg);
9cbd06e0
DA
8245
8246 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8247 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8248 "true");
9cbd06e0 8249
04261dec 8250 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8251}
e0701b79 8252
d62a17ae 8253ALIAS_HIDDEN(
8254 neighbor_maximum_prefix_threshold,
8255 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8256 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8257 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8258 "Maximum number of prefix accept from this peer\n"
8259 "maximum no. of prefix limit\n"
9cbd06e0
DA
8260 "Threshold value (%) at which to generate a warning msg\n"
8261 "Force checking all received routes not only accepted\n")
596c17ba 8262
232c75cd
CS
8263DEFUN_YANG(neighbor_maximum_prefix_warning,
8264 neighbor_maximum_prefix_warning_cmd,
8265 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8266 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8267 "Maximum number of prefix accept from this peer\n"
8268 "maximum no. of prefix limit\n"
8269 "Only give warning message when limit is exceeded\n"
8270 "Force checking all received routes not only accepted\n")
718e3744 8271{
d62a17ae 8272 int idx_peer = 1;
8273 int idx_number = 3;
9cbd06e0 8274 int idx_force = 0;
04261dec
CS
8275 char base_xpath[XPATH_MAXLEN];
8276 char af_xpath[XPATH_MAXLEN];
8277 char attr_xpath[XPATH_MAXLEN];
8278 afi_t afi = bgp_node_afi(vty);
8279 safi_t safi = bgp_node_safi(vty);
8280
8281 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8282 yang_afi_safi_value2identity(afi, safi));
8283 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8284 sizeof(base_xpath), af_xpath)
8285 < 0)
8286 return CMD_WARNING_CONFIG_FAILED;
9cbd06e0 8287
04261dec
CS
8288 snprintf(attr_xpath, sizeof(attr_xpath),
8289 "/%s/prefix-limit/direction-list[direction='in']",
8290 bgp_afi_safi_get_container_str(afi, safi));
8291 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8292
8293 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8294
8295 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8296 argv[idx_number]->arg);
8297
8298 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8299 "true");
9cbd06e0 8300 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8301 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8302 "true");
9cbd06e0 8303
04261dec 8304 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8305}
8306
d62a17ae 8307ALIAS_HIDDEN(
8308 neighbor_maximum_prefix_warning,
8309 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8310 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8312 "Maximum number of prefix accept from this peer\n"
8313 "maximum no. of prefix limit\n"
9cbd06e0
DA
8314 "Only give warning message when limit is exceeded\n"
8315 "Force checking all received routes not only accepted\n")
596c17ba 8316
232c75cd
CS
8317DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8318 neighbor_maximum_prefix_threshold_warning_cmd,
8319 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8320 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8321 "Maximum number of prefix accept from this peer\n"
8322 "maximum no. of prefix limit\n"
8323 "Threshold value (%) at which to generate a warning msg\n"
8324 "Only give warning message when limit is exceeded\n"
8325 "Force checking all received routes not only accepted\n")
e0701b79 8326{
d62a17ae 8327 int idx_peer = 1;
8328 int idx_number = 3;
8329 int idx_number_2 = 4;
9cbd06e0 8330 int idx_force = 0;
04261dec
CS
8331 char base_xpath[XPATH_MAXLEN];
8332 char af_xpath[XPATH_MAXLEN];
8333 char attr_xpath[XPATH_MAXLEN];
8334 afi_t afi = bgp_node_afi(vty);
8335 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8336
04261dec
CS
8337 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8338 yang_afi_safi_value2identity(afi, safi));
8339 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8340 sizeof(base_xpath), af_xpath)
8341 < 0)
8342 return CMD_WARNING_CONFIG_FAILED;
8343
8344 snprintf(attr_xpath, sizeof(attr_xpath),
8345 "/%s/prefix-limit/direction-list[direction='in']",
8346 bgp_afi_safi_get_container_str(afi, safi));
8347 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8348
8349 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8350
8351 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8352 argv[idx_number]->arg);
8353 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8354 NB_OP_MODIFY, argv[idx_number_2]->arg);
8355 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8356 "true");
9cbd06e0 8357 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8358 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8359 "true");
9cbd06e0 8360
04261dec 8361 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8362}
8363
d62a17ae 8364ALIAS_HIDDEN(
8365 neighbor_maximum_prefix_threshold_warning,
8366 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8367 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8368 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8369 "Maximum number of prefix accept from this peer\n"
8370 "maximum no. of prefix limit\n"
8371 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8372 "Only give warning message when limit is exceeded\n"
8373 "Force checking all received routes not only accepted\n")
596c17ba 8374
232c75cd
CS
8375DEFUN_YANG(neighbor_maximum_prefix_restart,
8376 neighbor_maximum_prefix_restart_cmd,
8377 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8378 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8379 "Maximum number of prefix accept from this peer\n"
8380 "maximum no. of prefix limit\n"
8381 "Restart bgp connection after limit is exceeded\n"
8382 "Restart interval in minutes\n"
8383 "Force checking all received routes not only accepted\n")
0a486e5f 8384{
d62a17ae 8385 int idx_peer = 1;
8386 int idx_number = 3;
8387 int idx_number_2 = 5;
9cbd06e0 8388 int idx_force = 0;
04261dec
CS
8389 char base_xpath[XPATH_MAXLEN];
8390 char af_xpath[XPATH_MAXLEN];
8391 char attr_xpath[XPATH_MAXLEN];
8392 afi_t afi = bgp_node_afi(vty);
8393 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8394
04261dec
CS
8395 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8396 yang_afi_safi_value2identity(afi, safi));
8397 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8398 sizeof(base_xpath), af_xpath)
8399 < 0)
8400 return CMD_WARNING_CONFIG_FAILED;
8401
8402 snprintf(attr_xpath, sizeof(attr_xpath),
8403 "/%s/prefix-limit/direction-list[direction='in']",
8404 bgp_afi_safi_get_container_str(afi, safi));
8405 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8406
8407 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8408
8409 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8410 argv[idx_number]->arg);
8411 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8412 argv[idx_number_2]->arg);
9cbd06e0 8413 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8414 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8415 "true");
9cbd06e0 8416
04261dec 8417 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8418}
8419
d62a17ae 8420ALIAS_HIDDEN(
8421 neighbor_maximum_prefix_restart,
8422 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8423 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8424 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8425 "Maximum number of prefix accept from this peer\n"
8426 "maximum no. of prefix limit\n"
8427 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8428 "Restart interval in minutes\n"
8429 "Force checking all received routes not only accepted\n")
596c17ba 8430
232c75cd
CS
8431DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8432 neighbor_maximum_prefix_threshold_restart_cmd,
8433 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8434 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8435 "Maximum number of prefixes to accept from this peer\n"
8436 "maximum no. of prefix limit\n"
8437 "Threshold value (%) at which to generate a warning msg\n"
8438 "Restart bgp connection after limit is exceeded\n"
8439 "Restart interval in minutes\n"
8440 "Force checking all received routes not only accepted\n")
0a486e5f 8441{
d62a17ae 8442 int idx_peer = 1;
8443 int idx_number = 3;
8444 int idx_number_2 = 4;
8445 int idx_number_3 = 6;
9cbd06e0 8446 int idx_force = 0;
04261dec
CS
8447 char base_xpath[XPATH_MAXLEN];
8448 char af_xpath[XPATH_MAXLEN];
8449 char attr_xpath[XPATH_MAXLEN];
8450 afi_t afi = bgp_node_afi(vty);
8451 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8452
04261dec
CS
8453 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8454 yang_afi_safi_value2identity(afi, safi));
8455 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8456 sizeof(base_xpath), af_xpath)
8457 < 0)
8458 return CMD_WARNING_CONFIG_FAILED;
8459
8460 snprintf(attr_xpath, sizeof(attr_xpath),
8461 "/%s/prefix-limit/direction-list[direction='in']",
8462 bgp_afi_safi_get_container_str(afi, safi));
8463 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8464
8465 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8466
8467 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8468 argv[idx_number]->arg);
8469 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8470 NB_OP_MODIFY, argv[idx_number_2]->arg);
8471 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8472 argv[idx_number_3]->arg);
9cbd06e0 8473 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8474 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8475 "true");
9cbd06e0 8476
04261dec 8477 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 8478}
8479
8480ALIAS_HIDDEN(
8481 neighbor_maximum_prefix_threshold_restart,
8482 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8483 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8484 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8485 "Maximum number of prefixes to accept from this peer\n"
8486 "maximum no. of prefix limit\n"
8487 "Threshold value (%) at which to generate a warning msg\n"
8488 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8489 "Restart interval in minutes\n"
8490 "Force checking all received routes not only accepted\n")
596c17ba 8491
232c75cd
CS
8492DEFUN_YANG(no_neighbor_maximum_prefix,
8493 no_neighbor_maximum_prefix_cmd,
8494 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8495 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8496 "Maximum number of prefixes to accept from this peer\n"
8497 "maximum no. of prefix limit\n"
8498 "Threshold value (%) at which to generate a warning msg\n"
8499 "Restart bgp connection after limit is exceeded\n"
8500 "Restart interval in minutes\n"
8501 "Only give warning message when limit is exceeded\n"
8502 "Force checking all received routes not only accepted\n")
718e3744 8503{
d62a17ae 8504 int idx_peer = 2;
04261dec
CS
8505 char base_xpath[XPATH_MAXLEN];
8506 char af_xpath[XPATH_MAXLEN];
8507 char attr_xpath[XPATH_MAXLEN];
8508 afi_t afi = bgp_node_afi(vty);
8509 safi_t safi = bgp_node_safi(vty);
8510
8511 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8512 yang_afi_safi_value2identity(afi, safi));
8513 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8514 sizeof(base_xpath), af_xpath)
8515 < 0)
8516 return CMD_WARNING_CONFIG_FAILED;
8517
8518 snprintf(attr_xpath, sizeof(attr_xpath),
8519 "/%s/prefix-limit/direction-list[direction='in']",
8520 bgp_afi_safi_get_container_str(afi, safi));
8521 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8522
8523 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8524
8525 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8526}
e52702f2 8527
d62a17ae 8528ALIAS_HIDDEN(
8529 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8530 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8531 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8532 "Maximum number of prefixes to accept from this peer\n"
8533 "maximum no. of prefix limit\n"
8534 "Threshold value (%) at which to generate a warning msg\n"
8535 "Restart bgp connection after limit is exceeded\n"
8536 "Restart interval in minutes\n"
9cbd06e0
DA
8537 "Only give warning message when limit is exceeded\n"
8538 "Force checking all received routes not only accepted\n")
596c17ba 8539
718e3744 8540
718e3744 8541/* "neighbor allowas-in" */
8542DEFUN (neighbor_allowas_in,
8543 neighbor_allowas_in_cmd,
fd8503f5 8544 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8545 NEIGHBOR_STR
8546 NEIGHBOR_ADDR_STR2
31500417 8547 "Accept as-path with my AS present in it\n"
f79f7a7b 8548 "Number of occurrences of AS number\n"
fd8503f5 8549 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8550{
d62a17ae 8551 int idx_peer = 1;
8552 int idx_number_origin = 3;
8553 int ret;
8554 int origin = 0;
8555 struct peer *peer;
8556 int allow_num = 0;
8557
8558 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8559 if (!peer)
8560 return CMD_WARNING_CONFIG_FAILED;
8561
8562 if (argc <= idx_number_origin)
8563 allow_num = 3;
8564 else {
8565 if (argv[idx_number_origin]->type == WORD_TKN)
8566 origin = 1;
8567 else
8568 allow_num = atoi(argv[idx_number_origin]->arg);
8569 }
8570
8571 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8572 allow_num, origin);
8573
8574 return bgp_vty_return(vty, ret);
8575}
8576
8577ALIAS_HIDDEN(
8578 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8579 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8580 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8581 "Accept as-path with my AS present in it\n"
f79f7a7b 8582 "Number of occurrences of AS number\n"
d62a17ae 8583 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8584
718e3744 8585DEFUN (no_neighbor_allowas_in,
8586 no_neighbor_allowas_in_cmd,
fd8503f5 8587 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8588 NO_STR
8589 NEIGHBOR_STR
8590 NEIGHBOR_ADDR_STR2
8334fd5a 8591 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8592 "Number of occurrences of AS number\n"
fd8503f5 8593 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8594{
d62a17ae 8595 int idx_peer = 2;
8596 int ret;
8597 struct peer *peer;
718e3744 8598
d62a17ae 8599 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8600 if (!peer)
8601 return CMD_WARNING_CONFIG_FAILED;
718e3744 8602
d62a17ae 8603 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8604 bgp_node_safi(vty));
718e3744 8605
d62a17ae 8606 return bgp_vty_return(vty, ret);
718e3744 8607}
6b0655a2 8608
d62a17ae 8609ALIAS_HIDDEN(
8610 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8611 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8612 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8613 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8614 "Number of occurrences of AS number\n"
d62a17ae 8615 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8616
f4b8ec07
CS
8617DEFUN_YANG (neighbor_ttl_security,
8618 neighbor_ttl_security_cmd,
8619 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8620 NEIGHBOR_STR
8621 NEIGHBOR_ADDR_STR2
8622 "BGP ttl-security parameters\n"
8623 "Specify the maximum number of hops to the BGP peer\n"
8624 "Number of hops to BGP peer\n")
fa411a21 8625{
d62a17ae 8626 int idx_peer = 1;
8627 int idx_number = 4;
f4b8ec07 8628 char base_xpath[XPATH_MAXLEN];
d62a17ae 8629
f4b8ec07
CS
8630 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8631 sizeof(base_xpath), NULL)
8632 < 0)
d62a17ae 8633 return CMD_WARNING_CONFIG_FAILED;
8634
f4b8ec07
CS
8635 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8636 argv[idx_number]->arg);
7ebe625c 8637
f4b8ec07 8638 return nb_cli_apply_changes(vty, base_xpath);
fa411a21
NH
8639}
8640
232c75cd
CS
8641DEFUN_YANG(no_neighbor_ttl_security,
8642 no_neighbor_ttl_security_cmd,
8643 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8644 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8645 "BGP ttl-security parameters\n"
8646 "Specify the maximum number of hops to the BGP peer\n"
8647 "Number of hops to BGP peer\n")
fa411a21 8648{
d62a17ae 8649 int idx_peer = 2;
f4b8ec07 8650 char base_xpath[XPATH_MAXLEN];
fa411a21 8651
f4b8ec07
CS
8652 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8653 sizeof(base_xpath), NULL)
8654 < 0)
d62a17ae 8655 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8656
f4b8ec07
CS
8657 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8658
8659 return nb_cli_apply_changes(vty, base_xpath);
fa411a21 8660}
6b0655a2 8661
adbac85e
DW
8662DEFUN (neighbor_addpath_tx_all_paths,
8663 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8664 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8665 NEIGHBOR_STR
8666 NEIGHBOR_ADDR_STR2
8667 "Use addpath to advertise all paths to a neighbor\n")
8668{
d62a17ae 8669 int idx_peer = 1;
8670 struct peer *peer;
adbac85e 8671
d62a17ae 8672 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8673 if (!peer)
8674 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8675
dcc68b5e
MS
8676 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8677 BGP_ADDPATH_ALL);
8678 return CMD_SUCCESS;
adbac85e
DW
8679}
8680
d62a17ae 8681ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8682 neighbor_addpath_tx_all_paths_hidden_cmd,
8683 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8684 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8685 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8686
adbac85e
DW
8687DEFUN (no_neighbor_addpath_tx_all_paths,
8688 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8689 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8690 NO_STR
8691 NEIGHBOR_STR
8692 NEIGHBOR_ADDR_STR2
8693 "Use addpath to advertise all paths to a neighbor\n")
8694{
d62a17ae 8695 int idx_peer = 2;
dcc68b5e
MS
8696 struct peer *peer;
8697
8698 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8699 if (!peer)
8700 return CMD_WARNING_CONFIG_FAILED;
8701
8702 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8703 != BGP_ADDPATH_ALL) {
8704 vty_out(vty,
8705 "%% Peer not currently configured to transmit all paths.");
8706 return CMD_WARNING_CONFIG_FAILED;
8707 }
8708
8709 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8710 BGP_ADDPATH_NONE);
8711
8712 return CMD_SUCCESS;
adbac85e
DW
8713}
8714
d62a17ae 8715ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8716 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8717 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8718 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8719 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8720
06370dac
DW
8721DEFUN (neighbor_addpath_tx_bestpath_per_as,
8722 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8723 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8724 NEIGHBOR_STR
8725 NEIGHBOR_ADDR_STR2
8726 "Use addpath to advertise the bestpath per each neighboring AS\n")
8727{
d62a17ae 8728 int idx_peer = 1;
8729 struct peer *peer;
06370dac 8730
d62a17ae 8731 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8732 if (!peer)
8733 return CMD_WARNING_CONFIG_FAILED;
06370dac 8734
dcc68b5e
MS
8735 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8736 BGP_ADDPATH_BEST_PER_AS);
8737
8738 return CMD_SUCCESS;
06370dac
DW
8739}
8740
d62a17ae 8741ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8742 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8743 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8744 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8745 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8746
06370dac
DW
8747DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8748 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8749 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8750 NO_STR
8751 NEIGHBOR_STR
8752 NEIGHBOR_ADDR_STR2
8753 "Use addpath to advertise the bestpath per each neighboring AS\n")
8754{
d62a17ae 8755 int idx_peer = 2;
dcc68b5e
MS
8756 struct peer *peer;
8757
8758 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8759 if (!peer)
8760 return CMD_WARNING_CONFIG_FAILED;
8761
8762 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8763 != BGP_ADDPATH_BEST_PER_AS) {
8764 vty_out(vty,
8765 "%% Peer not currently configured to transmit all best path per as.");
8766 return CMD_WARNING_CONFIG_FAILED;
8767 }
8768
8769 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8770 BGP_ADDPATH_NONE);
8771
8772 return CMD_SUCCESS;
06370dac
DW
8773}
8774
d62a17ae 8775ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8776 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8777 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8778 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8779 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8780
2b31007c
RZ
8781DEFPY(
8782 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8783 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8784 NEIGHBOR_STR
8785 NEIGHBOR_ADDR_STR2
8786 "Detect AS loops before sending to neighbor\n")
8787{
8788 struct peer *peer;
8789
8790 peer = peer_and_group_lookup_vty(vty, neighbor);
8791 if (!peer)
8792 return CMD_WARNING_CONFIG_FAILED;
8793
8794 peer->as_path_loop_detection = true;
8795
8796 return CMD_SUCCESS;
8797}
8798
8799DEFPY(
8800 no_neighbor_aspath_loop_detection,
8801 no_neighbor_aspath_loop_detection_cmd,
8802 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8803 NO_STR
8804 NEIGHBOR_STR
8805 NEIGHBOR_ADDR_STR2
8806 "Detect AS loops before sending to neighbor\n")
8807{
8808 struct peer *peer;
8809
8810 peer = peer_and_group_lookup_vty(vty, neighbor);
8811 if (!peer)
8812 return CMD_WARNING_CONFIG_FAILED;
8813
8814 peer->as_path_loop_detection = false;
8815
8816 return CMD_SUCCESS;
8817}
8818
b9c7bc5a 8819static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8820 struct ecommunity **list, bool is_rt6)
ddb5b488 8821{
b9c7bc5a
PZ
8822 struct ecommunity *ecom = NULL;
8823 struct ecommunity *ecomadd;
ddb5b488 8824
b9c7bc5a 8825 for (; argc; --argc, ++argv) {
9a659715
PG
8826 if (is_rt6)
8827 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8828 ECOMMUNITY_ROUTE_TARGET,
8829 0);
8830 else
8831 ecomadd = ecommunity_str2com(argv[0]->arg,
8832 ECOMMUNITY_ROUTE_TARGET,
8833 0);
b9c7bc5a
PZ
8834 if (!ecomadd) {
8835 vty_out(vty, "Malformed community-list value\n");
8836 if (ecom)
8837 ecommunity_free(&ecom);
8838 return CMD_WARNING_CONFIG_FAILED;
8839 }
ddb5b488 8840
b9c7bc5a
PZ
8841 if (ecom) {
8842 ecommunity_merge(ecom, ecomadd);
8843 ecommunity_free(&ecomadd);
8844 } else {
8845 ecom = ecomadd;
8846 }
8847 }
8848
8849 if (*list) {
8850 ecommunity_free(&*list);
ddb5b488 8851 }
b9c7bc5a
PZ
8852 *list = ecom;
8853
8854 return CMD_SUCCESS;
ddb5b488
PZ
8855}
8856
37a87b8f
CS
8857bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8858 bool v2vimport, char *errmsg, size_t errmsg_len)
8859{
8860 if (!v2vimport) {
8861 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8862 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8863 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8864 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8865 snprintf(
8866 errmsg, errmsg_len, "%s",
8867 "%% error: Please unconfigure import vrf commands before using vpn commands");
8868 return false;
8869 }
8870 } else {
8871 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8872 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8873 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8874 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8875 snprintf(
8876 errmsg, errmsg_len, "%s",
8877 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8878 return false;
8879 }
8880 }
8881 return true;
8882}
8883
0ca70ba5
DS
8884/*
8885 * v2vimport is true if we are handling a `import vrf ...` command
8886 */
8887static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8888{
0ca70ba5
DS
8889 afi_t afi;
8890
ddb5b488 8891 switch (vty->node) {
b9c7bc5a 8892 case BGP_IPV4_NODE:
0ca70ba5
DS
8893 afi = AFI_IP;
8894 break;
b9c7bc5a 8895 case BGP_IPV6_NODE:
0ca70ba5
DS
8896 afi = AFI_IP6;
8897 break;
ddb5b488
PZ
8898 default:
8899 vty_out(vty,
b9c7bc5a 8900 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8901 return AFI_MAX;
ddb5b488 8902 }
69b07479 8903
0ca70ba5
DS
8904 if (!v2vimport) {
8905 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8906 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8907 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8908 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8909 vty_out(vty,
8910 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8911 return AFI_MAX;
8912 }
8913 } else {
8914 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8915 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8916 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8917 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8918 vty_out(vty,
8919 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8920 return AFI_MAX;
8921 }
8922 }
8923 return afi;
ddb5b488
PZ
8924}
8925
37a87b8f
CS
8926DEFPY_YANG(
8927 af_rd_vpn_export,
8928 af_rd_vpn_export_cmd,
8929 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8930 NO_STR
8931 "Specify route distinguisher\n"
8932 "Between current address-family and vpn\n"
8933 "For routes leaked from current address-family to vpn\n"
8934 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8935{
37a87b8f 8936 char base_xpath[XPATH_MAXLEN];
ddb5b488 8937 afi_t afi;
37a87b8f 8938 safi_t safi;
b9c7bc5a 8939 int idx = 0;
b9c7bc5a 8940
37a87b8f
CS
8941 afi = bgp_node_afi(vty);
8942 safi = bgp_node_safi(vty);
ddb5b488 8943
37a87b8f
CS
8944 snprintf(
8945 base_xpath, sizeof(base_xpath),
8946 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
8947 yang_afi_safi_value2identity(afi, safi),
8948 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 8949
37a87b8f
CS
8950 if (argv_find(argv, argc, "no", &idx))
8951 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
8952 else
8953 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
ddb5b488 8954
37a87b8f
CS
8955 return nb_cli_apply_changes(vty, base_xpath);
8956}
ddb5b488 8957
37a87b8f
CS
8958void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
8959 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8960{
8961 int indent = 2;
69b07479 8962
37a87b8f
CS
8963 vty_out(vty, "%*srd vpn export %s\n", indent, "",
8964 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
8965}
8966
b9c7bc5a
PZ
8967ALIAS (af_rd_vpn_export,
8968 af_no_rd_vpn_export_cmd,
8969 "no rd vpn export",
ddb5b488 8970 NO_STR
b9c7bc5a
PZ
8971 "Specify route distinguisher\n"
8972 "Between current address-family and vpn\n"
8973 "For routes leaked from current address-family to vpn\n")
ddb5b488 8974
b9c7bc5a
PZ
8975DEFPY (af_label_vpn_export,
8976 af_label_vpn_export_cmd,
e70e9f8e 8977 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8978 NO_STR
ddb5b488 8979 "label value for VRF\n"
b9c7bc5a
PZ
8980 "Between current address-family and vpn\n"
8981 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8982 "Label Value <0-1048575>\n"
8983 "Automatically assign a label\n")
ddb5b488
PZ
8984{
8985 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8986 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8987 afi_t afi;
b9c7bc5a 8988 int idx = 0;
c6423c31 8989 bool yes = true;
b9c7bc5a
PZ
8990
8991 if (argv_find(argv, argc, "no", &idx))
c6423c31 8992 yes = false;
ddb5b488 8993
21a16cc2
PZ
8994 /* If "no ...", squash trailing parameter */
8995 if (!yes)
8996 label_auto = NULL;
8997
e70e9f8e
PZ
8998 if (yes) {
8999 if (!label_auto)
9000 label = label_val; /* parser should force unsigned */
9001 }
ddb5b488 9002
0ca70ba5 9003 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9004 if (afi == AFI_MAX)
9005 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9006
e70e9f8e 9007
69b07479
DS
9008 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9009 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9010 /* no change */
9011 return CMD_SUCCESS;
e70e9f8e 9012
69b07479
DS
9013 /*
9014 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9015 */
9016 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9017 bgp_get_default(), bgp);
9018
9019 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9020 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9021
9022 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9023
9024 /*
9025 * label has previously been automatically
9026 * assigned by labelpool: release it
9027 *
9028 * NB if tovpn_label == MPLS_LABEL_NONE it
9029 * means the automatic assignment is in flight
9030 * and therefore the labelpool callback must
9031 * detect that the auto label is not needed.
9032 */
9033
9034 bgp_lp_release(LP_TYPE_VRF,
9035 &bgp->vpn_policy[afi],
9036 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9037 }
69b07479
DS
9038 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9039 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9040 }
ddb5b488 9041
69b07479
DS
9042 bgp->vpn_policy[afi].tovpn_label = label;
9043 if (label_auto) {
9044 SET_FLAG(bgp->vpn_policy[afi].flags,
9045 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9046 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9047 vpn_leak_label_callback);
ddb5b488
PZ
9048 }
9049
69b07479
DS
9050 /* post-change: re-export vpn routes */
9051 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9052 bgp_get_default(), bgp);
9053
ddb5b488
PZ
9054 return CMD_SUCCESS;
9055}
9056
b9c7bc5a
PZ
9057ALIAS (af_label_vpn_export,
9058 af_no_label_vpn_export_cmd,
9059 "no label vpn export",
9060 NO_STR
9061 "label value for VRF\n"
9062 "Between current address-family and vpn\n"
9063 "For routes leaked from current address-family to vpn\n")
ddb5b488 9064
37a87b8f 9065DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 9066 af_nexthop_vpn_export_cmd,
8c85ca28 9067 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9068 NO_STR
ddb5b488 9069 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9070 "Between current address-family and vpn\n"
9071 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9072 "IPv4 prefix\n"
9073 "IPv6 prefix\n")
9074{
37a87b8f 9075 char base_xpath[XPATH_MAXLEN];
ddb5b488 9076 afi_t afi;
37a87b8f
CS
9077 safi_t safi;
9078 int idx = 0;
ddb5b488
PZ
9079 struct prefix p;
9080
8c85ca28
QY
9081 if (!no) {
9082 if (!nexthop_su) {
9083 vty_out(vty, "%% Nexthop required\n");
9084 return CMD_WARNING_CONFIG_FAILED;
9085 }
8c85ca28 9086 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9087 return CMD_WARNING_CONFIG_FAILED;
9088 }
ddb5b488 9089
37a87b8f
CS
9090 afi = bgp_node_afi(vty);
9091 safi = bgp_node_safi(vty);
ddb5b488 9092
37a87b8f
CS
9093 snprintf(
9094 base_xpath, sizeof(base_xpath),
9095 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9096 yang_afi_safi_value2identity(afi, safi),
9097 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9098
37a87b8f
CS
9099 if (argv_find(argv, argc, "no", &idx))
9100 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9101 else
9102 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9103 nexthop_su_str);
ddb5b488 9104
37a87b8f
CS
9105 return nb_cli_apply_changes(vty, base_xpath);
9106}
69b07479 9107
37a87b8f
CS
9108void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9109 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9110{
9111 int indent = 2;
9112
9113 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9114 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9115}
9116
b9c7bc5a 9117static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9118{
b9c7bc5a
PZ
9119 if (!strcmp(dstr, "import")) {
9120 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9121 } else if (!strcmp(dstr, "export")) {
9122 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9123 } else if (!strcmp(dstr, "both")) {
9124 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9125 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9126 } else {
9127 vty_out(vty, "%% direction parse error\n");
9128 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9129 }
ddb5b488
PZ
9130 return CMD_SUCCESS;
9131}
9132
b9c7bc5a
PZ
9133DEFPY (af_rt_vpn_imexport,
9134 af_rt_vpn_imexport_cmd,
9135 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9136 NO_STR
9137 "Specify route target list\n"
ddb5b488 9138 "Specify route target list\n"
b9c7bc5a
PZ
9139 "Between current address-family and vpn\n"
9140 "For routes leaked from vpn to current address-family: match any\n"
9141 "For routes leaked from current address-family to vpn: set\n"
9142 "both import: match any and export: set\n"
ddb5b488
PZ
9143 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9144{
9145 VTY_DECLVAR_CONTEXT(bgp, bgp);
9146 int ret;
9147 struct ecommunity *ecom = NULL;
9148 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
9149 vpn_policy_direction_t dir;
9150 afi_t afi;
9151 int idx = 0;
c6423c31 9152 bool yes = true;
ddb5b488 9153
b9c7bc5a 9154 if (argv_find(argv, argc, "no", &idx))
c6423c31 9155 yes = false;
b9c7bc5a 9156
0ca70ba5 9157 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9158 if (afi == AFI_MAX)
9159 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9160
b9c7bc5a 9161 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9162 if (ret != CMD_SUCCESS)
9163 return ret;
9164
b9c7bc5a
PZ
9165 if (yes) {
9166 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9167 vty_out(vty, "%% Missing RTLIST\n");
9168 return CMD_WARNING_CONFIG_FAILED;
9169 }
c6423c31 9170 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9171 if (ret != CMD_SUCCESS) {
9172 return ret;
9173 }
ddb5b488
PZ
9174 }
9175
69b07479
DS
9176 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9177 if (!dodir[dir])
ddb5b488 9178 continue;
ddb5b488 9179
69b07479 9180 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9181
69b07479
DS
9182 if (yes) {
9183 if (bgp->vpn_policy[afi].rtlist[dir])
9184 ecommunity_free(
9185 &bgp->vpn_policy[afi].rtlist[dir]);
9186 bgp->vpn_policy[afi].rtlist[dir] =
9187 ecommunity_dup(ecom);
9188 } else {
9189 if (bgp->vpn_policy[afi].rtlist[dir])
9190 ecommunity_free(
9191 &bgp->vpn_policy[afi].rtlist[dir]);
9192 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9193 }
69b07479
DS
9194
9195 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9196 }
69b07479 9197
d555f3e9
PZ
9198 if (ecom)
9199 ecommunity_free(&ecom);
ddb5b488
PZ
9200
9201 return CMD_SUCCESS;
9202}
9203
b9c7bc5a
PZ
9204ALIAS (af_rt_vpn_imexport,
9205 af_no_rt_vpn_imexport_cmd,
9206 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9207 NO_STR
9208 "Specify route target list\n"
b9c7bc5a
PZ
9209 "Specify route target list\n"
9210 "Between current address-family and vpn\n"
9211 "For routes leaked from vpn to current address-family\n"
9212 "For routes leaked from current address-family to vpn\n"
9213 "both import and export\n")
9214
37a87b8f 9215DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9216 af_route_map_vpn_imexport_cmd,
9217/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9218 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9219 NO_STR
ddb5b488 9220 "Specify route map\n"
b9c7bc5a
PZ
9221 "Between current address-family and vpn\n"
9222 "For routes leaked from vpn to current address-family\n"
9223 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9224 "name of route-map\n")
9225{
37a87b8f 9226 char base_xpath[XPATH_MAXLEN];
ddb5b488 9227 afi_t afi;
37a87b8f 9228 safi_t safi;
ddb5b488 9229 int idx = 0;
ddb5b488 9230
37a87b8f
CS
9231 afi = bgp_node_afi(vty);
9232 safi = bgp_node_safi(vty);
ddb5b488 9233
37a87b8f
CS
9234 snprintf(
9235 base_xpath, sizeof(base_xpath),
9236 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9237 yang_afi_safi_value2identity(afi, safi),
9238 bgp_afi_safi_get_container_str(afi, safi));
9239
9240 if (argv_find(argv, argc, "no", &idx)) {
9241 if (!strcmp(direction_str, "import"))
9242 nb_cli_enqueue_change(vty, "./rmap-import",
9243 NB_OP_DESTROY, NULL);
9244 else if (!strcmp(direction_str, "export"))
9245 nb_cli_enqueue_change(vty, "./rmap-export",
9246 NB_OP_DESTROY, NULL);
9247 } else {
9248 if (!strcmp(direction_str, "import"))
9249 nb_cli_enqueue_change(vty, "./rmap-import",
9250 NB_OP_MODIFY, rmap_str);
9251 if (!strcmp(direction_str, "export"))
9252 nb_cli_enqueue_change(vty, "./rmap-export",
9253 NB_OP_MODIFY, rmap_str);
9254 }
9255 return nb_cli_apply_changes(vty, base_xpath);
9256}
ddb5b488 9257
37a87b8f
CS
9258void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9259 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9260{
9261 int indent = 2;
ddb5b488 9262
37a87b8f
CS
9263 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9264 yang_dnode_get_string(dnode, NULL));
9265}
69b07479 9266
37a87b8f
CS
9267void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9268 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9269{
9270 int indent = 2;
ddb5b488 9271
37a87b8f
CS
9272 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9273 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9274}
9275
b9c7bc5a
PZ
9276ALIAS (af_route_map_vpn_imexport,
9277 af_no_route_map_vpn_imexport_cmd,
9278 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9279 NO_STR
9280 "Specify route map\n"
b9c7bc5a
PZ
9281 "Between current address-family and vpn\n"
9282 "For routes leaked from vpn to current address-family\n"
9283 "For routes leaked from current address-family to vpn\n")
9284
bb4f6190 9285DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9286 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9287 "Import routes from another VRF\n"
9288 "Vrf routes being filtered\n"
9289 "Specify route map\n"
9290 "name of route-map\n")
9291{
9292 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
9293 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9294 afi_t afi;
bb4f6190
DS
9295 struct bgp *bgp_default;
9296
0ca70ba5 9297 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9298 if (afi == AFI_MAX)
9299 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9300
9301 bgp_default = bgp_get_default();
9302 if (!bgp_default) {
9303 int32_t ret;
9304 as_t as = bgp->as;
9305
9306 /* Auto-create assuming the same AS */
5d5393b9
DL
9307 ret = bgp_get_vty(&bgp_default, &as, NULL,
9308 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9309
9310 if (ret) {
9311 vty_out(vty,
9312 "VRF default is not configured as a bgp instance\n");
9313 return CMD_WARNING;
9314 }
9315 }
9316
69b07479 9317 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9318
ae6a6fb4
DS
9319 if (bgp->vpn_policy[afi].rmap_name[dir])
9320 XFREE(MTYPE_ROUTE_MAP_NAME,
9321 bgp->vpn_policy[afi].rmap_name[dir]);
9322 bgp->vpn_policy[afi].rmap_name[dir] =
9323 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9324 bgp->vpn_policy[afi].rmap[dir] =
9325 route_map_lookup_warn_noexist(vty, rmap_str);
9326 if (!bgp->vpn_policy[afi].rmap[dir])
9327 return CMD_SUCCESS;
9328
9329 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9330 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9331
69b07479
DS
9332 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9333
bb4f6190
DS
9334 return CMD_SUCCESS;
9335}
9336
ae6a6fb4
DS
9337DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9338 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9339 NO_STR
9340 "Import routes from another VRF\n"
9341 "Vrf routes being filtered\n"
ae6a6fb4
DS
9342 "Specify route map\n"
9343 "name of route-map\n")
9344{
9345 VTY_DECLVAR_CONTEXT(bgp, bgp);
9346 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9347 afi_t afi;
9348
9349 afi = vpn_policy_getafi(vty, bgp, true);
9350 if (afi == AFI_MAX)
9351 return CMD_WARNING_CONFIG_FAILED;
9352
9353 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9354
9355 if (bgp->vpn_policy[afi].rmap_name[dir])
9356 XFREE(MTYPE_ROUTE_MAP_NAME,
9357 bgp->vpn_policy[afi].rmap_name[dir]);
9358 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9359 bgp->vpn_policy[afi].rmap[dir] = NULL;
9360
9361 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9362 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9363 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9364
9365 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9366
9367 return CMD_SUCCESS;
9368}
bb4f6190 9369
37a87b8f
CS
9370DEFPY_YANG(bgp_imexport_vrf,
9371 bgp_imexport_vrf_cmd,
9372 "[no] import vrf VIEWVRFNAME$import_name",
9373 NO_STR
9374 "Import routes from another VRF\n"
9375 "VRF to import from\n"
9376 "The name of the VRF\n")
12a844a5 9377{
37a87b8f 9378 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
9379 safi_t safi;
9380 afi_t afi;
37a87b8f 9381 int32_t idx = 0;
12a844a5 9382
867f0cca 9383 if (import_name == NULL) {
9384 vty_out(vty, "%% Missing import name\n");
9385 return CMD_WARNING;
9386 }
9387
ae6a6fb4
DS
9388 if (strcmp(import_name, "route-map") == 0) {
9389 vty_out(vty, "%% Must include route-map name\n");
9390 return CMD_WARNING;
9391 }
9392
37a87b8f 9393 afi = bgp_node_afi(vty);
12a844a5
DS
9394 safi = bgp_node_safi(vty);
9395
37a87b8f
CS
9396 snprintf(
9397 base_xpath, sizeof(base_xpath),
9398 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9399 yang_afi_safi_value2identity(afi, safi),
9400 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 9401
37a87b8f
CS
9402 if (argv_find(argv, argc, "no", &idx))
9403 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9404 else
9405 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 9406
37a87b8f
CS
9407 return nb_cli_apply_changes(vty, base_xpath);
9408}
12a844a5 9409
37a87b8f
CS
9410void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9411 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9412{
9413 vty_out(vty, " import vrf %s\n",
9414 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
9415}
9416
b9c7bc5a 9417/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 9418DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
9419 bgp_imexport_vpn_cmd,
9420 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9421 NO_STR
9422 "Import routes to this address-family\n"
9423 "Export routes from this address-family\n"
9424 "to/from default instance VPN RIB\n")
ddb5b488 9425{
37a87b8f 9426 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 9427 safi_t safi;
37a87b8f
CS
9428 afi_t afi;
9429 int32_t idx = 0;
ddb5b488 9430
b9c7bc5a
PZ
9431 afi = bgp_node_afi(vty);
9432 safi = bgp_node_safi(vty);
ddb5b488 9433
b9c7bc5a 9434 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
9435 snprintf(
9436 base_xpath, sizeof(base_xpath),
9437 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9438 yang_afi_safi_value2identity(afi, safi),
9439 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 9440 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
9441 snprintf(
9442 base_xpath, sizeof(base_xpath),
9443 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9444 yang_afi_safi_value2identity(afi, safi),
9445 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
9446 } else {
9447 vty_out(vty, "%% unknown direction %s\n", direction_str);
9448 return CMD_WARNING_CONFIG_FAILED;
9449 }
9450
37a87b8f
CS
9451 if (argv_find(argv, argc, "no", &idx))
9452 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9453 else
9454 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 9455
37a87b8f
CS
9456 return nb_cli_apply_changes(vty, base_xpath);
9457}
ddb5b488 9458
37a87b8f
CS
9459void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9460 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9461{
9462 if (yang_dnode_get_bool(dnode, NULL))
9463 vty_out(vty, " import vpn\n");
9464}
9465
9466void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9467 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9468{
9469 if (yang_dnode_get_bool(dnode, NULL))
9470 vty_out(vty, " export vpn\n");
ddb5b488
PZ
9471}
9472
301ad80a
PG
9473DEFPY (af_routetarget_import,
9474 af_routetarget_import_cmd,
9a659715 9475 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9476 NO_STR
9477 "Specify route target list\n"
9478 "Specify route target list\n"
9a659715
PG
9479 "Specify route target list\n"
9480 "Specify route target list\n"
301ad80a
PG
9481 "Flow-spec redirect type route target\n"
9482 "Import routes to this address-family\n"
9a659715 9483 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9484{
9485 VTY_DECLVAR_CONTEXT(bgp, bgp);
9486 int ret;
9487 struct ecommunity *ecom = NULL;
301ad80a 9488 afi_t afi;
9a659715 9489 int idx = 0, idx_unused = 0;
c6423c31
PG
9490 bool yes = true;
9491 bool rt6 = false;
301ad80a
PG
9492
9493 if (argv_find(argv, argc, "no", &idx))
c6423c31 9494 yes = false;
301ad80a 9495
9a659715
PG
9496 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9497 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9498 rt6 = true;
301ad80a 9499
0ca70ba5 9500 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9501 if (afi == AFI_MAX)
9502 return CMD_WARNING_CONFIG_FAILED;
9503
9a659715
PG
9504 if (rt6 && afi != AFI_IP6)
9505 return CMD_WARNING_CONFIG_FAILED;
9506
301ad80a
PG
9507 if (yes) {
9508 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9509 vty_out(vty, "%% Missing RTLIST\n");
9510 return CMD_WARNING_CONFIG_FAILED;
9511 }
9a659715 9512 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9513 if (ret != CMD_SUCCESS)
9514 return ret;
9515 }
69b07479
DS
9516
9517 if (yes) {
9518 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9519 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9520 .import_redirect_rtlist);
69b07479
DS
9521 bgp->vpn_policy[afi].import_redirect_rtlist =
9522 ecommunity_dup(ecom);
9523 } else {
9524 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9525 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9526 .import_redirect_rtlist);
69b07479 9527 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9528 }
69b07479 9529
301ad80a
PG
9530 if (ecom)
9531 ecommunity_free(&ecom);
9532
9533 return CMD_SUCCESS;
9534}
9535
37a87b8f
CS
9536void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9537 struct lyd_node *dnode,
9538 bool show_defaults)
9539{
9540 const char *af_name;
9541 afi_t afi;
9542 safi_t safi;
9543
9544 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9545 yang_afi_safi_identity2value(af_name, &afi, &safi);
9546
9547 vty_out(vty, " !\n address-family ");
9548 if (afi == AFI_IP) {
9549 if (safi == SAFI_UNICAST)
9550 vty_out(vty, "ipv4 unicast");
9551 else if (safi == SAFI_LABELED_UNICAST)
9552 vty_out(vty, "ipv4 labeled-unicast");
9553 else if (safi == SAFI_MULTICAST)
9554 vty_out(vty, "ipv4 multicast");
9555 else if (safi == SAFI_MPLS_VPN)
9556 vty_out(vty, "ipv4 vpn");
9557 else if (safi == SAFI_ENCAP)
9558 vty_out(vty, "ipv4 encap");
9559 else if (safi == SAFI_FLOWSPEC)
9560 vty_out(vty, "ipv4 flowspec");
9561 } else if (afi == AFI_IP6) {
9562 if (safi == SAFI_UNICAST)
9563 vty_out(vty, "ipv6 unicast");
9564 else if (safi == SAFI_LABELED_UNICAST)
9565 vty_out(vty, "ipv6 labeled-unicast");
9566 else if (safi == SAFI_MULTICAST)
9567 vty_out(vty, "ipv6 multicast");
9568 else if (safi == SAFI_MPLS_VPN)
9569 vty_out(vty, "ipv6 vpn");
9570 else if (safi == SAFI_ENCAP)
9571 vty_out(vty, "ipv6 encap");
9572 else if (safi == SAFI_FLOWSPEC)
9573 vty_out(vty, "ipv6 flowspec");
9574 } else if (afi == AFI_L2VPN) {
9575 if (safi == SAFI_EVPN)
9576 vty_out(vty, "l2vpn evpn");
9577 }
9578 vty_out(vty, "\n");
9579}
9580
505e5056 9581DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9582 address_family_ipv4_safi_cmd,
9583 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9584 "Enter Address Family command mode\n"
9585 "Address Family\n"
9586 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9587{
f51bae9c 9588
37a87b8f
CS
9589 safi_t safi = SAFI_UNICAST;
9590 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9591 const char *vrf_name = NULL;
9592
d62a17ae 9593 if (argc == 3) {
37a87b8f
CS
9594 safi = bgp_vty_safi_from_str(argv[2]->text);
9595
9596 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9597 VTY_CURR_XPATH);
9598 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9599 "control-plane-protocol");
9600 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9601
9602 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9603 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9604 && safi != SAFI_EVPN) {
31947174
MK
9605 vty_out(vty,
9606 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9607 return CMD_WARNING_CONFIG_FAILED;
9608 }
37a87b8f
CS
9609 }
9610 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 9611
d62a17ae 9612 return CMD_SUCCESS;
718e3744 9613}
9614
505e5056 9615DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9616 address_family_ipv6_safi_cmd,
9617 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9618 "Enter Address Family command mode\n"
9619 "Address Family\n"
9620 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9621{
37a87b8f
CS
9622 safi_t safi = SAFI_UNICAST;
9623 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9624 const char *vrf_name = NULL;
9625
d62a17ae 9626 if (argc == 3) {
37a87b8f
CS
9627 safi = bgp_vty_safi_from_str(argv[2]->text);
9628 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9629 VTY_CURR_XPATH);
9630 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9631 "control-plane-protocol");
9632 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9633
9634 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9635 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9636 && safi != SAFI_EVPN) {
31947174
MK
9637 vty_out(vty,
9638 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9639 return CMD_WARNING_CONFIG_FAILED;
9640 }
37a87b8f
CS
9641 }
9642 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 9643
d62a17ae 9644 return CMD_SUCCESS;
25ffbdc1 9645}
718e3744 9646
d6902373 9647#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9648DEFUN_NOSH (address_family_vpnv4,
718e3744 9649 address_family_vpnv4_cmd,
8334fd5a 9650 "address-family vpnv4 [unicast]",
718e3744 9651 "Enter Address Family command mode\n"
8c3deaae 9652 "Address Family\n"
3a2d747c 9653 "Address Family modifier\n")
718e3744 9654{
d62a17ae 9655 vty->node = BGP_VPNV4_NODE;
9656 return CMD_SUCCESS;
718e3744 9657}
9658
505e5056 9659DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9660 address_family_vpnv6_cmd,
8334fd5a 9661 "address-family vpnv6 [unicast]",
8ecd3266 9662 "Enter Address Family command mode\n"
8c3deaae 9663 "Address Family\n"
3a2d747c 9664 "Address Family modifier\n")
8ecd3266 9665{
d62a17ae 9666 vty->node = BGP_VPNV6_NODE;
9667 return CMD_SUCCESS;
8ecd3266 9668}
64e4a6c5 9669#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9670
505e5056 9671DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9672 address_family_evpn_cmd,
7111c1a0 9673 "address-family l2vpn evpn",
4e0b7b6d 9674 "Enter Address Family command mode\n"
7111c1a0
QY
9675 "Address Family\n"
9676 "Address Family modifier\n")
4e0b7b6d 9677{
2131d5cf 9678 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9679 vty->node = BGP_EVPN_NODE;
9680 return CMD_SUCCESS;
4e0b7b6d
PG
9681}
9682
505e5056 9683DEFUN_NOSH (exit_address_family,
718e3744 9684 exit_address_family_cmd,
9685 "exit-address-family",
9686 "Exit from Address Family configuration mode\n")
9687{
d62a17ae 9688 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9689 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9690 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9691 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9692 || vty->node == BGP_EVPN_NODE
9693 || vty->node == BGP_FLOWSPECV4_NODE
9694 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9695 vty->node = BGP_NODE;
9696 return CMD_SUCCESS;
718e3744 9697}
6b0655a2 9698
37a87b8f
CS
9699void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9700 struct lyd_node *dnode
9701 __attribute__((__unused__)))
9702{
9703 vty_out(vty, " exit-address-family\n");
9704}
9705
8ad7271d 9706/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9707static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9708 const char *ip_str, afi_t afi, safi_t safi,
9709 struct prefix_rd *prd)
9710{
9711 int ret;
9712 struct prefix match;
9bcb3eef
DS
9713 struct bgp_dest *dest;
9714 struct bgp_dest *rm;
d62a17ae 9715 struct bgp *bgp;
9716 struct bgp_table *table;
9717 struct bgp_table *rib;
9718
9719 /* BGP structure lookup. */
9720 if (view_name) {
9721 bgp = bgp_lookup_by_name(view_name);
9722 if (bgp == NULL) {
9723 vty_out(vty, "%% Can't find BGP instance %s\n",
9724 view_name);
9725 return CMD_WARNING;
9726 }
9727 } else {
9728 bgp = bgp_get_default();
9729 if (bgp == NULL) {
9730 vty_out(vty, "%% No BGP process is configured\n");
9731 return CMD_WARNING;
9732 }
9733 }
9734
9735 /* Check IP address argument. */
9736 ret = str2prefix(ip_str, &match);
9737 if (!ret) {
9738 vty_out(vty, "%% address is malformed\n");
9739 return CMD_WARNING;
9740 }
9741
9742 match.family = afi2family(afi);
9743 rib = bgp->rib[afi][safi];
9744
9745 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9746 for (dest = bgp_table_top(rib); dest;
9747 dest = bgp_route_next(dest)) {
9748 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9749
9bcb3eef 9750 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9751 continue;
9752
9bcb3eef 9753 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9754 if (table == NULL)
9755 continue;
9756
9757 if ((rm = bgp_node_match(table, &match)) != NULL) {
9758 const struct prefix *rm_p =
9bcb3eef 9759 bgp_dest_get_prefix(rm);
b54892e0
DS
9760
9761 if (rm_p->prefixlen == match.prefixlen) {
9762 SET_FLAG(rm->flags,
9763 BGP_NODE_USER_CLEAR);
9764 bgp_process(bgp, rm, afi, safi);
d62a17ae 9765 }
9bcb3eef 9766 bgp_dest_unlock_node(rm);
d62a17ae 9767 }
9768 }
9769 } else {
9bcb3eef
DS
9770 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9771 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9772
9bcb3eef
DS
9773 if (dest_p->prefixlen == match.prefixlen) {
9774 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9775 bgp_process(bgp, dest, afi, safi);
d62a17ae 9776 }
9bcb3eef 9777 bgp_dest_unlock_node(dest);
d62a17ae 9778 }
9779 }
9780
9781 return CMD_SUCCESS;
8ad7271d
DS
9782}
9783
b09b5ae0 9784/* one clear bgp command to rule them all */
718e3744 9785DEFUN (clear_ip_bgp_all,
9786 clear_ip_bgp_all_cmd,
453c92f6 9787 "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 9788 CLEAR_STR
9789 IP_STR
9790 BGP_STR
838758ac 9791 BGP_INSTANCE_HELP_STR
510afcd6 9792 BGP_AFI_HELP_STR
fd5e7b70 9793 "Address Family\n"
510afcd6 9794 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9795 "Address Family modifier\n"
b09b5ae0 9796 "Clear all peers\n"
453c92f6 9797 "BGP IPv4 neighbor to clear\n"
a80beece 9798 "BGP IPv6 neighbor to clear\n"
838758ac 9799 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9800 "Clear peers with the AS number\n"
9801 "Clear all external peers\n"
718e3744 9802 "Clear all members of peer-group\n"
b09b5ae0 9803 "BGP peer-group name\n"
b09b5ae0
DW
9804 BGP_SOFT_STR
9805 BGP_SOFT_IN_STR
b09b5ae0
DW
9806 BGP_SOFT_OUT_STR
9807 BGP_SOFT_IN_STR
9808 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9809 BGP_SOFT_OUT_STR)
718e3744 9810{
d62a17ae 9811 char *vrf = NULL;
9812
dc912615
DS
9813 afi_t afi = AFI_UNSPEC;
9814 safi_t safi = SAFI_UNSPEC;
d62a17ae 9815 enum clear_sort clr_sort = clear_peer;
9816 enum bgp_clear_type clr_type;
9817 char *clr_arg = NULL;
9818
9819 int idx = 0;
ff8a8a7a
CS
9820 char errmsg[BUFSIZ] = {'\0'};
9821 int ret;
d62a17ae 9822
9823 /* clear [ip] bgp */
9824 if (argv_find(argv, argc, "ip", &idx))
9825 afi = AFI_IP;
9826
9a8bdf1c
PG
9827 /* [<vrf> VIEWVRFNAME] */
9828 if (argv_find(argv, argc, "vrf", &idx)) {
9829 vrf = argv[idx + 1]->arg;
9830 idx += 2;
9831 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9832 vrf = NULL;
9833 } else if (argv_find(argv, argc, "view", &idx)) {
9834 /* [<view> VIEWVRFNAME] */
d62a17ae 9835 vrf = argv[idx + 1]->arg;
9836 idx += 2;
9837 }
d62a17ae 9838 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9839 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9840 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9841
d7b9898c 9842 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9843 if (argv_find(argv, argc, "*", &idx)) {
9844 clr_sort = clear_all;
9845 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9846 clr_sort = clear_peer;
9847 clr_arg = argv[idx]->arg;
9848 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9849 clr_sort = clear_peer;
9850 clr_arg = argv[idx]->arg;
9851 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9852 clr_sort = clear_group;
9853 idx++;
9854 clr_arg = argv[idx]->arg;
d7b9898c 9855 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9856 clr_sort = clear_peer;
9857 clr_arg = argv[idx]->arg;
8fa7d444
DS
9858 } else if (argv_find(argv, argc, "WORD", &idx)) {
9859 clr_sort = clear_peer;
9860 clr_arg = argv[idx]->arg;
d62a17ae 9861 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9862 clr_sort = clear_as;
9863 clr_arg = argv[idx]->arg;
9864 } else if (argv_find(argv, argc, "external", &idx)) {
9865 clr_sort = clear_external;
9866 }
9867
9868 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9869 if (argv_find(argv, argc, "soft", &idx)) {
9870 if (argv_find(argv, argc, "in", &idx)
9871 || argv_find(argv, argc, "out", &idx))
9872 clr_type = strmatch(argv[idx]->text, "in")
9873 ? BGP_CLEAR_SOFT_IN
9874 : BGP_CLEAR_SOFT_OUT;
9875 else
9876 clr_type = BGP_CLEAR_SOFT_BOTH;
9877 } else if (argv_find(argv, argc, "in", &idx)) {
9878 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9879 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9880 : BGP_CLEAR_SOFT_IN;
9881 } else if (argv_find(argv, argc, "out", &idx)) {
9882 clr_type = BGP_CLEAR_SOFT_OUT;
9883 } else
9884 clr_type = BGP_CLEAR_SOFT_NONE;
9885
ff8a8a7a
CS
9886 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9887 sizeof(errmsg));
9888 if (ret != NB_OK)
9889 vty_out(vty, "Error description: %s\n", errmsg);
9890
9891 return ret;
838758ac 9892}
01080f7c 9893
8ad7271d
DS
9894DEFUN (clear_ip_bgp_prefix,
9895 clear_ip_bgp_prefix_cmd,
18c57037 9896 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9897 CLEAR_STR
9898 IP_STR
9899 BGP_STR
838758ac 9900 BGP_INSTANCE_HELP_STR
8ad7271d 9901 "Clear bestpath and re-advertise\n"
0c7b1b01 9902 "IPv4 prefix\n")
8ad7271d 9903{
d62a17ae 9904 char *vrf = NULL;
9905 char *prefix = NULL;
8ad7271d 9906
d62a17ae 9907 int idx = 0;
01080f7c 9908
d62a17ae 9909 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9910 if (argv_find(argv, argc, "vrf", &idx)) {
9911 vrf = argv[idx + 1]->arg;
9912 idx += 2;
9913 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9914 vrf = NULL;
9915 } else if (argv_find(argv, argc, "view", &idx)) {
9916 /* [<view> VIEWVRFNAME] */
9917 vrf = argv[idx + 1]->arg;
9918 idx += 2;
9919 }
0c7b1b01 9920
d62a17ae 9921 prefix = argv[argc - 1]->arg;
8ad7271d 9922
d62a17ae 9923 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9924}
8ad7271d 9925
b09b5ae0
DW
9926DEFUN (clear_bgp_ipv6_safi_prefix,
9927 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9928 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9929 CLEAR_STR
3a2d747c 9930 IP_STR
718e3744 9931 BGP_STR
8c3deaae 9932 "Address Family\n"
46f296b4 9933 BGP_SAFI_HELP_STR
b09b5ae0 9934 "Clear bestpath and re-advertise\n"
0c7b1b01 9935 "IPv6 prefix\n")
718e3744 9936{
9b475e76
PG
9937 int idx_safi = 0;
9938 int idx_ipv6_prefix = 0;
9939 safi_t safi = SAFI_UNICAST;
9940 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9941 argv[idx_ipv6_prefix]->arg : NULL;
9942
9943 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9944 return bgp_clear_prefix(
9b475e76
PG
9945 vty, NULL, prefix, AFI_IP6,
9946 safi, NULL);
838758ac 9947}
01080f7c 9948
b09b5ae0
DW
9949DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9950 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9951 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9952 CLEAR_STR
3a2d747c 9953 IP_STR
718e3744 9954 BGP_STR
838758ac 9955 BGP_INSTANCE_HELP_STR
8c3deaae 9956 "Address Family\n"
46f296b4 9957 BGP_SAFI_HELP_STR
b09b5ae0 9958 "Clear bestpath and re-advertise\n"
0c7b1b01 9959 "IPv6 prefix\n")
718e3744 9960{
9b475e76 9961 int idx_safi = 0;
9a8bdf1c 9962 int idx_vrfview = 0;
9b475e76
PG
9963 int idx_ipv6_prefix = 0;
9964 safi_t safi = SAFI_UNICAST;
9965 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9966 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9967 char *vrfview = NULL;
9b475e76 9968
9a8bdf1c
PG
9969 /* [<view|vrf> VIEWVRFNAME] */
9970 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9971 vrfview = argv[idx_vrfview + 1]->arg;
9972 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9973 vrfview = NULL;
9974 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9975 /* [<view> VIEWVRFNAME] */
9976 vrfview = argv[idx_vrfview + 1]->arg;
9977 }
9b475e76
PG
9978 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9979
d62a17ae 9980 return bgp_clear_prefix(
9b475e76
PG
9981 vty, vrfview, prefix,
9982 AFI_IP6, safi, NULL);
718e3744 9983}
9984
b09b5ae0
DW
9985DEFUN (show_bgp_views,
9986 show_bgp_views_cmd,
d6e3c605 9987 "show [ip] bgp views",
b09b5ae0 9988 SHOW_STR
d6e3c605 9989 IP_STR
01080f7c 9990 BGP_STR
b09b5ae0 9991 "Show the defined BGP views\n")
01080f7c 9992{
d62a17ae 9993 struct list *inst = bm->bgp;
9994 struct listnode *node;
9995 struct bgp *bgp;
01080f7c 9996
d62a17ae 9997 vty_out(vty, "Defined BGP views:\n");
9998 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9999 /* Skip VRFs. */
10000 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10001 continue;
10002 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10003 bgp->as);
10004 }
e52702f2 10005
d62a17ae 10006 return CMD_SUCCESS;
e0081f70
ML
10007}
10008
8386ac43 10009DEFUN (show_bgp_vrfs,
10010 show_bgp_vrfs_cmd,
d6e3c605 10011 "show [ip] bgp vrfs [json]",
8386ac43 10012 SHOW_STR
d6e3c605 10013 IP_STR
8386ac43 10014 BGP_STR
10015 "Show BGP VRFs\n"
9973d184 10016 JSON_STR)
8386ac43 10017{
fe1dc5a3 10018 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10019 struct list *inst = bm->bgp;
10020 struct listnode *node;
10021 struct bgp *bgp;
9f049418 10022 bool uj = use_json(argc, argv);
d62a17ae 10023 json_object *json = NULL;
10024 json_object *json_vrfs = NULL;
10025 int count = 0;
d62a17ae 10026
d62a17ae 10027 if (uj) {
10028 json = json_object_new_object();
10029 json_vrfs = json_object_new_object();
10030 }
10031
10032 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10033 const char *name, *type;
10034 struct peer *peer;
7fe96307 10035 struct listnode *node2, *nnode2;
d62a17ae 10036 int peers_cfg, peers_estb;
10037 json_object *json_vrf = NULL;
d62a17ae 10038
10039 /* Skip Views. */
10040 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10041 continue;
10042
10043 count++;
efb4077a 10044 if (!uj && count == 1) {
fe1dc5a3 10045 vty_out(vty,
efb4077a 10046 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10047 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10048 "#PeersEstb", "Name");
10049 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10050 "L3-VNI", "RouterMAC", "Interface");
10051 }
d62a17ae 10052
10053 peers_cfg = peers_estb = 0;
10054 if (uj)
10055 json_vrf = json_object_new_object();
10056
10057
7fe96307 10058 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10059 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10060 continue;
10061 peers_cfg++;
10062 if (peer->status == Established)
10063 peers_estb++;
10064 }
10065
10066 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10067 name = VRF_DEFAULT_NAME;
d62a17ae 10068 type = "DFLT";
10069 } else {
10070 name = bgp->name;
10071 type = "VRF";
10072 }
10073
a8bf7d9c 10074
d62a17ae 10075 if (uj) {
a4d82a8a
PZ
10076 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10077 ? -1
10078 : (int64_t)bgp->vrf_id;
23d0a753
DA
10079 char buf[BUFSIZ] = {0};
10080
d62a17ae 10081 json_object_string_add(json_vrf, "type", type);
10082 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10083 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
10084 inet_ntop(AF_INET,
10085 &bgp->router_id, buf,
10086 sizeof(buf)));
d62a17ae 10087 json_object_int_add(json_vrf, "numConfiguredPeers",
10088 peers_cfg);
10089 json_object_int_add(json_vrf, "numEstablishedPeers",
10090 peers_estb);
10091
fe1dc5a3 10092 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10093 json_object_string_add(
10094 json_vrf, "rmac",
10095 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10096 json_object_string_add(json_vrf, "interface",
10097 ifindex2ifname(bgp->l3vni_svi_ifindex,
10098 bgp->vrf_id));
d62a17ae 10099 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10100 } else {
23d0a753 10101 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10102 type,
10103 bgp->vrf_id == VRF_UNKNOWN ? -1
10104 : (int)bgp->vrf_id,
23d0a753 10105 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10106 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10107 bgp->l3vni,
10108 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10109 ifindex2ifname(bgp->l3vni_svi_ifindex,
10110 bgp->vrf_id));
10111 }
d62a17ae 10112 }
10113
10114 if (uj) {
10115 json_object_object_add(json, "vrfs", json_vrfs);
10116
10117 json_object_int_add(json, "totalVrfs", count);
10118
996c9314
LB
10119 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10120 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10121 json_object_free(json);
10122 } else {
10123 if (count)
10124 vty_out(vty,
10125 "\nTotal number of VRFs (including default): %d\n",
10126 count);
10127 }
10128
10129 return CMD_SUCCESS;
8386ac43 10130}
10131
48ecf8f5
DS
10132DEFUN (show_bgp_mac_hash,
10133 show_bgp_mac_hash_cmd,
10134 "show bgp mac hash",
10135 SHOW_STR
10136 BGP_STR
10137 "Mac Address\n"
10138 "Mac Address database\n")
10139{
10140 bgp_mac_dump_table(vty);
10141
10142 return CMD_SUCCESS;
10143}
acf71666 10144
e3b78da8 10145static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10146{
0291c246 10147 struct vty *vty = (struct vty *)args;
e3b78da8 10148 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10149
23d0a753 10150 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10151}
10152
10153static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10154{
10155 vty_out(vty, "self nexthop database:\n");
af97a18b 10156 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10157
10158 vty_out(vty, "Tunnel-ip database:\n");
10159 hash_iterate(bgp->tip_hash,
e3b78da8 10160 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10161 vty);
10162}
10163
15c81ca4
DS
10164DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10165 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10166 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10167 "martian next-hops\n"
10168 "martian next-hop database\n")
acf71666 10169{
0291c246 10170 struct bgp *bgp = NULL;
15c81ca4 10171 int idx = 0;
9a8bdf1c
PG
10172 char *name = NULL;
10173
10174 /* [<vrf> VIEWVRFNAME] */
10175 if (argv_find(argv, argc, "vrf", &idx)) {
10176 name = argv[idx + 1]->arg;
10177 if (name && strmatch(name, VRF_DEFAULT_NAME))
10178 name = NULL;
10179 } else if (argv_find(argv, argc, "view", &idx))
10180 /* [<view> VIEWVRFNAME] */
10181 name = argv[idx + 1]->arg;
10182 if (name)
10183 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10184 else
10185 bgp = bgp_get_default();
acf71666 10186
acf71666
MK
10187 if (!bgp) {
10188 vty_out(vty, "%% No BGP process is configured\n");
10189 return CMD_WARNING;
10190 }
10191 bgp_show_martian_nexthops(vty, bgp);
10192
10193 return CMD_SUCCESS;
10194}
10195
f412b39a 10196DEFUN (show_bgp_memory,
4bf6a362 10197 show_bgp_memory_cmd,
7fa12b13 10198 "show [ip] bgp memory",
4bf6a362 10199 SHOW_STR
3a2d747c 10200 IP_STR
4bf6a362
PJ
10201 BGP_STR
10202 "Global BGP memory statistics\n")
10203{
d62a17ae 10204 char memstrbuf[MTYPE_MEMSTR_LEN];
10205 unsigned long count;
10206
10207 /* RIB related usage stats */
10208 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10209 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10210 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10211 count * sizeof(struct bgp_dest)));
d62a17ae 10212
10213 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10214 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10215 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10216 count * sizeof(struct bgp_path_info)));
d62a17ae 10217 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10218 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10219 count,
4b7e6066
DS
10220 mtype_memstr(
10221 memstrbuf, sizeof(memstrbuf),
10222 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10223
10224 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10225 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10226 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10227 count * sizeof(struct bgp_static)));
10228
10229 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10230 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10231 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10232 count * sizeof(struct bpacket)));
10233
10234 /* Adj-In/Out */
10235 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10236 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10237 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10238 count * sizeof(struct bgp_adj_in)));
10239 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10240 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10241 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10242 count * sizeof(struct bgp_adj_out)));
10243
10244 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10245 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10246 count,
10247 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10248 count * sizeof(struct bgp_nexthop_cache)));
10249
10250 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10251 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10252 count,
10253 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10254 count * sizeof(struct bgp_damp_info)));
10255
10256 /* Attributes */
10257 count = attr_count();
10258 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10259 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10260 count * sizeof(struct attr)));
10261
10262 if ((count = attr_unknown_count()))
10263 vty_out(vty, "%ld unknown attributes\n", count);
10264
10265 /* AS_PATH attributes */
10266 count = aspath_count();
10267 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10268 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10269 count * sizeof(struct aspath)));
10270
10271 count = mtype_stats_alloc(MTYPE_AS_SEG);
10272 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10273 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10274 count * sizeof(struct assegment)));
10275
10276 /* Other attributes */
10277 if ((count = community_count()))
10278 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10279 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10280 count * sizeof(struct community)));
d62a17ae 10281 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10282 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10283 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10284 count * sizeof(struct ecommunity)));
d62a17ae 10285 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10286 vty_out(vty,
10287 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10288 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10289 count * sizeof(struct lcommunity)));
d62a17ae 10290
10291 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10292 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10293 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10294 count * sizeof(struct cluster_list)));
10295
10296 /* Peer related usage */
10297 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10298 vty_out(vty, "%ld peers, using %s of memory\n", count,
10299 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10300 count * sizeof(struct peer)));
10301
10302 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10303 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10304 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10305 count * sizeof(struct peer_group)));
10306
10307 /* Other */
d62a17ae 10308 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10309 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10310 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10311 count * sizeof(regex_t)));
d62a17ae 10312 return CMD_SUCCESS;
4bf6a362 10313}
fee0f4c6 10314
57a9c8a8
DS
10315static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10316{
10317 json_object *bestpath = json_object_new_object();
10318
892fedb6 10319 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10320 json_object_string_add(bestpath, "asPath", "ignore");
10321
892fedb6 10322 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10323 json_object_string_add(bestpath, "asPath", "confed");
10324
892fedb6
DA
10325 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10326 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10327 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10328 "as-set");
10329 else
a4d82a8a 10330 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10331 "true");
10332 } else
a4d82a8a 10333 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10334
892fedb6 10335 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10336 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10337 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10338 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10339 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10340 json_object_string_add(bestpath, "med", "confed");
892fedb6 10341 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10342 json_object_string_add(bestpath, "med",
10343 "missing-as-worst");
10344 else
10345 json_object_string_add(bestpath, "med", "true");
10346 }
10347
10348 json_object_object_add(json, "bestPath", bestpath);
10349}
10350
3577f1c5
DD
10351/* Print the error code/subcode for why the peer is down */
10352static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10353 json_object *json_peer, bool use_json)
10354{
10355 const char *code_str;
10356 const char *subcode_str;
10357
10358 if (use_json) {
10359 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10360 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10361 char errorcodesubcode_hexstr[5];
10362 char errorcodesubcode_str[256];
10363
10364 code_str = bgp_notify_code_str(peer->notify.code);
10365 subcode_str = bgp_notify_subcode_str(
10366 peer->notify.code,
10367 peer->notify.subcode);
10368
772270f3
QY
10369 snprintf(errorcodesubcode_hexstr,
10370 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10371 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10372 json_object_string_add(json_peer,
10373 "lastErrorCodeSubcode",
10374 errorcodesubcode_hexstr);
10375 snprintf(errorcodesubcode_str, 255, "%s%s",
10376 code_str, subcode_str);
10377 json_object_string_add(json_peer,
10378 "lastNotificationReason",
10379 errorcodesubcode_str);
10380 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10381 && peer->notify.code == BGP_NOTIFY_CEASE
10382 && (peer->notify.subcode
10383 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10384 || peer->notify.subcode
10385 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10386 && peer->notify.length) {
10387 char msgbuf[1024];
10388 const char *msg_str;
10389
10390 msg_str = bgp_notify_admin_message(
10391 msgbuf, sizeof(msgbuf),
10392 (uint8_t *)peer->notify.data,
10393 peer->notify.length);
10394 if (msg_str)
10395 json_object_string_add(
10396 json_peer,
10397 "lastShutdownDescription",
10398 msg_str);
10399 }
10400
c258527b 10401 }
3577f1c5
DD
10402 json_object_string_add(json_peer, "lastResetDueTo",
10403 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10404 json_object_int_add(json_peer, "lastResetCode",
10405 peer->last_reset);
3577f1c5
DD
10406 } else {
10407 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10408 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10409 code_str = bgp_notify_code_str(peer->notify.code);
10410 subcode_str =
10411 bgp_notify_subcode_str(peer->notify.code,
10412 peer->notify.subcode);
10413 vty_out(vty, " Notification %s (%s%s)\n",
10414 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10415 ? "sent"
10416 : "received",
10417 code_str, subcode_str);
10418 } else {
e91c24c8 10419 vty_out(vty, " %s\n",
3577f1c5
DD
10420 peer_down_str[(int)peer->last_reset]);
10421 }
10422 }
10423}
10424
10425static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10426 safi_t safi)
10427{
10428 return ((peer->status != Established) ||
10429 !peer->afc_recv[afi][safi]);
10430}
10431
10432static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10433 struct peer *peer, json_object *json_peer,
10434 int max_neighbor_width, bool use_json)
10435{
10436 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10437 int len;
10438
10439 if (use_json) {
10440 if (peer_dynamic_neighbor(peer))
10441 json_object_boolean_true_add(json_peer,
10442 "dynamicPeer");
10443 if (peer->hostname)
10444 json_object_string_add(json_peer, "hostname",
10445 peer->hostname);
10446
10447 if (peer->domainname)
10448 json_object_string_add(json_peer, "domainname",
10449 peer->domainname);
10450 json_object_int_add(json_peer, "connectionsEstablished",
10451 peer->established);
10452 json_object_int_add(json_peer, "connectionsDropped",
10453 peer->dropped);
10454 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10455 use_json, json_peer);
10456 if (peer->status == Established)
10457 json_object_string_add(json_peer, "lastResetDueTo",
10458 "AFI/SAFI Not Negotiated");
10459 else
10460 bgp_show_peer_reset(NULL, peer, json_peer, true);
10461 } else {
10462 dn_flag[1] = '\0';
10463 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10464 if (peer->hostname
892fedb6 10465 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10466 len = vty_out(vty, "%s%s(%s)", dn_flag,
10467 peer->hostname, peer->host);
10468 else
10469 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10470
10471 /* pad the neighbor column with spaces */
10472 if (len < max_neighbor_width)
10473 vty_out(vty, "%*s", max_neighbor_width - len,
10474 " ");
e91c24c8 10475 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10476 peer->dropped,
10477 peer_uptime(peer->uptime, timebuf,
10478 BGP_UPTIME_LEN, 0, NULL));
10479 if (peer->status == Established)
10480 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10481 else
10482 bgp_show_peer_reset(vty, peer, NULL,
10483 false);
10484 }
10485}
c258527b 10486
3577f1c5 10487
718e3744 10488/* Show BGP peer's summary information. */
d62a17ae 10489static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10b49f14
DA
10490 bool show_failed, bool show_established,
10491 bool use_json)
d62a17ae 10492{
10493 struct peer *peer;
10494 struct listnode *node, *nnode;
10495 unsigned int count = 0, dn_count = 0;
10496 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10497 char neighbor_buf[VTY_BUFSIZ];
10498 int neighbor_col_default_width = 16;
3577f1c5 10499 int len, failed_count = 0;
d62a17ae 10500 int max_neighbor_width = 0;
10501 int pfx_rcd_safi;
3c13337d 10502 json_object *json = NULL;
d62a17ae 10503 json_object *json_peer = NULL;
10504 json_object *json_peers = NULL;
50e05855 10505 struct peer_af *paf;
d3ada366 10506 struct bgp_filter *filter;
d62a17ae 10507
10508 /* labeled-unicast routes are installed in the unicast table so in order
10509 * to
10510 * display the correct PfxRcd value we must look at SAFI_UNICAST
10511 */
3577f1c5 10512
d62a17ae 10513 if (safi == SAFI_LABELED_UNICAST)
10514 pfx_rcd_safi = SAFI_UNICAST;
10515 else
10516 pfx_rcd_safi = safi;
10517
10518 if (use_json) {
3c13337d 10519 json = json_object_new_object();
d62a17ae 10520 json_peers = json_object_new_object();
3577f1c5
DD
10521 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10522 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10523 continue;
10524
10525 if (peer->afc[afi][safi]) {
10526 /* See if we have at least a single failed peer */
10527 if (bgp_has_peer_failed(peer, afi, safi))
10528 failed_count++;
10529 count++;
10530 }
10531 if (peer_dynamic_neighbor(peer))
10532 dn_count++;
10533 }
c258527b 10534
d62a17ae 10535 } else {
10536 /* Loop over all neighbors that will be displayed to determine
10537 * how many
10538 * characters are needed for the Neighbor column
10539 */
10540 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10541 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10542 continue;
10543
10544 if (peer->afc[afi][safi]) {
10545 memset(dn_flag, '\0', sizeof(dn_flag));
10546 if (peer_dynamic_neighbor(peer))
10547 dn_flag[0] = '*';
10548
10549 if (peer->hostname
892fedb6
DA
10550 && CHECK_FLAG(bgp->flags,
10551 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10552 snprintf(neighbor_buf,
10553 sizeof(neighbor_buf),
10554 "%s%s(%s) ", dn_flag,
10555 peer->hostname, peer->host);
d62a17ae 10556 else
772270f3
QY
10557 snprintf(neighbor_buf,
10558 sizeof(neighbor_buf), "%s%s ",
10559 dn_flag, peer->host);
d62a17ae 10560
10561 len = strlen(neighbor_buf);
10562
10563 if (len > max_neighbor_width)
10564 max_neighbor_width = len;
c258527b 10565
3577f1c5
DD
10566 /* See if we have at least a single failed peer */
10567 if (bgp_has_peer_failed(peer, afi, safi))
10568 failed_count++;
10569 count++;
d62a17ae 10570 }
10571 }
f933309e 10572
d62a17ae 10573 /* Originally we displayed the Neighbor column as 16
10574 * characters wide so make that the default
10575 */
10576 if (max_neighbor_width < neighbor_col_default_width)
10577 max_neighbor_width = neighbor_col_default_width;
10578 }
f933309e 10579
3577f1c5
DD
10580 if (show_failed && !failed_count) {
10581 if (use_json) {
10582 json_object_int_add(json, "failedPeersCount", 0);
10583 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10584 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
10585
10586 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10587 json, JSON_C_TO_STRING_PRETTY));
10588 json_object_free(json);
10589 } else {
10590 vty_out(vty, "%% No failed BGP neighbors found\n");
10591 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10592 }
10593 return CMD_SUCCESS;
10594 }
c258527b 10595
3577f1c5 10596 count = 0; /* Reset the value as its used again */
d62a17ae 10597 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10598 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10599 continue;
10600
ea47320b
DL
10601 if (!peer->afc[afi][safi])
10602 continue;
d62a17ae 10603
ea47320b
DL
10604 if (!count) {
10605 unsigned long ents;
10606 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10607 int64_t vrf_id_ui;
d62a17ae 10608
a4d82a8a
PZ
10609 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10610 ? -1
10611 : (int64_t)bgp->vrf_id;
ea47320b
DL
10612
10613 /* Usage summary and header */
10614 if (use_json) {
23d0a753
DA
10615 char buf[BUFSIZ] = {0};
10616
ea47320b
DL
10617 json_object_string_add(
10618 json, "routerId",
23d0a753
DA
10619 inet_ntop(AF_INET, &bgp->router_id, buf,
10620 sizeof(buf)));
60466a63
QY
10621 json_object_int_add(json, "as", bgp->as);
10622 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10623 json_object_string_add(
10624 json, "vrfName",
10625 (bgp->inst_type
10626 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10627 ? VRF_DEFAULT_NAME
ea47320b
DL
10628 : bgp->name);
10629 } else {
10630 vty_out(vty,
23d0a753
DA
10631 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10632 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10633 bgp->vrf_id == VRF_UNKNOWN
10634 ? -1
10635 : (int)bgp->vrf_id);
ea47320b
DL
10636 vty_out(vty, "\n");
10637 }
d62a17ae 10638
ea47320b 10639 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10640 if (use_json) {
ea47320b 10641 json_object_int_add(
60466a63 10642 json, "updateDelayLimit",
ea47320b 10643 bgp->v_update_delay);
d62a17ae 10644
ea47320b
DL
10645 if (bgp->v_update_delay
10646 != bgp->v_establish_wait)
d62a17ae 10647 json_object_int_add(
10648 json,
ea47320b
DL
10649 "updateDelayEstablishWait",
10650 bgp->v_establish_wait);
d62a17ae 10651
60466a63 10652 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10653 json_object_string_add(
10654 json,
10655 "updateDelayFirstNeighbor",
10656 bgp->update_delay_begin_time);
10657 json_object_boolean_true_add(
10658 json,
10659 "updateDelayInProgress");
10660 } else {
10661 if (bgp->update_delay_over) {
d62a17ae 10662 json_object_string_add(
10663 json,
10664 "updateDelayFirstNeighbor",
10665 bgp->update_delay_begin_time);
ea47320b 10666 json_object_string_add(
d62a17ae 10667 json,
ea47320b
DL
10668 "updateDelayBestpathResumed",
10669 bgp->update_delay_end_time);
10670 json_object_string_add(
d62a17ae 10671 json,
ea47320b
DL
10672 "updateDelayZebraUpdateResume",
10673 bgp->update_delay_zebra_resume_time);
10674 json_object_string_add(
10675 json,
10676 "updateDelayPeerUpdateResume",
10677 bgp->update_delay_peers_resume_time);
d62a17ae 10678 }
ea47320b
DL
10679 }
10680 } else {
10681 vty_out(vty,
10682 "Read-only mode update-delay limit: %d seconds\n",
10683 bgp->v_update_delay);
10684 if (bgp->v_update_delay
10685 != bgp->v_establish_wait)
d62a17ae 10686 vty_out(vty,
ea47320b
DL
10687 " Establish wait: %d seconds\n",
10688 bgp->v_establish_wait);
d62a17ae 10689
60466a63 10690 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10691 vty_out(vty,
10692 " First neighbor established: %s\n",
10693 bgp->update_delay_begin_time);
10694 vty_out(vty,
10695 " Delay in progress\n");
10696 } else {
10697 if (bgp->update_delay_over) {
d62a17ae 10698 vty_out(vty,
10699 " First neighbor established: %s\n",
10700 bgp->update_delay_begin_time);
10701 vty_out(vty,
ea47320b
DL
10702 " Best-paths resumed: %s\n",
10703 bgp->update_delay_end_time);
10704 vty_out(vty,
10705 " zebra update resumed: %s\n",
10706 bgp->update_delay_zebra_resume_time);
10707 vty_out(vty,
10708 " peers update resumed: %s\n",
10709 bgp->update_delay_peers_resume_time);
d62a17ae 10710 }
10711 }
10712 }
ea47320b 10713 }
d62a17ae 10714
ea47320b
DL
10715 if (use_json) {
10716 if (bgp_maxmed_onstartup_configured(bgp)
10717 && bgp->maxmed_active)
10718 json_object_boolean_true_add(
60466a63 10719 json, "maxMedOnStartup");
ea47320b
DL
10720 if (bgp->v_maxmed_admin)
10721 json_object_boolean_true_add(
60466a63 10722 json, "maxMedAdministrative");
d62a17ae 10723
ea47320b
DL
10724 json_object_int_add(
10725 json, "tableVersion",
60466a63 10726 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10727
60466a63
QY
10728 ents = bgp_table_count(bgp->rib[afi][safi]);
10729 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10730 json_object_int_add(
10731 json, "ribMemory",
9bcb3eef 10732 ents * sizeof(struct bgp_dest));
d62a17ae 10733
210ec2a0 10734 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10735 json_object_int_add(json, "peerCount", ents);
10736 json_object_int_add(json, "peerMemory",
10737 ents * sizeof(struct peer));
d62a17ae 10738
ea47320b
DL
10739 if ((ents = listcount(bgp->group))) {
10740 json_object_int_add(
60466a63 10741 json, "peerGroupCount", ents);
ea47320b
DL
10742 json_object_int_add(
10743 json, "peerGroupMemory",
996c9314
LB
10744 ents * sizeof(struct
10745 peer_group));
ea47320b 10746 }
d62a17ae 10747
ea47320b
DL
10748 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10749 BGP_CONFIG_DAMPENING))
10750 json_object_boolean_true_add(
60466a63 10751 json, "dampeningEnabled");
ea47320b
DL
10752 } else {
10753 if (bgp_maxmed_onstartup_configured(bgp)
10754 && bgp->maxmed_active)
d62a17ae 10755 vty_out(vty,
ea47320b
DL
10756 "Max-med on-startup active\n");
10757 if (bgp->v_maxmed_admin)
d62a17ae 10758 vty_out(vty,
ea47320b 10759 "Max-med administrative active\n");
d62a17ae 10760
60466a63
QY
10761 vty_out(vty, "BGP table version %" PRIu64 "\n",
10762 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 10763
60466a63 10764 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
10765 vty_out(vty,
10766 "RIB entries %ld, using %s of memory\n",
10767 ents,
9bcb3eef
DS
10768 mtype_memstr(
10769 memstrbuf, sizeof(memstrbuf),
10770 ents
10771 * sizeof(struct
10772 bgp_dest)));
ea47320b
DL
10773
10774 /* Peer related usage */
210ec2a0 10775 ents = bgp->af_peer_count[afi][safi];
60466a63 10776 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
10777 ents,
10778 mtype_memstr(
60466a63
QY
10779 memstrbuf, sizeof(memstrbuf),
10780 ents * sizeof(struct peer)));
ea47320b
DL
10781
10782 if ((ents = listcount(bgp->group)))
d62a17ae 10783 vty_out(vty,
ea47320b 10784 "Peer groups %ld, using %s of memory\n",
d62a17ae 10785 ents,
10786 mtype_memstr(
10787 memstrbuf,
10788 sizeof(memstrbuf),
996c9314
LB
10789 ents * sizeof(struct
10790 peer_group)));
d62a17ae 10791
ea47320b
DL
10792 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10793 BGP_CONFIG_DAMPENING))
60466a63 10794 vty_out(vty, "Dampening enabled.\n");
ea47320b 10795 vty_out(vty, "\n");
d62a17ae 10796
ea47320b
DL
10797 /* Subtract 8 here because 'Neighbor' is
10798 * 8 characters */
10799 vty_out(vty, "Neighbor");
60466a63
QY
10800 vty_out(vty, "%*s", max_neighbor_width - 8,
10801 " ");
3577f1c5
DD
10802 if (show_failed)
10803 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
10804 else
10805 vty_out(vty,
aa72bd7e 10806 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n");
d62a17ae 10807 }
ea47320b 10808 }
d62a17ae 10809
d55811cc 10810 paf = peer_af_find(peer, afi, safi);
d3ada366 10811 filter = &peer->filter[afi][safi];
db92d226 10812
ea47320b 10813 count++;
3577f1c5
DD
10814 /* Works for both failed & successful cases */
10815 if (peer_dynamic_neighbor(peer))
10816 dn_count++;
d62a17ae 10817
ea47320b 10818 if (use_json) {
3577f1c5
DD
10819 json_peer = NULL;
10820
10821 if (show_failed &&
10822 bgp_has_peer_failed(peer, afi, safi)) {
10823 json_peer = json_object_new_object();
10824 bgp_show_failed_summary(vty, bgp, peer,
10825 json_peer, 0, use_json);
10826 } else if (!show_failed) {
10b49f14
DA
10827 if (show_established
10828 && bgp_has_peer_failed(peer, afi, safi))
10829 continue;
10830
3577f1c5
DD
10831 json_peer = json_object_new_object();
10832 if (peer_dynamic_neighbor(peer)) {
10833 json_object_boolean_true_add(json_peer,
10834 "dynamicPeer");
10835 }
d62a17ae 10836
3577f1c5
DD
10837 if (peer->hostname)
10838 json_object_string_add(json_peer, "hostname",
10839 peer->hostname);
10840
10841 if (peer->domainname)
10842 json_object_string_add(json_peer, "domainname",
10843 peer->domainname);
10844
10845 json_object_int_add(json_peer, "remoteAs", peer->as);
10846 json_object_int_add(json_peer, "version", 4);
10847 json_object_int_add(json_peer, "msgRcvd",
10848 PEER_TOTAL_RX(peer));
10849 json_object_int_add(json_peer, "msgSent",
10850 PEER_TOTAL_TX(peer));
10851
43aa5965
QY
10852 atomic_size_t outq_count, inq_count;
10853 outq_count = atomic_load_explicit(
10854 &peer->obuf->count,
10855 memory_order_relaxed);
10856 inq_count = atomic_load_explicit(
10857 &peer->ibuf->count,
10858 memory_order_relaxed);
10859
3577f1c5
DD
10860 json_object_int_add(json_peer, "tableVersion",
10861 peer->version[afi][safi]);
10862 json_object_int_add(json_peer, "outq",
43aa5965
QY
10863 outq_count);
10864 json_object_int_add(json_peer, "inq",
10865 inq_count);
3577f1c5
DD
10866 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10867 use_json, json_peer);
10868
3577f1c5
DD
10869 json_object_int_add(json_peer, "pfxRcd",
10870 peer->pcount[afi][pfx_rcd_safi]);
10871
3577f1c5 10872 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10873 json_object_int_add(
10874 json_peer, "pfxSnt",
10875 (PAF_SUBGRP(paf))->scount);
10876 else
10877 json_object_int_add(json_peer, "pfxSnt",
10878 0);
0e1f8ab5
DA
10879
10880 /* BGP FSM state */
cb9196e7 10881 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10882 || CHECK_FLAG(peer->bgp->flags,
10883 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10884 json_object_string_add(json_peer,
10885 "state",
3577f1c5
DD
10886 "Idle (Admin)");
10887 else if (peer->afc_recv[afi][safi])
10888 json_object_string_add(
0e1f8ab5
DA
10889 json_peer, "state",
10890 lookup_msg(bgp_status_msg,
10891 peer->status, NULL));
10892 else if (CHECK_FLAG(
10893 peer->sflags,
10894 PEER_STATUS_PREFIX_OVERFLOW))
10895 json_object_string_add(json_peer,
10896 "state",
3577f1c5
DD
10897 "Idle (PfxCt)");
10898 else
10899 json_object_string_add(
0e1f8ab5
DA
10900 json_peer, "state",
10901 lookup_msg(bgp_status_msg,
10902 peer->status, NULL));
10903
10904 /* BGP peer state */
10905 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10906 || CHECK_FLAG(peer->bgp->flags,
10907 BGP_FLAG_SHUTDOWN))
10908 json_object_string_add(json_peer,
10909 "peerState",
10910 "Admin");
10911 else if (CHECK_FLAG(
10912 peer->sflags,
10913 PEER_STATUS_PREFIX_OVERFLOW))
10914 json_object_string_add(json_peer,
10915 "peerState",
10916 "PfxCt");
10917 else if (CHECK_FLAG(peer->flags,
10918 PEER_FLAG_PASSIVE))
10919 json_object_string_add(json_peer,
10920 "peerState",
10921 "Passive");
10922 else if (CHECK_FLAG(peer->sflags,
10923 PEER_STATUS_NSF_WAIT))
10924 json_object_string_add(json_peer,
10925 "peerState",
10926 "NSF passive");
10927 else if (CHECK_FLAG(
10928 peer->bgp->flags,
10929 BGP_FLAG_EBGP_REQUIRES_POLICY)
10930 && (!bgp_inbound_policy_exists(peer,
10931 filter)
10932 || !bgp_outbound_policy_exists(
10933 peer, filter)))
10934 json_object_string_add(json_peer,
10935 "peerState",
10936 "Policy");
10937 else
10938 json_object_string_add(
10939 json_peer, "peerState", "OK");
10940
200116db
DD
10941 json_object_int_add(json_peer, "connectionsEstablished",
10942 peer->established);
10943 json_object_int_add(json_peer, "connectionsDropped",
10944 peer->dropped);
aa72bd7e
PG
10945 if (peer->desc)
10946 json_object_string_add(
10947 json_peer, "desc", peer->desc);
b4e9dcba 10948 }
3577f1c5
DD
10949 /* Avoid creating empty peer dicts in JSON */
10950 if (json_peer == NULL)
10951 continue;
ea47320b
DL
10952
10953 if (peer->conf_if)
60466a63 10954 json_object_string_add(json_peer, "idType",
ea47320b
DL
10955 "interface");
10956 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10957 json_object_string_add(json_peer, "idType",
10958 "ipv4");
ea47320b 10959 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10960 json_object_string_add(json_peer, "idType",
10961 "ipv6");
ea47320b
DL
10962 json_object_object_add(json_peers, peer->host,
10963 json_peer);
10964 } else {
3577f1c5
DD
10965 if (show_failed &&
10966 bgp_has_peer_failed(peer, afi, safi)) {
10967 bgp_show_failed_summary(vty, bgp, peer, NULL,
10968 max_neighbor_width,
10969 use_json);
10970 } else if (!show_failed) {
10b49f14
DA
10971 if (show_established
10972 && bgp_has_peer_failed(peer, afi, safi))
10973 continue;
10974
3577f1c5
DD
10975 memset(dn_flag, '\0', sizeof(dn_flag));
10976 if (peer_dynamic_neighbor(peer)) {
10977 dn_flag[0] = '*';
10978 }
d62a17ae 10979
3577f1c5 10980 if (peer->hostname
892fedb6
DA
10981 && CHECK_FLAG(bgp->flags,
10982 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10983 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10984 peer->hostname,
10985 peer->host);
d62a17ae 10986 else
3577f1c5
DD
10987 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10988
10989 /* pad the neighbor column with spaces */
10990 if (len < max_neighbor_width)
10991 vty_out(vty, "%*s", max_neighbor_width - len,
10992 " ");
10993
43aa5965
QY
10994 atomic_size_t outq_count, inq_count;
10995 outq_count = atomic_load_explicit(
10996 &peer->obuf->count,
10997 memory_order_relaxed);
10998 inq_count = atomic_load_explicit(
10999 &peer->ibuf->count,
11000 memory_order_relaxed);
11001
566bdaf6 11002 vty_out(vty,
6cde4b45 11003 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
3577f1c5 11004 peer->as, PEER_TOTAL_RX(peer),
566bdaf6 11005 PEER_TOTAL_TX(peer),
43aa5965
QY
11006 peer->version[afi][safi], inq_count,
11007 outq_count,
3577f1c5
DD
11008 peer_uptime(peer->uptime, timebuf,
11009 BGP_UPTIME_LEN, 0, NULL));
11010
db92d226 11011 if (peer->status == Established) {
d3ada366
DA
11012 if (peer->afc_recv[afi][safi]) {
11013 if (CHECK_FLAG(
11014 bgp->flags,
11015 BGP_FLAG_EBGP_REQUIRES_POLICY)
11016 && !bgp_inbound_policy_exists(
11017 peer, filter))
11018 vty_out(vty, " %12s",
11019 "(Policy)");
11020 else
11021 vty_out(vty,
6cde4b45 11022 " %12u",
d3ada366
DA
11023 peer->pcount
11024 [afi]
11025 [pfx_rcd_safi]);
11026 } else {
3577f1c5 11027 vty_out(vty, " NoNeg");
d3ada366 11028 }
db92d226 11029
d3ada366
DA
11030 if (paf && PAF_SUBGRP(paf)) {
11031 if (CHECK_FLAG(
11032 bgp->flags,
11033 BGP_FLAG_EBGP_REQUIRES_POLICY)
11034 && !bgp_outbound_policy_exists(
11035 peer, filter))
11036 vty_out(vty, " %8s",
11037 "(Policy)");
11038 else
11039 vty_out(vty,
6cde4b45 11040 " %8u",
d3ada366
DA
11041 (PAF_SUBGRP(
11042 paf))
11043 ->scount);
11044 }
db92d226 11045 } else {
736b68f3
DS
11046 if (CHECK_FLAG(peer->flags,
11047 PEER_FLAG_SHUTDOWN)
11048 || CHECK_FLAG(peer->bgp->flags,
11049 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11050 vty_out(vty, " Idle (Admin)");
11051 else if (CHECK_FLAG(
11052 peer->sflags,
11053 PEER_STATUS_PREFIX_OVERFLOW))
11054 vty_out(vty, " Idle (PfxCt)");
11055 else
11056 vty_out(vty, " %12s",
11057 lookup_msg(bgp_status_msg,
11058 peer->status, NULL));
db92d226 11059
6cde4b45 11060 vty_out(vty, " %8u", 0);
3577f1c5 11061 }
aa72bd7e
PG
11062 if (peer->desc)
11063 vty_out(vty, " %s", peer->desc);
11064 else
11065 vty_out(vty, " N/A");
3577f1c5 11066 vty_out(vty, "\n");
d62a17ae 11067 }
3577f1c5 11068
d62a17ae 11069 }
11070 }
f933309e 11071
d62a17ae 11072 if (use_json) {
11073 json_object_object_add(json, "peers", json_peers);
3577f1c5 11074 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 11075 json_object_int_add(json, "totalPeers", count);
11076 json_object_int_add(json, "dynamicPeers", dn_count);
11077
3577f1c5
DD
11078 if (!show_failed)
11079 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11080
996c9314
LB
11081 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11082 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11083 json_object_free(json);
11084 } else {
11085 if (count)
11086 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11087 else {
d6ceaca3 11088 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11089 get_afi_safi_str(afi, safi, false));
d62a17ae 11090 }
b05a1c8b 11091
d6ceaca3 11092 if (dn_count) {
d62a17ae 11093 vty_out(vty, "* - dynamic neighbor\n");
11094 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11095 dn_count, bgp->dynamic_neighbors_limit);
11096 }
11097 }
1ff9a340 11098
d62a17ae 11099 return CMD_SUCCESS;
718e3744 11100}
11101
d62a17ae 11102static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10b49f14
DA
11103 int safi, bool show_failed,
11104 bool show_established, bool use_json)
d62a17ae 11105{
11106 int is_first = 1;
11107 int afi_wildcard = (afi == AFI_MAX);
11108 int safi_wildcard = (safi == SAFI_MAX);
11109 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11110 bool nbr_output = false;
d62a17ae 11111
11112 if (use_json && is_wildcard)
11113 vty_out(vty, "{\n");
11114 if (afi_wildcard)
11115 afi = 1; /* AFI_IP */
11116 while (afi < AFI_MAX) {
11117 if (safi_wildcard)
11118 safi = 1; /* SAFI_UNICAST */
11119 while (safi < SAFI_MAX) {
318cac96 11120 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11121 nbr_output = true;
f86897b9 11122
d62a17ae 11123 if (is_wildcard) {
11124 /*
11125 * So limit output to those afi/safi
11126 * pairs that
11127 * actualy have something interesting in
11128 * them
11129 */
11130 if (use_json) {
d62a17ae 11131 if (!is_first)
11132 vty_out(vty, ",\n");
11133 else
11134 is_first = 0;
11135
11136 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11137 get_afi_safi_str(afi,
11138 safi,
11139 true));
d62a17ae 11140 } else {
11141 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
11142 get_afi_safi_str(afi,
11143 safi,
11144 false));
d62a17ae 11145 }
11146 }
10b49f14
DA
11147 bgp_show_summary(vty, bgp, afi, safi,
11148 show_failed, show_established,
3577f1c5 11149 use_json);
d62a17ae 11150 }
11151 safi++;
d62a17ae 11152 if (!safi_wildcard)
11153 safi = SAFI_MAX;
11154 }
11155 afi++;
ee851c8c 11156 if (!afi_wildcard)
d62a17ae 11157 afi = AFI_MAX;
11158 }
11159
11160 if (use_json && is_wildcard)
11161 vty_out(vty, "}\n");
ca61fd25
DS
11162 else if (!nbr_output) {
11163 if (use_json)
11164 vty_out(vty, "{}\n");
11165 else
11166 vty_out(vty, "%% No BGP neighbors found\n");
11167 }
d62a17ae 11168}
11169
11170static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5 11171 safi_t safi, bool show_failed,
10b49f14 11172 bool show_established,
3577f1c5 11173 bool use_json)
d62a17ae 11174{
11175 struct listnode *node, *nnode;
11176 struct bgp *bgp;
d62a17ae 11177 int is_first = 1;
9f049418 11178 bool nbr_output = false;
d62a17ae 11179
11180 if (use_json)
11181 vty_out(vty, "{\n");
11182
11183 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11184 nbr_output = true;
d62a17ae 11185 if (use_json) {
d62a17ae 11186 if (!is_first)
11187 vty_out(vty, ",\n");
11188 else
11189 is_first = 0;
11190
11191 vty_out(vty, "\"%s\":",
11192 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11193 ? VRF_DEFAULT_NAME
d62a17ae 11194 : bgp->name);
11195 } else {
11196 vty_out(vty, "\nInstance %s:\n",
11197 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11198 ? VRF_DEFAULT_NAME
d62a17ae 11199 : bgp->name);
11200 }
3577f1c5 11201 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 11202 show_established, use_json);
d62a17ae 11203 }
11204
11205 if (use_json)
11206 vty_out(vty, "}\n");
9f049418
DS
11207 else if (!nbr_output)
11208 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11209}
11210
11211int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10b49f14
DA
11212 safi_t safi, bool show_failed, bool show_established,
11213 bool use_json)
d62a17ae 11214{
11215 struct bgp *bgp;
11216
11217 if (name) {
11218 if (strmatch(name, "all")) {
10b49f14
DA
11219 bgp_show_all_instances_summary_vty(
11220 vty, afi, safi, show_failed, show_established,
11221 use_json);
d62a17ae 11222 return CMD_SUCCESS;
11223 } else {
11224 bgp = bgp_lookup_by_name(name);
11225
11226 if (!bgp) {
11227 if (use_json)
11228 vty_out(vty, "{}\n");
11229 else
11230 vty_out(vty,
ca61fd25 11231 "%% BGP instance not found\n");
d62a17ae 11232 return CMD_WARNING;
11233 }
11234
f86897b9 11235 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
10b49f14
DA
11236 show_failed, show_established,
11237 use_json);
d62a17ae 11238 return CMD_SUCCESS;
11239 }
11240 }
11241
11242 bgp = bgp_get_default();
11243
11244 if (bgp)
3577f1c5 11245 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 11246 show_established, use_json);
9f049418 11247 else {
ca61fd25
DS
11248 if (use_json)
11249 vty_out(vty, "{}\n");
11250 else
11251 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11252 return CMD_WARNING;
11253 }
d62a17ae 11254
11255 return CMD_SUCCESS;
4fb25c53
DW
11256}
11257
716b2d8a 11258/* `show [ip] bgp summary' commands. */
96f3485c 11259DEFPY (show_ip_bgp_summary,
718e3744 11260 show_ip_bgp_summary_cmd,
96f3485c 11261 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
718e3744 11262 SHOW_STR
11263 IP_STR
11264 BGP_STR
8386ac43 11265 BGP_INSTANCE_HELP_STR
46f296b4 11266 BGP_AFI_HELP_STR
dd6bd0f1 11267 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 11268 "Display the entries for all address families\n"
b05a1c8b 11269 "Summary of BGP neighbor status\n"
10b49f14 11270 "Show only sessions in Established state\n"
3577f1c5 11271 "Show only sessions not in Established state\n"
9973d184 11272 JSON_STR)
718e3744 11273{
d62a17ae 11274 char *vrf = NULL;
11275 afi_t afi = AFI_MAX;
11276 safi_t safi = SAFI_MAX;
3577f1c5 11277 bool show_failed = false;
10b49f14 11278 bool show_established = false;
d62a17ae 11279
11280 int idx = 0;
11281
11282 /* show [ip] bgp */
96f3485c 11283 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11284 afi = AFI_IP;
9a8bdf1c
PG
11285 /* [<vrf> VIEWVRFNAME] */
11286 if (argv_find(argv, argc, "vrf", &idx)) {
11287 vrf = argv[idx + 1]->arg;
11288 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11289 vrf = NULL;
11290 } else if (argv_find(argv, argc, "view", &idx))
11291 /* [<view> VIEWVRFNAME] */
11292 vrf = argv[idx + 1]->arg;
d62a17ae 11293 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11294 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11295 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11296 }
11297
3577f1c5
DD
11298 if (argv_find(argv, argc, "failed", &idx))
11299 show_failed = true;
10b49f14
DA
11300 if (argv_find(argv, argc, "established", &idx))
11301 show_established = true;
3577f1c5 11302
10b49f14
DA
11303 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
11304 show_established, uj);
d62a17ae 11305}
11306
5cb5f4d0 11307const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11308{
5cb5f4d0
DD
11309 if (for_json)
11310 return get_afi_safi_json_str(afi, safi);
d62a17ae 11311 else
5cb5f4d0 11312 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11313}
11314
d62a17ae 11315
11316static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11317 afi_t afi, safi_t safi,
d7c0a89a
QY
11318 uint16_t adv_smcap, uint16_t adv_rmcap,
11319 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11320 bool use_json, json_object *json_pref)
d62a17ae 11321{
11322 /* Send-Mode */
11323 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11324 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11325 if (use_json) {
11326 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11327 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11328 json_object_string_add(json_pref, "sendMode",
11329 "advertisedAndReceived");
11330 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11331 json_object_string_add(json_pref, "sendMode",
11332 "advertised");
11333 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11334 json_object_string_add(json_pref, "sendMode",
11335 "received");
11336 } else {
11337 vty_out(vty, " Send-mode: ");
11338 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11339 vty_out(vty, "advertised");
11340 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11341 vty_out(vty, "%sreceived",
11342 CHECK_FLAG(p->af_cap[afi][safi],
11343 adv_smcap)
11344 ? ", "
11345 : "");
11346 vty_out(vty, "\n");
11347 }
11348 }
11349
11350 /* Receive-Mode */
11351 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11352 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11353 if (use_json) {
11354 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11355 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11356 json_object_string_add(json_pref, "recvMode",
11357 "advertisedAndReceived");
11358 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11359 json_object_string_add(json_pref, "recvMode",
11360 "advertised");
11361 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11362 json_object_string_add(json_pref, "recvMode",
11363 "received");
11364 } else {
11365 vty_out(vty, " Receive-mode: ");
11366 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11367 vty_out(vty, "advertised");
11368 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11369 vty_out(vty, "%sreceived",
11370 CHECK_FLAG(p->af_cap[afi][safi],
11371 adv_rmcap)
11372 ? ", "
11373 : "");
11374 vty_out(vty, "\n");
11375 }
11376 }
11377}
11378
13909c4f
DS
11379static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11380 struct peer *p,
11381 bool use_json,
11382 json_object *json)
2986cac2 11383{
08c2d52a 11384 bool rbit_status = false;
2986cac2 11385
11386 if (!use_json)
a53ca37b 11387 vty_out(vty, "\n R bit: ");
2986cac2 11388
13909c4f
DS
11389 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11390 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11391 && (p->status == Established)) {
2986cac2 11392
11393 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11394 rbit_status = true;
2986cac2 11395 else
08c2d52a 11396 rbit_status = false;
2986cac2 11397 }
11398
11399 if (rbit_status) {
11400 if (use_json)
13909c4f 11401 json_object_boolean_true_add(json, "rBit");
2986cac2 11402 else
11403 vty_out(vty, "True\n");
11404 } else {
11405 if (use_json)
13909c4f 11406 json_object_boolean_false_add(json, "rBit");
2986cac2 11407 else
11408 vty_out(vty, "False\n");
11409 }
11410}
11411
13909c4f
DS
11412static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11413 struct peer *peer,
11414 bool use_json,
11415 json_object *json)
2986cac2 11416{
2bb5d39b 11417 const char *mode = "NotApplicable";
2986cac2 11418
11419 if (!use_json)
a53ca37b 11420 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11421
13909c4f
DS
11422 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11423 && (peer->status == Established)) {
2986cac2 11424
13909c4f
DS
11425 if ((peer->nsf_af_count == 0)
11426 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11427
2986cac2 11428 mode = "Disable";
11429
13909c4f
DS
11430 } else if (peer->nsf_af_count == 0
11431 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11432
2986cac2 11433 mode = "Helper";
11434
13909c4f
DS
11435 } else if (peer->nsf_af_count != 0
11436 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11437
2986cac2 11438 mode = "Restart";
2986cac2 11439 }
11440 }
11441
11442 if (use_json) {
13909c4f 11443 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11444 } else
11445 vty_out(vty, mode, "\n");
11446}
11447
13909c4f
DS
11448static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11449 struct peer *p,
11450 bool use_json,
11451 json_object *json)
2986cac2 11452{
11453 const char *mode = "Invalid";
11454
11455 if (!use_json)
a53ca37b 11456 vty_out(vty, " Local GR Mode: ");
2986cac2 11457
11458 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11459 mode = "Helper";
11460 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11461 mode = "Restart";
11462 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11463 mode = "Disable";
2ba1fe69 11464 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11465 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11466 mode = "Helper*";
11467 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11468 mode = "Restart*";
11469 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11470 mode = "Disable*";
11471 else
11472 mode = "Invalid*";
2ba1fe69 11473 }
2986cac2 11474
11475 if (use_json) {
13909c4f 11476 json_object_string_add(json, "localGrMode", mode);
2986cac2 11477 } else {
11478 vty_out(vty, mode, "\n");
11479 }
11480}
11481
13909c4f
DS
11482static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11483 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11484{
2ba1fe69 11485 afi_t afi;
11486 safi_t safi;
2986cac2 11487 json_object *json_afi_safi = NULL;
11488 json_object *json_timer = NULL;
11489 json_object *json_endofrib_status = NULL;
9e3b51a7 11490 bool eor_flag = false;
2986cac2 11491
11492 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11493 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
11494 if (!peer->afc[afi][safi])
11495 continue;
2986cac2 11496
13909c4f
DS
11497 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11498 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11499 continue;
9e3b51a7 11500
13909c4f
DS
11501 if (use_json) {
11502 json_afi_safi = json_object_new_object();
11503 json_endofrib_status = json_object_new_object();
11504 json_timer = json_object_new_object();
11505 }
2986cac2 11506
13909c4f
DS
11507 if (peer->eor_stime[afi][safi]
11508 >= peer->pkt_stime[afi][safi])
11509 eor_flag = true;
11510 else
11511 eor_flag = false;
2986cac2 11512
13909c4f 11513 if (!use_json) {
a53ca37b 11514 vty_out(vty, " %s:\n",
13909c4f 11515 get_afi_safi_str(afi, safi, false));
2986cac2 11516
a53ca37b 11517 vty_out(vty, " F bit: ");
698ba8d0 11518 }
2986cac2 11519
13909c4f
DS
11520 if (peer->nsf[afi][safi]
11521 && CHECK_FLAG(peer->af_cap[afi][safi],
11522 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11523
13909c4f
DS
11524 if (use_json) {
11525 json_object_boolean_true_add(
2986cac2 11526 json_afi_safi, "fBit");
13909c4f
DS
11527 } else
11528 vty_out(vty, "True\n");
11529 } else {
11530 if (use_json)
11531 json_object_boolean_false_add(
11532 json_afi_safi, "fBit");
11533 else
11534 vty_out(vty, "False\n");
11535 }
2986cac2 11536
13909c4f 11537 if (!use_json)
a53ca37b 11538 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11539
13909c4f
DS
11540 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11541 PEER_STATUS_EOR_SEND)) {
11542 if (use_json) {
11543 json_object_boolean_true_add(
2986cac2 11544 json_endofrib_status,
13909c4f 11545 "endOfRibSend");
9e3b51a7 11546
13909c4f
DS
11547 PRINT_EOR_JSON(eor_flag);
11548 } else {
11549 vty_out(vty, "Yes\n");
11550 vty_out(vty,
a53ca37b 11551 " End-of-RIB sent after update: ");
2986cac2 11552
13909c4f
DS
11553 PRINT_EOR(eor_flag);
11554 }
11555 } else {
11556 if (use_json) {
11557 json_object_boolean_false_add(
2986cac2 11558 json_endofrib_status,
13909c4f
DS
11559 "endOfRibSend");
11560 json_object_boolean_false_add(
9e3b51a7 11561 json_endofrib_status,
13909c4f
DS
11562 "endOfRibSentAfterUpdate");
11563 } else {
11564 vty_out(vty, "No\n");
11565 vty_out(vty,
a53ca37b 11566 " End-of-RIB sent after update: ");
13909c4f 11567 vty_out(vty, "No\n");
2986cac2 11568 }
13909c4f 11569 }
2986cac2 11570
a53ca37b
DA
11571 if (!use_json)
11572 vty_out(vty, " End-of-RIB received: ");
11573
11574 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11575 PEER_STATUS_EOR_RECEIVED)) {
11576 if (use_json)
11577 json_object_boolean_true_add(
11578 json_endofrib_status,
11579 "endOfRibRecv");
11580 else
11581 vty_out(vty, "Yes\n");
11582 } else {
11583 if (use_json)
11584 json_object_boolean_false_add(
11585 json_endofrib_status,
11586 "endOfRibRecv");
11587 else
11588 vty_out(vty, "No\n");
11589 }
11590
13909c4f
DS
11591 if (use_json) {
11592 json_object_int_add(json_timer,
11593 "stalePathTimer",
11594 peer->bgp->stalepath_time);
2986cac2 11595
13909c4f
DS
11596 if (peer->t_gr_stale != NULL) {
11597 json_object_int_add(
2986cac2 11598 json_timer,
11599 "stalePathTimerRemaining",
11600 thread_timer_remain_second(
13909c4f
DS
11601 peer->t_gr_stale));
11602 }
3a75afa4 11603
13909c4f
DS
11604 /* Display Configured Selection
11605 * Deferral only when when
11606 * Gr mode is enabled.
11607 */
11608 if (CHECK_FLAG(peer->flags,
11609 PEER_FLAG_GRACEFUL_RESTART)) {
11610 json_object_int_add(
3a75afa4 11611 json_timer,
2986cac2 11612 "selectionDeferralTimer",
11613 peer->bgp->stalepath_time);
13909c4f 11614 }
2986cac2 11615
13909c4f
DS
11616 if (peer->bgp->gr_info[afi][safi]
11617 .t_select_deferral
11618 != NULL) {
2986cac2 11619
13909c4f 11620 json_object_int_add(
2986cac2 11621 json_timer,
11622 "selectionDeferralTimerRemaining",
11623 thread_timer_remain_second(
13909c4f
DS
11624 peer->bgp
11625 ->gr_info[afi]
11626 [safi]
11627 .t_select_deferral));
11628 }
11629 } else {
a53ca37b 11630 vty_out(vty, " Timers:\n");
13909c4f 11631 vty_out(vty,
a53ca37b
DA
11632 " Configured Stale Path Time(sec): %u\n",
11633 peer->bgp->stalepath_time);
2986cac2 11634
a53ca37b 11635 if (peer->t_gr_stale != NULL)
2986cac2 11636 vty_out(vty,
a53ca37b 11637 " Stale Path Remaining(sec): %ld\n",
2986cac2 11638 thread_timer_remain_second(
13909c4f 11639 peer->t_gr_stale));
13909c4f
DS
11640 /* Display Configured Selection
11641 * Deferral only when when
11642 * Gr mode is enabled.
11643 */
11644 if (CHECK_FLAG(peer->flags,
a53ca37b 11645 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 11646 vty_out(vty,
a53ca37b 11647 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 11648 peer->bgp->select_defer_time);
2986cac2 11649
13909c4f
DS
11650 if (peer->bgp->gr_info[afi][safi]
11651 .t_select_deferral
a53ca37b 11652 != NULL)
13909c4f 11653 vty_out(vty,
a53ca37b 11654 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 11655 thread_timer_remain_second(
13909c4f
DS
11656 peer->bgp
11657 ->gr_info[afi]
11658 [safi]
11659 .t_select_deferral));
2986cac2 11660 }
13909c4f
DS
11661 if (use_json) {
11662 json_object_object_add(json_afi_safi,
11663 "endOfRibStatus",
11664 json_endofrib_status);
11665 json_object_object_add(json_afi_safi, "timers",
11666 json_timer);
11667 json_object_object_add(
11668 json, get_afi_safi_str(afi, safi, true),
11669 json_afi_safi);
11670 }
2986cac2 11671 }
11672 }
11673}
11674
36235319
QY
11675static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11676 struct peer *p,
11677 bool use_json,
11678 json_object *json)
2986cac2 11679{
11680 if (use_json) {
11681 json_object *json_timer = NULL;
11682
11683 json_timer = json_object_new_object();
11684
13909c4f
DS
11685 json_object_int_add(json_timer, "configuredRestartTimer",
11686 p->bgp->restart_time);
2986cac2 11687
13909c4f
DS
11688 json_object_int_add(json_timer, "receivedRestartTimer",
11689 p->v_gr_restart);
2986cac2 11690
13909c4f
DS
11691 if (p->t_gr_restart != NULL)
11692 json_object_int_add(
11693 json_timer, "restartTimerRemaining",
11694 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11695
11696 json_object_object_add(json, "timers", json_timer);
11697 } else {
11698
a53ca37b
DA
11699 vty_out(vty, " Timers:\n");
11700 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11701 p->bgp->restart_time);
2986cac2 11702
a53ca37b 11703 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11704 p->v_gr_restart);
11705 if (p->t_gr_restart != NULL)
a53ca37b 11706 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11707 thread_timer_remain_second(p->t_gr_restart));
36235319 11708 if (p->t_gr_restart != NULL) {
a53ca37b 11709 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11710 thread_timer_remain_second(p->t_gr_restart));
11711 }
2986cac2 11712 }
11713}
11714
11715static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11716 bool use_json, json_object *json)
2986cac2 11717{
11718 char buf[SU_ADDRSTRLEN] = {0};
11719 char dn_flag[2] = {0};
2b7165e7
QY
11720 /* '*' + v6 address of neighbor */
11721 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11722
2986cac2 11723 if (!p->conf_if && peer_dynamic_neighbor(p))
11724 dn_flag[0] = '*';
11725
11726 if (p->conf_if) {
11727 if (use_json)
13909c4f
DS
11728 json_object_string_add(
11729 json, "neighborAddr",
2986cac2 11730 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11731 ? "none"
11732 : sockunion2str(&p->su, buf,
11733 SU_ADDRSTRLEN));
2986cac2 11734 else
13909c4f 11735 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11736 BGP_PEER_SU_UNSPEC(p)
11737 ? "none"
11738 : sockunion2str(&p->su, buf,
11739 SU_ADDRSTRLEN));
11740 } else {
772270f3
QY
11741 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11742 p->host);
2986cac2 11743
11744 if (use_json)
36235319
QY
11745 json_object_string_add(json, "neighborAddr",
11746 neighborAddr);
2986cac2 11747 else
36235319 11748 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11749 }
11750
11751 /* more gr info in new format */
11752 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11753}
11754
d62a17ae 11755static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11756 safi_t safi, bool use_json,
d62a17ae 11757 json_object *json_neigh)
11758{
0291c246
MK
11759 struct bgp_filter *filter;
11760 struct peer_af *paf;
11761 char orf_pfx_name[BUFSIZ];
11762 int orf_pfx_count;
11763 json_object *json_af = NULL;
11764 json_object *json_prefA = NULL;
11765 json_object *json_prefB = NULL;
11766 json_object *json_addr = NULL;
fa36596c 11767 json_object *json_advmap = NULL;
d62a17ae 11768
11769 if (use_json) {
11770 json_addr = json_object_new_object();
11771 json_af = json_object_new_object();
11772 filter = &p->filter[afi][safi];
11773
11774 if (peer_group_active(p))
11775 json_object_string_add(json_addr, "peerGroupMember",
11776 p->group->name);
11777
11778 paf = peer_af_find(p, afi, safi);
11779 if (paf && PAF_SUBGRP(paf)) {
11780 json_object_int_add(json_addr, "updateGroupId",
11781 PAF_UPDGRP(paf)->id);
11782 json_object_int_add(json_addr, "subGroupId",
11783 PAF_SUBGRP(paf)->id);
11784 json_object_int_add(json_addr, "packetQueueLength",
11785 bpacket_queue_virtual_length(paf));
11786 }
11787
11788 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11789 || CHECK_FLAG(p->af_cap[afi][safi],
11790 PEER_CAP_ORF_PREFIX_SM_RCV)
11791 || CHECK_FLAG(p->af_cap[afi][safi],
11792 PEER_CAP_ORF_PREFIX_RM_ADV)
11793 || CHECK_FLAG(p->af_cap[afi][safi],
11794 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11795 json_object_int_add(json_af, "orfType",
11796 ORF_TYPE_PREFIX);
11797 json_prefA = json_object_new_object();
11798 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11799 PEER_CAP_ORF_PREFIX_SM_ADV,
11800 PEER_CAP_ORF_PREFIX_RM_ADV,
11801 PEER_CAP_ORF_PREFIX_SM_RCV,
11802 PEER_CAP_ORF_PREFIX_RM_RCV,
11803 use_json, json_prefA);
11804 json_object_object_add(json_af, "orfPrefixList",
11805 json_prefA);
11806 }
11807
11808 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11809 || CHECK_FLAG(p->af_cap[afi][safi],
11810 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11811 || CHECK_FLAG(p->af_cap[afi][safi],
11812 PEER_CAP_ORF_PREFIX_RM_ADV)
11813 || CHECK_FLAG(p->af_cap[afi][safi],
11814 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11815 json_object_int_add(json_af, "orfOldType",
11816 ORF_TYPE_PREFIX_OLD);
11817 json_prefB = json_object_new_object();
11818 bgp_show_peer_afi_orf_cap(
11819 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11820 PEER_CAP_ORF_PREFIX_RM_ADV,
11821 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11822 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11823 json_prefB);
11824 json_object_object_add(json_af, "orfOldPrefixList",
11825 json_prefB);
11826 }
11827
11828 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11829 || CHECK_FLAG(p->af_cap[afi][safi],
11830 PEER_CAP_ORF_PREFIX_SM_RCV)
11831 || CHECK_FLAG(p->af_cap[afi][safi],
11832 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11833 || CHECK_FLAG(p->af_cap[afi][safi],
11834 PEER_CAP_ORF_PREFIX_RM_ADV)
11835 || CHECK_FLAG(p->af_cap[afi][safi],
11836 PEER_CAP_ORF_PREFIX_RM_RCV)
11837 || CHECK_FLAG(p->af_cap[afi][safi],
11838 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11839 json_object_object_add(json_addr, "afDependentCap",
11840 json_af);
11841 else
11842 json_object_free(json_af);
11843
772270f3
QY
11844 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11845 p->host, afi, safi);
d62a17ae 11846 orf_pfx_count = prefix_bgp_show_prefix_list(
11847 NULL, afi, orf_pfx_name, use_json);
11848
11849 if (CHECK_FLAG(p->af_sflags[afi][safi],
11850 PEER_STATUS_ORF_PREFIX_SEND)
11851 || orf_pfx_count) {
11852 if (CHECK_FLAG(p->af_sflags[afi][safi],
11853 PEER_STATUS_ORF_PREFIX_SEND))
11854 json_object_boolean_true_add(json_neigh,
11855 "orfSent");
11856 if (orf_pfx_count)
11857 json_object_int_add(json_addr, "orfRecvCounter",
11858 orf_pfx_count);
11859 }
11860 if (CHECK_FLAG(p->af_sflags[afi][safi],
11861 PEER_STATUS_ORF_WAIT_REFRESH))
11862 json_object_string_add(
11863 json_addr, "orfFirstUpdate",
11864 "deferredUntilORFOrRouteRefreshRecvd");
11865
11866 if (CHECK_FLAG(p->af_flags[afi][safi],
11867 PEER_FLAG_REFLECTOR_CLIENT))
11868 json_object_boolean_true_add(json_addr,
11869 "routeReflectorClient");
11870 if (CHECK_FLAG(p->af_flags[afi][safi],
11871 PEER_FLAG_RSERVER_CLIENT))
11872 json_object_boolean_true_add(json_addr,
11873 "routeServerClient");
11874 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11875 json_object_boolean_true_add(json_addr,
11876 "inboundSoftConfigPermit");
11877
11878 if (CHECK_FLAG(p->af_flags[afi][safi],
11879 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11880 json_object_boolean_true_add(
11881 json_addr,
11882 "privateAsNumsAllReplacedInUpdatesToNbr");
11883 else if (CHECK_FLAG(p->af_flags[afi][safi],
11884 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11885 json_object_boolean_true_add(
11886 json_addr,
11887 "privateAsNumsReplacedInUpdatesToNbr");
11888 else if (CHECK_FLAG(p->af_flags[afi][safi],
11889 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11890 json_object_boolean_true_add(
11891 json_addr,
11892 "privateAsNumsAllRemovedInUpdatesToNbr");
11893 else if (CHECK_FLAG(p->af_flags[afi][safi],
11894 PEER_FLAG_REMOVE_PRIVATE_AS))
11895 json_object_boolean_true_add(
11896 json_addr,
11897 "privateAsNumsRemovedInUpdatesToNbr");
11898
dcc68b5e
MS
11899 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11900 json_object_boolean_true_add(
11901 json_addr,
11902 bgp_addpath_names(p->addpath_type[afi][safi])
11903 ->type_json_name);
d62a17ae 11904
11905 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11906 json_object_string_add(json_addr,
11907 "overrideASNsInOutboundUpdates",
11908 "ifAspathEqualRemoteAs");
11909
11910 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11911 || CHECK_FLAG(p->af_flags[afi][safi],
11912 PEER_FLAG_FORCE_NEXTHOP_SELF))
11913 json_object_boolean_true_add(json_addr,
11914 "routerAlwaysNextHop");
11915 if (CHECK_FLAG(p->af_flags[afi][safi],
11916 PEER_FLAG_AS_PATH_UNCHANGED))
11917 json_object_boolean_true_add(
11918 json_addr, "unchangedAsPathPropogatedToNbr");
11919 if (CHECK_FLAG(p->af_flags[afi][safi],
11920 PEER_FLAG_NEXTHOP_UNCHANGED))
11921 json_object_boolean_true_add(
11922 json_addr, "unchangedNextHopPropogatedToNbr");
11923 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11924 json_object_boolean_true_add(
11925 json_addr, "unchangedMedPropogatedToNbr");
11926 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11927 || CHECK_FLAG(p->af_flags[afi][safi],
11928 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11929 if (CHECK_FLAG(p->af_flags[afi][safi],
11930 PEER_FLAG_SEND_COMMUNITY)
11931 && CHECK_FLAG(p->af_flags[afi][safi],
11932 PEER_FLAG_SEND_EXT_COMMUNITY))
11933 json_object_string_add(json_addr,
11934 "commAttriSentToNbr",
11935 "extendedAndStandard");
11936 else if (CHECK_FLAG(p->af_flags[afi][safi],
11937 PEER_FLAG_SEND_EXT_COMMUNITY))
11938 json_object_string_add(json_addr,
11939 "commAttriSentToNbr",
11940 "extended");
11941 else
11942 json_object_string_add(json_addr,
11943 "commAttriSentToNbr",
11944 "standard");
11945 }
11946 if (CHECK_FLAG(p->af_flags[afi][safi],
11947 PEER_FLAG_DEFAULT_ORIGINATE)) {
11948 if (p->default_rmap[afi][safi].name)
11949 json_object_string_add(
11950 json_addr, "defaultRouteMap",
11951 p->default_rmap[afi][safi].name);
11952
11953 if (paf && PAF_SUBGRP(paf)
11954 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11955 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11956 json_object_boolean_true_add(json_addr,
11957 "defaultSent");
11958 else
11959 json_object_boolean_true_add(json_addr,
11960 "defaultNotSent");
11961 }
11962
dff8f48d 11963 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11964 if (is_evpn_enabled())
60466a63
QY
11965 json_object_boolean_true_add(
11966 json_addr, "advertiseAllVnis");
dff8f48d
MK
11967 }
11968
d62a17ae 11969 if (filter->plist[FILTER_IN].name
11970 || filter->dlist[FILTER_IN].name
11971 || filter->aslist[FILTER_IN].name
11972 || filter->map[RMAP_IN].name)
11973 json_object_boolean_true_add(json_addr,
11974 "inboundPathPolicyConfig");
11975 if (filter->plist[FILTER_OUT].name
11976 || filter->dlist[FILTER_OUT].name
11977 || filter->aslist[FILTER_OUT].name
11978 || filter->map[RMAP_OUT].name || filter->usmap.name)
11979 json_object_boolean_true_add(
11980 json_addr, "outboundPathPolicyConfig");
11981
11982 /* prefix-list */
11983 if (filter->plist[FILTER_IN].name)
11984 json_object_string_add(json_addr,
11985 "incomingUpdatePrefixFilterList",
11986 filter->plist[FILTER_IN].name);
11987 if (filter->plist[FILTER_OUT].name)
11988 json_object_string_add(json_addr,
11989 "outgoingUpdatePrefixFilterList",
11990 filter->plist[FILTER_OUT].name);
11991
11992 /* distribute-list */
11993 if (filter->dlist[FILTER_IN].name)
11994 json_object_string_add(
11995 json_addr, "incomingUpdateNetworkFilterList",
11996 filter->dlist[FILTER_IN].name);
11997 if (filter->dlist[FILTER_OUT].name)
11998 json_object_string_add(
11999 json_addr, "outgoingUpdateNetworkFilterList",
12000 filter->dlist[FILTER_OUT].name);
12001
12002 /* filter-list. */
12003 if (filter->aslist[FILTER_IN].name)
12004 json_object_string_add(json_addr,
12005 "incomingUpdateAsPathFilterList",
12006 filter->aslist[FILTER_IN].name);
12007 if (filter->aslist[FILTER_OUT].name)
12008 json_object_string_add(json_addr,
12009 "outgoingUpdateAsPathFilterList",
12010 filter->aslist[FILTER_OUT].name);
12011
12012 /* route-map. */
12013 if (filter->map[RMAP_IN].name)
12014 json_object_string_add(
12015 json_addr, "routeMapForIncomingAdvertisements",
12016 filter->map[RMAP_IN].name);
12017 if (filter->map[RMAP_OUT].name)
12018 json_object_string_add(
12019 json_addr, "routeMapForOutgoingAdvertisements",
12020 filter->map[RMAP_OUT].name);
12021
9dac9fc8 12022 /* ebgp-requires-policy (inbound) */
1d3fdccf 12023 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12024 && !bgp_inbound_policy_exists(p, filter))
12025 json_object_string_add(
12026 json_addr, "inboundEbgpRequiresPolicy",
12027 "Inbound updates discarded due to missing policy");
12028
12029 /* ebgp-requires-policy (outbound) */
1d3fdccf 12030 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12031 && (!bgp_outbound_policy_exists(p, filter)))
12032 json_object_string_add(
12033 json_addr, "outboundEbgpRequiresPolicy",
12034 "Outbound updates discarded due to missing policy");
12035
d62a17ae 12036 /* unsuppress-map */
12037 if (filter->usmap.name)
12038 json_object_string_add(json_addr,
12039 "selectiveUnsuppressRouteMap",
12040 filter->usmap.name);
12041
fa36596c
MK
12042 /* advertise-map */
12043 if (filter->advmap.aname) {
12044 json_advmap = json_object_new_object();
12045 json_object_string_add(json_advmap, "condition",
12046 filter->advmap.condition
12047 ? "EXIST"
12048 : "NON_EXIST");
12049 json_object_string_add(json_advmap, "conditionMap",
12050 filter->advmap.cname);
12051 json_object_string_add(json_advmap, "advertiseMap",
12052 filter->advmap.aname);
12053 json_object_string_add(json_advmap, "advertiseStatus",
12054 filter->advmap.update_type
12055 == ADVERTISE
12056 ? "Advertise"
12057 : "Withdraw");
12058 json_object_object_add(json_addr, "advertiseMap",
12059 json_advmap);
12060 }
12061
d62a17ae 12062 /* Receive prefix count */
12063 json_object_int_add(json_addr, "acceptedPrefixCounter",
12064 p->pcount[afi][safi]);
50e05855
AD
12065 if (paf && PAF_SUBGRP(paf))
12066 json_object_int_add(json_addr, "sentPrefixCounter",
12067 (PAF_SUBGRP(paf))->scount);
d62a17ae 12068
fde246e8
DA
12069 /* Maximum prefix */
12070 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12071 json_object_int_add(json_addr, "prefixOutAllowedMax",
12072 p->pmax_out[afi][safi]);
12073
d62a17ae 12074 /* Maximum prefix */
12075 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12076 json_object_int_add(json_addr, "prefixAllowedMax",
12077 p->pmax[afi][safi]);
12078 if (CHECK_FLAG(p->af_flags[afi][safi],
12079 PEER_FLAG_MAX_PREFIX_WARNING))
12080 json_object_boolean_true_add(
12081 json_addr, "prefixAllowedMaxWarning");
12082 json_object_int_add(json_addr,
12083 "prefixAllowedWarningThresh",
12084 p->pmax_threshold[afi][safi]);
12085 if (p->pmax_restart[afi][safi])
12086 json_object_int_add(
12087 json_addr,
12088 "prefixAllowedRestartIntervalMsecs",
12089 p->pmax_restart[afi][safi] * 60000);
12090 }
2986cac2 12091 json_object_object_add(json_neigh,
36235319 12092 get_afi_safi_str(afi, safi, true),
d62a17ae 12093 json_addr);
12094
12095 } else {
12096 filter = &p->filter[afi][safi];
12097
12098 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12099 get_afi_safi_str(afi, safi, false));
d62a17ae 12100
12101 if (peer_group_active(p))
12102 vty_out(vty, " %s peer-group member\n",
12103 p->group->name);
12104
12105 paf = peer_af_find(p, afi, safi);
12106 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12107 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12108 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12109 vty_out(vty, " Packet Queue length %d\n",
12110 bpacket_queue_virtual_length(paf));
12111 } else {
12112 vty_out(vty, " Not part of any update group\n");
12113 }
12114 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12115 || CHECK_FLAG(p->af_cap[afi][safi],
12116 PEER_CAP_ORF_PREFIX_SM_RCV)
12117 || CHECK_FLAG(p->af_cap[afi][safi],
12118 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12119 || CHECK_FLAG(p->af_cap[afi][safi],
12120 PEER_CAP_ORF_PREFIX_RM_ADV)
12121 || CHECK_FLAG(p->af_cap[afi][safi],
12122 PEER_CAP_ORF_PREFIX_RM_RCV)
12123 || CHECK_FLAG(p->af_cap[afi][safi],
12124 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12125 vty_out(vty, " AF-dependant capabilities:\n");
12126
12127 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12128 || CHECK_FLAG(p->af_cap[afi][safi],
12129 PEER_CAP_ORF_PREFIX_SM_RCV)
12130 || CHECK_FLAG(p->af_cap[afi][safi],
12131 PEER_CAP_ORF_PREFIX_RM_ADV)
12132 || CHECK_FLAG(p->af_cap[afi][safi],
12133 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12134 vty_out(vty,
12135 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12136 ORF_TYPE_PREFIX);
12137 bgp_show_peer_afi_orf_cap(
12138 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12139 PEER_CAP_ORF_PREFIX_RM_ADV,
12140 PEER_CAP_ORF_PREFIX_SM_RCV,
12141 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12142 }
12143 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12144 || CHECK_FLAG(p->af_cap[afi][safi],
12145 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12146 || CHECK_FLAG(p->af_cap[afi][safi],
12147 PEER_CAP_ORF_PREFIX_RM_ADV)
12148 || CHECK_FLAG(p->af_cap[afi][safi],
12149 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12150 vty_out(vty,
12151 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12152 ORF_TYPE_PREFIX_OLD);
12153 bgp_show_peer_afi_orf_cap(
12154 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12155 PEER_CAP_ORF_PREFIX_RM_ADV,
12156 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12157 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12158 }
12159
772270f3
QY
12160 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12161 p->host, afi, safi);
d62a17ae 12162 orf_pfx_count = prefix_bgp_show_prefix_list(
12163 NULL, afi, orf_pfx_name, use_json);
12164
12165 if (CHECK_FLAG(p->af_sflags[afi][safi],
12166 PEER_STATUS_ORF_PREFIX_SEND)
12167 || orf_pfx_count) {
12168 vty_out(vty, " Outbound Route Filter (ORF):");
12169 if (CHECK_FLAG(p->af_sflags[afi][safi],
12170 PEER_STATUS_ORF_PREFIX_SEND))
12171 vty_out(vty, " sent;");
12172 if (orf_pfx_count)
12173 vty_out(vty, " received (%d entries)",
12174 orf_pfx_count);
12175 vty_out(vty, "\n");
12176 }
12177 if (CHECK_FLAG(p->af_sflags[afi][safi],
12178 PEER_STATUS_ORF_WAIT_REFRESH))
12179 vty_out(vty,
12180 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12181
12182 if (CHECK_FLAG(p->af_flags[afi][safi],
12183 PEER_FLAG_REFLECTOR_CLIENT))
12184 vty_out(vty, " Route-Reflector Client\n");
12185 if (CHECK_FLAG(p->af_flags[afi][safi],
12186 PEER_FLAG_RSERVER_CLIENT))
12187 vty_out(vty, " Route-Server Client\n");
12188 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12189 vty_out(vty,
12190 " Inbound soft reconfiguration allowed\n");
12191
12192 if (CHECK_FLAG(p->af_flags[afi][safi],
12193 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12194 vty_out(vty,
12195 " Private AS numbers (all) replaced in updates to this neighbor\n");
12196 else if (CHECK_FLAG(p->af_flags[afi][safi],
12197 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12198 vty_out(vty,
12199 " Private AS numbers replaced in updates to this neighbor\n");
12200 else if (CHECK_FLAG(p->af_flags[afi][safi],
12201 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12202 vty_out(vty,
12203 " Private AS numbers (all) removed in updates to this neighbor\n");
12204 else if (CHECK_FLAG(p->af_flags[afi][safi],
12205 PEER_FLAG_REMOVE_PRIVATE_AS))
12206 vty_out(vty,
12207 " Private AS numbers removed in updates to this neighbor\n");
12208
dcc68b5e
MS
12209 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12210 vty_out(vty, " %s\n",
12211 bgp_addpath_names(p->addpath_type[afi][safi])
12212 ->human_description);
d62a17ae 12213
12214 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12215 vty_out(vty,
12216 " Override ASNs in outbound updates if aspath equals remote-as\n");
12217
12218 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12219 || CHECK_FLAG(p->af_flags[afi][safi],
12220 PEER_FLAG_FORCE_NEXTHOP_SELF))
12221 vty_out(vty, " NEXT_HOP is always this router\n");
12222 if (CHECK_FLAG(p->af_flags[afi][safi],
12223 PEER_FLAG_AS_PATH_UNCHANGED))
12224 vty_out(vty,
12225 " AS_PATH is propagated unchanged to this neighbor\n");
12226 if (CHECK_FLAG(p->af_flags[afi][safi],
12227 PEER_FLAG_NEXTHOP_UNCHANGED))
12228 vty_out(vty,
12229 " NEXT_HOP is propagated unchanged to this neighbor\n");
12230 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12231 vty_out(vty,
12232 " MED is propagated unchanged to this neighbor\n");
12233 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12234 || CHECK_FLAG(p->af_flags[afi][safi],
12235 PEER_FLAG_SEND_EXT_COMMUNITY)
12236 || CHECK_FLAG(p->af_flags[afi][safi],
12237 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12238 vty_out(vty,
12239 " Community attribute sent to this neighbor");
12240 if (CHECK_FLAG(p->af_flags[afi][safi],
12241 PEER_FLAG_SEND_COMMUNITY)
12242 && CHECK_FLAG(p->af_flags[afi][safi],
12243 PEER_FLAG_SEND_EXT_COMMUNITY)
12244 && CHECK_FLAG(p->af_flags[afi][safi],
12245 PEER_FLAG_SEND_LARGE_COMMUNITY))
12246 vty_out(vty, "(all)\n");
12247 else if (CHECK_FLAG(p->af_flags[afi][safi],
12248 PEER_FLAG_SEND_LARGE_COMMUNITY))
12249 vty_out(vty, "(large)\n");
12250 else if (CHECK_FLAG(p->af_flags[afi][safi],
12251 PEER_FLAG_SEND_EXT_COMMUNITY))
12252 vty_out(vty, "(extended)\n");
12253 else
12254 vty_out(vty, "(standard)\n");
12255 }
12256 if (CHECK_FLAG(p->af_flags[afi][safi],
12257 PEER_FLAG_DEFAULT_ORIGINATE)) {
12258 vty_out(vty, " Default information originate,");
12259
12260 if (p->default_rmap[afi][safi].name)
12261 vty_out(vty, " default route-map %s%s,",
12262 p->default_rmap[afi][safi].map ? "*"
12263 : "",
12264 p->default_rmap[afi][safi].name);
12265 if (paf && PAF_SUBGRP(paf)
12266 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12267 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12268 vty_out(vty, " default sent\n");
12269 else
12270 vty_out(vty, " default not sent\n");
12271 }
12272
dff8f48d
MK
12273 /* advertise-vni-all */
12274 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12275 if (is_evpn_enabled())
dff8f48d
MK
12276 vty_out(vty, " advertise-all-vni\n");
12277 }
12278
d62a17ae 12279 if (filter->plist[FILTER_IN].name
12280 || filter->dlist[FILTER_IN].name
12281 || filter->aslist[FILTER_IN].name
12282 || filter->map[RMAP_IN].name)
12283 vty_out(vty, " Inbound path policy configured\n");
12284 if (filter->plist[FILTER_OUT].name
12285 || filter->dlist[FILTER_OUT].name
12286 || filter->aslist[FILTER_OUT].name
12287 || filter->map[RMAP_OUT].name || filter->usmap.name)
12288 vty_out(vty, " Outbound path policy configured\n");
12289
12290 /* prefix-list */
12291 if (filter->plist[FILTER_IN].name)
12292 vty_out(vty,
12293 " Incoming update prefix filter list is %s%s\n",
12294 filter->plist[FILTER_IN].plist ? "*" : "",
12295 filter->plist[FILTER_IN].name);
12296 if (filter->plist[FILTER_OUT].name)
12297 vty_out(vty,
12298 " Outgoing update prefix filter list is %s%s\n",
12299 filter->plist[FILTER_OUT].plist ? "*" : "",
12300 filter->plist[FILTER_OUT].name);
12301
12302 /* distribute-list */
12303 if (filter->dlist[FILTER_IN].name)
12304 vty_out(vty,
12305 " Incoming update network filter list is %s%s\n",
12306 filter->dlist[FILTER_IN].alist ? "*" : "",
12307 filter->dlist[FILTER_IN].name);
12308 if (filter->dlist[FILTER_OUT].name)
12309 vty_out(vty,
12310 " Outgoing update network filter list is %s%s\n",
12311 filter->dlist[FILTER_OUT].alist ? "*" : "",
12312 filter->dlist[FILTER_OUT].name);
12313
12314 /* filter-list. */
12315 if (filter->aslist[FILTER_IN].name)
12316 vty_out(vty,
12317 " Incoming update AS path filter list is %s%s\n",
12318 filter->aslist[FILTER_IN].aslist ? "*" : "",
12319 filter->aslist[FILTER_IN].name);
12320 if (filter->aslist[FILTER_OUT].name)
12321 vty_out(vty,
12322 " Outgoing update AS path filter list is %s%s\n",
12323 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12324 filter->aslist[FILTER_OUT].name);
12325
12326 /* route-map. */
12327 if (filter->map[RMAP_IN].name)
12328 vty_out(vty,
12329 " Route map for incoming advertisements is %s%s\n",
12330 filter->map[RMAP_IN].map ? "*" : "",
12331 filter->map[RMAP_IN].name);
12332 if (filter->map[RMAP_OUT].name)
12333 vty_out(vty,
12334 " Route map for outgoing advertisements is %s%s\n",
12335 filter->map[RMAP_OUT].map ? "*" : "",
12336 filter->map[RMAP_OUT].name);
12337
9dac9fc8 12338 /* ebgp-requires-policy (inbound) */
1d3fdccf 12339 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12340 && !bgp_inbound_policy_exists(p, filter))
12341 vty_out(vty,
12342 " Inbound updates discarded due to missing policy\n");
12343
12344 /* ebgp-requires-policy (outbound) */
1d3fdccf 12345 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12346 && !bgp_outbound_policy_exists(p, filter))
12347 vty_out(vty,
12348 " Outbound updates discarded due to missing policy\n");
12349
d62a17ae 12350 /* unsuppress-map */
12351 if (filter->usmap.name)
12352 vty_out(vty,
12353 " Route map for selective unsuppress is %s%s\n",
12354 filter->usmap.map ? "*" : "",
12355 filter->usmap.name);
12356
7f7940e6
MK
12357 /* advertise-map */
12358 if (filter->advmap.aname && filter->advmap.cname)
12359 vty_out(vty,
12360 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12361 filter->advmap.condition ? "EXIST"
12362 : "NON_EXIST",
12363 filter->advmap.cmap ? "*" : "",
12364 filter->advmap.cname,
12365 filter->advmap.amap ? "*" : "",
12366 filter->advmap.aname,
fa36596c 12367 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12368 ? "Advertise"
12369 : "Withdraw");
7f7940e6 12370
d62a17ae 12371 /* Receive prefix count */
6cde4b45 12372 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12373 p->pcount[afi][safi]);
d62a17ae 12374
fde246e8
DA
12375 /* maximum-prefix-out */
12376 if (CHECK_FLAG(p->af_flags[afi][safi],
12377 PEER_FLAG_MAX_PREFIX_OUT))
12378 vty_out(vty,
6cde4b45 12379 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12380 p->pmax_out[afi][safi]);
12381
d62a17ae 12382 /* Maximum prefix */
12383 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12384 vty_out(vty,
6cde4b45 12385 " Maximum prefixes allowed %u%s\n",
d62a17ae 12386 p->pmax[afi][safi],
12387 CHECK_FLAG(p->af_flags[afi][safi],
12388 PEER_FLAG_MAX_PREFIX_WARNING)
12389 ? " (warning-only)"
12390 : "");
12391 vty_out(vty, " Threshold for warning message %d%%",
12392 p->pmax_threshold[afi][safi]);
12393 if (p->pmax_restart[afi][safi])
12394 vty_out(vty, ", restart interval %d min",
12395 p->pmax_restart[afi][safi]);
12396 vty_out(vty, "\n");
12397 }
12398
12399 vty_out(vty, "\n");
12400 }
12401}
12402
9f049418 12403static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12404 json_object *json)
718e3744 12405{
d62a17ae 12406 struct bgp *bgp;
12407 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12408 char timebuf[BGP_UPTIME_LEN];
12409 char dn_flag[2];
d62a17ae 12410 afi_t afi;
12411 safi_t safi;
d7c0a89a
QY
12412 uint16_t i;
12413 uint8_t *msg;
d62a17ae 12414 json_object *json_neigh = NULL;
12415 time_t epoch_tbuf;
718e3744 12416
d62a17ae 12417 bgp = p->bgp;
12418
12419 if (use_json)
12420 json_neigh = json_object_new_object();
12421
12422 memset(dn_flag, '\0', sizeof(dn_flag));
12423 if (!p->conf_if && peer_dynamic_neighbor(p))
12424 dn_flag[0] = '*';
12425
12426 if (!use_json) {
12427 if (p->conf_if) /* Configured interface name. */
12428 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12429 BGP_PEER_SU_UNSPEC(p)
12430 ? "None"
12431 : sockunion2str(&p->su, buf,
12432 SU_ADDRSTRLEN));
12433 else /* Configured IP address. */
12434 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12435 p->host);
12436 }
12437
12438 if (use_json) {
12439 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12440 json_object_string_add(json_neigh, "bgpNeighborAddr",
12441 "none");
12442 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12443 json_object_string_add(
12444 json_neigh, "bgpNeighborAddr",
12445 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12446
12447 json_object_int_add(json_neigh, "remoteAs", p->as);
12448
12449 if (p->change_local_as)
12450 json_object_int_add(json_neigh, "localAs",
12451 p->change_local_as);
12452 else
12453 json_object_int_add(json_neigh, "localAs", p->local_as);
12454
12455 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12456 json_object_boolean_true_add(json_neigh,
12457 "localAsNoPrepend");
12458
12459 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12460 json_object_boolean_true_add(json_neigh,
12461 "localAsReplaceAs");
12462 } else {
12463 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12464 || (p->as_type == AS_INTERNAL))
12465 vty_out(vty, "remote AS %u, ", p->as);
12466 else
12467 vty_out(vty, "remote AS Unspecified, ");
12468 vty_out(vty, "local AS %u%s%s, ",
12469 p->change_local_as ? p->change_local_as : p->local_as,
12470 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12471 ? " no-prepend"
12472 : "",
12473 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12474 ? " replace-as"
12475 : "");
12476 }
faa16034
DS
12477 /* peer type internal or confed-internal */
12478 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12479 if (use_json) {
12480 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12481 json_object_boolean_true_add(
12482 json_neigh, "nbrConfedInternalLink");
12483 else
12484 json_object_boolean_true_add(json_neigh,
12485 "nbrInternalLink");
12486 } else {
12487 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12488 vty_out(vty, "confed-internal link\n");
12489 else
12490 vty_out(vty, "internal link\n");
12491 }
faa16034
DS
12492 /* peer type external or confed-external */
12493 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12494 if (use_json) {
12495 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12496 json_object_boolean_true_add(
12497 json_neigh, "nbrConfedExternalLink");
12498 else
12499 json_object_boolean_true_add(json_neigh,
12500 "nbrExternalLink");
12501 } else {
12502 if (bgp_confederation_peers_check(bgp, p->as))
12503 vty_out(vty, "confed-external link\n");
12504 else
12505 vty_out(vty, "external link\n");
12506 }
faa16034
DS
12507 } else {
12508 if (use_json)
12509 json_object_boolean_true_add(json_neigh,
12510 "nbrUnspecifiedLink");
12511 else
12512 vty_out(vty, "unspecified link\n");
d62a17ae 12513 }
12514
12515 /* Description. */
12516 if (p->desc) {
12517 if (use_json)
12518 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12519 else
12520 vty_out(vty, " Description: %s\n", p->desc);
12521 }
12522
12523 if (p->hostname) {
12524 if (use_json) {
12525 if (p->hostname)
12526 json_object_string_add(json_neigh, "hostname",
12527 p->hostname);
12528
12529 if (p->domainname)
12530 json_object_string_add(json_neigh, "domainname",
12531 p->domainname);
12532 } else {
12533 if (p->domainname && (p->domainname[0] != '\0'))
12534 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12535 p->domainname);
12536 else
12537 vty_out(vty, "Hostname: %s\n", p->hostname);
12538 }
12539 }
12540
12541 /* Peer-group */
12542 if (p->group) {
12543 if (use_json) {
12544 json_object_string_add(json_neigh, "peerGroup",
12545 p->group->name);
12546
12547 if (dn_flag[0]) {
12548 struct prefix prefix, *range = NULL;
12549
0154d8ce
DS
12550 if (sockunion2hostprefix(&(p->su), &prefix))
12551 range = peer_group_lookup_dynamic_neighbor_range(
12552 p->group, &prefix);
d62a17ae 12553
12554 if (range) {
12555 prefix2str(range, buf1, sizeof(buf1));
12556 json_object_string_add(
12557 json_neigh,
12558 "peerSubnetRangeGroup", buf1);
12559 }
12560 }
12561 } else {
12562 vty_out(vty,
12563 " Member of peer-group %s for session parameters\n",
12564 p->group->name);
12565
12566 if (dn_flag[0]) {
12567 struct prefix prefix, *range = NULL;
12568
0154d8ce
DS
12569 if (sockunion2hostprefix(&(p->su), &prefix))
12570 range = peer_group_lookup_dynamic_neighbor_range(
12571 p->group, &prefix);
d62a17ae 12572
12573 if (range) {
d62a17ae 12574 vty_out(vty,
1b78780b
DL
12575 " Belongs to the subnet range group: %pFX\n",
12576 range);
d62a17ae 12577 }
12578 }
12579 }
12580 }
12581
12582 if (use_json) {
12583 /* Administrative shutdown. */
cb9196e7
DS
12584 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12585 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12586 json_object_boolean_true_add(json_neigh,
12587 "adminShutDown");
12588
12589 /* BGP Version. */
12590 json_object_int_add(json_neigh, "bgpVersion", 4);
12591 json_object_string_add(
12592 json_neigh, "remoteRouterId",
12593 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
12594 json_object_string_add(
12595 json_neigh, "localRouterId",
12596 inet_ntop(AF_INET, &bgp->router_id, buf1,
12597 sizeof(buf1)));
d62a17ae 12598
12599 /* Confederation */
12600 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12601 && bgp_confederation_peers_check(bgp, p->as))
12602 json_object_boolean_true_add(json_neigh,
12603 "nbrCommonAdmin");
12604
12605 /* Status. */
12606 json_object_string_add(
12607 json_neigh, "bgpState",
12608 lookup_msg(bgp_status_msg, p->status, NULL));
12609
12610 if (p->status == Established) {
12611 time_t uptime;
d62a17ae 12612
12613 uptime = bgp_clock();
12614 uptime -= p->uptime;
d62a17ae 12615 epoch_tbuf = time(NULL) - uptime;
12616
d3c7efed
DS
12617 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12618 uptime * 1000);
d62a17ae 12619 json_object_string_add(json_neigh, "bgpTimerUpString",
12620 peer_uptime(p->uptime, timebuf,
12621 BGP_UPTIME_LEN, 0,
12622 NULL));
12623 json_object_int_add(json_neigh,
12624 "bgpTimerUpEstablishedEpoch",
12625 epoch_tbuf);
12626 }
12627
12628 else if (p->status == Active) {
12629 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12630 json_object_string_add(json_neigh, "bgpStateIs",
12631 "passive");
12632 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12633 json_object_string_add(json_neigh, "bgpStateIs",
12634 "passiveNSF");
12635 }
12636
12637 /* read timer */
12638 time_t uptime;
a2700b50 12639 struct tm tm;
d62a17ae 12640
12641 uptime = bgp_clock();
12642 uptime -= p->readtime;
a2700b50
MS
12643 gmtime_r(&uptime, &tm);
12644
d62a17ae 12645 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12646 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12647 + (tm.tm_hour * 3600000));
d62a17ae 12648
12649 uptime = bgp_clock();
12650 uptime -= p->last_write;
a2700b50
MS
12651 gmtime_r(&uptime, &tm);
12652
d62a17ae 12653 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12654 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12655 + (tm.tm_hour * 3600000));
d62a17ae 12656
12657 uptime = bgp_clock();
12658 uptime -= p->update_time;
a2700b50
MS
12659 gmtime_r(&uptime, &tm);
12660
d62a17ae 12661 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12662 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12663 + (tm.tm_hour * 3600000));
d62a17ae 12664
12665 /* Configured timer values. */
12666 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12667 p->v_holdtime * 1000);
12668 json_object_int_add(json_neigh,
12669 "bgpTimerKeepAliveIntervalMsecs",
12670 p->v_keepalive * 1000);
d43114f3
DS
12671 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12672 json_object_int_add(json_neigh,
12673 "bgpTimerDelayOpenTimeMsecs",
12674 p->v_delayopen * 1000);
12675 }
12676
b90a8e13 12677 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12678 json_object_int_add(json_neigh,
12679 "bgpTimerConfiguredHoldTimeMsecs",
12680 p->holdtime * 1000);
12681 json_object_int_add(
12682 json_neigh,
12683 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12684 p->keepalive * 1000);
5d5393b9
DL
12685 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12686 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12687 json_object_int_add(json_neigh,
12688 "bgpTimerConfiguredHoldTimeMsecs",
12689 bgp->default_holdtime);
12690 json_object_int_add(
12691 json_neigh,
12692 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12693 bgp->default_keepalive);
d62a17ae 12694 }
12695 } else {
12696 /* Administrative shutdown. */
cb9196e7
DS
12697 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12698 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12699 vty_out(vty, " Administratively shut down\n");
12700
12701 /* BGP Version. */
12702 vty_out(vty, " BGP version 4");
0e38aeb4 12703 vty_out(vty, ", remote router ID %s",
d62a17ae 12704 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12705 vty_out(vty, ", local router ID %s\n",
12706 inet_ntop(AF_INET, &bgp->router_id, buf1,
12707 sizeof(buf1)));
d62a17ae 12708
12709 /* Confederation */
12710 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12711 && bgp_confederation_peers_check(bgp, p->as))
12712 vty_out(vty,
12713 " Neighbor under common administration\n");
12714
12715 /* Status. */
12716 vty_out(vty, " BGP state = %s",
12717 lookup_msg(bgp_status_msg, p->status, NULL));
12718
12719 if (p->status == Established)
12720 vty_out(vty, ", up for %8s",
12721 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12722 0, NULL));
12723
12724 else if (p->status == Active) {
12725 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12726 vty_out(vty, " (passive)");
12727 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12728 vty_out(vty, " (NSF passive)");
12729 }
12730 vty_out(vty, "\n");
12731
12732 /* read timer */
12733 vty_out(vty, " Last read %s",
12734 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12735 NULL));
12736 vty_out(vty, ", Last write %s\n",
12737 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12738 NULL));
12739
12740 /* Configured timer values. */
12741 vty_out(vty,
12742 " Hold time is %d, keepalive interval is %d seconds\n",
12743 p->v_holdtime, p->v_keepalive);
b90a8e13 12744 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12745 vty_out(vty, " Configured hold time is %d",
12746 p->holdtime);
12747 vty_out(vty, ", keepalive interval is %d seconds\n",
12748 p->keepalive);
5d5393b9
DL
12749 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12750 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12751 vty_out(vty, " Configured hold time is %d",
12752 bgp->default_holdtime);
12753 vty_out(vty, ", keepalive interval is %d seconds\n",
12754 bgp->default_keepalive);
d62a17ae 12755 }
d43114f3
DS
12756 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12757 vty_out(vty,
12758 " Configured DelayOpenTime is %d seconds\n",
12759 p->delayopen);
d62a17ae 12760 }
12761 /* Capability. */
12762 if (p->status == Established) {
12763 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12764 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12765 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12766 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12767 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12768 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12769 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12770 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12771 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12772 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12773 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12774 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 12775 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12776 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 12777 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12778 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 12779 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12780 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 12781 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12782 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12783 if (use_json) {
12784 json_object *json_cap = NULL;
12785
12786 json_cap = json_object_new_object();
12787
12788 /* AS4 */
12789 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12790 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12791 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12792 && CHECK_FLAG(p->cap,
12793 PEER_CAP_AS4_RCV))
12794 json_object_string_add(
12795 json_cap, "4byteAs",
12796 "advertisedAndReceived");
12797 else if (CHECK_FLAG(p->cap,
12798 PEER_CAP_AS4_ADV))
12799 json_object_string_add(
12800 json_cap, "4byteAs",
12801 "advertised");
12802 else if (CHECK_FLAG(p->cap,
12803 PEER_CAP_AS4_RCV))
12804 json_object_string_add(
12805 json_cap, "4byteAs",
12806 "received");
12807 }
12808
12809 /* AddPath */
12810 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12811 || CHECK_FLAG(p->cap,
12812 PEER_CAP_ADDPATH_ADV)) {
12813 json_object *json_add = NULL;
12814 const char *print_store;
12815
12816 json_add = json_object_new_object();
12817
05c7a1cc
QY
12818 FOREACH_AFI_SAFI (afi, safi) {
12819 json_object *json_sub = NULL;
12820 json_sub =
12821 json_object_new_object();
5cb5f4d0
DD
12822 print_store = get_afi_safi_str(
12823 afi, safi, true);
d62a17ae 12824
05c7a1cc
QY
12825 if (CHECK_FLAG(
12826 p->af_cap[afi]
12827 [safi],
12828 PEER_CAP_ADDPATH_AF_TX_ADV)
12829 || CHECK_FLAG(
12830 p->af_cap[afi]
12831 [safi],
12832 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 12833 if (CHECK_FLAG(
12834 p->af_cap
12835 [afi]
12836 [safi],
12837 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 12838 && CHECK_FLAG(
d62a17ae 12839 p->af_cap
12840 [afi]
12841 [safi],
05c7a1cc
QY
12842 PEER_CAP_ADDPATH_AF_TX_RCV))
12843 json_object_boolean_true_add(
12844 json_sub,
12845 "txAdvertisedAndReceived");
12846 else if (
12847 CHECK_FLAG(
12848 p->af_cap
12849 [afi]
12850 [safi],
12851 PEER_CAP_ADDPATH_AF_TX_ADV))
12852 json_object_boolean_true_add(
12853 json_sub,
12854 "txAdvertised");
12855 else if (
12856 CHECK_FLAG(
12857 p->af_cap
12858 [afi]
12859 [safi],
12860 PEER_CAP_ADDPATH_AF_TX_RCV))
12861 json_object_boolean_true_add(
12862 json_sub,
12863 "txReceived");
12864 }
d62a17ae 12865
05c7a1cc
QY
12866 if (CHECK_FLAG(
12867 p->af_cap[afi]
12868 [safi],
12869 PEER_CAP_ADDPATH_AF_RX_ADV)
12870 || CHECK_FLAG(
12871 p->af_cap[afi]
12872 [safi],
12873 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 12874 if (CHECK_FLAG(
12875 p->af_cap
12876 [afi]
12877 [safi],
12878 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 12879 && CHECK_FLAG(
d62a17ae 12880 p->af_cap
12881 [afi]
12882 [safi],
12883 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
12884 json_object_boolean_true_add(
12885 json_sub,
12886 "rxAdvertisedAndReceived");
12887 else if (
12888 CHECK_FLAG(
12889 p->af_cap
12890 [afi]
12891 [safi],
12892 PEER_CAP_ADDPATH_AF_RX_ADV))
12893 json_object_boolean_true_add(
12894 json_sub,
12895 "rxAdvertised");
12896 else if (
12897 CHECK_FLAG(
12898 p->af_cap
12899 [afi]
12900 [safi],
12901 PEER_CAP_ADDPATH_AF_RX_RCV))
12902 json_object_boolean_true_add(
12903 json_sub,
12904 "rxReceived");
d62a17ae 12905 }
12906
05c7a1cc
QY
12907 if (CHECK_FLAG(
12908 p->af_cap[afi]
12909 [safi],
12910 PEER_CAP_ADDPATH_AF_TX_ADV)
12911 || CHECK_FLAG(
12912 p->af_cap[afi]
12913 [safi],
12914 PEER_CAP_ADDPATH_AF_TX_RCV)
12915 || CHECK_FLAG(
12916 p->af_cap[afi]
12917 [safi],
12918 PEER_CAP_ADDPATH_AF_RX_ADV)
12919 || CHECK_FLAG(
12920 p->af_cap[afi]
12921 [safi],
12922 PEER_CAP_ADDPATH_AF_RX_RCV))
12923 json_object_object_add(
12924 json_add,
12925 print_store,
12926 json_sub);
12927 else
12928 json_object_free(
12929 json_sub);
12930 }
12931
d62a17ae 12932 json_object_object_add(
12933 json_cap, "addPath", json_add);
12934 }
12935
12936 /* Dynamic */
12937 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12938 || CHECK_FLAG(p->cap,
12939 PEER_CAP_DYNAMIC_ADV)) {
12940 if (CHECK_FLAG(p->cap,
12941 PEER_CAP_DYNAMIC_ADV)
12942 && CHECK_FLAG(p->cap,
12943 PEER_CAP_DYNAMIC_RCV))
12944 json_object_string_add(
12945 json_cap, "dynamic",
12946 "advertisedAndReceived");
12947 else if (CHECK_FLAG(
12948 p->cap,
12949 PEER_CAP_DYNAMIC_ADV))
12950 json_object_string_add(
12951 json_cap, "dynamic",
12952 "advertised");
12953 else if (CHECK_FLAG(
12954 p->cap,
12955 PEER_CAP_DYNAMIC_RCV))
12956 json_object_string_add(
12957 json_cap, "dynamic",
12958 "received");
12959 }
12960
12961 /* Extended nexthop */
12962 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12963 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12964 json_object *json_nxt = NULL;
12965 const char *print_store;
12966
12967
12968 if (CHECK_FLAG(p->cap,
12969 PEER_CAP_ENHE_ADV)
12970 && CHECK_FLAG(p->cap,
12971 PEER_CAP_ENHE_RCV))
12972 json_object_string_add(
12973 json_cap,
12974 "extendedNexthop",
12975 "advertisedAndReceived");
12976 else if (CHECK_FLAG(p->cap,
12977 PEER_CAP_ENHE_ADV))
12978 json_object_string_add(
12979 json_cap,
12980 "extendedNexthop",
12981 "advertised");
12982 else if (CHECK_FLAG(p->cap,
12983 PEER_CAP_ENHE_RCV))
12984 json_object_string_add(
12985 json_cap,
12986 "extendedNexthop",
12987 "received");
12988
12989 if (CHECK_FLAG(p->cap,
12990 PEER_CAP_ENHE_RCV)) {
12991 json_nxt =
12992 json_object_new_object();
12993
12994 for (safi = SAFI_UNICAST;
12995 safi < SAFI_MAX; safi++) {
12996 if (CHECK_FLAG(
12997 p->af_cap
12998 [AFI_IP]
12999 [safi],
13000 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 13001 print_store = get_afi_safi_str(
d62a17ae 13002 AFI_IP,
5cb5f4d0 13003 safi, true);
d62a17ae 13004 json_object_string_add(
13005 json_nxt,
13006 print_store,
54f29523 13007 "recieved"); /* misspelled for compatibility */
d62a17ae 13008 }
13009 }
13010 json_object_object_add(
13011 json_cap,
13012 "extendedNexthopFamililesByPeer",
13013 json_nxt);
13014 }
13015 }
13016
13017 /* Route Refresh */
13018 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13019 || CHECK_FLAG(p->cap,
13020 PEER_CAP_REFRESH_NEW_RCV)
13021 || CHECK_FLAG(p->cap,
13022 PEER_CAP_REFRESH_OLD_RCV)) {
13023 if (CHECK_FLAG(p->cap,
13024 PEER_CAP_REFRESH_ADV)
13025 && (CHECK_FLAG(
13026 p->cap,
13027 PEER_CAP_REFRESH_NEW_RCV)
13028 || CHECK_FLAG(
13029 p->cap,
13030 PEER_CAP_REFRESH_OLD_RCV))) {
13031 if (CHECK_FLAG(
13032 p->cap,
13033 PEER_CAP_REFRESH_OLD_RCV)
13034 && CHECK_FLAG(
13035 p->cap,
13036 PEER_CAP_REFRESH_NEW_RCV))
13037 json_object_string_add(
13038 json_cap,
13039 "routeRefresh",
13040 "advertisedAndReceivedOldNew");
13041 else {
13042 if (CHECK_FLAG(
13043 p->cap,
13044 PEER_CAP_REFRESH_OLD_RCV))
13045 json_object_string_add(
13046 json_cap,
13047 "routeRefresh",
13048 "advertisedAndReceivedOld");
13049 else
13050 json_object_string_add(
13051 json_cap,
13052 "routeRefresh",
13053 "advertisedAndReceivedNew");
13054 }
13055 } else if (
13056 CHECK_FLAG(
13057 p->cap,
13058 PEER_CAP_REFRESH_ADV))
13059 json_object_string_add(
13060 json_cap,
13061 "routeRefresh",
13062 "advertised");
13063 else if (
13064 CHECK_FLAG(
13065 p->cap,
13066 PEER_CAP_REFRESH_NEW_RCV)
13067 || CHECK_FLAG(
13068 p->cap,
13069 PEER_CAP_REFRESH_OLD_RCV))
13070 json_object_string_add(
13071 json_cap,
13072 "routeRefresh",
13073 "received");
13074 }
13075
13076 /* Multiprotocol Extensions */
13077 json_object *json_multi = NULL;
13078 json_multi = json_object_new_object();
13079
05c7a1cc
QY
13080 FOREACH_AFI_SAFI (afi, safi) {
13081 if (p->afc_adv[afi][safi]
13082 || p->afc_recv[afi][safi]) {
13083 json_object *json_exten = NULL;
13084 json_exten =
13085 json_object_new_object();
13086
d62a17ae 13087 if (p->afc_adv[afi][safi]
05c7a1cc
QY
13088 && p->afc_recv[afi][safi])
13089 json_object_boolean_true_add(
13090 json_exten,
13091 "advertisedAndReceived");
13092 else if (p->afc_adv[afi][safi])
13093 json_object_boolean_true_add(
13094 json_exten,
13095 "advertised");
13096 else if (p->afc_recv[afi][safi])
13097 json_object_boolean_true_add(
13098 json_exten,
13099 "received");
d62a17ae 13100
05c7a1cc
QY
13101 json_object_object_add(
13102 json_multi,
5cb5f4d0
DD
13103 get_afi_safi_str(afi,
13104 safi,
13105 true),
05c7a1cc 13106 json_exten);
d62a17ae 13107 }
13108 }
13109 json_object_object_add(
13110 json_cap, "multiprotocolExtensions",
13111 json_multi);
13112
d77114b7 13113 /* Hostname capabilities */
60466a63 13114 json_object *json_hname = NULL;
d77114b7
MK
13115
13116 json_hname = json_object_new_object();
13117
13118 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13119 json_object_string_add(
60466a63
QY
13120 json_hname, "advHostName",
13121 bgp->peer_self->hostname
13122 ? bgp->peer_self
13123 ->hostname
d77114b7
MK
13124 : "n/a");
13125 json_object_string_add(
60466a63
QY
13126 json_hname, "advDomainName",
13127 bgp->peer_self->domainname
13128 ? bgp->peer_self
13129 ->domainname
d77114b7
MK
13130 : "n/a");
13131 }
13132
13133
13134 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13135 json_object_string_add(
60466a63
QY
13136 json_hname, "rcvHostName",
13137 p->hostname ? p->hostname
13138 : "n/a");
d77114b7 13139 json_object_string_add(
60466a63
QY
13140 json_hname, "rcvDomainName",
13141 p->domainname ? p->domainname
13142 : "n/a");
d77114b7
MK
13143 }
13144
60466a63 13145 json_object_object_add(json_cap, "hostName",
d77114b7
MK
13146 json_hname);
13147
d62a17ae 13148 /* Gracefull Restart */
13149 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13150 || CHECK_FLAG(p->cap,
13151 PEER_CAP_RESTART_ADV)) {
13152 if (CHECK_FLAG(p->cap,
13153 PEER_CAP_RESTART_ADV)
13154 && CHECK_FLAG(p->cap,
13155 PEER_CAP_RESTART_RCV))
13156 json_object_string_add(
13157 json_cap,
13158 "gracefulRestart",
13159 "advertisedAndReceived");
13160 else if (CHECK_FLAG(
13161 p->cap,
13162 PEER_CAP_RESTART_ADV))
13163 json_object_string_add(
13164 json_cap,
13165 "gracefulRestartCapability",
13166 "advertised");
13167 else if (CHECK_FLAG(
13168 p->cap,
13169 PEER_CAP_RESTART_RCV))
13170 json_object_string_add(
13171 json_cap,
13172 "gracefulRestartCapability",
13173 "received");
13174
13175 if (CHECK_FLAG(p->cap,
13176 PEER_CAP_RESTART_RCV)) {
13177 int restart_af_count = 0;
13178 json_object *json_restart =
13179 NULL;
13180 json_restart =
13181 json_object_new_object();
13182
13183 json_object_int_add(
13184 json_cap,
13185 "gracefulRestartRemoteTimerMsecs",
13186 p->v_gr_restart * 1000);
13187
05c7a1cc
QY
13188 FOREACH_AFI_SAFI (afi, safi) {
13189 if (CHECK_FLAG(
13190 p->af_cap
13191 [afi]
13192 [safi],
13193 PEER_CAP_RESTART_AF_RCV)) {
13194 json_object *
13195 json_sub =
13196 NULL;
13197 json_sub =
13198 json_object_new_object();
13199
d62a17ae 13200 if (CHECK_FLAG(
13201 p->af_cap
13202 [afi]
13203 [safi],
05c7a1cc
QY
13204 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13205 json_object_boolean_true_add(
13206 json_sub,
13207 "preserved");
13208 restart_af_count++;
13209 json_object_object_add(
13210 json_restart,
5cb5f4d0 13211 get_afi_safi_str(
05c7a1cc 13212 afi,
5cb5f4d0
DD
13213 safi,
13214 true),
05c7a1cc 13215 json_sub);
d62a17ae 13216 }
13217 }
13218 if (!restart_af_count) {
13219 json_object_string_add(
13220 json_cap,
13221 "addressFamiliesByPeer",
13222 "none");
13223 json_object_free(
13224 json_restart);
13225 } else
13226 json_object_object_add(
13227 json_cap,
13228 "addressFamiliesByPeer",
13229 json_restart);
13230 }
13231 }
13232 json_object_object_add(json_neigh,
13233 "neighborCapabilities",
13234 json_cap);
13235 } else {
13236 vty_out(vty, " Neighbor capabilities:\n");
13237
13238 /* AS4 */
13239 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13240 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13241 vty_out(vty, " 4 Byte AS:");
13242 if (CHECK_FLAG(p->cap,
13243 PEER_CAP_AS4_ADV))
13244 vty_out(vty, " advertised");
13245 if (CHECK_FLAG(p->cap,
13246 PEER_CAP_AS4_RCV))
13247 vty_out(vty, " %sreceived",
13248 CHECK_FLAG(
13249 p->cap,
13250 PEER_CAP_AS4_ADV)
13251 ? "and "
13252 : "");
13253 vty_out(vty, "\n");
13254 }
13255
13256 /* AddPath */
13257 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13258 || CHECK_FLAG(p->cap,
13259 PEER_CAP_ADDPATH_ADV)) {
13260 vty_out(vty, " AddPath:\n");
13261
05c7a1cc
QY
13262 FOREACH_AFI_SAFI (afi, safi) {
13263 if (CHECK_FLAG(
13264 p->af_cap[afi]
13265 [safi],
13266 PEER_CAP_ADDPATH_AF_TX_ADV)
13267 || CHECK_FLAG(
13268 p->af_cap[afi]
13269 [safi],
13270 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13271 vty_out(vty,
13272 " %s: TX ",
5cb5f4d0 13273 get_afi_safi_str(
05c7a1cc 13274 afi,
5cb5f4d0
DD
13275 safi,
13276 false));
05c7a1cc 13277
d62a17ae 13278 if (CHECK_FLAG(
13279 p->af_cap
13280 [afi]
13281 [safi],
05c7a1cc 13282 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 13283 vty_out(vty,
05c7a1cc 13284 "advertised %s",
5cb5f4d0 13285 get_afi_safi_str(
d62a17ae 13286 afi,
5cb5f4d0
DD
13287 safi,
13288 false));
d62a17ae 13289
05c7a1cc
QY
13290 if (CHECK_FLAG(
13291 p->af_cap
13292 [afi]
13293 [safi],
13294 PEER_CAP_ADDPATH_AF_TX_RCV))
13295 vty_out(vty,
13296 "%sreceived",
13297 CHECK_FLAG(
13298 p->af_cap
13299 [afi]
13300 [safi],
13301 PEER_CAP_ADDPATH_AF_TX_ADV)
13302 ? " and "
13303 : "");
d62a17ae 13304
05c7a1cc
QY
13305 vty_out(vty, "\n");
13306 }
d62a17ae 13307
05c7a1cc
QY
13308 if (CHECK_FLAG(
13309 p->af_cap[afi]
13310 [safi],
13311 PEER_CAP_ADDPATH_AF_RX_ADV)
13312 || CHECK_FLAG(
13313 p->af_cap[afi]
13314 [safi],
13315 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13316 vty_out(vty,
13317 " %s: RX ",
5cb5f4d0 13318 get_afi_safi_str(
05c7a1cc 13319 afi,
5cb5f4d0
DD
13320 safi,
13321 false));
d62a17ae 13322
13323 if (CHECK_FLAG(
13324 p->af_cap
13325 [afi]
13326 [safi],
05c7a1cc 13327 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 13328 vty_out(vty,
05c7a1cc 13329 "advertised %s",
5cb5f4d0 13330 get_afi_safi_str(
d62a17ae 13331 afi,
5cb5f4d0
DD
13332 safi,
13333 false));
d62a17ae 13334
05c7a1cc
QY
13335 if (CHECK_FLAG(
13336 p->af_cap
13337 [afi]
13338 [safi],
13339 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 13340 vty_out(vty,
05c7a1cc
QY
13341 "%sreceived",
13342 CHECK_FLAG(
13343 p->af_cap
13344 [afi]
13345 [safi],
13346 PEER_CAP_ADDPATH_AF_RX_ADV)
13347 ? " and "
13348 : "");
13349
13350 vty_out(vty, "\n");
d62a17ae 13351 }
05c7a1cc 13352 }
d62a17ae 13353 }
13354
13355 /* Dynamic */
13356 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13357 || CHECK_FLAG(p->cap,
13358 PEER_CAP_DYNAMIC_ADV)) {
13359 vty_out(vty, " Dynamic:");
13360 if (CHECK_FLAG(p->cap,
13361 PEER_CAP_DYNAMIC_ADV))
13362 vty_out(vty, " advertised");
13363 if (CHECK_FLAG(p->cap,
13364 PEER_CAP_DYNAMIC_RCV))
13365 vty_out(vty, " %sreceived",
13366 CHECK_FLAG(
13367 p->cap,
13368 PEER_CAP_DYNAMIC_ADV)
13369 ? "and "
13370 : "");
13371 vty_out(vty, "\n");
13372 }
13373
13374 /* Extended nexthop */
13375 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13376 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13377 vty_out(vty, " Extended nexthop:");
13378 if (CHECK_FLAG(p->cap,
13379 PEER_CAP_ENHE_ADV))
13380 vty_out(vty, " advertised");
13381 if (CHECK_FLAG(p->cap,
13382 PEER_CAP_ENHE_RCV))
13383 vty_out(vty, " %sreceived",
13384 CHECK_FLAG(
13385 p->cap,
13386 PEER_CAP_ENHE_ADV)
13387 ? "and "
13388 : "");
13389 vty_out(vty, "\n");
13390
13391 if (CHECK_FLAG(p->cap,
13392 PEER_CAP_ENHE_RCV)) {
13393 vty_out(vty,
13394 " Address families by peer:\n ");
13395 for (safi = SAFI_UNICAST;
13396 safi < SAFI_MAX; safi++)
13397 if (CHECK_FLAG(
13398 p->af_cap
13399 [AFI_IP]
13400 [safi],
13401 PEER_CAP_ENHE_AF_RCV))
13402 vty_out(vty,
13403 " %s\n",
5cb5f4d0 13404 get_afi_safi_str(
d62a17ae 13405 AFI_IP,
5cb5f4d0
DD
13406 safi,
13407 false));
d62a17ae 13408 }
13409 }
13410
13411 /* Route Refresh */
13412 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13413 || CHECK_FLAG(p->cap,
13414 PEER_CAP_REFRESH_NEW_RCV)
13415 || CHECK_FLAG(p->cap,
13416 PEER_CAP_REFRESH_OLD_RCV)) {
13417 vty_out(vty, " Route refresh:");
13418 if (CHECK_FLAG(p->cap,
13419 PEER_CAP_REFRESH_ADV))
13420 vty_out(vty, " advertised");
13421 if (CHECK_FLAG(p->cap,
13422 PEER_CAP_REFRESH_NEW_RCV)
13423 || CHECK_FLAG(
13424 p->cap,
13425 PEER_CAP_REFRESH_OLD_RCV))
13426 vty_out(vty, " %sreceived(%s)",
13427 CHECK_FLAG(
13428 p->cap,
13429 PEER_CAP_REFRESH_ADV)
13430 ? "and "
13431 : "",
13432 (CHECK_FLAG(
13433 p->cap,
13434 PEER_CAP_REFRESH_OLD_RCV)
13435 && CHECK_FLAG(
13436 p->cap,
13437 PEER_CAP_REFRESH_NEW_RCV))
13438 ? "old & new"
13439 : CHECK_FLAG(
13440 p->cap,
13441 PEER_CAP_REFRESH_OLD_RCV)
13442 ? "old"
13443 : "new");
13444
13445 vty_out(vty, "\n");
13446 }
13447
13448 /* Multiprotocol Extensions */
05c7a1cc
QY
13449 FOREACH_AFI_SAFI (afi, safi)
13450 if (p->afc_adv[afi][safi]
13451 || p->afc_recv[afi][safi]) {
13452 vty_out(vty,
13453 " Address Family %s:",
5cb5f4d0
DD
13454 get_afi_safi_str(
13455 afi,
13456 safi,
13457 false));
05c7a1cc 13458 if (p->afc_adv[afi][safi])
d62a17ae 13459 vty_out(vty,
05c7a1cc
QY
13460 " advertised");
13461 if (p->afc_recv[afi][safi])
13462 vty_out(vty,
13463 " %sreceived",
13464 p->afc_adv[afi]
13465 [safi]
13466 ? "and "
13467 : "");
13468 vty_out(vty, "\n");
13469 }
d62a17ae 13470
13471 /* Hostname capability */
60466a63 13472 vty_out(vty, " Hostname Capability:");
d77114b7
MK
13473
13474 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
13475 vty_out(vty,
13476 " advertised (name: %s,domain name: %s)",
60466a63
QY
13477 bgp->peer_self->hostname
13478 ? bgp->peer_self
13479 ->hostname
d77114b7 13480 : "n/a",
60466a63
QY
13481 bgp->peer_self->domainname
13482 ? bgp->peer_self
13483 ->domainname
d77114b7
MK
13484 : "n/a");
13485 } else {
13486 vty_out(vty, " not advertised");
d62a17ae 13487 }
13488
d77114b7 13489 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
13490 vty_out(vty,
13491 " received (name: %s,domain name: %s)",
60466a63
QY
13492 p->hostname ? p->hostname
13493 : "n/a",
13494 p->domainname ? p->domainname
13495 : "n/a");
d77114b7
MK
13496 } else {
13497 vty_out(vty, " not received");
13498 }
13499
13500 vty_out(vty, "\n");
13501
61bfbd51 13502 /* Graceful Restart */
d62a17ae 13503 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13504 || CHECK_FLAG(p->cap,
13505 PEER_CAP_RESTART_ADV)) {
13506 vty_out(vty,
61bfbd51 13507 " Graceful Restart Capability:");
d62a17ae 13508 if (CHECK_FLAG(p->cap,
13509 PEER_CAP_RESTART_ADV))
13510 vty_out(vty, " advertised");
13511 if (CHECK_FLAG(p->cap,
13512 PEER_CAP_RESTART_RCV))
13513 vty_out(vty, " %sreceived",
13514 CHECK_FLAG(
13515 p->cap,
13516 PEER_CAP_RESTART_ADV)
13517 ? "and "
13518 : "");
13519 vty_out(vty, "\n");
13520
13521 if (CHECK_FLAG(p->cap,
13522 PEER_CAP_RESTART_RCV)) {
13523 int restart_af_count = 0;
13524
13525 vty_out(vty,
13526 " Remote Restart timer is %d seconds\n",
13527 p->v_gr_restart);
13528 vty_out(vty,
13529 " Address families by peer:\n ");
13530
05c7a1cc
QY
13531 FOREACH_AFI_SAFI (afi, safi)
13532 if (CHECK_FLAG(
13533 p->af_cap
13534 [afi]
13535 [safi],
13536 PEER_CAP_RESTART_AF_RCV)) {
13537 vty_out(vty,
13538 "%s%s(%s)",
13539 restart_af_count
13540 ? ", "
13541 : "",
5cb5f4d0 13542 get_afi_safi_str(
05c7a1cc 13543 afi,
5cb5f4d0
DD
13544 safi,
13545 false),
05c7a1cc
QY
13546 CHECK_FLAG(
13547 p->af_cap
13548 [afi]
13549 [safi],
13550 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13551 ? "preserved"
13552 : "not preserved");
13553 restart_af_count++;
13554 }
d62a17ae 13555 if (!restart_af_count)
13556 vty_out(vty, "none");
13557 vty_out(vty, "\n");
13558 }
2986cac2 13559 } /* Gracefull Restart */
d62a17ae 13560 }
13561 }
13562 }
13563
13564 /* graceful restart information */
d62a17ae 13565 json_object *json_grace = NULL;
13566 json_object *json_grace_send = NULL;
13567 json_object *json_grace_recv = NULL;
13568 int eor_send_af_count = 0;
13569 int eor_receive_af_count = 0;
13570
13571 if (use_json) {
13572 json_grace = json_object_new_object();
13573 json_grace_send = json_object_new_object();
13574 json_grace_recv = json_object_new_object();
13575
36235319
QY
13576 if ((p->status == Established)
13577 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
13578 FOREACH_AFI_SAFI (afi, safi) {
13579 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 13580 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
13581 json_object_boolean_true_add(
13582 json_grace_send,
5cb5f4d0
DD
13583 get_afi_safi_str(afi,
13584 safi,
13585 true));
05c7a1cc 13586 eor_send_af_count++;
d62a17ae 13587 }
13588 }
05c7a1cc
QY
13589 FOREACH_AFI_SAFI (afi, safi) {
13590 if (CHECK_FLAG(
36235319
QY
13591 p->af_sflags[afi][safi],
13592 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
13593 json_object_boolean_true_add(
13594 json_grace_recv,
5cb5f4d0
DD
13595 get_afi_safi_str(afi,
13596 safi,
13597 true));
05c7a1cc 13598 eor_receive_af_count++;
d62a17ae 13599 }
13600 }
13601 }
36235319
QY
13602 json_object_object_add(json_grace, "endOfRibSend",
13603 json_grace_send);
13604 json_object_object_add(json_grace, "endOfRibRecv",
13605 json_grace_recv);
d62a17ae 13606
d62a17ae 13607
13608 if (p->t_gr_restart)
13609 json_object_int_add(json_grace,
13610 "gracefulRestartTimerMsecs",
13611 thread_timer_remain_second(
13612 p->t_gr_restart)
13613 * 1000);
13614
13615 if (p->t_gr_stale)
13616 json_object_int_add(
13617 json_grace,
13618 "gracefulStalepathTimerMsecs",
13619 thread_timer_remain_second(
13620 p->t_gr_stale)
13621 * 1000);
2986cac2 13622 /* more gr info in new format */
13623 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 13624 json_grace);
d62a17ae 13625 json_object_object_add(
13626 json_neigh, "gracefulRestartInfo", json_grace);
13627 } else {
2089dd80 13628 vty_out(vty, " Graceful restart information:\n");
36235319
QY
13629 if ((p->status == Established)
13630 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 13631
d62a17ae 13632 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
13633 FOREACH_AFI_SAFI (afi, safi) {
13634 if (CHECK_FLAG(p->af_sflags[afi][safi],
13635 PEER_STATUS_EOR_SEND)) {
13636 vty_out(vty, "%s%s",
13637 eor_send_af_count ? ", "
13638 : "",
36235319
QY
13639 get_afi_safi_str(
13640 afi, safi,
13641 false));
05c7a1cc 13642 eor_send_af_count++;
d62a17ae 13643 }
13644 }
13645 vty_out(vty, "\n");
13646 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
13647 FOREACH_AFI_SAFI (afi, safi) {
13648 if (CHECK_FLAG(
13649 p->af_sflags[afi][safi],
13650 PEER_STATUS_EOR_RECEIVED)) {
13651 vty_out(vty, "%s%s",
13652 eor_receive_af_count
13653 ? ", "
13654 : "",
5cb5f4d0
DD
13655 get_afi_safi_str(afi,
13656 safi,
13657 false));
05c7a1cc 13658 eor_receive_af_count++;
d62a17ae 13659 }
13660 }
13661 vty_out(vty, "\n");
13662 }
13663
13664 if (p->t_gr_restart)
13665 vty_out(vty,
13666 " The remaining time of restart timer is %ld\n",
13667 thread_timer_remain_second(
13668 p->t_gr_restart));
13669
13670 if (p->t_gr_stale)
13671 vty_out(vty,
13672 " The remaining time of stalepath timer is %ld\n",
13673 thread_timer_remain_second(
13674 p->t_gr_stale));
2986cac2 13675
13676 /* more gr info in new format */
13677 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 13678 }
2986cac2 13679
d62a17ae 13680 if (use_json) {
13681 json_object *json_stat = NULL;
13682 json_stat = json_object_new_object();
13683 /* Packet counts. */
43aa5965
QY
13684
13685 atomic_size_t outq_count, inq_count;
13686 outq_count = atomic_load_explicit(&p->obuf->count,
13687 memory_order_relaxed);
13688 inq_count = atomic_load_explicit(&p->ibuf->count,
13689 memory_order_relaxed);
13690
13691 json_object_int_add(json_stat, "depthInq",
13692 (unsigned long)inq_count);
d62a17ae 13693 json_object_int_add(json_stat, "depthOutq",
43aa5965 13694 (unsigned long)outq_count);
0112e9e0
QY
13695 json_object_int_add(json_stat, "opensSent",
13696 atomic_load_explicit(&p->open_out,
13697 memory_order_relaxed));
13698 json_object_int_add(json_stat, "opensRecv",
13699 atomic_load_explicit(&p->open_in,
13700 memory_order_relaxed));
d62a17ae 13701 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13702 atomic_load_explicit(&p->notify_out,
13703 memory_order_relaxed));
d62a17ae 13704 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13705 atomic_load_explicit(&p->notify_in,
13706 memory_order_relaxed));
13707 json_object_int_add(json_stat, "updatesSent",
13708 atomic_load_explicit(&p->update_out,
13709 memory_order_relaxed));
13710 json_object_int_add(json_stat, "updatesRecv",
13711 atomic_load_explicit(&p->update_in,
13712 memory_order_relaxed));
d62a17ae 13713 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13714 atomic_load_explicit(&p->keepalive_out,
13715 memory_order_relaxed));
d62a17ae 13716 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13717 atomic_load_explicit(&p->keepalive_in,
13718 memory_order_relaxed));
d62a17ae 13719 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13720 atomic_load_explicit(&p->refresh_out,
13721 memory_order_relaxed));
d62a17ae 13722 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13723 atomic_load_explicit(&p->refresh_in,
13724 memory_order_relaxed));
d62a17ae 13725 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13726 atomic_load_explicit(&p->dynamic_cap_out,
13727 memory_order_relaxed));
d62a17ae 13728 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13729 atomic_load_explicit(&p->dynamic_cap_in,
13730 memory_order_relaxed));
13731 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13732 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13733 json_object_object_add(json_neigh, "messageStats", json_stat);
13734 } else {
43aa5965
QY
13735 atomic_size_t outq_count, inq_count;
13736 outq_count = atomic_load_explicit(&p->obuf->count,
13737 memory_order_relaxed);
13738 inq_count = atomic_load_explicit(&p->ibuf->count,
13739 memory_order_relaxed);
13740
d62a17ae 13741 /* Packet counts. */
13742 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13743 vty_out(vty, " Inq depth is %zu\n", inq_count);
13744 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13745 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
13746 vty_out(vty, " Opens: %10d %10d\n",
13747 atomic_load_explicit(&p->open_out,
13748 memory_order_relaxed),
13749 atomic_load_explicit(&p->open_in,
13750 memory_order_relaxed));
13751 vty_out(vty, " Notifications: %10d %10d\n",
13752 atomic_load_explicit(&p->notify_out,
13753 memory_order_relaxed),
13754 atomic_load_explicit(&p->notify_in,
13755 memory_order_relaxed));
13756 vty_out(vty, " Updates: %10d %10d\n",
13757 atomic_load_explicit(&p->update_out,
13758 memory_order_relaxed),
13759 atomic_load_explicit(&p->update_in,
13760 memory_order_relaxed));
13761 vty_out(vty, " Keepalives: %10d %10d\n",
13762 atomic_load_explicit(&p->keepalive_out,
13763 memory_order_relaxed),
13764 atomic_load_explicit(&p->keepalive_in,
13765 memory_order_relaxed));
13766 vty_out(vty, " Route Refresh: %10d %10d\n",
13767 atomic_load_explicit(&p->refresh_out,
13768 memory_order_relaxed),
13769 atomic_load_explicit(&p->refresh_in,
13770 memory_order_relaxed));
d62a17ae 13771 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
13772 atomic_load_explicit(&p->dynamic_cap_out,
13773 memory_order_relaxed),
13774 atomic_load_explicit(&p->dynamic_cap_in,
13775 memory_order_relaxed));
13776 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13777 PEER_TOTAL_RX(p));
d62a17ae 13778 }
13779
13780 if (use_json) {
13781 /* advertisement-interval */
13782 json_object_int_add(json_neigh,
13783 "minBtwnAdvertisementRunsTimerMsecs",
13784 p->v_routeadv * 1000);
13785
13786 /* Update-source. */
13787 if (p->update_if || p->update_source) {
13788 if (p->update_if)
13789 json_object_string_add(json_neigh,
13790 "updateSource",
13791 p->update_if);
13792 else if (p->update_source)
13793 json_object_string_add(
13794 json_neigh, "updateSource",
13795 sockunion2str(p->update_source, buf1,
13796 SU_ADDRSTRLEN));
13797 }
13798 } else {
13799 /* advertisement-interval */
13800 vty_out(vty,
13801 " Minimum time between advertisement runs is %d seconds\n",
13802 p->v_routeadv);
13803
13804 /* Update-source. */
13805 if (p->update_if || p->update_source) {
13806 vty_out(vty, " Update source is ");
13807 if (p->update_if)
13808 vty_out(vty, "%s", p->update_if);
13809 else if (p->update_source)
13810 vty_out(vty, "%s",
13811 sockunion2str(p->update_source, buf1,
13812 SU_ADDRSTRLEN));
13813 vty_out(vty, "\n");
13814 }
13815
13816 vty_out(vty, "\n");
13817 }
13818
13819 /* Address Family Information */
13820 json_object *json_hold = NULL;
13821
13822 if (use_json)
13823 json_hold = json_object_new_object();
13824
05c7a1cc
QY
13825 FOREACH_AFI_SAFI (afi, safi)
13826 if (p->afc[afi][safi])
13827 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13828 json_hold);
d62a17ae 13829
13830 if (use_json) {
13831 json_object_object_add(json_neigh, "addressFamilyInfo",
13832 json_hold);
13833 json_object_int_add(json_neigh, "connectionsEstablished",
13834 p->established);
13835 json_object_int_add(json_neigh, "connectionsDropped",
13836 p->dropped);
13837 } else
13838 vty_out(vty, " Connections established %d; dropped %d\n",
13839 p->established, p->dropped);
13840
13841 if (!p->last_reset) {
13842 if (use_json)
13843 json_object_string_add(json_neigh, "lastReset",
13844 "never");
13845 else
13846 vty_out(vty, " Last reset never\n");
13847 } else {
13848 if (use_json) {
13849 time_t uptime;
a2700b50 13850 struct tm tm;
d62a17ae 13851
13852 uptime = bgp_clock();
13853 uptime -= p->resettime;
a2700b50
MS
13854 gmtime_r(&uptime, &tm);
13855
d62a17ae 13856 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13857 (tm.tm_sec * 1000)
13858 + (tm.tm_min * 60000)
13859 + (tm.tm_hour * 3600000));
3577f1c5 13860 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13861 } else {
13862 vty_out(vty, " Last reset %s, ",
13863 peer_uptime(p->resettime, timebuf,
13864 BGP_UPTIME_LEN, 0, NULL));
13865
3577f1c5 13866 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13867 if (p->last_reset_cause_size) {
13868 msg = p->last_reset_cause;
13869 vty_out(vty,
13870 " Message received that caused BGP to send a NOTIFICATION:\n ");
13871 for (i = 1; i <= p->last_reset_cause_size;
13872 i++) {
13873 vty_out(vty, "%02X", *msg++);
13874
13875 if (i != p->last_reset_cause_size) {
13876 if (i % 16 == 0) {
13877 vty_out(vty, "\n ");
13878 } else if (i % 4 == 0) {
13879 vty_out(vty, " ");
13880 }
13881 }
13882 }
13883 vty_out(vty, "\n");
13884 }
13885 }
13886 }
13887
13888 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13889 if (use_json)
13890 json_object_boolean_true_add(json_neigh,
13891 "prefixesConfigExceedMax");
13892 else
13893 vty_out(vty,
13894 " Peer had exceeded the max. no. of prefixes configured.\n");
13895
13896 if (p->t_pmax_restart) {
13897 if (use_json) {
13898 json_object_boolean_true_add(
13899 json_neigh, "reducePrefixNumFrom");
13900 json_object_int_add(json_neigh,
13901 "restartInTimerMsec",
13902 thread_timer_remain_second(
13903 p->t_pmax_restart)
13904 * 1000);
13905 } else
13906 vty_out(vty,
13907 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13908 p->host, thread_timer_remain_second(
13909 p->t_pmax_restart));
d62a17ae 13910 } else {
13911 if (use_json)
13912 json_object_boolean_true_add(
13913 json_neigh,
13914 "reducePrefixNumAndClearIpBgp");
13915 else
13916 vty_out(vty,
13917 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13918 p->host);
13919 }
13920 }
13921
13922 /* EBGP Multihop and GTSM */
13923 if (p->sort != BGP_PEER_IBGP) {
13924 if (use_json) {
e2521429 13925 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13926 json_object_int_add(json_neigh,
13927 "externalBgpNbrMaxHopsAway",
13928 p->gtsm_hops);
c8d6f0d6 13929 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13930 json_object_int_add(json_neigh,
13931 "externalBgpNbrMaxHopsAway",
13932 p->ttl);
13933 } else {
e2521429 13934 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13935 vty_out(vty,
13936 " External BGP neighbor may be up to %d hops away.\n",
13937 p->gtsm_hops);
c8d6f0d6 13938 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13939 vty_out(vty,
13940 " External BGP neighbor may be up to %d hops away.\n",
13941 p->ttl);
13942 }
13943 } else {
e2521429 13944 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13945 if (use_json)
13946 json_object_int_add(json_neigh,
13947 "internalBgpNbrMaxHopsAway",
13948 p->gtsm_hops);
13949 else
13950 vty_out(vty,
13951 " Internal BGP neighbor may be up to %d hops away.\n",
13952 p->gtsm_hops);
13953 }
13954 }
13955
13956 /* Local address. */
13957 if (p->su_local) {
13958 if (use_json) {
13959 json_object_string_add(json_neigh, "hostLocal",
13960 sockunion2str(p->su_local, buf1,
13961 SU_ADDRSTRLEN));
13962 json_object_int_add(json_neigh, "portLocal",
13963 ntohs(p->su_local->sin.sin_port));
13964 } else
13965 vty_out(vty, "Local host: %s, Local port: %d\n",
13966 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13967 ntohs(p->su_local->sin.sin_port));
13968 }
13969
13970 /* Remote address. */
13971 if (p->su_remote) {
13972 if (use_json) {
13973 json_object_string_add(json_neigh, "hostForeign",
13974 sockunion2str(p->su_remote, buf1,
13975 SU_ADDRSTRLEN));
13976 json_object_int_add(json_neigh, "portForeign",
13977 ntohs(p->su_remote->sin.sin_port));
13978 } else
13979 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13980 sockunion2str(p->su_remote, buf1,
13981 SU_ADDRSTRLEN),
13982 ntohs(p->su_remote->sin.sin_port));
13983 }
13984
13985 /* Nexthop display. */
13986 if (p->su_local) {
13987 if (use_json) {
13988 json_object_string_add(json_neigh, "nexthop",
13989 inet_ntop(AF_INET,
13990 &p->nexthop.v4, buf1,
13991 sizeof(buf1)));
13992 json_object_string_add(json_neigh, "nexthopGlobal",
13993 inet_ntop(AF_INET6,
13994 &p->nexthop.v6_global,
13995 buf1, sizeof(buf1)));
13996 json_object_string_add(json_neigh, "nexthopLocal",
13997 inet_ntop(AF_INET6,
13998 &p->nexthop.v6_local,
13999 buf1, sizeof(buf1)));
14000 if (p->shared_network)
14001 json_object_string_add(json_neigh,
14002 "bgpConnection",
14003 "sharedNetwork");
14004 else
14005 json_object_string_add(json_neigh,
14006 "bgpConnection",
14007 "nonSharedNetwork");
14008 } else {
14009 vty_out(vty, "Nexthop: %s\n",
14010 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14011 sizeof(buf1)));
14012 vty_out(vty, "Nexthop global: %s\n",
14013 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14014 sizeof(buf1)));
14015 vty_out(vty, "Nexthop local: %s\n",
14016 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14017 sizeof(buf1)));
14018 vty_out(vty, "BGP connection: %s\n",
14019 p->shared_network ? "shared network"
14020 : "non shared network");
14021 }
14022 }
14023
14024 /* Timer information. */
14025 if (use_json) {
14026 json_object_int_add(json_neigh, "connectRetryTimer",
14027 p->v_connect);
14028 if (p->status == Established && p->rtt)
14029 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14030 p->rtt);
14031 if (p->t_start)
14032 json_object_int_add(
14033 json_neigh, "nextStartTimerDueInMsecs",
14034 thread_timer_remain_second(p->t_start) * 1000);
14035 if (p->t_connect)
14036 json_object_int_add(
14037 json_neigh, "nextConnectTimerDueInMsecs",
14038 thread_timer_remain_second(p->t_connect)
14039 * 1000);
14040 if (p->t_routeadv) {
14041 json_object_int_add(json_neigh, "mraiInterval",
14042 p->v_routeadv);
14043 json_object_int_add(
14044 json_neigh, "mraiTimerExpireInMsecs",
14045 thread_timer_remain_second(p->t_routeadv)
14046 * 1000);
14047 }
14048 if (p->password)
14049 json_object_int_add(json_neigh, "authenticationEnabled",
14050 1);
14051
14052 if (p->t_read)
14053 json_object_string_add(json_neigh, "readThread", "on");
14054 else
14055 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14056
14057 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14058 json_object_string_add(json_neigh, "writeThread", "on");
14059 else
14060 json_object_string_add(json_neigh, "writeThread",
14061 "off");
14062 } else {
14063 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14064 p->v_connect);
14065 if (p->status == Established && p->rtt)
14066 vty_out(vty, "Estimated round trip time: %d ms\n",
14067 p->rtt);
14068 if (p->t_start)
14069 vty_out(vty, "Next start timer due in %ld seconds\n",
14070 thread_timer_remain_second(p->t_start));
14071 if (p->t_connect)
14072 vty_out(vty, "Next connect timer due in %ld seconds\n",
14073 thread_timer_remain_second(p->t_connect));
14074 if (p->t_routeadv)
14075 vty_out(vty,
14076 "MRAI (interval %u) timer expires in %ld seconds\n",
14077 p->v_routeadv,
14078 thread_timer_remain_second(p->t_routeadv));
14079 if (p->password)
14080 vty_out(vty, "Peer Authentication Enabled\n");
14081
cac9e917 14082 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14083 p->t_read ? "on" : "off",
14084 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14085 ? "on"
cac9e917 14086 : "off", p->fd);
d62a17ae 14087 }
14088
14089 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14090 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14091 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14092
14093 if (!use_json)
14094 vty_out(vty, "\n");
14095
14096 /* BFD information. */
14097 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14098
14099 if (use_json) {
14100 if (p->conf_if) /* Configured interface name. */
14101 json_object_object_add(json, p->conf_if, json_neigh);
14102 else /* Configured IP address. */
14103 json_object_object_add(json, p->host, json_neigh);
14104 }
14105}
14106
36235319
QY
14107static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14108 enum show_type type,
14109 union sockunion *su,
14110 const char *conf_if, afi_t afi,
74a630b6 14111 bool use_json)
2986cac2 14112{
14113 struct listnode *node, *nnode;
14114 struct peer *peer;
14115 int find = 0;
14116 safi_t safi = SAFI_UNICAST;
74a630b6 14117 json_object *json = NULL;
2986cac2 14118 json_object *json_neighbor = NULL;
14119
74a630b6
NT
14120 if (use_json) {
14121 json = json_object_new_object();
14122 json_neighbor = json_object_new_object();
14123 }
14124
2986cac2 14125 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14126
14127 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14128 continue;
14129
14130 if ((peer->afc[afi][safi]) == 0)
14131 continue;
14132
2ba1fe69 14133 if (type == show_all) {
2986cac2 14134 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14135 json_neighbor);
2986cac2 14136
74a630b6 14137 if (use_json) {
13909c4f
DS
14138 json_object_object_add(json, peer->host,
14139 json_neighbor);
74a630b6
NT
14140 json_neighbor = NULL;
14141 }
2986cac2 14142
2ba1fe69 14143 } else if (type == show_peer) {
2986cac2 14144 if (conf_if) {
14145 if ((peer->conf_if
13909c4f
DS
14146 && !strcmp(peer->conf_if, conf_if))
14147 || (peer->hostname
2986cac2 14148 && !strcmp(peer->hostname, conf_if))) {
14149 find = 1;
13909c4f
DS
14150 bgp_show_peer_gr_status(vty, peer,
14151 use_json,
14152 json_neighbor);
2986cac2 14153 }
14154 } else {
14155 if (sockunion_same(&peer->su, su)) {
14156 find = 1;
13909c4f
DS
14157 bgp_show_peer_gr_status(vty, peer,
14158 use_json,
14159 json_neighbor);
2986cac2 14160 }
14161 }
13909c4f
DS
14162 if (use_json && find)
14163 json_object_object_add(json, peer->host,
14164 json_neighbor);
2986cac2 14165 }
14166
74a630b6
NT
14167 if (find) {
14168 json_neighbor = NULL;
2986cac2 14169 break;
74a630b6 14170 }
2986cac2 14171 }
14172
14173 if (type == show_peer && !find) {
14174 if (use_json)
13909c4f 14175 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14176 else
14177 vty_out(vty, "%% No such neighbor\n");
14178 }
14179 if (use_json) {
13909c4f
DS
14180 vty_out(vty, "%s\n",
14181 json_object_to_json_string_ext(
14182 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
14183
14184 if (json_neighbor)
14185 json_object_free(json_neighbor);
14186 json_object_free(json);
2986cac2 14187 } else {
14188 vty_out(vty, "\n");
14189 }
14190
14191 return CMD_SUCCESS;
14192}
14193
d62a17ae 14194static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14195 enum show_type type, union sockunion *su,
9f049418 14196 const char *conf_if, bool use_json,
d62a17ae 14197 json_object *json)
14198{
14199 struct listnode *node, *nnode;
14200 struct peer *peer;
14201 int find = 0;
9f049418 14202 bool nbr_output = false;
d1927ebe
AS
14203 afi_t afi = AFI_MAX;
14204 safi_t safi = SAFI_MAX;
14205
14206 if (type == show_ipv4_peer || type == show_ipv4_all) {
14207 afi = AFI_IP;
14208 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14209 afi = AFI_IP6;
14210 }
d62a17ae 14211
14212 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14213 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14214 continue;
14215
14216 switch (type) {
14217 case show_all:
14218 bgp_show_peer(vty, peer, use_json, json);
9f049418 14219 nbr_output = true;
d62a17ae 14220 break;
14221 case show_peer:
14222 if (conf_if) {
14223 if ((peer->conf_if
14224 && !strcmp(peer->conf_if, conf_if))
14225 || (peer->hostname
14226 && !strcmp(peer->hostname, conf_if))) {
14227 find = 1;
14228 bgp_show_peer(vty, peer, use_json,
14229 json);
14230 }
14231 } else {
14232 if (sockunion_same(&peer->su, su)) {
14233 find = 1;
14234 bgp_show_peer(vty, peer, use_json,
14235 json);
14236 }
14237 }
14238 break;
d1927ebe
AS
14239 case show_ipv4_peer:
14240 case show_ipv6_peer:
14241 FOREACH_SAFI (safi) {
14242 if (peer->afc[afi][safi]) {
14243 if (conf_if) {
14244 if ((peer->conf_if
14245 && !strcmp(peer->conf_if, conf_if))
14246 || (peer->hostname
14247 && !strcmp(peer->hostname, conf_if))) {
14248 find = 1;
14249 bgp_show_peer(vty, peer, use_json,
14250 json);
14251 break;
14252 }
14253 } else {
14254 if (sockunion_same(&peer->su, su)) {
14255 find = 1;
14256 bgp_show_peer(vty, peer, use_json,
14257 json);
14258 break;
14259 }
14260 }
14261 }
14262 }
14263 break;
14264 case show_ipv4_all:
14265 case show_ipv6_all:
14266 FOREACH_SAFI (safi) {
14267 if (peer->afc[afi][safi]) {
14268 bgp_show_peer(vty, peer, use_json, json);
14269 nbr_output = true;
14270 break;
14271 }
14272 }
14273 break;
d62a17ae 14274 }
14275 }
14276
d1927ebe
AS
14277 if ((type == show_peer || type == show_ipv4_peer ||
14278 type == show_ipv6_peer) && !find) {
d62a17ae 14279 if (use_json)
14280 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14281 else
88b7d255 14282 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14283 }
14284
d1927ebe
AS
14285 if (type != show_peer && type != show_ipv4_peer &&
14286 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14287 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14288
d62a17ae 14289 if (use_json) {
996c9314
LB
14290 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14291 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14292 } else {
14293 vty_out(vty, "\n");
14294 }
14295
14296 return CMD_SUCCESS;
14297}
14298
36235319
QY
14299static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14300 enum show_type type,
14301 const char *ip_str,
14302 afi_t afi, bool use_json)
2986cac2 14303{
14304
14305 int ret;
14306 struct bgp *bgp;
14307 union sockunion su;
2986cac2 14308
14309 bgp = bgp_get_default();
14310
13909c4f
DS
14311 if (!bgp)
14312 return;
2986cac2 14313
13909c4f
DS
14314 if (!use_json)
14315 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14316 NULL);
2986cac2 14317
13909c4f
DS
14318 if (ip_str) {
14319 ret = str2sockunion(ip_str, &su);
14320 if (ret < 0)
13909c4f 14321 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14322 vty, bgp, type, NULL, ip_str, afi, use_json);
14323 else
14324 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14325 NULL, afi, use_json);
13909c4f
DS
14326 } else
14327 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14328 afi, use_json);
2986cac2 14329}
14330
d62a17ae 14331static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14332 enum show_type type,
14333 const char *ip_str,
9f049418 14334 bool use_json)
d62a17ae 14335{
0291c246
MK
14336 struct listnode *node, *nnode;
14337 struct bgp *bgp;
71aedaa3 14338 union sockunion su;
0291c246 14339 json_object *json = NULL;
71aedaa3 14340 int ret, is_first = 1;
9f049418 14341 bool nbr_output = false;
d62a17ae 14342
14343 if (use_json)
14344 vty_out(vty, "{\n");
14345
14346 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14347 nbr_output = true;
d62a17ae 14348 if (use_json) {
14349 if (!(json = json_object_new_object())) {
af4c2728 14350 flog_err(
e50f7cfd 14351 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14352 "Unable to allocate memory for JSON object");
14353 vty_out(vty,
14354 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14355 return;
14356 }
14357
14358 json_object_int_add(json, "vrfId",
14359 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14360 ? -1
14361 : (int64_t)bgp->vrf_id);
d62a17ae 14362 json_object_string_add(
14363 json, "vrfName",
14364 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14365 ? VRF_DEFAULT_NAME
d62a17ae 14366 : bgp->name);
14367
14368 if (!is_first)
14369 vty_out(vty, ",\n");
14370 else
14371 is_first = 0;
14372
14373 vty_out(vty, "\"%s\":",
14374 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14375 ? VRF_DEFAULT_NAME
d62a17ae 14376 : bgp->name);
14377 } else {
14378 vty_out(vty, "\nInstance %s:\n",
14379 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14380 ? VRF_DEFAULT_NAME
d62a17ae 14381 : bgp->name);
14382 }
71aedaa3 14383
d1927ebe
AS
14384 if (type == show_peer || type == show_ipv4_peer ||
14385 type == show_ipv6_peer) {
71aedaa3
DS
14386 ret = str2sockunion(ip_str, &su);
14387 if (ret < 0)
14388 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14389 use_json, json);
14390 else
14391 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14392 use_json, json);
14393 } else {
d1927ebe 14394 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14395 use_json, json);
14396 }
b77004d6 14397 json_object_free(json);
121067e9 14398 json = NULL;
d62a17ae 14399 }
14400
3e78a6ce 14401 if (use_json)
d62a17ae 14402 vty_out(vty, "}\n");
9f049418
DS
14403 else if (!nbr_output)
14404 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14405}
14406
14407static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14408 enum show_type type, const char *ip_str,
9f049418 14409 bool use_json)
d62a17ae 14410{
14411 int ret;
14412 struct bgp *bgp;
14413 union sockunion su;
14414 json_object *json = NULL;
14415
14416 if (name) {
14417 if (strmatch(name, "all")) {
71aedaa3
DS
14418 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14419 use_json);
d62a17ae 14420 return CMD_SUCCESS;
14421 } else {
14422 bgp = bgp_lookup_by_name(name);
14423 if (!bgp) {
14424 if (use_json) {
14425 json = json_object_new_object();
d62a17ae 14426 vty_out(vty, "%s\n",
14427 json_object_to_json_string_ext(
14428 json,
14429 JSON_C_TO_STRING_PRETTY));
14430 json_object_free(json);
14431 } else
14432 vty_out(vty,
9f049418 14433 "%% BGP instance not found\n");
d62a17ae 14434
14435 return CMD_WARNING;
14436 }
14437 }
14438 } else {
14439 bgp = bgp_get_default();
14440 }
14441
14442 if (bgp) {
14443 json = json_object_new_object();
14444 if (ip_str) {
14445 ret = str2sockunion(ip_str, &su);
14446 if (ret < 0)
14447 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14448 use_json, json);
14449 else
14450 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14451 use_json, json);
14452 } else {
14453 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14454 json);
14455 }
14456 json_object_free(json);
ca61fd25
DS
14457 } else {
14458 if (use_json)
14459 vty_out(vty, "{}\n");
14460 else
14461 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14462 }
14463
14464 return CMD_SUCCESS;
4fb25c53
DW
14465}
14466
2986cac2 14467
14468
14469/* "show [ip] bgp neighbors graceful-restart" commands. */
14470DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14471 show_ip_bgp_neighbors_graceful_restart_cmd,
14472 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14473 SHOW_STR
14474 BGP_STR
14475 IP_STR
14476 IPV6_STR
14477 NEIGHBOR_STR
14478 "Neighbor to display information about\n"
14479 "Neighbor to display information about\n"
14480 "Neighbor on BGP configured interface\n"
14481 GR_SHOW
14482 JSON_STR)
14483{
14484 char *sh_arg = NULL;
14485 enum show_type sh_type;
14486 int idx = 0;
14487 afi_t afi = AFI_MAX;
2986cac2 14488 bool uj = use_json(argc, argv);
14489
36235319 14490 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14491 afi = AFI_MAX;
14492
14493 idx++;
14494
14495 if (argv_find(argv, argc, "A.B.C.D", &idx)
14496 || argv_find(argv, argc, "X:X::X:X", &idx)
14497 || argv_find(argv, argc, "WORD", &idx)) {
14498 sh_type = show_peer;
14499 sh_arg = argv[idx]->arg;
14500 } else
14501 sh_type = show_all;
14502
14503 if (!argv_find(argv, argc, "graceful-restart", &idx))
14504 return CMD_SUCCESS;
14505
14506
36235319
QY
14507 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14508 afi, uj);
2986cac2 14509}
14510
716b2d8a 14511/* "show [ip] bgp neighbors" commands. */
718e3744 14512DEFUN (show_ip_bgp_neighbors,
14513 show_ip_bgp_neighbors_cmd,
24345e82 14514 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14515 SHOW_STR
14516 IP_STR
14517 BGP_STR
f2a8972b 14518 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14519 "Address Family\n"
14520 "Address Family\n"
718e3744 14521 "Detailed information on TCP and BGP neighbor connections\n"
14522 "Neighbor to display information about\n"
a80beece 14523 "Neighbor to display information about\n"
91d37724 14524 "Neighbor on BGP configured interface\n"
9973d184 14525 JSON_STR)
718e3744 14526{
d62a17ae 14527 char *vrf = NULL;
14528 char *sh_arg = NULL;
14529 enum show_type sh_type;
d1927ebe 14530 afi_t afi = AFI_MAX;
718e3744 14531
9f049418 14532 bool uj = use_json(argc, argv);
718e3744 14533
d62a17ae 14534 int idx = 0;
718e3744 14535
9a8bdf1c
PG
14536 /* [<vrf> VIEWVRFNAME] */
14537 if (argv_find(argv, argc, "vrf", &idx)) {
14538 vrf = argv[idx + 1]->arg;
14539 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14540 vrf = NULL;
14541 } else if (argv_find(argv, argc, "view", &idx))
14542 /* [<view> VIEWVRFNAME] */
d62a17ae 14543 vrf = argv[idx + 1]->arg;
718e3744 14544
d62a17ae 14545 idx++;
d1927ebe
AS
14546
14547 if (argv_find(argv, argc, "ipv4", &idx)) {
14548 sh_type = show_ipv4_all;
14549 afi = AFI_IP;
14550 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14551 sh_type = show_ipv6_all;
14552 afi = AFI_IP6;
14553 } else {
14554 sh_type = show_all;
14555 }
14556
d62a17ae 14557 if (argv_find(argv, argc, "A.B.C.D", &idx)
14558 || argv_find(argv, argc, "X:X::X:X", &idx)
14559 || argv_find(argv, argc, "WORD", &idx)) {
14560 sh_type = show_peer;
14561 sh_arg = argv[idx]->arg;
d1927ebe
AS
14562 }
14563
14564 if (sh_type == show_peer && afi == AFI_IP) {
14565 sh_type = show_ipv4_peer;
14566 } else if (sh_type == show_peer && afi == AFI_IP6) {
14567 sh_type = show_ipv6_peer;
14568 }
856ca177 14569
d62a17ae 14570 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14571}
14572
716b2d8a 14573/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14574 paths' and `show ip mbgp paths'. Those functions results are the
14575 same.*/
f412b39a 14576DEFUN (show_ip_bgp_paths,
718e3744 14577 show_ip_bgp_paths_cmd,
46f296b4 14578 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14579 SHOW_STR
14580 IP_STR
14581 BGP_STR
46f296b4 14582 BGP_SAFI_HELP_STR
718e3744 14583 "Path information\n")
14584{
d62a17ae 14585 vty_out(vty, "Address Refcnt Path\n");
14586 aspath_print_all_vty(vty);
14587 return CMD_SUCCESS;
718e3744 14588}
14589
718e3744 14590#include "hash.h"
14591
e3b78da8 14592static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14593 struct vty *vty)
718e3744 14594{
d62a17ae 14595 struct community *com;
718e3744 14596
e3b78da8 14597 com = (struct community *)bucket->data;
3f65c5b1 14598 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14599 community_str(com, false));
718e3744 14600}
14601
14602/* Show BGP's community internal data. */
f412b39a 14603DEFUN (show_ip_bgp_community_info,
718e3744 14604 show_ip_bgp_community_info_cmd,
bec37ba5 14605 "show [ip] bgp community-info",
718e3744 14606 SHOW_STR
14607 IP_STR
14608 BGP_STR
14609 "List all bgp community information\n")
14610{
d62a17ae 14611 vty_out(vty, "Address Refcnt Community\n");
718e3744 14612
d62a17ae 14613 hash_iterate(community_hash(),
e3b78da8 14614 (void (*)(struct hash_bucket *,
d62a17ae 14615 void *))community_show_all_iterator,
14616 vty);
718e3744 14617
d62a17ae 14618 return CMD_SUCCESS;
718e3744 14619}
14620
e3b78da8 14621static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14622 struct vty *vty)
57d187bc 14623{
d62a17ae 14624 struct lcommunity *lcom;
57d187bc 14625
e3b78da8 14626 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14627 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14628 lcommunity_str(lcom, false));
57d187bc
JS
14629}
14630
14631/* Show BGP's community internal data. */
14632DEFUN (show_ip_bgp_lcommunity_info,
14633 show_ip_bgp_lcommunity_info_cmd,
14634 "show ip bgp large-community-info",
14635 SHOW_STR
14636 IP_STR
14637 BGP_STR
14638 "List all bgp large-community information\n")
14639{
d62a17ae 14640 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14641
d62a17ae 14642 hash_iterate(lcommunity_hash(),
e3b78da8 14643 (void (*)(struct hash_bucket *,
d62a17ae 14644 void *))lcommunity_show_all_iterator,
14645 vty);
57d187bc 14646
d62a17ae 14647 return CMD_SUCCESS;
57d187bc 14648}
2986cac2 14649/* Graceful Restart */
14650
14651static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14652 struct bgp *bgp,
14653 bool use_json,
14654 json_object *json)
2986cac2 14655{
57d187bc
JS
14656
14657
2986cac2 14658 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14659
7318ae88 14660 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14661
14662 switch (bgp_global_gr_mode) {
14663
14664 case GLOBAL_HELPER:
13909c4f 14665 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14666 break;
14667
14668 case GLOBAL_GR:
13909c4f 14669 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14670 break;
14671
14672 case GLOBAL_DISABLE:
13909c4f 14673 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14674 break;
14675
14676 case GLOBAL_INVALID:
2986cac2 14677 vty_out(vty,
2ba1fe69 14678 "Global BGP GR Mode Invalid\n");
2986cac2 14679 break;
14680 }
14681 vty_out(vty, "\n");
14682}
14683
36235319
QY
14684static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14685 enum show_type type,
14686 const char *ip_str,
14687 afi_t afi, bool use_json)
2986cac2 14688{
14689 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14690 afi = AFI_IP;
14691
14692 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14693
36235319
QY
14694 bgp_show_neighbor_graceful_restart_vty(
14695 vty, type, ip_str, afi, use_json);
2986cac2 14696 afi++;
14697 }
14698 } else if (afi != AFI_MAX) {
36235319
QY
14699 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14700 use_json);
2986cac2 14701 } else {
14702 return CMD_ERR_INCOMPLETE;
14703 }
14704
14705 return CMD_SUCCESS;
14706}
14707/* Graceful Restart */
14708
f412b39a 14709DEFUN (show_ip_bgp_attr_info,
718e3744 14710 show_ip_bgp_attr_info_cmd,
bec37ba5 14711 "show [ip] bgp attribute-info",
718e3744 14712 SHOW_STR
14713 IP_STR
14714 BGP_STR
14715 "List all bgp attribute information\n")
14716{
d62a17ae 14717 attr_show_all(vty);
14718 return CMD_SUCCESS;
718e3744 14719}
6b0655a2 14720
03915806
CS
14721static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14722 afi_t afi, safi_t safi,
14723 bool use_json, json_object *json)
53089bec 14724{
14725 struct bgp *bgp;
14726 struct listnode *node;
14727 char *vname;
14728 char buf1[INET6_ADDRSTRLEN];
14729 char *ecom_str;
14730 vpn_policy_direction_t dir;
14731
03915806 14732 if (json) {
b46dfd20
DS
14733 json_object *json_import_vrfs = NULL;
14734 json_object *json_export_vrfs = NULL;
14735
b46dfd20
DS
14736 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14737
53089bec 14738 if (!bgp) {
b46dfd20
DS
14739 vty_out(vty, "%s\n",
14740 json_object_to_json_string_ext(
14741 json,
14742 JSON_C_TO_STRING_PRETTY));
14743 json_object_free(json);
14744
53089bec 14745 return CMD_WARNING;
14746 }
b46dfd20 14747
94d4c685
DS
14748 /* Provide context for the block */
14749 json_object_string_add(json, "vrf", name ? name : "default");
14750 json_object_string_add(json, "afiSafi",
5cb5f4d0 14751 get_afi_safi_str(afi, safi, true));
94d4c685 14752
b46dfd20
DS
14753 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14754 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14755 json_object_string_add(json, "importFromVrfs", "none");
14756 json_object_string_add(json, "importRts", "none");
14757 } else {
6ce24e52
DS
14758 json_import_vrfs = json_object_new_array();
14759
b46dfd20
DS
14760 for (ALL_LIST_ELEMENTS_RO(
14761 bgp->vpn_policy[afi].import_vrf,
14762 node, vname))
14763 json_object_array_add(json_import_vrfs,
14764 json_object_new_string(vname));
14765
b20875ea
CS
14766 json_object_object_add(json, "importFromVrfs",
14767 json_import_vrfs);
b46dfd20 14768 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14769 if (bgp->vpn_policy[afi].rtlist[dir]) {
14770 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14771 bgp->vpn_policy[afi].rtlist[dir],
14772 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14773 json_object_string_add(json, "importRts",
14774 ecom_str);
14775 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14776 } else
14777 json_object_string_add(json, "importRts",
14778 "none");
b46dfd20
DS
14779 }
14780
14781 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14782 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14783 json_object_string_add(json, "exportToVrfs", "none");
14784 json_object_string_add(json, "routeDistinguisher",
14785 "none");
14786 json_object_string_add(json, "exportRts", "none");
14787 } else {
6ce24e52
DS
14788 json_export_vrfs = json_object_new_array();
14789
b46dfd20
DS
14790 for (ALL_LIST_ELEMENTS_RO(
14791 bgp->vpn_policy[afi].export_vrf,
14792 node, vname))
14793 json_object_array_add(json_export_vrfs,
14794 json_object_new_string(vname));
14795 json_object_object_add(json, "exportToVrfs",
14796 json_export_vrfs);
14797 json_object_string_add(json, "routeDistinguisher",
14798 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14799 buf1, RD_ADDRSTRLEN));
14800
14801 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14802 if (bgp->vpn_policy[afi].rtlist[dir]) {
14803 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14804 bgp->vpn_policy[afi].rtlist[dir],
14805 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14806 json_object_string_add(json, "exportRts",
14807 ecom_str);
14808 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14809 } else
14810 json_object_string_add(json, "exportRts",
14811 "none");
b46dfd20
DS
14812 }
14813
03915806
CS
14814 if (use_json) {
14815 vty_out(vty, "%s\n",
14816 json_object_to_json_string_ext(json,
b46dfd20 14817 JSON_C_TO_STRING_PRETTY));
03915806
CS
14818 json_object_free(json);
14819 }
53089bec 14820 } else {
b46dfd20
DS
14821 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14822
53089bec 14823 if (!bgp) {
b46dfd20 14824 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14825 return CMD_WARNING;
14826 }
53089bec 14827
b46dfd20
DS
14828 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14829 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14830 vty_out(vty,
14831 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14832 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14833 else {
14834 vty_out(vty,
14835 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14836 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14837
14838 for (ALL_LIST_ELEMENTS_RO(
14839 bgp->vpn_policy[afi].import_vrf,
14840 node, vname))
14841 vty_out(vty, " %s\n", vname);
14842
14843 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14844 ecom_str = NULL;
14845 if (bgp->vpn_policy[afi].rtlist[dir]) {
14846 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14847 bgp->vpn_policy[afi].rtlist[dir],
14848 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14849 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14850
b20875ea
CS
14851 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14852 } else
14853 vty_out(vty, "Import RT(s):\n");
53089bec 14854 }
53089bec 14855
b46dfd20
DS
14856 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14857 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14858 vty_out(vty,
14859 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14860 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14861 else {
14862 vty_out(vty,
04c9077f 14863 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14864 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14865
14866 for (ALL_LIST_ELEMENTS_RO(
14867 bgp->vpn_policy[afi].export_vrf,
14868 node, vname))
14869 vty_out(vty, " %s\n", vname);
14870
14871 vty_out(vty, "RD: %s\n",
14872 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14873 buf1, RD_ADDRSTRLEN));
14874
14875 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14876 if (bgp->vpn_policy[afi].rtlist[dir]) {
14877 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14878 bgp->vpn_policy[afi].rtlist[dir],
14879 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14880 vty_out(vty, "Export RT: %s\n", ecom_str);
14881 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14882 } else
14883 vty_out(vty, "Import RT(s):\n");
53089bec 14884 }
53089bec 14885 }
14886
14887 return CMD_SUCCESS;
14888}
14889
03915806
CS
14890static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14891 safi_t safi, bool use_json)
14892{
14893 struct listnode *node, *nnode;
14894 struct bgp *bgp;
14895 char *vrf_name = NULL;
14896 json_object *json = NULL;
14897 json_object *json_vrf = NULL;
14898 json_object *json_vrfs = NULL;
14899
14900 if (use_json) {
14901 json = json_object_new_object();
14902 json_vrfs = json_object_new_object();
14903 }
14904
14905 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14906
14907 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14908 vrf_name = bgp->name;
14909
14910 if (use_json) {
14911 json_vrf = json_object_new_object();
14912 } else {
14913 vty_out(vty, "\nInstance %s:\n",
14914 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14915 ? VRF_DEFAULT_NAME : bgp->name);
14916 }
14917 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14918 if (use_json) {
14919 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14920 json_object_object_add(json_vrfs,
14921 VRF_DEFAULT_NAME, json_vrf);
14922 else
14923 json_object_object_add(json_vrfs, vrf_name,
14924 json_vrf);
14925 }
14926 }
14927
14928 if (use_json) {
14929 json_object_object_add(json, "vrfs", json_vrfs);
14930 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
14931 JSON_C_TO_STRING_PRETTY));
14932 json_object_free(json);
14933 }
14934
14935 return CMD_SUCCESS;
14936}
14937
53089bec 14938/* "show [ip] bgp route-leak" command. */
14939DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14940 show_ip_bgp_route_leak_cmd,
14941 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14942 SHOW_STR
14943 IP_STR
14944 BGP_STR
14945 BGP_INSTANCE_HELP_STR
14946 BGP_AFI_HELP_STR
14947 BGP_SAFI_HELP_STR
14948 "Route leaking information\n"
14949 JSON_STR)
53089bec 14950{
14951 char *vrf = NULL;
14952 afi_t afi = AFI_MAX;
14953 safi_t safi = SAFI_MAX;
14954
9f049418 14955 bool uj = use_json(argc, argv);
53089bec 14956 int idx = 0;
03915806 14957 json_object *json = NULL;
53089bec 14958
14959 /* show [ip] bgp */
14960 if (argv_find(argv, argc, "ip", &idx)) {
14961 afi = AFI_IP;
14962 safi = SAFI_UNICAST;
14963 }
14964 /* [vrf VIEWVRFNAME] */
14965 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14966 vty_out(vty,
14967 "%% This command is not applicable to BGP views\n");
53089bec 14968 return CMD_WARNING;
14969 }
14970
9a8bdf1c
PG
14971 if (argv_find(argv, argc, "vrf", &idx)) {
14972 vrf = argv[idx + 1]->arg;
14973 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14974 vrf = NULL;
14975 }
53089bec 14976 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14977 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14978 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14979 }
14980
14981 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14982 vty_out(vty,
14983 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14984 return CMD_WARNING;
14985 }
14986
03915806
CS
14987 if (vrf && strmatch(vrf, "all"))
14988 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14989
14990 if (uj)
14991 json = json_object_new_object();
14992
14993 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14994}
14995
d62a17ae 14996static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14997 safi_t safi)
f186de26 14998{
d62a17ae 14999 struct listnode *node, *nnode;
15000 struct bgp *bgp;
f186de26 15001
d62a17ae 15002 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15003 vty_out(vty, "\nInstance %s:\n",
15004 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15005 ? VRF_DEFAULT_NAME
d62a17ae 15006 : bgp->name);
15007 update_group_show(bgp, afi, safi, vty, 0);
15008 }
f186de26 15009}
15010
d62a17ae 15011static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15012 int safi, uint64_t subgrp_id)
4fb25c53 15013{
d62a17ae 15014 struct bgp *bgp;
4fb25c53 15015
d62a17ae 15016 if (name) {
15017 if (strmatch(name, "all")) {
15018 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15019 return CMD_SUCCESS;
15020 } else {
15021 bgp = bgp_lookup_by_name(name);
15022 }
15023 } else {
15024 bgp = bgp_get_default();
15025 }
4fb25c53 15026
d62a17ae 15027 if (bgp)
15028 update_group_show(bgp, afi, safi, vty, subgrp_id);
15029 return CMD_SUCCESS;
4fb25c53
DW
15030}
15031
8fe8a7f6
DS
15032DEFUN (show_ip_bgp_updgrps,
15033 show_ip_bgp_updgrps_cmd,
c1a44e43 15034 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15035 SHOW_STR
15036 IP_STR
15037 BGP_STR
15038 BGP_INSTANCE_HELP_STR
c9e571b4 15039 BGP_AFI_HELP_STR
9bedbb1e 15040 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15041 "Detailed info about dynamic update groups\n"
15042 "Specific subgroup to display detailed info for\n")
8386ac43 15043{
d62a17ae 15044 char *vrf = NULL;
15045 afi_t afi = AFI_IP6;
15046 safi_t safi = SAFI_UNICAST;
15047 uint64_t subgrp_id = 0;
15048
15049 int idx = 0;
15050
15051 /* show [ip] bgp */
15052 if (argv_find(argv, argc, "ip", &idx))
15053 afi = AFI_IP;
9a8bdf1c
PG
15054 /* [<vrf> VIEWVRFNAME] */
15055 if (argv_find(argv, argc, "vrf", &idx)) {
15056 vrf = argv[idx + 1]->arg;
15057 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15058 vrf = NULL;
15059 } else if (argv_find(argv, argc, "view", &idx))
15060 /* [<view> VIEWVRFNAME] */
15061 vrf = argv[idx + 1]->arg;
d62a17ae 15062 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15063 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15064 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15065 }
5bf15956 15066
d62a17ae 15067 /* get subgroup id, if provided */
15068 idx = argc - 1;
15069 if (argv[idx]->type == VARIABLE_TKN)
15070 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15071
d62a17ae 15072 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15073}
15074
f186de26 15075DEFUN (show_bgp_instance_all_ipv6_updgrps,
15076 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15077 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15078 SHOW_STR
716b2d8a 15079 IP_STR
f186de26 15080 BGP_STR
15081 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15082 "Detailed info about dynamic update groups\n")
f186de26 15083{
d62a17ae 15084 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15085 return CMD_SUCCESS;
f186de26 15086}
15087
43d3f4fc
DS
15088DEFUN (show_bgp_l2vpn_evpn_updgrps,
15089 show_bgp_l2vpn_evpn_updgrps_cmd,
15090 "show [ip] bgp l2vpn evpn update-groups",
15091 SHOW_STR
15092 IP_STR
15093 BGP_STR
15094 "l2vpn address family\n"
15095 "evpn sub-address family\n"
15096 "Detailed info about dynamic update groups\n")
15097{
15098 char *vrf = NULL;
15099 uint64_t subgrp_id = 0;
15100
15101 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15102 return CMD_SUCCESS;
15103}
15104
5bf15956
DW
15105DEFUN (show_bgp_updgrps_stats,
15106 show_bgp_updgrps_stats_cmd,
716b2d8a 15107 "show [ip] bgp update-groups statistics",
3f9c7369 15108 SHOW_STR
716b2d8a 15109 IP_STR
3f9c7369 15110 BGP_STR
0c7b1b01 15111 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15112 "Statistics\n")
15113{
d62a17ae 15114 struct bgp *bgp;
3f9c7369 15115
d62a17ae 15116 bgp = bgp_get_default();
15117 if (bgp)
15118 update_group_show_stats(bgp, vty);
3f9c7369 15119
d62a17ae 15120 return CMD_SUCCESS;
3f9c7369
DS
15121}
15122
8386ac43 15123DEFUN (show_bgp_instance_updgrps_stats,
15124 show_bgp_instance_updgrps_stats_cmd,
18c57037 15125 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15126 SHOW_STR
716b2d8a 15127 IP_STR
8386ac43 15128 BGP_STR
15129 BGP_INSTANCE_HELP_STR
0c7b1b01 15130 "Detailed info about dynamic update groups\n"
8386ac43 15131 "Statistics\n")
15132{
d62a17ae 15133 int idx_word = 3;
15134 struct bgp *bgp;
8386ac43 15135
d62a17ae 15136 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15137 if (bgp)
15138 update_group_show_stats(bgp, vty);
8386ac43 15139
d62a17ae 15140 return CMD_SUCCESS;
8386ac43 15141}
15142
d62a17ae 15143static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15144 afi_t afi, safi_t safi,
15145 const char *what, uint64_t subgrp_id)
3f9c7369 15146{
d62a17ae 15147 struct bgp *bgp;
8386ac43 15148
d62a17ae 15149 if (name)
15150 bgp = bgp_lookup_by_name(name);
15151 else
15152 bgp = bgp_get_default();
8386ac43 15153
d62a17ae 15154 if (bgp) {
15155 if (!strcmp(what, "advertise-queue"))
15156 update_group_show_adj_queue(bgp, afi, safi, vty,
15157 subgrp_id);
15158 else if (!strcmp(what, "advertised-routes"))
15159 update_group_show_advertised(bgp, afi, safi, vty,
15160 subgrp_id);
15161 else if (!strcmp(what, "packet-queue"))
15162 update_group_show_packet_queue(bgp, afi, safi, vty,
15163 subgrp_id);
15164 }
3f9c7369
DS
15165}
15166
dc64bdec
QY
15167DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15168 show_ip_bgp_instance_updgrps_adj_s_cmd,
15169 "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",
15170 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15171 BGP_SAFI_HELP_STR
15172 "Detailed info about dynamic update groups\n"
15173 "Specific subgroup to display info for\n"
15174 "Advertisement queue\n"
15175 "Announced routes\n"
15176 "Packet queue\n")
3f9c7369 15177{
dc64bdec
QY
15178 uint64_t subgrp_id = 0;
15179 afi_t afiz;
15180 safi_t safiz;
15181 if (sgid)
15182 subgrp_id = strtoull(sgid, NULL, 10);
15183
15184 if (!ip && !afi)
15185 afiz = AFI_IP6;
15186 if (!ip && afi)
15187 afiz = bgp_vty_afi_from_str(afi);
15188 if (ip && !afi)
15189 afiz = AFI_IP;
15190 if (ip && afi) {
15191 afiz = bgp_vty_afi_from_str(afi);
15192 if (afiz != AFI_IP)
15193 vty_out(vty,
15194 "%% Cannot specify both 'ip' and 'ipv6'\n");
15195 return CMD_WARNING;
15196 }
d62a17ae 15197
dc64bdec 15198 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15199
dc64bdec 15200 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15201 return CMD_SUCCESS;
15202}
15203
d62a17ae 15204static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15205{
15206 struct listnode *node, *nnode;
15207 struct prefix *range;
15208 struct peer *conf;
15209 struct peer *peer;
d62a17ae 15210 afi_t afi;
15211 safi_t safi;
15212 const char *peer_status;
15213 const char *af_str;
15214 int lr_count;
15215 int dynamic;
15216 int af_cfgd;
15217
15218 conf = group->conf;
15219
15220 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 15221 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 15222 group->name, conf->as);
d62a17ae 15223 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 15224 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 15225 group->name, group->bgp->as);
d62a17ae 15226 } else {
15227 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15228 }
f14e6fdb 15229
d62a17ae 15230 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15231 vty_out(vty, " Peer-group type is internal\n");
15232 else
15233 vty_out(vty, " Peer-group type is external\n");
15234
15235 /* Display AFs configured. */
15236 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
15237 FOREACH_AFI_SAFI (afi, safi) {
15238 if (conf->afc[afi][safi]) {
15239 af_cfgd = 1;
5cb5f4d0 15240 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 15241 }
05c7a1cc 15242 }
d62a17ae 15243 if (!af_cfgd)
15244 vty_out(vty, " none\n");
15245 else
15246 vty_out(vty, "\n");
15247
15248 /* Display listen ranges (for dynamic neighbors), if any */
15249 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15250 if (afi == AFI_IP)
15251 af_str = "IPv4";
15252 else if (afi == AFI_IP6)
15253 af_str = "IPv6";
15254 else
15255 af_str = "???";
15256 lr_count = listcount(group->listen_range[afi]);
15257 if (lr_count) {
15258 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15259 af_str);
15260
15261
15262 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
2dbe669b
DA
15263 nnode, range))
15264 vty_out(vty, " %pFX\n", range);
d62a17ae 15265 }
15266 }
f14e6fdb 15267
d62a17ae 15268 /* Display group members and their status */
15269 if (listcount(group->peer)) {
15270 vty_out(vty, " Peer-group members:\n");
15271 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15272 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15273 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15274 peer_status = "Idle (Admin)";
15275 else if (CHECK_FLAG(peer->sflags,
15276 PEER_STATUS_PREFIX_OVERFLOW))
15277 peer_status = "Idle (PfxCt)";
15278 else
15279 peer_status = lookup_msg(bgp_status_msg,
15280 peer->status, NULL);
15281
15282 dynamic = peer_dynamic_neighbor(peer);
15283 vty_out(vty, " %s %s %s \n", peer->host,
15284 dynamic ? "(dynamic)" : "", peer_status);
15285 }
15286 }
f14e6fdb 15287
d62a17ae 15288 return CMD_SUCCESS;
15289}
15290
ff9959b0
QY
15291static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15292 const char *group_name)
d62a17ae 15293{
ff9959b0 15294 struct bgp *bgp;
d62a17ae 15295 struct listnode *node, *nnode;
15296 struct peer_group *group;
ff9959b0
QY
15297 bool found = false;
15298
15299 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15300
15301 if (!bgp) {
9f049418 15302 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
15303 return CMD_WARNING;
15304 }
d62a17ae 15305
15306 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15307 if (group_name) {
15308 if (strmatch(group->name, group_name)) {
d62a17ae 15309 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
15310 found = true;
15311 break;
d62a17ae 15312 }
ff9959b0
QY
15313 } else {
15314 bgp_show_one_peer_group(vty, group);
d62a17ae 15315 }
f14e6fdb 15316 }
f14e6fdb 15317
ff9959b0 15318 if (group_name && !found)
d62a17ae 15319 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15320
d62a17ae 15321 return CMD_SUCCESS;
f14e6fdb
DS
15322}
15323
f14e6fdb
DS
15324DEFUN (show_ip_bgp_peer_groups,
15325 show_ip_bgp_peer_groups_cmd,
18c57037 15326 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
15327 SHOW_STR
15328 IP_STR
15329 BGP_STR
8386ac43 15330 BGP_INSTANCE_HELP_STR
d6e3c605
QY
15331 "Detailed information on BGP peer groups\n"
15332 "Peer group name\n")
f14e6fdb 15333{
d62a17ae 15334 char *vrf, *pg;
d62a17ae 15335 int idx = 0;
f14e6fdb 15336
a4d82a8a
PZ
15337 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15338 : NULL;
d62a17ae 15339 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15340
ff9959b0 15341 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 15342}
3f9c7369 15343
d6e3c605 15344
718e3744 15345/* Redistribute VTY commands. */
15346
37a87b8f
CS
15347DEFUN_YANG (bgp_redistribute_ipv4,
15348 bgp_redistribute_ipv4_cmd,
15349 "redistribute " FRR_IP_REDIST_STR_BGPD,
15350 "Redistribute information from another routing protocol\n"
15351 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15352{
d62a17ae 15353 int idx_protocol = 1;
37a87b8f 15354 char base_xpath[XPATH_MAXLEN];
718e3744 15355
37a87b8f
CS
15356 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15357 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15358 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15359 argv[idx_protocol]->text, "0");
15360
15361 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 15362
37a87b8f 15363 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15364}
15365
d62a17ae 15366ALIAS_HIDDEN(
15367 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15368 "redistribute " FRR_IP_REDIST_STR_BGPD,
15369 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15370
37a87b8f
CS
15371DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15372 bgp_redistribute_ipv4_rmap_cmd,
15373 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15374 "Redistribute information from another routing protocol\n"
15375 FRR_IP_REDIST_HELP_STR_BGPD
15376 "Route map reference\n"
15377 "Pointer to route-map entries\n")
718e3744 15378{
d62a17ae 15379 int idx_protocol = 1;
15380 int idx_word = 3;
37a87b8f
CS
15381 char base_xpath[XPATH_MAXLEN];
15382
15383 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15384 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15385 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15386 argv[idx_protocol]->text, "0");
718e3744 15387
37a87b8f
CS
15388 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15389 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15390 argv[idx_word]->arg);
15391
15392 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15393}
15394
d62a17ae 15395ALIAS_HIDDEN(
15396 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15397 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15398 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15399 "Route map reference\n"
15400 "Pointer to route-map entries\n")
596c17ba 15401
37a87b8f
CS
15402DEFUN_YANG (bgp_redistribute_ipv4_metric,
15403 bgp_redistribute_ipv4_metric_cmd,
15404 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15405 "Redistribute information from another routing protocol\n"
15406 FRR_IP_REDIST_HELP_STR_BGPD
15407 "Metric for redistributed routes\n"
15408 "Default metric\n")
718e3744 15409{
d62a17ae 15410 int idx_protocol = 1;
15411 int idx_number = 3;
37a87b8f
CS
15412 char base_xpath[XPATH_MAXLEN];
15413
15414 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15415 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15416 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15417 argv[idx_protocol]->text, "0");
d62a17ae 15418
37a87b8f
CS
15419 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15420 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15421 argv[idx_number]->arg);
15422
15423 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15424}
15425
15426ALIAS_HIDDEN(
15427 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15428 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15429 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15430 "Metric for redistributed routes\n"
15431 "Default metric\n")
596c17ba 15432
37a87b8f
CS
15433DEFUN_YANG(
15434 bgp_redistribute_ipv4_rmap_metric,
15435 bgp_redistribute_ipv4_rmap_metric_cmd,
15436 "redistribute " FRR_IP_REDIST_STR_BGPD
15437 " route-map WORD metric (0-4294967295)",
15438 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15439 "Route map reference\n"
15440 "Pointer to route-map entries\n"
15441 "Metric for redistributed routes\n"
15442 "Default metric\n")
718e3744 15443{
d62a17ae 15444 int idx_protocol = 1;
15445 int idx_word = 3;
15446 int idx_number = 5;
37a87b8f
CS
15447 char base_xpath[XPATH_MAXLEN];
15448
15449 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15450 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15451 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15452 argv[idx_protocol]->text, "0");
15453
15454 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15455 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15456 argv[idx_word]->arg);
15457 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15458 argv[idx_number]->arg);
d62a17ae 15459
37a87b8f 15460 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15461}
15462
15463ALIAS_HIDDEN(
15464 bgp_redistribute_ipv4_rmap_metric,
15465 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15466 "redistribute " FRR_IP_REDIST_STR_BGPD
15467 " route-map WORD metric (0-4294967295)",
15468 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15469 "Route map reference\n"
15470 "Pointer to route-map entries\n"
15471 "Metric for redistributed routes\n"
15472 "Default metric\n")
596c17ba 15473
37a87b8f
CS
15474DEFUN_YANG(
15475 bgp_redistribute_ipv4_metric_rmap,
15476 bgp_redistribute_ipv4_metric_rmap_cmd,
15477 "redistribute " FRR_IP_REDIST_STR_BGPD
15478 " metric (0-4294967295) route-map WORD",
15479 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15480 "Metric for redistributed routes\n"
15481 "Default metric\n"
15482 "Route map reference\n"
15483 "Pointer to route-map entries\n")
718e3744 15484{
d62a17ae 15485 int idx_protocol = 1;
d62a17ae 15486 int idx_word = 5;
37a87b8f
CS
15487 int idx_number = 3;
15488 char base_xpath[XPATH_MAXLEN];
15489
15490 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15491 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15492 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15493 argv[idx_protocol]->text, "0");
15494
15495 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15496 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15497 argv[idx_number]->arg);
15498 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15499 argv[idx_word]->arg);
d62a17ae 15500
37a87b8f 15501 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15502}
15503
15504ALIAS_HIDDEN(
15505 bgp_redistribute_ipv4_metric_rmap,
15506 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15507 "redistribute " FRR_IP_REDIST_STR_BGPD
15508 " metric (0-4294967295) route-map WORD",
15509 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15510 "Metric for redistributed routes\n"
15511 "Default metric\n"
15512 "Route map reference\n"
15513 "Pointer to route-map entries\n")
596c17ba 15514
37a87b8f
CS
15515DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15516 bgp_redistribute_ipv4_ospf_cmd,
15517 "redistribute <ospf|table> (1-65535)",
15518 "Redistribute information from another routing protocol\n"
15519 "Open Shortest Path First (OSPFv2)\n"
15520 "Non-main Kernel Routing Table\n"
15521 "Instance ID/Table ID\n")
7c8ff89e 15522{
37a87b8f 15523 int idx_protocol = 1;
d62a17ae 15524 int idx_number = 2;
37a87b8f 15525 char base_xpath[XPATH_MAXLEN];
7c8ff89e 15526
37a87b8f
CS
15527 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15528 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15529 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15530 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 15531
37a87b8f 15532 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 15533
37a87b8f 15534 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
15535}
15536
d62a17ae 15537ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15538 "redistribute <ospf|table> (1-65535)",
15539 "Redistribute information from another routing protocol\n"
15540 "Open Shortest Path First (OSPFv2)\n"
15541 "Non-main Kernel Routing Table\n"
15542 "Instance ID/Table ID\n")
596c17ba 15543
37a87b8f
CS
15544DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15545 bgp_redistribute_ipv4_ospf_rmap_cmd,
15546 "redistribute <ospf|table> (1-65535) route-map WORD",
15547 "Redistribute information from another routing protocol\n"
15548 "Open Shortest Path First (OSPFv2)\n"
15549 "Non-main Kernel Routing Table\n"
15550 "Instance ID/Table ID\n"
15551 "Route map reference\n"
15552 "Pointer to route-map entries\n")
7c8ff89e 15553{
37a87b8f 15554 int idx_protocol = 1;
d62a17ae 15555 int idx_number = 2;
15556 int idx_word = 4;
37a87b8f
CS
15557 char base_xpath[XPATH_MAXLEN];
15558
15559 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15560 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15561 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15562 argv[idx_protocol]->text, argv[idx_number]->arg);
15563
15564 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15565
15566 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15567 argv[idx_word]->arg);
d62a17ae 15568
37a87b8f 15569 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15570}
15571
15572ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15573 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15574 "redistribute <ospf|table> (1-65535) route-map WORD",
15575 "Redistribute information from another routing protocol\n"
15576 "Open Shortest Path First (OSPFv2)\n"
15577 "Non-main Kernel Routing Table\n"
15578 "Instance ID/Table ID\n"
15579 "Route map reference\n"
15580 "Pointer to route-map entries\n")
596c17ba 15581
37a87b8f
CS
15582DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15583 bgp_redistribute_ipv4_ospf_metric_cmd,
15584 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15585 "Redistribute information from another routing protocol\n"
15586 "Open Shortest Path First (OSPFv2)\n"
15587 "Non-main Kernel Routing Table\n"
15588 "Instance ID/Table ID\n"
15589 "Metric for redistributed routes\n"
15590 "Default metric\n")
7c8ff89e 15591{
37a87b8f 15592 int idx_protocol = 1;
d62a17ae 15593 int idx_number = 2;
15594 int idx_number_2 = 4;
37a87b8f
CS
15595 char base_xpath[XPATH_MAXLEN];
15596
15597 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15598 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15599 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15600 argv[idx_protocol]->text, argv[idx_number]->arg);
15601
15602 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15603
37a87b8f
CS
15604 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15605 argv[idx_number_2]->arg);
d62a17ae 15606
37a87b8f 15607 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15608}
15609
15610ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15611 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15612 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15613 "Redistribute information from another routing protocol\n"
15614 "Open Shortest Path First (OSPFv2)\n"
15615 "Non-main Kernel Routing Table\n"
15616 "Instance ID/Table ID\n"
15617 "Metric for redistributed routes\n"
15618 "Default metric\n")
596c17ba 15619
37a87b8f
CS
15620DEFUN_YANG(
15621 bgp_redistribute_ipv4_ospf_rmap_metric,
15622 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15623 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15624 "Redistribute information from another routing protocol\n"
15625 "Open Shortest Path First (OSPFv2)\n"
15626 "Non-main Kernel Routing Table\n"
15627 "Instance ID/Table ID\n"
15628 "Route map reference\n"
15629 "Pointer to route-map entries\n"
15630 "Metric for redistributed routes\n"
15631 "Default metric\n")
7c8ff89e 15632{
37a87b8f 15633 int idx_protocol = 1;
d62a17ae 15634 int idx_number = 2;
15635 int idx_word = 4;
15636 int idx_number_2 = 6;
37a87b8f
CS
15637 char base_xpath[XPATH_MAXLEN];
15638
15639 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15640 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15641 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15642 argv[idx_protocol]->text, argv[idx_number]->arg);
15643
15644 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15645
37a87b8f
CS
15646 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15647 argv[idx_word]->arg);
15648 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15649 argv[idx_number_2]->arg);
d62a17ae 15650
37a87b8f 15651 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15652}
15653
15654ALIAS_HIDDEN(
15655 bgp_redistribute_ipv4_ospf_rmap_metric,
15656 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15657 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15658 "Redistribute information from another routing protocol\n"
15659 "Open Shortest Path First (OSPFv2)\n"
15660 "Non-main Kernel Routing Table\n"
15661 "Instance ID/Table ID\n"
15662 "Route map reference\n"
15663 "Pointer to route-map entries\n"
15664 "Metric for redistributed routes\n"
15665 "Default metric\n")
596c17ba 15666
37a87b8f
CS
15667DEFUN_YANG(
15668 bgp_redistribute_ipv4_ospf_metric_rmap,
15669 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15670 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15671 "Redistribute information from another routing protocol\n"
15672 "Open Shortest Path First (OSPFv2)\n"
15673 "Non-main Kernel Routing Table\n"
15674 "Instance ID/Table ID\n"
15675 "Metric for redistributed routes\n"
15676 "Default metric\n"
15677 "Route map reference\n"
15678 "Pointer to route-map entries\n")
7c8ff89e 15679{
37a87b8f 15680 int idx_protocol = 1;
d62a17ae 15681 int idx_number = 2;
15682 int idx_number_2 = 4;
15683 int idx_word = 6;
37a87b8f
CS
15684 char base_xpath[XPATH_MAXLEN];
15685
15686 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15687 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15688 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15689 argv[idx_protocol]->text, argv[idx_number]->arg);
15690
15691 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15692
37a87b8f
CS
15693 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15694 argv[idx_number_2]->arg);
15695 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15696 argv[idx_word]->arg);
d62a17ae 15697
37a87b8f 15698 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15699}
15700
15701ALIAS_HIDDEN(
15702 bgp_redistribute_ipv4_ospf_metric_rmap,
15703 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15704 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15705 "Redistribute information from another routing protocol\n"
15706 "Open Shortest Path First (OSPFv2)\n"
15707 "Non-main Kernel Routing Table\n"
15708 "Instance ID/Table ID\n"
15709 "Metric for redistributed routes\n"
15710 "Default metric\n"
15711 "Route map reference\n"
15712 "Pointer to route-map entries\n")
596c17ba 15713
37a87b8f
CS
15714DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15715 no_bgp_redistribute_ipv4_ospf_cmd,
15716 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15717 NO_STR
15718 "Redistribute information from another routing protocol\n"
15719 "Open Shortest Path First (OSPFv2)\n"
15720 "Non-main Kernel Routing Table\n"
15721 "Instance ID/Table ID\n"
15722 "Metric for redistributed routes\n"
15723 "Default metric\n"
15724 "Route map reference\n"
15725 "Pointer to route-map entries\n")
7c8ff89e 15726{
37a87b8f 15727 int idx_protocol = 2;
d62a17ae 15728 int idx_number = 3;
37a87b8f 15729 char base_xpath[XPATH_MAXLEN];
d62a17ae 15730
37a87b8f
CS
15731 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15732 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15733 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15734 argv[idx_protocol]->text, argv[idx_number]->arg);
15735
15736 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 15737
37a87b8f 15738 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15739}
15740
15741ALIAS_HIDDEN(
15742 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15743 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15744 NO_STR
15745 "Redistribute information from another routing protocol\n"
15746 "Open Shortest Path First (OSPFv2)\n"
15747 "Non-main Kernel Routing Table\n"
15748 "Instance ID/Table ID\n"
15749 "Metric for redistributed routes\n"
15750 "Default metric\n"
15751 "Route map reference\n"
15752 "Pointer to route-map entries\n")
596c17ba 15753
37a87b8f
CS
15754DEFUN_YANG (no_bgp_redistribute_ipv4,
15755 no_bgp_redistribute_ipv4_cmd,
15756 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15757 NO_STR
15758 "Redistribute information from another routing protocol\n"
15759 FRR_IP_REDIST_HELP_STR_BGPD
15760 "Metric for redistributed routes\n"
15761 "Default metric\n"
15762 "Route map reference\n"
15763 "Pointer to route-map entries\n")
718e3744 15764{
d62a17ae 15765 int idx_protocol = 2;
37a87b8f 15766 char base_xpath[XPATH_MAXLEN];
d62a17ae 15767
37a87b8f
CS
15768 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15769 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15770 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15771 argv[idx_protocol]->text, "0");
15772
15773 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15774
15775 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15776}
15777
15778ALIAS_HIDDEN(
15779 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15780 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15781 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15782 NO_STR
15783 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15784 "Metric for redistributed routes\n"
15785 "Default metric\n"
15786 "Route map reference\n"
15787 "Pointer to route-map entries\n")
596c17ba 15788
37a87b8f
CS
15789DEFUN_YANG (bgp_redistribute_ipv6,
15790 bgp_redistribute_ipv6_cmd,
15791 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15792 "Redistribute information from another routing protocol\n"
15793 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15794{
d62a17ae 15795 int idx_protocol = 1;
37a87b8f 15796 char base_xpath[XPATH_MAXLEN];
718e3744 15797
37a87b8f
CS
15798 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15799 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15800 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15801 argv[idx_protocol]->text, "0");
15802
15803 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 15804
37a87b8f 15805 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15806}
15807
37a87b8f
CS
15808DEFUN_YANG (bgp_redistribute_ipv6_rmap,
15809 bgp_redistribute_ipv6_rmap_cmd,
15810 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15811 "Redistribute information from another routing protocol\n"
15812 FRR_IP6_REDIST_HELP_STR_BGPD
15813 "Route map reference\n"
15814 "Pointer to route-map entries\n")
718e3744 15815{
d62a17ae 15816 int idx_protocol = 1;
15817 int idx_word = 3;
37a87b8f
CS
15818 char base_xpath[XPATH_MAXLEN];
15819
15820 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15821 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15822 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15823 argv[idx_protocol]->text, "0");
718e3744 15824
37a87b8f
CS
15825 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15826 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15827 argv[idx_word]->arg);
15828
15829 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15830}
15831
37a87b8f 15832DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 15833 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15834 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15835 "Redistribute information from another routing protocol\n"
ab0181ee 15836 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15837 "Metric for redistributed routes\n"
15838 "Default metric\n")
15839{
d62a17ae 15840 int idx_protocol = 1;
15841 int idx_number = 3;
37a87b8f
CS
15842 char base_xpath[XPATH_MAXLEN];
15843
15844 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15845 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15846 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15847 argv[idx_protocol]->text, "0");
718e3744 15848
37a87b8f
CS
15849 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15850 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15851 argv[idx_number]->arg);
15852
15853 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15854}
15855
37a87b8f
CS
15856DEFUN_YANG(
15857 bgp_redistribute_ipv6_rmap_metric,
15858 bgp_redistribute_ipv6_rmap_metric_cmd,
15859 "redistribute " FRR_IP6_REDIST_STR_BGPD
15860 " route-map WORD metric (0-4294967295)",
15861 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15862 "Route map reference\n"
15863 "Pointer to route-map entries\n"
15864 "Metric for redistributed routes\n"
15865 "Default metric\n")
718e3744 15866{
d62a17ae 15867 int idx_protocol = 1;
15868 int idx_word = 3;
15869 int idx_number = 5;
37a87b8f
CS
15870 char base_xpath[XPATH_MAXLEN];
15871
15872 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15873 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15874 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15875 argv[idx_protocol]->text, "0");
718e3744 15876
37a87b8f
CS
15877 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15878 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15879 argv[idx_word]->arg);
15880 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15881 argv[idx_number]->arg);
15882
15883 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15884}
15885
37a87b8f
CS
15886DEFUN_YANG(
15887 bgp_redistribute_ipv6_metric_rmap,
15888 bgp_redistribute_ipv6_metric_rmap_cmd,
15889 "redistribute " FRR_IP6_REDIST_STR_BGPD
15890 " metric (0-4294967295) route-map WORD",
15891 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15892 "Metric for redistributed routes\n"
15893 "Default metric\n"
15894 "Route map reference\n"
15895 "Pointer to route-map entries\n")
718e3744 15896{
d62a17ae 15897 int idx_protocol = 1;
d62a17ae 15898 int idx_word = 5;
37a87b8f
CS
15899 int idx_number = 3;
15900 char base_xpath[XPATH_MAXLEN];
15901
15902 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15903 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15904 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15905 argv[idx_protocol]->text, "0");
718e3744 15906
37a87b8f
CS
15907 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15908 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15909 argv[idx_number]->arg);
15910 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15911 argv[idx_word]->arg);
15912
15913 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15914}
15915
37a87b8f
CS
15916DEFUN_YANG(
15917 no_bgp_redistribute_ipv6,
15918 no_bgp_redistribute_ipv6_cmd,
15919 "no redistribute " FRR_IP6_REDIST_STR_BGPD
15920 " [{metric (0-4294967295)|route-map WORD}]",
15921 NO_STR
15922 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15923 "Metric for redistributed routes\n"
15924 "Default metric\n"
15925 "Route map reference\n"
15926 "Pointer to route-map entries\n")
718e3744 15927{
d62a17ae 15928 int idx_protocol = 2;
37a87b8f 15929 char base_xpath[XPATH_MAXLEN];
718e3744 15930
37a87b8f
CS
15931 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15932 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15933 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15934 argv[idx_protocol]->text, "0");
15935
15936 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15937
15938 return nb_cli_apply_changes(vty, base_xpath);
15939}
718e3744 15940
37a87b8f
CS
15941void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
15942 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
15943{
15944 uint32_t instance = 0;
15945
15946 vty_out(vty, " redistribute %s",
15947 yang_dnode_get_string(dnode, "./route-type"));
15948 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
15949 vty_out(vty, " %d", instance);
15950 if (yang_dnode_exists(dnode, "./metric"))
15951 vty_out(vty, " metric %u",
15952 yang_dnode_get_uint32(dnode, "./metric"));
15953 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
15954 vty_out(vty, " route-map %s",
15955 yang_dnode_get_string(dnode, "./rmap-policy-import"));
15956 vty_out(vty, "\n");
d62a17ae 15957}
15958
dd65f45e
DL
15959static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15960 afi_t afi, safi_t safi)
d62a17ae 15961{
15962 int i;
15963
15964 /* Unicast redistribution only. */
15965 if (safi != SAFI_UNICAST)
2b791107 15966 return;
d62a17ae 15967
15968 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
15969 /* Redistribute BGP does not make sense. */
15970 if (i != ZEBRA_ROUTE_BGP) {
15971 struct list *red_list;
15972 struct listnode *node;
15973 struct bgp_redist *red;
15974
15975 red_list = bgp->redist[afi][i];
15976 if (!red_list)
15977 continue;
15978
15979 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 15980 /* "redistribute" configuration. */
15981 vty_out(vty, " redistribute %s",
15982 zebra_route_string(i));
15983 if (red->instance)
15984 vty_out(vty, " %d", red->instance);
15985 if (red->redist_metric_flag)
15986 vty_out(vty, " metric %u",
15987 red->redist_metric);
15988 if (red->rmap.name)
15989 vty_out(vty, " route-map %s",
15990 red->rmap.name);
15991 vty_out(vty, "\n");
15992 }
15993 }
15994 }
718e3744 15995}
6b0655a2 15996
dd65f45e
DL
15997/* peer-group helpers for config-write */
15998
15999static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16000{
16001 if (!peer_group_active(peer)) {
16002 if (CHECK_FLAG(peer->flags_invert, flag))
16003 return !CHECK_FLAG(peer->flags, flag);
16004 else
16005 return !!CHECK_FLAG(peer->flags, flag);
16006 }
16007
16008 return !!CHECK_FLAG(peer->flags_override, flag);
16009}
16010
16011static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16012 uint32_t flag)
16013{
16014 if (!peer_group_active(peer)) {
16015 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16016 return !peer_af_flag_check(peer, afi, safi, flag);
16017 else
16018 return !!peer_af_flag_check(peer, afi, safi, flag);
16019 }
16020
16021 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16022}
16023
16024static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16025 uint8_t type, int direct)
16026{
16027 struct bgp_filter *filter;
16028
16029 if (peer_group_active(peer))
16030 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16031 type);
16032
16033 filter = &peer->filter[afi][safi];
16034 switch (type) {
16035 case PEER_FT_DISTRIBUTE_LIST:
16036 return !!(filter->dlist[direct].name);
16037 case PEER_FT_FILTER_LIST:
16038 return !!(filter->aslist[direct].name);
16039 case PEER_FT_PREFIX_LIST:
16040 return !!(filter->plist[direct].name);
16041 case PEER_FT_ROUTE_MAP:
16042 return !!(filter->map[direct].name);
16043 case PEER_FT_UNSUPPRESS_MAP:
16044 return !!(filter->usmap.name);
7f7940e6
MK
16045 case PEER_FT_ADVERTISE_MAP:
16046 return !!(filter->advmap.aname
16047 && ((filter->advmap.condition == direct)
16048 && filter->advmap.cname));
dd65f45e
DL
16049 default:
16050 return false;
16051 }
16052}
16053
16054/* Return true if the addpath type is set for peer and different from
16055 * peer-group.
16056 */
3dc339cd
DA
16057static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16058 safi_t safi)
dd65f45e
DL
16059{
16060 enum bgp_addpath_strat type, g_type;
16061
16062 type = peer->addpath_type[afi][safi];
16063
16064 if (type != BGP_ADDPATH_NONE) {
16065 if (peer_group_active(peer)) {
16066 g_type = peer->group->conf->addpath_type[afi][safi];
16067
16068 if (type != g_type)
3dc339cd 16069 return true;
dd65f45e 16070 else
3dc339cd 16071 return false;
dd65f45e
DL
16072 }
16073
3dc339cd 16074 return true;
dd65f45e
DL
16075 }
16076
3dc339cd 16077 return false;
dd65f45e
DL
16078}
16079
b9c7bc5a 16080/* This is part of the address-family block (unicast only) */
dd65f45e 16081static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16082 afi_t afi)
16083{
b9c7bc5a 16084 int indent = 2;
ddb5b488 16085
8a066a70 16086 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16087 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16088 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16089 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16090 bgp->vpn_policy[afi]
bb4f6190 16091 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16092 else
16093 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16094 bgp->vpn_policy[afi]
16095 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16096 }
12a844a5
DS
16097 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16098 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16099 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16100 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16101 return;
16102
e70e9f8e
PZ
16103 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16104 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16105
16106 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16107
16108 } else {
16109 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16110 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16111 bgp->vpn_policy[afi].tovpn_label);
16112 }
ddb5b488
PZ
16113 }
16114 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16115 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16116 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16117 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16118 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16119 sizeof(buf)));
16120 }
16121 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16122 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16123
16124 char buf[PREFIX_STRLEN];
16125 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16126 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16127 sizeof(buf))) {
16128
b9c7bc5a
PZ
16129 vty_out(vty, "%*snexthop vpn export %s\n",
16130 indent, "", buf);
ddb5b488
PZ
16131 }
16132 }
16133 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16134 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16135 && ecommunity_cmp(
16136 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16137 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16138
16139 char *b = ecommunity_ecom2str(
16140 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16141 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16142 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16143 XFREE(MTYPE_ECOMMUNITY_STR, b);
16144 } else {
16145 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16146 char *b = ecommunity_ecom2str(
16147 bgp->vpn_policy[afi]
16148 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16149 ECOMMUNITY_FORMAT_ROUTE_MAP,
16150 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16151 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16152 XFREE(MTYPE_ECOMMUNITY_STR, b);
16153 }
16154 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16155 char *b = ecommunity_ecom2str(
16156 bgp->vpn_policy[afi]
16157 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16158 ECOMMUNITY_FORMAT_ROUTE_MAP,
16159 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16160 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16161 XFREE(MTYPE_ECOMMUNITY_STR, b);
16162 }
16163 }
bb4f6190
DS
16164
16165 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16166 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16167 bgp->vpn_policy[afi]
16168 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16169
301ad80a
PG
16170 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16171 char *b = ecommunity_ecom2str(
16172 bgp->vpn_policy[afi]
16173 .import_redirect_rtlist,
16174 ECOMMUNITY_FORMAT_ROUTE_MAP,
16175 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16176
9a659715
PG
16177 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16178 != ECOMMUNITY_SIZE)
c6423c31 16179 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16180 indent, "", b);
16181 else
16182 vty_out(vty, "%*srt redirect import %s\n",
16183 indent, "", b);
301ad80a
PG
16184 XFREE(MTYPE_ECOMMUNITY_STR, b);
16185 }
ddb5b488
PZ
16186}
16187
dd65f45e
DL
16188static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16189 afi_t afi, safi_t safi)
16190{
16191 struct bgp_filter *filter;
16192 char *addr;
16193
16194 addr = peer->host;
16195 filter = &peer->filter[afi][safi];
16196
16197 /* distribute-list. */
16198 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16199 FILTER_IN))
16200 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16201 filter->dlist[FILTER_IN].name);
16202
16203 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16204 FILTER_OUT))
16205 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16206 filter->dlist[FILTER_OUT].name);
16207
16208 /* prefix-list. */
16209 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16210 FILTER_IN))
16211 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16212 filter->plist[FILTER_IN].name);
16213
16214 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16215 FILTER_OUT))
16216 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16217 filter->plist[FILTER_OUT].name);
16218
16219 /* route-map. */
16220 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16221 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16222 filter->map[RMAP_IN].name);
16223
16224 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16225 RMAP_OUT))
16226 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16227 filter->map[RMAP_OUT].name);
16228
16229 /* unsuppress-map */
16230 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16231 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16232 filter->usmap.name);
16233
7f7940e6
MK
16234 /* advertise-map : always applied in OUT direction*/
16235 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16236 CONDITION_NON_EXIST))
16237 vty_out(vty,
16238 " neighbor %s advertise-map %s non-exist-map %s\n",
16239 addr, filter->advmap.aname, filter->advmap.cname);
16240
16241 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16242 CONDITION_EXIST))
16243 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16244 addr, filter->advmap.aname, filter->advmap.cname);
16245
dd65f45e
DL
16246 /* filter-list. */
16247 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16248 FILTER_IN))
16249 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16250 filter->aslist[FILTER_IN].name);
16251
16252 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16253 FILTER_OUT))
16254 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16255 filter->aslist[FILTER_OUT].name);
16256}
16257
16258/* BGP peer configuration display function. */
16259static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16260 struct peer *peer)
16261{
16262 struct peer *g_peer = NULL;
16263 char buf[SU_ADDRSTRLEN];
16264 char *addr;
16265 int if_pg_printed = false;
16266 int if_ras_printed = false;
16267
16268 /* Skip dynamic neighbors. */
16269 if (peer_dynamic_neighbor(peer))
16270 return;
16271
16272 if (peer->conf_if)
16273 addr = peer->conf_if;
16274 else
16275 addr = peer->host;
16276
16277 /************************************
16278 ****** Global to the neighbor ******
16279 ************************************/
16280 if (peer->conf_if) {
16281 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16282 vty_out(vty, " neighbor %s interface v6only", addr);
16283 else
16284 vty_out(vty, " neighbor %s interface", addr);
16285
16286 if (peer_group_active(peer)) {
16287 vty_out(vty, " peer-group %s", peer->group->name);
16288 if_pg_printed = true;
16289 } else if (peer->as_type == AS_SPECIFIED) {
16290 vty_out(vty, " remote-as %u", peer->as);
16291 if_ras_printed = true;
16292 } else if (peer->as_type == AS_INTERNAL) {
16293 vty_out(vty, " remote-as internal");
16294 if_ras_printed = true;
16295 } else if (peer->as_type == AS_EXTERNAL) {
16296 vty_out(vty, " remote-as external");
16297 if_ras_printed = true;
16298 }
16299
16300 vty_out(vty, "\n");
16301 }
16302
16303 /* remote-as and peer-group */
16304 /* peer is a member of a peer-group */
16305 if (peer_group_active(peer)) {
16306 g_peer = peer->group->conf;
16307
16308 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16309 if (peer->as_type == AS_SPECIFIED) {
16310 vty_out(vty, " neighbor %s remote-as %u\n",
16311 addr, peer->as);
16312 } else if (peer->as_type == AS_INTERNAL) {
16313 vty_out(vty,
16314 " neighbor %s remote-as internal\n",
16315 addr);
16316 } else if (peer->as_type == AS_EXTERNAL) {
16317 vty_out(vty,
16318 " neighbor %s remote-as external\n",
16319 addr);
16320 }
16321 }
16322
16323 /* For swpX peers we displayed the peer-group
16324 * via 'neighbor swpX interface peer-group PGNAME' */
16325 if (!if_pg_printed)
16326 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16327 peer->group->name);
16328 }
16329
16330 /* peer is NOT a member of a peer-group */
16331 else {
16332 /* peer is a peer-group, declare the peer-group */
16333 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16334 vty_out(vty, " neighbor %s peer-group\n", addr);
16335 }
16336
16337 if (!if_ras_printed) {
16338 if (peer->as_type == AS_SPECIFIED) {
16339 vty_out(vty, " neighbor %s remote-as %u\n",
16340 addr, peer->as);
16341 } else if (peer->as_type == AS_INTERNAL) {
16342 vty_out(vty,
16343 " neighbor %s remote-as internal\n",
16344 addr);
16345 } else if (peer->as_type == AS_EXTERNAL) {
16346 vty_out(vty,
16347 " neighbor %s remote-as external\n",
16348 addr);
16349 }
16350 }
16351 }
16352
16353 /* local-as */
16354 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16355 vty_out(vty, " neighbor %s local-as %u", addr,
16356 peer->change_local_as);
16357 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16358 vty_out(vty, " no-prepend");
16359 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16360 vty_out(vty, " replace-as");
16361 vty_out(vty, "\n");
16362 }
16363
16364 /* description */
16365 if (peer->desc) {
16366 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16367 }
16368
16369 /* shutdown */
16370 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16371 if (peer->tx_shutdown_message)
16372 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16373 peer->tx_shutdown_message);
16374 else
16375 vty_out(vty, " neighbor %s shutdown\n", addr);
16376 }
16377
8336c896
DA
16378 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16379 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16380 peer->rtt_expected, peer->rtt_keepalive_conf);
16381
dd65f45e
DL
16382 /* bfd */
16383 if (peer->bfd_info) {
16384 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16385 bgp_bfd_peer_config_write(vty, peer, addr);
16386 }
16387 }
16388
16389 /* password */
16390 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16391 vty_out(vty, " neighbor %s password %s\n", addr,
16392 peer->password);
16393
16394 /* neighbor solo */
16395 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16396 if (!peer_group_active(peer)) {
16397 vty_out(vty, " neighbor %s solo\n", addr);
16398 }
16399 }
16400
16401 /* BGP port */
16402 if (peer->port != BGP_PORT_DEFAULT) {
16403 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16404 }
16405
16406 /* Local interface name */
16407 if (peer->ifname) {
16408 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16409 }
16410
16411 /* passive */
16412 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16413 vty_out(vty, " neighbor %s passive\n", addr);
16414
16415 /* ebgp-multihop */
16416 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16417 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16418 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16419 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16420 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16421 peer->ttl);
16422 }
16423 }
16424
16425 /* ttl-security hops */
e2521429 16426 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16427 if (!peer_group_active(peer)
16428 || g_peer->gtsm_hops != peer->gtsm_hops) {
16429 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16430 addr, peer->gtsm_hops);
16431 }
16432 }
16433
16434 /* disable-connected-check */
16435 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16436 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16437
16438 /* enforce-first-as */
16439 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16440 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16441
16442 /* update-source */
16443 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16444 if (peer->update_source)
16445 vty_out(vty, " neighbor %s update-source %s\n", addr,
16446 sockunion2str(peer->update_source, buf,
16447 SU_ADDRSTRLEN));
16448 else if (peer->update_if)
16449 vty_out(vty, " neighbor %s update-source %s\n", addr,
16450 peer->update_if);
16451 }
16452
16453 /* advertisement-interval */
16454 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16455 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16456 peer->routeadv);
16457
16458 /* timers */
16459 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16460 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16461 peer->keepalive, peer->holdtime);
16462
16463 /* timers connect */
16464 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16465 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16466 peer->connect);
5d5393b9
DL
16467 /* need special-case handling for changed default values due to
16468 * config profile / version (because there is no "timers bgp connect"
16469 * command, we need to save this per-peer :/)
16470 */
16471 else if (!peer_group_active(peer) && !peer->connect &&
16472 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16473 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16474 peer->bgp->default_connect_retry);
dd65f45e 16475
d43114f3
DS
16476 /* timers delayopen */
16477 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16478 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16479 peer->delayopen);
16480 /* Save config even though flag is not set if default values have been
16481 * changed
16482 */
16483 else if (!peer_group_active(peer) && !peer->delayopen
16484 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16485 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16486 peer->bgp->default_delayopen);
16487
dd65f45e
DL
16488 /* capability dynamic */
16489 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16490 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16491
16492 /* capability extended-nexthop */
16493 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16494 if (!peer->conf_if) {
16495 if (CHECK_FLAG(peer->flags_invert,
16496 PEER_FLAG_CAPABILITY_ENHE))
16497 vty_out(vty,
16498 " no neighbor %s capability extended-nexthop\n",
16499 addr);
16500 else
16501 vty_out(vty,
16502 " neighbor %s capability extended-nexthop\n",
16503 addr);
16504 }
16505 }
16506
16507 /* dont-capability-negotiation */
16508 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16509 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16510
16511 /* override-capability */
16512 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16513 vty_out(vty, " neighbor %s override-capability\n", addr);
16514
16515 /* strict-capability-match */
16516 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16517 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16518
16519 /* Sender side AS path loop detection. */
16520 if (peer->as_path_loop_detection)
16521 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16522 addr);
cfd47646 16523
16524 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16525 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16526
16527 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16528 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16529 vty_out(vty,
16530 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16531 } else if (CHECK_FLAG(
16532 peer->peer_gr_new_status_flag,
16533 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16534 vty_out(vty,
16535 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16536 } else if (
16537 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16538 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16539 && !(CHECK_FLAG(
16540 peer->peer_gr_new_status_flag,
16541 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16542 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16543 addr);
cfd47646 16544 }
16545 }
dd65f45e
DL
16546}
16547
16548/* BGP peer configuration display function. */
16549static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16550 struct peer *peer, afi_t afi, safi_t safi)
16551{
16552 struct peer *g_peer = NULL;
16553 char *addr;
16554 bool flag_scomm, flag_secomm, flag_slcomm;
16555
16556 /* Skip dynamic neighbors. */
16557 if (peer_dynamic_neighbor(peer))
16558 return;
16559
16560 if (peer->conf_if)
16561 addr = peer->conf_if;
16562 else
16563 addr = peer->host;
16564
16565 /************************************
16566 ****** Per AF to the neighbor ******
16567 ************************************/
16568 if (peer_group_active(peer)) {
16569 g_peer = peer->group->conf;
16570
16571 /* If the peer-group is active but peer is not, print a 'no
16572 * activate' */
16573 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16574 vty_out(vty, " no neighbor %s activate\n", addr);
16575 }
16576
16577 /* If the peer-group is not active but peer is, print an
16578 'activate' */
16579 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16580 vty_out(vty, " neighbor %s activate\n", addr);
16581 }
16582 } else {
16583 if (peer->afc[afi][safi]) {
16584 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16585 if (CHECK_FLAG(bgp->flags,
16586 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16587 vty_out(vty, " neighbor %s activate\n",
16588 addr);
16589 }
16590 } else
16591 vty_out(vty, " neighbor %s activate\n", addr);
16592 } else {
16593 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16594 if (!CHECK_FLAG(bgp->flags,
16595 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16596 vty_out(vty,
16597 " no neighbor %s activate\n",
16598 addr);
16599 }
16600 }
16601 }
16602 }
16603
16604 /* addpath TX knobs */
16605 if (peergroup_af_addpath_check(peer, afi, safi)) {
16606 switch (peer->addpath_type[afi][safi]) {
16607 case BGP_ADDPATH_ALL:
16608 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16609 addr);
16610 break;
16611 case BGP_ADDPATH_BEST_PER_AS:
16612 vty_out(vty,
16613 " neighbor %s addpath-tx-bestpath-per-AS\n",
16614 addr);
16615 break;
16616 case BGP_ADDPATH_MAX:
16617 case BGP_ADDPATH_NONE:
16618 break;
16619 }
16620 }
16621
16622 /* ORF capability. */
16623 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16624 || peergroup_af_flag_check(peer, afi, safi,
16625 PEER_FLAG_ORF_PREFIX_RM)) {
16626 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16627
16628 if (peergroup_af_flag_check(peer, afi, safi,
16629 PEER_FLAG_ORF_PREFIX_SM)
16630 && peergroup_af_flag_check(peer, afi, safi,
16631 PEER_FLAG_ORF_PREFIX_RM))
16632 vty_out(vty, " both");
16633 else if (peergroup_af_flag_check(peer, afi, safi,
16634 PEER_FLAG_ORF_PREFIX_SM))
16635 vty_out(vty, " send");
16636 else
16637 vty_out(vty, " receive");
16638 vty_out(vty, "\n");
16639 }
16640
dd65f45e
DL
16641 /* Route reflector client. */
16642 if (peergroup_af_flag_check(peer, afi, safi,
16643 PEER_FLAG_REFLECTOR_CLIENT)) {
16644 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16645 }
16646
16647 /* next-hop-self force */
16648 if (peergroup_af_flag_check(peer, afi, safi,
16649 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16650 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16651 }
16652
16653 /* next-hop-self */
16654 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16655 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16656 }
16657
16658 /* remove-private-AS */
16659 if (peergroup_af_flag_check(peer, afi, safi,
16660 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16661 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16662 addr);
16663 }
16664
16665 else if (peergroup_af_flag_check(peer, afi, safi,
16666 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16667 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16668 addr);
16669 }
16670
16671 else if (peergroup_af_flag_check(peer, afi, safi,
16672 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16673 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16674 }
16675
16676 else if (peergroup_af_flag_check(peer, afi, safi,
16677 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16678 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16679 }
16680
16681 /* as-override */
16682 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16683 vty_out(vty, " neighbor %s as-override\n", addr);
16684 }
16685
16686 /* send-community print. */
16687 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16688 PEER_FLAG_SEND_COMMUNITY);
16689 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16690 PEER_FLAG_SEND_EXT_COMMUNITY);
16691 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16692 PEER_FLAG_SEND_LARGE_COMMUNITY);
16693
16694 if (flag_scomm && flag_secomm && flag_slcomm) {
16695 vty_out(vty, " no neighbor %s send-community all\n", addr);
16696 } else {
16697 if (flag_scomm)
16698 vty_out(vty, " no neighbor %s send-community\n", addr);
16699 if (flag_secomm)
16700 vty_out(vty,
16701 " no neighbor %s send-community extended\n",
16702 addr);
16703
16704 if (flag_slcomm)
16705 vty_out(vty, " no neighbor %s send-community large\n",
16706 addr);
16707 }
16708
16709 /* Default information */
16710 if (peergroup_af_flag_check(peer, afi, safi,
16711 PEER_FLAG_DEFAULT_ORIGINATE)) {
16712 vty_out(vty, " neighbor %s default-originate", addr);
16713
16714 if (peer->default_rmap[afi][safi].name)
16715 vty_out(vty, " route-map %s",
16716 peer->default_rmap[afi][safi].name);
16717
16718 vty_out(vty, "\n");
16719 }
16720
16721 /* Soft reconfiguration inbound. */
16722 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16723 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16724 addr);
16725 }
16726
16727 /* maximum-prefix. */
16728 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16729 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16730 peer->pmax[afi][safi]);
16731
16732 if (peer->pmax_threshold[afi][safi]
16733 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16734 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16735 if (peer_af_flag_check(peer, afi, safi,
16736 PEER_FLAG_MAX_PREFIX_WARNING))
16737 vty_out(vty, " warning-only");
16738 if (peer->pmax_restart[afi][safi])
16739 vty_out(vty, " restart %u",
16740 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16741 if (peer_af_flag_check(peer, afi, safi,
16742 PEER_FLAG_MAX_PREFIX_FORCE))
16743 vty_out(vty, " force");
dd65f45e
DL
16744
16745 vty_out(vty, "\n");
16746 }
16747
fde246e8
DA
16748 /* maximum-prefix-out */
16749 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16750 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16751 addr, peer->pmax_out[afi][safi]);
16752
dd65f45e
DL
16753 /* Route server client. */
16754 if (peergroup_af_flag_check(peer, afi, safi,
16755 PEER_FLAG_RSERVER_CLIENT)) {
16756 vty_out(vty, " neighbor %s route-server-client\n", addr);
16757 }
16758
16759 /* Nexthop-local unchanged. */
16760 if (peergroup_af_flag_check(peer, afi, safi,
16761 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16762 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16763 }
16764
16765 /* allowas-in <1-10> */
16766 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16767 if (peer_af_flag_check(peer, afi, safi,
16768 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16769 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16770 } else if (peer->allowas_in[afi][safi] == 3) {
16771 vty_out(vty, " neighbor %s allowas-in\n", addr);
16772 } else {
16773 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16774 peer->allowas_in[afi][safi]);
16775 }
16776 }
16777
16778 /* weight */
16779 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16780 vty_out(vty, " neighbor %s weight %lu\n", addr,
16781 peer->weight[afi][safi]);
16782
16783 /* Filter. */
16784 bgp_config_write_filter(vty, peer, afi, safi);
16785
16786 /* atribute-unchanged. */
16787 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16788 || (safi != SAFI_EVPN
16789 && peer_af_flag_check(peer, afi, safi,
16790 PEER_FLAG_NEXTHOP_UNCHANGED))
16791 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16792
16793 if (!peer_group_active(peer)
16794 || peergroup_af_flag_check(peer, afi, safi,
16795 PEER_FLAG_AS_PATH_UNCHANGED)
16796 || peergroup_af_flag_check(peer, afi, safi,
16797 PEER_FLAG_NEXTHOP_UNCHANGED)
16798 || peergroup_af_flag_check(peer, afi, safi,
16799 PEER_FLAG_MED_UNCHANGED)) {
16800
16801 vty_out(vty,
16802 " neighbor %s attribute-unchanged%s%s%s\n",
16803 addr,
16804 peer_af_flag_check(peer, afi, safi,
16805 PEER_FLAG_AS_PATH_UNCHANGED)
16806 ? " as-path"
16807 : "",
16808 peer_af_flag_check(peer, afi, safi,
16809 PEER_FLAG_NEXTHOP_UNCHANGED)
16810 ? " next-hop"
16811 : "",
16812 peer_af_flag_check(peer, afi, safi,
16813 PEER_FLAG_MED_UNCHANGED)
16814 ? " med"
16815 : "");
16816 }
16817 }
16818}
16819
16820/* Address family based peer configuration display. */
16821static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16822 safi_t safi)
16823{
16824 struct peer *peer;
16825 struct peer_group *group;
16826 struct listnode *node, *nnode;
16827
16828
16829 vty_frame(vty, " !\n address-family ");
16830 if (afi == AFI_IP) {
16831 if (safi == SAFI_UNICAST)
16832 vty_frame(vty, "ipv4 unicast");
16833 else if (safi == SAFI_LABELED_UNICAST)
16834 vty_frame(vty, "ipv4 labeled-unicast");
16835 else if (safi == SAFI_MULTICAST)
16836 vty_frame(vty, "ipv4 multicast");
16837 else if (safi == SAFI_MPLS_VPN)
16838 vty_frame(vty, "ipv4 vpn");
16839 else if (safi == SAFI_ENCAP)
16840 vty_frame(vty, "ipv4 encap");
16841 else if (safi == SAFI_FLOWSPEC)
16842 vty_frame(vty, "ipv4 flowspec");
16843 } else if (afi == AFI_IP6) {
16844 if (safi == SAFI_UNICAST)
16845 vty_frame(vty, "ipv6 unicast");
16846 else if (safi == SAFI_LABELED_UNICAST)
16847 vty_frame(vty, "ipv6 labeled-unicast");
16848 else if (safi == SAFI_MULTICAST)
16849 vty_frame(vty, "ipv6 multicast");
16850 else if (safi == SAFI_MPLS_VPN)
16851 vty_frame(vty, "ipv6 vpn");
16852 else if (safi == SAFI_ENCAP)
16853 vty_frame(vty, "ipv6 encap");
16854 else if (safi == SAFI_FLOWSPEC)
16855 vty_frame(vty, "ipv6 flowspec");
16856 } else if (afi == AFI_L2VPN) {
16857 if (safi == SAFI_EVPN)
16858 vty_frame(vty, "l2vpn evpn");
16859 }
16860 vty_frame(vty, "\n");
16861
16862 bgp_config_write_distance(vty, bgp, afi, safi);
16863
16864 bgp_config_write_network(vty, bgp, afi, safi);
16865
16866 bgp_config_write_redistribute(vty, bgp, afi, safi);
16867
8a4e7fe6
DA
16868 /* BGP flag dampening. */
16869 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
16870 bgp_config_write_damp(vty, afi, safi);
16871
dd65f45e
DL
16872 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16873 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16874
16875 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16876 /* Skip dynamic neighbors. */
16877 if (peer_dynamic_neighbor(peer))
16878 continue;
16879
16880 /* Do not display doppelganger peers */
16881 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16882 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16883 }
16884
16885 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16886 bgp_config_write_table_map(vty, bgp, afi, safi);
16887
16888 if (safi == SAFI_EVPN)
16889 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16890
16891 if (safi == SAFI_FLOWSPEC)
16892 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16893
16894 if (safi == SAFI_UNICAST) {
16895 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16896 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16897 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16898
16899 vty_out(vty, " export vpn\n");
16900 }
16901 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16902 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16903
16904 vty_out(vty, " import vpn\n");
16905 }
16906 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16907 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16908 char *name;
16909
16910 for (ALL_LIST_ELEMENTS_RO(
16911 bgp->vpn_policy[afi].import_vrf, node,
16912 name))
16913 vty_out(vty, " import vrf %s\n", name);
16914 }
16915 }
16916
16917 vty_endframe(vty, " exit-address-family\n");
16918}
16919
16920int bgp_config_write(struct vty *vty)
16921{
16922 struct bgp *bgp;
16923 struct peer_group *group;
16924 struct peer *peer;
16925 struct listnode *node, *nnode;
16926 struct listnode *mnode, *mnnode;
16927
16928 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16929 vty_out(vty, "bgp route-map delay-timer %u\n",
16930 bm->rmap_update_timer);
16931
d70583f7
D
16932 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16933 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16934 if (bm->v_update_delay != bm->v_establish_wait)
16935 vty_out(vty, " %d", bm->v_establish_wait);
16936 vty_out(vty, "\n");
16937 }
16938
05bd726c 16939 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16940 vty_out(vty, "bgp graceful-shutdown\n");
16941
c163f297
DS
16942 /* No-RIB (Zebra) option flag configuration */
16943 if (bgp_option_check(BGP_OPT_NO_FIB))
16944 vty_out(vty, "bgp no-rib\n");
16945
e46723a5
DS
16946 if (bm->send_extra_data_to_zebra)
16947 vty_out(vty, "no bgp send-extra-data zebra\n");
16948
dd65f45e
DL
16949 /* BGP configuration. */
16950 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
16951
16952 /* skip all auto created vrf as they dont have user config */
16953 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
16954 continue;
16955
16956 /* Router bgp ASN */
16957 vty_out(vty, "router bgp %u", bgp->as);
16958
16959 if (bgp->name)
16960 vty_out(vty, " %s %s",
16961 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
16962 ? "view" : "vrf", bgp->name);
16963 vty_out(vty, "\n");
16964
16965 /* BGP fast-external-failover. */
16966 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
16967 vty_out(vty, " no bgp fast-external-failover\n");
16968
16969 /* BGP router ID. */
16970 if (bgp->router_id_static.s_addr != 0)
23d0a753
DA
16971 vty_out(vty, " bgp router-id %pI4\n",
16972 &bgp->router_id_static);
dd65f45e 16973
c208c586
S
16974 /* Suppress fib pending */
16975 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
16976 vty_out(vty, " bgp suppress-fib-pending\n");
16977
dd65f45e 16978 /* BGP log-neighbor-changes. */
892fedb6 16979 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 16980 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 16981 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
16982 CHECK_FLAG(bgp->flags,
16983 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
16984 ? ""
16985 : "no ");
16986
16987 /* BGP configuration. */
892fedb6 16988 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
16989 vty_out(vty, " bgp always-compare-med\n");
16990
16991 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
16992 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
16993 != SAVE_BGP_EBGP_REQUIRES_POLICY)
16994 vty_out(vty, " %sbgp ebgp-requires-policy\n",
16995 CHECK_FLAG(bgp->flags,
16996 BGP_FLAG_EBGP_REQUIRES_POLICY)
16997 ? ""
16998 : "no ");
dd65f45e
DL
16999
17000 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17001 if (bgp->reject_as_sets)
dd65f45e
DL
17002 vty_out(vty, " bgp reject-as-sets\n");
17003
17004 /* BGP default ipv4-unicast. */
892fedb6 17005 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
17006 vty_out(vty, " no bgp default ipv4-unicast\n");
17007
17008 /* BGP default local-preference. */
17009 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17010 vty_out(vty, " bgp default local-preference %u\n",
17011 bgp->default_local_pref);
17012
17013 /* BGP default show-hostname */
892fedb6 17014 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17015 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17016 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17017 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17018 ? ""
17019 : "no ");
17020
aef999a2
DA
17021 /* BGP default show-nexthop-hostname */
17022 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17023 != SAVE_BGP_SHOW_HOSTNAME)
17024 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17025 CHECK_FLAG(bgp->flags,
17026 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17027 ? ""
17028 : "no ");
17029
dd65f45e
DL
17030 /* BGP default subgroup-pkt-queue-max. */
17031 if (bgp->default_subgroup_pkt_queue_max
17032 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17033 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17034 bgp->default_subgroup_pkt_queue_max);
17035
17036 /* BGP client-to-client reflection. */
892fedb6 17037 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17038 vty_out(vty, " no bgp client-to-client reflection\n");
17039
17040 /* BGP cluster ID. */
17041 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17042 vty_out(vty, " bgp cluster-id %pI4\n",
17043 &bgp->cluster_id);
dd65f45e
DL
17044
17045 /* Disable ebgp connected nexthop check */
892fedb6 17046 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17047 vty_out(vty,
17048 " bgp disable-ebgp-connected-route-check\n");
17049
17050 /* Confederation identifier*/
17051 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17052 vty_out(vty, " bgp confederation identifier %u\n",
17053 bgp->confed_id);
17054
17055 /* Confederation peer */
17056 if (bgp->confed_peers_cnt > 0) {
17057 int i;
17058
17059 vty_out(vty, " bgp confederation peers");
17060
17061 for (i = 0; i < bgp->confed_peers_cnt; i++)
17062 vty_out(vty, " %u", bgp->confed_peers[i]);
17063
17064 vty_out(vty, "\n");
17065 }
17066
17067 /* BGP deterministic-med. */
892fedb6 17068 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17069 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17070 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17071 CHECK_FLAG(bgp->flags,
17072 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17073 ? ""
17074 : "no ");
17075
17076 /* BGP update-delay. */
17077 bgp_config_write_update_delay(vty, bgp);
17078
17079 if (bgp->v_maxmed_onstartup
17080 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17081 vty_out(vty, " bgp max-med on-startup %u",
17082 bgp->v_maxmed_onstartup);
17083 if (bgp->maxmed_onstartup_value
17084 != BGP_MAXMED_VALUE_DEFAULT)
17085 vty_out(vty, " %u",
17086 bgp->maxmed_onstartup_value);
17087 vty_out(vty, "\n");
17088 }
17089 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17090 vty_out(vty, " bgp max-med administrative");
17091 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17092 vty_out(vty, " %u", bgp->maxmed_admin_value);
17093 vty_out(vty, "\n");
17094 }
17095
17096 /* write quanta */
17097 bgp_config_write_wpkt_quanta(vty, bgp);
17098 /* read quanta */
17099 bgp_config_write_rpkt_quanta(vty, bgp);
17100
17101 /* coalesce time */
17102 bgp_config_write_coalesce_time(vty, bgp);
17103
05bd726c 17104 /* BGP per-instance graceful-shutdown */
17105 /* BGP-wide settings and per-instance settings are mutually
17106 * exclusive.
17107 */
17108 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17109 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17110 vty_out(vty, " bgp graceful-shutdown\n");
17111
dd65f45e
DL
17112 /* BGP graceful-restart. */
17113 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17114 vty_out(vty,
17115 " bgp graceful-restart stalepath-time %u\n",
17116 bgp->stalepath_time);
cfd47646 17117
dd65f45e
DL
17118 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17119 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17120 bgp->restart_time);
cfd47646 17121
17122 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17123 vty_out(vty,
17124 " bgp graceful-restart select-defer-time %u\n",
17125 bgp->select_defer_time);
17126
17127 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17128 vty_out(vty, " bgp graceful-restart\n");
17129
cfd47646 17130 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17131 vty_out(vty, " bgp graceful-restart-disable\n");
17132
dd65f45e 17133 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17134 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17135 vty_out(vty,
17136 " bgp graceful-restart preserve-fw-state\n");
17137
dc95985f 17138 /* Stale timer for RIB */
17139 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17140 vty_out(vty,
17141 " bgp graceful-restart rib-stale-time %u\n",
17142 bgp->rib_stale_time);
17143
dd65f45e 17144 /* BGP bestpath method. */
892fedb6 17145 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17146 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17147 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17148 vty_out(vty, " bgp bestpath as-path confed\n");
17149
892fedb6
DA
17150 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17151 if (CHECK_FLAG(bgp->flags,
17152 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17153 vty_out(vty,
17154 " bgp bestpath as-path multipath-relax as-set\n");
17155 } else {
17156 vty_out(vty,
17157 " bgp bestpath as-path multipath-relax\n");
17158 }
17159 }
17160
892fedb6 17161 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17162 vty_out(vty,
17163 " bgp route-reflector allow-outbound-policy\n");
17164 }
892fedb6 17165 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17166 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17167 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17168 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17169 vty_out(vty, " bgp bestpath med");
892fedb6 17170 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17171 vty_out(vty, " confed");
892fedb6
DA
17172 if (CHECK_FLAG(bgp->flags,
17173 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17174 vty_out(vty, " missing-as-worst");
17175 vty_out(vty, "\n");
17176 }
17177
f7e1c681 17178 /* Link bandwidth handling. */
17179 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17180 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17181 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17182 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17183 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17184 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17185
dd65f45e 17186 /* BGP network import check. */
892fedb6 17187 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17188 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17189 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17190 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17191 ? ""
17192 : "no ");
17193
17194 /* BGP timers configuration. */
5d5393b9
DL
17195 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17196 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17197 vty_out(vty, " timers bgp %u %u\n",
17198 bgp->default_keepalive, bgp->default_holdtime);
17199
17200 /* peer-group */
17201 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17202 bgp_config_write_peer_global(vty, bgp, group->conf);
17203 }
17204
17205 /* Normal neighbor configuration. */
17206 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17207 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17208 bgp_config_write_peer_global(vty, bgp, peer);
17209 }
17210
17211 /* listen range and limit for dynamic BGP neighbors */
17212 bgp_config_write_listen(vty, bgp);
17213
17214 /*
17215 * BGP default autoshutdown neighbors
17216 *
17217 * This must be placed after any peer and peer-group
17218 * configuration, to avoid setting all peers to shutdown after
17219 * a daemon restart, which is undesired behavior. (see #2286)
17220 */
17221 if (bgp->autoshutdown)
17222 vty_out(vty, " bgp default shutdown\n");
17223
9cf59432
DS
17224 /* BGP instance administrative shutdown */
17225 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17226 vty_out(vty, " bgp shutdown\n");
17227
dd65f45e
DL
17228 /* IPv4 unicast configuration. */
17229 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17230
17231 /* IPv4 multicast configuration. */
17232 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17233
17234 /* IPv4 labeled-unicast configuration. */
17235 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17236
17237 /* IPv4 VPN configuration. */
17238 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17239
17240 /* ENCAPv4 configuration. */
17241 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17242
17243 /* FLOWSPEC v4 configuration. */
17244 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17245
17246 /* IPv6 unicast configuration. */
17247 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17248
17249 /* IPv6 multicast configuration. */
17250 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17251
17252 /* IPv6 labeled-unicast configuration. */
17253 bgp_config_write_family(vty, bgp, AFI_IP6,
17254 SAFI_LABELED_UNICAST);
17255
17256 /* IPv6 VPN configuration. */
17257 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17258
17259 /* ENCAPv6 configuration. */
17260 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17261
17262 /* FLOWSPEC v6 configuration. */
17263 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17264
17265 /* EVPN configuration. */
17266 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17267
17268 hook_call(bgp_inst_config_write, bgp, vty);
17269
49e5a4a0 17270#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17271 bgp_rfapi_cfg_write(vty, bgp);
17272#endif
17273
17274 vty_out(vty, "!\n");
17275 }
17276 return 0;
17277}
17278
ddb5b488 17279
718e3744 17280/* BGP node structure. */
d62a17ae 17281static struct cmd_node bgp_node = {
f4b8291f 17282 .name = "bgp",
62b346ee 17283 .node = BGP_NODE,
24389580 17284 .parent_node = CONFIG_NODE,
62b346ee 17285 .prompt = "%s(config-router)# ",
612c2c15 17286 .config_write = bgp_config_write,
718e3744 17287};
17288
d62a17ae 17289static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17290 .name = "bgp ipv4 unicast",
62b346ee 17291 .node = BGP_IPV4_NODE,
24389580 17292 .parent_node = BGP_NODE,
62b346ee 17293 .prompt = "%s(config-router-af)# ",
718e3744 17294};
17295
d62a17ae 17296static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17297 .name = "bgp ipv4 multicast",
62b346ee 17298 .node = BGP_IPV4M_NODE,
24389580 17299 .parent_node = BGP_NODE,
62b346ee 17300 .prompt = "%s(config-router-af)# ",
718e3744 17301};
17302
d62a17ae 17303static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17304 .name = "bgp ipv4 labeled unicast",
62b346ee 17305 .node = BGP_IPV4L_NODE,
24389580 17306 .parent_node = BGP_NODE,
62b346ee 17307 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17308};
17309
d62a17ae 17310static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 17311 .name = "bgp ipv6",
62b346ee 17312 .node = BGP_IPV6_NODE,
24389580 17313 .parent_node = BGP_NODE,
62b346ee 17314 .prompt = "%s(config-router-af)# ",
718e3744 17315};
17316
d62a17ae 17317static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17318 .name = "bgp ipv6 multicast",
62b346ee 17319 .node = BGP_IPV6M_NODE,
24389580 17320 .parent_node = BGP_NODE,
62b346ee 17321 .prompt = "%s(config-router-af)# ",
25ffbdc1 17322};
17323
d62a17ae 17324static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17325 .name = "bgp ipv6 labeled unicast",
62b346ee 17326 .node = BGP_IPV6L_NODE,
24389580 17327 .parent_node = BGP_NODE,
62b346ee 17328 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17329};
17330
62b346ee 17331static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17332 .name = "bgp vpnv4",
62b346ee 17333 .node = BGP_VPNV4_NODE,
24389580 17334 .parent_node = BGP_NODE,
62b346ee 17335 .prompt = "%s(config-router-af)# ",
62b346ee 17336};
6b0655a2 17337
62b346ee 17338static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17339 .name = "bgp vpnv6",
62b346ee 17340 .node = BGP_VPNV6_NODE,
24389580 17341 .parent_node = BGP_NODE,
62b346ee 17342 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17343};
8ecd3266 17344
62b346ee 17345static struct cmd_node bgp_evpn_node = {
f4b8291f 17346 .name = "bgp evpn",
62b346ee 17347 .node = BGP_EVPN_NODE,
24389580 17348 .parent_node = BGP_NODE,
62b346ee 17349 .prompt = "%s(config-router-evpn)# ",
62b346ee 17350};
4e0b7b6d 17351
62b346ee 17352static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17353 .name = "bgp evpn vni",
62b346ee 17354 .node = BGP_EVPN_VNI_NODE,
24389580 17355 .parent_node = BGP_EVPN_NODE,
62b346ee 17356 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17357};
90e60aa7 17358
62b346ee 17359static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17360 .name = "bgp ipv4 flowspec",
62b346ee 17361 .node = BGP_FLOWSPECV4_NODE,
24389580 17362 .parent_node = BGP_NODE,
62b346ee 17363 .prompt = "%s(config-router-af)# ",
62b346ee 17364};
7c40bf39 17365
62b346ee 17366static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17367 .name = "bgp ipv6 flowspec",
62b346ee 17368 .node = BGP_FLOWSPECV6_NODE,
24389580 17369 .parent_node = BGP_NODE,
62b346ee 17370 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17371};
7c40bf39 17372
d62a17ae 17373static void community_list_vty(void);
1f8ae70b 17374
d62a17ae 17375static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 17376{
d62a17ae 17377 struct bgp *bgp;
17378 struct peer *peer;
d62a17ae 17379 struct listnode *lnbgp, *lnpeer;
b8a815e5 17380
d62a17ae 17381 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17382 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17383 /* only provide suggestions on the appropriate input
17384 * token type,
17385 * they'll otherwise show up multiple times */
17386 enum cmd_token_type match_type;
17387 char *name = peer->host;
d48ed3e0 17388
d62a17ae 17389 if (peer->conf_if) {
17390 match_type = VARIABLE_TKN;
17391 name = peer->conf_if;
17392 } else if (strchr(peer->host, ':'))
17393 match_type = IPV6_TKN;
17394 else
17395 match_type = IPV4_TKN;
d48ed3e0 17396
d62a17ae 17397 if (token->type != match_type)
17398 continue;
d48ed3e0 17399
d62a17ae 17400 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17401 }
d62a17ae 17402 }
b8a815e5
DL
17403}
17404
17405static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17406 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17407 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17408 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17409 {.completions = NULL}};
17410
47a306a0
DS
17411static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17412{
17413 struct bgp *bgp;
17414 struct peer_group *group;
17415 struct listnode *lnbgp, *lnpeer;
17416
17417 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17418 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17419 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17420 group->name));
17421 }
17422}
17423
17424static const struct cmd_variable_handler bgp_var_peergroup[] = {
17425 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17426 {.completions = NULL} };
17427
d62a17ae 17428void bgp_vty_init(void)
17429{
17430 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17431 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17432
17433 /* Install bgp top node. */
612c2c15
DL
17434 install_node(&bgp_node);
17435 install_node(&bgp_ipv4_unicast_node);
17436 install_node(&bgp_ipv4_multicast_node);
17437 install_node(&bgp_ipv4_labeled_unicast_node);
17438 install_node(&bgp_ipv6_unicast_node);
17439 install_node(&bgp_ipv6_multicast_node);
17440 install_node(&bgp_ipv6_labeled_unicast_node);
17441 install_node(&bgp_vpnv4_node);
17442 install_node(&bgp_vpnv6_node);
17443 install_node(&bgp_evpn_node);
17444 install_node(&bgp_evpn_vni_node);
17445 install_node(&bgp_flowspecv4_node);
17446 install_node(&bgp_flowspecv6_node);
d62a17ae 17447
17448 /* Install default VTY commands to new nodes. */
17449 install_default(BGP_NODE);
17450 install_default(BGP_IPV4_NODE);
17451 install_default(BGP_IPV4M_NODE);
17452 install_default(BGP_IPV4L_NODE);
17453 install_default(BGP_IPV6_NODE);
17454 install_default(BGP_IPV6M_NODE);
17455 install_default(BGP_IPV6L_NODE);
17456 install_default(BGP_VPNV4_NODE);
17457 install_default(BGP_VPNV6_NODE);
7c40bf39 17458 install_default(BGP_FLOWSPECV4_NODE);
17459 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17460 install_default(BGP_EVPN_NODE);
17461 install_default(BGP_EVPN_VNI_NODE);
17462
8029b216
AK
17463 /* "bgp local-mac" hidden commands. */
17464 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17465 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17466
d62a17ae 17467 /* bgp route-map delay-timer commands. */
17468 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17469 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17470
d70583f7
D
17471 /* global bgp update-delay command */
17472 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17473 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17474
05bd726c 17475 /* global bgp graceful-shutdown command */
17476 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17477 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17478
d62a17ae 17479 /* Dummy commands (Currently not supported) */
17480 install_element(BGP_NODE, &no_synchronization_cmd);
17481 install_element(BGP_NODE, &no_auto_summary_cmd);
17482
17483 /* "router bgp" commands. */
17484 install_element(CONFIG_NODE, &router_bgp_cmd);
17485
17486 /* "no router bgp" commands. */
17487 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17488
17489 /* "bgp router-id" commands. */
17490 install_element(BGP_NODE, &bgp_router_id_cmd);
17491 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17492
c208c586
S
17493 /* "bgp suppress-fib-pending" command */
17494 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17495
d62a17ae 17496 /* "bgp cluster-id" commands. */
17497 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17498 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17499
c163f297
DS
17500 /* "bgp no-rib" commands. */
17501 install_element(CONFIG_NODE, &bgp_norib_cmd);
17502 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17503
e46723a5
DS
17504 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17505
d62a17ae 17506 /* "bgp confederation" commands. */
17507 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17508 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17509
17510 /* "bgp confederation peers" commands. */
17511 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17512 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17513
17514 /* bgp max-med command */
17515 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17516 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17517 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17518 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17519 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17520
17521 /* bgp disable-ebgp-connected-nh-check */
17522 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17523 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17524
17525 /* bgp update-delay command */
17526 install_element(BGP_NODE, &bgp_update_delay_cmd);
17527 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17528
17529 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17530 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17531
17532 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17533 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17534
17535 /* "maximum-paths" commands. */
17536 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17537 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17538 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17539 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17540 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17541 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17542 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17543 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17544 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17545 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17546 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17547 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17548 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17549 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17550 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17551
39edabac
PG
17552 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17553 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17554 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17555 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17556 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17557 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17558 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17559 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17560 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17561 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17562
17563 /* "timers bgp" commands. */
17564 install_element(BGP_NODE, &bgp_timers_cmd);
17565 install_element(BGP_NODE, &no_bgp_timers_cmd);
17566
17567 /* route-map delay-timer commands - per instance for backwards compat.
17568 */
17569 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17570 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17571
17572 /* "bgp client-to-client reflection" commands */
17573 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17574 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17575
17576 /* "bgp always-compare-med" commands */
17577 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17578 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17579
9dac9fc8
DA
17580 /* bgp ebgp-requires-policy */
17581 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17582 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17583
fb29348a
DA
17584 /* bgp reject-as-sets */
17585 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17586 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17587
d62a17ae 17588 /* "bgp deterministic-med" commands */
17589 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17590 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17591
055679e9 17592 /* "bgp graceful-restart" command */
36235319
QY
17593 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17594 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17595
17596 /* "bgp graceful-restart-disable" command */
36235319
QY
17597 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17598 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17599
17600 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17601 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17602 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17603
17604 /* "neighbor a:b:c:d graceful-restart-disable" command */
17605 install_element(BGP_NODE,
17606 &bgp_neighbor_graceful_restart_disable_set_cmd);
17607 install_element(BGP_NODE,
17608 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17609
17610 /* "neighbor a:b:c:d graceful-restart-helper" command */
17611 install_element(BGP_NODE,
17612 &bgp_neighbor_graceful_restart_helper_set_cmd);
17613 install_element(BGP_NODE,
17614 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17615
d62a17ae 17616 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17617 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17618 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17619 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17620 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17621 install_element(BGP_NODE,
17622 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17623 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17624 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17625
d6e3c15b 17626 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17627 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17628 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17629 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17630
7f323236
DW
17631 /* "bgp graceful-shutdown" commands */
17632 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17633 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17634
d62a17ae 17635 /* "bgp fast-external-failover" commands */
17636 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17637 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17638
d62a17ae 17639 /* "bgp bestpath compare-routerid" commands */
17640 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17641 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17642
17643 /* "bgp bestpath as-path ignore" commands */
17644 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17645 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17646
17647 /* "bgp bestpath as-path confed" commands */
17648 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17649 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17650
17651 /* "bgp bestpath as-path multipath-relax" commands */
17652 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17653 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17654
17655 /* "bgp log-neighbor-changes" commands */
17656 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17657 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17658
17659 /* "bgp bestpath med" commands */
17660 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17661 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17662
f7e1c681 17663 /* "bgp bestpath bandwidth" commands */
17664 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17665 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17666
d62a17ae 17667 /* "no bgp default ipv4-unicast" commands. */
17668 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17669 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17670
17671 /* "bgp network import-check" commands. */
17672 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17673 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17674 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17675
17676 /* "bgp default local-preference" commands. */
17677 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17678 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17679
17680 /* bgp default show-hostname */
17681 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17682 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17683
aef999a2
DA
17684 /* bgp default show-nexthop-hostname */
17685 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17686 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17687
d62a17ae 17688 /* "bgp default subgroup-pkt-queue-max" commands. */
17689 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17690 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17691
17692 /* bgp ibgp-allow-policy-mods command */
17693 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17694 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17695
17696 /* "bgp listen limit" commands. */
17697 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17698 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17699
17700 /* "bgp listen range" commands. */
17701 install_element(BGP_NODE, &bgp_listen_range_cmd);
17702 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17703
8175f54a 17704 /* "bgp default shutdown" command */
f26845f9 17705 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17706
17707 /* "bgp shutdown" commands */
17708 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17709 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17710 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17711 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17712
d62a17ae 17713 /* "neighbor remote-as" commands. */
17714 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17715 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17716 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17717 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17718 install_element(BGP_NODE,
17719 &neighbor_interface_v6only_config_remote_as_cmd);
17720 install_element(BGP_NODE, &no_neighbor_cmd);
17721 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17722
17723 /* "neighbor peer-group" commands. */
17724 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17725 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17726 install_element(BGP_NODE,
17727 &no_neighbor_interface_peer_group_remote_as_cmd);
17728
17729 /* "neighbor local-as" commands. */
17730 install_element(BGP_NODE, &neighbor_local_as_cmd);
17731 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17732 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17733 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17734
17735 /* "neighbor solo" commands. */
17736 install_element(BGP_NODE, &neighbor_solo_cmd);
17737 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17738
17739 /* "neighbor password" commands. */
17740 install_element(BGP_NODE, &neighbor_password_cmd);
17741 install_element(BGP_NODE, &no_neighbor_password_cmd);
17742
17743 /* "neighbor activate" commands. */
17744 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17745 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17746 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17747 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17748 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17749 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17750 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17751 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17752 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17753 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17754 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17755 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17756
17757 /* "no neighbor activate" commands. */
17758 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17759 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17760 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17761 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17762 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17763 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17764 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17765 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17766 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 17767 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17768 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 17769 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17770
17771 /* "neighbor peer-group" set commands. */
17772 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17773 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17774 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17775 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17776 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17777 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17778 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17779 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 17780 install_element(BGP_FLOWSPECV4_NODE,
17781 &neighbor_set_peer_group_hidden_cmd);
17782 install_element(BGP_FLOWSPECV6_NODE,
17783 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 17784
17785 /* "no neighbor peer-group unset" commands. */
17786 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17787 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17788 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17789 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17790 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17791 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17792 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17793 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 17794 install_element(BGP_FLOWSPECV4_NODE,
17795 &no_neighbor_set_peer_group_hidden_cmd);
17796 install_element(BGP_FLOWSPECV6_NODE,
17797 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 17798
17799 /* "neighbor softreconfiguration inbound" commands.*/
17800 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17801 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17802 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17803 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17804 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17805 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17806 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17807 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17808 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17809 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17810 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17811 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17812 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17813 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17814 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17815 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17816 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17817 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 17818 install_element(BGP_FLOWSPECV4_NODE,
17819 &neighbor_soft_reconfiguration_cmd);
17820 install_element(BGP_FLOWSPECV4_NODE,
17821 &no_neighbor_soft_reconfiguration_cmd);
17822 install_element(BGP_FLOWSPECV6_NODE,
17823 &neighbor_soft_reconfiguration_cmd);
17824 install_element(BGP_FLOWSPECV6_NODE,
17825 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
17826 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17827 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 17828
17829 /* "neighbor attribute-unchanged" commands. */
17830 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17831 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17832 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17833 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17834 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17835 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17836 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17837 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17838 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17839 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17840 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17841 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17842 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17843 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17844 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17845 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17846 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
17847 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
17848
17849 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
17850 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
17851
17852 /* "nexthop-local unchanged" commands */
17853 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
17854 install_element(BGP_IPV6_NODE,
17855 &no_neighbor_nexthop_local_unchanged_cmd);
17856
17857 /* "neighbor next-hop-self" commands. */
17858 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
17859 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
17860 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
17861 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
17862 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
17863 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
17864 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
17865 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
17866 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
17867 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
17868 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
17869 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
17870 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
17871 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
17872 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
17873 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
17874 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
17875 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
17876 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
17877 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 17878
17879 /* "neighbor next-hop-self force" commands. */
17880 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
17881 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
17882 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17883 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17884 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
17885 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17886 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17887 install_element(BGP_IPV4_NODE,
17888 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17889 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
17890 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17891 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17892 install_element(BGP_IPV4M_NODE,
17893 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17894 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
17895 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17896 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17897 install_element(BGP_IPV4L_NODE,
17898 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17899 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
17900 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17901 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17902 install_element(BGP_IPV6_NODE,
17903 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17904 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
17905 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17906 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17907 install_element(BGP_IPV6M_NODE,
17908 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17909 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
17910 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17911 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17912 install_element(BGP_IPV6L_NODE,
17913 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17914 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
17915 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17916 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17917 install_element(BGP_VPNV4_NODE,
17918 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17919 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
17920 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17921 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17922 install_element(BGP_VPNV6_NODE,
17923 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
17924 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
17925 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 17926
17927 /* "neighbor as-override" commands. */
17928 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
17929 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
17930 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
17931 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
17932 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
17933 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
17934 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
17935 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
17936 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
17937 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
17938 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
17939 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
17940 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
17941 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
17942 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
17943 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
17944 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
17945 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
17946
17947 /* "neighbor remove-private-AS" commands. */
17948 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
17949 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
17950 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
17951 install_element(BGP_NODE,
17952 &no_neighbor_remove_private_as_all_hidden_cmd);
17953 install_element(BGP_NODE,
17954 &neighbor_remove_private_as_replace_as_hidden_cmd);
17955 install_element(BGP_NODE,
17956 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
17957 install_element(BGP_NODE,
17958 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
17959 install_element(
17960 BGP_NODE,
17961 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
17962 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
17963 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
17964 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
17965 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17966 install_element(BGP_IPV4_NODE,
17967 &neighbor_remove_private_as_replace_as_cmd);
17968 install_element(BGP_IPV4_NODE,
17969 &no_neighbor_remove_private_as_replace_as_cmd);
17970 install_element(BGP_IPV4_NODE,
17971 &neighbor_remove_private_as_all_replace_as_cmd);
17972 install_element(BGP_IPV4_NODE,
17973 &no_neighbor_remove_private_as_all_replace_as_cmd);
17974 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
17975 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
17976 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
17977 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
17978 install_element(BGP_IPV4M_NODE,
17979 &neighbor_remove_private_as_replace_as_cmd);
17980 install_element(BGP_IPV4M_NODE,
17981 &no_neighbor_remove_private_as_replace_as_cmd);
17982 install_element(BGP_IPV4M_NODE,
17983 &neighbor_remove_private_as_all_replace_as_cmd);
17984 install_element(BGP_IPV4M_NODE,
17985 &no_neighbor_remove_private_as_all_replace_as_cmd);
17986 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
17987 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
17988 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
17989 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
17990 install_element(BGP_IPV4L_NODE,
17991 &neighbor_remove_private_as_replace_as_cmd);
17992 install_element(BGP_IPV4L_NODE,
17993 &no_neighbor_remove_private_as_replace_as_cmd);
17994 install_element(BGP_IPV4L_NODE,
17995 &neighbor_remove_private_as_all_replace_as_cmd);
17996 install_element(BGP_IPV4L_NODE,
17997 &no_neighbor_remove_private_as_all_replace_as_cmd);
17998 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
17999 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18000 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18001 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18002 install_element(BGP_IPV6_NODE,
18003 &neighbor_remove_private_as_replace_as_cmd);
18004 install_element(BGP_IPV6_NODE,
18005 &no_neighbor_remove_private_as_replace_as_cmd);
18006 install_element(BGP_IPV6_NODE,
18007 &neighbor_remove_private_as_all_replace_as_cmd);
18008 install_element(BGP_IPV6_NODE,
18009 &no_neighbor_remove_private_as_all_replace_as_cmd);
18010 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18011 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18012 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18013 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18014 install_element(BGP_IPV6M_NODE,
18015 &neighbor_remove_private_as_replace_as_cmd);
18016 install_element(BGP_IPV6M_NODE,
18017 &no_neighbor_remove_private_as_replace_as_cmd);
18018 install_element(BGP_IPV6M_NODE,
18019 &neighbor_remove_private_as_all_replace_as_cmd);
18020 install_element(BGP_IPV6M_NODE,
18021 &no_neighbor_remove_private_as_all_replace_as_cmd);
18022 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18023 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18024 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18025 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18026 install_element(BGP_IPV6L_NODE,
18027 &neighbor_remove_private_as_replace_as_cmd);
18028 install_element(BGP_IPV6L_NODE,
18029 &no_neighbor_remove_private_as_replace_as_cmd);
18030 install_element(BGP_IPV6L_NODE,
18031 &neighbor_remove_private_as_all_replace_as_cmd);
18032 install_element(BGP_IPV6L_NODE,
18033 &no_neighbor_remove_private_as_all_replace_as_cmd);
18034 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18035 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18036 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18037 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18038 install_element(BGP_VPNV4_NODE,
18039 &neighbor_remove_private_as_replace_as_cmd);
18040 install_element(BGP_VPNV4_NODE,
18041 &no_neighbor_remove_private_as_replace_as_cmd);
18042 install_element(BGP_VPNV4_NODE,
18043 &neighbor_remove_private_as_all_replace_as_cmd);
18044 install_element(BGP_VPNV4_NODE,
18045 &no_neighbor_remove_private_as_all_replace_as_cmd);
18046 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18047 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18048 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18049 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18050 install_element(BGP_VPNV6_NODE,
18051 &neighbor_remove_private_as_replace_as_cmd);
18052 install_element(BGP_VPNV6_NODE,
18053 &no_neighbor_remove_private_as_replace_as_cmd);
18054 install_element(BGP_VPNV6_NODE,
18055 &neighbor_remove_private_as_all_replace_as_cmd);
18056 install_element(BGP_VPNV6_NODE,
18057 &no_neighbor_remove_private_as_all_replace_as_cmd);
18058
18059 /* "neighbor send-community" commands.*/
18060 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18061 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18062 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18063 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18064 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18065 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18066 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18067 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18068 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18069 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18070 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18071 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18072 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18073 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18074 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18075 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18076 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18077 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18078 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18079 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18080 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18081 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18082 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18083 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18084 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18085 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18086 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18087 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18088 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18089 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18090 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18091 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18092 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18093 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18094 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18095 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18096
18097 /* "neighbor route-reflector" commands.*/
18098 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18099 install_element(BGP_NODE,
18100 &no_neighbor_route_reflector_client_hidden_cmd);
18101 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18102 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18103 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18104 install_element(BGP_IPV4M_NODE,
18105 &no_neighbor_route_reflector_client_cmd);
18106 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18107 install_element(BGP_IPV4L_NODE,
18108 &no_neighbor_route_reflector_client_cmd);
18109 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18110 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18111 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18112 install_element(BGP_IPV6M_NODE,
18113 &no_neighbor_route_reflector_client_cmd);
18114 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18115 install_element(BGP_IPV6L_NODE,
18116 &no_neighbor_route_reflector_client_cmd);
18117 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18118 install_element(BGP_VPNV4_NODE,
18119 &no_neighbor_route_reflector_client_cmd);
18120 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18121 install_element(BGP_VPNV6_NODE,
18122 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18123 install_element(BGP_FLOWSPECV4_NODE,
18124 &neighbor_route_reflector_client_cmd);
18125 install_element(BGP_FLOWSPECV4_NODE,
18126 &no_neighbor_route_reflector_client_cmd);
18127 install_element(BGP_FLOWSPECV6_NODE,
18128 &neighbor_route_reflector_client_cmd);
18129 install_element(BGP_FLOWSPECV6_NODE,
18130 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18131 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18132 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18133
18134 /* "neighbor route-server" commands.*/
18135 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18136 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18137 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18138 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18139 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18140 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18141 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18142 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18143 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18144 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18145 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18146 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18147 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18148 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18149 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18150 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18151 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18152 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18153 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18154 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18155 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18156 install_element(BGP_FLOWSPECV4_NODE,
18157 &no_neighbor_route_server_client_cmd);
18158 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18159 install_element(BGP_FLOWSPECV6_NODE,
18160 &no_neighbor_route_server_client_cmd);
d62a17ae 18161
18162 /* "neighbor addpath-tx-all-paths" commands.*/
18163 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18164 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18165 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18166 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18167 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18168 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18169 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18170 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18171 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18172 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18173 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18174 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18175 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18176 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18177 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18178 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18179 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18180 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18181
18182 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18183 install_element(BGP_NODE,
18184 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18185 install_element(BGP_NODE,
18186 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18187 install_element(BGP_IPV4_NODE,
18188 &neighbor_addpath_tx_bestpath_per_as_cmd);
18189 install_element(BGP_IPV4_NODE,
18190 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18191 install_element(BGP_IPV4M_NODE,
18192 &neighbor_addpath_tx_bestpath_per_as_cmd);
18193 install_element(BGP_IPV4M_NODE,
18194 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18195 install_element(BGP_IPV4L_NODE,
18196 &neighbor_addpath_tx_bestpath_per_as_cmd);
18197 install_element(BGP_IPV4L_NODE,
18198 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18199 install_element(BGP_IPV6_NODE,
18200 &neighbor_addpath_tx_bestpath_per_as_cmd);
18201 install_element(BGP_IPV6_NODE,
18202 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18203 install_element(BGP_IPV6M_NODE,
18204 &neighbor_addpath_tx_bestpath_per_as_cmd);
18205 install_element(BGP_IPV6M_NODE,
18206 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18207 install_element(BGP_IPV6L_NODE,
18208 &neighbor_addpath_tx_bestpath_per_as_cmd);
18209 install_element(BGP_IPV6L_NODE,
18210 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18211 install_element(BGP_VPNV4_NODE,
18212 &neighbor_addpath_tx_bestpath_per_as_cmd);
18213 install_element(BGP_VPNV4_NODE,
18214 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18215 install_element(BGP_VPNV6_NODE,
18216 &neighbor_addpath_tx_bestpath_per_as_cmd);
18217 install_element(BGP_VPNV6_NODE,
18218 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18219
2b31007c
RZ
18220 /* "neighbor sender-as-path-loop-detection" commands. */
18221 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18222 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18223
d62a17ae 18224 /* "neighbor passive" commands. */
18225 install_element(BGP_NODE, &neighbor_passive_cmd);
18226 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18227
18228
18229 /* "neighbor shutdown" commands. */
18230 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18231 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18232 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18233 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18234 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18235 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18236
18237 /* "neighbor capability extended-nexthop" commands.*/
18238 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18239 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18240
18241 /* "neighbor capability orf prefix-list" commands.*/
18242 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18243 install_element(BGP_NODE,
18244 &no_neighbor_capability_orf_prefix_hidden_cmd);
18245 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18246 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18247 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18248 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18249 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18250 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18251 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18252 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18253 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18254 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18255 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18256 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18257
18258 /* "neighbor capability dynamic" commands.*/
18259 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18260 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18261
18262 /* "neighbor dont-capability-negotiate" commands. */
18263 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18264 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18265
18266 /* "neighbor ebgp-multihop" commands. */
18267 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18268 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18269 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18270
18271 /* "neighbor disable-connected-check" commands. */
18272 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18273 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18274
47cbc09b
PM
18275 /* "neighbor enforce-first-as" commands. */
18276 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18277 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18278
d62a17ae 18279 /* "neighbor description" commands. */
18280 install_element(BGP_NODE, &neighbor_description_cmd);
18281 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18282 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18283
18284 /* "neighbor update-source" commands. "*/
18285 install_element(BGP_NODE, &neighbor_update_source_cmd);
18286 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18287
18288 /* "neighbor default-originate" commands. */
18289 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18290 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18291 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18292 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18293 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18294 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18295 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18296 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18297 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18298 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18299 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18300 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18301 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18302 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18303 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18304 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18305 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18306 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18307 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18308 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18309 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18310
18311 /* "neighbor port" commands. */
18312 install_element(BGP_NODE, &neighbor_port_cmd);
18313 install_element(BGP_NODE, &no_neighbor_port_cmd);
18314
18315 /* "neighbor weight" commands. */
18316 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18317 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18318
18319 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18320 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18321 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18322 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18323 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18324 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18325 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18326 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18327 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18328 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18329 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18330 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18331 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18332 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18333 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18334 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18335
18336 /* "neighbor override-capability" commands. */
18337 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18338 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18339
18340 /* "neighbor strict-capability-match" commands. */
18341 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18342 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18343
18344 /* "neighbor timers" commands. */
18345 install_element(BGP_NODE, &neighbor_timers_cmd);
18346 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18347
18348 /* "neighbor timers connect" commands. */
18349 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18350 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18351
d43114f3
DS
18352 /* "neighbor timers delayopen" commands. */
18353 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18354 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18355
d62a17ae 18356 /* "neighbor advertisement-interval" commands. */
18357 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18358 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18359
18360 /* "neighbor interface" commands. */
18361 install_element(BGP_NODE, &neighbor_interface_cmd);
18362 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18363
18364 /* "neighbor distribute" commands. */
18365 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18366 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18367 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18368 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18369 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18370 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18371 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18372 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18373 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18374 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18375 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18376 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18377 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18378 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18379 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18380 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18381 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18382 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18383
18384 /* "neighbor prefix-list" commands. */
18385 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18386 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18387 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18388 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18389 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18390 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18391 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18392 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18393 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18394 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18395 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18396 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18397 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18398 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18399 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18400 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18401 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18402 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18403 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18404 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18405 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18406 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18407
18408 /* "neighbor filter-list" commands. */
18409 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18410 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18411 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18412 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18413 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18414 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18415 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18416 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18417 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18418 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18419 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18420 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18421 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18422 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18423 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18424 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18425 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18426 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18427 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18428 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18429 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18430 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18431
18432 /* "neighbor route-map" commands. */
18433 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18434 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18435 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18436 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18437 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18438 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18439 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18440 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18441 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18442 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18443 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18444 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18445 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18446 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18447 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18448 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18449 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18450 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18451 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18452 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18453 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18454 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
18455 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18456 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18457
18458 /* "neighbor unsuppress-map" commands. */
18459 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18460 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18461 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18462 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18463 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18464 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18465 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18466 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18467 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18468 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18469 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18470 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18471 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18472 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18473 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18474 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18475 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18476 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18477
7f7940e6
MK
18478 /* "neighbor advertise-map" commands. */
18479 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18480 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18481 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18482 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18483 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18484 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18485 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18486 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18487 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18488
fde246e8
DA
18489 /* neighbor maximum-prefix-out commands. */
18490 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18491 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18492 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18493 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18494 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18495 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18496 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18497 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18498 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18499 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18500 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18501 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18502 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18503 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18504 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18505 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18506 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18507 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18508
d62a17ae 18509 /* "neighbor maximum-prefix" commands. */
18510 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18511 install_element(BGP_NODE,
18512 &neighbor_maximum_prefix_threshold_hidden_cmd);
18513 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18514 install_element(BGP_NODE,
18515 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18516 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18517 install_element(BGP_NODE,
18518 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18519 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18520 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18521 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18522 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18523 install_element(BGP_IPV4_NODE,
18524 &neighbor_maximum_prefix_threshold_warning_cmd);
18525 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18526 install_element(BGP_IPV4_NODE,
18527 &neighbor_maximum_prefix_threshold_restart_cmd);
18528 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18529 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18530 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18531 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18532 install_element(BGP_IPV4M_NODE,
18533 &neighbor_maximum_prefix_threshold_warning_cmd);
18534 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18535 install_element(BGP_IPV4M_NODE,
18536 &neighbor_maximum_prefix_threshold_restart_cmd);
18537 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18538 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18539 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18540 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18541 install_element(BGP_IPV4L_NODE,
18542 &neighbor_maximum_prefix_threshold_warning_cmd);
18543 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18544 install_element(BGP_IPV4L_NODE,
18545 &neighbor_maximum_prefix_threshold_restart_cmd);
18546 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18547 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18548 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18549 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18550 install_element(BGP_IPV6_NODE,
18551 &neighbor_maximum_prefix_threshold_warning_cmd);
18552 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18553 install_element(BGP_IPV6_NODE,
18554 &neighbor_maximum_prefix_threshold_restart_cmd);
18555 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18556 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18557 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18558 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18559 install_element(BGP_IPV6M_NODE,
18560 &neighbor_maximum_prefix_threshold_warning_cmd);
18561 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18562 install_element(BGP_IPV6M_NODE,
18563 &neighbor_maximum_prefix_threshold_restart_cmd);
18564 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18565 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18566 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18567 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18568 install_element(BGP_IPV6L_NODE,
18569 &neighbor_maximum_prefix_threshold_warning_cmd);
18570 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18571 install_element(BGP_IPV6L_NODE,
18572 &neighbor_maximum_prefix_threshold_restart_cmd);
18573 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18574 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18575 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18576 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18577 install_element(BGP_VPNV4_NODE,
18578 &neighbor_maximum_prefix_threshold_warning_cmd);
18579 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18580 install_element(BGP_VPNV4_NODE,
18581 &neighbor_maximum_prefix_threshold_restart_cmd);
18582 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18583 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18584 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18585 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18586 install_element(BGP_VPNV6_NODE,
18587 &neighbor_maximum_prefix_threshold_warning_cmd);
18588 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18589 install_element(BGP_VPNV6_NODE,
18590 &neighbor_maximum_prefix_threshold_restart_cmd);
18591 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18592
18593 /* "neighbor allowas-in" */
18594 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18595 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18596 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18597 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18598 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18599 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18600 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18601 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18602 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18603 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18604 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18605 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18606 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18607 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18608 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18609 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18610 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18611 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18612 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18613 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18614
18615 /* address-family commands. */
18616 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18617 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18618#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18619 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18620 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18621#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18622
d62a17ae 18623 install_element(BGP_NODE, &address_family_evpn_cmd);
18624
18625 /* "exit-address-family" command. */
18626 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18627 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18628 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18629 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18630 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18631 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18632 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18633 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18634 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18635 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18636 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18637
18638 /* "clear ip bgp commands" */
18639 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18640
18641 /* clear ip bgp prefix */
18642 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18643 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18644 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18645
18646 /* "show [ip] bgp summary" commands. */
18647 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18648 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18649 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18650 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18651 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18652 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18653 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18654
18655 /* "show [ip] bgp neighbors" commands. */
18656 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18657
36235319 18658 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18659
d62a17ae 18660 /* "show [ip] bgp peer-group" commands. */
18661 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18662
18663 /* "show [ip] bgp paths" commands. */
18664 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18665
18666 /* "show [ip] bgp community" commands. */
18667 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18668
18669 /* "show ip bgp large-community" commands. */
18670 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18671 /* "show [ip] bgp attribute-info" commands. */
18672 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18673 /* "show [ip] bgp route-leak" command */
18674 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18675
18676 /* "redistribute" commands. */
18677 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18678 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18679 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18680 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18681 install_element(BGP_NODE,
18682 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18683 install_element(BGP_NODE,
18684 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18685 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18686 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18687 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18688 install_element(BGP_NODE,
18689 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18690 install_element(BGP_NODE,
18691 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18692 install_element(BGP_NODE,
18693 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18694 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18695 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18696 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18697 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18698 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18699 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18700 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18701 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18702 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18703 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18704 install_element(BGP_IPV4_NODE,
18705 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18706 install_element(BGP_IPV4_NODE,
18707 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18708 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18709 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18710 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18711 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18712 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18713 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18714
b9c7bc5a
PZ
18715 /* import|export vpn [route-map WORD] */
18716 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18717 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18718
12a844a5
DS
18719 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18720 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18721
d62a17ae 18722 /* ttl_security commands */
18723 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18724 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18725
18726 /* "show [ip] bgp memory" commands. */
18727 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18728
acf71666
MK
18729 /* "show bgp martian next-hop" */
18730 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18731
48ecf8f5
DS
18732 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18733
d62a17ae 18734 /* "show [ip] bgp views" commands. */
18735 install_element(VIEW_NODE, &show_bgp_views_cmd);
18736
18737 /* "show [ip] bgp vrfs" commands. */
18738 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18739
18740 /* Community-list. */
18741 community_list_vty();
ddb5b488
PZ
18742
18743 /* vpn-policy commands */
b9c7bc5a
PZ
18744 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18745 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18746 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18747 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18748 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18749 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18750 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18751 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18752 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18753 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18754 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18755 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18756
301ad80a
PG
18757 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18758 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18759
b9c7bc5a
PZ
18760 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18761 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18762 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18763 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18764 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18765 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18766 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18767 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
18768 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18769 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 18770}
6b0655a2 18771
718e3744 18772#include "memory.h"
18773#include "bgp_regex.h"
18774#include "bgp_clist.h"
18775#include "bgp_ecommunity.h"
18776
18777/* VTY functions. */
18778
18779/* Direction value to string conversion. */
d62a17ae 18780static const char *community_direct_str(int direct)
18781{
18782 switch (direct) {
18783 case COMMUNITY_DENY:
18784 return "deny";
18785 case COMMUNITY_PERMIT:
18786 return "permit";
18787 default:
18788 return "unknown";
18789 }
718e3744 18790}
18791
18792/* Display error string. */
d62a17ae 18793static void community_list_perror(struct vty *vty, int ret)
18794{
18795 switch (ret) {
18796 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18797 vty_out(vty, "%% Can't find community-list\n");
18798 break;
18799 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
18800 vty_out(vty, "%% Malformed community-list value\n");
18801 break;
18802 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
18803 vty_out(vty,
18804 "%% Community name conflict, previously defined as standard community\n");
18805 break;
18806 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
18807 vty_out(vty,
18808 "%% Community name conflict, previously defined as expanded community\n");
18809 break;
18810 }
718e3744 18811}
18812
5bf15956
DW
18813/* "community-list" keyword help string. */
18814#define COMMUNITY_LIST_STR "Add a community list entry\n"
18815
7336e101
SP
18816/*community-list standard */
18817DEFUN (community_list_standard,
18818 bgp_community_list_standard_cmd,
2f8cc0e5 18819 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 18820 BGP_STR
718e3744 18821 COMMUNITY_LIST_STR
18822 "Community list number (standard)\n"
5bf15956 18823 "Add an standard community-list entry\n"
718e3744 18824 "Community list name\n"
2f8cc0e5
DA
18825 "Sequence number of an entry\n"
18826 "Sequence number\n"
718e3744 18827 "Specify community to reject\n"
18828 "Specify community to accept\n"
18829 COMMUNITY_VAL_STR)
18830{
d62a17ae 18831 char *cl_name_or_number = NULL;
2f8cc0e5 18832 char *seq = NULL;
d62a17ae 18833 int direct = 0;
18834 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 18835 int idx = 0;
7336e101 18836
2f8cc0e5
DA
18837 argv_find(argv, argc, "(1-4294967295)", &idx);
18838 if (idx)
18839 seq = argv[idx]->arg;
18840
18841 idx = 0;
d62a17ae 18842 argv_find(argv, argc, "(1-99)", &idx);
18843 argv_find(argv, argc, "WORD", &idx);
18844 cl_name_or_number = argv[idx]->arg;
18845 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18846 : COMMUNITY_DENY;
18847 argv_find(argv, argc, "AA:NN", &idx);
18848 char *str = argv_concat(argv, argc, idx);
42f914d4 18849
2f8cc0e5
DA
18850 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18851 direct, style);
42f914d4 18852
d62a17ae 18853 XFREE(MTYPE_TMP, str);
42f914d4 18854
d62a17ae 18855 if (ret < 0) {
18856 /* Display error string. */
18857 community_list_perror(vty, ret);
18858 return CMD_WARNING_CONFIG_FAILED;
18859 }
42f914d4 18860
d62a17ae 18861 return CMD_SUCCESS;
718e3744 18862}
18863
7336e101
SP
18864DEFUN (no_community_list_standard_all,
18865 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 18866 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18867 NO_STR
18868 BGP_STR
18869 COMMUNITY_LIST_STR
18870 "Community list number (standard)\n"
18871 "Add an standard community-list entry\n"
18872 "Community list name\n"
2f8cc0e5
DA
18873 "Sequence number of an entry\n"
18874 "Sequence number\n"
7336e101
SP
18875 "Specify community to reject\n"
18876 "Specify community to accept\n"
18877 COMMUNITY_VAL_STR)
718e3744 18878{
d62a17ae 18879 char *cl_name_or_number = NULL;
174b5cb9 18880 char *str = NULL;
d62a17ae 18881 int direct = 0;
18882 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 18883 char *seq = NULL;
d62a17ae 18884 int idx = 0;
7336e101 18885
2f8cc0e5
DA
18886 argv_find(argv, argc, "(1-4294967295)", &idx);
18887 if (idx)
18888 seq = argv[idx]->arg;
18889
18890 idx = 0;
174b5cb9
DA
18891 argv_find(argv, argc, "permit", &idx);
18892 argv_find(argv, argc, "deny", &idx);
18893
18894 if (idx) {
18895 direct = argv_find(argv, argc, "permit", &idx)
18896 ? COMMUNITY_PERMIT
18897 : COMMUNITY_DENY;
18898
18899 idx = 0;
18900 argv_find(argv, argc, "AA:NN", &idx);
18901 str = argv_concat(argv, argc, idx);
18902 }
18903
18904 idx = 0;
d62a17ae 18905 argv_find(argv, argc, "(1-99)", &idx);
18906 argv_find(argv, argc, "WORD", &idx);
18907 cl_name_or_number = argv[idx]->arg;
42f914d4 18908
2f8cc0e5 18909 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 18910 direct, style);
42f914d4 18911
d62a17ae 18912 XFREE(MTYPE_TMP, str);
daf9ddbb 18913
d62a17ae 18914 if (ret < 0) {
18915 community_list_perror(vty, ret);
18916 return CMD_WARNING_CONFIG_FAILED;
18917 }
42f914d4 18918
d62a17ae 18919 return CMD_SUCCESS;
718e3744 18920}
7336e101 18921
174b5cb9
DA
18922ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
18923 "no bgp community-list <(1-99)|standard WORD>",
18924 NO_STR BGP_STR COMMUNITY_LIST_STR
18925 "Community list number (standard)\n"
18926 "Add an standard community-list entry\n"
18927 "Community list name\n")
18928
7336e101
SP
18929/*community-list expanded */
18930DEFUN (community_list_expanded_all,
18931 bgp_community_list_expanded_all_cmd,
2f8cc0e5 18932 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18933 BGP_STR
18934 COMMUNITY_LIST_STR
718e3744 18935 "Community list number (expanded)\n"
5bf15956 18936 "Add an expanded community-list entry\n"
718e3744 18937 "Community list name\n"
2f8cc0e5
DA
18938 "Sequence number of an entry\n"
18939 "Sequence number\n"
718e3744 18940 "Specify community to reject\n"
18941 "Specify community to accept\n"
18942 COMMUNITY_VAL_STR)
18943{
d62a17ae 18944 char *cl_name_or_number = NULL;
2f8cc0e5 18945 char *seq = NULL;
d62a17ae 18946 int direct = 0;
18947 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 18948 int idx = 0;
7b9a4750 18949
2f8cc0e5
DA
18950 argv_find(argv, argc, "(1-4294967295)", &idx);
18951 if (idx)
18952 seq = argv[idx]->arg;
18953
18954 idx = 0;
18955
d62a17ae 18956 argv_find(argv, argc, "(100-500)", &idx);
18957 argv_find(argv, argc, "WORD", &idx);
18958 cl_name_or_number = argv[idx]->arg;
18959 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18960 : COMMUNITY_DENY;
18961 argv_find(argv, argc, "AA:NN", &idx);
18962 char *str = argv_concat(argv, argc, idx);
42f914d4 18963
2f8cc0e5
DA
18964 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18965 direct, style);
42f914d4 18966
d62a17ae 18967 XFREE(MTYPE_TMP, str);
42f914d4 18968
d62a17ae 18969 if (ret < 0) {
18970 /* Display error string. */
18971 community_list_perror(vty, ret);
18972 return CMD_WARNING_CONFIG_FAILED;
18973 }
42f914d4 18974
d62a17ae 18975 return CMD_SUCCESS;
718e3744 18976}
18977
7336e101
SP
18978DEFUN (no_community_list_expanded_all,
18979 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 18980 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18981 NO_STR
18982 BGP_STR
18983 COMMUNITY_LIST_STR
18984 "Community list number (expanded)\n"
18985 "Add an expanded community-list entry\n"
18986 "Community list name\n"
2f8cc0e5
DA
18987 "Sequence number of an entry\n"
18988 "Sequence number\n"
7336e101
SP
18989 "Specify community to reject\n"
18990 "Specify community to accept\n"
18991 COMMUNITY_VAL_STR)
718e3744 18992{
d62a17ae 18993 char *cl_name_or_number = NULL;
2f8cc0e5 18994 char *seq = NULL;
174b5cb9 18995 char *str = NULL;
d62a17ae 18996 int direct = 0;
18997 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 18998 int idx = 0;
174b5cb9 18999
2f8cc0e5
DA
19000 argv_find(argv, argc, "(1-4294967295)", &idx);
19001 if (idx)
19002 seq = argv[idx]->arg;
19003
19004 idx = 0;
174b5cb9
DA
19005 argv_find(argv, argc, "permit", &idx);
19006 argv_find(argv, argc, "deny", &idx);
19007
19008 if (idx) {
19009 direct = argv_find(argv, argc, "permit", &idx)
19010 ? COMMUNITY_PERMIT
19011 : COMMUNITY_DENY;
19012
19013 idx = 0;
19014 argv_find(argv, argc, "AA:NN", &idx);
19015 str = argv_concat(argv, argc, idx);
7336e101 19016 }
174b5cb9
DA
19017
19018 idx = 0;
d62a17ae 19019 argv_find(argv, argc, "(100-500)", &idx);
19020 argv_find(argv, argc, "WORD", &idx);
19021 cl_name_or_number = argv[idx]->arg;
42f914d4 19022
2f8cc0e5 19023 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19024 direct, style);
42f914d4 19025
d62a17ae 19026 XFREE(MTYPE_TMP, str);
daf9ddbb 19027
d62a17ae 19028 if (ret < 0) {
19029 community_list_perror(vty, ret);
19030 return CMD_WARNING_CONFIG_FAILED;
19031 }
42f914d4 19032
d62a17ae 19033 return CMD_SUCCESS;
718e3744 19034}
19035
36d4bb44
EB
19036ALIAS(no_community_list_expanded_all,
19037 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 19038 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 19039 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19040 "Community list number (expanded)\n"
19041 "Add an expanded community-list entry\n"
19042 "Community list name\n")
19043
8d9b8ed9
PM
19044/* Return configuration string of community-list entry. */
19045static const char *community_list_config_str(struct community_entry *entry)
19046{
19047 const char *str;
19048
19049 if (entry->any)
19050 str = "";
19051 else {
19052 if (entry->style == COMMUNITY_LIST_STANDARD)
19053 str = community_str(entry->u.com, false);
19054 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19055 str = lcommunity_str(entry->u.lcom, false);
19056 else
19057 str = entry->config;
19058 }
19059 return str;
19060}
19061
d62a17ae 19062static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19063{
d62a17ae 19064 struct community_entry *entry;
718e3744 19065
d62a17ae 19066 for (entry = list->head; entry; entry = entry->next) {
19067 if (entry == list->head) {
19068 if (all_digit(list->name))
19069 vty_out(vty, "Community %s list %s\n",
19070 entry->style == COMMUNITY_LIST_STANDARD
19071 ? "standard"
19072 : "(expanded) access",
19073 list->name);
19074 else
19075 vty_out(vty, "Named Community %s list %s\n",
19076 entry->style == COMMUNITY_LIST_STANDARD
19077 ? "standard"
19078 : "expanded",
19079 list->name);
19080 }
19081 if (entry->any)
19082 vty_out(vty, " %s\n",
19083 community_direct_str(entry->direct));
19084 else
19085 vty_out(vty, " %s %s\n",
19086 community_direct_str(entry->direct),
8d9b8ed9 19087 community_list_config_str(entry));
d62a17ae 19088 }
718e3744 19089}
19090
7336e101
SP
19091DEFUN (show_community_list,
19092 show_bgp_community_list_cmd,
19093 "show bgp community-list",
718e3744 19094 SHOW_STR
7336e101 19095 BGP_STR
718e3744 19096 "List community-list\n")
19097{
d62a17ae 19098 struct community_list *list;
19099 struct community_list_master *cm;
718e3744 19100
d62a17ae 19101 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19102 if (!cm)
19103 return CMD_SUCCESS;
718e3744 19104
d62a17ae 19105 for (list = cm->num.head; list; list = list->next)
19106 community_list_show(vty, list);
718e3744 19107
d62a17ae 19108 for (list = cm->str.head; list; list = list->next)
19109 community_list_show(vty, list);
718e3744 19110
d62a17ae 19111 return CMD_SUCCESS;
718e3744 19112}
19113
7336e101
SP
19114DEFUN (show_community_list_arg,
19115 show_bgp_community_list_arg_cmd,
960b69b9 19116 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
19117 SHOW_STR
19118 BGP_STR
718e3744 19119 "List community-list\n"
19120 "Community-list number\n"
960b69b9 19121 "Community-list name\n"
19122 "Detailed information on community-list\n")
718e3744 19123{
d62a17ae 19124 int idx_comm_list = 3;
19125 struct community_list *list;
718e3744 19126
e237b0d2 19127 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19128 COMMUNITY_LIST_MASTER);
19129 if (!list) {
19130 vty_out(vty, "%% Can't find community-list\n");
19131 return CMD_WARNING;
19132 }
718e3744 19133
d62a17ae 19134 community_list_show(vty, list);
718e3744 19135
d62a17ae 19136 return CMD_SUCCESS;
718e3744 19137}
6b0655a2 19138
57d187bc
JS
19139/*
19140 * Large Community code.
19141 */
d62a17ae 19142static int lcommunity_list_set_vty(struct vty *vty, int argc,
19143 struct cmd_token **argv, int style,
19144 int reject_all_digit_name)
19145{
19146 int ret;
19147 int direct;
19148 char *str;
19149 int idx = 0;
19150 char *cl_name;
2f8cc0e5
DA
19151 char *seq = NULL;
19152
947073e3 19153 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 19154 seq = argv[idx]->arg;
d62a17ae 19155
2f8cc0e5 19156 idx = 0;
d62a17ae 19157 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19158 : COMMUNITY_DENY;
19159
19160 /* All digit name check. */
19161 idx = 0;
19162 argv_find(argv, argc, "WORD", &idx);
19163 argv_find(argv, argc, "(1-99)", &idx);
19164 argv_find(argv, argc, "(100-500)", &idx);
19165 cl_name = argv[idx]->arg;
19166 if (reject_all_digit_name && all_digit(cl_name)) {
19167 vty_out(vty, "%% Community name cannot have all digits\n");
19168 return CMD_WARNING_CONFIG_FAILED;
19169 }
19170
19171 idx = 0;
19172 argv_find(argv, argc, "AA:BB:CC", &idx);
19173 argv_find(argv, argc, "LINE", &idx);
19174 /* Concat community string argument. */
19175 if (idx)
19176 str = argv_concat(argv, argc, idx);
19177 else
19178 str = NULL;
19179
2f8cc0e5 19180 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19181
19182 /* Free temporary community list string allocated by
19183 argv_concat(). */
0a22ddfb 19184 XFREE(MTYPE_TMP, str);
d62a17ae 19185
19186 if (ret < 0) {
19187 community_list_perror(vty, ret);
19188 return CMD_WARNING_CONFIG_FAILED;
19189 }
19190 return CMD_SUCCESS;
19191}
19192
19193static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19194 struct cmd_token **argv, int style)
19195{
19196 int ret;
19197 int direct = 0;
19198 char *str = NULL;
19199 int idx = 0;
2f8cc0e5 19200 char *seq = NULL;
d62a17ae 19201
947073e3 19202 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 19203 seq = argv[idx]->arg;
d62a17ae 19204
2f8cc0e5 19205 idx = 0;
d62a17ae 19206 argv_find(argv, argc, "permit", &idx);
19207 argv_find(argv, argc, "deny", &idx);
19208
19209 if (idx) {
19210 /* Check the list direct. */
19211 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19212 direct = COMMUNITY_PERMIT;
19213 else
19214 direct = COMMUNITY_DENY;
19215
19216 idx = 0;
19217 argv_find(argv, argc, "LINE", &idx);
19218 argv_find(argv, argc, "AA:AA:NN", &idx);
19219 /* Concat community string argument. */
19220 str = argv_concat(argv, argc, idx);
19221 }
19222
19223 idx = 0;
19224 argv_find(argv, argc, "(1-99)", &idx);
19225 argv_find(argv, argc, "(100-500)", &idx);
19226 argv_find(argv, argc, "WORD", &idx);
19227
19228 /* Unset community list. */
2f8cc0e5 19229 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19230 style);
19231
19232 /* Free temporary community list string allocated by
19233 argv_concat(). */
0a22ddfb 19234 XFREE(MTYPE_TMP, str);
d62a17ae 19235
19236 if (ret < 0) {
19237 community_list_perror(vty, ret);
19238 return CMD_WARNING_CONFIG_FAILED;
19239 }
19240
19241 return CMD_SUCCESS;
57d187bc
JS
19242}
19243
19244/* "large-community-list" keyword help string. */
19245#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19246#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19247
7336e101
SP
19248DEFUN (lcommunity_list_standard,
19249 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 19250 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19251 BGP_STR
19252 LCOMMUNITY_LIST_STR
19253 "Large Community list number (standard)\n"
2f8cc0e5
DA
19254 "Sequence number of an entry\n"
19255 "Sequence number\n"
7336e101
SP
19256 "Specify large community to reject\n"
19257 "Specify large community to accept\n"
19258 LCOMMUNITY_VAL_STR)
52951b63 19259{
d62a17ae 19260 return lcommunity_list_set_vty(vty, argc, argv,
19261 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19262}
19263
7336e101
SP
19264DEFUN (lcommunity_list_expanded,
19265 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 19266 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19267 BGP_STR
19268 LCOMMUNITY_LIST_STR
19269 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19270 "Sequence number of an entry\n"
19271 "Sequence number\n"
7336e101
SP
19272 "Specify large community to reject\n"
19273 "Specify large community to accept\n"
19274 "An ordered list as a regular-expression\n")
57d187bc 19275{
d62a17ae 19276 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19277 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19278}
19279
7336e101
SP
19280DEFUN (lcommunity_list_name_standard,
19281 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 19282 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19283 BGP_STR
19284 LCOMMUNITY_LIST_STR
19285 "Specify standard large-community-list\n"
19286 "Large Community list name\n"
2f8cc0e5
DA
19287 "Sequence number of an entry\n"
19288 "Sequence number\n"
7336e101
SP
19289 "Specify large community to reject\n"
19290 "Specify large community to accept\n"
19291 LCOMMUNITY_VAL_STR)
52951b63 19292{
d62a17ae 19293 return lcommunity_list_set_vty(vty, argc, argv,
19294 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19295}
19296
7336e101
SP
19297DEFUN (lcommunity_list_name_expanded,
19298 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 19299 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19300 BGP_STR
19301 LCOMMUNITY_LIST_STR
19302 "Specify expanded large-community-list\n"
19303 "Large Community list name\n"
2f8cc0e5
DA
19304 "Sequence number of an entry\n"
19305 "Sequence number\n"
7336e101
SP
19306 "Specify large community to reject\n"
19307 "Specify large community to accept\n"
19308 "An ordered list as a regular-expression\n")
57d187bc 19309{
d62a17ae 19310 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19311 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19312}
19313
4378f57c
DA
19314DEFUN (no_lcommunity_list_all,
19315 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
19316 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19317 NO_STR
19318 BGP_STR
19319 LCOMMUNITY_LIST_STR
19320 "Large Community list number (standard)\n"
19321 "Large Community list number (expanded)\n"
19322 "Large Community list name\n")
57d187bc 19323{
7336e101
SP
19324 return lcommunity_list_unset_vty(vty, argc, argv,
19325 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19326}
19327
4378f57c
DA
19328DEFUN (no_lcommunity_list_name_standard_all,
19329 no_bgp_lcommunity_list_name_standard_all_cmd,
19330 "no bgp large-community-list standard WORD",
19331 NO_STR
19332 BGP_STR
19333 LCOMMUNITY_LIST_STR
19334 "Specify standard large-community-list\n"
19335 "Large Community list name\n")
19336{
19337 return lcommunity_list_unset_vty(vty, argc, argv,
19338 LARGE_COMMUNITY_LIST_STANDARD);
19339}
19340
7336e101
SP
19341DEFUN (no_lcommunity_list_name_expanded_all,
19342 no_bgp_lcommunity_list_name_expanded_all_cmd,
19343 "no bgp large-community-list expanded WORD",
19344 NO_STR
19345 BGP_STR
19346 LCOMMUNITY_LIST_STR
19347 "Specify expanded large-community-list\n"
19348 "Large Community list name\n")
57d187bc 19349{
d62a17ae 19350 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19351 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19352}
19353
7336e101
SP
19354DEFUN (no_lcommunity_list_standard,
19355 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 19356 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19357 NO_STR
19358 BGP_STR
19359 LCOMMUNITY_LIST_STR
19360 "Large Community list number (standard)\n"
2f8cc0e5
DA
19361 "Sequence number of an entry\n"
19362 "Sequence number\n"
7336e101
SP
19363 "Specify large community to reject\n"
19364 "Specify large community to accept\n"
19365 LCOMMUNITY_VAL_STR)
57d187bc 19366{
d62a17ae 19367 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19368 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19369}
19370
7336e101
SP
19371DEFUN (no_lcommunity_list_expanded,
19372 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 19373 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19374 NO_STR
19375 BGP_STR
19376 LCOMMUNITY_LIST_STR
19377 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19378 "Sequence number of an entry\n"
19379 "Sequence number\n"
7336e101
SP
19380 "Specify large community to reject\n"
19381 "Specify large community to accept\n"
19382 "An ordered list as a regular-expression\n")
57d187bc 19383{
d62a17ae 19384 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19385 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19386}
19387
7336e101
SP
19388DEFUN (no_lcommunity_list_name_standard,
19389 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 19390 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19391 NO_STR
19392 BGP_STR
19393 LCOMMUNITY_LIST_STR
19394 "Specify standard large-community-list\n"
19395 "Large Community list name\n"
2f8cc0e5
DA
19396 "Sequence number of an entry\n"
19397 "Sequence number\n"
7336e101
SP
19398 "Specify large community to reject\n"
19399 "Specify large community to accept\n"
19400 LCOMMUNITY_VAL_STR)
57d187bc 19401{
d62a17ae 19402 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19403 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19404}
19405
7336e101
SP
19406DEFUN (no_lcommunity_list_name_expanded,
19407 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 19408 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19409 NO_STR
19410 BGP_STR
19411 LCOMMUNITY_LIST_STR
19412 "Specify expanded large-community-list\n"
19413 "Large community list name\n"
2f8cc0e5
DA
19414 "Sequence number of an entry\n"
19415 "Sequence number\n"
7336e101
SP
19416 "Specify large community to reject\n"
19417 "Specify large community to accept\n"
19418 "An ordered list as a regular-expression\n")
57d187bc 19419{
d62a17ae 19420 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19421 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19422}
19423
d62a17ae 19424static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19425{
19426 struct community_entry *entry;
19427
19428 for (entry = list->head; entry; entry = entry->next) {
19429 if (entry == list->head) {
19430 if (all_digit(list->name))
19431 vty_out(vty, "Large community %s list %s\n",
169b72c8 19432 entry->style ==
19433 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19434 ? "standard"
19435 : "(expanded) access",
19436 list->name);
19437 else
19438 vty_out(vty,
19439 "Named large community %s list %s\n",
169b72c8 19440 entry->style ==
19441 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19442 ? "standard"
19443 : "expanded",
19444 list->name);
19445 }
19446 if (entry->any)
19447 vty_out(vty, " %s\n",
19448 community_direct_str(entry->direct));
19449 else
19450 vty_out(vty, " %s %s\n",
19451 community_direct_str(entry->direct),
8d9b8ed9 19452 community_list_config_str(entry));
d62a17ae 19453 }
57d187bc
JS
19454}
19455
7336e101
SP
19456DEFUN (show_lcommunity_list,
19457 show_bgp_lcommunity_list_cmd,
19458 "show bgp large-community-list",
57d187bc 19459 SHOW_STR
7336e101 19460 BGP_STR
57d187bc
JS
19461 "List large-community list\n")
19462{
d62a17ae 19463 struct community_list *list;
19464 struct community_list_master *cm;
57d187bc 19465
d62a17ae 19466 cm = community_list_master_lookup(bgp_clist,
19467 LARGE_COMMUNITY_LIST_MASTER);
19468 if (!cm)
19469 return CMD_SUCCESS;
57d187bc 19470
d62a17ae 19471 for (list = cm->num.head; list; list = list->next)
19472 lcommunity_list_show(vty, list);
57d187bc 19473
d62a17ae 19474 for (list = cm->str.head; list; list = list->next)
19475 lcommunity_list_show(vty, list);
57d187bc 19476
d62a17ae 19477 return CMD_SUCCESS;
57d187bc
JS
19478}
19479
7336e101
SP
19480DEFUN (show_lcommunity_list_arg,
19481 show_bgp_lcommunity_list_arg_cmd,
960b69b9 19482 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
19483 SHOW_STR
19484 BGP_STR
57d187bc 19485 "List large-community list\n"
960b69b9 19486 "Large-community-list number\n"
19487 "Large-community-list name\n"
19488 "Detailed information on large-community-list\n")
57d187bc 19489{
d62a17ae 19490 struct community_list *list;
57d187bc 19491
e237b0d2 19492 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19493 LARGE_COMMUNITY_LIST_MASTER);
19494 if (!list) {
960b69b9 19495 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19496 return CMD_WARNING;
19497 }
57d187bc 19498
d62a17ae 19499 lcommunity_list_show(vty, list);
57d187bc 19500
d62a17ae 19501 return CMD_SUCCESS;
57d187bc
JS
19502}
19503
718e3744 19504/* "extcommunity-list" keyword help string. */
19505#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19506#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19507
7336e101
SP
19508DEFUN (extcommunity_list_standard,
19509 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 19510 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 19511 BGP_STR
718e3744 19512 EXTCOMMUNITY_LIST_STR
19513 "Extended Community list number (standard)\n"
718e3744 19514 "Specify standard extcommunity-list\n"
5bf15956 19515 "Community list name\n"
2f8cc0e5
DA
19516 "Sequence number of an entry\n"
19517 "Sequence number\n"
718e3744 19518 "Specify community to reject\n"
19519 "Specify community to accept\n"
19520 EXTCOMMUNITY_VAL_STR)
19521{
d62a17ae 19522 int style = EXTCOMMUNITY_LIST_STANDARD;
19523 int direct = 0;
19524 char *cl_number_or_name = NULL;
2f8cc0e5 19525 char *seq = NULL;
42f914d4 19526
d62a17ae 19527 int idx = 0;
7b9a4750 19528
d62a17ae 19529 argv_find(argv, argc, "(1-99)", &idx);
19530 argv_find(argv, argc, "WORD", &idx);
19531 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19532
409148f6 19533 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19534 seq = argv[idx]->arg;
19535
d62a17ae 19536 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19537 : COMMUNITY_DENY;
19538 argv_find(argv, argc, "AA:NN", &idx);
19539 char *str = argv_concat(argv, argc, idx);
42f914d4 19540
2f8cc0e5 19541 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19542 direct, style);
42f914d4 19543
d62a17ae 19544 XFREE(MTYPE_TMP, str);
42f914d4 19545
d62a17ae 19546 if (ret < 0) {
19547 community_list_perror(vty, ret);
19548 return CMD_WARNING_CONFIG_FAILED;
19549 }
42f914d4 19550
d62a17ae 19551 return CMD_SUCCESS;
718e3744 19552}
19553
7336e101
SP
19554DEFUN (extcommunity_list_name_expanded,
19555 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 19556 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19557 BGP_STR
19558 EXTCOMMUNITY_LIST_STR
5bf15956 19559 "Extended Community list number (expanded)\n"
718e3744 19560 "Specify expanded extcommunity-list\n"
19561 "Extended Community list name\n"
2f8cc0e5
DA
19562 "Sequence number of an entry\n"
19563 "Sequence number\n"
718e3744 19564 "Specify community to reject\n"
19565 "Specify community to accept\n"
19566 "An ordered list as a regular-expression\n")
19567{
d62a17ae 19568 int style = EXTCOMMUNITY_LIST_EXPANDED;
19569 int direct = 0;
19570 char *cl_number_or_name = NULL;
2f8cc0e5 19571 char *seq = NULL;
d62a17ae 19572 int idx = 0;
7336e101 19573
d62a17ae 19574 argv_find(argv, argc, "(100-500)", &idx);
19575 argv_find(argv, argc, "WORD", &idx);
19576 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19577
409148f6 19578 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19579 seq = argv[idx]->arg;
19580
d62a17ae 19581 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19582 : COMMUNITY_DENY;
19583 argv_find(argv, argc, "LINE", &idx);
19584 char *str = argv_concat(argv, argc, idx);
42f914d4 19585
2f8cc0e5 19586 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19587 direct, style);
42f914d4 19588
d62a17ae 19589 XFREE(MTYPE_TMP, str);
42f914d4 19590
d62a17ae 19591 if (ret < 0) {
19592 community_list_perror(vty, ret);
19593 return CMD_WARNING_CONFIG_FAILED;
19594 }
42f914d4 19595
d62a17ae 19596 return CMD_SUCCESS;
718e3744 19597}
19598
7336e101
SP
19599DEFUN (no_extcommunity_list_standard_all,
19600 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 19601 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19602 NO_STR
19603 BGP_STR
19604 EXTCOMMUNITY_LIST_STR
813d4307 19605 "Extended Community list number (standard)\n"
718e3744 19606 "Specify standard extcommunity-list\n"
5bf15956 19607 "Community list name\n"
2f8cc0e5
DA
19608 "Sequence number of an entry\n"
19609 "Sequence number\n"
718e3744 19610 "Specify community to reject\n"
19611 "Specify community to accept\n"
19612 EXTCOMMUNITY_VAL_STR)
19613{
d62a17ae 19614 int style = EXTCOMMUNITY_LIST_STANDARD;
19615 int direct = 0;
19616 char *cl_number_or_name = NULL;
d4455c89 19617 char *str = NULL;
2f8cc0e5 19618 char *seq = NULL;
d62a17ae 19619 int idx = 0;
d4455c89 19620
409148f6 19621 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19622 seq = argv[idx]->arg;
19623
19624 idx = 0;
d4455c89
DA
19625 argv_find(argv, argc, "permit", &idx);
19626 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19627 if (idx) {
19628 direct = argv_find(argv, argc, "permit", &idx)
19629 ? COMMUNITY_PERMIT
19630 : COMMUNITY_DENY;
19631
19632 idx = 0;
19633 argv_find(argv, argc, "AA:NN", &idx);
19634 str = argv_concat(argv, argc, idx);
19635 }
19636
19637 idx = 0;
d62a17ae 19638 argv_find(argv, argc, "(1-99)", &idx);
19639 argv_find(argv, argc, "WORD", &idx);
19640 cl_number_or_name = argv[idx]->arg;
42f914d4 19641
d62a17ae 19642 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19643 seq, direct, style);
42f914d4 19644
d62a17ae 19645 XFREE(MTYPE_TMP, str);
42f914d4 19646
d62a17ae 19647 if (ret < 0) {
19648 community_list_perror(vty, ret);
19649 return CMD_WARNING_CONFIG_FAILED;
19650 }
42f914d4 19651
d62a17ae 19652 return CMD_SUCCESS;
718e3744 19653}
19654
d4455c89
DA
19655ALIAS(no_extcommunity_list_standard_all,
19656 no_bgp_extcommunity_list_standard_all_list_cmd,
19657 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 19658 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19659 "Extended Community list number (standard)\n"
19660 "Specify standard extcommunity-list\n"
19661 "Community list name\n")
19662
7336e101
SP
19663DEFUN (no_extcommunity_list_expanded_all,
19664 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 19665 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19666 NO_STR
19667 BGP_STR
19668 EXTCOMMUNITY_LIST_STR
718e3744 19669 "Extended Community list number (expanded)\n"
718e3744 19670 "Specify expanded extcommunity-list\n"
5bf15956 19671 "Extended Community list name\n"
2f8cc0e5
DA
19672 "Sequence number of an entry\n"
19673 "Sequence number\n"
718e3744 19674 "Specify community to reject\n"
19675 "Specify community to accept\n"
19676 "An ordered list as a regular-expression\n")
19677{
d62a17ae 19678 int style = EXTCOMMUNITY_LIST_EXPANDED;
19679 int direct = 0;
19680 char *cl_number_or_name = NULL;
d4455c89 19681 char *str = NULL;
2f8cc0e5 19682 char *seq = NULL;
d62a17ae 19683 int idx = 0;
d4455c89 19684
409148f6 19685 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19686 seq = argv[idx]->arg;
19687
19688 idx = 0;
d4455c89
DA
19689 argv_find(argv, argc, "permit", &idx);
19690 argv_find(argv, argc, "deny", &idx);
19691
19692 if (idx) {
19693 direct = argv_find(argv, argc, "permit", &idx)
19694 ? COMMUNITY_PERMIT
19695 : COMMUNITY_DENY;
19696
19697 idx = 0;
19698 argv_find(argv, argc, "LINE", &idx);
19699 str = argv_concat(argv, argc, idx);
19700 }
19701
19702 idx = 0;
d62a17ae 19703 argv_find(argv, argc, "(100-500)", &idx);
19704 argv_find(argv, argc, "WORD", &idx);
19705 cl_number_or_name = argv[idx]->arg;
42f914d4 19706
d62a17ae 19707 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19708 seq, direct, style);
42f914d4 19709
d62a17ae 19710 XFREE(MTYPE_TMP, str);
42f914d4 19711
d62a17ae 19712 if (ret < 0) {
19713 community_list_perror(vty, ret);
19714 return CMD_WARNING_CONFIG_FAILED;
19715 }
42f914d4 19716
d62a17ae 19717 return CMD_SUCCESS;
718e3744 19718}
19719
d4455c89
DA
19720ALIAS(no_extcommunity_list_expanded_all,
19721 no_bgp_extcommunity_list_expanded_all_list_cmd,
19722 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 19723 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19724 "Extended Community list number (expanded)\n"
19725 "Specify expanded extcommunity-list\n"
19726 "Extended Community list name\n")
19727
d62a17ae 19728static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19729{
d62a17ae 19730 struct community_entry *entry;
718e3744 19731
d62a17ae 19732 for (entry = list->head; entry; entry = entry->next) {
19733 if (entry == list->head) {
19734 if (all_digit(list->name))
19735 vty_out(vty, "Extended community %s list %s\n",
19736 entry->style == EXTCOMMUNITY_LIST_STANDARD
19737 ? "standard"
19738 : "(expanded) access",
19739 list->name);
19740 else
19741 vty_out(vty,
19742 "Named extended community %s list %s\n",
19743 entry->style == EXTCOMMUNITY_LIST_STANDARD
19744 ? "standard"
19745 : "expanded",
19746 list->name);
19747 }
19748 if (entry->any)
19749 vty_out(vty, " %s\n",
19750 community_direct_str(entry->direct));
19751 else
19752 vty_out(vty, " %s %s\n",
19753 community_direct_str(entry->direct),
8d9b8ed9 19754 community_list_config_str(entry));
d62a17ae 19755 }
718e3744 19756}
19757
7336e101
SP
19758DEFUN (show_extcommunity_list,
19759 show_bgp_extcommunity_list_cmd,
19760 "show bgp extcommunity-list",
718e3744 19761 SHOW_STR
7336e101 19762 BGP_STR
718e3744 19763 "List extended-community list\n")
19764{
d62a17ae 19765 struct community_list *list;
19766 struct community_list_master *cm;
718e3744 19767
d62a17ae 19768 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19769 if (!cm)
19770 return CMD_SUCCESS;
718e3744 19771
d62a17ae 19772 for (list = cm->num.head; list; list = list->next)
19773 extcommunity_list_show(vty, list);
718e3744 19774
d62a17ae 19775 for (list = cm->str.head; list; list = list->next)
19776 extcommunity_list_show(vty, list);
718e3744 19777
d62a17ae 19778 return CMD_SUCCESS;
718e3744 19779}
19780
7336e101
SP
19781DEFUN (show_extcommunity_list_arg,
19782 show_bgp_extcommunity_list_arg_cmd,
960b69b9 19783 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
19784 SHOW_STR
19785 BGP_STR
718e3744 19786 "List extended-community list\n"
19787 "Extcommunity-list number\n"
960b69b9 19788 "Extcommunity-list name\n"
19789 "Detailed information on extcommunity-list\n")
718e3744 19790{
d62a17ae 19791 int idx_comm_list = 3;
19792 struct community_list *list;
718e3744 19793
e237b0d2 19794 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19795 EXTCOMMUNITY_LIST_MASTER);
19796 if (!list) {
19797 vty_out(vty, "%% Can't find extcommunity-list\n");
19798 return CMD_WARNING;
19799 }
718e3744 19800
d62a17ae 19801 extcommunity_list_show(vty, list);
718e3744 19802
d62a17ae 19803 return CMD_SUCCESS;
718e3744 19804}
6b0655a2 19805
718e3744 19806/* Display community-list and extcommunity-list configuration. */
d62a17ae 19807static int community_list_config_write(struct vty *vty)
19808{
19809 struct community_list *list;
19810 struct community_entry *entry;
19811 struct community_list_master *cm;
19812 int write = 0;
19813
19814 /* Community-list. */
19815 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19816
19817 for (list = cm->num.head; list; list = list->next)
19818 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
19819 vty_out(vty,
19820 "bgp community-list %s seq %" PRId64 " %s %s\n",
19821 list->name, entry->seq,
d62a17ae 19822 community_direct_str(entry->direct),
19823 community_list_config_str(entry));
19824 write++;
19825 }
19826 for (list = cm->str.head; list; list = list->next)
19827 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
19828 vty_out(vty,
19829 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 19830 entry->style == COMMUNITY_LIST_STANDARD
19831 ? "standard"
19832 : "expanded",
2f8cc0e5
DA
19833 list->name, entry->seq,
19834 community_direct_str(entry->direct),
d62a17ae 19835 community_list_config_str(entry));
19836 write++;
19837 }
19838
19839 /* Extcommunity-list. */
19840 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19841
19842 for (list = cm->num.head; list; list = list->next)
19843 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
19844 vty_out(vty,
19845 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
19846 list->name, entry->seq,
19847 community_direct_str(entry->direct),
d62a17ae 19848 community_list_config_str(entry));
19849 write++;
19850 }
19851 for (list = cm->str.head; list; list = list->next)
19852 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19853 vty_out(vty,
6cde4b45 19854 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 19855 entry->style == EXTCOMMUNITY_LIST_STANDARD
19856 ? "standard"
19857 : "expanded",
2f8cc0e5
DA
19858 list->name, entry->seq,
19859 community_direct_str(entry->direct),
d62a17ae 19860 community_list_config_str(entry));
19861 write++;
19862 }
19863
19864
19865 /* lcommunity-list. */
19866 cm = community_list_master_lookup(bgp_clist,
19867 LARGE_COMMUNITY_LIST_MASTER);
19868
19869 for (list = cm->num.head; list; list = list->next)
19870 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19871 vty_out(vty,
6cde4b45 19872 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
19873 list->name, entry->seq,
19874 community_direct_str(entry->direct),
d62a17ae 19875 community_list_config_str(entry));
19876 write++;
19877 }
19878 for (list = cm->str.head; list; list = list->next)
19879 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19880 vty_out(vty,
6cde4b45 19881 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 19882
d62a17ae 19883 entry->style == LARGE_COMMUNITY_LIST_STANDARD
19884 ? "standard"
19885 : "expanded",
2f8cc0e5 19886 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 19887 community_list_config_str(entry));
19888 write++;
19889 }
19890
19891 return write;
19892}
19893
612c2c15 19894static int community_list_config_write(struct vty *vty);
d62a17ae 19895static struct cmd_node community_list_node = {
f4b8291f 19896 .name = "community list",
62b346ee
DL
19897 .node = COMMUNITY_LIST_NODE,
19898 .prompt = "",
612c2c15 19899 .config_write = community_list_config_write,
718e3744 19900};
19901
d62a17ae 19902static void community_list_vty(void)
19903{
612c2c15 19904 install_node(&community_list_node);
d62a17ae 19905
19906 /* Community-list. */
7336e101
SP
19907 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
19908 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
19909 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 19910 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 19911 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 19912 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
19913 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
19914 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 19915
19916 /* Extcommunity-list. */
7336e101
SP
19917 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
19918 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
19919 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
19920 install_element(CONFIG_NODE,
19921 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 19922 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
19923 install_element(CONFIG_NODE,
19924 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
19925 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
19926 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 19927
19928 /* Large Community List */
7336e101 19929 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
19930 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
19931 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 19932 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
19933 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
19934 install_element(CONFIG_NODE,
19935 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
19936 install_element(CONFIG_NODE,
19937 &no_bgp_lcommunity_list_name_expanded_all_cmd);
19938 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
19939 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
19940 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
19941 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
19942 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
19943 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 19944}