Line data Source code
1 : /* BGP VTY interface.
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 : */
20 :
21 : #include <zebra.h>
22 :
23 : #include "command.h"
24 : #include "lib/json.h"
25 : #include "lib/sockopt.h"
26 : #include "lib_errors.h"
27 : #include "lib/zclient.h"
28 : #include "lib/printfrr.h"
29 : #include "prefix.h"
30 : #include "plist.h"
31 : #include "buffer.h"
32 : #include "linklist.h"
33 : #include "stream.h"
34 : #include "thread.h"
35 : #include "log.h"
36 : #include "memory.h"
37 : #include "lib_vty.h"
38 : #include "hash.h"
39 : #include "queue.h"
40 : #include "filter.h"
41 : #include "frrstr.h"
42 :
43 : #include "bgpd/bgpd.h"
44 : #include "bgpd/bgp_attr_evpn.h"
45 : #include "bgpd/bgp_advertise.h"
46 : #include "bgpd/bgp_attr.h"
47 : #include "bgpd/bgp_aspath.h"
48 : #include "bgpd/bgp_community.h"
49 : #include "bgpd/bgp_community_alias.h"
50 : #include "bgpd/bgp_ecommunity.h"
51 : #include "bgpd/bgp_lcommunity.h"
52 : #include "bgpd/bgp_damp.h"
53 : #include "bgpd/bgp_debug.h"
54 : #include "bgpd/bgp_errors.h"
55 : #include "bgpd/bgp_fsm.h"
56 : #include "bgpd/bgp_nht.h"
57 : #include "bgpd/bgp_nexthop.h"
58 : #include "bgpd/bgp_network.h"
59 : #include "bgpd/bgp_open.h"
60 : #include "bgpd/bgp_regex.h"
61 : #include "bgpd/bgp_route.h"
62 : #include "bgpd/bgp_mplsvpn.h"
63 : #include "bgpd/bgp_zebra.h"
64 : #include "bgpd/bgp_table.h"
65 : #include "bgpd/bgp_vty.h"
66 : #include "bgpd/bgp_mpath.h"
67 : #include "bgpd/bgp_packet.h"
68 : #include "bgpd/bgp_updgrp.h"
69 : #include "bgpd/bgp_bfd.h"
70 : #include "bgpd/bgp_io.h"
71 : #include "bgpd/bgp_evpn.h"
72 : #include "bgpd/bgp_evpn_vty.h"
73 : #include "bgpd/bgp_evpn_mh.h"
74 : #include "bgpd/bgp_addpath.h"
75 : #include "bgpd/bgp_mac.h"
76 : #include "bgpd/bgp_flowspec.h"
77 : #include "bgpd/bgp_conditional_adv.h"
78 : #ifdef ENABLE_BGP_VNC
79 : #include "bgpd/rfapi/bgp_rfapi_cfg.h"
80 : #endif
81 :
82 2 : FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
83 : {
84 : .val_bool = false,
85 : .match_profile = "traditional",
86 : .match_version = "< 7.4",
87 : },
88 : { .val_bool = true },
89 : );
90 2 : FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
91 : { .val_bool = true, .match_profile = "datacenter", },
92 : { .val_bool = false },
93 : );
94 2 : FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
95 : { .val_bool = true, .match_profile = "datacenter", },
96 : { .val_bool = false },
97 : );
98 2 : FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
99 : { .val_bool = true, .match_profile = "datacenter", },
100 : { .val_bool = false },
101 : );
102 2 : FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
103 : { .val_bool = true, .match_profile = "datacenter", },
104 : { .val_bool = false },
105 : );
106 2 : FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
107 : { .val_ulong = 10, .match_profile = "datacenter", },
108 : { .val_ulong = 120 },
109 : );
110 2 : FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
111 : { .val_ulong = 9, .match_profile = "datacenter", },
112 : { .val_ulong = 180 },
113 : );
114 2 : FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
115 : { .val_ulong = 3, .match_profile = "datacenter", },
116 : { .val_ulong = 60 },
117 : );
118 2 : FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
119 : { .val_bool = false, .match_profile = "datacenter", },
120 : { .val_bool = false, .match_version = "< 7.4", },
121 : { .val_bool = true },
122 : );
123 2 : FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
124 : { .val_bool = false, .match_version = "< 7.6", },
125 : { .val_bool = true },
126 : );
127 2 : FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
128 : { .val_bool = false, .match_version = "< 8.3", },
129 : { .val_bool = true },
130 : );
131 2 : FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
132 : { .val_bool = false, .match_version = "< 8.3", },
133 : { .val_bool = true },
134 : );
135 :
136 0 : DEFINE_HOOK(bgp_inst_config_write,
137 : (struct bgp *bgp, struct vty *vty),
138 : (bgp, vty));
139 0 : DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
140 0 : DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
141 :
142 : static struct peer_group *listen_range_exists(struct bgp *bgp,
143 : struct prefix *range, int exact);
144 :
145 : /* Show BGP peer's information. */
146 : enum show_type {
147 : show_all,
148 : show_peer,
149 : show_ipv4_all,
150 : show_ipv6_all,
151 : show_ipv4_peer,
152 : show_ipv6_peer
153 : };
154 :
155 : static struct peer_group *listen_range_exists(struct bgp *bgp,
156 : struct prefix *range, int exact);
157 :
158 : static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
159 : struct bgp *bgp);
160 :
161 : static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
162 : enum show_type type,
163 : const char *ip_str,
164 : afi_t afi, bool use_json);
165 :
166 1 : static enum node_type bgp_node_type(afi_t afi, safi_t safi)
167 : {
168 0 : switch (afi) {
169 1 : case AFI_IP:
170 0 : switch (safi) {
171 : case SAFI_UNICAST:
172 : return BGP_IPV4_NODE;
173 : case SAFI_MULTICAST:
174 : return BGP_IPV4M_NODE;
175 0 : case SAFI_LABELED_UNICAST:
176 0 : return BGP_IPV4L_NODE;
177 0 : case SAFI_MPLS_VPN:
178 0 : return BGP_VPNV4_NODE;
179 0 : case SAFI_FLOWSPEC:
180 0 : return BGP_FLOWSPECV4_NODE;
181 : case SAFI_UNSPEC:
182 : case SAFI_ENCAP:
183 : case SAFI_EVPN:
184 : case SAFI_MAX:
185 : /* not expected */
186 : return BGP_IPV4_NODE;
187 : }
188 : break;
189 0 : case AFI_IP6:
190 0 : switch (safi) {
191 : case SAFI_UNICAST:
192 : return BGP_IPV6_NODE;
193 0 : case SAFI_MULTICAST:
194 0 : return BGP_IPV6M_NODE;
195 0 : case SAFI_LABELED_UNICAST:
196 0 : return BGP_IPV6L_NODE;
197 0 : case SAFI_MPLS_VPN:
198 0 : return BGP_VPNV6_NODE;
199 0 : case SAFI_FLOWSPEC:
200 0 : return BGP_FLOWSPECV6_NODE;
201 : case SAFI_UNSPEC:
202 : case SAFI_ENCAP:
203 : case SAFI_EVPN:
204 : case SAFI_MAX:
205 : /* not expected and the return value seems wrong */
206 : return BGP_IPV4_NODE;
207 : }
208 : break;
209 : case AFI_L2VPN:
210 : return BGP_EVPN_NODE;
211 : case AFI_UNSPEC:
212 : case AFI_MAX:
213 : // We should never be here but to clarify the switch statement..
214 : return BGP_IPV4_NODE;
215 : }
216 :
217 : // Impossible to happen
218 : return BGP_IPV4_NODE;
219 : }
220 :
221 2 : static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
222 : {
223 2 : if (afi == AFI_IP) {
224 2 : if (safi == SAFI_UNICAST)
225 2 : return "IPv4 Unicast";
226 : if (safi == SAFI_MULTICAST)
227 0 : return "IPv4 Multicast";
228 : if (safi == SAFI_LABELED_UNICAST)
229 0 : return "IPv4 Labeled Unicast";
230 : if (safi == SAFI_MPLS_VPN)
231 0 : return "IPv4 VPN";
232 : if (safi == SAFI_ENCAP)
233 0 : return "IPv4 Encap";
234 : if (safi == SAFI_FLOWSPEC)
235 0 : return "IPv4 Flowspec";
236 0 : } else if (afi == AFI_IP6) {
237 0 : if (safi == SAFI_UNICAST)
238 0 : return "IPv6 Unicast";
239 : if (safi == SAFI_MULTICAST)
240 0 : return "IPv6 Multicast";
241 : if (safi == SAFI_LABELED_UNICAST)
242 0 : return "IPv6 Labeled Unicast";
243 : if (safi == SAFI_MPLS_VPN)
244 0 : return "IPv6 VPN";
245 : if (safi == SAFI_ENCAP)
246 0 : return "IPv6 Encap";
247 : if (safi == SAFI_FLOWSPEC)
248 0 : return "IPv6 Flowspec";
249 0 : } else if (afi == AFI_L2VPN) {
250 0 : if (safi == SAFI_EVPN)
251 0 : return "L2VPN EVPN";
252 : }
253 :
254 : return "Unknown";
255 : }
256 :
257 : /*
258 : * Please note that we have intentionally camelCased
259 : * the return strings here. So if you want
260 : * to use this function, please ensure you
261 : * are doing this within json output
262 : */
263 305 : static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
264 : {
265 305 : if (afi == AFI_IP) {
266 137 : if (safi == SAFI_UNICAST)
267 65 : return "ipv4Unicast";
268 : if (safi == SAFI_MULTICAST)
269 12 : return "ipv4Multicast";
270 : if (safi == SAFI_LABELED_UNICAST)
271 12 : return "ipv4LabeledUnicast";
272 : if (safi == SAFI_MPLS_VPN)
273 12 : return "ipv4Vpn";
274 : if (safi == SAFI_ENCAP)
275 12 : return "ipv4Encap";
276 : if (safi == SAFI_FLOWSPEC)
277 12 : return "ipv4Flowspec";
278 168 : } else if (afi == AFI_IP6) {
279 84 : if (safi == SAFI_UNICAST)
280 12 : return "ipv6Unicast";
281 : if (safi == SAFI_MULTICAST)
282 12 : return "ipv6Multicast";
283 : if (safi == SAFI_LABELED_UNICAST)
284 12 : return "ipv6LabeledUnicast";
285 : if (safi == SAFI_MPLS_VPN)
286 12 : return "ipv6Vpn";
287 : if (safi == SAFI_ENCAP)
288 12 : return "ipv6Encap";
289 : if (safi == SAFI_FLOWSPEC)
290 12 : return "ipv6Flowspec";
291 84 : } else if (afi == AFI_L2VPN) {
292 84 : if (safi == SAFI_EVPN)
293 12 : return "l2VpnEvpn";
294 : }
295 :
296 : return "Unknown";
297 : }
298 :
299 : /* unset srv6 locator */
300 0 : static int bgp_srv6_locator_unset(struct bgp *bgp)
301 : {
302 0 : int ret;
303 0 : struct listnode *node, *nnode;
304 0 : struct srv6_locator_chunk *chunk;
305 0 : struct bgp_srv6_function *func;
306 0 : struct bgp *bgp_vrf;
307 :
308 : /* release chunk notification via ZAPI */
309 0 : ret = bgp_zebra_srv6_manager_release_locator_chunk(
310 0 : bgp->srv6_locator_name);
311 0 : if (ret < 0)
312 : return -1;
313 :
314 : /* refresh chunks */
315 0 : for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
316 0 : listnode_delete(bgp->srv6_locator_chunks, chunk);
317 0 : srv6_locator_chunk_free(&chunk);
318 : }
319 :
320 : /* refresh functions */
321 0 : for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
322 0 : listnode_delete(bgp->srv6_functions, func);
323 0 : XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
324 : }
325 :
326 : /* refresh tovpn_sid */
327 0 : for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
328 0 : if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
329 0 : continue;
330 :
331 : /* refresh vpnv4 tovpn_sid */
332 0 : XFREE(MTYPE_BGP_SRV6_SID,
333 : bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
334 :
335 : /* refresh vpnv6 tovpn_sid */
336 0 : XFREE(MTYPE_BGP_SRV6_SID,
337 : bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
338 :
339 : /* refresh per-vrf tovpn_sid */
340 0 : XFREE(MTYPE_BGP_SRV6_SID, bgp_vrf->tovpn_sid);
341 : }
342 :
343 : /* update vpn bgp processes */
344 0 : vpn_leak_postchange_all();
345 :
346 : /* refresh tovpn_sid_locator */
347 0 : for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
348 0 : if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
349 0 : continue;
350 :
351 : /* refresh vpnv4 tovpn_sid_locator */
352 0 : srv6_locator_chunk_free(
353 : &bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
354 :
355 : /* refresh vpnv6 tovpn_sid_locator */
356 0 : srv6_locator_chunk_free(
357 : &bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
358 :
359 : /* refresh per-vrf tovpn_sid_locator */
360 0 : srv6_locator_chunk_free(&bgp_vrf->tovpn_sid_locator);
361 : }
362 :
363 : /* clear locator name */
364 0 : memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
365 :
366 0 : return 0;
367 : }
368 :
369 : /* Utility function to get address family from current node. */
370 1 : afi_t bgp_node_afi(struct vty *vty)
371 : {
372 1 : afi_t afi;
373 1 : switch (vty->node) {
374 : case BGP_IPV6_NODE:
375 : case BGP_IPV6M_NODE:
376 : case BGP_IPV6L_NODE:
377 : case BGP_VPNV6_NODE:
378 : case BGP_FLOWSPECV6_NODE:
379 : afi = AFI_IP6;
380 : break;
381 0 : case BGP_EVPN_NODE:
382 0 : afi = AFI_L2VPN;
383 0 : break;
384 1 : default:
385 1 : afi = AFI_IP;
386 1 : break;
387 : }
388 1 : return afi;
389 : }
390 :
391 : /* Utility function to get subsequent address family from current
392 : node. */
393 1 : safi_t bgp_node_safi(struct vty *vty)
394 : {
395 1 : safi_t safi;
396 1 : switch (vty->node) {
397 : case BGP_VPNV4_NODE:
398 : case BGP_VPNV6_NODE:
399 : safi = SAFI_MPLS_VPN;
400 : break;
401 : case BGP_IPV4M_NODE:
402 : case BGP_IPV6M_NODE:
403 : safi = SAFI_MULTICAST;
404 : break;
405 : case BGP_EVPN_NODE:
406 : safi = SAFI_EVPN;
407 : break;
408 : case BGP_IPV4L_NODE:
409 : case BGP_IPV6L_NODE:
410 : safi = SAFI_LABELED_UNICAST;
411 : break;
412 : case BGP_FLOWSPECV4_NODE:
413 : case BGP_FLOWSPECV6_NODE:
414 : safi = SAFI_FLOWSPEC;
415 : break;
416 : default:
417 : safi = SAFI_UNICAST;
418 : break;
419 : }
420 1 : return safi;
421 : }
422 :
423 : /**
424 : * Converts an AFI in string form to afi_t
425 : *
426 : * @param afi string, one of
427 : * - "ipv4"
428 : * - "ipv6"
429 : * - "l2vpn"
430 : * @return the corresponding afi_t
431 : */
432 0 : afi_t bgp_vty_afi_from_str(const char *afi_str)
433 : {
434 0 : afi_t afi = AFI_MAX; /* unknown */
435 0 : if (strmatch(afi_str, "ipv4"))
436 : afi = AFI_IP;
437 0 : else if (strmatch(afi_str, "ipv6"))
438 : afi = AFI_IP6;
439 0 : else if (strmatch(afi_str, "l2vpn"))
440 0 : afi = AFI_L2VPN;
441 0 : return afi;
442 : }
443 :
444 0 : int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
445 : afi_t *afi)
446 : {
447 0 : int ret = 0;
448 0 : if (argv_find(argv, argc, "ipv4", index)) {
449 0 : ret = 1;
450 0 : if (afi)
451 0 : *afi = AFI_IP;
452 0 : } else if (argv_find(argv, argc, "ipv6", index)) {
453 0 : ret = 1;
454 0 : if (afi)
455 0 : *afi = AFI_IP6;
456 0 : } else if (argv_find(argv, argc, "l2vpn", index)) {
457 0 : ret = 1;
458 0 : if (afi)
459 0 : *afi = AFI_L2VPN;
460 : }
461 0 : return ret;
462 : }
463 :
464 : /* supports <unicast|multicast|vpn|labeled-unicast> */
465 1 : safi_t bgp_vty_safi_from_str(const char *safi_str)
466 : {
467 1 : safi_t safi = SAFI_MAX; /* unknown */
468 1 : if (strmatch(safi_str, "multicast"))
469 : safi = SAFI_MULTICAST;
470 1 : else if (strmatch(safi_str, "unicast"))
471 : safi = SAFI_UNICAST;
472 0 : else if (strmatch(safi_str, "vpn"))
473 : safi = SAFI_MPLS_VPN;
474 0 : else if (strmatch(safi_str, "evpn"))
475 : safi = SAFI_EVPN;
476 0 : else if (strmatch(safi_str, "labeled-unicast"))
477 : safi = SAFI_LABELED_UNICAST;
478 0 : else if (strmatch(safi_str, "flowspec"))
479 0 : safi = SAFI_FLOWSPEC;
480 1 : return safi;
481 : }
482 :
483 0 : int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
484 : safi_t *safi)
485 : {
486 0 : int ret = 0;
487 0 : if (argv_find(argv, argc, "unicast", index)) {
488 0 : ret = 1;
489 0 : if (safi)
490 0 : *safi = SAFI_UNICAST;
491 0 : } else if (argv_find(argv, argc, "multicast", index)) {
492 0 : ret = 1;
493 0 : if (safi)
494 0 : *safi = SAFI_MULTICAST;
495 0 : } else if (argv_find(argv, argc, "labeled-unicast", index)) {
496 0 : ret = 1;
497 0 : if (safi)
498 0 : *safi = SAFI_LABELED_UNICAST;
499 0 : } else if (argv_find(argv, argc, "vpn", index)) {
500 0 : ret = 1;
501 0 : if (safi)
502 0 : *safi = SAFI_MPLS_VPN;
503 0 : } else if (argv_find(argv, argc, "evpn", index)) {
504 0 : ret = 1;
505 0 : if (safi)
506 0 : *safi = SAFI_EVPN;
507 0 : } else if (argv_find(argv, argc, "flowspec", index)) {
508 0 : ret = 1;
509 0 : if (safi)
510 0 : *safi = SAFI_FLOWSPEC;
511 : }
512 0 : return ret;
513 : }
514 :
515 : /*
516 : * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
517 : *
518 : * afi
519 : * address-family identifier
520 : *
521 : * safi
522 : * subsequent address-family identifier
523 : *
524 : * Returns:
525 : * default_af string corresponding to the supplied afi/safi pair.
526 : * If afi/safi is invalid or if flag for afi/safi doesn't exist,
527 : * return -1.
528 : */
529 0 : static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
530 : {
531 0 : switch (afi) {
532 0 : case AFI_IP:
533 0 : switch (safi) {
534 : case SAFI_UNICAST:
535 : return "ipv4-unicast";
536 0 : case SAFI_MULTICAST:
537 0 : return "ipv4-multicast";
538 0 : case SAFI_MPLS_VPN:
539 0 : return "ipv4-vpn";
540 0 : case SAFI_ENCAP:
541 0 : return "ipv4-encap";
542 0 : case SAFI_LABELED_UNICAST:
543 0 : return "ipv4-labeled-unicast";
544 0 : case SAFI_FLOWSPEC:
545 0 : return "ipv4-flowspec";
546 : case SAFI_UNSPEC:
547 : case SAFI_EVPN:
548 : case SAFI_MAX:
549 : return "unknown-afi/safi";
550 : }
551 : break;
552 0 : case AFI_IP6:
553 0 : switch (safi) {
554 : case SAFI_UNICAST:
555 : return "ipv6-unicast";
556 0 : case SAFI_MULTICAST:
557 0 : return "ipv6-multicast";
558 0 : case SAFI_MPLS_VPN:
559 0 : return "ipv6-vpn";
560 0 : case SAFI_ENCAP:
561 0 : return "ipv6-encap";
562 0 : case SAFI_LABELED_UNICAST:
563 0 : return "ipv6-labeled-unicast";
564 0 : case SAFI_FLOWSPEC:
565 0 : return "ipv6-flowspec";
566 : case SAFI_UNSPEC:
567 : case SAFI_EVPN:
568 : case SAFI_MAX:
569 : return "unknown-afi/safi";
570 : }
571 : break;
572 0 : case AFI_L2VPN:
573 0 : switch (safi) {
574 : case SAFI_EVPN:
575 : return "l2vpn-evpn";
576 : case SAFI_UNICAST:
577 : case SAFI_MULTICAST:
578 : case SAFI_MPLS_VPN:
579 : case SAFI_ENCAP:
580 : case SAFI_LABELED_UNICAST:
581 : case SAFI_FLOWSPEC:
582 : case SAFI_UNSPEC:
583 : case SAFI_MAX:
584 : return "unknown-afi/safi";
585 : }
586 : break;
587 : case AFI_UNSPEC:
588 : case AFI_MAX:
589 : return "unknown-afi/safi";
590 : }
591 : /* all AFIs are accounted for above, so this shouldn't happen */
592 :
593 0 : assert(!"Reached end of function where we did not expect to");
594 : }
595 :
596 3 : int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
597 : enum bgp_instance_type inst_type)
598 : {
599 3 : int ret = bgp_get(bgp, as, name, inst_type);
600 :
601 3 : if (ret == BGP_CREATED) {
602 2 : bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
603 : DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
604 :
605 2 : if (DFLT_BGP_IMPORT_CHECK)
606 2 : SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
607 2 : if (DFLT_BGP_SHOW_HOSTNAME)
608 0 : SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
609 2 : if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
610 0 : SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
611 2 : if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
612 0 : SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
613 2 : if (DFLT_BGP_DETERMINISTIC_MED)
614 0 : SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
615 2 : if (DFLT_BGP_EBGP_REQUIRES_POLICY)
616 2 : SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
617 2 : if (DFLT_BGP_SUPPRESS_DUPLICATES)
618 2 : SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
619 2 : if (DFLT_BGP_GRACEFUL_NOTIFICATION)
620 2 : SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
621 2 : if (DFLT_BGP_HARD_ADMIN_RESET)
622 2 : SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
623 :
624 : ret = BGP_SUCCESS;
625 : }
626 3 : return ret;
627 : }
628 :
629 : /*
630 : * bgp_vty_find_and_parse_afi_safi_bgp
631 : *
632 : * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
633 : * This function *assumes* that the calling function pre-sets the afi/safi/bgp
634 : * to appropriate values for the calling function. This is to allow the
635 : * calling function to make decisions appropriate for the show command
636 : * that is being parsed.
637 : *
638 : * The show commands are generally of the form:
639 : * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
640 : * [<unicast|multicast|vpn|labeled-unicast>]] ..."
641 : *
642 : * Since we use argv_find if the show command in particular doesn't have:
643 : * [ip]
644 : * [<view|vrf> VIEWVRFNAME]
645 : * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
646 : * The command parsing should still be ok.
647 : *
648 : * vty -> The vty for the command so we can output some useful data in
649 : * the event of a parse error in the vrf.
650 : * argv -> The command tokens
651 : * argc -> How many command tokens we have
652 : * idx -> The current place in the command, generally should be 0 for this
653 : * function
654 : * afi -> The parsed afi if it was included in the show command, returned here
655 : * safi -> The parsed safi if it was included in the show command, returned here
656 : * bgp -> Pointer to the bgp data structure we need to fill in.
657 : * use_json -> json is configured or not
658 : *
659 : * The function returns the correct location in the parse tree for the
660 : * last token found.
661 : *
662 : * Returns 0 for failure to parse correctly, else the idx position of where
663 : * it found the last token.
664 : */
665 0 : int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
666 : struct cmd_token **argv, int argc,
667 : int *idx, afi_t *afi, safi_t *safi,
668 : struct bgp **bgp, bool use_json)
669 : {
670 0 : char *vrf_name = NULL;
671 :
672 0 : assert(afi);
673 0 : assert(safi);
674 0 : assert(bgp);
675 :
676 0 : if (argv_find(argv, argc, "ip", idx))
677 0 : *afi = AFI_IP;
678 :
679 0 : if (argv_find(argv, argc, "view", idx))
680 0 : vrf_name = argv[*idx + 1]->arg;
681 0 : else if (argv_find(argv, argc, "vrf", idx)) {
682 0 : vrf_name = argv[*idx + 1]->arg;
683 0 : if (strmatch(vrf_name, VRF_DEFAULT_NAME))
684 : vrf_name = NULL;
685 : }
686 0 : if (vrf_name) {
687 0 : if (strmatch(vrf_name, "all"))
688 0 : *bgp = NULL;
689 : else {
690 0 : *bgp = bgp_lookup_by_name(vrf_name);
691 0 : if (!*bgp) {
692 0 : if (use_json) {
693 0 : json_object *json = NULL;
694 0 : json = json_object_new_object();
695 0 : json_object_string_add(
696 : json, "warning",
697 : "View/Vrf is unknown");
698 0 : vty_json(vty, json);
699 : }
700 : else
701 0 : vty_out(vty, "View/Vrf %s is unknown\n",
702 : vrf_name);
703 0 : *idx = 0;
704 0 : return 0;
705 : }
706 : }
707 : } else {
708 0 : *bgp = bgp_get_default();
709 0 : if (!*bgp) {
710 0 : if (use_json) {
711 0 : json_object *json = NULL;
712 0 : json = json_object_new_object();
713 0 : json_object_string_add(
714 : json, "warning",
715 : "Default BGP instance not found");
716 0 : vty_json(vty, json);
717 : }
718 : else
719 0 : vty_out(vty,
720 : "Default BGP instance not found\n");
721 0 : *idx = 0;
722 0 : return 0;
723 : }
724 : }
725 :
726 0 : if (argv_find_and_parse_afi(argv, argc, idx, afi))
727 0 : argv_find_and_parse_safi(argv, argc, idx, safi);
728 :
729 0 : *idx += 1;
730 0 : return *idx;
731 : }
732 :
733 2 : static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
734 : {
735 2 : struct interface *ifp = NULL;
736 2 : struct listnode *node;
737 2 : struct bgp_listener *listener;
738 2 : union sockunion all_su;
739 :
740 2 : if (su->sa.sa_family == AF_INET) {
741 2 : (void)str2sockunion("0.0.0.0", &all_su);
742 2 : ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
743 0 : } else if (su->sa.sa_family == AF_INET6) {
744 0 : (void)str2sockunion("::", &all_su);
745 0 : ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
746 0 : su->sin6.sin6_scope_id,
747 : bgp->vrf_id);
748 : }
749 :
750 2 : if (ifp) {
751 0 : for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
752 0 : if (sockunion_family(su) !=
753 0 : sockunion_family(&listener->su))
754 0 : continue;
755 :
756 : /* If 0.0.0.0/:: is a listener, then treat as self and
757 : * reject.
758 : */
759 0 : if (!sockunion_cmp(&listener->su, su) ||
760 0 : !sockunion_cmp(&listener->su, &all_su))
761 0 : return true;
762 : }
763 : }
764 :
765 : return false;
766 : }
767 :
768 : /* Utility function for looking up peer from VTY. */
769 : /* This is used only for configuration, so disallow if attempted on
770 : * a dynamic neighbor.
771 : */
772 0 : static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
773 : {
774 0 : struct bgp *bgp = VTY_GET_CONTEXT(bgp);
775 0 : int ret;
776 0 : union sockunion su;
777 0 : struct peer *peer;
778 :
779 0 : if (!bgp) {
780 : return NULL;
781 : }
782 :
783 0 : ret = str2sockunion(ip_str, &su);
784 0 : if (ret < 0) {
785 0 : peer = peer_lookup_by_conf_if(bgp, ip_str);
786 0 : if (!peer) {
787 0 : if ((peer = peer_lookup_by_hostname(bgp, ip_str))
788 : == NULL) {
789 0 : vty_out(vty,
790 : "%% Malformed address or name: %s\n",
791 : ip_str);
792 0 : return NULL;
793 : }
794 : }
795 : } else {
796 0 : peer = peer_lookup(bgp, &su);
797 0 : if (!peer) {
798 0 : vty_out(vty,
799 : "%% Specify remote-as or peer-group commands first\n");
800 0 : return NULL;
801 : }
802 0 : if (peer_dynamic_neighbor(peer)) {
803 0 : vty_out(vty,
804 : "%% Operation not allowed on a dynamic neighbor\n");
805 0 : return NULL;
806 : }
807 : }
808 : return peer;
809 : }
810 :
811 : /* Utility function for looking up peer or peer group. */
812 : /* This is used only for configuration, so disallow if attempted on
813 : * a dynamic neighbor.
814 : */
815 2 : struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
816 : {
817 2 : struct bgp *bgp = VTY_GET_CONTEXT(bgp);
818 2 : int ret;
819 2 : union sockunion su;
820 2 : struct peer *peer = NULL;
821 2 : struct peer_group *group = NULL;
822 :
823 2 : if (!bgp) {
824 : return NULL;
825 : }
826 :
827 2 : ret = str2sockunion(peer_str, &su);
828 2 : if (ret == 0) {
829 : /* IP address, locate peer. */
830 2 : peer = peer_lookup(bgp, &su);
831 : } else {
832 : /* Not IP, could match either peer configured on interface or a
833 : * group. */
834 0 : peer = peer_lookup_by_conf_if(bgp, peer_str);
835 0 : if (!peer)
836 0 : group = peer_group_lookup(bgp, peer_str);
837 : }
838 :
839 2 : if (peer) {
840 2 : if (peer_dynamic_neighbor(peer)) {
841 0 : zlog_warn(
842 : "%pBP: Operation not allowed on a dynamic neighbor",
843 : peer);
844 0 : vty_out(vty,
845 : "%% Operation not allowed on a dynamic neighbor\n");
846 0 : return NULL;
847 : }
848 :
849 : return peer;
850 : }
851 :
852 0 : if (group)
853 0 : return group->conf;
854 :
855 0 : zlog_warn("Specify remote-as or peer-group commands first before: %s",
856 : vty->buf);
857 0 : vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
858 :
859 0 : return NULL;
860 : }
861 :
862 4 : int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
863 : {
864 4 : const char *str = NULL;
865 :
866 4 : switch (ret) {
867 : case BGP_SUCCESS:
868 : case BGP_CREATED:
869 : case BGP_GR_NO_OPERATION:
870 : break;
871 : case BGP_ERR_INVALID_VALUE:
872 : str = "Invalid value";
873 : break;
874 : case BGP_ERR_INVALID_FLAG:
875 0 : str = "Invalid flag";
876 0 : break;
877 : case BGP_ERR_PEER_GROUP_SHUTDOWN:
878 0 : str = "Peer-group has been shutdown. Activate the peer-group first";
879 0 : break;
880 : case BGP_ERR_PEER_FLAG_CONFLICT:
881 0 : str = "Can't set override-capability and strict-capability-match at the same time";
882 0 : break;
883 : case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
884 0 : str = "Specify remote-as or peer-group remote AS first";
885 0 : break;
886 : case BGP_ERR_PEER_GROUP_CANT_CHANGE:
887 0 : str = "Cannot change the peer-group. Deconfigure first";
888 0 : break;
889 : case BGP_ERR_PEER_GROUP_MISMATCH:
890 0 : str = "Peer is not a member of this peer-group";
891 0 : break;
892 : case BGP_ERR_PEER_FILTER_CONFLICT:
893 0 : str = "Prefix/distribute list can not co-exist";
894 0 : break;
895 : case BGP_ERR_NOT_INTERNAL_PEER:
896 0 : str = "Invalid command. Not an internal neighbor";
897 0 : break;
898 : case BGP_ERR_REMOVE_PRIVATE_AS:
899 0 : str = "remove-private-AS cannot be configured for IBGP peers";
900 0 : break;
901 : case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
902 0 : str = "Cannot have local-as same as BGP AS number";
903 0 : break;
904 : case BGP_ERR_TCPSIG_FAILED:
905 0 : str = "Error while applying TCP-Sig to session(s)";
906 0 : break;
907 : case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
908 0 : str = "ebgp-multihop and ttl-security cannot be configured together";
909 0 : break;
910 : case BGP_ERR_NO_IBGP_WITH_TTLHACK:
911 0 : str = "ttl-security only allowed for EBGP peers";
912 0 : break;
913 : case BGP_ERR_AS_OVERRIDE:
914 0 : str = "as-override cannot be configured for IBGP peers";
915 0 : break;
916 : case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
917 0 : str = "Invalid limit for number of dynamic neighbors";
918 0 : break;
919 : case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
920 0 : str = "Dynamic neighbor listen range already exists";
921 0 : break;
922 : case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
923 0 : str = "Operation not allowed on a dynamic neighbor";
924 0 : break;
925 : case BGP_ERR_INVALID_FOR_DIRECT_PEER:
926 0 : str = "Operation not allowed on a directly connected neighbor";
927 0 : break;
928 : case BGP_ERR_PEER_SAFI_CONFLICT:
929 0 : str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
930 0 : break;
931 : case BGP_ERR_GR_INVALID_CMD:
932 0 : str = "The Graceful Restart command used is not valid at this moment.";
933 0 : break;
934 : case BGP_ERR_GR_OPERATION_FAILED:
935 0 : str = "The Graceful Restart Operation failed due to an err.";
936 0 : break;
937 : case BGP_ERR_PEER_GROUP_MEMBER:
938 0 : str = "Peer-group member cannot override remote-as of peer-group.";
939 0 : break;
940 : case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
941 0 : str = "Peer-group members must be all internal or all external.";
942 0 : break;
943 : case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
944 0 : str = "Range specified cannot be deleted because it is not part of current config.";
945 0 : break;
946 : case BGP_ERR_INSTANCE_MISMATCH:
947 0 : str = "Instance specified does not match the current instance.";
948 0 : break;
949 : case BGP_ERR_NO_INTERFACE_CONFIG:
950 0 : str = "Interface specified is not being used for interface based peer.";
951 0 : break;
952 : case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
953 0 : str = "No configuration already specified for soft reconfiguration.";
954 0 : break;
955 : case BGP_ERR_AS_MISMATCH:
956 0 : str = "BGP is already running.";
957 0 : break;
958 : case BGP_ERR_AF_UNCONFIGURED:
959 0 : str = "AFI/SAFI specified is not currently configured.";
960 0 : break;
961 : case BGP_ERR_INVALID_AS:
962 0 : str = "Confederation AS specified is the same AS as our AS.";
963 0 : break;
964 : case BGP_ERR_INVALID_ROLE_NAME:
965 0 : str = "Invalid role name";
966 0 : break;
967 : case BGP_ERR_INVALID_INTERNAL_ROLE:
968 0 : str = "External roles can be set only on eBGP session";
969 0 : break;
970 : }
971 0 : if (str) {
972 0 : vty_out(vty, "%% %s\n", str);
973 0 : return CMD_WARNING_CONFIG_FAILED;
974 : }
975 : return CMD_SUCCESS;
976 : }
977 :
978 : /* BGP clear sort. */
979 : enum clear_sort {
980 : clear_all,
981 : clear_peer,
982 : clear_group,
983 : clear_external,
984 : clear_as
985 : };
986 :
987 0 : static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
988 : safi_t safi, int error)
989 : {
990 0 : switch (error) {
991 0 : case BGP_ERR_AF_UNCONFIGURED:
992 0 : if (vty)
993 0 : vty_out(vty,
994 : "%% BGP: Enable %s address family for the neighbor %s\n",
995 : get_afi_safi_str(afi, safi, false), peer->host);
996 : else
997 0 : zlog_warn(
998 : "%% BGP: Enable %s address family for the neighbor %s",
999 : get_afi_safi_str(afi, safi, false), peer->host);
1000 : break;
1001 0 : case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1002 0 : if (vty)
1003 0 : vty_out(vty,
1004 : "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
1005 : peer->host);
1006 : else
1007 0 : zlog_warn(
1008 : "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
1009 : peer->host);
1010 : break;
1011 : default:
1012 : break;
1013 : }
1014 0 : }
1015 :
1016 0 : static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
1017 : struct listnode **nnode, enum bgp_clear_type stype)
1018 : {
1019 0 : int ret = 0;
1020 0 : struct peer_af *paf;
1021 :
1022 : /* if afi/.safi not specified, spin thru all of them */
1023 0 : if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1024 : afi_t tmp_afi;
1025 : safi_t tmp_safi;
1026 : enum bgp_af_index index;
1027 :
1028 0 : for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1029 0 : paf = peer->peer_af_array[index];
1030 0 : if (!paf)
1031 0 : continue;
1032 :
1033 0 : if (paf && paf->subgroup)
1034 0 : SET_FLAG(paf->subgroup->sflags,
1035 : SUBGRP_STATUS_FORCE_UPDATES);
1036 :
1037 0 : tmp_afi = paf->afi;
1038 0 : tmp_safi = paf->safi;
1039 0 : if (!peer->afc[tmp_afi][tmp_safi])
1040 0 : continue;
1041 :
1042 0 : if (stype == BGP_CLEAR_SOFT_NONE)
1043 0 : ret = peer_clear(peer, nnode);
1044 : else
1045 0 : ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1046 : stype);
1047 : }
1048 : /* if afi specified and safi not, spin thru safis on this afi */
1049 0 : } else if (safi == SAFI_UNSPEC) {
1050 : safi_t tmp_safi;
1051 :
1052 : for (tmp_safi = SAFI_UNICAST;
1053 0 : tmp_safi < SAFI_MAX; tmp_safi++) {
1054 0 : if (!peer->afc[afi][tmp_safi])
1055 0 : continue;
1056 :
1057 0 : paf = peer_af_find(peer, afi, tmp_safi);
1058 0 : if (paf && paf->subgroup)
1059 0 : SET_FLAG(paf->subgroup->sflags,
1060 : SUBGRP_STATUS_FORCE_UPDATES);
1061 :
1062 0 : if (stype == BGP_CLEAR_SOFT_NONE)
1063 0 : ret = peer_clear(peer, nnode);
1064 : else
1065 0 : ret = peer_clear_soft(peer, afi,
1066 : tmp_safi, stype);
1067 : }
1068 : /* both afi/safi specified, let the caller know if not defined */
1069 : } else {
1070 0 : if (!peer->afc[afi][safi])
1071 : return 1;
1072 :
1073 0 : paf = peer_af_find(peer, afi, safi);
1074 0 : if (paf && paf->subgroup)
1075 0 : SET_FLAG(paf->subgroup->sflags,
1076 : SUBGRP_STATUS_FORCE_UPDATES);
1077 :
1078 0 : if (stype == BGP_CLEAR_SOFT_NONE)
1079 0 : ret = peer_clear(peer, nnode);
1080 : else
1081 0 : ret = peer_clear_soft(peer, afi, safi, stype);
1082 : }
1083 :
1084 : return ret;
1085 : }
1086 :
1087 : /* `clear ip bgp' functions. */
1088 0 : static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1089 : enum clear_sort sort, enum bgp_clear_type stype,
1090 : const char *arg)
1091 : {
1092 0 : int ret = 0;
1093 0 : bool found = false;
1094 0 : struct peer *peer;
1095 :
1096 0 : VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1097 :
1098 : /* Clear all neighbors. */
1099 : /*
1100 : * Pass along pointer to next node to peer_clear() when walking all
1101 : * nodes on the BGP instance as that may get freed if it is a
1102 : * doppelganger
1103 : */
1104 0 : if (sort == clear_all) {
1105 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1106 :
1107 0 : bgp_peer_gr_flags_update(peer);
1108 :
1109 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1110 0 : gr_router_detected = true;
1111 :
1112 0 : ret = bgp_peer_clear(peer, afi, safi, &nnode,
1113 : stype);
1114 :
1115 0 : if (ret < 0)
1116 0 : bgp_clear_vty_error(vty, peer, afi, safi, ret);
1117 : }
1118 :
1119 0 : if (gr_router_detected
1120 0 : && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1121 0 : bgp_zebra_send_capabilities(bgp, false);
1122 0 : } else if (!gr_router_detected
1123 0 : && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1124 0 : bgp_zebra_send_capabilities(bgp, true);
1125 : }
1126 :
1127 : /* This is to apply read-only mode on this clear. */
1128 0 : if (stype == BGP_CLEAR_SOFT_NONE)
1129 0 : bgp->update_delay_over = 0;
1130 :
1131 0 : return CMD_SUCCESS;
1132 : }
1133 :
1134 : /* Clear specified neighbor. */
1135 0 : if (sort == clear_peer) {
1136 0 : union sockunion su;
1137 :
1138 : /* Make sockunion for lookup. */
1139 0 : ret = str2sockunion(arg, &su);
1140 0 : if (ret < 0) {
1141 0 : peer = peer_lookup_by_conf_if(bgp, arg);
1142 0 : if (!peer) {
1143 0 : peer = peer_lookup_by_hostname(bgp, arg);
1144 0 : if (!peer) {
1145 0 : vty_out(vty,
1146 : "Malformed address or name: %s\n",
1147 : arg);
1148 0 : return CMD_WARNING;
1149 : }
1150 : }
1151 : } else {
1152 0 : peer = peer_lookup(bgp, &su);
1153 0 : if (!peer) {
1154 0 : vty_out(vty,
1155 : "%% BGP: Unknown neighbor - \"%s\"\n",
1156 : arg);
1157 0 : return CMD_WARNING;
1158 : }
1159 : }
1160 :
1161 0 : VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1162 0 : VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1163 :
1164 0 : ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1165 :
1166 : /* if afi/safi not defined for this peer, let caller know */
1167 0 : if (ret == 1)
1168 : ret = BGP_ERR_AF_UNCONFIGURED;
1169 :
1170 0 : if (ret < 0)
1171 0 : bgp_clear_vty_error(vty, peer, afi, safi, ret);
1172 :
1173 0 : return CMD_SUCCESS;
1174 : }
1175 :
1176 : /* Clear all neighbors belonging to a specific peer-group. */
1177 0 : if (sort == clear_group) {
1178 0 : struct peer_group *group;
1179 :
1180 0 : group = peer_group_lookup(bgp, arg);
1181 0 : if (!group) {
1182 0 : vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1183 0 : return CMD_WARNING;
1184 : }
1185 :
1186 0 : for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1187 0 : ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1188 :
1189 0 : if (ret < 0)
1190 0 : bgp_clear_vty_error(vty, peer, afi, safi, ret);
1191 : else
1192 : found = true;
1193 : }
1194 :
1195 0 : if (!found)
1196 0 : vty_out(vty,
1197 : "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1198 : get_afi_safi_str(afi, safi, false), arg);
1199 :
1200 0 : return CMD_SUCCESS;
1201 : }
1202 :
1203 : /* Clear all external (eBGP) neighbors. */
1204 0 : if (sort == clear_external) {
1205 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1206 0 : if (peer->sort == BGP_PEER_IBGP)
1207 0 : continue;
1208 :
1209 0 : bgp_peer_gr_flags_update(peer);
1210 :
1211 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1212 0 : gr_router_detected = true;
1213 :
1214 0 : ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1215 :
1216 0 : if (ret < 0)
1217 0 : bgp_clear_vty_error(vty, peer, afi, safi, ret);
1218 : else
1219 : found = true;
1220 : }
1221 :
1222 0 : if (gr_router_detected
1223 0 : && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1224 0 : bgp_zebra_send_capabilities(bgp, false);
1225 0 : } else if (!gr_router_detected
1226 0 : && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1227 0 : bgp_zebra_send_capabilities(bgp, true);
1228 : }
1229 :
1230 0 : if (!found)
1231 0 : vty_out(vty,
1232 : "%% BGP: No external %s peer is configured\n",
1233 : get_afi_safi_str(afi, safi, false));
1234 :
1235 0 : return CMD_SUCCESS;
1236 : }
1237 :
1238 : /* Clear all neighbors belonging to a specific AS. */
1239 0 : if (sort == clear_as) {
1240 0 : as_t as = strtoul(arg, NULL, 10);
1241 :
1242 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1243 0 : if (peer->as != as)
1244 0 : continue;
1245 :
1246 0 : bgp_peer_gr_flags_update(peer);
1247 :
1248 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1249 0 : gr_router_detected = true;
1250 :
1251 0 : ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1252 :
1253 0 : if (ret < 0)
1254 0 : bgp_clear_vty_error(vty, peer, afi, safi, ret);
1255 : else
1256 : found = true;
1257 : }
1258 :
1259 0 : if (gr_router_detected
1260 0 : && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1261 0 : bgp_zebra_send_capabilities(bgp, false);
1262 0 : } else if (!gr_router_detected
1263 0 : && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1264 0 : bgp_zebra_send_capabilities(bgp, true);
1265 : }
1266 :
1267 0 : if (!found)
1268 0 : vty_out(vty,
1269 : "%% BGP: No %s peer is configured with AS %s\n",
1270 : get_afi_safi_str(afi, safi, false), arg);
1271 :
1272 0 : return CMD_SUCCESS;
1273 : }
1274 :
1275 : return CMD_SUCCESS;
1276 : }
1277 :
1278 0 : static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1279 : safi_t safi, enum clear_sort sort,
1280 : enum bgp_clear_type stype, const char *arg)
1281 : {
1282 0 : struct bgp *bgp;
1283 :
1284 : /* BGP structure lookup. */
1285 0 : if (name) {
1286 0 : bgp = bgp_lookup_by_name(name);
1287 0 : if (bgp == NULL) {
1288 0 : vty_out(vty, "Can't find BGP instance %s\n", name);
1289 0 : return CMD_WARNING;
1290 : }
1291 : } else {
1292 0 : bgp = bgp_get_default();
1293 0 : if (bgp == NULL) {
1294 0 : vty_out(vty, "No BGP process is configured\n");
1295 0 : return CMD_WARNING;
1296 : }
1297 : }
1298 :
1299 0 : return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1300 : }
1301 :
1302 : /* clear soft inbound */
1303 0 : static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1304 : {
1305 0 : afi_t afi;
1306 0 : safi_t safi;
1307 :
1308 0 : FOREACH_AFI_SAFI (afi, safi)
1309 0 : bgp_clear_vty(vty, name, afi, safi, clear_all,
1310 : BGP_CLEAR_SOFT_IN, NULL);
1311 0 : }
1312 :
1313 : /* clear soft outbound */
1314 0 : static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1315 : {
1316 0 : afi_t afi;
1317 0 : safi_t safi;
1318 :
1319 0 : FOREACH_AFI_SAFI (afi, safi)
1320 0 : bgp_clear_vty(vty, name, afi, safi, clear_all,
1321 : BGP_CLEAR_SOFT_OUT, NULL);
1322 0 : }
1323 :
1324 :
1325 0 : void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1326 : {
1327 0 : bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1328 0 : }
1329 :
1330 0 : static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
1331 : uint64_t flag, int set)
1332 : {
1333 0 : int ret;
1334 0 : struct peer *peer;
1335 :
1336 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
1337 0 : if (!peer)
1338 : return CMD_WARNING_CONFIG_FAILED;
1339 :
1340 : /*
1341 : * If 'neighbor <interface>', then this is for directly connected peers,
1342 : * we should not accept disable-connected-check.
1343 : */
1344 0 : if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
1345 0 : vty_out(vty,
1346 : "%s is directly connected peer, cannot accept disable-connected-check\n",
1347 : ip_str);
1348 0 : return CMD_WARNING_CONFIG_FAILED;
1349 : }
1350 :
1351 0 : if (!set && flag == PEER_FLAG_SHUTDOWN)
1352 0 : peer_tx_shutdown_message_unset(peer);
1353 :
1354 0 : if (set)
1355 0 : ret = peer_flag_set(peer, flag);
1356 : else
1357 0 : ret = peer_flag_unset(peer, flag);
1358 :
1359 0 : return bgp_vty_return(vty, ret);
1360 : }
1361 :
1362 0 : static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
1363 : {
1364 0 : return peer_flag_modify_vty(vty, ip_str, flag, 1);
1365 : }
1366 :
1367 0 : static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
1368 : uint64_t flag)
1369 : {
1370 0 : return peer_flag_modify_vty(vty, ip_str, flag, 0);
1371 : }
1372 :
1373 : #include "bgpd/bgp_vty_clippy.c"
1374 :
1375 0 : DEFUN_HIDDEN (bgp_local_mac,
1376 : bgp_local_mac_cmd,
1377 : "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1378 : BGP_STR
1379 : "Local MAC config\n"
1380 : "VxLAN Network Identifier\n"
1381 : "VNI number\n"
1382 : "local mac\n"
1383 : "mac address\n"
1384 : "mac-mobility sequence\n"
1385 : "seq number\n")
1386 : {
1387 0 : int rv;
1388 0 : vni_t vni;
1389 0 : struct ethaddr mac;
1390 0 : struct ipaddr ip;
1391 0 : uint32_t seq;
1392 0 : struct bgp *bgp;
1393 :
1394 0 : vni = strtoul(argv[3]->arg, NULL, 10);
1395 0 : if (!prefix_str2mac(argv[5]->arg, &mac)) {
1396 0 : vty_out(vty, "%% Malformed MAC address\n");
1397 0 : return CMD_WARNING;
1398 : }
1399 0 : memset(&ip, 0, sizeof(ip));
1400 0 : seq = strtoul(argv[7]->arg, NULL, 10);
1401 :
1402 0 : bgp = bgp_get_default();
1403 0 : if (!bgp) {
1404 0 : vty_out(vty, "Default BGP instance is not there\n");
1405 0 : return CMD_WARNING;
1406 : }
1407 :
1408 0 : rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1409 : zero_esi);
1410 0 : if (rv < 0) {
1411 0 : vty_out(vty, "Internal error\n");
1412 0 : return CMD_WARNING;
1413 : }
1414 :
1415 : return CMD_SUCCESS;
1416 : }
1417 :
1418 0 : DEFUN_HIDDEN (no_bgp_local_mac,
1419 : no_bgp_local_mac_cmd,
1420 : "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1421 : NO_STR
1422 : BGP_STR
1423 : "Local MAC config\n"
1424 : "VxLAN Network Identifier\n"
1425 : "VNI number\n"
1426 : "local mac\n"
1427 : "mac address\n")
1428 : {
1429 0 : int rv;
1430 0 : vni_t vni;
1431 0 : struct ethaddr mac;
1432 0 : struct ipaddr ip;
1433 0 : struct bgp *bgp;
1434 :
1435 0 : vni = strtoul(argv[4]->arg, NULL, 10);
1436 0 : if (!prefix_str2mac(argv[6]->arg, &mac)) {
1437 0 : vty_out(vty, "%% Malformed MAC address\n");
1438 0 : return CMD_WARNING;
1439 : }
1440 0 : memset(&ip, 0, sizeof(ip));
1441 :
1442 0 : bgp = bgp_get_default();
1443 0 : if (!bgp) {
1444 0 : vty_out(vty, "Default BGP instance is not there\n");
1445 0 : return CMD_WARNING;
1446 : }
1447 :
1448 0 : rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1449 0 : if (rv < 0) {
1450 0 : vty_out(vty, "Internal error\n");
1451 0 : return CMD_WARNING;
1452 : }
1453 :
1454 : return CMD_SUCCESS;
1455 : }
1456 :
1457 0 : DEFUN (no_synchronization,
1458 : no_synchronization_cmd,
1459 : "no synchronization",
1460 : NO_STR
1461 : "Perform IGP synchronization\n")
1462 : {
1463 0 : return CMD_SUCCESS;
1464 : }
1465 :
1466 0 : DEFUN (no_auto_summary,
1467 : no_auto_summary_cmd,
1468 : "no auto-summary",
1469 : NO_STR
1470 : "Enable automatic network number summarization\n")
1471 : {
1472 0 : return CMD_SUCCESS;
1473 : }
1474 :
1475 : /* "router bgp" commands. */
1476 3 : DEFUN_NOSH (router_bgp,
1477 : router_bgp_cmd,
1478 : "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1479 : ROUTER_STR
1480 : BGP_STR
1481 : AS_STR
1482 : BGP_INSTANCE_HELP_STR)
1483 : {
1484 3 : int idx_asn = 2;
1485 3 : int idx_view_vrf = 3;
1486 3 : int idx_vrf = 4;
1487 3 : int is_new_bgp = 0;
1488 3 : int ret;
1489 3 : as_t as;
1490 3 : struct bgp *bgp;
1491 3 : const char *name = NULL;
1492 3 : enum bgp_instance_type inst_type;
1493 :
1494 : // "router bgp" without an ASN
1495 3 : if (argc == 2) {
1496 : // Pending: Make VRF option available for ASN less config
1497 0 : bgp = bgp_get_default();
1498 :
1499 0 : if (bgp == NULL) {
1500 0 : vty_out(vty, "%% No BGP process is configured\n");
1501 0 : return CMD_WARNING_CONFIG_FAILED;
1502 : }
1503 :
1504 0 : if (listcount(bm->bgp) > 1) {
1505 0 : vty_out(vty, "%% Please specify ASN and VRF\n");
1506 0 : return CMD_WARNING_CONFIG_FAILED;
1507 : }
1508 : }
1509 :
1510 : // "router bgp X"
1511 : else {
1512 3 : as = strtoul(argv[idx_asn]->arg, NULL, 10);
1513 :
1514 3 : if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1515 0 : vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1516 : BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1517 :
1518 3 : inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1519 3 : if (argc > 3) {
1520 0 : name = argv[idx_vrf]->arg;
1521 :
1522 0 : if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1523 0 : if (strmatch(name, VRF_DEFAULT_NAME))
1524 : name = NULL;
1525 : else
1526 : inst_type = BGP_INSTANCE_TYPE_VRF;
1527 0 : } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1528 : inst_type = BGP_INSTANCE_TYPE_VIEW;
1529 : }
1530 :
1531 : if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1532 3 : is_new_bgp = (bgp_lookup(as, name) == NULL);
1533 :
1534 3 : ret = bgp_get_vty(&bgp, &as, name, inst_type);
1535 3 : switch (ret) {
1536 0 : case BGP_ERR_AS_MISMATCH:
1537 0 : vty_out(vty, "BGP is already running; AS is %u\n", as);
1538 0 : return CMD_WARNING_CONFIG_FAILED;
1539 0 : case BGP_ERR_INSTANCE_MISMATCH:
1540 0 : vty_out(vty,
1541 : "BGP instance name and AS number mismatch\n");
1542 0 : vty_out(vty,
1543 : "BGP instance is already running; AS is %u\n",
1544 : as);
1545 0 : return CMD_WARNING_CONFIG_FAILED;
1546 : }
1547 :
1548 : /*
1549 : * If we just instantiated the default instance, complete
1550 : * any pending VRF-VPN leaking that was configured via
1551 : * earlier "router bgp X vrf FOO" blocks.
1552 : */
1553 3 : if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1554 2 : vpn_leak_postchange_all();
1555 :
1556 3 : if (inst_type == BGP_INSTANCE_TYPE_VRF)
1557 0 : bgp_vpn_leak_export(bgp);
1558 : /* Pending: handle when user tries to change a view to vrf n vv.
1559 : */
1560 : }
1561 :
1562 : /* unset the auto created flag as the user config is now present */
1563 3 : UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1564 3 : VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1565 :
1566 3 : return CMD_SUCCESS;
1567 : }
1568 :
1569 : /* "no router bgp" commands. */
1570 0 : DEFUN (no_router_bgp,
1571 : no_router_bgp_cmd,
1572 : "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1573 : NO_STR
1574 : ROUTER_STR
1575 : BGP_STR
1576 : AS_STR
1577 : BGP_INSTANCE_HELP_STR)
1578 : {
1579 0 : int idx_asn = 3;
1580 0 : int idx_vrf = 5;
1581 0 : as_t as;
1582 0 : struct bgp *bgp;
1583 0 : const char *name = NULL;
1584 :
1585 : // "no router bgp" without an ASN
1586 0 : if (argc == 3) {
1587 : // Pending: Make VRF option available for ASN less config
1588 0 : bgp = bgp_get_default();
1589 :
1590 0 : if (bgp == NULL) {
1591 0 : vty_out(vty, "%% No BGP process is configured\n");
1592 0 : return CMD_WARNING_CONFIG_FAILED;
1593 : }
1594 :
1595 0 : if (listcount(bm->bgp) > 1) {
1596 0 : vty_out(vty, "%% Please specify ASN and VRF\n");
1597 0 : return CMD_WARNING_CONFIG_FAILED;
1598 : }
1599 :
1600 0 : if (bgp->l3vni) {
1601 0 : vty_out(vty, "%% Please unconfigure l3vni %u\n",
1602 : bgp->l3vni);
1603 0 : return CMD_WARNING_CONFIG_FAILED;
1604 : }
1605 : } else {
1606 0 : as = strtoul(argv[idx_asn]->arg, NULL, 10);
1607 :
1608 0 : if (argc > 4) {
1609 0 : name = argv[idx_vrf]->arg;
1610 0 : if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1611 0 : && strmatch(name, VRF_DEFAULT_NAME))
1612 0 : name = NULL;
1613 : }
1614 :
1615 : /* Lookup bgp structure. */
1616 0 : bgp = bgp_lookup(as, name);
1617 0 : if (!bgp) {
1618 0 : vty_out(vty, "%% Can't find BGP instance\n");
1619 0 : return CMD_WARNING_CONFIG_FAILED;
1620 : }
1621 :
1622 0 : if (bgp->l3vni) {
1623 0 : vty_out(vty, "%% Please unconfigure l3vni %u\n",
1624 : bgp->l3vni);
1625 0 : return CMD_WARNING_CONFIG_FAILED;
1626 : }
1627 :
1628 : /* Cannot delete default instance if vrf instances exist */
1629 0 : if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1630 0 : struct listnode *node;
1631 0 : struct bgp *tmp_bgp;
1632 :
1633 0 : for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1634 0 : if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1635 0 : continue;
1636 0 : if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1637 0 : BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1638 0 : CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1639 0 : BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1640 : CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1641 0 : BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1642 : CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1643 0 : BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1644 : CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1645 0 : BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1646 : CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1647 0 : BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1648 0 : (bgp == bgp_get_evpn() &&
1649 0 : (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1650 : BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1651 : CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1652 : BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1653 : CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1654 : BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1655 : CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1656 0 : BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1657 0 : (hashcount(tmp_bgp->vnihash))) {
1658 0 : vty_out(vty,
1659 : "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1660 0 : return CMD_WARNING_CONFIG_FAILED;
1661 : }
1662 : }
1663 : }
1664 : }
1665 :
1666 0 : bgp_delete(bgp);
1667 :
1668 0 : return CMD_SUCCESS;
1669 : }
1670 :
1671 : /* bgp session-dscp */
1672 :
1673 0 : DEFPY (bgp_session_dscp,
1674 : bgp_session_dscp_cmd,
1675 : "bgp session-dscp (0-63)$dscp",
1676 : BGP_STR
1677 : "Override default (C6) bgp TCP session DSCP value\n"
1678 : "Manually configured dscp parameter\n")
1679 : {
1680 0 : bm->tcp_dscp = dscp << 2;
1681 :
1682 0 : return CMD_SUCCESS;
1683 : }
1684 :
1685 0 : DEFPY (no_bgp_session_dscp,
1686 : no_bgp_session_dscp_cmd,
1687 : "no bgp session-dscp [(0-63)]",
1688 : NO_STR
1689 : BGP_STR
1690 : "Override default (C6) bgp TCP session DSCP value\n"
1691 : "Manually configured dscp parameter\n")
1692 : {
1693 0 : bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1694 :
1695 0 : return CMD_SUCCESS;
1696 : }
1697 :
1698 : /* BGP router-id. */
1699 :
1700 0 : DEFPY (bgp_router_id,
1701 : bgp_router_id_cmd,
1702 : "bgp router-id A.B.C.D",
1703 : BGP_STR
1704 : "Override configured router identifier\n"
1705 : "Manually configured router identifier\n")
1706 : {
1707 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
1708 0 : bgp_router_id_static_set(bgp, router_id);
1709 0 : return CMD_SUCCESS;
1710 : }
1711 :
1712 0 : DEFPY (no_bgp_router_id,
1713 : no_bgp_router_id_cmd,
1714 : "no bgp router-id [A.B.C.D]",
1715 : NO_STR
1716 : BGP_STR
1717 : "Override configured router identifier\n"
1718 : "Manually configured router identifier\n")
1719 : {
1720 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
1721 :
1722 0 : if (router_id_str) {
1723 0 : if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1724 0 : vty_out(vty, "%% BGP router-id doesn't match\n");
1725 0 : return CMD_WARNING_CONFIG_FAILED;
1726 : }
1727 : }
1728 :
1729 0 : router_id.s_addr = 0;
1730 0 : bgp_router_id_static_set(bgp, router_id);
1731 :
1732 0 : return CMD_SUCCESS;
1733 : }
1734 :
1735 0 : DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1736 : "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1737 : NO_STR BGP_STR
1738 : "Add community specific parameters\n"
1739 : "Create an alias for a community\n"
1740 : "Community (AA:BB or AA:BB:CC)\n"
1741 : "Alias name\n")
1742 : {
1743 0 : struct community_alias ca = {};
1744 0 : struct community_alias *lookup_community;
1745 0 : struct community_alias *lookup_alias;
1746 0 : struct community *comm;
1747 0 : struct lcommunity *lcomm;
1748 0 : uint8_t invalid = 0;
1749 :
1750 0 : comm = community_str2com(community);
1751 0 : if (!comm)
1752 0 : invalid++;
1753 0 : community_free(&comm);
1754 :
1755 0 : lcomm = lcommunity_str2com(community);
1756 0 : if (!lcomm)
1757 0 : invalid++;
1758 0 : lcommunity_free(&lcomm);
1759 :
1760 0 : if (invalid > 1) {
1761 0 : vty_out(vty, "Invalid community format\n");
1762 0 : return CMD_WARNING;
1763 : }
1764 :
1765 0 : strlcpy(ca.community, community, sizeof(ca.community));
1766 0 : strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1767 :
1768 0 : lookup_community = bgp_ca_community_lookup(&ca);
1769 0 : lookup_alias = bgp_ca_alias_lookup(&ca);
1770 :
1771 0 : if (no) {
1772 0 : bgp_ca_alias_delete(&ca);
1773 0 : bgp_ca_community_delete(&ca);
1774 : } else {
1775 0 : if (lookup_alias) {
1776 : /* Lookup if community hash table has an item
1777 : * with the same alias name.
1778 : */
1779 0 : strlcpy(ca.community, lookup_alias->community,
1780 : sizeof(ca.community));
1781 0 : if (bgp_ca_community_lookup(&ca)) {
1782 0 : vty_out(vty,
1783 : "community (%s) already has this alias (%s)\n",
1784 : lookup_alias->community,
1785 0 : lookup_alias->alias);
1786 0 : return CMD_WARNING;
1787 : }
1788 0 : bgp_ca_alias_delete(&ca);
1789 : }
1790 :
1791 0 : if (lookup_community) {
1792 : /* Lookup if alias hash table has an item
1793 : * with the same community.
1794 : */
1795 0 : strlcpy(ca.alias, lookup_community->alias,
1796 : sizeof(ca.alias));
1797 0 : if (bgp_ca_alias_lookup(&ca)) {
1798 0 : vty_out(vty,
1799 : "alias (%s) already has this community (%s)\n",
1800 : lookup_community->alias,
1801 0 : lookup_community->community);
1802 0 : return CMD_WARNING;
1803 : }
1804 0 : bgp_ca_community_delete(&ca);
1805 : }
1806 :
1807 0 : bgp_ca_alias_insert(&ca);
1808 0 : bgp_ca_community_insert(&ca);
1809 : }
1810 :
1811 : return CMD_SUCCESS;
1812 : }
1813 :
1814 0 : DEFPY (bgp_global_suppress_fib_pending,
1815 : bgp_global_suppress_fib_pending_cmd,
1816 : "[no] bgp suppress-fib-pending",
1817 : NO_STR
1818 : BGP_STR
1819 : "Advertise only routes that are programmed in kernel to peers globally\n")
1820 : {
1821 0 : bm_wait_for_fib_set(!no);
1822 :
1823 0 : return CMD_SUCCESS;
1824 : }
1825 :
1826 0 : DEFPY (bgp_suppress_fib_pending,
1827 : bgp_suppress_fib_pending_cmd,
1828 : "[no] bgp suppress-fib-pending",
1829 : NO_STR
1830 : BGP_STR
1831 : "Advertise only routes that are programmed in kernel to peers\n")
1832 : {
1833 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
1834 :
1835 0 : bgp_suppress_fib_pending_set(bgp, !no);
1836 0 : return CMD_SUCCESS;
1837 : }
1838 :
1839 :
1840 : /* BGP Cluster ID. */
1841 0 : DEFUN (bgp_cluster_id,
1842 : bgp_cluster_id_cmd,
1843 : "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1844 : BGP_STR
1845 : "Configure Route-Reflector Cluster-id\n"
1846 : "Route-Reflector Cluster-id in IP address format\n"
1847 : "Route-Reflector Cluster-id as 32 bit quantity\n")
1848 : {
1849 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
1850 0 : int idx_ipv4 = 2;
1851 0 : int ret;
1852 0 : struct in_addr cluster;
1853 :
1854 0 : ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1855 0 : if (!ret) {
1856 0 : vty_out(vty, "%% Malformed bgp cluster identifier\n");
1857 0 : return CMD_WARNING_CONFIG_FAILED;
1858 : }
1859 :
1860 0 : bgp_cluster_id_set(bgp, &cluster);
1861 0 : bgp_clear_star_soft_out(vty, bgp->name);
1862 :
1863 0 : return CMD_SUCCESS;
1864 : }
1865 :
1866 0 : DEFUN (no_bgp_cluster_id,
1867 : no_bgp_cluster_id_cmd,
1868 : "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1869 : NO_STR
1870 : BGP_STR
1871 : "Configure Route-Reflector Cluster-id\n"
1872 : "Route-Reflector Cluster-id in IP address format\n"
1873 : "Route-Reflector Cluster-id as 32 bit quantity\n")
1874 : {
1875 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
1876 0 : bgp_cluster_id_unset(bgp);
1877 0 : bgp_clear_star_soft_out(vty, bgp->name);
1878 :
1879 0 : return CMD_SUCCESS;
1880 : }
1881 :
1882 0 : DEFPY (bgp_norib,
1883 : bgp_norib_cmd,
1884 : "bgp no-rib",
1885 : BGP_STR
1886 : "Disable BGP route installation to RIB (Zebra)\n")
1887 : {
1888 0 : if (bgp_option_check(BGP_OPT_NO_FIB)) {
1889 0 : vty_out(vty,
1890 : "%% No-RIB option is already set, nothing to do here.\n");
1891 0 : return CMD_SUCCESS;
1892 : }
1893 :
1894 0 : bgp_option_norib_set_runtime();
1895 :
1896 0 : return CMD_SUCCESS;
1897 : }
1898 :
1899 0 : DEFPY (no_bgp_norib,
1900 : no_bgp_norib_cmd,
1901 : "no bgp no-rib",
1902 : NO_STR
1903 : BGP_STR
1904 : "Disable BGP route installation to RIB (Zebra)\n")
1905 : {
1906 0 : if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1907 0 : vty_out(vty,
1908 : "%% No-RIB option is not set, nothing to do here.\n");
1909 0 : return CMD_SUCCESS;
1910 : }
1911 :
1912 0 : bgp_option_norib_unset_runtime();
1913 :
1914 0 : return CMD_SUCCESS;
1915 : }
1916 :
1917 0 : DEFPY (no_bgp_send_extra_data,
1918 : no_bgp_send_extra_data_cmd,
1919 : "[no] bgp send-extra-data zebra",
1920 : NO_STR
1921 : BGP_STR
1922 : "Extra data to Zebra for display/use\n"
1923 : "To zebra\n")
1924 : {
1925 0 : if (no)
1926 0 : UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1927 : else
1928 0 : SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1929 :
1930 0 : return CMD_SUCCESS;
1931 : }
1932 :
1933 0 : DEFUN (bgp_confederation_identifier,
1934 : bgp_confederation_identifier_cmd,
1935 : "bgp confederation identifier (1-4294967295)",
1936 : BGP_STR
1937 : "AS confederation parameters\n"
1938 : "AS number\n"
1939 : "Set routing domain confederation AS\n")
1940 : {
1941 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
1942 0 : int idx_number = 3;
1943 0 : as_t as;
1944 :
1945 0 : as = strtoul(argv[idx_number]->arg, NULL, 10);
1946 :
1947 0 : bgp_confederation_id_set(bgp, as);
1948 :
1949 0 : return CMD_SUCCESS;
1950 : }
1951 :
1952 0 : DEFUN (no_bgp_confederation_identifier,
1953 : no_bgp_confederation_identifier_cmd,
1954 : "no bgp confederation identifier [(1-4294967295)]",
1955 : NO_STR
1956 : BGP_STR
1957 : "AS confederation parameters\n"
1958 : "AS number\n"
1959 : "Set routing domain confederation AS\n")
1960 : {
1961 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
1962 0 : bgp_confederation_id_unset(bgp);
1963 :
1964 0 : return CMD_SUCCESS;
1965 : }
1966 :
1967 0 : DEFUN (bgp_confederation_peers,
1968 : bgp_confederation_peers_cmd,
1969 : "bgp confederation peers (1-4294967295)...",
1970 : BGP_STR
1971 : "AS confederation parameters\n"
1972 : "Peer ASs in BGP confederation\n"
1973 : AS_STR)
1974 : {
1975 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
1976 : int idx_asn = 3;
1977 : as_t as;
1978 : int i;
1979 :
1980 0 : for (i = idx_asn; i < argc; i++) {
1981 0 : as = strtoul(argv[i]->arg, NULL, 10);
1982 0 : bgp_confederation_peers_add(bgp, as);
1983 : }
1984 : return CMD_SUCCESS;
1985 : }
1986 :
1987 0 : DEFUN (no_bgp_confederation_peers,
1988 : no_bgp_confederation_peers_cmd,
1989 : "no bgp confederation peers (1-4294967295)...",
1990 : NO_STR
1991 : BGP_STR
1992 : "AS confederation parameters\n"
1993 : "Peer ASs in BGP confederation\n"
1994 : AS_STR)
1995 : {
1996 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
1997 : int idx_asn = 4;
1998 : as_t as;
1999 : int i;
2000 :
2001 0 : for (i = idx_asn; i < argc; i++) {
2002 0 : as = strtoul(argv[i]->arg, NULL, 10);
2003 :
2004 0 : bgp_confederation_peers_remove(bgp, as);
2005 : }
2006 : return CMD_SUCCESS;
2007 : }
2008 :
2009 : /**
2010 : * Central routine for maximum-paths configuration.
2011 : * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
2012 : * @set: 1 for setting values, 0 for removing the max-paths config.
2013 : */
2014 0 : static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
2015 : const char *mpaths, uint16_t options,
2016 : int set)
2017 : {
2018 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2019 0 : uint16_t maxpaths = 0;
2020 0 : int ret;
2021 0 : afi_t afi;
2022 0 : safi_t safi;
2023 :
2024 0 : afi = bgp_node_afi(vty);
2025 0 : safi = bgp_node_safi(vty);
2026 :
2027 0 : if (set) {
2028 0 : maxpaths = strtol(mpaths, NULL, 10);
2029 0 : if (maxpaths > multipath_num) {
2030 0 : vty_out(vty,
2031 : "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
2032 : maxpaths, multipath_num);
2033 0 : return CMD_WARNING_CONFIG_FAILED;
2034 : }
2035 0 : ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
2036 : options);
2037 : } else
2038 0 : ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
2039 :
2040 0 : if (ret < 0) {
2041 0 : vty_out(vty,
2042 : "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
2043 : (set == 1) ? "" : "un",
2044 : (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
2045 : maxpaths, afi, safi);
2046 0 : return CMD_WARNING_CONFIG_FAILED;
2047 : }
2048 :
2049 0 : bgp_recalculate_all_bestpaths(bgp);
2050 :
2051 0 : return CMD_SUCCESS;
2052 : }
2053 :
2054 0 : DEFUN (bgp_maxmed_admin,
2055 : bgp_maxmed_admin_cmd,
2056 : "bgp max-med administrative ",
2057 : BGP_STR
2058 : "Advertise routes with max-med\n"
2059 : "Administratively applied, for an indefinite period\n")
2060 : {
2061 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2062 :
2063 0 : bgp->v_maxmed_admin = 1;
2064 0 : bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2065 :
2066 0 : bgp_maxmed_update(bgp);
2067 :
2068 0 : return CMD_SUCCESS;
2069 : }
2070 :
2071 0 : DEFUN (bgp_maxmed_admin_medv,
2072 : bgp_maxmed_admin_medv_cmd,
2073 : "bgp max-med administrative (0-4294967295)",
2074 : BGP_STR
2075 : "Advertise routes with max-med\n"
2076 : "Administratively applied, for an indefinite period\n"
2077 : "Max MED value to be used\n")
2078 : {
2079 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2080 0 : int idx_number = 3;
2081 :
2082 0 : bgp->v_maxmed_admin = 1;
2083 0 : bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
2084 :
2085 0 : bgp_maxmed_update(bgp);
2086 :
2087 0 : return CMD_SUCCESS;
2088 : }
2089 :
2090 0 : DEFUN (no_bgp_maxmed_admin,
2091 : no_bgp_maxmed_admin_cmd,
2092 : "no bgp max-med administrative [(0-4294967295)]",
2093 : NO_STR
2094 : BGP_STR
2095 : "Advertise routes with max-med\n"
2096 : "Administratively applied, for an indefinite period\n"
2097 : "Max MED value to be used\n")
2098 : {
2099 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2100 0 : bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2101 0 : bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2102 0 : bgp_maxmed_update(bgp);
2103 :
2104 0 : return CMD_SUCCESS;
2105 : }
2106 :
2107 0 : DEFUN (bgp_maxmed_onstartup,
2108 : bgp_maxmed_onstartup_cmd,
2109 : "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2110 : BGP_STR
2111 : "Advertise routes with max-med\n"
2112 : "Effective on a startup\n"
2113 : "Time (seconds) period for max-med\n"
2114 : "Max MED value to be used\n")
2115 : {
2116 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2117 0 : int idx = 0;
2118 :
2119 0 : if (argv_find(argv, argc, "(5-86400)", &idx))
2120 0 : bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2121 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
2122 0 : bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2123 : else
2124 0 : bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2125 :
2126 0 : bgp_maxmed_update(bgp);
2127 :
2128 0 : return CMD_SUCCESS;
2129 : }
2130 :
2131 0 : DEFUN (no_bgp_maxmed_onstartup,
2132 : no_bgp_maxmed_onstartup_cmd,
2133 : "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2134 : NO_STR
2135 : BGP_STR
2136 : "Advertise routes with max-med\n"
2137 : "Effective on a startup\n"
2138 : "Time (seconds) period for max-med\n"
2139 : "Max MED value to be used\n")
2140 : {
2141 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2142 :
2143 : /* Cancel max-med onstartup if its on */
2144 0 : if (bgp->t_maxmed_onstartup) {
2145 0 : THREAD_OFF(bgp->t_maxmed_onstartup);
2146 0 : bgp->maxmed_onstartup_over = 1;
2147 : }
2148 :
2149 0 : bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2150 0 : bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2151 :
2152 0 : bgp_maxmed_update(bgp);
2153 :
2154 0 : return CMD_SUCCESS;
2155 : }
2156 :
2157 0 : static int bgp_global_update_delay_config_vty(struct vty *vty,
2158 : uint16_t update_delay,
2159 : uint16_t establish_wait)
2160 : {
2161 0 : struct listnode *node, *nnode;
2162 0 : struct bgp *bgp;
2163 0 : bool vrf_cfg = false;
2164 :
2165 : /*
2166 : * See if update-delay is set per-vrf and warn user to delete it
2167 : * Note that we only need to check this if this is the first time
2168 : * setting the global config.
2169 : */
2170 0 : if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2171 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2172 0 : if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2173 0 : vty_out(vty,
2174 : "%% update-delay configuration found in vrf %s\n",
2175 0 : bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2176 0 : ? VRF_DEFAULT_NAME
2177 : : bgp->name);
2178 0 : vrf_cfg = true;
2179 : }
2180 : }
2181 : }
2182 :
2183 0 : if (vrf_cfg) {
2184 0 : vty_out(vty,
2185 : "%%Failed: global update-delay config not permitted\n");
2186 0 : return CMD_WARNING;
2187 : }
2188 :
2189 0 : if (!establish_wait) { /* update-delay <delay> */
2190 0 : bm->v_update_delay = update_delay;
2191 0 : bm->v_establish_wait = bm->v_update_delay;
2192 : } else {
2193 : /* update-delay <delay> <establish-wait> */
2194 0 : if (update_delay < establish_wait) {
2195 0 : vty_out(vty,
2196 : "%%Failed: update-delay less than the establish-wait!\n");
2197 0 : return CMD_WARNING_CONFIG_FAILED;
2198 : }
2199 :
2200 0 : bm->v_update_delay = update_delay;
2201 0 : bm->v_establish_wait = establish_wait;
2202 : }
2203 :
2204 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2205 0 : bgp->v_update_delay = bm->v_update_delay;
2206 0 : bgp->v_establish_wait = bm->v_establish_wait;
2207 : }
2208 :
2209 : return CMD_SUCCESS;
2210 : }
2211 :
2212 0 : static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2213 : {
2214 0 : struct listnode *node, *nnode;
2215 0 : struct bgp *bgp;
2216 :
2217 0 : bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2218 0 : bm->v_establish_wait = bm->v_update_delay;
2219 :
2220 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2221 0 : bgp->v_update_delay = bm->v_update_delay;
2222 0 : bgp->v_establish_wait = bm->v_establish_wait;
2223 : }
2224 :
2225 0 : return CMD_SUCCESS;
2226 : }
2227 :
2228 0 : static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2229 : uint16_t establish_wait)
2230 : {
2231 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2232 :
2233 : /* if configured globally, per-instance config is not allowed */
2234 0 : if (bm->v_update_delay) {
2235 0 : vty_out(vty,
2236 : "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2237 0 : return CMD_WARNING_CONFIG_FAILED;
2238 : }
2239 :
2240 :
2241 0 : if (!establish_wait) /* update-delay <delay> */
2242 : {
2243 0 : bgp->v_update_delay = update_delay;
2244 0 : bgp->v_establish_wait = bgp->v_update_delay;
2245 0 : return CMD_SUCCESS;
2246 : }
2247 :
2248 : /* update-delay <delay> <establish-wait> */
2249 0 : if (update_delay < establish_wait) {
2250 0 : vty_out(vty,
2251 : "%%Failed: update-delay less than the establish-wait!\n");
2252 0 : return CMD_WARNING_CONFIG_FAILED;
2253 : }
2254 :
2255 0 : bgp->v_update_delay = update_delay;
2256 0 : bgp->v_establish_wait = establish_wait;
2257 :
2258 0 : return CMD_SUCCESS;
2259 : }
2260 :
2261 0 : static int bgp_update_delay_deconfig_vty(struct vty *vty)
2262 : {
2263 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2264 :
2265 : /* If configured globally, cannot remove from one bgp instance */
2266 0 : if (bm->v_update_delay) {
2267 0 : vty_out(vty,
2268 : "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2269 0 : return CMD_WARNING_CONFIG_FAILED;
2270 : }
2271 0 : bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2272 0 : bgp->v_establish_wait = bgp->v_update_delay;
2273 :
2274 0 : return CMD_SUCCESS;
2275 : }
2276 :
2277 0 : void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2278 : {
2279 : /* If configured globally, no need to display per-instance value */
2280 0 : if (bgp->v_update_delay != bm->v_update_delay) {
2281 0 : vty_out(vty, " update-delay %d", bgp->v_update_delay);
2282 0 : if (bgp->v_update_delay != bgp->v_establish_wait)
2283 0 : vty_out(vty, " %d", bgp->v_establish_wait);
2284 0 : vty_out(vty, "\n");
2285 : }
2286 0 : }
2287 :
2288 : /* Global update-delay configuration */
2289 0 : DEFPY (bgp_global_update_delay,
2290 : bgp_global_update_delay_cmd,
2291 : "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2292 : BGP_STR
2293 : "Force initial delay for best-path and updates for all bgp instances\n"
2294 : "Max delay in seconds\n"
2295 : "Establish wait in seconds\n")
2296 : {
2297 0 : return bgp_global_update_delay_config_vty(vty, delay, wait);
2298 : }
2299 :
2300 : /* Global update-delay deconfiguration */
2301 0 : DEFPY (no_bgp_global_update_delay,
2302 : no_bgp_global_update_delay_cmd,
2303 : "no bgp update-delay [(0-3600) [(1-3600)]]",
2304 : NO_STR
2305 : BGP_STR
2306 : "Force initial delay for best-path and updates\n"
2307 : "Max delay in seconds\n"
2308 : "Establish wait in seconds\n")
2309 : {
2310 0 : return bgp_global_update_delay_deconfig_vty(vty);
2311 : }
2312 :
2313 : /* Update-delay configuration */
2314 :
2315 0 : DEFPY (bgp_update_delay,
2316 : bgp_update_delay_cmd,
2317 : "update-delay (0-3600)$delay [(1-3600)$wait]",
2318 : "Force initial delay for best-path and updates\n"
2319 : "Max delay in seconds\n"
2320 : "Establish wait in seconds\n")
2321 : {
2322 0 : return bgp_update_delay_config_vty(vty, delay, wait);
2323 : }
2324 :
2325 : /* Update-delay deconfiguration */
2326 0 : DEFPY (no_bgp_update_delay,
2327 : no_bgp_update_delay_cmd,
2328 : "no update-delay [(0-3600) [(1-3600)]]",
2329 : NO_STR
2330 : "Force initial delay for best-path and updates\n"
2331 : "Max delay in seconds\n"
2332 : "Establish wait in seconds\n")
2333 : {
2334 0 : return bgp_update_delay_deconfig_vty(vty);
2335 : }
2336 :
2337 :
2338 0 : static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2339 : bool set)
2340 : {
2341 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2342 :
2343 0 : quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2344 0 : atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2345 :
2346 0 : return CMD_SUCCESS;
2347 : }
2348 :
2349 0 : static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2350 : bool set)
2351 : {
2352 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2353 :
2354 0 : quanta = set ? quanta : BGP_READ_PACKET_MAX;
2355 0 : atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2356 :
2357 0 : return CMD_SUCCESS;
2358 : }
2359 :
2360 0 : void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2361 : {
2362 0 : uint32_t quanta =
2363 0 : atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2364 0 : if (quanta != BGP_WRITE_PACKET_MAX)
2365 0 : vty_out(vty, " write-quanta %d\n", quanta);
2366 0 : }
2367 :
2368 0 : void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2369 : {
2370 0 : uint32_t quanta =
2371 0 : atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2372 0 : if (quanta != BGP_READ_PACKET_MAX)
2373 0 : vty_out(vty, " read-quanta %d\n", quanta);
2374 0 : }
2375 :
2376 : /* Packet quanta configuration
2377 : *
2378 : * XXX: The value set here controls the size of a stack buffer in the IO
2379 : * thread. When changing these limits be careful to prevent stack overflow.
2380 : *
2381 : * Furthermore, the maximums used here should correspond to
2382 : * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2383 : */
2384 0 : DEFPY (bgp_wpkt_quanta,
2385 : bgp_wpkt_quanta_cmd,
2386 : "[no] write-quanta (1-64)$quanta",
2387 : NO_STR
2388 : "How many packets to write to peer socket per run\n"
2389 : "Number of packets\n")
2390 : {
2391 0 : return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2392 : }
2393 :
2394 0 : DEFPY (bgp_rpkt_quanta,
2395 : bgp_rpkt_quanta_cmd,
2396 : "[no] read-quanta (1-10)$quanta",
2397 : NO_STR
2398 : "How many packets to read from peer socket per I/O cycle\n"
2399 : "Number of packets\n")
2400 : {
2401 0 : return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2402 : }
2403 :
2404 0 : void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2405 : {
2406 0 : if (!bgp->heuristic_coalesce)
2407 0 : vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2408 0 : }
2409 :
2410 : /* BGP TCP keepalive */
2411 0 : static void bgp_config_tcp_keepalive(struct vty *vty, struct bgp *bgp)
2412 : {
2413 0 : if (bgp->tcp_keepalive_idle) {
2414 0 : vty_out(vty, " bgp tcp-keepalive %u %u %u\n",
2415 0 : bgp->tcp_keepalive_idle, bgp->tcp_keepalive_intvl,
2416 0 : bgp->tcp_keepalive_probes);
2417 : }
2418 0 : }
2419 :
2420 0 : DEFUN (bgp_coalesce_time,
2421 : bgp_coalesce_time_cmd,
2422 : "coalesce-time (0-4294967295)",
2423 : "Subgroup coalesce timer\n"
2424 : "Subgroup coalesce timer value (in ms)\n")
2425 : {
2426 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2427 :
2428 0 : int idx = 0;
2429 :
2430 0 : bgp->heuristic_coalesce = false;
2431 :
2432 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
2433 0 : bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2434 :
2435 : return CMD_SUCCESS;
2436 : }
2437 :
2438 0 : DEFUN (no_bgp_coalesce_time,
2439 : no_bgp_coalesce_time_cmd,
2440 : "no coalesce-time (0-4294967295)",
2441 : NO_STR
2442 : "Subgroup coalesce timer\n"
2443 : "Subgroup coalesce timer value (in ms)\n")
2444 : {
2445 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2446 :
2447 0 : bgp->heuristic_coalesce = true;
2448 0 : bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2449 0 : return CMD_SUCCESS;
2450 : }
2451 :
2452 : /* Maximum-paths configuration */
2453 0 : DEFUN (bgp_maxpaths,
2454 : bgp_maxpaths_cmd,
2455 : "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2456 : "Forward packets over multiple paths\n"
2457 : "Number of paths\n")
2458 : {
2459 0 : int idx_number = 1;
2460 0 : return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2461 0 : argv[idx_number]->arg, 0, 1);
2462 : }
2463 :
2464 : ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2465 : "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2466 : "Forward packets over multiple paths\n"
2467 : "Number of paths\n")
2468 :
2469 0 : DEFUN (bgp_maxpaths_ibgp,
2470 : bgp_maxpaths_ibgp_cmd,
2471 : "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2472 : "Forward packets over multiple paths\n"
2473 : "iBGP-multipath\n"
2474 : "Number of paths\n")
2475 : {
2476 0 : int idx_number = 2;
2477 0 : return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2478 0 : argv[idx_number]->arg, 0, 1);
2479 : }
2480 :
2481 : ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2482 : "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2483 : "Forward packets over multiple paths\n"
2484 : "iBGP-multipath\n"
2485 : "Number of paths\n")
2486 :
2487 0 : DEFUN (bgp_maxpaths_ibgp_cluster,
2488 : bgp_maxpaths_ibgp_cluster_cmd,
2489 : "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2490 : "Forward packets over multiple paths\n"
2491 : "iBGP-multipath\n"
2492 : "Number of paths\n"
2493 : "Match the cluster length\n")
2494 : {
2495 0 : int idx_number = 2;
2496 0 : return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2497 0 : argv[idx_number]->arg, true, 1);
2498 : }
2499 :
2500 : ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2501 : "maximum-paths ibgp " CMD_RANGE_STR(
2502 : 1, MULTIPATH_NUM) " equal-cluster-length",
2503 : "Forward packets over multiple paths\n"
2504 : "iBGP-multipath\n"
2505 : "Number of paths\n"
2506 : "Match the cluster length\n")
2507 :
2508 0 : DEFUN (no_bgp_maxpaths,
2509 : no_bgp_maxpaths_cmd,
2510 : "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2511 : NO_STR
2512 : "Forward packets over multiple paths\n"
2513 : "Number of paths\n")
2514 : {
2515 0 : return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2516 : }
2517 :
2518 : ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2519 : "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2520 : "Forward packets over multiple paths\n"
2521 : "Number of paths\n")
2522 :
2523 0 : DEFUN (no_bgp_maxpaths_ibgp,
2524 : no_bgp_maxpaths_ibgp_cmd,
2525 : "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2526 : NO_STR
2527 : "Forward packets over multiple paths\n"
2528 : "iBGP-multipath\n"
2529 : "Number of paths\n"
2530 : "Match the cluster length\n")
2531 : {
2532 0 : return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2533 : }
2534 :
2535 : ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2536 : "no maximum-paths ibgp [" CMD_RANGE_STR(
2537 : 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2538 : NO_STR
2539 : "Forward packets over multiple paths\n"
2540 : "iBGP-multipath\n"
2541 : "Number of paths\n"
2542 : "Match the cluster length\n")
2543 :
2544 0 : static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2545 : afi_t afi, safi_t safi)
2546 : {
2547 0 : if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2548 0 : vty_out(vty, " maximum-paths %d\n",
2549 : bgp->maxpaths[afi][safi].maxpaths_ebgp);
2550 : }
2551 :
2552 0 : if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2553 0 : vty_out(vty, " maximum-paths ibgp %d",
2554 : bgp->maxpaths[afi][safi].maxpaths_ibgp);
2555 0 : if (bgp->maxpaths[afi][safi].same_clusterlen)
2556 0 : vty_out(vty, " equal-cluster-length");
2557 0 : vty_out(vty, "\n");
2558 : }
2559 0 : }
2560 :
2561 : /* BGP timers. */
2562 :
2563 0 : DEFUN (bgp_timers,
2564 : bgp_timers_cmd,
2565 : "timers bgp (0-65535) (0-65535)",
2566 : "Adjust routing timers\n"
2567 : "BGP timers\n"
2568 : "Keepalive interval\n"
2569 : "Holdtime\n")
2570 : {
2571 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2572 0 : int idx_number = 2;
2573 0 : int idx_number_2 = 3;
2574 0 : unsigned long keepalive = 0;
2575 0 : unsigned long holdtime = 0;
2576 :
2577 0 : keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2578 0 : holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2579 :
2580 : /* Holdtime value check. */
2581 0 : if (holdtime < 3 && holdtime != 0) {
2582 0 : vty_out(vty,
2583 : "%% hold time value must be either 0 or greater than 3\n");
2584 0 : return CMD_WARNING_CONFIG_FAILED;
2585 : }
2586 :
2587 0 : bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2588 : BGP_DEFAULT_DELAYOPEN);
2589 :
2590 0 : return CMD_SUCCESS;
2591 : }
2592 :
2593 0 : DEFUN (no_bgp_timers,
2594 : no_bgp_timers_cmd,
2595 : "no timers bgp [(0-65535) (0-65535)]",
2596 : NO_STR
2597 : "Adjust routing timers\n"
2598 : "BGP timers\n"
2599 : "Keepalive interval\n"
2600 : "Holdtime\n")
2601 : {
2602 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2603 0 : bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2604 : DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2605 :
2606 0 : return CMD_SUCCESS;
2607 : }
2608 :
2609 : /* BGP minimum holdtime. */
2610 :
2611 0 : DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2612 : "bgp minimum-holdtime (1-65535)",
2613 : "BGP specific commands\n"
2614 : "BGP minimum holdtime\n"
2615 : "Seconds\n")
2616 : {
2617 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2618 0 : int idx_number = 2;
2619 0 : unsigned long min_holdtime;
2620 :
2621 0 : min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2622 :
2623 0 : bgp->default_min_holdtime = min_holdtime;
2624 :
2625 0 : return CMD_SUCCESS;
2626 : }
2627 :
2628 0 : DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2629 : "no bgp minimum-holdtime [(1-65535)]",
2630 : NO_STR
2631 : "BGP specific commands\n"
2632 : "BGP minimum holdtime\n"
2633 : "Seconds\n")
2634 : {
2635 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2636 :
2637 0 : bgp->default_min_holdtime = 0;
2638 :
2639 0 : return CMD_SUCCESS;
2640 : }
2641 :
2642 0 : DEFPY(bgp_tcp_keepalive, bgp_tcp_keepalive_cmd,
2643 : "bgp tcp-keepalive (1-65535)$idle (1-65535)$intvl (1-30)$probes",
2644 : BGP_STR
2645 : "TCP keepalive parameters\n"
2646 : "TCP keepalive idle time (seconds)\n"
2647 : "TCP keepalive interval (seconds)\n"
2648 : "TCP keepalive maximum probes\n")
2649 : {
2650 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2651 :
2652 0 : bgp_tcp_keepalive_set(bgp, (uint16_t)idle, (uint16_t)intvl,
2653 0 : (uint16_t)probes);
2654 :
2655 0 : return CMD_SUCCESS;
2656 : }
2657 :
2658 0 : DEFPY(no_bgp_tcp_keepalive, no_bgp_tcp_keepalive_cmd,
2659 : "no bgp tcp-keepalive [(1-65535) (1-65535) (1-30)]",
2660 : NO_STR
2661 : BGP_STR
2662 : "TCP keepalive parameters\n"
2663 : "TCP keepalive idle time (seconds)\n"
2664 : "TCP keepalive interval (seconds)\n"
2665 : "TCP keepalive maximum probes\n")
2666 : {
2667 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2668 :
2669 0 : bgp_tcp_keepalive_unset(bgp);
2670 :
2671 0 : return CMD_SUCCESS;
2672 : }
2673 :
2674 0 : DEFUN (bgp_client_to_client_reflection,
2675 : bgp_client_to_client_reflection_cmd,
2676 : "bgp client-to-client reflection",
2677 : BGP_STR
2678 : "Configure client to client route reflection\n"
2679 : "reflection of routes allowed\n")
2680 : {
2681 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2682 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2683 0 : bgp_clear_star_soft_out(vty, bgp->name);
2684 :
2685 0 : return CMD_SUCCESS;
2686 : }
2687 :
2688 0 : DEFUN (no_bgp_client_to_client_reflection,
2689 : no_bgp_client_to_client_reflection_cmd,
2690 : "no bgp client-to-client reflection",
2691 : NO_STR
2692 : BGP_STR
2693 : "Configure client to client route reflection\n"
2694 : "reflection of routes allowed\n")
2695 : {
2696 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2697 0 : SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2698 0 : bgp_clear_star_soft_out(vty, bgp->name);
2699 :
2700 0 : return CMD_SUCCESS;
2701 : }
2702 :
2703 : /* "bgp always-compare-med" configuration. */
2704 0 : DEFUN (bgp_always_compare_med,
2705 : bgp_always_compare_med_cmd,
2706 : "bgp always-compare-med",
2707 : BGP_STR
2708 : "Allow comparing MED from different neighbors\n")
2709 : {
2710 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2711 0 : SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2712 0 : bgp_recalculate_all_bestpaths(bgp);
2713 :
2714 0 : return CMD_SUCCESS;
2715 : }
2716 :
2717 0 : DEFUN (no_bgp_always_compare_med,
2718 : no_bgp_always_compare_med_cmd,
2719 : "no bgp always-compare-med",
2720 : NO_STR
2721 : BGP_STR
2722 : "Allow comparing MED from different neighbors\n")
2723 : {
2724 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2725 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2726 0 : bgp_recalculate_all_bestpaths(bgp);
2727 :
2728 0 : return CMD_SUCCESS;
2729 : }
2730 :
2731 :
2732 0 : DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2733 : "bgp ebgp-requires-policy",
2734 : BGP_STR
2735 : "Require in and out policy for eBGP peers (RFC8212)\n")
2736 : {
2737 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2738 0 : SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2739 0 : return CMD_SUCCESS;
2740 : }
2741 :
2742 2 : DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2743 : "no bgp ebgp-requires-policy",
2744 : NO_STR
2745 : BGP_STR
2746 : "Require in and out policy for eBGP peers (RFC8212)\n")
2747 : {
2748 2 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2749 2 : UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2750 2 : return CMD_SUCCESS;
2751 : }
2752 :
2753 0 : DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2754 : "bgp suppress-duplicates",
2755 : BGP_STR
2756 : "Suppress duplicate updates if the route actually not changed\n")
2757 : {
2758 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2759 0 : SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2760 0 : return CMD_SUCCESS;
2761 : }
2762 :
2763 0 : DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2764 : "no bgp suppress-duplicates",
2765 : NO_STR
2766 : BGP_STR
2767 : "Suppress duplicate updates if the route actually not changed\n")
2768 : {
2769 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2770 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2771 0 : return CMD_SUCCESS;
2772 : }
2773 :
2774 0 : DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2775 : "bgp reject-as-sets",
2776 : BGP_STR
2777 : "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2778 : {
2779 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2780 0 : struct listnode *node, *nnode;
2781 0 : struct peer *peer;
2782 :
2783 0 : bgp->reject_as_sets = true;
2784 :
2785 : /* Reset existing BGP sessions to reject routes
2786 : * with aspath containing AS_SET or AS_CONFED_SET.
2787 : */
2788 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2789 0 : if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2790 0 : peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2791 0 : bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2792 : BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2793 : }
2794 : }
2795 :
2796 : return CMD_SUCCESS;
2797 : }
2798 :
2799 0 : DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2800 : "no bgp reject-as-sets",
2801 : NO_STR
2802 : BGP_STR
2803 : "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2804 : {
2805 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2806 0 : struct listnode *node, *nnode;
2807 0 : struct peer *peer;
2808 :
2809 0 : bgp->reject_as_sets = false;
2810 :
2811 : /* Reset existing BGP sessions to reject routes
2812 : * with aspath containing AS_SET or AS_CONFED_SET.
2813 : */
2814 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2815 0 : if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2816 0 : peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2817 0 : bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2818 : BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2819 : }
2820 : }
2821 :
2822 : return CMD_SUCCESS;
2823 : }
2824 :
2825 : /* "bgp deterministic-med" configuration. */
2826 0 : DEFUN (bgp_deterministic_med,
2827 : bgp_deterministic_med_cmd,
2828 : "bgp deterministic-med",
2829 : BGP_STR
2830 : "Pick the best-MED path among paths advertised from the neighboring AS\n")
2831 : {
2832 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2833 :
2834 0 : if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2835 0 : SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2836 0 : bgp_recalculate_all_bestpaths(bgp);
2837 : }
2838 :
2839 : return CMD_SUCCESS;
2840 : }
2841 :
2842 0 : DEFUN (no_bgp_deterministic_med,
2843 : no_bgp_deterministic_med_cmd,
2844 : "no bgp deterministic-med",
2845 : NO_STR
2846 : BGP_STR
2847 : "Pick the best-MED path among paths advertised from the neighboring AS\n")
2848 : {
2849 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2850 0 : int bestpath_per_as_used;
2851 0 : afi_t afi;
2852 0 : safi_t safi;
2853 0 : struct peer *peer;
2854 0 : struct listnode *node, *nnode;
2855 :
2856 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2857 0 : bestpath_per_as_used = 0;
2858 :
2859 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2860 0 : FOREACH_AFI_SAFI (afi, safi)
2861 0 : if (bgp_addpath_dmed_required(
2862 0 : peer->addpath_type[afi][safi])) {
2863 : bestpath_per_as_used = 1;
2864 : break;
2865 : }
2866 :
2867 0 : if (bestpath_per_as_used)
2868 : break;
2869 : }
2870 :
2871 0 : if (bestpath_per_as_used) {
2872 0 : vty_out(vty,
2873 : "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2874 0 : return CMD_WARNING_CONFIG_FAILED;
2875 : } else {
2876 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2877 0 : bgp_recalculate_all_bestpaths(bgp);
2878 : }
2879 : }
2880 :
2881 : return CMD_SUCCESS;
2882 : }
2883 :
2884 : /* "bgp graceful-restart mode" configuration. */
2885 0 : DEFUN (bgp_graceful_restart,
2886 : bgp_graceful_restart_cmd,
2887 : "bgp graceful-restart",
2888 : BGP_STR
2889 : GR_CMD
2890 : )
2891 : {
2892 0 : int ret = BGP_GR_FAILURE;
2893 :
2894 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2895 0 : zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2896 :
2897 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2898 :
2899 0 : ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2900 :
2901 0 : VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2902 : ret);
2903 :
2904 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2905 0 : zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2906 0 : vty_out(vty,
2907 : "Graceful restart configuration changed, reset all peers to take effect\n");
2908 0 : return bgp_vty_return(vty, ret);
2909 : }
2910 :
2911 0 : DEFUN (no_bgp_graceful_restart,
2912 : no_bgp_graceful_restart_cmd,
2913 : "no bgp graceful-restart",
2914 : NO_STR
2915 : BGP_STR
2916 : NO_GR_CMD
2917 : )
2918 : {
2919 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2920 :
2921 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2922 0 : zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2923 :
2924 0 : int ret = BGP_GR_FAILURE;
2925 :
2926 0 : ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2927 :
2928 0 : VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2929 : ret);
2930 :
2931 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2932 0 : zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2933 0 : vty_out(vty,
2934 : "Graceful restart configuration changed, reset all peers to take effect\n");
2935 :
2936 0 : return bgp_vty_return(vty, ret);
2937 : }
2938 :
2939 0 : DEFUN (bgp_graceful_restart_stalepath_time,
2940 : bgp_graceful_restart_stalepath_time_cmd,
2941 : "bgp graceful-restart stalepath-time (1-4095)",
2942 : BGP_STR
2943 : "Graceful restart capability parameters\n"
2944 : "Set the max time to hold onto restarting peer's stale paths\n"
2945 : "Delay value (seconds)\n")
2946 : {
2947 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2948 0 : int idx_number = 3;
2949 0 : uint32_t stalepath;
2950 :
2951 0 : stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2952 0 : bgp->stalepath_time = stalepath;
2953 0 : return CMD_SUCCESS;
2954 : }
2955 :
2956 0 : DEFUN (bgp_graceful_restart_restart_time,
2957 : bgp_graceful_restart_restart_time_cmd,
2958 : "bgp graceful-restart restart-time (0-4095)",
2959 : BGP_STR
2960 : "Graceful restart capability parameters\n"
2961 : "Set the time to wait to delete stale routes before a BGP open message is received\n"
2962 : "Delay value (seconds)\n")
2963 : {
2964 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2965 0 : int idx_number = 3;
2966 0 : uint32_t restart;
2967 :
2968 0 : restart = strtoul(argv[idx_number]->arg, NULL, 10);
2969 0 : bgp->restart_time = restart;
2970 0 : return CMD_SUCCESS;
2971 : }
2972 :
2973 0 : DEFUN (bgp_graceful_restart_select_defer_time,
2974 : bgp_graceful_restart_select_defer_time_cmd,
2975 : "bgp graceful-restart select-defer-time (0-3600)",
2976 : BGP_STR
2977 : "Graceful restart capability parameters\n"
2978 : "Set the time to defer the BGP route selection after restart\n"
2979 : "Delay value (seconds, 0 - disable)\n")
2980 : {
2981 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
2982 0 : int idx_number = 3;
2983 0 : uint32_t defer_time;
2984 :
2985 0 : defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2986 0 : bgp->select_defer_time = defer_time;
2987 0 : if (defer_time == 0)
2988 0 : SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2989 : else
2990 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2991 :
2992 : return CMD_SUCCESS;
2993 : }
2994 :
2995 0 : DEFUN (no_bgp_graceful_restart_stalepath_time,
2996 : no_bgp_graceful_restart_stalepath_time_cmd,
2997 : "no bgp graceful-restart stalepath-time [(1-4095)]",
2998 : NO_STR
2999 : BGP_STR
3000 : "Graceful restart capability parameters\n"
3001 : "Set the max time to hold onto restarting peer's stale paths\n"
3002 : "Delay value (seconds)\n")
3003 : {
3004 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3005 :
3006 0 : bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
3007 0 : return CMD_SUCCESS;
3008 : }
3009 :
3010 0 : DEFUN (no_bgp_graceful_restart_restart_time,
3011 : no_bgp_graceful_restart_restart_time_cmd,
3012 : "no bgp graceful-restart restart-time [(0-4095)]",
3013 : NO_STR
3014 : BGP_STR
3015 : "Graceful restart capability parameters\n"
3016 : "Set the time to wait to delete stale routes before a BGP open message is received\n"
3017 : "Delay value (seconds)\n")
3018 : {
3019 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3020 :
3021 0 : bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
3022 0 : return CMD_SUCCESS;
3023 : }
3024 :
3025 0 : DEFUN (no_bgp_graceful_restart_select_defer_time,
3026 : no_bgp_graceful_restart_select_defer_time_cmd,
3027 : "no bgp graceful-restart select-defer-time [(0-3600)]",
3028 : NO_STR
3029 : BGP_STR
3030 : "Graceful restart capability parameters\n"
3031 : "Set the time to defer the BGP route selection after restart\n"
3032 : "Delay value (seconds)\n")
3033 : {
3034 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3035 :
3036 0 : bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
3037 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
3038 :
3039 0 : return CMD_SUCCESS;
3040 : }
3041 :
3042 0 : DEFUN (bgp_graceful_restart_preserve_fw,
3043 : bgp_graceful_restart_preserve_fw_cmd,
3044 : "bgp graceful-restart preserve-fw-state",
3045 : BGP_STR
3046 : "Graceful restart capability parameters\n"
3047 : "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
3048 : {
3049 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3050 0 : SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3051 0 : return CMD_SUCCESS;
3052 : }
3053 :
3054 0 : DEFUN (no_bgp_graceful_restart_preserve_fw,
3055 : no_bgp_graceful_restart_preserve_fw_cmd,
3056 : "no bgp graceful-restart preserve-fw-state",
3057 : NO_STR
3058 : BGP_STR
3059 : "Graceful restart capability parameters\n"
3060 : "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
3061 : {
3062 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3063 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
3064 0 : return CMD_SUCCESS;
3065 : }
3066 :
3067 0 : DEFPY (bgp_graceful_restart_notification,
3068 : bgp_graceful_restart_notification_cmd,
3069 : "[no$no] bgp graceful-restart notification",
3070 : NO_STR
3071 : BGP_STR
3072 : "Graceful restart capability parameters\n"
3073 : "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
3074 : {
3075 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3076 :
3077 0 : if (no)
3078 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3079 : else
3080 0 : SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
3081 :
3082 : return CMD_SUCCESS;
3083 : }
3084 :
3085 0 : DEFPY (bgp_administrative_reset,
3086 : bgp_administrative_reset_cmd,
3087 : "[no$no] bgp hard-administrative-reset",
3088 : NO_STR
3089 : BGP_STR
3090 : "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
3091 : {
3092 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3093 :
3094 0 : if (no)
3095 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3096 : else
3097 0 : SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3098 :
3099 : return CMD_SUCCESS;
3100 : }
3101 :
3102 0 : DEFUN (bgp_graceful_restart_disable,
3103 : bgp_graceful_restart_disable_cmd,
3104 : "bgp graceful-restart-disable",
3105 : BGP_STR
3106 : GR_DISABLE)
3107 : {
3108 0 : int ret = BGP_GR_FAILURE;
3109 :
3110 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3111 0 : zlog_debug(
3112 : "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
3113 :
3114 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3115 :
3116 0 : ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3117 :
3118 0 : VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3119 : bgp->peer, ret);
3120 :
3121 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3122 0 : zlog_debug(
3123 : "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
3124 0 : vty_out(vty,
3125 : "Graceful restart configuration changed, reset all peers to take effect\n");
3126 :
3127 0 : return bgp_vty_return(vty, ret);
3128 : }
3129 :
3130 0 : DEFUN (no_bgp_graceful_restart_disable,
3131 : no_bgp_graceful_restart_disable_cmd,
3132 : "no bgp graceful-restart-disable",
3133 : NO_STR
3134 : BGP_STR
3135 : NO_GR_DISABLE
3136 : )
3137 : {
3138 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3139 :
3140 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3141 0 : zlog_debug(
3142 : "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3143 :
3144 0 : int ret = BGP_GR_FAILURE;
3145 :
3146 0 : ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3147 :
3148 0 : VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3149 : ret);
3150 :
3151 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3152 0 : zlog_debug(
3153 : "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3154 0 : vty_out(vty,
3155 : "Graceful restart configuration changed, reset all peers to take effect\n");
3156 :
3157 0 : return bgp_vty_return(vty, ret);
3158 : }
3159 :
3160 0 : DEFUN (bgp_neighbor_graceful_restart_set,
3161 : bgp_neighbor_graceful_restart_set_cmd,
3162 : "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3163 : NEIGHBOR_STR
3164 : NEIGHBOR_ADDR_STR2
3165 : GR_NEIGHBOR_CMD
3166 : )
3167 : {
3168 0 : int idx_peer = 1;
3169 0 : struct peer *peer;
3170 0 : int ret = BGP_GR_FAILURE;
3171 :
3172 0 : VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3173 :
3174 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3175 0 : zlog_debug(
3176 : "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3177 :
3178 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3179 0 : if (!peer)
3180 : return CMD_WARNING_CONFIG_FAILED;
3181 :
3182 0 : ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3183 :
3184 0 : VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3185 0 : VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3186 :
3187 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3188 0 : zlog_debug(
3189 : "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3190 0 : vty_out(vty,
3191 : "Graceful restart configuration changed, reset this peer to take effect\n");
3192 :
3193 0 : return bgp_vty_return(vty, ret);
3194 : }
3195 :
3196 0 : DEFUN (no_bgp_neighbor_graceful_restart,
3197 : no_bgp_neighbor_graceful_restart_set_cmd,
3198 : "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3199 : NO_STR
3200 : NEIGHBOR_STR
3201 : NEIGHBOR_ADDR_STR2
3202 : NO_GR_NEIGHBOR_CMD
3203 : )
3204 : {
3205 0 : int idx_peer = 2;
3206 0 : int ret = BGP_GR_FAILURE;
3207 0 : struct peer *peer;
3208 :
3209 0 : VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3210 :
3211 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3212 0 : if (!peer)
3213 : return CMD_WARNING_CONFIG_FAILED;
3214 :
3215 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3216 0 : zlog_debug(
3217 : "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3218 :
3219 0 : ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3220 :
3221 0 : VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3222 0 : VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3223 :
3224 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3225 0 : zlog_debug(
3226 : "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3227 0 : vty_out(vty,
3228 : "Graceful restart configuration changed, reset this peer to take effect\n");
3229 :
3230 0 : return bgp_vty_return(vty, ret);
3231 : }
3232 :
3233 0 : DEFUN (bgp_neighbor_graceful_restart_helper_set,
3234 : bgp_neighbor_graceful_restart_helper_set_cmd,
3235 : "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3236 : NEIGHBOR_STR
3237 : NEIGHBOR_ADDR_STR2
3238 : GR_NEIGHBOR_HELPER_CMD
3239 : )
3240 : {
3241 0 : int idx_peer = 1;
3242 0 : struct peer *peer;
3243 0 : int ret = BGP_GR_FAILURE;
3244 :
3245 0 : VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3246 :
3247 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3248 0 : zlog_debug(
3249 : "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3250 :
3251 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3252 :
3253 0 : if (!peer)
3254 : return CMD_WARNING_CONFIG_FAILED;
3255 :
3256 :
3257 0 : ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3258 :
3259 0 : VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3260 0 : VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3261 :
3262 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3263 0 : zlog_debug(
3264 : "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3265 0 : vty_out(vty,
3266 : "Graceful restart configuration changed, reset this peer to take effect\n");
3267 :
3268 0 : return bgp_vty_return(vty, ret);
3269 : }
3270 :
3271 0 : DEFUN (no_bgp_neighbor_graceful_restart_helper,
3272 : no_bgp_neighbor_graceful_restart_helper_set_cmd,
3273 : "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3274 : NO_STR
3275 : NEIGHBOR_STR
3276 : NEIGHBOR_ADDR_STR2
3277 : NO_GR_NEIGHBOR_HELPER_CMD
3278 : )
3279 : {
3280 0 : int idx_peer = 2;
3281 0 : int ret = BGP_GR_FAILURE;
3282 0 : struct peer *peer;
3283 :
3284 0 : VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3285 :
3286 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3287 0 : if (!peer)
3288 : return CMD_WARNING_CONFIG_FAILED;
3289 :
3290 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3291 0 : zlog_debug(
3292 : "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3293 :
3294 0 : ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3295 :
3296 0 : VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3297 0 : VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3298 :
3299 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3300 0 : zlog_debug(
3301 : "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3302 0 : vty_out(vty,
3303 : "Graceful restart configuration changed, reset this peer to take effect\n");
3304 :
3305 0 : return bgp_vty_return(vty, ret);
3306 : }
3307 :
3308 0 : DEFUN (bgp_neighbor_graceful_restart_disable_set,
3309 : bgp_neighbor_graceful_restart_disable_set_cmd,
3310 : "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3311 : NEIGHBOR_STR
3312 : NEIGHBOR_ADDR_STR2
3313 : GR_NEIGHBOR_DISABLE_CMD
3314 : )
3315 : {
3316 0 : int idx_peer = 1;
3317 0 : struct peer *peer;
3318 0 : int ret = BGP_GR_FAILURE;
3319 :
3320 0 : VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3321 :
3322 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3323 0 : zlog_debug(
3324 : "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3325 :
3326 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3327 0 : if (!peer)
3328 : return CMD_WARNING_CONFIG_FAILED;
3329 :
3330 0 : ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3331 :
3332 0 : if (peer->bgp->t_startup)
3333 0 : bgp_peer_gr_flags_update(peer);
3334 :
3335 0 : VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3336 0 : VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3337 :
3338 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3339 0 : zlog_debug(
3340 : "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3341 0 : vty_out(vty,
3342 : "Graceful restart configuration changed, reset this peer to take effect\n");
3343 :
3344 0 : return bgp_vty_return(vty, ret);
3345 : }
3346 :
3347 0 : DEFUN (no_bgp_neighbor_graceful_restart_disable,
3348 : no_bgp_neighbor_graceful_restart_disable_set_cmd,
3349 : "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3350 : NO_STR
3351 : NEIGHBOR_STR
3352 : NEIGHBOR_ADDR_STR2
3353 : NO_GR_NEIGHBOR_DISABLE_CMD
3354 : )
3355 : {
3356 0 : int idx_peer = 2;
3357 0 : int ret = BGP_GR_FAILURE;
3358 0 : struct peer *peer;
3359 :
3360 0 : VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3361 :
3362 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3363 0 : if (!peer)
3364 : return CMD_WARNING_CONFIG_FAILED;
3365 :
3366 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3367 0 : zlog_debug(
3368 : "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3369 :
3370 0 : ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3371 :
3372 0 : VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3373 0 : VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3374 :
3375 0 : if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3376 0 : zlog_debug(
3377 : "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3378 0 : vty_out(vty,
3379 : "Graceful restart configuration changed, reset this peer to take effect\n");
3380 :
3381 0 : return bgp_vty_return(vty, ret);
3382 : }
3383 :
3384 0 : DEFPY (neighbor_graceful_shutdown,
3385 : neighbor_graceful_shutdown_cmd,
3386 : "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor graceful-shutdown",
3387 : NO_STR
3388 : NEIGHBOR_STR
3389 : NEIGHBOR_ADDR_STR2
3390 : "Graceful shutdown\n")
3391 : {
3392 0 : afi_t afi;
3393 0 : safi_t safi;
3394 0 : struct peer *peer;
3395 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3396 0 : int ret;
3397 :
3398 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
3399 0 : if (!peer)
3400 : return CMD_WARNING_CONFIG_FAILED;
3401 :
3402 0 : if (no)
3403 0 : ret = peer_flag_unset_vty(vty, neighbor,
3404 : PEER_FLAG_GRACEFUL_SHUTDOWN);
3405 : else
3406 0 : ret = peer_flag_set_vty(vty, neighbor,
3407 : PEER_FLAG_GRACEFUL_SHUTDOWN);
3408 :
3409 0 : FOREACH_AFI_SAFI (afi, safi) {
3410 0 : if (!peer->afc[afi][safi])
3411 0 : continue;
3412 :
3413 0 : bgp_clear(vty, bgp, afi, safi, clear_peer, BGP_CLEAR_SOFT_IN,
3414 : neighbor);
3415 : }
3416 :
3417 : return ret;
3418 : }
3419 :
3420 0 : DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3421 : bgp_graceful_restart_disable_eor_cmd,
3422 : "bgp graceful-restart disable-eor",
3423 : BGP_STR
3424 : "Graceful restart configuration parameters\n"
3425 : "Disable EOR Check\n")
3426 : {
3427 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3428 0 : SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3429 :
3430 0 : return CMD_SUCCESS;
3431 : }
3432 :
3433 0 : DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3434 : no_bgp_graceful_restart_disable_eor_cmd,
3435 : "no bgp graceful-restart disable-eor",
3436 : NO_STR
3437 : BGP_STR
3438 : "Graceful restart configuration parameters\n"
3439 : "Disable EOR Check\n")
3440 : {
3441 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3442 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3443 :
3444 0 : return CMD_SUCCESS;
3445 : }
3446 :
3447 0 : DEFUN (bgp_graceful_restart_rib_stale_time,
3448 : bgp_graceful_restart_rib_stale_time_cmd,
3449 : "bgp graceful-restart rib-stale-time (1-3600)",
3450 : BGP_STR
3451 : "Graceful restart configuration parameters\n"
3452 : "Specify the stale route removal timer in rib\n"
3453 : "Delay value (seconds)\n")
3454 : {
3455 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3456 0 : int idx_number = 3;
3457 0 : uint32_t stale_time;
3458 :
3459 0 : stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3460 0 : bgp->rib_stale_time = stale_time;
3461 : /* Send the stale timer update message to RIB */
3462 0 : if (bgp_zebra_stale_timer_update(bgp))
3463 : return CMD_WARNING;
3464 :
3465 : return CMD_SUCCESS;
3466 : }
3467 :
3468 0 : DEFUN (no_bgp_graceful_restart_rib_stale_time,
3469 : no_bgp_graceful_restart_rib_stale_time_cmd,
3470 : "no bgp graceful-restart rib-stale-time [(1-3600)]",
3471 : NO_STR
3472 : BGP_STR
3473 : "Graceful restart configuration parameters\n"
3474 : "Specify the stale route removal timer in rib\n"
3475 : "Delay value (seconds)\n")
3476 : {
3477 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3478 :
3479 0 : bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3480 : /* Send the stale timer update message to RIB */
3481 0 : if (bgp_zebra_stale_timer_update(bgp))
3482 : return CMD_WARNING;
3483 :
3484 : return CMD_SUCCESS;
3485 : }
3486 :
3487 0 : DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3488 : "bgp long-lived-graceful-restart stale-time (1-16777215)",
3489 : BGP_STR
3490 : "Enable Long-lived Graceful Restart\n"
3491 : "Specifies maximum time to wait before purging long-lived stale routes\n"
3492 : "Stale time value (seconds)\n")
3493 : {
3494 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3495 :
3496 0 : uint32_t llgr_stale_time;
3497 :
3498 0 : llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3499 0 : bgp->llgr_stale_time = llgr_stale_time;
3500 :
3501 0 : return CMD_SUCCESS;
3502 : }
3503 :
3504 0 : DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3505 : "no bgp long-lived-graceful-restart stale-time [(1-16777215)]",
3506 : NO_STR BGP_STR
3507 : "Enable Long-lived Graceful Restart\n"
3508 : "Specifies maximum time to wait before purging long-lived stale routes\n"
3509 : "Stale time value (seconds)\n")
3510 : {
3511 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3512 :
3513 0 : bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3514 :
3515 0 : return CMD_SUCCESS;
3516 : }
3517 :
3518 0 : static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3519 : struct bgp *bgp)
3520 : {
3521 0 : bgp_static_redo_import_check(bgp);
3522 0 : bgp_redistribute_redo(bgp);
3523 0 : bgp_clear_star_soft_out(vty, bgp->name);
3524 0 : bgp_clear_star_soft_in(vty, bgp->name);
3525 0 : }
3526 :
3527 0 : static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3528 : {
3529 0 : struct listnode *node, *nnode;
3530 0 : struct bgp *bgp;
3531 0 : bool vrf_cfg = false;
3532 :
3533 0 : if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3534 : return CMD_SUCCESS;
3535 :
3536 : /* See if graceful-shutdown is set per-vrf and warn user to delete */
3537 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3538 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3539 0 : vty_out(vty,
3540 : "%% graceful-shutdown configuration found in vrf %s\n",
3541 0 : bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3542 0 : VRF_DEFAULT_NAME : bgp->name);
3543 0 : vrf_cfg = true;
3544 : }
3545 : }
3546 :
3547 0 : if (vrf_cfg) {
3548 0 : vty_out(vty,
3549 : "%%Failed: global graceful-shutdown not permitted\n");
3550 0 : return CMD_WARNING;
3551 : }
3552 :
3553 : /* Set flag globally */
3554 0 : SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3555 :
3556 : /* Initiate processing for all BGP instances. */
3557 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3558 0 : bgp_initiate_graceful_shut_unshut(vty, bgp);
3559 :
3560 : return CMD_SUCCESS;
3561 : }
3562 :
3563 0 : static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3564 : {
3565 0 : struct listnode *node, *nnode;
3566 0 : struct bgp *bgp;
3567 :
3568 0 : if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3569 : return CMD_SUCCESS;
3570 :
3571 : /* Unset flag globally */
3572 0 : UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3573 :
3574 : /* Initiate processing for all BGP instances. */
3575 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3576 0 : bgp_initiate_graceful_shut_unshut(vty, bgp);
3577 :
3578 : return CMD_SUCCESS;
3579 : }
3580 :
3581 : /* "bgp graceful-shutdown" configuration */
3582 0 : DEFUN (bgp_graceful_shutdown,
3583 : bgp_graceful_shutdown_cmd,
3584 : "bgp graceful-shutdown",
3585 : BGP_STR
3586 : "Graceful shutdown parameters\n")
3587 : {
3588 0 : if (vty->node == CONFIG_NODE)
3589 0 : return bgp_global_graceful_shutdown_config_vty(vty);
3590 :
3591 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3592 :
3593 : /* if configured globally, per-instance config is not allowed */
3594 0 : if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3595 0 : vty_out(vty,
3596 : "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3597 0 : return CMD_WARNING_CONFIG_FAILED;
3598 : }
3599 :
3600 0 : if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3601 0 : SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3602 0 : bgp_initiate_graceful_shut_unshut(vty, bgp);
3603 : }
3604 :
3605 : return CMD_SUCCESS;
3606 : }
3607 :
3608 0 : DEFUN (no_bgp_graceful_shutdown,
3609 : no_bgp_graceful_shutdown_cmd,
3610 : "no bgp graceful-shutdown",
3611 : NO_STR
3612 : BGP_STR
3613 : "Graceful shutdown parameters\n")
3614 : {
3615 0 : if (vty->node == CONFIG_NODE)
3616 0 : return bgp_global_graceful_shutdown_deconfig_vty(vty);
3617 :
3618 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3619 :
3620 : /* If configured globally, cannot remove from one bgp instance */
3621 0 : if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3622 0 : vty_out(vty,
3623 : "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3624 0 : return CMD_WARNING_CONFIG_FAILED;
3625 : }
3626 :
3627 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3628 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3629 0 : bgp_initiate_graceful_shut_unshut(vty, bgp);
3630 : }
3631 :
3632 : return CMD_SUCCESS;
3633 : }
3634 :
3635 : /* "bgp fast-external-failover" configuration. */
3636 0 : DEFUN (bgp_fast_external_failover,
3637 : bgp_fast_external_failover_cmd,
3638 : "bgp fast-external-failover",
3639 : BGP_STR
3640 : "Immediately reset session if a link to a directly connected external peer goes down\n")
3641 : {
3642 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3643 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3644 0 : return CMD_SUCCESS;
3645 : }
3646 :
3647 0 : DEFUN (no_bgp_fast_external_failover,
3648 : no_bgp_fast_external_failover_cmd,
3649 : "no bgp fast-external-failover",
3650 : NO_STR
3651 : BGP_STR
3652 : "Immediately reset session if a link to a directly connected external peer goes down\n")
3653 : {
3654 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3655 0 : SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3656 0 : return CMD_SUCCESS;
3657 : }
3658 :
3659 0 : DEFPY (bgp_bestpath_aigp,
3660 : bgp_bestpath_aigp_cmd,
3661 : "[no$no] bgp bestpath aigp",
3662 : NO_STR
3663 : BGP_STR
3664 : "Change the default bestpath selection\n"
3665 : "Evaluate the AIGP attribute during the best path selection process\n")
3666 : {
3667 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3668 :
3669 0 : if (no)
3670 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3671 : else
3672 0 : SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP);
3673 :
3674 0 : bgp_recalculate_all_bestpaths(bgp);
3675 :
3676 0 : return CMD_SUCCESS;
3677 : }
3678 :
3679 : /* "bgp bestpath compare-routerid" configuration. */
3680 0 : DEFUN (bgp_bestpath_compare_router_id,
3681 : bgp_bestpath_compare_router_id_cmd,
3682 : "bgp bestpath compare-routerid",
3683 : BGP_STR
3684 : "Change the default bestpath selection\n"
3685 : "Compare router-id for identical EBGP paths\n")
3686 : {
3687 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3688 0 : SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3689 0 : bgp_recalculate_all_bestpaths(bgp);
3690 :
3691 0 : return CMD_SUCCESS;
3692 : }
3693 :
3694 0 : DEFUN (no_bgp_bestpath_compare_router_id,
3695 : no_bgp_bestpath_compare_router_id_cmd,
3696 : "no bgp bestpath compare-routerid",
3697 : NO_STR
3698 : BGP_STR
3699 : "Change the default bestpath selection\n"
3700 : "Compare router-id for identical EBGP paths\n")
3701 : {
3702 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3703 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3704 0 : bgp_recalculate_all_bestpaths(bgp);
3705 :
3706 0 : return CMD_SUCCESS;
3707 : }
3708 :
3709 : /* "bgp bestpath as-path ignore" configuration. */
3710 0 : DEFUN (bgp_bestpath_aspath_ignore,
3711 : bgp_bestpath_aspath_ignore_cmd,
3712 : "bgp bestpath as-path ignore",
3713 : BGP_STR
3714 : "Change the default bestpath selection\n"
3715 : "AS-path attribute\n"
3716 : "Ignore as-path length in selecting a route\n")
3717 : {
3718 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3719 0 : SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3720 0 : bgp_recalculate_all_bestpaths(bgp);
3721 :
3722 0 : return CMD_SUCCESS;
3723 : }
3724 :
3725 0 : DEFUN (no_bgp_bestpath_aspath_ignore,
3726 : no_bgp_bestpath_aspath_ignore_cmd,
3727 : "no bgp bestpath as-path ignore",
3728 : NO_STR
3729 : BGP_STR
3730 : "Change the default bestpath selection\n"
3731 : "AS-path attribute\n"
3732 : "Ignore as-path length in selecting a route\n")
3733 : {
3734 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3735 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3736 0 : bgp_recalculate_all_bestpaths(bgp);
3737 :
3738 0 : return CMD_SUCCESS;
3739 : }
3740 :
3741 : /* "bgp bestpath as-path confed" configuration. */
3742 0 : DEFUN (bgp_bestpath_aspath_confed,
3743 : bgp_bestpath_aspath_confed_cmd,
3744 : "bgp bestpath as-path confed",
3745 : BGP_STR
3746 : "Change the default bestpath selection\n"
3747 : "AS-path attribute\n"
3748 : "Compare path lengths including confederation sets & sequences in selecting a route\n")
3749 : {
3750 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3751 0 : SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3752 0 : bgp_recalculate_all_bestpaths(bgp);
3753 :
3754 0 : return CMD_SUCCESS;
3755 : }
3756 :
3757 0 : DEFUN (no_bgp_bestpath_aspath_confed,
3758 : no_bgp_bestpath_aspath_confed_cmd,
3759 : "no bgp bestpath as-path confed",
3760 : NO_STR
3761 : BGP_STR
3762 : "Change the default bestpath selection\n"
3763 : "AS-path attribute\n"
3764 : "Compare path lengths including confederation sets & sequences in selecting a route\n")
3765 : {
3766 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3767 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3768 0 : bgp_recalculate_all_bestpaths(bgp);
3769 :
3770 0 : return CMD_SUCCESS;
3771 : }
3772 :
3773 : /* "bgp bestpath as-path multipath-relax" configuration. */
3774 0 : DEFUN (bgp_bestpath_aspath_multipath_relax,
3775 : bgp_bestpath_aspath_multipath_relax_cmd,
3776 : "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3777 : BGP_STR
3778 : "Change the default bestpath selection\n"
3779 : "AS-path attribute\n"
3780 : "Allow load sharing across routes that have different AS paths (but same length)\n"
3781 : "Generate an AS_SET\n"
3782 : "Do not generate an AS_SET\n")
3783 : {
3784 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3785 0 : int idx = 0;
3786 0 : SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3787 :
3788 : /* no-as-set is now the default behavior so we can silently
3789 : * ignore it */
3790 0 : if (argv_find(argv, argc, "as-set", &idx))
3791 0 : SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3792 : else
3793 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3794 :
3795 0 : bgp_recalculate_all_bestpaths(bgp);
3796 :
3797 0 : return CMD_SUCCESS;
3798 : }
3799 :
3800 0 : DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3801 : no_bgp_bestpath_aspath_multipath_relax_cmd,
3802 : "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3803 : NO_STR
3804 : BGP_STR
3805 : "Change the default bestpath selection\n"
3806 : "AS-path attribute\n"
3807 : "Allow load sharing across routes that have different AS paths (but same length)\n"
3808 : "Generate an AS_SET\n"
3809 : "Do not generate an AS_SET\n")
3810 : {
3811 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3812 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3813 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3814 0 : bgp_recalculate_all_bestpaths(bgp);
3815 :
3816 0 : return CMD_SUCCESS;
3817 : }
3818 :
3819 : /* "bgp bestpath peer-type multipath-relax" configuration. */
3820 0 : DEFUN(bgp_bestpath_peer_type_multipath_relax,
3821 : bgp_bestpath_peer_type_multipath_relax_cmd,
3822 : "bgp bestpath peer-type multipath-relax",
3823 : BGP_STR
3824 : "Change the default bestpath selection\n"
3825 : "Peer type\n"
3826 : "Allow load sharing across routes learned from different peer types\n")
3827 : {
3828 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3829 0 : SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3830 0 : bgp_recalculate_all_bestpaths(bgp);
3831 :
3832 0 : return CMD_SUCCESS;
3833 : }
3834 :
3835 0 : DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3836 : no_bgp_bestpath_peer_type_multipath_relax_cmd,
3837 : "no bgp bestpath peer-type multipath-relax",
3838 : NO_STR BGP_STR
3839 : "Change the default bestpath selection\n"
3840 : "Peer type\n"
3841 : "Allow load sharing across routes learned from different peer types\n")
3842 : {
3843 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3844 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3845 0 : bgp_recalculate_all_bestpaths(bgp);
3846 :
3847 0 : return CMD_SUCCESS;
3848 : }
3849 :
3850 : /* "bgp log-neighbor-changes" configuration. */
3851 0 : DEFUN (bgp_log_neighbor_changes,
3852 : bgp_log_neighbor_changes_cmd,
3853 : "bgp log-neighbor-changes",
3854 : BGP_STR
3855 : "Log neighbor up/down and reset reason\n")
3856 : {
3857 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3858 0 : SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3859 0 : return CMD_SUCCESS;
3860 : }
3861 :
3862 0 : DEFUN (no_bgp_log_neighbor_changes,
3863 : no_bgp_log_neighbor_changes_cmd,
3864 : "no bgp log-neighbor-changes",
3865 : NO_STR
3866 : BGP_STR
3867 : "Log neighbor up/down and reset reason\n")
3868 : {
3869 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3870 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3871 0 : return CMD_SUCCESS;
3872 : }
3873 :
3874 : /* "bgp bestpath med" configuration. */
3875 0 : DEFUN (bgp_bestpath_med,
3876 : bgp_bestpath_med_cmd,
3877 : "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3878 : BGP_STR
3879 : "Change the default bestpath selection\n"
3880 : "MED attribute\n"
3881 : "Compare MED among confederation paths\n"
3882 : "Treat missing MED as the least preferred one\n"
3883 : "Treat missing MED as the least preferred one\n"
3884 : "Compare MED among confederation paths\n")
3885 : {
3886 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3887 :
3888 0 : int idx = 0;
3889 0 : if (argv_find(argv, argc, "confed", &idx))
3890 0 : SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3891 0 : idx = 0;
3892 0 : if (argv_find(argv, argc, "missing-as-worst", &idx))
3893 0 : SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3894 :
3895 0 : bgp_recalculate_all_bestpaths(bgp);
3896 :
3897 0 : return CMD_SUCCESS;
3898 : }
3899 :
3900 0 : DEFUN (no_bgp_bestpath_med,
3901 : no_bgp_bestpath_med_cmd,
3902 : "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3903 : NO_STR
3904 : BGP_STR
3905 : "Change the default bestpath selection\n"
3906 : "MED attribute\n"
3907 : "Compare MED among confederation paths\n"
3908 : "Treat missing MED as the least preferred one\n"
3909 : "Treat missing MED as the least preferred one\n"
3910 : "Compare MED among confederation paths\n")
3911 : {
3912 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3913 :
3914 0 : int idx = 0;
3915 0 : if (argv_find(argv, argc, "confed", &idx))
3916 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3917 0 : idx = 0;
3918 0 : if (argv_find(argv, argc, "missing-as-worst", &idx))
3919 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3920 :
3921 0 : bgp_recalculate_all_bestpaths(bgp);
3922 :
3923 0 : return CMD_SUCCESS;
3924 : }
3925 :
3926 : /* "bgp bestpath bandwidth" configuration. */
3927 0 : DEFPY (bgp_bestpath_bw,
3928 : bgp_bestpath_bw_cmd,
3929 : "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3930 : BGP_STR
3931 : "Change the default bestpath selection\n"
3932 : "Link Bandwidth attribute\n"
3933 : "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3934 : "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3935 : "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3936 : {
3937 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3938 0 : afi_t afi;
3939 0 : safi_t safi;
3940 :
3941 0 : if (!bw_cfg) {
3942 0 : vty_out(vty, "%% Bandwidth configuration must be specified\n");
3943 0 : return CMD_ERR_INCOMPLETE;
3944 : }
3945 0 : if (!strcmp(bw_cfg, "ignore"))
3946 0 : bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3947 0 : else if (!strcmp(bw_cfg, "skip-missing"))
3948 0 : bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3949 0 : else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3950 0 : bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3951 : else
3952 : return CMD_ERR_NO_MATCH;
3953 :
3954 : /* This config is used in route install, so redo that. */
3955 0 : FOREACH_AFI_SAFI (afi, safi) {
3956 0 : if (!bgp_fibupd_safi(safi))
3957 0 : continue;
3958 0 : bgp_zebra_announce_table(bgp, afi, safi);
3959 : }
3960 :
3961 : return CMD_SUCCESS;
3962 : }
3963 :
3964 0 : DEFPY (no_bgp_bestpath_bw,
3965 : no_bgp_bestpath_bw_cmd,
3966 : "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3967 : NO_STR
3968 : BGP_STR
3969 : "Change the default bestpath selection\n"
3970 : "Link Bandwidth attribute\n"
3971 : "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3972 : "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3973 : "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3974 : {
3975 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
3976 0 : afi_t afi;
3977 0 : safi_t safi;
3978 :
3979 0 : bgp->lb_handling = BGP_LINK_BW_ECMP;
3980 :
3981 : /* This config is used in route install, so redo that. */
3982 0 : FOREACH_AFI_SAFI (afi, safi) {
3983 0 : if (!bgp_fibupd_safi(safi))
3984 0 : continue;
3985 0 : bgp_zebra_announce_table(bgp, afi, safi);
3986 : }
3987 : return CMD_SUCCESS;
3988 : }
3989 :
3990 0 : DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3991 : "[no] bgp default <ipv4-unicast|"
3992 : "ipv4-multicast|"
3993 : "ipv4-vpn|"
3994 : "ipv4-labeled-unicast|"
3995 : "ipv4-flowspec|"
3996 : "ipv6-unicast|"
3997 : "ipv6-multicast|"
3998 : "ipv6-vpn|"
3999 : "ipv6-labeled-unicast|"
4000 : "ipv6-flowspec|"
4001 : "l2vpn-evpn>$afi_safi",
4002 : NO_STR
4003 : BGP_STR
4004 : "Configure BGP defaults\n"
4005 : "Activate ipv4-unicast for a peer by default\n"
4006 : "Activate ipv4-multicast for a peer by default\n"
4007 : "Activate ipv4-vpn for a peer by default\n"
4008 : "Activate ipv4-labeled-unicast for a peer by default\n"
4009 : "Activate ipv4-flowspec for a peer by default\n"
4010 : "Activate ipv6-unicast for a peer by default\n"
4011 : "Activate ipv6-multicast for a peer by default\n"
4012 : "Activate ipv6-vpn for a peer by default\n"
4013 : "Activate ipv6-labeled-unicast for a peer by default\n"
4014 : "Activate ipv6-flowspec for a peer by default\n"
4015 : "Activate l2vpn-evpn for a peer by default\n")
4016 0 : {
4017 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4018 0 : char afi_safi_str[strlen(afi_safi) + 1];
4019 0 : char *afi_safi_str_tok;
4020 :
4021 0 : strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
4022 0 : char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
4023 0 : char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
4024 0 : afi_t afi = bgp_vty_afi_from_str(afi_str);
4025 0 : safi_t safi;
4026 :
4027 : /*
4028 : * Impossible situation but making coverity happy
4029 : */
4030 0 : assert(afi != AFI_MAX);
4031 :
4032 0 : if (strmatch(safi_str, "labeled"))
4033 0 : safi = bgp_vty_safi_from_str("labeled-unicast");
4034 : else
4035 0 : safi = bgp_vty_safi_from_str(safi_str);
4036 :
4037 0 : assert(safi != SAFI_MAX);
4038 0 : if (no)
4039 0 : bgp->default_af[afi][safi] = false;
4040 : else {
4041 0 : if ((safi == SAFI_LABELED_UNICAST
4042 0 : && bgp->default_af[afi][SAFI_UNICAST])
4043 0 : || (safi == SAFI_UNICAST
4044 0 : && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
4045 0 : bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
4046 : else
4047 0 : bgp->default_af[afi][safi] = true;
4048 : }
4049 :
4050 : return CMD_SUCCESS;
4051 : }
4052 :
4053 : /* Display hostname in certain command outputs */
4054 0 : DEFUN (bgp_default_show_hostname,
4055 : bgp_default_show_hostname_cmd,
4056 : "bgp default show-hostname",
4057 : BGP_STR
4058 : "Configure BGP defaults\n"
4059 : "Show hostname in certain command outputs\n")
4060 : {
4061 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4062 0 : SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4063 0 : return CMD_SUCCESS;
4064 : }
4065 :
4066 0 : DEFUN (no_bgp_default_show_hostname,
4067 : no_bgp_default_show_hostname_cmd,
4068 : "no bgp default show-hostname",
4069 : NO_STR
4070 : BGP_STR
4071 : "Configure BGP defaults\n"
4072 : "Show hostname in certain command outputs\n")
4073 : {
4074 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4075 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
4076 0 : return CMD_SUCCESS;
4077 : }
4078 :
4079 : /* Display hostname in certain command outputs */
4080 0 : DEFUN (bgp_default_show_nexthop_hostname,
4081 : bgp_default_show_nexthop_hostname_cmd,
4082 : "bgp default show-nexthop-hostname",
4083 : BGP_STR
4084 : "Configure BGP defaults\n"
4085 : "Show hostname for nexthop in certain command outputs\n")
4086 : {
4087 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4088 0 : SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4089 0 : return CMD_SUCCESS;
4090 : }
4091 :
4092 0 : DEFUN (no_bgp_default_show_nexthop_hostname,
4093 : no_bgp_default_show_nexthop_hostname_cmd,
4094 : "no bgp default show-nexthop-hostname",
4095 : NO_STR
4096 : BGP_STR
4097 : "Configure BGP defaults\n"
4098 : "Show hostname for nexthop in certain command outputs\n")
4099 : {
4100 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4101 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
4102 0 : return CMD_SUCCESS;
4103 : }
4104 :
4105 : /* "bgp network import-check" configuration. */
4106 0 : DEFUN (bgp_network_import_check,
4107 : bgp_network_import_check_cmd,
4108 : "bgp network import-check",
4109 : BGP_STR
4110 : "BGP network command\n"
4111 : "Check BGP network route exists in IGP\n")
4112 : {
4113 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4114 0 : if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4115 0 : SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4116 0 : bgp_static_redo_import_check(bgp);
4117 : }
4118 :
4119 : return CMD_SUCCESS;
4120 : }
4121 :
4122 : ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
4123 : "bgp network import-check exact",
4124 : BGP_STR
4125 : "BGP network command\n"
4126 : "Check BGP network route exists in IGP\n"
4127 : "Match route precisely\n")
4128 :
4129 0 : DEFUN (no_bgp_network_import_check,
4130 : no_bgp_network_import_check_cmd,
4131 : "no bgp network import-check",
4132 : NO_STR
4133 : BGP_STR
4134 : "BGP network command\n"
4135 : "Check BGP network route exists in IGP\n")
4136 : {
4137 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4138 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
4139 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
4140 0 : bgp_static_redo_import_check(bgp);
4141 : }
4142 :
4143 : return CMD_SUCCESS;
4144 : }
4145 :
4146 0 : DEFUN (bgp_default_local_preference,
4147 : bgp_default_local_preference_cmd,
4148 : "bgp default local-preference (0-4294967295)",
4149 : BGP_STR
4150 : "Configure BGP defaults\n"
4151 : "local preference (higher=more preferred)\n"
4152 : "Configure default local preference value\n")
4153 : {
4154 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4155 0 : int idx_number = 3;
4156 0 : uint32_t local_pref;
4157 :
4158 0 : local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
4159 :
4160 0 : bgp_default_local_preference_set(bgp, local_pref);
4161 0 : bgp_clear_star_soft_in(vty, bgp->name);
4162 :
4163 0 : return CMD_SUCCESS;
4164 : }
4165 :
4166 0 : DEFUN (no_bgp_default_local_preference,
4167 : no_bgp_default_local_preference_cmd,
4168 : "no bgp default local-preference [(0-4294967295)]",
4169 : NO_STR
4170 : BGP_STR
4171 : "Configure BGP defaults\n"
4172 : "local preference (higher=more preferred)\n"
4173 : "Configure default local preference value\n")
4174 : {
4175 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4176 0 : bgp_default_local_preference_unset(bgp);
4177 0 : bgp_clear_star_soft_in(vty, bgp->name);
4178 :
4179 0 : return CMD_SUCCESS;
4180 : }
4181 :
4182 :
4183 0 : DEFUN (bgp_default_subgroup_pkt_queue_max,
4184 : bgp_default_subgroup_pkt_queue_max_cmd,
4185 : "bgp default subgroup-pkt-queue-max (20-100)",
4186 : BGP_STR
4187 : "Configure BGP defaults\n"
4188 : "subgroup-pkt-queue-max\n"
4189 : "Configure subgroup packet queue max\n")
4190 : {
4191 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4192 0 : int idx_number = 3;
4193 0 : uint32_t max_size;
4194 :
4195 0 : max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4196 :
4197 0 : bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4198 :
4199 0 : return CMD_SUCCESS;
4200 : }
4201 :
4202 0 : DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4203 : no_bgp_default_subgroup_pkt_queue_max_cmd,
4204 : "no bgp default subgroup-pkt-queue-max [(20-100)]",
4205 : NO_STR
4206 : BGP_STR
4207 : "Configure BGP defaults\n"
4208 : "subgroup-pkt-queue-max\n"
4209 : "Configure subgroup packet queue max\n")
4210 : {
4211 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4212 0 : bgp_default_subgroup_pkt_queue_max_unset(bgp);
4213 0 : return CMD_SUCCESS;
4214 : }
4215 :
4216 :
4217 0 : DEFUN (bgp_rr_allow_outbound_policy,
4218 : bgp_rr_allow_outbound_policy_cmd,
4219 : "bgp route-reflector allow-outbound-policy",
4220 : BGP_STR
4221 : "Allow modifications made by out route-map\n"
4222 : "on ibgp neighbors\n")
4223 : {
4224 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4225 :
4226 0 : if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4227 0 : SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4228 0 : update_group_announce_rrclients(bgp);
4229 0 : bgp_clear_star_soft_out(vty, bgp->name);
4230 : }
4231 :
4232 : return CMD_SUCCESS;
4233 : }
4234 :
4235 0 : DEFUN (no_bgp_rr_allow_outbound_policy,
4236 : no_bgp_rr_allow_outbound_policy_cmd,
4237 : "no bgp route-reflector allow-outbound-policy",
4238 : NO_STR
4239 : BGP_STR
4240 : "Allow modifications made by out route-map\n"
4241 : "on ibgp neighbors\n")
4242 : {
4243 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4244 :
4245 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4246 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4247 0 : update_group_announce_rrclients(bgp);
4248 0 : bgp_clear_star_soft_out(vty, bgp->name);
4249 : }
4250 :
4251 : return CMD_SUCCESS;
4252 : }
4253 :
4254 0 : DEFUN (bgp_listen_limit,
4255 : bgp_listen_limit_cmd,
4256 : "bgp listen limit (1-65535)",
4257 : BGP_STR
4258 : "BGP Dynamic Neighbors listen commands\n"
4259 : "Maximum number of BGP Dynamic Neighbors that can be created\n"
4260 : "Configure Dynamic Neighbors listen limit value\n")
4261 : {
4262 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4263 0 : int idx_number = 3;
4264 0 : int listen_limit;
4265 :
4266 0 : listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4267 :
4268 0 : bgp_listen_limit_set(bgp, listen_limit);
4269 :
4270 0 : return CMD_SUCCESS;
4271 : }
4272 :
4273 0 : DEFUN (no_bgp_listen_limit,
4274 : no_bgp_listen_limit_cmd,
4275 : "no bgp listen limit [(1-65535)]",
4276 : NO_STR
4277 : BGP_STR
4278 : "BGP Dynamic Neighbors listen commands\n"
4279 : "Maximum number of BGP Dynamic Neighbors that can be created\n"
4280 : "Configure Dynamic Neighbors listen limit value\n")
4281 : {
4282 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4283 0 : bgp_listen_limit_unset(bgp);
4284 0 : return CMD_SUCCESS;
4285 : }
4286 :
4287 :
4288 : /*
4289 : * Check if this listen range is already configured. Check for exact
4290 : * match or overlap based on input.
4291 : */
4292 0 : static struct peer_group *listen_range_exists(struct bgp *bgp,
4293 : struct prefix *range, int exact)
4294 : {
4295 0 : struct listnode *node, *nnode;
4296 0 : struct listnode *node1, *nnode1;
4297 0 : struct peer_group *group;
4298 0 : struct prefix *lr;
4299 0 : afi_t afi;
4300 0 : int match;
4301 :
4302 0 : afi = family2afi(range->family);
4303 0 : for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4304 0 : for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4305 : lr)) {
4306 0 : if (exact)
4307 0 : match = prefix_same(range, lr);
4308 : else
4309 0 : match = (prefix_match(range, lr)
4310 0 : || prefix_match(lr, range));
4311 0 : if (match)
4312 0 : return group;
4313 : }
4314 : }
4315 :
4316 : return NULL;
4317 : }
4318 :
4319 0 : DEFUN (bgp_listen_range,
4320 : bgp_listen_range_cmd,
4321 : "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4322 : BGP_STR
4323 : "Configure BGP dynamic neighbors listen range\n"
4324 : "Configure BGP dynamic neighbors listen range\n"
4325 : NEIGHBOR_ADDR_STR
4326 : "Member of the peer-group\n"
4327 : "Peer-group name\n")
4328 : {
4329 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4330 0 : struct prefix range;
4331 0 : struct peer_group *group, *existing_group;
4332 0 : afi_t afi;
4333 0 : int ret;
4334 0 : int idx = 0;
4335 :
4336 0 : argv_find(argv, argc, "A.B.C.D/M", &idx);
4337 0 : argv_find(argv, argc, "X:X::X:X/M", &idx);
4338 0 : char *prefix = argv[idx]->arg;
4339 0 : argv_find(argv, argc, "PGNAME", &idx);
4340 0 : char *peergroup = argv[idx]->arg;
4341 :
4342 : /* Convert IP prefix string to struct prefix. */
4343 0 : ret = str2prefix(prefix, &range);
4344 0 : if (!ret) {
4345 0 : vty_out(vty, "%% Malformed listen range\n");
4346 0 : return CMD_WARNING_CONFIG_FAILED;
4347 : }
4348 :
4349 0 : afi = family2afi(range.family);
4350 :
4351 0 : if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4352 0 : vty_out(vty,
4353 : "%% Malformed listen range (link-local address)\n");
4354 0 : return CMD_WARNING_CONFIG_FAILED;
4355 : }
4356 :
4357 0 : apply_mask(&range);
4358 :
4359 : /* Check if same listen range is already configured. */
4360 0 : existing_group = listen_range_exists(bgp, &range, 1);
4361 0 : if (existing_group) {
4362 0 : if (strcmp(existing_group->name, peergroup) == 0)
4363 : return CMD_SUCCESS;
4364 : else {
4365 0 : vty_out(vty,
4366 : "%% Same listen range is attached to peer-group %s\n",
4367 : existing_group->name);
4368 0 : return CMD_WARNING_CONFIG_FAILED;
4369 : }
4370 : }
4371 :
4372 : /* Check if an overlapping listen range exists. */
4373 0 : if (listen_range_exists(bgp, &range, 0)) {
4374 0 : vty_out(vty,
4375 : "%% Listen range overlaps with existing listen range\n");
4376 0 : return CMD_WARNING_CONFIG_FAILED;
4377 : }
4378 :
4379 0 : group = peer_group_lookup(bgp, peergroup);
4380 0 : if (!group) {
4381 0 : vty_out(vty, "%% Configure the peer-group first\n");
4382 0 : return CMD_WARNING_CONFIG_FAILED;
4383 : }
4384 :
4385 0 : ret = peer_group_listen_range_add(group, &range);
4386 0 : return bgp_vty_return(vty, ret);
4387 : }
4388 :
4389 0 : DEFUN (no_bgp_listen_range,
4390 : no_bgp_listen_range_cmd,
4391 : "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4392 : NO_STR
4393 : BGP_STR
4394 : "Unconfigure BGP dynamic neighbors listen range\n"
4395 : "Unconfigure BGP dynamic neighbors listen range\n"
4396 : NEIGHBOR_ADDR_STR
4397 : "Member of the peer-group\n"
4398 : "Peer-group name\n")
4399 : {
4400 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4401 0 : struct prefix range;
4402 0 : struct peer_group *group;
4403 0 : afi_t afi;
4404 0 : int ret;
4405 0 : int idx = 0;
4406 :
4407 0 : argv_find(argv, argc, "A.B.C.D/M", &idx);
4408 0 : argv_find(argv, argc, "X:X::X:X/M", &idx);
4409 0 : char *prefix = argv[idx]->arg;
4410 0 : argv_find(argv, argc, "PGNAME", &idx);
4411 0 : char *peergroup = argv[idx]->arg;
4412 :
4413 : /* Convert IP prefix string to struct prefix. */
4414 0 : ret = str2prefix(prefix, &range);
4415 0 : if (!ret) {
4416 0 : vty_out(vty, "%% Malformed listen range\n");
4417 0 : return CMD_WARNING_CONFIG_FAILED;
4418 : }
4419 :
4420 0 : afi = family2afi(range.family);
4421 :
4422 0 : if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4423 0 : vty_out(vty,
4424 : "%% Malformed listen range (link-local address)\n");
4425 0 : return CMD_WARNING_CONFIG_FAILED;
4426 : }
4427 :
4428 0 : apply_mask(&range);
4429 :
4430 0 : group = peer_group_lookup(bgp, peergroup);
4431 0 : if (!group) {
4432 0 : vty_out(vty, "%% Peer-group does not exist\n");
4433 0 : return CMD_WARNING_CONFIG_FAILED;
4434 : }
4435 :
4436 0 : ret = peer_group_listen_range_del(group, &range);
4437 0 : return bgp_vty_return(vty, ret);
4438 : }
4439 :
4440 0 : void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4441 : {
4442 0 : struct peer_group *group;
4443 0 : struct listnode *node, *nnode, *rnode, *nrnode;
4444 0 : struct prefix *range;
4445 0 : afi_t afi;
4446 :
4447 0 : if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4448 0 : vty_out(vty, " bgp listen limit %d\n",
4449 : bgp->dynamic_neighbors_limit);
4450 :
4451 0 : for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4452 0 : for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4453 0 : for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4454 : nrnode, range)) {
4455 0 : vty_out(vty,
4456 : " bgp listen range %pFX peer-group %s\n",
4457 : range, group->name);
4458 : }
4459 : }
4460 : }
4461 0 : }
4462 :
4463 :
4464 0 : DEFUN (bgp_disable_connected_route_check,
4465 : bgp_disable_connected_route_check_cmd,
4466 : "bgp disable-ebgp-connected-route-check",
4467 : BGP_STR
4468 : "Disable checking if nexthop is connected on ebgp sessions\n")
4469 : {
4470 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4471 0 : SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4472 0 : bgp_clear_star_soft_in(vty, bgp->name);
4473 :
4474 0 : return CMD_SUCCESS;
4475 : }
4476 :
4477 0 : DEFUN (no_bgp_disable_connected_route_check,
4478 : no_bgp_disable_connected_route_check_cmd,
4479 : "no bgp disable-ebgp-connected-route-check",
4480 : NO_STR
4481 : BGP_STR
4482 : "Disable checking if nexthop is connected on ebgp sessions\n")
4483 : {
4484 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4485 0 : UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4486 0 : bgp_clear_star_soft_in(vty, bgp->name);
4487 :
4488 0 : return CMD_SUCCESS;
4489 : }
4490 :
4491 :
4492 2 : static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4493 : const char *as_str)
4494 : {
4495 2 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4496 2 : int ret;
4497 2 : as_t as;
4498 2 : int as_type = AS_SPECIFIED;
4499 2 : union sockunion su;
4500 :
4501 2 : if (as_str[0] == 'i') {
4502 0 : as = 0;
4503 0 : as_type = AS_INTERNAL;
4504 2 : } else if (as_str[0] == 'e') {
4505 0 : as = 0;
4506 0 : as_type = AS_EXTERNAL;
4507 : } else {
4508 : /* Get AS number. */
4509 2 : as = strtoul(as_str, NULL, 10);
4510 : }
4511 :
4512 : /* If peer is peer group or interface peer, call proper function. */
4513 2 : ret = str2sockunion(peer_str, &su);
4514 2 : if (ret < 0) {
4515 0 : struct peer *peer;
4516 :
4517 : /* Check if existing interface peer */
4518 0 : peer = peer_lookup_by_conf_if(bgp, peer_str);
4519 :
4520 0 : ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4521 :
4522 : /* if not interface peer, check peer-group settings */
4523 0 : if (ret < 0 && !peer) {
4524 0 : ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4525 0 : if (ret < 0) {
4526 0 : vty_out(vty,
4527 : "%% Create the peer-group or interface first\n");
4528 0 : return CMD_WARNING_CONFIG_FAILED;
4529 : }
4530 : return CMD_SUCCESS;
4531 : }
4532 : } else {
4533 2 : if (peer_address_self_check(bgp, &su)) {
4534 0 : vty_out(vty,
4535 : "%% Can not configure the local system as neighbor\n");
4536 0 : return CMD_WARNING_CONFIG_FAILED;
4537 : }
4538 2 : ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4539 : }
4540 :
4541 2 : return bgp_vty_return(vty, ret);
4542 : }
4543 :
4544 0 : DEFUN (bgp_default_shutdown,
4545 : bgp_default_shutdown_cmd,
4546 : "[no] bgp default shutdown",
4547 : NO_STR
4548 : BGP_STR
4549 : "Configure BGP defaults\n"
4550 : "Apply administrative shutdown to newly configured peers\n")
4551 : {
4552 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4553 0 : bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4554 0 : return CMD_SUCCESS;
4555 : }
4556 :
4557 0 : DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4558 : BGP_STR
4559 : "Administrative shutdown of the BGP instance\n"
4560 : "Add a shutdown message (RFC 8203)\n"
4561 : "Shutdown message\n")
4562 : {
4563 0 : char *msgstr = NULL;
4564 :
4565 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4566 :
4567 0 : if (argc > 3)
4568 0 : msgstr = argv_concat(argv, argc, 3);
4569 :
4570 0 : if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4571 0 : vty_out(vty, "%% Shutdown message size exceeded %d\n",
4572 : BGP_ADMIN_SHUTDOWN_MSG_LEN);
4573 0 : return CMD_WARNING_CONFIG_FAILED;
4574 : }
4575 :
4576 0 : bgp_shutdown_enable(bgp, msgstr);
4577 0 : XFREE(MTYPE_TMP, msgstr);
4578 :
4579 0 : return CMD_SUCCESS;
4580 : }
4581 :
4582 0 : DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4583 : BGP_STR "Administrative shutdown of the BGP instance\n")
4584 : {
4585 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4586 :
4587 0 : bgp_shutdown_enable(bgp, NULL);
4588 :
4589 0 : return CMD_SUCCESS;
4590 : }
4591 :
4592 0 : DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4593 : NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4594 : {
4595 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4596 :
4597 0 : bgp_shutdown_disable(bgp);
4598 :
4599 0 : return CMD_SUCCESS;
4600 : }
4601 :
4602 : ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4603 : "no bgp shutdown message MSG...", NO_STR BGP_STR
4604 : "Administrative shutdown of the BGP instance\n"
4605 : "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4606 :
4607 2 : DEFUN (neighbor_remote_as,
4608 : neighbor_remote_as_cmd,
4609 : "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4610 : NEIGHBOR_STR
4611 : NEIGHBOR_ADDR_STR2
4612 : "Specify a BGP neighbor\n"
4613 : AS_STR
4614 : "Internal BGP peer\n"
4615 : "External BGP peer\n")
4616 : {
4617 2 : int idx_peer = 1;
4618 2 : int idx_remote_as = 3;
4619 4 : return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4620 2 : argv[idx_remote_as]->arg);
4621 : }
4622 :
4623 0 : DEFPY (bgp_allow_martian,
4624 : bgp_allow_martian_cmd,
4625 : "[no]$no bgp allow-martian-nexthop",
4626 : NO_STR
4627 : BGP_STR
4628 : "Allow Martian nexthops to be received in the NLRI from a peer\n")
4629 : {
4630 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4631 :
4632 0 : if (no)
4633 0 : bgp->allow_martian = false;
4634 : else
4635 0 : bgp->allow_martian = true;
4636 :
4637 : return CMD_SUCCESS;
4638 : }
4639 :
4640 : /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4641 : * sessions do not wait for hold timer expiry to bring down the sessions
4642 : * when nexthop becomes unreachable
4643 : */
4644 0 : DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4645 : BGP_STR "Fast convergence for bgp sessions\n")
4646 : {
4647 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4648 0 : bgp->fast_convergence = true;
4649 :
4650 0 : return CMD_SUCCESS;
4651 : }
4652 :
4653 0 : DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4654 : "no bgp fast-convergence",
4655 : NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4656 : {
4657 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4658 0 : bgp->fast_convergence = false;
4659 :
4660 0 : return CMD_SUCCESS;
4661 : }
4662 :
4663 0 : static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4664 : int v6only,
4665 : const char *peer_group_name,
4666 : const char *as_str)
4667 : {
4668 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4669 0 : as_t as = 0;
4670 0 : int as_type = AS_UNSPECIFIED;
4671 0 : struct peer *peer;
4672 0 : struct peer_group *group;
4673 0 : int ret = 0;
4674 :
4675 0 : group = peer_group_lookup(bgp, conf_if);
4676 :
4677 0 : if (group) {
4678 0 : vty_out(vty, "%% Name conflict with peer-group \n");
4679 0 : return CMD_WARNING_CONFIG_FAILED;
4680 : }
4681 :
4682 0 : if (as_str) {
4683 0 : if (as_str[0] == 'i') {
4684 : as_type = AS_INTERNAL;
4685 0 : } else if (as_str[0] == 'e') {
4686 : as_type = AS_EXTERNAL;
4687 : } else {
4688 : /* Get AS number. */
4689 0 : as = strtoul(as_str, NULL, 10);
4690 0 : as_type = AS_SPECIFIED;
4691 : }
4692 : }
4693 :
4694 0 : peer = peer_lookup_by_conf_if(bgp, conf_if);
4695 0 : if (peer) {
4696 0 : if (as_str)
4697 0 : ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4698 : } else {
4699 0 : peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4700 : NULL, true);
4701 :
4702 0 : if (!peer) {
4703 0 : vty_out(vty, "%% BGP failed to create peer\n");
4704 0 : return CMD_WARNING_CONFIG_FAILED;
4705 : }
4706 :
4707 0 : if (v6only)
4708 0 : peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4709 :
4710 : /* Request zebra to initiate IPv6 RAs on this interface. We do
4711 : * this
4712 : * any unnumbered peer in order to not worry about run-time
4713 : * transitions
4714 : * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4715 : * address
4716 : * gets deleted later etc.)
4717 : */
4718 0 : if (peer->ifp)
4719 0 : bgp_zebra_initiate_radv(bgp, peer);
4720 : }
4721 :
4722 0 : if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4723 0 : || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4724 0 : if (v6only)
4725 0 : peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4726 : else
4727 0 : peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4728 :
4729 : /* v6only flag changed. Reset bgp seesion */
4730 0 : if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4731 0 : peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4732 0 : bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4733 : BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4734 : } else
4735 0 : bgp_session_reset(peer);
4736 : }
4737 :
4738 0 : if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4739 0 : SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4740 0 : SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4741 0 : SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4742 : }
4743 :
4744 0 : if (peer_group_name) {
4745 0 : group = peer_group_lookup(bgp, peer_group_name);
4746 0 : if (!group) {
4747 0 : vty_out(vty, "%% Configure the peer-group first\n");
4748 0 : return CMD_WARNING_CONFIG_FAILED;
4749 : }
4750 :
4751 0 : ret = peer_group_bind(bgp, NULL, peer, group, &as);
4752 : }
4753 :
4754 0 : return bgp_vty_return(vty, ret);
4755 : }
4756 :
4757 0 : DEFUN (neighbor_interface_config,
4758 : neighbor_interface_config_cmd,
4759 : "neighbor WORD interface [peer-group PGNAME]",
4760 : NEIGHBOR_STR
4761 : "Interface name or neighbor tag\n"
4762 : "Enable BGP on interface\n"
4763 : "Member of the peer-group\n"
4764 : "Peer-group name\n")
4765 : {
4766 0 : int idx_word = 1;
4767 0 : int idx_peer_group_word = 4;
4768 :
4769 0 : if (argc > idx_peer_group_word)
4770 0 : return peer_conf_interface_get(
4771 0 : vty, argv[idx_word]->arg, 0,
4772 0 : argv[idx_peer_group_word]->arg, NULL);
4773 : else
4774 0 : return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4775 : NULL, NULL);
4776 : }
4777 :
4778 0 : DEFUN (neighbor_interface_config_v6only,
4779 : neighbor_interface_config_v6only_cmd,
4780 : "neighbor WORD interface v6only [peer-group PGNAME]",
4781 : NEIGHBOR_STR
4782 : "Interface name or neighbor tag\n"
4783 : "Enable BGP on interface\n"
4784 : "Enable BGP with v6 link-local only\n"
4785 : "Member of the peer-group\n"
4786 : "Peer-group name\n")
4787 : {
4788 0 : int idx_word = 1;
4789 0 : int idx_peer_group_word = 5;
4790 :
4791 0 : if (argc > idx_peer_group_word)
4792 0 : return peer_conf_interface_get(
4793 0 : vty, argv[idx_word]->arg, 1,
4794 0 : argv[idx_peer_group_word]->arg, NULL);
4795 :
4796 0 : return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4797 : }
4798 :
4799 :
4800 0 : DEFUN (neighbor_interface_config_remote_as,
4801 : neighbor_interface_config_remote_as_cmd,
4802 : "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4803 : NEIGHBOR_STR
4804 : "Interface name or neighbor tag\n"
4805 : "Enable BGP on interface\n"
4806 : "Specify a BGP neighbor\n"
4807 : AS_STR
4808 : "Internal BGP peer\n"
4809 : "External BGP peer\n")
4810 : {
4811 0 : int idx_word = 1;
4812 0 : int idx_remote_as = 4;
4813 0 : return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4814 0 : argv[idx_remote_as]->arg);
4815 : }
4816 :
4817 0 : DEFUN (neighbor_interface_v6only_config_remote_as,
4818 : neighbor_interface_v6only_config_remote_as_cmd,
4819 : "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4820 : NEIGHBOR_STR
4821 : "Interface name or neighbor tag\n"
4822 : "Enable BGP with v6 link-local only\n"
4823 : "Enable BGP on interface\n"
4824 : "Specify a BGP neighbor\n"
4825 : AS_STR
4826 : "Internal BGP peer\n"
4827 : "External BGP peer\n")
4828 : {
4829 0 : int idx_word = 1;
4830 0 : int idx_remote_as = 5;
4831 0 : return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4832 0 : argv[idx_remote_as]->arg);
4833 : }
4834 :
4835 0 : DEFUN (neighbor_peer_group,
4836 : neighbor_peer_group_cmd,
4837 : "neighbor WORD peer-group",
4838 : NEIGHBOR_STR
4839 : "Interface name or neighbor tag\n"
4840 : "Configure peer-group\n")
4841 : {
4842 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4843 0 : int idx_word = 1;
4844 0 : struct peer *peer;
4845 0 : struct peer_group *group;
4846 :
4847 0 : peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4848 0 : if (peer) {
4849 0 : vty_out(vty, "%% Name conflict with interface: \n");
4850 0 : return CMD_WARNING_CONFIG_FAILED;
4851 : }
4852 :
4853 0 : group = peer_group_get(bgp, argv[idx_word]->arg);
4854 0 : if (!group) {
4855 0 : vty_out(vty, "%% BGP failed to find or create peer-group\n");
4856 0 : return CMD_WARNING_CONFIG_FAILED;
4857 : }
4858 :
4859 : return CMD_SUCCESS;
4860 : }
4861 :
4862 0 : DEFUN (no_neighbor,
4863 : no_neighbor_cmd,
4864 : "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4865 : NO_STR
4866 : NEIGHBOR_STR
4867 : NEIGHBOR_ADDR_STR2
4868 : "Specify a BGP neighbor\n"
4869 : AS_STR
4870 : "Internal BGP peer\n"
4871 : "External BGP peer\n")
4872 : {
4873 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4874 0 : int idx_peer = 2;
4875 0 : int ret;
4876 0 : union sockunion su;
4877 0 : struct peer_group *group;
4878 0 : struct peer *peer;
4879 0 : struct peer *other;
4880 :
4881 0 : ret = str2sockunion(argv[idx_peer]->arg, &su);
4882 0 : if (ret < 0) {
4883 : /* look up for neighbor by interface name config. */
4884 0 : peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4885 0 : if (peer) {
4886 : /* Request zebra to terminate IPv6 RAs on this
4887 : * interface. */
4888 0 : if (peer->ifp)
4889 0 : bgp_zebra_terminate_radv(peer->bgp, peer);
4890 0 : peer_notify_unconfig(peer);
4891 0 : peer_delete(peer);
4892 0 : return CMD_SUCCESS;
4893 : }
4894 :
4895 0 : group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4896 0 : if (group) {
4897 0 : peer_group_notify_unconfig(group);
4898 0 : peer_group_delete(group);
4899 : } else {
4900 0 : vty_out(vty, "%% Create the peer-group first\n");
4901 0 : return CMD_WARNING_CONFIG_FAILED;
4902 : }
4903 : } else {
4904 0 : peer = peer_lookup(bgp, &su);
4905 0 : if (peer) {
4906 0 : if (peer_dynamic_neighbor(peer)) {
4907 0 : vty_out(vty,
4908 : "%% Operation not allowed on a dynamic neighbor\n");
4909 0 : return CMD_WARNING_CONFIG_FAILED;
4910 : }
4911 :
4912 0 : other = peer->doppelganger;
4913 :
4914 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4915 0 : bgp_zebra_terminate_radv(peer->bgp, peer);
4916 :
4917 0 : peer_notify_unconfig(peer);
4918 0 : peer_delete(peer);
4919 0 : if (other && other->status != Deleted) {
4920 0 : peer_notify_unconfig(other);
4921 0 : peer_delete(other);
4922 : }
4923 : }
4924 : }
4925 :
4926 : return CMD_SUCCESS;
4927 : }
4928 :
4929 0 : DEFUN (no_neighbor_interface_config,
4930 : no_neighbor_interface_config_cmd,
4931 : "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4932 : NO_STR
4933 : NEIGHBOR_STR
4934 : "Interface name\n"
4935 : "Configure BGP on interface\n"
4936 : "Enable BGP with v6 link-local only\n"
4937 : "Member of the peer-group\n"
4938 : "Peer-group name\n"
4939 : "Specify a BGP neighbor\n"
4940 : AS_STR
4941 : "Internal BGP peer\n"
4942 : "External BGP peer\n")
4943 : {
4944 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4945 0 : int idx_word = 2;
4946 0 : struct peer *peer;
4947 :
4948 : /* look up for neighbor by interface name config. */
4949 0 : peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4950 0 : if (peer) {
4951 : /* Request zebra to terminate IPv6 RAs on this interface. */
4952 0 : if (peer->ifp)
4953 0 : bgp_zebra_terminate_radv(peer->bgp, peer);
4954 0 : peer_notify_unconfig(peer);
4955 0 : peer_delete(peer);
4956 : } else {
4957 0 : vty_out(vty, "%% Create the bgp interface first\n");
4958 0 : return CMD_WARNING_CONFIG_FAILED;
4959 : }
4960 0 : return CMD_SUCCESS;
4961 : }
4962 :
4963 0 : DEFUN (no_neighbor_peer_group,
4964 : no_neighbor_peer_group_cmd,
4965 : "no neighbor WORD peer-group",
4966 : NO_STR
4967 : NEIGHBOR_STR
4968 : "Neighbor tag\n"
4969 : "Configure peer-group\n")
4970 : {
4971 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4972 0 : int idx_word = 2;
4973 0 : struct peer_group *group;
4974 :
4975 0 : group = peer_group_lookup(bgp, argv[idx_word]->arg);
4976 0 : if (group) {
4977 0 : peer_group_notify_unconfig(group);
4978 0 : peer_group_delete(group);
4979 : } else {
4980 0 : vty_out(vty, "%% Create the peer-group first\n");
4981 0 : return CMD_WARNING_CONFIG_FAILED;
4982 : }
4983 0 : return CMD_SUCCESS;
4984 : }
4985 :
4986 0 : DEFUN (no_neighbor_interface_peer_group_remote_as,
4987 : no_neighbor_interface_peer_group_remote_as_cmd,
4988 : "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4989 : NO_STR
4990 : NEIGHBOR_STR
4991 : "Interface name or neighbor tag\n"
4992 : "Specify a BGP neighbor\n"
4993 : AS_STR
4994 : "Internal BGP peer\n"
4995 : "External BGP peer\n")
4996 : {
4997 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
4998 0 : int idx_word = 2;
4999 0 : struct peer_group *group;
5000 0 : struct peer *peer;
5001 :
5002 : /* look up for neighbor by interface name config. */
5003 0 : peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
5004 0 : if (peer) {
5005 0 : peer_as_change(peer, 0, AS_UNSPECIFIED);
5006 0 : return CMD_SUCCESS;
5007 : }
5008 :
5009 0 : group = peer_group_lookup(bgp, argv[idx_word]->arg);
5010 0 : if (group)
5011 0 : peer_group_remote_as_delete(group);
5012 : else {
5013 0 : vty_out(vty, "%% Create the peer-group or interface first\n");
5014 0 : return CMD_WARNING_CONFIG_FAILED;
5015 : }
5016 0 : return CMD_SUCCESS;
5017 : }
5018 :
5019 0 : DEFUN (neighbor_local_as,
5020 : neighbor_local_as_cmd,
5021 : "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
5022 : NEIGHBOR_STR
5023 : NEIGHBOR_ADDR_STR2
5024 : "Specify a local-as number\n"
5025 : "AS number used as local AS\n")
5026 : {
5027 0 : int idx_peer = 1;
5028 0 : int idx_number = 3;
5029 0 : struct peer *peer;
5030 0 : int ret;
5031 0 : as_t as;
5032 :
5033 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5034 0 : if (!peer)
5035 : return CMD_WARNING_CONFIG_FAILED;
5036 :
5037 0 : as = strtoul(argv[idx_number]->arg, NULL, 10);
5038 0 : ret = peer_local_as_set(peer, as, 0, 0);
5039 0 : return bgp_vty_return(vty, ret);
5040 : }
5041 :
5042 0 : DEFUN (neighbor_local_as_no_prepend,
5043 : neighbor_local_as_no_prepend_cmd,
5044 : "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
5045 : NEIGHBOR_STR
5046 : NEIGHBOR_ADDR_STR2
5047 : "Specify a local-as number\n"
5048 : "AS number used as local AS\n"
5049 : "Do not prepend local-as to updates from ebgp peers\n")
5050 : {
5051 0 : int idx_peer = 1;
5052 0 : int idx_number = 3;
5053 0 : struct peer *peer;
5054 0 : int ret;
5055 0 : as_t as;
5056 :
5057 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5058 0 : if (!peer)
5059 : return CMD_WARNING_CONFIG_FAILED;
5060 :
5061 0 : as = strtoul(argv[idx_number]->arg, NULL, 10);
5062 0 : ret = peer_local_as_set(peer, as, 1, 0);
5063 0 : return bgp_vty_return(vty, ret);
5064 : }
5065 :
5066 0 : DEFUN (neighbor_local_as_no_prepend_replace_as,
5067 : neighbor_local_as_no_prepend_replace_as_cmd,
5068 : "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
5069 : NEIGHBOR_STR
5070 : NEIGHBOR_ADDR_STR2
5071 : "Specify a local-as number\n"
5072 : "AS number used as local AS\n"
5073 : "Do not prepend local-as to updates from ebgp peers\n"
5074 : "Do not prepend local-as to updates from ibgp peers\n")
5075 : {
5076 0 : int idx_peer = 1;
5077 0 : int idx_number = 3;
5078 0 : struct peer *peer;
5079 0 : int ret;
5080 0 : as_t as;
5081 :
5082 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5083 0 : if (!peer)
5084 : return CMD_WARNING_CONFIG_FAILED;
5085 :
5086 0 : as = strtoul(argv[idx_number]->arg, NULL, 10);
5087 0 : ret = peer_local_as_set(peer, as, 1, 1);
5088 0 : return bgp_vty_return(vty, ret);
5089 : }
5090 :
5091 0 : DEFUN (no_neighbor_local_as,
5092 : no_neighbor_local_as_cmd,
5093 : "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
5094 : NO_STR
5095 : NEIGHBOR_STR
5096 : NEIGHBOR_ADDR_STR2
5097 : "Specify a local-as number\n"
5098 : "AS number used as local AS\n"
5099 : "Do not prepend local-as to updates from ebgp peers\n"
5100 : "Do not prepend local-as to updates from ibgp peers\n")
5101 : {
5102 0 : int idx_peer = 2;
5103 0 : struct peer *peer;
5104 0 : int ret;
5105 :
5106 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5107 0 : if (!peer)
5108 : return CMD_WARNING_CONFIG_FAILED;
5109 :
5110 0 : ret = peer_local_as_unset(peer);
5111 0 : return bgp_vty_return(vty, ret);
5112 : }
5113 :
5114 :
5115 0 : DEFUN (neighbor_solo,
5116 : neighbor_solo_cmd,
5117 : "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5118 : NEIGHBOR_STR
5119 : NEIGHBOR_ADDR_STR2
5120 : "Solo peer - part of its own update group\n")
5121 : {
5122 0 : int idx_peer = 1;
5123 0 : struct peer *peer;
5124 0 : int ret;
5125 :
5126 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5127 0 : if (!peer)
5128 : return CMD_WARNING_CONFIG_FAILED;
5129 :
5130 0 : ret = update_group_adjust_soloness(peer, 1);
5131 0 : return bgp_vty_return(vty, ret);
5132 : }
5133 :
5134 0 : DEFUN (no_neighbor_solo,
5135 : no_neighbor_solo_cmd,
5136 : "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
5137 : NO_STR
5138 : NEIGHBOR_STR
5139 : NEIGHBOR_ADDR_STR2
5140 : "Solo peer - part of its own update group\n")
5141 : {
5142 0 : int idx_peer = 2;
5143 0 : struct peer *peer;
5144 0 : int ret;
5145 :
5146 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5147 0 : if (!peer)
5148 : return CMD_WARNING_CONFIG_FAILED;
5149 :
5150 0 : ret = update_group_adjust_soloness(peer, 0);
5151 0 : return bgp_vty_return(vty, ret);
5152 : }
5153 :
5154 0 : DEFUN (neighbor_password,
5155 : neighbor_password_cmd,
5156 : "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5157 : NEIGHBOR_STR
5158 : NEIGHBOR_ADDR_STR2
5159 : "Set a password\n"
5160 : "The password\n")
5161 : {
5162 0 : int idx_peer = 1;
5163 0 : int idx_line = 3;
5164 0 : struct peer *peer;
5165 0 : int ret;
5166 :
5167 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5168 0 : if (!peer)
5169 : return CMD_WARNING_CONFIG_FAILED;
5170 :
5171 0 : ret = peer_password_set(peer, argv[idx_line]->arg);
5172 0 : return bgp_vty_return(vty, ret);
5173 : }
5174 :
5175 0 : DEFUN (no_neighbor_password,
5176 : no_neighbor_password_cmd,
5177 : "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5178 : NO_STR
5179 : NEIGHBOR_STR
5180 : NEIGHBOR_ADDR_STR2
5181 : "Set a password\n"
5182 : "The password\n")
5183 : {
5184 0 : int idx_peer = 2;
5185 0 : struct peer *peer;
5186 0 : int ret;
5187 :
5188 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5189 0 : if (!peer)
5190 : return CMD_WARNING_CONFIG_FAILED;
5191 :
5192 0 : ret = peer_password_unset(peer);
5193 0 : return bgp_vty_return(vty, ret);
5194 : }
5195 :
5196 0 : DEFUN (neighbor_activate,
5197 : neighbor_activate_cmd,
5198 : "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5199 : NEIGHBOR_STR
5200 : NEIGHBOR_ADDR_STR2
5201 : "Enable the Address Family for this Neighbor\n")
5202 : {
5203 0 : int idx_peer = 1;
5204 0 : int ret;
5205 0 : struct peer *peer;
5206 :
5207 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5208 0 : if (!peer)
5209 : return CMD_WARNING_CONFIG_FAILED;
5210 :
5211 0 : ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5212 0 : return bgp_vty_return(vty, ret);
5213 : }
5214 :
5215 : ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5216 : "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5217 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5218 : "Enable the Address Family for this Neighbor\n")
5219 :
5220 0 : DEFUN (no_neighbor_activate,
5221 : no_neighbor_activate_cmd,
5222 : "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5223 : NO_STR
5224 : NEIGHBOR_STR
5225 : NEIGHBOR_ADDR_STR2
5226 : "Enable the Address Family for this Neighbor\n")
5227 : {
5228 0 : int idx_peer = 2;
5229 0 : int ret;
5230 0 : struct peer *peer;
5231 :
5232 : /* Lookup peer. */
5233 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5234 0 : if (!peer)
5235 : return CMD_WARNING_CONFIG_FAILED;
5236 :
5237 0 : ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5238 0 : return bgp_vty_return(vty, ret);
5239 : }
5240 :
5241 : ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5242 : "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5243 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5244 : "Enable the Address Family for this Neighbor\n")
5245 :
5246 0 : DEFUN (neighbor_set_peer_group,
5247 : neighbor_set_peer_group_cmd,
5248 : "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5249 : NEIGHBOR_STR
5250 : NEIGHBOR_ADDR_STR2
5251 : "Member of the peer-group\n"
5252 : "Peer-group name\n")
5253 : {
5254 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
5255 0 : int idx_peer = 1;
5256 0 : int idx_word = 3;
5257 0 : int ret;
5258 0 : as_t as;
5259 0 : union sockunion su;
5260 0 : struct peer *peer;
5261 0 : struct peer_group *group;
5262 :
5263 0 : ret = str2sockunion(argv[idx_peer]->arg, &su);
5264 0 : if (ret < 0) {
5265 0 : peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5266 0 : if (!peer) {
5267 0 : vty_out(vty, "%% Malformed address or name: %s\n",
5268 0 : argv[idx_peer]->arg);
5269 0 : return CMD_WARNING_CONFIG_FAILED;
5270 : }
5271 : } else {
5272 0 : if (peer_address_self_check(bgp, &su)) {
5273 0 : vty_out(vty,
5274 : "%% Can not configure the local system as neighbor\n");
5275 0 : return CMD_WARNING_CONFIG_FAILED;
5276 : }
5277 :
5278 : /* Disallow for dynamic neighbor. */
5279 0 : peer = peer_lookup(bgp, &su);
5280 0 : if (peer && peer_dynamic_neighbor(peer)) {
5281 0 : vty_out(vty,
5282 : "%% Operation not allowed on a dynamic neighbor\n");
5283 0 : return CMD_WARNING_CONFIG_FAILED;
5284 : }
5285 : }
5286 :
5287 0 : group = peer_group_lookup(bgp, argv[idx_word]->arg);
5288 0 : if (!group) {
5289 0 : vty_out(vty, "%% Configure the peer-group first\n");
5290 0 : return CMD_WARNING_CONFIG_FAILED;
5291 : }
5292 :
5293 0 : ret = peer_group_bind(bgp, &su, peer, group, &as);
5294 :
5295 0 : return bgp_vty_return(vty, ret);
5296 : }
5297 :
5298 : ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5299 : "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5300 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5301 : "Member of the peer-group\n"
5302 : "Peer-group name\n")
5303 :
5304 0 : DEFUN (no_neighbor_set_peer_group,
5305 : no_neighbor_set_peer_group_cmd,
5306 : "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5307 : NO_STR
5308 : NEIGHBOR_STR
5309 : NEIGHBOR_ADDR_STR2
5310 : "Member of the peer-group\n"
5311 : "Peer-group name\n")
5312 : {
5313 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
5314 0 : int idx_peer = 2;
5315 0 : int idx_word = 4;
5316 0 : int ret;
5317 0 : struct peer *peer;
5318 0 : struct peer_group *group;
5319 :
5320 0 : peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5321 0 : if (!peer)
5322 : return CMD_WARNING_CONFIG_FAILED;
5323 :
5324 0 : group = peer_group_lookup(bgp, argv[idx_word]->arg);
5325 0 : if (!group) {
5326 0 : vty_out(vty, "%% Configure the peer-group first\n");
5327 0 : return CMD_WARNING_CONFIG_FAILED;
5328 : }
5329 :
5330 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5331 0 : bgp_zebra_terminate_radv(peer->bgp, peer);
5332 :
5333 0 : peer_notify_unconfig(peer);
5334 0 : ret = peer_delete(peer);
5335 :
5336 0 : return bgp_vty_return(vty, ret);
5337 : }
5338 :
5339 : ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5340 : "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5341 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5342 : "Member of the peer-group\n"
5343 : "Peer-group name\n")
5344 :
5345 : /* neighbor passive. */
5346 0 : DEFUN (neighbor_passive,
5347 : neighbor_passive_cmd,
5348 : "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5349 : NEIGHBOR_STR
5350 : NEIGHBOR_ADDR_STR2
5351 : "Don't send open messages to this neighbor\n")
5352 : {
5353 0 : int idx_peer = 1;
5354 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5355 : }
5356 :
5357 0 : DEFUN (no_neighbor_passive,
5358 : no_neighbor_passive_cmd,
5359 : "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5360 : NO_STR
5361 : NEIGHBOR_STR
5362 : NEIGHBOR_ADDR_STR2
5363 : "Don't send open messages to this neighbor\n")
5364 : {
5365 0 : int idx_peer = 2;
5366 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5367 : }
5368 :
5369 : /* neighbor shutdown. */
5370 0 : DEFUN (neighbor_shutdown_msg,
5371 : neighbor_shutdown_msg_cmd,
5372 : "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5373 : NEIGHBOR_STR
5374 : NEIGHBOR_ADDR_STR2
5375 : "Administratively shut down this neighbor\n"
5376 : "Add a shutdown message (RFC 8203)\n"
5377 : "Shutdown message\n")
5378 : {
5379 0 : int idx_peer = 1;
5380 :
5381 0 : if (argc >= 5) {
5382 0 : struct peer *peer =
5383 0 : peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5384 0 : char *message;
5385 :
5386 0 : if (!peer)
5387 : return CMD_WARNING_CONFIG_FAILED;
5388 0 : message = argv_concat(argv, argc, 4);
5389 0 : peer_tx_shutdown_message_set(peer, message);
5390 0 : XFREE(MTYPE_TMP, message);
5391 : }
5392 :
5393 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5394 : }
5395 :
5396 : ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5397 : "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5398 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5399 : "Administratively shut down this neighbor\n")
5400 :
5401 0 : DEFUN (no_neighbor_shutdown_msg,
5402 : no_neighbor_shutdown_msg_cmd,
5403 : "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5404 : NO_STR
5405 : NEIGHBOR_STR
5406 : NEIGHBOR_ADDR_STR2
5407 : "Administratively shut down this neighbor\n"
5408 : "Remove a shutdown message (RFC 8203)\n"
5409 : "Shutdown message\n")
5410 : {
5411 0 : int idx_peer = 2;
5412 :
5413 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5414 : PEER_FLAG_SHUTDOWN);
5415 : }
5416 :
5417 : ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5418 : "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5419 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5420 : "Administratively shut down this neighbor\n")
5421 :
5422 0 : DEFUN(neighbor_shutdown_rtt,
5423 : neighbor_shutdown_rtt_cmd,
5424 : "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5425 : NEIGHBOR_STR
5426 : NEIGHBOR_ADDR_STR2
5427 : "Administratively shut down this neighbor\n"
5428 : "Shutdown if round-trip-time is higher than expected\n"
5429 : "Round-trip-time in milliseconds\n"
5430 : "Specify the number of keepalives before shutdown\n"
5431 : "The number of keepalives with higher RTT to shutdown\n")
5432 : {
5433 0 : int idx_peer = 1;
5434 0 : int idx_rtt = 4;
5435 0 : int idx_count = 0;
5436 0 : struct peer *peer;
5437 :
5438 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5439 :
5440 0 : if (!peer)
5441 : return CMD_WARNING_CONFIG_FAILED;
5442 :
5443 0 : peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5444 :
5445 0 : if (argv_find(argv, argc, "count", &idx_count))
5446 0 : peer->rtt_keepalive_conf =
5447 0 : strtol(argv[idx_count + 1]->arg, NULL, 10);
5448 :
5449 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5450 : PEER_FLAG_RTT_SHUTDOWN);
5451 : }
5452 :
5453 0 : DEFUN(no_neighbor_shutdown_rtt,
5454 : no_neighbor_shutdown_rtt_cmd,
5455 : "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5456 : NO_STR
5457 : NEIGHBOR_STR
5458 : NEIGHBOR_ADDR_STR2
5459 : "Administratively shut down this neighbor\n"
5460 : "Shutdown if round-trip-time is higher than expected\n"
5461 : "Round-trip-time in milliseconds\n"
5462 : "Specify the number of keepalives before shutdown\n"
5463 : "The number of keepalives with higher RTT to shutdown\n")
5464 : {
5465 0 : int idx_peer = 2;
5466 0 : struct peer *peer;
5467 :
5468 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5469 :
5470 0 : if (!peer)
5471 : return CMD_WARNING_CONFIG_FAILED;
5472 :
5473 0 : peer->rtt_expected = 0;
5474 0 : peer->rtt_keepalive_conf = 1;
5475 :
5476 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5477 : PEER_FLAG_RTT_SHUTDOWN);
5478 : }
5479 :
5480 : /* neighbor capability dynamic. */
5481 0 : DEFUN (neighbor_capability_dynamic,
5482 : neighbor_capability_dynamic_cmd,
5483 : "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5484 : NEIGHBOR_STR
5485 : NEIGHBOR_ADDR_STR2
5486 : "Advertise capability to the peer\n"
5487 : "Advertise dynamic capability to this neighbor\n")
5488 : {
5489 0 : int idx_peer = 1;
5490 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5491 : PEER_FLAG_DYNAMIC_CAPABILITY);
5492 : }
5493 :
5494 0 : DEFUN (no_neighbor_capability_dynamic,
5495 : no_neighbor_capability_dynamic_cmd,
5496 : "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5497 : NO_STR
5498 : NEIGHBOR_STR
5499 : NEIGHBOR_ADDR_STR2
5500 : "Advertise capability to the peer\n"
5501 : "Advertise dynamic capability to this neighbor\n")
5502 : {
5503 0 : int idx_peer = 2;
5504 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5505 : PEER_FLAG_DYNAMIC_CAPABILITY);
5506 : }
5507 :
5508 : /* neighbor dont-capability-negotiate */
5509 0 : DEFUN (neighbor_dont_capability_negotiate,
5510 : neighbor_dont_capability_negotiate_cmd,
5511 : "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5512 : NEIGHBOR_STR
5513 : NEIGHBOR_ADDR_STR2
5514 : "Do not perform capability negotiation\n")
5515 : {
5516 0 : int idx_peer = 1;
5517 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5518 : PEER_FLAG_DONT_CAPABILITY);
5519 : }
5520 :
5521 0 : DEFUN (no_neighbor_dont_capability_negotiate,
5522 : no_neighbor_dont_capability_negotiate_cmd,
5523 : "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5524 : NO_STR
5525 : NEIGHBOR_STR
5526 : NEIGHBOR_ADDR_STR2
5527 : "Do not perform capability negotiation\n")
5528 : {
5529 0 : int idx_peer = 2;
5530 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5531 : PEER_FLAG_DONT_CAPABILITY);
5532 : }
5533 :
5534 : /* neighbor capability extended next hop encoding */
5535 0 : DEFUN (neighbor_capability_enhe,
5536 : neighbor_capability_enhe_cmd,
5537 : "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5538 : NEIGHBOR_STR
5539 : NEIGHBOR_ADDR_STR2
5540 : "Advertise capability to the peer\n"
5541 : "Advertise extended next-hop capability to the peer\n")
5542 : {
5543 0 : int idx_peer = 1;
5544 0 : struct peer *peer;
5545 :
5546 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5547 0 : if (peer && peer->conf_if)
5548 : return CMD_SUCCESS;
5549 :
5550 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5551 : PEER_FLAG_CAPABILITY_ENHE);
5552 : }
5553 :
5554 0 : DEFUN (no_neighbor_capability_enhe,
5555 : no_neighbor_capability_enhe_cmd,
5556 : "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5557 : NO_STR
5558 : NEIGHBOR_STR
5559 : NEIGHBOR_ADDR_STR2
5560 : "Advertise capability to the peer\n"
5561 : "Advertise extended next-hop capability to the peer\n")
5562 : {
5563 0 : int idx_peer = 2;
5564 0 : struct peer *peer;
5565 :
5566 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5567 0 : if (peer && peer->conf_if) {
5568 0 : vty_out(vty,
5569 : "Peer %s cannot have capability extended-nexthop turned off\n",
5570 0 : argv[idx_peer]->arg);
5571 0 : return CMD_WARNING_CONFIG_FAILED;
5572 : }
5573 :
5574 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5575 : PEER_FLAG_CAPABILITY_ENHE);
5576 : }
5577 :
5578 0 : static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5579 : afi_t afi, safi_t safi, uint32_t flag,
5580 : int set)
5581 : {
5582 0 : int ret;
5583 0 : struct peer *peer;
5584 :
5585 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
5586 0 : if (!peer)
5587 : return CMD_WARNING_CONFIG_FAILED;
5588 :
5589 0 : if (set)
5590 0 : ret = peer_af_flag_set(peer, afi, safi, flag);
5591 : else
5592 0 : ret = peer_af_flag_unset(peer, afi, safi, flag);
5593 :
5594 0 : return bgp_vty_return(vty, ret);
5595 : }
5596 :
5597 0 : static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5598 : afi_t afi, safi_t safi, uint32_t flag)
5599 : {
5600 0 : return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5601 : }
5602 :
5603 0 : static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5604 : afi_t afi, safi_t safi, uint32_t flag)
5605 : {
5606 0 : return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5607 : }
5608 :
5609 : /* neighbor capability orf prefix-list. */
5610 0 : DEFUN (neighbor_capability_orf_prefix,
5611 : neighbor_capability_orf_prefix_cmd,
5612 : "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5613 : NEIGHBOR_STR
5614 : NEIGHBOR_ADDR_STR2
5615 : "Advertise capability to the peer\n"
5616 : "Advertise ORF capability to the peer\n"
5617 : "Advertise prefixlist ORF capability to this neighbor\n"
5618 : "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5619 : "Capability to RECEIVE the ORF from this neighbor\n"
5620 : "Capability to SEND the ORF to this neighbor\n")
5621 : {
5622 0 : int idx_send_recv = 5;
5623 0 : char *peer_str = argv[1]->arg;
5624 0 : struct peer *peer;
5625 0 : afi_t afi = bgp_node_afi(vty);
5626 0 : safi_t safi = bgp_node_safi(vty);
5627 :
5628 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
5629 0 : if (!peer)
5630 : return CMD_WARNING_CONFIG_FAILED;
5631 :
5632 0 : if (strmatch(argv[idx_send_recv]->text, "send"))
5633 0 : return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5634 : PEER_FLAG_ORF_PREFIX_SM);
5635 :
5636 0 : if (strmatch(argv[idx_send_recv]->text, "receive"))
5637 0 : return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5638 : PEER_FLAG_ORF_PREFIX_RM);
5639 :
5640 0 : if (strmatch(argv[idx_send_recv]->text, "both"))
5641 0 : return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5642 : PEER_FLAG_ORF_PREFIX_SM)
5643 0 : | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5644 : PEER_FLAG_ORF_PREFIX_RM);
5645 :
5646 : return CMD_WARNING_CONFIG_FAILED;
5647 : }
5648 :
5649 : ALIAS_HIDDEN(
5650 : neighbor_capability_orf_prefix,
5651 : neighbor_capability_orf_prefix_hidden_cmd,
5652 : "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5653 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5654 : "Advertise capability to the peer\n"
5655 : "Advertise ORF capability to the peer\n"
5656 : "Advertise prefixlist ORF capability to this neighbor\n"
5657 : "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5658 : "Capability to RECEIVE the ORF from this neighbor\n"
5659 : "Capability to SEND the ORF to this neighbor\n")
5660 :
5661 0 : DEFUN (no_neighbor_capability_orf_prefix,
5662 : no_neighbor_capability_orf_prefix_cmd,
5663 : "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5664 : NO_STR
5665 : NEIGHBOR_STR
5666 : NEIGHBOR_ADDR_STR2
5667 : "Advertise capability to the peer\n"
5668 : "Advertise ORF capability to the peer\n"
5669 : "Advertise prefixlist ORF capability to this neighbor\n"
5670 : "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5671 : "Capability to RECEIVE the ORF from this neighbor\n"
5672 : "Capability to SEND the ORF to this neighbor\n")
5673 : {
5674 0 : int idx_send_recv = 6;
5675 0 : char *peer_str = argv[2]->arg;
5676 0 : struct peer *peer;
5677 0 : afi_t afi = bgp_node_afi(vty);
5678 0 : safi_t safi = bgp_node_safi(vty);
5679 :
5680 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
5681 0 : if (!peer)
5682 : return CMD_WARNING_CONFIG_FAILED;
5683 :
5684 0 : if (strmatch(argv[idx_send_recv]->text, "send"))
5685 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5686 : PEER_FLAG_ORF_PREFIX_SM);
5687 :
5688 0 : if (strmatch(argv[idx_send_recv]->text, "receive"))
5689 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5690 : PEER_FLAG_ORF_PREFIX_RM);
5691 :
5692 0 : if (strmatch(argv[idx_send_recv]->text, "both"))
5693 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5694 : PEER_FLAG_ORF_PREFIX_SM)
5695 0 : | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5696 : PEER_FLAG_ORF_PREFIX_RM);
5697 :
5698 : return CMD_WARNING_CONFIG_FAILED;
5699 : }
5700 :
5701 : ALIAS_HIDDEN(
5702 : no_neighbor_capability_orf_prefix,
5703 : no_neighbor_capability_orf_prefix_hidden_cmd,
5704 : "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5705 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5706 : "Advertise capability to the peer\n"
5707 : "Advertise ORF capability to the peer\n"
5708 : "Advertise prefixlist ORF capability to this neighbor\n"
5709 : "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5710 : "Capability to RECEIVE the ORF from this neighbor\n"
5711 : "Capability to SEND the ORF to this neighbor\n")
5712 :
5713 : /* neighbor next-hop-self. */
5714 0 : DEFUN (neighbor_nexthop_self,
5715 : neighbor_nexthop_self_cmd,
5716 : "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5717 : NEIGHBOR_STR
5718 : NEIGHBOR_ADDR_STR2
5719 : "Disable the next hop calculation for this neighbor\n")
5720 : {
5721 0 : int idx_peer = 1;
5722 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5723 : bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5724 : }
5725 :
5726 : ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5727 : "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5728 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5729 : "Disable the next hop calculation for this neighbor\n")
5730 :
5731 : /* neighbor next-hop-self. */
5732 0 : DEFUN (neighbor_nexthop_self_force,
5733 : neighbor_nexthop_self_force_cmd,
5734 : "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5735 : NEIGHBOR_STR
5736 : NEIGHBOR_ADDR_STR2
5737 : "Disable the next hop calculation for this neighbor\n"
5738 : "Set the next hop to self for reflected routes\n")
5739 : {
5740 0 : int idx_peer = 1;
5741 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5742 : bgp_node_safi(vty),
5743 : PEER_FLAG_FORCE_NEXTHOP_SELF);
5744 : }
5745 :
5746 : ALIAS_HIDDEN(neighbor_nexthop_self_force,
5747 : neighbor_nexthop_self_force_hidden_cmd,
5748 : "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5749 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5750 : "Disable the next hop calculation for this neighbor\n"
5751 : "Set the next hop to self for reflected routes\n")
5752 :
5753 : ALIAS_HIDDEN(neighbor_nexthop_self_force,
5754 : neighbor_nexthop_self_all_hidden_cmd,
5755 : "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5756 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5757 : "Disable the next hop calculation for this neighbor\n"
5758 : "Set the next hop to self for reflected routes\n")
5759 :
5760 0 : DEFUN (no_neighbor_nexthop_self,
5761 : no_neighbor_nexthop_self_cmd,
5762 : "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5763 : NO_STR
5764 : NEIGHBOR_STR
5765 : NEIGHBOR_ADDR_STR2
5766 : "Disable the next hop calculation for this neighbor\n")
5767 : {
5768 0 : int idx_peer = 2;
5769 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5770 : bgp_node_afi(vty), bgp_node_safi(vty),
5771 : PEER_FLAG_NEXTHOP_SELF);
5772 : }
5773 :
5774 : ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5775 : "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5776 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5777 : "Disable the next hop calculation for this neighbor\n")
5778 :
5779 0 : DEFUN (no_neighbor_nexthop_self_force,
5780 : no_neighbor_nexthop_self_force_cmd,
5781 : "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5782 : NO_STR
5783 : NEIGHBOR_STR
5784 : NEIGHBOR_ADDR_STR2
5785 : "Disable the next hop calculation for this neighbor\n"
5786 : "Set the next hop to self for reflected routes\n")
5787 : {
5788 0 : int idx_peer = 2;
5789 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5790 : bgp_node_afi(vty), bgp_node_safi(vty),
5791 : PEER_FLAG_FORCE_NEXTHOP_SELF);
5792 : }
5793 :
5794 : ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5795 : no_neighbor_nexthop_self_force_hidden_cmd,
5796 : "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5797 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5798 : "Disable the next hop calculation for this neighbor\n"
5799 : "Set the next hop to self for reflected routes\n")
5800 :
5801 : ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5802 : no_neighbor_nexthop_self_all_hidden_cmd,
5803 : "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5804 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5805 : "Disable the next hop calculation for this neighbor\n"
5806 : "Set the next hop to self for reflected routes\n")
5807 :
5808 : /* neighbor as-override */
5809 0 : DEFUN (neighbor_as_override,
5810 : neighbor_as_override_cmd,
5811 : "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5812 : NEIGHBOR_STR
5813 : NEIGHBOR_ADDR_STR2
5814 : "Override ASNs in outbound updates if aspath equals remote-as\n")
5815 : {
5816 0 : int idx_peer = 1;
5817 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5818 : bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5819 : }
5820 :
5821 : ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5822 : "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5823 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5824 : "Override ASNs in outbound updates if aspath equals remote-as\n")
5825 :
5826 0 : DEFUN (no_neighbor_as_override,
5827 : no_neighbor_as_override_cmd,
5828 : "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5829 : NO_STR
5830 : NEIGHBOR_STR
5831 : NEIGHBOR_ADDR_STR2
5832 : "Override ASNs in outbound updates if aspath equals remote-as\n")
5833 : {
5834 0 : int idx_peer = 2;
5835 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5836 : bgp_node_afi(vty), bgp_node_safi(vty),
5837 : PEER_FLAG_AS_OVERRIDE);
5838 : }
5839 :
5840 : ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5841 : "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5842 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 : "Override ASNs in outbound updates if aspath equals remote-as\n")
5844 :
5845 : /* neighbor remove-private-AS. */
5846 0 : DEFUN (neighbor_remove_private_as,
5847 : neighbor_remove_private_as_cmd,
5848 : "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5849 : NEIGHBOR_STR
5850 : NEIGHBOR_ADDR_STR2
5851 : "Remove private ASNs in outbound updates\n")
5852 : {
5853 0 : int idx_peer = 1;
5854 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5855 : bgp_node_safi(vty),
5856 : PEER_FLAG_REMOVE_PRIVATE_AS);
5857 : }
5858 :
5859 : ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5860 : "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5861 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5862 : "Remove private ASNs in outbound updates\n")
5863 :
5864 0 : DEFUN (neighbor_remove_private_as_all,
5865 : neighbor_remove_private_as_all_cmd,
5866 : "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5867 : NEIGHBOR_STR
5868 : NEIGHBOR_ADDR_STR2
5869 : "Remove private ASNs in outbound updates\n"
5870 : "Apply to all AS numbers\n")
5871 : {
5872 0 : int idx_peer = 1;
5873 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5874 : bgp_node_safi(vty),
5875 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5876 : }
5877 :
5878 : ALIAS_HIDDEN(neighbor_remove_private_as_all,
5879 : neighbor_remove_private_as_all_hidden_cmd,
5880 : "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5881 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5882 : "Remove private ASNs in outbound updates\n"
5883 : "Apply to all AS numbers\n")
5884 :
5885 0 : DEFUN (neighbor_remove_private_as_replace_as,
5886 : neighbor_remove_private_as_replace_as_cmd,
5887 : "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5888 : NEIGHBOR_STR
5889 : NEIGHBOR_ADDR_STR2
5890 : "Remove private ASNs in outbound updates\n"
5891 : "Replace private ASNs with our ASN in outbound updates\n")
5892 : {
5893 0 : int idx_peer = 1;
5894 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5895 : bgp_node_safi(vty),
5896 : PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5897 : }
5898 :
5899 : ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5900 : neighbor_remove_private_as_replace_as_hidden_cmd,
5901 : "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5902 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5903 : "Remove private ASNs in outbound updates\n"
5904 : "Replace private ASNs with our ASN in outbound updates\n")
5905 :
5906 0 : DEFUN (neighbor_remove_private_as_all_replace_as,
5907 : neighbor_remove_private_as_all_replace_as_cmd,
5908 : "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5909 : NEIGHBOR_STR
5910 : NEIGHBOR_ADDR_STR2
5911 : "Remove private ASNs in outbound updates\n"
5912 : "Apply to all AS numbers\n"
5913 : "Replace private ASNs with our ASN in outbound updates\n")
5914 : {
5915 0 : int idx_peer = 1;
5916 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5917 : bgp_node_safi(vty),
5918 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5919 : }
5920 :
5921 : ALIAS_HIDDEN(
5922 : neighbor_remove_private_as_all_replace_as,
5923 : neighbor_remove_private_as_all_replace_as_hidden_cmd,
5924 : "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5925 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5926 : "Remove private ASNs in outbound updates\n"
5927 : "Apply to all AS numbers\n"
5928 : "Replace private ASNs with our ASN in outbound updates\n")
5929 :
5930 0 : DEFUN (no_neighbor_remove_private_as,
5931 : no_neighbor_remove_private_as_cmd,
5932 : "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5933 : NO_STR
5934 : NEIGHBOR_STR
5935 : NEIGHBOR_ADDR_STR2
5936 : "Remove private ASNs in outbound updates\n")
5937 : {
5938 0 : int idx_peer = 2;
5939 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5940 : bgp_node_afi(vty), bgp_node_safi(vty),
5941 : PEER_FLAG_REMOVE_PRIVATE_AS);
5942 : }
5943 :
5944 : ALIAS_HIDDEN(no_neighbor_remove_private_as,
5945 : no_neighbor_remove_private_as_hidden_cmd,
5946 : "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5947 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 : "Remove private ASNs in outbound updates\n")
5949 :
5950 0 : DEFUN (no_neighbor_remove_private_as_all,
5951 : no_neighbor_remove_private_as_all_cmd,
5952 : "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5953 : NO_STR
5954 : NEIGHBOR_STR
5955 : NEIGHBOR_ADDR_STR2
5956 : "Remove private ASNs in outbound updates\n"
5957 : "Apply to all AS numbers\n")
5958 : {
5959 0 : int idx_peer = 2;
5960 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5961 : bgp_node_afi(vty), bgp_node_safi(vty),
5962 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5963 : }
5964 :
5965 : ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5966 : no_neighbor_remove_private_as_all_hidden_cmd,
5967 : "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5968 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 : "Remove private ASNs in outbound updates\n"
5970 : "Apply to all AS numbers\n")
5971 :
5972 0 : DEFUN (no_neighbor_remove_private_as_replace_as,
5973 : no_neighbor_remove_private_as_replace_as_cmd,
5974 : "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5975 : NO_STR
5976 : NEIGHBOR_STR
5977 : NEIGHBOR_ADDR_STR2
5978 : "Remove private ASNs in outbound updates\n"
5979 : "Replace private ASNs with our ASN in outbound updates\n")
5980 : {
5981 0 : int idx_peer = 2;
5982 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5983 : bgp_node_afi(vty), bgp_node_safi(vty),
5984 : PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5985 : }
5986 :
5987 : ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5988 : no_neighbor_remove_private_as_replace_as_hidden_cmd,
5989 : "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5990 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5991 : "Remove private ASNs in outbound updates\n"
5992 : "Replace private ASNs with our ASN in outbound updates\n")
5993 :
5994 0 : DEFUN (no_neighbor_remove_private_as_all_replace_as,
5995 : no_neighbor_remove_private_as_all_replace_as_cmd,
5996 : "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5997 : NO_STR
5998 : NEIGHBOR_STR
5999 : NEIGHBOR_ADDR_STR2
6000 : "Remove private ASNs in outbound updates\n"
6001 : "Apply to all AS numbers\n"
6002 : "Replace private ASNs with our ASN in outbound updates\n")
6003 : {
6004 0 : int idx_peer = 2;
6005 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6006 : bgp_node_afi(vty), bgp_node_safi(vty),
6007 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
6008 : }
6009 :
6010 : ALIAS_HIDDEN(
6011 : no_neighbor_remove_private_as_all_replace_as,
6012 : no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6013 : "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6014 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6015 : "Remove private ASNs in outbound updates\n"
6016 : "Apply to all AS numbers\n"
6017 : "Replace private ASNs with our ASN in outbound updates\n")
6018 :
6019 :
6020 : /* neighbor send-community. */
6021 0 : DEFUN (neighbor_send_community,
6022 : neighbor_send_community_cmd,
6023 : "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6024 : NEIGHBOR_STR
6025 : NEIGHBOR_ADDR_STR2
6026 : "Send Community attribute to this neighbor\n")
6027 : {
6028 0 : int idx_peer = 1;
6029 :
6030 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6031 : bgp_node_safi(vty),
6032 : PEER_FLAG_SEND_COMMUNITY);
6033 : }
6034 :
6035 : ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6036 : "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6037 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6038 : "Send Community attribute to this neighbor\n")
6039 :
6040 0 : DEFUN (no_neighbor_send_community,
6041 : no_neighbor_send_community_cmd,
6042 : "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6043 : NO_STR
6044 : NEIGHBOR_STR
6045 : NEIGHBOR_ADDR_STR2
6046 : "Send Community attribute to this neighbor\n")
6047 : {
6048 0 : int idx_peer = 2;
6049 :
6050 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6051 : bgp_node_afi(vty), bgp_node_safi(vty),
6052 : PEER_FLAG_SEND_COMMUNITY);
6053 : }
6054 :
6055 : ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6056 : "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6057 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6058 : "Send Community attribute to this neighbor\n")
6059 :
6060 : /* neighbor send-community extended. */
6061 0 : DEFUN (neighbor_send_community_type,
6062 : neighbor_send_community_type_cmd,
6063 : "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6064 : NEIGHBOR_STR
6065 : NEIGHBOR_ADDR_STR2
6066 : "Send Community attribute to this neighbor\n"
6067 : "Send Standard and Extended Community attributes\n"
6068 : "Send Standard, Large and Extended Community attributes\n"
6069 : "Send Extended Community attributes\n"
6070 : "Send Standard Community attributes\n"
6071 : "Send Large Community attributes\n")
6072 : {
6073 0 : const char *type = argv[argc - 1]->text;
6074 0 : char *peer_str = argv[1]->arg;
6075 0 : struct peer *peer;
6076 0 : afi_t afi = bgp_node_afi(vty);
6077 0 : safi_t safi = bgp_node_safi(vty);
6078 :
6079 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
6080 0 : if (!peer)
6081 : return CMD_WARNING_CONFIG_FAILED;
6082 :
6083 0 : if (strmatch(type, "standard"))
6084 0 : return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6085 : PEER_FLAG_SEND_COMMUNITY);
6086 :
6087 0 : if (strmatch(type, "extended"))
6088 0 : return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6089 : PEER_FLAG_SEND_EXT_COMMUNITY);
6090 :
6091 0 : if (strmatch(type, "large"))
6092 0 : return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6093 : PEER_FLAG_SEND_LARGE_COMMUNITY);
6094 :
6095 0 : if (strmatch(type, "both")) {
6096 0 : return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6097 : PEER_FLAG_SEND_COMMUNITY)
6098 0 : | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6099 : PEER_FLAG_SEND_EXT_COMMUNITY);
6100 : }
6101 0 : return peer_af_flag_set_vty(vty, peer_str, afi, safi,
6102 : PEER_FLAG_SEND_COMMUNITY)
6103 0 : | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6104 : PEER_FLAG_SEND_EXT_COMMUNITY)
6105 0 : | peer_af_flag_set_vty(vty, peer_str, afi, safi,
6106 : PEER_FLAG_SEND_LARGE_COMMUNITY);
6107 : }
6108 :
6109 : ALIAS_HIDDEN(
6110 : neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6111 : "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6112 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6113 : "Send Community attribute to this neighbor\n"
6114 : "Send Standard and Extended Community attributes\n"
6115 : "Send Standard, Large and Extended Community attributes\n"
6116 : "Send Extended Community attributes\n"
6117 : "Send Standard Community attributes\n"
6118 : "Send Large Community attributes\n")
6119 :
6120 0 : DEFUN (no_neighbor_send_community_type,
6121 : no_neighbor_send_community_type_cmd,
6122 : "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6123 : NO_STR
6124 : NEIGHBOR_STR
6125 : 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")
6132 : {
6133 0 : const char *type = argv[argc - 1]->text;
6134 0 : char *peer_str = argv[2]->arg;
6135 0 : struct peer *peer;
6136 0 : afi_t afi = bgp_node_afi(vty);
6137 0 : safi_t safi = bgp_node_safi(vty);
6138 :
6139 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
6140 0 : if (!peer)
6141 : return CMD_WARNING_CONFIG_FAILED;
6142 :
6143 0 : if (strmatch(type, "standard"))
6144 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6145 : PEER_FLAG_SEND_COMMUNITY);
6146 :
6147 0 : if (strmatch(type, "extended"))
6148 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6149 : PEER_FLAG_SEND_EXT_COMMUNITY);
6150 :
6151 0 : if (strmatch(type, "large"))
6152 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6153 : PEER_FLAG_SEND_LARGE_COMMUNITY);
6154 :
6155 0 : if (strmatch(type, "both")) {
6156 :
6157 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6158 : PEER_FLAG_SEND_COMMUNITY)
6159 0 : | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6160 : PEER_FLAG_SEND_EXT_COMMUNITY);
6161 : }
6162 :
6163 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6164 : PEER_FLAG_SEND_COMMUNITY)
6165 0 : | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6166 : PEER_FLAG_SEND_EXT_COMMUNITY)
6167 0 : | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6168 : PEER_FLAG_SEND_LARGE_COMMUNITY);
6169 : }
6170 :
6171 : ALIAS_HIDDEN(
6172 : no_neighbor_send_community_type,
6173 : no_neighbor_send_community_type_hidden_cmd,
6174 : "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6175 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6176 : "Send Community attribute to this neighbor\n"
6177 : "Send Standard and Extended Community attributes\n"
6178 : "Send Standard, Large and Extended Community attributes\n"
6179 : "Send Extended Community attributes\n"
6180 : "Send Standard Community attributes\n"
6181 : "Send Large Community attributes\n")
6182 :
6183 : /* neighbor soft-reconfig. */
6184 0 : DEFUN (neighbor_soft_reconfiguration,
6185 : neighbor_soft_reconfiguration_cmd,
6186 : "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6187 : NEIGHBOR_STR
6188 : NEIGHBOR_ADDR_STR2
6189 : "Per neighbor soft reconfiguration\n"
6190 : "Allow inbound soft reconfiguration for this neighbor\n")
6191 : {
6192 0 : int idx_peer = 1;
6193 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6194 : bgp_node_safi(vty),
6195 : PEER_FLAG_SOFT_RECONFIG);
6196 : }
6197 :
6198 : ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6199 : neighbor_soft_reconfiguration_hidden_cmd,
6200 : "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6201 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6202 : "Per neighbor soft reconfiguration\n"
6203 : "Allow inbound soft reconfiguration for this neighbor\n")
6204 :
6205 0 : DEFUN (no_neighbor_soft_reconfiguration,
6206 : no_neighbor_soft_reconfiguration_cmd,
6207 : "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6208 : NO_STR
6209 : NEIGHBOR_STR
6210 : NEIGHBOR_ADDR_STR2
6211 : "Per neighbor soft reconfiguration\n"
6212 : "Allow inbound soft reconfiguration for this neighbor\n")
6213 : {
6214 0 : int idx_peer = 2;
6215 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6216 : bgp_node_afi(vty), bgp_node_safi(vty),
6217 : PEER_FLAG_SOFT_RECONFIG);
6218 : }
6219 :
6220 : ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6221 : no_neighbor_soft_reconfiguration_hidden_cmd,
6222 : "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6223 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6224 : "Per neighbor soft reconfiguration\n"
6225 : "Allow inbound soft reconfiguration for this neighbor\n")
6226 :
6227 0 : DEFUN (neighbor_route_reflector_client,
6228 : neighbor_route_reflector_client_cmd,
6229 : "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6230 : NEIGHBOR_STR
6231 : NEIGHBOR_ADDR_STR2
6232 : "Configure a neighbor as Route Reflector client\n")
6233 : {
6234 0 : int idx_peer = 1;
6235 0 : struct peer *peer;
6236 :
6237 :
6238 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6239 0 : if (!peer)
6240 : return CMD_WARNING_CONFIG_FAILED;
6241 :
6242 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6243 : bgp_node_safi(vty),
6244 : PEER_FLAG_REFLECTOR_CLIENT);
6245 : }
6246 :
6247 : ALIAS_HIDDEN(neighbor_route_reflector_client,
6248 : neighbor_route_reflector_client_hidden_cmd,
6249 : "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6250 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6251 : "Configure a neighbor as Route Reflector client\n")
6252 :
6253 0 : DEFUN (no_neighbor_route_reflector_client,
6254 : no_neighbor_route_reflector_client_cmd,
6255 : "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6256 : NO_STR
6257 : NEIGHBOR_STR
6258 : NEIGHBOR_ADDR_STR2
6259 : "Configure a neighbor as Route Reflector client\n")
6260 : {
6261 0 : int idx_peer = 2;
6262 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6263 : bgp_node_afi(vty), bgp_node_safi(vty),
6264 : PEER_FLAG_REFLECTOR_CLIENT);
6265 : }
6266 :
6267 : ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6268 : no_neighbor_route_reflector_client_hidden_cmd,
6269 : "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6270 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6271 : "Configure a neighbor as Route Reflector client\n")
6272 :
6273 : /* neighbor route-server-client. */
6274 0 : DEFUN (neighbor_route_server_client,
6275 : neighbor_route_server_client_cmd,
6276 : "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6277 : NEIGHBOR_STR
6278 : NEIGHBOR_ADDR_STR2
6279 : "Configure a neighbor as Route Server client\n")
6280 : {
6281 0 : int idx_peer = 1;
6282 0 : struct peer *peer;
6283 :
6284 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6285 0 : if (!peer)
6286 : return CMD_WARNING_CONFIG_FAILED;
6287 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6288 : bgp_node_safi(vty),
6289 : PEER_FLAG_RSERVER_CLIENT);
6290 : }
6291 :
6292 : ALIAS_HIDDEN(neighbor_route_server_client,
6293 : neighbor_route_server_client_hidden_cmd,
6294 : "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6295 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6296 : "Configure a neighbor as Route Server client\n")
6297 :
6298 0 : DEFUN (no_neighbor_route_server_client,
6299 : no_neighbor_route_server_client_cmd,
6300 : "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6301 : NO_STR
6302 : NEIGHBOR_STR
6303 : NEIGHBOR_ADDR_STR2
6304 : "Configure a neighbor as Route Server client\n")
6305 : {
6306 0 : int idx_peer = 2;
6307 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6308 : bgp_node_afi(vty), bgp_node_safi(vty),
6309 : PEER_FLAG_RSERVER_CLIENT);
6310 : }
6311 :
6312 : ALIAS_HIDDEN(no_neighbor_route_server_client,
6313 : no_neighbor_route_server_client_hidden_cmd,
6314 : "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6315 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6316 : "Configure a neighbor as Route Server client\n")
6317 :
6318 0 : DEFUN (neighbor_nexthop_local_unchanged,
6319 : neighbor_nexthop_local_unchanged_cmd,
6320 : "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6321 : NEIGHBOR_STR
6322 : NEIGHBOR_ADDR_STR2
6323 : "Configure treatment of outgoing link-local nexthop attribute\n"
6324 : "Leave link-local nexthop unchanged for this peer\n")
6325 : {
6326 0 : int idx_peer = 1;
6327 0 : return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6328 : bgp_node_safi(vty),
6329 : PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6330 : }
6331 :
6332 0 : DEFUN (no_neighbor_nexthop_local_unchanged,
6333 : no_neighbor_nexthop_local_unchanged_cmd,
6334 : "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6335 : NO_STR
6336 : NEIGHBOR_STR
6337 : NEIGHBOR_ADDR_STR2
6338 : "Configure treatment of outgoing link-local-nexthop attribute\n"
6339 : "Leave link-local nexthop unchanged for this peer\n")
6340 : {
6341 0 : int idx_peer = 2;
6342 0 : return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6343 : bgp_node_afi(vty), bgp_node_safi(vty),
6344 : PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6345 : }
6346 :
6347 0 : DEFUN (neighbor_attr_unchanged,
6348 : neighbor_attr_unchanged_cmd,
6349 : "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6350 : NEIGHBOR_STR
6351 : NEIGHBOR_ADDR_STR2
6352 : "BGP attribute is propagated unchanged to this neighbor\n"
6353 : "As-path attribute\n"
6354 : "Nexthop attribute\n"
6355 : "Med attribute\n")
6356 : {
6357 0 : int idx = 0;
6358 0 : char *peer_str = argv[1]->arg;
6359 0 : struct peer *peer;
6360 0 : bool aspath = false;
6361 0 : bool nexthop = false;
6362 0 : bool med = false;
6363 0 : afi_t afi = bgp_node_afi(vty);
6364 0 : safi_t safi = bgp_node_safi(vty);
6365 0 : int ret = 0;
6366 :
6367 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
6368 0 : if (!peer)
6369 : return CMD_WARNING_CONFIG_FAILED;
6370 :
6371 0 : if (argv_find(argv, argc, "as-path", &idx))
6372 0 : aspath = true;
6373 :
6374 0 : idx = 0;
6375 0 : if (argv_find(argv, argc, "next-hop", &idx))
6376 0 : nexthop = true;
6377 :
6378 0 : idx = 0;
6379 0 : if (argv_find(argv, argc, "med", &idx))
6380 0 : med = true;
6381 :
6382 : /* no flags means all of them! */
6383 0 : if (!aspath && !nexthop && !med) {
6384 0 : ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6385 : PEER_FLAG_AS_PATH_UNCHANGED);
6386 0 : ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6387 : PEER_FLAG_NEXTHOP_UNCHANGED);
6388 0 : ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6389 0 : PEER_FLAG_MED_UNCHANGED);
6390 : } else {
6391 0 : if (!aspath) {
6392 0 : if (peer_af_flag_check(peer, afi, safi,
6393 : PEER_FLAG_AS_PATH_UNCHANGED)) {
6394 0 : ret |= peer_af_flag_unset_vty(
6395 : vty, peer_str, afi, safi,
6396 : PEER_FLAG_AS_PATH_UNCHANGED);
6397 : }
6398 : } else
6399 0 : ret |= peer_af_flag_set_vty(
6400 : vty, peer_str, afi, safi,
6401 : PEER_FLAG_AS_PATH_UNCHANGED);
6402 :
6403 0 : if (!nexthop) {
6404 0 : if (peer_af_flag_check(peer, afi, safi,
6405 : PEER_FLAG_NEXTHOP_UNCHANGED)) {
6406 0 : ret |= peer_af_flag_unset_vty(
6407 : vty, peer_str, afi, safi,
6408 : PEER_FLAG_NEXTHOP_UNCHANGED);
6409 : }
6410 : } else
6411 0 : ret |= peer_af_flag_set_vty(
6412 : vty, peer_str, afi, safi,
6413 : PEER_FLAG_NEXTHOP_UNCHANGED);
6414 :
6415 0 : if (!med) {
6416 0 : if (peer_af_flag_check(peer, afi, safi,
6417 : PEER_FLAG_MED_UNCHANGED)) {
6418 0 : ret |= peer_af_flag_unset_vty(
6419 : vty, peer_str, afi, safi,
6420 : PEER_FLAG_MED_UNCHANGED);
6421 : }
6422 : } else
6423 0 : ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6424 : PEER_FLAG_MED_UNCHANGED);
6425 : }
6426 :
6427 : return ret;
6428 : }
6429 :
6430 : ALIAS_HIDDEN(
6431 : neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6432 : "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6433 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6434 : "BGP attribute is propagated unchanged to this neighbor\n"
6435 : "As-path attribute\n"
6436 : "Nexthop attribute\n"
6437 : "Med attribute\n")
6438 :
6439 0 : DEFUN (no_neighbor_attr_unchanged,
6440 : no_neighbor_attr_unchanged_cmd,
6441 : "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6442 : NO_STR
6443 : NEIGHBOR_STR
6444 : NEIGHBOR_ADDR_STR2
6445 : "BGP attribute is propagated unchanged to this neighbor\n"
6446 : "As-path attribute\n"
6447 : "Nexthop attribute\n"
6448 : "Med attribute\n")
6449 : {
6450 0 : int idx = 0;
6451 0 : char *peer_str = argv[2]->arg;
6452 0 : struct peer *peer;
6453 0 : bool aspath = false;
6454 0 : bool nexthop = false;
6455 0 : bool med = false;
6456 0 : afi_t afi = bgp_node_afi(vty);
6457 0 : safi_t safi = bgp_node_safi(vty);
6458 0 : int ret = 0;
6459 :
6460 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
6461 0 : if (!peer)
6462 : return CMD_WARNING_CONFIG_FAILED;
6463 :
6464 0 : if (argv_find(argv, argc, "as-path", &idx))
6465 0 : aspath = true;
6466 :
6467 0 : idx = 0;
6468 0 : if (argv_find(argv, argc, "next-hop", &idx))
6469 0 : nexthop = true;
6470 :
6471 0 : idx = 0;
6472 0 : if (argv_find(argv, argc, "med", &idx))
6473 0 : med = true;
6474 :
6475 0 : if (!aspath && !nexthop && !med) // no flags means all of them!
6476 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6477 : PEER_FLAG_AS_PATH_UNCHANGED)
6478 0 : | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6479 : PEER_FLAG_NEXTHOP_UNCHANGED)
6480 0 : | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6481 : PEER_FLAG_MED_UNCHANGED);
6482 :
6483 0 : if (aspath)
6484 0 : ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6485 : PEER_FLAG_AS_PATH_UNCHANGED);
6486 :
6487 0 : if (nexthop)
6488 0 : ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6489 : PEER_FLAG_NEXTHOP_UNCHANGED);
6490 :
6491 0 : if (med)
6492 0 : ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6493 : PEER_FLAG_MED_UNCHANGED);
6494 :
6495 : return ret;
6496 : }
6497 :
6498 : ALIAS_HIDDEN(
6499 : no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6500 : "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6501 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6502 : "BGP attribute is propagated unchanged to this neighbor\n"
6503 : "As-path attribute\n"
6504 : "Nexthop attribute\n"
6505 : "Med attribute\n")
6506 :
6507 : /* EBGP multihop configuration. */
6508 0 : static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6509 : const char *ttl_str)
6510 : {
6511 0 : struct peer *peer;
6512 0 : unsigned int ttl;
6513 :
6514 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
6515 0 : if (!peer)
6516 : return CMD_WARNING_CONFIG_FAILED;
6517 :
6518 0 : if (peer->conf_if)
6519 0 : return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6520 :
6521 0 : if (!ttl_str)
6522 : ttl = MAXTTL;
6523 : else
6524 0 : ttl = strtoul(ttl_str, NULL, 10);
6525 :
6526 0 : return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6527 : }
6528 :
6529 0 : static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6530 : {
6531 0 : struct peer *peer;
6532 :
6533 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
6534 0 : if (!peer)
6535 : return CMD_WARNING_CONFIG_FAILED;
6536 :
6537 0 : return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6538 : }
6539 :
6540 : /* neighbor ebgp-multihop. */
6541 0 : DEFUN (neighbor_ebgp_multihop,
6542 : neighbor_ebgp_multihop_cmd,
6543 : "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6544 : NEIGHBOR_STR
6545 : NEIGHBOR_ADDR_STR2
6546 : "Allow EBGP neighbors not on directly connected networks\n")
6547 : {
6548 0 : int idx_peer = 1;
6549 0 : return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6550 : }
6551 :
6552 0 : DEFUN (neighbor_ebgp_multihop_ttl,
6553 : neighbor_ebgp_multihop_ttl_cmd,
6554 : "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6555 : NEIGHBOR_STR
6556 : NEIGHBOR_ADDR_STR2
6557 : "Allow EBGP neighbors not on directly connected networks\n"
6558 : "maximum hop count\n")
6559 : {
6560 0 : int idx_peer = 1;
6561 0 : int idx_number = 3;
6562 0 : return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6563 0 : argv[idx_number]->arg);
6564 : }
6565 :
6566 0 : DEFUN (no_neighbor_ebgp_multihop,
6567 : no_neighbor_ebgp_multihop_cmd,
6568 : "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6569 : NO_STR
6570 : NEIGHBOR_STR
6571 : NEIGHBOR_ADDR_STR2
6572 : "Allow EBGP neighbors not on directly connected networks\n"
6573 : "maximum hop count\n")
6574 : {
6575 0 : int idx_peer = 2;
6576 0 : return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6577 : }
6578 :
6579 0 : DEFPY (neighbor_aigp,
6580 : neighbor_aigp_cmd,
6581 : "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor aigp",
6582 : NO_STR
6583 : NEIGHBOR_STR
6584 : NEIGHBOR_ADDR_STR2
6585 : "Enable send and receive of the AIGP attribute per neighbor\n")
6586 : {
6587 0 : struct peer *peer;
6588 :
6589 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
6590 0 : if (!peer)
6591 : return CMD_WARNING_CONFIG_FAILED;
6592 :
6593 0 : if (no)
6594 0 : return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AIGP);
6595 : else
6596 0 : return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AIGP);
6597 : }
6598 :
6599 0 : static uint8_t get_role_by_name(const char *role_str)
6600 : {
6601 0 : if (strncmp(role_str, "peer", 2) == 0)
6602 : return ROLE_PEER;
6603 0 : if (strncmp(role_str, "provider", 2) == 0)
6604 : return ROLE_PROVIDER;
6605 0 : if (strncmp(role_str, "customer", 2) == 0)
6606 : return ROLE_CUSTOMER;
6607 0 : if (strncmp(role_str, "rs-server", 4) == 0)
6608 : return ROLE_RS_SERVER;
6609 0 : if (strncmp(role_str, "rs-client", 4) == 0)
6610 0 : return ROLE_RS_CLIENT;
6611 : return ROLE_UNDEFINED;
6612 : }
6613 :
6614 0 : static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6615 : const char *role_str, bool strict_mode)
6616 : {
6617 0 : struct peer *peer;
6618 :
6619 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
6620 0 : if (!peer)
6621 : return CMD_WARNING_CONFIG_FAILED;
6622 0 : uint8_t role = get_role_by_name(role_str);
6623 :
6624 0 : if (role == ROLE_UNDEFINED)
6625 0 : return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6626 0 : return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6627 : }
6628 :
6629 0 : static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6630 : {
6631 0 : struct peer *peer;
6632 :
6633 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
6634 0 : if (!peer)
6635 : return CMD_WARNING_CONFIG_FAILED;
6636 0 : return bgp_vty_return(vty, peer_role_unset(peer));
6637 : }
6638 :
6639 0 : DEFPY(neighbor_role,
6640 : neighbor_role_cmd,
6641 : "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6642 : NEIGHBOR_STR
6643 : NEIGHBOR_ADDR_STR2
6644 : "Set session role\n"
6645 : ROLE_STR)
6646 : {
6647 0 : int idx_peer = 1;
6648 0 : int idx_role = 3;
6649 :
6650 0 : return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6651 : false);
6652 : }
6653 :
6654 0 : DEFPY(neighbor_role_strict,
6655 : neighbor_role_strict_cmd,
6656 : "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6657 : NEIGHBOR_STR
6658 : NEIGHBOR_ADDR_STR2
6659 : "Set session role\n"
6660 : ROLE_STR
6661 : "Use additional restriction on peer\n")
6662 : {
6663 0 : int idx_peer = 1;
6664 0 : int idx_role = 3;
6665 :
6666 0 : return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6667 : true);
6668 : }
6669 :
6670 0 : DEFPY(no_neighbor_role,
6671 : no_neighbor_role_cmd,
6672 : "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6673 : NO_STR
6674 : NEIGHBOR_STR
6675 : NEIGHBOR_ADDR_STR2
6676 : "Set session role\n"
6677 : ROLE_STR
6678 : "Use additional restriction on peer\n")
6679 : {
6680 0 : int idx_peer = 2;
6681 :
6682 0 : return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6683 : }
6684 :
6685 : /* disable-connected-check */
6686 0 : DEFUN (neighbor_disable_connected_check,
6687 : neighbor_disable_connected_check_cmd,
6688 : "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6689 : NEIGHBOR_STR
6690 : NEIGHBOR_ADDR_STR2
6691 : "one-hop away EBGP peer using loopback address\n"
6692 : "Enforce EBGP neighbors perform multihop\n")
6693 : {
6694 0 : int idx_peer = 1;
6695 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6696 : PEER_FLAG_DISABLE_CONNECTED_CHECK);
6697 : }
6698 :
6699 0 : DEFUN (no_neighbor_disable_connected_check,
6700 : no_neighbor_disable_connected_check_cmd,
6701 : "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6702 : NO_STR
6703 : NEIGHBOR_STR
6704 : NEIGHBOR_ADDR_STR2
6705 : "one-hop away EBGP peer using loopback address\n"
6706 : "Enforce EBGP neighbors perform multihop\n")
6707 : {
6708 0 : int idx_peer = 2;
6709 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6710 : PEER_FLAG_DISABLE_CONNECTED_CHECK);
6711 : }
6712 :
6713 : /* disable-link-bw-encoding-ieee */
6714 0 : DEFUN(neighbor_disable_link_bw_encoding_ieee,
6715 : neighbor_disable_link_bw_encoding_ieee_cmd,
6716 : "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6717 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6718 : "Disable IEEE floating-point encoding for extended community bandwidth\n")
6719 : {
6720 0 : int idx_peer = 1;
6721 :
6722 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6723 : PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6724 : }
6725 :
6726 0 : DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6727 : no_neighbor_disable_link_bw_encoding_ieee_cmd,
6728 : "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6729 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6730 : "Disable IEEE floating-point encoding for extended community bandwidth\n")
6731 : {
6732 0 : int idx_peer = 2;
6733 :
6734 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6735 : PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6736 : }
6737 :
6738 : /* extended-optional-parameters */
6739 0 : DEFUN(neighbor_extended_optional_parameters,
6740 : neighbor_extended_optional_parameters_cmd,
6741 : "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6742 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6743 : "Force the extended optional parameters format for OPEN messages\n")
6744 : {
6745 0 : int idx_peer = 1;
6746 :
6747 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6748 : PEER_FLAG_EXTENDED_OPT_PARAMS);
6749 : }
6750 :
6751 0 : DEFUN(no_neighbor_extended_optional_parameters,
6752 : no_neighbor_extended_optional_parameters_cmd,
6753 : "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6754 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6755 : "Force the extended optional parameters format for OPEN messages\n")
6756 : {
6757 0 : int idx_peer = 2;
6758 :
6759 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6760 : PEER_FLAG_EXTENDED_OPT_PARAMS);
6761 : }
6762 :
6763 : /* enforce-first-as */
6764 0 : DEFUN (neighbor_enforce_first_as,
6765 : neighbor_enforce_first_as_cmd,
6766 : "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6767 : NEIGHBOR_STR
6768 : NEIGHBOR_ADDR_STR2
6769 : "Enforce the first AS for EBGP routes\n")
6770 : {
6771 0 : int idx_peer = 1;
6772 :
6773 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6774 : PEER_FLAG_ENFORCE_FIRST_AS);
6775 : }
6776 :
6777 0 : DEFUN (no_neighbor_enforce_first_as,
6778 : no_neighbor_enforce_first_as_cmd,
6779 : "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6780 : NO_STR
6781 : NEIGHBOR_STR
6782 : NEIGHBOR_ADDR_STR2
6783 : "Enforce the first AS for EBGP routes\n")
6784 : {
6785 0 : int idx_peer = 2;
6786 :
6787 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6788 : PEER_FLAG_ENFORCE_FIRST_AS);
6789 : }
6790 :
6791 :
6792 0 : DEFUN (neighbor_description,
6793 : neighbor_description_cmd,
6794 : "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6795 : NEIGHBOR_STR
6796 : NEIGHBOR_ADDR_STR2
6797 : "Neighbor specific description\n"
6798 : "Up to 80 characters describing this neighbor\n")
6799 : {
6800 0 : int idx_peer = 1;
6801 0 : int idx_line = 3;
6802 0 : struct peer *peer;
6803 0 : char *str;
6804 :
6805 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6806 0 : if (!peer)
6807 : return CMD_WARNING_CONFIG_FAILED;
6808 :
6809 0 : str = argv_concat(argv, argc, idx_line);
6810 :
6811 0 : peer_description_set(peer, str);
6812 :
6813 0 : XFREE(MTYPE_TMP, str);
6814 :
6815 0 : return CMD_SUCCESS;
6816 : }
6817 :
6818 0 : DEFUN (no_neighbor_description,
6819 : no_neighbor_description_cmd,
6820 : "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6821 : NO_STR
6822 : NEIGHBOR_STR
6823 : NEIGHBOR_ADDR_STR2
6824 : "Neighbor specific description\n")
6825 : {
6826 0 : int idx_peer = 2;
6827 0 : struct peer *peer;
6828 :
6829 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6830 0 : if (!peer)
6831 : return CMD_WARNING_CONFIG_FAILED;
6832 :
6833 0 : peer_description_unset(peer);
6834 :
6835 0 : return CMD_SUCCESS;
6836 : }
6837 :
6838 : ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6839 : "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6840 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6841 : "Neighbor specific description\n"
6842 : "Up to 80 characters describing this neighbor\n")
6843 :
6844 : /* Neighbor update-source. */
6845 0 : static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6846 : const char *source_str)
6847 : {
6848 0 : struct peer *peer;
6849 0 : struct prefix p;
6850 0 : union sockunion su;
6851 :
6852 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
6853 0 : if (!peer)
6854 : return CMD_WARNING_CONFIG_FAILED;
6855 :
6856 0 : if (peer->conf_if)
6857 : return CMD_WARNING;
6858 :
6859 0 : if (source_str) {
6860 0 : if (str2sockunion(source_str, &su) == 0)
6861 0 : peer_update_source_addr_set(peer, &su);
6862 : else {
6863 0 : if (str2prefix(source_str, &p)) {
6864 0 : vty_out(vty,
6865 : "%% Invalid update-source, remove prefix length \n");
6866 0 : return CMD_WARNING_CONFIG_FAILED;
6867 : } else
6868 0 : peer_update_source_if_set(peer, source_str);
6869 : }
6870 : } else
6871 0 : peer_update_source_unset(peer);
6872 :
6873 : return CMD_SUCCESS;
6874 : }
6875 :
6876 : #define BGP_UPDATE_SOURCE_HELP_STR \
6877 : "IPv4 address\n" \
6878 : "IPv6 address\n" \
6879 : "Interface name (requires zebra to be running)\n"
6880 :
6881 0 : DEFUN (neighbor_update_source,
6882 : neighbor_update_source_cmd,
6883 : "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6884 : NEIGHBOR_STR
6885 : NEIGHBOR_ADDR_STR2
6886 : "Source of routing updates\n"
6887 : BGP_UPDATE_SOURCE_HELP_STR)
6888 : {
6889 0 : int idx_peer = 1;
6890 0 : int idx_peer_2 = 3;
6891 0 : return peer_update_source_vty(vty, argv[idx_peer]->arg,
6892 0 : argv[idx_peer_2]->arg);
6893 : }
6894 :
6895 0 : DEFUN (no_neighbor_update_source,
6896 : no_neighbor_update_source_cmd,
6897 : "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6898 : NO_STR
6899 : NEIGHBOR_STR
6900 : NEIGHBOR_ADDR_STR2
6901 : "Source of routing updates\n"
6902 : BGP_UPDATE_SOURCE_HELP_STR)
6903 : {
6904 0 : int idx_peer = 2;
6905 0 : return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6906 : }
6907 :
6908 0 : static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6909 : afi_t afi, safi_t safi,
6910 : const char *rmap, int set)
6911 : {
6912 0 : int ret;
6913 0 : struct peer *peer;
6914 0 : struct route_map *route_map = NULL;
6915 :
6916 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
6917 0 : if (!peer)
6918 : return CMD_WARNING_CONFIG_FAILED;
6919 :
6920 0 : if (set) {
6921 0 : if (rmap)
6922 0 : route_map = route_map_lookup_warn_noexist(vty, rmap);
6923 0 : ret = peer_default_originate_set(peer, afi, safi,
6924 : rmap, route_map);
6925 : } else
6926 0 : ret = peer_default_originate_unset(peer, afi, safi);
6927 :
6928 0 : return bgp_vty_return(vty, ret);
6929 : }
6930 :
6931 : /* neighbor default-originate. */
6932 0 : DEFUN (neighbor_default_originate,
6933 : neighbor_default_originate_cmd,
6934 : "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6935 : NEIGHBOR_STR
6936 : NEIGHBOR_ADDR_STR2
6937 : "Originate default route to this neighbor\n")
6938 : {
6939 0 : int idx_peer = 1;
6940 0 : return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6941 : bgp_node_afi(vty),
6942 : bgp_node_safi(vty), NULL, 1);
6943 : }
6944 :
6945 : ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6946 : "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6947 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6948 : "Originate default route to this neighbor\n")
6949 :
6950 0 : DEFUN (neighbor_default_originate_rmap,
6951 : neighbor_default_originate_rmap_cmd,
6952 : "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6953 : NEIGHBOR_STR
6954 : NEIGHBOR_ADDR_STR2
6955 : "Originate default route to this neighbor\n"
6956 : "Route-map to specify criteria to originate default\n"
6957 : "route-map name\n")
6958 : {
6959 0 : int idx_peer = 1;
6960 0 : int idx_word = 4;
6961 0 : return peer_default_originate_set_vty(
6962 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6963 0 : argv[idx_word]->arg, 1);
6964 : }
6965 :
6966 : ALIAS_HIDDEN(
6967 : neighbor_default_originate_rmap,
6968 : neighbor_default_originate_rmap_hidden_cmd,
6969 : "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6970 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6971 : "Originate default route to this neighbor\n"
6972 : "Route-map to specify criteria to originate default\n"
6973 : "route-map name\n")
6974 :
6975 0 : DEFUN (no_neighbor_default_originate,
6976 : no_neighbor_default_originate_cmd,
6977 : "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6978 : NO_STR
6979 : NEIGHBOR_STR
6980 : NEIGHBOR_ADDR_STR2
6981 : "Originate default route to this neighbor\n"
6982 : "Route-map to specify criteria to originate default\n"
6983 : "route-map name\n")
6984 : {
6985 0 : int idx_peer = 2;
6986 0 : return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6987 : bgp_node_afi(vty),
6988 : bgp_node_safi(vty), NULL, 0);
6989 : }
6990 :
6991 : ALIAS_HIDDEN(
6992 : no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6993 : "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6994 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6995 : "Originate default route to this neighbor\n"
6996 : "Route-map to specify criteria to originate default\n"
6997 : "route-map name\n")
6998 :
6999 :
7000 : /* Set neighbor's BGP port. */
7001 0 : static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
7002 : const char *port_str)
7003 : {
7004 0 : struct peer *peer;
7005 0 : uint16_t port;
7006 0 : struct servent *sp;
7007 :
7008 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7009 0 : if (!peer)
7010 : return CMD_WARNING_CONFIG_FAILED;
7011 :
7012 0 : if (!port_str) {
7013 0 : sp = getservbyname("bgp", "tcp");
7014 0 : port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
7015 : } else {
7016 0 : port = strtoul(port_str, NULL, 10);
7017 : }
7018 :
7019 0 : peer_port_set(peer, port);
7020 :
7021 0 : return CMD_SUCCESS;
7022 : }
7023 :
7024 : /* Set specified peer's BGP port. */
7025 0 : DEFUN (neighbor_port,
7026 : neighbor_port_cmd,
7027 : "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
7028 : NEIGHBOR_STR
7029 : NEIGHBOR_ADDR_STR2
7030 : "Neighbor's BGP port\n"
7031 : "TCP port number\n")
7032 : {
7033 0 : int idx_ip = 1;
7034 0 : int idx_number = 3;
7035 0 : return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
7036 0 : argv[idx_number]->arg);
7037 : }
7038 :
7039 0 : DEFUN (no_neighbor_port,
7040 : no_neighbor_port_cmd,
7041 : "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
7042 : NO_STR
7043 : NEIGHBOR_STR
7044 : NEIGHBOR_ADDR_STR2
7045 : "Neighbor's BGP port\n"
7046 : "TCP port number\n")
7047 : {
7048 0 : int idx_ip = 2;
7049 0 : return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
7050 : }
7051 :
7052 :
7053 : /* neighbor weight. */
7054 0 : static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7055 : safi_t safi, const char *weight_str)
7056 : {
7057 0 : int ret;
7058 0 : struct peer *peer;
7059 0 : unsigned long weight;
7060 :
7061 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7062 0 : if (!peer)
7063 : return CMD_WARNING_CONFIG_FAILED;
7064 :
7065 0 : weight = strtoul(weight_str, NULL, 10);
7066 :
7067 0 : ret = peer_weight_set(peer, afi, safi, weight);
7068 0 : return bgp_vty_return(vty, ret);
7069 : }
7070 :
7071 0 : static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7072 : safi_t safi)
7073 : {
7074 0 : int ret;
7075 0 : struct peer *peer;
7076 :
7077 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7078 0 : if (!peer)
7079 : return CMD_WARNING_CONFIG_FAILED;
7080 :
7081 0 : ret = peer_weight_unset(peer, afi, safi);
7082 0 : return bgp_vty_return(vty, ret);
7083 : }
7084 :
7085 0 : DEFUN (neighbor_weight,
7086 : neighbor_weight_cmd,
7087 : "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7088 : NEIGHBOR_STR
7089 : NEIGHBOR_ADDR_STR2
7090 : "Set default weight for routes from this neighbor\n"
7091 : "default weight\n")
7092 : {
7093 0 : int idx_peer = 1;
7094 0 : int idx_number = 3;
7095 0 : return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7096 0 : bgp_node_safi(vty), argv[idx_number]->arg);
7097 : }
7098 :
7099 : ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7100 : "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7101 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7102 : "Set default weight for routes from this neighbor\n"
7103 : "default weight\n")
7104 :
7105 0 : DEFUN (no_neighbor_weight,
7106 : no_neighbor_weight_cmd,
7107 : "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7108 : NO_STR
7109 : NEIGHBOR_STR
7110 : NEIGHBOR_ADDR_STR2
7111 : "Set default weight for routes from this neighbor\n"
7112 : "default weight\n")
7113 : {
7114 0 : int idx_peer = 2;
7115 0 : return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
7116 : bgp_node_afi(vty), bgp_node_safi(vty));
7117 : }
7118 :
7119 : ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7120 : "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7121 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7122 : "Set default weight for routes from this neighbor\n"
7123 : "default weight\n")
7124 :
7125 :
7126 : /* Override capability negotiation. */
7127 0 : DEFUN (neighbor_override_capability,
7128 : neighbor_override_capability_cmd,
7129 : "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7130 : NEIGHBOR_STR
7131 : NEIGHBOR_ADDR_STR2
7132 : "Override capability negotiation result\n")
7133 : {
7134 0 : int idx_peer = 1;
7135 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7136 : PEER_FLAG_OVERRIDE_CAPABILITY);
7137 : }
7138 :
7139 0 : DEFUN (no_neighbor_override_capability,
7140 : no_neighbor_override_capability_cmd,
7141 : "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7142 : NO_STR
7143 : NEIGHBOR_STR
7144 : NEIGHBOR_ADDR_STR2
7145 : "Override capability negotiation result\n")
7146 : {
7147 0 : int idx_peer = 2;
7148 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7149 : PEER_FLAG_OVERRIDE_CAPABILITY);
7150 : }
7151 :
7152 0 : DEFUN (neighbor_strict_capability,
7153 : neighbor_strict_capability_cmd,
7154 : "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7155 : NEIGHBOR_STR
7156 : NEIGHBOR_ADDR_STR2
7157 : "Strict capability negotiation match\n")
7158 : {
7159 0 : int idx_peer = 1;
7160 :
7161 0 : return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7162 : PEER_FLAG_STRICT_CAP_MATCH);
7163 : }
7164 :
7165 0 : DEFUN (no_neighbor_strict_capability,
7166 : no_neighbor_strict_capability_cmd,
7167 : "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7168 : NO_STR
7169 : NEIGHBOR_STR
7170 : NEIGHBOR_ADDR_STR2
7171 : "Strict capability negotiation match\n")
7172 : {
7173 0 : int idx_peer = 2;
7174 :
7175 0 : return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7176 : PEER_FLAG_STRICT_CAP_MATCH);
7177 : }
7178 :
7179 2 : static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7180 : const char *keep_str, const char *hold_str)
7181 : {
7182 2 : int ret;
7183 2 : struct peer *peer;
7184 2 : uint32_t keepalive;
7185 2 : uint32_t holdtime;
7186 :
7187 2 : peer = peer_and_group_lookup_vty(vty, ip_str);
7188 2 : if (!peer)
7189 : return CMD_WARNING_CONFIG_FAILED;
7190 :
7191 2 : keepalive = strtoul(keep_str, NULL, 10);
7192 2 : holdtime = strtoul(hold_str, NULL, 10);
7193 :
7194 2 : ret = peer_timers_set(peer, keepalive, holdtime);
7195 :
7196 2 : return bgp_vty_return(vty, ret);
7197 : }
7198 :
7199 0 : static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7200 : {
7201 0 : int ret;
7202 0 : struct peer *peer;
7203 :
7204 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7205 0 : if (!peer)
7206 : return CMD_WARNING_CONFIG_FAILED;
7207 :
7208 0 : ret = peer_timers_unset(peer);
7209 :
7210 0 : return bgp_vty_return(vty, ret);
7211 : }
7212 :
7213 2 : DEFUN (neighbor_timers,
7214 : neighbor_timers_cmd,
7215 : "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7216 : NEIGHBOR_STR
7217 : NEIGHBOR_ADDR_STR2
7218 : "BGP per neighbor timers\n"
7219 : "Keepalive interval\n"
7220 : "Holdtime\n")
7221 : {
7222 2 : int idx_peer = 1;
7223 2 : int idx_number = 3;
7224 2 : int idx_number_2 = 4;
7225 4 : return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7226 2 : argv[idx_number]->arg,
7227 2 : argv[idx_number_2]->arg);
7228 : }
7229 :
7230 0 : DEFUN (no_neighbor_timers,
7231 : no_neighbor_timers_cmd,
7232 : "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7233 : NO_STR
7234 : NEIGHBOR_STR
7235 : NEIGHBOR_ADDR_STR2
7236 : "BGP per neighbor timers\n"
7237 : "Keepalive interval\n"
7238 : "Holdtime\n")
7239 : {
7240 0 : int idx_peer = 2;
7241 0 : return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7242 : }
7243 :
7244 :
7245 0 : static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7246 : const char *time_str)
7247 : {
7248 0 : int ret;
7249 0 : struct peer *peer;
7250 0 : uint32_t connect;
7251 :
7252 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7253 0 : if (!peer)
7254 : return CMD_WARNING_CONFIG_FAILED;
7255 :
7256 0 : connect = strtoul(time_str, NULL, 10);
7257 :
7258 0 : ret = peer_timers_connect_set(peer, connect);
7259 :
7260 0 : return bgp_vty_return(vty, ret);
7261 : }
7262 :
7263 0 : static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7264 : {
7265 0 : int ret;
7266 0 : struct peer *peer;
7267 :
7268 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7269 0 : if (!peer)
7270 : return CMD_WARNING_CONFIG_FAILED;
7271 :
7272 0 : ret = peer_timers_connect_unset(peer);
7273 :
7274 0 : return bgp_vty_return(vty, ret);
7275 : }
7276 :
7277 0 : DEFUN (neighbor_timers_connect,
7278 : neighbor_timers_connect_cmd,
7279 : "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7280 : NEIGHBOR_STR
7281 : NEIGHBOR_ADDR_STR2
7282 : "BGP per neighbor timers\n"
7283 : "BGP connect timer\n"
7284 : "Connect timer\n")
7285 : {
7286 0 : int idx_peer = 1;
7287 0 : int idx_number = 4;
7288 0 : return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7289 0 : argv[idx_number]->arg);
7290 : }
7291 :
7292 0 : DEFUN (no_neighbor_timers_connect,
7293 : no_neighbor_timers_connect_cmd,
7294 : "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7295 : NO_STR
7296 : NEIGHBOR_STR
7297 : NEIGHBOR_ADDR_STR2
7298 : "BGP per neighbor timers\n"
7299 : "BGP connect timer\n"
7300 : "Connect timer\n")
7301 : {
7302 0 : int idx_peer = 2;
7303 0 : return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7304 : }
7305 :
7306 0 : DEFPY (neighbor_timers_delayopen,
7307 : neighbor_timers_delayopen_cmd,
7308 : "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7309 : NEIGHBOR_STR
7310 : NEIGHBOR_ADDR_STR2
7311 : "BGP per neighbor timers\n"
7312 : "RFC 4271 DelayOpenTimer\n"
7313 : "DelayOpenTime timer interval\n")
7314 : {
7315 0 : struct peer *peer;
7316 :
7317 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
7318 0 : if (!peer)
7319 : return CMD_WARNING_CONFIG_FAILED;
7320 :
7321 0 : if (!interval) {
7322 0 : if (peer_timers_delayopen_unset(peer))
7323 : return CMD_WARNING_CONFIG_FAILED;
7324 : } else {
7325 0 : if (peer_timers_delayopen_set(peer, interval))
7326 : return CMD_WARNING_CONFIG_FAILED;
7327 : }
7328 :
7329 : return CMD_SUCCESS;
7330 : }
7331 :
7332 0 : DEFPY (no_neighbor_timers_delayopen,
7333 : no_neighbor_timers_delayopen_cmd,
7334 : "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7335 : NO_STR
7336 : NEIGHBOR_STR
7337 : NEIGHBOR_ADDR_STR2
7338 : "BGP per neighbor timers\n"
7339 : "RFC 4271 DelayOpenTimer\n"
7340 : "DelayOpenTime timer interval\n")
7341 : {
7342 0 : struct peer *peer;
7343 :
7344 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
7345 0 : if (!peer)
7346 : return CMD_WARNING_CONFIG_FAILED;
7347 :
7348 0 : if (peer_timers_delayopen_unset(peer))
7349 : return CMD_WARNING_CONFIG_FAILED;
7350 :
7351 : return CMD_SUCCESS;
7352 : }
7353 :
7354 0 : static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7355 : const char *time_str, int set)
7356 : {
7357 0 : int ret;
7358 0 : struct peer *peer;
7359 0 : uint32_t routeadv = 0;
7360 :
7361 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7362 0 : if (!peer)
7363 : return CMD_WARNING_CONFIG_FAILED;
7364 :
7365 0 : if (time_str)
7366 0 : routeadv = strtoul(time_str, NULL, 10);
7367 :
7368 0 : if (set)
7369 0 : ret = peer_advertise_interval_set(peer, routeadv);
7370 : else
7371 0 : ret = peer_advertise_interval_unset(peer);
7372 :
7373 0 : return bgp_vty_return(vty, ret);
7374 : }
7375 :
7376 0 : DEFUN (neighbor_advertise_interval,
7377 : neighbor_advertise_interval_cmd,
7378 : "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7379 : NEIGHBOR_STR
7380 : NEIGHBOR_ADDR_STR2
7381 : "Minimum interval between sending BGP routing updates\n"
7382 : "time in seconds\n")
7383 : {
7384 0 : int idx_peer = 1;
7385 0 : int idx_number = 3;
7386 0 : return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7387 0 : argv[idx_number]->arg, 1);
7388 : }
7389 :
7390 0 : DEFUN (no_neighbor_advertise_interval,
7391 : no_neighbor_advertise_interval_cmd,
7392 : "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7393 : NO_STR
7394 : NEIGHBOR_STR
7395 : NEIGHBOR_ADDR_STR2
7396 : "Minimum interval between sending BGP routing updates\n"
7397 : "time in seconds\n")
7398 : {
7399 0 : int idx_peer = 2;
7400 0 : return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7401 : }
7402 :
7403 :
7404 : /* Time to wait before processing route-map updates */
7405 0 : DEFUN (bgp_set_route_map_delay_timer,
7406 : bgp_set_route_map_delay_timer_cmd,
7407 : "bgp route-map delay-timer (0-600)",
7408 : SET_STR
7409 : "BGP route-map delay timer\n"
7410 : "Time in secs to wait before processing route-map changes\n"
7411 : "0 disables the timer, no route updates happen when route-maps change\n")
7412 : {
7413 0 : int idx_number = 3;
7414 0 : uint32_t rmap_delay_timer;
7415 :
7416 0 : if (argv[idx_number]->arg) {
7417 0 : rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7418 0 : bm->rmap_update_timer = rmap_delay_timer;
7419 :
7420 : /* if the dynamic update handling is being disabled, and a timer
7421 : * is
7422 : * running, stop the timer and act as if the timer has already
7423 : * fired.
7424 : */
7425 0 : if (!rmap_delay_timer && bm->t_rmap_update) {
7426 0 : THREAD_OFF(bm->t_rmap_update);
7427 0 : thread_execute(bm->master, bgp_route_map_update_timer,
7428 : NULL, 0);
7429 : }
7430 0 : return CMD_SUCCESS;
7431 : } else {
7432 0 : vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7433 0 : return CMD_WARNING_CONFIG_FAILED;
7434 : }
7435 : }
7436 :
7437 0 : DEFUN (no_bgp_set_route_map_delay_timer,
7438 : no_bgp_set_route_map_delay_timer_cmd,
7439 : "no bgp route-map delay-timer [(0-600)]",
7440 : NO_STR
7441 : BGP_STR
7442 : "Default BGP route-map delay timer\n"
7443 : "Reset to default time to wait for processing route-map changes\n"
7444 : "0 disables the timer, no route updates happen when route-maps change\n")
7445 : {
7446 :
7447 0 : bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7448 :
7449 0 : return CMD_SUCCESS;
7450 : }
7451 :
7452 : /* neighbor interface */
7453 0 : static int peer_interface_vty(struct vty *vty, const char *ip_str,
7454 : const char *str)
7455 : {
7456 0 : struct peer *peer;
7457 :
7458 0 : peer = peer_lookup_vty(vty, ip_str);
7459 0 : if (!peer || peer->conf_if) {
7460 0 : vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7461 0 : return CMD_WARNING_CONFIG_FAILED;
7462 : }
7463 :
7464 0 : if (str)
7465 0 : peer_interface_set(peer, str);
7466 : else
7467 0 : peer_interface_unset(peer);
7468 :
7469 : return CMD_SUCCESS;
7470 : }
7471 :
7472 0 : DEFUN (neighbor_interface,
7473 : neighbor_interface_cmd,
7474 : "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7475 : NEIGHBOR_STR
7476 : NEIGHBOR_ADDR_STR
7477 : "Interface\n"
7478 : "Interface name\n")
7479 : {
7480 0 : int idx_ip = 1;
7481 0 : int idx_word = 3;
7482 :
7483 0 : return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7484 : }
7485 :
7486 0 : DEFUN (no_neighbor_interface,
7487 : no_neighbor_interface_cmd,
7488 : "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7489 : NO_STR
7490 : NEIGHBOR_STR
7491 : NEIGHBOR_ADDR_STR
7492 : "Interface\n"
7493 : "Interface name\n")
7494 : {
7495 0 : int idx_peer = 2;
7496 :
7497 0 : return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7498 : }
7499 :
7500 0 : DEFUN (neighbor_distribute_list,
7501 : neighbor_distribute_list_cmd,
7502 : "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7503 : NEIGHBOR_STR
7504 : NEIGHBOR_ADDR_STR2
7505 : "Filter updates to/from this neighbor\n"
7506 : "IP Access-list name\n"
7507 : "Filter incoming updates\n"
7508 : "Filter outgoing updates\n")
7509 : {
7510 0 : int idx_peer = 1;
7511 0 : int idx_acl = 3;
7512 0 : int direct, ret;
7513 0 : struct peer *peer;
7514 :
7515 0 : const char *pstr = argv[idx_peer]->arg;
7516 0 : const char *acl = argv[idx_acl]->arg;
7517 0 : const char *inout = argv[argc - 1]->text;
7518 :
7519 0 : peer = peer_and_group_lookup_vty(vty, pstr);
7520 0 : if (!peer)
7521 : return CMD_WARNING_CONFIG_FAILED;
7522 :
7523 : /* Check filter direction. */
7524 0 : direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7525 0 : ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7526 : direct, acl);
7527 :
7528 0 : return bgp_vty_return(vty, ret);
7529 : }
7530 :
7531 : ALIAS_HIDDEN(
7532 : neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7533 : "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7534 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7535 : "Filter updates to/from this neighbor\n"
7536 : "IP Access-list name\n"
7537 : "Filter incoming updates\n"
7538 : "Filter outgoing updates\n")
7539 :
7540 0 : DEFUN (no_neighbor_distribute_list,
7541 : no_neighbor_distribute_list_cmd,
7542 : "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7543 : NO_STR
7544 : NEIGHBOR_STR
7545 : NEIGHBOR_ADDR_STR2
7546 : "Filter updates to/from this neighbor\n"
7547 : "IP Access-list name\n"
7548 : "Filter incoming updates\n"
7549 : "Filter outgoing updates\n")
7550 : {
7551 0 : int idx_peer = 2;
7552 0 : int direct, ret;
7553 0 : struct peer *peer;
7554 :
7555 0 : const char *pstr = argv[idx_peer]->arg;
7556 0 : const char *inout = argv[argc - 1]->text;
7557 :
7558 0 : peer = peer_and_group_lookup_vty(vty, pstr);
7559 0 : if (!peer)
7560 : return CMD_WARNING_CONFIG_FAILED;
7561 :
7562 : /* Check filter direction. */
7563 0 : direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7564 0 : ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7565 : direct);
7566 :
7567 0 : return bgp_vty_return(vty, ret);
7568 : }
7569 :
7570 : ALIAS_HIDDEN(
7571 : no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7572 : "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7573 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7574 : "Filter updates to/from this neighbor\n"
7575 : "IP Access-list name\n"
7576 : "Filter incoming updates\n"
7577 : "Filter outgoing updates\n")
7578 :
7579 : /* Set prefix list to the peer. */
7580 0 : static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7581 : afi_t afi, safi_t safi,
7582 : const char *name_str,
7583 : const char *direct_str)
7584 : {
7585 0 : int ret;
7586 0 : int direct = FILTER_IN;
7587 0 : struct peer *peer;
7588 :
7589 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7590 0 : if (!peer)
7591 : return CMD_WARNING_CONFIG_FAILED;
7592 :
7593 : /* Check filter direction. */
7594 0 : if (strncmp(direct_str, "i", 1) == 0)
7595 : direct = FILTER_IN;
7596 0 : else if (strncmp(direct_str, "o", 1) == 0)
7597 0 : direct = FILTER_OUT;
7598 :
7599 0 : ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7600 :
7601 0 : return bgp_vty_return(vty, ret);
7602 : }
7603 :
7604 0 : static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7605 : afi_t afi, safi_t safi,
7606 : const char *direct_str)
7607 : {
7608 0 : int ret;
7609 0 : struct peer *peer;
7610 0 : int direct = FILTER_IN;
7611 :
7612 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7613 0 : if (!peer)
7614 : return CMD_WARNING_CONFIG_FAILED;
7615 :
7616 : /* Check filter direction. */
7617 0 : if (strncmp(direct_str, "i", 1) == 0)
7618 : direct = FILTER_IN;
7619 0 : else if (strncmp(direct_str, "o", 1) == 0)
7620 0 : direct = FILTER_OUT;
7621 :
7622 0 : ret = peer_prefix_list_unset(peer, afi, safi, direct);
7623 :
7624 0 : return bgp_vty_return(vty, ret);
7625 : }
7626 :
7627 0 : DEFUN (neighbor_prefix_list,
7628 : neighbor_prefix_list_cmd,
7629 : "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7630 : NEIGHBOR_STR
7631 : NEIGHBOR_ADDR_STR2
7632 : "Filter updates to/from this neighbor\n"
7633 : "Name of a prefix list\n"
7634 : "Filter incoming updates\n"
7635 : "Filter outgoing updates\n")
7636 : {
7637 0 : int idx_peer = 1;
7638 0 : int idx_word = 3;
7639 0 : int idx_in_out = 4;
7640 0 : return peer_prefix_list_set_vty(
7641 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7642 0 : argv[idx_word]->arg, argv[idx_in_out]->arg);
7643 : }
7644 :
7645 : ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7646 : "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7647 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7648 : "Filter updates to/from this neighbor\n"
7649 : "Name of a prefix list\n"
7650 : "Filter incoming updates\n"
7651 : "Filter outgoing updates\n")
7652 :
7653 0 : DEFUN (no_neighbor_prefix_list,
7654 : no_neighbor_prefix_list_cmd,
7655 : "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7656 : NO_STR
7657 : NEIGHBOR_STR
7658 : NEIGHBOR_ADDR_STR2
7659 : "Filter updates to/from this neighbor\n"
7660 : "Name of a prefix list\n"
7661 : "Filter incoming updates\n"
7662 : "Filter outgoing updates\n")
7663 : {
7664 0 : int idx_peer = 2;
7665 0 : int idx_in_out = 5;
7666 0 : return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7667 : bgp_node_afi(vty), bgp_node_safi(vty),
7668 0 : argv[idx_in_out]->arg);
7669 : }
7670 :
7671 : ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7672 : "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7673 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7674 : "Filter updates to/from this neighbor\n"
7675 : "Name of a prefix list\n"
7676 : "Filter incoming updates\n"
7677 : "Filter outgoing updates\n")
7678 :
7679 0 : static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7680 : safi_t safi, const char *name_str,
7681 : const char *direct_str)
7682 : {
7683 0 : int ret;
7684 0 : struct peer *peer;
7685 0 : int direct = FILTER_IN;
7686 :
7687 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7688 0 : if (!peer)
7689 : return CMD_WARNING_CONFIG_FAILED;
7690 :
7691 : /* Check filter direction. */
7692 0 : if (strncmp(direct_str, "i", 1) == 0)
7693 : direct = FILTER_IN;
7694 0 : else if (strncmp(direct_str, "o", 1) == 0)
7695 0 : direct = FILTER_OUT;
7696 :
7697 0 : ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7698 :
7699 0 : return bgp_vty_return(vty, ret);
7700 : }
7701 :
7702 0 : static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7703 : safi_t safi, const char *direct_str)
7704 : {
7705 0 : int ret;
7706 0 : struct peer *peer;
7707 0 : int direct = FILTER_IN;
7708 :
7709 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7710 0 : if (!peer)
7711 : return CMD_WARNING_CONFIG_FAILED;
7712 :
7713 : /* Check filter direction. */
7714 0 : if (strncmp(direct_str, "i", 1) == 0)
7715 : direct = FILTER_IN;
7716 0 : else if (strncmp(direct_str, "o", 1) == 0)
7717 0 : direct = FILTER_OUT;
7718 :
7719 0 : ret = peer_aslist_unset(peer, afi, safi, direct);
7720 :
7721 0 : return bgp_vty_return(vty, ret);
7722 : }
7723 :
7724 0 : DEFUN (neighbor_filter_list,
7725 : neighbor_filter_list_cmd,
7726 : "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7727 : NEIGHBOR_STR
7728 : NEIGHBOR_ADDR_STR2
7729 : "Establish BGP filters\n"
7730 : "AS path access-list name\n"
7731 : "Filter incoming routes\n"
7732 : "Filter outgoing routes\n")
7733 : {
7734 0 : int idx_peer = 1;
7735 0 : int idx_word = 3;
7736 0 : int idx_in_out = 4;
7737 0 : return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7738 0 : bgp_node_safi(vty), argv[idx_word]->arg,
7739 0 : argv[idx_in_out]->arg);
7740 : }
7741 :
7742 : ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7743 : "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7744 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7745 : "Establish BGP filters\n"
7746 : "AS path access-list name\n"
7747 : "Filter incoming routes\n"
7748 : "Filter outgoing routes\n")
7749 :
7750 0 : DEFUN (no_neighbor_filter_list,
7751 : no_neighbor_filter_list_cmd,
7752 : "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7753 : NO_STR
7754 : NEIGHBOR_STR
7755 : NEIGHBOR_ADDR_STR2
7756 : "Establish BGP filters\n"
7757 : "AS path access-list name\n"
7758 : "Filter incoming routes\n"
7759 : "Filter outgoing routes\n")
7760 : {
7761 0 : int idx_peer = 2;
7762 0 : int idx_in_out = 5;
7763 0 : return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7764 : bgp_node_afi(vty), bgp_node_safi(vty),
7765 0 : argv[idx_in_out]->arg);
7766 : }
7767 :
7768 : ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7769 : "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7770 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7771 : "Establish BGP filters\n"
7772 : "AS path access-list name\n"
7773 : "Filter incoming routes\n"
7774 : "Filter outgoing routes\n")
7775 :
7776 : /* Set advertise-map to the peer. */
7777 0 : static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7778 : afi_t afi, safi_t safi,
7779 : const char *advertise_str,
7780 : const char *condition_str, bool condition,
7781 : bool set)
7782 : {
7783 0 : int ret = CMD_WARNING_CONFIG_FAILED;
7784 0 : struct peer *peer;
7785 0 : struct route_map *advertise_map;
7786 0 : struct route_map *condition_map;
7787 :
7788 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7789 0 : if (!peer)
7790 : return ret;
7791 :
7792 0 : condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7793 0 : advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7794 :
7795 0 : if (set)
7796 0 : ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7797 : advertise_map, condition_str,
7798 : condition_map, condition);
7799 : else
7800 0 : ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7801 : advertise_map, condition_str,
7802 : condition_map, condition);
7803 :
7804 0 : return bgp_vty_return(vty, ret);
7805 : }
7806 :
7807 0 : DEFPY (bgp_condadv_period,
7808 : bgp_condadv_period_cmd,
7809 : "[no$no] bgp conditional-advertisement timer (5-240)$period",
7810 : NO_STR
7811 : BGP_STR
7812 : "Conditional advertisement settings\n"
7813 : "Set period to rescan BGP table to check if condition is met\n"
7814 : "Period between BGP table scans, in seconds; default 60\n")
7815 : {
7816 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
7817 :
7818 0 : bgp->condition_check_period =
7819 : no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7820 :
7821 0 : return CMD_SUCCESS;
7822 : }
7823 :
7824 0 : DEFPY (neighbor_advertise_map,
7825 : neighbor_advertise_map_cmd,
7826 : "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
7827 : NO_STR
7828 : NEIGHBOR_STR
7829 : NEIGHBOR_ADDR_STR2
7830 : "Route-map to conditionally advertise routes\n"
7831 : "Name of advertise map\n"
7832 : "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7833 : "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7834 : "Name of the exist or non exist map\n")
7835 : {
7836 0 : bool condition = CONDITION_EXIST;
7837 :
7838 0 : if (!strcmp(exist, "non-exist-map"))
7839 0 : condition = CONDITION_NON_EXIST;
7840 :
7841 0 : return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7842 : bgp_node_safi(vty), advertise_str,
7843 : condition_str, condition, !no);
7844 : }
7845 :
7846 : ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7847 : "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
7848 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7849 : "Route-map to conditionally advertise routes\n"
7850 : "Name of advertise map\n"
7851 : "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7852 : "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7853 : "Name of the exist or non exist map\n")
7854 :
7855 : /* Set route-map to the peer. */
7856 0 : static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7857 : afi_t afi, safi_t safi, const char *name_str,
7858 : const char *direct_str)
7859 : {
7860 0 : int ret;
7861 0 : struct peer *peer;
7862 0 : int direct = RMAP_IN;
7863 0 : struct route_map *route_map;
7864 :
7865 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7866 0 : if (!peer)
7867 : return CMD_WARNING_CONFIG_FAILED;
7868 :
7869 : /* Check filter direction. */
7870 0 : if (strncmp(direct_str, "in", 2) == 0)
7871 : direct = RMAP_IN;
7872 0 : else if (strncmp(direct_str, "o", 1) == 0)
7873 0 : direct = RMAP_OUT;
7874 :
7875 0 : route_map = route_map_lookup_warn_noexist(vty, name_str);
7876 0 : ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7877 :
7878 0 : return bgp_vty_return(vty, ret);
7879 : }
7880 :
7881 0 : static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7882 : afi_t afi, safi_t safi,
7883 : const char *direct_str)
7884 : {
7885 0 : int ret;
7886 0 : struct peer *peer;
7887 0 : int direct = RMAP_IN;
7888 :
7889 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7890 0 : if (!peer)
7891 : return CMD_WARNING_CONFIG_FAILED;
7892 :
7893 : /* Check filter direction. */
7894 0 : if (strncmp(direct_str, "in", 2) == 0)
7895 : direct = RMAP_IN;
7896 0 : else if (strncmp(direct_str, "o", 1) == 0)
7897 0 : direct = RMAP_OUT;
7898 :
7899 0 : ret = peer_route_map_unset(peer, afi, safi, direct);
7900 :
7901 0 : return bgp_vty_return(vty, ret);
7902 : }
7903 :
7904 0 : DEFUN (neighbor_route_map,
7905 : neighbor_route_map_cmd,
7906 : "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7907 : NEIGHBOR_STR
7908 : NEIGHBOR_ADDR_STR2
7909 : "Apply route map to neighbor\n"
7910 : "Name of route map\n"
7911 : "Apply map to incoming routes\n"
7912 : "Apply map to outbound routes\n")
7913 : {
7914 0 : int idx_peer = 1;
7915 0 : int idx_word = 3;
7916 0 : int idx_in_out = 4;
7917 0 : return peer_route_map_set_vty(
7918 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7919 0 : argv[idx_word]->arg, argv[idx_in_out]->arg);
7920 : }
7921 :
7922 : ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7923 : "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7924 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7925 : "Apply route map to neighbor\n"
7926 : "Name of route map\n"
7927 : "Apply map to incoming routes\n"
7928 : "Apply map to outbound routes\n")
7929 :
7930 0 : DEFUN (no_neighbor_route_map,
7931 : no_neighbor_route_map_cmd,
7932 : "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7933 : NO_STR
7934 : NEIGHBOR_STR
7935 : NEIGHBOR_ADDR_STR2
7936 : "Apply route map to neighbor\n"
7937 : "Name of route map\n"
7938 : "Apply map to incoming routes\n"
7939 : "Apply map to outbound routes\n")
7940 : {
7941 0 : int idx_peer = 2;
7942 0 : int idx_in_out = 5;
7943 0 : return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7944 : bgp_node_afi(vty), bgp_node_safi(vty),
7945 0 : argv[idx_in_out]->arg);
7946 : }
7947 :
7948 : ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7949 : "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7950 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7951 : "Apply route map to neighbor\n"
7952 : "Name of route map\n"
7953 : "Apply map to incoming routes\n"
7954 : "Apply map to outbound routes\n")
7955 :
7956 : /* Set unsuppress-map to the peer. */
7957 0 : static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7958 : afi_t afi, safi_t safi,
7959 : const char *name_str)
7960 : {
7961 0 : int ret;
7962 0 : struct peer *peer;
7963 0 : struct route_map *route_map;
7964 :
7965 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7966 0 : if (!peer)
7967 : return CMD_WARNING_CONFIG_FAILED;
7968 :
7969 0 : route_map = route_map_lookup_warn_noexist(vty, name_str);
7970 0 : ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7971 :
7972 0 : return bgp_vty_return(vty, ret);
7973 : }
7974 :
7975 : /* Unset route-map from the peer. */
7976 0 : static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7977 : afi_t afi, safi_t safi)
7978 : {
7979 0 : int ret;
7980 0 : struct peer *peer;
7981 :
7982 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
7983 0 : if (!peer)
7984 : return CMD_WARNING_CONFIG_FAILED;
7985 :
7986 0 : ret = peer_unsuppress_map_unset(peer, afi, safi);
7987 :
7988 0 : return bgp_vty_return(vty, ret);
7989 : }
7990 :
7991 0 : DEFUN (neighbor_unsuppress_map,
7992 : neighbor_unsuppress_map_cmd,
7993 : "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7994 : NEIGHBOR_STR
7995 : NEIGHBOR_ADDR_STR2
7996 : "Route-map to selectively unsuppress suppressed routes\n"
7997 : "Name of route map\n")
7998 : {
7999 0 : int idx_peer = 1;
8000 0 : int idx_word = 3;
8001 0 : return peer_unsuppress_map_set_vty(
8002 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8003 0 : argv[idx_word]->arg);
8004 : }
8005 :
8006 : ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8007 : "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8008 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8009 : "Route-map to selectively unsuppress suppressed routes\n"
8010 : "Name of route map\n")
8011 :
8012 0 : DEFUN (no_neighbor_unsuppress_map,
8013 : no_neighbor_unsuppress_map_cmd,
8014 : "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8015 : NO_STR
8016 : NEIGHBOR_STR
8017 : NEIGHBOR_ADDR_STR2
8018 : "Route-map to selectively unsuppress suppressed routes\n"
8019 : "Name of route map\n")
8020 : {
8021 0 : int idx_peer = 2;
8022 0 : return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8023 : bgp_node_afi(vty),
8024 : bgp_node_safi(vty));
8025 : }
8026 :
8027 : ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8028 : "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8029 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8030 : "Route-map to selectively unsuppress suppressed routes\n"
8031 : "Name of route map\n")
8032 :
8033 0 : static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
8034 : afi_t afi, safi_t safi,
8035 : const char *num_str,
8036 : const char *threshold_str, int warning,
8037 : const char *restart_str,
8038 : const char *force_str)
8039 : {
8040 0 : int ret;
8041 0 : struct peer *peer;
8042 0 : uint32_t max;
8043 0 : uint8_t threshold;
8044 0 : uint16_t restart;
8045 :
8046 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
8047 0 : if (!peer)
8048 : return CMD_WARNING_CONFIG_FAILED;
8049 :
8050 0 : max = strtoul(num_str, NULL, 10);
8051 0 : if (threshold_str)
8052 0 : threshold = atoi(threshold_str);
8053 : else
8054 : threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
8055 :
8056 0 : if (restart_str)
8057 0 : restart = atoi(restart_str);
8058 : else
8059 : restart = 0;
8060 :
8061 0 : ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
8062 : restart, force_str ? true : false);
8063 :
8064 0 : return bgp_vty_return(vty, ret);
8065 : }
8066 :
8067 0 : static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
8068 : afi_t afi, safi_t safi)
8069 : {
8070 0 : int ret;
8071 0 : struct peer *peer;
8072 :
8073 0 : peer = peer_and_group_lookup_vty(vty, ip_str);
8074 0 : if (!peer)
8075 : return CMD_WARNING_CONFIG_FAILED;
8076 :
8077 0 : ret = peer_maximum_prefix_unset(peer, afi, safi);
8078 :
8079 0 : return bgp_vty_return(vty, ret);
8080 : }
8081 :
8082 : /* Maximum number of prefix to be sent to the neighbor. */
8083 0 : DEFUN(neighbor_maximum_prefix_out,
8084 : neighbor_maximum_prefix_out_cmd,
8085 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8086 : NEIGHBOR_STR
8087 : NEIGHBOR_ADDR_STR2
8088 : "Maximum number of prefixes to be sent to this peer\n"
8089 : "Maximum no. of prefix limit\n")
8090 : {
8091 0 : int ret;
8092 0 : int idx_peer = 1;
8093 0 : int idx_number = 3;
8094 0 : struct peer *peer;
8095 0 : uint32_t max;
8096 0 : afi_t afi = bgp_node_afi(vty);
8097 0 : safi_t safi = bgp_node_safi(vty);
8098 :
8099 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8100 0 : if (!peer)
8101 : return CMD_WARNING_CONFIG_FAILED;
8102 :
8103 0 : max = strtoul(argv[idx_number]->arg, NULL, 10);
8104 :
8105 0 : ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
8106 :
8107 0 : return bgp_vty_return(vty, ret);
8108 : }
8109 :
8110 0 : DEFUN(no_neighbor_maximum_prefix_out,
8111 : no_neighbor_maximum_prefix_out_cmd,
8112 : "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
8113 : NO_STR
8114 : NEIGHBOR_STR
8115 : NEIGHBOR_ADDR_STR2
8116 : "Maximum number of prefixes to be sent to this peer\n"
8117 : "Maximum no. of prefix limit\n")
8118 : {
8119 0 : int ret;
8120 0 : int idx_peer = 2;
8121 0 : struct peer *peer;
8122 0 : afi_t afi = bgp_node_afi(vty);
8123 0 : safi_t safi = bgp_node_safi(vty);
8124 :
8125 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8126 0 : if (!peer)
8127 : return CMD_WARNING_CONFIG_FAILED;
8128 :
8129 0 : ret = peer_maximum_prefix_out_unset(peer, afi, safi);
8130 :
8131 0 : return bgp_vty_return(vty, ret);
8132 : }
8133 :
8134 : /* Maximum number of prefix configuration. Prefix count is different
8135 : for each peer configuration. So this configuration can be set for
8136 : each peer configuration. */
8137 0 : DEFUN (neighbor_maximum_prefix,
8138 : neighbor_maximum_prefix_cmd,
8139 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8140 : NEIGHBOR_STR
8141 : NEIGHBOR_ADDR_STR2
8142 : "Maximum number of prefix accept from this peer\n"
8143 : "maximum no. of prefix limit\n"
8144 : "Force checking all received routes not only accepted\n")
8145 : {
8146 0 : int idx_peer = 1;
8147 0 : int idx_number = 3;
8148 0 : int idx_force = 0;
8149 0 : char *force = NULL;
8150 :
8151 0 : if (argv_find(argv, argc, "force", &idx_force))
8152 0 : force = argv[idx_force]->arg;
8153 :
8154 0 : return peer_maximum_prefix_set_vty(
8155 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8156 0 : argv[idx_number]->arg, NULL, 0, NULL, force);
8157 : }
8158 :
8159 : ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8160 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8161 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8162 : "Maximum number of prefix accept from this peer\n"
8163 : "maximum no. of prefix limit\n"
8164 : "Force checking all received routes not only accepted\n")
8165 :
8166 0 : DEFUN (neighbor_maximum_prefix_threshold,
8167 : neighbor_maximum_prefix_threshold_cmd,
8168 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8169 : NEIGHBOR_STR
8170 : NEIGHBOR_ADDR_STR2
8171 : "Maximum number of prefix accept from this peer\n"
8172 : "maximum no. of prefix limit\n"
8173 : "Threshold value (%) at which to generate a warning msg\n"
8174 : "Force checking all received routes not only accepted\n")
8175 : {
8176 0 : int idx_peer = 1;
8177 0 : int idx_number = 3;
8178 0 : int idx_number_2 = 4;
8179 0 : int idx_force = 0;
8180 0 : char *force = NULL;
8181 :
8182 0 : if (argv_find(argv, argc, "force", &idx_force))
8183 0 : force = argv[idx_force]->arg;
8184 :
8185 0 : return peer_maximum_prefix_set_vty(
8186 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8187 0 : argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8188 : }
8189 :
8190 : ALIAS_HIDDEN(
8191 : neighbor_maximum_prefix_threshold,
8192 : neighbor_maximum_prefix_threshold_hidden_cmd,
8193 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8194 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8195 : "Maximum number of prefix accept from this peer\n"
8196 : "maximum no. of prefix limit\n"
8197 : "Threshold value (%) at which to generate a warning msg\n"
8198 : "Force checking all received routes not only accepted\n")
8199 :
8200 0 : DEFUN (neighbor_maximum_prefix_warning,
8201 : neighbor_maximum_prefix_warning_cmd,
8202 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8203 : NEIGHBOR_STR
8204 : NEIGHBOR_ADDR_STR2
8205 : "Maximum number of prefix accept from this peer\n"
8206 : "maximum no. of prefix limit\n"
8207 : "Only give warning message when limit is exceeded\n"
8208 : "Force checking all received routes not only accepted\n")
8209 : {
8210 0 : int idx_peer = 1;
8211 0 : int idx_number = 3;
8212 0 : int idx_force = 0;
8213 0 : char *force = NULL;
8214 :
8215 0 : if (argv_find(argv, argc, "force", &idx_force))
8216 0 : force = argv[idx_force]->arg;
8217 :
8218 0 : return peer_maximum_prefix_set_vty(
8219 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8220 0 : argv[idx_number]->arg, NULL, 1, NULL, force);
8221 : }
8222 :
8223 : ALIAS_HIDDEN(
8224 : neighbor_maximum_prefix_warning,
8225 : neighbor_maximum_prefix_warning_hidden_cmd,
8226 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8227 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8228 : "Maximum number of prefix accept from this peer\n"
8229 : "maximum no. of prefix limit\n"
8230 : "Only give warning message when limit is exceeded\n"
8231 : "Force checking all received routes not only accepted\n")
8232 :
8233 0 : DEFUN (neighbor_maximum_prefix_threshold_warning,
8234 : neighbor_maximum_prefix_threshold_warning_cmd,
8235 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8236 : NEIGHBOR_STR
8237 : NEIGHBOR_ADDR_STR2
8238 : "Maximum number of prefix accept from this peer\n"
8239 : "maximum no. of prefix limit\n"
8240 : "Threshold value (%) at which to generate a warning msg\n"
8241 : "Only give warning message when limit is exceeded\n"
8242 : "Force checking all received routes not only accepted\n")
8243 : {
8244 0 : int idx_peer = 1;
8245 0 : int idx_number = 3;
8246 0 : int idx_number_2 = 4;
8247 0 : int idx_force = 0;
8248 0 : char *force = NULL;
8249 :
8250 0 : if (argv_find(argv, argc, "force", &idx_force))
8251 0 : force = argv[idx_force]->arg;
8252 :
8253 0 : return peer_maximum_prefix_set_vty(
8254 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8255 0 : argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8256 : }
8257 :
8258 : ALIAS_HIDDEN(
8259 : neighbor_maximum_prefix_threshold_warning,
8260 : neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8261 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8262 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8263 : "Maximum number of prefix accept from this peer\n"
8264 : "maximum no. of prefix limit\n"
8265 : "Threshold value (%) at which to generate a warning msg\n"
8266 : "Only give warning message when limit is exceeded\n"
8267 : "Force checking all received routes not only accepted\n")
8268 :
8269 0 : DEFUN (neighbor_maximum_prefix_restart,
8270 : neighbor_maximum_prefix_restart_cmd,
8271 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8272 : NEIGHBOR_STR
8273 : NEIGHBOR_ADDR_STR2
8274 : "Maximum number of prefix accept from this peer\n"
8275 : "maximum no. of prefix limit\n"
8276 : "Restart bgp connection after limit is exceeded\n"
8277 : "Restart interval in minutes\n"
8278 : "Force checking all received routes not only accepted\n")
8279 : {
8280 0 : int idx_peer = 1;
8281 0 : int idx_number = 3;
8282 0 : int idx_number_2 = 5;
8283 0 : int idx_force = 0;
8284 0 : char *force = NULL;
8285 :
8286 0 : if (argv_find(argv, argc, "force", &idx_force))
8287 0 : force = argv[idx_force]->arg;
8288 :
8289 0 : return peer_maximum_prefix_set_vty(
8290 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8291 0 : argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8292 : }
8293 :
8294 : ALIAS_HIDDEN(
8295 : neighbor_maximum_prefix_restart,
8296 : neighbor_maximum_prefix_restart_hidden_cmd,
8297 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8298 : NEIGHBOR_STR 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"
8302 : "Restart interval in minutes\n"
8303 : "Force checking all received routes not only accepted\n")
8304 :
8305 0 : DEFUN (neighbor_maximum_prefix_threshold_restart,
8306 : neighbor_maximum_prefix_threshold_restart_cmd,
8307 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8308 : NEIGHBOR_STR
8309 : NEIGHBOR_ADDR_STR2
8310 : "Maximum number of prefixes to accept from this peer\n"
8311 : "maximum no. of prefix limit\n"
8312 : "Threshold value (%) at which to generate a warning msg\n"
8313 : "Restart bgp connection after limit is exceeded\n"
8314 : "Restart interval in minutes\n"
8315 : "Force checking all received routes not only accepted\n")
8316 : {
8317 0 : int idx_peer = 1;
8318 0 : int idx_number = 3;
8319 0 : int idx_number_2 = 4;
8320 0 : int idx_number_3 = 6;
8321 0 : int idx_force = 0;
8322 0 : char *force = NULL;
8323 :
8324 0 : if (argv_find(argv, argc, "force", &idx_force))
8325 0 : force = argv[idx_force]->arg;
8326 :
8327 0 : return peer_maximum_prefix_set_vty(
8328 0 : vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8329 0 : argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8330 0 : argv[idx_number_3]->arg, force);
8331 : }
8332 :
8333 : ALIAS_HIDDEN(
8334 : neighbor_maximum_prefix_threshold_restart,
8335 : neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8336 : "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8337 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8338 : "Maximum number of prefixes to accept from this peer\n"
8339 : "maximum no. of prefix limit\n"
8340 : "Threshold value (%) at which to generate a warning msg\n"
8341 : "Restart bgp connection after limit is exceeded\n"
8342 : "Restart interval in minutes\n"
8343 : "Force checking all received routes not only accepted\n")
8344 :
8345 0 : DEFUN (no_neighbor_maximum_prefix,
8346 : no_neighbor_maximum_prefix_cmd,
8347 : "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8348 : NO_STR
8349 : NEIGHBOR_STR
8350 : NEIGHBOR_ADDR_STR2
8351 : "Maximum number of prefixes to accept from this peer\n"
8352 : "maximum no. of prefix limit\n"
8353 : "Threshold value (%) at which to generate a warning msg\n"
8354 : "Restart bgp connection after limit is exceeded\n"
8355 : "Restart interval in minutes\n"
8356 : "Only give warning message when limit is exceeded\n"
8357 : "Force checking all received routes not only accepted\n")
8358 : {
8359 0 : int idx_peer = 2;
8360 0 : return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8361 : bgp_node_afi(vty),
8362 : bgp_node_safi(vty));
8363 : }
8364 :
8365 : ALIAS_HIDDEN(
8366 : no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8367 : "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8368 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8369 : "Maximum number of prefixes to accept from this peer\n"
8370 : "maximum no. of prefix limit\n"
8371 : "Threshold value (%) at which to generate a warning msg\n"
8372 : "Restart bgp connection after limit is exceeded\n"
8373 : "Restart interval in minutes\n"
8374 : "Only give warning message when limit is exceeded\n"
8375 : "Force checking all received routes not only accepted\n")
8376 :
8377 : /* "neighbor accept-own" */
8378 0 : DEFPY (neighbor_accept_own,
8379 : neighbor_accept_own_cmd,
8380 : "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor accept-own",
8381 : NO_STR
8382 : NEIGHBOR_STR
8383 : NEIGHBOR_ADDR_STR2
8384 : "Enable handling of self-originated VPN routes containing ACCEPT_OWN community\n")
8385 : {
8386 0 : struct peer *peer;
8387 0 : afi_t afi = bgp_node_afi(vty);
8388 0 : safi_t safi = bgp_node_safi(vty);
8389 0 : int ret;
8390 :
8391 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
8392 0 : if (!peer)
8393 : return CMD_WARNING_CONFIG_FAILED;
8394 :
8395 0 : if (no)
8396 0 : ret = peer_af_flag_unset(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8397 : else
8398 0 : ret = peer_af_flag_set(peer, afi, safi, PEER_FLAG_ACCEPT_OWN);
8399 :
8400 0 : return bgp_vty_return(vty, ret);
8401 : }
8402 :
8403 : /* "neighbor soo" */
8404 0 : DEFPY (neighbor_soo,
8405 : neighbor_soo_cmd,
8406 : "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8407 : NEIGHBOR_STR
8408 : NEIGHBOR_ADDR_STR2
8409 : "Set the Site-of-Origin (SoO) extended community\n"
8410 : "VPN extended community\n")
8411 : {
8412 0 : struct peer *peer;
8413 0 : afi_t afi = bgp_node_afi(vty);
8414 0 : safi_t safi = bgp_node_safi(vty);
8415 0 : struct ecommunity *ecomm_soo;
8416 :
8417 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
8418 0 : if (!peer)
8419 : return CMD_WARNING_CONFIG_FAILED;
8420 :
8421 0 : ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8422 0 : if (!ecomm_soo) {
8423 0 : vty_out(vty, "%% Malformed SoO extended community\n");
8424 0 : return CMD_WARNING;
8425 : }
8426 0 : ecommunity_str(ecomm_soo);
8427 :
8428 0 : if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8429 0 : ecommunity_free(&peer->soo[afi][safi]);
8430 0 : peer->soo[afi][safi] = ecomm_soo;
8431 0 : peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8432 : }
8433 :
8434 0 : return bgp_vty_return(vty,
8435 0 : peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8436 : }
8437 :
8438 0 : DEFPY (no_neighbor_soo,
8439 : no_neighbor_soo_cmd,
8440 : "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8441 : NO_STR
8442 : NEIGHBOR_STR
8443 : NEIGHBOR_ADDR_STR2
8444 : "Set the Site-of-Origin (SoO) extended community\n"
8445 : "VPN extended community\n")
8446 : {
8447 0 : struct peer *peer;
8448 0 : afi_t afi = bgp_node_afi(vty);
8449 0 : safi_t safi = bgp_node_safi(vty);
8450 :
8451 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
8452 0 : if (!peer)
8453 : return CMD_WARNING_CONFIG_FAILED;
8454 :
8455 0 : ecommunity_free(&peer->soo[afi][safi]);
8456 :
8457 0 : return bgp_vty_return(
8458 0 : vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8459 : }
8460 :
8461 : /* "neighbor allowas-in" */
8462 0 : DEFUN (neighbor_allowas_in,
8463 : neighbor_allowas_in_cmd,
8464 : "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8465 : NEIGHBOR_STR
8466 : NEIGHBOR_ADDR_STR2
8467 : "Accept as-path with my AS present in it\n"
8468 : "Number of occurrences of AS number\n"
8469 : "Only accept my AS in the as-path if the route was originated in my AS\n")
8470 : {
8471 0 : int idx_peer = 1;
8472 0 : int idx_number_origin = 3;
8473 0 : int ret;
8474 0 : int origin = 0;
8475 0 : struct peer *peer;
8476 0 : int allow_num = 0;
8477 :
8478 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8479 0 : if (!peer)
8480 : return CMD_WARNING_CONFIG_FAILED;
8481 :
8482 0 : if (argc <= idx_number_origin)
8483 : allow_num = 3;
8484 : else {
8485 0 : if (argv[idx_number_origin]->type == WORD_TKN)
8486 : origin = 1;
8487 : else
8488 0 : allow_num = atoi(argv[idx_number_origin]->arg);
8489 : }
8490 :
8491 0 : ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8492 : allow_num, origin);
8493 :
8494 0 : return bgp_vty_return(vty, ret);
8495 : }
8496 :
8497 : ALIAS_HIDDEN(
8498 : neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8499 : "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8500 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8501 : "Accept as-path with my AS present in it\n"
8502 : "Number of occurrences of AS number\n"
8503 : "Only accept my AS in the as-path if the route was originated in my AS\n")
8504 :
8505 0 : DEFUN (no_neighbor_allowas_in,
8506 : no_neighbor_allowas_in_cmd,
8507 : "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8508 : NO_STR
8509 : NEIGHBOR_STR
8510 : NEIGHBOR_ADDR_STR2
8511 : "allow local ASN appears in aspath attribute\n"
8512 : "Number of occurrences of AS number\n"
8513 : "Only accept my AS in the as-path if the route was originated in my AS\n")
8514 : {
8515 0 : int idx_peer = 2;
8516 0 : int ret;
8517 0 : struct peer *peer;
8518 :
8519 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8520 0 : if (!peer)
8521 : return CMD_WARNING_CONFIG_FAILED;
8522 :
8523 0 : ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8524 : bgp_node_safi(vty));
8525 :
8526 0 : return bgp_vty_return(vty, ret);
8527 : }
8528 :
8529 : ALIAS_HIDDEN(
8530 : no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8531 : "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8532 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8533 : "allow local ASN appears in aspath attribute\n"
8534 : "Number of occurrences of AS number\n"
8535 : "Only accept my AS in the as-path if the route was originated in my AS\n")
8536 :
8537 0 : DEFUN (neighbor_ttl_security,
8538 : neighbor_ttl_security_cmd,
8539 : "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8540 : NEIGHBOR_STR
8541 : NEIGHBOR_ADDR_STR2
8542 : "BGP ttl-security parameters\n"
8543 : "Specify the maximum number of hops to the BGP peer\n"
8544 : "Number of hops to BGP peer\n")
8545 : {
8546 0 : int idx_peer = 1;
8547 0 : int idx_number = 4;
8548 0 : struct peer *peer;
8549 0 : int gtsm_hops;
8550 :
8551 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8552 0 : if (!peer)
8553 : return CMD_WARNING_CONFIG_FAILED;
8554 :
8555 0 : gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8556 :
8557 : /*
8558 : * If 'neighbor swpX', then this is for directly connected peers,
8559 : * we should not accept a ttl-security hops value greater than 1.
8560 : */
8561 0 : if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8562 0 : vty_out(vty,
8563 : "%s is directly connected peer, hops cannot exceed 1\n",
8564 0 : argv[idx_peer]->arg);
8565 0 : return CMD_WARNING_CONFIG_FAILED;
8566 : }
8567 :
8568 0 : return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8569 : }
8570 :
8571 0 : DEFUN (no_neighbor_ttl_security,
8572 : no_neighbor_ttl_security_cmd,
8573 : "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8574 : NO_STR
8575 : NEIGHBOR_STR
8576 : NEIGHBOR_ADDR_STR2
8577 : "BGP ttl-security parameters\n"
8578 : "Specify the maximum number of hops to the BGP peer\n"
8579 : "Number of hops to BGP peer\n")
8580 : {
8581 0 : int idx_peer = 2;
8582 0 : struct peer *peer;
8583 :
8584 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8585 0 : if (!peer)
8586 : return CMD_WARNING_CONFIG_FAILED;
8587 :
8588 0 : return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8589 : }
8590 :
8591 : /* disable-addpath-rx */
8592 0 : DEFUN(neighbor_disable_addpath_rx,
8593 : neighbor_disable_addpath_rx_cmd,
8594 : "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8595 : NEIGHBOR_STR
8596 : NEIGHBOR_ADDR_STR2
8597 : "Do not accept additional paths\n")
8598 : {
8599 0 : char *peer_str = argv[1]->arg;
8600 0 : struct peer *peer;
8601 0 : afi_t afi = bgp_node_afi(vty);
8602 0 : safi_t safi = bgp_node_safi(vty);
8603 :
8604 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
8605 0 : if (!peer)
8606 : return CMD_WARNING_CONFIG_FAILED;
8607 :
8608 0 : return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8609 : PEER_FLAG_DISABLE_ADDPATH_RX);
8610 : }
8611 :
8612 0 : DEFUN(no_neighbor_disable_addpath_rx,
8613 : no_neighbor_disable_addpath_rx_cmd,
8614 : "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8615 : NO_STR
8616 : NEIGHBOR_STR
8617 : NEIGHBOR_ADDR_STR2
8618 : "Do not accept additional paths\n")
8619 : {
8620 0 : char *peer_str = argv[2]->arg;
8621 0 : struct peer *peer;
8622 0 : afi_t afi = bgp_node_afi(vty);
8623 0 : safi_t safi = bgp_node_safi(vty);
8624 :
8625 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
8626 0 : if (!peer)
8627 : return CMD_WARNING_CONFIG_FAILED;
8628 :
8629 0 : return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8630 : PEER_FLAG_DISABLE_ADDPATH_RX);
8631 : }
8632 :
8633 0 : DEFUN (neighbor_addpath_tx_all_paths,
8634 : neighbor_addpath_tx_all_paths_cmd,
8635 : "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8636 : NEIGHBOR_STR
8637 : NEIGHBOR_ADDR_STR2
8638 : "Use addpath to advertise all paths to a neighbor\n")
8639 : {
8640 0 : int idx_peer = 1;
8641 0 : struct peer *peer;
8642 :
8643 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8644 0 : if (!peer)
8645 : return CMD_WARNING_CONFIG_FAILED;
8646 :
8647 0 : bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8648 : BGP_ADDPATH_ALL);
8649 0 : return CMD_SUCCESS;
8650 : }
8651 :
8652 : ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8653 : neighbor_addpath_tx_all_paths_hidden_cmd,
8654 : "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8655 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8656 : "Use addpath to advertise all paths to a neighbor\n")
8657 :
8658 0 : DEFUN (no_neighbor_addpath_tx_all_paths,
8659 : no_neighbor_addpath_tx_all_paths_cmd,
8660 : "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8661 : NO_STR
8662 : NEIGHBOR_STR
8663 : NEIGHBOR_ADDR_STR2
8664 : "Use addpath to advertise all paths to a neighbor\n")
8665 : {
8666 0 : int idx_peer = 2;
8667 0 : struct peer *peer;
8668 :
8669 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8670 0 : if (!peer)
8671 : return CMD_WARNING_CONFIG_FAILED;
8672 :
8673 0 : if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8674 : != BGP_ADDPATH_ALL) {
8675 0 : vty_out(vty,
8676 : "%% Peer not currently configured to transmit all paths.");
8677 0 : return CMD_WARNING_CONFIG_FAILED;
8678 : }
8679 :
8680 0 : bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8681 : BGP_ADDPATH_NONE);
8682 :
8683 0 : return CMD_SUCCESS;
8684 : }
8685 :
8686 : ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8687 : no_neighbor_addpath_tx_all_paths_hidden_cmd,
8688 : "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8689 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8690 : "Use addpath to advertise all paths to a neighbor\n")
8691 :
8692 0 : DEFUN (neighbor_addpath_tx_bestpath_per_as,
8693 : neighbor_addpath_tx_bestpath_per_as_cmd,
8694 : "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8695 : NEIGHBOR_STR
8696 : NEIGHBOR_ADDR_STR2
8697 : "Use addpath to advertise the bestpath per each neighboring AS\n")
8698 : {
8699 0 : int idx_peer = 1;
8700 0 : struct peer *peer;
8701 :
8702 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8703 0 : if (!peer)
8704 : return CMD_WARNING_CONFIG_FAILED;
8705 :
8706 0 : bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8707 : BGP_ADDPATH_BEST_PER_AS);
8708 :
8709 0 : return CMD_SUCCESS;
8710 : }
8711 :
8712 : ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8713 : neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8714 : "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8715 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8716 : "Use addpath to advertise the bestpath per each neighboring AS\n")
8717 :
8718 0 : DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8719 : no_neighbor_addpath_tx_bestpath_per_as_cmd,
8720 : "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8721 : NO_STR
8722 : NEIGHBOR_STR
8723 : NEIGHBOR_ADDR_STR2
8724 : "Use addpath to advertise the bestpath per each neighboring AS\n")
8725 : {
8726 0 : int idx_peer = 2;
8727 0 : struct peer *peer;
8728 :
8729 0 : peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8730 0 : if (!peer)
8731 : return CMD_WARNING_CONFIG_FAILED;
8732 :
8733 0 : if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8734 : != BGP_ADDPATH_BEST_PER_AS) {
8735 0 : vty_out(vty,
8736 : "%% Peer not currently configured to transmit all best path per as.");
8737 0 : return CMD_WARNING_CONFIG_FAILED;
8738 : }
8739 :
8740 0 : bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8741 : BGP_ADDPATH_NONE);
8742 :
8743 0 : return CMD_SUCCESS;
8744 : }
8745 :
8746 : ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8747 : no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8748 : "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8749 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8750 : "Use addpath to advertise the bestpath per each neighboring AS\n")
8751 :
8752 0 : DEFPY(
8753 : neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8754 : "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8755 : NEIGHBOR_STR
8756 : NEIGHBOR_ADDR_STR2
8757 : "Detect AS loops before sending to neighbor\n")
8758 : {
8759 0 : struct peer *peer;
8760 :
8761 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
8762 0 : if (!peer)
8763 : return CMD_WARNING_CONFIG_FAILED;
8764 :
8765 0 : peer->as_path_loop_detection = true;
8766 :
8767 0 : return CMD_SUCCESS;
8768 : }
8769 :
8770 0 : DEFPY(
8771 : no_neighbor_aspath_loop_detection,
8772 : no_neighbor_aspath_loop_detection_cmd,
8773 : "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8774 : NO_STR
8775 : NEIGHBOR_STR
8776 : NEIGHBOR_ADDR_STR2
8777 : "Detect AS loops before sending to neighbor\n")
8778 : {
8779 0 : struct peer *peer;
8780 :
8781 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
8782 0 : if (!peer)
8783 : return CMD_WARNING_CONFIG_FAILED;
8784 :
8785 0 : peer->as_path_loop_detection = false;
8786 :
8787 0 : return CMD_SUCCESS;
8788 : }
8789 :
8790 0 : DEFPY(neighbor_path_attribute_discard,
8791 : neighbor_path_attribute_discard_cmd,
8792 : "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard (1-255)...",
8793 : NEIGHBOR_STR
8794 : NEIGHBOR_ADDR_STR2
8795 : "Manipulate path attributes from incoming UPDATE messages\n"
8796 : "Drop specified attributes from incoming UPDATE messages\n"
8797 : "Attribute number\n")
8798 : {
8799 0 : struct peer *peer;
8800 0 : int idx = 0;
8801 0 : const char *discard_attrs = NULL;
8802 :
8803 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
8804 0 : if (!peer)
8805 : return CMD_WARNING_CONFIG_FAILED;
8806 :
8807 0 : argv_find(argv, argc, "(1-255)", &idx);
8808 0 : if (idx)
8809 0 : discard_attrs = argv_concat(argv, argc, idx);
8810 :
8811 0 : bgp_path_attribute_discard_vty(vty, peer, discard_attrs, true);
8812 :
8813 0 : return CMD_SUCCESS;
8814 : }
8815 :
8816 0 : DEFPY(no_neighbor_path_attribute_discard,
8817 : no_neighbor_path_attribute_discard_cmd,
8818 : "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor path-attribute discard [(1-255)]",
8819 : NO_STR
8820 : NEIGHBOR_STR
8821 : NEIGHBOR_ADDR_STR2
8822 : "Manipulate path attributes from incoming UPDATE messages\n"
8823 : "Drop specified attributes from incoming UPDATE messages\n"
8824 : "Attribute number\n")
8825 : {
8826 0 : struct peer *peer;
8827 0 : int idx = 0;
8828 0 : const char *discard_attrs = NULL;
8829 :
8830 0 : peer = peer_and_group_lookup_vty(vty, neighbor);
8831 0 : if (!peer)
8832 : return CMD_WARNING_CONFIG_FAILED;
8833 :
8834 0 : argv_find(argv, argc, "(1-255)", &idx);
8835 0 : if (idx)
8836 0 : discard_attrs = argv[idx]->arg;
8837 :
8838 0 : bgp_path_attribute_discard_vty(vty, peer, discard_attrs, false);
8839 :
8840 0 : return CMD_SUCCESS;
8841 : }
8842 :
8843 0 : static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8844 : struct ecommunity **list, bool is_rt6)
8845 : {
8846 0 : struct ecommunity *ecom = NULL;
8847 0 : struct ecommunity *ecomadd;
8848 :
8849 0 : for (; argc; --argc, ++argv) {
8850 0 : if (is_rt6)
8851 0 : ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8852 : ECOMMUNITY_ROUTE_TARGET,
8853 : 0);
8854 : else
8855 0 : ecomadd = ecommunity_str2com(argv[0]->arg,
8856 : ECOMMUNITY_ROUTE_TARGET,
8857 : 0);
8858 0 : if (!ecomadd) {
8859 0 : vty_out(vty, "Malformed community-list value\n");
8860 0 : if (ecom)
8861 0 : ecommunity_free(&ecom);
8862 0 : return CMD_WARNING_CONFIG_FAILED;
8863 : }
8864 :
8865 0 : if (ecom) {
8866 0 : ecommunity_merge(ecom, ecomadd);
8867 0 : ecommunity_free(&ecomadd);
8868 : } else {
8869 0 : ecom = ecomadd;
8870 : }
8871 : }
8872 :
8873 0 : if (*list) {
8874 0 : ecommunity_free(&*list);
8875 : }
8876 0 : *list = ecom;
8877 :
8878 0 : return CMD_SUCCESS;
8879 : }
8880 :
8881 : /*
8882 : * v2vimport is true if we are handling a `import vrf ...` command
8883 : */
8884 0 : static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8885 : {
8886 0 : afi_t afi;
8887 :
8888 0 : switch (vty->node) {
8889 : case BGP_IPV4_NODE:
8890 : afi = AFI_IP;
8891 : break;
8892 0 : case BGP_IPV6_NODE:
8893 0 : afi = AFI_IP6;
8894 0 : break;
8895 0 : default:
8896 0 : vty_out(vty,
8897 : "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8898 0 : return AFI_MAX;
8899 : }
8900 :
8901 0 : if (!v2vimport) {
8902 0 : if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8903 : BGP_CONFIG_VRF_TO_VRF_IMPORT)
8904 : || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8905 : BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8906 0 : vty_out(vty,
8907 : "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8908 0 : return AFI_MAX;
8909 : }
8910 : } else {
8911 0 : if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8912 : BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8913 : || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8914 : BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8915 0 : vty_out(vty,
8916 : "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8917 0 : return AFI_MAX;
8918 : }
8919 : }
8920 : return afi;
8921 : }
8922 :
8923 0 : DEFPY (af_rd_vpn_export,
8924 : af_rd_vpn_export_cmd,
8925 : "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8926 : NO_STR
8927 : "Specify route distinguisher\n"
8928 : "Between current address-family and vpn\n"
8929 : "For routes leaked from current address-family to vpn\n"
8930 : "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8931 : {
8932 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
8933 0 : struct prefix_rd prd;
8934 0 : int ret;
8935 0 : afi_t afi;
8936 0 : int idx = 0;
8937 0 : bool yes = true;
8938 :
8939 0 : if (argv_find(argv, argc, "no", &idx))
8940 : yes = false;
8941 :
8942 0 : if (yes) {
8943 0 : ret = str2prefix_rd(rd_str, &prd);
8944 0 : if (!ret) {
8945 0 : vty_out(vty, "%% Malformed rd\n");
8946 0 : return CMD_WARNING_CONFIG_FAILED;
8947 : }
8948 : }
8949 :
8950 0 : afi = vpn_policy_getafi(vty, bgp, false);
8951 0 : if (afi == AFI_MAX)
8952 : return CMD_WARNING_CONFIG_FAILED;
8953 :
8954 : /*
8955 : * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8956 : */
8957 0 : vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8958 : bgp_get_default(), bgp);
8959 :
8960 0 : if (yes) {
8961 0 : bgp->vpn_policy[afi].tovpn_rd = prd;
8962 0 : SET_FLAG(bgp->vpn_policy[afi].flags,
8963 : BGP_VPN_POLICY_TOVPN_RD_SET);
8964 : } else {
8965 0 : UNSET_FLAG(bgp->vpn_policy[afi].flags,
8966 : BGP_VPN_POLICY_TOVPN_RD_SET);
8967 : }
8968 :
8969 : /* post-change: re-export vpn routes */
8970 0 : vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8971 : bgp_get_default(), bgp);
8972 :
8973 0 : return CMD_SUCCESS;
8974 : }
8975 :
8976 : ALIAS (af_rd_vpn_export,
8977 : af_no_rd_vpn_export_cmd,
8978 : "no rd vpn export",
8979 : NO_STR
8980 : "Specify route distinguisher\n"
8981 : "Between current address-family and vpn\n"
8982 : "For routes leaked from current address-family to vpn\n")
8983 :
8984 0 : DEFPY (af_label_vpn_export,
8985 : af_label_vpn_export_cmd,
8986 : "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8987 : NO_STR
8988 : "label value for VRF\n"
8989 : "Between current address-family and vpn\n"
8990 : "For routes leaked from current address-family to vpn\n"
8991 : "Label Value <0-1048575>\n"
8992 : "Automatically assign a label\n")
8993 : {
8994 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
8995 0 : mpls_label_t label = MPLS_LABEL_NONE;
8996 0 : afi_t afi;
8997 0 : int idx = 0;
8998 0 : bool yes = true;
8999 :
9000 0 : if (argv_find(argv, argc, "no", &idx))
9001 : yes = false;
9002 :
9003 : /* If "no ...", squash trailing parameter */
9004 0 : if (!yes)
9005 : label_auto = NULL;
9006 :
9007 0 : if (yes) {
9008 0 : if (!label_auto)
9009 0 : label = label_val; /* parser should force unsigned */
9010 : }
9011 :
9012 0 : afi = vpn_policy_getafi(vty, bgp, false);
9013 0 : if (afi == AFI_MAX)
9014 : return CMD_WARNING_CONFIG_FAILED;
9015 :
9016 :
9017 0 : if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9018 : BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9019 : /* no change */
9020 : return CMD_SUCCESS;
9021 :
9022 : /*
9023 : * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9024 : */
9025 0 : vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9026 : bgp_get_default(), bgp);
9027 :
9028 0 : if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9029 : BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9030 :
9031 0 : if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9032 :
9033 : /*
9034 : * label has previously been automatically
9035 : * assigned by labelpool: release it
9036 : *
9037 : * NB if tovpn_label == MPLS_LABEL_NONE it
9038 : * means the automatic assignment is in flight
9039 : * and therefore the labelpool callback must
9040 : * detect that the auto label is not needed.
9041 : */
9042 :
9043 0 : bgp_lp_release(LP_TYPE_VRF,
9044 0 : &bgp->vpn_policy[afi],
9045 : bgp->vpn_policy[afi].tovpn_label);
9046 : }
9047 0 : UNSET_FLAG(bgp->vpn_policy[afi].flags,
9048 : BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9049 : }
9050 :
9051 0 : bgp->vpn_policy[afi].tovpn_label = label;
9052 0 : if (label_auto) {
9053 0 : SET_FLAG(bgp->vpn_policy[afi].flags,
9054 : BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9055 0 : bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9056 : vpn_leak_label_callback);
9057 : }
9058 :
9059 : /* post-change: re-export vpn routes */
9060 0 : vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9061 : bgp_get_default(), bgp);
9062 :
9063 0 : hook_call(bgp_snmp_update_last_changed, bgp);
9064 0 : return CMD_SUCCESS;
9065 : }
9066 :
9067 0 : DEFPY (af_sid_vpn_export,
9068 : af_sid_vpn_export_cmd,
9069 : "[no] sid vpn export <(1-1048575)$sid_idx|auto$sid_auto>",
9070 : NO_STR
9071 : "sid value for VRF\n"
9072 : "Between current address-family and vpn\n"
9073 : "For routes leaked from current address-family to vpn\n"
9074 : "Sid allocation index\n"
9075 : "Automatically assign a label\n")
9076 : {
9077 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9078 0 : afi_t afi;
9079 0 : int debug = 0;
9080 0 : int idx = 0;
9081 0 : bool yes = true;
9082 :
9083 0 : if (argv_find(argv, argc, "no", &idx))
9084 0 : yes = false;
9085 0 : debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9086 : BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9087 :
9088 0 : afi = vpn_policy_getafi(vty, bgp, false);
9089 0 : if (afi == AFI_MAX)
9090 : return CMD_WARNING_CONFIG_FAILED;
9091 :
9092 0 : if (!yes) {
9093 : /* implement me */
9094 0 : vty_out(vty, "It's not implemented\n");
9095 0 : return CMD_WARNING_CONFIG_FAILED;
9096 : }
9097 :
9098 0 : if (bgp->tovpn_sid_index != 0 ||
9099 0 : CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
9100 0 : vty_out(vty,
9101 : "per-vrf sid and per-af sid are mutually exclusive\n"
9102 : "Failed: per-vrf sid is configured. Remove per-vrf sid before configuring per-af sid\n");
9103 0 : return CMD_WARNING_CONFIG_FAILED;
9104 : }
9105 :
9106 : /* skip when it's already configured */
9107 0 : if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9108 0 : || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9109 : BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9110 : return CMD_SUCCESS;
9111 :
9112 : /*
9113 : * mode change between sid_idx and sid_auto isn't supported.
9114 : * user must negate sid vpn export when they want to change the mode
9115 : */
9116 0 : if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9117 0 : || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9118 : BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9119 0 : vty_out(vty, "it's already configured as %s.\n",
9120 : sid_auto ? "auto-mode" : "idx-mode");
9121 0 : return CMD_WARNING_CONFIG_FAILED;
9122 : }
9123 :
9124 : /* pre-change */
9125 0 : vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9126 : bgp_get_default(), bgp);
9127 :
9128 0 : if (sid_auto) {
9129 : /* SID allocation auto-mode */
9130 0 : if (debug)
9131 0 : zlog_debug("%s: auto sid alloc.", __func__);
9132 0 : SET_FLAG(bgp->vpn_policy[afi].flags,
9133 : BGP_VPN_POLICY_TOVPN_SID_AUTO);
9134 : } else {
9135 : /* SID allocation index-mode */
9136 0 : if (debug)
9137 0 : zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9138 0 : bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9139 : }
9140 :
9141 : /* post-change */
9142 0 : vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9143 : bgp_get_default(), bgp);
9144 0 : return CMD_SUCCESS;
9145 : }
9146 :
9147 0 : DEFPY (bgp_sid_vpn_export,
9148 : bgp_sid_vpn_export_cmd,
9149 : "[no] sid vpn per-vrf export <(1-1048575)$sid_idx|auto$sid_auto>",
9150 : NO_STR
9151 : "sid value for VRF\n"
9152 : "Between current vrf and vpn\n"
9153 : "sid per-VRF (both IPv4 and IPv6 address families)\n"
9154 : "For routes leaked from current vrf to vpn\n"
9155 : "Sid allocation index\n"
9156 : "Automatically assign a label\n")
9157 : {
9158 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9159 0 : int debug;
9160 :
9161 0 : debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9162 : BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9163 :
9164 0 : if (no) {
9165 : /* when per-VRF SID is not set, do nothing */
9166 0 : if (bgp->tovpn_sid_index == 0 &&
9167 0 : !CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))
9168 : return CMD_SUCCESS;
9169 :
9170 0 : sid_idx = 0;
9171 0 : sid_auto = false;
9172 0 : bgp->tovpn_sid_index = 0;
9173 0 : UNSET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9174 : }
9175 :
9176 0 : if (bgp->vpn_policy[AFI_IP].tovpn_sid_index != 0 ||
9177 0 : CHECK_FLAG(bgp->vpn_policy[AFI_IP].flags,
9178 0 : BGP_VPN_POLICY_TOVPN_SID_AUTO) ||
9179 0 : bgp->vpn_policy[AFI_IP6].tovpn_sid_index != 0 ||
9180 0 : CHECK_FLAG(bgp->vpn_policy[AFI_IP6].flags,
9181 : BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
9182 0 : vty_out(vty,
9183 : "per-vrf sid and per-af sid are mutually exclusive\n"
9184 : "Failed: per-af sid is configured. Remove per-af sid before configuring per-vrf sid\n");
9185 0 : return CMD_WARNING_CONFIG_FAILED;
9186 : }
9187 :
9188 : /* skip when it's already configured */
9189 0 : if ((sid_idx != 0 && bgp->tovpn_sid_index != 0) ||
9190 0 : (sid_auto && CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)))
9191 : return CMD_SUCCESS;
9192 :
9193 : /*
9194 : * mode change between sid_idx and sid_auto isn't supported.
9195 : * user must negate sid vpn export when they want to change the mode
9196 : */
9197 0 : if ((sid_auto && bgp->tovpn_sid_index != 0) ||
9198 0 : (sid_idx != 0 &&
9199 0 : CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO))) {
9200 0 : vty_out(vty, "it's already configured as %s.\n",
9201 : sid_auto ? "auto-mode" : "idx-mode");
9202 0 : return CMD_WARNING_CONFIG_FAILED;
9203 : }
9204 :
9205 : /* pre-change */
9206 0 : vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9207 : bgp);
9208 0 : vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6, bgp_get_default(),
9209 : bgp);
9210 :
9211 0 : if (sid_auto) {
9212 : /* SID allocation auto-mode */
9213 0 : if (debug)
9214 0 : zlog_debug("%s: auto per-vrf sid alloc.", __func__);
9215 0 : SET_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO);
9216 0 : } else if (sid_idx != 0) {
9217 : /* SID allocation index-mode */
9218 0 : if (debug)
9219 0 : zlog_debug("%s: idx %ld per-vrf sid alloc.", __func__,
9220 : sid_idx);
9221 0 : bgp->tovpn_sid_index = sid_idx;
9222 : }
9223 :
9224 : /* post-change */
9225 0 : vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP, bgp_get_default(),
9226 : bgp);
9227 0 : vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, AFI_IP6,
9228 : bgp_get_default(), bgp);
9229 :
9230 0 : return CMD_SUCCESS;
9231 : }
9232 :
9233 : ALIAS (af_label_vpn_export,
9234 : af_no_label_vpn_export_cmd,
9235 : "no label vpn export",
9236 : NO_STR
9237 : "label value for VRF\n"
9238 : "Between current address-family and vpn\n"
9239 : "For routes leaked from current address-family to vpn\n")
9240 :
9241 : ALIAS (bgp_sid_vpn_export,
9242 : no_bgp_sid_vpn_export_cmd,
9243 : "no$no sid vpn per-vrf export",
9244 : NO_STR
9245 : "sid value for VRF\n"
9246 : "Between current vrf and vpn\n"
9247 : "sid per-VRF (both IPv4 and IPv6 address families)\n"
9248 : "For routes leaked from current vrf to vpn\n")
9249 :
9250 0 : DEFPY (af_nexthop_vpn_export,
9251 : af_nexthop_vpn_export_cmd,
9252 : "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9253 : NO_STR
9254 : "Specify next hop to use for VRF advertised prefixes\n"
9255 : "Between current address-family and vpn\n"
9256 : "For routes leaked from current address-family to vpn\n"
9257 : "IPv4 prefix\n"
9258 : "IPv6 prefix\n")
9259 : {
9260 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9261 0 : afi_t afi;
9262 0 : struct prefix p;
9263 :
9264 0 : if (!no) {
9265 0 : if (!nexthop_su) {
9266 0 : vty_out(vty, "%% Nexthop required\n");
9267 0 : return CMD_WARNING_CONFIG_FAILED;
9268 : }
9269 0 : if (!sockunion2hostprefix(nexthop_su, &p))
9270 : return CMD_WARNING_CONFIG_FAILED;
9271 : }
9272 :
9273 0 : afi = vpn_policy_getafi(vty, bgp, false);
9274 0 : if (afi == AFI_MAX)
9275 : return CMD_WARNING_CONFIG_FAILED;
9276 :
9277 : /*
9278 : * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9279 : */
9280 0 : vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9281 : bgp_get_default(), bgp);
9282 :
9283 0 : if (!no) {
9284 0 : bgp->vpn_policy[afi].tovpn_nexthop = p;
9285 0 : SET_FLAG(bgp->vpn_policy[afi].flags,
9286 : BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9287 : } else {
9288 0 : UNSET_FLAG(bgp->vpn_policy[afi].flags,
9289 : BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
9290 : }
9291 :
9292 : /* post-change: re-export vpn routes */
9293 0 : vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9294 : bgp_get_default(), bgp);
9295 :
9296 0 : return CMD_SUCCESS;
9297 : }
9298 :
9299 0 : static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9300 : {
9301 0 : if (!strcmp(dstr, "import")) {
9302 0 : dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9303 0 : } else if (!strcmp(dstr, "export")) {
9304 0 : dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9305 0 : } else if (!strcmp(dstr, "both")) {
9306 0 : dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9307 0 : dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9308 : } else {
9309 0 : vty_out(vty, "%% direction parse error\n");
9310 0 : return CMD_WARNING_CONFIG_FAILED;
9311 : }
9312 : return CMD_SUCCESS;
9313 : }
9314 :
9315 0 : DEFPY (af_rt_vpn_imexport,
9316 : af_rt_vpn_imexport_cmd,
9317 : "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9318 : NO_STR
9319 : "Specify route target list\n"
9320 : "Specify route target list\n"
9321 : "Between current address-family and vpn\n"
9322 : "For routes leaked from vpn to current address-family: match any\n"
9323 : "For routes leaked from current address-family to vpn: set\n"
9324 : "both import: match any and export: set\n"
9325 : "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9326 : {
9327 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9328 0 : int ret;
9329 0 : struct ecommunity *ecom = NULL;
9330 0 : int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9331 0 : enum vpn_policy_direction dir;
9332 0 : afi_t afi;
9333 0 : int idx = 0;
9334 0 : bool yes = true;
9335 :
9336 0 : if (argv_find(argv, argc, "no", &idx))
9337 0 : yes = false;
9338 :
9339 0 : afi = vpn_policy_getafi(vty, bgp, false);
9340 0 : if (afi == AFI_MAX)
9341 : return CMD_WARNING_CONFIG_FAILED;
9342 :
9343 0 : ret = vpn_policy_getdirs(vty, direction_str, dodir);
9344 0 : if (ret != CMD_SUCCESS)
9345 : return ret;
9346 :
9347 0 : if (yes) {
9348 0 : if (!argv_find(argv, argc, "RTLIST", &idx)) {
9349 0 : vty_out(vty, "%% Missing RTLIST\n");
9350 0 : return CMD_WARNING_CONFIG_FAILED;
9351 : }
9352 0 : ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9353 0 : if (ret != CMD_SUCCESS) {
9354 : return ret;
9355 : }
9356 : }
9357 :
9358 0 : for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9359 0 : if (!dodir[dir])
9360 0 : continue;
9361 :
9362 0 : vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9363 :
9364 0 : if (yes) {
9365 0 : if (bgp->vpn_policy[afi].rtlist[dir])
9366 0 : ecommunity_free(
9367 : &bgp->vpn_policy[afi].rtlist[dir]);
9368 0 : bgp->vpn_policy[afi].rtlist[dir] =
9369 0 : ecommunity_dup(ecom);
9370 : } else {
9371 0 : if (bgp->vpn_policy[afi].rtlist[dir])
9372 0 : ecommunity_free(
9373 : &bgp->vpn_policy[afi].rtlist[dir]);
9374 0 : bgp->vpn_policy[afi].rtlist[dir] = NULL;
9375 : }
9376 :
9377 0 : vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9378 : }
9379 :
9380 0 : if (ecom)
9381 0 : ecommunity_free(&ecom);
9382 :
9383 : return CMD_SUCCESS;
9384 : }
9385 :
9386 : ALIAS (af_rt_vpn_imexport,
9387 : af_no_rt_vpn_imexport_cmd,
9388 : "no <rt|route-target> vpn <import|export|both>$direction_str",
9389 : NO_STR
9390 : "Specify route target list\n"
9391 : "Specify route target list\n"
9392 : "Between current address-family and vpn\n"
9393 : "For routes leaked from vpn to current address-family\n"
9394 : "For routes leaked from current address-family to vpn\n"
9395 : "both import and export\n")
9396 :
9397 0 : DEFPY (af_route_map_vpn_imexport,
9398 : af_route_map_vpn_imexport_cmd,
9399 : /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9400 : "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9401 : NO_STR
9402 : "Specify route map\n"
9403 : "Between current address-family and vpn\n"
9404 : "For routes leaked from vpn to current address-family\n"
9405 : "For routes leaked from current address-family to vpn\n"
9406 : "name of route-map\n")
9407 : {
9408 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9409 0 : int ret;
9410 0 : int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9411 0 : enum vpn_policy_direction dir;
9412 0 : afi_t afi;
9413 0 : int idx = 0;
9414 0 : bool yes = true;
9415 :
9416 0 : if (argv_find(argv, argc, "no", &idx))
9417 0 : yes = false;
9418 :
9419 0 : afi = vpn_policy_getafi(vty, bgp, false);
9420 0 : if (afi == AFI_MAX)
9421 : return CMD_WARNING_CONFIG_FAILED;
9422 :
9423 0 : ret = vpn_policy_getdirs(vty, direction_str, dodir);
9424 0 : if (ret != CMD_SUCCESS)
9425 : return ret;
9426 :
9427 0 : for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9428 0 : if (!dodir[dir])
9429 0 : continue;
9430 :
9431 0 : vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9432 :
9433 0 : if (yes) {
9434 0 : if (bgp->vpn_policy[afi].rmap_name[dir])
9435 0 : XFREE(MTYPE_ROUTE_MAP_NAME,
9436 : bgp->vpn_policy[afi].rmap_name[dir]);
9437 0 : bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9438 : MTYPE_ROUTE_MAP_NAME, rmap_str);
9439 0 : bgp->vpn_policy[afi].rmap[dir] =
9440 0 : route_map_lookup_warn_noexist(vty, rmap_str);
9441 0 : if (!bgp->vpn_policy[afi].rmap[dir])
9442 : return CMD_SUCCESS;
9443 : } else {
9444 0 : if (bgp->vpn_policy[afi].rmap_name[dir])
9445 0 : XFREE(MTYPE_ROUTE_MAP_NAME,
9446 : bgp->vpn_policy[afi].rmap_name[dir]);
9447 0 : bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9448 0 : bgp->vpn_policy[afi].rmap[dir] = NULL;
9449 : }
9450 :
9451 0 : vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9452 : }
9453 :
9454 : return CMD_SUCCESS;
9455 : }
9456 :
9457 : ALIAS (af_route_map_vpn_imexport,
9458 : af_no_route_map_vpn_imexport_cmd,
9459 : "no route-map vpn <import|export>$direction_str",
9460 : NO_STR
9461 : "Specify route map\n"
9462 : "Between current address-family and vpn\n"
9463 : "For routes leaked from vpn to current address-family\n"
9464 : "For routes leaked from current address-family to vpn\n")
9465 :
9466 0 : DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9467 : "import vrf route-map RMAP$rmap_str",
9468 : "Import routes from another VRF\n"
9469 : "Vrf routes being filtered\n"
9470 : "Specify route map\n"
9471 : "name of route-map\n")
9472 : {
9473 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9474 0 : enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9475 0 : afi_t afi;
9476 0 : struct bgp *bgp_default;
9477 :
9478 0 : afi = vpn_policy_getafi(vty, bgp, true);
9479 0 : if (afi == AFI_MAX)
9480 : return CMD_WARNING_CONFIG_FAILED;
9481 :
9482 0 : bgp_default = bgp_get_default();
9483 0 : if (!bgp_default) {
9484 0 : int32_t ret;
9485 0 : as_t as = bgp->as;
9486 :
9487 : /* Auto-create assuming the same AS */
9488 0 : ret = bgp_get_vty(&bgp_default, &as, NULL,
9489 : BGP_INSTANCE_TYPE_DEFAULT);
9490 :
9491 0 : if (ret) {
9492 0 : vty_out(vty,
9493 : "VRF default is not configured as a bgp instance\n");
9494 0 : return CMD_WARNING;
9495 : }
9496 : }
9497 :
9498 0 : vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9499 :
9500 0 : if (bgp->vpn_policy[afi].rmap_name[dir])
9501 0 : XFREE(MTYPE_ROUTE_MAP_NAME,
9502 : bgp->vpn_policy[afi].rmap_name[dir]);
9503 0 : bgp->vpn_policy[afi].rmap_name[dir] =
9504 0 : XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9505 0 : bgp->vpn_policy[afi].rmap[dir] =
9506 0 : route_map_lookup_warn_noexist(vty, rmap_str);
9507 0 : if (!bgp->vpn_policy[afi].rmap[dir])
9508 : return CMD_SUCCESS;
9509 :
9510 0 : SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9511 : BGP_CONFIG_VRF_TO_VRF_IMPORT);
9512 :
9513 0 : vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9514 :
9515 0 : return CMD_SUCCESS;
9516 : }
9517 :
9518 0 : DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9519 : "no import vrf route-map [RMAP$rmap_str]",
9520 : NO_STR
9521 : "Import routes from another VRF\n"
9522 : "Vrf routes being filtered\n"
9523 : "Specify route map\n"
9524 : "name of route-map\n")
9525 : {
9526 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9527 0 : enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9528 0 : afi_t afi;
9529 :
9530 0 : afi = vpn_policy_getafi(vty, bgp, true);
9531 0 : if (afi == AFI_MAX)
9532 : return CMD_WARNING_CONFIG_FAILED;
9533 :
9534 0 : vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9535 :
9536 0 : if (bgp->vpn_policy[afi].rmap_name[dir])
9537 0 : XFREE(MTYPE_ROUTE_MAP_NAME,
9538 : bgp->vpn_policy[afi].rmap_name[dir]);
9539 0 : bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9540 0 : bgp->vpn_policy[afi].rmap[dir] = NULL;
9541 :
9542 0 : if (bgp->vpn_policy[afi].import_vrf->count == 0)
9543 0 : UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9544 : BGP_CONFIG_VRF_TO_VRF_IMPORT);
9545 :
9546 0 : vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9547 :
9548 0 : return CMD_SUCCESS;
9549 : }
9550 :
9551 0 : DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9552 : "[no] import vrf VIEWVRFNAME$import_name",
9553 : NO_STR
9554 : "Import routes from another VRF\n"
9555 : "VRF to import from\n"
9556 : "The name of the VRF\n")
9557 : {
9558 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9559 0 : struct listnode *node;
9560 0 : struct bgp *vrf_bgp, *bgp_default;
9561 0 : int32_t ret = 0;
9562 0 : as_t as = bgp->as;
9563 0 : bool remove = false;
9564 0 : int32_t idx = 0;
9565 0 : char *vname;
9566 0 : enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9567 0 : safi_t safi;
9568 0 : afi_t afi;
9569 :
9570 0 : if (import_name == NULL) {
9571 0 : vty_out(vty, "%% Missing import name\n");
9572 0 : return CMD_WARNING;
9573 : }
9574 :
9575 0 : if (strcmp(import_name, "route-map") == 0) {
9576 0 : vty_out(vty, "%% Must include route-map name\n");
9577 0 : return CMD_WARNING;
9578 : }
9579 :
9580 0 : if (argv_find(argv, argc, "no", &idx))
9581 0 : remove = true;
9582 :
9583 0 : afi = vpn_policy_getafi(vty, bgp, true);
9584 0 : if (afi == AFI_MAX)
9585 : return CMD_WARNING_CONFIG_FAILED;
9586 :
9587 0 : safi = bgp_node_safi(vty);
9588 :
9589 0 : if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9590 0 : && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9591 0 : || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9592 0 : vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9593 : remove ? "unimport" : "import", import_name);
9594 0 : return CMD_WARNING;
9595 : }
9596 :
9597 0 : bgp_default = bgp_get_default();
9598 0 : if (!bgp_default) {
9599 : /* Auto-create assuming the same AS */
9600 0 : ret = bgp_get_vty(&bgp_default, &as, NULL,
9601 : BGP_INSTANCE_TYPE_DEFAULT);
9602 :
9603 0 : if (ret) {
9604 0 : vty_out(vty,
9605 : "VRF default is not configured as a bgp instance\n");
9606 0 : return CMD_WARNING;
9607 : }
9608 : }
9609 :
9610 0 : vrf_bgp = bgp_lookup_by_name(import_name);
9611 0 : if (!vrf_bgp) {
9612 0 : if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9613 0 : vrf_bgp = bgp_default;
9614 : else
9615 : /* Auto-create assuming the same AS */
9616 0 : ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9617 :
9618 0 : if (ret) {
9619 0 : vty_out(vty,
9620 : "VRF %s is not configured as a bgp instance\n",
9621 : import_name);
9622 0 : return CMD_WARNING;
9623 : }
9624 : }
9625 :
9626 0 : if (remove) {
9627 0 : vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9628 : } else {
9629 : /* Already importing from "import_vrf"? */
9630 0 : for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9631 : vname)) {
9632 0 : if (strcmp(vname, import_name) == 0)
9633 : return CMD_WARNING;
9634 : }
9635 :
9636 0 : vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9637 : }
9638 :
9639 : return CMD_SUCCESS;
9640 : }
9641 :
9642 : /* This command is valid only in a bgp vrf instance or the default instance */
9643 0 : DEFPY (bgp_imexport_vpn,
9644 : bgp_imexport_vpn_cmd,
9645 : "[no] <import|export>$direction_str vpn",
9646 : NO_STR
9647 : "Import routes to this address-family\n"
9648 : "Export routes from this address-family\n"
9649 : "to/from default instance VPN RIB\n")
9650 : {
9651 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9652 0 : int previous_state;
9653 0 : afi_t afi;
9654 0 : safi_t safi;
9655 0 : int idx = 0;
9656 0 : bool yes = true;
9657 0 : int flag;
9658 0 : enum vpn_policy_direction dir;
9659 :
9660 0 : if (argv_find(argv, argc, "no", &idx))
9661 0 : yes = false;
9662 :
9663 0 : if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9664 : BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9665 :
9666 0 : vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9667 0 : return CMD_WARNING_CONFIG_FAILED;
9668 : }
9669 :
9670 0 : afi = bgp_node_afi(vty);
9671 0 : safi = bgp_node_safi(vty);
9672 0 : if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9673 0 : vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9674 0 : return CMD_WARNING_CONFIG_FAILED;
9675 : }
9676 :
9677 0 : if (!strcmp(direction_str, "import")) {
9678 : flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9679 : dir = BGP_VPN_POLICY_DIR_FROMVPN;
9680 0 : } else if (!strcmp(direction_str, "export")) {
9681 : flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9682 : dir = BGP_VPN_POLICY_DIR_TOVPN;
9683 : } else {
9684 0 : vty_out(vty, "%% unknown direction %s\n", direction_str);
9685 0 : return CMD_WARNING_CONFIG_FAILED;
9686 : }
9687 :
9688 0 : previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9689 :
9690 0 : if (yes) {
9691 0 : SET_FLAG(bgp->af_flags[afi][safi], flag);
9692 0 : if (!previous_state) {
9693 : /* trigger export current vrf */
9694 0 : vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9695 : }
9696 : } else {
9697 0 : if (previous_state) {
9698 : /* trigger un-export current vrf */
9699 0 : vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9700 : }
9701 0 : UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9702 : }
9703 :
9704 0 : hook_call(bgp_snmp_init_stats, bgp);
9705 :
9706 0 : return CMD_SUCCESS;
9707 : }
9708 :
9709 0 : DEFPY (af_routetarget_import,
9710 : af_routetarget_import_cmd,
9711 : "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9712 : NO_STR
9713 : "Specify route target list\n"
9714 : "Specify route target list\n"
9715 : "Specify route target list\n"
9716 : "Specify route target list\n"
9717 : "Flow-spec redirect type route target\n"
9718 : "Import routes to this address-family\n"
9719 : "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9720 : {
9721 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9722 0 : int ret;
9723 0 : struct ecommunity *ecom = NULL;
9724 0 : afi_t afi;
9725 0 : int idx = 0, idx_unused = 0;
9726 0 : bool yes = true;
9727 0 : bool rt6 = false;
9728 :
9729 0 : if (argv_find(argv, argc, "no", &idx))
9730 0 : yes = false;
9731 :
9732 0 : if (argv_find(argv, argc, "rt6", &idx_unused) ||
9733 0 : argv_find(argv, argc, "route-target6", &idx_unused))
9734 : rt6 = true;
9735 :
9736 0 : afi = vpn_policy_getafi(vty, bgp, false);
9737 0 : if (afi == AFI_MAX)
9738 : return CMD_WARNING_CONFIG_FAILED;
9739 :
9740 0 : if (rt6 && afi != AFI_IP6)
9741 : return CMD_WARNING_CONFIG_FAILED;
9742 :
9743 0 : if (yes) {
9744 0 : if (!argv_find(argv, argc, "RTLIST", &idx)) {
9745 0 : vty_out(vty, "%% Missing RTLIST\n");
9746 0 : return CMD_WARNING_CONFIG_FAILED;
9747 : }
9748 0 : ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9749 0 : if (ret != CMD_SUCCESS)
9750 : return ret;
9751 : }
9752 :
9753 0 : if (yes) {
9754 0 : if (bgp->vpn_policy[afi].import_redirect_rtlist)
9755 0 : ecommunity_free(&bgp->vpn_policy[afi]
9756 : .import_redirect_rtlist);
9757 0 : bgp->vpn_policy[afi].import_redirect_rtlist =
9758 0 : ecommunity_dup(ecom);
9759 : } else {
9760 0 : if (bgp->vpn_policy[afi].import_redirect_rtlist)
9761 0 : ecommunity_free(&bgp->vpn_policy[afi]
9762 : .import_redirect_rtlist);
9763 0 : bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9764 : }
9765 :
9766 0 : if (ecom)
9767 0 : ecommunity_free(&ecom);
9768 :
9769 : return CMD_SUCCESS;
9770 : }
9771 :
9772 2 : DEFUN_NOSH (address_family_ipv4_safi,
9773 : address_family_ipv4_safi_cmd,
9774 : "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9775 : "Enter Address Family command mode\n"
9776 : BGP_AF_STR
9777 : BGP_SAFI_WITH_LABEL_HELP_STR)
9778 : {
9779 :
9780 2 : if (argc == 3) {
9781 1 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9782 1 : safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9783 1 : if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9784 0 : && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9785 0 : && safi != SAFI_EVPN) {
9786 0 : vty_out(vty,
9787 : "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9788 0 : return CMD_WARNING_CONFIG_FAILED;
9789 : }
9790 1 : vty->node = bgp_node_type(AFI_IP, safi);
9791 : } else
9792 1 : vty->node = BGP_IPV4_NODE;
9793 :
9794 : return CMD_SUCCESS;
9795 : }
9796 :
9797 0 : DEFUN_NOSH (address_family_ipv6_safi,
9798 : address_family_ipv6_safi_cmd,
9799 : "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9800 : "Enter Address Family command mode\n"
9801 : BGP_AF_STR
9802 : BGP_SAFI_WITH_LABEL_HELP_STR)
9803 : {
9804 0 : if (argc == 3) {
9805 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9806 0 : safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9807 0 : if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9808 0 : && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9809 0 : && safi != SAFI_EVPN) {
9810 0 : vty_out(vty,
9811 : "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9812 0 : return CMD_WARNING_CONFIG_FAILED;
9813 : }
9814 0 : vty->node = bgp_node_type(AFI_IP6, safi);
9815 : } else
9816 0 : vty->node = BGP_IPV6_NODE;
9817 :
9818 : return CMD_SUCCESS;
9819 : }
9820 :
9821 : #ifdef KEEP_OLD_VPN_COMMANDS
9822 : DEFUN_NOSH (address_family_vpnv4,
9823 : address_family_vpnv4_cmd,
9824 : "address-family vpnv4 [unicast]",
9825 : "Enter Address Family command mode\n"
9826 : BGP_AF_STR
9827 : BGP_AF_MODIFIER_STR)
9828 : {
9829 : vty->node = BGP_VPNV4_NODE;
9830 : return CMD_SUCCESS;
9831 : }
9832 :
9833 : DEFUN_NOSH (address_family_vpnv6,
9834 : address_family_vpnv6_cmd,
9835 : "address-family vpnv6 [unicast]",
9836 : "Enter Address Family command mode\n"
9837 : BGP_AF_STR
9838 : BGP_AF_MODIFIER_STR)
9839 : {
9840 : vty->node = BGP_VPNV6_NODE;
9841 : return CMD_SUCCESS;
9842 : }
9843 : #endif /* KEEP_OLD_VPN_COMMANDS */
9844 :
9845 0 : DEFUN_NOSH (address_family_evpn,
9846 : address_family_evpn_cmd,
9847 : "address-family l2vpn evpn",
9848 : "Enter Address Family command mode\n"
9849 : BGP_AF_STR
9850 : BGP_AF_MODIFIER_STR)
9851 : {
9852 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9853 0 : vty->node = BGP_EVPN_NODE;
9854 0 : return CMD_SUCCESS;
9855 : }
9856 :
9857 0 : DEFUN_NOSH (bgp_segment_routing_srv6,
9858 : bgp_segment_routing_srv6_cmd,
9859 : "segment-routing srv6",
9860 : "Segment-Routing configuration\n"
9861 : "Segment-Routing SRv6 configuration\n")
9862 : {
9863 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9864 0 : bgp->srv6_enabled = true;
9865 0 : vty->node = BGP_SRV6_NODE;
9866 0 : return CMD_SUCCESS;
9867 : }
9868 :
9869 0 : DEFUN (no_bgp_segment_routing_srv6,
9870 : no_bgp_segment_routing_srv6_cmd,
9871 : "no segment-routing srv6",
9872 : NO_STR
9873 : "Segment-Routing configuration\n"
9874 : "Segment-Routing SRv6 configuration\n")
9875 : {
9876 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9877 :
9878 0 : if (strlen(bgp->srv6_locator_name) > 0)
9879 0 : if (bgp_srv6_locator_unset(bgp) < 0)
9880 : return CMD_WARNING_CONFIG_FAILED;
9881 :
9882 0 : bgp->srv6_enabled = false;
9883 0 : return CMD_SUCCESS;
9884 : }
9885 :
9886 0 : DEFPY (bgp_srv6_locator,
9887 : bgp_srv6_locator_cmd,
9888 : "locator NAME$name",
9889 : "Specify SRv6 locator\n"
9890 : "Specify SRv6 locator\n")
9891 : {
9892 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9893 0 : int ret;
9894 :
9895 0 : if (strlen(bgp->srv6_locator_name) > 0
9896 0 : && strcmp(name, bgp->srv6_locator_name) != 0) {
9897 0 : vty_out(vty, "srv6 locator is already configured\n");
9898 0 : return CMD_WARNING_CONFIG_FAILED;
9899 : }
9900 :
9901 0 : snprintf(bgp->srv6_locator_name,
9902 : sizeof(bgp->srv6_locator_name), "%s", name);
9903 :
9904 0 : ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9905 0 : if (ret < 0)
9906 : return CMD_WARNING_CONFIG_FAILED;
9907 :
9908 : return CMD_SUCCESS;
9909 : }
9910 :
9911 0 : DEFPY (no_bgp_srv6_locator,
9912 : no_bgp_srv6_locator_cmd,
9913 : "no locator NAME$name",
9914 : NO_STR
9915 : "Specify SRv6 locator\n"
9916 : "Specify SRv6 locator\n")
9917 : {
9918 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
9919 :
9920 : /* when locator isn't configured, do nothing */
9921 0 : if (strlen(bgp->srv6_locator_name) < 1)
9922 : return CMD_SUCCESS;
9923 :
9924 : /* name validation */
9925 0 : if (strcmp(name, bgp->srv6_locator_name) != 0) {
9926 0 : vty_out(vty, "%% No srv6 locator is configured\n");
9927 0 : return CMD_WARNING_CONFIG_FAILED;
9928 : }
9929 :
9930 : /* unset locator */
9931 0 : if (bgp_srv6_locator_unset(bgp) < 0)
9932 : return CMD_WARNING_CONFIG_FAILED;
9933 :
9934 : return CMD_SUCCESS;
9935 : }
9936 :
9937 0 : DEFPY (show_bgp_srv6,
9938 : show_bgp_srv6_cmd,
9939 : "show bgp segment-routing srv6",
9940 : SHOW_STR
9941 : BGP_STR
9942 : "BGP Segment Routing\n"
9943 : "BGP Segment Routing SRv6\n")
9944 : {
9945 0 : struct bgp *bgp;
9946 0 : struct listnode *node;
9947 0 : struct srv6_locator_chunk *chunk;
9948 0 : struct bgp_srv6_function *func;
9949 :
9950 0 : bgp = bgp_get_default();
9951 0 : if (!bgp)
9952 : return CMD_SUCCESS;
9953 :
9954 0 : vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9955 0 : vty_out(vty, "locator_chunks:\n");
9956 0 : for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9957 0 : vty_out(vty, "- %pFX\n", &chunk->prefix);
9958 0 : vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
9959 0 : vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
9960 0 : vty_out(vty, " func-length: %d\n",
9961 0 : chunk->function_bits_length);
9962 0 : vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
9963 : }
9964 :
9965 0 : vty_out(vty, "functions:\n");
9966 0 : for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9967 0 : vty_out(vty, "- sid: %pI6\n", &func->sid);
9968 0 : vty_out(vty, " locator: %s\n", func->locator_name);
9969 : }
9970 :
9971 0 : vty_out(vty, "bgps:\n");
9972 0 : for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9973 0 : vty_out(vty, "- name: %s\n",
9974 0 : bgp->name ? bgp->name : "default");
9975 :
9976 0 : vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
9977 : bgp->vpn_policy[AFI_IP].tovpn_sid);
9978 0 : vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
9979 : bgp->vpn_policy[AFI_IP6].tovpn_sid);
9980 0 : vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);
9981 : }
9982 :
9983 : return CMD_SUCCESS;
9984 : }
9985 :
9986 1 : DEFUN_NOSH (exit_address_family,
9987 : exit_address_family_cmd,
9988 : "exit-address-family",
9989 : "Exit from Address Family configuration mode\n")
9990 : {
9991 1 : if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9992 1 : || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9993 : || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9994 : || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9995 : || vty->node == BGP_EVPN_NODE
9996 : || vty->node == BGP_FLOWSPECV4_NODE
9997 : || vty->node == BGP_FLOWSPECV6_NODE)
9998 1 : vty->node = BGP_NODE;
9999 1 : return CMD_SUCCESS;
10000 : }
10001 :
10002 : /* Recalculate bestpath and re-advertise a prefix */
10003 0 : static int bgp_clear_prefix(struct vty *vty, const char *view_name,
10004 : const char *ip_str, afi_t afi, safi_t safi,
10005 : struct prefix_rd *prd)
10006 : {
10007 0 : int ret;
10008 0 : struct prefix match;
10009 0 : struct bgp_dest *dest;
10010 0 : struct bgp_dest *rm;
10011 0 : struct bgp *bgp;
10012 0 : struct bgp_table *table;
10013 0 : struct bgp_table *rib;
10014 :
10015 : /* BGP structure lookup. */
10016 0 : if (view_name) {
10017 0 : bgp = bgp_lookup_by_name(view_name);
10018 0 : if (bgp == NULL) {
10019 0 : vty_out(vty, "%% Can't find BGP instance %s\n",
10020 : view_name);
10021 0 : return CMD_WARNING;
10022 : }
10023 : } else {
10024 0 : bgp = bgp_get_default();
10025 0 : if (bgp == NULL) {
10026 0 : vty_out(vty, "%% No BGP process is configured\n");
10027 0 : return CMD_WARNING;
10028 : }
10029 : }
10030 :
10031 : /* Check IP address argument. */
10032 0 : ret = str2prefix(ip_str, &match);
10033 0 : if (!ret) {
10034 0 : vty_out(vty, "%% address is malformed\n");
10035 0 : return CMD_WARNING;
10036 : }
10037 :
10038 0 : match.family = afi2family(afi);
10039 0 : rib = bgp->rib[afi][safi];
10040 :
10041 0 : if (safi == SAFI_MPLS_VPN) {
10042 0 : for (dest = bgp_table_top(rib); dest;
10043 0 : dest = bgp_route_next(dest)) {
10044 0 : const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10045 :
10046 0 : if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
10047 0 : continue;
10048 :
10049 0 : table = bgp_dest_get_bgp_table_info(dest);
10050 0 : if (table == NULL)
10051 0 : continue;
10052 :
10053 0 : rm = bgp_node_match(table, &match);
10054 0 : if (rm != NULL) {
10055 0 : const struct prefix *rm_p =
10056 0 : bgp_dest_get_prefix(rm);
10057 :
10058 0 : if (rm_p->prefixlen == match.prefixlen) {
10059 0 : SET_FLAG(rm->flags,
10060 : BGP_NODE_USER_CLEAR);
10061 0 : bgp_process(bgp, rm, afi, safi);
10062 : }
10063 0 : bgp_dest_unlock_node(rm);
10064 : }
10065 : }
10066 : } else {
10067 0 : dest = bgp_node_match(rib, &match);
10068 0 : if (dest != NULL) {
10069 0 : const struct prefix *dest_p = bgp_dest_get_prefix(dest);
10070 :
10071 0 : if (dest_p->prefixlen == match.prefixlen) {
10072 0 : SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10073 0 : bgp_process(bgp, dest, afi, safi);
10074 : }
10075 0 : bgp_dest_unlock_node(dest);
10076 : }
10077 : }
10078 :
10079 : return CMD_SUCCESS;
10080 : }
10081 :
10082 : /* one clear bgp command to rule them all */
10083 0 : DEFUN (clear_ip_bgp_all,
10084 : clear_ip_bgp_all_cmd,
10085 : "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|message-stats>]",
10086 : CLEAR_STR
10087 : IP_STR
10088 : BGP_STR
10089 : BGP_INSTANCE_HELP_STR
10090 : BGP_AFI_HELP_STR
10091 : BGP_AF_STR
10092 : BGP_SAFI_WITH_LABEL_HELP_STR
10093 : BGP_AF_MODIFIER_STR
10094 : "Clear all peers\n"
10095 : "BGP IPv4 neighbor to clear\n"
10096 : "BGP IPv6 neighbor to clear\n"
10097 : "BGP neighbor on interface to clear\n"
10098 : "Clear peers with the AS number\n"
10099 : "Clear all external peers\n"
10100 : "Clear all members of peer-group\n"
10101 : "BGP peer-group name\n"
10102 : BGP_SOFT_STR
10103 : BGP_SOFT_IN_STR
10104 : BGP_SOFT_OUT_STR
10105 : BGP_SOFT_IN_STR
10106 : "Push out prefix-list ORF and do inbound soft reconfig\n"
10107 : BGP_SOFT_OUT_STR
10108 : "Reset message statistics\n")
10109 : {
10110 0 : char *vrf = NULL;
10111 :
10112 0 : afi_t afi = AFI_UNSPEC;
10113 0 : safi_t safi = SAFI_UNSPEC;
10114 0 : enum clear_sort clr_sort = clear_peer;
10115 0 : enum bgp_clear_type clr_type;
10116 0 : char *clr_arg = NULL;
10117 :
10118 0 : int idx = 0;
10119 :
10120 : /* clear [ip] bgp */
10121 0 : if (argv_find(argv, argc, "ip", &idx))
10122 0 : afi = AFI_IP;
10123 :
10124 : /* [<vrf> VIEWVRFNAME] */
10125 0 : if (argv_find(argv, argc, "vrf", &idx)) {
10126 0 : vrf = argv[idx + 1]->arg;
10127 0 : idx += 2;
10128 0 : if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10129 0 : vrf = NULL;
10130 0 : } else if (argv_find(argv, argc, "view", &idx)) {
10131 : /* [<view> VIEWVRFNAME] */
10132 0 : vrf = argv[idx + 1]->arg;
10133 0 : idx += 2;
10134 : }
10135 : /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10136 0 : if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10137 0 : argv_find_and_parse_safi(argv, argc, &idx, &safi);
10138 :
10139 : /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
10140 0 : if (argv_find(argv, argc, "*", &idx)) {
10141 : clr_sort = clear_all;
10142 0 : } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10143 0 : clr_sort = clear_peer;
10144 0 : clr_arg = argv[idx]->arg;
10145 0 : } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10146 0 : clr_sort = clear_peer;
10147 0 : clr_arg = argv[idx]->arg;
10148 0 : } else if (argv_find(argv, argc, "peer-group", &idx)) {
10149 0 : clr_sort = clear_group;
10150 0 : idx++;
10151 0 : clr_arg = argv[idx]->arg;
10152 0 : } else if (argv_find(argv, argc, "PGNAME", &idx)) {
10153 0 : clr_sort = clear_peer;
10154 0 : clr_arg = argv[idx]->arg;
10155 0 : } else if (argv_find(argv, argc, "WORD", &idx)) {
10156 0 : clr_sort = clear_peer;
10157 0 : clr_arg = argv[idx]->arg;
10158 0 : } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10159 0 : clr_sort = clear_as;
10160 0 : clr_arg = argv[idx]->arg;
10161 0 : } else if (argv_find(argv, argc, "external", &idx)) {
10162 0 : clr_sort = clear_external;
10163 : }
10164 :
10165 : /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
10166 0 : if (argv_find(argv, argc, "soft", &idx)) {
10167 0 : if (argv_find(argv, argc, "in", &idx)
10168 0 : || argv_find(argv, argc, "out", &idx))
10169 0 : clr_type = strmatch(argv[idx]->text, "in")
10170 : ? BGP_CLEAR_SOFT_IN
10171 0 : : BGP_CLEAR_SOFT_OUT;
10172 : else
10173 : clr_type = BGP_CLEAR_SOFT_BOTH;
10174 0 : } else if (argv_find(argv, argc, "in", &idx)) {
10175 0 : clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10176 : ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10177 0 : : BGP_CLEAR_SOFT_IN;
10178 0 : } else if (argv_find(argv, argc, "out", &idx)) {
10179 : clr_type = BGP_CLEAR_SOFT_OUT;
10180 0 : } else if (argv_find(argv, argc, "message-stats", &idx)) {
10181 : clr_type = BGP_CLEAR_MESSAGE_STATS;
10182 : } else
10183 0 : clr_type = BGP_CLEAR_SOFT_NONE;
10184 :
10185 0 : return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
10186 : }
10187 :
10188 0 : DEFUN (clear_ip_bgp_prefix,
10189 : clear_ip_bgp_prefix_cmd,
10190 : "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
10191 : CLEAR_STR
10192 : IP_STR
10193 : BGP_STR
10194 : BGP_INSTANCE_HELP_STR
10195 : "Clear bestpath and re-advertise\n"
10196 : "IPv4 prefix\n")
10197 : {
10198 0 : char *vrf = NULL;
10199 0 : char *prefix = NULL;
10200 :
10201 0 : int idx = 0;
10202 :
10203 : /* [<view|vrf> VIEWVRFNAME] */
10204 0 : if (argv_find(argv, argc, "vrf", &idx)) {
10205 0 : vrf = argv[idx + 1]->arg;
10206 0 : idx += 2;
10207 0 : if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10208 0 : vrf = NULL;
10209 0 : } else if (argv_find(argv, argc, "view", &idx)) {
10210 : /* [<view> VIEWVRFNAME] */
10211 0 : vrf = argv[idx + 1]->arg;
10212 0 : idx += 2;
10213 : }
10214 :
10215 0 : prefix = argv[argc - 1]->arg;
10216 :
10217 0 : return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10218 : }
10219 :
10220 0 : DEFUN (clear_bgp_ipv6_safi_prefix,
10221 : clear_bgp_ipv6_safi_prefix_cmd,
10222 : "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10223 : CLEAR_STR
10224 : IP_STR
10225 : BGP_STR
10226 : BGP_AF_STR
10227 : BGP_SAFI_HELP_STR
10228 : "Clear bestpath and re-advertise\n"
10229 : "IPv6 prefix\n")
10230 : {
10231 0 : int idx_safi = 0;
10232 0 : int idx_ipv6_prefix = 0;
10233 0 : safi_t safi = SAFI_UNICAST;
10234 0 : char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10235 0 : argv[idx_ipv6_prefix]->arg : NULL;
10236 :
10237 0 : argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10238 0 : return bgp_clear_prefix(
10239 : vty, NULL, prefix, AFI_IP6,
10240 : safi, NULL);
10241 : }
10242 :
10243 0 : DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10244 : clear_bgp_instance_ipv6_safi_prefix_cmd,
10245 : "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10246 : CLEAR_STR
10247 : IP_STR
10248 : BGP_STR
10249 : BGP_INSTANCE_HELP_STR
10250 : BGP_AF_STR
10251 : BGP_SAFI_HELP_STR
10252 : "Clear bestpath and re-advertise\n"
10253 : "IPv6 prefix\n")
10254 : {
10255 0 : int idx_safi = 0;
10256 0 : int idx_vrfview = 0;
10257 0 : int idx_ipv6_prefix = 0;
10258 0 : safi_t safi = SAFI_UNICAST;
10259 0 : char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10260 0 : argv[idx_ipv6_prefix]->arg : NULL;
10261 0 : char *vrfview = NULL;
10262 :
10263 : /* [<view|vrf> VIEWVRFNAME] */
10264 0 : if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10265 0 : vrfview = argv[idx_vrfview + 1]->arg;
10266 0 : if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10267 0 : vrfview = NULL;
10268 0 : } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10269 : /* [<view> VIEWVRFNAME] */
10270 0 : vrfview = argv[idx_vrfview + 1]->arg;
10271 : }
10272 0 : argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10273 :
10274 0 : return bgp_clear_prefix(
10275 : vty, vrfview, prefix,
10276 : AFI_IP6, safi, NULL);
10277 : }
10278 :
10279 0 : DEFUN (show_bgp_views,
10280 : show_bgp_views_cmd,
10281 : "show [ip] bgp views",
10282 : SHOW_STR
10283 : IP_STR
10284 : BGP_STR
10285 : "Show the defined BGP views\n")
10286 : {
10287 0 : struct list *inst = bm->bgp;
10288 0 : struct listnode *node;
10289 0 : struct bgp *bgp;
10290 :
10291 0 : vty_out(vty, "Defined BGP views:\n");
10292 0 : for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10293 : /* Skip VRFs. */
10294 0 : if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10295 0 : continue;
10296 0 : vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10297 : bgp->as);
10298 : }
10299 :
10300 0 : return CMD_SUCCESS;
10301 : }
10302 :
10303 0 : static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd,
10304 : int *peers_estbd)
10305 : {
10306 0 : struct peer *peer;
10307 0 : struct listnode *node;
10308 :
10309 0 : *peers_cfgd = *peers_estbd = 0;
10310 0 : for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
10311 0 : if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10312 0 : continue;
10313 0 : (*peers_cfgd)++;
10314 0 : if (peer_established(peer))
10315 0 : (*peers_estbd)++;
10316 : }
10317 0 : }
10318 :
10319 0 : static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json,
10320 : const char *type)
10321 : {
10322 0 : int peers_cfg, peers_estb;
10323 :
10324 0 : calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10325 :
10326 0 : if (json) {
10327 0 : int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10328 : ? -1
10329 0 : : (int64_t)bgp->vrf_id;
10330 0 : json_object_string_add(json, "type", type);
10331 0 : json_object_int_add(json, "vrfId", vrf_id_ui);
10332 0 : json_object_string_addf(json, "routerId", "%pI4",
10333 : &bgp->router_id);
10334 0 : json_object_int_add(json, "numConfiguredPeers", peers_cfg);
10335 0 : json_object_int_add(json, "numEstablishedPeers", peers_estb);
10336 0 : json_object_int_add(json, "l3vni", bgp->l3vni);
10337 0 : json_object_string_addf(json, "rmac", "%pEA", &bgp->rmac);
10338 0 : json_object_string_add(
10339 : json, "interface",
10340 : ifindex2ifname(bgp->l3vni_svi_ifindex, bgp->vrf_id));
10341 : }
10342 0 : }
10343 :
10344 0 : static int show_bgp_vrfs_detail_common(struct vty *vty, struct bgp *bgp,
10345 : json_object *json, const char *name,
10346 : const char *type, bool use_vrf)
10347 : {
10348 0 : int peers_cfg, peers_estb;
10349 :
10350 0 : calc_peers_cfgd_estbd(bgp, &peers_cfg, &peers_estb);
10351 :
10352 0 : if (use_vrf) {
10353 0 : if (json) {
10354 0 : print_bgp_vrfs(bgp, vty, json, type);
10355 : } else {
10356 0 : vty_out(vty, "BGP instance %s VRF id %d\n",
10357 : bgp->name_pretty,
10358 0 : bgp->vrf_id == VRF_UNKNOWN ? -1
10359 : : (int)bgp->vrf_id);
10360 0 : vty_out(vty, "Router Id %pI4\n", &bgp->router_id);
10361 0 : vty_out(vty,
10362 : "Num Configured Peers %d, Established %d\n",
10363 : peers_cfg, peers_estb);
10364 0 : if (bgp->l3vni) {
10365 0 : vty_out(vty,
10366 : "L3VNI %u, L3VNI-SVI %s, Router MAC %pEA\n",
10367 : bgp->l3vni,
10368 : ifindex2ifname(bgp->l3vni_svi_ifindex,
10369 : bgp->vrf_id),
10370 : &bgp->rmac);
10371 : }
10372 : }
10373 : } else {
10374 0 : if (json) {
10375 0 : print_bgp_vrfs(bgp, vty, json, type);
10376 : } else {
10377 0 : vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10378 : type,
10379 0 : bgp->vrf_id == VRF_UNKNOWN ? -1
10380 : : (int)bgp->vrf_id,
10381 : &bgp->router_id, peers_cfg, peers_estb, name);
10382 0 : vty_out(vty, "%11s %-16u %-21pEA %-20s\n", " ",
10383 : bgp->l3vni, &bgp->rmac,
10384 : ifindex2ifname(bgp->l3vni_svi_ifindex,
10385 : bgp->vrf_id));
10386 : }
10387 : }
10388 :
10389 0 : return CMD_SUCCESS;
10390 : }
10391 :
10392 0 : DEFPY (show_bgp_vrfs,
10393 : show_bgp_vrfs_cmd,
10394 : "show [ip] bgp vrfs [<VRFNAME$vrf_name>] [json]",
10395 : SHOW_STR
10396 : IP_STR
10397 : BGP_STR
10398 : "Show BGP VRFs\n"
10399 : "Specific VRF name\n"
10400 : JSON_STR)
10401 : {
10402 0 : struct list *inst = bm->bgp;
10403 0 : struct listnode *node;
10404 0 : struct bgp *bgp;
10405 0 : bool uj = use_json(argc, argv);
10406 0 : json_object *json = NULL;
10407 0 : json_object *json_vrfs = NULL;
10408 0 : json_object *json_vrf = NULL;
10409 0 : int count = 0;
10410 0 : const char *name = vrf_name;
10411 0 : const char *type;
10412 :
10413 0 : if (uj)
10414 0 : json = json_object_new_object();
10415 :
10416 0 : if (name) {
10417 0 : if (strmatch(name, VRF_DEFAULT_NAME)) {
10418 0 : bgp = bgp_get_default();
10419 0 : type = "DFLT";
10420 : } else {
10421 0 : bgp = bgp_lookup_by_name(name);
10422 0 : type = "VRF";
10423 : }
10424 0 : if (!bgp) {
10425 0 : if (uj)
10426 0 : vty_json(vty, json);
10427 : else
10428 0 : vty_out(vty,
10429 : "%% Specified BGP instance not found\n");
10430 :
10431 0 : return CMD_WARNING;
10432 : }
10433 : }
10434 :
10435 0 : if (vrf_name) {
10436 0 : if (uj)
10437 0 : json_vrf = json_object_new_object();
10438 :
10439 0 : show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10440 : true);
10441 :
10442 0 : if (uj) {
10443 0 : json_object_object_add(json, name, json_vrf);
10444 0 : vty_json(vty, json);
10445 : }
10446 :
10447 0 : return CMD_SUCCESS;
10448 : }
10449 :
10450 0 : if (uj)
10451 0 : json_vrfs = json_object_new_object();
10452 :
10453 0 : for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10454 0 : const char *name;
10455 :
10456 : /* Skip Views. */
10457 0 : if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10458 0 : continue;
10459 :
10460 0 : count++;
10461 0 : if (!uj && count == 1) {
10462 0 : vty_out(vty,
10463 : "%4s %-5s %-16s %9s %10s %-37s\n",
10464 : "Type", "Id", "routerId", "#PeersCfg",
10465 : "#PeersEstb", "Name");
10466 0 : vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10467 : "L3-VNI", "RouterMAC", "Interface");
10468 : }
10469 0 : if (uj)
10470 0 : json_vrf = json_object_new_object();
10471 :
10472 0 : if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10473 0 : name = VRF_DEFAULT_NAME;
10474 0 : type = "DFLT";
10475 : } else {
10476 0 : name = bgp->name;
10477 0 : type = "VRF";
10478 : }
10479 :
10480 0 : show_bgp_vrfs_detail_common(vty, bgp, json_vrf, name, type,
10481 : false);
10482 :
10483 0 : if (uj)
10484 0 : json_object_object_add(json_vrfs, name, json_vrf);
10485 : }
10486 :
10487 0 : if (uj) {
10488 0 : json_object_object_add(json, "vrfs", json_vrfs);
10489 0 : json_object_int_add(json, "totalVrfs", count);
10490 0 : vty_json(vty, json);
10491 : } else {
10492 0 : if (count)
10493 0 : vty_out(vty,
10494 : "\nTotal number of VRFs (including default): %d\n",
10495 : count);
10496 : }
10497 :
10498 : return CMD_SUCCESS;
10499 : }
10500 :
10501 0 : DEFUN (show_bgp_mac_hash,
10502 : show_bgp_mac_hash_cmd,
10503 : "show bgp mac hash",
10504 : SHOW_STR
10505 : BGP_STR
10506 : "Mac Address\n"
10507 : "Mac Address database\n")
10508 : {
10509 0 : bgp_mac_dump_table(vty);
10510 :
10511 0 : return CMD_SUCCESS;
10512 : }
10513 :
10514 0 : static void show_tip_entry(struct hash_bucket *bucket, void *args)
10515 : {
10516 0 : struct vty *vty = (struct vty *)args;
10517 0 : struct tip_addr *tip = (struct tip_addr *)bucket->data;
10518 :
10519 0 : vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10520 0 : }
10521 :
10522 0 : static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10523 : {
10524 0 : vty_out(vty, "self nexthop database:\n");
10525 0 : bgp_nexthop_show_address_hash(vty, bgp);
10526 :
10527 0 : vty_out(vty, "Tunnel-ip database:\n");
10528 0 : hash_iterate(bgp->tip_hash,
10529 : (void (*)(struct hash_bucket *, void *))show_tip_entry,
10530 : vty);
10531 0 : }
10532 :
10533 0 : DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10534 : "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10535 : SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10536 : "martian next-hops\n"
10537 : "martian next-hop database\n")
10538 : {
10539 0 : struct bgp *bgp = NULL;
10540 0 : int idx = 0;
10541 0 : char *name = NULL;
10542 :
10543 : /* [<vrf> VIEWVRFNAME] */
10544 0 : if (argv_find(argv, argc, "vrf", &idx)) {
10545 0 : name = argv[idx + 1]->arg;
10546 0 : if (name && strmatch(name, VRF_DEFAULT_NAME))
10547 : name = NULL;
10548 0 : } else if (argv_find(argv, argc, "view", &idx))
10549 : /* [<view> VIEWVRFNAME] */
10550 0 : name = argv[idx + 1]->arg;
10551 0 : if (name)
10552 0 : bgp = bgp_lookup_by_name(name);
10553 : else
10554 0 : bgp = bgp_get_default();
10555 :
10556 0 : if (!bgp) {
10557 0 : vty_out(vty, "%% No BGP process is configured\n");
10558 0 : return CMD_WARNING;
10559 : }
10560 0 : bgp_show_martian_nexthops(vty, bgp);
10561 :
10562 0 : return CMD_SUCCESS;
10563 : }
10564 :
10565 0 : DEFUN (show_bgp_memory,
10566 : show_bgp_memory_cmd,
10567 : "show [ip] bgp memory",
10568 : SHOW_STR
10569 : IP_STR
10570 : BGP_STR
10571 : "Global BGP memory statistics\n")
10572 : {
10573 0 : char memstrbuf[MTYPE_MEMSTR_LEN];
10574 0 : unsigned long count;
10575 :
10576 : /* RIB related usage stats */
10577 0 : count = mtype_stats_alloc(MTYPE_BGP_NODE);
10578 0 : vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10579 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10580 : count * sizeof(struct bgp_dest)));
10581 :
10582 0 : count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10583 0 : vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10584 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10585 : count * sizeof(struct bgp_path_info)));
10586 0 : if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10587 0 : vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10588 : count,
10589 : mtype_memstr(
10590 : memstrbuf, sizeof(memstrbuf),
10591 : count * sizeof(struct bgp_path_info_extra)));
10592 :
10593 0 : if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10594 0 : vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10595 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10596 : count * sizeof(struct bgp_static)));
10597 :
10598 0 : if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10599 0 : vty_out(vty, "%ld Packets, using %s of memory\n", count,
10600 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10601 : count * sizeof(struct bpacket)));
10602 :
10603 : /* Adj-In/Out */
10604 0 : if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10605 0 : vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10606 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10607 : count * sizeof(struct bgp_adj_in)));
10608 0 : if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10609 0 : vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10610 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10611 : count * sizeof(struct bgp_adj_out)));
10612 :
10613 0 : if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10614 0 : vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10615 : count,
10616 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10617 : count * sizeof(struct bgp_nexthop_cache)));
10618 :
10619 0 : if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10620 0 : vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10621 : count,
10622 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10623 : count * sizeof(struct bgp_damp_info)));
10624 :
10625 : /* Attributes */
10626 0 : count = attr_count();
10627 0 : vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10628 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10629 : count * sizeof(struct attr)));
10630 :
10631 0 : if ((count = attr_unknown_count()))
10632 0 : vty_out(vty, "%ld unknown attributes\n", count);
10633 :
10634 : /* AS_PATH attributes */
10635 0 : count = aspath_count();
10636 0 : vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10637 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10638 : count * sizeof(struct aspath)));
10639 :
10640 0 : count = mtype_stats_alloc(MTYPE_AS_SEG);
10641 0 : vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10642 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10643 : count * sizeof(struct assegment)));
10644 :
10645 : /* Other attributes */
10646 0 : if ((count = community_count()))
10647 0 : vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10648 : count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10649 : count * sizeof(struct community)));
10650 0 : if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10651 0 : vty_out(vty,
10652 : "%ld BGP ext-community entries, using %s of memory\n",
10653 : count,
10654 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10655 : count * sizeof(struct ecommunity)));
10656 0 : if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10657 0 : vty_out(vty,
10658 : "%ld BGP large-community entries, using %s of memory\n",
10659 : count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10660 : count * sizeof(struct lcommunity)));
10661 :
10662 0 : if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10663 0 : vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10664 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10665 : count * sizeof(struct cluster_list)));
10666 :
10667 : /* Peer related usage */
10668 0 : count = mtype_stats_alloc(MTYPE_BGP_PEER);
10669 0 : vty_out(vty, "%ld peers, using %s of memory\n", count,
10670 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10671 : count * sizeof(struct peer)));
10672 :
10673 0 : if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10674 0 : vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10675 : mtype_memstr(memstrbuf, sizeof(memstrbuf),
10676 : count * sizeof(struct peer_group)));
10677 :
10678 : /* Other */
10679 0 : if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10680 0 : vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10681 : count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10682 : count * sizeof(regex_t)));
10683 0 : return CMD_SUCCESS;
10684 : }
10685 :
10686 0 : static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10687 : {
10688 0 : json_object *bestpath = json_object_new_object();
10689 :
10690 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10691 0 : json_object_string_add(bestpath, "asPath", "ignore");
10692 :
10693 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10694 0 : json_object_string_add(bestpath, "asPath", "confed");
10695 :
10696 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10697 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10698 0 : json_object_string_add(bestpath, "multiPathRelax",
10699 : "as-set");
10700 : else
10701 0 : json_object_string_add(bestpath, "multiPathRelax",
10702 : "true");
10703 : } else
10704 0 : json_object_string_add(bestpath, "multiPathRelax", "false");
10705 :
10706 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10707 0 : json_object_boolean_true_add(bestpath, "peerTypeRelax");
10708 :
10709 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10710 0 : json_object_string_add(bestpath, "compareRouterId", "true");
10711 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10712 0 : || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10713 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10714 0 : json_object_string_add(bestpath, "med", "confed");
10715 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10716 0 : json_object_string_add(bestpath, "med",
10717 : "missing-as-worst");
10718 : else
10719 0 : json_object_string_add(bestpath, "med", "true");
10720 : }
10721 :
10722 0 : json_object_object_add(json, "bestPath", bestpath);
10723 0 : }
10724 :
10725 : /* Print the error code/subcode for why the peer is down */
10726 27 : static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10727 : json_object *json_peer, bool use_json)
10728 : {
10729 27 : const char *code_str;
10730 27 : const char *subcode_str;
10731 :
10732 27 : if (use_json) {
10733 27 : if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10734 27 : || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10735 0 : char errorcodesubcode_hexstr[5];
10736 0 : char errorcodesubcode_str[256];
10737 :
10738 0 : code_str = bgp_notify_code_str(peer->notify.code);
10739 0 : subcode_str = bgp_notify_subcode_str(
10740 0 : peer->notify.code,
10741 0 : peer->notify.subcode);
10742 :
10743 0 : snprintf(errorcodesubcode_hexstr,
10744 : sizeof(errorcodesubcode_hexstr), "%02X%02X",
10745 0 : peer->notify.code, peer->notify.subcode);
10746 0 : json_object_string_add(json_peer,
10747 : "lastErrorCodeSubcode",
10748 : errorcodesubcode_hexstr);
10749 0 : snprintf(errorcodesubcode_str, 255, "%s%s",
10750 : code_str, subcode_str);
10751 0 : json_object_string_add(json_peer,
10752 : "lastNotificationReason",
10753 : errorcodesubcode_str);
10754 0 : json_object_boolean_add(json_peer,
10755 : "lastNotificationHardReset",
10756 0 : peer->notify.hard_reset);
10757 0 : if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10758 0 : && peer->notify.code == BGP_NOTIFY_CEASE
10759 0 : && (peer->notify.subcode
10760 : == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10761 0 : || peer->notify.subcode
10762 : == BGP_NOTIFY_CEASE_ADMIN_RESET)
10763 0 : && peer->notify.length) {
10764 0 : char msgbuf[1024];
10765 0 : const char *msg_str;
10766 :
10767 0 : msg_str = bgp_notify_admin_message(
10768 : msgbuf, sizeof(msgbuf),
10769 0 : (uint8_t *)peer->notify.data,
10770 : peer->notify.length);
10771 0 : if (msg_str)
10772 0 : json_object_string_add(
10773 : json_peer,
10774 : "lastShutdownDescription",
10775 : msg_str);
10776 : }
10777 :
10778 : }
10779 27 : json_object_string_add(json_peer, "lastResetDueTo",
10780 27 : peer_down_str[(int)peer->last_reset]);
10781 27 : json_object_int_add(json_peer, "lastResetCode",
10782 27 : peer->last_reset);
10783 : } else {
10784 0 : if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10785 0 : || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10786 0 : code_str = bgp_notify_code_str(peer->notify.code);
10787 0 : subcode_str =
10788 0 : bgp_notify_subcode_str(peer->notify.code,
10789 0 : peer->notify.subcode);
10790 0 : vty_out(vty, " Notification %s (%s%s%s)\n",
10791 0 : peer->last_reset == PEER_DOWN_NOTIFY_SEND
10792 : ? "sent"
10793 : : "received",
10794 : code_str, subcode_str,
10795 0 : peer->notify.hard_reset
10796 0 : ? bgp_notify_subcode_str(
10797 : BGP_NOTIFY_CEASE,
10798 : BGP_NOTIFY_CEASE_HARD_RESET)
10799 : : "");
10800 : } else {
10801 0 : vty_out(vty, " %s\n",
10802 0 : peer_down_str[(int)peer->last_reset]);
10803 : }
10804 : }
10805 27 : }
10806 :
10807 0 : static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10808 : safi_t safi)
10809 : {
10810 0 : return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10811 : }
10812 :
10813 0 : static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10814 : struct peer *peer, json_object *json_peer,
10815 : int max_neighbor_width, bool use_json)
10816 : {
10817 0 : char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10818 0 : int len;
10819 :
10820 0 : if (use_json) {
10821 0 : if (peer_dynamic_neighbor(peer))
10822 0 : json_object_boolean_true_add(json_peer,
10823 : "dynamicPeer");
10824 0 : if (peer->hostname)
10825 0 : json_object_string_add(json_peer, "hostname",
10826 : peer->hostname);
10827 :
10828 0 : if (peer->domainname)
10829 0 : json_object_string_add(json_peer, "domainname",
10830 : peer->domainname);
10831 0 : json_object_int_add(json_peer, "connectionsEstablished",
10832 0 : peer->established);
10833 0 : json_object_int_add(json_peer, "connectionsDropped",
10834 0 : peer->dropped);
10835 0 : peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10836 : use_json, json_peer);
10837 0 : if (peer_established(peer))
10838 0 : json_object_string_add(json_peer, "lastResetDueTo",
10839 : "AFI/SAFI Not Negotiated");
10840 : else
10841 0 : bgp_show_peer_reset(NULL, peer, json_peer, true);
10842 : } else {
10843 0 : dn_flag[1] = '\0';
10844 0 : dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10845 0 : if (peer->hostname
10846 0 : && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10847 0 : len = vty_out(vty, "%s%s(%s)", dn_flag,
10848 : peer->hostname, peer->host);
10849 : else
10850 0 : len = vty_out(vty, "%s%s", dn_flag, peer->host);
10851 :
10852 : /* pad the neighbor column with spaces */
10853 0 : if (len < max_neighbor_width)
10854 0 : vty_out(vty, "%*s", max_neighbor_width - len,
10855 : " ");
10856 0 : vty_out(vty, "%7d %7d %9s", peer->established,
10857 : peer->dropped,
10858 : peer_uptime(peer->uptime, timebuf,
10859 : BGP_UPTIME_LEN, 0, NULL));
10860 0 : if (peer_established(peer))
10861 0 : vty_out(vty, " AFI/SAFI Not Negotiated\n");
10862 : else
10863 0 : bgp_show_peer_reset(vty, peer, NULL,
10864 : false);
10865 : }
10866 0 : }
10867 :
10868 : /* Strip peer's description to the given size. */
10869 0 : static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10870 : {
10871 0 : static char stripped[BUFSIZ];
10872 0 : uint32_t i = 0;
10873 0 : uint32_t last_space = 0;
10874 :
10875 0 : while (i < size) {
10876 0 : if (*(desc + i) == 0) {
10877 0 : stripped[i] = '\0';
10878 0 : return stripped;
10879 : }
10880 0 : if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10881 0 : last_space = i;
10882 0 : stripped[i] = *(desc + i);
10883 0 : i++;
10884 : }
10885 :
10886 0 : if (last_space > size)
10887 0 : stripped[size + 1] = '\0';
10888 : else
10889 0 : stripped[last_space] = '\0';
10890 :
10891 : return stripped;
10892 : }
10893 :
10894 : /* Determine whether var peer should be filtered out of the summary. */
10895 0 : static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10896 : struct peer *fpeer, int as_type,
10897 : as_t as)
10898 : {
10899 :
10900 : /* filter neighbor XXXX */
10901 0 : if (fpeer && fpeer != peer)
10902 : return true;
10903 :
10904 : /* filter remote-as (internal|external) */
10905 0 : if (as_type != AS_UNSPECIFIED) {
10906 0 : if (peer->as_type == AS_SPECIFIED) {
10907 0 : if (as_type == AS_INTERNAL) {
10908 0 : if (peer->as != peer->local_as)
10909 0 : return true;
10910 0 : } else if (peer->as == peer->local_as)
10911 0 : return true;
10912 0 : } else if (as_type != peer->as_type)
10913 0 : return true;
10914 0 : } else if (as && as != peer->as) /* filter remote-as XXX */
10915 0 : return true;
10916 :
10917 : return false;
10918 : }
10919 :
10920 : /* Show BGP peer's summary information.
10921 : *
10922 : * Peer's description is stripped according to if `wide` option is given
10923 : * or not.
10924 : *
10925 : * When adding new columns to `show bgp summary` output, please make
10926 : * sure `Desc` is the lastest column to show because it can contain
10927 : * whitespaces and the whole output will be tricky.
10928 : */
10929 0 : static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10930 : struct peer *fpeer, int as_type, as_t as,
10931 : uint16_t show_flags)
10932 : {
10933 0 : struct peer *peer;
10934 0 : struct listnode *node, *nnode;
10935 0 : unsigned int count = 0, dn_count = 0;
10936 0 : char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10937 0 : char neighbor_buf[VTY_BUFSIZ];
10938 0 : int neighbor_col_default_width = 16;
10939 0 : int len, failed_count = 0;
10940 0 : unsigned int filtered_count = 0;
10941 0 : int max_neighbor_width = 0;
10942 0 : int pfx_rcd_safi;
10943 0 : json_object *json = NULL;
10944 0 : json_object *json_peer = NULL;
10945 0 : json_object *json_peers = NULL;
10946 0 : struct peer_af *paf;
10947 0 : struct bgp_filter *filter;
10948 0 : bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10949 0 : bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10950 0 : bool show_established =
10951 : CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10952 0 : bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10953 0 : bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10954 :
10955 : /* labeled-unicast routes are installed in the unicast table so in order
10956 : * to
10957 : * display the correct PfxRcd value we must look at SAFI_UNICAST
10958 : */
10959 :
10960 0 : if (safi == SAFI_LABELED_UNICAST)
10961 : pfx_rcd_safi = SAFI_UNICAST;
10962 : else
10963 0 : pfx_rcd_safi = safi;
10964 :
10965 0 : if (use_json) {
10966 0 : json = json_object_new_object();
10967 0 : json_peers = json_object_new_object();
10968 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10969 0 : if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10970 : as_type, as)) {
10971 0 : filtered_count++;
10972 0 : count++;
10973 0 : continue;
10974 : }
10975 :
10976 0 : if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10977 0 : continue;
10978 :
10979 0 : if (peer->afc[afi][safi]) {
10980 : /* See if we have at least a single failed peer */
10981 0 : if (bgp_has_peer_failed(peer, afi, safi))
10982 0 : failed_count++;
10983 0 : count++;
10984 : }
10985 0 : if (peer_dynamic_neighbor(peer))
10986 0 : dn_count++;
10987 : }
10988 :
10989 : } else {
10990 : /* Loop over all neighbors that will be displayed to determine
10991 : * how many
10992 : * characters are needed for the Neighbor column
10993 : */
10994 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10995 0 : if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10996 : as_type, as)) {
10997 0 : filtered_count++;
10998 0 : count++;
10999 0 : continue;
11000 : }
11001 :
11002 0 : if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11003 0 : continue;
11004 :
11005 0 : if (peer->afc[afi][safi]) {
11006 0 : memset(dn_flag, '\0', sizeof(dn_flag));
11007 0 : if (peer_dynamic_neighbor(peer))
11008 0 : dn_flag[0] = '*';
11009 :
11010 0 : if (peer->hostname
11011 0 : && CHECK_FLAG(bgp->flags,
11012 : BGP_FLAG_SHOW_HOSTNAME))
11013 0 : snprintf(neighbor_buf,
11014 : sizeof(neighbor_buf),
11015 : "%s%s(%s) ", dn_flag,
11016 : peer->hostname, peer->host);
11017 : else
11018 0 : snprintf(neighbor_buf,
11019 : sizeof(neighbor_buf), "%s%s ",
11020 : dn_flag, peer->host);
11021 :
11022 0 : len = strlen(neighbor_buf);
11023 :
11024 0 : if (len > max_neighbor_width)
11025 : max_neighbor_width = len;
11026 :
11027 : /* See if we have at least a single failed peer */
11028 0 : if (bgp_has_peer_failed(peer, afi, safi))
11029 0 : failed_count++;
11030 0 : count++;
11031 : }
11032 : }
11033 :
11034 : /* Originally we displayed the Neighbor column as 16
11035 : * characters wide so make that the default
11036 : */
11037 0 : if (max_neighbor_width < neighbor_col_default_width)
11038 : max_neighbor_width = neighbor_col_default_width;
11039 : }
11040 :
11041 0 : if (show_failed && !failed_count) {
11042 0 : if (use_json) {
11043 0 : json_object_int_add(json, "failedPeersCount", 0);
11044 0 : json_object_int_add(json, "dynamicPeers", dn_count);
11045 0 : json_object_int_add(json, "totalPeers", count);
11046 :
11047 0 : vty_json(vty, json);
11048 : } else {
11049 0 : vty_out(vty, "%% No failed BGP neighbors found\n");
11050 : }
11051 0 : return CMD_SUCCESS;
11052 : }
11053 :
11054 0 : count = 0; /* Reset the value as its used again */
11055 0 : filtered_count = 0;
11056 0 : dn_count = 0;
11057 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11058 0 : if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11059 0 : continue;
11060 :
11061 0 : if (!peer->afc[afi][safi])
11062 0 : continue;
11063 :
11064 0 : if (!count) {
11065 0 : unsigned long ents;
11066 0 : char memstrbuf[MTYPE_MEMSTR_LEN];
11067 0 : int64_t vrf_id_ui;
11068 :
11069 0 : vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
11070 : ? -1
11071 0 : : (int64_t)bgp->vrf_id;
11072 :
11073 : /* Usage summary and header */
11074 0 : if (use_json) {
11075 0 : json_object_string_addf(json, "routerId",
11076 : "%pI4",
11077 : &bgp->router_id);
11078 0 : json_object_int_add(json, "as", bgp->as);
11079 0 : json_object_int_add(json, "vrfId", vrf_id_ui);
11080 0 : json_object_string_add(
11081 : json, "vrfName",
11082 0 : (bgp->inst_type
11083 : == BGP_INSTANCE_TYPE_DEFAULT)
11084 0 : ? VRF_DEFAULT_NAME
11085 : : bgp->name);
11086 : } else {
11087 0 : vty_out(vty,
11088 : "BGP router identifier %pI4, local AS number %u vrf-id %d",
11089 : &bgp->router_id, bgp->as,
11090 : bgp->vrf_id == VRF_UNKNOWN
11091 : ? -1
11092 : : (int)bgp->vrf_id);
11093 0 : vty_out(vty, "\n");
11094 : }
11095 :
11096 0 : if (bgp_update_delay_configured(bgp)) {
11097 0 : if (use_json) {
11098 0 : json_object_int_add(
11099 : json, "updateDelayLimit",
11100 0 : bgp->v_update_delay);
11101 :
11102 0 : if (bgp->v_update_delay
11103 0 : != bgp->v_establish_wait)
11104 0 : json_object_int_add(
11105 : json,
11106 : "updateDelayEstablishWait",
11107 : bgp->v_establish_wait);
11108 :
11109 0 : if (bgp_update_delay_active(bgp)) {
11110 0 : json_object_string_add(
11111 : json,
11112 : "updateDelayFirstNeighbor",
11113 0 : bgp->update_delay_begin_time);
11114 0 : json_object_boolean_true_add(
11115 : json,
11116 : "updateDelayInProgress");
11117 : } else {
11118 0 : if (bgp->update_delay_over) {
11119 0 : json_object_string_add(
11120 : json,
11121 : "updateDelayFirstNeighbor",
11122 0 : bgp->update_delay_begin_time);
11123 0 : json_object_string_add(
11124 : json,
11125 : "updateDelayBestpathResumed",
11126 0 : bgp->update_delay_end_time);
11127 0 : json_object_string_add(
11128 : json,
11129 : "updateDelayZebraUpdateResume",
11130 0 : bgp->update_delay_zebra_resume_time);
11131 0 : json_object_string_add(
11132 : json,
11133 : "updateDelayPeerUpdateResume",
11134 0 : bgp->update_delay_peers_resume_time);
11135 : }
11136 : }
11137 : } else {
11138 0 : vty_out(vty,
11139 : "Read-only mode update-delay limit: %d seconds\n",
11140 0 : bgp->v_update_delay);
11141 0 : if (bgp->v_update_delay
11142 0 : != bgp->v_establish_wait)
11143 0 : vty_out(vty,
11144 : " Establish wait: %d seconds\n",
11145 : bgp->v_establish_wait);
11146 :
11147 0 : if (bgp_update_delay_active(bgp)) {
11148 0 : vty_out(vty,
11149 : " First neighbor established: %s\n",
11150 0 : bgp->update_delay_begin_time);
11151 0 : vty_out(vty,
11152 : " Delay in progress\n");
11153 : } else {
11154 0 : if (bgp->update_delay_over) {
11155 0 : vty_out(vty,
11156 : " First neighbor established: %s\n",
11157 0 : bgp->update_delay_begin_time);
11158 0 : vty_out(vty,
11159 : " Best-paths resumed: %s\n",
11160 0 : bgp->update_delay_end_time);
11161 0 : vty_out(vty,
11162 : " zebra update resumed: %s\n",
11163 0 : bgp->update_delay_zebra_resume_time);
11164 0 : vty_out(vty,
11165 : " peers update resumed: %s\n",
11166 0 : bgp->update_delay_peers_resume_time);
11167 : }
11168 : }
11169 : }
11170 : }
11171 :
11172 0 : if (use_json) {
11173 0 : if (bgp_maxmed_onstartup_configured(bgp)
11174 0 : && bgp->maxmed_active)
11175 0 : json_object_boolean_true_add(
11176 : json, "maxMedOnStartup");
11177 0 : if (bgp->v_maxmed_admin)
11178 0 : json_object_boolean_true_add(
11179 : json, "maxMedAdministrative");
11180 :
11181 0 : json_object_int_add(
11182 : json, "tableVersion",
11183 0 : bgp_table_version(bgp->rib[afi][safi]));
11184 :
11185 0 : ents = bgp_table_count(bgp->rib[afi][safi]);
11186 0 : json_object_int_add(json, "ribCount", ents);
11187 0 : json_object_int_add(
11188 : json, "ribMemory",
11189 0 : ents * sizeof(struct bgp_dest));
11190 :
11191 0 : ents = bgp->af_peer_count[afi][safi];
11192 0 : json_object_int_add(json, "peerCount", ents);
11193 0 : json_object_int_add(json, "peerMemory",
11194 0 : ents * sizeof(struct peer));
11195 :
11196 0 : if ((ents = listcount(bgp->group))) {
11197 0 : json_object_int_add(
11198 : json, "peerGroupCount", ents);
11199 0 : json_object_int_add(
11200 : json, "peerGroupMemory",
11201 0 : ents * sizeof(struct
11202 : peer_group));
11203 : }
11204 :
11205 0 : if (CHECK_FLAG(bgp->af_flags[afi][safi],
11206 : BGP_CONFIG_DAMPENING))
11207 0 : json_object_boolean_true_add(
11208 : json, "dampeningEnabled");
11209 : } else {
11210 0 : if (!show_terse) {
11211 0 : if (bgp_maxmed_onstartup_configured(bgp)
11212 0 : && bgp->maxmed_active)
11213 0 : vty_out(vty,
11214 : "Max-med on-startup active\n");
11215 0 : if (bgp->v_maxmed_admin)
11216 0 : vty_out(vty,
11217 : "Max-med administrative active\n");
11218 :
11219 0 : vty_out(vty,
11220 : "BGP table version %" PRIu64
11221 : "\n",
11222 : bgp_table_version(
11223 : bgp->rib[afi][safi]));
11224 :
11225 0 : ents = bgp_table_count(
11226 0 : bgp->rib[afi][safi]);
11227 0 : vty_out(vty,
11228 : "RIB entries %ld, using %s of memory\n",
11229 : ents,
11230 : mtype_memstr(
11231 : memstrbuf,
11232 : sizeof(memstrbuf),
11233 : ents
11234 : * sizeof(
11235 : struct
11236 : bgp_dest)));
11237 :
11238 : /* Peer related usage */
11239 0 : ents = bgp->af_peer_count[afi][safi];
11240 0 : vty_out(vty,
11241 : "Peers %ld, using %s of memory\n",
11242 : ents,
11243 : mtype_memstr(
11244 : memstrbuf,
11245 : sizeof(memstrbuf),
11246 : ents
11247 : * sizeof(
11248 : struct
11249 : peer)));
11250 :
11251 0 : if ((ents = listcount(bgp->group)))
11252 0 : vty_out(vty,
11253 : "Peer groups %ld, using %s of memory\n",
11254 : ents,
11255 : mtype_memstr(
11256 : memstrbuf,
11257 : sizeof(memstrbuf),
11258 : ents
11259 : * sizeof(
11260 : struct
11261 : peer_group)));
11262 :
11263 0 : if (CHECK_FLAG(bgp->af_flags[afi][safi],
11264 : BGP_CONFIG_DAMPENING))
11265 0 : vty_out(vty,
11266 : "Dampening enabled.\n");
11267 : }
11268 0 : if (show_failed) {
11269 0 : vty_out(vty, "\n");
11270 :
11271 : /* Subtract 8 here because 'Neighbor' is
11272 : * 8 characters */
11273 0 : vty_out(vty, "Neighbor");
11274 0 : vty_out(vty, "%*s",
11275 : max_neighbor_width - 8, " ");
11276 0 : vty_out(vty,
11277 : BGP_SHOW_SUMMARY_HEADER_FAILED);
11278 : }
11279 : }
11280 : }
11281 :
11282 0 : paf = peer_af_find(peer, afi, safi);
11283 0 : filter = &peer->filter[afi][safi];
11284 :
11285 0 : count++;
11286 : /* Works for both failed & successful cases */
11287 0 : if (peer_dynamic_neighbor(peer))
11288 0 : dn_count++;
11289 :
11290 0 : if (use_json) {
11291 0 : json_peer = NULL;
11292 0 : if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11293 : as_type, as)) {
11294 0 : filtered_count++;
11295 0 : continue;
11296 : }
11297 0 : if (show_failed &&
11298 0 : bgp_has_peer_failed(peer, afi, safi)) {
11299 0 : json_peer = json_object_new_object();
11300 0 : bgp_show_failed_summary(vty, bgp, peer,
11301 : json_peer, 0, use_json);
11302 0 : } else if (!show_failed) {
11303 0 : if (show_established
11304 0 : && bgp_has_peer_failed(peer, afi, safi)) {
11305 0 : filtered_count++;
11306 0 : continue;
11307 : }
11308 :
11309 0 : json_peer = json_object_new_object();
11310 0 : if (peer_dynamic_neighbor(peer)) {
11311 0 : json_object_boolean_true_add(json_peer,
11312 : "dynamicPeer");
11313 : }
11314 :
11315 0 : if (peer->hostname)
11316 0 : json_object_string_add(json_peer, "hostname",
11317 : peer->hostname);
11318 :
11319 0 : if (peer->domainname)
11320 0 : json_object_string_add(json_peer, "domainname",
11321 : peer->domainname);
11322 :
11323 0 : json_object_int_add(json_peer, "remoteAs", peer->as);
11324 0 : json_object_int_add(
11325 : json_peer, "localAs",
11326 0 : peer->change_local_as
11327 : ? peer->change_local_as
11328 0 : : peer->local_as);
11329 0 : json_object_int_add(json_peer, "version", 4);
11330 0 : json_object_int_add(json_peer, "msgRcvd",
11331 0 : PEER_TOTAL_RX(peer));
11332 0 : json_object_int_add(json_peer, "msgSent",
11333 0 : PEER_TOTAL_TX(peer));
11334 :
11335 0 : atomic_size_t outq_count, inq_count;
11336 0 : outq_count = atomic_load_explicit(
11337 : &peer->obuf->count,
11338 : memory_order_relaxed);
11339 0 : inq_count = atomic_load_explicit(
11340 : &peer->ibuf->count,
11341 : memory_order_relaxed);
11342 :
11343 0 : json_object_int_add(json_peer, "tableVersion",
11344 0 : peer->version[afi][safi]);
11345 0 : json_object_int_add(json_peer, "outq",
11346 0 : outq_count);
11347 0 : json_object_int_add(json_peer, "inq",
11348 0 : inq_count);
11349 0 : peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11350 : use_json, json_peer);
11351 :
11352 0 : json_object_int_add(json_peer, "pfxRcd",
11353 0 : peer->pcount[afi][pfx_rcd_safi]);
11354 :
11355 0 : if (paf && PAF_SUBGRP(paf))
11356 0 : json_object_int_add(
11357 : json_peer, "pfxSnt",
11358 0 : (PAF_SUBGRP(paf))->scount);
11359 : else
11360 0 : json_object_int_add(json_peer, "pfxSnt",
11361 : 0);
11362 :
11363 : /* BGP FSM state */
11364 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11365 0 : || CHECK_FLAG(peer->bgp->flags,
11366 : BGP_FLAG_SHUTDOWN))
11367 0 : json_object_string_add(json_peer,
11368 : "state",
11369 : "Idle (Admin)");
11370 0 : else if (peer->afc_recv[afi][safi])
11371 0 : json_object_string_add(
11372 : json_peer, "state",
11373 : lookup_msg(bgp_status_msg,
11374 0 : peer->status, NULL));
11375 0 : else if (CHECK_FLAG(
11376 : peer->sflags,
11377 : PEER_STATUS_PREFIX_OVERFLOW))
11378 0 : json_object_string_add(json_peer,
11379 : "state",
11380 : "Idle (PfxCt)");
11381 : else
11382 0 : json_object_string_add(
11383 : json_peer, "state",
11384 : lookup_msg(bgp_status_msg,
11385 0 : peer->status, NULL));
11386 :
11387 : /* BGP peer state */
11388 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11389 0 : || CHECK_FLAG(peer->bgp->flags,
11390 : BGP_FLAG_SHUTDOWN))
11391 0 : json_object_string_add(json_peer,
11392 : "peerState",
11393 : "Admin");
11394 0 : else if (CHECK_FLAG(
11395 : peer->sflags,
11396 : PEER_STATUS_PREFIX_OVERFLOW))
11397 0 : json_object_string_add(json_peer,
11398 : "peerState",
11399 : "PfxCt");
11400 0 : else if (CHECK_FLAG(peer->flags,
11401 : PEER_FLAG_PASSIVE))
11402 0 : json_object_string_add(json_peer,
11403 : "peerState",
11404 : "Passive");
11405 0 : else if (CHECK_FLAG(peer->sflags,
11406 : PEER_STATUS_NSF_WAIT))
11407 0 : json_object_string_add(json_peer,
11408 : "peerState",
11409 : "NSF passive");
11410 0 : else if (CHECK_FLAG(
11411 : peer->bgp->flags,
11412 : BGP_FLAG_EBGP_REQUIRES_POLICY)
11413 0 : && (!bgp_inbound_policy_exists(peer,
11414 : filter)
11415 0 : || !bgp_outbound_policy_exists(
11416 : peer, filter)))
11417 0 : json_object_string_add(json_peer,
11418 : "peerState",
11419 : "Policy");
11420 : else
11421 0 : json_object_string_add(
11422 : json_peer, "peerState", "OK");
11423 :
11424 0 : json_object_int_add(json_peer, "connectionsEstablished",
11425 0 : peer->established);
11426 0 : json_object_int_add(json_peer, "connectionsDropped",
11427 0 : peer->dropped);
11428 0 : if (peer->desc)
11429 0 : json_object_string_add(
11430 : json_peer, "desc", peer->desc);
11431 : }
11432 : /* Avoid creating empty peer dicts in JSON */
11433 0 : if (json_peer == NULL)
11434 0 : continue;
11435 :
11436 0 : if (peer->conf_if)
11437 0 : json_object_string_add(json_peer, "idType",
11438 : "interface");
11439 0 : else if (peer->su.sa.sa_family == AF_INET)
11440 0 : json_object_string_add(json_peer, "idType",
11441 : "ipv4");
11442 0 : else if (peer->su.sa.sa_family == AF_INET6)
11443 0 : json_object_string_add(json_peer, "idType",
11444 : "ipv6");
11445 0 : json_object_object_add(json_peers, peer->host,
11446 : json_peer);
11447 : } else {
11448 0 : if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11449 : as_type, as)) {
11450 0 : filtered_count++;
11451 0 : continue;
11452 : }
11453 0 : if (show_failed &&
11454 0 : bgp_has_peer_failed(peer, afi, safi)) {
11455 0 : bgp_show_failed_summary(vty, bgp, peer, NULL,
11456 : max_neighbor_width,
11457 : use_json);
11458 0 : } else if (!show_failed) {
11459 0 : if (show_established
11460 0 : && bgp_has_peer_failed(peer, afi, safi)) {
11461 0 : filtered_count++;
11462 0 : continue;
11463 : }
11464 :
11465 0 : if ((count - filtered_count) == 1) {
11466 : /* display headline before the first
11467 : * neighbor line */
11468 0 : vty_out(vty, "\n");
11469 :
11470 : /* Subtract 8 here because 'Neighbor' is
11471 : * 8 characters */
11472 0 : vty_out(vty, "Neighbor");
11473 0 : vty_out(vty, "%*s",
11474 : max_neighbor_width - 8, " ");
11475 0 : vty_out(vty,
11476 : show_wide
11477 : ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11478 : : BGP_SHOW_SUMMARY_HEADER_ALL);
11479 : }
11480 :
11481 0 : memset(dn_flag, '\0', sizeof(dn_flag));
11482 0 : if (peer_dynamic_neighbor(peer)) {
11483 0 : dn_flag[0] = '*';
11484 : }
11485 :
11486 0 : if (peer->hostname
11487 0 : && CHECK_FLAG(bgp->flags,
11488 : BGP_FLAG_SHOW_HOSTNAME))
11489 0 : len = vty_out(vty, "%s%s(%s)", dn_flag,
11490 : peer->hostname,
11491 : peer->host);
11492 : else
11493 0 : len = vty_out(vty, "%s%s", dn_flag, peer->host);
11494 :
11495 : /* pad the neighbor column with spaces */
11496 0 : if (len < max_neighbor_width)
11497 0 : vty_out(vty, "%*s", max_neighbor_width - len,
11498 : " ");
11499 :
11500 0 : atomic_size_t outq_count, inq_count;
11501 0 : outq_count = atomic_load_explicit(
11502 : &peer->obuf->count,
11503 : memory_order_relaxed);
11504 0 : inq_count = atomic_load_explicit(
11505 : &peer->ibuf->count,
11506 : memory_order_relaxed);
11507 :
11508 0 : if (show_wide)
11509 0 : vty_out(vty,
11510 : "4 %10u %10u %9u %9u %8" PRIu64
11511 : " %4zu %4zu %8s",
11512 : peer->as,
11513 0 : peer->change_local_as
11514 : ? peer->change_local_as
11515 : : peer->local_as,
11516 0 : PEER_TOTAL_RX(peer),
11517 0 : PEER_TOTAL_TX(peer),
11518 : peer->version[afi][safi],
11519 0 : inq_count, outq_count,
11520 : peer_uptime(peer->uptime,
11521 : timebuf,
11522 : BGP_UPTIME_LEN, 0,
11523 : NULL));
11524 : else
11525 0 : vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11526 : " %4zu %4zu %8s",
11527 0 : peer->as, PEER_TOTAL_RX(peer),
11528 0 : PEER_TOTAL_TX(peer),
11529 : peer->version[afi][safi],
11530 0 : inq_count, outq_count,
11531 : peer_uptime(peer->uptime,
11532 : timebuf,
11533 : BGP_UPTIME_LEN, 0,
11534 : NULL));
11535 :
11536 0 : if (peer_established(peer)) {
11537 0 : if (peer->afc_recv[afi][safi]) {
11538 0 : if (CHECK_FLAG(
11539 : bgp->flags,
11540 : BGP_FLAG_EBGP_REQUIRES_POLICY)
11541 0 : && !bgp_inbound_policy_exists(
11542 : peer, filter))
11543 0 : vty_out(vty, " %12s",
11544 : "(Policy)");
11545 : else
11546 0 : vty_out(vty,
11547 : " %12u",
11548 : peer->pcount
11549 : [afi]
11550 : [pfx_rcd_safi]);
11551 : } else {
11552 0 : vty_out(vty, " NoNeg");
11553 : }
11554 :
11555 0 : if (paf && PAF_SUBGRP(paf)) {
11556 0 : if (CHECK_FLAG(
11557 : bgp->flags,
11558 : BGP_FLAG_EBGP_REQUIRES_POLICY)
11559 0 : && !bgp_outbound_policy_exists(
11560 : peer, filter))
11561 0 : vty_out(vty, " %8s",
11562 : "(Policy)");
11563 : else
11564 0 : vty_out(vty,
11565 : " %8u",
11566 0 : (PAF_SUBGRP(
11567 : paf))
11568 : ->scount);
11569 : } else {
11570 0 : vty_out(vty, " NoNeg");
11571 : }
11572 : } else {
11573 0 : if (CHECK_FLAG(peer->flags,
11574 : PEER_FLAG_SHUTDOWN)
11575 0 : || CHECK_FLAG(peer->bgp->flags,
11576 : BGP_FLAG_SHUTDOWN))
11577 0 : vty_out(vty, " Idle (Admin)");
11578 0 : else if (CHECK_FLAG(
11579 : peer->sflags,
11580 : PEER_STATUS_PREFIX_OVERFLOW))
11581 0 : vty_out(vty, " Idle (PfxCt)");
11582 : else
11583 0 : vty_out(vty, " %12s",
11584 : lookup_msg(bgp_status_msg,
11585 : peer->status, NULL));
11586 :
11587 0 : vty_out(vty, " %8u", 0);
11588 : }
11589 : /* Make sure `Desc` column is the lastest in
11590 : * the output.
11591 : */
11592 0 : if (peer->desc)
11593 0 : vty_out(vty, " %s",
11594 : bgp_peer_description_stripped(
11595 : peer->desc,
11596 : show_wide ? 64 : 20));
11597 : else
11598 0 : vty_out(vty, " N/A");
11599 0 : vty_out(vty, "\n");
11600 : }
11601 :
11602 : }
11603 : }
11604 :
11605 0 : if (use_json) {
11606 0 : json_object_object_add(json, "peers", json_peers);
11607 0 : json_object_int_add(json, "failedPeers", failed_count);
11608 0 : json_object_int_add(json, "displayedPeers",
11609 0 : count - filtered_count);
11610 0 : json_object_int_add(json, "totalPeers", count);
11611 0 : json_object_int_add(json, "dynamicPeers", dn_count);
11612 :
11613 0 : if (!show_failed)
11614 0 : bgp_show_bestpath_json(bgp, json);
11615 :
11616 0 : vty_json(vty, json);
11617 : } else {
11618 0 : if (count) {
11619 0 : if (filtered_count == count)
11620 0 : vty_out(vty, "\n%% No matching neighbor\n");
11621 : else {
11622 0 : if (show_failed)
11623 0 : vty_out(vty, "\nDisplayed neighbors %d",
11624 : failed_count);
11625 0 : else if (as_type != AS_UNSPECIFIED || as
11626 0 : || fpeer || show_established)
11627 0 : vty_out(vty, "\nDisplayed neighbors %d",
11628 : count - filtered_count);
11629 :
11630 0 : vty_out(vty, "\nTotal number of neighbors %d\n",
11631 : count);
11632 : }
11633 : } else {
11634 0 : vty_out(vty, "No %s neighbor is configured\n",
11635 : get_afi_safi_str(afi, safi, false));
11636 : }
11637 :
11638 0 : if (dn_count) {
11639 0 : vty_out(vty, "* - dynamic neighbor\n");
11640 0 : vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11641 : dn_count, bgp->dynamic_neighbors_limit);
11642 : }
11643 : }
11644 :
11645 : return CMD_SUCCESS;
11646 : }
11647 :
11648 0 : static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11649 : int safi, struct peer *fpeer, int as_type,
11650 : as_t as, uint16_t show_flags)
11651 : {
11652 0 : int is_first = 1;
11653 0 : int afi_wildcard = (afi == AFI_MAX);
11654 0 : int safi_wildcard = (safi == SAFI_MAX);
11655 0 : int is_wildcard = (afi_wildcard || safi_wildcard);
11656 0 : bool nbr_output = false;
11657 0 : bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11658 :
11659 0 : if (use_json && is_wildcard)
11660 0 : vty_out(vty, "{\n");
11661 0 : if (afi_wildcard)
11662 0 : afi = 1; /* AFI_IP */
11663 0 : while (afi < AFI_MAX) {
11664 0 : if (safi_wildcard)
11665 0 : safi = 1; /* SAFI_UNICAST */
11666 0 : while (safi < SAFI_MAX) {
11667 0 : if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11668 0 : nbr_output = true;
11669 :
11670 0 : if (is_wildcard) {
11671 : /*
11672 : * So limit output to those afi/safi
11673 : * pairs that
11674 : * actualy have something interesting in
11675 : * them
11676 : */
11677 0 : if (use_json) {
11678 0 : if (!is_first)
11679 0 : vty_out(vty, ",\n");
11680 : else
11681 : is_first = 0;
11682 :
11683 0 : vty_out(vty, "\"%s\":",
11684 : get_afi_safi_str(afi,
11685 : safi,
11686 : true));
11687 : } else {
11688 0 : vty_out(vty,
11689 : "\n%s Summary (%s):\n",
11690 : get_afi_safi_str(afi,
11691 : safi,
11692 : false),
11693 : bgp->name_pretty);
11694 : }
11695 : }
11696 0 : bgp_show_summary(vty, bgp, afi, safi, fpeer,
11697 : as_type, as, show_flags);
11698 : }
11699 0 : safi++;
11700 0 : if (!safi_wildcard)
11701 0 : safi = SAFI_MAX;
11702 : }
11703 0 : afi++;
11704 0 : if (!afi_wildcard)
11705 0 : afi = AFI_MAX;
11706 : }
11707 :
11708 0 : if (use_json && is_wildcard)
11709 0 : vty_out(vty, "}\n");
11710 0 : else if (!nbr_output) {
11711 0 : if (use_json)
11712 0 : vty_out(vty, "{}\n");
11713 : else
11714 0 : vty_out(vty, "%% No BGP neighbors found in %s\n",
11715 : bgp->name_pretty);
11716 : }
11717 0 : }
11718 :
11719 0 : static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11720 : safi_t safi,
11721 : const char *neighbor,
11722 : int as_type, as_t as,
11723 : uint16_t show_flags)
11724 : {
11725 0 : struct listnode *node, *nnode;
11726 0 : struct bgp *bgp;
11727 0 : struct peer *fpeer = NULL;
11728 0 : int is_first = 1;
11729 0 : bool nbr_output = false;
11730 0 : bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11731 :
11732 0 : if (use_json)
11733 0 : vty_out(vty, "{\n");
11734 :
11735 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11736 0 : nbr_output = true;
11737 0 : if (use_json) {
11738 0 : if (!is_first)
11739 0 : vty_out(vty, ",\n");
11740 : else
11741 : is_first = 0;
11742 :
11743 0 : vty_out(vty, "\"%s\":",
11744 0 : (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11745 0 : ? VRF_DEFAULT_NAME
11746 : : bgp->name);
11747 : }
11748 0 : if (neighbor) {
11749 0 : fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11750 : use_json);
11751 0 : if (!fpeer)
11752 0 : continue;
11753 : }
11754 0 : bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11755 : as, show_flags);
11756 : }
11757 :
11758 0 : if (use_json)
11759 0 : vty_out(vty, "}\n");
11760 0 : else if (!nbr_output)
11761 0 : vty_out(vty, "%% BGP instance not found\n");
11762 0 : }
11763 :
11764 0 : int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11765 : safi_t safi, const char *neighbor, int as_type,
11766 : as_t as, uint16_t show_flags)
11767 : {
11768 0 : struct bgp *bgp;
11769 0 : bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11770 0 : struct peer *fpeer = NULL;
11771 :
11772 0 : if (name) {
11773 0 : if (strmatch(name, "all")) {
11774 0 : bgp_show_all_instances_summary_vty(vty, afi, safi,
11775 : neighbor, as_type,
11776 : as, show_flags);
11777 0 : return CMD_SUCCESS;
11778 : } else {
11779 0 : bgp = bgp_lookup_by_name(name);
11780 :
11781 0 : if (!bgp) {
11782 0 : if (use_json)
11783 0 : vty_out(vty, "{}\n");
11784 : else
11785 0 : vty_out(vty,
11786 : "%% BGP instance not found\n");
11787 0 : return CMD_WARNING;
11788 : }
11789 :
11790 0 : if (neighbor) {
11791 0 : fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11792 : use_json);
11793 0 : if (!fpeer)
11794 : return CMD_WARNING;
11795 : }
11796 0 : bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11797 : as_type, as, show_flags);
11798 0 : return CMD_SUCCESS;
11799 : }
11800 : }
11801 :
11802 0 : bgp = bgp_get_default();
11803 :
11804 0 : if (bgp) {
11805 0 : if (neighbor) {
11806 0 : fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11807 : use_json);
11808 0 : if (!fpeer)
11809 : return CMD_WARNING;
11810 : }
11811 0 : bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11812 : as, show_flags);
11813 : } else {
11814 0 : if (use_json)
11815 0 : vty_out(vty, "{}\n");
11816 : else
11817 0 : vty_out(vty, "%% BGP instance not found\n");
11818 0 : return CMD_WARNING;
11819 : }
11820 :
11821 0 : return CMD_SUCCESS;
11822 : }
11823 :
11824 : /* `show [ip] bgp summary' commands. */
11825 0 : DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11826 : "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11827 : " [" BGP_SAFI_WITH_LABEL_CMD_STR
11828 : "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
11829 : SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11830 : BGP_SAFI_WITH_LABEL_HELP_STR
11831 : "Display the entries for all address families\n"
11832 : "Summary of BGP neighbor status\n"
11833 : "Show only sessions in Established state\n"
11834 : "Show only sessions not in Established state\n"
11835 : "Show only the specified neighbor session\n"
11836 : "Neighbor to display information about\n"
11837 : "Neighbor to display information about\n"
11838 : "Neighbor on BGP configured interface\n"
11839 : "Show only the specified remote AS sessions\n"
11840 : "AS number\n"
11841 : "Internal (iBGP) AS sessions\n"
11842 : "External (eBGP) AS sessions\n"
11843 : "Shorten the information on BGP instances\n"
11844 : "Increase table width for longer output\n" JSON_STR)
11845 : {
11846 0 : char *vrf = NULL;
11847 0 : afi_t afi = AFI_MAX;
11848 0 : safi_t safi = SAFI_MAX;
11849 0 : as_t as = 0; /* 0 means AS filter not set */
11850 0 : int as_type = AS_UNSPECIFIED;
11851 0 : uint16_t show_flags = 0;
11852 :
11853 0 : int idx = 0;
11854 :
11855 : /* show [ip] bgp */
11856 0 : if (!all && argv_find(argv, argc, "ip", &idx))
11857 0 : afi = AFI_IP;
11858 : /* [<vrf> VIEWVRFNAME] */
11859 0 : if (argv_find(argv, argc, "vrf", &idx)) {
11860 0 : vrf = argv[idx + 1]->arg;
11861 0 : if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11862 0 : vrf = NULL;
11863 0 : } else if (argv_find(argv, argc, "view", &idx))
11864 : /* [<view> VIEWVRFNAME] */
11865 0 : vrf = argv[idx + 1]->arg;
11866 : /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11867 0 : if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11868 0 : argv_find_and_parse_safi(argv, argc, &idx, &safi);
11869 : }
11870 :
11871 0 : if (argv_find(argv, argc, "failed", &idx))
11872 0 : SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11873 :
11874 0 : if (argv_find(argv, argc, "established", &idx))
11875 0 : SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11876 :
11877 0 : if (argv_find(argv, argc, "remote-as", &idx)) {
11878 0 : if (argv[idx + 1]->arg[0] == 'i')
11879 : as_type = AS_INTERNAL;
11880 0 : else if (argv[idx + 1]->arg[0] == 'e')
11881 : as_type = AS_EXTERNAL;
11882 : else
11883 0 : as = (as_t)atoi(argv[idx + 1]->arg);
11884 : }
11885 :
11886 0 : if (argv_find(argv, argc, "terse", &idx))
11887 0 : SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11888 :
11889 0 : if (argv_find(argv, argc, "wide", &idx))
11890 0 : SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11891 :
11892 0 : if (argv_find(argv, argc, "json", &idx))
11893 0 : SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11894 :
11895 0 : return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11896 : show_flags);
11897 : }
11898 :
11899 307 : const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11900 : {
11901 307 : if (for_json)
11902 305 : return get_afi_safi_json_str(afi, safi);
11903 : else
11904 2 : return get_afi_safi_vty_str(afi, safi);
11905 : }
11906 :
11907 :
11908 0 : static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11909 : afi_t afi, safi_t safi,
11910 : uint16_t adv_smcap, uint16_t adv_rmcap,
11911 : uint16_t rcv_smcap, uint16_t rcv_rmcap,
11912 : bool use_json, json_object *json_pref)
11913 : {
11914 : /* Send-Mode */
11915 0 : if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11916 0 : || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11917 0 : if (use_json) {
11918 0 : if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11919 0 : && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11920 0 : json_object_string_add(json_pref, "sendMode",
11921 : "advertisedAndReceived");
11922 0 : else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11923 0 : json_object_string_add(json_pref, "sendMode",
11924 : "advertised");
11925 0 : else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11926 0 : json_object_string_add(json_pref, "sendMode",
11927 : "received");
11928 : } else {
11929 0 : vty_out(vty, " Send-mode: ");
11930 0 : if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11931 0 : vty_out(vty, "advertised");
11932 0 : if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11933 0 : vty_out(vty, "%sreceived",
11934 0 : CHECK_FLAG(p->af_cap[afi][safi],
11935 : adv_smcap)
11936 : ? ", "
11937 : : "");
11938 0 : vty_out(vty, "\n");
11939 : }
11940 : }
11941 :
11942 : /* Receive-Mode */
11943 0 : if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11944 0 : || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11945 0 : if (use_json) {
11946 0 : if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11947 0 : && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11948 0 : json_object_string_add(json_pref, "recvMode",
11949 : "advertisedAndReceived");
11950 0 : else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11951 0 : json_object_string_add(json_pref, "recvMode",
11952 : "advertised");
11953 0 : else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11954 0 : json_object_string_add(json_pref, "recvMode",
11955 : "received");
11956 : } else {
11957 0 : vty_out(vty, " Receive-mode: ");
11958 0 : if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11959 0 : vty_out(vty, "advertised");
11960 0 : if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11961 0 : vty_out(vty, "%sreceived",
11962 0 : CHECK_FLAG(p->af_cap[afi][safi],
11963 : adv_rmcap)
11964 : ? ", "
11965 : : "");
11966 0 : vty_out(vty, "\n");
11967 : }
11968 : }
11969 0 : }
11970 :
11971 27 : static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11972 : struct peer *p,
11973 : json_object *json)
11974 : {
11975 27 : bool rbit = false;
11976 27 : bool nbit = false;
11977 :
11978 27 : if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11979 27 : && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11980 12 : && (peer_established(p))) {
11981 12 : rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11982 12 : nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11983 : }
11984 :
11985 27 : if (json) {
11986 27 : json_object_boolean_add(json, "rBit", rbit);
11987 27 : json_object_boolean_add(json, "nBit", nbit);
11988 : } else {
11989 0 : vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11990 0 : vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11991 : }
11992 27 : }
11993 :
11994 27 : static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11995 : struct peer *peer,
11996 : json_object *json)
11997 : {
11998 27 : const char *mode = "NotApplicable";
11999 :
12000 27 : if (!json)
12001 0 : vty_out(vty, "\n Remote GR Mode: ");
12002 :
12003 27 : if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
12004 12 : && (peer_established(peer))) {
12005 :
12006 12 : if ((peer->nsf_af_count == 0)
12007 12 : && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12008 :
12009 : mode = "Disable";
12010 :
12011 12 : } else if (peer->nsf_af_count == 0
12012 12 : && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12013 :
12014 : mode = "Helper";
12015 :
12016 0 : } else if (peer->nsf_af_count != 0
12017 0 : && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
12018 :
12019 27 : mode = "Restart";
12020 : }
12021 : }
12022 :
12023 27 : if (json)
12024 27 : json_object_string_add(json, "remoteGrMode", mode);
12025 : else
12026 0 : vty_out(vty, "%s\n", mode);
12027 27 : }
12028 :
12029 27 : static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
12030 : struct peer *p,
12031 : json_object *json)
12032 : {
12033 27 : const char *mode = "Invalid";
12034 :
12035 27 : if (!json)
12036 0 : vty_out(vty, " Local GR Mode: ");
12037 :
12038 27 : if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
12039 : mode = "Helper";
12040 27 : else if (bgp_peer_gr_mode_get(p) == PEER_GR)
12041 : mode = "Restart";
12042 27 : else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
12043 : mode = "Disable";
12044 27 : else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
12045 27 : if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
12046 : mode = "Helper*";
12047 0 : else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
12048 : mode = "Restart*";
12049 0 : else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
12050 : mode = "Disable*";
12051 : else
12052 0 : mode = "Invalid*";
12053 : }
12054 :
12055 27 : if (json)
12056 27 : json_object_string_add(json, "localGrMode", mode);
12057 : else
12058 0 : vty_out(vty, "%s\n", mode);
12059 27 : }
12060 :
12061 27 : static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
12062 : struct vty *vty, struct peer *peer, json_object *json)
12063 : {
12064 27 : afi_t afi;
12065 27 : safi_t safi;
12066 27 : json_object *json_afi_safi = NULL;
12067 27 : json_object *json_timer = NULL;
12068 27 : json_object *json_endofrib_status = NULL;
12069 27 : bool eor_flag = false;
12070 :
12071 351 : FOREACH_AFI_SAFI_NSF (afi, safi) {
12072 243 : if (!peer->afc[afi][safi])
12073 216 : continue;
12074 :
12075 27 : if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
12076 : !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
12077 15 : continue;
12078 :
12079 12 : if (json) {
12080 12 : json_afi_safi = json_object_new_object();
12081 12 : json_endofrib_status = json_object_new_object();
12082 12 : json_timer = json_object_new_object();
12083 : }
12084 :
12085 12 : if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
12086 : eor_flag = true;
12087 : else
12088 0 : eor_flag = false;
12089 :
12090 12 : if (!json) {
12091 0 : vty_out(vty, " %s:\n",
12092 : get_afi_safi_str(afi, safi, false));
12093 :
12094 0 : vty_out(vty, " F bit: ");
12095 : }
12096 :
12097 12 : if (peer->nsf[afi][safi] &&
12098 0 : CHECK_FLAG(peer->af_cap[afi][safi],
12099 : PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
12100 :
12101 0 : if (json) {
12102 0 : json_object_boolean_true_add(json_afi_safi,
12103 : "fBit");
12104 : } else
12105 0 : vty_out(vty, "True\n");
12106 : } else {
12107 12 : if (json)
12108 12 : json_object_boolean_false_add(json_afi_safi,
12109 : "fBit");
12110 : else
12111 0 : vty_out(vty, "False\n");
12112 : }
12113 :
12114 12 : if (!json)
12115 0 : vty_out(vty, " End-of-RIB sent: ");
12116 :
12117 12 : if (CHECK_FLAG(peer->af_sflags[afi][safi],
12118 : PEER_STATUS_EOR_SEND)) {
12119 1 : if (json) {
12120 1 : json_object_boolean_true_add(
12121 : json_endofrib_status, "endOfRibSend");
12122 :
12123 1 : PRINT_EOR_JSON(eor_flag);
12124 : } else {
12125 0 : vty_out(vty, "Yes\n");
12126 0 : vty_out(vty,
12127 : " End-of-RIB sent after update: ");
12128 :
12129 0 : PRINT_EOR(eor_flag);
12130 : }
12131 : } else {
12132 11 : if (json) {
12133 11 : json_object_boolean_false_add(
12134 : json_endofrib_status, "endOfRibSend");
12135 11 : json_object_boolean_false_add(
12136 : json_endofrib_status,
12137 : "endOfRibSentAfterUpdate");
12138 : } else {
12139 0 : vty_out(vty, "No\n");
12140 0 : vty_out(vty,
12141 : " End-of-RIB sent after update: ");
12142 0 : vty_out(vty, "No\n");
12143 : }
12144 : }
12145 :
12146 12 : if (!json)
12147 0 : vty_out(vty, " End-of-RIB received: ");
12148 :
12149 12 : if (CHECK_FLAG(peer->af_sflags[afi][safi],
12150 : PEER_STATUS_EOR_RECEIVED)) {
12151 1 : if (json)
12152 1 : json_object_boolean_true_add(
12153 : json_endofrib_status, "endOfRibRecv");
12154 : else
12155 0 : vty_out(vty, "Yes\n");
12156 : } else {
12157 11 : if (json)
12158 11 : json_object_boolean_false_add(
12159 : json_endofrib_status, "endOfRibRecv");
12160 : else
12161 0 : vty_out(vty, "No\n");
12162 : }
12163 :
12164 12 : if (json) {
12165 12 : json_object_int_add(json_timer, "stalePathTimer",
12166 12 : peer->bgp->stalepath_time);
12167 :
12168 12 : if (peer->t_gr_stale != NULL) {
12169 0 : json_object_int_add(json_timer,
12170 : "stalePathTimerRemaining",
12171 0 : thread_timer_remain_second(
12172 : peer->t_gr_stale));
12173 : }
12174 :
12175 : /* Display Configured Selection
12176 : * Deferral only when when
12177 : * Gr mode is enabled.
12178 : */
12179 12 : if (CHECK_FLAG(peer->flags,
12180 : PEER_FLAG_GRACEFUL_RESTART)) {
12181 0 : json_object_int_add(json_timer,
12182 : "selectionDeferralTimer",
12183 0 : peer->bgp->stalepath_time);
12184 : }
12185 :
12186 12 : if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12187 : NULL) {
12188 :
12189 0 : json_object_int_add(
12190 : json_timer,
12191 : "selectionDeferralTimerRemaining",
12192 0 : thread_timer_remain_second(
12193 : peer->bgp->gr_info[afi][safi]
12194 : .t_select_deferral));
12195 : }
12196 : } else {
12197 0 : vty_out(vty, " Timers:\n");
12198 0 : vty_out(vty,
12199 : " Configured Stale Path Time(sec): %u\n",
12200 0 : peer->bgp->stalepath_time);
12201 :
12202 0 : if (peer->t_gr_stale != NULL)
12203 0 : vty_out(vty,
12204 : " Stale Path Remaining(sec): %ld\n",
12205 : thread_timer_remain_second(
12206 : peer->t_gr_stale));
12207 : /* Display Configured Selection
12208 : * Deferral only when when
12209 : * Gr mode is enabled.
12210 : */
12211 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
12212 0 : vty_out(vty,
12213 : " Configured Selection Deferral Time(sec): %u\n",
12214 0 : peer->bgp->select_defer_time);
12215 :
12216 0 : if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
12217 : NULL)
12218 0 : vty_out(vty,
12219 : " Selection Deferral Time Remaining(sec): %ld\n",
12220 : thread_timer_remain_second(
12221 : peer->bgp->gr_info[afi][safi]
12222 : .t_select_deferral));
12223 : }
12224 12 : if (json) {
12225 12 : json_object_object_add(json_afi_safi, "endOfRibStatus",
12226 : json_endofrib_status);
12227 12 : json_object_object_add(json_afi_safi, "timers",
12228 : json_timer);
12229 12 : json_object_object_add(
12230 : json, get_afi_safi_str(afi, safi, true),
12231 : json_afi_safi);
12232 : }
12233 : }
12234 27 : }
12235 :
12236 27 : static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12237 : struct peer *p,
12238 : json_object *json)
12239 : {
12240 27 : if (json) {
12241 27 : json_object *json_timer = NULL;
12242 :
12243 27 : json_timer = json_object_new_object();
12244 :
12245 27 : json_object_int_add(json_timer, "configuredRestartTimer",
12246 27 : p->bgp->restart_time);
12247 :
12248 27 : json_object_int_add(json_timer, "receivedRestartTimer",
12249 27 : p->v_gr_restart);
12250 :
12251 27 : if (p->t_gr_restart != NULL)
12252 0 : json_object_int_add(
12253 : json_timer, "restartTimerRemaining",
12254 0 : thread_timer_remain_second(p->t_gr_restart));
12255 :
12256 27 : json_object_object_add(json, "timers", json_timer);
12257 : } else {
12258 :
12259 0 : vty_out(vty, " Timers:\n");
12260 0 : vty_out(vty, " Configured Restart Time(sec): %u\n",
12261 0 : p->bgp->restart_time);
12262 :
12263 0 : vty_out(vty, " Received Restart Time(sec): %u\n",
12264 0 : p->v_gr_restart);
12265 0 : if (p->t_gr_restart != NULL)
12266 0 : vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12267 : thread_timer_remain_second(p->t_gr_restart));
12268 0 : if (p->t_gr_restart != NULL) {
12269 0 : vty_out(vty, " Restart Time Remaining(sec): %ld\n",
12270 : thread_timer_remain_second(p->t_gr_restart));
12271 : }
12272 : }
12273 27 : }
12274 :
12275 0 : static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
12276 : json_object *json)
12277 : {
12278 0 : char dn_flag[2] = {0};
12279 : /* '*' + v6 address of neighbor */
12280 0 : char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
12281 :
12282 0 : if (!p->conf_if && peer_dynamic_neighbor(p))
12283 0 : dn_flag[0] = '*';
12284 :
12285 0 : if (p->conf_if) {
12286 0 : if (json)
12287 0 : json_object_string_addf(json, "neighborAddr", "%pSU",
12288 : &p->su);
12289 : else
12290 0 : vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
12291 : &p->su);
12292 : } else {
12293 0 : snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12294 : p->host);
12295 :
12296 0 : if (json)
12297 0 : json_object_string_add(json, "neighborAddr",
12298 : neighborAddr);
12299 : else
12300 0 : vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
12301 : }
12302 :
12303 : /* more gr info in new format */
12304 0 : BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json);
12305 0 : }
12306 :
12307 27 : static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
12308 : safi_t safi, bool use_json,
12309 : json_object *json_neigh)
12310 : {
12311 27 : struct bgp_filter *filter;
12312 27 : struct peer_af *paf;
12313 27 : char orf_pfx_name[BUFSIZ];
12314 27 : int orf_pfx_count;
12315 27 : json_object *json_af = NULL;
12316 27 : json_object *json_prefA = NULL;
12317 27 : json_object *json_prefB = NULL;
12318 27 : json_object *json_addr = NULL;
12319 27 : json_object *json_advmap = NULL;
12320 :
12321 27 : if (use_json) {
12322 27 : json_addr = json_object_new_object();
12323 27 : json_af = json_object_new_object();
12324 27 : filter = &p->filter[afi][safi];
12325 :
12326 27 : if (peer_group_active(p))
12327 0 : json_object_string_add(json_addr, "peerGroupMember",
12328 0 : p->group->name);
12329 :
12330 27 : paf = peer_af_find(p, afi, safi);
12331 27 : if (paf && PAF_SUBGRP(paf)) {
12332 12 : json_object_int_add(json_addr, "updateGroupId",
12333 12 : PAF_UPDGRP(paf)->id);
12334 12 : json_object_int_add(json_addr, "subGroupId",
12335 12 : PAF_SUBGRP(paf)->id);
12336 12 : json_object_int_add(json_addr, "packetQueueLength",
12337 12 : bpacket_queue_virtual_length(paf));
12338 : }
12339 :
12340 27 : if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12341 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12342 : PEER_CAP_ORF_PREFIX_SM_RCV)
12343 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12344 : PEER_CAP_ORF_PREFIX_RM_ADV)
12345 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12346 : PEER_CAP_ORF_PREFIX_RM_RCV)) {
12347 0 : json_object_int_add(json_af, "orfType",
12348 : ORF_TYPE_PREFIX);
12349 0 : json_prefA = json_object_new_object();
12350 0 : bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12351 : PEER_CAP_ORF_PREFIX_SM_ADV,
12352 : PEER_CAP_ORF_PREFIX_RM_ADV,
12353 : PEER_CAP_ORF_PREFIX_SM_RCV,
12354 : PEER_CAP_ORF_PREFIX_RM_RCV,
12355 : use_json, json_prefA);
12356 0 : json_object_object_add(json_af, "orfPrefixList",
12357 : json_prefA);
12358 : }
12359 :
12360 27 : if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12361 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12362 : PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12363 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12364 : PEER_CAP_ORF_PREFIX_RM_ADV)
12365 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12366 : PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12367 0 : json_object_int_add(json_af, "orfOldType",
12368 : ORF_TYPE_PREFIX_OLD);
12369 0 : json_prefB = json_object_new_object();
12370 0 : bgp_show_peer_afi_orf_cap(
12371 : vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12372 : PEER_CAP_ORF_PREFIX_RM_ADV,
12373 : PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12374 : PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12375 : json_prefB);
12376 0 : json_object_object_add(json_af, "orfOldPrefixList",
12377 : json_prefB);
12378 : }
12379 :
12380 27 : if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12381 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12382 : PEER_CAP_ORF_PREFIX_SM_RCV)
12383 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12384 : PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12385 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12386 : PEER_CAP_ORF_PREFIX_RM_ADV)
12387 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12388 : PEER_CAP_ORF_PREFIX_RM_RCV)
12389 27 : || CHECK_FLAG(p->af_cap[afi][safi],
12390 : PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12391 0 : json_object_object_add(json_addr, "afDependentCap",
12392 : json_af);
12393 : else
12394 27 : json_object_free(json_af);
12395 :
12396 27 : snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12397 : p->host, afi, safi);
12398 27 : orf_pfx_count = prefix_bgp_show_prefix_list(
12399 : NULL, afi, orf_pfx_name, use_json);
12400 :
12401 27 : if (CHECK_FLAG(p->af_sflags[afi][safi],
12402 : PEER_STATUS_ORF_PREFIX_SEND)
12403 27 : || orf_pfx_count) {
12404 0 : if (CHECK_FLAG(p->af_sflags[afi][safi],
12405 : PEER_STATUS_ORF_PREFIX_SEND))
12406 0 : json_object_boolean_true_add(json_neigh,
12407 : "orfSent");
12408 0 : if (orf_pfx_count)
12409 0 : json_object_int_add(json_addr, "orfRecvCounter",
12410 : orf_pfx_count);
12411 : }
12412 27 : if (CHECK_FLAG(p->af_sflags[afi][safi],
12413 : PEER_STATUS_ORF_WAIT_REFRESH))
12414 0 : json_object_string_add(
12415 : json_addr, "orfFirstUpdate",
12416 : "deferredUntilORFOrRouteRefreshRecvd");
12417 :
12418 27 : if (CHECK_FLAG(p->af_flags[afi][safi],
12419 : PEER_FLAG_REFLECTOR_CLIENT))
12420 0 : json_object_boolean_true_add(json_addr,
12421 : "routeReflectorClient");
12422 27 : if (CHECK_FLAG(p->af_flags[afi][safi],
12423 : PEER_FLAG_RSERVER_CLIENT))
12424 0 : json_object_boolean_true_add(json_addr,
12425 : "routeServerClient");
12426 27 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12427 0 : json_object_boolean_true_add(json_addr,
12428 : "inboundSoftConfigPermit");
12429 :
12430 27 : if (CHECK_FLAG(p->af_flags[afi][safi],
12431 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12432 0 : json_object_boolean_true_add(
12433 : json_addr,
12434 : "privateAsNumsAllReplacedInUpdatesToNbr");
12435 27 : else if (CHECK_FLAG(p->af_flags[afi][safi],
12436 : PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12437 0 : json_object_boolean_true_add(
12438 : json_addr,
12439 : "privateAsNumsReplacedInUpdatesToNbr");
12440 27 : else if (CHECK_FLAG(p->af_flags[afi][safi],
12441 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12442 0 : json_object_boolean_true_add(
12443 : json_addr,
12444 : "privateAsNumsAllRemovedInUpdatesToNbr");
12445 27 : else if (CHECK_FLAG(p->af_flags[afi][safi],
12446 : PEER_FLAG_REMOVE_PRIVATE_AS))
12447 0 : json_object_boolean_true_add(
12448 : json_addr,
12449 : "privateAsNumsRemovedInUpdatesToNbr");
12450 :
12451 27 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12452 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12453 : PEER_FLAG_ALLOWAS_IN_ORIGIN))
12454 0 : json_object_boolean_true_add(json_addr,
12455 : "allowAsInOrigin");
12456 : else
12457 0 : json_object_int_add(json_addr, "allowAsInCount",
12458 0 : p->allowas_in[afi][safi]);
12459 : }
12460 :
12461 27 : if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12462 0 : json_object_boolean_true_add(
12463 : json_addr,
12464 0 : bgp_addpath_names(p->addpath_type[afi][safi])
12465 0 : ->type_json_name);
12466 :
12467 27 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12468 0 : json_object_string_add(json_addr,
12469 : "overrideASNsInOutboundUpdates",
12470 : "ifAspathEqualRemoteAs");
12471 :
12472 27 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12473 27 : || CHECK_FLAG(p->af_flags[afi][safi],
12474 : PEER_FLAG_FORCE_NEXTHOP_SELF))
12475 0 : json_object_boolean_true_add(json_addr,
12476 : "routerAlwaysNextHop");
12477 27 : if (CHECK_FLAG(p->af_flags[afi][safi],
12478 : PEER_FLAG_AS_PATH_UNCHANGED))
12479 0 : json_object_boolean_true_add(
12480 : json_addr, "unchangedAsPathPropogatedToNbr");
12481 27 : if (CHECK_FLAG(p->af_flags[afi][safi],
12482 : PEER_FLAG_NEXTHOP_UNCHANGED))
12483 0 : json_object_boolean_true_add(
12484 : json_addr, "unchangedNextHopPropogatedToNbr");
12485 27 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12486 0 : json_object_boolean_true_add(
12487 : json_addr, "unchangedMedPropogatedToNbr");
12488 27 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12489 0 : || CHECK_FLAG(p->af_flags[afi][safi],
12490 : PEER_FLAG_SEND_EXT_COMMUNITY)) {
12491 27 : if (CHECK_FLAG(p->af_flags[afi][safi],
12492 : PEER_FLAG_SEND_COMMUNITY)
12493 27 : && CHECK_FLAG(p->af_flags[afi][safi],
12494 : PEER_FLAG_SEND_EXT_COMMUNITY))
12495 27 : json_object_string_add(json_addr,
12496 : "commAttriSentToNbr",
12497 : "extendedAndStandard");
12498 0 : else if (CHECK_FLAG(p->af_flags[afi][safi],
12499 : PEER_FLAG_SEND_EXT_COMMUNITY))
12500 0 : json_object_string_add(json_addr,
12501 : "commAttriSentToNbr",
12502 : "extended");
12503 : else
12504 0 : json_object_string_add(json_addr,
12505 : "commAttriSentToNbr",
12506 : "standard");
12507 : }
12508 27 : if (CHECK_FLAG(p->af_flags[afi][safi],
12509 : PEER_FLAG_DEFAULT_ORIGINATE)) {
12510 0 : if (p->default_rmap[afi][safi].name)
12511 0 : json_object_string_add(
12512 : json_addr, "defaultRouteMap",
12513 : p->default_rmap[afi][safi].name);
12514 :
12515 0 : if (paf && PAF_SUBGRP(paf)
12516 0 : && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12517 : SUBGRP_STATUS_DEFAULT_ORIGINATE))
12518 0 : json_object_boolean_true_add(json_addr,
12519 : "defaultSent");
12520 : else
12521 0 : json_object_boolean_true_add(json_addr,
12522 : "defaultNotSent");
12523 : }
12524 :
12525 27 : if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12526 0 : if (is_evpn_enabled())
12527 0 : json_object_boolean_true_add(
12528 : json_addr, "advertiseAllVnis");
12529 : }
12530 :
12531 27 : if (filter->plist[FILTER_IN].name
12532 27 : || filter->dlist[FILTER_IN].name
12533 27 : || filter->aslist[FILTER_IN].name
12534 27 : || filter->map[RMAP_IN].name)
12535 0 : json_object_boolean_true_add(json_addr,
12536 : "inboundPathPolicyConfig");
12537 27 : if (filter->plist[FILTER_OUT].name
12538 27 : || filter->dlist[FILTER_OUT].name
12539 27 : || filter->aslist[FILTER_OUT].name
12540 27 : || filter->map[RMAP_OUT].name || filter->usmap.name)
12541 0 : json_object_boolean_true_add(
12542 : json_addr, "outboundPathPolicyConfig");
12543 :
12544 : /* prefix-list */
12545 27 : if (filter->plist[FILTER_IN].name)
12546 0 : json_object_string_add(json_addr,
12547 : "incomingUpdatePrefixFilterList",
12548 : filter->plist[FILTER_IN].name);
12549 27 : if (filter->plist[FILTER_OUT].name)
12550 0 : json_object_string_add(json_addr,
12551 : "outgoingUpdatePrefixFilterList",
12552 : filter->plist[FILTER_OUT].name);
12553 :
12554 : /* distribute-list */
12555 27 : if (filter->dlist[FILTER_IN].name)
12556 0 : json_object_string_add(
12557 : json_addr, "incomingUpdateNetworkFilterList",
12558 : filter->dlist[FILTER_IN].name);
12559 27 : if (filter->dlist[FILTER_OUT].name)
12560 0 : json_object_string_add(
12561 : json_addr, "outgoingUpdateNetworkFilterList",
12562 : filter->dlist[FILTER_OUT].name);
12563 :
12564 : /* filter-list. */
12565 27 : if (filter->aslist[FILTER_IN].name)
12566 0 : json_object_string_add(json_addr,
12567 : "incomingUpdateAsPathFilterList",
12568 : filter->aslist[FILTER_IN].name);
12569 27 : if (filter->aslist[FILTER_OUT].name)
12570 0 : json_object_string_add(json_addr,
12571 : "outgoingUpdateAsPathFilterList",
12572 : filter->aslist[FILTER_OUT].name);
12573 :
12574 : /* route-map. */
12575 27 : if (filter->map[RMAP_IN].name)
12576 0 : json_object_string_add(
12577 : json_addr, "routeMapForIncomingAdvertisements",
12578 : filter->map[RMAP_IN].name);
12579 27 : if (filter->map[RMAP_OUT].name)
12580 0 : json_object_string_add(
12581 : json_addr, "routeMapForOutgoingAdvertisements",
12582 : filter->map[RMAP_OUT].name);
12583 :
12584 : /* ebgp-requires-policy (inbound) */
12585 27 : if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12586 0 : && !bgp_inbound_policy_exists(p, filter))
12587 0 : json_object_string_add(
12588 : json_addr, "inboundEbgpRequiresPolicy",
12589 : "Inbound updates discarded due to missing policy");
12590 :
12591 : /* ebgp-requires-policy (outbound) */
12592 27 : if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12593 0 : && (!bgp_outbound_policy_exists(p, filter)))
12594 0 : json_object_string_add(
12595 : json_addr, "outboundEbgpRequiresPolicy",
12596 : "Outbound updates discarded due to missing policy");
12597 :
12598 : /* unsuppress-map */
12599 27 : if (filter->usmap.name)
12600 0 : json_object_string_add(json_addr,
12601 : "selectiveUnsuppressRouteMap",
12602 : filter->usmap.name);
12603 :
12604 : /* advertise-map */
12605 27 : if (filter->advmap.aname) {
12606 0 : json_advmap = json_object_new_object();
12607 0 : json_object_string_add(json_advmap, "condition",
12608 0 : filter->advmap.condition
12609 : ? "EXIST"
12610 : : "NON_EXIST");
12611 0 : json_object_string_add(json_advmap, "conditionMap",
12612 0 : filter->advmap.cname);
12613 0 : json_object_string_add(json_advmap, "advertiseMap",
12614 0 : filter->advmap.aname);
12615 0 : json_object_string_add(
12616 : json_advmap, "advertiseStatus",
12617 0 : filter->advmap.update_type ==
12618 : UPDATE_TYPE_ADVERTISE
12619 : ? "Advertise"
12620 : : "Withdraw");
12621 0 : json_object_object_add(json_addr, "advertiseMap",
12622 : json_advmap);
12623 : }
12624 :
12625 : /* Receive prefix count */
12626 27 : json_object_int_add(json_addr, "acceptedPrefixCounter",
12627 27 : p->pcount[afi][safi]);
12628 27 : if (paf && PAF_SUBGRP(paf))
12629 12 : json_object_int_add(json_addr, "sentPrefixCounter",
12630 12 : (PAF_SUBGRP(paf))->scount);
12631 :
12632 : /* Maximum prefix */
12633 27 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12634 0 : json_object_int_add(json_addr, "prefixOutAllowedMax",
12635 0 : p->pmax_out[afi][safi]);
12636 :
12637 : /* Maximum prefix */
12638 27 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12639 0 : json_object_int_add(json_addr, "prefixAllowedMax",
12640 0 : p->pmax[afi][safi]);
12641 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12642 : PEER_FLAG_MAX_PREFIX_WARNING))
12643 0 : json_object_boolean_true_add(
12644 : json_addr, "prefixAllowedMaxWarning");
12645 0 : json_object_int_add(json_addr,
12646 : "prefixAllowedWarningThresh",
12647 0 : p->pmax_threshold[afi][safi]);
12648 0 : if (p->pmax_restart[afi][safi])
12649 0 : json_object_int_add(
12650 : json_addr,
12651 : "prefixAllowedRestartIntervalMsecs",
12652 0 : p->pmax_restart[afi][safi] * 60000);
12653 : }
12654 27 : json_object_object_add(json_neigh,
12655 : get_afi_safi_str(afi, safi, true),
12656 : json_addr);
12657 :
12658 : } else {
12659 0 : filter = &p->filter[afi][safi];
12660 :
12661 0 : vty_out(vty, " For address family: %s\n",
12662 : get_afi_safi_str(afi, safi, false));
12663 :
12664 0 : if (peer_group_active(p))
12665 0 : vty_out(vty, " %s peer-group member\n",
12666 : p->group->name);
12667 :
12668 0 : paf = peer_af_find(p, afi, safi);
12669 0 : if (paf && PAF_SUBGRP(paf)) {
12670 0 : vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12671 0 : PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12672 0 : vty_out(vty, " Packet Queue length %d\n",
12673 : bpacket_queue_virtual_length(paf));
12674 : } else {
12675 0 : vty_out(vty, " Not part of any update group\n");
12676 : }
12677 0 : if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12678 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12679 : PEER_CAP_ORF_PREFIX_SM_RCV)
12680 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12681 : PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12682 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12683 : PEER_CAP_ORF_PREFIX_RM_ADV)
12684 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12685 : PEER_CAP_ORF_PREFIX_RM_RCV)
12686 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12687 : PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12688 0 : vty_out(vty, " AF-dependant capabilities:\n");
12689 :
12690 0 : if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12691 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12692 : PEER_CAP_ORF_PREFIX_SM_RCV)
12693 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12694 : PEER_CAP_ORF_PREFIX_RM_ADV)
12695 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12696 : PEER_CAP_ORF_PREFIX_RM_RCV)) {
12697 0 : vty_out(vty,
12698 : " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12699 : ORF_TYPE_PREFIX);
12700 0 : bgp_show_peer_afi_orf_cap(
12701 : vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12702 : PEER_CAP_ORF_PREFIX_RM_ADV,
12703 : PEER_CAP_ORF_PREFIX_SM_RCV,
12704 : PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12705 : }
12706 0 : if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12707 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12708 : PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12709 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12710 : PEER_CAP_ORF_PREFIX_RM_ADV)
12711 0 : || CHECK_FLAG(p->af_cap[afi][safi],
12712 : PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12713 0 : vty_out(vty,
12714 : " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12715 : ORF_TYPE_PREFIX_OLD);
12716 0 : bgp_show_peer_afi_orf_cap(
12717 : vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12718 : PEER_CAP_ORF_PREFIX_RM_ADV,
12719 : PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12720 : PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12721 : }
12722 :
12723 0 : snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12724 : p->host, afi, safi);
12725 0 : orf_pfx_count = prefix_bgp_show_prefix_list(
12726 : NULL, afi, orf_pfx_name, use_json);
12727 :
12728 0 : if (CHECK_FLAG(p->af_sflags[afi][safi],
12729 : PEER_STATUS_ORF_PREFIX_SEND)
12730 0 : || orf_pfx_count) {
12731 0 : vty_out(vty, " Outbound Route Filter (ORF):");
12732 0 : if (CHECK_FLAG(p->af_sflags[afi][safi],
12733 : PEER_STATUS_ORF_PREFIX_SEND))
12734 0 : vty_out(vty, " sent;");
12735 0 : if (orf_pfx_count)
12736 0 : vty_out(vty, " received (%d entries)",
12737 : orf_pfx_count);
12738 0 : vty_out(vty, "\n");
12739 : }
12740 0 : if (CHECK_FLAG(p->af_sflags[afi][safi],
12741 : PEER_STATUS_ORF_WAIT_REFRESH))
12742 0 : vty_out(vty,
12743 : " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12744 :
12745 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12746 : PEER_FLAG_REFLECTOR_CLIENT))
12747 0 : vty_out(vty, " Route-Reflector Client\n");
12748 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12749 : PEER_FLAG_RSERVER_CLIENT))
12750 0 : vty_out(vty, " Route-Server Client\n");
12751 0 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12752 0 : vty_out(vty,
12753 : " Inbound soft reconfiguration allowed\n");
12754 :
12755 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12756 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12757 0 : vty_out(vty,
12758 : " Private AS numbers (all) replaced in updates to this neighbor\n");
12759 0 : else if (CHECK_FLAG(p->af_flags[afi][safi],
12760 : PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12761 0 : vty_out(vty,
12762 : " Private AS numbers replaced in updates to this neighbor\n");
12763 0 : else if (CHECK_FLAG(p->af_flags[afi][safi],
12764 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12765 0 : vty_out(vty,
12766 : " Private AS numbers (all) removed in updates to this neighbor\n");
12767 0 : else if (CHECK_FLAG(p->af_flags[afi][safi],
12768 : PEER_FLAG_REMOVE_PRIVATE_AS))
12769 0 : vty_out(vty,
12770 : " Private AS numbers removed in updates to this neighbor\n");
12771 :
12772 0 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) {
12773 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12774 : PEER_FLAG_ALLOWAS_IN_ORIGIN))
12775 0 : vty_out(vty,
12776 : " Local AS allowed as path origin\n");
12777 : else
12778 0 : vty_out(vty,
12779 : " Local AS allowed in path, %d occurrences\n",
12780 0 : p->allowas_in[afi][safi]);
12781 : }
12782 :
12783 0 : if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12784 0 : vty_out(vty, " %s\n",
12785 0 : bgp_addpath_names(p->addpath_type[afi][safi])
12786 0 : ->human_description);
12787 :
12788 0 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12789 0 : vty_out(vty,
12790 : " Override ASNs in outbound updates if aspath equals remote-as\n");
12791 :
12792 0 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12793 0 : || CHECK_FLAG(p->af_flags[afi][safi],
12794 : PEER_FLAG_FORCE_NEXTHOP_SELF))
12795 0 : vty_out(vty, " NEXT_HOP is always this router\n");
12796 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12797 : PEER_FLAG_AS_PATH_UNCHANGED))
12798 0 : vty_out(vty,
12799 : " AS_PATH is propagated unchanged to this neighbor\n");
12800 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12801 : PEER_FLAG_NEXTHOP_UNCHANGED))
12802 0 : vty_out(vty,
12803 : " NEXT_HOP is propagated unchanged to this neighbor\n");
12804 0 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12805 0 : vty_out(vty,
12806 : " MED is propagated unchanged to this neighbor\n");
12807 0 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12808 0 : || CHECK_FLAG(p->af_flags[afi][safi],
12809 : PEER_FLAG_SEND_EXT_COMMUNITY)
12810 0 : || CHECK_FLAG(p->af_flags[afi][safi],
12811 : PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12812 0 : vty_out(vty,
12813 : " Community attribute sent to this neighbor");
12814 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12815 : PEER_FLAG_SEND_COMMUNITY)
12816 0 : && CHECK_FLAG(p->af_flags[afi][safi],
12817 : PEER_FLAG_SEND_EXT_COMMUNITY)
12818 0 : && CHECK_FLAG(p->af_flags[afi][safi],
12819 : PEER_FLAG_SEND_LARGE_COMMUNITY))
12820 0 : vty_out(vty, "(all)\n");
12821 0 : else if (CHECK_FLAG(p->af_flags[afi][safi],
12822 : PEER_FLAG_SEND_LARGE_COMMUNITY))
12823 0 : vty_out(vty, "(large)\n");
12824 0 : else if (CHECK_FLAG(p->af_flags[afi][safi],
12825 : PEER_FLAG_SEND_EXT_COMMUNITY))
12826 0 : vty_out(vty, "(extended)\n");
12827 : else
12828 0 : vty_out(vty, "(standard)\n");
12829 : }
12830 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12831 : PEER_FLAG_DEFAULT_ORIGINATE)) {
12832 0 : vty_out(vty, " Default information originate,");
12833 :
12834 0 : if (p->default_rmap[afi][safi].name)
12835 0 : vty_out(vty, " default route-map %s%s,",
12836 0 : p->default_rmap[afi][safi].map ? "*"
12837 : : "",
12838 : p->default_rmap[afi][safi].name);
12839 0 : if (paf && PAF_SUBGRP(paf)
12840 0 : && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12841 : SUBGRP_STATUS_DEFAULT_ORIGINATE))
12842 0 : vty_out(vty, " default sent\n");
12843 : else
12844 0 : vty_out(vty, " default not sent\n");
12845 : }
12846 :
12847 : /* advertise-vni-all */
12848 0 : if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12849 0 : if (is_evpn_enabled())
12850 0 : vty_out(vty, " advertise-all-vni\n");
12851 : }
12852 :
12853 0 : if (filter->plist[FILTER_IN].name
12854 0 : || filter->dlist[FILTER_IN].name
12855 0 : || filter->aslist[FILTER_IN].name
12856 0 : || filter->map[RMAP_IN].name)
12857 0 : vty_out(vty, " Inbound path policy configured\n");
12858 0 : if (filter->plist[FILTER_OUT].name
12859 0 : || filter->dlist[FILTER_OUT].name
12860 0 : || filter->aslist[FILTER_OUT].name
12861 0 : || filter->map[RMAP_OUT].name || filter->usmap.name)
12862 0 : vty_out(vty, " Outbound path policy configured\n");
12863 :
12864 : /* prefix-list */
12865 0 : if (filter->plist[FILTER_IN].name)
12866 0 : vty_out(vty,
12867 : " Incoming update prefix filter list is %s%s\n",
12868 0 : filter->plist[FILTER_IN].plist ? "*" : "",
12869 : filter->plist[FILTER_IN].name);
12870 0 : if (filter->plist[FILTER_OUT].name)
12871 0 : vty_out(vty,
12872 : " Outgoing update prefix filter list is %s%s\n",
12873 0 : filter->plist[FILTER_OUT].plist ? "*" : "",
12874 : filter->plist[FILTER_OUT].name);
12875 :
12876 : /* distribute-list */
12877 0 : if (filter->dlist[FILTER_IN].name)
12878 0 : vty_out(vty,
12879 : " Incoming update network filter list is %s%s\n",
12880 0 : filter->dlist[FILTER_IN].alist ? "*" : "",
12881 : filter->dlist[FILTER_IN].name);
12882 0 : if (filter->dlist[FILTER_OUT].name)
12883 0 : vty_out(vty,
12884 : " Outgoing update network filter list is %s%s\n",
12885 0 : filter->dlist[FILTER_OUT].alist ? "*" : "",
12886 : filter->dlist[FILTER_OUT].name);
12887 :
12888 : /* filter-list. */
12889 0 : if (filter->aslist[FILTER_IN].name)
12890 0 : vty_out(vty,
12891 : " Incoming update AS path filter list is %s%s\n",
12892 0 : filter->aslist[FILTER_IN].aslist ? "*" : "",
12893 : filter->aslist[FILTER_IN].name);
12894 0 : if (filter->aslist[FILTER_OUT].name)
12895 0 : vty_out(vty,
12896 : " Outgoing update AS path filter list is %s%s\n",
12897 0 : filter->aslist[FILTER_OUT].aslist ? "*" : "",
12898 : filter->aslist[FILTER_OUT].name);
12899 :
12900 : /* route-map. */
12901 0 : if (filter->map[RMAP_IN].name)
12902 0 : vty_out(vty,
12903 : " Route map for incoming advertisements is %s%s\n",
12904 0 : filter->map[RMAP_IN].map ? "*" : "",
12905 : filter->map[RMAP_IN].name);
12906 0 : if (filter->map[RMAP_OUT].name)
12907 0 : vty_out(vty,
12908 : " Route map for outgoing advertisements is %s%s\n",
12909 0 : filter->map[RMAP_OUT].map ? "*" : "",
12910 : filter->map[RMAP_OUT].name);
12911 :
12912 : /* ebgp-requires-policy (inbound) */
12913 0 : if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12914 0 : && !bgp_inbound_policy_exists(p, filter))
12915 0 : vty_out(vty,
12916 : " Inbound updates discarded due to missing policy\n");
12917 :
12918 : /* ebgp-requires-policy (outbound) */
12919 0 : if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12920 0 : && !bgp_outbound_policy_exists(p, filter))
12921 0 : vty_out(vty,
12922 : " Outbound updates discarded due to missing policy\n");
12923 :
12924 : /* unsuppress-map */
12925 0 : if (filter->usmap.name)
12926 0 : vty_out(vty,
12927 : " Route map for selective unsuppress is %s%s\n",
12928 0 : filter->usmap.map ? "*" : "",
12929 : filter->usmap.name);
12930 :
12931 : /* advertise-map */
12932 0 : if (filter->advmap.aname && filter->advmap.cname)
12933 0 : vty_out(vty,
12934 : " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12935 0 : filter->advmap.condition ? "EXIST"
12936 : : "NON_EXIST",
12937 0 : filter->advmap.cmap ? "*" : "",
12938 : filter->advmap.cname,
12939 0 : filter->advmap.amap ? "*" : "",
12940 : filter->advmap.aname,
12941 0 : filter->advmap.update_type ==
12942 : UPDATE_TYPE_ADVERTISE
12943 : ? "Advertise"
12944 : : "Withdraw");
12945 :
12946 : /* Receive prefix count */
12947 0 : vty_out(vty, " %u accepted prefixes\n",
12948 : p->pcount[afi][safi]);
12949 :
12950 : /* maximum-prefix-out */
12951 0 : if (CHECK_FLAG(p->af_flags[afi][safi],
12952 : PEER_FLAG_MAX_PREFIX_OUT))
12953 0 : vty_out(vty,
12954 : " Maximum allowed prefixes sent %u\n",
12955 : p->pmax_out[afi][safi]);
12956 :
12957 : /* Maximum prefix */
12958 0 : if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12959 0 : vty_out(vty,
12960 : " Maximum prefixes allowed %u%s\n",
12961 : p->pmax[afi][safi],
12962 0 : CHECK_FLAG(p->af_flags[afi][safi],
12963 : PEER_FLAG_MAX_PREFIX_WARNING)
12964 : ? " (warning-only)"
12965 : : "");
12966 0 : vty_out(vty, " Threshold for warning message %d%%",
12967 0 : p->pmax_threshold[afi][safi]);
12968 0 : if (p->pmax_restart[afi][safi])
12969 0 : vty_out(vty, ", restart interval %d min",
12970 : p->pmax_restart[afi][safi]);
12971 0 : vty_out(vty, "\n");
12972 : }
12973 :
12974 0 : vty_out(vty, "\n");
12975 : }
12976 27 : }
12977 :
12978 27 : static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12979 : json_object *json)
12980 : {
12981 27 : struct bgp *bgp;
12982 27 : char timebuf[BGP_UPTIME_LEN];
12983 27 : char dn_flag[2];
12984 27 : afi_t afi;
12985 27 : safi_t safi;
12986 27 : uint16_t i;
12987 27 : uint8_t *msg;
12988 27 : json_object *json_neigh = NULL;
12989 27 : time_t epoch_tbuf;
12990 27 : uint32_t sync_tcp_mss;
12991 :
12992 27 : bgp = p->bgp;
12993 :
12994 27 : if (use_json)
12995 27 : json_neigh = json_object_new_object();
12996 :
12997 27 : memset(dn_flag, '\0', sizeof(dn_flag));
12998 27 : if (!p->conf_if && peer_dynamic_neighbor(p))
12999 0 : dn_flag[0] = '*';
13000 :
13001 27 : if (!use_json) {
13002 0 : if (p->conf_if) /* Configured interface name. */
13003 0 : vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
13004 : &p->su);
13005 : else /* Configured IP address. */
13006 0 : vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
13007 : p->host);
13008 : }
13009 :
13010 27 : if (use_json) {
13011 27 : if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
13012 0 : json_object_string_add(json_neigh, "bgpNeighborAddr",
13013 : "none");
13014 27 : else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
13015 0 : json_object_string_addf(json_neigh, "bgpNeighborAddr",
13016 : "%pSU", &p->su);
13017 :
13018 27 : json_object_int_add(json_neigh, "remoteAs", p->as);
13019 :
13020 27 : if (p->change_local_as)
13021 0 : json_object_int_add(json_neigh, "localAs",
13022 : p->change_local_as);
13023 : else
13024 27 : json_object_int_add(json_neigh, "localAs", p->local_as);
13025 :
13026 27 : if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
13027 0 : json_object_boolean_true_add(json_neigh,
13028 : "localAsNoPrepend");
13029 :
13030 27 : if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
13031 0 : json_object_boolean_true_add(json_neigh,
13032 : "localAsReplaceAs");
13033 : } else {
13034 0 : if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
13035 0 : || (p->as_type == AS_INTERNAL))
13036 0 : vty_out(vty, "remote AS %u, ", p->as);
13037 : else
13038 0 : vty_out(vty, "remote AS Unspecified, ");
13039 0 : vty_out(vty, "local AS %u%s%s, ",
13040 0 : p->change_local_as ? p->change_local_as : p->local_as,
13041 0 : CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
13042 : ? " no-prepend"
13043 : : "",
13044 0 : CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
13045 : ? " replace-as"
13046 : : "");
13047 : }
13048 : /* peer type internal or confed-internal */
13049 27 : if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
13050 0 : if (use_json) {
13051 0 : if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13052 0 : json_object_boolean_true_add(
13053 : json_neigh, "nbrConfedInternalLink");
13054 : else
13055 0 : json_object_boolean_true_add(json_neigh,
13056 : "nbrInternalLink");
13057 : } else {
13058 0 : if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13059 0 : vty_out(vty, "confed-internal link\n");
13060 : else
13061 0 : vty_out(vty, "internal link\n");
13062 : }
13063 : /* peer type external or confed-external */
13064 27 : } else if (p->as || (p->as_type == AS_EXTERNAL)) {
13065 27 : if (use_json) {
13066 27 : if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
13067 0 : json_object_boolean_true_add(
13068 : json_neigh, "nbrConfedExternalLink");
13069 : else
13070 27 : json_object_boolean_true_add(json_neigh,
13071 : "nbrExternalLink");
13072 : } else {
13073 0 : if (bgp_confederation_peers_check(bgp, p->as))
13074 0 : vty_out(vty, "confed-external link\n");
13075 : else
13076 0 : vty_out(vty, "external link\n");
13077 : }
13078 : } else {
13079 0 : if (use_json)
13080 0 : json_object_boolean_true_add(json_neigh,
13081 : "nbrUnspecifiedLink");
13082 : else
13083 0 : vty_out(vty, "unspecified link\n");
13084 : }
13085 :
13086 : /* Roles */
13087 27 : if (use_json) {
13088 27 : json_object_string_add(json_neigh, "localRole",
13089 27 : bgp_get_name_by_role(p->local_role));
13090 27 : json_object_string_add(json_neigh, "remoteRole",
13091 27 : bgp_get_name_by_role(p->remote_role));
13092 : } else {
13093 0 : vty_out(vty, " Local Role: %s\n",
13094 0 : bgp_get_name_by_role(p->local_role));
13095 0 : vty_out(vty, " Remote Role: %s\n",
13096 0 : bgp_get_name_by_role(p->remote_role));
13097 : }
13098 :
13099 :
13100 : /* Description. */
13101 27 : if (p->desc) {
13102 0 : if (use_json)
13103 0 : json_object_string_add(json_neigh, "nbrDesc", p->desc);
13104 : else
13105 0 : vty_out(vty, " Description: %s\n", p->desc);
13106 : }
13107 :
13108 27 : if (p->hostname) {
13109 12 : if (use_json) {
13110 12 : json_object_string_add(json_neigh, "hostname",
13111 : p->hostname);
13112 :
13113 12 : if (p->domainname)
13114 0 : json_object_string_add(json_neigh, "domainname",
13115 : p->domainname);
13116 : } else {
13117 0 : if (p->domainname && (p->domainname[0] != '\0'))
13118 0 : vty_out(vty, "Hostname: %s.%s\n", p->hostname,
13119 : p->domainname);
13120 : else
13121 0 : vty_out(vty, "Hostname: %s\n", p->hostname);
13122 : }
13123 : } else {
13124 15 : if (use_json)
13125 15 : json_object_string_add(json_neigh, "hostname",
13126 : "Unknown");
13127 : }
13128 :
13129 : /* Peer-group */
13130 27 : if (p->group) {
13131 0 : if (use_json) {
13132 0 : json_object_string_add(json_neigh, "peerGroup",
13133 0 : p->group->name);
13134 :
13135 0 : if (dn_flag[0]) {
13136 0 : struct prefix prefix, *range = NULL;
13137 :
13138 0 : if (sockunion2hostprefix(&(p->su), &prefix))
13139 0 : range = peer_group_lookup_dynamic_neighbor_range(
13140 : p->group, &prefix);
13141 :
13142 0 : if (range) {
13143 0 : json_object_string_addf(
13144 : json_neigh,
13145 : "peerSubnetRangeGroup", "%pFX",
13146 : range);
13147 : }
13148 : }
13149 : } else {
13150 0 : vty_out(vty,
13151 : " Member of peer-group %s for session parameters\n",
13152 : p->group->name);
13153 :
13154 0 : if (dn_flag[0]) {
13155 0 : struct prefix prefix, *range = NULL;
13156 :
13157 0 : if (sockunion2hostprefix(&(p->su), &prefix))
13158 0 : range = peer_group_lookup_dynamic_neighbor_range(
13159 : p->group, &prefix);
13160 :
13161 0 : if (range) {
13162 0 : vty_out(vty,
13163 : " Belongs to the subnet range group: %pFX\n",
13164 : range);
13165 : }
13166 : }
13167 : }
13168 : }
13169 :
13170 27 : if (use_json) {
13171 : /* Administrative shutdown. */
13172 27 : if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13173 27 : || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13174 0 : json_object_boolean_true_add(json_neigh,
13175 : "adminShutDown");
13176 :
13177 : /* BGP Version. */
13178 27 : json_object_int_add(json_neigh, "bgpVersion", 4);
13179 27 : json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
13180 : &p->remote_id);
13181 27 : json_object_string_addf(json_neigh, "localRouterId", "%pI4",
13182 : &bgp->router_id);
13183 :
13184 : /* Confederation */
13185 27 : if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13186 0 : && bgp_confederation_peers_check(bgp, p->as))
13187 0 : json_object_boolean_true_add(json_neigh,
13188 : "nbrCommonAdmin");
13189 :
13190 : /* Status. */
13191 27 : json_object_string_add(
13192 : json_neigh, "bgpState",
13193 27 : lookup_msg(bgp_status_msg, p->status, NULL));
13194 :
13195 27 : if (peer_established(p)) {
13196 12 : time_t uptime;
13197 :
13198 12 : uptime = monotime(NULL);
13199 12 : uptime -= p->uptime;
13200 12 : epoch_tbuf = time(NULL) - uptime;
13201 :
13202 12 : json_object_int_add(json_neigh, "bgpTimerUpMsec",
13203 : uptime * 1000);
13204 12 : json_object_string_add(json_neigh, "bgpTimerUpString",
13205 12 : peer_uptime(p->uptime, timebuf,
13206 : BGP_UPTIME_LEN, 0,
13207 : NULL));
13208 12 : json_object_int_add(json_neigh,
13209 : "bgpTimerUpEstablishedEpoch",
13210 : epoch_tbuf);
13211 : }
13212 :
13213 15 : else if (p->status == Active) {
13214 0 : if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13215 0 : json_object_string_add(json_neigh, "bgpStateIs",
13216 : "passive");
13217 0 : else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13218 0 : json_object_string_add(json_neigh, "bgpStateIs",
13219 : "passiveNSF");
13220 : }
13221 :
13222 : /* read timer */
13223 27 : time_t uptime;
13224 27 : struct tm tm;
13225 :
13226 27 : uptime = monotime(NULL);
13227 27 : uptime -= p->readtime;
13228 27 : gmtime_r(&uptime, &tm);
13229 :
13230 27 : json_object_int_add(json_neigh, "bgpTimerLastRead",
13231 27 : (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13232 27 : + (tm.tm_hour * 3600000));
13233 :
13234 27 : uptime = monotime(NULL);
13235 27 : uptime -= p->last_write;
13236 27 : gmtime_r(&uptime, &tm);
13237 :
13238 27 : json_object_int_add(json_neigh, "bgpTimerLastWrite",
13239 27 : (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13240 27 : + (tm.tm_hour * 3600000));
13241 :
13242 27 : uptime = monotime(NULL);
13243 27 : uptime -= p->update_time;
13244 27 : gmtime_r(&uptime, &tm);
13245 :
13246 27 : json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
13247 27 : (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13248 27 : + (tm.tm_hour * 3600000));
13249 :
13250 : /* Configured timer values. */
13251 27 : json_object_int_add(json_neigh,
13252 : "bgpTimerConfiguredHoldTimeMsecs",
13253 27 : CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13254 27 : ? p->holdtime * 1000
13255 0 : : bgp->default_holdtime * 1000);
13256 27 : json_object_int_add(json_neigh,
13257 : "bgpTimerConfiguredKeepAliveIntervalMsecs",
13258 27 : CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13259 27 : ? p->keepalive * 1000
13260 0 : : bgp->default_keepalive * 1000);
13261 27 : json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13262 27 : p->v_holdtime * 1000);
13263 27 : json_object_int_add(json_neigh,
13264 : "bgpTimerKeepAliveIntervalMsecs",
13265 27 : p->v_keepalive * 1000);
13266 27 : if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13267 0 : json_object_int_add(json_neigh,
13268 : "bgpTimerDelayOpenTimeMsecs",
13269 0 : p->v_delayopen * 1000);
13270 : }
13271 :
13272 : /* Configured and Synced tcp-mss value for peer */
13273 27 : if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13274 0 : sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13275 0 : json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13276 0 : p->tcp_mss);
13277 0 : json_object_int_add(json_neigh, "bgpTcpMssSynced",
13278 : sync_tcp_mss);
13279 : }
13280 :
13281 : /* Extended Optional Parameters Length for BGP OPEN Message */
13282 27 : if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13283 0 : json_object_boolean_true_add(
13284 : json_neigh, "extendedOptionalParametersLength");
13285 : else
13286 27 : json_object_boolean_false_add(
13287 : json_neigh, "extendedOptionalParametersLength");
13288 :
13289 : /* Conditional advertisements */
13290 27 : json_object_int_add(
13291 : json_neigh,
13292 : "bgpTimerConfiguredConditionalAdvertisementsSec",
13293 27 : bgp->condition_check_period);
13294 27 : if (thread_is_scheduled(bgp->t_condition_check))
13295 0 : json_object_int_add(
13296 : json_neigh,
13297 : "bgpTimerUntilConditionalAdvertisementsSec",
13298 0 : thread_timer_remain_second(
13299 : bgp->t_condition_check));
13300 : } else {
13301 : /* Administrative shutdown. */
13302 0 : if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13303 0 : || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
13304 0 : vty_out(vty, " Administratively shut down\n");
13305 :
13306 : /* BGP Version. */
13307 0 : vty_out(vty, " BGP version 4");
13308 0 : vty_out(vty, ", remote router ID %pI4", &p->remote_id);
13309 0 : vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
13310 :
13311 : /* Confederation */
13312 0 : if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13313 0 : && bgp_confederation_peers_check(bgp, p->as))
13314 0 : vty_out(vty,
13315 : " Neighbor under common administration\n");
13316 :
13317 : /* Status. */
13318 0 : vty_out(vty, " BGP state = %s",
13319 0 : lookup_msg(bgp_status_msg, p->status, NULL));
13320 :
13321 0 : if (peer_established(p))
13322 0 : vty_out(vty, ", up for %8s",
13323 : peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13324 : 0, NULL));
13325 :
13326 0 : else if (p->status == Active) {
13327 0 : if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13328 0 : vty_out(vty, " (passive)");
13329 0 : else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13330 0 : vty_out(vty, " (NSF passive)");
13331 : }
13332 0 : vty_out(vty, "\n");
13333 :
13334 : /* read timer */
13335 0 : vty_out(vty, " Last read %s",
13336 : peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13337 : NULL));
13338 0 : vty_out(vty, ", Last write %s\n",
13339 0 : peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13340 : NULL));
13341 :
13342 : /* Configured timer values. */
13343 0 : vty_out(vty,
13344 : " Hold time is %d seconds, keepalive interval is %d seconds\n",
13345 0 : p->v_holdtime, p->v_keepalive);
13346 0 : vty_out(vty, " Configured hold time is %d seconds",
13347 0 : CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13348 0 : ? p->holdtime
13349 : : bgp->default_holdtime);
13350 0 : vty_out(vty, ", keepalive interval is %d seconds\n",
13351 0 : CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
13352 0 : ? p->keepalive
13353 : : bgp->default_keepalive);
13354 0 : if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13355 0 : vty_out(vty,
13356 : " Configured DelayOpenTime is %d seconds\n",
13357 0 : p->delayopen);
13358 :
13359 : /* Configured and synced tcp-mss value for peer */
13360 0 : if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13361 0 : sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13362 0 : vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13363 0 : vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13364 : }
13365 :
13366 : /* Extended Optional Parameters Length for BGP OPEN Message */
13367 0 : if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
13368 0 : vty_out(vty,
13369 : " Extended Optional Parameters Length is enabled\n");
13370 :
13371 : /* Conditional advertisements */
13372 0 : vty_out(vty,
13373 : " Configured conditional advertisements interval is %d seconds\n",
13374 : bgp->condition_check_period);
13375 0 : if (thread_is_scheduled(bgp->t_condition_check))
13376 0 : vty_out(vty,
13377 : " Time until conditional advertisements begin is %lu seconds\n",
13378 : thread_timer_remain_second(
13379 : bgp->t_condition_check));
13380 : }
13381 : /* Capability. */
13382 27 : if (peer_established(p) &&
13383 12 : (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
13384 12 : if (use_json) {
13385 12 : json_object *json_cap = NULL;
13386 :
13387 12 : json_cap = json_object_new_object();
13388 :
13389 : /* AS4 */
13390 12 : if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13391 : CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13392 12 : if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
13393 : CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13394 12 : json_object_string_add(
13395 : json_cap, "4byteAs",
13396 : "advertisedAndReceived");
13397 0 : else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13398 0 : json_object_string_add(json_cap,
13399 : "4byteAs",
13400 : "advertised");
13401 0 : else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13402 0 : json_object_string_add(json_cap,
13403 : "4byteAs",
13404 : "received");
13405 : }
13406 :
13407 : /* Extended Message Support */
13408 12 : if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13409 : CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13410 12 : json_object_string_add(json_cap,
13411 : "extendedMessage",
13412 : "advertisedAndReceived");
13413 0 : else if (CHECK_FLAG(p->cap,
13414 : PEER_CAP_EXTENDED_MESSAGE_ADV))
13415 0 : json_object_string_add(json_cap,
13416 : "extendedMessage",
13417 : "advertised");
13418 0 : else if (CHECK_FLAG(p->cap,
13419 : PEER_CAP_EXTENDED_MESSAGE_RCV))
13420 0 : json_object_string_add(json_cap,
13421 : "extendedMessage",
13422 : "received");
13423 :
13424 : /* AddPath */
13425 12 : if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13426 : CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13427 12 : json_object *json_add = NULL;
13428 12 : const char *print_store;
13429 :
13430 12 : json_add = json_object_new_object();
13431 :
13432 312 : FOREACH_AFI_SAFI (afi, safi) {
13433 252 : json_object *json_sub = NULL;
13434 252 : json_sub = json_object_new_object();
13435 252 : print_store = get_afi_safi_str(
13436 : afi, safi, true);
13437 :
13438 252 : if (CHECK_FLAG(
13439 : p->af_cap[afi][safi],
13440 252 : PEER_CAP_ADDPATH_AF_TX_ADV) ||
13441 252 : CHECK_FLAG(
13442 : p->af_cap[afi][safi],
13443 : PEER_CAP_ADDPATH_AF_TX_RCV)) {
13444 0 : if (CHECK_FLAG(
13445 : p->af_cap[afi]
13446 : [safi],
13447 0 : PEER_CAP_ADDPATH_AF_TX_ADV) &&
13448 0 : CHECK_FLAG(
13449 : p->af_cap[afi]
13450 : [safi],
13451 : PEER_CAP_ADDPATH_AF_TX_RCV))
13452 0 : json_object_boolean_true_add(
13453 : json_sub,
13454 : "txAdvertisedAndReceived");
13455 0 : else if (
13456 : CHECK_FLAG(
13457 : p->af_cap[afi]
13458 : [safi],
13459 : PEER_CAP_ADDPATH_AF_TX_ADV))
13460 0 : json_object_boolean_true_add(
13461 : json_sub,
13462 : "txAdvertised");
13463 0 : else if (
13464 0 : CHECK_FLAG(
13465 : p->af_cap[afi]
13466 : [safi],
13467 : PEER_CAP_ADDPATH_AF_TX_RCV))
13468 0 : json_object_boolean_true_add(
13469 : json_sub,
13470 : "txReceived");
13471 : }
13472 :
13473 252 : if (CHECK_FLAG(
13474 : p->af_cap[afi][safi],
13475 240 : PEER_CAP_ADDPATH_AF_RX_ADV) ||
13476 240 : CHECK_FLAG(
13477 : p->af_cap[afi][safi],
13478 : PEER_CAP_ADDPATH_AF_RX_RCV)) {
13479 12 : if (CHECK_FLAG(
13480 : p->af_cap[afi]
13481 : [safi],
13482 12 : PEER_CAP_ADDPATH_AF_RX_ADV) &&
13483 12 : CHECK_FLAG(
13484 : p->af_cap[afi]
13485 : [safi],
13486 : PEER_CAP_ADDPATH_AF_RX_RCV))
13487 12 : json_object_boolean_true_add(
13488 : json_sub,
13489 : "rxAdvertisedAndReceived");
13490 0 : else if (
13491 : CHECK_FLAG(
13492 : p->af_cap[afi]
13493 : [safi],
13494 : PEER_CAP_ADDPATH_AF_RX_ADV))
13495 0 : json_object_boolean_true_add(
13496 : json_sub,
13497 : "rxAdvertised");
13498 0 : else if (
13499 0 : CHECK_FLAG(
13500 : p->af_cap[afi]
13501 : [safi],
13502 : PEER_CAP_ADDPATH_AF_RX_RCV))
13503 0 : json_object_boolean_true_add(
13504 : json_sub,
13505 : "rxReceived");
13506 : }
13507 :
13508 252 : if (CHECK_FLAG(
13509 : p->af_cap[afi][safi],
13510 252 : PEER_CAP_ADDPATH_AF_TX_ADV) ||
13511 252 : CHECK_FLAG(
13512 : p->af_cap[afi][safi],
13513 252 : PEER_CAP_ADDPATH_AF_TX_RCV) ||
13514 252 : CHECK_FLAG(
13515 : p->af_cap[afi][safi],
13516 240 : PEER_CAP_ADDPATH_AF_RX_ADV) ||
13517 240 : CHECK_FLAG(
13518 : p->af_cap[afi][safi],
13519 : PEER_CAP_ADDPATH_AF_RX_RCV))
13520 12 : json_object_object_add(
13521 : json_add, print_store,
13522 : json_sub);
13523 : else
13524 240 : json_object_free(json_sub);
13525 : }
13526 :
13527 12 : json_object_object_add(json_cap, "addPath",
13528 : json_add);
13529 : }
13530 :
13531 : /* Dynamic */
13532 12 : if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13533 : CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13534 0 : if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13535 : CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13536 0 : json_object_string_add(
13537 : json_cap, "dynamic",
13538 : "advertisedAndReceived");
13539 0 : else if (CHECK_FLAG(p->cap,
13540 : PEER_CAP_DYNAMIC_ADV))
13541 0 : json_object_string_add(json_cap,
13542 : "dynamic",
13543 : "advertised");
13544 0 : else if (CHECK_FLAG(p->cap,
13545 : PEER_CAP_DYNAMIC_RCV))
13546 0 : json_object_string_add(json_cap,
13547 : "dynamic",
13548 : "received");
13549 : }
13550 :
13551 : /* Role */
13552 12 : if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13553 : CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13554 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13555 : CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13556 0 : json_object_string_add(
13557 : json_cap, "role",
13558 : "advertisedAndReceived");
13559 0 : else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13560 0 : json_object_string_add(json_cap, "role",
13561 : "advertised");
13562 0 : else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13563 0 : json_object_string_add(json_cap, "role",
13564 : "received");
13565 : }
13566 :
13567 : /* Extended nexthop */
13568 12 : if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13569 : CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13570 0 : json_object *json_nxt = NULL;
13571 0 : const char *print_store;
13572 :
13573 :
13574 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13575 : CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13576 0 : json_object_string_add(
13577 : json_cap, "extendedNexthop",
13578 : "advertisedAndReceived");
13579 0 : else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13580 0 : json_object_string_add(
13581 : json_cap, "extendedNexthop",
13582 : "advertised");
13583 0 : else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13584 0 : json_object_string_add(
13585 : json_cap, "extendedNexthop",
13586 : "received");
13587 :
13588 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13589 0 : json_nxt = json_object_new_object();
13590 :
13591 0 : for (safi = SAFI_UNICAST;
13592 0 : safi < SAFI_MAX; safi++) {
13593 0 : if (CHECK_FLAG(
13594 : p->af_cap[AFI_IP]
13595 : [safi],
13596 : PEER_CAP_ENHE_AF_RCV)) {
13597 0 : print_store =
13598 0 : get_afi_safi_str(
13599 : AFI_IP,
13600 : safi,
13601 : true);
13602 0 : json_object_string_add(
13603 : json_nxt,
13604 : print_store,
13605 : "recieved"); /* misspelled for compatibility */
13606 : }
13607 : }
13608 0 : json_object_object_add(
13609 : json_cap,
13610 : "extendedNexthopFamililesByPeer",
13611 : json_nxt);
13612 : }
13613 : }
13614 :
13615 : /* Long-lived Graceful Restart */
13616 12 : if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13617 : CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13618 12 : json_object *json_llgr = NULL;
13619 12 : const char *afi_safi_str;
13620 :
13621 12 : if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13622 : CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13623 12 : json_object_string_add(
13624 : json_cap,
13625 : "longLivedGracefulRestart",
13626 : "advertisedAndReceived");
13627 0 : else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13628 0 : json_object_string_add(
13629 : json_cap,
13630 : "longLivedGracefulRestart",
13631 : "advertised");
13632 0 : else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13633 0 : json_object_string_add(
13634 : json_cap,
13635 : "longLivedGracefulRestart",
13636 : "received");
13637 :
13638 12 : if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13639 12 : json_llgr = json_object_new_object();
13640 :
13641 312 : FOREACH_AFI_SAFI (afi, safi) {
13642 252 : if (CHECK_FLAG(
13643 : p->af_cap[afi]
13644 : [safi],
13645 : PEER_CAP_ENHE_AF_RCV)) {
13646 0 : afi_safi_str =
13647 0 : get_afi_safi_str(
13648 : afi,
13649 : safi,
13650 : true);
13651 0 : json_object_string_add(
13652 : json_llgr,
13653 : afi_safi_str,
13654 : "received");
13655 : }
13656 : }
13657 12 : json_object_object_add(
13658 : json_cap,
13659 : "longLivedGracefulRestartByPeer",
13660 : json_llgr);
13661 : }
13662 : }
13663 :
13664 : /* Route Refresh */
13665 12 : if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13666 12 : CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13667 : CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13668 12 : if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13669 : (CHECK_FLAG(p->cap,
13670 12 : PEER_CAP_REFRESH_NEW_RCV) ||
13671 : CHECK_FLAG(p->cap,
13672 : PEER_CAP_REFRESH_OLD_RCV))) {
13673 12 : if (CHECK_FLAG(
13674 : p->cap,
13675 : PEER_CAP_REFRESH_OLD_RCV) &&
13676 : CHECK_FLAG(
13677 : p->cap,
13678 : PEER_CAP_REFRESH_NEW_RCV))
13679 12 : json_object_string_add(
13680 : json_cap,
13681 : "routeRefresh",
13682 : "advertisedAndReceivedOldNew");
13683 : else {
13684 0 : if (CHECK_FLAG(
13685 : p->cap,
13686 : PEER_CAP_REFRESH_OLD_RCV))
13687 0 : json_object_string_add(
13688 : json_cap,
13689 : "routeRefresh",
13690 : "advertisedAndReceivedOld");
13691 : else
13692 0 : json_object_string_add(
13693 : json_cap,
13694 : "routeRefresh",
13695 : "advertisedAndReceivedNew");
13696 : }
13697 0 : } else if (CHECK_FLAG(p->cap,
13698 : PEER_CAP_REFRESH_ADV))
13699 0 : json_object_string_add(json_cap,
13700 : "routeRefresh",
13701 : "advertised");
13702 0 : else if (CHECK_FLAG(p->cap,
13703 0 : PEER_CAP_REFRESH_NEW_RCV) ||
13704 : CHECK_FLAG(p->cap,
13705 : PEER_CAP_REFRESH_OLD_RCV))
13706 0 : json_object_string_add(json_cap,
13707 : "routeRefresh",
13708 : "received");
13709 : }
13710 :
13711 : /* Enhanced Route Refresh */
13712 12 : if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13713 : CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13714 12 : if (CHECK_FLAG(p->cap,
13715 : PEER_CAP_ENHANCED_RR_ADV) &&
13716 : CHECK_FLAG(p->cap,
13717 : PEER_CAP_ENHANCED_RR_RCV))
13718 12 : json_object_string_add(
13719 : json_cap,
13720 : "enhancedRouteRefresh",
13721 : "advertisedAndReceived");
13722 0 : else if (CHECK_FLAG(p->cap,
13723 : PEER_CAP_ENHANCED_RR_ADV))
13724 0 : json_object_string_add(
13725 : json_cap,
13726 : "enhancedRouteRefresh",
13727 : "advertised");
13728 0 : else if (CHECK_FLAG(p->cap,
13729 : PEER_CAP_ENHANCED_RR_RCV))
13730 0 : json_object_string_add(
13731 : json_cap,
13732 : "enhancedRouteRefresh",
13733 : "received");
13734 : }
13735 :
13736 : /* Multiprotocol Extensions */
13737 12 : json_object *json_multi = NULL;
13738 :
13739 12 : json_multi = json_object_new_object();
13740 :
13741 312 : FOREACH_AFI_SAFI (afi, safi) {
13742 252 : if (p->afc_adv[afi][safi] ||
13743 240 : p->afc_recv[afi][safi]) {
13744 12 : json_object *json_exten = NULL;
13745 12 : json_exten = json_object_new_object();
13746 :
13747 12 : if (p->afc_adv[afi][safi] &&
13748 12 : p->afc_recv[afi][safi])
13749 12 : json_object_boolean_true_add(
13750 : json_exten,
13751 : "advertisedAndReceived");
13752 0 : else if (p->afc_adv[afi][safi])
13753 0 : json_object_boolean_true_add(
13754 : json_exten,
13755 : "advertised");
13756 0 : else if (p->afc_recv[afi][safi])
13757 0 : json_object_boolean_true_add(
13758 : json_exten, "received");
13759 :
13760 12 : json_object_object_add(
13761 : json_multi,
13762 : get_afi_safi_str(afi, safi,
13763 : true),
13764 : json_exten);
13765 : }
13766 : }
13767 12 : json_object_object_add(json_cap,
13768 : "multiprotocolExtensions",
13769 : json_multi);
13770 :
13771 : /* Hostname capabilities */
13772 12 : json_object *json_hname = NULL;
13773 :
13774 12 : json_hname = json_object_new_object();
13775 :
13776 12 : if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13777 12 : json_object_string_add(
13778 : json_hname, "advHostName",
13779 12 : bgp->peer_self->hostname
13780 : ? bgp->peer_self->hostname
13781 : : "n/a");
13782 12 : json_object_string_add(
13783 : json_hname, "advDomainName",
13784 12 : bgp->peer_self->domainname
13785 : ? bgp->peer_self->domainname
13786 : : "n/a");
13787 : }
13788 :
13789 :
13790 12 : if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13791 12 : json_object_string_add(
13792 : json_hname, "rcvHostName",
13793 12 : p->hostname ? p->hostname : "n/a");
13794 12 : json_object_string_add(
13795 : json_hname, "rcvDomainName",
13796 12 : p->domainname ? p->domainname : "n/a");
13797 : }
13798 :
13799 12 : json_object_object_add(json_cap, "hostName",
13800 : json_hname);
13801 :
13802 : /* Graceful Restart */
13803 12 : if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13804 : CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13805 12 : if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13806 : CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13807 12 : json_object_string_add(
13808 : json_cap, "gracefulRestart",
13809 : "advertisedAndReceived");
13810 0 : else if (CHECK_FLAG(p->cap,
13811 : PEER_CAP_RESTART_ADV))
13812 0 : json_object_string_add(
13813 : json_cap,
13814 : "gracefulRestartCapability",
13815 : "advertised");
13816 0 : else if (CHECK_FLAG(p->cap,
13817 : PEER_CAP_RESTART_RCV))
13818 0 : json_object_string_add(
13819 : json_cap,
13820 : "gracefulRestartCapability",
13821 : "received");
13822 :
13823 12 : if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13824 12 : int restart_af_count = 0;
13825 12 : json_object *json_restart = NULL;
13826 12 : json_restart = json_object_new_object();
13827 :
13828 12 : json_object_int_add(
13829 : json_cap,
13830 : "gracefulRestartRemoteTimerMsecs",
13831 12 : p->v_gr_restart * 1000);
13832 :
13833 312 : FOREACH_AFI_SAFI (afi, safi) {
13834 252 : if (CHECK_FLAG(
13835 : p->af_cap[afi]
13836 : [safi],
13837 : PEER_CAP_RESTART_AF_RCV)) {
13838 0 : json_object *json_sub =
13839 : NULL;
13840 0 : json_sub =
13841 0 : json_object_new_object();
13842 :
13843 0 : if (CHECK_FLAG(
13844 : p->af_cap
13845 : [afi]
13846 : [safi],
13847 : PEER_CAP_RESTART_AF_PRESERVE_RCV))
13848 0 : json_object_boolean_true_add(
13849 : json_sub,
13850 : "preserved");
13851 0 : restart_af_count++;
13852 0 : json_object_object_add(
13853 : json_restart,
13854 : get_afi_safi_str(
13855 : afi,
13856 : safi,
13857 : true),
13858 : json_sub);
13859 : }
13860 : }
13861 12 : if (!restart_af_count) {
13862 12 : json_object_string_add(
13863 : json_cap,
13864 : "addressFamiliesByPeer",
13865 : "none");
13866 12 : json_object_free(json_restart);
13867 : } else
13868 0 : json_object_object_add(
13869 : json_cap,
13870 : "addressFamiliesByPeer",
13871 : json_restart);
13872 : }
13873 : }
13874 12 : json_object_object_add(
13875 : json_neigh, "neighborCapabilities", json_cap);
13876 : } else {
13877 0 : vty_out(vty, " Neighbor capabilities:\n");
13878 :
13879 : /* AS4 */
13880 0 : if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13881 : CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13882 0 : vty_out(vty, " 4 Byte AS:");
13883 0 : if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13884 0 : vty_out(vty, " advertised");
13885 0 : if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13886 0 : vty_out(vty, " %sreceived",
13887 0 : CHECK_FLAG(p->cap,
13888 : PEER_CAP_AS4_ADV)
13889 : ? "and "
13890 : : "");
13891 0 : vty_out(vty, "\n");
13892 : }
13893 :
13894 : /* Extended Message Support */
13895 0 : if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13896 : CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13897 0 : vty_out(vty, " Extended Message:");
13898 0 : if (CHECK_FLAG(p->cap,
13899 : PEER_CAP_EXTENDED_MESSAGE_ADV))
13900 0 : vty_out(vty, " advertised");
13901 0 : if (CHECK_FLAG(p->cap,
13902 : PEER_CAP_EXTENDED_MESSAGE_RCV))
13903 0 : vty_out(vty, " %sreceived",
13904 0 : CHECK_FLAG(
13905 : p->cap,
13906 : PEER_CAP_EXTENDED_MESSAGE_ADV)
13907 : ? "and "
13908 : : "");
13909 0 : vty_out(vty, "\n");
13910 : }
13911 :
13912 : /* AddPath */
13913 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13914 : CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13915 0 : vty_out(vty, " AddPath:\n");
13916 :
13917 0 : FOREACH_AFI_SAFI (afi, safi) {
13918 0 : if (CHECK_FLAG(
13919 : p->af_cap[afi][safi],
13920 0 : PEER_CAP_ADDPATH_AF_TX_ADV) ||
13921 0 : CHECK_FLAG(
13922 : p->af_cap[afi][safi],
13923 : PEER_CAP_ADDPATH_AF_TX_RCV)) {
13924 0 : vty_out(vty, " %s: TX ",
13925 : get_afi_safi_str(
13926 : afi, safi,
13927 : false));
13928 :
13929 0 : if (CHECK_FLAG(
13930 : p->af_cap[afi]
13931 : [safi],
13932 : PEER_CAP_ADDPATH_AF_TX_ADV))
13933 0 : vty_out(vty,
13934 : "advertised");
13935 :
13936 0 : if (CHECK_FLAG(
13937 : p->af_cap[afi]
13938 : [safi],
13939 : PEER_CAP_ADDPATH_AF_TX_RCV))
13940 0 : vty_out(vty,
13941 : "%sreceived",
13942 0 : CHECK_FLAG(
13943 : p->af_cap
13944 : [afi]
13945 : [safi],
13946 : PEER_CAP_ADDPATH_AF_TX_ADV)
13947 : ? " and "
13948 : : "");
13949 :
13950 0 : vty_out(vty, "\n");
13951 : }
13952 :
13953 0 : if (CHECK_FLAG(
13954 : p->af_cap[afi][safi],
13955 0 : PEER_CAP_ADDPATH_AF_RX_ADV) ||
13956 0 : CHECK_FLAG(
13957 : p->af_cap[afi][safi],
13958 : PEER_CAP_ADDPATH_AF_RX_RCV)) {
13959 0 : vty_out(vty, " %s: RX ",
13960 : get_afi_safi_str(
13961 : afi, safi,
13962 : false));
13963 :
13964 0 : if (CHECK_FLAG(
13965 : p->af_cap[afi]
13966 : [safi],
13967 : PEER_CAP_ADDPATH_AF_RX_ADV))
13968 0 : vty_out(vty,
13969 : "advertised");
13970 :
13971 0 : if (CHECK_FLAG(
13972 : p->af_cap[afi]
13973 : [safi],
13974 : PEER_CAP_ADDPATH_AF_RX_RCV))
13975 0 : vty_out(vty,
13976 : "%sreceived",
13977 0 : CHECK_FLAG(
13978 : p->af_cap
13979 : [afi]
13980 : [safi],
13981 : PEER_CAP_ADDPATH_AF_RX_ADV)
13982 : ? " and "
13983 : : "");
13984 :
13985 0 : vty_out(vty, "\n");
13986 : }
13987 : }
13988 : }
13989 :
13990 : /* Dynamic */
13991 0 : if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13992 : CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13993 0 : vty_out(vty, " Dynamic:");
13994 0 : if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13995 0 : vty_out(vty, " advertised");
13996 0 : if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13997 0 : vty_out(vty, " %sreceived",
13998 0 : CHECK_FLAG(p->cap,
13999 : PEER_CAP_DYNAMIC_ADV)
14000 : ? "and "
14001 : : "");
14002 0 : vty_out(vty, "\n");
14003 : }
14004 :
14005 : /* Role */
14006 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
14007 : CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
14008 0 : vty_out(vty, " Role:");
14009 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
14010 0 : vty_out(vty, " advertised");
14011 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
14012 0 : vty_out(vty, " %sreceived",
14013 0 : CHECK_FLAG(p->cap,
14014 : PEER_CAP_ROLE_ADV)
14015 : ? "and "
14016 : : "");
14017 0 : vty_out(vty, "\n");
14018 : }
14019 :
14020 : /* Extended nexthop */
14021 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
14022 : CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
14023 0 : vty_out(vty, " Extended nexthop:");
14024 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
14025 0 : vty_out(vty, " advertised");
14026 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
14027 0 : vty_out(vty, " %sreceived",
14028 0 : CHECK_FLAG(p->cap,
14029 : PEER_CAP_ENHE_ADV)
14030 : ? "and "
14031 : : "");
14032 0 : vty_out(vty, "\n");
14033 :
14034 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
14035 0 : vty_out(vty,
14036 : " Address families by peer:\n ");
14037 0 : for (safi = SAFI_UNICAST;
14038 0 : safi < SAFI_MAX; safi++)
14039 0 : if (CHECK_FLAG(
14040 : p->af_cap[AFI_IP]
14041 : [safi],
14042 : PEER_CAP_ENHE_AF_RCV))
14043 0 : vty_out(vty,
14044 : " %s\n",
14045 : get_afi_safi_str(
14046 : AFI_IP,
14047 : safi,
14048 : false));
14049 : }
14050 : }
14051 :
14052 : /* Long-lived Graceful Restart */
14053 0 : if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
14054 : CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
14055 0 : vty_out(vty,
14056 : " Long-lived Graceful Restart:");
14057 0 : if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
14058 0 : vty_out(vty, " advertised");
14059 0 : if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
14060 0 : vty_out(vty, " %sreceived",
14061 0 : CHECK_FLAG(p->cap,
14062 : PEER_CAP_LLGR_ADV)
14063 : ? "and "
14064 : : "");
14065 0 : vty_out(vty, "\n");
14066 :
14067 0 : if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
14068 0 : vty_out(vty,
14069 : " Address families by peer:\n");
14070 0 : FOREACH_AFI_SAFI (afi, safi)
14071 0 : if (CHECK_FLAG(
14072 : p->af_cap[afi]
14073 : [safi],
14074 : PEER_CAP_LLGR_AF_RCV))
14075 0 : vty_out(vty,
14076 : " %s\n",
14077 : get_afi_safi_str(
14078 : afi,
14079 : safi,
14080 : false));
14081 : }
14082 : }
14083 :
14084 : /* Route Refresh */
14085 0 : if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
14086 0 : CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
14087 : CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
14088 0 : vty_out(vty, " Route refresh:");
14089 0 : if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
14090 0 : vty_out(vty, " advertised");
14091 0 : if (CHECK_FLAG(p->cap,
14092 0 : PEER_CAP_REFRESH_NEW_RCV) ||
14093 : CHECK_FLAG(p->cap,
14094 : PEER_CAP_REFRESH_OLD_RCV))
14095 0 : vty_out(vty, " %sreceived(%s)",
14096 0 : CHECK_FLAG(p->cap,
14097 : PEER_CAP_REFRESH_ADV)
14098 : ? "and "
14099 : : "",
14100 : (CHECK_FLAG(
14101 : p->cap,
14102 : PEER_CAP_REFRESH_OLD_RCV) &&
14103 : CHECK_FLAG(
14104 : p->cap,
14105 : PEER_CAP_REFRESH_NEW_RCV))
14106 : ? "old & new"
14107 0 : : CHECK_FLAG(
14108 : p->cap,
14109 : PEER_CAP_REFRESH_OLD_RCV)
14110 : ? "old"
14111 0 : : "new");
14112 :
14113 0 : vty_out(vty, "\n");
14114 : }
14115 :
14116 : /* Enhanced Route Refresh */
14117 0 : if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
14118 : CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
14119 0 : vty_out(vty, " Enhanced Route Refresh:");
14120 0 : if (CHECK_FLAG(p->cap,
14121 : PEER_CAP_ENHANCED_RR_ADV))
14122 0 : vty_out(vty, " advertised");
14123 0 : if (CHECK_FLAG(p->cap,
14124 : PEER_CAP_ENHANCED_RR_RCV))
14125 0 : vty_out(vty, " %sreceived",
14126 0 : CHECK_FLAG(p->cap,
14127 : PEER_CAP_REFRESH_ADV)
14128 : ? "and "
14129 : : "");
14130 0 : vty_out(vty, "\n");
14131 : }
14132 :
14133 : /* Multiprotocol Extensions */
14134 0 : FOREACH_AFI_SAFI (afi, safi)
14135 0 : if (p->afc_adv[afi][safi] ||
14136 0 : p->afc_recv[afi][safi]) {
14137 0 : vty_out(vty, " Address Family %s:",
14138 : get_afi_safi_str(afi, safi,
14139 : false));
14140 0 : if (p->afc_adv[afi][safi])
14141 0 : vty_out(vty, " advertised");
14142 0 : if (p->afc_recv[afi][safi])
14143 0 : vty_out(vty, " %sreceived",
14144 0 : p->afc_adv[afi][safi]
14145 : ? "and "
14146 : : "");
14147 0 : vty_out(vty, "\n");
14148 : }
14149 :
14150 : /* Hostname capability */
14151 0 : vty_out(vty, " Hostname Capability:");
14152 :
14153 0 : if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
14154 0 : vty_out(vty,
14155 : " advertised (name: %s,domain name: %s)",
14156 0 : bgp->peer_self->hostname
14157 : ? bgp->peer_self->hostname
14158 : : "n/a",
14159 0 : bgp->peer_self->domainname
14160 : ? bgp->peer_self->domainname
14161 : : "n/a");
14162 : } else {
14163 0 : vty_out(vty, " not advertised");
14164 : }
14165 :
14166 0 : if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
14167 0 : vty_out(vty,
14168 : " received (name: %s,domain name: %s)",
14169 0 : p->hostname ? p->hostname : "n/a",
14170 0 : p->domainname ? p->domainname : "n/a");
14171 : } else {
14172 0 : vty_out(vty, " not received");
14173 : }
14174 :
14175 0 : vty_out(vty, "\n");
14176 :
14177 : /* Graceful Restart */
14178 0 : if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
14179 : CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
14180 0 : vty_out(vty,
14181 : " Graceful Restart Capability:");
14182 0 : if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
14183 0 : vty_out(vty, " advertised");
14184 0 : if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
14185 0 : vty_out(vty, " %sreceived",
14186 0 : CHECK_FLAG(p->cap,
14187 : PEER_CAP_RESTART_ADV)
14188 : ? "and "
14189 : : "");
14190 0 : vty_out(vty, "\n");
14191 :
14192 0 : if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14193 0 : int restart_af_count = 0;
14194 :
14195 0 : vty_out(vty,
14196 : " Remote Restart timer is %d seconds\n",
14197 0 : p->v_gr_restart);
14198 0 : vty_out(vty,
14199 : " Address families by peer:\n ");
14200 :
14201 0 : FOREACH_AFI_SAFI (afi, safi)
14202 0 : if (CHECK_FLAG(
14203 : p->af_cap[afi]
14204 : [safi],
14205 : PEER_CAP_RESTART_AF_RCV)) {
14206 0 : vty_out(vty, "%s%s(%s)",
14207 : restart_af_count
14208 : ? ", "
14209 : : "",
14210 : get_afi_safi_str(
14211 : afi,
14212 : safi,
14213 : false),
14214 0 : CHECK_FLAG(
14215 : p->af_cap
14216 : [afi]
14217 : [safi],
14218 : PEER_CAP_RESTART_AF_PRESERVE_RCV)
14219 : ? "preserved"
14220 : : "not preserved");
14221 0 : restart_af_count++;
14222 : }
14223 0 : if (!restart_af_count)
14224 0 : vty_out(vty, "none");
14225 0 : vty_out(vty, "\n");
14226 : }
14227 : } /* Graceful Restart */
14228 : }
14229 : }
14230 :
14231 : /* graceful restart information */
14232 27 : json_object *json_grace = NULL;
14233 27 : json_object *json_grace_send = NULL;
14234 27 : json_object *json_grace_recv = NULL;
14235 27 : int eor_send_af_count = 0;
14236 27 : int eor_receive_af_count = 0;
14237 :
14238 27 : if (use_json) {
14239 27 : json_grace = json_object_new_object();
14240 27 : json_grace_send = json_object_new_object();
14241 27 : json_grace_recv = json_object_new_object();
14242 :
14243 27 : if ((peer_established(p)) &&
14244 12 : CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14245 300 : FOREACH_AFI_SAFI (afi, safi) {
14246 252 : if (CHECK_FLAG(p->af_sflags[afi][safi],
14247 : PEER_STATUS_EOR_SEND)) {
14248 1 : json_object_boolean_true_add(
14249 : json_grace_send,
14250 : get_afi_safi_str(afi, safi,
14251 : true));
14252 1 : eor_send_af_count++;
14253 : }
14254 : }
14255 300 : FOREACH_AFI_SAFI (afi, safi) {
14256 252 : if (CHECK_FLAG(p->af_sflags[afi][safi],
14257 : PEER_STATUS_EOR_RECEIVED)) {
14258 1 : json_object_boolean_true_add(
14259 : json_grace_recv,
14260 : get_afi_safi_str(afi, safi,
14261 : true));
14262 1 : eor_receive_af_count++;
14263 : }
14264 : }
14265 : }
14266 27 : json_object_object_add(json_grace, "endOfRibSend",
14267 : json_grace_send);
14268 27 : json_object_object_add(json_grace, "endOfRibRecv",
14269 : json_grace_recv);
14270 :
14271 :
14272 27 : if (p->t_gr_restart)
14273 0 : json_object_int_add(
14274 : json_grace, "gracefulRestartTimerMsecs",
14275 0 : thread_timer_remain_second(p->t_gr_restart) *
14276 : 1000);
14277 :
14278 27 : if (p->t_gr_stale)
14279 0 : json_object_int_add(
14280 : json_grace, "gracefulStalepathTimerMsecs",
14281 0 : thread_timer_remain_second(p->t_gr_stale) *
14282 : 1000);
14283 : /* more gr info in new format */
14284 27 : BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
14285 27 : json_object_object_add(json_neigh, "gracefulRestartInfo",
14286 : json_grace);
14287 : } else {
14288 0 : vty_out(vty, " Graceful restart information:\n");
14289 0 : if ((peer_established(p)) &&
14290 0 : CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
14291 :
14292 0 : vty_out(vty, " End-of-RIB send: ");
14293 0 : FOREACH_AFI_SAFI (afi, safi) {
14294 0 : if (CHECK_FLAG(p->af_sflags[afi][safi],
14295 : PEER_STATUS_EOR_SEND)) {
14296 0 : vty_out(vty, "%s%s",
14297 : eor_send_af_count ? ", " : "",
14298 : get_afi_safi_str(afi, safi,
14299 : false));
14300 0 : eor_send_af_count++;
14301 : }
14302 : }
14303 0 : vty_out(vty, "\n");
14304 0 : vty_out(vty, " End-of-RIB received: ");
14305 0 : FOREACH_AFI_SAFI (afi, safi) {
14306 0 : if (CHECK_FLAG(p->af_sflags[afi][safi],
14307 : PEER_STATUS_EOR_RECEIVED)) {
14308 0 : vty_out(vty, "%s%s",
14309 : eor_receive_af_count ? ", "
14310 : : "",
14311 : get_afi_safi_str(afi, safi,
14312 : false));
14313 0 : eor_receive_af_count++;
14314 : }
14315 : }
14316 0 : vty_out(vty, "\n");
14317 : }
14318 :
14319 0 : if (p->t_gr_restart)
14320 0 : vty_out(vty,
14321 : " The remaining time of restart timer is %ld\n",
14322 : thread_timer_remain_second(p->t_gr_restart));
14323 :
14324 0 : if (p->t_gr_stale)
14325 0 : vty_out(vty,
14326 : " The remaining time of stalepath timer is %ld\n",
14327 : thread_timer_remain_second(p->t_gr_stale));
14328 :
14329 : /* more gr info in new format */
14330 0 : BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
14331 : }
14332 :
14333 27 : if (use_json) {
14334 27 : json_object *json_stat = NULL;
14335 27 : json_stat = json_object_new_object();
14336 : /* Packet counts. */
14337 :
14338 27 : atomic_size_t outq_count, inq_count;
14339 27 : outq_count = atomic_load_explicit(&p->obuf->count,
14340 : memory_order_relaxed);
14341 27 : inq_count = atomic_load_explicit(&p->ibuf->count,
14342 : memory_order_relaxed);
14343 :
14344 27 : json_object_int_add(json_stat, "depthInq",
14345 27 : (unsigned long)inq_count);
14346 27 : json_object_int_add(json_stat, "depthOutq",
14347 27 : (unsigned long)outq_count);
14348 27 : json_object_int_add(json_stat, "opensSent",
14349 27 : atomic_load_explicit(&p->open_out,
14350 : memory_order_relaxed));
14351 27 : json_object_int_add(json_stat, "opensRecv",
14352 27 : atomic_load_explicit(&p->open_in,
14353 : memory_order_relaxed));
14354 27 : json_object_int_add(json_stat, "notificationsSent",
14355 27 : atomic_load_explicit(&p->notify_out,
14356 : memory_order_relaxed));
14357 27 : json_object_int_add(json_stat, "notificationsRecv",
14358 27 : atomic_load_explicit(&p->notify_in,
14359 : memory_order_relaxed));
14360 27 : json_object_int_add(json_stat, "updatesSent",
14361 27 : atomic_load_explicit(&p->update_out,
14362 : memory_order_relaxed));
14363 27 : json_object_int_add(json_stat, "updatesRecv",
14364 27 : atomic_load_explicit(&p->update_in,
14365 : memory_order_relaxed));
14366 27 : json_object_int_add(json_stat, "keepalivesSent",
14367 27 : atomic_load_explicit(&p->keepalive_out,
14368 : memory_order_relaxed));
14369 27 : json_object_int_add(json_stat, "keepalivesRecv",
14370 27 : atomic_load_explicit(&p->keepalive_in,
14371 : memory_order_relaxed));
14372 27 : json_object_int_add(json_stat, "routeRefreshSent",
14373 27 : atomic_load_explicit(&p->refresh_out,
14374 : memory_order_relaxed));
14375 27 : json_object_int_add(json_stat, "routeRefreshRecv",
14376 27 : atomic_load_explicit(&p->refresh_in,
14377 : memory_order_relaxed));
14378 27 : json_object_int_add(json_stat, "capabilitySent",
14379 27 : atomic_load_explicit(&p->dynamic_cap_out,
14380 : memory_order_relaxed));
14381 27 : json_object_int_add(json_stat, "capabilityRecv",
14382 27 : atomic_load_explicit(&p->dynamic_cap_in,
14383 : memory_order_relaxed));
14384 27 : json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14385 27 : json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
14386 27 : json_object_object_add(json_neigh, "messageStats", json_stat);
14387 : } else {
14388 0 : atomic_size_t outq_count, inq_count, open_out, open_in,
14389 : notify_out, notify_in, update_out, update_in,
14390 : keepalive_out, keepalive_in, refresh_out, refresh_in,
14391 : dynamic_cap_out, dynamic_cap_in;
14392 0 : outq_count = atomic_load_explicit(&p->obuf->count,
14393 : memory_order_relaxed);
14394 0 : inq_count = atomic_load_explicit(&p->ibuf->count,
14395 : memory_order_relaxed);
14396 0 : open_out = atomic_load_explicit(&p->open_out,
14397 : memory_order_relaxed);
14398 0 : open_in =
14399 0 : atomic_load_explicit(&p->open_in, memory_order_relaxed);
14400 0 : notify_out = atomic_load_explicit(&p->notify_out,
14401 : memory_order_relaxed);
14402 0 : notify_in = atomic_load_explicit(&p->notify_in,
14403 : memory_order_relaxed);
14404 0 : update_out = atomic_load_explicit(&p->update_out,
14405 : memory_order_relaxed);
14406 0 : update_in = atomic_load_explicit(&p->update_in,
14407 : memory_order_relaxed);
14408 0 : keepalive_out = atomic_load_explicit(&p->keepalive_out,
14409 : memory_order_relaxed);
14410 0 : keepalive_in = atomic_load_explicit(&p->keepalive_in,
14411 : memory_order_relaxed);
14412 0 : refresh_out = atomic_load_explicit(&p->refresh_out,
14413 : memory_order_relaxed);
14414 0 : refresh_in = atomic_load_explicit(&p->refresh_in,
14415 : memory_order_relaxed);
14416 0 : dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14417 : memory_order_relaxed);
14418 0 : dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14419 : memory_order_relaxed);
14420 :
14421 : /* Packet counts. */
14422 0 : vty_out(vty, " Message statistics:\n");
14423 0 : vty_out(vty, " Inq depth is %zu\n", inq_count);
14424 0 : vty_out(vty, " Outq depth is %zu\n", outq_count);
14425 0 : vty_out(vty, " Sent Rcvd\n");
14426 0 : vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14427 0 : open_in);
14428 0 : vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14429 0 : notify_in);
14430 0 : vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14431 0 : update_in);
14432 0 : vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14433 0 : keepalive_in);
14434 0 : vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14435 0 : refresh_in);
14436 0 : vty_out(vty, " Capability: %10zu %10zu\n",
14437 0 : dynamic_cap_out, dynamic_cap_in);
14438 0 : vty_out(vty, " Total: %10u %10u\n",
14439 0 : (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
14440 : }
14441 :
14442 27 : if (use_json) {
14443 : /* advertisement-interval */
14444 27 : json_object_int_add(json_neigh,
14445 : "minBtwnAdvertisementRunsTimerMsecs",
14446 27 : p->v_routeadv * 1000);
14447 :
14448 : /* Update-source. */
14449 27 : if (p->update_if || p->update_source) {
14450 0 : if (p->update_if)
14451 0 : json_object_string_add(json_neigh,
14452 : "updateSource",
14453 : p->update_if);
14454 0 : else if (p->update_source)
14455 0 : json_object_string_addf(json_neigh,
14456 : "updateSource", "%pSU",
14457 : p->update_source);
14458 : }
14459 : } else {
14460 : /* advertisement-interval */
14461 0 : vty_out(vty,
14462 : " Minimum time between advertisement runs is %d seconds\n",
14463 0 : p->v_routeadv);
14464 :
14465 : /* Update-source. */
14466 0 : if (p->update_if || p->update_source) {
14467 0 : vty_out(vty, " Update source is ");
14468 0 : if (p->update_if)
14469 0 : vty_out(vty, "%s", p->update_if);
14470 0 : else if (p->update_source)
14471 0 : vty_out(vty, "%pSU", p->update_source);
14472 0 : vty_out(vty, "\n");
14473 : }
14474 :
14475 0 : vty_out(vty, "\n");
14476 : }
14477 :
14478 : /* Address Family Information */
14479 27 : json_object *json_hold = NULL;
14480 :
14481 27 : if (use_json)
14482 27 : json_hold = json_object_new_object();
14483 :
14484 675 : FOREACH_AFI_SAFI (afi, safi)
14485 567 : if (p->afc[afi][safi])
14486 27 : bgp_show_peer_afi(vty, p, afi, safi, use_json,
14487 : json_hold);
14488 :
14489 27 : if (use_json) {
14490 27 : json_object_object_add(json_neigh, "addressFamilyInfo",
14491 : json_hold);
14492 27 : json_object_int_add(json_neigh, "connectionsEstablished",
14493 27 : p->established);
14494 27 : json_object_int_add(json_neigh, "connectionsDropped",
14495 27 : p->dropped);
14496 : } else
14497 0 : vty_out(vty, " Connections established %d; dropped %d\n",
14498 : p->established, p->dropped);
14499 :
14500 27 : if (!p->last_reset) {
14501 0 : if (use_json)
14502 0 : json_object_string_add(json_neigh, "lastReset",
14503 : "never");
14504 : else
14505 0 : vty_out(vty, " Last reset never\n");
14506 : } else {
14507 27 : if (use_json) {
14508 27 : time_t uptime;
14509 27 : struct tm tm;
14510 :
14511 27 : uptime = monotime(NULL);
14512 27 : uptime -= p->resettime;
14513 27 : gmtime_r(&uptime, &tm);
14514 :
14515 27 : json_object_int_add(json_neigh, "lastResetTimerMsecs",
14516 27 : (tm.tm_sec * 1000)
14517 27 : + (tm.tm_min * 60000)
14518 27 : + (tm.tm_hour * 3600000));
14519 27 : bgp_show_peer_reset(NULL, p, json_neigh, true);
14520 : } else {
14521 0 : vty_out(vty, " Last reset %s, ",
14522 : peer_uptime(p->resettime, timebuf,
14523 : BGP_UPTIME_LEN, 0, NULL));
14524 :
14525 0 : bgp_show_peer_reset(vty, p, NULL, false);
14526 0 : if (p->last_reset_cause_size) {
14527 0 : msg = p->last_reset_cause;
14528 0 : vty_out(vty,
14529 : " Message received that caused BGP to send a NOTIFICATION:\n ");
14530 0 : for (i = 1; i <= p->last_reset_cause_size;
14531 0 : i++) {
14532 0 : vty_out(vty, "%02X", *msg++);
14533 :
14534 0 : if (i != p->last_reset_cause_size) {
14535 0 : if (i % 16 == 0) {
14536 0 : vty_out(vty, "\n ");
14537 0 : } else if (i % 4 == 0) {
14538 0 : vty_out(vty, " ");
14539 : }
14540 : }
14541 : }
14542 0 : vty_out(vty, "\n");
14543 : }
14544 : }
14545 : }
14546 :
14547 27 : if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14548 0 : if (use_json)
14549 0 : json_object_boolean_true_add(json_neigh,
14550 : "prefixesConfigExceedMax");
14551 : else
14552 0 : vty_out(vty,
14553 : " Peer had exceeded the max. no. of prefixes configured.\n");
14554 :
14555 0 : if (p->t_pmax_restart) {
14556 0 : if (use_json) {
14557 0 : json_object_boolean_true_add(
14558 : json_neigh, "reducePrefixNumFrom");
14559 0 : json_object_int_add(json_neigh,
14560 : "restartInTimerMsec",
14561 0 : thread_timer_remain_second(
14562 : p->t_pmax_restart)
14563 0 : * 1000);
14564 : } else
14565 0 : vty_out(vty,
14566 : " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14567 : p->host, thread_timer_remain_second(
14568 : p->t_pmax_restart));
14569 : } else {
14570 0 : if (use_json)
14571 0 : json_object_boolean_true_add(
14572 : json_neigh,
14573 : "reducePrefixNumAndClearIpBgp");
14574 : else
14575 0 : vty_out(vty,
14576 : " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14577 : p->host);
14578 : }
14579 : }
14580 :
14581 : /* EBGP Multihop and GTSM */
14582 27 : if (p->sort != BGP_PEER_IBGP) {
14583 27 : if (use_json) {
14584 27 : if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14585 0 : json_object_int_add(json_neigh,
14586 : "externalBgpNbrMaxHopsAway",
14587 : p->gtsm_hops);
14588 : else
14589 27 : json_object_int_add(json_neigh,
14590 : "externalBgpNbrMaxHopsAway",
14591 27 : p->ttl);
14592 : } else {
14593 0 : if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14594 0 : vty_out(vty,
14595 : " External BGP neighbor may be up to %d hops away.\n",
14596 : p->gtsm_hops);
14597 : else
14598 0 : vty_out(vty,
14599 : " External BGP neighbor may be up to %d hops away.\n",
14600 : p->ttl);
14601 : }
14602 : } else {
14603 0 : if (use_json) {
14604 0 : if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14605 0 : json_object_int_add(json_neigh,
14606 : "internalBgpNbrMaxHopsAway",
14607 : p->gtsm_hops);
14608 : else
14609 0 : json_object_int_add(json_neigh,
14610 : "internalBgpNbrMaxHopsAway",
14611 0 : p->ttl);
14612 : } else {
14613 0 : if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14614 0 : vty_out(vty,
14615 : " Internal BGP neighbor may be up to %d hops away.\n",
14616 : p->gtsm_hops);
14617 : else
14618 0 : vty_out(vty,
14619 : " Internal BGP neighbor may be up to %d hops away.\n",
14620 : p->ttl);
14621 : }
14622 : }
14623 :
14624 : /* Local address. */
14625 27 : if (p->su_local) {
14626 12 : if (use_json) {
14627 12 : json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14628 : p->su_local);
14629 12 : json_object_int_add(json_neigh, "portLocal",
14630 12 : ntohs(p->su_local->sin.sin_port));
14631 : } else
14632 0 : vty_out(vty, "Local host: %pSU, Local port: %d\n",
14633 0 : p->su_local, ntohs(p->su_local->sin.sin_port));
14634 : } else {
14635 15 : if (use_json) {
14636 15 : json_object_string_add(json_neigh, "hostLocal",
14637 : "Unknown");
14638 15 : json_object_int_add(json_neigh, "portLocal", -1);
14639 : }
14640 : }
14641 :
14642 : /* Remote address. */
14643 27 : if (p->su_remote) {
14644 12 : if (use_json) {
14645 12 : json_object_string_addf(json_neigh, "hostForeign",
14646 : "%pSU", p->su_remote);
14647 12 : json_object_int_add(json_neigh, "portForeign",
14648 12 : ntohs(p->su_remote->sin.sin_port));
14649 : } else
14650 0 : vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14651 : p->su_remote,
14652 0 : ntohs(p->su_remote->sin.sin_port));
14653 : } else {
14654 15 : if (use_json) {
14655 15 : json_object_string_add(json_neigh, "hostForeign",
14656 : "Unknown");
14657 15 : json_object_int_add(json_neigh, "portForeign", -1);
14658 : }
14659 : }
14660 :
14661 : /* Nexthop display. */
14662 27 : if (p->su_local) {
14663 12 : if (use_json) {
14664 12 : json_object_string_addf(json_neigh, "nexthop", "%pI4",
14665 : &p->nexthop.v4);
14666 12 : json_object_string_addf(json_neigh, "nexthopGlobal",
14667 : "%pI6", &p->nexthop.v6_global);
14668 12 : json_object_string_addf(json_neigh, "nexthopLocal",
14669 : "%pI6", &p->nexthop.v6_local);
14670 12 : if (p->shared_network)
14671 12 : json_object_string_add(json_neigh,
14672 : "bgpConnection",
14673 : "sharedNetwork");
14674 : else
14675 0 : json_object_string_add(json_neigh,
14676 : "bgpConnection",
14677 : "nonSharedNetwork");
14678 : } else {
14679 0 : vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
14680 0 : vty_out(vty, "Nexthop global: %pI6\n",
14681 : &p->nexthop.v6_global);
14682 0 : vty_out(vty, "Nexthop local: %pI6\n",
14683 : &p->nexthop.v6_local);
14684 0 : vty_out(vty, "BGP connection: %s\n",
14685 0 : p->shared_network ? "shared network"
14686 : : "non shared network");
14687 : }
14688 : } else {
14689 15 : if (use_json) {
14690 15 : json_object_string_add(json_neigh, "nexthop",
14691 : "Unknown");
14692 15 : json_object_string_add(json_neigh, "nexthopGlobal",
14693 : "Unknown");
14694 15 : json_object_string_add(json_neigh, "nexthopLocal",
14695 : "Unknown");
14696 15 : json_object_string_add(json_neigh, "bgpConnection",
14697 : "Unknown");
14698 : }
14699 : }
14700 :
14701 : /* Timer information. */
14702 27 : if (use_json) {
14703 27 : json_object_int_add(json_neigh, "connectRetryTimer",
14704 27 : p->v_connect);
14705 27 : if (peer_established(p)) {
14706 12 : json_object_int_add(json_neigh, "estimatedRttInMsecs",
14707 12 : p->rtt);
14708 12 : if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) {
14709 0 : json_object_int_add(json_neigh,
14710 : "shutdownRttInMsecs",
14711 0 : p->rtt_expected);
14712 0 : json_object_int_add(json_neigh,
14713 : "shutdownRttAfterCount",
14714 0 : p->rtt_keepalive_rcv);
14715 : }
14716 : }
14717 27 : if (p->t_start)
14718 10 : json_object_int_add(
14719 : json_neigh, "nextStartTimerDueInMsecs",
14720 5 : thread_timer_remain_second(p->t_start) * 1000);
14721 27 : if (p->t_connect)
14722 20 : json_object_int_add(
14723 : json_neigh, "nextConnectTimerDueInMsecs",
14724 10 : thread_timer_remain_second(p->t_connect)
14725 10 : * 1000);
14726 27 : if (p->t_routeadv) {
14727 0 : json_object_int_add(json_neigh, "mraiInterval",
14728 0 : p->v_routeadv);
14729 0 : json_object_int_add(
14730 : json_neigh, "mraiTimerExpireInMsecs",
14731 0 : thread_timer_remain_second(p->t_routeadv)
14732 0 : * 1000);
14733 : }
14734 27 : if (p->password)
14735 0 : json_object_int_add(json_neigh, "authenticationEnabled",
14736 : 1);
14737 :
14738 27 : if (p->t_read)
14739 12 : json_object_string_add(json_neigh, "readThread", "on");
14740 : else
14741 15 : json_object_string_add(json_neigh, "readThread", "off");
14742 :
14743 27 : if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14744 12 : json_object_string_add(json_neigh, "writeThread", "on");
14745 : else
14746 15 : json_object_string_add(json_neigh, "writeThread",
14747 : "off");
14748 : } else {
14749 0 : vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14750 0 : p->v_connect);
14751 0 : if (peer_established(p)) {
14752 0 : vty_out(vty, "Estimated round trip time: %d ms\n",
14753 : p->rtt);
14754 0 : if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN))
14755 0 : vty_out(vty,
14756 : "Shutdown when RTT > %dms, count > %u\n",
14757 0 : p->rtt_expected, p->rtt_keepalive_rcv);
14758 : }
14759 0 : if (p->t_start)
14760 0 : vty_out(vty, "Next start timer due in %ld seconds\n",
14761 : thread_timer_remain_second(p->t_start));
14762 0 : if (p->t_connect)
14763 0 : vty_out(vty, "Next connect timer due in %ld seconds\n",
14764 : thread_timer_remain_second(p->t_connect));
14765 0 : if (p->t_routeadv)
14766 0 : vty_out(vty,
14767 : "MRAI (interval %u) timer expires in %ld seconds\n",
14768 0 : p->v_routeadv,
14769 : thread_timer_remain_second(p->t_routeadv));
14770 0 : if (p->password)
14771 0 : vty_out(vty, "Peer Authentication Enabled\n");
14772 :
14773 0 : vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14774 0 : p->t_read ? "on" : "off",
14775 0 : CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14776 : ? "on"
14777 : : "off", p->fd);
14778 : }
14779 :
14780 27 : if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14781 27 : && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14782 0 : bgp_capability_vty_out(vty, p, use_json, json_neigh);
14783 :
14784 27 : if (!use_json)
14785 0 : vty_out(vty, "\n");
14786 :
14787 : /* BFD information. */
14788 27 : if (p->bfd_config)
14789 0 : bgp_bfd_show_info(vty, p, json_neigh);
14790 :
14791 27 : if (use_json) {
14792 27 : if (p->conf_if) /* Configured interface name. */
14793 0 : json_object_object_add(json, p->conf_if, json_neigh);
14794 : else /* Configured IP address. */
14795 27 : json_object_object_add(json, p->host, json_neigh);
14796 : }
14797 27 : }
14798 :
14799 0 : static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14800 : enum show_type type,
14801 : union sockunion *su,
14802 : const char *conf_if, afi_t afi,
14803 : json_object *json)
14804 : {
14805 0 : struct listnode *node, *nnode;
14806 0 : struct peer *peer;
14807 0 : bool found = false;
14808 0 : safi_t safi = SAFI_UNICAST;
14809 0 : json_object *json_neighbor = NULL;
14810 :
14811 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14812 :
14813 0 : if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14814 0 : continue;
14815 :
14816 0 : if ((peer->afc[afi][safi]) == 0)
14817 0 : continue;
14818 :
14819 0 : if (json)
14820 0 : json_neighbor = json_object_new_object();
14821 :
14822 0 : if (type == show_all) {
14823 0 : bgp_show_peer_gr_status(vty, peer, json_neighbor);
14824 :
14825 0 : if (json)
14826 0 : json_object_object_add(json, peer->host,
14827 : json_neighbor);
14828 :
14829 0 : } else if (type == show_peer) {
14830 0 : if (conf_if) {
14831 0 : if ((peer->conf_if
14832 0 : && !strcmp(peer->conf_if, conf_if))
14833 0 : || (peer->hostname
14834 0 : && !strcmp(peer->hostname, conf_if))) {
14835 0 : found = true;
14836 0 : bgp_show_peer_gr_status(vty, peer,
14837 : json_neighbor);
14838 : }
14839 : } else {
14840 0 : if (sockunion_same(&peer->su, su)) {
14841 0 : found = true;
14842 0 : bgp_show_peer_gr_status(vty, peer,
14843 : json_neighbor);
14844 : }
14845 : }
14846 0 : if (json) {
14847 0 : if (found)
14848 0 : json_object_object_add(json, peer->host,
14849 : json_neighbor);
14850 : else
14851 0 : json_object_free(json_neighbor);
14852 : }
14853 : }
14854 :
14855 0 : if (found)
14856 : break;
14857 : }
14858 :
14859 0 : if (type == show_peer && !found) {
14860 0 : if (json)
14861 0 : json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14862 : else
14863 0 : vty_out(vty, "%% No such neighbor\n");
14864 : }
14865 :
14866 0 : if (!json)
14867 0 : vty_out(vty, "\n");
14868 :
14869 0 : return CMD_SUCCESS;
14870 : }
14871 :
14872 27 : static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14873 : enum show_type type, union sockunion *su,
14874 : const char *conf_if, bool use_json,
14875 : json_object *json)
14876 : {
14877 27 : struct listnode *node, *nnode;
14878 27 : struct peer *peer;
14879 27 : int find = 0;
14880 27 : bool nbr_output = false;
14881 27 : afi_t afi = AFI_MAX;
14882 27 : safi_t safi = SAFI_MAX;
14883 :
14884 27 : if (type == show_ipv4_peer || type == show_ipv4_all) {
14885 : afi = AFI_IP;
14886 27 : } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14887 0 : afi = AFI_IP6;
14888 : }
14889 :
14890 81 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14891 27 : if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14892 0 : continue;
14893 :
14894 27 : switch (type) {
14895 0 : case show_all:
14896 0 : bgp_show_peer(vty, peer, use_json, json);
14897 0 : nbr_output = true;
14898 0 : break;
14899 27 : case show_peer:
14900 27 : if (conf_if) {
14901 0 : if ((peer->conf_if
14902 0 : && !strcmp(peer->conf_if, conf_if))
14903 0 : || (peer->hostname
14904 0 : && !strcmp(peer->hostname, conf_if))) {
14905 0 : find = 1;
14906 0 : bgp_show_peer(vty, peer, use_json,
14907 : json);
14908 : }
14909 : } else {
14910 27 : if (sockunion_same(&peer->su, su)) {
14911 27 : find = 1;
14912 27 : bgp_show_peer(vty, peer, use_json,
14913 : json);
14914 : }
14915 : }
14916 : break;
14917 : case show_ipv4_peer:
14918 : case show_ipv6_peer:
14919 0 : FOREACH_SAFI (safi) {
14920 0 : if (peer->afc[afi][safi]) {
14921 0 : if (conf_if) {
14922 0 : if ((peer->conf_if
14923 0 : && !strcmp(peer->conf_if, conf_if))
14924 0 : || (peer->hostname
14925 0 : && !strcmp(peer->hostname, conf_if))) {
14926 0 : find = 1;
14927 0 : bgp_show_peer(vty, peer, use_json,
14928 : json);
14929 0 : break;
14930 : }
14931 : } else {
14932 0 : if (sockunion_same(&peer->su, su)) {
14933 0 : find = 1;
14934 0 : bgp_show_peer(vty, peer, use_json,
14935 : json);
14936 0 : break;
14937 : }
14938 : }
14939 : }
14940 : }
14941 : break;
14942 : case show_ipv4_all:
14943 : case show_ipv6_all:
14944 0 : FOREACH_SAFI (safi) {
14945 0 : if (peer->afc[afi][safi]) {
14946 0 : bgp_show_peer(vty, peer, use_json, json);
14947 0 : nbr_output = true;
14948 0 : break;
14949 : }
14950 : }
14951 : break;
14952 : }
14953 : }
14954 :
14955 27 : if ((type == show_peer || type == show_ipv4_peer ||
14956 27 : type == show_ipv6_peer) && !find) {
14957 0 : if (use_json)
14958 0 : json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14959 : else
14960 0 : vty_out(vty, "%% No such neighbor in this view/vrf\n");
14961 : }
14962 :
14963 27 : if (type != show_peer && type != show_ipv4_peer &&
14964 0 : type != show_ipv6_peer && !nbr_output && !use_json)
14965 0 : vty_out(vty, "%% No BGP neighbors found\n");
14966 :
14967 27 : if (use_json) {
14968 27 : vty_out(vty, "%s\n", json_object_to_json_string_ext(
14969 : json, JSON_C_TO_STRING_PRETTY));
14970 : } else {
14971 0 : vty_out(vty, "\n");
14972 : }
14973 :
14974 27 : return CMD_SUCCESS;
14975 : }
14976 :
14977 0 : static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14978 : enum show_type type,
14979 : const char *ip_str,
14980 : afi_t afi, json_object *json)
14981 : {
14982 :
14983 0 : int ret;
14984 0 : struct bgp *bgp;
14985 0 : union sockunion su;
14986 :
14987 0 : bgp = bgp_get_default();
14988 :
14989 0 : if (!bgp)
14990 0 : return;
14991 :
14992 0 : if (!json)
14993 0 : bgp_show_global_graceful_restart_mode_vty(vty, bgp);
14994 :
14995 0 : if (ip_str) {
14996 0 : ret = str2sockunion(ip_str, &su);
14997 0 : if (ret < 0)
14998 0 : bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
14999 : ip_str, afi, json);
15000 : else
15001 0 : bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
15002 : NULL, afi, json);
15003 : } else
15004 0 : bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
15005 : afi, json);
15006 : }
15007 :
15008 0 : static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
15009 : enum show_type type,
15010 : const char *ip_str,
15011 : bool use_json)
15012 : {
15013 0 : struct listnode *node, *nnode;
15014 0 : struct bgp *bgp;
15015 0 : union sockunion su;
15016 0 : json_object *json = NULL;
15017 0 : int ret, is_first = 1;
15018 0 : bool nbr_output = false;
15019 :
15020 0 : if (use_json)
15021 0 : vty_out(vty, "{\n");
15022 :
15023 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15024 0 : nbr_output = true;
15025 0 : if (use_json) {
15026 0 : if (!(json = json_object_new_object())) {
15027 0 : flog_err(
15028 : EC_BGP_JSON_MEM_ERROR,
15029 : "Unable to allocate memory for JSON object");
15030 0 : vty_out(vty,
15031 : "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
15032 0 : return;
15033 : }
15034 :
15035 0 : json_object_int_add(json, "vrfId",
15036 0 : (bgp->vrf_id == VRF_UNKNOWN)
15037 : ? -1
15038 : : (int64_t)bgp->vrf_id);
15039 0 : json_object_string_add(
15040 : json, "vrfName",
15041 0 : (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15042 0 : ? VRF_DEFAULT_NAME
15043 : : bgp->name);
15044 :
15045 0 : if (!is_first)
15046 0 : vty_out(vty, ",\n");
15047 : else
15048 : is_first = 0;
15049 :
15050 0 : vty_out(vty, "\"%s\":",
15051 0 : (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15052 0 : ? VRF_DEFAULT_NAME
15053 : : bgp->name);
15054 : } else {
15055 0 : vty_out(vty, "\nInstance %s:\n",
15056 0 : (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15057 0 : ? VRF_DEFAULT_NAME
15058 : : bgp->name);
15059 : }
15060 :
15061 0 : if (type == show_peer || type == show_ipv4_peer ||
15062 : type == show_ipv6_peer) {
15063 0 : ret = str2sockunion(ip_str, &su);
15064 0 : if (ret < 0)
15065 0 : bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15066 : use_json, json);
15067 : else
15068 0 : bgp_show_neighbor(vty, bgp, type, &su, NULL,
15069 : use_json, json);
15070 : } else {
15071 0 : bgp_show_neighbor(vty, bgp, type, NULL, NULL,
15072 : use_json, json);
15073 : }
15074 0 : json_object_free(json);
15075 0 : json = NULL;
15076 : }
15077 :
15078 0 : if (use_json)
15079 0 : vty_out(vty, "}\n");
15080 0 : else if (!nbr_output)
15081 0 : vty_out(vty, "%% BGP instance not found\n");
15082 : }
15083 :
15084 27 : static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
15085 : enum show_type type, const char *ip_str,
15086 : bool use_json)
15087 : {
15088 27 : int ret;
15089 27 : struct bgp *bgp;
15090 27 : union sockunion su;
15091 27 : json_object *json = NULL;
15092 :
15093 27 : if (name) {
15094 0 : if (strmatch(name, "all")) {
15095 0 : bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
15096 : use_json);
15097 0 : return CMD_SUCCESS;
15098 : } else {
15099 0 : bgp = bgp_lookup_by_name(name);
15100 0 : if (!bgp) {
15101 0 : if (use_json) {
15102 0 : json = json_object_new_object();
15103 0 : vty_json(vty, json);
15104 : } else
15105 0 : vty_out(vty,
15106 : "%% BGP instance not found\n");
15107 :
15108 0 : return CMD_WARNING;
15109 : }
15110 : }
15111 : } else {
15112 27 : bgp = bgp_get_default();
15113 : }
15114 :
15115 27 : if (bgp) {
15116 27 : json = json_object_new_object();
15117 27 : if (ip_str) {
15118 27 : ret = str2sockunion(ip_str, &su);
15119 27 : if (ret < 0)
15120 0 : bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
15121 : use_json, json);
15122 : else
15123 27 : bgp_show_neighbor(vty, bgp, type, &su, NULL,
15124 : use_json, json);
15125 : } else {
15126 0 : bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15127 : json);
15128 : }
15129 27 : json_object_free(json);
15130 : } else {
15131 0 : if (use_json)
15132 0 : vty_out(vty, "{}\n");
15133 : else
15134 0 : vty_out(vty, "%% BGP instance not found\n");
15135 : }
15136 :
15137 : return CMD_SUCCESS;
15138 : }
15139 :
15140 :
15141 :
15142 : /* "show [ip] bgp neighbors graceful-restart" commands. */
15143 0 : DEFUN (show_ip_bgp_neighbors_graceful_restart,
15144 : show_ip_bgp_neighbors_graceful_restart_cmd,
15145 : "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15146 : SHOW_STR
15147 : BGP_STR
15148 : IP_STR
15149 : IPV6_STR
15150 : NEIGHBOR_STR
15151 : "Neighbor to display information about\n"
15152 : "Neighbor to display information about\n"
15153 : "Neighbor on BGP configured interface\n"
15154 : GR_SHOW
15155 : JSON_STR)
15156 : {
15157 0 : char *sh_arg = NULL;
15158 0 : enum show_type sh_type;
15159 0 : int idx = 0;
15160 0 : afi_t afi = AFI_MAX;
15161 0 : bool uj = use_json(argc, argv);
15162 :
15163 0 : if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
15164 0 : afi = AFI_MAX;
15165 :
15166 0 : idx++;
15167 :
15168 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)
15169 0 : || argv_find(argv, argc, "X:X::X:X", &idx)
15170 0 : || argv_find(argv, argc, "WORD", &idx)) {
15171 0 : sh_type = show_peer;
15172 0 : sh_arg = argv[idx]->arg;
15173 : } else
15174 : sh_type = show_all;
15175 :
15176 0 : if (!argv_find(argv, argc, "graceful-restart", &idx))
15177 : return CMD_SUCCESS;
15178 :
15179 :
15180 0 : return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15181 : afi, uj);
15182 : }
15183 :
15184 : /* "show [ip] bgp neighbors" commands. */
15185 27 : DEFUN (show_ip_bgp_neighbors,
15186 : show_ip_bgp_neighbors_cmd,
15187 : "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
15188 : SHOW_STR
15189 : IP_STR
15190 : BGP_STR
15191 : BGP_INSTANCE_HELP_STR
15192 : BGP_AF_STR
15193 : BGP_AF_STR
15194 : "Detailed information on TCP and BGP neighbor connections\n"
15195 : "Neighbor to display information about\n"
15196 : "Neighbor to display information about\n"
15197 : "Neighbor on BGP configured interface\n"
15198 : JSON_STR)
15199 : {
15200 27 : char *vrf = NULL;
15201 27 : char *sh_arg = NULL;
15202 27 : enum show_type sh_type;
15203 27 : afi_t afi = AFI_MAX;
15204 :
15205 27 : bool uj = use_json(argc, argv);
15206 :
15207 27 : int idx = 0;
15208 :
15209 : /* [<vrf> VIEWVRFNAME] */
15210 27 : if (argv_find(argv, argc, "vrf", &idx)) {
15211 0 : vrf = argv[idx + 1]->arg;
15212 0 : if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15213 27 : vrf = NULL;
15214 27 : } else if (argv_find(argv, argc, "view", &idx))
15215 : /* [<view> VIEWVRFNAME] */
15216 0 : vrf = argv[idx + 1]->arg;
15217 :
15218 27 : idx++;
15219 :
15220 27 : if (argv_find(argv, argc, "ipv4", &idx)) {
15221 : sh_type = show_ipv4_all;
15222 : afi = AFI_IP;
15223 27 : } else if (argv_find(argv, argc, "ipv6", &idx)) {
15224 : sh_type = show_ipv6_all;
15225 : afi = AFI_IP6;
15226 : } else {
15227 27 : sh_type = show_all;
15228 : }
15229 :
15230 27 : if (argv_find(argv, argc, "A.B.C.D", &idx)
15231 0 : || argv_find(argv, argc, "X:X::X:X", &idx)
15232 0 : || argv_find(argv, argc, "WORD", &idx)) {
15233 27 : sh_type = show_peer;
15234 27 : sh_arg = argv[idx]->arg;
15235 : }
15236 :
15237 27 : if (sh_type == show_peer && afi == AFI_IP) {
15238 : sh_type = show_ipv4_peer;
15239 27 : } else if (sh_type == show_peer && afi == AFI_IP6) {
15240 0 : sh_type = show_ipv6_peer;
15241 : }
15242 :
15243 27 : return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
15244 : }
15245 :
15246 : /* Show BGP's AS paths internal data. There are both `show [ip] bgp
15247 : paths' and `show ip mbgp paths'. Those functions results are the
15248 : same.*/
15249 0 : DEFUN (show_ip_bgp_paths,
15250 : show_ip_bgp_paths_cmd,
15251 : "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
15252 : SHOW_STR
15253 : IP_STR
15254 : BGP_STR
15255 : BGP_SAFI_HELP_STR
15256 : "Path information\n")
15257 : {
15258 0 : vty_out(vty, "Address Refcnt Path\n");
15259 0 : aspath_print_all_vty(vty);
15260 0 : return CMD_SUCCESS;
15261 : }
15262 :
15263 : #include "hash.h"
15264 :
15265 0 : static void community_show_all_iterator(struct hash_bucket *bucket,
15266 : struct vty *vty)
15267 : {
15268 0 : struct community *com;
15269 :
15270 0 : com = (struct community *)bucket->data;
15271 0 : vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
15272 : community_str(com, false, false));
15273 0 : }
15274 :
15275 : /* Show BGP's community internal data. */
15276 0 : DEFUN (show_ip_bgp_community_info,
15277 : show_ip_bgp_community_info_cmd,
15278 : "show [ip] bgp community-info",
15279 : SHOW_STR
15280 : IP_STR
15281 : BGP_STR
15282 : "List all bgp community information\n")
15283 : {
15284 0 : vty_out(vty, "Address Refcnt Community\n");
15285 :
15286 0 : hash_iterate(community_hash(),
15287 : (void (*)(struct hash_bucket *,
15288 : void *))community_show_all_iterator,
15289 : vty);
15290 :
15291 0 : return CMD_SUCCESS;
15292 : }
15293 :
15294 0 : static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
15295 : struct vty *vty)
15296 : {
15297 0 : struct lcommunity *lcom;
15298 :
15299 0 : lcom = (struct lcommunity *)bucket->data;
15300 0 : vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
15301 : lcommunity_str(lcom, false, false));
15302 0 : }
15303 :
15304 : /* Show BGP's community internal data. */
15305 0 : DEFUN (show_ip_bgp_lcommunity_info,
15306 : show_ip_bgp_lcommunity_info_cmd,
15307 : "show ip bgp large-community-info",
15308 : SHOW_STR
15309 : IP_STR
15310 : BGP_STR
15311 : "List all bgp large-community information\n")
15312 : {
15313 0 : vty_out(vty, "Address Refcnt Large-community\n");
15314 :
15315 0 : hash_iterate(lcommunity_hash(),
15316 : (void (*)(struct hash_bucket *,
15317 : void *))lcommunity_show_all_iterator,
15318 : vty);
15319 :
15320 0 : return CMD_SUCCESS;
15321 : }
15322 : /* Graceful Restart */
15323 :
15324 0 : static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
15325 : struct bgp *bgp)
15326 : {
15327 :
15328 :
15329 0 : vty_out(vty, "\n%s", SHOW_GR_HEADER);
15330 :
15331 0 : enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
15332 :
15333 0 : switch (bgp_global_gr_mode) {
15334 :
15335 0 : case GLOBAL_HELPER:
15336 0 : vty_out(vty, "Global BGP GR Mode : Helper\n");
15337 0 : break;
15338 :
15339 0 : case GLOBAL_GR:
15340 0 : vty_out(vty, "Global BGP GR Mode : Restart\n");
15341 0 : break;
15342 :
15343 0 : case GLOBAL_DISABLE:
15344 0 : vty_out(vty, "Global BGP GR Mode : Disable\n");
15345 0 : break;
15346 :
15347 0 : case GLOBAL_INVALID:
15348 0 : vty_out(vty,
15349 : "Global BGP GR Mode Invalid\n");
15350 0 : break;
15351 : }
15352 0 : vty_out(vty, "\n");
15353 0 : }
15354 :
15355 0 : static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15356 : enum show_type type,
15357 : const char *ip_str,
15358 : afi_t afi, bool use_json)
15359 : {
15360 0 : json_object *json = NULL;
15361 :
15362 0 : if (use_json)
15363 0 : json = json_object_new_object();
15364 :
15365 0 : if ((afi == AFI_MAX) && (ip_str == NULL)) {
15366 : afi = AFI_IP;
15367 :
15368 0 : while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15369 :
15370 0 : bgp_show_neighbor_graceful_restart_vty(
15371 : vty, type, ip_str, afi, json);
15372 0 : afi++;
15373 : }
15374 0 : } else if (afi != AFI_MAX) {
15375 0 : bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15376 : json);
15377 : } else {
15378 0 : if (json)
15379 0 : json_object_free(json);
15380 0 : return CMD_ERR_INCOMPLETE;
15381 : }
15382 :
15383 0 : if (json)
15384 0 : vty_json(vty, json);
15385 :
15386 : return CMD_SUCCESS;
15387 : }
15388 : /* Graceful Restart */
15389 :
15390 0 : DEFUN (show_ip_bgp_attr_info,
15391 : show_ip_bgp_attr_info_cmd,
15392 : "show [ip] bgp attribute-info",
15393 : SHOW_STR
15394 : IP_STR
15395 : BGP_STR
15396 : "List all bgp attribute information\n")
15397 : {
15398 0 : attr_show_all(vty);
15399 0 : return CMD_SUCCESS;
15400 : }
15401 :
15402 0 : static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15403 : afi_t afi, safi_t safi,
15404 : bool use_json, json_object *json)
15405 : {
15406 0 : struct bgp *bgp;
15407 0 : struct listnode *node;
15408 0 : char *vname;
15409 0 : char *ecom_str;
15410 0 : enum vpn_policy_direction dir;
15411 :
15412 0 : if (json) {
15413 0 : json_object *json_import_vrfs = NULL;
15414 0 : json_object *json_export_vrfs = NULL;
15415 :
15416 0 : bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15417 :
15418 0 : if (!bgp) {
15419 0 : vty_json(vty, json);
15420 :
15421 0 : return CMD_WARNING;
15422 : }
15423 :
15424 : /* Provide context for the block */
15425 0 : json_object_string_add(json, "vrf", name ? name : "default");
15426 0 : json_object_string_add(json, "afiSafi",
15427 : get_afi_safi_str(afi, safi, true));
15428 :
15429 0 : if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15430 : BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15431 0 : json_object_string_add(json, "importFromVrfs", "none");
15432 0 : json_object_string_add(json, "importRts", "none");
15433 : } else {
15434 0 : json_import_vrfs = json_object_new_array();
15435 :
15436 0 : for (ALL_LIST_ELEMENTS_RO(
15437 : bgp->vpn_policy[afi].import_vrf,
15438 : node, vname))
15439 0 : json_object_array_add(json_import_vrfs,
15440 : json_object_new_string(vname));
15441 :
15442 0 : json_object_object_add(json, "importFromVrfs",
15443 : json_import_vrfs);
15444 0 : dir = BGP_VPN_POLICY_DIR_FROMVPN;
15445 0 : if (bgp->vpn_policy[afi].rtlist[dir]) {
15446 0 : ecom_str = ecommunity_ecom2str(
15447 : bgp->vpn_policy[afi].rtlist[dir],
15448 : ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15449 0 : json_object_string_add(json, "importRts",
15450 : ecom_str);
15451 0 : XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15452 : } else
15453 0 : json_object_string_add(json, "importRts",
15454 : "none");
15455 : }
15456 :
15457 0 : if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15458 : BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15459 0 : json_object_string_add(json, "exportToVrfs", "none");
15460 0 : json_object_string_add(json, "routeDistinguisher",
15461 : "none");
15462 0 : json_object_string_add(json, "exportRts", "none");
15463 : } else {
15464 0 : json_export_vrfs = json_object_new_array();
15465 :
15466 0 : for (ALL_LIST_ELEMENTS_RO(
15467 : bgp->vpn_policy[afi].export_vrf,
15468 : node, vname))
15469 0 : json_object_array_add(json_export_vrfs,
15470 : json_object_new_string(vname));
15471 0 : json_object_object_add(json, "exportToVrfs",
15472 : json_export_vrfs);
15473 0 : json_object_string_addf(json, "routeDistinguisher",
15474 : "%pRD",
15475 : &bgp->vpn_policy[afi].tovpn_rd);
15476 :
15477 0 : dir = BGP_VPN_POLICY_DIR_TOVPN;
15478 0 : if (bgp->vpn_policy[afi].rtlist[dir]) {
15479 0 : ecom_str = ecommunity_ecom2str(
15480 : bgp->vpn_policy[afi].rtlist[dir],
15481 : ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15482 0 : json_object_string_add(json, "exportRts",
15483 : ecom_str);
15484 0 : XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15485 : } else
15486 0 : json_object_string_add(json, "exportRts",
15487 : "none");
15488 : }
15489 :
15490 0 : if (use_json) {
15491 0 : vty_json(vty, json);
15492 : }
15493 : } else {
15494 0 : bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15495 :
15496 0 : if (!bgp) {
15497 0 : vty_out(vty, "%% No such BGP instance exist\n");
15498 0 : return CMD_WARNING;
15499 : }
15500 :
15501 0 : if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15502 : BGP_CONFIG_VRF_TO_VRF_IMPORT))
15503 0 : vty_out(vty,
15504 : "This VRF is not importing %s routes from any other VRF\n",
15505 : get_afi_safi_str(afi, safi, false));
15506 : else {
15507 0 : vty_out(vty,
15508 : "This VRF is importing %s routes from the following VRFs:\n",
15509 : get_afi_safi_str(afi, safi, false));
15510 :
15511 0 : for (ALL_LIST_ELEMENTS_RO(
15512 : bgp->vpn_policy[afi].import_vrf,
15513 : node, vname))
15514 0 : vty_out(vty, " %s\n", vname);
15515 :
15516 0 : dir = BGP_VPN_POLICY_DIR_FROMVPN;
15517 0 : ecom_str = NULL;
15518 0 : if (bgp->vpn_policy[afi].rtlist[dir]) {
15519 0 : ecom_str = ecommunity_ecom2str(
15520 : bgp->vpn_policy[afi].rtlist[dir],
15521 : ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15522 0 : vty_out(vty, "Import RT(s): %s\n", ecom_str);
15523 :
15524 0 : XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15525 : } else
15526 0 : vty_out(vty, "Import RT(s):\n");
15527 : }
15528 :
15529 0 : if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15530 : BGP_CONFIG_VRF_TO_VRF_EXPORT))
15531 0 : vty_out(vty,
15532 : "This VRF is not exporting %s routes to any other VRF\n",
15533 : get_afi_safi_str(afi, safi, false));
15534 : else {
15535 0 : vty_out(vty,
15536 : "This VRF is exporting %s routes to the following VRFs:\n",
15537 : get_afi_safi_str(afi, safi, false));
15538 :
15539 0 : for (ALL_LIST_ELEMENTS_RO(
15540 : bgp->vpn_policy[afi].export_vrf,
15541 : node, vname))
15542 0 : vty_out(vty, " %s\n", vname);
15543 :
15544 0 : vty_out(vty, "RD: %pRD\n",
15545 : &bgp->vpn_policy[afi].tovpn_rd);
15546 :
15547 0 : dir = BGP_VPN_POLICY_DIR_TOVPN;
15548 0 : if (bgp->vpn_policy[afi].rtlist[dir]) {
15549 0 : ecom_str = ecommunity_ecom2str(
15550 : bgp->vpn_policy[afi].rtlist[dir],
15551 : ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15552 0 : vty_out(vty, "Export RT: %s\n", ecom_str);
15553 0 : XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15554 : } else
15555 0 : vty_out(vty, "Import RT(s):\n");
15556 : }
15557 : }
15558 :
15559 : return CMD_SUCCESS;
15560 : }
15561 :
15562 0 : static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15563 : safi_t safi, bool use_json)
15564 : {
15565 0 : struct listnode *node, *nnode;
15566 0 : struct bgp *bgp;
15567 0 : char *vrf_name = NULL;
15568 0 : json_object *json = NULL;
15569 0 : json_object *json_vrf = NULL;
15570 0 : json_object *json_vrfs = NULL;
15571 :
15572 0 : if (use_json) {
15573 0 : json = json_object_new_object();
15574 0 : json_vrfs = json_object_new_object();
15575 : }
15576 :
15577 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15578 :
15579 0 : if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15580 0 : vrf_name = bgp->name;
15581 :
15582 0 : if (use_json) {
15583 0 : json_vrf = json_object_new_object();
15584 : } else {
15585 0 : vty_out(vty, "\nInstance %s:\n",
15586 : (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15587 0 : ? VRF_DEFAULT_NAME : bgp->name);
15588 : }
15589 0 : bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15590 0 : if (use_json) {
15591 0 : if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15592 0 : json_object_object_add(json_vrfs,
15593 : VRF_DEFAULT_NAME, json_vrf);
15594 : else
15595 0 : json_object_object_add(json_vrfs, vrf_name,
15596 : json_vrf);
15597 : }
15598 : }
15599 :
15600 0 : if (use_json) {
15601 0 : json_object_object_add(json, "vrfs", json_vrfs);
15602 0 : vty_json(vty, json);
15603 : }
15604 :
15605 0 : return CMD_SUCCESS;
15606 : }
15607 :
15608 : /* "show [ip] bgp route-leak" command. */
15609 0 : DEFUN (show_ip_bgp_route_leak,
15610 : show_ip_bgp_route_leak_cmd,
15611 : "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15612 : SHOW_STR
15613 : IP_STR
15614 : BGP_STR
15615 : BGP_INSTANCE_HELP_STR
15616 : BGP_AFI_HELP_STR
15617 : BGP_SAFI_HELP_STR
15618 : "Route leaking information\n"
15619 : JSON_STR)
15620 : {
15621 0 : char *vrf = NULL;
15622 0 : afi_t afi = AFI_MAX;
15623 0 : safi_t safi = SAFI_MAX;
15624 :
15625 0 : bool uj = use_json(argc, argv);
15626 0 : int idx = 0;
15627 0 : json_object *json = NULL;
15628 :
15629 : /* show [ip] bgp */
15630 0 : if (argv_find(argv, argc, "ip", &idx)) {
15631 0 : afi = AFI_IP;
15632 0 : safi = SAFI_UNICAST;
15633 : }
15634 : /* [vrf VIEWVRFNAME] */
15635 0 : if (argv_find(argv, argc, "view", &idx)) {
15636 0 : vty_out(vty,
15637 : "%% This command is not applicable to BGP views\n");
15638 0 : return CMD_WARNING;
15639 : }
15640 :
15641 0 : if (argv_find(argv, argc, "vrf", &idx)) {
15642 0 : vrf = argv[idx + 1]->arg;
15643 0 : if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15644 0 : vrf = NULL;
15645 : }
15646 : /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15647 0 : if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15648 0 : argv_find_and_parse_safi(argv, argc, &idx, &safi);
15649 :
15650 0 : if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15651 0 : vty_out(vty,
15652 : "%% This command is applicable only for unicast ipv4|ipv6\n");
15653 0 : return CMD_WARNING;
15654 : }
15655 :
15656 0 : if (vrf && strmatch(vrf, "all"))
15657 0 : return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15658 :
15659 0 : if (uj)
15660 0 : json = json_object_new_object();
15661 :
15662 0 : return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15663 : }
15664 :
15665 0 : static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15666 : safi_t safi, bool uj)
15667 : {
15668 0 : struct listnode *node, *nnode;
15669 0 : struct bgp *bgp;
15670 :
15671 0 : for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15672 0 : if (!uj)
15673 0 : vty_out(vty, "\nInstance %s:\n",
15674 0 : (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15675 0 : ? VRF_DEFAULT_NAME
15676 : : bgp->name);
15677 :
15678 0 : update_group_show(bgp, afi, safi, vty, 0, uj);
15679 : }
15680 0 : }
15681 :
15682 0 : static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15683 : int safi, uint64_t subgrp_id, bool uj)
15684 : {
15685 0 : struct bgp *bgp;
15686 :
15687 0 : if (name) {
15688 0 : if (strmatch(name, "all")) {
15689 0 : bgp_show_all_instances_updgrps_vty(vty, afi, safi, uj);
15690 0 : return CMD_SUCCESS;
15691 : } else {
15692 0 : bgp = bgp_lookup_by_name(name);
15693 : }
15694 : } else {
15695 0 : bgp = bgp_get_default();
15696 : }
15697 :
15698 0 : if (bgp)
15699 0 : update_group_show(bgp, afi, safi, vty, subgrp_id, uj);
15700 : return CMD_SUCCESS;
15701 : }
15702 :
15703 0 : DEFUN (show_ip_bgp_updgrps,
15704 : show_ip_bgp_updgrps_cmd,
15705 : "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID] [json]",
15706 : SHOW_STR
15707 : IP_STR
15708 : BGP_STR
15709 : BGP_INSTANCE_HELP_STR
15710 : BGP_AFI_HELP_STR
15711 : BGP_SAFI_WITH_LABEL_HELP_STR
15712 : "Detailed info about dynamic update groups\n"
15713 : "Specific subgroup to display detailed info for\n"
15714 : JSON_STR)
15715 : {
15716 0 : char *vrf = NULL;
15717 0 : afi_t afi = AFI_IP6;
15718 0 : safi_t safi = SAFI_UNICAST;
15719 0 : uint64_t subgrp_id = 0;
15720 :
15721 0 : int idx = 0;
15722 :
15723 0 : bool uj = use_json(argc, argv);
15724 :
15725 : /* show [ip] bgp */
15726 0 : if (argv_find(argv, argc, "ip", &idx))
15727 0 : afi = AFI_IP;
15728 : /* [<vrf> VIEWVRFNAME] */
15729 0 : if (argv_find(argv, argc, "vrf", &idx)) {
15730 0 : vrf = argv[idx + 1]->arg;
15731 0 : if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15732 0 : vrf = NULL;
15733 0 : } else if (argv_find(argv, argc, "view", &idx))
15734 : /* [<view> VIEWVRFNAME] */
15735 0 : vrf = argv[idx + 1]->arg;
15736 : /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15737 0 : if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15738 0 : argv_find_and_parse_safi(argv, argc, &idx, &safi);
15739 : }
15740 :
15741 : /* get subgroup id, if provided */
15742 0 : idx = argc - 1;
15743 0 : if (argv[idx]->type == VARIABLE_TKN)
15744 0 : subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15745 :
15746 0 : return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id, uj));
15747 : }
15748 :
15749 0 : DEFUN (show_bgp_instance_all_ipv6_updgrps,
15750 : show_bgp_instance_all_ipv6_updgrps_cmd,
15751 : "show [ip] bgp <view|vrf> all update-groups [json]",
15752 : SHOW_STR
15753 : IP_STR
15754 : BGP_STR
15755 : BGP_INSTANCE_ALL_HELP_STR
15756 : "Detailed info about dynamic update groups\n"
15757 : JSON_STR)
15758 : {
15759 0 : bool uj = use_json(argc, argv);
15760 :
15761 0 : bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST, uj);
15762 0 : return CMD_SUCCESS;
15763 : }
15764 :
15765 0 : DEFUN (show_bgp_l2vpn_evpn_updgrps,
15766 : show_bgp_l2vpn_evpn_updgrps_cmd,
15767 : "show [ip] bgp l2vpn evpn update-groups",
15768 : SHOW_STR
15769 : IP_STR
15770 : BGP_STR
15771 : "l2vpn address family\n"
15772 : "evpn sub-address family\n"
15773 : "Detailed info about dynamic update groups\n")
15774 : {
15775 0 : char *vrf = NULL;
15776 0 : uint64_t subgrp_id = 0;
15777 :
15778 0 : bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
15779 0 : return CMD_SUCCESS;
15780 : }
15781 :
15782 0 : DEFUN (show_bgp_updgrps_stats,
15783 : show_bgp_updgrps_stats_cmd,
15784 : "show [ip] bgp update-groups statistics",
15785 : SHOW_STR
15786 : IP_STR
15787 : BGP_STR
15788 : "Detailed info about dynamic update groups\n"
15789 : "Statistics\n")
15790 : {
15791 0 : struct bgp *bgp;
15792 :
15793 0 : bgp = bgp_get_default();
15794 0 : if (bgp)
15795 0 : update_group_show_stats(bgp, vty);
15796 :
15797 0 : return CMD_SUCCESS;
15798 : }
15799 :
15800 0 : DEFUN (show_bgp_instance_updgrps_stats,
15801 : show_bgp_instance_updgrps_stats_cmd,
15802 : "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15803 : SHOW_STR
15804 : IP_STR
15805 : BGP_STR
15806 : BGP_INSTANCE_HELP_STR
15807 : "Detailed info about dynamic update groups\n"
15808 : "Statistics\n")
15809 : {
15810 0 : int idx_word = 3;
15811 0 : struct bgp *bgp;
15812 :
15813 0 : bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15814 0 : if (bgp)
15815 0 : update_group_show_stats(bgp, vty);
15816 :
15817 0 : return CMD_SUCCESS;
15818 : }
15819 :
15820 0 : static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15821 : afi_t afi, safi_t safi,
15822 : const char *what, uint64_t subgrp_id)
15823 : {
15824 0 : struct bgp *bgp;
15825 :
15826 0 : if (name)
15827 0 : bgp = bgp_lookup_by_name(name);
15828 : else
15829 0 : bgp = bgp_get_default();
15830 :
15831 0 : if (bgp) {
15832 0 : if (!strcmp(what, "advertise-queue"))
15833 0 : update_group_show_adj_queue(bgp, afi, safi, vty,
15834 : subgrp_id);
15835 0 : else if (!strcmp(what, "advertised-routes"))
15836 0 : update_group_show_advertised(bgp, afi, safi, vty,
15837 : subgrp_id);
15838 0 : else if (!strcmp(what, "packet-queue"))
15839 0 : update_group_show_packet_queue(bgp, afi, safi, vty,
15840 : subgrp_id);
15841 : }
15842 0 : }
15843 :
15844 0 : DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15845 : show_ip_bgp_instance_updgrps_adj_s_cmd,
15846 : "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",
15847 : SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15848 : BGP_SAFI_HELP_STR
15849 : "Detailed info about dynamic update groups\n"
15850 : "Specific subgroup to display info for\n"
15851 : "Advertisement queue\n"
15852 : "Announced routes\n"
15853 : "Packet queue\n")
15854 : {
15855 0 : uint64_t subgrp_id = 0;
15856 0 : afi_t afiz;
15857 0 : safi_t safiz;
15858 0 : if (sgid)
15859 0 : subgrp_id = strtoull(sgid, NULL, 10);
15860 :
15861 0 : if (!ip && !afi)
15862 : afiz = AFI_IP6;
15863 0 : if (!ip && afi)
15864 0 : afiz = bgp_vty_afi_from_str(afi);
15865 0 : if (ip && !afi)
15866 0 : afiz = AFI_IP;
15867 0 : if (ip && afi) {
15868 0 : afiz = bgp_vty_afi_from_str(afi);
15869 0 : if (afiz != AFI_IP)
15870 0 : vty_out(vty,
15871 : "%% Cannot specify both 'ip' and 'ipv6'\n");
15872 0 : return CMD_WARNING;
15873 : }
15874 :
15875 0 : safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15876 :
15877 0 : show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15878 0 : return CMD_SUCCESS;
15879 : }
15880 :
15881 0 : static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15882 : json_object *json)
15883 : {
15884 0 : struct listnode *node, *nnode;
15885 0 : struct prefix *range;
15886 0 : struct peer *conf;
15887 0 : struct peer *peer;
15888 0 : afi_t afi;
15889 0 : safi_t safi;
15890 0 : const char *peer_status;
15891 0 : int lr_count;
15892 0 : int dynamic;
15893 0 : bool af_cfgd;
15894 0 : json_object *json_peer_group = NULL;
15895 0 : json_object *json_peer_group_afc = NULL;
15896 0 : json_object *json_peer_group_members = NULL;
15897 0 : json_object *json_peer_group_dynamic = NULL;
15898 0 : json_object *json_peer_group_dynamic_af = NULL;
15899 0 : json_object *json_peer_group_ranges = NULL;
15900 :
15901 0 : conf = group->conf;
15902 :
15903 0 : if (json) {
15904 0 : json_peer_group = json_object_new_object();
15905 0 : json_peer_group_afc = json_object_new_array();
15906 : }
15907 :
15908 0 : if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15909 0 : if (json)
15910 0 : json_object_int_add(json_peer_group, "remoteAs",
15911 0 : conf->as);
15912 : else
15913 0 : vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15914 : group->name, conf->as);
15915 0 : } else if (conf->as_type == AS_INTERNAL) {
15916 0 : if (json)
15917 0 : json_object_int_add(json_peer_group, "remoteAs",
15918 0 : group->bgp->as);
15919 : else
15920 0 : vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15921 0 : group->name, group->bgp->as);
15922 : } else {
15923 0 : if (!json)
15924 0 : vty_out(vty, "\nBGP peer-group %s\n", group->name);
15925 : }
15926 :
15927 0 : if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15928 0 : if (json)
15929 0 : json_object_string_add(json_peer_group, "type",
15930 : "internal");
15931 : else
15932 0 : vty_out(vty, " Peer-group type is internal\n");
15933 : } else {
15934 0 : if (json)
15935 0 : json_object_string_add(json_peer_group, "type",
15936 : "external");
15937 : else
15938 0 : vty_out(vty, " Peer-group type is external\n");
15939 : }
15940 :
15941 : /* Display AFs configured. */
15942 0 : if (!json)
15943 0 : vty_out(vty, " Configured address-families:");
15944 :
15945 0 : FOREACH_AFI_SAFI (afi, safi) {
15946 0 : if (conf->afc[afi][safi]) {
15947 0 : af_cfgd = true;
15948 0 : if (json)
15949 0 : json_object_array_add(
15950 : json_peer_group_afc,
15951 : json_object_new_string(get_afi_safi_str(
15952 : afi, safi, false)));
15953 : else
15954 0 : vty_out(vty, " %s;",
15955 : get_afi_safi_str(afi, safi, false));
15956 : }
15957 : }
15958 :
15959 0 : if (json) {
15960 0 : json_object_object_add(json_peer_group,
15961 : "addressFamiliesConfigured",
15962 : json_peer_group_afc);
15963 : } else {
15964 0 : if (!af_cfgd)
15965 : vty_out(vty, " none\n");
15966 : else
15967 0 : vty_out(vty, "\n");
15968 : }
15969 :
15970 : /* Display listen ranges (for dynamic neighbors), if any */
15971 0 : for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15972 0 : lr_count = listcount(group->listen_range[afi]);
15973 0 : if (lr_count) {
15974 0 : if (json) {
15975 0 : if (!json_peer_group_dynamic)
15976 0 : json_peer_group_dynamic =
15977 0 : json_object_new_object();
15978 :
15979 0 : json_peer_group_dynamic_af =
15980 0 : json_object_new_object();
15981 0 : json_peer_group_ranges =
15982 0 : json_object_new_array();
15983 0 : json_object_int_add(json_peer_group_dynamic_af,
15984 : "count", lr_count);
15985 : } else {
15986 0 : vty_out(vty, " %d %s listen range(s)\n",
15987 : lr_count, afi2str(afi));
15988 : }
15989 :
15990 0 : for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15991 : nnode, range)) {
15992 0 : if (json) {
15993 0 : char buf[BUFSIZ];
15994 :
15995 0 : snprintfrr(buf, sizeof(buf), "%pFX",
15996 : range);
15997 :
15998 0 : json_object_array_add(
15999 : json_peer_group_ranges,
16000 : json_object_new_string(buf));
16001 : } else {
16002 0 : vty_out(vty, " %pFX\n", range);
16003 : }
16004 : }
16005 :
16006 0 : if (json) {
16007 0 : json_object_object_add(
16008 : json_peer_group_dynamic_af, "ranges",
16009 : json_peer_group_ranges);
16010 :
16011 0 : json_object_object_add(
16012 : json_peer_group_dynamic, afi2str(afi),
16013 : json_peer_group_dynamic_af);
16014 : }
16015 : }
16016 : }
16017 :
16018 0 : if (json_peer_group_dynamic)
16019 0 : json_object_object_add(json_peer_group, "dynamicRanges",
16020 : json_peer_group_dynamic);
16021 :
16022 : /* Display group members and their status */
16023 0 : if (listcount(group->peer)) {
16024 0 : if (json)
16025 0 : json_peer_group_members = json_object_new_object();
16026 : else
16027 0 : vty_out(vty, " Peer-group members:\n");
16028 0 : for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
16029 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
16030 0 : || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
16031 : peer_status = "Idle (Admin)";
16032 0 : else if (CHECK_FLAG(peer->sflags,
16033 : PEER_STATUS_PREFIX_OVERFLOW))
16034 : peer_status = "Idle (PfxCt)";
16035 : else
16036 0 : peer_status = lookup_msg(bgp_status_msg,
16037 0 : peer->status, NULL);
16038 :
16039 0 : dynamic = peer_dynamic_neighbor(peer);
16040 :
16041 0 : if (json) {
16042 0 : json_object *json_peer_group_member =
16043 0 : json_object_new_object();
16044 :
16045 0 : json_object_string_add(json_peer_group_member,
16046 : "status", peer_status);
16047 :
16048 0 : if (dynamic)
16049 0 : json_object_boolean_true_add(
16050 : json_peer_group_member,
16051 : "dynamic");
16052 :
16053 0 : json_object_object_add(json_peer_group_members,
16054 0 : peer->host,
16055 : json_peer_group_member);
16056 : } else {
16057 0 : vty_out(vty, " %s %s %s \n", peer->host,
16058 : dynamic ? "(dynamic)" : "",
16059 : peer_status);
16060 : }
16061 : }
16062 0 : if (json)
16063 0 : json_object_object_add(json_peer_group, "members",
16064 : json_peer_group_members);
16065 : }
16066 :
16067 0 : if (json)
16068 0 : json_object_object_add(json, group->name, json_peer_group);
16069 :
16070 0 : return CMD_SUCCESS;
16071 : }
16072 :
16073 0 : static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
16074 : const char *group_name, bool uj)
16075 : {
16076 0 : struct bgp *bgp;
16077 0 : struct listnode *node, *nnode;
16078 0 : struct peer_group *group;
16079 0 : bool found = false;
16080 0 : json_object *json = NULL;
16081 :
16082 0 : if (uj)
16083 0 : json = json_object_new_object();
16084 :
16085 0 : bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
16086 :
16087 0 : if (!bgp) {
16088 0 : if (uj)
16089 0 : vty_json(vty, json);
16090 : else
16091 0 : vty_out(vty, "%% BGP instance not found\n");
16092 :
16093 0 : return CMD_WARNING;
16094 : }
16095 :
16096 0 : for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16097 0 : if (group_name) {
16098 0 : if (strmatch(group->name, group_name)) {
16099 0 : bgp_show_one_peer_group(vty, group, json);
16100 0 : found = true;
16101 0 : break;
16102 : }
16103 : } else {
16104 0 : bgp_show_one_peer_group(vty, group, json);
16105 : }
16106 : }
16107 :
16108 0 : if (group_name && !found && !uj)
16109 0 : vty_out(vty, "%% No such peer-group\n");
16110 :
16111 0 : if (uj)
16112 0 : vty_json(vty, json);
16113 :
16114 : return CMD_SUCCESS;
16115 : }
16116 :
16117 0 : DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
16118 : "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
16119 : SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
16120 : "Detailed information on BGP peer groups\n"
16121 : "Peer group name\n" JSON_STR)
16122 : {
16123 0 : char *vrf, *pg;
16124 0 : int idx = 0;
16125 0 : bool uj = use_json(argc, argv);
16126 :
16127 0 : vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16128 0 : : NULL;
16129 0 : pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
16130 :
16131 0 : return bgp_show_peer_group_vty(vty, vrf, pg, uj);
16132 : }
16133 :
16134 :
16135 : /* Redistribute VTY commands. */
16136 :
16137 1 : DEFUN (bgp_redistribute_ipv4,
16138 : bgp_redistribute_ipv4_cmd,
16139 : "redistribute " FRR_IP_REDIST_STR_BGPD,
16140 : "Redistribute information from another routing protocol\n"
16141 : FRR_IP_REDIST_HELP_STR_BGPD)
16142 : {
16143 1 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16144 1 : int idx_protocol = 1;
16145 1 : int type;
16146 :
16147 1 : type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16148 1 : if (type < 0) {
16149 0 : vty_out(vty, "%% Invalid route type\n");
16150 0 : return CMD_WARNING_CONFIG_FAILED;
16151 : }
16152 :
16153 1 : bgp_redist_add(bgp, AFI_IP, type, 0);
16154 1 : return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
16155 : }
16156 :
16157 : ALIAS_HIDDEN(
16158 : bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16159 : "redistribute " FRR_IP_REDIST_STR_BGPD,
16160 : "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
16161 :
16162 0 : DEFUN (bgp_redistribute_ipv4_rmap,
16163 : bgp_redistribute_ipv4_rmap_cmd,
16164 : "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16165 : "Redistribute information from another routing protocol\n"
16166 : FRR_IP_REDIST_HELP_STR_BGPD
16167 : "Route map reference\n"
16168 : "Pointer to route-map entries\n")
16169 : {
16170 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16171 0 : int idx_protocol = 1;
16172 0 : int idx_word = 3;
16173 0 : int type;
16174 0 : struct bgp_redist *red;
16175 0 : bool changed;
16176 0 : struct route_map *route_map = route_map_lookup_warn_noexist(
16177 0 : vty, argv[idx_word]->arg);
16178 :
16179 0 : type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16180 0 : if (type < 0) {
16181 0 : vty_out(vty, "%% Invalid route type\n");
16182 0 : return CMD_WARNING_CONFIG_FAILED;
16183 : }
16184 :
16185 0 : red = bgp_redist_add(bgp, AFI_IP, type, 0);
16186 0 : changed =
16187 0 : bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16188 0 : return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16189 : }
16190 :
16191 : ALIAS_HIDDEN(
16192 : bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16193 : "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
16194 : "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16195 : "Route map reference\n"
16196 : "Pointer to route-map entries\n")
16197 :
16198 0 : DEFUN (bgp_redistribute_ipv4_metric,
16199 : bgp_redistribute_ipv4_metric_cmd,
16200 : "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16201 : "Redistribute information from another routing protocol\n"
16202 : FRR_IP_REDIST_HELP_STR_BGPD
16203 : "Metric for redistributed routes\n"
16204 : "Default metric\n")
16205 : {
16206 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16207 0 : int idx_protocol = 1;
16208 0 : int idx_number = 3;
16209 0 : int type;
16210 0 : uint32_t metric;
16211 0 : struct bgp_redist *red;
16212 0 : bool changed;
16213 :
16214 0 : type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16215 0 : if (type < 0) {
16216 0 : vty_out(vty, "%% Invalid route type\n");
16217 0 : return CMD_WARNING_CONFIG_FAILED;
16218 : }
16219 0 : metric = strtoul(argv[idx_number]->arg, NULL, 10);
16220 :
16221 0 : red = bgp_redist_add(bgp, AFI_IP, type, 0);
16222 0 : changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16223 0 : return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16224 : }
16225 :
16226 : ALIAS_HIDDEN(
16227 : bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16228 : "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16229 : "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16230 : "Metric for redistributed routes\n"
16231 : "Default metric\n")
16232 :
16233 0 : DEFUN (bgp_redistribute_ipv4_rmap_metric,
16234 : bgp_redistribute_ipv4_rmap_metric_cmd,
16235 : "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16236 : "Redistribute information from another routing protocol\n"
16237 : FRR_IP_REDIST_HELP_STR_BGPD
16238 : "Route map reference\n"
16239 : "Pointer to route-map entries\n"
16240 : "Metric for redistributed routes\n"
16241 : "Default metric\n")
16242 : {
16243 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16244 0 : int idx_protocol = 1;
16245 0 : int idx_word = 3;
16246 0 : int idx_number = 5;
16247 0 : int type;
16248 0 : uint32_t metric;
16249 0 : struct bgp_redist *red;
16250 0 : bool changed;
16251 0 : struct route_map *route_map =
16252 0 : route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16253 :
16254 0 : type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16255 0 : if (type < 0) {
16256 0 : vty_out(vty, "%% Invalid route type\n");
16257 0 : return CMD_WARNING_CONFIG_FAILED;
16258 : }
16259 0 : metric = strtoul(argv[idx_number]->arg, NULL, 10);
16260 :
16261 0 : red = bgp_redist_add(bgp, AFI_IP, type, 0);
16262 0 : changed =
16263 0 : bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16264 0 : changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16265 0 : return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16266 : }
16267 :
16268 : ALIAS_HIDDEN(
16269 : bgp_redistribute_ipv4_rmap_metric,
16270 : bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16271 : "redistribute " FRR_IP_REDIST_STR_BGPD
16272 : " route-map RMAP_NAME metric (0-4294967295)",
16273 : "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16274 : "Route map reference\n"
16275 : "Pointer to route-map entries\n"
16276 : "Metric for redistributed routes\n"
16277 : "Default metric\n")
16278 :
16279 0 : DEFUN (bgp_redistribute_ipv4_metric_rmap,
16280 : bgp_redistribute_ipv4_metric_rmap_cmd,
16281 : "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16282 : "Redistribute information from another routing protocol\n"
16283 : FRR_IP_REDIST_HELP_STR_BGPD
16284 : "Metric for redistributed routes\n"
16285 : "Default metric\n"
16286 : "Route map reference\n"
16287 : "Pointer to route-map entries\n")
16288 : {
16289 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16290 0 : int idx_protocol = 1;
16291 0 : int idx_number = 3;
16292 0 : int idx_word = 5;
16293 0 : int type;
16294 0 : uint32_t metric;
16295 0 : struct bgp_redist *red;
16296 0 : bool changed;
16297 0 : struct route_map *route_map =
16298 0 : route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16299 :
16300 0 : type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16301 0 : if (type < 0) {
16302 0 : vty_out(vty, "%% Invalid route type\n");
16303 0 : return CMD_WARNING_CONFIG_FAILED;
16304 : }
16305 0 : metric = strtoul(argv[idx_number]->arg, NULL, 10);
16306 :
16307 0 : red = bgp_redist_add(bgp, AFI_IP, type, 0);
16308 0 : changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
16309 0 : changed |=
16310 0 : bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16311 0 : return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
16312 : }
16313 :
16314 : ALIAS_HIDDEN(
16315 : bgp_redistribute_ipv4_metric_rmap,
16316 : bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16317 : "redistribute " FRR_IP_REDIST_STR_BGPD
16318 : " metric (0-4294967295) route-map RMAP_NAME",
16319 : "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16320 : "Metric for redistributed routes\n"
16321 : "Default metric\n"
16322 : "Route map reference\n"
16323 : "Pointer to route-map entries\n")
16324 :
16325 0 : DEFUN (bgp_redistribute_ipv4_ospf,
16326 : bgp_redistribute_ipv4_ospf_cmd,
16327 : "redistribute <ospf|table> (1-65535)",
16328 : "Redistribute information from another routing protocol\n"
16329 : "Open Shortest Path First (OSPFv2)\n"
16330 : "Non-main Kernel Routing Table\n"
16331 : "Instance ID/Table ID\n")
16332 : {
16333 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16334 0 : int idx_ospf_table = 1;
16335 0 : int idx_number = 2;
16336 0 : unsigned short instance;
16337 0 : unsigned short protocol;
16338 :
16339 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
16340 :
16341 0 : if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16342 : protocol = ZEBRA_ROUTE_OSPF;
16343 : else
16344 0 : protocol = ZEBRA_ROUTE_TABLE;
16345 :
16346 0 : bgp_redist_add(bgp, AFI_IP, protocol, instance);
16347 0 : return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
16348 : }
16349 :
16350 : ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16351 : "redistribute <ospf|table> (1-65535)",
16352 : "Redistribute information from another routing protocol\n"
16353 : "Open Shortest Path First (OSPFv2)\n"
16354 : "Non-main Kernel Routing Table\n"
16355 : "Instance ID/Table ID\n")
16356 :
16357 0 : DEFUN (bgp_redistribute_ipv4_ospf_rmap,
16358 : bgp_redistribute_ipv4_ospf_rmap_cmd,
16359 : "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16360 : "Redistribute information from another routing protocol\n"
16361 : "Open Shortest Path First (OSPFv2)\n"
16362 : "Non-main Kernel Routing Table\n"
16363 : "Instance ID/Table ID\n"
16364 : "Route map reference\n"
16365 : "Pointer to route-map entries\n")
16366 : {
16367 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16368 0 : int idx_ospf_table = 1;
16369 0 : int idx_number = 2;
16370 0 : int idx_word = 4;
16371 0 : struct bgp_redist *red;
16372 0 : unsigned short instance;
16373 0 : int protocol;
16374 0 : bool changed;
16375 0 : struct route_map *route_map =
16376 0 : route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16377 :
16378 0 : if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16379 : protocol = ZEBRA_ROUTE_OSPF;
16380 : else
16381 0 : protocol = ZEBRA_ROUTE_TABLE;
16382 :
16383 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
16384 0 : red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16385 0 : changed =
16386 0 : bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16387 0 : return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16388 : }
16389 :
16390 : ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16391 : bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16392 : "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
16393 : "Redistribute information from another routing protocol\n"
16394 : "Open Shortest Path First (OSPFv2)\n"
16395 : "Non-main Kernel Routing Table\n"
16396 : "Instance ID/Table ID\n"
16397 : "Route map reference\n"
16398 : "Pointer to route-map entries\n")
16399 :
16400 0 : DEFUN (bgp_redistribute_ipv4_ospf_metric,
16401 : bgp_redistribute_ipv4_ospf_metric_cmd,
16402 : "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16403 : "Redistribute information from another routing protocol\n"
16404 : "Open Shortest Path First (OSPFv2)\n"
16405 : "Non-main Kernel Routing Table\n"
16406 : "Instance ID/Table ID\n"
16407 : "Metric for redistributed routes\n"
16408 : "Default metric\n")
16409 : {
16410 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16411 0 : int idx_ospf_table = 1;
16412 0 : int idx_number = 2;
16413 0 : int idx_number_2 = 4;
16414 0 : uint32_t metric;
16415 0 : struct bgp_redist *red;
16416 0 : unsigned short instance;
16417 0 : int protocol;
16418 0 : bool changed;
16419 :
16420 0 : if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16421 : protocol = ZEBRA_ROUTE_OSPF;
16422 : else
16423 0 : protocol = ZEBRA_ROUTE_TABLE;
16424 :
16425 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
16426 0 : metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16427 :
16428 0 : red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16429 0 : changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16430 : metric);
16431 0 : return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16432 : }
16433 :
16434 : ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16435 : bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16436 : "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16437 : "Redistribute information from another routing protocol\n"
16438 : "Open Shortest Path First (OSPFv2)\n"
16439 : "Non-main Kernel Routing Table\n"
16440 : "Instance ID/Table ID\n"
16441 : "Metric for redistributed routes\n"
16442 : "Default metric\n")
16443 :
16444 0 : DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16445 : bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16446 : "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16447 : "Redistribute information from another routing protocol\n"
16448 : "Open Shortest Path First (OSPFv2)\n"
16449 : "Non-main Kernel Routing Table\n"
16450 : "Instance ID/Table ID\n"
16451 : "Route map reference\n"
16452 : "Pointer to route-map entries\n"
16453 : "Metric for redistributed routes\n"
16454 : "Default metric\n")
16455 : {
16456 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16457 0 : int idx_ospf_table = 1;
16458 0 : int idx_number = 2;
16459 0 : int idx_word = 4;
16460 0 : int idx_number_2 = 6;
16461 0 : uint32_t metric;
16462 0 : struct bgp_redist *red;
16463 0 : unsigned short instance;
16464 0 : int protocol;
16465 0 : bool changed;
16466 0 : struct route_map *route_map =
16467 0 : route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16468 :
16469 0 : if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16470 : protocol = ZEBRA_ROUTE_OSPF;
16471 : else
16472 0 : protocol = ZEBRA_ROUTE_TABLE;
16473 :
16474 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
16475 0 : metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16476 :
16477 0 : red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16478 0 : changed =
16479 0 : bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16480 0 : changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16481 : metric);
16482 0 : return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16483 : }
16484 :
16485 : ALIAS_HIDDEN(
16486 : bgp_redistribute_ipv4_ospf_rmap_metric,
16487 : bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16488 : "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
16489 : "Redistribute information from another routing protocol\n"
16490 : "Open Shortest Path First (OSPFv2)\n"
16491 : "Non-main Kernel Routing Table\n"
16492 : "Instance ID/Table ID\n"
16493 : "Route map reference\n"
16494 : "Pointer to route-map entries\n"
16495 : "Metric for redistributed routes\n"
16496 : "Default metric\n")
16497 :
16498 0 : DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16499 : bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16500 : "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16501 : "Redistribute information from another routing protocol\n"
16502 : "Open Shortest Path First (OSPFv2)\n"
16503 : "Non-main Kernel Routing Table\n"
16504 : "Instance ID/Table ID\n"
16505 : "Metric for redistributed routes\n"
16506 : "Default metric\n"
16507 : "Route map reference\n"
16508 : "Pointer to route-map entries\n")
16509 : {
16510 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16511 0 : int idx_ospf_table = 1;
16512 0 : int idx_number = 2;
16513 0 : int idx_number_2 = 4;
16514 0 : int idx_word = 6;
16515 0 : uint32_t metric;
16516 0 : struct bgp_redist *red;
16517 0 : unsigned short instance;
16518 0 : int protocol;
16519 0 : bool changed;
16520 0 : struct route_map *route_map =
16521 0 : route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16522 :
16523 0 : if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16524 : protocol = ZEBRA_ROUTE_OSPF;
16525 : else
16526 0 : protocol = ZEBRA_ROUTE_TABLE;
16527 :
16528 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
16529 0 : metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
16530 :
16531 0 : red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16532 0 : changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16533 : metric);
16534 0 : changed |=
16535 0 : bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16536 0 : return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16537 : }
16538 :
16539 : ALIAS_HIDDEN(
16540 : bgp_redistribute_ipv4_ospf_metric_rmap,
16541 : bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16542 : "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16543 : "Redistribute information from another routing protocol\n"
16544 : "Open Shortest Path First (OSPFv2)\n"
16545 : "Non-main Kernel Routing Table\n"
16546 : "Instance ID/Table ID\n"
16547 : "Metric for redistributed routes\n"
16548 : "Default metric\n"
16549 : "Route map reference\n"
16550 : "Pointer to route-map entries\n")
16551 :
16552 0 : DEFUN (no_bgp_redistribute_ipv4_ospf,
16553 : no_bgp_redistribute_ipv4_ospf_cmd,
16554 : "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16555 : NO_STR
16556 : "Redistribute information from another routing protocol\n"
16557 : "Open Shortest Path First (OSPFv2)\n"
16558 : "Non-main Kernel Routing Table\n"
16559 : "Instance ID/Table ID\n"
16560 : "Metric for redistributed routes\n"
16561 : "Default metric\n"
16562 : "Route map reference\n"
16563 : "Pointer to route-map entries\n")
16564 : {
16565 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16566 0 : int idx_ospf_table = 2;
16567 0 : int idx_number = 3;
16568 0 : unsigned short instance;
16569 0 : int protocol;
16570 :
16571 0 : if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16572 : protocol = ZEBRA_ROUTE_OSPF;
16573 : else
16574 0 : protocol = ZEBRA_ROUTE_TABLE;
16575 :
16576 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
16577 0 : return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16578 : }
16579 :
16580 : ALIAS_HIDDEN(
16581 : no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16582 : "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16583 : NO_STR
16584 : "Redistribute information from another routing protocol\n"
16585 : "Open Shortest Path First (OSPFv2)\n"
16586 : "Non-main Kernel Routing Table\n"
16587 : "Instance ID/Table ID\n"
16588 : "Metric for redistributed routes\n"
16589 : "Default metric\n"
16590 : "Route map reference\n"
16591 : "Pointer to route-map entries\n")
16592 :
16593 0 : DEFUN (no_bgp_redistribute_ipv4,
16594 : no_bgp_redistribute_ipv4_cmd,
16595 : "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16596 : NO_STR
16597 : "Redistribute information from another routing protocol\n"
16598 : FRR_IP_REDIST_HELP_STR_BGPD
16599 : "Metric for redistributed routes\n"
16600 : "Default metric\n"
16601 : "Route map reference\n"
16602 : "Pointer to route-map entries\n")
16603 : {
16604 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16605 0 : int idx_protocol = 2;
16606 0 : int type;
16607 :
16608 0 : type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16609 0 : if (type < 0) {
16610 0 : vty_out(vty, "%% Invalid route type\n");
16611 0 : return CMD_WARNING_CONFIG_FAILED;
16612 : }
16613 0 : return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16614 : }
16615 :
16616 : ALIAS_HIDDEN(
16617 : no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16618 : "no redistribute " FRR_IP_REDIST_STR_BGPD
16619 : " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16620 : NO_STR
16621 : "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16622 : "Metric for redistributed routes\n"
16623 : "Default metric\n"
16624 : "Route map reference\n"
16625 : "Pointer to route-map entries\n")
16626 :
16627 0 : DEFUN (bgp_redistribute_ipv6,
16628 : bgp_redistribute_ipv6_cmd,
16629 : "redistribute " FRR_IP6_REDIST_STR_BGPD,
16630 : "Redistribute information from another routing protocol\n"
16631 : FRR_IP6_REDIST_HELP_STR_BGPD)
16632 : {
16633 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16634 0 : int idx_protocol = 1;
16635 0 : int type;
16636 :
16637 0 : type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16638 0 : if (type < 0) {
16639 0 : vty_out(vty, "%% Invalid route type\n");
16640 0 : return CMD_WARNING_CONFIG_FAILED;
16641 : }
16642 :
16643 0 : bgp_redist_add(bgp, AFI_IP6, type, 0);
16644 0 : return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16645 : }
16646 :
16647 0 : DEFUN (bgp_redistribute_ipv6_rmap,
16648 : bgp_redistribute_ipv6_rmap_cmd,
16649 : "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16650 : "Redistribute information from another routing protocol\n"
16651 : FRR_IP6_REDIST_HELP_STR_BGPD
16652 : "Route map reference\n"
16653 : "Pointer to route-map entries\n")
16654 : {
16655 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16656 0 : int idx_protocol = 1;
16657 0 : int idx_word = 3;
16658 0 : int type;
16659 0 : struct bgp_redist *red;
16660 0 : bool changed;
16661 0 : struct route_map *route_map =
16662 0 : route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16663 :
16664 0 : type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16665 0 : if (type < 0) {
16666 0 : vty_out(vty, "%% Invalid route type\n");
16667 0 : return CMD_WARNING_CONFIG_FAILED;
16668 : }
16669 :
16670 0 : red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16671 0 : changed =
16672 0 : bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16673 0 : return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16674 : }
16675 :
16676 0 : DEFUN (bgp_redistribute_ipv6_metric,
16677 : bgp_redistribute_ipv6_metric_cmd,
16678 : "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16679 : "Redistribute information from another routing protocol\n"
16680 : FRR_IP6_REDIST_HELP_STR_BGPD
16681 : "Metric for redistributed routes\n"
16682 : "Default metric\n")
16683 : {
16684 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16685 0 : int idx_protocol = 1;
16686 0 : int idx_number = 3;
16687 0 : int type;
16688 0 : uint32_t metric;
16689 0 : struct bgp_redist *red;
16690 0 : bool changed;
16691 :
16692 0 : type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16693 0 : if (type < 0) {
16694 0 : vty_out(vty, "%% Invalid route type\n");
16695 0 : return CMD_WARNING_CONFIG_FAILED;
16696 : }
16697 0 : metric = strtoul(argv[idx_number]->arg, NULL, 10);
16698 :
16699 0 : red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16700 0 : changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16701 0 : return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16702 : }
16703 :
16704 0 : DEFUN (bgp_redistribute_ipv6_rmap_metric,
16705 : bgp_redistribute_ipv6_rmap_metric_cmd,
16706 : "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16707 : "Redistribute information from another routing protocol\n"
16708 : FRR_IP6_REDIST_HELP_STR_BGPD
16709 : "Route map reference\n"
16710 : "Pointer to route-map entries\n"
16711 : "Metric for redistributed routes\n"
16712 : "Default metric\n")
16713 : {
16714 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16715 0 : int idx_protocol = 1;
16716 0 : int idx_word = 3;
16717 0 : int idx_number = 5;
16718 0 : int type;
16719 0 : uint32_t metric;
16720 0 : struct bgp_redist *red;
16721 0 : bool changed;
16722 0 : struct route_map *route_map =
16723 0 : route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16724 :
16725 0 : type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16726 0 : if (type < 0) {
16727 0 : vty_out(vty, "%% Invalid route type\n");
16728 0 : return CMD_WARNING_CONFIG_FAILED;
16729 : }
16730 0 : metric = strtoul(argv[idx_number]->arg, NULL, 10);
16731 :
16732 0 : red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16733 0 : changed =
16734 0 : bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16735 0 : changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16736 : metric);
16737 0 : return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16738 : }
16739 :
16740 0 : DEFUN (bgp_redistribute_ipv6_metric_rmap,
16741 : bgp_redistribute_ipv6_metric_rmap_cmd,
16742 : "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16743 : "Redistribute information from another routing protocol\n"
16744 : FRR_IP6_REDIST_HELP_STR_BGPD
16745 : "Metric for redistributed routes\n"
16746 : "Default metric\n"
16747 : "Route map reference\n"
16748 : "Pointer to route-map entries\n")
16749 : {
16750 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16751 0 : int idx_protocol = 1;
16752 0 : int idx_number = 3;
16753 0 : int idx_word = 5;
16754 0 : int type;
16755 0 : uint32_t metric;
16756 0 : struct bgp_redist *red;
16757 0 : bool changed;
16758 0 : struct route_map *route_map =
16759 0 : route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16760 :
16761 0 : type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16762 0 : if (type < 0) {
16763 0 : vty_out(vty, "%% Invalid route type\n");
16764 0 : return CMD_WARNING_CONFIG_FAILED;
16765 : }
16766 0 : metric = strtoul(argv[idx_number]->arg, NULL, 10);
16767 :
16768 0 : red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16769 0 : changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16770 : metric);
16771 0 : changed |=
16772 0 : bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16773 0 : return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16774 : }
16775 :
16776 0 : DEFUN (no_bgp_redistribute_ipv6,
16777 : no_bgp_redistribute_ipv6_cmd,
16778 : "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16779 : NO_STR
16780 : "Redistribute information from another routing protocol\n"
16781 : FRR_IP6_REDIST_HELP_STR_BGPD
16782 : "Metric for redistributed routes\n"
16783 : "Default metric\n"
16784 : "Route map reference\n"
16785 : "Pointer to route-map entries\n")
16786 : {
16787 0 : VTY_DECLVAR_CONTEXT(bgp, bgp);
16788 0 : int idx_protocol = 2;
16789 0 : int type;
16790 :
16791 0 : type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16792 0 : if (type < 0) {
16793 0 : vty_out(vty, "%% Invalid route type\n");
16794 0 : return CMD_WARNING_CONFIG_FAILED;
16795 : }
16796 :
16797 0 : return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16798 : }
16799 :
16800 : /* Neighbor update tcp-mss. */
16801 0 : static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16802 : const char *tcp_mss_str)
16803 : {
16804 0 : struct peer *peer;
16805 0 : uint32_t tcp_mss_val = 0;
16806 :
16807 0 : peer = peer_and_group_lookup_vty(vty, peer_str);
16808 0 : if (!peer)
16809 : return CMD_WARNING_CONFIG_FAILED;
16810 :
16811 0 : if (tcp_mss_str) {
16812 0 : tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16813 0 : peer_tcp_mss_set(peer, tcp_mss_val);
16814 : } else {
16815 0 : peer_tcp_mss_unset(peer);
16816 : }
16817 :
16818 : return CMD_SUCCESS;
16819 : }
16820 :
16821 0 : DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16822 : "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16823 : NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16824 : "TCP max segment size\n"
16825 : "TCP MSS value\n")
16826 : {
16827 0 : int peer_index = 1;
16828 0 : int mss_index = 3;
16829 :
16830 0 : vty_out(vty,
16831 : " Warning: Reset BGP session for tcp-mss value to take effect\n");
16832 0 : return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16833 0 : argv[mss_index]->arg);
16834 : }
16835 :
16836 0 : DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16837 : "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16838 : NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16839 : "TCP max segment size\n"
16840 : "TCP MSS value\n")
16841 : {
16842 0 : int peer_index = 2;
16843 :
16844 0 : vty_out(vty,
16845 : " Warning: Reset BGP session for tcp-mss value to take effect\n");
16846 0 : return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16847 : }
16848 :
16849 0 : DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16850 : "[no$no] bgp retain route-target all",
16851 : NO_STR BGP_STR
16852 : "Retain BGP updates\n"
16853 : "Retain BGP updates based on route-target values\n"
16854 : "Retain all BGP updates\n")
16855 : {
16856 0 : bool check;
16857 0 : struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16858 :
16859 0 : check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16860 : BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16861 0 : if (check != !no) {
16862 0 : if (!no)
16863 0 : SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16864 : [bgp_node_safi(vty)],
16865 : BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16866 : else
16867 0 : UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16868 : [bgp_node_safi(vty)],
16869 : BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16870 : /* trigger a flush to re-sync with ADJ-RIB-in */
16871 0 : bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16872 : clear_all, BGP_CLEAR_SOFT_IN, NULL);
16873 : }
16874 0 : return CMD_SUCCESS;
16875 : }
16876 :
16877 0 : static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16878 : afi_t afi, safi_t safi)
16879 : {
16880 0 : int i;
16881 :
16882 : /* Unicast redistribution only. */
16883 0 : if (safi != SAFI_UNICAST)
16884 : return;
16885 :
16886 0 : for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16887 : /* Redistribute BGP does not make sense. */
16888 0 : if (i != ZEBRA_ROUTE_BGP) {
16889 0 : struct list *red_list;
16890 0 : struct listnode *node;
16891 0 : struct bgp_redist *red;
16892 :
16893 0 : red_list = bgp->redist[afi][i];
16894 0 : if (!red_list)
16895 0 : continue;
16896 :
16897 0 : for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16898 : /* "redistribute" configuration. */
16899 0 : vty_out(vty, " redistribute %s",
16900 : zebra_route_string(i));
16901 0 : if (red->instance)
16902 0 : vty_out(vty, " %d", red->instance);
16903 0 : if (red->redist_metric_flag)
16904 0 : vty_out(vty, " metric %u",
16905 : red->redist_metric);
16906 0 : if (red->rmap.name)
16907 0 : vty_out(vty, " route-map %s",
16908 : red->rmap.name);
16909 0 : vty_out(vty, "\n");
16910 : }
16911 : }
16912 : }
16913 : }
16914 :
16915 : /* peer-group helpers for config-write */
16916 :
16917 0 : static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16918 : {
16919 0 : if (!peer_group_active(peer)) {
16920 0 : if (CHECK_FLAG(peer->flags_invert, flag))
16921 0 : return !CHECK_FLAG(peer->flags, flag);
16922 : else
16923 0 : return !!CHECK_FLAG(peer->flags, flag);
16924 : }
16925 :
16926 0 : return !!CHECK_FLAG(peer->flags_override, flag);
16927 : }
16928 :
16929 0 : static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16930 : uint64_t flag)
16931 : {
16932 0 : if (!peer_group_active(peer)) {
16933 0 : if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16934 0 : return !peer_af_flag_check(peer, afi, safi, flag);
16935 : else
16936 0 : return !!peer_af_flag_check(peer, afi, safi, flag);
16937 : }
16938 :
16939 0 : return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16940 : }
16941 :
16942 0 : static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16943 : uint8_t type, int direct)
16944 : {
16945 0 : struct bgp_filter *filter;
16946 :
16947 0 : if (peer_group_active(peer))
16948 0 : return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16949 : type);
16950 :
16951 0 : filter = &peer->filter[afi][safi];
16952 0 : switch (type) {
16953 0 : case PEER_FT_DISTRIBUTE_LIST:
16954 0 : return !!(filter->dlist[direct].name);
16955 0 : case PEER_FT_FILTER_LIST:
16956 0 : return !!(filter->aslist[direct].name);
16957 0 : case PEER_FT_PREFIX_LIST:
16958 0 : return !!(filter->plist[direct].name);
16959 0 : case PEER_FT_ROUTE_MAP:
16960 0 : return !!(filter->map[direct].name);
16961 0 : case PEER_FT_UNSUPPRESS_MAP:
16962 0 : return !!(filter->usmap.name);
16963 0 : case PEER_FT_ADVERTISE_MAP:
16964 0 : return !!(filter->advmap.aname
16965 0 : && ((filter->advmap.condition == direct)
16966 0 : && filter->advmap.cname));
16967 : default:
16968 : return false;
16969 : }
16970 : }
16971 :
16972 : /* Return true if the addpath type is set for peer and different from
16973 : * peer-group.
16974 : */
16975 0 : static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16976 : safi_t safi)
16977 : {
16978 0 : enum bgp_addpath_strat type, g_type;
16979 :
16980 0 : type = peer->addpath_type[afi][safi];
16981 :
16982 0 : if (type != BGP_ADDPATH_NONE) {
16983 0 : if (peer_group_active(peer)) {
16984 0 : g_type = peer->group->conf->addpath_type[afi][safi];
16985 :
16986 0 : if (type != g_type)
16987 : return true;
16988 : else
16989 0 : return false;
16990 : }
16991 :
16992 : return true;
16993 : }
16994 :
16995 : return false;
16996 : }
16997 :
16998 : /* This is part of the address-family block (unicast only) */
16999 0 : static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
17000 : afi_t afi)
17001 : {
17002 0 : int indent = 2;
17003 0 : uint32_t tovpn_sid_index = 0;
17004 :
17005 0 : if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
17006 0 : if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17007 : BGP_CONFIG_VRF_TO_VRF_IMPORT))
17008 0 : vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
17009 : bgp->vpn_policy[afi]
17010 : .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17011 : else
17012 0 : vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
17013 : bgp->vpn_policy[afi]
17014 : .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
17015 : }
17016 0 : if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17017 : BGP_CONFIG_VRF_TO_VRF_IMPORT)
17018 : || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
17019 : BGP_CONFIG_VRF_TO_VRF_EXPORT))
17020 : return;
17021 :
17022 0 : if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17023 : BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
17024 :
17025 0 : vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
17026 :
17027 : } else {
17028 0 : if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
17029 0 : vty_out(vty, "%*slabel vpn export %u\n", indent, "",
17030 : bgp->vpn_policy[afi].tovpn_label);
17031 : }
17032 : }
17033 :
17034 0 : tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
17035 0 : if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17036 : BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
17037 0 : vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
17038 0 : } else if (tovpn_sid_index != 0) {
17039 0 : vty_out(vty, "%*ssid vpn export %d\n", indent, "",
17040 : tovpn_sid_index);
17041 : }
17042 :
17043 0 : if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
17044 0 : vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
17045 : &bgp->vpn_policy[afi].tovpn_rd);
17046 :
17047 0 : if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
17048 : BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
17049 :
17050 0 : char buf[PREFIX_STRLEN];
17051 0 : if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
17052 0 : &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
17053 : sizeof(buf))) {
17054 :
17055 0 : vty_out(vty, "%*snexthop vpn export %s\n",
17056 : indent, "", buf);
17057 : }
17058 : }
17059 0 : if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
17060 0 : && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
17061 0 : && ecommunity_cmp(
17062 : bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17063 0 : bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
17064 :
17065 0 : char *b = ecommunity_ecom2str(
17066 : bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17067 : ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
17068 0 : vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
17069 0 : XFREE(MTYPE_ECOMMUNITY_STR, b);
17070 : } else {
17071 0 : if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
17072 0 : char *b = ecommunity_ecom2str(
17073 : bgp->vpn_policy[afi]
17074 : .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
17075 : ECOMMUNITY_FORMAT_ROUTE_MAP,
17076 : ECOMMUNITY_ROUTE_TARGET);
17077 0 : vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
17078 0 : XFREE(MTYPE_ECOMMUNITY_STR, b);
17079 : }
17080 0 : if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
17081 0 : char *b = ecommunity_ecom2str(
17082 : bgp->vpn_policy[afi]
17083 : .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
17084 : ECOMMUNITY_FORMAT_ROUTE_MAP,
17085 : ECOMMUNITY_ROUTE_TARGET);
17086 0 : vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
17087 0 : XFREE(MTYPE_ECOMMUNITY_STR, b);
17088 : }
17089 : }
17090 :
17091 0 : if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
17092 0 : vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
17093 : bgp->vpn_policy[afi]
17094 : .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
17095 :
17096 0 : if (bgp->vpn_policy[afi].import_redirect_rtlist) {
17097 0 : char *b = ecommunity_ecom2str(
17098 : bgp->vpn_policy[afi]
17099 : .import_redirect_rtlist,
17100 : ECOMMUNITY_FORMAT_ROUTE_MAP,
17101 : ECOMMUNITY_ROUTE_TARGET);
17102 :
17103 0 : if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
17104 : != ECOMMUNITY_SIZE)
17105 0 : vty_out(vty, "%*srt6 redirect import %s\n",
17106 : indent, "", b);
17107 : else
17108 0 : vty_out(vty, "%*srt redirect import %s\n",
17109 : indent, "", b);
17110 0 : XFREE(MTYPE_ECOMMUNITY_STR, b);
17111 : }
17112 : }
17113 :
17114 0 : static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
17115 : afi_t afi, safi_t safi)
17116 : {
17117 0 : struct bgp_filter *filter;
17118 0 : char *addr;
17119 :
17120 0 : addr = peer->host;
17121 0 : filter = &peer->filter[afi][safi];
17122 :
17123 : /* distribute-list. */
17124 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17125 : FILTER_IN))
17126 0 : vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
17127 : filter->dlist[FILTER_IN].name);
17128 :
17129 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
17130 : FILTER_OUT))
17131 0 : vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
17132 : filter->dlist[FILTER_OUT].name);
17133 :
17134 : /* prefix-list. */
17135 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17136 : FILTER_IN))
17137 0 : vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
17138 : filter->plist[FILTER_IN].name);
17139 :
17140 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
17141 : FILTER_OUT))
17142 0 : vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
17143 : filter->plist[FILTER_OUT].name);
17144 :
17145 : /* route-map. */
17146 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
17147 0 : vty_out(vty, " neighbor %s route-map %s in\n", addr,
17148 : filter->map[RMAP_IN].name);
17149 :
17150 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
17151 : RMAP_OUT))
17152 0 : vty_out(vty, " neighbor %s route-map %s out\n", addr,
17153 : filter->map[RMAP_OUT].name);
17154 :
17155 : /* unsuppress-map */
17156 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
17157 0 : vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
17158 : filter->usmap.name);
17159 :
17160 : /* advertise-map : always applied in OUT direction*/
17161 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17162 : CONDITION_NON_EXIST))
17163 0 : vty_out(vty,
17164 : " neighbor %s advertise-map %s non-exist-map %s\n",
17165 : addr, filter->advmap.aname, filter->advmap.cname);
17166 :
17167 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
17168 : CONDITION_EXIST))
17169 0 : vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
17170 : addr, filter->advmap.aname, filter->advmap.cname);
17171 :
17172 : /* filter-list. */
17173 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17174 : FILTER_IN))
17175 0 : vty_out(vty, " neighbor %s filter-list %s in\n", addr,
17176 : filter->aslist[FILTER_IN].name);
17177 :
17178 0 : if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
17179 : FILTER_OUT))
17180 0 : vty_out(vty, " neighbor %s filter-list %s out\n", addr,
17181 : filter->aslist[FILTER_OUT].name);
17182 0 : }
17183 :
17184 : /* BGP peer configuration display function. */
17185 0 : static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
17186 : struct peer *peer)
17187 : {
17188 0 : struct peer *g_peer = NULL;
17189 0 : char *addr;
17190 0 : int if_pg_printed = false;
17191 0 : int if_ras_printed = false;
17192 :
17193 : /* Skip dynamic neighbors. */
17194 0 : if (peer_dynamic_neighbor(peer))
17195 0 : return;
17196 :
17197 0 : if (peer->conf_if)
17198 : addr = peer->conf_if;
17199 : else
17200 0 : addr = peer->host;
17201 :
17202 : /************************************
17203 : ****** Global to the neighbor ******
17204 : ************************************/
17205 0 : if (peer->conf_if) {
17206 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
17207 0 : vty_out(vty, " neighbor %s interface v6only", addr);
17208 : else
17209 0 : vty_out(vty, " neighbor %s interface", addr);
17210 :
17211 0 : if (peer_group_active(peer)) {
17212 0 : vty_out(vty, " peer-group %s", peer->group->name);
17213 0 : if_pg_printed = true;
17214 0 : } else if (peer->as_type == AS_SPECIFIED) {
17215 0 : vty_out(vty, " remote-as %u", peer->as);
17216 0 : if_ras_printed = true;
17217 0 : } else if (peer->as_type == AS_INTERNAL) {
17218 0 : vty_out(vty, " remote-as internal");
17219 0 : if_ras_printed = true;
17220 0 : } else if (peer->as_type == AS_EXTERNAL) {
17221 0 : vty_out(vty, " remote-as external");
17222 0 : if_ras_printed = true;
17223 : }
17224 :
17225 0 : vty_out(vty, "\n");
17226 : }
17227 :
17228 : /* remote-as and peer-group */
17229 : /* peer is a member of a peer-group */
17230 0 : if (peer_group_active(peer)) {
17231 0 : g_peer = peer->group->conf;
17232 :
17233 0 : if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17234 0 : if (peer->as_type == AS_SPECIFIED) {
17235 0 : vty_out(vty, " neighbor %s remote-as %u\n",
17236 : addr, peer->as);
17237 0 : } else if (peer->as_type == AS_INTERNAL) {
17238 0 : vty_out(vty,
17239 : " neighbor %s remote-as internal\n",
17240 : addr);
17241 0 : } else if (peer->as_type == AS_EXTERNAL) {
17242 0 : vty_out(vty,
17243 : " neighbor %s remote-as external\n",
17244 : addr);
17245 : }
17246 : }
17247 :
17248 : /* For swpX peers we displayed the peer-group
17249 : * via 'neighbor swpX interface peer-group PGNAME' */
17250 0 : if (!if_pg_printed)
17251 0 : vty_out(vty, " neighbor %s peer-group %s\n", addr,
17252 0 : peer->group->name);
17253 : }
17254 :
17255 : /* peer is NOT a member of a peer-group */
17256 : else {
17257 : /* peer is a peer-group, declare the peer-group */
17258 0 : if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17259 0 : vty_out(vty, " neighbor %s peer-group\n", addr);
17260 : }
17261 :
17262 0 : if (!if_ras_printed) {
17263 0 : if (peer->as_type == AS_SPECIFIED) {
17264 0 : vty_out(vty, " neighbor %s remote-as %u\n",
17265 : addr, peer->as);
17266 0 : } else if (peer->as_type == AS_INTERNAL) {
17267 0 : vty_out(vty,
17268 : " neighbor %s remote-as internal\n",
17269 : addr);
17270 0 : } else if (peer->as_type == AS_EXTERNAL) {
17271 0 : vty_out(vty,
17272 : " neighbor %s remote-as external\n",
17273 : addr);
17274 : }
17275 : }
17276 : }
17277 :
17278 : /* local-as */
17279 0 : if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17280 0 : vty_out(vty, " neighbor %s local-as %u", addr,
17281 : peer->change_local_as);
17282 0 : if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17283 0 : vty_out(vty, " no-prepend");
17284 0 : if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17285 0 : vty_out(vty, " replace-as");
17286 0 : vty_out(vty, "\n");
17287 : }
17288 :
17289 : /* description */
17290 0 : if (peer->desc) {
17291 0 : vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17292 : }
17293 :
17294 : /* shutdown */
17295 0 : if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17296 0 : if (peer->tx_shutdown_message)
17297 0 : vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17298 : peer->tx_shutdown_message);
17299 : else
17300 0 : vty_out(vty, " neighbor %s shutdown\n", addr);
17301 : }
17302 :
17303 0 : if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17304 0 : vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17305 0 : peer->rtt_expected, peer->rtt_keepalive_conf);
17306 :
17307 : /* bfd */
17308 0 : if (peer->bfd_config)
17309 0 : bgp_bfd_peer_config_write(vty, peer, addr);
17310 :
17311 : /* password */
17312 0 : if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17313 0 : vty_out(vty, " neighbor %s password %s\n", addr,
17314 : peer->password);
17315 :
17316 : /* neighbor solo */
17317 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17318 0 : if (!peer_group_active(peer)) {
17319 0 : vty_out(vty, " neighbor %s solo\n", addr);
17320 : }
17321 : }
17322 :
17323 : /* BGP port */
17324 0 : if (peer->port != BGP_PORT_DEFAULT) {
17325 0 : vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17326 : }
17327 :
17328 : /* Local interface name */
17329 0 : if (peer->ifname) {
17330 0 : vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17331 : }
17332 :
17333 : /* TCP max segment size */
17334 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17335 0 : vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17336 :
17337 : /* passive */
17338 0 : if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17339 0 : vty_out(vty, " neighbor %s passive\n", addr);
17340 :
17341 : /* ebgp-multihop */
17342 0 : if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
17343 0 : && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17344 : && peer->ttl == MAXTTL)) {
17345 0 : if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17346 0 : vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17347 : peer->ttl);
17348 : }
17349 : }
17350 :
17351 : /* aigp */
17352 0 : if (peergroup_flag_check(peer, PEER_FLAG_AIGP))
17353 0 : vty_out(vty, " neighbor %s aigp\n", addr);
17354 :
17355 : /* graceful-shutdown */
17356 0 : if (peergroup_flag_check(peer, PEER_FLAG_GRACEFUL_SHUTDOWN))
17357 0 : vty_out(vty, " neighbor %s graceful-shutdown\n", addr);
17358 :
17359 : /* role */
17360 0 : if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
17361 0 : peer->local_role != ROLE_UNDEFINED)
17362 0 : vty_out(vty, " neighbor %s local-role %s%s\n", addr,
17363 : bgp_get_name_by_role(peer->local_role),
17364 0 : CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
17365 : ? " strict-mode"
17366 : : "");
17367 :
17368 : /* ttl-security hops */
17369 0 : if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
17370 0 : if (!peer_group_active(peer)
17371 0 : || g_peer->gtsm_hops != peer->gtsm_hops) {
17372 0 : vty_out(vty, " neighbor %s ttl-security hops %d\n",
17373 : addr, peer->gtsm_hops);
17374 : }
17375 : }
17376 :
17377 : /* disable-connected-check */
17378 0 : if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17379 0 : vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17380 :
17381 : /* link-bw-encoding-ieee */
17382 0 : if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
17383 0 : vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
17384 : addr);
17385 :
17386 : /* extended-optional-parameters */
17387 0 : if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
17388 0 : vty_out(vty, " neighbor %s extended-optional-parameters\n",
17389 : addr);
17390 :
17391 : /* enforce-first-as */
17392 0 : if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17393 0 : vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17394 :
17395 : /* update-source */
17396 0 : if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17397 0 : if (peer->update_source)
17398 0 : vty_out(vty, " neighbor %s update-source %pSU\n", addr,
17399 : peer->update_source);
17400 0 : else if (peer->update_if)
17401 0 : vty_out(vty, " neighbor %s update-source %s\n", addr,
17402 : peer->update_if);
17403 : }
17404 :
17405 : /* advertisement-interval */
17406 0 : if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17407 0 : vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17408 0 : peer->routeadv);
17409 :
17410 : /* timers */
17411 0 : if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17412 0 : vty_out(vty, " neighbor %s timers %u %u\n", addr,
17413 0 : peer->keepalive, peer->holdtime);
17414 :
17415 : /* timers connect */
17416 0 : if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17417 0 : vty_out(vty, " neighbor %s timers connect %u\n", addr,
17418 0 : peer->connect);
17419 : /* need special-case handling for changed default values due to
17420 : * config profile / version (because there is no "timers bgp connect"
17421 : * command, we need to save this per-peer :/)
17422 : */
17423 0 : else if (!peer_group_active(peer) && !peer->connect &&
17424 0 : peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17425 0 : vty_out(vty, " neighbor %s timers connect %u\n", addr,
17426 : peer->bgp->default_connect_retry);
17427 :
17428 : /* timers delayopen */
17429 0 : if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17430 0 : vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17431 0 : peer->delayopen);
17432 : /* Save config even though flag is not set if default values have been
17433 : * changed
17434 : */
17435 0 : else if (!peer_group_active(peer) && !peer->delayopen
17436 0 : && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17437 0 : vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17438 : peer->bgp->default_delayopen);
17439 :
17440 : /* capability dynamic */
17441 0 : if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17442 0 : vty_out(vty, " neighbor %s capability dynamic\n", addr);
17443 :
17444 : /* capability extended-nexthop */
17445 0 : if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17446 0 : if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17447 0 : !peer->conf_if)
17448 0 : vty_out(vty,
17449 : " no neighbor %s capability extended-nexthop\n",
17450 : addr);
17451 0 : else if (!peer->conf_if)
17452 0 : vty_out(vty,
17453 : " neighbor %s capability extended-nexthop\n",
17454 : addr);
17455 : }
17456 :
17457 : /* dont-capability-negotiation */
17458 0 : if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17459 0 : vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17460 :
17461 : /* override-capability */
17462 0 : if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17463 0 : vty_out(vty, " neighbor %s override-capability\n", addr);
17464 :
17465 : /* strict-capability-match */
17466 0 : if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17467 0 : vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17468 :
17469 : /* Sender side AS path loop detection. */
17470 0 : if (peer->as_path_loop_detection)
17471 0 : vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17472 : addr);
17473 :
17474 : /* path-attribute discard */
17475 0 : char discard_attrs_str[BUFSIZ] = {0};
17476 0 : bool discard_attrs = bgp_path_attribute_discard(
17477 : peer, discard_attrs_str, sizeof(discard_attrs_str));
17478 :
17479 0 : if (discard_attrs)
17480 0 : vty_out(vty, " neighbor %s path-attribute discard %s\n", addr,
17481 : discard_attrs_str);
17482 :
17483 0 : if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
17484 : PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
17485 :
17486 0 : if (CHECK_FLAG(peer->peer_gr_new_status_flag,
17487 : PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
17488 0 : vty_out(vty,
17489 : " neighbor %s graceful-restart-helper\n", addr);
17490 0 : } else if (CHECK_FLAG(
17491 : peer->peer_gr_new_status_flag,
17492 : PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
17493 0 : vty_out(vty,
17494 : " neighbor %s graceful-restart\n", addr);
17495 0 : } else if (
17496 : (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17497 : PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17498 : && !(CHECK_FLAG(
17499 : peer->peer_gr_new_status_flag,
17500 : PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17501 0 : vty_out(vty, " neighbor %s graceful-restart-disable\n",
17502 : addr);
17503 : }
17504 : }
17505 : }
17506 :
17507 : /* BGP peer configuration display function. */
17508 0 : static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17509 : struct peer *peer, afi_t afi, safi_t safi)
17510 : {
17511 0 : struct peer *g_peer = NULL;
17512 0 : char *addr;
17513 0 : bool flag_scomm, flag_secomm, flag_slcomm;
17514 :
17515 : /* Skip dynamic neighbors. */
17516 0 : if (peer_dynamic_neighbor(peer))
17517 : return;
17518 :
17519 0 : if (peer->conf_if)
17520 : addr = peer->conf_if;
17521 : else
17522 0 : addr = peer->host;
17523 :
17524 : /************************************
17525 : ****** Per AF to the neighbor ******
17526 : ************************************/
17527 0 : if (peer_group_active(peer)) {
17528 0 : g_peer = peer->group->conf;
17529 :
17530 : /* If the peer-group is active but peer is not, print a 'no
17531 : * activate' */
17532 0 : if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17533 0 : vty_out(vty, " no neighbor %s activate\n", addr);
17534 : }
17535 :
17536 : /* If the peer-group is not active but peer is, print an
17537 : 'activate' */
17538 0 : else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17539 0 : vty_out(vty, " neighbor %s activate\n", addr);
17540 : }
17541 : } else {
17542 0 : if (peer->afc[afi][safi]) {
17543 0 : if (safi == SAFI_ENCAP)
17544 0 : vty_out(vty, " neighbor %s activate\n", addr);
17545 0 : else if (!bgp->default_af[afi][safi])
17546 0 : vty_out(vty, " neighbor %s activate\n", addr);
17547 : } else {
17548 0 : if (bgp->default_af[afi][safi])
17549 0 : vty_out(vty, " no neighbor %s activate\n",
17550 : addr);
17551 : }
17552 : }
17553 :
17554 : /* addpath TX knobs */
17555 0 : if (peergroup_af_addpath_check(peer, afi, safi)) {
17556 0 : switch (peer->addpath_type[afi][safi]) {
17557 0 : case BGP_ADDPATH_ALL:
17558 0 : vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17559 : addr);
17560 0 : break;
17561 0 : case BGP_ADDPATH_BEST_PER_AS:
17562 0 : vty_out(vty,
17563 : " neighbor %s addpath-tx-bestpath-per-AS\n",
17564 : addr);
17565 0 : break;
17566 : case BGP_ADDPATH_MAX:
17567 : case BGP_ADDPATH_NONE:
17568 : break;
17569 : }
17570 : }
17571 :
17572 0 : if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17573 0 : vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17574 :
17575 : /* ORF capability. */
17576 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17577 0 : || peergroup_af_flag_check(peer, afi, safi,
17578 : PEER_FLAG_ORF_PREFIX_RM)) {
17579 0 : vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17580 :
17581 0 : if (peergroup_af_flag_check(peer, afi, safi,
17582 : PEER_FLAG_ORF_PREFIX_SM)
17583 0 : && peergroup_af_flag_check(peer, afi, safi,
17584 : PEER_FLAG_ORF_PREFIX_RM))
17585 0 : vty_out(vty, " both");
17586 0 : else if (peergroup_af_flag_check(peer, afi, safi,
17587 : PEER_FLAG_ORF_PREFIX_SM))
17588 0 : vty_out(vty, " send");
17589 : else
17590 0 : vty_out(vty, " receive");
17591 0 : vty_out(vty, "\n");
17592 : }
17593 :
17594 : /* Route reflector client. */
17595 0 : if (peergroup_af_flag_check(peer, afi, safi,
17596 : PEER_FLAG_REFLECTOR_CLIENT)) {
17597 0 : vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17598 : }
17599 :
17600 : /* next-hop-self force */
17601 0 : if (peergroup_af_flag_check(peer, afi, safi,
17602 : PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17603 0 : vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17604 : }
17605 :
17606 : /* next-hop-self */
17607 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17608 0 : vty_out(vty, " neighbor %s next-hop-self\n", addr);
17609 : }
17610 :
17611 : /* remove-private-AS */
17612 0 : if (peergroup_af_flag_check(peer, afi, safi,
17613 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17614 0 : vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17615 : addr);
17616 : }
17617 :
17618 0 : else if (peergroup_af_flag_check(peer, afi, safi,
17619 : PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17620 0 : vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17621 : addr);
17622 : }
17623 :
17624 0 : else if (peergroup_af_flag_check(peer, afi, safi,
17625 : PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17626 0 : vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17627 : }
17628 :
17629 0 : else if (peergroup_af_flag_check(peer, afi, safi,
17630 : PEER_FLAG_REMOVE_PRIVATE_AS)) {
17631 0 : vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17632 : }
17633 :
17634 : /* as-override */
17635 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17636 0 : vty_out(vty, " neighbor %s as-override\n", addr);
17637 : }
17638 :
17639 : /* send-community print. */
17640 0 : flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17641 : PEER_FLAG_SEND_COMMUNITY);
17642 0 : flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17643 : PEER_FLAG_SEND_EXT_COMMUNITY);
17644 0 : flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17645 : PEER_FLAG_SEND_LARGE_COMMUNITY);
17646 :
17647 0 : if (flag_scomm && flag_secomm && flag_slcomm) {
17648 0 : vty_out(vty, " no neighbor %s send-community all\n", addr);
17649 : } else {
17650 0 : if (flag_scomm)
17651 0 : vty_out(vty, " no neighbor %s send-community\n", addr);
17652 0 : if (flag_secomm)
17653 0 : vty_out(vty,
17654 : " no neighbor %s send-community extended\n",
17655 : addr);
17656 :
17657 0 : if (flag_slcomm)
17658 0 : vty_out(vty, " no neighbor %s send-community large\n",
17659 : addr);
17660 : }
17661 :
17662 : /* Default information */
17663 0 : if (peergroup_af_flag_check(peer, afi, safi,
17664 : PEER_FLAG_DEFAULT_ORIGINATE)) {
17665 0 : vty_out(vty, " neighbor %s default-originate", addr);
17666 :
17667 0 : if (peer->default_rmap[afi][safi].name)
17668 0 : vty_out(vty, " route-map %s",
17669 : peer->default_rmap[afi][safi].name);
17670 :
17671 0 : vty_out(vty, "\n");
17672 : }
17673 :
17674 : /* Soft reconfiguration inbound. */
17675 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17676 0 : vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17677 : addr);
17678 : }
17679 :
17680 : /* maximum-prefix. */
17681 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17682 0 : vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17683 : peer->pmax[afi][safi]);
17684 :
17685 0 : if (peer->pmax_threshold[afi][safi]
17686 : != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17687 0 : vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17688 0 : if (peer_af_flag_check(peer, afi, safi,
17689 : PEER_FLAG_MAX_PREFIX_WARNING))
17690 0 : vty_out(vty, " warning-only");
17691 0 : if (peer->pmax_restart[afi][safi])
17692 0 : vty_out(vty, " restart %u",
17693 : peer->pmax_restart[afi][safi]);
17694 0 : if (peer_af_flag_check(peer, afi, safi,
17695 : PEER_FLAG_MAX_PREFIX_FORCE))
17696 0 : vty_out(vty, " force");
17697 :
17698 0 : vty_out(vty, "\n");
17699 : }
17700 :
17701 : /* maximum-prefix-out */
17702 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17703 0 : vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17704 : addr, peer->pmax_out[afi][safi]);
17705 :
17706 : /* Route server client. */
17707 0 : if (peergroup_af_flag_check(peer, afi, safi,
17708 : PEER_FLAG_RSERVER_CLIENT)) {
17709 0 : vty_out(vty, " neighbor %s route-server-client\n", addr);
17710 : }
17711 :
17712 : /* Nexthop-local unchanged. */
17713 0 : if (peergroup_af_flag_check(peer, afi, safi,
17714 : PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17715 0 : vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17716 : }
17717 :
17718 : /* allowas-in <1-10> */
17719 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17720 0 : if (peer_af_flag_check(peer, afi, safi,
17721 : PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17722 0 : vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17723 0 : } else if (peer->allowas_in[afi][safi] == 3) {
17724 0 : vty_out(vty, " neighbor %s allowas-in\n", addr);
17725 : } else {
17726 0 : vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17727 : peer->allowas_in[afi][safi]);
17728 : }
17729 : }
17730 :
17731 : /* accept-own */
17732 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ACCEPT_OWN))
17733 0 : vty_out(vty, " neighbor %s accept-own\n", addr);
17734 :
17735 : /* soo */
17736 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17737 0 : char *soo_str = ecommunity_ecom2str(
17738 : peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17739 :
17740 0 : vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17741 0 : XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17742 : }
17743 :
17744 : /* weight */
17745 0 : if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17746 0 : vty_out(vty, " neighbor %s weight %lu\n", addr,
17747 : peer->weight[afi][safi]);
17748 :
17749 : /* Filter. */
17750 0 : bgp_config_write_filter(vty, peer, afi, safi);
17751 :
17752 : /* atribute-unchanged. */
17753 0 : if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17754 0 : || (safi != SAFI_EVPN
17755 0 : && peer_af_flag_check(peer, afi, safi,
17756 : PEER_FLAG_NEXTHOP_UNCHANGED))
17757 0 : || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17758 :
17759 0 : if (!peer_group_active(peer)
17760 0 : || peergroup_af_flag_check(peer, afi, safi,
17761 : PEER_FLAG_AS_PATH_UNCHANGED)
17762 0 : || peergroup_af_flag_check(peer, afi, safi,
17763 : PEER_FLAG_NEXTHOP_UNCHANGED)
17764 0 : || peergroup_af_flag_check(peer, afi, safi,
17765 : PEER_FLAG_MED_UNCHANGED)) {
17766 :
17767 0 : vty_out(vty,
17768 : " neighbor %s attribute-unchanged%s%s%s\n",
17769 : addr,
17770 0 : peer_af_flag_check(peer, afi, safi,
17771 : PEER_FLAG_AS_PATH_UNCHANGED)
17772 : ? " as-path"
17773 : : "",
17774 0 : peer_af_flag_check(peer, afi, safi,
17775 : PEER_FLAG_NEXTHOP_UNCHANGED)
17776 : ? " next-hop"
17777 : : "",
17778 0 : peer_af_flag_check(peer, afi, safi,
17779 : PEER_FLAG_MED_UNCHANGED)
17780 : ? " med"
17781 : : "");
17782 : }
17783 : }
17784 : }
17785 :
17786 0 : static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17787 : safi_t safi)
17788 : {
17789 0 : if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17790 : BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17791 0 : vty_out(vty, " no bgp retain route-target all\n");
17792 0 : }
17793 :
17794 : /* Address family based peer configuration display. */
17795 0 : static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17796 : safi_t safi)
17797 : {
17798 0 : struct peer *peer;
17799 0 : struct peer_group *group;
17800 0 : struct listnode *node, *nnode;
17801 :
17802 :
17803 0 : vty_frame(vty, " !\n address-family ");
17804 0 : if (afi == AFI_IP) {
17805 0 : if (safi == SAFI_UNICAST)
17806 0 : vty_frame(vty, "ipv4 unicast");
17807 : else if (safi == SAFI_LABELED_UNICAST)
17808 0 : vty_frame(vty, "ipv4 labeled-unicast");
17809 : else if (safi == SAFI_MULTICAST)
17810 0 : vty_frame(vty, "ipv4 multicast");
17811 : else if (safi == SAFI_MPLS_VPN)
17812 0 : vty_frame(vty, "ipv4 vpn");
17813 : else if (safi == SAFI_ENCAP)
17814 0 : vty_frame(vty, "ipv4 encap");
17815 : else if (safi == SAFI_FLOWSPEC)
17816 0 : vty_frame(vty, "ipv4 flowspec");
17817 0 : } else if (afi == AFI_IP6) {
17818 0 : if (safi == SAFI_UNICAST)
17819 0 : vty_frame(vty, "ipv6 unicast");
17820 : else if (safi == SAFI_LABELED_UNICAST)
17821 0 : vty_frame(vty, "ipv6 labeled-unicast");
17822 : else if (safi == SAFI_MULTICAST)
17823 0 : vty_frame(vty, "ipv6 multicast");
17824 : else if (safi == SAFI_MPLS_VPN)
17825 0 : vty_frame(vty, "ipv6 vpn");
17826 : else if (safi == SAFI_ENCAP)
17827 0 : vty_frame(vty, "ipv6 encap");
17828 : else if (safi == SAFI_FLOWSPEC)
17829 0 : vty_frame(vty, "ipv6 flowspec");
17830 0 : } else if (afi == AFI_L2VPN) {
17831 0 : if (safi == SAFI_EVPN)
17832 0 : vty_frame(vty, "l2vpn evpn");
17833 : }
17834 0 : vty_frame(vty, "\n");
17835 :
17836 0 : bgp_config_write_distance(vty, bgp, afi, safi);
17837 :
17838 0 : bgp_config_write_network(vty, bgp, afi, safi);
17839 :
17840 0 : bgp_config_write_redistribute(vty, bgp, afi, safi);
17841 :
17842 : /* BGP flag dampening. */
17843 0 : if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17844 0 : bgp_config_write_damp(vty, afi, safi);
17845 :
17846 0 : for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17847 0 : bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17848 :
17849 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17850 : /* Do not display doppelganger peers */
17851 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17852 0 : bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17853 : }
17854 :
17855 0 : bgp_config_write_maxpaths(vty, bgp, afi, safi);
17856 0 : bgp_config_write_table_map(vty, bgp, afi, safi);
17857 :
17858 0 : if (safi == SAFI_EVPN)
17859 0 : bgp_config_write_evpn_info(vty, bgp, afi, safi);
17860 :
17861 0 : if (safi == SAFI_FLOWSPEC)
17862 0 : bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17863 :
17864 0 : if (safi == SAFI_MPLS_VPN)
17865 0 : bgp_vpn_config_write(vty, bgp, afi, safi);
17866 :
17867 0 : if (safi == SAFI_UNICAST) {
17868 0 : bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17869 0 : if (CHECK_FLAG(bgp->af_flags[afi][safi],
17870 : BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17871 :
17872 0 : vty_out(vty, " export vpn\n");
17873 : }
17874 0 : if (CHECK_FLAG(bgp->af_flags[afi][safi],
17875 : BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17876 :
17877 0 : vty_out(vty, " import vpn\n");
17878 : }
17879 0 : if (CHECK_FLAG(bgp->af_flags[afi][safi],
17880 : BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17881 0 : char *name;
17882 :
17883 0 : for (ALL_LIST_ELEMENTS_RO(
17884 : bgp->vpn_policy[afi].import_vrf, node,
17885 : name))
17886 0 : vty_out(vty, " import vrf %s\n", name);
17887 : }
17888 : }
17889 :
17890 0 : vty_endframe(vty, " exit-address-family\n");
17891 0 : }
17892 :
17893 0 : int bgp_config_write(struct vty *vty)
17894 : {
17895 0 : struct bgp *bgp;
17896 0 : struct peer_group *group;
17897 0 : struct peer *peer;
17898 0 : struct listnode *node, *nnode;
17899 0 : struct listnode *mnode, *mnnode;
17900 0 : afi_t afi;
17901 0 : safi_t safi;
17902 0 : uint32_t tovpn_sid_index = 0;
17903 :
17904 0 : if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17905 0 : vty_out(vty, "bgp route-map delay-timer %u\n",
17906 : bm->rmap_update_timer);
17907 :
17908 0 : if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17909 0 : vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17910 0 : if (bm->v_update_delay != bm->v_establish_wait)
17911 0 : vty_out(vty, " %d", bm->v_establish_wait);
17912 0 : vty_out(vty, "\n");
17913 : }
17914 :
17915 0 : if (bm->wait_for_fib)
17916 0 : vty_out(vty, "bgp suppress-fib-pending\n");
17917 :
17918 0 : if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17919 0 : vty_out(vty, "bgp graceful-shutdown\n");
17920 :
17921 : /* No-RIB (Zebra) option flag configuration */
17922 0 : if (bgp_option_check(BGP_OPT_NO_FIB))
17923 0 : vty_out(vty, "bgp no-rib\n");
17924 :
17925 0 : if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17926 0 : vty_out(vty, "bgp send-extra-data zebra\n");
17927 :
17928 : /* BGP session DSCP value */
17929 0 : if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17930 0 : vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17931 :
17932 : /* BGP InQ limit */
17933 0 : if (bm->inq_limit != BM_DEFAULT_Q_LIMIT)
17934 0 : vty_out(vty, "bgp input-queue-limit %u\n", bm->inq_limit);
17935 :
17936 0 : if (bm->outq_limit != BM_DEFAULT_Q_LIMIT)
17937 0 : vty_out(vty, "bgp output-queue-limit %u\n", bm->outq_limit);
17938 :
17939 : /* BGP configuration. */
17940 0 : for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17941 :
17942 : /* skip all auto created vrf as they dont have user config */
17943 0 : if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17944 0 : continue;
17945 :
17946 : /* Router bgp ASN */
17947 0 : vty_out(vty, "router bgp %u", bgp->as);
17948 :
17949 0 : if (bgp->name)
17950 0 : vty_out(vty, " %s %s",
17951 0 : (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17952 : ? "view" : "vrf", bgp->name);
17953 0 : vty_out(vty, "\n");
17954 :
17955 : /* BGP fast-external-failover. */
17956 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17957 0 : vty_out(vty, " no bgp fast-external-failover\n");
17958 :
17959 : /* BGP router ID. */
17960 0 : if (bgp->router_id_static.s_addr != INADDR_ANY)
17961 0 : vty_out(vty, " bgp router-id %pI4\n",
17962 : &bgp->router_id_static);
17963 :
17964 : /* Suppress fib pending */
17965 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17966 0 : vty_out(vty, " bgp suppress-fib-pending\n");
17967 :
17968 : /* BGP log-neighbor-changes. */
17969 0 : if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17970 0 : != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17971 0 : vty_out(vty, " %sbgp log-neighbor-changes\n",
17972 : CHECK_FLAG(bgp->flags,
17973 : BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17974 : ? ""
17975 : : "no ");
17976 :
17977 : /* BGP configuration. */
17978 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17979 0 : vty_out(vty, " bgp always-compare-med\n");
17980 :
17981 : /* RFC8212 default eBGP policy. */
17982 0 : if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17983 0 : != SAVE_BGP_EBGP_REQUIRES_POLICY)
17984 0 : vty_out(vty, " %sbgp ebgp-requires-policy\n",
17985 : CHECK_FLAG(bgp->flags,
17986 : BGP_FLAG_EBGP_REQUIRES_POLICY)
17987 : ? ""
17988 : : "no ");
17989 :
17990 : /* draft-ietf-idr-deprecate-as-set-confed-set */
17991 0 : if (bgp->reject_as_sets)
17992 0 : vty_out(vty, " bgp reject-as-sets\n");
17993 :
17994 : /* Suppress duplicate updates if the route actually not changed
17995 : */
17996 0 : if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17997 0 : != SAVE_BGP_SUPPRESS_DUPLICATES)
17998 0 : vty_out(vty, " %sbgp suppress-duplicates\n",
17999 : CHECK_FLAG(bgp->flags,
18000 : BGP_FLAG_SUPPRESS_DUPLICATES)
18001 : ? ""
18002 : : "no ");
18003 :
18004 : /* Send Hard Reset CEASE Notification for 'Administrative Reset'
18005 : */
18006 0 : if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
18007 : SAVE_BGP_HARD_ADMIN_RESET)
18008 0 : vty_out(vty, " %sbgp hard-administrative-reset\n",
18009 : CHECK_FLAG(bgp->flags,
18010 : BGP_FLAG_HARD_ADMIN_RESET)
18011 : ? ""
18012 : : "no ");
18013 :
18014 : /* BGP default <afi>-<safi> */
18015 0 : FOREACH_AFI_SAFI (afi, safi) {
18016 0 : if (afi == AFI_IP && safi == SAFI_UNICAST) {
18017 0 : if (!bgp->default_af[afi][safi])
18018 0 : vty_out(vty, " no bgp default %s\n",
18019 : get_bgp_default_af_flag(afi,
18020 : safi));
18021 0 : } else if (bgp->default_af[afi][safi])
18022 0 : vty_out(vty, " bgp default %s\n",
18023 : get_bgp_default_af_flag(afi, safi));
18024 : }
18025 :
18026 : /* BGP default local-preference. */
18027 0 : if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
18028 0 : vty_out(vty, " bgp default local-preference %u\n",
18029 : bgp->default_local_pref);
18030 :
18031 : /* BGP default show-hostname */
18032 0 : if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18033 0 : != SAVE_BGP_SHOW_HOSTNAME)
18034 0 : vty_out(vty, " %sbgp default show-hostname\n",
18035 : CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
18036 : ? ""
18037 : : "no ");
18038 :
18039 : /* BGP default show-nexthop-hostname */
18040 0 : if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18041 0 : != SAVE_BGP_SHOW_HOSTNAME)
18042 0 : vty_out(vty, " %sbgp default show-nexthop-hostname\n",
18043 : CHECK_FLAG(bgp->flags,
18044 : BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
18045 : ? ""
18046 : : "no ");
18047 :
18048 : /* BGP default subgroup-pkt-queue-max. */
18049 0 : if (bgp->default_subgroup_pkt_queue_max
18050 : != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
18051 0 : vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
18052 : bgp->default_subgroup_pkt_queue_max);
18053 :
18054 : /* BGP client-to-client reflection. */
18055 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
18056 0 : vty_out(vty, " no bgp client-to-client reflection\n");
18057 :
18058 : /* BGP cluster ID. */
18059 0 : if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
18060 0 : vty_out(vty, " bgp cluster-id %pI4\n",
18061 : &bgp->cluster_id);
18062 :
18063 : /* Disable ebgp connected nexthop check */
18064 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
18065 0 : vty_out(vty,
18066 : " bgp disable-ebgp-connected-route-check\n");
18067 :
18068 : /* Confederation identifier*/
18069 0 : if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
18070 0 : vty_out(vty, " bgp confederation identifier %u\n",
18071 : bgp->confed_id);
18072 :
18073 : /* Confederation peer */
18074 0 : if (bgp->confed_peers_cnt > 0) {
18075 0 : int i;
18076 :
18077 0 : vty_out(vty, " bgp confederation peers");
18078 :
18079 0 : for (i = 0; i < bgp->confed_peers_cnt; i++)
18080 0 : vty_out(vty, " %u", bgp->confed_peers[i]);
18081 :
18082 0 : vty_out(vty, "\n");
18083 : }
18084 :
18085 : /* BGP deterministic-med. */
18086 0 : if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
18087 0 : != SAVE_BGP_DETERMINISTIC_MED)
18088 0 : vty_out(vty, " %sbgp deterministic-med\n",
18089 : CHECK_FLAG(bgp->flags,
18090 : BGP_FLAG_DETERMINISTIC_MED)
18091 : ? ""
18092 : : "no ");
18093 :
18094 : /* BGP update-delay. */
18095 0 : bgp_config_write_update_delay(vty, bgp);
18096 :
18097 0 : if (bgp->v_maxmed_onstartup
18098 : != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
18099 0 : vty_out(vty, " bgp max-med on-startup %u",
18100 : bgp->v_maxmed_onstartup);
18101 0 : if (bgp->maxmed_onstartup_value
18102 : != BGP_MAXMED_VALUE_DEFAULT)
18103 0 : vty_out(vty, " %u",
18104 : bgp->maxmed_onstartup_value);
18105 0 : vty_out(vty, "\n");
18106 : }
18107 0 : if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
18108 0 : vty_out(vty, " bgp max-med administrative");
18109 0 : if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
18110 0 : vty_out(vty, " %u", bgp->maxmed_admin_value);
18111 0 : vty_out(vty, "\n");
18112 : }
18113 :
18114 : /* write quanta */
18115 0 : bgp_config_write_wpkt_quanta(vty, bgp);
18116 : /* read quanta */
18117 0 : bgp_config_write_rpkt_quanta(vty, bgp);
18118 :
18119 : /* coalesce time */
18120 0 : bgp_config_write_coalesce_time(vty, bgp);
18121 :
18122 : /* BGP per-instance graceful-shutdown */
18123 : /* BGP-wide settings and per-instance settings are mutually
18124 : * exclusive.
18125 : */
18126 0 : if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
18127 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
18128 0 : vty_out(vty, " bgp graceful-shutdown\n");
18129 :
18130 : /* Long-lived Graceful Restart */
18131 0 : if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
18132 0 : vty_out(vty,
18133 : " bgp long-lived-graceful-restart stale-time %u\n",
18134 : bgp->llgr_stale_time);
18135 :
18136 : /* BGP graceful-restart. */
18137 0 : if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
18138 0 : vty_out(vty,
18139 : " bgp graceful-restart stalepath-time %u\n",
18140 : bgp->stalepath_time);
18141 :
18142 0 : if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
18143 0 : vty_out(vty, " bgp graceful-restart restart-time %u\n",
18144 : bgp->restart_time);
18145 :
18146 0 : if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
18147 : SAVE_BGP_GRACEFUL_NOTIFICATION)
18148 0 : vty_out(vty, " %sbgp graceful-restart notification\n",
18149 : CHECK_FLAG(bgp->flags,
18150 : BGP_FLAG_GRACEFUL_NOTIFICATION)
18151 : ? ""
18152 : : "no ");
18153 :
18154 0 : if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
18155 0 : vty_out(vty,
18156 : " bgp graceful-restart select-defer-time %u\n",
18157 : bgp->select_defer_time);
18158 :
18159 0 : if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
18160 0 : vty_out(vty, " bgp graceful-restart\n");
18161 :
18162 0 : if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
18163 0 : vty_out(vty, " bgp graceful-restart-disable\n");
18164 :
18165 : /* BGP graceful-restart Preserve State F bit. */
18166 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
18167 0 : vty_out(vty,
18168 : " bgp graceful-restart preserve-fw-state\n");
18169 :
18170 : /* BGP TCP keepalive */
18171 0 : bgp_config_tcp_keepalive(vty, bgp);
18172 :
18173 : /* Stale timer for RIB */
18174 0 : if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
18175 0 : vty_out(vty,
18176 : " bgp graceful-restart rib-stale-time %u\n",
18177 : bgp->rib_stale_time);
18178 :
18179 : /* BGP bestpath method. */
18180 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
18181 0 : vty_out(vty, " bgp bestpath as-path ignore\n");
18182 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
18183 0 : vty_out(vty, " bgp bestpath as-path confed\n");
18184 :
18185 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
18186 0 : if (CHECK_FLAG(bgp->flags,
18187 : BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
18188 0 : vty_out(vty,
18189 : " bgp bestpath as-path multipath-relax as-set\n");
18190 : } else {
18191 0 : vty_out(vty,
18192 : " bgp bestpath as-path multipath-relax\n");
18193 : }
18194 : }
18195 :
18196 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
18197 0 : vty_out(vty,
18198 : " bgp route-reflector allow-outbound-policy\n");
18199 : }
18200 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
18201 0 : vty_out(vty, " bgp bestpath compare-routerid\n");
18202 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP))
18203 0 : vty_out(vty, " bgp bestpath aigp\n");
18204 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
18205 0 : || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
18206 0 : vty_out(vty, " bgp bestpath med");
18207 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
18208 0 : vty_out(vty, " confed");
18209 0 : if (CHECK_FLAG(bgp->flags,
18210 : BGP_FLAG_MED_MISSING_AS_WORST))
18211 0 : vty_out(vty, " missing-as-worst");
18212 0 : vty_out(vty, "\n");
18213 : }
18214 :
18215 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
18216 0 : vty_out(vty,
18217 : " bgp bestpath peer-type multipath-relax\n");
18218 :
18219 : /* Link bandwidth handling. */
18220 0 : if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
18221 0 : vty_out(vty, " bgp bestpath bandwidth ignore\n");
18222 0 : else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
18223 0 : vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
18224 0 : else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
18225 0 : vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
18226 :
18227 : /* BGP network import check. */
18228 0 : if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18229 0 : != SAVE_BGP_IMPORT_CHECK)
18230 0 : vty_out(vty, " %sbgp network import-check\n",
18231 : CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
18232 : ? ""
18233 : : "no ");
18234 :
18235 : /* BGP timers configuration. */
18236 0 : if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
18237 0 : || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
18238 0 : vty_out(vty, " timers bgp %u %u\n",
18239 : bgp->default_keepalive, bgp->default_holdtime);
18240 :
18241 : /* BGP minimum holdtime configuration. */
18242 0 : if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
18243 0 : && bgp->default_min_holdtime != 0)
18244 0 : vty_out(vty, " bgp minimum-holdtime %u\n",
18245 : bgp->default_min_holdtime);
18246 :
18247 : /* Conditional advertisement timer configuration */
18248 0 : if (bgp->condition_check_period
18249 : != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
18250 0 : vty_out(vty,
18251 : " bgp conditional-advertisement timer %u\n",
18252 : bgp->condition_check_period);
18253 :
18254 : /* peer-group */
18255 0 : for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
18256 0 : bgp_config_write_peer_global(vty, bgp, group->conf);
18257 : }
18258 :
18259 : /* Normal neighbor configuration. */
18260 0 : for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
18261 0 : if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
18262 0 : bgp_config_write_peer_global(vty, bgp, peer);
18263 : }
18264 :
18265 : /* listen range and limit for dynamic BGP neighbors */
18266 0 : bgp_config_write_listen(vty, bgp);
18267 :
18268 : /*
18269 : * BGP default autoshutdown neighbors
18270 : *
18271 : * This must be placed after any peer and peer-group
18272 : * configuration, to avoid setting all peers to shutdown after
18273 : * a daemon restart, which is undesired behavior. (see #2286)
18274 : */
18275 0 : if (bgp->autoshutdown)
18276 0 : vty_out(vty, " bgp default shutdown\n");
18277 :
18278 : /* BGP instance administrative shutdown */
18279 0 : if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
18280 0 : vty_out(vty, " bgp shutdown\n");
18281 :
18282 0 : if (bgp->allow_martian)
18283 0 : vty_out(vty, " bgp allow-martian-nexthop\n");
18284 :
18285 0 : if (bgp->fast_convergence)
18286 0 : vty_out(vty, " bgp fast-convergence\n");
18287 :
18288 0 : if (bgp->srv6_enabled) {
18289 0 : vty_frame(vty, " !\n segment-routing srv6\n");
18290 0 : if (strlen(bgp->srv6_locator_name))
18291 0 : vty_out(vty, " locator %s\n",
18292 0 : bgp->srv6_locator_name);
18293 0 : vty_endframe(vty, " exit\n");
18294 : }
18295 :
18296 0 : tovpn_sid_index = bgp->tovpn_sid_index;
18297 0 : if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_TOVPN_SID_AUTO)) {
18298 0 : vty_out(vty, " sid vpn per-vrf export auto\n");
18299 0 : } else if (tovpn_sid_index != 0) {
18300 0 : vty_out(vty, " sid vpn per-vrf export %d\n",
18301 : tovpn_sid_index);
18302 : }
18303 :
18304 : /* IPv4 unicast configuration. */
18305 0 : bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
18306 :
18307 : /* IPv4 multicast configuration. */
18308 0 : bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
18309 :
18310 : /* IPv4 labeled-unicast configuration. */
18311 0 : bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18312 :
18313 : /* IPv4 VPN configuration. */
18314 0 : bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18315 :
18316 : /* ENCAPv4 configuration. */
18317 0 : bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18318 :
18319 : /* FLOWSPEC v4 configuration. */
18320 0 : bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18321 :
18322 : /* IPv6 unicast configuration. */
18323 0 : bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18324 :
18325 : /* IPv6 multicast configuration. */
18326 0 : bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18327 :
18328 : /* IPv6 labeled-unicast configuration. */
18329 0 : bgp_config_write_family(vty, bgp, AFI_IP6,
18330 : SAFI_LABELED_UNICAST);
18331 :
18332 : /* IPv6 VPN configuration. */
18333 0 : bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18334 :
18335 : /* ENCAPv6 configuration. */
18336 0 : bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18337 :
18338 : /* FLOWSPEC v6 configuration. */
18339 0 : bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18340 :
18341 : /* EVPN configuration. */
18342 0 : bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18343 :
18344 0 : hook_call(bgp_inst_config_write, bgp, vty);
18345 :
18346 : #ifdef ENABLE_BGP_VNC
18347 0 : bgp_rfapi_cfg_write(vty, bgp);
18348 : #endif
18349 :
18350 0 : vty_out(vty, "exit\n");
18351 0 : vty_out(vty, "!\n");
18352 : }
18353 0 : return 0;
18354 : }
18355 :
18356 :
18357 : /* BGP node structure. */
18358 : static struct cmd_node bgp_node = {
18359 : .name = "bgp",
18360 : .node = BGP_NODE,
18361 : .parent_node = CONFIG_NODE,
18362 : .prompt = "%s(config-router)# ",
18363 : .config_write = bgp_config_write,
18364 : };
18365 :
18366 : static struct cmd_node bgp_ipv4_unicast_node = {
18367 : .name = "bgp ipv4 unicast",
18368 : .node = BGP_IPV4_NODE,
18369 : .parent_node = BGP_NODE,
18370 : .prompt = "%s(config-router-af)# ",
18371 : .no_xpath = true,
18372 : };
18373 :
18374 : static struct cmd_node bgp_ipv4_multicast_node = {
18375 : .name = "bgp ipv4 multicast",
18376 : .node = BGP_IPV4M_NODE,
18377 : .parent_node = BGP_NODE,
18378 : .prompt = "%s(config-router-af)# ",
18379 : .no_xpath = true,
18380 : };
18381 :
18382 : static struct cmd_node bgp_ipv4_labeled_unicast_node = {
18383 : .name = "bgp ipv4 labeled unicast",
18384 : .node = BGP_IPV4L_NODE,
18385 : .parent_node = BGP_NODE,
18386 : .prompt = "%s(config-router-af)# ",
18387 : .no_xpath = true,
18388 : };
18389 :
18390 : static struct cmd_node bgp_ipv6_unicast_node = {
18391 : .name = "bgp ipv6 unicast",
18392 : .node = BGP_IPV6_NODE,
18393 : .parent_node = BGP_NODE,
18394 : .prompt = "%s(config-router-af)# ",
18395 : .no_xpath = true,
18396 : };
18397 :
18398 : static struct cmd_node bgp_ipv6_multicast_node = {
18399 : .name = "bgp ipv6 multicast",
18400 : .node = BGP_IPV6M_NODE,
18401 : .parent_node = BGP_NODE,
18402 : .prompt = "%s(config-router-af)# ",
18403 : .no_xpath = true,
18404 : };
18405 :
18406 : static struct cmd_node bgp_ipv6_labeled_unicast_node = {
18407 : .name = "bgp ipv6 labeled unicast",
18408 : .node = BGP_IPV6L_NODE,
18409 : .parent_node = BGP_NODE,
18410 : .prompt = "%s(config-router-af)# ",
18411 : .no_xpath = true,
18412 : };
18413 :
18414 : static struct cmd_node bgp_vpnv4_node = {
18415 : .name = "bgp vpnv4",
18416 : .node = BGP_VPNV4_NODE,
18417 : .parent_node = BGP_NODE,
18418 : .prompt = "%s(config-router-af)# ",
18419 : .no_xpath = true,
18420 : };
18421 :
18422 : static struct cmd_node bgp_vpnv6_node = {
18423 : .name = "bgp vpnv6",
18424 : .node = BGP_VPNV6_NODE,
18425 : .parent_node = BGP_NODE,
18426 : .prompt = "%s(config-router-af-vpnv6)# ",
18427 : .no_xpath = true,
18428 : };
18429 :
18430 : static struct cmd_node bgp_evpn_node = {
18431 : .name = "bgp evpn",
18432 : .node = BGP_EVPN_NODE,
18433 : .parent_node = BGP_NODE,
18434 : .prompt = "%s(config-router-evpn)# ",
18435 : .no_xpath = true,
18436 : };
18437 :
18438 : static struct cmd_node bgp_evpn_vni_node = {
18439 : .name = "bgp evpn vni",
18440 : .node = BGP_EVPN_VNI_NODE,
18441 : .parent_node = BGP_EVPN_NODE,
18442 : .prompt = "%s(config-router-af-vni)# ",
18443 : };
18444 :
18445 : static struct cmd_node bgp_flowspecv4_node = {
18446 : .name = "bgp ipv4 flowspec",
18447 : .node = BGP_FLOWSPECV4_NODE,
18448 : .parent_node = BGP_NODE,
18449 : .prompt = "%s(config-router-af)# ",
18450 : .no_xpath = true,
18451 : };
18452 :
18453 : static struct cmd_node bgp_flowspecv6_node = {
18454 : .name = "bgp ipv6 flowspec",
18455 : .node = BGP_FLOWSPECV6_NODE,
18456 : .parent_node = BGP_NODE,
18457 : .prompt = "%s(config-router-af-vpnv6)# ",
18458 : .no_xpath = true,
18459 : };
18460 :
18461 : static struct cmd_node bgp_srv6_node = {
18462 : .name = "bgp srv6",
18463 : .node = BGP_SRV6_NODE,
18464 : .parent_node = BGP_NODE,
18465 : .prompt = "%s(config-router-srv6)# ",
18466 : };
18467 :
18468 : static void community_list_vty(void);
18469 :
18470 0 : static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18471 : {
18472 0 : struct bgp *bgp;
18473 0 : struct peer_group *group;
18474 0 : struct listnode *lnbgp, *lnpeer;
18475 :
18476 0 : for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18477 0 : for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18478 0 : vector_set(comps,
18479 0 : XSTRDUP(MTYPE_COMPLETION, group->name));
18480 : }
18481 0 : }
18482 :
18483 0 : static void bgp_ac_peer(vector comps, struct cmd_token *token)
18484 : {
18485 0 : struct bgp *bgp;
18486 0 : struct peer *peer;
18487 0 : struct listnode *lnbgp, *lnpeer;
18488 :
18489 0 : for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18490 0 : for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18491 : /* only provide suggestions on the appropriate input
18492 : * token type,
18493 : * they'll otherwise show up multiple times */
18494 0 : enum cmd_token_type match_type;
18495 0 : char *name = peer->host;
18496 :
18497 0 : if (peer->conf_if) {
18498 : match_type = VARIABLE_TKN;
18499 : name = peer->conf_if;
18500 0 : } else if (strchr(peer->host, ':'))
18501 : match_type = IPV6_TKN;
18502 : else
18503 0 : match_type = IPV4_TKN;
18504 :
18505 0 : if (token->type != match_type)
18506 0 : continue;
18507 :
18508 0 : vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18509 : }
18510 : }
18511 0 : }
18512 :
18513 0 : static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18514 : {
18515 0 : bgp_ac_peer(comps, token);
18516 :
18517 0 : if (token->type == VARIABLE_TKN)
18518 0 : bgp_ac_peergroup(comps, token);
18519 0 : }
18520 :
18521 : static const struct cmd_variable_handler bgp_var_neighbor[] = {
18522 : {.varname = "neighbor", .completions = bgp_ac_neighbor},
18523 : {.varname = "neighbors", .completions = bgp_ac_neighbor},
18524 : {.varname = "peer", .completions = bgp_ac_neighbor},
18525 : {.completions = NULL}};
18526 :
18527 : static const struct cmd_variable_handler bgp_var_peergroup[] = {
18528 : {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18529 : {.completions = NULL} };
18530 :
18531 0 : DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18532 :
18533 : static struct thread *t_bgp_cfg;
18534 :
18535 4 : bool bgp_config_inprocess(void)
18536 : {
18537 4 : return thread_is_scheduled(t_bgp_cfg);
18538 : }
18539 :
18540 0 : static void bgp_config_finish(struct thread *t)
18541 : {
18542 0 : struct listnode *node;
18543 0 : struct bgp *bgp;
18544 :
18545 0 : for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18546 0 : hook_call(bgp_config_end, bgp);
18547 0 : }
18548 :
18549 0 : static void bgp_config_start(void)
18550 : {
18551 : #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18552 0 : THREAD_OFF(t_bgp_cfg);
18553 0 : thread_add_timer(bm->master, bgp_config_finish, NULL,
18554 : BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18555 0 : }
18556 :
18557 : /* When we receive a hook the configuration is read,
18558 : * we start a timer to make sure we postpone sending
18559 : * EoR before route-maps are processed.
18560 : * This is especially valid if using `bgp route-map delay-timer`.
18561 : */
18562 0 : static void bgp_config_end(void)
18563 : {
18564 : #define BGP_POST_CONFIG_DELAY_SECONDS 1
18565 0 : uint32_t bgp_post_config_delay =
18566 0 : thread_is_scheduled(bm->t_rmap_update)
18567 0 : ? thread_timer_remain_second(bm->t_rmap_update)
18568 : : BGP_POST_CONFIG_DELAY_SECONDS;
18569 :
18570 : /* If BGP config processing thread isn't running, then
18571 : * we can return and rely it's properly handled.
18572 : */
18573 0 : if (!bgp_config_inprocess())
18574 : return;
18575 :
18576 0 : THREAD_OFF(t_bgp_cfg);
18577 :
18578 : /* Start a new timer to make sure we don't send EoR
18579 : * before route-maps are processed.
18580 : */
18581 0 : thread_add_timer(bm->master, bgp_config_finish, NULL,
18582 : bgp_post_config_delay, &t_bgp_cfg);
18583 : }
18584 :
18585 0 : static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
18586 : {
18587 0 : int write = 0;
18588 0 : struct interface *ifp;
18589 0 : struct bgp_interface *iifp;
18590 :
18591 0 : FOR_ALL_INTERFACES (vrf, ifp) {
18592 0 : iifp = ifp->info;
18593 0 : if (!iifp)
18594 0 : continue;
18595 :
18596 0 : if_vty_config_start(vty, ifp);
18597 :
18598 0 : if (CHECK_FLAG(iifp->flags,
18599 : BGP_INTERFACE_MPLS_BGP_FORWARDING)) {
18600 0 : vty_out(vty, " mpls bgp forwarding\n");
18601 0 : write++;
18602 : }
18603 :
18604 0 : if_vty_config_end(vty);
18605 : }
18606 :
18607 0 : return write;
18608 : }
18609 :
18610 : /* Configuration write function for bgpd. */
18611 0 : static int config_write_interface(struct vty *vty)
18612 : {
18613 0 : int write = 0;
18614 0 : struct vrf *vrf = NULL;
18615 :
18616 : /* Display all VRF aware OSPF interface configuration */
18617 0 : RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
18618 0 : write += config_write_interface_one(vty, vrf);
18619 : }
18620 :
18621 0 : return write;
18622 : }
18623 :
18624 0 : DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd,
18625 : "[no$no] mpls bgp forwarding",
18626 : NO_STR MPLS_STR BGP_STR
18627 : "Enable MPLS forwarding for eBGP directly connected peers\n")
18628 : {
18629 0 : bool check;
18630 0 : struct bgp_interface *iifp;
18631 :
18632 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
18633 0 : iifp = ifp->info;
18634 0 : if (!iifp) {
18635 0 : vty_out(vty, "Interface %s not available\n", ifp->name);
18636 0 : return CMD_WARNING_CONFIG_FAILED;
18637 : }
18638 0 : check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_BGP_FORWARDING);
18639 0 : if (check != !no) {
18640 0 : if (no)
18641 0 : UNSET_FLAG(iifp->flags,
18642 : BGP_INTERFACE_MPLS_BGP_FORWARDING);
18643 : else
18644 0 : SET_FLAG(iifp->flags,
18645 : BGP_INTERFACE_MPLS_BGP_FORWARDING);
18646 : /* trigger a nht update on eBGP sessions */
18647 0 : if (if_is_operative(ifp))
18648 0 : bgp_nht_ifp_up(ifp);
18649 : }
18650 : return CMD_SUCCESS;
18651 : }
18652 :
18653 0 : DEFPY (bgp_inq_limit,
18654 : bgp_inq_limit_cmd,
18655 : "bgp input-queue-limit (1-4294967295)$limit",
18656 : BGP_STR
18657 : "Set the BGP Input Queue limit for all peers when message parsing\n"
18658 : "Input-Queue limit\n")
18659 : {
18660 0 : bm->inq_limit = limit;
18661 :
18662 0 : return CMD_SUCCESS;
18663 : }
18664 :
18665 0 : DEFPY (no_bgp_inq_limit,
18666 : no_bgp_inq_limit_cmd,
18667 : "no bgp input-queue-limit [(1-4294967295)$limit]",
18668 : NO_STR
18669 : BGP_STR
18670 : "Set the BGP Input Queue limit for all peers when message parsing\n"
18671 : "Input-Queue limit\n")
18672 : {
18673 0 : bm->inq_limit = BM_DEFAULT_Q_LIMIT;
18674 :
18675 0 : return CMD_SUCCESS;
18676 : }
18677 :
18678 0 : DEFPY (bgp_outq_limit,
18679 : bgp_outq_limit_cmd,
18680 : "bgp output-queue-limit (1-4294967295)$limit",
18681 : BGP_STR
18682 : "Set the BGP Output Queue limit for all peers when message parsing\n"
18683 : "Output-Queue limit\n")
18684 : {
18685 0 : bm->outq_limit = limit;
18686 :
18687 0 : return CMD_SUCCESS;
18688 : }
18689 :
18690 0 : DEFPY (no_bgp_outq_limit,
18691 : no_bgp_outq_limit_cmd,
18692 : "no bgp output-queue-limit [(1-4294967295)$limit]",
18693 : NO_STR
18694 : BGP_STR
18695 : "Set the BGP Output Queue limit for all peers when message parsing\n"
18696 : "Output-Queue limit\n")
18697 : {
18698 0 : bm->outq_limit = BM_DEFAULT_Q_LIMIT;
18699 :
18700 0 : return CMD_SUCCESS;
18701 : }
18702 :
18703 :
18704 : /* Initialization of BGP interface. */
18705 2 : static void bgp_vty_if_init(void)
18706 : {
18707 : /* Install interface node. */
18708 2 : if_cmd_init(config_write_interface);
18709 :
18710 : /* "mpls bgp forwarding" commands. */
18711 2 : install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd);
18712 2 : }
18713 :
18714 2 : void bgp_vty_init(void)
18715 : {
18716 2 : cmd_variable_handler_register(bgp_var_neighbor);
18717 2 : cmd_variable_handler_register(bgp_var_peergroup);
18718 :
18719 2 : cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18720 :
18721 : /* Install bgp top node. */
18722 2 : install_node(&bgp_node);
18723 2 : install_node(&bgp_ipv4_unicast_node);
18724 2 : install_node(&bgp_ipv4_multicast_node);
18725 2 : install_node(&bgp_ipv4_labeled_unicast_node);
18726 2 : install_node(&bgp_ipv6_unicast_node);
18727 2 : install_node(&bgp_ipv6_multicast_node);
18728 2 : install_node(&bgp_ipv6_labeled_unicast_node);
18729 2 : install_node(&bgp_vpnv4_node);
18730 2 : install_node(&bgp_vpnv6_node);
18731 2 : install_node(&bgp_evpn_node);
18732 2 : install_node(&bgp_evpn_vni_node);
18733 2 : install_node(&bgp_flowspecv4_node);
18734 2 : install_node(&bgp_flowspecv6_node);
18735 2 : install_node(&bgp_srv6_node);
18736 :
18737 : /* Install default VTY commands to new nodes. */
18738 2 : install_default(BGP_NODE);
18739 2 : install_default(BGP_IPV4_NODE);
18740 2 : install_default(BGP_IPV4M_NODE);
18741 2 : install_default(BGP_IPV4L_NODE);
18742 2 : install_default(BGP_IPV6_NODE);
18743 2 : install_default(BGP_IPV6M_NODE);
18744 2 : install_default(BGP_IPV6L_NODE);
18745 2 : install_default(BGP_VPNV4_NODE);
18746 2 : install_default(BGP_VPNV6_NODE);
18747 2 : install_default(BGP_FLOWSPECV4_NODE);
18748 2 : install_default(BGP_FLOWSPECV6_NODE);
18749 2 : install_default(BGP_EVPN_NODE);
18750 2 : install_default(BGP_EVPN_VNI_NODE);
18751 2 : install_default(BGP_SRV6_NODE);
18752 :
18753 : /* "global bgp inq-limit command */
18754 2 : install_element(CONFIG_NODE, &bgp_inq_limit_cmd);
18755 2 : install_element(CONFIG_NODE, &no_bgp_inq_limit_cmd);
18756 2 : install_element(CONFIG_NODE, &bgp_outq_limit_cmd);
18757 2 : install_element(CONFIG_NODE, &no_bgp_outq_limit_cmd);
18758 :
18759 : /* "bgp local-mac" hidden commands. */
18760 2 : install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18761 2 : install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18762 :
18763 : /* "bgp suppress-fib-pending" global */
18764 2 : install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18765 :
18766 : /* bgp route-map delay-timer commands. */
18767 2 : install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18768 2 : install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18769 :
18770 2 : install_element(BGP_NODE, &bgp_allow_martian_cmd);
18771 :
18772 : /* bgp fast-convergence command */
18773 2 : install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18774 2 : install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18775 :
18776 : /* global bgp update-delay command */
18777 2 : install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18778 2 : install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18779 :
18780 : /* global bgp graceful-shutdown command */
18781 2 : install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18782 2 : install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18783 :
18784 : /* Dummy commands (Currently not supported) */
18785 2 : install_element(BGP_NODE, &no_synchronization_cmd);
18786 2 : install_element(BGP_NODE, &no_auto_summary_cmd);
18787 :
18788 : /* "router bgp" commands. */
18789 2 : install_element(CONFIG_NODE, &router_bgp_cmd);
18790 :
18791 : /* "no router bgp" commands. */
18792 2 : install_element(CONFIG_NODE, &no_router_bgp_cmd);
18793 :
18794 : /* "bgp session-dscp command */
18795 2 : install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18796 2 : install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18797 :
18798 : /* "bgp router-id" commands. */
18799 2 : install_element(BGP_NODE, &bgp_router_id_cmd);
18800 2 : install_element(BGP_NODE, &no_bgp_router_id_cmd);
18801 :
18802 : /* "bgp suppress-fib-pending" command */
18803 2 : install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18804 :
18805 : /* "bgp cluster-id" commands. */
18806 2 : install_element(BGP_NODE, &bgp_cluster_id_cmd);
18807 2 : install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18808 :
18809 : /* "bgp no-rib" commands. */
18810 2 : install_element(CONFIG_NODE, &bgp_norib_cmd);
18811 2 : install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18812 :
18813 2 : install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18814 :
18815 : /* "bgp confederation" commands. */
18816 2 : install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18817 2 : install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18818 :
18819 : /* "bgp confederation peers" commands. */
18820 2 : install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18821 2 : install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18822 :
18823 : /* bgp max-med command */
18824 2 : install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18825 2 : install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18826 2 : install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18827 2 : install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18828 2 : install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18829 :
18830 : /* "neighbor role" commands. */
18831 2 : install_element(BGP_NODE, &neighbor_role_cmd);
18832 2 : install_element(BGP_NODE, &neighbor_role_strict_cmd);
18833 2 : install_element(BGP_NODE, &no_neighbor_role_cmd);
18834 :
18835 : /* "neighbor aigp" commands. */
18836 2 : install_element(BGP_NODE, &neighbor_aigp_cmd);
18837 :
18838 : /* "neighbor graceful-shutdown" command */
18839 2 : install_element(BGP_NODE, &neighbor_graceful_shutdown_cmd);
18840 :
18841 : /* bgp disable-ebgp-connected-nh-check */
18842 2 : install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18843 2 : install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18844 :
18845 : /* bgp update-delay command */
18846 2 : install_element(BGP_NODE, &bgp_update_delay_cmd);
18847 2 : install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18848 :
18849 2 : install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18850 2 : install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18851 :
18852 2 : install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18853 2 : install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18854 :
18855 : /* "maximum-paths" commands. */
18856 2 : install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18857 2 : install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18858 2 : install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18859 2 : install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18860 2 : install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18861 2 : install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18862 2 : install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18863 2 : install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18864 2 : install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18865 2 : install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18866 2 : install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18867 2 : install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18868 2 : install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18869 2 : install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18870 2 : install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18871 :
18872 2 : install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18873 2 : install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18874 2 : install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18875 2 : install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18876 2 : install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18877 2 : install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18878 2 : install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18879 2 : install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18880 2 : install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18881 2 : install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18882 :
18883 : /* "timers bgp" commands. */
18884 2 : install_element(BGP_NODE, &bgp_timers_cmd);
18885 2 : install_element(BGP_NODE, &no_bgp_timers_cmd);
18886 :
18887 : /* "minimum-holdtime" commands. */
18888 2 : install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18889 2 : install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18890 :
18891 : /* route-map delay-timer commands - per instance for backwards compat.
18892 : */
18893 2 : install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18894 2 : install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18895 :
18896 : /* "bgp client-to-client reflection" commands */
18897 2 : install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18898 2 : install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18899 :
18900 : /* "bgp always-compare-med" commands */
18901 2 : install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18902 2 : install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18903 :
18904 : /* bgp ebgp-requires-policy */
18905 2 : install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18906 2 : install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18907 :
18908 : /* bgp suppress-duplicates */
18909 2 : install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18910 2 : install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18911 :
18912 : /* bgp reject-as-sets */
18913 2 : install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18914 2 : install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18915 :
18916 : /* "bgp deterministic-med" commands */
18917 2 : install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18918 2 : install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18919 :
18920 : /* "bgp graceful-restart" command */
18921 2 : install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18922 2 : install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18923 :
18924 : /* "bgp graceful-restart-disable" command */
18925 2 : install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18926 2 : install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18927 :
18928 : /* "neighbor a:b:c:d graceful-restart" command */
18929 2 : install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18930 2 : install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18931 :
18932 : /* "neighbor a:b:c:d graceful-restart-disable" command */
18933 2 : install_element(BGP_NODE,
18934 : &bgp_neighbor_graceful_restart_disable_set_cmd);
18935 2 : install_element(BGP_NODE,
18936 : &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18937 :
18938 : /* "neighbor a:b:c:d graceful-restart-helper" command */
18939 2 : install_element(BGP_NODE,
18940 : &bgp_neighbor_graceful_restart_helper_set_cmd);
18941 2 : install_element(BGP_NODE,
18942 : &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18943 :
18944 2 : install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18945 2 : install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18946 2 : install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18947 2 : install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18948 2 : install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18949 2 : install_element(BGP_NODE,
18950 : &no_bgp_graceful_restart_select_defer_time_cmd);
18951 2 : install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18952 2 : install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18953 2 : install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18954 :
18955 2 : install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18956 2 : install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18957 2 : install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18958 2 : install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18959 :
18960 : /* "bgp graceful-shutdown" commands */
18961 2 : install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18962 2 : install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18963 :
18964 : /* "bgp hard-administrative-reset" commands */
18965 2 : install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18966 :
18967 : /* "bgp long-lived-graceful-restart" commands */
18968 2 : install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18969 2 : install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18970 :
18971 : /* "bgp fast-external-failover" commands */
18972 2 : install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18973 2 : install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18974 :
18975 : /* "bgp bestpath aigp" commands */
18976 2 : install_element(BGP_NODE, &bgp_bestpath_aigp_cmd);
18977 :
18978 : /* "bgp bestpath compare-routerid" commands */
18979 2 : install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18980 2 : install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18981 :
18982 : /* "bgp bestpath as-path ignore" commands */
18983 2 : install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18984 2 : install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18985 :
18986 : /* "bgp bestpath as-path confed" commands */
18987 2 : install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18988 2 : install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18989 :
18990 : /* "bgp bestpath as-path multipath-relax" commands */
18991 2 : install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18992 2 : install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18993 :
18994 : /* "bgp bestpath peer-type multipath-relax" commands */
18995 2 : install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18996 2 : install_element(BGP_NODE,
18997 : &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18998 :
18999 : /* "bgp log-neighbor-changes" commands */
19000 2 : install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
19001 2 : install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
19002 :
19003 : /* "bgp bestpath med" commands */
19004 2 : install_element(BGP_NODE, &bgp_bestpath_med_cmd);
19005 2 : install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
19006 :
19007 : /* "bgp bestpath bandwidth" commands */
19008 2 : install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
19009 2 : install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
19010 :
19011 : /* "no bgp default <afi>-<safi>" commands. */
19012 2 : install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
19013 :
19014 : /* "bgp network import-check" commands. */
19015 2 : install_element(BGP_NODE, &bgp_network_import_check_cmd);
19016 2 : install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
19017 2 : install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
19018 :
19019 : /* "bgp default local-preference" commands. */
19020 2 : install_element(BGP_NODE, &bgp_default_local_preference_cmd);
19021 2 : install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
19022 :
19023 : /* bgp default show-hostname */
19024 2 : install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
19025 2 : install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
19026 :
19027 : /* bgp default show-nexthop-hostname */
19028 2 : install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
19029 2 : install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
19030 :
19031 : /* "bgp default subgroup-pkt-queue-max" commands. */
19032 2 : install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
19033 2 : install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
19034 :
19035 : /* bgp ibgp-allow-policy-mods command */
19036 2 : install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
19037 2 : install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
19038 :
19039 : /* "bgp listen limit" commands. */
19040 2 : install_element(BGP_NODE, &bgp_listen_limit_cmd);
19041 2 : install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
19042 :
19043 : /* "bgp listen range" commands. */
19044 2 : install_element(BGP_NODE, &bgp_listen_range_cmd);
19045 2 : install_element(BGP_NODE, &no_bgp_listen_range_cmd);
19046 :
19047 : /* "bgp default shutdown" command */
19048 2 : install_element(BGP_NODE, &bgp_default_shutdown_cmd);
19049 :
19050 : /* "bgp shutdown" commands */
19051 2 : install_element(BGP_NODE, &bgp_shutdown_cmd);
19052 2 : install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
19053 2 : install_element(BGP_NODE, &no_bgp_shutdown_cmd);
19054 2 : install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
19055 :
19056 : /* "neighbor remote-as" commands. */
19057 2 : install_element(BGP_NODE, &neighbor_remote_as_cmd);
19058 2 : install_element(BGP_NODE, &neighbor_interface_config_cmd);
19059 2 : install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
19060 2 : install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
19061 2 : install_element(BGP_NODE,
19062 : &neighbor_interface_v6only_config_remote_as_cmd);
19063 2 : install_element(BGP_NODE, &no_neighbor_cmd);
19064 2 : install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
19065 :
19066 : /* "neighbor peer-group" commands. */
19067 2 : install_element(BGP_NODE, &neighbor_peer_group_cmd);
19068 2 : install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
19069 2 : install_element(BGP_NODE,
19070 : &no_neighbor_interface_peer_group_remote_as_cmd);
19071 :
19072 : /* "neighbor local-as" commands. */
19073 2 : install_element(BGP_NODE, &neighbor_local_as_cmd);
19074 2 : install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
19075 2 : install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
19076 2 : install_element(BGP_NODE, &no_neighbor_local_as_cmd);
19077 :
19078 : /* "neighbor solo" commands. */
19079 2 : install_element(BGP_NODE, &neighbor_solo_cmd);
19080 2 : install_element(BGP_NODE, &no_neighbor_solo_cmd);
19081 :
19082 : /* "neighbor password" commands. */
19083 2 : install_element(BGP_NODE, &neighbor_password_cmd);
19084 2 : install_element(BGP_NODE, &no_neighbor_password_cmd);
19085 :
19086 : /* "neighbor activate" commands. */
19087 2 : install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
19088 2 : install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
19089 2 : install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
19090 2 : install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
19091 2 : install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
19092 2 : install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
19093 2 : install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
19094 2 : install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
19095 2 : install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
19096 2 : install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
19097 2 : install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
19098 2 : install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
19099 :
19100 : /* "no neighbor activate" commands. */
19101 2 : install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
19102 2 : install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
19103 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
19104 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
19105 2 : install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
19106 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
19107 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
19108 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
19109 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
19110 2 : install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
19111 2 : install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
19112 2 : install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
19113 :
19114 : /* "neighbor peer-group" set commands. */
19115 2 : install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
19116 2 : install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19117 2 : install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
19118 2 : install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19119 2 : install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
19120 2 : install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
19121 2 : install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
19122 2 : install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
19123 2 : install_element(BGP_FLOWSPECV4_NODE,
19124 : &neighbor_set_peer_group_hidden_cmd);
19125 2 : install_element(BGP_FLOWSPECV6_NODE,
19126 : &neighbor_set_peer_group_hidden_cmd);
19127 :
19128 : /* "no neighbor peer-group unset" commands. */
19129 2 : install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
19130 2 : install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19131 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19132 2 : install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19133 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19134 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19135 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19136 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
19137 2 : install_element(BGP_FLOWSPECV4_NODE,
19138 : &no_neighbor_set_peer_group_hidden_cmd);
19139 2 : install_element(BGP_FLOWSPECV6_NODE,
19140 : &no_neighbor_set_peer_group_hidden_cmd);
19141 :
19142 : /* "neighbor softreconfiguration inbound" commands.*/
19143 2 : install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
19144 2 : install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
19145 2 : install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
19146 2 : install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19147 2 : install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
19148 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19149 2 : install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
19150 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19151 2 : install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
19152 2 : install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19153 2 : install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
19154 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
19155 2 : install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
19156 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
19157 2 : install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
19158 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
19159 2 : install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
19160 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
19161 2 : install_element(BGP_FLOWSPECV4_NODE,
19162 : &neighbor_soft_reconfiguration_cmd);
19163 2 : install_element(BGP_FLOWSPECV4_NODE,
19164 : &no_neighbor_soft_reconfiguration_cmd);
19165 2 : install_element(BGP_FLOWSPECV6_NODE,
19166 : &neighbor_soft_reconfiguration_cmd);
19167 2 : install_element(BGP_FLOWSPECV6_NODE,
19168 : &no_neighbor_soft_reconfiguration_cmd);
19169 2 : install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
19170 2 : install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
19171 :
19172 : /* "neighbor attribute-unchanged" commands. */
19173 2 : install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
19174 2 : install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
19175 2 : install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
19176 2 : install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
19177 2 : install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
19178 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
19179 2 : install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
19180 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
19181 2 : install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
19182 2 : install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
19183 2 : install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
19184 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
19185 2 : install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
19186 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
19187 2 : install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
19188 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
19189 2 : install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
19190 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
19191 :
19192 2 : install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
19193 2 : install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
19194 :
19195 2 : install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
19196 2 : install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
19197 2 : install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
19198 2 : install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
19199 :
19200 : /* "nexthop-local unchanged" commands */
19201 2 : install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
19202 2 : install_element(BGP_IPV6_NODE,
19203 : &no_neighbor_nexthop_local_unchanged_cmd);
19204 :
19205 : /* "neighbor next-hop-self" commands. */
19206 2 : install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
19207 2 : install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
19208 2 : install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
19209 2 : install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
19210 2 : install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
19211 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
19212 2 : install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
19213 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
19214 2 : install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
19215 2 : install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
19216 2 : install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
19217 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
19218 2 : install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
19219 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
19220 2 : install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
19221 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
19222 2 : install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
19223 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
19224 2 : install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
19225 2 : install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
19226 :
19227 : /* "neighbor next-hop-self force" commands. */
19228 2 : install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
19229 2 : install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
19230 2 : install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19231 2 : install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
19232 2 : install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
19233 2 : install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19234 2 : install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19235 2 : install_element(BGP_IPV4_NODE,
19236 : &no_neighbor_nexthop_self_all_hidden_cmd);
19237 2 : install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
19238 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
19239 2 : install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19240 2 : install_element(BGP_IPV4M_NODE,
19241 : &no_neighbor_nexthop_self_all_hidden_cmd);
19242 2 : install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
19243 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
19244 2 : install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19245 2 : install_element(BGP_IPV4L_NODE,
19246 : &no_neighbor_nexthop_self_all_hidden_cmd);
19247 2 : install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
19248 2 : install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19249 2 : install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19250 2 : install_element(BGP_IPV6_NODE,
19251 : &no_neighbor_nexthop_self_all_hidden_cmd);
19252 2 : install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
19253 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
19254 2 : install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19255 2 : install_element(BGP_IPV6M_NODE,
19256 : &no_neighbor_nexthop_self_all_hidden_cmd);
19257 2 : install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
19258 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
19259 2 : install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19260 2 : install_element(BGP_IPV6L_NODE,
19261 : &no_neighbor_nexthop_self_all_hidden_cmd);
19262 2 : install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
19263 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
19264 2 : install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19265 2 : install_element(BGP_VPNV4_NODE,
19266 : &no_neighbor_nexthop_self_all_hidden_cmd);
19267 2 : install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
19268 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
19269 2 : install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
19270 2 : install_element(BGP_VPNV6_NODE,
19271 : &no_neighbor_nexthop_self_all_hidden_cmd);
19272 2 : install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
19273 2 : install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
19274 :
19275 : /* "neighbor as-override" commands. */
19276 2 : install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
19277 2 : install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
19278 2 : install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
19279 2 : install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
19280 2 : install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
19281 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
19282 2 : install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
19283 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
19284 2 : install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
19285 2 : install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
19286 2 : install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
19287 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
19288 2 : install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
19289 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
19290 2 : install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
19291 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
19292 2 : install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
19293 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
19294 :
19295 : /* "neighbor remove-private-AS" commands. */
19296 2 : install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
19297 2 : install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
19298 2 : install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
19299 2 : install_element(BGP_NODE,
19300 : &no_neighbor_remove_private_as_all_hidden_cmd);
19301 2 : install_element(BGP_NODE,
19302 : &neighbor_remove_private_as_replace_as_hidden_cmd);
19303 2 : install_element(BGP_NODE,
19304 : &no_neighbor_remove_private_as_replace_as_hidden_cmd);
19305 2 : install_element(BGP_NODE,
19306 : &neighbor_remove_private_as_all_replace_as_hidden_cmd);
19307 2 : install_element(
19308 : BGP_NODE,
19309 : &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
19310 2 : install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
19311 2 : install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
19312 2 : install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
19313 2 : install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19314 2 : install_element(BGP_IPV4_NODE,
19315 : &neighbor_remove_private_as_replace_as_cmd);
19316 2 : install_element(BGP_IPV4_NODE,
19317 : &no_neighbor_remove_private_as_replace_as_cmd);
19318 2 : install_element(BGP_IPV4_NODE,
19319 : &neighbor_remove_private_as_all_replace_as_cmd);
19320 2 : install_element(BGP_IPV4_NODE,
19321 : &no_neighbor_remove_private_as_all_replace_as_cmd);
19322 2 : install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
19323 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
19324 2 : install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
19325 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
19326 2 : install_element(BGP_IPV4M_NODE,
19327 : &neighbor_remove_private_as_replace_as_cmd);
19328 2 : install_element(BGP_IPV4M_NODE,
19329 : &no_neighbor_remove_private_as_replace_as_cmd);
19330 2 : install_element(BGP_IPV4M_NODE,
19331 : &neighbor_remove_private_as_all_replace_as_cmd);
19332 2 : install_element(BGP_IPV4M_NODE,
19333 : &no_neighbor_remove_private_as_all_replace_as_cmd);
19334 2 : install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
19335 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
19336 2 : install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
19337 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
19338 2 : install_element(BGP_IPV4L_NODE,
19339 : &neighbor_remove_private_as_replace_as_cmd);
19340 2 : install_element(BGP_IPV4L_NODE,
19341 : &no_neighbor_remove_private_as_replace_as_cmd);
19342 2 : install_element(BGP_IPV4L_NODE,
19343 : &neighbor_remove_private_as_all_replace_as_cmd);
19344 2 : install_element(BGP_IPV4L_NODE,
19345 : &no_neighbor_remove_private_as_all_replace_as_cmd);
19346 2 : install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
19347 2 : install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
19348 2 : install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
19349 2 : install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19350 2 : install_element(BGP_IPV6_NODE,
19351 : &neighbor_remove_private_as_replace_as_cmd);
19352 2 : install_element(BGP_IPV6_NODE,
19353 : &no_neighbor_remove_private_as_replace_as_cmd);
19354 2 : install_element(BGP_IPV6_NODE,
19355 : &neighbor_remove_private_as_all_replace_as_cmd);
19356 2 : install_element(BGP_IPV6_NODE,
19357 : &no_neighbor_remove_private_as_all_replace_as_cmd);
19358 2 : install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
19359 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
19360 2 : install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
19361 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
19362 2 : install_element(BGP_IPV6M_NODE,
19363 : &neighbor_remove_private_as_replace_as_cmd);
19364 2 : install_element(BGP_IPV6M_NODE,
19365 : &no_neighbor_remove_private_as_replace_as_cmd);
19366 2 : install_element(BGP_IPV6M_NODE,
19367 : &neighbor_remove_private_as_all_replace_as_cmd);
19368 2 : install_element(BGP_IPV6M_NODE,
19369 : &no_neighbor_remove_private_as_all_replace_as_cmd);
19370 2 : install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
19371 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
19372 2 : install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
19373 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
19374 2 : install_element(BGP_IPV6L_NODE,
19375 : &neighbor_remove_private_as_replace_as_cmd);
19376 2 : install_element(BGP_IPV6L_NODE,
19377 : &no_neighbor_remove_private_as_replace_as_cmd);
19378 2 : install_element(BGP_IPV6L_NODE,
19379 : &neighbor_remove_private_as_all_replace_as_cmd);
19380 2 : install_element(BGP_IPV6L_NODE,
19381 : &no_neighbor_remove_private_as_all_replace_as_cmd);
19382 2 : install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
19383 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
19384 2 : install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
19385 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
19386 2 : install_element(BGP_VPNV4_NODE,
19387 : &neighbor_remove_private_as_replace_as_cmd);
19388 2 : install_element(BGP_VPNV4_NODE,
19389 : &no_neighbor_remove_private_as_replace_as_cmd);
19390 2 : install_element(BGP_VPNV4_NODE,
19391 : &neighbor_remove_private_as_all_replace_as_cmd);
19392 2 : install_element(BGP_VPNV4_NODE,
19393 : &no_neighbor_remove_private_as_all_replace_as_cmd);
19394 2 : install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
19395 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
19396 2 : install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
19397 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
19398 2 : install_element(BGP_VPNV6_NODE,
19399 : &neighbor_remove_private_as_replace_as_cmd);
19400 2 : install_element(BGP_VPNV6_NODE,
19401 : &no_neighbor_remove_private_as_replace_as_cmd);
19402 2 : install_element(BGP_VPNV6_NODE,
19403 : &neighbor_remove_private_as_all_replace_as_cmd);
19404 2 : install_element(BGP_VPNV6_NODE,
19405 : &no_neighbor_remove_private_as_all_replace_as_cmd);
19406 :
19407 : /* "neighbor send-community" commands.*/
19408 2 : install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
19409 2 : install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
19410 2 : install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
19411 2 : install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
19412 2 : install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
19413 2 : install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
19414 2 : install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
19415 2 : install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
19416 2 : install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
19417 2 : install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
19418 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
19419 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
19420 2 : install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
19421 2 : install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
19422 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
19423 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
19424 2 : install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
19425 2 : install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
19426 2 : install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
19427 2 : install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
19428 2 : install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
19429 2 : install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
19430 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
19431 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
19432 2 : install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
19433 2 : install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
19434 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
19435 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
19436 2 : install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
19437 2 : install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
19438 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
19439 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
19440 2 : install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
19441 2 : install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
19442 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
19443 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
19444 :
19445 : /* "neighbor route-reflector" commands.*/
19446 2 : install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
19447 2 : install_element(BGP_NODE,
19448 : &no_neighbor_route_reflector_client_hidden_cmd);
19449 2 : install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
19450 2 : install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
19451 2 : install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
19452 2 : install_element(BGP_IPV4M_NODE,
19453 : &no_neighbor_route_reflector_client_cmd);
19454 2 : install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
19455 2 : install_element(BGP_IPV4L_NODE,
19456 : &no_neighbor_route_reflector_client_cmd);
19457 2 : install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
19458 2 : install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
19459 2 : install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
19460 2 : install_element(BGP_IPV6M_NODE,
19461 : &no_neighbor_route_reflector_client_cmd);
19462 2 : install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
19463 2 : install_element(BGP_IPV6L_NODE,
19464 : &no_neighbor_route_reflector_client_cmd);
19465 2 : install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
19466 2 : install_element(BGP_VPNV4_NODE,
19467 : &no_neighbor_route_reflector_client_cmd);
19468 2 : install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
19469 2 : install_element(BGP_VPNV6_NODE,
19470 : &no_neighbor_route_reflector_client_cmd);
19471 2 : install_element(BGP_FLOWSPECV4_NODE,
19472 : &neighbor_route_reflector_client_cmd);
19473 2 : install_element(BGP_FLOWSPECV4_NODE,
19474 : &no_neighbor_route_reflector_client_cmd);
19475 2 : install_element(BGP_FLOWSPECV6_NODE,
19476 : &neighbor_route_reflector_client_cmd);
19477 2 : install_element(BGP_FLOWSPECV6_NODE,
19478 : &no_neighbor_route_reflector_client_cmd);
19479 2 : install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
19480 2 : install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
19481 :
19482 : /* "neighbor route-server" commands.*/
19483 2 : install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
19484 2 : install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
19485 2 : install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
19486 2 : install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
19487 2 : install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
19488 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
19489 2 : install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
19490 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
19491 2 : install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
19492 2 : install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
19493 2 : install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
19494 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
19495 2 : install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
19496 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
19497 2 : install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
19498 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
19499 2 : install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
19500 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
19501 2 : install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
19502 2 : install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
19503 2 : install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
19504 2 : install_element(BGP_FLOWSPECV4_NODE,
19505 : &no_neighbor_route_server_client_cmd);
19506 2 : install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
19507 2 : install_element(BGP_FLOWSPECV6_NODE,
19508 : &no_neighbor_route_server_client_cmd);
19509 :
19510 : /* "neighbor disable-addpath-rx" commands. */
19511 2 : install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
19512 2 : install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19513 2 : install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
19514 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19515 2 : install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
19516 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19517 2 : install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
19518 2 : install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19519 2 : install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
19520 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
19521 2 : install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
19522 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
19523 2 : install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
19524 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
19525 2 : install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
19526 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
19527 :
19528 : /* "neighbor addpath-tx-all-paths" commands.*/
19529 2 : install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
19530 2 : install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
19531 2 : install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19532 2 : install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19533 2 : install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19534 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19535 2 : install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19536 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19537 2 : install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19538 2 : install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19539 2 : install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
19540 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19541 2 : install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
19542 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19543 2 : install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
19544 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19545 2 : install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
19546 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
19547 :
19548 : /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
19549 2 : install_element(BGP_NODE,
19550 : &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19551 2 : install_element(BGP_NODE,
19552 : &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
19553 2 : install_element(BGP_IPV4_NODE,
19554 : &neighbor_addpath_tx_bestpath_per_as_cmd);
19555 2 : install_element(BGP_IPV4_NODE,
19556 : &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19557 2 : install_element(BGP_IPV4M_NODE,
19558 : &neighbor_addpath_tx_bestpath_per_as_cmd);
19559 2 : install_element(BGP_IPV4M_NODE,
19560 : &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19561 2 : install_element(BGP_IPV4L_NODE,
19562 : &neighbor_addpath_tx_bestpath_per_as_cmd);
19563 2 : install_element(BGP_IPV4L_NODE,
19564 : &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19565 2 : install_element(BGP_IPV6_NODE,
19566 : &neighbor_addpath_tx_bestpath_per_as_cmd);
19567 2 : install_element(BGP_IPV6_NODE,
19568 : &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19569 2 : install_element(BGP_IPV6M_NODE,
19570 : &neighbor_addpath_tx_bestpath_per_as_cmd);
19571 2 : install_element(BGP_IPV6M_NODE,
19572 : &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19573 2 : install_element(BGP_IPV6L_NODE,
19574 : &neighbor_addpath_tx_bestpath_per_as_cmd);
19575 2 : install_element(BGP_IPV6L_NODE,
19576 : &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19577 2 : install_element(BGP_VPNV4_NODE,
19578 : &neighbor_addpath_tx_bestpath_per_as_cmd);
19579 2 : install_element(BGP_VPNV4_NODE,
19580 : &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19581 2 : install_element(BGP_VPNV6_NODE,
19582 : &neighbor_addpath_tx_bestpath_per_as_cmd);
19583 2 : install_element(BGP_VPNV6_NODE,
19584 : &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19585 :
19586 : /* "neighbor sender-as-path-loop-detection" commands. */
19587 2 : install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19588 2 : install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19589 :
19590 : /* "neighbor path-attribute discard" commands. */
19591 2 : install_element(BGP_NODE, &neighbor_path_attribute_discard_cmd);
19592 2 : install_element(BGP_NODE, &no_neighbor_path_attribute_discard_cmd);
19593 :
19594 : /* "neighbor passive" commands. */
19595 2 : install_element(BGP_NODE, &neighbor_passive_cmd);
19596 2 : install_element(BGP_NODE, &no_neighbor_passive_cmd);
19597 :
19598 :
19599 : /* "neighbor shutdown" commands. */
19600 2 : install_element(BGP_NODE, &neighbor_shutdown_cmd);
19601 2 : install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19602 2 : install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19603 2 : install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
19604 2 : install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19605 2 : install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
19606 :
19607 : /* "neighbor capability extended-nexthop" commands.*/
19608 2 : install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19609 2 : install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19610 :
19611 : /* "neighbor capability orf prefix-list" commands.*/
19612 2 : install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19613 2 : install_element(BGP_NODE,
19614 : &no_neighbor_capability_orf_prefix_hidden_cmd);
19615 2 : install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19616 2 : install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19617 2 : install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19618 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19619 2 : install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19620 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19621 2 : install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19622 2 : install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19623 2 : install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19624 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19625 2 : install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19626 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19627 :
19628 : /* "neighbor capability dynamic" commands.*/
19629 2 : install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19630 2 : install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19631 :
19632 : /* "neighbor dont-capability-negotiate" commands. */
19633 2 : install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19634 2 : install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19635 :
19636 : /* "neighbor ebgp-multihop" commands. */
19637 2 : install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19638 2 : install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19639 2 : install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19640 :
19641 : /* "neighbor disable-connected-check" commands. */
19642 2 : install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19643 2 : install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19644 :
19645 : /* "neighbor disable-link-bw-encoding-ieee" commands. */
19646 2 : install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19647 2 : install_element(BGP_NODE,
19648 : &no_neighbor_disable_link_bw_encoding_ieee_cmd);
19649 :
19650 : /* "neighbor extended-optional-parameters" commands. */
19651 2 : install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19652 2 : install_element(BGP_NODE,
19653 : &no_neighbor_extended_optional_parameters_cmd);
19654 :
19655 : /* "neighbor enforce-first-as" commands. */
19656 2 : install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19657 2 : install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19658 :
19659 : /* "neighbor description" commands. */
19660 2 : install_element(BGP_NODE, &neighbor_description_cmd);
19661 2 : install_element(BGP_NODE, &no_neighbor_description_cmd);
19662 2 : install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
19663 :
19664 : /* "neighbor update-source" commands. "*/
19665 2 : install_element(BGP_NODE, &neighbor_update_source_cmd);
19666 2 : install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19667 :
19668 : /* "neighbor default-originate" commands. */
19669 2 : install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19670 2 : install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19671 2 : install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19672 2 : install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19673 2 : install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19674 2 : install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19675 2 : install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19676 2 : install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19677 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19678 2 : install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19679 2 : install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19680 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19681 2 : install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19682 2 : install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19683 2 : install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19684 2 : install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19685 2 : install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19686 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19687 2 : install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19688 2 : install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19689 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19690 :
19691 : /* "neighbor port" commands. */
19692 2 : install_element(BGP_NODE, &neighbor_port_cmd);
19693 2 : install_element(BGP_NODE, &no_neighbor_port_cmd);
19694 :
19695 : /* "neighbor weight" commands. */
19696 2 : install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19697 2 : install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19698 :
19699 2 : install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19700 2 : install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19701 2 : install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19702 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19703 2 : install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19704 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19705 2 : install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19706 2 : install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19707 2 : install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19708 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19709 2 : install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19710 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19711 2 : install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19712 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19713 2 : install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19714 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19715 :
19716 : /* "neighbor override-capability" commands. */
19717 2 : install_element(BGP_NODE, &neighbor_override_capability_cmd);
19718 2 : install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19719 :
19720 : /* "neighbor strict-capability-match" commands. */
19721 2 : install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19722 2 : install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19723 :
19724 : /* "neighbor timers" commands. */
19725 2 : install_element(BGP_NODE, &neighbor_timers_cmd);
19726 2 : install_element(BGP_NODE, &no_neighbor_timers_cmd);
19727 :
19728 : /* "neighbor timers connect" commands. */
19729 2 : install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19730 2 : install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19731 :
19732 : /* "neighbor timers delayopen" commands. */
19733 2 : install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19734 2 : install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19735 :
19736 : /* "neighbor advertisement-interval" commands. */
19737 2 : install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19738 2 : install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19739 :
19740 : /* "neighbor interface" commands. */
19741 2 : install_element(BGP_NODE, &neighbor_interface_cmd);
19742 2 : install_element(BGP_NODE, &no_neighbor_interface_cmd);
19743 :
19744 : /* "neighbor distribute" commands. */
19745 2 : install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19746 2 : install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19747 2 : install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19748 2 : install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19749 2 : install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19750 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19751 2 : install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19752 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19753 2 : install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19754 2 : install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19755 2 : install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19756 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19757 2 : install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19758 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19759 2 : install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19760 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19761 2 : install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19762 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19763 :
19764 : /* "neighbor prefix-list" commands. */
19765 2 : install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19766 2 : install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19767 2 : install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19768 2 : install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19769 2 : install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19770 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19771 2 : install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19772 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19773 2 : install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19774 2 : install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19775 2 : install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19776 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19777 2 : install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19778 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19779 2 : install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19780 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19781 2 : install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19782 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19783 2 : install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19784 2 : install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19785 2 : install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19786 2 : install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19787 :
19788 : /* "neighbor filter-list" commands. */
19789 2 : install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19790 2 : install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19791 2 : install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19792 2 : install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19793 2 : install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19794 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19795 2 : install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19796 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19797 2 : install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19798 2 : install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19799 2 : install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19800 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19801 2 : install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19802 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19803 2 : install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19804 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19805 2 : install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19806 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19807 2 : install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19808 2 : install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19809 2 : install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19810 2 : install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19811 :
19812 : /* "neighbor route-map" commands. */
19813 2 : install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19814 2 : install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19815 2 : install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19816 2 : install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19817 2 : install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19818 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19819 2 : install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19820 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19821 2 : install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19822 2 : install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19823 2 : install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19824 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19825 2 : install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19826 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19827 2 : install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19828 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19829 2 : install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19830 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19831 2 : install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19832 2 : install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19833 2 : install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19834 2 : install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19835 2 : install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19836 2 : install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19837 :
19838 : /* "neighbor unsuppress-map" commands. */
19839 2 : install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19840 2 : install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19841 2 : install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19842 2 : install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19843 2 : install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19844 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19845 2 : install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19846 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19847 2 : install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19848 2 : install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19849 2 : install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19850 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19851 2 : install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19852 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19853 2 : install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19854 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19855 2 : install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19856 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19857 :
19858 : /* "neighbor advertise-map" commands. */
19859 2 : install_element(BGP_NODE, &bgp_condadv_period_cmd);
19860 2 : install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19861 2 : install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19862 2 : install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19863 2 : install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19864 2 : install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19865 2 : install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19866 2 : install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19867 2 : install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19868 2 : install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19869 :
19870 : /* neighbor maximum-prefix-out commands. */
19871 2 : install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19872 2 : install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19873 2 : install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19874 2 : install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19875 2 : install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19876 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19877 2 : install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19878 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19879 2 : install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19880 2 : install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19881 2 : install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19882 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19883 2 : install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19884 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19885 2 : install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19886 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19887 2 : install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19888 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19889 :
19890 : /* "neighbor maximum-prefix" commands. */
19891 2 : install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19892 2 : install_element(BGP_NODE,
19893 : &neighbor_maximum_prefix_threshold_hidden_cmd);
19894 2 : install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19895 2 : install_element(BGP_NODE,
19896 : &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19897 2 : install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19898 2 : install_element(BGP_NODE,
19899 : &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19900 2 : install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19901 2 : install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19902 2 : install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19903 2 : install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19904 2 : install_element(BGP_IPV4_NODE,
19905 : &neighbor_maximum_prefix_threshold_warning_cmd);
19906 2 : install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19907 2 : install_element(BGP_IPV4_NODE,
19908 : &neighbor_maximum_prefix_threshold_restart_cmd);
19909 2 : install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19910 2 : install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19911 2 : install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19912 2 : install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19913 2 : install_element(BGP_IPV4M_NODE,
19914 : &neighbor_maximum_prefix_threshold_warning_cmd);
19915 2 : install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19916 2 : install_element(BGP_IPV4M_NODE,
19917 : &neighbor_maximum_prefix_threshold_restart_cmd);
19918 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19919 2 : install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19920 2 : install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19921 2 : install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19922 2 : install_element(BGP_IPV4L_NODE,
19923 : &neighbor_maximum_prefix_threshold_warning_cmd);
19924 2 : install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19925 2 : install_element(BGP_IPV4L_NODE,
19926 : &neighbor_maximum_prefix_threshold_restart_cmd);
19927 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19928 2 : install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19929 2 : install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19930 2 : install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19931 2 : install_element(BGP_IPV6_NODE,
19932 : &neighbor_maximum_prefix_threshold_warning_cmd);
19933 2 : install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19934 2 : install_element(BGP_IPV6_NODE,
19935 : &neighbor_maximum_prefix_threshold_restart_cmd);
19936 2 : install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19937 2 : install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19938 2 : install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19939 2 : install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19940 2 : install_element(BGP_IPV6M_NODE,
19941 : &neighbor_maximum_prefix_threshold_warning_cmd);
19942 2 : install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19943 2 : install_element(BGP_IPV6M_NODE,
19944 : &neighbor_maximum_prefix_threshold_restart_cmd);
19945 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19946 2 : install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19947 2 : install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19948 2 : install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19949 2 : install_element(BGP_IPV6L_NODE,
19950 : &neighbor_maximum_prefix_threshold_warning_cmd);
19951 2 : install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19952 2 : install_element(BGP_IPV6L_NODE,
19953 : &neighbor_maximum_prefix_threshold_restart_cmd);
19954 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19955 2 : install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19956 2 : install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19957 2 : install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19958 2 : install_element(BGP_VPNV4_NODE,
19959 : &neighbor_maximum_prefix_threshold_warning_cmd);
19960 2 : install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19961 2 : install_element(BGP_VPNV4_NODE,
19962 : &neighbor_maximum_prefix_threshold_restart_cmd);
19963 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19964 2 : install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19965 2 : install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19966 2 : install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19967 2 : install_element(BGP_VPNV6_NODE,
19968 : &neighbor_maximum_prefix_threshold_warning_cmd);
19969 2 : install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19970 2 : install_element(BGP_VPNV6_NODE,
19971 : &neighbor_maximum_prefix_threshold_restart_cmd);
19972 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19973 :
19974 : /* "neighbor allowas-in" */
19975 2 : install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19976 2 : install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19977 2 : install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19978 2 : install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19979 2 : install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19980 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19981 2 : install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19982 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19983 2 : install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19984 2 : install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19985 2 : install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19986 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19987 2 : install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19988 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19989 2 : install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19990 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19991 2 : install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19992 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19993 2 : install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19994 2 : install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19995 :
19996 : /* neighbor accept-own */
19997 2 : install_element(BGP_VPNV4_NODE, &neighbor_accept_own_cmd);
19998 2 : install_element(BGP_VPNV6_NODE, &neighbor_accept_own_cmd);
19999 :
20000 : /* "neighbor soo" */
20001 2 : install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
20002 2 : install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
20003 2 : install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
20004 2 : install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
20005 2 : install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
20006 2 : install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
20007 2 : install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
20008 2 : install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
20009 2 : install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
20010 2 : install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
20011 2 : install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
20012 2 : install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
20013 2 : install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
20014 2 : install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
20015 2 : install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
20016 2 : install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
20017 2 : install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
20018 2 : install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
20019 :
20020 : /* address-family commands. */
20021 2 : install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
20022 2 : install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
20023 : #ifdef KEEP_OLD_VPN_COMMANDS
20024 : install_element(BGP_NODE, &address_family_vpnv4_cmd);
20025 : install_element(BGP_NODE, &address_family_vpnv6_cmd);
20026 : #endif /* KEEP_OLD_VPN_COMMANDS */
20027 :
20028 2 : install_element(BGP_NODE, &address_family_evpn_cmd);
20029 :
20030 : /* "exit-address-family" command. */
20031 2 : install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
20032 2 : install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
20033 2 : install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
20034 2 : install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
20035 2 : install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
20036 2 : install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
20037 2 : install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
20038 2 : install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
20039 2 : install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
20040 2 : install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
20041 2 : install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
20042 :
20043 : /* BGP retain all route-target */
20044 2 : install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
20045 2 : install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
20046 :
20047 : /* "clear ip bgp commands" */
20048 2 : install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
20049 :
20050 : /* clear ip bgp prefix */
20051 2 : install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
20052 2 : install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
20053 2 : install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
20054 :
20055 : /* "show [ip] bgp summary" commands. */
20056 2 : install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
20057 2 : install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
20058 2 : install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
20059 2 : install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
20060 2 : install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
20061 2 : install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
20062 2 : install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
20063 :
20064 : /* "show [ip] bgp neighbors" commands. */
20065 2 : install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
20066 :
20067 2 : install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
20068 :
20069 : /* "show [ip] bgp peer-group" commands. */
20070 2 : install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
20071 :
20072 : /* "show [ip] bgp paths" commands. */
20073 2 : install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
20074 :
20075 : /* "show [ip] bgp community" commands. */
20076 2 : install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
20077 :
20078 : /* "show ip bgp large-community" commands. */
20079 2 : install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
20080 : /* "show [ip] bgp attribute-info" commands. */
20081 2 : install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
20082 : /* "show [ip] bgp route-leak" command */
20083 2 : install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
20084 :
20085 : /* "redistribute" commands. */
20086 2 : install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
20087 2 : install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
20088 2 : install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
20089 2 : install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
20090 2 : install_element(BGP_NODE,
20091 : &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
20092 2 : install_element(BGP_NODE,
20093 : &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
20094 2 : install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
20095 2 : install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
20096 2 : install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
20097 2 : install_element(BGP_NODE,
20098 : &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
20099 2 : install_element(BGP_NODE,
20100 : &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
20101 2 : install_element(BGP_NODE,
20102 : &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
20103 2 : install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
20104 2 : install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
20105 2 : install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
20106 2 : install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
20107 2 : install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
20108 2 : install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
20109 2 : install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
20110 2 : install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
20111 2 : install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
20112 2 : install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
20113 2 : install_element(BGP_IPV4_NODE,
20114 : &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
20115 2 : install_element(BGP_IPV4_NODE,
20116 : &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
20117 2 : install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
20118 2 : install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
20119 2 : install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
20120 2 : install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
20121 2 : install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
20122 2 : install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
20123 :
20124 : /* import|export vpn [route-map RMAP_NAME] */
20125 2 : install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
20126 2 : install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
20127 :
20128 2 : install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
20129 2 : install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
20130 :
20131 : /* ttl_security commands */
20132 2 : install_element(BGP_NODE, &neighbor_ttl_security_cmd);
20133 2 : install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
20134 :
20135 : /* "bgp tcp-keepalive" commands */
20136 2 : install_element(BGP_NODE, &bgp_tcp_keepalive_cmd);
20137 2 : install_element(BGP_NODE, &no_bgp_tcp_keepalive_cmd);
20138 :
20139 : /* "show [ip] bgp memory" commands. */
20140 2 : install_element(VIEW_NODE, &show_bgp_memory_cmd);
20141 :
20142 : /* "show bgp martian next-hop" */
20143 2 : install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
20144 :
20145 2 : install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
20146 :
20147 : /* "show [ip] bgp views" commands. */
20148 2 : install_element(VIEW_NODE, &show_bgp_views_cmd);
20149 :
20150 : /* "show [ip] bgp vrfs" commands. */
20151 2 : install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
20152 :
20153 : /* Community-list. */
20154 2 : community_list_vty();
20155 :
20156 2 : community_alias_vty();
20157 :
20158 : /* vpn-policy commands */
20159 2 : install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
20160 2 : install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
20161 2 : install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
20162 2 : install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
20163 2 : install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
20164 2 : install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
20165 2 : install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
20166 2 : install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
20167 2 : install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
20168 2 : install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
20169 2 : install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
20170 2 : install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
20171 :
20172 2 : install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
20173 2 : install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
20174 :
20175 2 : install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
20176 2 : install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
20177 2 : install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
20178 2 : install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
20179 2 : install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
20180 2 : install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
20181 2 : install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
20182 2 : install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
20183 2 : install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
20184 2 : install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
20185 :
20186 : /* tcp-mss command */
20187 2 : install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
20188 2 : install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
20189 :
20190 : /* srv6 commands */
20191 2 : install_element(VIEW_NODE, &show_bgp_srv6_cmd);
20192 2 : install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
20193 2 : install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
20194 2 : install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
20195 2 : install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
20196 2 : install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
20197 2 : install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
20198 2 : install_element(BGP_NODE, &bgp_sid_vpn_export_cmd);
20199 2 : install_element(BGP_NODE, &no_bgp_sid_vpn_export_cmd);
20200 :
20201 2 : bgp_vty_if_init();
20202 2 : }
20203 :
20204 : #include "memory.h"
20205 : #include "bgp_regex.h"
20206 : #include "bgp_clist.h"
20207 : #include "bgp_ecommunity.h"
20208 :
20209 : /* VTY functions. */
20210 :
20211 : /* Direction value to string conversion. */
20212 0 : static const char *community_direct_str(int direct)
20213 : {
20214 0 : switch (direct) {
20215 : case COMMUNITY_DENY:
20216 : return "deny";
20217 0 : case COMMUNITY_PERMIT:
20218 0 : return "permit";
20219 0 : default:
20220 0 : return "unknown";
20221 : }
20222 : }
20223 :
20224 : /* Display error string. */
20225 0 : static void community_list_perror(struct vty *vty, int ret)
20226 : {
20227 0 : switch (ret) {
20228 0 : case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
20229 0 : vty_out(vty, "%% Can't find community-list\n");
20230 0 : break;
20231 0 : case COMMUNITY_LIST_ERR_MALFORMED_VAL:
20232 0 : vty_out(vty, "%% Malformed community-list value\n");
20233 0 : break;
20234 0 : case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
20235 0 : vty_out(vty,
20236 : "%% Community name conflict, previously defined as standard community\n");
20237 0 : break;
20238 0 : case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
20239 0 : vty_out(vty,
20240 : "%% Community name conflict, previously defined as expanded community\n");
20241 0 : break;
20242 : }
20243 0 : }
20244 :
20245 : /* "community-list" keyword help string. */
20246 : #define COMMUNITY_LIST_STR "Add a community list entry\n"
20247 :
20248 : /*community-list standard */
20249 0 : DEFUN (community_list_standard,
20250 : bgp_community_list_standard_cmd,
20251 : "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20252 : BGP_STR
20253 : COMMUNITY_LIST_STR
20254 : "Community list number (standard)\n"
20255 : "Add an standard community-list entry\n"
20256 : "Community list name\n"
20257 : "Sequence number of an entry\n"
20258 : "Sequence number\n"
20259 : "Specify community to reject\n"
20260 : "Specify community to accept\n"
20261 : COMMUNITY_VAL_STR)
20262 : {
20263 0 : char *cl_name_or_number = NULL;
20264 0 : char *seq = NULL;
20265 0 : int direct = 0;
20266 0 : int style = COMMUNITY_LIST_STANDARD;
20267 0 : int idx = 0;
20268 :
20269 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
20270 0 : seq = argv[idx]->arg;
20271 :
20272 0 : idx = 0;
20273 0 : argv_find(argv, argc, "(1-99)", &idx);
20274 0 : argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20275 0 : cl_name_or_number = argv[idx]->arg;
20276 0 : direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20277 0 : : COMMUNITY_DENY;
20278 0 : argv_find(argv, argc, "AA:NN", &idx);
20279 0 : char *str = argv_concat(argv, argc, idx);
20280 :
20281 0 : int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20282 : direct, style);
20283 :
20284 0 : XFREE(MTYPE_TMP, str);
20285 :
20286 0 : if (ret < 0) {
20287 : /* Display error string. */
20288 0 : community_list_perror(vty, ret);
20289 0 : return CMD_WARNING_CONFIG_FAILED;
20290 : }
20291 :
20292 : return CMD_SUCCESS;
20293 : }
20294 :
20295 0 : DEFUN (no_community_list_standard_all,
20296 : no_bgp_community_list_standard_all_cmd,
20297 : "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20298 : NO_STR
20299 : BGP_STR
20300 : COMMUNITY_LIST_STR
20301 : "Community list number (standard)\n"
20302 : "Add an standard community-list entry\n"
20303 : "Community list name\n"
20304 : "Sequence number of an entry\n"
20305 : "Sequence number\n"
20306 : "Specify community to reject\n"
20307 : "Specify community to accept\n"
20308 : COMMUNITY_VAL_STR)
20309 : {
20310 0 : char *cl_name_or_number = NULL;
20311 0 : char *str = NULL;
20312 0 : int direct = 0;
20313 0 : int style = COMMUNITY_LIST_STANDARD;
20314 0 : char *seq = NULL;
20315 0 : int idx = 0;
20316 :
20317 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
20318 0 : seq = argv[idx]->arg;
20319 :
20320 0 : idx = 0;
20321 0 : argv_find(argv, argc, "permit", &idx);
20322 0 : argv_find(argv, argc, "deny", &idx);
20323 :
20324 0 : if (idx) {
20325 0 : direct = argv_find(argv, argc, "permit", &idx)
20326 : ? COMMUNITY_PERMIT
20327 0 : : COMMUNITY_DENY;
20328 :
20329 0 : idx = 0;
20330 0 : argv_find(argv, argc, "AA:NN", &idx);
20331 0 : str = argv_concat(argv, argc, idx);
20332 : }
20333 :
20334 0 : idx = 0;
20335 0 : argv_find(argv, argc, "(1-99)", &idx);
20336 0 : argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20337 0 : cl_name_or_number = argv[idx]->arg;
20338 :
20339 0 : int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20340 : direct, style);
20341 :
20342 0 : XFREE(MTYPE_TMP, str);
20343 :
20344 0 : if (ret < 0) {
20345 0 : community_list_perror(vty, ret);
20346 0 : return CMD_WARNING_CONFIG_FAILED;
20347 : }
20348 :
20349 : return CMD_SUCCESS;
20350 : }
20351 :
20352 : ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
20353 : "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
20354 : NO_STR BGP_STR COMMUNITY_LIST_STR
20355 : "Community list number (standard)\n"
20356 : "Add an standard community-list entry\n"
20357 : "Community list name\n")
20358 :
20359 : /*community-list expanded */
20360 0 : DEFUN (community_list_expanded_all,
20361 : bgp_community_list_expanded_all_cmd,
20362 : "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20363 : BGP_STR
20364 : COMMUNITY_LIST_STR
20365 : "Community list number (expanded)\n"
20366 : "Add an expanded community-list entry\n"
20367 : "Community list name\n"
20368 : "Sequence number of an entry\n"
20369 : "Sequence number\n"
20370 : "Specify community to reject\n"
20371 : "Specify community to accept\n"
20372 : COMMUNITY_VAL_STR)
20373 : {
20374 0 : char *cl_name_or_number = NULL;
20375 0 : char *seq = NULL;
20376 0 : int direct = 0;
20377 0 : int style = COMMUNITY_LIST_EXPANDED;
20378 0 : int idx = 0;
20379 :
20380 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
20381 0 : seq = argv[idx]->arg;
20382 :
20383 0 : idx = 0;
20384 :
20385 0 : argv_find(argv, argc, "(100-500)", &idx);
20386 0 : argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20387 0 : cl_name_or_number = argv[idx]->arg;
20388 0 : direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20389 0 : : COMMUNITY_DENY;
20390 0 : argv_find(argv, argc, "AA:NN", &idx);
20391 0 : char *str = argv_concat(argv, argc, idx);
20392 :
20393 0 : int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
20394 : direct, style);
20395 :
20396 0 : XFREE(MTYPE_TMP, str);
20397 :
20398 0 : if (ret < 0) {
20399 : /* Display error string. */
20400 0 : community_list_perror(vty, ret);
20401 0 : return CMD_WARNING_CONFIG_FAILED;
20402 : }
20403 :
20404 : return CMD_SUCCESS;
20405 : }
20406 :
20407 0 : DEFUN (no_community_list_expanded_all,
20408 : no_bgp_community_list_expanded_all_cmd,
20409 : "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20410 : NO_STR
20411 : BGP_STR
20412 : COMMUNITY_LIST_STR
20413 : "Community list number (expanded)\n"
20414 : "Add an expanded community-list entry\n"
20415 : "Community list name\n"
20416 : "Sequence number of an entry\n"
20417 : "Sequence number\n"
20418 : "Specify community to reject\n"
20419 : "Specify community to accept\n"
20420 : COMMUNITY_VAL_STR)
20421 : {
20422 0 : char *cl_name_or_number = NULL;
20423 0 : char *seq = NULL;
20424 0 : char *str = NULL;
20425 0 : int direct = 0;
20426 0 : int style = COMMUNITY_LIST_EXPANDED;
20427 0 : int idx = 0;
20428 :
20429 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
20430 0 : seq = argv[idx]->arg;
20431 :
20432 0 : idx = 0;
20433 0 : argv_find(argv, argc, "permit", &idx);
20434 0 : argv_find(argv, argc, "deny", &idx);
20435 :
20436 0 : if (idx) {
20437 0 : direct = argv_find(argv, argc, "permit", &idx)
20438 : ? COMMUNITY_PERMIT
20439 0 : : COMMUNITY_DENY;
20440 :
20441 0 : idx = 0;
20442 0 : argv_find(argv, argc, "AA:NN", &idx);
20443 0 : str = argv_concat(argv, argc, idx);
20444 : }
20445 :
20446 0 : idx = 0;
20447 0 : argv_find(argv, argc, "(100-500)", &idx);
20448 0 : argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
20449 0 : cl_name_or_number = argv[idx]->arg;
20450 :
20451 0 : int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
20452 : direct, style);
20453 :
20454 0 : XFREE(MTYPE_TMP, str);
20455 :
20456 0 : if (ret < 0) {
20457 0 : community_list_perror(vty, ret);
20458 0 : return CMD_WARNING_CONFIG_FAILED;
20459 : }
20460 :
20461 : return CMD_SUCCESS;
20462 : }
20463 :
20464 : ALIAS(no_community_list_expanded_all,
20465 : no_bgp_community_list_expanded_all_list_cmd,
20466 : "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
20467 : NO_STR BGP_STR COMMUNITY_LIST_STR
20468 : "Community list number (expanded)\n"
20469 : "Add an expanded community-list entry\n"
20470 : "Community list name\n")
20471 :
20472 : /* Return configuration string of community-list entry. */
20473 0 : static const char *community_list_config_str(struct community_entry *entry)
20474 : {
20475 0 : const char *str;
20476 :
20477 0 : if (entry->any)
20478 : str = "";
20479 : else {
20480 0 : if (entry->style == COMMUNITY_LIST_STANDARD)
20481 0 : str = community_str(entry->u.com, false, false);
20482 0 : else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
20483 0 : str = lcommunity_str(entry->u.lcom, false, false);
20484 : else
20485 0 : str = entry->config;
20486 : }
20487 0 : return str;
20488 : }
20489 :
20490 0 : static void community_list_show(struct vty *vty, struct community_list *list)
20491 : {
20492 0 : struct community_entry *entry;
20493 :
20494 0 : for (entry = list->head; entry; entry = entry->next) {
20495 0 : if (entry == list->head) {
20496 0 : if (all_digit(list->name))
20497 0 : vty_out(vty, "Community %s list %s\n",
20498 0 : entry->style == COMMUNITY_LIST_STANDARD
20499 : ? "standard"
20500 : : "(expanded) access",
20501 : list->name);
20502 : else
20503 0 : vty_out(vty, "Named Community %s list %s\n",
20504 0 : entry->style == COMMUNITY_LIST_STANDARD
20505 : ? "standard"
20506 : : "expanded",
20507 : list->name);
20508 : }
20509 0 : if (entry->any)
20510 0 : vty_out(vty, " %s\n",
20511 0 : community_direct_str(entry->direct));
20512 : else
20513 0 : vty_out(vty, " %s %s\n",
20514 0 : community_direct_str(entry->direct),
20515 : community_list_config_str(entry));
20516 : }
20517 0 : }
20518 :
20519 0 : DEFUN (show_community_list,
20520 : show_bgp_community_list_cmd,
20521 : "show bgp community-list",
20522 : SHOW_STR
20523 : BGP_STR
20524 : "List community-list\n")
20525 : {
20526 0 : struct community_list *list;
20527 0 : struct community_list_master *cm;
20528 :
20529 0 : cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20530 0 : if (!cm)
20531 : return CMD_SUCCESS;
20532 :
20533 0 : for (list = cm->num.head; list; list = list->next)
20534 0 : community_list_show(vty, list);
20535 :
20536 0 : for (list = cm->str.head; list; list = list->next)
20537 0 : community_list_show(vty, list);
20538 :
20539 : return CMD_SUCCESS;
20540 : }
20541 :
20542 0 : DEFUN (show_community_list_arg,
20543 : show_bgp_community_list_arg_cmd,
20544 : "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
20545 : SHOW_STR
20546 : BGP_STR
20547 : "List community-list\n"
20548 : "Community-list number\n"
20549 : "Community-list name\n"
20550 : "Detailed information on community-list\n")
20551 : {
20552 0 : int idx_comm_list = 3;
20553 0 : struct community_list *list;
20554 :
20555 0 : list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20556 : COMMUNITY_LIST_MASTER);
20557 0 : if (!list) {
20558 0 : vty_out(vty, "%% Can't find community-list\n");
20559 0 : return CMD_WARNING;
20560 : }
20561 :
20562 0 : community_list_show(vty, list);
20563 :
20564 0 : return CMD_SUCCESS;
20565 : }
20566 :
20567 : /*
20568 : * Large Community code.
20569 : */
20570 0 : static int lcommunity_list_set_vty(struct vty *vty, int argc,
20571 : struct cmd_token **argv, int style,
20572 : int reject_all_digit_name)
20573 : {
20574 0 : int ret;
20575 0 : int direct;
20576 0 : char *str;
20577 0 : int idx = 0;
20578 0 : char *cl_name;
20579 0 : char *seq = NULL;
20580 :
20581 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
20582 0 : seq = argv[idx]->arg;
20583 :
20584 0 : idx = 0;
20585 0 : direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20586 0 : : COMMUNITY_DENY;
20587 :
20588 : /* All digit name check. */
20589 0 : idx = 0;
20590 0 : argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20591 0 : argv_find(argv, argc, "(1-99)", &idx);
20592 0 : argv_find(argv, argc, "(100-500)", &idx);
20593 0 : cl_name = argv[idx]->arg;
20594 0 : if (reject_all_digit_name && all_digit(cl_name)) {
20595 0 : vty_out(vty, "%% Community name cannot have all digits\n");
20596 0 : return CMD_WARNING_CONFIG_FAILED;
20597 : }
20598 :
20599 0 : idx = 0;
20600 0 : argv_find(argv, argc, "AA:BB:CC", &idx);
20601 0 : argv_find(argv, argc, "LINE", &idx);
20602 : /* Concat community string argument. */
20603 0 : if (idx)
20604 0 : str = argv_concat(argv, argc, idx);
20605 : else
20606 : str = NULL;
20607 :
20608 0 : ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
20609 :
20610 : /* Free temporary community list string allocated by
20611 : argv_concat(). */
20612 0 : XFREE(MTYPE_TMP, str);
20613 :
20614 0 : if (ret < 0) {
20615 0 : community_list_perror(vty, ret);
20616 0 : return CMD_WARNING_CONFIG_FAILED;
20617 : }
20618 : return CMD_SUCCESS;
20619 : }
20620 :
20621 0 : static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20622 : struct cmd_token **argv, int style)
20623 : {
20624 0 : int ret;
20625 0 : int direct = 0;
20626 0 : char *str = NULL;
20627 0 : int idx = 0;
20628 0 : char *seq = NULL;
20629 :
20630 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
20631 0 : seq = argv[idx]->arg;
20632 :
20633 0 : idx = 0;
20634 0 : argv_find(argv, argc, "permit", &idx);
20635 0 : argv_find(argv, argc, "deny", &idx);
20636 :
20637 0 : if (idx) {
20638 : /* Check the list direct. */
20639 0 : if (strncmp(argv[idx]->arg, "p", 1) == 0)
20640 : direct = COMMUNITY_PERMIT;
20641 : else
20642 0 : direct = COMMUNITY_DENY;
20643 :
20644 0 : idx = 0;
20645 0 : argv_find(argv, argc, "LINE", &idx);
20646 0 : argv_find(argv, argc, "AA:AA:NN", &idx);
20647 : /* Concat community string argument. */
20648 0 : str = argv_concat(argv, argc, idx);
20649 : }
20650 :
20651 0 : idx = 0;
20652 0 : argv_find(argv, argc, "(1-99)", &idx);
20653 0 : argv_find(argv, argc, "(100-500)", &idx);
20654 0 : argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
20655 :
20656 : /* Unset community list. */
20657 0 : ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
20658 : style);
20659 :
20660 : /* Free temporary community list string allocated by
20661 : argv_concat(). */
20662 0 : XFREE(MTYPE_TMP, str);
20663 :
20664 0 : if (ret < 0) {
20665 0 : community_list_perror(vty, ret);
20666 0 : return CMD_WARNING_CONFIG_FAILED;
20667 : }
20668 :
20669 : return CMD_SUCCESS;
20670 : }
20671 :
20672 : /* "large-community-list" keyword help string. */
20673 : #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20674 : #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20675 :
20676 0 : DEFUN (lcommunity_list_standard,
20677 : bgp_lcommunity_list_standard_cmd,
20678 : "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20679 : BGP_STR
20680 : LCOMMUNITY_LIST_STR
20681 : "Large Community list number (standard)\n"
20682 : "Sequence number of an entry\n"
20683 : "Sequence number\n"
20684 : "Specify large community to reject\n"
20685 : "Specify large community to accept\n"
20686 : LCOMMUNITY_VAL_STR)
20687 : {
20688 0 : return lcommunity_list_set_vty(vty, argc, argv,
20689 : LARGE_COMMUNITY_LIST_STANDARD, 0);
20690 : }
20691 :
20692 0 : DEFUN (lcommunity_list_expanded,
20693 : bgp_lcommunity_list_expanded_cmd,
20694 : "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20695 : BGP_STR
20696 : LCOMMUNITY_LIST_STR
20697 : "Large Community list number (expanded)\n"
20698 : "Sequence number of an entry\n"
20699 : "Sequence number\n"
20700 : "Specify large community to reject\n"
20701 : "Specify large community to accept\n"
20702 : "An ordered list as a regular-expression\n")
20703 : {
20704 0 : return lcommunity_list_set_vty(vty, argc, argv,
20705 : LARGE_COMMUNITY_LIST_EXPANDED, 0);
20706 : }
20707 :
20708 0 : DEFUN (lcommunity_list_name_standard,
20709 : bgp_lcommunity_list_name_standard_cmd,
20710 : "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
20711 : BGP_STR
20712 : LCOMMUNITY_LIST_STR
20713 : "Specify standard large-community-list\n"
20714 : "Large Community list name\n"
20715 : "Sequence number of an entry\n"
20716 : "Sequence number\n"
20717 : "Specify large community to reject\n"
20718 : "Specify large community to accept\n"
20719 : LCOMMUNITY_VAL_STR)
20720 : {
20721 0 : return lcommunity_list_set_vty(vty, argc, argv,
20722 : LARGE_COMMUNITY_LIST_STANDARD, 1);
20723 : }
20724 :
20725 0 : DEFUN (lcommunity_list_name_expanded,
20726 : bgp_lcommunity_list_name_expanded_cmd,
20727 : "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20728 : BGP_STR
20729 : LCOMMUNITY_LIST_STR
20730 : "Specify expanded large-community-list\n"
20731 : "Large Community list name\n"
20732 : "Sequence number of an entry\n"
20733 : "Sequence number\n"
20734 : "Specify large community to reject\n"
20735 : "Specify large community to accept\n"
20736 : "An ordered list as a regular-expression\n")
20737 : {
20738 0 : return lcommunity_list_set_vty(vty, argc, argv,
20739 : LARGE_COMMUNITY_LIST_EXPANDED, 1);
20740 : }
20741 :
20742 0 : DEFUN (no_lcommunity_list_all,
20743 : no_bgp_lcommunity_list_all_cmd,
20744 : "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
20745 : NO_STR
20746 : BGP_STR
20747 : LCOMMUNITY_LIST_STR
20748 : "Large Community list number (standard)\n"
20749 : "Large Community list number (expanded)\n"
20750 : "Large Community list name\n")
20751 : {
20752 0 : return lcommunity_list_unset_vty(vty, argc, argv,
20753 : LARGE_COMMUNITY_LIST_STANDARD);
20754 : }
20755 :
20756 0 : DEFUN (no_lcommunity_list_name_standard_all,
20757 : no_bgp_lcommunity_list_name_standard_all_cmd,
20758 : "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
20759 : NO_STR
20760 : BGP_STR
20761 : LCOMMUNITY_LIST_STR
20762 : "Specify standard large-community-list\n"
20763 : "Large Community list name\n")
20764 : {
20765 0 : return lcommunity_list_unset_vty(vty, argc, argv,
20766 : LARGE_COMMUNITY_LIST_STANDARD);
20767 : }
20768 :
20769 0 : DEFUN (no_lcommunity_list_name_expanded_all,
20770 : no_bgp_lcommunity_list_name_expanded_all_cmd,
20771 : "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
20772 : NO_STR
20773 : BGP_STR
20774 : LCOMMUNITY_LIST_STR
20775 : "Specify expanded large-community-list\n"
20776 : "Large Community list name\n")
20777 : {
20778 0 : return lcommunity_list_unset_vty(vty, argc, argv,
20779 : LARGE_COMMUNITY_LIST_EXPANDED);
20780 : }
20781 :
20782 0 : DEFUN (no_lcommunity_list_standard,
20783 : no_bgp_lcommunity_list_standard_cmd,
20784 : "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20785 : NO_STR
20786 : BGP_STR
20787 : LCOMMUNITY_LIST_STR
20788 : "Large Community list number (standard)\n"
20789 : "Sequence number of an entry\n"
20790 : "Sequence number\n"
20791 : "Specify large community to reject\n"
20792 : "Specify large community to accept\n"
20793 : LCOMMUNITY_VAL_STR)
20794 : {
20795 0 : return lcommunity_list_unset_vty(vty, argc, argv,
20796 : LARGE_COMMUNITY_LIST_STANDARD);
20797 : }
20798 :
20799 0 : DEFUN (no_lcommunity_list_expanded,
20800 : no_bgp_lcommunity_list_expanded_cmd,
20801 : "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20802 : NO_STR
20803 : BGP_STR
20804 : LCOMMUNITY_LIST_STR
20805 : "Large Community list number (expanded)\n"
20806 : "Sequence number of an entry\n"
20807 : "Sequence number\n"
20808 : "Specify large community to reject\n"
20809 : "Specify large community to accept\n"
20810 : "An ordered list as a regular-expression\n")
20811 : {
20812 0 : return lcommunity_list_unset_vty(vty, argc, argv,
20813 : LARGE_COMMUNITY_LIST_EXPANDED);
20814 : }
20815 :
20816 0 : DEFUN (no_lcommunity_list_name_standard,
20817 : no_bgp_lcommunity_list_name_standard_cmd,
20818 : "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20819 : NO_STR
20820 : BGP_STR
20821 : LCOMMUNITY_LIST_STR
20822 : "Specify standard large-community-list\n"
20823 : "Large Community list name\n"
20824 : "Sequence number of an entry\n"
20825 : "Sequence number\n"
20826 : "Specify large community to reject\n"
20827 : "Specify large community to accept\n"
20828 : LCOMMUNITY_VAL_STR)
20829 : {
20830 0 : return lcommunity_list_unset_vty(vty, argc, argv,
20831 : LARGE_COMMUNITY_LIST_STANDARD);
20832 : }
20833 :
20834 0 : DEFUN (no_lcommunity_list_name_expanded,
20835 : no_bgp_lcommunity_list_name_expanded_cmd,
20836 : "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20837 : NO_STR
20838 : BGP_STR
20839 : LCOMMUNITY_LIST_STR
20840 : "Specify expanded large-community-list\n"
20841 : "Large community list name\n"
20842 : "Sequence number of an entry\n"
20843 : "Sequence number\n"
20844 : "Specify large community to reject\n"
20845 : "Specify large community to accept\n"
20846 : "An ordered list as a regular-expression\n")
20847 : {
20848 0 : return lcommunity_list_unset_vty(vty, argc, argv,
20849 : LARGE_COMMUNITY_LIST_EXPANDED);
20850 : }
20851 :
20852 0 : static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20853 : {
20854 0 : struct community_entry *entry;
20855 :
20856 0 : for (entry = list->head; entry; entry = entry->next) {
20857 0 : if (entry == list->head) {
20858 0 : if (all_digit(list->name))
20859 0 : vty_out(vty, "Large community %s list %s\n",
20860 0 : entry->style ==
20861 : LARGE_COMMUNITY_LIST_STANDARD
20862 : ? "standard"
20863 : : "(expanded) access",
20864 : list->name);
20865 : else
20866 0 : vty_out(vty,
20867 : "Named large community %s list %s\n",
20868 0 : entry->style ==
20869 : LARGE_COMMUNITY_LIST_STANDARD
20870 : ? "standard"
20871 : : "expanded",
20872 : list->name);
20873 : }
20874 0 : if (entry->any)
20875 0 : vty_out(vty, " %s\n",
20876 0 : community_direct_str(entry->direct));
20877 : else
20878 0 : vty_out(vty, " %s %s\n",
20879 0 : community_direct_str(entry->direct),
20880 : community_list_config_str(entry));
20881 : }
20882 0 : }
20883 :
20884 0 : DEFUN (show_lcommunity_list,
20885 : show_bgp_lcommunity_list_cmd,
20886 : "show bgp large-community-list",
20887 : SHOW_STR
20888 : BGP_STR
20889 : "List large-community list\n")
20890 : {
20891 0 : struct community_list *list;
20892 0 : struct community_list_master *cm;
20893 :
20894 0 : cm = community_list_master_lookup(bgp_clist,
20895 : LARGE_COMMUNITY_LIST_MASTER);
20896 0 : if (!cm)
20897 : return CMD_SUCCESS;
20898 :
20899 0 : for (list = cm->num.head; list; list = list->next)
20900 0 : lcommunity_list_show(vty, list);
20901 :
20902 0 : for (list = cm->str.head; list; list = list->next)
20903 0 : lcommunity_list_show(vty, list);
20904 :
20905 : return CMD_SUCCESS;
20906 : }
20907 :
20908 0 : DEFUN (show_lcommunity_list_arg,
20909 : show_bgp_lcommunity_list_arg_cmd,
20910 : "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20911 : SHOW_STR
20912 : BGP_STR
20913 : "List large-community list\n"
20914 : "Large-community-list number\n"
20915 : "Large-community-list name\n"
20916 : "Detailed information on large-community-list\n")
20917 : {
20918 0 : struct community_list *list;
20919 :
20920 0 : list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20921 : LARGE_COMMUNITY_LIST_MASTER);
20922 0 : if (!list) {
20923 0 : vty_out(vty, "%% Can't find large-community-list\n");
20924 0 : return CMD_WARNING;
20925 : }
20926 :
20927 0 : lcommunity_list_show(vty, list);
20928 :
20929 0 : return CMD_SUCCESS;
20930 : }
20931 :
20932 : /* "extcommunity-list" keyword help string. */
20933 : #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20934 : #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20935 :
20936 0 : DEFUN (extcommunity_list_standard,
20937 : bgp_extcommunity_list_standard_cmd,
20938 : "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20939 : BGP_STR
20940 : EXTCOMMUNITY_LIST_STR
20941 : "Extended Community list number (standard)\n"
20942 : "Specify standard extcommunity-list\n"
20943 : "Community list name\n"
20944 : "Sequence number of an entry\n"
20945 : "Sequence number\n"
20946 : "Specify community to reject\n"
20947 : "Specify community to accept\n"
20948 : EXTCOMMUNITY_VAL_STR)
20949 : {
20950 0 : int style = EXTCOMMUNITY_LIST_STANDARD;
20951 0 : int direct = 0;
20952 0 : char *cl_number_or_name = NULL;
20953 0 : char *seq = NULL;
20954 :
20955 0 : int idx = 0;
20956 :
20957 0 : argv_find(argv, argc, "(1-99)", &idx);
20958 0 : argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20959 0 : cl_number_or_name = argv[idx]->arg;
20960 :
20961 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
20962 0 : seq = argv[idx]->arg;
20963 :
20964 0 : direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20965 0 : : COMMUNITY_DENY;
20966 0 : argv_find(argv, argc, "AA:NN", &idx);
20967 0 : char *str = argv_concat(argv, argc, idx);
20968 :
20969 0 : int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20970 : direct, style);
20971 :
20972 0 : XFREE(MTYPE_TMP, str);
20973 :
20974 0 : if (ret < 0) {
20975 0 : community_list_perror(vty, ret);
20976 0 : return CMD_WARNING_CONFIG_FAILED;
20977 : }
20978 :
20979 : return CMD_SUCCESS;
20980 : }
20981 :
20982 0 : DEFUN (extcommunity_list_name_expanded,
20983 : bgp_extcommunity_list_name_expanded_cmd,
20984 : "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20985 : BGP_STR
20986 : EXTCOMMUNITY_LIST_STR
20987 : "Extended Community list number (expanded)\n"
20988 : "Specify expanded extcommunity-list\n"
20989 : "Extended Community list name\n"
20990 : "Sequence number of an entry\n"
20991 : "Sequence number\n"
20992 : "Specify community to reject\n"
20993 : "Specify community to accept\n"
20994 : "An ordered list as a regular-expression\n")
20995 : {
20996 0 : int style = EXTCOMMUNITY_LIST_EXPANDED;
20997 0 : int direct = 0;
20998 0 : char *cl_number_or_name = NULL;
20999 0 : char *seq = NULL;
21000 0 : int idx = 0;
21001 :
21002 0 : argv_find(argv, argc, "(100-500)", &idx);
21003 0 : argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21004 0 : cl_number_or_name = argv[idx]->arg;
21005 :
21006 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
21007 0 : seq = argv[idx]->arg;
21008 :
21009 0 : direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
21010 0 : : COMMUNITY_DENY;
21011 0 : argv_find(argv, argc, "LINE", &idx);
21012 0 : char *str = argv_concat(argv, argc, idx);
21013 :
21014 0 : int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
21015 : direct, style);
21016 :
21017 0 : XFREE(MTYPE_TMP, str);
21018 :
21019 0 : if (ret < 0) {
21020 0 : community_list_perror(vty, ret);
21021 0 : return CMD_WARNING_CONFIG_FAILED;
21022 : }
21023 :
21024 : return CMD_SUCCESS;
21025 : }
21026 :
21027 0 : DEFUN (no_extcommunity_list_standard_all,
21028 : no_bgp_extcommunity_list_standard_all_cmd,
21029 : "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
21030 : NO_STR
21031 : BGP_STR
21032 : EXTCOMMUNITY_LIST_STR
21033 : "Extended Community list number (standard)\n"
21034 : "Specify standard extcommunity-list\n"
21035 : "Community list name\n"
21036 : "Sequence number of an entry\n"
21037 : "Sequence number\n"
21038 : "Specify community to reject\n"
21039 : "Specify community to accept\n"
21040 : EXTCOMMUNITY_VAL_STR)
21041 : {
21042 0 : int style = EXTCOMMUNITY_LIST_STANDARD;
21043 0 : int direct = 0;
21044 0 : char *cl_number_or_name = NULL;
21045 0 : char *str = NULL;
21046 0 : char *seq = NULL;
21047 0 : int idx = 0;
21048 :
21049 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
21050 0 : seq = argv[idx]->arg;
21051 :
21052 0 : idx = 0;
21053 0 : argv_find(argv, argc, "permit", &idx);
21054 0 : argv_find(argv, argc, "deny", &idx);
21055 0 : if (idx) {
21056 0 : direct = argv_find(argv, argc, "permit", &idx)
21057 : ? COMMUNITY_PERMIT
21058 0 : : COMMUNITY_DENY;
21059 :
21060 0 : idx = 0;
21061 0 : argv_find(argv, argc, "AA:NN", &idx);
21062 0 : str = argv_concat(argv, argc, idx);
21063 : }
21064 :
21065 0 : idx = 0;
21066 0 : argv_find(argv, argc, "(1-99)", &idx);
21067 0 : argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21068 0 : cl_number_or_name = argv[idx]->arg;
21069 :
21070 0 : int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21071 : seq, direct, style);
21072 :
21073 0 : XFREE(MTYPE_TMP, str);
21074 :
21075 0 : if (ret < 0) {
21076 0 : community_list_perror(vty, ret);
21077 0 : return CMD_WARNING_CONFIG_FAILED;
21078 : }
21079 :
21080 : return CMD_SUCCESS;
21081 : }
21082 :
21083 : ALIAS(no_extcommunity_list_standard_all,
21084 : no_bgp_extcommunity_list_standard_all_list_cmd,
21085 : "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
21086 : NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21087 : "Extended Community list number (standard)\n"
21088 : "Specify standard extcommunity-list\n"
21089 : "Community list name\n")
21090 :
21091 0 : DEFUN (no_extcommunity_list_expanded_all,
21092 : no_bgp_extcommunity_list_expanded_all_cmd,
21093 : "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
21094 : NO_STR
21095 : BGP_STR
21096 : EXTCOMMUNITY_LIST_STR
21097 : "Extended Community list number (expanded)\n"
21098 : "Specify expanded extcommunity-list\n"
21099 : "Extended Community list name\n"
21100 : "Sequence number of an entry\n"
21101 : "Sequence number\n"
21102 : "Specify community to reject\n"
21103 : "Specify community to accept\n"
21104 : "An ordered list as a regular-expression\n")
21105 : {
21106 0 : int style = EXTCOMMUNITY_LIST_EXPANDED;
21107 0 : int direct = 0;
21108 0 : char *cl_number_or_name = NULL;
21109 0 : char *str = NULL;
21110 0 : char *seq = NULL;
21111 0 : int idx = 0;
21112 :
21113 0 : if (argv_find(argv, argc, "(0-4294967295)", &idx))
21114 0 : seq = argv[idx]->arg;
21115 :
21116 0 : idx = 0;
21117 0 : argv_find(argv, argc, "permit", &idx);
21118 0 : argv_find(argv, argc, "deny", &idx);
21119 :
21120 0 : if (idx) {
21121 0 : direct = argv_find(argv, argc, "permit", &idx)
21122 : ? COMMUNITY_PERMIT
21123 0 : : COMMUNITY_DENY;
21124 :
21125 0 : idx = 0;
21126 0 : argv_find(argv, argc, "LINE", &idx);
21127 0 : str = argv_concat(argv, argc, idx);
21128 : }
21129 :
21130 0 : idx = 0;
21131 0 : argv_find(argv, argc, "(100-500)", &idx);
21132 0 : argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
21133 0 : cl_number_or_name = argv[idx]->arg;
21134 :
21135 0 : int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
21136 : seq, direct, style);
21137 :
21138 0 : XFREE(MTYPE_TMP, str);
21139 :
21140 0 : if (ret < 0) {
21141 0 : community_list_perror(vty, ret);
21142 0 : return CMD_WARNING_CONFIG_FAILED;
21143 : }
21144 :
21145 : return CMD_SUCCESS;
21146 : }
21147 :
21148 : ALIAS(no_extcommunity_list_expanded_all,
21149 : no_bgp_extcommunity_list_expanded_all_list_cmd,
21150 : "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
21151 : NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
21152 : "Extended Community list number (expanded)\n"
21153 : "Specify expanded extcommunity-list\n"
21154 : "Extended Community list name\n")
21155 :
21156 0 : static void extcommunity_list_show(struct vty *vty, struct community_list *list)
21157 : {
21158 0 : struct community_entry *entry;
21159 :
21160 0 : for (entry = list->head; entry; entry = entry->next) {
21161 0 : if (entry == list->head) {
21162 0 : if (all_digit(list->name))
21163 0 : vty_out(vty, "Extended community %s list %s\n",
21164 0 : entry->style == EXTCOMMUNITY_LIST_STANDARD
21165 : ? "standard"
21166 : : "(expanded) access",
21167 : list->name);
21168 : else
21169 0 : vty_out(vty,
21170 : "Named extended community %s list %s\n",
21171 0 : entry->style == EXTCOMMUNITY_LIST_STANDARD
21172 : ? "standard"
21173 : : "expanded",
21174 : list->name);
21175 : }
21176 0 : if (entry->any)
21177 0 : vty_out(vty, " %s\n",
21178 0 : community_direct_str(entry->direct));
21179 : else
21180 0 : vty_out(vty, " %s %s\n",
21181 0 : community_direct_str(entry->direct),
21182 : community_list_config_str(entry));
21183 : }
21184 0 : }
21185 :
21186 0 : DEFUN (show_extcommunity_list,
21187 : show_bgp_extcommunity_list_cmd,
21188 : "show bgp extcommunity-list",
21189 : SHOW_STR
21190 : BGP_STR
21191 : "List extended-community list\n")
21192 : {
21193 0 : struct community_list *list;
21194 0 : struct community_list_master *cm;
21195 :
21196 0 : cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21197 0 : if (!cm)
21198 : return CMD_SUCCESS;
21199 :
21200 0 : for (list = cm->num.head; list; list = list->next)
21201 0 : extcommunity_list_show(vty, list);
21202 :
21203 0 : for (list = cm->str.head; list; list = list->next)
21204 0 : extcommunity_list_show(vty, list);
21205 :
21206 : return CMD_SUCCESS;
21207 : }
21208 :
21209 0 : DEFUN (show_extcommunity_list_arg,
21210 : show_bgp_extcommunity_list_arg_cmd,
21211 : "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
21212 : SHOW_STR
21213 : BGP_STR
21214 : "List extended-community list\n"
21215 : "Extcommunity-list number\n"
21216 : "Extcommunity-list name\n"
21217 : "Detailed information on extcommunity-list\n")
21218 : {
21219 0 : int idx_comm_list = 3;
21220 0 : struct community_list *list;
21221 :
21222 0 : list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
21223 : EXTCOMMUNITY_LIST_MASTER);
21224 0 : if (!list) {
21225 0 : vty_out(vty, "%% Can't find extcommunity-list\n");
21226 0 : return CMD_WARNING;
21227 : }
21228 :
21229 0 : extcommunity_list_show(vty, list);
21230 :
21231 0 : return CMD_SUCCESS;
21232 : }
21233 :
21234 : /* Display community-list and extcommunity-list configuration. */
21235 0 : static int community_list_config_write(struct vty *vty)
21236 : {
21237 0 : struct community_list *list;
21238 0 : struct community_entry *entry;
21239 0 : struct community_list_master *cm;
21240 0 : int write = 0;
21241 :
21242 : /* Community-list. */
21243 0 : cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
21244 :
21245 0 : for (list = cm->num.head; list; list = list->next)
21246 0 : for (entry = list->head; entry; entry = entry->next) {
21247 0 : vty_out(vty,
21248 : "bgp community-list %s seq %" PRId64 " %s %s\n",
21249 : list->name, entry->seq,
21250 0 : community_direct_str(entry->direct),
21251 : community_list_config_str(entry));
21252 0 : write++;
21253 : }
21254 0 : for (list = cm->str.head; list; list = list->next)
21255 0 : for (entry = list->head; entry; entry = entry->next) {
21256 0 : vty_out(vty,
21257 : "bgp community-list %s %s seq %" PRId64 " %s %s\n",
21258 0 : entry->style == COMMUNITY_LIST_STANDARD
21259 : ? "standard"
21260 : : "expanded",
21261 : list->name, entry->seq,
21262 0 : community_direct_str(entry->direct),
21263 : community_list_config_str(entry));
21264 0 : write++;
21265 : }
21266 :
21267 : /* Extcommunity-list. */
21268 0 : cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
21269 :
21270 0 : for (list = cm->num.head; list; list = list->next)
21271 0 : for (entry = list->head; entry; entry = entry->next) {
21272 0 : vty_out(vty,
21273 : "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
21274 : list->name, entry->seq,
21275 0 : community_direct_str(entry->direct),
21276 : community_list_config_str(entry));
21277 0 : write++;
21278 : }
21279 0 : for (list = cm->str.head; list; list = list->next)
21280 0 : for (entry = list->head; entry; entry = entry->next) {
21281 0 : vty_out(vty,
21282 : "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
21283 0 : entry->style == EXTCOMMUNITY_LIST_STANDARD
21284 : ? "standard"
21285 : : "expanded",
21286 : list->name, entry->seq,
21287 0 : community_direct_str(entry->direct),
21288 : community_list_config_str(entry));
21289 0 : write++;
21290 : }
21291 :
21292 :
21293 : /* lcommunity-list. */
21294 0 : cm = community_list_master_lookup(bgp_clist,
21295 : LARGE_COMMUNITY_LIST_MASTER);
21296 :
21297 0 : for (list = cm->num.head; list; list = list->next)
21298 0 : for (entry = list->head; entry; entry = entry->next) {
21299 0 : vty_out(vty,
21300 : "bgp large-community-list %s seq %" PRId64" %s %s\n",
21301 : list->name, entry->seq,
21302 0 : community_direct_str(entry->direct),
21303 : community_list_config_str(entry));
21304 0 : write++;
21305 : }
21306 0 : for (list = cm->str.head; list; list = list->next)
21307 0 : for (entry = list->head; entry; entry = entry->next) {
21308 0 : vty_out(vty,
21309 : "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
21310 :
21311 0 : entry->style == LARGE_COMMUNITY_LIST_STANDARD
21312 : ? "standard"
21313 : : "expanded",
21314 0 : list->name, entry->seq, community_direct_str(entry->direct),
21315 : community_list_config_str(entry));
21316 0 : write++;
21317 : }
21318 :
21319 0 : return write;
21320 : }
21321 :
21322 : static int community_list_config_write(struct vty *vty);
21323 : static struct cmd_node community_list_node = {
21324 : .name = "community list",
21325 : .node = COMMUNITY_LIST_NODE,
21326 : .prompt = "",
21327 : .config_write = community_list_config_write,
21328 : };
21329 :
21330 2 : static void community_list_vty(void)
21331 : {
21332 2 : install_node(&community_list_node);
21333 :
21334 : /* Community-list. */
21335 2 : install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
21336 2 : install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
21337 2 : install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
21338 2 : install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
21339 2 : install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
21340 2 : install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
21341 2 : install_element(VIEW_NODE, &show_bgp_community_list_cmd);
21342 2 : install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
21343 :
21344 : /* Extcommunity-list. */
21345 2 : install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
21346 2 : install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
21347 2 : install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
21348 2 : install_element(CONFIG_NODE,
21349 : &no_bgp_extcommunity_list_standard_all_list_cmd);
21350 2 : install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
21351 2 : install_element(CONFIG_NODE,
21352 : &no_bgp_extcommunity_list_expanded_all_list_cmd);
21353 2 : install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
21354 2 : install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
21355 :
21356 : /* Large Community List */
21357 2 : install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
21358 2 : install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
21359 2 : install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
21360 2 : install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
21361 2 : install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
21362 2 : install_element(CONFIG_NODE,
21363 : &no_bgp_lcommunity_list_name_standard_all_cmd);
21364 2 : install_element(CONFIG_NODE,
21365 : &no_bgp_lcommunity_list_name_expanded_all_cmd);
21366 2 : install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
21367 2 : install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
21368 2 : install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
21369 2 : install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
21370 2 : install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
21371 2 : install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
21372 :
21373 2 : bgp_community_list_command_completion_setup();
21374 2 : }
21375 :
21376 : static struct cmd_node community_alias_node = {
21377 : .name = "community alias",
21378 : .node = COMMUNITY_ALIAS_NODE,
21379 : .prompt = "",
21380 : .config_write = bgp_community_alias_write,
21381 : };
21382 :
21383 2 : void community_alias_vty(void)
21384 : {
21385 2 : install_node(&community_alias_node);
21386 :
21387 : /* Community-list. */
21388 2 : install_element(CONFIG_NODE, &bgp_community_alias_cmd);
21389 :
21390 2 : bgp_community_alias_command_completion_setup();
21391 2 : }
|