]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: convert max prefix clis to transactional
[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,
464 DFLT_BGP_CONNECT_RETRY);
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
718e3744 1517/* BGP Cluster ID. */
ff8a8a7a
CS
1518DEFUN_YANG(bgp_cluster_id,
1519 bgp_cluster_id_cmd,
1520 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1521 BGP_STR
1522 "Configure Route-Reflector Cluster-id\n"
1523 "Route-Reflector Cluster-id in IP address format\n"
1524 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1525{
d62a17ae 1526 int idx_ipv4 = 2;
718e3744 1527
87ce2564
CS
1528 nb_cli_enqueue_change(
1529 vty, "./global/route-reflector/route-reflector-cluster-id",
1530 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1531
ff8a8a7a 1532 return nb_cli_apply_changes(vty, NULL);
718e3744 1533}
1534
ff8a8a7a
CS
1535DEFUN_YANG(no_bgp_cluster_id,
1536 no_bgp_cluster_id_cmd,
1537 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1538 NO_STR BGP_STR
1539 "Configure Route-Reflector Cluster-id\n"
1540 "Route-Reflector Cluster-id in IP address format\n"
1541 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1542{
87ce2564
CS
1543 nb_cli_enqueue_change(
1544 vty, "./global/route-reflector/route-reflector-cluster-id",
1545 NB_OP_DESTROY, NULL);
718e3744 1546
ff8a8a7a 1547 return nb_cli_apply_changes(vty, NULL);
718e3744 1548}
1549
c163f297
DS
1550DEFPY (bgp_norib,
1551 bgp_norib_cmd,
1552 "bgp no-rib",
1553 BGP_STR
1554 "Disable BGP route installation to RIB (Zebra)\n")
1555{
1556 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1557 vty_out(vty,
1558 "%% No-RIB option is already set, nothing to do here.\n");
1559 return CMD_SUCCESS;
1560 }
1561
1562 bgp_option_norib_set_runtime();
1563
1564 return CMD_SUCCESS;
1565}
1566
1567DEFPY (no_bgp_norib,
1568 no_bgp_norib_cmd,
1569 "no bgp no-rib",
1570 NO_STR
1571 BGP_STR
1572 "Disable BGP route installation to RIB (Zebra)\n")
1573{
1574 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1575 vty_out(vty,
1576 "%% No-RIB option is not set, nothing to do here.\n");
1577 return CMD_SUCCESS;
1578 }
1579
1580 bgp_option_norib_unset_runtime();
1581
1582 return CMD_SUCCESS;
1583}
1584
ff8a8a7a
CS
1585DEFUN_YANG(bgp_confederation_identifier,
1586 bgp_confederation_identifier_cmd,
1587 "bgp confederation identifier (1-4294967295)",
1588 "BGP specific commands\n"
1589 "AS confederation parameters\n"
1590 "AS number\n"
1591 "Set routing domain confederation AS\n")
718e3744 1592{
d62a17ae 1593 int idx_number = 3;
718e3744 1594
87ce2564
CS
1595 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1596 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1597
ff8a8a7a 1598 return nb_cli_apply_changes(vty, NULL);
718e3744 1599}
1600
ff8a8a7a
CS
1601DEFUN_YANG(no_bgp_confederation_identifier,
1602 no_bgp_confederation_identifier_cmd,
1603 "no bgp confederation identifier [(1-4294967295)]",
1604 NO_STR
1605 "BGP specific commands\n"
1606 "AS confederation parameters\n"
1607 "AS number\n"
1608 "Set routing domain confederation AS\n")
718e3744 1609{
87ce2564
CS
1610 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1611 NB_OP_DESTROY, NULL);
718e3744 1612
ff8a8a7a 1613 return nb_cli_apply_changes(vty, NULL);
718e3744 1614}
1615
ff8a8a7a
CS
1616void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1617 struct lyd_node *dnode,
1618 bool show_defaults)
1619{
1620 vty_out(vty, " bgp confederation identifier %u\n",
1621 yang_dnode_get_uint32(dnode, NULL));
1622}
1623
1624DEFUN_YANG(bgp_confederation_peers,
1625 bgp_confederation_peers_cmd,
1626 "bgp confederation peers (1-4294967295)...",
1627 "BGP specific commands\n"
1628 "AS confederation parameters\n"
1629 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1630{
d62a17ae 1631 int idx_asn = 3;
d62a17ae 1632 int i;
718e3744 1633
ff8a8a7a 1634 for (i = idx_asn; i < argc; i++)
87ce2564 1635 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1636 NB_OP_CREATE, argv[i]->arg);
718e3744 1637
ff8a8a7a 1638 return nb_cli_apply_changes(vty, NULL);
718e3744 1639}
1640
ff8a8a7a
CS
1641DEFUN_YANG(no_bgp_confederation_peers,
1642 no_bgp_confederation_peers_cmd,
1643 "no bgp confederation peers (1-4294967295)...",
1644 NO_STR
1645 "BGP specific commands\n"
1646 "AS confederation parameters\n"
1647 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1648{
d62a17ae 1649 int idx_asn = 4;
d62a17ae 1650 int i;
718e3744 1651
ff8a8a7a 1652 for (i = idx_asn; i < argc; i++)
87ce2564 1653 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1654 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1655
ff8a8a7a
CS
1656 return nb_cli_apply_changes(vty, NULL);
1657}
1658
1659void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1660 struct lyd_node *dnode,
1661 bool show_defaults)
1662{
1663 vty_out(vty, " bgp confederation peers %u \n",
1664 yang_dnode_get_uint32(dnode, NULL));
718e3744 1665}
6b0655a2 1666
5e242b0d
DS
1667/**
1668 * Central routine for maximum-paths configuration.
1669 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1670 * @set: 1 for setting values, 0 for removing the max-paths config.
1671 */
37a87b8f
CS
1672int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1673 int peer_type, uint16_t maxpaths, uint16_t options,
1674 int set, char *errmsg, size_t errmsg_len)
d62a17ae 1675{
d62a17ae 1676 int ret;
d62a17ae 1677
1678 if (set) {
d62a17ae 1679 if (maxpaths > multipath_num) {
37a87b8f
CS
1680 snprintf(
1681 errmsg, errmsg_len,
d62a17ae 1682 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1683 maxpaths, multipath_num);
1684 return CMD_WARNING_CONFIG_FAILED;
1685 }
1686 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1687 options);
1688 } else
1689 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1690
1691 if (ret < 0) {
37a87b8f
CS
1692 snprintf(
1693 errmsg, errmsg_len,
d62a17ae 1694 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1695 (set == 1) ? "" : "un",
1696 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1697 maxpaths, afi, safi);
1698 return CMD_WARNING_CONFIG_FAILED;
1699 }
1700
1701 bgp_recalculate_all_bestpaths(bgp);
1702
1703 return CMD_SUCCESS;
165b5fff
JB
1704}
1705
ff8a8a7a
CS
1706void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1707 bool show_defaults)
abc920f8 1708{
ff8a8a7a
CS
1709 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1710 uint32_t med_admin_val;
abc920f8 1711
ff8a8a7a
CS
1712 vty_out(vty, " bgp max-med administrative");
1713 if ((med_admin_val =
1714 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1715 != BGP_MAXMED_VALUE_DEFAULT)
1716 vty_out(vty, " %u", med_admin_val);
1717 vty_out(vty, "\n");
1718 }
abc920f8 1719
ff8a8a7a
CS
1720 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1721 uint32_t onstartup_val;
abc920f8 1722
ff8a8a7a
CS
1723 vty_out(vty, " bgp max-med on-startup %u",
1724 yang_dnode_get_uint32(dnode,
1725 "./max-med-onstart-up-time"));
1726 onstartup_val = yang_dnode_get_uint32(
1727 dnode, "./max-med-onstart-up-value");
1728 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1729 vty_out(vty, " %u", onstartup_val);
1730
1731 vty_out(vty, "\n");
1732 }
abc920f8
DS
1733}
1734
ff8a8a7a
CS
1735DEFUN_YANG(bgp_maxmed_admin,
1736 bgp_maxmed_admin_cmd,
1737 "bgp max-med administrative ",
1738 BGP_STR
1739 "Advertise routes with max-med\n"
1740 "Administratively applied, for an indefinite period\n")
1741{
87ce2564 1742 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1743 NB_OP_MODIFY, "true");
1744
1745 return nb_cli_apply_changes(vty, NULL);
1746}
1747
1748DEFUN_YANG(bgp_maxmed_admin_medv,
1749 bgp_maxmed_admin_medv_cmd,
1750 "bgp max-med administrative (0-4294967295)",
1751 BGP_STR
1752 "Advertise routes with max-med\n"
1753 "Administratively applied, for an indefinite period\n"
1754 "Max MED value to be used\n")
abc920f8 1755{
d62a17ae 1756 int idx_number = 3;
abc920f8 1757
87ce2564 1758 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1759 NB_OP_MODIFY, "true");
abc920f8 1760
87ce2564
CS
1761 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1762 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1763
ff8a8a7a 1764 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1765}
1766
ff8a8a7a
CS
1767DEFUN_YANG(no_bgp_maxmed_admin,
1768 no_bgp_maxmed_admin_cmd,
1769 "no bgp max-med administrative [(0-4294967295)]",
1770 NO_STR BGP_STR
1771 "Advertise routes with max-med\n"
1772 "Administratively applied, for an indefinite period\n"
1773 "Max MED value to be used\n")
abc920f8 1774{
87ce2564 1775 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1776 NB_OP_MODIFY, "false");
abc920f8 1777
87ce2564
CS
1778 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1779 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1780
1781 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1782}
1783
37a87b8f
CS
1784DEFUN_YANG (bgp_maxmed_onstartup,
1785 bgp_maxmed_onstartup_cmd,
1786 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1787 BGP_STR
1788 "Advertise routes with max-med\n"
1789 "Effective on a startup\n"
1790 "Time (seconds) period for max-med\n"
1791 "Max MED value to be used\n")
abc920f8 1792{
d62a17ae 1793 int idx = 0;
4668a151 1794
d62a17ae 1795 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1796 nb_cli_enqueue_change(vty,
1797 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1798 NB_OP_MODIFY, argv[idx]->arg);
1799
d62a17ae 1800 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1801 nb_cli_enqueue_change(
1802 vty, "./global/med-config/max-med-onstart-up-value",
1803 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1804 else
87ce2564
CS
1805 nb_cli_enqueue_change(
1806 vty, "./global/med-config/max-med-onstart-up-value",
1807 NB_OP_MODIFY, NULL);
abc920f8 1808
ff8a8a7a 1809 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1810}
1811
37a87b8f
CS
1812DEFUN_YANG (no_bgp_maxmed_onstartup,
1813 no_bgp_maxmed_onstartup_cmd,
1814 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1815 NO_STR BGP_STR
1816 "Advertise routes with max-med\n"
1817 "Effective on a startup\n"
1818 "Time (seconds) period for max-med\n"
1819 "Max MED value to be used\n")
abc920f8 1820{
87ce2564
CS
1821 nb_cli_enqueue_change(vty,
1822 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1823 NB_OP_DESTROY, NULL);
abc920f8 1824
87ce2564
CS
1825 nb_cli_enqueue_change(vty,
1826 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1827 NB_OP_MODIFY, NULL);
abc920f8 1828
ff8a8a7a 1829 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1830}
1831
d70583f7
D
1832static int bgp_global_update_delay_config_vty(struct vty *vty,
1833 uint16_t update_delay,
1834 uint16_t establish_wait)
1835{
1836 struct listnode *node, *nnode;
1837 struct bgp *bgp;
1838 bool vrf_cfg = false;
1839
1840 /*
1841 * See if update-delay is set per-vrf and warn user to delete it
1842 * Note that we only need to check this if this is the first time
1843 * setting the global config.
1844 */
1845 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1846 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1847 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1848 vty_out(vty,
1849 "%% update-delay configuration found in vrf %s\n",
1850 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1851 ? VRF_DEFAULT_NAME
1852 : bgp->name);
1853 vrf_cfg = true;
1854 }
1855 }
1856 }
1857
1858 if (vrf_cfg) {
1859 vty_out(vty,
1860 "%%Failed: global update-delay config not permitted\n");
1861 return CMD_WARNING;
1862 }
1863
1864 if (!establish_wait) { /* update-delay <delay> */
1865 bm->v_update_delay = update_delay;
1866 bm->v_establish_wait = bm->v_update_delay;
1867 } else {
1868 /* update-delay <delay> <establish-wait> */
1869 if (update_delay < establish_wait) {
1870 vty_out(vty,
1871 "%%Failed: update-delay less than the establish-wait!\n");
1872 return CMD_WARNING_CONFIG_FAILED;
1873 }
1874
1875 bm->v_update_delay = update_delay;
1876 bm->v_establish_wait = establish_wait;
1877 }
1878
1879 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1880 bgp->v_update_delay = bm->v_update_delay;
1881 bgp->v_establish_wait = bm->v_establish_wait;
1882 }
1883
1884 return CMD_SUCCESS;
1885}
1886
1887static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1888{
1889 struct listnode *node, *nnode;
1890 struct bgp *bgp;
1891
1892 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1893 bm->v_establish_wait = bm->v_update_delay;
1894
1895 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1896 bgp->v_update_delay = bm->v_update_delay;
1897 bgp->v_establish_wait = bm->v_establish_wait;
1898 }
1899
1900 return CMD_SUCCESS;
1901}
1902
1903static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1904 uint16_t establish_wait)
f188f2c4 1905{
d62a17ae 1906 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1907
d70583f7
D
1908 /* if configured globally, per-instance config is not allowed */
1909 if (bm->v_update_delay) {
1910 vty_out(vty,
1911 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1912 return CMD_WARNING_CONFIG_FAILED;
1913 }
1914
f188f2c4 1915
d70583f7 1916 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1917 {
1918 bgp->v_update_delay = update_delay;
1919 bgp->v_establish_wait = bgp->v_update_delay;
1920 return CMD_SUCCESS;
1921 }
f188f2c4 1922
d62a17ae 1923 /* update-delay <delay> <establish-wait> */
d62a17ae 1924 if (update_delay < establish_wait) {
1925 vty_out(vty,
1926 "%%Failed: update-delay less than the establish-wait!\n");
1927 return CMD_WARNING_CONFIG_FAILED;
1928 }
f188f2c4 1929
d62a17ae 1930 bgp->v_update_delay = update_delay;
1931 bgp->v_establish_wait = establish_wait;
f188f2c4 1932
d62a17ae 1933 return CMD_SUCCESS;
f188f2c4
DS
1934}
1935
d62a17ae 1936static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1937{
d62a17ae 1938 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1939
d70583f7
D
1940 /* If configured globally, cannot remove from one bgp instance */
1941 if (bm->v_update_delay) {
1942 vty_out(vty,
1943 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
1944 return CMD_WARNING_CONFIG_FAILED;
1945 }
d62a17ae 1946 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1947 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1948
d62a17ae 1949 return CMD_SUCCESS;
f188f2c4
DS
1950}
1951
2b791107 1952void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1953{
d70583f7
D
1954 /* If configured globally, no need to display per-instance value */
1955 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 1956 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1957 if (bgp->v_update_delay != bgp->v_establish_wait)
1958 vty_out(vty, " %d", bgp->v_establish_wait);
1959 vty_out(vty, "\n");
1960 }
f188f2c4
DS
1961}
1962
d70583f7
D
1963/* Global update-delay configuration */
1964DEFPY (bgp_global_update_delay,
1965 bgp_global_update_delay_cmd,
1966 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
1967 BGP_STR
1968 "Force initial delay for best-path and updates for all bgp instances\n"
1969 "Max delay in seconds\n"
1970 "Establish wait in seconds\n")
1971{
1972 return bgp_global_update_delay_config_vty(vty, delay, wait);
1973}
f188f2c4 1974
d70583f7
D
1975/* Global update-delay deconfiguration */
1976DEFPY (no_bgp_global_update_delay,
1977 no_bgp_global_update_delay_cmd,
1978 "no bgp update-delay [(0-3600) [(1-3600)]]",
1979 NO_STR
1980 BGP_STR
f188f2c4 1981 "Force initial delay for best-path and updates\n"
d70583f7
D
1982 "Max delay in seconds\n"
1983 "Establish wait in seconds\n")
f188f2c4 1984{
d70583f7 1985 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
1986}
1987
d70583f7
D
1988/* Update-delay configuration */
1989
1990DEFPY (bgp_update_delay,
1991 bgp_update_delay_cmd,
1992 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 1993 "Force initial delay for best-path and updates\n"
d70583f7
D
1994 "Max delay in seconds\n"
1995 "Establish wait in seconds\n")
f188f2c4 1996{
d70583f7 1997 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
1998}
1999
2000/* Update-delay deconfiguration */
d70583f7 2001DEFPY (no_bgp_update_delay,
f188f2c4 2002 no_bgp_update_delay_cmd,
838758ac
DW
2003 "no update-delay [(0-3600) [(1-3600)]]",
2004 NO_STR
f188f2c4 2005 "Force initial delay for best-path and updates\n"
d70583f7
D
2006 "Max delay in seconds\n"
2007 "Establish wait in seconds\n")
f188f2c4 2008{
d62a17ae 2009 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2010}
2011
5e242b0d 2012
ff8a8a7a 2013int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 2014{
8fa7732f
QY
2015 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2016 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2017
2018 return CMD_SUCCESS;
2019}
2020
ff8a8a7a 2021int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 2022{
8fa7732f
QY
2023 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2024 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2025
d62a17ae 2026 return CMD_SUCCESS;
cb1faec9
DS
2027}
2028
2b791107 2029void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2030{
555e09d4
QY
2031 uint32_t quanta =
2032 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2033 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2034 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2035}
2036
555e09d4
QY
2037void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2038{
2039 uint32_t quanta =
2040 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2041 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2042 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2043}
cb1faec9 2044
8fa7732f
QY
2045/* Packet quanta configuration
2046 *
2047 * XXX: The value set here controls the size of a stack buffer in the IO
2048 * thread. When changing these limits be careful to prevent stack overflow.
2049 *
2050 * Furthermore, the maximums used here should correspond to
2051 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2052 */
37a87b8f
CS
2053DEFPY_YANG (bgp_wpkt_quanta,
2054 bgp_wpkt_quanta_cmd,
2055 "[no] write-quanta (1-64)$quanta",
2056 NO_STR
2057 "How many packets to write to peer socket per run\n"
2058 "Number of packets\n")
ff8a8a7a
CS
2059{
2060 if (!no)
2061 nb_cli_enqueue_change(
2062 vty,
87ce2564 2063 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2064 NB_OP_MODIFY, quanta_str);
2065 else
2066 nb_cli_enqueue_change(
2067 vty,
87ce2564 2068 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2069 NB_OP_MODIFY, NULL);
2070
2071 return nb_cli_apply_changes(vty, NULL);
2072}
2073
37a87b8f
CS
2074DEFPY_YANG (bgp_rpkt_quanta,
2075 bgp_rpkt_quanta_cmd,
2076 "[no] read-quanta (1-10)$quanta",
2077 NO_STR
2078 "How many packets to read from peer socket per I/O cycle\n"
2079 "Number of packets\n")
ff8a8a7a
CS
2080{
2081 if (!no)
2082 nb_cli_enqueue_change(
2083 vty,
87ce2564 2084 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2085 NB_OP_MODIFY, quanta_str);
2086 else
2087 nb_cli_enqueue_change(
2088 vty,
87ce2564 2089 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2090 NB_OP_MODIFY, NULL);
cb1faec9 2091
ff8a8a7a 2092 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2093}
2094
2b791107 2095void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2096{
37a333fe 2097 if (!bgp->heuristic_coalesce)
d62a17ae 2098 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2099}
2100
ff8a8a7a
CS
2101void cli_show_router_global_update_group_config_coalesce_time(
2102 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2103{
ff8a8a7a
CS
2104 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2105}
2106
4668a151 2107
37a87b8f
CS
2108DEFUN_YANG (bgp_coalesce_time,
2109 bgp_coalesce_time_cmd,
2110 "coalesce-time (0-4294967295)",
2111 "Subgroup coalesce timer\n"
2112 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2113{
d62a17ae 2114 int idx = 0;
ff8a8a7a 2115
d62a17ae 2116 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2117 nb_cli_enqueue_change(
2118 vty, "./global/global-update-group-config/coalesce-time",
2119 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2120
2121 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2122}
2123
ff8a8a7a
CS
2124DEFUN_YANG(no_bgp_coalesce_time,
2125 no_bgp_coalesce_time_cmd,
2126 "no coalesce-time (0-4294967295)",
2127 NO_STR
2128 "Subgroup coalesce timer\n"
2129 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2130{
87ce2564
CS
2131 nb_cli_enqueue_change(
2132 vty, "./global/global-update-group-config/coalesce-time",
2133 NB_OP_MODIFY, NULL);
4668a151 2134
ff8a8a7a 2135 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2136}
2137
5e242b0d 2138/* Maximum-paths configuration */
37a87b8f
CS
2139DEFUN_YANG (bgp_maxpaths,
2140 bgp_maxpaths_cmd,
2141 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2142 "Forward packets over multiple paths\n"
2143 "Number of paths\n")
5e242b0d 2144{
d62a17ae 2145 int idx_number = 1;
37a87b8f
CS
2146 char base_xpath[XPATH_MAXLEN];
2147 afi_t afi;
2148 safi_t safi;
2149
2150 afi = bgp_node_afi(vty);
2151 safi = bgp_node_safi(vty);
2152
2153 snprintf(
2154 base_xpath, sizeof(base_xpath),
2155 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2156 yang_afi_safi_value2identity(afi, safi),
2157 bgp_afi_safi_get_container_str(afi, safi));
2158
2159 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2160 argv[idx_number]->arg);
2161
2162 return nb_cli_apply_changes(vty, NULL);
2163}
2164
2165void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2166 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2167{
2168 vty_out(vty, " maximum-paths %d\n",
2169 yang_dnode_get_uint16(dnode, NULL));
5e242b0d
DS
2170}
2171
d62a17ae 2172ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2173 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2174 "Forward packets over multiple paths\n"
2175 "Number of paths\n")
596c17ba 2176
37a87b8f
CS
2177DEFUN_YANG (bgp_maxpaths_ibgp,
2178 bgp_maxpaths_ibgp_cmd,
2179 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2180 "Forward packets over multiple paths\n"
2181 "iBGP-multipath\n"
2182 "Number of paths\n")
165b5fff 2183{
d62a17ae 2184 int idx_number = 2;
37a87b8f
CS
2185 char base_xpath[XPATH_MAXLEN];
2186 afi_t afi;
2187 safi_t safi;
2188
2189 afi = bgp_node_afi(vty);
2190 safi = bgp_node_safi(vty);
2191
2192 snprintf(
2193 base_xpath, sizeof(base_xpath),
2194 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2195 yang_afi_safi_value2identity(afi, safi),
2196 bgp_afi_safi_get_container_str(afi, safi));
2197
2198 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2199 argv[idx_number]->arg);
2200
2201 return nb_cli_apply_changes(vty, NULL);
5e242b0d 2202}
165b5fff 2203
d62a17ae 2204ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2205 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2206 "Forward packets over multiple paths\n"
2207 "iBGP-multipath\n"
2208 "Number of paths\n")
596c17ba 2209
37a87b8f
CS
2210DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2211 bgp_maxpaths_ibgp_cluster_cmd,
2212 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2213 "Forward packets over multiple paths\n"
2214 "iBGP-multipath\n"
2215 "Number of paths\n"
2216 "Match the cluster length\n")
5e242b0d 2217{
d62a17ae 2218 int idx_number = 2;
37a87b8f
CS
2219 char base_xpath[XPATH_MAXLEN];
2220 afi_t afi;
2221 safi_t safi;
2222
2223 afi = bgp_node_afi(vty);
2224 safi = bgp_node_safi(vty);
2225
2226 snprintf(
2227 base_xpath, sizeof(base_xpath),
2228 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2229 yang_afi_safi_value2identity(afi, safi),
2230 bgp_afi_safi_get_container_str(afi, safi));
2231
2232 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2233 argv[idx_number]->arg);
2234
2235 snprintf(
2236 base_xpath, sizeof(base_xpath),
2237 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2238 yang_afi_safi_value2identity(afi, safi),
2239 bgp_afi_safi_get_container_str(afi, safi));
2240
2241 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2242
2243 return nb_cli_apply_changes(vty, NULL);
2244}
2245
2246void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2247 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2248{
2249 vty_out(vty, " maximum-paths ibgp %d",
2250 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2251 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2252 vty_out(vty, " equal-cluster-length");
2253 vty_out(vty, "\n");
165b5fff
JB
2254}
2255
d62a17ae 2256ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2257 "maximum-paths ibgp " CMD_RANGE_STR(
2258 1, MULTIPATH_NUM) " equal-cluster-length",
2259 "Forward packets over multiple paths\n"
2260 "iBGP-multipath\n"
2261 "Number of paths\n"
2262 "Match the cluster length\n")
596c17ba 2263
37a87b8f
CS
2264DEFUN_YANG (no_bgp_maxpaths,
2265 no_bgp_maxpaths_cmd,
2266 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2267 NO_STR
2268 "Forward packets over multiple paths\n"
2269 "Number of paths\n")
165b5fff 2270{
37a87b8f
CS
2271 char base_xpath[XPATH_MAXLEN];
2272 afi_t afi;
2273 safi_t safi;
2274
2275 afi = bgp_node_afi(vty);
2276 safi = bgp_node_safi(vty);
2277
2278 snprintf(
2279 base_xpath, sizeof(base_xpath),
2280 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2281 yang_afi_safi_value2identity(afi, safi),
2282 bgp_afi_safi_get_container_str(afi, safi));
2283
2284 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2285
2286 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2287}
2288
d62a17ae 2289ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2290 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2291 "Forward packets over multiple paths\n"
2292 "Number of paths\n")
596c17ba 2293
37a87b8f
CS
2294DEFUN_YANG (no_bgp_maxpaths_ibgp,
2295 no_bgp_maxpaths_ibgp_cmd,
2296 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2297 NO_STR
2298 "Forward packets over multiple paths\n"
2299 "iBGP-multipath\n"
2300 "Number of paths\n"
2301 "Match the cluster length\n")
165b5fff 2302{
37a87b8f
CS
2303 char base_xpath[XPATH_MAXLEN];
2304 afi_t afi;
2305 safi_t safi;
2306
2307 afi = bgp_node_afi(vty);
2308 safi = bgp_node_safi(vty);
2309
2310 snprintf(
2311 base_xpath, sizeof(base_xpath),
2312 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2313 yang_afi_safi_value2identity(afi, safi),
2314 bgp_afi_safi_get_container_str(afi, safi));
2315
2316 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2317
2318 snprintf(
2319 base_xpath, sizeof(base_xpath),
2320 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2321 yang_afi_safi_value2identity(afi, safi),
2322 bgp_afi_safi_get_container_str(afi, safi));
2323
2324 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2325
2326 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2327}
2328
d62a17ae 2329ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2330 "no maximum-paths ibgp [" CMD_RANGE_STR(
2331 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2332 NO_STR
2333 "Forward packets over multiple paths\n"
2334 "iBGP-multipath\n"
2335 "Number of paths\n"
2336 "Match the cluster length\n")
596c17ba 2337
dd65f45e
DL
2338static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2339 afi_t afi, safi_t safi)
165b5fff 2340{
d62a17ae 2341 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 2342 vty_out(vty, " maximum-paths %d\n",
2343 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2344 }
165b5fff 2345
d62a17ae 2346 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 2347 vty_out(vty, " maximum-paths ibgp %d",
2348 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2349 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2350 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2351 vty_out(vty, " equal-cluster-length");
2352 vty_out(vty, "\n");
2353 }
165b5fff 2354}
6b0655a2 2355
718e3744 2356/* BGP timers. */
2357
37a87b8f
CS
2358DEFUN_YANG (bgp_timers,
2359 bgp_timers_cmd,
2360 "timers bgp (0-65535) (0-65535)",
2361 "Adjust routing timers\n"
2362 "BGP timers\n"
2363 "Keepalive interval\n"
2364 "Holdtime\n")
718e3744 2365{
d62a17ae 2366 int idx_number = 2;
2367 int idx_number_2 = 3;
718e3744 2368
87ce2564 2369 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2370 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2371 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2372 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2373
ff8a8a7a
CS
2374 return nb_cli_apply_changes(vty, NULL);
2375}
718e3744 2376
37a87b8f
CS
2377DEFUN_YANG (no_bgp_timers,
2378 no_bgp_timers_cmd,
2379 "no timers bgp [(0-65535) (0-65535)]",
2380 NO_STR
2381 "Adjust routing timers\n"
2382 "BGP timers\n"
2383 "Keepalive interval\n"
2384 "Holdtime\n")
ff8a8a7a 2385{
87ce2564 2386 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2387 NB_OP_DESTROY, NULL);
87ce2564 2388 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2389 NB_OP_DESTROY, NULL);
718e3744 2390
ff8a8a7a 2391 return nb_cli_apply_changes(vty, NULL);
718e3744 2392}
2393
ff8a8a7a
CS
2394void cli_show_router_bgp_route_reflector(struct vty *vty,
2395 struct lyd_node *dnode,
2396 bool show_defaults)
718e3744 2397{
ff8a8a7a
CS
2398 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2399 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2400
ff8a8a7a
CS
2401 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2402 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2403
2404 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2405 vty_out(vty, " bgp cluster-id %s\n",
2406 yang_dnode_get_string(dnode,
2407 "./route-reflector-cluster-id"));
718e3744 2408}
2409
ff8a8a7a
CS
2410DEFUN_YANG(bgp_client_to_client_reflection,
2411 bgp_client_to_client_reflection_cmd,
2412 "bgp client-to-client reflection",
2413 "BGP specific commands\n"
2414 "Configure client to client route reflection\n"
2415 "reflection of routes allowed\n")
2416{
87ce2564 2417 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2418 NB_OP_MODIFY, "false");
6b0655a2 2419
ff8a8a7a
CS
2420 return nb_cli_apply_changes(vty, NULL);
2421}
2422
2423DEFUN_YANG(no_bgp_client_to_client_reflection,
2424 no_bgp_client_to_client_reflection_cmd,
2425 "no bgp client-to-client reflection",
2426 NO_STR
2427 "BGP specific commands\n"
2428 "Configure client to client route reflection\n"
2429 "reflection of routes allowed\n")
718e3744 2430{
87ce2564 2431 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2432 NB_OP_MODIFY, "true");
7aafcaca 2433
ff8a8a7a 2434 return nb_cli_apply_changes(vty, NULL);
718e3744 2435}
2436
ff8a8a7a
CS
2437void cli_show_router_bgp_route_selection(struct vty *vty,
2438 struct lyd_node *dnode,
2439 bool show_defaults)
718e3744 2440{
7aafcaca 2441
ff8a8a7a
CS
2442 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2443 vty_out(vty, " bgp always-compare-med\n");
2444
2445 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2446 vty_out(vty, " bgp bestpath as-path ignore\n");
2447
2448 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2449 vty_out(vty, " bgp bestpath as-path confed\n");
2450
2451 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2452 vty_out(vty, " bgp bestpath compare-routerid\n");
2453
2454 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2455 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2456 vty_out(vty,
2457 " bgp bestpath as-path multipath-relax as-set\n");
2458 else
2459 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2460 }
2461
2462 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2463 vty_out(vty, " bgp deterministic-med\n");
2464
2465 if (yang_dnode_get_bool(dnode, "./confed-med")
2466 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2467 vty_out(vty, " bgp bestpath med");
2468 if (yang_dnode_get_bool(dnode, "./confed-med"))
2469 vty_out(vty, " confed");
2470 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2471 vty_out(vty, " missing-as-worst");
2472 vty_out(vty, "\n");
2473 }
718e3744 2474}
2475
2476/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2477DEFUN_YANG(bgp_always_compare_med,
2478 bgp_always_compare_med_cmd,
2479 "bgp always-compare-med",
2480 "BGP specific commands\n"
2481 "Allow comparing MED from different neighbors\n")
718e3744 2482{
87ce2564
CS
2483 nb_cli_enqueue_change(
2484 vty, "./global/route-selection-options/always-compare-med",
2485 NB_OP_MODIFY, "true");
7aafcaca 2486
ff8a8a7a 2487 return nb_cli_apply_changes(vty, NULL);
718e3744 2488}
2489
ff8a8a7a
CS
2490DEFUN_YANG(no_bgp_always_compare_med,
2491 no_bgp_always_compare_med_cmd,
2492 "no bgp always-compare-med",
2493 NO_STR
2494 "BGP specific commands\n"
2495 "Allow comparing MED from different neighbors\n")
718e3744 2496{
87ce2564
CS
2497 nb_cli_enqueue_change(
2498 vty, "./global/route-selection-options/always-compare-med",
2499 NB_OP_MODIFY, "false");
7aafcaca 2500
ff8a8a7a 2501 return nb_cli_apply_changes(vty, NULL);
718e3744 2502}
6b0655a2 2503
ff8a8a7a
CS
2504DEFUN_YANG(bgp_ebgp_requires_policy,
2505 bgp_ebgp_requires_policy_cmd,
2506 "bgp ebgp-requires-policy",
2507 "BGP specific commands\n"
2508 "Require in and out policy for eBGP peers (RFC8212)\n")
2509{
87ce2564
CS
2510 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2511 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2512 return nb_cli_apply_changes(vty, NULL);
2513}
9dac9fc8 2514
ff8a8a7a
CS
2515DEFUN_YANG(no_bgp_ebgp_requires_policy,
2516 no_bgp_ebgp_requires_policy_cmd,
2517 "no bgp ebgp-requires-policy",
2518 NO_STR
2519 "BGP specific commands\n"
2520 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2521{
87ce2564
CS
2522 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2523 NB_OP_MODIFY, "false");
ff8a8a7a 2524 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2525}
2526
ff8a8a7a
CS
2527void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2528 struct lyd_node *dnode,
2529 bool show_defaults)
9dac9fc8 2530{
ff8a8a7a
CS
2531 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2532 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2533}
2534
fb29348a
DA
2535DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2536 "bgp reject-as-sets",
2537 "BGP specific commands\n"
2538 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2539{
2540 VTY_DECLVAR_CONTEXT(bgp, bgp);
2541 struct listnode *node, *nnode;
2542 struct peer *peer;
2543
7f972cd8 2544 bgp->reject_as_sets = true;
fb29348a
DA
2545
2546 /* Reset existing BGP sessions to reject routes
2547 * with aspath containing AS_SET or AS_CONFED_SET.
2548 */
2549 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2550 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2551 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2552 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2553 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2554 }
2555 }
2556
2557 return CMD_SUCCESS;
2558}
2559
2560DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2561 "no bgp reject-as-sets",
2562 NO_STR
2563 "BGP specific commands\n"
2564 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2565{
2566 VTY_DECLVAR_CONTEXT(bgp, bgp);
2567 struct listnode *node, *nnode;
2568 struct peer *peer;
2569
7f972cd8 2570 bgp->reject_as_sets = false;
fb29348a
DA
2571
2572 /* Reset existing BGP sessions to reject routes
2573 * with aspath containing AS_SET or AS_CONFED_SET.
2574 */
2575 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2576 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2577 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2578 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2579 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2580 }
2581 }
2582
2583 return CMD_SUCCESS;
2584}
9dac9fc8 2585
718e3744 2586/* "bgp deterministic-med" configuration. */
ff8a8a7a 2587DEFUN_YANG (bgp_deterministic_med,
718e3744 2588 bgp_deterministic_med_cmd,
2589 "bgp deterministic-med",
2590 "BGP specific commands\n"
2591 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2592{
87ce2564
CS
2593 nb_cli_enqueue_change(
2594 vty, "./global/route-selection-options/deterministic-med",
2595 NB_OP_MODIFY, "true");
7aafcaca 2596
ff8a8a7a 2597 return nb_cli_apply_changes(vty, NULL);
718e3744 2598}
2599
ff8a8a7a 2600DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2601 no_bgp_deterministic_med_cmd,
2602 "no bgp deterministic-med",
2603 NO_STR
2604 "BGP specific commands\n"
2605 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2606{
87ce2564
CS
2607 nb_cli_enqueue_change(
2608 vty, "./global/route-selection-options/deterministic-med",
2609 NB_OP_MODIFY, "false");
d62a17ae 2610
ff8a8a7a 2611 return nb_cli_apply_changes(vty, NULL);
718e3744 2612}
538621f2 2613
055679e9 2614/* "bgp graceful-restart mode" configuration. */
538621f2 2615DEFUN (bgp_graceful_restart,
2ba1fe69 2616 bgp_graceful_restart_cmd,
2617 "bgp graceful-restart",
2618 "BGP specific commands\n"
2619 GR_CMD
055679e9 2620 )
538621f2 2621{
055679e9 2622 int ret = BGP_GR_FAILURE;
2623
2624 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2625 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2626
d62a17ae 2627 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2628
2629 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2630
36235319
QY
2631 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2632 ret);
5cce3f05 2633
055679e9 2634 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2635 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2636 vty_out(vty,
2637 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2638 return bgp_vty_return(vty, ret);
538621f2 2639}
2640
2641DEFUN (no_bgp_graceful_restart,
2ba1fe69 2642 no_bgp_graceful_restart_cmd,
2643 "no bgp graceful-restart",
2644 NO_STR
2645 "BGP specific commands\n"
2646 NO_GR_CMD
055679e9 2647 )
538621f2 2648{
d62a17ae 2649 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2650
2651 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2652 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2653
2654 int ret = BGP_GR_FAILURE;
2655
2656 ret = bgp_gr_update_all(bgp, NO_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] no_bgp_graceful_restart_cmd : END ");
dc95985f 2663 vty_out(vty,
2664 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2665
2666 return bgp_vty_return(vty, ret);
538621f2 2667}
2668
93406d87 2669DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2670 bgp_graceful_restart_stalepath_time_cmd,
2671 "bgp graceful-restart stalepath-time (1-4095)",
2672 "BGP specific commands\n"
2673 "Graceful restart capability parameters\n"
2674 "Set the max time to hold onto restarting peer's stale paths\n"
2675 "Delay value (seconds)\n")
93406d87 2676{
d62a17ae 2677 VTY_DECLVAR_CONTEXT(bgp, bgp);
2678 int idx_number = 3;
d7c0a89a 2679 uint32_t stalepath;
93406d87 2680
d62a17ae 2681 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2682 bgp->stalepath_time = stalepath;
2683 return CMD_SUCCESS;
93406d87 2684}
2685
eb6f1b41 2686DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2687 bgp_graceful_restart_restart_time_cmd,
2688 "bgp graceful-restart restart-time (1-4095)",
2689 "BGP specific commands\n"
2690 "Graceful restart capability parameters\n"
2691 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2692 "Delay value (seconds)\n")
eb6f1b41 2693{
d62a17ae 2694 VTY_DECLVAR_CONTEXT(bgp, bgp);
2695 int idx_number = 3;
d7c0a89a 2696 uint32_t restart;
eb6f1b41 2697
d62a17ae 2698 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2699 bgp->restart_time = restart;
2700 return CMD_SUCCESS;
eb6f1b41
PG
2701}
2702
cfd47646 2703DEFUN (bgp_graceful_restart_select_defer_time,
2704 bgp_graceful_restart_select_defer_time_cmd,
2705 "bgp graceful-restart select-defer-time (0-3600)",
2706 "BGP specific commands\n"
2707 "Graceful restart capability parameters\n"
2708 "Set the time to defer the BGP route selection after restart\n"
2709 "Delay value (seconds, 0 - disable)\n")
2710{
2711 VTY_DECLVAR_CONTEXT(bgp, bgp);
2712 int idx_number = 3;
2713 uint32_t defer_time;
2714
2715 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2716 bgp->select_defer_time = defer_time;
2717 if (defer_time == 0)
892fedb6 2718 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2719 else
892fedb6 2720 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2721
2722 return CMD_SUCCESS;
2723}
2724
93406d87 2725DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2726 no_bgp_graceful_restart_stalepath_time_cmd,
2727 "no bgp graceful-restart stalepath-time [(1-4095)]",
2728 NO_STR
2729 "BGP specific commands\n"
2730 "Graceful restart capability parameters\n"
2731 "Set the max time to hold onto restarting peer's stale paths\n"
2732 "Delay value (seconds)\n")
93406d87 2733{
d62a17ae 2734 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2735
d62a17ae 2736 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2737 return CMD_SUCCESS;
93406d87 2738}
2739
eb6f1b41 2740DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2741 no_bgp_graceful_restart_restart_time_cmd,
2742 "no bgp graceful-restart restart-time [(1-4095)]",
2743 NO_STR
2744 "BGP specific commands\n"
2745 "Graceful restart capability parameters\n"
2746 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2747 "Delay value (seconds)\n")
eb6f1b41 2748{
d62a17ae 2749 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2750
d62a17ae 2751 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2752 return CMD_SUCCESS;
eb6f1b41
PG
2753}
2754
cfd47646 2755DEFUN (no_bgp_graceful_restart_select_defer_time,
2756 no_bgp_graceful_restart_select_defer_time_cmd,
2757 "no bgp graceful-restart select-defer-time [(0-3600)]",
2758 NO_STR
2759 "BGP specific commands\n"
2760 "Graceful restart capability parameters\n"
2761 "Set the time to defer the BGP route selection after restart\n"
2762 "Delay value (seconds)\n")
2763{
2764 VTY_DECLVAR_CONTEXT(bgp, bgp);
2765
2766 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2767 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2768
2769 return CMD_SUCCESS;
2770}
2771
43fc21b3 2772DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2773 bgp_graceful_restart_preserve_fw_cmd,
2774 "bgp graceful-restart preserve-fw-state",
2775 "BGP specific commands\n"
2776 "Graceful restart capability parameters\n"
2777 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2778{
d62a17ae 2779 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2780 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2781 return CMD_SUCCESS;
43fc21b3
JC
2782}
2783
2784DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2785 no_bgp_graceful_restart_preserve_fw_cmd,
2786 "no bgp graceful-restart preserve-fw-state",
2787 NO_STR
2788 "BGP specific commands\n"
2789 "Graceful restart capability parameters\n"
2790 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2791{
d62a17ae 2792 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2793 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2794 return CMD_SUCCESS;
43fc21b3
JC
2795}
2796
055679e9 2797DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2798 bgp_graceful_restart_disable_cmd,
2799 "bgp graceful-restart-disable",
2800 "BGP specific commands\n"
2801 GR_DISABLE)
055679e9 2802{
2803 int ret = BGP_GR_FAILURE;
2804
2805 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2806 zlog_debug(
2ba1fe69 2807 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2808
055679e9 2809 VTY_DECLVAR_CONTEXT(bgp, bgp);
2810
2811 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2812
dc95985f 2813 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2814 bgp->peer, ret);
5cce3f05 2815
055679e9 2816 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2817 zlog_debug(
2ba1fe69 2818 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2819 vty_out(vty,
2820 "Graceful restart configuration changed, reset all peers to take effect\n");
2821
055679e9 2822 return bgp_vty_return(vty, ret);
2823}
2824
2825DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2826 no_bgp_graceful_restart_disable_cmd,
2827 "no bgp graceful-restart-disable",
2828 NO_STR
2829 "BGP specific commands\n"
2830 NO_GR_DISABLE
055679e9 2831 )
2832{
2833 VTY_DECLVAR_CONTEXT(bgp, bgp);
2834
2835 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2836 zlog_debug(
2ba1fe69 2837 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2838
2839 int ret = BGP_GR_FAILURE;
2840
2841 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2842
36235319
QY
2843 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2844 ret);
5cce3f05 2845
055679e9 2846 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2847 zlog_debug(
2ba1fe69 2848 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2849 vty_out(vty,
2850 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2851
2852 return bgp_vty_return(vty, ret);
2853}
2854
2855DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2856 bgp_neighbor_graceful_restart_set_cmd,
2857 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2858 NEIGHBOR_STR
2859 NEIGHBOR_ADDR_STR2
2860 GR_NEIGHBOR_CMD
055679e9 2861 )
2862{
2863 int idx_peer = 1;
2864 struct peer *peer;
2865 int ret = BGP_GR_FAILURE;
2866
dc95985f 2867 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2868
055679e9 2869 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2870 zlog_debug(
2ba1fe69 2871 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2872
055679e9 2873 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2874 if (!peer)
2875 return CMD_WARNING_CONFIG_FAILED;
2876
2877 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2878
dc95985f 2879 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2880 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2881
2882 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2883 zlog_debug(
2ba1fe69 2884 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2885 vty_out(vty,
2886 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2887
2888 return bgp_vty_return(vty, ret);
2889}
2890
2891DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2892 no_bgp_neighbor_graceful_restart_set_cmd,
2893 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2894 NO_STR
2895 NEIGHBOR_STR
2896 NEIGHBOR_ADDR_STR2
2897 NO_GR_NEIGHBOR_CMD
055679e9 2898 )
2899{
2900 int idx_peer = 2;
2901 int ret = BGP_GR_FAILURE;
2902 struct peer *peer;
2903
dc95985f 2904 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2905
055679e9 2906 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2907 if (!peer)
2908 return CMD_WARNING_CONFIG_FAILED;
2909
2910 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2911 zlog_debug(
2ba1fe69 2912 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2913
2914 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2915
dc95985f 2916 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2917 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2918
2919 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2920 zlog_debug(
2ba1fe69 2921 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2922 vty_out(vty,
2923 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2924
2925 return bgp_vty_return(vty, ret);
2926}
2927
2928DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2929 bgp_neighbor_graceful_restart_helper_set_cmd,
2930 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2931 NEIGHBOR_STR
2932 NEIGHBOR_ADDR_STR2
2933 GR_NEIGHBOR_HELPER_CMD
055679e9 2934 )
2935{
2936 int idx_peer = 1;
2937 struct peer *peer;
2938 int ret = BGP_GR_FAILURE;
2939
dc95985f 2940 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2941
055679e9 2942 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2943 zlog_debug(
2ba1fe69 2944 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2945
055679e9 2946 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2947
055679e9 2948 if (!peer)
2949 return CMD_WARNING_CONFIG_FAILED;
2950
2951
2952 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2953
dc95985f 2954 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2955 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2956
055679e9 2957 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2958 zlog_debug(
2ba1fe69 2959 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2960 vty_out(vty,
2961 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2962
2963 return bgp_vty_return(vty, ret);
2964}
2965
2966DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2967 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2968 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2969 NO_STR
2970 NEIGHBOR_STR
2971 NEIGHBOR_ADDR_STR2
2972 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2973 )
2974{
2975 int idx_peer = 2;
2976 int ret = BGP_GR_FAILURE;
2977 struct peer *peer;
2978
dc95985f 2979 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2980
055679e9 2981 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2982 if (!peer)
2983 return CMD_WARNING_CONFIG_FAILED;
2984
2985 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2986 zlog_debug(
2ba1fe69 2987 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 2988
36235319 2989 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 2990
dc95985f 2991 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2992 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2993
2994 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2995 zlog_debug(
2ba1fe69 2996 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2997 vty_out(vty,
2998 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2999
3000 return bgp_vty_return(vty, ret);
3001}
3002
3003DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3004 bgp_neighbor_graceful_restart_disable_set_cmd,
3005 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3006 NEIGHBOR_STR
3007 NEIGHBOR_ADDR_STR2
3008 GR_NEIGHBOR_DISABLE_CMD
055679e9 3009 )
3010{
3011 int idx_peer = 1;
3012 struct peer *peer;
3013 int ret = BGP_GR_FAILURE;
3014
dc95985f 3015 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3016
055679e9 3017 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3018 zlog_debug(
2ba1fe69 3019 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3020
3021 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3022 if (!peer)
3023 return CMD_WARNING_CONFIG_FAILED;
3024
36235319 3025 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3026
3027 if (peer->bgp->t_startup)
3028 bgp_peer_gr_flags_update(peer);
3029
dc95985f 3030 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3031 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3032
055679e9 3033 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3034 zlog_debug(
2ba1fe69 3035 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3036 vty_out(vty,
3037 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3038
3039 return bgp_vty_return(vty, ret);
3040}
3041
3042DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3043 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3044 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3045 NO_STR
3046 NEIGHBOR_STR
3047 NEIGHBOR_ADDR_STR2
3048 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3049 )
3050{
3051 int idx_peer = 2;
3052 int ret = BGP_GR_FAILURE;
3053 struct peer *peer;
3054
dc95985f 3055 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3056
055679e9 3057 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3058 if (!peer)
3059 return CMD_WARNING_CONFIG_FAILED;
3060
3061 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3062 zlog_debug(
2ba1fe69 3063 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3064
3065 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3066
dc95985f 3067 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3068 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3069
3070 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3071 zlog_debug(
2ba1fe69 3072 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3073 vty_out(vty,
3074 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3075
3076 return bgp_vty_return(vty, ret);
3077}
3078
d6e3c15b 3079DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3080 bgp_graceful_restart_disable_eor_cmd,
3081 "bgp graceful-restart disable-eor",
3082 "BGP specific commands\n"
3083 "Graceful restart configuration parameters\n"
3084 "Disable EOR Check\n")
3085{
3086 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3087 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3088
d6e3c15b 3089 return CMD_SUCCESS;
3090}
3091
3092DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3093 no_bgp_graceful_restart_disable_eor_cmd,
3094 "no bgp graceful-restart disable-eor",
3095 NO_STR
3096 "BGP specific commands\n"
3097 "Graceful restart configuration parameters\n"
3098 "Disable EOR Check\n")
3099{
3100 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3101 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3102
3103 return CMD_SUCCESS;
3104}
3105
3106DEFUN (bgp_graceful_restart_rib_stale_time,
3107 bgp_graceful_restart_rib_stale_time_cmd,
3108 "bgp graceful-restart rib-stale-time (1-3600)",
3109 "BGP specific commands\n"
3110 "Graceful restart configuration parameters\n"
3111 "Specify the stale route removal timer in rib\n"
3112 "Delay value (seconds)\n")
3113{
3114 VTY_DECLVAR_CONTEXT(bgp, bgp);
3115 int idx_number = 3;
3116 uint32_t stale_time;
3117
3118 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3119 bgp->rib_stale_time = stale_time;
3120 /* Send the stale timer update message to RIB */
3121 if (bgp_zebra_stale_timer_update(bgp))
3122 return CMD_WARNING;
3123
3124 return CMD_SUCCESS;
3125}
3126
3127DEFUN (no_bgp_graceful_restart_rib_stale_time,
3128 no_bgp_graceful_restart_rib_stale_time_cmd,
3129 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3130 NO_STR
3131 "BGP specific commands\n"
3132 "Graceful restart configuration parameters\n"
3133 "Specify the stale route removal timer in rib\n"
3134 "Delay value (seconds)\n")
3135{
3136 VTY_DECLVAR_CONTEXT(bgp, bgp);
3137
3138 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3139 /* Send the stale timer update message to RIB */
3140 if (bgp_zebra_stale_timer_update(bgp))
3141 return CMD_WARNING;
3142
d6e3c15b 3143 return CMD_SUCCESS;
3144}
3145
ff8a8a7a
CS
3146static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3147 char *errmsg,
3148 size_t errmsg_len)
05bd726c 3149{
3150 bgp_static_redo_import_check(bgp);
3151 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
3152 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3153 return -1;
3154 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3155 return -1;
3156
3157 return 0;
05bd726c 3158}
3159
3160static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3161{
3162 struct listnode *node, *nnode;
3163 struct bgp *bgp;
3164 bool vrf_cfg = false;
ff8a8a7a 3165 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3166
3167 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3168 return CMD_SUCCESS;
3169
3170 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3171 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3172 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3173 vty_out(vty,
3174 "%% graceful-shutdown configuration found in vrf %s\n",
3175 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3176 VRF_DEFAULT_NAME : bgp->name);
3177 vrf_cfg = true;
3178 }
3179 }
3180
3181 if (vrf_cfg) {
3182 vty_out(vty,
3183 "%%Failed: global graceful-shutdown not permitted\n");
3184 return CMD_WARNING;
3185 }
3186
3187 /* Set flag globally */
3188 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3189
3190 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3191 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3192 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3193 sizeof(errmsg))
3194 < 0)
3195 if (strlen(errmsg))
3196 vty_out(vty, "%s\n", errmsg);
3197 }
05bd726c 3198
3199 return CMD_SUCCESS;
3200}
3201
3202static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3203{
3204 struct listnode *node, *nnode;
3205 struct bgp *bgp;
ff8a8a7a 3206 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3207
3208 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3209 return CMD_SUCCESS;
3210
3211 /* Unset flag globally */
3212 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3213
3214 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3215 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3216 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3217 sizeof(errmsg))
3218 < 0)
3219 if (strlen(errmsg))
3220 vty_out(vty, "%s\n", errmsg);
3221 }
05bd726c 3222
3223 return CMD_SUCCESS;
3224}
3225
7f323236
DW
3226/* "bgp graceful-shutdown" configuration */
3227DEFUN (bgp_graceful_shutdown,
3228 bgp_graceful_shutdown_cmd,
3229 "bgp graceful-shutdown",
3230 BGP_STR
3231 "Graceful shutdown parameters\n")
3232{
05bd726c 3233 if (vty->node == CONFIG_NODE)
3234 return bgp_global_graceful_shutdown_config_vty(vty);
3235
87ce2564
CS
3236 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3237 NB_OP_MODIFY, "true");
7f323236 3238
ff8a8a7a 3239 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3240}
3241
ff8a8a7a 3242DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3243 no_bgp_graceful_shutdown_cmd,
3244 "no bgp graceful-shutdown",
3245 NO_STR
3246 BGP_STR
3247 "Graceful shutdown parameters\n")
3248{
05bd726c 3249 if (vty->node == CONFIG_NODE)
3250 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3251
87ce2564
CS
3252 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3253 NB_OP_MODIFY, "false");
05bd726c 3254
ff8a8a7a
CS
3255 return nb_cli_apply_changes(vty, NULL);
3256}
7f323236 3257
ff8a8a7a
CS
3258void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3259 struct lyd_node *dnode,
3260 bool show_defaults)
3261{
3262 if (yang_dnode_get_bool(dnode, NULL))
3263 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3264}
3265
718e3744 3266/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3267DEFUN_YANG (bgp_fast_external_failover,
718e3744 3268 bgp_fast_external_failover_cmd,
3269 "bgp fast-external-failover",
3270 BGP_STR
3271 "Immediately reset session if a link to a directly connected external peer goes down\n")
3272{
87ce2564
CS
3273 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3274 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3275
3276 return nb_cli_apply_changes(vty, NULL);
718e3744 3277}
3278
ff8a8a7a 3279DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3280 no_bgp_fast_external_failover_cmd,
3281 "no bgp fast-external-failover",
3282 NO_STR
3283 BGP_STR
3284 "Immediately reset session if a link to a directly connected external peer goes down\n")
3285{
87ce2564
CS
3286 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3287 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3288
3289 return nb_cli_apply_changes(vty, NULL);
3290}
3291
3292void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3293 struct lyd_node *dnode,
3294 bool show_defaults)
3295{
3296 if (!yang_dnode_get_bool(dnode, NULL))
3297 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3298}
6b0655a2 3299
718e3744 3300/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3301DEFUN_YANG(bgp_bestpath_compare_router_id,
3302 bgp_bestpath_compare_router_id_cmd,
3303 "bgp bestpath compare-routerid",
3304 "BGP specific commands\n"
3305 "Change the default bestpath selection\n"
3306 "Compare router-id for identical EBGP paths\n")
718e3744 3307{
ff8a8a7a 3308 nb_cli_enqueue_change(
87ce2564
CS
3309 vty,
3310 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3311 NB_OP_MODIFY, "true");
7aafcaca 3312
ff8a8a7a 3313 return nb_cli_apply_changes(vty, NULL);
718e3744 3314}
3315
ff8a8a7a
CS
3316DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3317 no_bgp_bestpath_compare_router_id_cmd,
3318 "no bgp bestpath compare-routerid",
3319 NO_STR
3320 "BGP specific commands\n"
3321 "Change the default bestpath selection\n"
3322 "Compare router-id for identical EBGP paths\n")
718e3744 3323{
ff8a8a7a 3324 nb_cli_enqueue_change(
87ce2564
CS
3325 vty,
3326 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3327 NB_OP_MODIFY, "false");
7aafcaca 3328
ff8a8a7a 3329 return nb_cli_apply_changes(vty, NULL);
718e3744 3330}
6b0655a2 3331
718e3744 3332/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3333DEFUN_YANG(bgp_bestpath_aspath_ignore,
3334 bgp_bestpath_aspath_ignore_cmd,
3335 "bgp bestpath as-path ignore",
3336 "BGP specific commands\n"
3337 "Change the default bestpath selection\n"
3338 "AS-path attribute\n"
3339 "Ignore as-path length in selecting a route\n")
718e3744 3340{
87ce2564
CS
3341 nb_cli_enqueue_change(
3342 vty, "./global/route-selection-options/ignore-as-path-length",
3343 NB_OP_MODIFY, "true");
7aafcaca 3344
ff8a8a7a 3345 return nb_cli_apply_changes(vty, NULL);
718e3744 3346}
3347
ff8a8a7a
CS
3348DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3349 no_bgp_bestpath_aspath_ignore_cmd,
3350 "no bgp bestpath as-path ignore",
3351 NO_STR
3352 "BGP specific commands\n"
3353 "Change the default bestpath selection\n"
3354 "AS-path attribute\n"
3355 "Ignore as-path length in selecting a route\n")
718e3744 3356{
87ce2564
CS
3357 nb_cli_enqueue_change(
3358 vty, "./global/route-selection-options/ignore-as-path-length",
3359 NB_OP_MODIFY, "false");
7aafcaca 3360
ff8a8a7a 3361 return nb_cli_apply_changes(vty, NULL);
718e3744 3362}
6b0655a2 3363
6811845b 3364/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3365DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3366 bgp_bestpath_aspath_confed_cmd,
3367 "bgp bestpath as-path confed",
3368 "BGP specific commands\n"
3369 "Change the default bestpath selection\n"
3370 "AS-path attribute\n"
3371 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3372{
87ce2564
CS
3373 nb_cli_enqueue_change(vty,
3374 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3375 NB_OP_MODIFY, "true");
7aafcaca 3376
ff8a8a7a 3377 return nb_cli_apply_changes(vty, NULL);
6811845b 3378}
3379
ff8a8a7a 3380DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3381 no_bgp_bestpath_aspath_confed_cmd,
3382 "no bgp bestpath as-path confed",
3383 NO_STR
3384 "BGP specific commands\n"
3385 "Change the default bestpath selection\n"
3386 "AS-path attribute\n"
3387 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3388{
87ce2564
CS
3389 nb_cli_enqueue_change(vty,
3390 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3391 NB_OP_MODIFY, "false");
7aafcaca 3392
ff8a8a7a 3393 return nb_cli_apply_changes(vty, NULL);
6811845b 3394}
6b0655a2 3395
2fdd455c 3396/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3397DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3398 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3399 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3400 "BGP specific commands\n"
3401 "Change the default bestpath selection\n"
3402 "AS-path attribute\n"
3403 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3404 "Generate an AS_SET\n"
16fc1eec
DS
3405 "Do not generate an AS_SET\n")
3406{
d62a17ae 3407 int idx = 0;
219178b6 3408
87ce2564
CS
3409 nb_cli_enqueue_change(
3410 vty, "./global/route-selection-options/allow-multiple-as",
3411 NB_OP_MODIFY, "true");
d62a17ae 3412 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3413 nb_cli_enqueue_change(
87ce2564
CS
3414 vty,
3415 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3416 NB_OP_MODIFY, "true");
d62a17ae 3417 else
ff8a8a7a 3418 nb_cli_enqueue_change(
87ce2564
CS
3419 vty,
3420 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3421 NB_OP_MODIFY, "false");
7aafcaca 3422
ff8a8a7a 3423 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3424}
3425
ff8a8a7a 3426DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3427 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3428 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3429 NO_STR
3430 "BGP specific commands\n"
3431 "Change the default bestpath selection\n"
3432 "AS-path attribute\n"
3433 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3434 "Generate an AS_SET\n"
16fc1eec
DS
3435 "Do not generate an AS_SET\n")
3436{
87ce2564
CS
3437 nb_cli_enqueue_change(
3438 vty, "./global/route-selection-options/allow-multiple-as",
3439 NB_OP_MODIFY, "false");
3440 nb_cli_enqueue_change(
3441 vty, "./global/route-selection-options/multi-path-as-set",
3442 NB_OP_MODIFY, "false");
7aafcaca 3443
ff8a8a7a 3444 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3445}
6b0655a2 3446
848973c7 3447/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3448DEFUN_YANG(bgp_log_neighbor_changes,
3449 bgp_log_neighbor_changes_cmd,
3450 "bgp log-neighbor-changes",
3451 "BGP specific commands\n"
3452 "Log neighbor up/down and reset reason\n")
848973c7 3453{
87ce2564
CS
3454 nb_cli_enqueue_change(
3455 vty, "./global/global-neighbor-config/log-neighbor-changes",
3456 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3457
3458 return nb_cli_apply_changes(vty, NULL);
848973c7 3459}
3460
ff8a8a7a
CS
3461DEFUN_YANG(no_bgp_log_neighbor_changes,
3462 no_bgp_log_neighbor_changes_cmd,
3463 "no bgp log-neighbor-changes",
3464 NO_STR
3465 "BGP specific commands\n"
3466 "Log neighbor up/down and reset reason\n")
848973c7 3467{
87ce2564
CS
3468 nb_cli_enqueue_change(
3469 vty, "./global/global-neighbor-config/log-neighbor-changes",
3470 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3471
3472 return nb_cli_apply_changes(vty, NULL);
848973c7 3473}
6b0655a2 3474
718e3744 3475/* "bgp bestpath med" configuration. */
ff8a8a7a 3476DEFUN_YANG (bgp_bestpath_med,
718e3744 3477 bgp_bestpath_med_cmd,
2d8c1a4d 3478 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3479 "BGP specific commands\n"
3480 "Change the default bestpath selection\n"
3481 "MED attribute\n"
3482 "Compare MED among confederation paths\n"
838758ac
DW
3483 "Treat missing MED as the least preferred one\n"
3484 "Treat missing MED as the least preferred one\n"
3485 "Compare MED among confederation paths\n")
718e3744 3486{
d62a17ae 3487 int idx = 0;
ff8a8a7a
CS
3488 bool confed = false;
3489 bool worst_med = false;
3490
3491
d62a17ae 3492 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3493 confed = true;
3494
87ce2564
CS
3495 nb_cli_enqueue_change(vty,
3496 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3497 NB_OP_MODIFY, confed ? "true" : "false");
3498
d62a17ae 3499 idx = 0;
3500 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3501 worst_med = true;
e52702f2 3502
87ce2564
CS
3503 nb_cli_enqueue_change(
3504 vty, "./global/route-selection-options/missing-as-worst-med",
3505 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3506
ff8a8a7a 3507 return nb_cli_apply_changes(vty, NULL);
718e3744 3508}
3509
ff8a8a7a 3510DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3511 no_bgp_bestpath_med_cmd,
2d8c1a4d 3512 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3513 NO_STR
3514 "BGP specific commands\n"
3515 "Change the default bestpath selection\n"
3516 "MED attribute\n"
3517 "Compare MED among confederation paths\n"
3a2d747c
QY
3518 "Treat missing MED as the least preferred one\n"
3519 "Treat missing MED as the least preferred one\n"
3520 "Compare MED among confederation paths\n")
718e3744 3521{
d62a17ae 3522 int idx = 0;
ff8a8a7a 3523
d62a17ae 3524 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3525 nb_cli_enqueue_change(
3526 vty, "./global/route-selection-options/confed-med",
3527 NB_OP_MODIFY, "false");
ff8a8a7a 3528
d62a17ae 3529 idx = 0;
3530 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3531 nb_cli_enqueue_change(
87ce2564
CS
3532 vty,
3533 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3534 NB_OP_MODIFY, "false");
718e3744 3535
ff8a8a7a 3536 return nb_cli_apply_changes(vty, NULL);
718e3744 3537}
3538
f7e1c681 3539/* "bgp bestpath bandwidth" configuration. */
3540DEFPY (bgp_bestpath_bw,
3541 bgp_bestpath_bw_cmd,
ad36d216 3542 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3543 "BGP specific commands\n"
3544 "Change the default bestpath selection\n"
3545 "Link Bandwidth attribute\n"
3546 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3547 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3548 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3549{
3550 VTY_DECLVAR_CONTEXT(bgp, bgp);
3551 afi_t afi;
3552 safi_t safi;
3553
ad36d216
DS
3554 if (!bw_cfg) {
3555 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3556 return CMD_ERR_INCOMPLETE;
f7e1c681 3557 }
ad36d216
DS
3558 if (!strcmp(bw_cfg, "ignore"))
3559 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3560 else if (!strcmp(bw_cfg, "skip-missing"))
3561 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3562 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3563 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3564 else
3565 return CMD_ERR_NO_MATCH;
f7e1c681 3566
3567 /* This config is used in route install, so redo that. */
3568 FOREACH_AFI_SAFI (afi, safi) {
3569 if (!bgp_fibupd_safi(safi))
3570 continue;
3571 bgp_zebra_announce_table(bgp, afi, safi);
3572 }
3573
3574 return CMD_SUCCESS;
3575}
3576
ad36d216
DS
3577DEFPY (no_bgp_bestpath_bw,
3578 no_bgp_bestpath_bw_cmd,
3579 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3580 NO_STR
3581 "BGP specific commands\n"
3582 "Change the default bestpath selection\n"
3583 "Link Bandwidth attribute\n"
3584 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3585 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3586 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3587{
3588 VTY_DECLVAR_CONTEXT(bgp, bgp);
3589 afi_t afi;
3590 safi_t safi;
3591
3592 bgp->lb_handling = BGP_LINK_BW_ECMP;
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 return CMD_SUCCESS;
3601}
3602
718e3744 3603/* "no bgp default ipv4-unicast". */
3604DEFUN (no_bgp_default_ipv4_unicast,
3605 no_bgp_default_ipv4_unicast_cmd,
3606 "no bgp default ipv4-unicast",
3607 NO_STR
3608 "BGP specific commands\n"
3609 "Configure BGP defaults\n"
3610 "Activate ipv4-unicast for a peer by default\n")
3611{
d62a17ae 3612 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3613 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3614 return CMD_SUCCESS;
718e3744 3615}
3616
3617DEFUN (bgp_default_ipv4_unicast,
3618 bgp_default_ipv4_unicast_cmd,
3619 "bgp default ipv4-unicast",
3620 "BGP specific commands\n"
3621 "Configure BGP defaults\n"
3622 "Activate ipv4-unicast for a peer by default\n")
3623{
d62a17ae 3624 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3625 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3626 return CMD_SUCCESS;
718e3744 3627}
6b0655a2 3628
04b6bdc0 3629/* Display hostname in certain command outputs */
ff8a8a7a 3630DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3631 bgp_default_show_hostname_cmd,
3632 "bgp default show-hostname",
3633 "BGP specific commands\n"
3634 "Configure BGP defaults\n"
0437e105 3635 "Show hostname in certain command outputs\n")
04b6bdc0 3636{
87ce2564
CS
3637 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3638 "true");
ff8a8a7a
CS
3639
3640 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3641}
3642
ff8a8a7a
CS
3643DEFUN_YANG(no_bgp_default_show_hostname,
3644 no_bgp_default_show_hostname_cmd,
3645 "no bgp default show-hostname",
3646 NO_STR
3647 "BGP specific commands\n"
3648 "Configure BGP defaults\n"
3649 "Show hostname in certain command outputs\n")
04b6bdc0 3650{
87ce2564
CS
3651 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3652 "false");
ff8a8a7a
CS
3653
3654 return nb_cli_apply_changes(vty, NULL);
3655}
3656
3657void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3658 bool show_defaults)
3659{
3660 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3661 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3662}
3663
aef999a2
DA
3664/* Display hostname in certain command outputs */
3665DEFUN (bgp_default_show_nexthop_hostname,
3666 bgp_default_show_nexthop_hostname_cmd,
3667 "bgp default show-nexthop-hostname",
3668 "BGP specific commands\n"
3669 "Configure BGP defaults\n"
3670 "Show hostname for nexthop in certain command outputs\n")
3671{
87ce2564
CS
3672 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3673 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3674
3675 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3676}
3677
3678DEFUN (no_bgp_default_show_nexthop_hostname,
3679 no_bgp_default_show_nexthop_hostname_cmd,
3680 "no bgp default show-nexthop-hostname",
3681 NO_STR
3682 "BGP specific commands\n"
3683 "Configure BGP defaults\n"
3684 "Show hostname for nexthop in certain command outputs\n")
3685{
87ce2564
CS
3686 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3687 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3688
3689 return nb_cli_apply_changes(vty, NULL);
3690}
3691
3692void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3693 struct lyd_node *dnode,
3694 bool show_defaults)
3695{
3696 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3697 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3698}
3699
8233ef81 3700/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3701DEFUN_YANG(bgp_network_import_check,
3702 bgp_network_import_check_cmd,
3703 "bgp network import-check",
3704 "BGP specific commands\n"
3705 "BGP network command\n"
3706 "Check BGP network route exists in IGP\n")
718e3744 3707{
87ce2564
CS
3708 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3709 "true");
078430f6 3710
ff8a8a7a 3711 return nb_cli_apply_changes(vty, NULL);
718e3744 3712}
3713
d62a17ae 3714ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3715 "bgp network import-check exact",
3716 "BGP specific commands\n"
3717 "BGP network command\n"
3718 "Check BGP network route exists in IGP\n"
3719 "Match route precisely\n")
8233ef81 3720
ff8a8a7a
CS
3721DEFUN_YANG(no_bgp_network_import_check,
3722 no_bgp_network_import_check_cmd,
3723 "no bgp network import-check",
3724 NO_STR
3725 "BGP specific commands\n"
3726 "BGP network command\n"
3727 "Check BGP network route exists in IGP\n")
718e3744 3728{
87ce2564
CS
3729 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3730 "false");
5623e905 3731
ff8a8a7a 3732 return nb_cli_apply_changes(vty, NULL);
718e3744 3733}
6b0655a2 3734
ff8a8a7a
CS
3735void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3736 bool show_defaults)
718e3744 3737{
ff8a8a7a
CS
3738 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3739 vty_out(vty, " bgp network import-check\n");
3740}
718e3744 3741
ff8a8a7a
CS
3742DEFUN_YANG(bgp_default_local_preference,
3743 bgp_default_local_preference_cmd,
3744 "bgp default local-preference (0-4294967295)",
3745 "BGP specific commands\n"
3746 "Configure BGP defaults\n"
3747 "local preference (higher=more preferred)\n"
3748 "Configure default local preference value\n")
3749{
3750 int idx_number = 3;
718e3744 3751
87ce2564 3752 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3753 argv[idx_number]->arg);
718e3744 3754
ff8a8a7a 3755 return nb_cli_apply_changes(vty, NULL);
718e3744 3756}
3757
ff8a8a7a
CS
3758DEFUN_YANG(no_bgp_default_local_preference,
3759 no_bgp_default_local_preference_cmd,
3760 "no bgp default local-preference [(0-4294967295)]",
3761 NO_STR
3762 "BGP specific commands\n"
3763 "Configure BGP defaults\n"
3764 "local preference (higher=more preferred)\n"
3765 "Configure default local preference value\n")
718e3744 3766{
87ce2564 3767 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 3768
ff8a8a7a 3769 return nb_cli_apply_changes(vty, NULL);
718e3744 3770}
3771
ff8a8a7a
CS
3772void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3773 bool show_defaults)
3774{
3775 vty_out(vty, " bgp default local-preference %u\n",
3776 yang_dnode_get_uint32(dnode, NULL));
3777}
6b0655a2 3778
ff8a8a7a
CS
3779
3780DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3781 bgp_default_subgroup_pkt_queue_max_cmd,
3782 "bgp default subgroup-pkt-queue-max (20-100)",
3783 "BGP specific commands\n"
3784 "Configure BGP defaults\n"
3785 "subgroup-pkt-queue-max\n"
3786 "Configure subgroup packet queue max\n")
8bd9d948 3787{
d62a17ae 3788 int idx_number = 3;
3f9c7369 3789
ff8a8a7a 3790 nb_cli_enqueue_change(
87ce2564
CS
3791 vty,
3792 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 3793 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 3794
ff8a8a7a 3795 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
3796}
3797
ff8a8a7a
CS
3798DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3799 no_bgp_default_subgroup_pkt_queue_max_cmd,
3800 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3801 NO_STR
3802 "BGP specific commands\n"
3803 "Configure BGP defaults\n"
3804 "subgroup-pkt-queue-max\n"
3805 "Configure subgroup packet queue max\n")
3f9c7369 3806{
ff8a8a7a 3807 nb_cli_enqueue_change(
87ce2564
CS
3808 vty,
3809 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
3810 NB_OP_MODIFY, NULL);
3811
3812 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3813}
3814
ff8a8a7a
CS
3815void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3816 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3817{
3818 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3819 yang_dnode_get_uint32(dnode, NULL));
3820}
813d4307 3821
ff8a8a7a
CS
3822DEFUN_YANG(bgp_rr_allow_outbound_policy,
3823 bgp_rr_allow_outbound_policy_cmd,
3824 "bgp route-reflector allow-outbound-policy",
3825 "BGP specific commands\n"
3826 "Allow modifications made by out route-map\n"
3827 "on ibgp neighbors\n")
8bd9d948 3828{
87ce2564
CS
3829 nb_cli_enqueue_change(vty,
3830 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 3831 NB_OP_MODIFY, "true");
8bd9d948 3832
ff8a8a7a
CS
3833 return nb_cli_apply_changes(vty, NULL);
3834}
8bd9d948 3835
ff8a8a7a
CS
3836DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3837 no_bgp_rr_allow_outbound_policy_cmd,
3838 "no bgp route-reflector allow-outbound-policy",
3839 NO_STR
3840 "BGP specific commands\n"
3841 "Allow modifications made by out route-map\n"
3842 "on ibgp neighbors\n")
3843{
87ce2564
CS
3844 nb_cli_enqueue_change(vty,
3845 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
3846 NB_OP_MODIFY, "false");
3847
3848 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3849}
3850
ff8a8a7a
CS
3851
3852void cli_show_router_global_neighbor_config(struct vty *vty,
3853 struct lyd_node *dnode,
3854 bool show_defaults)
8bd9d948 3855{
ff8a8a7a
CS
3856 uint32_t write_quanta, read_quanta;
3857
3858 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3859 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 3860
ff8a8a7a
CS
3861 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3862 uint32_t listen_limit = yang_dnode_get_uint32(
3863 dnode, "./dynamic-neighbors-limit");
3864 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 3865 }
8bd9d948 3866
ff8a8a7a
CS
3867 write_quanta = yang_dnode_get_uint32(
3868 dnode, "./packet-quanta-config/wpkt-quanta");
3869 if (write_quanta != BGP_WRITE_PACKET_MAX)
3870 vty_out(vty, " write-quanta %d\n", write_quanta);
3871
3872 read_quanta = yang_dnode_get_uint32(
3873 dnode, "./packet-quanta-config/rpkt-quanta");
3874
3875 if (read_quanta != BGP_READ_PACKET_MAX)
3876 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
3877}
3878
ff8a8a7a
CS
3879DEFUN_YANG(bgp_listen_limit,
3880 bgp_listen_limit_cmd,
3881 "bgp listen limit (1-5000)",
3882 "BGP specific commands\n"
3883 "BGP Dynamic Neighbors listen commands\n"
3884 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3885 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3886{
d62a17ae 3887 int idx_number = 3;
f14e6fdb 3888
ff8a8a7a 3889 nb_cli_enqueue_change(
87ce2564 3890 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 3891 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 3892
ff8a8a7a 3893 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3894}
3895
ff8a8a7a
CS
3896DEFUN_YANG(no_bgp_listen_limit,
3897 no_bgp_listen_limit_cmd,
3898 "no bgp listen limit [(1-5000)]",
3899 NO_STR
3900 "BGP specific commands\n"
3901 "BGP Dynamic Neighbors listen commands\n"
3902 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3903 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3904{
ff8a8a7a 3905 nb_cli_enqueue_change(
87ce2564 3906 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
3907 NB_OP_DESTROY, NULL);
3908
3909 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3910}
3911
3912
20eb8864 3913/*
3914 * Check if this listen range is already configured. Check for exact
3915 * match or overlap based on input.
3916 */
d62a17ae 3917static struct peer_group *listen_range_exists(struct bgp *bgp,
3918 struct prefix *range, int exact)
3919{
3920 struct listnode *node, *nnode;
3921 struct listnode *node1, *nnode1;
3922 struct peer_group *group;
3923 struct prefix *lr;
3924 afi_t afi;
3925 int match;
3926
3927 afi = family2afi(range->family);
3928 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3929 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3930 lr)) {
3931 if (exact)
3932 match = prefix_same(range, lr);
3933 else
3934 match = (prefix_match(range, lr)
3935 || prefix_match(lr, range));
3936 if (match)
3937 return group;
3938 }
3939 }
3940
3941 return NULL;
20eb8864 3942}
3943
f14e6fdb
DS
3944DEFUN (bgp_listen_range,
3945 bgp_listen_range_cmd,
d7b9898c 3946 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3947 "BGP specific commands\n"
d7fa34c1
QY
3948 "Configure BGP dynamic neighbors listen range\n"
3949 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3950 NEIGHBOR_ADDR_STR
3951 "Member of the peer-group\n"
3952 "Peer-group name\n")
f14e6fdb 3953{
d62a17ae 3954 VTY_DECLVAR_CONTEXT(bgp, bgp);
3955 struct prefix range;
3956 struct peer_group *group, *existing_group;
3957 afi_t afi;
3958 int ret;
3959 int idx = 0;
3960
3961 argv_find(argv, argc, "A.B.C.D/M", &idx);
3962 argv_find(argv, argc, "X:X::X:X/M", &idx);
3963 char *prefix = argv[idx]->arg;
d7b9898c 3964 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3965 char *peergroup = argv[idx]->arg;
3966
3967 /* Convert IP prefix string to struct prefix. */
3968 ret = str2prefix(prefix, &range);
3969 if (!ret) {
3970 vty_out(vty, "%% Malformed listen range\n");
3971 return CMD_WARNING_CONFIG_FAILED;
3972 }
3973
3974 afi = family2afi(range.family);
3975
3976 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3977 vty_out(vty,
3978 "%% Malformed listen range (link-local address)\n");
3979 return CMD_WARNING_CONFIG_FAILED;
3980 }
3981
3982 apply_mask(&range);
3983
3984 /* Check if same listen range is already configured. */
3985 existing_group = listen_range_exists(bgp, &range, 1);
3986 if (existing_group) {
3987 if (strcmp(existing_group->name, peergroup) == 0)
3988 return CMD_SUCCESS;
3989 else {
3990 vty_out(vty,
3991 "%% Same listen range is attached to peer-group %s\n",
3992 existing_group->name);
3993 return CMD_WARNING_CONFIG_FAILED;
3994 }
3995 }
3996
3997 /* Check if an overlapping listen range exists. */
3998 if (listen_range_exists(bgp, &range, 0)) {
3999 vty_out(vty,
4000 "%% Listen range overlaps with existing listen range\n");
4001 return CMD_WARNING_CONFIG_FAILED;
4002 }
4003
4004 group = peer_group_lookup(bgp, peergroup);
4005 if (!group) {
4006 vty_out(vty, "%% Configure the peer-group first\n");
4007 return CMD_WARNING_CONFIG_FAILED;
4008 }
4009
4010 ret = peer_group_listen_range_add(group, &range);
4011 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4012}
4013
4014DEFUN (no_bgp_listen_range,
4015 no_bgp_listen_range_cmd,
d7b9898c 4016 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4017 NO_STR
f14e6fdb 4018 "BGP specific commands\n"
d7fa34c1
QY
4019 "Unconfigure BGP dynamic neighbors listen range\n"
4020 "Unconfigure BGP dynamic neighbors listen range\n"
4021 NEIGHBOR_ADDR_STR
4022 "Member of the peer-group\n"
4023 "Peer-group name\n")
f14e6fdb 4024{
d62a17ae 4025 VTY_DECLVAR_CONTEXT(bgp, bgp);
4026 struct prefix range;
4027 struct peer_group *group;
4028 afi_t afi;
4029 int ret;
4030 int idx = 0;
4031
4032 argv_find(argv, argc, "A.B.C.D/M", &idx);
4033 argv_find(argv, argc, "X:X::X:X/M", &idx);
4034 char *prefix = argv[idx]->arg;
21d88a71 4035 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4036 char *peergroup = argv[idx]->arg;
4037
4038 /* Convert IP prefix string to struct prefix. */
4039 ret = str2prefix(prefix, &range);
4040 if (!ret) {
4041 vty_out(vty, "%% Malformed listen range\n");
4042 return CMD_WARNING_CONFIG_FAILED;
4043 }
4044
4045 afi = family2afi(range.family);
4046
4047 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4048 vty_out(vty,
4049 "%% Malformed listen range (link-local address)\n");
4050 return CMD_WARNING_CONFIG_FAILED;
4051 }
4052
4053 apply_mask(&range);
4054
4055 group = peer_group_lookup(bgp, peergroup);
4056 if (!group) {
4057 vty_out(vty, "%% Peer-group does not exist\n");
4058 return CMD_WARNING_CONFIG_FAILED;
4059 }
4060
4061 ret = peer_group_listen_range_del(group, &range);
4062 return bgp_vty_return(vty, ret);
4063}
4064
2b791107 4065void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4066{
4067 struct peer_group *group;
4068 struct listnode *node, *nnode, *rnode, *nrnode;
4069 struct prefix *range;
4070 afi_t afi;
d62a17ae 4071
4072 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4073 vty_out(vty, " bgp listen limit %d\n",
4074 bgp->dynamic_neighbors_limit);
4075
4076 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4077 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4078 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4079 nrnode, range)) {
d62a17ae 4080 vty_out(vty,
2dbe669b
DA
4081 " bgp listen range %pFX peer-group %s\n",
4082 range, group->name);
d62a17ae 4083 }
4084 }
4085 }
f14e6fdb
DS
4086}
4087
4088
ff8a8a7a
CS
4089DEFUN_YANG(bgp_disable_connected_route_check,
4090 bgp_disable_connected_route_check_cmd,
4091 "bgp disable-ebgp-connected-route-check",
4092 "BGP specific commands\n"
4093 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4094{
87ce2564
CS
4095 nb_cli_enqueue_change(vty,
4096 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4097 NB_OP_MODIFY, "true");
7aafcaca 4098
ff8a8a7a 4099 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
4100}
4101
ff8a8a7a
CS
4102DEFUN_YANG(no_bgp_disable_connected_route_check,
4103 no_bgp_disable_connected_route_check_cmd,
4104 "no bgp disable-ebgp-connected-route-check",
4105 NO_STR
4106 "BGP specific commands\n"
4107 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4108{
87ce2564
CS
4109 nb_cli_enqueue_change(vty,
4110 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4111 NB_OP_MODIFY, "false");
d62a17ae 4112
ff8a8a7a 4113 return nb_cli_apply_changes(vty, NULL);
d62a17ae 4114}
4115
ff8a8a7a
CS
4116void cli_show_router_global_ebgp_multihop_connected_route_check(
4117 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4118{
4119 if (yang_dnode_get_bool(dnode, NULL))
4120 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4121}
d62a17ae 4122
ff8a8a7a
CS
4123DEFUN_YANG(bgp_default_shutdown,
4124 bgp_default_shutdown_cmd,
4125 "[no] bgp default shutdown",
4126 NO_STR BGP_STR
4127 "Configure BGP defaults\n"
4128 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4129{
87ce2564 4130 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4131 strmatch(argv[0]->text, "no") ? "false" : "true");
4132
4133 return nb_cli_apply_changes(vty, NULL);
4134}
4135
4136void cli_show_router_bgp_default_shutdown(struct vty *vty,
4137 struct lyd_node *dnode,
4138 bool show_defaults)
4139{
4140 if (yang_dnode_get_bool(dnode, NULL))
4141 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4142}
4143
736b68f3
DS
4144DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4145 BGP_STR
9ddf4b81 4146 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4147 "Add a shutdown message (RFC 8203)\n"
4148 "Shutdown message\n")
9cf59432 4149{
736b68f3 4150 char *msgstr = NULL;
8389c83a 4151
9cf59432
DS
4152 VTY_DECLVAR_CONTEXT(bgp, bgp);
4153
8389c83a 4154 if (argc > 3)
f80e35b6 4155 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4156
4157 bgp_shutdown_enable(bgp, msgstr);
4158 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4159
4160 return CMD_SUCCESS;
4161}
4162
736b68f3 4163DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4164 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4165{
4166 VTY_DECLVAR_CONTEXT(bgp, bgp);
4167
4168 bgp_shutdown_enable(bgp, NULL);
4169
4170 return CMD_SUCCESS;
4171}
8389c83a 4172
736b68f3 4173DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4174 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4175{
4176 VTY_DECLVAR_CONTEXT(bgp, bgp);
4177
4178 bgp_shutdown_disable(bgp);
4179
4180 return CMD_SUCCESS;
4181}
4182
9ddf4b81 4183ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4184 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4185 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4186 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4187
f4b8ec07
CS
4188DEFUN_YANG(neighbor_remote_as,
4189 neighbor_remote_as_cmd,
4190 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4191 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4192 "Specify a BGP neighbor\n" AS_STR
4193 "Internal BGP peer\n"
4194 "External BGP peer\n")
718e3744 4195{
d62a17ae 4196 int idx_peer = 1;
4197 int idx_remote_as = 3;
f4b8ec07
CS
4198 char base_xpath[XPATH_MAXLEN];
4199 char unnbr_xpath[XPATH_MAXLEN];
4200 char prgrp_xpath[XPATH_MAXLEN];
4201 union sockunion su;
4202 const char *as_type_str = "as-specified";
4203
4204 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4205 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4206 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4207
4208 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4209 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4210
4211 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4212 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4213 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4214 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4215 "%s%s", VTY_CURR_XPATH,
4216 prgrp_xpath + 1)) {
4217 snprintf(base_xpath, sizeof(base_xpath),
4218 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4219 "");
4220 } else {
4221 vty_out(vty,
4222 "%% Create the peer-group or interface first\n");
4223 return CMD_WARNING_CONFIG_FAILED;
4224 }
4225 } else {
4226 snprintf(base_xpath, sizeof(base_xpath),
4227 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4228 }
4229
4230 if (argv[idx_remote_as]->arg[0] == 'i') {
4231 as_type_str = "internal";
4232 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4233 as_type_str = "external";
4234 } else {
4235 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4236 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4237 }
4238 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4239 NB_OP_MODIFY, as_type_str);
4240
4241 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4242}
4243
f4b8ec07
CS
4244int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4245 safi_t safi, bool v6only,
4246 const char *peer_group_name, int as_type,
4247 as_t as, char *errmsg, size_t errmsg_len)
d62a17ae 4248{
d62a17ae 4249 struct peer *peer;
4250 struct peer_group *group;
4251 int ret = 0;
4252 union sockunion su;
4253
4254 group = peer_group_lookup(bgp, conf_if);
4255
4256 if (group) {
f4b8ec07
CS
4257 snprintf(errmsg, errmsg_len,
4258 "Name conflict with peer-group \n");
4259 return -1;
d62a17ae 4260 }
4261
4262 peer = peer_lookup_by_conf_if(bgp, conf_if);
4263 if (peer) {
f4b8ec07 4264 if (as_type != AS_UNSPECIFIED)
cc4d4ce8 4265 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 4266 afi, safi);
4267 } else {
892fedb6 4268 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 4269 && afi == AFI_IP && safi == SAFI_UNICAST)
4270 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4271 as_type, 0, 0, NULL);
4272 else
4273 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4274 as_type, afi, safi, NULL);
4275
4276 if (!peer) {
f4b8ec07
CS
4277 snprintf(errmsg, errmsg_len,
4278 "BGP failed to create peer\n");
4279 return -1;
d62a17ae 4280 }
4281
4282 if (v6only)
527de3dc 4283 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4284
4285 /* Request zebra to initiate IPv6 RAs on this interface. We do
4286 * this
4287 * any unnumbered peer in order to not worry about run-time
4288 * transitions
4289 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4290 * address
4291 * gets deleted later etc.)
4292 */
4293 if (peer->ifp)
4294 bgp_zebra_initiate_radv(bgp, peer);
4295 }
4296
4297 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4298 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4299 if (v6only)
527de3dc 4300 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4301 else
527de3dc 4302 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4303
4304 /* v6only flag changed. Reset bgp seesion */
4305 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4306 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4307 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4308 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4309 } else
4310 bgp_session_reset(peer);
4311 }
4312
9fb964de
PM
4313 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4314 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4315 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4316 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4317 }
d62a17ae 4318
4319 if (peer_group_name) {
4320 group = peer_group_lookup(bgp, peer_group_name);
4321 if (!group) {
f4b8ec07
CS
4322 snprintf(errmsg, errmsg_len,
4323 "Configure the peer-group first\n");
4324 return -1;
d62a17ae 4325 }
4326
4327 ret = peer_group_bind(bgp, &su, peer, group, &as);
4328 }
4329
f4b8ec07 4330 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
a80beece
DS
4331}
4332
f4b8ec07
CS
4333DEFUN_YANG(neighbor_interface_config, neighbor_interface_config_cmd,
4334 "neighbor WORD interface [peer-group PGNAME]",
4335 NEIGHBOR_STR
4336 "Interface name or neighbor tag\n"
4337 "Enable BGP on interface\n"
4338 "Member of the peer-group\n"
4339 "Peer-group name\n")
4c48cf63 4340{
d62a17ae 4341 int idx_word = 1;
4342 int idx_peer_group_word = 4;
f4b8ec07
CS
4343 char base_xpath[XPATH_MAXLEN];
4344
4345 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4346 argv[idx_word]->arg, "");
31500417 4347
f4b8ec07 4348 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4349 if (argc > idx_peer_group_word)
f4b8ec07
CS
4350 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4351 argv[idx_peer_group_word]->arg);
4352
4353 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4354}
4355
f4b8ec07
CS
4356DEFUN_YANG(neighbor_interface_config_v6only,
4357 neighbor_interface_config_v6only_cmd,
4358 "neighbor WORD interface v6only [peer-group PGNAME]",
4359 NEIGHBOR_STR
4360 "Interface name or neighbor tag\n"
4361 "Enable BGP on interface\n"
4362 "Enable BGP with v6 link-local only\n"
4363 "Member of the peer-group\n"
4364 "Peer-group name\n")
4c48cf63 4365{
d62a17ae 4366 int idx_word = 1;
4367 int idx_peer_group_word = 5;
f4b8ec07
CS
4368 char base_xpath[XPATH_MAXLEN];
4369
4370 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4371 argv[idx_word]->arg, "");
31500417 4372
f4b8ec07 4373 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4374 if (argc > idx_peer_group_word)
f4b8ec07
CS
4375 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4376 argv[idx_peer_group_word]->arg);
31500417 4377
f4b8ec07
CS
4378 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4379
4380 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4381}
4382
a80beece 4383
f4b8ec07
CS
4384DEFUN_YANG(
4385 neighbor_interface_config_remote_as,
4386 neighbor_interface_config_remote_as_cmd,
4387 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4388 NEIGHBOR_STR
4389 "Interface name or neighbor tag\n"
4390 "Enable BGP on interface\n"
4391 "Specify a BGP neighbor\n" AS_STR
4392 "Internal BGP peer\n"
4393 "External BGP peer\n")
b3a39dc5 4394{
d62a17ae 4395 int idx_word = 1;
4396 int idx_remote_as = 4;
f4b8ec07
CS
4397 char base_xpath[XPATH_MAXLEN];
4398 const char *as_type_str = "as-specified";
4399
4400 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4401 argv[idx_word]->arg, "");
4402
4403 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4404
4405 if (argv[idx_remote_as]->arg[0] == 'i') {
4406 as_type_str = "internal";
4407 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4408 as_type_str = "external";
4409 } else {
4410 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4411 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4412 }
4413 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4414 NB_OP_MODIFY, as_type_str);
4415
4416 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4417}
4418
f4b8ec07
CS
4419DEFUN_YANG(
4420 neighbor_interface_v6only_config_remote_as,
4421 neighbor_interface_v6only_config_remote_as_cmd,
4422 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4423 NEIGHBOR_STR
4424 "Interface name or neighbor tag\n"
4425 "Enable BGP with v6 link-local only\n"
4426 "Enable BGP on interface\n"
4427 "Specify a BGP neighbor\n" AS_STR
4428 "Internal BGP peer\n"
4429 "External BGP peer\n")
b3a39dc5 4430{
d62a17ae 4431 int idx_word = 1;
4432 int idx_remote_as = 5;
f4b8ec07
CS
4433 char base_xpath[XPATH_MAXLEN];
4434 const char *as_type_str = "as-specified";
4435
4436 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4437 argv[idx_word]->arg, "");
4438
4439 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4440
4441 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4442
4443 if (argv[idx_remote_as]->arg[0] == 'i') {
4444 as_type_str = "internal";
4445 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4446 as_type_str = "external";
4447 } else {
4448 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4449 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4450 }
4451 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4452 NB_OP_MODIFY, as_type_str);
4453
4454 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4455}
4456
f4b8ec07
CS
4457DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4458 "neighbor WORD peer-group",
4459 NEIGHBOR_STR
4460 "Interface name or neighbor tag\n"
4461 "Configure peer-group\n")
718e3744 4462{
f4b8ec07 4463 char base_xpath[XPATH_MAXLEN];
d62a17ae 4464 int idx_word = 1;
718e3744 4465
f4b8ec07
CS
4466 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4467 argv[idx_word]->arg, "");
718e3744 4468
f4b8ec07 4469 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 4470
f4b8ec07 4471 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4472}
4473
4474DEFUN (no_neighbor,
4475 no_neighbor_cmd,
dab8cd00 4476 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 4477 NO_STR
4478 NEIGHBOR_STR
3a2d747c
QY
4479 NEIGHBOR_ADDR_STR2
4480 "Specify a BGP neighbor\n"
4481 AS_STR
4482 "Internal BGP peer\n"
4483 "External BGP peer\n")
718e3744 4484{
d62a17ae 4485 int idx_peer = 2;
f4b8ec07
CS
4486 char base_xpath[XPATH_MAXLEN];
4487 char num_xpath[XPATH_MAXLEN];
4488 char unnbr_xpath[XPATH_MAXLEN];
4489 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4490 union sockunion su;
d62a17ae 4491
f4b8ec07
CS
4492 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4493 snprintf(num_xpath, sizeof(num_xpath),
4494 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4495 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4496 VTY_CURR_XPATH, num_xpath + 1)) {
4497 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
d62a17ae 4498 }
f4b8ec07
CS
4499 } else {
4500 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4501 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4502
4503 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4504 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4505
4506 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4507 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4508 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4509 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4510 "%s%s", VTY_CURR_XPATH,
4511 prgrp_xpath + 1)) {
4512 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4e2786df 4513 } else {
f4b8ec07
CS
4514 vty_out(vty,
4515 "%% Create the peer-group or interface first\n");
d62a17ae 4516 return CMD_WARNING_CONFIG_FAILED;
4517 }
1ff9a340 4518 }
718e3744 4519
f4b8ec07
CS
4520 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4521
4522 return nb_cli_apply_changes(vty, NULL);
718e3744 4523}
4524
f4b8ec07
CS
4525DEFUN_YANG(no_neighbor_interface_config,
4526 no_neighbor_interface_config_cmd,
4527 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4528 NO_STR NEIGHBOR_STR
4529 "Interface name\n"
4530 "Configure BGP on interface\n"
4531 "Enable BGP with v6 link-local only\n"
4532 "Member of the peer-group\n"
4533 "Peer-group name\n"
4534 "Specify a BGP neighbor\n" AS_STR
4535 "Internal BGP peer\n"
4536 "External BGP peer\n")
a80beece 4537{
d62a17ae 4538 int idx_word = 2;
f4b8ec07 4539 char base_xpath[XPATH_MAXLEN];
d62a17ae 4540
f4b8ec07
CS
4541 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4542 argv[idx_word]->arg, "");
4543
4544 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4545
4546 return nb_cli_apply_changes(vty, base_xpath);
a80beece
DS
4547}
4548
f4b8ec07
CS
4549DEFUN_YANG(no_neighbor_peer_group,
4550 no_neighbor_peer_group_cmd,
4551 "no neighbor WORD peer-group",
4552 NO_STR NEIGHBOR_STR
4553 "Neighbor tag\n"
4554 "Configure peer-group\n")
718e3744 4555{
f4b8ec07 4556 char base_xpath[XPATH_MAXLEN];
d62a17ae 4557 int idx_word = 2;
718e3744 4558
f4b8ec07
CS
4559 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4560 argv[idx_word]->arg, "");
4561
4562 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4563
4564 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4565}
4566
f4b8ec07
CS
4567DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4568 no_neighbor_interface_peer_group_remote_as_cmd,
4569 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4570 NO_STR NEIGHBOR_STR
4571 "Interface name or neighbor tag\n"
4572 "Specify a BGP neighbor\n" AS_STR
4573 "Internal BGP peer\n"
4574 "External BGP peer\n")
718e3744 4575{
f4b8ec07
CS
4576 int idx_peer = 2;
4577 char base_xpath[XPATH_MAXLEN];
4578 char unnbr_xpath[XPATH_MAXLEN];
4579 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4580
f4b8ec07
CS
4581 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4582 argv[idx_peer]->arg, "");
d62a17ae 4583
f4b8ec07
CS
4584 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4585 argv[idx_peer]->arg, "");
4586
4587 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4588 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4589 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4590 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4591 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4592 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4593 } else {
d62a17ae 4594 vty_out(vty, "%% Create the peer-group or interface first\n");
4595 return CMD_WARNING_CONFIG_FAILED;
4596 }
f4b8ec07
CS
4597
4598 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4599 sizeof(base_xpath));
4600
4601 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4602
4603 return nb_cli_apply_changes(vty, NULL);
718e3744 4604}
6b0655a2 4605
f4b8ec07
CS
4606DEFUN_YANG(neighbor_local_as,
4607 neighbor_local_as_cmd,
4608 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4609 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4610 "Specify a local-as number\n"
4611 "AS number used as local AS\n")
718e3744 4612{
d62a17ae 4613 int idx_peer = 1;
4614 int idx_number = 3;
f4b8ec07 4615 char base_xpath[XPATH_MAXLEN];
718e3744 4616
f4b8ec07
CS
4617 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4618 sizeof(base_xpath), NULL)
4619 < 0)
d62a17ae 4620 return CMD_WARNING_CONFIG_FAILED;
718e3744 4621
f4b8ec07
CS
4622 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4623 argv[idx_number]->arg);
4624
4625 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4626}
4627
f4b8ec07
CS
4628DEFUN_YANG(
4629 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4630 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4631 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4632 "Specify a local-as number\n"
4633 "AS number used as local AS\n"
4634 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4635{
d62a17ae 4636 int idx_peer = 1;
4637 int idx_number = 3;
f4b8ec07 4638 char base_xpath[XPATH_MAXLEN];
718e3744 4639
f4b8ec07
CS
4640 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4641 sizeof(base_xpath), NULL)
4642 < 0)
d62a17ae 4643 return CMD_WARNING_CONFIG_FAILED;
718e3744 4644
f4b8ec07
CS
4645 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4646 argv[idx_number]->arg);
4647 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4648 "true");
4649
4650 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4651}
4652
f4b8ec07
CS
4653DEFUN_YANG(
4654 neighbor_local_as_no_prepend_replace_as,
4655 neighbor_local_as_no_prepend_replace_as_cmd,
4656 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4657 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4658 "Specify a local-as number\n"
4659 "AS number used as local AS\n"
4660 "Do not prepend local-as to updates from ebgp peers\n"
4661 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4662{
d62a17ae 4663 int idx_peer = 1;
4664 int idx_number = 3;
f4b8ec07 4665 char base_xpath[XPATH_MAXLEN];
9d3f9705 4666
f4b8ec07
CS
4667 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4668 sizeof(base_xpath), NULL)
4669 < 0)
d62a17ae 4670 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4671
f4b8ec07
CS
4672 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4673 argv[idx_number]->arg);
4674 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4675 "true");
4676 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4677 "true");
4678
4679 return nb_cli_apply_changes(vty, base_xpath);
9d3f9705
AC
4680}
4681
f4b8ec07
CS
4682DEFUN_YANG(no_neighbor_local_as,
4683 no_neighbor_local_as_cmd,
4684 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4685 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4686 "Specify a local-as number\n"
4687 "AS number used as local AS\n"
4688 "Do not prepend local-as to updates from ebgp peers\n"
4689 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4690{
d62a17ae 4691 int idx_peer = 2;
f4b8ec07 4692 char base_xpath[XPATH_MAXLEN];
718e3744 4693
f4b8ec07
CS
4694 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4695 sizeof(base_xpath), NULL)
4696 < 0)
d62a17ae 4697 return CMD_WARNING_CONFIG_FAILED;
718e3744 4698
f4b8ec07
CS
4699 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4700 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4701 "false");
4702 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4703 "false");
4704
4705 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4706}
4707
718e3744 4708
3f9c7369
DS
4709DEFUN (neighbor_solo,
4710 neighbor_solo_cmd,
9ccf14f7 4711 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4712 NEIGHBOR_STR
4713 NEIGHBOR_ADDR_STR2
4714 "Solo peer - part of its own update group\n")
4715{
d62a17ae 4716 int idx_peer = 1;
4717 struct peer *peer;
4718 int ret;
3f9c7369 4719
d62a17ae 4720 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4721 if (!peer)
4722 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4723
d62a17ae 4724 ret = update_group_adjust_soloness(peer, 1);
4725 return bgp_vty_return(vty, ret);
3f9c7369
DS
4726}
4727
4728DEFUN (no_neighbor_solo,
4729 no_neighbor_solo_cmd,
9ccf14f7 4730 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4731 NO_STR
4732 NEIGHBOR_STR
4733 NEIGHBOR_ADDR_STR2
4734 "Solo peer - part of its own update group\n")
4735{
d62a17ae 4736 int idx_peer = 2;
4737 struct peer *peer;
4738 int ret;
3f9c7369 4739
d62a17ae 4740 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4741 if (!peer)
4742 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4743
d62a17ae 4744 ret = update_group_adjust_soloness(peer, 0);
4745 return bgp_vty_return(vty, ret);
3f9c7369
DS
4746}
4747
f4b8ec07
CS
4748DEFUN_YANG(neighbor_password,
4749 neighbor_password_cmd,
4750 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4751 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4752 "Set a password\n"
4753 "The password\n")
0df7c91f 4754{
d62a17ae 4755 int idx_peer = 1;
4756 int idx_line = 3;
f4b8ec07 4757 char base_xpath[XPATH_MAXLEN];
0df7c91f 4758
f4b8ec07
CS
4759 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4760 sizeof(base_xpath), NULL)
4761 < 0)
d62a17ae 4762 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4763
f4b8ec07
CS
4764 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4765 argv[idx_line]->arg);
4766
4767 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f
PJ
4768}
4769
f4b8ec07
CS
4770DEFUN_YANG(no_neighbor_password,
4771 no_neighbor_password_cmd,
4772 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4773 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4774 "Set a password\n"
4775 "The password\n")
0df7c91f 4776{
d62a17ae 4777 int idx_peer = 2;
f4b8ec07 4778 char base_xpath[XPATH_MAXLEN];
0df7c91f 4779
f4b8ec07
CS
4780 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4781 sizeof(base_xpath), NULL)
4782 < 0)
d62a17ae 4783 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4784
f4b8ec07
CS
4785 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4786
4787 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f 4788}
6b0655a2 4789
f4b8ec07
CS
4790DEFUN_YANG(neighbor_activate,
4791 neighbor_activate_cmd,
4792 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4793 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4794 "Enable the Address Family for this Neighbor\n")
718e3744 4795{
d62a17ae 4796 int idx_peer = 1;
f4b8ec07
CS
4797 char base_xpath[XPATH_MAXLEN];
4798 char abs_xpath[XPATH_MAXLEN];
4799 char nbr_xpath[XPATH_MAXLEN];
4800 char af_xpath[XPATH_MAXLEN];
4801 afi_t afi = bgp_node_afi(vty);
4802 safi_t safi = bgp_node_safi(vty);
718e3744 4803
f4b8ec07
CS
4804 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4805 yang_afi_safi_value2identity(afi, safi));
4806
4807 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, nbr_xpath,
4808 sizeof(nbr_xpath), af_xpath)
4809 < 0)
d62a17ae 4810 return CMD_WARNING_CONFIG_FAILED;
718e3744 4811
f4b8ec07
CS
4812 snprintf(base_xpath, sizeof(base_xpath), "%s%s", VTY_CURR_XPATH,
4813 nbr_xpath + 1);
4814
4815 snprintf(abs_xpath, sizeof(abs_xpath), "%s%s/enabled", VTY_CURR_XPATH,
4816 nbr_xpath + 1);
4817
4818 nb_cli_enqueue_change(vty, abs_xpath, NB_OP_MODIFY, "true");
4819
4820 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4821}
4822
d62a17ae 4823ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4824 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4825 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4826 "Enable the Address Family for this Neighbor\n")
596c17ba 4827
f4b8ec07
CS
4828DEFUN_YANG(no_neighbor_activate,
4829 no_neighbor_activate_cmd,
4830 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4831 NO_STR NEIGHBOR_STR
4832 NEIGHBOR_ADDR_STR2
4833 "Enable the Address Family for this Neighbor\n")
718e3744 4834{
d62a17ae 4835 int idx_peer = 2;
f4b8ec07
CS
4836 char base_xpath[XPATH_MAXLEN];
4837 char af_xpath[XPATH_MAXLEN];
4838 afi_t afi = bgp_node_afi(vty);
4839 safi_t safi = bgp_node_safi(vty);
718e3744 4840
f4b8ec07
CS
4841 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4842 yang_afi_safi_value2identity(afi, safi));
4843
4844 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4845 sizeof(base_xpath), af_xpath)
4846 < 0)
d62a17ae 4847 return CMD_WARNING_CONFIG_FAILED;
718e3744 4848
f4b8ec07
CS
4849 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4850
4851 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4852}
6b0655a2 4853
d62a17ae 4854ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4855 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4856 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4857 "Enable the Address Family for this Neighbor\n")
596c17ba 4858
f4b8ec07
CS
4859DEFUN_YANG (neighbor_set_peer_group,
4860 neighbor_set_peer_group_cmd,
4861 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4862 NEIGHBOR_STR
4863 NEIGHBOR_ADDR_STR2
4864 "Member of the peer-group\n"
4865 "Peer-group name\n")
718e3744 4866{
d62a17ae 4867 int idx_peer = 1;
4868 int idx_word = 3;
f4b8ec07 4869 char base_xpath[XPATH_MAXLEN];
d62a17ae 4870
f4b8ec07
CS
4871 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4872 sizeof(base_xpath), NULL)
4873 < 0)
d62a17ae 4874 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4875
f4b8ec07
CS
4876 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4877 argv[idx_word]->arg);
d62a17ae 4878
f4b8ec07 4879 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4880}
4881
4882ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4883 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4884 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4885 "Member of the peer-group\n"
4886 "Peer-group name\n")
596c17ba 4887
f4b8ec07
CS
4888DEFUN_YANG (no_neighbor_set_peer_group,
4889 no_neighbor_set_peer_group_cmd,
4890 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4891 NO_STR
4892 NEIGHBOR_STR
4893 NEIGHBOR_ADDR_STR2
4894 "Member of the peer-group\n"
4895 "Peer-group name\n")
718e3744 4896{
d62a17ae 4897 int idx_peer = 2;
f4b8ec07 4898 char base_xpath[XPATH_MAXLEN];
d62a17ae 4899
f4b8ec07
CS
4900 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4901 sizeof(base_xpath), NULL)
4902 < 0)
d62a17ae 4903 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 4904
f4b8ec07 4905 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
718e3744 4906
f4b8ec07 4907 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4908}
6b0655a2 4909
d62a17ae 4910ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4911 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4912 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4913 "Member of the peer-group\n"
4914 "Peer-group name\n")
596c17ba 4915
d62a17ae 4916static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4917 uint32_t flag, int set)
718e3744 4918{
d62a17ae 4919 int ret;
4920 struct peer *peer;
718e3744 4921
d62a17ae 4922 peer = peer_and_group_lookup_vty(vty, ip_str);
4923 if (!peer)
4924 return CMD_WARNING_CONFIG_FAILED;
718e3744 4925
7ebe625c
QY
4926 /*
4927 * If 'neighbor <interface>', then this is for directly connected peers,
4928 * we should not accept disable-connected-check.
4929 */
4930 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4931 vty_out(vty,
3efd0893 4932 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
4933 ip_str);
4934 return CMD_WARNING_CONFIG_FAILED;
4935 }
4936
d62a17ae 4937 if (!set && flag == PEER_FLAG_SHUTDOWN)
4938 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4939
d62a17ae 4940 if (set)
4941 ret = peer_flag_set(peer, flag);
4942 else
4943 ret = peer_flag_unset(peer, flag);
718e3744 4944
d62a17ae 4945 return bgp_vty_return(vty, ret);
718e3744 4946}
4947
47cbc09b 4948static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4949{
d62a17ae 4950 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4951}
4952
d62a17ae 4953static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4954 uint32_t flag)
718e3744 4955{
d62a17ae 4956 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4957}
4958
f4b8ec07
CS
4959int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
4960 uint32_t flag, bool set, char *errmsg,
4961 size_t errmsg_len)
4962{
4963 int ret;
4964
4965 /*
4966 * If 'neighbor <interface>', then this is for directly connected peers,
4967 * we should not accept disable-connected-check.
4968 */
4969 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4970 snprintf(
4971 errmsg, errmsg_len,
4972 "%s is directly connected peer, cannot accept disable-connected-check\n",
4973 ip_str);
4974 return -1;
4975 }
4976
4977 if (!set && flag == PEER_FLAG_SHUTDOWN)
4978 peer_tx_shutdown_message_unset(peer);
4979
4980 if (set)
4981 ret = peer_flag_set(peer, flag);
4982 else
4983 ret = peer_flag_unset(peer, flag);
4984
4985 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
4986}
4987
718e3744 4988/* neighbor passive. */
f4b8ec07
CS
4989DEFUN_YANG(neighbor_passive,
4990 neighbor_passive_cmd,
4991 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4992 NEIGHBOR_STR
4993 NEIGHBOR_ADDR_STR2
4994 "Don't send open messages to this neighbor\n")
718e3744 4995{
d62a17ae 4996 int idx_peer = 1;
f4b8ec07
CS
4997 char base_xpath[XPATH_MAXLEN];
4998
4999 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5000 sizeof(base_xpath), NULL)
5001 < 0)
5002 return CMD_WARNING_CONFIG_FAILED;
5003
5004 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5005
5006 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5007}
5008
f4b8ec07
CS
5009DEFUN_YANG(no_neighbor_passive,
5010 no_neighbor_passive_cmd,
5011 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5012 NO_STR NEIGHBOR_STR
5013 NEIGHBOR_ADDR_STR2
5014 "Don't send open messages to this neighbor\n")
718e3744 5015{
d62a17ae 5016 int idx_peer = 2;
f4b8ec07
CS
5017 char base_xpath[XPATH_MAXLEN];
5018
5019 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5020 sizeof(base_xpath), NULL)
5021 < 0)
5022 return CMD_WARNING_CONFIG_FAILED;
5023
5024 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5025
5026 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5027}
6b0655a2 5028
718e3744 5029/* neighbor shutdown. */
f4b8ec07
CS
5030DEFUN_YANG(neighbor_shutdown_msg,
5031 neighbor_shutdown_msg_cmd,
5032 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5033 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5034 "Administratively shut down this neighbor\n"
5035 "Add a shutdown message (RFC 8203)\n"
5036 "Shutdown message\n")
718e3744 5037{
d62a17ae 5038 int idx_peer = 1;
f4b8ec07
CS
5039 char base_xpath[XPATH_MAXLEN];
5040
5041 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5042 sizeof(base_xpath), NULL)
5043 < 0)
5044 return CMD_WARNING_CONFIG_FAILED;
73d70fa6 5045
d62a17ae 5046 if (argc >= 5) {
d62a17ae 5047 char *message;
73d70fa6 5048
d62a17ae 5049 message = argv_concat(argv, argc, 4);
f4b8ec07
CS
5050 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5051 NB_OP_MODIFY, message);
d62a17ae 5052 }
73d70fa6 5053
f4b8ec07
CS
5054 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5055 "true");
5056
5057 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5058}
5059
d62a17ae 5060ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5061 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5062 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5063 "Administratively shut down this neighbor\n")
73d70fa6 5064
f4b8ec07
CS
5065DEFUN_YANG(no_neighbor_shutdown_msg,
5066 no_neighbor_shutdown_msg_cmd,
5067 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5068 NO_STR NEIGHBOR_STR
5069 NEIGHBOR_ADDR_STR2
5070 "Administratively shut down this neighbor\n"
5071 "Remove a shutdown message (RFC 8203)\n"
5072 "Shutdown message\n")
718e3744 5073{
d62a17ae 5074 int idx_peer = 2;
f4b8ec07 5075 char base_xpath[XPATH_MAXLEN];
73d70fa6 5076
f4b8ec07
CS
5077 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5078 sizeof(base_xpath), NULL)
5079 < 0)
5080 return CMD_WARNING_CONFIG_FAILED;
5081
5082 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5083 "false");
5084
5085 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5086}
6b0655a2 5087
d62a17ae 5088ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5089 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5090 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5091 "Administratively shut down this neighbor\n")
73d70fa6 5092
8336c896
DA
5093DEFUN(neighbor_shutdown_rtt,
5094 neighbor_shutdown_rtt_cmd,
5095 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5096 NEIGHBOR_STR
5097 NEIGHBOR_ADDR_STR2
5098 "Administratively shut down this neighbor\n"
5099 "Shutdown if round-trip-time is higher than expected\n"
5100 "Round-trip-time in milliseconds\n"
5101 "Specify the number of keepalives before shutdown\n"
5102 "The number of keepalives with higher RTT to shutdown\n")
5103{
5104 int idx_peer = 1;
5105 int idx_rtt = 4;
5106 int idx_count = 0;
5107 struct peer *peer;
5108
5109 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5110
5111 if (!peer)
5112 return CMD_WARNING_CONFIG_FAILED;
5113
5114 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5115
5116 if (argv_find(argv, argc, "count", &idx_count))
5117 peer->rtt_keepalive_conf =
5118 strtol(argv[idx_count + 1]->arg, NULL, 10);
5119
5120 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5121 PEER_FLAG_RTT_SHUTDOWN);
5122}
5123
5124DEFUN(no_neighbor_shutdown_rtt,
5125 no_neighbor_shutdown_rtt_cmd,
5126 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5127 NO_STR
5128 NEIGHBOR_STR
5129 NEIGHBOR_ADDR_STR2
5130 "Administratively shut down this neighbor\n"
5131 "Shutdown if round-trip-time is higher than expected\n"
5132 "Round-trip-time in milliseconds\n"
5133 "Specify the number of keepalives before shutdown\n"
5134 "The number of keepalives with higher RTT to shutdown\n")
5135{
5136 int idx_peer = 2;
5137 struct peer *peer;
5138
5139 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5140
5141 if (!peer)
5142 return CMD_WARNING_CONFIG_FAILED;
5143
5144 peer->rtt_expected = 0;
5145 peer->rtt_keepalive_conf = 1;
5146
5147 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5148 PEER_FLAG_RTT_SHUTDOWN);
5149}
5150
718e3744 5151/* neighbor capability dynamic. */
f4b8ec07
CS
5152DEFUN_YANG (neighbor_capability_dynamic,
5153 neighbor_capability_dynamic_cmd,
5154 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5155 NEIGHBOR_STR
5156 NEIGHBOR_ADDR_STR2
5157 "Advertise capability to the peer\n"
5158 "Advertise dynamic capability to this neighbor\n")
718e3744 5159{
d62a17ae 5160 int idx_peer = 1;
f4b8ec07
CS
5161 char base_xpath[XPATH_MAXLEN];
5162
5163 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5164 sizeof(base_xpath), NULL)
5165 < 0)
5166 return CMD_WARNING_CONFIG_FAILED;
5167
5168 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5169 NB_OP_MODIFY, "true");
5170
5171 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5172}
5173
f4b8ec07
CS
5174DEFUN_YANG (no_neighbor_capability_dynamic,
5175 no_neighbor_capability_dynamic_cmd,
5176 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5177 NO_STR
5178 NEIGHBOR_STR
5179 NEIGHBOR_ADDR_STR2
5180 "Advertise capability to the peer\n"
5181 "Advertise dynamic capability to this neighbor\n")
718e3744 5182{
d62a17ae 5183 int idx_peer = 2;
f4b8ec07
CS
5184 char base_xpath[XPATH_MAXLEN];
5185
5186 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5187 sizeof(base_xpath), NULL)
5188 < 0)
5189 return CMD_WARNING_CONFIG_FAILED;
5190
5191 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5192 NB_OP_MODIFY, "false");
5193
5194 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5195}
6b0655a2 5196
718e3744 5197/* neighbor dont-capability-negotiate */
5198DEFUN (neighbor_dont_capability_negotiate,
5199 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5200 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5201 NEIGHBOR_STR
5202 NEIGHBOR_ADDR_STR2
5203 "Do not perform capability negotiation\n")
5204{
d62a17ae 5205 int idx_peer = 1;
5206 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5207 PEER_FLAG_DONT_CAPABILITY);
718e3744 5208}
5209
5210DEFUN (no_neighbor_dont_capability_negotiate,
5211 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5212 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5213 NO_STR
5214 NEIGHBOR_STR
5215 NEIGHBOR_ADDR_STR2
5216 "Do not perform capability negotiation\n")
5217{
d62a17ae 5218 int idx_peer = 2;
5219 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5220 PEER_FLAG_DONT_CAPABILITY);
718e3744 5221}
6b0655a2 5222
8a92a8a0 5223/* neighbor capability extended next hop encoding */
f4b8ec07
CS
5224DEFUN_YANG (neighbor_capability_enhe,
5225 neighbor_capability_enhe_cmd,
5226 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5227 NEIGHBOR_STR
5228 NEIGHBOR_ADDR_STR2
5229 "Advertise capability to the peer\n"
5230 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5231{
d62a17ae 5232 int idx_peer = 1;
f4b8ec07
CS
5233 char base_xpath[XPATH_MAXLEN];
5234
5235 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5236 sizeof(base_xpath), NULL)
5237 < 0)
5238 return CMD_WARNING_CONFIG_FAILED;
5239
5240 nb_cli_enqueue_change(
5241 vty, "./capability-options/extended-nexthop-capability",
5242 NB_OP_MODIFY, "true");
5243
5244 return nb_cli_apply_changes(vty, base_xpath);
8a92a8a0
DS
5245}
5246
f4b8ec07
CS
5247DEFUN_YANG (no_neighbor_capability_enhe,
5248 no_neighbor_capability_enhe_cmd,
5249 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5250 NO_STR
5251 NEIGHBOR_STR
5252 NEIGHBOR_ADDR_STR2
5253 "Advertise capability to the peer\n"
5254 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5255{
d62a17ae 5256 int idx_peer = 2;
f4b8ec07
CS
5257 char base_xpath[XPATH_MAXLEN];
5258
5259 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5260 sizeof(base_xpath), NULL)
5261 < 0)
5262 return CMD_WARNING_CONFIG_FAILED;
5263
5264 nb_cli_enqueue_change(
5265 vty, "./capability-options/extended-nexthop-capability",
5266 NB_OP_MODIFY, "false");
5267
5268 return nb_cli_apply_changes(vty, base_xpath);
5269}
5270
5271int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5272 uint32_t flag, int set, char *errmsg,
5273 size_t errmsg_len)
5274{
5275 int ret;
5276
5277 if (set)
5278 ret = peer_af_flag_set(peer, afi, safi, flag);
5279 else
5280 ret = peer_af_flag_unset(peer, afi, safi, flag);
5281
5282 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
8a92a8a0
DS
5283}
5284
d62a17ae 5285static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5286 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5287 int set)
718e3744 5288{
d62a17ae 5289 int ret;
5290 struct peer *peer;
718e3744 5291
d62a17ae 5292 peer = peer_and_group_lookup_vty(vty, peer_str);
5293 if (!peer)
5294 return CMD_WARNING_CONFIG_FAILED;
718e3744 5295
d62a17ae 5296 if (set)
5297 ret = peer_af_flag_set(peer, afi, safi, flag);
5298 else
5299 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5300
d62a17ae 5301 return bgp_vty_return(vty, ret);
718e3744 5302}
5303
d62a17ae 5304static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5305 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5306{
d62a17ae 5307 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5308}
5309
d62a17ae 5310static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5311 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5312{
d62a17ae 5313 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5314}
6b0655a2 5315
718e3744 5316/* neighbor capability orf prefix-list. */
5317DEFUN (neighbor_capability_orf_prefix,
5318 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5319 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5320 NEIGHBOR_STR
5321 NEIGHBOR_ADDR_STR2
5322 "Advertise capability to the peer\n"
5323 "Advertise ORF capability to the peer\n"
5324 "Advertise prefixlist ORF capability to this neighbor\n"
5325 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5326 "Capability to RECEIVE the ORF from this neighbor\n"
5327 "Capability to SEND the ORF to this neighbor\n")
5328{
d62a17ae 5329 int idx_send_recv = 5;
db45f64d
DS
5330 char *peer_str = argv[1]->arg;
5331 struct peer *peer;
5332 afi_t afi = bgp_node_afi(vty);
5333 safi_t safi = bgp_node_safi(vty);
d62a17ae 5334
db45f64d
DS
5335 peer = peer_and_group_lookup_vty(vty, peer_str);
5336 if (!peer)
d62a17ae 5337 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5338
db45f64d
DS
5339 if (strmatch(argv[idx_send_recv]->text, "send"))
5340 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5341 PEER_FLAG_ORF_PREFIX_SM);
5342
5343 if (strmatch(argv[idx_send_recv]->text, "receive"))
5344 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5345 PEER_FLAG_ORF_PREFIX_RM);
5346
5347 if (strmatch(argv[idx_send_recv]->text, "both"))
5348 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5349 PEER_FLAG_ORF_PREFIX_SM)
5350 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5351 PEER_FLAG_ORF_PREFIX_RM);
5352
5353 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5354}
5355
5356ALIAS_HIDDEN(
5357 neighbor_capability_orf_prefix,
5358 neighbor_capability_orf_prefix_hidden_cmd,
5359 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5360 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5361 "Advertise capability to the peer\n"
5362 "Advertise ORF capability to the peer\n"
5363 "Advertise prefixlist ORF capability to this neighbor\n"
5364 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5365 "Capability to RECEIVE the ORF from this neighbor\n"
5366 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5367
718e3744 5368DEFUN (no_neighbor_capability_orf_prefix,
5369 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5370 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5371 NO_STR
5372 NEIGHBOR_STR
5373 NEIGHBOR_ADDR_STR2
5374 "Advertise capability to the peer\n"
5375 "Advertise ORF capability to the peer\n"
5376 "Advertise prefixlist ORF capability to this neighbor\n"
5377 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5378 "Capability to RECEIVE the ORF from this neighbor\n"
5379 "Capability to SEND the ORF to this neighbor\n")
5380{
d62a17ae 5381 int idx_send_recv = 6;
db45f64d
DS
5382 char *peer_str = argv[2]->arg;
5383 struct peer *peer;
5384 afi_t afi = bgp_node_afi(vty);
5385 safi_t safi = bgp_node_safi(vty);
d62a17ae 5386
db45f64d
DS
5387 peer = peer_and_group_lookup_vty(vty, peer_str);
5388 if (!peer)
d62a17ae 5389 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5390
db45f64d
DS
5391 if (strmatch(argv[idx_send_recv]->text, "send"))
5392 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5393 PEER_FLAG_ORF_PREFIX_SM);
5394
5395 if (strmatch(argv[idx_send_recv]->text, "receive"))
5396 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5397 PEER_FLAG_ORF_PREFIX_RM);
5398
5399 if (strmatch(argv[idx_send_recv]->text, "both"))
5400 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5401 PEER_FLAG_ORF_PREFIX_SM)
5402 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5403 PEER_FLAG_ORF_PREFIX_RM);
5404
5405 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5406}
5407
5408ALIAS_HIDDEN(
5409 no_neighbor_capability_orf_prefix,
5410 no_neighbor_capability_orf_prefix_hidden_cmd,
5411 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5413 "Advertise capability to the peer\n"
5414 "Advertise ORF capability to the peer\n"
5415 "Advertise prefixlist ORF capability to this neighbor\n"
5416 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5417 "Capability to RECEIVE the ORF from this neighbor\n"
5418 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5419
718e3744 5420/* neighbor next-hop-self. */
f4b8ec07
CS
5421DEFUN_YANG (neighbor_nexthop_self,
5422 neighbor_nexthop_self_cmd,
5423 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5424 NEIGHBOR_STR
5425 NEIGHBOR_ADDR_STR2
5426 "Disable the next hop calculation for this neighbor\n")
718e3744 5427{
d62a17ae 5428 int idx_peer = 1;
f4b8ec07
CS
5429 char base_xpath[XPATH_MAXLEN];
5430 char af_xpath[XPATH_MAXLEN];
5431 char attr_xpath[XPATH_MAXLEN];
5432 afi_t afi = bgp_node_afi(vty);
5433 safi_t safi = bgp_node_safi(vty);
5434
5435
5436 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5437 yang_afi_safi_value2identity(afi, safi));
5438
5439 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5440 sizeof(base_xpath), af_xpath)
5441 < 0)
5442 return CMD_WARNING_CONFIG_FAILED;
5443
5444 snprintf(attr_xpath, sizeof(attr_xpath),
5445 "./%s/nexthop-self/next-hop-self",
5446 bgp_afi_safi_get_container_str(afi, safi));
5447
5448 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5449
5450 return nb_cli_apply_changes(vty, base_xpath);
a538debe 5451}
9e7a53c1 5452
d62a17ae 5453ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5454 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5455 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5456 "Disable the next hop calculation for this neighbor\n")
596c17ba 5457
f4b8ec07
CS
5458/* neighbor next-hop-self. */
5459DEFUN_YANG(neighbor_nexthop_self_force,
5460 neighbor_nexthop_self_force_cmd,
5461 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5462 NEIGHBOR_STR
5463 NEIGHBOR_ADDR_STR2
5464 "Disable the next hop calculation for this neighbor\n"
5465 "Set the next hop to self for reflected routes\n")
5466{
5467 int idx_peer = 1;
5468 char base_xpath[XPATH_MAXLEN];
5469 char af_xpath[XPATH_MAXLEN];
5470 char attr_xpath[XPATH_MAXLEN];
5471 afi_t afi = bgp_node_afi(vty);
5472 safi_t safi = bgp_node_safi(vty);
5473
5474
5475 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5476 yang_afi_safi_value2identity(afi, safi));
5477
5478 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5479 sizeof(base_xpath), af_xpath)
5480 < 0)
5481 return CMD_WARNING_CONFIG_FAILED;
5482
5483 snprintf(attr_xpath, sizeof(attr_xpath),
5484 "./%s/nexthop-self/next-hop-self-force",
5485 bgp_afi_safi_get_container_str(afi, safi));
5486
5487 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5488
5489 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5490}
5491
d62a17ae 5492ALIAS_HIDDEN(neighbor_nexthop_self_force,
5493 neighbor_nexthop_self_force_hidden_cmd,
5494 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5495 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5496 "Disable the next hop calculation for this neighbor\n"
5497 "Set the next hop to self for reflected routes\n")
596c17ba 5498
1bc4e531
DA
5499ALIAS_HIDDEN(neighbor_nexthop_self_force,
5500 neighbor_nexthop_self_all_hidden_cmd,
5501 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5502 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5503 "Disable the next hop calculation for this neighbor\n"
5504 "Set the next hop to self for reflected routes\n")
5505
f4b8ec07
CS
5506DEFUN_YANG (no_neighbor_nexthop_self,
5507 no_neighbor_nexthop_self_cmd,
5508 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5509 NO_STR
5510 NEIGHBOR_STR
5511 NEIGHBOR_ADDR_STR2
5512 "Disable the next hop calculation for this neighbor\n")
718e3744 5513{
d62a17ae 5514 int idx_peer = 2;
f4b8ec07
CS
5515 char base_xpath[XPATH_MAXLEN];
5516 char af_xpath[XPATH_MAXLEN];
5517 char attr_xpath[XPATH_MAXLEN];
5518 afi_t afi = bgp_node_afi(vty);
5519 safi_t safi = bgp_node_safi(vty);
5520
5521 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5522 yang_afi_safi_value2identity(afi, safi));
5523
5524 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5525 sizeof(base_xpath), af_xpath)
5526 < 0)
5527 return CMD_WARNING_CONFIG_FAILED;
5528
5529 snprintf(attr_xpath, sizeof(attr_xpath),
5530 "./%s/nexthop-self/next-hop-self",
5531 bgp_afi_safi_get_container_str(afi, safi));
5532
5533 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5534
5535 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5536}
6b0655a2 5537
d62a17ae 5538ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5539 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5540 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5541 "Disable the next hop calculation for this neighbor\n")
596c17ba 5542
f4b8ec07
CS
5543DEFUN_YANG (no_neighbor_nexthop_self_force,
5544 no_neighbor_nexthop_self_force_cmd,
5545 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5546 NO_STR
5547 NEIGHBOR_STR
5548 NEIGHBOR_ADDR_STR2
5549 "Disable the next hop calculation for this neighbor\n"
5550 "Set the next hop to self for reflected routes\n")
88b8ed8d 5551{
d62a17ae 5552 int idx_peer = 2;
f4b8ec07
CS
5553 char base_xpath[XPATH_MAXLEN];
5554 char af_xpath[XPATH_MAXLEN];
5555 char attr_xpath[XPATH_MAXLEN];
5556 afi_t afi = bgp_node_afi(vty);
5557 safi_t safi = bgp_node_safi(vty);
5558
5559
5560 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5561 yang_afi_safi_value2identity(afi, safi));
5562
5563 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5564 sizeof(base_xpath), af_xpath)
5565 < 0)
5566 return CMD_WARNING_CONFIG_FAILED;
5567
5568 snprintf(attr_xpath, sizeof(attr_xpath),
5569 "./%s/nexthop-self/next-hop-self-force",
5570 bgp_afi_safi_get_container_str(afi, safi));
5571
5572 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5573
5574 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5575}
a538debe 5576
d62a17ae 5577ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5578 no_neighbor_nexthop_self_force_hidden_cmd,
5579 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5580 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5581 "Disable the next hop calculation for this neighbor\n"
5582 "Set the next hop to self for reflected routes\n")
596c17ba 5583
1bc4e531
DA
5584ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5585 no_neighbor_nexthop_self_all_hidden_cmd,
5586 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5587 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5588 "Disable the next hop calculation for this neighbor\n"
5589 "Set the next hop to self for reflected routes\n")
5590
c7122e14 5591/* neighbor as-override */
f4b8ec07
CS
5592DEFUN_YANG (neighbor_as_override,
5593 neighbor_as_override_cmd,
5594 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5595 NEIGHBOR_STR
5596 NEIGHBOR_ADDR_STR2
5597 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5598{
d62a17ae 5599 int idx_peer = 1;
f4b8ec07
CS
5600 char base_xpath[XPATH_MAXLEN];
5601 char af_xpath[XPATH_MAXLEN];
5602 char attr_xpath[XPATH_MAXLEN];
5603 afi_t afi = bgp_node_afi(vty);
5604 safi_t safi = bgp_node_safi(vty);
5605
5606 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5607 yang_afi_safi_value2identity(afi, safi));
5608
5609 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5610 sizeof(base_xpath), af_xpath)
5611 < 0)
5612 return CMD_WARNING_CONFIG_FAILED;
5613
5614 snprintf(attr_xpath, sizeof(attr_xpath),
5615 "./%s/as-path-options/replace-peer-as",
5616 bgp_afi_safi_get_container_str(afi, safi));
5617
5618 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5619
5620 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5621}
5622
d62a17ae 5623ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5624 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5625 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5626 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5627
f4b8ec07
CS
5628DEFUN_YANG (no_neighbor_as_override,
5629 no_neighbor_as_override_cmd,
5630 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5631 NO_STR
5632 NEIGHBOR_STR
5633 NEIGHBOR_ADDR_STR2
5634 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5635{
d62a17ae 5636 int idx_peer = 2;
f4b8ec07
CS
5637 char base_xpath[XPATH_MAXLEN];
5638 char af_xpath[XPATH_MAXLEN];
5639 char attr_xpath[XPATH_MAXLEN];
5640 afi_t afi = bgp_node_afi(vty);
5641 safi_t safi = bgp_node_safi(vty);
5642
5643 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5644 yang_afi_safi_value2identity(afi, safi));
5645
5646 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5647 sizeof(base_xpath), af_xpath)
5648 < 0)
5649 return CMD_WARNING_CONFIG_FAILED;
5650
5651 snprintf(attr_xpath, sizeof(attr_xpath),
5652 "./%s/as-path-options/replace-peer-as",
5653 bgp_afi_safi_get_container_str(afi, safi));
5654
5655 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5656
5657 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5658}
5659
d62a17ae 5660ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5661 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5662 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5663 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5664
718e3744 5665/* neighbor remove-private-AS. */
f4b8ec07
CS
5666DEFUN_YANG (neighbor_remove_private_as,
5667 neighbor_remove_private_as_cmd,
5668 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5669 NEIGHBOR_STR
5670 NEIGHBOR_ADDR_STR2
5671 "Remove private ASNs in outbound updates\n")
718e3744 5672{
d62a17ae 5673 int idx_peer = 1;
f4b8ec07
CS
5674 char base_xpath[XPATH_MAXLEN];
5675 char af_xpath[XPATH_MAXLEN];
5676 char attr_xpath[XPATH_MAXLEN];
5677 afi_t afi = bgp_node_afi(vty);
5678 safi_t safi = bgp_node_safi(vty);
5679
5680 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5681 yang_afi_safi_value2identity(afi, safi));
5682
5683 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5684 sizeof(base_xpath), af_xpath)
5685 < 0)
5686 return CMD_WARNING_CONFIG_FAILED;
5687
5688 snprintf(attr_xpath, sizeof(attr_xpath),
5689 "./%s/private-as/remove-private-as",
5690 bgp_afi_safi_get_container_str(afi, safi));
5691
5692 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5693
5694 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5695}
5696
d62a17ae 5697ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5698 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5700 "Remove private ASNs in outbound updates\n")
596c17ba 5701
f4b8ec07
CS
5702DEFUN_YANG (neighbor_remove_private_as_all,
5703 neighbor_remove_private_as_all_cmd,
5704 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5705 NEIGHBOR_STR
5706 NEIGHBOR_ADDR_STR2
5707 "Remove private ASNs in outbound updates\n"
5708 "Apply to all AS numbers\n")
5000f21c 5709{
d62a17ae 5710 int idx_peer = 1;
f4b8ec07
CS
5711 char base_xpath[XPATH_MAXLEN];
5712 char af_xpath[XPATH_MAXLEN];
5713 char attr_xpath[XPATH_MAXLEN];
5714 afi_t afi = bgp_node_afi(vty);
5715 safi_t safi = bgp_node_safi(vty);
5716
5717
5718 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5719 yang_afi_safi_value2identity(afi, safi));
5720
5721 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5722 sizeof(base_xpath), af_xpath)
5723 < 0)
5724 return CMD_WARNING_CONFIG_FAILED;
5725
5726 snprintf(attr_xpath, sizeof(attr_xpath),
5727 "./%s/private-as/remove-private-as-all",
5728 bgp_afi_safi_get_container_str(afi, safi));
5729
5730 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5731
5732 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5733}
5734
d62a17ae 5735ALIAS_HIDDEN(neighbor_remove_private_as_all,
5736 neighbor_remove_private_as_all_hidden_cmd,
5737 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5738 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5739 "Remove private ASNs in outbound updates\n"
5740 "Apply to all AS numbers")
596c17ba 5741
f4b8ec07
CS
5742DEFUN_YANG (neighbor_remove_private_as_replace_as,
5743 neighbor_remove_private_as_replace_as_cmd,
5744 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5745 NEIGHBOR_STR
5746 NEIGHBOR_ADDR_STR2
5747 "Remove private ASNs in outbound updates\n"
5748 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5749{
d62a17ae 5750 int idx_peer = 1;
f4b8ec07
CS
5751 char base_xpath[XPATH_MAXLEN];
5752 char af_xpath[XPATH_MAXLEN];
5753 char attr_xpath[XPATH_MAXLEN];
5754 afi_t afi = bgp_node_afi(vty);
5755 safi_t safi = bgp_node_safi(vty);
5756
5757
5758 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5759 yang_afi_safi_value2identity(afi, safi));
5760
5761 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5762 sizeof(base_xpath), af_xpath)
5763 < 0)
5764 return CMD_WARNING_CONFIG_FAILED;
5765
5766 snprintf(attr_xpath, sizeof(attr_xpath),
5767 "./%s/private-as/remove-private-as-replace",
5768 bgp_afi_safi_get_container_str(afi, safi));
5769
5770 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5771
5772 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5773}
5774
d62a17ae 5775ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5776 neighbor_remove_private_as_replace_as_hidden_cmd,
5777 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5778 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5779 "Remove private ASNs in outbound updates\n"
5780 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5781
f4b8ec07
CS
5782DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5783 neighbor_remove_private_as_all_replace_as_cmd,
5784 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5785 NEIGHBOR_STR
5786 NEIGHBOR_ADDR_STR2
5787 "Remove private ASNs in outbound updates\n"
5788 "Apply to all AS numbers\n"
5789 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5790{
d62a17ae 5791 int idx_peer = 1;
f4b8ec07
CS
5792 char base_xpath[XPATH_MAXLEN];
5793 char af_xpath[XPATH_MAXLEN];
5794 char attr_xpath[XPATH_MAXLEN];
5795 afi_t afi = bgp_node_afi(vty);
5796 safi_t safi = bgp_node_safi(vty);
5797
5798
5799 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5800 yang_afi_safi_value2identity(afi, safi));
5801
5802 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5803 sizeof(base_xpath), af_xpath)
5804 < 0)
5805 return CMD_WARNING_CONFIG_FAILED;
5806
5807 snprintf(attr_xpath, sizeof(attr_xpath),
5808 "./%s/private-as/remove-private-as-all-replace",
5809 bgp_afi_safi_get_container_str(afi, safi));
5810
5811 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5812
5813 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5814}
5815
d62a17ae 5816ALIAS_HIDDEN(
5817 neighbor_remove_private_as_all_replace_as,
5818 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5819 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5820 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5821 "Remove private ASNs in outbound updates\n"
5822 "Apply to all AS numbers\n"
5823 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5824
f4b8ec07
CS
5825DEFUN_YANG (no_neighbor_remove_private_as,
5826 no_neighbor_remove_private_as_cmd,
5827 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5828 NO_STR
5829 NEIGHBOR_STR
5830 NEIGHBOR_ADDR_STR2
5831 "Remove private ASNs in outbound updates\n")
718e3744 5832{
d62a17ae 5833 int idx_peer = 2;
f4b8ec07
CS
5834 char base_xpath[XPATH_MAXLEN];
5835 char af_xpath[XPATH_MAXLEN];
5836 char attr_xpath[XPATH_MAXLEN];
5837 afi_t afi = bgp_node_afi(vty);
5838 safi_t safi = bgp_node_safi(vty);
5839
5840 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5841 yang_afi_safi_value2identity(afi, safi));
5842
5843 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5844 sizeof(base_xpath), af_xpath)
5845 < 0)
5846 return CMD_WARNING_CONFIG_FAILED;
5847
5848 snprintf(attr_xpath, sizeof(attr_xpath),
5849 "./%s/private-as/remove-private-as",
5850 bgp_afi_safi_get_container_str(afi, safi));
5851
5852 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5853
5854 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5855}
6b0655a2 5856
d62a17ae 5857ALIAS_HIDDEN(no_neighbor_remove_private_as,
5858 no_neighbor_remove_private_as_hidden_cmd,
5859 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5860 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5861 "Remove private ASNs in outbound updates\n")
596c17ba 5862
f4b8ec07
CS
5863DEFUN_YANG (no_neighbor_remove_private_as_all,
5864 no_neighbor_remove_private_as_all_cmd,
5865 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5866 NO_STR
5867 NEIGHBOR_STR
5868 NEIGHBOR_ADDR_STR2
5869 "Remove private ASNs in outbound updates\n"
5870 "Apply to all AS numbers\n")
88b8ed8d 5871{
d62a17ae 5872 int idx_peer = 2;
f4b8ec07
CS
5873 char base_xpath[XPATH_MAXLEN];
5874 char af_xpath[XPATH_MAXLEN];
5875 char attr_xpath[XPATH_MAXLEN];
5876 afi_t afi = bgp_node_afi(vty);
5877 safi_t safi = bgp_node_safi(vty);
5878
5879
5880 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5881 yang_afi_safi_value2identity(afi, safi));
5882
5883 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5884 sizeof(base_xpath), af_xpath)
5885 < 0)
5886 return CMD_WARNING_CONFIG_FAILED;
5887
5888 snprintf(attr_xpath, sizeof(attr_xpath),
5889 "./%s/private-as/remove-private-as-all",
5890 bgp_afi_safi_get_container_str(afi, safi));
5891
5892 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5893
5894 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5895}
5000f21c 5896
d62a17ae 5897ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5898 no_neighbor_remove_private_as_all_hidden_cmd,
5899 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5900 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5901 "Remove private ASNs in outbound updates\n"
5902 "Apply to all AS numbers\n")
596c17ba 5903
f4b8ec07
CS
5904DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
5905 no_neighbor_remove_private_as_replace_as_cmd,
5906 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5907 NO_STR
5908 NEIGHBOR_STR
5909 NEIGHBOR_ADDR_STR2
5910 "Remove private ASNs in outbound updates\n"
5911 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5912{
d62a17ae 5913 int idx_peer = 2;
f4b8ec07
CS
5914 char base_xpath[XPATH_MAXLEN];
5915 char af_xpath[XPATH_MAXLEN];
5916 char attr_xpath[XPATH_MAXLEN];
5917 afi_t afi = bgp_node_afi(vty);
5918 safi_t safi = bgp_node_safi(vty);
5919
5920
5921 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5922 yang_afi_safi_value2identity(afi, safi));
5923
5924 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5925 sizeof(base_xpath), af_xpath)
5926 < 0)
5927 return CMD_WARNING_CONFIG_FAILED;
5928
5929 snprintf(attr_xpath, sizeof(attr_xpath),
5930 "./%s/private-as/remove-private-as-replace",
5931 bgp_afi_safi_get_container_str(afi, safi));
5932
5933 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5934
5935 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5936}
5000f21c 5937
d62a17ae 5938ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5939 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5940 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5941 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5942 "Remove private ASNs in outbound updates\n"
5943 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5944
f4b8ec07
CS
5945DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
5946 no_neighbor_remove_private_as_all_replace_as_cmd,
5947 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5948 NO_STR
5949 NEIGHBOR_STR
5950 NEIGHBOR_ADDR_STR2
5951 "Remove private ASNs in outbound updates\n"
5952 "Apply to all AS numbers\n"
5953 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5954{
d62a17ae 5955 int idx_peer = 2;
f4b8ec07
CS
5956 char base_xpath[XPATH_MAXLEN];
5957 char af_xpath[XPATH_MAXLEN];
5958 char attr_xpath[XPATH_MAXLEN];
5959 afi_t afi = bgp_node_afi(vty);
5960 safi_t safi = bgp_node_safi(vty);
5961
5962
5963 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5964 yang_afi_safi_value2identity(afi, safi));
5965
5966 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5967 sizeof(base_xpath), af_xpath)
5968 < 0)
5969 return CMD_WARNING_CONFIG_FAILED;
5970
5971 snprintf(attr_xpath, sizeof(attr_xpath),
5972 "./%s/private-as/remove-private-as-all-replace",
5973 bgp_afi_safi_get_container_str(afi, safi));
5974
5975 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5976
5977 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5978}
5000f21c 5979
d62a17ae 5980ALIAS_HIDDEN(
5981 no_neighbor_remove_private_as_all_replace_as,
5982 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5983 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5984 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5985 "Remove private ASNs in outbound updates\n"
5986 "Apply to all AS numbers\n"
5987 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5988
5000f21c 5989
718e3744 5990/* neighbor send-community. */
f4b8ec07
CS
5991DEFUN_YANG (neighbor_send_community,
5992 neighbor_send_community_cmd,
5993 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5994 NEIGHBOR_STR
5995 NEIGHBOR_ADDR_STR2
5996 "Send Community attribute to this neighbor\n")
718e3744 5997{
d62a17ae 5998 int idx_peer = 1;
27c05d4d 5999
d62a17ae 6000 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6001 bgp_node_safi(vty),
6002 PEER_FLAG_SEND_COMMUNITY);
718e3744 6003}
6004
d62a17ae 6005ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6006 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6007 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6008 "Send Community attribute to this neighbor\n")
596c17ba 6009
f4b8ec07
CS
6010DEFUN_YANG (no_neighbor_send_community,
6011 no_neighbor_send_community_cmd,
6012 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6013 NO_STR
6014 NEIGHBOR_STR
6015 NEIGHBOR_ADDR_STR2
6016 "Send Community attribute to this neighbor\n")
718e3744 6017{
d62a17ae 6018 int idx_peer = 2;
27c05d4d 6019
d62a17ae 6020 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6021 bgp_node_afi(vty), bgp_node_safi(vty),
6022 PEER_FLAG_SEND_COMMUNITY);
718e3744 6023}
6b0655a2 6024
d62a17ae 6025ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6026 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6027 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6028 "Send Community attribute to this neighbor\n")
596c17ba 6029
718e3744 6030/* neighbor send-community extended. */
f4b8ec07
CS
6031DEFUN_YANG (neighbor_send_community_type,
6032 neighbor_send_community_type_cmd,
6033 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6034 NEIGHBOR_STR
6035 NEIGHBOR_ADDR_STR2
6036 "Send Community attribute to this neighbor\n"
6037 "Send Standard and Extended Community attributes\n"
6038 "Send Standard, Large and Extended Community attributes\n"
6039 "Send Extended Community attributes\n"
6040 "Send Standard Community attributes\n"
6041 "Send Large Community attributes\n")
718e3744 6042{
27c05d4d 6043 const char *type = argv[argc - 1]->text;
db45f64d 6044 char *peer_str = argv[1]->arg;
f4b8ec07
CS
6045 char base_xpath[XPATH_MAXLEN];
6046 char af_xpath[XPATH_MAXLEN];
6047 char std_xpath[XPATH_MAXLEN];
6048 char ext_xpath[XPATH_MAXLEN];
6049 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6050 afi_t afi = bgp_node_afi(vty);
6051 safi_t safi = bgp_node_safi(vty);
d62a17ae 6052
f4b8ec07
CS
6053 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6054 yang_afi_safi_value2identity(afi, safi));
6055
6056 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6057 sizeof(base_xpath), af_xpath)
6058 < 0)
db45f64d 6059 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6060
f4b8ec07
CS
6061 if (strmatch(type, "standard")) {
6062 snprintf(std_xpath, sizeof(std_xpath),
6063 "./%s/send-community/send-community",
6064 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6065
f4b8ec07
CS
6066 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6067 }
db45f64d 6068
f4b8ec07
CS
6069 if (strmatch(type, "extended")) {
6070 snprintf(ext_xpath, sizeof(ext_xpath),
6071 "./%s/send-community/send-ext-community",
6072 bgp_afi_safi_get_container_str(afi, safi));
6073
6074 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6075 }
6076
6077 if (strmatch(type, "large")) {
6078 snprintf(lrg_xpath, sizeof(lrg_xpath),
6079 "./%s/send-community/send-large-community",
6080 bgp_afi_safi_get_container_str(afi, safi));
6081
6082 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6083 }
db45f64d
DS
6084
6085 if (strmatch(type, "both")) {
f4b8ec07
CS
6086 snprintf(std_xpath, sizeof(std_xpath),
6087 "./%s/send-community/send-community",
6088 bgp_afi_safi_get_container_str(afi, safi));
6089
6090 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6091
6092 snprintf(ext_xpath, sizeof(ext_xpath),
6093 "./%s/send-community/send-ext-community",
6094 bgp_afi_safi_get_container_str(afi, safi));
6095
6096 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
db45f64d 6097 }
f4b8ec07
CS
6098
6099 if (strmatch(type, "all")) {
6100 snprintf(std_xpath, sizeof(std_xpath),
6101 "./%s/send-community/send-community",
6102 bgp_afi_safi_get_container_str(afi, safi));
6103
6104 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6105
6106 snprintf(ext_xpath, sizeof(ext_xpath),
6107 "./%s/send-community/send-ext-community",
6108 bgp_afi_safi_get_container_str(afi, safi));
6109
6110 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6111
6112 snprintf(lrg_xpath, sizeof(lrg_xpath),
6113 "./%s/send-community/send-large-community",
6114 bgp_afi_safi_get_container_str(afi, safi));
6115
6116 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6117 }
6118
6119 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6120}
6121
6122ALIAS_HIDDEN(
6123 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6124 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6125 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6126 "Send Community attribute to this neighbor\n"
6127 "Send Standard and Extended Community attributes\n"
6128 "Send Standard, Large and Extended Community attributes\n"
6129 "Send Extended Community attributes\n"
6130 "Send Standard Community attributes\n"
6131 "Send Large Community attributes\n")
596c17ba 6132
f4b8ec07
CS
6133DEFUN_YANG (no_neighbor_send_community_type,
6134 no_neighbor_send_community_type_cmd,
6135 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6136 NO_STR
6137 NEIGHBOR_STR
6138 NEIGHBOR_ADDR_STR2
6139 "Send Community attribute to this neighbor\n"
6140 "Send Standard and Extended Community attributes\n"
6141 "Send Standard, Large and Extended Community attributes\n"
6142 "Send Extended Community attributes\n"
6143 "Send Standard Community attributes\n"
6144 "Send Large Community attributes\n")
718e3744 6145{
d62a17ae 6146 const char *type = argv[argc - 1]->text;
db45f64d 6147 char *peer_str = argv[2]->arg;
f4b8ec07
CS
6148 char base_xpath[XPATH_MAXLEN];
6149 char af_xpath[XPATH_MAXLEN];
6150 char std_xpath[XPATH_MAXLEN];
6151 char ext_xpath[XPATH_MAXLEN];
6152 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6153 afi_t afi = bgp_node_afi(vty);
6154 safi_t safi = bgp_node_safi(vty);
6155
f4b8ec07
CS
6156 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6157 yang_afi_safi_value2identity(afi, safi));
6158
6159 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6160 sizeof(base_xpath), af_xpath)
6161 < 0)
6162 return CMD_WARNING_CONFIG_FAILED;
6163
6164 if (strmatch(type, "standard")) {
6165 snprintf(std_xpath, sizeof(std_xpath),
6166 "./%s/send-community/send-community",
6167 bgp_afi_safi_get_container_str(afi, safi));
6168
6169 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6170 }
6171
6172 if (strmatch(type, "extended")) {
6173 snprintf(ext_xpath, sizeof(ext_xpath),
6174 "./%s/send-community/send-ext-community",
6175 bgp_afi_safi_get_container_str(afi, safi));
6176
6177 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6178 }
6179
6180 if (strmatch(type, "large")) {
6181 snprintf(lrg_xpath, sizeof(lrg_xpath),
6182 "./%s/send-community/send-large-community",
6183 bgp_afi_safi_get_container_str(afi, safi));
6184
6185 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6186 }
6187
6188 if (strmatch(type, "both")) {
6189 snprintf(std_xpath, sizeof(std_xpath),
6190 "./%s/send-community/send-community",
6191 bgp_afi_safi_get_container_str(afi, safi));
6192
6193 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6194
6195 snprintf(ext_xpath, sizeof(ext_xpath),
6196 "./%s/send-community/send-ext-community",
6197 bgp_afi_safi_get_container_str(afi, safi));
6198
6199 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6200 }
6201
6202 if (strmatch(type, "all")) {
6203 snprintf(std_xpath, sizeof(std_xpath),
6204 "./%s/send-community/send-community",
6205 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6206
f4b8ec07 6207 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
db45f64d 6208
f4b8ec07
CS
6209 snprintf(ext_xpath, sizeof(ext_xpath),
6210 "./%s/send-community/send-ext-community",
6211 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6212
f4b8ec07 6213 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
db45f64d 6214
f4b8ec07
CS
6215 snprintf(lrg_xpath, sizeof(lrg_xpath),
6216 "./%s/send-community/send-large-community",
6217 bgp_afi_safi_get_container_str(afi, safi));
d62a17ae 6218
f4b8ec07 6219 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
27c05d4d
PM
6220 }
6221
f4b8ec07 6222 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6223}
6224
6225ALIAS_HIDDEN(
6226 no_neighbor_send_community_type,
6227 no_neighbor_send_community_type_hidden_cmd,
6228 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6229 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6230 "Send Community attribute to this neighbor\n"
6231 "Send Standard and Extended Community attributes\n"
6232 "Send Standard, Large and Extended Community attributes\n"
6233 "Send Extended Community attributes\n"
6234 "Send Standard Community attributes\n"
6235 "Send Large Community attributes\n")
596c17ba 6236
718e3744 6237/* neighbor soft-reconfig. */
f4b8ec07
CS
6238DEFUN_YANG (neighbor_soft_reconfiguration,
6239 neighbor_soft_reconfiguration_cmd,
6240 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6241 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6242 "Per neighbor soft reconfiguration\n"
6243 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6244{
d62a17ae 6245 int idx_peer = 1;
f4b8ec07
CS
6246 char base_xpath[XPATH_MAXLEN];
6247 char af_xpath[XPATH_MAXLEN];
6248 char soft_xpath[XPATH_MAXLEN];
6249 afi_t afi = bgp_node_afi(vty);
6250 safi_t safi = bgp_node_safi(vty);
6251
6252
6253 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6254 yang_afi_safi_value2identity(afi, safi));
6255
6256 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6257 sizeof(base_xpath), af_xpath)
6258 < 0)
6259 return CMD_WARNING_CONFIG_FAILED;
6260
6261 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6262 bgp_afi_safi_get_container_str(afi, safi));
6263
6264 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6265
6266 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6267}
6268
d62a17ae 6269ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6270 neighbor_soft_reconfiguration_hidden_cmd,
6271 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6272 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6273 "Per neighbor soft reconfiguration\n"
6274 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6275
f4b8ec07
CS
6276DEFUN_YANG (no_neighbor_soft_reconfiguration,
6277 no_neighbor_soft_reconfiguration_cmd,
6278 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6279 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6280 "Per neighbor soft reconfiguration\n"
6281 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6282{
d62a17ae 6283 int idx_peer = 2;
f4b8ec07
CS
6284 char base_xpath[XPATH_MAXLEN];
6285 char af_xpath[XPATH_MAXLEN];
6286 char soft_xpath[XPATH_MAXLEN];
6287 afi_t afi = bgp_node_afi(vty);
6288 safi_t safi = bgp_node_safi(vty);
6289
6290 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6291 yang_afi_safi_value2identity(afi, safi));
6292
6293 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6294 bgp_afi_safi_get_container_str(afi, safi));
6295
6296 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6297 sizeof(base_xpath), af_xpath)
6298 < 0)
6299 return CMD_WARNING_CONFIG_FAILED;
6300
6301 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6302
6303 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6304}
6b0655a2 6305
d62a17ae 6306ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6307 no_neighbor_soft_reconfiguration_hidden_cmd,
6308 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6309 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6310 "Per neighbor soft reconfiguration\n"
6311 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6312
f4b8ec07
CS
6313DEFUN_YANG (neighbor_route_reflector_client,
6314 neighbor_route_reflector_client_cmd,
6315 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6316 NEIGHBOR_STR
6317 NEIGHBOR_ADDR_STR2
6318 "Configure a neighbor as Route Reflector client\n")
718e3744 6319{
d62a17ae 6320 int idx_peer = 1;
f4b8ec07
CS
6321 char base_xpath[XPATH_MAXLEN];
6322 char af_xpath[XPATH_MAXLEN];
6323 char attr_xpath[XPATH_MAXLEN];
6324 afi_t afi = bgp_node_afi(vty);
6325 safi_t safi = bgp_node_safi(vty);
718e3744 6326
f4b8ec07
CS
6327 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6328 yang_afi_safi_value2identity(afi, safi));
718e3744 6329
f4b8ec07
CS
6330 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6331 sizeof(base_xpath), af_xpath)
6332 < 0)
d62a17ae 6333 return CMD_WARNING_CONFIG_FAILED;
718e3744 6334
f4b8ec07
CS
6335 snprintf(attr_xpath, sizeof(attr_xpath),
6336 "./%s/route-reflector/route-reflector-client",
6337 bgp_afi_safi_get_container_str(afi, safi));
6338
6339 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6340
6341 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6342}
6343
d62a17ae 6344ALIAS_HIDDEN(neighbor_route_reflector_client,
6345 neighbor_route_reflector_client_hidden_cmd,
6346 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6347 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6348 "Configure a neighbor as Route Reflector client\n")
596c17ba 6349
f4b8ec07
CS
6350DEFUN_YANG (no_neighbor_route_reflector_client,
6351 no_neighbor_route_reflector_client_cmd,
6352 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6353 NO_STR
6354 NEIGHBOR_STR
6355 NEIGHBOR_ADDR_STR2
6356 "Configure a neighbor as Route Reflector client\n")
718e3744 6357{
d62a17ae 6358 int idx_peer = 2;
f4b8ec07
CS
6359 char base_xpath[XPATH_MAXLEN];
6360 char af_xpath[XPATH_MAXLEN];
6361 char attr_xpath[XPATH_MAXLEN];
6362 afi_t afi = bgp_node_afi(vty);
6363 safi_t safi = bgp_node_safi(vty);
6364
6365 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6366 yang_afi_safi_value2identity(afi, safi));
6367
6368 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6369 sizeof(base_xpath), af_xpath)
6370 < 0)
6371 return CMD_WARNING_CONFIG_FAILED;
6372
6373 snprintf(attr_xpath, sizeof(attr_xpath),
6374 "./%s/route-reflector/route-reflector-client",
6375 bgp_afi_safi_get_container_str(afi, safi));
6376
6377 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6378
6379 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6380}
6b0655a2 6381
d62a17ae 6382ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6383 no_neighbor_route_reflector_client_hidden_cmd,
6384 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6385 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6386 "Configure a neighbor as Route Reflector client\n")
596c17ba 6387
718e3744 6388/* neighbor route-server-client. */
f4b8ec07
CS
6389DEFUN_YANG (neighbor_route_server_client,
6390 neighbor_route_server_client_cmd,
6391 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6392 NEIGHBOR_STR
6393 NEIGHBOR_ADDR_STR2
6394 "Configure a neighbor as Route Server client\n")
718e3744 6395{
d62a17ae 6396 int idx_peer = 1;
f4b8ec07
CS
6397 char base_xpath[XPATH_MAXLEN];
6398 char af_xpath[XPATH_MAXLEN];
6399 char attr_xpath[XPATH_MAXLEN];
6400 afi_t afi = bgp_node_afi(vty);
6401 safi_t safi = bgp_node_safi(vty);
2a3d5731 6402
f4b8ec07
CS
6403 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6404 yang_afi_safi_value2identity(afi, safi));
6405
6406 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6407 sizeof(base_xpath), af_xpath)
6408 < 0)
d62a17ae 6409 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07
CS
6410
6411 snprintf(attr_xpath, sizeof(attr_xpath),
6412 "./%s/route-server/route-server-client",
6413 bgp_afi_safi_get_container_str(afi, safi));
6414
6415 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6416
6417 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6418}
6419
d62a17ae 6420ALIAS_HIDDEN(neighbor_route_server_client,
6421 neighbor_route_server_client_hidden_cmd,
6422 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6423 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6424 "Configure a neighbor as Route Server client\n")
596c17ba 6425
f4b8ec07
CS
6426DEFUN_YANG (no_neighbor_route_server_client,
6427 no_neighbor_route_server_client_cmd,
6428 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6429 NO_STR
6430 NEIGHBOR_STR
6431 NEIGHBOR_ADDR_STR2
6432 "Configure a neighbor as Route Server client\n")
fee0f4c6 6433{
d62a17ae 6434 int idx_peer = 2;
f4b8ec07
CS
6435 char base_xpath[XPATH_MAXLEN];
6436 char af_xpath[XPATH_MAXLEN];
6437 char attr_xpath[XPATH_MAXLEN];
6438 afi_t afi = bgp_node_afi(vty);
6439 safi_t safi = bgp_node_safi(vty);
6440
6441 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6442 yang_afi_safi_value2identity(afi, safi));
6443
6444 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6445 sizeof(base_xpath), af_xpath)
6446 < 0)
6447 return CMD_WARNING_CONFIG_FAILED;
6448
6449 snprintf(attr_xpath, sizeof(attr_xpath),
6450 "./%s/route-server/route-server-client",
6451 bgp_afi_safi_get_container_str(afi, safi));
6452
6453 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6454
6455 return nb_cli_apply_changes(vty, base_xpath);
fee0f4c6 6456}
6b0655a2 6457
d62a17ae 6458ALIAS_HIDDEN(no_neighbor_route_server_client,
6459 no_neighbor_route_server_client_hidden_cmd,
6460 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6461 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6462 "Configure a neighbor as Route Server client\n")
596c17ba 6463
fee0f4c6 6464DEFUN (neighbor_nexthop_local_unchanged,
6465 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6466 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6467 NEIGHBOR_STR
6468 NEIGHBOR_ADDR_STR2
6469 "Configure treatment of outgoing link-local nexthop attribute\n"
6470 "Leave link-local nexthop unchanged for this peer\n")
6471{
d62a17ae 6472 int idx_peer = 1;
6473 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6474 bgp_node_safi(vty),
6475 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6476}
6b0655a2 6477
fee0f4c6 6478DEFUN (no_neighbor_nexthop_local_unchanged,
6479 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6480 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6481 NO_STR
6482 NEIGHBOR_STR
6483 NEIGHBOR_ADDR_STR2
6484 "Configure treatment of outgoing link-local-nexthop attribute\n"
6485 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6486{
d62a17ae 6487 int idx_peer = 2;
6488 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6489 bgp_node_afi(vty), bgp_node_safi(vty),
6490 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6491}
6b0655a2 6492
f4b8ec07
CS
6493DEFUN_YANG (neighbor_attr_unchanged,
6494 neighbor_attr_unchanged_cmd,
6495 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6496 NEIGHBOR_STR
6497 NEIGHBOR_ADDR_STR2
6498 "BGP attribute is propagated unchanged to this neighbor\n"
6499 "As-path attribute\n"
6500 "Nexthop attribute\n"
6501 "Med attribute\n")
718e3744 6502{
d62a17ae 6503 int idx = 0;
8eeb0335 6504 char *peer_str = argv[1]->arg;
db45f64d
DS
6505 bool aspath = false;
6506 bool nexthop = false;
6507 bool med = false;
8eeb0335
DW
6508 afi_t afi = bgp_node_afi(vty);
6509 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6510 char base_xpath[XPATH_MAXLEN];
6511 char af_xpath[XPATH_MAXLEN];
6512 char as_xpath[XPATH_MAXLEN];
6513 char nxthop_xpath[XPATH_MAXLEN];
6514 char med_xpath[XPATH_MAXLEN];
8eeb0335 6515
f4b8ec07
CS
6516 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6517 yang_afi_safi_value2identity(afi, safi));
6518
6519 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6520 sizeof(base_xpath), af_xpath)
6521 < 0)
8eeb0335 6522 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6523
6524 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6525 aspath = true;
6526
d62a17ae 6527 idx = 0;
6528 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6529 nexthop = true;
6530
d62a17ae 6531 idx = 0;
6532 if (argv_find(argv, argc, "med", &idx))
db45f64d 6533 med = true;
d62a17ae 6534
f4b8ec07
CS
6535 snprintf(as_xpath, sizeof(as_xpath),
6536 "./%s/attr-unchanged/as-path-unchanged",
6537 bgp_afi_safi_get_container_str(afi, safi));
6538 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6539 "./%s/attr-unchanged/next-hop-unchanged",
6540 bgp_afi_safi_get_container_str(afi, safi));
6541 snprintf(med_xpath, sizeof(med_xpath),
6542 "./%s/attr-unchanged/med-unchanged",
6543 bgp_afi_safi_get_container_str(afi, safi));
6544
8eeb0335 6545 /* no flags means all of them! */
db45f64d 6546 if (!aspath && !nexthop && !med) {
f4b8ec07
CS
6547 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6548 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6549 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
8eeb0335 6550 } else {
f4b8ec07
CS
6551 if (!aspath)
6552 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6553 "false");
6554 else
6555 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6556 "true");
6557
6558 if (!nexthop)
6559 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6560 "false");
6561 else
6562 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6563 "true");
6564
6565 if (!med)
6566 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6567 "false");
6568 else
6569 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6570 "true");
d62a17ae 6571 }
6572
f4b8ec07 6573 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6574}
6575
6576ALIAS_HIDDEN(
6577 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6578 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6579 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6580 "BGP attribute is propagated unchanged to this neighbor\n"
6581 "As-path attribute\n"
6582 "Nexthop attribute\n"
6583 "Med attribute\n")
596c17ba 6584
f4b8ec07
CS
6585DEFUN_YANG (no_neighbor_attr_unchanged,
6586 no_neighbor_attr_unchanged_cmd,
6587 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6588 NO_STR
6589 NEIGHBOR_STR
6590 NEIGHBOR_ADDR_STR2
6591 "BGP attribute is propagated unchanged to this neighbor\n"
6592 "As-path attribute\n"
6593 "Nexthop attribute\n"
6594 "Med attribute\n")
718e3744 6595{
d62a17ae 6596 int idx = 0;
db45f64d 6597 char *peer_str = argv[2]->arg;
db45f64d
DS
6598 bool aspath = false;
6599 bool nexthop = false;
6600 bool med = false;
6601 afi_t afi = bgp_node_afi(vty);
6602 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6603 char base_xpath[XPATH_MAXLEN];
6604 char af_xpath[XPATH_MAXLEN];
6605 char as_xpath[XPATH_MAXLEN];
6606 char nxthop_xpath[XPATH_MAXLEN];
6607 char med_xpath[XPATH_MAXLEN];
db45f64d 6608
f4b8ec07
CS
6609 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6610 yang_afi_safi_value2identity(afi, safi));
6611
6612 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6613 sizeof(base_xpath), af_xpath)
6614 < 0)
db45f64d 6615 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6616
6617 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6618 aspath = true;
6619
d62a17ae 6620 idx = 0;
6621 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6622 nexthop = true;
6623
d62a17ae 6624 idx = 0;
6625 if (argv_find(argv, argc, "med", &idx))
db45f64d 6626 med = true;
d62a17ae 6627
f4b8ec07
CS
6628 snprintf(as_xpath, sizeof(as_xpath),
6629 "./%s/attr-unchanged/as-path-unchanged",
6630 bgp_afi_safi_get_container_str(afi, safi));
6631 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6632 "./%s/attr-unchanged/next-hop-unchanged",
6633 bgp_afi_safi_get_container_str(afi, safi));
6634 snprintf(med_xpath, sizeof(med_xpath),
6635 "./%s/attr-unchanged/med-unchanged",
6636 bgp_afi_safi_get_container_str(afi, safi));
6637
6638 /* no flags means all of them! */
6639 if (!aspath && !nexthop && !med) {
6640 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6641 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6642 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6643 }
db45f64d
DS
6644
6645 if (aspath)
f4b8ec07 6646 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
db45f64d
DS
6647
6648 if (nexthop)
f4b8ec07 6649 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
d62a17ae 6650
db45f64d 6651 if (med)
f4b8ec07 6652 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
db45f64d 6653
f4b8ec07 6654 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6655}
6656
6657ALIAS_HIDDEN(
6658 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6659 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6660 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6661 "BGP attribute is propagated unchanged to this neighbor\n"
6662 "As-path attribute\n"
6663 "Nexthop attribute\n"
6664 "Med attribute\n")
718e3744 6665
f4b8ec07
CS
6666/* neighbor ebgp-multihop. */
6667DEFUN_YANG (neighbor_ebgp_multihop,
6668 neighbor_ebgp_multihop_cmd,
6669 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6671 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6672{
f4b8ec07
CS
6673 int idx_peer = 1;
6674 char base_xpath[XPATH_MAXLEN];
718e3744 6675
f4b8ec07
CS
6676 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6677 sizeof(base_xpath), NULL)
6678 < 0)
d62a17ae 6679 return CMD_WARNING_CONFIG_FAILED;
718e3744 6680
f4b8ec07
CS
6681 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6682 "true");
718e3744 6683
f4b8ec07 6684 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6685}
6686
f4b8ec07
CS
6687DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6688 neighbor_ebgp_multihop_ttl_cmd,
6689 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6690 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6691 "Allow EBGP neighbors not on directly connected networks\n"
6692 "maximum hop count\n")
718e3744 6693{
f4b8ec07
CS
6694 int idx_peer = 1;
6695 int idx_number = 3;
6696 char base_xpath[XPATH_MAXLEN];
718e3744 6697
f4b8ec07
CS
6698 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6699 sizeof(base_xpath), NULL)
6700 < 0)
d62a17ae 6701 return CMD_WARNING_CONFIG_FAILED;
718e3744 6702
f4b8ec07
CS
6703 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6704 argv[idx_number]->arg);
718e3744 6705
f4b8ec07 6706 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6707}
6708
f4b8ec07
CS
6709DEFUN_YANG (no_neighbor_ebgp_multihop,
6710 no_neighbor_ebgp_multihop_cmd,
6711 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6712 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6713 "Allow EBGP neighbors not on directly connected networks\n"
6714 "maximum hop count\n")
718e3744 6715{
d62a17ae 6716 int idx_peer = 2;
f4b8ec07
CS
6717 char base_xpath[XPATH_MAXLEN];
6718
6719 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6720 sizeof(base_xpath), NULL)
6721 < 0)
6722 return CMD_WARNING_CONFIG_FAILED;
6723
6724 if (argc > 4)
6725 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6726 NB_OP_DESTROY, NULL);
6727 else
6728 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6729 NB_OP_MODIFY, "false");
6730
6731 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6732}
6733
6b0655a2 6734
6ffd2079 6735/* disable-connected-check */
f4b8ec07
CS
6736DEFUN_YANG (neighbor_disable_connected_check,
6737 neighbor_disable_connected_check_cmd,
6738 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6739 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6740 "one-hop away EBGP peer using loopback address\n"
6741 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6742{
d62a17ae 6743 int idx_peer = 1;
f4b8ec07
CS
6744 char base_xpath[XPATH_MAXLEN];
6745
6746 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6747 sizeof(base_xpath), NULL)
6748 < 0)
6749 return CMD_WARNING_CONFIG_FAILED;
6750
6751 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6752 NB_OP_MODIFY, "true");
6753
6754 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6755}
6756
f4b8ec07
CS
6757DEFUN_YANG (no_neighbor_disable_connected_check,
6758 no_neighbor_disable_connected_check_cmd,
6759 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6760 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6761 "one-hop away EBGP peer using loopback address\n"
6762 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6763{
d62a17ae 6764 int idx_peer = 2;
f4b8ec07
CS
6765 char base_xpath[XPATH_MAXLEN];
6766
6767 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6768 sizeof(base_xpath), NULL)
6769 < 0)
6770 return CMD_WARNING_CONFIG_FAILED;
6771
6772 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6773 NB_OP_MODIFY, "false");
6774
6775 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6776}
6777
47cbc09b
PM
6778
6779/* enforce-first-as */
f4b8ec07
CS
6780DEFUN_YANG (neighbor_enforce_first_as,
6781 neighbor_enforce_first_as_cmd,
6782 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6783 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6784 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6785{
6786 int idx_peer = 1;
f4b8ec07 6787 char base_xpath[XPATH_MAXLEN];
47cbc09b 6788
f4b8ec07
CS
6789 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6790 sizeof(base_xpath), NULL)
6791 < 0)
6792 return CMD_WARNING_CONFIG_FAILED;
6793
6794 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6795
6796 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6797}
6798
f4b8ec07
CS
6799DEFUN_YANG (no_neighbor_enforce_first_as,
6800 no_neighbor_enforce_first_as_cmd,
6801 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6802 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6803 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6804{
6805 int idx_peer = 2;
f4b8ec07 6806 char base_xpath[XPATH_MAXLEN];
47cbc09b 6807
f4b8ec07
CS
6808 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6809 sizeof(base_xpath), NULL)
6810 < 0)
6811 return CMD_WARNING_CONFIG_FAILED;
6812
6813 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6814
6815 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
6816}
6817
f4b8ec07
CS
6818static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6819 char *base_xpath, int xpath_len,
6820 char *xpath)
6821{
6822 union sockunion su;
6823 char num_xpath[XPATH_MAXLEN];
6824 char unnbr_xpath[XPATH_MAXLEN];
6825 char prgrp_xpath[XPATH_MAXLEN];
6826
6827 if (str2sockunion(peer_str, &su) == 0) {
6828 snprintf(num_xpath, sizeof(num_xpath),
6829 "/neighbors/neighbor[remote-address='%s']", peer_str);
6830 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6831 VTY_CURR_XPATH, num_xpath)) {
6832 snprintf(base_xpath, xpath_len,
6833 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6834 xpath ? xpath : "");
6835 } else {
6836 vty_out(vty,
6837 "%% Specify remote-as or peer-group commands first\n");
6838 return -1;
6839 }
6840
6841 } else {
6842 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6843 "/neighbors/unnumbered-neighbor[interface='%s']",
6844 peer_str);
6845
6846 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6847 "/peer-groups/peer-group[peer-group-name='%s']",
6848 peer_str);
6849
6850 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6851 VTY_CURR_XPATH, unnbr_xpath)) {
6852 snprintf(base_xpath, xpath_len,
6853 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6854 xpath ? xpath : "");
6855 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6856 "%s%s", VTY_CURR_XPATH,
6857 prgrp_xpath)) {
6858 snprintf(base_xpath, xpath_len,
6859 FRR_BGP_PEER_GROUP_XPATH, peer_str,
6860 xpath ? xpath : "");
6861 } else {
6862 vty_out(vty,
6863 "%% Create the peer-group or interface first\n");
6864 return -1;
6865 }
6866 }
6867
6868 return 0;
6869}
47cbc09b 6870
f4b8ec07
CS
6871DEFUN_YANG (neighbor_description,
6872 neighbor_description_cmd,
6873 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6874 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6875 "Neighbor specific description\n"
6876 "Up to 80 characters describing this neighbor\n")
718e3744 6877{
d62a17ae 6878 int idx_peer = 1;
6879 int idx_line = 3;
f4b8ec07
CS
6880 int ret;
6881 char base_xpath[XPATH_MAXLEN];
d62a17ae 6882 char *str;
718e3744 6883
f4b8ec07
CS
6884 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6885 sizeof(base_xpath), NULL)
6886 < 0)
d62a17ae 6887 return CMD_WARNING_CONFIG_FAILED;
718e3744 6888
d62a17ae 6889 str = argv_concat(argv, argc, idx_line);
718e3744 6890
f4b8ec07
CS
6891 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
6892
6893 ret = nb_cli_apply_changes(vty, base_xpath);
718e3744 6894
d62a17ae 6895 XFREE(MTYPE_TMP, str);
718e3744 6896
f4b8ec07 6897 return ret;
718e3744 6898}
6899
f4b8ec07
CS
6900DEFUN_YANG (no_neighbor_description,
6901 no_neighbor_description_cmd,
6902 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6903 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6904 "Neighbor specific description\n")
718e3744 6905{
d62a17ae 6906 int idx_peer = 2;
f4b8ec07
CS
6907 char base_xpath[XPATH_MAXLEN];
6908
6909 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6910 sizeof(base_xpath), NULL)
6911 < 0)
d62a17ae 6912 return CMD_WARNING_CONFIG_FAILED;
718e3744 6913
f4b8ec07 6914 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
718e3744 6915
f4b8ec07 6916 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6917}
6918
a14810f4
PM
6919ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6920 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6921 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6922 "Neighbor specific description\n"
6923 "Up to 80 characters describing this neighbor\n")
6b0655a2 6924
d62a17ae 6925#define BGP_UPDATE_SOURCE_HELP_STR \
6926 "IPv4 address\n" \
6927 "IPv6 address\n" \
6928 "Interface name (requires zebra to be running)\n"
369688c0 6929
f4b8ec07
CS
6930DEFUN_YANG (neighbor_update_source,
6931 neighbor_update_source_cmd,
6932 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6934 "Source of routing updates\n"
6935 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6936{
d62a17ae 6937 int idx_peer = 1;
6938 int idx_peer_2 = 3;
f4b8ec07
CS
6939 union sockunion su;
6940 char base_xpath[XPATH_MAXLEN];
6941
6942 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6943 sizeof(base_xpath), NULL)
6944 < 0)
6945 return CMD_WARNING_CONFIG_FAILED;
6946
6947 // NOTE: Check source_str prefix address
6948 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
6949 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
d62a17ae 6950 argv[idx_peer_2]->arg);
f4b8ec07
CS
6951 else
6952 nb_cli_enqueue_change(vty, "./update-source/interface",
6953 NB_OP_MODIFY, argv[idx_peer_2]->arg);
6954
6955 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6956}
6957
f4b8ec07
CS
6958DEFUN_YANG (no_neighbor_update_source,
6959 no_neighbor_update_source_cmd,
6960 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6961 NO_STR NEIGHBOR_STR
6962 NEIGHBOR_ADDR_STR2
6963 "Source of routing updates\n"
6964 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6965{
d62a17ae 6966 int idx_peer = 2;
f4b8ec07
CS
6967 char base_xpath[XPATH_MAXLEN];
6968 char abs_xpath_ip[XPATH_MAXLEN];
6969 char abs_xpath_intf[XPATH_MAXLEN];
6970
6971 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6972 sizeof(base_xpath), NULL)
6973 < 0)
6974 return CMD_WARNING_CONFIG_FAILED;
6975
6976 snprintf(abs_xpath_ip, sizeof(abs_xpath_ip), "%s%s/update-source/ip",
6977 VTY_CURR_XPATH, base_xpath + 1);
6978 snprintf(abs_xpath_intf, sizeof(abs_xpath_intf),
6979 "%s%s/update-source/interface", VTY_CURR_XPATH,
6980 base_xpath + 1);
6981
6982 if (yang_dnode_exists(vty->candidate_config->dnode, abs_xpath_ip)) {
6983 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY,
6984 NULL);
6985 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6986 abs_xpath_intf)) {
6987 nb_cli_enqueue_change(vty, "./update-source/interface",
6988 NB_OP_DESTROY, NULL);
6989 }
6990
6991 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6992}
6b0655a2 6993
d62a17ae 6994static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6995 afi_t afi, safi_t safi,
6996 const char *rmap, int set)
718e3744 6997{
d62a17ae 6998 int ret;
6999 struct peer *peer;
80912664 7000 struct route_map *route_map = NULL;
718e3744 7001
d62a17ae 7002 peer = peer_and_group_lookup_vty(vty, peer_str);
7003 if (!peer)
7004 return CMD_WARNING_CONFIG_FAILED;
718e3744 7005
1de27621 7006 if (set) {
80912664
DS
7007 if (rmap)
7008 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7009 ret = peer_default_originate_set(peer, afi, safi,
7010 rmap, route_map);
7011 } else
d62a17ae 7012 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7013
d62a17ae 7014 return bgp_vty_return(vty, ret);
718e3744 7015}
7016
7017/* neighbor default-originate. */
7018DEFUN (neighbor_default_originate,
7019 neighbor_default_originate_cmd,
9ccf14f7 7020 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7021 NEIGHBOR_STR
7022 NEIGHBOR_ADDR_STR2
7023 "Originate default route to this neighbor\n")
7024{
d62a17ae 7025 int idx_peer = 1;
7026 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7027 bgp_node_afi(vty),
7028 bgp_node_safi(vty), NULL, 1);
718e3744 7029}
7030
d62a17ae 7031ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7032 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7033 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7034 "Originate default route to this neighbor\n")
596c17ba 7035
718e3744 7036DEFUN (neighbor_default_originate_rmap,
7037 neighbor_default_originate_rmap_cmd,
9ccf14f7 7038 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 7039 NEIGHBOR_STR
7040 NEIGHBOR_ADDR_STR2
7041 "Originate default route to this neighbor\n"
7042 "Route-map to specify criteria to originate default\n"
7043 "route-map name\n")
7044{
d62a17ae 7045 int idx_peer = 1;
7046 int idx_word = 4;
7047 return peer_default_originate_set_vty(
7048 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7049 argv[idx_word]->arg, 1);
718e3744 7050}
7051
d62a17ae 7052ALIAS_HIDDEN(
7053 neighbor_default_originate_rmap,
7054 neighbor_default_originate_rmap_hidden_cmd,
7055 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7056 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7057 "Originate default route to this neighbor\n"
7058 "Route-map to specify criteria to originate default\n"
7059 "route-map name\n")
596c17ba 7060
718e3744 7061DEFUN (no_neighbor_default_originate,
7062 no_neighbor_default_originate_cmd,
a636c635 7063 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 7064 NO_STR
7065 NEIGHBOR_STR
7066 NEIGHBOR_ADDR_STR2
a636c635
DW
7067 "Originate default route to this neighbor\n"
7068 "Route-map to specify criteria to originate default\n"
7069 "route-map name\n")
718e3744 7070{
d62a17ae 7071 int idx_peer = 2;
7072 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7073 bgp_node_afi(vty),
7074 bgp_node_safi(vty), NULL, 0);
718e3744 7075}
7076
d62a17ae 7077ALIAS_HIDDEN(
7078 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7079 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7080 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7081 "Originate default route to this neighbor\n"
7082 "Route-map to specify criteria to originate default\n"
7083 "route-map name\n")
596c17ba 7084
6b0655a2 7085
f418446b 7086/* Set specified peer's BGP port. */
f4b8ec07
CS
7087DEFUN_YANG (neighbor_port,
7088 neighbor_port_cmd,
7089 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7090 NEIGHBOR_STR
7091 NEIGHBOR_ADDR_STR
7092 "Neighbor's BGP port\n"
7093 "TCP port number\n")
718e3744 7094{
d62a17ae 7095 int idx_ip = 1;
7096 int idx_number = 3;
f4b8ec07 7097 char base_xpath[XPATH_MAXLEN];
718e3744 7098
f4b8ec07
CS
7099 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7100 argv[idx_ip]->arg, "");
718e3744 7101
f4b8ec07
CS
7102 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7103 argv[idx_number]->arg);
7104
7105 return nb_cli_apply_changes(vty, base_xpath);
7106}
6b0655a2 7107
f4b8ec07
CS
7108DEFUN_YANG (no_neighbor_port,
7109 no_neighbor_port_cmd,
7110 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7111 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7112 "Neighbor's BGP port\n"
7113 "TCP port number\n")
718e3744 7114{
f4b8ec07
CS
7115 int idx_ip = 2;
7116 char base_xpath[XPATH_MAXLEN];
718e3744 7117
f4b8ec07
CS
7118 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7119 argv[idx_ip]->arg, "");
718e3744 7120
f4b8ec07 7121 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
718e3744 7122
f4b8ec07 7123 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7124}
7125
f4b8ec07
CS
7126DEFUN_YANG (neighbor_weight,
7127 neighbor_weight_cmd,
7128 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7129 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7130 "Set default weight for routes from this neighbor\n"
7131 "default weight\n")
718e3744 7132{
f4b8ec07
CS
7133 int idx_peer = 1;
7134 int idx_number = 3;
7135 char base_xpath[XPATH_MAXLEN];
7136 char af_xpath[XPATH_MAXLEN];
7137 char attr_xpath[XPATH_MAXLEN];
7138 afi_t afi = bgp_node_afi(vty);
7139 safi_t safi = bgp_node_safi(vty);
718e3744 7140
f4b8ec07
CS
7141 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7142 yang_afi_safi_value2identity(afi, safi));
7143
7144 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7145 sizeof(base_xpath), af_xpath)
7146 < 0)
d62a17ae 7147 return CMD_WARNING_CONFIG_FAILED;
718e3744 7148
f4b8ec07
CS
7149 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7150 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7151
f4b8ec07
CS
7152 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7153 argv[idx_number]->arg);
7154
7155 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7156}
7157
d62a17ae 7158ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7159 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7160 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7161 "Set default weight for routes from this neighbor\n"
7162 "default weight\n")
596c17ba 7163
f4b8ec07
CS
7164DEFUN_YANG (no_neighbor_weight,
7165 no_neighbor_weight_cmd,
7166 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7167 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7168 "Set default weight for routes from this neighbor\n"
7169 "default weight\n")
718e3744 7170{
d62a17ae 7171 int idx_peer = 2;
f4b8ec07
CS
7172 char base_xpath[XPATH_MAXLEN];
7173 char af_xpath[XPATH_MAXLEN];
7174 char attr_xpath[XPATH_MAXLEN];
7175 afi_t afi = bgp_node_afi(vty);
7176 safi_t safi = bgp_node_safi(vty);
7177
7178 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7179 yang_afi_safi_value2identity(afi, safi));
7180
7181 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7182 sizeof(base_xpath), af_xpath)
7183 < 0)
7184 return CMD_WARNING_CONFIG_FAILED;
7185
7186 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7187 bgp_afi_safi_get_container_str(afi, safi));
7188
7189 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7190
7191 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7192}
7193
d62a17ae 7194ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7195 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7196 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7197 "Set default weight for routes from this neighbor\n"
7198 "default weight\n")
596c17ba 7199
6b0655a2 7200
718e3744 7201/* Override capability negotiation. */
7202DEFUN (neighbor_override_capability,
7203 neighbor_override_capability_cmd,
9ccf14f7 7204 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 7205 NEIGHBOR_STR
7206 NEIGHBOR_ADDR_STR2
7207 "Override capability negotiation result\n")
7208{
d62a17ae 7209 int idx_peer = 1;
7210 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7211 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7212}
7213
7214DEFUN (no_neighbor_override_capability,
7215 no_neighbor_override_capability_cmd,
9ccf14f7 7216 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 7217 NO_STR
7218 NEIGHBOR_STR
7219 NEIGHBOR_ADDR_STR2
7220 "Override capability negotiation result\n")
7221{
d62a17ae 7222 int idx_peer = 2;
7223 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7224 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7225}
6b0655a2 7226
718e3744 7227DEFUN (neighbor_strict_capability,
7228 neighbor_strict_capability_cmd,
9fb964de 7229 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 7230 NEIGHBOR_STR
9fb964de 7231 NEIGHBOR_ADDR_STR2
718e3744 7232 "Strict capability negotiation match\n")
7233{
9fb964de
PM
7234 int idx_peer = 1;
7235
7236 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 7237 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7238}
7239
7240DEFUN (no_neighbor_strict_capability,
7241 no_neighbor_strict_capability_cmd,
9fb964de 7242 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 7243 NO_STR
7244 NEIGHBOR_STR
9fb964de 7245 NEIGHBOR_ADDR_STR2
718e3744 7246 "Strict capability negotiation match\n")
7247{
9fb964de
PM
7248 int idx_peer = 2;
7249
7250 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 7251 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7252}
6b0655a2 7253
f4b8ec07
CS
7254DEFUN_YANG (neighbor_timers,
7255 neighbor_timers_cmd,
7256 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7257 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7258 "BGP per neighbor timers\n"
7259 "Keepalive interval\n"
7260 "Holdtime\n")
718e3744 7261{
f4b8ec07
CS
7262 int idx_peer = 1;
7263 int idx_number = 3;
7264 int idx_number_2 = 4;
7265 char base_xpath[XPATH_MAXLEN];
718e3744 7266
f4b8ec07
CS
7267 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7268 sizeof(base_xpath), NULL)
7269 < 0)
d62a17ae 7270 return CMD_WARNING_CONFIG_FAILED;
718e3744 7271
f4b8ec07
CS
7272 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7273 argv[idx_number]->arg);
718e3744 7274
f4b8ec07
CS
7275 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7276 argv[idx_number_2]->arg);
718e3744 7277
f4b8ec07 7278 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7279}
6b0655a2 7280
f4b8ec07
CS
7281DEFUN_YANG (no_neighbor_timers,
7282 no_neighbor_timers_cmd,
7283 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7284 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7285 "BGP per neighbor timers\n"
7286 "Keepalive interval\n"
7287 "Holdtime\n")
718e3744 7288{
f4b8ec07
CS
7289 int idx_peer = 2;
7290 char base_xpath[XPATH_MAXLEN];
718e3744 7291
f4b8ec07
CS
7292 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7293 sizeof(base_xpath), NULL)
7294 < 0)
d62a17ae 7295 return CMD_WARNING_CONFIG_FAILED;
718e3744 7296
f4b8ec07 7297 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
718e3744 7298
f4b8ec07 7299 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
718e3744 7300
f4b8ec07 7301 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7302}
6b0655a2 7303
f4b8ec07
CS
7304DEFUN_YANG (neighbor_timers_connect,
7305 neighbor_timers_connect_cmd,
7306 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7307 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7308 "BGP per neighbor timers\n"
7309 "BGP connect timer\n"
7310 "Connect timer\n")
718e3744 7311{
f4b8ec07
CS
7312 int idx_peer = 1;
7313 int idx_number = 4;
7314 char base_xpath[XPATH_MAXLEN];
718e3744 7315
f4b8ec07
CS
7316 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7317 sizeof(base_xpath), NULL)
7318 < 0)
d62a17ae 7319 return CMD_WARNING_CONFIG_FAILED;
718e3744 7320
f4b8ec07
CS
7321 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7322 argv[idx_number]->arg);
718e3744 7323
f4b8ec07 7324 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7325}
7326
f4b8ec07
CS
7327DEFUN_YANG (no_neighbor_timers_connect,
7328 no_neighbor_timers_connect_cmd,
7329 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7330 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7331 "BGP per neighbor timers\n"
7332 "BGP connect timer\n"
7333 "Connect timer\n")
718e3744 7334{
f4b8ec07
CS
7335 int idx_peer = 2;
7336 char base_xpath[XPATH_MAXLEN];
718e3744 7337
f4b8ec07
CS
7338 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7339 sizeof(base_xpath), NULL)
7340 < 0)
d62a17ae 7341 return CMD_WARNING_CONFIG_FAILED;
718e3744 7342
f4b8ec07
CS
7343 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7344 NULL);
718e3744 7345
f4b8ec07 7346 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7347}
7348
f4b8ec07
CS
7349DEFUN_YANG (neighbor_advertise_interval,
7350 neighbor_advertise_interval_cmd,
7351 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7352 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7353 "Minimum interval between sending BGP routing updates\n"
7354 "time in seconds\n")
718e3744 7355{
d62a17ae 7356 int idx_peer = 1;
f4b8ec07
CS
7357 int idx_number = 3;
7358 char base_xpath[XPATH_MAXLEN];
718e3744 7359
f4b8ec07
CS
7360 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7361 sizeof(base_xpath), NULL)
7362 < 0)
d62a17ae 7363 return CMD_WARNING_CONFIG_FAILED;
718e3744 7364
f4b8ec07
CS
7365 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7366 argv[idx_number]->arg);
718e3744 7367
f4b8ec07 7368 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7369}
7370
f4b8ec07
CS
7371DEFUN_YANG (no_neighbor_advertise_interval,
7372 no_neighbor_advertise_interval_cmd,
7373 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7374 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7375 "Minimum interval between sending BGP routing updates\n"
7376 "time in seconds\n")
718e3744 7377{
d62a17ae 7378 int idx_peer = 2;
f4b8ec07
CS
7379 char base_xpath[XPATH_MAXLEN];
7380
7381 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7382 sizeof(base_xpath), NULL)
7383 < 0)
7384 return CMD_WARNING_CONFIG_FAILED;
7385
7386 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7387 NULL);
7388
7389 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7390}
7391
6b0655a2 7392
518f0eb1
DS
7393/* Time to wait before processing route-map updates */
7394DEFUN (bgp_set_route_map_delay_timer,
7395 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7396 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7397 SET_STR
7398 "BGP route-map delay timer\n"
7399 "Time in secs to wait before processing route-map changes\n"
f414725f 7400 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7401{
d62a17ae 7402 int idx_number = 3;
d7c0a89a 7403 uint32_t rmap_delay_timer;
d62a17ae 7404
7405 if (argv[idx_number]->arg) {
7406 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7407 bm->rmap_update_timer = rmap_delay_timer;
7408
7409 /* if the dynamic update handling is being disabled, and a timer
7410 * is
7411 * running, stop the timer and act as if the timer has already
7412 * fired.
7413 */
7414 if (!rmap_delay_timer && bm->t_rmap_update) {
7415 BGP_TIMER_OFF(bm->t_rmap_update);
7416 thread_execute(bm->master, bgp_route_map_update_timer,
7417 NULL, 0);
7418 }
7419 return CMD_SUCCESS;
7420 } else {
7421 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7422 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7423 }
518f0eb1
DS
7424}
7425
7426DEFUN (no_bgp_set_route_map_delay_timer,
7427 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7428 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7429 NO_STR
3a2d747c 7430 BGP_STR
518f0eb1 7431 "Default BGP route-map delay timer\n"
8334fd5a
DW
7432 "Reset to default time to wait for processing route-map changes\n"
7433 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7434{
518f0eb1 7435
d62a17ae 7436 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7437
d62a17ae 7438 return CMD_SUCCESS;
518f0eb1
DS
7439}
7440
f4b8ec07
CS
7441DEFUN_YANG (neighbor_interface,
7442 neighbor_interface_cmd,
7443 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7444 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7445 "Interface\n"
7446 "Interface name\n")
718e3744 7447{
f4b8ec07
CS
7448 int idx_ip = 1;
7449 int idx_word = 3;
7450 char base_xpath[XPATH_MAXLEN];
718e3744 7451
f4b8ec07
CS
7452 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7453 argv[idx_ip]->arg, "");
718e3744 7454
f4b8ec07
CS
7455 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7456 argv[idx_word]->arg);
718e3744 7457
f4b8ec07 7458 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7459}
7460
f4b8ec07
CS
7461DEFUN_YANG (no_neighbor_interface,
7462 no_neighbor_interface_cmd,
7463 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7464 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7465 "Interface\n"
7466 "Interface name\n")
718e3744 7467{
d62a17ae 7468 int idx_peer = 2;
f4b8ec07
CS
7469 char base_xpath[XPATH_MAXLEN];
7470
7471 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7472 argv[idx_peer]->arg, "");
7473
7474 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7475
7476 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7477}
6b0655a2 7478
718e3744 7479DEFUN (neighbor_distribute_list,
7480 neighbor_distribute_list_cmd,
9ccf14f7 7481 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7482 NEIGHBOR_STR
7483 NEIGHBOR_ADDR_STR2
7484 "Filter updates to/from this neighbor\n"
7485 "IP access-list number\n"
7486 "IP access-list number (expanded range)\n"
7487 "IP Access-list name\n"
7488 "Filter incoming updates\n"
7489 "Filter outgoing updates\n")
7490{
d62a17ae 7491 int idx_peer = 1;
7492 int idx_acl = 3;
7493 int direct, ret;
7494 struct peer *peer;
a8206004 7495
d62a17ae 7496 const char *pstr = argv[idx_peer]->arg;
7497 const char *acl = argv[idx_acl]->arg;
7498 const char *inout = argv[argc - 1]->text;
a8206004 7499
d62a17ae 7500 peer = peer_and_group_lookup_vty(vty, pstr);
7501 if (!peer)
7502 return CMD_WARNING_CONFIG_FAILED;
a8206004 7503
d62a17ae 7504 /* Check filter direction. */
7505 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7506 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7507 direct, acl);
a8206004 7508
d62a17ae 7509 return bgp_vty_return(vty, ret);
718e3744 7510}
7511
d62a17ae 7512ALIAS_HIDDEN(
7513 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7514 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7515 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7516 "Filter updates to/from this neighbor\n"
7517 "IP access-list number\n"
7518 "IP access-list number (expanded range)\n"
7519 "IP Access-list name\n"
7520 "Filter incoming updates\n"
7521 "Filter outgoing updates\n")
596c17ba 7522
718e3744 7523DEFUN (no_neighbor_distribute_list,
7524 no_neighbor_distribute_list_cmd,
9ccf14f7 7525 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7526 NO_STR
7527 NEIGHBOR_STR
7528 NEIGHBOR_ADDR_STR2
7529 "Filter updates to/from this neighbor\n"
7530 "IP access-list number\n"
7531 "IP access-list number (expanded range)\n"
7532 "IP Access-list name\n"
7533 "Filter incoming updates\n"
7534 "Filter outgoing updates\n")
7535{
d62a17ae 7536 int idx_peer = 2;
7537 int direct, ret;
7538 struct peer *peer;
a8206004 7539
d62a17ae 7540 const char *pstr = argv[idx_peer]->arg;
7541 const char *inout = argv[argc - 1]->text;
a8206004 7542
d62a17ae 7543 peer = peer_and_group_lookup_vty(vty, pstr);
7544 if (!peer)
7545 return CMD_WARNING_CONFIG_FAILED;
a8206004 7546
d62a17ae 7547 /* Check filter direction. */
7548 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7549 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7550 direct);
a8206004 7551
d62a17ae 7552 return bgp_vty_return(vty, ret);
718e3744 7553}
6b0655a2 7554
d62a17ae 7555ALIAS_HIDDEN(
7556 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7557 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7558 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7559 "Filter updates to/from this neighbor\n"
7560 "IP access-list number\n"
7561 "IP access-list number (expanded range)\n"
7562 "IP Access-list name\n"
7563 "Filter incoming updates\n"
7564 "Filter outgoing updates\n")
596c17ba 7565
718e3744 7566/* Set prefix list to the peer. */
d62a17ae 7567static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7568 afi_t afi, safi_t safi,
7569 const char *name_str,
7570 const char *direct_str)
718e3744 7571{
d62a17ae 7572 int ret;
d62a17ae 7573 int direct = FILTER_IN;
cf9ac8bf 7574 struct peer *peer;
718e3744 7575
d62a17ae 7576 peer = peer_and_group_lookup_vty(vty, ip_str);
7577 if (!peer)
7578 return CMD_WARNING_CONFIG_FAILED;
718e3744 7579
d62a17ae 7580 /* Check filter direction. */
7581 if (strncmp(direct_str, "i", 1) == 0)
7582 direct = FILTER_IN;
7583 else if (strncmp(direct_str, "o", 1) == 0)
7584 direct = FILTER_OUT;
718e3744 7585
d62a17ae 7586 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7587
d62a17ae 7588 return bgp_vty_return(vty, ret);
718e3744 7589}
7590
d62a17ae 7591static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7592 afi_t afi, safi_t safi,
7593 const char *direct_str)
718e3744 7594{
d62a17ae 7595 int ret;
7596 struct peer *peer;
7597 int direct = FILTER_IN;
718e3744 7598
d62a17ae 7599 peer = peer_and_group_lookup_vty(vty, ip_str);
7600 if (!peer)
7601 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7602
d62a17ae 7603 /* Check filter direction. */
7604 if (strncmp(direct_str, "i", 1) == 0)
7605 direct = FILTER_IN;
7606 else if (strncmp(direct_str, "o", 1) == 0)
7607 direct = FILTER_OUT;
718e3744 7608
d62a17ae 7609 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 7610
d62a17ae 7611 return bgp_vty_return(vty, ret);
718e3744 7612}
7613
7614DEFUN (neighbor_prefix_list,
7615 neighbor_prefix_list_cmd,
9ccf14f7 7616 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 7617 NEIGHBOR_STR
7618 NEIGHBOR_ADDR_STR2
7619 "Filter updates to/from this neighbor\n"
7620 "Name of a prefix list\n"
7621 "Filter incoming updates\n"
7622 "Filter outgoing updates\n")
7623{
d62a17ae 7624 int idx_peer = 1;
7625 int idx_word = 3;
7626 int idx_in_out = 4;
7627 return peer_prefix_list_set_vty(
7628 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7629 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7630}
7631
d62a17ae 7632ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7633 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7634 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7635 "Filter updates to/from this neighbor\n"
7636 "Name of a prefix list\n"
7637 "Filter incoming updates\n"
7638 "Filter outgoing updates\n")
596c17ba 7639
718e3744 7640DEFUN (no_neighbor_prefix_list,
7641 no_neighbor_prefix_list_cmd,
9ccf14f7 7642 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 7643 NO_STR
7644 NEIGHBOR_STR
7645 NEIGHBOR_ADDR_STR2
7646 "Filter updates to/from this neighbor\n"
7647 "Name of a prefix list\n"
7648 "Filter incoming updates\n"
7649 "Filter outgoing updates\n")
7650{
d62a17ae 7651 int idx_peer = 2;
7652 int idx_in_out = 5;
7653 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7654 bgp_node_afi(vty), bgp_node_safi(vty),
7655 argv[idx_in_out]->arg);
718e3744 7656}
6b0655a2 7657
d62a17ae 7658ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7659 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7660 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7661 "Filter updates to/from this neighbor\n"
7662 "Name of a prefix list\n"
7663 "Filter incoming updates\n"
7664 "Filter outgoing updates\n")
596c17ba 7665
d62a17ae 7666static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7667 safi_t safi, const char *name_str,
7668 const char *direct_str)
718e3744 7669{
d62a17ae 7670 int ret;
7671 struct peer *peer;
7672 int direct = FILTER_IN;
718e3744 7673
d62a17ae 7674 peer = peer_and_group_lookup_vty(vty, ip_str);
7675 if (!peer)
7676 return CMD_WARNING_CONFIG_FAILED;
718e3744 7677
d62a17ae 7678 /* Check filter direction. */
7679 if (strncmp(direct_str, "i", 1) == 0)
7680 direct = FILTER_IN;
7681 else if (strncmp(direct_str, "o", 1) == 0)
7682 direct = FILTER_OUT;
718e3744 7683
d62a17ae 7684 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7685
d62a17ae 7686 return bgp_vty_return(vty, ret);
718e3744 7687}
7688
d62a17ae 7689static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7690 safi_t safi, const char *direct_str)
718e3744 7691{
d62a17ae 7692 int ret;
7693 struct peer *peer;
7694 int direct = FILTER_IN;
718e3744 7695
d62a17ae 7696 peer = peer_and_group_lookup_vty(vty, ip_str);
7697 if (!peer)
7698 return CMD_WARNING_CONFIG_FAILED;
718e3744 7699
d62a17ae 7700 /* Check filter direction. */
7701 if (strncmp(direct_str, "i", 1) == 0)
7702 direct = FILTER_IN;
7703 else if (strncmp(direct_str, "o", 1) == 0)
7704 direct = FILTER_OUT;
718e3744 7705
d62a17ae 7706 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7707
d62a17ae 7708 return bgp_vty_return(vty, ret);
718e3744 7709}
7710
7711DEFUN (neighbor_filter_list,
7712 neighbor_filter_list_cmd,
9ccf14f7 7713 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7714 NEIGHBOR_STR
7715 NEIGHBOR_ADDR_STR2
7716 "Establish BGP filters\n"
7717 "AS path access-list name\n"
7718 "Filter incoming routes\n"
7719 "Filter outgoing routes\n")
7720{
d62a17ae 7721 int idx_peer = 1;
7722 int idx_word = 3;
7723 int idx_in_out = 4;
7724 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7725 bgp_node_safi(vty), argv[idx_word]->arg,
7726 argv[idx_in_out]->arg);
718e3744 7727}
7728
d62a17ae 7729ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7730 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7731 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7732 "Establish BGP filters\n"
7733 "AS path access-list name\n"
7734 "Filter incoming routes\n"
7735 "Filter outgoing routes\n")
596c17ba 7736
718e3744 7737DEFUN (no_neighbor_filter_list,
7738 no_neighbor_filter_list_cmd,
9ccf14f7 7739 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7740 NO_STR
7741 NEIGHBOR_STR
7742 NEIGHBOR_ADDR_STR2
7743 "Establish BGP filters\n"
7744 "AS path access-list name\n"
7745 "Filter incoming routes\n"
7746 "Filter outgoing routes\n")
7747{
d62a17ae 7748 int idx_peer = 2;
7749 int idx_in_out = 5;
7750 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7751 bgp_node_afi(vty), bgp_node_safi(vty),
7752 argv[idx_in_out]->arg);
718e3744 7753}
6b0655a2 7754
d62a17ae 7755ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7756 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7757 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7758 "Establish BGP filters\n"
7759 "AS path access-list name\n"
7760 "Filter incoming routes\n"
7761 "Filter outgoing routes\n")
596c17ba 7762
7f7940e6
MK
7763/* Set advertise-map to the peer. */
7764static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7765 afi_t afi, safi_t safi,
cf2ad4d8
MK
7766 const char *advertise_str,
7767 const char *condition_str, bool condition,
7768 bool set)
7f7940e6
MK
7769{
7770 int ret = CMD_WARNING_CONFIG_FAILED;
7771 struct peer *peer;
7772 struct route_map *advertise_map;
7773 struct route_map *condition_map;
7774
7775 peer = peer_and_group_lookup_vty(vty, ip_str);
7776 if (!peer)
7777 return ret;
7778
7779 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7780 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7781
cf2ad4d8
MK
7782 if (set)
7783 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7784 advertise_map, condition_str,
7785 condition_map, condition);
7786 else
7787 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7788 advertise_map, condition_str,
7789 condition_map, condition);
7f7940e6
MK
7790
7791 return bgp_vty_return(vty, ret);
7792}
7793
cf2ad4d8 7794DEFPY (neighbor_advertise_map,
7f7940e6 7795 neighbor_advertise_map_cmd,
52b84062 7796 "[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 7797 NO_STR
7f7940e6
MK
7798 NEIGHBOR_STR
7799 NEIGHBOR_ADDR_STR2
7800 "Route-map to conditionally advertise routes\n"
7801 "Name of advertise map\n"
7802 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7803 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7804 "Name of the exist or non exist map\n")
7f7940e6 7805{
7f7940e6
MK
7806 bool condition = CONDITION_EXIST;
7807
52b84062 7808 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7809 condition = CONDITION_NON_EXIST;
7810
52b84062
MK
7811 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7812 bgp_node_safi(vty), advertise_str,
7813 condition_str, condition, !no);
7f7940e6
MK
7814}
7815
7816ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7817 "[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
7818 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7819 "Route-map to conditionally advertise routes\n"
7820 "Name of advertise map\n"
7821 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7822 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7823 "Name of the exist or non exist map\n")
7f7940e6 7824
718e3744 7825/* Set route-map to the peer. */
d62a17ae 7826static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7827 afi_t afi, safi_t safi, const char *name_str,
7828 const char *direct_str)
718e3744 7829{
d62a17ae 7830 int ret;
7831 struct peer *peer;
7832 int direct = RMAP_IN;
1de27621 7833 struct route_map *route_map;
718e3744 7834
d62a17ae 7835 peer = peer_and_group_lookup_vty(vty, ip_str);
7836 if (!peer)
7837 return CMD_WARNING_CONFIG_FAILED;
718e3744 7838
d62a17ae 7839 /* Check filter direction. */
7840 if (strncmp(direct_str, "in", 2) == 0)
7841 direct = RMAP_IN;
7842 else if (strncmp(direct_str, "o", 1) == 0)
7843 direct = RMAP_OUT;
718e3744 7844
1de27621
DA
7845 route_map = route_map_lookup_warn_noexist(vty, name_str);
7846 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7847
d62a17ae 7848 return bgp_vty_return(vty, ret);
718e3744 7849}
7850
d62a17ae 7851static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7852 afi_t afi, safi_t safi,
7853 const char *direct_str)
718e3744 7854{
d62a17ae 7855 int ret;
7856 struct peer *peer;
7857 int direct = RMAP_IN;
718e3744 7858
d62a17ae 7859 peer = peer_and_group_lookup_vty(vty, ip_str);
7860 if (!peer)
7861 return CMD_WARNING_CONFIG_FAILED;
718e3744 7862
d62a17ae 7863 /* Check filter direction. */
7864 if (strncmp(direct_str, "in", 2) == 0)
7865 direct = RMAP_IN;
7866 else if (strncmp(direct_str, "o", 1) == 0)
7867 direct = RMAP_OUT;
718e3744 7868
d62a17ae 7869 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 7870
d62a17ae 7871 return bgp_vty_return(vty, ret);
718e3744 7872}
7873
7874DEFUN (neighbor_route_map,
7875 neighbor_route_map_cmd,
9ccf14f7 7876 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7877 NEIGHBOR_STR
7878 NEIGHBOR_ADDR_STR2
7879 "Apply route map to neighbor\n"
7880 "Name of route map\n"
7881 "Apply map to incoming routes\n"
2a3d5731 7882 "Apply map to outbound routes\n")
718e3744 7883{
d62a17ae 7884 int idx_peer = 1;
7885 int idx_word = 3;
7886 int idx_in_out = 4;
7887 return peer_route_map_set_vty(
7888 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7889 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7890}
7891
d62a17ae 7892ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7893 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7894 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7895 "Apply route map to neighbor\n"
7896 "Name of route map\n"
7897 "Apply map to incoming routes\n"
7898 "Apply map to outbound routes\n")
596c17ba 7899
718e3744 7900DEFUN (no_neighbor_route_map,
7901 no_neighbor_route_map_cmd,
9ccf14f7 7902 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7903 NO_STR
7904 NEIGHBOR_STR
7905 NEIGHBOR_ADDR_STR2
7906 "Apply route map to neighbor\n"
7907 "Name of route map\n"
7908 "Apply map to incoming routes\n"
2a3d5731 7909 "Apply map to outbound routes\n")
718e3744 7910{
d62a17ae 7911 int idx_peer = 2;
7912 int idx_in_out = 5;
7913 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7914 bgp_node_afi(vty), bgp_node_safi(vty),
7915 argv[idx_in_out]->arg);
718e3744 7916}
6b0655a2 7917
d62a17ae 7918ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7919 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7920 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7921 "Apply route map to neighbor\n"
7922 "Name of route map\n"
7923 "Apply map to incoming routes\n"
7924 "Apply map to outbound routes\n")
596c17ba 7925
718e3744 7926/* Set unsuppress-map to the peer. */
d62a17ae 7927static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7928 afi_t afi, safi_t safi,
7929 const char *name_str)
718e3744 7930{
d62a17ae 7931 int ret;
7932 struct peer *peer;
1de27621 7933 struct route_map *route_map;
718e3744 7934
d62a17ae 7935 peer = peer_and_group_lookup_vty(vty, ip_str);
7936 if (!peer)
7937 return CMD_WARNING_CONFIG_FAILED;
718e3744 7938
1de27621
DA
7939 route_map = route_map_lookup_warn_noexist(vty, name_str);
7940 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7941
d62a17ae 7942 return bgp_vty_return(vty, ret);
718e3744 7943}
7944
7945/* Unset route-map from the peer. */
d62a17ae 7946static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7947 afi_t afi, safi_t safi)
718e3744 7948{
d62a17ae 7949 int ret;
7950 struct peer *peer;
718e3744 7951
d62a17ae 7952 peer = peer_and_group_lookup_vty(vty, ip_str);
7953 if (!peer)
7954 return CMD_WARNING_CONFIG_FAILED;
718e3744 7955
d62a17ae 7956 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7957
d62a17ae 7958 return bgp_vty_return(vty, ret);
718e3744 7959}
7960
7961DEFUN (neighbor_unsuppress_map,
7962 neighbor_unsuppress_map_cmd,
9ccf14f7 7963 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7964 NEIGHBOR_STR
7965 NEIGHBOR_ADDR_STR2
7966 "Route-map to selectively unsuppress suppressed routes\n"
7967 "Name of route map\n")
7968{
d62a17ae 7969 int idx_peer = 1;
7970 int idx_word = 3;
7971 return peer_unsuppress_map_set_vty(
7972 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7973 argv[idx_word]->arg);
718e3744 7974}
7975
d62a17ae 7976ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7977 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7978 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7979 "Route-map to selectively unsuppress suppressed routes\n"
7980 "Name of route map\n")
596c17ba 7981
718e3744 7982DEFUN (no_neighbor_unsuppress_map,
7983 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7984 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7985 NO_STR
7986 NEIGHBOR_STR
7987 NEIGHBOR_ADDR_STR2
7988 "Route-map to selectively unsuppress suppressed routes\n"
7989 "Name of route map\n")
7990{
d62a17ae 7991 int idx_peer = 2;
7992 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7993 bgp_node_afi(vty),
7994 bgp_node_safi(vty));
718e3744 7995}
6b0655a2 7996
d62a17ae 7997ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7998 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7999 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8000 "Route-map to selectively unsuppress suppressed routes\n"
8001 "Name of route map\n")
596c17ba 8002
fde246e8
DA
8003/* Maximum number of prefix to be sent to the neighbor. */
8004DEFUN(neighbor_maximum_prefix_out,
8005 neighbor_maximum_prefix_out_cmd,
8006 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8007 NEIGHBOR_STR
8008 NEIGHBOR_ADDR_STR2
8009 "Maximum number of prefixes to be sent to this peer\n"
8010 "Maximum no. of prefix limit\n")
8011{
04261dec
CS
8012 char base_xpath[XPATH_MAXLEN];
8013 char af_xpath[XPATH_MAXLEN];
8014 char attr_xpath[XPATH_MAXLEN];
fde246e8
DA
8015 int idx_peer = 1;
8016 int idx_number = 3;
fde246e8
DA
8017 afi_t afi = bgp_node_afi(vty);
8018 safi_t safi = bgp_node_safi(vty);
8019
04261dec
CS
8020 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8021 yang_afi_safi_value2identity(afi, safi));
8022 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8023 sizeof(base_xpath), af_xpath)
8024 < 0)
fde246e8
DA
8025 return CMD_WARNING_CONFIG_FAILED;
8026
04261dec
CS
8027 snprintf(attr_xpath, sizeof(attr_xpath),
8028 "/%s/prefix-limit/direction-list[direction='out']",
8029 bgp_afi_safi_get_container_str(afi, safi));
8030 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
fde246e8 8031
04261dec 8032 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
fde246e8 8033
04261dec
CS
8034 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8035 argv[idx_number]->arg);
8036
8037 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8038}
8039
8040DEFUN(no_neighbor_maximum_prefix_out,
8041 no_neighbor_maximum_prefix_out_cmd,
8042 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8043 NO_STR
8044 NEIGHBOR_STR
8045 NEIGHBOR_ADDR_STR2
8046 "Maximum number of prefixes to be sent to this peer\n")
8047{
04261dec
CS
8048 char base_xpath[XPATH_MAXLEN];
8049 char af_xpath[XPATH_MAXLEN];
8050 char attr_xpath[XPATH_MAXLEN];
fde246e8 8051 int idx_peer = 2;
fde246e8
DA
8052 afi_t afi = bgp_node_afi(vty);
8053 safi_t safi = bgp_node_safi(vty);
8054
04261dec
CS
8055 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8056 yang_afi_safi_value2identity(afi, safi));
8057 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8058 sizeof(base_xpath), af_xpath)
8059 < 0)
fde246e8
DA
8060 return CMD_WARNING_CONFIG_FAILED;
8061
04261dec
CS
8062 snprintf(attr_xpath, sizeof(attr_xpath),
8063 "/%s/prefix-limit/direction-list[direction='out']",
8064 bgp_afi_safi_get_container_str(afi, safi));
8065 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8066
8067 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
fde246e8 8068
04261dec 8069 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8070}
8071
9cbd06e0
DA
8072/* Maximum number of prefix configuration. Prefix count is different
8073 for each peer configuration. So this configuration can be set for
718e3744 8074 each peer configuration. */
8075DEFUN (neighbor_maximum_prefix,
8076 neighbor_maximum_prefix_cmd,
9cbd06e0 8077 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
718e3744 8078 NEIGHBOR_STR
8079 NEIGHBOR_ADDR_STR2
8080 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8081 "maximum no. of prefix limit\n"
8082 "Force checking all received routes not only accepted\n")
718e3744 8083{
d62a17ae 8084 int idx_peer = 1;
8085 int idx_number = 3;
9cbd06e0 8086 int idx_force = 0;
04261dec
CS
8087 char base_xpath[XPATH_MAXLEN];
8088 char af_xpath[XPATH_MAXLEN];
8089 char attr_xpath[XPATH_MAXLEN];
8090 afi_t afi = bgp_node_afi(vty);
8091 safi_t safi = bgp_node_safi(vty);
8092
8093 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8094 yang_afi_safi_value2identity(afi, safi));
8095 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8096 sizeof(base_xpath), af_xpath)
8097 < 0)
8098 return CMD_WARNING_CONFIG_FAILED;
8099
8100 snprintf(attr_xpath, sizeof(attr_xpath),
8101 "/%s/prefix-limit/direction-list[direction='in']",
8102 bgp_afi_safi_get_container_str(afi, safi));
8103 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8104
8105 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9cbd06e0 8106
04261dec
CS
8107 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8108 argv[idx_number]->arg);
9cbd06e0 8109 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8110 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8111 "true");
9cbd06e0 8112
04261dec 8113 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8114}
8115
d62a17ae 8116ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8117 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8118 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8119 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8120 "maximum no. of prefix limit\n"
8121 "Force checking all received routes not only accepted\n")
596c17ba 8122
e0701b79 8123DEFUN (neighbor_maximum_prefix_threshold,
8124 neighbor_maximum_prefix_threshold_cmd,
9cbd06e0 8125 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
e0701b79 8126 NEIGHBOR_STR
8127 NEIGHBOR_ADDR_STR2
8128 "Maximum number of prefix accept from this peer\n"
8129 "maximum no. of prefix limit\n"
9cbd06e0
DA
8130 "Threshold value (%) at which to generate a warning msg\n"
8131 "Force checking all received routes not only accepted\n")
e0701b79 8132{
d62a17ae 8133 int idx_peer = 1;
8134 int idx_number = 3;
8135 int idx_number_2 = 4;
9cbd06e0 8136 int idx_force = 0;
04261dec
CS
8137 char base_xpath[XPATH_MAXLEN];
8138 char af_xpath[XPATH_MAXLEN];
8139 char attr_xpath[XPATH_MAXLEN];
8140 afi_t afi = bgp_node_afi(vty);
8141 safi_t safi = bgp_node_safi(vty);
8142
8143 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8144 yang_afi_safi_value2identity(afi, safi));
8145 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8146 sizeof(base_xpath), af_xpath)
8147 < 0)
8148 return CMD_WARNING_CONFIG_FAILED;
8149
8150 snprintf(attr_xpath, sizeof(attr_xpath),
8151 "/%s/prefix-limit/direction-list[direction='in']",
8152 bgp_afi_safi_get_container_str(afi, safi));
8153 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8154
8155 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8156
8157 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8158 argv[idx_number]->arg);
8159
8160 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8161 NB_OP_MODIFY, argv[idx_number_2]->arg);
9cbd06e0
DA
8162
8163 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8164 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8165 "true");
9cbd06e0 8166
04261dec 8167 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8168}
e0701b79 8169
d62a17ae 8170ALIAS_HIDDEN(
8171 neighbor_maximum_prefix_threshold,
8172 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8173 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8174 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8175 "Maximum number of prefix accept from this peer\n"
8176 "maximum no. of prefix limit\n"
9cbd06e0
DA
8177 "Threshold value (%) at which to generate a warning msg\n"
8178 "Force checking all received routes not only accepted\n")
596c17ba 8179
718e3744 8180DEFUN (neighbor_maximum_prefix_warning,
8181 neighbor_maximum_prefix_warning_cmd,
9cbd06e0 8182 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
718e3744 8183 NEIGHBOR_STR
8184 NEIGHBOR_ADDR_STR2
8185 "Maximum number of prefix accept from this peer\n"
8186 "maximum no. of prefix limit\n"
9cbd06e0
DA
8187 "Only give warning message when limit is exceeded\n"
8188 "Force checking all received routes not only accepted\n")
718e3744 8189{
d62a17ae 8190 int idx_peer = 1;
8191 int idx_number = 3;
9cbd06e0 8192 int idx_force = 0;
04261dec
CS
8193 char base_xpath[XPATH_MAXLEN];
8194 char af_xpath[XPATH_MAXLEN];
8195 char attr_xpath[XPATH_MAXLEN];
8196 afi_t afi = bgp_node_afi(vty);
8197 safi_t safi = bgp_node_safi(vty);
8198
8199 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8200 yang_afi_safi_value2identity(afi, safi));
8201 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8202 sizeof(base_xpath), af_xpath)
8203 < 0)
8204 return CMD_WARNING_CONFIG_FAILED;
9cbd06e0 8205
04261dec
CS
8206 snprintf(attr_xpath, sizeof(attr_xpath),
8207 "/%s/prefix-limit/direction-list[direction='in']",
8208 bgp_afi_safi_get_container_str(afi, safi));
8209 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8210
8211 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8212
8213 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8214 argv[idx_number]->arg);
8215
8216 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8217 "true");
9cbd06e0 8218 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8219 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8220 "true");
9cbd06e0 8221
04261dec 8222 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8223}
8224
d62a17ae 8225ALIAS_HIDDEN(
8226 neighbor_maximum_prefix_warning,
8227 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8228 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8229 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8230 "Maximum number of prefix accept from this peer\n"
8231 "maximum no. of prefix limit\n"
9cbd06e0
DA
8232 "Only give warning message when limit is exceeded\n"
8233 "Force checking all received routes not only accepted\n")
596c17ba 8234
e0701b79 8235DEFUN (neighbor_maximum_prefix_threshold_warning,
8236 neighbor_maximum_prefix_threshold_warning_cmd,
9cbd06e0 8237 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
e0701b79 8238 NEIGHBOR_STR
8239 NEIGHBOR_ADDR_STR2
8240 "Maximum number of prefix accept from this peer\n"
8241 "maximum no. of prefix limit\n"
8242 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8243 "Only give warning message when limit is exceeded\n"
8244 "Force checking all received routes not only accepted\n")
e0701b79 8245{
d62a17ae 8246 int idx_peer = 1;
8247 int idx_number = 3;
8248 int idx_number_2 = 4;
9cbd06e0 8249 int idx_force = 0;
04261dec
CS
8250 char base_xpath[XPATH_MAXLEN];
8251 char af_xpath[XPATH_MAXLEN];
8252 char attr_xpath[XPATH_MAXLEN];
8253 afi_t afi = bgp_node_afi(vty);
8254 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8255
04261dec
CS
8256 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8257 yang_afi_safi_value2identity(afi, safi));
8258 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8259 sizeof(base_xpath), af_xpath)
8260 < 0)
8261 return CMD_WARNING_CONFIG_FAILED;
8262
8263 snprintf(attr_xpath, sizeof(attr_xpath),
8264 "/%s/prefix-limit/direction-list[direction='in']",
8265 bgp_afi_safi_get_container_str(afi, safi));
8266 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8267
8268 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8269
8270 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8271 argv[idx_number]->arg);
8272 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8273 NB_OP_MODIFY, argv[idx_number_2]->arg);
8274 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8275 "true");
9cbd06e0 8276 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8277 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8278 "true");
9cbd06e0 8279
04261dec 8280 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8281}
8282
d62a17ae 8283ALIAS_HIDDEN(
8284 neighbor_maximum_prefix_threshold_warning,
8285 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8286 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8287 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8288 "Maximum number of prefix accept from this peer\n"
8289 "maximum no. of prefix limit\n"
8290 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8291 "Only give warning message when limit is exceeded\n"
8292 "Force checking all received routes not only accepted\n")
596c17ba 8293
0a486e5f 8294DEFUN (neighbor_maximum_prefix_restart,
8295 neighbor_maximum_prefix_restart_cmd,
9cbd06e0 8296 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
0a486e5f 8297 NEIGHBOR_STR
8298 NEIGHBOR_ADDR_STR2
8299 "Maximum number of prefix accept from this peer\n"
8300 "maximum no. of prefix limit\n"
8301 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8302 "Restart interval in minutes\n"
8303 "Force checking all received routes not only accepted\n")
0a486e5f 8304{
d62a17ae 8305 int idx_peer = 1;
8306 int idx_number = 3;
8307 int idx_number_2 = 5;
9cbd06e0 8308 int idx_force = 0;
04261dec
CS
8309 char base_xpath[XPATH_MAXLEN];
8310 char af_xpath[XPATH_MAXLEN];
8311 char attr_xpath[XPATH_MAXLEN];
8312 afi_t afi = bgp_node_afi(vty);
8313 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8314
04261dec
CS
8315 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8316 yang_afi_safi_value2identity(afi, safi));
8317 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8318 sizeof(base_xpath), af_xpath)
8319 < 0)
8320 return CMD_WARNING_CONFIG_FAILED;
8321
8322 snprintf(attr_xpath, sizeof(attr_xpath),
8323 "/%s/prefix-limit/direction-list[direction='in']",
8324 bgp_afi_safi_get_container_str(afi, safi));
8325 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8326
8327 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8328
8329 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8330 argv[idx_number]->arg);
8331 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8332 argv[idx_number_2]->arg);
9cbd06e0 8333 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8334 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8335 "true");
9cbd06e0 8336
04261dec 8337 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8338}
8339
d62a17ae 8340ALIAS_HIDDEN(
8341 neighbor_maximum_prefix_restart,
8342 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8343 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8344 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8345 "Maximum number of prefix accept from this peer\n"
8346 "maximum no. of prefix limit\n"
8347 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8348 "Restart interval in minutes\n"
8349 "Force checking all received routes not only accepted\n")
596c17ba 8350
0a486e5f 8351DEFUN (neighbor_maximum_prefix_threshold_restart,
8352 neighbor_maximum_prefix_threshold_restart_cmd,
9cbd06e0 8353 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
0a486e5f 8354 NEIGHBOR_STR
8355 NEIGHBOR_ADDR_STR2
16cedbb0 8356 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 8357 "maximum no. of prefix limit\n"
8358 "Threshold value (%) at which to generate a warning msg\n"
8359 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8360 "Restart interval in minutes\n"
8361 "Force checking all received routes not only accepted\n")
0a486e5f 8362{
d62a17ae 8363 int idx_peer = 1;
8364 int idx_number = 3;
8365 int idx_number_2 = 4;
8366 int idx_number_3 = 6;
9cbd06e0 8367 int idx_force = 0;
04261dec
CS
8368 char base_xpath[XPATH_MAXLEN];
8369 char af_xpath[XPATH_MAXLEN];
8370 char attr_xpath[XPATH_MAXLEN];
8371 afi_t afi = bgp_node_afi(vty);
8372 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8373
04261dec
CS
8374 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8375 yang_afi_safi_value2identity(afi, safi));
8376 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8377 sizeof(base_xpath), af_xpath)
8378 < 0)
8379 return CMD_WARNING_CONFIG_FAILED;
8380
8381 snprintf(attr_xpath, sizeof(attr_xpath),
8382 "/%s/prefix-limit/direction-list[direction='in']",
8383 bgp_afi_safi_get_container_str(afi, safi));
8384 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8385
8386 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8387
8388 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8389 argv[idx_number]->arg);
8390 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8391 NB_OP_MODIFY, argv[idx_number_2]->arg);
8392 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8393 argv[idx_number_3]->arg);
9cbd06e0 8394 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8395 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8396 "true");
9cbd06e0 8397
04261dec 8398 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 8399}
8400
8401ALIAS_HIDDEN(
8402 neighbor_maximum_prefix_threshold_restart,
8403 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8404 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8405 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8406 "Maximum number of prefixes to accept from this peer\n"
8407 "maximum no. of prefix limit\n"
8408 "Threshold value (%) at which to generate a warning msg\n"
8409 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8410 "Restart interval in minutes\n"
8411 "Force checking all received routes not only accepted\n")
596c17ba 8412
718e3744 8413DEFUN (no_neighbor_maximum_prefix,
8414 no_neighbor_maximum_prefix_cmd,
9cbd06e0 8415 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
718e3744 8416 NO_STR
8417 NEIGHBOR_STR
8418 NEIGHBOR_ADDR_STR2
16cedbb0 8419 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
8420 "maximum no. of prefix limit\n"
8421 "Threshold value (%) at which to generate a warning msg\n"
8422 "Restart bgp connection after limit is exceeded\n"
16cedbb0 8423 "Restart interval in minutes\n"
9cbd06e0
DA
8424 "Only give warning message when limit is exceeded\n"
8425 "Force checking all received routes not only accepted\n")
718e3744 8426{
d62a17ae 8427 int idx_peer = 2;
04261dec
CS
8428 char base_xpath[XPATH_MAXLEN];
8429 char af_xpath[XPATH_MAXLEN];
8430 char attr_xpath[XPATH_MAXLEN];
8431 afi_t afi = bgp_node_afi(vty);
8432 safi_t safi = bgp_node_safi(vty);
8433
8434 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8435 yang_afi_safi_value2identity(afi, safi));
8436 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8437 sizeof(base_xpath), af_xpath)
8438 < 0)
8439 return CMD_WARNING_CONFIG_FAILED;
8440
8441 snprintf(attr_xpath, sizeof(attr_xpath),
8442 "/%s/prefix-limit/direction-list[direction='in']",
8443 bgp_afi_safi_get_container_str(afi, safi));
8444 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8445
8446 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8447
8448 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8449}
e52702f2 8450
d62a17ae 8451ALIAS_HIDDEN(
8452 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8453 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8454 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8455 "Maximum number of prefixes to accept from this peer\n"
8456 "maximum no. of prefix limit\n"
8457 "Threshold value (%) at which to generate a warning msg\n"
8458 "Restart bgp connection after limit is exceeded\n"
8459 "Restart interval in minutes\n"
9cbd06e0
DA
8460 "Only give warning message when limit is exceeded\n"
8461 "Force checking all received routes not only accepted\n")
596c17ba 8462
718e3744 8463
718e3744 8464/* "neighbor allowas-in" */
8465DEFUN (neighbor_allowas_in,
8466 neighbor_allowas_in_cmd,
fd8503f5 8467 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8468 NEIGHBOR_STR
8469 NEIGHBOR_ADDR_STR2
31500417 8470 "Accept as-path with my AS present in it\n"
f79f7a7b 8471 "Number of occurrences of AS number\n"
fd8503f5 8472 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8473{
d62a17ae 8474 int idx_peer = 1;
8475 int idx_number_origin = 3;
8476 int ret;
8477 int origin = 0;
8478 struct peer *peer;
8479 int allow_num = 0;
8480
8481 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8482 if (!peer)
8483 return CMD_WARNING_CONFIG_FAILED;
8484
8485 if (argc <= idx_number_origin)
8486 allow_num = 3;
8487 else {
8488 if (argv[idx_number_origin]->type == WORD_TKN)
8489 origin = 1;
8490 else
8491 allow_num = atoi(argv[idx_number_origin]->arg);
8492 }
8493
8494 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8495 allow_num, origin);
8496
8497 return bgp_vty_return(vty, ret);
8498}
8499
8500ALIAS_HIDDEN(
8501 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8502 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8503 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8504 "Accept as-path with my AS present in it\n"
f79f7a7b 8505 "Number of occurrences of AS number\n"
d62a17ae 8506 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8507
718e3744 8508DEFUN (no_neighbor_allowas_in,
8509 no_neighbor_allowas_in_cmd,
fd8503f5 8510 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8511 NO_STR
8512 NEIGHBOR_STR
8513 NEIGHBOR_ADDR_STR2
8334fd5a 8514 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8515 "Number of occurrences of AS number\n"
fd8503f5 8516 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8517{
d62a17ae 8518 int idx_peer = 2;
8519 int ret;
8520 struct peer *peer;
718e3744 8521
d62a17ae 8522 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8523 if (!peer)
8524 return CMD_WARNING_CONFIG_FAILED;
718e3744 8525
d62a17ae 8526 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8527 bgp_node_safi(vty));
718e3744 8528
d62a17ae 8529 return bgp_vty_return(vty, ret);
718e3744 8530}
6b0655a2 8531
d62a17ae 8532ALIAS_HIDDEN(
8533 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8534 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8535 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8536 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8537 "Number of occurrences of AS number\n"
d62a17ae 8538 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8539
f4b8ec07
CS
8540DEFUN_YANG (neighbor_ttl_security,
8541 neighbor_ttl_security_cmd,
8542 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8543 NEIGHBOR_STR
8544 NEIGHBOR_ADDR_STR2
8545 "BGP ttl-security parameters\n"
8546 "Specify the maximum number of hops to the BGP peer\n"
8547 "Number of hops to BGP peer\n")
fa411a21 8548{
d62a17ae 8549 int idx_peer = 1;
8550 int idx_number = 4;
f4b8ec07 8551 char base_xpath[XPATH_MAXLEN];
d62a17ae 8552
f4b8ec07
CS
8553 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8554 sizeof(base_xpath), NULL)
8555 < 0)
d62a17ae 8556 return CMD_WARNING_CONFIG_FAILED;
8557
f4b8ec07
CS
8558 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8559 argv[idx_number]->arg);
7ebe625c 8560
f4b8ec07 8561 return nb_cli_apply_changes(vty, base_xpath);
fa411a21
NH
8562}
8563
8564DEFUN (no_neighbor_ttl_security,
8565 no_neighbor_ttl_security_cmd,
7ebe625c 8566 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
8567 NO_STR
8568 NEIGHBOR_STR
7ebe625c 8569 NEIGHBOR_ADDR_STR2
16cedbb0 8570 "BGP ttl-security parameters\n"
3a2d747c
QY
8571 "Specify the maximum number of hops to the BGP peer\n"
8572 "Number of hops to BGP peer\n")
fa411a21 8573{
d62a17ae 8574 int idx_peer = 2;
f4b8ec07 8575 char base_xpath[XPATH_MAXLEN];
fa411a21 8576
f4b8ec07
CS
8577 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8578 sizeof(base_xpath), NULL)
8579 < 0)
d62a17ae 8580 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8581
f4b8ec07
CS
8582 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8583
8584 return nb_cli_apply_changes(vty, base_xpath);
fa411a21 8585}
6b0655a2 8586
adbac85e
DW
8587DEFUN (neighbor_addpath_tx_all_paths,
8588 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8589 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8590 NEIGHBOR_STR
8591 NEIGHBOR_ADDR_STR2
8592 "Use addpath to advertise all paths to a neighbor\n")
8593{
d62a17ae 8594 int idx_peer = 1;
8595 struct peer *peer;
adbac85e 8596
d62a17ae 8597 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8598 if (!peer)
8599 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8600
dcc68b5e
MS
8601 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8602 BGP_ADDPATH_ALL);
8603 return CMD_SUCCESS;
adbac85e
DW
8604}
8605
d62a17ae 8606ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8607 neighbor_addpath_tx_all_paths_hidden_cmd,
8608 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8609 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8610 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8611
adbac85e
DW
8612DEFUN (no_neighbor_addpath_tx_all_paths,
8613 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8614 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8615 NO_STR
8616 NEIGHBOR_STR
8617 NEIGHBOR_ADDR_STR2
8618 "Use addpath to advertise all paths to a neighbor\n")
8619{
d62a17ae 8620 int idx_peer = 2;
dcc68b5e
MS
8621 struct peer *peer;
8622
8623 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8624 if (!peer)
8625 return CMD_WARNING_CONFIG_FAILED;
8626
8627 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8628 != BGP_ADDPATH_ALL) {
8629 vty_out(vty,
8630 "%% Peer not currently configured to transmit all paths.");
8631 return CMD_WARNING_CONFIG_FAILED;
8632 }
8633
8634 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8635 BGP_ADDPATH_NONE);
8636
8637 return CMD_SUCCESS;
adbac85e
DW
8638}
8639
d62a17ae 8640ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8641 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8642 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8643 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8644 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8645
06370dac
DW
8646DEFUN (neighbor_addpath_tx_bestpath_per_as,
8647 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8648 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8649 NEIGHBOR_STR
8650 NEIGHBOR_ADDR_STR2
8651 "Use addpath to advertise the bestpath per each neighboring AS\n")
8652{
d62a17ae 8653 int idx_peer = 1;
8654 struct peer *peer;
06370dac 8655
d62a17ae 8656 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8657 if (!peer)
8658 return CMD_WARNING_CONFIG_FAILED;
06370dac 8659
dcc68b5e
MS
8660 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8661 BGP_ADDPATH_BEST_PER_AS);
8662
8663 return CMD_SUCCESS;
06370dac
DW
8664}
8665
d62a17ae 8666ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8667 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8668 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8669 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8670 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8671
06370dac
DW
8672DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8673 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8674 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8675 NO_STR
8676 NEIGHBOR_STR
8677 NEIGHBOR_ADDR_STR2
8678 "Use addpath to advertise the bestpath per each neighboring AS\n")
8679{
d62a17ae 8680 int idx_peer = 2;
dcc68b5e
MS
8681 struct peer *peer;
8682
8683 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8684 if (!peer)
8685 return CMD_WARNING_CONFIG_FAILED;
8686
8687 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8688 != BGP_ADDPATH_BEST_PER_AS) {
8689 vty_out(vty,
8690 "%% Peer not currently configured to transmit all best path per as.");
8691 return CMD_WARNING_CONFIG_FAILED;
8692 }
8693
8694 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8695 BGP_ADDPATH_NONE);
8696
8697 return CMD_SUCCESS;
06370dac
DW
8698}
8699
d62a17ae 8700ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8701 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8702 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8703 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8704 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8705
2b31007c
RZ
8706DEFPY(
8707 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8708 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8709 NEIGHBOR_STR
8710 NEIGHBOR_ADDR_STR2
8711 "Detect AS loops before sending to neighbor\n")
8712{
8713 struct peer *peer;
8714
8715 peer = peer_and_group_lookup_vty(vty, neighbor);
8716 if (!peer)
8717 return CMD_WARNING_CONFIG_FAILED;
8718
8719 peer->as_path_loop_detection = true;
8720
8721 return CMD_SUCCESS;
8722}
8723
8724DEFPY(
8725 no_neighbor_aspath_loop_detection,
8726 no_neighbor_aspath_loop_detection_cmd,
8727 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8728 NO_STR
8729 NEIGHBOR_STR
8730 NEIGHBOR_ADDR_STR2
8731 "Detect AS loops before sending to neighbor\n")
8732{
8733 struct peer *peer;
8734
8735 peer = peer_and_group_lookup_vty(vty, neighbor);
8736 if (!peer)
8737 return CMD_WARNING_CONFIG_FAILED;
8738
8739 peer->as_path_loop_detection = false;
8740
8741 return CMD_SUCCESS;
8742}
8743
b9c7bc5a 8744static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8745 struct ecommunity **list, bool is_rt6)
ddb5b488 8746{
b9c7bc5a
PZ
8747 struct ecommunity *ecom = NULL;
8748 struct ecommunity *ecomadd;
ddb5b488 8749
b9c7bc5a 8750 for (; argc; --argc, ++argv) {
9a659715
PG
8751 if (is_rt6)
8752 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8753 ECOMMUNITY_ROUTE_TARGET,
8754 0);
8755 else
8756 ecomadd = ecommunity_str2com(argv[0]->arg,
8757 ECOMMUNITY_ROUTE_TARGET,
8758 0);
b9c7bc5a
PZ
8759 if (!ecomadd) {
8760 vty_out(vty, "Malformed community-list value\n");
8761 if (ecom)
8762 ecommunity_free(&ecom);
8763 return CMD_WARNING_CONFIG_FAILED;
8764 }
ddb5b488 8765
b9c7bc5a
PZ
8766 if (ecom) {
8767 ecommunity_merge(ecom, ecomadd);
8768 ecommunity_free(&ecomadd);
8769 } else {
8770 ecom = ecomadd;
8771 }
8772 }
8773
8774 if (*list) {
8775 ecommunity_free(&*list);
ddb5b488 8776 }
b9c7bc5a
PZ
8777 *list = ecom;
8778
8779 return CMD_SUCCESS;
ddb5b488
PZ
8780}
8781
37a87b8f
CS
8782bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8783 bool v2vimport, char *errmsg, size_t errmsg_len)
8784{
8785 if (!v2vimport) {
8786 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8787 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8788 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8789 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8790 snprintf(
8791 errmsg, errmsg_len, "%s",
8792 "%% error: Please unconfigure import vrf commands before using vpn commands");
8793 return false;
8794 }
8795 } else {
8796 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8797 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8798 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8799 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8800 snprintf(
8801 errmsg, errmsg_len, "%s",
8802 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8803 return false;
8804 }
8805 }
8806 return true;
8807}
8808
0ca70ba5
DS
8809/*
8810 * v2vimport is true if we are handling a `import vrf ...` command
8811 */
8812static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8813{
0ca70ba5
DS
8814 afi_t afi;
8815
ddb5b488 8816 switch (vty->node) {
b9c7bc5a 8817 case BGP_IPV4_NODE:
0ca70ba5
DS
8818 afi = AFI_IP;
8819 break;
b9c7bc5a 8820 case BGP_IPV6_NODE:
0ca70ba5
DS
8821 afi = AFI_IP6;
8822 break;
ddb5b488
PZ
8823 default:
8824 vty_out(vty,
b9c7bc5a 8825 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8826 return AFI_MAX;
ddb5b488 8827 }
69b07479 8828
0ca70ba5
DS
8829 if (!v2vimport) {
8830 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8831 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8832 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8833 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8834 vty_out(vty,
8835 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8836 return AFI_MAX;
8837 }
8838 } else {
8839 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8840 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8841 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8842 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8843 vty_out(vty,
8844 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8845 return AFI_MAX;
8846 }
8847 }
8848 return afi;
ddb5b488
PZ
8849}
8850
37a87b8f
CS
8851DEFPY_YANG(
8852 af_rd_vpn_export,
8853 af_rd_vpn_export_cmd,
8854 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8855 NO_STR
8856 "Specify route distinguisher\n"
8857 "Between current address-family and vpn\n"
8858 "For routes leaked from current address-family to vpn\n"
8859 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8860{
37a87b8f 8861 char base_xpath[XPATH_MAXLEN];
ddb5b488 8862 afi_t afi;
37a87b8f 8863 safi_t safi;
b9c7bc5a 8864 int idx = 0;
b9c7bc5a 8865
37a87b8f
CS
8866 afi = bgp_node_afi(vty);
8867 safi = bgp_node_safi(vty);
ddb5b488 8868
37a87b8f
CS
8869 snprintf(
8870 base_xpath, sizeof(base_xpath),
8871 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
8872 yang_afi_safi_value2identity(afi, safi),
8873 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 8874
37a87b8f
CS
8875 if (argv_find(argv, argc, "no", &idx))
8876 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
8877 else
8878 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
ddb5b488 8879
37a87b8f
CS
8880 return nb_cli_apply_changes(vty, base_xpath);
8881}
ddb5b488 8882
37a87b8f
CS
8883void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
8884 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
8885{
8886 int indent = 2;
69b07479 8887
37a87b8f
CS
8888 vty_out(vty, "%*srd vpn export %s\n", indent, "",
8889 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
8890}
8891
b9c7bc5a
PZ
8892ALIAS (af_rd_vpn_export,
8893 af_no_rd_vpn_export_cmd,
8894 "no rd vpn export",
ddb5b488 8895 NO_STR
b9c7bc5a
PZ
8896 "Specify route distinguisher\n"
8897 "Between current address-family and vpn\n"
8898 "For routes leaked from current address-family to vpn\n")
ddb5b488 8899
b9c7bc5a
PZ
8900DEFPY (af_label_vpn_export,
8901 af_label_vpn_export_cmd,
e70e9f8e 8902 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8903 NO_STR
ddb5b488 8904 "label value for VRF\n"
b9c7bc5a
PZ
8905 "Between current address-family and vpn\n"
8906 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8907 "Label Value <0-1048575>\n"
8908 "Automatically assign a label\n")
ddb5b488
PZ
8909{
8910 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8911 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8912 afi_t afi;
b9c7bc5a 8913 int idx = 0;
c6423c31 8914 bool yes = true;
b9c7bc5a
PZ
8915
8916 if (argv_find(argv, argc, "no", &idx))
c6423c31 8917 yes = false;
ddb5b488 8918
21a16cc2
PZ
8919 /* If "no ...", squash trailing parameter */
8920 if (!yes)
8921 label_auto = NULL;
8922
e70e9f8e
PZ
8923 if (yes) {
8924 if (!label_auto)
8925 label = label_val; /* parser should force unsigned */
8926 }
ddb5b488 8927
0ca70ba5 8928 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8929 if (afi == AFI_MAX)
8930 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8931
e70e9f8e 8932
69b07479
DS
8933 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8934 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8935 /* no change */
8936 return CMD_SUCCESS;
e70e9f8e 8937
69b07479
DS
8938 /*
8939 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8940 */
8941 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8942 bgp_get_default(), bgp);
8943
8944 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8945 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8946
8947 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8948
8949 /*
8950 * label has previously been automatically
8951 * assigned by labelpool: release it
8952 *
8953 * NB if tovpn_label == MPLS_LABEL_NONE it
8954 * means the automatic assignment is in flight
8955 * and therefore the labelpool callback must
8956 * detect that the auto label is not needed.
8957 */
8958
8959 bgp_lp_release(LP_TYPE_VRF,
8960 &bgp->vpn_policy[afi],
8961 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8962 }
69b07479
DS
8963 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8964 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8965 }
ddb5b488 8966
69b07479
DS
8967 bgp->vpn_policy[afi].tovpn_label = label;
8968 if (label_auto) {
8969 SET_FLAG(bgp->vpn_policy[afi].flags,
8970 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8971 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8972 vpn_leak_label_callback);
ddb5b488
PZ
8973 }
8974
69b07479
DS
8975 /* post-change: re-export vpn routes */
8976 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8977 bgp_get_default(), bgp);
8978
ddb5b488
PZ
8979 return CMD_SUCCESS;
8980}
8981
b9c7bc5a
PZ
8982ALIAS (af_label_vpn_export,
8983 af_no_label_vpn_export_cmd,
8984 "no label vpn export",
8985 NO_STR
8986 "label value for VRF\n"
8987 "Between current address-family and vpn\n"
8988 "For routes leaked from current address-family to vpn\n")
ddb5b488 8989
37a87b8f 8990DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 8991 af_nexthop_vpn_export_cmd,
8c85ca28 8992 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8993 NO_STR
ddb5b488 8994 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8995 "Between current address-family and vpn\n"
8996 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8997 "IPv4 prefix\n"
8998 "IPv6 prefix\n")
8999{
37a87b8f 9000 char base_xpath[XPATH_MAXLEN];
ddb5b488 9001 afi_t afi;
37a87b8f
CS
9002 safi_t safi;
9003 int idx = 0;
ddb5b488
PZ
9004 struct prefix p;
9005
8c85ca28
QY
9006 if (!no) {
9007 if (!nexthop_su) {
9008 vty_out(vty, "%% Nexthop required\n");
9009 return CMD_WARNING_CONFIG_FAILED;
9010 }
8c85ca28 9011 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9012 return CMD_WARNING_CONFIG_FAILED;
9013 }
ddb5b488 9014
37a87b8f
CS
9015 afi = bgp_node_afi(vty);
9016 safi = bgp_node_safi(vty);
ddb5b488 9017
37a87b8f
CS
9018 snprintf(
9019 base_xpath, sizeof(base_xpath),
9020 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9021 yang_afi_safi_value2identity(afi, safi),
9022 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9023
37a87b8f
CS
9024 if (argv_find(argv, argc, "no", &idx))
9025 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9026 else
9027 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9028 nexthop_su_str);
ddb5b488 9029
37a87b8f
CS
9030 return nb_cli_apply_changes(vty, base_xpath);
9031}
69b07479 9032
37a87b8f
CS
9033void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9034 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9035{
9036 int indent = 2;
9037
9038 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9039 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9040}
9041
b9c7bc5a 9042static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9043{
b9c7bc5a
PZ
9044 if (!strcmp(dstr, "import")) {
9045 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9046 } else if (!strcmp(dstr, "export")) {
9047 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9048 } else if (!strcmp(dstr, "both")) {
9049 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9050 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9051 } else {
9052 vty_out(vty, "%% direction parse error\n");
9053 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9054 }
ddb5b488
PZ
9055 return CMD_SUCCESS;
9056}
9057
b9c7bc5a
PZ
9058DEFPY (af_rt_vpn_imexport,
9059 af_rt_vpn_imexport_cmd,
9060 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9061 NO_STR
9062 "Specify route target list\n"
ddb5b488 9063 "Specify route target list\n"
b9c7bc5a
PZ
9064 "Between current address-family and vpn\n"
9065 "For routes leaked from vpn to current address-family: match any\n"
9066 "For routes leaked from current address-family to vpn: set\n"
9067 "both import: match any and export: set\n"
ddb5b488
PZ
9068 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9069{
9070 VTY_DECLVAR_CONTEXT(bgp, bgp);
9071 int ret;
9072 struct ecommunity *ecom = NULL;
9073 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
9074 vpn_policy_direction_t dir;
9075 afi_t afi;
9076 int idx = 0;
c6423c31 9077 bool yes = true;
ddb5b488 9078
b9c7bc5a 9079 if (argv_find(argv, argc, "no", &idx))
c6423c31 9080 yes = false;
b9c7bc5a 9081
0ca70ba5 9082 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9083 if (afi == AFI_MAX)
9084 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9085
b9c7bc5a 9086 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9087 if (ret != CMD_SUCCESS)
9088 return ret;
9089
b9c7bc5a
PZ
9090 if (yes) {
9091 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9092 vty_out(vty, "%% Missing RTLIST\n");
9093 return CMD_WARNING_CONFIG_FAILED;
9094 }
c6423c31 9095 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9096 if (ret != CMD_SUCCESS) {
9097 return ret;
9098 }
ddb5b488
PZ
9099 }
9100
69b07479
DS
9101 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9102 if (!dodir[dir])
ddb5b488 9103 continue;
ddb5b488 9104
69b07479 9105 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9106
69b07479
DS
9107 if (yes) {
9108 if (bgp->vpn_policy[afi].rtlist[dir])
9109 ecommunity_free(
9110 &bgp->vpn_policy[afi].rtlist[dir]);
9111 bgp->vpn_policy[afi].rtlist[dir] =
9112 ecommunity_dup(ecom);
9113 } else {
9114 if (bgp->vpn_policy[afi].rtlist[dir])
9115 ecommunity_free(
9116 &bgp->vpn_policy[afi].rtlist[dir]);
9117 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9118 }
69b07479
DS
9119
9120 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9121 }
69b07479 9122
d555f3e9
PZ
9123 if (ecom)
9124 ecommunity_free(&ecom);
ddb5b488
PZ
9125
9126 return CMD_SUCCESS;
9127}
9128
b9c7bc5a
PZ
9129ALIAS (af_rt_vpn_imexport,
9130 af_no_rt_vpn_imexport_cmd,
9131 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9132 NO_STR
9133 "Specify route target list\n"
b9c7bc5a
PZ
9134 "Specify route target list\n"
9135 "Between current address-family and vpn\n"
9136 "For routes leaked from vpn to current address-family\n"
9137 "For routes leaked from current address-family to vpn\n"
9138 "both import and export\n")
9139
37a87b8f 9140DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9141 af_route_map_vpn_imexport_cmd,
9142/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9143 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9144 NO_STR
ddb5b488 9145 "Specify route map\n"
b9c7bc5a
PZ
9146 "Between current address-family and vpn\n"
9147 "For routes leaked from vpn to current address-family\n"
9148 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9149 "name of route-map\n")
9150{
37a87b8f 9151 char base_xpath[XPATH_MAXLEN];
ddb5b488 9152 afi_t afi;
37a87b8f 9153 safi_t safi;
ddb5b488 9154 int idx = 0;
ddb5b488 9155
37a87b8f
CS
9156 afi = bgp_node_afi(vty);
9157 safi = bgp_node_safi(vty);
ddb5b488 9158
37a87b8f
CS
9159 snprintf(
9160 base_xpath, sizeof(base_xpath),
9161 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9162 yang_afi_safi_value2identity(afi, safi),
9163 bgp_afi_safi_get_container_str(afi, safi));
9164
9165 if (argv_find(argv, argc, "no", &idx)) {
9166 if (!strcmp(direction_str, "import"))
9167 nb_cli_enqueue_change(vty, "./rmap-import",
9168 NB_OP_DESTROY, NULL);
9169 else if (!strcmp(direction_str, "export"))
9170 nb_cli_enqueue_change(vty, "./rmap-export",
9171 NB_OP_DESTROY, NULL);
9172 } else {
9173 if (!strcmp(direction_str, "import"))
9174 nb_cli_enqueue_change(vty, "./rmap-import",
9175 NB_OP_MODIFY, rmap_str);
9176 if (!strcmp(direction_str, "export"))
9177 nb_cli_enqueue_change(vty, "./rmap-export",
9178 NB_OP_MODIFY, rmap_str);
9179 }
9180 return nb_cli_apply_changes(vty, base_xpath);
9181}
ddb5b488 9182
37a87b8f
CS
9183void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9184 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9185{
9186 int indent = 2;
ddb5b488 9187
37a87b8f
CS
9188 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9189 yang_dnode_get_string(dnode, NULL));
9190}
69b07479 9191
37a87b8f
CS
9192void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9193 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9194{
9195 int indent = 2;
ddb5b488 9196
37a87b8f
CS
9197 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9198 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9199}
9200
b9c7bc5a
PZ
9201ALIAS (af_route_map_vpn_imexport,
9202 af_no_route_map_vpn_imexport_cmd,
9203 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9204 NO_STR
9205 "Specify route map\n"
b9c7bc5a
PZ
9206 "Between current address-family and vpn\n"
9207 "For routes leaked from vpn to current address-family\n"
9208 "For routes leaked from current address-family to vpn\n")
9209
bb4f6190 9210DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9211 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9212 "Import routes from another VRF\n"
9213 "Vrf routes being filtered\n"
9214 "Specify route map\n"
9215 "name of route-map\n")
9216{
9217 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
9218 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9219 afi_t afi;
bb4f6190
DS
9220 struct bgp *bgp_default;
9221
0ca70ba5 9222 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9223 if (afi == AFI_MAX)
9224 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9225
9226 bgp_default = bgp_get_default();
9227 if (!bgp_default) {
9228 int32_t ret;
9229 as_t as = bgp->as;
9230
9231 /* Auto-create assuming the same AS */
5d5393b9
DL
9232 ret = bgp_get_vty(&bgp_default, &as, NULL,
9233 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9234
9235 if (ret) {
9236 vty_out(vty,
9237 "VRF default is not configured as a bgp instance\n");
9238 return CMD_WARNING;
9239 }
9240 }
9241
69b07479 9242 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9243
ae6a6fb4
DS
9244 if (bgp->vpn_policy[afi].rmap_name[dir])
9245 XFREE(MTYPE_ROUTE_MAP_NAME,
9246 bgp->vpn_policy[afi].rmap_name[dir]);
9247 bgp->vpn_policy[afi].rmap_name[dir] =
9248 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9249 bgp->vpn_policy[afi].rmap[dir] =
9250 route_map_lookup_warn_noexist(vty, rmap_str);
9251 if (!bgp->vpn_policy[afi].rmap[dir])
9252 return CMD_SUCCESS;
9253
9254 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9255 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9256
69b07479
DS
9257 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9258
bb4f6190
DS
9259 return CMD_SUCCESS;
9260}
9261
ae6a6fb4
DS
9262DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9263 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9264 NO_STR
9265 "Import routes from another VRF\n"
9266 "Vrf routes being filtered\n"
ae6a6fb4
DS
9267 "Specify route map\n"
9268 "name of route-map\n")
9269{
9270 VTY_DECLVAR_CONTEXT(bgp, bgp);
9271 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9272 afi_t afi;
9273
9274 afi = vpn_policy_getafi(vty, bgp, true);
9275 if (afi == AFI_MAX)
9276 return CMD_WARNING_CONFIG_FAILED;
9277
9278 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9279
9280 if (bgp->vpn_policy[afi].rmap_name[dir])
9281 XFREE(MTYPE_ROUTE_MAP_NAME,
9282 bgp->vpn_policy[afi].rmap_name[dir]);
9283 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9284 bgp->vpn_policy[afi].rmap[dir] = NULL;
9285
9286 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9287 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9288 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9289
9290 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9291
9292 return CMD_SUCCESS;
9293}
bb4f6190 9294
37a87b8f
CS
9295DEFPY_YANG(bgp_imexport_vrf,
9296 bgp_imexport_vrf_cmd,
9297 "[no] import vrf VIEWVRFNAME$import_name",
9298 NO_STR
9299 "Import routes from another VRF\n"
9300 "VRF to import from\n"
9301 "The name of the VRF\n")
12a844a5 9302{
37a87b8f 9303 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
9304 safi_t safi;
9305 afi_t afi;
37a87b8f 9306 int32_t idx = 0;
12a844a5 9307
867f0cca 9308 if (import_name == NULL) {
9309 vty_out(vty, "%% Missing import name\n");
9310 return CMD_WARNING;
9311 }
9312
ae6a6fb4
DS
9313 if (strcmp(import_name, "route-map") == 0) {
9314 vty_out(vty, "%% Must include route-map name\n");
9315 return CMD_WARNING;
9316 }
9317
37a87b8f 9318 afi = bgp_node_afi(vty);
12a844a5
DS
9319 safi = bgp_node_safi(vty);
9320
37a87b8f
CS
9321 snprintf(
9322 base_xpath, sizeof(base_xpath),
9323 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9324 yang_afi_safi_value2identity(afi, safi),
9325 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 9326
37a87b8f
CS
9327 if (argv_find(argv, argc, "no", &idx))
9328 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9329 else
9330 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 9331
37a87b8f
CS
9332 return nb_cli_apply_changes(vty, base_xpath);
9333}
12a844a5 9334
37a87b8f
CS
9335void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9336 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9337{
9338 vty_out(vty, " import vrf %s\n",
9339 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
9340}
9341
b9c7bc5a 9342/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 9343DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
9344 bgp_imexport_vpn_cmd,
9345 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9346 NO_STR
9347 "Import routes to this address-family\n"
9348 "Export routes from this address-family\n"
9349 "to/from default instance VPN RIB\n")
ddb5b488 9350{
37a87b8f 9351 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 9352 safi_t safi;
37a87b8f
CS
9353 afi_t afi;
9354 int32_t idx = 0;
ddb5b488 9355
b9c7bc5a
PZ
9356 afi = bgp_node_afi(vty);
9357 safi = bgp_node_safi(vty);
ddb5b488 9358
b9c7bc5a 9359 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
9360 snprintf(
9361 base_xpath, sizeof(base_xpath),
9362 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9363 yang_afi_safi_value2identity(afi, safi),
9364 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 9365 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
9366 snprintf(
9367 base_xpath, sizeof(base_xpath),
9368 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9369 yang_afi_safi_value2identity(afi, safi),
9370 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
9371 } else {
9372 vty_out(vty, "%% unknown direction %s\n", direction_str);
9373 return CMD_WARNING_CONFIG_FAILED;
9374 }
9375
37a87b8f
CS
9376 if (argv_find(argv, argc, "no", &idx))
9377 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9378 else
9379 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 9380
37a87b8f
CS
9381 return nb_cli_apply_changes(vty, base_xpath);
9382}
ddb5b488 9383
37a87b8f
CS
9384void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9385 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9386{
9387 if (yang_dnode_get_bool(dnode, NULL))
9388 vty_out(vty, " import vpn\n");
9389}
9390
9391void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9392 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9393{
9394 if (yang_dnode_get_bool(dnode, NULL))
9395 vty_out(vty, " export vpn\n");
ddb5b488
PZ
9396}
9397
301ad80a
PG
9398DEFPY (af_routetarget_import,
9399 af_routetarget_import_cmd,
9a659715 9400 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9401 NO_STR
9402 "Specify route target list\n"
9403 "Specify route target list\n"
9a659715
PG
9404 "Specify route target list\n"
9405 "Specify route target list\n"
301ad80a
PG
9406 "Flow-spec redirect type route target\n"
9407 "Import routes to this address-family\n"
9a659715 9408 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9409{
9410 VTY_DECLVAR_CONTEXT(bgp, bgp);
9411 int ret;
9412 struct ecommunity *ecom = NULL;
301ad80a 9413 afi_t afi;
9a659715 9414 int idx = 0, idx_unused = 0;
c6423c31
PG
9415 bool yes = true;
9416 bool rt6 = false;
301ad80a
PG
9417
9418 if (argv_find(argv, argc, "no", &idx))
c6423c31 9419 yes = false;
301ad80a 9420
9a659715
PG
9421 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9422 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9423 rt6 = true;
301ad80a 9424
0ca70ba5 9425 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9426 if (afi == AFI_MAX)
9427 return CMD_WARNING_CONFIG_FAILED;
9428
9a659715
PG
9429 if (rt6 && afi != AFI_IP6)
9430 return CMD_WARNING_CONFIG_FAILED;
9431
301ad80a
PG
9432 if (yes) {
9433 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9434 vty_out(vty, "%% Missing RTLIST\n");
9435 return CMD_WARNING_CONFIG_FAILED;
9436 }
9a659715 9437 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9438 if (ret != CMD_SUCCESS)
9439 return ret;
9440 }
69b07479
DS
9441
9442 if (yes) {
9443 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9444 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9445 .import_redirect_rtlist);
69b07479
DS
9446 bgp->vpn_policy[afi].import_redirect_rtlist =
9447 ecommunity_dup(ecom);
9448 } else {
9449 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9450 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9451 .import_redirect_rtlist);
69b07479 9452 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9453 }
69b07479 9454
301ad80a
PG
9455 if (ecom)
9456 ecommunity_free(&ecom);
9457
9458 return CMD_SUCCESS;
9459}
9460
37a87b8f
CS
9461void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9462 struct lyd_node *dnode,
9463 bool show_defaults)
9464{
9465 const char *af_name;
9466 afi_t afi;
9467 safi_t safi;
9468
9469 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9470 yang_afi_safi_identity2value(af_name, &afi, &safi);
9471
9472 vty_out(vty, " !\n address-family ");
9473 if (afi == AFI_IP) {
9474 if (safi == SAFI_UNICAST)
9475 vty_out(vty, "ipv4 unicast");
9476 else if (safi == SAFI_LABELED_UNICAST)
9477 vty_out(vty, "ipv4 labeled-unicast");
9478 else if (safi == SAFI_MULTICAST)
9479 vty_out(vty, "ipv4 multicast");
9480 else if (safi == SAFI_MPLS_VPN)
9481 vty_out(vty, "ipv4 vpn");
9482 else if (safi == SAFI_ENCAP)
9483 vty_out(vty, "ipv4 encap");
9484 else if (safi == SAFI_FLOWSPEC)
9485 vty_out(vty, "ipv4 flowspec");
9486 } else if (afi == AFI_IP6) {
9487 if (safi == SAFI_UNICAST)
9488 vty_out(vty, "ipv6 unicast");
9489 else if (safi == SAFI_LABELED_UNICAST)
9490 vty_out(vty, "ipv6 labeled-unicast");
9491 else if (safi == SAFI_MULTICAST)
9492 vty_out(vty, "ipv6 multicast");
9493 else if (safi == SAFI_MPLS_VPN)
9494 vty_out(vty, "ipv6 vpn");
9495 else if (safi == SAFI_ENCAP)
9496 vty_out(vty, "ipv6 encap");
9497 else if (safi == SAFI_FLOWSPEC)
9498 vty_out(vty, "ipv6 flowspec");
9499 } else if (afi == AFI_L2VPN) {
9500 if (safi == SAFI_EVPN)
9501 vty_out(vty, "l2vpn evpn");
9502 }
9503 vty_out(vty, "\n");
9504}
9505
505e5056 9506DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9507 address_family_ipv4_safi_cmd,
9508 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9509 "Enter Address Family command mode\n"
9510 "Address Family\n"
9511 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9512{
f51bae9c 9513
37a87b8f
CS
9514 safi_t safi = SAFI_UNICAST;
9515 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9516 const char *vrf_name = NULL;
9517
d62a17ae 9518 if (argc == 3) {
37a87b8f
CS
9519 safi = bgp_vty_safi_from_str(argv[2]->text);
9520
9521 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9522 VTY_CURR_XPATH);
9523 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9524 "control-plane-protocol");
9525 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9526
9527 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9528 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9529 && safi != SAFI_EVPN) {
31947174
MK
9530 vty_out(vty,
9531 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9532 return CMD_WARNING_CONFIG_FAILED;
9533 }
37a87b8f
CS
9534 }
9535 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 9536
d62a17ae 9537 return CMD_SUCCESS;
718e3744 9538}
9539
505e5056 9540DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9541 address_family_ipv6_safi_cmd,
9542 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9543 "Enter Address Family command mode\n"
9544 "Address Family\n"
9545 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9546{
37a87b8f
CS
9547 safi_t safi = SAFI_UNICAST;
9548 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9549 const char *vrf_name = NULL;
9550
d62a17ae 9551 if (argc == 3) {
37a87b8f
CS
9552 safi = bgp_vty_safi_from_str(argv[2]->text);
9553 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9554 VTY_CURR_XPATH);
9555 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9556 "control-plane-protocol");
9557 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9558
9559 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9560 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9561 && safi != SAFI_EVPN) {
31947174
MK
9562 vty_out(vty,
9563 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9564 return CMD_WARNING_CONFIG_FAILED;
9565 }
37a87b8f
CS
9566 }
9567 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 9568
d62a17ae 9569 return CMD_SUCCESS;
25ffbdc1 9570}
718e3744 9571
d6902373 9572#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9573DEFUN_NOSH (address_family_vpnv4,
718e3744 9574 address_family_vpnv4_cmd,
8334fd5a 9575 "address-family vpnv4 [unicast]",
718e3744 9576 "Enter Address Family command mode\n"
8c3deaae 9577 "Address Family\n"
3a2d747c 9578 "Address Family modifier\n")
718e3744 9579{
d62a17ae 9580 vty->node = BGP_VPNV4_NODE;
9581 return CMD_SUCCESS;
718e3744 9582}
9583
505e5056 9584DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9585 address_family_vpnv6_cmd,
8334fd5a 9586 "address-family vpnv6 [unicast]",
8ecd3266 9587 "Enter Address Family command mode\n"
8c3deaae 9588 "Address Family\n"
3a2d747c 9589 "Address Family modifier\n")
8ecd3266 9590{
d62a17ae 9591 vty->node = BGP_VPNV6_NODE;
9592 return CMD_SUCCESS;
8ecd3266 9593}
64e4a6c5 9594#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9595
505e5056 9596DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9597 address_family_evpn_cmd,
7111c1a0 9598 "address-family l2vpn evpn",
4e0b7b6d 9599 "Enter Address Family command mode\n"
7111c1a0
QY
9600 "Address Family\n"
9601 "Address Family modifier\n")
4e0b7b6d 9602{
2131d5cf 9603 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9604 vty->node = BGP_EVPN_NODE;
9605 return CMD_SUCCESS;
4e0b7b6d
PG
9606}
9607
505e5056 9608DEFUN_NOSH (exit_address_family,
718e3744 9609 exit_address_family_cmd,
9610 "exit-address-family",
9611 "Exit from Address Family configuration mode\n")
9612{
d62a17ae 9613 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9614 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9615 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9616 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9617 || vty->node == BGP_EVPN_NODE
9618 || vty->node == BGP_FLOWSPECV4_NODE
9619 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9620 vty->node = BGP_NODE;
9621 return CMD_SUCCESS;
718e3744 9622}
6b0655a2 9623
37a87b8f
CS
9624void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9625 struct lyd_node *dnode
9626 __attribute__((__unused__)))
9627{
9628 vty_out(vty, " exit-address-family\n");
9629}
9630
8ad7271d 9631/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9632static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9633 const char *ip_str, afi_t afi, safi_t safi,
9634 struct prefix_rd *prd)
9635{
9636 int ret;
9637 struct prefix match;
9bcb3eef
DS
9638 struct bgp_dest *dest;
9639 struct bgp_dest *rm;
d62a17ae 9640 struct bgp *bgp;
9641 struct bgp_table *table;
9642 struct bgp_table *rib;
9643
9644 /* BGP structure lookup. */
9645 if (view_name) {
9646 bgp = bgp_lookup_by_name(view_name);
9647 if (bgp == NULL) {
9648 vty_out(vty, "%% Can't find BGP instance %s\n",
9649 view_name);
9650 return CMD_WARNING;
9651 }
9652 } else {
9653 bgp = bgp_get_default();
9654 if (bgp == NULL) {
9655 vty_out(vty, "%% No BGP process is configured\n");
9656 return CMD_WARNING;
9657 }
9658 }
9659
9660 /* Check IP address argument. */
9661 ret = str2prefix(ip_str, &match);
9662 if (!ret) {
9663 vty_out(vty, "%% address is malformed\n");
9664 return CMD_WARNING;
9665 }
9666
9667 match.family = afi2family(afi);
9668 rib = bgp->rib[afi][safi];
9669
9670 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9671 for (dest = bgp_table_top(rib); dest;
9672 dest = bgp_route_next(dest)) {
9673 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9674
9bcb3eef 9675 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9676 continue;
9677
9bcb3eef 9678 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9679 if (table == NULL)
9680 continue;
9681
9682 if ((rm = bgp_node_match(table, &match)) != NULL) {
9683 const struct prefix *rm_p =
9bcb3eef 9684 bgp_dest_get_prefix(rm);
b54892e0
DS
9685
9686 if (rm_p->prefixlen == match.prefixlen) {
9687 SET_FLAG(rm->flags,
9688 BGP_NODE_USER_CLEAR);
9689 bgp_process(bgp, rm, afi, safi);
d62a17ae 9690 }
9bcb3eef 9691 bgp_dest_unlock_node(rm);
d62a17ae 9692 }
9693 }
9694 } else {
9bcb3eef
DS
9695 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9696 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9697
9bcb3eef
DS
9698 if (dest_p->prefixlen == match.prefixlen) {
9699 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9700 bgp_process(bgp, dest, afi, safi);
d62a17ae 9701 }
9bcb3eef 9702 bgp_dest_unlock_node(dest);
d62a17ae 9703 }
9704 }
9705
9706 return CMD_SUCCESS;
8ad7271d
DS
9707}
9708
b09b5ae0 9709/* one clear bgp command to rule them all */
718e3744 9710DEFUN (clear_ip_bgp_all,
9711 clear_ip_bgp_all_cmd,
453c92f6 9712 "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 9713 CLEAR_STR
9714 IP_STR
9715 BGP_STR
838758ac 9716 BGP_INSTANCE_HELP_STR
510afcd6 9717 BGP_AFI_HELP_STR
fd5e7b70 9718 "Address Family\n"
510afcd6 9719 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9720 "Address Family modifier\n"
b09b5ae0 9721 "Clear all peers\n"
453c92f6 9722 "BGP IPv4 neighbor to clear\n"
a80beece 9723 "BGP IPv6 neighbor to clear\n"
838758ac 9724 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9725 "Clear peers with the AS number\n"
9726 "Clear all external peers\n"
718e3744 9727 "Clear all members of peer-group\n"
b09b5ae0 9728 "BGP peer-group name\n"
b09b5ae0
DW
9729 BGP_SOFT_STR
9730 BGP_SOFT_IN_STR
b09b5ae0
DW
9731 BGP_SOFT_OUT_STR
9732 BGP_SOFT_IN_STR
9733 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9734 BGP_SOFT_OUT_STR)
718e3744 9735{
d62a17ae 9736 char *vrf = NULL;
9737
dc912615
DS
9738 afi_t afi = AFI_UNSPEC;
9739 safi_t safi = SAFI_UNSPEC;
d62a17ae 9740 enum clear_sort clr_sort = clear_peer;
9741 enum bgp_clear_type clr_type;
9742 char *clr_arg = NULL;
9743
9744 int idx = 0;
ff8a8a7a
CS
9745 char errmsg[BUFSIZ] = {'\0'};
9746 int ret;
d62a17ae 9747
9748 /* clear [ip] bgp */
9749 if (argv_find(argv, argc, "ip", &idx))
9750 afi = AFI_IP;
9751
9a8bdf1c
PG
9752 /* [<vrf> VIEWVRFNAME] */
9753 if (argv_find(argv, argc, "vrf", &idx)) {
9754 vrf = argv[idx + 1]->arg;
9755 idx += 2;
9756 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9757 vrf = NULL;
9758 } else if (argv_find(argv, argc, "view", &idx)) {
9759 /* [<view> VIEWVRFNAME] */
d62a17ae 9760 vrf = argv[idx + 1]->arg;
9761 idx += 2;
9762 }
d62a17ae 9763 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9764 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9765 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9766
d7b9898c 9767 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9768 if (argv_find(argv, argc, "*", &idx)) {
9769 clr_sort = clear_all;
9770 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9771 clr_sort = clear_peer;
9772 clr_arg = argv[idx]->arg;
9773 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9774 clr_sort = clear_peer;
9775 clr_arg = argv[idx]->arg;
9776 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9777 clr_sort = clear_group;
9778 idx++;
9779 clr_arg = argv[idx]->arg;
d7b9898c 9780 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9781 clr_sort = clear_peer;
9782 clr_arg = argv[idx]->arg;
8fa7d444
DS
9783 } else if (argv_find(argv, argc, "WORD", &idx)) {
9784 clr_sort = clear_peer;
9785 clr_arg = argv[idx]->arg;
d62a17ae 9786 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9787 clr_sort = clear_as;
9788 clr_arg = argv[idx]->arg;
9789 } else if (argv_find(argv, argc, "external", &idx)) {
9790 clr_sort = clear_external;
9791 }
9792
9793 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9794 if (argv_find(argv, argc, "soft", &idx)) {
9795 if (argv_find(argv, argc, "in", &idx)
9796 || argv_find(argv, argc, "out", &idx))
9797 clr_type = strmatch(argv[idx]->text, "in")
9798 ? BGP_CLEAR_SOFT_IN
9799 : BGP_CLEAR_SOFT_OUT;
9800 else
9801 clr_type = BGP_CLEAR_SOFT_BOTH;
9802 } else if (argv_find(argv, argc, "in", &idx)) {
9803 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9804 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9805 : BGP_CLEAR_SOFT_IN;
9806 } else if (argv_find(argv, argc, "out", &idx)) {
9807 clr_type = BGP_CLEAR_SOFT_OUT;
9808 } else
9809 clr_type = BGP_CLEAR_SOFT_NONE;
9810
ff8a8a7a
CS
9811 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9812 sizeof(errmsg));
9813 if (ret != NB_OK)
9814 vty_out(vty, "Error description: %s\n", errmsg);
9815
9816 return ret;
838758ac 9817}
01080f7c 9818
8ad7271d
DS
9819DEFUN (clear_ip_bgp_prefix,
9820 clear_ip_bgp_prefix_cmd,
18c57037 9821 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9822 CLEAR_STR
9823 IP_STR
9824 BGP_STR
838758ac 9825 BGP_INSTANCE_HELP_STR
8ad7271d 9826 "Clear bestpath and re-advertise\n"
0c7b1b01 9827 "IPv4 prefix\n")
8ad7271d 9828{
d62a17ae 9829 char *vrf = NULL;
9830 char *prefix = NULL;
8ad7271d 9831
d62a17ae 9832 int idx = 0;
01080f7c 9833
d62a17ae 9834 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9835 if (argv_find(argv, argc, "vrf", &idx)) {
9836 vrf = argv[idx + 1]->arg;
9837 idx += 2;
9838 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9839 vrf = NULL;
9840 } else if (argv_find(argv, argc, "view", &idx)) {
9841 /* [<view> VIEWVRFNAME] */
9842 vrf = argv[idx + 1]->arg;
9843 idx += 2;
9844 }
0c7b1b01 9845
d62a17ae 9846 prefix = argv[argc - 1]->arg;
8ad7271d 9847
d62a17ae 9848 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9849}
8ad7271d 9850
b09b5ae0
DW
9851DEFUN (clear_bgp_ipv6_safi_prefix,
9852 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9853 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9854 CLEAR_STR
3a2d747c 9855 IP_STR
718e3744 9856 BGP_STR
8c3deaae 9857 "Address Family\n"
46f296b4 9858 BGP_SAFI_HELP_STR
b09b5ae0 9859 "Clear bestpath and re-advertise\n"
0c7b1b01 9860 "IPv6 prefix\n")
718e3744 9861{
9b475e76
PG
9862 int idx_safi = 0;
9863 int idx_ipv6_prefix = 0;
9864 safi_t safi = SAFI_UNICAST;
9865 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9866 argv[idx_ipv6_prefix]->arg : NULL;
9867
9868 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9869 return bgp_clear_prefix(
9b475e76
PG
9870 vty, NULL, prefix, AFI_IP6,
9871 safi, NULL);
838758ac 9872}
01080f7c 9873
b09b5ae0
DW
9874DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9875 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9876 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9877 CLEAR_STR
3a2d747c 9878 IP_STR
718e3744 9879 BGP_STR
838758ac 9880 BGP_INSTANCE_HELP_STR
8c3deaae 9881 "Address Family\n"
46f296b4 9882 BGP_SAFI_HELP_STR
b09b5ae0 9883 "Clear bestpath and re-advertise\n"
0c7b1b01 9884 "IPv6 prefix\n")
718e3744 9885{
9b475e76 9886 int idx_safi = 0;
9a8bdf1c 9887 int idx_vrfview = 0;
9b475e76
PG
9888 int idx_ipv6_prefix = 0;
9889 safi_t safi = SAFI_UNICAST;
9890 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9891 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9892 char *vrfview = NULL;
9b475e76 9893
9a8bdf1c
PG
9894 /* [<view|vrf> VIEWVRFNAME] */
9895 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9896 vrfview = argv[idx_vrfview + 1]->arg;
9897 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9898 vrfview = NULL;
9899 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9900 /* [<view> VIEWVRFNAME] */
9901 vrfview = argv[idx_vrfview + 1]->arg;
9902 }
9b475e76
PG
9903 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9904
d62a17ae 9905 return bgp_clear_prefix(
9b475e76
PG
9906 vty, vrfview, prefix,
9907 AFI_IP6, safi, NULL);
718e3744 9908}
9909
b09b5ae0
DW
9910DEFUN (show_bgp_views,
9911 show_bgp_views_cmd,
d6e3c605 9912 "show [ip] bgp views",
b09b5ae0 9913 SHOW_STR
d6e3c605 9914 IP_STR
01080f7c 9915 BGP_STR
b09b5ae0 9916 "Show the defined BGP views\n")
01080f7c 9917{
d62a17ae 9918 struct list *inst = bm->bgp;
9919 struct listnode *node;
9920 struct bgp *bgp;
01080f7c 9921
d62a17ae 9922 vty_out(vty, "Defined BGP views:\n");
9923 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9924 /* Skip VRFs. */
9925 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9926 continue;
9927 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9928 bgp->as);
9929 }
e52702f2 9930
d62a17ae 9931 return CMD_SUCCESS;
e0081f70
ML
9932}
9933
8386ac43 9934DEFUN (show_bgp_vrfs,
9935 show_bgp_vrfs_cmd,
d6e3c605 9936 "show [ip] bgp vrfs [json]",
8386ac43 9937 SHOW_STR
d6e3c605 9938 IP_STR
8386ac43 9939 BGP_STR
9940 "Show BGP VRFs\n"
9973d184 9941 JSON_STR)
8386ac43 9942{
fe1dc5a3 9943 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9944 struct list *inst = bm->bgp;
9945 struct listnode *node;
9946 struct bgp *bgp;
9f049418 9947 bool uj = use_json(argc, argv);
d62a17ae 9948 json_object *json = NULL;
9949 json_object *json_vrfs = NULL;
9950 int count = 0;
d62a17ae 9951
d62a17ae 9952 if (uj) {
9953 json = json_object_new_object();
9954 json_vrfs = json_object_new_object();
9955 }
9956
9957 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9958 const char *name, *type;
9959 struct peer *peer;
7fe96307 9960 struct listnode *node2, *nnode2;
d62a17ae 9961 int peers_cfg, peers_estb;
9962 json_object *json_vrf = NULL;
d62a17ae 9963
9964 /* Skip Views. */
9965 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9966 continue;
9967
9968 count++;
efb4077a 9969 if (!uj && count == 1) {
fe1dc5a3 9970 vty_out(vty,
efb4077a 9971 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9972 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9973 "#PeersEstb", "Name");
9974 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9975 "L3-VNI", "RouterMAC", "Interface");
9976 }
d62a17ae 9977
9978 peers_cfg = peers_estb = 0;
9979 if (uj)
9980 json_vrf = json_object_new_object();
9981
9982
7fe96307 9983 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9984 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9985 continue;
9986 peers_cfg++;
9987 if (peer->status == Established)
9988 peers_estb++;
9989 }
9990
9991 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9992 name = VRF_DEFAULT_NAME;
d62a17ae 9993 type = "DFLT";
9994 } else {
9995 name = bgp->name;
9996 type = "VRF";
9997 }
9998
a8bf7d9c 9999
d62a17ae 10000 if (uj) {
a4d82a8a
PZ
10001 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10002 ? -1
10003 : (int64_t)bgp->vrf_id;
23d0a753
DA
10004 char buf[BUFSIZ] = {0};
10005
d62a17ae 10006 json_object_string_add(json_vrf, "type", type);
10007 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10008 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
10009 inet_ntop(AF_INET,
10010 &bgp->router_id, buf,
10011 sizeof(buf)));
d62a17ae 10012 json_object_int_add(json_vrf, "numConfiguredPeers",
10013 peers_cfg);
10014 json_object_int_add(json_vrf, "numEstablishedPeers",
10015 peers_estb);
10016
fe1dc5a3 10017 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10018 json_object_string_add(
10019 json_vrf, "rmac",
10020 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10021 json_object_string_add(json_vrf, "interface",
10022 ifindex2ifname(bgp->l3vni_svi_ifindex,
10023 bgp->vrf_id));
d62a17ae 10024 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10025 } else {
23d0a753 10026 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10027 type,
10028 bgp->vrf_id == VRF_UNKNOWN ? -1
10029 : (int)bgp->vrf_id,
23d0a753 10030 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10031 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10032 bgp->l3vni,
10033 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10034 ifindex2ifname(bgp->l3vni_svi_ifindex,
10035 bgp->vrf_id));
10036 }
d62a17ae 10037 }
10038
10039 if (uj) {
10040 json_object_object_add(json, "vrfs", json_vrfs);
10041
10042 json_object_int_add(json, "totalVrfs", count);
10043
996c9314
LB
10044 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10045 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10046 json_object_free(json);
10047 } else {
10048 if (count)
10049 vty_out(vty,
10050 "\nTotal number of VRFs (including default): %d\n",
10051 count);
10052 }
10053
10054 return CMD_SUCCESS;
8386ac43 10055}
10056
48ecf8f5
DS
10057DEFUN (show_bgp_mac_hash,
10058 show_bgp_mac_hash_cmd,
10059 "show bgp mac hash",
10060 SHOW_STR
10061 BGP_STR
10062 "Mac Address\n"
10063 "Mac Address database\n")
10064{
10065 bgp_mac_dump_table(vty);
10066
10067 return CMD_SUCCESS;
10068}
acf71666 10069
e3b78da8 10070static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10071{
0291c246 10072 struct vty *vty = (struct vty *)args;
e3b78da8 10073 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10074
23d0a753 10075 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10076}
10077
10078static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10079{
10080 vty_out(vty, "self nexthop database:\n");
af97a18b 10081 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10082
10083 vty_out(vty, "Tunnel-ip database:\n");
10084 hash_iterate(bgp->tip_hash,
e3b78da8 10085 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10086 vty);
10087}
10088
15c81ca4
DS
10089DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10090 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10091 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10092 "martian next-hops\n"
10093 "martian next-hop database\n")
acf71666 10094{
0291c246 10095 struct bgp *bgp = NULL;
15c81ca4 10096 int idx = 0;
9a8bdf1c
PG
10097 char *name = NULL;
10098
10099 /* [<vrf> VIEWVRFNAME] */
10100 if (argv_find(argv, argc, "vrf", &idx)) {
10101 name = argv[idx + 1]->arg;
10102 if (name && strmatch(name, VRF_DEFAULT_NAME))
10103 name = NULL;
10104 } else if (argv_find(argv, argc, "view", &idx))
10105 /* [<view> VIEWVRFNAME] */
10106 name = argv[idx + 1]->arg;
10107 if (name)
10108 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10109 else
10110 bgp = bgp_get_default();
acf71666 10111
acf71666
MK
10112 if (!bgp) {
10113 vty_out(vty, "%% No BGP process is configured\n");
10114 return CMD_WARNING;
10115 }
10116 bgp_show_martian_nexthops(vty, bgp);
10117
10118 return CMD_SUCCESS;
10119}
10120
f412b39a 10121DEFUN (show_bgp_memory,
4bf6a362 10122 show_bgp_memory_cmd,
7fa12b13 10123 "show [ip] bgp memory",
4bf6a362 10124 SHOW_STR
3a2d747c 10125 IP_STR
4bf6a362
PJ
10126 BGP_STR
10127 "Global BGP memory statistics\n")
10128{
d62a17ae 10129 char memstrbuf[MTYPE_MEMSTR_LEN];
10130 unsigned long count;
10131
10132 /* RIB related usage stats */
10133 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10134 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10135 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10136 count * sizeof(struct bgp_dest)));
d62a17ae 10137
10138 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10139 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10140 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10141 count * sizeof(struct bgp_path_info)));
d62a17ae 10142 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10143 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10144 count,
4b7e6066
DS
10145 mtype_memstr(
10146 memstrbuf, sizeof(memstrbuf),
10147 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10148
10149 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10150 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10151 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10152 count * sizeof(struct bgp_static)));
10153
10154 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10155 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10156 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10157 count * sizeof(struct bpacket)));
10158
10159 /* Adj-In/Out */
10160 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10161 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10162 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10163 count * sizeof(struct bgp_adj_in)));
10164 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10165 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10166 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10167 count * sizeof(struct bgp_adj_out)));
10168
10169 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10170 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10171 count,
10172 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10173 count * sizeof(struct bgp_nexthop_cache)));
10174
10175 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10176 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10177 count,
10178 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10179 count * sizeof(struct bgp_damp_info)));
10180
10181 /* Attributes */
10182 count = attr_count();
10183 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10184 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10185 count * sizeof(struct attr)));
10186
10187 if ((count = attr_unknown_count()))
10188 vty_out(vty, "%ld unknown attributes\n", count);
10189
10190 /* AS_PATH attributes */
10191 count = aspath_count();
10192 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10193 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10194 count * sizeof(struct aspath)));
10195
10196 count = mtype_stats_alloc(MTYPE_AS_SEG);
10197 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10198 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10199 count * sizeof(struct assegment)));
10200
10201 /* Other attributes */
10202 if ((count = community_count()))
10203 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10204 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10205 count * sizeof(struct community)));
d62a17ae 10206 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10207 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10208 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10209 count * sizeof(struct ecommunity)));
d62a17ae 10210 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10211 vty_out(vty,
10212 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10213 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10214 count * sizeof(struct lcommunity)));
d62a17ae 10215
10216 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10217 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10218 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10219 count * sizeof(struct cluster_list)));
10220
10221 /* Peer related usage */
10222 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10223 vty_out(vty, "%ld peers, using %s of memory\n", count,
10224 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10225 count * sizeof(struct peer)));
10226
10227 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10228 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10229 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10230 count * sizeof(struct peer_group)));
10231
10232 /* Other */
d62a17ae 10233 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10234 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10235 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10236 count * sizeof(regex_t)));
d62a17ae 10237 return CMD_SUCCESS;
4bf6a362 10238}
fee0f4c6 10239
57a9c8a8
DS
10240static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10241{
10242 json_object *bestpath = json_object_new_object();
10243
892fedb6 10244 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10245 json_object_string_add(bestpath, "asPath", "ignore");
10246
892fedb6 10247 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10248 json_object_string_add(bestpath, "asPath", "confed");
10249
892fedb6
DA
10250 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10251 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10252 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10253 "as-set");
10254 else
a4d82a8a 10255 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10256 "true");
10257 } else
a4d82a8a 10258 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10259
892fedb6 10260 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10261 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10262 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10263 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10264 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10265 json_object_string_add(bestpath, "med", "confed");
892fedb6 10266 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10267 json_object_string_add(bestpath, "med",
10268 "missing-as-worst");
10269 else
10270 json_object_string_add(bestpath, "med", "true");
10271 }
10272
10273 json_object_object_add(json, "bestPath", bestpath);
10274}
10275
3577f1c5
DD
10276/* Print the error code/subcode for why the peer is down */
10277static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10278 json_object *json_peer, bool use_json)
10279{
10280 const char *code_str;
10281 const char *subcode_str;
10282
10283 if (use_json) {
10284 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10285 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10286 char errorcodesubcode_hexstr[5];
10287 char errorcodesubcode_str[256];
10288
10289 code_str = bgp_notify_code_str(peer->notify.code);
10290 subcode_str = bgp_notify_subcode_str(
10291 peer->notify.code,
10292 peer->notify.subcode);
10293
772270f3
QY
10294 snprintf(errorcodesubcode_hexstr,
10295 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10296 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10297 json_object_string_add(json_peer,
10298 "lastErrorCodeSubcode",
10299 errorcodesubcode_hexstr);
10300 snprintf(errorcodesubcode_str, 255, "%s%s",
10301 code_str, subcode_str);
10302 json_object_string_add(json_peer,
10303 "lastNotificationReason",
10304 errorcodesubcode_str);
10305 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10306 && peer->notify.code == BGP_NOTIFY_CEASE
10307 && (peer->notify.subcode
10308 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10309 || peer->notify.subcode
10310 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10311 && peer->notify.length) {
10312 char msgbuf[1024];
10313 const char *msg_str;
10314
10315 msg_str = bgp_notify_admin_message(
10316 msgbuf, sizeof(msgbuf),
10317 (uint8_t *)peer->notify.data,
10318 peer->notify.length);
10319 if (msg_str)
10320 json_object_string_add(
10321 json_peer,
10322 "lastShutdownDescription",
10323 msg_str);
10324 }
10325
c258527b 10326 }
3577f1c5
DD
10327 json_object_string_add(json_peer, "lastResetDueTo",
10328 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10329 json_object_int_add(json_peer, "lastResetCode",
10330 peer->last_reset);
3577f1c5
DD
10331 } else {
10332 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10333 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10334 code_str = bgp_notify_code_str(peer->notify.code);
10335 subcode_str =
10336 bgp_notify_subcode_str(peer->notify.code,
10337 peer->notify.subcode);
10338 vty_out(vty, " Notification %s (%s%s)\n",
10339 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10340 ? "sent"
10341 : "received",
10342 code_str, subcode_str);
10343 } else {
e91c24c8 10344 vty_out(vty, " %s\n",
3577f1c5
DD
10345 peer_down_str[(int)peer->last_reset]);
10346 }
10347 }
10348}
10349
10350static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10351 safi_t safi)
10352{
10353 return ((peer->status != Established) ||
10354 !peer->afc_recv[afi][safi]);
10355}
10356
10357static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10358 struct peer *peer, json_object *json_peer,
10359 int max_neighbor_width, bool use_json)
10360{
10361 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10362 int len;
10363
10364 if (use_json) {
10365 if (peer_dynamic_neighbor(peer))
10366 json_object_boolean_true_add(json_peer,
10367 "dynamicPeer");
10368 if (peer->hostname)
10369 json_object_string_add(json_peer, "hostname",
10370 peer->hostname);
10371
10372 if (peer->domainname)
10373 json_object_string_add(json_peer, "domainname",
10374 peer->domainname);
10375 json_object_int_add(json_peer, "connectionsEstablished",
10376 peer->established);
10377 json_object_int_add(json_peer, "connectionsDropped",
10378 peer->dropped);
10379 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10380 use_json, json_peer);
10381 if (peer->status == Established)
10382 json_object_string_add(json_peer, "lastResetDueTo",
10383 "AFI/SAFI Not Negotiated");
10384 else
10385 bgp_show_peer_reset(NULL, peer, json_peer, true);
10386 } else {
10387 dn_flag[1] = '\0';
10388 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10389 if (peer->hostname
892fedb6 10390 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10391 len = vty_out(vty, "%s%s(%s)", dn_flag,
10392 peer->hostname, peer->host);
10393 else
10394 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10395
10396 /* pad the neighbor column with spaces */
10397 if (len < max_neighbor_width)
10398 vty_out(vty, "%*s", max_neighbor_width - len,
10399 " ");
e91c24c8 10400 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10401 peer->dropped,
10402 peer_uptime(peer->uptime, timebuf,
10403 BGP_UPTIME_LEN, 0, NULL));
10404 if (peer->status == Established)
10405 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10406 else
10407 bgp_show_peer_reset(vty, peer, NULL,
10408 false);
10409 }
10410}
c258527b 10411
3577f1c5 10412
718e3744 10413/* Show BGP peer's summary information. */
d62a17ae 10414static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10b49f14
DA
10415 bool show_failed, bool show_established,
10416 bool use_json)
d62a17ae 10417{
10418 struct peer *peer;
10419 struct listnode *node, *nnode;
10420 unsigned int count = 0, dn_count = 0;
10421 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10422 char neighbor_buf[VTY_BUFSIZ];
10423 int neighbor_col_default_width = 16;
3577f1c5 10424 int len, failed_count = 0;
d62a17ae 10425 int max_neighbor_width = 0;
10426 int pfx_rcd_safi;
3c13337d 10427 json_object *json = NULL;
d62a17ae 10428 json_object *json_peer = NULL;
10429 json_object *json_peers = NULL;
50e05855 10430 struct peer_af *paf;
d3ada366 10431 struct bgp_filter *filter;
d62a17ae 10432
10433 /* labeled-unicast routes are installed in the unicast table so in order
10434 * to
10435 * display the correct PfxRcd value we must look at SAFI_UNICAST
10436 */
3577f1c5 10437
d62a17ae 10438 if (safi == SAFI_LABELED_UNICAST)
10439 pfx_rcd_safi = SAFI_UNICAST;
10440 else
10441 pfx_rcd_safi = safi;
10442
10443 if (use_json) {
3c13337d 10444 json = json_object_new_object();
d62a17ae 10445 json_peers = json_object_new_object();
3577f1c5
DD
10446 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10447 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10448 continue;
10449
10450 if (peer->afc[afi][safi]) {
10451 /* See if we have at least a single failed peer */
10452 if (bgp_has_peer_failed(peer, afi, safi))
10453 failed_count++;
10454 count++;
10455 }
10456 if (peer_dynamic_neighbor(peer))
10457 dn_count++;
10458 }
c258527b 10459
d62a17ae 10460 } else {
10461 /* Loop over all neighbors that will be displayed to determine
10462 * how many
10463 * characters are needed for the Neighbor column
10464 */
10465 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10466 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10467 continue;
10468
10469 if (peer->afc[afi][safi]) {
10470 memset(dn_flag, '\0', sizeof(dn_flag));
10471 if (peer_dynamic_neighbor(peer))
10472 dn_flag[0] = '*';
10473
10474 if (peer->hostname
892fedb6
DA
10475 && CHECK_FLAG(bgp->flags,
10476 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10477 snprintf(neighbor_buf,
10478 sizeof(neighbor_buf),
10479 "%s%s(%s) ", dn_flag,
10480 peer->hostname, peer->host);
d62a17ae 10481 else
772270f3
QY
10482 snprintf(neighbor_buf,
10483 sizeof(neighbor_buf), "%s%s ",
10484 dn_flag, peer->host);
d62a17ae 10485
10486 len = strlen(neighbor_buf);
10487
10488 if (len > max_neighbor_width)
10489 max_neighbor_width = len;
c258527b 10490
3577f1c5
DD
10491 /* See if we have at least a single failed peer */
10492 if (bgp_has_peer_failed(peer, afi, safi))
10493 failed_count++;
10494 count++;
d62a17ae 10495 }
10496 }
f933309e 10497
d62a17ae 10498 /* Originally we displayed the Neighbor column as 16
10499 * characters wide so make that the default
10500 */
10501 if (max_neighbor_width < neighbor_col_default_width)
10502 max_neighbor_width = neighbor_col_default_width;
10503 }
f933309e 10504
3577f1c5
DD
10505 if (show_failed && !failed_count) {
10506 if (use_json) {
10507 json_object_int_add(json, "failedPeersCount", 0);
10508 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10509 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
10510
10511 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10512 json, JSON_C_TO_STRING_PRETTY));
10513 json_object_free(json);
10514 } else {
10515 vty_out(vty, "%% No failed BGP neighbors found\n");
10516 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10517 }
10518 return CMD_SUCCESS;
10519 }
c258527b 10520
3577f1c5 10521 count = 0; /* Reset the value as its used again */
d62a17ae 10522 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10523 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10524 continue;
10525
ea47320b
DL
10526 if (!peer->afc[afi][safi])
10527 continue;
d62a17ae 10528
ea47320b
DL
10529 if (!count) {
10530 unsigned long ents;
10531 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10532 int64_t vrf_id_ui;
d62a17ae 10533
a4d82a8a
PZ
10534 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10535 ? -1
10536 : (int64_t)bgp->vrf_id;
ea47320b
DL
10537
10538 /* Usage summary and header */
10539 if (use_json) {
23d0a753
DA
10540 char buf[BUFSIZ] = {0};
10541
ea47320b
DL
10542 json_object_string_add(
10543 json, "routerId",
23d0a753
DA
10544 inet_ntop(AF_INET, &bgp->router_id, buf,
10545 sizeof(buf)));
60466a63
QY
10546 json_object_int_add(json, "as", bgp->as);
10547 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10548 json_object_string_add(
10549 json, "vrfName",
10550 (bgp->inst_type
10551 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10552 ? VRF_DEFAULT_NAME
ea47320b
DL
10553 : bgp->name);
10554 } else {
10555 vty_out(vty,
23d0a753
DA
10556 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10557 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10558 bgp->vrf_id == VRF_UNKNOWN
10559 ? -1
10560 : (int)bgp->vrf_id);
ea47320b
DL
10561 vty_out(vty, "\n");
10562 }
d62a17ae 10563
ea47320b 10564 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10565 if (use_json) {
ea47320b 10566 json_object_int_add(
60466a63 10567 json, "updateDelayLimit",
ea47320b 10568 bgp->v_update_delay);
d62a17ae 10569
ea47320b
DL
10570 if (bgp->v_update_delay
10571 != bgp->v_establish_wait)
d62a17ae 10572 json_object_int_add(
10573 json,
ea47320b
DL
10574 "updateDelayEstablishWait",
10575 bgp->v_establish_wait);
d62a17ae 10576
60466a63 10577 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10578 json_object_string_add(
10579 json,
10580 "updateDelayFirstNeighbor",
10581 bgp->update_delay_begin_time);
10582 json_object_boolean_true_add(
10583 json,
10584 "updateDelayInProgress");
10585 } else {
10586 if (bgp->update_delay_over) {
d62a17ae 10587 json_object_string_add(
10588 json,
10589 "updateDelayFirstNeighbor",
10590 bgp->update_delay_begin_time);
ea47320b 10591 json_object_string_add(
d62a17ae 10592 json,
ea47320b
DL
10593 "updateDelayBestpathResumed",
10594 bgp->update_delay_end_time);
10595 json_object_string_add(
d62a17ae 10596 json,
ea47320b
DL
10597 "updateDelayZebraUpdateResume",
10598 bgp->update_delay_zebra_resume_time);
10599 json_object_string_add(
10600 json,
10601 "updateDelayPeerUpdateResume",
10602 bgp->update_delay_peers_resume_time);
d62a17ae 10603 }
ea47320b
DL
10604 }
10605 } else {
10606 vty_out(vty,
10607 "Read-only mode update-delay limit: %d seconds\n",
10608 bgp->v_update_delay);
10609 if (bgp->v_update_delay
10610 != bgp->v_establish_wait)
d62a17ae 10611 vty_out(vty,
ea47320b
DL
10612 " Establish wait: %d seconds\n",
10613 bgp->v_establish_wait);
d62a17ae 10614
60466a63 10615 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10616 vty_out(vty,
10617 " First neighbor established: %s\n",
10618 bgp->update_delay_begin_time);
10619 vty_out(vty,
10620 " Delay in progress\n");
10621 } else {
10622 if (bgp->update_delay_over) {
d62a17ae 10623 vty_out(vty,
10624 " First neighbor established: %s\n",
10625 bgp->update_delay_begin_time);
10626 vty_out(vty,
ea47320b
DL
10627 " Best-paths resumed: %s\n",
10628 bgp->update_delay_end_time);
10629 vty_out(vty,
10630 " zebra update resumed: %s\n",
10631 bgp->update_delay_zebra_resume_time);
10632 vty_out(vty,
10633 " peers update resumed: %s\n",
10634 bgp->update_delay_peers_resume_time);
d62a17ae 10635 }
10636 }
10637 }
ea47320b 10638 }
d62a17ae 10639
ea47320b
DL
10640 if (use_json) {
10641 if (bgp_maxmed_onstartup_configured(bgp)
10642 && bgp->maxmed_active)
10643 json_object_boolean_true_add(
60466a63 10644 json, "maxMedOnStartup");
ea47320b
DL
10645 if (bgp->v_maxmed_admin)
10646 json_object_boolean_true_add(
60466a63 10647 json, "maxMedAdministrative");
d62a17ae 10648
ea47320b
DL
10649 json_object_int_add(
10650 json, "tableVersion",
60466a63 10651 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10652
60466a63
QY
10653 ents = bgp_table_count(bgp->rib[afi][safi]);
10654 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10655 json_object_int_add(
10656 json, "ribMemory",
9bcb3eef 10657 ents * sizeof(struct bgp_dest));
d62a17ae 10658
210ec2a0 10659 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10660 json_object_int_add(json, "peerCount", ents);
10661 json_object_int_add(json, "peerMemory",
10662 ents * sizeof(struct peer));
d62a17ae 10663
ea47320b
DL
10664 if ((ents = listcount(bgp->group))) {
10665 json_object_int_add(
60466a63 10666 json, "peerGroupCount", ents);
ea47320b
DL
10667 json_object_int_add(
10668 json, "peerGroupMemory",
996c9314
LB
10669 ents * sizeof(struct
10670 peer_group));
ea47320b 10671 }
d62a17ae 10672
ea47320b
DL
10673 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10674 BGP_CONFIG_DAMPENING))
10675 json_object_boolean_true_add(
60466a63 10676 json, "dampeningEnabled");
ea47320b
DL
10677 } else {
10678 if (bgp_maxmed_onstartup_configured(bgp)
10679 && bgp->maxmed_active)
d62a17ae 10680 vty_out(vty,
ea47320b
DL
10681 "Max-med on-startup active\n");
10682 if (bgp->v_maxmed_admin)
d62a17ae 10683 vty_out(vty,
ea47320b 10684 "Max-med administrative active\n");
d62a17ae 10685
60466a63
QY
10686 vty_out(vty, "BGP table version %" PRIu64 "\n",
10687 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 10688
60466a63 10689 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
10690 vty_out(vty,
10691 "RIB entries %ld, using %s of memory\n",
10692 ents,
9bcb3eef
DS
10693 mtype_memstr(
10694 memstrbuf, sizeof(memstrbuf),
10695 ents
10696 * sizeof(struct
10697 bgp_dest)));
ea47320b
DL
10698
10699 /* Peer related usage */
210ec2a0 10700 ents = bgp->af_peer_count[afi][safi];
60466a63 10701 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
10702 ents,
10703 mtype_memstr(
60466a63
QY
10704 memstrbuf, sizeof(memstrbuf),
10705 ents * sizeof(struct peer)));
ea47320b
DL
10706
10707 if ((ents = listcount(bgp->group)))
d62a17ae 10708 vty_out(vty,
ea47320b 10709 "Peer groups %ld, using %s of memory\n",
d62a17ae 10710 ents,
10711 mtype_memstr(
10712 memstrbuf,
10713 sizeof(memstrbuf),
996c9314
LB
10714 ents * sizeof(struct
10715 peer_group)));
d62a17ae 10716
ea47320b
DL
10717 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10718 BGP_CONFIG_DAMPENING))
60466a63 10719 vty_out(vty, "Dampening enabled.\n");
ea47320b 10720 vty_out(vty, "\n");
d62a17ae 10721
ea47320b
DL
10722 /* Subtract 8 here because 'Neighbor' is
10723 * 8 characters */
10724 vty_out(vty, "Neighbor");
60466a63
QY
10725 vty_out(vty, "%*s", max_neighbor_width - 8,
10726 " ");
3577f1c5
DD
10727 if (show_failed)
10728 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
10729 else
10730 vty_out(vty,
db92d226 10731 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
d62a17ae 10732 }
ea47320b 10733 }
d62a17ae 10734
d55811cc 10735 paf = peer_af_find(peer, afi, safi);
d3ada366 10736 filter = &peer->filter[afi][safi];
db92d226 10737
ea47320b 10738 count++;
3577f1c5
DD
10739 /* Works for both failed & successful cases */
10740 if (peer_dynamic_neighbor(peer))
10741 dn_count++;
d62a17ae 10742
ea47320b 10743 if (use_json) {
3577f1c5
DD
10744 json_peer = NULL;
10745
10746 if (show_failed &&
10747 bgp_has_peer_failed(peer, afi, safi)) {
10748 json_peer = json_object_new_object();
10749 bgp_show_failed_summary(vty, bgp, peer,
10750 json_peer, 0, use_json);
10751 } else if (!show_failed) {
10b49f14
DA
10752 if (show_established
10753 && bgp_has_peer_failed(peer, afi, safi))
10754 continue;
10755
3577f1c5
DD
10756 json_peer = json_object_new_object();
10757 if (peer_dynamic_neighbor(peer)) {
10758 json_object_boolean_true_add(json_peer,
10759 "dynamicPeer");
10760 }
d62a17ae 10761
3577f1c5
DD
10762 if (peer->hostname)
10763 json_object_string_add(json_peer, "hostname",
10764 peer->hostname);
10765
10766 if (peer->domainname)
10767 json_object_string_add(json_peer, "domainname",
10768 peer->domainname);
10769
10770 json_object_int_add(json_peer, "remoteAs", peer->as);
10771 json_object_int_add(json_peer, "version", 4);
10772 json_object_int_add(json_peer, "msgRcvd",
10773 PEER_TOTAL_RX(peer));
10774 json_object_int_add(json_peer, "msgSent",
10775 PEER_TOTAL_TX(peer));
10776
43aa5965
QY
10777 atomic_size_t outq_count, inq_count;
10778 outq_count = atomic_load_explicit(
10779 &peer->obuf->count,
10780 memory_order_relaxed);
10781 inq_count = atomic_load_explicit(
10782 &peer->ibuf->count,
10783 memory_order_relaxed);
10784
3577f1c5
DD
10785 json_object_int_add(json_peer, "tableVersion",
10786 peer->version[afi][safi]);
10787 json_object_int_add(json_peer, "outq",
43aa5965
QY
10788 outq_count);
10789 json_object_int_add(json_peer, "inq",
10790 inq_count);
3577f1c5
DD
10791 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10792 use_json, json_peer);
10793
3577f1c5
DD
10794 json_object_int_add(json_peer, "pfxRcd",
10795 peer->pcount[afi][pfx_rcd_safi]);
10796
3577f1c5
DD
10797 if (paf && PAF_SUBGRP(paf))
10798 json_object_int_add(json_peer,
10799 "pfxSnt",
10800 (PAF_SUBGRP(paf))->scount);
cb9196e7 10801 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10802 || CHECK_FLAG(peer->bgp->flags,
10803 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10804 json_object_string_add(json_peer, "state",
10805 "Idle (Admin)");
10806 else if (peer->afc_recv[afi][safi])
10807 json_object_string_add(
10808 json_peer, "state",
10809 lookup_msg(bgp_status_msg, peer->status,
10810 NULL));
10811 else if (CHECK_FLAG(peer->sflags,
10812 PEER_STATUS_PREFIX_OVERFLOW))
10813 json_object_string_add(json_peer, "state",
10814 "Idle (PfxCt)");
10815 else
10816 json_object_string_add(
10817 json_peer, "state",
10818 lookup_msg(bgp_status_msg, peer->status,
10819 NULL));
200116db
DD
10820 json_object_int_add(json_peer, "connectionsEstablished",
10821 peer->established);
10822 json_object_int_add(json_peer, "connectionsDropped",
10823 peer->dropped);
b4e9dcba 10824 }
3577f1c5
DD
10825 /* Avoid creating empty peer dicts in JSON */
10826 if (json_peer == NULL)
10827 continue;
ea47320b
DL
10828
10829 if (peer->conf_if)
60466a63 10830 json_object_string_add(json_peer, "idType",
ea47320b
DL
10831 "interface");
10832 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10833 json_object_string_add(json_peer, "idType",
10834 "ipv4");
ea47320b 10835 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10836 json_object_string_add(json_peer, "idType",
10837 "ipv6");
ea47320b
DL
10838 json_object_object_add(json_peers, peer->host,
10839 json_peer);
10840 } else {
3577f1c5
DD
10841 if (show_failed &&
10842 bgp_has_peer_failed(peer, afi, safi)) {
10843 bgp_show_failed_summary(vty, bgp, peer, NULL,
10844 max_neighbor_width,
10845 use_json);
10846 } else if (!show_failed) {
10b49f14
DA
10847 if (show_established
10848 && bgp_has_peer_failed(peer, afi, safi))
10849 continue;
10850
3577f1c5
DD
10851 memset(dn_flag, '\0', sizeof(dn_flag));
10852 if (peer_dynamic_neighbor(peer)) {
10853 dn_flag[0] = '*';
10854 }
d62a17ae 10855
3577f1c5 10856 if (peer->hostname
892fedb6
DA
10857 && CHECK_FLAG(bgp->flags,
10858 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10859 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10860 peer->hostname,
10861 peer->host);
d62a17ae 10862 else
3577f1c5
DD
10863 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10864
10865 /* pad the neighbor column with spaces */
10866 if (len < max_neighbor_width)
10867 vty_out(vty, "%*s", max_neighbor_width - len,
10868 " ");
10869
43aa5965
QY
10870 atomic_size_t outq_count, inq_count;
10871 outq_count = atomic_load_explicit(
10872 &peer->obuf->count,
10873 memory_order_relaxed);
10874 inq_count = atomic_load_explicit(
10875 &peer->ibuf->count,
10876 memory_order_relaxed);
10877
566bdaf6 10878 vty_out(vty,
6cde4b45 10879 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
3577f1c5 10880 peer->as, PEER_TOTAL_RX(peer),
566bdaf6 10881 PEER_TOTAL_TX(peer),
43aa5965
QY
10882 peer->version[afi][safi], inq_count,
10883 outq_count,
3577f1c5
DD
10884 peer_uptime(peer->uptime, timebuf,
10885 BGP_UPTIME_LEN, 0, NULL));
10886
db92d226 10887 if (peer->status == Established) {
d3ada366
DA
10888 if (peer->afc_recv[afi][safi]) {
10889 if (CHECK_FLAG(
10890 bgp->flags,
10891 BGP_FLAG_EBGP_REQUIRES_POLICY)
10892 && !bgp_inbound_policy_exists(
10893 peer, filter))
10894 vty_out(vty, " %12s",
10895 "(Policy)");
10896 else
10897 vty_out(vty,
6cde4b45 10898 " %12u",
d3ada366
DA
10899 peer->pcount
10900 [afi]
10901 [pfx_rcd_safi]);
10902 } else {
3577f1c5 10903 vty_out(vty, " NoNeg");
d3ada366 10904 }
db92d226 10905
d3ada366
DA
10906 if (paf && PAF_SUBGRP(paf)) {
10907 if (CHECK_FLAG(
10908 bgp->flags,
10909 BGP_FLAG_EBGP_REQUIRES_POLICY)
10910 && !bgp_outbound_policy_exists(
10911 peer, filter))
10912 vty_out(vty, " %8s",
10913 "(Policy)");
10914 else
10915 vty_out(vty,
6cde4b45 10916 " %8u",
d3ada366
DA
10917 (PAF_SUBGRP(
10918 paf))
10919 ->scount);
10920 }
db92d226 10921 } else {
736b68f3
DS
10922 if (CHECK_FLAG(peer->flags,
10923 PEER_FLAG_SHUTDOWN)
10924 || CHECK_FLAG(peer->bgp->flags,
10925 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10926 vty_out(vty, " Idle (Admin)");
10927 else if (CHECK_FLAG(
10928 peer->sflags,
10929 PEER_STATUS_PREFIX_OVERFLOW))
10930 vty_out(vty, " Idle (PfxCt)");
10931 else
10932 vty_out(vty, " %12s",
10933 lookup_msg(bgp_status_msg,
10934 peer->status, NULL));
db92d226 10935
6cde4b45 10936 vty_out(vty, " %8u", 0);
3577f1c5
DD
10937 }
10938 vty_out(vty, "\n");
d62a17ae 10939 }
3577f1c5 10940
d62a17ae 10941 }
10942 }
f933309e 10943
d62a17ae 10944 if (use_json) {
10945 json_object_object_add(json, "peers", json_peers);
3577f1c5 10946 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 10947 json_object_int_add(json, "totalPeers", count);
10948 json_object_int_add(json, "dynamicPeers", dn_count);
10949
3577f1c5
DD
10950 if (!show_failed)
10951 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10952
996c9314
LB
10953 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10954 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10955 json_object_free(json);
10956 } else {
10957 if (count)
10958 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10959 else {
d6ceaca3 10960 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10961 get_afi_safi_str(afi, safi, false));
d62a17ae 10962 }
b05a1c8b 10963
d6ceaca3 10964 if (dn_count) {
d62a17ae 10965 vty_out(vty, "* - dynamic neighbor\n");
10966 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10967 dn_count, bgp->dynamic_neighbors_limit);
10968 }
10969 }
1ff9a340 10970
d62a17ae 10971 return CMD_SUCCESS;
718e3744 10972}
10973
d62a17ae 10974static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10b49f14
DA
10975 int safi, bool show_failed,
10976 bool show_established, bool use_json)
d62a17ae 10977{
10978 int is_first = 1;
10979 int afi_wildcard = (afi == AFI_MAX);
10980 int safi_wildcard = (safi == SAFI_MAX);
10981 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10982 bool nbr_output = false;
d62a17ae 10983
10984 if (use_json && is_wildcard)
10985 vty_out(vty, "{\n");
10986 if (afi_wildcard)
10987 afi = 1; /* AFI_IP */
10988 while (afi < AFI_MAX) {
10989 if (safi_wildcard)
10990 safi = 1; /* SAFI_UNICAST */
10991 while (safi < SAFI_MAX) {
318cac96 10992 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10993 nbr_output = true;
f86897b9 10994
d62a17ae 10995 if (is_wildcard) {
10996 /*
10997 * So limit output to those afi/safi
10998 * pairs that
10999 * actualy have something interesting in
11000 * them
11001 */
11002 if (use_json) {
d62a17ae 11003 if (!is_first)
11004 vty_out(vty, ",\n");
11005 else
11006 is_first = 0;
11007
11008 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11009 get_afi_safi_str(afi,
11010 safi,
11011 true));
d62a17ae 11012 } else {
11013 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
11014 get_afi_safi_str(afi,
11015 safi,
11016 false));
d62a17ae 11017 }
11018 }
10b49f14
DA
11019 bgp_show_summary(vty, bgp, afi, safi,
11020 show_failed, show_established,
3577f1c5 11021 use_json);
d62a17ae 11022 }
11023 safi++;
d62a17ae 11024 if (!safi_wildcard)
11025 safi = SAFI_MAX;
11026 }
11027 afi++;
ee851c8c 11028 if (!afi_wildcard)
d62a17ae 11029 afi = AFI_MAX;
11030 }
11031
11032 if (use_json && is_wildcard)
11033 vty_out(vty, "}\n");
ca61fd25
DS
11034 else if (!nbr_output) {
11035 if (use_json)
11036 vty_out(vty, "{}\n");
11037 else
11038 vty_out(vty, "%% No BGP neighbors found\n");
11039 }
d62a17ae 11040}
11041
11042static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5 11043 safi_t safi, bool show_failed,
10b49f14 11044 bool show_established,
3577f1c5 11045 bool use_json)
d62a17ae 11046{
11047 struct listnode *node, *nnode;
11048 struct bgp *bgp;
d62a17ae 11049 int is_first = 1;
9f049418 11050 bool nbr_output = false;
d62a17ae 11051
11052 if (use_json)
11053 vty_out(vty, "{\n");
11054
11055 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11056 nbr_output = true;
d62a17ae 11057 if (use_json) {
d62a17ae 11058 if (!is_first)
11059 vty_out(vty, ",\n");
11060 else
11061 is_first = 0;
11062
11063 vty_out(vty, "\"%s\":",
11064 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11065 ? VRF_DEFAULT_NAME
d62a17ae 11066 : bgp->name);
11067 } else {
11068 vty_out(vty, "\nInstance %s:\n",
11069 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11070 ? VRF_DEFAULT_NAME
d62a17ae 11071 : bgp->name);
11072 }
3577f1c5 11073 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 11074 show_established, use_json);
d62a17ae 11075 }
11076
11077 if (use_json)
11078 vty_out(vty, "}\n");
9f049418
DS
11079 else if (!nbr_output)
11080 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11081}
11082
11083int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10b49f14
DA
11084 safi_t safi, bool show_failed, bool show_established,
11085 bool use_json)
d62a17ae 11086{
11087 struct bgp *bgp;
11088
11089 if (name) {
11090 if (strmatch(name, "all")) {
10b49f14
DA
11091 bgp_show_all_instances_summary_vty(
11092 vty, afi, safi, show_failed, show_established,
11093 use_json);
d62a17ae 11094 return CMD_SUCCESS;
11095 } else {
11096 bgp = bgp_lookup_by_name(name);
11097
11098 if (!bgp) {
11099 if (use_json)
11100 vty_out(vty, "{}\n");
11101 else
11102 vty_out(vty,
ca61fd25 11103 "%% BGP instance not found\n");
d62a17ae 11104 return CMD_WARNING;
11105 }
11106
f86897b9 11107 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
10b49f14
DA
11108 show_failed, show_established,
11109 use_json);
d62a17ae 11110 return CMD_SUCCESS;
11111 }
11112 }
11113
11114 bgp = bgp_get_default();
11115
11116 if (bgp)
3577f1c5 11117 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 11118 show_established, use_json);
9f049418 11119 else {
ca61fd25
DS
11120 if (use_json)
11121 vty_out(vty, "{}\n");
11122 else
11123 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11124 return CMD_WARNING;
11125 }
d62a17ae 11126
11127 return CMD_SUCCESS;
4fb25c53
DW
11128}
11129
716b2d8a 11130/* `show [ip] bgp summary' commands. */
96f3485c 11131DEFPY (show_ip_bgp_summary,
718e3744 11132 show_ip_bgp_summary_cmd,
96f3485c 11133 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
718e3744 11134 SHOW_STR
11135 IP_STR
11136 BGP_STR
8386ac43 11137 BGP_INSTANCE_HELP_STR
46f296b4 11138 BGP_AFI_HELP_STR
dd6bd0f1 11139 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 11140 "Display the entries for all address families\n"
b05a1c8b 11141 "Summary of BGP neighbor status\n"
10b49f14 11142 "Show only sessions in Established state\n"
3577f1c5 11143 "Show only sessions not in Established state\n"
9973d184 11144 JSON_STR)
718e3744 11145{
d62a17ae 11146 char *vrf = NULL;
11147 afi_t afi = AFI_MAX;
11148 safi_t safi = SAFI_MAX;
3577f1c5 11149 bool show_failed = false;
10b49f14 11150 bool show_established = false;
d62a17ae 11151
11152 int idx = 0;
11153
11154 /* show [ip] bgp */
96f3485c 11155 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11156 afi = AFI_IP;
9a8bdf1c
PG
11157 /* [<vrf> VIEWVRFNAME] */
11158 if (argv_find(argv, argc, "vrf", &idx)) {
11159 vrf = argv[idx + 1]->arg;
11160 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11161 vrf = NULL;
11162 } else if (argv_find(argv, argc, "view", &idx))
11163 /* [<view> VIEWVRFNAME] */
11164 vrf = argv[idx + 1]->arg;
d62a17ae 11165 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11166 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11167 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11168 }
11169
3577f1c5
DD
11170 if (argv_find(argv, argc, "failed", &idx))
11171 show_failed = true;
10b49f14
DA
11172 if (argv_find(argv, argc, "established", &idx))
11173 show_established = true;
3577f1c5 11174
10b49f14
DA
11175 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
11176 show_established, uj);
d62a17ae 11177}
11178
5cb5f4d0 11179const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11180{
5cb5f4d0
DD
11181 if (for_json)
11182 return get_afi_safi_json_str(afi, safi);
d62a17ae 11183 else
5cb5f4d0 11184 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11185}
11186
d62a17ae 11187
11188static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11189 afi_t afi, safi_t safi,
d7c0a89a
QY
11190 uint16_t adv_smcap, uint16_t adv_rmcap,
11191 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11192 bool use_json, json_object *json_pref)
d62a17ae 11193{
11194 /* Send-Mode */
11195 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11196 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11197 if (use_json) {
11198 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11199 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11200 json_object_string_add(json_pref, "sendMode",
11201 "advertisedAndReceived");
11202 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11203 json_object_string_add(json_pref, "sendMode",
11204 "advertised");
11205 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11206 json_object_string_add(json_pref, "sendMode",
11207 "received");
11208 } else {
11209 vty_out(vty, " Send-mode: ");
11210 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11211 vty_out(vty, "advertised");
11212 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11213 vty_out(vty, "%sreceived",
11214 CHECK_FLAG(p->af_cap[afi][safi],
11215 adv_smcap)
11216 ? ", "
11217 : "");
11218 vty_out(vty, "\n");
11219 }
11220 }
11221
11222 /* Receive-Mode */
11223 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11224 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11225 if (use_json) {
11226 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11227 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11228 json_object_string_add(json_pref, "recvMode",
11229 "advertisedAndReceived");
11230 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11231 json_object_string_add(json_pref, "recvMode",
11232 "advertised");
11233 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11234 json_object_string_add(json_pref, "recvMode",
11235 "received");
11236 } else {
11237 vty_out(vty, " Receive-mode: ");
11238 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11239 vty_out(vty, "advertised");
11240 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11241 vty_out(vty, "%sreceived",
11242 CHECK_FLAG(p->af_cap[afi][safi],
11243 adv_rmcap)
11244 ? ", "
11245 : "");
11246 vty_out(vty, "\n");
11247 }
11248 }
11249}
11250
13909c4f
DS
11251static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11252 struct peer *p,
11253 bool use_json,
11254 json_object *json)
2986cac2 11255{
08c2d52a 11256 bool rbit_status = false;
2986cac2 11257
11258 if (!use_json)
a53ca37b 11259 vty_out(vty, "\n R bit: ");
2986cac2 11260
13909c4f
DS
11261 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11262 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11263 && (p->status == Established)) {
2986cac2 11264
11265 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11266 rbit_status = true;
2986cac2 11267 else
08c2d52a 11268 rbit_status = false;
2986cac2 11269 }
11270
11271 if (rbit_status) {
11272 if (use_json)
13909c4f 11273 json_object_boolean_true_add(json, "rBit");
2986cac2 11274 else
11275 vty_out(vty, "True\n");
11276 } else {
11277 if (use_json)
13909c4f 11278 json_object_boolean_false_add(json, "rBit");
2986cac2 11279 else
11280 vty_out(vty, "False\n");
11281 }
11282}
11283
13909c4f
DS
11284static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11285 struct peer *peer,
11286 bool use_json,
11287 json_object *json)
2986cac2 11288{
2bb5d39b 11289 const char *mode = "NotApplicable";
2986cac2 11290
11291 if (!use_json)
a53ca37b 11292 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11293
13909c4f
DS
11294 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11295 && (peer->status == Established)) {
2986cac2 11296
13909c4f
DS
11297 if ((peer->nsf_af_count == 0)
11298 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11299
2986cac2 11300 mode = "Disable";
11301
13909c4f
DS
11302 } else if (peer->nsf_af_count == 0
11303 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11304
2986cac2 11305 mode = "Helper";
11306
13909c4f
DS
11307 } else if (peer->nsf_af_count != 0
11308 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11309
2986cac2 11310 mode = "Restart";
2986cac2 11311 }
11312 }
11313
11314 if (use_json) {
13909c4f 11315 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11316 } else
11317 vty_out(vty, mode, "\n");
11318}
11319
13909c4f
DS
11320static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11321 struct peer *p,
11322 bool use_json,
11323 json_object *json)
2986cac2 11324{
11325 const char *mode = "Invalid";
11326
11327 if (!use_json)
a53ca37b 11328 vty_out(vty, " Local GR Mode: ");
2986cac2 11329
11330 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11331 mode = "Helper";
11332 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11333 mode = "Restart";
11334 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11335 mode = "Disable";
2ba1fe69 11336 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11337 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11338 mode = "Helper*";
11339 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11340 mode = "Restart*";
11341 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11342 mode = "Disable*";
11343 else
11344 mode = "Invalid*";
2ba1fe69 11345 }
2986cac2 11346
11347 if (use_json) {
13909c4f 11348 json_object_string_add(json, "localGrMode", mode);
2986cac2 11349 } else {
11350 vty_out(vty, mode, "\n");
11351 }
11352}
11353
13909c4f
DS
11354static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11355 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11356{
2ba1fe69 11357 afi_t afi;
11358 safi_t safi;
2986cac2 11359 json_object *json_afi_safi = NULL;
11360 json_object *json_timer = NULL;
11361 json_object *json_endofrib_status = NULL;
9e3b51a7 11362 bool eor_flag = false;
2986cac2 11363
11364 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11365 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
11366 if (!peer->afc[afi][safi])
11367 continue;
2986cac2 11368
13909c4f
DS
11369 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11370 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11371 continue;
9e3b51a7 11372
13909c4f
DS
11373 if (use_json) {
11374 json_afi_safi = json_object_new_object();
11375 json_endofrib_status = json_object_new_object();
11376 json_timer = json_object_new_object();
11377 }
2986cac2 11378
13909c4f
DS
11379 if (peer->eor_stime[afi][safi]
11380 >= peer->pkt_stime[afi][safi])
11381 eor_flag = true;
11382 else
11383 eor_flag = false;
2986cac2 11384
13909c4f 11385 if (!use_json) {
a53ca37b 11386 vty_out(vty, " %s:\n",
13909c4f 11387 get_afi_safi_str(afi, safi, false));
2986cac2 11388
a53ca37b 11389 vty_out(vty, " F bit: ");
698ba8d0 11390 }
2986cac2 11391
13909c4f
DS
11392 if (peer->nsf[afi][safi]
11393 && CHECK_FLAG(peer->af_cap[afi][safi],
11394 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11395
13909c4f
DS
11396 if (use_json) {
11397 json_object_boolean_true_add(
2986cac2 11398 json_afi_safi, "fBit");
13909c4f
DS
11399 } else
11400 vty_out(vty, "True\n");
11401 } else {
11402 if (use_json)
11403 json_object_boolean_false_add(
11404 json_afi_safi, "fBit");
11405 else
11406 vty_out(vty, "False\n");
11407 }
2986cac2 11408
13909c4f 11409 if (!use_json)
a53ca37b 11410 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11411
13909c4f
DS
11412 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11413 PEER_STATUS_EOR_SEND)) {
11414 if (use_json) {
11415 json_object_boolean_true_add(
2986cac2 11416 json_endofrib_status,
13909c4f 11417 "endOfRibSend");
9e3b51a7 11418
13909c4f
DS
11419 PRINT_EOR_JSON(eor_flag);
11420 } else {
11421 vty_out(vty, "Yes\n");
11422 vty_out(vty,
a53ca37b 11423 " End-of-RIB sent after update: ");
2986cac2 11424
13909c4f
DS
11425 PRINT_EOR(eor_flag);
11426 }
11427 } else {
11428 if (use_json) {
11429 json_object_boolean_false_add(
2986cac2 11430 json_endofrib_status,
13909c4f
DS
11431 "endOfRibSend");
11432 json_object_boolean_false_add(
9e3b51a7 11433 json_endofrib_status,
13909c4f
DS
11434 "endOfRibSentAfterUpdate");
11435 } else {
11436 vty_out(vty, "No\n");
11437 vty_out(vty,
a53ca37b 11438 " End-of-RIB sent after update: ");
13909c4f 11439 vty_out(vty, "No\n");
2986cac2 11440 }
13909c4f 11441 }
2986cac2 11442
a53ca37b
DA
11443 if (!use_json)
11444 vty_out(vty, " End-of-RIB received: ");
11445
11446 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11447 PEER_STATUS_EOR_RECEIVED)) {
11448 if (use_json)
11449 json_object_boolean_true_add(
11450 json_endofrib_status,
11451 "endOfRibRecv");
11452 else
11453 vty_out(vty, "Yes\n");
11454 } else {
11455 if (use_json)
11456 json_object_boolean_false_add(
11457 json_endofrib_status,
11458 "endOfRibRecv");
11459 else
11460 vty_out(vty, "No\n");
11461 }
11462
13909c4f
DS
11463 if (use_json) {
11464 json_object_int_add(json_timer,
11465 "stalePathTimer",
11466 peer->bgp->stalepath_time);
2986cac2 11467
13909c4f
DS
11468 if (peer->t_gr_stale != NULL) {
11469 json_object_int_add(
2986cac2 11470 json_timer,
11471 "stalePathTimerRemaining",
11472 thread_timer_remain_second(
13909c4f
DS
11473 peer->t_gr_stale));
11474 }
3a75afa4 11475
13909c4f
DS
11476 /* Display Configured Selection
11477 * Deferral only when when
11478 * Gr mode is enabled.
11479 */
11480 if (CHECK_FLAG(peer->flags,
11481 PEER_FLAG_GRACEFUL_RESTART)) {
11482 json_object_int_add(
3a75afa4 11483 json_timer,
2986cac2 11484 "selectionDeferralTimer",
11485 peer->bgp->stalepath_time);
13909c4f 11486 }
2986cac2 11487
13909c4f
DS
11488 if (peer->bgp->gr_info[afi][safi]
11489 .t_select_deferral
11490 != NULL) {
2986cac2 11491
13909c4f 11492 json_object_int_add(
2986cac2 11493 json_timer,
11494 "selectionDeferralTimerRemaining",
11495 thread_timer_remain_second(
13909c4f
DS
11496 peer->bgp
11497 ->gr_info[afi]
11498 [safi]
11499 .t_select_deferral));
11500 }
11501 } else {
a53ca37b 11502 vty_out(vty, " Timers:\n");
13909c4f 11503 vty_out(vty,
a53ca37b
DA
11504 " Configured Stale Path Time(sec): %u\n",
11505 peer->bgp->stalepath_time);
2986cac2 11506
a53ca37b 11507 if (peer->t_gr_stale != NULL)
2986cac2 11508 vty_out(vty,
a53ca37b 11509 " Stale Path Remaining(sec): %ld\n",
2986cac2 11510 thread_timer_remain_second(
13909c4f 11511 peer->t_gr_stale));
13909c4f
DS
11512 /* Display Configured Selection
11513 * Deferral only when when
11514 * Gr mode is enabled.
11515 */
11516 if (CHECK_FLAG(peer->flags,
a53ca37b 11517 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 11518 vty_out(vty,
a53ca37b 11519 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 11520 peer->bgp->select_defer_time);
2986cac2 11521
13909c4f
DS
11522 if (peer->bgp->gr_info[afi][safi]
11523 .t_select_deferral
a53ca37b 11524 != NULL)
13909c4f 11525 vty_out(vty,
a53ca37b 11526 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 11527 thread_timer_remain_second(
13909c4f
DS
11528 peer->bgp
11529 ->gr_info[afi]
11530 [safi]
11531 .t_select_deferral));
2986cac2 11532 }
13909c4f
DS
11533 if (use_json) {
11534 json_object_object_add(json_afi_safi,
11535 "endOfRibStatus",
11536 json_endofrib_status);
11537 json_object_object_add(json_afi_safi, "timers",
11538 json_timer);
11539 json_object_object_add(
11540 json, get_afi_safi_str(afi, safi, true),
11541 json_afi_safi);
11542 }
2986cac2 11543 }
11544 }
11545}
11546
36235319
QY
11547static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11548 struct peer *p,
11549 bool use_json,
11550 json_object *json)
2986cac2 11551{
11552 if (use_json) {
11553 json_object *json_timer = NULL;
11554
11555 json_timer = json_object_new_object();
11556
13909c4f
DS
11557 json_object_int_add(json_timer, "configuredRestartTimer",
11558 p->bgp->restart_time);
2986cac2 11559
13909c4f
DS
11560 json_object_int_add(json_timer, "receivedRestartTimer",
11561 p->v_gr_restart);
2986cac2 11562
13909c4f
DS
11563 if (p->t_gr_restart != NULL)
11564 json_object_int_add(
11565 json_timer, "restartTimerRemaining",
11566 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11567
11568 json_object_object_add(json, "timers", json_timer);
11569 } else {
11570
a53ca37b
DA
11571 vty_out(vty, " Timers:\n");
11572 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11573 p->bgp->restart_time);
2986cac2 11574
a53ca37b 11575 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11576 p->v_gr_restart);
11577 if (p->t_gr_restart != NULL)
a53ca37b 11578 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11579 thread_timer_remain_second(p->t_gr_restart));
36235319 11580 if (p->t_gr_restart != NULL) {
a53ca37b 11581 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11582 thread_timer_remain_second(p->t_gr_restart));
11583 }
2986cac2 11584 }
11585}
11586
11587static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11588 bool use_json, json_object *json)
2986cac2 11589{
11590 char buf[SU_ADDRSTRLEN] = {0};
11591 char dn_flag[2] = {0};
2b7165e7
QY
11592 /* '*' + v6 address of neighbor */
11593 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11594
2986cac2 11595 if (!p->conf_if && peer_dynamic_neighbor(p))
11596 dn_flag[0] = '*';
11597
11598 if (p->conf_if) {
11599 if (use_json)
13909c4f
DS
11600 json_object_string_add(
11601 json, "neighborAddr",
2986cac2 11602 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11603 ? "none"
11604 : sockunion2str(&p->su, buf,
11605 SU_ADDRSTRLEN));
2986cac2 11606 else
13909c4f 11607 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11608 BGP_PEER_SU_UNSPEC(p)
11609 ? "none"
11610 : sockunion2str(&p->su, buf,
11611 SU_ADDRSTRLEN));
11612 } else {
772270f3
QY
11613 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11614 p->host);
2986cac2 11615
11616 if (use_json)
36235319
QY
11617 json_object_string_add(json, "neighborAddr",
11618 neighborAddr);
2986cac2 11619 else
36235319 11620 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11621 }
11622
11623 /* more gr info in new format */
11624 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11625}
11626
d62a17ae 11627static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11628 safi_t safi, bool use_json,
d62a17ae 11629 json_object *json_neigh)
11630{
0291c246
MK
11631 struct bgp_filter *filter;
11632 struct peer_af *paf;
11633 char orf_pfx_name[BUFSIZ];
11634 int orf_pfx_count;
11635 json_object *json_af = NULL;
11636 json_object *json_prefA = NULL;
11637 json_object *json_prefB = NULL;
11638 json_object *json_addr = NULL;
fa36596c 11639 json_object *json_advmap = NULL;
d62a17ae 11640
11641 if (use_json) {
11642 json_addr = json_object_new_object();
11643 json_af = json_object_new_object();
11644 filter = &p->filter[afi][safi];
11645
11646 if (peer_group_active(p))
11647 json_object_string_add(json_addr, "peerGroupMember",
11648 p->group->name);
11649
11650 paf = peer_af_find(p, afi, safi);
11651 if (paf && PAF_SUBGRP(paf)) {
11652 json_object_int_add(json_addr, "updateGroupId",
11653 PAF_UPDGRP(paf)->id);
11654 json_object_int_add(json_addr, "subGroupId",
11655 PAF_SUBGRP(paf)->id);
11656 json_object_int_add(json_addr, "packetQueueLength",
11657 bpacket_queue_virtual_length(paf));
11658 }
11659
11660 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11661 || CHECK_FLAG(p->af_cap[afi][safi],
11662 PEER_CAP_ORF_PREFIX_SM_RCV)
11663 || CHECK_FLAG(p->af_cap[afi][safi],
11664 PEER_CAP_ORF_PREFIX_RM_ADV)
11665 || CHECK_FLAG(p->af_cap[afi][safi],
11666 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11667 json_object_int_add(json_af, "orfType",
11668 ORF_TYPE_PREFIX);
11669 json_prefA = json_object_new_object();
11670 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11671 PEER_CAP_ORF_PREFIX_SM_ADV,
11672 PEER_CAP_ORF_PREFIX_RM_ADV,
11673 PEER_CAP_ORF_PREFIX_SM_RCV,
11674 PEER_CAP_ORF_PREFIX_RM_RCV,
11675 use_json, json_prefA);
11676 json_object_object_add(json_af, "orfPrefixList",
11677 json_prefA);
11678 }
11679
11680 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11681 || CHECK_FLAG(p->af_cap[afi][safi],
11682 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11683 || CHECK_FLAG(p->af_cap[afi][safi],
11684 PEER_CAP_ORF_PREFIX_RM_ADV)
11685 || CHECK_FLAG(p->af_cap[afi][safi],
11686 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11687 json_object_int_add(json_af, "orfOldType",
11688 ORF_TYPE_PREFIX_OLD);
11689 json_prefB = json_object_new_object();
11690 bgp_show_peer_afi_orf_cap(
11691 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11692 PEER_CAP_ORF_PREFIX_RM_ADV,
11693 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11694 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11695 json_prefB);
11696 json_object_object_add(json_af, "orfOldPrefixList",
11697 json_prefB);
11698 }
11699
11700 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11701 || CHECK_FLAG(p->af_cap[afi][safi],
11702 PEER_CAP_ORF_PREFIX_SM_RCV)
11703 || CHECK_FLAG(p->af_cap[afi][safi],
11704 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11705 || CHECK_FLAG(p->af_cap[afi][safi],
11706 PEER_CAP_ORF_PREFIX_RM_ADV)
11707 || CHECK_FLAG(p->af_cap[afi][safi],
11708 PEER_CAP_ORF_PREFIX_RM_RCV)
11709 || CHECK_FLAG(p->af_cap[afi][safi],
11710 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11711 json_object_object_add(json_addr, "afDependentCap",
11712 json_af);
11713 else
11714 json_object_free(json_af);
11715
772270f3
QY
11716 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11717 p->host, afi, safi);
d62a17ae 11718 orf_pfx_count = prefix_bgp_show_prefix_list(
11719 NULL, afi, orf_pfx_name, use_json);
11720
11721 if (CHECK_FLAG(p->af_sflags[afi][safi],
11722 PEER_STATUS_ORF_PREFIX_SEND)
11723 || orf_pfx_count) {
11724 if (CHECK_FLAG(p->af_sflags[afi][safi],
11725 PEER_STATUS_ORF_PREFIX_SEND))
11726 json_object_boolean_true_add(json_neigh,
11727 "orfSent");
11728 if (orf_pfx_count)
11729 json_object_int_add(json_addr, "orfRecvCounter",
11730 orf_pfx_count);
11731 }
11732 if (CHECK_FLAG(p->af_sflags[afi][safi],
11733 PEER_STATUS_ORF_WAIT_REFRESH))
11734 json_object_string_add(
11735 json_addr, "orfFirstUpdate",
11736 "deferredUntilORFOrRouteRefreshRecvd");
11737
11738 if (CHECK_FLAG(p->af_flags[afi][safi],
11739 PEER_FLAG_REFLECTOR_CLIENT))
11740 json_object_boolean_true_add(json_addr,
11741 "routeReflectorClient");
11742 if (CHECK_FLAG(p->af_flags[afi][safi],
11743 PEER_FLAG_RSERVER_CLIENT))
11744 json_object_boolean_true_add(json_addr,
11745 "routeServerClient");
11746 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11747 json_object_boolean_true_add(json_addr,
11748 "inboundSoftConfigPermit");
11749
11750 if (CHECK_FLAG(p->af_flags[afi][safi],
11751 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11752 json_object_boolean_true_add(
11753 json_addr,
11754 "privateAsNumsAllReplacedInUpdatesToNbr");
11755 else if (CHECK_FLAG(p->af_flags[afi][safi],
11756 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11757 json_object_boolean_true_add(
11758 json_addr,
11759 "privateAsNumsReplacedInUpdatesToNbr");
11760 else if (CHECK_FLAG(p->af_flags[afi][safi],
11761 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11762 json_object_boolean_true_add(
11763 json_addr,
11764 "privateAsNumsAllRemovedInUpdatesToNbr");
11765 else if (CHECK_FLAG(p->af_flags[afi][safi],
11766 PEER_FLAG_REMOVE_PRIVATE_AS))
11767 json_object_boolean_true_add(
11768 json_addr,
11769 "privateAsNumsRemovedInUpdatesToNbr");
11770
dcc68b5e
MS
11771 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11772 json_object_boolean_true_add(
11773 json_addr,
11774 bgp_addpath_names(p->addpath_type[afi][safi])
11775 ->type_json_name);
d62a17ae 11776
11777 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11778 json_object_string_add(json_addr,
11779 "overrideASNsInOutboundUpdates",
11780 "ifAspathEqualRemoteAs");
11781
11782 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11783 || CHECK_FLAG(p->af_flags[afi][safi],
11784 PEER_FLAG_FORCE_NEXTHOP_SELF))
11785 json_object_boolean_true_add(json_addr,
11786 "routerAlwaysNextHop");
11787 if (CHECK_FLAG(p->af_flags[afi][safi],
11788 PEER_FLAG_AS_PATH_UNCHANGED))
11789 json_object_boolean_true_add(
11790 json_addr, "unchangedAsPathPropogatedToNbr");
11791 if (CHECK_FLAG(p->af_flags[afi][safi],
11792 PEER_FLAG_NEXTHOP_UNCHANGED))
11793 json_object_boolean_true_add(
11794 json_addr, "unchangedNextHopPropogatedToNbr");
11795 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11796 json_object_boolean_true_add(
11797 json_addr, "unchangedMedPropogatedToNbr");
11798 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11799 || CHECK_FLAG(p->af_flags[afi][safi],
11800 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11801 if (CHECK_FLAG(p->af_flags[afi][safi],
11802 PEER_FLAG_SEND_COMMUNITY)
11803 && CHECK_FLAG(p->af_flags[afi][safi],
11804 PEER_FLAG_SEND_EXT_COMMUNITY))
11805 json_object_string_add(json_addr,
11806 "commAttriSentToNbr",
11807 "extendedAndStandard");
11808 else if (CHECK_FLAG(p->af_flags[afi][safi],
11809 PEER_FLAG_SEND_EXT_COMMUNITY))
11810 json_object_string_add(json_addr,
11811 "commAttriSentToNbr",
11812 "extended");
11813 else
11814 json_object_string_add(json_addr,
11815 "commAttriSentToNbr",
11816 "standard");
11817 }
11818 if (CHECK_FLAG(p->af_flags[afi][safi],
11819 PEER_FLAG_DEFAULT_ORIGINATE)) {
11820 if (p->default_rmap[afi][safi].name)
11821 json_object_string_add(
11822 json_addr, "defaultRouteMap",
11823 p->default_rmap[afi][safi].name);
11824
11825 if (paf && PAF_SUBGRP(paf)
11826 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11827 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11828 json_object_boolean_true_add(json_addr,
11829 "defaultSent");
11830 else
11831 json_object_boolean_true_add(json_addr,
11832 "defaultNotSent");
11833 }
11834
dff8f48d 11835 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11836 if (is_evpn_enabled())
60466a63
QY
11837 json_object_boolean_true_add(
11838 json_addr, "advertiseAllVnis");
dff8f48d
MK
11839 }
11840
d62a17ae 11841 if (filter->plist[FILTER_IN].name
11842 || filter->dlist[FILTER_IN].name
11843 || filter->aslist[FILTER_IN].name
11844 || filter->map[RMAP_IN].name)
11845 json_object_boolean_true_add(json_addr,
11846 "inboundPathPolicyConfig");
11847 if (filter->plist[FILTER_OUT].name
11848 || filter->dlist[FILTER_OUT].name
11849 || filter->aslist[FILTER_OUT].name
11850 || filter->map[RMAP_OUT].name || filter->usmap.name)
11851 json_object_boolean_true_add(
11852 json_addr, "outboundPathPolicyConfig");
11853
11854 /* prefix-list */
11855 if (filter->plist[FILTER_IN].name)
11856 json_object_string_add(json_addr,
11857 "incomingUpdatePrefixFilterList",
11858 filter->plist[FILTER_IN].name);
11859 if (filter->plist[FILTER_OUT].name)
11860 json_object_string_add(json_addr,
11861 "outgoingUpdatePrefixFilterList",
11862 filter->plist[FILTER_OUT].name);
11863
11864 /* distribute-list */
11865 if (filter->dlist[FILTER_IN].name)
11866 json_object_string_add(
11867 json_addr, "incomingUpdateNetworkFilterList",
11868 filter->dlist[FILTER_IN].name);
11869 if (filter->dlist[FILTER_OUT].name)
11870 json_object_string_add(
11871 json_addr, "outgoingUpdateNetworkFilterList",
11872 filter->dlist[FILTER_OUT].name);
11873
11874 /* filter-list. */
11875 if (filter->aslist[FILTER_IN].name)
11876 json_object_string_add(json_addr,
11877 "incomingUpdateAsPathFilterList",
11878 filter->aslist[FILTER_IN].name);
11879 if (filter->aslist[FILTER_OUT].name)
11880 json_object_string_add(json_addr,
11881 "outgoingUpdateAsPathFilterList",
11882 filter->aslist[FILTER_OUT].name);
11883
11884 /* route-map. */
11885 if (filter->map[RMAP_IN].name)
11886 json_object_string_add(
11887 json_addr, "routeMapForIncomingAdvertisements",
11888 filter->map[RMAP_IN].name);
11889 if (filter->map[RMAP_OUT].name)
11890 json_object_string_add(
11891 json_addr, "routeMapForOutgoingAdvertisements",
11892 filter->map[RMAP_OUT].name);
11893
9dac9fc8 11894 /* ebgp-requires-policy (inbound) */
1d3fdccf 11895 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11896 && !bgp_inbound_policy_exists(p, filter))
11897 json_object_string_add(
11898 json_addr, "inboundEbgpRequiresPolicy",
11899 "Inbound updates discarded due to missing policy");
11900
11901 /* ebgp-requires-policy (outbound) */
1d3fdccf 11902 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11903 && (!bgp_outbound_policy_exists(p, filter)))
11904 json_object_string_add(
11905 json_addr, "outboundEbgpRequiresPolicy",
11906 "Outbound updates discarded due to missing policy");
11907
d62a17ae 11908 /* unsuppress-map */
11909 if (filter->usmap.name)
11910 json_object_string_add(json_addr,
11911 "selectiveUnsuppressRouteMap",
11912 filter->usmap.name);
11913
fa36596c
MK
11914 /* advertise-map */
11915 if (filter->advmap.aname) {
11916 json_advmap = json_object_new_object();
11917 json_object_string_add(json_advmap, "condition",
11918 filter->advmap.condition
11919 ? "EXIST"
11920 : "NON_EXIST");
11921 json_object_string_add(json_advmap, "conditionMap",
11922 filter->advmap.cname);
11923 json_object_string_add(json_advmap, "advertiseMap",
11924 filter->advmap.aname);
11925 json_object_string_add(json_advmap, "advertiseStatus",
11926 filter->advmap.update_type
11927 == ADVERTISE
11928 ? "Advertise"
11929 : "Withdraw");
11930 json_object_object_add(json_addr, "advertiseMap",
11931 json_advmap);
11932 }
11933
d62a17ae 11934 /* Receive prefix count */
11935 json_object_int_add(json_addr, "acceptedPrefixCounter",
11936 p->pcount[afi][safi]);
50e05855
AD
11937 if (paf && PAF_SUBGRP(paf))
11938 json_object_int_add(json_addr, "sentPrefixCounter",
11939 (PAF_SUBGRP(paf))->scount);
d62a17ae 11940
fde246e8
DA
11941 /* Maximum prefix */
11942 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11943 json_object_int_add(json_addr, "prefixOutAllowedMax",
11944 p->pmax_out[afi][safi]);
11945
d62a17ae 11946 /* Maximum prefix */
11947 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11948 json_object_int_add(json_addr, "prefixAllowedMax",
11949 p->pmax[afi][safi]);
11950 if (CHECK_FLAG(p->af_flags[afi][safi],
11951 PEER_FLAG_MAX_PREFIX_WARNING))
11952 json_object_boolean_true_add(
11953 json_addr, "prefixAllowedMaxWarning");
11954 json_object_int_add(json_addr,
11955 "prefixAllowedWarningThresh",
11956 p->pmax_threshold[afi][safi]);
11957 if (p->pmax_restart[afi][safi])
11958 json_object_int_add(
11959 json_addr,
11960 "prefixAllowedRestartIntervalMsecs",
11961 p->pmax_restart[afi][safi] * 60000);
11962 }
2986cac2 11963 json_object_object_add(json_neigh,
36235319 11964 get_afi_safi_str(afi, safi, true),
d62a17ae 11965 json_addr);
11966
11967 } else {
11968 filter = &p->filter[afi][safi];
11969
11970 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11971 get_afi_safi_str(afi, safi, false));
d62a17ae 11972
11973 if (peer_group_active(p))
11974 vty_out(vty, " %s peer-group member\n",
11975 p->group->name);
11976
11977 paf = peer_af_find(p, afi, safi);
11978 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11979 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11980 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11981 vty_out(vty, " Packet Queue length %d\n",
11982 bpacket_queue_virtual_length(paf));
11983 } else {
11984 vty_out(vty, " Not part of any update group\n");
11985 }
11986 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11987 || CHECK_FLAG(p->af_cap[afi][safi],
11988 PEER_CAP_ORF_PREFIX_SM_RCV)
11989 || CHECK_FLAG(p->af_cap[afi][safi],
11990 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11991 || CHECK_FLAG(p->af_cap[afi][safi],
11992 PEER_CAP_ORF_PREFIX_RM_ADV)
11993 || CHECK_FLAG(p->af_cap[afi][safi],
11994 PEER_CAP_ORF_PREFIX_RM_RCV)
11995 || CHECK_FLAG(p->af_cap[afi][safi],
11996 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11997 vty_out(vty, " AF-dependant capabilities:\n");
11998
11999 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12000 || CHECK_FLAG(p->af_cap[afi][safi],
12001 PEER_CAP_ORF_PREFIX_SM_RCV)
12002 || CHECK_FLAG(p->af_cap[afi][safi],
12003 PEER_CAP_ORF_PREFIX_RM_ADV)
12004 || CHECK_FLAG(p->af_cap[afi][safi],
12005 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12006 vty_out(vty,
12007 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12008 ORF_TYPE_PREFIX);
12009 bgp_show_peer_afi_orf_cap(
12010 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12011 PEER_CAP_ORF_PREFIX_RM_ADV,
12012 PEER_CAP_ORF_PREFIX_SM_RCV,
12013 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12014 }
12015 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12016 || CHECK_FLAG(p->af_cap[afi][safi],
12017 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12018 || CHECK_FLAG(p->af_cap[afi][safi],
12019 PEER_CAP_ORF_PREFIX_RM_ADV)
12020 || CHECK_FLAG(p->af_cap[afi][safi],
12021 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12022 vty_out(vty,
12023 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12024 ORF_TYPE_PREFIX_OLD);
12025 bgp_show_peer_afi_orf_cap(
12026 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12027 PEER_CAP_ORF_PREFIX_RM_ADV,
12028 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12029 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12030 }
12031
772270f3
QY
12032 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12033 p->host, afi, safi);
d62a17ae 12034 orf_pfx_count = prefix_bgp_show_prefix_list(
12035 NULL, afi, orf_pfx_name, use_json);
12036
12037 if (CHECK_FLAG(p->af_sflags[afi][safi],
12038 PEER_STATUS_ORF_PREFIX_SEND)
12039 || orf_pfx_count) {
12040 vty_out(vty, " Outbound Route Filter (ORF):");
12041 if (CHECK_FLAG(p->af_sflags[afi][safi],
12042 PEER_STATUS_ORF_PREFIX_SEND))
12043 vty_out(vty, " sent;");
12044 if (orf_pfx_count)
12045 vty_out(vty, " received (%d entries)",
12046 orf_pfx_count);
12047 vty_out(vty, "\n");
12048 }
12049 if (CHECK_FLAG(p->af_sflags[afi][safi],
12050 PEER_STATUS_ORF_WAIT_REFRESH))
12051 vty_out(vty,
12052 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12053
12054 if (CHECK_FLAG(p->af_flags[afi][safi],
12055 PEER_FLAG_REFLECTOR_CLIENT))
12056 vty_out(vty, " Route-Reflector Client\n");
12057 if (CHECK_FLAG(p->af_flags[afi][safi],
12058 PEER_FLAG_RSERVER_CLIENT))
12059 vty_out(vty, " Route-Server Client\n");
12060 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12061 vty_out(vty,
12062 " Inbound soft reconfiguration allowed\n");
12063
12064 if (CHECK_FLAG(p->af_flags[afi][safi],
12065 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12066 vty_out(vty,
12067 " Private AS numbers (all) replaced in updates to this neighbor\n");
12068 else if (CHECK_FLAG(p->af_flags[afi][safi],
12069 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12070 vty_out(vty,
12071 " Private AS numbers replaced in updates to this neighbor\n");
12072 else if (CHECK_FLAG(p->af_flags[afi][safi],
12073 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12074 vty_out(vty,
12075 " Private AS numbers (all) removed in updates to this neighbor\n");
12076 else if (CHECK_FLAG(p->af_flags[afi][safi],
12077 PEER_FLAG_REMOVE_PRIVATE_AS))
12078 vty_out(vty,
12079 " Private AS numbers removed in updates to this neighbor\n");
12080
dcc68b5e
MS
12081 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12082 vty_out(vty, " %s\n",
12083 bgp_addpath_names(p->addpath_type[afi][safi])
12084 ->human_description);
d62a17ae 12085
12086 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12087 vty_out(vty,
12088 " Override ASNs in outbound updates if aspath equals remote-as\n");
12089
12090 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12091 || CHECK_FLAG(p->af_flags[afi][safi],
12092 PEER_FLAG_FORCE_NEXTHOP_SELF))
12093 vty_out(vty, " NEXT_HOP is always this router\n");
12094 if (CHECK_FLAG(p->af_flags[afi][safi],
12095 PEER_FLAG_AS_PATH_UNCHANGED))
12096 vty_out(vty,
12097 " AS_PATH is propagated unchanged to this neighbor\n");
12098 if (CHECK_FLAG(p->af_flags[afi][safi],
12099 PEER_FLAG_NEXTHOP_UNCHANGED))
12100 vty_out(vty,
12101 " NEXT_HOP is propagated unchanged to this neighbor\n");
12102 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12103 vty_out(vty,
12104 " MED is propagated unchanged to this neighbor\n");
12105 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12106 || CHECK_FLAG(p->af_flags[afi][safi],
12107 PEER_FLAG_SEND_EXT_COMMUNITY)
12108 || CHECK_FLAG(p->af_flags[afi][safi],
12109 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12110 vty_out(vty,
12111 " Community attribute sent to this neighbor");
12112 if (CHECK_FLAG(p->af_flags[afi][safi],
12113 PEER_FLAG_SEND_COMMUNITY)
12114 && CHECK_FLAG(p->af_flags[afi][safi],
12115 PEER_FLAG_SEND_EXT_COMMUNITY)
12116 && CHECK_FLAG(p->af_flags[afi][safi],
12117 PEER_FLAG_SEND_LARGE_COMMUNITY))
12118 vty_out(vty, "(all)\n");
12119 else if (CHECK_FLAG(p->af_flags[afi][safi],
12120 PEER_FLAG_SEND_LARGE_COMMUNITY))
12121 vty_out(vty, "(large)\n");
12122 else if (CHECK_FLAG(p->af_flags[afi][safi],
12123 PEER_FLAG_SEND_EXT_COMMUNITY))
12124 vty_out(vty, "(extended)\n");
12125 else
12126 vty_out(vty, "(standard)\n");
12127 }
12128 if (CHECK_FLAG(p->af_flags[afi][safi],
12129 PEER_FLAG_DEFAULT_ORIGINATE)) {
12130 vty_out(vty, " Default information originate,");
12131
12132 if (p->default_rmap[afi][safi].name)
12133 vty_out(vty, " default route-map %s%s,",
12134 p->default_rmap[afi][safi].map ? "*"
12135 : "",
12136 p->default_rmap[afi][safi].name);
12137 if (paf && PAF_SUBGRP(paf)
12138 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12139 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12140 vty_out(vty, " default sent\n");
12141 else
12142 vty_out(vty, " default not sent\n");
12143 }
12144
dff8f48d
MK
12145 /* advertise-vni-all */
12146 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12147 if (is_evpn_enabled())
dff8f48d
MK
12148 vty_out(vty, " advertise-all-vni\n");
12149 }
12150
d62a17ae 12151 if (filter->plist[FILTER_IN].name
12152 || filter->dlist[FILTER_IN].name
12153 || filter->aslist[FILTER_IN].name
12154 || filter->map[RMAP_IN].name)
12155 vty_out(vty, " Inbound path policy configured\n");
12156 if (filter->plist[FILTER_OUT].name
12157 || filter->dlist[FILTER_OUT].name
12158 || filter->aslist[FILTER_OUT].name
12159 || filter->map[RMAP_OUT].name || filter->usmap.name)
12160 vty_out(vty, " Outbound path policy configured\n");
12161
12162 /* prefix-list */
12163 if (filter->plist[FILTER_IN].name)
12164 vty_out(vty,
12165 " Incoming update prefix filter list is %s%s\n",
12166 filter->plist[FILTER_IN].plist ? "*" : "",
12167 filter->plist[FILTER_IN].name);
12168 if (filter->plist[FILTER_OUT].name)
12169 vty_out(vty,
12170 " Outgoing update prefix filter list is %s%s\n",
12171 filter->plist[FILTER_OUT].plist ? "*" : "",
12172 filter->plist[FILTER_OUT].name);
12173
12174 /* distribute-list */
12175 if (filter->dlist[FILTER_IN].name)
12176 vty_out(vty,
12177 " Incoming update network filter list is %s%s\n",
12178 filter->dlist[FILTER_IN].alist ? "*" : "",
12179 filter->dlist[FILTER_IN].name);
12180 if (filter->dlist[FILTER_OUT].name)
12181 vty_out(vty,
12182 " Outgoing update network filter list is %s%s\n",
12183 filter->dlist[FILTER_OUT].alist ? "*" : "",
12184 filter->dlist[FILTER_OUT].name);
12185
12186 /* filter-list. */
12187 if (filter->aslist[FILTER_IN].name)
12188 vty_out(vty,
12189 " Incoming update AS path filter list is %s%s\n",
12190 filter->aslist[FILTER_IN].aslist ? "*" : "",
12191 filter->aslist[FILTER_IN].name);
12192 if (filter->aslist[FILTER_OUT].name)
12193 vty_out(vty,
12194 " Outgoing update AS path filter list is %s%s\n",
12195 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12196 filter->aslist[FILTER_OUT].name);
12197
12198 /* route-map. */
12199 if (filter->map[RMAP_IN].name)
12200 vty_out(vty,
12201 " Route map for incoming advertisements is %s%s\n",
12202 filter->map[RMAP_IN].map ? "*" : "",
12203 filter->map[RMAP_IN].name);
12204 if (filter->map[RMAP_OUT].name)
12205 vty_out(vty,
12206 " Route map for outgoing advertisements is %s%s\n",
12207 filter->map[RMAP_OUT].map ? "*" : "",
12208 filter->map[RMAP_OUT].name);
12209
9dac9fc8 12210 /* ebgp-requires-policy (inbound) */
1d3fdccf 12211 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12212 && !bgp_inbound_policy_exists(p, filter))
12213 vty_out(vty,
12214 " Inbound updates discarded due to missing policy\n");
12215
12216 /* ebgp-requires-policy (outbound) */
1d3fdccf 12217 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12218 && !bgp_outbound_policy_exists(p, filter))
12219 vty_out(vty,
12220 " Outbound updates discarded due to missing policy\n");
12221
d62a17ae 12222 /* unsuppress-map */
12223 if (filter->usmap.name)
12224 vty_out(vty,
12225 " Route map for selective unsuppress is %s%s\n",
12226 filter->usmap.map ? "*" : "",
12227 filter->usmap.name);
12228
7f7940e6
MK
12229 /* advertise-map */
12230 if (filter->advmap.aname && filter->advmap.cname)
12231 vty_out(vty,
12232 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12233 filter->advmap.condition ? "EXIST"
12234 : "NON_EXIST",
12235 filter->advmap.cmap ? "*" : "",
12236 filter->advmap.cname,
12237 filter->advmap.amap ? "*" : "",
12238 filter->advmap.aname,
fa36596c 12239 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12240 ? "Advertise"
12241 : "Withdraw");
7f7940e6 12242
d62a17ae 12243 /* Receive prefix count */
6cde4b45 12244 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12245 p->pcount[afi][safi]);
d62a17ae 12246
fde246e8
DA
12247 /* maximum-prefix-out */
12248 if (CHECK_FLAG(p->af_flags[afi][safi],
12249 PEER_FLAG_MAX_PREFIX_OUT))
12250 vty_out(vty,
6cde4b45 12251 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12252 p->pmax_out[afi][safi]);
12253
d62a17ae 12254 /* Maximum prefix */
12255 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12256 vty_out(vty,
6cde4b45 12257 " Maximum prefixes allowed %u%s\n",
d62a17ae 12258 p->pmax[afi][safi],
12259 CHECK_FLAG(p->af_flags[afi][safi],
12260 PEER_FLAG_MAX_PREFIX_WARNING)
12261 ? " (warning-only)"
12262 : "");
12263 vty_out(vty, " Threshold for warning message %d%%",
12264 p->pmax_threshold[afi][safi]);
12265 if (p->pmax_restart[afi][safi])
12266 vty_out(vty, ", restart interval %d min",
12267 p->pmax_restart[afi][safi]);
12268 vty_out(vty, "\n");
12269 }
12270
12271 vty_out(vty, "\n");
12272 }
12273}
12274
9f049418 12275static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12276 json_object *json)
718e3744 12277{
d62a17ae 12278 struct bgp *bgp;
12279 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12280 char timebuf[BGP_UPTIME_LEN];
12281 char dn_flag[2];
d62a17ae 12282 afi_t afi;
12283 safi_t safi;
d7c0a89a
QY
12284 uint16_t i;
12285 uint8_t *msg;
d62a17ae 12286 json_object *json_neigh = NULL;
12287 time_t epoch_tbuf;
718e3744 12288
d62a17ae 12289 bgp = p->bgp;
12290
12291 if (use_json)
12292 json_neigh = json_object_new_object();
12293
12294 memset(dn_flag, '\0', sizeof(dn_flag));
12295 if (!p->conf_if && peer_dynamic_neighbor(p))
12296 dn_flag[0] = '*';
12297
12298 if (!use_json) {
12299 if (p->conf_if) /* Configured interface name. */
12300 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12301 BGP_PEER_SU_UNSPEC(p)
12302 ? "None"
12303 : sockunion2str(&p->su, buf,
12304 SU_ADDRSTRLEN));
12305 else /* Configured IP address. */
12306 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12307 p->host);
12308 }
12309
12310 if (use_json) {
12311 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12312 json_object_string_add(json_neigh, "bgpNeighborAddr",
12313 "none");
12314 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12315 json_object_string_add(
12316 json_neigh, "bgpNeighborAddr",
12317 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12318
12319 json_object_int_add(json_neigh, "remoteAs", p->as);
12320
12321 if (p->change_local_as)
12322 json_object_int_add(json_neigh, "localAs",
12323 p->change_local_as);
12324 else
12325 json_object_int_add(json_neigh, "localAs", p->local_as);
12326
12327 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12328 json_object_boolean_true_add(json_neigh,
12329 "localAsNoPrepend");
12330
12331 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12332 json_object_boolean_true_add(json_neigh,
12333 "localAsReplaceAs");
12334 } else {
12335 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12336 || (p->as_type == AS_INTERNAL))
12337 vty_out(vty, "remote AS %u, ", p->as);
12338 else
12339 vty_out(vty, "remote AS Unspecified, ");
12340 vty_out(vty, "local AS %u%s%s, ",
12341 p->change_local_as ? p->change_local_as : p->local_as,
12342 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12343 ? " no-prepend"
12344 : "",
12345 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12346 ? " replace-as"
12347 : "");
12348 }
faa16034
DS
12349 /* peer type internal or confed-internal */
12350 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12351 if (use_json) {
12352 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12353 json_object_boolean_true_add(
12354 json_neigh, "nbrConfedInternalLink");
12355 else
12356 json_object_boolean_true_add(json_neigh,
12357 "nbrInternalLink");
12358 } else {
12359 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12360 vty_out(vty, "confed-internal link\n");
12361 else
12362 vty_out(vty, "internal link\n");
12363 }
faa16034
DS
12364 /* peer type external or confed-external */
12365 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12366 if (use_json) {
12367 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12368 json_object_boolean_true_add(
12369 json_neigh, "nbrConfedExternalLink");
12370 else
12371 json_object_boolean_true_add(json_neigh,
12372 "nbrExternalLink");
12373 } else {
12374 if (bgp_confederation_peers_check(bgp, p->as))
12375 vty_out(vty, "confed-external link\n");
12376 else
12377 vty_out(vty, "external link\n");
12378 }
faa16034
DS
12379 } else {
12380 if (use_json)
12381 json_object_boolean_true_add(json_neigh,
12382 "nbrUnspecifiedLink");
12383 else
12384 vty_out(vty, "unspecified link\n");
d62a17ae 12385 }
12386
12387 /* Description. */
12388 if (p->desc) {
12389 if (use_json)
12390 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12391 else
12392 vty_out(vty, " Description: %s\n", p->desc);
12393 }
12394
12395 if (p->hostname) {
12396 if (use_json) {
12397 if (p->hostname)
12398 json_object_string_add(json_neigh, "hostname",
12399 p->hostname);
12400
12401 if (p->domainname)
12402 json_object_string_add(json_neigh, "domainname",
12403 p->domainname);
12404 } else {
12405 if (p->domainname && (p->domainname[0] != '\0'))
12406 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12407 p->domainname);
12408 else
12409 vty_out(vty, "Hostname: %s\n", p->hostname);
12410 }
12411 }
12412
12413 /* Peer-group */
12414 if (p->group) {
12415 if (use_json) {
12416 json_object_string_add(json_neigh, "peerGroup",
12417 p->group->name);
12418
12419 if (dn_flag[0]) {
12420 struct prefix prefix, *range = NULL;
12421
12422 sockunion2hostprefix(&(p->su), &prefix);
12423 range = peer_group_lookup_dynamic_neighbor_range(
12424 p->group, &prefix);
12425
12426 if (range) {
12427 prefix2str(range, buf1, sizeof(buf1));
12428 json_object_string_add(
12429 json_neigh,
12430 "peerSubnetRangeGroup", buf1);
12431 }
12432 }
12433 } else {
12434 vty_out(vty,
12435 " Member of peer-group %s for session parameters\n",
12436 p->group->name);
12437
12438 if (dn_flag[0]) {
12439 struct prefix prefix, *range = NULL;
12440
12441 sockunion2hostprefix(&(p->su), &prefix);
12442 range = peer_group_lookup_dynamic_neighbor_range(
12443 p->group, &prefix);
12444
12445 if (range) {
d62a17ae 12446 vty_out(vty,
1b78780b
DL
12447 " Belongs to the subnet range group: %pFX\n",
12448 range);
d62a17ae 12449 }
12450 }
12451 }
12452 }
12453
12454 if (use_json) {
12455 /* Administrative shutdown. */
cb9196e7
DS
12456 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12457 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12458 json_object_boolean_true_add(json_neigh,
12459 "adminShutDown");
12460
12461 /* BGP Version. */
12462 json_object_int_add(json_neigh, "bgpVersion", 4);
12463 json_object_string_add(
12464 json_neigh, "remoteRouterId",
12465 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
12466 json_object_string_add(
12467 json_neigh, "localRouterId",
12468 inet_ntop(AF_INET, &bgp->router_id, buf1,
12469 sizeof(buf1)));
d62a17ae 12470
12471 /* Confederation */
12472 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12473 && bgp_confederation_peers_check(bgp, p->as))
12474 json_object_boolean_true_add(json_neigh,
12475 "nbrCommonAdmin");
12476
12477 /* Status. */
12478 json_object_string_add(
12479 json_neigh, "bgpState",
12480 lookup_msg(bgp_status_msg, p->status, NULL));
12481
12482 if (p->status == Established) {
12483 time_t uptime;
d62a17ae 12484
12485 uptime = bgp_clock();
12486 uptime -= p->uptime;
d62a17ae 12487 epoch_tbuf = time(NULL) - uptime;
12488
d3c7efed
DS
12489 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12490 uptime * 1000);
d62a17ae 12491 json_object_string_add(json_neigh, "bgpTimerUpString",
12492 peer_uptime(p->uptime, timebuf,
12493 BGP_UPTIME_LEN, 0,
12494 NULL));
12495 json_object_int_add(json_neigh,
12496 "bgpTimerUpEstablishedEpoch",
12497 epoch_tbuf);
12498 }
12499
12500 else if (p->status == Active) {
12501 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12502 json_object_string_add(json_neigh, "bgpStateIs",
12503 "passive");
12504 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12505 json_object_string_add(json_neigh, "bgpStateIs",
12506 "passiveNSF");
12507 }
12508
12509 /* read timer */
12510 time_t uptime;
a2700b50 12511 struct tm tm;
d62a17ae 12512
12513 uptime = bgp_clock();
12514 uptime -= p->readtime;
a2700b50
MS
12515 gmtime_r(&uptime, &tm);
12516
d62a17ae 12517 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12518 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12519 + (tm.tm_hour * 3600000));
d62a17ae 12520
12521 uptime = bgp_clock();
12522 uptime -= p->last_write;
a2700b50
MS
12523 gmtime_r(&uptime, &tm);
12524
d62a17ae 12525 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12526 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12527 + (tm.tm_hour * 3600000));
d62a17ae 12528
12529 uptime = bgp_clock();
12530 uptime -= p->update_time;
a2700b50
MS
12531 gmtime_r(&uptime, &tm);
12532
d62a17ae 12533 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12534 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12535 + (tm.tm_hour * 3600000));
d62a17ae 12536
12537 /* Configured timer values. */
12538 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12539 p->v_holdtime * 1000);
12540 json_object_int_add(json_neigh,
12541 "bgpTimerKeepAliveIntervalMsecs",
12542 p->v_keepalive * 1000);
b90a8e13 12543 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12544 json_object_int_add(json_neigh,
12545 "bgpTimerConfiguredHoldTimeMsecs",
12546 p->holdtime * 1000);
12547 json_object_int_add(
12548 json_neigh,
12549 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12550 p->keepalive * 1000);
5d5393b9
DL
12551 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12552 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12553 json_object_int_add(json_neigh,
12554 "bgpTimerConfiguredHoldTimeMsecs",
12555 bgp->default_holdtime);
12556 json_object_int_add(
12557 json_neigh,
12558 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12559 bgp->default_keepalive);
d62a17ae 12560 }
12561 } else {
12562 /* Administrative shutdown. */
cb9196e7
DS
12563 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12564 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12565 vty_out(vty, " Administratively shut down\n");
12566
12567 /* BGP Version. */
12568 vty_out(vty, " BGP version 4");
0e38aeb4 12569 vty_out(vty, ", remote router ID %s",
d62a17ae 12570 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12571 vty_out(vty, ", local router ID %s\n",
12572 inet_ntop(AF_INET, &bgp->router_id, buf1,
12573 sizeof(buf1)));
d62a17ae 12574
12575 /* Confederation */
12576 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12577 && bgp_confederation_peers_check(bgp, p->as))
12578 vty_out(vty,
12579 " Neighbor under common administration\n");
12580
12581 /* Status. */
12582 vty_out(vty, " BGP state = %s",
12583 lookup_msg(bgp_status_msg, p->status, NULL));
12584
12585 if (p->status == Established)
12586 vty_out(vty, ", up for %8s",
12587 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12588 0, NULL));
12589
12590 else if (p->status == Active) {
12591 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12592 vty_out(vty, " (passive)");
12593 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12594 vty_out(vty, " (NSF passive)");
12595 }
12596 vty_out(vty, "\n");
12597
12598 /* read timer */
12599 vty_out(vty, " Last read %s",
12600 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12601 NULL));
12602 vty_out(vty, ", Last write %s\n",
12603 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12604 NULL));
12605
12606 /* Configured timer values. */
12607 vty_out(vty,
12608 " Hold time is %d, keepalive interval is %d seconds\n",
12609 p->v_holdtime, p->v_keepalive);
b90a8e13 12610 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12611 vty_out(vty, " Configured hold time is %d",
12612 p->holdtime);
12613 vty_out(vty, ", keepalive interval is %d seconds\n",
12614 p->keepalive);
5d5393b9
DL
12615 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12616 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12617 vty_out(vty, " Configured hold time is %d",
12618 bgp->default_holdtime);
12619 vty_out(vty, ", keepalive interval is %d seconds\n",
12620 bgp->default_keepalive);
d62a17ae 12621 }
12622 }
12623 /* Capability. */
12624 if (p->status == Established) {
12625 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12626 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12627 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12628 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12629 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12630 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12631 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12632 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12633 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12634 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12635 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12636 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 12637 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12638 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 12639 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12640 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 12641 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12642 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 12643 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12644 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12645 if (use_json) {
12646 json_object *json_cap = NULL;
12647
12648 json_cap = json_object_new_object();
12649
12650 /* AS4 */
12651 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12652 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12653 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12654 && CHECK_FLAG(p->cap,
12655 PEER_CAP_AS4_RCV))
12656 json_object_string_add(
12657 json_cap, "4byteAs",
12658 "advertisedAndReceived");
12659 else if (CHECK_FLAG(p->cap,
12660 PEER_CAP_AS4_ADV))
12661 json_object_string_add(
12662 json_cap, "4byteAs",
12663 "advertised");
12664 else if (CHECK_FLAG(p->cap,
12665 PEER_CAP_AS4_RCV))
12666 json_object_string_add(
12667 json_cap, "4byteAs",
12668 "received");
12669 }
12670
12671 /* AddPath */
12672 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12673 || CHECK_FLAG(p->cap,
12674 PEER_CAP_ADDPATH_ADV)) {
12675 json_object *json_add = NULL;
12676 const char *print_store;
12677
12678 json_add = json_object_new_object();
12679
05c7a1cc
QY
12680 FOREACH_AFI_SAFI (afi, safi) {
12681 json_object *json_sub = NULL;
12682 json_sub =
12683 json_object_new_object();
5cb5f4d0
DD
12684 print_store = get_afi_safi_str(
12685 afi, safi, true);
d62a17ae 12686
05c7a1cc
QY
12687 if (CHECK_FLAG(
12688 p->af_cap[afi]
12689 [safi],
12690 PEER_CAP_ADDPATH_AF_TX_ADV)
12691 || CHECK_FLAG(
12692 p->af_cap[afi]
12693 [safi],
12694 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 12695 if (CHECK_FLAG(
12696 p->af_cap
12697 [afi]
12698 [safi],
12699 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 12700 && CHECK_FLAG(
d62a17ae 12701 p->af_cap
12702 [afi]
12703 [safi],
05c7a1cc
QY
12704 PEER_CAP_ADDPATH_AF_TX_RCV))
12705 json_object_boolean_true_add(
12706 json_sub,
12707 "txAdvertisedAndReceived");
12708 else if (
12709 CHECK_FLAG(
12710 p->af_cap
12711 [afi]
12712 [safi],
12713 PEER_CAP_ADDPATH_AF_TX_ADV))
12714 json_object_boolean_true_add(
12715 json_sub,
12716 "txAdvertised");
12717 else if (
12718 CHECK_FLAG(
12719 p->af_cap
12720 [afi]
12721 [safi],
12722 PEER_CAP_ADDPATH_AF_TX_RCV))
12723 json_object_boolean_true_add(
12724 json_sub,
12725 "txReceived");
12726 }
d62a17ae 12727
05c7a1cc
QY
12728 if (CHECK_FLAG(
12729 p->af_cap[afi]
12730 [safi],
12731 PEER_CAP_ADDPATH_AF_RX_ADV)
12732 || CHECK_FLAG(
12733 p->af_cap[afi]
12734 [safi],
12735 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 12736 if (CHECK_FLAG(
12737 p->af_cap
12738 [afi]
12739 [safi],
12740 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 12741 && CHECK_FLAG(
d62a17ae 12742 p->af_cap
12743 [afi]
12744 [safi],
12745 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
12746 json_object_boolean_true_add(
12747 json_sub,
12748 "rxAdvertisedAndReceived");
12749 else if (
12750 CHECK_FLAG(
12751 p->af_cap
12752 [afi]
12753 [safi],
12754 PEER_CAP_ADDPATH_AF_RX_ADV))
12755 json_object_boolean_true_add(
12756 json_sub,
12757 "rxAdvertised");
12758 else if (
12759 CHECK_FLAG(
12760 p->af_cap
12761 [afi]
12762 [safi],
12763 PEER_CAP_ADDPATH_AF_RX_RCV))
12764 json_object_boolean_true_add(
12765 json_sub,
12766 "rxReceived");
d62a17ae 12767 }
12768
05c7a1cc
QY
12769 if (CHECK_FLAG(
12770 p->af_cap[afi]
12771 [safi],
12772 PEER_CAP_ADDPATH_AF_TX_ADV)
12773 || CHECK_FLAG(
12774 p->af_cap[afi]
12775 [safi],
12776 PEER_CAP_ADDPATH_AF_TX_RCV)
12777 || CHECK_FLAG(
12778 p->af_cap[afi]
12779 [safi],
12780 PEER_CAP_ADDPATH_AF_RX_ADV)
12781 || CHECK_FLAG(
12782 p->af_cap[afi]
12783 [safi],
12784 PEER_CAP_ADDPATH_AF_RX_RCV))
12785 json_object_object_add(
12786 json_add,
12787 print_store,
12788 json_sub);
12789 else
12790 json_object_free(
12791 json_sub);
12792 }
12793
d62a17ae 12794 json_object_object_add(
12795 json_cap, "addPath", json_add);
12796 }
12797
12798 /* Dynamic */
12799 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12800 || CHECK_FLAG(p->cap,
12801 PEER_CAP_DYNAMIC_ADV)) {
12802 if (CHECK_FLAG(p->cap,
12803 PEER_CAP_DYNAMIC_ADV)
12804 && CHECK_FLAG(p->cap,
12805 PEER_CAP_DYNAMIC_RCV))
12806 json_object_string_add(
12807 json_cap, "dynamic",
12808 "advertisedAndReceived");
12809 else if (CHECK_FLAG(
12810 p->cap,
12811 PEER_CAP_DYNAMIC_ADV))
12812 json_object_string_add(
12813 json_cap, "dynamic",
12814 "advertised");
12815 else if (CHECK_FLAG(
12816 p->cap,
12817 PEER_CAP_DYNAMIC_RCV))
12818 json_object_string_add(
12819 json_cap, "dynamic",
12820 "received");
12821 }
12822
12823 /* Extended nexthop */
12824 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12825 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12826 json_object *json_nxt = NULL;
12827 const char *print_store;
12828
12829
12830 if (CHECK_FLAG(p->cap,
12831 PEER_CAP_ENHE_ADV)
12832 && CHECK_FLAG(p->cap,
12833 PEER_CAP_ENHE_RCV))
12834 json_object_string_add(
12835 json_cap,
12836 "extendedNexthop",
12837 "advertisedAndReceived");
12838 else if (CHECK_FLAG(p->cap,
12839 PEER_CAP_ENHE_ADV))
12840 json_object_string_add(
12841 json_cap,
12842 "extendedNexthop",
12843 "advertised");
12844 else if (CHECK_FLAG(p->cap,
12845 PEER_CAP_ENHE_RCV))
12846 json_object_string_add(
12847 json_cap,
12848 "extendedNexthop",
12849 "received");
12850
12851 if (CHECK_FLAG(p->cap,
12852 PEER_CAP_ENHE_RCV)) {
12853 json_nxt =
12854 json_object_new_object();
12855
12856 for (safi = SAFI_UNICAST;
12857 safi < SAFI_MAX; safi++) {
12858 if (CHECK_FLAG(
12859 p->af_cap
12860 [AFI_IP]
12861 [safi],
12862 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 12863 print_store = get_afi_safi_str(
d62a17ae 12864 AFI_IP,
5cb5f4d0 12865 safi, true);
d62a17ae 12866 json_object_string_add(
12867 json_nxt,
12868 print_store,
54f29523 12869 "recieved"); /* misspelled for compatibility */
d62a17ae 12870 }
12871 }
12872 json_object_object_add(
12873 json_cap,
12874 "extendedNexthopFamililesByPeer",
12875 json_nxt);
12876 }
12877 }
12878
12879 /* Route Refresh */
12880 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12881 || CHECK_FLAG(p->cap,
12882 PEER_CAP_REFRESH_NEW_RCV)
12883 || CHECK_FLAG(p->cap,
12884 PEER_CAP_REFRESH_OLD_RCV)) {
12885 if (CHECK_FLAG(p->cap,
12886 PEER_CAP_REFRESH_ADV)
12887 && (CHECK_FLAG(
12888 p->cap,
12889 PEER_CAP_REFRESH_NEW_RCV)
12890 || CHECK_FLAG(
12891 p->cap,
12892 PEER_CAP_REFRESH_OLD_RCV))) {
12893 if (CHECK_FLAG(
12894 p->cap,
12895 PEER_CAP_REFRESH_OLD_RCV)
12896 && CHECK_FLAG(
12897 p->cap,
12898 PEER_CAP_REFRESH_NEW_RCV))
12899 json_object_string_add(
12900 json_cap,
12901 "routeRefresh",
12902 "advertisedAndReceivedOldNew");
12903 else {
12904 if (CHECK_FLAG(
12905 p->cap,
12906 PEER_CAP_REFRESH_OLD_RCV))
12907 json_object_string_add(
12908 json_cap,
12909 "routeRefresh",
12910 "advertisedAndReceivedOld");
12911 else
12912 json_object_string_add(
12913 json_cap,
12914 "routeRefresh",
12915 "advertisedAndReceivedNew");
12916 }
12917 } else if (
12918 CHECK_FLAG(
12919 p->cap,
12920 PEER_CAP_REFRESH_ADV))
12921 json_object_string_add(
12922 json_cap,
12923 "routeRefresh",
12924 "advertised");
12925 else if (
12926 CHECK_FLAG(
12927 p->cap,
12928 PEER_CAP_REFRESH_NEW_RCV)
12929 || CHECK_FLAG(
12930 p->cap,
12931 PEER_CAP_REFRESH_OLD_RCV))
12932 json_object_string_add(
12933 json_cap,
12934 "routeRefresh",
12935 "received");
12936 }
12937
12938 /* Multiprotocol Extensions */
12939 json_object *json_multi = NULL;
12940 json_multi = json_object_new_object();
12941
05c7a1cc
QY
12942 FOREACH_AFI_SAFI (afi, safi) {
12943 if (p->afc_adv[afi][safi]
12944 || p->afc_recv[afi][safi]) {
12945 json_object *json_exten = NULL;
12946 json_exten =
12947 json_object_new_object();
12948
d62a17ae 12949 if (p->afc_adv[afi][safi]
05c7a1cc
QY
12950 && p->afc_recv[afi][safi])
12951 json_object_boolean_true_add(
12952 json_exten,
12953 "advertisedAndReceived");
12954 else if (p->afc_adv[afi][safi])
12955 json_object_boolean_true_add(
12956 json_exten,
12957 "advertised");
12958 else if (p->afc_recv[afi][safi])
12959 json_object_boolean_true_add(
12960 json_exten,
12961 "received");
d62a17ae 12962
05c7a1cc
QY
12963 json_object_object_add(
12964 json_multi,
5cb5f4d0
DD
12965 get_afi_safi_str(afi,
12966 safi,
12967 true),
05c7a1cc 12968 json_exten);
d62a17ae 12969 }
12970 }
12971 json_object_object_add(
12972 json_cap, "multiprotocolExtensions",
12973 json_multi);
12974
d77114b7 12975 /* Hostname capabilities */
60466a63 12976 json_object *json_hname = NULL;
d77114b7
MK
12977
12978 json_hname = json_object_new_object();
12979
12980 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12981 json_object_string_add(
60466a63
QY
12982 json_hname, "advHostName",
12983 bgp->peer_self->hostname
12984 ? bgp->peer_self
12985 ->hostname
d77114b7
MK
12986 : "n/a");
12987 json_object_string_add(
60466a63
QY
12988 json_hname, "advDomainName",
12989 bgp->peer_self->domainname
12990 ? bgp->peer_self
12991 ->domainname
d77114b7
MK
12992 : "n/a");
12993 }
12994
12995
12996 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12997 json_object_string_add(
60466a63
QY
12998 json_hname, "rcvHostName",
12999 p->hostname ? p->hostname
13000 : "n/a");
d77114b7 13001 json_object_string_add(
60466a63
QY
13002 json_hname, "rcvDomainName",
13003 p->domainname ? p->domainname
13004 : "n/a");
d77114b7
MK
13005 }
13006
60466a63 13007 json_object_object_add(json_cap, "hostName",
d77114b7
MK
13008 json_hname);
13009
d62a17ae 13010 /* Gracefull Restart */
13011 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13012 || CHECK_FLAG(p->cap,
13013 PEER_CAP_RESTART_ADV)) {
13014 if (CHECK_FLAG(p->cap,
13015 PEER_CAP_RESTART_ADV)
13016 && CHECK_FLAG(p->cap,
13017 PEER_CAP_RESTART_RCV))
13018 json_object_string_add(
13019 json_cap,
13020 "gracefulRestart",
13021 "advertisedAndReceived");
13022 else if (CHECK_FLAG(
13023 p->cap,
13024 PEER_CAP_RESTART_ADV))
13025 json_object_string_add(
13026 json_cap,
13027 "gracefulRestartCapability",
13028 "advertised");
13029 else if (CHECK_FLAG(
13030 p->cap,
13031 PEER_CAP_RESTART_RCV))
13032 json_object_string_add(
13033 json_cap,
13034 "gracefulRestartCapability",
13035 "received");
13036
13037 if (CHECK_FLAG(p->cap,
13038 PEER_CAP_RESTART_RCV)) {
13039 int restart_af_count = 0;
13040 json_object *json_restart =
13041 NULL;
13042 json_restart =
13043 json_object_new_object();
13044
13045 json_object_int_add(
13046 json_cap,
13047 "gracefulRestartRemoteTimerMsecs",
13048 p->v_gr_restart * 1000);
13049
05c7a1cc
QY
13050 FOREACH_AFI_SAFI (afi, safi) {
13051 if (CHECK_FLAG(
13052 p->af_cap
13053 [afi]
13054 [safi],
13055 PEER_CAP_RESTART_AF_RCV)) {
13056 json_object *
13057 json_sub =
13058 NULL;
13059 json_sub =
13060 json_object_new_object();
13061
d62a17ae 13062 if (CHECK_FLAG(
13063 p->af_cap
13064 [afi]
13065 [safi],
05c7a1cc
QY
13066 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13067 json_object_boolean_true_add(
13068 json_sub,
13069 "preserved");
13070 restart_af_count++;
13071 json_object_object_add(
13072 json_restart,
5cb5f4d0 13073 get_afi_safi_str(
05c7a1cc 13074 afi,
5cb5f4d0
DD
13075 safi,
13076 true),
05c7a1cc 13077 json_sub);
d62a17ae 13078 }
13079 }
13080 if (!restart_af_count) {
13081 json_object_string_add(
13082 json_cap,
13083 "addressFamiliesByPeer",
13084 "none");
13085 json_object_free(
13086 json_restart);
13087 } else
13088 json_object_object_add(
13089 json_cap,
13090 "addressFamiliesByPeer",
13091 json_restart);
13092 }
13093 }
13094 json_object_object_add(json_neigh,
13095 "neighborCapabilities",
13096 json_cap);
13097 } else {
13098 vty_out(vty, " Neighbor capabilities:\n");
13099
13100 /* AS4 */
13101 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13102 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13103 vty_out(vty, " 4 Byte AS:");
13104 if (CHECK_FLAG(p->cap,
13105 PEER_CAP_AS4_ADV))
13106 vty_out(vty, " advertised");
13107 if (CHECK_FLAG(p->cap,
13108 PEER_CAP_AS4_RCV))
13109 vty_out(vty, " %sreceived",
13110 CHECK_FLAG(
13111 p->cap,
13112 PEER_CAP_AS4_ADV)
13113 ? "and "
13114 : "");
13115 vty_out(vty, "\n");
13116 }
13117
13118 /* AddPath */
13119 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13120 || CHECK_FLAG(p->cap,
13121 PEER_CAP_ADDPATH_ADV)) {
13122 vty_out(vty, " AddPath:\n");
13123
05c7a1cc
QY
13124 FOREACH_AFI_SAFI (afi, safi) {
13125 if (CHECK_FLAG(
13126 p->af_cap[afi]
13127 [safi],
13128 PEER_CAP_ADDPATH_AF_TX_ADV)
13129 || CHECK_FLAG(
13130 p->af_cap[afi]
13131 [safi],
13132 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13133 vty_out(vty,
13134 " %s: TX ",
5cb5f4d0 13135 get_afi_safi_str(
05c7a1cc 13136 afi,
5cb5f4d0
DD
13137 safi,
13138 false));
05c7a1cc 13139
d62a17ae 13140 if (CHECK_FLAG(
13141 p->af_cap
13142 [afi]
13143 [safi],
05c7a1cc 13144 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 13145 vty_out(vty,
05c7a1cc 13146 "advertised %s",
5cb5f4d0 13147 get_afi_safi_str(
d62a17ae 13148 afi,
5cb5f4d0
DD
13149 safi,
13150 false));
d62a17ae 13151
05c7a1cc
QY
13152 if (CHECK_FLAG(
13153 p->af_cap
13154 [afi]
13155 [safi],
13156 PEER_CAP_ADDPATH_AF_TX_RCV))
13157 vty_out(vty,
13158 "%sreceived",
13159 CHECK_FLAG(
13160 p->af_cap
13161 [afi]
13162 [safi],
13163 PEER_CAP_ADDPATH_AF_TX_ADV)
13164 ? " and "
13165 : "");
d62a17ae 13166
05c7a1cc
QY
13167 vty_out(vty, "\n");
13168 }
d62a17ae 13169
05c7a1cc
QY
13170 if (CHECK_FLAG(
13171 p->af_cap[afi]
13172 [safi],
13173 PEER_CAP_ADDPATH_AF_RX_ADV)
13174 || CHECK_FLAG(
13175 p->af_cap[afi]
13176 [safi],
13177 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13178 vty_out(vty,
13179 " %s: RX ",
5cb5f4d0 13180 get_afi_safi_str(
05c7a1cc 13181 afi,
5cb5f4d0
DD
13182 safi,
13183 false));
d62a17ae 13184
13185 if (CHECK_FLAG(
13186 p->af_cap
13187 [afi]
13188 [safi],
05c7a1cc 13189 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 13190 vty_out(vty,
05c7a1cc 13191 "advertised %s",
5cb5f4d0 13192 get_afi_safi_str(
d62a17ae 13193 afi,
5cb5f4d0
DD
13194 safi,
13195 false));
d62a17ae 13196
05c7a1cc
QY
13197 if (CHECK_FLAG(
13198 p->af_cap
13199 [afi]
13200 [safi],
13201 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 13202 vty_out(vty,
05c7a1cc
QY
13203 "%sreceived",
13204 CHECK_FLAG(
13205 p->af_cap
13206 [afi]
13207 [safi],
13208 PEER_CAP_ADDPATH_AF_RX_ADV)
13209 ? " and "
13210 : "");
13211
13212 vty_out(vty, "\n");
d62a17ae 13213 }
05c7a1cc 13214 }
d62a17ae 13215 }
13216
13217 /* Dynamic */
13218 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13219 || CHECK_FLAG(p->cap,
13220 PEER_CAP_DYNAMIC_ADV)) {
13221 vty_out(vty, " Dynamic:");
13222 if (CHECK_FLAG(p->cap,
13223 PEER_CAP_DYNAMIC_ADV))
13224 vty_out(vty, " advertised");
13225 if (CHECK_FLAG(p->cap,
13226 PEER_CAP_DYNAMIC_RCV))
13227 vty_out(vty, " %sreceived",
13228 CHECK_FLAG(
13229 p->cap,
13230 PEER_CAP_DYNAMIC_ADV)
13231 ? "and "
13232 : "");
13233 vty_out(vty, "\n");
13234 }
13235
13236 /* Extended nexthop */
13237 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13238 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13239 vty_out(vty, " Extended nexthop:");
13240 if (CHECK_FLAG(p->cap,
13241 PEER_CAP_ENHE_ADV))
13242 vty_out(vty, " advertised");
13243 if (CHECK_FLAG(p->cap,
13244 PEER_CAP_ENHE_RCV))
13245 vty_out(vty, " %sreceived",
13246 CHECK_FLAG(
13247 p->cap,
13248 PEER_CAP_ENHE_ADV)
13249 ? "and "
13250 : "");
13251 vty_out(vty, "\n");
13252
13253 if (CHECK_FLAG(p->cap,
13254 PEER_CAP_ENHE_RCV)) {
13255 vty_out(vty,
13256 " Address families by peer:\n ");
13257 for (safi = SAFI_UNICAST;
13258 safi < SAFI_MAX; safi++)
13259 if (CHECK_FLAG(
13260 p->af_cap
13261 [AFI_IP]
13262 [safi],
13263 PEER_CAP_ENHE_AF_RCV))
13264 vty_out(vty,
13265 " %s\n",
5cb5f4d0 13266 get_afi_safi_str(
d62a17ae 13267 AFI_IP,
5cb5f4d0
DD
13268 safi,
13269 false));
d62a17ae 13270 }
13271 }
13272
13273 /* Route Refresh */
13274 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13275 || CHECK_FLAG(p->cap,
13276 PEER_CAP_REFRESH_NEW_RCV)
13277 || CHECK_FLAG(p->cap,
13278 PEER_CAP_REFRESH_OLD_RCV)) {
13279 vty_out(vty, " Route refresh:");
13280 if (CHECK_FLAG(p->cap,
13281 PEER_CAP_REFRESH_ADV))
13282 vty_out(vty, " advertised");
13283 if (CHECK_FLAG(p->cap,
13284 PEER_CAP_REFRESH_NEW_RCV)
13285 || CHECK_FLAG(
13286 p->cap,
13287 PEER_CAP_REFRESH_OLD_RCV))
13288 vty_out(vty, " %sreceived(%s)",
13289 CHECK_FLAG(
13290 p->cap,
13291 PEER_CAP_REFRESH_ADV)
13292 ? "and "
13293 : "",
13294 (CHECK_FLAG(
13295 p->cap,
13296 PEER_CAP_REFRESH_OLD_RCV)
13297 && CHECK_FLAG(
13298 p->cap,
13299 PEER_CAP_REFRESH_NEW_RCV))
13300 ? "old & new"
13301 : CHECK_FLAG(
13302 p->cap,
13303 PEER_CAP_REFRESH_OLD_RCV)
13304 ? "old"
13305 : "new");
13306
13307 vty_out(vty, "\n");
13308 }
13309
13310 /* Multiprotocol Extensions */
05c7a1cc
QY
13311 FOREACH_AFI_SAFI (afi, safi)
13312 if (p->afc_adv[afi][safi]
13313 || p->afc_recv[afi][safi]) {
13314 vty_out(vty,
13315 " Address Family %s:",
5cb5f4d0
DD
13316 get_afi_safi_str(
13317 afi,
13318 safi,
13319 false));
05c7a1cc 13320 if (p->afc_adv[afi][safi])
d62a17ae 13321 vty_out(vty,
05c7a1cc
QY
13322 " advertised");
13323 if (p->afc_recv[afi][safi])
13324 vty_out(vty,
13325 " %sreceived",
13326 p->afc_adv[afi]
13327 [safi]
13328 ? "and "
13329 : "");
13330 vty_out(vty, "\n");
13331 }
d62a17ae 13332
13333 /* Hostname capability */
60466a63 13334 vty_out(vty, " Hostname Capability:");
d77114b7
MK
13335
13336 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
13337 vty_out(vty,
13338 " advertised (name: %s,domain name: %s)",
60466a63
QY
13339 bgp->peer_self->hostname
13340 ? bgp->peer_self
13341 ->hostname
d77114b7 13342 : "n/a",
60466a63
QY
13343 bgp->peer_self->domainname
13344 ? bgp->peer_self
13345 ->domainname
d77114b7
MK
13346 : "n/a");
13347 } else {
13348 vty_out(vty, " not advertised");
d62a17ae 13349 }
13350
d77114b7 13351 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
13352 vty_out(vty,
13353 " received (name: %s,domain name: %s)",
60466a63
QY
13354 p->hostname ? p->hostname
13355 : "n/a",
13356 p->domainname ? p->domainname
13357 : "n/a");
d77114b7
MK
13358 } else {
13359 vty_out(vty, " not received");
13360 }
13361
13362 vty_out(vty, "\n");
13363
61bfbd51 13364 /* Graceful Restart */
d62a17ae 13365 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13366 || CHECK_FLAG(p->cap,
13367 PEER_CAP_RESTART_ADV)) {
13368 vty_out(vty,
61bfbd51 13369 " Graceful Restart Capability:");
d62a17ae 13370 if (CHECK_FLAG(p->cap,
13371 PEER_CAP_RESTART_ADV))
13372 vty_out(vty, " advertised");
13373 if (CHECK_FLAG(p->cap,
13374 PEER_CAP_RESTART_RCV))
13375 vty_out(vty, " %sreceived",
13376 CHECK_FLAG(
13377 p->cap,
13378 PEER_CAP_RESTART_ADV)
13379 ? "and "
13380 : "");
13381 vty_out(vty, "\n");
13382
13383 if (CHECK_FLAG(p->cap,
13384 PEER_CAP_RESTART_RCV)) {
13385 int restart_af_count = 0;
13386
13387 vty_out(vty,
13388 " Remote Restart timer is %d seconds\n",
13389 p->v_gr_restart);
13390 vty_out(vty,
13391 " Address families by peer:\n ");
13392
05c7a1cc
QY
13393 FOREACH_AFI_SAFI (afi, safi)
13394 if (CHECK_FLAG(
13395 p->af_cap
13396 [afi]
13397 [safi],
13398 PEER_CAP_RESTART_AF_RCV)) {
13399 vty_out(vty,
13400 "%s%s(%s)",
13401 restart_af_count
13402 ? ", "
13403 : "",
5cb5f4d0 13404 get_afi_safi_str(
05c7a1cc 13405 afi,
5cb5f4d0
DD
13406 safi,
13407 false),
05c7a1cc
QY
13408 CHECK_FLAG(
13409 p->af_cap
13410 [afi]
13411 [safi],
13412 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13413 ? "preserved"
13414 : "not preserved");
13415 restart_af_count++;
13416 }
d62a17ae 13417 if (!restart_af_count)
13418 vty_out(vty, "none");
13419 vty_out(vty, "\n");
13420 }
2986cac2 13421 } /* Gracefull Restart */
d62a17ae 13422 }
13423 }
13424 }
13425
13426 /* graceful restart information */
d62a17ae 13427 json_object *json_grace = NULL;
13428 json_object *json_grace_send = NULL;
13429 json_object *json_grace_recv = NULL;
13430 int eor_send_af_count = 0;
13431 int eor_receive_af_count = 0;
13432
13433 if (use_json) {
13434 json_grace = json_object_new_object();
13435 json_grace_send = json_object_new_object();
13436 json_grace_recv = json_object_new_object();
13437
36235319
QY
13438 if ((p->status == Established)
13439 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
13440 FOREACH_AFI_SAFI (afi, safi) {
13441 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 13442 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
13443 json_object_boolean_true_add(
13444 json_grace_send,
5cb5f4d0
DD
13445 get_afi_safi_str(afi,
13446 safi,
13447 true));
05c7a1cc 13448 eor_send_af_count++;
d62a17ae 13449 }
13450 }
05c7a1cc
QY
13451 FOREACH_AFI_SAFI (afi, safi) {
13452 if (CHECK_FLAG(
36235319
QY
13453 p->af_sflags[afi][safi],
13454 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
13455 json_object_boolean_true_add(
13456 json_grace_recv,
5cb5f4d0
DD
13457 get_afi_safi_str(afi,
13458 safi,
13459 true));
05c7a1cc 13460 eor_receive_af_count++;
d62a17ae 13461 }
13462 }
13463 }
36235319
QY
13464 json_object_object_add(json_grace, "endOfRibSend",
13465 json_grace_send);
13466 json_object_object_add(json_grace, "endOfRibRecv",
13467 json_grace_recv);
d62a17ae 13468
d62a17ae 13469
13470 if (p->t_gr_restart)
13471 json_object_int_add(json_grace,
13472 "gracefulRestartTimerMsecs",
13473 thread_timer_remain_second(
13474 p->t_gr_restart)
13475 * 1000);
13476
13477 if (p->t_gr_stale)
13478 json_object_int_add(
13479 json_grace,
13480 "gracefulStalepathTimerMsecs",
13481 thread_timer_remain_second(
13482 p->t_gr_stale)
13483 * 1000);
2986cac2 13484 /* more gr info in new format */
13485 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 13486 json_grace);
d62a17ae 13487 json_object_object_add(
13488 json_neigh, "gracefulRestartInfo", json_grace);
13489 } else {
2089dd80 13490 vty_out(vty, " Graceful restart information:\n");
36235319
QY
13491 if ((p->status == Established)
13492 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 13493
d62a17ae 13494 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
13495 FOREACH_AFI_SAFI (afi, safi) {
13496 if (CHECK_FLAG(p->af_sflags[afi][safi],
13497 PEER_STATUS_EOR_SEND)) {
13498 vty_out(vty, "%s%s",
13499 eor_send_af_count ? ", "
13500 : "",
36235319
QY
13501 get_afi_safi_str(
13502 afi, safi,
13503 false));
05c7a1cc 13504 eor_send_af_count++;
d62a17ae 13505 }
13506 }
13507 vty_out(vty, "\n");
13508 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
13509 FOREACH_AFI_SAFI (afi, safi) {
13510 if (CHECK_FLAG(
13511 p->af_sflags[afi][safi],
13512 PEER_STATUS_EOR_RECEIVED)) {
13513 vty_out(vty, "%s%s",
13514 eor_receive_af_count
13515 ? ", "
13516 : "",
5cb5f4d0
DD
13517 get_afi_safi_str(afi,
13518 safi,
13519 false));
05c7a1cc 13520 eor_receive_af_count++;
d62a17ae 13521 }
13522 }
13523 vty_out(vty, "\n");
13524 }
13525
13526 if (p->t_gr_restart)
13527 vty_out(vty,
13528 " The remaining time of restart timer is %ld\n",
13529 thread_timer_remain_second(
13530 p->t_gr_restart));
13531
13532 if (p->t_gr_stale)
13533 vty_out(vty,
13534 " The remaining time of stalepath timer is %ld\n",
13535 thread_timer_remain_second(
13536 p->t_gr_stale));
2986cac2 13537
13538 /* more gr info in new format */
13539 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 13540 }
2986cac2 13541
d62a17ae 13542 if (use_json) {
13543 json_object *json_stat = NULL;
13544 json_stat = json_object_new_object();
13545 /* Packet counts. */
43aa5965
QY
13546
13547 atomic_size_t outq_count, inq_count;
13548 outq_count = atomic_load_explicit(&p->obuf->count,
13549 memory_order_relaxed);
13550 inq_count = atomic_load_explicit(&p->ibuf->count,
13551 memory_order_relaxed);
13552
13553 json_object_int_add(json_stat, "depthInq",
13554 (unsigned long)inq_count);
d62a17ae 13555 json_object_int_add(json_stat, "depthOutq",
43aa5965 13556 (unsigned long)outq_count);
0112e9e0
QY
13557 json_object_int_add(json_stat, "opensSent",
13558 atomic_load_explicit(&p->open_out,
13559 memory_order_relaxed));
13560 json_object_int_add(json_stat, "opensRecv",
13561 atomic_load_explicit(&p->open_in,
13562 memory_order_relaxed));
d62a17ae 13563 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13564 atomic_load_explicit(&p->notify_out,
13565 memory_order_relaxed));
d62a17ae 13566 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13567 atomic_load_explicit(&p->notify_in,
13568 memory_order_relaxed));
13569 json_object_int_add(json_stat, "updatesSent",
13570 atomic_load_explicit(&p->update_out,
13571 memory_order_relaxed));
13572 json_object_int_add(json_stat, "updatesRecv",
13573 atomic_load_explicit(&p->update_in,
13574 memory_order_relaxed));
d62a17ae 13575 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13576 atomic_load_explicit(&p->keepalive_out,
13577 memory_order_relaxed));
d62a17ae 13578 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13579 atomic_load_explicit(&p->keepalive_in,
13580 memory_order_relaxed));
d62a17ae 13581 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13582 atomic_load_explicit(&p->refresh_out,
13583 memory_order_relaxed));
d62a17ae 13584 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13585 atomic_load_explicit(&p->refresh_in,
13586 memory_order_relaxed));
d62a17ae 13587 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13588 atomic_load_explicit(&p->dynamic_cap_out,
13589 memory_order_relaxed));
d62a17ae 13590 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13591 atomic_load_explicit(&p->dynamic_cap_in,
13592 memory_order_relaxed));
13593 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13594 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13595 json_object_object_add(json_neigh, "messageStats", json_stat);
13596 } else {
43aa5965
QY
13597 atomic_size_t outq_count, inq_count;
13598 outq_count = atomic_load_explicit(&p->obuf->count,
13599 memory_order_relaxed);
13600 inq_count = atomic_load_explicit(&p->ibuf->count,
13601 memory_order_relaxed);
13602
d62a17ae 13603 /* Packet counts. */
13604 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13605 vty_out(vty, " Inq depth is %zu\n", inq_count);
13606 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13607 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
13608 vty_out(vty, " Opens: %10d %10d\n",
13609 atomic_load_explicit(&p->open_out,
13610 memory_order_relaxed),
13611 atomic_load_explicit(&p->open_in,
13612 memory_order_relaxed));
13613 vty_out(vty, " Notifications: %10d %10d\n",
13614 atomic_load_explicit(&p->notify_out,
13615 memory_order_relaxed),
13616 atomic_load_explicit(&p->notify_in,
13617 memory_order_relaxed));
13618 vty_out(vty, " Updates: %10d %10d\n",
13619 atomic_load_explicit(&p->update_out,
13620 memory_order_relaxed),
13621 atomic_load_explicit(&p->update_in,
13622 memory_order_relaxed));
13623 vty_out(vty, " Keepalives: %10d %10d\n",
13624 atomic_load_explicit(&p->keepalive_out,
13625 memory_order_relaxed),
13626 atomic_load_explicit(&p->keepalive_in,
13627 memory_order_relaxed));
13628 vty_out(vty, " Route Refresh: %10d %10d\n",
13629 atomic_load_explicit(&p->refresh_out,
13630 memory_order_relaxed),
13631 atomic_load_explicit(&p->refresh_in,
13632 memory_order_relaxed));
d62a17ae 13633 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
13634 atomic_load_explicit(&p->dynamic_cap_out,
13635 memory_order_relaxed),
13636 atomic_load_explicit(&p->dynamic_cap_in,
13637 memory_order_relaxed));
13638 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13639 PEER_TOTAL_RX(p));
d62a17ae 13640 }
13641
13642 if (use_json) {
13643 /* advertisement-interval */
13644 json_object_int_add(json_neigh,
13645 "minBtwnAdvertisementRunsTimerMsecs",
13646 p->v_routeadv * 1000);
13647
13648 /* Update-source. */
13649 if (p->update_if || p->update_source) {
13650 if (p->update_if)
13651 json_object_string_add(json_neigh,
13652 "updateSource",
13653 p->update_if);
13654 else if (p->update_source)
13655 json_object_string_add(
13656 json_neigh, "updateSource",
13657 sockunion2str(p->update_source, buf1,
13658 SU_ADDRSTRLEN));
13659 }
13660 } else {
13661 /* advertisement-interval */
13662 vty_out(vty,
13663 " Minimum time between advertisement runs is %d seconds\n",
13664 p->v_routeadv);
13665
13666 /* Update-source. */
13667 if (p->update_if || p->update_source) {
13668 vty_out(vty, " Update source is ");
13669 if (p->update_if)
13670 vty_out(vty, "%s", p->update_if);
13671 else if (p->update_source)
13672 vty_out(vty, "%s",
13673 sockunion2str(p->update_source, buf1,
13674 SU_ADDRSTRLEN));
13675 vty_out(vty, "\n");
13676 }
13677
13678 vty_out(vty, "\n");
13679 }
13680
13681 /* Address Family Information */
13682 json_object *json_hold = NULL;
13683
13684 if (use_json)
13685 json_hold = json_object_new_object();
13686
05c7a1cc
QY
13687 FOREACH_AFI_SAFI (afi, safi)
13688 if (p->afc[afi][safi])
13689 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13690 json_hold);
d62a17ae 13691
13692 if (use_json) {
13693 json_object_object_add(json_neigh, "addressFamilyInfo",
13694 json_hold);
13695 json_object_int_add(json_neigh, "connectionsEstablished",
13696 p->established);
13697 json_object_int_add(json_neigh, "connectionsDropped",
13698 p->dropped);
13699 } else
13700 vty_out(vty, " Connections established %d; dropped %d\n",
13701 p->established, p->dropped);
13702
13703 if (!p->last_reset) {
13704 if (use_json)
13705 json_object_string_add(json_neigh, "lastReset",
13706 "never");
13707 else
13708 vty_out(vty, " Last reset never\n");
13709 } else {
13710 if (use_json) {
13711 time_t uptime;
a2700b50 13712 struct tm tm;
d62a17ae 13713
13714 uptime = bgp_clock();
13715 uptime -= p->resettime;
a2700b50
MS
13716 gmtime_r(&uptime, &tm);
13717
d62a17ae 13718 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13719 (tm.tm_sec * 1000)
13720 + (tm.tm_min * 60000)
13721 + (tm.tm_hour * 3600000));
3577f1c5 13722 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13723 } else {
13724 vty_out(vty, " Last reset %s, ",
13725 peer_uptime(p->resettime, timebuf,
13726 BGP_UPTIME_LEN, 0, NULL));
13727
3577f1c5 13728 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13729 if (p->last_reset_cause_size) {
13730 msg = p->last_reset_cause;
13731 vty_out(vty,
13732 " Message received that caused BGP to send a NOTIFICATION:\n ");
13733 for (i = 1; i <= p->last_reset_cause_size;
13734 i++) {
13735 vty_out(vty, "%02X", *msg++);
13736
13737 if (i != p->last_reset_cause_size) {
13738 if (i % 16 == 0) {
13739 vty_out(vty, "\n ");
13740 } else if (i % 4 == 0) {
13741 vty_out(vty, " ");
13742 }
13743 }
13744 }
13745 vty_out(vty, "\n");
13746 }
13747 }
13748 }
13749
13750 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13751 if (use_json)
13752 json_object_boolean_true_add(json_neigh,
13753 "prefixesConfigExceedMax");
13754 else
13755 vty_out(vty,
13756 " Peer had exceeded the max. no. of prefixes configured.\n");
13757
13758 if (p->t_pmax_restart) {
13759 if (use_json) {
13760 json_object_boolean_true_add(
13761 json_neigh, "reducePrefixNumFrom");
13762 json_object_int_add(json_neigh,
13763 "restartInTimerMsec",
13764 thread_timer_remain_second(
13765 p->t_pmax_restart)
13766 * 1000);
13767 } else
13768 vty_out(vty,
13769 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13770 p->host, thread_timer_remain_second(
13771 p->t_pmax_restart));
d62a17ae 13772 } else {
13773 if (use_json)
13774 json_object_boolean_true_add(
13775 json_neigh,
13776 "reducePrefixNumAndClearIpBgp");
13777 else
13778 vty_out(vty,
13779 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13780 p->host);
13781 }
13782 }
13783
13784 /* EBGP Multihop and GTSM */
13785 if (p->sort != BGP_PEER_IBGP) {
13786 if (use_json) {
e2521429 13787 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13788 json_object_int_add(json_neigh,
13789 "externalBgpNbrMaxHopsAway",
13790 p->gtsm_hops);
c8d6f0d6 13791 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13792 json_object_int_add(json_neigh,
13793 "externalBgpNbrMaxHopsAway",
13794 p->ttl);
13795 } else {
e2521429 13796 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13797 vty_out(vty,
13798 " External BGP neighbor may be up to %d hops away.\n",
13799 p->gtsm_hops);
c8d6f0d6 13800 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13801 vty_out(vty,
13802 " External BGP neighbor may be up to %d hops away.\n",
13803 p->ttl);
13804 }
13805 } else {
e2521429 13806 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13807 if (use_json)
13808 json_object_int_add(json_neigh,
13809 "internalBgpNbrMaxHopsAway",
13810 p->gtsm_hops);
13811 else
13812 vty_out(vty,
13813 " Internal BGP neighbor may be up to %d hops away.\n",
13814 p->gtsm_hops);
13815 }
13816 }
13817
13818 /* Local address. */
13819 if (p->su_local) {
13820 if (use_json) {
13821 json_object_string_add(json_neigh, "hostLocal",
13822 sockunion2str(p->su_local, buf1,
13823 SU_ADDRSTRLEN));
13824 json_object_int_add(json_neigh, "portLocal",
13825 ntohs(p->su_local->sin.sin_port));
13826 } else
13827 vty_out(vty, "Local host: %s, Local port: %d\n",
13828 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13829 ntohs(p->su_local->sin.sin_port));
13830 }
13831
13832 /* Remote address. */
13833 if (p->su_remote) {
13834 if (use_json) {
13835 json_object_string_add(json_neigh, "hostForeign",
13836 sockunion2str(p->su_remote, buf1,
13837 SU_ADDRSTRLEN));
13838 json_object_int_add(json_neigh, "portForeign",
13839 ntohs(p->su_remote->sin.sin_port));
13840 } else
13841 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13842 sockunion2str(p->su_remote, buf1,
13843 SU_ADDRSTRLEN),
13844 ntohs(p->su_remote->sin.sin_port));
13845 }
13846
13847 /* Nexthop display. */
13848 if (p->su_local) {
13849 if (use_json) {
13850 json_object_string_add(json_neigh, "nexthop",
13851 inet_ntop(AF_INET,
13852 &p->nexthop.v4, buf1,
13853 sizeof(buf1)));
13854 json_object_string_add(json_neigh, "nexthopGlobal",
13855 inet_ntop(AF_INET6,
13856 &p->nexthop.v6_global,
13857 buf1, sizeof(buf1)));
13858 json_object_string_add(json_neigh, "nexthopLocal",
13859 inet_ntop(AF_INET6,
13860 &p->nexthop.v6_local,
13861 buf1, sizeof(buf1)));
13862 if (p->shared_network)
13863 json_object_string_add(json_neigh,
13864 "bgpConnection",
13865 "sharedNetwork");
13866 else
13867 json_object_string_add(json_neigh,
13868 "bgpConnection",
13869 "nonSharedNetwork");
13870 } else {
13871 vty_out(vty, "Nexthop: %s\n",
13872 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13873 sizeof(buf1)));
13874 vty_out(vty, "Nexthop global: %s\n",
13875 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13876 sizeof(buf1)));
13877 vty_out(vty, "Nexthop local: %s\n",
13878 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13879 sizeof(buf1)));
13880 vty_out(vty, "BGP connection: %s\n",
13881 p->shared_network ? "shared network"
13882 : "non shared network");
13883 }
13884 }
13885
13886 /* Timer information. */
13887 if (use_json) {
13888 json_object_int_add(json_neigh, "connectRetryTimer",
13889 p->v_connect);
13890 if (p->status == Established && p->rtt)
13891 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13892 p->rtt);
13893 if (p->t_start)
13894 json_object_int_add(
13895 json_neigh, "nextStartTimerDueInMsecs",
13896 thread_timer_remain_second(p->t_start) * 1000);
13897 if (p->t_connect)
13898 json_object_int_add(
13899 json_neigh, "nextConnectTimerDueInMsecs",
13900 thread_timer_remain_second(p->t_connect)
13901 * 1000);
13902 if (p->t_routeadv) {
13903 json_object_int_add(json_neigh, "mraiInterval",
13904 p->v_routeadv);
13905 json_object_int_add(
13906 json_neigh, "mraiTimerExpireInMsecs",
13907 thread_timer_remain_second(p->t_routeadv)
13908 * 1000);
13909 }
13910 if (p->password)
13911 json_object_int_add(json_neigh, "authenticationEnabled",
13912 1);
13913
13914 if (p->t_read)
13915 json_object_string_add(json_neigh, "readThread", "on");
13916 else
13917 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
13918
13919 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 13920 json_object_string_add(json_neigh, "writeThread", "on");
13921 else
13922 json_object_string_add(json_neigh, "writeThread",
13923 "off");
13924 } else {
13925 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13926 p->v_connect);
13927 if (p->status == Established && p->rtt)
13928 vty_out(vty, "Estimated round trip time: %d ms\n",
13929 p->rtt);
13930 if (p->t_start)
13931 vty_out(vty, "Next start timer due in %ld seconds\n",
13932 thread_timer_remain_second(p->t_start));
13933 if (p->t_connect)
13934 vty_out(vty, "Next connect timer due in %ld seconds\n",
13935 thread_timer_remain_second(p->t_connect));
13936 if (p->t_routeadv)
13937 vty_out(vty,
13938 "MRAI (interval %u) timer expires in %ld seconds\n",
13939 p->v_routeadv,
13940 thread_timer_remain_second(p->t_routeadv));
13941 if (p->password)
13942 vty_out(vty, "Peer Authentication Enabled\n");
13943
cac9e917 13944 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
13945 p->t_read ? "on" : "off",
13946 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13947 ? "on"
cac9e917 13948 : "off", p->fd);
d62a17ae 13949 }
13950
13951 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13952 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13953 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13954
13955 if (!use_json)
13956 vty_out(vty, "\n");
13957
13958 /* BFD information. */
13959 bgp_bfd_show_info(vty, p, use_json, json_neigh);
13960
13961 if (use_json) {
13962 if (p->conf_if) /* Configured interface name. */
13963 json_object_object_add(json, p->conf_if, json_neigh);
13964 else /* Configured IP address. */
13965 json_object_object_add(json, p->host, json_neigh);
13966 }
13967}
13968
36235319
QY
13969static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13970 enum show_type type,
13971 union sockunion *su,
13972 const char *conf_if, afi_t afi,
74a630b6 13973 bool use_json)
2986cac2 13974{
13975 struct listnode *node, *nnode;
13976 struct peer *peer;
13977 int find = 0;
13978 safi_t safi = SAFI_UNICAST;
74a630b6 13979 json_object *json = NULL;
2986cac2 13980 json_object *json_neighbor = NULL;
13981
74a630b6
NT
13982 if (use_json) {
13983 json = json_object_new_object();
13984 json_neighbor = json_object_new_object();
13985 }
13986
2986cac2 13987 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13988
13989 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13990 continue;
13991
13992 if ((peer->afc[afi][safi]) == 0)
13993 continue;
13994
2ba1fe69 13995 if (type == show_all) {
2986cac2 13996 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 13997 json_neighbor);
2986cac2 13998
74a630b6 13999 if (use_json) {
13909c4f
DS
14000 json_object_object_add(json, peer->host,
14001 json_neighbor);
74a630b6
NT
14002 json_neighbor = NULL;
14003 }
2986cac2 14004
2ba1fe69 14005 } else if (type == show_peer) {
2986cac2 14006 if (conf_if) {
14007 if ((peer->conf_if
13909c4f
DS
14008 && !strcmp(peer->conf_if, conf_if))
14009 || (peer->hostname
2986cac2 14010 && !strcmp(peer->hostname, conf_if))) {
14011 find = 1;
13909c4f
DS
14012 bgp_show_peer_gr_status(vty, peer,
14013 use_json,
14014 json_neighbor);
2986cac2 14015 }
14016 } else {
14017 if (sockunion_same(&peer->su, su)) {
14018 find = 1;
13909c4f
DS
14019 bgp_show_peer_gr_status(vty, peer,
14020 use_json,
14021 json_neighbor);
2986cac2 14022 }
14023 }
13909c4f
DS
14024 if (use_json && find)
14025 json_object_object_add(json, peer->host,
14026 json_neighbor);
2986cac2 14027 }
14028
74a630b6
NT
14029 if (find) {
14030 json_neighbor = NULL;
2986cac2 14031 break;
74a630b6 14032 }
2986cac2 14033 }
14034
14035 if (type == show_peer && !find) {
14036 if (use_json)
13909c4f 14037 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14038 else
14039 vty_out(vty, "%% No such neighbor\n");
14040 }
14041 if (use_json) {
13909c4f
DS
14042 vty_out(vty, "%s\n",
14043 json_object_to_json_string_ext(
14044 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
14045
14046 if (json_neighbor)
14047 json_object_free(json_neighbor);
14048 json_object_free(json);
2986cac2 14049 } else {
14050 vty_out(vty, "\n");
14051 }
14052
14053 return CMD_SUCCESS;
14054}
14055
d62a17ae 14056static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14057 enum show_type type, union sockunion *su,
9f049418 14058 const char *conf_if, bool use_json,
d62a17ae 14059 json_object *json)
14060{
14061 struct listnode *node, *nnode;
14062 struct peer *peer;
14063 int find = 0;
9f049418 14064 bool nbr_output = false;
d1927ebe
AS
14065 afi_t afi = AFI_MAX;
14066 safi_t safi = SAFI_MAX;
14067
14068 if (type == show_ipv4_peer || type == show_ipv4_all) {
14069 afi = AFI_IP;
14070 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14071 afi = AFI_IP6;
14072 }
d62a17ae 14073
14074 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14075 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14076 continue;
14077
14078 switch (type) {
14079 case show_all:
14080 bgp_show_peer(vty, peer, use_json, json);
9f049418 14081 nbr_output = true;
d62a17ae 14082 break;
14083 case show_peer:
14084 if (conf_if) {
14085 if ((peer->conf_if
14086 && !strcmp(peer->conf_if, conf_if))
14087 || (peer->hostname
14088 && !strcmp(peer->hostname, conf_if))) {
14089 find = 1;
14090 bgp_show_peer(vty, peer, use_json,
14091 json);
14092 }
14093 } else {
14094 if (sockunion_same(&peer->su, su)) {
14095 find = 1;
14096 bgp_show_peer(vty, peer, use_json,
14097 json);
14098 }
14099 }
14100 break;
d1927ebe
AS
14101 case show_ipv4_peer:
14102 case show_ipv6_peer:
14103 FOREACH_SAFI (safi) {
14104 if (peer->afc[afi][safi]) {
14105 if (conf_if) {
14106 if ((peer->conf_if
14107 && !strcmp(peer->conf_if, conf_if))
14108 || (peer->hostname
14109 && !strcmp(peer->hostname, conf_if))) {
14110 find = 1;
14111 bgp_show_peer(vty, peer, use_json,
14112 json);
14113 break;
14114 }
14115 } else {
14116 if (sockunion_same(&peer->su, su)) {
14117 find = 1;
14118 bgp_show_peer(vty, peer, use_json,
14119 json);
14120 break;
14121 }
14122 }
14123 }
14124 }
14125 break;
14126 case show_ipv4_all:
14127 case show_ipv6_all:
14128 FOREACH_SAFI (safi) {
14129 if (peer->afc[afi][safi]) {
14130 bgp_show_peer(vty, peer, use_json, json);
14131 nbr_output = true;
14132 break;
14133 }
14134 }
14135 break;
d62a17ae 14136 }
14137 }
14138
d1927ebe
AS
14139 if ((type == show_peer || type == show_ipv4_peer ||
14140 type == show_ipv6_peer) && !find) {
d62a17ae 14141 if (use_json)
14142 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14143 else
88b7d255 14144 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14145 }
14146
d1927ebe
AS
14147 if (type != show_peer && type != show_ipv4_peer &&
14148 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14149 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14150
d62a17ae 14151 if (use_json) {
996c9314
LB
14152 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14153 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14154 } else {
14155 vty_out(vty, "\n");
14156 }
14157
14158 return CMD_SUCCESS;
14159}
14160
36235319
QY
14161static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14162 enum show_type type,
14163 const char *ip_str,
14164 afi_t afi, bool use_json)
2986cac2 14165{
14166
14167 int ret;
14168 struct bgp *bgp;
14169 union sockunion su;
2986cac2 14170
14171 bgp = bgp_get_default();
14172
13909c4f
DS
14173 if (!bgp)
14174 return;
2986cac2 14175
13909c4f
DS
14176 if (!use_json)
14177 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14178 NULL);
2986cac2 14179
13909c4f
DS
14180 if (ip_str) {
14181 ret = str2sockunion(ip_str, &su);
14182 if (ret < 0)
13909c4f 14183 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14184 vty, bgp, type, NULL, ip_str, afi, use_json);
14185 else
14186 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14187 NULL, afi, use_json);
13909c4f
DS
14188 } else
14189 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14190 afi, use_json);
2986cac2 14191}
14192
d62a17ae 14193static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14194 enum show_type type,
14195 const char *ip_str,
9f049418 14196 bool use_json)
d62a17ae 14197{
0291c246
MK
14198 struct listnode *node, *nnode;
14199 struct bgp *bgp;
71aedaa3 14200 union sockunion su;
0291c246 14201 json_object *json = NULL;
71aedaa3 14202 int ret, is_first = 1;
9f049418 14203 bool nbr_output = false;
d62a17ae 14204
14205 if (use_json)
14206 vty_out(vty, "{\n");
14207
14208 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14209 nbr_output = true;
d62a17ae 14210 if (use_json) {
14211 if (!(json = json_object_new_object())) {
af4c2728 14212 flog_err(
e50f7cfd 14213 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14214 "Unable to allocate memory for JSON object");
14215 vty_out(vty,
14216 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14217 return;
14218 }
14219
14220 json_object_int_add(json, "vrfId",
14221 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14222 ? -1
14223 : (int64_t)bgp->vrf_id);
d62a17ae 14224 json_object_string_add(
14225 json, "vrfName",
14226 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14227 ? VRF_DEFAULT_NAME
d62a17ae 14228 : bgp->name);
14229
14230 if (!is_first)
14231 vty_out(vty, ",\n");
14232 else
14233 is_first = 0;
14234
14235 vty_out(vty, "\"%s\":",
14236 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14237 ? VRF_DEFAULT_NAME
d62a17ae 14238 : bgp->name);
14239 } else {
14240 vty_out(vty, "\nInstance %s:\n",
14241 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14242 ? VRF_DEFAULT_NAME
d62a17ae 14243 : bgp->name);
14244 }
71aedaa3 14245
d1927ebe
AS
14246 if (type == show_peer || type == show_ipv4_peer ||
14247 type == show_ipv6_peer) {
71aedaa3
DS
14248 ret = str2sockunion(ip_str, &su);
14249 if (ret < 0)
14250 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14251 use_json, json);
14252 else
14253 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14254 use_json, json);
14255 } else {
d1927ebe 14256 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14257 use_json, json);
14258 }
b77004d6 14259 json_object_free(json);
121067e9 14260 json = NULL;
d62a17ae 14261 }
14262
3e78a6ce 14263 if (use_json)
d62a17ae 14264 vty_out(vty, "}\n");
9f049418
DS
14265 else if (!nbr_output)
14266 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14267}
14268
14269static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14270 enum show_type type, const char *ip_str,
9f049418 14271 bool use_json)
d62a17ae 14272{
14273 int ret;
14274 struct bgp *bgp;
14275 union sockunion su;
14276 json_object *json = NULL;
14277
14278 if (name) {
14279 if (strmatch(name, "all")) {
71aedaa3
DS
14280 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14281 use_json);
d62a17ae 14282 return CMD_SUCCESS;
14283 } else {
14284 bgp = bgp_lookup_by_name(name);
14285 if (!bgp) {
14286 if (use_json) {
14287 json = json_object_new_object();
d62a17ae 14288 vty_out(vty, "%s\n",
14289 json_object_to_json_string_ext(
14290 json,
14291 JSON_C_TO_STRING_PRETTY));
14292 json_object_free(json);
14293 } else
14294 vty_out(vty,
9f049418 14295 "%% BGP instance not found\n");
d62a17ae 14296
14297 return CMD_WARNING;
14298 }
14299 }
14300 } else {
14301 bgp = bgp_get_default();
14302 }
14303
14304 if (bgp) {
14305 json = json_object_new_object();
14306 if (ip_str) {
14307 ret = str2sockunion(ip_str, &su);
14308 if (ret < 0)
14309 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14310 use_json, json);
14311 else
14312 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14313 use_json, json);
14314 } else {
14315 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14316 json);
14317 }
14318 json_object_free(json);
ca61fd25
DS
14319 } else {
14320 if (use_json)
14321 vty_out(vty, "{}\n");
14322 else
14323 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14324 }
14325
14326 return CMD_SUCCESS;
4fb25c53
DW
14327}
14328
2986cac2 14329
14330
14331/* "show [ip] bgp neighbors graceful-restart" commands. */
14332DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14333 show_ip_bgp_neighbors_graceful_restart_cmd,
14334 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14335 SHOW_STR
14336 BGP_STR
14337 IP_STR
14338 IPV6_STR
14339 NEIGHBOR_STR
14340 "Neighbor to display information about\n"
14341 "Neighbor to display information about\n"
14342 "Neighbor on BGP configured interface\n"
14343 GR_SHOW
14344 JSON_STR)
14345{
14346 char *sh_arg = NULL;
14347 enum show_type sh_type;
14348 int idx = 0;
14349 afi_t afi = AFI_MAX;
2986cac2 14350 bool uj = use_json(argc, argv);
14351
36235319 14352 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14353 afi = AFI_MAX;
14354
14355 idx++;
14356
14357 if (argv_find(argv, argc, "A.B.C.D", &idx)
14358 || argv_find(argv, argc, "X:X::X:X", &idx)
14359 || argv_find(argv, argc, "WORD", &idx)) {
14360 sh_type = show_peer;
14361 sh_arg = argv[idx]->arg;
14362 } else
14363 sh_type = show_all;
14364
14365 if (!argv_find(argv, argc, "graceful-restart", &idx))
14366 return CMD_SUCCESS;
14367
14368
36235319
QY
14369 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14370 afi, uj);
2986cac2 14371}
14372
716b2d8a 14373/* "show [ip] bgp neighbors" commands. */
718e3744 14374DEFUN (show_ip_bgp_neighbors,
14375 show_ip_bgp_neighbors_cmd,
24345e82 14376 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14377 SHOW_STR
14378 IP_STR
14379 BGP_STR
f2a8972b 14380 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14381 "Address Family\n"
14382 "Address Family\n"
718e3744 14383 "Detailed information on TCP and BGP neighbor connections\n"
14384 "Neighbor to display information about\n"
a80beece 14385 "Neighbor to display information about\n"
91d37724 14386 "Neighbor on BGP configured interface\n"
9973d184 14387 JSON_STR)
718e3744 14388{
d62a17ae 14389 char *vrf = NULL;
14390 char *sh_arg = NULL;
14391 enum show_type sh_type;
d1927ebe 14392 afi_t afi = AFI_MAX;
718e3744 14393
9f049418 14394 bool uj = use_json(argc, argv);
718e3744 14395
d62a17ae 14396 int idx = 0;
718e3744 14397
9a8bdf1c
PG
14398 /* [<vrf> VIEWVRFNAME] */
14399 if (argv_find(argv, argc, "vrf", &idx)) {
14400 vrf = argv[idx + 1]->arg;
14401 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14402 vrf = NULL;
14403 } else if (argv_find(argv, argc, "view", &idx))
14404 /* [<view> VIEWVRFNAME] */
d62a17ae 14405 vrf = argv[idx + 1]->arg;
718e3744 14406
d62a17ae 14407 idx++;
d1927ebe
AS
14408
14409 if (argv_find(argv, argc, "ipv4", &idx)) {
14410 sh_type = show_ipv4_all;
14411 afi = AFI_IP;
14412 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14413 sh_type = show_ipv6_all;
14414 afi = AFI_IP6;
14415 } else {
14416 sh_type = show_all;
14417 }
14418
d62a17ae 14419 if (argv_find(argv, argc, "A.B.C.D", &idx)
14420 || argv_find(argv, argc, "X:X::X:X", &idx)
14421 || argv_find(argv, argc, "WORD", &idx)) {
14422 sh_type = show_peer;
14423 sh_arg = argv[idx]->arg;
d1927ebe
AS
14424 }
14425
14426 if (sh_type == show_peer && afi == AFI_IP) {
14427 sh_type = show_ipv4_peer;
14428 } else if (sh_type == show_peer && afi == AFI_IP6) {
14429 sh_type = show_ipv6_peer;
14430 }
856ca177 14431
d62a17ae 14432 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14433}
14434
716b2d8a 14435/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14436 paths' and `show ip mbgp paths'. Those functions results are the
14437 same.*/
f412b39a 14438DEFUN (show_ip_bgp_paths,
718e3744 14439 show_ip_bgp_paths_cmd,
46f296b4 14440 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14441 SHOW_STR
14442 IP_STR
14443 BGP_STR
46f296b4 14444 BGP_SAFI_HELP_STR
718e3744 14445 "Path information\n")
14446{
d62a17ae 14447 vty_out(vty, "Address Refcnt Path\n");
14448 aspath_print_all_vty(vty);
14449 return CMD_SUCCESS;
718e3744 14450}
14451
718e3744 14452#include "hash.h"
14453
e3b78da8 14454static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14455 struct vty *vty)
718e3744 14456{
d62a17ae 14457 struct community *com;
718e3744 14458
e3b78da8 14459 com = (struct community *)bucket->data;
3f65c5b1 14460 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14461 community_str(com, false));
718e3744 14462}
14463
14464/* Show BGP's community internal data. */
f412b39a 14465DEFUN (show_ip_bgp_community_info,
718e3744 14466 show_ip_bgp_community_info_cmd,
bec37ba5 14467 "show [ip] bgp community-info",
718e3744 14468 SHOW_STR
14469 IP_STR
14470 BGP_STR
14471 "List all bgp community information\n")
14472{
d62a17ae 14473 vty_out(vty, "Address Refcnt Community\n");
718e3744 14474
d62a17ae 14475 hash_iterate(community_hash(),
e3b78da8 14476 (void (*)(struct hash_bucket *,
d62a17ae 14477 void *))community_show_all_iterator,
14478 vty);
718e3744 14479
d62a17ae 14480 return CMD_SUCCESS;
718e3744 14481}
14482
e3b78da8 14483static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14484 struct vty *vty)
57d187bc 14485{
d62a17ae 14486 struct lcommunity *lcom;
57d187bc 14487
e3b78da8 14488 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14489 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14490 lcommunity_str(lcom, false));
57d187bc
JS
14491}
14492
14493/* Show BGP's community internal data. */
14494DEFUN (show_ip_bgp_lcommunity_info,
14495 show_ip_bgp_lcommunity_info_cmd,
14496 "show ip bgp large-community-info",
14497 SHOW_STR
14498 IP_STR
14499 BGP_STR
14500 "List all bgp large-community information\n")
14501{
d62a17ae 14502 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14503
d62a17ae 14504 hash_iterate(lcommunity_hash(),
e3b78da8 14505 (void (*)(struct hash_bucket *,
d62a17ae 14506 void *))lcommunity_show_all_iterator,
14507 vty);
57d187bc 14508
d62a17ae 14509 return CMD_SUCCESS;
57d187bc 14510}
2986cac2 14511/* Graceful Restart */
14512
14513static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14514 struct bgp *bgp,
14515 bool use_json,
14516 json_object *json)
2986cac2 14517{
57d187bc
JS
14518
14519
2986cac2 14520 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14521
7318ae88 14522 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14523
14524 switch (bgp_global_gr_mode) {
14525
14526 case GLOBAL_HELPER:
13909c4f 14527 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14528 break;
14529
14530 case GLOBAL_GR:
13909c4f 14531 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14532 break;
14533
14534 case GLOBAL_DISABLE:
13909c4f 14535 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14536 break;
14537
14538 case GLOBAL_INVALID:
2986cac2 14539 vty_out(vty,
2ba1fe69 14540 "Global BGP GR Mode Invalid\n");
2986cac2 14541 break;
14542 }
14543 vty_out(vty, "\n");
14544}
14545
36235319
QY
14546static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14547 enum show_type type,
14548 const char *ip_str,
14549 afi_t afi, bool use_json)
2986cac2 14550{
14551 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14552 afi = AFI_IP;
14553
14554 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14555
36235319
QY
14556 bgp_show_neighbor_graceful_restart_vty(
14557 vty, type, ip_str, afi, use_json);
2986cac2 14558 afi++;
14559 }
14560 } else if (afi != AFI_MAX) {
36235319
QY
14561 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14562 use_json);
2986cac2 14563 } else {
14564 return CMD_ERR_INCOMPLETE;
14565 }
14566
14567 return CMD_SUCCESS;
14568}
14569/* Graceful Restart */
14570
f412b39a 14571DEFUN (show_ip_bgp_attr_info,
718e3744 14572 show_ip_bgp_attr_info_cmd,
bec37ba5 14573 "show [ip] bgp attribute-info",
718e3744 14574 SHOW_STR
14575 IP_STR
14576 BGP_STR
14577 "List all bgp attribute information\n")
14578{
d62a17ae 14579 attr_show_all(vty);
14580 return CMD_SUCCESS;
718e3744 14581}
6b0655a2 14582
03915806
CS
14583static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14584 afi_t afi, safi_t safi,
14585 bool use_json, json_object *json)
53089bec 14586{
14587 struct bgp *bgp;
14588 struct listnode *node;
14589 char *vname;
14590 char buf1[INET6_ADDRSTRLEN];
14591 char *ecom_str;
14592 vpn_policy_direction_t dir;
14593
03915806 14594 if (json) {
b46dfd20
DS
14595 json_object *json_import_vrfs = NULL;
14596 json_object *json_export_vrfs = NULL;
14597
b46dfd20
DS
14598 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14599
53089bec 14600 if (!bgp) {
b46dfd20
DS
14601 vty_out(vty, "%s\n",
14602 json_object_to_json_string_ext(
14603 json,
14604 JSON_C_TO_STRING_PRETTY));
14605 json_object_free(json);
14606
53089bec 14607 return CMD_WARNING;
14608 }
b46dfd20 14609
94d4c685
DS
14610 /* Provide context for the block */
14611 json_object_string_add(json, "vrf", name ? name : "default");
14612 json_object_string_add(json, "afiSafi",
5cb5f4d0 14613 get_afi_safi_str(afi, safi, true));
94d4c685 14614
b46dfd20
DS
14615 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14616 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14617 json_object_string_add(json, "importFromVrfs", "none");
14618 json_object_string_add(json, "importRts", "none");
14619 } else {
6ce24e52
DS
14620 json_import_vrfs = json_object_new_array();
14621
b46dfd20
DS
14622 for (ALL_LIST_ELEMENTS_RO(
14623 bgp->vpn_policy[afi].import_vrf,
14624 node, vname))
14625 json_object_array_add(json_import_vrfs,
14626 json_object_new_string(vname));
14627
b20875ea
CS
14628 json_object_object_add(json, "importFromVrfs",
14629 json_import_vrfs);
b46dfd20 14630 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14631 if (bgp->vpn_policy[afi].rtlist[dir]) {
14632 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14633 bgp->vpn_policy[afi].rtlist[dir],
14634 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14635 json_object_string_add(json, "importRts",
14636 ecom_str);
14637 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14638 } else
14639 json_object_string_add(json, "importRts",
14640 "none");
b46dfd20
DS
14641 }
14642
14643 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14644 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14645 json_object_string_add(json, "exportToVrfs", "none");
14646 json_object_string_add(json, "routeDistinguisher",
14647 "none");
14648 json_object_string_add(json, "exportRts", "none");
14649 } else {
6ce24e52
DS
14650 json_export_vrfs = json_object_new_array();
14651
b46dfd20
DS
14652 for (ALL_LIST_ELEMENTS_RO(
14653 bgp->vpn_policy[afi].export_vrf,
14654 node, vname))
14655 json_object_array_add(json_export_vrfs,
14656 json_object_new_string(vname));
14657 json_object_object_add(json, "exportToVrfs",
14658 json_export_vrfs);
14659 json_object_string_add(json, "routeDistinguisher",
14660 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14661 buf1, RD_ADDRSTRLEN));
14662
14663 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14664 if (bgp->vpn_policy[afi].rtlist[dir]) {
14665 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14666 bgp->vpn_policy[afi].rtlist[dir],
14667 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14668 json_object_string_add(json, "exportRts",
14669 ecom_str);
14670 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14671 } else
14672 json_object_string_add(json, "exportRts",
14673 "none");
b46dfd20
DS
14674 }
14675
03915806
CS
14676 if (use_json) {
14677 vty_out(vty, "%s\n",
14678 json_object_to_json_string_ext(json,
b46dfd20 14679 JSON_C_TO_STRING_PRETTY));
03915806
CS
14680 json_object_free(json);
14681 }
53089bec 14682 } else {
b46dfd20
DS
14683 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14684
53089bec 14685 if (!bgp) {
b46dfd20 14686 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14687 return CMD_WARNING;
14688 }
53089bec 14689
b46dfd20
DS
14690 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14691 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14692 vty_out(vty,
14693 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14694 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14695 else {
14696 vty_out(vty,
14697 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14698 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14699
14700 for (ALL_LIST_ELEMENTS_RO(
14701 bgp->vpn_policy[afi].import_vrf,
14702 node, vname))
14703 vty_out(vty, " %s\n", vname);
14704
14705 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14706 ecom_str = NULL;
14707 if (bgp->vpn_policy[afi].rtlist[dir]) {
14708 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14709 bgp->vpn_policy[afi].rtlist[dir],
14710 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14711 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14712
b20875ea
CS
14713 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14714 } else
14715 vty_out(vty, "Import RT(s):\n");
53089bec 14716 }
53089bec 14717
b46dfd20
DS
14718 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14719 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14720 vty_out(vty,
14721 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14722 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14723 else {
14724 vty_out(vty,
04c9077f 14725 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14726 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14727
14728 for (ALL_LIST_ELEMENTS_RO(
14729 bgp->vpn_policy[afi].export_vrf,
14730 node, vname))
14731 vty_out(vty, " %s\n", vname);
14732
14733 vty_out(vty, "RD: %s\n",
14734 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14735 buf1, RD_ADDRSTRLEN));
14736
14737 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14738 if (bgp->vpn_policy[afi].rtlist[dir]) {
14739 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14740 bgp->vpn_policy[afi].rtlist[dir],
14741 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14742 vty_out(vty, "Export RT: %s\n", ecom_str);
14743 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14744 } else
14745 vty_out(vty, "Import RT(s):\n");
53089bec 14746 }
53089bec 14747 }
14748
14749 return CMD_SUCCESS;
14750}
14751
03915806
CS
14752static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14753 safi_t safi, bool use_json)
14754{
14755 struct listnode *node, *nnode;
14756 struct bgp *bgp;
14757 char *vrf_name = NULL;
14758 json_object *json = NULL;
14759 json_object *json_vrf = NULL;
14760 json_object *json_vrfs = NULL;
14761
14762 if (use_json) {
14763 json = json_object_new_object();
14764 json_vrfs = json_object_new_object();
14765 }
14766
14767 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14768
14769 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14770 vrf_name = bgp->name;
14771
14772 if (use_json) {
14773 json_vrf = json_object_new_object();
14774 } else {
14775 vty_out(vty, "\nInstance %s:\n",
14776 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14777 ? VRF_DEFAULT_NAME : bgp->name);
14778 }
14779 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14780 if (use_json) {
14781 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14782 json_object_object_add(json_vrfs,
14783 VRF_DEFAULT_NAME, json_vrf);
14784 else
14785 json_object_object_add(json_vrfs, vrf_name,
14786 json_vrf);
14787 }
14788 }
14789
14790 if (use_json) {
14791 json_object_object_add(json, "vrfs", json_vrfs);
14792 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
14793 JSON_C_TO_STRING_PRETTY));
14794 json_object_free(json);
14795 }
14796
14797 return CMD_SUCCESS;
14798}
14799
53089bec 14800/* "show [ip] bgp route-leak" command. */
14801DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14802 show_ip_bgp_route_leak_cmd,
14803 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14804 SHOW_STR
14805 IP_STR
14806 BGP_STR
14807 BGP_INSTANCE_HELP_STR
14808 BGP_AFI_HELP_STR
14809 BGP_SAFI_HELP_STR
14810 "Route leaking information\n"
14811 JSON_STR)
53089bec 14812{
14813 char *vrf = NULL;
14814 afi_t afi = AFI_MAX;
14815 safi_t safi = SAFI_MAX;
14816
9f049418 14817 bool uj = use_json(argc, argv);
53089bec 14818 int idx = 0;
03915806 14819 json_object *json = NULL;
53089bec 14820
14821 /* show [ip] bgp */
14822 if (argv_find(argv, argc, "ip", &idx)) {
14823 afi = AFI_IP;
14824 safi = SAFI_UNICAST;
14825 }
14826 /* [vrf VIEWVRFNAME] */
14827 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14828 vty_out(vty,
14829 "%% This command is not applicable to BGP views\n");
53089bec 14830 return CMD_WARNING;
14831 }
14832
9a8bdf1c
PG
14833 if (argv_find(argv, argc, "vrf", &idx)) {
14834 vrf = argv[idx + 1]->arg;
14835 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14836 vrf = NULL;
14837 }
53089bec 14838 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14839 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14840 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14841 }
14842
14843 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14844 vty_out(vty,
14845 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14846 return CMD_WARNING;
14847 }
14848
03915806
CS
14849 if (vrf && strmatch(vrf, "all"))
14850 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14851
14852 if (uj)
14853 json = json_object_new_object();
14854
14855 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14856}
14857
d62a17ae 14858static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14859 safi_t safi)
f186de26 14860{
d62a17ae 14861 struct listnode *node, *nnode;
14862 struct bgp *bgp;
f186de26 14863
d62a17ae 14864 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14865 vty_out(vty, "\nInstance %s:\n",
14866 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14867 ? VRF_DEFAULT_NAME
d62a17ae 14868 : bgp->name);
14869 update_group_show(bgp, afi, safi, vty, 0);
14870 }
f186de26 14871}
14872
d62a17ae 14873static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14874 int safi, uint64_t subgrp_id)
4fb25c53 14875{
d62a17ae 14876 struct bgp *bgp;
4fb25c53 14877
d62a17ae 14878 if (name) {
14879 if (strmatch(name, "all")) {
14880 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14881 return CMD_SUCCESS;
14882 } else {
14883 bgp = bgp_lookup_by_name(name);
14884 }
14885 } else {
14886 bgp = bgp_get_default();
14887 }
4fb25c53 14888
d62a17ae 14889 if (bgp)
14890 update_group_show(bgp, afi, safi, vty, subgrp_id);
14891 return CMD_SUCCESS;
4fb25c53
DW
14892}
14893
8fe8a7f6
DS
14894DEFUN (show_ip_bgp_updgrps,
14895 show_ip_bgp_updgrps_cmd,
c1a44e43 14896 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14897 SHOW_STR
14898 IP_STR
14899 BGP_STR
14900 BGP_INSTANCE_HELP_STR
c9e571b4 14901 BGP_AFI_HELP_STR
9bedbb1e 14902 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14903 "Detailed info about dynamic update groups\n"
14904 "Specific subgroup to display detailed info for\n")
8386ac43 14905{
d62a17ae 14906 char *vrf = NULL;
14907 afi_t afi = AFI_IP6;
14908 safi_t safi = SAFI_UNICAST;
14909 uint64_t subgrp_id = 0;
14910
14911 int idx = 0;
14912
14913 /* show [ip] bgp */
14914 if (argv_find(argv, argc, "ip", &idx))
14915 afi = AFI_IP;
9a8bdf1c
PG
14916 /* [<vrf> VIEWVRFNAME] */
14917 if (argv_find(argv, argc, "vrf", &idx)) {
14918 vrf = argv[idx + 1]->arg;
14919 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14920 vrf = NULL;
14921 } else if (argv_find(argv, argc, "view", &idx))
14922 /* [<view> VIEWVRFNAME] */
14923 vrf = argv[idx + 1]->arg;
d62a17ae 14924 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14925 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14926 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14927 }
5bf15956 14928
d62a17ae 14929 /* get subgroup id, if provided */
14930 idx = argc - 1;
14931 if (argv[idx]->type == VARIABLE_TKN)
14932 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 14933
d62a17ae 14934 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
14935}
14936
f186de26 14937DEFUN (show_bgp_instance_all_ipv6_updgrps,
14938 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 14939 "show [ip] bgp <view|vrf> all update-groups",
f186de26 14940 SHOW_STR
716b2d8a 14941 IP_STR
f186de26 14942 BGP_STR
14943 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 14944 "Detailed info about dynamic update groups\n")
f186de26 14945{
d62a17ae 14946 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14947 return CMD_SUCCESS;
f186de26 14948}
14949
43d3f4fc
DS
14950DEFUN (show_bgp_l2vpn_evpn_updgrps,
14951 show_bgp_l2vpn_evpn_updgrps_cmd,
14952 "show [ip] bgp l2vpn evpn update-groups",
14953 SHOW_STR
14954 IP_STR
14955 BGP_STR
14956 "l2vpn address family\n"
14957 "evpn sub-address family\n"
14958 "Detailed info about dynamic update groups\n")
14959{
14960 char *vrf = NULL;
14961 uint64_t subgrp_id = 0;
14962
14963 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14964 return CMD_SUCCESS;
14965}
14966
5bf15956
DW
14967DEFUN (show_bgp_updgrps_stats,
14968 show_bgp_updgrps_stats_cmd,
716b2d8a 14969 "show [ip] bgp update-groups statistics",
3f9c7369 14970 SHOW_STR
716b2d8a 14971 IP_STR
3f9c7369 14972 BGP_STR
0c7b1b01 14973 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14974 "Statistics\n")
14975{
d62a17ae 14976 struct bgp *bgp;
3f9c7369 14977
d62a17ae 14978 bgp = bgp_get_default();
14979 if (bgp)
14980 update_group_show_stats(bgp, vty);
3f9c7369 14981
d62a17ae 14982 return CMD_SUCCESS;
3f9c7369
DS
14983}
14984
8386ac43 14985DEFUN (show_bgp_instance_updgrps_stats,
14986 show_bgp_instance_updgrps_stats_cmd,
18c57037 14987 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14988 SHOW_STR
716b2d8a 14989 IP_STR
8386ac43 14990 BGP_STR
14991 BGP_INSTANCE_HELP_STR
0c7b1b01 14992 "Detailed info about dynamic update groups\n"
8386ac43 14993 "Statistics\n")
14994{
d62a17ae 14995 int idx_word = 3;
14996 struct bgp *bgp;
8386ac43 14997
d62a17ae 14998 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14999 if (bgp)
15000 update_group_show_stats(bgp, vty);
8386ac43 15001
d62a17ae 15002 return CMD_SUCCESS;
8386ac43 15003}
15004
d62a17ae 15005static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15006 afi_t afi, safi_t safi,
15007 const char *what, uint64_t subgrp_id)
3f9c7369 15008{
d62a17ae 15009 struct bgp *bgp;
8386ac43 15010
d62a17ae 15011 if (name)
15012 bgp = bgp_lookup_by_name(name);
15013 else
15014 bgp = bgp_get_default();
8386ac43 15015
d62a17ae 15016 if (bgp) {
15017 if (!strcmp(what, "advertise-queue"))
15018 update_group_show_adj_queue(bgp, afi, safi, vty,
15019 subgrp_id);
15020 else if (!strcmp(what, "advertised-routes"))
15021 update_group_show_advertised(bgp, afi, safi, vty,
15022 subgrp_id);
15023 else if (!strcmp(what, "packet-queue"))
15024 update_group_show_packet_queue(bgp, afi, safi, vty,
15025 subgrp_id);
15026 }
3f9c7369
DS
15027}
15028
dc64bdec
QY
15029DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15030 show_ip_bgp_instance_updgrps_adj_s_cmd,
15031 "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",
15032 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15033 BGP_SAFI_HELP_STR
15034 "Detailed info about dynamic update groups\n"
15035 "Specific subgroup to display info for\n"
15036 "Advertisement queue\n"
15037 "Announced routes\n"
15038 "Packet queue\n")
3f9c7369 15039{
dc64bdec
QY
15040 uint64_t subgrp_id = 0;
15041 afi_t afiz;
15042 safi_t safiz;
15043 if (sgid)
15044 subgrp_id = strtoull(sgid, NULL, 10);
15045
15046 if (!ip && !afi)
15047 afiz = AFI_IP6;
15048 if (!ip && afi)
15049 afiz = bgp_vty_afi_from_str(afi);
15050 if (ip && !afi)
15051 afiz = AFI_IP;
15052 if (ip && afi) {
15053 afiz = bgp_vty_afi_from_str(afi);
15054 if (afiz != AFI_IP)
15055 vty_out(vty,
15056 "%% Cannot specify both 'ip' and 'ipv6'\n");
15057 return CMD_WARNING;
15058 }
d62a17ae 15059
dc64bdec 15060 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15061
dc64bdec 15062 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15063 return CMD_SUCCESS;
15064}
15065
d62a17ae 15066static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15067{
15068 struct listnode *node, *nnode;
15069 struct prefix *range;
15070 struct peer *conf;
15071 struct peer *peer;
d62a17ae 15072 afi_t afi;
15073 safi_t safi;
15074 const char *peer_status;
15075 const char *af_str;
15076 int lr_count;
15077 int dynamic;
15078 int af_cfgd;
15079
15080 conf = group->conf;
15081
15082 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 15083 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 15084 group->name, conf->as);
d62a17ae 15085 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 15086 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 15087 group->name, group->bgp->as);
d62a17ae 15088 } else {
15089 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15090 }
f14e6fdb 15091
d62a17ae 15092 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15093 vty_out(vty, " Peer-group type is internal\n");
15094 else
15095 vty_out(vty, " Peer-group type is external\n");
15096
15097 /* Display AFs configured. */
15098 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
15099 FOREACH_AFI_SAFI (afi, safi) {
15100 if (conf->afc[afi][safi]) {
15101 af_cfgd = 1;
5cb5f4d0 15102 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 15103 }
05c7a1cc 15104 }
d62a17ae 15105 if (!af_cfgd)
15106 vty_out(vty, " none\n");
15107 else
15108 vty_out(vty, "\n");
15109
15110 /* Display listen ranges (for dynamic neighbors), if any */
15111 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15112 if (afi == AFI_IP)
15113 af_str = "IPv4";
15114 else if (afi == AFI_IP6)
15115 af_str = "IPv6";
15116 else
15117 af_str = "???";
15118 lr_count = listcount(group->listen_range[afi]);
15119 if (lr_count) {
15120 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15121 af_str);
15122
15123
15124 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
2dbe669b
DA
15125 nnode, range))
15126 vty_out(vty, " %pFX\n", range);
d62a17ae 15127 }
15128 }
f14e6fdb 15129
d62a17ae 15130 /* Display group members and their status */
15131 if (listcount(group->peer)) {
15132 vty_out(vty, " Peer-group members:\n");
15133 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15134 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15135 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15136 peer_status = "Idle (Admin)";
15137 else if (CHECK_FLAG(peer->sflags,
15138 PEER_STATUS_PREFIX_OVERFLOW))
15139 peer_status = "Idle (PfxCt)";
15140 else
15141 peer_status = lookup_msg(bgp_status_msg,
15142 peer->status, NULL);
15143
15144 dynamic = peer_dynamic_neighbor(peer);
15145 vty_out(vty, " %s %s %s \n", peer->host,
15146 dynamic ? "(dynamic)" : "", peer_status);
15147 }
15148 }
f14e6fdb 15149
d62a17ae 15150 return CMD_SUCCESS;
15151}
15152
ff9959b0
QY
15153static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15154 const char *group_name)
d62a17ae 15155{
ff9959b0 15156 struct bgp *bgp;
d62a17ae 15157 struct listnode *node, *nnode;
15158 struct peer_group *group;
ff9959b0
QY
15159 bool found = false;
15160
15161 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15162
15163 if (!bgp) {
9f049418 15164 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
15165 return CMD_WARNING;
15166 }
d62a17ae 15167
15168 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15169 if (group_name) {
15170 if (strmatch(group->name, group_name)) {
d62a17ae 15171 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
15172 found = true;
15173 break;
d62a17ae 15174 }
ff9959b0
QY
15175 } else {
15176 bgp_show_one_peer_group(vty, group);
d62a17ae 15177 }
f14e6fdb 15178 }
f14e6fdb 15179
ff9959b0 15180 if (group_name && !found)
d62a17ae 15181 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15182
d62a17ae 15183 return CMD_SUCCESS;
f14e6fdb
DS
15184}
15185
f14e6fdb
DS
15186DEFUN (show_ip_bgp_peer_groups,
15187 show_ip_bgp_peer_groups_cmd,
18c57037 15188 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
15189 SHOW_STR
15190 IP_STR
15191 BGP_STR
8386ac43 15192 BGP_INSTANCE_HELP_STR
d6e3c605
QY
15193 "Detailed information on BGP peer groups\n"
15194 "Peer group name\n")
f14e6fdb 15195{
d62a17ae 15196 char *vrf, *pg;
d62a17ae 15197 int idx = 0;
f14e6fdb 15198
a4d82a8a
PZ
15199 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15200 : NULL;
d62a17ae 15201 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15202
ff9959b0 15203 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 15204}
3f9c7369 15205
d6e3c605 15206
718e3744 15207/* Redistribute VTY commands. */
15208
37a87b8f
CS
15209DEFUN_YANG (bgp_redistribute_ipv4,
15210 bgp_redistribute_ipv4_cmd,
15211 "redistribute " FRR_IP_REDIST_STR_BGPD,
15212 "Redistribute information from another routing protocol\n"
15213 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15214{
d62a17ae 15215 int idx_protocol = 1;
37a87b8f 15216 char base_xpath[XPATH_MAXLEN];
718e3744 15217
37a87b8f
CS
15218 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15219 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15220 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15221 argv[idx_protocol]->text, "0");
15222
15223 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 15224
37a87b8f 15225 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15226}
15227
d62a17ae 15228ALIAS_HIDDEN(
15229 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15230 "redistribute " FRR_IP_REDIST_STR_BGPD,
15231 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15232
37a87b8f
CS
15233DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15234 bgp_redistribute_ipv4_rmap_cmd,
15235 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15236 "Redistribute information from another routing protocol\n"
15237 FRR_IP_REDIST_HELP_STR_BGPD
15238 "Route map reference\n"
15239 "Pointer to route-map entries\n")
718e3744 15240{
d62a17ae 15241 int idx_protocol = 1;
15242 int idx_word = 3;
37a87b8f
CS
15243 char base_xpath[XPATH_MAXLEN];
15244
15245 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15246 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15247 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15248 argv[idx_protocol]->text, "0");
718e3744 15249
37a87b8f
CS
15250 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15251 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15252 argv[idx_word]->arg);
15253
15254 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15255}
15256
d62a17ae 15257ALIAS_HIDDEN(
15258 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15259 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15260 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15261 "Route map reference\n"
15262 "Pointer to route-map entries\n")
596c17ba 15263
37a87b8f
CS
15264DEFUN_YANG (bgp_redistribute_ipv4_metric,
15265 bgp_redistribute_ipv4_metric_cmd,
15266 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15267 "Redistribute information from another routing protocol\n"
15268 FRR_IP_REDIST_HELP_STR_BGPD
15269 "Metric for redistributed routes\n"
15270 "Default metric\n")
718e3744 15271{
d62a17ae 15272 int idx_protocol = 1;
15273 int idx_number = 3;
37a87b8f
CS
15274 char base_xpath[XPATH_MAXLEN];
15275
15276 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15277 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15278 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15279 argv[idx_protocol]->text, "0");
d62a17ae 15280
37a87b8f
CS
15281 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15282 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15283 argv[idx_number]->arg);
15284
15285 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15286}
15287
15288ALIAS_HIDDEN(
15289 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15290 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15291 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15292 "Metric for redistributed routes\n"
15293 "Default metric\n")
596c17ba 15294
37a87b8f
CS
15295DEFUN_YANG(
15296 bgp_redistribute_ipv4_rmap_metric,
15297 bgp_redistribute_ipv4_rmap_metric_cmd,
15298 "redistribute " FRR_IP_REDIST_STR_BGPD
15299 " route-map WORD metric (0-4294967295)",
15300 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15301 "Route map reference\n"
15302 "Pointer to route-map entries\n"
15303 "Metric for redistributed routes\n"
15304 "Default metric\n")
718e3744 15305{
d62a17ae 15306 int idx_protocol = 1;
15307 int idx_word = 3;
15308 int idx_number = 5;
37a87b8f
CS
15309 char base_xpath[XPATH_MAXLEN];
15310
15311 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15312 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15313 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15314 argv[idx_protocol]->text, "0");
15315
15316 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15317 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15318 argv[idx_word]->arg);
15319 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15320 argv[idx_number]->arg);
d62a17ae 15321
37a87b8f 15322 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15323}
15324
15325ALIAS_HIDDEN(
15326 bgp_redistribute_ipv4_rmap_metric,
15327 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15328 "redistribute " FRR_IP_REDIST_STR_BGPD
15329 " route-map WORD metric (0-4294967295)",
15330 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15331 "Route map reference\n"
15332 "Pointer to route-map entries\n"
15333 "Metric for redistributed routes\n"
15334 "Default metric\n")
596c17ba 15335
37a87b8f
CS
15336DEFUN_YANG(
15337 bgp_redistribute_ipv4_metric_rmap,
15338 bgp_redistribute_ipv4_metric_rmap_cmd,
15339 "redistribute " FRR_IP_REDIST_STR_BGPD
15340 " metric (0-4294967295) route-map WORD",
15341 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15342 "Metric for redistributed routes\n"
15343 "Default metric\n"
15344 "Route map reference\n"
15345 "Pointer to route-map entries\n")
718e3744 15346{
d62a17ae 15347 int idx_protocol = 1;
d62a17ae 15348 int idx_word = 5;
37a87b8f
CS
15349 int idx_number = 3;
15350 char base_xpath[XPATH_MAXLEN];
15351
15352 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15353 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15354 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15355 argv[idx_protocol]->text, "0");
15356
15357 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15358 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15359 argv[idx_number]->arg);
15360 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15361 argv[idx_word]->arg);
d62a17ae 15362
37a87b8f 15363 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15364}
15365
15366ALIAS_HIDDEN(
15367 bgp_redistribute_ipv4_metric_rmap,
15368 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15369 "redistribute " FRR_IP_REDIST_STR_BGPD
15370 " metric (0-4294967295) route-map WORD",
15371 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15372 "Metric for redistributed routes\n"
15373 "Default metric\n"
15374 "Route map reference\n"
15375 "Pointer to route-map entries\n")
596c17ba 15376
37a87b8f
CS
15377DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15378 bgp_redistribute_ipv4_ospf_cmd,
15379 "redistribute <ospf|table> (1-65535)",
15380 "Redistribute information from another routing protocol\n"
15381 "Open Shortest Path First (OSPFv2)\n"
15382 "Non-main Kernel Routing Table\n"
15383 "Instance ID/Table ID\n")
7c8ff89e 15384{
37a87b8f 15385 int idx_protocol = 1;
d62a17ae 15386 int idx_number = 2;
37a87b8f 15387 char base_xpath[XPATH_MAXLEN];
7c8ff89e 15388
37a87b8f
CS
15389 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15390 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15391 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15392 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 15393
37a87b8f 15394 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 15395
37a87b8f 15396 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
15397}
15398
d62a17ae 15399ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15400 "redistribute <ospf|table> (1-65535)",
15401 "Redistribute information from another routing protocol\n"
15402 "Open Shortest Path First (OSPFv2)\n"
15403 "Non-main Kernel Routing Table\n"
15404 "Instance ID/Table ID\n")
596c17ba 15405
37a87b8f
CS
15406DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15407 bgp_redistribute_ipv4_ospf_rmap_cmd,
15408 "redistribute <ospf|table> (1-65535) route-map WORD",
15409 "Redistribute information from another routing protocol\n"
15410 "Open Shortest Path First (OSPFv2)\n"
15411 "Non-main Kernel Routing Table\n"
15412 "Instance ID/Table ID\n"
15413 "Route map reference\n"
15414 "Pointer to route-map entries\n")
7c8ff89e 15415{
37a87b8f 15416 int idx_protocol = 1;
d62a17ae 15417 int idx_number = 2;
15418 int idx_word = 4;
37a87b8f
CS
15419 char base_xpath[XPATH_MAXLEN];
15420
15421 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15422 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15423 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15424 argv[idx_protocol]->text, argv[idx_number]->arg);
15425
15426 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15427
15428 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15429 argv[idx_word]->arg);
d62a17ae 15430
37a87b8f 15431 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15432}
15433
15434ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15435 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15436 "redistribute <ospf|table> (1-65535) route-map WORD",
15437 "Redistribute information from another routing protocol\n"
15438 "Open Shortest Path First (OSPFv2)\n"
15439 "Non-main Kernel Routing Table\n"
15440 "Instance ID/Table ID\n"
15441 "Route map reference\n"
15442 "Pointer to route-map entries\n")
596c17ba 15443
37a87b8f
CS
15444DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15445 bgp_redistribute_ipv4_ospf_metric_cmd,
15446 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15447 "Redistribute information from another routing protocol\n"
15448 "Open Shortest Path First (OSPFv2)\n"
15449 "Non-main Kernel Routing Table\n"
15450 "Instance ID/Table ID\n"
15451 "Metric for redistributed routes\n"
15452 "Default metric\n")
7c8ff89e 15453{
37a87b8f 15454 int idx_protocol = 1;
d62a17ae 15455 int idx_number = 2;
15456 int idx_number_2 = 4;
37a87b8f
CS
15457 char base_xpath[XPATH_MAXLEN];
15458
15459 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15460 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15461 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15462 argv[idx_protocol]->text, argv[idx_number]->arg);
15463
15464 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15465
37a87b8f
CS
15466 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15467 argv[idx_number_2]->arg);
d62a17ae 15468
37a87b8f 15469 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15470}
15471
15472ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15473 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15474 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15475 "Redistribute information from another routing protocol\n"
15476 "Open Shortest Path First (OSPFv2)\n"
15477 "Non-main Kernel Routing Table\n"
15478 "Instance ID/Table ID\n"
15479 "Metric for redistributed routes\n"
15480 "Default metric\n")
596c17ba 15481
37a87b8f
CS
15482DEFUN_YANG(
15483 bgp_redistribute_ipv4_ospf_rmap_metric,
15484 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15485 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15486 "Redistribute information from another routing protocol\n"
15487 "Open Shortest Path First (OSPFv2)\n"
15488 "Non-main Kernel Routing Table\n"
15489 "Instance ID/Table ID\n"
15490 "Route map reference\n"
15491 "Pointer to route-map entries\n"
15492 "Metric for redistributed routes\n"
15493 "Default metric\n")
7c8ff89e 15494{
37a87b8f 15495 int idx_protocol = 1;
d62a17ae 15496 int idx_number = 2;
15497 int idx_word = 4;
15498 int idx_number_2 = 6;
37a87b8f
CS
15499 char base_xpath[XPATH_MAXLEN];
15500
15501 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15502 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15503 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15504 argv[idx_protocol]->text, argv[idx_number]->arg);
15505
15506 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15507
37a87b8f
CS
15508 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15509 argv[idx_word]->arg);
15510 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15511 argv[idx_number_2]->arg);
d62a17ae 15512
37a87b8f 15513 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15514}
15515
15516ALIAS_HIDDEN(
15517 bgp_redistribute_ipv4_ospf_rmap_metric,
15518 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15519 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15520 "Redistribute information from another routing protocol\n"
15521 "Open Shortest Path First (OSPFv2)\n"
15522 "Non-main Kernel Routing Table\n"
15523 "Instance ID/Table ID\n"
15524 "Route map reference\n"
15525 "Pointer to route-map entries\n"
15526 "Metric for redistributed routes\n"
15527 "Default metric\n")
596c17ba 15528
37a87b8f
CS
15529DEFUN_YANG(
15530 bgp_redistribute_ipv4_ospf_metric_rmap,
15531 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15532 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15533 "Redistribute information from another routing protocol\n"
15534 "Open Shortest Path First (OSPFv2)\n"
15535 "Non-main Kernel Routing Table\n"
15536 "Instance ID/Table ID\n"
15537 "Metric for redistributed routes\n"
15538 "Default metric\n"
15539 "Route map reference\n"
15540 "Pointer to route-map entries\n")
7c8ff89e 15541{
37a87b8f 15542 int idx_protocol = 1;
d62a17ae 15543 int idx_number = 2;
15544 int idx_number_2 = 4;
15545 int idx_word = 6;
37a87b8f
CS
15546 char base_xpath[XPATH_MAXLEN];
15547
15548 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15549 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15550 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15551 argv[idx_protocol]->text, argv[idx_number]->arg);
15552
15553 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 15554
37a87b8f
CS
15555 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15556 argv[idx_number_2]->arg);
15557 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15558 argv[idx_word]->arg);
d62a17ae 15559
37a87b8f 15560 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15561}
15562
15563ALIAS_HIDDEN(
15564 bgp_redistribute_ipv4_ospf_metric_rmap,
15565 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15566 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15567 "Redistribute information from another routing protocol\n"
15568 "Open Shortest Path First (OSPFv2)\n"
15569 "Non-main Kernel Routing Table\n"
15570 "Instance ID/Table ID\n"
15571 "Metric for redistributed routes\n"
15572 "Default metric\n"
15573 "Route map reference\n"
15574 "Pointer to route-map entries\n")
596c17ba 15575
37a87b8f
CS
15576DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15577 no_bgp_redistribute_ipv4_ospf_cmd,
15578 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15579 NO_STR
15580 "Redistribute information from another routing protocol\n"
15581 "Open Shortest Path First (OSPFv2)\n"
15582 "Non-main Kernel Routing Table\n"
15583 "Instance ID/Table ID\n"
15584 "Metric for redistributed routes\n"
15585 "Default metric\n"
15586 "Route map reference\n"
15587 "Pointer to route-map entries\n")
7c8ff89e 15588{
37a87b8f 15589 int idx_protocol = 2;
d62a17ae 15590 int idx_number = 3;
37a87b8f 15591 char base_xpath[XPATH_MAXLEN];
d62a17ae 15592
37a87b8f
CS
15593 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15594 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15595 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15596 argv[idx_protocol]->text, argv[idx_number]->arg);
15597
15598 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 15599
37a87b8f 15600 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15601}
15602
15603ALIAS_HIDDEN(
15604 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15605 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15606 NO_STR
15607 "Redistribute information from another routing protocol\n"
15608 "Open Shortest Path First (OSPFv2)\n"
15609 "Non-main Kernel Routing Table\n"
15610 "Instance ID/Table ID\n"
15611 "Metric for redistributed routes\n"
15612 "Default metric\n"
15613 "Route map reference\n"
15614 "Pointer to route-map entries\n")
596c17ba 15615
37a87b8f
CS
15616DEFUN_YANG (no_bgp_redistribute_ipv4,
15617 no_bgp_redistribute_ipv4_cmd,
15618 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15619 NO_STR
15620 "Redistribute information from another routing protocol\n"
15621 FRR_IP_REDIST_HELP_STR_BGPD
15622 "Metric for redistributed routes\n"
15623 "Default metric\n"
15624 "Route map reference\n"
15625 "Pointer to route-map entries\n")
718e3744 15626{
d62a17ae 15627 int idx_protocol = 2;
37a87b8f 15628 char base_xpath[XPATH_MAXLEN];
d62a17ae 15629
37a87b8f
CS
15630 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15631 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15632 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15633 argv[idx_protocol]->text, "0");
15634
15635 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15636
15637 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15638}
15639
15640ALIAS_HIDDEN(
15641 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15642 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15643 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15644 NO_STR
15645 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15646 "Metric for redistributed routes\n"
15647 "Default metric\n"
15648 "Route map reference\n"
15649 "Pointer to route-map entries\n")
596c17ba 15650
37a87b8f
CS
15651DEFUN_YANG (bgp_redistribute_ipv6,
15652 bgp_redistribute_ipv6_cmd,
15653 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15654 "Redistribute information from another routing protocol\n"
15655 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15656{
d62a17ae 15657 int idx_protocol = 1;
37a87b8f 15658 char base_xpath[XPATH_MAXLEN];
718e3744 15659
37a87b8f
CS
15660 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15661 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15662 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15663 argv[idx_protocol]->text, "0");
15664
15665 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 15666
37a87b8f 15667 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15668}
15669
37a87b8f
CS
15670DEFUN_YANG (bgp_redistribute_ipv6_rmap,
15671 bgp_redistribute_ipv6_rmap_cmd,
15672 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15673 "Redistribute information from another routing protocol\n"
15674 FRR_IP6_REDIST_HELP_STR_BGPD
15675 "Route map reference\n"
15676 "Pointer to route-map entries\n")
718e3744 15677{
d62a17ae 15678 int idx_protocol = 1;
15679 int idx_word = 3;
37a87b8f
CS
15680 char base_xpath[XPATH_MAXLEN];
15681
15682 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15683 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15684 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15685 argv[idx_protocol]->text, "0");
718e3744 15686
37a87b8f
CS
15687 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15688 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15689 argv[idx_word]->arg);
15690
15691 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15692}
15693
37a87b8f 15694DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 15695 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15696 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15697 "Redistribute information from another routing protocol\n"
ab0181ee 15698 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15699 "Metric for redistributed routes\n"
15700 "Default metric\n")
15701{
d62a17ae 15702 int idx_protocol = 1;
15703 int idx_number = 3;
37a87b8f
CS
15704 char base_xpath[XPATH_MAXLEN];
15705
15706 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15707 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15708 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15709 argv[idx_protocol]->text, "0");
718e3744 15710
37a87b8f
CS
15711 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15712 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15713 argv[idx_number]->arg);
15714
15715 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15716}
15717
37a87b8f
CS
15718DEFUN_YANG(
15719 bgp_redistribute_ipv6_rmap_metric,
15720 bgp_redistribute_ipv6_rmap_metric_cmd,
15721 "redistribute " FRR_IP6_REDIST_STR_BGPD
15722 " route-map WORD metric (0-4294967295)",
15723 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15724 "Route map reference\n"
15725 "Pointer to route-map entries\n"
15726 "Metric for redistributed routes\n"
15727 "Default metric\n")
718e3744 15728{
d62a17ae 15729 int idx_protocol = 1;
15730 int idx_word = 3;
15731 int idx_number = 5;
37a87b8f
CS
15732 char base_xpath[XPATH_MAXLEN];
15733
15734 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15735 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15736 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15737 argv[idx_protocol]->text, "0");
718e3744 15738
37a87b8f
CS
15739 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15740 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15741 argv[idx_word]->arg);
15742 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15743 argv[idx_number]->arg);
15744
15745 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15746}
15747
37a87b8f
CS
15748DEFUN_YANG(
15749 bgp_redistribute_ipv6_metric_rmap,
15750 bgp_redistribute_ipv6_metric_rmap_cmd,
15751 "redistribute " FRR_IP6_REDIST_STR_BGPD
15752 " metric (0-4294967295) route-map WORD",
15753 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15754 "Metric for redistributed routes\n"
15755 "Default metric\n"
15756 "Route map reference\n"
15757 "Pointer to route-map entries\n")
718e3744 15758{
d62a17ae 15759 int idx_protocol = 1;
d62a17ae 15760 int idx_word = 5;
37a87b8f
CS
15761 int idx_number = 3;
15762 char base_xpath[XPATH_MAXLEN];
15763
15764 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15765 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15766 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15767 argv[idx_protocol]->text, "0");
718e3744 15768
37a87b8f
CS
15769 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15770 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15771 argv[idx_number]->arg);
15772 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15773 argv[idx_word]->arg);
15774
15775 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15776}
15777
37a87b8f
CS
15778DEFUN_YANG(
15779 no_bgp_redistribute_ipv6,
15780 no_bgp_redistribute_ipv6_cmd,
15781 "no redistribute " FRR_IP6_REDIST_STR_BGPD
15782 " [{metric (0-4294967295)|route-map WORD}]",
15783 NO_STR
15784 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
15785 "Metric for redistributed routes\n"
15786 "Default metric\n"
15787 "Route map reference\n"
15788 "Pointer to route-map entries\n")
718e3744 15789{
d62a17ae 15790 int idx_protocol = 2;
37a87b8f 15791 char base_xpath[XPATH_MAXLEN];
718e3744 15792
37a87b8f
CS
15793 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15794 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
15795 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
15796 argv[idx_protocol]->text, "0");
15797
15798 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15799
15800 return nb_cli_apply_changes(vty, base_xpath);
15801}
718e3744 15802
37a87b8f
CS
15803void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
15804 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
15805{
15806 uint32_t instance = 0;
15807
15808 vty_out(vty, " redistribute %s",
15809 yang_dnode_get_string(dnode, "./route-type"));
15810 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
15811 vty_out(vty, " %d", instance);
15812 if (yang_dnode_exists(dnode, "./metric"))
15813 vty_out(vty, " metric %u",
15814 yang_dnode_get_uint32(dnode, "./metric"));
15815 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
15816 vty_out(vty, " route-map %s",
15817 yang_dnode_get_string(dnode, "./rmap-policy-import"));
15818 vty_out(vty, "\n");
d62a17ae 15819}
15820
dd65f45e
DL
15821static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15822 afi_t afi, safi_t safi)
d62a17ae 15823{
15824 int i;
15825
15826 /* Unicast redistribution only. */
15827 if (safi != SAFI_UNICAST)
2b791107 15828 return;
d62a17ae 15829
15830 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
15831 /* Redistribute BGP does not make sense. */
15832 if (i != ZEBRA_ROUTE_BGP) {
15833 struct list *red_list;
15834 struct listnode *node;
15835 struct bgp_redist *red;
15836
15837 red_list = bgp->redist[afi][i];
15838 if (!red_list)
15839 continue;
15840
15841 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 15842 /* "redistribute" configuration. */
15843 vty_out(vty, " redistribute %s",
15844 zebra_route_string(i));
15845 if (red->instance)
15846 vty_out(vty, " %d", red->instance);
15847 if (red->redist_metric_flag)
15848 vty_out(vty, " metric %u",
15849 red->redist_metric);
15850 if (red->rmap.name)
15851 vty_out(vty, " route-map %s",
15852 red->rmap.name);
15853 vty_out(vty, "\n");
15854 }
15855 }
15856 }
718e3744 15857}
6b0655a2 15858
dd65f45e
DL
15859/* peer-group helpers for config-write */
15860
15861static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
15862{
15863 if (!peer_group_active(peer)) {
15864 if (CHECK_FLAG(peer->flags_invert, flag))
15865 return !CHECK_FLAG(peer->flags, flag);
15866 else
15867 return !!CHECK_FLAG(peer->flags, flag);
15868 }
15869
15870 return !!CHECK_FLAG(peer->flags_override, flag);
15871}
15872
15873static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
15874 uint32_t flag)
15875{
15876 if (!peer_group_active(peer)) {
15877 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
15878 return !peer_af_flag_check(peer, afi, safi, flag);
15879 else
15880 return !!peer_af_flag_check(peer, afi, safi, flag);
15881 }
15882
15883 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
15884}
15885
15886static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
15887 uint8_t type, int direct)
15888{
15889 struct bgp_filter *filter;
15890
15891 if (peer_group_active(peer))
15892 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
15893 type);
15894
15895 filter = &peer->filter[afi][safi];
15896 switch (type) {
15897 case PEER_FT_DISTRIBUTE_LIST:
15898 return !!(filter->dlist[direct].name);
15899 case PEER_FT_FILTER_LIST:
15900 return !!(filter->aslist[direct].name);
15901 case PEER_FT_PREFIX_LIST:
15902 return !!(filter->plist[direct].name);
15903 case PEER_FT_ROUTE_MAP:
15904 return !!(filter->map[direct].name);
15905 case PEER_FT_UNSUPPRESS_MAP:
15906 return !!(filter->usmap.name);
7f7940e6
MK
15907 case PEER_FT_ADVERTISE_MAP:
15908 return !!(filter->advmap.aname
15909 && ((filter->advmap.condition == direct)
15910 && filter->advmap.cname));
dd65f45e
DL
15911 default:
15912 return false;
15913 }
15914}
15915
15916/* Return true if the addpath type is set for peer and different from
15917 * peer-group.
15918 */
3dc339cd
DA
15919static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
15920 safi_t safi)
dd65f45e
DL
15921{
15922 enum bgp_addpath_strat type, g_type;
15923
15924 type = peer->addpath_type[afi][safi];
15925
15926 if (type != BGP_ADDPATH_NONE) {
15927 if (peer_group_active(peer)) {
15928 g_type = peer->group->conf->addpath_type[afi][safi];
15929
15930 if (type != g_type)
3dc339cd 15931 return true;
dd65f45e 15932 else
3dc339cd 15933 return false;
dd65f45e
DL
15934 }
15935
3dc339cd 15936 return true;
dd65f45e
DL
15937 }
15938
3dc339cd 15939 return false;
dd65f45e
DL
15940}
15941
b9c7bc5a 15942/* This is part of the address-family block (unicast only) */
dd65f45e 15943static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
15944 afi_t afi)
15945{
b9c7bc5a 15946 int indent = 2;
ddb5b488 15947
8a066a70 15948 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
15949 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15950 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
15951 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
15952 bgp->vpn_policy[afi]
bb4f6190 15953 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
15954 else
15955 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
15956 bgp->vpn_policy[afi]
15957 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
15958 }
12a844a5
DS
15959 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15960 BGP_CONFIG_VRF_TO_VRF_IMPORT)
15961 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15962 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15963 return;
15964
e70e9f8e
PZ
15965 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15966 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
15967
15968 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
15969
15970 } else {
15971 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
15972 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
15973 bgp->vpn_policy[afi].tovpn_label);
15974 }
ddb5b488
PZ
15975 }
15976 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15977 BGP_VPN_POLICY_TOVPN_RD_SET)) {
15978 char buf[RD_ADDRSTRLEN];
b9c7bc5a 15979 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
15980 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
15981 sizeof(buf)));
15982 }
15983 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15984 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
15985
15986 char buf[PREFIX_STRLEN];
15987 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
15988 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
15989 sizeof(buf))) {
15990
b9c7bc5a
PZ
15991 vty_out(vty, "%*snexthop vpn export %s\n",
15992 indent, "", buf);
ddb5b488
PZ
15993 }
15994 }
15995 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
15996 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
15997 && ecommunity_cmp(
15998 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
15999 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16000
16001 char *b = ecommunity_ecom2str(
16002 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16003 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16004 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16005 XFREE(MTYPE_ECOMMUNITY_STR, b);
16006 } else {
16007 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16008 char *b = ecommunity_ecom2str(
16009 bgp->vpn_policy[afi]
16010 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16011 ECOMMUNITY_FORMAT_ROUTE_MAP,
16012 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16013 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16014 XFREE(MTYPE_ECOMMUNITY_STR, b);
16015 }
16016 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16017 char *b = ecommunity_ecom2str(
16018 bgp->vpn_policy[afi]
16019 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16020 ECOMMUNITY_FORMAT_ROUTE_MAP,
16021 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16022 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16023 XFREE(MTYPE_ECOMMUNITY_STR, b);
16024 }
16025 }
bb4f6190
DS
16026
16027 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16028 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16029 bgp->vpn_policy[afi]
16030 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16031
301ad80a
PG
16032 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16033 char *b = ecommunity_ecom2str(
16034 bgp->vpn_policy[afi]
16035 .import_redirect_rtlist,
16036 ECOMMUNITY_FORMAT_ROUTE_MAP,
16037 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16038
9a659715
PG
16039 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16040 != ECOMMUNITY_SIZE)
c6423c31 16041 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16042 indent, "", b);
16043 else
16044 vty_out(vty, "%*srt redirect import %s\n",
16045 indent, "", b);
301ad80a
PG
16046 XFREE(MTYPE_ECOMMUNITY_STR, b);
16047 }
ddb5b488
PZ
16048}
16049
dd65f45e
DL
16050static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16051 afi_t afi, safi_t safi)
16052{
16053 struct bgp_filter *filter;
16054 char *addr;
16055
16056 addr = peer->host;
16057 filter = &peer->filter[afi][safi];
16058
16059 /* distribute-list. */
16060 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16061 FILTER_IN))
16062 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16063 filter->dlist[FILTER_IN].name);
16064
16065 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16066 FILTER_OUT))
16067 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16068 filter->dlist[FILTER_OUT].name);
16069
16070 /* prefix-list. */
16071 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16072 FILTER_IN))
16073 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16074 filter->plist[FILTER_IN].name);
16075
16076 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16077 FILTER_OUT))
16078 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16079 filter->plist[FILTER_OUT].name);
16080
16081 /* route-map. */
16082 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16083 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16084 filter->map[RMAP_IN].name);
16085
16086 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16087 RMAP_OUT))
16088 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16089 filter->map[RMAP_OUT].name);
16090
16091 /* unsuppress-map */
16092 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16093 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16094 filter->usmap.name);
16095
7f7940e6
MK
16096 /* advertise-map : always applied in OUT direction*/
16097 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16098 CONDITION_NON_EXIST))
16099 vty_out(vty,
16100 " neighbor %s advertise-map %s non-exist-map %s\n",
16101 addr, filter->advmap.aname, filter->advmap.cname);
16102
16103 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16104 CONDITION_EXIST))
16105 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16106 addr, filter->advmap.aname, filter->advmap.cname);
16107
dd65f45e
DL
16108 /* filter-list. */
16109 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16110 FILTER_IN))
16111 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16112 filter->aslist[FILTER_IN].name);
16113
16114 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16115 FILTER_OUT))
16116 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16117 filter->aslist[FILTER_OUT].name);
16118}
16119
16120/* BGP peer configuration display function. */
16121static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16122 struct peer *peer)
16123{
16124 struct peer *g_peer = NULL;
16125 char buf[SU_ADDRSTRLEN];
16126 char *addr;
16127 int if_pg_printed = false;
16128 int if_ras_printed = false;
16129
16130 /* Skip dynamic neighbors. */
16131 if (peer_dynamic_neighbor(peer))
16132 return;
16133
16134 if (peer->conf_if)
16135 addr = peer->conf_if;
16136 else
16137 addr = peer->host;
16138
16139 /************************************
16140 ****** Global to the neighbor ******
16141 ************************************/
16142 if (peer->conf_if) {
16143 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16144 vty_out(vty, " neighbor %s interface v6only", addr);
16145 else
16146 vty_out(vty, " neighbor %s interface", addr);
16147
16148 if (peer_group_active(peer)) {
16149 vty_out(vty, " peer-group %s", peer->group->name);
16150 if_pg_printed = true;
16151 } else if (peer->as_type == AS_SPECIFIED) {
16152 vty_out(vty, " remote-as %u", peer->as);
16153 if_ras_printed = true;
16154 } else if (peer->as_type == AS_INTERNAL) {
16155 vty_out(vty, " remote-as internal");
16156 if_ras_printed = true;
16157 } else if (peer->as_type == AS_EXTERNAL) {
16158 vty_out(vty, " remote-as external");
16159 if_ras_printed = true;
16160 }
16161
16162 vty_out(vty, "\n");
16163 }
16164
16165 /* remote-as and peer-group */
16166 /* peer is a member of a peer-group */
16167 if (peer_group_active(peer)) {
16168 g_peer = peer->group->conf;
16169
16170 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16171 if (peer->as_type == AS_SPECIFIED) {
16172 vty_out(vty, " neighbor %s remote-as %u\n",
16173 addr, peer->as);
16174 } else if (peer->as_type == AS_INTERNAL) {
16175 vty_out(vty,
16176 " neighbor %s remote-as internal\n",
16177 addr);
16178 } else if (peer->as_type == AS_EXTERNAL) {
16179 vty_out(vty,
16180 " neighbor %s remote-as external\n",
16181 addr);
16182 }
16183 }
16184
16185 /* For swpX peers we displayed the peer-group
16186 * via 'neighbor swpX interface peer-group PGNAME' */
16187 if (!if_pg_printed)
16188 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16189 peer->group->name);
16190 }
16191
16192 /* peer is NOT a member of a peer-group */
16193 else {
16194 /* peer is a peer-group, declare the peer-group */
16195 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16196 vty_out(vty, " neighbor %s peer-group\n", addr);
16197 }
16198
16199 if (!if_ras_printed) {
16200 if (peer->as_type == AS_SPECIFIED) {
16201 vty_out(vty, " neighbor %s remote-as %u\n",
16202 addr, peer->as);
16203 } else if (peer->as_type == AS_INTERNAL) {
16204 vty_out(vty,
16205 " neighbor %s remote-as internal\n",
16206 addr);
16207 } else if (peer->as_type == AS_EXTERNAL) {
16208 vty_out(vty,
16209 " neighbor %s remote-as external\n",
16210 addr);
16211 }
16212 }
16213 }
16214
16215 /* local-as */
16216 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16217 vty_out(vty, " neighbor %s local-as %u", addr,
16218 peer->change_local_as);
16219 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16220 vty_out(vty, " no-prepend");
16221 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16222 vty_out(vty, " replace-as");
16223 vty_out(vty, "\n");
16224 }
16225
16226 /* description */
16227 if (peer->desc) {
16228 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16229 }
16230
16231 /* shutdown */
16232 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16233 if (peer->tx_shutdown_message)
16234 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16235 peer->tx_shutdown_message);
16236 else
16237 vty_out(vty, " neighbor %s shutdown\n", addr);
16238 }
16239
8336c896
DA
16240 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16241 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16242 peer->rtt_expected, peer->rtt_keepalive_conf);
16243
dd65f45e
DL
16244 /* bfd */
16245 if (peer->bfd_info) {
16246 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16247 bgp_bfd_peer_config_write(vty, peer, addr);
16248 }
16249 }
16250
16251 /* password */
16252 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16253 vty_out(vty, " neighbor %s password %s\n", addr,
16254 peer->password);
16255
16256 /* neighbor solo */
16257 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16258 if (!peer_group_active(peer)) {
16259 vty_out(vty, " neighbor %s solo\n", addr);
16260 }
16261 }
16262
16263 /* BGP port */
16264 if (peer->port != BGP_PORT_DEFAULT) {
16265 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16266 }
16267
16268 /* Local interface name */
16269 if (peer->ifname) {
16270 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16271 }
16272
16273 /* passive */
16274 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16275 vty_out(vty, " neighbor %s passive\n", addr);
16276
16277 /* ebgp-multihop */
16278 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16279 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16280 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16281 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16282 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16283 peer->ttl);
16284 }
16285 }
16286
16287 /* ttl-security hops */
e2521429 16288 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16289 if (!peer_group_active(peer)
16290 || g_peer->gtsm_hops != peer->gtsm_hops) {
16291 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16292 addr, peer->gtsm_hops);
16293 }
16294 }
16295
16296 /* disable-connected-check */
16297 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16298 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16299
16300 /* enforce-first-as */
16301 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16302 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16303
16304 /* update-source */
16305 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16306 if (peer->update_source)
16307 vty_out(vty, " neighbor %s update-source %s\n", addr,
16308 sockunion2str(peer->update_source, buf,
16309 SU_ADDRSTRLEN));
16310 else if (peer->update_if)
16311 vty_out(vty, " neighbor %s update-source %s\n", addr,
16312 peer->update_if);
16313 }
16314
16315 /* advertisement-interval */
16316 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16317 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16318 peer->routeadv);
16319
16320 /* timers */
16321 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16322 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16323 peer->keepalive, peer->holdtime);
16324
16325 /* timers connect */
16326 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16327 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16328 peer->connect);
5d5393b9
DL
16329 /* need special-case handling for changed default values due to
16330 * config profile / version (because there is no "timers bgp connect"
16331 * command, we need to save this per-peer :/)
16332 */
16333 else if (!peer_group_active(peer) && !peer->connect &&
16334 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16335 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16336 peer->bgp->default_connect_retry);
dd65f45e
DL
16337
16338 /* capability dynamic */
16339 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16340 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16341
16342 /* capability extended-nexthop */
16343 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16344 if (!peer->conf_if) {
16345 if (CHECK_FLAG(peer->flags_invert,
16346 PEER_FLAG_CAPABILITY_ENHE))
16347 vty_out(vty,
16348 " no neighbor %s capability extended-nexthop\n",
16349 addr);
16350 else
16351 vty_out(vty,
16352 " neighbor %s capability extended-nexthop\n",
16353 addr);
16354 }
16355 }
16356
16357 /* dont-capability-negotiation */
16358 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16359 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16360
16361 /* override-capability */
16362 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16363 vty_out(vty, " neighbor %s override-capability\n", addr);
16364
16365 /* strict-capability-match */
16366 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16367 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16368
16369 /* Sender side AS path loop detection. */
16370 if (peer->as_path_loop_detection)
16371 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16372 addr);
cfd47646 16373
16374 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16375 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16376
16377 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16378 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16379 vty_out(vty,
16380 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16381 } else if (CHECK_FLAG(
16382 peer->peer_gr_new_status_flag,
16383 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16384 vty_out(vty,
16385 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16386 } else if (
16387 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16388 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16389 && !(CHECK_FLAG(
16390 peer->peer_gr_new_status_flag,
16391 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16392 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16393 addr);
cfd47646 16394 }
16395 }
dd65f45e
DL
16396}
16397
16398/* BGP peer configuration display function. */
16399static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16400 struct peer *peer, afi_t afi, safi_t safi)
16401{
16402 struct peer *g_peer = NULL;
16403 char *addr;
16404 bool flag_scomm, flag_secomm, flag_slcomm;
16405
16406 /* Skip dynamic neighbors. */
16407 if (peer_dynamic_neighbor(peer))
16408 return;
16409
16410 if (peer->conf_if)
16411 addr = peer->conf_if;
16412 else
16413 addr = peer->host;
16414
16415 /************************************
16416 ****** Per AF to the neighbor ******
16417 ************************************/
16418 if (peer_group_active(peer)) {
16419 g_peer = peer->group->conf;
16420
16421 /* If the peer-group is active but peer is not, print a 'no
16422 * activate' */
16423 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16424 vty_out(vty, " no neighbor %s activate\n", addr);
16425 }
16426
16427 /* If the peer-group is not active but peer is, print an
16428 'activate' */
16429 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16430 vty_out(vty, " neighbor %s activate\n", addr);
16431 }
16432 } else {
16433 if (peer->afc[afi][safi]) {
16434 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16435 if (CHECK_FLAG(bgp->flags,
16436 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16437 vty_out(vty, " neighbor %s activate\n",
16438 addr);
16439 }
16440 } else
16441 vty_out(vty, " neighbor %s activate\n", addr);
16442 } else {
16443 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
16444 if (!CHECK_FLAG(bgp->flags,
16445 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
16446 vty_out(vty,
16447 " no neighbor %s activate\n",
16448 addr);
16449 }
16450 }
16451 }
16452 }
16453
16454 /* addpath TX knobs */
16455 if (peergroup_af_addpath_check(peer, afi, safi)) {
16456 switch (peer->addpath_type[afi][safi]) {
16457 case BGP_ADDPATH_ALL:
16458 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16459 addr);
16460 break;
16461 case BGP_ADDPATH_BEST_PER_AS:
16462 vty_out(vty,
16463 " neighbor %s addpath-tx-bestpath-per-AS\n",
16464 addr);
16465 break;
16466 case BGP_ADDPATH_MAX:
16467 case BGP_ADDPATH_NONE:
16468 break;
16469 }
16470 }
16471
16472 /* ORF capability. */
16473 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16474 || peergroup_af_flag_check(peer, afi, safi,
16475 PEER_FLAG_ORF_PREFIX_RM)) {
16476 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16477
16478 if (peergroup_af_flag_check(peer, afi, safi,
16479 PEER_FLAG_ORF_PREFIX_SM)
16480 && peergroup_af_flag_check(peer, afi, safi,
16481 PEER_FLAG_ORF_PREFIX_RM))
16482 vty_out(vty, " both");
16483 else if (peergroup_af_flag_check(peer, afi, safi,
16484 PEER_FLAG_ORF_PREFIX_SM))
16485 vty_out(vty, " send");
16486 else
16487 vty_out(vty, " receive");
16488 vty_out(vty, "\n");
16489 }
16490
dd65f45e
DL
16491 /* Route reflector client. */
16492 if (peergroup_af_flag_check(peer, afi, safi,
16493 PEER_FLAG_REFLECTOR_CLIENT)) {
16494 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16495 }
16496
16497 /* next-hop-self force */
16498 if (peergroup_af_flag_check(peer, afi, safi,
16499 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16500 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16501 }
16502
16503 /* next-hop-self */
16504 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16505 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16506 }
16507
16508 /* remove-private-AS */
16509 if (peergroup_af_flag_check(peer, afi, safi,
16510 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16511 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16512 addr);
16513 }
16514
16515 else if (peergroup_af_flag_check(peer, afi, safi,
16516 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16517 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16518 addr);
16519 }
16520
16521 else if (peergroup_af_flag_check(peer, afi, safi,
16522 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16523 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16524 }
16525
16526 else if (peergroup_af_flag_check(peer, afi, safi,
16527 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16528 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16529 }
16530
16531 /* as-override */
16532 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16533 vty_out(vty, " neighbor %s as-override\n", addr);
16534 }
16535
16536 /* send-community print. */
16537 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16538 PEER_FLAG_SEND_COMMUNITY);
16539 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16540 PEER_FLAG_SEND_EXT_COMMUNITY);
16541 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16542 PEER_FLAG_SEND_LARGE_COMMUNITY);
16543
16544 if (flag_scomm && flag_secomm && flag_slcomm) {
16545 vty_out(vty, " no neighbor %s send-community all\n", addr);
16546 } else {
16547 if (flag_scomm)
16548 vty_out(vty, " no neighbor %s send-community\n", addr);
16549 if (flag_secomm)
16550 vty_out(vty,
16551 " no neighbor %s send-community extended\n",
16552 addr);
16553
16554 if (flag_slcomm)
16555 vty_out(vty, " no neighbor %s send-community large\n",
16556 addr);
16557 }
16558
16559 /* Default information */
16560 if (peergroup_af_flag_check(peer, afi, safi,
16561 PEER_FLAG_DEFAULT_ORIGINATE)) {
16562 vty_out(vty, " neighbor %s default-originate", addr);
16563
16564 if (peer->default_rmap[afi][safi].name)
16565 vty_out(vty, " route-map %s",
16566 peer->default_rmap[afi][safi].name);
16567
16568 vty_out(vty, "\n");
16569 }
16570
16571 /* Soft reconfiguration inbound. */
16572 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16573 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16574 addr);
16575 }
16576
16577 /* maximum-prefix. */
16578 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16579 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16580 peer->pmax[afi][safi]);
16581
16582 if (peer->pmax_threshold[afi][safi]
16583 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16584 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16585 if (peer_af_flag_check(peer, afi, safi,
16586 PEER_FLAG_MAX_PREFIX_WARNING))
16587 vty_out(vty, " warning-only");
16588 if (peer->pmax_restart[afi][safi])
16589 vty_out(vty, " restart %u",
16590 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16591 if (peer_af_flag_check(peer, afi, safi,
16592 PEER_FLAG_MAX_PREFIX_FORCE))
16593 vty_out(vty, " force");
dd65f45e
DL
16594
16595 vty_out(vty, "\n");
16596 }
16597
fde246e8
DA
16598 /* maximum-prefix-out */
16599 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16600 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16601 addr, peer->pmax_out[afi][safi]);
16602
dd65f45e
DL
16603 /* Route server client. */
16604 if (peergroup_af_flag_check(peer, afi, safi,
16605 PEER_FLAG_RSERVER_CLIENT)) {
16606 vty_out(vty, " neighbor %s route-server-client\n", addr);
16607 }
16608
16609 /* Nexthop-local unchanged. */
16610 if (peergroup_af_flag_check(peer, afi, safi,
16611 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16612 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16613 }
16614
16615 /* allowas-in <1-10> */
16616 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16617 if (peer_af_flag_check(peer, afi, safi,
16618 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16619 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16620 } else if (peer->allowas_in[afi][safi] == 3) {
16621 vty_out(vty, " neighbor %s allowas-in\n", addr);
16622 } else {
16623 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16624 peer->allowas_in[afi][safi]);
16625 }
16626 }
16627
16628 /* weight */
16629 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16630 vty_out(vty, " neighbor %s weight %lu\n", addr,
16631 peer->weight[afi][safi]);
16632
16633 /* Filter. */
16634 bgp_config_write_filter(vty, peer, afi, safi);
16635
16636 /* atribute-unchanged. */
16637 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16638 || (safi != SAFI_EVPN
16639 && peer_af_flag_check(peer, afi, safi,
16640 PEER_FLAG_NEXTHOP_UNCHANGED))
16641 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16642
16643 if (!peer_group_active(peer)
16644 || peergroup_af_flag_check(peer, afi, safi,
16645 PEER_FLAG_AS_PATH_UNCHANGED)
16646 || peergroup_af_flag_check(peer, afi, safi,
16647 PEER_FLAG_NEXTHOP_UNCHANGED)
16648 || peergroup_af_flag_check(peer, afi, safi,
16649 PEER_FLAG_MED_UNCHANGED)) {
16650
16651 vty_out(vty,
16652 " neighbor %s attribute-unchanged%s%s%s\n",
16653 addr,
16654 peer_af_flag_check(peer, afi, safi,
16655 PEER_FLAG_AS_PATH_UNCHANGED)
16656 ? " as-path"
16657 : "",
16658 peer_af_flag_check(peer, afi, safi,
16659 PEER_FLAG_NEXTHOP_UNCHANGED)
16660 ? " next-hop"
16661 : "",
16662 peer_af_flag_check(peer, afi, safi,
16663 PEER_FLAG_MED_UNCHANGED)
16664 ? " med"
16665 : "");
16666 }
16667 }
16668}
16669
16670/* Address family based peer configuration display. */
16671static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16672 safi_t safi)
16673{
16674 struct peer *peer;
16675 struct peer_group *group;
16676 struct listnode *node, *nnode;
16677
16678
16679 vty_frame(vty, " !\n address-family ");
16680 if (afi == AFI_IP) {
16681 if (safi == SAFI_UNICAST)
16682 vty_frame(vty, "ipv4 unicast");
16683 else if (safi == SAFI_LABELED_UNICAST)
16684 vty_frame(vty, "ipv4 labeled-unicast");
16685 else if (safi == SAFI_MULTICAST)
16686 vty_frame(vty, "ipv4 multicast");
16687 else if (safi == SAFI_MPLS_VPN)
16688 vty_frame(vty, "ipv4 vpn");
16689 else if (safi == SAFI_ENCAP)
16690 vty_frame(vty, "ipv4 encap");
16691 else if (safi == SAFI_FLOWSPEC)
16692 vty_frame(vty, "ipv4 flowspec");
16693 } else if (afi == AFI_IP6) {
16694 if (safi == SAFI_UNICAST)
16695 vty_frame(vty, "ipv6 unicast");
16696 else if (safi == SAFI_LABELED_UNICAST)
16697 vty_frame(vty, "ipv6 labeled-unicast");
16698 else if (safi == SAFI_MULTICAST)
16699 vty_frame(vty, "ipv6 multicast");
16700 else if (safi == SAFI_MPLS_VPN)
16701 vty_frame(vty, "ipv6 vpn");
16702 else if (safi == SAFI_ENCAP)
16703 vty_frame(vty, "ipv6 encap");
16704 else if (safi == SAFI_FLOWSPEC)
16705 vty_frame(vty, "ipv6 flowspec");
16706 } else if (afi == AFI_L2VPN) {
16707 if (safi == SAFI_EVPN)
16708 vty_frame(vty, "l2vpn evpn");
16709 }
16710 vty_frame(vty, "\n");
16711
16712 bgp_config_write_distance(vty, bgp, afi, safi);
16713
16714 bgp_config_write_network(vty, bgp, afi, safi);
16715
16716 bgp_config_write_redistribute(vty, bgp, afi, safi);
16717
8a4e7fe6
DA
16718 /* BGP flag dampening. */
16719 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
16720 bgp_config_write_damp(vty, afi, safi);
16721
dd65f45e
DL
16722 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16723 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16724
16725 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16726 /* Skip dynamic neighbors. */
16727 if (peer_dynamic_neighbor(peer))
16728 continue;
16729
16730 /* Do not display doppelganger peers */
16731 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16732 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16733 }
16734
16735 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16736 bgp_config_write_table_map(vty, bgp, afi, safi);
16737
16738 if (safi == SAFI_EVPN)
16739 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16740
16741 if (safi == SAFI_FLOWSPEC)
16742 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16743
16744 if (safi == SAFI_UNICAST) {
16745 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16746 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16747 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16748
16749 vty_out(vty, " export vpn\n");
16750 }
16751 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16752 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16753
16754 vty_out(vty, " import vpn\n");
16755 }
16756 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16757 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16758 char *name;
16759
16760 for (ALL_LIST_ELEMENTS_RO(
16761 bgp->vpn_policy[afi].import_vrf, node,
16762 name))
16763 vty_out(vty, " import vrf %s\n", name);
16764 }
16765 }
16766
16767 vty_endframe(vty, " exit-address-family\n");
16768}
16769
16770int bgp_config_write(struct vty *vty)
16771{
16772 struct bgp *bgp;
16773 struct peer_group *group;
16774 struct peer *peer;
16775 struct listnode *node, *nnode;
16776 struct listnode *mnode, *mnnode;
16777
16778 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16779 vty_out(vty, "bgp route-map delay-timer %u\n",
16780 bm->rmap_update_timer);
16781
d70583f7
D
16782 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16783 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16784 if (bm->v_update_delay != bm->v_establish_wait)
16785 vty_out(vty, " %d", bm->v_establish_wait);
16786 vty_out(vty, "\n");
16787 }
16788
05bd726c 16789 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16790 vty_out(vty, "bgp graceful-shutdown\n");
16791
c163f297
DS
16792 /* No-RIB (Zebra) option flag configuration */
16793 if (bgp_option_check(BGP_OPT_NO_FIB))
16794 vty_out(vty, "bgp no-rib\n");
16795
dd65f45e
DL
16796 /* BGP configuration. */
16797 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
16798
16799 /* skip all auto created vrf as they dont have user config */
16800 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
16801 continue;
16802
16803 /* Router bgp ASN */
16804 vty_out(vty, "router bgp %u", bgp->as);
16805
16806 if (bgp->name)
16807 vty_out(vty, " %s %s",
16808 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
16809 ? "view" : "vrf", bgp->name);
16810 vty_out(vty, "\n");
16811
16812 /* BGP fast-external-failover. */
16813 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
16814 vty_out(vty, " no bgp fast-external-failover\n");
16815
16816 /* BGP router ID. */
16817 if (bgp->router_id_static.s_addr != 0)
23d0a753
DA
16818 vty_out(vty, " bgp router-id %pI4\n",
16819 &bgp->router_id_static);
dd65f45e
DL
16820
16821 /* BGP log-neighbor-changes. */
892fedb6 16822 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 16823 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 16824 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
16825 CHECK_FLAG(bgp->flags,
16826 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
16827 ? ""
16828 : "no ");
16829
16830 /* BGP configuration. */
892fedb6 16831 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
16832 vty_out(vty, " bgp always-compare-med\n");
16833
16834 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
16835 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
16836 != SAVE_BGP_EBGP_REQUIRES_POLICY)
16837 vty_out(vty, " %sbgp ebgp-requires-policy\n",
16838 CHECK_FLAG(bgp->flags,
16839 BGP_FLAG_EBGP_REQUIRES_POLICY)
16840 ? ""
16841 : "no ");
dd65f45e
DL
16842
16843 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 16844 if (bgp->reject_as_sets)
dd65f45e
DL
16845 vty_out(vty, " bgp reject-as-sets\n");
16846
16847 /* BGP default ipv4-unicast. */
892fedb6 16848 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
16849 vty_out(vty, " no bgp default ipv4-unicast\n");
16850
16851 /* BGP default local-preference. */
16852 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
16853 vty_out(vty, " bgp default local-preference %u\n",
16854 bgp->default_local_pref);
16855
16856 /* BGP default show-hostname */
892fedb6 16857 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 16858 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 16859 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 16860 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
16861 ? ""
16862 : "no ");
16863
aef999a2
DA
16864 /* BGP default show-nexthop-hostname */
16865 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16866 != SAVE_BGP_SHOW_HOSTNAME)
16867 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
16868 CHECK_FLAG(bgp->flags,
16869 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16870 ? ""
16871 : "no ");
16872
dd65f45e
DL
16873 /* BGP default subgroup-pkt-queue-max. */
16874 if (bgp->default_subgroup_pkt_queue_max
16875 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
16876 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
16877 bgp->default_subgroup_pkt_queue_max);
16878
16879 /* BGP client-to-client reflection. */
892fedb6 16880 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
16881 vty_out(vty, " no bgp client-to-client reflection\n");
16882
16883 /* BGP cluster ID. */
16884 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
16885 vty_out(vty, " bgp cluster-id %pI4\n",
16886 &bgp->cluster_id);
dd65f45e
DL
16887
16888 /* Disable ebgp connected nexthop check */
892fedb6 16889 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
16890 vty_out(vty,
16891 " bgp disable-ebgp-connected-route-check\n");
16892
16893 /* Confederation identifier*/
16894 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
16895 vty_out(vty, " bgp confederation identifier %u\n",
16896 bgp->confed_id);
16897
16898 /* Confederation peer */
16899 if (bgp->confed_peers_cnt > 0) {
16900 int i;
16901
16902 vty_out(vty, " bgp confederation peers");
16903
16904 for (i = 0; i < bgp->confed_peers_cnt; i++)
16905 vty_out(vty, " %u", bgp->confed_peers[i]);
16906
16907 vty_out(vty, "\n");
16908 }
16909
16910 /* BGP deterministic-med. */
892fedb6 16911 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 16912 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 16913 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
16914 CHECK_FLAG(bgp->flags,
16915 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
16916 ? ""
16917 : "no ");
16918
16919 /* BGP update-delay. */
16920 bgp_config_write_update_delay(vty, bgp);
16921
16922 if (bgp->v_maxmed_onstartup
16923 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
16924 vty_out(vty, " bgp max-med on-startup %u",
16925 bgp->v_maxmed_onstartup);
16926 if (bgp->maxmed_onstartup_value
16927 != BGP_MAXMED_VALUE_DEFAULT)
16928 vty_out(vty, " %u",
16929 bgp->maxmed_onstartup_value);
16930 vty_out(vty, "\n");
16931 }
16932 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
16933 vty_out(vty, " bgp max-med administrative");
16934 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
16935 vty_out(vty, " %u", bgp->maxmed_admin_value);
16936 vty_out(vty, "\n");
16937 }
16938
16939 /* write quanta */
16940 bgp_config_write_wpkt_quanta(vty, bgp);
16941 /* read quanta */
16942 bgp_config_write_rpkt_quanta(vty, bgp);
16943
16944 /* coalesce time */
16945 bgp_config_write_coalesce_time(vty, bgp);
16946
05bd726c 16947 /* BGP per-instance graceful-shutdown */
16948 /* BGP-wide settings and per-instance settings are mutually
16949 * exclusive.
16950 */
16951 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16952 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
16953 vty_out(vty, " bgp graceful-shutdown\n");
16954
dd65f45e
DL
16955 /* BGP graceful-restart. */
16956 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
16957 vty_out(vty,
16958 " bgp graceful-restart stalepath-time %u\n",
16959 bgp->stalepath_time);
cfd47646 16960
dd65f45e
DL
16961 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
16962 vty_out(vty, " bgp graceful-restart restart-time %u\n",
16963 bgp->restart_time);
cfd47646 16964
16965 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
16966 vty_out(vty,
16967 " bgp graceful-restart select-defer-time %u\n",
16968 bgp->select_defer_time);
16969
16970 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
16971 vty_out(vty, " bgp graceful-restart\n");
16972
cfd47646 16973 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
16974 vty_out(vty, " bgp graceful-restart-disable\n");
16975
dd65f45e 16976 /* BGP graceful-restart Preserve State F bit. */
892fedb6 16977 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
16978 vty_out(vty,
16979 " bgp graceful-restart preserve-fw-state\n");
16980
dc95985f 16981 /* Stale timer for RIB */
16982 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
16983 vty_out(vty,
16984 " bgp graceful-restart rib-stale-time %u\n",
16985 bgp->rib_stale_time);
16986
dd65f45e 16987 /* BGP bestpath method. */
892fedb6 16988 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 16989 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 16990 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
16991 vty_out(vty, " bgp bestpath as-path confed\n");
16992
892fedb6
DA
16993 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
16994 if (CHECK_FLAG(bgp->flags,
16995 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
16996 vty_out(vty,
16997 " bgp bestpath as-path multipath-relax as-set\n");
16998 } else {
16999 vty_out(vty,
17000 " bgp bestpath as-path multipath-relax\n");
17001 }
17002 }
17003
892fedb6 17004 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17005 vty_out(vty,
17006 " bgp route-reflector allow-outbound-policy\n");
17007 }
892fedb6 17008 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17009 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17010 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17011 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17012 vty_out(vty, " bgp bestpath med");
892fedb6 17013 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17014 vty_out(vty, " confed");
892fedb6
DA
17015 if (CHECK_FLAG(bgp->flags,
17016 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17017 vty_out(vty, " missing-as-worst");
17018 vty_out(vty, "\n");
17019 }
17020
f7e1c681 17021 /* Link bandwidth handling. */
17022 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17023 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17024 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17025 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17026 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17027 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17028
dd65f45e 17029 /* BGP network import check. */
892fedb6 17030 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17031 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17032 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17033 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17034 ? ""
17035 : "no ");
17036
17037 /* BGP timers configuration. */
5d5393b9
DL
17038 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17039 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17040 vty_out(vty, " timers bgp %u %u\n",
17041 bgp->default_keepalive, bgp->default_holdtime);
17042
17043 /* peer-group */
17044 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17045 bgp_config_write_peer_global(vty, bgp, group->conf);
17046 }
17047
17048 /* Normal neighbor configuration. */
17049 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17050 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17051 bgp_config_write_peer_global(vty, bgp, peer);
17052 }
17053
17054 /* listen range and limit for dynamic BGP neighbors */
17055 bgp_config_write_listen(vty, bgp);
17056
17057 /*
17058 * BGP default autoshutdown neighbors
17059 *
17060 * This must be placed after any peer and peer-group
17061 * configuration, to avoid setting all peers to shutdown after
17062 * a daemon restart, which is undesired behavior. (see #2286)
17063 */
17064 if (bgp->autoshutdown)
17065 vty_out(vty, " bgp default shutdown\n");
17066
9cf59432
DS
17067 /* BGP instance administrative shutdown */
17068 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17069 vty_out(vty, " bgp shutdown\n");
17070
dd65f45e
DL
17071 /* IPv4 unicast configuration. */
17072 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17073
17074 /* IPv4 multicast configuration. */
17075 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17076
17077 /* IPv4 labeled-unicast configuration. */
17078 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17079
17080 /* IPv4 VPN configuration. */
17081 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17082
17083 /* ENCAPv4 configuration. */
17084 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17085
17086 /* FLOWSPEC v4 configuration. */
17087 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17088
17089 /* IPv6 unicast configuration. */
17090 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17091
17092 /* IPv6 multicast configuration. */
17093 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17094
17095 /* IPv6 labeled-unicast configuration. */
17096 bgp_config_write_family(vty, bgp, AFI_IP6,
17097 SAFI_LABELED_UNICAST);
17098
17099 /* IPv6 VPN configuration. */
17100 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17101
17102 /* ENCAPv6 configuration. */
17103 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17104
17105 /* FLOWSPEC v6 configuration. */
17106 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17107
17108 /* EVPN configuration. */
17109 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17110
17111 hook_call(bgp_inst_config_write, bgp, vty);
17112
49e5a4a0 17113#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17114 bgp_rfapi_cfg_write(vty, bgp);
17115#endif
17116
17117 vty_out(vty, "!\n");
17118 }
17119 return 0;
17120}
17121
ddb5b488 17122
718e3744 17123/* BGP node structure. */
d62a17ae 17124static struct cmd_node bgp_node = {
f4b8291f 17125 .name = "bgp",
62b346ee 17126 .node = BGP_NODE,
24389580 17127 .parent_node = CONFIG_NODE,
62b346ee 17128 .prompt = "%s(config-router)# ",
612c2c15 17129 .config_write = bgp_config_write,
718e3744 17130};
17131
d62a17ae 17132static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17133 .name = "bgp ipv4 unicast",
62b346ee 17134 .node = BGP_IPV4_NODE,
24389580 17135 .parent_node = BGP_NODE,
62b346ee 17136 .prompt = "%s(config-router-af)# ",
718e3744 17137};
17138
d62a17ae 17139static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17140 .name = "bgp ipv4 multicast",
62b346ee 17141 .node = BGP_IPV4M_NODE,
24389580 17142 .parent_node = BGP_NODE,
62b346ee 17143 .prompt = "%s(config-router-af)# ",
718e3744 17144};
17145
d62a17ae 17146static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17147 .name = "bgp ipv4 labeled unicast",
62b346ee 17148 .node = BGP_IPV4L_NODE,
24389580 17149 .parent_node = BGP_NODE,
62b346ee 17150 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17151};
17152
d62a17ae 17153static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 17154 .name = "bgp ipv6",
62b346ee 17155 .node = BGP_IPV6_NODE,
24389580 17156 .parent_node = BGP_NODE,
62b346ee 17157 .prompt = "%s(config-router-af)# ",
718e3744 17158};
17159
d62a17ae 17160static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17161 .name = "bgp ipv6 multicast",
62b346ee 17162 .node = BGP_IPV6M_NODE,
24389580 17163 .parent_node = BGP_NODE,
62b346ee 17164 .prompt = "%s(config-router-af)# ",
25ffbdc1 17165};
17166
d62a17ae 17167static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17168 .name = "bgp ipv6 labeled unicast",
62b346ee 17169 .node = BGP_IPV6L_NODE,
24389580 17170 .parent_node = BGP_NODE,
62b346ee 17171 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17172};
17173
62b346ee 17174static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17175 .name = "bgp vpnv4",
62b346ee 17176 .node = BGP_VPNV4_NODE,
24389580 17177 .parent_node = BGP_NODE,
62b346ee 17178 .prompt = "%s(config-router-af)# ",
62b346ee 17179};
6b0655a2 17180
62b346ee 17181static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17182 .name = "bgp vpnv6",
62b346ee 17183 .node = BGP_VPNV6_NODE,
24389580 17184 .parent_node = BGP_NODE,
62b346ee 17185 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17186};
8ecd3266 17187
62b346ee 17188static struct cmd_node bgp_evpn_node = {
f4b8291f 17189 .name = "bgp evpn",
62b346ee 17190 .node = BGP_EVPN_NODE,
24389580 17191 .parent_node = BGP_NODE,
62b346ee 17192 .prompt = "%s(config-router-evpn)# ",
62b346ee 17193};
4e0b7b6d 17194
62b346ee 17195static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17196 .name = "bgp evpn vni",
62b346ee 17197 .node = BGP_EVPN_VNI_NODE,
24389580 17198 .parent_node = BGP_EVPN_NODE,
62b346ee 17199 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17200};
90e60aa7 17201
62b346ee 17202static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17203 .name = "bgp ipv4 flowspec",
62b346ee 17204 .node = BGP_FLOWSPECV4_NODE,
24389580 17205 .parent_node = BGP_NODE,
62b346ee 17206 .prompt = "%s(config-router-af)# ",
62b346ee 17207};
7c40bf39 17208
62b346ee 17209static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17210 .name = "bgp ipv6 flowspec",
62b346ee 17211 .node = BGP_FLOWSPECV6_NODE,
24389580 17212 .parent_node = BGP_NODE,
62b346ee 17213 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17214};
7c40bf39 17215
d62a17ae 17216static void community_list_vty(void);
1f8ae70b 17217
d62a17ae 17218static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 17219{
d62a17ae 17220 struct bgp *bgp;
17221 struct peer *peer;
d62a17ae 17222 struct listnode *lnbgp, *lnpeer;
b8a815e5 17223
d62a17ae 17224 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17225 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17226 /* only provide suggestions on the appropriate input
17227 * token type,
17228 * they'll otherwise show up multiple times */
17229 enum cmd_token_type match_type;
17230 char *name = peer->host;
d48ed3e0 17231
d62a17ae 17232 if (peer->conf_if) {
17233 match_type = VARIABLE_TKN;
17234 name = peer->conf_if;
17235 } else if (strchr(peer->host, ':'))
17236 match_type = IPV6_TKN;
17237 else
17238 match_type = IPV4_TKN;
d48ed3e0 17239
d62a17ae 17240 if (token->type != match_type)
17241 continue;
d48ed3e0 17242
d62a17ae 17243 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17244 }
d62a17ae 17245 }
b8a815e5
DL
17246}
17247
17248static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17249 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17250 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17251 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17252 {.completions = NULL}};
17253
47a306a0
DS
17254static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17255{
17256 struct bgp *bgp;
17257 struct peer_group *group;
17258 struct listnode *lnbgp, *lnpeer;
17259
17260 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17261 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17262 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17263 group->name));
17264 }
17265}
17266
17267static const struct cmd_variable_handler bgp_var_peergroup[] = {
17268 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17269 {.completions = NULL} };
17270
d62a17ae 17271void bgp_vty_init(void)
17272{
17273 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17274 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17275
17276 /* Install bgp top node. */
612c2c15
DL
17277 install_node(&bgp_node);
17278 install_node(&bgp_ipv4_unicast_node);
17279 install_node(&bgp_ipv4_multicast_node);
17280 install_node(&bgp_ipv4_labeled_unicast_node);
17281 install_node(&bgp_ipv6_unicast_node);
17282 install_node(&bgp_ipv6_multicast_node);
17283 install_node(&bgp_ipv6_labeled_unicast_node);
17284 install_node(&bgp_vpnv4_node);
17285 install_node(&bgp_vpnv6_node);
17286 install_node(&bgp_evpn_node);
17287 install_node(&bgp_evpn_vni_node);
17288 install_node(&bgp_flowspecv4_node);
17289 install_node(&bgp_flowspecv6_node);
d62a17ae 17290
17291 /* Install default VTY commands to new nodes. */
17292 install_default(BGP_NODE);
17293 install_default(BGP_IPV4_NODE);
17294 install_default(BGP_IPV4M_NODE);
17295 install_default(BGP_IPV4L_NODE);
17296 install_default(BGP_IPV6_NODE);
17297 install_default(BGP_IPV6M_NODE);
17298 install_default(BGP_IPV6L_NODE);
17299 install_default(BGP_VPNV4_NODE);
17300 install_default(BGP_VPNV6_NODE);
7c40bf39 17301 install_default(BGP_FLOWSPECV4_NODE);
17302 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17303 install_default(BGP_EVPN_NODE);
17304 install_default(BGP_EVPN_VNI_NODE);
17305
8029b216
AK
17306 /* "bgp local-mac" hidden commands. */
17307 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17308 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17309
d62a17ae 17310 /* bgp route-map delay-timer commands. */
17311 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17312 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17313
d70583f7
D
17314 /* global bgp update-delay command */
17315 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17316 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17317
05bd726c 17318 /* global bgp graceful-shutdown command */
17319 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17320 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17321
d62a17ae 17322 /* Dummy commands (Currently not supported) */
17323 install_element(BGP_NODE, &no_synchronization_cmd);
17324 install_element(BGP_NODE, &no_auto_summary_cmd);
17325
17326 /* "router bgp" commands. */
17327 install_element(CONFIG_NODE, &router_bgp_cmd);
17328
17329 /* "no router bgp" commands. */
17330 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17331
17332 /* "bgp router-id" commands. */
17333 install_element(BGP_NODE, &bgp_router_id_cmd);
17334 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17335
17336 /* "bgp cluster-id" commands. */
17337 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17338 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17339
c163f297
DS
17340 /* "bgp no-rib" commands. */
17341 install_element(CONFIG_NODE, &bgp_norib_cmd);
17342 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17343
d62a17ae 17344 /* "bgp confederation" commands. */
17345 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17346 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17347
17348 /* "bgp confederation peers" commands. */
17349 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17350 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17351
17352 /* bgp max-med command */
17353 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17354 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17355 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17356 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17357 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17358
17359 /* bgp disable-ebgp-connected-nh-check */
17360 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17361 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17362
17363 /* bgp update-delay command */
17364 install_element(BGP_NODE, &bgp_update_delay_cmd);
17365 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17366
17367 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17368 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17369
17370 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17371 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17372
17373 /* "maximum-paths" commands. */
17374 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17375 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17376 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17377 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17378 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17379 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17380 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17381 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17382 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17383 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17384 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17385 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17386 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17387 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17388 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17389
39edabac
PG
17390 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17391 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17392 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17393 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17394 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17395 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17396 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17397 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17398 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17399 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17400
17401 /* "timers bgp" commands. */
17402 install_element(BGP_NODE, &bgp_timers_cmd);
17403 install_element(BGP_NODE, &no_bgp_timers_cmd);
17404
17405 /* route-map delay-timer commands - per instance for backwards compat.
17406 */
17407 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17408 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17409
17410 /* "bgp client-to-client reflection" commands */
17411 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17412 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17413
17414 /* "bgp always-compare-med" commands */
17415 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17416 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17417
9dac9fc8
DA
17418 /* bgp ebgp-requires-policy */
17419 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17420 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17421
fb29348a
DA
17422 /* bgp reject-as-sets */
17423 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17424 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17425
d62a17ae 17426 /* "bgp deterministic-med" commands */
17427 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17428 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17429
055679e9 17430 /* "bgp graceful-restart" command */
36235319
QY
17431 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17432 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17433
17434 /* "bgp graceful-restart-disable" command */
36235319
QY
17435 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17436 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17437
17438 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17439 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17440 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17441
17442 /* "neighbor a:b:c:d graceful-restart-disable" command */
17443 install_element(BGP_NODE,
17444 &bgp_neighbor_graceful_restart_disable_set_cmd);
17445 install_element(BGP_NODE,
17446 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17447
17448 /* "neighbor a:b:c:d graceful-restart-helper" command */
17449 install_element(BGP_NODE,
17450 &bgp_neighbor_graceful_restart_helper_set_cmd);
17451 install_element(BGP_NODE,
17452 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17453
d62a17ae 17454 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17455 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17456 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17457 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17458 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17459 install_element(BGP_NODE,
17460 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17461 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17462 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17463
d6e3c15b 17464 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17465 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17466 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17467 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17468
7f323236
DW
17469 /* "bgp graceful-shutdown" commands */
17470 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17471 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17472
d62a17ae 17473 /* "bgp fast-external-failover" commands */
17474 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17475 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17476
d62a17ae 17477 /* "bgp bestpath compare-routerid" commands */
17478 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17479 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17480
17481 /* "bgp bestpath as-path ignore" commands */
17482 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17483 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17484
17485 /* "bgp bestpath as-path confed" commands */
17486 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17487 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17488
17489 /* "bgp bestpath as-path multipath-relax" commands */
17490 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17491 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17492
17493 /* "bgp log-neighbor-changes" commands */
17494 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17495 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17496
17497 /* "bgp bestpath med" commands */
17498 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17499 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17500
f7e1c681 17501 /* "bgp bestpath bandwidth" commands */
17502 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17503 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17504
d62a17ae 17505 /* "no bgp default ipv4-unicast" commands. */
17506 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17507 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17508
17509 /* "bgp network import-check" commands. */
17510 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17511 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17512 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17513
17514 /* "bgp default local-preference" commands. */
17515 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17516 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17517
17518 /* bgp default show-hostname */
17519 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17520 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17521
aef999a2
DA
17522 /* bgp default show-nexthop-hostname */
17523 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17524 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17525
d62a17ae 17526 /* "bgp default subgroup-pkt-queue-max" commands. */
17527 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17528 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17529
17530 /* bgp ibgp-allow-policy-mods command */
17531 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17532 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17533
17534 /* "bgp listen limit" commands. */
17535 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17536 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17537
17538 /* "bgp listen range" commands. */
17539 install_element(BGP_NODE, &bgp_listen_range_cmd);
17540 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17541
8175f54a 17542 /* "bgp default shutdown" command */
f26845f9 17543 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17544
17545 /* "bgp shutdown" commands */
17546 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17547 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17548 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17549 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17550
d62a17ae 17551 /* "neighbor remote-as" commands. */
17552 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17553 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17554 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17555 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17556 install_element(BGP_NODE,
17557 &neighbor_interface_v6only_config_remote_as_cmd);
17558 install_element(BGP_NODE, &no_neighbor_cmd);
17559 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17560
17561 /* "neighbor peer-group" commands. */
17562 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17563 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17564 install_element(BGP_NODE,
17565 &no_neighbor_interface_peer_group_remote_as_cmd);
17566
17567 /* "neighbor local-as" commands. */
17568 install_element(BGP_NODE, &neighbor_local_as_cmd);
17569 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17570 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17571 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17572
17573 /* "neighbor solo" commands. */
17574 install_element(BGP_NODE, &neighbor_solo_cmd);
17575 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17576
17577 /* "neighbor password" commands. */
17578 install_element(BGP_NODE, &neighbor_password_cmd);
17579 install_element(BGP_NODE, &no_neighbor_password_cmd);
17580
17581 /* "neighbor activate" commands. */
17582 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17583 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17584 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17585 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17586 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17587 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17588 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17589 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17590 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17591 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17592 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17593 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17594
17595 /* "no neighbor activate" commands. */
17596 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17597 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17598 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17599 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17600 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17601 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17602 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17603 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17604 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 17605 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17606 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 17607 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17608
17609 /* "neighbor peer-group" set commands. */
17610 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17611 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17612 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17613 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17614 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17615 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17616 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17617 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 17618 install_element(BGP_FLOWSPECV4_NODE,
17619 &neighbor_set_peer_group_hidden_cmd);
17620 install_element(BGP_FLOWSPECV6_NODE,
17621 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 17622
17623 /* "no neighbor peer-group unset" commands. */
17624 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17625 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17626 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17627 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17628 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17629 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17630 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17631 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 17632 install_element(BGP_FLOWSPECV4_NODE,
17633 &no_neighbor_set_peer_group_hidden_cmd);
17634 install_element(BGP_FLOWSPECV6_NODE,
17635 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 17636
17637 /* "neighbor softreconfiguration inbound" commands.*/
17638 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17639 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17640 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17641 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17642 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17643 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17644 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17645 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17646 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17647 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17648 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17649 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17650 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17651 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17652 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17653 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17654 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17655 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 17656 install_element(BGP_FLOWSPECV4_NODE,
17657 &neighbor_soft_reconfiguration_cmd);
17658 install_element(BGP_FLOWSPECV4_NODE,
17659 &no_neighbor_soft_reconfiguration_cmd);
17660 install_element(BGP_FLOWSPECV6_NODE,
17661 &neighbor_soft_reconfiguration_cmd);
17662 install_element(BGP_FLOWSPECV6_NODE,
17663 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
17664 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17665 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 17666
17667 /* "neighbor attribute-unchanged" commands. */
17668 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17669 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17670 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17671 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17672 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17673 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17674 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17675 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17676 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17677 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17678 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17679 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17680 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17681 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17682 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17683 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17684 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
17685 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
17686
17687 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
17688 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
17689
17690 /* "nexthop-local unchanged" commands */
17691 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
17692 install_element(BGP_IPV6_NODE,
17693 &no_neighbor_nexthop_local_unchanged_cmd);
17694
17695 /* "neighbor next-hop-self" commands. */
17696 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
17697 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
17698 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
17699 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
17700 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
17701 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
17702 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
17703 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
17704 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
17705 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
17706 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
17707 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
17708 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
17709 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
17710 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
17711 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
17712 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
17713 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
17714 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
17715 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 17716
17717 /* "neighbor next-hop-self force" commands. */
17718 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
17719 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
17720 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17721 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17722 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
17723 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17724 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17725 install_element(BGP_IPV4_NODE,
17726 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17727 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
17728 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17729 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17730 install_element(BGP_IPV4M_NODE,
17731 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17732 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
17733 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17734 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17735 install_element(BGP_IPV4L_NODE,
17736 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17737 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
17738 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17739 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17740 install_element(BGP_IPV6_NODE,
17741 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17742 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
17743 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17744 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17745 install_element(BGP_IPV6M_NODE,
17746 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17747 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
17748 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17749 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17750 install_element(BGP_IPV6L_NODE,
17751 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17752 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
17753 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17754 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17755 install_element(BGP_VPNV4_NODE,
17756 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17757 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
17758 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17759 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17760 install_element(BGP_VPNV6_NODE,
17761 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
17762 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
17763 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 17764
17765 /* "neighbor as-override" commands. */
17766 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
17767 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
17768 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
17769 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
17770 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
17771 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
17772 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
17773 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
17774 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
17775 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
17776 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
17777 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
17778 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
17779 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
17780 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
17781 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
17782 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
17783 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
17784
17785 /* "neighbor remove-private-AS" commands. */
17786 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
17787 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
17788 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
17789 install_element(BGP_NODE,
17790 &no_neighbor_remove_private_as_all_hidden_cmd);
17791 install_element(BGP_NODE,
17792 &neighbor_remove_private_as_replace_as_hidden_cmd);
17793 install_element(BGP_NODE,
17794 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
17795 install_element(BGP_NODE,
17796 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
17797 install_element(
17798 BGP_NODE,
17799 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
17800 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
17801 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
17802 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
17803 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17804 install_element(BGP_IPV4_NODE,
17805 &neighbor_remove_private_as_replace_as_cmd);
17806 install_element(BGP_IPV4_NODE,
17807 &no_neighbor_remove_private_as_replace_as_cmd);
17808 install_element(BGP_IPV4_NODE,
17809 &neighbor_remove_private_as_all_replace_as_cmd);
17810 install_element(BGP_IPV4_NODE,
17811 &no_neighbor_remove_private_as_all_replace_as_cmd);
17812 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
17813 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
17814 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
17815 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
17816 install_element(BGP_IPV4M_NODE,
17817 &neighbor_remove_private_as_replace_as_cmd);
17818 install_element(BGP_IPV4M_NODE,
17819 &no_neighbor_remove_private_as_replace_as_cmd);
17820 install_element(BGP_IPV4M_NODE,
17821 &neighbor_remove_private_as_all_replace_as_cmd);
17822 install_element(BGP_IPV4M_NODE,
17823 &no_neighbor_remove_private_as_all_replace_as_cmd);
17824 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
17825 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
17826 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
17827 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
17828 install_element(BGP_IPV4L_NODE,
17829 &neighbor_remove_private_as_replace_as_cmd);
17830 install_element(BGP_IPV4L_NODE,
17831 &no_neighbor_remove_private_as_replace_as_cmd);
17832 install_element(BGP_IPV4L_NODE,
17833 &neighbor_remove_private_as_all_replace_as_cmd);
17834 install_element(BGP_IPV4L_NODE,
17835 &no_neighbor_remove_private_as_all_replace_as_cmd);
17836 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
17837 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
17838 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
17839 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
17840 install_element(BGP_IPV6_NODE,
17841 &neighbor_remove_private_as_replace_as_cmd);
17842 install_element(BGP_IPV6_NODE,
17843 &no_neighbor_remove_private_as_replace_as_cmd);
17844 install_element(BGP_IPV6_NODE,
17845 &neighbor_remove_private_as_all_replace_as_cmd);
17846 install_element(BGP_IPV6_NODE,
17847 &no_neighbor_remove_private_as_all_replace_as_cmd);
17848 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
17849 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
17850 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
17851 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
17852 install_element(BGP_IPV6M_NODE,
17853 &neighbor_remove_private_as_replace_as_cmd);
17854 install_element(BGP_IPV6M_NODE,
17855 &no_neighbor_remove_private_as_replace_as_cmd);
17856 install_element(BGP_IPV6M_NODE,
17857 &neighbor_remove_private_as_all_replace_as_cmd);
17858 install_element(BGP_IPV6M_NODE,
17859 &no_neighbor_remove_private_as_all_replace_as_cmd);
17860 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
17861 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
17862 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
17863 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
17864 install_element(BGP_IPV6L_NODE,
17865 &neighbor_remove_private_as_replace_as_cmd);
17866 install_element(BGP_IPV6L_NODE,
17867 &no_neighbor_remove_private_as_replace_as_cmd);
17868 install_element(BGP_IPV6L_NODE,
17869 &neighbor_remove_private_as_all_replace_as_cmd);
17870 install_element(BGP_IPV6L_NODE,
17871 &no_neighbor_remove_private_as_all_replace_as_cmd);
17872 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
17873 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
17874 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
17875 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17876 install_element(BGP_VPNV4_NODE,
17877 &neighbor_remove_private_as_replace_as_cmd);
17878 install_element(BGP_VPNV4_NODE,
17879 &no_neighbor_remove_private_as_replace_as_cmd);
17880 install_element(BGP_VPNV4_NODE,
17881 &neighbor_remove_private_as_all_replace_as_cmd);
17882 install_element(BGP_VPNV4_NODE,
17883 &no_neighbor_remove_private_as_all_replace_as_cmd);
17884 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
17885 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
17886 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
17887 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
17888 install_element(BGP_VPNV6_NODE,
17889 &neighbor_remove_private_as_replace_as_cmd);
17890 install_element(BGP_VPNV6_NODE,
17891 &no_neighbor_remove_private_as_replace_as_cmd);
17892 install_element(BGP_VPNV6_NODE,
17893 &neighbor_remove_private_as_all_replace_as_cmd);
17894 install_element(BGP_VPNV6_NODE,
17895 &no_neighbor_remove_private_as_all_replace_as_cmd);
17896
17897 /* "neighbor send-community" commands.*/
17898 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
17899 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
17900 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
17901 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
17902 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
17903 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
17904 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
17905 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
17906 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
17907 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
17908 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
17909 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
17910 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
17911 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
17912 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
17913 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
17914 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
17915 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
17916 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
17917 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
17918 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
17919 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
17920 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
17921 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
17922 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
17923 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
17924 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
17925 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
17926 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
17927 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
17928 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
17929 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
17930 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
17931 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
17932 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
17933 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
17934
17935 /* "neighbor route-reflector" commands.*/
17936 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
17937 install_element(BGP_NODE,
17938 &no_neighbor_route_reflector_client_hidden_cmd);
17939 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
17940 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
17941 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
17942 install_element(BGP_IPV4M_NODE,
17943 &no_neighbor_route_reflector_client_cmd);
17944 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
17945 install_element(BGP_IPV4L_NODE,
17946 &no_neighbor_route_reflector_client_cmd);
17947 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
17948 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
17949 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
17950 install_element(BGP_IPV6M_NODE,
17951 &no_neighbor_route_reflector_client_cmd);
17952 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
17953 install_element(BGP_IPV6L_NODE,
17954 &no_neighbor_route_reflector_client_cmd);
17955 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
17956 install_element(BGP_VPNV4_NODE,
17957 &no_neighbor_route_reflector_client_cmd);
17958 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
17959 install_element(BGP_VPNV6_NODE,
17960 &no_neighbor_route_reflector_client_cmd);
7c40bf39 17961 install_element(BGP_FLOWSPECV4_NODE,
17962 &neighbor_route_reflector_client_cmd);
17963 install_element(BGP_FLOWSPECV4_NODE,
17964 &no_neighbor_route_reflector_client_cmd);
17965 install_element(BGP_FLOWSPECV6_NODE,
17966 &neighbor_route_reflector_client_cmd);
17967 install_element(BGP_FLOWSPECV6_NODE,
17968 &no_neighbor_route_reflector_client_cmd);
d62a17ae 17969 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
17970 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
17971
17972 /* "neighbor route-server" commands.*/
17973 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
17974 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
17975 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
17976 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
17977 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
17978 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
17979 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
17980 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
17981 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
17982 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
17983 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
17984 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
17985 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
17986 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
17987 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
17988 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
17989 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
17990 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
17991 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
17992 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 17993 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
17994 install_element(BGP_FLOWSPECV4_NODE,
17995 &no_neighbor_route_server_client_cmd);
17996 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
17997 install_element(BGP_FLOWSPECV6_NODE,
17998 &no_neighbor_route_server_client_cmd);
d62a17ae 17999
18000 /* "neighbor addpath-tx-all-paths" commands.*/
18001 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18002 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18003 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18004 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18005 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18006 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18007 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18008 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18009 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18010 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18011 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18012 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18013 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18014 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18015 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18016 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18017 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18018 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18019
18020 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18021 install_element(BGP_NODE,
18022 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18023 install_element(BGP_NODE,
18024 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18025 install_element(BGP_IPV4_NODE,
18026 &neighbor_addpath_tx_bestpath_per_as_cmd);
18027 install_element(BGP_IPV4_NODE,
18028 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18029 install_element(BGP_IPV4M_NODE,
18030 &neighbor_addpath_tx_bestpath_per_as_cmd);
18031 install_element(BGP_IPV4M_NODE,
18032 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18033 install_element(BGP_IPV4L_NODE,
18034 &neighbor_addpath_tx_bestpath_per_as_cmd);
18035 install_element(BGP_IPV4L_NODE,
18036 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18037 install_element(BGP_IPV6_NODE,
18038 &neighbor_addpath_tx_bestpath_per_as_cmd);
18039 install_element(BGP_IPV6_NODE,
18040 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18041 install_element(BGP_IPV6M_NODE,
18042 &neighbor_addpath_tx_bestpath_per_as_cmd);
18043 install_element(BGP_IPV6M_NODE,
18044 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18045 install_element(BGP_IPV6L_NODE,
18046 &neighbor_addpath_tx_bestpath_per_as_cmd);
18047 install_element(BGP_IPV6L_NODE,
18048 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18049 install_element(BGP_VPNV4_NODE,
18050 &neighbor_addpath_tx_bestpath_per_as_cmd);
18051 install_element(BGP_VPNV4_NODE,
18052 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18053 install_element(BGP_VPNV6_NODE,
18054 &neighbor_addpath_tx_bestpath_per_as_cmd);
18055 install_element(BGP_VPNV6_NODE,
18056 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18057
2b31007c
RZ
18058 /* "neighbor sender-as-path-loop-detection" commands. */
18059 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18060 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18061
d62a17ae 18062 /* "neighbor passive" commands. */
18063 install_element(BGP_NODE, &neighbor_passive_cmd);
18064 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18065
18066
18067 /* "neighbor shutdown" commands. */
18068 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18069 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18070 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18071 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18072 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18073 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18074
18075 /* "neighbor capability extended-nexthop" commands.*/
18076 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18077 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18078
18079 /* "neighbor capability orf prefix-list" commands.*/
18080 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18081 install_element(BGP_NODE,
18082 &no_neighbor_capability_orf_prefix_hidden_cmd);
18083 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18084 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18085 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18086 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18087 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18088 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18089 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18090 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18091 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18092 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18093 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18094 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18095
18096 /* "neighbor capability dynamic" commands.*/
18097 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18098 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18099
18100 /* "neighbor dont-capability-negotiate" commands. */
18101 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18102 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18103
18104 /* "neighbor ebgp-multihop" commands. */
18105 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18106 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18107 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18108
18109 /* "neighbor disable-connected-check" commands. */
18110 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18111 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18112
47cbc09b
PM
18113 /* "neighbor enforce-first-as" commands. */
18114 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18115 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18116
d62a17ae 18117 /* "neighbor description" commands. */
18118 install_element(BGP_NODE, &neighbor_description_cmd);
18119 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18120 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18121
18122 /* "neighbor update-source" commands. "*/
18123 install_element(BGP_NODE, &neighbor_update_source_cmd);
18124 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18125
18126 /* "neighbor default-originate" commands. */
18127 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18128 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18129 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18130 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18131 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18132 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18133 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18134 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18135 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18136 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18137 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18138 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18139 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18140 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18141 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18142 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18143 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18144 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18145 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18146 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18147 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18148
18149 /* "neighbor port" commands. */
18150 install_element(BGP_NODE, &neighbor_port_cmd);
18151 install_element(BGP_NODE, &no_neighbor_port_cmd);
18152
18153 /* "neighbor weight" commands. */
18154 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18155 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18156
18157 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18158 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18159 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18160 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18161 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18162 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18163 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18164 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18165 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18166 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18167 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18168 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18169 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18170 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18171 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18172 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18173
18174 /* "neighbor override-capability" commands. */
18175 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18176 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18177
18178 /* "neighbor strict-capability-match" commands. */
18179 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18180 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18181
18182 /* "neighbor timers" commands. */
18183 install_element(BGP_NODE, &neighbor_timers_cmd);
18184 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18185
18186 /* "neighbor timers connect" commands. */
18187 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18188 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18189
18190 /* "neighbor advertisement-interval" commands. */
18191 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18192 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18193
18194 /* "neighbor interface" commands. */
18195 install_element(BGP_NODE, &neighbor_interface_cmd);
18196 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18197
18198 /* "neighbor distribute" commands. */
18199 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18200 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18201 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18202 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18203 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18204 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18205 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18206 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18207 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18208 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18209 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18210 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18211 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18212 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18213 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18214 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18215 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18216 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18217
18218 /* "neighbor prefix-list" commands. */
18219 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18220 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18221 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18222 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18223 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18224 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18225 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18226 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18227 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18228 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18229 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18230 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18231 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18232 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18233 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18234 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18235 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18236 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18237 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18238 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18239 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18240 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18241
18242 /* "neighbor filter-list" commands. */
18243 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18244 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18245 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18246 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18247 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18248 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18249 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18250 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18251 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18252 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18253 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18254 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18255 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18256 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18257 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18258 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18259 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18260 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18261 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18262 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18263 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18264 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18265
18266 /* "neighbor route-map" commands. */
18267 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18268 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18269 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18270 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18271 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18272 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18273 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18274 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18275 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18276 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18277 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18278 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18279 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18280 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18281 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18282 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18283 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18284 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18285 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18286 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18287 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18288 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
18289 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18290 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18291
18292 /* "neighbor unsuppress-map" commands. */
18293 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18294 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18295 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18296 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18297 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18298 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18299 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18300 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18301 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18302 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18303 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18304 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18305 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18306 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18307 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18308 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18309 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18310 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18311
7f7940e6
MK
18312 /* "neighbor advertise-map" commands. */
18313 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18314 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18315 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18316 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18317 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18318 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18319 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18320 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18321 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18322
fde246e8
DA
18323 /* neighbor maximum-prefix-out commands. */
18324 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18325 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18326 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18327 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18328 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18329 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18330 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18331 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18332 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18333 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18334 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18335 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18336 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18337 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18338 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18339 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18340 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18341 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18342
d62a17ae 18343 /* "neighbor maximum-prefix" commands. */
18344 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18345 install_element(BGP_NODE,
18346 &neighbor_maximum_prefix_threshold_hidden_cmd);
18347 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18348 install_element(BGP_NODE,
18349 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18350 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18351 install_element(BGP_NODE,
18352 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18353 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18354 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18355 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18356 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18357 install_element(BGP_IPV4_NODE,
18358 &neighbor_maximum_prefix_threshold_warning_cmd);
18359 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18360 install_element(BGP_IPV4_NODE,
18361 &neighbor_maximum_prefix_threshold_restart_cmd);
18362 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18363 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18364 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18365 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18366 install_element(BGP_IPV4M_NODE,
18367 &neighbor_maximum_prefix_threshold_warning_cmd);
18368 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18369 install_element(BGP_IPV4M_NODE,
18370 &neighbor_maximum_prefix_threshold_restart_cmd);
18371 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18372 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18373 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18374 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18375 install_element(BGP_IPV4L_NODE,
18376 &neighbor_maximum_prefix_threshold_warning_cmd);
18377 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18378 install_element(BGP_IPV4L_NODE,
18379 &neighbor_maximum_prefix_threshold_restart_cmd);
18380 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18381 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18382 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18383 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18384 install_element(BGP_IPV6_NODE,
18385 &neighbor_maximum_prefix_threshold_warning_cmd);
18386 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18387 install_element(BGP_IPV6_NODE,
18388 &neighbor_maximum_prefix_threshold_restart_cmd);
18389 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18390 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18391 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18392 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18393 install_element(BGP_IPV6M_NODE,
18394 &neighbor_maximum_prefix_threshold_warning_cmd);
18395 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18396 install_element(BGP_IPV6M_NODE,
18397 &neighbor_maximum_prefix_threshold_restart_cmd);
18398 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18399 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18400 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18401 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18402 install_element(BGP_IPV6L_NODE,
18403 &neighbor_maximum_prefix_threshold_warning_cmd);
18404 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18405 install_element(BGP_IPV6L_NODE,
18406 &neighbor_maximum_prefix_threshold_restart_cmd);
18407 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18408 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18409 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18410 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18411 install_element(BGP_VPNV4_NODE,
18412 &neighbor_maximum_prefix_threshold_warning_cmd);
18413 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18414 install_element(BGP_VPNV4_NODE,
18415 &neighbor_maximum_prefix_threshold_restart_cmd);
18416 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18417 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18418 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18419 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18420 install_element(BGP_VPNV6_NODE,
18421 &neighbor_maximum_prefix_threshold_warning_cmd);
18422 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18423 install_element(BGP_VPNV6_NODE,
18424 &neighbor_maximum_prefix_threshold_restart_cmd);
18425 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18426
18427 /* "neighbor allowas-in" */
18428 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18429 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18430 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18431 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18432 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18433 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18434 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18435 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18436 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18437 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18438 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18439 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18440 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18441 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18442 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18443 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18444 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18445 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18446 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18447 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18448
18449 /* address-family commands. */
18450 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18451 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18452#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18453 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18454 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18455#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18456
d62a17ae 18457 install_element(BGP_NODE, &address_family_evpn_cmd);
18458
18459 /* "exit-address-family" command. */
18460 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18461 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18462 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18463 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18464 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18465 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18466 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18467 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18468 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18469 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18470 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18471
18472 /* "clear ip bgp commands" */
18473 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18474
18475 /* clear ip bgp prefix */
18476 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18477 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18478 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18479
18480 /* "show [ip] bgp summary" commands. */
18481 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18482 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18483 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18484 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18485 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18486 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18487 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18488
18489 /* "show [ip] bgp neighbors" commands. */
18490 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18491
36235319 18492 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18493
d62a17ae 18494 /* "show [ip] bgp peer-group" commands. */
18495 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18496
18497 /* "show [ip] bgp paths" commands. */
18498 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18499
18500 /* "show [ip] bgp community" commands. */
18501 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18502
18503 /* "show ip bgp large-community" commands. */
18504 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18505 /* "show [ip] bgp attribute-info" commands. */
18506 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18507 /* "show [ip] bgp route-leak" command */
18508 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18509
18510 /* "redistribute" commands. */
18511 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18512 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18513 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18514 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18515 install_element(BGP_NODE,
18516 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18517 install_element(BGP_NODE,
18518 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18519 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18520 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18521 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18522 install_element(BGP_NODE,
18523 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18524 install_element(BGP_NODE,
18525 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18526 install_element(BGP_NODE,
18527 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18528 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18529 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18530 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18531 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18532 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18533 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18534 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18535 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18536 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18537 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18538 install_element(BGP_IPV4_NODE,
18539 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18540 install_element(BGP_IPV4_NODE,
18541 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18542 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18543 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18544 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18545 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18546 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18547 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18548
b9c7bc5a
PZ
18549 /* import|export vpn [route-map WORD] */
18550 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18551 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18552
12a844a5
DS
18553 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18554 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18555
d62a17ae 18556 /* ttl_security commands */
18557 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18558 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18559
18560 /* "show [ip] bgp memory" commands. */
18561 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18562
acf71666
MK
18563 /* "show bgp martian next-hop" */
18564 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18565
48ecf8f5
DS
18566 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18567
d62a17ae 18568 /* "show [ip] bgp views" commands. */
18569 install_element(VIEW_NODE, &show_bgp_views_cmd);
18570
18571 /* "show [ip] bgp vrfs" commands. */
18572 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18573
18574 /* Community-list. */
18575 community_list_vty();
ddb5b488
PZ
18576
18577 /* vpn-policy commands */
b9c7bc5a
PZ
18578 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18579 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18580 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18581 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18582 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18583 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18584 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18585 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18586 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18587 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18588 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18589 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18590
301ad80a
PG
18591 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18592 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18593
b9c7bc5a
PZ
18594 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18595 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18596 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18597 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18598 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18599 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18600 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18601 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
18602 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18603 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 18604}
6b0655a2 18605
718e3744 18606#include "memory.h"
18607#include "bgp_regex.h"
18608#include "bgp_clist.h"
18609#include "bgp_ecommunity.h"
18610
18611/* VTY functions. */
18612
18613/* Direction value to string conversion. */
d62a17ae 18614static const char *community_direct_str(int direct)
18615{
18616 switch (direct) {
18617 case COMMUNITY_DENY:
18618 return "deny";
18619 case COMMUNITY_PERMIT:
18620 return "permit";
18621 default:
18622 return "unknown";
18623 }
718e3744 18624}
18625
18626/* Display error string. */
d62a17ae 18627static void community_list_perror(struct vty *vty, int ret)
18628{
18629 switch (ret) {
18630 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18631 vty_out(vty, "%% Can't find community-list\n");
18632 break;
18633 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
18634 vty_out(vty, "%% Malformed community-list value\n");
18635 break;
18636 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
18637 vty_out(vty,
18638 "%% Community name conflict, previously defined as standard community\n");
18639 break;
18640 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
18641 vty_out(vty,
18642 "%% Community name conflict, previously defined as expanded community\n");
18643 break;
18644 }
718e3744 18645}
18646
5bf15956
DW
18647/* "community-list" keyword help string. */
18648#define COMMUNITY_LIST_STR "Add a community list entry\n"
18649
7336e101
SP
18650/*community-list standard */
18651DEFUN (community_list_standard,
18652 bgp_community_list_standard_cmd,
2f8cc0e5 18653 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 18654 BGP_STR
718e3744 18655 COMMUNITY_LIST_STR
18656 "Community list number (standard)\n"
5bf15956 18657 "Add an standard community-list entry\n"
718e3744 18658 "Community list name\n"
2f8cc0e5
DA
18659 "Sequence number of an entry\n"
18660 "Sequence number\n"
718e3744 18661 "Specify community to reject\n"
18662 "Specify community to accept\n"
18663 COMMUNITY_VAL_STR)
18664{
d62a17ae 18665 char *cl_name_or_number = NULL;
2f8cc0e5 18666 char *seq = NULL;
d62a17ae 18667 int direct = 0;
18668 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 18669 int idx = 0;
7336e101 18670
2f8cc0e5
DA
18671 argv_find(argv, argc, "(1-4294967295)", &idx);
18672 if (idx)
18673 seq = argv[idx]->arg;
18674
18675 idx = 0;
d62a17ae 18676 argv_find(argv, argc, "(1-99)", &idx);
18677 argv_find(argv, argc, "WORD", &idx);
18678 cl_name_or_number = argv[idx]->arg;
18679 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18680 : COMMUNITY_DENY;
18681 argv_find(argv, argc, "AA:NN", &idx);
18682 char *str = argv_concat(argv, argc, idx);
42f914d4 18683
2f8cc0e5
DA
18684 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18685 direct, style);
42f914d4 18686
d62a17ae 18687 XFREE(MTYPE_TMP, str);
42f914d4 18688
d62a17ae 18689 if (ret < 0) {
18690 /* Display error string. */
18691 community_list_perror(vty, ret);
18692 return CMD_WARNING_CONFIG_FAILED;
18693 }
42f914d4 18694
d62a17ae 18695 return CMD_SUCCESS;
718e3744 18696}
18697
7336e101
SP
18698DEFUN (no_community_list_standard_all,
18699 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 18700 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18701 NO_STR
18702 BGP_STR
18703 COMMUNITY_LIST_STR
18704 "Community list number (standard)\n"
18705 "Add an standard community-list entry\n"
18706 "Community list name\n"
2f8cc0e5
DA
18707 "Sequence number of an entry\n"
18708 "Sequence number\n"
7336e101
SP
18709 "Specify community to reject\n"
18710 "Specify community to accept\n"
18711 COMMUNITY_VAL_STR)
718e3744 18712{
d62a17ae 18713 char *cl_name_or_number = NULL;
174b5cb9 18714 char *str = NULL;
d62a17ae 18715 int direct = 0;
18716 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 18717 char *seq = NULL;
d62a17ae 18718 int idx = 0;
7336e101 18719
2f8cc0e5
DA
18720 argv_find(argv, argc, "(1-4294967295)", &idx);
18721 if (idx)
18722 seq = argv[idx]->arg;
18723
18724 idx = 0;
174b5cb9
DA
18725 argv_find(argv, argc, "permit", &idx);
18726 argv_find(argv, argc, "deny", &idx);
18727
18728 if (idx) {
18729 direct = argv_find(argv, argc, "permit", &idx)
18730 ? COMMUNITY_PERMIT
18731 : COMMUNITY_DENY;
18732
18733 idx = 0;
18734 argv_find(argv, argc, "AA:NN", &idx);
18735 str = argv_concat(argv, argc, idx);
18736 }
18737
18738 idx = 0;
d62a17ae 18739 argv_find(argv, argc, "(1-99)", &idx);
18740 argv_find(argv, argc, "WORD", &idx);
18741 cl_name_or_number = argv[idx]->arg;
42f914d4 18742
2f8cc0e5 18743 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 18744 direct, style);
42f914d4 18745
d62a17ae 18746 XFREE(MTYPE_TMP, str);
daf9ddbb 18747
d62a17ae 18748 if (ret < 0) {
18749 community_list_perror(vty, ret);
18750 return CMD_WARNING_CONFIG_FAILED;
18751 }
42f914d4 18752
d62a17ae 18753 return CMD_SUCCESS;
718e3744 18754}
7336e101 18755
174b5cb9
DA
18756ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
18757 "no bgp community-list <(1-99)|standard WORD>",
18758 NO_STR BGP_STR COMMUNITY_LIST_STR
18759 "Community list number (standard)\n"
18760 "Add an standard community-list entry\n"
18761 "Community list name\n")
18762
7336e101
SP
18763/*community-list expanded */
18764DEFUN (community_list_expanded_all,
18765 bgp_community_list_expanded_all_cmd,
2f8cc0e5 18766 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18767 BGP_STR
18768 COMMUNITY_LIST_STR
718e3744 18769 "Community list number (expanded)\n"
5bf15956 18770 "Add an expanded community-list entry\n"
718e3744 18771 "Community list name\n"
2f8cc0e5
DA
18772 "Sequence number of an entry\n"
18773 "Sequence number\n"
718e3744 18774 "Specify community to reject\n"
18775 "Specify community to accept\n"
18776 COMMUNITY_VAL_STR)
18777{
d62a17ae 18778 char *cl_name_or_number = NULL;
2f8cc0e5 18779 char *seq = NULL;
d62a17ae 18780 int direct = 0;
18781 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 18782 int idx = 0;
7b9a4750 18783
2f8cc0e5
DA
18784 argv_find(argv, argc, "(1-4294967295)", &idx);
18785 if (idx)
18786 seq = argv[idx]->arg;
18787
18788 idx = 0;
18789
d62a17ae 18790 argv_find(argv, argc, "(100-500)", &idx);
18791 argv_find(argv, argc, "WORD", &idx);
18792 cl_name_or_number = argv[idx]->arg;
18793 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18794 : COMMUNITY_DENY;
18795 argv_find(argv, argc, "AA:NN", &idx);
18796 char *str = argv_concat(argv, argc, idx);
42f914d4 18797
2f8cc0e5
DA
18798 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18799 direct, style);
42f914d4 18800
d62a17ae 18801 XFREE(MTYPE_TMP, str);
42f914d4 18802
d62a17ae 18803 if (ret < 0) {
18804 /* Display error string. */
18805 community_list_perror(vty, ret);
18806 return CMD_WARNING_CONFIG_FAILED;
18807 }
42f914d4 18808
d62a17ae 18809 return CMD_SUCCESS;
718e3744 18810}
18811
7336e101
SP
18812DEFUN (no_community_list_expanded_all,
18813 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 18814 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18815 NO_STR
18816 BGP_STR
18817 COMMUNITY_LIST_STR
18818 "Community list number (expanded)\n"
18819 "Add an expanded community-list entry\n"
18820 "Community list name\n"
2f8cc0e5
DA
18821 "Sequence number of an entry\n"
18822 "Sequence number\n"
7336e101
SP
18823 "Specify community to reject\n"
18824 "Specify community to accept\n"
18825 COMMUNITY_VAL_STR)
718e3744 18826{
d62a17ae 18827 char *cl_name_or_number = NULL;
2f8cc0e5 18828 char *seq = NULL;
174b5cb9 18829 char *str = NULL;
d62a17ae 18830 int direct = 0;
18831 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 18832 int idx = 0;
174b5cb9 18833
2f8cc0e5
DA
18834 argv_find(argv, argc, "(1-4294967295)", &idx);
18835 if (idx)
18836 seq = argv[idx]->arg;
18837
18838 idx = 0;
174b5cb9
DA
18839 argv_find(argv, argc, "permit", &idx);
18840 argv_find(argv, argc, "deny", &idx);
18841
18842 if (idx) {
18843 direct = argv_find(argv, argc, "permit", &idx)
18844 ? COMMUNITY_PERMIT
18845 : COMMUNITY_DENY;
18846
18847 idx = 0;
18848 argv_find(argv, argc, "AA:NN", &idx);
18849 str = argv_concat(argv, argc, idx);
7336e101 18850 }
174b5cb9
DA
18851
18852 idx = 0;
d62a17ae 18853 argv_find(argv, argc, "(100-500)", &idx);
18854 argv_find(argv, argc, "WORD", &idx);
18855 cl_name_or_number = argv[idx]->arg;
42f914d4 18856
2f8cc0e5 18857 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 18858 direct, style);
42f914d4 18859
d62a17ae 18860 XFREE(MTYPE_TMP, str);
daf9ddbb 18861
d62a17ae 18862 if (ret < 0) {
18863 community_list_perror(vty, ret);
18864 return CMD_WARNING_CONFIG_FAILED;
18865 }
42f914d4 18866
d62a17ae 18867 return CMD_SUCCESS;
718e3744 18868}
18869
36d4bb44
EB
18870ALIAS(no_community_list_expanded_all,
18871 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 18872 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 18873 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
18874 "Community list number (expanded)\n"
18875 "Add an expanded community-list entry\n"
18876 "Community list name\n")
18877
8d9b8ed9
PM
18878/* Return configuration string of community-list entry. */
18879static const char *community_list_config_str(struct community_entry *entry)
18880{
18881 const char *str;
18882
18883 if (entry->any)
18884 str = "";
18885 else {
18886 if (entry->style == COMMUNITY_LIST_STANDARD)
18887 str = community_str(entry->u.com, false);
18888 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
18889 str = lcommunity_str(entry->u.lcom, false);
18890 else
18891 str = entry->config;
18892 }
18893 return str;
18894}
18895
d62a17ae 18896static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 18897{
d62a17ae 18898 struct community_entry *entry;
718e3744 18899
d62a17ae 18900 for (entry = list->head; entry; entry = entry->next) {
18901 if (entry == list->head) {
18902 if (all_digit(list->name))
18903 vty_out(vty, "Community %s list %s\n",
18904 entry->style == COMMUNITY_LIST_STANDARD
18905 ? "standard"
18906 : "(expanded) access",
18907 list->name);
18908 else
18909 vty_out(vty, "Named Community %s list %s\n",
18910 entry->style == COMMUNITY_LIST_STANDARD
18911 ? "standard"
18912 : "expanded",
18913 list->name);
18914 }
18915 if (entry->any)
18916 vty_out(vty, " %s\n",
18917 community_direct_str(entry->direct));
18918 else
18919 vty_out(vty, " %s %s\n",
18920 community_direct_str(entry->direct),
8d9b8ed9 18921 community_list_config_str(entry));
d62a17ae 18922 }
718e3744 18923}
18924
7336e101
SP
18925DEFUN (show_community_list,
18926 show_bgp_community_list_cmd,
18927 "show bgp community-list",
718e3744 18928 SHOW_STR
7336e101 18929 BGP_STR
718e3744 18930 "List community-list\n")
18931{
d62a17ae 18932 struct community_list *list;
18933 struct community_list_master *cm;
718e3744 18934
d62a17ae 18935 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18936 if (!cm)
18937 return CMD_SUCCESS;
718e3744 18938
d62a17ae 18939 for (list = cm->num.head; list; list = list->next)
18940 community_list_show(vty, list);
718e3744 18941
d62a17ae 18942 for (list = cm->str.head; list; list = list->next)
18943 community_list_show(vty, list);
718e3744 18944
d62a17ae 18945 return CMD_SUCCESS;
718e3744 18946}
18947
7336e101
SP
18948DEFUN (show_community_list_arg,
18949 show_bgp_community_list_arg_cmd,
960b69b9 18950 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
18951 SHOW_STR
18952 BGP_STR
718e3744 18953 "List community-list\n"
18954 "Community-list number\n"
960b69b9 18955 "Community-list name\n"
18956 "Detailed information on community-list\n")
718e3744 18957{
d62a17ae 18958 int idx_comm_list = 3;
18959 struct community_list *list;
718e3744 18960
e237b0d2 18961 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18962 COMMUNITY_LIST_MASTER);
18963 if (!list) {
18964 vty_out(vty, "%% Can't find community-list\n");
18965 return CMD_WARNING;
18966 }
718e3744 18967
d62a17ae 18968 community_list_show(vty, list);
718e3744 18969
d62a17ae 18970 return CMD_SUCCESS;
718e3744 18971}
6b0655a2 18972
57d187bc
JS
18973/*
18974 * Large Community code.
18975 */
d62a17ae 18976static int lcommunity_list_set_vty(struct vty *vty, int argc,
18977 struct cmd_token **argv, int style,
18978 int reject_all_digit_name)
18979{
18980 int ret;
18981 int direct;
18982 char *str;
18983 int idx = 0;
18984 char *cl_name;
2f8cc0e5
DA
18985 char *seq = NULL;
18986
947073e3 18987 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 18988 seq = argv[idx]->arg;
d62a17ae 18989
2f8cc0e5 18990 idx = 0;
d62a17ae 18991 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18992 : COMMUNITY_DENY;
18993
18994 /* All digit name check. */
18995 idx = 0;
18996 argv_find(argv, argc, "WORD", &idx);
18997 argv_find(argv, argc, "(1-99)", &idx);
18998 argv_find(argv, argc, "(100-500)", &idx);
18999 cl_name = argv[idx]->arg;
19000 if (reject_all_digit_name && all_digit(cl_name)) {
19001 vty_out(vty, "%% Community name cannot have all digits\n");
19002 return CMD_WARNING_CONFIG_FAILED;
19003 }
19004
19005 idx = 0;
19006 argv_find(argv, argc, "AA:BB:CC", &idx);
19007 argv_find(argv, argc, "LINE", &idx);
19008 /* Concat community string argument. */
19009 if (idx)
19010 str = argv_concat(argv, argc, idx);
19011 else
19012 str = NULL;
19013
2f8cc0e5 19014 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19015
19016 /* Free temporary community list string allocated by
19017 argv_concat(). */
0a22ddfb 19018 XFREE(MTYPE_TMP, str);
d62a17ae 19019
19020 if (ret < 0) {
19021 community_list_perror(vty, ret);
19022 return CMD_WARNING_CONFIG_FAILED;
19023 }
19024 return CMD_SUCCESS;
19025}
19026
19027static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19028 struct cmd_token **argv, int style)
19029{
19030 int ret;
19031 int direct = 0;
19032 char *str = NULL;
19033 int idx = 0;
2f8cc0e5 19034 char *seq = NULL;
d62a17ae 19035
947073e3 19036 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 19037 seq = argv[idx]->arg;
d62a17ae 19038
2f8cc0e5 19039 idx = 0;
d62a17ae 19040 argv_find(argv, argc, "permit", &idx);
19041 argv_find(argv, argc, "deny", &idx);
19042
19043 if (idx) {
19044 /* Check the list direct. */
19045 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19046 direct = COMMUNITY_PERMIT;
19047 else
19048 direct = COMMUNITY_DENY;
19049
19050 idx = 0;
19051 argv_find(argv, argc, "LINE", &idx);
19052 argv_find(argv, argc, "AA:AA:NN", &idx);
19053 /* Concat community string argument. */
19054 str = argv_concat(argv, argc, idx);
19055 }
19056
19057 idx = 0;
19058 argv_find(argv, argc, "(1-99)", &idx);
19059 argv_find(argv, argc, "(100-500)", &idx);
19060 argv_find(argv, argc, "WORD", &idx);
19061
19062 /* Unset community list. */
2f8cc0e5 19063 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19064 style);
19065
19066 /* Free temporary community list string allocated by
19067 argv_concat(). */
0a22ddfb 19068 XFREE(MTYPE_TMP, str);
d62a17ae 19069
19070 if (ret < 0) {
19071 community_list_perror(vty, ret);
19072 return CMD_WARNING_CONFIG_FAILED;
19073 }
19074
19075 return CMD_SUCCESS;
57d187bc
JS
19076}
19077
19078/* "large-community-list" keyword help string. */
19079#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19080#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19081
7336e101
SP
19082DEFUN (lcommunity_list_standard,
19083 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 19084 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19085 BGP_STR
19086 LCOMMUNITY_LIST_STR
19087 "Large Community list number (standard)\n"
2f8cc0e5
DA
19088 "Sequence number of an entry\n"
19089 "Sequence number\n"
7336e101
SP
19090 "Specify large community to reject\n"
19091 "Specify large community to accept\n"
19092 LCOMMUNITY_VAL_STR)
52951b63 19093{
d62a17ae 19094 return lcommunity_list_set_vty(vty, argc, argv,
19095 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19096}
19097
7336e101
SP
19098DEFUN (lcommunity_list_expanded,
19099 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 19100 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19101 BGP_STR
19102 LCOMMUNITY_LIST_STR
19103 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19104 "Sequence number of an entry\n"
19105 "Sequence number\n"
7336e101
SP
19106 "Specify large community to reject\n"
19107 "Specify large community to accept\n"
19108 "An ordered list as a regular-expression\n")
57d187bc 19109{
d62a17ae 19110 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19111 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19112}
19113
7336e101
SP
19114DEFUN (lcommunity_list_name_standard,
19115 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 19116 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19117 BGP_STR
19118 LCOMMUNITY_LIST_STR
19119 "Specify standard large-community-list\n"
19120 "Large Community list name\n"
2f8cc0e5
DA
19121 "Sequence number of an entry\n"
19122 "Sequence number\n"
7336e101
SP
19123 "Specify large community to reject\n"
19124 "Specify large community to accept\n"
19125 LCOMMUNITY_VAL_STR)
52951b63 19126{
d62a17ae 19127 return lcommunity_list_set_vty(vty, argc, argv,
19128 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19129}
19130
7336e101
SP
19131DEFUN (lcommunity_list_name_expanded,
19132 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 19133 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19134 BGP_STR
19135 LCOMMUNITY_LIST_STR
19136 "Specify expanded large-community-list\n"
19137 "Large Community list name\n"
2f8cc0e5
DA
19138 "Sequence number of an entry\n"
19139 "Sequence number\n"
7336e101
SP
19140 "Specify large community to reject\n"
19141 "Specify large community to accept\n"
19142 "An ordered list as a regular-expression\n")
57d187bc 19143{
d62a17ae 19144 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19145 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19146}
19147
4378f57c
DA
19148DEFUN (no_lcommunity_list_all,
19149 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
19150 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19151 NO_STR
19152 BGP_STR
19153 LCOMMUNITY_LIST_STR
19154 "Large Community list number (standard)\n"
19155 "Large Community list number (expanded)\n"
19156 "Large Community list name\n")
57d187bc 19157{
7336e101
SP
19158 return lcommunity_list_unset_vty(vty, argc, argv,
19159 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19160}
19161
4378f57c
DA
19162DEFUN (no_lcommunity_list_name_standard_all,
19163 no_bgp_lcommunity_list_name_standard_all_cmd,
19164 "no bgp large-community-list standard WORD",
19165 NO_STR
19166 BGP_STR
19167 LCOMMUNITY_LIST_STR
19168 "Specify standard large-community-list\n"
19169 "Large Community list name\n")
19170{
19171 return lcommunity_list_unset_vty(vty, argc, argv,
19172 LARGE_COMMUNITY_LIST_STANDARD);
19173}
19174
7336e101
SP
19175DEFUN (no_lcommunity_list_name_expanded_all,
19176 no_bgp_lcommunity_list_name_expanded_all_cmd,
19177 "no bgp large-community-list expanded WORD",
19178 NO_STR
19179 BGP_STR
19180 LCOMMUNITY_LIST_STR
19181 "Specify expanded large-community-list\n"
19182 "Large Community list name\n")
57d187bc 19183{
d62a17ae 19184 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19185 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19186}
19187
7336e101
SP
19188DEFUN (no_lcommunity_list_standard,
19189 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 19190 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19191 NO_STR
19192 BGP_STR
19193 LCOMMUNITY_LIST_STR
19194 "Large Community list number (standard)\n"
2f8cc0e5
DA
19195 "Sequence number of an entry\n"
19196 "Sequence number\n"
7336e101
SP
19197 "Specify large community to reject\n"
19198 "Specify large community to accept\n"
19199 LCOMMUNITY_VAL_STR)
57d187bc 19200{
d62a17ae 19201 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19202 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19203}
19204
7336e101
SP
19205DEFUN (no_lcommunity_list_expanded,
19206 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 19207 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19208 NO_STR
19209 BGP_STR
19210 LCOMMUNITY_LIST_STR
19211 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19212 "Sequence number of an entry\n"
19213 "Sequence number\n"
7336e101
SP
19214 "Specify large community to reject\n"
19215 "Specify large community to accept\n"
19216 "An ordered list as a regular-expression\n")
57d187bc 19217{
d62a17ae 19218 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19219 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19220}
19221
7336e101
SP
19222DEFUN (no_lcommunity_list_name_standard,
19223 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 19224 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19225 NO_STR
19226 BGP_STR
19227 LCOMMUNITY_LIST_STR
19228 "Specify standard large-community-list\n"
19229 "Large Community list name\n"
2f8cc0e5
DA
19230 "Sequence number of an entry\n"
19231 "Sequence number\n"
7336e101
SP
19232 "Specify large community to reject\n"
19233 "Specify large community to accept\n"
19234 LCOMMUNITY_VAL_STR)
57d187bc 19235{
d62a17ae 19236 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19237 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19238}
19239
7336e101
SP
19240DEFUN (no_lcommunity_list_name_expanded,
19241 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 19242 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19243 NO_STR
19244 BGP_STR
19245 LCOMMUNITY_LIST_STR
19246 "Specify expanded large-community-list\n"
19247 "Large community list name\n"
2f8cc0e5
DA
19248 "Sequence number of an entry\n"
19249 "Sequence number\n"
7336e101
SP
19250 "Specify large community to reject\n"
19251 "Specify large community to accept\n"
19252 "An ordered list as a regular-expression\n")
57d187bc 19253{
d62a17ae 19254 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19255 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19256}
19257
d62a17ae 19258static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19259{
19260 struct community_entry *entry;
19261
19262 for (entry = list->head; entry; entry = entry->next) {
19263 if (entry == list->head) {
19264 if (all_digit(list->name))
19265 vty_out(vty, "Large community %s list %s\n",
169b72c8 19266 entry->style ==
19267 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19268 ? "standard"
19269 : "(expanded) access",
19270 list->name);
19271 else
19272 vty_out(vty,
19273 "Named large community %s list %s\n",
169b72c8 19274 entry->style ==
19275 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19276 ? "standard"
19277 : "expanded",
19278 list->name);
19279 }
19280 if (entry->any)
19281 vty_out(vty, " %s\n",
19282 community_direct_str(entry->direct));
19283 else
19284 vty_out(vty, " %s %s\n",
19285 community_direct_str(entry->direct),
8d9b8ed9 19286 community_list_config_str(entry));
d62a17ae 19287 }
57d187bc
JS
19288}
19289
7336e101
SP
19290DEFUN (show_lcommunity_list,
19291 show_bgp_lcommunity_list_cmd,
19292 "show bgp large-community-list",
57d187bc 19293 SHOW_STR
7336e101 19294 BGP_STR
57d187bc
JS
19295 "List large-community list\n")
19296{
d62a17ae 19297 struct community_list *list;
19298 struct community_list_master *cm;
57d187bc 19299
d62a17ae 19300 cm = community_list_master_lookup(bgp_clist,
19301 LARGE_COMMUNITY_LIST_MASTER);
19302 if (!cm)
19303 return CMD_SUCCESS;
57d187bc 19304
d62a17ae 19305 for (list = cm->num.head; list; list = list->next)
19306 lcommunity_list_show(vty, list);
57d187bc 19307
d62a17ae 19308 for (list = cm->str.head; list; list = list->next)
19309 lcommunity_list_show(vty, list);
57d187bc 19310
d62a17ae 19311 return CMD_SUCCESS;
57d187bc
JS
19312}
19313
7336e101
SP
19314DEFUN (show_lcommunity_list_arg,
19315 show_bgp_lcommunity_list_arg_cmd,
960b69b9 19316 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
19317 SHOW_STR
19318 BGP_STR
57d187bc 19319 "List large-community list\n"
960b69b9 19320 "Large-community-list number\n"
19321 "Large-community-list name\n"
19322 "Detailed information on large-community-list\n")
57d187bc 19323{
d62a17ae 19324 struct community_list *list;
57d187bc 19325
e237b0d2 19326 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19327 LARGE_COMMUNITY_LIST_MASTER);
19328 if (!list) {
960b69b9 19329 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19330 return CMD_WARNING;
19331 }
57d187bc 19332
d62a17ae 19333 lcommunity_list_show(vty, list);
57d187bc 19334
d62a17ae 19335 return CMD_SUCCESS;
57d187bc
JS
19336}
19337
718e3744 19338/* "extcommunity-list" keyword help string. */
19339#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19340#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19341
7336e101
SP
19342DEFUN (extcommunity_list_standard,
19343 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 19344 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 19345 BGP_STR
718e3744 19346 EXTCOMMUNITY_LIST_STR
19347 "Extended Community list number (standard)\n"
718e3744 19348 "Specify standard extcommunity-list\n"
5bf15956 19349 "Community list name\n"
2f8cc0e5
DA
19350 "Sequence number of an entry\n"
19351 "Sequence number\n"
718e3744 19352 "Specify community to reject\n"
19353 "Specify community to accept\n"
19354 EXTCOMMUNITY_VAL_STR)
19355{
d62a17ae 19356 int style = EXTCOMMUNITY_LIST_STANDARD;
19357 int direct = 0;
19358 char *cl_number_or_name = NULL;
2f8cc0e5 19359 char *seq = NULL;
42f914d4 19360
d62a17ae 19361 int idx = 0;
7b9a4750 19362
d62a17ae 19363 argv_find(argv, argc, "(1-99)", &idx);
19364 argv_find(argv, argc, "WORD", &idx);
19365 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19366
409148f6 19367 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19368 seq = argv[idx]->arg;
19369
d62a17ae 19370 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19371 : COMMUNITY_DENY;
19372 argv_find(argv, argc, "AA:NN", &idx);
19373 char *str = argv_concat(argv, argc, idx);
42f914d4 19374
2f8cc0e5 19375 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19376 direct, style);
42f914d4 19377
d62a17ae 19378 XFREE(MTYPE_TMP, str);
42f914d4 19379
d62a17ae 19380 if (ret < 0) {
19381 community_list_perror(vty, ret);
19382 return CMD_WARNING_CONFIG_FAILED;
19383 }
42f914d4 19384
d62a17ae 19385 return CMD_SUCCESS;
718e3744 19386}
19387
7336e101
SP
19388DEFUN (extcommunity_list_name_expanded,
19389 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 19390 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19391 BGP_STR
19392 EXTCOMMUNITY_LIST_STR
5bf15956 19393 "Extended Community list number (expanded)\n"
718e3744 19394 "Specify expanded extcommunity-list\n"
19395 "Extended Community list name\n"
2f8cc0e5
DA
19396 "Sequence number of an entry\n"
19397 "Sequence number\n"
718e3744 19398 "Specify community to reject\n"
19399 "Specify community to accept\n"
19400 "An ordered list as a regular-expression\n")
19401{
d62a17ae 19402 int style = EXTCOMMUNITY_LIST_EXPANDED;
19403 int direct = 0;
19404 char *cl_number_or_name = NULL;
2f8cc0e5 19405 char *seq = NULL;
d62a17ae 19406 int idx = 0;
7336e101 19407
d62a17ae 19408 argv_find(argv, argc, "(100-500)", &idx);
19409 argv_find(argv, argc, "WORD", &idx);
19410 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19411
409148f6 19412 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19413 seq = argv[idx]->arg;
19414
d62a17ae 19415 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19416 : COMMUNITY_DENY;
19417 argv_find(argv, argc, "LINE", &idx);
19418 char *str = argv_concat(argv, argc, idx);
42f914d4 19419
2f8cc0e5 19420 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19421 direct, style);
42f914d4 19422
d62a17ae 19423 XFREE(MTYPE_TMP, str);
42f914d4 19424
d62a17ae 19425 if (ret < 0) {
19426 community_list_perror(vty, ret);
19427 return CMD_WARNING_CONFIG_FAILED;
19428 }
42f914d4 19429
d62a17ae 19430 return CMD_SUCCESS;
718e3744 19431}
19432
7336e101
SP
19433DEFUN (no_extcommunity_list_standard_all,
19434 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 19435 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19436 NO_STR
19437 BGP_STR
19438 EXTCOMMUNITY_LIST_STR
813d4307 19439 "Extended Community list number (standard)\n"
718e3744 19440 "Specify standard extcommunity-list\n"
5bf15956 19441 "Community list name\n"
2f8cc0e5
DA
19442 "Sequence number of an entry\n"
19443 "Sequence number\n"
718e3744 19444 "Specify community to reject\n"
19445 "Specify community to accept\n"
19446 EXTCOMMUNITY_VAL_STR)
19447{
d62a17ae 19448 int style = EXTCOMMUNITY_LIST_STANDARD;
19449 int direct = 0;
19450 char *cl_number_or_name = NULL;
d4455c89 19451 char *str = NULL;
2f8cc0e5 19452 char *seq = NULL;
d62a17ae 19453 int idx = 0;
d4455c89 19454
409148f6 19455 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19456 seq = argv[idx]->arg;
19457
19458 idx = 0;
d4455c89
DA
19459 argv_find(argv, argc, "permit", &idx);
19460 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19461 if (idx) {
19462 direct = argv_find(argv, argc, "permit", &idx)
19463 ? COMMUNITY_PERMIT
19464 : COMMUNITY_DENY;
19465
19466 idx = 0;
19467 argv_find(argv, argc, "AA:NN", &idx);
19468 str = argv_concat(argv, argc, idx);
19469 }
19470
19471 idx = 0;
d62a17ae 19472 argv_find(argv, argc, "(1-99)", &idx);
19473 argv_find(argv, argc, "WORD", &idx);
19474 cl_number_or_name = argv[idx]->arg;
42f914d4 19475
d62a17ae 19476 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19477 seq, direct, style);
42f914d4 19478
d62a17ae 19479 XFREE(MTYPE_TMP, str);
42f914d4 19480
d62a17ae 19481 if (ret < 0) {
19482 community_list_perror(vty, ret);
19483 return CMD_WARNING_CONFIG_FAILED;
19484 }
42f914d4 19485
d62a17ae 19486 return CMD_SUCCESS;
718e3744 19487}
19488
d4455c89
DA
19489ALIAS(no_extcommunity_list_standard_all,
19490 no_bgp_extcommunity_list_standard_all_list_cmd,
19491 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 19492 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19493 "Extended Community list number (standard)\n"
19494 "Specify standard extcommunity-list\n"
19495 "Community list name\n")
19496
7336e101
SP
19497DEFUN (no_extcommunity_list_expanded_all,
19498 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 19499 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
19500 NO_STR
19501 BGP_STR
19502 EXTCOMMUNITY_LIST_STR
718e3744 19503 "Extended Community list number (expanded)\n"
718e3744 19504 "Specify expanded extcommunity-list\n"
5bf15956 19505 "Extended Community list name\n"
2f8cc0e5
DA
19506 "Sequence number of an entry\n"
19507 "Sequence number\n"
718e3744 19508 "Specify community to reject\n"
19509 "Specify community to accept\n"
19510 "An ordered list as a regular-expression\n")
19511{
d62a17ae 19512 int style = EXTCOMMUNITY_LIST_EXPANDED;
19513 int direct = 0;
19514 char *cl_number_or_name = NULL;
d4455c89 19515 char *str = NULL;
2f8cc0e5 19516 char *seq = NULL;
d62a17ae 19517 int idx = 0;
d4455c89 19518
409148f6 19519 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
19520 seq = argv[idx]->arg;
19521
19522 idx = 0;
d4455c89
DA
19523 argv_find(argv, argc, "permit", &idx);
19524 argv_find(argv, argc, "deny", &idx);
19525
19526 if (idx) {
19527 direct = argv_find(argv, argc, "permit", &idx)
19528 ? COMMUNITY_PERMIT
19529 : COMMUNITY_DENY;
19530
19531 idx = 0;
19532 argv_find(argv, argc, "LINE", &idx);
19533 str = argv_concat(argv, argc, idx);
19534 }
19535
19536 idx = 0;
d62a17ae 19537 argv_find(argv, argc, "(100-500)", &idx);
19538 argv_find(argv, argc, "WORD", &idx);
19539 cl_number_or_name = argv[idx]->arg;
42f914d4 19540
d62a17ae 19541 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19542 seq, 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
d4455c89
DA
19554ALIAS(no_extcommunity_list_expanded_all,
19555 no_bgp_extcommunity_list_expanded_all_list_cmd,
19556 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 19557 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19558 "Extended Community list number (expanded)\n"
19559 "Specify expanded extcommunity-list\n"
19560 "Extended Community list name\n")
19561
d62a17ae 19562static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19563{
d62a17ae 19564 struct community_entry *entry;
718e3744 19565
d62a17ae 19566 for (entry = list->head; entry; entry = entry->next) {
19567 if (entry == list->head) {
19568 if (all_digit(list->name))
19569 vty_out(vty, "Extended community %s list %s\n",
19570 entry->style == EXTCOMMUNITY_LIST_STANDARD
19571 ? "standard"
19572 : "(expanded) access",
19573 list->name);
19574 else
19575 vty_out(vty,
19576 "Named extended community %s list %s\n",
19577 entry->style == EXTCOMMUNITY_LIST_STANDARD
19578 ? "standard"
19579 : "expanded",
19580 list->name);
19581 }
19582 if (entry->any)
19583 vty_out(vty, " %s\n",
19584 community_direct_str(entry->direct));
19585 else
19586 vty_out(vty, " %s %s\n",
19587 community_direct_str(entry->direct),
8d9b8ed9 19588 community_list_config_str(entry));
d62a17ae 19589 }
718e3744 19590}
19591
7336e101
SP
19592DEFUN (show_extcommunity_list,
19593 show_bgp_extcommunity_list_cmd,
19594 "show bgp extcommunity-list",
718e3744 19595 SHOW_STR
7336e101 19596 BGP_STR
718e3744 19597 "List extended-community list\n")
19598{
d62a17ae 19599 struct community_list *list;
19600 struct community_list_master *cm;
718e3744 19601
d62a17ae 19602 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19603 if (!cm)
19604 return CMD_SUCCESS;
718e3744 19605
d62a17ae 19606 for (list = cm->num.head; list; list = list->next)
19607 extcommunity_list_show(vty, list);
718e3744 19608
d62a17ae 19609 for (list = cm->str.head; list; list = list->next)
19610 extcommunity_list_show(vty, list);
718e3744 19611
d62a17ae 19612 return CMD_SUCCESS;
718e3744 19613}
19614
7336e101
SP
19615DEFUN (show_extcommunity_list_arg,
19616 show_bgp_extcommunity_list_arg_cmd,
960b69b9 19617 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
19618 SHOW_STR
19619 BGP_STR
718e3744 19620 "List extended-community list\n"
19621 "Extcommunity-list number\n"
960b69b9 19622 "Extcommunity-list name\n"
19623 "Detailed information on extcommunity-list\n")
718e3744 19624{
d62a17ae 19625 int idx_comm_list = 3;
19626 struct community_list *list;
718e3744 19627
e237b0d2 19628 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19629 EXTCOMMUNITY_LIST_MASTER);
19630 if (!list) {
19631 vty_out(vty, "%% Can't find extcommunity-list\n");
19632 return CMD_WARNING;
19633 }
718e3744 19634
d62a17ae 19635 extcommunity_list_show(vty, list);
718e3744 19636
d62a17ae 19637 return CMD_SUCCESS;
718e3744 19638}
6b0655a2 19639
718e3744 19640/* Display community-list and extcommunity-list configuration. */
d62a17ae 19641static int community_list_config_write(struct vty *vty)
19642{
19643 struct community_list *list;
19644 struct community_entry *entry;
19645 struct community_list_master *cm;
19646 int write = 0;
19647
19648 /* Community-list. */
19649 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19650
19651 for (list = cm->num.head; list; list = list->next)
19652 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
19653 vty_out(vty,
19654 "bgp community-list %s seq %" PRId64 " %s %s\n",
19655 list->name, entry->seq,
d62a17ae 19656 community_direct_str(entry->direct),
19657 community_list_config_str(entry));
19658 write++;
19659 }
19660 for (list = cm->str.head; list; list = list->next)
19661 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
19662 vty_out(vty,
19663 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 19664 entry->style == COMMUNITY_LIST_STANDARD
19665 ? "standard"
19666 : "expanded",
2f8cc0e5
DA
19667 list->name, entry->seq,
19668 community_direct_str(entry->direct),
d62a17ae 19669 community_list_config_str(entry));
19670 write++;
19671 }
19672
19673 /* Extcommunity-list. */
19674 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19675
19676 for (list = cm->num.head; list; list = list->next)
19677 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
19678 vty_out(vty,
19679 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
19680 list->name, entry->seq,
19681 community_direct_str(entry->direct),
d62a17ae 19682 community_list_config_str(entry));
19683 write++;
19684 }
19685 for (list = cm->str.head; list; list = list->next)
19686 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19687 vty_out(vty,
6cde4b45 19688 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 19689 entry->style == EXTCOMMUNITY_LIST_STANDARD
19690 ? "standard"
19691 : "expanded",
2f8cc0e5
DA
19692 list->name, entry->seq,
19693 community_direct_str(entry->direct),
d62a17ae 19694 community_list_config_str(entry));
19695 write++;
19696 }
19697
19698
19699 /* lcommunity-list. */
19700 cm = community_list_master_lookup(bgp_clist,
19701 LARGE_COMMUNITY_LIST_MASTER);
19702
19703 for (list = cm->num.head; list; list = list->next)
19704 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19705 vty_out(vty,
6cde4b45 19706 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
19707 list->name, entry->seq,
19708 community_direct_str(entry->direct),
d62a17ae 19709 community_list_config_str(entry));
19710 write++;
19711 }
19712 for (list = cm->str.head; list; list = list->next)
19713 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19714 vty_out(vty,
6cde4b45 19715 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 19716
d62a17ae 19717 entry->style == LARGE_COMMUNITY_LIST_STANDARD
19718 ? "standard"
19719 : "expanded",
2f8cc0e5 19720 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 19721 community_list_config_str(entry));
19722 write++;
19723 }
19724
19725 return write;
19726}
19727
612c2c15 19728static int community_list_config_write(struct vty *vty);
d62a17ae 19729static struct cmd_node community_list_node = {
f4b8291f 19730 .name = "community list",
62b346ee
DL
19731 .node = COMMUNITY_LIST_NODE,
19732 .prompt = "",
612c2c15 19733 .config_write = community_list_config_write,
718e3744 19734};
19735
d62a17ae 19736static void community_list_vty(void)
19737{
612c2c15 19738 install_node(&community_list_node);
d62a17ae 19739
19740 /* Community-list. */
7336e101
SP
19741 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
19742 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
19743 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 19744 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 19745 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 19746 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
19747 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
19748 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 19749
19750 /* Extcommunity-list. */
7336e101
SP
19751 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
19752 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
19753 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
19754 install_element(CONFIG_NODE,
19755 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 19756 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
19757 install_element(CONFIG_NODE,
19758 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
19759 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
19760 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 19761
19762 /* Large Community List */
7336e101 19763 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
19764 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
19765 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 19766 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
19767 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
19768 install_element(CONFIG_NODE,
19769 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
19770 install_element(CONFIG_NODE,
19771 &no_bgp_lcommunity_list_name_expanded_all_cmd);
19772 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
19773 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
19774 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
19775 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
19776 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
19777 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 19778}