]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #11445 from opensourcerouting/fix/replace_sockunion2str
[mirror_frr.git] / bgpd / bgp_vty.c
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_nexthop.h"
57 #include "bgpd/bgp_network.h"
58 #include "bgpd/bgp_open.h"
59 #include "bgpd/bgp_regex.h"
60 #include "bgpd/bgp_route.h"
61 #include "bgpd/bgp_mplsvpn.h"
62 #include "bgpd/bgp_zebra.h"
63 #include "bgpd/bgp_table.h"
64 #include "bgpd/bgp_vty.h"
65 #include "bgpd/bgp_mpath.h"
66 #include "bgpd/bgp_packet.h"
67 #include "bgpd/bgp_updgrp.h"
68 #include "bgpd/bgp_bfd.h"
69 #include "bgpd/bgp_io.h"
70 #include "bgpd/bgp_evpn.h"
71 #include "bgpd/bgp_evpn_vty.h"
72 #include "bgpd/bgp_evpn_mh.h"
73 #include "bgpd/bgp_addpath.h"
74 #include "bgpd/bgp_mac.h"
75 #include "bgpd/bgp_flowspec.h"
76 #include "bgpd/bgp_conditional_adv.h"
77 #ifdef ENABLE_BGP_VNC
78 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
79 #endif
80
81 FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
88 );
89 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
92 );
93 FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96 );
97 FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
100 );
101 FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
104 );
105 FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108 );
109 FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112 );
113 FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
116 );
117 FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
121 );
122 FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
123 { .val_bool = false, .match_version = "< 7.6", },
124 { .val_bool = true },
125 );
126 FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
127 { .val_bool = false, .match_version = "< 8.3", },
128 { .val_bool = true },
129 );
130 FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
131 { .val_bool = false, .match_version = "< 8.3", },
132 { .val_bool = true },
133 );
134
135 DEFINE_HOOK(bgp_inst_config_write,
136 (struct bgp *bgp, struct vty *vty),
137 (bgp, vty));
138 DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
139 DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
140
141 static struct peer_group *listen_range_exists(struct bgp *bgp,
142 struct prefix *range, int exact);
143
144 /* Show BGP peer's information. */
145 enum show_type {
146 show_all,
147 show_peer,
148 show_ipv4_all,
149 show_ipv6_all,
150 show_ipv4_peer,
151 show_ipv6_peer
152 };
153
154 static struct peer_group *listen_range_exists(struct bgp *bgp,
155 struct prefix *range, int exact);
156
157 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
158 struct bgp *bgp,
159 bool use_json,
160 json_object *json);
161
162 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
163 enum show_type type,
164 const char *ip_str,
165 afi_t afi, bool use_json);
166
167 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
168 {
169 switch (afi) {
170 case AFI_IP:
171 switch (safi) {
172 case SAFI_UNICAST:
173 return BGP_IPV4_NODE;
174 case SAFI_MULTICAST:
175 return BGP_IPV4M_NODE;
176 case SAFI_LABELED_UNICAST:
177 return BGP_IPV4L_NODE;
178 case SAFI_MPLS_VPN:
179 return BGP_VPNV4_NODE;
180 case SAFI_FLOWSPEC:
181 return BGP_FLOWSPECV4_NODE;
182 default:
183 /* not expected */
184 return BGP_IPV4_NODE;
185 }
186 case AFI_IP6:
187 switch (safi) {
188 case SAFI_UNICAST:
189 return BGP_IPV6_NODE;
190 case SAFI_MULTICAST:
191 return BGP_IPV6M_NODE;
192 case SAFI_LABELED_UNICAST:
193 return BGP_IPV6L_NODE;
194 case SAFI_MPLS_VPN:
195 return BGP_VPNV6_NODE;
196 case SAFI_FLOWSPEC:
197 return BGP_FLOWSPECV6_NODE;
198 default:
199 /* not expected */
200 return BGP_IPV4_NODE;
201 }
202 case AFI_L2VPN:
203 return BGP_EVPN_NODE;
204 case AFI_UNSPEC:
205 case AFI_MAX:
206 // We should never be here but to clarify the switch statement..
207 return BGP_IPV4_NODE;
208 }
209
210 // Impossible to happen
211 return BGP_IPV4_NODE;
212 }
213
214 static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
215 {
216 if (afi == AFI_IP) {
217 if (safi == SAFI_UNICAST)
218 return "IPv4 Unicast";
219 if (safi == SAFI_MULTICAST)
220 return "IPv4 Multicast";
221 if (safi == SAFI_LABELED_UNICAST)
222 return "IPv4 Labeled Unicast";
223 if (safi == SAFI_MPLS_VPN)
224 return "IPv4 VPN";
225 if (safi == SAFI_ENCAP)
226 return "IPv4 Encap";
227 if (safi == SAFI_FLOWSPEC)
228 return "IPv4 Flowspec";
229 } else if (afi == AFI_IP6) {
230 if (safi == SAFI_UNICAST)
231 return "IPv6 Unicast";
232 if (safi == SAFI_MULTICAST)
233 return "IPv6 Multicast";
234 if (safi == SAFI_LABELED_UNICAST)
235 return "IPv6 Labeled Unicast";
236 if (safi == SAFI_MPLS_VPN)
237 return "IPv6 VPN";
238 if (safi == SAFI_ENCAP)
239 return "IPv6 Encap";
240 if (safi == SAFI_FLOWSPEC)
241 return "IPv6 Flowspec";
242 } else if (afi == AFI_L2VPN) {
243 if (safi == SAFI_EVPN)
244 return "L2VPN EVPN";
245 }
246
247 return "Unknown";
248 }
249
250 /*
251 * Please note that we have intentionally camelCased
252 * the return strings here. So if you want
253 * to use this function, please ensure you
254 * are doing this within json output
255 */
256 static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
257 {
258 if (afi == AFI_IP) {
259 if (safi == SAFI_UNICAST)
260 return "ipv4Unicast";
261 if (safi == SAFI_MULTICAST)
262 return "ipv4Multicast";
263 if (safi == SAFI_LABELED_UNICAST)
264 return "ipv4LabeledUnicast";
265 if (safi == SAFI_MPLS_VPN)
266 return "ipv4Vpn";
267 if (safi == SAFI_ENCAP)
268 return "ipv4Encap";
269 if (safi == SAFI_FLOWSPEC)
270 return "ipv4Flowspec";
271 } else if (afi == AFI_IP6) {
272 if (safi == SAFI_UNICAST)
273 return "ipv6Unicast";
274 if (safi == SAFI_MULTICAST)
275 return "ipv6Multicast";
276 if (safi == SAFI_LABELED_UNICAST)
277 return "ipv6LabeledUnicast";
278 if (safi == SAFI_MPLS_VPN)
279 return "ipv6Vpn";
280 if (safi == SAFI_ENCAP)
281 return "ipv6Encap";
282 if (safi == SAFI_FLOWSPEC)
283 return "ipv6Flowspec";
284 } else if (afi == AFI_L2VPN) {
285 if (safi == SAFI_EVPN)
286 return "l2VpnEvpn";
287 }
288
289 return "Unknown";
290 }
291
292 /* unset srv6 locator */
293 static int bgp_srv6_locator_unset(struct bgp *bgp)
294 {
295 int ret;
296 struct listnode *node, *nnode;
297 struct srv6_locator_chunk *chunk;
298 struct bgp_srv6_function *func;
299 struct bgp *bgp_vrf;
300 struct in6_addr *tovpn_sid;
301
302 /* release chunk notification via ZAPI */
303 ret = bgp_zebra_srv6_manager_release_locator_chunk(
304 bgp->srv6_locator_name);
305 if (ret < 0)
306 return -1;
307
308 /* refresh chunks */
309 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk))
310 listnode_delete(bgp->srv6_locator_chunks, chunk);
311
312 /* refresh functions */
313 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func))
314 listnode_delete(bgp->srv6_functions, func);
315
316 /* refresh tovpn_sid */
317 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
318 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
319 continue;
320
321 /* refresh vpnv4 tovpn_sid */
322 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
323 if (tovpn_sid)
324 XFREE(MTYPE_BGP_SRV6_SID,
325 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
326
327 /* refresh vpnv6 tovpn_sid */
328 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
329 if (tovpn_sid)
330 XFREE(MTYPE_BGP_SRV6_SID,
331 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
332 }
333
334 /* update vpn bgp processes */
335 vpn_leak_postchange_all();
336
337 /* clear locator name */
338 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
339
340 return 0;
341 }
342
343 /* Utility function to get address family from current node. */
344 afi_t bgp_node_afi(struct vty *vty)
345 {
346 afi_t afi;
347 switch (vty->node) {
348 case BGP_IPV6_NODE:
349 case BGP_IPV6M_NODE:
350 case BGP_IPV6L_NODE:
351 case BGP_VPNV6_NODE:
352 case BGP_FLOWSPECV6_NODE:
353 afi = AFI_IP6;
354 break;
355 case BGP_EVPN_NODE:
356 afi = AFI_L2VPN;
357 break;
358 default:
359 afi = AFI_IP;
360 break;
361 }
362 return afi;
363 }
364
365 /* Utility function to get subsequent address family from current
366 node. */
367 safi_t bgp_node_safi(struct vty *vty)
368 {
369 safi_t safi;
370 switch (vty->node) {
371 case BGP_VPNV4_NODE:
372 case BGP_VPNV6_NODE:
373 safi = SAFI_MPLS_VPN;
374 break;
375 case BGP_IPV4M_NODE:
376 case BGP_IPV6M_NODE:
377 safi = SAFI_MULTICAST;
378 break;
379 case BGP_EVPN_NODE:
380 safi = SAFI_EVPN;
381 break;
382 case BGP_IPV4L_NODE:
383 case BGP_IPV6L_NODE:
384 safi = SAFI_LABELED_UNICAST;
385 break;
386 case BGP_FLOWSPECV4_NODE:
387 case BGP_FLOWSPECV6_NODE:
388 safi = SAFI_FLOWSPEC;
389 break;
390 default:
391 safi = SAFI_UNICAST;
392 break;
393 }
394 return safi;
395 }
396
397 /**
398 * Converts an AFI in string form to afi_t
399 *
400 * @param afi string, one of
401 * - "ipv4"
402 * - "ipv6"
403 * - "l2vpn"
404 * @return the corresponding afi_t
405 */
406 afi_t bgp_vty_afi_from_str(const char *afi_str)
407 {
408 afi_t afi = AFI_MAX; /* unknown */
409 if (strmatch(afi_str, "ipv4"))
410 afi = AFI_IP;
411 else if (strmatch(afi_str, "ipv6"))
412 afi = AFI_IP6;
413 else if (strmatch(afi_str, "l2vpn"))
414 afi = AFI_L2VPN;
415 return afi;
416 }
417
418 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
419 afi_t *afi)
420 {
421 int ret = 0;
422 if (argv_find(argv, argc, "ipv4", index)) {
423 ret = 1;
424 if (afi)
425 *afi = AFI_IP;
426 } else if (argv_find(argv, argc, "ipv6", index)) {
427 ret = 1;
428 if (afi)
429 *afi = AFI_IP6;
430 } else if (argv_find(argv, argc, "l2vpn", index)) {
431 ret = 1;
432 if (afi)
433 *afi = AFI_L2VPN;
434 }
435 return ret;
436 }
437
438 /* supports <unicast|multicast|vpn|labeled-unicast> */
439 safi_t bgp_vty_safi_from_str(const char *safi_str)
440 {
441 safi_t safi = SAFI_MAX; /* unknown */
442 if (strmatch(safi_str, "multicast"))
443 safi = SAFI_MULTICAST;
444 else if (strmatch(safi_str, "unicast"))
445 safi = SAFI_UNICAST;
446 else if (strmatch(safi_str, "vpn"))
447 safi = SAFI_MPLS_VPN;
448 else if (strmatch(safi_str, "evpn"))
449 safi = SAFI_EVPN;
450 else if (strmatch(safi_str, "labeled-unicast"))
451 safi = SAFI_LABELED_UNICAST;
452 else if (strmatch(safi_str, "flowspec"))
453 safi = SAFI_FLOWSPEC;
454 return safi;
455 }
456
457 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
458 safi_t *safi)
459 {
460 int ret = 0;
461 if (argv_find(argv, argc, "unicast", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_UNICAST;
465 } else if (argv_find(argv, argc, "multicast", index)) {
466 ret = 1;
467 if (safi)
468 *safi = SAFI_MULTICAST;
469 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
470 ret = 1;
471 if (safi)
472 *safi = SAFI_LABELED_UNICAST;
473 } else if (argv_find(argv, argc, "vpn", index)) {
474 ret = 1;
475 if (safi)
476 *safi = SAFI_MPLS_VPN;
477 } else if (argv_find(argv, argc, "evpn", index)) {
478 ret = 1;
479 if (safi)
480 *safi = SAFI_EVPN;
481 } else if (argv_find(argv, argc, "flowspec", index)) {
482 ret = 1;
483 if (safi)
484 *safi = SAFI_FLOWSPEC;
485 }
486 return ret;
487 }
488
489 /*
490 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
491 *
492 * afi
493 * address-family identifier
494 *
495 * safi
496 * subsequent address-family identifier
497 *
498 * Returns:
499 * default_af string corresponding to the supplied afi/safi pair.
500 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
501 * return -1.
502 */
503 static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
504 {
505 switch (afi) {
506 case AFI_IP:
507 switch (safi) {
508 case SAFI_UNICAST:
509 return "ipv4-unicast";
510 case SAFI_MULTICAST:
511 return "ipv4-multicast";
512 case SAFI_MPLS_VPN:
513 return "ipv4-vpn";
514 case SAFI_ENCAP:
515 return "ipv4-encap";
516 case SAFI_LABELED_UNICAST:
517 return "ipv4-labeled-unicast";
518 case SAFI_FLOWSPEC:
519 return "ipv4-flowspec";
520 default:
521 return "unknown-afi/safi";
522 }
523 break;
524 case AFI_IP6:
525 switch (safi) {
526 case SAFI_UNICAST:
527 return "ipv6-unicast";
528 case SAFI_MULTICAST:
529 return "ipv6-multicast";
530 case SAFI_MPLS_VPN:
531 return "ipv6-vpn";
532 case SAFI_ENCAP:
533 return "ipv6-encap";
534 case SAFI_LABELED_UNICAST:
535 return "ipv6-labeled-unicast";
536 case SAFI_FLOWSPEC:
537 return "ipv6-flowspec";
538 default:
539 return "unknown-afi/safi";
540 }
541 break;
542 case AFI_L2VPN:
543 switch (safi) {
544 case SAFI_EVPN:
545 return "l2vpn-evpn";
546 default:
547 return "unknown-afi/safi";
548 }
549 case AFI_UNSPEC:
550 case AFI_MAX:
551 return "unknown-afi/safi";
552 }
553 /* all AFIs are accounted for above, so this shouldn't happen */
554 return "unknown-afi/safi";
555 }
556
557 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
558 enum bgp_instance_type inst_type)
559 {
560 int ret = bgp_get(bgp, as, name, inst_type);
561
562 if (ret == BGP_CREATED) {
563 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
564 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
565
566 if (DFLT_BGP_IMPORT_CHECK)
567 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
568 if (DFLT_BGP_SHOW_HOSTNAME)
569 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
570 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
571 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
572 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
573 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
574 if (DFLT_BGP_DETERMINISTIC_MED)
575 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
576 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
577 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
578 if (DFLT_BGP_SUPPRESS_DUPLICATES)
579 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
580 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
581 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
582 if (DFLT_BGP_HARD_ADMIN_RESET)
583 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
584
585 ret = BGP_SUCCESS;
586 }
587 return ret;
588 }
589
590 /*
591 * bgp_vty_find_and_parse_afi_safi_bgp
592 *
593 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
594 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
595 * to appropriate values for the calling function. This is to allow the
596 * calling function to make decisions appropriate for the show command
597 * that is being parsed.
598 *
599 * The show commands are generally of the form:
600 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
601 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
602 *
603 * Since we use argv_find if the show command in particular doesn't have:
604 * [ip]
605 * [<view|vrf> VIEWVRFNAME]
606 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
607 * The command parsing should still be ok.
608 *
609 * vty -> The vty for the command so we can output some useful data in
610 * the event of a parse error in the vrf.
611 * argv -> The command tokens
612 * argc -> How many command tokens we have
613 * idx -> The current place in the command, generally should be 0 for this
614 * function
615 * afi -> The parsed afi if it was included in the show command, returned here
616 * safi -> The parsed safi if it was included in the show command, returned here
617 * bgp -> Pointer to the bgp data structure we need to fill in.
618 * use_json -> json is configured or not
619 *
620 * The function returns the correct location in the parse tree for the
621 * last token found.
622 *
623 * Returns 0 for failure to parse correctly, else the idx position of where
624 * it found the last token.
625 */
626 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
627 struct cmd_token **argv, int argc,
628 int *idx, afi_t *afi, safi_t *safi,
629 struct bgp **bgp, bool use_json)
630 {
631 char *vrf_name = NULL;
632
633 assert(afi);
634 assert(safi);
635 assert(bgp);
636
637 if (argv_find(argv, argc, "ip", idx))
638 *afi = AFI_IP;
639
640 if (argv_find(argv, argc, "view", idx))
641 vrf_name = argv[*idx + 1]->arg;
642 else if (argv_find(argv, argc, "vrf", idx)) {
643 vrf_name = argv[*idx + 1]->arg;
644 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
645 vrf_name = NULL;
646 }
647 if (vrf_name) {
648 if (strmatch(vrf_name, "all"))
649 *bgp = NULL;
650 else {
651 *bgp = bgp_lookup_by_name(vrf_name);
652 if (!*bgp) {
653 if (use_json) {
654 json_object *json = NULL;
655 json = json_object_new_object();
656 json_object_string_add(
657 json, "warning",
658 "View/Vrf is unknown");
659 vty_json(vty, json);
660 }
661 else
662 vty_out(vty, "View/Vrf %s is unknown\n",
663 vrf_name);
664 *idx = 0;
665 return 0;
666 }
667 }
668 } else {
669 *bgp = bgp_get_default();
670 if (!*bgp) {
671 if (use_json) {
672 json_object *json = NULL;
673 json = json_object_new_object();
674 json_object_string_add(
675 json, "warning",
676 "Default BGP instance not found");
677 vty_json(vty, json);
678 }
679 else
680 vty_out(vty,
681 "Default BGP instance not found\n");
682 *idx = 0;
683 return 0;
684 }
685 }
686
687 if (argv_find_and_parse_afi(argv, argc, idx, afi))
688 argv_find_and_parse_safi(argv, argc, idx, safi);
689
690 *idx += 1;
691 return *idx;
692 }
693
694 static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
695 {
696 struct interface *ifp = NULL;
697 struct listnode *node;
698 struct bgp_listener *listener;
699 union sockunion all_su;
700
701 if (su->sa.sa_family == AF_INET) {
702 (void)str2sockunion("0.0.0.0", &all_su);
703 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
704 } else if (su->sa.sa_family == AF_INET6) {
705 (void)str2sockunion("::", &all_su);
706 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
707 su->sin6.sin6_scope_id,
708 bgp->vrf_id);
709 }
710
711 if (ifp) {
712 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
713 if (sockunion_family(su) !=
714 sockunion_family(&listener->su))
715 continue;
716
717 /* If 0.0.0.0/:: is a listener, then treat as self and
718 * reject.
719 */
720 if (!sockunion_cmp(&listener->su, su) ||
721 !sockunion_cmp(&listener->su, &all_su))
722 return true;
723 }
724 }
725
726 return false;
727 }
728
729 /* Utility function for looking up peer from VTY. */
730 /* This is used only for configuration, so disallow if attempted on
731 * a dynamic neighbor.
732 */
733 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
734 {
735 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
736 int ret;
737 union sockunion su;
738 struct peer *peer;
739
740 if (!bgp) {
741 return NULL;
742 }
743
744 ret = str2sockunion(ip_str, &su);
745 if (ret < 0) {
746 peer = peer_lookup_by_conf_if(bgp, ip_str);
747 if (!peer) {
748 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
749 == NULL) {
750 vty_out(vty,
751 "%% Malformed address or name: %s\n",
752 ip_str);
753 return NULL;
754 }
755 }
756 } else {
757 peer = peer_lookup(bgp, &su);
758 if (!peer) {
759 vty_out(vty,
760 "%% Specify remote-as or peer-group commands first\n");
761 return NULL;
762 }
763 if (peer_dynamic_neighbor(peer)) {
764 vty_out(vty,
765 "%% Operation not allowed on a dynamic neighbor\n");
766 return NULL;
767 }
768 }
769 return peer;
770 }
771
772 /* Utility function for looking up peer or peer group. */
773 /* This is used only for configuration, so disallow if attempted on
774 * a dynamic neighbor.
775 */
776 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
777 {
778 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
779 int ret;
780 union sockunion su;
781 struct peer *peer = NULL;
782 struct peer_group *group = NULL;
783
784 if (!bgp) {
785 return NULL;
786 }
787
788 ret = str2sockunion(peer_str, &su);
789 if (ret == 0) {
790 /* IP address, locate peer. */
791 peer = peer_lookup(bgp, &su);
792 } else {
793 /* Not IP, could match either peer configured on interface or a
794 * group. */
795 peer = peer_lookup_by_conf_if(bgp, peer_str);
796 if (!peer)
797 group = peer_group_lookup(bgp, peer_str);
798 }
799
800 if (peer) {
801 if (peer_dynamic_neighbor(peer)) {
802 vty_out(vty,
803 "%% Operation not allowed on a dynamic neighbor\n");
804 return NULL;
805 }
806
807 return peer;
808 }
809
810 if (group)
811 return group->conf;
812
813 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
814
815 return NULL;
816 }
817
818 int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
819 {
820 const char *str = NULL;
821
822 switch (ret) {
823 case BGP_SUCCESS:
824 case BGP_CREATED:
825 case BGP_GR_NO_OPERATION:
826 break;
827 case BGP_ERR_INVALID_VALUE:
828 str = "Invalid value";
829 break;
830 case BGP_ERR_INVALID_FLAG:
831 str = "Invalid flag";
832 break;
833 case BGP_ERR_PEER_GROUP_SHUTDOWN:
834 str = "Peer-group has been shutdown. Activate the peer-group first";
835 break;
836 case BGP_ERR_PEER_FLAG_CONFLICT:
837 str = "Can't set override-capability and strict-capability-match at the same time";
838 break;
839 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
840 str = "Specify remote-as or peer-group remote AS first";
841 break;
842 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
843 str = "Cannot change the peer-group. Deconfigure first";
844 break;
845 case BGP_ERR_PEER_GROUP_MISMATCH:
846 str = "Peer is not a member of this peer-group";
847 break;
848 case BGP_ERR_PEER_FILTER_CONFLICT:
849 str = "Prefix/distribute list can not co-exist";
850 break;
851 case BGP_ERR_NOT_INTERNAL_PEER:
852 str = "Invalid command. Not an internal neighbor";
853 break;
854 case BGP_ERR_REMOVE_PRIVATE_AS:
855 str = "remove-private-AS cannot be configured for IBGP peers";
856 break;
857 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
858 str = "Local-AS allowed only for EBGP peers";
859 break;
860 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
861 str = "Cannot have local-as same as BGP AS number";
862 break;
863 case BGP_ERR_TCPSIG_FAILED:
864 str = "Error while applying TCP-Sig to session(s)";
865 break;
866 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
867 str = "ebgp-multihop and ttl-security cannot be configured together";
868 break;
869 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
870 str = "ttl-security only allowed for EBGP peers";
871 break;
872 case BGP_ERR_AS_OVERRIDE:
873 str = "as-override cannot be configured for IBGP peers";
874 break;
875 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
876 str = "Invalid limit for number of dynamic neighbors";
877 break;
878 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
879 str = "Dynamic neighbor listen range already exists";
880 break;
881 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
882 str = "Operation not allowed on a dynamic neighbor";
883 break;
884 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
885 str = "Operation not allowed on a directly connected neighbor";
886 break;
887 case BGP_ERR_PEER_SAFI_CONFLICT:
888 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
889 break;
890 case BGP_ERR_GR_INVALID_CMD:
891 str = "The Graceful Restart command used is not valid at this moment.";
892 break;
893 case BGP_ERR_GR_OPERATION_FAILED:
894 str = "The Graceful Restart Operation failed due to an err.";
895 break;
896 case BGP_ERR_PEER_GROUP_MEMBER:
897 str = "Peer-group member cannot override remote-as of peer-group.";
898 break;
899 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
900 str = "Peer-group members must be all internal or all external.";
901 break;
902 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
903 str = "Range specified cannot be deleted because it is not part of current config.";
904 break;
905 case BGP_ERR_INSTANCE_MISMATCH:
906 str = "Instance specified does not match the current instance.";
907 break;
908 case BGP_ERR_NO_INTERFACE_CONFIG:
909 str = "Interface specified is not being used for interface based peer.";
910 break;
911 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
912 str = "No configuration already specified for soft reconfiguration.";
913 break;
914 case BGP_ERR_AS_MISMATCH:
915 str = "BGP is already running.";
916 break;
917 case BGP_ERR_AF_UNCONFIGURED:
918 str = "AFI/SAFI specified is not currently configured.";
919 break;
920 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS:
921 str = "AS specified for local as is the same as the remote as and this is not allowed.";
922 break;
923 case BGP_ERR_INVALID_AS:
924 str = "Confederation AS specified is the same AS as our AS.";
925 break;
926 }
927 if (str) {
928 vty_out(vty, "%% %s\n", str);
929 return CMD_WARNING_CONFIG_FAILED;
930 }
931 return CMD_SUCCESS;
932 }
933
934 /* BGP clear sort. */
935 enum clear_sort {
936 clear_all,
937 clear_peer,
938 clear_group,
939 clear_external,
940 clear_as
941 };
942
943 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
944 safi_t safi, int error)
945 {
946 switch (error) {
947 case BGP_ERR_AF_UNCONFIGURED:
948 vty_out(vty,
949 "%% BGP: Enable %s address family for the neighbor %s\n",
950 get_afi_safi_str(afi, safi, false), peer->host);
951 break;
952 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
953 vty_out(vty,
954 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
955 peer->host);
956 break;
957 default:
958 break;
959 }
960 }
961
962 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
963 struct listnode **nnode, enum bgp_clear_type stype)
964 {
965 int ret = 0;
966 struct peer_af *paf;
967
968 /* if afi/.safi not specified, spin thru all of them */
969 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
970 afi_t tmp_afi;
971 safi_t tmp_safi;
972 enum bgp_af_index index;
973
974 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
975 paf = peer->peer_af_array[index];
976 if (!paf)
977 continue;
978
979 if (paf && paf->subgroup)
980 SET_FLAG(paf->subgroup->sflags,
981 SUBGRP_STATUS_FORCE_UPDATES);
982
983 tmp_afi = paf->afi;
984 tmp_safi = paf->safi;
985 if (!peer->afc[tmp_afi][tmp_safi])
986 continue;
987
988 if (stype == BGP_CLEAR_SOFT_NONE)
989 ret = peer_clear(peer, nnode);
990 else
991 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
992 stype);
993 }
994 /* if afi specified and safi not, spin thru safis on this afi */
995 } else if (safi == SAFI_UNSPEC) {
996 safi_t tmp_safi;
997
998 for (tmp_safi = SAFI_UNICAST;
999 tmp_safi < SAFI_MAX; tmp_safi++) {
1000 if (!peer->afc[afi][tmp_safi])
1001 continue;
1002
1003 paf = peer_af_find(peer, afi, tmp_safi);
1004 if (paf && paf->subgroup)
1005 SET_FLAG(paf->subgroup->sflags,
1006 SUBGRP_STATUS_FORCE_UPDATES);
1007
1008 if (stype == BGP_CLEAR_SOFT_NONE)
1009 ret = peer_clear(peer, nnode);
1010 else
1011 ret = peer_clear_soft(peer, afi,
1012 tmp_safi, stype);
1013 }
1014 /* both afi/safi specified, let the caller know if not defined */
1015 } else {
1016 if (!peer->afc[afi][safi])
1017 return 1;
1018
1019 paf = peer_af_find(peer, afi, safi);
1020 if (paf && paf->subgroup)
1021 SET_FLAG(paf->subgroup->sflags,
1022 SUBGRP_STATUS_FORCE_UPDATES);
1023
1024 if (stype == BGP_CLEAR_SOFT_NONE)
1025 ret = peer_clear(peer, nnode);
1026 else
1027 ret = peer_clear_soft(peer, afi, safi, stype);
1028 }
1029
1030 return ret;
1031 }
1032
1033 /* `clear ip bgp' functions. */
1034 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1035 enum clear_sort sort, enum bgp_clear_type stype,
1036 const char *arg)
1037 {
1038 int ret = 0;
1039 bool found = false;
1040 struct peer *peer;
1041
1042 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1043
1044 /* Clear all neighbors. */
1045 /*
1046 * Pass along pointer to next node to peer_clear() when walking all
1047 * nodes on the BGP instance as that may get freed if it is a
1048 * doppelganger
1049 */
1050 if (sort == clear_all) {
1051 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1052
1053 bgp_peer_gr_flags_update(peer);
1054
1055 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1056 gr_router_detected = true;
1057
1058 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1059 stype);
1060
1061 if (ret < 0)
1062 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1063 }
1064
1065 if (gr_router_detected
1066 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1067 bgp_zebra_send_capabilities(bgp, false);
1068 } else if (!gr_router_detected
1069 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1070 bgp_zebra_send_capabilities(bgp, true);
1071 }
1072
1073 /* This is to apply read-only mode on this clear. */
1074 if (stype == BGP_CLEAR_SOFT_NONE)
1075 bgp->update_delay_over = 0;
1076
1077 return CMD_SUCCESS;
1078 }
1079
1080 /* Clear specified neighbor. */
1081 if (sort == clear_peer) {
1082 union sockunion su;
1083
1084 /* Make sockunion for lookup. */
1085 ret = str2sockunion(arg, &su);
1086 if (ret < 0) {
1087 peer = peer_lookup_by_conf_if(bgp, arg);
1088 if (!peer) {
1089 peer = peer_lookup_by_hostname(bgp, arg);
1090 if (!peer) {
1091 vty_out(vty,
1092 "Malformed address or name: %s\n",
1093 arg);
1094 return CMD_WARNING;
1095 }
1096 }
1097 } else {
1098 peer = peer_lookup(bgp, &su);
1099 if (!peer) {
1100 vty_out(vty,
1101 "%% BGP: Unknown neighbor - \"%s\"\n",
1102 arg);
1103 return CMD_WARNING;
1104 }
1105 }
1106
1107 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1108 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1109
1110 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1111
1112 /* if afi/safi not defined for this peer, let caller know */
1113 if (ret == 1)
1114 ret = BGP_ERR_AF_UNCONFIGURED;
1115
1116 if (ret < 0)
1117 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1118
1119 return CMD_SUCCESS;
1120 }
1121
1122 /* Clear all neighbors belonging to a specific peer-group. */
1123 if (sort == clear_group) {
1124 struct peer_group *group;
1125
1126 group = peer_group_lookup(bgp, arg);
1127 if (!group) {
1128 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1129 return CMD_WARNING;
1130 }
1131
1132 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1133 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1134
1135 if (ret < 0)
1136 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1137 else
1138 found = true;
1139 }
1140
1141 if (!found)
1142 vty_out(vty,
1143 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1144 get_afi_safi_str(afi, safi, false), arg);
1145
1146 return CMD_SUCCESS;
1147 }
1148
1149 /* Clear all external (eBGP) neighbors. */
1150 if (sort == clear_external) {
1151 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1152 if (peer->sort == BGP_PEER_IBGP)
1153 continue;
1154
1155 bgp_peer_gr_flags_update(peer);
1156
1157 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1158 gr_router_detected = true;
1159
1160 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1161
1162 if (ret < 0)
1163 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1164 else
1165 found = true;
1166 }
1167
1168 if (gr_router_detected
1169 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1170 bgp_zebra_send_capabilities(bgp, false);
1171 } else if (!gr_router_detected
1172 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1173 bgp_zebra_send_capabilities(bgp, true);
1174 }
1175
1176 if (!found)
1177 vty_out(vty,
1178 "%% BGP: No external %s peer is configured\n",
1179 get_afi_safi_str(afi, safi, false));
1180
1181 return CMD_SUCCESS;
1182 }
1183
1184 /* Clear all neighbors belonging to a specific AS. */
1185 if (sort == clear_as) {
1186 as_t as = strtoul(arg, NULL, 10);
1187
1188 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1189 if (peer->as != as)
1190 continue;
1191
1192 bgp_peer_gr_flags_update(peer);
1193
1194 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1195 gr_router_detected = true;
1196
1197 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1198
1199 if (ret < 0)
1200 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1201 else
1202 found = true;
1203 }
1204
1205 if (gr_router_detected
1206 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1207 bgp_zebra_send_capabilities(bgp, false);
1208 } else if (!gr_router_detected
1209 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1210 bgp_zebra_send_capabilities(bgp, true);
1211 }
1212
1213 if (!found)
1214 vty_out(vty,
1215 "%% BGP: No %s peer is configured with AS %s\n",
1216 get_afi_safi_str(afi, safi, false), arg);
1217
1218 return CMD_SUCCESS;
1219 }
1220
1221 return CMD_SUCCESS;
1222 }
1223
1224 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1225 safi_t safi, enum clear_sort sort,
1226 enum bgp_clear_type stype, const char *arg)
1227 {
1228 struct bgp *bgp;
1229
1230 /* BGP structure lookup. */
1231 if (name) {
1232 bgp = bgp_lookup_by_name(name);
1233 if (bgp == NULL) {
1234 vty_out(vty, "Can't find BGP instance %s\n", name);
1235 return CMD_WARNING;
1236 }
1237 } else {
1238 bgp = bgp_get_default();
1239 if (bgp == NULL) {
1240 vty_out(vty, "No BGP process is configured\n");
1241 return CMD_WARNING;
1242 }
1243 }
1244
1245 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1246 }
1247
1248 /* clear soft inbound */
1249 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1250 {
1251 afi_t afi;
1252 safi_t safi;
1253
1254 FOREACH_AFI_SAFI (afi, safi)
1255 bgp_clear_vty(vty, name, afi, safi, clear_all,
1256 BGP_CLEAR_SOFT_IN, NULL);
1257 }
1258
1259 /* clear soft outbound */
1260 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1261 {
1262 afi_t afi;
1263 safi_t safi;
1264
1265 FOREACH_AFI_SAFI (afi, safi)
1266 bgp_clear_vty(vty, name, afi, safi, clear_all,
1267 BGP_CLEAR_SOFT_OUT, NULL);
1268 }
1269
1270
1271 #ifndef VTYSH_EXTRACT_PL
1272 #include "bgpd/bgp_vty_clippy.c"
1273 #endif
1274
1275 DEFUN_HIDDEN (bgp_local_mac,
1276 bgp_local_mac_cmd,
1277 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1278 BGP_STR
1279 "Local MAC config\n"
1280 "VxLAN Network Identifier\n"
1281 "VNI number\n"
1282 "local mac\n"
1283 "mac address\n"
1284 "mac-mobility sequence\n"
1285 "seq number\n")
1286 {
1287 int rv;
1288 vni_t vni;
1289 struct ethaddr mac;
1290 struct ipaddr ip;
1291 uint32_t seq;
1292 struct bgp *bgp;
1293
1294 vni = strtoul(argv[3]->arg, NULL, 10);
1295 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1296 vty_out(vty, "%% Malformed MAC address\n");
1297 return CMD_WARNING;
1298 }
1299 memset(&ip, 0, sizeof(ip));
1300 seq = strtoul(argv[7]->arg, NULL, 10);
1301
1302 bgp = bgp_get_default();
1303 if (!bgp) {
1304 vty_out(vty, "Default BGP instance is not there\n");
1305 return CMD_WARNING;
1306 }
1307
1308 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1309 zero_esi);
1310 if (rv < 0) {
1311 vty_out(vty, "Internal error\n");
1312 return CMD_WARNING;
1313 }
1314
1315 return CMD_SUCCESS;
1316 }
1317
1318 DEFUN_HIDDEN (no_bgp_local_mac,
1319 no_bgp_local_mac_cmd,
1320 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1321 NO_STR
1322 BGP_STR
1323 "Local MAC config\n"
1324 "VxLAN Network Identifier\n"
1325 "VNI number\n"
1326 "local mac\n"
1327 "mac address\n")
1328 {
1329 int rv;
1330 vni_t vni;
1331 struct ethaddr mac;
1332 struct ipaddr ip;
1333 struct bgp *bgp;
1334
1335 vni = strtoul(argv[4]->arg, NULL, 10);
1336 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1337 vty_out(vty, "%% Malformed MAC address\n");
1338 return CMD_WARNING;
1339 }
1340 memset(&ip, 0, sizeof(ip));
1341
1342 bgp = bgp_get_default();
1343 if (!bgp) {
1344 vty_out(vty, "Default BGP instance is not there\n");
1345 return CMD_WARNING;
1346 }
1347
1348 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1349 if (rv < 0) {
1350 vty_out(vty, "Internal error\n");
1351 return CMD_WARNING;
1352 }
1353
1354 return CMD_SUCCESS;
1355 }
1356
1357 DEFUN (no_synchronization,
1358 no_synchronization_cmd,
1359 "no synchronization",
1360 NO_STR
1361 "Perform IGP synchronization\n")
1362 {
1363 return CMD_SUCCESS;
1364 }
1365
1366 DEFUN (no_auto_summary,
1367 no_auto_summary_cmd,
1368 "no auto-summary",
1369 NO_STR
1370 "Enable automatic network number summarization\n")
1371 {
1372 return CMD_SUCCESS;
1373 }
1374
1375 /* "router bgp" commands. */
1376 DEFUN_NOSH (router_bgp,
1377 router_bgp_cmd,
1378 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1379 ROUTER_STR
1380 BGP_STR
1381 AS_STR
1382 BGP_INSTANCE_HELP_STR)
1383 {
1384 int idx_asn = 2;
1385 int idx_view_vrf = 3;
1386 int idx_vrf = 4;
1387 int is_new_bgp = 0;
1388 int ret;
1389 as_t as;
1390 struct bgp *bgp;
1391 const char *name = NULL;
1392 enum bgp_instance_type inst_type;
1393
1394 // "router bgp" without an ASN
1395 if (argc == 2) {
1396 // Pending: Make VRF option available for ASN less config
1397 bgp = bgp_get_default();
1398
1399 if (bgp == NULL) {
1400 vty_out(vty, "%% No BGP process is configured\n");
1401 return CMD_WARNING_CONFIG_FAILED;
1402 }
1403
1404 if (listcount(bm->bgp) > 1) {
1405 vty_out(vty, "%% Please specify ASN and VRF\n");
1406 return CMD_WARNING_CONFIG_FAILED;
1407 }
1408 }
1409
1410 // "router bgp X"
1411 else {
1412 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1413
1414 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1415 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1416 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1417
1418 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1419 if (argc > 3) {
1420 name = argv[idx_vrf]->arg;
1421
1422 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1423 if (strmatch(name, VRF_DEFAULT_NAME))
1424 name = NULL;
1425 else
1426 inst_type = BGP_INSTANCE_TYPE_VRF;
1427 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1428 inst_type = BGP_INSTANCE_TYPE_VIEW;
1429 }
1430
1431 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1432 is_new_bgp = (bgp_lookup(as, name) == NULL);
1433
1434 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1435 switch (ret) {
1436 case BGP_ERR_AS_MISMATCH:
1437 vty_out(vty, "BGP is already running; AS is %u\n", as);
1438 return CMD_WARNING_CONFIG_FAILED;
1439 case BGP_ERR_INSTANCE_MISMATCH:
1440 vty_out(vty,
1441 "BGP instance name and AS number mismatch\n");
1442 vty_out(vty,
1443 "BGP instance is already running; AS is %u\n",
1444 as);
1445 return CMD_WARNING_CONFIG_FAILED;
1446 }
1447
1448 /*
1449 * If we just instantiated the default instance, complete
1450 * any pending VRF-VPN leaking that was configured via
1451 * earlier "router bgp X vrf FOO" blocks.
1452 */
1453 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1454 vpn_leak_postchange_all();
1455
1456 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1457 bgp_vpn_leak_export(bgp);
1458 /* Pending: handle when user tries to change a view to vrf n vv.
1459 */
1460 }
1461
1462 /* unset the auto created flag as the user config is now present */
1463 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1464 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1465
1466 return CMD_SUCCESS;
1467 }
1468
1469 /* "no router bgp" commands. */
1470 DEFUN (no_router_bgp,
1471 no_router_bgp_cmd,
1472 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1473 NO_STR
1474 ROUTER_STR
1475 BGP_STR
1476 AS_STR
1477 BGP_INSTANCE_HELP_STR)
1478 {
1479 int idx_asn = 3;
1480 int idx_vrf = 5;
1481 as_t as;
1482 struct bgp *bgp;
1483 const char *name = NULL;
1484
1485 // "no router bgp" without an ASN
1486 if (argc == 3) {
1487 // Pending: Make VRF option available for ASN less config
1488 bgp = bgp_get_default();
1489
1490 if (bgp == NULL) {
1491 vty_out(vty, "%% No BGP process is configured\n");
1492 return CMD_WARNING_CONFIG_FAILED;
1493 }
1494
1495 if (listcount(bm->bgp) > 1) {
1496 vty_out(vty, "%% Please specify ASN and VRF\n");
1497 return CMD_WARNING_CONFIG_FAILED;
1498 }
1499
1500 if (bgp->l3vni) {
1501 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1502 bgp->l3vni);
1503 return CMD_WARNING_CONFIG_FAILED;
1504 }
1505 } else {
1506 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1507
1508 if (argc > 4) {
1509 name = argv[idx_vrf]->arg;
1510 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1511 && strmatch(name, VRF_DEFAULT_NAME))
1512 name = NULL;
1513 }
1514
1515 /* Lookup bgp structure. */
1516 bgp = bgp_lookup(as, name);
1517 if (!bgp) {
1518 vty_out(vty, "%% Can't find BGP instance\n");
1519 return CMD_WARNING_CONFIG_FAILED;
1520 }
1521
1522 if (bgp->l3vni) {
1523 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1524 bgp->l3vni);
1525 return CMD_WARNING_CONFIG_FAILED;
1526 }
1527
1528 /* Cannot delete default instance if vrf instances exist */
1529 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1530 struct listnode *node;
1531 struct bgp *tmp_bgp;
1532
1533 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1534 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1535 continue;
1536 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1537 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1538 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1539 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1540 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1541 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1542 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1543 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1544 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1545 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1546 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1547 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1548 (bgp == bgp_get_evpn() &&
1549 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1550 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1551 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1552 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1553 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1554 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1555 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1556 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1557 (hashcount(tmp_bgp->vnihash))) {
1558 vty_out(vty,
1559 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1560 return CMD_WARNING_CONFIG_FAILED;
1561 }
1562 }
1563 }
1564 }
1565
1566 bgp_delete(bgp);
1567
1568 return CMD_SUCCESS;
1569 }
1570
1571 /* bgp session-dscp */
1572
1573 DEFPY (bgp_session_dscp,
1574 bgp_session_dscp_cmd,
1575 "bgp session-dscp (0-63)$dscp",
1576 BGP_STR
1577 "Override default (C6) bgp TCP session DSCP value\n"
1578 "Manually configured dscp parameter\n")
1579 {
1580 bm->tcp_dscp = dscp << 2;
1581
1582 return CMD_SUCCESS;
1583 }
1584
1585 DEFPY (no_bgp_session_dscp,
1586 no_bgp_session_dscp_cmd,
1587 "no bgp session-dscp [(0-63)]",
1588 NO_STR
1589 BGP_STR
1590 "Override default (C6) bgp TCP session DSCP value\n"
1591 "Manually configured dscp parameter\n")
1592 {
1593 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1594
1595 return CMD_SUCCESS;
1596 }
1597
1598 /* BGP router-id. */
1599
1600 DEFPY (bgp_router_id,
1601 bgp_router_id_cmd,
1602 "bgp router-id A.B.C.D",
1603 BGP_STR
1604 "Override configured router identifier\n"
1605 "Manually configured router identifier\n")
1606 {
1607 VTY_DECLVAR_CONTEXT(bgp, bgp);
1608 bgp_router_id_static_set(bgp, router_id);
1609 return CMD_SUCCESS;
1610 }
1611
1612 DEFPY (no_bgp_router_id,
1613 no_bgp_router_id_cmd,
1614 "no bgp router-id [A.B.C.D]",
1615 NO_STR
1616 BGP_STR
1617 "Override configured router identifier\n"
1618 "Manually configured router identifier\n")
1619 {
1620 VTY_DECLVAR_CONTEXT(bgp, bgp);
1621
1622 if (router_id_str) {
1623 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1624 vty_out(vty, "%% BGP router-id doesn't match\n");
1625 return CMD_WARNING_CONFIG_FAILED;
1626 }
1627 }
1628
1629 router_id.s_addr = 0;
1630 bgp_router_id_static_set(bgp, router_id);
1631
1632 return CMD_SUCCESS;
1633 }
1634
1635 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1636 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1637 NO_STR BGP_STR
1638 "Add community specific parameters\n"
1639 "Create an alias for a community\n"
1640 "Community (AA:BB or AA:BB:CC)\n"
1641 "Alias name\n")
1642 {
1643 struct community_alias ca = {};
1644 struct community_alias *lookup_community;
1645 struct community_alias *lookup_alias;
1646 struct community *comm;
1647 struct lcommunity *lcomm;
1648 uint8_t invalid = 0;
1649
1650 comm = community_str2com(community);
1651 if (!comm)
1652 invalid++;
1653 community_free(&comm);
1654
1655 lcomm = lcommunity_str2com(community);
1656 if (!lcomm)
1657 invalid++;
1658 lcommunity_free(&lcomm);
1659
1660 if (invalid > 1) {
1661 vty_out(vty, "Invalid community format\n");
1662 return CMD_WARNING;
1663 }
1664
1665 strlcpy(ca.community, community, sizeof(ca.community));
1666 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1667
1668 lookup_community = bgp_ca_community_lookup(&ca);
1669 lookup_alias = bgp_ca_alias_lookup(&ca);
1670
1671 if (no) {
1672 bgp_ca_alias_delete(&ca);
1673 bgp_ca_community_delete(&ca);
1674 } else {
1675 if (lookup_alias) {
1676 /* Lookup if community hash table has an item
1677 * with the same alias name.
1678 */
1679 strlcpy(ca.community, lookup_alias->community,
1680 sizeof(ca.community));
1681 if (bgp_ca_community_lookup(&ca)) {
1682 vty_out(vty,
1683 "community (%s) already has this alias (%s)\n",
1684 lookup_alias->community,
1685 lookup_alias->alias);
1686 return CMD_WARNING;
1687 }
1688 bgp_ca_alias_delete(&ca);
1689 }
1690
1691 if (lookup_community) {
1692 /* Lookup if alias hash table has an item
1693 * with the same community.
1694 */
1695 strlcpy(ca.alias, lookup_community->alias,
1696 sizeof(ca.alias));
1697 if (bgp_ca_alias_lookup(&ca)) {
1698 vty_out(vty,
1699 "alias (%s) already has this community (%s)\n",
1700 lookup_community->alias,
1701 lookup_community->community);
1702 return CMD_WARNING;
1703 }
1704 bgp_ca_community_delete(&ca);
1705 }
1706
1707 bgp_ca_alias_insert(&ca);
1708 bgp_ca_community_insert(&ca);
1709 }
1710
1711 return CMD_SUCCESS;
1712 }
1713
1714 DEFPY (bgp_global_suppress_fib_pending,
1715 bgp_global_suppress_fib_pending_cmd,
1716 "[no] bgp suppress-fib-pending",
1717 NO_STR
1718 BGP_STR
1719 "Advertise only routes that are programmed in kernel to peers globally\n")
1720 {
1721 bm_wait_for_fib_set(!no);
1722
1723 return CMD_SUCCESS;
1724 }
1725
1726 DEFPY (bgp_suppress_fib_pending,
1727 bgp_suppress_fib_pending_cmd,
1728 "[no] bgp suppress-fib-pending",
1729 NO_STR
1730 BGP_STR
1731 "Advertise only routes that are programmed in kernel to peers\n")
1732 {
1733 VTY_DECLVAR_CONTEXT(bgp, bgp);
1734
1735 bgp_suppress_fib_pending_set(bgp, !no);
1736 return CMD_SUCCESS;
1737 }
1738
1739
1740 /* BGP Cluster ID. */
1741 DEFUN (bgp_cluster_id,
1742 bgp_cluster_id_cmd,
1743 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1744 BGP_STR
1745 "Configure Route-Reflector Cluster-id\n"
1746 "Route-Reflector Cluster-id in IP address format\n"
1747 "Route-Reflector Cluster-id as 32 bit quantity\n")
1748 {
1749 VTY_DECLVAR_CONTEXT(bgp, bgp);
1750 int idx_ipv4 = 2;
1751 int ret;
1752 struct in_addr cluster;
1753
1754 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1755 if (!ret) {
1756 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1757 return CMD_WARNING_CONFIG_FAILED;
1758 }
1759
1760 bgp_cluster_id_set(bgp, &cluster);
1761 bgp_clear_star_soft_out(vty, bgp->name);
1762
1763 return CMD_SUCCESS;
1764 }
1765
1766 DEFUN (no_bgp_cluster_id,
1767 no_bgp_cluster_id_cmd,
1768 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1769 NO_STR
1770 BGP_STR
1771 "Configure Route-Reflector Cluster-id\n"
1772 "Route-Reflector Cluster-id in IP address format\n"
1773 "Route-Reflector Cluster-id as 32 bit quantity\n")
1774 {
1775 VTY_DECLVAR_CONTEXT(bgp, bgp);
1776 bgp_cluster_id_unset(bgp);
1777 bgp_clear_star_soft_out(vty, bgp->name);
1778
1779 return CMD_SUCCESS;
1780 }
1781
1782 DEFPY (bgp_norib,
1783 bgp_norib_cmd,
1784 "bgp no-rib",
1785 BGP_STR
1786 "Disable BGP route installation to RIB (Zebra)\n")
1787 {
1788 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1789 vty_out(vty,
1790 "%% No-RIB option is already set, nothing to do here.\n");
1791 return CMD_SUCCESS;
1792 }
1793
1794 bgp_option_norib_set_runtime();
1795
1796 return CMD_SUCCESS;
1797 }
1798
1799 DEFPY (no_bgp_norib,
1800 no_bgp_norib_cmd,
1801 "no bgp no-rib",
1802 NO_STR
1803 BGP_STR
1804 "Disable BGP route installation to RIB (Zebra)\n")
1805 {
1806 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1807 vty_out(vty,
1808 "%% No-RIB option is not set, nothing to do here.\n");
1809 return CMD_SUCCESS;
1810 }
1811
1812 bgp_option_norib_unset_runtime();
1813
1814 return CMD_SUCCESS;
1815 }
1816
1817 DEFPY (no_bgp_send_extra_data,
1818 no_bgp_send_extra_data_cmd,
1819 "[no] bgp send-extra-data zebra",
1820 NO_STR
1821 BGP_STR
1822 "Extra data to Zebra for display/use\n"
1823 "To zebra\n")
1824 {
1825 if (no)
1826 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1827 else
1828 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1829
1830 return CMD_SUCCESS;
1831 }
1832
1833 DEFUN (bgp_confederation_identifier,
1834 bgp_confederation_identifier_cmd,
1835 "bgp confederation identifier (1-4294967295)",
1836 BGP_STR
1837 "AS confederation parameters\n"
1838 "AS number\n"
1839 "Set routing domain confederation AS\n")
1840 {
1841 VTY_DECLVAR_CONTEXT(bgp, bgp);
1842 int idx_number = 3;
1843 as_t as;
1844
1845 as = strtoul(argv[idx_number]->arg, NULL, 10);
1846
1847 bgp_confederation_id_set(bgp, as);
1848
1849 return CMD_SUCCESS;
1850 }
1851
1852 DEFUN (no_bgp_confederation_identifier,
1853 no_bgp_confederation_identifier_cmd,
1854 "no bgp confederation identifier [(1-4294967295)]",
1855 NO_STR
1856 BGP_STR
1857 "AS confederation parameters\n"
1858 "AS number\n"
1859 "Set routing domain confederation AS\n")
1860 {
1861 VTY_DECLVAR_CONTEXT(bgp, bgp);
1862 bgp_confederation_id_unset(bgp);
1863
1864 return CMD_SUCCESS;
1865 }
1866
1867 DEFUN (bgp_confederation_peers,
1868 bgp_confederation_peers_cmd,
1869 "bgp confederation peers (1-4294967295)...",
1870 BGP_STR
1871 "AS confederation parameters\n"
1872 "Peer ASs in BGP confederation\n"
1873 AS_STR)
1874 {
1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876 int idx_asn = 3;
1877 as_t as;
1878 int i;
1879
1880 for (i = idx_asn; i < argc; i++) {
1881 as = strtoul(argv[i]->arg, NULL, 10);
1882
1883 if (bgp->as == as) {
1884 vty_out(vty,
1885 "%% Local member-AS not allowed in confed peer list\n");
1886 continue;
1887 }
1888
1889 bgp_confederation_peers_add(bgp, as);
1890 }
1891 return CMD_SUCCESS;
1892 }
1893
1894 DEFUN (no_bgp_confederation_peers,
1895 no_bgp_confederation_peers_cmd,
1896 "no bgp confederation peers (1-4294967295)...",
1897 NO_STR
1898 BGP_STR
1899 "AS confederation parameters\n"
1900 "Peer ASs in BGP confederation\n"
1901 AS_STR)
1902 {
1903 VTY_DECLVAR_CONTEXT(bgp, bgp);
1904 int idx_asn = 4;
1905 as_t as;
1906 int i;
1907
1908 for (i = idx_asn; i < argc; i++) {
1909 as = strtoul(argv[i]->arg, NULL, 10);
1910
1911 bgp_confederation_peers_remove(bgp, as);
1912 }
1913 return CMD_SUCCESS;
1914 }
1915
1916 /**
1917 * Central routine for maximum-paths configuration.
1918 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1919 * @set: 1 for setting values, 0 for removing the max-paths config.
1920 */
1921 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1922 const char *mpaths, uint16_t options,
1923 int set)
1924 {
1925 VTY_DECLVAR_CONTEXT(bgp, bgp);
1926 uint16_t maxpaths = 0;
1927 int ret;
1928 afi_t afi;
1929 safi_t safi;
1930
1931 afi = bgp_node_afi(vty);
1932 safi = bgp_node_safi(vty);
1933
1934 if (set) {
1935 maxpaths = strtol(mpaths, NULL, 10);
1936 if (maxpaths > multipath_num) {
1937 vty_out(vty,
1938 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1939 maxpaths, multipath_num);
1940 return CMD_WARNING_CONFIG_FAILED;
1941 }
1942 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1943 options);
1944 } else
1945 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1946
1947 if (ret < 0) {
1948 vty_out(vty,
1949 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1950 (set == 1) ? "" : "un",
1951 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1952 maxpaths, afi, safi);
1953 return CMD_WARNING_CONFIG_FAILED;
1954 }
1955
1956 bgp_recalculate_all_bestpaths(bgp);
1957
1958 return CMD_SUCCESS;
1959 }
1960
1961 DEFUN (bgp_maxmed_admin,
1962 bgp_maxmed_admin_cmd,
1963 "bgp max-med administrative ",
1964 BGP_STR
1965 "Advertise routes with max-med\n"
1966 "Administratively applied, for an indefinite period\n")
1967 {
1968 VTY_DECLVAR_CONTEXT(bgp, bgp);
1969
1970 bgp->v_maxmed_admin = 1;
1971 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1972
1973 bgp_maxmed_update(bgp);
1974
1975 return CMD_SUCCESS;
1976 }
1977
1978 DEFUN (bgp_maxmed_admin_medv,
1979 bgp_maxmed_admin_medv_cmd,
1980 "bgp max-med administrative (0-4294967295)",
1981 BGP_STR
1982 "Advertise routes with max-med\n"
1983 "Administratively applied, for an indefinite period\n"
1984 "Max MED value to be used\n")
1985 {
1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
1987 int idx_number = 3;
1988
1989 bgp->v_maxmed_admin = 1;
1990 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1991
1992 bgp_maxmed_update(bgp);
1993
1994 return CMD_SUCCESS;
1995 }
1996
1997 DEFUN (no_bgp_maxmed_admin,
1998 no_bgp_maxmed_admin_cmd,
1999 "no bgp max-med administrative [(0-4294967295)]",
2000 NO_STR
2001 BGP_STR
2002 "Advertise routes with max-med\n"
2003 "Administratively applied, for an indefinite period\n"
2004 "Max MED value to be used\n")
2005 {
2006 VTY_DECLVAR_CONTEXT(bgp, bgp);
2007 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2008 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2009 bgp_maxmed_update(bgp);
2010
2011 return CMD_SUCCESS;
2012 }
2013
2014 DEFUN (bgp_maxmed_onstartup,
2015 bgp_maxmed_onstartup_cmd,
2016 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2017 BGP_STR
2018 "Advertise routes with max-med\n"
2019 "Effective on a startup\n"
2020 "Time (seconds) period for max-med\n"
2021 "Max MED value to be used\n")
2022 {
2023 VTY_DECLVAR_CONTEXT(bgp, bgp);
2024 int idx = 0;
2025
2026 if (argv_find(argv, argc, "(5-86400)", &idx))
2027 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2028 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2029 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2030 else
2031 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2032
2033 bgp_maxmed_update(bgp);
2034
2035 return CMD_SUCCESS;
2036 }
2037
2038 DEFUN (no_bgp_maxmed_onstartup,
2039 no_bgp_maxmed_onstartup_cmd,
2040 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2041 NO_STR
2042 BGP_STR
2043 "Advertise routes with max-med\n"
2044 "Effective on a startup\n"
2045 "Time (seconds) period for max-med\n"
2046 "Max MED value to be used\n")
2047 {
2048 VTY_DECLVAR_CONTEXT(bgp, bgp);
2049
2050 /* Cancel max-med onstartup if its on */
2051 if (bgp->t_maxmed_onstartup) {
2052 thread_cancel(&bgp->t_maxmed_onstartup);
2053 bgp->maxmed_onstartup_over = 1;
2054 }
2055
2056 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2057 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2058
2059 bgp_maxmed_update(bgp);
2060
2061 return CMD_SUCCESS;
2062 }
2063
2064 static int bgp_global_update_delay_config_vty(struct vty *vty,
2065 uint16_t update_delay,
2066 uint16_t establish_wait)
2067 {
2068 struct listnode *node, *nnode;
2069 struct bgp *bgp;
2070 bool vrf_cfg = false;
2071
2072 /*
2073 * See if update-delay is set per-vrf and warn user to delete it
2074 * Note that we only need to check this if this is the first time
2075 * setting the global config.
2076 */
2077 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2078 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2079 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2080 vty_out(vty,
2081 "%% update-delay configuration found in vrf %s\n",
2082 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2083 ? VRF_DEFAULT_NAME
2084 : bgp->name);
2085 vrf_cfg = true;
2086 }
2087 }
2088 }
2089
2090 if (vrf_cfg) {
2091 vty_out(vty,
2092 "%%Failed: global update-delay config not permitted\n");
2093 return CMD_WARNING;
2094 }
2095
2096 if (!establish_wait) { /* update-delay <delay> */
2097 bm->v_update_delay = update_delay;
2098 bm->v_establish_wait = bm->v_update_delay;
2099 } else {
2100 /* update-delay <delay> <establish-wait> */
2101 if (update_delay < establish_wait) {
2102 vty_out(vty,
2103 "%%Failed: update-delay less than the establish-wait!\n");
2104 return CMD_WARNING_CONFIG_FAILED;
2105 }
2106
2107 bm->v_update_delay = update_delay;
2108 bm->v_establish_wait = establish_wait;
2109 }
2110
2111 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2112 bgp->v_update_delay = bm->v_update_delay;
2113 bgp->v_establish_wait = bm->v_establish_wait;
2114 }
2115
2116 return CMD_SUCCESS;
2117 }
2118
2119 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2120 {
2121 struct listnode *node, *nnode;
2122 struct bgp *bgp;
2123
2124 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2125 bm->v_establish_wait = bm->v_update_delay;
2126
2127 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2128 bgp->v_update_delay = bm->v_update_delay;
2129 bgp->v_establish_wait = bm->v_establish_wait;
2130 }
2131
2132 return CMD_SUCCESS;
2133 }
2134
2135 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2136 uint16_t establish_wait)
2137 {
2138 VTY_DECLVAR_CONTEXT(bgp, bgp);
2139
2140 /* if configured globally, per-instance config is not allowed */
2141 if (bm->v_update_delay) {
2142 vty_out(vty,
2143 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2144 return CMD_WARNING_CONFIG_FAILED;
2145 }
2146
2147
2148 if (!establish_wait) /* update-delay <delay> */
2149 {
2150 bgp->v_update_delay = update_delay;
2151 bgp->v_establish_wait = bgp->v_update_delay;
2152 return CMD_SUCCESS;
2153 }
2154
2155 /* update-delay <delay> <establish-wait> */
2156 if (update_delay < establish_wait) {
2157 vty_out(vty,
2158 "%%Failed: update-delay less than the establish-wait!\n");
2159 return CMD_WARNING_CONFIG_FAILED;
2160 }
2161
2162 bgp->v_update_delay = update_delay;
2163 bgp->v_establish_wait = establish_wait;
2164
2165 return CMD_SUCCESS;
2166 }
2167
2168 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2169 {
2170 VTY_DECLVAR_CONTEXT(bgp, bgp);
2171
2172 /* If configured globally, cannot remove from one bgp instance */
2173 if (bm->v_update_delay) {
2174 vty_out(vty,
2175 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2176 return CMD_WARNING_CONFIG_FAILED;
2177 }
2178 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2179 bgp->v_establish_wait = bgp->v_update_delay;
2180
2181 return CMD_SUCCESS;
2182 }
2183
2184 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2185 {
2186 /* If configured globally, no need to display per-instance value */
2187 if (bgp->v_update_delay != bm->v_update_delay) {
2188 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2189 if (bgp->v_update_delay != bgp->v_establish_wait)
2190 vty_out(vty, " %d", bgp->v_establish_wait);
2191 vty_out(vty, "\n");
2192 }
2193 }
2194
2195 /* Global update-delay configuration */
2196 DEFPY (bgp_global_update_delay,
2197 bgp_global_update_delay_cmd,
2198 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2199 BGP_STR
2200 "Force initial delay for best-path and updates for all bgp instances\n"
2201 "Max delay in seconds\n"
2202 "Establish wait in seconds\n")
2203 {
2204 return bgp_global_update_delay_config_vty(vty, delay, wait);
2205 }
2206
2207 /* Global update-delay deconfiguration */
2208 DEFPY (no_bgp_global_update_delay,
2209 no_bgp_global_update_delay_cmd,
2210 "no bgp update-delay [(0-3600) [(1-3600)]]",
2211 NO_STR
2212 BGP_STR
2213 "Force initial delay for best-path and updates\n"
2214 "Max delay in seconds\n"
2215 "Establish wait in seconds\n")
2216 {
2217 return bgp_global_update_delay_deconfig_vty(vty);
2218 }
2219
2220 /* Update-delay configuration */
2221
2222 DEFPY (bgp_update_delay,
2223 bgp_update_delay_cmd,
2224 "update-delay (0-3600)$delay [(1-3600)$wait]",
2225 "Force initial delay for best-path and updates\n"
2226 "Max delay in seconds\n"
2227 "Establish wait in seconds\n")
2228 {
2229 return bgp_update_delay_config_vty(vty, delay, wait);
2230 }
2231
2232 /* Update-delay deconfiguration */
2233 DEFPY (no_bgp_update_delay,
2234 no_bgp_update_delay_cmd,
2235 "no update-delay [(0-3600) [(1-3600)]]",
2236 NO_STR
2237 "Force initial delay for best-path and updates\n"
2238 "Max delay in seconds\n"
2239 "Establish wait in seconds\n")
2240 {
2241 return bgp_update_delay_deconfig_vty(vty);
2242 }
2243
2244
2245 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2246 bool set)
2247 {
2248 VTY_DECLVAR_CONTEXT(bgp, bgp);
2249
2250 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2251 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2252
2253 return CMD_SUCCESS;
2254 }
2255
2256 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2257 bool set)
2258 {
2259 VTY_DECLVAR_CONTEXT(bgp, bgp);
2260
2261 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2262 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2263
2264 return CMD_SUCCESS;
2265 }
2266
2267 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2268 {
2269 uint32_t quanta =
2270 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2271 if (quanta != BGP_WRITE_PACKET_MAX)
2272 vty_out(vty, " write-quanta %d\n", quanta);
2273 }
2274
2275 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2276 {
2277 uint32_t quanta =
2278 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2279 if (quanta != BGP_READ_PACKET_MAX)
2280 vty_out(vty, " read-quanta %d\n", quanta);
2281 }
2282
2283 /* Packet quanta configuration
2284 *
2285 * XXX: The value set here controls the size of a stack buffer in the IO
2286 * thread. When changing these limits be careful to prevent stack overflow.
2287 *
2288 * Furthermore, the maximums used here should correspond to
2289 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2290 */
2291 DEFPY (bgp_wpkt_quanta,
2292 bgp_wpkt_quanta_cmd,
2293 "[no] write-quanta (1-64)$quanta",
2294 NO_STR
2295 "How many packets to write to peer socket per run\n"
2296 "Number of packets\n")
2297 {
2298 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2299 }
2300
2301 DEFPY (bgp_rpkt_quanta,
2302 bgp_rpkt_quanta_cmd,
2303 "[no] read-quanta (1-10)$quanta",
2304 NO_STR
2305 "How many packets to read from peer socket per I/O cycle\n"
2306 "Number of packets\n")
2307 {
2308 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2309 }
2310
2311 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2312 {
2313 if (!bgp->heuristic_coalesce)
2314 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2315 }
2316
2317
2318 DEFUN (bgp_coalesce_time,
2319 bgp_coalesce_time_cmd,
2320 "coalesce-time (0-4294967295)",
2321 "Subgroup coalesce timer\n"
2322 "Subgroup coalesce timer value (in ms)\n")
2323 {
2324 VTY_DECLVAR_CONTEXT(bgp, bgp);
2325
2326 int idx = 0;
2327
2328 bgp->heuristic_coalesce = false;
2329
2330 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2331 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2332
2333 return CMD_SUCCESS;
2334 }
2335
2336 DEFUN (no_bgp_coalesce_time,
2337 no_bgp_coalesce_time_cmd,
2338 "no coalesce-time (0-4294967295)",
2339 NO_STR
2340 "Subgroup coalesce timer\n"
2341 "Subgroup coalesce timer value (in ms)\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344
2345 bgp->heuristic_coalesce = true;
2346 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2347 return CMD_SUCCESS;
2348 }
2349
2350 /* Maximum-paths configuration */
2351 DEFUN (bgp_maxpaths,
2352 bgp_maxpaths_cmd,
2353 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2354 "Forward packets over multiple paths\n"
2355 "Number of paths\n")
2356 {
2357 int idx_number = 1;
2358 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2359 argv[idx_number]->arg, 0, 1);
2360 }
2361
2362 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2363 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2364 "Forward packets over multiple paths\n"
2365 "Number of paths\n")
2366
2367 DEFUN (bgp_maxpaths_ibgp,
2368 bgp_maxpaths_ibgp_cmd,
2369 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2370 "Forward packets over multiple paths\n"
2371 "iBGP-multipath\n"
2372 "Number of paths\n")
2373 {
2374 int idx_number = 2;
2375 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2376 argv[idx_number]->arg, 0, 1);
2377 }
2378
2379 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2380 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2381 "Forward packets over multiple paths\n"
2382 "iBGP-multipath\n"
2383 "Number of paths\n")
2384
2385 DEFUN (bgp_maxpaths_ibgp_cluster,
2386 bgp_maxpaths_ibgp_cluster_cmd,
2387 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2388 "Forward packets over multiple paths\n"
2389 "iBGP-multipath\n"
2390 "Number of paths\n"
2391 "Match the cluster length\n")
2392 {
2393 int idx_number = 2;
2394 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2395 argv[idx_number]->arg, true, 1);
2396 }
2397
2398 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2399 "maximum-paths ibgp " CMD_RANGE_STR(
2400 1, MULTIPATH_NUM) " equal-cluster-length",
2401 "Forward packets over multiple paths\n"
2402 "iBGP-multipath\n"
2403 "Number of paths\n"
2404 "Match the cluster length\n")
2405
2406 DEFUN (no_bgp_maxpaths,
2407 no_bgp_maxpaths_cmd,
2408 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2409 NO_STR
2410 "Forward packets over multiple paths\n"
2411 "Number of paths\n")
2412 {
2413 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2414 }
2415
2416 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2417 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2418 "Forward packets over multiple paths\n"
2419 "Number of paths\n")
2420
2421 DEFUN (no_bgp_maxpaths_ibgp,
2422 no_bgp_maxpaths_ibgp_cmd,
2423 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2424 NO_STR
2425 "Forward packets over multiple paths\n"
2426 "iBGP-multipath\n"
2427 "Number of paths\n"
2428 "Match the cluster length\n")
2429 {
2430 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2431 }
2432
2433 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2434 "no maximum-paths ibgp [" CMD_RANGE_STR(
2435 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2436 NO_STR
2437 "Forward packets over multiple paths\n"
2438 "iBGP-multipath\n"
2439 "Number of paths\n"
2440 "Match the cluster length\n")
2441
2442 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2443 afi_t afi, safi_t safi)
2444 {
2445 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2446 vty_out(vty, " maximum-paths %d\n",
2447 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2448 }
2449
2450 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2451 vty_out(vty, " maximum-paths ibgp %d",
2452 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2453 if (bgp->maxpaths[afi][safi].same_clusterlen)
2454 vty_out(vty, " equal-cluster-length");
2455 vty_out(vty, "\n");
2456 }
2457 }
2458
2459 /* BGP timers. */
2460
2461 DEFUN (bgp_timers,
2462 bgp_timers_cmd,
2463 "timers bgp (0-65535) (0-65535)",
2464 "Adjust routing timers\n"
2465 "BGP timers\n"
2466 "Keepalive interval\n"
2467 "Holdtime\n")
2468 {
2469 VTY_DECLVAR_CONTEXT(bgp, bgp);
2470 int idx_number = 2;
2471 int idx_number_2 = 3;
2472 unsigned long keepalive = 0;
2473 unsigned long holdtime = 0;
2474
2475 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2476 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2477
2478 /* Holdtime value check. */
2479 if (holdtime < 3 && holdtime != 0) {
2480 vty_out(vty,
2481 "%% hold time value must be either 0 or greater than 3\n");
2482 return CMD_WARNING_CONFIG_FAILED;
2483 }
2484
2485 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2486 BGP_DEFAULT_DELAYOPEN);
2487
2488 return CMD_SUCCESS;
2489 }
2490
2491 DEFUN (no_bgp_timers,
2492 no_bgp_timers_cmd,
2493 "no timers bgp [(0-65535) (0-65535)]",
2494 NO_STR
2495 "Adjust routing timers\n"
2496 "BGP timers\n"
2497 "Keepalive interval\n"
2498 "Holdtime\n")
2499 {
2500 VTY_DECLVAR_CONTEXT(bgp, bgp);
2501 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2502 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2503
2504 return CMD_SUCCESS;
2505 }
2506
2507 /* BGP minimum holdtime. */
2508
2509 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2510 "bgp minimum-holdtime (1-65535)",
2511 "BGP specific commands\n"
2512 "BGP minimum holdtime\n"
2513 "Seconds\n")
2514 {
2515 VTY_DECLVAR_CONTEXT(bgp, bgp);
2516 int idx_number = 2;
2517 unsigned long min_holdtime;
2518
2519 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2520
2521 bgp->default_min_holdtime = min_holdtime;
2522
2523 return CMD_SUCCESS;
2524 }
2525
2526 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2527 "no bgp minimum-holdtime [(1-65535)]",
2528 NO_STR
2529 "BGP specific commands\n"
2530 "BGP minimum holdtime\n"
2531 "Seconds\n")
2532 {
2533 VTY_DECLVAR_CONTEXT(bgp, bgp);
2534
2535 bgp->default_min_holdtime = 0;
2536
2537 return CMD_SUCCESS;
2538 }
2539
2540 DEFUN (bgp_client_to_client_reflection,
2541 bgp_client_to_client_reflection_cmd,
2542 "bgp client-to-client reflection",
2543 BGP_STR
2544 "Configure client to client route reflection\n"
2545 "reflection of routes allowed\n")
2546 {
2547 VTY_DECLVAR_CONTEXT(bgp, bgp);
2548 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2549 bgp_clear_star_soft_out(vty, bgp->name);
2550
2551 return CMD_SUCCESS;
2552 }
2553
2554 DEFUN (no_bgp_client_to_client_reflection,
2555 no_bgp_client_to_client_reflection_cmd,
2556 "no bgp client-to-client reflection",
2557 NO_STR
2558 BGP_STR
2559 "Configure client to client route reflection\n"
2560 "reflection of routes allowed\n")
2561 {
2562 VTY_DECLVAR_CONTEXT(bgp, bgp);
2563 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2564 bgp_clear_star_soft_out(vty, bgp->name);
2565
2566 return CMD_SUCCESS;
2567 }
2568
2569 /* "bgp always-compare-med" configuration. */
2570 DEFUN (bgp_always_compare_med,
2571 bgp_always_compare_med_cmd,
2572 "bgp always-compare-med",
2573 BGP_STR
2574 "Allow comparing MED from different neighbors\n")
2575 {
2576 VTY_DECLVAR_CONTEXT(bgp, bgp);
2577 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2578 bgp_recalculate_all_bestpaths(bgp);
2579
2580 return CMD_SUCCESS;
2581 }
2582
2583 DEFUN (no_bgp_always_compare_med,
2584 no_bgp_always_compare_med_cmd,
2585 "no bgp always-compare-med",
2586 NO_STR
2587 BGP_STR
2588 "Allow comparing MED from different neighbors\n")
2589 {
2590 VTY_DECLVAR_CONTEXT(bgp, bgp);
2591 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2592 bgp_recalculate_all_bestpaths(bgp);
2593
2594 return CMD_SUCCESS;
2595 }
2596
2597
2598 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2599 "bgp ebgp-requires-policy",
2600 BGP_STR
2601 "Require in and out policy for eBGP peers (RFC8212)\n")
2602 {
2603 VTY_DECLVAR_CONTEXT(bgp, bgp);
2604 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2605 return CMD_SUCCESS;
2606 }
2607
2608 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2609 "no bgp ebgp-requires-policy",
2610 NO_STR
2611 BGP_STR
2612 "Require in and out policy for eBGP peers (RFC8212)\n")
2613 {
2614 VTY_DECLVAR_CONTEXT(bgp, bgp);
2615 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2616 return CMD_SUCCESS;
2617 }
2618
2619 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2620 "bgp suppress-duplicates",
2621 BGP_STR
2622 "Suppress duplicate updates if the route actually not changed\n")
2623 {
2624 VTY_DECLVAR_CONTEXT(bgp, bgp);
2625 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2626 return CMD_SUCCESS;
2627 }
2628
2629 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2630 "no bgp suppress-duplicates",
2631 NO_STR
2632 BGP_STR
2633 "Suppress duplicate updates if the route actually not changed\n")
2634 {
2635 VTY_DECLVAR_CONTEXT(bgp, bgp);
2636 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2637 return CMD_SUCCESS;
2638 }
2639
2640 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2641 "bgp reject-as-sets",
2642 BGP_STR
2643 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2644 {
2645 VTY_DECLVAR_CONTEXT(bgp, bgp);
2646 struct listnode *node, *nnode;
2647 struct peer *peer;
2648
2649 bgp->reject_as_sets = true;
2650
2651 /* Reset existing BGP sessions to reject routes
2652 * with aspath containing AS_SET or AS_CONFED_SET.
2653 */
2654 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2655 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2656 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2657 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2658 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2659 }
2660 }
2661
2662 return CMD_SUCCESS;
2663 }
2664
2665 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2666 "no bgp reject-as-sets",
2667 NO_STR
2668 BGP_STR
2669 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2670 {
2671 VTY_DECLVAR_CONTEXT(bgp, bgp);
2672 struct listnode *node, *nnode;
2673 struct peer *peer;
2674
2675 bgp->reject_as_sets = false;
2676
2677 /* Reset existing BGP sessions to reject routes
2678 * with aspath containing AS_SET or AS_CONFED_SET.
2679 */
2680 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2681 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2682 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2683 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2684 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2685 }
2686 }
2687
2688 return CMD_SUCCESS;
2689 }
2690
2691 /* "bgp deterministic-med" configuration. */
2692 DEFUN (bgp_deterministic_med,
2693 bgp_deterministic_med_cmd,
2694 "bgp deterministic-med",
2695 BGP_STR
2696 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2697 {
2698 VTY_DECLVAR_CONTEXT(bgp, bgp);
2699
2700 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2701 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2702 bgp_recalculate_all_bestpaths(bgp);
2703 }
2704
2705 return CMD_SUCCESS;
2706 }
2707
2708 DEFUN (no_bgp_deterministic_med,
2709 no_bgp_deterministic_med_cmd,
2710 "no bgp deterministic-med",
2711 NO_STR
2712 BGP_STR
2713 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2714 {
2715 VTY_DECLVAR_CONTEXT(bgp, bgp);
2716 int bestpath_per_as_used;
2717 afi_t afi;
2718 safi_t safi;
2719 struct peer *peer;
2720 struct listnode *node, *nnode;
2721
2722 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2723 bestpath_per_as_used = 0;
2724
2725 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2726 FOREACH_AFI_SAFI (afi, safi)
2727 if (bgp_addpath_dmed_required(
2728 peer->addpath_type[afi][safi])) {
2729 bestpath_per_as_used = 1;
2730 break;
2731 }
2732
2733 if (bestpath_per_as_used)
2734 break;
2735 }
2736
2737 if (bestpath_per_as_used) {
2738 vty_out(vty,
2739 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2740 return CMD_WARNING_CONFIG_FAILED;
2741 } else {
2742 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2743 bgp_recalculate_all_bestpaths(bgp);
2744 }
2745 }
2746
2747 return CMD_SUCCESS;
2748 }
2749
2750 /* "bgp graceful-restart mode" configuration. */
2751 DEFUN (bgp_graceful_restart,
2752 bgp_graceful_restart_cmd,
2753 "bgp graceful-restart",
2754 BGP_STR
2755 GR_CMD
2756 )
2757 {
2758 int ret = BGP_GR_FAILURE;
2759
2760 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2761 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2762
2763 VTY_DECLVAR_CONTEXT(bgp, bgp);
2764
2765 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2766
2767 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2768 ret);
2769
2770 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2771 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2772 vty_out(vty,
2773 "Graceful restart configuration changed, reset all peers to take effect\n");
2774 return bgp_vty_return(vty, ret);
2775 }
2776
2777 DEFUN (no_bgp_graceful_restart,
2778 no_bgp_graceful_restart_cmd,
2779 "no bgp graceful-restart",
2780 NO_STR
2781 BGP_STR
2782 NO_GR_CMD
2783 )
2784 {
2785 VTY_DECLVAR_CONTEXT(bgp, bgp);
2786
2787 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2788 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2789
2790 int ret = BGP_GR_FAILURE;
2791
2792 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2793
2794 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2795 ret);
2796
2797 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2798 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2799 vty_out(vty,
2800 "Graceful restart configuration changed, reset all peers to take effect\n");
2801
2802 return bgp_vty_return(vty, ret);
2803 }
2804
2805 DEFUN (bgp_graceful_restart_stalepath_time,
2806 bgp_graceful_restart_stalepath_time_cmd,
2807 "bgp graceful-restart stalepath-time (1-4095)",
2808 BGP_STR
2809 "Graceful restart capability parameters\n"
2810 "Set the max time to hold onto restarting peer's stale paths\n"
2811 "Delay value (seconds)\n")
2812 {
2813 VTY_DECLVAR_CONTEXT(bgp, bgp);
2814 int idx_number = 3;
2815 uint32_t stalepath;
2816
2817 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2818 bgp->stalepath_time = stalepath;
2819 return CMD_SUCCESS;
2820 }
2821
2822 DEFUN (bgp_graceful_restart_restart_time,
2823 bgp_graceful_restart_restart_time_cmd,
2824 "bgp graceful-restart restart-time (0-4095)",
2825 BGP_STR
2826 "Graceful restart capability parameters\n"
2827 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2828 "Delay value (seconds)\n")
2829 {
2830 VTY_DECLVAR_CONTEXT(bgp, bgp);
2831 int idx_number = 3;
2832 uint32_t restart;
2833
2834 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2835 bgp->restart_time = restart;
2836 return CMD_SUCCESS;
2837 }
2838
2839 DEFUN (bgp_graceful_restart_select_defer_time,
2840 bgp_graceful_restart_select_defer_time_cmd,
2841 "bgp graceful-restart select-defer-time (0-3600)",
2842 BGP_STR
2843 "Graceful restart capability parameters\n"
2844 "Set the time to defer the BGP route selection after restart\n"
2845 "Delay value (seconds, 0 - disable)\n")
2846 {
2847 VTY_DECLVAR_CONTEXT(bgp, bgp);
2848 int idx_number = 3;
2849 uint32_t defer_time;
2850
2851 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2852 bgp->select_defer_time = defer_time;
2853 if (defer_time == 0)
2854 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2855 else
2856 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2857
2858 return CMD_SUCCESS;
2859 }
2860
2861 DEFUN (no_bgp_graceful_restart_stalepath_time,
2862 no_bgp_graceful_restart_stalepath_time_cmd,
2863 "no bgp graceful-restart stalepath-time [(1-4095)]",
2864 NO_STR
2865 BGP_STR
2866 "Graceful restart capability parameters\n"
2867 "Set the max time to hold onto restarting peer's stale paths\n"
2868 "Delay value (seconds)\n")
2869 {
2870 VTY_DECLVAR_CONTEXT(bgp, bgp);
2871
2872 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2873 return CMD_SUCCESS;
2874 }
2875
2876 DEFUN (no_bgp_graceful_restart_restart_time,
2877 no_bgp_graceful_restart_restart_time_cmd,
2878 "no bgp graceful-restart restart-time [(0-4095)]",
2879 NO_STR
2880 BGP_STR
2881 "Graceful restart capability parameters\n"
2882 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2883 "Delay value (seconds)\n")
2884 {
2885 VTY_DECLVAR_CONTEXT(bgp, bgp);
2886
2887 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2888 return CMD_SUCCESS;
2889 }
2890
2891 DEFUN (no_bgp_graceful_restart_select_defer_time,
2892 no_bgp_graceful_restart_select_defer_time_cmd,
2893 "no bgp graceful-restart select-defer-time [(0-3600)]",
2894 NO_STR
2895 BGP_STR
2896 "Graceful restart capability parameters\n"
2897 "Set the time to defer the BGP route selection after restart\n"
2898 "Delay value (seconds)\n")
2899 {
2900 VTY_DECLVAR_CONTEXT(bgp, bgp);
2901
2902 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2903 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2904
2905 return CMD_SUCCESS;
2906 }
2907
2908 DEFUN (bgp_graceful_restart_preserve_fw,
2909 bgp_graceful_restart_preserve_fw_cmd,
2910 "bgp graceful-restart preserve-fw-state",
2911 BGP_STR
2912 "Graceful restart capability parameters\n"
2913 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2914 {
2915 VTY_DECLVAR_CONTEXT(bgp, bgp);
2916 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2917 return CMD_SUCCESS;
2918 }
2919
2920 DEFUN (no_bgp_graceful_restart_preserve_fw,
2921 no_bgp_graceful_restart_preserve_fw_cmd,
2922 "no bgp graceful-restart preserve-fw-state",
2923 NO_STR
2924 BGP_STR
2925 "Graceful restart capability parameters\n"
2926 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2927 {
2928 VTY_DECLVAR_CONTEXT(bgp, bgp);
2929 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2930 return CMD_SUCCESS;
2931 }
2932
2933 DEFPY (bgp_graceful_restart_notification,
2934 bgp_graceful_restart_notification_cmd,
2935 "[no$no] bgp graceful-restart notification",
2936 NO_STR
2937 BGP_STR
2938 "Graceful restart capability parameters\n"
2939 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
2940 {
2941 VTY_DECLVAR_CONTEXT(bgp, bgp);
2942
2943 if (no)
2944 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2945 else
2946 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2947
2948 return CMD_SUCCESS;
2949 }
2950
2951 DEFPY (bgp_administrative_reset,
2952 bgp_administrative_reset_cmd,
2953 "[no$no] bgp hard-administrative-reset",
2954 NO_STR
2955 BGP_STR
2956 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
2957 {
2958 VTY_DECLVAR_CONTEXT(bgp, bgp);
2959
2960 if (no)
2961 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2962 else
2963 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2964
2965 return CMD_SUCCESS;
2966 }
2967
2968 DEFUN (bgp_graceful_restart_disable,
2969 bgp_graceful_restart_disable_cmd,
2970 "bgp graceful-restart-disable",
2971 BGP_STR
2972 GR_DISABLE)
2973 {
2974 int ret = BGP_GR_FAILURE;
2975
2976 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2977 zlog_debug(
2978 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2979
2980 VTY_DECLVAR_CONTEXT(bgp, bgp);
2981
2982 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2983
2984 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2985 bgp->peer, ret);
2986
2987 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2988 zlog_debug(
2989 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2990 vty_out(vty,
2991 "Graceful restart configuration changed, reset all peers to take effect\n");
2992
2993 return bgp_vty_return(vty, ret);
2994 }
2995
2996 DEFUN (no_bgp_graceful_restart_disable,
2997 no_bgp_graceful_restart_disable_cmd,
2998 "no bgp graceful-restart-disable",
2999 NO_STR
3000 BGP_STR
3001 NO_GR_DISABLE
3002 )
3003 {
3004 VTY_DECLVAR_CONTEXT(bgp, bgp);
3005
3006 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3007 zlog_debug(
3008 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3009
3010 int ret = BGP_GR_FAILURE;
3011
3012 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3013
3014 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3015 ret);
3016
3017 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3018 zlog_debug(
3019 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3020 vty_out(vty,
3021 "Graceful restart configuration changed, reset all peers to take effect\n");
3022
3023 return bgp_vty_return(vty, ret);
3024 }
3025
3026 DEFUN (bgp_neighbor_graceful_restart_set,
3027 bgp_neighbor_graceful_restart_set_cmd,
3028 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3029 NEIGHBOR_STR
3030 NEIGHBOR_ADDR_STR2
3031 GR_NEIGHBOR_CMD
3032 )
3033 {
3034 int idx_peer = 1;
3035 struct peer *peer;
3036 int ret = BGP_GR_FAILURE;
3037
3038 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3039
3040 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3041 zlog_debug(
3042 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3043
3044 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3045 if (!peer)
3046 return CMD_WARNING_CONFIG_FAILED;
3047
3048 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3049
3050 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3051 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3052
3053 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3054 zlog_debug(
3055 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3056 vty_out(vty,
3057 "Graceful restart configuration changed, reset this peer to take effect\n");
3058
3059 return bgp_vty_return(vty, ret);
3060 }
3061
3062 DEFUN (no_bgp_neighbor_graceful_restart,
3063 no_bgp_neighbor_graceful_restart_set_cmd,
3064 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3065 NO_STR
3066 NEIGHBOR_STR
3067 NEIGHBOR_ADDR_STR2
3068 NO_GR_NEIGHBOR_CMD
3069 )
3070 {
3071 int idx_peer = 2;
3072 int ret = BGP_GR_FAILURE;
3073 struct peer *peer;
3074
3075 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3076
3077 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3078 if (!peer)
3079 return CMD_WARNING_CONFIG_FAILED;
3080
3081 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3082 zlog_debug(
3083 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3084
3085 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3086
3087 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3088 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3089
3090 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3091 zlog_debug(
3092 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3093 vty_out(vty,
3094 "Graceful restart configuration changed, reset this peer to take effect\n");
3095
3096 return bgp_vty_return(vty, ret);
3097 }
3098
3099 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3100 bgp_neighbor_graceful_restart_helper_set_cmd,
3101 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3102 NEIGHBOR_STR
3103 NEIGHBOR_ADDR_STR2
3104 GR_NEIGHBOR_HELPER_CMD
3105 )
3106 {
3107 int idx_peer = 1;
3108 struct peer *peer;
3109 int ret = BGP_GR_FAILURE;
3110
3111 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3112
3113 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3114 zlog_debug(
3115 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3116
3117 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3118
3119 if (!peer)
3120 return CMD_WARNING_CONFIG_FAILED;
3121
3122
3123 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3124
3125 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3126 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3127
3128 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3129 zlog_debug(
3130 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3131 vty_out(vty,
3132 "Graceful restart configuration changed, reset this peer to take effect\n");
3133
3134 return bgp_vty_return(vty, ret);
3135 }
3136
3137 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3138 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3139 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3140 NO_STR
3141 NEIGHBOR_STR
3142 NEIGHBOR_ADDR_STR2
3143 NO_GR_NEIGHBOR_HELPER_CMD
3144 )
3145 {
3146 int idx_peer = 2;
3147 int ret = BGP_GR_FAILURE;
3148 struct peer *peer;
3149
3150 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3151
3152 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3153 if (!peer)
3154 return CMD_WARNING_CONFIG_FAILED;
3155
3156 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3157 zlog_debug(
3158 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3159
3160 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3161
3162 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3163 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3164
3165 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3166 zlog_debug(
3167 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3168 vty_out(vty,
3169 "Graceful restart configuration changed, reset this peer to take effect\n");
3170
3171 return bgp_vty_return(vty, ret);
3172 }
3173
3174 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3175 bgp_neighbor_graceful_restart_disable_set_cmd,
3176 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3177 NEIGHBOR_STR
3178 NEIGHBOR_ADDR_STR2
3179 GR_NEIGHBOR_DISABLE_CMD
3180 )
3181 {
3182 int idx_peer = 1;
3183 struct peer *peer;
3184 int ret = BGP_GR_FAILURE;
3185
3186 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3187
3188 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3189 zlog_debug(
3190 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3191
3192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3193 if (!peer)
3194 return CMD_WARNING_CONFIG_FAILED;
3195
3196 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3197
3198 if (peer->bgp->t_startup)
3199 bgp_peer_gr_flags_update(peer);
3200
3201 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3202 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3203
3204 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3205 zlog_debug(
3206 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3207 vty_out(vty,
3208 "Graceful restart configuration changed, reset this peer to take effect\n");
3209
3210 return bgp_vty_return(vty, ret);
3211 }
3212
3213 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3214 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3215 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3216 NO_STR
3217 NEIGHBOR_STR
3218 NEIGHBOR_ADDR_STR2
3219 NO_GR_NEIGHBOR_DISABLE_CMD
3220 )
3221 {
3222 int idx_peer = 2;
3223 int ret = BGP_GR_FAILURE;
3224 struct peer *peer;
3225
3226 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3227
3228 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3229 if (!peer)
3230 return CMD_WARNING_CONFIG_FAILED;
3231
3232 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3233 zlog_debug(
3234 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3235
3236 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3237
3238 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3239 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3240
3241 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3242 zlog_debug(
3243 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3244 vty_out(vty,
3245 "Graceful restart configuration changed, reset this peer to take effect\n");
3246
3247 return bgp_vty_return(vty, ret);
3248 }
3249
3250 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3251 bgp_graceful_restart_disable_eor_cmd,
3252 "bgp graceful-restart disable-eor",
3253 BGP_STR
3254 "Graceful restart configuration parameters\n"
3255 "Disable EOR Check\n")
3256 {
3257 VTY_DECLVAR_CONTEXT(bgp, bgp);
3258 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3259
3260 return CMD_SUCCESS;
3261 }
3262
3263 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3264 no_bgp_graceful_restart_disable_eor_cmd,
3265 "no bgp graceful-restart disable-eor",
3266 NO_STR
3267 BGP_STR
3268 "Graceful restart configuration parameters\n"
3269 "Disable EOR Check\n")
3270 {
3271 VTY_DECLVAR_CONTEXT(bgp, bgp);
3272 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3273
3274 return CMD_SUCCESS;
3275 }
3276
3277 DEFUN (bgp_graceful_restart_rib_stale_time,
3278 bgp_graceful_restart_rib_stale_time_cmd,
3279 "bgp graceful-restart rib-stale-time (1-3600)",
3280 BGP_STR
3281 "Graceful restart configuration parameters\n"
3282 "Specify the stale route removal timer in rib\n"
3283 "Delay value (seconds)\n")
3284 {
3285 VTY_DECLVAR_CONTEXT(bgp, bgp);
3286 int idx_number = 3;
3287 uint32_t stale_time;
3288
3289 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3290 bgp->rib_stale_time = stale_time;
3291 /* Send the stale timer update message to RIB */
3292 if (bgp_zebra_stale_timer_update(bgp))
3293 return CMD_WARNING;
3294
3295 return CMD_SUCCESS;
3296 }
3297
3298 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3299 no_bgp_graceful_restart_rib_stale_time_cmd,
3300 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3301 NO_STR
3302 BGP_STR
3303 "Graceful restart configuration parameters\n"
3304 "Specify the stale route removal timer in rib\n"
3305 "Delay value (seconds)\n")
3306 {
3307 VTY_DECLVAR_CONTEXT(bgp, bgp);
3308
3309 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3310 /* Send the stale timer update message to RIB */
3311 if (bgp_zebra_stale_timer_update(bgp))
3312 return CMD_WARNING;
3313
3314 return CMD_SUCCESS;
3315 }
3316
3317 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3318 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3319 BGP_STR
3320 "Enable Long-lived Graceful Restart\n"
3321 "Specifies maximum time to wait before purging long-lived stale routes\n"
3322 "Stale time value (seconds)\n")
3323 {
3324 VTY_DECLVAR_CONTEXT(bgp, bgp);
3325
3326 uint32_t llgr_stale_time;
3327
3328 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3329 bgp->llgr_stale_time = llgr_stale_time;
3330
3331 return CMD_SUCCESS;
3332 }
3333
3334 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3335 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3336 NO_STR BGP_STR
3337 "Enable Long-lived Graceful Restart\n"
3338 "Specifies maximum time to wait before purging long-lived stale routes\n"
3339 "Stale time value (seconds)\n")
3340 {
3341 VTY_DECLVAR_CONTEXT(bgp, bgp);
3342
3343 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3344
3345 return CMD_SUCCESS;
3346 }
3347
3348 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3349 struct bgp *bgp)
3350 {
3351 bgp_static_redo_import_check(bgp);
3352 bgp_redistribute_redo(bgp);
3353 bgp_clear_star_soft_out(vty, bgp->name);
3354 bgp_clear_star_soft_in(vty, bgp->name);
3355 }
3356
3357 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3358 {
3359 struct listnode *node, *nnode;
3360 struct bgp *bgp;
3361 bool vrf_cfg = false;
3362
3363 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3364 return CMD_SUCCESS;
3365
3366 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3367 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3368 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3369 vty_out(vty,
3370 "%% graceful-shutdown configuration found in vrf %s\n",
3371 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3372 VRF_DEFAULT_NAME : bgp->name);
3373 vrf_cfg = true;
3374 }
3375 }
3376
3377 if (vrf_cfg) {
3378 vty_out(vty,
3379 "%%Failed: global graceful-shutdown not permitted\n");
3380 return CMD_WARNING;
3381 }
3382
3383 /* Set flag globally */
3384 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3385
3386 /* Initiate processing for all BGP instances. */
3387 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3388 bgp_initiate_graceful_shut_unshut(vty, bgp);
3389
3390 return CMD_SUCCESS;
3391 }
3392
3393 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3394 {
3395 struct listnode *node, *nnode;
3396 struct bgp *bgp;
3397
3398 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3399 return CMD_SUCCESS;
3400
3401 /* Unset flag globally */
3402 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3403
3404 /* Initiate processing for all BGP instances. */
3405 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3406 bgp_initiate_graceful_shut_unshut(vty, bgp);
3407
3408 return CMD_SUCCESS;
3409 }
3410
3411 /* "bgp graceful-shutdown" configuration */
3412 DEFUN (bgp_graceful_shutdown,
3413 bgp_graceful_shutdown_cmd,
3414 "bgp graceful-shutdown",
3415 BGP_STR
3416 "Graceful shutdown parameters\n")
3417 {
3418 if (vty->node == CONFIG_NODE)
3419 return bgp_global_graceful_shutdown_config_vty(vty);
3420
3421 VTY_DECLVAR_CONTEXT(bgp, bgp);
3422
3423 /* if configured globally, per-instance config is not allowed */
3424 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3425 vty_out(vty,
3426 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3427 return CMD_WARNING_CONFIG_FAILED;
3428 }
3429
3430 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3431 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3432 bgp_initiate_graceful_shut_unshut(vty, bgp);
3433 }
3434
3435 return CMD_SUCCESS;
3436 }
3437
3438 DEFUN (no_bgp_graceful_shutdown,
3439 no_bgp_graceful_shutdown_cmd,
3440 "no bgp graceful-shutdown",
3441 NO_STR
3442 BGP_STR
3443 "Graceful shutdown parameters\n")
3444 {
3445 if (vty->node == CONFIG_NODE)
3446 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3447
3448 VTY_DECLVAR_CONTEXT(bgp, bgp);
3449
3450 /* If configured globally, cannot remove from one bgp instance */
3451 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3452 vty_out(vty,
3453 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3454 return CMD_WARNING_CONFIG_FAILED;
3455 }
3456
3457 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3458 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3459 bgp_initiate_graceful_shut_unshut(vty, bgp);
3460 }
3461
3462 return CMD_SUCCESS;
3463 }
3464
3465 /* "bgp fast-external-failover" configuration. */
3466 DEFUN (bgp_fast_external_failover,
3467 bgp_fast_external_failover_cmd,
3468 "bgp fast-external-failover",
3469 BGP_STR
3470 "Immediately reset session if a link to a directly connected external peer goes down\n")
3471 {
3472 VTY_DECLVAR_CONTEXT(bgp, bgp);
3473 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3474 return CMD_SUCCESS;
3475 }
3476
3477 DEFUN (no_bgp_fast_external_failover,
3478 no_bgp_fast_external_failover_cmd,
3479 "no bgp fast-external-failover",
3480 NO_STR
3481 BGP_STR
3482 "Immediately reset session if a link to a directly connected external peer goes down\n")
3483 {
3484 VTY_DECLVAR_CONTEXT(bgp, bgp);
3485 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3486 return CMD_SUCCESS;
3487 }
3488
3489 /* "bgp bestpath compare-routerid" configuration. */
3490 DEFUN (bgp_bestpath_compare_router_id,
3491 bgp_bestpath_compare_router_id_cmd,
3492 "bgp bestpath compare-routerid",
3493 BGP_STR
3494 "Change the default bestpath selection\n"
3495 "Compare router-id for identical EBGP paths\n")
3496 {
3497 VTY_DECLVAR_CONTEXT(bgp, bgp);
3498 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3499 bgp_recalculate_all_bestpaths(bgp);
3500
3501 return CMD_SUCCESS;
3502 }
3503
3504 DEFUN (no_bgp_bestpath_compare_router_id,
3505 no_bgp_bestpath_compare_router_id_cmd,
3506 "no bgp bestpath compare-routerid",
3507 NO_STR
3508 BGP_STR
3509 "Change the default bestpath selection\n"
3510 "Compare router-id for identical EBGP paths\n")
3511 {
3512 VTY_DECLVAR_CONTEXT(bgp, bgp);
3513 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3514 bgp_recalculate_all_bestpaths(bgp);
3515
3516 return CMD_SUCCESS;
3517 }
3518
3519 /* "bgp bestpath as-path ignore" configuration. */
3520 DEFUN (bgp_bestpath_aspath_ignore,
3521 bgp_bestpath_aspath_ignore_cmd,
3522 "bgp bestpath as-path ignore",
3523 BGP_STR
3524 "Change the default bestpath selection\n"
3525 "AS-path attribute\n"
3526 "Ignore as-path length in selecting a route\n")
3527 {
3528 VTY_DECLVAR_CONTEXT(bgp, bgp);
3529 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3530 bgp_recalculate_all_bestpaths(bgp);
3531
3532 return CMD_SUCCESS;
3533 }
3534
3535 DEFUN (no_bgp_bestpath_aspath_ignore,
3536 no_bgp_bestpath_aspath_ignore_cmd,
3537 "no bgp bestpath as-path ignore",
3538 NO_STR
3539 BGP_STR
3540 "Change the default bestpath selection\n"
3541 "AS-path attribute\n"
3542 "Ignore as-path length in selecting a route\n")
3543 {
3544 VTY_DECLVAR_CONTEXT(bgp, bgp);
3545 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3546 bgp_recalculate_all_bestpaths(bgp);
3547
3548 return CMD_SUCCESS;
3549 }
3550
3551 /* "bgp bestpath as-path confed" configuration. */
3552 DEFUN (bgp_bestpath_aspath_confed,
3553 bgp_bestpath_aspath_confed_cmd,
3554 "bgp bestpath as-path confed",
3555 BGP_STR
3556 "Change the default bestpath selection\n"
3557 "AS-path attribute\n"
3558 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3559 {
3560 VTY_DECLVAR_CONTEXT(bgp, bgp);
3561 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3562 bgp_recalculate_all_bestpaths(bgp);
3563
3564 return CMD_SUCCESS;
3565 }
3566
3567 DEFUN (no_bgp_bestpath_aspath_confed,
3568 no_bgp_bestpath_aspath_confed_cmd,
3569 "no bgp bestpath as-path confed",
3570 NO_STR
3571 BGP_STR
3572 "Change the default bestpath selection\n"
3573 "AS-path attribute\n"
3574 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3575 {
3576 VTY_DECLVAR_CONTEXT(bgp, bgp);
3577 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3578 bgp_recalculate_all_bestpaths(bgp);
3579
3580 return CMD_SUCCESS;
3581 }
3582
3583 /* "bgp bestpath as-path multipath-relax" configuration. */
3584 DEFUN (bgp_bestpath_aspath_multipath_relax,
3585 bgp_bestpath_aspath_multipath_relax_cmd,
3586 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3587 BGP_STR
3588 "Change the default bestpath selection\n"
3589 "AS-path attribute\n"
3590 "Allow load sharing across routes that have different AS paths (but same length)\n"
3591 "Generate an AS_SET\n"
3592 "Do not generate an AS_SET\n")
3593 {
3594 VTY_DECLVAR_CONTEXT(bgp, bgp);
3595 int idx = 0;
3596 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3597
3598 /* no-as-set is now the default behavior so we can silently
3599 * ignore it */
3600 if (argv_find(argv, argc, "as-set", &idx))
3601 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3602 else
3603 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3604
3605 bgp_recalculate_all_bestpaths(bgp);
3606
3607 return CMD_SUCCESS;
3608 }
3609
3610 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3611 no_bgp_bestpath_aspath_multipath_relax_cmd,
3612 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3613 NO_STR
3614 BGP_STR
3615 "Change the default bestpath selection\n"
3616 "AS-path attribute\n"
3617 "Allow load sharing across routes that have different AS paths (but same length)\n"
3618 "Generate an AS_SET\n"
3619 "Do not generate an AS_SET\n")
3620 {
3621 VTY_DECLVAR_CONTEXT(bgp, bgp);
3622 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3623 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3624 bgp_recalculate_all_bestpaths(bgp);
3625
3626 return CMD_SUCCESS;
3627 }
3628
3629 /* "bgp bestpath peer-type multipath-relax" configuration. */
3630 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3631 bgp_bestpath_peer_type_multipath_relax_cmd,
3632 "bgp bestpath peer-type multipath-relax",
3633 BGP_STR
3634 "Change the default bestpath selection\n"
3635 "Peer type\n"
3636 "Allow load sharing across routes learned from different peer types\n")
3637 {
3638 VTY_DECLVAR_CONTEXT(bgp, bgp);
3639 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3640 bgp_recalculate_all_bestpaths(bgp);
3641
3642 return CMD_SUCCESS;
3643 }
3644
3645 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3646 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3647 "no bgp bestpath peer-type multipath-relax",
3648 NO_STR BGP_STR
3649 "Change the default bestpath selection\n"
3650 "Peer type\n"
3651 "Allow load sharing across routes learned from different peer types\n")
3652 {
3653 VTY_DECLVAR_CONTEXT(bgp, bgp);
3654 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3655 bgp_recalculate_all_bestpaths(bgp);
3656
3657 return CMD_SUCCESS;
3658 }
3659
3660 /* "bgp log-neighbor-changes" configuration. */
3661 DEFUN (bgp_log_neighbor_changes,
3662 bgp_log_neighbor_changes_cmd,
3663 "bgp log-neighbor-changes",
3664 BGP_STR
3665 "Log neighbor up/down and reset reason\n")
3666 {
3667 VTY_DECLVAR_CONTEXT(bgp, bgp);
3668 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3669 return CMD_SUCCESS;
3670 }
3671
3672 DEFUN (no_bgp_log_neighbor_changes,
3673 no_bgp_log_neighbor_changes_cmd,
3674 "no bgp log-neighbor-changes",
3675 NO_STR
3676 BGP_STR
3677 "Log neighbor up/down and reset reason\n")
3678 {
3679 VTY_DECLVAR_CONTEXT(bgp, bgp);
3680 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3681 return CMD_SUCCESS;
3682 }
3683
3684 /* "bgp bestpath med" configuration. */
3685 DEFUN (bgp_bestpath_med,
3686 bgp_bestpath_med_cmd,
3687 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3688 BGP_STR
3689 "Change the default bestpath selection\n"
3690 "MED attribute\n"
3691 "Compare MED among confederation paths\n"
3692 "Treat missing MED as the least preferred one\n"
3693 "Treat missing MED as the least preferred one\n"
3694 "Compare MED among confederation paths\n")
3695 {
3696 VTY_DECLVAR_CONTEXT(bgp, bgp);
3697
3698 int idx = 0;
3699 if (argv_find(argv, argc, "confed", &idx))
3700 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3701 idx = 0;
3702 if (argv_find(argv, argc, "missing-as-worst", &idx))
3703 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3704
3705 bgp_recalculate_all_bestpaths(bgp);
3706
3707 return CMD_SUCCESS;
3708 }
3709
3710 DEFUN (no_bgp_bestpath_med,
3711 no_bgp_bestpath_med_cmd,
3712 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3713 NO_STR
3714 BGP_STR
3715 "Change the default bestpath selection\n"
3716 "MED attribute\n"
3717 "Compare MED among confederation paths\n"
3718 "Treat missing MED as the least preferred one\n"
3719 "Treat missing MED as the least preferred one\n"
3720 "Compare MED among confederation paths\n")
3721 {
3722 VTY_DECLVAR_CONTEXT(bgp, bgp);
3723
3724 int idx = 0;
3725 if (argv_find(argv, argc, "confed", &idx))
3726 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3727 idx = 0;
3728 if (argv_find(argv, argc, "missing-as-worst", &idx))
3729 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3730
3731 bgp_recalculate_all_bestpaths(bgp);
3732
3733 return CMD_SUCCESS;
3734 }
3735
3736 /* "bgp bestpath bandwidth" configuration. */
3737 DEFPY (bgp_bestpath_bw,
3738 bgp_bestpath_bw_cmd,
3739 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3740 BGP_STR
3741 "Change the default bestpath selection\n"
3742 "Link Bandwidth attribute\n"
3743 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3744 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3745 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3746 {
3747 VTY_DECLVAR_CONTEXT(bgp, bgp);
3748 afi_t afi;
3749 safi_t safi;
3750
3751 if (!bw_cfg) {
3752 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3753 return CMD_ERR_INCOMPLETE;
3754 }
3755 if (!strcmp(bw_cfg, "ignore"))
3756 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3757 else if (!strcmp(bw_cfg, "skip-missing"))
3758 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3759 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3760 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3761 else
3762 return CMD_ERR_NO_MATCH;
3763
3764 /* This config is used in route install, so redo that. */
3765 FOREACH_AFI_SAFI (afi, safi) {
3766 if (!bgp_fibupd_safi(safi))
3767 continue;
3768 bgp_zebra_announce_table(bgp, afi, safi);
3769 }
3770
3771 return CMD_SUCCESS;
3772 }
3773
3774 DEFPY (no_bgp_bestpath_bw,
3775 no_bgp_bestpath_bw_cmd,
3776 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3777 NO_STR
3778 BGP_STR
3779 "Change the default bestpath selection\n"
3780 "Link Bandwidth attribute\n"
3781 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3782 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3783 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3784 {
3785 VTY_DECLVAR_CONTEXT(bgp, bgp);
3786 afi_t afi;
3787 safi_t safi;
3788
3789 bgp->lb_handling = BGP_LINK_BW_ECMP;
3790
3791 /* This config is used in route install, so redo that. */
3792 FOREACH_AFI_SAFI (afi, safi) {
3793 if (!bgp_fibupd_safi(safi))
3794 continue;
3795 bgp_zebra_announce_table(bgp, afi, safi);
3796 }
3797 return CMD_SUCCESS;
3798 }
3799
3800 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3801 "[no] bgp default <ipv4-unicast|"
3802 "ipv4-multicast|"
3803 "ipv4-vpn|"
3804 "ipv4-labeled-unicast|"
3805 "ipv4-flowspec|"
3806 "ipv6-unicast|"
3807 "ipv6-multicast|"
3808 "ipv6-vpn|"
3809 "ipv6-labeled-unicast|"
3810 "ipv6-flowspec|"
3811 "l2vpn-evpn>$afi_safi",
3812 NO_STR
3813 BGP_STR
3814 "Configure BGP defaults\n"
3815 "Activate ipv4-unicast for a peer by default\n"
3816 "Activate ipv4-multicast for a peer by default\n"
3817 "Activate ipv4-vpn for a peer by default\n"
3818 "Activate ipv4-labeled-unicast for a peer by default\n"
3819 "Activate ipv4-flowspec for a peer by default\n"
3820 "Activate ipv6-unicast for a peer by default\n"
3821 "Activate ipv6-multicast for a peer by default\n"
3822 "Activate ipv6-vpn for a peer by default\n"
3823 "Activate ipv6-labeled-unicast for a peer by default\n"
3824 "Activate ipv6-flowspec for a peer by default\n"
3825 "Activate l2vpn-evpn for a peer by default\n")
3826 {
3827 VTY_DECLVAR_CONTEXT(bgp, bgp);
3828 char afi_safi_str[strlen(afi_safi) + 1];
3829 char *afi_safi_str_tok;
3830
3831 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3832 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3833 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3834 afi_t afi = bgp_vty_afi_from_str(afi_str);
3835 safi_t safi;
3836
3837 if (strmatch(safi_str, "labeled"))
3838 safi = bgp_vty_safi_from_str("labeled-unicast");
3839 else
3840 safi = bgp_vty_safi_from_str(safi_str);
3841
3842 if (no)
3843 bgp->default_af[afi][safi] = false;
3844 else {
3845 if ((safi == SAFI_LABELED_UNICAST
3846 && bgp->default_af[afi][SAFI_UNICAST])
3847 || (safi == SAFI_UNICAST
3848 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3849 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3850 else
3851 bgp->default_af[afi][safi] = true;
3852 }
3853
3854 return CMD_SUCCESS;
3855 }
3856
3857 /* Display hostname in certain command outputs */
3858 DEFUN (bgp_default_show_hostname,
3859 bgp_default_show_hostname_cmd,
3860 "bgp default show-hostname",
3861 BGP_STR
3862 "Configure BGP defaults\n"
3863 "Show hostname in certain command outputs\n")
3864 {
3865 VTY_DECLVAR_CONTEXT(bgp, bgp);
3866 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3867 return CMD_SUCCESS;
3868 }
3869
3870 DEFUN (no_bgp_default_show_hostname,
3871 no_bgp_default_show_hostname_cmd,
3872 "no bgp default show-hostname",
3873 NO_STR
3874 BGP_STR
3875 "Configure BGP defaults\n"
3876 "Show hostname in certain command outputs\n")
3877 {
3878 VTY_DECLVAR_CONTEXT(bgp, bgp);
3879 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3880 return CMD_SUCCESS;
3881 }
3882
3883 /* Display hostname in certain command outputs */
3884 DEFUN (bgp_default_show_nexthop_hostname,
3885 bgp_default_show_nexthop_hostname_cmd,
3886 "bgp default show-nexthop-hostname",
3887 BGP_STR
3888 "Configure BGP defaults\n"
3889 "Show hostname for nexthop in certain command outputs\n")
3890 {
3891 VTY_DECLVAR_CONTEXT(bgp, bgp);
3892 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3893 return CMD_SUCCESS;
3894 }
3895
3896 DEFUN (no_bgp_default_show_nexthop_hostname,
3897 no_bgp_default_show_nexthop_hostname_cmd,
3898 "no bgp default show-nexthop-hostname",
3899 NO_STR
3900 BGP_STR
3901 "Configure BGP defaults\n"
3902 "Show hostname for nexthop in certain command outputs\n")
3903 {
3904 VTY_DECLVAR_CONTEXT(bgp, bgp);
3905 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3906 return CMD_SUCCESS;
3907 }
3908
3909 /* "bgp network import-check" configuration. */
3910 DEFUN (bgp_network_import_check,
3911 bgp_network_import_check_cmd,
3912 "bgp network import-check",
3913 BGP_STR
3914 "BGP network command\n"
3915 "Check BGP network route exists in IGP\n")
3916 {
3917 VTY_DECLVAR_CONTEXT(bgp, bgp);
3918 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3919 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3920 bgp_static_redo_import_check(bgp);
3921 }
3922
3923 return CMD_SUCCESS;
3924 }
3925
3926 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3927 "bgp network import-check exact",
3928 BGP_STR
3929 "BGP network command\n"
3930 "Check BGP network route exists in IGP\n"
3931 "Match route precisely\n")
3932
3933 DEFUN (no_bgp_network_import_check,
3934 no_bgp_network_import_check_cmd,
3935 "no bgp network import-check",
3936 NO_STR
3937 BGP_STR
3938 "BGP network command\n"
3939 "Check BGP network route exists in IGP\n")
3940 {
3941 VTY_DECLVAR_CONTEXT(bgp, bgp);
3942 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3943 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3944 bgp_static_redo_import_check(bgp);
3945 }
3946
3947 return CMD_SUCCESS;
3948 }
3949
3950 DEFUN (bgp_default_local_preference,
3951 bgp_default_local_preference_cmd,
3952 "bgp default local-preference (0-4294967295)",
3953 BGP_STR
3954 "Configure BGP defaults\n"
3955 "local preference (higher=more preferred)\n"
3956 "Configure default local preference value\n")
3957 {
3958 VTY_DECLVAR_CONTEXT(bgp, bgp);
3959 int idx_number = 3;
3960 uint32_t local_pref;
3961
3962 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3963
3964 bgp_default_local_preference_set(bgp, local_pref);
3965 bgp_clear_star_soft_in(vty, bgp->name);
3966
3967 return CMD_SUCCESS;
3968 }
3969
3970 DEFUN (no_bgp_default_local_preference,
3971 no_bgp_default_local_preference_cmd,
3972 "no bgp default local-preference [(0-4294967295)]",
3973 NO_STR
3974 BGP_STR
3975 "Configure BGP defaults\n"
3976 "local preference (higher=more preferred)\n"
3977 "Configure default local preference value\n")
3978 {
3979 VTY_DECLVAR_CONTEXT(bgp, bgp);
3980 bgp_default_local_preference_unset(bgp);
3981 bgp_clear_star_soft_in(vty, bgp->name);
3982
3983 return CMD_SUCCESS;
3984 }
3985
3986
3987 DEFUN (bgp_default_subgroup_pkt_queue_max,
3988 bgp_default_subgroup_pkt_queue_max_cmd,
3989 "bgp default subgroup-pkt-queue-max (20-100)",
3990 BGP_STR
3991 "Configure BGP defaults\n"
3992 "subgroup-pkt-queue-max\n"
3993 "Configure subgroup packet queue max\n")
3994 {
3995 VTY_DECLVAR_CONTEXT(bgp, bgp);
3996 int idx_number = 3;
3997 uint32_t max_size;
3998
3999 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4000
4001 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4002
4003 return CMD_SUCCESS;
4004 }
4005
4006 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4007 no_bgp_default_subgroup_pkt_queue_max_cmd,
4008 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4009 NO_STR
4010 BGP_STR
4011 "Configure BGP defaults\n"
4012 "subgroup-pkt-queue-max\n"
4013 "Configure subgroup packet queue max\n")
4014 {
4015 VTY_DECLVAR_CONTEXT(bgp, bgp);
4016 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4017 return CMD_SUCCESS;
4018 }
4019
4020
4021 DEFUN (bgp_rr_allow_outbound_policy,
4022 bgp_rr_allow_outbound_policy_cmd,
4023 "bgp route-reflector allow-outbound-policy",
4024 BGP_STR
4025 "Allow modifications made by out route-map\n"
4026 "on ibgp neighbors\n")
4027 {
4028 VTY_DECLVAR_CONTEXT(bgp, bgp);
4029
4030 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4031 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4032 update_group_announce_rrclients(bgp);
4033 bgp_clear_star_soft_out(vty, bgp->name);
4034 }
4035
4036 return CMD_SUCCESS;
4037 }
4038
4039 DEFUN (no_bgp_rr_allow_outbound_policy,
4040 no_bgp_rr_allow_outbound_policy_cmd,
4041 "no bgp route-reflector allow-outbound-policy",
4042 NO_STR
4043 BGP_STR
4044 "Allow modifications made by out route-map\n"
4045 "on ibgp neighbors\n")
4046 {
4047 VTY_DECLVAR_CONTEXT(bgp, bgp);
4048
4049 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4050 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4051 update_group_announce_rrclients(bgp);
4052 bgp_clear_star_soft_out(vty, bgp->name);
4053 }
4054
4055 return CMD_SUCCESS;
4056 }
4057
4058 DEFUN (bgp_listen_limit,
4059 bgp_listen_limit_cmd,
4060 "bgp listen limit (1-65535)",
4061 BGP_STR
4062 "BGP Dynamic Neighbors listen commands\n"
4063 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4064 "Configure Dynamic Neighbors listen limit value\n")
4065 {
4066 VTY_DECLVAR_CONTEXT(bgp, bgp);
4067 int idx_number = 3;
4068 int listen_limit;
4069
4070 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4071
4072 bgp_listen_limit_set(bgp, listen_limit);
4073
4074 return CMD_SUCCESS;
4075 }
4076
4077 DEFUN (no_bgp_listen_limit,
4078 no_bgp_listen_limit_cmd,
4079 "no bgp listen limit [(1-65535)]",
4080 NO_STR
4081 BGP_STR
4082 "BGP Dynamic Neighbors listen commands\n"
4083 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4084 "Configure Dynamic Neighbors listen limit value\n")
4085 {
4086 VTY_DECLVAR_CONTEXT(bgp, bgp);
4087 bgp_listen_limit_unset(bgp);
4088 return CMD_SUCCESS;
4089 }
4090
4091
4092 /*
4093 * Check if this listen range is already configured. Check for exact
4094 * match or overlap based on input.
4095 */
4096 static struct peer_group *listen_range_exists(struct bgp *bgp,
4097 struct prefix *range, int exact)
4098 {
4099 struct listnode *node, *nnode;
4100 struct listnode *node1, *nnode1;
4101 struct peer_group *group;
4102 struct prefix *lr;
4103 afi_t afi;
4104 int match;
4105
4106 afi = family2afi(range->family);
4107 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4108 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4109 lr)) {
4110 if (exact)
4111 match = prefix_same(range, lr);
4112 else
4113 match = (prefix_match(range, lr)
4114 || prefix_match(lr, range));
4115 if (match)
4116 return group;
4117 }
4118 }
4119
4120 return NULL;
4121 }
4122
4123 DEFUN (bgp_listen_range,
4124 bgp_listen_range_cmd,
4125 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4126 BGP_STR
4127 "Configure BGP dynamic neighbors listen range\n"
4128 "Configure BGP dynamic neighbors listen range\n"
4129 NEIGHBOR_ADDR_STR
4130 "Member of the peer-group\n"
4131 "Peer-group name\n")
4132 {
4133 VTY_DECLVAR_CONTEXT(bgp, bgp);
4134 struct prefix range;
4135 struct peer_group *group, *existing_group;
4136 afi_t afi;
4137 int ret;
4138 int idx = 0;
4139
4140 argv_find(argv, argc, "A.B.C.D/M", &idx);
4141 argv_find(argv, argc, "X:X::X:X/M", &idx);
4142 char *prefix = argv[idx]->arg;
4143 argv_find(argv, argc, "PGNAME", &idx);
4144 char *peergroup = argv[idx]->arg;
4145
4146 /* Convert IP prefix string to struct prefix. */
4147 ret = str2prefix(prefix, &range);
4148 if (!ret) {
4149 vty_out(vty, "%% Malformed listen range\n");
4150 return CMD_WARNING_CONFIG_FAILED;
4151 }
4152
4153 afi = family2afi(range.family);
4154
4155 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4156 vty_out(vty,
4157 "%% Malformed listen range (link-local address)\n");
4158 return CMD_WARNING_CONFIG_FAILED;
4159 }
4160
4161 apply_mask(&range);
4162
4163 /* Check if same listen range is already configured. */
4164 existing_group = listen_range_exists(bgp, &range, 1);
4165 if (existing_group) {
4166 if (strcmp(existing_group->name, peergroup) == 0)
4167 return CMD_SUCCESS;
4168 else {
4169 vty_out(vty,
4170 "%% Same listen range is attached to peer-group %s\n",
4171 existing_group->name);
4172 return CMD_WARNING_CONFIG_FAILED;
4173 }
4174 }
4175
4176 /* Check if an overlapping listen range exists. */
4177 if (listen_range_exists(bgp, &range, 0)) {
4178 vty_out(vty,
4179 "%% Listen range overlaps with existing listen range\n");
4180 return CMD_WARNING_CONFIG_FAILED;
4181 }
4182
4183 group = peer_group_lookup(bgp, peergroup);
4184 if (!group) {
4185 vty_out(vty, "%% Configure the peer-group first\n");
4186 return CMD_WARNING_CONFIG_FAILED;
4187 }
4188
4189 ret = peer_group_listen_range_add(group, &range);
4190 return bgp_vty_return(vty, ret);
4191 }
4192
4193 DEFUN (no_bgp_listen_range,
4194 no_bgp_listen_range_cmd,
4195 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4196 NO_STR
4197 BGP_STR
4198 "Unconfigure BGP dynamic neighbors listen range\n"
4199 "Unconfigure BGP dynamic neighbors listen range\n"
4200 NEIGHBOR_ADDR_STR
4201 "Member of the peer-group\n"
4202 "Peer-group name\n")
4203 {
4204 VTY_DECLVAR_CONTEXT(bgp, bgp);
4205 struct prefix range;
4206 struct peer_group *group;
4207 afi_t afi;
4208 int ret;
4209 int idx = 0;
4210
4211 argv_find(argv, argc, "A.B.C.D/M", &idx);
4212 argv_find(argv, argc, "X:X::X:X/M", &idx);
4213 char *prefix = argv[idx]->arg;
4214 argv_find(argv, argc, "PGNAME", &idx);
4215 char *peergroup = argv[idx]->arg;
4216
4217 /* Convert IP prefix string to struct prefix. */
4218 ret = str2prefix(prefix, &range);
4219 if (!ret) {
4220 vty_out(vty, "%% Malformed listen range\n");
4221 return CMD_WARNING_CONFIG_FAILED;
4222 }
4223
4224 afi = family2afi(range.family);
4225
4226 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4227 vty_out(vty,
4228 "%% Malformed listen range (link-local address)\n");
4229 return CMD_WARNING_CONFIG_FAILED;
4230 }
4231
4232 apply_mask(&range);
4233
4234 group = peer_group_lookup(bgp, peergroup);
4235 if (!group) {
4236 vty_out(vty, "%% Peer-group does not exist\n");
4237 return CMD_WARNING_CONFIG_FAILED;
4238 }
4239
4240 ret = peer_group_listen_range_del(group, &range);
4241 return bgp_vty_return(vty, ret);
4242 }
4243
4244 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4245 {
4246 struct peer_group *group;
4247 struct listnode *node, *nnode, *rnode, *nrnode;
4248 struct prefix *range;
4249 afi_t afi;
4250
4251 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4252 vty_out(vty, " bgp listen limit %d\n",
4253 bgp->dynamic_neighbors_limit);
4254
4255 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4256 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4257 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4258 nrnode, range)) {
4259 vty_out(vty,
4260 " bgp listen range %pFX peer-group %s\n",
4261 range, group->name);
4262 }
4263 }
4264 }
4265 }
4266
4267
4268 DEFUN (bgp_disable_connected_route_check,
4269 bgp_disable_connected_route_check_cmd,
4270 "bgp disable-ebgp-connected-route-check",
4271 BGP_STR
4272 "Disable checking if nexthop is connected on ebgp sessions\n")
4273 {
4274 VTY_DECLVAR_CONTEXT(bgp, bgp);
4275 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4276 bgp_clear_star_soft_in(vty, bgp->name);
4277
4278 return CMD_SUCCESS;
4279 }
4280
4281 DEFUN (no_bgp_disable_connected_route_check,
4282 no_bgp_disable_connected_route_check_cmd,
4283 "no bgp disable-ebgp-connected-route-check",
4284 NO_STR
4285 BGP_STR
4286 "Disable checking if nexthop is connected on ebgp sessions\n")
4287 {
4288 VTY_DECLVAR_CONTEXT(bgp, bgp);
4289 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4290 bgp_clear_star_soft_in(vty, bgp->name);
4291
4292 return CMD_SUCCESS;
4293 }
4294
4295
4296 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4297 const char *as_str)
4298 {
4299 VTY_DECLVAR_CONTEXT(bgp, bgp);
4300 int ret;
4301 as_t as;
4302 int as_type = AS_SPECIFIED;
4303 union sockunion su;
4304
4305 if (as_str[0] == 'i') {
4306 as = 0;
4307 as_type = AS_INTERNAL;
4308 } else if (as_str[0] == 'e') {
4309 as = 0;
4310 as_type = AS_EXTERNAL;
4311 } else {
4312 /* Get AS number. */
4313 as = strtoul(as_str, NULL, 10);
4314 }
4315
4316 /* If peer is peer group or interface peer, call proper function. */
4317 ret = str2sockunion(peer_str, &su);
4318 if (ret < 0) {
4319 struct peer *peer;
4320
4321 /* Check if existing interface peer */
4322 peer = peer_lookup_by_conf_if(bgp, peer_str);
4323
4324 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4325
4326 /* if not interface peer, check peer-group settings */
4327 if (ret < 0 && !peer) {
4328 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4329 if (ret < 0) {
4330 vty_out(vty,
4331 "%% Create the peer-group or interface first\n");
4332 return CMD_WARNING_CONFIG_FAILED;
4333 }
4334 return CMD_SUCCESS;
4335 }
4336 } else {
4337 if (peer_address_self_check(bgp, &su)) {
4338 vty_out(vty,
4339 "%% Can not configure the local system as neighbor\n");
4340 return CMD_WARNING_CONFIG_FAILED;
4341 }
4342 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4343 }
4344
4345 return bgp_vty_return(vty, ret);
4346 }
4347
4348 DEFUN (bgp_default_shutdown,
4349 bgp_default_shutdown_cmd,
4350 "[no] bgp default shutdown",
4351 NO_STR
4352 BGP_STR
4353 "Configure BGP defaults\n"
4354 "Apply administrative shutdown to newly configured peers\n")
4355 {
4356 VTY_DECLVAR_CONTEXT(bgp, bgp);
4357 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4358 return CMD_SUCCESS;
4359 }
4360
4361 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4362 BGP_STR
4363 "Administrative shutdown of the BGP instance\n"
4364 "Add a shutdown message (RFC 8203)\n"
4365 "Shutdown message\n")
4366 {
4367 char *msgstr = NULL;
4368
4369 VTY_DECLVAR_CONTEXT(bgp, bgp);
4370
4371 if (argc > 3)
4372 msgstr = argv_concat(argv, argc, 3);
4373
4374 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4375 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4376 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4377 return CMD_WARNING_CONFIG_FAILED;
4378 }
4379
4380 bgp_shutdown_enable(bgp, msgstr);
4381 XFREE(MTYPE_TMP, msgstr);
4382
4383 return CMD_SUCCESS;
4384 }
4385
4386 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4387 BGP_STR "Administrative shutdown of the BGP instance\n")
4388 {
4389 VTY_DECLVAR_CONTEXT(bgp, bgp);
4390
4391 bgp_shutdown_enable(bgp, NULL);
4392
4393 return CMD_SUCCESS;
4394 }
4395
4396 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4397 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4398 {
4399 VTY_DECLVAR_CONTEXT(bgp, bgp);
4400
4401 bgp_shutdown_disable(bgp);
4402
4403 return CMD_SUCCESS;
4404 }
4405
4406 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4407 "no bgp shutdown message MSG...", NO_STR BGP_STR
4408 "Administrative shutdown of the BGP instance\n"
4409 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4410
4411 DEFUN (neighbor_remote_as,
4412 neighbor_remote_as_cmd,
4413 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4414 NEIGHBOR_STR
4415 NEIGHBOR_ADDR_STR2
4416 "Specify a BGP neighbor\n"
4417 AS_STR
4418 "Internal BGP peer\n"
4419 "External BGP peer\n")
4420 {
4421 int idx_peer = 1;
4422 int idx_remote_as = 3;
4423 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4424 argv[idx_remote_as]->arg);
4425 }
4426 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4427 * sessions do not wait for hold timer expiry to bring down the sessions
4428 * when nexthop becomes unreachable
4429 */
4430 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4431 BGP_STR "Fast convergence for bgp sessions\n")
4432 {
4433 VTY_DECLVAR_CONTEXT(bgp, bgp);
4434 bgp->fast_convergence = true;
4435
4436 return CMD_SUCCESS;
4437 }
4438
4439 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4440 "no bgp fast-convergence",
4441 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4442 {
4443 VTY_DECLVAR_CONTEXT(bgp, bgp);
4444 bgp->fast_convergence = false;
4445
4446 return CMD_SUCCESS;
4447 }
4448
4449 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4450 int v6only,
4451 const char *peer_group_name,
4452 const char *as_str)
4453 {
4454 VTY_DECLVAR_CONTEXT(bgp, bgp);
4455 as_t as = 0;
4456 int as_type = AS_UNSPECIFIED;
4457 struct peer *peer;
4458 struct peer_group *group;
4459 int ret = 0;
4460
4461 group = peer_group_lookup(bgp, conf_if);
4462
4463 if (group) {
4464 vty_out(vty, "%% Name conflict with peer-group \n");
4465 return CMD_WARNING_CONFIG_FAILED;
4466 }
4467
4468 if (as_str) {
4469 if (as_str[0] == 'i') {
4470 as_type = AS_INTERNAL;
4471 } else if (as_str[0] == 'e') {
4472 as_type = AS_EXTERNAL;
4473 } else {
4474 /* Get AS number. */
4475 as = strtoul(as_str, NULL, 10);
4476 as_type = AS_SPECIFIED;
4477 }
4478 }
4479
4480 peer = peer_lookup_by_conf_if(bgp, conf_if);
4481 if (peer) {
4482 if (as_str)
4483 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4484 } else {
4485 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4486 NULL);
4487
4488 if (!peer) {
4489 vty_out(vty, "%% BGP failed to create peer\n");
4490 return CMD_WARNING_CONFIG_FAILED;
4491 }
4492
4493 if (v6only)
4494 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4495
4496 /* Request zebra to initiate IPv6 RAs on this interface. We do
4497 * this
4498 * any unnumbered peer in order to not worry about run-time
4499 * transitions
4500 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4501 * address
4502 * gets deleted later etc.)
4503 */
4504 if (peer->ifp)
4505 bgp_zebra_initiate_radv(bgp, peer);
4506 }
4507
4508 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4509 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4510 if (v6only)
4511 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4512 else
4513 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4514
4515 /* v6only flag changed. Reset bgp seesion */
4516 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4517 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4518 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4519 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4520 } else
4521 bgp_session_reset(peer);
4522 }
4523
4524 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4525 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4526 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4527 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4528 }
4529
4530 if (peer_group_name) {
4531 group = peer_group_lookup(bgp, peer_group_name);
4532 if (!group) {
4533 vty_out(vty, "%% Configure the peer-group first\n");
4534 return CMD_WARNING_CONFIG_FAILED;
4535 }
4536
4537 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4538 }
4539
4540 return bgp_vty_return(vty, ret);
4541 }
4542
4543 DEFUN (neighbor_interface_config,
4544 neighbor_interface_config_cmd,
4545 "neighbor WORD interface [peer-group PGNAME]",
4546 NEIGHBOR_STR
4547 "Interface name or neighbor tag\n"
4548 "Enable BGP on interface\n"
4549 "Member of the peer-group\n"
4550 "Peer-group name\n")
4551 {
4552 int idx_word = 1;
4553 int idx_peer_group_word = 4;
4554
4555 if (argc > idx_peer_group_word)
4556 return peer_conf_interface_get(
4557 vty, argv[idx_word]->arg, 0,
4558 argv[idx_peer_group_word]->arg, NULL);
4559 else
4560 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4561 NULL, NULL);
4562 }
4563
4564 DEFUN (neighbor_interface_config_v6only,
4565 neighbor_interface_config_v6only_cmd,
4566 "neighbor WORD interface v6only [peer-group PGNAME]",
4567 NEIGHBOR_STR
4568 "Interface name or neighbor tag\n"
4569 "Enable BGP on interface\n"
4570 "Enable BGP with v6 link-local only\n"
4571 "Member of the peer-group\n"
4572 "Peer-group name\n")
4573 {
4574 int idx_word = 1;
4575 int idx_peer_group_word = 5;
4576
4577 if (argc > idx_peer_group_word)
4578 return peer_conf_interface_get(
4579 vty, argv[idx_word]->arg, 1,
4580 argv[idx_peer_group_word]->arg, NULL);
4581
4582 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4583 }
4584
4585
4586 DEFUN (neighbor_interface_config_remote_as,
4587 neighbor_interface_config_remote_as_cmd,
4588 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4589 NEIGHBOR_STR
4590 "Interface name or neighbor tag\n"
4591 "Enable BGP on interface\n"
4592 "Specify a BGP neighbor\n"
4593 AS_STR
4594 "Internal BGP peer\n"
4595 "External BGP peer\n")
4596 {
4597 int idx_word = 1;
4598 int idx_remote_as = 4;
4599 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4600 argv[idx_remote_as]->arg);
4601 }
4602
4603 DEFUN (neighbor_interface_v6only_config_remote_as,
4604 neighbor_interface_v6only_config_remote_as_cmd,
4605 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4606 NEIGHBOR_STR
4607 "Interface name or neighbor tag\n"
4608 "Enable BGP with v6 link-local only\n"
4609 "Enable BGP on interface\n"
4610 "Specify a BGP neighbor\n"
4611 AS_STR
4612 "Internal BGP peer\n"
4613 "External BGP peer\n")
4614 {
4615 int idx_word = 1;
4616 int idx_remote_as = 5;
4617 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4618 argv[idx_remote_as]->arg);
4619 }
4620
4621 DEFUN (neighbor_peer_group,
4622 neighbor_peer_group_cmd,
4623 "neighbor WORD peer-group",
4624 NEIGHBOR_STR
4625 "Interface name or neighbor tag\n"
4626 "Configure peer-group\n")
4627 {
4628 VTY_DECLVAR_CONTEXT(bgp, bgp);
4629 int idx_word = 1;
4630 struct peer *peer;
4631 struct peer_group *group;
4632
4633 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4634 if (peer) {
4635 vty_out(vty, "%% Name conflict with interface: \n");
4636 return CMD_WARNING_CONFIG_FAILED;
4637 }
4638
4639 group = peer_group_get(bgp, argv[idx_word]->arg);
4640 if (!group) {
4641 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4642 return CMD_WARNING_CONFIG_FAILED;
4643 }
4644
4645 return CMD_SUCCESS;
4646 }
4647
4648 DEFUN (no_neighbor,
4649 no_neighbor_cmd,
4650 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4651 NO_STR
4652 NEIGHBOR_STR
4653 NEIGHBOR_ADDR_STR2
4654 "Specify a BGP neighbor\n"
4655 AS_STR
4656 "Internal BGP peer\n"
4657 "External BGP peer\n")
4658 {
4659 VTY_DECLVAR_CONTEXT(bgp, bgp);
4660 int idx_peer = 2;
4661 int ret;
4662 union sockunion su;
4663 struct peer_group *group;
4664 struct peer *peer;
4665 struct peer *other;
4666
4667 ret = str2sockunion(argv[idx_peer]->arg, &su);
4668 if (ret < 0) {
4669 /* look up for neighbor by interface name config. */
4670 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4671 if (peer) {
4672 /* Request zebra to terminate IPv6 RAs on this
4673 * interface. */
4674 if (peer->ifp)
4675 bgp_zebra_terminate_radv(peer->bgp, peer);
4676 peer_notify_unconfig(peer);
4677 peer_delete(peer);
4678 return CMD_SUCCESS;
4679 }
4680
4681 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4682 if (group) {
4683 peer_group_notify_unconfig(group);
4684 peer_group_delete(group);
4685 } else {
4686 vty_out(vty, "%% Create the peer-group first\n");
4687 return CMD_WARNING_CONFIG_FAILED;
4688 }
4689 } else {
4690 peer = peer_lookup(bgp, &su);
4691 if (peer) {
4692 if (peer_dynamic_neighbor(peer)) {
4693 vty_out(vty,
4694 "%% Operation not allowed on a dynamic neighbor\n");
4695 return CMD_WARNING_CONFIG_FAILED;
4696 }
4697
4698 other = peer->doppelganger;
4699
4700 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4701 bgp_zebra_terminate_radv(peer->bgp, peer);
4702
4703 peer_notify_unconfig(peer);
4704 peer_delete(peer);
4705 if (other && other->status != Deleted) {
4706 peer_notify_unconfig(other);
4707 peer_delete(other);
4708 }
4709 }
4710 }
4711
4712 return CMD_SUCCESS;
4713 }
4714
4715 DEFUN (no_neighbor_interface_config,
4716 no_neighbor_interface_config_cmd,
4717 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4718 NO_STR
4719 NEIGHBOR_STR
4720 "Interface name\n"
4721 "Configure BGP on interface\n"
4722 "Enable BGP with v6 link-local only\n"
4723 "Member of the peer-group\n"
4724 "Peer-group name\n"
4725 "Specify a BGP neighbor\n"
4726 AS_STR
4727 "Internal BGP peer\n"
4728 "External BGP peer\n")
4729 {
4730 VTY_DECLVAR_CONTEXT(bgp, bgp);
4731 int idx_word = 2;
4732 struct peer *peer;
4733
4734 /* look up for neighbor by interface name config. */
4735 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4736 if (peer) {
4737 /* Request zebra to terminate IPv6 RAs on this interface. */
4738 if (peer->ifp)
4739 bgp_zebra_terminate_radv(peer->bgp, peer);
4740 peer_notify_unconfig(peer);
4741 peer_delete(peer);
4742 } else {
4743 vty_out(vty, "%% Create the bgp interface first\n");
4744 return CMD_WARNING_CONFIG_FAILED;
4745 }
4746 return CMD_SUCCESS;
4747 }
4748
4749 DEFUN (no_neighbor_peer_group,
4750 no_neighbor_peer_group_cmd,
4751 "no neighbor WORD peer-group",
4752 NO_STR
4753 NEIGHBOR_STR
4754 "Neighbor tag\n"
4755 "Configure peer-group\n")
4756 {
4757 VTY_DECLVAR_CONTEXT(bgp, bgp);
4758 int idx_word = 2;
4759 struct peer_group *group;
4760
4761 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4762 if (group) {
4763 peer_group_notify_unconfig(group);
4764 peer_group_delete(group);
4765 } else {
4766 vty_out(vty, "%% Create the peer-group first\n");
4767 return CMD_WARNING_CONFIG_FAILED;
4768 }
4769 return CMD_SUCCESS;
4770 }
4771
4772 DEFUN (no_neighbor_interface_peer_group_remote_as,
4773 no_neighbor_interface_peer_group_remote_as_cmd,
4774 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4775 NO_STR
4776 NEIGHBOR_STR
4777 "Interface name or neighbor tag\n"
4778 "Specify a BGP neighbor\n"
4779 AS_STR
4780 "Internal BGP peer\n"
4781 "External BGP peer\n")
4782 {
4783 VTY_DECLVAR_CONTEXT(bgp, bgp);
4784 int idx_word = 2;
4785 struct peer_group *group;
4786 struct peer *peer;
4787
4788 /* look up for neighbor by interface name config. */
4789 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4790 if (peer) {
4791 peer_as_change(peer, 0, AS_UNSPECIFIED);
4792 return CMD_SUCCESS;
4793 }
4794
4795 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4796 if (group)
4797 peer_group_remote_as_delete(group);
4798 else {
4799 vty_out(vty, "%% Create the peer-group or interface first\n");
4800 return CMD_WARNING_CONFIG_FAILED;
4801 }
4802 return CMD_SUCCESS;
4803 }
4804
4805 DEFUN (neighbor_local_as,
4806 neighbor_local_as_cmd,
4807 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4808 NEIGHBOR_STR
4809 NEIGHBOR_ADDR_STR2
4810 "Specify a local-as number\n"
4811 "AS number used as local AS\n")
4812 {
4813 int idx_peer = 1;
4814 int idx_number = 3;
4815 struct peer *peer;
4816 int ret;
4817 as_t as;
4818
4819 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4820 if (!peer)
4821 return CMD_WARNING_CONFIG_FAILED;
4822
4823 as = strtoul(argv[idx_number]->arg, NULL, 10);
4824 ret = peer_local_as_set(peer, as, 0, 0);
4825 return bgp_vty_return(vty, ret);
4826 }
4827
4828 DEFUN (neighbor_local_as_no_prepend,
4829 neighbor_local_as_no_prepend_cmd,
4830 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4831 NEIGHBOR_STR
4832 NEIGHBOR_ADDR_STR2
4833 "Specify a local-as number\n"
4834 "AS number used as local AS\n"
4835 "Do not prepend local-as to updates from ebgp peers\n")
4836 {
4837 int idx_peer = 1;
4838 int idx_number = 3;
4839 struct peer *peer;
4840 int ret;
4841 as_t as;
4842
4843 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4844 if (!peer)
4845 return CMD_WARNING_CONFIG_FAILED;
4846
4847 as = strtoul(argv[idx_number]->arg, NULL, 10);
4848 ret = peer_local_as_set(peer, as, 1, 0);
4849 return bgp_vty_return(vty, ret);
4850 }
4851
4852 DEFUN (neighbor_local_as_no_prepend_replace_as,
4853 neighbor_local_as_no_prepend_replace_as_cmd,
4854 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4855 NEIGHBOR_STR
4856 NEIGHBOR_ADDR_STR2
4857 "Specify a local-as number\n"
4858 "AS number used as local AS\n"
4859 "Do not prepend local-as to updates from ebgp peers\n"
4860 "Do not prepend local-as to updates from ibgp peers\n")
4861 {
4862 int idx_peer = 1;
4863 int idx_number = 3;
4864 struct peer *peer;
4865 int ret;
4866 as_t as;
4867
4868 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4869 if (!peer)
4870 return CMD_WARNING_CONFIG_FAILED;
4871
4872 as = strtoul(argv[idx_number]->arg, NULL, 10);
4873 ret = peer_local_as_set(peer, as, 1, 1);
4874 return bgp_vty_return(vty, ret);
4875 }
4876
4877 DEFUN (no_neighbor_local_as,
4878 no_neighbor_local_as_cmd,
4879 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4880 NO_STR
4881 NEIGHBOR_STR
4882 NEIGHBOR_ADDR_STR2
4883 "Specify a local-as number\n"
4884 "AS number used as local AS\n"
4885 "Do not prepend local-as to updates from ebgp peers\n"
4886 "Do not prepend local-as to updates from ibgp peers\n")
4887 {
4888 int idx_peer = 2;
4889 struct peer *peer;
4890 int ret;
4891
4892 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4893 if (!peer)
4894 return CMD_WARNING_CONFIG_FAILED;
4895
4896 ret = peer_local_as_unset(peer);
4897 return bgp_vty_return(vty, ret);
4898 }
4899
4900
4901 DEFUN (neighbor_solo,
4902 neighbor_solo_cmd,
4903 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4904 NEIGHBOR_STR
4905 NEIGHBOR_ADDR_STR2
4906 "Solo peer - part of its own update group\n")
4907 {
4908 int idx_peer = 1;
4909 struct peer *peer;
4910 int ret;
4911
4912 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4913 if (!peer)
4914 return CMD_WARNING_CONFIG_FAILED;
4915
4916 ret = update_group_adjust_soloness(peer, 1);
4917 return bgp_vty_return(vty, ret);
4918 }
4919
4920 DEFUN (no_neighbor_solo,
4921 no_neighbor_solo_cmd,
4922 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4923 NO_STR
4924 NEIGHBOR_STR
4925 NEIGHBOR_ADDR_STR2
4926 "Solo peer - part of its own update group\n")
4927 {
4928 int idx_peer = 2;
4929 struct peer *peer;
4930 int ret;
4931
4932 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4933 if (!peer)
4934 return CMD_WARNING_CONFIG_FAILED;
4935
4936 ret = update_group_adjust_soloness(peer, 0);
4937 return bgp_vty_return(vty, ret);
4938 }
4939
4940 DEFUN (neighbor_password,
4941 neighbor_password_cmd,
4942 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4943 NEIGHBOR_STR
4944 NEIGHBOR_ADDR_STR2
4945 "Set a password\n"
4946 "The password\n")
4947 {
4948 int idx_peer = 1;
4949 int idx_line = 3;
4950 struct peer *peer;
4951 int ret;
4952
4953 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4954 if (!peer)
4955 return CMD_WARNING_CONFIG_FAILED;
4956
4957 ret = peer_password_set(peer, argv[idx_line]->arg);
4958 return bgp_vty_return(vty, ret);
4959 }
4960
4961 DEFUN (no_neighbor_password,
4962 no_neighbor_password_cmd,
4963 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4964 NO_STR
4965 NEIGHBOR_STR
4966 NEIGHBOR_ADDR_STR2
4967 "Set a password\n"
4968 "The password\n")
4969 {
4970 int idx_peer = 2;
4971 struct peer *peer;
4972 int ret;
4973
4974 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4975 if (!peer)
4976 return CMD_WARNING_CONFIG_FAILED;
4977
4978 ret = peer_password_unset(peer);
4979 return bgp_vty_return(vty, ret);
4980 }
4981
4982 DEFUN (neighbor_activate,
4983 neighbor_activate_cmd,
4984 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4985 NEIGHBOR_STR
4986 NEIGHBOR_ADDR_STR2
4987 "Enable the Address Family for this Neighbor\n")
4988 {
4989 int idx_peer = 1;
4990 int ret;
4991 struct peer *peer;
4992
4993 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4994 if (!peer)
4995 return CMD_WARNING_CONFIG_FAILED;
4996
4997 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4998 return bgp_vty_return(vty, ret);
4999 }
5000
5001 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5002 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5003 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5004 "Enable the Address Family for this Neighbor\n")
5005
5006 DEFUN (no_neighbor_activate,
5007 no_neighbor_activate_cmd,
5008 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5009 NO_STR
5010 NEIGHBOR_STR
5011 NEIGHBOR_ADDR_STR2
5012 "Enable the Address Family for this Neighbor\n")
5013 {
5014 int idx_peer = 2;
5015 int ret;
5016 struct peer *peer;
5017
5018 /* Lookup peer. */
5019 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5020 if (!peer)
5021 return CMD_WARNING_CONFIG_FAILED;
5022
5023 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5024 return bgp_vty_return(vty, ret);
5025 }
5026
5027 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5028 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5029 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5030 "Enable the Address Family for this Neighbor\n")
5031
5032 DEFUN (neighbor_set_peer_group,
5033 neighbor_set_peer_group_cmd,
5034 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5035 NEIGHBOR_STR
5036 NEIGHBOR_ADDR_STR2
5037 "Member of the peer-group\n"
5038 "Peer-group name\n")
5039 {
5040 VTY_DECLVAR_CONTEXT(bgp, bgp);
5041 int idx_peer = 1;
5042 int idx_word = 3;
5043 int ret;
5044 as_t as;
5045 union sockunion su;
5046 struct peer *peer;
5047 struct peer_group *group;
5048
5049 ret = str2sockunion(argv[idx_peer]->arg, &su);
5050 if (ret < 0) {
5051 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5052 if (!peer) {
5053 vty_out(vty, "%% Malformed address or name: %s\n",
5054 argv[idx_peer]->arg);
5055 return CMD_WARNING_CONFIG_FAILED;
5056 }
5057 } else {
5058 if (peer_address_self_check(bgp, &su)) {
5059 vty_out(vty,
5060 "%% Can not configure the local system as neighbor\n");
5061 return CMD_WARNING_CONFIG_FAILED;
5062 }
5063
5064 /* Disallow for dynamic neighbor. */
5065 peer = peer_lookup(bgp, &su);
5066 if (peer && peer_dynamic_neighbor(peer)) {
5067 vty_out(vty,
5068 "%% Operation not allowed on a dynamic neighbor\n");
5069 return CMD_WARNING_CONFIG_FAILED;
5070 }
5071 }
5072
5073 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5074 if (!group) {
5075 vty_out(vty, "%% Configure the peer-group first\n");
5076 return CMD_WARNING_CONFIG_FAILED;
5077 }
5078
5079 ret = peer_group_bind(bgp, &su, peer, group, &as);
5080
5081 return bgp_vty_return(vty, ret);
5082 }
5083
5084 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5085 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5086 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5087 "Member of the peer-group\n"
5088 "Peer-group name\n")
5089
5090 DEFUN (no_neighbor_set_peer_group,
5091 no_neighbor_set_peer_group_cmd,
5092 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5093 NO_STR
5094 NEIGHBOR_STR
5095 NEIGHBOR_ADDR_STR2
5096 "Member of the peer-group\n"
5097 "Peer-group name\n")
5098 {
5099 VTY_DECLVAR_CONTEXT(bgp, bgp);
5100 int idx_peer = 2;
5101 int idx_word = 4;
5102 int ret;
5103 struct peer *peer;
5104 struct peer_group *group;
5105
5106 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5107 if (!peer)
5108 return CMD_WARNING_CONFIG_FAILED;
5109
5110 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5111 if (!group) {
5112 vty_out(vty, "%% Configure the peer-group first\n");
5113 return CMD_WARNING_CONFIG_FAILED;
5114 }
5115
5116 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5117 bgp_zebra_terminate_radv(peer->bgp, peer);
5118
5119 peer_notify_unconfig(peer);
5120 ret = peer_delete(peer);
5121
5122 return bgp_vty_return(vty, ret);
5123 }
5124
5125 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5126 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5127 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5128 "Member of the peer-group\n"
5129 "Peer-group name\n")
5130
5131 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5132 uint32_t flag, int set)
5133 {
5134 int ret;
5135 struct peer *peer;
5136
5137 peer = peer_and_group_lookup_vty(vty, ip_str);
5138 if (!peer)
5139 return CMD_WARNING_CONFIG_FAILED;
5140
5141 /*
5142 * If 'neighbor <interface>', then this is for directly connected peers,
5143 * we should not accept disable-connected-check.
5144 */
5145 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5146 vty_out(vty,
5147 "%s is directly connected peer, cannot accept disable-connected-check\n",
5148 ip_str);
5149 return CMD_WARNING_CONFIG_FAILED;
5150 }
5151
5152 if (!set && flag == PEER_FLAG_SHUTDOWN)
5153 peer_tx_shutdown_message_unset(peer);
5154
5155 if (set)
5156 ret = peer_flag_set(peer, flag);
5157 else
5158 ret = peer_flag_unset(peer, flag);
5159
5160 return bgp_vty_return(vty, ret);
5161 }
5162
5163 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5164 {
5165 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5166 }
5167
5168 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5169 uint32_t flag)
5170 {
5171 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5172 }
5173
5174 /* neighbor passive. */
5175 DEFUN (neighbor_passive,
5176 neighbor_passive_cmd,
5177 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5178 NEIGHBOR_STR
5179 NEIGHBOR_ADDR_STR2
5180 "Don't send open messages to this neighbor\n")
5181 {
5182 int idx_peer = 1;
5183 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5184 }
5185
5186 DEFUN (no_neighbor_passive,
5187 no_neighbor_passive_cmd,
5188 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5189 NO_STR
5190 NEIGHBOR_STR
5191 NEIGHBOR_ADDR_STR2
5192 "Don't send open messages to this neighbor\n")
5193 {
5194 int idx_peer = 2;
5195 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5196 }
5197
5198 /* neighbor shutdown. */
5199 DEFUN (neighbor_shutdown_msg,
5200 neighbor_shutdown_msg_cmd,
5201 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5202 NEIGHBOR_STR
5203 NEIGHBOR_ADDR_STR2
5204 "Administratively shut down this neighbor\n"
5205 "Add a shutdown message (RFC 8203)\n"
5206 "Shutdown message\n")
5207 {
5208 int idx_peer = 1;
5209
5210 if (argc >= 5) {
5211 struct peer *peer =
5212 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5213 char *message;
5214
5215 if (!peer)
5216 return CMD_WARNING_CONFIG_FAILED;
5217 message = argv_concat(argv, argc, 4);
5218 peer_tx_shutdown_message_set(peer, message);
5219 XFREE(MTYPE_TMP, message);
5220 }
5221
5222 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5223 }
5224
5225 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5226 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5227 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5228 "Administratively shut down this neighbor\n")
5229
5230 DEFUN (no_neighbor_shutdown_msg,
5231 no_neighbor_shutdown_msg_cmd,
5232 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5233 NO_STR
5234 NEIGHBOR_STR
5235 NEIGHBOR_ADDR_STR2
5236 "Administratively shut down this neighbor\n"
5237 "Remove a shutdown message (RFC 8203)\n"
5238 "Shutdown message\n")
5239 {
5240 int idx_peer = 2;
5241
5242 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5243 PEER_FLAG_SHUTDOWN);
5244 }
5245
5246 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5247 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5248 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5249 "Administratively shut down this neighbor\n")
5250
5251 DEFUN(neighbor_shutdown_rtt,
5252 neighbor_shutdown_rtt_cmd,
5253 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5254 NEIGHBOR_STR
5255 NEIGHBOR_ADDR_STR2
5256 "Administratively shut down this neighbor\n"
5257 "Shutdown if round-trip-time is higher than expected\n"
5258 "Round-trip-time in milliseconds\n"
5259 "Specify the number of keepalives before shutdown\n"
5260 "The number of keepalives with higher RTT to shutdown\n")
5261 {
5262 int idx_peer = 1;
5263 int idx_rtt = 4;
5264 int idx_count = 0;
5265 struct peer *peer;
5266
5267 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5268
5269 if (!peer)
5270 return CMD_WARNING_CONFIG_FAILED;
5271
5272 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5273
5274 if (argv_find(argv, argc, "count", &idx_count))
5275 peer->rtt_keepalive_conf =
5276 strtol(argv[idx_count + 1]->arg, NULL, 10);
5277
5278 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5279 PEER_FLAG_RTT_SHUTDOWN);
5280 }
5281
5282 DEFUN(no_neighbor_shutdown_rtt,
5283 no_neighbor_shutdown_rtt_cmd,
5284 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5285 NO_STR
5286 NEIGHBOR_STR
5287 NEIGHBOR_ADDR_STR2
5288 "Administratively shut down this neighbor\n"
5289 "Shutdown if round-trip-time is higher than expected\n"
5290 "Round-trip-time in milliseconds\n"
5291 "Specify the number of keepalives before shutdown\n"
5292 "The number of keepalives with higher RTT to shutdown\n")
5293 {
5294 int idx_peer = 2;
5295 struct peer *peer;
5296
5297 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5298
5299 if (!peer)
5300 return CMD_WARNING_CONFIG_FAILED;
5301
5302 peer->rtt_expected = 0;
5303 peer->rtt_keepalive_conf = 1;
5304
5305 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5306 PEER_FLAG_RTT_SHUTDOWN);
5307 }
5308
5309 /* neighbor capability dynamic. */
5310 DEFUN (neighbor_capability_dynamic,
5311 neighbor_capability_dynamic_cmd,
5312 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5313 NEIGHBOR_STR
5314 NEIGHBOR_ADDR_STR2
5315 "Advertise capability to the peer\n"
5316 "Advertise dynamic capability to this neighbor\n")
5317 {
5318 int idx_peer = 1;
5319 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5320 PEER_FLAG_DYNAMIC_CAPABILITY);
5321 }
5322
5323 DEFUN (no_neighbor_capability_dynamic,
5324 no_neighbor_capability_dynamic_cmd,
5325 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5326 NO_STR
5327 NEIGHBOR_STR
5328 NEIGHBOR_ADDR_STR2
5329 "Advertise capability to the peer\n"
5330 "Advertise dynamic capability to this neighbor\n")
5331 {
5332 int idx_peer = 2;
5333 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5334 PEER_FLAG_DYNAMIC_CAPABILITY);
5335 }
5336
5337 /* neighbor dont-capability-negotiate */
5338 DEFUN (neighbor_dont_capability_negotiate,
5339 neighbor_dont_capability_negotiate_cmd,
5340 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5341 NEIGHBOR_STR
5342 NEIGHBOR_ADDR_STR2
5343 "Do not perform capability negotiation\n")
5344 {
5345 int idx_peer = 1;
5346 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5347 PEER_FLAG_DONT_CAPABILITY);
5348 }
5349
5350 DEFUN (no_neighbor_dont_capability_negotiate,
5351 no_neighbor_dont_capability_negotiate_cmd,
5352 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5353 NO_STR
5354 NEIGHBOR_STR
5355 NEIGHBOR_ADDR_STR2
5356 "Do not perform capability negotiation\n")
5357 {
5358 int idx_peer = 2;
5359 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5360 PEER_FLAG_DONT_CAPABILITY);
5361 }
5362
5363 /* neighbor capability extended next hop encoding */
5364 DEFUN (neighbor_capability_enhe,
5365 neighbor_capability_enhe_cmd,
5366 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5367 NEIGHBOR_STR
5368 NEIGHBOR_ADDR_STR2
5369 "Advertise capability to the peer\n"
5370 "Advertise extended next-hop capability to the peer\n")
5371 {
5372 int idx_peer = 1;
5373 struct peer *peer;
5374
5375 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5376 if (peer && peer->conf_if)
5377 return CMD_SUCCESS;
5378
5379 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5380 PEER_FLAG_CAPABILITY_ENHE);
5381 }
5382
5383 DEFUN (no_neighbor_capability_enhe,
5384 no_neighbor_capability_enhe_cmd,
5385 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5386 NO_STR
5387 NEIGHBOR_STR
5388 NEIGHBOR_ADDR_STR2
5389 "Advertise capability to the peer\n"
5390 "Advertise extended next-hop capability to the peer\n")
5391 {
5392 int idx_peer = 2;
5393 struct peer *peer;
5394
5395 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5396 if (peer && peer->conf_if) {
5397 vty_out(vty,
5398 "Peer %s cannot have capability extended-nexthop turned off\n",
5399 argv[idx_peer]->arg);
5400 return CMD_WARNING_CONFIG_FAILED;
5401 }
5402
5403 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5404 PEER_FLAG_CAPABILITY_ENHE);
5405 }
5406
5407 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5408 afi_t afi, safi_t safi, uint32_t flag,
5409 int set)
5410 {
5411 int ret;
5412 struct peer *peer;
5413
5414 peer = peer_and_group_lookup_vty(vty, peer_str);
5415 if (!peer)
5416 return CMD_WARNING_CONFIG_FAILED;
5417
5418 if (set)
5419 ret = peer_af_flag_set(peer, afi, safi, flag);
5420 else
5421 ret = peer_af_flag_unset(peer, afi, safi, flag);
5422
5423 return bgp_vty_return(vty, ret);
5424 }
5425
5426 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5427 afi_t afi, safi_t safi, uint32_t flag)
5428 {
5429 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5430 }
5431
5432 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5433 afi_t afi, safi_t safi, uint32_t flag)
5434 {
5435 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5436 }
5437
5438 /* neighbor capability orf prefix-list. */
5439 DEFUN (neighbor_capability_orf_prefix,
5440 neighbor_capability_orf_prefix_cmd,
5441 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5442 NEIGHBOR_STR
5443 NEIGHBOR_ADDR_STR2
5444 "Advertise capability to the peer\n"
5445 "Advertise ORF capability to the peer\n"
5446 "Advertise prefixlist ORF capability to this neighbor\n"
5447 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5448 "Capability to RECEIVE the ORF from this neighbor\n"
5449 "Capability to SEND the ORF to this neighbor\n")
5450 {
5451 int idx_send_recv = 5;
5452 char *peer_str = argv[1]->arg;
5453 struct peer *peer;
5454 afi_t afi = bgp_node_afi(vty);
5455 safi_t safi = bgp_node_safi(vty);
5456
5457 peer = peer_and_group_lookup_vty(vty, peer_str);
5458 if (!peer)
5459 return CMD_WARNING_CONFIG_FAILED;
5460
5461 if (strmatch(argv[idx_send_recv]->text, "send"))
5462 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5463 PEER_FLAG_ORF_PREFIX_SM);
5464
5465 if (strmatch(argv[idx_send_recv]->text, "receive"))
5466 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5467 PEER_FLAG_ORF_PREFIX_RM);
5468
5469 if (strmatch(argv[idx_send_recv]->text, "both"))
5470 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5471 PEER_FLAG_ORF_PREFIX_SM)
5472 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5473 PEER_FLAG_ORF_PREFIX_RM);
5474
5475 return CMD_WARNING_CONFIG_FAILED;
5476 }
5477
5478 ALIAS_HIDDEN(
5479 neighbor_capability_orf_prefix,
5480 neighbor_capability_orf_prefix_hidden_cmd,
5481 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5482 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5483 "Advertise capability to the peer\n"
5484 "Advertise ORF capability to the peer\n"
5485 "Advertise prefixlist ORF capability to this neighbor\n"
5486 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5487 "Capability to RECEIVE the ORF from this neighbor\n"
5488 "Capability to SEND the ORF to this neighbor\n")
5489
5490 DEFUN (no_neighbor_capability_orf_prefix,
5491 no_neighbor_capability_orf_prefix_cmd,
5492 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5493 NO_STR
5494 NEIGHBOR_STR
5495 NEIGHBOR_ADDR_STR2
5496 "Advertise capability to the peer\n"
5497 "Advertise ORF capability to the peer\n"
5498 "Advertise prefixlist ORF capability to this neighbor\n"
5499 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5500 "Capability to RECEIVE the ORF from this neighbor\n"
5501 "Capability to SEND the ORF to this neighbor\n")
5502 {
5503 int idx_send_recv = 6;
5504 char *peer_str = argv[2]->arg;
5505 struct peer *peer;
5506 afi_t afi = bgp_node_afi(vty);
5507 safi_t safi = bgp_node_safi(vty);
5508
5509 peer = peer_and_group_lookup_vty(vty, peer_str);
5510 if (!peer)
5511 return CMD_WARNING_CONFIG_FAILED;
5512
5513 if (strmatch(argv[idx_send_recv]->text, "send"))
5514 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5515 PEER_FLAG_ORF_PREFIX_SM);
5516
5517 if (strmatch(argv[idx_send_recv]->text, "receive"))
5518 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5519 PEER_FLAG_ORF_PREFIX_RM);
5520
5521 if (strmatch(argv[idx_send_recv]->text, "both"))
5522 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5523 PEER_FLAG_ORF_PREFIX_SM)
5524 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5525 PEER_FLAG_ORF_PREFIX_RM);
5526
5527 return CMD_WARNING_CONFIG_FAILED;
5528 }
5529
5530 ALIAS_HIDDEN(
5531 no_neighbor_capability_orf_prefix,
5532 no_neighbor_capability_orf_prefix_hidden_cmd,
5533 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5534 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5535 "Advertise capability to the peer\n"
5536 "Advertise ORF capability to the peer\n"
5537 "Advertise prefixlist ORF capability to this neighbor\n"
5538 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5539 "Capability to RECEIVE the ORF from this neighbor\n"
5540 "Capability to SEND the ORF to this neighbor\n")
5541
5542 /* neighbor next-hop-self. */
5543 DEFUN (neighbor_nexthop_self,
5544 neighbor_nexthop_self_cmd,
5545 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5546 NEIGHBOR_STR
5547 NEIGHBOR_ADDR_STR2
5548 "Disable the next hop calculation for this neighbor\n")
5549 {
5550 int idx_peer = 1;
5551 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5552 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5553 }
5554
5555 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5556 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5557 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5558 "Disable the next hop calculation for this neighbor\n")
5559
5560 /* neighbor next-hop-self. */
5561 DEFUN (neighbor_nexthop_self_force,
5562 neighbor_nexthop_self_force_cmd,
5563 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5564 NEIGHBOR_STR
5565 NEIGHBOR_ADDR_STR2
5566 "Disable the next hop calculation for this neighbor\n"
5567 "Set the next hop to self for reflected routes\n")
5568 {
5569 int idx_peer = 1;
5570 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5571 bgp_node_safi(vty),
5572 PEER_FLAG_FORCE_NEXTHOP_SELF);
5573 }
5574
5575 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5576 neighbor_nexthop_self_force_hidden_cmd,
5577 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5578 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5579 "Disable the next hop calculation for this neighbor\n"
5580 "Set the next hop to self for reflected routes\n")
5581
5582 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5583 neighbor_nexthop_self_all_hidden_cmd,
5584 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5585 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5586 "Disable the next hop calculation for this neighbor\n"
5587 "Set the next hop to self for reflected routes\n")
5588
5589 DEFUN (no_neighbor_nexthop_self,
5590 no_neighbor_nexthop_self_cmd,
5591 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5592 NO_STR
5593 NEIGHBOR_STR
5594 NEIGHBOR_ADDR_STR2
5595 "Disable the next hop calculation for this neighbor\n")
5596 {
5597 int idx_peer = 2;
5598 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5599 bgp_node_afi(vty), bgp_node_safi(vty),
5600 PEER_FLAG_NEXTHOP_SELF);
5601 }
5602
5603 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5604 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5605 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5606 "Disable the next hop calculation for this neighbor\n")
5607
5608 DEFUN (no_neighbor_nexthop_self_force,
5609 no_neighbor_nexthop_self_force_cmd,
5610 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5611 NO_STR
5612 NEIGHBOR_STR
5613 NEIGHBOR_ADDR_STR2
5614 "Disable the next hop calculation for this neighbor\n"
5615 "Set the next hop to self for reflected routes\n")
5616 {
5617 int idx_peer = 2;
5618 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5619 bgp_node_afi(vty), bgp_node_safi(vty),
5620 PEER_FLAG_FORCE_NEXTHOP_SELF);
5621 }
5622
5623 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5624 no_neighbor_nexthop_self_force_hidden_cmd,
5625 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5626 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5627 "Disable the next hop calculation for this neighbor\n"
5628 "Set the next hop to self for reflected routes\n")
5629
5630 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5631 no_neighbor_nexthop_self_all_hidden_cmd,
5632 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5633 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5634 "Disable the next hop calculation for this neighbor\n"
5635 "Set the next hop to self for reflected routes\n")
5636
5637 /* neighbor as-override */
5638 DEFUN (neighbor_as_override,
5639 neighbor_as_override_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5641 NEIGHBOR_STR
5642 NEIGHBOR_ADDR_STR2
5643 "Override ASNs in outbound updates if aspath equals remote-as\n")
5644 {
5645 int idx_peer = 1;
5646 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5647 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5648 }
5649
5650 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5651 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5652 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5653 "Override ASNs in outbound updates if aspath equals remote-as\n")
5654
5655 DEFUN (no_neighbor_as_override,
5656 no_neighbor_as_override_cmd,
5657 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5658 NO_STR
5659 NEIGHBOR_STR
5660 NEIGHBOR_ADDR_STR2
5661 "Override ASNs in outbound updates if aspath equals remote-as\n")
5662 {
5663 int idx_peer = 2;
5664 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5665 bgp_node_afi(vty), bgp_node_safi(vty),
5666 PEER_FLAG_AS_OVERRIDE);
5667 }
5668
5669 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5670 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5672 "Override ASNs in outbound updates if aspath equals remote-as\n")
5673
5674 /* neighbor remove-private-AS. */
5675 DEFUN (neighbor_remove_private_as,
5676 neighbor_remove_private_as_cmd,
5677 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5678 NEIGHBOR_STR
5679 NEIGHBOR_ADDR_STR2
5680 "Remove private ASNs in outbound updates\n")
5681 {
5682 int idx_peer = 1;
5683 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5684 bgp_node_safi(vty),
5685 PEER_FLAG_REMOVE_PRIVATE_AS);
5686 }
5687
5688 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5689 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5690 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5691 "Remove private ASNs in outbound updates\n")
5692
5693 DEFUN (neighbor_remove_private_as_all,
5694 neighbor_remove_private_as_all_cmd,
5695 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5696 NEIGHBOR_STR
5697 NEIGHBOR_ADDR_STR2
5698 "Remove private ASNs in outbound updates\n"
5699 "Apply to all AS numbers\n")
5700 {
5701 int idx_peer = 1;
5702 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5703 bgp_node_safi(vty),
5704 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5705 }
5706
5707 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5708 neighbor_remove_private_as_all_hidden_cmd,
5709 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5710 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5711 "Remove private ASNs in outbound updates\n"
5712 "Apply to all AS numbers")
5713
5714 DEFUN (neighbor_remove_private_as_replace_as,
5715 neighbor_remove_private_as_replace_as_cmd,
5716 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5717 NEIGHBOR_STR
5718 NEIGHBOR_ADDR_STR2
5719 "Remove private ASNs in outbound updates\n"
5720 "Replace private ASNs with our ASN in outbound updates\n")
5721 {
5722 int idx_peer = 1;
5723 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5724 bgp_node_safi(vty),
5725 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5726 }
5727
5728 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5729 neighbor_remove_private_as_replace_as_hidden_cmd,
5730 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5731 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5732 "Remove private ASNs in outbound updates\n"
5733 "Replace private ASNs with our ASN in outbound updates\n")
5734
5735 DEFUN (neighbor_remove_private_as_all_replace_as,
5736 neighbor_remove_private_as_all_replace_as_cmd,
5737 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5738 NEIGHBOR_STR
5739 NEIGHBOR_ADDR_STR2
5740 "Remove private ASNs in outbound updates\n"
5741 "Apply to all AS numbers\n"
5742 "Replace private ASNs with our ASN in outbound updates\n")
5743 {
5744 int idx_peer = 1;
5745 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5746 bgp_node_safi(vty),
5747 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5748 }
5749
5750 ALIAS_HIDDEN(
5751 neighbor_remove_private_as_all_replace_as,
5752 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5753 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5754 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5755 "Remove private ASNs in outbound updates\n"
5756 "Apply to all AS numbers\n"
5757 "Replace private ASNs with our ASN in outbound updates\n")
5758
5759 DEFUN (no_neighbor_remove_private_as,
5760 no_neighbor_remove_private_as_cmd,
5761 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5762 NO_STR
5763 NEIGHBOR_STR
5764 NEIGHBOR_ADDR_STR2
5765 "Remove private ASNs in outbound updates\n")
5766 {
5767 int idx_peer = 2;
5768 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5769 bgp_node_afi(vty), bgp_node_safi(vty),
5770 PEER_FLAG_REMOVE_PRIVATE_AS);
5771 }
5772
5773 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5774 no_neighbor_remove_private_as_hidden_cmd,
5775 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5776 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5777 "Remove private ASNs in outbound updates\n")
5778
5779 DEFUN (no_neighbor_remove_private_as_all,
5780 no_neighbor_remove_private_as_all_cmd,
5781 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5782 NO_STR
5783 NEIGHBOR_STR
5784 NEIGHBOR_ADDR_STR2
5785 "Remove private ASNs in outbound updates\n"
5786 "Apply to all AS numbers\n")
5787 {
5788 int idx_peer = 2;
5789 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5790 bgp_node_afi(vty), bgp_node_safi(vty),
5791 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5792 }
5793
5794 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5795 no_neighbor_remove_private_as_all_hidden_cmd,
5796 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5797 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5798 "Remove private ASNs in outbound updates\n"
5799 "Apply to all AS numbers\n")
5800
5801 DEFUN (no_neighbor_remove_private_as_replace_as,
5802 no_neighbor_remove_private_as_replace_as_cmd,
5803 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5804 NO_STR
5805 NEIGHBOR_STR
5806 NEIGHBOR_ADDR_STR2
5807 "Remove private ASNs in outbound updates\n"
5808 "Replace private ASNs with our ASN in outbound updates\n")
5809 {
5810 int idx_peer = 2;
5811 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5812 bgp_node_afi(vty), bgp_node_safi(vty),
5813 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5814 }
5815
5816 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5817 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5818 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5819 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5820 "Remove private ASNs in outbound updates\n"
5821 "Replace private ASNs with our ASN in outbound updates\n")
5822
5823 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5824 no_neighbor_remove_private_as_all_replace_as_cmd,
5825 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5826 NO_STR
5827 NEIGHBOR_STR
5828 NEIGHBOR_ADDR_STR2
5829 "Remove private ASNs in outbound updates\n"
5830 "Apply to all AS numbers\n"
5831 "Replace private ASNs with our ASN in outbound updates\n")
5832 {
5833 int idx_peer = 2;
5834 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5835 bgp_node_afi(vty), bgp_node_safi(vty),
5836 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5837 }
5838
5839 ALIAS_HIDDEN(
5840 no_neighbor_remove_private_as_all_replace_as,
5841 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5842 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5843 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5844 "Remove private ASNs in outbound updates\n"
5845 "Apply to all AS numbers\n"
5846 "Replace private ASNs with our ASN in outbound updates\n")
5847
5848
5849 /* neighbor send-community. */
5850 DEFUN (neighbor_send_community,
5851 neighbor_send_community_cmd,
5852 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5853 NEIGHBOR_STR
5854 NEIGHBOR_ADDR_STR2
5855 "Send Community attribute to this neighbor\n")
5856 {
5857 int idx_peer = 1;
5858
5859 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5860 bgp_node_safi(vty),
5861 PEER_FLAG_SEND_COMMUNITY);
5862 }
5863
5864 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5865 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5866 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5867 "Send Community attribute to this neighbor\n")
5868
5869 DEFUN (no_neighbor_send_community,
5870 no_neighbor_send_community_cmd,
5871 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5872 NO_STR
5873 NEIGHBOR_STR
5874 NEIGHBOR_ADDR_STR2
5875 "Send Community attribute to this neighbor\n")
5876 {
5877 int idx_peer = 2;
5878
5879 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5880 bgp_node_afi(vty), bgp_node_safi(vty),
5881 PEER_FLAG_SEND_COMMUNITY);
5882 }
5883
5884 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5885 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5886 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5887 "Send Community attribute to this neighbor\n")
5888
5889 /* neighbor send-community extended. */
5890 DEFUN (neighbor_send_community_type,
5891 neighbor_send_community_type_cmd,
5892 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5893 NEIGHBOR_STR
5894 NEIGHBOR_ADDR_STR2
5895 "Send Community attribute to this neighbor\n"
5896 "Send Standard and Extended Community attributes\n"
5897 "Send Standard, Large and Extended Community attributes\n"
5898 "Send Extended Community attributes\n"
5899 "Send Standard Community attributes\n"
5900 "Send Large Community attributes\n")
5901 {
5902 const char *type = argv[argc - 1]->text;
5903 char *peer_str = argv[1]->arg;
5904 struct peer *peer;
5905 afi_t afi = bgp_node_afi(vty);
5906 safi_t safi = bgp_node_safi(vty);
5907
5908 peer = peer_and_group_lookup_vty(vty, peer_str);
5909 if (!peer)
5910 return CMD_WARNING_CONFIG_FAILED;
5911
5912 if (strmatch(type, "standard"))
5913 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5914 PEER_FLAG_SEND_COMMUNITY);
5915
5916 if (strmatch(type, "extended"))
5917 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5918 PEER_FLAG_SEND_EXT_COMMUNITY);
5919
5920 if (strmatch(type, "large"))
5921 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5922 PEER_FLAG_SEND_LARGE_COMMUNITY);
5923
5924 if (strmatch(type, "both")) {
5925 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5926 PEER_FLAG_SEND_COMMUNITY)
5927 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5928 PEER_FLAG_SEND_EXT_COMMUNITY);
5929 }
5930 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5931 PEER_FLAG_SEND_COMMUNITY)
5932 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5933 PEER_FLAG_SEND_EXT_COMMUNITY)
5934 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5935 PEER_FLAG_SEND_LARGE_COMMUNITY);
5936 }
5937
5938 ALIAS_HIDDEN(
5939 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5940 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5941 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5942 "Send Community attribute to this neighbor\n"
5943 "Send Standard and Extended Community attributes\n"
5944 "Send Standard, Large and Extended Community attributes\n"
5945 "Send Extended Community attributes\n"
5946 "Send Standard Community attributes\n"
5947 "Send Large Community attributes\n")
5948
5949 DEFUN (no_neighbor_send_community_type,
5950 no_neighbor_send_community_type_cmd,
5951 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5952 NO_STR
5953 NEIGHBOR_STR
5954 NEIGHBOR_ADDR_STR2
5955 "Send Community attribute to this neighbor\n"
5956 "Send Standard and Extended Community attributes\n"
5957 "Send Standard, Large and Extended Community attributes\n"
5958 "Send Extended Community attributes\n"
5959 "Send Standard Community attributes\n"
5960 "Send Large Community attributes\n")
5961 {
5962 const char *type = argv[argc - 1]->text;
5963 char *peer_str = argv[2]->arg;
5964 struct peer *peer;
5965 afi_t afi = bgp_node_afi(vty);
5966 safi_t safi = bgp_node_safi(vty);
5967
5968 peer = peer_and_group_lookup_vty(vty, peer_str);
5969 if (!peer)
5970 return CMD_WARNING_CONFIG_FAILED;
5971
5972 if (strmatch(type, "standard"))
5973 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5974 PEER_FLAG_SEND_COMMUNITY);
5975
5976 if (strmatch(type, "extended"))
5977 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5978 PEER_FLAG_SEND_EXT_COMMUNITY);
5979
5980 if (strmatch(type, "large"))
5981 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5982 PEER_FLAG_SEND_LARGE_COMMUNITY);
5983
5984 if (strmatch(type, "both")) {
5985
5986 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5987 PEER_FLAG_SEND_COMMUNITY)
5988 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5989 PEER_FLAG_SEND_EXT_COMMUNITY);
5990 }
5991
5992 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5993 PEER_FLAG_SEND_COMMUNITY)
5994 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5995 PEER_FLAG_SEND_EXT_COMMUNITY)
5996 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5997 PEER_FLAG_SEND_LARGE_COMMUNITY);
5998 }
5999
6000 ALIAS_HIDDEN(
6001 no_neighbor_send_community_type,
6002 no_neighbor_send_community_type_hidden_cmd,
6003 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6004 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6005 "Send Community attribute to this neighbor\n"
6006 "Send Standard and Extended Community attributes\n"
6007 "Send Standard, Large and Extended Community attributes\n"
6008 "Send Extended Community attributes\n"
6009 "Send Standard Community attributes\n"
6010 "Send Large Community attributes\n")
6011
6012 /* neighbor soft-reconfig. */
6013 DEFUN (neighbor_soft_reconfiguration,
6014 neighbor_soft_reconfiguration_cmd,
6015 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6016 NEIGHBOR_STR
6017 NEIGHBOR_ADDR_STR2
6018 "Per neighbor soft reconfiguration\n"
6019 "Allow inbound soft reconfiguration for this neighbor\n")
6020 {
6021 int idx_peer = 1;
6022 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6023 bgp_node_safi(vty),
6024 PEER_FLAG_SOFT_RECONFIG);
6025 }
6026
6027 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6028 neighbor_soft_reconfiguration_hidden_cmd,
6029 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6031 "Per neighbor soft reconfiguration\n"
6032 "Allow inbound soft reconfiguration for this neighbor\n")
6033
6034 DEFUN (no_neighbor_soft_reconfiguration,
6035 no_neighbor_soft_reconfiguration_cmd,
6036 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6037 NO_STR
6038 NEIGHBOR_STR
6039 NEIGHBOR_ADDR_STR2
6040 "Per neighbor soft reconfiguration\n"
6041 "Allow inbound soft reconfiguration for this neighbor\n")
6042 {
6043 int idx_peer = 2;
6044 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6045 bgp_node_afi(vty), bgp_node_safi(vty),
6046 PEER_FLAG_SOFT_RECONFIG);
6047 }
6048
6049 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6050 no_neighbor_soft_reconfiguration_hidden_cmd,
6051 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6052 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6053 "Per neighbor soft reconfiguration\n"
6054 "Allow inbound soft reconfiguration for this neighbor\n")
6055
6056 DEFUN (neighbor_route_reflector_client,
6057 neighbor_route_reflector_client_cmd,
6058 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6059 NEIGHBOR_STR
6060 NEIGHBOR_ADDR_STR2
6061 "Configure a neighbor as Route Reflector client\n")
6062 {
6063 int idx_peer = 1;
6064 struct peer *peer;
6065
6066
6067 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6068 if (!peer)
6069 return CMD_WARNING_CONFIG_FAILED;
6070
6071 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6072 bgp_node_safi(vty),
6073 PEER_FLAG_REFLECTOR_CLIENT);
6074 }
6075
6076 ALIAS_HIDDEN(neighbor_route_reflector_client,
6077 neighbor_route_reflector_client_hidden_cmd,
6078 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6079 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6080 "Configure a neighbor as Route Reflector client\n")
6081
6082 DEFUN (no_neighbor_route_reflector_client,
6083 no_neighbor_route_reflector_client_cmd,
6084 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6085 NO_STR
6086 NEIGHBOR_STR
6087 NEIGHBOR_ADDR_STR2
6088 "Configure a neighbor as Route Reflector client\n")
6089 {
6090 int idx_peer = 2;
6091 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6092 bgp_node_afi(vty), bgp_node_safi(vty),
6093 PEER_FLAG_REFLECTOR_CLIENT);
6094 }
6095
6096 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6097 no_neighbor_route_reflector_client_hidden_cmd,
6098 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6099 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6100 "Configure a neighbor as Route Reflector client\n")
6101
6102 /* neighbor route-server-client. */
6103 DEFUN (neighbor_route_server_client,
6104 neighbor_route_server_client_cmd,
6105 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6106 NEIGHBOR_STR
6107 NEIGHBOR_ADDR_STR2
6108 "Configure a neighbor as Route Server client\n")
6109 {
6110 int idx_peer = 1;
6111 struct peer *peer;
6112
6113 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6114 if (!peer)
6115 return CMD_WARNING_CONFIG_FAILED;
6116 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6117 bgp_node_safi(vty),
6118 PEER_FLAG_RSERVER_CLIENT);
6119 }
6120
6121 ALIAS_HIDDEN(neighbor_route_server_client,
6122 neighbor_route_server_client_hidden_cmd,
6123 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6124 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6125 "Configure a neighbor as Route Server client\n")
6126
6127 DEFUN (no_neighbor_route_server_client,
6128 no_neighbor_route_server_client_cmd,
6129 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6130 NO_STR
6131 NEIGHBOR_STR
6132 NEIGHBOR_ADDR_STR2
6133 "Configure a neighbor as Route Server client\n")
6134 {
6135 int idx_peer = 2;
6136 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6137 bgp_node_afi(vty), bgp_node_safi(vty),
6138 PEER_FLAG_RSERVER_CLIENT);
6139 }
6140
6141 ALIAS_HIDDEN(no_neighbor_route_server_client,
6142 no_neighbor_route_server_client_hidden_cmd,
6143 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6144 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6145 "Configure a neighbor as Route Server client\n")
6146
6147 DEFUN (neighbor_nexthop_local_unchanged,
6148 neighbor_nexthop_local_unchanged_cmd,
6149 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6150 NEIGHBOR_STR
6151 NEIGHBOR_ADDR_STR2
6152 "Configure treatment of outgoing link-local nexthop attribute\n"
6153 "Leave link-local nexthop unchanged for this peer\n")
6154 {
6155 int idx_peer = 1;
6156 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6157 bgp_node_safi(vty),
6158 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6159 }
6160
6161 DEFUN (no_neighbor_nexthop_local_unchanged,
6162 no_neighbor_nexthop_local_unchanged_cmd,
6163 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6164 NO_STR
6165 NEIGHBOR_STR
6166 NEIGHBOR_ADDR_STR2
6167 "Configure treatment of outgoing link-local-nexthop attribute\n"
6168 "Leave link-local nexthop unchanged for this peer\n")
6169 {
6170 int idx_peer = 2;
6171 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6172 bgp_node_afi(vty), bgp_node_safi(vty),
6173 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6174 }
6175
6176 DEFUN (neighbor_attr_unchanged,
6177 neighbor_attr_unchanged_cmd,
6178 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6179 NEIGHBOR_STR
6180 NEIGHBOR_ADDR_STR2
6181 "BGP attribute is propagated unchanged to this neighbor\n"
6182 "As-path attribute\n"
6183 "Nexthop attribute\n"
6184 "Med attribute\n")
6185 {
6186 int idx = 0;
6187 char *peer_str = argv[1]->arg;
6188 struct peer *peer;
6189 bool aspath = false;
6190 bool nexthop = false;
6191 bool med = false;
6192 afi_t afi = bgp_node_afi(vty);
6193 safi_t safi = bgp_node_safi(vty);
6194 int ret = 0;
6195
6196 peer = peer_and_group_lookup_vty(vty, peer_str);
6197 if (!peer)
6198 return CMD_WARNING_CONFIG_FAILED;
6199
6200 if (argv_find(argv, argc, "as-path", &idx))
6201 aspath = true;
6202
6203 idx = 0;
6204 if (argv_find(argv, argc, "next-hop", &idx))
6205 nexthop = true;
6206
6207 idx = 0;
6208 if (argv_find(argv, argc, "med", &idx))
6209 med = true;
6210
6211 /* no flags means all of them! */
6212 if (!aspath && !nexthop && !med) {
6213 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6214 PEER_FLAG_AS_PATH_UNCHANGED);
6215 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6216 PEER_FLAG_NEXTHOP_UNCHANGED);
6217 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6218 PEER_FLAG_MED_UNCHANGED);
6219 } else {
6220 if (!aspath) {
6221 if (peer_af_flag_check(peer, afi, safi,
6222 PEER_FLAG_AS_PATH_UNCHANGED)) {
6223 ret |= peer_af_flag_unset_vty(
6224 vty, peer_str, afi, safi,
6225 PEER_FLAG_AS_PATH_UNCHANGED);
6226 }
6227 } else
6228 ret |= peer_af_flag_set_vty(
6229 vty, peer_str, afi, safi,
6230 PEER_FLAG_AS_PATH_UNCHANGED);
6231
6232 if (!nexthop) {
6233 if (peer_af_flag_check(peer, afi, safi,
6234 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6235 ret |= peer_af_flag_unset_vty(
6236 vty, peer_str, afi, safi,
6237 PEER_FLAG_NEXTHOP_UNCHANGED);
6238 }
6239 } else
6240 ret |= peer_af_flag_set_vty(
6241 vty, peer_str, afi, safi,
6242 PEER_FLAG_NEXTHOP_UNCHANGED);
6243
6244 if (!med) {
6245 if (peer_af_flag_check(peer, afi, safi,
6246 PEER_FLAG_MED_UNCHANGED)) {
6247 ret |= peer_af_flag_unset_vty(
6248 vty, peer_str, afi, safi,
6249 PEER_FLAG_MED_UNCHANGED);
6250 }
6251 } else
6252 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6253 PEER_FLAG_MED_UNCHANGED);
6254 }
6255
6256 return ret;
6257 }
6258
6259 ALIAS_HIDDEN(
6260 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6261 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6262 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6263 "BGP attribute is propagated unchanged to this neighbor\n"
6264 "As-path attribute\n"
6265 "Nexthop attribute\n"
6266 "Med attribute\n")
6267
6268 DEFUN (no_neighbor_attr_unchanged,
6269 no_neighbor_attr_unchanged_cmd,
6270 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6271 NO_STR
6272 NEIGHBOR_STR
6273 NEIGHBOR_ADDR_STR2
6274 "BGP attribute is propagated unchanged to this neighbor\n"
6275 "As-path attribute\n"
6276 "Nexthop attribute\n"
6277 "Med attribute\n")
6278 {
6279 int idx = 0;
6280 char *peer_str = argv[2]->arg;
6281 struct peer *peer;
6282 bool aspath = false;
6283 bool nexthop = false;
6284 bool med = false;
6285 afi_t afi = bgp_node_afi(vty);
6286 safi_t safi = bgp_node_safi(vty);
6287 int ret = 0;
6288
6289 peer = peer_and_group_lookup_vty(vty, peer_str);
6290 if (!peer)
6291 return CMD_WARNING_CONFIG_FAILED;
6292
6293 if (argv_find(argv, argc, "as-path", &idx))
6294 aspath = true;
6295
6296 idx = 0;
6297 if (argv_find(argv, argc, "next-hop", &idx))
6298 nexthop = true;
6299
6300 idx = 0;
6301 if (argv_find(argv, argc, "med", &idx))
6302 med = true;
6303
6304 if (!aspath && !nexthop && !med) // no flags means all of them!
6305 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6306 PEER_FLAG_AS_PATH_UNCHANGED)
6307 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6308 PEER_FLAG_NEXTHOP_UNCHANGED)
6309 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6310 PEER_FLAG_MED_UNCHANGED);
6311
6312 if (aspath)
6313 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6314 PEER_FLAG_AS_PATH_UNCHANGED);
6315
6316 if (nexthop)
6317 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6318 PEER_FLAG_NEXTHOP_UNCHANGED);
6319
6320 if (med)
6321 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6322 PEER_FLAG_MED_UNCHANGED);
6323
6324 return ret;
6325 }
6326
6327 ALIAS_HIDDEN(
6328 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6329 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6330 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6331 "BGP attribute is propagated unchanged to this neighbor\n"
6332 "As-path attribute\n"
6333 "Nexthop attribute\n"
6334 "Med attribute\n")
6335
6336 /* EBGP multihop configuration. */
6337 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6338 const char *ttl_str)
6339 {
6340 struct peer *peer;
6341 unsigned int ttl;
6342
6343 peer = peer_and_group_lookup_vty(vty, ip_str);
6344 if (!peer)
6345 return CMD_WARNING_CONFIG_FAILED;
6346
6347 if (peer->conf_if)
6348 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6349
6350 if (!ttl_str)
6351 ttl = MAXTTL;
6352 else
6353 ttl = strtoul(ttl_str, NULL, 10);
6354
6355 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6356 }
6357
6358 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6359 {
6360 struct peer *peer;
6361
6362 peer = peer_and_group_lookup_vty(vty, ip_str);
6363 if (!peer)
6364 return CMD_WARNING_CONFIG_FAILED;
6365
6366 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6367 }
6368
6369 /* neighbor ebgp-multihop. */
6370 DEFUN (neighbor_ebgp_multihop,
6371 neighbor_ebgp_multihop_cmd,
6372 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6373 NEIGHBOR_STR
6374 NEIGHBOR_ADDR_STR2
6375 "Allow EBGP neighbors not on directly connected networks\n")
6376 {
6377 int idx_peer = 1;
6378 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6379 }
6380
6381 DEFUN (neighbor_ebgp_multihop_ttl,
6382 neighbor_ebgp_multihop_ttl_cmd,
6383 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6384 NEIGHBOR_STR
6385 NEIGHBOR_ADDR_STR2
6386 "Allow EBGP neighbors not on directly connected networks\n"
6387 "maximum hop count\n")
6388 {
6389 int idx_peer = 1;
6390 int idx_number = 3;
6391 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6392 argv[idx_number]->arg);
6393 }
6394
6395 DEFUN (no_neighbor_ebgp_multihop,
6396 no_neighbor_ebgp_multihop_cmd,
6397 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6398 NO_STR
6399 NEIGHBOR_STR
6400 NEIGHBOR_ADDR_STR2
6401 "Allow EBGP neighbors not on directly connected networks\n"
6402 "maximum hop count\n")
6403 {
6404 int idx_peer = 2;
6405 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6406 }
6407
6408
6409 /* disable-connected-check */
6410 DEFUN (neighbor_disable_connected_check,
6411 neighbor_disable_connected_check_cmd,
6412 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6413 NEIGHBOR_STR
6414 NEIGHBOR_ADDR_STR2
6415 "one-hop away EBGP peer using loopback address\n"
6416 "Enforce EBGP neighbors perform multihop\n")
6417 {
6418 int idx_peer = 1;
6419 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6420 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6421 }
6422
6423 DEFUN (no_neighbor_disable_connected_check,
6424 no_neighbor_disable_connected_check_cmd,
6425 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6426 NO_STR
6427 NEIGHBOR_STR
6428 NEIGHBOR_ADDR_STR2
6429 "one-hop away EBGP peer using loopback address\n"
6430 "Enforce EBGP neighbors perform multihop\n")
6431 {
6432 int idx_peer = 2;
6433 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6434 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6435 }
6436
6437 /* disable-link-bw-encoding-ieee */
6438 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6439 neighbor_disable_link_bw_encoding_ieee_cmd,
6440 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6441 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6442 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6443 {
6444 int idx_peer = 1;
6445
6446 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6447 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6448 }
6449
6450 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6451 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6452 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6453 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6454 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6455 {
6456 int idx_peer = 2;
6457
6458 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6459 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6460 }
6461
6462 /* extended-optional-parameters */
6463 DEFUN(neighbor_extended_optional_parameters,
6464 neighbor_extended_optional_parameters_cmd,
6465 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6466 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6467 "Force the extended optional parameters format for OPEN messages\n")
6468 {
6469 int idx_peer = 1;
6470
6471 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6472 PEER_FLAG_EXTENDED_OPT_PARAMS);
6473 }
6474
6475 DEFUN(no_neighbor_extended_optional_parameters,
6476 no_neighbor_extended_optional_parameters_cmd,
6477 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6478 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6479 "Force the extended optional parameters format for OPEN messages\n")
6480 {
6481 int idx_peer = 2;
6482
6483 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6484 PEER_FLAG_EXTENDED_OPT_PARAMS);
6485 }
6486
6487 /* enforce-first-as */
6488 DEFUN (neighbor_enforce_first_as,
6489 neighbor_enforce_first_as_cmd,
6490 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6491 NEIGHBOR_STR
6492 NEIGHBOR_ADDR_STR2
6493 "Enforce the first AS for EBGP routes\n")
6494 {
6495 int idx_peer = 1;
6496
6497 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6498 PEER_FLAG_ENFORCE_FIRST_AS);
6499 }
6500
6501 DEFUN (no_neighbor_enforce_first_as,
6502 no_neighbor_enforce_first_as_cmd,
6503 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6504 NO_STR
6505 NEIGHBOR_STR
6506 NEIGHBOR_ADDR_STR2
6507 "Enforce the first AS for EBGP routes\n")
6508 {
6509 int idx_peer = 2;
6510
6511 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6512 PEER_FLAG_ENFORCE_FIRST_AS);
6513 }
6514
6515
6516 DEFUN (neighbor_description,
6517 neighbor_description_cmd,
6518 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6519 NEIGHBOR_STR
6520 NEIGHBOR_ADDR_STR2
6521 "Neighbor specific description\n"
6522 "Up to 80 characters describing this neighbor\n")
6523 {
6524 int idx_peer = 1;
6525 int idx_line = 3;
6526 struct peer *peer;
6527 char *str;
6528
6529 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6530 if (!peer)
6531 return CMD_WARNING_CONFIG_FAILED;
6532
6533 str = argv_concat(argv, argc, idx_line);
6534
6535 peer_description_set(peer, str);
6536
6537 XFREE(MTYPE_TMP, str);
6538
6539 return CMD_SUCCESS;
6540 }
6541
6542 DEFUN (no_neighbor_description,
6543 no_neighbor_description_cmd,
6544 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6545 NO_STR
6546 NEIGHBOR_STR
6547 NEIGHBOR_ADDR_STR2
6548 "Neighbor specific description\n")
6549 {
6550 int idx_peer = 2;
6551 struct peer *peer;
6552
6553 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6554 if (!peer)
6555 return CMD_WARNING_CONFIG_FAILED;
6556
6557 peer_description_unset(peer);
6558
6559 return CMD_SUCCESS;
6560 }
6561
6562 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6563 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6564 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6565 "Neighbor specific description\n"
6566 "Up to 80 characters describing this neighbor\n")
6567
6568 /* Neighbor update-source. */
6569 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6570 const char *source_str)
6571 {
6572 struct peer *peer;
6573 struct prefix p;
6574 union sockunion su;
6575
6576 peer = peer_and_group_lookup_vty(vty, peer_str);
6577 if (!peer)
6578 return CMD_WARNING_CONFIG_FAILED;
6579
6580 if (peer->conf_if)
6581 return CMD_WARNING;
6582
6583 if (source_str) {
6584 if (str2sockunion(source_str, &su) == 0)
6585 peer_update_source_addr_set(peer, &su);
6586 else {
6587 if (str2prefix(source_str, &p)) {
6588 vty_out(vty,
6589 "%% Invalid update-source, remove prefix length \n");
6590 return CMD_WARNING_CONFIG_FAILED;
6591 } else
6592 peer_update_source_if_set(peer, source_str);
6593 }
6594 } else
6595 peer_update_source_unset(peer);
6596
6597 return CMD_SUCCESS;
6598 }
6599
6600 #define BGP_UPDATE_SOURCE_HELP_STR \
6601 "IPv4 address\n" \
6602 "IPv6 address\n" \
6603 "Interface name (requires zebra to be running)\n"
6604
6605 DEFUN (neighbor_update_source,
6606 neighbor_update_source_cmd,
6607 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6608 NEIGHBOR_STR
6609 NEIGHBOR_ADDR_STR2
6610 "Source of routing updates\n"
6611 BGP_UPDATE_SOURCE_HELP_STR)
6612 {
6613 int idx_peer = 1;
6614 int idx_peer_2 = 3;
6615 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6616 argv[idx_peer_2]->arg);
6617 }
6618
6619 DEFUN (no_neighbor_update_source,
6620 no_neighbor_update_source_cmd,
6621 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6622 NO_STR
6623 NEIGHBOR_STR
6624 NEIGHBOR_ADDR_STR2
6625 "Source of routing updates\n"
6626 BGP_UPDATE_SOURCE_HELP_STR)
6627 {
6628 int idx_peer = 2;
6629 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6630 }
6631
6632 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6633 afi_t afi, safi_t safi,
6634 const char *rmap, int set)
6635 {
6636 int ret;
6637 struct peer *peer;
6638 struct route_map *route_map = NULL;
6639
6640 peer = peer_and_group_lookup_vty(vty, peer_str);
6641 if (!peer)
6642 return CMD_WARNING_CONFIG_FAILED;
6643
6644 if (set) {
6645 if (rmap)
6646 route_map = route_map_lookup_warn_noexist(vty, rmap);
6647 ret = peer_default_originate_set(peer, afi, safi,
6648 rmap, route_map);
6649 } else
6650 ret = peer_default_originate_unset(peer, afi, safi);
6651
6652 return bgp_vty_return(vty, ret);
6653 }
6654
6655 /* neighbor default-originate. */
6656 DEFUN (neighbor_default_originate,
6657 neighbor_default_originate_cmd,
6658 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6659 NEIGHBOR_STR
6660 NEIGHBOR_ADDR_STR2
6661 "Originate default route to this neighbor\n")
6662 {
6663 int idx_peer = 1;
6664 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6665 bgp_node_afi(vty),
6666 bgp_node_safi(vty), NULL, 1);
6667 }
6668
6669 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6670 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6671 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6672 "Originate default route to this neighbor\n")
6673
6674 DEFUN (neighbor_default_originate_rmap,
6675 neighbor_default_originate_rmap_cmd,
6676 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6677 NEIGHBOR_STR
6678 NEIGHBOR_ADDR_STR2
6679 "Originate default route to this neighbor\n"
6680 "Route-map to specify criteria to originate default\n"
6681 "route-map name\n")
6682 {
6683 int idx_peer = 1;
6684 int idx_word = 4;
6685 return peer_default_originate_set_vty(
6686 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6687 argv[idx_word]->arg, 1);
6688 }
6689
6690 ALIAS_HIDDEN(
6691 neighbor_default_originate_rmap,
6692 neighbor_default_originate_rmap_hidden_cmd,
6693 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6694 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6695 "Originate default route to this neighbor\n"
6696 "Route-map to specify criteria to originate default\n"
6697 "route-map name\n")
6698
6699 DEFUN (no_neighbor_default_originate,
6700 no_neighbor_default_originate_cmd,
6701 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6702 NO_STR
6703 NEIGHBOR_STR
6704 NEIGHBOR_ADDR_STR2
6705 "Originate default route to this neighbor\n"
6706 "Route-map to specify criteria to originate default\n"
6707 "route-map name\n")
6708 {
6709 int idx_peer = 2;
6710 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6711 bgp_node_afi(vty),
6712 bgp_node_safi(vty), NULL, 0);
6713 }
6714
6715 ALIAS_HIDDEN(
6716 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6717 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6718 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6719 "Originate default route to this neighbor\n"
6720 "Route-map to specify criteria to originate default\n"
6721 "route-map name\n")
6722
6723
6724 /* Set neighbor's BGP port. */
6725 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6726 const char *port_str)
6727 {
6728 struct peer *peer;
6729 uint16_t port;
6730 struct servent *sp;
6731
6732 peer = peer_lookup_vty(vty, ip_str);
6733 if (!peer)
6734 return CMD_WARNING_CONFIG_FAILED;
6735
6736 if (!port_str) {
6737 sp = getservbyname("bgp", "tcp");
6738 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6739 } else {
6740 port = strtoul(port_str, NULL, 10);
6741 }
6742
6743 peer_port_set(peer, port);
6744
6745 return CMD_SUCCESS;
6746 }
6747
6748 /* Set specified peer's BGP port. */
6749 DEFUN (neighbor_port,
6750 neighbor_port_cmd,
6751 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6752 NEIGHBOR_STR
6753 NEIGHBOR_ADDR_STR
6754 "Neighbor's BGP port\n"
6755 "TCP port number\n")
6756 {
6757 int idx_ip = 1;
6758 int idx_number = 3;
6759 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6760 argv[idx_number]->arg);
6761 }
6762
6763 DEFUN (no_neighbor_port,
6764 no_neighbor_port_cmd,
6765 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6766 NO_STR
6767 NEIGHBOR_STR
6768 NEIGHBOR_ADDR_STR
6769 "Neighbor's BGP port\n"
6770 "TCP port number\n")
6771 {
6772 int idx_ip = 2;
6773 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6774 }
6775
6776
6777 /* neighbor weight. */
6778 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6779 safi_t safi, const char *weight_str)
6780 {
6781 int ret;
6782 struct peer *peer;
6783 unsigned long weight;
6784
6785 peer = peer_and_group_lookup_vty(vty, ip_str);
6786 if (!peer)
6787 return CMD_WARNING_CONFIG_FAILED;
6788
6789 weight = strtoul(weight_str, NULL, 10);
6790
6791 ret = peer_weight_set(peer, afi, safi, weight);
6792 return bgp_vty_return(vty, ret);
6793 }
6794
6795 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6796 safi_t safi)
6797 {
6798 int ret;
6799 struct peer *peer;
6800
6801 peer = peer_and_group_lookup_vty(vty, ip_str);
6802 if (!peer)
6803 return CMD_WARNING_CONFIG_FAILED;
6804
6805 ret = peer_weight_unset(peer, afi, safi);
6806 return bgp_vty_return(vty, ret);
6807 }
6808
6809 DEFUN (neighbor_weight,
6810 neighbor_weight_cmd,
6811 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6812 NEIGHBOR_STR
6813 NEIGHBOR_ADDR_STR2
6814 "Set default weight for routes from this neighbor\n"
6815 "default weight\n")
6816 {
6817 int idx_peer = 1;
6818 int idx_number = 3;
6819 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6820 bgp_node_safi(vty), argv[idx_number]->arg);
6821 }
6822
6823 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6824 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6825 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6826 "Set default weight for routes from this neighbor\n"
6827 "default weight\n")
6828
6829 DEFUN (no_neighbor_weight,
6830 no_neighbor_weight_cmd,
6831 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6832 NO_STR
6833 NEIGHBOR_STR
6834 NEIGHBOR_ADDR_STR2
6835 "Set default weight for routes from this neighbor\n"
6836 "default weight\n")
6837 {
6838 int idx_peer = 2;
6839 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6840 bgp_node_afi(vty), bgp_node_safi(vty));
6841 }
6842
6843 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6844 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6845 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6846 "Set default weight for routes from this neighbor\n"
6847 "default weight\n")
6848
6849
6850 /* Override capability negotiation. */
6851 DEFUN (neighbor_override_capability,
6852 neighbor_override_capability_cmd,
6853 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6854 NEIGHBOR_STR
6855 NEIGHBOR_ADDR_STR2
6856 "Override capability negotiation result\n")
6857 {
6858 int idx_peer = 1;
6859 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6860 PEER_FLAG_OVERRIDE_CAPABILITY);
6861 }
6862
6863 DEFUN (no_neighbor_override_capability,
6864 no_neighbor_override_capability_cmd,
6865 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6866 NO_STR
6867 NEIGHBOR_STR
6868 NEIGHBOR_ADDR_STR2
6869 "Override capability negotiation result\n")
6870 {
6871 int idx_peer = 2;
6872 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6873 PEER_FLAG_OVERRIDE_CAPABILITY);
6874 }
6875
6876 DEFUN (neighbor_strict_capability,
6877 neighbor_strict_capability_cmd,
6878 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6879 NEIGHBOR_STR
6880 NEIGHBOR_ADDR_STR2
6881 "Strict capability negotiation match\n")
6882 {
6883 int idx_peer = 1;
6884
6885 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6886 PEER_FLAG_STRICT_CAP_MATCH);
6887 }
6888
6889 DEFUN (no_neighbor_strict_capability,
6890 no_neighbor_strict_capability_cmd,
6891 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6892 NO_STR
6893 NEIGHBOR_STR
6894 NEIGHBOR_ADDR_STR2
6895 "Strict capability negotiation match\n")
6896 {
6897 int idx_peer = 2;
6898
6899 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6900 PEER_FLAG_STRICT_CAP_MATCH);
6901 }
6902
6903 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6904 const char *keep_str, const char *hold_str)
6905 {
6906 int ret;
6907 struct peer *peer;
6908 uint32_t keepalive;
6909 uint32_t holdtime;
6910
6911 peer = peer_and_group_lookup_vty(vty, ip_str);
6912 if (!peer)
6913 return CMD_WARNING_CONFIG_FAILED;
6914
6915 keepalive = strtoul(keep_str, NULL, 10);
6916 holdtime = strtoul(hold_str, NULL, 10);
6917
6918 ret = peer_timers_set(peer, keepalive, holdtime);
6919
6920 return bgp_vty_return(vty, ret);
6921 }
6922
6923 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
6924 {
6925 int ret;
6926 struct peer *peer;
6927
6928 peer = peer_and_group_lookup_vty(vty, ip_str);
6929 if (!peer)
6930 return CMD_WARNING_CONFIG_FAILED;
6931
6932 ret = peer_timers_unset(peer);
6933
6934 return bgp_vty_return(vty, ret);
6935 }
6936
6937 DEFUN (neighbor_timers,
6938 neighbor_timers_cmd,
6939 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6940 NEIGHBOR_STR
6941 NEIGHBOR_ADDR_STR2
6942 "BGP per neighbor timers\n"
6943 "Keepalive interval\n"
6944 "Holdtime\n")
6945 {
6946 int idx_peer = 1;
6947 int idx_number = 3;
6948 int idx_number_2 = 4;
6949 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6950 argv[idx_number]->arg,
6951 argv[idx_number_2]->arg);
6952 }
6953
6954 DEFUN (no_neighbor_timers,
6955 no_neighbor_timers_cmd,
6956 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6957 NO_STR
6958 NEIGHBOR_STR
6959 NEIGHBOR_ADDR_STR2
6960 "BGP per neighbor timers\n"
6961 "Keepalive interval\n"
6962 "Holdtime\n")
6963 {
6964 int idx_peer = 2;
6965 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6966 }
6967
6968
6969 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6970 const char *time_str)
6971 {
6972 int ret;
6973 struct peer *peer;
6974 uint32_t connect;
6975
6976 peer = peer_and_group_lookup_vty(vty, ip_str);
6977 if (!peer)
6978 return CMD_WARNING_CONFIG_FAILED;
6979
6980 connect = strtoul(time_str, NULL, 10);
6981
6982 ret = peer_timers_connect_set(peer, connect);
6983
6984 return bgp_vty_return(vty, ret);
6985 }
6986
6987 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
6988 {
6989 int ret;
6990 struct peer *peer;
6991
6992 peer = peer_and_group_lookup_vty(vty, ip_str);
6993 if (!peer)
6994 return CMD_WARNING_CONFIG_FAILED;
6995
6996 ret = peer_timers_connect_unset(peer);
6997
6998 return bgp_vty_return(vty, ret);
6999 }
7000
7001 DEFUN (neighbor_timers_connect,
7002 neighbor_timers_connect_cmd,
7003 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7004 NEIGHBOR_STR
7005 NEIGHBOR_ADDR_STR2
7006 "BGP per neighbor timers\n"
7007 "BGP connect timer\n"
7008 "Connect timer\n")
7009 {
7010 int idx_peer = 1;
7011 int idx_number = 4;
7012 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7013 argv[idx_number]->arg);
7014 }
7015
7016 DEFUN (no_neighbor_timers_connect,
7017 no_neighbor_timers_connect_cmd,
7018 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7019 NO_STR
7020 NEIGHBOR_STR
7021 NEIGHBOR_ADDR_STR2
7022 "BGP per neighbor timers\n"
7023 "BGP connect timer\n"
7024 "Connect timer\n")
7025 {
7026 int idx_peer = 2;
7027 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7028 }
7029
7030 DEFPY (neighbor_timers_delayopen,
7031 neighbor_timers_delayopen_cmd,
7032 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7033 NEIGHBOR_STR
7034 NEIGHBOR_ADDR_STR2
7035 "BGP per neighbor timers\n"
7036 "RFC 4271 DelayOpenTimer\n"
7037 "DelayOpenTime timer interval\n")
7038 {
7039 struct peer *peer;
7040
7041 peer = peer_and_group_lookup_vty(vty, neighbor);
7042 if (!peer)
7043 return CMD_WARNING_CONFIG_FAILED;
7044
7045 if (!interval) {
7046 if (peer_timers_delayopen_unset(peer))
7047 return CMD_WARNING_CONFIG_FAILED;
7048 } else {
7049 if (peer_timers_delayopen_set(peer, interval))
7050 return CMD_WARNING_CONFIG_FAILED;
7051 }
7052
7053 return CMD_SUCCESS;
7054 }
7055
7056 DEFPY (no_neighbor_timers_delayopen,
7057 no_neighbor_timers_delayopen_cmd,
7058 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7059 NO_STR
7060 NEIGHBOR_STR
7061 NEIGHBOR_ADDR_STR2
7062 "BGP per neighbor timers\n"
7063 "RFC 4271 DelayOpenTimer\n"
7064 "DelayOpenTime timer interval\n")
7065 {
7066 struct peer *peer;
7067
7068 peer = peer_and_group_lookup_vty(vty, neighbor);
7069 if (!peer)
7070 return CMD_WARNING_CONFIG_FAILED;
7071
7072 if (peer_timers_delayopen_unset(peer))
7073 return CMD_WARNING_CONFIG_FAILED;
7074
7075 return CMD_SUCCESS;
7076 }
7077
7078 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7079 const char *time_str, int set)
7080 {
7081 int ret;
7082 struct peer *peer;
7083 uint32_t routeadv = 0;
7084
7085 peer = peer_and_group_lookup_vty(vty, ip_str);
7086 if (!peer)
7087 return CMD_WARNING_CONFIG_FAILED;
7088
7089 if (time_str)
7090 routeadv = strtoul(time_str, NULL, 10);
7091
7092 if (set)
7093 ret = peer_advertise_interval_set(peer, routeadv);
7094 else
7095 ret = peer_advertise_interval_unset(peer);
7096
7097 return bgp_vty_return(vty, ret);
7098 }
7099
7100 DEFUN (neighbor_advertise_interval,
7101 neighbor_advertise_interval_cmd,
7102 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7103 NEIGHBOR_STR
7104 NEIGHBOR_ADDR_STR2
7105 "Minimum interval between sending BGP routing updates\n"
7106 "time in seconds\n")
7107 {
7108 int idx_peer = 1;
7109 int idx_number = 3;
7110 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7111 argv[idx_number]->arg, 1);
7112 }
7113
7114 DEFUN (no_neighbor_advertise_interval,
7115 no_neighbor_advertise_interval_cmd,
7116 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7117 NO_STR
7118 NEIGHBOR_STR
7119 NEIGHBOR_ADDR_STR2
7120 "Minimum interval between sending BGP routing updates\n"
7121 "time in seconds\n")
7122 {
7123 int idx_peer = 2;
7124 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7125 }
7126
7127
7128 /* Time to wait before processing route-map updates */
7129 DEFUN (bgp_set_route_map_delay_timer,
7130 bgp_set_route_map_delay_timer_cmd,
7131 "bgp route-map delay-timer (0-600)",
7132 SET_STR
7133 "BGP route-map delay timer\n"
7134 "Time in secs to wait before processing route-map changes\n"
7135 "0 disables the timer, no route updates happen when route-maps change\n")
7136 {
7137 int idx_number = 3;
7138 uint32_t rmap_delay_timer;
7139
7140 if (argv[idx_number]->arg) {
7141 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7142 bm->rmap_update_timer = rmap_delay_timer;
7143
7144 /* if the dynamic update handling is being disabled, and a timer
7145 * is
7146 * running, stop the timer and act as if the timer has already
7147 * fired.
7148 */
7149 if (!rmap_delay_timer && bm->t_rmap_update) {
7150 BGP_TIMER_OFF(bm->t_rmap_update);
7151 thread_execute(bm->master, bgp_route_map_update_timer,
7152 NULL, 0);
7153 }
7154 return CMD_SUCCESS;
7155 } else {
7156 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7157 return CMD_WARNING_CONFIG_FAILED;
7158 }
7159 }
7160
7161 DEFUN (no_bgp_set_route_map_delay_timer,
7162 no_bgp_set_route_map_delay_timer_cmd,
7163 "no bgp route-map delay-timer [(0-600)]",
7164 NO_STR
7165 BGP_STR
7166 "Default BGP route-map delay timer\n"
7167 "Reset to default time to wait for processing route-map changes\n"
7168 "0 disables the timer, no route updates happen when route-maps change\n")
7169 {
7170
7171 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7172
7173 return CMD_SUCCESS;
7174 }
7175
7176 /* neighbor interface */
7177 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7178 const char *str)
7179 {
7180 struct peer *peer;
7181
7182 peer = peer_lookup_vty(vty, ip_str);
7183 if (!peer || peer->conf_if) {
7184 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7185 return CMD_WARNING_CONFIG_FAILED;
7186 }
7187
7188 if (str)
7189 peer_interface_set(peer, str);
7190 else
7191 peer_interface_unset(peer);
7192
7193 return CMD_SUCCESS;
7194 }
7195
7196 DEFUN (neighbor_interface,
7197 neighbor_interface_cmd,
7198 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7199 NEIGHBOR_STR
7200 NEIGHBOR_ADDR_STR
7201 "Interface\n"
7202 "Interface name\n")
7203 {
7204 int idx_ip = 1;
7205 int idx_word = 3;
7206
7207 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7208 }
7209
7210 DEFUN (no_neighbor_interface,
7211 no_neighbor_interface_cmd,
7212 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7213 NO_STR
7214 NEIGHBOR_STR
7215 NEIGHBOR_ADDR_STR
7216 "Interface\n"
7217 "Interface name\n")
7218 {
7219 int idx_peer = 2;
7220
7221 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7222 }
7223
7224 DEFUN (neighbor_distribute_list,
7225 neighbor_distribute_list_cmd,
7226 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7227 NEIGHBOR_STR
7228 NEIGHBOR_ADDR_STR2
7229 "Filter updates to/from this neighbor\n"
7230 "IP Access-list name\n"
7231 "Filter incoming updates\n"
7232 "Filter outgoing updates\n")
7233 {
7234 int idx_peer = 1;
7235 int idx_acl = 3;
7236 int direct, ret;
7237 struct peer *peer;
7238
7239 const char *pstr = argv[idx_peer]->arg;
7240 const char *acl = argv[idx_acl]->arg;
7241 const char *inout = argv[argc - 1]->text;
7242
7243 peer = peer_and_group_lookup_vty(vty, pstr);
7244 if (!peer)
7245 return CMD_WARNING_CONFIG_FAILED;
7246
7247 /* Check filter direction. */
7248 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7249 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7250 direct, acl);
7251
7252 return bgp_vty_return(vty, ret);
7253 }
7254
7255 ALIAS_HIDDEN(
7256 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7257 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7258 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7259 "Filter updates to/from this neighbor\n"
7260 "IP Access-list name\n"
7261 "Filter incoming updates\n"
7262 "Filter outgoing updates\n")
7263
7264 DEFUN (no_neighbor_distribute_list,
7265 no_neighbor_distribute_list_cmd,
7266 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7267 NO_STR
7268 NEIGHBOR_STR
7269 NEIGHBOR_ADDR_STR2
7270 "Filter updates to/from this neighbor\n"
7271 "IP Access-list name\n"
7272 "Filter incoming updates\n"
7273 "Filter outgoing updates\n")
7274 {
7275 int idx_peer = 2;
7276 int direct, ret;
7277 struct peer *peer;
7278
7279 const char *pstr = argv[idx_peer]->arg;
7280 const char *inout = argv[argc - 1]->text;
7281
7282 peer = peer_and_group_lookup_vty(vty, pstr);
7283 if (!peer)
7284 return CMD_WARNING_CONFIG_FAILED;
7285
7286 /* Check filter direction. */
7287 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7288 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7289 direct);
7290
7291 return bgp_vty_return(vty, ret);
7292 }
7293
7294 ALIAS_HIDDEN(
7295 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7296 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7297 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7298 "Filter updates to/from this neighbor\n"
7299 "IP Access-list name\n"
7300 "Filter incoming updates\n"
7301 "Filter outgoing updates\n")
7302
7303 /* Set prefix list to the peer. */
7304 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7305 afi_t afi, safi_t safi,
7306 const char *name_str,
7307 const char *direct_str)
7308 {
7309 int ret;
7310 int direct = FILTER_IN;
7311 struct peer *peer;
7312
7313 peer = peer_and_group_lookup_vty(vty, ip_str);
7314 if (!peer)
7315 return CMD_WARNING_CONFIG_FAILED;
7316
7317 /* Check filter direction. */
7318 if (strncmp(direct_str, "i", 1) == 0)
7319 direct = FILTER_IN;
7320 else if (strncmp(direct_str, "o", 1) == 0)
7321 direct = FILTER_OUT;
7322
7323 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7324
7325 return bgp_vty_return(vty, ret);
7326 }
7327
7328 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7329 afi_t afi, safi_t safi,
7330 const char *direct_str)
7331 {
7332 int ret;
7333 struct peer *peer;
7334 int direct = FILTER_IN;
7335
7336 peer = peer_and_group_lookup_vty(vty, ip_str);
7337 if (!peer)
7338 return CMD_WARNING_CONFIG_FAILED;
7339
7340 /* Check filter direction. */
7341 if (strncmp(direct_str, "i", 1) == 0)
7342 direct = FILTER_IN;
7343 else if (strncmp(direct_str, "o", 1) == 0)
7344 direct = FILTER_OUT;
7345
7346 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7347
7348 return bgp_vty_return(vty, ret);
7349 }
7350
7351 DEFUN (neighbor_prefix_list,
7352 neighbor_prefix_list_cmd,
7353 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7354 NEIGHBOR_STR
7355 NEIGHBOR_ADDR_STR2
7356 "Filter updates to/from this neighbor\n"
7357 "Name of a prefix list\n"
7358 "Filter incoming updates\n"
7359 "Filter outgoing updates\n")
7360 {
7361 int idx_peer = 1;
7362 int idx_word = 3;
7363 int idx_in_out = 4;
7364 return peer_prefix_list_set_vty(
7365 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7366 argv[idx_word]->arg, argv[idx_in_out]->arg);
7367 }
7368
7369 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7370 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7371 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7372 "Filter updates to/from this neighbor\n"
7373 "Name of a prefix list\n"
7374 "Filter incoming updates\n"
7375 "Filter outgoing updates\n")
7376
7377 DEFUN (no_neighbor_prefix_list,
7378 no_neighbor_prefix_list_cmd,
7379 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7380 NO_STR
7381 NEIGHBOR_STR
7382 NEIGHBOR_ADDR_STR2
7383 "Filter updates to/from this neighbor\n"
7384 "Name of a prefix list\n"
7385 "Filter incoming updates\n"
7386 "Filter outgoing updates\n")
7387 {
7388 int idx_peer = 2;
7389 int idx_in_out = 5;
7390 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7391 bgp_node_afi(vty), bgp_node_safi(vty),
7392 argv[idx_in_out]->arg);
7393 }
7394
7395 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7396 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7397 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7398 "Filter updates to/from this neighbor\n"
7399 "Name of a prefix list\n"
7400 "Filter incoming updates\n"
7401 "Filter outgoing updates\n")
7402
7403 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7404 safi_t safi, const char *name_str,
7405 const char *direct_str)
7406 {
7407 int ret;
7408 struct peer *peer;
7409 int direct = FILTER_IN;
7410
7411 peer = peer_and_group_lookup_vty(vty, ip_str);
7412 if (!peer)
7413 return CMD_WARNING_CONFIG_FAILED;
7414
7415 /* Check filter direction. */
7416 if (strncmp(direct_str, "i", 1) == 0)
7417 direct = FILTER_IN;
7418 else if (strncmp(direct_str, "o", 1) == 0)
7419 direct = FILTER_OUT;
7420
7421 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7422
7423 return bgp_vty_return(vty, ret);
7424 }
7425
7426 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7427 safi_t safi, const char *direct_str)
7428 {
7429 int ret;
7430 struct peer *peer;
7431 int direct = FILTER_IN;
7432
7433 peer = peer_and_group_lookup_vty(vty, ip_str);
7434 if (!peer)
7435 return CMD_WARNING_CONFIG_FAILED;
7436
7437 /* Check filter direction. */
7438 if (strncmp(direct_str, "i", 1) == 0)
7439 direct = FILTER_IN;
7440 else if (strncmp(direct_str, "o", 1) == 0)
7441 direct = FILTER_OUT;
7442
7443 ret = peer_aslist_unset(peer, afi, safi, direct);
7444
7445 return bgp_vty_return(vty, ret);
7446 }
7447
7448 DEFUN (neighbor_filter_list,
7449 neighbor_filter_list_cmd,
7450 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7451 NEIGHBOR_STR
7452 NEIGHBOR_ADDR_STR2
7453 "Establish BGP filters\n"
7454 "AS path access-list name\n"
7455 "Filter incoming routes\n"
7456 "Filter outgoing routes\n")
7457 {
7458 int idx_peer = 1;
7459 int idx_word = 3;
7460 int idx_in_out = 4;
7461 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7462 bgp_node_safi(vty), argv[idx_word]->arg,
7463 argv[idx_in_out]->arg);
7464 }
7465
7466 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7467 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7468 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7469 "Establish BGP filters\n"
7470 "AS path access-list name\n"
7471 "Filter incoming routes\n"
7472 "Filter outgoing routes\n")
7473
7474 DEFUN (no_neighbor_filter_list,
7475 no_neighbor_filter_list_cmd,
7476 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7477 NO_STR
7478 NEIGHBOR_STR
7479 NEIGHBOR_ADDR_STR2
7480 "Establish BGP filters\n"
7481 "AS path access-list name\n"
7482 "Filter incoming routes\n"
7483 "Filter outgoing routes\n")
7484 {
7485 int idx_peer = 2;
7486 int idx_in_out = 5;
7487 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7488 bgp_node_afi(vty), bgp_node_safi(vty),
7489 argv[idx_in_out]->arg);
7490 }
7491
7492 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7493 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7494 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7495 "Establish BGP filters\n"
7496 "AS path access-list name\n"
7497 "Filter incoming routes\n"
7498 "Filter outgoing routes\n")
7499
7500 /* Set advertise-map to the peer. */
7501 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7502 afi_t afi, safi_t safi,
7503 const char *advertise_str,
7504 const char *condition_str, bool condition,
7505 bool set)
7506 {
7507 int ret = CMD_WARNING_CONFIG_FAILED;
7508 struct peer *peer;
7509 struct route_map *advertise_map;
7510 struct route_map *condition_map;
7511
7512 peer = peer_and_group_lookup_vty(vty, ip_str);
7513 if (!peer)
7514 return ret;
7515
7516 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7517 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7518
7519 if (set)
7520 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7521 advertise_map, condition_str,
7522 condition_map, condition);
7523 else
7524 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7525 advertise_map, condition_str,
7526 condition_map, condition);
7527
7528 return bgp_vty_return(vty, ret);
7529 }
7530
7531 DEFPY (bgp_condadv_period,
7532 bgp_condadv_period_cmd,
7533 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7534 NO_STR
7535 BGP_STR
7536 "Conditional advertisement settings\n"
7537 "Set period to rescan BGP table to check if condition is met\n"
7538 "Period between BGP table scans, in seconds; default 60\n")
7539 {
7540 VTY_DECLVAR_CONTEXT(bgp, bgp);
7541
7542 bgp->condition_check_period =
7543 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7544
7545 return CMD_SUCCESS;
7546 }
7547
7548 DEFPY (neighbor_advertise_map,
7549 neighbor_advertise_map_cmd,
7550 "[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",
7551 NO_STR
7552 NEIGHBOR_STR
7553 NEIGHBOR_ADDR_STR2
7554 "Route-map to conditionally advertise routes\n"
7555 "Name of advertise map\n"
7556 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7557 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7558 "Name of the exist or non exist map\n")
7559 {
7560 bool condition = CONDITION_EXIST;
7561
7562 if (!strcmp(exist, "non-exist-map"))
7563 condition = CONDITION_NON_EXIST;
7564
7565 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7566 bgp_node_safi(vty), advertise_str,
7567 condition_str, condition, !no);
7568 }
7569
7570 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7571 "[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",
7572 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7573 "Route-map to conditionally advertise routes\n"
7574 "Name of advertise map\n"
7575 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7576 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7577 "Name of the exist or non exist map\n")
7578
7579 /* Set route-map to the peer. */
7580 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7581 afi_t afi, safi_t safi, const char *name_str,
7582 const char *direct_str)
7583 {
7584 int ret;
7585 struct peer *peer;
7586 int direct = RMAP_IN;
7587 struct route_map *route_map;
7588
7589 peer = peer_and_group_lookup_vty(vty, ip_str);
7590 if (!peer)
7591 return CMD_WARNING_CONFIG_FAILED;
7592
7593 /* Check filter direction. */
7594 if (strncmp(direct_str, "in", 2) == 0)
7595 direct = RMAP_IN;
7596 else if (strncmp(direct_str, "o", 1) == 0)
7597 direct = RMAP_OUT;
7598
7599 route_map = route_map_lookup_warn_noexist(vty, name_str);
7600 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7601
7602 return bgp_vty_return(vty, ret);
7603 }
7604
7605 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7606 afi_t afi, safi_t safi,
7607 const char *direct_str)
7608 {
7609 int ret;
7610 struct peer *peer;
7611 int direct = RMAP_IN;
7612
7613 peer = peer_and_group_lookup_vty(vty, ip_str);
7614 if (!peer)
7615 return CMD_WARNING_CONFIG_FAILED;
7616
7617 /* Check filter direction. */
7618 if (strncmp(direct_str, "in", 2) == 0)
7619 direct = RMAP_IN;
7620 else if (strncmp(direct_str, "o", 1) == 0)
7621 direct = RMAP_OUT;
7622
7623 ret = peer_route_map_unset(peer, afi, safi, direct);
7624
7625 return bgp_vty_return(vty, ret);
7626 }
7627
7628 DEFUN (neighbor_route_map,
7629 neighbor_route_map_cmd,
7630 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7631 NEIGHBOR_STR
7632 NEIGHBOR_ADDR_STR2
7633 "Apply route map to neighbor\n"
7634 "Name of route map\n"
7635 "Apply map to incoming routes\n"
7636 "Apply map to outbound routes\n")
7637 {
7638 int idx_peer = 1;
7639 int idx_word = 3;
7640 int idx_in_out = 4;
7641 return peer_route_map_set_vty(
7642 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7643 argv[idx_word]->arg, argv[idx_in_out]->arg);
7644 }
7645
7646 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7647 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7648 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7649 "Apply route map to neighbor\n"
7650 "Name of route map\n"
7651 "Apply map to incoming routes\n"
7652 "Apply map to outbound routes\n")
7653
7654 DEFUN (no_neighbor_route_map,
7655 no_neighbor_route_map_cmd,
7656 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7657 NO_STR
7658 NEIGHBOR_STR
7659 NEIGHBOR_ADDR_STR2
7660 "Apply route map to neighbor\n"
7661 "Name of route map\n"
7662 "Apply map to incoming routes\n"
7663 "Apply map to outbound routes\n")
7664 {
7665 int idx_peer = 2;
7666 int idx_in_out = 5;
7667 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7668 bgp_node_afi(vty), bgp_node_safi(vty),
7669 argv[idx_in_out]->arg);
7670 }
7671
7672 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7673 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7674 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7675 "Apply route map to neighbor\n"
7676 "Name of route map\n"
7677 "Apply map to incoming routes\n"
7678 "Apply map to outbound routes\n")
7679
7680 /* Set unsuppress-map to the peer. */
7681 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7682 afi_t afi, safi_t safi,
7683 const char *name_str)
7684 {
7685 int ret;
7686 struct peer *peer;
7687 struct route_map *route_map;
7688
7689 peer = peer_and_group_lookup_vty(vty, ip_str);
7690 if (!peer)
7691 return CMD_WARNING_CONFIG_FAILED;
7692
7693 route_map = route_map_lookup_warn_noexist(vty, name_str);
7694 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7695
7696 return bgp_vty_return(vty, ret);
7697 }
7698
7699 /* Unset route-map from the peer. */
7700 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7701 afi_t afi, safi_t safi)
7702 {
7703 int ret;
7704 struct peer *peer;
7705
7706 peer = peer_and_group_lookup_vty(vty, ip_str);
7707 if (!peer)
7708 return CMD_WARNING_CONFIG_FAILED;
7709
7710 ret = peer_unsuppress_map_unset(peer, afi, safi);
7711
7712 return bgp_vty_return(vty, ret);
7713 }
7714
7715 DEFUN (neighbor_unsuppress_map,
7716 neighbor_unsuppress_map_cmd,
7717 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7718 NEIGHBOR_STR
7719 NEIGHBOR_ADDR_STR2
7720 "Route-map to selectively unsuppress suppressed routes\n"
7721 "Name of route map\n")
7722 {
7723 int idx_peer = 1;
7724 int idx_word = 3;
7725 return peer_unsuppress_map_set_vty(
7726 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7727 argv[idx_word]->arg);
7728 }
7729
7730 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7731 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7732 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7733 "Route-map to selectively unsuppress suppressed routes\n"
7734 "Name of route map\n")
7735
7736 DEFUN (no_neighbor_unsuppress_map,
7737 no_neighbor_unsuppress_map_cmd,
7738 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7739 NO_STR
7740 NEIGHBOR_STR
7741 NEIGHBOR_ADDR_STR2
7742 "Route-map to selectively unsuppress suppressed routes\n"
7743 "Name of route map\n")
7744 {
7745 int idx_peer = 2;
7746 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7747 bgp_node_afi(vty),
7748 bgp_node_safi(vty));
7749 }
7750
7751 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7752 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7753 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7754 "Route-map to selectively unsuppress suppressed routes\n"
7755 "Name of route map\n")
7756
7757 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7758 afi_t afi, safi_t safi,
7759 const char *num_str,
7760 const char *threshold_str, int warning,
7761 const char *restart_str,
7762 const char *force_str)
7763 {
7764 int ret;
7765 struct peer *peer;
7766 uint32_t max;
7767 uint8_t threshold;
7768 uint16_t restart;
7769
7770 peer = peer_and_group_lookup_vty(vty, ip_str);
7771 if (!peer)
7772 return CMD_WARNING_CONFIG_FAILED;
7773
7774 max = strtoul(num_str, NULL, 10);
7775 if (threshold_str)
7776 threshold = atoi(threshold_str);
7777 else
7778 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7779
7780 if (restart_str)
7781 restart = atoi(restart_str);
7782 else
7783 restart = 0;
7784
7785 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7786 restart, force_str ? true : false);
7787
7788 return bgp_vty_return(vty, ret);
7789 }
7790
7791 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7792 afi_t afi, safi_t safi)
7793 {
7794 int ret;
7795 struct peer *peer;
7796
7797 peer = peer_and_group_lookup_vty(vty, ip_str);
7798 if (!peer)
7799 return CMD_WARNING_CONFIG_FAILED;
7800
7801 ret = peer_maximum_prefix_unset(peer, afi, safi);
7802
7803 return bgp_vty_return(vty, ret);
7804 }
7805
7806 /* Maximum number of prefix to be sent to the neighbor. */
7807 DEFUN(neighbor_maximum_prefix_out,
7808 neighbor_maximum_prefix_out_cmd,
7809 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7810 NEIGHBOR_STR
7811 NEIGHBOR_ADDR_STR2
7812 "Maximum number of prefixes to be sent to this peer\n"
7813 "Maximum no. of prefix limit\n")
7814 {
7815 int ret;
7816 int idx_peer = 1;
7817 int idx_number = 3;
7818 struct peer *peer;
7819 uint32_t max;
7820 afi_t afi = bgp_node_afi(vty);
7821 safi_t safi = bgp_node_safi(vty);
7822
7823 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7824 if (!peer)
7825 return CMD_WARNING_CONFIG_FAILED;
7826
7827 max = strtoul(argv[idx_number]->arg, NULL, 10);
7828
7829 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
7830
7831 return bgp_vty_return(vty, ret);
7832 }
7833
7834 DEFUN(no_neighbor_maximum_prefix_out,
7835 no_neighbor_maximum_prefix_out_cmd,
7836 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
7837 NO_STR
7838 NEIGHBOR_STR
7839 NEIGHBOR_ADDR_STR2
7840 "Maximum number of prefixes to be sent to this peer\n"
7841 "Maximum no. of prefix limit\n")
7842 {
7843 int ret;
7844 int idx_peer = 2;
7845 struct peer *peer;
7846 afi_t afi = bgp_node_afi(vty);
7847 safi_t safi = bgp_node_safi(vty);
7848
7849 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7850 if (!peer)
7851 return CMD_WARNING_CONFIG_FAILED;
7852
7853 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
7854
7855 return bgp_vty_return(vty, ret);
7856 }
7857
7858 /* Maximum number of prefix configuration. Prefix count is different
7859 for each peer configuration. So this configuration can be set for
7860 each peer configuration. */
7861 DEFUN (neighbor_maximum_prefix,
7862 neighbor_maximum_prefix_cmd,
7863 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7864 NEIGHBOR_STR
7865 NEIGHBOR_ADDR_STR2
7866 "Maximum number of prefix accept from this peer\n"
7867 "maximum no. of prefix limit\n"
7868 "Force checking all received routes not only accepted\n")
7869 {
7870 int idx_peer = 1;
7871 int idx_number = 3;
7872 int idx_force = 0;
7873 char *force = NULL;
7874
7875 if (argv_find(argv, argc, "force", &idx_force))
7876 force = argv[idx_force]->arg;
7877
7878 return peer_maximum_prefix_set_vty(
7879 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7880 argv[idx_number]->arg, NULL, 0, NULL, force);
7881 }
7882
7883 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
7884 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7885 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7886 "Maximum number of prefix accept from this peer\n"
7887 "maximum no. of prefix limit\n"
7888 "Force checking all received routes not only accepted\n")
7889
7890 DEFUN (neighbor_maximum_prefix_threshold,
7891 neighbor_maximum_prefix_threshold_cmd,
7892 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7893 NEIGHBOR_STR
7894 NEIGHBOR_ADDR_STR2
7895 "Maximum number of prefix accept from this peer\n"
7896 "maximum no. of prefix limit\n"
7897 "Threshold value (%) at which to generate a warning msg\n"
7898 "Force checking all received routes not only accepted\n")
7899 {
7900 int idx_peer = 1;
7901 int idx_number = 3;
7902 int idx_number_2 = 4;
7903 int idx_force = 0;
7904 char *force = NULL;
7905
7906 if (argv_find(argv, argc, "force", &idx_force))
7907 force = argv[idx_force]->arg;
7908
7909 return peer_maximum_prefix_set_vty(
7910 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7911 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
7912 }
7913
7914 ALIAS_HIDDEN(
7915 neighbor_maximum_prefix_threshold,
7916 neighbor_maximum_prefix_threshold_hidden_cmd,
7917 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7918 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7919 "Maximum number of prefix accept from this peer\n"
7920 "maximum no. of prefix limit\n"
7921 "Threshold value (%) at which to generate a warning msg\n"
7922 "Force checking all received routes not only accepted\n")
7923
7924 DEFUN (neighbor_maximum_prefix_warning,
7925 neighbor_maximum_prefix_warning_cmd,
7926 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7927 NEIGHBOR_STR
7928 NEIGHBOR_ADDR_STR2
7929 "Maximum number of prefix accept from this peer\n"
7930 "maximum no. of prefix limit\n"
7931 "Only give warning message when limit is exceeded\n"
7932 "Force checking all received routes not only accepted\n")
7933 {
7934 int idx_peer = 1;
7935 int idx_number = 3;
7936 int idx_force = 0;
7937 char *force = NULL;
7938
7939 if (argv_find(argv, argc, "force", &idx_force))
7940 force = argv[idx_force]->arg;
7941
7942 return peer_maximum_prefix_set_vty(
7943 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7944 argv[idx_number]->arg, NULL, 1, NULL, force);
7945 }
7946
7947 ALIAS_HIDDEN(
7948 neighbor_maximum_prefix_warning,
7949 neighbor_maximum_prefix_warning_hidden_cmd,
7950 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7951 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7952 "Maximum number of prefix accept from this peer\n"
7953 "maximum no. of prefix limit\n"
7954 "Only give warning message when limit is exceeded\n"
7955 "Force checking all received routes not only accepted\n")
7956
7957 DEFUN (neighbor_maximum_prefix_threshold_warning,
7958 neighbor_maximum_prefix_threshold_warning_cmd,
7959 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7960 NEIGHBOR_STR
7961 NEIGHBOR_ADDR_STR2
7962 "Maximum number of prefix accept from this peer\n"
7963 "maximum no. of prefix limit\n"
7964 "Threshold value (%) at which to generate a warning msg\n"
7965 "Only give warning message when limit is exceeded\n"
7966 "Force checking all received routes not only accepted\n")
7967 {
7968 int idx_peer = 1;
7969 int idx_number = 3;
7970 int idx_number_2 = 4;
7971 int idx_force = 0;
7972 char *force = NULL;
7973
7974 if (argv_find(argv, argc, "force", &idx_force))
7975 force = argv[idx_force]->arg;
7976
7977 return peer_maximum_prefix_set_vty(
7978 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7979 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
7980 }
7981
7982 ALIAS_HIDDEN(
7983 neighbor_maximum_prefix_threshold_warning,
7984 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
7985 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7986 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7987 "Maximum number of prefix accept from this peer\n"
7988 "maximum no. of prefix limit\n"
7989 "Threshold value (%) at which to generate a warning msg\n"
7990 "Only give warning message when limit is exceeded\n"
7991 "Force checking all received routes not only accepted\n")
7992
7993 DEFUN (neighbor_maximum_prefix_restart,
7994 neighbor_maximum_prefix_restart_cmd,
7995 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7996 NEIGHBOR_STR
7997 NEIGHBOR_ADDR_STR2
7998 "Maximum number of prefix accept from this peer\n"
7999 "maximum no. of prefix limit\n"
8000 "Restart bgp connection after limit is exceeded\n"
8001 "Restart interval in minutes\n"
8002 "Force checking all received routes not only accepted\n")
8003 {
8004 int idx_peer = 1;
8005 int idx_number = 3;
8006 int idx_number_2 = 5;
8007 int idx_force = 0;
8008 char *force = NULL;
8009
8010 if (argv_find(argv, argc, "force", &idx_force))
8011 force = argv[idx_force]->arg;
8012
8013 return peer_maximum_prefix_set_vty(
8014 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8015 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8016 }
8017
8018 ALIAS_HIDDEN(
8019 neighbor_maximum_prefix_restart,
8020 neighbor_maximum_prefix_restart_hidden_cmd,
8021 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8022 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8023 "Maximum number of prefix accept from this peer\n"
8024 "maximum no. of prefix limit\n"
8025 "Restart bgp connection after limit is exceeded\n"
8026 "Restart interval in minutes\n"
8027 "Force checking all received routes not only accepted\n")
8028
8029 DEFUN (neighbor_maximum_prefix_threshold_restart,
8030 neighbor_maximum_prefix_threshold_restart_cmd,
8031 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8032 NEIGHBOR_STR
8033 NEIGHBOR_ADDR_STR2
8034 "Maximum number of prefixes to accept from this peer\n"
8035 "maximum no. of prefix limit\n"
8036 "Threshold value (%) at which to generate a warning msg\n"
8037 "Restart bgp connection after limit is exceeded\n"
8038 "Restart interval in minutes\n"
8039 "Force checking all received routes not only accepted\n")
8040 {
8041 int idx_peer = 1;
8042 int idx_number = 3;
8043 int idx_number_2 = 4;
8044 int idx_number_3 = 6;
8045 int idx_force = 0;
8046 char *force = NULL;
8047
8048 if (argv_find(argv, argc, "force", &idx_force))
8049 force = argv[idx_force]->arg;
8050
8051 return peer_maximum_prefix_set_vty(
8052 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8053 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8054 argv[idx_number_3]->arg, force);
8055 }
8056
8057 ALIAS_HIDDEN(
8058 neighbor_maximum_prefix_threshold_restart,
8059 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8060 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8061 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8062 "Maximum number of prefixes to accept from this peer\n"
8063 "maximum no. of prefix limit\n"
8064 "Threshold value (%) at which to generate a warning msg\n"
8065 "Restart bgp connection after limit is exceeded\n"
8066 "Restart interval in minutes\n"
8067 "Force checking all received routes not only accepted\n")
8068
8069 DEFUN (no_neighbor_maximum_prefix,
8070 no_neighbor_maximum_prefix_cmd,
8071 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8072 NO_STR
8073 NEIGHBOR_STR
8074 NEIGHBOR_ADDR_STR2
8075 "Maximum number of prefixes to accept from this peer\n"
8076 "maximum no. of prefix limit\n"
8077 "Threshold value (%) at which to generate a warning msg\n"
8078 "Restart bgp connection after limit is exceeded\n"
8079 "Restart interval in minutes\n"
8080 "Only give warning message when limit is exceeded\n"
8081 "Force checking all received routes not only accepted\n")
8082 {
8083 int idx_peer = 2;
8084 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8085 bgp_node_afi(vty),
8086 bgp_node_safi(vty));
8087 }
8088
8089 ALIAS_HIDDEN(
8090 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8091 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8092 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8093 "Maximum number of prefixes to accept from this peer\n"
8094 "maximum no. of prefix limit\n"
8095 "Threshold value (%) at which to generate a warning msg\n"
8096 "Restart bgp connection after limit is exceeded\n"
8097 "Restart interval in minutes\n"
8098 "Only give warning message when limit is exceeded\n"
8099 "Force checking all received routes not only accepted\n")
8100
8101
8102 /* "neighbor allowas-in" */
8103 DEFUN (neighbor_allowas_in,
8104 neighbor_allowas_in_cmd,
8105 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8106 NEIGHBOR_STR
8107 NEIGHBOR_ADDR_STR2
8108 "Accept as-path with my AS present in it\n"
8109 "Number of occurrences of AS number\n"
8110 "Only accept my AS in the as-path if the route was originated in my AS\n")
8111 {
8112 int idx_peer = 1;
8113 int idx_number_origin = 3;
8114 int ret;
8115 int origin = 0;
8116 struct peer *peer;
8117 int allow_num = 0;
8118
8119 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8120 if (!peer)
8121 return CMD_WARNING_CONFIG_FAILED;
8122
8123 if (argc <= idx_number_origin)
8124 allow_num = 3;
8125 else {
8126 if (argv[idx_number_origin]->type == WORD_TKN)
8127 origin = 1;
8128 else
8129 allow_num = atoi(argv[idx_number_origin]->arg);
8130 }
8131
8132 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8133 allow_num, origin);
8134
8135 return bgp_vty_return(vty, ret);
8136 }
8137
8138 ALIAS_HIDDEN(
8139 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8140 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8141 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8142 "Accept as-path with my AS present in it\n"
8143 "Number of occurrences of AS number\n"
8144 "Only accept my AS in the as-path if the route was originated in my AS\n")
8145
8146 DEFUN (no_neighbor_allowas_in,
8147 no_neighbor_allowas_in_cmd,
8148 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8149 NO_STR
8150 NEIGHBOR_STR
8151 NEIGHBOR_ADDR_STR2
8152 "allow local ASN appears in aspath attribute\n"
8153 "Number of occurrences of AS number\n"
8154 "Only accept my AS in the as-path if the route was originated in my AS\n")
8155 {
8156 int idx_peer = 2;
8157 int ret;
8158 struct peer *peer;
8159
8160 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8161 if (!peer)
8162 return CMD_WARNING_CONFIG_FAILED;
8163
8164 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8165 bgp_node_safi(vty));
8166
8167 return bgp_vty_return(vty, ret);
8168 }
8169
8170 ALIAS_HIDDEN(
8171 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8172 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8173 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8174 "allow local ASN appears in aspath attribute\n"
8175 "Number of occurrences of AS number\n"
8176 "Only accept my AS in the as-path if the route was originated in my AS\n")
8177
8178 DEFUN (neighbor_ttl_security,
8179 neighbor_ttl_security_cmd,
8180 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8181 NEIGHBOR_STR
8182 NEIGHBOR_ADDR_STR2
8183 "BGP ttl-security parameters\n"
8184 "Specify the maximum number of hops to the BGP peer\n"
8185 "Number of hops to BGP peer\n")
8186 {
8187 int idx_peer = 1;
8188 int idx_number = 4;
8189 struct peer *peer;
8190 int gtsm_hops;
8191
8192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8193 if (!peer)
8194 return CMD_WARNING_CONFIG_FAILED;
8195
8196 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8197
8198 /*
8199 * If 'neighbor swpX', then this is for directly connected peers,
8200 * we should not accept a ttl-security hops value greater than 1.
8201 */
8202 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8203 vty_out(vty,
8204 "%s is directly connected peer, hops cannot exceed 1\n",
8205 argv[idx_peer]->arg);
8206 return CMD_WARNING_CONFIG_FAILED;
8207 }
8208
8209 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8210 }
8211
8212 DEFUN (no_neighbor_ttl_security,
8213 no_neighbor_ttl_security_cmd,
8214 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8215 NO_STR
8216 NEIGHBOR_STR
8217 NEIGHBOR_ADDR_STR2
8218 "BGP ttl-security parameters\n"
8219 "Specify the maximum number of hops to the BGP peer\n"
8220 "Number of hops to BGP peer\n")
8221 {
8222 int idx_peer = 2;
8223 struct peer *peer;
8224
8225 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8226 if (!peer)
8227 return CMD_WARNING_CONFIG_FAILED;
8228
8229 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8230 }
8231
8232 /* disable-addpath-rx */
8233 DEFUN(neighbor_disable_addpath_rx,
8234 neighbor_disable_addpath_rx_cmd,
8235 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8236 NEIGHBOR_STR
8237 NEIGHBOR_ADDR_STR2
8238 "Do not accept additional paths\n")
8239 {
8240 char *peer_str = argv[1]->arg;
8241 struct peer *peer;
8242 afi_t afi = bgp_node_afi(vty);
8243 safi_t safi = bgp_node_safi(vty);
8244
8245 peer = peer_and_group_lookup_vty(vty, peer_str);
8246 if (!peer)
8247 return CMD_WARNING_CONFIG_FAILED;
8248
8249 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8250 PEER_FLAG_DISABLE_ADDPATH_RX);
8251 }
8252
8253 DEFUN(no_neighbor_disable_addpath_rx,
8254 no_neighbor_disable_addpath_rx_cmd,
8255 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8256 NO_STR
8257 NEIGHBOR_STR
8258 NEIGHBOR_ADDR_STR2
8259 "Do not accept additional paths\n")
8260 {
8261 char *peer_str = argv[2]->arg;
8262 struct peer *peer;
8263 afi_t afi = bgp_node_afi(vty);
8264 safi_t safi = bgp_node_safi(vty);
8265
8266 peer = peer_and_group_lookup_vty(vty, peer_str);
8267 if (!peer)
8268 return CMD_WARNING_CONFIG_FAILED;
8269
8270 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8271 PEER_FLAG_DISABLE_ADDPATH_RX);
8272 }
8273
8274 DEFUN (neighbor_addpath_tx_all_paths,
8275 neighbor_addpath_tx_all_paths_cmd,
8276 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8277 NEIGHBOR_STR
8278 NEIGHBOR_ADDR_STR2
8279 "Use addpath to advertise all paths to a neighbor\n")
8280 {
8281 int idx_peer = 1;
8282 struct peer *peer;
8283
8284 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8285 if (!peer)
8286 return CMD_WARNING_CONFIG_FAILED;
8287
8288 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8289 BGP_ADDPATH_ALL);
8290 return CMD_SUCCESS;
8291 }
8292
8293 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8294 neighbor_addpath_tx_all_paths_hidden_cmd,
8295 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8296 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8297 "Use addpath to advertise all paths to a neighbor\n")
8298
8299 DEFUN (no_neighbor_addpath_tx_all_paths,
8300 no_neighbor_addpath_tx_all_paths_cmd,
8301 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8302 NO_STR
8303 NEIGHBOR_STR
8304 NEIGHBOR_ADDR_STR2
8305 "Use addpath to advertise all paths to a neighbor\n")
8306 {
8307 int idx_peer = 2;
8308 struct peer *peer;
8309
8310 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8311 if (!peer)
8312 return CMD_WARNING_CONFIG_FAILED;
8313
8314 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8315 != BGP_ADDPATH_ALL) {
8316 vty_out(vty,
8317 "%% Peer not currently configured to transmit all paths.");
8318 return CMD_WARNING_CONFIG_FAILED;
8319 }
8320
8321 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8322 BGP_ADDPATH_NONE);
8323
8324 return CMD_SUCCESS;
8325 }
8326
8327 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8328 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8329 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8330 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8331 "Use addpath to advertise all paths to a neighbor\n")
8332
8333 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8334 neighbor_addpath_tx_bestpath_per_as_cmd,
8335 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8336 NEIGHBOR_STR
8337 NEIGHBOR_ADDR_STR2
8338 "Use addpath to advertise the bestpath per each neighboring AS\n")
8339 {
8340 int idx_peer = 1;
8341 struct peer *peer;
8342
8343 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8344 if (!peer)
8345 return CMD_WARNING_CONFIG_FAILED;
8346
8347 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8348 BGP_ADDPATH_BEST_PER_AS);
8349
8350 return CMD_SUCCESS;
8351 }
8352
8353 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8354 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8355 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8356 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8357 "Use addpath to advertise the bestpath per each neighboring AS\n")
8358
8359 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8360 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8361 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8362 NO_STR
8363 NEIGHBOR_STR
8364 NEIGHBOR_ADDR_STR2
8365 "Use addpath to advertise the bestpath per each neighboring AS\n")
8366 {
8367 int idx_peer = 2;
8368 struct peer *peer;
8369
8370 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8371 if (!peer)
8372 return CMD_WARNING_CONFIG_FAILED;
8373
8374 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8375 != BGP_ADDPATH_BEST_PER_AS) {
8376 vty_out(vty,
8377 "%% Peer not currently configured to transmit all best path per as.");
8378 return CMD_WARNING_CONFIG_FAILED;
8379 }
8380
8381 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8382 BGP_ADDPATH_NONE);
8383
8384 return CMD_SUCCESS;
8385 }
8386
8387 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8388 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8389 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8390 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8391 "Use addpath to advertise the bestpath per each neighboring AS\n")
8392
8393 DEFPY(
8394 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8395 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8396 NEIGHBOR_STR
8397 NEIGHBOR_ADDR_STR2
8398 "Detect AS loops before sending to neighbor\n")
8399 {
8400 struct peer *peer;
8401
8402 peer = peer_and_group_lookup_vty(vty, neighbor);
8403 if (!peer)
8404 return CMD_WARNING_CONFIG_FAILED;
8405
8406 peer->as_path_loop_detection = true;
8407
8408 return CMD_SUCCESS;
8409 }
8410
8411 DEFPY(
8412 no_neighbor_aspath_loop_detection,
8413 no_neighbor_aspath_loop_detection_cmd,
8414 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8415 NO_STR
8416 NEIGHBOR_STR
8417 NEIGHBOR_ADDR_STR2
8418 "Detect AS loops before sending to neighbor\n")
8419 {
8420 struct peer *peer;
8421
8422 peer = peer_and_group_lookup_vty(vty, neighbor);
8423 if (!peer)
8424 return CMD_WARNING_CONFIG_FAILED;
8425
8426 peer->as_path_loop_detection = false;
8427
8428 return CMD_SUCCESS;
8429 }
8430
8431 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8432 struct ecommunity **list, bool is_rt6)
8433 {
8434 struct ecommunity *ecom = NULL;
8435 struct ecommunity *ecomadd;
8436
8437 for (; argc; --argc, ++argv) {
8438 if (is_rt6)
8439 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8440 ECOMMUNITY_ROUTE_TARGET,
8441 0);
8442 else
8443 ecomadd = ecommunity_str2com(argv[0]->arg,
8444 ECOMMUNITY_ROUTE_TARGET,
8445 0);
8446 if (!ecomadd) {
8447 vty_out(vty, "Malformed community-list value\n");
8448 if (ecom)
8449 ecommunity_free(&ecom);
8450 return CMD_WARNING_CONFIG_FAILED;
8451 }
8452
8453 if (ecom) {
8454 ecommunity_merge(ecom, ecomadd);
8455 ecommunity_free(&ecomadd);
8456 } else {
8457 ecom = ecomadd;
8458 }
8459 }
8460
8461 if (*list) {
8462 ecommunity_free(&*list);
8463 }
8464 *list = ecom;
8465
8466 return CMD_SUCCESS;
8467 }
8468
8469 /*
8470 * v2vimport is true if we are handling a `import vrf ...` command
8471 */
8472 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8473 {
8474 afi_t afi;
8475
8476 switch (vty->node) {
8477 case BGP_IPV4_NODE:
8478 afi = AFI_IP;
8479 break;
8480 case BGP_IPV6_NODE:
8481 afi = AFI_IP6;
8482 break;
8483 default:
8484 vty_out(vty,
8485 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8486 return AFI_MAX;
8487 }
8488
8489 if (!v2vimport) {
8490 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8491 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8492 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8493 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8494 vty_out(vty,
8495 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8496 return AFI_MAX;
8497 }
8498 } else {
8499 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8500 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8501 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8502 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8503 vty_out(vty,
8504 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8505 return AFI_MAX;
8506 }
8507 }
8508 return afi;
8509 }
8510
8511 DEFPY (af_rd_vpn_export,
8512 af_rd_vpn_export_cmd,
8513 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8514 NO_STR
8515 "Specify route distinguisher\n"
8516 "Between current address-family and vpn\n"
8517 "For routes leaked from current address-family to vpn\n"
8518 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8519 {
8520 VTY_DECLVAR_CONTEXT(bgp, bgp);
8521 struct prefix_rd prd;
8522 int ret;
8523 afi_t afi;
8524 int idx = 0;
8525 bool yes = true;
8526
8527 if (argv_find(argv, argc, "no", &idx))
8528 yes = false;
8529
8530 if (yes) {
8531 ret = str2prefix_rd(rd_str, &prd);
8532 if (!ret) {
8533 vty_out(vty, "%% Malformed rd\n");
8534 return CMD_WARNING_CONFIG_FAILED;
8535 }
8536 }
8537
8538 afi = vpn_policy_getafi(vty, bgp, false);
8539 if (afi == AFI_MAX)
8540 return CMD_WARNING_CONFIG_FAILED;
8541
8542 /*
8543 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8544 */
8545 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8546 bgp_get_default(), bgp);
8547
8548 if (yes) {
8549 bgp->vpn_policy[afi].tovpn_rd = prd;
8550 SET_FLAG(bgp->vpn_policy[afi].flags,
8551 BGP_VPN_POLICY_TOVPN_RD_SET);
8552 } else {
8553 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8554 BGP_VPN_POLICY_TOVPN_RD_SET);
8555 }
8556
8557 /* post-change: re-export vpn routes */
8558 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8559 bgp_get_default(), bgp);
8560
8561 return CMD_SUCCESS;
8562 }
8563
8564 ALIAS (af_rd_vpn_export,
8565 af_no_rd_vpn_export_cmd,
8566 "no rd vpn export",
8567 NO_STR
8568 "Specify route distinguisher\n"
8569 "Between current address-family and vpn\n"
8570 "For routes leaked from current address-family to vpn\n")
8571
8572 DEFPY (af_label_vpn_export,
8573 af_label_vpn_export_cmd,
8574 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8575 NO_STR
8576 "label value for VRF\n"
8577 "Between current address-family and vpn\n"
8578 "For routes leaked from current address-family to vpn\n"
8579 "Label Value <0-1048575>\n"
8580 "Automatically assign a label\n")
8581 {
8582 VTY_DECLVAR_CONTEXT(bgp, bgp);
8583 mpls_label_t label = MPLS_LABEL_NONE;
8584 afi_t afi;
8585 int idx = 0;
8586 bool yes = true;
8587
8588 if (argv_find(argv, argc, "no", &idx))
8589 yes = false;
8590
8591 /* If "no ...", squash trailing parameter */
8592 if (!yes)
8593 label_auto = NULL;
8594
8595 if (yes) {
8596 if (!label_auto)
8597 label = label_val; /* parser should force unsigned */
8598 }
8599
8600 afi = vpn_policy_getafi(vty, bgp, false);
8601 if (afi == AFI_MAX)
8602 return CMD_WARNING_CONFIG_FAILED;
8603
8604
8605 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8606 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8607 /* no change */
8608 return CMD_SUCCESS;
8609
8610 /*
8611 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8612 */
8613 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8614 bgp_get_default(), bgp);
8615
8616 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8617 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8618
8619 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8620
8621 /*
8622 * label has previously been automatically
8623 * assigned by labelpool: release it
8624 *
8625 * NB if tovpn_label == MPLS_LABEL_NONE it
8626 * means the automatic assignment is in flight
8627 * and therefore the labelpool callback must
8628 * detect that the auto label is not needed.
8629 */
8630
8631 bgp_lp_release(LP_TYPE_VRF,
8632 &bgp->vpn_policy[afi],
8633 bgp->vpn_policy[afi].tovpn_label);
8634 }
8635 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8636 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8637 }
8638
8639 bgp->vpn_policy[afi].tovpn_label = label;
8640 if (label_auto) {
8641 SET_FLAG(bgp->vpn_policy[afi].flags,
8642 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8643 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8644 vpn_leak_label_callback);
8645 }
8646
8647 /* post-change: re-export vpn routes */
8648 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8649 bgp_get_default(), bgp);
8650
8651 hook_call(bgp_snmp_update_last_changed, bgp);
8652 return CMD_SUCCESS;
8653 }
8654
8655 DEFPY (af_sid_vpn_export,
8656 af_sid_vpn_export_cmd,
8657 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8658 NO_STR
8659 "sid value for VRF\n"
8660 "Between current address-family and vpn\n"
8661 "For routes leaked from current address-family to vpn\n"
8662 "Sid allocation index\n"
8663 "Automatically assign a label\n")
8664 {
8665 VTY_DECLVAR_CONTEXT(bgp, bgp);
8666 afi_t afi;
8667 int debug = 0;
8668 int idx = 0;
8669 bool yes = true;
8670
8671 if (argv_find(argv, argc, "no", &idx))
8672 yes = false;
8673 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8674 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8675
8676 afi = vpn_policy_getafi(vty, bgp, false);
8677 if (afi == AFI_MAX)
8678 return CMD_WARNING_CONFIG_FAILED;
8679
8680 if (!yes) {
8681 /* implement me */
8682 vty_out(vty, "It's not implemented\n");
8683 return CMD_WARNING_CONFIG_FAILED;
8684 }
8685
8686 /* skip when it's already configured */
8687 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8688 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8689 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8690 return CMD_SUCCESS;
8691
8692 /*
8693 * mode change between sid_idx and sid_auto isn't supported.
8694 * user must negate sid vpn export when they want to change the mode
8695 */
8696 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8697 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8698 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8699 vty_out(vty, "it's already configured as %s.\n",
8700 sid_auto ? "auto-mode" : "idx-mode");
8701 return CMD_WARNING_CONFIG_FAILED;
8702 }
8703
8704 /* pre-change */
8705 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8706 bgp_get_default(), bgp);
8707
8708 if (sid_auto) {
8709 /* SID allocation auto-mode */
8710 if (debug)
8711 zlog_debug("%s: auto sid alloc.", __func__);
8712 SET_FLAG(bgp->vpn_policy[afi].flags,
8713 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8714 } else {
8715 /* SID allocation index-mode */
8716 if (debug)
8717 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8718 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8719 }
8720
8721 /* post-change */
8722 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8723 bgp_get_default(), bgp);
8724 return CMD_SUCCESS;
8725 }
8726
8727 ALIAS (af_label_vpn_export,
8728 af_no_label_vpn_export_cmd,
8729 "no label vpn export",
8730 NO_STR
8731 "label value for VRF\n"
8732 "Between current address-family and vpn\n"
8733 "For routes leaked from current address-family to vpn\n")
8734
8735 DEFPY (af_nexthop_vpn_export,
8736 af_nexthop_vpn_export_cmd,
8737 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8738 NO_STR
8739 "Specify next hop to use for VRF advertised prefixes\n"
8740 "Between current address-family and vpn\n"
8741 "For routes leaked from current address-family to vpn\n"
8742 "IPv4 prefix\n"
8743 "IPv6 prefix\n")
8744 {
8745 VTY_DECLVAR_CONTEXT(bgp, bgp);
8746 afi_t afi;
8747 struct prefix p;
8748
8749 if (!no) {
8750 if (!nexthop_su) {
8751 vty_out(vty, "%% Nexthop required\n");
8752 return CMD_WARNING_CONFIG_FAILED;
8753 }
8754 if (!sockunion2hostprefix(nexthop_su, &p))
8755 return CMD_WARNING_CONFIG_FAILED;
8756 }
8757
8758 afi = vpn_policy_getafi(vty, bgp, false);
8759 if (afi == AFI_MAX)
8760 return CMD_WARNING_CONFIG_FAILED;
8761
8762 /*
8763 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8764 */
8765 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8766 bgp_get_default(), bgp);
8767
8768 if (!no) {
8769 bgp->vpn_policy[afi].tovpn_nexthop = p;
8770 SET_FLAG(bgp->vpn_policy[afi].flags,
8771 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8772 } else {
8773 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8774 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8775 }
8776
8777 /* post-change: re-export vpn routes */
8778 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8779 bgp_get_default(), bgp);
8780
8781 return CMD_SUCCESS;
8782 }
8783
8784 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8785 {
8786 if (!strcmp(dstr, "import")) {
8787 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8788 } else if (!strcmp(dstr, "export")) {
8789 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8790 } else if (!strcmp(dstr, "both")) {
8791 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8792 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8793 } else {
8794 vty_out(vty, "%% direction parse error\n");
8795 return CMD_WARNING_CONFIG_FAILED;
8796 }
8797 return CMD_SUCCESS;
8798 }
8799
8800 DEFPY (af_rt_vpn_imexport,
8801 af_rt_vpn_imexport_cmd,
8802 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8803 NO_STR
8804 "Specify route target list\n"
8805 "Specify route target list\n"
8806 "Between current address-family and vpn\n"
8807 "For routes leaked from vpn to current address-family: match any\n"
8808 "For routes leaked from current address-family to vpn: set\n"
8809 "both import: match any and export: set\n"
8810 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8811 {
8812 VTY_DECLVAR_CONTEXT(bgp, bgp);
8813 int ret;
8814 struct ecommunity *ecom = NULL;
8815 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8816 enum vpn_policy_direction dir;
8817 afi_t afi;
8818 int idx = 0;
8819 bool yes = true;
8820
8821 if (argv_find(argv, argc, "no", &idx))
8822 yes = false;
8823
8824 afi = vpn_policy_getafi(vty, bgp, false);
8825 if (afi == AFI_MAX)
8826 return CMD_WARNING_CONFIG_FAILED;
8827
8828 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8829 if (ret != CMD_SUCCESS)
8830 return ret;
8831
8832 if (yes) {
8833 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8834 vty_out(vty, "%% Missing RTLIST\n");
8835 return CMD_WARNING_CONFIG_FAILED;
8836 }
8837 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
8838 if (ret != CMD_SUCCESS) {
8839 return ret;
8840 }
8841 }
8842
8843 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8844 if (!dodir[dir])
8845 continue;
8846
8847 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8848
8849 if (yes) {
8850 if (bgp->vpn_policy[afi].rtlist[dir])
8851 ecommunity_free(
8852 &bgp->vpn_policy[afi].rtlist[dir]);
8853 bgp->vpn_policy[afi].rtlist[dir] =
8854 ecommunity_dup(ecom);
8855 } else {
8856 if (bgp->vpn_policy[afi].rtlist[dir])
8857 ecommunity_free(
8858 &bgp->vpn_policy[afi].rtlist[dir]);
8859 bgp->vpn_policy[afi].rtlist[dir] = NULL;
8860 }
8861
8862 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8863 }
8864
8865 if (ecom)
8866 ecommunity_free(&ecom);
8867
8868 return CMD_SUCCESS;
8869 }
8870
8871 ALIAS (af_rt_vpn_imexport,
8872 af_no_rt_vpn_imexport_cmd,
8873 "no <rt|route-target> vpn <import|export|both>$direction_str",
8874 NO_STR
8875 "Specify route target list\n"
8876 "Specify route target list\n"
8877 "Between current address-family and vpn\n"
8878 "For routes leaked from vpn to current address-family\n"
8879 "For routes leaked from current address-family to vpn\n"
8880 "both import and export\n")
8881
8882 DEFPY (af_route_map_vpn_imexport,
8883 af_route_map_vpn_imexport_cmd,
8884 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8885 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8886 NO_STR
8887 "Specify route map\n"
8888 "Between current address-family and vpn\n"
8889 "For routes leaked from vpn to current address-family\n"
8890 "For routes leaked from current address-family to vpn\n"
8891 "name of route-map\n")
8892 {
8893 VTY_DECLVAR_CONTEXT(bgp, bgp);
8894 int ret;
8895 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8896 enum vpn_policy_direction dir;
8897 afi_t afi;
8898 int idx = 0;
8899 bool yes = true;
8900
8901 if (argv_find(argv, argc, "no", &idx))
8902 yes = false;
8903
8904 afi = vpn_policy_getafi(vty, bgp, false);
8905 if (afi == AFI_MAX)
8906 return CMD_WARNING_CONFIG_FAILED;
8907
8908 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8909 if (ret != CMD_SUCCESS)
8910 return ret;
8911
8912 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8913 if (!dodir[dir])
8914 continue;
8915
8916 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8917
8918 if (yes) {
8919 if (bgp->vpn_policy[afi].rmap_name[dir])
8920 XFREE(MTYPE_ROUTE_MAP_NAME,
8921 bgp->vpn_policy[afi].rmap_name[dir]);
8922 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8923 MTYPE_ROUTE_MAP_NAME, rmap_str);
8924 bgp->vpn_policy[afi].rmap[dir] =
8925 route_map_lookup_warn_noexist(vty, rmap_str);
8926 if (!bgp->vpn_policy[afi].rmap[dir])
8927 return CMD_SUCCESS;
8928 } else {
8929 if (bgp->vpn_policy[afi].rmap_name[dir])
8930 XFREE(MTYPE_ROUTE_MAP_NAME,
8931 bgp->vpn_policy[afi].rmap_name[dir]);
8932 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8933 bgp->vpn_policy[afi].rmap[dir] = NULL;
8934 }
8935
8936 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8937 }
8938
8939 return CMD_SUCCESS;
8940 }
8941
8942 ALIAS (af_route_map_vpn_imexport,
8943 af_no_route_map_vpn_imexport_cmd,
8944 "no route-map vpn <import|export>$direction_str",
8945 NO_STR
8946 "Specify route map\n"
8947 "Between current address-family and vpn\n"
8948 "For routes leaked from vpn to current address-family\n"
8949 "For routes leaked from current address-family to vpn\n")
8950
8951 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
8952 "import vrf route-map RMAP$rmap_str",
8953 "Import routes from another VRF\n"
8954 "Vrf routes being filtered\n"
8955 "Specify route map\n"
8956 "name of route-map\n")
8957 {
8958 VTY_DECLVAR_CONTEXT(bgp, bgp);
8959 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
8960 afi_t afi;
8961 struct bgp *bgp_default;
8962
8963 afi = vpn_policy_getafi(vty, bgp, true);
8964 if (afi == AFI_MAX)
8965 return CMD_WARNING_CONFIG_FAILED;
8966
8967 bgp_default = bgp_get_default();
8968 if (!bgp_default) {
8969 int32_t ret;
8970 as_t as = bgp->as;
8971
8972 /* Auto-create assuming the same AS */
8973 ret = bgp_get_vty(&bgp_default, &as, NULL,
8974 BGP_INSTANCE_TYPE_DEFAULT);
8975
8976 if (ret) {
8977 vty_out(vty,
8978 "VRF default is not configured as a bgp instance\n");
8979 return CMD_WARNING;
8980 }
8981 }
8982
8983 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8984
8985 if (bgp->vpn_policy[afi].rmap_name[dir])
8986 XFREE(MTYPE_ROUTE_MAP_NAME,
8987 bgp->vpn_policy[afi].rmap_name[dir]);
8988 bgp->vpn_policy[afi].rmap_name[dir] =
8989 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8990 bgp->vpn_policy[afi].rmap[dir] =
8991 route_map_lookup_warn_noexist(vty, rmap_str);
8992 if (!bgp->vpn_policy[afi].rmap[dir])
8993 return CMD_SUCCESS;
8994
8995 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8996 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8997
8998 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8999
9000 return CMD_SUCCESS;
9001 }
9002
9003 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9004 "no import vrf route-map [RMAP$rmap_str]",
9005 NO_STR
9006 "Import routes from another VRF\n"
9007 "Vrf routes being filtered\n"
9008 "Specify route map\n"
9009 "name of route-map\n")
9010 {
9011 VTY_DECLVAR_CONTEXT(bgp, bgp);
9012 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9013 afi_t afi;
9014
9015 afi = vpn_policy_getafi(vty, bgp, true);
9016 if (afi == AFI_MAX)
9017 return CMD_WARNING_CONFIG_FAILED;
9018
9019 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9020
9021 if (bgp->vpn_policy[afi].rmap_name[dir])
9022 XFREE(MTYPE_ROUTE_MAP_NAME,
9023 bgp->vpn_policy[afi].rmap_name[dir]);
9024 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9025 bgp->vpn_policy[afi].rmap[dir] = NULL;
9026
9027 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9028 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9029 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9030
9031 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9032
9033 return CMD_SUCCESS;
9034 }
9035
9036 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9037 "[no] import vrf VIEWVRFNAME$import_name",
9038 NO_STR
9039 "Import routes from another VRF\n"
9040 "VRF to import from\n"
9041 "The name of the VRF\n")
9042 {
9043 VTY_DECLVAR_CONTEXT(bgp, bgp);
9044 struct listnode *node;
9045 struct bgp *vrf_bgp, *bgp_default;
9046 int32_t ret = 0;
9047 as_t as = bgp->as;
9048 bool remove = false;
9049 int32_t idx = 0;
9050 char *vname;
9051 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9052 safi_t safi;
9053 afi_t afi;
9054
9055 if (import_name == NULL) {
9056 vty_out(vty, "%% Missing import name\n");
9057 return CMD_WARNING;
9058 }
9059
9060 if (strcmp(import_name, "route-map") == 0) {
9061 vty_out(vty, "%% Must include route-map name\n");
9062 return CMD_WARNING;
9063 }
9064
9065 if (argv_find(argv, argc, "no", &idx))
9066 remove = true;
9067
9068 afi = vpn_policy_getafi(vty, bgp, true);
9069 if (afi == AFI_MAX)
9070 return CMD_WARNING_CONFIG_FAILED;
9071
9072 safi = bgp_node_safi(vty);
9073
9074 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9075 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9076 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9077 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9078 remove ? "unimport" : "import", import_name);
9079 return CMD_WARNING;
9080 }
9081
9082 bgp_default = bgp_get_default();
9083 if (!bgp_default) {
9084 /* Auto-create assuming the same AS */
9085 ret = bgp_get_vty(&bgp_default, &as, NULL,
9086 BGP_INSTANCE_TYPE_DEFAULT);
9087
9088 if (ret) {
9089 vty_out(vty,
9090 "VRF default is not configured as a bgp instance\n");
9091 return CMD_WARNING;
9092 }
9093 }
9094
9095 vrf_bgp = bgp_lookup_by_name(import_name);
9096 if (!vrf_bgp) {
9097 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9098 vrf_bgp = bgp_default;
9099 else
9100 /* Auto-create assuming the same AS */
9101 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9102
9103 if (ret) {
9104 vty_out(vty,
9105 "VRF %s is not configured as a bgp instance\n",
9106 import_name);
9107 return CMD_WARNING;
9108 }
9109 }
9110
9111 if (remove) {
9112 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9113 } else {
9114 /* Already importing from "import_vrf"? */
9115 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9116 vname)) {
9117 if (strcmp(vname, import_name) == 0)
9118 return CMD_WARNING;
9119 }
9120
9121 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9122 }
9123
9124 return CMD_SUCCESS;
9125 }
9126
9127 /* This command is valid only in a bgp vrf instance or the default instance */
9128 DEFPY (bgp_imexport_vpn,
9129 bgp_imexport_vpn_cmd,
9130 "[no] <import|export>$direction_str vpn",
9131 NO_STR
9132 "Import routes to this address-family\n"
9133 "Export routes from this address-family\n"
9134 "to/from default instance VPN RIB\n")
9135 {
9136 VTY_DECLVAR_CONTEXT(bgp, bgp);
9137 int previous_state;
9138 afi_t afi;
9139 safi_t safi;
9140 int idx = 0;
9141 bool yes = true;
9142 int flag;
9143 enum vpn_policy_direction dir;
9144
9145 if (argv_find(argv, argc, "no", &idx))
9146 yes = false;
9147
9148 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9149 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9150
9151 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9152 return CMD_WARNING_CONFIG_FAILED;
9153 }
9154
9155 afi = bgp_node_afi(vty);
9156 safi = bgp_node_safi(vty);
9157 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9158 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9159 return CMD_WARNING_CONFIG_FAILED;
9160 }
9161
9162 if (!strcmp(direction_str, "import")) {
9163 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9164 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9165 } else if (!strcmp(direction_str, "export")) {
9166 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9167 dir = BGP_VPN_POLICY_DIR_TOVPN;
9168 } else {
9169 vty_out(vty, "%% unknown direction %s\n", direction_str);
9170 return CMD_WARNING_CONFIG_FAILED;
9171 }
9172
9173 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9174
9175 if (yes) {
9176 SET_FLAG(bgp->af_flags[afi][safi], flag);
9177 if (!previous_state) {
9178 /* trigger export current vrf */
9179 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9180 }
9181 } else {
9182 if (previous_state) {
9183 /* trigger un-export current vrf */
9184 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9185 }
9186 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9187 }
9188
9189 hook_call(bgp_snmp_init_stats, bgp);
9190
9191 return CMD_SUCCESS;
9192 }
9193
9194 DEFPY (af_routetarget_import,
9195 af_routetarget_import_cmd,
9196 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9197 NO_STR
9198 "Specify route target list\n"
9199 "Specify route target list\n"
9200 "Specify route target list\n"
9201 "Specify route target list\n"
9202 "Flow-spec redirect type route target\n"
9203 "Import routes to this address-family\n"
9204 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9205 {
9206 VTY_DECLVAR_CONTEXT(bgp, bgp);
9207 int ret;
9208 struct ecommunity *ecom = NULL;
9209 afi_t afi;
9210 int idx = 0, idx_unused = 0;
9211 bool yes = true;
9212 bool rt6 = false;
9213
9214 if (argv_find(argv, argc, "no", &idx))
9215 yes = false;
9216
9217 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9218 argv_find(argv, argc, "route-target6", &idx_unused))
9219 rt6 = true;
9220
9221 afi = vpn_policy_getafi(vty, bgp, false);
9222 if (afi == AFI_MAX)
9223 return CMD_WARNING_CONFIG_FAILED;
9224
9225 if (rt6 && afi != AFI_IP6)
9226 return CMD_WARNING_CONFIG_FAILED;
9227
9228 if (yes) {
9229 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9230 vty_out(vty, "%% Missing RTLIST\n");
9231 return CMD_WARNING_CONFIG_FAILED;
9232 }
9233 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9234 if (ret != CMD_SUCCESS)
9235 return ret;
9236 }
9237
9238 if (yes) {
9239 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9240 ecommunity_free(&bgp->vpn_policy[afi]
9241 .import_redirect_rtlist);
9242 bgp->vpn_policy[afi].import_redirect_rtlist =
9243 ecommunity_dup(ecom);
9244 } else {
9245 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9246 ecommunity_free(&bgp->vpn_policy[afi]
9247 .import_redirect_rtlist);
9248 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9249 }
9250
9251 if (ecom)
9252 ecommunity_free(&ecom);
9253
9254 return CMD_SUCCESS;
9255 }
9256
9257 DEFUN_NOSH (address_family_ipv4_safi,
9258 address_family_ipv4_safi_cmd,
9259 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9260 "Enter Address Family command mode\n"
9261 "Address Family\n"
9262 BGP_SAFI_WITH_LABEL_HELP_STR)
9263 {
9264
9265 if (argc == 3) {
9266 VTY_DECLVAR_CONTEXT(bgp, bgp);
9267 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9268 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9269 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9270 && safi != SAFI_EVPN) {
9271 vty_out(vty,
9272 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9273 return CMD_WARNING_CONFIG_FAILED;
9274 }
9275 vty->node = bgp_node_type(AFI_IP, safi);
9276 } else
9277 vty->node = BGP_IPV4_NODE;
9278
9279 return CMD_SUCCESS;
9280 }
9281
9282 DEFUN_NOSH (address_family_ipv6_safi,
9283 address_family_ipv6_safi_cmd,
9284 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9285 "Enter Address Family command mode\n"
9286 "Address Family\n"
9287 BGP_SAFI_WITH_LABEL_HELP_STR)
9288 {
9289 if (argc == 3) {
9290 VTY_DECLVAR_CONTEXT(bgp, bgp);
9291 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9292 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9293 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9294 && safi != SAFI_EVPN) {
9295 vty_out(vty,
9296 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9297 return CMD_WARNING_CONFIG_FAILED;
9298 }
9299 vty->node = bgp_node_type(AFI_IP6, safi);
9300 } else
9301 vty->node = BGP_IPV6_NODE;
9302
9303 return CMD_SUCCESS;
9304 }
9305
9306 #ifdef KEEP_OLD_VPN_COMMANDS
9307 DEFUN_NOSH (address_family_vpnv4,
9308 address_family_vpnv4_cmd,
9309 "address-family vpnv4 [unicast]",
9310 "Enter Address Family command mode\n"
9311 "Address Family\n"
9312 "Address Family modifier\n")
9313 {
9314 vty->node = BGP_VPNV4_NODE;
9315 return CMD_SUCCESS;
9316 }
9317
9318 DEFUN_NOSH (address_family_vpnv6,
9319 address_family_vpnv6_cmd,
9320 "address-family vpnv6 [unicast]",
9321 "Enter Address Family command mode\n"
9322 "Address Family\n"
9323 "Address Family modifier\n")
9324 {
9325 vty->node = BGP_VPNV6_NODE;
9326 return CMD_SUCCESS;
9327 }
9328 #endif /* KEEP_OLD_VPN_COMMANDS */
9329
9330 DEFUN_NOSH (address_family_evpn,
9331 address_family_evpn_cmd,
9332 "address-family l2vpn evpn",
9333 "Enter Address Family command mode\n"
9334 "Address Family\n"
9335 "Address Family modifier\n")
9336 {
9337 VTY_DECLVAR_CONTEXT(bgp, bgp);
9338 vty->node = BGP_EVPN_NODE;
9339 return CMD_SUCCESS;
9340 }
9341
9342 DEFUN_NOSH (bgp_segment_routing_srv6,
9343 bgp_segment_routing_srv6_cmd,
9344 "segment-routing srv6",
9345 "Segment-Routing configuration\n"
9346 "Segment-Routing SRv6 configuration\n")
9347 {
9348 VTY_DECLVAR_CONTEXT(bgp, bgp);
9349 bgp->srv6_enabled = true;
9350 vty->node = BGP_SRV6_NODE;
9351 return CMD_SUCCESS;
9352 }
9353
9354 DEFUN (no_bgp_segment_routing_srv6,
9355 no_bgp_segment_routing_srv6_cmd,
9356 "no segment-routing srv6",
9357 NO_STR
9358 "Segment-Routing configuration\n"
9359 "Segment-Routing SRv6 configuration\n")
9360 {
9361 VTY_DECLVAR_CONTEXT(bgp, bgp);
9362
9363 if (strlen(bgp->srv6_locator_name) > 0)
9364 if (bgp_srv6_locator_unset(bgp) < 0)
9365 return CMD_WARNING_CONFIG_FAILED;
9366
9367 bgp->srv6_enabled = false;
9368 return CMD_SUCCESS;
9369 }
9370
9371 DEFPY (bgp_srv6_locator,
9372 bgp_srv6_locator_cmd,
9373 "locator NAME$name",
9374 "Specify SRv6 locator\n"
9375 "Specify SRv6 locator\n")
9376 {
9377 VTY_DECLVAR_CONTEXT(bgp, bgp);
9378 int ret;
9379
9380 if (strlen(bgp->srv6_locator_name) > 0
9381 && strcmp(name, bgp->srv6_locator_name) != 0) {
9382 vty_out(vty, "srv6 locator is already configured\n");
9383 return CMD_WARNING_CONFIG_FAILED;
9384 }
9385
9386 snprintf(bgp->srv6_locator_name,
9387 sizeof(bgp->srv6_locator_name), "%s", name);
9388
9389 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9390 if (ret < 0)
9391 return CMD_WARNING_CONFIG_FAILED;
9392
9393 return CMD_SUCCESS;
9394 }
9395
9396 DEFPY (no_bgp_srv6_locator,
9397 no_bgp_srv6_locator_cmd,
9398 "no locator NAME$name",
9399 NO_STR
9400 "Specify SRv6 locator\n"
9401 "Specify SRv6 locator\n")
9402 {
9403 VTY_DECLVAR_CONTEXT(bgp, bgp);
9404
9405 /* when locator isn't configured, do nothing */
9406 if (strlen(bgp->srv6_locator_name) < 1)
9407 return CMD_SUCCESS;
9408
9409 /* name validation */
9410 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9411 vty_out(vty, "%% No srv6 locator is configured\n");
9412 return CMD_WARNING_CONFIG_FAILED;
9413 }
9414
9415 /* unset locator */
9416 if (bgp_srv6_locator_unset(bgp) < 0)
9417 return CMD_WARNING_CONFIG_FAILED;
9418
9419 return CMD_SUCCESS;
9420 }
9421
9422 DEFPY (show_bgp_srv6,
9423 show_bgp_srv6_cmd,
9424 "show bgp segment-routing srv6",
9425 SHOW_STR
9426 BGP_STR
9427 "BGP Segment Routing\n"
9428 "BGP Segment Routing SRv6\n")
9429 {
9430 struct bgp *bgp;
9431 struct listnode *node;
9432 struct srv6_locator_chunk *chunk;
9433 struct bgp_srv6_function *func;
9434 struct in6_addr *tovpn4_sid;
9435 struct in6_addr *tovpn6_sid;
9436 char buf[256];
9437 char buf_tovpn4_sid[256];
9438 char buf_tovpn6_sid[256];
9439
9440 bgp = bgp_get_default();
9441 if (!bgp)
9442 return CMD_SUCCESS;
9443
9444 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9445 vty_out(vty, "locator_chunks:\n");
9446 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9447 prefix2str(&chunk->prefix, buf, sizeof(buf));
9448 vty_out(vty, "- %s\n", buf);
9449 }
9450
9451 vty_out(vty, "functions:\n");
9452 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9453 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9454 vty_out(vty, "- sid: %s\n", buf);
9455 vty_out(vty, " locator: %s\n", func->locator_name);
9456 }
9457
9458 vty_out(vty, "bgps:\n");
9459 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9460 vty_out(vty, "- name: %s\n",
9461 bgp->name ? bgp->name : "default");
9462
9463 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9464 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9465 if (tovpn4_sid)
9466 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9467 sizeof(buf_tovpn4_sid));
9468 if (tovpn6_sid)
9469 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9470 sizeof(buf_tovpn6_sid));
9471
9472 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9473 tovpn4_sid ? buf_tovpn4_sid : "none");
9474 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9475 tovpn6_sid ? buf_tovpn6_sid : "none");
9476 }
9477
9478 return CMD_SUCCESS;
9479 }
9480
9481 DEFUN_NOSH (exit_address_family,
9482 exit_address_family_cmd,
9483 "exit-address-family",
9484 "Exit from Address Family configuration mode\n")
9485 {
9486 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9487 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9488 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9489 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9490 || vty->node == BGP_EVPN_NODE
9491 || vty->node == BGP_FLOWSPECV4_NODE
9492 || vty->node == BGP_FLOWSPECV6_NODE)
9493 vty->node = BGP_NODE;
9494 return CMD_SUCCESS;
9495 }
9496
9497 /* Recalculate bestpath and re-advertise a prefix */
9498 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9499 const char *ip_str, afi_t afi, safi_t safi,
9500 struct prefix_rd *prd)
9501 {
9502 int ret;
9503 struct prefix match;
9504 struct bgp_dest *dest;
9505 struct bgp_dest *rm;
9506 struct bgp *bgp;
9507 struct bgp_table *table;
9508 struct bgp_table *rib;
9509
9510 /* BGP structure lookup. */
9511 if (view_name) {
9512 bgp = bgp_lookup_by_name(view_name);
9513 if (bgp == NULL) {
9514 vty_out(vty, "%% Can't find BGP instance %s\n",
9515 view_name);
9516 return CMD_WARNING;
9517 }
9518 } else {
9519 bgp = bgp_get_default();
9520 if (bgp == NULL) {
9521 vty_out(vty, "%% No BGP process is configured\n");
9522 return CMD_WARNING;
9523 }
9524 }
9525
9526 /* Check IP address argument. */
9527 ret = str2prefix(ip_str, &match);
9528 if (!ret) {
9529 vty_out(vty, "%% address is malformed\n");
9530 return CMD_WARNING;
9531 }
9532
9533 match.family = afi2family(afi);
9534 rib = bgp->rib[afi][safi];
9535
9536 if (safi == SAFI_MPLS_VPN) {
9537 for (dest = bgp_table_top(rib); dest;
9538 dest = bgp_route_next(dest)) {
9539 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9540
9541 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9542 continue;
9543
9544 table = bgp_dest_get_bgp_table_info(dest);
9545 if (table == NULL)
9546 continue;
9547
9548 rm = bgp_node_match(table, &match);
9549 if (rm != NULL) {
9550 const struct prefix *rm_p =
9551 bgp_dest_get_prefix(rm);
9552
9553 if (rm_p->prefixlen == match.prefixlen) {
9554 SET_FLAG(rm->flags,
9555 BGP_NODE_USER_CLEAR);
9556 bgp_process(bgp, rm, afi, safi);
9557 }
9558 bgp_dest_unlock_node(rm);
9559 }
9560 }
9561 } else {
9562 dest = bgp_node_match(rib, &match);
9563 if (dest != NULL) {
9564 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9565
9566 if (dest_p->prefixlen == match.prefixlen) {
9567 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9568 bgp_process(bgp, dest, afi, safi);
9569 }
9570 bgp_dest_unlock_node(dest);
9571 }
9572 }
9573
9574 return CMD_SUCCESS;
9575 }
9576
9577 /* one clear bgp command to rule them all */
9578 DEFUN (clear_ip_bgp_all,
9579 clear_ip_bgp_all_cmd,
9580 "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>]",
9581 CLEAR_STR
9582 IP_STR
9583 BGP_STR
9584 BGP_INSTANCE_HELP_STR
9585 BGP_AFI_HELP_STR
9586 "Address Family\n"
9587 BGP_SAFI_WITH_LABEL_HELP_STR
9588 "Address Family modifier\n"
9589 "Clear all peers\n"
9590 "BGP IPv4 neighbor to clear\n"
9591 "BGP IPv6 neighbor to clear\n"
9592 "BGP neighbor on interface to clear\n"
9593 "Clear peers with the AS number\n"
9594 "Clear all external peers\n"
9595 "Clear all members of peer-group\n"
9596 "BGP peer-group name\n"
9597 BGP_SOFT_STR
9598 BGP_SOFT_IN_STR
9599 BGP_SOFT_OUT_STR
9600 BGP_SOFT_IN_STR
9601 "Push out prefix-list ORF and do inbound soft reconfig\n"
9602 BGP_SOFT_OUT_STR
9603 "Reset message statistics\n")
9604 {
9605 char *vrf = NULL;
9606
9607 afi_t afi = AFI_UNSPEC;
9608 safi_t safi = SAFI_UNSPEC;
9609 enum clear_sort clr_sort = clear_peer;
9610 enum bgp_clear_type clr_type;
9611 char *clr_arg = NULL;
9612
9613 int idx = 0;
9614
9615 /* clear [ip] bgp */
9616 if (argv_find(argv, argc, "ip", &idx))
9617 afi = AFI_IP;
9618
9619 /* [<vrf> VIEWVRFNAME] */
9620 if (argv_find(argv, argc, "vrf", &idx)) {
9621 vrf = argv[idx + 1]->arg;
9622 idx += 2;
9623 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9624 vrf = NULL;
9625 } else if (argv_find(argv, argc, "view", &idx)) {
9626 /* [<view> VIEWVRFNAME] */
9627 vrf = argv[idx + 1]->arg;
9628 idx += 2;
9629 }
9630 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9631 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9632 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9633
9634 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9635 if (argv_find(argv, argc, "*", &idx)) {
9636 clr_sort = clear_all;
9637 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9638 clr_sort = clear_peer;
9639 clr_arg = argv[idx]->arg;
9640 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9641 clr_sort = clear_peer;
9642 clr_arg = argv[idx]->arg;
9643 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9644 clr_sort = clear_group;
9645 idx++;
9646 clr_arg = argv[idx]->arg;
9647 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9648 clr_sort = clear_peer;
9649 clr_arg = argv[idx]->arg;
9650 } else if (argv_find(argv, argc, "WORD", &idx)) {
9651 clr_sort = clear_peer;
9652 clr_arg = argv[idx]->arg;
9653 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9654 clr_sort = clear_as;
9655 clr_arg = argv[idx]->arg;
9656 } else if (argv_find(argv, argc, "external", &idx)) {
9657 clr_sort = clear_external;
9658 }
9659
9660 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9661 if (argv_find(argv, argc, "soft", &idx)) {
9662 if (argv_find(argv, argc, "in", &idx)
9663 || argv_find(argv, argc, "out", &idx))
9664 clr_type = strmatch(argv[idx]->text, "in")
9665 ? BGP_CLEAR_SOFT_IN
9666 : BGP_CLEAR_SOFT_OUT;
9667 else
9668 clr_type = BGP_CLEAR_SOFT_BOTH;
9669 } else if (argv_find(argv, argc, "in", &idx)) {
9670 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9671 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9672 : BGP_CLEAR_SOFT_IN;
9673 } else if (argv_find(argv, argc, "out", &idx)) {
9674 clr_type = BGP_CLEAR_SOFT_OUT;
9675 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9676 clr_type = BGP_CLEAR_MESSAGE_STATS;
9677 } else
9678 clr_type = BGP_CLEAR_SOFT_NONE;
9679
9680 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9681 }
9682
9683 DEFUN (clear_ip_bgp_prefix,
9684 clear_ip_bgp_prefix_cmd,
9685 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9686 CLEAR_STR
9687 IP_STR
9688 BGP_STR
9689 BGP_INSTANCE_HELP_STR
9690 "Clear bestpath and re-advertise\n"
9691 "IPv4 prefix\n")
9692 {
9693 char *vrf = NULL;
9694 char *prefix = NULL;
9695
9696 int idx = 0;
9697
9698 /* [<view|vrf> VIEWVRFNAME] */
9699 if (argv_find(argv, argc, "vrf", &idx)) {
9700 vrf = argv[idx + 1]->arg;
9701 idx += 2;
9702 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9703 vrf = NULL;
9704 } else if (argv_find(argv, argc, "view", &idx)) {
9705 /* [<view> VIEWVRFNAME] */
9706 vrf = argv[idx + 1]->arg;
9707 idx += 2;
9708 }
9709
9710 prefix = argv[argc - 1]->arg;
9711
9712 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9713 }
9714
9715 DEFUN (clear_bgp_ipv6_safi_prefix,
9716 clear_bgp_ipv6_safi_prefix_cmd,
9717 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9718 CLEAR_STR
9719 IP_STR
9720 BGP_STR
9721 "Address Family\n"
9722 BGP_SAFI_HELP_STR
9723 "Clear bestpath and re-advertise\n"
9724 "IPv6 prefix\n")
9725 {
9726 int idx_safi = 0;
9727 int idx_ipv6_prefix = 0;
9728 safi_t safi = SAFI_UNICAST;
9729 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9730 argv[idx_ipv6_prefix]->arg : NULL;
9731
9732 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9733 return bgp_clear_prefix(
9734 vty, NULL, prefix, AFI_IP6,
9735 safi, NULL);
9736 }
9737
9738 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9739 clear_bgp_instance_ipv6_safi_prefix_cmd,
9740 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9741 CLEAR_STR
9742 IP_STR
9743 BGP_STR
9744 BGP_INSTANCE_HELP_STR
9745 "Address Family\n"
9746 BGP_SAFI_HELP_STR
9747 "Clear bestpath and re-advertise\n"
9748 "IPv6 prefix\n")
9749 {
9750 int idx_safi = 0;
9751 int idx_vrfview = 0;
9752 int idx_ipv6_prefix = 0;
9753 safi_t safi = SAFI_UNICAST;
9754 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9755 argv[idx_ipv6_prefix]->arg : NULL;
9756 char *vrfview = NULL;
9757
9758 /* [<view|vrf> VIEWVRFNAME] */
9759 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9760 vrfview = argv[idx_vrfview + 1]->arg;
9761 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9762 vrfview = NULL;
9763 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9764 /* [<view> VIEWVRFNAME] */
9765 vrfview = argv[idx_vrfview + 1]->arg;
9766 }
9767 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9768
9769 return bgp_clear_prefix(
9770 vty, vrfview, prefix,
9771 AFI_IP6, safi, NULL);
9772 }
9773
9774 DEFUN (show_bgp_views,
9775 show_bgp_views_cmd,
9776 "show [ip] bgp views",
9777 SHOW_STR
9778 IP_STR
9779 BGP_STR
9780 "Show the defined BGP views\n")
9781 {
9782 struct list *inst = bm->bgp;
9783 struct listnode *node;
9784 struct bgp *bgp;
9785
9786 vty_out(vty, "Defined BGP views:\n");
9787 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9788 /* Skip VRFs. */
9789 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9790 continue;
9791 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9792 bgp->as);
9793 }
9794
9795 return CMD_SUCCESS;
9796 }
9797
9798 DEFUN (show_bgp_vrfs,
9799 show_bgp_vrfs_cmd,
9800 "show [ip] bgp vrfs [json]",
9801 SHOW_STR
9802 IP_STR
9803 BGP_STR
9804 "Show BGP VRFs\n"
9805 JSON_STR)
9806 {
9807 char buf[ETHER_ADDR_STRLEN];
9808 struct list *inst = bm->bgp;
9809 struct listnode *node;
9810 struct bgp *bgp;
9811 bool uj = use_json(argc, argv);
9812 json_object *json = NULL;
9813 json_object *json_vrfs = NULL;
9814 int count = 0;
9815
9816 if (uj) {
9817 json = json_object_new_object();
9818 json_vrfs = json_object_new_object();
9819 }
9820
9821 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9822 const char *name, *type;
9823 struct peer *peer;
9824 struct listnode *node2, *nnode2;
9825 int peers_cfg, peers_estb;
9826 json_object *json_vrf = NULL;
9827
9828 /* Skip Views. */
9829 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9830 continue;
9831
9832 count++;
9833 if (!uj && count == 1) {
9834 vty_out(vty,
9835 "%4s %-5s %-16s %9s %10s %-37s\n",
9836 "Type", "Id", "routerId", "#PeersCfg",
9837 "#PeersEstb", "Name");
9838 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9839 "L3-VNI", "RouterMAC", "Interface");
9840 }
9841
9842 peers_cfg = peers_estb = 0;
9843 if (uj)
9844 json_vrf = json_object_new_object();
9845
9846
9847 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9848 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9849 continue;
9850 peers_cfg++;
9851 if (peer_established(peer))
9852 peers_estb++;
9853 }
9854
9855 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
9856 name = VRF_DEFAULT_NAME;
9857 type = "DFLT";
9858 } else {
9859 name = bgp->name;
9860 type = "VRF";
9861 }
9862
9863
9864 if (uj) {
9865 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9866 ? -1
9867 : (int64_t)bgp->vrf_id;
9868 char buf[BUFSIZ] = {0};
9869
9870 json_object_string_add(json_vrf, "type", type);
9871 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9872 json_object_string_addf(json_vrf, "routerId", "%pI4",
9873 &bgp->router_id);
9874 json_object_int_add(json_vrf, "numConfiguredPeers",
9875 peers_cfg);
9876 json_object_int_add(json_vrf, "numEstablishedPeers",
9877 peers_estb);
9878
9879 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
9880 json_object_string_add(
9881 json_vrf, "rmac",
9882 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
9883 json_object_string_add(json_vrf, "interface",
9884 ifindex2ifname(bgp->l3vni_svi_ifindex,
9885 bgp->vrf_id));
9886 json_object_object_add(json_vrfs, name, json_vrf);
9887 } else {
9888 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
9889 type,
9890 bgp->vrf_id == VRF_UNKNOWN ? -1
9891 : (int)bgp->vrf_id,
9892 &bgp->router_id, peers_cfg, peers_estb, name);
9893 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9894 bgp->l3vni,
9895 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9896 ifindex2ifname(bgp->l3vni_svi_ifindex,
9897 bgp->vrf_id));
9898 }
9899 }
9900
9901 if (uj) {
9902 json_object_object_add(json, "vrfs", json_vrfs);
9903
9904 json_object_int_add(json, "totalVrfs", count);
9905
9906 vty_json(vty, json);
9907 } else {
9908 if (count)
9909 vty_out(vty,
9910 "\nTotal number of VRFs (including default): %d\n",
9911 count);
9912 }
9913
9914 return CMD_SUCCESS;
9915 }
9916
9917 DEFUN (show_bgp_mac_hash,
9918 show_bgp_mac_hash_cmd,
9919 "show bgp mac hash",
9920 SHOW_STR
9921 BGP_STR
9922 "Mac Address\n"
9923 "Mac Address database\n")
9924 {
9925 bgp_mac_dump_table(vty);
9926
9927 return CMD_SUCCESS;
9928 }
9929
9930 static void show_tip_entry(struct hash_bucket *bucket, void *args)
9931 {
9932 struct vty *vty = (struct vty *)args;
9933 struct tip_addr *tip = (struct tip_addr *)bucket->data;
9934
9935 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
9936 }
9937
9938 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9939 {
9940 vty_out(vty, "self nexthop database:\n");
9941 bgp_nexthop_show_address_hash(vty, bgp);
9942
9943 vty_out(vty, "Tunnel-ip database:\n");
9944 hash_iterate(bgp->tip_hash,
9945 (void (*)(struct hash_bucket *, void *))show_tip_entry,
9946 vty);
9947 }
9948
9949 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9950 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9951 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
9952 "martian next-hops\n"
9953 "martian next-hop database\n")
9954 {
9955 struct bgp *bgp = NULL;
9956 int idx = 0;
9957 char *name = NULL;
9958
9959 /* [<vrf> VIEWVRFNAME] */
9960 if (argv_find(argv, argc, "vrf", &idx)) {
9961 name = argv[idx + 1]->arg;
9962 if (name && strmatch(name, VRF_DEFAULT_NAME))
9963 name = NULL;
9964 } else if (argv_find(argv, argc, "view", &idx))
9965 /* [<view> VIEWVRFNAME] */
9966 name = argv[idx + 1]->arg;
9967 if (name)
9968 bgp = bgp_lookup_by_name(name);
9969 else
9970 bgp = bgp_get_default();
9971
9972 if (!bgp) {
9973 vty_out(vty, "%% No BGP process is configured\n");
9974 return CMD_WARNING;
9975 }
9976 bgp_show_martian_nexthops(vty, bgp);
9977
9978 return CMD_SUCCESS;
9979 }
9980
9981 DEFUN (show_bgp_memory,
9982 show_bgp_memory_cmd,
9983 "show [ip] bgp memory",
9984 SHOW_STR
9985 IP_STR
9986 BGP_STR
9987 "Global BGP memory statistics\n")
9988 {
9989 char memstrbuf[MTYPE_MEMSTR_LEN];
9990 unsigned long count;
9991
9992 /* RIB related usage stats */
9993 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9994 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9995 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9996 count * sizeof(struct bgp_dest)));
9997
9998 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9999 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10000 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10001 count * sizeof(struct bgp_path_info)));
10002 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10003 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10004 count,
10005 mtype_memstr(
10006 memstrbuf, sizeof(memstrbuf),
10007 count * sizeof(struct bgp_path_info_extra)));
10008
10009 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10010 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10011 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10012 count * sizeof(struct bgp_static)));
10013
10014 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10015 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10016 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10017 count * sizeof(struct bpacket)));
10018
10019 /* Adj-In/Out */
10020 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10021 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10022 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10023 count * sizeof(struct bgp_adj_in)));
10024 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10025 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10026 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10027 count * sizeof(struct bgp_adj_out)));
10028
10029 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10030 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10031 count,
10032 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10033 count * sizeof(struct bgp_nexthop_cache)));
10034
10035 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10036 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10037 count,
10038 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10039 count * sizeof(struct bgp_damp_info)));
10040
10041 /* Attributes */
10042 count = attr_count();
10043 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10044 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10045 count * sizeof(struct attr)));
10046
10047 if ((count = attr_unknown_count()))
10048 vty_out(vty, "%ld unknown attributes\n", count);
10049
10050 /* AS_PATH attributes */
10051 count = aspath_count();
10052 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10053 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10054 count * sizeof(struct aspath)));
10055
10056 count = mtype_stats_alloc(MTYPE_AS_SEG);
10057 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10058 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10059 count * sizeof(struct assegment)));
10060
10061 /* Other attributes */
10062 if ((count = community_count()))
10063 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10064 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10065 count * sizeof(struct community)));
10066 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10067 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10068 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10069 count * sizeof(struct ecommunity)));
10070 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10071 vty_out(vty,
10072 "%ld BGP large-community entries, using %s of memory\n",
10073 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10074 count * sizeof(struct lcommunity)));
10075
10076 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10077 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10078 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10079 count * sizeof(struct cluster_list)));
10080
10081 /* Peer related usage */
10082 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10083 vty_out(vty, "%ld peers, using %s of memory\n", count,
10084 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10085 count * sizeof(struct peer)));
10086
10087 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10088 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10089 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10090 count * sizeof(struct peer_group)));
10091
10092 /* Other */
10093 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10094 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10095 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10096 count * sizeof(regex_t)));
10097 return CMD_SUCCESS;
10098 }
10099
10100 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10101 {
10102 json_object *bestpath = json_object_new_object();
10103
10104 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10105 json_object_string_add(bestpath, "asPath", "ignore");
10106
10107 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10108 json_object_string_add(bestpath, "asPath", "confed");
10109
10110 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10111 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10112 json_object_string_add(bestpath, "multiPathRelax",
10113 "as-set");
10114 else
10115 json_object_string_add(bestpath, "multiPathRelax",
10116 "true");
10117 } else
10118 json_object_string_add(bestpath, "multiPathRelax", "false");
10119
10120 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10121 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10122
10123 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10124 json_object_string_add(bestpath, "compareRouterId", "true");
10125 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10126 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10127 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10128 json_object_string_add(bestpath, "med", "confed");
10129 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10130 json_object_string_add(bestpath, "med",
10131 "missing-as-worst");
10132 else
10133 json_object_string_add(bestpath, "med", "true");
10134 }
10135
10136 json_object_object_add(json, "bestPath", bestpath);
10137 }
10138
10139 /* Print the error code/subcode for why the peer is down */
10140 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10141 json_object *json_peer, bool use_json)
10142 {
10143 const char *code_str;
10144 const char *subcode_str;
10145
10146 if (use_json) {
10147 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10148 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10149 char errorcodesubcode_hexstr[5];
10150 char errorcodesubcode_str[256];
10151
10152 code_str = bgp_notify_code_str(peer->notify.code);
10153 subcode_str = bgp_notify_subcode_str(
10154 peer->notify.code,
10155 peer->notify.subcode);
10156
10157 snprintf(errorcodesubcode_hexstr,
10158 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10159 peer->notify.code, peer->notify.subcode);
10160 json_object_string_add(json_peer,
10161 "lastErrorCodeSubcode",
10162 errorcodesubcode_hexstr);
10163 snprintf(errorcodesubcode_str, 255, "%s%s",
10164 code_str, subcode_str);
10165 json_object_string_add(json_peer,
10166 "lastNotificationReason",
10167 errorcodesubcode_str);
10168 json_object_boolean_add(json_peer,
10169 "lastNotificationHardReset",
10170 peer->notify.hard_reset);
10171 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10172 && peer->notify.code == BGP_NOTIFY_CEASE
10173 && (peer->notify.subcode
10174 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10175 || peer->notify.subcode
10176 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10177 && peer->notify.length) {
10178 char msgbuf[1024];
10179 const char *msg_str;
10180
10181 msg_str = bgp_notify_admin_message(
10182 msgbuf, sizeof(msgbuf),
10183 (uint8_t *)peer->notify.data,
10184 peer->notify.length);
10185 if (msg_str)
10186 json_object_string_add(
10187 json_peer,
10188 "lastShutdownDescription",
10189 msg_str);
10190 }
10191
10192 }
10193 json_object_string_add(json_peer, "lastResetDueTo",
10194 peer_down_str[(int)peer->last_reset]);
10195 json_object_int_add(json_peer, "lastResetCode",
10196 peer->last_reset);
10197 } else {
10198 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10199 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10200 code_str = bgp_notify_code_str(peer->notify.code);
10201 subcode_str =
10202 bgp_notify_subcode_str(peer->notify.code,
10203 peer->notify.subcode);
10204 vty_out(vty, " Notification %s (%s%s%s)\n",
10205 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10206 ? "sent"
10207 : "received",
10208 code_str, subcode_str,
10209 peer->notify.hard_reset
10210 ? bgp_notify_subcode_str(
10211 BGP_NOTIFY_CEASE,
10212 BGP_NOTIFY_CEASE_HARD_RESET)
10213 : "");
10214 } else {
10215 vty_out(vty, " %s\n",
10216 peer_down_str[(int)peer->last_reset]);
10217 }
10218 }
10219 }
10220
10221 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10222 safi_t safi)
10223 {
10224 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10225 }
10226
10227 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10228 struct peer *peer, json_object *json_peer,
10229 int max_neighbor_width, bool use_json)
10230 {
10231 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10232 int len;
10233
10234 if (use_json) {
10235 if (peer_dynamic_neighbor(peer))
10236 json_object_boolean_true_add(json_peer,
10237 "dynamicPeer");
10238 if (peer->hostname)
10239 json_object_string_add(json_peer, "hostname",
10240 peer->hostname);
10241
10242 if (peer->domainname)
10243 json_object_string_add(json_peer, "domainname",
10244 peer->domainname);
10245 json_object_int_add(json_peer, "connectionsEstablished",
10246 peer->established);
10247 json_object_int_add(json_peer, "connectionsDropped",
10248 peer->dropped);
10249 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10250 use_json, json_peer);
10251 if (peer_established(peer))
10252 json_object_string_add(json_peer, "lastResetDueTo",
10253 "AFI/SAFI Not Negotiated");
10254 else
10255 bgp_show_peer_reset(NULL, peer, json_peer, true);
10256 } else {
10257 dn_flag[1] = '\0';
10258 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10259 if (peer->hostname
10260 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10261 len = vty_out(vty, "%s%s(%s)", dn_flag,
10262 peer->hostname, peer->host);
10263 else
10264 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10265
10266 /* pad the neighbor column with spaces */
10267 if (len < max_neighbor_width)
10268 vty_out(vty, "%*s", max_neighbor_width - len,
10269 " ");
10270 vty_out(vty, "%7d %7d %9s", peer->established,
10271 peer->dropped,
10272 peer_uptime(peer->uptime, timebuf,
10273 BGP_UPTIME_LEN, 0, NULL));
10274 if (peer_established(peer))
10275 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10276 else
10277 bgp_show_peer_reset(vty, peer, NULL,
10278 false);
10279 }
10280 }
10281
10282 /* Strip peer's description to the given size. */
10283 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10284 {
10285 static char stripped[BUFSIZ];
10286 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10287
10288 strlcpy(stripped, desc, len + 1);
10289
10290 return stripped;
10291 }
10292
10293 /* Determine whether var peer should be filtered out of the summary. */
10294 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10295 struct peer *fpeer, int as_type,
10296 as_t as)
10297 {
10298
10299 /* filter neighbor XXXX */
10300 if (fpeer && fpeer != peer)
10301 return true;
10302
10303 /* filter remote-as (internal|external) */
10304 if (as_type != AS_UNSPECIFIED) {
10305 if (peer->as_type == AS_SPECIFIED) {
10306 if (as_type == AS_INTERNAL) {
10307 if (peer->as != peer->local_as)
10308 return true;
10309 } else if (peer->as == peer->local_as)
10310 return true;
10311 } else if (as_type != peer->as_type)
10312 return true;
10313 } else if (as && as != peer->as) /* filter remote-as XXX */
10314 return true;
10315
10316 return false;
10317 }
10318
10319 /* Show BGP peer's summary information.
10320 *
10321 * Peer's description is stripped according to if `wide` option is given
10322 * or not.
10323 *
10324 * When adding new columns to `show bgp summary` output, please make
10325 * sure `Desc` is the lastest column to show because it can contain
10326 * whitespaces and the whole output will be tricky.
10327 */
10328 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10329 struct peer *fpeer, int as_type, as_t as,
10330 uint16_t show_flags)
10331 {
10332 struct peer *peer;
10333 struct listnode *node, *nnode;
10334 unsigned int count = 0, dn_count = 0;
10335 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10336 char neighbor_buf[VTY_BUFSIZ];
10337 int neighbor_col_default_width = 16;
10338 int len, failed_count = 0;
10339 unsigned int filtered_count = 0;
10340 int max_neighbor_width = 0;
10341 int pfx_rcd_safi;
10342 json_object *json = NULL;
10343 json_object *json_peer = NULL;
10344 json_object *json_peers = NULL;
10345 struct peer_af *paf;
10346 struct bgp_filter *filter;
10347 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10348 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10349 bool show_established =
10350 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10351 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10352 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10353
10354 /* labeled-unicast routes are installed in the unicast table so in order
10355 * to
10356 * display the correct PfxRcd value we must look at SAFI_UNICAST
10357 */
10358
10359 if (safi == SAFI_LABELED_UNICAST)
10360 pfx_rcd_safi = SAFI_UNICAST;
10361 else
10362 pfx_rcd_safi = safi;
10363
10364 if (use_json) {
10365 json = json_object_new_object();
10366 json_peers = json_object_new_object();
10367 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10368 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10369 as_type, as)) {
10370 filtered_count++;
10371 count++;
10372 continue;
10373 }
10374
10375 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10376 continue;
10377
10378 if (peer->afc[afi][safi]) {
10379 /* See if we have at least a single failed peer */
10380 if (bgp_has_peer_failed(peer, afi, safi))
10381 failed_count++;
10382 count++;
10383 }
10384 if (peer_dynamic_neighbor(peer))
10385 dn_count++;
10386 }
10387
10388 } else {
10389 /* Loop over all neighbors that will be displayed to determine
10390 * how many
10391 * characters are needed for the Neighbor column
10392 */
10393 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10394 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10395 as_type, as)) {
10396 filtered_count++;
10397 count++;
10398 continue;
10399 }
10400
10401 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10402 continue;
10403
10404 if (peer->afc[afi][safi]) {
10405 memset(dn_flag, '\0', sizeof(dn_flag));
10406 if (peer_dynamic_neighbor(peer))
10407 dn_flag[0] = '*';
10408
10409 if (peer->hostname
10410 && CHECK_FLAG(bgp->flags,
10411 BGP_FLAG_SHOW_HOSTNAME))
10412 snprintf(neighbor_buf,
10413 sizeof(neighbor_buf),
10414 "%s%s(%s) ", dn_flag,
10415 peer->hostname, peer->host);
10416 else
10417 snprintf(neighbor_buf,
10418 sizeof(neighbor_buf), "%s%s ",
10419 dn_flag, peer->host);
10420
10421 len = strlen(neighbor_buf);
10422
10423 if (len > max_neighbor_width)
10424 max_neighbor_width = len;
10425
10426 /* See if we have at least a single failed peer */
10427 if (bgp_has_peer_failed(peer, afi, safi))
10428 failed_count++;
10429 count++;
10430 }
10431 }
10432
10433 /* Originally we displayed the Neighbor column as 16
10434 * characters wide so make that the default
10435 */
10436 if (max_neighbor_width < neighbor_col_default_width)
10437 max_neighbor_width = neighbor_col_default_width;
10438 }
10439
10440 if (show_failed && !failed_count) {
10441 if (use_json) {
10442 json_object_int_add(json, "failedPeersCount", 0);
10443 json_object_int_add(json, "dynamicPeers", dn_count);
10444 json_object_int_add(json, "totalPeers", count);
10445
10446 vty_json(vty, json);
10447 } else {
10448 vty_out(vty, "%% No failed BGP neighbors found\n");
10449 }
10450 return CMD_SUCCESS;
10451 }
10452
10453 count = 0; /* Reset the value as its used again */
10454 filtered_count = 0;
10455 dn_count = 0;
10456 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10457 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10458 continue;
10459
10460 if (!peer->afc[afi][safi])
10461 continue;
10462
10463 if (!count) {
10464 unsigned long ents;
10465 char memstrbuf[MTYPE_MEMSTR_LEN];
10466 int64_t vrf_id_ui;
10467
10468 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10469 ? -1
10470 : (int64_t)bgp->vrf_id;
10471
10472 /* Usage summary and header */
10473 if (use_json) {
10474 json_object_string_addf(json, "routerId",
10475 "%pI4",
10476 &bgp->router_id);
10477 json_object_int_add(json, "as", bgp->as);
10478 json_object_int_add(json, "vrfId", vrf_id_ui);
10479 json_object_string_add(
10480 json, "vrfName",
10481 (bgp->inst_type
10482 == BGP_INSTANCE_TYPE_DEFAULT)
10483 ? VRF_DEFAULT_NAME
10484 : bgp->name);
10485 } else {
10486 vty_out(vty,
10487 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10488 &bgp->router_id, bgp->as,
10489 bgp->vrf_id == VRF_UNKNOWN
10490 ? -1
10491 : (int)bgp->vrf_id);
10492 vty_out(vty, "\n");
10493 }
10494
10495 if (bgp_update_delay_configured(bgp)) {
10496 if (use_json) {
10497 json_object_int_add(
10498 json, "updateDelayLimit",
10499 bgp->v_update_delay);
10500
10501 if (bgp->v_update_delay
10502 != bgp->v_establish_wait)
10503 json_object_int_add(
10504 json,
10505 "updateDelayEstablishWait",
10506 bgp->v_establish_wait);
10507
10508 if (bgp_update_delay_active(bgp)) {
10509 json_object_string_add(
10510 json,
10511 "updateDelayFirstNeighbor",
10512 bgp->update_delay_begin_time);
10513 json_object_boolean_true_add(
10514 json,
10515 "updateDelayInProgress");
10516 } else {
10517 if (bgp->update_delay_over) {
10518 json_object_string_add(
10519 json,
10520 "updateDelayFirstNeighbor",
10521 bgp->update_delay_begin_time);
10522 json_object_string_add(
10523 json,
10524 "updateDelayBestpathResumed",
10525 bgp->update_delay_end_time);
10526 json_object_string_add(
10527 json,
10528 "updateDelayZebraUpdateResume",
10529 bgp->update_delay_zebra_resume_time);
10530 json_object_string_add(
10531 json,
10532 "updateDelayPeerUpdateResume",
10533 bgp->update_delay_peers_resume_time);
10534 }
10535 }
10536 } else {
10537 vty_out(vty,
10538 "Read-only mode update-delay limit: %d seconds\n",
10539 bgp->v_update_delay);
10540 if (bgp->v_update_delay
10541 != bgp->v_establish_wait)
10542 vty_out(vty,
10543 " Establish wait: %d seconds\n",
10544 bgp->v_establish_wait);
10545
10546 if (bgp_update_delay_active(bgp)) {
10547 vty_out(vty,
10548 " First neighbor established: %s\n",
10549 bgp->update_delay_begin_time);
10550 vty_out(vty,
10551 " Delay in progress\n");
10552 } else {
10553 if (bgp->update_delay_over) {
10554 vty_out(vty,
10555 " First neighbor established: %s\n",
10556 bgp->update_delay_begin_time);
10557 vty_out(vty,
10558 " Best-paths resumed: %s\n",
10559 bgp->update_delay_end_time);
10560 vty_out(vty,
10561 " zebra update resumed: %s\n",
10562 bgp->update_delay_zebra_resume_time);
10563 vty_out(vty,
10564 " peers update resumed: %s\n",
10565 bgp->update_delay_peers_resume_time);
10566 }
10567 }
10568 }
10569 }
10570
10571 if (use_json) {
10572 if (bgp_maxmed_onstartup_configured(bgp)
10573 && bgp->maxmed_active)
10574 json_object_boolean_true_add(
10575 json, "maxMedOnStartup");
10576 if (bgp->v_maxmed_admin)
10577 json_object_boolean_true_add(
10578 json, "maxMedAdministrative");
10579
10580 json_object_int_add(
10581 json, "tableVersion",
10582 bgp_table_version(bgp->rib[afi][safi]));
10583
10584 ents = bgp_table_count(bgp->rib[afi][safi]);
10585 json_object_int_add(json, "ribCount", ents);
10586 json_object_int_add(
10587 json, "ribMemory",
10588 ents * sizeof(struct bgp_dest));
10589
10590 ents = bgp->af_peer_count[afi][safi];
10591 json_object_int_add(json, "peerCount", ents);
10592 json_object_int_add(json, "peerMemory",
10593 ents * sizeof(struct peer));
10594
10595 if ((ents = listcount(bgp->group))) {
10596 json_object_int_add(
10597 json, "peerGroupCount", ents);
10598 json_object_int_add(
10599 json, "peerGroupMemory",
10600 ents * sizeof(struct
10601 peer_group));
10602 }
10603
10604 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10605 BGP_CONFIG_DAMPENING))
10606 json_object_boolean_true_add(
10607 json, "dampeningEnabled");
10608 } else {
10609 if (!show_terse) {
10610 if (bgp_maxmed_onstartup_configured(bgp)
10611 && bgp->maxmed_active)
10612 vty_out(vty,
10613 "Max-med on-startup active\n");
10614 if (bgp->v_maxmed_admin)
10615 vty_out(vty,
10616 "Max-med administrative active\n");
10617
10618 vty_out(vty,
10619 "BGP table version %" PRIu64
10620 "\n",
10621 bgp_table_version(
10622 bgp->rib[afi][safi]));
10623
10624 ents = bgp_table_count(
10625 bgp->rib[afi][safi]);
10626 vty_out(vty,
10627 "RIB entries %ld, using %s of memory\n",
10628 ents,
10629 mtype_memstr(
10630 memstrbuf,
10631 sizeof(memstrbuf),
10632 ents
10633 * sizeof(
10634 struct
10635 bgp_dest)));
10636
10637 /* Peer related usage */
10638 ents = bgp->af_peer_count[afi][safi];
10639 vty_out(vty,
10640 "Peers %ld, using %s of memory\n",
10641 ents,
10642 mtype_memstr(
10643 memstrbuf,
10644 sizeof(memstrbuf),
10645 ents
10646 * sizeof(
10647 struct
10648 peer)));
10649
10650 if ((ents = listcount(bgp->group)))
10651 vty_out(vty,
10652 "Peer groups %ld, using %s of memory\n",
10653 ents,
10654 mtype_memstr(
10655 memstrbuf,
10656 sizeof(memstrbuf),
10657 ents
10658 * sizeof(
10659 struct
10660 peer_group)));
10661
10662 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10663 BGP_CONFIG_DAMPENING))
10664 vty_out(vty,
10665 "Dampening enabled.\n");
10666 }
10667 if (show_failed) {
10668 vty_out(vty, "\n");
10669
10670 /* Subtract 8 here because 'Neighbor' is
10671 * 8 characters */
10672 vty_out(vty, "Neighbor");
10673 vty_out(vty, "%*s",
10674 max_neighbor_width - 8, " ");
10675 vty_out(vty,
10676 BGP_SHOW_SUMMARY_HEADER_FAILED);
10677 }
10678 }
10679 }
10680
10681 paf = peer_af_find(peer, afi, safi);
10682 filter = &peer->filter[afi][safi];
10683
10684 count++;
10685 /* Works for both failed & successful cases */
10686 if (peer_dynamic_neighbor(peer))
10687 dn_count++;
10688
10689 if (use_json) {
10690 json_peer = NULL;
10691 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10692 as_type, as)) {
10693 filtered_count++;
10694 continue;
10695 }
10696 if (show_failed &&
10697 bgp_has_peer_failed(peer, afi, safi)) {
10698 json_peer = json_object_new_object();
10699 bgp_show_failed_summary(vty, bgp, peer,
10700 json_peer, 0, use_json);
10701 } else if (!show_failed) {
10702 if (show_established
10703 && bgp_has_peer_failed(peer, afi, safi)) {
10704 filtered_count++;
10705 continue;
10706 }
10707
10708 json_peer = json_object_new_object();
10709 if (peer_dynamic_neighbor(peer)) {
10710 json_object_boolean_true_add(json_peer,
10711 "dynamicPeer");
10712 }
10713
10714 if (peer->hostname)
10715 json_object_string_add(json_peer, "hostname",
10716 peer->hostname);
10717
10718 if (peer->domainname)
10719 json_object_string_add(json_peer, "domainname",
10720 peer->domainname);
10721
10722 json_object_int_add(json_peer, "remoteAs", peer->as);
10723 json_object_int_add(
10724 json_peer, "localAs",
10725 peer->change_local_as
10726 ? peer->change_local_as
10727 : peer->local_as);
10728 json_object_int_add(json_peer, "version", 4);
10729 json_object_int_add(json_peer, "msgRcvd",
10730 PEER_TOTAL_RX(peer));
10731 json_object_int_add(json_peer, "msgSent",
10732 PEER_TOTAL_TX(peer));
10733
10734 atomic_size_t outq_count, inq_count;
10735 outq_count = atomic_load_explicit(
10736 &peer->obuf->count,
10737 memory_order_relaxed);
10738 inq_count = atomic_load_explicit(
10739 &peer->ibuf->count,
10740 memory_order_relaxed);
10741
10742 json_object_int_add(json_peer, "tableVersion",
10743 peer->version[afi][safi]);
10744 json_object_int_add(json_peer, "outq",
10745 outq_count);
10746 json_object_int_add(json_peer, "inq",
10747 inq_count);
10748 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10749 use_json, json_peer);
10750
10751 json_object_int_add(json_peer, "pfxRcd",
10752 peer->pcount[afi][pfx_rcd_safi]);
10753
10754 if (paf && PAF_SUBGRP(paf))
10755 json_object_int_add(
10756 json_peer, "pfxSnt",
10757 (PAF_SUBGRP(paf))->scount);
10758 else
10759 json_object_int_add(json_peer, "pfxSnt",
10760 0);
10761
10762 /* BGP FSM state */
10763 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10764 || CHECK_FLAG(peer->bgp->flags,
10765 BGP_FLAG_SHUTDOWN))
10766 json_object_string_add(json_peer,
10767 "state",
10768 "Idle (Admin)");
10769 else if (peer->afc_recv[afi][safi])
10770 json_object_string_add(
10771 json_peer, "state",
10772 lookup_msg(bgp_status_msg,
10773 peer->status, NULL));
10774 else if (CHECK_FLAG(
10775 peer->sflags,
10776 PEER_STATUS_PREFIX_OVERFLOW))
10777 json_object_string_add(json_peer,
10778 "state",
10779 "Idle (PfxCt)");
10780 else
10781 json_object_string_add(
10782 json_peer, "state",
10783 lookup_msg(bgp_status_msg,
10784 peer->status, NULL));
10785
10786 /* BGP peer state */
10787 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10788 || CHECK_FLAG(peer->bgp->flags,
10789 BGP_FLAG_SHUTDOWN))
10790 json_object_string_add(json_peer,
10791 "peerState",
10792 "Admin");
10793 else if (CHECK_FLAG(
10794 peer->sflags,
10795 PEER_STATUS_PREFIX_OVERFLOW))
10796 json_object_string_add(json_peer,
10797 "peerState",
10798 "PfxCt");
10799 else if (CHECK_FLAG(peer->flags,
10800 PEER_FLAG_PASSIVE))
10801 json_object_string_add(json_peer,
10802 "peerState",
10803 "Passive");
10804 else if (CHECK_FLAG(peer->sflags,
10805 PEER_STATUS_NSF_WAIT))
10806 json_object_string_add(json_peer,
10807 "peerState",
10808 "NSF passive");
10809 else if (CHECK_FLAG(
10810 peer->bgp->flags,
10811 BGP_FLAG_EBGP_REQUIRES_POLICY)
10812 && (!bgp_inbound_policy_exists(peer,
10813 filter)
10814 || !bgp_outbound_policy_exists(
10815 peer, filter)))
10816 json_object_string_add(json_peer,
10817 "peerState",
10818 "Policy");
10819 else
10820 json_object_string_add(
10821 json_peer, "peerState", "OK");
10822
10823 json_object_int_add(json_peer, "connectionsEstablished",
10824 peer->established);
10825 json_object_int_add(json_peer, "connectionsDropped",
10826 peer->dropped);
10827 if (peer->desc)
10828 json_object_string_add(
10829 json_peer, "desc", peer->desc);
10830 }
10831 /* Avoid creating empty peer dicts in JSON */
10832 if (json_peer == NULL)
10833 continue;
10834
10835 if (peer->conf_if)
10836 json_object_string_add(json_peer, "idType",
10837 "interface");
10838 else if (peer->su.sa.sa_family == AF_INET)
10839 json_object_string_add(json_peer, "idType",
10840 "ipv4");
10841 else if (peer->su.sa.sa_family == AF_INET6)
10842 json_object_string_add(json_peer, "idType",
10843 "ipv6");
10844 json_object_object_add(json_peers, peer->host,
10845 json_peer);
10846 } else {
10847 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10848 as_type, as)) {
10849 filtered_count++;
10850 continue;
10851 }
10852 if (show_failed &&
10853 bgp_has_peer_failed(peer, afi, safi)) {
10854 bgp_show_failed_summary(vty, bgp, peer, NULL,
10855 max_neighbor_width,
10856 use_json);
10857 } else if (!show_failed) {
10858 if (show_established
10859 && bgp_has_peer_failed(peer, afi, safi)) {
10860 filtered_count++;
10861 continue;
10862 }
10863
10864 if ((count - filtered_count) == 1) {
10865 /* display headline before the first
10866 * neighbor line */
10867 vty_out(vty, "\n");
10868
10869 /* Subtract 8 here because 'Neighbor' is
10870 * 8 characters */
10871 vty_out(vty, "Neighbor");
10872 vty_out(vty, "%*s",
10873 max_neighbor_width - 8, " ");
10874 vty_out(vty,
10875 show_wide
10876 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10877 : BGP_SHOW_SUMMARY_HEADER_ALL);
10878 }
10879
10880 memset(dn_flag, '\0', sizeof(dn_flag));
10881 if (peer_dynamic_neighbor(peer)) {
10882 dn_flag[0] = '*';
10883 }
10884
10885 if (peer->hostname
10886 && CHECK_FLAG(bgp->flags,
10887 BGP_FLAG_SHOW_HOSTNAME))
10888 len = vty_out(vty, "%s%s(%s)", dn_flag,
10889 peer->hostname,
10890 peer->host);
10891 else
10892 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10893
10894 /* pad the neighbor column with spaces */
10895 if (len < max_neighbor_width)
10896 vty_out(vty, "%*s", max_neighbor_width - len,
10897 " ");
10898
10899 atomic_size_t outq_count, inq_count;
10900 outq_count = atomic_load_explicit(
10901 &peer->obuf->count,
10902 memory_order_relaxed);
10903 inq_count = atomic_load_explicit(
10904 &peer->ibuf->count,
10905 memory_order_relaxed);
10906
10907 if (show_wide)
10908 vty_out(vty,
10909 "4 %10u %10u %9u %9u %8" PRIu64
10910 " %4zu %4zu %8s",
10911 peer->as,
10912 peer->change_local_as
10913 ? peer->change_local_as
10914 : peer->local_as,
10915 PEER_TOTAL_RX(peer),
10916 PEER_TOTAL_TX(peer),
10917 peer->version[afi][safi],
10918 inq_count, outq_count,
10919 peer_uptime(peer->uptime,
10920 timebuf,
10921 BGP_UPTIME_LEN, 0,
10922 NULL));
10923 else
10924 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10925 " %4zu %4zu %8s",
10926 peer->as, PEER_TOTAL_RX(peer),
10927 PEER_TOTAL_TX(peer),
10928 peer->version[afi][safi],
10929 inq_count, outq_count,
10930 peer_uptime(peer->uptime,
10931 timebuf,
10932 BGP_UPTIME_LEN, 0,
10933 NULL));
10934
10935 if (peer_established(peer)) {
10936 if (peer->afc_recv[afi][safi]) {
10937 if (CHECK_FLAG(
10938 bgp->flags,
10939 BGP_FLAG_EBGP_REQUIRES_POLICY)
10940 && !bgp_inbound_policy_exists(
10941 peer, filter))
10942 vty_out(vty, " %12s",
10943 "(Policy)");
10944 else
10945 vty_out(vty,
10946 " %12u",
10947 peer->pcount
10948 [afi]
10949 [pfx_rcd_safi]);
10950 } else {
10951 vty_out(vty, " NoNeg");
10952 }
10953
10954 if (paf && PAF_SUBGRP(paf)) {
10955 if (CHECK_FLAG(
10956 bgp->flags,
10957 BGP_FLAG_EBGP_REQUIRES_POLICY)
10958 && !bgp_outbound_policy_exists(
10959 peer, filter))
10960 vty_out(vty, " %8s",
10961 "(Policy)");
10962 else
10963 vty_out(vty,
10964 " %8u",
10965 (PAF_SUBGRP(
10966 paf))
10967 ->scount);
10968 } else {
10969 vty_out(vty, " NoNeg");
10970 }
10971 } else {
10972 if (CHECK_FLAG(peer->flags,
10973 PEER_FLAG_SHUTDOWN)
10974 || CHECK_FLAG(peer->bgp->flags,
10975 BGP_FLAG_SHUTDOWN))
10976 vty_out(vty, " Idle (Admin)");
10977 else if (CHECK_FLAG(
10978 peer->sflags,
10979 PEER_STATUS_PREFIX_OVERFLOW))
10980 vty_out(vty, " Idle (PfxCt)");
10981 else
10982 vty_out(vty, " %12s",
10983 lookup_msg(bgp_status_msg,
10984 peer->status, NULL));
10985
10986 vty_out(vty, " %8u", 0);
10987 }
10988 /* Make sure `Desc` column is the lastest in
10989 * the output.
10990 */
10991 if (peer->desc)
10992 vty_out(vty, " %s",
10993 bgp_peer_description_stripped(
10994 peer->desc,
10995 show_wide ? 64 : 20));
10996 else
10997 vty_out(vty, " N/A");
10998 vty_out(vty, "\n");
10999 }
11000
11001 }
11002 }
11003
11004 if (use_json) {
11005 json_object_object_add(json, "peers", json_peers);
11006 json_object_int_add(json, "failedPeers", failed_count);
11007 json_object_int_add(json, "displayedPeers",
11008 count - filtered_count);
11009 json_object_int_add(json, "totalPeers", count);
11010 json_object_int_add(json, "dynamicPeers", dn_count);
11011
11012 if (!show_failed)
11013 bgp_show_bestpath_json(bgp, json);
11014
11015 vty_json(vty, json);
11016 } else {
11017 if (count) {
11018 if (filtered_count == count)
11019 vty_out(vty, "\n%% No matching neighbor\n");
11020 else {
11021 if (show_failed)
11022 vty_out(vty, "\nDisplayed neighbors %d",
11023 failed_count);
11024 else if (as_type != AS_UNSPECIFIED || as
11025 || fpeer || show_established)
11026 vty_out(vty, "\nDisplayed neighbors %d",
11027 count - filtered_count);
11028
11029 vty_out(vty, "\nTotal number of neighbors %d\n",
11030 count);
11031 }
11032 } else {
11033 vty_out(vty, "No %s neighbor is configured\n",
11034 get_afi_safi_str(afi, safi, false));
11035 }
11036
11037 if (dn_count) {
11038 vty_out(vty, "* - dynamic neighbor\n");
11039 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11040 dn_count, bgp->dynamic_neighbors_limit);
11041 }
11042 }
11043
11044 return CMD_SUCCESS;
11045 }
11046
11047 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11048 int safi, struct peer *fpeer, int as_type,
11049 as_t as, uint16_t show_flags)
11050 {
11051 int is_first = 1;
11052 int afi_wildcard = (afi == AFI_MAX);
11053 int safi_wildcard = (safi == SAFI_MAX);
11054 int is_wildcard = (afi_wildcard || safi_wildcard);
11055 bool nbr_output = false;
11056 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11057
11058 if (use_json && is_wildcard)
11059 vty_out(vty, "{\n");
11060 if (afi_wildcard)
11061 afi = 1; /* AFI_IP */
11062 while (afi < AFI_MAX) {
11063 if (safi_wildcard)
11064 safi = 1; /* SAFI_UNICAST */
11065 while (safi < SAFI_MAX) {
11066 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11067 nbr_output = true;
11068
11069 if (is_wildcard) {
11070 /*
11071 * So limit output to those afi/safi
11072 * pairs that
11073 * actualy have something interesting in
11074 * them
11075 */
11076 if (use_json) {
11077 if (!is_first)
11078 vty_out(vty, ",\n");
11079 else
11080 is_first = 0;
11081
11082 vty_out(vty, "\"%s\":",
11083 get_afi_safi_str(afi,
11084 safi,
11085 true));
11086 } else {
11087 vty_out(vty,
11088 "\n%s Summary (%s):\n",
11089 get_afi_safi_str(afi,
11090 safi,
11091 false),
11092 bgp->name_pretty);
11093 }
11094 }
11095 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11096 as_type, as, show_flags);
11097 }
11098 safi++;
11099 if (!safi_wildcard)
11100 safi = SAFI_MAX;
11101 }
11102 afi++;
11103 if (!afi_wildcard)
11104 afi = AFI_MAX;
11105 }
11106
11107 if (use_json && is_wildcard)
11108 vty_out(vty, "}\n");
11109 else if (!nbr_output) {
11110 if (use_json)
11111 vty_out(vty, "{}\n");
11112 else
11113 vty_out(vty, "%% No BGP neighbors found in %s\n",
11114 bgp->name_pretty);
11115 }
11116 }
11117
11118 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11119 safi_t safi,
11120 const char *neighbor,
11121 int as_type, as_t as,
11122 uint16_t show_flags)
11123 {
11124 struct listnode *node, *nnode;
11125 struct bgp *bgp;
11126 struct peer *fpeer = NULL;
11127 int is_first = 1;
11128 bool nbr_output = false;
11129 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11130
11131 if (use_json)
11132 vty_out(vty, "{\n");
11133
11134 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11135 nbr_output = true;
11136 if (use_json) {
11137 if (!is_first)
11138 vty_out(vty, ",\n");
11139 else
11140 is_first = 0;
11141
11142 vty_out(vty, "\"%s\":",
11143 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11144 ? VRF_DEFAULT_NAME
11145 : bgp->name);
11146 }
11147 if (neighbor) {
11148 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11149 use_json);
11150 if (!fpeer)
11151 continue;
11152 }
11153 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11154 as, show_flags);
11155 }
11156
11157 if (use_json)
11158 vty_out(vty, "}\n");
11159 else if (!nbr_output)
11160 vty_out(vty, "%% BGP instance not found\n");
11161 }
11162
11163 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11164 safi_t safi, const char *neighbor, int as_type,
11165 as_t as, uint16_t show_flags)
11166 {
11167 struct bgp *bgp;
11168 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11169 struct peer *fpeer = NULL;
11170
11171 if (name) {
11172 if (strmatch(name, "all")) {
11173 bgp_show_all_instances_summary_vty(vty, afi, safi,
11174 neighbor, as_type,
11175 as, show_flags);
11176 return CMD_SUCCESS;
11177 } else {
11178 bgp = bgp_lookup_by_name(name);
11179
11180 if (!bgp) {
11181 if (use_json)
11182 vty_out(vty, "{}\n");
11183 else
11184 vty_out(vty,
11185 "%% BGP instance not found\n");
11186 return CMD_WARNING;
11187 }
11188
11189 if (neighbor) {
11190 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11191 use_json);
11192 if (!fpeer)
11193 return CMD_WARNING;
11194 }
11195 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11196 as_type, as, show_flags);
11197 return CMD_SUCCESS;
11198 }
11199 }
11200
11201 bgp = bgp_get_default();
11202
11203 if (bgp) {
11204 if (neighbor) {
11205 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11206 use_json);
11207 if (!fpeer)
11208 return CMD_WARNING;
11209 }
11210 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11211 as, show_flags);
11212 } else {
11213 if (use_json)
11214 vty_out(vty, "{}\n");
11215 else
11216 vty_out(vty, "%% BGP instance not found\n");
11217 return CMD_WARNING;
11218 }
11219
11220 return CMD_SUCCESS;
11221 }
11222
11223 /* `show [ip] bgp summary' commands. */
11224 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11225 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11226 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11227 "]] [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]",
11228 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11229 BGP_SAFI_WITH_LABEL_HELP_STR
11230 "Display the entries for all address families\n"
11231 "Summary of BGP neighbor status\n"
11232 "Show only sessions in Established state\n"
11233 "Show only sessions not in Established state\n"
11234 "Show only the specified neighbor session\n"
11235 "Neighbor to display information about\n"
11236 "Neighbor to display information about\n"
11237 "Neighbor on BGP configured interface\n"
11238 "Show only the specified remote AS sessions\n"
11239 "AS number\n"
11240 "Internal (iBGP) AS sessions\n"
11241 "External (eBGP) AS sessions\n"
11242 "Shorten the information on BGP instances\n"
11243 "Increase table width for longer output\n" JSON_STR)
11244 {
11245 char *vrf = NULL;
11246 afi_t afi = AFI_MAX;
11247 safi_t safi = SAFI_MAX;
11248 as_t as = 0; /* 0 means AS filter not set */
11249 int as_type = AS_UNSPECIFIED;
11250 uint16_t show_flags = 0;
11251
11252 int idx = 0;
11253
11254 /* show [ip] bgp */
11255 if (!all && argv_find(argv, argc, "ip", &idx))
11256 afi = AFI_IP;
11257 /* [<vrf> VIEWVRFNAME] */
11258 if (argv_find(argv, argc, "vrf", &idx)) {
11259 vrf = argv[idx + 1]->arg;
11260 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11261 vrf = NULL;
11262 } else if (argv_find(argv, argc, "view", &idx))
11263 /* [<view> VIEWVRFNAME] */
11264 vrf = argv[idx + 1]->arg;
11265 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11266 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11267 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11268 }
11269
11270 if (argv_find(argv, argc, "failed", &idx))
11271 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11272
11273 if (argv_find(argv, argc, "established", &idx))
11274 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11275
11276 if (argv_find(argv, argc, "remote-as", &idx)) {
11277 if (argv[idx + 1]->arg[0] == 'i')
11278 as_type = AS_INTERNAL;
11279 else if (argv[idx + 1]->arg[0] == 'e')
11280 as_type = AS_EXTERNAL;
11281 else
11282 as = (as_t)atoi(argv[idx + 1]->arg);
11283 }
11284
11285 if (argv_find(argv, argc, "terse", &idx))
11286 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11287
11288 if (argv_find(argv, argc, "wide", &idx))
11289 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11290
11291 if (argv_find(argv, argc, "json", &idx))
11292 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11293
11294 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11295 show_flags);
11296 }
11297
11298 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11299 {
11300 if (for_json)
11301 return get_afi_safi_json_str(afi, safi);
11302 else
11303 return get_afi_safi_vty_str(afi, safi);
11304 }
11305
11306
11307 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11308 afi_t afi, safi_t safi,
11309 uint16_t adv_smcap, uint16_t adv_rmcap,
11310 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11311 bool use_json, json_object *json_pref)
11312 {
11313 /* Send-Mode */
11314 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11315 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11316 if (use_json) {
11317 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11318 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11319 json_object_string_add(json_pref, "sendMode",
11320 "advertisedAndReceived");
11321 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11322 json_object_string_add(json_pref, "sendMode",
11323 "advertised");
11324 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11325 json_object_string_add(json_pref, "sendMode",
11326 "received");
11327 } else {
11328 vty_out(vty, " Send-mode: ");
11329 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11330 vty_out(vty, "advertised");
11331 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11332 vty_out(vty, "%sreceived",
11333 CHECK_FLAG(p->af_cap[afi][safi],
11334 adv_smcap)
11335 ? ", "
11336 : "");
11337 vty_out(vty, "\n");
11338 }
11339 }
11340
11341 /* Receive-Mode */
11342 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11343 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11344 if (use_json) {
11345 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11346 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11347 json_object_string_add(json_pref, "recvMode",
11348 "advertisedAndReceived");
11349 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11350 json_object_string_add(json_pref, "recvMode",
11351 "advertised");
11352 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11353 json_object_string_add(json_pref, "recvMode",
11354 "received");
11355 } else {
11356 vty_out(vty, " Receive-mode: ");
11357 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11358 vty_out(vty, "advertised");
11359 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11360 vty_out(vty, "%sreceived",
11361 CHECK_FLAG(p->af_cap[afi][safi],
11362 adv_rmcap)
11363 ? ", "
11364 : "");
11365 vty_out(vty, "\n");
11366 }
11367 }
11368 }
11369
11370 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11371 struct peer *p,
11372 bool use_json,
11373 json_object *json)
11374 {
11375 bool rbit = false;
11376 bool nbit = false;
11377
11378 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11379 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11380 && (peer_established(p))) {
11381 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11382 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11383 }
11384
11385 if (use_json) {
11386 json_object_boolean_add(json, "rBit", rbit);
11387 json_object_boolean_add(json, "nBit", nbit);
11388 } else {
11389 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11390 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11391 }
11392 }
11393
11394 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11395 struct peer *peer,
11396 bool use_json,
11397 json_object *json)
11398 {
11399 const char *mode = "NotApplicable";
11400
11401 if (!use_json)
11402 vty_out(vty, "\n Remote GR Mode: ");
11403
11404 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11405 && (peer_established(peer))) {
11406
11407 if ((peer->nsf_af_count == 0)
11408 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11409
11410 mode = "Disable";
11411
11412 } else if (peer->nsf_af_count == 0
11413 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11414
11415 mode = "Helper";
11416
11417 } else if (peer->nsf_af_count != 0
11418 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11419
11420 mode = "Restart";
11421 }
11422 }
11423
11424 if (use_json) {
11425 json_object_string_add(json, "remoteGrMode", mode);
11426 } else
11427 vty_out(vty, mode, "\n");
11428 }
11429
11430 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11431 struct peer *p,
11432 bool use_json,
11433 json_object *json)
11434 {
11435 const char *mode = "Invalid";
11436
11437 if (!use_json)
11438 vty_out(vty, " Local GR Mode: ");
11439
11440 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11441 mode = "Helper";
11442 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11443 mode = "Restart";
11444 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11445 mode = "Disable";
11446 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11447 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11448 mode = "Helper*";
11449 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11450 mode = "Restart*";
11451 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11452 mode = "Disable*";
11453 else
11454 mode = "Invalid*";
11455 }
11456
11457 if (use_json) {
11458 json_object_string_add(json, "localGrMode", mode);
11459 } else {
11460 vty_out(vty, mode, "\n");
11461 }
11462 }
11463
11464 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11465 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11466 {
11467 afi_t afi;
11468 safi_t safi;
11469 json_object *json_afi_safi = NULL;
11470 json_object *json_timer = NULL;
11471 json_object *json_endofrib_status = NULL;
11472 bool eor_flag = false;
11473
11474 FOREACH_AFI_SAFI_NSF (afi, safi) {
11475 if (!peer->afc[afi][safi])
11476 continue;
11477
11478 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11479 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11480 continue;
11481
11482 if (use_json) {
11483 json_afi_safi = json_object_new_object();
11484 json_endofrib_status = json_object_new_object();
11485 json_timer = json_object_new_object();
11486 }
11487
11488 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11489 eor_flag = true;
11490 else
11491 eor_flag = false;
11492
11493 if (!use_json) {
11494 vty_out(vty, " %s:\n",
11495 get_afi_safi_str(afi, safi, false));
11496
11497 vty_out(vty, " F bit: ");
11498 }
11499
11500 if (peer->nsf[afi][safi] &&
11501 CHECK_FLAG(peer->af_cap[afi][safi],
11502 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11503
11504 if (use_json) {
11505 json_object_boolean_true_add(json_afi_safi,
11506 "fBit");
11507 } else
11508 vty_out(vty, "True\n");
11509 } else {
11510 if (use_json)
11511 json_object_boolean_false_add(json_afi_safi,
11512 "fBit");
11513 else
11514 vty_out(vty, "False\n");
11515 }
11516
11517 if (!use_json)
11518 vty_out(vty, " End-of-RIB sent: ");
11519
11520 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11521 PEER_STATUS_EOR_SEND)) {
11522 if (use_json) {
11523 json_object_boolean_true_add(
11524 json_endofrib_status, "endOfRibSend");
11525
11526 PRINT_EOR_JSON(eor_flag);
11527 } else {
11528 vty_out(vty, "Yes\n");
11529 vty_out(vty,
11530 " End-of-RIB sent after update: ");
11531
11532 PRINT_EOR(eor_flag);
11533 }
11534 } else {
11535 if (use_json) {
11536 json_object_boolean_false_add(
11537 json_endofrib_status, "endOfRibSend");
11538 json_object_boolean_false_add(
11539 json_endofrib_status,
11540 "endOfRibSentAfterUpdate");
11541 } else {
11542 vty_out(vty, "No\n");
11543 vty_out(vty,
11544 " End-of-RIB sent after update: ");
11545 vty_out(vty, "No\n");
11546 }
11547 }
11548
11549 if (!use_json)
11550 vty_out(vty, " End-of-RIB received: ");
11551
11552 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11553 PEER_STATUS_EOR_RECEIVED)) {
11554 if (use_json)
11555 json_object_boolean_true_add(
11556 json_endofrib_status, "endOfRibRecv");
11557 else
11558 vty_out(vty, "Yes\n");
11559 } else {
11560 if (use_json)
11561 json_object_boolean_false_add(
11562 json_endofrib_status, "endOfRibRecv");
11563 else
11564 vty_out(vty, "No\n");
11565 }
11566
11567 if (use_json) {
11568 json_object_int_add(json_timer, "stalePathTimer",
11569 peer->bgp->stalepath_time);
11570
11571 if (peer->t_gr_stale != NULL) {
11572 json_object_int_add(json_timer,
11573 "stalePathTimerRemaining",
11574 thread_timer_remain_second(
11575 peer->t_gr_stale));
11576 }
11577
11578 /* Display Configured Selection
11579 * Deferral only when when
11580 * Gr mode is enabled.
11581 */
11582 if (CHECK_FLAG(peer->flags,
11583 PEER_FLAG_GRACEFUL_RESTART)) {
11584 json_object_int_add(json_timer,
11585 "selectionDeferralTimer",
11586 peer->bgp->stalepath_time);
11587 }
11588
11589 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11590 NULL) {
11591
11592 json_object_int_add(
11593 json_timer,
11594 "selectionDeferralTimerRemaining",
11595 thread_timer_remain_second(
11596 peer->bgp->gr_info[afi][safi]
11597 .t_select_deferral));
11598 }
11599 } else {
11600 vty_out(vty, " Timers:\n");
11601 vty_out(vty,
11602 " Configured Stale Path Time(sec): %u\n",
11603 peer->bgp->stalepath_time);
11604
11605 if (peer->t_gr_stale != NULL)
11606 vty_out(vty,
11607 " Stale Path Remaining(sec): %ld\n",
11608 thread_timer_remain_second(
11609 peer->t_gr_stale));
11610 /* Display Configured Selection
11611 * Deferral only when when
11612 * Gr mode is enabled.
11613 */
11614 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11615 vty_out(vty,
11616 " Configured Selection Deferral Time(sec): %u\n",
11617 peer->bgp->select_defer_time);
11618
11619 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11620 NULL)
11621 vty_out(vty,
11622 " Selection Deferral Time Remaining(sec): %ld\n",
11623 thread_timer_remain_second(
11624 peer->bgp->gr_info[afi][safi]
11625 .t_select_deferral));
11626 }
11627 if (use_json) {
11628 json_object_object_add(json_afi_safi, "endOfRibStatus",
11629 json_endofrib_status);
11630 json_object_object_add(json_afi_safi, "timers",
11631 json_timer);
11632 json_object_object_add(
11633 json, get_afi_safi_str(afi, safi, true),
11634 json_afi_safi);
11635 }
11636 }
11637 }
11638
11639 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11640 struct peer *p,
11641 bool use_json,
11642 json_object *json)
11643 {
11644 if (use_json) {
11645 json_object *json_timer = NULL;
11646
11647 json_timer = json_object_new_object();
11648
11649 json_object_int_add(json_timer, "configuredRestartTimer",
11650 p->bgp->restart_time);
11651
11652 json_object_int_add(json_timer, "receivedRestartTimer",
11653 p->v_gr_restart);
11654
11655 if (p->t_gr_restart != NULL)
11656 json_object_int_add(
11657 json_timer, "restartTimerRemaining",
11658 thread_timer_remain_second(p->t_gr_restart));
11659
11660 json_object_object_add(json, "timers", json_timer);
11661 } else {
11662
11663 vty_out(vty, " Timers:\n");
11664 vty_out(vty, " Configured Restart Time(sec): %u\n",
11665 p->bgp->restart_time);
11666
11667 vty_out(vty, " Received Restart Time(sec): %u\n",
11668 p->v_gr_restart);
11669 if (p->t_gr_restart != NULL)
11670 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11671 thread_timer_remain_second(p->t_gr_restart));
11672 if (p->t_gr_restart != NULL) {
11673 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11674 thread_timer_remain_second(p->t_gr_restart));
11675 }
11676 }
11677 }
11678
11679 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11680 bool use_json, json_object *json)
11681 {
11682 char dn_flag[2] = {0};
11683 /* '*' + v6 address of neighbor */
11684 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11685
11686 if (!p->conf_if && peer_dynamic_neighbor(p))
11687 dn_flag[0] = '*';
11688
11689 if (p->conf_if) {
11690 if (use_json)
11691 json_object_string_addf(json, "neighborAddr", "%pSU",
11692 &p->su);
11693 else
11694 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11695 &p->su);
11696 } else {
11697 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11698 p->host);
11699
11700 if (use_json)
11701 json_object_string_add(json, "neighborAddr",
11702 neighborAddr);
11703 else
11704 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11705 }
11706
11707 /* more gr info in new format */
11708 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11709 }
11710
11711 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11712 safi_t safi, bool use_json,
11713 json_object *json_neigh)
11714 {
11715 struct bgp_filter *filter;
11716 struct peer_af *paf;
11717 char orf_pfx_name[BUFSIZ];
11718 int orf_pfx_count;
11719 json_object *json_af = NULL;
11720 json_object *json_prefA = NULL;
11721 json_object *json_prefB = NULL;
11722 json_object *json_addr = NULL;
11723 json_object *json_advmap = NULL;
11724
11725 if (use_json) {
11726 json_addr = json_object_new_object();
11727 json_af = json_object_new_object();
11728 filter = &p->filter[afi][safi];
11729
11730 if (peer_group_active(p))
11731 json_object_string_add(json_addr, "peerGroupMember",
11732 p->group->name);
11733
11734 paf = peer_af_find(p, afi, safi);
11735 if (paf && PAF_SUBGRP(paf)) {
11736 json_object_int_add(json_addr, "updateGroupId",
11737 PAF_UPDGRP(paf)->id);
11738 json_object_int_add(json_addr, "subGroupId",
11739 PAF_SUBGRP(paf)->id);
11740 json_object_int_add(json_addr, "packetQueueLength",
11741 bpacket_queue_virtual_length(paf));
11742 }
11743
11744 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11745 || CHECK_FLAG(p->af_cap[afi][safi],
11746 PEER_CAP_ORF_PREFIX_SM_RCV)
11747 || CHECK_FLAG(p->af_cap[afi][safi],
11748 PEER_CAP_ORF_PREFIX_RM_ADV)
11749 || CHECK_FLAG(p->af_cap[afi][safi],
11750 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11751 json_object_int_add(json_af, "orfType",
11752 ORF_TYPE_PREFIX);
11753 json_prefA = json_object_new_object();
11754 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11755 PEER_CAP_ORF_PREFIX_SM_ADV,
11756 PEER_CAP_ORF_PREFIX_RM_ADV,
11757 PEER_CAP_ORF_PREFIX_SM_RCV,
11758 PEER_CAP_ORF_PREFIX_RM_RCV,
11759 use_json, json_prefA);
11760 json_object_object_add(json_af, "orfPrefixList",
11761 json_prefA);
11762 }
11763
11764 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11765 || CHECK_FLAG(p->af_cap[afi][safi],
11766 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11767 || CHECK_FLAG(p->af_cap[afi][safi],
11768 PEER_CAP_ORF_PREFIX_RM_ADV)
11769 || CHECK_FLAG(p->af_cap[afi][safi],
11770 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11771 json_object_int_add(json_af, "orfOldType",
11772 ORF_TYPE_PREFIX_OLD);
11773 json_prefB = json_object_new_object();
11774 bgp_show_peer_afi_orf_cap(
11775 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11776 PEER_CAP_ORF_PREFIX_RM_ADV,
11777 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11778 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11779 json_prefB);
11780 json_object_object_add(json_af, "orfOldPrefixList",
11781 json_prefB);
11782 }
11783
11784 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11785 || CHECK_FLAG(p->af_cap[afi][safi],
11786 PEER_CAP_ORF_PREFIX_SM_RCV)
11787 || CHECK_FLAG(p->af_cap[afi][safi],
11788 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11789 || CHECK_FLAG(p->af_cap[afi][safi],
11790 PEER_CAP_ORF_PREFIX_RM_ADV)
11791 || CHECK_FLAG(p->af_cap[afi][safi],
11792 PEER_CAP_ORF_PREFIX_RM_RCV)
11793 || CHECK_FLAG(p->af_cap[afi][safi],
11794 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11795 json_object_object_add(json_addr, "afDependentCap",
11796 json_af);
11797 else
11798 json_object_free(json_af);
11799
11800 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11801 p->host, afi, safi);
11802 orf_pfx_count = prefix_bgp_show_prefix_list(
11803 NULL, afi, orf_pfx_name, use_json);
11804
11805 if (CHECK_FLAG(p->af_sflags[afi][safi],
11806 PEER_STATUS_ORF_PREFIX_SEND)
11807 || orf_pfx_count) {
11808 if (CHECK_FLAG(p->af_sflags[afi][safi],
11809 PEER_STATUS_ORF_PREFIX_SEND))
11810 json_object_boolean_true_add(json_neigh,
11811 "orfSent");
11812 if (orf_pfx_count)
11813 json_object_int_add(json_addr, "orfRecvCounter",
11814 orf_pfx_count);
11815 }
11816 if (CHECK_FLAG(p->af_sflags[afi][safi],
11817 PEER_STATUS_ORF_WAIT_REFRESH))
11818 json_object_string_add(
11819 json_addr, "orfFirstUpdate",
11820 "deferredUntilORFOrRouteRefreshRecvd");
11821
11822 if (CHECK_FLAG(p->af_flags[afi][safi],
11823 PEER_FLAG_REFLECTOR_CLIENT))
11824 json_object_boolean_true_add(json_addr,
11825 "routeReflectorClient");
11826 if (CHECK_FLAG(p->af_flags[afi][safi],
11827 PEER_FLAG_RSERVER_CLIENT))
11828 json_object_boolean_true_add(json_addr,
11829 "routeServerClient");
11830 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11831 json_object_boolean_true_add(json_addr,
11832 "inboundSoftConfigPermit");
11833
11834 if (CHECK_FLAG(p->af_flags[afi][safi],
11835 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11836 json_object_boolean_true_add(
11837 json_addr,
11838 "privateAsNumsAllReplacedInUpdatesToNbr");
11839 else if (CHECK_FLAG(p->af_flags[afi][safi],
11840 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11841 json_object_boolean_true_add(
11842 json_addr,
11843 "privateAsNumsReplacedInUpdatesToNbr");
11844 else if (CHECK_FLAG(p->af_flags[afi][safi],
11845 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11846 json_object_boolean_true_add(
11847 json_addr,
11848 "privateAsNumsAllRemovedInUpdatesToNbr");
11849 else if (CHECK_FLAG(p->af_flags[afi][safi],
11850 PEER_FLAG_REMOVE_PRIVATE_AS))
11851 json_object_boolean_true_add(
11852 json_addr,
11853 "privateAsNumsRemovedInUpdatesToNbr");
11854
11855 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11856 json_object_boolean_true_add(
11857 json_addr,
11858 bgp_addpath_names(p->addpath_type[afi][safi])
11859 ->type_json_name);
11860
11861 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11862 json_object_string_add(json_addr,
11863 "overrideASNsInOutboundUpdates",
11864 "ifAspathEqualRemoteAs");
11865
11866 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11867 || CHECK_FLAG(p->af_flags[afi][safi],
11868 PEER_FLAG_FORCE_NEXTHOP_SELF))
11869 json_object_boolean_true_add(json_addr,
11870 "routerAlwaysNextHop");
11871 if (CHECK_FLAG(p->af_flags[afi][safi],
11872 PEER_FLAG_AS_PATH_UNCHANGED))
11873 json_object_boolean_true_add(
11874 json_addr, "unchangedAsPathPropogatedToNbr");
11875 if (CHECK_FLAG(p->af_flags[afi][safi],
11876 PEER_FLAG_NEXTHOP_UNCHANGED))
11877 json_object_boolean_true_add(
11878 json_addr, "unchangedNextHopPropogatedToNbr");
11879 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11880 json_object_boolean_true_add(
11881 json_addr, "unchangedMedPropogatedToNbr");
11882 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11883 || CHECK_FLAG(p->af_flags[afi][safi],
11884 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11885 if (CHECK_FLAG(p->af_flags[afi][safi],
11886 PEER_FLAG_SEND_COMMUNITY)
11887 && CHECK_FLAG(p->af_flags[afi][safi],
11888 PEER_FLAG_SEND_EXT_COMMUNITY))
11889 json_object_string_add(json_addr,
11890 "commAttriSentToNbr",
11891 "extendedAndStandard");
11892 else if (CHECK_FLAG(p->af_flags[afi][safi],
11893 PEER_FLAG_SEND_EXT_COMMUNITY))
11894 json_object_string_add(json_addr,
11895 "commAttriSentToNbr",
11896 "extended");
11897 else
11898 json_object_string_add(json_addr,
11899 "commAttriSentToNbr",
11900 "standard");
11901 }
11902 if (CHECK_FLAG(p->af_flags[afi][safi],
11903 PEER_FLAG_DEFAULT_ORIGINATE)) {
11904 if (p->default_rmap[afi][safi].name)
11905 json_object_string_add(
11906 json_addr, "defaultRouteMap",
11907 p->default_rmap[afi][safi].name);
11908
11909 if (paf && PAF_SUBGRP(paf)
11910 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11911 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11912 json_object_boolean_true_add(json_addr,
11913 "defaultSent");
11914 else
11915 json_object_boolean_true_add(json_addr,
11916 "defaultNotSent");
11917 }
11918
11919 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
11920 if (is_evpn_enabled())
11921 json_object_boolean_true_add(
11922 json_addr, "advertiseAllVnis");
11923 }
11924
11925 if (filter->plist[FILTER_IN].name
11926 || filter->dlist[FILTER_IN].name
11927 || filter->aslist[FILTER_IN].name
11928 || filter->map[RMAP_IN].name)
11929 json_object_boolean_true_add(json_addr,
11930 "inboundPathPolicyConfig");
11931 if (filter->plist[FILTER_OUT].name
11932 || filter->dlist[FILTER_OUT].name
11933 || filter->aslist[FILTER_OUT].name
11934 || filter->map[RMAP_OUT].name || filter->usmap.name)
11935 json_object_boolean_true_add(
11936 json_addr, "outboundPathPolicyConfig");
11937
11938 /* prefix-list */
11939 if (filter->plist[FILTER_IN].name)
11940 json_object_string_add(json_addr,
11941 "incomingUpdatePrefixFilterList",
11942 filter->plist[FILTER_IN].name);
11943 if (filter->plist[FILTER_OUT].name)
11944 json_object_string_add(json_addr,
11945 "outgoingUpdatePrefixFilterList",
11946 filter->plist[FILTER_OUT].name);
11947
11948 /* distribute-list */
11949 if (filter->dlist[FILTER_IN].name)
11950 json_object_string_add(
11951 json_addr, "incomingUpdateNetworkFilterList",
11952 filter->dlist[FILTER_IN].name);
11953 if (filter->dlist[FILTER_OUT].name)
11954 json_object_string_add(
11955 json_addr, "outgoingUpdateNetworkFilterList",
11956 filter->dlist[FILTER_OUT].name);
11957
11958 /* filter-list. */
11959 if (filter->aslist[FILTER_IN].name)
11960 json_object_string_add(json_addr,
11961 "incomingUpdateAsPathFilterList",
11962 filter->aslist[FILTER_IN].name);
11963 if (filter->aslist[FILTER_OUT].name)
11964 json_object_string_add(json_addr,
11965 "outgoingUpdateAsPathFilterList",
11966 filter->aslist[FILTER_OUT].name);
11967
11968 /* route-map. */
11969 if (filter->map[RMAP_IN].name)
11970 json_object_string_add(
11971 json_addr, "routeMapForIncomingAdvertisements",
11972 filter->map[RMAP_IN].name);
11973 if (filter->map[RMAP_OUT].name)
11974 json_object_string_add(
11975 json_addr, "routeMapForOutgoingAdvertisements",
11976 filter->map[RMAP_OUT].name);
11977
11978 /* ebgp-requires-policy (inbound) */
11979 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11980 && !bgp_inbound_policy_exists(p, filter))
11981 json_object_string_add(
11982 json_addr, "inboundEbgpRequiresPolicy",
11983 "Inbound updates discarded due to missing policy");
11984
11985 /* ebgp-requires-policy (outbound) */
11986 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
11987 && (!bgp_outbound_policy_exists(p, filter)))
11988 json_object_string_add(
11989 json_addr, "outboundEbgpRequiresPolicy",
11990 "Outbound updates discarded due to missing policy");
11991
11992 /* unsuppress-map */
11993 if (filter->usmap.name)
11994 json_object_string_add(json_addr,
11995 "selectiveUnsuppressRouteMap",
11996 filter->usmap.name);
11997
11998 /* advertise-map */
11999 if (filter->advmap.aname) {
12000 json_advmap = json_object_new_object();
12001 json_object_string_add(json_advmap, "condition",
12002 filter->advmap.condition
12003 ? "EXIST"
12004 : "NON_EXIST");
12005 json_object_string_add(json_advmap, "conditionMap",
12006 filter->advmap.cname);
12007 json_object_string_add(json_advmap, "advertiseMap",
12008 filter->advmap.aname);
12009 json_object_string_add(json_advmap, "advertiseStatus",
12010 filter->advmap.update_type
12011 == ADVERTISE
12012 ? "Advertise"
12013 : "Withdraw");
12014 json_object_object_add(json_addr, "advertiseMap",
12015 json_advmap);
12016 }
12017
12018 /* Receive prefix count */
12019 json_object_int_add(json_addr, "acceptedPrefixCounter",
12020 p->pcount[afi][safi]);
12021 if (paf && PAF_SUBGRP(paf))
12022 json_object_int_add(json_addr, "sentPrefixCounter",
12023 (PAF_SUBGRP(paf))->scount);
12024
12025 /* Maximum prefix */
12026 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12027 json_object_int_add(json_addr, "prefixOutAllowedMax",
12028 p->pmax_out[afi][safi]);
12029
12030 /* Maximum prefix */
12031 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12032 json_object_int_add(json_addr, "prefixAllowedMax",
12033 p->pmax[afi][safi]);
12034 if (CHECK_FLAG(p->af_flags[afi][safi],
12035 PEER_FLAG_MAX_PREFIX_WARNING))
12036 json_object_boolean_true_add(
12037 json_addr, "prefixAllowedMaxWarning");
12038 json_object_int_add(json_addr,
12039 "prefixAllowedWarningThresh",
12040 p->pmax_threshold[afi][safi]);
12041 if (p->pmax_restart[afi][safi])
12042 json_object_int_add(
12043 json_addr,
12044 "prefixAllowedRestartIntervalMsecs",
12045 p->pmax_restart[afi][safi] * 60000);
12046 }
12047 json_object_object_add(json_neigh,
12048 get_afi_safi_str(afi, safi, true),
12049 json_addr);
12050
12051 } else {
12052 filter = &p->filter[afi][safi];
12053
12054 vty_out(vty, " For address family: %s\n",
12055 get_afi_safi_str(afi, safi, false));
12056
12057 if (peer_group_active(p))
12058 vty_out(vty, " %s peer-group member\n",
12059 p->group->name);
12060
12061 paf = peer_af_find(p, afi, safi);
12062 if (paf && PAF_SUBGRP(paf)) {
12063 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12064 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12065 vty_out(vty, " Packet Queue length %d\n",
12066 bpacket_queue_virtual_length(paf));
12067 } else {
12068 vty_out(vty, " Not part of any update group\n");
12069 }
12070 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12071 || CHECK_FLAG(p->af_cap[afi][safi],
12072 PEER_CAP_ORF_PREFIX_SM_RCV)
12073 || CHECK_FLAG(p->af_cap[afi][safi],
12074 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12075 || CHECK_FLAG(p->af_cap[afi][safi],
12076 PEER_CAP_ORF_PREFIX_RM_ADV)
12077 || CHECK_FLAG(p->af_cap[afi][safi],
12078 PEER_CAP_ORF_PREFIX_RM_RCV)
12079 || CHECK_FLAG(p->af_cap[afi][safi],
12080 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12081 vty_out(vty, " AF-dependant capabilities:\n");
12082
12083 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12084 || CHECK_FLAG(p->af_cap[afi][safi],
12085 PEER_CAP_ORF_PREFIX_SM_RCV)
12086 || CHECK_FLAG(p->af_cap[afi][safi],
12087 PEER_CAP_ORF_PREFIX_RM_ADV)
12088 || CHECK_FLAG(p->af_cap[afi][safi],
12089 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12090 vty_out(vty,
12091 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12092 ORF_TYPE_PREFIX);
12093 bgp_show_peer_afi_orf_cap(
12094 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12095 PEER_CAP_ORF_PREFIX_RM_ADV,
12096 PEER_CAP_ORF_PREFIX_SM_RCV,
12097 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12098 }
12099 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12100 || CHECK_FLAG(p->af_cap[afi][safi],
12101 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12102 || CHECK_FLAG(p->af_cap[afi][safi],
12103 PEER_CAP_ORF_PREFIX_RM_ADV)
12104 || CHECK_FLAG(p->af_cap[afi][safi],
12105 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12106 vty_out(vty,
12107 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12108 ORF_TYPE_PREFIX_OLD);
12109 bgp_show_peer_afi_orf_cap(
12110 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12111 PEER_CAP_ORF_PREFIX_RM_ADV,
12112 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12113 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12114 }
12115
12116 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12117 p->host, afi, safi);
12118 orf_pfx_count = prefix_bgp_show_prefix_list(
12119 NULL, afi, orf_pfx_name, use_json);
12120
12121 if (CHECK_FLAG(p->af_sflags[afi][safi],
12122 PEER_STATUS_ORF_PREFIX_SEND)
12123 || orf_pfx_count) {
12124 vty_out(vty, " Outbound Route Filter (ORF):");
12125 if (CHECK_FLAG(p->af_sflags[afi][safi],
12126 PEER_STATUS_ORF_PREFIX_SEND))
12127 vty_out(vty, " sent;");
12128 if (orf_pfx_count)
12129 vty_out(vty, " received (%d entries)",
12130 orf_pfx_count);
12131 vty_out(vty, "\n");
12132 }
12133 if (CHECK_FLAG(p->af_sflags[afi][safi],
12134 PEER_STATUS_ORF_WAIT_REFRESH))
12135 vty_out(vty,
12136 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12137
12138 if (CHECK_FLAG(p->af_flags[afi][safi],
12139 PEER_FLAG_REFLECTOR_CLIENT))
12140 vty_out(vty, " Route-Reflector Client\n");
12141 if (CHECK_FLAG(p->af_flags[afi][safi],
12142 PEER_FLAG_RSERVER_CLIENT))
12143 vty_out(vty, " Route-Server Client\n");
12144 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12145 vty_out(vty,
12146 " Inbound soft reconfiguration allowed\n");
12147
12148 if (CHECK_FLAG(p->af_flags[afi][safi],
12149 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12150 vty_out(vty,
12151 " Private AS numbers (all) replaced in updates to this neighbor\n");
12152 else if (CHECK_FLAG(p->af_flags[afi][safi],
12153 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12154 vty_out(vty,
12155 " Private AS numbers replaced in updates to this neighbor\n");
12156 else if (CHECK_FLAG(p->af_flags[afi][safi],
12157 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12158 vty_out(vty,
12159 " Private AS numbers (all) removed in updates to this neighbor\n");
12160 else if (CHECK_FLAG(p->af_flags[afi][safi],
12161 PEER_FLAG_REMOVE_PRIVATE_AS))
12162 vty_out(vty,
12163 " Private AS numbers removed in updates to this neighbor\n");
12164
12165 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12166 vty_out(vty, " %s\n",
12167 bgp_addpath_names(p->addpath_type[afi][safi])
12168 ->human_description);
12169
12170 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12171 vty_out(vty,
12172 " Override ASNs in outbound updates if aspath equals remote-as\n");
12173
12174 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12175 || CHECK_FLAG(p->af_flags[afi][safi],
12176 PEER_FLAG_FORCE_NEXTHOP_SELF))
12177 vty_out(vty, " NEXT_HOP is always this router\n");
12178 if (CHECK_FLAG(p->af_flags[afi][safi],
12179 PEER_FLAG_AS_PATH_UNCHANGED))
12180 vty_out(vty,
12181 " AS_PATH is propagated unchanged to this neighbor\n");
12182 if (CHECK_FLAG(p->af_flags[afi][safi],
12183 PEER_FLAG_NEXTHOP_UNCHANGED))
12184 vty_out(vty,
12185 " NEXT_HOP is propagated unchanged to this neighbor\n");
12186 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12187 vty_out(vty,
12188 " MED is propagated unchanged to this neighbor\n");
12189 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12190 || CHECK_FLAG(p->af_flags[afi][safi],
12191 PEER_FLAG_SEND_EXT_COMMUNITY)
12192 || CHECK_FLAG(p->af_flags[afi][safi],
12193 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12194 vty_out(vty,
12195 " Community attribute sent to this neighbor");
12196 if (CHECK_FLAG(p->af_flags[afi][safi],
12197 PEER_FLAG_SEND_COMMUNITY)
12198 && CHECK_FLAG(p->af_flags[afi][safi],
12199 PEER_FLAG_SEND_EXT_COMMUNITY)
12200 && CHECK_FLAG(p->af_flags[afi][safi],
12201 PEER_FLAG_SEND_LARGE_COMMUNITY))
12202 vty_out(vty, "(all)\n");
12203 else if (CHECK_FLAG(p->af_flags[afi][safi],
12204 PEER_FLAG_SEND_LARGE_COMMUNITY))
12205 vty_out(vty, "(large)\n");
12206 else if (CHECK_FLAG(p->af_flags[afi][safi],
12207 PEER_FLAG_SEND_EXT_COMMUNITY))
12208 vty_out(vty, "(extended)\n");
12209 else
12210 vty_out(vty, "(standard)\n");
12211 }
12212 if (CHECK_FLAG(p->af_flags[afi][safi],
12213 PEER_FLAG_DEFAULT_ORIGINATE)) {
12214 vty_out(vty, " Default information originate,");
12215
12216 if (p->default_rmap[afi][safi].name)
12217 vty_out(vty, " default route-map %s%s,",
12218 p->default_rmap[afi][safi].map ? "*"
12219 : "",
12220 p->default_rmap[afi][safi].name);
12221 if (paf && PAF_SUBGRP(paf)
12222 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12223 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12224 vty_out(vty, " default sent\n");
12225 else
12226 vty_out(vty, " default not sent\n");
12227 }
12228
12229 /* advertise-vni-all */
12230 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12231 if (is_evpn_enabled())
12232 vty_out(vty, " advertise-all-vni\n");
12233 }
12234
12235 if (filter->plist[FILTER_IN].name
12236 || filter->dlist[FILTER_IN].name
12237 || filter->aslist[FILTER_IN].name
12238 || filter->map[RMAP_IN].name)
12239 vty_out(vty, " Inbound path policy configured\n");
12240 if (filter->plist[FILTER_OUT].name
12241 || filter->dlist[FILTER_OUT].name
12242 || filter->aslist[FILTER_OUT].name
12243 || filter->map[RMAP_OUT].name || filter->usmap.name)
12244 vty_out(vty, " Outbound path policy configured\n");
12245
12246 /* prefix-list */
12247 if (filter->plist[FILTER_IN].name)
12248 vty_out(vty,
12249 " Incoming update prefix filter list is %s%s\n",
12250 filter->plist[FILTER_IN].plist ? "*" : "",
12251 filter->plist[FILTER_IN].name);
12252 if (filter->plist[FILTER_OUT].name)
12253 vty_out(vty,
12254 " Outgoing update prefix filter list is %s%s\n",
12255 filter->plist[FILTER_OUT].plist ? "*" : "",
12256 filter->plist[FILTER_OUT].name);
12257
12258 /* distribute-list */
12259 if (filter->dlist[FILTER_IN].name)
12260 vty_out(vty,
12261 " Incoming update network filter list is %s%s\n",
12262 filter->dlist[FILTER_IN].alist ? "*" : "",
12263 filter->dlist[FILTER_IN].name);
12264 if (filter->dlist[FILTER_OUT].name)
12265 vty_out(vty,
12266 " Outgoing update network filter list is %s%s\n",
12267 filter->dlist[FILTER_OUT].alist ? "*" : "",
12268 filter->dlist[FILTER_OUT].name);
12269
12270 /* filter-list. */
12271 if (filter->aslist[FILTER_IN].name)
12272 vty_out(vty,
12273 " Incoming update AS path filter list is %s%s\n",
12274 filter->aslist[FILTER_IN].aslist ? "*" : "",
12275 filter->aslist[FILTER_IN].name);
12276 if (filter->aslist[FILTER_OUT].name)
12277 vty_out(vty,
12278 " Outgoing update AS path filter list is %s%s\n",
12279 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12280 filter->aslist[FILTER_OUT].name);
12281
12282 /* route-map. */
12283 if (filter->map[RMAP_IN].name)
12284 vty_out(vty,
12285 " Route map for incoming advertisements is %s%s\n",
12286 filter->map[RMAP_IN].map ? "*" : "",
12287 filter->map[RMAP_IN].name);
12288 if (filter->map[RMAP_OUT].name)
12289 vty_out(vty,
12290 " Route map for outgoing advertisements is %s%s\n",
12291 filter->map[RMAP_OUT].map ? "*" : "",
12292 filter->map[RMAP_OUT].name);
12293
12294 /* ebgp-requires-policy (inbound) */
12295 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12296 && !bgp_inbound_policy_exists(p, filter))
12297 vty_out(vty,
12298 " Inbound updates discarded due to missing policy\n");
12299
12300 /* ebgp-requires-policy (outbound) */
12301 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12302 && !bgp_outbound_policy_exists(p, filter))
12303 vty_out(vty,
12304 " Outbound updates discarded due to missing policy\n");
12305
12306 /* unsuppress-map */
12307 if (filter->usmap.name)
12308 vty_out(vty,
12309 " Route map for selective unsuppress is %s%s\n",
12310 filter->usmap.map ? "*" : "",
12311 filter->usmap.name);
12312
12313 /* advertise-map */
12314 if (filter->advmap.aname && filter->advmap.cname)
12315 vty_out(vty,
12316 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12317 filter->advmap.condition ? "EXIST"
12318 : "NON_EXIST",
12319 filter->advmap.cmap ? "*" : "",
12320 filter->advmap.cname,
12321 filter->advmap.amap ? "*" : "",
12322 filter->advmap.aname,
12323 filter->advmap.update_type == ADVERTISE
12324 ? "Advertise"
12325 : "Withdraw");
12326
12327 /* Receive prefix count */
12328 vty_out(vty, " %u accepted prefixes\n",
12329 p->pcount[afi][safi]);
12330
12331 /* maximum-prefix-out */
12332 if (CHECK_FLAG(p->af_flags[afi][safi],
12333 PEER_FLAG_MAX_PREFIX_OUT))
12334 vty_out(vty,
12335 " Maximum allowed prefixes sent %u\n",
12336 p->pmax_out[afi][safi]);
12337
12338 /* Maximum prefix */
12339 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12340 vty_out(vty,
12341 " Maximum prefixes allowed %u%s\n",
12342 p->pmax[afi][safi],
12343 CHECK_FLAG(p->af_flags[afi][safi],
12344 PEER_FLAG_MAX_PREFIX_WARNING)
12345 ? " (warning-only)"
12346 : "");
12347 vty_out(vty, " Threshold for warning message %d%%",
12348 p->pmax_threshold[afi][safi]);
12349 if (p->pmax_restart[afi][safi])
12350 vty_out(vty, ", restart interval %d min",
12351 p->pmax_restart[afi][safi]);
12352 vty_out(vty, "\n");
12353 }
12354
12355 vty_out(vty, "\n");
12356 }
12357 }
12358
12359 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12360 json_object *json)
12361 {
12362 struct bgp *bgp;
12363 char buf1[PREFIX2STR_BUFFER];
12364 char timebuf[BGP_UPTIME_LEN];
12365 char dn_flag[2];
12366 afi_t afi;
12367 safi_t safi;
12368 uint16_t i;
12369 uint8_t *msg;
12370 json_object *json_neigh = NULL;
12371 time_t epoch_tbuf;
12372 uint32_t sync_tcp_mss;
12373
12374 bgp = p->bgp;
12375
12376 if (use_json)
12377 json_neigh = json_object_new_object();
12378
12379 memset(dn_flag, '\0', sizeof(dn_flag));
12380 if (!p->conf_if && peer_dynamic_neighbor(p))
12381 dn_flag[0] = '*';
12382
12383 if (!use_json) {
12384 if (p->conf_if) /* Configured interface name. */
12385 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12386 &p->su);
12387 else /* Configured IP address. */
12388 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12389 p->host);
12390 }
12391
12392 if (use_json) {
12393 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12394 json_object_string_add(json_neigh, "bgpNeighborAddr",
12395 "none");
12396 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12397 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12398 "%pSU", &p->su);
12399
12400 json_object_int_add(json_neigh, "remoteAs", p->as);
12401
12402 if (p->change_local_as)
12403 json_object_int_add(json_neigh, "localAs",
12404 p->change_local_as);
12405 else
12406 json_object_int_add(json_neigh, "localAs", p->local_as);
12407
12408 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12409 json_object_boolean_true_add(json_neigh,
12410 "localAsNoPrepend");
12411
12412 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12413 json_object_boolean_true_add(json_neigh,
12414 "localAsReplaceAs");
12415 } else {
12416 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12417 || (p->as_type == AS_INTERNAL))
12418 vty_out(vty, "remote AS %u, ", p->as);
12419 else
12420 vty_out(vty, "remote AS Unspecified, ");
12421 vty_out(vty, "local AS %u%s%s, ",
12422 p->change_local_as ? p->change_local_as : p->local_as,
12423 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12424 ? " no-prepend"
12425 : "",
12426 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12427 ? " replace-as"
12428 : "");
12429 }
12430 /* peer type internal or confed-internal */
12431 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12432 if (use_json) {
12433 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12434 json_object_boolean_true_add(
12435 json_neigh, "nbrConfedInternalLink");
12436 else
12437 json_object_boolean_true_add(json_neigh,
12438 "nbrInternalLink");
12439 } else {
12440 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12441 vty_out(vty, "confed-internal link\n");
12442 else
12443 vty_out(vty, "internal link\n");
12444 }
12445 /* peer type external or confed-external */
12446 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12447 if (use_json) {
12448 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12449 json_object_boolean_true_add(
12450 json_neigh, "nbrConfedExternalLink");
12451 else
12452 json_object_boolean_true_add(json_neigh,
12453 "nbrExternalLink");
12454 } else {
12455 if (bgp_confederation_peers_check(bgp, p->as))
12456 vty_out(vty, "confed-external link\n");
12457 else
12458 vty_out(vty, "external link\n");
12459 }
12460 } else {
12461 if (use_json)
12462 json_object_boolean_true_add(json_neigh,
12463 "nbrUnspecifiedLink");
12464 else
12465 vty_out(vty, "unspecified link\n");
12466 }
12467
12468 /* Description. */
12469 if (p->desc) {
12470 if (use_json)
12471 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12472 else
12473 vty_out(vty, " Description: %s\n", p->desc);
12474 }
12475
12476 if (p->hostname) {
12477 if (use_json) {
12478 if (p->hostname)
12479 json_object_string_add(json_neigh, "hostname",
12480 p->hostname);
12481
12482 if (p->domainname)
12483 json_object_string_add(json_neigh, "domainname",
12484 p->domainname);
12485 } else {
12486 if (p->domainname && (p->domainname[0] != '\0'))
12487 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12488 p->domainname);
12489 else
12490 vty_out(vty, "Hostname: %s\n", p->hostname);
12491 }
12492 }
12493
12494 /* Peer-group */
12495 if (p->group) {
12496 if (use_json) {
12497 json_object_string_add(json_neigh, "peerGroup",
12498 p->group->name);
12499
12500 if (dn_flag[0]) {
12501 struct prefix prefix, *range = NULL;
12502
12503 if (sockunion2hostprefix(&(p->su), &prefix))
12504 range = peer_group_lookup_dynamic_neighbor_range(
12505 p->group, &prefix);
12506
12507 if (range) {
12508 json_object_string_addf(
12509 json_neigh,
12510 "peerSubnetRangeGroup", "%pFX",
12511 range);
12512 }
12513 }
12514 } else {
12515 vty_out(vty,
12516 " Member of peer-group %s for session parameters\n",
12517 p->group->name);
12518
12519 if (dn_flag[0]) {
12520 struct prefix prefix, *range = NULL;
12521
12522 if (sockunion2hostprefix(&(p->su), &prefix))
12523 range = peer_group_lookup_dynamic_neighbor_range(
12524 p->group, &prefix);
12525
12526 if (range) {
12527 vty_out(vty,
12528 " Belongs to the subnet range group: %pFX\n",
12529 range);
12530 }
12531 }
12532 }
12533 }
12534
12535 if (use_json) {
12536 /* Administrative shutdown. */
12537 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12538 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12539 json_object_boolean_true_add(json_neigh,
12540 "adminShutDown");
12541
12542 /* BGP Version. */
12543 json_object_int_add(json_neigh, "bgpVersion", 4);
12544 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12545 &p->remote_id);
12546 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12547 &bgp->router_id);
12548
12549 /* Confederation */
12550 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12551 && bgp_confederation_peers_check(bgp, p->as))
12552 json_object_boolean_true_add(json_neigh,
12553 "nbrCommonAdmin");
12554
12555 /* Status. */
12556 json_object_string_add(
12557 json_neigh, "bgpState",
12558 lookup_msg(bgp_status_msg, p->status, NULL));
12559
12560 if (peer_established(p)) {
12561 time_t uptime;
12562
12563 uptime = bgp_clock();
12564 uptime -= p->uptime;
12565 epoch_tbuf = time(NULL) - uptime;
12566
12567 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12568 uptime * 1000);
12569 json_object_string_add(json_neigh, "bgpTimerUpString",
12570 peer_uptime(p->uptime, timebuf,
12571 BGP_UPTIME_LEN, 0,
12572 NULL));
12573 json_object_int_add(json_neigh,
12574 "bgpTimerUpEstablishedEpoch",
12575 epoch_tbuf);
12576 }
12577
12578 else if (p->status == Active) {
12579 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12580 json_object_string_add(json_neigh, "bgpStateIs",
12581 "passive");
12582 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12583 json_object_string_add(json_neigh, "bgpStateIs",
12584 "passiveNSF");
12585 }
12586
12587 /* read timer */
12588 time_t uptime;
12589 struct tm tm;
12590
12591 uptime = bgp_clock();
12592 uptime -= p->readtime;
12593 gmtime_r(&uptime, &tm);
12594
12595 json_object_int_add(json_neigh, "bgpTimerLastRead",
12596 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12597 + (tm.tm_hour * 3600000));
12598
12599 uptime = bgp_clock();
12600 uptime -= p->last_write;
12601 gmtime_r(&uptime, &tm);
12602
12603 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12604 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12605 + (tm.tm_hour * 3600000));
12606
12607 uptime = bgp_clock();
12608 uptime -= p->update_time;
12609 gmtime_r(&uptime, &tm);
12610
12611 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12612 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12613 + (tm.tm_hour * 3600000));
12614
12615 /* Configured timer values. */
12616 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12617 p->v_holdtime * 1000);
12618 json_object_int_add(json_neigh,
12619 "bgpTimerKeepAliveIntervalMsecs",
12620 p->v_keepalive * 1000);
12621 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12622 json_object_int_add(json_neigh,
12623 "bgpTimerDelayOpenTimeMsecs",
12624 p->v_delayopen * 1000);
12625 }
12626
12627 /* Configured and Synced tcp-mss value for peer */
12628 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12629 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12630 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12631 p->tcp_mss);
12632 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12633 sync_tcp_mss);
12634 }
12635
12636 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12637 json_object_int_add(json_neigh,
12638 "bgpTimerConfiguredHoldTimeMsecs",
12639 p->holdtime * 1000);
12640 json_object_int_add(
12641 json_neigh,
12642 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12643 p->keepalive * 1000);
12644 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12645 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12646 json_object_int_add(json_neigh,
12647 "bgpTimerConfiguredHoldTimeMsecs",
12648 bgp->default_holdtime);
12649 json_object_int_add(
12650 json_neigh,
12651 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12652 bgp->default_keepalive);
12653 }
12654
12655 /* Extended Optional Parameters Length for BGP OPEN Message */
12656 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12657 json_object_boolean_true_add(
12658 json_neigh, "extendedOptionalParametersLength");
12659 else
12660 json_object_boolean_false_add(
12661 json_neigh, "extendedOptionalParametersLength");
12662
12663 /* Conditional advertisements */
12664 json_object_int_add(
12665 json_neigh,
12666 "bgpTimerConfiguredConditionalAdvertisementsSec",
12667 bgp->condition_check_period);
12668 if (thread_is_scheduled(bgp->t_condition_check))
12669 json_object_int_add(
12670 json_neigh,
12671 "bgpTimerUntilConditionalAdvertisementsSec",
12672 thread_timer_remain_second(
12673 bgp->t_condition_check));
12674 } else {
12675 /* Administrative shutdown. */
12676 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12677 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12678 vty_out(vty, " Administratively shut down\n");
12679
12680 /* BGP Version. */
12681 vty_out(vty, " BGP version 4");
12682 vty_out(vty, ", remote router ID %s",
12683 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12684 vty_out(vty, ", local router ID %s\n",
12685 inet_ntop(AF_INET, &bgp->router_id, buf1,
12686 sizeof(buf1)));
12687
12688 /* Confederation */
12689 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12690 && bgp_confederation_peers_check(bgp, p->as))
12691 vty_out(vty,
12692 " Neighbor under common administration\n");
12693
12694 /* Status. */
12695 vty_out(vty, " BGP state = %s",
12696 lookup_msg(bgp_status_msg, p->status, NULL));
12697
12698 if (peer_established(p))
12699 vty_out(vty, ", up for %8s",
12700 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12701 0, NULL));
12702
12703 else if (p->status == Active) {
12704 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12705 vty_out(vty, " (passive)");
12706 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12707 vty_out(vty, " (NSF passive)");
12708 }
12709 vty_out(vty, "\n");
12710
12711 /* read timer */
12712 vty_out(vty, " Last read %s",
12713 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12714 NULL));
12715 vty_out(vty, ", Last write %s\n",
12716 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12717 NULL));
12718
12719 /* Configured timer values. */
12720 vty_out(vty,
12721 " Hold time is %d, keepalive interval is %d seconds\n",
12722 p->v_holdtime, p->v_keepalive);
12723 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12724 vty_out(vty, " Configured hold time is %d",
12725 p->holdtime);
12726 vty_out(vty, ", keepalive interval is %d seconds\n",
12727 p->keepalive);
12728 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12729 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12730 vty_out(vty, " Configured hold time is %d",
12731 bgp->default_holdtime);
12732 vty_out(vty, ", keepalive interval is %d seconds\n",
12733 bgp->default_keepalive);
12734 }
12735 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12736 vty_out(vty,
12737 " Configured DelayOpenTime is %d seconds\n",
12738 p->delayopen);
12739
12740 /* Configured and synced tcp-mss value for peer */
12741 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12742 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12743 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12744 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12745 }
12746
12747 /* Extended Optional Parameters Length for BGP OPEN Message */
12748 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12749 vty_out(vty,
12750 " Extended Optional Parameters Length is enabled\n");
12751
12752 /* Conditional advertisements */
12753 vty_out(vty,
12754 " Configured conditional advertisements interval is %d seconds\n",
12755 bgp->condition_check_period);
12756 if (thread_is_scheduled(bgp->t_condition_check))
12757 vty_out(vty,
12758 " Time until conditional advertisements begin is %lu seconds\n",
12759 thread_timer_remain_second(
12760 bgp->t_condition_check));
12761 }
12762 /* Capability. */
12763 if (peer_established(p) &&
12764 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12765 if (use_json) {
12766 json_object *json_cap = NULL;
12767
12768 json_cap = json_object_new_object();
12769
12770 /* AS4 */
12771 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12772 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12773 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12774 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12775 json_object_string_add(
12776 json_cap, "4byteAs",
12777 "advertisedAndReceived");
12778 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12779 json_object_string_add(json_cap,
12780 "4byteAs",
12781 "advertised");
12782 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12783 json_object_string_add(json_cap,
12784 "4byteAs",
12785 "received");
12786 }
12787
12788 /* Extended Message Support */
12789 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12790 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12791 json_object_string_add(json_cap,
12792 "extendedMessage",
12793 "advertisedAndReceived");
12794 else if (CHECK_FLAG(p->cap,
12795 PEER_CAP_EXTENDED_MESSAGE_ADV))
12796 json_object_string_add(json_cap,
12797 "extendedMessage",
12798 "advertised");
12799 else if (CHECK_FLAG(p->cap,
12800 PEER_CAP_EXTENDED_MESSAGE_RCV))
12801 json_object_string_add(json_cap,
12802 "extendedMessage",
12803 "received");
12804
12805 /* AddPath */
12806 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12807 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12808 json_object *json_add = NULL;
12809 const char *print_store;
12810
12811 json_add = json_object_new_object();
12812
12813 FOREACH_AFI_SAFI (afi, safi) {
12814 json_object *json_sub = NULL;
12815 json_sub = json_object_new_object();
12816 print_store = get_afi_safi_str(
12817 afi, safi, true);
12818
12819 if (CHECK_FLAG(
12820 p->af_cap[afi][safi],
12821 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12822 CHECK_FLAG(
12823 p->af_cap[afi][safi],
12824 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12825 if (CHECK_FLAG(
12826 p->af_cap[afi]
12827 [safi],
12828 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12829 CHECK_FLAG(
12830 p->af_cap[afi]
12831 [safi],
12832 PEER_CAP_ADDPATH_AF_TX_RCV))
12833 json_object_boolean_true_add(
12834 json_sub,
12835 "txAdvertisedAndReceived");
12836 else if (
12837 CHECK_FLAG(
12838 p->af_cap[afi]
12839 [safi],
12840 PEER_CAP_ADDPATH_AF_TX_ADV))
12841 json_object_boolean_true_add(
12842 json_sub,
12843 "txAdvertised");
12844 else if (
12845 CHECK_FLAG(
12846 p->af_cap[afi]
12847 [safi],
12848 PEER_CAP_ADDPATH_AF_TX_RCV))
12849 json_object_boolean_true_add(
12850 json_sub,
12851 "txReceived");
12852 }
12853
12854 if (CHECK_FLAG(
12855 p->af_cap[afi][safi],
12856 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12857 CHECK_FLAG(
12858 p->af_cap[afi][safi],
12859 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12860 if (CHECK_FLAG(
12861 p->af_cap[afi]
12862 [safi],
12863 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12864 CHECK_FLAG(
12865 p->af_cap[afi]
12866 [safi],
12867 PEER_CAP_ADDPATH_AF_RX_RCV))
12868 json_object_boolean_true_add(
12869 json_sub,
12870 "rxAdvertisedAndReceived");
12871 else if (
12872 CHECK_FLAG(
12873 p->af_cap[afi]
12874 [safi],
12875 PEER_CAP_ADDPATH_AF_RX_ADV))
12876 json_object_boolean_true_add(
12877 json_sub,
12878 "rxAdvertised");
12879 else if (
12880 CHECK_FLAG(
12881 p->af_cap[afi]
12882 [safi],
12883 PEER_CAP_ADDPATH_AF_RX_RCV))
12884 json_object_boolean_true_add(
12885 json_sub,
12886 "rxReceived");
12887 }
12888
12889 if (CHECK_FLAG(
12890 p->af_cap[afi][safi],
12891 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12892 CHECK_FLAG(
12893 p->af_cap[afi][safi],
12894 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12895 CHECK_FLAG(
12896 p->af_cap[afi][safi],
12897 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12898 CHECK_FLAG(
12899 p->af_cap[afi][safi],
12900 PEER_CAP_ADDPATH_AF_RX_RCV))
12901 json_object_object_add(
12902 json_add, print_store,
12903 json_sub);
12904 else
12905 json_object_free(json_sub);
12906 }
12907
12908 json_object_object_add(json_cap, "addPath",
12909 json_add);
12910 }
12911
12912 /* Dynamic */
12913 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12914 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12915 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12916 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12917 json_object_string_add(
12918 json_cap, "dynamic",
12919 "advertisedAndReceived");
12920 else if (CHECK_FLAG(p->cap,
12921 PEER_CAP_DYNAMIC_ADV))
12922 json_object_string_add(json_cap,
12923 "dynamic",
12924 "advertised");
12925 else if (CHECK_FLAG(p->cap,
12926 PEER_CAP_DYNAMIC_RCV))
12927 json_object_string_add(json_cap,
12928 "dynamic",
12929 "received");
12930 }
12931
12932 /* Extended nexthop */
12933 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12934 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12935 json_object *json_nxt = NULL;
12936 const char *print_store;
12937
12938
12939 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12940 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12941 json_object_string_add(
12942 json_cap, "extendedNexthop",
12943 "advertisedAndReceived");
12944 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12945 json_object_string_add(
12946 json_cap, "extendedNexthop",
12947 "advertised");
12948 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12949 json_object_string_add(
12950 json_cap, "extendedNexthop",
12951 "received");
12952
12953 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12954 json_nxt = json_object_new_object();
12955
12956 for (safi = SAFI_UNICAST;
12957 safi < SAFI_MAX; safi++) {
12958 if (CHECK_FLAG(
12959 p->af_cap[AFI_IP]
12960 [safi],
12961 PEER_CAP_ENHE_AF_RCV)) {
12962 print_store =
12963 get_afi_safi_str(
12964 AFI_IP,
12965 safi,
12966 true);
12967 json_object_string_add(
12968 json_nxt,
12969 print_store,
12970 "recieved"); /* misspelled for compatibility */
12971 }
12972 }
12973 json_object_object_add(
12974 json_cap,
12975 "extendedNexthopFamililesByPeer",
12976 json_nxt);
12977 }
12978 }
12979
12980 /* Long-lived Graceful Restart */
12981 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12982 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12983 json_object *json_llgr = NULL;
12984 const char *afi_safi_str;
12985
12986 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12987 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12988 json_object_string_add(
12989 json_cap,
12990 "longLivedGracefulRestart",
12991 "advertisedAndReceived");
12992 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12993 json_object_string_add(
12994 json_cap,
12995 "longLivedGracefulRestart",
12996 "advertised");
12997 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12998 json_object_string_add(
12999 json_cap,
13000 "longLivedGracefulRestart",
13001 "received");
13002
13003 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13004 json_llgr = json_object_new_object();
13005
13006 FOREACH_AFI_SAFI (afi, safi) {
13007 if (CHECK_FLAG(
13008 p->af_cap[afi]
13009 [safi],
13010 PEER_CAP_ENHE_AF_RCV)) {
13011 afi_safi_str =
13012 get_afi_safi_str(
13013 afi,
13014 safi,
13015 true);
13016 json_object_string_add(
13017 json_llgr,
13018 afi_safi_str,
13019 "received");
13020 }
13021 }
13022 json_object_object_add(
13023 json_cap,
13024 "longLivedGracefulRestartByPeer",
13025 json_llgr);
13026 }
13027 }
13028
13029 /* Route Refresh */
13030 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13031 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13032 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13033 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13034 (CHECK_FLAG(p->cap,
13035 PEER_CAP_REFRESH_NEW_RCV) ||
13036 CHECK_FLAG(p->cap,
13037 PEER_CAP_REFRESH_OLD_RCV))) {
13038 if (CHECK_FLAG(
13039 p->cap,
13040 PEER_CAP_REFRESH_OLD_RCV) &&
13041 CHECK_FLAG(
13042 p->cap,
13043 PEER_CAP_REFRESH_NEW_RCV))
13044 json_object_string_add(
13045 json_cap,
13046 "routeRefresh",
13047 "advertisedAndReceivedOldNew");
13048 else {
13049 if (CHECK_FLAG(
13050 p->cap,
13051 PEER_CAP_REFRESH_OLD_RCV))
13052 json_object_string_add(
13053 json_cap,
13054 "routeRefresh",
13055 "advertisedAndReceivedOld");
13056 else
13057 json_object_string_add(
13058 json_cap,
13059 "routeRefresh",
13060 "advertisedAndReceivedNew");
13061 }
13062 } else if (CHECK_FLAG(p->cap,
13063 PEER_CAP_REFRESH_ADV))
13064 json_object_string_add(json_cap,
13065 "routeRefresh",
13066 "advertised");
13067 else if (CHECK_FLAG(p->cap,
13068 PEER_CAP_REFRESH_NEW_RCV) ||
13069 CHECK_FLAG(p->cap,
13070 PEER_CAP_REFRESH_OLD_RCV))
13071 json_object_string_add(json_cap,
13072 "routeRefresh",
13073 "received");
13074 }
13075
13076 /* Enhanced Route Refresh */
13077 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13078 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13079 if (CHECK_FLAG(p->cap,
13080 PEER_CAP_ENHANCED_RR_ADV) &&
13081 CHECK_FLAG(p->cap,
13082 PEER_CAP_ENHANCED_RR_RCV))
13083 json_object_string_add(
13084 json_cap,
13085 "enhancedRouteRefresh",
13086 "advertisedAndReceived");
13087 else if (CHECK_FLAG(p->cap,
13088 PEER_CAP_ENHANCED_RR_ADV))
13089 json_object_string_add(
13090 json_cap,
13091 "enhancedRouteRefresh",
13092 "advertised");
13093 else if (CHECK_FLAG(p->cap,
13094 PEER_CAP_ENHANCED_RR_RCV))
13095 json_object_string_add(
13096 json_cap,
13097 "enhancedRouteRefresh",
13098 "received");
13099 }
13100
13101 /* Multiprotocol Extensions */
13102 json_object *json_multi = NULL;
13103
13104 json_multi = json_object_new_object();
13105
13106 FOREACH_AFI_SAFI (afi, safi) {
13107 if (p->afc_adv[afi][safi] ||
13108 p->afc_recv[afi][safi]) {
13109 json_object *json_exten = NULL;
13110 json_exten = json_object_new_object();
13111
13112 if (p->afc_adv[afi][safi] &&
13113 p->afc_recv[afi][safi])
13114 json_object_boolean_true_add(
13115 json_exten,
13116 "advertisedAndReceived");
13117 else if (p->afc_adv[afi][safi])
13118 json_object_boolean_true_add(
13119 json_exten,
13120 "advertised");
13121 else if (p->afc_recv[afi][safi])
13122 json_object_boolean_true_add(
13123 json_exten, "received");
13124
13125 json_object_object_add(
13126 json_multi,
13127 get_afi_safi_str(afi, safi,
13128 true),
13129 json_exten);
13130 }
13131 }
13132 json_object_object_add(json_cap,
13133 "multiprotocolExtensions",
13134 json_multi);
13135
13136 /* Hostname capabilities */
13137 json_object *json_hname = NULL;
13138
13139 json_hname = json_object_new_object();
13140
13141 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13142 json_object_string_add(
13143 json_hname, "advHostName",
13144 bgp->peer_self->hostname
13145 ? bgp->peer_self->hostname
13146 : "n/a");
13147 json_object_string_add(
13148 json_hname, "advDomainName",
13149 bgp->peer_self->domainname
13150 ? bgp->peer_self->domainname
13151 : "n/a");
13152 }
13153
13154
13155 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13156 json_object_string_add(
13157 json_hname, "rcvHostName",
13158 p->hostname ? p->hostname : "n/a");
13159 json_object_string_add(
13160 json_hname, "rcvDomainName",
13161 p->domainname ? p->domainname : "n/a");
13162 }
13163
13164 json_object_object_add(json_cap, "hostName",
13165 json_hname);
13166
13167 /* Graceful Restart */
13168 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13169 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13170 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13171 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13172 json_object_string_add(
13173 json_cap, "gracefulRestart",
13174 "advertisedAndReceived");
13175 else if (CHECK_FLAG(p->cap,
13176 PEER_CAP_RESTART_ADV))
13177 json_object_string_add(
13178 json_cap,
13179 "gracefulRestartCapability",
13180 "advertised");
13181 else if (CHECK_FLAG(p->cap,
13182 PEER_CAP_RESTART_RCV))
13183 json_object_string_add(
13184 json_cap,
13185 "gracefulRestartCapability",
13186 "received");
13187
13188 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13189 int restart_af_count = 0;
13190 json_object *json_restart = NULL;
13191 json_restart = json_object_new_object();
13192
13193 json_object_int_add(
13194 json_cap,
13195 "gracefulRestartRemoteTimerMsecs",
13196 p->v_gr_restart * 1000);
13197
13198 FOREACH_AFI_SAFI (afi, safi) {
13199 if (CHECK_FLAG(
13200 p->af_cap[afi]
13201 [safi],
13202 PEER_CAP_RESTART_AF_RCV)) {
13203 json_object *json_sub =
13204 NULL;
13205 json_sub =
13206 json_object_new_object();
13207
13208 if (CHECK_FLAG(
13209 p->af_cap
13210 [afi]
13211 [safi],
13212 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13213 json_object_boolean_true_add(
13214 json_sub,
13215 "preserved");
13216 restart_af_count++;
13217 json_object_object_add(
13218 json_restart,
13219 get_afi_safi_str(
13220 afi,
13221 safi,
13222 true),
13223 json_sub);
13224 }
13225 }
13226 if (!restart_af_count) {
13227 json_object_string_add(
13228 json_cap,
13229 "addressFamiliesByPeer",
13230 "none");
13231 json_object_free(json_restart);
13232 } else
13233 json_object_object_add(
13234 json_cap,
13235 "addressFamiliesByPeer",
13236 json_restart);
13237 }
13238 }
13239 json_object_object_add(
13240 json_neigh, "neighborCapabilities", json_cap);
13241 } else {
13242 vty_out(vty, " Neighbor capabilities:\n");
13243
13244 /* AS4 */
13245 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13246 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13247 vty_out(vty, " 4 Byte AS:");
13248 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13249 vty_out(vty, " advertised");
13250 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13251 vty_out(vty, " %sreceived",
13252 CHECK_FLAG(p->cap,
13253 PEER_CAP_AS4_ADV)
13254 ? "and "
13255 : "");
13256 vty_out(vty, "\n");
13257 }
13258
13259 /* Extended Message Support */
13260 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13261 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13262 vty_out(vty, " Extended Message:");
13263 if (CHECK_FLAG(p->cap,
13264 PEER_CAP_EXTENDED_MESSAGE_ADV))
13265 vty_out(vty, " advertised");
13266 if (CHECK_FLAG(p->cap,
13267 PEER_CAP_EXTENDED_MESSAGE_RCV))
13268 vty_out(vty, " %sreceived",
13269 CHECK_FLAG(
13270 p->cap,
13271 PEER_CAP_EXTENDED_MESSAGE_ADV)
13272 ? "and "
13273 : "");
13274 vty_out(vty, "\n");
13275 }
13276
13277 /* AddPath */
13278 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13279 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13280 vty_out(vty, " AddPath:\n");
13281
13282 FOREACH_AFI_SAFI (afi, safi) {
13283 if (CHECK_FLAG(
13284 p->af_cap[afi][safi],
13285 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13286 CHECK_FLAG(
13287 p->af_cap[afi][safi],
13288 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13289 vty_out(vty, " %s: TX ",
13290 get_afi_safi_str(
13291 afi, safi,
13292 false));
13293
13294 if (CHECK_FLAG(
13295 p->af_cap[afi]
13296 [safi],
13297 PEER_CAP_ADDPATH_AF_TX_ADV))
13298 vty_out(vty,
13299 "advertised");
13300
13301 if (CHECK_FLAG(
13302 p->af_cap[afi]
13303 [safi],
13304 PEER_CAP_ADDPATH_AF_TX_RCV))
13305 vty_out(vty,
13306 "%sreceived",
13307 CHECK_FLAG(
13308 p->af_cap
13309 [afi]
13310 [safi],
13311 PEER_CAP_ADDPATH_AF_TX_ADV)
13312 ? " and "
13313 : "");
13314
13315 vty_out(vty, "\n");
13316 }
13317
13318 if (CHECK_FLAG(
13319 p->af_cap[afi][safi],
13320 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13321 CHECK_FLAG(
13322 p->af_cap[afi][safi],
13323 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13324 vty_out(vty, " %s: RX ",
13325 get_afi_safi_str(
13326 afi, safi,
13327 false));
13328
13329 if (CHECK_FLAG(
13330 p->af_cap[afi]
13331 [safi],
13332 PEER_CAP_ADDPATH_AF_RX_ADV))
13333 vty_out(vty,
13334 "advertised");
13335
13336 if (CHECK_FLAG(
13337 p->af_cap[afi]
13338 [safi],
13339 PEER_CAP_ADDPATH_AF_RX_RCV))
13340 vty_out(vty,
13341 "%sreceived",
13342 CHECK_FLAG(
13343 p->af_cap
13344 [afi]
13345 [safi],
13346 PEER_CAP_ADDPATH_AF_RX_ADV)
13347 ? " and "
13348 : "");
13349
13350 vty_out(vty, "\n");
13351 }
13352 }
13353 }
13354
13355 /* Dynamic */
13356 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13357 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13358 vty_out(vty, " Dynamic:");
13359 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13360 vty_out(vty, " advertised");
13361 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13362 vty_out(vty, " %sreceived",
13363 CHECK_FLAG(p->cap,
13364 PEER_CAP_DYNAMIC_ADV)
13365 ? "and "
13366 : "");
13367 vty_out(vty, "\n");
13368 }
13369
13370 /* Extended nexthop */
13371 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13372 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13373 vty_out(vty, " Extended nexthop:");
13374 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13375 vty_out(vty, " advertised");
13376 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13377 vty_out(vty, " %sreceived",
13378 CHECK_FLAG(p->cap,
13379 PEER_CAP_ENHE_ADV)
13380 ? "and "
13381 : "");
13382 vty_out(vty, "\n");
13383
13384 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13385 vty_out(vty,
13386 " Address families by peer:\n ");
13387 for (safi = SAFI_UNICAST;
13388 safi < SAFI_MAX; safi++)
13389 if (CHECK_FLAG(
13390 p->af_cap[AFI_IP]
13391 [safi],
13392 PEER_CAP_ENHE_AF_RCV))
13393 vty_out(vty,
13394 " %s\n",
13395 get_afi_safi_str(
13396 AFI_IP,
13397 safi,
13398 false));
13399 }
13400 }
13401
13402 /* Long-lived Graceful Restart */
13403 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13404 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13405 vty_out(vty,
13406 " Long-lived Graceful Restart:");
13407 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13408 vty_out(vty, " advertised");
13409 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13410 vty_out(vty, " %sreceived",
13411 CHECK_FLAG(p->cap,
13412 PEER_CAP_LLGR_ADV)
13413 ? "and "
13414 : "");
13415 vty_out(vty, "\n");
13416
13417 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13418 vty_out(vty,
13419 " Address families by peer:\n");
13420 FOREACH_AFI_SAFI (afi, safi)
13421 if (CHECK_FLAG(
13422 p->af_cap[afi]
13423 [safi],
13424 PEER_CAP_LLGR_AF_RCV))
13425 vty_out(vty,
13426 " %s\n",
13427 get_afi_safi_str(
13428 afi,
13429 safi,
13430 false));
13431 }
13432 }
13433
13434 /* Route Refresh */
13435 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13436 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13437 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13438 vty_out(vty, " Route refresh:");
13439 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13440 vty_out(vty, " advertised");
13441 if (CHECK_FLAG(p->cap,
13442 PEER_CAP_REFRESH_NEW_RCV) ||
13443 CHECK_FLAG(p->cap,
13444 PEER_CAP_REFRESH_OLD_RCV))
13445 vty_out(vty, " %sreceived(%s)",
13446 CHECK_FLAG(p->cap,
13447 PEER_CAP_REFRESH_ADV)
13448 ? "and "
13449 : "",
13450 (CHECK_FLAG(
13451 p->cap,
13452 PEER_CAP_REFRESH_OLD_RCV) &&
13453 CHECK_FLAG(
13454 p->cap,
13455 PEER_CAP_REFRESH_NEW_RCV))
13456 ? "old & new"
13457 : CHECK_FLAG(
13458 p->cap,
13459 PEER_CAP_REFRESH_OLD_RCV)
13460 ? "old"
13461 : "new");
13462
13463 vty_out(vty, "\n");
13464 }
13465
13466 /* Enhanced Route Refresh */
13467 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13468 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13469 vty_out(vty, " Enhanced Route Refresh:");
13470 if (CHECK_FLAG(p->cap,
13471 PEER_CAP_ENHANCED_RR_ADV))
13472 vty_out(vty, " advertised");
13473 if (CHECK_FLAG(p->cap,
13474 PEER_CAP_ENHANCED_RR_RCV))
13475 vty_out(vty, " %sreceived",
13476 CHECK_FLAG(p->cap,
13477 PEER_CAP_REFRESH_ADV)
13478 ? "and "
13479 : "");
13480 vty_out(vty, "\n");
13481 }
13482
13483 /* Multiprotocol Extensions */
13484 FOREACH_AFI_SAFI (afi, safi)
13485 if (p->afc_adv[afi][safi] ||
13486 p->afc_recv[afi][safi]) {
13487 vty_out(vty, " Address Family %s:",
13488 get_afi_safi_str(afi, safi,
13489 false));
13490 if (p->afc_adv[afi][safi])
13491 vty_out(vty, " advertised");
13492 if (p->afc_recv[afi][safi])
13493 vty_out(vty, " %sreceived",
13494 p->afc_adv[afi][safi]
13495 ? "and "
13496 : "");
13497 vty_out(vty, "\n");
13498 }
13499
13500 /* Hostname capability */
13501 vty_out(vty, " Hostname Capability:");
13502
13503 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13504 vty_out(vty,
13505 " advertised (name: %s,domain name: %s)",
13506 bgp->peer_self->hostname
13507 ? bgp->peer_self->hostname
13508 : "n/a",
13509 bgp->peer_self->domainname
13510 ? bgp->peer_self->domainname
13511 : "n/a");
13512 } else {
13513 vty_out(vty, " not advertised");
13514 }
13515
13516 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13517 vty_out(vty,
13518 " received (name: %s,domain name: %s)",
13519 p->hostname ? p->hostname : "n/a",
13520 p->domainname ? p->domainname : "n/a");
13521 } else {
13522 vty_out(vty, " not received");
13523 }
13524
13525 vty_out(vty, "\n");
13526
13527 /* Graceful Restart */
13528 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13529 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13530 vty_out(vty,
13531 " Graceful Restart Capability:");
13532 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13533 vty_out(vty, " advertised");
13534 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13535 vty_out(vty, " %sreceived",
13536 CHECK_FLAG(p->cap,
13537 PEER_CAP_RESTART_ADV)
13538 ? "and "
13539 : "");
13540 vty_out(vty, "\n");
13541
13542 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13543 int restart_af_count = 0;
13544
13545 vty_out(vty,
13546 " Remote Restart timer is %d seconds\n",
13547 p->v_gr_restart);
13548 vty_out(vty,
13549 " Address families by peer:\n ");
13550
13551 FOREACH_AFI_SAFI (afi, safi)
13552 if (CHECK_FLAG(
13553 p->af_cap[afi]
13554 [safi],
13555 PEER_CAP_RESTART_AF_RCV)) {
13556 vty_out(vty, "%s%s(%s)",
13557 restart_af_count
13558 ? ", "
13559 : "",
13560 get_afi_safi_str(
13561 afi,
13562 safi,
13563 false),
13564 CHECK_FLAG(
13565 p->af_cap
13566 [afi]
13567 [safi],
13568 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13569 ? "preserved"
13570 : "not preserved");
13571 restart_af_count++;
13572 }
13573 if (!restart_af_count)
13574 vty_out(vty, "none");
13575 vty_out(vty, "\n");
13576 }
13577 } /* Graceful Restart */
13578 }
13579 }
13580
13581 /* graceful restart information */
13582 json_object *json_grace = NULL;
13583 json_object *json_grace_send = NULL;
13584 json_object *json_grace_recv = NULL;
13585 int eor_send_af_count = 0;
13586 int eor_receive_af_count = 0;
13587
13588 if (use_json) {
13589 json_grace = json_object_new_object();
13590 json_grace_send = json_object_new_object();
13591 json_grace_recv = json_object_new_object();
13592
13593 if ((peer_established(p)) &&
13594 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13595 FOREACH_AFI_SAFI (afi, safi) {
13596 if (CHECK_FLAG(p->af_sflags[afi][safi],
13597 PEER_STATUS_EOR_SEND)) {
13598 json_object_boolean_true_add(
13599 json_grace_send,
13600 get_afi_safi_str(afi, safi,
13601 true));
13602 eor_send_af_count++;
13603 }
13604 }
13605 FOREACH_AFI_SAFI (afi, safi) {
13606 if (CHECK_FLAG(p->af_sflags[afi][safi],
13607 PEER_STATUS_EOR_RECEIVED)) {
13608 json_object_boolean_true_add(
13609 json_grace_recv,
13610 get_afi_safi_str(afi, safi,
13611 true));
13612 eor_receive_af_count++;
13613 }
13614 }
13615 }
13616 json_object_object_add(json_grace, "endOfRibSend",
13617 json_grace_send);
13618 json_object_object_add(json_grace, "endOfRibRecv",
13619 json_grace_recv);
13620
13621
13622 if (p->t_gr_restart)
13623 json_object_int_add(
13624 json_grace, "gracefulRestartTimerMsecs",
13625 thread_timer_remain_second(p->t_gr_restart) *
13626 1000);
13627
13628 if (p->t_gr_stale)
13629 json_object_int_add(
13630 json_grace, "gracefulStalepathTimerMsecs",
13631 thread_timer_remain_second(p->t_gr_stale) *
13632 1000);
13633 /* more gr info in new format */
13634 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13635 json_object_object_add(json_neigh, "gracefulRestartInfo",
13636 json_grace);
13637 } else {
13638 vty_out(vty, " Graceful restart information:\n");
13639 if ((peer_established(p)) &&
13640 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13641
13642 vty_out(vty, " End-of-RIB send: ");
13643 FOREACH_AFI_SAFI (afi, safi) {
13644 if (CHECK_FLAG(p->af_sflags[afi][safi],
13645 PEER_STATUS_EOR_SEND)) {
13646 vty_out(vty, "%s%s",
13647 eor_send_af_count ? ", " : "",
13648 get_afi_safi_str(afi, safi,
13649 false));
13650 eor_send_af_count++;
13651 }
13652 }
13653 vty_out(vty, "\n");
13654 vty_out(vty, " End-of-RIB received: ");
13655 FOREACH_AFI_SAFI (afi, safi) {
13656 if (CHECK_FLAG(p->af_sflags[afi][safi],
13657 PEER_STATUS_EOR_RECEIVED)) {
13658 vty_out(vty, "%s%s",
13659 eor_receive_af_count ? ", "
13660 : "",
13661 get_afi_safi_str(afi, safi,
13662 false));
13663 eor_receive_af_count++;
13664 }
13665 }
13666 vty_out(vty, "\n");
13667 }
13668
13669 if (p->t_gr_restart)
13670 vty_out(vty,
13671 " The remaining time of restart timer is %ld\n",
13672 thread_timer_remain_second(p->t_gr_restart));
13673
13674 if (p->t_gr_stale)
13675 vty_out(vty,
13676 " The remaining time of stalepath timer is %ld\n",
13677 thread_timer_remain_second(p->t_gr_stale));
13678
13679 /* more gr info in new format */
13680 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13681 }
13682
13683 if (use_json) {
13684 json_object *json_stat = NULL;
13685 json_stat = json_object_new_object();
13686 /* Packet counts. */
13687
13688 atomic_size_t outq_count, inq_count;
13689 outq_count = atomic_load_explicit(&p->obuf->count,
13690 memory_order_relaxed);
13691 inq_count = atomic_load_explicit(&p->ibuf->count,
13692 memory_order_relaxed);
13693
13694 json_object_int_add(json_stat, "depthInq",
13695 (unsigned long)inq_count);
13696 json_object_int_add(json_stat, "depthOutq",
13697 (unsigned long)outq_count);
13698 json_object_int_add(json_stat, "opensSent",
13699 atomic_load_explicit(&p->open_out,
13700 memory_order_relaxed));
13701 json_object_int_add(json_stat, "opensRecv",
13702 atomic_load_explicit(&p->open_in,
13703 memory_order_relaxed));
13704 json_object_int_add(json_stat, "notificationsSent",
13705 atomic_load_explicit(&p->notify_out,
13706 memory_order_relaxed));
13707 json_object_int_add(json_stat, "notificationsRecv",
13708 atomic_load_explicit(&p->notify_in,
13709 memory_order_relaxed));
13710 json_object_int_add(json_stat, "updatesSent",
13711 atomic_load_explicit(&p->update_out,
13712 memory_order_relaxed));
13713 json_object_int_add(json_stat, "updatesRecv",
13714 atomic_load_explicit(&p->update_in,
13715 memory_order_relaxed));
13716 json_object_int_add(json_stat, "keepalivesSent",
13717 atomic_load_explicit(&p->keepalive_out,
13718 memory_order_relaxed));
13719 json_object_int_add(json_stat, "keepalivesRecv",
13720 atomic_load_explicit(&p->keepalive_in,
13721 memory_order_relaxed));
13722 json_object_int_add(json_stat, "routeRefreshSent",
13723 atomic_load_explicit(&p->refresh_out,
13724 memory_order_relaxed));
13725 json_object_int_add(json_stat, "routeRefreshRecv",
13726 atomic_load_explicit(&p->refresh_in,
13727 memory_order_relaxed));
13728 json_object_int_add(json_stat, "capabilitySent",
13729 atomic_load_explicit(&p->dynamic_cap_out,
13730 memory_order_relaxed));
13731 json_object_int_add(json_stat, "capabilityRecv",
13732 atomic_load_explicit(&p->dynamic_cap_in,
13733 memory_order_relaxed));
13734 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13735 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13736 json_object_object_add(json_neigh, "messageStats", json_stat);
13737 } else {
13738 atomic_size_t outq_count, inq_count, open_out, open_in,
13739 notify_out, notify_in, update_out, update_in,
13740 keepalive_out, keepalive_in, refresh_out, refresh_in,
13741 dynamic_cap_out, dynamic_cap_in;
13742 outq_count = atomic_load_explicit(&p->obuf->count,
13743 memory_order_relaxed);
13744 inq_count = atomic_load_explicit(&p->ibuf->count,
13745 memory_order_relaxed);
13746 open_out = atomic_load_explicit(&p->open_out,
13747 memory_order_relaxed);
13748 open_in =
13749 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13750 notify_out = atomic_load_explicit(&p->notify_out,
13751 memory_order_relaxed);
13752 notify_in = atomic_load_explicit(&p->notify_in,
13753 memory_order_relaxed);
13754 update_out = atomic_load_explicit(&p->update_out,
13755 memory_order_relaxed);
13756 update_in = atomic_load_explicit(&p->update_in,
13757 memory_order_relaxed);
13758 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13759 memory_order_relaxed);
13760 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13761 memory_order_relaxed);
13762 refresh_out = atomic_load_explicit(&p->refresh_out,
13763 memory_order_relaxed);
13764 refresh_in = atomic_load_explicit(&p->refresh_in,
13765 memory_order_relaxed);
13766 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13767 memory_order_relaxed);
13768 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13769 memory_order_relaxed);
13770
13771 /* Packet counts. */
13772 vty_out(vty, " Message statistics:\n");
13773 vty_out(vty, " Inq depth is %zu\n", inq_count);
13774 vty_out(vty, " Outq depth is %zu\n", outq_count);
13775 vty_out(vty, " Sent Rcvd\n");
13776 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13777 open_in);
13778 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13779 notify_in);
13780 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13781 update_in);
13782 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13783 keepalive_in);
13784 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13785 refresh_in);
13786 vty_out(vty, " Capability: %10zu %10zu\n",
13787 dynamic_cap_out, dynamic_cap_in);
13788 vty_out(vty, " Total: %10u %10u\n",
13789 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
13790 }
13791
13792 if (use_json) {
13793 /* advertisement-interval */
13794 json_object_int_add(json_neigh,
13795 "minBtwnAdvertisementRunsTimerMsecs",
13796 p->v_routeadv * 1000);
13797
13798 /* Update-source. */
13799 if (p->update_if || p->update_source) {
13800 if (p->update_if)
13801 json_object_string_add(json_neigh,
13802 "updateSource",
13803 p->update_if);
13804 else if (p->update_source)
13805 json_object_string_addf(json_neigh,
13806 "updateSource", "%pSU",
13807 p->update_source);
13808 }
13809 } else {
13810 /* advertisement-interval */
13811 vty_out(vty,
13812 " Minimum time between advertisement runs is %d seconds\n",
13813 p->v_routeadv);
13814
13815 /* Update-source. */
13816 if (p->update_if || p->update_source) {
13817 vty_out(vty, " Update source is ");
13818 if (p->update_if)
13819 vty_out(vty, "%s", p->update_if);
13820 else if (p->update_source)
13821 vty_out(vty, "%pSU", p->update_source);
13822 vty_out(vty, "\n");
13823 }
13824
13825 vty_out(vty, "\n");
13826 }
13827
13828 /* Address Family Information */
13829 json_object *json_hold = NULL;
13830
13831 if (use_json)
13832 json_hold = json_object_new_object();
13833
13834 FOREACH_AFI_SAFI (afi, safi)
13835 if (p->afc[afi][safi])
13836 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13837 json_hold);
13838
13839 if (use_json) {
13840 json_object_object_add(json_neigh, "addressFamilyInfo",
13841 json_hold);
13842 json_object_int_add(json_neigh, "connectionsEstablished",
13843 p->established);
13844 json_object_int_add(json_neigh, "connectionsDropped",
13845 p->dropped);
13846 } else
13847 vty_out(vty, " Connections established %d; dropped %d\n",
13848 p->established, p->dropped);
13849
13850 if (!p->last_reset) {
13851 if (use_json)
13852 json_object_string_add(json_neigh, "lastReset",
13853 "never");
13854 else
13855 vty_out(vty, " Last reset never\n");
13856 } else {
13857 if (use_json) {
13858 time_t uptime;
13859 struct tm tm;
13860
13861 uptime = bgp_clock();
13862 uptime -= p->resettime;
13863 gmtime_r(&uptime, &tm);
13864
13865 json_object_int_add(json_neigh, "lastResetTimerMsecs",
13866 (tm.tm_sec * 1000)
13867 + (tm.tm_min * 60000)
13868 + (tm.tm_hour * 3600000));
13869 bgp_show_peer_reset(NULL, p, json_neigh, true);
13870 } else {
13871 vty_out(vty, " Last reset %s, ",
13872 peer_uptime(p->resettime, timebuf,
13873 BGP_UPTIME_LEN, 0, NULL));
13874
13875 bgp_show_peer_reset(vty, p, NULL, false);
13876 if (p->last_reset_cause_size) {
13877 msg = p->last_reset_cause;
13878 vty_out(vty,
13879 " Message received that caused BGP to send a NOTIFICATION:\n ");
13880 for (i = 1; i <= p->last_reset_cause_size;
13881 i++) {
13882 vty_out(vty, "%02X", *msg++);
13883
13884 if (i != p->last_reset_cause_size) {
13885 if (i % 16 == 0) {
13886 vty_out(vty, "\n ");
13887 } else if (i % 4 == 0) {
13888 vty_out(vty, " ");
13889 }
13890 }
13891 }
13892 vty_out(vty, "\n");
13893 }
13894 }
13895 }
13896
13897 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13898 if (use_json)
13899 json_object_boolean_true_add(json_neigh,
13900 "prefixesConfigExceedMax");
13901 else
13902 vty_out(vty,
13903 " Peer had exceeded the max. no. of prefixes configured.\n");
13904
13905 if (p->t_pmax_restart) {
13906 if (use_json) {
13907 json_object_boolean_true_add(
13908 json_neigh, "reducePrefixNumFrom");
13909 json_object_int_add(json_neigh,
13910 "restartInTimerMsec",
13911 thread_timer_remain_second(
13912 p->t_pmax_restart)
13913 * 1000);
13914 } else
13915 vty_out(vty,
13916 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
13917 p->host, thread_timer_remain_second(
13918 p->t_pmax_restart));
13919 } else {
13920 if (use_json)
13921 json_object_boolean_true_add(
13922 json_neigh,
13923 "reducePrefixNumAndClearIpBgp");
13924 else
13925 vty_out(vty,
13926 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13927 p->host);
13928 }
13929 }
13930
13931 /* EBGP Multihop and GTSM */
13932 if (p->sort != BGP_PEER_IBGP) {
13933 if (use_json) {
13934 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13935 json_object_int_add(json_neigh,
13936 "externalBgpNbrMaxHopsAway",
13937 p->gtsm_hops);
13938 else
13939 json_object_int_add(json_neigh,
13940 "externalBgpNbrMaxHopsAway",
13941 p->ttl);
13942 } else {
13943 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13944 vty_out(vty,
13945 " External BGP neighbor may be up to %d hops away.\n",
13946 p->gtsm_hops);
13947 else
13948 vty_out(vty,
13949 " External BGP neighbor may be up to %d hops away.\n",
13950 p->ttl);
13951 }
13952 } else {
13953 if (use_json) {
13954 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13955 json_object_int_add(json_neigh,
13956 "internalBgpNbrMaxHopsAway",
13957 p->gtsm_hops);
13958 else
13959 json_object_int_add(json_neigh,
13960 "internalBgpNbrMaxHopsAway",
13961 p->ttl);
13962 } else {
13963 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
13964 vty_out(vty,
13965 " Internal BGP neighbor may be up to %d hops away.\n",
13966 p->gtsm_hops);
13967 else
13968 vty_out(vty,
13969 " Internal BGP neighbor may be up to %d hops away.\n",
13970 p->ttl);
13971 }
13972 }
13973
13974 /* Local address. */
13975 if (p->su_local) {
13976 if (use_json) {
13977 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
13978 p->su_local);
13979 json_object_int_add(json_neigh, "portLocal",
13980 ntohs(p->su_local->sin.sin_port));
13981 } else
13982 vty_out(vty, "Local host: %pSU, Local port: %d\n",
13983 p->su_local, ntohs(p->su_local->sin.sin_port));
13984 } else {
13985 if (use_json) {
13986 json_object_string_add(json_neigh, "hostLocal",
13987 "Unknown");
13988 json_object_int_add(json_neigh, "portLocal", -1);
13989 }
13990 }
13991
13992 /* Remote address. */
13993 if (p->su_remote) {
13994 if (use_json) {
13995 json_object_string_addf(json_neigh, "hostForeign",
13996 "%pSU", p->su_remote);
13997 json_object_int_add(json_neigh, "portForeign",
13998 ntohs(p->su_remote->sin.sin_port));
13999 } else
14000 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14001 p->su_remote,
14002 ntohs(p->su_remote->sin.sin_port));
14003 } else {
14004 if (use_json) {
14005 json_object_string_add(json_neigh, "hostForeign",
14006 "Unknown");
14007 json_object_int_add(json_neigh, "portForeign", -1);
14008 }
14009 }
14010
14011 /* Nexthop display. */
14012 if (p->su_local) {
14013 if (use_json) {
14014 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14015 &p->nexthop.v4);
14016 json_object_string_addf(json_neigh, "nexthopGlobal",
14017 "%pI6", &p->nexthop.v6_global);
14018 json_object_string_addf(json_neigh, "nexthopLocal",
14019 "%pI6", &p->nexthop.v6_local);
14020 if (p->shared_network)
14021 json_object_string_add(json_neigh,
14022 "bgpConnection",
14023 "sharedNetwork");
14024 else
14025 json_object_string_add(json_neigh,
14026 "bgpConnection",
14027 "nonSharedNetwork");
14028 } else {
14029 vty_out(vty, "Nexthop: %s\n",
14030 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14031 sizeof(buf1)));
14032 vty_out(vty, "Nexthop global: %s\n",
14033 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14034 sizeof(buf1)));
14035 vty_out(vty, "Nexthop local: %s\n",
14036 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14037 sizeof(buf1)));
14038 vty_out(vty, "BGP connection: %s\n",
14039 p->shared_network ? "shared network"
14040 : "non shared network");
14041 }
14042 }
14043
14044 /* Timer information. */
14045 if (use_json) {
14046 json_object_int_add(json_neigh, "connectRetryTimer",
14047 p->v_connect);
14048 if (peer_established(p) && p->rtt)
14049 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14050 p->rtt);
14051 if (p->t_start)
14052 json_object_int_add(
14053 json_neigh, "nextStartTimerDueInMsecs",
14054 thread_timer_remain_second(p->t_start) * 1000);
14055 if (p->t_connect)
14056 json_object_int_add(
14057 json_neigh, "nextConnectTimerDueInMsecs",
14058 thread_timer_remain_second(p->t_connect)
14059 * 1000);
14060 if (p->t_routeadv) {
14061 json_object_int_add(json_neigh, "mraiInterval",
14062 p->v_routeadv);
14063 json_object_int_add(
14064 json_neigh, "mraiTimerExpireInMsecs",
14065 thread_timer_remain_second(p->t_routeadv)
14066 * 1000);
14067 }
14068 if (p->password)
14069 json_object_int_add(json_neigh, "authenticationEnabled",
14070 1);
14071
14072 if (p->t_read)
14073 json_object_string_add(json_neigh, "readThread", "on");
14074 else
14075 json_object_string_add(json_neigh, "readThread", "off");
14076
14077 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14078 json_object_string_add(json_neigh, "writeThread", "on");
14079 else
14080 json_object_string_add(json_neigh, "writeThread",
14081 "off");
14082 } else {
14083 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14084 p->v_connect);
14085 if (peer_established(p) && p->rtt)
14086 vty_out(vty, "Estimated round trip time: %d ms\n",
14087 p->rtt);
14088 if (p->t_start)
14089 vty_out(vty, "Next start timer due in %ld seconds\n",
14090 thread_timer_remain_second(p->t_start));
14091 if (p->t_connect)
14092 vty_out(vty, "Next connect timer due in %ld seconds\n",
14093 thread_timer_remain_second(p->t_connect));
14094 if (p->t_routeadv)
14095 vty_out(vty,
14096 "MRAI (interval %u) timer expires in %ld seconds\n",
14097 p->v_routeadv,
14098 thread_timer_remain_second(p->t_routeadv));
14099 if (p->password)
14100 vty_out(vty, "Peer Authentication Enabled\n");
14101
14102 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14103 p->t_read ? "on" : "off",
14104 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14105 ? "on"
14106 : "off", p->fd);
14107 }
14108
14109 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14110 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14111 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14112
14113 if (!use_json)
14114 vty_out(vty, "\n");
14115
14116 /* BFD information. */
14117 if (p->bfd_config)
14118 bgp_bfd_show_info(vty, p, json_neigh);
14119
14120 if (use_json) {
14121 if (p->conf_if) /* Configured interface name. */
14122 json_object_object_add(json, p->conf_if, json_neigh);
14123 else /* Configured IP address. */
14124 json_object_object_add(json, p->host, json_neigh);
14125 }
14126 }
14127
14128 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14129 enum show_type type,
14130 union sockunion *su,
14131 const char *conf_if, afi_t afi,
14132 bool use_json)
14133 {
14134 struct listnode *node, *nnode;
14135 struct peer *peer;
14136 int find = 0;
14137 safi_t safi = SAFI_UNICAST;
14138 json_object *json = NULL;
14139 json_object *json_neighbor = NULL;
14140
14141 if (use_json) {
14142 json = json_object_new_object();
14143 json_neighbor = json_object_new_object();
14144 }
14145
14146 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14147
14148 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14149 continue;
14150
14151 if ((peer->afc[afi][safi]) == 0)
14152 continue;
14153
14154 if (type == show_all) {
14155 bgp_show_peer_gr_status(vty, peer, use_json,
14156 json_neighbor);
14157
14158 if (use_json) {
14159 json_object_object_add(json, peer->host,
14160 json_neighbor);
14161 json_neighbor = NULL;
14162 }
14163
14164 } else if (type == show_peer) {
14165 if (conf_if) {
14166 if ((peer->conf_if
14167 && !strcmp(peer->conf_if, conf_if))
14168 || (peer->hostname
14169 && !strcmp(peer->hostname, conf_if))) {
14170 find = 1;
14171 bgp_show_peer_gr_status(vty, peer,
14172 use_json,
14173 json_neighbor);
14174 }
14175 } else {
14176 if (sockunion_same(&peer->su, su)) {
14177 find = 1;
14178 bgp_show_peer_gr_status(vty, peer,
14179 use_json,
14180 json_neighbor);
14181 }
14182 }
14183 if (use_json && find)
14184 json_object_object_add(json, peer->host,
14185 json_neighbor);
14186 }
14187
14188 if (find) {
14189 json_neighbor = NULL;
14190 break;
14191 }
14192 }
14193
14194 if (type == show_peer && !find) {
14195 if (use_json)
14196 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14197 else
14198 vty_out(vty, "%% No such neighbor\n");
14199 }
14200 if (use_json) {
14201 if (json_neighbor)
14202 json_object_free(json_neighbor);
14203 vty_json(vty, json);
14204 } else {
14205 vty_out(vty, "\n");
14206 }
14207
14208 return CMD_SUCCESS;
14209 }
14210
14211 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14212 enum show_type type, union sockunion *su,
14213 const char *conf_if, bool use_json,
14214 json_object *json)
14215 {
14216 struct listnode *node, *nnode;
14217 struct peer *peer;
14218 int find = 0;
14219 bool nbr_output = false;
14220 afi_t afi = AFI_MAX;
14221 safi_t safi = SAFI_MAX;
14222
14223 if (type == show_ipv4_peer || type == show_ipv4_all) {
14224 afi = AFI_IP;
14225 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14226 afi = AFI_IP6;
14227 }
14228
14229 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14230 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14231 continue;
14232
14233 switch (type) {
14234 case show_all:
14235 bgp_show_peer(vty, peer, use_json, json);
14236 nbr_output = true;
14237 break;
14238 case show_peer:
14239 if (conf_if) {
14240 if ((peer->conf_if
14241 && !strcmp(peer->conf_if, conf_if))
14242 || (peer->hostname
14243 && !strcmp(peer->hostname, conf_if))) {
14244 find = 1;
14245 bgp_show_peer(vty, peer, use_json,
14246 json);
14247 }
14248 } else {
14249 if (sockunion_same(&peer->su, su)) {
14250 find = 1;
14251 bgp_show_peer(vty, peer, use_json,
14252 json);
14253 }
14254 }
14255 break;
14256 case show_ipv4_peer:
14257 case show_ipv6_peer:
14258 FOREACH_SAFI (safi) {
14259 if (peer->afc[afi][safi]) {
14260 if (conf_if) {
14261 if ((peer->conf_if
14262 && !strcmp(peer->conf_if, conf_if))
14263 || (peer->hostname
14264 && !strcmp(peer->hostname, conf_if))) {
14265 find = 1;
14266 bgp_show_peer(vty, peer, use_json,
14267 json);
14268 break;
14269 }
14270 } else {
14271 if (sockunion_same(&peer->su, su)) {
14272 find = 1;
14273 bgp_show_peer(vty, peer, use_json,
14274 json);
14275 break;
14276 }
14277 }
14278 }
14279 }
14280 break;
14281 case show_ipv4_all:
14282 case show_ipv6_all:
14283 FOREACH_SAFI (safi) {
14284 if (peer->afc[afi][safi]) {
14285 bgp_show_peer(vty, peer, use_json, json);
14286 nbr_output = true;
14287 break;
14288 }
14289 }
14290 break;
14291 }
14292 }
14293
14294 if ((type == show_peer || type == show_ipv4_peer ||
14295 type == show_ipv6_peer) && !find) {
14296 if (use_json)
14297 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14298 else
14299 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14300 }
14301
14302 if (type != show_peer && type != show_ipv4_peer &&
14303 type != show_ipv6_peer && !nbr_output && !use_json)
14304 vty_out(vty, "%% No BGP neighbors found\n");
14305
14306 if (use_json) {
14307 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14308 json, JSON_C_TO_STRING_PRETTY));
14309 } else {
14310 vty_out(vty, "\n");
14311 }
14312
14313 return CMD_SUCCESS;
14314 }
14315
14316 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14317 enum show_type type,
14318 const char *ip_str,
14319 afi_t afi, bool use_json)
14320 {
14321
14322 int ret;
14323 struct bgp *bgp;
14324 union sockunion su;
14325
14326 bgp = bgp_get_default();
14327
14328 if (!bgp)
14329 return;
14330
14331 if (!use_json)
14332 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14333 NULL);
14334
14335 if (ip_str) {
14336 ret = str2sockunion(ip_str, &su);
14337 if (ret < 0)
14338 bgp_show_neighbor_graceful_restart(
14339 vty, bgp, type, NULL, ip_str, afi, use_json);
14340 else
14341 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14342 NULL, afi, use_json);
14343 } else
14344 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14345 afi, use_json);
14346 }
14347
14348 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14349 enum show_type type,
14350 const char *ip_str,
14351 bool use_json)
14352 {
14353 struct listnode *node, *nnode;
14354 struct bgp *bgp;
14355 union sockunion su;
14356 json_object *json = NULL;
14357 int ret, is_first = 1;
14358 bool nbr_output = false;
14359
14360 if (use_json)
14361 vty_out(vty, "{\n");
14362
14363 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14364 nbr_output = true;
14365 if (use_json) {
14366 if (!(json = json_object_new_object())) {
14367 flog_err(
14368 EC_BGP_JSON_MEM_ERROR,
14369 "Unable to allocate memory for JSON object");
14370 vty_out(vty,
14371 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14372 return;
14373 }
14374
14375 json_object_int_add(json, "vrfId",
14376 (bgp->vrf_id == VRF_UNKNOWN)
14377 ? -1
14378 : (int64_t)bgp->vrf_id);
14379 json_object_string_add(
14380 json, "vrfName",
14381 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14382 ? VRF_DEFAULT_NAME
14383 : bgp->name);
14384
14385 if (!is_first)
14386 vty_out(vty, ",\n");
14387 else
14388 is_first = 0;
14389
14390 vty_out(vty, "\"%s\":",
14391 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14392 ? VRF_DEFAULT_NAME
14393 : bgp->name);
14394 } else {
14395 vty_out(vty, "\nInstance %s:\n",
14396 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14397 ? VRF_DEFAULT_NAME
14398 : bgp->name);
14399 }
14400
14401 if (type == show_peer || type == show_ipv4_peer ||
14402 type == show_ipv6_peer) {
14403 ret = str2sockunion(ip_str, &su);
14404 if (ret < 0)
14405 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14406 use_json, json);
14407 else
14408 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14409 use_json, json);
14410 } else {
14411 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14412 use_json, json);
14413 }
14414 json_object_free(json);
14415 json = NULL;
14416 }
14417
14418 if (use_json)
14419 vty_out(vty, "}\n");
14420 else if (!nbr_output)
14421 vty_out(vty, "%% BGP instance not found\n");
14422 }
14423
14424 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14425 enum show_type type, const char *ip_str,
14426 bool use_json)
14427 {
14428 int ret;
14429 struct bgp *bgp;
14430 union sockunion su;
14431 json_object *json = NULL;
14432
14433 if (name) {
14434 if (strmatch(name, "all")) {
14435 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14436 use_json);
14437 return CMD_SUCCESS;
14438 } else {
14439 bgp = bgp_lookup_by_name(name);
14440 if (!bgp) {
14441 if (use_json) {
14442 json = json_object_new_object();
14443 vty_json(vty, json);
14444 } else
14445 vty_out(vty,
14446 "%% BGP instance not found\n");
14447
14448 return CMD_WARNING;
14449 }
14450 }
14451 } else {
14452 bgp = bgp_get_default();
14453 }
14454
14455 if (bgp) {
14456 json = json_object_new_object();
14457 if (ip_str) {
14458 ret = str2sockunion(ip_str, &su);
14459 if (ret < 0)
14460 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14461 use_json, json);
14462 else
14463 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14464 use_json, json);
14465 } else {
14466 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14467 json);
14468 }
14469 json_object_free(json);
14470 } else {
14471 if (use_json)
14472 vty_out(vty, "{}\n");
14473 else
14474 vty_out(vty, "%% BGP instance not found\n");
14475 }
14476
14477 return CMD_SUCCESS;
14478 }
14479
14480
14481
14482 /* "show [ip] bgp neighbors graceful-restart" commands. */
14483 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14484 show_ip_bgp_neighbors_graceful_restart_cmd,
14485 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14486 SHOW_STR
14487 BGP_STR
14488 IP_STR
14489 IPV6_STR
14490 NEIGHBOR_STR
14491 "Neighbor to display information about\n"
14492 "Neighbor to display information about\n"
14493 "Neighbor on BGP configured interface\n"
14494 GR_SHOW
14495 JSON_STR)
14496 {
14497 char *sh_arg = NULL;
14498 enum show_type sh_type;
14499 int idx = 0;
14500 afi_t afi = AFI_MAX;
14501 bool uj = use_json(argc, argv);
14502
14503 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14504 afi = AFI_MAX;
14505
14506 idx++;
14507
14508 if (argv_find(argv, argc, "A.B.C.D", &idx)
14509 || argv_find(argv, argc, "X:X::X:X", &idx)
14510 || argv_find(argv, argc, "WORD", &idx)) {
14511 sh_type = show_peer;
14512 sh_arg = argv[idx]->arg;
14513 } else
14514 sh_type = show_all;
14515
14516 if (!argv_find(argv, argc, "graceful-restart", &idx))
14517 return CMD_SUCCESS;
14518
14519
14520 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14521 afi, uj);
14522 }
14523
14524 /* "show [ip] bgp neighbors" commands. */
14525 DEFUN (show_ip_bgp_neighbors,
14526 show_ip_bgp_neighbors_cmd,
14527 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14528 SHOW_STR
14529 IP_STR
14530 BGP_STR
14531 BGP_INSTANCE_HELP_STR
14532 "Address Family\n"
14533 "Address Family\n"
14534 "Detailed information on TCP and BGP neighbor connections\n"
14535 "Neighbor to display information about\n"
14536 "Neighbor to display information about\n"
14537 "Neighbor on BGP configured interface\n"
14538 JSON_STR)
14539 {
14540 char *vrf = NULL;
14541 char *sh_arg = NULL;
14542 enum show_type sh_type;
14543 afi_t afi = AFI_MAX;
14544
14545 bool uj = use_json(argc, argv);
14546
14547 int idx = 0;
14548
14549 /* [<vrf> VIEWVRFNAME] */
14550 if (argv_find(argv, argc, "vrf", &idx)) {
14551 vrf = argv[idx + 1]->arg;
14552 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14553 vrf = NULL;
14554 } else if (argv_find(argv, argc, "view", &idx))
14555 /* [<view> VIEWVRFNAME] */
14556 vrf = argv[idx + 1]->arg;
14557
14558 idx++;
14559
14560 if (argv_find(argv, argc, "ipv4", &idx)) {
14561 sh_type = show_ipv4_all;
14562 afi = AFI_IP;
14563 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14564 sh_type = show_ipv6_all;
14565 afi = AFI_IP6;
14566 } else {
14567 sh_type = show_all;
14568 }
14569
14570 if (argv_find(argv, argc, "A.B.C.D", &idx)
14571 || argv_find(argv, argc, "X:X::X:X", &idx)
14572 || argv_find(argv, argc, "WORD", &idx)) {
14573 sh_type = show_peer;
14574 sh_arg = argv[idx]->arg;
14575 }
14576
14577 if (sh_type == show_peer && afi == AFI_IP) {
14578 sh_type = show_ipv4_peer;
14579 } else if (sh_type == show_peer && afi == AFI_IP6) {
14580 sh_type = show_ipv6_peer;
14581 }
14582
14583 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14584 }
14585
14586 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14587 paths' and `show ip mbgp paths'. Those functions results are the
14588 same.*/
14589 DEFUN (show_ip_bgp_paths,
14590 show_ip_bgp_paths_cmd,
14591 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14592 SHOW_STR
14593 IP_STR
14594 BGP_STR
14595 BGP_SAFI_HELP_STR
14596 "Path information\n")
14597 {
14598 vty_out(vty, "Address Refcnt Path\n");
14599 aspath_print_all_vty(vty);
14600 return CMD_SUCCESS;
14601 }
14602
14603 #include "hash.h"
14604
14605 static void community_show_all_iterator(struct hash_bucket *bucket,
14606 struct vty *vty)
14607 {
14608 struct community *com;
14609
14610 com = (struct community *)bucket->data;
14611 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14612 community_str(com, false, false));
14613 }
14614
14615 /* Show BGP's community internal data. */
14616 DEFUN (show_ip_bgp_community_info,
14617 show_ip_bgp_community_info_cmd,
14618 "show [ip] bgp community-info",
14619 SHOW_STR
14620 IP_STR
14621 BGP_STR
14622 "List all bgp community information\n")
14623 {
14624 vty_out(vty, "Address Refcnt Community\n");
14625
14626 hash_iterate(community_hash(),
14627 (void (*)(struct hash_bucket *,
14628 void *))community_show_all_iterator,
14629 vty);
14630
14631 return CMD_SUCCESS;
14632 }
14633
14634 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14635 struct vty *vty)
14636 {
14637 struct lcommunity *lcom;
14638
14639 lcom = (struct lcommunity *)bucket->data;
14640 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14641 lcommunity_str(lcom, false, false));
14642 }
14643
14644 /* Show BGP's community internal data. */
14645 DEFUN (show_ip_bgp_lcommunity_info,
14646 show_ip_bgp_lcommunity_info_cmd,
14647 "show ip bgp large-community-info",
14648 SHOW_STR
14649 IP_STR
14650 BGP_STR
14651 "List all bgp large-community information\n")
14652 {
14653 vty_out(vty, "Address Refcnt Large-community\n");
14654
14655 hash_iterate(lcommunity_hash(),
14656 (void (*)(struct hash_bucket *,
14657 void *))lcommunity_show_all_iterator,
14658 vty);
14659
14660 return CMD_SUCCESS;
14661 }
14662 /* Graceful Restart */
14663
14664 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14665 struct bgp *bgp,
14666 bool use_json,
14667 json_object *json)
14668 {
14669
14670
14671 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14672
14673 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14674
14675 switch (bgp_global_gr_mode) {
14676
14677 case GLOBAL_HELPER:
14678 vty_out(vty, "Global BGP GR Mode : Helper\n");
14679 break;
14680
14681 case GLOBAL_GR:
14682 vty_out(vty, "Global BGP GR Mode : Restart\n");
14683 break;
14684
14685 case GLOBAL_DISABLE:
14686 vty_out(vty, "Global BGP GR Mode : Disable\n");
14687 break;
14688
14689 case GLOBAL_INVALID:
14690 vty_out(vty,
14691 "Global BGP GR Mode Invalid\n");
14692 break;
14693 }
14694 vty_out(vty, "\n");
14695 }
14696
14697 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14698 enum show_type type,
14699 const char *ip_str,
14700 afi_t afi, bool use_json)
14701 {
14702 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14703 afi = AFI_IP;
14704
14705 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14706
14707 bgp_show_neighbor_graceful_restart_vty(
14708 vty, type, ip_str, afi, use_json);
14709 afi++;
14710 }
14711 } else if (afi != AFI_MAX) {
14712 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14713 use_json);
14714 } else {
14715 return CMD_ERR_INCOMPLETE;
14716 }
14717
14718 return CMD_SUCCESS;
14719 }
14720 /* Graceful Restart */
14721
14722 DEFUN (show_ip_bgp_attr_info,
14723 show_ip_bgp_attr_info_cmd,
14724 "show [ip] bgp attribute-info",
14725 SHOW_STR
14726 IP_STR
14727 BGP_STR
14728 "List all bgp attribute information\n")
14729 {
14730 attr_show_all(vty);
14731 return CMD_SUCCESS;
14732 }
14733
14734 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14735 afi_t afi, safi_t safi,
14736 bool use_json, json_object *json)
14737 {
14738 struct bgp *bgp;
14739 struct listnode *node;
14740 char *vname;
14741 char buf1[INET6_ADDRSTRLEN];
14742 char *ecom_str;
14743 enum vpn_policy_direction dir;
14744
14745 if (json) {
14746 json_object *json_import_vrfs = NULL;
14747 json_object *json_export_vrfs = NULL;
14748
14749 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14750
14751 if (!bgp) {
14752 vty_json(vty, json);
14753
14754 return CMD_WARNING;
14755 }
14756
14757 /* Provide context for the block */
14758 json_object_string_add(json, "vrf", name ? name : "default");
14759 json_object_string_add(json, "afiSafi",
14760 get_afi_safi_str(afi, safi, true));
14761
14762 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14763 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14764 json_object_string_add(json, "importFromVrfs", "none");
14765 json_object_string_add(json, "importRts", "none");
14766 } else {
14767 json_import_vrfs = json_object_new_array();
14768
14769 for (ALL_LIST_ELEMENTS_RO(
14770 bgp->vpn_policy[afi].import_vrf,
14771 node, vname))
14772 json_object_array_add(json_import_vrfs,
14773 json_object_new_string(vname));
14774
14775 json_object_object_add(json, "importFromVrfs",
14776 json_import_vrfs);
14777 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14778 if (bgp->vpn_policy[afi].rtlist[dir]) {
14779 ecom_str = ecommunity_ecom2str(
14780 bgp->vpn_policy[afi].rtlist[dir],
14781 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14782 json_object_string_add(json, "importRts",
14783 ecom_str);
14784 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14785 } else
14786 json_object_string_add(json, "importRts",
14787 "none");
14788 }
14789
14790 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14791 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14792 json_object_string_add(json, "exportToVrfs", "none");
14793 json_object_string_add(json, "routeDistinguisher",
14794 "none");
14795 json_object_string_add(json, "exportRts", "none");
14796 } else {
14797 json_export_vrfs = json_object_new_array();
14798
14799 for (ALL_LIST_ELEMENTS_RO(
14800 bgp->vpn_policy[afi].export_vrf,
14801 node, vname))
14802 json_object_array_add(json_export_vrfs,
14803 json_object_new_string(vname));
14804 json_object_object_add(json, "exportToVrfs",
14805 json_export_vrfs);
14806 json_object_string_add(json, "routeDistinguisher",
14807 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14808 buf1, RD_ADDRSTRLEN));
14809
14810 dir = BGP_VPN_POLICY_DIR_TOVPN;
14811 if (bgp->vpn_policy[afi].rtlist[dir]) {
14812 ecom_str = ecommunity_ecom2str(
14813 bgp->vpn_policy[afi].rtlist[dir],
14814 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14815 json_object_string_add(json, "exportRts",
14816 ecom_str);
14817 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14818 } else
14819 json_object_string_add(json, "exportRts",
14820 "none");
14821 }
14822
14823 if (use_json) {
14824 vty_json(vty, json);
14825 }
14826 } else {
14827 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14828
14829 if (!bgp) {
14830 vty_out(vty, "%% No such BGP instance exist\n");
14831 return CMD_WARNING;
14832 }
14833
14834 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14835 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14836 vty_out(vty,
14837 "This VRF is not importing %s routes from any other VRF\n",
14838 get_afi_safi_str(afi, safi, false));
14839 else {
14840 vty_out(vty,
14841 "This VRF is importing %s routes from the following VRFs:\n",
14842 get_afi_safi_str(afi, safi, false));
14843
14844 for (ALL_LIST_ELEMENTS_RO(
14845 bgp->vpn_policy[afi].import_vrf,
14846 node, vname))
14847 vty_out(vty, " %s\n", vname);
14848
14849 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14850 ecom_str = NULL;
14851 if (bgp->vpn_policy[afi].rtlist[dir]) {
14852 ecom_str = ecommunity_ecom2str(
14853 bgp->vpn_policy[afi].rtlist[dir],
14854 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14855 vty_out(vty, "Import RT(s): %s\n", ecom_str);
14856
14857 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14858 } else
14859 vty_out(vty, "Import RT(s):\n");
14860 }
14861
14862 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14863 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14864 vty_out(vty,
14865 "This VRF is not exporting %s routes to any other VRF\n",
14866 get_afi_safi_str(afi, safi, false));
14867 else {
14868 vty_out(vty,
14869 "This VRF is exporting %s routes to the following VRFs:\n",
14870 get_afi_safi_str(afi, safi, false));
14871
14872 for (ALL_LIST_ELEMENTS_RO(
14873 bgp->vpn_policy[afi].export_vrf,
14874 node, vname))
14875 vty_out(vty, " %s\n", vname);
14876
14877 vty_out(vty, "RD: %s\n",
14878 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14879 buf1, RD_ADDRSTRLEN));
14880
14881 dir = BGP_VPN_POLICY_DIR_TOVPN;
14882 if (bgp->vpn_policy[afi].rtlist[dir]) {
14883 ecom_str = ecommunity_ecom2str(
14884 bgp->vpn_policy[afi].rtlist[dir],
14885 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14886 vty_out(vty, "Export RT: %s\n", ecom_str);
14887 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14888 } else
14889 vty_out(vty, "Import RT(s):\n");
14890 }
14891 }
14892
14893 return CMD_SUCCESS;
14894 }
14895
14896 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14897 safi_t safi, bool use_json)
14898 {
14899 struct listnode *node, *nnode;
14900 struct bgp *bgp;
14901 char *vrf_name = NULL;
14902 json_object *json = NULL;
14903 json_object *json_vrf = NULL;
14904 json_object *json_vrfs = NULL;
14905
14906 if (use_json) {
14907 json = json_object_new_object();
14908 json_vrfs = json_object_new_object();
14909 }
14910
14911 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14912
14913 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14914 vrf_name = bgp->name;
14915
14916 if (use_json) {
14917 json_vrf = json_object_new_object();
14918 } else {
14919 vty_out(vty, "\nInstance %s:\n",
14920 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14921 ? VRF_DEFAULT_NAME : bgp->name);
14922 }
14923 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14924 if (use_json) {
14925 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14926 json_object_object_add(json_vrfs,
14927 VRF_DEFAULT_NAME, json_vrf);
14928 else
14929 json_object_object_add(json_vrfs, vrf_name,
14930 json_vrf);
14931 }
14932 }
14933
14934 if (use_json) {
14935 json_object_object_add(json, "vrfs", json_vrfs);
14936 vty_json(vty, json);
14937 }
14938
14939 return CMD_SUCCESS;
14940 }
14941
14942 /* "show [ip] bgp route-leak" command. */
14943 DEFUN (show_ip_bgp_route_leak,
14944 show_ip_bgp_route_leak_cmd,
14945 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
14946 SHOW_STR
14947 IP_STR
14948 BGP_STR
14949 BGP_INSTANCE_HELP_STR
14950 BGP_AFI_HELP_STR
14951 BGP_SAFI_HELP_STR
14952 "Route leaking information\n"
14953 JSON_STR)
14954 {
14955 char *vrf = NULL;
14956 afi_t afi = AFI_MAX;
14957 safi_t safi = SAFI_MAX;
14958
14959 bool uj = use_json(argc, argv);
14960 int idx = 0;
14961 json_object *json = NULL;
14962
14963 /* show [ip] bgp */
14964 if (argv_find(argv, argc, "ip", &idx)) {
14965 afi = AFI_IP;
14966 safi = SAFI_UNICAST;
14967 }
14968 /* [vrf VIEWVRFNAME] */
14969 if (argv_find(argv, argc, "view", &idx)) {
14970 vty_out(vty,
14971 "%% This command is not applicable to BGP views\n");
14972 return CMD_WARNING;
14973 }
14974
14975 if (argv_find(argv, argc, "vrf", &idx)) {
14976 vrf = argv[idx + 1]->arg;
14977 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14978 vrf = NULL;
14979 }
14980 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14981 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
14982 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14983
14984 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
14985 vty_out(vty,
14986 "%% This command is applicable only for unicast ipv4|ipv6\n");
14987 return CMD_WARNING;
14988 }
14989
14990 if (vrf && strmatch(vrf, "all"))
14991 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14992
14993 if (uj)
14994 json = json_object_new_object();
14995
14996 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
14997 }
14998
14999 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15000 safi_t safi)
15001 {
15002 struct listnode *node, *nnode;
15003 struct bgp *bgp;
15004
15005 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15006 vty_out(vty, "\nInstance %s:\n",
15007 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15008 ? VRF_DEFAULT_NAME
15009 : bgp->name);
15010 update_group_show(bgp, afi, safi, vty, 0);
15011 }
15012 }
15013
15014 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15015 int safi, uint64_t subgrp_id)
15016 {
15017 struct bgp *bgp;
15018
15019 if (name) {
15020 if (strmatch(name, "all")) {
15021 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15022 return CMD_SUCCESS;
15023 } else {
15024 bgp = bgp_lookup_by_name(name);
15025 }
15026 } else {
15027 bgp = bgp_get_default();
15028 }
15029
15030 if (bgp)
15031 update_group_show(bgp, afi, safi, vty, subgrp_id);
15032 return CMD_SUCCESS;
15033 }
15034
15035 DEFUN (show_ip_bgp_updgrps,
15036 show_ip_bgp_updgrps_cmd,
15037 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15038 SHOW_STR
15039 IP_STR
15040 BGP_STR
15041 BGP_INSTANCE_HELP_STR
15042 BGP_AFI_HELP_STR
15043 BGP_SAFI_WITH_LABEL_HELP_STR
15044 "Detailed info about dynamic update groups\n"
15045 "Specific subgroup to display detailed info for\n")
15046 {
15047 char *vrf = NULL;
15048 afi_t afi = AFI_IP6;
15049 safi_t safi = SAFI_UNICAST;
15050 uint64_t subgrp_id = 0;
15051
15052 int idx = 0;
15053
15054 /* show [ip] bgp */
15055 if (argv_find(argv, argc, "ip", &idx))
15056 afi = AFI_IP;
15057 /* [<vrf> VIEWVRFNAME] */
15058 if (argv_find(argv, argc, "vrf", &idx)) {
15059 vrf = argv[idx + 1]->arg;
15060 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15061 vrf = NULL;
15062 } else if (argv_find(argv, argc, "view", &idx))
15063 /* [<view> VIEWVRFNAME] */
15064 vrf = argv[idx + 1]->arg;
15065 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15066 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15067 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15068 }
15069
15070 /* get subgroup id, if provided */
15071 idx = argc - 1;
15072 if (argv[idx]->type == VARIABLE_TKN)
15073 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15074
15075 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15076 }
15077
15078 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15079 show_bgp_instance_all_ipv6_updgrps_cmd,
15080 "show [ip] bgp <view|vrf> all update-groups",
15081 SHOW_STR
15082 IP_STR
15083 BGP_STR
15084 BGP_INSTANCE_ALL_HELP_STR
15085 "Detailed info about dynamic update groups\n")
15086 {
15087 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15088 return CMD_SUCCESS;
15089 }
15090
15091 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15092 show_bgp_l2vpn_evpn_updgrps_cmd,
15093 "show [ip] bgp l2vpn evpn update-groups",
15094 SHOW_STR
15095 IP_STR
15096 BGP_STR
15097 "l2vpn address family\n"
15098 "evpn sub-address family\n"
15099 "Detailed info about dynamic update groups\n")
15100 {
15101 char *vrf = NULL;
15102 uint64_t subgrp_id = 0;
15103
15104 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15105 return CMD_SUCCESS;
15106 }
15107
15108 DEFUN (show_bgp_updgrps_stats,
15109 show_bgp_updgrps_stats_cmd,
15110 "show [ip] bgp update-groups statistics",
15111 SHOW_STR
15112 IP_STR
15113 BGP_STR
15114 "Detailed info about dynamic update groups\n"
15115 "Statistics\n")
15116 {
15117 struct bgp *bgp;
15118
15119 bgp = bgp_get_default();
15120 if (bgp)
15121 update_group_show_stats(bgp, vty);
15122
15123 return CMD_SUCCESS;
15124 }
15125
15126 DEFUN (show_bgp_instance_updgrps_stats,
15127 show_bgp_instance_updgrps_stats_cmd,
15128 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15129 SHOW_STR
15130 IP_STR
15131 BGP_STR
15132 BGP_INSTANCE_HELP_STR
15133 "Detailed info about dynamic update groups\n"
15134 "Statistics\n")
15135 {
15136 int idx_word = 3;
15137 struct bgp *bgp;
15138
15139 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15140 if (bgp)
15141 update_group_show_stats(bgp, vty);
15142
15143 return CMD_SUCCESS;
15144 }
15145
15146 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15147 afi_t afi, safi_t safi,
15148 const char *what, uint64_t subgrp_id)
15149 {
15150 struct bgp *bgp;
15151
15152 if (name)
15153 bgp = bgp_lookup_by_name(name);
15154 else
15155 bgp = bgp_get_default();
15156
15157 if (bgp) {
15158 if (!strcmp(what, "advertise-queue"))
15159 update_group_show_adj_queue(bgp, afi, safi, vty,
15160 subgrp_id);
15161 else if (!strcmp(what, "advertised-routes"))
15162 update_group_show_advertised(bgp, afi, safi, vty,
15163 subgrp_id);
15164 else if (!strcmp(what, "packet-queue"))
15165 update_group_show_packet_queue(bgp, afi, safi, vty,
15166 subgrp_id);
15167 }
15168 }
15169
15170 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15171 show_ip_bgp_instance_updgrps_adj_s_cmd,
15172 "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",
15173 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15174 BGP_SAFI_HELP_STR
15175 "Detailed info about dynamic update groups\n"
15176 "Specific subgroup to display info for\n"
15177 "Advertisement queue\n"
15178 "Announced routes\n"
15179 "Packet queue\n")
15180 {
15181 uint64_t subgrp_id = 0;
15182 afi_t afiz;
15183 safi_t safiz;
15184 if (sgid)
15185 subgrp_id = strtoull(sgid, NULL, 10);
15186
15187 if (!ip && !afi)
15188 afiz = AFI_IP6;
15189 if (!ip && afi)
15190 afiz = bgp_vty_afi_from_str(afi);
15191 if (ip && !afi)
15192 afiz = AFI_IP;
15193 if (ip && afi) {
15194 afiz = bgp_vty_afi_from_str(afi);
15195 if (afiz != AFI_IP)
15196 vty_out(vty,
15197 "%% Cannot specify both 'ip' and 'ipv6'\n");
15198 return CMD_WARNING;
15199 }
15200
15201 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15202
15203 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15204 return CMD_SUCCESS;
15205 }
15206
15207 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15208 json_object *json)
15209 {
15210 struct listnode *node, *nnode;
15211 struct prefix *range;
15212 struct peer *conf;
15213 struct peer *peer;
15214 afi_t afi;
15215 safi_t safi;
15216 const char *peer_status;
15217 int lr_count;
15218 int dynamic;
15219 bool af_cfgd;
15220 json_object *json_peer_group = NULL;
15221 json_object *json_peer_group_afc = NULL;
15222 json_object *json_peer_group_members = NULL;
15223 json_object *json_peer_group_dynamic = NULL;
15224 json_object *json_peer_group_dynamic_af = NULL;
15225 json_object *json_peer_group_ranges = NULL;
15226
15227 conf = group->conf;
15228
15229 if (json) {
15230 json_peer_group = json_object_new_object();
15231 json_peer_group_afc = json_object_new_array();
15232 }
15233
15234 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15235 if (json)
15236 json_object_int_add(json_peer_group, "remoteAs",
15237 conf->as);
15238 else
15239 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15240 group->name, conf->as);
15241 } else if (conf->as_type == AS_INTERNAL) {
15242 if (json)
15243 json_object_int_add(json_peer_group, "remoteAs",
15244 group->bgp->as);
15245 else
15246 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15247 group->name, group->bgp->as);
15248 } else {
15249 if (!json)
15250 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15251 }
15252
15253 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15254 if (json)
15255 json_object_string_add(json_peer_group, "type",
15256 "internal");
15257 else
15258 vty_out(vty, " Peer-group type is internal\n");
15259 } else {
15260 if (json)
15261 json_object_string_add(json_peer_group, "type",
15262 "external");
15263 else
15264 vty_out(vty, " Peer-group type is external\n");
15265 }
15266
15267 /* Display AFs configured. */
15268 if (!json)
15269 vty_out(vty, " Configured address-families:");
15270
15271 FOREACH_AFI_SAFI (afi, safi) {
15272 if (conf->afc[afi][safi]) {
15273 af_cfgd = true;
15274 if (json)
15275 json_object_array_add(
15276 json_peer_group_afc,
15277 json_object_new_string(get_afi_safi_str(
15278 afi, safi, false)));
15279 else
15280 vty_out(vty, " %s;",
15281 get_afi_safi_str(afi, safi, false));
15282 }
15283 }
15284
15285 if (json) {
15286 json_object_object_add(json_peer_group,
15287 "addressFamiliesConfigured",
15288 json_peer_group_afc);
15289 } else {
15290 if (!af_cfgd)
15291 vty_out(vty, " none\n");
15292 else
15293 vty_out(vty, "\n");
15294 }
15295
15296 /* Display listen ranges (for dynamic neighbors), if any */
15297 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15298 lr_count = listcount(group->listen_range[afi]);
15299 if (lr_count) {
15300 if (json) {
15301 if (!json_peer_group_dynamic)
15302 json_peer_group_dynamic =
15303 json_object_new_object();
15304
15305 json_peer_group_dynamic_af =
15306 json_object_new_object();
15307 json_peer_group_ranges =
15308 json_object_new_array();
15309 json_object_int_add(json_peer_group_dynamic_af,
15310 "count", lr_count);
15311 } else {
15312 vty_out(vty, " %d %s listen range(s)\n",
15313 lr_count, afi2str(afi));
15314 }
15315
15316 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15317 nnode, range)) {
15318 if (json) {
15319 char buf[BUFSIZ];
15320
15321 snprintfrr(buf, sizeof(buf), "%pFX",
15322 range);
15323
15324 json_object_array_add(
15325 json_peer_group_ranges,
15326 json_object_new_string(buf));
15327 } else {
15328 vty_out(vty, " %pFX\n", range);
15329 }
15330 }
15331
15332 if (json) {
15333 json_object_object_add(
15334 json_peer_group_dynamic_af, "ranges",
15335 json_peer_group_ranges);
15336
15337 json_object_object_add(
15338 json_peer_group_dynamic, afi2str(afi),
15339 json_peer_group_dynamic_af);
15340 }
15341 }
15342 }
15343
15344 if (json_peer_group_dynamic)
15345 json_object_object_add(json_peer_group, "dynamicRanges",
15346 json_peer_group_dynamic);
15347
15348 /* Display group members and their status */
15349 if (listcount(group->peer)) {
15350 if (json)
15351 json_peer_group_members = json_object_new_object();
15352 else
15353 vty_out(vty, " Peer-group members:\n");
15354 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15355 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15356 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15357 peer_status = "Idle (Admin)";
15358 else if (CHECK_FLAG(peer->sflags,
15359 PEER_STATUS_PREFIX_OVERFLOW))
15360 peer_status = "Idle (PfxCt)";
15361 else
15362 peer_status = lookup_msg(bgp_status_msg,
15363 peer->status, NULL);
15364
15365 dynamic = peer_dynamic_neighbor(peer);
15366
15367 if (json) {
15368 json_object *json_peer_group_member =
15369 json_object_new_object();
15370
15371 json_object_string_add(json_peer_group_member,
15372 "status", peer_status);
15373
15374 if (dynamic)
15375 json_object_boolean_true_add(
15376 json_peer_group_member,
15377 "dynamic");
15378
15379 json_object_object_add(json_peer_group_members,
15380 peer->host,
15381 json_peer_group_member);
15382 } else {
15383 vty_out(vty, " %s %s %s \n", peer->host,
15384 dynamic ? "(dynamic)" : "",
15385 peer_status);
15386 }
15387 }
15388 if (json)
15389 json_object_object_add(json_peer_group, "members",
15390 json_peer_group_members);
15391 }
15392
15393 if (json)
15394 json_object_object_add(json, group->name, json_peer_group);
15395
15396 return CMD_SUCCESS;
15397 }
15398
15399 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15400 const char *group_name, bool uj)
15401 {
15402 struct bgp *bgp;
15403 struct listnode *node, *nnode;
15404 struct peer_group *group;
15405 bool found = false;
15406 json_object *json = NULL;
15407
15408 if (uj)
15409 json = json_object_new_object();
15410
15411 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15412
15413 if (!bgp) {
15414 if (uj)
15415 vty_json(vty, json);
15416 else
15417 vty_out(vty, "%% BGP instance not found\n");
15418
15419 return CMD_WARNING;
15420 }
15421
15422 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15423 if (group_name) {
15424 if (strmatch(group->name, group_name)) {
15425 bgp_show_one_peer_group(vty, group, json);
15426 found = true;
15427 break;
15428 }
15429 } else {
15430 bgp_show_one_peer_group(vty, group, json);
15431 }
15432 }
15433
15434 if (group_name && !found && !uj)
15435 vty_out(vty, "%% No such peer-group\n");
15436
15437 if (uj)
15438 vty_json(vty, json);
15439
15440 return CMD_SUCCESS;
15441 }
15442
15443 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15444 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15445 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15446 "Detailed information on BGP peer groups\n"
15447 "Peer group name\n" JSON_STR)
15448 {
15449 char *vrf, *pg;
15450 int idx = 0;
15451 bool uj = use_json(argc, argv);
15452
15453 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15454 : NULL;
15455 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15456
15457 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15458 }
15459
15460
15461 /* Redistribute VTY commands. */
15462
15463 DEFUN (bgp_redistribute_ipv4,
15464 bgp_redistribute_ipv4_cmd,
15465 "redistribute " FRR_IP_REDIST_STR_BGPD,
15466 "Redistribute information from another routing protocol\n"
15467 FRR_IP_REDIST_HELP_STR_BGPD)
15468 {
15469 VTY_DECLVAR_CONTEXT(bgp, bgp);
15470 int idx_protocol = 1;
15471 int type;
15472
15473 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15474 if (type < 0) {
15475 vty_out(vty, "%% Invalid route type\n");
15476 return CMD_WARNING_CONFIG_FAILED;
15477 }
15478
15479 bgp_redist_add(bgp, AFI_IP, type, 0);
15480 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15481 }
15482
15483 ALIAS_HIDDEN(
15484 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15485 "redistribute " FRR_IP_REDIST_STR_BGPD,
15486 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15487
15488 DEFUN (bgp_redistribute_ipv4_rmap,
15489 bgp_redistribute_ipv4_rmap_cmd,
15490 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15491 "Redistribute information from another routing protocol\n"
15492 FRR_IP_REDIST_HELP_STR_BGPD
15493 "Route map reference\n"
15494 "Pointer to route-map entries\n")
15495 {
15496 VTY_DECLVAR_CONTEXT(bgp, bgp);
15497 int idx_protocol = 1;
15498 int idx_word = 3;
15499 int type;
15500 struct bgp_redist *red;
15501 bool changed;
15502 struct route_map *route_map = route_map_lookup_warn_noexist(
15503 vty, argv[idx_word]->arg);
15504
15505 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15506 if (type < 0) {
15507 vty_out(vty, "%% Invalid route type\n");
15508 return CMD_WARNING_CONFIG_FAILED;
15509 }
15510
15511 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15512 changed =
15513 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15514 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15515 }
15516
15517 ALIAS_HIDDEN(
15518 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15519 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15520 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15521 "Route map reference\n"
15522 "Pointer to route-map entries\n")
15523
15524 DEFUN (bgp_redistribute_ipv4_metric,
15525 bgp_redistribute_ipv4_metric_cmd,
15526 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15527 "Redistribute information from another routing protocol\n"
15528 FRR_IP_REDIST_HELP_STR_BGPD
15529 "Metric for redistributed routes\n"
15530 "Default metric\n")
15531 {
15532 VTY_DECLVAR_CONTEXT(bgp, bgp);
15533 int idx_protocol = 1;
15534 int idx_number = 3;
15535 int type;
15536 uint32_t metric;
15537 struct bgp_redist *red;
15538 bool changed;
15539
15540 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15541 if (type < 0) {
15542 vty_out(vty, "%% Invalid route type\n");
15543 return CMD_WARNING_CONFIG_FAILED;
15544 }
15545 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15546
15547 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15548 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15549 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15550 }
15551
15552 ALIAS_HIDDEN(
15553 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15554 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15555 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15556 "Metric for redistributed routes\n"
15557 "Default metric\n")
15558
15559 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15560 bgp_redistribute_ipv4_rmap_metric_cmd,
15561 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15562 "Redistribute information from another routing protocol\n"
15563 FRR_IP_REDIST_HELP_STR_BGPD
15564 "Route map reference\n"
15565 "Pointer to route-map entries\n"
15566 "Metric for redistributed routes\n"
15567 "Default metric\n")
15568 {
15569 VTY_DECLVAR_CONTEXT(bgp, bgp);
15570 int idx_protocol = 1;
15571 int idx_word = 3;
15572 int idx_number = 5;
15573 int type;
15574 uint32_t metric;
15575 struct bgp_redist *red;
15576 bool changed;
15577 struct route_map *route_map =
15578 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15579
15580 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15581 if (type < 0) {
15582 vty_out(vty, "%% Invalid route type\n");
15583 return CMD_WARNING_CONFIG_FAILED;
15584 }
15585 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15586
15587 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15588 changed =
15589 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15590 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15591 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15592 }
15593
15594 ALIAS_HIDDEN(
15595 bgp_redistribute_ipv4_rmap_metric,
15596 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15597 "redistribute " FRR_IP_REDIST_STR_BGPD
15598 " route-map RMAP_NAME metric (0-4294967295)",
15599 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15600 "Route map reference\n"
15601 "Pointer to route-map entries\n"
15602 "Metric for redistributed routes\n"
15603 "Default metric\n")
15604
15605 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15606 bgp_redistribute_ipv4_metric_rmap_cmd,
15607 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15608 "Redistribute information from another routing protocol\n"
15609 FRR_IP_REDIST_HELP_STR_BGPD
15610 "Metric for redistributed routes\n"
15611 "Default metric\n"
15612 "Route map reference\n"
15613 "Pointer to route-map entries\n")
15614 {
15615 VTY_DECLVAR_CONTEXT(bgp, bgp);
15616 int idx_protocol = 1;
15617 int idx_number = 3;
15618 int idx_word = 5;
15619 int type;
15620 uint32_t metric;
15621 struct bgp_redist *red;
15622 bool changed;
15623 struct route_map *route_map =
15624 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15625
15626 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15627 if (type < 0) {
15628 vty_out(vty, "%% Invalid route type\n");
15629 return CMD_WARNING_CONFIG_FAILED;
15630 }
15631 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15632
15633 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15634 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15635 changed |=
15636 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15637 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15638 }
15639
15640 ALIAS_HIDDEN(
15641 bgp_redistribute_ipv4_metric_rmap,
15642 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15643 "redistribute " FRR_IP_REDIST_STR_BGPD
15644 " metric (0-4294967295) route-map RMAP_NAME",
15645 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15646 "Metric for redistributed routes\n"
15647 "Default metric\n"
15648 "Route map reference\n"
15649 "Pointer to route-map entries\n")
15650
15651 DEFUN (bgp_redistribute_ipv4_ospf,
15652 bgp_redistribute_ipv4_ospf_cmd,
15653 "redistribute <ospf|table> (1-65535)",
15654 "Redistribute information from another routing protocol\n"
15655 "Open Shortest Path First (OSPFv2)\n"
15656 "Non-main Kernel Routing Table\n"
15657 "Instance ID/Table ID\n")
15658 {
15659 VTY_DECLVAR_CONTEXT(bgp, bgp);
15660 int idx_ospf_table = 1;
15661 int idx_number = 2;
15662 unsigned short instance;
15663 unsigned short protocol;
15664
15665 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15666
15667 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15668 protocol = ZEBRA_ROUTE_OSPF;
15669 else
15670 protocol = ZEBRA_ROUTE_TABLE;
15671
15672 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15673 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15674 }
15675
15676 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15677 "redistribute <ospf|table> (1-65535)",
15678 "Redistribute information from another routing protocol\n"
15679 "Open Shortest Path First (OSPFv2)\n"
15680 "Non-main Kernel Routing Table\n"
15681 "Instance ID/Table ID\n")
15682
15683 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15684 bgp_redistribute_ipv4_ospf_rmap_cmd,
15685 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15686 "Redistribute information from another routing protocol\n"
15687 "Open Shortest Path First (OSPFv2)\n"
15688 "Non-main Kernel Routing Table\n"
15689 "Instance ID/Table ID\n"
15690 "Route map reference\n"
15691 "Pointer to route-map entries\n")
15692 {
15693 VTY_DECLVAR_CONTEXT(bgp, bgp);
15694 int idx_ospf_table = 1;
15695 int idx_number = 2;
15696 int idx_word = 4;
15697 struct bgp_redist *red;
15698 unsigned short instance;
15699 int protocol;
15700 bool changed;
15701 struct route_map *route_map =
15702 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15703
15704 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15705 protocol = ZEBRA_ROUTE_OSPF;
15706 else
15707 protocol = ZEBRA_ROUTE_TABLE;
15708
15709 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15710 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15711 changed =
15712 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15713 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15714 }
15715
15716 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15717 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15718 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15719 "Redistribute information from another routing protocol\n"
15720 "Open Shortest Path First (OSPFv2)\n"
15721 "Non-main Kernel Routing Table\n"
15722 "Instance ID/Table ID\n"
15723 "Route map reference\n"
15724 "Pointer to route-map entries\n")
15725
15726 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15727 bgp_redistribute_ipv4_ospf_metric_cmd,
15728 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15729 "Redistribute information from another routing protocol\n"
15730 "Open Shortest Path First (OSPFv2)\n"
15731 "Non-main Kernel Routing Table\n"
15732 "Instance ID/Table ID\n"
15733 "Metric for redistributed routes\n"
15734 "Default metric\n")
15735 {
15736 VTY_DECLVAR_CONTEXT(bgp, bgp);
15737 int idx_ospf_table = 1;
15738 int idx_number = 2;
15739 int idx_number_2 = 4;
15740 uint32_t metric;
15741 struct bgp_redist *red;
15742 unsigned short instance;
15743 int protocol;
15744 bool changed;
15745
15746 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15747 protocol = ZEBRA_ROUTE_OSPF;
15748 else
15749 protocol = ZEBRA_ROUTE_TABLE;
15750
15751 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15752 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15753
15754 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15755 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15756 metric);
15757 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15758 }
15759
15760 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15761 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15762 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15763 "Redistribute information from another routing protocol\n"
15764 "Open Shortest Path First (OSPFv2)\n"
15765 "Non-main Kernel Routing Table\n"
15766 "Instance ID/Table ID\n"
15767 "Metric for redistributed routes\n"
15768 "Default metric\n")
15769
15770 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15771 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15772 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
15773 "Redistribute information from another routing protocol\n"
15774 "Open Shortest Path First (OSPFv2)\n"
15775 "Non-main Kernel Routing Table\n"
15776 "Instance ID/Table ID\n"
15777 "Route map reference\n"
15778 "Pointer to route-map entries\n"
15779 "Metric for redistributed routes\n"
15780 "Default metric\n")
15781 {
15782 VTY_DECLVAR_CONTEXT(bgp, bgp);
15783 int idx_ospf_table = 1;
15784 int idx_number = 2;
15785 int idx_word = 4;
15786 int idx_number_2 = 6;
15787 uint32_t metric;
15788 struct bgp_redist *red;
15789 unsigned short instance;
15790 int protocol;
15791 bool changed;
15792 struct route_map *route_map =
15793 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15794
15795 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15796 protocol = ZEBRA_ROUTE_OSPF;
15797 else
15798 protocol = ZEBRA_ROUTE_TABLE;
15799
15800 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15801 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15802
15803 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15804 changed =
15805 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15806 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15807 metric);
15808 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15809 }
15810
15811 ALIAS_HIDDEN(
15812 bgp_redistribute_ipv4_ospf_rmap_metric,
15813 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15814 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
15815 "Redistribute information from another routing protocol\n"
15816 "Open Shortest Path First (OSPFv2)\n"
15817 "Non-main Kernel Routing Table\n"
15818 "Instance ID/Table ID\n"
15819 "Route map reference\n"
15820 "Pointer to route-map entries\n"
15821 "Metric for redistributed routes\n"
15822 "Default metric\n")
15823
15824 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15825 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15826 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
15827 "Redistribute information from another routing protocol\n"
15828 "Open Shortest Path First (OSPFv2)\n"
15829 "Non-main Kernel Routing Table\n"
15830 "Instance ID/Table ID\n"
15831 "Metric for redistributed routes\n"
15832 "Default metric\n"
15833 "Route map reference\n"
15834 "Pointer to route-map entries\n")
15835 {
15836 VTY_DECLVAR_CONTEXT(bgp, bgp);
15837 int idx_ospf_table = 1;
15838 int idx_number = 2;
15839 int idx_number_2 = 4;
15840 int idx_word = 6;
15841 uint32_t metric;
15842 struct bgp_redist *red;
15843 unsigned short instance;
15844 int protocol;
15845 bool changed;
15846 struct route_map *route_map =
15847 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15848
15849 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15850 protocol = ZEBRA_ROUTE_OSPF;
15851 else
15852 protocol = ZEBRA_ROUTE_TABLE;
15853
15854 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15855 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15856
15857 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15858 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15859 metric);
15860 changed |=
15861 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15862 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15863 }
15864
15865 ALIAS_HIDDEN(
15866 bgp_redistribute_ipv4_ospf_metric_rmap,
15867 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15868 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
15869 "Redistribute information from another routing protocol\n"
15870 "Open Shortest Path First (OSPFv2)\n"
15871 "Non-main Kernel Routing Table\n"
15872 "Instance ID/Table ID\n"
15873 "Metric for redistributed routes\n"
15874 "Default metric\n"
15875 "Route map reference\n"
15876 "Pointer to route-map entries\n")
15877
15878 DEFUN (no_bgp_redistribute_ipv4_ospf,
15879 no_bgp_redistribute_ipv4_ospf_cmd,
15880 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
15881 NO_STR
15882 "Redistribute information from another routing protocol\n"
15883 "Open Shortest Path First (OSPFv2)\n"
15884 "Non-main Kernel Routing Table\n"
15885 "Instance ID/Table ID\n"
15886 "Metric for redistributed routes\n"
15887 "Default metric\n"
15888 "Route map reference\n"
15889 "Pointer to route-map entries\n")
15890 {
15891 VTY_DECLVAR_CONTEXT(bgp, bgp);
15892 int idx_ospf_table = 2;
15893 int idx_number = 3;
15894 unsigned short instance;
15895 int protocol;
15896
15897 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15898 protocol = ZEBRA_ROUTE_OSPF;
15899 else
15900 protocol = ZEBRA_ROUTE_TABLE;
15901
15902 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15903 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
15904 }
15905
15906 ALIAS_HIDDEN(
15907 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15908 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
15909 NO_STR
15910 "Redistribute information from another routing protocol\n"
15911 "Open Shortest Path First (OSPFv2)\n"
15912 "Non-main Kernel Routing Table\n"
15913 "Instance ID/Table ID\n"
15914 "Metric for redistributed routes\n"
15915 "Default metric\n"
15916 "Route map reference\n"
15917 "Pointer to route-map entries\n")
15918
15919 DEFUN (no_bgp_redistribute_ipv4,
15920 no_bgp_redistribute_ipv4_cmd,
15921 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
15922 NO_STR
15923 "Redistribute information from another routing protocol\n"
15924 FRR_IP_REDIST_HELP_STR_BGPD
15925 "Metric for redistributed routes\n"
15926 "Default metric\n"
15927 "Route map reference\n"
15928 "Pointer to route-map entries\n")
15929 {
15930 VTY_DECLVAR_CONTEXT(bgp, bgp);
15931 int idx_protocol = 2;
15932 int type;
15933
15934 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15935 if (type < 0) {
15936 vty_out(vty, "%% Invalid route type\n");
15937 return CMD_WARNING_CONFIG_FAILED;
15938 }
15939 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
15940 }
15941
15942 ALIAS_HIDDEN(
15943 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15944 "no redistribute " FRR_IP_REDIST_STR_BGPD
15945 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
15946 NO_STR
15947 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15948 "Metric for redistributed routes\n"
15949 "Default metric\n"
15950 "Route map reference\n"
15951 "Pointer to route-map entries\n")
15952
15953 DEFUN (bgp_redistribute_ipv6,
15954 bgp_redistribute_ipv6_cmd,
15955 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15956 "Redistribute information from another routing protocol\n"
15957 FRR_IP6_REDIST_HELP_STR_BGPD)
15958 {
15959 VTY_DECLVAR_CONTEXT(bgp, bgp);
15960 int idx_protocol = 1;
15961 int type;
15962
15963 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15964 if (type < 0) {
15965 vty_out(vty, "%% Invalid route type\n");
15966 return CMD_WARNING_CONFIG_FAILED;
15967 }
15968
15969 bgp_redist_add(bgp, AFI_IP6, type, 0);
15970 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
15971 }
15972
15973 DEFUN (bgp_redistribute_ipv6_rmap,
15974 bgp_redistribute_ipv6_rmap_cmd,
15975 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
15976 "Redistribute information from another routing protocol\n"
15977 FRR_IP6_REDIST_HELP_STR_BGPD
15978 "Route map reference\n"
15979 "Pointer to route-map entries\n")
15980 {
15981 VTY_DECLVAR_CONTEXT(bgp, bgp);
15982 int idx_protocol = 1;
15983 int idx_word = 3;
15984 int type;
15985 struct bgp_redist *red;
15986 bool changed;
15987 struct route_map *route_map =
15988 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15989
15990 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15991 if (type < 0) {
15992 vty_out(vty, "%% Invalid route type\n");
15993 return CMD_WARNING_CONFIG_FAILED;
15994 }
15995
15996 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15997 changed =
15998 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15999 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16000 }
16001
16002 DEFUN (bgp_redistribute_ipv6_metric,
16003 bgp_redistribute_ipv6_metric_cmd,
16004 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16005 "Redistribute information from another routing protocol\n"
16006 FRR_IP6_REDIST_HELP_STR_BGPD
16007 "Metric for redistributed routes\n"
16008 "Default metric\n")
16009 {
16010 VTY_DECLVAR_CONTEXT(bgp, bgp);
16011 int idx_protocol = 1;
16012 int idx_number = 3;
16013 int type;
16014 uint32_t metric;
16015 struct bgp_redist *red;
16016 bool changed;
16017
16018 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16019 if (type < 0) {
16020 vty_out(vty, "%% Invalid route type\n");
16021 return CMD_WARNING_CONFIG_FAILED;
16022 }
16023 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16024
16025 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16026 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16027 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16028 }
16029
16030 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16031 bgp_redistribute_ipv6_rmap_metric_cmd,
16032 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16033 "Redistribute information from another routing protocol\n"
16034 FRR_IP6_REDIST_HELP_STR_BGPD
16035 "Route map reference\n"
16036 "Pointer to route-map entries\n"
16037 "Metric for redistributed routes\n"
16038 "Default metric\n")
16039 {
16040 VTY_DECLVAR_CONTEXT(bgp, bgp);
16041 int idx_protocol = 1;
16042 int idx_word = 3;
16043 int idx_number = 5;
16044 int type;
16045 uint32_t metric;
16046 struct bgp_redist *red;
16047 bool changed;
16048 struct route_map *route_map =
16049 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16050
16051 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16052 if (type < 0) {
16053 vty_out(vty, "%% Invalid route type\n");
16054 return CMD_WARNING_CONFIG_FAILED;
16055 }
16056 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16057
16058 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16059 changed =
16060 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16061 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16062 metric);
16063 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16064 }
16065
16066 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16067 bgp_redistribute_ipv6_metric_rmap_cmd,
16068 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16069 "Redistribute information from another routing protocol\n"
16070 FRR_IP6_REDIST_HELP_STR_BGPD
16071 "Metric for redistributed routes\n"
16072 "Default metric\n"
16073 "Route map reference\n"
16074 "Pointer to route-map entries\n")
16075 {
16076 VTY_DECLVAR_CONTEXT(bgp, bgp);
16077 int idx_protocol = 1;
16078 int idx_number = 3;
16079 int idx_word = 5;
16080 int type;
16081 uint32_t metric;
16082 struct bgp_redist *red;
16083 bool changed;
16084 struct route_map *route_map =
16085 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16086
16087 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16088 if (type < 0) {
16089 vty_out(vty, "%% Invalid route type\n");
16090 return CMD_WARNING_CONFIG_FAILED;
16091 }
16092 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16093
16094 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16095 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16096 metric);
16097 changed |=
16098 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16099 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16100 }
16101
16102 DEFUN (no_bgp_redistribute_ipv6,
16103 no_bgp_redistribute_ipv6_cmd,
16104 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16105 NO_STR
16106 "Redistribute information from another routing protocol\n"
16107 FRR_IP6_REDIST_HELP_STR_BGPD
16108 "Metric for redistributed routes\n"
16109 "Default metric\n"
16110 "Route map reference\n"
16111 "Pointer to route-map entries\n")
16112 {
16113 VTY_DECLVAR_CONTEXT(bgp, bgp);
16114 int idx_protocol = 2;
16115 int type;
16116
16117 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16118 if (type < 0) {
16119 vty_out(vty, "%% Invalid route type\n");
16120 return CMD_WARNING_CONFIG_FAILED;
16121 }
16122
16123 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16124 }
16125
16126 /* Neighbor update tcp-mss. */
16127 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16128 const char *tcp_mss_str)
16129 {
16130 struct peer *peer;
16131 uint32_t tcp_mss_val = 0;
16132
16133 peer = peer_and_group_lookup_vty(vty, peer_str);
16134 if (!peer)
16135 return CMD_WARNING_CONFIG_FAILED;
16136
16137 if (tcp_mss_str) {
16138 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16139 peer_tcp_mss_set(peer, tcp_mss_val);
16140 } else {
16141 peer_tcp_mss_unset(peer);
16142 }
16143
16144 return CMD_SUCCESS;
16145 }
16146
16147 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16148 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16150 "TCP max segment size\n"
16151 "TCP MSS value\n")
16152 {
16153 int peer_index = 1;
16154 int mss_index = 3;
16155
16156 vty_out(vty,
16157 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16158 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16159 argv[mss_index]->arg);
16160 }
16161
16162 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16163 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16164 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16165 "TCP max segment size\n"
16166 "TCP MSS value\n")
16167 {
16168 int peer_index = 2;
16169
16170 vty_out(vty,
16171 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16172 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16173 }
16174
16175 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16176 afi_t afi, safi_t safi)
16177 {
16178 int i;
16179
16180 /* Unicast redistribution only. */
16181 if (safi != SAFI_UNICAST)
16182 return;
16183
16184 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16185 /* Redistribute BGP does not make sense. */
16186 if (i != ZEBRA_ROUTE_BGP) {
16187 struct list *red_list;
16188 struct listnode *node;
16189 struct bgp_redist *red;
16190
16191 red_list = bgp->redist[afi][i];
16192 if (!red_list)
16193 continue;
16194
16195 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16196 /* "redistribute" configuration. */
16197 vty_out(vty, " redistribute %s",
16198 zebra_route_string(i));
16199 if (red->instance)
16200 vty_out(vty, " %d", red->instance);
16201 if (red->redist_metric_flag)
16202 vty_out(vty, " metric %u",
16203 red->redist_metric);
16204 if (red->rmap.name)
16205 vty_out(vty, " route-map %s",
16206 red->rmap.name);
16207 vty_out(vty, "\n");
16208 }
16209 }
16210 }
16211 }
16212
16213 /* peer-group helpers for config-write */
16214
16215 static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16216 {
16217 if (!peer_group_active(peer)) {
16218 if (CHECK_FLAG(peer->flags_invert, flag))
16219 return !CHECK_FLAG(peer->flags, flag);
16220 else
16221 return !!CHECK_FLAG(peer->flags, flag);
16222 }
16223
16224 return !!CHECK_FLAG(peer->flags_override, flag);
16225 }
16226
16227 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16228 uint32_t flag)
16229 {
16230 if (!peer_group_active(peer)) {
16231 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16232 return !peer_af_flag_check(peer, afi, safi, flag);
16233 else
16234 return !!peer_af_flag_check(peer, afi, safi, flag);
16235 }
16236
16237 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16238 }
16239
16240 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16241 uint8_t type, int direct)
16242 {
16243 struct bgp_filter *filter;
16244
16245 if (peer_group_active(peer))
16246 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16247 type);
16248
16249 filter = &peer->filter[afi][safi];
16250 switch (type) {
16251 case PEER_FT_DISTRIBUTE_LIST:
16252 return !!(filter->dlist[direct].name);
16253 case PEER_FT_FILTER_LIST:
16254 return !!(filter->aslist[direct].name);
16255 case PEER_FT_PREFIX_LIST:
16256 return !!(filter->plist[direct].name);
16257 case PEER_FT_ROUTE_MAP:
16258 return !!(filter->map[direct].name);
16259 case PEER_FT_UNSUPPRESS_MAP:
16260 return !!(filter->usmap.name);
16261 case PEER_FT_ADVERTISE_MAP:
16262 return !!(filter->advmap.aname
16263 && ((filter->advmap.condition == direct)
16264 && filter->advmap.cname));
16265 default:
16266 return false;
16267 }
16268 }
16269
16270 /* Return true if the addpath type is set for peer and different from
16271 * peer-group.
16272 */
16273 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16274 safi_t safi)
16275 {
16276 enum bgp_addpath_strat type, g_type;
16277
16278 type = peer->addpath_type[afi][safi];
16279
16280 if (type != BGP_ADDPATH_NONE) {
16281 if (peer_group_active(peer)) {
16282 g_type = peer->group->conf->addpath_type[afi][safi];
16283
16284 if (type != g_type)
16285 return true;
16286 else
16287 return false;
16288 }
16289
16290 return true;
16291 }
16292
16293 return false;
16294 }
16295
16296 /* This is part of the address-family block (unicast only) */
16297 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16298 afi_t afi)
16299 {
16300 int indent = 2;
16301 uint32_t tovpn_sid_index = 0;
16302
16303 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16304 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16305 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16306 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16307 bgp->vpn_policy[afi]
16308 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16309 else
16310 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16311 bgp->vpn_policy[afi]
16312 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16313 }
16314 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16315 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16316 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16317 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16318 return;
16319
16320 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16321 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16322
16323 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16324
16325 } else {
16326 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16327 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16328 bgp->vpn_policy[afi].tovpn_label);
16329 }
16330 }
16331
16332 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16333 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16334 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16335 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16336 } else if (tovpn_sid_index != 0) {
16337 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16338 tovpn_sid_index);
16339 }
16340
16341 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16342 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16343 char buf[RD_ADDRSTRLEN];
16344 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16345 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16346 sizeof(buf)));
16347 }
16348 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16349 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16350
16351 char buf[PREFIX_STRLEN];
16352 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16353 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16354 sizeof(buf))) {
16355
16356 vty_out(vty, "%*snexthop vpn export %s\n",
16357 indent, "", buf);
16358 }
16359 }
16360 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16361 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16362 && ecommunity_cmp(
16363 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16364 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16365
16366 char *b = ecommunity_ecom2str(
16367 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16368 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16369 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16370 XFREE(MTYPE_ECOMMUNITY_STR, b);
16371 } else {
16372 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16373 char *b = ecommunity_ecom2str(
16374 bgp->vpn_policy[afi]
16375 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16376 ECOMMUNITY_FORMAT_ROUTE_MAP,
16377 ECOMMUNITY_ROUTE_TARGET);
16378 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16379 XFREE(MTYPE_ECOMMUNITY_STR, b);
16380 }
16381 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16382 char *b = ecommunity_ecom2str(
16383 bgp->vpn_policy[afi]
16384 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16385 ECOMMUNITY_FORMAT_ROUTE_MAP,
16386 ECOMMUNITY_ROUTE_TARGET);
16387 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16388 XFREE(MTYPE_ECOMMUNITY_STR, b);
16389 }
16390 }
16391
16392 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16393 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16394 bgp->vpn_policy[afi]
16395 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16396
16397 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16398 char *b = ecommunity_ecom2str(
16399 bgp->vpn_policy[afi]
16400 .import_redirect_rtlist,
16401 ECOMMUNITY_FORMAT_ROUTE_MAP,
16402 ECOMMUNITY_ROUTE_TARGET);
16403
16404 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16405 != ECOMMUNITY_SIZE)
16406 vty_out(vty, "%*srt6 redirect import %s\n",
16407 indent, "", b);
16408 else
16409 vty_out(vty, "%*srt redirect import %s\n",
16410 indent, "", b);
16411 XFREE(MTYPE_ECOMMUNITY_STR, b);
16412 }
16413 }
16414
16415 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16416 afi_t afi, safi_t safi)
16417 {
16418 struct bgp_filter *filter;
16419 char *addr;
16420
16421 addr = peer->host;
16422 filter = &peer->filter[afi][safi];
16423
16424 /* distribute-list. */
16425 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16426 FILTER_IN))
16427 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16428 filter->dlist[FILTER_IN].name);
16429
16430 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16431 FILTER_OUT))
16432 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16433 filter->dlist[FILTER_OUT].name);
16434
16435 /* prefix-list. */
16436 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16437 FILTER_IN))
16438 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16439 filter->plist[FILTER_IN].name);
16440
16441 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16442 FILTER_OUT))
16443 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16444 filter->plist[FILTER_OUT].name);
16445
16446 /* route-map. */
16447 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16448 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16449 filter->map[RMAP_IN].name);
16450
16451 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16452 RMAP_OUT))
16453 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16454 filter->map[RMAP_OUT].name);
16455
16456 /* unsuppress-map */
16457 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16458 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16459 filter->usmap.name);
16460
16461 /* advertise-map : always applied in OUT direction*/
16462 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16463 CONDITION_NON_EXIST))
16464 vty_out(vty,
16465 " neighbor %s advertise-map %s non-exist-map %s\n",
16466 addr, filter->advmap.aname, filter->advmap.cname);
16467
16468 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16469 CONDITION_EXIST))
16470 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16471 addr, filter->advmap.aname, filter->advmap.cname);
16472
16473 /* filter-list. */
16474 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16475 FILTER_IN))
16476 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16477 filter->aslist[FILTER_IN].name);
16478
16479 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16480 FILTER_OUT))
16481 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16482 filter->aslist[FILTER_OUT].name);
16483 }
16484
16485 /* BGP peer configuration display function. */
16486 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16487 struct peer *peer)
16488 {
16489 struct peer *g_peer = NULL;
16490 char *addr;
16491 int if_pg_printed = false;
16492 int if_ras_printed = false;
16493
16494 /* Skip dynamic neighbors. */
16495 if (peer_dynamic_neighbor(peer))
16496 return;
16497
16498 if (peer->conf_if)
16499 addr = peer->conf_if;
16500 else
16501 addr = peer->host;
16502
16503 /************************************
16504 ****** Global to the neighbor ******
16505 ************************************/
16506 if (peer->conf_if) {
16507 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16508 vty_out(vty, " neighbor %s interface v6only", addr);
16509 else
16510 vty_out(vty, " neighbor %s interface", addr);
16511
16512 if (peer_group_active(peer)) {
16513 vty_out(vty, " peer-group %s", peer->group->name);
16514 if_pg_printed = true;
16515 } else if (peer->as_type == AS_SPECIFIED) {
16516 vty_out(vty, " remote-as %u", peer->as);
16517 if_ras_printed = true;
16518 } else if (peer->as_type == AS_INTERNAL) {
16519 vty_out(vty, " remote-as internal");
16520 if_ras_printed = true;
16521 } else if (peer->as_type == AS_EXTERNAL) {
16522 vty_out(vty, " remote-as external");
16523 if_ras_printed = true;
16524 }
16525
16526 vty_out(vty, "\n");
16527 }
16528
16529 /* remote-as and peer-group */
16530 /* peer is a member of a peer-group */
16531 if (peer_group_active(peer)) {
16532 g_peer = peer->group->conf;
16533
16534 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16535 if (peer->as_type == AS_SPECIFIED) {
16536 vty_out(vty, " neighbor %s remote-as %u\n",
16537 addr, peer->as);
16538 } else if (peer->as_type == AS_INTERNAL) {
16539 vty_out(vty,
16540 " neighbor %s remote-as internal\n",
16541 addr);
16542 } else if (peer->as_type == AS_EXTERNAL) {
16543 vty_out(vty,
16544 " neighbor %s remote-as external\n",
16545 addr);
16546 }
16547 }
16548
16549 /* For swpX peers we displayed the peer-group
16550 * via 'neighbor swpX interface peer-group PGNAME' */
16551 if (!if_pg_printed)
16552 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16553 peer->group->name);
16554 }
16555
16556 /* peer is NOT a member of a peer-group */
16557 else {
16558 /* peer is a peer-group, declare the peer-group */
16559 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16560 vty_out(vty, " neighbor %s peer-group\n", addr);
16561 }
16562
16563 if (!if_ras_printed) {
16564 if (peer->as_type == AS_SPECIFIED) {
16565 vty_out(vty, " neighbor %s remote-as %u\n",
16566 addr, peer->as);
16567 } else if (peer->as_type == AS_INTERNAL) {
16568 vty_out(vty,
16569 " neighbor %s remote-as internal\n",
16570 addr);
16571 } else if (peer->as_type == AS_EXTERNAL) {
16572 vty_out(vty,
16573 " neighbor %s remote-as external\n",
16574 addr);
16575 }
16576 }
16577 }
16578
16579 /* local-as */
16580 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16581 vty_out(vty, " neighbor %s local-as %u", addr,
16582 peer->change_local_as);
16583 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16584 vty_out(vty, " no-prepend");
16585 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16586 vty_out(vty, " replace-as");
16587 vty_out(vty, "\n");
16588 }
16589
16590 /* description */
16591 if (peer->desc) {
16592 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16593 }
16594
16595 /* shutdown */
16596 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16597 if (peer->tx_shutdown_message)
16598 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16599 peer->tx_shutdown_message);
16600 else
16601 vty_out(vty, " neighbor %s shutdown\n", addr);
16602 }
16603
16604 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16605 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16606 peer->rtt_expected, peer->rtt_keepalive_conf);
16607
16608 /* bfd */
16609 if (peer->bfd_config)
16610 bgp_bfd_peer_config_write(vty, peer, addr);
16611
16612 /* password */
16613 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16614 vty_out(vty, " neighbor %s password %s\n", addr,
16615 peer->password);
16616
16617 /* neighbor solo */
16618 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16619 if (!peer_group_active(peer)) {
16620 vty_out(vty, " neighbor %s solo\n", addr);
16621 }
16622 }
16623
16624 /* BGP port */
16625 if (peer->port != BGP_PORT_DEFAULT) {
16626 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16627 }
16628
16629 /* Local interface name */
16630 if (peer->ifname) {
16631 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16632 }
16633
16634 /* TCP max segment size */
16635 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16636 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16637
16638 /* passive */
16639 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16640 vty_out(vty, " neighbor %s passive\n", addr);
16641
16642 /* ebgp-multihop */
16643 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16644 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16645 && peer->ttl == MAXTTL)) {
16646 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16647 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16648 peer->ttl);
16649 }
16650 }
16651
16652 /* ttl-security hops */
16653 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16654 if (!peer_group_active(peer)
16655 || g_peer->gtsm_hops != peer->gtsm_hops) {
16656 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16657 addr, peer->gtsm_hops);
16658 }
16659 }
16660
16661 /* disable-connected-check */
16662 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16663 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16664
16665 /* link-bw-encoding-ieee */
16666 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16667 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16668 addr);
16669
16670 /* extended-optional-parameters */
16671 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16672 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16673 addr);
16674
16675 /* enforce-first-as */
16676 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16677 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16678
16679 /* update-source */
16680 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16681 if (peer->update_source)
16682 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16683 peer->update_source);
16684 else if (peer->update_if)
16685 vty_out(vty, " neighbor %s update-source %s\n", addr,
16686 peer->update_if);
16687 }
16688
16689 /* advertisement-interval */
16690 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16691 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16692 peer->routeadv);
16693
16694 /* timers */
16695 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16696 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16697 peer->keepalive, peer->holdtime);
16698
16699 /* timers connect */
16700 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16701 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16702 peer->connect);
16703 /* need special-case handling for changed default values due to
16704 * config profile / version (because there is no "timers bgp connect"
16705 * command, we need to save this per-peer :/)
16706 */
16707 else if (!peer_group_active(peer) && !peer->connect &&
16708 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16709 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16710 peer->bgp->default_connect_retry);
16711
16712 /* timers delayopen */
16713 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16714 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16715 peer->delayopen);
16716 /* Save config even though flag is not set if default values have been
16717 * changed
16718 */
16719 else if (!peer_group_active(peer) && !peer->delayopen
16720 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16721 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16722 peer->bgp->default_delayopen);
16723
16724 /* capability dynamic */
16725 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16726 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16727
16728 /* capability extended-nexthop */
16729 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16730 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
16731 !peer->conf_if)
16732 vty_out(vty,
16733 " no neighbor %s capability extended-nexthop\n",
16734 addr);
16735 else if (!peer->conf_if)
16736 vty_out(vty,
16737 " neighbor %s capability extended-nexthop\n",
16738 addr);
16739 }
16740
16741 /* dont-capability-negotiation */
16742 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16743 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16744
16745 /* override-capability */
16746 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16747 vty_out(vty, " neighbor %s override-capability\n", addr);
16748
16749 /* strict-capability-match */
16750 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16751 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16752
16753 /* Sender side AS path loop detection. */
16754 if (peer->as_path_loop_detection)
16755 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16756 addr);
16757
16758 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16759 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16760
16761 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16762 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16763 vty_out(vty,
16764 " neighbor %s graceful-restart-helper\n", addr);
16765 } else if (CHECK_FLAG(
16766 peer->peer_gr_new_status_flag,
16767 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16768 vty_out(vty,
16769 " neighbor %s graceful-restart\n", addr);
16770 } else if (
16771 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16772 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16773 && !(CHECK_FLAG(
16774 peer->peer_gr_new_status_flag,
16775 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16776 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16777 addr);
16778 }
16779 }
16780 }
16781
16782 /* BGP peer configuration display function. */
16783 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16784 struct peer *peer, afi_t afi, safi_t safi)
16785 {
16786 struct peer *g_peer = NULL;
16787 char *addr;
16788 bool flag_scomm, flag_secomm, flag_slcomm;
16789
16790 /* Skip dynamic neighbors. */
16791 if (peer_dynamic_neighbor(peer))
16792 return;
16793
16794 if (peer->conf_if)
16795 addr = peer->conf_if;
16796 else
16797 addr = peer->host;
16798
16799 /************************************
16800 ****** Per AF to the neighbor ******
16801 ************************************/
16802 if (peer_group_active(peer)) {
16803 g_peer = peer->group->conf;
16804
16805 /* If the peer-group is active but peer is not, print a 'no
16806 * activate' */
16807 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16808 vty_out(vty, " no neighbor %s activate\n", addr);
16809 }
16810
16811 /* If the peer-group is not active but peer is, print an
16812 'activate' */
16813 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16814 vty_out(vty, " neighbor %s activate\n", addr);
16815 }
16816 } else {
16817 if (peer->afc[afi][safi]) {
16818 if (safi == SAFI_ENCAP)
16819 vty_out(vty, " neighbor %s activate\n", addr);
16820 else if (!bgp->default_af[afi][safi])
16821 vty_out(vty, " neighbor %s activate\n", addr);
16822 } else {
16823 if (bgp->default_af[afi][safi])
16824 vty_out(vty, " no neighbor %s activate\n",
16825 addr);
16826 }
16827 }
16828
16829 /* addpath TX knobs */
16830 if (peergroup_af_addpath_check(peer, afi, safi)) {
16831 switch (peer->addpath_type[afi][safi]) {
16832 case BGP_ADDPATH_ALL:
16833 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16834 addr);
16835 break;
16836 case BGP_ADDPATH_BEST_PER_AS:
16837 vty_out(vty,
16838 " neighbor %s addpath-tx-bestpath-per-AS\n",
16839 addr);
16840 break;
16841 case BGP_ADDPATH_MAX:
16842 case BGP_ADDPATH_NONE:
16843 break;
16844 }
16845 }
16846
16847 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16848 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16849
16850 /* ORF capability. */
16851 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16852 || peergroup_af_flag_check(peer, afi, safi,
16853 PEER_FLAG_ORF_PREFIX_RM)) {
16854 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16855
16856 if (peergroup_af_flag_check(peer, afi, safi,
16857 PEER_FLAG_ORF_PREFIX_SM)
16858 && peergroup_af_flag_check(peer, afi, safi,
16859 PEER_FLAG_ORF_PREFIX_RM))
16860 vty_out(vty, " both");
16861 else if (peergroup_af_flag_check(peer, afi, safi,
16862 PEER_FLAG_ORF_PREFIX_SM))
16863 vty_out(vty, " send");
16864 else
16865 vty_out(vty, " receive");
16866 vty_out(vty, "\n");
16867 }
16868
16869 /* Route reflector client. */
16870 if (peergroup_af_flag_check(peer, afi, safi,
16871 PEER_FLAG_REFLECTOR_CLIENT)) {
16872 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16873 }
16874
16875 /* next-hop-self force */
16876 if (peergroup_af_flag_check(peer, afi, safi,
16877 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16878 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16879 }
16880
16881 /* next-hop-self */
16882 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16883 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16884 }
16885
16886 /* remove-private-AS */
16887 if (peergroup_af_flag_check(peer, afi, safi,
16888 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16889 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16890 addr);
16891 }
16892
16893 else if (peergroup_af_flag_check(peer, afi, safi,
16894 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16895 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16896 addr);
16897 }
16898
16899 else if (peergroup_af_flag_check(peer, afi, safi,
16900 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16901 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16902 }
16903
16904 else if (peergroup_af_flag_check(peer, afi, safi,
16905 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16906 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16907 }
16908
16909 /* as-override */
16910 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16911 vty_out(vty, " neighbor %s as-override\n", addr);
16912 }
16913
16914 /* send-community print. */
16915 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16916 PEER_FLAG_SEND_COMMUNITY);
16917 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16918 PEER_FLAG_SEND_EXT_COMMUNITY);
16919 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16920 PEER_FLAG_SEND_LARGE_COMMUNITY);
16921
16922 if (flag_scomm && flag_secomm && flag_slcomm) {
16923 vty_out(vty, " no neighbor %s send-community all\n", addr);
16924 } else {
16925 if (flag_scomm)
16926 vty_out(vty, " no neighbor %s send-community\n", addr);
16927 if (flag_secomm)
16928 vty_out(vty,
16929 " no neighbor %s send-community extended\n",
16930 addr);
16931
16932 if (flag_slcomm)
16933 vty_out(vty, " no neighbor %s send-community large\n",
16934 addr);
16935 }
16936
16937 /* Default information */
16938 if (peergroup_af_flag_check(peer, afi, safi,
16939 PEER_FLAG_DEFAULT_ORIGINATE)) {
16940 vty_out(vty, " neighbor %s default-originate", addr);
16941
16942 if (peer->default_rmap[afi][safi].name)
16943 vty_out(vty, " route-map %s",
16944 peer->default_rmap[afi][safi].name);
16945
16946 vty_out(vty, "\n");
16947 }
16948
16949 /* Soft reconfiguration inbound. */
16950 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16951 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16952 addr);
16953 }
16954
16955 /* maximum-prefix. */
16956 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16957 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16958 peer->pmax[afi][safi]);
16959
16960 if (peer->pmax_threshold[afi][safi]
16961 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16962 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16963 if (peer_af_flag_check(peer, afi, safi,
16964 PEER_FLAG_MAX_PREFIX_WARNING))
16965 vty_out(vty, " warning-only");
16966 if (peer->pmax_restart[afi][safi])
16967 vty_out(vty, " restart %u",
16968 peer->pmax_restart[afi][safi]);
16969 if (peer_af_flag_check(peer, afi, safi,
16970 PEER_FLAG_MAX_PREFIX_FORCE))
16971 vty_out(vty, " force");
16972
16973 vty_out(vty, "\n");
16974 }
16975
16976 /* maximum-prefix-out */
16977 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16978 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16979 addr, peer->pmax_out[afi][safi]);
16980
16981 /* Route server client. */
16982 if (peergroup_af_flag_check(peer, afi, safi,
16983 PEER_FLAG_RSERVER_CLIENT)) {
16984 vty_out(vty, " neighbor %s route-server-client\n", addr);
16985 }
16986
16987 /* Nexthop-local unchanged. */
16988 if (peergroup_af_flag_check(peer, afi, safi,
16989 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16990 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16991 }
16992
16993 /* allowas-in <1-10> */
16994 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16995 if (peer_af_flag_check(peer, afi, safi,
16996 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16997 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16998 } else if (peer->allowas_in[afi][safi] == 3) {
16999 vty_out(vty, " neighbor %s allowas-in\n", addr);
17000 } else {
17001 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17002 peer->allowas_in[afi][safi]);
17003 }
17004 }
17005
17006 /* weight */
17007 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17008 vty_out(vty, " neighbor %s weight %lu\n", addr,
17009 peer->weight[afi][safi]);
17010
17011 /* Filter. */
17012 bgp_config_write_filter(vty, peer, afi, safi);
17013
17014 /* atribute-unchanged. */
17015 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17016 || (safi != SAFI_EVPN
17017 && peer_af_flag_check(peer, afi, safi,
17018 PEER_FLAG_NEXTHOP_UNCHANGED))
17019 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17020
17021 if (!peer_group_active(peer)
17022 || peergroup_af_flag_check(peer, afi, safi,
17023 PEER_FLAG_AS_PATH_UNCHANGED)
17024 || peergroup_af_flag_check(peer, afi, safi,
17025 PEER_FLAG_NEXTHOP_UNCHANGED)
17026 || peergroup_af_flag_check(peer, afi, safi,
17027 PEER_FLAG_MED_UNCHANGED)) {
17028
17029 vty_out(vty,
17030 " neighbor %s attribute-unchanged%s%s%s\n",
17031 addr,
17032 peer_af_flag_check(peer, afi, safi,
17033 PEER_FLAG_AS_PATH_UNCHANGED)
17034 ? " as-path"
17035 : "",
17036 peer_af_flag_check(peer, afi, safi,
17037 PEER_FLAG_NEXTHOP_UNCHANGED)
17038 ? " next-hop"
17039 : "",
17040 peer_af_flag_check(peer, afi, safi,
17041 PEER_FLAG_MED_UNCHANGED)
17042 ? " med"
17043 : "");
17044 }
17045 }
17046 }
17047
17048 /* Address family based peer configuration display. */
17049 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17050 safi_t safi)
17051 {
17052 struct peer *peer;
17053 struct peer_group *group;
17054 struct listnode *node, *nnode;
17055
17056
17057 vty_frame(vty, " !\n address-family ");
17058 if (afi == AFI_IP) {
17059 if (safi == SAFI_UNICAST)
17060 vty_frame(vty, "ipv4 unicast");
17061 else if (safi == SAFI_LABELED_UNICAST)
17062 vty_frame(vty, "ipv4 labeled-unicast");
17063 else if (safi == SAFI_MULTICAST)
17064 vty_frame(vty, "ipv4 multicast");
17065 else if (safi == SAFI_MPLS_VPN)
17066 vty_frame(vty, "ipv4 vpn");
17067 else if (safi == SAFI_ENCAP)
17068 vty_frame(vty, "ipv4 encap");
17069 else if (safi == SAFI_FLOWSPEC)
17070 vty_frame(vty, "ipv4 flowspec");
17071 } else if (afi == AFI_IP6) {
17072 if (safi == SAFI_UNICAST)
17073 vty_frame(vty, "ipv6 unicast");
17074 else if (safi == SAFI_LABELED_UNICAST)
17075 vty_frame(vty, "ipv6 labeled-unicast");
17076 else if (safi == SAFI_MULTICAST)
17077 vty_frame(vty, "ipv6 multicast");
17078 else if (safi == SAFI_MPLS_VPN)
17079 vty_frame(vty, "ipv6 vpn");
17080 else if (safi == SAFI_ENCAP)
17081 vty_frame(vty, "ipv6 encap");
17082 else if (safi == SAFI_FLOWSPEC)
17083 vty_frame(vty, "ipv6 flowspec");
17084 } else if (afi == AFI_L2VPN) {
17085 if (safi == SAFI_EVPN)
17086 vty_frame(vty, "l2vpn evpn");
17087 }
17088 vty_frame(vty, "\n");
17089
17090 bgp_config_write_distance(vty, bgp, afi, safi);
17091
17092 bgp_config_write_network(vty, bgp, afi, safi);
17093
17094 bgp_config_write_redistribute(vty, bgp, afi, safi);
17095
17096 /* BGP flag dampening. */
17097 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17098 bgp_config_write_damp(vty, afi, safi);
17099
17100 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17101 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17102
17103 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17104 /* Do not display doppelganger peers */
17105 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17106 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17107 }
17108
17109 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17110 bgp_config_write_table_map(vty, bgp, afi, safi);
17111
17112 if (safi == SAFI_EVPN)
17113 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17114
17115 if (safi == SAFI_FLOWSPEC)
17116 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17117
17118 if (safi == SAFI_UNICAST) {
17119 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17120 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17121 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17122
17123 vty_out(vty, " export vpn\n");
17124 }
17125 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17126 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17127
17128 vty_out(vty, " import vpn\n");
17129 }
17130 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17131 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17132 char *name;
17133
17134 for (ALL_LIST_ELEMENTS_RO(
17135 bgp->vpn_policy[afi].import_vrf, node,
17136 name))
17137 vty_out(vty, " import vrf %s\n", name);
17138 }
17139 }
17140
17141 vty_endframe(vty, " exit-address-family\n");
17142 }
17143
17144 int bgp_config_write(struct vty *vty)
17145 {
17146 struct bgp *bgp;
17147 struct peer_group *group;
17148 struct peer *peer;
17149 struct listnode *node, *nnode;
17150 struct listnode *mnode, *mnnode;
17151 afi_t afi;
17152 safi_t safi;
17153
17154 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17155 vty_out(vty, "bgp route-map delay-timer %u\n",
17156 bm->rmap_update_timer);
17157
17158 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17159 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17160 if (bm->v_update_delay != bm->v_establish_wait)
17161 vty_out(vty, " %d", bm->v_establish_wait);
17162 vty_out(vty, "\n");
17163 }
17164
17165 if (bm->wait_for_fib)
17166 vty_out(vty, "bgp suppress-fib-pending\n");
17167
17168 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17169 vty_out(vty, "bgp graceful-shutdown\n");
17170
17171 /* No-RIB (Zebra) option flag configuration */
17172 if (bgp_option_check(BGP_OPT_NO_FIB))
17173 vty_out(vty, "bgp no-rib\n");
17174
17175 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17176 vty_out(vty, "bgp send-extra-data zebra\n");
17177
17178 /* BGP session DSCP value */
17179 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17180 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17181
17182 /* BGP configuration. */
17183 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17184
17185 /* skip all auto created vrf as they dont have user config */
17186 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17187 continue;
17188
17189 /* Router bgp ASN */
17190 vty_out(vty, "router bgp %u", bgp->as);
17191
17192 if (bgp->name)
17193 vty_out(vty, " %s %s",
17194 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17195 ? "view" : "vrf", bgp->name);
17196 vty_out(vty, "\n");
17197
17198 /* BGP fast-external-failover. */
17199 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17200 vty_out(vty, " no bgp fast-external-failover\n");
17201
17202 /* BGP router ID. */
17203 if (bgp->router_id_static.s_addr != INADDR_ANY)
17204 vty_out(vty, " bgp router-id %pI4\n",
17205 &bgp->router_id_static);
17206
17207 /* Suppress fib pending */
17208 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17209 vty_out(vty, " bgp suppress-fib-pending\n");
17210
17211 /* BGP log-neighbor-changes. */
17212 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17213 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17214 vty_out(vty, " %sbgp log-neighbor-changes\n",
17215 CHECK_FLAG(bgp->flags,
17216 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17217 ? ""
17218 : "no ");
17219
17220 /* BGP configuration. */
17221 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17222 vty_out(vty, " bgp always-compare-med\n");
17223
17224 /* RFC8212 default eBGP policy. */
17225 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17226 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17227 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17228 CHECK_FLAG(bgp->flags,
17229 BGP_FLAG_EBGP_REQUIRES_POLICY)
17230 ? ""
17231 : "no ");
17232
17233 /* draft-ietf-idr-deprecate-as-set-confed-set */
17234 if (bgp->reject_as_sets)
17235 vty_out(vty, " bgp reject-as-sets\n");
17236
17237 /* Suppress duplicate updates if the route actually not changed
17238 */
17239 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17240 != SAVE_BGP_SUPPRESS_DUPLICATES)
17241 vty_out(vty, " %sbgp suppress-duplicates\n",
17242 CHECK_FLAG(bgp->flags,
17243 BGP_FLAG_SUPPRESS_DUPLICATES)
17244 ? ""
17245 : "no ");
17246
17247 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17248 */
17249 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17250 SAVE_BGP_HARD_ADMIN_RESET)
17251 vty_out(vty, " %sbgp hard-administrative-reset\n",
17252 CHECK_FLAG(bgp->flags,
17253 BGP_FLAG_HARD_ADMIN_RESET)
17254 ? ""
17255 : "no ");
17256
17257 /* BGP default <afi>-<safi> */
17258 FOREACH_AFI_SAFI (afi, safi) {
17259 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17260 if (!bgp->default_af[afi][safi])
17261 vty_out(vty, " no bgp default %s\n",
17262 get_bgp_default_af_flag(afi,
17263 safi));
17264 } else if (bgp->default_af[afi][safi])
17265 vty_out(vty, " bgp default %s\n",
17266 get_bgp_default_af_flag(afi, safi));
17267 }
17268
17269 /* BGP default local-preference. */
17270 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17271 vty_out(vty, " bgp default local-preference %u\n",
17272 bgp->default_local_pref);
17273
17274 /* BGP default show-hostname */
17275 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17276 != SAVE_BGP_SHOW_HOSTNAME)
17277 vty_out(vty, " %sbgp default show-hostname\n",
17278 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17279 ? ""
17280 : "no ");
17281
17282 /* BGP default show-nexthop-hostname */
17283 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17284 != SAVE_BGP_SHOW_HOSTNAME)
17285 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17286 CHECK_FLAG(bgp->flags,
17287 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17288 ? ""
17289 : "no ");
17290
17291 /* BGP default subgroup-pkt-queue-max. */
17292 if (bgp->default_subgroup_pkt_queue_max
17293 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17294 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17295 bgp->default_subgroup_pkt_queue_max);
17296
17297 /* BGP client-to-client reflection. */
17298 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17299 vty_out(vty, " no bgp client-to-client reflection\n");
17300
17301 /* BGP cluster ID. */
17302 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17303 vty_out(vty, " bgp cluster-id %pI4\n",
17304 &bgp->cluster_id);
17305
17306 /* Disable ebgp connected nexthop check */
17307 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17308 vty_out(vty,
17309 " bgp disable-ebgp-connected-route-check\n");
17310
17311 /* Confederation identifier*/
17312 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17313 vty_out(vty, " bgp confederation identifier %u\n",
17314 bgp->confed_id);
17315
17316 /* Confederation peer */
17317 if (bgp->confed_peers_cnt > 0) {
17318 int i;
17319
17320 vty_out(vty, " bgp confederation peers");
17321
17322 for (i = 0; i < bgp->confed_peers_cnt; i++)
17323 vty_out(vty, " %u", bgp->confed_peers[i]);
17324
17325 vty_out(vty, "\n");
17326 }
17327
17328 /* BGP deterministic-med. */
17329 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17330 != SAVE_BGP_DETERMINISTIC_MED)
17331 vty_out(vty, " %sbgp deterministic-med\n",
17332 CHECK_FLAG(bgp->flags,
17333 BGP_FLAG_DETERMINISTIC_MED)
17334 ? ""
17335 : "no ");
17336
17337 /* BGP update-delay. */
17338 bgp_config_write_update_delay(vty, bgp);
17339
17340 if (bgp->v_maxmed_onstartup
17341 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17342 vty_out(vty, " bgp max-med on-startup %u",
17343 bgp->v_maxmed_onstartup);
17344 if (bgp->maxmed_onstartup_value
17345 != BGP_MAXMED_VALUE_DEFAULT)
17346 vty_out(vty, " %u",
17347 bgp->maxmed_onstartup_value);
17348 vty_out(vty, "\n");
17349 }
17350 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17351 vty_out(vty, " bgp max-med administrative");
17352 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17353 vty_out(vty, " %u", bgp->maxmed_admin_value);
17354 vty_out(vty, "\n");
17355 }
17356
17357 /* write quanta */
17358 bgp_config_write_wpkt_quanta(vty, bgp);
17359 /* read quanta */
17360 bgp_config_write_rpkt_quanta(vty, bgp);
17361
17362 /* coalesce time */
17363 bgp_config_write_coalesce_time(vty, bgp);
17364
17365 /* BGP per-instance graceful-shutdown */
17366 /* BGP-wide settings and per-instance settings are mutually
17367 * exclusive.
17368 */
17369 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17370 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17371 vty_out(vty, " bgp graceful-shutdown\n");
17372
17373 /* Long-lived Graceful Restart */
17374 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17375 vty_out(vty,
17376 " bgp long-lived-graceful-restart stale-time %u\n",
17377 bgp->llgr_stale_time);
17378
17379 /* BGP graceful-restart. */
17380 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17381 vty_out(vty,
17382 " bgp graceful-restart stalepath-time %u\n",
17383 bgp->stalepath_time);
17384
17385 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17386 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17387 bgp->restart_time);
17388
17389 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17390 SAVE_BGP_GRACEFUL_NOTIFICATION)
17391 vty_out(vty, " %sbgp graceful-restart notification\n",
17392 CHECK_FLAG(bgp->flags,
17393 BGP_FLAG_GRACEFUL_NOTIFICATION)
17394 ? ""
17395 : "no ");
17396
17397 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17398 vty_out(vty,
17399 " bgp graceful-restart select-defer-time %u\n",
17400 bgp->select_defer_time);
17401
17402 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17403 vty_out(vty, " bgp graceful-restart\n");
17404
17405 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17406 vty_out(vty, " bgp graceful-restart-disable\n");
17407
17408 /* BGP graceful-restart Preserve State F bit. */
17409 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17410 vty_out(vty,
17411 " bgp graceful-restart preserve-fw-state\n");
17412
17413 /* Stale timer for RIB */
17414 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17415 vty_out(vty,
17416 " bgp graceful-restart rib-stale-time %u\n",
17417 bgp->rib_stale_time);
17418
17419 /* BGP bestpath method. */
17420 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17421 vty_out(vty, " bgp bestpath as-path ignore\n");
17422 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17423 vty_out(vty, " bgp bestpath as-path confed\n");
17424
17425 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17426 if (CHECK_FLAG(bgp->flags,
17427 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17428 vty_out(vty,
17429 " bgp bestpath as-path multipath-relax as-set\n");
17430 } else {
17431 vty_out(vty,
17432 " bgp bestpath as-path multipath-relax\n");
17433 }
17434 }
17435
17436 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17437 vty_out(vty,
17438 " bgp route-reflector allow-outbound-policy\n");
17439 }
17440 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17441 vty_out(vty, " bgp bestpath compare-routerid\n");
17442 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17443 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17444 vty_out(vty, " bgp bestpath med");
17445 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17446 vty_out(vty, " confed");
17447 if (CHECK_FLAG(bgp->flags,
17448 BGP_FLAG_MED_MISSING_AS_WORST))
17449 vty_out(vty, " missing-as-worst");
17450 vty_out(vty, "\n");
17451 }
17452
17453 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17454 vty_out(vty,
17455 " bgp bestpath peer-type multipath-relax\n");
17456
17457 /* Link bandwidth handling. */
17458 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17459 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17460 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17461 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17462 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17463 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17464
17465 /* BGP network import check. */
17466 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17467 != SAVE_BGP_IMPORT_CHECK)
17468 vty_out(vty, " %sbgp network import-check\n",
17469 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17470 ? ""
17471 : "no ");
17472
17473 /* BGP timers configuration. */
17474 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17475 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17476 vty_out(vty, " timers bgp %u %u\n",
17477 bgp->default_keepalive, bgp->default_holdtime);
17478
17479 /* BGP minimum holdtime configuration. */
17480 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17481 && bgp->default_min_holdtime != 0)
17482 vty_out(vty, " bgp minimum-holdtime %u\n",
17483 bgp->default_min_holdtime);
17484
17485 /* Conditional advertisement timer configuration */
17486 if (bgp->condition_check_period
17487 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17488 vty_out(vty,
17489 " bgp conditional-advertisement timer %u\n",
17490 bgp->condition_check_period);
17491
17492 /* peer-group */
17493 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17494 bgp_config_write_peer_global(vty, bgp, group->conf);
17495 }
17496
17497 /* Normal neighbor configuration. */
17498 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17499 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17500 bgp_config_write_peer_global(vty, bgp, peer);
17501 }
17502
17503 /* listen range and limit for dynamic BGP neighbors */
17504 bgp_config_write_listen(vty, bgp);
17505
17506 /*
17507 * BGP default autoshutdown neighbors
17508 *
17509 * This must be placed after any peer and peer-group
17510 * configuration, to avoid setting all peers to shutdown after
17511 * a daemon restart, which is undesired behavior. (see #2286)
17512 */
17513 if (bgp->autoshutdown)
17514 vty_out(vty, " bgp default shutdown\n");
17515
17516 /* BGP instance administrative shutdown */
17517 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17518 vty_out(vty, " bgp shutdown\n");
17519
17520 if (bgp->fast_convergence)
17521 vty_out(vty, " bgp fast-convergence\n");
17522
17523 if (bgp->srv6_enabled) {
17524 vty_frame(vty, " !\n segment-routing srv6\n");
17525 if (strlen(bgp->srv6_locator_name))
17526 vty_out(vty, " locator %s\n",
17527 bgp->srv6_locator_name);
17528 vty_endframe(vty, " exit\n");
17529 }
17530
17531
17532 /* IPv4 unicast configuration. */
17533 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17534
17535 /* IPv4 multicast configuration. */
17536 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17537
17538 /* IPv4 labeled-unicast configuration. */
17539 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17540
17541 /* IPv4 VPN configuration. */
17542 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17543
17544 /* ENCAPv4 configuration. */
17545 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17546
17547 /* FLOWSPEC v4 configuration. */
17548 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17549
17550 /* IPv6 unicast configuration. */
17551 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17552
17553 /* IPv6 multicast configuration. */
17554 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17555
17556 /* IPv6 labeled-unicast configuration. */
17557 bgp_config_write_family(vty, bgp, AFI_IP6,
17558 SAFI_LABELED_UNICAST);
17559
17560 /* IPv6 VPN configuration. */
17561 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17562
17563 /* ENCAPv6 configuration. */
17564 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17565
17566 /* FLOWSPEC v6 configuration. */
17567 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17568
17569 /* EVPN configuration. */
17570 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17571
17572 hook_call(bgp_inst_config_write, bgp, vty);
17573
17574 #ifdef ENABLE_BGP_VNC
17575 bgp_rfapi_cfg_write(vty, bgp);
17576 #endif
17577
17578 vty_out(vty, "exit\n");
17579 vty_out(vty, "!\n");
17580 }
17581 return 0;
17582 }
17583
17584
17585 /* BGP node structure. */
17586 static struct cmd_node bgp_node = {
17587 .name = "bgp",
17588 .node = BGP_NODE,
17589 .parent_node = CONFIG_NODE,
17590 .prompt = "%s(config-router)# ",
17591 .config_write = bgp_config_write,
17592 };
17593
17594 static struct cmd_node bgp_ipv4_unicast_node = {
17595 .name = "bgp ipv4 unicast",
17596 .node = BGP_IPV4_NODE,
17597 .parent_node = BGP_NODE,
17598 .prompt = "%s(config-router-af)# ",
17599 .no_xpath = true,
17600 };
17601
17602 static struct cmd_node bgp_ipv4_multicast_node = {
17603 .name = "bgp ipv4 multicast",
17604 .node = BGP_IPV4M_NODE,
17605 .parent_node = BGP_NODE,
17606 .prompt = "%s(config-router-af)# ",
17607 .no_xpath = true,
17608 };
17609
17610 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17611 .name = "bgp ipv4 labeled unicast",
17612 .node = BGP_IPV4L_NODE,
17613 .parent_node = BGP_NODE,
17614 .prompt = "%s(config-router-af)# ",
17615 .no_xpath = true,
17616 };
17617
17618 static struct cmd_node bgp_ipv6_unicast_node = {
17619 .name = "bgp ipv6 unicast",
17620 .node = BGP_IPV6_NODE,
17621 .parent_node = BGP_NODE,
17622 .prompt = "%s(config-router-af)# ",
17623 .no_xpath = true,
17624 };
17625
17626 static struct cmd_node bgp_ipv6_multicast_node = {
17627 .name = "bgp ipv6 multicast",
17628 .node = BGP_IPV6M_NODE,
17629 .parent_node = BGP_NODE,
17630 .prompt = "%s(config-router-af)# ",
17631 .no_xpath = true,
17632 };
17633
17634 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17635 .name = "bgp ipv6 labeled unicast",
17636 .node = BGP_IPV6L_NODE,
17637 .parent_node = BGP_NODE,
17638 .prompt = "%s(config-router-af)# ",
17639 .no_xpath = true,
17640 };
17641
17642 static struct cmd_node bgp_vpnv4_node = {
17643 .name = "bgp vpnv4",
17644 .node = BGP_VPNV4_NODE,
17645 .parent_node = BGP_NODE,
17646 .prompt = "%s(config-router-af)# ",
17647 .no_xpath = true,
17648 };
17649
17650 static struct cmd_node bgp_vpnv6_node = {
17651 .name = "bgp vpnv6",
17652 .node = BGP_VPNV6_NODE,
17653 .parent_node = BGP_NODE,
17654 .prompt = "%s(config-router-af-vpnv6)# ",
17655 .no_xpath = true,
17656 };
17657
17658 static struct cmd_node bgp_evpn_node = {
17659 .name = "bgp evpn",
17660 .node = BGP_EVPN_NODE,
17661 .parent_node = BGP_NODE,
17662 .prompt = "%s(config-router-evpn)# ",
17663 .no_xpath = true,
17664 };
17665
17666 static struct cmd_node bgp_evpn_vni_node = {
17667 .name = "bgp evpn vni",
17668 .node = BGP_EVPN_VNI_NODE,
17669 .parent_node = BGP_EVPN_NODE,
17670 .prompt = "%s(config-router-af-vni)# ",
17671 };
17672
17673 static struct cmd_node bgp_flowspecv4_node = {
17674 .name = "bgp ipv4 flowspec",
17675 .node = BGP_FLOWSPECV4_NODE,
17676 .parent_node = BGP_NODE,
17677 .prompt = "%s(config-router-af)# ",
17678 .no_xpath = true,
17679 };
17680
17681 static struct cmd_node bgp_flowspecv6_node = {
17682 .name = "bgp ipv6 flowspec",
17683 .node = BGP_FLOWSPECV6_NODE,
17684 .parent_node = BGP_NODE,
17685 .prompt = "%s(config-router-af-vpnv6)# ",
17686 .no_xpath = true,
17687 };
17688
17689 static struct cmd_node bgp_srv6_node = {
17690 .name = "bgp srv6",
17691 .node = BGP_SRV6_NODE,
17692 .parent_node = BGP_NODE,
17693 .prompt = "%s(config-router-srv6)# ",
17694 };
17695
17696 static void community_list_vty(void);
17697
17698 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17699 {
17700 struct bgp *bgp;
17701 struct peer_group *group;
17702 struct listnode *lnbgp, *lnpeer;
17703
17704 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17705 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17706 vector_set(comps,
17707 XSTRDUP(MTYPE_COMPLETION, group->name));
17708 }
17709 }
17710
17711 static void bgp_ac_peer(vector comps, struct cmd_token *token)
17712 {
17713 struct bgp *bgp;
17714 struct peer *peer;
17715 struct listnode *lnbgp, *lnpeer;
17716
17717 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17718 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17719 /* only provide suggestions on the appropriate input
17720 * token type,
17721 * they'll otherwise show up multiple times */
17722 enum cmd_token_type match_type;
17723 char *name = peer->host;
17724
17725 if (peer->conf_if) {
17726 match_type = VARIABLE_TKN;
17727 name = peer->conf_if;
17728 } else if (strchr(peer->host, ':'))
17729 match_type = IPV6_TKN;
17730 else
17731 match_type = IPV4_TKN;
17732
17733 if (token->type != match_type)
17734 continue;
17735
17736 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17737 }
17738 }
17739 }
17740
17741 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17742 {
17743 bgp_ac_peer(comps, token);
17744
17745 if (token->type == VARIABLE_TKN)
17746 bgp_ac_peergroup(comps, token);
17747 }
17748
17749 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17750 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17751 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17752 {.varname = "peer", .completions = bgp_ac_neighbor},
17753 {.completions = NULL}};
17754
17755 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17756 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17757 {.completions = NULL} };
17758
17759 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
17760
17761 static struct thread *t_bgp_cfg;
17762
17763 bool bgp_config_inprocess(void)
17764 {
17765 return thread_is_scheduled(t_bgp_cfg);
17766 }
17767
17768 static void bgp_config_finish(struct thread *t)
17769 {
17770 struct listnode *node;
17771 struct bgp *bgp;
17772
17773 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
17774 hook_call(bgp_config_end, bgp);
17775 }
17776
17777 static void bgp_config_start(void)
17778 {
17779 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
17780 THREAD_OFF(t_bgp_cfg);
17781 thread_add_timer(bm->master, bgp_config_finish, NULL,
17782 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
17783 }
17784
17785 /* When we receive a hook the configuration is read,
17786 * we start a timer to make sure we postpone sending
17787 * EoR before route-maps are processed.
17788 * This is especially valid if using `bgp route-map delay-timer`.
17789 */
17790 static void bgp_config_end(void)
17791 {
17792 #define BGP_POST_CONFIG_DELAY_SECONDS 1
17793 uint32_t bgp_post_config_delay =
17794 thread_is_scheduled(bm->t_rmap_update)
17795 ? thread_timer_remain_second(bm->t_rmap_update)
17796 : BGP_POST_CONFIG_DELAY_SECONDS;
17797
17798 /* If BGP config processing thread isn't running, then
17799 * we can return and rely it's properly handled.
17800 */
17801 if (!bgp_config_inprocess())
17802 return;
17803
17804 THREAD_OFF(t_bgp_cfg);
17805
17806 /* Start a new timer to make sure we don't send EoR
17807 * before route-maps are processed.
17808 */
17809 thread_add_timer(bm->master, bgp_config_finish, NULL,
17810 bgp_post_config_delay, &t_bgp_cfg);
17811 }
17812
17813 void bgp_vty_init(void)
17814 {
17815 cmd_variable_handler_register(bgp_var_neighbor);
17816 cmd_variable_handler_register(bgp_var_peergroup);
17817
17818 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
17819
17820 /* Install bgp top node. */
17821 install_node(&bgp_node);
17822 install_node(&bgp_ipv4_unicast_node);
17823 install_node(&bgp_ipv4_multicast_node);
17824 install_node(&bgp_ipv4_labeled_unicast_node);
17825 install_node(&bgp_ipv6_unicast_node);
17826 install_node(&bgp_ipv6_multicast_node);
17827 install_node(&bgp_ipv6_labeled_unicast_node);
17828 install_node(&bgp_vpnv4_node);
17829 install_node(&bgp_vpnv6_node);
17830 install_node(&bgp_evpn_node);
17831 install_node(&bgp_evpn_vni_node);
17832 install_node(&bgp_flowspecv4_node);
17833 install_node(&bgp_flowspecv6_node);
17834 install_node(&bgp_srv6_node);
17835
17836 /* Install default VTY commands to new nodes. */
17837 install_default(BGP_NODE);
17838 install_default(BGP_IPV4_NODE);
17839 install_default(BGP_IPV4M_NODE);
17840 install_default(BGP_IPV4L_NODE);
17841 install_default(BGP_IPV6_NODE);
17842 install_default(BGP_IPV6M_NODE);
17843 install_default(BGP_IPV6L_NODE);
17844 install_default(BGP_VPNV4_NODE);
17845 install_default(BGP_VPNV6_NODE);
17846 install_default(BGP_FLOWSPECV4_NODE);
17847 install_default(BGP_FLOWSPECV6_NODE);
17848 install_default(BGP_EVPN_NODE);
17849 install_default(BGP_EVPN_VNI_NODE);
17850 install_default(BGP_SRV6_NODE);
17851
17852 /* "bgp local-mac" hidden commands. */
17853 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17854 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17855
17856 /* "bgp suppress-fib-pending" global */
17857 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17858
17859 /* bgp route-map delay-timer commands. */
17860 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17861 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17862
17863 /* bgp fast-convergence command */
17864 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17865 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17866
17867 /* global bgp update-delay command */
17868 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17869 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17870
17871 /* global bgp graceful-shutdown command */
17872 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17873 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17874
17875 /* Dummy commands (Currently not supported) */
17876 install_element(BGP_NODE, &no_synchronization_cmd);
17877 install_element(BGP_NODE, &no_auto_summary_cmd);
17878
17879 /* "router bgp" commands. */
17880 install_element(CONFIG_NODE, &router_bgp_cmd);
17881
17882 /* "no router bgp" commands. */
17883 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17884
17885 /* "bgp session-dscp command */
17886 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
17887 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
17888
17889 /* "bgp router-id" commands. */
17890 install_element(BGP_NODE, &bgp_router_id_cmd);
17891 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17892
17893 /* "bgp suppress-fib-pending" command */
17894 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17895
17896 /* "bgp cluster-id" commands. */
17897 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17898 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17899
17900 /* "bgp no-rib" commands. */
17901 install_element(CONFIG_NODE, &bgp_norib_cmd);
17902 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17903
17904 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17905
17906 /* "bgp confederation" commands. */
17907 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17908 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17909
17910 /* "bgp confederation peers" commands. */
17911 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17912 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17913
17914 /* bgp max-med command */
17915 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17916 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17917 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17918 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17919 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17920
17921 /* bgp disable-ebgp-connected-nh-check */
17922 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17923 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17924
17925 /* bgp update-delay command */
17926 install_element(BGP_NODE, &bgp_update_delay_cmd);
17927 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17928
17929 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17930 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17931
17932 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17933 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17934
17935 /* "maximum-paths" commands. */
17936 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17937 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17938 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17939 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17940 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17941 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17942 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17943 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17944 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17945 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17946 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17947 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17948 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17949 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17950 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17951
17952 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17953 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17954 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17955 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17956 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17957 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17958 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17959 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17960 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17961 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17962
17963 /* "timers bgp" commands. */
17964 install_element(BGP_NODE, &bgp_timers_cmd);
17965 install_element(BGP_NODE, &no_bgp_timers_cmd);
17966
17967 /* "minimum-holdtime" commands. */
17968 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17969 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17970
17971 /* route-map delay-timer commands - per instance for backwards compat.
17972 */
17973 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17974 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17975
17976 /* "bgp client-to-client reflection" commands */
17977 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17978 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17979
17980 /* "bgp always-compare-med" commands */
17981 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17982 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17983
17984 /* bgp ebgp-requires-policy */
17985 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17986 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17987
17988 /* bgp suppress-duplicates */
17989 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17990 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17991
17992 /* bgp reject-as-sets */
17993 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17994 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17995
17996 /* "bgp deterministic-med" commands */
17997 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17998 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17999
18000 /* "bgp graceful-restart" command */
18001 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18002 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18003
18004 /* "bgp graceful-restart-disable" command */
18005 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18006 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18007
18008 /* "neighbor a:b:c:d graceful-restart" command */
18009 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18010 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18011
18012 /* "neighbor a:b:c:d graceful-restart-disable" command */
18013 install_element(BGP_NODE,
18014 &bgp_neighbor_graceful_restart_disable_set_cmd);
18015 install_element(BGP_NODE,
18016 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18017
18018 /* "neighbor a:b:c:d graceful-restart-helper" command */
18019 install_element(BGP_NODE,
18020 &bgp_neighbor_graceful_restart_helper_set_cmd);
18021 install_element(BGP_NODE,
18022 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18023
18024 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18025 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18026 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18027 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18028 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18029 install_element(BGP_NODE,
18030 &no_bgp_graceful_restart_select_defer_time_cmd);
18031 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18032 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18033 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18034
18035 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18036 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18037 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18038 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18039
18040 /* "bgp graceful-shutdown" commands */
18041 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18042 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18043
18044 /* "bgp hard-administrative-reset" commands */
18045 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18046
18047 /* "bgp long-lived-graceful-restart" commands */
18048 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18049 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18050
18051 /* "bgp fast-external-failover" commands */
18052 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18053 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18054
18055 /* "bgp bestpath compare-routerid" commands */
18056 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18057 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18058
18059 /* "bgp bestpath as-path ignore" commands */
18060 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18061 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18062
18063 /* "bgp bestpath as-path confed" commands */
18064 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18065 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18066
18067 /* "bgp bestpath as-path multipath-relax" commands */
18068 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18069 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18070
18071 /* "bgp bestpath peer-type multipath-relax" commands */
18072 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18073 install_element(BGP_NODE,
18074 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18075
18076 /* "bgp log-neighbor-changes" commands */
18077 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18078 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18079
18080 /* "bgp bestpath med" commands */
18081 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18082 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18083
18084 /* "bgp bestpath bandwidth" commands */
18085 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18086 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18087
18088 /* "no bgp default <afi>-<safi>" commands. */
18089 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18090
18091 /* "bgp network import-check" commands. */
18092 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18093 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18094 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18095
18096 /* "bgp default local-preference" commands. */
18097 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18098 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18099
18100 /* bgp default show-hostname */
18101 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18102 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18103
18104 /* bgp default show-nexthop-hostname */
18105 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18106 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18107
18108 /* "bgp default subgroup-pkt-queue-max" commands. */
18109 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18110 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18111
18112 /* bgp ibgp-allow-policy-mods command */
18113 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18114 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18115
18116 /* "bgp listen limit" commands. */
18117 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18118 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18119
18120 /* "bgp listen range" commands. */
18121 install_element(BGP_NODE, &bgp_listen_range_cmd);
18122 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18123
18124 /* "bgp default shutdown" command */
18125 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18126
18127 /* "bgp shutdown" commands */
18128 install_element(BGP_NODE, &bgp_shutdown_cmd);
18129 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18130 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18131 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18132
18133 /* "neighbor remote-as" commands. */
18134 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18135 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18136 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18137 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18138 install_element(BGP_NODE,
18139 &neighbor_interface_v6only_config_remote_as_cmd);
18140 install_element(BGP_NODE, &no_neighbor_cmd);
18141 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18142
18143 /* "neighbor peer-group" commands. */
18144 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18145 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18146 install_element(BGP_NODE,
18147 &no_neighbor_interface_peer_group_remote_as_cmd);
18148
18149 /* "neighbor local-as" commands. */
18150 install_element(BGP_NODE, &neighbor_local_as_cmd);
18151 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18152 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18153 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18154
18155 /* "neighbor solo" commands. */
18156 install_element(BGP_NODE, &neighbor_solo_cmd);
18157 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18158
18159 /* "neighbor password" commands. */
18160 install_element(BGP_NODE, &neighbor_password_cmd);
18161 install_element(BGP_NODE, &no_neighbor_password_cmd);
18162
18163 /* "neighbor activate" commands. */
18164 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18165 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18166 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18167 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18168 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18169 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18170 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18171 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18172 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18173 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18174 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18175 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18176
18177 /* "no neighbor activate" commands. */
18178 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18179 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18180 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18181 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18182 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18183 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18184 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18185 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18186 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18187 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18188 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18189 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18190
18191 /* "neighbor peer-group" set commands. */
18192 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18193 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18194 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18195 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18196 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18197 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18198 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18199 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18200 install_element(BGP_FLOWSPECV4_NODE,
18201 &neighbor_set_peer_group_hidden_cmd);
18202 install_element(BGP_FLOWSPECV6_NODE,
18203 &neighbor_set_peer_group_hidden_cmd);
18204
18205 /* "no neighbor peer-group unset" commands. */
18206 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18207 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18208 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18209 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18210 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18211 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18212 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18213 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18214 install_element(BGP_FLOWSPECV4_NODE,
18215 &no_neighbor_set_peer_group_hidden_cmd);
18216 install_element(BGP_FLOWSPECV6_NODE,
18217 &no_neighbor_set_peer_group_hidden_cmd);
18218
18219 /* "neighbor softreconfiguration inbound" commands.*/
18220 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18221 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18222 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18223 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18224 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18225 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18226 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18227 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18228 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18229 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18230 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18231 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18232 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18233 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18234 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18235 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18236 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18237 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18238 install_element(BGP_FLOWSPECV4_NODE,
18239 &neighbor_soft_reconfiguration_cmd);
18240 install_element(BGP_FLOWSPECV4_NODE,
18241 &no_neighbor_soft_reconfiguration_cmd);
18242 install_element(BGP_FLOWSPECV6_NODE,
18243 &neighbor_soft_reconfiguration_cmd);
18244 install_element(BGP_FLOWSPECV6_NODE,
18245 &no_neighbor_soft_reconfiguration_cmd);
18246 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18247 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18248
18249 /* "neighbor attribute-unchanged" commands. */
18250 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18251 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18252 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18253 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18254 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18255 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18256 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18257 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18258 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18259 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18260 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18261 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18262 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18263 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18264 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18265 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18266 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18267 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18268
18269 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18270 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18271
18272 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18273 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18274 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18275 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18276
18277 /* "nexthop-local unchanged" commands */
18278 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18279 install_element(BGP_IPV6_NODE,
18280 &no_neighbor_nexthop_local_unchanged_cmd);
18281
18282 /* "neighbor next-hop-self" commands. */
18283 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18284 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18285 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18286 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18287 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18288 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18289 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18290 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18291 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18292 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18293 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18294 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18295 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18296 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18297 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18298 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18299 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18300 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18301 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18302 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18303
18304 /* "neighbor next-hop-self force" commands. */
18305 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18306 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18307 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18308 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18309 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18310 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18311 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18312 install_element(BGP_IPV4_NODE,
18313 &no_neighbor_nexthop_self_all_hidden_cmd);
18314 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18315 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18316 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18317 install_element(BGP_IPV4M_NODE,
18318 &no_neighbor_nexthop_self_all_hidden_cmd);
18319 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18320 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18321 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18322 install_element(BGP_IPV4L_NODE,
18323 &no_neighbor_nexthop_self_all_hidden_cmd);
18324 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18325 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18326 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18327 install_element(BGP_IPV6_NODE,
18328 &no_neighbor_nexthop_self_all_hidden_cmd);
18329 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18330 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18331 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18332 install_element(BGP_IPV6M_NODE,
18333 &no_neighbor_nexthop_self_all_hidden_cmd);
18334 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18335 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18336 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18337 install_element(BGP_IPV6L_NODE,
18338 &no_neighbor_nexthop_self_all_hidden_cmd);
18339 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18340 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18341 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18342 install_element(BGP_VPNV4_NODE,
18343 &no_neighbor_nexthop_self_all_hidden_cmd);
18344 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18345 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18346 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18347 install_element(BGP_VPNV6_NODE,
18348 &no_neighbor_nexthop_self_all_hidden_cmd);
18349 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18350 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18351
18352 /* "neighbor as-override" commands. */
18353 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18354 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18355 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18356 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18357 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18358 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18359 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18360 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18361 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18362 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18363 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18364 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18365 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18366 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18367 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18368 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18369 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18370 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18371
18372 /* "neighbor remove-private-AS" commands. */
18373 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18374 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18375 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18376 install_element(BGP_NODE,
18377 &no_neighbor_remove_private_as_all_hidden_cmd);
18378 install_element(BGP_NODE,
18379 &neighbor_remove_private_as_replace_as_hidden_cmd);
18380 install_element(BGP_NODE,
18381 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18382 install_element(BGP_NODE,
18383 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18384 install_element(
18385 BGP_NODE,
18386 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18387 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18388 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18389 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18390 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18391 install_element(BGP_IPV4_NODE,
18392 &neighbor_remove_private_as_replace_as_cmd);
18393 install_element(BGP_IPV4_NODE,
18394 &no_neighbor_remove_private_as_replace_as_cmd);
18395 install_element(BGP_IPV4_NODE,
18396 &neighbor_remove_private_as_all_replace_as_cmd);
18397 install_element(BGP_IPV4_NODE,
18398 &no_neighbor_remove_private_as_all_replace_as_cmd);
18399 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18400 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18401 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18402 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18403 install_element(BGP_IPV4M_NODE,
18404 &neighbor_remove_private_as_replace_as_cmd);
18405 install_element(BGP_IPV4M_NODE,
18406 &no_neighbor_remove_private_as_replace_as_cmd);
18407 install_element(BGP_IPV4M_NODE,
18408 &neighbor_remove_private_as_all_replace_as_cmd);
18409 install_element(BGP_IPV4M_NODE,
18410 &no_neighbor_remove_private_as_all_replace_as_cmd);
18411 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18412 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18413 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18414 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18415 install_element(BGP_IPV4L_NODE,
18416 &neighbor_remove_private_as_replace_as_cmd);
18417 install_element(BGP_IPV4L_NODE,
18418 &no_neighbor_remove_private_as_replace_as_cmd);
18419 install_element(BGP_IPV4L_NODE,
18420 &neighbor_remove_private_as_all_replace_as_cmd);
18421 install_element(BGP_IPV4L_NODE,
18422 &no_neighbor_remove_private_as_all_replace_as_cmd);
18423 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18424 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18425 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18426 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18427 install_element(BGP_IPV6_NODE,
18428 &neighbor_remove_private_as_replace_as_cmd);
18429 install_element(BGP_IPV6_NODE,
18430 &no_neighbor_remove_private_as_replace_as_cmd);
18431 install_element(BGP_IPV6_NODE,
18432 &neighbor_remove_private_as_all_replace_as_cmd);
18433 install_element(BGP_IPV6_NODE,
18434 &no_neighbor_remove_private_as_all_replace_as_cmd);
18435 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18436 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18437 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18438 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18439 install_element(BGP_IPV6M_NODE,
18440 &neighbor_remove_private_as_replace_as_cmd);
18441 install_element(BGP_IPV6M_NODE,
18442 &no_neighbor_remove_private_as_replace_as_cmd);
18443 install_element(BGP_IPV6M_NODE,
18444 &neighbor_remove_private_as_all_replace_as_cmd);
18445 install_element(BGP_IPV6M_NODE,
18446 &no_neighbor_remove_private_as_all_replace_as_cmd);
18447 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18448 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18449 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18450 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18451 install_element(BGP_IPV6L_NODE,
18452 &neighbor_remove_private_as_replace_as_cmd);
18453 install_element(BGP_IPV6L_NODE,
18454 &no_neighbor_remove_private_as_replace_as_cmd);
18455 install_element(BGP_IPV6L_NODE,
18456 &neighbor_remove_private_as_all_replace_as_cmd);
18457 install_element(BGP_IPV6L_NODE,
18458 &no_neighbor_remove_private_as_all_replace_as_cmd);
18459 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18460 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18461 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18462 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18463 install_element(BGP_VPNV4_NODE,
18464 &neighbor_remove_private_as_replace_as_cmd);
18465 install_element(BGP_VPNV4_NODE,
18466 &no_neighbor_remove_private_as_replace_as_cmd);
18467 install_element(BGP_VPNV4_NODE,
18468 &neighbor_remove_private_as_all_replace_as_cmd);
18469 install_element(BGP_VPNV4_NODE,
18470 &no_neighbor_remove_private_as_all_replace_as_cmd);
18471 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18472 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18473 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18474 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18475 install_element(BGP_VPNV6_NODE,
18476 &neighbor_remove_private_as_replace_as_cmd);
18477 install_element(BGP_VPNV6_NODE,
18478 &no_neighbor_remove_private_as_replace_as_cmd);
18479 install_element(BGP_VPNV6_NODE,
18480 &neighbor_remove_private_as_all_replace_as_cmd);
18481 install_element(BGP_VPNV6_NODE,
18482 &no_neighbor_remove_private_as_all_replace_as_cmd);
18483
18484 /* "neighbor send-community" commands.*/
18485 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18486 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18487 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18488 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18489 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18490 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18491 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18492 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18493 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18494 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18495 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18496 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18497 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18498 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18499 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18500 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18501 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18502 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18503 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18504 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18505 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18506 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18507 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18508 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18509 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18510 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18511 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18512 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18513 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18514 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18515 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18516 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18517 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18518 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18519 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18520 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18521
18522 /* "neighbor route-reflector" commands.*/
18523 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18524 install_element(BGP_NODE,
18525 &no_neighbor_route_reflector_client_hidden_cmd);
18526 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18527 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18528 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18529 install_element(BGP_IPV4M_NODE,
18530 &no_neighbor_route_reflector_client_cmd);
18531 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18532 install_element(BGP_IPV4L_NODE,
18533 &no_neighbor_route_reflector_client_cmd);
18534 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18535 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18536 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18537 install_element(BGP_IPV6M_NODE,
18538 &no_neighbor_route_reflector_client_cmd);
18539 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18540 install_element(BGP_IPV6L_NODE,
18541 &no_neighbor_route_reflector_client_cmd);
18542 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18543 install_element(BGP_VPNV4_NODE,
18544 &no_neighbor_route_reflector_client_cmd);
18545 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18546 install_element(BGP_VPNV6_NODE,
18547 &no_neighbor_route_reflector_client_cmd);
18548 install_element(BGP_FLOWSPECV4_NODE,
18549 &neighbor_route_reflector_client_cmd);
18550 install_element(BGP_FLOWSPECV4_NODE,
18551 &no_neighbor_route_reflector_client_cmd);
18552 install_element(BGP_FLOWSPECV6_NODE,
18553 &neighbor_route_reflector_client_cmd);
18554 install_element(BGP_FLOWSPECV6_NODE,
18555 &no_neighbor_route_reflector_client_cmd);
18556 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18557 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18558
18559 /* "neighbor route-server" commands.*/
18560 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18561 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18562 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18563 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18564 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18565 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18566 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18567 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18568 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18569 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18570 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18571 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18572 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18573 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18574 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18575 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18576 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18577 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18578 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18579 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18580 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18581 install_element(BGP_FLOWSPECV4_NODE,
18582 &no_neighbor_route_server_client_cmd);
18583 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18584 install_element(BGP_FLOWSPECV6_NODE,
18585 &no_neighbor_route_server_client_cmd);
18586
18587 /* "neighbor disable-addpath-rx" commands. */
18588 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18589 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18590 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18591 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18592 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18593 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18594 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18595 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18596 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18597 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18598 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18599 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18600 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18601 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18602 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18603 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18604
18605 /* "neighbor addpath-tx-all-paths" commands.*/
18606 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18607 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18608 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18609 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18610 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18611 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18612 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18613 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18614 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18615 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18616 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18617 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18618 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18619 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18620 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18621 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18622 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18623 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18624
18625 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18626 install_element(BGP_NODE,
18627 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18628 install_element(BGP_NODE,
18629 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18630 install_element(BGP_IPV4_NODE,
18631 &neighbor_addpath_tx_bestpath_per_as_cmd);
18632 install_element(BGP_IPV4_NODE,
18633 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18634 install_element(BGP_IPV4M_NODE,
18635 &neighbor_addpath_tx_bestpath_per_as_cmd);
18636 install_element(BGP_IPV4M_NODE,
18637 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18638 install_element(BGP_IPV4L_NODE,
18639 &neighbor_addpath_tx_bestpath_per_as_cmd);
18640 install_element(BGP_IPV4L_NODE,
18641 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18642 install_element(BGP_IPV6_NODE,
18643 &neighbor_addpath_tx_bestpath_per_as_cmd);
18644 install_element(BGP_IPV6_NODE,
18645 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18646 install_element(BGP_IPV6M_NODE,
18647 &neighbor_addpath_tx_bestpath_per_as_cmd);
18648 install_element(BGP_IPV6M_NODE,
18649 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18650 install_element(BGP_IPV6L_NODE,
18651 &neighbor_addpath_tx_bestpath_per_as_cmd);
18652 install_element(BGP_IPV6L_NODE,
18653 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18654 install_element(BGP_VPNV4_NODE,
18655 &neighbor_addpath_tx_bestpath_per_as_cmd);
18656 install_element(BGP_VPNV4_NODE,
18657 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18658 install_element(BGP_VPNV6_NODE,
18659 &neighbor_addpath_tx_bestpath_per_as_cmd);
18660 install_element(BGP_VPNV6_NODE,
18661 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18662
18663 /* "neighbor sender-as-path-loop-detection" commands. */
18664 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18665 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18666
18667 /* "neighbor passive" commands. */
18668 install_element(BGP_NODE, &neighbor_passive_cmd);
18669 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18670
18671
18672 /* "neighbor shutdown" commands. */
18673 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18674 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18675 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18676 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18677 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18678 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18679
18680 /* "neighbor capability extended-nexthop" commands.*/
18681 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18682 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18683
18684 /* "neighbor capability orf prefix-list" commands.*/
18685 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18686 install_element(BGP_NODE,
18687 &no_neighbor_capability_orf_prefix_hidden_cmd);
18688 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18689 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18690 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18691 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18692 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18693 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18694 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18695 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18696 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18697 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18698 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18699 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18700
18701 /* "neighbor capability dynamic" commands.*/
18702 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18703 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18704
18705 /* "neighbor dont-capability-negotiate" commands. */
18706 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18707 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18708
18709 /* "neighbor ebgp-multihop" commands. */
18710 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18711 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18712 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18713
18714 /* "neighbor disable-connected-check" commands. */
18715 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18716 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18717
18718 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18719 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18720 install_element(BGP_NODE,
18721 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
18722
18723 /* "neighbor extended-optional-parameters" commands. */
18724 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18725 install_element(BGP_NODE,
18726 &no_neighbor_extended_optional_parameters_cmd);
18727
18728 /* "neighbor enforce-first-as" commands. */
18729 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18730 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18731
18732 /* "neighbor description" commands. */
18733 install_element(BGP_NODE, &neighbor_description_cmd);
18734 install_element(BGP_NODE, &no_neighbor_description_cmd);
18735 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18736
18737 /* "neighbor update-source" commands. "*/
18738 install_element(BGP_NODE, &neighbor_update_source_cmd);
18739 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18740
18741 /* "neighbor default-originate" commands. */
18742 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18743 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18744 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18745 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18746 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18747 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18748 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18749 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18750 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18751 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18752 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18753 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18754 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18755 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18756 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18757 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18758 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18759 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18760 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18761 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18762 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18763
18764 /* "neighbor port" commands. */
18765 install_element(BGP_NODE, &neighbor_port_cmd);
18766 install_element(BGP_NODE, &no_neighbor_port_cmd);
18767
18768 /* "neighbor weight" commands. */
18769 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18770 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18771
18772 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18773 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18774 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18775 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18776 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18777 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18778 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18779 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18780 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18781 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18782 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18783 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18784 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18785 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18786 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18787 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18788
18789 /* "neighbor override-capability" commands. */
18790 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18791 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18792
18793 /* "neighbor strict-capability-match" commands. */
18794 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18795 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18796
18797 /* "neighbor timers" commands. */
18798 install_element(BGP_NODE, &neighbor_timers_cmd);
18799 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18800
18801 /* "neighbor timers connect" commands. */
18802 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18803 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18804
18805 /* "neighbor timers delayopen" commands. */
18806 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18807 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18808
18809 /* "neighbor advertisement-interval" commands. */
18810 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18811 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18812
18813 /* "neighbor interface" commands. */
18814 install_element(BGP_NODE, &neighbor_interface_cmd);
18815 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18816
18817 /* "neighbor distribute" commands. */
18818 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18819 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18820 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18821 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18822 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18823 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18824 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18825 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18826 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18827 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18828 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18829 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18830 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18831 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18832 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18833 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18834 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18835 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18836
18837 /* "neighbor prefix-list" commands. */
18838 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18839 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
18840 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18841 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
18842 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18843 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
18844 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18845 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
18846 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18847 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
18848 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18849 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
18850 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18851 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
18852 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18853 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
18854 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18855 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
18856 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18857 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
18858 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18859 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
18860
18861 /* "neighbor filter-list" commands. */
18862 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18863 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18864 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18865 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18866 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18867 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18868 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18869 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18870 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18871 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18872 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18873 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18874 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18875 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18876 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18877 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18878 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18879 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18880 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18881 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18882 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18883 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18884
18885 /* "neighbor route-map" commands. */
18886 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18887 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
18888 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18889 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
18890 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18891 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
18892 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18893 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
18894 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18895 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
18896 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18897 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
18898 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18899 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
18900 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18901 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
18902 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18903 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
18904 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18905 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
18906 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18907 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
18908 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18909 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
18910
18911 /* "neighbor unsuppress-map" commands. */
18912 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18913 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18914 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18915 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18916 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18917 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18918 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18919 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18920 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18921 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18922 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18923 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18924 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18925 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18926 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18927 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18928 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18929 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18930
18931 /* "neighbor advertise-map" commands. */
18932 install_element(BGP_NODE, &bgp_condadv_period_cmd);
18933 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18934 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18935 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18936 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18937 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18938 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18939 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18940 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18941 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18942
18943 /* neighbor maximum-prefix-out commands. */
18944 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18945 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18946 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18947 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18948 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18949 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18950 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18951 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18952 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18953 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18954 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18955 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18956 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18957 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18958 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18959 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18960 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18961 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18962
18963 /* "neighbor maximum-prefix" commands. */
18964 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18965 install_element(BGP_NODE,
18966 &neighbor_maximum_prefix_threshold_hidden_cmd);
18967 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18968 install_element(BGP_NODE,
18969 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18970 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18971 install_element(BGP_NODE,
18972 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18973 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18974 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18975 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18976 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18977 install_element(BGP_IPV4_NODE,
18978 &neighbor_maximum_prefix_threshold_warning_cmd);
18979 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18980 install_element(BGP_IPV4_NODE,
18981 &neighbor_maximum_prefix_threshold_restart_cmd);
18982 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18983 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18984 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18985 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18986 install_element(BGP_IPV4M_NODE,
18987 &neighbor_maximum_prefix_threshold_warning_cmd);
18988 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18989 install_element(BGP_IPV4M_NODE,
18990 &neighbor_maximum_prefix_threshold_restart_cmd);
18991 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18992 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18993 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18994 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18995 install_element(BGP_IPV4L_NODE,
18996 &neighbor_maximum_prefix_threshold_warning_cmd);
18997 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18998 install_element(BGP_IPV4L_NODE,
18999 &neighbor_maximum_prefix_threshold_restart_cmd);
19000 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19001 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19002 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19003 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19004 install_element(BGP_IPV6_NODE,
19005 &neighbor_maximum_prefix_threshold_warning_cmd);
19006 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19007 install_element(BGP_IPV6_NODE,
19008 &neighbor_maximum_prefix_threshold_restart_cmd);
19009 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19010 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19011 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19012 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19013 install_element(BGP_IPV6M_NODE,
19014 &neighbor_maximum_prefix_threshold_warning_cmd);
19015 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19016 install_element(BGP_IPV6M_NODE,
19017 &neighbor_maximum_prefix_threshold_restart_cmd);
19018 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19019 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19020 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19021 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19022 install_element(BGP_IPV6L_NODE,
19023 &neighbor_maximum_prefix_threshold_warning_cmd);
19024 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19025 install_element(BGP_IPV6L_NODE,
19026 &neighbor_maximum_prefix_threshold_restart_cmd);
19027 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19028 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19029 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19030 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19031 install_element(BGP_VPNV4_NODE,
19032 &neighbor_maximum_prefix_threshold_warning_cmd);
19033 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19034 install_element(BGP_VPNV4_NODE,
19035 &neighbor_maximum_prefix_threshold_restart_cmd);
19036 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19037 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19038 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19039 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19040 install_element(BGP_VPNV6_NODE,
19041 &neighbor_maximum_prefix_threshold_warning_cmd);
19042 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19043 install_element(BGP_VPNV6_NODE,
19044 &neighbor_maximum_prefix_threshold_restart_cmd);
19045 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19046
19047 /* "neighbor allowas-in" */
19048 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19049 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19050 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19051 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19052 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19053 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19054 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19055 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19056 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19057 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19058 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19059 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19060 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19061 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19062 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19063 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19064 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19065 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19066 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19067 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19068
19069 /* address-family commands. */
19070 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19071 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19072 #ifdef KEEP_OLD_VPN_COMMANDS
19073 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19074 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19075 #endif /* KEEP_OLD_VPN_COMMANDS */
19076
19077 install_element(BGP_NODE, &address_family_evpn_cmd);
19078
19079 /* "exit-address-family" command. */
19080 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19081 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19082 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19083 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19084 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19085 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19086 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19087 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19088 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19089 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19090 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19091
19092 /* "clear ip bgp commands" */
19093 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19094
19095 /* clear ip bgp prefix */
19096 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19097 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19098 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19099
19100 /* "show [ip] bgp summary" commands. */
19101 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19102 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19103 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19104 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19105 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19106 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19107 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19108
19109 /* "show [ip] bgp neighbors" commands. */
19110 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19111
19112 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19113
19114 /* "show [ip] bgp peer-group" commands. */
19115 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19116
19117 /* "show [ip] bgp paths" commands. */
19118 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19119
19120 /* "show [ip] bgp community" commands. */
19121 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19122
19123 /* "show ip bgp large-community" commands. */
19124 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19125 /* "show [ip] bgp attribute-info" commands. */
19126 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19127 /* "show [ip] bgp route-leak" command */
19128 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19129
19130 /* "redistribute" commands. */
19131 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19132 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19133 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19134 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19135 install_element(BGP_NODE,
19136 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19137 install_element(BGP_NODE,
19138 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19139 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19140 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19141 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19142 install_element(BGP_NODE,
19143 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19144 install_element(BGP_NODE,
19145 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19146 install_element(BGP_NODE,
19147 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19148 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19149 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19150 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19151 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19152 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19153 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19154 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19155 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19156 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19157 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19158 install_element(BGP_IPV4_NODE,
19159 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19160 install_element(BGP_IPV4_NODE,
19161 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19162 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19163 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19164 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19165 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19166 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19167 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19168
19169 /* import|export vpn [route-map RMAP_NAME] */
19170 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19171 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19172
19173 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19174 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19175
19176 /* ttl_security commands */
19177 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19178 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19179
19180 /* "show [ip] bgp memory" commands. */
19181 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19182
19183 /* "show bgp martian next-hop" */
19184 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19185
19186 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19187
19188 /* "show [ip] bgp views" commands. */
19189 install_element(VIEW_NODE, &show_bgp_views_cmd);
19190
19191 /* "show [ip] bgp vrfs" commands. */
19192 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19193
19194 /* Community-list. */
19195 community_list_vty();
19196
19197 community_alias_vty();
19198
19199 /* vpn-policy commands */
19200 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19201 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19202 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19203 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19204 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19205 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19206 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19207 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19208 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19209 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19210 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19211 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19212
19213 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19214 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19215
19216 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19217 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19218 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19219 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19220 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19221 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19222 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19223 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19224 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19225 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19226
19227 /* tcp-mss command */
19228 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19229 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19230
19231 /* srv6 commands */
19232 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19233 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19234 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19235 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19236 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19237 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19238 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19239 }
19240
19241 #include "memory.h"
19242 #include "bgp_regex.h"
19243 #include "bgp_clist.h"
19244 #include "bgp_ecommunity.h"
19245
19246 /* VTY functions. */
19247
19248 /* Direction value to string conversion. */
19249 static const char *community_direct_str(int direct)
19250 {
19251 switch (direct) {
19252 case COMMUNITY_DENY:
19253 return "deny";
19254 case COMMUNITY_PERMIT:
19255 return "permit";
19256 default:
19257 return "unknown";
19258 }
19259 }
19260
19261 /* Display error string. */
19262 static void community_list_perror(struct vty *vty, int ret)
19263 {
19264 switch (ret) {
19265 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19266 vty_out(vty, "%% Can't find community-list\n");
19267 break;
19268 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19269 vty_out(vty, "%% Malformed community-list value\n");
19270 break;
19271 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19272 vty_out(vty,
19273 "%% Community name conflict, previously defined as standard community\n");
19274 break;
19275 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19276 vty_out(vty,
19277 "%% Community name conflict, previously defined as expanded community\n");
19278 break;
19279 }
19280 }
19281
19282 /* "community-list" keyword help string. */
19283 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19284
19285 /*community-list standard */
19286 DEFUN (community_list_standard,
19287 bgp_community_list_standard_cmd,
19288 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19289 BGP_STR
19290 COMMUNITY_LIST_STR
19291 "Community list number (standard)\n"
19292 "Add an standard community-list entry\n"
19293 "Community list name\n"
19294 "Sequence number of an entry\n"
19295 "Sequence number\n"
19296 "Specify community to reject\n"
19297 "Specify community to accept\n"
19298 COMMUNITY_VAL_STR)
19299 {
19300 char *cl_name_or_number = NULL;
19301 char *seq = NULL;
19302 int direct = 0;
19303 int style = COMMUNITY_LIST_STANDARD;
19304 int idx = 0;
19305
19306 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19307 seq = argv[idx]->arg;
19308
19309 idx = 0;
19310 argv_find(argv, argc, "(1-99)", &idx);
19311 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19312 cl_name_or_number = argv[idx]->arg;
19313 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19314 : COMMUNITY_DENY;
19315 argv_find(argv, argc, "AA:NN", &idx);
19316 char *str = argv_concat(argv, argc, idx);
19317
19318 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19319 direct, style);
19320
19321 XFREE(MTYPE_TMP, str);
19322
19323 if (ret < 0) {
19324 /* Display error string. */
19325 community_list_perror(vty, ret);
19326 return CMD_WARNING_CONFIG_FAILED;
19327 }
19328
19329 return CMD_SUCCESS;
19330 }
19331
19332 DEFUN (no_community_list_standard_all,
19333 no_bgp_community_list_standard_all_cmd,
19334 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19335 NO_STR
19336 BGP_STR
19337 COMMUNITY_LIST_STR
19338 "Community list number (standard)\n"
19339 "Add an standard community-list entry\n"
19340 "Community list name\n"
19341 "Sequence number of an entry\n"
19342 "Sequence number\n"
19343 "Specify community to reject\n"
19344 "Specify community to accept\n"
19345 COMMUNITY_VAL_STR)
19346 {
19347 char *cl_name_or_number = NULL;
19348 char *str = NULL;
19349 int direct = 0;
19350 int style = COMMUNITY_LIST_STANDARD;
19351 char *seq = NULL;
19352 int idx = 0;
19353
19354 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19355 seq = argv[idx]->arg;
19356
19357 idx = 0;
19358 argv_find(argv, argc, "permit", &idx);
19359 argv_find(argv, argc, "deny", &idx);
19360
19361 if (idx) {
19362 direct = argv_find(argv, argc, "permit", &idx)
19363 ? COMMUNITY_PERMIT
19364 : COMMUNITY_DENY;
19365
19366 idx = 0;
19367 argv_find(argv, argc, "AA:NN", &idx);
19368 str = argv_concat(argv, argc, idx);
19369 }
19370
19371 idx = 0;
19372 argv_find(argv, argc, "(1-99)", &idx);
19373 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19374 cl_name_or_number = argv[idx]->arg;
19375
19376 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19377 direct, style);
19378
19379 XFREE(MTYPE_TMP, str);
19380
19381 if (ret < 0) {
19382 community_list_perror(vty, ret);
19383 return CMD_WARNING_CONFIG_FAILED;
19384 }
19385
19386 return CMD_SUCCESS;
19387 }
19388
19389 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19390 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19391 NO_STR BGP_STR COMMUNITY_LIST_STR
19392 "Community list number (standard)\n"
19393 "Add an standard community-list entry\n"
19394 "Community list name\n")
19395
19396 /*community-list expanded */
19397 DEFUN (community_list_expanded_all,
19398 bgp_community_list_expanded_all_cmd,
19399 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19400 BGP_STR
19401 COMMUNITY_LIST_STR
19402 "Community list number (expanded)\n"
19403 "Add an expanded community-list entry\n"
19404 "Community list name\n"
19405 "Sequence number of an entry\n"
19406 "Sequence number\n"
19407 "Specify community to reject\n"
19408 "Specify community to accept\n"
19409 COMMUNITY_VAL_STR)
19410 {
19411 char *cl_name_or_number = NULL;
19412 char *seq = NULL;
19413 int direct = 0;
19414 int style = COMMUNITY_LIST_EXPANDED;
19415 int idx = 0;
19416
19417 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19418 seq = argv[idx]->arg;
19419
19420 idx = 0;
19421
19422 argv_find(argv, argc, "(100-500)", &idx);
19423 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19424 cl_name_or_number = argv[idx]->arg;
19425 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19426 : COMMUNITY_DENY;
19427 argv_find(argv, argc, "AA:NN", &idx);
19428 char *str = argv_concat(argv, argc, idx);
19429
19430 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19431 direct, style);
19432
19433 XFREE(MTYPE_TMP, str);
19434
19435 if (ret < 0) {
19436 /* Display error string. */
19437 community_list_perror(vty, ret);
19438 return CMD_WARNING_CONFIG_FAILED;
19439 }
19440
19441 return CMD_SUCCESS;
19442 }
19443
19444 DEFUN (no_community_list_expanded_all,
19445 no_bgp_community_list_expanded_all_cmd,
19446 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19447 NO_STR
19448 BGP_STR
19449 COMMUNITY_LIST_STR
19450 "Community list number (expanded)\n"
19451 "Add an expanded community-list entry\n"
19452 "Community list name\n"
19453 "Sequence number of an entry\n"
19454 "Sequence number\n"
19455 "Specify community to reject\n"
19456 "Specify community to accept\n"
19457 COMMUNITY_VAL_STR)
19458 {
19459 char *cl_name_or_number = NULL;
19460 char *seq = NULL;
19461 char *str = NULL;
19462 int direct = 0;
19463 int style = COMMUNITY_LIST_EXPANDED;
19464 int idx = 0;
19465
19466 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19467 seq = argv[idx]->arg;
19468
19469 idx = 0;
19470 argv_find(argv, argc, "permit", &idx);
19471 argv_find(argv, argc, "deny", &idx);
19472
19473 if (idx) {
19474 direct = argv_find(argv, argc, "permit", &idx)
19475 ? COMMUNITY_PERMIT
19476 : COMMUNITY_DENY;
19477
19478 idx = 0;
19479 argv_find(argv, argc, "AA:NN", &idx);
19480 str = argv_concat(argv, argc, idx);
19481 }
19482
19483 idx = 0;
19484 argv_find(argv, argc, "(100-500)", &idx);
19485 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19486 cl_name_or_number = argv[idx]->arg;
19487
19488 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19489 direct, style);
19490
19491 XFREE(MTYPE_TMP, str);
19492
19493 if (ret < 0) {
19494 community_list_perror(vty, ret);
19495 return CMD_WARNING_CONFIG_FAILED;
19496 }
19497
19498 return CMD_SUCCESS;
19499 }
19500
19501 ALIAS(no_community_list_expanded_all,
19502 no_bgp_community_list_expanded_all_list_cmd,
19503 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19504 NO_STR BGP_STR COMMUNITY_LIST_STR
19505 "Community list number (expanded)\n"
19506 "Add an expanded community-list entry\n"
19507 "Community list name\n")
19508
19509 /* Return configuration string of community-list entry. */
19510 static const char *community_list_config_str(struct community_entry *entry)
19511 {
19512 const char *str;
19513
19514 if (entry->any)
19515 str = "";
19516 else {
19517 if (entry->style == COMMUNITY_LIST_STANDARD)
19518 str = community_str(entry->u.com, false, false);
19519 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19520 str = lcommunity_str(entry->u.lcom, false, false);
19521 else
19522 str = entry->config;
19523 }
19524 return str;
19525 }
19526
19527 static void community_list_show(struct vty *vty, struct community_list *list)
19528 {
19529 struct community_entry *entry;
19530
19531 for (entry = list->head; entry; entry = entry->next) {
19532 if (entry == list->head) {
19533 if (all_digit(list->name))
19534 vty_out(vty, "Community %s list %s\n",
19535 entry->style == COMMUNITY_LIST_STANDARD
19536 ? "standard"
19537 : "(expanded) access",
19538 list->name);
19539 else
19540 vty_out(vty, "Named Community %s list %s\n",
19541 entry->style == COMMUNITY_LIST_STANDARD
19542 ? "standard"
19543 : "expanded",
19544 list->name);
19545 }
19546 if (entry->any)
19547 vty_out(vty, " %s\n",
19548 community_direct_str(entry->direct));
19549 else
19550 vty_out(vty, " %s %s\n",
19551 community_direct_str(entry->direct),
19552 community_list_config_str(entry));
19553 }
19554 }
19555
19556 DEFUN (show_community_list,
19557 show_bgp_community_list_cmd,
19558 "show bgp community-list",
19559 SHOW_STR
19560 BGP_STR
19561 "List community-list\n")
19562 {
19563 struct community_list *list;
19564 struct community_list_master *cm;
19565
19566 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19567 if (!cm)
19568 return CMD_SUCCESS;
19569
19570 for (list = cm->num.head; list; list = list->next)
19571 community_list_show(vty, list);
19572
19573 for (list = cm->str.head; list; list = list->next)
19574 community_list_show(vty, list);
19575
19576 return CMD_SUCCESS;
19577 }
19578
19579 DEFUN (show_community_list_arg,
19580 show_bgp_community_list_arg_cmd,
19581 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
19582 SHOW_STR
19583 BGP_STR
19584 "List community-list\n"
19585 "Community-list number\n"
19586 "Community-list name\n"
19587 "Detailed information on community-list\n")
19588 {
19589 int idx_comm_list = 3;
19590 struct community_list *list;
19591
19592 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19593 COMMUNITY_LIST_MASTER);
19594 if (!list) {
19595 vty_out(vty, "%% Can't find community-list\n");
19596 return CMD_WARNING;
19597 }
19598
19599 community_list_show(vty, list);
19600
19601 return CMD_SUCCESS;
19602 }
19603
19604 /*
19605 * Large Community code.
19606 */
19607 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19608 struct cmd_token **argv, int style,
19609 int reject_all_digit_name)
19610 {
19611 int ret;
19612 int direct;
19613 char *str;
19614 int idx = 0;
19615 char *cl_name;
19616 char *seq = NULL;
19617
19618 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19619 seq = argv[idx]->arg;
19620
19621 idx = 0;
19622 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19623 : COMMUNITY_DENY;
19624
19625 /* All digit name check. */
19626 idx = 0;
19627 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19628 argv_find(argv, argc, "(1-99)", &idx);
19629 argv_find(argv, argc, "(100-500)", &idx);
19630 cl_name = argv[idx]->arg;
19631 if (reject_all_digit_name && all_digit(cl_name)) {
19632 vty_out(vty, "%% Community name cannot have all digits\n");
19633 return CMD_WARNING_CONFIG_FAILED;
19634 }
19635
19636 idx = 0;
19637 argv_find(argv, argc, "AA:BB:CC", &idx);
19638 argv_find(argv, argc, "LINE", &idx);
19639 /* Concat community string argument. */
19640 if (idx)
19641 str = argv_concat(argv, argc, idx);
19642 else
19643 str = NULL;
19644
19645 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19646
19647 /* Free temporary community list string allocated by
19648 argv_concat(). */
19649 XFREE(MTYPE_TMP, str);
19650
19651 if (ret < 0) {
19652 community_list_perror(vty, ret);
19653 return CMD_WARNING_CONFIG_FAILED;
19654 }
19655 return CMD_SUCCESS;
19656 }
19657
19658 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19659 struct cmd_token **argv, int style)
19660 {
19661 int ret;
19662 int direct = 0;
19663 char *str = NULL;
19664 int idx = 0;
19665 char *seq = NULL;
19666
19667 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19668 seq = argv[idx]->arg;
19669
19670 idx = 0;
19671 argv_find(argv, argc, "permit", &idx);
19672 argv_find(argv, argc, "deny", &idx);
19673
19674 if (idx) {
19675 /* Check the list direct. */
19676 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19677 direct = COMMUNITY_PERMIT;
19678 else
19679 direct = COMMUNITY_DENY;
19680
19681 idx = 0;
19682 argv_find(argv, argc, "LINE", &idx);
19683 argv_find(argv, argc, "AA:AA:NN", &idx);
19684 /* Concat community string argument. */
19685 str = argv_concat(argv, argc, idx);
19686 }
19687
19688 idx = 0;
19689 argv_find(argv, argc, "(1-99)", &idx);
19690 argv_find(argv, argc, "(100-500)", &idx);
19691 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19692
19693 /* Unset community list. */
19694 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19695 style);
19696
19697 /* Free temporary community list string allocated by
19698 argv_concat(). */
19699 XFREE(MTYPE_TMP, str);
19700
19701 if (ret < 0) {
19702 community_list_perror(vty, ret);
19703 return CMD_WARNING_CONFIG_FAILED;
19704 }
19705
19706 return CMD_SUCCESS;
19707 }
19708
19709 /* "large-community-list" keyword help string. */
19710 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19711 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19712
19713 DEFUN (lcommunity_list_standard,
19714 bgp_lcommunity_list_standard_cmd,
19715 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19716 BGP_STR
19717 LCOMMUNITY_LIST_STR
19718 "Large Community list number (standard)\n"
19719 "Sequence number of an entry\n"
19720 "Sequence number\n"
19721 "Specify large community to reject\n"
19722 "Specify large community to accept\n"
19723 LCOMMUNITY_VAL_STR)
19724 {
19725 return lcommunity_list_set_vty(vty, argc, argv,
19726 LARGE_COMMUNITY_LIST_STANDARD, 0);
19727 }
19728
19729 DEFUN (lcommunity_list_expanded,
19730 bgp_lcommunity_list_expanded_cmd,
19731 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19732 BGP_STR
19733 LCOMMUNITY_LIST_STR
19734 "Large Community list number (expanded)\n"
19735 "Sequence number of an entry\n"
19736 "Sequence number\n"
19737 "Specify large community to reject\n"
19738 "Specify large community to accept\n"
19739 "An ordered list as a regular-expression\n")
19740 {
19741 return lcommunity_list_set_vty(vty, argc, argv,
19742 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19743 }
19744
19745 DEFUN (lcommunity_list_name_standard,
19746 bgp_lcommunity_list_name_standard_cmd,
19747 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19748 BGP_STR
19749 LCOMMUNITY_LIST_STR
19750 "Specify standard large-community-list\n"
19751 "Large Community list name\n"
19752 "Sequence number of an entry\n"
19753 "Sequence number\n"
19754 "Specify large community to reject\n"
19755 "Specify large community to accept\n"
19756 LCOMMUNITY_VAL_STR)
19757 {
19758 return lcommunity_list_set_vty(vty, argc, argv,
19759 LARGE_COMMUNITY_LIST_STANDARD, 1);
19760 }
19761
19762 DEFUN (lcommunity_list_name_expanded,
19763 bgp_lcommunity_list_name_expanded_cmd,
19764 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19765 BGP_STR
19766 LCOMMUNITY_LIST_STR
19767 "Specify expanded large-community-list\n"
19768 "Large Community list name\n"
19769 "Sequence number of an entry\n"
19770 "Sequence number\n"
19771 "Specify large community to reject\n"
19772 "Specify large community to accept\n"
19773 "An ordered list as a regular-expression\n")
19774 {
19775 return lcommunity_list_set_vty(vty, argc, argv,
19776 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19777 }
19778
19779 DEFUN (no_lcommunity_list_all,
19780 no_bgp_lcommunity_list_all_cmd,
19781 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
19782 NO_STR
19783 BGP_STR
19784 LCOMMUNITY_LIST_STR
19785 "Large Community list number (standard)\n"
19786 "Large Community list number (expanded)\n"
19787 "Large Community list name\n")
19788 {
19789 return lcommunity_list_unset_vty(vty, argc, argv,
19790 LARGE_COMMUNITY_LIST_STANDARD);
19791 }
19792
19793 DEFUN (no_lcommunity_list_name_standard_all,
19794 no_bgp_lcommunity_list_name_standard_all_cmd,
19795 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
19796 NO_STR
19797 BGP_STR
19798 LCOMMUNITY_LIST_STR
19799 "Specify standard large-community-list\n"
19800 "Large Community list name\n")
19801 {
19802 return lcommunity_list_unset_vty(vty, argc, argv,
19803 LARGE_COMMUNITY_LIST_STANDARD);
19804 }
19805
19806 DEFUN (no_lcommunity_list_name_expanded_all,
19807 no_bgp_lcommunity_list_name_expanded_all_cmd,
19808 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
19809 NO_STR
19810 BGP_STR
19811 LCOMMUNITY_LIST_STR
19812 "Specify expanded large-community-list\n"
19813 "Large Community list name\n")
19814 {
19815 return lcommunity_list_unset_vty(vty, argc, argv,
19816 LARGE_COMMUNITY_LIST_EXPANDED);
19817 }
19818
19819 DEFUN (no_lcommunity_list_standard,
19820 no_bgp_lcommunity_list_standard_cmd,
19821 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19822 NO_STR
19823 BGP_STR
19824 LCOMMUNITY_LIST_STR
19825 "Large Community list number (standard)\n"
19826 "Sequence number of an entry\n"
19827 "Sequence number\n"
19828 "Specify large community to reject\n"
19829 "Specify large community to accept\n"
19830 LCOMMUNITY_VAL_STR)
19831 {
19832 return lcommunity_list_unset_vty(vty, argc, argv,
19833 LARGE_COMMUNITY_LIST_STANDARD);
19834 }
19835
19836 DEFUN (no_lcommunity_list_expanded,
19837 no_bgp_lcommunity_list_expanded_cmd,
19838 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19839 NO_STR
19840 BGP_STR
19841 LCOMMUNITY_LIST_STR
19842 "Large Community list number (expanded)\n"
19843 "Sequence number of an entry\n"
19844 "Sequence number\n"
19845 "Specify large community to reject\n"
19846 "Specify large community to accept\n"
19847 "An ordered list as a regular-expression\n")
19848 {
19849 return lcommunity_list_unset_vty(vty, argc, argv,
19850 LARGE_COMMUNITY_LIST_EXPANDED);
19851 }
19852
19853 DEFUN (no_lcommunity_list_name_standard,
19854 no_bgp_lcommunity_list_name_standard_cmd,
19855 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19856 NO_STR
19857 BGP_STR
19858 LCOMMUNITY_LIST_STR
19859 "Specify standard large-community-list\n"
19860 "Large Community list name\n"
19861 "Sequence number of an entry\n"
19862 "Sequence number\n"
19863 "Specify large community to reject\n"
19864 "Specify large community to accept\n"
19865 LCOMMUNITY_VAL_STR)
19866 {
19867 return lcommunity_list_unset_vty(vty, argc, argv,
19868 LARGE_COMMUNITY_LIST_STANDARD);
19869 }
19870
19871 DEFUN (no_lcommunity_list_name_expanded,
19872 no_bgp_lcommunity_list_name_expanded_cmd,
19873 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19874 NO_STR
19875 BGP_STR
19876 LCOMMUNITY_LIST_STR
19877 "Specify expanded large-community-list\n"
19878 "Large community list name\n"
19879 "Sequence number of an entry\n"
19880 "Sequence number\n"
19881 "Specify large community to reject\n"
19882 "Specify large community to accept\n"
19883 "An ordered list as a regular-expression\n")
19884 {
19885 return lcommunity_list_unset_vty(vty, argc, argv,
19886 LARGE_COMMUNITY_LIST_EXPANDED);
19887 }
19888
19889 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19890 {
19891 struct community_entry *entry;
19892
19893 for (entry = list->head; entry; entry = entry->next) {
19894 if (entry == list->head) {
19895 if (all_digit(list->name))
19896 vty_out(vty, "Large community %s list %s\n",
19897 entry->style ==
19898 LARGE_COMMUNITY_LIST_STANDARD
19899 ? "standard"
19900 : "(expanded) access",
19901 list->name);
19902 else
19903 vty_out(vty,
19904 "Named large community %s list %s\n",
19905 entry->style ==
19906 LARGE_COMMUNITY_LIST_STANDARD
19907 ? "standard"
19908 : "expanded",
19909 list->name);
19910 }
19911 if (entry->any)
19912 vty_out(vty, " %s\n",
19913 community_direct_str(entry->direct));
19914 else
19915 vty_out(vty, " %s %s\n",
19916 community_direct_str(entry->direct),
19917 community_list_config_str(entry));
19918 }
19919 }
19920
19921 DEFUN (show_lcommunity_list,
19922 show_bgp_lcommunity_list_cmd,
19923 "show bgp large-community-list",
19924 SHOW_STR
19925 BGP_STR
19926 "List large-community list\n")
19927 {
19928 struct community_list *list;
19929 struct community_list_master *cm;
19930
19931 cm = community_list_master_lookup(bgp_clist,
19932 LARGE_COMMUNITY_LIST_MASTER);
19933 if (!cm)
19934 return CMD_SUCCESS;
19935
19936 for (list = cm->num.head; list; list = list->next)
19937 lcommunity_list_show(vty, list);
19938
19939 for (list = cm->str.head; list; list = list->next)
19940 lcommunity_list_show(vty, list);
19941
19942 return CMD_SUCCESS;
19943 }
19944
19945 DEFUN (show_lcommunity_list_arg,
19946 show_bgp_lcommunity_list_arg_cmd,
19947 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
19948 SHOW_STR
19949 BGP_STR
19950 "List large-community list\n"
19951 "Large-community-list number\n"
19952 "Large-community-list name\n"
19953 "Detailed information on large-community-list\n")
19954 {
19955 struct community_list *list;
19956
19957 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19958 LARGE_COMMUNITY_LIST_MASTER);
19959 if (!list) {
19960 vty_out(vty, "%% Can't find large-community-list\n");
19961 return CMD_WARNING;
19962 }
19963
19964 lcommunity_list_show(vty, list);
19965
19966 return CMD_SUCCESS;
19967 }
19968
19969 /* "extcommunity-list" keyword help string. */
19970 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19971 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19972
19973 DEFUN (extcommunity_list_standard,
19974 bgp_extcommunity_list_standard_cmd,
19975 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19976 BGP_STR
19977 EXTCOMMUNITY_LIST_STR
19978 "Extended Community list number (standard)\n"
19979 "Specify standard extcommunity-list\n"
19980 "Community list name\n"
19981 "Sequence number of an entry\n"
19982 "Sequence number\n"
19983 "Specify community to reject\n"
19984 "Specify community to accept\n"
19985 EXTCOMMUNITY_VAL_STR)
19986 {
19987 int style = EXTCOMMUNITY_LIST_STANDARD;
19988 int direct = 0;
19989 char *cl_number_or_name = NULL;
19990 char *seq = NULL;
19991
19992 int idx = 0;
19993
19994 argv_find(argv, argc, "(1-99)", &idx);
19995 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
19996 cl_number_or_name = argv[idx]->arg;
19997
19998 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19999 seq = argv[idx]->arg;
20000
20001 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20002 : COMMUNITY_DENY;
20003 argv_find(argv, argc, "AA:NN", &idx);
20004 char *str = argv_concat(argv, argc, idx);
20005
20006 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20007 direct, style);
20008
20009 XFREE(MTYPE_TMP, str);
20010
20011 if (ret < 0) {
20012 community_list_perror(vty, ret);
20013 return CMD_WARNING_CONFIG_FAILED;
20014 }
20015
20016 return CMD_SUCCESS;
20017 }
20018
20019 DEFUN (extcommunity_list_name_expanded,
20020 bgp_extcommunity_list_name_expanded_cmd,
20021 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20022 BGP_STR
20023 EXTCOMMUNITY_LIST_STR
20024 "Extended Community list number (expanded)\n"
20025 "Specify expanded extcommunity-list\n"
20026 "Extended Community list name\n"
20027 "Sequence number of an entry\n"
20028 "Sequence number\n"
20029 "Specify community to reject\n"
20030 "Specify community to accept\n"
20031 "An ordered list as a regular-expression\n")
20032 {
20033 int style = EXTCOMMUNITY_LIST_EXPANDED;
20034 int direct = 0;
20035 char *cl_number_or_name = NULL;
20036 char *seq = NULL;
20037 int idx = 0;
20038
20039 argv_find(argv, argc, "(100-500)", &idx);
20040 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20041 cl_number_or_name = argv[idx]->arg;
20042
20043 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20044 seq = argv[idx]->arg;
20045
20046 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20047 : COMMUNITY_DENY;
20048 argv_find(argv, argc, "LINE", &idx);
20049 char *str = argv_concat(argv, argc, idx);
20050
20051 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20052 direct, style);
20053
20054 XFREE(MTYPE_TMP, str);
20055
20056 if (ret < 0) {
20057 community_list_perror(vty, ret);
20058 return CMD_WARNING_CONFIG_FAILED;
20059 }
20060
20061 return CMD_SUCCESS;
20062 }
20063
20064 DEFUN (no_extcommunity_list_standard_all,
20065 no_bgp_extcommunity_list_standard_all_cmd,
20066 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20067 NO_STR
20068 BGP_STR
20069 EXTCOMMUNITY_LIST_STR
20070 "Extended Community list number (standard)\n"
20071 "Specify standard extcommunity-list\n"
20072 "Community list name\n"
20073 "Sequence number of an entry\n"
20074 "Sequence number\n"
20075 "Specify community to reject\n"
20076 "Specify community to accept\n"
20077 EXTCOMMUNITY_VAL_STR)
20078 {
20079 int style = EXTCOMMUNITY_LIST_STANDARD;
20080 int direct = 0;
20081 char *cl_number_or_name = NULL;
20082 char *str = NULL;
20083 char *seq = NULL;
20084 int idx = 0;
20085
20086 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20087 seq = argv[idx]->arg;
20088
20089 idx = 0;
20090 argv_find(argv, argc, "permit", &idx);
20091 argv_find(argv, argc, "deny", &idx);
20092 if (idx) {
20093 direct = argv_find(argv, argc, "permit", &idx)
20094 ? COMMUNITY_PERMIT
20095 : COMMUNITY_DENY;
20096
20097 idx = 0;
20098 argv_find(argv, argc, "AA:NN", &idx);
20099 str = argv_concat(argv, argc, idx);
20100 }
20101
20102 idx = 0;
20103 argv_find(argv, argc, "(1-99)", &idx);
20104 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20105 cl_number_or_name = argv[idx]->arg;
20106
20107 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20108 seq, direct, style);
20109
20110 XFREE(MTYPE_TMP, str);
20111
20112 if (ret < 0) {
20113 community_list_perror(vty, ret);
20114 return CMD_WARNING_CONFIG_FAILED;
20115 }
20116
20117 return CMD_SUCCESS;
20118 }
20119
20120 ALIAS(no_extcommunity_list_standard_all,
20121 no_bgp_extcommunity_list_standard_all_list_cmd,
20122 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20123 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20124 "Extended Community list number (standard)\n"
20125 "Specify standard extcommunity-list\n"
20126 "Community list name\n")
20127
20128 DEFUN (no_extcommunity_list_expanded_all,
20129 no_bgp_extcommunity_list_expanded_all_cmd,
20130 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20131 NO_STR
20132 BGP_STR
20133 EXTCOMMUNITY_LIST_STR
20134 "Extended Community list number (expanded)\n"
20135 "Specify expanded extcommunity-list\n"
20136 "Extended Community list name\n"
20137 "Sequence number of an entry\n"
20138 "Sequence number\n"
20139 "Specify community to reject\n"
20140 "Specify community to accept\n"
20141 "An ordered list as a regular-expression\n")
20142 {
20143 int style = EXTCOMMUNITY_LIST_EXPANDED;
20144 int direct = 0;
20145 char *cl_number_or_name = NULL;
20146 char *str = NULL;
20147 char *seq = NULL;
20148 int idx = 0;
20149
20150 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20151 seq = argv[idx]->arg;
20152
20153 idx = 0;
20154 argv_find(argv, argc, "permit", &idx);
20155 argv_find(argv, argc, "deny", &idx);
20156
20157 if (idx) {
20158 direct = argv_find(argv, argc, "permit", &idx)
20159 ? COMMUNITY_PERMIT
20160 : COMMUNITY_DENY;
20161
20162 idx = 0;
20163 argv_find(argv, argc, "LINE", &idx);
20164 str = argv_concat(argv, argc, idx);
20165 }
20166
20167 idx = 0;
20168 argv_find(argv, argc, "(100-500)", &idx);
20169 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20170 cl_number_or_name = argv[idx]->arg;
20171
20172 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20173 seq, direct, style);
20174
20175 XFREE(MTYPE_TMP, str);
20176
20177 if (ret < 0) {
20178 community_list_perror(vty, ret);
20179 return CMD_WARNING_CONFIG_FAILED;
20180 }
20181
20182 return CMD_SUCCESS;
20183 }
20184
20185 ALIAS(no_extcommunity_list_expanded_all,
20186 no_bgp_extcommunity_list_expanded_all_list_cmd,
20187 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20188 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20189 "Extended Community list number (expanded)\n"
20190 "Specify expanded extcommunity-list\n"
20191 "Extended Community list name\n")
20192
20193 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20194 {
20195 struct community_entry *entry;
20196
20197 for (entry = list->head; entry; entry = entry->next) {
20198 if (entry == list->head) {
20199 if (all_digit(list->name))
20200 vty_out(vty, "Extended community %s list %s\n",
20201 entry->style == EXTCOMMUNITY_LIST_STANDARD
20202 ? "standard"
20203 : "(expanded) access",
20204 list->name);
20205 else
20206 vty_out(vty,
20207 "Named extended community %s list %s\n",
20208 entry->style == EXTCOMMUNITY_LIST_STANDARD
20209 ? "standard"
20210 : "expanded",
20211 list->name);
20212 }
20213 if (entry->any)
20214 vty_out(vty, " %s\n",
20215 community_direct_str(entry->direct));
20216 else
20217 vty_out(vty, " %s %s\n",
20218 community_direct_str(entry->direct),
20219 community_list_config_str(entry));
20220 }
20221 }
20222
20223 DEFUN (show_extcommunity_list,
20224 show_bgp_extcommunity_list_cmd,
20225 "show bgp extcommunity-list",
20226 SHOW_STR
20227 BGP_STR
20228 "List extended-community list\n")
20229 {
20230 struct community_list *list;
20231 struct community_list_master *cm;
20232
20233 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20234 if (!cm)
20235 return CMD_SUCCESS;
20236
20237 for (list = cm->num.head; list; list = list->next)
20238 extcommunity_list_show(vty, list);
20239
20240 for (list = cm->str.head; list; list = list->next)
20241 extcommunity_list_show(vty, list);
20242
20243 return CMD_SUCCESS;
20244 }
20245
20246 DEFUN (show_extcommunity_list_arg,
20247 show_bgp_extcommunity_list_arg_cmd,
20248 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20249 SHOW_STR
20250 BGP_STR
20251 "List extended-community list\n"
20252 "Extcommunity-list number\n"
20253 "Extcommunity-list name\n"
20254 "Detailed information on extcommunity-list\n")
20255 {
20256 int idx_comm_list = 3;
20257 struct community_list *list;
20258
20259 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20260 EXTCOMMUNITY_LIST_MASTER);
20261 if (!list) {
20262 vty_out(vty, "%% Can't find extcommunity-list\n");
20263 return CMD_WARNING;
20264 }
20265
20266 extcommunity_list_show(vty, list);
20267
20268 return CMD_SUCCESS;
20269 }
20270
20271 /* Display community-list and extcommunity-list configuration. */
20272 static int community_list_config_write(struct vty *vty)
20273 {
20274 struct community_list *list;
20275 struct community_entry *entry;
20276 struct community_list_master *cm;
20277 int write = 0;
20278
20279 /* Community-list. */
20280 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20281
20282 for (list = cm->num.head; list; list = list->next)
20283 for (entry = list->head; entry; entry = entry->next) {
20284 vty_out(vty,
20285 "bgp community-list %s seq %" PRId64 " %s %s\n",
20286 list->name, entry->seq,
20287 community_direct_str(entry->direct),
20288 community_list_config_str(entry));
20289 write++;
20290 }
20291 for (list = cm->str.head; list; list = list->next)
20292 for (entry = list->head; entry; entry = entry->next) {
20293 vty_out(vty,
20294 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20295 entry->style == COMMUNITY_LIST_STANDARD
20296 ? "standard"
20297 : "expanded",
20298 list->name, entry->seq,
20299 community_direct_str(entry->direct),
20300 community_list_config_str(entry));
20301 write++;
20302 }
20303
20304 /* Extcommunity-list. */
20305 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20306
20307 for (list = cm->num.head; list; list = list->next)
20308 for (entry = list->head; entry; entry = entry->next) {
20309 vty_out(vty,
20310 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20311 list->name, entry->seq,
20312 community_direct_str(entry->direct),
20313 community_list_config_str(entry));
20314 write++;
20315 }
20316 for (list = cm->str.head; list; list = list->next)
20317 for (entry = list->head; entry; entry = entry->next) {
20318 vty_out(vty,
20319 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20320 entry->style == EXTCOMMUNITY_LIST_STANDARD
20321 ? "standard"
20322 : "expanded",
20323 list->name, entry->seq,
20324 community_direct_str(entry->direct),
20325 community_list_config_str(entry));
20326 write++;
20327 }
20328
20329
20330 /* lcommunity-list. */
20331 cm = community_list_master_lookup(bgp_clist,
20332 LARGE_COMMUNITY_LIST_MASTER);
20333
20334 for (list = cm->num.head; list; list = list->next)
20335 for (entry = list->head; entry; entry = entry->next) {
20336 vty_out(vty,
20337 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20338 list->name, entry->seq,
20339 community_direct_str(entry->direct),
20340 community_list_config_str(entry));
20341 write++;
20342 }
20343 for (list = cm->str.head; list; list = list->next)
20344 for (entry = list->head; entry; entry = entry->next) {
20345 vty_out(vty,
20346 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20347
20348 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20349 ? "standard"
20350 : "expanded",
20351 list->name, entry->seq, community_direct_str(entry->direct),
20352 community_list_config_str(entry));
20353 write++;
20354 }
20355
20356 return write;
20357 }
20358
20359 static int community_list_config_write(struct vty *vty);
20360 static struct cmd_node community_list_node = {
20361 .name = "community list",
20362 .node = COMMUNITY_LIST_NODE,
20363 .prompt = "",
20364 .config_write = community_list_config_write,
20365 };
20366
20367 static void community_list_vty(void)
20368 {
20369 install_node(&community_list_node);
20370
20371 /* Community-list. */
20372 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20373 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20374 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20375 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20376 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20377 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20378 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20379 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20380
20381 /* Extcommunity-list. */
20382 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20383 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20384 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20385 install_element(CONFIG_NODE,
20386 &no_bgp_extcommunity_list_standard_all_list_cmd);
20387 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20388 install_element(CONFIG_NODE,
20389 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20390 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20391 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20392
20393 /* Large Community List */
20394 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20395 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20396 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20397 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20398 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20399 install_element(CONFIG_NODE,
20400 &no_bgp_lcommunity_list_name_standard_all_cmd);
20401 install_element(CONFIG_NODE,
20402 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20403 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20404 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20405 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20406 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20407 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20408 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20409
20410 bgp_community_list_command_completion_setup();
20411 }
20412
20413 static struct cmd_node community_alias_node = {
20414 .name = "community alias",
20415 .node = COMMUNITY_ALIAS_NODE,
20416 .prompt = "",
20417 .config_write = bgp_community_alias_write,
20418 };
20419
20420 void community_alias_vty(void)
20421 {
20422 install_node(&community_alias_node);
20423
20424 /* Community-list. */
20425 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20426
20427 bgp_community_alias_command_completion_setup();
20428 }