]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #11494 from ak503/ospf_bfd
[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 case BGP_ERR_INVALID_ROLE_NAME:
927 str = "Invalid role name";
928 break;
929 case BGP_ERR_INVALID_INTERNAL_ROLE:
930 str = "External roles can be set only on eBGP session";
931 break;
932 }
933 if (str) {
934 vty_out(vty, "%% %s\n", str);
935 return CMD_WARNING_CONFIG_FAILED;
936 }
937 return CMD_SUCCESS;
938 }
939
940 /* BGP clear sort. */
941 enum clear_sort {
942 clear_all,
943 clear_peer,
944 clear_group,
945 clear_external,
946 clear_as
947 };
948
949 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
950 safi_t safi, int error)
951 {
952 switch (error) {
953 case BGP_ERR_AF_UNCONFIGURED:
954 vty_out(vty,
955 "%% BGP: Enable %s address family for the neighbor %s\n",
956 get_afi_safi_str(afi, safi, false), peer->host);
957 break;
958 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
959 vty_out(vty,
960 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
961 peer->host);
962 break;
963 default:
964 break;
965 }
966 }
967
968 static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
969 struct listnode **nnode, enum bgp_clear_type stype)
970 {
971 int ret = 0;
972 struct peer_af *paf;
973
974 /* if afi/.safi not specified, spin thru all of them */
975 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
976 afi_t tmp_afi;
977 safi_t tmp_safi;
978 enum bgp_af_index index;
979
980 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
981 paf = peer->peer_af_array[index];
982 if (!paf)
983 continue;
984
985 if (paf && paf->subgroup)
986 SET_FLAG(paf->subgroup->sflags,
987 SUBGRP_STATUS_FORCE_UPDATES);
988
989 tmp_afi = paf->afi;
990 tmp_safi = paf->safi;
991 if (!peer->afc[tmp_afi][tmp_safi])
992 continue;
993
994 if (stype == BGP_CLEAR_SOFT_NONE)
995 ret = peer_clear(peer, nnode);
996 else
997 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
998 stype);
999 }
1000 /* if afi specified and safi not, spin thru safis on this afi */
1001 } else if (safi == SAFI_UNSPEC) {
1002 safi_t tmp_safi;
1003
1004 for (tmp_safi = SAFI_UNICAST;
1005 tmp_safi < SAFI_MAX; tmp_safi++) {
1006 if (!peer->afc[afi][tmp_safi])
1007 continue;
1008
1009 paf = peer_af_find(peer, afi, tmp_safi);
1010 if (paf && paf->subgroup)
1011 SET_FLAG(paf->subgroup->sflags,
1012 SUBGRP_STATUS_FORCE_UPDATES);
1013
1014 if (stype == BGP_CLEAR_SOFT_NONE)
1015 ret = peer_clear(peer, nnode);
1016 else
1017 ret = peer_clear_soft(peer, afi,
1018 tmp_safi, stype);
1019 }
1020 /* both afi/safi specified, let the caller know if not defined */
1021 } else {
1022 if (!peer->afc[afi][safi])
1023 return 1;
1024
1025 paf = peer_af_find(peer, afi, safi);
1026 if (paf && paf->subgroup)
1027 SET_FLAG(paf->subgroup->sflags,
1028 SUBGRP_STATUS_FORCE_UPDATES);
1029
1030 if (stype == BGP_CLEAR_SOFT_NONE)
1031 ret = peer_clear(peer, nnode);
1032 else
1033 ret = peer_clear_soft(peer, afi, safi, stype);
1034 }
1035
1036 return ret;
1037 }
1038
1039 /* `clear ip bgp' functions. */
1040 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1041 enum clear_sort sort, enum bgp_clear_type stype,
1042 const char *arg)
1043 {
1044 int ret = 0;
1045 bool found = false;
1046 struct peer *peer;
1047
1048 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
1049
1050 /* Clear all neighbors. */
1051 /*
1052 * Pass along pointer to next node to peer_clear() when walking all
1053 * nodes on the BGP instance as that may get freed if it is a
1054 * doppelganger
1055 */
1056 if (sort == clear_all) {
1057 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1058
1059 bgp_peer_gr_flags_update(peer);
1060
1061 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1062 gr_router_detected = true;
1063
1064 ret = bgp_peer_clear(peer, afi, safi, &nnode,
1065 stype);
1066
1067 if (ret < 0)
1068 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1069 }
1070
1071 if (gr_router_detected
1072 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1073 bgp_zebra_send_capabilities(bgp, false);
1074 } else if (!gr_router_detected
1075 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1076 bgp_zebra_send_capabilities(bgp, true);
1077 }
1078
1079 /* This is to apply read-only mode on this clear. */
1080 if (stype == BGP_CLEAR_SOFT_NONE)
1081 bgp->update_delay_over = 0;
1082
1083 return CMD_SUCCESS;
1084 }
1085
1086 /* Clear specified neighbor. */
1087 if (sort == clear_peer) {
1088 union sockunion su;
1089
1090 /* Make sockunion for lookup. */
1091 ret = str2sockunion(arg, &su);
1092 if (ret < 0) {
1093 peer = peer_lookup_by_conf_if(bgp, arg);
1094 if (!peer) {
1095 peer = peer_lookup_by_hostname(bgp, arg);
1096 if (!peer) {
1097 vty_out(vty,
1098 "Malformed address or name: %s\n",
1099 arg);
1100 return CMD_WARNING;
1101 }
1102 }
1103 } else {
1104 peer = peer_lookup(bgp, &su);
1105 if (!peer) {
1106 vty_out(vty,
1107 "%% BGP: Unknown neighbor - \"%s\"\n",
1108 arg);
1109 return CMD_WARNING;
1110 }
1111 }
1112
1113 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1114 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1115
1116 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1117
1118 /* if afi/safi not defined for this peer, let caller know */
1119 if (ret == 1)
1120 ret = BGP_ERR_AF_UNCONFIGURED;
1121
1122 if (ret < 0)
1123 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1124
1125 return CMD_SUCCESS;
1126 }
1127
1128 /* Clear all neighbors belonging to a specific peer-group. */
1129 if (sort == clear_group) {
1130 struct peer_group *group;
1131
1132 group = peer_group_lookup(bgp, arg);
1133 if (!group) {
1134 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
1135 return CMD_WARNING;
1136 }
1137
1138 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1139 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1140
1141 if (ret < 0)
1142 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1143 else
1144 found = true;
1145 }
1146
1147 if (!found)
1148 vty_out(vty,
1149 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
1150 get_afi_safi_str(afi, safi, false), arg);
1151
1152 return CMD_SUCCESS;
1153 }
1154
1155 /* Clear all external (eBGP) neighbors. */
1156 if (sort == clear_external) {
1157 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1158 if (peer->sort == BGP_PEER_IBGP)
1159 continue;
1160
1161 bgp_peer_gr_flags_update(peer);
1162
1163 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1164 gr_router_detected = true;
1165
1166 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1167
1168 if (ret < 0)
1169 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1170 else
1171 found = true;
1172 }
1173
1174 if (gr_router_detected
1175 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1176 bgp_zebra_send_capabilities(bgp, false);
1177 } else if (!gr_router_detected
1178 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1179 bgp_zebra_send_capabilities(bgp, true);
1180 }
1181
1182 if (!found)
1183 vty_out(vty,
1184 "%% BGP: No external %s peer is configured\n",
1185 get_afi_safi_str(afi, safi, false));
1186
1187 return CMD_SUCCESS;
1188 }
1189
1190 /* Clear all neighbors belonging to a specific AS. */
1191 if (sort == clear_as) {
1192 as_t as = strtoul(arg, NULL, 10);
1193
1194 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1195 if (peer->as != as)
1196 continue;
1197
1198 bgp_peer_gr_flags_update(peer);
1199
1200 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1201 gr_router_detected = true;
1202
1203 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1204
1205 if (ret < 0)
1206 bgp_clear_vty_error(vty, peer, afi, safi, ret);
1207 else
1208 found = true;
1209 }
1210
1211 if (gr_router_detected
1212 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1213 bgp_zebra_send_capabilities(bgp, false);
1214 } else if (!gr_router_detected
1215 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1216 bgp_zebra_send_capabilities(bgp, true);
1217 }
1218
1219 if (!found)
1220 vty_out(vty,
1221 "%% BGP: No %s peer is configured with AS %s\n",
1222 get_afi_safi_str(afi, safi, false), arg);
1223
1224 return CMD_SUCCESS;
1225 }
1226
1227 return CMD_SUCCESS;
1228 }
1229
1230 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1231 safi_t safi, enum clear_sort sort,
1232 enum bgp_clear_type stype, const char *arg)
1233 {
1234 struct bgp *bgp;
1235
1236 /* BGP structure lookup. */
1237 if (name) {
1238 bgp = bgp_lookup_by_name(name);
1239 if (bgp == NULL) {
1240 vty_out(vty, "Can't find BGP instance %s\n", name);
1241 return CMD_WARNING;
1242 }
1243 } else {
1244 bgp = bgp_get_default();
1245 if (bgp == NULL) {
1246 vty_out(vty, "No BGP process is configured\n");
1247 return CMD_WARNING;
1248 }
1249 }
1250
1251 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
1252 }
1253
1254 /* clear soft inbound */
1255 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
1256 {
1257 afi_t afi;
1258 safi_t safi;
1259
1260 FOREACH_AFI_SAFI (afi, safi)
1261 bgp_clear_vty(vty, name, afi, safi, clear_all,
1262 BGP_CLEAR_SOFT_IN, NULL);
1263 }
1264
1265 /* clear soft outbound */
1266 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
1267 {
1268 afi_t afi;
1269 safi_t safi;
1270
1271 FOREACH_AFI_SAFI (afi, safi)
1272 bgp_clear_vty(vty, name, afi, safi, clear_all,
1273 BGP_CLEAR_SOFT_OUT, NULL);
1274 }
1275
1276
1277 #ifndef VTYSH_EXTRACT_PL
1278 #include "bgpd/bgp_vty_clippy.c"
1279 #endif
1280
1281 DEFUN_HIDDEN (bgp_local_mac,
1282 bgp_local_mac_cmd,
1283 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1284 BGP_STR
1285 "Local MAC config\n"
1286 "VxLAN Network Identifier\n"
1287 "VNI number\n"
1288 "local mac\n"
1289 "mac address\n"
1290 "mac-mobility sequence\n"
1291 "seq number\n")
1292 {
1293 int rv;
1294 vni_t vni;
1295 struct ethaddr mac;
1296 struct ipaddr ip;
1297 uint32_t seq;
1298 struct bgp *bgp;
1299
1300 vni = strtoul(argv[3]->arg, NULL, 10);
1301 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1302 vty_out(vty, "%% Malformed MAC address\n");
1303 return CMD_WARNING;
1304 }
1305 memset(&ip, 0, sizeof(ip));
1306 seq = strtoul(argv[7]->arg, NULL, 10);
1307
1308 bgp = bgp_get_default();
1309 if (!bgp) {
1310 vty_out(vty, "Default BGP instance is not there\n");
1311 return CMD_WARNING;
1312 }
1313
1314 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1315 zero_esi);
1316 if (rv < 0) {
1317 vty_out(vty, "Internal error\n");
1318 return CMD_WARNING;
1319 }
1320
1321 return CMD_SUCCESS;
1322 }
1323
1324 DEFUN_HIDDEN (no_bgp_local_mac,
1325 no_bgp_local_mac_cmd,
1326 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1327 NO_STR
1328 BGP_STR
1329 "Local MAC config\n"
1330 "VxLAN Network Identifier\n"
1331 "VNI number\n"
1332 "local mac\n"
1333 "mac address\n")
1334 {
1335 int rv;
1336 vni_t vni;
1337 struct ethaddr mac;
1338 struct ipaddr ip;
1339 struct bgp *bgp;
1340
1341 vni = strtoul(argv[4]->arg, NULL, 10);
1342 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1343 vty_out(vty, "%% Malformed MAC address\n");
1344 return CMD_WARNING;
1345 }
1346 memset(&ip, 0, sizeof(ip));
1347
1348 bgp = bgp_get_default();
1349 if (!bgp) {
1350 vty_out(vty, "Default BGP instance is not there\n");
1351 return CMD_WARNING;
1352 }
1353
1354 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1355 if (rv < 0) {
1356 vty_out(vty, "Internal error\n");
1357 return CMD_WARNING;
1358 }
1359
1360 return CMD_SUCCESS;
1361 }
1362
1363 DEFUN (no_synchronization,
1364 no_synchronization_cmd,
1365 "no synchronization",
1366 NO_STR
1367 "Perform IGP synchronization\n")
1368 {
1369 return CMD_SUCCESS;
1370 }
1371
1372 DEFUN (no_auto_summary,
1373 no_auto_summary_cmd,
1374 "no auto-summary",
1375 NO_STR
1376 "Enable automatic network number summarization\n")
1377 {
1378 return CMD_SUCCESS;
1379 }
1380
1381 /* "router bgp" commands. */
1382 DEFUN_NOSH (router_bgp,
1383 router_bgp_cmd,
1384 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1385 ROUTER_STR
1386 BGP_STR
1387 AS_STR
1388 BGP_INSTANCE_HELP_STR)
1389 {
1390 int idx_asn = 2;
1391 int idx_view_vrf = 3;
1392 int idx_vrf = 4;
1393 int is_new_bgp = 0;
1394 int ret;
1395 as_t as;
1396 struct bgp *bgp;
1397 const char *name = NULL;
1398 enum bgp_instance_type inst_type;
1399
1400 // "router bgp" without an ASN
1401 if (argc == 2) {
1402 // Pending: Make VRF option available for ASN less config
1403 bgp = bgp_get_default();
1404
1405 if (bgp == NULL) {
1406 vty_out(vty, "%% No BGP process is configured\n");
1407 return CMD_WARNING_CONFIG_FAILED;
1408 }
1409
1410 if (listcount(bm->bgp) > 1) {
1411 vty_out(vty, "%% Please specify ASN and VRF\n");
1412 return CMD_WARNING_CONFIG_FAILED;
1413 }
1414 }
1415
1416 // "router bgp X"
1417 else {
1418 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1419
1420 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1421 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1422 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1423
1424 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1425 if (argc > 3) {
1426 name = argv[idx_vrf]->arg;
1427
1428 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1429 if (strmatch(name, VRF_DEFAULT_NAME))
1430 name = NULL;
1431 else
1432 inst_type = BGP_INSTANCE_TYPE_VRF;
1433 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1434 inst_type = BGP_INSTANCE_TYPE_VIEW;
1435 }
1436
1437 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1438 is_new_bgp = (bgp_lookup(as, name) == NULL);
1439
1440 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1441 switch (ret) {
1442 case BGP_ERR_AS_MISMATCH:
1443 vty_out(vty, "BGP is already running; AS is %u\n", as);
1444 return CMD_WARNING_CONFIG_FAILED;
1445 case BGP_ERR_INSTANCE_MISMATCH:
1446 vty_out(vty,
1447 "BGP instance name and AS number mismatch\n");
1448 vty_out(vty,
1449 "BGP instance is already running; AS is %u\n",
1450 as);
1451 return CMD_WARNING_CONFIG_FAILED;
1452 }
1453
1454 /*
1455 * If we just instantiated the default instance, complete
1456 * any pending VRF-VPN leaking that was configured via
1457 * earlier "router bgp X vrf FOO" blocks.
1458 */
1459 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1460 vpn_leak_postchange_all();
1461
1462 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1463 bgp_vpn_leak_export(bgp);
1464 /* Pending: handle when user tries to change a view to vrf n vv.
1465 */
1466 }
1467
1468 /* unset the auto created flag as the user config is now present */
1469 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1470 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1471
1472 return CMD_SUCCESS;
1473 }
1474
1475 /* "no router bgp" commands. */
1476 DEFUN (no_router_bgp,
1477 no_router_bgp_cmd,
1478 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1479 NO_STR
1480 ROUTER_STR
1481 BGP_STR
1482 AS_STR
1483 BGP_INSTANCE_HELP_STR)
1484 {
1485 int idx_asn = 3;
1486 int idx_vrf = 5;
1487 as_t as;
1488 struct bgp *bgp;
1489 const char *name = NULL;
1490
1491 // "no router bgp" without an ASN
1492 if (argc == 3) {
1493 // Pending: Make VRF option available for ASN less config
1494 bgp = bgp_get_default();
1495
1496 if (bgp == NULL) {
1497 vty_out(vty, "%% No BGP process is configured\n");
1498 return CMD_WARNING_CONFIG_FAILED;
1499 }
1500
1501 if (listcount(bm->bgp) > 1) {
1502 vty_out(vty, "%% Please specify ASN and VRF\n");
1503 return CMD_WARNING_CONFIG_FAILED;
1504 }
1505
1506 if (bgp->l3vni) {
1507 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1508 bgp->l3vni);
1509 return CMD_WARNING_CONFIG_FAILED;
1510 }
1511 } else {
1512 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1513
1514 if (argc > 4) {
1515 name = argv[idx_vrf]->arg;
1516 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1517 && strmatch(name, VRF_DEFAULT_NAME))
1518 name = NULL;
1519 }
1520
1521 /* Lookup bgp structure. */
1522 bgp = bgp_lookup(as, name);
1523 if (!bgp) {
1524 vty_out(vty, "%% Can't find BGP instance\n");
1525 return CMD_WARNING_CONFIG_FAILED;
1526 }
1527
1528 if (bgp->l3vni) {
1529 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1530 bgp->l3vni);
1531 return CMD_WARNING_CONFIG_FAILED;
1532 }
1533
1534 /* Cannot delete default instance if vrf instances exist */
1535 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1536 struct listnode *node;
1537 struct bgp *tmp_bgp;
1538
1539 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1540 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1541 continue;
1542 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1543 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1544 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1545 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1546 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1547 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1548 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1549 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1550 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1551 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1552 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1553 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1554 (bgp == bgp_get_evpn() &&
1555 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1556 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1557 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1558 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1559 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1560 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1561 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1562 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1563 (hashcount(tmp_bgp->vnihash))) {
1564 vty_out(vty,
1565 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1566 return CMD_WARNING_CONFIG_FAILED;
1567 }
1568 }
1569 }
1570 }
1571
1572 bgp_delete(bgp);
1573
1574 return CMD_SUCCESS;
1575 }
1576
1577 /* bgp session-dscp */
1578
1579 DEFPY (bgp_session_dscp,
1580 bgp_session_dscp_cmd,
1581 "bgp session-dscp (0-63)$dscp",
1582 BGP_STR
1583 "Override default (C6) bgp TCP session DSCP value\n"
1584 "Manually configured dscp parameter\n")
1585 {
1586 bm->tcp_dscp = dscp << 2;
1587
1588 return CMD_SUCCESS;
1589 }
1590
1591 DEFPY (no_bgp_session_dscp,
1592 no_bgp_session_dscp_cmd,
1593 "no bgp session-dscp [(0-63)]",
1594 NO_STR
1595 BGP_STR
1596 "Override default (C6) bgp TCP session DSCP value\n"
1597 "Manually configured dscp parameter\n")
1598 {
1599 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1600
1601 return CMD_SUCCESS;
1602 }
1603
1604 /* BGP router-id. */
1605
1606 DEFPY (bgp_router_id,
1607 bgp_router_id_cmd,
1608 "bgp router-id A.B.C.D",
1609 BGP_STR
1610 "Override configured router identifier\n"
1611 "Manually configured router identifier\n")
1612 {
1613 VTY_DECLVAR_CONTEXT(bgp, bgp);
1614 bgp_router_id_static_set(bgp, router_id);
1615 return CMD_SUCCESS;
1616 }
1617
1618 DEFPY (no_bgp_router_id,
1619 no_bgp_router_id_cmd,
1620 "no bgp router-id [A.B.C.D]",
1621 NO_STR
1622 BGP_STR
1623 "Override configured router identifier\n"
1624 "Manually configured router identifier\n")
1625 {
1626 VTY_DECLVAR_CONTEXT(bgp, bgp);
1627
1628 if (router_id_str) {
1629 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1630 vty_out(vty, "%% BGP router-id doesn't match\n");
1631 return CMD_WARNING_CONFIG_FAILED;
1632 }
1633 }
1634
1635 router_id.s_addr = 0;
1636 bgp_router_id_static_set(bgp, router_id);
1637
1638 return CMD_SUCCESS;
1639 }
1640
1641 DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1642 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
1643 NO_STR BGP_STR
1644 "Add community specific parameters\n"
1645 "Create an alias for a community\n"
1646 "Community (AA:BB or AA:BB:CC)\n"
1647 "Alias name\n")
1648 {
1649 struct community_alias ca = {};
1650 struct community_alias *lookup_community;
1651 struct community_alias *lookup_alias;
1652 struct community *comm;
1653 struct lcommunity *lcomm;
1654 uint8_t invalid = 0;
1655
1656 comm = community_str2com(community);
1657 if (!comm)
1658 invalid++;
1659 community_free(&comm);
1660
1661 lcomm = lcommunity_str2com(community);
1662 if (!lcomm)
1663 invalid++;
1664 lcommunity_free(&lcomm);
1665
1666 if (invalid > 1) {
1667 vty_out(vty, "Invalid community format\n");
1668 return CMD_WARNING;
1669 }
1670
1671 strlcpy(ca.community, community, sizeof(ca.community));
1672 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
1673
1674 lookup_community = bgp_ca_community_lookup(&ca);
1675 lookup_alias = bgp_ca_alias_lookup(&ca);
1676
1677 if (no) {
1678 bgp_ca_alias_delete(&ca);
1679 bgp_ca_community_delete(&ca);
1680 } else {
1681 if (lookup_alias) {
1682 /* Lookup if community hash table has an item
1683 * with the same alias name.
1684 */
1685 strlcpy(ca.community, lookup_alias->community,
1686 sizeof(ca.community));
1687 if (bgp_ca_community_lookup(&ca)) {
1688 vty_out(vty,
1689 "community (%s) already has this alias (%s)\n",
1690 lookup_alias->community,
1691 lookup_alias->alias);
1692 return CMD_WARNING;
1693 }
1694 bgp_ca_alias_delete(&ca);
1695 }
1696
1697 if (lookup_community) {
1698 /* Lookup if alias hash table has an item
1699 * with the same community.
1700 */
1701 strlcpy(ca.alias, lookup_community->alias,
1702 sizeof(ca.alias));
1703 if (bgp_ca_alias_lookup(&ca)) {
1704 vty_out(vty,
1705 "alias (%s) already has this community (%s)\n",
1706 lookup_community->alias,
1707 lookup_community->community);
1708 return CMD_WARNING;
1709 }
1710 bgp_ca_community_delete(&ca);
1711 }
1712
1713 bgp_ca_alias_insert(&ca);
1714 bgp_ca_community_insert(&ca);
1715 }
1716
1717 return CMD_SUCCESS;
1718 }
1719
1720 DEFPY (bgp_global_suppress_fib_pending,
1721 bgp_global_suppress_fib_pending_cmd,
1722 "[no] bgp suppress-fib-pending",
1723 NO_STR
1724 BGP_STR
1725 "Advertise only routes that are programmed in kernel to peers globally\n")
1726 {
1727 bm_wait_for_fib_set(!no);
1728
1729 return CMD_SUCCESS;
1730 }
1731
1732 DEFPY (bgp_suppress_fib_pending,
1733 bgp_suppress_fib_pending_cmd,
1734 "[no] bgp suppress-fib-pending",
1735 NO_STR
1736 BGP_STR
1737 "Advertise only routes that are programmed in kernel to peers\n")
1738 {
1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740
1741 bgp_suppress_fib_pending_set(bgp, !no);
1742 return CMD_SUCCESS;
1743 }
1744
1745
1746 /* BGP Cluster ID. */
1747 DEFUN (bgp_cluster_id,
1748 bgp_cluster_id_cmd,
1749 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1750 BGP_STR
1751 "Configure Route-Reflector Cluster-id\n"
1752 "Route-Reflector Cluster-id in IP address format\n"
1753 "Route-Reflector Cluster-id as 32 bit quantity\n")
1754 {
1755 VTY_DECLVAR_CONTEXT(bgp, bgp);
1756 int idx_ipv4 = 2;
1757 int ret;
1758 struct in_addr cluster;
1759
1760 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1761 if (!ret) {
1762 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1763 return CMD_WARNING_CONFIG_FAILED;
1764 }
1765
1766 bgp_cluster_id_set(bgp, &cluster);
1767 bgp_clear_star_soft_out(vty, bgp->name);
1768
1769 return CMD_SUCCESS;
1770 }
1771
1772 DEFUN (no_bgp_cluster_id,
1773 no_bgp_cluster_id_cmd,
1774 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1775 NO_STR
1776 BGP_STR
1777 "Configure Route-Reflector Cluster-id\n"
1778 "Route-Reflector Cluster-id in IP address format\n"
1779 "Route-Reflector Cluster-id as 32 bit quantity\n")
1780 {
1781 VTY_DECLVAR_CONTEXT(bgp, bgp);
1782 bgp_cluster_id_unset(bgp);
1783 bgp_clear_star_soft_out(vty, bgp->name);
1784
1785 return CMD_SUCCESS;
1786 }
1787
1788 DEFPY (bgp_norib,
1789 bgp_norib_cmd,
1790 "bgp no-rib",
1791 BGP_STR
1792 "Disable BGP route installation to RIB (Zebra)\n")
1793 {
1794 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1795 vty_out(vty,
1796 "%% No-RIB option is already set, nothing to do here.\n");
1797 return CMD_SUCCESS;
1798 }
1799
1800 bgp_option_norib_set_runtime();
1801
1802 return CMD_SUCCESS;
1803 }
1804
1805 DEFPY (no_bgp_norib,
1806 no_bgp_norib_cmd,
1807 "no bgp no-rib",
1808 NO_STR
1809 BGP_STR
1810 "Disable BGP route installation to RIB (Zebra)\n")
1811 {
1812 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1813 vty_out(vty,
1814 "%% No-RIB option is not set, nothing to do here.\n");
1815 return CMD_SUCCESS;
1816 }
1817
1818 bgp_option_norib_unset_runtime();
1819
1820 return CMD_SUCCESS;
1821 }
1822
1823 DEFPY (no_bgp_send_extra_data,
1824 no_bgp_send_extra_data_cmd,
1825 "[no] bgp send-extra-data zebra",
1826 NO_STR
1827 BGP_STR
1828 "Extra data to Zebra for display/use\n"
1829 "To zebra\n")
1830 {
1831 if (no)
1832 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1833 else
1834 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1835
1836 return CMD_SUCCESS;
1837 }
1838
1839 DEFUN (bgp_confederation_identifier,
1840 bgp_confederation_identifier_cmd,
1841 "bgp confederation identifier (1-4294967295)",
1842 BGP_STR
1843 "AS confederation parameters\n"
1844 "AS number\n"
1845 "Set routing domain confederation AS\n")
1846 {
1847 VTY_DECLVAR_CONTEXT(bgp, bgp);
1848 int idx_number = 3;
1849 as_t as;
1850
1851 as = strtoul(argv[idx_number]->arg, NULL, 10);
1852
1853 bgp_confederation_id_set(bgp, as);
1854
1855 return CMD_SUCCESS;
1856 }
1857
1858 DEFUN (no_bgp_confederation_identifier,
1859 no_bgp_confederation_identifier_cmd,
1860 "no bgp confederation identifier [(1-4294967295)]",
1861 NO_STR
1862 BGP_STR
1863 "AS confederation parameters\n"
1864 "AS number\n"
1865 "Set routing domain confederation AS\n")
1866 {
1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1868 bgp_confederation_id_unset(bgp);
1869
1870 return CMD_SUCCESS;
1871 }
1872
1873 DEFUN (bgp_confederation_peers,
1874 bgp_confederation_peers_cmd,
1875 "bgp confederation peers (1-4294967295)...",
1876 BGP_STR
1877 "AS confederation parameters\n"
1878 "Peer ASs in BGP confederation\n"
1879 AS_STR)
1880 {
1881 VTY_DECLVAR_CONTEXT(bgp, bgp);
1882 int idx_asn = 3;
1883 as_t as;
1884 int i;
1885
1886 for (i = idx_asn; i < argc; i++) {
1887 as = strtoul(argv[i]->arg, NULL, 10);
1888
1889 if (bgp->as == as) {
1890 vty_out(vty,
1891 "%% Local member-AS not allowed in confed peer list\n");
1892 continue;
1893 }
1894
1895 bgp_confederation_peers_add(bgp, as);
1896 }
1897 return CMD_SUCCESS;
1898 }
1899
1900 DEFUN (no_bgp_confederation_peers,
1901 no_bgp_confederation_peers_cmd,
1902 "no bgp confederation peers (1-4294967295)...",
1903 NO_STR
1904 BGP_STR
1905 "AS confederation parameters\n"
1906 "Peer ASs in BGP confederation\n"
1907 AS_STR)
1908 {
1909 VTY_DECLVAR_CONTEXT(bgp, bgp);
1910 int idx_asn = 4;
1911 as_t as;
1912 int i;
1913
1914 for (i = idx_asn; i < argc; i++) {
1915 as = strtoul(argv[i]->arg, NULL, 10);
1916
1917 bgp_confederation_peers_remove(bgp, as);
1918 }
1919 return CMD_SUCCESS;
1920 }
1921
1922 /**
1923 * Central routine for maximum-paths configuration.
1924 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1925 * @set: 1 for setting values, 0 for removing the max-paths config.
1926 */
1927 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1928 const char *mpaths, uint16_t options,
1929 int set)
1930 {
1931 VTY_DECLVAR_CONTEXT(bgp, bgp);
1932 uint16_t maxpaths = 0;
1933 int ret;
1934 afi_t afi;
1935 safi_t safi;
1936
1937 afi = bgp_node_afi(vty);
1938 safi = bgp_node_safi(vty);
1939
1940 if (set) {
1941 maxpaths = strtol(mpaths, NULL, 10);
1942 if (maxpaths > multipath_num) {
1943 vty_out(vty,
1944 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1945 maxpaths, multipath_num);
1946 return CMD_WARNING_CONFIG_FAILED;
1947 }
1948 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1949 options);
1950 } else
1951 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1952
1953 if (ret < 0) {
1954 vty_out(vty,
1955 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1956 (set == 1) ? "" : "un",
1957 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1958 maxpaths, afi, safi);
1959 return CMD_WARNING_CONFIG_FAILED;
1960 }
1961
1962 bgp_recalculate_all_bestpaths(bgp);
1963
1964 return CMD_SUCCESS;
1965 }
1966
1967 DEFUN (bgp_maxmed_admin,
1968 bgp_maxmed_admin_cmd,
1969 "bgp max-med administrative ",
1970 BGP_STR
1971 "Advertise routes with max-med\n"
1972 "Administratively applied, for an indefinite period\n")
1973 {
1974 VTY_DECLVAR_CONTEXT(bgp, bgp);
1975
1976 bgp->v_maxmed_admin = 1;
1977 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1978
1979 bgp_maxmed_update(bgp);
1980
1981 return CMD_SUCCESS;
1982 }
1983
1984 DEFUN (bgp_maxmed_admin_medv,
1985 bgp_maxmed_admin_medv_cmd,
1986 "bgp max-med administrative (0-4294967295)",
1987 BGP_STR
1988 "Advertise routes with max-med\n"
1989 "Administratively applied, for an indefinite period\n"
1990 "Max MED value to be used\n")
1991 {
1992 VTY_DECLVAR_CONTEXT(bgp, bgp);
1993 int idx_number = 3;
1994
1995 bgp->v_maxmed_admin = 1;
1996 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1997
1998 bgp_maxmed_update(bgp);
1999
2000 return CMD_SUCCESS;
2001 }
2002
2003 DEFUN (no_bgp_maxmed_admin,
2004 no_bgp_maxmed_admin_cmd,
2005 "no bgp max-med administrative [(0-4294967295)]",
2006 NO_STR
2007 BGP_STR
2008 "Advertise routes with max-med\n"
2009 "Administratively applied, for an indefinite period\n"
2010 "Max MED value to be used\n")
2011 {
2012 VTY_DECLVAR_CONTEXT(bgp, bgp);
2013 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2014 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2015 bgp_maxmed_update(bgp);
2016
2017 return CMD_SUCCESS;
2018 }
2019
2020 DEFUN (bgp_maxmed_onstartup,
2021 bgp_maxmed_onstartup_cmd,
2022 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2023 BGP_STR
2024 "Advertise routes with max-med\n"
2025 "Effective on a startup\n"
2026 "Time (seconds) period for max-med\n"
2027 "Max MED value to be used\n")
2028 {
2029 VTY_DECLVAR_CONTEXT(bgp, bgp);
2030 int idx = 0;
2031
2032 if (argv_find(argv, argc, "(5-86400)", &idx))
2033 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
2034 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2035 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
2036 else
2037 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2038
2039 bgp_maxmed_update(bgp);
2040
2041 return CMD_SUCCESS;
2042 }
2043
2044 DEFUN (no_bgp_maxmed_onstartup,
2045 no_bgp_maxmed_onstartup_cmd,
2046 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2047 NO_STR
2048 BGP_STR
2049 "Advertise routes with max-med\n"
2050 "Effective on a startup\n"
2051 "Time (seconds) period for max-med\n"
2052 "Max MED value to be used\n")
2053 {
2054 VTY_DECLVAR_CONTEXT(bgp, bgp);
2055
2056 /* Cancel max-med onstartup if its on */
2057 if (bgp->t_maxmed_onstartup) {
2058 thread_cancel(&bgp->t_maxmed_onstartup);
2059 bgp->maxmed_onstartup_over = 1;
2060 }
2061
2062 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2063 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
2064
2065 bgp_maxmed_update(bgp);
2066
2067 return CMD_SUCCESS;
2068 }
2069
2070 static int bgp_global_update_delay_config_vty(struct vty *vty,
2071 uint16_t update_delay,
2072 uint16_t establish_wait)
2073 {
2074 struct listnode *node, *nnode;
2075 struct bgp *bgp;
2076 bool vrf_cfg = false;
2077
2078 /*
2079 * See if update-delay is set per-vrf and warn user to delete it
2080 * Note that we only need to check this if this is the first time
2081 * setting the global config.
2082 */
2083 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2084 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2085 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2086 vty_out(vty,
2087 "%% update-delay configuration found in vrf %s\n",
2088 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2089 ? VRF_DEFAULT_NAME
2090 : bgp->name);
2091 vrf_cfg = true;
2092 }
2093 }
2094 }
2095
2096 if (vrf_cfg) {
2097 vty_out(vty,
2098 "%%Failed: global update-delay config not permitted\n");
2099 return CMD_WARNING;
2100 }
2101
2102 if (!establish_wait) { /* update-delay <delay> */
2103 bm->v_update_delay = update_delay;
2104 bm->v_establish_wait = bm->v_update_delay;
2105 } else {
2106 /* update-delay <delay> <establish-wait> */
2107 if (update_delay < establish_wait) {
2108 vty_out(vty,
2109 "%%Failed: update-delay less than the establish-wait!\n");
2110 return CMD_WARNING_CONFIG_FAILED;
2111 }
2112
2113 bm->v_update_delay = update_delay;
2114 bm->v_establish_wait = establish_wait;
2115 }
2116
2117 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2118 bgp->v_update_delay = bm->v_update_delay;
2119 bgp->v_establish_wait = bm->v_establish_wait;
2120 }
2121
2122 return CMD_SUCCESS;
2123 }
2124
2125 static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2126 {
2127 struct listnode *node, *nnode;
2128 struct bgp *bgp;
2129
2130 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2131 bm->v_establish_wait = bm->v_update_delay;
2132
2133 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2134 bgp->v_update_delay = bm->v_update_delay;
2135 bgp->v_establish_wait = bm->v_establish_wait;
2136 }
2137
2138 return CMD_SUCCESS;
2139 }
2140
2141 static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2142 uint16_t establish_wait)
2143 {
2144 VTY_DECLVAR_CONTEXT(bgp, bgp);
2145
2146 /* if configured globally, per-instance config is not allowed */
2147 if (bm->v_update_delay) {
2148 vty_out(vty,
2149 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2150 return CMD_WARNING_CONFIG_FAILED;
2151 }
2152
2153
2154 if (!establish_wait) /* update-delay <delay> */
2155 {
2156 bgp->v_update_delay = update_delay;
2157 bgp->v_establish_wait = bgp->v_update_delay;
2158 return CMD_SUCCESS;
2159 }
2160
2161 /* update-delay <delay> <establish-wait> */
2162 if (update_delay < establish_wait) {
2163 vty_out(vty,
2164 "%%Failed: update-delay less than the establish-wait!\n");
2165 return CMD_WARNING_CONFIG_FAILED;
2166 }
2167
2168 bgp->v_update_delay = update_delay;
2169 bgp->v_establish_wait = establish_wait;
2170
2171 return CMD_SUCCESS;
2172 }
2173
2174 static int bgp_update_delay_deconfig_vty(struct vty *vty)
2175 {
2176 VTY_DECLVAR_CONTEXT(bgp, bgp);
2177
2178 /* If configured globally, cannot remove from one bgp instance */
2179 if (bm->v_update_delay) {
2180 vty_out(vty,
2181 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2182 return CMD_WARNING_CONFIG_FAILED;
2183 }
2184 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2185 bgp->v_establish_wait = bgp->v_update_delay;
2186
2187 return CMD_SUCCESS;
2188 }
2189
2190 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2191 {
2192 /* If configured globally, no need to display per-instance value */
2193 if (bgp->v_update_delay != bm->v_update_delay) {
2194 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2195 if (bgp->v_update_delay != bgp->v_establish_wait)
2196 vty_out(vty, " %d", bgp->v_establish_wait);
2197 vty_out(vty, "\n");
2198 }
2199 }
2200
2201 /* Global update-delay configuration */
2202 DEFPY (bgp_global_update_delay,
2203 bgp_global_update_delay_cmd,
2204 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2205 BGP_STR
2206 "Force initial delay for best-path and updates for all bgp instances\n"
2207 "Max delay in seconds\n"
2208 "Establish wait in seconds\n")
2209 {
2210 return bgp_global_update_delay_config_vty(vty, delay, wait);
2211 }
2212
2213 /* Global update-delay deconfiguration */
2214 DEFPY (no_bgp_global_update_delay,
2215 no_bgp_global_update_delay_cmd,
2216 "no bgp update-delay [(0-3600) [(1-3600)]]",
2217 NO_STR
2218 BGP_STR
2219 "Force initial delay for best-path and updates\n"
2220 "Max delay in seconds\n"
2221 "Establish wait in seconds\n")
2222 {
2223 return bgp_global_update_delay_deconfig_vty(vty);
2224 }
2225
2226 /* Update-delay configuration */
2227
2228 DEFPY (bgp_update_delay,
2229 bgp_update_delay_cmd,
2230 "update-delay (0-3600)$delay [(1-3600)$wait]",
2231 "Force initial delay for best-path and updates\n"
2232 "Max delay in seconds\n"
2233 "Establish wait in seconds\n")
2234 {
2235 return bgp_update_delay_config_vty(vty, delay, wait);
2236 }
2237
2238 /* Update-delay deconfiguration */
2239 DEFPY (no_bgp_update_delay,
2240 no_bgp_update_delay_cmd,
2241 "no update-delay [(0-3600) [(1-3600)]]",
2242 NO_STR
2243 "Force initial delay for best-path and updates\n"
2244 "Max delay in seconds\n"
2245 "Establish wait in seconds\n")
2246 {
2247 return bgp_update_delay_deconfig_vty(vty);
2248 }
2249
2250
2251 static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2252 bool set)
2253 {
2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255
2256 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2257 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2258
2259 return CMD_SUCCESS;
2260 }
2261
2262 static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2263 bool set)
2264 {
2265 VTY_DECLVAR_CONTEXT(bgp, bgp);
2266
2267 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2268 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2269
2270 return CMD_SUCCESS;
2271 }
2272
2273 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2274 {
2275 uint32_t quanta =
2276 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2277 if (quanta != BGP_WRITE_PACKET_MAX)
2278 vty_out(vty, " write-quanta %d\n", quanta);
2279 }
2280
2281 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2282 {
2283 uint32_t quanta =
2284 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2285 if (quanta != BGP_READ_PACKET_MAX)
2286 vty_out(vty, " read-quanta %d\n", quanta);
2287 }
2288
2289 /* Packet quanta configuration
2290 *
2291 * XXX: The value set here controls the size of a stack buffer in the IO
2292 * thread. When changing these limits be careful to prevent stack overflow.
2293 *
2294 * Furthermore, the maximums used here should correspond to
2295 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2296 */
2297 DEFPY (bgp_wpkt_quanta,
2298 bgp_wpkt_quanta_cmd,
2299 "[no] write-quanta (1-64)$quanta",
2300 NO_STR
2301 "How many packets to write to peer socket per run\n"
2302 "Number of packets\n")
2303 {
2304 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2305 }
2306
2307 DEFPY (bgp_rpkt_quanta,
2308 bgp_rpkt_quanta_cmd,
2309 "[no] read-quanta (1-10)$quanta",
2310 NO_STR
2311 "How many packets to read from peer socket per I/O cycle\n"
2312 "Number of packets\n")
2313 {
2314 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
2315 }
2316
2317 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2318 {
2319 if (!bgp->heuristic_coalesce)
2320 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2321 }
2322
2323
2324 DEFUN (bgp_coalesce_time,
2325 bgp_coalesce_time_cmd,
2326 "coalesce-time (0-4294967295)",
2327 "Subgroup coalesce timer\n"
2328 "Subgroup coalesce timer value (in ms)\n")
2329 {
2330 VTY_DECLVAR_CONTEXT(bgp, bgp);
2331
2332 int idx = 0;
2333
2334 bgp->heuristic_coalesce = false;
2335
2336 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2337 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2338
2339 return CMD_SUCCESS;
2340 }
2341
2342 DEFUN (no_bgp_coalesce_time,
2343 no_bgp_coalesce_time_cmd,
2344 "no coalesce-time (0-4294967295)",
2345 NO_STR
2346 "Subgroup coalesce timer\n"
2347 "Subgroup coalesce timer value (in ms)\n")
2348 {
2349 VTY_DECLVAR_CONTEXT(bgp, bgp);
2350
2351 bgp->heuristic_coalesce = true;
2352 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2353 return CMD_SUCCESS;
2354 }
2355
2356 /* Maximum-paths configuration */
2357 DEFUN (bgp_maxpaths,
2358 bgp_maxpaths_cmd,
2359 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2360 "Forward packets over multiple paths\n"
2361 "Number of paths\n")
2362 {
2363 int idx_number = 1;
2364 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2365 argv[idx_number]->arg, 0, 1);
2366 }
2367
2368 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2369 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2370 "Forward packets over multiple paths\n"
2371 "Number of paths\n")
2372
2373 DEFUN (bgp_maxpaths_ibgp,
2374 bgp_maxpaths_ibgp_cmd,
2375 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2376 "Forward packets over multiple paths\n"
2377 "iBGP-multipath\n"
2378 "Number of paths\n")
2379 {
2380 int idx_number = 2;
2381 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2382 argv[idx_number]->arg, 0, 1);
2383 }
2384
2385 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2386 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2387 "Forward packets over multiple paths\n"
2388 "iBGP-multipath\n"
2389 "Number of paths\n")
2390
2391 DEFUN (bgp_maxpaths_ibgp_cluster,
2392 bgp_maxpaths_ibgp_cluster_cmd,
2393 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2394 "Forward packets over multiple paths\n"
2395 "iBGP-multipath\n"
2396 "Number of paths\n"
2397 "Match the cluster length\n")
2398 {
2399 int idx_number = 2;
2400 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2401 argv[idx_number]->arg, true, 1);
2402 }
2403
2404 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2405 "maximum-paths ibgp " CMD_RANGE_STR(
2406 1, MULTIPATH_NUM) " equal-cluster-length",
2407 "Forward packets over multiple paths\n"
2408 "iBGP-multipath\n"
2409 "Number of paths\n"
2410 "Match the cluster length\n")
2411
2412 DEFUN (no_bgp_maxpaths,
2413 no_bgp_maxpaths_cmd,
2414 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2415 NO_STR
2416 "Forward packets over multiple paths\n"
2417 "Number of paths\n")
2418 {
2419 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
2420 }
2421
2422 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2423 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2424 "Forward packets over multiple paths\n"
2425 "Number of paths\n")
2426
2427 DEFUN (no_bgp_maxpaths_ibgp,
2428 no_bgp_maxpaths_ibgp_cmd,
2429 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2430 NO_STR
2431 "Forward packets over multiple paths\n"
2432 "iBGP-multipath\n"
2433 "Number of paths\n"
2434 "Match the cluster length\n")
2435 {
2436 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
2437 }
2438
2439 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2440 "no maximum-paths ibgp [" CMD_RANGE_STR(
2441 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2442 NO_STR
2443 "Forward packets over multiple paths\n"
2444 "iBGP-multipath\n"
2445 "Number of paths\n"
2446 "Match the cluster length\n")
2447
2448 static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2449 afi_t afi, safi_t safi)
2450 {
2451 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2452 vty_out(vty, " maximum-paths %d\n",
2453 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2454 }
2455
2456 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2457 vty_out(vty, " maximum-paths ibgp %d",
2458 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2459 if (bgp->maxpaths[afi][safi].same_clusterlen)
2460 vty_out(vty, " equal-cluster-length");
2461 vty_out(vty, "\n");
2462 }
2463 }
2464
2465 /* BGP timers. */
2466
2467 DEFUN (bgp_timers,
2468 bgp_timers_cmd,
2469 "timers bgp (0-65535) (0-65535)",
2470 "Adjust routing timers\n"
2471 "BGP timers\n"
2472 "Keepalive interval\n"
2473 "Holdtime\n")
2474 {
2475 VTY_DECLVAR_CONTEXT(bgp, bgp);
2476 int idx_number = 2;
2477 int idx_number_2 = 3;
2478 unsigned long keepalive = 0;
2479 unsigned long holdtime = 0;
2480
2481 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2482 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
2483
2484 /* Holdtime value check. */
2485 if (holdtime < 3 && holdtime != 0) {
2486 vty_out(vty,
2487 "%% hold time value must be either 0 or greater than 3\n");
2488 return CMD_WARNING_CONFIG_FAILED;
2489 }
2490
2491 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2492 BGP_DEFAULT_DELAYOPEN);
2493
2494 return CMD_SUCCESS;
2495 }
2496
2497 DEFUN (no_bgp_timers,
2498 no_bgp_timers_cmd,
2499 "no timers bgp [(0-65535) (0-65535)]",
2500 NO_STR
2501 "Adjust routing timers\n"
2502 "BGP timers\n"
2503 "Keepalive interval\n"
2504 "Holdtime\n")
2505 {
2506 VTY_DECLVAR_CONTEXT(bgp, bgp);
2507 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2508 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
2509
2510 return CMD_SUCCESS;
2511 }
2512
2513 /* BGP minimum holdtime. */
2514
2515 DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2516 "bgp minimum-holdtime (1-65535)",
2517 "BGP specific commands\n"
2518 "BGP minimum holdtime\n"
2519 "Seconds\n")
2520 {
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 int idx_number = 2;
2523 unsigned long min_holdtime;
2524
2525 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2526
2527 bgp->default_min_holdtime = min_holdtime;
2528
2529 return CMD_SUCCESS;
2530 }
2531
2532 DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2533 "no bgp minimum-holdtime [(1-65535)]",
2534 NO_STR
2535 "BGP specific commands\n"
2536 "BGP minimum holdtime\n"
2537 "Seconds\n")
2538 {
2539 VTY_DECLVAR_CONTEXT(bgp, bgp);
2540
2541 bgp->default_min_holdtime = 0;
2542
2543 return CMD_SUCCESS;
2544 }
2545
2546 DEFUN (bgp_client_to_client_reflection,
2547 bgp_client_to_client_reflection_cmd,
2548 "bgp client-to-client reflection",
2549 BGP_STR
2550 "Configure client to client route reflection\n"
2551 "reflection of routes allowed\n")
2552 {
2553 VTY_DECLVAR_CONTEXT(bgp, bgp);
2554 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2555 bgp_clear_star_soft_out(vty, bgp->name);
2556
2557 return CMD_SUCCESS;
2558 }
2559
2560 DEFUN (no_bgp_client_to_client_reflection,
2561 no_bgp_client_to_client_reflection_cmd,
2562 "no bgp client-to-client reflection",
2563 NO_STR
2564 BGP_STR
2565 "Configure client to client route reflection\n"
2566 "reflection of routes allowed\n")
2567 {
2568 VTY_DECLVAR_CONTEXT(bgp, bgp);
2569 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2570 bgp_clear_star_soft_out(vty, bgp->name);
2571
2572 return CMD_SUCCESS;
2573 }
2574
2575 /* "bgp always-compare-med" configuration. */
2576 DEFUN (bgp_always_compare_med,
2577 bgp_always_compare_med_cmd,
2578 "bgp always-compare-med",
2579 BGP_STR
2580 "Allow comparing MED from different neighbors\n")
2581 {
2582 VTY_DECLVAR_CONTEXT(bgp, bgp);
2583 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2584 bgp_recalculate_all_bestpaths(bgp);
2585
2586 return CMD_SUCCESS;
2587 }
2588
2589 DEFUN (no_bgp_always_compare_med,
2590 no_bgp_always_compare_med_cmd,
2591 "no bgp always-compare-med",
2592 NO_STR
2593 BGP_STR
2594 "Allow comparing MED from different neighbors\n")
2595 {
2596 VTY_DECLVAR_CONTEXT(bgp, bgp);
2597 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2598 bgp_recalculate_all_bestpaths(bgp);
2599
2600 return CMD_SUCCESS;
2601 }
2602
2603
2604 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2605 "bgp ebgp-requires-policy",
2606 BGP_STR
2607 "Require in and out policy for eBGP peers (RFC8212)\n")
2608 {
2609 VTY_DECLVAR_CONTEXT(bgp, bgp);
2610 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2611 return CMD_SUCCESS;
2612 }
2613
2614 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2615 "no bgp ebgp-requires-policy",
2616 NO_STR
2617 BGP_STR
2618 "Require in and out policy for eBGP peers (RFC8212)\n")
2619 {
2620 VTY_DECLVAR_CONTEXT(bgp, bgp);
2621 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2622 return CMD_SUCCESS;
2623 }
2624
2625 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2626 "bgp suppress-duplicates",
2627 BGP_STR
2628 "Suppress duplicate updates if the route actually not changed\n")
2629 {
2630 VTY_DECLVAR_CONTEXT(bgp, bgp);
2631 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2632 return CMD_SUCCESS;
2633 }
2634
2635 DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2636 "no bgp suppress-duplicates",
2637 NO_STR
2638 BGP_STR
2639 "Suppress duplicate updates if the route actually not changed\n")
2640 {
2641 VTY_DECLVAR_CONTEXT(bgp, bgp);
2642 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2643 return CMD_SUCCESS;
2644 }
2645
2646 DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2647 "bgp reject-as-sets",
2648 BGP_STR
2649 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2650 {
2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
2652 struct listnode *node, *nnode;
2653 struct peer *peer;
2654
2655 bgp->reject_as_sets = true;
2656
2657 /* Reset existing BGP sessions to reject routes
2658 * with aspath containing AS_SET or AS_CONFED_SET.
2659 */
2660 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2661 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2662 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2663 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2664 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2665 }
2666 }
2667
2668 return CMD_SUCCESS;
2669 }
2670
2671 DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2672 "no bgp reject-as-sets",
2673 NO_STR
2674 BGP_STR
2675 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2676 {
2677 VTY_DECLVAR_CONTEXT(bgp, bgp);
2678 struct listnode *node, *nnode;
2679 struct peer *peer;
2680
2681 bgp->reject_as_sets = false;
2682
2683 /* Reset existing BGP sessions to reject routes
2684 * with aspath containing AS_SET or AS_CONFED_SET.
2685 */
2686 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2687 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2688 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2689 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2690 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2691 }
2692 }
2693
2694 return CMD_SUCCESS;
2695 }
2696
2697 /* "bgp deterministic-med" configuration. */
2698 DEFUN (bgp_deterministic_med,
2699 bgp_deterministic_med_cmd,
2700 "bgp deterministic-med",
2701 BGP_STR
2702 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2703 {
2704 VTY_DECLVAR_CONTEXT(bgp, bgp);
2705
2706 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2707 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2708 bgp_recalculate_all_bestpaths(bgp);
2709 }
2710
2711 return CMD_SUCCESS;
2712 }
2713
2714 DEFUN (no_bgp_deterministic_med,
2715 no_bgp_deterministic_med_cmd,
2716 "no bgp deterministic-med",
2717 NO_STR
2718 BGP_STR
2719 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2720 {
2721 VTY_DECLVAR_CONTEXT(bgp, bgp);
2722 int bestpath_per_as_used;
2723 afi_t afi;
2724 safi_t safi;
2725 struct peer *peer;
2726 struct listnode *node, *nnode;
2727
2728 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2729 bestpath_per_as_used = 0;
2730
2731 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2732 FOREACH_AFI_SAFI (afi, safi)
2733 if (bgp_addpath_dmed_required(
2734 peer->addpath_type[afi][safi])) {
2735 bestpath_per_as_used = 1;
2736 break;
2737 }
2738
2739 if (bestpath_per_as_used)
2740 break;
2741 }
2742
2743 if (bestpath_per_as_used) {
2744 vty_out(vty,
2745 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2746 return CMD_WARNING_CONFIG_FAILED;
2747 } else {
2748 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2749 bgp_recalculate_all_bestpaths(bgp);
2750 }
2751 }
2752
2753 return CMD_SUCCESS;
2754 }
2755
2756 /* "bgp graceful-restart mode" configuration. */
2757 DEFUN (bgp_graceful_restart,
2758 bgp_graceful_restart_cmd,
2759 "bgp graceful-restart",
2760 BGP_STR
2761 GR_CMD
2762 )
2763 {
2764 int ret = BGP_GR_FAILURE;
2765
2766 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2767 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2768
2769 VTY_DECLVAR_CONTEXT(bgp, bgp);
2770
2771 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2772
2773 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2774 ret);
2775
2776 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2777 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2778 vty_out(vty,
2779 "Graceful restart configuration changed, reset all peers to take effect\n");
2780 return bgp_vty_return(vty, ret);
2781 }
2782
2783 DEFUN (no_bgp_graceful_restart,
2784 no_bgp_graceful_restart_cmd,
2785 "no bgp graceful-restart",
2786 NO_STR
2787 BGP_STR
2788 NO_GR_CMD
2789 )
2790 {
2791 VTY_DECLVAR_CONTEXT(bgp, bgp);
2792
2793 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2794 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2795
2796 int ret = BGP_GR_FAILURE;
2797
2798 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2799
2800 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2801 ret);
2802
2803 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2804 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2805 vty_out(vty,
2806 "Graceful restart configuration changed, reset all peers to take effect\n");
2807
2808 return bgp_vty_return(vty, ret);
2809 }
2810
2811 DEFUN (bgp_graceful_restart_stalepath_time,
2812 bgp_graceful_restart_stalepath_time_cmd,
2813 "bgp graceful-restart stalepath-time (1-4095)",
2814 BGP_STR
2815 "Graceful restart capability parameters\n"
2816 "Set the max time to hold onto restarting peer's stale paths\n"
2817 "Delay value (seconds)\n")
2818 {
2819 VTY_DECLVAR_CONTEXT(bgp, bgp);
2820 int idx_number = 3;
2821 uint32_t stalepath;
2822
2823 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2824 bgp->stalepath_time = stalepath;
2825 return CMD_SUCCESS;
2826 }
2827
2828 DEFUN (bgp_graceful_restart_restart_time,
2829 bgp_graceful_restart_restart_time_cmd,
2830 "bgp graceful-restart restart-time (0-4095)",
2831 BGP_STR
2832 "Graceful restart capability parameters\n"
2833 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2834 "Delay value (seconds)\n")
2835 {
2836 VTY_DECLVAR_CONTEXT(bgp, bgp);
2837 int idx_number = 3;
2838 uint32_t restart;
2839
2840 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2841 bgp->restart_time = restart;
2842 return CMD_SUCCESS;
2843 }
2844
2845 DEFUN (bgp_graceful_restart_select_defer_time,
2846 bgp_graceful_restart_select_defer_time_cmd,
2847 "bgp graceful-restart select-defer-time (0-3600)",
2848 BGP_STR
2849 "Graceful restart capability parameters\n"
2850 "Set the time to defer the BGP route selection after restart\n"
2851 "Delay value (seconds, 0 - disable)\n")
2852 {
2853 VTY_DECLVAR_CONTEXT(bgp, bgp);
2854 int idx_number = 3;
2855 uint32_t defer_time;
2856
2857 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2858 bgp->select_defer_time = defer_time;
2859 if (defer_time == 0)
2860 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2861 else
2862 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2863
2864 return CMD_SUCCESS;
2865 }
2866
2867 DEFUN (no_bgp_graceful_restart_stalepath_time,
2868 no_bgp_graceful_restart_stalepath_time_cmd,
2869 "no bgp graceful-restart stalepath-time [(1-4095)]",
2870 NO_STR
2871 BGP_STR
2872 "Graceful restart capability parameters\n"
2873 "Set the max time to hold onto restarting peer's stale paths\n"
2874 "Delay value (seconds)\n")
2875 {
2876 VTY_DECLVAR_CONTEXT(bgp, bgp);
2877
2878 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2879 return CMD_SUCCESS;
2880 }
2881
2882 DEFUN (no_bgp_graceful_restart_restart_time,
2883 no_bgp_graceful_restart_restart_time_cmd,
2884 "no bgp graceful-restart restart-time [(0-4095)]",
2885 NO_STR
2886 BGP_STR
2887 "Graceful restart capability parameters\n"
2888 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2889 "Delay value (seconds)\n")
2890 {
2891 VTY_DECLVAR_CONTEXT(bgp, bgp);
2892
2893 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2894 return CMD_SUCCESS;
2895 }
2896
2897 DEFUN (no_bgp_graceful_restart_select_defer_time,
2898 no_bgp_graceful_restart_select_defer_time_cmd,
2899 "no bgp graceful-restart select-defer-time [(0-3600)]",
2900 NO_STR
2901 BGP_STR
2902 "Graceful restart capability parameters\n"
2903 "Set the time to defer the BGP route selection after restart\n"
2904 "Delay value (seconds)\n")
2905 {
2906 VTY_DECLVAR_CONTEXT(bgp, bgp);
2907
2908 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2909 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2910
2911 return CMD_SUCCESS;
2912 }
2913
2914 DEFUN (bgp_graceful_restart_preserve_fw,
2915 bgp_graceful_restart_preserve_fw_cmd,
2916 "bgp graceful-restart preserve-fw-state",
2917 BGP_STR
2918 "Graceful restart capability parameters\n"
2919 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2920 {
2921 VTY_DECLVAR_CONTEXT(bgp, bgp);
2922 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2923 return CMD_SUCCESS;
2924 }
2925
2926 DEFUN (no_bgp_graceful_restart_preserve_fw,
2927 no_bgp_graceful_restart_preserve_fw_cmd,
2928 "no bgp graceful-restart preserve-fw-state",
2929 NO_STR
2930 BGP_STR
2931 "Graceful restart capability parameters\n"
2932 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2933 {
2934 VTY_DECLVAR_CONTEXT(bgp, bgp);
2935 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2936 return CMD_SUCCESS;
2937 }
2938
2939 DEFPY (bgp_graceful_restart_notification,
2940 bgp_graceful_restart_notification_cmd,
2941 "[no$no] bgp graceful-restart notification",
2942 NO_STR
2943 BGP_STR
2944 "Graceful restart capability parameters\n"
2945 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
2946 {
2947 VTY_DECLVAR_CONTEXT(bgp, bgp);
2948
2949 if (no)
2950 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2951 else
2952 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2953
2954 return CMD_SUCCESS;
2955 }
2956
2957 DEFPY (bgp_administrative_reset,
2958 bgp_administrative_reset_cmd,
2959 "[no$no] bgp hard-administrative-reset",
2960 NO_STR
2961 BGP_STR
2962 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
2963 {
2964 VTY_DECLVAR_CONTEXT(bgp, bgp);
2965
2966 if (no)
2967 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2968 else
2969 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2970
2971 return CMD_SUCCESS;
2972 }
2973
2974 DEFUN (bgp_graceful_restart_disable,
2975 bgp_graceful_restart_disable_cmd,
2976 "bgp graceful-restart-disable",
2977 BGP_STR
2978 GR_DISABLE)
2979 {
2980 int ret = BGP_GR_FAILURE;
2981
2982 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2983 zlog_debug(
2984 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2985
2986 VTY_DECLVAR_CONTEXT(bgp, bgp);
2987
2988 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2989
2990 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2991 bgp->peer, ret);
2992
2993 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2994 zlog_debug(
2995 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2996 vty_out(vty,
2997 "Graceful restart configuration changed, reset all peers to take effect\n");
2998
2999 return bgp_vty_return(vty, ret);
3000 }
3001
3002 DEFUN (no_bgp_graceful_restart_disable,
3003 no_bgp_graceful_restart_disable_cmd,
3004 "no bgp graceful-restart-disable",
3005 NO_STR
3006 BGP_STR
3007 NO_GR_DISABLE
3008 )
3009 {
3010 VTY_DECLVAR_CONTEXT(bgp, bgp);
3011
3012 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3013 zlog_debug(
3014 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
3015
3016 int ret = BGP_GR_FAILURE;
3017
3018 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3019
3020 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3021 ret);
3022
3023 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3024 zlog_debug(
3025 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
3026 vty_out(vty,
3027 "Graceful restart configuration changed, reset all peers to take effect\n");
3028
3029 return bgp_vty_return(vty, ret);
3030 }
3031
3032 DEFUN (bgp_neighbor_graceful_restart_set,
3033 bgp_neighbor_graceful_restart_set_cmd,
3034 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3035 NEIGHBOR_STR
3036 NEIGHBOR_ADDR_STR2
3037 GR_NEIGHBOR_CMD
3038 )
3039 {
3040 int idx_peer = 1;
3041 struct peer *peer;
3042 int ret = BGP_GR_FAILURE;
3043
3044 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3045
3046 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3047 zlog_debug(
3048 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
3049
3050 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3051 if (!peer)
3052 return CMD_WARNING_CONFIG_FAILED;
3053
3054 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3055
3056 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3057 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3058
3059 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3060 zlog_debug(
3061 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
3062 vty_out(vty,
3063 "Graceful restart configuration changed, reset this peer to take effect\n");
3064
3065 return bgp_vty_return(vty, ret);
3066 }
3067
3068 DEFUN (no_bgp_neighbor_graceful_restart,
3069 no_bgp_neighbor_graceful_restart_set_cmd,
3070 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3071 NO_STR
3072 NEIGHBOR_STR
3073 NEIGHBOR_ADDR_STR2
3074 NO_GR_NEIGHBOR_CMD
3075 )
3076 {
3077 int idx_peer = 2;
3078 int ret = BGP_GR_FAILURE;
3079 struct peer *peer;
3080
3081 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3082
3083 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3084 if (!peer)
3085 return CMD_WARNING_CONFIG_FAILED;
3086
3087 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3088 zlog_debug(
3089 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3090
3091 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3092
3093 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3094 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3095
3096 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3097 zlog_debug(
3098 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3099 vty_out(vty,
3100 "Graceful restart configuration changed, reset this peer to take effect\n");
3101
3102 return bgp_vty_return(vty, ret);
3103 }
3104
3105 DEFUN (bgp_neighbor_graceful_restart_helper_set,
3106 bgp_neighbor_graceful_restart_helper_set_cmd,
3107 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3108 NEIGHBOR_STR
3109 NEIGHBOR_ADDR_STR2
3110 GR_NEIGHBOR_HELPER_CMD
3111 )
3112 {
3113 int idx_peer = 1;
3114 struct peer *peer;
3115 int ret = BGP_GR_FAILURE;
3116
3117 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3118
3119 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3120 zlog_debug(
3121 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3122
3123 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3124
3125 if (!peer)
3126 return CMD_WARNING_CONFIG_FAILED;
3127
3128
3129 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3130
3131 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3132 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3133
3134 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3135 zlog_debug(
3136 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3137 vty_out(vty,
3138 "Graceful restart configuration changed, reset this peer to take effect\n");
3139
3140 return bgp_vty_return(vty, ret);
3141 }
3142
3143 DEFUN (no_bgp_neighbor_graceful_restart_helper,
3144 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3145 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3146 NO_STR
3147 NEIGHBOR_STR
3148 NEIGHBOR_ADDR_STR2
3149 NO_GR_NEIGHBOR_HELPER_CMD
3150 )
3151 {
3152 int idx_peer = 2;
3153 int ret = BGP_GR_FAILURE;
3154 struct peer *peer;
3155
3156 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3157
3158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3159 if (!peer)
3160 return CMD_WARNING_CONFIG_FAILED;
3161
3162 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3163 zlog_debug(
3164 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3165
3166 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3167
3168 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3169 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3170
3171 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3172 zlog_debug(
3173 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3174 vty_out(vty,
3175 "Graceful restart configuration changed, reset this peer to take effect\n");
3176
3177 return bgp_vty_return(vty, ret);
3178 }
3179
3180 DEFUN (bgp_neighbor_graceful_restart_disable_set,
3181 bgp_neighbor_graceful_restart_disable_set_cmd,
3182 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3183 NEIGHBOR_STR
3184 NEIGHBOR_ADDR_STR2
3185 GR_NEIGHBOR_DISABLE_CMD
3186 )
3187 {
3188 int idx_peer = 1;
3189 struct peer *peer;
3190 int ret = BGP_GR_FAILURE;
3191
3192 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3193
3194 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3195 zlog_debug(
3196 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3197
3198 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3199 if (!peer)
3200 return CMD_WARNING_CONFIG_FAILED;
3201
3202 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3203
3204 if (peer->bgp->t_startup)
3205 bgp_peer_gr_flags_update(peer);
3206
3207 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3208 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3209
3210 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3211 zlog_debug(
3212 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3213 vty_out(vty,
3214 "Graceful restart configuration changed, reset this peer to take effect\n");
3215
3216 return bgp_vty_return(vty, ret);
3217 }
3218
3219 DEFUN (no_bgp_neighbor_graceful_restart_disable,
3220 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3221 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3222 NO_STR
3223 NEIGHBOR_STR
3224 NEIGHBOR_ADDR_STR2
3225 NO_GR_NEIGHBOR_DISABLE_CMD
3226 )
3227 {
3228 int idx_peer = 2;
3229 int ret = BGP_GR_FAILURE;
3230 struct peer *peer;
3231
3232 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3233
3234 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3235 if (!peer)
3236 return CMD_WARNING_CONFIG_FAILED;
3237
3238 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3239 zlog_debug(
3240 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3241
3242 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3243
3244 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3245 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3246
3247 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3248 zlog_debug(
3249 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3250 vty_out(vty,
3251 "Graceful restart configuration changed, reset this peer to take effect\n");
3252
3253 return bgp_vty_return(vty, ret);
3254 }
3255
3256 DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3257 bgp_graceful_restart_disable_eor_cmd,
3258 "bgp graceful-restart disable-eor",
3259 BGP_STR
3260 "Graceful restart configuration parameters\n"
3261 "Disable EOR Check\n")
3262 {
3263 VTY_DECLVAR_CONTEXT(bgp, bgp);
3264 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3265
3266 return CMD_SUCCESS;
3267 }
3268
3269 DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3270 no_bgp_graceful_restart_disable_eor_cmd,
3271 "no bgp graceful-restart disable-eor",
3272 NO_STR
3273 BGP_STR
3274 "Graceful restart configuration parameters\n"
3275 "Disable EOR Check\n")
3276 {
3277 VTY_DECLVAR_CONTEXT(bgp, bgp);
3278 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3279
3280 return CMD_SUCCESS;
3281 }
3282
3283 DEFUN (bgp_graceful_restart_rib_stale_time,
3284 bgp_graceful_restart_rib_stale_time_cmd,
3285 "bgp graceful-restart rib-stale-time (1-3600)",
3286 BGP_STR
3287 "Graceful restart configuration parameters\n"
3288 "Specify the stale route removal timer in rib\n"
3289 "Delay value (seconds)\n")
3290 {
3291 VTY_DECLVAR_CONTEXT(bgp, bgp);
3292 int idx_number = 3;
3293 uint32_t stale_time;
3294
3295 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3296 bgp->rib_stale_time = stale_time;
3297 /* Send the stale timer update message to RIB */
3298 if (bgp_zebra_stale_timer_update(bgp))
3299 return CMD_WARNING;
3300
3301 return CMD_SUCCESS;
3302 }
3303
3304 DEFUN (no_bgp_graceful_restart_rib_stale_time,
3305 no_bgp_graceful_restart_rib_stale_time_cmd,
3306 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3307 NO_STR
3308 BGP_STR
3309 "Graceful restart configuration parameters\n"
3310 "Specify the stale route removal timer in rib\n"
3311 "Delay value (seconds)\n")
3312 {
3313 VTY_DECLVAR_CONTEXT(bgp, bgp);
3314
3315 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3316 /* Send the stale timer update message to RIB */
3317 if (bgp_zebra_stale_timer_update(bgp))
3318 return CMD_WARNING;
3319
3320 return CMD_SUCCESS;
3321 }
3322
3323 DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
3324 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3325 BGP_STR
3326 "Enable Long-lived Graceful Restart\n"
3327 "Specifies maximum time to wait before purging long-lived stale routes\n"
3328 "Stale time value (seconds)\n")
3329 {
3330 VTY_DECLVAR_CONTEXT(bgp, bgp);
3331
3332 uint32_t llgr_stale_time;
3333
3334 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3335 bgp->llgr_stale_time = llgr_stale_time;
3336
3337 return CMD_SUCCESS;
3338 }
3339
3340 DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
3341 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
3342 NO_STR BGP_STR
3343 "Enable Long-lived Graceful Restart\n"
3344 "Specifies maximum time to wait before purging long-lived stale routes\n"
3345 "Stale time value (seconds)\n")
3346 {
3347 VTY_DECLVAR_CONTEXT(bgp, bgp);
3348
3349 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3350
3351 return CMD_SUCCESS;
3352 }
3353
3354 static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3355 struct bgp *bgp)
3356 {
3357 bgp_static_redo_import_check(bgp);
3358 bgp_redistribute_redo(bgp);
3359 bgp_clear_star_soft_out(vty, bgp->name);
3360 bgp_clear_star_soft_in(vty, bgp->name);
3361 }
3362
3363 static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3364 {
3365 struct listnode *node, *nnode;
3366 struct bgp *bgp;
3367 bool vrf_cfg = false;
3368
3369 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3370 return CMD_SUCCESS;
3371
3372 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3373 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3374 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3375 vty_out(vty,
3376 "%% graceful-shutdown configuration found in vrf %s\n",
3377 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3378 VRF_DEFAULT_NAME : bgp->name);
3379 vrf_cfg = true;
3380 }
3381 }
3382
3383 if (vrf_cfg) {
3384 vty_out(vty,
3385 "%%Failed: global graceful-shutdown not permitted\n");
3386 return CMD_WARNING;
3387 }
3388
3389 /* Set flag globally */
3390 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3391
3392 /* Initiate processing for all BGP instances. */
3393 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3394 bgp_initiate_graceful_shut_unshut(vty, bgp);
3395
3396 return CMD_SUCCESS;
3397 }
3398
3399 static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3400 {
3401 struct listnode *node, *nnode;
3402 struct bgp *bgp;
3403
3404 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3405 return CMD_SUCCESS;
3406
3407 /* Unset flag globally */
3408 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3409
3410 /* Initiate processing for all BGP instances. */
3411 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3412 bgp_initiate_graceful_shut_unshut(vty, bgp);
3413
3414 return CMD_SUCCESS;
3415 }
3416
3417 /* "bgp graceful-shutdown" configuration */
3418 DEFUN (bgp_graceful_shutdown,
3419 bgp_graceful_shutdown_cmd,
3420 "bgp graceful-shutdown",
3421 BGP_STR
3422 "Graceful shutdown parameters\n")
3423 {
3424 if (vty->node == CONFIG_NODE)
3425 return bgp_global_graceful_shutdown_config_vty(vty);
3426
3427 VTY_DECLVAR_CONTEXT(bgp, bgp);
3428
3429 /* if configured globally, per-instance config is not allowed */
3430 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3431 vty_out(vty,
3432 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3433 return CMD_WARNING_CONFIG_FAILED;
3434 }
3435
3436 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3437 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3438 bgp_initiate_graceful_shut_unshut(vty, bgp);
3439 }
3440
3441 return CMD_SUCCESS;
3442 }
3443
3444 DEFUN (no_bgp_graceful_shutdown,
3445 no_bgp_graceful_shutdown_cmd,
3446 "no bgp graceful-shutdown",
3447 NO_STR
3448 BGP_STR
3449 "Graceful shutdown parameters\n")
3450 {
3451 if (vty->node == CONFIG_NODE)
3452 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3453
3454 VTY_DECLVAR_CONTEXT(bgp, bgp);
3455
3456 /* If configured globally, cannot remove from one bgp instance */
3457 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3458 vty_out(vty,
3459 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3460 return CMD_WARNING_CONFIG_FAILED;
3461 }
3462
3463 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3464 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3465 bgp_initiate_graceful_shut_unshut(vty, bgp);
3466 }
3467
3468 return CMD_SUCCESS;
3469 }
3470
3471 /* "bgp fast-external-failover" configuration. */
3472 DEFUN (bgp_fast_external_failover,
3473 bgp_fast_external_failover_cmd,
3474 "bgp fast-external-failover",
3475 BGP_STR
3476 "Immediately reset session if a link to a directly connected external peer goes down\n")
3477 {
3478 VTY_DECLVAR_CONTEXT(bgp, bgp);
3479 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3480 return CMD_SUCCESS;
3481 }
3482
3483 DEFUN (no_bgp_fast_external_failover,
3484 no_bgp_fast_external_failover_cmd,
3485 "no bgp fast-external-failover",
3486 NO_STR
3487 BGP_STR
3488 "Immediately reset session if a link to a directly connected external peer goes down\n")
3489 {
3490 VTY_DECLVAR_CONTEXT(bgp, bgp);
3491 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3492 return CMD_SUCCESS;
3493 }
3494
3495 /* "bgp bestpath compare-routerid" configuration. */
3496 DEFUN (bgp_bestpath_compare_router_id,
3497 bgp_bestpath_compare_router_id_cmd,
3498 "bgp bestpath compare-routerid",
3499 BGP_STR
3500 "Change the default bestpath selection\n"
3501 "Compare router-id for identical EBGP paths\n")
3502 {
3503 VTY_DECLVAR_CONTEXT(bgp, bgp);
3504 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3505 bgp_recalculate_all_bestpaths(bgp);
3506
3507 return CMD_SUCCESS;
3508 }
3509
3510 DEFUN (no_bgp_bestpath_compare_router_id,
3511 no_bgp_bestpath_compare_router_id_cmd,
3512 "no bgp bestpath compare-routerid",
3513 NO_STR
3514 BGP_STR
3515 "Change the default bestpath selection\n"
3516 "Compare router-id for identical EBGP paths\n")
3517 {
3518 VTY_DECLVAR_CONTEXT(bgp, bgp);
3519 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3520 bgp_recalculate_all_bestpaths(bgp);
3521
3522 return CMD_SUCCESS;
3523 }
3524
3525 /* "bgp bestpath as-path ignore" configuration. */
3526 DEFUN (bgp_bestpath_aspath_ignore,
3527 bgp_bestpath_aspath_ignore_cmd,
3528 "bgp bestpath as-path ignore",
3529 BGP_STR
3530 "Change the default bestpath selection\n"
3531 "AS-path attribute\n"
3532 "Ignore as-path length in selecting a route\n")
3533 {
3534 VTY_DECLVAR_CONTEXT(bgp, bgp);
3535 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3536 bgp_recalculate_all_bestpaths(bgp);
3537
3538 return CMD_SUCCESS;
3539 }
3540
3541 DEFUN (no_bgp_bestpath_aspath_ignore,
3542 no_bgp_bestpath_aspath_ignore_cmd,
3543 "no bgp bestpath as-path ignore",
3544 NO_STR
3545 BGP_STR
3546 "Change the default bestpath selection\n"
3547 "AS-path attribute\n"
3548 "Ignore as-path length in selecting a route\n")
3549 {
3550 VTY_DECLVAR_CONTEXT(bgp, bgp);
3551 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3552 bgp_recalculate_all_bestpaths(bgp);
3553
3554 return CMD_SUCCESS;
3555 }
3556
3557 /* "bgp bestpath as-path confed" configuration. */
3558 DEFUN (bgp_bestpath_aspath_confed,
3559 bgp_bestpath_aspath_confed_cmd,
3560 "bgp bestpath as-path confed",
3561 BGP_STR
3562 "Change the default bestpath selection\n"
3563 "AS-path attribute\n"
3564 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3565 {
3566 VTY_DECLVAR_CONTEXT(bgp, bgp);
3567 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3568 bgp_recalculate_all_bestpaths(bgp);
3569
3570 return CMD_SUCCESS;
3571 }
3572
3573 DEFUN (no_bgp_bestpath_aspath_confed,
3574 no_bgp_bestpath_aspath_confed_cmd,
3575 "no bgp bestpath as-path confed",
3576 NO_STR
3577 BGP_STR
3578 "Change the default bestpath selection\n"
3579 "AS-path attribute\n"
3580 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3581 {
3582 VTY_DECLVAR_CONTEXT(bgp, bgp);
3583 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3584 bgp_recalculate_all_bestpaths(bgp);
3585
3586 return CMD_SUCCESS;
3587 }
3588
3589 /* "bgp bestpath as-path multipath-relax" configuration. */
3590 DEFUN (bgp_bestpath_aspath_multipath_relax,
3591 bgp_bestpath_aspath_multipath_relax_cmd,
3592 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3593 BGP_STR
3594 "Change the default bestpath selection\n"
3595 "AS-path attribute\n"
3596 "Allow load sharing across routes that have different AS paths (but same length)\n"
3597 "Generate an AS_SET\n"
3598 "Do not generate an AS_SET\n")
3599 {
3600 VTY_DECLVAR_CONTEXT(bgp, bgp);
3601 int idx = 0;
3602 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3603
3604 /* no-as-set is now the default behavior so we can silently
3605 * ignore it */
3606 if (argv_find(argv, argc, "as-set", &idx))
3607 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3608 else
3609 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3610
3611 bgp_recalculate_all_bestpaths(bgp);
3612
3613 return CMD_SUCCESS;
3614 }
3615
3616 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
3617 no_bgp_bestpath_aspath_multipath_relax_cmd,
3618 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3619 NO_STR
3620 BGP_STR
3621 "Change the default bestpath selection\n"
3622 "AS-path attribute\n"
3623 "Allow load sharing across routes that have different AS paths (but same length)\n"
3624 "Generate an AS_SET\n"
3625 "Do not generate an AS_SET\n")
3626 {
3627 VTY_DECLVAR_CONTEXT(bgp, bgp);
3628 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3629 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3630 bgp_recalculate_all_bestpaths(bgp);
3631
3632 return CMD_SUCCESS;
3633 }
3634
3635 /* "bgp bestpath peer-type multipath-relax" configuration. */
3636 DEFUN(bgp_bestpath_peer_type_multipath_relax,
3637 bgp_bestpath_peer_type_multipath_relax_cmd,
3638 "bgp bestpath peer-type multipath-relax",
3639 BGP_STR
3640 "Change the default bestpath selection\n"
3641 "Peer type\n"
3642 "Allow load sharing across routes learned from different peer types\n")
3643 {
3644 VTY_DECLVAR_CONTEXT(bgp, bgp);
3645 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3646 bgp_recalculate_all_bestpaths(bgp);
3647
3648 return CMD_SUCCESS;
3649 }
3650
3651 DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3652 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3653 "no bgp bestpath peer-type multipath-relax",
3654 NO_STR BGP_STR
3655 "Change the default bestpath selection\n"
3656 "Peer type\n"
3657 "Allow load sharing across routes learned from different peer types\n")
3658 {
3659 VTY_DECLVAR_CONTEXT(bgp, bgp);
3660 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3661 bgp_recalculate_all_bestpaths(bgp);
3662
3663 return CMD_SUCCESS;
3664 }
3665
3666 /* "bgp log-neighbor-changes" configuration. */
3667 DEFUN (bgp_log_neighbor_changes,
3668 bgp_log_neighbor_changes_cmd,
3669 "bgp log-neighbor-changes",
3670 BGP_STR
3671 "Log neighbor up/down and reset reason\n")
3672 {
3673 VTY_DECLVAR_CONTEXT(bgp, bgp);
3674 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3675 return CMD_SUCCESS;
3676 }
3677
3678 DEFUN (no_bgp_log_neighbor_changes,
3679 no_bgp_log_neighbor_changes_cmd,
3680 "no bgp log-neighbor-changes",
3681 NO_STR
3682 BGP_STR
3683 "Log neighbor up/down and reset reason\n")
3684 {
3685 VTY_DECLVAR_CONTEXT(bgp, bgp);
3686 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3687 return CMD_SUCCESS;
3688 }
3689
3690 /* "bgp bestpath med" configuration. */
3691 DEFUN (bgp_bestpath_med,
3692 bgp_bestpath_med_cmd,
3693 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3694 BGP_STR
3695 "Change the default bestpath selection\n"
3696 "MED attribute\n"
3697 "Compare MED among confederation paths\n"
3698 "Treat missing MED as the least preferred one\n"
3699 "Treat missing MED as the least preferred one\n"
3700 "Compare MED among confederation paths\n")
3701 {
3702 VTY_DECLVAR_CONTEXT(bgp, bgp);
3703
3704 int idx = 0;
3705 if (argv_find(argv, argc, "confed", &idx))
3706 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3707 idx = 0;
3708 if (argv_find(argv, argc, "missing-as-worst", &idx))
3709 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3710
3711 bgp_recalculate_all_bestpaths(bgp);
3712
3713 return CMD_SUCCESS;
3714 }
3715
3716 DEFUN (no_bgp_bestpath_med,
3717 no_bgp_bestpath_med_cmd,
3718 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3719 NO_STR
3720 BGP_STR
3721 "Change the default bestpath selection\n"
3722 "MED attribute\n"
3723 "Compare MED among confederation paths\n"
3724 "Treat missing MED as the least preferred one\n"
3725 "Treat missing MED as the least preferred one\n"
3726 "Compare MED among confederation paths\n")
3727 {
3728 VTY_DECLVAR_CONTEXT(bgp, bgp);
3729
3730 int idx = 0;
3731 if (argv_find(argv, argc, "confed", &idx))
3732 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
3733 idx = 0;
3734 if (argv_find(argv, argc, "missing-as-worst", &idx))
3735 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3736
3737 bgp_recalculate_all_bestpaths(bgp);
3738
3739 return CMD_SUCCESS;
3740 }
3741
3742 /* "bgp bestpath bandwidth" configuration. */
3743 DEFPY (bgp_bestpath_bw,
3744 bgp_bestpath_bw_cmd,
3745 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3746 BGP_STR
3747 "Change the default bestpath selection\n"
3748 "Link Bandwidth attribute\n"
3749 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3750 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3751 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3752 {
3753 VTY_DECLVAR_CONTEXT(bgp, bgp);
3754 afi_t afi;
3755 safi_t safi;
3756
3757 if (!bw_cfg) {
3758 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3759 return CMD_ERR_INCOMPLETE;
3760 }
3761 if (!strcmp(bw_cfg, "ignore"))
3762 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3763 else if (!strcmp(bw_cfg, "skip-missing"))
3764 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3765 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3766 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3767 else
3768 return CMD_ERR_NO_MATCH;
3769
3770 /* This config is used in route install, so redo that. */
3771 FOREACH_AFI_SAFI (afi, safi) {
3772 if (!bgp_fibupd_safi(safi))
3773 continue;
3774 bgp_zebra_announce_table(bgp, afi, safi);
3775 }
3776
3777 return CMD_SUCCESS;
3778 }
3779
3780 DEFPY (no_bgp_bestpath_bw,
3781 no_bgp_bestpath_bw_cmd,
3782 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3783 NO_STR
3784 BGP_STR
3785 "Change the default bestpath selection\n"
3786 "Link Bandwidth attribute\n"
3787 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3788 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3789 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3790 {
3791 VTY_DECLVAR_CONTEXT(bgp, bgp);
3792 afi_t afi;
3793 safi_t safi;
3794
3795 bgp->lb_handling = BGP_LINK_BW_ECMP;
3796
3797 /* This config is used in route install, so redo that. */
3798 FOREACH_AFI_SAFI (afi, safi) {
3799 if (!bgp_fibupd_safi(safi))
3800 continue;
3801 bgp_zebra_announce_table(bgp, afi, safi);
3802 }
3803 return CMD_SUCCESS;
3804 }
3805
3806 DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
3807 "[no] bgp default <ipv4-unicast|"
3808 "ipv4-multicast|"
3809 "ipv4-vpn|"
3810 "ipv4-labeled-unicast|"
3811 "ipv4-flowspec|"
3812 "ipv6-unicast|"
3813 "ipv6-multicast|"
3814 "ipv6-vpn|"
3815 "ipv6-labeled-unicast|"
3816 "ipv6-flowspec|"
3817 "l2vpn-evpn>$afi_safi",
3818 NO_STR
3819 BGP_STR
3820 "Configure BGP defaults\n"
3821 "Activate ipv4-unicast for a peer by default\n"
3822 "Activate ipv4-multicast for a peer by default\n"
3823 "Activate ipv4-vpn for a peer by default\n"
3824 "Activate ipv4-labeled-unicast for a peer by default\n"
3825 "Activate ipv4-flowspec for a peer by default\n"
3826 "Activate ipv6-unicast for a peer by default\n"
3827 "Activate ipv6-multicast for a peer by default\n"
3828 "Activate ipv6-vpn for a peer by default\n"
3829 "Activate ipv6-labeled-unicast for a peer by default\n"
3830 "Activate ipv6-flowspec for a peer by default\n"
3831 "Activate l2vpn-evpn for a peer by default\n")
3832 {
3833 VTY_DECLVAR_CONTEXT(bgp, bgp);
3834 char afi_safi_str[strlen(afi_safi) + 1];
3835 char *afi_safi_str_tok;
3836
3837 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3838 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3839 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3840 afi_t afi = bgp_vty_afi_from_str(afi_str);
3841 safi_t safi;
3842
3843 if (strmatch(safi_str, "labeled"))
3844 safi = bgp_vty_safi_from_str("labeled-unicast");
3845 else
3846 safi = bgp_vty_safi_from_str(safi_str);
3847
3848 if (no)
3849 bgp->default_af[afi][safi] = false;
3850 else {
3851 if ((safi == SAFI_LABELED_UNICAST
3852 && bgp->default_af[afi][SAFI_UNICAST])
3853 || (safi == SAFI_UNICAST
3854 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3855 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3856 else
3857 bgp->default_af[afi][safi] = true;
3858 }
3859
3860 return CMD_SUCCESS;
3861 }
3862
3863 /* Display hostname in certain command outputs */
3864 DEFUN (bgp_default_show_hostname,
3865 bgp_default_show_hostname_cmd,
3866 "bgp default show-hostname",
3867 BGP_STR
3868 "Configure BGP defaults\n"
3869 "Show hostname in certain command outputs\n")
3870 {
3871 VTY_DECLVAR_CONTEXT(bgp, bgp);
3872 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3873 return CMD_SUCCESS;
3874 }
3875
3876 DEFUN (no_bgp_default_show_hostname,
3877 no_bgp_default_show_hostname_cmd,
3878 "no bgp default show-hostname",
3879 NO_STR
3880 BGP_STR
3881 "Configure BGP defaults\n"
3882 "Show hostname in certain command outputs\n")
3883 {
3884 VTY_DECLVAR_CONTEXT(bgp, bgp);
3885 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3886 return CMD_SUCCESS;
3887 }
3888
3889 /* Display hostname in certain command outputs */
3890 DEFUN (bgp_default_show_nexthop_hostname,
3891 bgp_default_show_nexthop_hostname_cmd,
3892 "bgp default show-nexthop-hostname",
3893 BGP_STR
3894 "Configure BGP defaults\n"
3895 "Show hostname for nexthop in certain command outputs\n")
3896 {
3897 VTY_DECLVAR_CONTEXT(bgp, bgp);
3898 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3899 return CMD_SUCCESS;
3900 }
3901
3902 DEFUN (no_bgp_default_show_nexthop_hostname,
3903 no_bgp_default_show_nexthop_hostname_cmd,
3904 "no bgp default show-nexthop-hostname",
3905 NO_STR
3906 BGP_STR
3907 "Configure BGP defaults\n"
3908 "Show hostname for nexthop in certain command outputs\n")
3909 {
3910 VTY_DECLVAR_CONTEXT(bgp, bgp);
3911 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3912 return CMD_SUCCESS;
3913 }
3914
3915 /* "bgp network import-check" configuration. */
3916 DEFUN (bgp_network_import_check,
3917 bgp_network_import_check_cmd,
3918 "bgp network import-check",
3919 BGP_STR
3920 "BGP network command\n"
3921 "Check BGP network route exists in IGP\n")
3922 {
3923 VTY_DECLVAR_CONTEXT(bgp, bgp);
3924 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3925 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3926 bgp_static_redo_import_check(bgp);
3927 }
3928
3929 return CMD_SUCCESS;
3930 }
3931
3932 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3933 "bgp network import-check exact",
3934 BGP_STR
3935 "BGP network command\n"
3936 "Check BGP network route exists in IGP\n"
3937 "Match route precisely\n")
3938
3939 DEFUN (no_bgp_network_import_check,
3940 no_bgp_network_import_check_cmd,
3941 "no bgp network import-check",
3942 NO_STR
3943 BGP_STR
3944 "BGP network command\n"
3945 "Check BGP network route exists in IGP\n")
3946 {
3947 VTY_DECLVAR_CONTEXT(bgp, bgp);
3948 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3949 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3950 bgp_static_redo_import_check(bgp);
3951 }
3952
3953 return CMD_SUCCESS;
3954 }
3955
3956 DEFUN (bgp_default_local_preference,
3957 bgp_default_local_preference_cmd,
3958 "bgp default local-preference (0-4294967295)",
3959 BGP_STR
3960 "Configure BGP defaults\n"
3961 "local preference (higher=more preferred)\n"
3962 "Configure default local preference value\n")
3963 {
3964 VTY_DECLVAR_CONTEXT(bgp, bgp);
3965 int idx_number = 3;
3966 uint32_t local_pref;
3967
3968 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
3969
3970 bgp_default_local_preference_set(bgp, local_pref);
3971 bgp_clear_star_soft_in(vty, bgp->name);
3972
3973 return CMD_SUCCESS;
3974 }
3975
3976 DEFUN (no_bgp_default_local_preference,
3977 no_bgp_default_local_preference_cmd,
3978 "no bgp default local-preference [(0-4294967295)]",
3979 NO_STR
3980 BGP_STR
3981 "Configure BGP defaults\n"
3982 "local preference (higher=more preferred)\n"
3983 "Configure default local preference value\n")
3984 {
3985 VTY_DECLVAR_CONTEXT(bgp, bgp);
3986 bgp_default_local_preference_unset(bgp);
3987 bgp_clear_star_soft_in(vty, bgp->name);
3988
3989 return CMD_SUCCESS;
3990 }
3991
3992
3993 DEFUN (bgp_default_subgroup_pkt_queue_max,
3994 bgp_default_subgroup_pkt_queue_max_cmd,
3995 "bgp default subgroup-pkt-queue-max (20-100)",
3996 BGP_STR
3997 "Configure BGP defaults\n"
3998 "subgroup-pkt-queue-max\n"
3999 "Configure subgroup packet queue max\n")
4000 {
4001 VTY_DECLVAR_CONTEXT(bgp, bgp);
4002 int idx_number = 3;
4003 uint32_t max_size;
4004
4005 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
4006
4007 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
4008
4009 return CMD_SUCCESS;
4010 }
4011
4012 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4013 no_bgp_default_subgroup_pkt_queue_max_cmd,
4014 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4015 NO_STR
4016 BGP_STR
4017 "Configure BGP defaults\n"
4018 "subgroup-pkt-queue-max\n"
4019 "Configure subgroup packet queue max\n")
4020 {
4021 VTY_DECLVAR_CONTEXT(bgp, bgp);
4022 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4023 return CMD_SUCCESS;
4024 }
4025
4026
4027 DEFUN (bgp_rr_allow_outbound_policy,
4028 bgp_rr_allow_outbound_policy_cmd,
4029 "bgp route-reflector allow-outbound-policy",
4030 BGP_STR
4031 "Allow modifications made by out route-map\n"
4032 "on ibgp neighbors\n")
4033 {
4034 VTY_DECLVAR_CONTEXT(bgp, bgp);
4035
4036 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4037 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4038 update_group_announce_rrclients(bgp);
4039 bgp_clear_star_soft_out(vty, bgp->name);
4040 }
4041
4042 return CMD_SUCCESS;
4043 }
4044
4045 DEFUN (no_bgp_rr_allow_outbound_policy,
4046 no_bgp_rr_allow_outbound_policy_cmd,
4047 "no bgp route-reflector allow-outbound-policy",
4048 NO_STR
4049 BGP_STR
4050 "Allow modifications made by out route-map\n"
4051 "on ibgp neighbors\n")
4052 {
4053 VTY_DECLVAR_CONTEXT(bgp, bgp);
4054
4055 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4056 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4057 update_group_announce_rrclients(bgp);
4058 bgp_clear_star_soft_out(vty, bgp->name);
4059 }
4060
4061 return CMD_SUCCESS;
4062 }
4063
4064 DEFUN (bgp_listen_limit,
4065 bgp_listen_limit_cmd,
4066 "bgp listen limit (1-65535)",
4067 BGP_STR
4068 "BGP Dynamic Neighbors listen commands\n"
4069 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4070 "Configure Dynamic Neighbors listen limit value\n")
4071 {
4072 VTY_DECLVAR_CONTEXT(bgp, bgp);
4073 int idx_number = 3;
4074 int listen_limit;
4075
4076 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
4077
4078 bgp_listen_limit_set(bgp, listen_limit);
4079
4080 return CMD_SUCCESS;
4081 }
4082
4083 DEFUN (no_bgp_listen_limit,
4084 no_bgp_listen_limit_cmd,
4085 "no bgp listen limit [(1-65535)]",
4086 NO_STR
4087 BGP_STR
4088 "BGP Dynamic Neighbors listen commands\n"
4089 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4090 "Configure Dynamic Neighbors listen limit value\n")
4091 {
4092 VTY_DECLVAR_CONTEXT(bgp, bgp);
4093 bgp_listen_limit_unset(bgp);
4094 return CMD_SUCCESS;
4095 }
4096
4097
4098 /*
4099 * Check if this listen range is already configured. Check for exact
4100 * match or overlap based on input.
4101 */
4102 static struct peer_group *listen_range_exists(struct bgp *bgp,
4103 struct prefix *range, int exact)
4104 {
4105 struct listnode *node, *nnode;
4106 struct listnode *node1, *nnode1;
4107 struct peer_group *group;
4108 struct prefix *lr;
4109 afi_t afi;
4110 int match;
4111
4112 afi = family2afi(range->family);
4113 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4114 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4115 lr)) {
4116 if (exact)
4117 match = prefix_same(range, lr);
4118 else
4119 match = (prefix_match(range, lr)
4120 || prefix_match(lr, range));
4121 if (match)
4122 return group;
4123 }
4124 }
4125
4126 return NULL;
4127 }
4128
4129 DEFUN (bgp_listen_range,
4130 bgp_listen_range_cmd,
4131 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4132 BGP_STR
4133 "Configure BGP dynamic neighbors listen range\n"
4134 "Configure BGP dynamic neighbors listen range\n"
4135 NEIGHBOR_ADDR_STR
4136 "Member of the peer-group\n"
4137 "Peer-group name\n")
4138 {
4139 VTY_DECLVAR_CONTEXT(bgp, bgp);
4140 struct prefix range;
4141 struct peer_group *group, *existing_group;
4142 afi_t afi;
4143 int ret;
4144 int idx = 0;
4145
4146 argv_find(argv, argc, "A.B.C.D/M", &idx);
4147 argv_find(argv, argc, "X:X::X:X/M", &idx);
4148 char *prefix = argv[idx]->arg;
4149 argv_find(argv, argc, "PGNAME", &idx);
4150 char *peergroup = argv[idx]->arg;
4151
4152 /* Convert IP prefix string to struct prefix. */
4153 ret = str2prefix(prefix, &range);
4154 if (!ret) {
4155 vty_out(vty, "%% Malformed listen range\n");
4156 return CMD_WARNING_CONFIG_FAILED;
4157 }
4158
4159 afi = family2afi(range.family);
4160
4161 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4162 vty_out(vty,
4163 "%% Malformed listen range (link-local address)\n");
4164 return CMD_WARNING_CONFIG_FAILED;
4165 }
4166
4167 apply_mask(&range);
4168
4169 /* Check if same listen range is already configured. */
4170 existing_group = listen_range_exists(bgp, &range, 1);
4171 if (existing_group) {
4172 if (strcmp(existing_group->name, peergroup) == 0)
4173 return CMD_SUCCESS;
4174 else {
4175 vty_out(vty,
4176 "%% Same listen range is attached to peer-group %s\n",
4177 existing_group->name);
4178 return CMD_WARNING_CONFIG_FAILED;
4179 }
4180 }
4181
4182 /* Check if an overlapping listen range exists. */
4183 if (listen_range_exists(bgp, &range, 0)) {
4184 vty_out(vty,
4185 "%% Listen range overlaps with existing listen range\n");
4186 return CMD_WARNING_CONFIG_FAILED;
4187 }
4188
4189 group = peer_group_lookup(bgp, peergroup);
4190 if (!group) {
4191 vty_out(vty, "%% Configure the peer-group first\n");
4192 return CMD_WARNING_CONFIG_FAILED;
4193 }
4194
4195 ret = peer_group_listen_range_add(group, &range);
4196 return bgp_vty_return(vty, ret);
4197 }
4198
4199 DEFUN (no_bgp_listen_range,
4200 no_bgp_listen_range_cmd,
4201 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4202 NO_STR
4203 BGP_STR
4204 "Unconfigure BGP dynamic neighbors listen range\n"
4205 "Unconfigure BGP dynamic neighbors listen range\n"
4206 NEIGHBOR_ADDR_STR
4207 "Member of the peer-group\n"
4208 "Peer-group name\n")
4209 {
4210 VTY_DECLVAR_CONTEXT(bgp, bgp);
4211 struct prefix range;
4212 struct peer_group *group;
4213 afi_t afi;
4214 int ret;
4215 int idx = 0;
4216
4217 argv_find(argv, argc, "A.B.C.D/M", &idx);
4218 argv_find(argv, argc, "X:X::X:X/M", &idx);
4219 char *prefix = argv[idx]->arg;
4220 argv_find(argv, argc, "PGNAME", &idx);
4221 char *peergroup = argv[idx]->arg;
4222
4223 /* Convert IP prefix string to struct prefix. */
4224 ret = str2prefix(prefix, &range);
4225 if (!ret) {
4226 vty_out(vty, "%% Malformed listen range\n");
4227 return CMD_WARNING_CONFIG_FAILED;
4228 }
4229
4230 afi = family2afi(range.family);
4231
4232 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4233 vty_out(vty,
4234 "%% Malformed listen range (link-local address)\n");
4235 return CMD_WARNING_CONFIG_FAILED;
4236 }
4237
4238 apply_mask(&range);
4239
4240 group = peer_group_lookup(bgp, peergroup);
4241 if (!group) {
4242 vty_out(vty, "%% Peer-group does not exist\n");
4243 return CMD_WARNING_CONFIG_FAILED;
4244 }
4245
4246 ret = peer_group_listen_range_del(group, &range);
4247 return bgp_vty_return(vty, ret);
4248 }
4249
4250 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4251 {
4252 struct peer_group *group;
4253 struct listnode *node, *nnode, *rnode, *nrnode;
4254 struct prefix *range;
4255 afi_t afi;
4256
4257 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4258 vty_out(vty, " bgp listen limit %d\n",
4259 bgp->dynamic_neighbors_limit);
4260
4261 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4262 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4263 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4264 nrnode, range)) {
4265 vty_out(vty,
4266 " bgp listen range %pFX peer-group %s\n",
4267 range, group->name);
4268 }
4269 }
4270 }
4271 }
4272
4273
4274 DEFUN (bgp_disable_connected_route_check,
4275 bgp_disable_connected_route_check_cmd,
4276 "bgp disable-ebgp-connected-route-check",
4277 BGP_STR
4278 "Disable checking if nexthop is connected on ebgp sessions\n")
4279 {
4280 VTY_DECLVAR_CONTEXT(bgp, bgp);
4281 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4282 bgp_clear_star_soft_in(vty, bgp->name);
4283
4284 return CMD_SUCCESS;
4285 }
4286
4287 DEFUN (no_bgp_disable_connected_route_check,
4288 no_bgp_disable_connected_route_check_cmd,
4289 "no bgp disable-ebgp-connected-route-check",
4290 NO_STR
4291 BGP_STR
4292 "Disable checking if nexthop is connected on ebgp sessions\n")
4293 {
4294 VTY_DECLVAR_CONTEXT(bgp, bgp);
4295 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4296 bgp_clear_star_soft_in(vty, bgp->name);
4297
4298 return CMD_SUCCESS;
4299 }
4300
4301
4302 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4303 const char *as_str)
4304 {
4305 VTY_DECLVAR_CONTEXT(bgp, bgp);
4306 int ret;
4307 as_t as;
4308 int as_type = AS_SPECIFIED;
4309 union sockunion su;
4310
4311 if (as_str[0] == 'i') {
4312 as = 0;
4313 as_type = AS_INTERNAL;
4314 } else if (as_str[0] == 'e') {
4315 as = 0;
4316 as_type = AS_EXTERNAL;
4317 } else {
4318 /* Get AS number. */
4319 as = strtoul(as_str, NULL, 10);
4320 }
4321
4322 /* If peer is peer group or interface peer, call proper function. */
4323 ret = str2sockunion(peer_str, &su);
4324 if (ret < 0) {
4325 struct peer *peer;
4326
4327 /* Check if existing interface peer */
4328 peer = peer_lookup_by_conf_if(bgp, peer_str);
4329
4330 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4331
4332 /* if not interface peer, check peer-group settings */
4333 if (ret < 0 && !peer) {
4334 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4335 if (ret < 0) {
4336 vty_out(vty,
4337 "%% Create the peer-group or interface first\n");
4338 return CMD_WARNING_CONFIG_FAILED;
4339 }
4340 return CMD_SUCCESS;
4341 }
4342 } else {
4343 if (peer_address_self_check(bgp, &su)) {
4344 vty_out(vty,
4345 "%% Can not configure the local system as neighbor\n");
4346 return CMD_WARNING_CONFIG_FAILED;
4347 }
4348 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4349 }
4350
4351 return bgp_vty_return(vty, ret);
4352 }
4353
4354 DEFUN (bgp_default_shutdown,
4355 bgp_default_shutdown_cmd,
4356 "[no] bgp default shutdown",
4357 NO_STR
4358 BGP_STR
4359 "Configure BGP defaults\n"
4360 "Apply administrative shutdown to newly configured peers\n")
4361 {
4362 VTY_DECLVAR_CONTEXT(bgp, bgp);
4363 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4364 return CMD_SUCCESS;
4365 }
4366
4367 DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4368 BGP_STR
4369 "Administrative shutdown of the BGP instance\n"
4370 "Add a shutdown message (RFC 8203)\n"
4371 "Shutdown message\n")
4372 {
4373 char *msgstr = NULL;
4374
4375 VTY_DECLVAR_CONTEXT(bgp, bgp);
4376
4377 if (argc > 3)
4378 msgstr = argv_concat(argv, argc, 3);
4379
4380 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4381 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4382 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4383 return CMD_WARNING_CONFIG_FAILED;
4384 }
4385
4386 bgp_shutdown_enable(bgp, msgstr);
4387 XFREE(MTYPE_TMP, msgstr);
4388
4389 return CMD_SUCCESS;
4390 }
4391
4392 DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4393 BGP_STR "Administrative shutdown of the BGP instance\n")
4394 {
4395 VTY_DECLVAR_CONTEXT(bgp, bgp);
4396
4397 bgp_shutdown_enable(bgp, NULL);
4398
4399 return CMD_SUCCESS;
4400 }
4401
4402 DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4403 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4404 {
4405 VTY_DECLVAR_CONTEXT(bgp, bgp);
4406
4407 bgp_shutdown_disable(bgp);
4408
4409 return CMD_SUCCESS;
4410 }
4411
4412 ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4413 "no bgp shutdown message MSG...", NO_STR BGP_STR
4414 "Administrative shutdown of the BGP instance\n"
4415 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4416
4417 DEFUN (neighbor_remote_as,
4418 neighbor_remote_as_cmd,
4419 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4420 NEIGHBOR_STR
4421 NEIGHBOR_ADDR_STR2
4422 "Specify a BGP neighbor\n"
4423 AS_STR
4424 "Internal BGP peer\n"
4425 "External BGP peer\n")
4426 {
4427 int idx_peer = 1;
4428 int idx_remote_as = 3;
4429 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4430 argv[idx_remote_as]->arg);
4431 }
4432
4433 DEFPY (bgp_allow_martian,
4434 bgp_allow_martian_cmd,
4435 "[no]$no bgp allow-martian-nexthop",
4436 NO_STR
4437 BGP_STR
4438 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4439 {
4440 VTY_DECLVAR_CONTEXT(bgp, bgp);
4441
4442 if (no)
4443 bgp->allow_martian = false;
4444 else
4445 bgp->allow_martian = true;
4446
4447 return CMD_SUCCESS;
4448 }
4449
4450 /* Enable fast convergence of bgp sessions. If this is enabled, bgp
4451 * sessions do not wait for hold timer expiry to bring down the sessions
4452 * when nexthop becomes unreachable
4453 */
4454 DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4455 BGP_STR "Fast convergence for bgp sessions\n")
4456 {
4457 VTY_DECLVAR_CONTEXT(bgp, bgp);
4458 bgp->fast_convergence = true;
4459
4460 return CMD_SUCCESS;
4461 }
4462
4463 DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4464 "no bgp fast-convergence",
4465 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4466 {
4467 VTY_DECLVAR_CONTEXT(bgp, bgp);
4468 bgp->fast_convergence = false;
4469
4470 return CMD_SUCCESS;
4471 }
4472
4473 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4474 int v6only,
4475 const char *peer_group_name,
4476 const char *as_str)
4477 {
4478 VTY_DECLVAR_CONTEXT(bgp, bgp);
4479 as_t as = 0;
4480 int as_type = AS_UNSPECIFIED;
4481 struct peer *peer;
4482 struct peer_group *group;
4483 int ret = 0;
4484
4485 group = peer_group_lookup(bgp, conf_if);
4486
4487 if (group) {
4488 vty_out(vty, "%% Name conflict with peer-group \n");
4489 return CMD_WARNING_CONFIG_FAILED;
4490 }
4491
4492 if (as_str) {
4493 if (as_str[0] == 'i') {
4494 as_type = AS_INTERNAL;
4495 } else if (as_str[0] == 'e') {
4496 as_type = AS_EXTERNAL;
4497 } else {
4498 /* Get AS number. */
4499 as = strtoul(as_str, NULL, 10);
4500 as_type = AS_SPECIFIED;
4501 }
4502 }
4503
4504 peer = peer_lookup_by_conf_if(bgp, conf_if);
4505 if (peer) {
4506 if (as_str)
4507 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
4508 } else {
4509 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4510 NULL);
4511
4512 if (!peer) {
4513 vty_out(vty, "%% BGP failed to create peer\n");
4514 return CMD_WARNING_CONFIG_FAILED;
4515 }
4516
4517 if (v6only)
4518 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4519
4520 /* Request zebra to initiate IPv6 RAs on this interface. We do
4521 * this
4522 * any unnumbered peer in order to not worry about run-time
4523 * transitions
4524 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4525 * address
4526 * gets deleted later etc.)
4527 */
4528 if (peer->ifp)
4529 bgp_zebra_initiate_radv(bgp, peer);
4530 }
4531
4532 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4533 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4534 if (v6only)
4535 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4536 else
4537 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4538
4539 /* v6only flag changed. Reset bgp seesion */
4540 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4541 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4542 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4543 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4544 } else
4545 bgp_session_reset(peer);
4546 }
4547
4548 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4549 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4550 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4551 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4552 }
4553
4554 if (peer_group_name) {
4555 group = peer_group_lookup(bgp, peer_group_name);
4556 if (!group) {
4557 vty_out(vty, "%% Configure the peer-group first\n");
4558 return CMD_WARNING_CONFIG_FAILED;
4559 }
4560
4561 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4562 }
4563
4564 return bgp_vty_return(vty, ret);
4565 }
4566
4567 DEFUN (neighbor_interface_config,
4568 neighbor_interface_config_cmd,
4569 "neighbor WORD interface [peer-group PGNAME]",
4570 NEIGHBOR_STR
4571 "Interface name or neighbor tag\n"
4572 "Enable BGP on interface\n"
4573 "Member of the peer-group\n"
4574 "Peer-group name\n")
4575 {
4576 int idx_word = 1;
4577 int idx_peer_group_word = 4;
4578
4579 if (argc > idx_peer_group_word)
4580 return peer_conf_interface_get(
4581 vty, argv[idx_word]->arg, 0,
4582 argv[idx_peer_group_word]->arg, NULL);
4583 else
4584 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4585 NULL, NULL);
4586 }
4587
4588 DEFUN (neighbor_interface_config_v6only,
4589 neighbor_interface_config_v6only_cmd,
4590 "neighbor WORD interface v6only [peer-group PGNAME]",
4591 NEIGHBOR_STR
4592 "Interface name or neighbor tag\n"
4593 "Enable BGP on interface\n"
4594 "Enable BGP with v6 link-local only\n"
4595 "Member of the peer-group\n"
4596 "Peer-group name\n")
4597 {
4598 int idx_word = 1;
4599 int idx_peer_group_word = 5;
4600
4601 if (argc > idx_peer_group_word)
4602 return peer_conf_interface_get(
4603 vty, argv[idx_word]->arg, 1,
4604 argv[idx_peer_group_word]->arg, NULL);
4605
4606 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4607 }
4608
4609
4610 DEFUN (neighbor_interface_config_remote_as,
4611 neighbor_interface_config_remote_as_cmd,
4612 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4613 NEIGHBOR_STR
4614 "Interface name or neighbor tag\n"
4615 "Enable BGP on interface\n"
4616 "Specify a BGP neighbor\n"
4617 AS_STR
4618 "Internal BGP peer\n"
4619 "External BGP peer\n")
4620 {
4621 int idx_word = 1;
4622 int idx_remote_as = 4;
4623 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4624 argv[idx_remote_as]->arg);
4625 }
4626
4627 DEFUN (neighbor_interface_v6only_config_remote_as,
4628 neighbor_interface_v6only_config_remote_as_cmd,
4629 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4630 NEIGHBOR_STR
4631 "Interface name or neighbor tag\n"
4632 "Enable BGP with v6 link-local only\n"
4633 "Enable BGP on interface\n"
4634 "Specify a BGP neighbor\n"
4635 AS_STR
4636 "Internal BGP peer\n"
4637 "External BGP peer\n")
4638 {
4639 int idx_word = 1;
4640 int idx_remote_as = 5;
4641 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4642 argv[idx_remote_as]->arg);
4643 }
4644
4645 DEFUN (neighbor_peer_group,
4646 neighbor_peer_group_cmd,
4647 "neighbor WORD peer-group",
4648 NEIGHBOR_STR
4649 "Interface name or neighbor tag\n"
4650 "Configure peer-group\n")
4651 {
4652 VTY_DECLVAR_CONTEXT(bgp, bgp);
4653 int idx_word = 1;
4654 struct peer *peer;
4655 struct peer_group *group;
4656
4657 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4658 if (peer) {
4659 vty_out(vty, "%% Name conflict with interface: \n");
4660 return CMD_WARNING_CONFIG_FAILED;
4661 }
4662
4663 group = peer_group_get(bgp, argv[idx_word]->arg);
4664 if (!group) {
4665 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4666 return CMD_WARNING_CONFIG_FAILED;
4667 }
4668
4669 return CMD_SUCCESS;
4670 }
4671
4672 DEFUN (no_neighbor,
4673 no_neighbor_cmd,
4674 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4675 NO_STR
4676 NEIGHBOR_STR
4677 NEIGHBOR_ADDR_STR2
4678 "Specify a BGP neighbor\n"
4679 AS_STR
4680 "Internal BGP peer\n"
4681 "External BGP peer\n")
4682 {
4683 VTY_DECLVAR_CONTEXT(bgp, bgp);
4684 int idx_peer = 2;
4685 int ret;
4686 union sockunion su;
4687 struct peer_group *group;
4688 struct peer *peer;
4689 struct peer *other;
4690
4691 ret = str2sockunion(argv[idx_peer]->arg, &su);
4692 if (ret < 0) {
4693 /* look up for neighbor by interface name config. */
4694 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4695 if (peer) {
4696 /* Request zebra to terminate IPv6 RAs on this
4697 * interface. */
4698 if (peer->ifp)
4699 bgp_zebra_terminate_radv(peer->bgp, peer);
4700 peer_notify_unconfig(peer);
4701 peer_delete(peer);
4702 return CMD_SUCCESS;
4703 }
4704
4705 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4706 if (group) {
4707 peer_group_notify_unconfig(group);
4708 peer_group_delete(group);
4709 } else {
4710 vty_out(vty, "%% Create the peer-group first\n");
4711 return CMD_WARNING_CONFIG_FAILED;
4712 }
4713 } else {
4714 peer = peer_lookup(bgp, &su);
4715 if (peer) {
4716 if (peer_dynamic_neighbor(peer)) {
4717 vty_out(vty,
4718 "%% Operation not allowed on a dynamic neighbor\n");
4719 return CMD_WARNING_CONFIG_FAILED;
4720 }
4721
4722 other = peer->doppelganger;
4723
4724 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4725 bgp_zebra_terminate_radv(peer->bgp, peer);
4726
4727 peer_notify_unconfig(peer);
4728 peer_delete(peer);
4729 if (other && other->status != Deleted) {
4730 peer_notify_unconfig(other);
4731 peer_delete(other);
4732 }
4733 }
4734 }
4735
4736 return CMD_SUCCESS;
4737 }
4738
4739 DEFUN (no_neighbor_interface_config,
4740 no_neighbor_interface_config_cmd,
4741 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4742 NO_STR
4743 NEIGHBOR_STR
4744 "Interface name\n"
4745 "Configure BGP on interface\n"
4746 "Enable BGP with v6 link-local only\n"
4747 "Member of the peer-group\n"
4748 "Peer-group name\n"
4749 "Specify a BGP neighbor\n"
4750 AS_STR
4751 "Internal BGP peer\n"
4752 "External BGP peer\n")
4753 {
4754 VTY_DECLVAR_CONTEXT(bgp, bgp);
4755 int idx_word = 2;
4756 struct peer *peer;
4757
4758 /* look up for neighbor by interface name config. */
4759 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4760 if (peer) {
4761 /* Request zebra to terminate IPv6 RAs on this interface. */
4762 if (peer->ifp)
4763 bgp_zebra_terminate_radv(peer->bgp, peer);
4764 peer_notify_unconfig(peer);
4765 peer_delete(peer);
4766 } else {
4767 vty_out(vty, "%% Create the bgp interface first\n");
4768 return CMD_WARNING_CONFIG_FAILED;
4769 }
4770 return CMD_SUCCESS;
4771 }
4772
4773 DEFUN (no_neighbor_peer_group,
4774 no_neighbor_peer_group_cmd,
4775 "no neighbor WORD peer-group",
4776 NO_STR
4777 NEIGHBOR_STR
4778 "Neighbor tag\n"
4779 "Configure peer-group\n")
4780 {
4781 VTY_DECLVAR_CONTEXT(bgp, bgp);
4782 int idx_word = 2;
4783 struct peer_group *group;
4784
4785 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4786 if (group) {
4787 peer_group_notify_unconfig(group);
4788 peer_group_delete(group);
4789 } else {
4790 vty_out(vty, "%% Create the peer-group first\n");
4791 return CMD_WARNING_CONFIG_FAILED;
4792 }
4793 return CMD_SUCCESS;
4794 }
4795
4796 DEFUN (no_neighbor_interface_peer_group_remote_as,
4797 no_neighbor_interface_peer_group_remote_as_cmd,
4798 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4799 NO_STR
4800 NEIGHBOR_STR
4801 "Interface name or neighbor tag\n"
4802 "Specify a BGP neighbor\n"
4803 AS_STR
4804 "Internal BGP peer\n"
4805 "External BGP peer\n")
4806 {
4807 VTY_DECLVAR_CONTEXT(bgp, bgp);
4808 int idx_word = 2;
4809 struct peer_group *group;
4810 struct peer *peer;
4811
4812 /* look up for neighbor by interface name config. */
4813 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4814 if (peer) {
4815 peer_as_change(peer, 0, AS_UNSPECIFIED);
4816 return CMD_SUCCESS;
4817 }
4818
4819 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4820 if (group)
4821 peer_group_remote_as_delete(group);
4822 else {
4823 vty_out(vty, "%% Create the peer-group or interface first\n");
4824 return CMD_WARNING_CONFIG_FAILED;
4825 }
4826 return CMD_SUCCESS;
4827 }
4828
4829 DEFUN (neighbor_local_as,
4830 neighbor_local_as_cmd,
4831 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Specify a local-as number\n"
4835 "AS number used as local AS\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, 0, 0);
4849 return bgp_vty_return(vty, ret);
4850 }
4851
4852 DEFUN (neighbor_local_as_no_prepend,
4853 neighbor_local_as_no_prepend_cmd,
4854 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
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 {
4861 int idx_peer = 1;
4862 int idx_number = 3;
4863 struct peer *peer;
4864 int ret;
4865 as_t as;
4866
4867 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4868 if (!peer)
4869 return CMD_WARNING_CONFIG_FAILED;
4870
4871 as = strtoul(argv[idx_number]->arg, NULL, 10);
4872 ret = peer_local_as_set(peer, as, 1, 0);
4873 return bgp_vty_return(vty, ret);
4874 }
4875
4876 DEFUN (neighbor_local_as_no_prepend_replace_as,
4877 neighbor_local_as_no_prepend_replace_as_cmd,
4878 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4879 NEIGHBOR_STR
4880 NEIGHBOR_ADDR_STR2
4881 "Specify a local-as number\n"
4882 "AS number used as local AS\n"
4883 "Do not prepend local-as to updates from ebgp peers\n"
4884 "Do not prepend local-as to updates from ibgp peers\n")
4885 {
4886 int idx_peer = 1;
4887 int idx_number = 3;
4888 struct peer *peer;
4889 int ret;
4890 as_t as;
4891
4892 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4893 if (!peer)
4894 return CMD_WARNING_CONFIG_FAILED;
4895
4896 as = strtoul(argv[idx_number]->arg, NULL, 10);
4897 ret = peer_local_as_set(peer, as, 1, 1);
4898 return bgp_vty_return(vty, ret);
4899 }
4900
4901 DEFUN (no_neighbor_local_as,
4902 no_neighbor_local_as_cmd,
4903 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4904 NO_STR
4905 NEIGHBOR_STR
4906 NEIGHBOR_ADDR_STR2
4907 "Specify a local-as number\n"
4908 "AS number used as local AS\n"
4909 "Do not prepend local-as to updates from ebgp peers\n"
4910 "Do not prepend local-as to updates from ibgp peers\n")
4911 {
4912 int idx_peer = 2;
4913 struct peer *peer;
4914 int ret;
4915
4916 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4917 if (!peer)
4918 return CMD_WARNING_CONFIG_FAILED;
4919
4920 ret = peer_local_as_unset(peer);
4921 return bgp_vty_return(vty, ret);
4922 }
4923
4924
4925 DEFUN (neighbor_solo,
4926 neighbor_solo_cmd,
4927 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4928 NEIGHBOR_STR
4929 NEIGHBOR_ADDR_STR2
4930 "Solo peer - part of its own update group\n")
4931 {
4932 int idx_peer = 1;
4933 struct peer *peer;
4934 int ret;
4935
4936 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4937 if (!peer)
4938 return CMD_WARNING_CONFIG_FAILED;
4939
4940 ret = update_group_adjust_soloness(peer, 1);
4941 return bgp_vty_return(vty, ret);
4942 }
4943
4944 DEFUN (no_neighbor_solo,
4945 no_neighbor_solo_cmd,
4946 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4947 NO_STR
4948 NEIGHBOR_STR
4949 NEIGHBOR_ADDR_STR2
4950 "Solo peer - part of its own update group\n")
4951 {
4952 int idx_peer = 2;
4953 struct peer *peer;
4954 int ret;
4955
4956 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4957 if (!peer)
4958 return CMD_WARNING_CONFIG_FAILED;
4959
4960 ret = update_group_adjust_soloness(peer, 0);
4961 return bgp_vty_return(vty, ret);
4962 }
4963
4964 DEFUN (neighbor_password,
4965 neighbor_password_cmd,
4966 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4967 NEIGHBOR_STR
4968 NEIGHBOR_ADDR_STR2
4969 "Set a password\n"
4970 "The password\n")
4971 {
4972 int idx_peer = 1;
4973 int idx_line = 3;
4974 struct peer *peer;
4975 int ret;
4976
4977 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4978 if (!peer)
4979 return CMD_WARNING_CONFIG_FAILED;
4980
4981 ret = peer_password_set(peer, argv[idx_line]->arg);
4982 return bgp_vty_return(vty, ret);
4983 }
4984
4985 DEFUN (no_neighbor_password,
4986 no_neighbor_password_cmd,
4987 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4988 NO_STR
4989 NEIGHBOR_STR
4990 NEIGHBOR_ADDR_STR2
4991 "Set a password\n"
4992 "The password\n")
4993 {
4994 int idx_peer = 2;
4995 struct peer *peer;
4996 int ret;
4997
4998 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4999 if (!peer)
5000 return CMD_WARNING_CONFIG_FAILED;
5001
5002 ret = peer_password_unset(peer);
5003 return bgp_vty_return(vty, ret);
5004 }
5005
5006 DEFUN (neighbor_activate,
5007 neighbor_activate_cmd,
5008 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5009 NEIGHBOR_STR
5010 NEIGHBOR_ADDR_STR2
5011 "Enable the Address Family for this Neighbor\n")
5012 {
5013 int idx_peer = 1;
5014 int ret;
5015 struct peer *peer;
5016
5017 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5018 if (!peer)
5019 return CMD_WARNING_CONFIG_FAILED;
5020
5021 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5022 return bgp_vty_return(vty, ret);
5023 }
5024
5025 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5026 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5027 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5028 "Enable the Address Family for this Neighbor\n")
5029
5030 DEFUN (no_neighbor_activate,
5031 no_neighbor_activate_cmd,
5032 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5033 NO_STR
5034 NEIGHBOR_STR
5035 NEIGHBOR_ADDR_STR2
5036 "Enable the Address Family for this Neighbor\n")
5037 {
5038 int idx_peer = 2;
5039 int ret;
5040 struct peer *peer;
5041
5042 /* Lookup peer. */
5043 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5044 if (!peer)
5045 return CMD_WARNING_CONFIG_FAILED;
5046
5047 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5048 return bgp_vty_return(vty, ret);
5049 }
5050
5051 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5052 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5053 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5054 "Enable the Address Family for this Neighbor\n")
5055
5056 DEFUN (neighbor_set_peer_group,
5057 neighbor_set_peer_group_cmd,
5058 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5059 NEIGHBOR_STR
5060 NEIGHBOR_ADDR_STR2
5061 "Member of the peer-group\n"
5062 "Peer-group name\n")
5063 {
5064 VTY_DECLVAR_CONTEXT(bgp, bgp);
5065 int idx_peer = 1;
5066 int idx_word = 3;
5067 int ret;
5068 as_t as;
5069 union sockunion su;
5070 struct peer *peer;
5071 struct peer_group *group;
5072
5073 ret = str2sockunion(argv[idx_peer]->arg, &su);
5074 if (ret < 0) {
5075 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5076 if (!peer) {
5077 vty_out(vty, "%% Malformed address or name: %s\n",
5078 argv[idx_peer]->arg);
5079 return CMD_WARNING_CONFIG_FAILED;
5080 }
5081 } else {
5082 if (peer_address_self_check(bgp, &su)) {
5083 vty_out(vty,
5084 "%% Can not configure the local system as neighbor\n");
5085 return CMD_WARNING_CONFIG_FAILED;
5086 }
5087
5088 /* Disallow for dynamic neighbor. */
5089 peer = peer_lookup(bgp, &su);
5090 if (peer && peer_dynamic_neighbor(peer)) {
5091 vty_out(vty,
5092 "%% Operation not allowed on a dynamic neighbor\n");
5093 return CMD_WARNING_CONFIG_FAILED;
5094 }
5095 }
5096
5097 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5098 if (!group) {
5099 vty_out(vty, "%% Configure the peer-group first\n");
5100 return CMD_WARNING_CONFIG_FAILED;
5101 }
5102
5103 ret = peer_group_bind(bgp, &su, peer, group, &as);
5104
5105 return bgp_vty_return(vty, ret);
5106 }
5107
5108 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5109 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5110 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5111 "Member of the peer-group\n"
5112 "Peer-group name\n")
5113
5114 DEFUN (no_neighbor_set_peer_group,
5115 no_neighbor_set_peer_group_cmd,
5116 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5117 NO_STR
5118 NEIGHBOR_STR
5119 NEIGHBOR_ADDR_STR2
5120 "Member of the peer-group\n"
5121 "Peer-group name\n")
5122 {
5123 VTY_DECLVAR_CONTEXT(bgp, bgp);
5124 int idx_peer = 2;
5125 int idx_word = 4;
5126 int ret;
5127 struct peer *peer;
5128 struct peer_group *group;
5129
5130 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5131 if (!peer)
5132 return CMD_WARNING_CONFIG_FAILED;
5133
5134 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5135 if (!group) {
5136 vty_out(vty, "%% Configure the peer-group first\n");
5137 return CMD_WARNING_CONFIG_FAILED;
5138 }
5139
5140 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5141 bgp_zebra_terminate_radv(peer->bgp, peer);
5142
5143 peer_notify_unconfig(peer);
5144 ret = peer_delete(peer);
5145
5146 return bgp_vty_return(vty, ret);
5147 }
5148
5149 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5150 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5152 "Member of the peer-group\n"
5153 "Peer-group name\n")
5154
5155 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5156 uint64_t flag, int set)
5157 {
5158 int ret;
5159 struct peer *peer;
5160
5161 peer = peer_and_group_lookup_vty(vty, ip_str);
5162 if (!peer)
5163 return CMD_WARNING_CONFIG_FAILED;
5164
5165 /*
5166 * If 'neighbor <interface>', then this is for directly connected peers,
5167 * we should not accept disable-connected-check.
5168 */
5169 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5170 vty_out(vty,
5171 "%s is directly connected peer, cannot accept disable-connected-check\n",
5172 ip_str);
5173 return CMD_WARNING_CONFIG_FAILED;
5174 }
5175
5176 if (!set && flag == PEER_FLAG_SHUTDOWN)
5177 peer_tx_shutdown_message_unset(peer);
5178
5179 if (set)
5180 ret = peer_flag_set(peer, flag);
5181 else
5182 ret = peer_flag_unset(peer, flag);
5183
5184 return bgp_vty_return(vty, ret);
5185 }
5186
5187 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
5188 {
5189 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5190 }
5191
5192 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5193 uint64_t flag)
5194 {
5195 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5196 }
5197
5198 /* neighbor passive. */
5199 DEFUN (neighbor_passive,
5200 neighbor_passive_cmd,
5201 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5202 NEIGHBOR_STR
5203 NEIGHBOR_ADDR_STR2
5204 "Don't send open messages to this neighbor\n")
5205 {
5206 int idx_peer = 1;
5207 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5208 }
5209
5210 DEFUN (no_neighbor_passive,
5211 no_neighbor_passive_cmd,
5212 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5213 NO_STR
5214 NEIGHBOR_STR
5215 NEIGHBOR_ADDR_STR2
5216 "Don't send open messages to this neighbor\n")
5217 {
5218 int idx_peer = 2;
5219 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
5220 }
5221
5222 /* neighbor shutdown. */
5223 DEFUN (neighbor_shutdown_msg,
5224 neighbor_shutdown_msg_cmd,
5225 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5226 NEIGHBOR_STR
5227 NEIGHBOR_ADDR_STR2
5228 "Administratively shut down this neighbor\n"
5229 "Add a shutdown message (RFC 8203)\n"
5230 "Shutdown message\n")
5231 {
5232 int idx_peer = 1;
5233
5234 if (argc >= 5) {
5235 struct peer *peer =
5236 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5237 char *message;
5238
5239 if (!peer)
5240 return CMD_WARNING_CONFIG_FAILED;
5241 message = argv_concat(argv, argc, 4);
5242 peer_tx_shutdown_message_set(peer, message);
5243 XFREE(MTYPE_TMP, message);
5244 }
5245
5246 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
5247 }
5248
5249 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5250 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5251 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5252 "Administratively shut down this neighbor\n")
5253
5254 DEFUN (no_neighbor_shutdown_msg,
5255 no_neighbor_shutdown_msg_cmd,
5256 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5257 NO_STR
5258 NEIGHBOR_STR
5259 NEIGHBOR_ADDR_STR2
5260 "Administratively shut down this neighbor\n"
5261 "Remove a shutdown message (RFC 8203)\n"
5262 "Shutdown message\n")
5263 {
5264 int idx_peer = 2;
5265
5266 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5267 PEER_FLAG_SHUTDOWN);
5268 }
5269
5270 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5271 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5272 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5273 "Administratively shut down this neighbor\n")
5274
5275 DEFUN(neighbor_shutdown_rtt,
5276 neighbor_shutdown_rtt_cmd,
5277 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5278 NEIGHBOR_STR
5279 NEIGHBOR_ADDR_STR2
5280 "Administratively shut down this neighbor\n"
5281 "Shutdown if round-trip-time is higher than expected\n"
5282 "Round-trip-time in milliseconds\n"
5283 "Specify the number of keepalives before shutdown\n"
5284 "The number of keepalives with higher RTT to shutdown\n")
5285 {
5286 int idx_peer = 1;
5287 int idx_rtt = 4;
5288 int idx_count = 0;
5289 struct peer *peer;
5290
5291 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5292
5293 if (!peer)
5294 return CMD_WARNING_CONFIG_FAILED;
5295
5296 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5297
5298 if (argv_find(argv, argc, "count", &idx_count))
5299 peer->rtt_keepalive_conf =
5300 strtol(argv[idx_count + 1]->arg, NULL, 10);
5301
5302 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5303 PEER_FLAG_RTT_SHUTDOWN);
5304 }
5305
5306 DEFUN(no_neighbor_shutdown_rtt,
5307 no_neighbor_shutdown_rtt_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5309 NO_STR
5310 NEIGHBOR_STR
5311 NEIGHBOR_ADDR_STR2
5312 "Administratively shut down this neighbor\n"
5313 "Shutdown if round-trip-time is higher than expected\n"
5314 "Round-trip-time in milliseconds\n"
5315 "Specify the number of keepalives before shutdown\n"
5316 "The number of keepalives with higher RTT to shutdown\n")
5317 {
5318 int idx_peer = 2;
5319 struct peer *peer;
5320
5321 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5322
5323 if (!peer)
5324 return CMD_WARNING_CONFIG_FAILED;
5325
5326 peer->rtt_expected = 0;
5327 peer->rtt_keepalive_conf = 1;
5328
5329 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5330 PEER_FLAG_RTT_SHUTDOWN);
5331 }
5332
5333 /* neighbor capability dynamic. */
5334 DEFUN (neighbor_capability_dynamic,
5335 neighbor_capability_dynamic_cmd,
5336 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5337 NEIGHBOR_STR
5338 NEIGHBOR_ADDR_STR2
5339 "Advertise capability to the peer\n"
5340 "Advertise dynamic capability to this neighbor\n")
5341 {
5342 int idx_peer = 1;
5343 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5344 PEER_FLAG_DYNAMIC_CAPABILITY);
5345 }
5346
5347 DEFUN (no_neighbor_capability_dynamic,
5348 no_neighbor_capability_dynamic_cmd,
5349 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5350 NO_STR
5351 NEIGHBOR_STR
5352 NEIGHBOR_ADDR_STR2
5353 "Advertise capability to the peer\n"
5354 "Advertise dynamic capability to this neighbor\n")
5355 {
5356 int idx_peer = 2;
5357 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5358 PEER_FLAG_DYNAMIC_CAPABILITY);
5359 }
5360
5361 /* neighbor dont-capability-negotiate */
5362 DEFUN (neighbor_dont_capability_negotiate,
5363 neighbor_dont_capability_negotiate_cmd,
5364 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5365 NEIGHBOR_STR
5366 NEIGHBOR_ADDR_STR2
5367 "Do not perform capability negotiation\n")
5368 {
5369 int idx_peer = 1;
5370 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5371 PEER_FLAG_DONT_CAPABILITY);
5372 }
5373
5374 DEFUN (no_neighbor_dont_capability_negotiate,
5375 no_neighbor_dont_capability_negotiate_cmd,
5376 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5377 NO_STR
5378 NEIGHBOR_STR
5379 NEIGHBOR_ADDR_STR2
5380 "Do not perform capability negotiation\n")
5381 {
5382 int idx_peer = 2;
5383 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5384 PEER_FLAG_DONT_CAPABILITY);
5385 }
5386
5387 /* neighbor capability extended next hop encoding */
5388 DEFUN (neighbor_capability_enhe,
5389 neighbor_capability_enhe_cmd,
5390 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5391 NEIGHBOR_STR
5392 NEIGHBOR_ADDR_STR2
5393 "Advertise capability to the peer\n"
5394 "Advertise extended next-hop capability to the peer\n")
5395 {
5396 int idx_peer = 1;
5397 struct peer *peer;
5398
5399 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5400 if (peer && peer->conf_if)
5401 return CMD_SUCCESS;
5402
5403 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5404 PEER_FLAG_CAPABILITY_ENHE);
5405 }
5406
5407 DEFUN (no_neighbor_capability_enhe,
5408 no_neighbor_capability_enhe_cmd,
5409 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5410 NO_STR
5411 NEIGHBOR_STR
5412 NEIGHBOR_ADDR_STR2
5413 "Advertise capability to the peer\n"
5414 "Advertise extended next-hop capability to the peer\n")
5415 {
5416 int idx_peer = 2;
5417 struct peer *peer;
5418
5419 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5420 if (peer && peer->conf_if) {
5421 vty_out(vty,
5422 "Peer %s cannot have capability extended-nexthop turned off\n",
5423 argv[idx_peer]->arg);
5424 return CMD_WARNING_CONFIG_FAILED;
5425 }
5426
5427 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5428 PEER_FLAG_CAPABILITY_ENHE);
5429 }
5430
5431 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5432 afi_t afi, safi_t safi, uint32_t flag,
5433 int set)
5434 {
5435 int ret;
5436 struct peer *peer;
5437
5438 peer = peer_and_group_lookup_vty(vty, peer_str);
5439 if (!peer)
5440 return CMD_WARNING_CONFIG_FAILED;
5441
5442 if (set)
5443 ret = peer_af_flag_set(peer, afi, safi, flag);
5444 else
5445 ret = peer_af_flag_unset(peer, afi, safi, flag);
5446
5447 return bgp_vty_return(vty, ret);
5448 }
5449
5450 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5451 afi_t afi, safi_t safi, uint32_t flag)
5452 {
5453 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5454 }
5455
5456 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5457 afi_t afi, safi_t safi, uint32_t flag)
5458 {
5459 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5460 }
5461
5462 /* neighbor capability orf prefix-list. */
5463 DEFUN (neighbor_capability_orf_prefix,
5464 neighbor_capability_orf_prefix_cmd,
5465 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5466 NEIGHBOR_STR
5467 NEIGHBOR_ADDR_STR2
5468 "Advertise capability to the peer\n"
5469 "Advertise ORF capability to the peer\n"
5470 "Advertise prefixlist ORF capability to this neighbor\n"
5471 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5472 "Capability to RECEIVE the ORF from this neighbor\n"
5473 "Capability to SEND the ORF to this neighbor\n")
5474 {
5475 int idx_send_recv = 5;
5476 char *peer_str = argv[1]->arg;
5477 struct peer *peer;
5478 afi_t afi = bgp_node_afi(vty);
5479 safi_t safi = bgp_node_safi(vty);
5480
5481 peer = peer_and_group_lookup_vty(vty, peer_str);
5482 if (!peer)
5483 return CMD_WARNING_CONFIG_FAILED;
5484
5485 if (strmatch(argv[idx_send_recv]->text, "send"))
5486 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5487 PEER_FLAG_ORF_PREFIX_SM);
5488
5489 if (strmatch(argv[idx_send_recv]->text, "receive"))
5490 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5491 PEER_FLAG_ORF_PREFIX_RM);
5492
5493 if (strmatch(argv[idx_send_recv]->text, "both"))
5494 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5495 PEER_FLAG_ORF_PREFIX_SM)
5496 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5497 PEER_FLAG_ORF_PREFIX_RM);
5498
5499 return CMD_WARNING_CONFIG_FAILED;
5500 }
5501
5502 ALIAS_HIDDEN(
5503 neighbor_capability_orf_prefix,
5504 neighbor_capability_orf_prefix_hidden_cmd,
5505 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5506 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5507 "Advertise capability to the peer\n"
5508 "Advertise ORF capability to the peer\n"
5509 "Advertise prefixlist ORF capability to this neighbor\n"
5510 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5511 "Capability to RECEIVE the ORF from this neighbor\n"
5512 "Capability to SEND the ORF to this neighbor\n")
5513
5514 DEFUN (no_neighbor_capability_orf_prefix,
5515 no_neighbor_capability_orf_prefix_cmd,
5516 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5517 NO_STR
5518 NEIGHBOR_STR
5519 NEIGHBOR_ADDR_STR2
5520 "Advertise capability to the peer\n"
5521 "Advertise ORF capability to the peer\n"
5522 "Advertise prefixlist ORF capability to this neighbor\n"
5523 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5524 "Capability to RECEIVE the ORF from this neighbor\n"
5525 "Capability to SEND the ORF to this neighbor\n")
5526 {
5527 int idx_send_recv = 6;
5528 char *peer_str = argv[2]->arg;
5529 struct peer *peer;
5530 afi_t afi = bgp_node_afi(vty);
5531 safi_t safi = bgp_node_safi(vty);
5532
5533 peer = peer_and_group_lookup_vty(vty, peer_str);
5534 if (!peer)
5535 return CMD_WARNING_CONFIG_FAILED;
5536
5537 if (strmatch(argv[idx_send_recv]->text, "send"))
5538 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5539 PEER_FLAG_ORF_PREFIX_SM);
5540
5541 if (strmatch(argv[idx_send_recv]->text, "receive"))
5542 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5543 PEER_FLAG_ORF_PREFIX_RM);
5544
5545 if (strmatch(argv[idx_send_recv]->text, "both"))
5546 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5547 PEER_FLAG_ORF_PREFIX_SM)
5548 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5549 PEER_FLAG_ORF_PREFIX_RM);
5550
5551 return CMD_WARNING_CONFIG_FAILED;
5552 }
5553
5554 ALIAS_HIDDEN(
5555 no_neighbor_capability_orf_prefix,
5556 no_neighbor_capability_orf_prefix_hidden_cmd,
5557 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5558 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5559 "Advertise capability to the peer\n"
5560 "Advertise ORF capability to the peer\n"
5561 "Advertise prefixlist ORF capability to this neighbor\n"
5562 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5563 "Capability to RECEIVE the ORF from this neighbor\n"
5564 "Capability to SEND the ORF to this neighbor\n")
5565
5566 /* neighbor next-hop-self. */
5567 DEFUN (neighbor_nexthop_self,
5568 neighbor_nexthop_self_cmd,
5569 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5570 NEIGHBOR_STR
5571 NEIGHBOR_ADDR_STR2
5572 "Disable the next hop calculation for this neighbor\n")
5573 {
5574 int idx_peer = 1;
5575 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5576 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
5577 }
5578
5579 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5580 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5582 "Disable the next hop calculation for this neighbor\n")
5583
5584 /* neighbor next-hop-self. */
5585 DEFUN (neighbor_nexthop_self_force,
5586 neighbor_nexthop_self_force_cmd,
5587 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5588 NEIGHBOR_STR
5589 NEIGHBOR_ADDR_STR2
5590 "Disable the next hop calculation for this neighbor\n"
5591 "Set the next hop to self for reflected routes\n")
5592 {
5593 int idx_peer = 1;
5594 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5595 bgp_node_safi(vty),
5596 PEER_FLAG_FORCE_NEXTHOP_SELF);
5597 }
5598
5599 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5600 neighbor_nexthop_self_force_hidden_cmd,
5601 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5602 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5603 "Disable the next hop calculation for this neighbor\n"
5604 "Set the next hop to self for reflected routes\n")
5605
5606 ALIAS_HIDDEN(neighbor_nexthop_self_force,
5607 neighbor_nexthop_self_all_hidden_cmd,
5608 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5609 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5610 "Disable the next hop calculation for this neighbor\n"
5611 "Set the next hop to self for reflected routes\n")
5612
5613 DEFUN (no_neighbor_nexthop_self,
5614 no_neighbor_nexthop_self_cmd,
5615 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5616 NO_STR
5617 NEIGHBOR_STR
5618 NEIGHBOR_ADDR_STR2
5619 "Disable the next hop calculation for this neighbor\n")
5620 {
5621 int idx_peer = 2;
5622 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5623 bgp_node_afi(vty), bgp_node_safi(vty),
5624 PEER_FLAG_NEXTHOP_SELF);
5625 }
5626
5627 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5628 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5629 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5630 "Disable the next hop calculation for this neighbor\n")
5631
5632 DEFUN (no_neighbor_nexthop_self_force,
5633 no_neighbor_nexthop_self_force_cmd,
5634 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5635 NO_STR
5636 NEIGHBOR_STR
5637 NEIGHBOR_ADDR_STR2
5638 "Disable the next hop calculation for this neighbor\n"
5639 "Set the next hop to self for reflected routes\n")
5640 {
5641 int idx_peer = 2;
5642 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5643 bgp_node_afi(vty), bgp_node_safi(vty),
5644 PEER_FLAG_FORCE_NEXTHOP_SELF);
5645 }
5646
5647 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5648 no_neighbor_nexthop_self_force_hidden_cmd,
5649 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5650 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5651 "Disable the next hop calculation for this neighbor\n"
5652 "Set the next hop to self for reflected routes\n")
5653
5654 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5655 no_neighbor_nexthop_self_all_hidden_cmd,
5656 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5657 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5658 "Disable the next hop calculation for this neighbor\n"
5659 "Set the next hop to self for reflected routes\n")
5660
5661 /* neighbor as-override */
5662 DEFUN (neighbor_as_override,
5663 neighbor_as_override_cmd,
5664 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5665 NEIGHBOR_STR
5666 NEIGHBOR_ADDR_STR2
5667 "Override ASNs in outbound updates if aspath equals remote-as\n")
5668 {
5669 int idx_peer = 1;
5670 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5671 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
5672 }
5673
5674 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5675 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5676 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5677 "Override ASNs in outbound updates if aspath equals remote-as\n")
5678
5679 DEFUN (no_neighbor_as_override,
5680 no_neighbor_as_override_cmd,
5681 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5682 NO_STR
5683 NEIGHBOR_STR
5684 NEIGHBOR_ADDR_STR2
5685 "Override ASNs in outbound updates if aspath equals remote-as\n")
5686 {
5687 int idx_peer = 2;
5688 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5689 bgp_node_afi(vty), bgp_node_safi(vty),
5690 PEER_FLAG_AS_OVERRIDE);
5691 }
5692
5693 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5694 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5695 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5696 "Override ASNs in outbound updates if aspath equals remote-as\n")
5697
5698 /* neighbor remove-private-AS. */
5699 DEFUN (neighbor_remove_private_as,
5700 neighbor_remove_private_as_cmd,
5701 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5702 NEIGHBOR_STR
5703 NEIGHBOR_ADDR_STR2
5704 "Remove private ASNs in outbound updates\n")
5705 {
5706 int idx_peer = 1;
5707 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5708 bgp_node_safi(vty),
5709 PEER_FLAG_REMOVE_PRIVATE_AS);
5710 }
5711
5712 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5713 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5714 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Remove private ASNs in outbound updates\n")
5716
5717 DEFUN (neighbor_remove_private_as_all,
5718 neighbor_remove_private_as_all_cmd,
5719 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5720 NEIGHBOR_STR
5721 NEIGHBOR_ADDR_STR2
5722 "Remove private ASNs in outbound updates\n"
5723 "Apply to all AS numbers\n")
5724 {
5725 int idx_peer = 1;
5726 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5727 bgp_node_safi(vty),
5728 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5729 }
5730
5731 ALIAS_HIDDEN(neighbor_remove_private_as_all,
5732 neighbor_remove_private_as_all_hidden_cmd,
5733 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5734 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5735 "Remove private ASNs in outbound updates\n"
5736 "Apply to all AS numbers")
5737
5738 DEFUN (neighbor_remove_private_as_replace_as,
5739 neighbor_remove_private_as_replace_as_cmd,
5740 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5741 NEIGHBOR_STR
5742 NEIGHBOR_ADDR_STR2
5743 "Remove private ASNs in outbound updates\n"
5744 "Replace private ASNs with our ASN in outbound updates\n")
5745 {
5746 int idx_peer = 1;
5747 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5748 bgp_node_safi(vty),
5749 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5750 }
5751
5752 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5753 neighbor_remove_private_as_replace_as_hidden_cmd,
5754 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5755 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5756 "Remove private ASNs in outbound updates\n"
5757 "Replace private ASNs with our ASN in outbound updates\n")
5758
5759 DEFUN (neighbor_remove_private_as_all_replace_as,
5760 neighbor_remove_private_as_all_replace_as_cmd,
5761 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5762 NEIGHBOR_STR
5763 NEIGHBOR_ADDR_STR2
5764 "Remove private ASNs in outbound updates\n"
5765 "Apply to all AS numbers\n"
5766 "Replace private ASNs with our ASN in outbound updates\n")
5767 {
5768 int idx_peer = 1;
5769 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5770 bgp_node_safi(vty),
5771 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5772 }
5773
5774 ALIAS_HIDDEN(
5775 neighbor_remove_private_as_all_replace_as,
5776 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5777 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5778 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5779 "Remove private ASNs in outbound updates\n"
5780 "Apply to all AS numbers\n"
5781 "Replace private ASNs with our ASN in outbound updates\n")
5782
5783 DEFUN (no_neighbor_remove_private_as,
5784 no_neighbor_remove_private_as_cmd,
5785 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5786 NO_STR
5787 NEIGHBOR_STR
5788 NEIGHBOR_ADDR_STR2
5789 "Remove private ASNs in outbound updates\n")
5790 {
5791 int idx_peer = 2;
5792 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5793 bgp_node_afi(vty), bgp_node_safi(vty),
5794 PEER_FLAG_REMOVE_PRIVATE_AS);
5795 }
5796
5797 ALIAS_HIDDEN(no_neighbor_remove_private_as,
5798 no_neighbor_remove_private_as_hidden_cmd,
5799 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5800 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5801 "Remove private ASNs in outbound updates\n")
5802
5803 DEFUN (no_neighbor_remove_private_as_all,
5804 no_neighbor_remove_private_as_all_cmd,
5805 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5806 NO_STR
5807 NEIGHBOR_STR
5808 NEIGHBOR_ADDR_STR2
5809 "Remove private ASNs in outbound updates\n"
5810 "Apply to all AS numbers\n")
5811 {
5812 int idx_peer = 2;
5813 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5814 bgp_node_afi(vty), bgp_node_safi(vty),
5815 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5816 }
5817
5818 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5819 no_neighbor_remove_private_as_all_hidden_cmd,
5820 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5821 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5822 "Remove private ASNs in outbound updates\n"
5823 "Apply to all AS numbers\n")
5824
5825 DEFUN (no_neighbor_remove_private_as_replace_as,
5826 no_neighbor_remove_private_as_replace_as_cmd,
5827 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5828 NO_STR
5829 NEIGHBOR_STR
5830 NEIGHBOR_ADDR_STR2
5831 "Remove private ASNs in outbound updates\n"
5832 "Replace private ASNs with our ASN in outbound updates\n")
5833 {
5834 int idx_peer = 2;
5835 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5836 bgp_node_afi(vty), bgp_node_safi(vty),
5837 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5838 }
5839
5840 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5841 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5842 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5843 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5844 "Remove private ASNs in outbound updates\n"
5845 "Replace private ASNs with our ASN in outbound updates\n")
5846
5847 DEFUN (no_neighbor_remove_private_as_all_replace_as,
5848 no_neighbor_remove_private_as_all_replace_as_cmd,
5849 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5850 NO_STR
5851 NEIGHBOR_STR
5852 NEIGHBOR_ADDR_STR2
5853 "Remove private ASNs in outbound updates\n"
5854 "Apply to all AS numbers\n"
5855 "Replace private ASNs with our ASN in outbound updates\n")
5856 {
5857 int idx_peer = 2;
5858 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5859 bgp_node_afi(vty), bgp_node_safi(vty),
5860 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5861 }
5862
5863 ALIAS_HIDDEN(
5864 no_neighbor_remove_private_as_all_replace_as,
5865 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5866 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5867 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5868 "Remove private ASNs in outbound updates\n"
5869 "Apply to all AS numbers\n"
5870 "Replace private ASNs with our ASN in outbound updates\n")
5871
5872
5873 /* neighbor send-community. */
5874 DEFUN (neighbor_send_community,
5875 neighbor_send_community_cmd,
5876 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5877 NEIGHBOR_STR
5878 NEIGHBOR_ADDR_STR2
5879 "Send Community attribute to this neighbor\n")
5880 {
5881 int idx_peer = 1;
5882
5883 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5884 bgp_node_safi(vty),
5885 PEER_FLAG_SEND_COMMUNITY);
5886 }
5887
5888 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5889 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5891 "Send Community attribute to this neighbor\n")
5892
5893 DEFUN (no_neighbor_send_community,
5894 no_neighbor_send_community_cmd,
5895 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5896 NO_STR
5897 NEIGHBOR_STR
5898 NEIGHBOR_ADDR_STR2
5899 "Send Community attribute to this neighbor\n")
5900 {
5901 int idx_peer = 2;
5902
5903 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5904 bgp_node_afi(vty), bgp_node_safi(vty),
5905 PEER_FLAG_SEND_COMMUNITY);
5906 }
5907
5908 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5909 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5910 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5911 "Send Community attribute to this neighbor\n")
5912
5913 /* neighbor send-community extended. */
5914 DEFUN (neighbor_send_community_type,
5915 neighbor_send_community_type_cmd,
5916 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5917 NEIGHBOR_STR
5918 NEIGHBOR_ADDR_STR2
5919 "Send Community attribute to this neighbor\n"
5920 "Send Standard and Extended Community attributes\n"
5921 "Send Standard, Large and Extended Community attributes\n"
5922 "Send Extended Community attributes\n"
5923 "Send Standard Community attributes\n"
5924 "Send Large Community attributes\n")
5925 {
5926 const char *type = argv[argc - 1]->text;
5927 char *peer_str = argv[1]->arg;
5928 struct peer *peer;
5929 afi_t afi = bgp_node_afi(vty);
5930 safi_t safi = bgp_node_safi(vty);
5931
5932 peer = peer_and_group_lookup_vty(vty, peer_str);
5933 if (!peer)
5934 return CMD_WARNING_CONFIG_FAILED;
5935
5936 if (strmatch(type, "standard"))
5937 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5938 PEER_FLAG_SEND_COMMUNITY);
5939
5940 if (strmatch(type, "extended"))
5941 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5942 PEER_FLAG_SEND_EXT_COMMUNITY);
5943
5944 if (strmatch(type, "large"))
5945 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5946 PEER_FLAG_SEND_LARGE_COMMUNITY);
5947
5948 if (strmatch(type, "both")) {
5949 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5950 PEER_FLAG_SEND_COMMUNITY)
5951 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5952 PEER_FLAG_SEND_EXT_COMMUNITY);
5953 }
5954 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5955 PEER_FLAG_SEND_COMMUNITY)
5956 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5957 PEER_FLAG_SEND_EXT_COMMUNITY)
5958 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5959 PEER_FLAG_SEND_LARGE_COMMUNITY);
5960 }
5961
5962 ALIAS_HIDDEN(
5963 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5964 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5966 "Send Community attribute to this neighbor\n"
5967 "Send Standard and Extended Community attributes\n"
5968 "Send Standard, Large and Extended Community attributes\n"
5969 "Send Extended Community attributes\n"
5970 "Send Standard Community attributes\n"
5971 "Send Large Community attributes\n")
5972
5973 DEFUN (no_neighbor_send_community_type,
5974 no_neighbor_send_community_type_cmd,
5975 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5976 NO_STR
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Send Community attribute to this neighbor\n"
5980 "Send Standard and Extended Community attributes\n"
5981 "Send Standard, Large and Extended Community attributes\n"
5982 "Send Extended Community attributes\n"
5983 "Send Standard Community attributes\n"
5984 "Send Large Community attributes\n")
5985 {
5986 const char *type = argv[argc - 1]->text;
5987 char *peer_str = argv[2]->arg;
5988 struct peer *peer;
5989 afi_t afi = bgp_node_afi(vty);
5990 safi_t safi = bgp_node_safi(vty);
5991
5992 peer = peer_and_group_lookup_vty(vty, peer_str);
5993 if (!peer)
5994 return CMD_WARNING_CONFIG_FAILED;
5995
5996 if (strmatch(type, "standard"))
5997 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5998 PEER_FLAG_SEND_COMMUNITY);
5999
6000 if (strmatch(type, "extended"))
6001 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6002 PEER_FLAG_SEND_EXT_COMMUNITY);
6003
6004 if (strmatch(type, "large"))
6005 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6006 PEER_FLAG_SEND_LARGE_COMMUNITY);
6007
6008 if (strmatch(type, "both")) {
6009
6010 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6011 PEER_FLAG_SEND_COMMUNITY)
6012 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6013 PEER_FLAG_SEND_EXT_COMMUNITY);
6014 }
6015
6016 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6017 PEER_FLAG_SEND_COMMUNITY)
6018 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6019 PEER_FLAG_SEND_EXT_COMMUNITY)
6020 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6021 PEER_FLAG_SEND_LARGE_COMMUNITY);
6022 }
6023
6024 ALIAS_HIDDEN(
6025 no_neighbor_send_community_type,
6026 no_neighbor_send_community_type_hidden_cmd,
6027 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6028 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6029 "Send Community attribute to this neighbor\n"
6030 "Send Standard and Extended Community attributes\n"
6031 "Send Standard, Large and Extended Community attributes\n"
6032 "Send Extended Community attributes\n"
6033 "Send Standard Community attributes\n"
6034 "Send Large Community attributes\n")
6035
6036 /* neighbor soft-reconfig. */
6037 DEFUN (neighbor_soft_reconfiguration,
6038 neighbor_soft_reconfiguration_cmd,
6039 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6040 NEIGHBOR_STR
6041 NEIGHBOR_ADDR_STR2
6042 "Per neighbor soft reconfiguration\n"
6043 "Allow inbound soft reconfiguration for this neighbor\n")
6044 {
6045 int idx_peer = 1;
6046 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6047 bgp_node_safi(vty),
6048 PEER_FLAG_SOFT_RECONFIG);
6049 }
6050
6051 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6052 neighbor_soft_reconfiguration_hidden_cmd,
6053 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6054 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6055 "Per neighbor soft reconfiguration\n"
6056 "Allow inbound soft reconfiguration for this neighbor\n")
6057
6058 DEFUN (no_neighbor_soft_reconfiguration,
6059 no_neighbor_soft_reconfiguration_cmd,
6060 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6061 NO_STR
6062 NEIGHBOR_STR
6063 NEIGHBOR_ADDR_STR2
6064 "Per neighbor soft reconfiguration\n"
6065 "Allow inbound soft reconfiguration for this neighbor\n")
6066 {
6067 int idx_peer = 2;
6068 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6069 bgp_node_afi(vty), bgp_node_safi(vty),
6070 PEER_FLAG_SOFT_RECONFIG);
6071 }
6072
6073 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6074 no_neighbor_soft_reconfiguration_hidden_cmd,
6075 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6076 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6077 "Per neighbor soft reconfiguration\n"
6078 "Allow inbound soft reconfiguration for this neighbor\n")
6079
6080 DEFUN (neighbor_route_reflector_client,
6081 neighbor_route_reflector_client_cmd,
6082 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6083 NEIGHBOR_STR
6084 NEIGHBOR_ADDR_STR2
6085 "Configure a neighbor as Route Reflector client\n")
6086 {
6087 int idx_peer = 1;
6088 struct peer *peer;
6089
6090
6091 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6092 if (!peer)
6093 return CMD_WARNING_CONFIG_FAILED;
6094
6095 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6096 bgp_node_safi(vty),
6097 PEER_FLAG_REFLECTOR_CLIENT);
6098 }
6099
6100 ALIAS_HIDDEN(neighbor_route_reflector_client,
6101 neighbor_route_reflector_client_hidden_cmd,
6102 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6104 "Configure a neighbor as Route Reflector client\n")
6105
6106 DEFUN (no_neighbor_route_reflector_client,
6107 no_neighbor_route_reflector_client_cmd,
6108 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6109 NO_STR
6110 NEIGHBOR_STR
6111 NEIGHBOR_ADDR_STR2
6112 "Configure a neighbor as Route Reflector client\n")
6113 {
6114 int idx_peer = 2;
6115 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6116 bgp_node_afi(vty), bgp_node_safi(vty),
6117 PEER_FLAG_REFLECTOR_CLIENT);
6118 }
6119
6120 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6121 no_neighbor_route_reflector_client_hidden_cmd,
6122 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6123 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6124 "Configure a neighbor as Route Reflector client\n")
6125
6126 /* neighbor route-server-client. */
6127 DEFUN (neighbor_route_server_client,
6128 neighbor_route_server_client_cmd,
6129 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6130 NEIGHBOR_STR
6131 NEIGHBOR_ADDR_STR2
6132 "Configure a neighbor as Route Server client\n")
6133 {
6134 int idx_peer = 1;
6135 struct peer *peer;
6136
6137 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6138 if (!peer)
6139 return CMD_WARNING_CONFIG_FAILED;
6140 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6141 bgp_node_safi(vty),
6142 PEER_FLAG_RSERVER_CLIENT);
6143 }
6144
6145 ALIAS_HIDDEN(neighbor_route_server_client,
6146 neighbor_route_server_client_hidden_cmd,
6147 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6148 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6149 "Configure a neighbor as Route Server client\n")
6150
6151 DEFUN (no_neighbor_route_server_client,
6152 no_neighbor_route_server_client_cmd,
6153 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6154 NO_STR
6155 NEIGHBOR_STR
6156 NEIGHBOR_ADDR_STR2
6157 "Configure a neighbor as Route Server client\n")
6158 {
6159 int idx_peer = 2;
6160 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6161 bgp_node_afi(vty), bgp_node_safi(vty),
6162 PEER_FLAG_RSERVER_CLIENT);
6163 }
6164
6165 ALIAS_HIDDEN(no_neighbor_route_server_client,
6166 no_neighbor_route_server_client_hidden_cmd,
6167 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6168 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6169 "Configure a neighbor as Route Server client\n")
6170
6171 DEFUN (neighbor_nexthop_local_unchanged,
6172 neighbor_nexthop_local_unchanged_cmd,
6173 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6174 NEIGHBOR_STR
6175 NEIGHBOR_ADDR_STR2
6176 "Configure treatment of outgoing link-local nexthop attribute\n"
6177 "Leave link-local nexthop unchanged for this peer\n")
6178 {
6179 int idx_peer = 1;
6180 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6181 bgp_node_safi(vty),
6182 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6183 }
6184
6185 DEFUN (no_neighbor_nexthop_local_unchanged,
6186 no_neighbor_nexthop_local_unchanged_cmd,
6187 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6188 NO_STR
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
6191 "Configure treatment of outgoing link-local-nexthop attribute\n"
6192 "Leave link-local nexthop unchanged for this peer\n")
6193 {
6194 int idx_peer = 2;
6195 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6196 bgp_node_afi(vty), bgp_node_safi(vty),
6197 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6198 }
6199
6200 DEFUN (neighbor_attr_unchanged,
6201 neighbor_attr_unchanged_cmd,
6202 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6203 NEIGHBOR_STR
6204 NEIGHBOR_ADDR_STR2
6205 "BGP attribute is propagated unchanged to this neighbor\n"
6206 "As-path attribute\n"
6207 "Nexthop attribute\n"
6208 "Med attribute\n")
6209 {
6210 int idx = 0;
6211 char *peer_str = argv[1]->arg;
6212 struct peer *peer;
6213 bool aspath = false;
6214 bool nexthop = false;
6215 bool med = false;
6216 afi_t afi = bgp_node_afi(vty);
6217 safi_t safi = bgp_node_safi(vty);
6218 int ret = 0;
6219
6220 peer = peer_and_group_lookup_vty(vty, peer_str);
6221 if (!peer)
6222 return CMD_WARNING_CONFIG_FAILED;
6223
6224 if (argv_find(argv, argc, "as-path", &idx))
6225 aspath = true;
6226
6227 idx = 0;
6228 if (argv_find(argv, argc, "next-hop", &idx))
6229 nexthop = true;
6230
6231 idx = 0;
6232 if (argv_find(argv, argc, "med", &idx))
6233 med = true;
6234
6235 /* no flags means all of them! */
6236 if (!aspath && !nexthop && !med) {
6237 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6238 PEER_FLAG_AS_PATH_UNCHANGED);
6239 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6240 PEER_FLAG_NEXTHOP_UNCHANGED);
6241 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6242 PEER_FLAG_MED_UNCHANGED);
6243 } else {
6244 if (!aspath) {
6245 if (peer_af_flag_check(peer, afi, safi,
6246 PEER_FLAG_AS_PATH_UNCHANGED)) {
6247 ret |= peer_af_flag_unset_vty(
6248 vty, peer_str, afi, safi,
6249 PEER_FLAG_AS_PATH_UNCHANGED);
6250 }
6251 } else
6252 ret |= peer_af_flag_set_vty(
6253 vty, peer_str, afi, safi,
6254 PEER_FLAG_AS_PATH_UNCHANGED);
6255
6256 if (!nexthop) {
6257 if (peer_af_flag_check(peer, afi, safi,
6258 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6259 ret |= peer_af_flag_unset_vty(
6260 vty, peer_str, afi, safi,
6261 PEER_FLAG_NEXTHOP_UNCHANGED);
6262 }
6263 } else
6264 ret |= peer_af_flag_set_vty(
6265 vty, peer_str, afi, safi,
6266 PEER_FLAG_NEXTHOP_UNCHANGED);
6267
6268 if (!med) {
6269 if (peer_af_flag_check(peer, afi, safi,
6270 PEER_FLAG_MED_UNCHANGED)) {
6271 ret |= peer_af_flag_unset_vty(
6272 vty, peer_str, afi, safi,
6273 PEER_FLAG_MED_UNCHANGED);
6274 }
6275 } else
6276 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6277 PEER_FLAG_MED_UNCHANGED);
6278 }
6279
6280 return ret;
6281 }
6282
6283 ALIAS_HIDDEN(
6284 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6285 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6286 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6287 "BGP attribute is propagated unchanged to this neighbor\n"
6288 "As-path attribute\n"
6289 "Nexthop attribute\n"
6290 "Med attribute\n")
6291
6292 DEFUN (no_neighbor_attr_unchanged,
6293 no_neighbor_attr_unchanged_cmd,
6294 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6295 NO_STR
6296 NEIGHBOR_STR
6297 NEIGHBOR_ADDR_STR2
6298 "BGP attribute is propagated unchanged to this neighbor\n"
6299 "As-path attribute\n"
6300 "Nexthop attribute\n"
6301 "Med attribute\n")
6302 {
6303 int idx = 0;
6304 char *peer_str = argv[2]->arg;
6305 struct peer *peer;
6306 bool aspath = false;
6307 bool nexthop = false;
6308 bool med = false;
6309 afi_t afi = bgp_node_afi(vty);
6310 safi_t safi = bgp_node_safi(vty);
6311 int ret = 0;
6312
6313 peer = peer_and_group_lookup_vty(vty, peer_str);
6314 if (!peer)
6315 return CMD_WARNING_CONFIG_FAILED;
6316
6317 if (argv_find(argv, argc, "as-path", &idx))
6318 aspath = true;
6319
6320 idx = 0;
6321 if (argv_find(argv, argc, "next-hop", &idx))
6322 nexthop = true;
6323
6324 idx = 0;
6325 if (argv_find(argv, argc, "med", &idx))
6326 med = true;
6327
6328 if (!aspath && !nexthop && !med) // no flags means all of them!
6329 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6330 PEER_FLAG_AS_PATH_UNCHANGED)
6331 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6332 PEER_FLAG_NEXTHOP_UNCHANGED)
6333 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6334 PEER_FLAG_MED_UNCHANGED);
6335
6336 if (aspath)
6337 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6338 PEER_FLAG_AS_PATH_UNCHANGED);
6339
6340 if (nexthop)
6341 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6342 PEER_FLAG_NEXTHOP_UNCHANGED);
6343
6344 if (med)
6345 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6346 PEER_FLAG_MED_UNCHANGED);
6347
6348 return ret;
6349 }
6350
6351 ALIAS_HIDDEN(
6352 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6353 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6354 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6355 "BGP attribute is propagated unchanged to this neighbor\n"
6356 "As-path attribute\n"
6357 "Nexthop attribute\n"
6358 "Med attribute\n")
6359
6360 /* EBGP multihop configuration. */
6361 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6362 const char *ttl_str)
6363 {
6364 struct peer *peer;
6365 unsigned int ttl;
6366
6367 peer = peer_and_group_lookup_vty(vty, ip_str);
6368 if (!peer)
6369 return CMD_WARNING_CONFIG_FAILED;
6370
6371 if (peer->conf_if)
6372 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6373
6374 if (!ttl_str)
6375 ttl = MAXTTL;
6376 else
6377 ttl = strtoul(ttl_str, NULL, 10);
6378
6379 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
6380 }
6381
6382 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
6383 {
6384 struct peer *peer;
6385
6386 peer = peer_and_group_lookup_vty(vty, ip_str);
6387 if (!peer)
6388 return CMD_WARNING_CONFIG_FAILED;
6389
6390 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
6391 }
6392
6393 /* neighbor ebgp-multihop. */
6394 DEFUN (neighbor_ebgp_multihop,
6395 neighbor_ebgp_multihop_cmd,
6396 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6397 NEIGHBOR_STR
6398 NEIGHBOR_ADDR_STR2
6399 "Allow EBGP neighbors not on directly connected networks\n")
6400 {
6401 int idx_peer = 1;
6402 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6403 }
6404
6405 DEFUN (neighbor_ebgp_multihop_ttl,
6406 neighbor_ebgp_multihop_ttl_cmd,
6407 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6408 NEIGHBOR_STR
6409 NEIGHBOR_ADDR_STR2
6410 "Allow EBGP neighbors not on directly connected networks\n"
6411 "maximum hop count\n")
6412 {
6413 int idx_peer = 1;
6414 int idx_number = 3;
6415 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6416 argv[idx_number]->arg);
6417 }
6418
6419 DEFUN (no_neighbor_ebgp_multihop,
6420 no_neighbor_ebgp_multihop_cmd,
6421 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6422 NO_STR
6423 NEIGHBOR_STR
6424 NEIGHBOR_ADDR_STR2
6425 "Allow EBGP neighbors not on directly connected networks\n"
6426 "maximum hop count\n")
6427 {
6428 int idx_peer = 2;
6429 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
6430 }
6431
6432 static uint8_t get_role_by_name(const char *role_str)
6433 {
6434 if (strncmp(role_str, "peer", 2) == 0)
6435 return ROLE_PEER;
6436 if (strncmp(role_str, "provider", 2) == 0)
6437 return ROLE_PROVIDER;
6438 if (strncmp(role_str, "customer", 2) == 0)
6439 return ROLE_CUSTOMER;
6440 if (strncmp(role_str, "rs-server", 4) == 0)
6441 return ROLE_RS_SERVER;
6442 if (strncmp(role_str, "rs-client", 4) == 0)
6443 return ROLE_RS_CLIENT;
6444 return ROLE_UNDEFINED;
6445 }
6446
6447 static int peer_role_set_vty(struct vty *vty, const char *ip_str,
6448 const char *role_str, bool strict_mode)
6449 {
6450 struct peer *peer;
6451
6452 peer = peer_and_group_lookup_vty(vty, ip_str);
6453 if (!peer)
6454 return CMD_WARNING_CONFIG_FAILED;
6455 uint8_t role = get_role_by_name(role_str);
6456
6457 if (role == ROLE_UNDEFINED)
6458 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6459 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6460 }
6461
6462 static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6463 {
6464 struct peer *peer;
6465
6466 peer = peer_and_group_lookup_vty(vty, ip_str);
6467 if (!peer)
6468 return CMD_WARNING_CONFIG_FAILED;
6469 return bgp_vty_return(vty, peer_role_unset(peer));
6470 }
6471
6472 DEFPY(neighbor_role,
6473 neighbor_role_cmd,
6474 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6475 NEIGHBOR_STR
6476 NEIGHBOR_ADDR_STR2
6477 "Set session role\n"
6478 ROLE_STR)
6479 {
6480 int idx_peer = 1;
6481 int idx_role = 3;
6482
6483 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6484 false);
6485 }
6486
6487 DEFPY(neighbor_role_strict,
6488 neighbor_role_strict_cmd,
6489 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6490 NEIGHBOR_STR
6491 NEIGHBOR_ADDR_STR2
6492 "Set session role\n"
6493 ROLE_STR
6494 "Use additional restriction on peer\n")
6495 {
6496 int idx_peer = 1;
6497 int idx_role = 3;
6498
6499 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
6500 true);
6501 }
6502
6503 DEFPY(no_neighbor_role,
6504 no_neighbor_role_cmd,
6505 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6506 NO_STR
6507 NEIGHBOR_STR
6508 NEIGHBOR_ADDR_STR2
6509 "Set session role\n"
6510 ROLE_STR
6511 "Use additional restriction on peer\n")
6512 {
6513 int idx_peer = 2;
6514
6515 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6516 }
6517
6518 /* disable-connected-check */
6519 DEFUN (neighbor_disable_connected_check,
6520 neighbor_disable_connected_check_cmd,
6521 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6522 NEIGHBOR_STR
6523 NEIGHBOR_ADDR_STR2
6524 "one-hop away EBGP peer using loopback address\n"
6525 "Enforce EBGP neighbors perform multihop\n")
6526 {
6527 int idx_peer = 1;
6528 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6529 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6530 }
6531
6532 DEFUN (no_neighbor_disable_connected_check,
6533 no_neighbor_disable_connected_check_cmd,
6534 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6535 NO_STR
6536 NEIGHBOR_STR
6537 NEIGHBOR_ADDR_STR2
6538 "one-hop away EBGP peer using loopback address\n"
6539 "Enforce EBGP neighbors perform multihop\n")
6540 {
6541 int idx_peer = 2;
6542 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6543 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6544 }
6545
6546 /* disable-link-bw-encoding-ieee */
6547 DEFUN(neighbor_disable_link_bw_encoding_ieee,
6548 neighbor_disable_link_bw_encoding_ieee_cmd,
6549 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6550 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6551 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6552 {
6553 int idx_peer = 1;
6554
6555 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6556 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6557 }
6558
6559 DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6560 no_neighbor_disable_link_bw_encoding_ieee_cmd,
6561 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6562 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6563 "Disable IEEE floating-point encoding for extended community bandwidth\n")
6564 {
6565 int idx_peer = 2;
6566
6567 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6568 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6569 }
6570
6571 /* extended-optional-parameters */
6572 DEFUN(neighbor_extended_optional_parameters,
6573 neighbor_extended_optional_parameters_cmd,
6574 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6575 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6576 "Force the extended optional parameters format for OPEN messages\n")
6577 {
6578 int idx_peer = 1;
6579
6580 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6581 PEER_FLAG_EXTENDED_OPT_PARAMS);
6582 }
6583
6584 DEFUN(no_neighbor_extended_optional_parameters,
6585 no_neighbor_extended_optional_parameters_cmd,
6586 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6587 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6588 "Force the extended optional parameters format for OPEN messages\n")
6589 {
6590 int idx_peer = 2;
6591
6592 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6593 PEER_FLAG_EXTENDED_OPT_PARAMS);
6594 }
6595
6596 /* enforce-first-as */
6597 DEFUN (neighbor_enforce_first_as,
6598 neighbor_enforce_first_as_cmd,
6599 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6600 NEIGHBOR_STR
6601 NEIGHBOR_ADDR_STR2
6602 "Enforce the first AS for EBGP routes\n")
6603 {
6604 int idx_peer = 1;
6605
6606 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6607 PEER_FLAG_ENFORCE_FIRST_AS);
6608 }
6609
6610 DEFUN (no_neighbor_enforce_first_as,
6611 no_neighbor_enforce_first_as_cmd,
6612 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6613 NO_STR
6614 NEIGHBOR_STR
6615 NEIGHBOR_ADDR_STR2
6616 "Enforce the first AS for EBGP routes\n")
6617 {
6618 int idx_peer = 2;
6619
6620 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6621 PEER_FLAG_ENFORCE_FIRST_AS);
6622 }
6623
6624
6625 DEFUN (neighbor_description,
6626 neighbor_description_cmd,
6627 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6628 NEIGHBOR_STR
6629 NEIGHBOR_ADDR_STR2
6630 "Neighbor specific description\n"
6631 "Up to 80 characters describing this neighbor\n")
6632 {
6633 int idx_peer = 1;
6634 int idx_line = 3;
6635 struct peer *peer;
6636 char *str;
6637
6638 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6639 if (!peer)
6640 return CMD_WARNING_CONFIG_FAILED;
6641
6642 str = argv_concat(argv, argc, idx_line);
6643
6644 peer_description_set(peer, str);
6645
6646 XFREE(MTYPE_TMP, str);
6647
6648 return CMD_SUCCESS;
6649 }
6650
6651 DEFUN (no_neighbor_description,
6652 no_neighbor_description_cmd,
6653 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6654 NO_STR
6655 NEIGHBOR_STR
6656 NEIGHBOR_ADDR_STR2
6657 "Neighbor specific description\n")
6658 {
6659 int idx_peer = 2;
6660 struct peer *peer;
6661
6662 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6663 if (!peer)
6664 return CMD_WARNING_CONFIG_FAILED;
6665
6666 peer_description_unset(peer);
6667
6668 return CMD_SUCCESS;
6669 }
6670
6671 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6672 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6673 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6674 "Neighbor specific description\n"
6675 "Up to 80 characters describing this neighbor\n")
6676
6677 /* Neighbor update-source. */
6678 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6679 const char *source_str)
6680 {
6681 struct peer *peer;
6682 struct prefix p;
6683 union sockunion su;
6684
6685 peer = peer_and_group_lookup_vty(vty, peer_str);
6686 if (!peer)
6687 return CMD_WARNING_CONFIG_FAILED;
6688
6689 if (peer->conf_if)
6690 return CMD_WARNING;
6691
6692 if (source_str) {
6693 if (str2sockunion(source_str, &su) == 0)
6694 peer_update_source_addr_set(peer, &su);
6695 else {
6696 if (str2prefix(source_str, &p)) {
6697 vty_out(vty,
6698 "%% Invalid update-source, remove prefix length \n");
6699 return CMD_WARNING_CONFIG_FAILED;
6700 } else
6701 peer_update_source_if_set(peer, source_str);
6702 }
6703 } else
6704 peer_update_source_unset(peer);
6705
6706 return CMD_SUCCESS;
6707 }
6708
6709 #define BGP_UPDATE_SOURCE_HELP_STR \
6710 "IPv4 address\n" \
6711 "IPv6 address\n" \
6712 "Interface name (requires zebra to be running)\n"
6713
6714 DEFUN (neighbor_update_source,
6715 neighbor_update_source_cmd,
6716 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6717 NEIGHBOR_STR
6718 NEIGHBOR_ADDR_STR2
6719 "Source of routing updates\n"
6720 BGP_UPDATE_SOURCE_HELP_STR)
6721 {
6722 int idx_peer = 1;
6723 int idx_peer_2 = 3;
6724 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6725 argv[idx_peer_2]->arg);
6726 }
6727
6728 DEFUN (no_neighbor_update_source,
6729 no_neighbor_update_source_cmd,
6730 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6731 NO_STR
6732 NEIGHBOR_STR
6733 NEIGHBOR_ADDR_STR2
6734 "Source of routing updates\n"
6735 BGP_UPDATE_SOURCE_HELP_STR)
6736 {
6737 int idx_peer = 2;
6738 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
6739 }
6740
6741 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6742 afi_t afi, safi_t safi,
6743 const char *rmap, int set)
6744 {
6745 int ret;
6746 struct peer *peer;
6747 struct route_map *route_map = NULL;
6748
6749 peer = peer_and_group_lookup_vty(vty, peer_str);
6750 if (!peer)
6751 return CMD_WARNING_CONFIG_FAILED;
6752
6753 if (set) {
6754 if (rmap)
6755 route_map = route_map_lookup_warn_noexist(vty, rmap);
6756 ret = peer_default_originate_set(peer, afi, safi,
6757 rmap, route_map);
6758 } else
6759 ret = peer_default_originate_unset(peer, afi, safi);
6760
6761 return bgp_vty_return(vty, ret);
6762 }
6763
6764 /* neighbor default-originate. */
6765 DEFUN (neighbor_default_originate,
6766 neighbor_default_originate_cmd,
6767 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6768 NEIGHBOR_STR
6769 NEIGHBOR_ADDR_STR2
6770 "Originate default route to this neighbor\n")
6771 {
6772 int idx_peer = 1;
6773 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6774 bgp_node_afi(vty),
6775 bgp_node_safi(vty), NULL, 1);
6776 }
6777
6778 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6779 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6780 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6781 "Originate default route to this neighbor\n")
6782
6783 DEFUN (neighbor_default_originate_rmap,
6784 neighbor_default_originate_rmap_cmd,
6785 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6786 NEIGHBOR_STR
6787 NEIGHBOR_ADDR_STR2
6788 "Originate default route to this neighbor\n"
6789 "Route-map to specify criteria to originate default\n"
6790 "route-map name\n")
6791 {
6792 int idx_peer = 1;
6793 int idx_word = 4;
6794 return peer_default_originate_set_vty(
6795 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6796 argv[idx_word]->arg, 1);
6797 }
6798
6799 ALIAS_HIDDEN(
6800 neighbor_default_originate_rmap,
6801 neighbor_default_originate_rmap_hidden_cmd,
6802 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
6803 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6804 "Originate default route to this neighbor\n"
6805 "Route-map to specify criteria to originate default\n"
6806 "route-map name\n")
6807
6808 DEFUN (no_neighbor_default_originate,
6809 no_neighbor_default_originate_cmd,
6810 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6811 NO_STR
6812 NEIGHBOR_STR
6813 NEIGHBOR_ADDR_STR2
6814 "Originate default route to this neighbor\n"
6815 "Route-map to specify criteria to originate default\n"
6816 "route-map name\n")
6817 {
6818 int idx_peer = 2;
6819 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6820 bgp_node_afi(vty),
6821 bgp_node_safi(vty), NULL, 0);
6822 }
6823
6824 ALIAS_HIDDEN(
6825 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6826 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
6827 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6828 "Originate default route to this neighbor\n"
6829 "Route-map to specify criteria to originate default\n"
6830 "route-map name\n")
6831
6832
6833 /* Set neighbor's BGP port. */
6834 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6835 const char *port_str)
6836 {
6837 struct peer *peer;
6838 uint16_t port;
6839 struct servent *sp;
6840
6841 peer = peer_lookup_vty(vty, ip_str);
6842 if (!peer)
6843 return CMD_WARNING_CONFIG_FAILED;
6844
6845 if (!port_str) {
6846 sp = getservbyname("bgp", "tcp");
6847 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6848 } else {
6849 port = strtoul(port_str, NULL, 10);
6850 }
6851
6852 peer_port_set(peer, port);
6853
6854 return CMD_SUCCESS;
6855 }
6856
6857 /* Set specified peer's BGP port. */
6858 DEFUN (neighbor_port,
6859 neighbor_port_cmd,
6860 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6861 NEIGHBOR_STR
6862 NEIGHBOR_ADDR_STR
6863 "Neighbor's BGP port\n"
6864 "TCP port number\n")
6865 {
6866 int idx_ip = 1;
6867 int idx_number = 3;
6868 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6869 argv[idx_number]->arg);
6870 }
6871
6872 DEFUN (no_neighbor_port,
6873 no_neighbor_port_cmd,
6874 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6875 NO_STR
6876 NEIGHBOR_STR
6877 NEIGHBOR_ADDR_STR
6878 "Neighbor's BGP port\n"
6879 "TCP port number\n")
6880 {
6881 int idx_ip = 2;
6882 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6883 }
6884
6885
6886 /* neighbor weight. */
6887 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6888 safi_t safi, const char *weight_str)
6889 {
6890 int ret;
6891 struct peer *peer;
6892 unsigned long weight;
6893
6894 peer = peer_and_group_lookup_vty(vty, ip_str);
6895 if (!peer)
6896 return CMD_WARNING_CONFIG_FAILED;
6897
6898 weight = strtoul(weight_str, NULL, 10);
6899
6900 ret = peer_weight_set(peer, afi, safi, weight);
6901 return bgp_vty_return(vty, ret);
6902 }
6903
6904 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6905 safi_t safi)
6906 {
6907 int ret;
6908 struct peer *peer;
6909
6910 peer = peer_and_group_lookup_vty(vty, ip_str);
6911 if (!peer)
6912 return CMD_WARNING_CONFIG_FAILED;
6913
6914 ret = peer_weight_unset(peer, afi, safi);
6915 return bgp_vty_return(vty, ret);
6916 }
6917
6918 DEFUN (neighbor_weight,
6919 neighbor_weight_cmd,
6920 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6921 NEIGHBOR_STR
6922 NEIGHBOR_ADDR_STR2
6923 "Set default weight for routes from this neighbor\n"
6924 "default weight\n")
6925 {
6926 int idx_peer = 1;
6927 int idx_number = 3;
6928 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6929 bgp_node_safi(vty), argv[idx_number]->arg);
6930 }
6931
6932 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6933 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6935 "Set default weight for routes from this neighbor\n"
6936 "default weight\n")
6937
6938 DEFUN (no_neighbor_weight,
6939 no_neighbor_weight_cmd,
6940 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6941 NO_STR
6942 NEIGHBOR_STR
6943 NEIGHBOR_ADDR_STR2
6944 "Set default weight for routes from this neighbor\n"
6945 "default weight\n")
6946 {
6947 int idx_peer = 2;
6948 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6949 bgp_node_afi(vty), bgp_node_safi(vty));
6950 }
6951
6952 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6953 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6954 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6955 "Set default weight for routes from this neighbor\n"
6956 "default weight\n")
6957
6958
6959 /* Override capability negotiation. */
6960 DEFUN (neighbor_override_capability,
6961 neighbor_override_capability_cmd,
6962 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6963 NEIGHBOR_STR
6964 NEIGHBOR_ADDR_STR2
6965 "Override capability negotiation result\n")
6966 {
6967 int idx_peer = 1;
6968 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6969 PEER_FLAG_OVERRIDE_CAPABILITY);
6970 }
6971
6972 DEFUN (no_neighbor_override_capability,
6973 no_neighbor_override_capability_cmd,
6974 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6975 NO_STR
6976 NEIGHBOR_STR
6977 NEIGHBOR_ADDR_STR2
6978 "Override capability negotiation result\n")
6979 {
6980 int idx_peer = 2;
6981 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6982 PEER_FLAG_OVERRIDE_CAPABILITY);
6983 }
6984
6985 DEFUN (neighbor_strict_capability,
6986 neighbor_strict_capability_cmd,
6987 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6988 NEIGHBOR_STR
6989 NEIGHBOR_ADDR_STR2
6990 "Strict capability negotiation match\n")
6991 {
6992 int idx_peer = 1;
6993
6994 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6995 PEER_FLAG_STRICT_CAP_MATCH);
6996 }
6997
6998 DEFUN (no_neighbor_strict_capability,
6999 no_neighbor_strict_capability_cmd,
7000 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7001 NO_STR
7002 NEIGHBOR_STR
7003 NEIGHBOR_ADDR_STR2
7004 "Strict capability negotiation match\n")
7005 {
7006 int idx_peer = 2;
7007
7008 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7009 PEER_FLAG_STRICT_CAP_MATCH);
7010 }
7011
7012 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7013 const char *keep_str, const char *hold_str)
7014 {
7015 int ret;
7016 struct peer *peer;
7017 uint32_t keepalive;
7018 uint32_t holdtime;
7019
7020 peer = peer_and_group_lookup_vty(vty, ip_str);
7021 if (!peer)
7022 return CMD_WARNING_CONFIG_FAILED;
7023
7024 keepalive = strtoul(keep_str, NULL, 10);
7025 holdtime = strtoul(hold_str, NULL, 10);
7026
7027 ret = peer_timers_set(peer, keepalive, holdtime);
7028
7029 return bgp_vty_return(vty, ret);
7030 }
7031
7032 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
7033 {
7034 int ret;
7035 struct peer *peer;
7036
7037 peer = peer_and_group_lookup_vty(vty, ip_str);
7038 if (!peer)
7039 return CMD_WARNING_CONFIG_FAILED;
7040
7041 ret = peer_timers_unset(peer);
7042
7043 return bgp_vty_return(vty, ret);
7044 }
7045
7046 DEFUN (neighbor_timers,
7047 neighbor_timers_cmd,
7048 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7049 NEIGHBOR_STR
7050 NEIGHBOR_ADDR_STR2
7051 "BGP per neighbor timers\n"
7052 "Keepalive interval\n"
7053 "Holdtime\n")
7054 {
7055 int idx_peer = 1;
7056 int idx_number = 3;
7057 int idx_number_2 = 4;
7058 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7059 argv[idx_number]->arg,
7060 argv[idx_number_2]->arg);
7061 }
7062
7063 DEFUN (no_neighbor_timers,
7064 no_neighbor_timers_cmd,
7065 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7066 NO_STR
7067 NEIGHBOR_STR
7068 NEIGHBOR_ADDR_STR2
7069 "BGP per neighbor timers\n"
7070 "Keepalive interval\n"
7071 "Holdtime\n")
7072 {
7073 int idx_peer = 2;
7074 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7075 }
7076
7077
7078 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7079 const char *time_str)
7080 {
7081 int ret;
7082 struct peer *peer;
7083 uint32_t connect;
7084
7085 peer = peer_and_group_lookup_vty(vty, ip_str);
7086 if (!peer)
7087 return CMD_WARNING_CONFIG_FAILED;
7088
7089 connect = strtoul(time_str, NULL, 10);
7090
7091 ret = peer_timers_connect_set(peer, connect);
7092
7093 return bgp_vty_return(vty, ret);
7094 }
7095
7096 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
7097 {
7098 int ret;
7099 struct peer *peer;
7100
7101 peer = peer_and_group_lookup_vty(vty, ip_str);
7102 if (!peer)
7103 return CMD_WARNING_CONFIG_FAILED;
7104
7105 ret = peer_timers_connect_unset(peer);
7106
7107 return bgp_vty_return(vty, ret);
7108 }
7109
7110 DEFUN (neighbor_timers_connect,
7111 neighbor_timers_connect_cmd,
7112 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7113 NEIGHBOR_STR
7114 NEIGHBOR_ADDR_STR2
7115 "BGP per neighbor timers\n"
7116 "BGP connect timer\n"
7117 "Connect timer\n")
7118 {
7119 int idx_peer = 1;
7120 int idx_number = 4;
7121 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7122 argv[idx_number]->arg);
7123 }
7124
7125 DEFUN (no_neighbor_timers_connect,
7126 no_neighbor_timers_connect_cmd,
7127 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7128 NO_STR
7129 NEIGHBOR_STR
7130 NEIGHBOR_ADDR_STR2
7131 "BGP per neighbor timers\n"
7132 "BGP connect timer\n"
7133 "Connect timer\n")
7134 {
7135 int idx_peer = 2;
7136 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
7137 }
7138
7139 DEFPY (neighbor_timers_delayopen,
7140 neighbor_timers_delayopen_cmd,
7141 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7142 NEIGHBOR_STR
7143 NEIGHBOR_ADDR_STR2
7144 "BGP per neighbor timers\n"
7145 "RFC 4271 DelayOpenTimer\n"
7146 "DelayOpenTime timer interval\n")
7147 {
7148 struct peer *peer;
7149
7150 peer = peer_and_group_lookup_vty(vty, neighbor);
7151 if (!peer)
7152 return CMD_WARNING_CONFIG_FAILED;
7153
7154 if (!interval) {
7155 if (peer_timers_delayopen_unset(peer))
7156 return CMD_WARNING_CONFIG_FAILED;
7157 } else {
7158 if (peer_timers_delayopen_set(peer, interval))
7159 return CMD_WARNING_CONFIG_FAILED;
7160 }
7161
7162 return CMD_SUCCESS;
7163 }
7164
7165 DEFPY (no_neighbor_timers_delayopen,
7166 no_neighbor_timers_delayopen_cmd,
7167 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7168 NO_STR
7169 NEIGHBOR_STR
7170 NEIGHBOR_ADDR_STR2
7171 "BGP per neighbor timers\n"
7172 "RFC 4271 DelayOpenTimer\n"
7173 "DelayOpenTime timer interval\n")
7174 {
7175 struct peer *peer;
7176
7177 peer = peer_and_group_lookup_vty(vty, neighbor);
7178 if (!peer)
7179 return CMD_WARNING_CONFIG_FAILED;
7180
7181 if (peer_timers_delayopen_unset(peer))
7182 return CMD_WARNING_CONFIG_FAILED;
7183
7184 return CMD_SUCCESS;
7185 }
7186
7187 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7188 const char *time_str, int set)
7189 {
7190 int ret;
7191 struct peer *peer;
7192 uint32_t routeadv = 0;
7193
7194 peer = peer_and_group_lookup_vty(vty, ip_str);
7195 if (!peer)
7196 return CMD_WARNING_CONFIG_FAILED;
7197
7198 if (time_str)
7199 routeadv = strtoul(time_str, NULL, 10);
7200
7201 if (set)
7202 ret = peer_advertise_interval_set(peer, routeadv);
7203 else
7204 ret = peer_advertise_interval_unset(peer);
7205
7206 return bgp_vty_return(vty, ret);
7207 }
7208
7209 DEFUN (neighbor_advertise_interval,
7210 neighbor_advertise_interval_cmd,
7211 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7212 NEIGHBOR_STR
7213 NEIGHBOR_ADDR_STR2
7214 "Minimum interval between sending BGP routing updates\n"
7215 "time in seconds\n")
7216 {
7217 int idx_peer = 1;
7218 int idx_number = 3;
7219 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7220 argv[idx_number]->arg, 1);
7221 }
7222
7223 DEFUN (no_neighbor_advertise_interval,
7224 no_neighbor_advertise_interval_cmd,
7225 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7226 NO_STR
7227 NEIGHBOR_STR
7228 NEIGHBOR_ADDR_STR2
7229 "Minimum interval between sending BGP routing updates\n"
7230 "time in seconds\n")
7231 {
7232 int idx_peer = 2;
7233 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
7234 }
7235
7236
7237 /* Time to wait before processing route-map updates */
7238 DEFUN (bgp_set_route_map_delay_timer,
7239 bgp_set_route_map_delay_timer_cmd,
7240 "bgp route-map delay-timer (0-600)",
7241 SET_STR
7242 "BGP route-map delay timer\n"
7243 "Time in secs to wait before processing route-map changes\n"
7244 "0 disables the timer, no route updates happen when route-maps change\n")
7245 {
7246 int idx_number = 3;
7247 uint32_t rmap_delay_timer;
7248
7249 if (argv[idx_number]->arg) {
7250 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7251 bm->rmap_update_timer = rmap_delay_timer;
7252
7253 /* if the dynamic update handling is being disabled, and a timer
7254 * is
7255 * running, stop the timer and act as if the timer has already
7256 * fired.
7257 */
7258 if (!rmap_delay_timer && bm->t_rmap_update) {
7259 BGP_TIMER_OFF(bm->t_rmap_update);
7260 thread_execute(bm->master, bgp_route_map_update_timer,
7261 NULL, 0);
7262 }
7263 return CMD_SUCCESS;
7264 } else {
7265 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7266 return CMD_WARNING_CONFIG_FAILED;
7267 }
7268 }
7269
7270 DEFUN (no_bgp_set_route_map_delay_timer,
7271 no_bgp_set_route_map_delay_timer_cmd,
7272 "no bgp route-map delay-timer [(0-600)]",
7273 NO_STR
7274 BGP_STR
7275 "Default BGP route-map delay timer\n"
7276 "Reset to default time to wait for processing route-map changes\n"
7277 "0 disables the timer, no route updates happen when route-maps change\n")
7278 {
7279
7280 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7281
7282 return CMD_SUCCESS;
7283 }
7284
7285 /* neighbor interface */
7286 static int peer_interface_vty(struct vty *vty, const char *ip_str,
7287 const char *str)
7288 {
7289 struct peer *peer;
7290
7291 peer = peer_lookup_vty(vty, ip_str);
7292 if (!peer || peer->conf_if) {
7293 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7294 return CMD_WARNING_CONFIG_FAILED;
7295 }
7296
7297 if (str)
7298 peer_interface_set(peer, str);
7299 else
7300 peer_interface_unset(peer);
7301
7302 return CMD_SUCCESS;
7303 }
7304
7305 DEFUN (neighbor_interface,
7306 neighbor_interface_cmd,
7307 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7308 NEIGHBOR_STR
7309 NEIGHBOR_ADDR_STR
7310 "Interface\n"
7311 "Interface name\n")
7312 {
7313 int idx_ip = 1;
7314 int idx_word = 3;
7315
7316 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7317 }
7318
7319 DEFUN (no_neighbor_interface,
7320 no_neighbor_interface_cmd,
7321 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
7322 NO_STR
7323 NEIGHBOR_STR
7324 NEIGHBOR_ADDR_STR
7325 "Interface\n"
7326 "Interface name\n")
7327 {
7328 int idx_peer = 2;
7329
7330 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
7331 }
7332
7333 DEFUN (neighbor_distribute_list,
7334 neighbor_distribute_list_cmd,
7335 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7336 NEIGHBOR_STR
7337 NEIGHBOR_ADDR_STR2
7338 "Filter updates to/from this neighbor\n"
7339 "IP Access-list name\n"
7340 "Filter incoming updates\n"
7341 "Filter outgoing updates\n")
7342 {
7343 int idx_peer = 1;
7344 int idx_acl = 3;
7345 int direct, ret;
7346 struct peer *peer;
7347
7348 const char *pstr = argv[idx_peer]->arg;
7349 const char *acl = argv[idx_acl]->arg;
7350 const char *inout = argv[argc - 1]->text;
7351
7352 peer = peer_and_group_lookup_vty(vty, pstr);
7353 if (!peer)
7354 return CMD_WARNING_CONFIG_FAILED;
7355
7356 /* Check filter direction. */
7357 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7358 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7359 direct, acl);
7360
7361 return bgp_vty_return(vty, ret);
7362 }
7363
7364 ALIAS_HIDDEN(
7365 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7366 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7367 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7368 "Filter updates to/from this neighbor\n"
7369 "IP Access-list name\n"
7370 "Filter incoming updates\n"
7371 "Filter outgoing updates\n")
7372
7373 DEFUN (no_neighbor_distribute_list,
7374 no_neighbor_distribute_list_cmd,
7375 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7376 NO_STR
7377 NEIGHBOR_STR
7378 NEIGHBOR_ADDR_STR2
7379 "Filter updates to/from this neighbor\n"
7380 "IP Access-list name\n"
7381 "Filter incoming updates\n"
7382 "Filter outgoing updates\n")
7383 {
7384 int idx_peer = 2;
7385 int direct, ret;
7386 struct peer *peer;
7387
7388 const char *pstr = argv[idx_peer]->arg;
7389 const char *inout = argv[argc - 1]->text;
7390
7391 peer = peer_and_group_lookup_vty(vty, pstr);
7392 if (!peer)
7393 return CMD_WARNING_CONFIG_FAILED;
7394
7395 /* Check filter direction. */
7396 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7397 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7398 direct);
7399
7400 return bgp_vty_return(vty, ret);
7401 }
7402
7403 ALIAS_HIDDEN(
7404 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7405 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
7406 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7407 "Filter updates to/from this neighbor\n"
7408 "IP Access-list name\n"
7409 "Filter incoming updates\n"
7410 "Filter outgoing updates\n")
7411
7412 /* Set prefix list to the peer. */
7413 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7414 afi_t afi, safi_t safi,
7415 const char *name_str,
7416 const char *direct_str)
7417 {
7418 int ret;
7419 int direct = FILTER_IN;
7420 struct peer *peer;
7421
7422 peer = peer_and_group_lookup_vty(vty, ip_str);
7423 if (!peer)
7424 return CMD_WARNING_CONFIG_FAILED;
7425
7426 /* Check filter direction. */
7427 if (strncmp(direct_str, "i", 1) == 0)
7428 direct = FILTER_IN;
7429 else if (strncmp(direct_str, "o", 1) == 0)
7430 direct = FILTER_OUT;
7431
7432 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
7433
7434 return bgp_vty_return(vty, ret);
7435 }
7436
7437 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7438 afi_t afi, safi_t safi,
7439 const char *direct_str)
7440 {
7441 int ret;
7442 struct peer *peer;
7443 int direct = FILTER_IN;
7444
7445 peer = peer_and_group_lookup_vty(vty, ip_str);
7446 if (!peer)
7447 return CMD_WARNING_CONFIG_FAILED;
7448
7449 /* Check filter direction. */
7450 if (strncmp(direct_str, "i", 1) == 0)
7451 direct = FILTER_IN;
7452 else if (strncmp(direct_str, "o", 1) == 0)
7453 direct = FILTER_OUT;
7454
7455 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7456
7457 return bgp_vty_return(vty, ret);
7458 }
7459
7460 DEFUN (neighbor_prefix_list,
7461 neighbor_prefix_list_cmd,
7462 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7463 NEIGHBOR_STR
7464 NEIGHBOR_ADDR_STR2
7465 "Filter updates to/from this neighbor\n"
7466 "Name of a prefix list\n"
7467 "Filter incoming updates\n"
7468 "Filter outgoing updates\n")
7469 {
7470 int idx_peer = 1;
7471 int idx_word = 3;
7472 int idx_in_out = 4;
7473 return peer_prefix_list_set_vty(
7474 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7475 argv[idx_word]->arg, argv[idx_in_out]->arg);
7476 }
7477
7478 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7479 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7480 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7481 "Filter updates to/from this neighbor\n"
7482 "Name of a prefix list\n"
7483 "Filter incoming updates\n"
7484 "Filter outgoing updates\n")
7485
7486 DEFUN (no_neighbor_prefix_list,
7487 no_neighbor_prefix_list_cmd,
7488 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7489 NO_STR
7490 NEIGHBOR_STR
7491 NEIGHBOR_ADDR_STR2
7492 "Filter updates to/from this neighbor\n"
7493 "Name of a prefix list\n"
7494 "Filter incoming updates\n"
7495 "Filter outgoing updates\n")
7496 {
7497 int idx_peer = 2;
7498 int idx_in_out = 5;
7499 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7500 bgp_node_afi(vty), bgp_node_safi(vty),
7501 argv[idx_in_out]->arg);
7502 }
7503
7504 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7505 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7506 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7507 "Filter updates to/from this neighbor\n"
7508 "Name of a prefix list\n"
7509 "Filter incoming updates\n"
7510 "Filter outgoing updates\n")
7511
7512 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7513 safi_t safi, const char *name_str,
7514 const char *direct_str)
7515 {
7516 int ret;
7517 struct peer *peer;
7518 int direct = FILTER_IN;
7519
7520 peer = peer_and_group_lookup_vty(vty, ip_str);
7521 if (!peer)
7522 return CMD_WARNING_CONFIG_FAILED;
7523
7524 /* Check filter direction. */
7525 if (strncmp(direct_str, "i", 1) == 0)
7526 direct = FILTER_IN;
7527 else if (strncmp(direct_str, "o", 1) == 0)
7528 direct = FILTER_OUT;
7529
7530 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7531
7532 return bgp_vty_return(vty, ret);
7533 }
7534
7535 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7536 safi_t safi, const char *direct_str)
7537 {
7538 int ret;
7539 struct peer *peer;
7540 int direct = FILTER_IN;
7541
7542 peer = peer_and_group_lookup_vty(vty, ip_str);
7543 if (!peer)
7544 return CMD_WARNING_CONFIG_FAILED;
7545
7546 /* Check filter direction. */
7547 if (strncmp(direct_str, "i", 1) == 0)
7548 direct = FILTER_IN;
7549 else if (strncmp(direct_str, "o", 1) == 0)
7550 direct = FILTER_OUT;
7551
7552 ret = peer_aslist_unset(peer, afi, safi, direct);
7553
7554 return bgp_vty_return(vty, ret);
7555 }
7556
7557 DEFUN (neighbor_filter_list,
7558 neighbor_filter_list_cmd,
7559 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7560 NEIGHBOR_STR
7561 NEIGHBOR_ADDR_STR2
7562 "Establish BGP filters\n"
7563 "AS path access-list name\n"
7564 "Filter incoming routes\n"
7565 "Filter outgoing routes\n")
7566 {
7567 int idx_peer = 1;
7568 int idx_word = 3;
7569 int idx_in_out = 4;
7570 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7571 bgp_node_safi(vty), argv[idx_word]->arg,
7572 argv[idx_in_out]->arg);
7573 }
7574
7575 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7576 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7578 "Establish BGP filters\n"
7579 "AS path access-list name\n"
7580 "Filter incoming routes\n"
7581 "Filter outgoing routes\n")
7582
7583 DEFUN (no_neighbor_filter_list,
7584 no_neighbor_filter_list_cmd,
7585 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7586 NO_STR
7587 NEIGHBOR_STR
7588 NEIGHBOR_ADDR_STR2
7589 "Establish BGP filters\n"
7590 "AS path access-list name\n"
7591 "Filter incoming routes\n"
7592 "Filter outgoing routes\n")
7593 {
7594 int idx_peer = 2;
7595 int idx_in_out = 5;
7596 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7597 bgp_node_afi(vty), bgp_node_safi(vty),
7598 argv[idx_in_out]->arg);
7599 }
7600
7601 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7602 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
7603 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7604 "Establish BGP filters\n"
7605 "AS path access-list name\n"
7606 "Filter incoming routes\n"
7607 "Filter outgoing routes\n")
7608
7609 /* Set advertise-map to the peer. */
7610 static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7611 afi_t afi, safi_t safi,
7612 const char *advertise_str,
7613 const char *condition_str, bool condition,
7614 bool set)
7615 {
7616 int ret = CMD_WARNING_CONFIG_FAILED;
7617 struct peer *peer;
7618 struct route_map *advertise_map;
7619 struct route_map *condition_map;
7620
7621 peer = peer_and_group_lookup_vty(vty, ip_str);
7622 if (!peer)
7623 return ret;
7624
7625 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7626 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7627
7628 if (set)
7629 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7630 advertise_map, condition_str,
7631 condition_map, condition);
7632 else
7633 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7634 advertise_map, condition_str,
7635 condition_map, condition);
7636
7637 return bgp_vty_return(vty, ret);
7638 }
7639
7640 DEFPY (bgp_condadv_period,
7641 bgp_condadv_period_cmd,
7642 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7643 NO_STR
7644 BGP_STR
7645 "Conditional advertisement settings\n"
7646 "Set period to rescan BGP table to check if condition is met\n"
7647 "Period between BGP table scans, in seconds; default 60\n")
7648 {
7649 VTY_DECLVAR_CONTEXT(bgp, bgp);
7650
7651 bgp->condition_check_period =
7652 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7653
7654 return CMD_SUCCESS;
7655 }
7656
7657 DEFPY (neighbor_advertise_map,
7658 neighbor_advertise_map_cmd,
7659 "[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",
7660 NO_STR
7661 NEIGHBOR_STR
7662 NEIGHBOR_ADDR_STR2
7663 "Route-map to conditionally advertise routes\n"
7664 "Name of advertise map\n"
7665 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7666 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7667 "Name of the exist or non exist map\n")
7668 {
7669 bool condition = CONDITION_EXIST;
7670
7671 if (!strcmp(exist, "non-exist-map"))
7672 condition = CONDITION_NON_EXIST;
7673
7674 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7675 bgp_node_safi(vty), advertise_str,
7676 condition_str, condition, !no);
7677 }
7678
7679 ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7680 "[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",
7681 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7682 "Route-map to conditionally advertise routes\n"
7683 "Name of advertise map\n"
7684 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7685 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7686 "Name of the exist or non exist map\n")
7687
7688 /* Set route-map to the peer. */
7689 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7690 afi_t afi, safi_t safi, const char *name_str,
7691 const char *direct_str)
7692 {
7693 int ret;
7694 struct peer *peer;
7695 int direct = RMAP_IN;
7696 struct route_map *route_map;
7697
7698 peer = peer_and_group_lookup_vty(vty, ip_str);
7699 if (!peer)
7700 return CMD_WARNING_CONFIG_FAILED;
7701
7702 /* Check filter direction. */
7703 if (strncmp(direct_str, "in", 2) == 0)
7704 direct = RMAP_IN;
7705 else if (strncmp(direct_str, "o", 1) == 0)
7706 direct = RMAP_OUT;
7707
7708 route_map = route_map_lookup_warn_noexist(vty, name_str);
7709 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
7710
7711 return bgp_vty_return(vty, ret);
7712 }
7713
7714 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7715 afi_t afi, safi_t safi,
7716 const char *direct_str)
7717 {
7718 int ret;
7719 struct peer *peer;
7720 int direct = RMAP_IN;
7721
7722 peer = peer_and_group_lookup_vty(vty, ip_str);
7723 if (!peer)
7724 return CMD_WARNING_CONFIG_FAILED;
7725
7726 /* Check filter direction. */
7727 if (strncmp(direct_str, "in", 2) == 0)
7728 direct = RMAP_IN;
7729 else if (strncmp(direct_str, "o", 1) == 0)
7730 direct = RMAP_OUT;
7731
7732 ret = peer_route_map_unset(peer, afi, safi, direct);
7733
7734 return bgp_vty_return(vty, ret);
7735 }
7736
7737 DEFUN (neighbor_route_map,
7738 neighbor_route_map_cmd,
7739 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7740 NEIGHBOR_STR
7741 NEIGHBOR_ADDR_STR2
7742 "Apply route map to neighbor\n"
7743 "Name of route map\n"
7744 "Apply map to incoming routes\n"
7745 "Apply map to outbound routes\n")
7746 {
7747 int idx_peer = 1;
7748 int idx_word = 3;
7749 int idx_in_out = 4;
7750 return peer_route_map_set_vty(
7751 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7752 argv[idx_word]->arg, argv[idx_in_out]->arg);
7753 }
7754
7755 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7756 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7757 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7758 "Apply route map to neighbor\n"
7759 "Name of route map\n"
7760 "Apply map to incoming routes\n"
7761 "Apply map to outbound routes\n")
7762
7763 DEFUN (no_neighbor_route_map,
7764 no_neighbor_route_map_cmd,
7765 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7766 NO_STR
7767 NEIGHBOR_STR
7768 NEIGHBOR_ADDR_STR2
7769 "Apply route map to neighbor\n"
7770 "Name of route map\n"
7771 "Apply map to incoming routes\n"
7772 "Apply map to outbound routes\n")
7773 {
7774 int idx_peer = 2;
7775 int idx_in_out = 5;
7776 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7777 bgp_node_afi(vty), bgp_node_safi(vty),
7778 argv[idx_in_out]->arg);
7779 }
7780
7781 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7782 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
7783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7784 "Apply route map to neighbor\n"
7785 "Name of route map\n"
7786 "Apply map to incoming routes\n"
7787 "Apply map to outbound routes\n")
7788
7789 /* Set unsuppress-map to the peer. */
7790 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7791 afi_t afi, safi_t safi,
7792 const char *name_str)
7793 {
7794 int ret;
7795 struct peer *peer;
7796 struct route_map *route_map;
7797
7798 peer = peer_and_group_lookup_vty(vty, ip_str);
7799 if (!peer)
7800 return CMD_WARNING_CONFIG_FAILED;
7801
7802 route_map = route_map_lookup_warn_noexist(vty, name_str);
7803 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
7804
7805 return bgp_vty_return(vty, ret);
7806 }
7807
7808 /* Unset route-map from the peer. */
7809 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7810 afi_t afi, safi_t safi)
7811 {
7812 int ret;
7813 struct peer *peer;
7814
7815 peer = peer_and_group_lookup_vty(vty, ip_str);
7816 if (!peer)
7817 return CMD_WARNING_CONFIG_FAILED;
7818
7819 ret = peer_unsuppress_map_unset(peer, afi, safi);
7820
7821 return bgp_vty_return(vty, ret);
7822 }
7823
7824 DEFUN (neighbor_unsuppress_map,
7825 neighbor_unsuppress_map_cmd,
7826 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7827 NEIGHBOR_STR
7828 NEIGHBOR_ADDR_STR2
7829 "Route-map to selectively unsuppress suppressed routes\n"
7830 "Name of route map\n")
7831 {
7832 int idx_peer = 1;
7833 int idx_word = 3;
7834 return peer_unsuppress_map_set_vty(
7835 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7836 argv[idx_word]->arg);
7837 }
7838
7839 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7840 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7841 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7842 "Route-map to selectively unsuppress suppressed routes\n"
7843 "Name of route map\n")
7844
7845 DEFUN (no_neighbor_unsuppress_map,
7846 no_neighbor_unsuppress_map_cmd,
7847 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7848 NO_STR
7849 NEIGHBOR_STR
7850 NEIGHBOR_ADDR_STR2
7851 "Route-map to selectively unsuppress suppressed routes\n"
7852 "Name of route map\n")
7853 {
7854 int idx_peer = 2;
7855 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7856 bgp_node_afi(vty),
7857 bgp_node_safi(vty));
7858 }
7859
7860 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7861 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7862 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7863 "Route-map to selectively unsuppress suppressed routes\n"
7864 "Name of route map\n")
7865
7866 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7867 afi_t afi, safi_t safi,
7868 const char *num_str,
7869 const char *threshold_str, int warning,
7870 const char *restart_str,
7871 const char *force_str)
7872 {
7873 int ret;
7874 struct peer *peer;
7875 uint32_t max;
7876 uint8_t threshold;
7877 uint16_t restart;
7878
7879 peer = peer_and_group_lookup_vty(vty, ip_str);
7880 if (!peer)
7881 return CMD_WARNING_CONFIG_FAILED;
7882
7883 max = strtoul(num_str, NULL, 10);
7884 if (threshold_str)
7885 threshold = atoi(threshold_str);
7886 else
7887 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7888
7889 if (restart_str)
7890 restart = atoi(restart_str);
7891 else
7892 restart = 0;
7893
7894 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7895 restart, force_str ? true : false);
7896
7897 return bgp_vty_return(vty, ret);
7898 }
7899
7900 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7901 afi_t afi, safi_t safi)
7902 {
7903 int ret;
7904 struct peer *peer;
7905
7906 peer = peer_and_group_lookup_vty(vty, ip_str);
7907 if (!peer)
7908 return CMD_WARNING_CONFIG_FAILED;
7909
7910 ret = peer_maximum_prefix_unset(peer, afi, safi);
7911
7912 return bgp_vty_return(vty, ret);
7913 }
7914
7915 /* Maximum number of prefix to be sent to the neighbor. */
7916 DEFUN(neighbor_maximum_prefix_out,
7917 neighbor_maximum_prefix_out_cmd,
7918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7919 NEIGHBOR_STR
7920 NEIGHBOR_ADDR_STR2
7921 "Maximum number of prefixes to be sent to this peer\n"
7922 "Maximum no. of prefix limit\n")
7923 {
7924 int ret;
7925 int idx_peer = 1;
7926 int idx_number = 3;
7927 struct peer *peer;
7928 uint32_t max;
7929 afi_t afi = bgp_node_afi(vty);
7930 safi_t safi = bgp_node_safi(vty);
7931
7932 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7933 if (!peer)
7934 return CMD_WARNING_CONFIG_FAILED;
7935
7936 max = strtoul(argv[idx_number]->arg, NULL, 10);
7937
7938 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
7939
7940 return bgp_vty_return(vty, ret);
7941 }
7942
7943 DEFUN(no_neighbor_maximum_prefix_out,
7944 no_neighbor_maximum_prefix_out_cmd,
7945 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
7946 NO_STR
7947 NEIGHBOR_STR
7948 NEIGHBOR_ADDR_STR2
7949 "Maximum number of prefixes to be sent to this peer\n"
7950 "Maximum no. of prefix limit\n")
7951 {
7952 int ret;
7953 int idx_peer = 2;
7954 struct peer *peer;
7955 afi_t afi = bgp_node_afi(vty);
7956 safi_t safi = bgp_node_safi(vty);
7957
7958 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7959 if (!peer)
7960 return CMD_WARNING_CONFIG_FAILED;
7961
7962 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
7963
7964 return bgp_vty_return(vty, ret);
7965 }
7966
7967 /* Maximum number of prefix configuration. Prefix count is different
7968 for each peer configuration. So this configuration can be set for
7969 each peer configuration. */
7970 DEFUN (neighbor_maximum_prefix,
7971 neighbor_maximum_prefix_cmd,
7972 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7973 NEIGHBOR_STR
7974 NEIGHBOR_ADDR_STR2
7975 "Maximum number of prefix accept from this peer\n"
7976 "maximum no. of prefix limit\n"
7977 "Force checking all received routes not only accepted\n")
7978 {
7979 int idx_peer = 1;
7980 int idx_number = 3;
7981 int idx_force = 0;
7982 char *force = NULL;
7983
7984 if (argv_find(argv, argc, "force", &idx_force))
7985 force = argv[idx_force]->arg;
7986
7987 return peer_maximum_prefix_set_vty(
7988 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7989 argv[idx_number]->arg, NULL, 0, NULL, force);
7990 }
7991
7992 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
7993 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7994 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7995 "Maximum number of prefix accept from this peer\n"
7996 "maximum no. of prefix limit\n"
7997 "Force checking all received routes not only accepted\n")
7998
7999 DEFUN (neighbor_maximum_prefix_threshold,
8000 neighbor_maximum_prefix_threshold_cmd,
8001 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8002 NEIGHBOR_STR
8003 NEIGHBOR_ADDR_STR2
8004 "Maximum number of prefix accept from this peer\n"
8005 "maximum no. of prefix limit\n"
8006 "Threshold value (%) at which to generate a warning msg\n"
8007 "Force checking all received routes not only accepted\n")
8008 {
8009 int idx_peer = 1;
8010 int idx_number = 3;
8011 int idx_number_2 = 4;
8012 int idx_force = 0;
8013 char *force = NULL;
8014
8015 if (argv_find(argv, argc, "force", &idx_force))
8016 force = argv[idx_force]->arg;
8017
8018 return peer_maximum_prefix_set_vty(
8019 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8020 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
8021 }
8022
8023 ALIAS_HIDDEN(
8024 neighbor_maximum_prefix_threshold,
8025 neighbor_maximum_prefix_threshold_hidden_cmd,
8026 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8027 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8028 "Maximum number of prefix accept from this peer\n"
8029 "maximum no. of prefix limit\n"
8030 "Threshold value (%) at which to generate a warning msg\n"
8031 "Force checking all received routes not only accepted\n")
8032
8033 DEFUN (neighbor_maximum_prefix_warning,
8034 neighbor_maximum_prefix_warning_cmd,
8035 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8036 NEIGHBOR_STR
8037 NEIGHBOR_ADDR_STR2
8038 "Maximum number of prefix accept from this peer\n"
8039 "maximum no. of prefix limit\n"
8040 "Only give warning message when limit is exceeded\n"
8041 "Force checking all received routes not only accepted\n")
8042 {
8043 int idx_peer = 1;
8044 int idx_number = 3;
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, NULL, 1, NULL, force);
8054 }
8055
8056 ALIAS_HIDDEN(
8057 neighbor_maximum_prefix_warning,
8058 neighbor_maximum_prefix_warning_hidden_cmd,
8059 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8060 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8061 "Maximum number of prefix accept from this peer\n"
8062 "maximum no. of prefix limit\n"
8063 "Only give warning message when limit is exceeded\n"
8064 "Force checking all received routes not only accepted\n")
8065
8066 DEFUN (neighbor_maximum_prefix_threshold_warning,
8067 neighbor_maximum_prefix_threshold_warning_cmd,
8068 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8069 NEIGHBOR_STR
8070 NEIGHBOR_ADDR_STR2
8071 "Maximum number of prefix accept from this peer\n"
8072 "maximum no. of prefix limit\n"
8073 "Threshold value (%) at which to generate a warning msg\n"
8074 "Only give warning message when limit is exceeded\n"
8075 "Force checking all received routes not only accepted\n")
8076 {
8077 int idx_peer = 1;
8078 int idx_number = 3;
8079 int idx_number_2 = 4;
8080 int idx_force = 0;
8081 char *force = NULL;
8082
8083 if (argv_find(argv, argc, "force", &idx_force))
8084 force = argv[idx_force]->arg;
8085
8086 return peer_maximum_prefix_set_vty(
8087 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8088 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
8089 }
8090
8091 ALIAS_HIDDEN(
8092 neighbor_maximum_prefix_threshold_warning,
8093 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8094 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8096 "Maximum number of prefix accept from this peer\n"
8097 "maximum no. of prefix limit\n"
8098 "Threshold value (%) at which to generate a warning msg\n"
8099 "Only give warning message when limit is exceeded\n"
8100 "Force checking all received routes not only accepted\n")
8101
8102 DEFUN (neighbor_maximum_prefix_restart,
8103 neighbor_maximum_prefix_restart_cmd,
8104 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8105 NEIGHBOR_STR
8106 NEIGHBOR_ADDR_STR2
8107 "Maximum number of prefix accept from this peer\n"
8108 "maximum no. of prefix limit\n"
8109 "Restart bgp connection after limit is exceeded\n"
8110 "Restart interval in minutes\n"
8111 "Force checking all received routes not only accepted\n")
8112 {
8113 int idx_peer = 1;
8114 int idx_number = 3;
8115 int idx_number_2 = 5;
8116 int idx_force = 0;
8117 char *force = NULL;
8118
8119 if (argv_find(argv, argc, "force", &idx_force))
8120 force = argv[idx_force]->arg;
8121
8122 return peer_maximum_prefix_set_vty(
8123 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8124 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
8125 }
8126
8127 ALIAS_HIDDEN(
8128 neighbor_maximum_prefix_restart,
8129 neighbor_maximum_prefix_restart_hidden_cmd,
8130 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8132 "Maximum number of prefix accept from this peer\n"
8133 "maximum no. of prefix limit\n"
8134 "Restart bgp connection after limit is exceeded\n"
8135 "Restart interval in minutes\n"
8136 "Force checking all received routes not only accepted\n")
8137
8138 DEFUN (neighbor_maximum_prefix_threshold_restart,
8139 neighbor_maximum_prefix_threshold_restart_cmd,
8140 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8141 NEIGHBOR_STR
8142 NEIGHBOR_ADDR_STR2
8143 "Maximum number of prefixes to accept from this peer\n"
8144 "maximum no. of prefix limit\n"
8145 "Threshold value (%) at which to generate a warning msg\n"
8146 "Restart bgp connection after limit is exceeded\n"
8147 "Restart interval in minutes\n"
8148 "Force checking all received routes not only accepted\n")
8149 {
8150 int idx_peer = 1;
8151 int idx_number = 3;
8152 int idx_number_2 = 4;
8153 int idx_number_3 = 6;
8154 int idx_force = 0;
8155 char *force = NULL;
8156
8157 if (argv_find(argv, argc, "force", &idx_force))
8158 force = argv[idx_force]->arg;
8159
8160 return peer_maximum_prefix_set_vty(
8161 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8162 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8163 argv[idx_number_3]->arg, force);
8164 }
8165
8166 ALIAS_HIDDEN(
8167 neighbor_maximum_prefix_threshold_restart,
8168 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8169 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8170 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8171 "Maximum number of prefixes to accept from this peer\n"
8172 "maximum no. of prefix limit\n"
8173 "Threshold value (%) at which to generate a warning msg\n"
8174 "Restart bgp connection after limit is exceeded\n"
8175 "Restart interval in minutes\n"
8176 "Force checking all received routes not only accepted\n")
8177
8178 DEFUN (no_neighbor_maximum_prefix,
8179 no_neighbor_maximum_prefix_cmd,
8180 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8181 NO_STR
8182 NEIGHBOR_STR
8183 NEIGHBOR_ADDR_STR2
8184 "Maximum number of prefixes to accept from this peer\n"
8185 "maximum no. of prefix limit\n"
8186 "Threshold value (%) at which to generate a warning msg\n"
8187 "Restart bgp connection after limit is exceeded\n"
8188 "Restart interval in minutes\n"
8189 "Only give warning message when limit is exceeded\n"
8190 "Force checking all received routes not only accepted\n")
8191 {
8192 int idx_peer = 2;
8193 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8194 bgp_node_afi(vty),
8195 bgp_node_safi(vty));
8196 }
8197
8198 ALIAS_HIDDEN(
8199 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8200 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8201 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8202 "Maximum number of prefixes to accept from this peer\n"
8203 "maximum no. of prefix limit\n"
8204 "Threshold value (%) at which to generate a warning msg\n"
8205 "Restart bgp connection after limit is exceeded\n"
8206 "Restart interval in minutes\n"
8207 "Only give warning message when limit is exceeded\n"
8208 "Force checking all received routes not only accepted\n")
8209
8210
8211 /* "neighbor allowas-in" */
8212 DEFUN (neighbor_allowas_in,
8213 neighbor_allowas_in_cmd,
8214 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8215 NEIGHBOR_STR
8216 NEIGHBOR_ADDR_STR2
8217 "Accept as-path with my AS present in it\n"
8218 "Number of occurrences of AS number\n"
8219 "Only accept my AS in the as-path if the route was originated in my AS\n")
8220 {
8221 int idx_peer = 1;
8222 int idx_number_origin = 3;
8223 int ret;
8224 int origin = 0;
8225 struct peer *peer;
8226 int allow_num = 0;
8227
8228 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8229 if (!peer)
8230 return CMD_WARNING_CONFIG_FAILED;
8231
8232 if (argc <= idx_number_origin)
8233 allow_num = 3;
8234 else {
8235 if (argv[idx_number_origin]->type == WORD_TKN)
8236 origin = 1;
8237 else
8238 allow_num = atoi(argv[idx_number_origin]->arg);
8239 }
8240
8241 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8242 allow_num, origin);
8243
8244 return bgp_vty_return(vty, ret);
8245 }
8246
8247 ALIAS_HIDDEN(
8248 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8249 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8250 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8251 "Accept as-path with my AS present in it\n"
8252 "Number of occurrences of AS number\n"
8253 "Only accept my AS in the as-path if the route was originated in my AS\n")
8254
8255 DEFUN (no_neighbor_allowas_in,
8256 no_neighbor_allowas_in_cmd,
8257 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8258 NO_STR
8259 NEIGHBOR_STR
8260 NEIGHBOR_ADDR_STR2
8261 "allow local ASN appears in aspath attribute\n"
8262 "Number of occurrences of AS number\n"
8263 "Only accept my AS in the as-path if the route was originated in my AS\n")
8264 {
8265 int idx_peer = 2;
8266 int ret;
8267 struct peer *peer;
8268
8269 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8270 if (!peer)
8271 return CMD_WARNING_CONFIG_FAILED;
8272
8273 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8274 bgp_node_safi(vty));
8275
8276 return bgp_vty_return(vty, ret);
8277 }
8278
8279 ALIAS_HIDDEN(
8280 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8281 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8282 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8283 "allow local ASN appears in aspath attribute\n"
8284 "Number of occurrences of AS number\n"
8285 "Only accept my AS in the as-path if the route was originated in my AS\n")
8286
8287 DEFUN (neighbor_ttl_security,
8288 neighbor_ttl_security_cmd,
8289 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8290 NEIGHBOR_STR
8291 NEIGHBOR_ADDR_STR2
8292 "BGP ttl-security parameters\n"
8293 "Specify the maximum number of hops to the BGP peer\n"
8294 "Number of hops to BGP peer\n")
8295 {
8296 int idx_peer = 1;
8297 int idx_number = 4;
8298 struct peer *peer;
8299 int gtsm_hops;
8300
8301 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8302 if (!peer)
8303 return CMD_WARNING_CONFIG_FAILED;
8304
8305 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8306
8307 /*
8308 * If 'neighbor swpX', then this is for directly connected peers,
8309 * we should not accept a ttl-security hops value greater than 1.
8310 */
8311 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8312 vty_out(vty,
8313 "%s is directly connected peer, hops cannot exceed 1\n",
8314 argv[idx_peer]->arg);
8315 return CMD_WARNING_CONFIG_FAILED;
8316 }
8317
8318 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
8319 }
8320
8321 DEFUN (no_neighbor_ttl_security,
8322 no_neighbor_ttl_security_cmd,
8323 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8324 NO_STR
8325 NEIGHBOR_STR
8326 NEIGHBOR_ADDR_STR2
8327 "BGP ttl-security parameters\n"
8328 "Specify the maximum number of hops to the BGP peer\n"
8329 "Number of hops to BGP peer\n")
8330 {
8331 int idx_peer = 2;
8332 struct peer *peer;
8333
8334 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8335 if (!peer)
8336 return CMD_WARNING_CONFIG_FAILED;
8337
8338 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
8339 }
8340
8341 /* disable-addpath-rx */
8342 DEFUN(neighbor_disable_addpath_rx,
8343 neighbor_disable_addpath_rx_cmd,
8344 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8345 NEIGHBOR_STR
8346 NEIGHBOR_ADDR_STR2
8347 "Do not accept additional paths\n")
8348 {
8349 char *peer_str = argv[1]->arg;
8350 struct peer *peer;
8351 afi_t afi = bgp_node_afi(vty);
8352 safi_t safi = bgp_node_safi(vty);
8353
8354 peer = peer_and_group_lookup_vty(vty, peer_str);
8355 if (!peer)
8356 return CMD_WARNING_CONFIG_FAILED;
8357
8358 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8359 PEER_FLAG_DISABLE_ADDPATH_RX);
8360 }
8361
8362 DEFUN(no_neighbor_disable_addpath_rx,
8363 no_neighbor_disable_addpath_rx_cmd,
8364 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8365 NO_STR
8366 NEIGHBOR_STR
8367 NEIGHBOR_ADDR_STR2
8368 "Do not accept additional paths\n")
8369 {
8370 char *peer_str = argv[2]->arg;
8371 struct peer *peer;
8372 afi_t afi = bgp_node_afi(vty);
8373 safi_t safi = bgp_node_safi(vty);
8374
8375 peer = peer_and_group_lookup_vty(vty, peer_str);
8376 if (!peer)
8377 return CMD_WARNING_CONFIG_FAILED;
8378
8379 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8380 PEER_FLAG_DISABLE_ADDPATH_RX);
8381 }
8382
8383 DEFUN (neighbor_addpath_tx_all_paths,
8384 neighbor_addpath_tx_all_paths_cmd,
8385 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8386 NEIGHBOR_STR
8387 NEIGHBOR_ADDR_STR2
8388 "Use addpath to advertise all paths to a neighbor\n")
8389 {
8390 int idx_peer = 1;
8391 struct peer *peer;
8392
8393 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8394 if (!peer)
8395 return CMD_WARNING_CONFIG_FAILED;
8396
8397 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8398 BGP_ADDPATH_ALL);
8399 return CMD_SUCCESS;
8400 }
8401
8402 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8403 neighbor_addpath_tx_all_paths_hidden_cmd,
8404 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8405 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8406 "Use addpath to advertise all paths to a neighbor\n")
8407
8408 DEFUN (no_neighbor_addpath_tx_all_paths,
8409 no_neighbor_addpath_tx_all_paths_cmd,
8410 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8411 NO_STR
8412 NEIGHBOR_STR
8413 NEIGHBOR_ADDR_STR2
8414 "Use addpath to advertise all paths to a neighbor\n")
8415 {
8416 int idx_peer = 2;
8417 struct peer *peer;
8418
8419 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8420 if (!peer)
8421 return CMD_WARNING_CONFIG_FAILED;
8422
8423 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8424 != BGP_ADDPATH_ALL) {
8425 vty_out(vty,
8426 "%% Peer not currently configured to transmit all paths.");
8427 return CMD_WARNING_CONFIG_FAILED;
8428 }
8429
8430 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8431 BGP_ADDPATH_NONE);
8432
8433 return CMD_SUCCESS;
8434 }
8435
8436 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8437 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8438 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8439 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8440 "Use addpath to advertise all paths to a neighbor\n")
8441
8442 DEFUN (neighbor_addpath_tx_bestpath_per_as,
8443 neighbor_addpath_tx_bestpath_per_as_cmd,
8444 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8445 NEIGHBOR_STR
8446 NEIGHBOR_ADDR_STR2
8447 "Use addpath to advertise the bestpath per each neighboring AS\n")
8448 {
8449 int idx_peer = 1;
8450 struct peer *peer;
8451
8452 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8453 if (!peer)
8454 return CMD_WARNING_CONFIG_FAILED;
8455
8456 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8457 BGP_ADDPATH_BEST_PER_AS);
8458
8459 return CMD_SUCCESS;
8460 }
8461
8462 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8463 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8464 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8465 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8466 "Use addpath to advertise the bestpath per each neighboring AS\n")
8467
8468 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8469 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8470 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8471 NO_STR
8472 NEIGHBOR_STR
8473 NEIGHBOR_ADDR_STR2
8474 "Use addpath to advertise the bestpath per each neighboring AS\n")
8475 {
8476 int idx_peer = 2;
8477 struct peer *peer;
8478
8479 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8480 if (!peer)
8481 return CMD_WARNING_CONFIG_FAILED;
8482
8483 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8484 != BGP_ADDPATH_BEST_PER_AS) {
8485 vty_out(vty,
8486 "%% Peer not currently configured to transmit all best path per as.");
8487 return CMD_WARNING_CONFIG_FAILED;
8488 }
8489
8490 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8491 BGP_ADDPATH_NONE);
8492
8493 return CMD_SUCCESS;
8494 }
8495
8496 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8497 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8498 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8499 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8500 "Use addpath to advertise the bestpath per each neighboring AS\n")
8501
8502 DEFPY(
8503 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8504 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8505 NEIGHBOR_STR
8506 NEIGHBOR_ADDR_STR2
8507 "Detect AS loops before sending to neighbor\n")
8508 {
8509 struct peer *peer;
8510
8511 peer = peer_and_group_lookup_vty(vty, neighbor);
8512 if (!peer)
8513 return CMD_WARNING_CONFIG_FAILED;
8514
8515 peer->as_path_loop_detection = true;
8516
8517 return CMD_SUCCESS;
8518 }
8519
8520 DEFPY(
8521 no_neighbor_aspath_loop_detection,
8522 no_neighbor_aspath_loop_detection_cmd,
8523 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8524 NO_STR
8525 NEIGHBOR_STR
8526 NEIGHBOR_ADDR_STR2
8527 "Detect AS loops before sending to neighbor\n")
8528 {
8529 struct peer *peer;
8530
8531 peer = peer_and_group_lookup_vty(vty, neighbor);
8532 if (!peer)
8533 return CMD_WARNING_CONFIG_FAILED;
8534
8535 peer->as_path_loop_detection = false;
8536
8537 return CMD_SUCCESS;
8538 }
8539
8540 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8541 struct ecommunity **list, bool is_rt6)
8542 {
8543 struct ecommunity *ecom = NULL;
8544 struct ecommunity *ecomadd;
8545
8546 for (; argc; --argc, ++argv) {
8547 if (is_rt6)
8548 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8549 ECOMMUNITY_ROUTE_TARGET,
8550 0);
8551 else
8552 ecomadd = ecommunity_str2com(argv[0]->arg,
8553 ECOMMUNITY_ROUTE_TARGET,
8554 0);
8555 if (!ecomadd) {
8556 vty_out(vty, "Malformed community-list value\n");
8557 if (ecom)
8558 ecommunity_free(&ecom);
8559 return CMD_WARNING_CONFIG_FAILED;
8560 }
8561
8562 if (ecom) {
8563 ecommunity_merge(ecom, ecomadd);
8564 ecommunity_free(&ecomadd);
8565 } else {
8566 ecom = ecomadd;
8567 }
8568 }
8569
8570 if (*list) {
8571 ecommunity_free(&*list);
8572 }
8573 *list = ecom;
8574
8575 return CMD_SUCCESS;
8576 }
8577
8578 /*
8579 * v2vimport is true if we are handling a `import vrf ...` command
8580 */
8581 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8582 {
8583 afi_t afi;
8584
8585 switch (vty->node) {
8586 case BGP_IPV4_NODE:
8587 afi = AFI_IP;
8588 break;
8589 case BGP_IPV6_NODE:
8590 afi = AFI_IP6;
8591 break;
8592 default:
8593 vty_out(vty,
8594 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8595 return AFI_MAX;
8596 }
8597
8598 if (!v2vimport) {
8599 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8600 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8601 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8602 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8603 vty_out(vty,
8604 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8605 return AFI_MAX;
8606 }
8607 } else {
8608 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8609 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8610 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8611 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8612 vty_out(vty,
8613 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8614 return AFI_MAX;
8615 }
8616 }
8617 return afi;
8618 }
8619
8620 DEFPY (af_rd_vpn_export,
8621 af_rd_vpn_export_cmd,
8622 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8623 NO_STR
8624 "Specify route distinguisher\n"
8625 "Between current address-family and vpn\n"
8626 "For routes leaked from current address-family to vpn\n"
8627 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
8628 {
8629 VTY_DECLVAR_CONTEXT(bgp, bgp);
8630 struct prefix_rd prd;
8631 int ret;
8632 afi_t afi;
8633 int idx = 0;
8634 bool yes = true;
8635
8636 if (argv_find(argv, argc, "no", &idx))
8637 yes = false;
8638
8639 if (yes) {
8640 ret = str2prefix_rd(rd_str, &prd);
8641 if (!ret) {
8642 vty_out(vty, "%% Malformed rd\n");
8643 return CMD_WARNING_CONFIG_FAILED;
8644 }
8645 }
8646
8647 afi = vpn_policy_getafi(vty, bgp, false);
8648 if (afi == AFI_MAX)
8649 return CMD_WARNING_CONFIG_FAILED;
8650
8651 /*
8652 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8653 */
8654 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8655 bgp_get_default(), bgp);
8656
8657 if (yes) {
8658 bgp->vpn_policy[afi].tovpn_rd = prd;
8659 SET_FLAG(bgp->vpn_policy[afi].flags,
8660 BGP_VPN_POLICY_TOVPN_RD_SET);
8661 } else {
8662 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8663 BGP_VPN_POLICY_TOVPN_RD_SET);
8664 }
8665
8666 /* post-change: re-export vpn routes */
8667 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8668 bgp_get_default(), bgp);
8669
8670 return CMD_SUCCESS;
8671 }
8672
8673 ALIAS (af_rd_vpn_export,
8674 af_no_rd_vpn_export_cmd,
8675 "no rd vpn export",
8676 NO_STR
8677 "Specify route distinguisher\n"
8678 "Between current address-family and vpn\n"
8679 "For routes leaked from current address-family to vpn\n")
8680
8681 DEFPY (af_label_vpn_export,
8682 af_label_vpn_export_cmd,
8683 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
8684 NO_STR
8685 "label value for VRF\n"
8686 "Between current address-family and vpn\n"
8687 "For routes leaked from current address-family to vpn\n"
8688 "Label Value <0-1048575>\n"
8689 "Automatically assign a label\n")
8690 {
8691 VTY_DECLVAR_CONTEXT(bgp, bgp);
8692 mpls_label_t label = MPLS_LABEL_NONE;
8693 afi_t afi;
8694 int idx = 0;
8695 bool yes = true;
8696
8697 if (argv_find(argv, argc, "no", &idx))
8698 yes = false;
8699
8700 /* If "no ...", squash trailing parameter */
8701 if (!yes)
8702 label_auto = NULL;
8703
8704 if (yes) {
8705 if (!label_auto)
8706 label = label_val; /* parser should force unsigned */
8707 }
8708
8709 afi = vpn_policy_getafi(vty, bgp, false);
8710 if (afi == AFI_MAX)
8711 return CMD_WARNING_CONFIG_FAILED;
8712
8713
8714 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8715 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8716 /* no change */
8717 return CMD_SUCCESS;
8718
8719 /*
8720 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8721 */
8722 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8723 bgp_get_default(), bgp);
8724
8725 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8726 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8727
8728 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8729
8730 /*
8731 * label has previously been automatically
8732 * assigned by labelpool: release it
8733 *
8734 * NB if tovpn_label == MPLS_LABEL_NONE it
8735 * means the automatic assignment is in flight
8736 * and therefore the labelpool callback must
8737 * detect that the auto label is not needed.
8738 */
8739
8740 bgp_lp_release(LP_TYPE_VRF,
8741 &bgp->vpn_policy[afi],
8742 bgp->vpn_policy[afi].tovpn_label);
8743 }
8744 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8745 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8746 }
8747
8748 bgp->vpn_policy[afi].tovpn_label = label;
8749 if (label_auto) {
8750 SET_FLAG(bgp->vpn_policy[afi].flags,
8751 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8752 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8753 vpn_leak_label_callback);
8754 }
8755
8756 /* post-change: re-export vpn routes */
8757 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8758 bgp_get_default(), bgp);
8759
8760 hook_call(bgp_snmp_update_last_changed, bgp);
8761 return CMD_SUCCESS;
8762 }
8763
8764 DEFPY (af_sid_vpn_export,
8765 af_sid_vpn_export_cmd,
8766 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8767 NO_STR
8768 "sid value for VRF\n"
8769 "Between current address-family and vpn\n"
8770 "For routes leaked from current address-family to vpn\n"
8771 "Sid allocation index\n"
8772 "Automatically assign a label\n")
8773 {
8774 VTY_DECLVAR_CONTEXT(bgp, bgp);
8775 afi_t afi;
8776 int debug = 0;
8777 int idx = 0;
8778 bool yes = true;
8779
8780 if (argv_find(argv, argc, "no", &idx))
8781 yes = false;
8782 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8783 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8784
8785 afi = vpn_policy_getafi(vty, bgp, false);
8786 if (afi == AFI_MAX)
8787 return CMD_WARNING_CONFIG_FAILED;
8788
8789 if (!yes) {
8790 /* implement me */
8791 vty_out(vty, "It's not implemented\n");
8792 return CMD_WARNING_CONFIG_FAILED;
8793 }
8794
8795 /* skip when it's already configured */
8796 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8797 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8798 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8799 return CMD_SUCCESS;
8800
8801 /*
8802 * mode change between sid_idx and sid_auto isn't supported.
8803 * user must negate sid vpn export when they want to change the mode
8804 */
8805 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8806 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8807 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8808 vty_out(vty, "it's already configured as %s.\n",
8809 sid_auto ? "auto-mode" : "idx-mode");
8810 return CMD_WARNING_CONFIG_FAILED;
8811 }
8812
8813 /* pre-change */
8814 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8815 bgp_get_default(), bgp);
8816
8817 if (sid_auto) {
8818 /* SID allocation auto-mode */
8819 if (debug)
8820 zlog_debug("%s: auto sid alloc.", __func__);
8821 SET_FLAG(bgp->vpn_policy[afi].flags,
8822 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8823 } else {
8824 /* SID allocation index-mode */
8825 if (debug)
8826 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8827 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8828 }
8829
8830 /* post-change */
8831 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8832 bgp_get_default(), bgp);
8833 return CMD_SUCCESS;
8834 }
8835
8836 ALIAS (af_label_vpn_export,
8837 af_no_label_vpn_export_cmd,
8838 "no label vpn export",
8839 NO_STR
8840 "label value for VRF\n"
8841 "Between current address-family and vpn\n"
8842 "For routes leaked from current address-family to vpn\n")
8843
8844 DEFPY (af_nexthop_vpn_export,
8845 af_nexthop_vpn_export_cmd,
8846 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
8847 NO_STR
8848 "Specify next hop to use for VRF advertised prefixes\n"
8849 "Between current address-family and vpn\n"
8850 "For routes leaked from current address-family to vpn\n"
8851 "IPv4 prefix\n"
8852 "IPv6 prefix\n")
8853 {
8854 VTY_DECLVAR_CONTEXT(bgp, bgp);
8855 afi_t afi;
8856 struct prefix p;
8857
8858 if (!no) {
8859 if (!nexthop_su) {
8860 vty_out(vty, "%% Nexthop required\n");
8861 return CMD_WARNING_CONFIG_FAILED;
8862 }
8863 if (!sockunion2hostprefix(nexthop_su, &p))
8864 return CMD_WARNING_CONFIG_FAILED;
8865 }
8866
8867 afi = vpn_policy_getafi(vty, bgp, false);
8868 if (afi == AFI_MAX)
8869 return CMD_WARNING_CONFIG_FAILED;
8870
8871 /*
8872 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8873 */
8874 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8875 bgp_get_default(), bgp);
8876
8877 if (!no) {
8878 bgp->vpn_policy[afi].tovpn_nexthop = p;
8879 SET_FLAG(bgp->vpn_policy[afi].flags,
8880 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8881 } else {
8882 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8883 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8884 }
8885
8886 /* post-change: re-export vpn routes */
8887 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8888 bgp_get_default(), bgp);
8889
8890 return CMD_SUCCESS;
8891 }
8892
8893 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
8894 {
8895 if (!strcmp(dstr, "import")) {
8896 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8897 } else if (!strcmp(dstr, "export")) {
8898 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8899 } else if (!strcmp(dstr, "both")) {
8900 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8901 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8902 } else {
8903 vty_out(vty, "%% direction parse error\n");
8904 return CMD_WARNING_CONFIG_FAILED;
8905 }
8906 return CMD_SUCCESS;
8907 }
8908
8909 DEFPY (af_rt_vpn_imexport,
8910 af_rt_vpn_imexport_cmd,
8911 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8912 NO_STR
8913 "Specify route target list\n"
8914 "Specify route target list\n"
8915 "Between current address-family and vpn\n"
8916 "For routes leaked from vpn to current address-family: match any\n"
8917 "For routes leaked from current address-family to vpn: set\n"
8918 "both import: match any and export: set\n"
8919 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8920 {
8921 VTY_DECLVAR_CONTEXT(bgp, bgp);
8922 int ret;
8923 struct ecommunity *ecom = NULL;
8924 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8925 enum vpn_policy_direction dir;
8926 afi_t afi;
8927 int idx = 0;
8928 bool yes = true;
8929
8930 if (argv_find(argv, argc, "no", &idx))
8931 yes = false;
8932
8933 afi = vpn_policy_getafi(vty, bgp, false);
8934 if (afi == AFI_MAX)
8935 return CMD_WARNING_CONFIG_FAILED;
8936
8937 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8938 if (ret != CMD_SUCCESS)
8939 return ret;
8940
8941 if (yes) {
8942 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8943 vty_out(vty, "%% Missing RTLIST\n");
8944 return CMD_WARNING_CONFIG_FAILED;
8945 }
8946 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
8947 if (ret != CMD_SUCCESS) {
8948 return ret;
8949 }
8950 }
8951
8952 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8953 if (!dodir[dir])
8954 continue;
8955
8956 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8957
8958 if (yes) {
8959 if (bgp->vpn_policy[afi].rtlist[dir])
8960 ecommunity_free(
8961 &bgp->vpn_policy[afi].rtlist[dir]);
8962 bgp->vpn_policy[afi].rtlist[dir] =
8963 ecommunity_dup(ecom);
8964 } else {
8965 if (bgp->vpn_policy[afi].rtlist[dir])
8966 ecommunity_free(
8967 &bgp->vpn_policy[afi].rtlist[dir]);
8968 bgp->vpn_policy[afi].rtlist[dir] = NULL;
8969 }
8970
8971 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8972 }
8973
8974 if (ecom)
8975 ecommunity_free(&ecom);
8976
8977 return CMD_SUCCESS;
8978 }
8979
8980 ALIAS (af_rt_vpn_imexport,
8981 af_no_rt_vpn_imexport_cmd,
8982 "no <rt|route-target> vpn <import|export|both>$direction_str",
8983 NO_STR
8984 "Specify route target list\n"
8985 "Specify route target list\n"
8986 "Between current address-family and vpn\n"
8987 "For routes leaked from vpn to current address-family\n"
8988 "For routes leaked from current address-family to vpn\n"
8989 "both import and export\n")
8990
8991 DEFPY (af_route_map_vpn_imexport,
8992 af_route_map_vpn_imexport_cmd,
8993 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8994 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8995 NO_STR
8996 "Specify route map\n"
8997 "Between current address-family and vpn\n"
8998 "For routes leaked from vpn to current address-family\n"
8999 "For routes leaked from current address-family to vpn\n"
9000 "name of route-map\n")
9001 {
9002 VTY_DECLVAR_CONTEXT(bgp, bgp);
9003 int ret;
9004 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9005 enum vpn_policy_direction dir;
9006 afi_t afi;
9007 int idx = 0;
9008 bool yes = true;
9009
9010 if (argv_find(argv, argc, "no", &idx))
9011 yes = false;
9012
9013 afi = vpn_policy_getafi(vty, bgp, false);
9014 if (afi == AFI_MAX)
9015 return CMD_WARNING_CONFIG_FAILED;
9016
9017 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9018 if (ret != CMD_SUCCESS)
9019 return ret;
9020
9021 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9022 if (!dodir[dir])
9023 continue;
9024
9025 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9026
9027 if (yes) {
9028 if (bgp->vpn_policy[afi].rmap_name[dir])
9029 XFREE(MTYPE_ROUTE_MAP_NAME,
9030 bgp->vpn_policy[afi].rmap_name[dir]);
9031 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9032 MTYPE_ROUTE_MAP_NAME, rmap_str);
9033 bgp->vpn_policy[afi].rmap[dir] =
9034 route_map_lookup_warn_noexist(vty, rmap_str);
9035 if (!bgp->vpn_policy[afi].rmap[dir])
9036 return CMD_SUCCESS;
9037 } else {
9038 if (bgp->vpn_policy[afi].rmap_name[dir])
9039 XFREE(MTYPE_ROUTE_MAP_NAME,
9040 bgp->vpn_policy[afi].rmap_name[dir]);
9041 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9042 bgp->vpn_policy[afi].rmap[dir] = NULL;
9043 }
9044
9045 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9046 }
9047
9048 return CMD_SUCCESS;
9049 }
9050
9051 ALIAS (af_route_map_vpn_imexport,
9052 af_no_route_map_vpn_imexport_cmd,
9053 "no route-map vpn <import|export>$direction_str",
9054 NO_STR
9055 "Specify route map\n"
9056 "Between current address-family and vpn\n"
9057 "For routes leaked from vpn to current address-family\n"
9058 "For routes leaked from current address-family to vpn\n")
9059
9060 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9061 "import vrf route-map RMAP$rmap_str",
9062 "Import routes from another VRF\n"
9063 "Vrf routes being filtered\n"
9064 "Specify route map\n"
9065 "name of route-map\n")
9066 {
9067 VTY_DECLVAR_CONTEXT(bgp, bgp);
9068 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9069 afi_t afi;
9070 struct bgp *bgp_default;
9071
9072 afi = vpn_policy_getafi(vty, bgp, true);
9073 if (afi == AFI_MAX)
9074 return CMD_WARNING_CONFIG_FAILED;
9075
9076 bgp_default = bgp_get_default();
9077 if (!bgp_default) {
9078 int32_t ret;
9079 as_t as = bgp->as;
9080
9081 /* Auto-create assuming the same AS */
9082 ret = bgp_get_vty(&bgp_default, &as, NULL,
9083 BGP_INSTANCE_TYPE_DEFAULT);
9084
9085 if (ret) {
9086 vty_out(vty,
9087 "VRF default is not configured as a bgp instance\n");
9088 return CMD_WARNING;
9089 }
9090 }
9091
9092 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9093
9094 if (bgp->vpn_policy[afi].rmap_name[dir])
9095 XFREE(MTYPE_ROUTE_MAP_NAME,
9096 bgp->vpn_policy[afi].rmap_name[dir]);
9097 bgp->vpn_policy[afi].rmap_name[dir] =
9098 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9099 bgp->vpn_policy[afi].rmap[dir] =
9100 route_map_lookup_warn_noexist(vty, rmap_str);
9101 if (!bgp->vpn_policy[afi].rmap[dir])
9102 return CMD_SUCCESS;
9103
9104 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9105 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9106
9107 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9108
9109 return CMD_SUCCESS;
9110 }
9111
9112 DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9113 "no import vrf route-map [RMAP$rmap_str]",
9114 NO_STR
9115 "Import routes from another VRF\n"
9116 "Vrf routes being filtered\n"
9117 "Specify route map\n"
9118 "name of route-map\n")
9119 {
9120 VTY_DECLVAR_CONTEXT(bgp, bgp);
9121 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
9122 afi_t afi;
9123
9124 afi = vpn_policy_getafi(vty, bgp, true);
9125 if (afi == AFI_MAX)
9126 return CMD_WARNING_CONFIG_FAILED;
9127
9128 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9129
9130 if (bgp->vpn_policy[afi].rmap_name[dir])
9131 XFREE(MTYPE_ROUTE_MAP_NAME,
9132 bgp->vpn_policy[afi].rmap_name[dir]);
9133 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9134 bgp->vpn_policy[afi].rmap[dir] = NULL;
9135
9136 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9137 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9138 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9139
9140 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9141
9142 return CMD_SUCCESS;
9143 }
9144
9145 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9146 "[no] import vrf VIEWVRFNAME$import_name",
9147 NO_STR
9148 "Import routes from another VRF\n"
9149 "VRF to import from\n"
9150 "The name of the VRF\n")
9151 {
9152 VTY_DECLVAR_CONTEXT(bgp, bgp);
9153 struct listnode *node;
9154 struct bgp *vrf_bgp, *bgp_default;
9155 int32_t ret = 0;
9156 as_t as = bgp->as;
9157 bool remove = false;
9158 int32_t idx = 0;
9159 char *vname;
9160 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
9161 safi_t safi;
9162 afi_t afi;
9163
9164 if (import_name == NULL) {
9165 vty_out(vty, "%% Missing import name\n");
9166 return CMD_WARNING;
9167 }
9168
9169 if (strcmp(import_name, "route-map") == 0) {
9170 vty_out(vty, "%% Must include route-map name\n");
9171 return CMD_WARNING;
9172 }
9173
9174 if (argv_find(argv, argc, "no", &idx))
9175 remove = true;
9176
9177 afi = vpn_policy_getafi(vty, bgp, true);
9178 if (afi == AFI_MAX)
9179 return CMD_WARNING_CONFIG_FAILED;
9180
9181 safi = bgp_node_safi(vty);
9182
9183 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9184 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9185 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9186 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9187 remove ? "unimport" : "import", import_name);
9188 return CMD_WARNING;
9189 }
9190
9191 bgp_default = bgp_get_default();
9192 if (!bgp_default) {
9193 /* Auto-create assuming the same AS */
9194 ret = bgp_get_vty(&bgp_default, &as, NULL,
9195 BGP_INSTANCE_TYPE_DEFAULT);
9196
9197 if (ret) {
9198 vty_out(vty,
9199 "VRF default is not configured as a bgp instance\n");
9200 return CMD_WARNING;
9201 }
9202 }
9203
9204 vrf_bgp = bgp_lookup_by_name(import_name);
9205 if (!vrf_bgp) {
9206 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9207 vrf_bgp = bgp_default;
9208 else
9209 /* Auto-create assuming the same AS */
9210 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9211
9212 if (ret) {
9213 vty_out(vty,
9214 "VRF %s is not configured as a bgp instance\n",
9215 import_name);
9216 return CMD_WARNING;
9217 }
9218 }
9219
9220 if (remove) {
9221 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9222 } else {
9223 /* Already importing from "import_vrf"? */
9224 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9225 vname)) {
9226 if (strcmp(vname, import_name) == 0)
9227 return CMD_WARNING;
9228 }
9229
9230 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9231 }
9232
9233 return CMD_SUCCESS;
9234 }
9235
9236 /* This command is valid only in a bgp vrf instance or the default instance */
9237 DEFPY (bgp_imexport_vpn,
9238 bgp_imexport_vpn_cmd,
9239 "[no] <import|export>$direction_str vpn",
9240 NO_STR
9241 "Import routes to this address-family\n"
9242 "Export routes from this address-family\n"
9243 "to/from default instance VPN RIB\n")
9244 {
9245 VTY_DECLVAR_CONTEXT(bgp, bgp);
9246 int previous_state;
9247 afi_t afi;
9248 safi_t safi;
9249 int idx = 0;
9250 bool yes = true;
9251 int flag;
9252 enum vpn_policy_direction dir;
9253
9254 if (argv_find(argv, argc, "no", &idx))
9255 yes = false;
9256
9257 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9258 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9259
9260 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9261 return CMD_WARNING_CONFIG_FAILED;
9262 }
9263
9264 afi = bgp_node_afi(vty);
9265 safi = bgp_node_safi(vty);
9266 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9267 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9268 return CMD_WARNING_CONFIG_FAILED;
9269 }
9270
9271 if (!strcmp(direction_str, "import")) {
9272 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9273 dir = BGP_VPN_POLICY_DIR_FROMVPN;
9274 } else if (!strcmp(direction_str, "export")) {
9275 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9276 dir = BGP_VPN_POLICY_DIR_TOVPN;
9277 } else {
9278 vty_out(vty, "%% unknown direction %s\n", direction_str);
9279 return CMD_WARNING_CONFIG_FAILED;
9280 }
9281
9282 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
9283
9284 if (yes) {
9285 SET_FLAG(bgp->af_flags[afi][safi], flag);
9286 if (!previous_state) {
9287 /* trigger export current vrf */
9288 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9289 }
9290 } else {
9291 if (previous_state) {
9292 /* trigger un-export current vrf */
9293 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9294 }
9295 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9296 }
9297
9298 hook_call(bgp_snmp_init_stats, bgp);
9299
9300 return CMD_SUCCESS;
9301 }
9302
9303 DEFPY (af_routetarget_import,
9304 af_routetarget_import_cmd,
9305 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9306 NO_STR
9307 "Specify route target list\n"
9308 "Specify route target list\n"
9309 "Specify route target list\n"
9310 "Specify route target list\n"
9311 "Flow-spec redirect type route target\n"
9312 "Import routes to this address-family\n"
9313 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9314 {
9315 VTY_DECLVAR_CONTEXT(bgp, bgp);
9316 int ret;
9317 struct ecommunity *ecom = NULL;
9318 afi_t afi;
9319 int idx = 0, idx_unused = 0;
9320 bool yes = true;
9321 bool rt6 = false;
9322
9323 if (argv_find(argv, argc, "no", &idx))
9324 yes = false;
9325
9326 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9327 argv_find(argv, argc, "route-target6", &idx_unused))
9328 rt6 = true;
9329
9330 afi = vpn_policy_getafi(vty, bgp, false);
9331 if (afi == AFI_MAX)
9332 return CMD_WARNING_CONFIG_FAILED;
9333
9334 if (rt6 && afi != AFI_IP6)
9335 return CMD_WARNING_CONFIG_FAILED;
9336
9337 if (yes) {
9338 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9339 vty_out(vty, "%% Missing RTLIST\n");
9340 return CMD_WARNING_CONFIG_FAILED;
9341 }
9342 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9343 if (ret != CMD_SUCCESS)
9344 return ret;
9345 }
9346
9347 if (yes) {
9348 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9349 ecommunity_free(&bgp->vpn_policy[afi]
9350 .import_redirect_rtlist);
9351 bgp->vpn_policy[afi].import_redirect_rtlist =
9352 ecommunity_dup(ecom);
9353 } else {
9354 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9355 ecommunity_free(&bgp->vpn_policy[afi]
9356 .import_redirect_rtlist);
9357 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9358 }
9359
9360 if (ecom)
9361 ecommunity_free(&ecom);
9362
9363 return CMD_SUCCESS;
9364 }
9365
9366 DEFUN_NOSH (address_family_ipv4_safi,
9367 address_family_ipv4_safi_cmd,
9368 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9369 "Enter Address Family command mode\n"
9370 "Address Family\n"
9371 BGP_SAFI_WITH_LABEL_HELP_STR)
9372 {
9373
9374 if (argc == 3) {
9375 VTY_DECLVAR_CONTEXT(bgp, bgp);
9376 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9377 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9378 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9379 && safi != SAFI_EVPN) {
9380 vty_out(vty,
9381 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9382 return CMD_WARNING_CONFIG_FAILED;
9383 }
9384 vty->node = bgp_node_type(AFI_IP, safi);
9385 } else
9386 vty->node = BGP_IPV4_NODE;
9387
9388 return CMD_SUCCESS;
9389 }
9390
9391 DEFUN_NOSH (address_family_ipv6_safi,
9392 address_family_ipv6_safi_cmd,
9393 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9394 "Enter Address Family command mode\n"
9395 "Address Family\n"
9396 BGP_SAFI_WITH_LABEL_HELP_STR)
9397 {
9398 if (argc == 3) {
9399 VTY_DECLVAR_CONTEXT(bgp, bgp);
9400 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9401 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
9402 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9403 && safi != SAFI_EVPN) {
9404 vty_out(vty,
9405 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9406 return CMD_WARNING_CONFIG_FAILED;
9407 }
9408 vty->node = bgp_node_type(AFI_IP6, safi);
9409 } else
9410 vty->node = BGP_IPV6_NODE;
9411
9412 return CMD_SUCCESS;
9413 }
9414
9415 #ifdef KEEP_OLD_VPN_COMMANDS
9416 DEFUN_NOSH (address_family_vpnv4,
9417 address_family_vpnv4_cmd,
9418 "address-family vpnv4 [unicast]",
9419 "Enter Address Family command mode\n"
9420 "Address Family\n"
9421 "Address Family modifier\n")
9422 {
9423 vty->node = BGP_VPNV4_NODE;
9424 return CMD_SUCCESS;
9425 }
9426
9427 DEFUN_NOSH (address_family_vpnv6,
9428 address_family_vpnv6_cmd,
9429 "address-family vpnv6 [unicast]",
9430 "Enter Address Family command mode\n"
9431 "Address Family\n"
9432 "Address Family modifier\n")
9433 {
9434 vty->node = BGP_VPNV6_NODE;
9435 return CMD_SUCCESS;
9436 }
9437 #endif /* KEEP_OLD_VPN_COMMANDS */
9438
9439 DEFUN_NOSH (address_family_evpn,
9440 address_family_evpn_cmd,
9441 "address-family l2vpn evpn",
9442 "Enter Address Family command mode\n"
9443 "Address Family\n"
9444 "Address Family modifier\n")
9445 {
9446 VTY_DECLVAR_CONTEXT(bgp, bgp);
9447 vty->node = BGP_EVPN_NODE;
9448 return CMD_SUCCESS;
9449 }
9450
9451 DEFUN_NOSH (bgp_segment_routing_srv6,
9452 bgp_segment_routing_srv6_cmd,
9453 "segment-routing srv6",
9454 "Segment-Routing configuration\n"
9455 "Segment-Routing SRv6 configuration\n")
9456 {
9457 VTY_DECLVAR_CONTEXT(bgp, bgp);
9458 bgp->srv6_enabled = true;
9459 vty->node = BGP_SRV6_NODE;
9460 return CMD_SUCCESS;
9461 }
9462
9463 DEFUN (no_bgp_segment_routing_srv6,
9464 no_bgp_segment_routing_srv6_cmd,
9465 "no segment-routing srv6",
9466 NO_STR
9467 "Segment-Routing configuration\n"
9468 "Segment-Routing SRv6 configuration\n")
9469 {
9470 VTY_DECLVAR_CONTEXT(bgp, bgp);
9471
9472 if (strlen(bgp->srv6_locator_name) > 0)
9473 if (bgp_srv6_locator_unset(bgp) < 0)
9474 return CMD_WARNING_CONFIG_FAILED;
9475
9476 bgp->srv6_enabled = false;
9477 return CMD_SUCCESS;
9478 }
9479
9480 DEFPY (bgp_srv6_locator,
9481 bgp_srv6_locator_cmd,
9482 "locator NAME$name",
9483 "Specify SRv6 locator\n"
9484 "Specify SRv6 locator\n")
9485 {
9486 VTY_DECLVAR_CONTEXT(bgp, bgp);
9487 int ret;
9488
9489 if (strlen(bgp->srv6_locator_name) > 0
9490 && strcmp(name, bgp->srv6_locator_name) != 0) {
9491 vty_out(vty, "srv6 locator is already configured\n");
9492 return CMD_WARNING_CONFIG_FAILED;
9493 }
9494
9495 snprintf(bgp->srv6_locator_name,
9496 sizeof(bgp->srv6_locator_name), "%s", name);
9497
9498 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9499 if (ret < 0)
9500 return CMD_WARNING_CONFIG_FAILED;
9501
9502 return CMD_SUCCESS;
9503 }
9504
9505 DEFPY (no_bgp_srv6_locator,
9506 no_bgp_srv6_locator_cmd,
9507 "no locator NAME$name",
9508 NO_STR
9509 "Specify SRv6 locator\n"
9510 "Specify SRv6 locator\n")
9511 {
9512 VTY_DECLVAR_CONTEXT(bgp, bgp);
9513
9514 /* when locator isn't configured, do nothing */
9515 if (strlen(bgp->srv6_locator_name) < 1)
9516 return CMD_SUCCESS;
9517
9518 /* name validation */
9519 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9520 vty_out(vty, "%% No srv6 locator is configured\n");
9521 return CMD_WARNING_CONFIG_FAILED;
9522 }
9523
9524 /* unset locator */
9525 if (bgp_srv6_locator_unset(bgp) < 0)
9526 return CMD_WARNING_CONFIG_FAILED;
9527
9528 return CMD_SUCCESS;
9529 }
9530
9531 DEFPY (show_bgp_srv6,
9532 show_bgp_srv6_cmd,
9533 "show bgp segment-routing srv6",
9534 SHOW_STR
9535 BGP_STR
9536 "BGP Segment Routing\n"
9537 "BGP Segment Routing SRv6\n")
9538 {
9539 struct bgp *bgp;
9540 struct listnode *node;
9541 struct srv6_locator_chunk *chunk;
9542 struct bgp_srv6_function *func;
9543 struct in6_addr *tovpn4_sid;
9544 struct in6_addr *tovpn6_sid;
9545 char buf[256];
9546 char buf_tovpn4_sid[256];
9547 char buf_tovpn6_sid[256];
9548
9549 bgp = bgp_get_default();
9550 if (!bgp)
9551 return CMD_SUCCESS;
9552
9553 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9554 vty_out(vty, "locator_chunks:\n");
9555 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9556 prefix2str(&chunk->prefix, buf, sizeof(buf));
9557 vty_out(vty, "- %s\n", buf);
9558 }
9559
9560 vty_out(vty, "functions:\n");
9561 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9562 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9563 vty_out(vty, "- sid: %s\n", buf);
9564 vty_out(vty, " locator: %s\n", func->locator_name);
9565 }
9566
9567 vty_out(vty, "bgps:\n");
9568 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9569 vty_out(vty, "- name: %s\n",
9570 bgp->name ? bgp->name : "default");
9571
9572 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9573 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9574 if (tovpn4_sid)
9575 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9576 sizeof(buf_tovpn4_sid));
9577 if (tovpn6_sid)
9578 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9579 sizeof(buf_tovpn6_sid));
9580
9581 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9582 tovpn4_sid ? buf_tovpn4_sid : "none");
9583 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9584 tovpn6_sid ? buf_tovpn6_sid : "none");
9585 }
9586
9587 return CMD_SUCCESS;
9588 }
9589
9590 DEFUN_NOSH (exit_address_family,
9591 exit_address_family_cmd,
9592 "exit-address-family",
9593 "Exit from Address Family configuration mode\n")
9594 {
9595 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9596 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9597 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9598 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9599 || vty->node == BGP_EVPN_NODE
9600 || vty->node == BGP_FLOWSPECV4_NODE
9601 || vty->node == BGP_FLOWSPECV6_NODE)
9602 vty->node = BGP_NODE;
9603 return CMD_SUCCESS;
9604 }
9605
9606 /* Recalculate bestpath and re-advertise a prefix */
9607 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9608 const char *ip_str, afi_t afi, safi_t safi,
9609 struct prefix_rd *prd)
9610 {
9611 int ret;
9612 struct prefix match;
9613 struct bgp_dest *dest;
9614 struct bgp_dest *rm;
9615 struct bgp *bgp;
9616 struct bgp_table *table;
9617 struct bgp_table *rib;
9618
9619 /* BGP structure lookup. */
9620 if (view_name) {
9621 bgp = bgp_lookup_by_name(view_name);
9622 if (bgp == NULL) {
9623 vty_out(vty, "%% Can't find BGP instance %s\n",
9624 view_name);
9625 return CMD_WARNING;
9626 }
9627 } else {
9628 bgp = bgp_get_default();
9629 if (bgp == NULL) {
9630 vty_out(vty, "%% No BGP process is configured\n");
9631 return CMD_WARNING;
9632 }
9633 }
9634
9635 /* Check IP address argument. */
9636 ret = str2prefix(ip_str, &match);
9637 if (!ret) {
9638 vty_out(vty, "%% address is malformed\n");
9639 return CMD_WARNING;
9640 }
9641
9642 match.family = afi2family(afi);
9643 rib = bgp->rib[afi][safi];
9644
9645 if (safi == SAFI_MPLS_VPN) {
9646 for (dest = bgp_table_top(rib); dest;
9647 dest = bgp_route_next(dest)) {
9648 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9649
9650 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9651 continue;
9652
9653 table = bgp_dest_get_bgp_table_info(dest);
9654 if (table == NULL)
9655 continue;
9656
9657 rm = bgp_node_match(table, &match);
9658 if (rm != NULL) {
9659 const struct prefix *rm_p =
9660 bgp_dest_get_prefix(rm);
9661
9662 if (rm_p->prefixlen == match.prefixlen) {
9663 SET_FLAG(rm->flags,
9664 BGP_NODE_USER_CLEAR);
9665 bgp_process(bgp, rm, afi, safi);
9666 }
9667 bgp_dest_unlock_node(rm);
9668 }
9669 }
9670 } else {
9671 dest = bgp_node_match(rib, &match);
9672 if (dest != NULL) {
9673 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9674
9675 if (dest_p->prefixlen == match.prefixlen) {
9676 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9677 bgp_process(bgp, dest, afi, safi);
9678 }
9679 bgp_dest_unlock_node(dest);
9680 }
9681 }
9682
9683 return CMD_SUCCESS;
9684 }
9685
9686 /* one clear bgp command to rule them all */
9687 DEFUN (clear_ip_bgp_all,
9688 clear_ip_bgp_all_cmd,
9689 "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>]",
9690 CLEAR_STR
9691 IP_STR
9692 BGP_STR
9693 BGP_INSTANCE_HELP_STR
9694 BGP_AFI_HELP_STR
9695 "Address Family\n"
9696 BGP_SAFI_WITH_LABEL_HELP_STR
9697 "Address Family modifier\n"
9698 "Clear all peers\n"
9699 "BGP IPv4 neighbor to clear\n"
9700 "BGP IPv6 neighbor to clear\n"
9701 "BGP neighbor on interface to clear\n"
9702 "Clear peers with the AS number\n"
9703 "Clear all external peers\n"
9704 "Clear all members of peer-group\n"
9705 "BGP peer-group name\n"
9706 BGP_SOFT_STR
9707 BGP_SOFT_IN_STR
9708 BGP_SOFT_OUT_STR
9709 BGP_SOFT_IN_STR
9710 "Push out prefix-list ORF and do inbound soft reconfig\n"
9711 BGP_SOFT_OUT_STR
9712 "Reset message statistics\n")
9713 {
9714 char *vrf = NULL;
9715
9716 afi_t afi = AFI_UNSPEC;
9717 safi_t safi = SAFI_UNSPEC;
9718 enum clear_sort clr_sort = clear_peer;
9719 enum bgp_clear_type clr_type;
9720 char *clr_arg = NULL;
9721
9722 int idx = 0;
9723
9724 /* clear [ip] bgp */
9725 if (argv_find(argv, argc, "ip", &idx))
9726 afi = AFI_IP;
9727
9728 /* [<vrf> VIEWVRFNAME] */
9729 if (argv_find(argv, argc, "vrf", &idx)) {
9730 vrf = argv[idx + 1]->arg;
9731 idx += 2;
9732 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9733 vrf = NULL;
9734 } else if (argv_find(argv, argc, "view", &idx)) {
9735 /* [<view> VIEWVRFNAME] */
9736 vrf = argv[idx + 1]->arg;
9737 idx += 2;
9738 }
9739 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9740 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9741 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9742
9743 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9744 if (argv_find(argv, argc, "*", &idx)) {
9745 clr_sort = clear_all;
9746 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9747 clr_sort = clear_peer;
9748 clr_arg = argv[idx]->arg;
9749 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9750 clr_sort = clear_peer;
9751 clr_arg = argv[idx]->arg;
9752 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9753 clr_sort = clear_group;
9754 idx++;
9755 clr_arg = argv[idx]->arg;
9756 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9757 clr_sort = clear_peer;
9758 clr_arg = argv[idx]->arg;
9759 } else if (argv_find(argv, argc, "WORD", &idx)) {
9760 clr_sort = clear_peer;
9761 clr_arg = argv[idx]->arg;
9762 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9763 clr_sort = clear_as;
9764 clr_arg = argv[idx]->arg;
9765 } else if (argv_find(argv, argc, "external", &idx)) {
9766 clr_sort = clear_external;
9767 }
9768
9769 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
9770 if (argv_find(argv, argc, "soft", &idx)) {
9771 if (argv_find(argv, argc, "in", &idx)
9772 || argv_find(argv, argc, "out", &idx))
9773 clr_type = strmatch(argv[idx]->text, "in")
9774 ? BGP_CLEAR_SOFT_IN
9775 : BGP_CLEAR_SOFT_OUT;
9776 else
9777 clr_type = BGP_CLEAR_SOFT_BOTH;
9778 } else if (argv_find(argv, argc, "in", &idx)) {
9779 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9780 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9781 : BGP_CLEAR_SOFT_IN;
9782 } else if (argv_find(argv, argc, "out", &idx)) {
9783 clr_type = BGP_CLEAR_SOFT_OUT;
9784 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9785 clr_type = BGP_CLEAR_MESSAGE_STATS;
9786 } else
9787 clr_type = BGP_CLEAR_SOFT_NONE;
9788
9789 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
9790 }
9791
9792 DEFUN (clear_ip_bgp_prefix,
9793 clear_ip_bgp_prefix_cmd,
9794 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9795 CLEAR_STR
9796 IP_STR
9797 BGP_STR
9798 BGP_INSTANCE_HELP_STR
9799 "Clear bestpath and re-advertise\n"
9800 "IPv4 prefix\n")
9801 {
9802 char *vrf = NULL;
9803 char *prefix = NULL;
9804
9805 int idx = 0;
9806
9807 /* [<view|vrf> VIEWVRFNAME] */
9808 if (argv_find(argv, argc, "vrf", &idx)) {
9809 vrf = argv[idx + 1]->arg;
9810 idx += 2;
9811 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9812 vrf = NULL;
9813 } else if (argv_find(argv, argc, "view", &idx)) {
9814 /* [<view> VIEWVRFNAME] */
9815 vrf = argv[idx + 1]->arg;
9816 idx += 2;
9817 }
9818
9819 prefix = argv[argc - 1]->arg;
9820
9821 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
9822 }
9823
9824 DEFUN (clear_bgp_ipv6_safi_prefix,
9825 clear_bgp_ipv6_safi_prefix_cmd,
9826 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9827 CLEAR_STR
9828 IP_STR
9829 BGP_STR
9830 "Address Family\n"
9831 BGP_SAFI_HELP_STR
9832 "Clear bestpath and re-advertise\n"
9833 "IPv6 prefix\n")
9834 {
9835 int idx_safi = 0;
9836 int idx_ipv6_prefix = 0;
9837 safi_t safi = SAFI_UNICAST;
9838 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9839 argv[idx_ipv6_prefix]->arg : NULL;
9840
9841 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9842 return bgp_clear_prefix(
9843 vty, NULL, prefix, AFI_IP6,
9844 safi, NULL);
9845 }
9846
9847 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9848 clear_bgp_instance_ipv6_safi_prefix_cmd,
9849 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
9850 CLEAR_STR
9851 IP_STR
9852 BGP_STR
9853 BGP_INSTANCE_HELP_STR
9854 "Address Family\n"
9855 BGP_SAFI_HELP_STR
9856 "Clear bestpath and re-advertise\n"
9857 "IPv6 prefix\n")
9858 {
9859 int idx_safi = 0;
9860 int idx_vrfview = 0;
9861 int idx_ipv6_prefix = 0;
9862 safi_t safi = SAFI_UNICAST;
9863 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9864 argv[idx_ipv6_prefix]->arg : NULL;
9865 char *vrfview = NULL;
9866
9867 /* [<view|vrf> VIEWVRFNAME] */
9868 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9869 vrfview = argv[idx_vrfview + 1]->arg;
9870 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9871 vrfview = NULL;
9872 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9873 /* [<view> VIEWVRFNAME] */
9874 vrfview = argv[idx_vrfview + 1]->arg;
9875 }
9876 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9877
9878 return bgp_clear_prefix(
9879 vty, vrfview, prefix,
9880 AFI_IP6, safi, NULL);
9881 }
9882
9883 DEFUN (show_bgp_views,
9884 show_bgp_views_cmd,
9885 "show [ip] bgp views",
9886 SHOW_STR
9887 IP_STR
9888 BGP_STR
9889 "Show the defined BGP views\n")
9890 {
9891 struct list *inst = bm->bgp;
9892 struct listnode *node;
9893 struct bgp *bgp;
9894
9895 vty_out(vty, "Defined BGP views:\n");
9896 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9897 /* Skip VRFs. */
9898 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9899 continue;
9900 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9901 bgp->as);
9902 }
9903
9904 return CMD_SUCCESS;
9905 }
9906
9907 DEFUN (show_bgp_vrfs,
9908 show_bgp_vrfs_cmd,
9909 "show [ip] bgp vrfs [json]",
9910 SHOW_STR
9911 IP_STR
9912 BGP_STR
9913 "Show BGP VRFs\n"
9914 JSON_STR)
9915 {
9916 char buf[ETHER_ADDR_STRLEN];
9917 struct list *inst = bm->bgp;
9918 struct listnode *node;
9919 struct bgp *bgp;
9920 bool uj = use_json(argc, argv);
9921 json_object *json = NULL;
9922 json_object *json_vrfs = NULL;
9923 int count = 0;
9924
9925 if (uj) {
9926 json = json_object_new_object();
9927 json_vrfs = json_object_new_object();
9928 }
9929
9930 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9931 const char *name, *type;
9932 struct peer *peer;
9933 struct listnode *node2, *nnode2;
9934 int peers_cfg, peers_estb;
9935 json_object *json_vrf = NULL;
9936
9937 /* Skip Views. */
9938 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9939 continue;
9940
9941 count++;
9942 if (!uj && count == 1) {
9943 vty_out(vty,
9944 "%4s %-5s %-16s %9s %10s %-37s\n",
9945 "Type", "Id", "routerId", "#PeersCfg",
9946 "#PeersEstb", "Name");
9947 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9948 "L3-VNI", "RouterMAC", "Interface");
9949 }
9950
9951 peers_cfg = peers_estb = 0;
9952 if (uj)
9953 json_vrf = json_object_new_object();
9954
9955
9956 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
9957 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9958 continue;
9959 peers_cfg++;
9960 if (peer_established(peer))
9961 peers_estb++;
9962 }
9963
9964 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
9965 name = VRF_DEFAULT_NAME;
9966 type = "DFLT";
9967 } else {
9968 name = bgp->name;
9969 type = "VRF";
9970 }
9971
9972
9973 if (uj) {
9974 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9975 ? -1
9976 : (int64_t)bgp->vrf_id;
9977 char buf[BUFSIZ] = {0};
9978
9979 json_object_string_add(json_vrf, "type", type);
9980 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9981 json_object_string_addf(json_vrf, "routerId", "%pI4",
9982 &bgp->router_id);
9983 json_object_int_add(json_vrf, "numConfiguredPeers",
9984 peers_cfg);
9985 json_object_int_add(json_vrf, "numEstablishedPeers",
9986 peers_estb);
9987
9988 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
9989 json_object_string_add(
9990 json_vrf, "rmac",
9991 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
9992 json_object_string_add(json_vrf, "interface",
9993 ifindex2ifname(bgp->l3vni_svi_ifindex,
9994 bgp->vrf_id));
9995 json_object_object_add(json_vrfs, name, json_vrf);
9996 } else {
9997 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
9998 type,
9999 bgp->vrf_id == VRF_UNKNOWN ? -1
10000 : (int)bgp->vrf_id,
10001 &bgp->router_id, peers_cfg, peers_estb, name);
10002 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10003 bgp->l3vni,
10004 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10005 ifindex2ifname(bgp->l3vni_svi_ifindex,
10006 bgp->vrf_id));
10007 }
10008 }
10009
10010 if (uj) {
10011 json_object_object_add(json, "vrfs", json_vrfs);
10012
10013 json_object_int_add(json, "totalVrfs", count);
10014
10015 vty_json(vty, json);
10016 } else {
10017 if (count)
10018 vty_out(vty,
10019 "\nTotal number of VRFs (including default): %d\n",
10020 count);
10021 }
10022
10023 return CMD_SUCCESS;
10024 }
10025
10026 DEFUN (show_bgp_mac_hash,
10027 show_bgp_mac_hash_cmd,
10028 "show bgp mac hash",
10029 SHOW_STR
10030 BGP_STR
10031 "Mac Address\n"
10032 "Mac Address database\n")
10033 {
10034 bgp_mac_dump_table(vty);
10035
10036 return CMD_SUCCESS;
10037 }
10038
10039 static void show_tip_entry(struct hash_bucket *bucket, void *args)
10040 {
10041 struct vty *vty = (struct vty *)args;
10042 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10043
10044 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10045 }
10046
10047 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10048 {
10049 vty_out(vty, "self nexthop database:\n");
10050 bgp_nexthop_show_address_hash(vty, bgp);
10051
10052 vty_out(vty, "Tunnel-ip database:\n");
10053 hash_iterate(bgp->tip_hash,
10054 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10055 vty);
10056 }
10057
10058 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10059 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10060 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10061 "martian next-hops\n"
10062 "martian next-hop database\n")
10063 {
10064 struct bgp *bgp = NULL;
10065 int idx = 0;
10066 char *name = NULL;
10067
10068 /* [<vrf> VIEWVRFNAME] */
10069 if (argv_find(argv, argc, "vrf", &idx)) {
10070 name = argv[idx + 1]->arg;
10071 if (name && strmatch(name, VRF_DEFAULT_NAME))
10072 name = NULL;
10073 } else if (argv_find(argv, argc, "view", &idx))
10074 /* [<view> VIEWVRFNAME] */
10075 name = argv[idx + 1]->arg;
10076 if (name)
10077 bgp = bgp_lookup_by_name(name);
10078 else
10079 bgp = bgp_get_default();
10080
10081 if (!bgp) {
10082 vty_out(vty, "%% No BGP process is configured\n");
10083 return CMD_WARNING;
10084 }
10085 bgp_show_martian_nexthops(vty, bgp);
10086
10087 return CMD_SUCCESS;
10088 }
10089
10090 DEFUN (show_bgp_memory,
10091 show_bgp_memory_cmd,
10092 "show [ip] bgp memory",
10093 SHOW_STR
10094 IP_STR
10095 BGP_STR
10096 "Global BGP memory statistics\n")
10097 {
10098 char memstrbuf[MTYPE_MEMSTR_LEN];
10099 unsigned long count;
10100
10101 /* RIB related usage stats */
10102 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10103 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10104 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10105 count * sizeof(struct bgp_dest)));
10106
10107 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10108 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10109 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10110 count * sizeof(struct bgp_path_info)));
10111 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10112 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10113 count,
10114 mtype_memstr(
10115 memstrbuf, sizeof(memstrbuf),
10116 count * sizeof(struct bgp_path_info_extra)));
10117
10118 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10119 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10120 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10121 count * sizeof(struct bgp_static)));
10122
10123 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10124 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10125 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10126 count * sizeof(struct bpacket)));
10127
10128 /* Adj-In/Out */
10129 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10130 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10131 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10132 count * sizeof(struct bgp_adj_in)));
10133 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10134 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10135 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10136 count * sizeof(struct bgp_adj_out)));
10137
10138 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10139 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10140 count,
10141 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10142 count * sizeof(struct bgp_nexthop_cache)));
10143
10144 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10145 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10146 count,
10147 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10148 count * sizeof(struct bgp_damp_info)));
10149
10150 /* Attributes */
10151 count = attr_count();
10152 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10153 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10154 count * sizeof(struct attr)));
10155
10156 if ((count = attr_unknown_count()))
10157 vty_out(vty, "%ld unknown attributes\n", count);
10158
10159 /* AS_PATH attributes */
10160 count = aspath_count();
10161 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10162 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10163 count * sizeof(struct aspath)));
10164
10165 count = mtype_stats_alloc(MTYPE_AS_SEG);
10166 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10167 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10168 count * sizeof(struct assegment)));
10169
10170 /* Other attributes */
10171 if ((count = community_count()))
10172 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10173 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10174 count * sizeof(struct community)));
10175 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10176 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10177 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10178 count * sizeof(struct ecommunity)));
10179 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10180 vty_out(vty,
10181 "%ld BGP large-community entries, using %s of memory\n",
10182 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10183 count * sizeof(struct lcommunity)));
10184
10185 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10186 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10187 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10188 count * sizeof(struct cluster_list)));
10189
10190 /* Peer related usage */
10191 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10192 vty_out(vty, "%ld peers, using %s of memory\n", count,
10193 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10194 count * sizeof(struct peer)));
10195
10196 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10197 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10198 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10199 count * sizeof(struct peer_group)));
10200
10201 /* Other */
10202 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10203 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10204 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10205 count * sizeof(regex_t)));
10206 return CMD_SUCCESS;
10207 }
10208
10209 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10210 {
10211 json_object *bestpath = json_object_new_object();
10212
10213 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10214 json_object_string_add(bestpath, "asPath", "ignore");
10215
10216 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10217 json_object_string_add(bestpath, "asPath", "confed");
10218
10219 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10220 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10221 json_object_string_add(bestpath, "multiPathRelax",
10222 "as-set");
10223 else
10224 json_object_string_add(bestpath, "multiPathRelax",
10225 "true");
10226 } else
10227 json_object_string_add(bestpath, "multiPathRelax", "false");
10228
10229 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10230 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10231
10232 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10233 json_object_string_add(bestpath, "compareRouterId", "true");
10234 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10235 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10236 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10237 json_object_string_add(bestpath, "med", "confed");
10238 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10239 json_object_string_add(bestpath, "med",
10240 "missing-as-worst");
10241 else
10242 json_object_string_add(bestpath, "med", "true");
10243 }
10244
10245 json_object_object_add(json, "bestPath", bestpath);
10246 }
10247
10248 /* Print the error code/subcode for why the peer is down */
10249 static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10250 json_object *json_peer, bool use_json)
10251 {
10252 const char *code_str;
10253 const char *subcode_str;
10254
10255 if (use_json) {
10256 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10257 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10258 char errorcodesubcode_hexstr[5];
10259 char errorcodesubcode_str[256];
10260
10261 code_str = bgp_notify_code_str(peer->notify.code);
10262 subcode_str = bgp_notify_subcode_str(
10263 peer->notify.code,
10264 peer->notify.subcode);
10265
10266 snprintf(errorcodesubcode_hexstr,
10267 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10268 peer->notify.code, peer->notify.subcode);
10269 json_object_string_add(json_peer,
10270 "lastErrorCodeSubcode",
10271 errorcodesubcode_hexstr);
10272 snprintf(errorcodesubcode_str, 255, "%s%s",
10273 code_str, subcode_str);
10274 json_object_string_add(json_peer,
10275 "lastNotificationReason",
10276 errorcodesubcode_str);
10277 json_object_boolean_add(json_peer,
10278 "lastNotificationHardReset",
10279 peer->notify.hard_reset);
10280 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10281 && peer->notify.code == BGP_NOTIFY_CEASE
10282 && (peer->notify.subcode
10283 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10284 || peer->notify.subcode
10285 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10286 && peer->notify.length) {
10287 char msgbuf[1024];
10288 const char *msg_str;
10289
10290 msg_str = bgp_notify_admin_message(
10291 msgbuf, sizeof(msgbuf),
10292 (uint8_t *)peer->notify.data,
10293 peer->notify.length);
10294 if (msg_str)
10295 json_object_string_add(
10296 json_peer,
10297 "lastShutdownDescription",
10298 msg_str);
10299 }
10300
10301 }
10302 json_object_string_add(json_peer, "lastResetDueTo",
10303 peer_down_str[(int)peer->last_reset]);
10304 json_object_int_add(json_peer, "lastResetCode",
10305 peer->last_reset);
10306 } else {
10307 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10308 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10309 code_str = bgp_notify_code_str(peer->notify.code);
10310 subcode_str =
10311 bgp_notify_subcode_str(peer->notify.code,
10312 peer->notify.subcode);
10313 vty_out(vty, " Notification %s (%s%s%s)\n",
10314 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10315 ? "sent"
10316 : "received",
10317 code_str, subcode_str,
10318 peer->notify.hard_reset
10319 ? bgp_notify_subcode_str(
10320 BGP_NOTIFY_CEASE,
10321 BGP_NOTIFY_CEASE_HARD_RESET)
10322 : "");
10323 } else {
10324 vty_out(vty, " %s\n",
10325 peer_down_str[(int)peer->last_reset]);
10326 }
10327 }
10328 }
10329
10330 static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10331 safi_t safi)
10332 {
10333 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
10334 }
10335
10336 static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10337 struct peer *peer, json_object *json_peer,
10338 int max_neighbor_width, bool use_json)
10339 {
10340 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10341 int len;
10342
10343 if (use_json) {
10344 if (peer_dynamic_neighbor(peer))
10345 json_object_boolean_true_add(json_peer,
10346 "dynamicPeer");
10347 if (peer->hostname)
10348 json_object_string_add(json_peer, "hostname",
10349 peer->hostname);
10350
10351 if (peer->domainname)
10352 json_object_string_add(json_peer, "domainname",
10353 peer->domainname);
10354 json_object_int_add(json_peer, "connectionsEstablished",
10355 peer->established);
10356 json_object_int_add(json_peer, "connectionsDropped",
10357 peer->dropped);
10358 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10359 use_json, json_peer);
10360 if (peer_established(peer))
10361 json_object_string_add(json_peer, "lastResetDueTo",
10362 "AFI/SAFI Not Negotiated");
10363 else
10364 bgp_show_peer_reset(NULL, peer, json_peer, true);
10365 } else {
10366 dn_flag[1] = '\0';
10367 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10368 if (peer->hostname
10369 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10370 len = vty_out(vty, "%s%s(%s)", dn_flag,
10371 peer->hostname, peer->host);
10372 else
10373 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10374
10375 /* pad the neighbor column with spaces */
10376 if (len < max_neighbor_width)
10377 vty_out(vty, "%*s", max_neighbor_width - len,
10378 " ");
10379 vty_out(vty, "%7d %7d %9s", peer->established,
10380 peer->dropped,
10381 peer_uptime(peer->uptime, timebuf,
10382 BGP_UPTIME_LEN, 0, NULL));
10383 if (peer_established(peer))
10384 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10385 else
10386 bgp_show_peer_reset(vty, peer, NULL,
10387 false);
10388 }
10389 }
10390
10391 /* Strip peer's description to the given size. */
10392 static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10393 {
10394 static char stripped[BUFSIZ];
10395 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10396
10397 strlcpy(stripped, desc, len + 1);
10398
10399 return stripped;
10400 }
10401
10402 /* Determine whether var peer should be filtered out of the summary. */
10403 static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10404 struct peer *fpeer, int as_type,
10405 as_t as)
10406 {
10407
10408 /* filter neighbor XXXX */
10409 if (fpeer && fpeer != peer)
10410 return true;
10411
10412 /* filter remote-as (internal|external) */
10413 if (as_type != AS_UNSPECIFIED) {
10414 if (peer->as_type == AS_SPECIFIED) {
10415 if (as_type == AS_INTERNAL) {
10416 if (peer->as != peer->local_as)
10417 return true;
10418 } else if (peer->as == peer->local_as)
10419 return true;
10420 } else if (as_type != peer->as_type)
10421 return true;
10422 } else if (as && as != peer->as) /* filter remote-as XXX */
10423 return true;
10424
10425 return false;
10426 }
10427
10428 /* Show BGP peer's summary information.
10429 *
10430 * Peer's description is stripped according to if `wide` option is given
10431 * or not.
10432 *
10433 * When adding new columns to `show bgp summary` output, please make
10434 * sure `Desc` is the lastest column to show because it can contain
10435 * whitespaces and the whole output will be tricky.
10436 */
10437 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10438 struct peer *fpeer, int as_type, as_t as,
10439 uint16_t show_flags)
10440 {
10441 struct peer *peer;
10442 struct listnode *node, *nnode;
10443 unsigned int count = 0, dn_count = 0;
10444 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10445 char neighbor_buf[VTY_BUFSIZ];
10446 int neighbor_col_default_width = 16;
10447 int len, failed_count = 0;
10448 unsigned int filtered_count = 0;
10449 int max_neighbor_width = 0;
10450 int pfx_rcd_safi;
10451 json_object *json = NULL;
10452 json_object *json_peer = NULL;
10453 json_object *json_peers = NULL;
10454 struct peer_af *paf;
10455 struct bgp_filter *filter;
10456 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10457 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10458 bool show_established =
10459 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10460 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10461 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10462
10463 /* labeled-unicast routes are installed in the unicast table so in order
10464 * to
10465 * display the correct PfxRcd value we must look at SAFI_UNICAST
10466 */
10467
10468 if (safi == SAFI_LABELED_UNICAST)
10469 pfx_rcd_safi = SAFI_UNICAST;
10470 else
10471 pfx_rcd_safi = safi;
10472
10473 if (use_json) {
10474 json = json_object_new_object();
10475 json_peers = json_object_new_object();
10476 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10477 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10478 as_type, as)) {
10479 filtered_count++;
10480 count++;
10481 continue;
10482 }
10483
10484 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10485 continue;
10486
10487 if (peer->afc[afi][safi]) {
10488 /* See if we have at least a single failed peer */
10489 if (bgp_has_peer_failed(peer, afi, safi))
10490 failed_count++;
10491 count++;
10492 }
10493 if (peer_dynamic_neighbor(peer))
10494 dn_count++;
10495 }
10496
10497 } else {
10498 /* Loop over all neighbors that will be displayed to determine
10499 * how many
10500 * characters are needed for the Neighbor column
10501 */
10502 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10503 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10504 as_type, as)) {
10505 filtered_count++;
10506 count++;
10507 continue;
10508 }
10509
10510 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10511 continue;
10512
10513 if (peer->afc[afi][safi]) {
10514 memset(dn_flag, '\0', sizeof(dn_flag));
10515 if (peer_dynamic_neighbor(peer))
10516 dn_flag[0] = '*';
10517
10518 if (peer->hostname
10519 && CHECK_FLAG(bgp->flags,
10520 BGP_FLAG_SHOW_HOSTNAME))
10521 snprintf(neighbor_buf,
10522 sizeof(neighbor_buf),
10523 "%s%s(%s) ", dn_flag,
10524 peer->hostname, peer->host);
10525 else
10526 snprintf(neighbor_buf,
10527 sizeof(neighbor_buf), "%s%s ",
10528 dn_flag, peer->host);
10529
10530 len = strlen(neighbor_buf);
10531
10532 if (len > max_neighbor_width)
10533 max_neighbor_width = len;
10534
10535 /* See if we have at least a single failed peer */
10536 if (bgp_has_peer_failed(peer, afi, safi))
10537 failed_count++;
10538 count++;
10539 }
10540 }
10541
10542 /* Originally we displayed the Neighbor column as 16
10543 * characters wide so make that the default
10544 */
10545 if (max_neighbor_width < neighbor_col_default_width)
10546 max_neighbor_width = neighbor_col_default_width;
10547 }
10548
10549 if (show_failed && !failed_count) {
10550 if (use_json) {
10551 json_object_int_add(json, "failedPeersCount", 0);
10552 json_object_int_add(json, "dynamicPeers", dn_count);
10553 json_object_int_add(json, "totalPeers", count);
10554
10555 vty_json(vty, json);
10556 } else {
10557 vty_out(vty, "%% No failed BGP neighbors found\n");
10558 }
10559 return CMD_SUCCESS;
10560 }
10561
10562 count = 0; /* Reset the value as its used again */
10563 filtered_count = 0;
10564 dn_count = 0;
10565 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10566 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10567 continue;
10568
10569 if (!peer->afc[afi][safi])
10570 continue;
10571
10572 if (!count) {
10573 unsigned long ents;
10574 char memstrbuf[MTYPE_MEMSTR_LEN];
10575 int64_t vrf_id_ui;
10576
10577 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10578 ? -1
10579 : (int64_t)bgp->vrf_id;
10580
10581 /* Usage summary and header */
10582 if (use_json) {
10583 json_object_string_addf(json, "routerId",
10584 "%pI4",
10585 &bgp->router_id);
10586 json_object_int_add(json, "as", bgp->as);
10587 json_object_int_add(json, "vrfId", vrf_id_ui);
10588 json_object_string_add(
10589 json, "vrfName",
10590 (bgp->inst_type
10591 == BGP_INSTANCE_TYPE_DEFAULT)
10592 ? VRF_DEFAULT_NAME
10593 : bgp->name);
10594 } else {
10595 vty_out(vty,
10596 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10597 &bgp->router_id, bgp->as,
10598 bgp->vrf_id == VRF_UNKNOWN
10599 ? -1
10600 : (int)bgp->vrf_id);
10601 vty_out(vty, "\n");
10602 }
10603
10604 if (bgp_update_delay_configured(bgp)) {
10605 if (use_json) {
10606 json_object_int_add(
10607 json, "updateDelayLimit",
10608 bgp->v_update_delay);
10609
10610 if (bgp->v_update_delay
10611 != bgp->v_establish_wait)
10612 json_object_int_add(
10613 json,
10614 "updateDelayEstablishWait",
10615 bgp->v_establish_wait);
10616
10617 if (bgp_update_delay_active(bgp)) {
10618 json_object_string_add(
10619 json,
10620 "updateDelayFirstNeighbor",
10621 bgp->update_delay_begin_time);
10622 json_object_boolean_true_add(
10623 json,
10624 "updateDelayInProgress");
10625 } else {
10626 if (bgp->update_delay_over) {
10627 json_object_string_add(
10628 json,
10629 "updateDelayFirstNeighbor",
10630 bgp->update_delay_begin_time);
10631 json_object_string_add(
10632 json,
10633 "updateDelayBestpathResumed",
10634 bgp->update_delay_end_time);
10635 json_object_string_add(
10636 json,
10637 "updateDelayZebraUpdateResume",
10638 bgp->update_delay_zebra_resume_time);
10639 json_object_string_add(
10640 json,
10641 "updateDelayPeerUpdateResume",
10642 bgp->update_delay_peers_resume_time);
10643 }
10644 }
10645 } else {
10646 vty_out(vty,
10647 "Read-only mode update-delay limit: %d seconds\n",
10648 bgp->v_update_delay);
10649 if (bgp->v_update_delay
10650 != bgp->v_establish_wait)
10651 vty_out(vty,
10652 " Establish wait: %d seconds\n",
10653 bgp->v_establish_wait);
10654
10655 if (bgp_update_delay_active(bgp)) {
10656 vty_out(vty,
10657 " First neighbor established: %s\n",
10658 bgp->update_delay_begin_time);
10659 vty_out(vty,
10660 " Delay in progress\n");
10661 } else {
10662 if (bgp->update_delay_over) {
10663 vty_out(vty,
10664 " First neighbor established: %s\n",
10665 bgp->update_delay_begin_time);
10666 vty_out(vty,
10667 " Best-paths resumed: %s\n",
10668 bgp->update_delay_end_time);
10669 vty_out(vty,
10670 " zebra update resumed: %s\n",
10671 bgp->update_delay_zebra_resume_time);
10672 vty_out(vty,
10673 " peers update resumed: %s\n",
10674 bgp->update_delay_peers_resume_time);
10675 }
10676 }
10677 }
10678 }
10679
10680 if (use_json) {
10681 if (bgp_maxmed_onstartup_configured(bgp)
10682 && bgp->maxmed_active)
10683 json_object_boolean_true_add(
10684 json, "maxMedOnStartup");
10685 if (bgp->v_maxmed_admin)
10686 json_object_boolean_true_add(
10687 json, "maxMedAdministrative");
10688
10689 json_object_int_add(
10690 json, "tableVersion",
10691 bgp_table_version(bgp->rib[afi][safi]));
10692
10693 ents = bgp_table_count(bgp->rib[afi][safi]);
10694 json_object_int_add(json, "ribCount", ents);
10695 json_object_int_add(
10696 json, "ribMemory",
10697 ents * sizeof(struct bgp_dest));
10698
10699 ents = bgp->af_peer_count[afi][safi];
10700 json_object_int_add(json, "peerCount", ents);
10701 json_object_int_add(json, "peerMemory",
10702 ents * sizeof(struct peer));
10703
10704 if ((ents = listcount(bgp->group))) {
10705 json_object_int_add(
10706 json, "peerGroupCount", ents);
10707 json_object_int_add(
10708 json, "peerGroupMemory",
10709 ents * sizeof(struct
10710 peer_group));
10711 }
10712
10713 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10714 BGP_CONFIG_DAMPENING))
10715 json_object_boolean_true_add(
10716 json, "dampeningEnabled");
10717 } else {
10718 if (!show_terse) {
10719 if (bgp_maxmed_onstartup_configured(bgp)
10720 && bgp->maxmed_active)
10721 vty_out(vty,
10722 "Max-med on-startup active\n");
10723 if (bgp->v_maxmed_admin)
10724 vty_out(vty,
10725 "Max-med administrative active\n");
10726
10727 vty_out(vty,
10728 "BGP table version %" PRIu64
10729 "\n",
10730 bgp_table_version(
10731 bgp->rib[afi][safi]));
10732
10733 ents = bgp_table_count(
10734 bgp->rib[afi][safi]);
10735 vty_out(vty,
10736 "RIB entries %ld, using %s of memory\n",
10737 ents,
10738 mtype_memstr(
10739 memstrbuf,
10740 sizeof(memstrbuf),
10741 ents
10742 * sizeof(
10743 struct
10744 bgp_dest)));
10745
10746 /* Peer related usage */
10747 ents = bgp->af_peer_count[afi][safi];
10748 vty_out(vty,
10749 "Peers %ld, using %s of memory\n",
10750 ents,
10751 mtype_memstr(
10752 memstrbuf,
10753 sizeof(memstrbuf),
10754 ents
10755 * sizeof(
10756 struct
10757 peer)));
10758
10759 if ((ents = listcount(bgp->group)))
10760 vty_out(vty,
10761 "Peer groups %ld, using %s of memory\n",
10762 ents,
10763 mtype_memstr(
10764 memstrbuf,
10765 sizeof(memstrbuf),
10766 ents
10767 * sizeof(
10768 struct
10769 peer_group)));
10770
10771 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10772 BGP_CONFIG_DAMPENING))
10773 vty_out(vty,
10774 "Dampening enabled.\n");
10775 }
10776 if (show_failed) {
10777 vty_out(vty, "\n");
10778
10779 /* Subtract 8 here because 'Neighbor' is
10780 * 8 characters */
10781 vty_out(vty, "Neighbor");
10782 vty_out(vty, "%*s",
10783 max_neighbor_width - 8, " ");
10784 vty_out(vty,
10785 BGP_SHOW_SUMMARY_HEADER_FAILED);
10786 }
10787 }
10788 }
10789
10790 paf = peer_af_find(peer, afi, safi);
10791 filter = &peer->filter[afi][safi];
10792
10793 count++;
10794 /* Works for both failed & successful cases */
10795 if (peer_dynamic_neighbor(peer))
10796 dn_count++;
10797
10798 if (use_json) {
10799 json_peer = NULL;
10800 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10801 as_type, as)) {
10802 filtered_count++;
10803 continue;
10804 }
10805 if (show_failed &&
10806 bgp_has_peer_failed(peer, afi, safi)) {
10807 json_peer = json_object_new_object();
10808 bgp_show_failed_summary(vty, bgp, peer,
10809 json_peer, 0, use_json);
10810 } else if (!show_failed) {
10811 if (show_established
10812 && bgp_has_peer_failed(peer, afi, safi)) {
10813 filtered_count++;
10814 continue;
10815 }
10816
10817 json_peer = json_object_new_object();
10818 if (peer_dynamic_neighbor(peer)) {
10819 json_object_boolean_true_add(json_peer,
10820 "dynamicPeer");
10821 }
10822
10823 if (peer->hostname)
10824 json_object_string_add(json_peer, "hostname",
10825 peer->hostname);
10826
10827 if (peer->domainname)
10828 json_object_string_add(json_peer, "domainname",
10829 peer->domainname);
10830
10831 json_object_int_add(json_peer, "remoteAs", peer->as);
10832 json_object_int_add(
10833 json_peer, "localAs",
10834 peer->change_local_as
10835 ? peer->change_local_as
10836 : peer->local_as);
10837 json_object_int_add(json_peer, "version", 4);
10838 json_object_int_add(json_peer, "msgRcvd",
10839 PEER_TOTAL_RX(peer));
10840 json_object_int_add(json_peer, "msgSent",
10841 PEER_TOTAL_TX(peer));
10842
10843 atomic_size_t outq_count, inq_count;
10844 outq_count = atomic_load_explicit(
10845 &peer->obuf->count,
10846 memory_order_relaxed);
10847 inq_count = atomic_load_explicit(
10848 &peer->ibuf->count,
10849 memory_order_relaxed);
10850
10851 json_object_int_add(json_peer, "tableVersion",
10852 peer->version[afi][safi]);
10853 json_object_int_add(json_peer, "outq",
10854 outq_count);
10855 json_object_int_add(json_peer, "inq",
10856 inq_count);
10857 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10858 use_json, json_peer);
10859
10860 json_object_int_add(json_peer, "pfxRcd",
10861 peer->pcount[afi][pfx_rcd_safi]);
10862
10863 if (paf && PAF_SUBGRP(paf))
10864 json_object_int_add(
10865 json_peer, "pfxSnt",
10866 (PAF_SUBGRP(paf))->scount);
10867 else
10868 json_object_int_add(json_peer, "pfxSnt",
10869 0);
10870
10871 /* BGP FSM state */
10872 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10873 || CHECK_FLAG(peer->bgp->flags,
10874 BGP_FLAG_SHUTDOWN))
10875 json_object_string_add(json_peer,
10876 "state",
10877 "Idle (Admin)");
10878 else if (peer->afc_recv[afi][safi])
10879 json_object_string_add(
10880 json_peer, "state",
10881 lookup_msg(bgp_status_msg,
10882 peer->status, NULL));
10883 else if (CHECK_FLAG(
10884 peer->sflags,
10885 PEER_STATUS_PREFIX_OVERFLOW))
10886 json_object_string_add(json_peer,
10887 "state",
10888 "Idle (PfxCt)");
10889 else
10890 json_object_string_add(
10891 json_peer, "state",
10892 lookup_msg(bgp_status_msg,
10893 peer->status, NULL));
10894
10895 /* BGP peer state */
10896 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10897 || CHECK_FLAG(peer->bgp->flags,
10898 BGP_FLAG_SHUTDOWN))
10899 json_object_string_add(json_peer,
10900 "peerState",
10901 "Admin");
10902 else if (CHECK_FLAG(
10903 peer->sflags,
10904 PEER_STATUS_PREFIX_OVERFLOW))
10905 json_object_string_add(json_peer,
10906 "peerState",
10907 "PfxCt");
10908 else if (CHECK_FLAG(peer->flags,
10909 PEER_FLAG_PASSIVE))
10910 json_object_string_add(json_peer,
10911 "peerState",
10912 "Passive");
10913 else if (CHECK_FLAG(peer->sflags,
10914 PEER_STATUS_NSF_WAIT))
10915 json_object_string_add(json_peer,
10916 "peerState",
10917 "NSF passive");
10918 else if (CHECK_FLAG(
10919 peer->bgp->flags,
10920 BGP_FLAG_EBGP_REQUIRES_POLICY)
10921 && (!bgp_inbound_policy_exists(peer,
10922 filter)
10923 || !bgp_outbound_policy_exists(
10924 peer, filter)))
10925 json_object_string_add(json_peer,
10926 "peerState",
10927 "Policy");
10928 else
10929 json_object_string_add(
10930 json_peer, "peerState", "OK");
10931
10932 json_object_int_add(json_peer, "connectionsEstablished",
10933 peer->established);
10934 json_object_int_add(json_peer, "connectionsDropped",
10935 peer->dropped);
10936 if (peer->desc)
10937 json_object_string_add(
10938 json_peer, "desc", peer->desc);
10939 }
10940 /* Avoid creating empty peer dicts in JSON */
10941 if (json_peer == NULL)
10942 continue;
10943
10944 if (peer->conf_if)
10945 json_object_string_add(json_peer, "idType",
10946 "interface");
10947 else if (peer->su.sa.sa_family == AF_INET)
10948 json_object_string_add(json_peer, "idType",
10949 "ipv4");
10950 else if (peer->su.sa.sa_family == AF_INET6)
10951 json_object_string_add(json_peer, "idType",
10952 "ipv6");
10953 json_object_object_add(json_peers, peer->host,
10954 json_peer);
10955 } else {
10956 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10957 as_type, as)) {
10958 filtered_count++;
10959 continue;
10960 }
10961 if (show_failed &&
10962 bgp_has_peer_failed(peer, afi, safi)) {
10963 bgp_show_failed_summary(vty, bgp, peer, NULL,
10964 max_neighbor_width,
10965 use_json);
10966 } else if (!show_failed) {
10967 if (show_established
10968 && bgp_has_peer_failed(peer, afi, safi)) {
10969 filtered_count++;
10970 continue;
10971 }
10972
10973 if ((count - filtered_count) == 1) {
10974 /* display headline before the first
10975 * neighbor line */
10976 vty_out(vty, "\n");
10977
10978 /* Subtract 8 here because 'Neighbor' is
10979 * 8 characters */
10980 vty_out(vty, "Neighbor");
10981 vty_out(vty, "%*s",
10982 max_neighbor_width - 8, " ");
10983 vty_out(vty,
10984 show_wide
10985 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10986 : BGP_SHOW_SUMMARY_HEADER_ALL);
10987 }
10988
10989 memset(dn_flag, '\0', sizeof(dn_flag));
10990 if (peer_dynamic_neighbor(peer)) {
10991 dn_flag[0] = '*';
10992 }
10993
10994 if (peer->hostname
10995 && CHECK_FLAG(bgp->flags,
10996 BGP_FLAG_SHOW_HOSTNAME))
10997 len = vty_out(vty, "%s%s(%s)", dn_flag,
10998 peer->hostname,
10999 peer->host);
11000 else
11001 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11002
11003 /* pad the neighbor column with spaces */
11004 if (len < max_neighbor_width)
11005 vty_out(vty, "%*s", max_neighbor_width - len,
11006 " ");
11007
11008 atomic_size_t outq_count, inq_count;
11009 outq_count = atomic_load_explicit(
11010 &peer->obuf->count,
11011 memory_order_relaxed);
11012 inq_count = atomic_load_explicit(
11013 &peer->ibuf->count,
11014 memory_order_relaxed);
11015
11016 if (show_wide)
11017 vty_out(vty,
11018 "4 %10u %10u %9u %9u %8" PRIu64
11019 " %4zu %4zu %8s",
11020 peer->as,
11021 peer->change_local_as
11022 ? peer->change_local_as
11023 : peer->local_as,
11024 PEER_TOTAL_RX(peer),
11025 PEER_TOTAL_TX(peer),
11026 peer->version[afi][safi],
11027 inq_count, outq_count,
11028 peer_uptime(peer->uptime,
11029 timebuf,
11030 BGP_UPTIME_LEN, 0,
11031 NULL));
11032 else
11033 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11034 " %4zu %4zu %8s",
11035 peer->as, PEER_TOTAL_RX(peer),
11036 PEER_TOTAL_TX(peer),
11037 peer->version[afi][safi],
11038 inq_count, outq_count,
11039 peer_uptime(peer->uptime,
11040 timebuf,
11041 BGP_UPTIME_LEN, 0,
11042 NULL));
11043
11044 if (peer_established(peer)) {
11045 if (peer->afc_recv[afi][safi]) {
11046 if (CHECK_FLAG(
11047 bgp->flags,
11048 BGP_FLAG_EBGP_REQUIRES_POLICY)
11049 && !bgp_inbound_policy_exists(
11050 peer, filter))
11051 vty_out(vty, " %12s",
11052 "(Policy)");
11053 else
11054 vty_out(vty,
11055 " %12u",
11056 peer->pcount
11057 [afi]
11058 [pfx_rcd_safi]);
11059 } else {
11060 vty_out(vty, " NoNeg");
11061 }
11062
11063 if (paf && PAF_SUBGRP(paf)) {
11064 if (CHECK_FLAG(
11065 bgp->flags,
11066 BGP_FLAG_EBGP_REQUIRES_POLICY)
11067 && !bgp_outbound_policy_exists(
11068 peer, filter))
11069 vty_out(vty, " %8s",
11070 "(Policy)");
11071 else
11072 vty_out(vty,
11073 " %8u",
11074 (PAF_SUBGRP(
11075 paf))
11076 ->scount);
11077 } else {
11078 vty_out(vty, " NoNeg");
11079 }
11080 } else {
11081 if (CHECK_FLAG(peer->flags,
11082 PEER_FLAG_SHUTDOWN)
11083 || CHECK_FLAG(peer->bgp->flags,
11084 BGP_FLAG_SHUTDOWN))
11085 vty_out(vty, " Idle (Admin)");
11086 else if (CHECK_FLAG(
11087 peer->sflags,
11088 PEER_STATUS_PREFIX_OVERFLOW))
11089 vty_out(vty, " Idle (PfxCt)");
11090 else
11091 vty_out(vty, " %12s",
11092 lookup_msg(bgp_status_msg,
11093 peer->status, NULL));
11094
11095 vty_out(vty, " %8u", 0);
11096 }
11097 /* Make sure `Desc` column is the lastest in
11098 * the output.
11099 */
11100 if (peer->desc)
11101 vty_out(vty, " %s",
11102 bgp_peer_description_stripped(
11103 peer->desc,
11104 show_wide ? 64 : 20));
11105 else
11106 vty_out(vty, " N/A");
11107 vty_out(vty, "\n");
11108 }
11109
11110 }
11111 }
11112
11113 if (use_json) {
11114 json_object_object_add(json, "peers", json_peers);
11115 json_object_int_add(json, "failedPeers", failed_count);
11116 json_object_int_add(json, "displayedPeers",
11117 count - filtered_count);
11118 json_object_int_add(json, "totalPeers", count);
11119 json_object_int_add(json, "dynamicPeers", dn_count);
11120
11121 if (!show_failed)
11122 bgp_show_bestpath_json(bgp, json);
11123
11124 vty_json(vty, json);
11125 } else {
11126 if (count) {
11127 if (filtered_count == count)
11128 vty_out(vty, "\n%% No matching neighbor\n");
11129 else {
11130 if (show_failed)
11131 vty_out(vty, "\nDisplayed neighbors %d",
11132 failed_count);
11133 else if (as_type != AS_UNSPECIFIED || as
11134 || fpeer || show_established)
11135 vty_out(vty, "\nDisplayed neighbors %d",
11136 count - filtered_count);
11137
11138 vty_out(vty, "\nTotal number of neighbors %d\n",
11139 count);
11140 }
11141 } else {
11142 vty_out(vty, "No %s neighbor is configured\n",
11143 get_afi_safi_str(afi, safi, false));
11144 }
11145
11146 if (dn_count) {
11147 vty_out(vty, "* - dynamic neighbor\n");
11148 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11149 dn_count, bgp->dynamic_neighbors_limit);
11150 }
11151 }
11152
11153 return CMD_SUCCESS;
11154 }
11155
11156 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11157 int safi, struct peer *fpeer, int as_type,
11158 as_t as, uint16_t show_flags)
11159 {
11160 int is_first = 1;
11161 int afi_wildcard = (afi == AFI_MAX);
11162 int safi_wildcard = (safi == SAFI_MAX);
11163 int is_wildcard = (afi_wildcard || safi_wildcard);
11164 bool nbr_output = false;
11165 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11166
11167 if (use_json && is_wildcard)
11168 vty_out(vty, "{\n");
11169 if (afi_wildcard)
11170 afi = 1; /* AFI_IP */
11171 while (afi < AFI_MAX) {
11172 if (safi_wildcard)
11173 safi = 1; /* SAFI_UNICAST */
11174 while (safi < SAFI_MAX) {
11175 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11176 nbr_output = true;
11177
11178 if (is_wildcard) {
11179 /*
11180 * So limit output to those afi/safi
11181 * pairs that
11182 * actualy have something interesting in
11183 * them
11184 */
11185 if (use_json) {
11186 if (!is_first)
11187 vty_out(vty, ",\n");
11188 else
11189 is_first = 0;
11190
11191 vty_out(vty, "\"%s\":",
11192 get_afi_safi_str(afi,
11193 safi,
11194 true));
11195 } else {
11196 vty_out(vty,
11197 "\n%s Summary (%s):\n",
11198 get_afi_safi_str(afi,
11199 safi,
11200 false),
11201 bgp->name_pretty);
11202 }
11203 }
11204 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11205 as_type, as, show_flags);
11206 }
11207 safi++;
11208 if (!safi_wildcard)
11209 safi = SAFI_MAX;
11210 }
11211 afi++;
11212 if (!afi_wildcard)
11213 afi = AFI_MAX;
11214 }
11215
11216 if (use_json && is_wildcard)
11217 vty_out(vty, "}\n");
11218 else if (!nbr_output) {
11219 if (use_json)
11220 vty_out(vty, "{}\n");
11221 else
11222 vty_out(vty, "%% No BGP neighbors found in %s\n",
11223 bgp->name_pretty);
11224 }
11225 }
11226
11227 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11228 safi_t safi,
11229 const char *neighbor,
11230 int as_type, as_t as,
11231 uint16_t show_flags)
11232 {
11233 struct listnode *node, *nnode;
11234 struct bgp *bgp;
11235 struct peer *fpeer = NULL;
11236 int is_first = 1;
11237 bool nbr_output = false;
11238 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11239
11240 if (use_json)
11241 vty_out(vty, "{\n");
11242
11243 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11244 nbr_output = true;
11245 if (use_json) {
11246 if (!is_first)
11247 vty_out(vty, ",\n");
11248 else
11249 is_first = 0;
11250
11251 vty_out(vty, "\"%s\":",
11252 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11253 ? VRF_DEFAULT_NAME
11254 : bgp->name);
11255 }
11256 if (neighbor) {
11257 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11258 use_json);
11259 if (!fpeer)
11260 continue;
11261 }
11262 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11263 as, show_flags);
11264 }
11265
11266 if (use_json)
11267 vty_out(vty, "}\n");
11268 else if (!nbr_output)
11269 vty_out(vty, "%% BGP instance not found\n");
11270 }
11271
11272 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11273 safi_t safi, const char *neighbor, int as_type,
11274 as_t as, uint16_t show_flags)
11275 {
11276 struct bgp *bgp;
11277 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11278 struct peer *fpeer = NULL;
11279
11280 if (name) {
11281 if (strmatch(name, "all")) {
11282 bgp_show_all_instances_summary_vty(vty, afi, safi,
11283 neighbor, as_type,
11284 as, show_flags);
11285 return CMD_SUCCESS;
11286 } else {
11287 bgp = bgp_lookup_by_name(name);
11288
11289 if (!bgp) {
11290 if (use_json)
11291 vty_out(vty, "{}\n");
11292 else
11293 vty_out(vty,
11294 "%% BGP instance not found\n");
11295 return CMD_WARNING;
11296 }
11297
11298 if (neighbor) {
11299 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11300 use_json);
11301 if (!fpeer)
11302 return CMD_WARNING;
11303 }
11304 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11305 as_type, as, show_flags);
11306 return CMD_SUCCESS;
11307 }
11308 }
11309
11310 bgp = bgp_get_default();
11311
11312 if (bgp) {
11313 if (neighbor) {
11314 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11315 use_json);
11316 if (!fpeer)
11317 return CMD_WARNING;
11318 }
11319 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11320 as, show_flags);
11321 } else {
11322 if (use_json)
11323 vty_out(vty, "{}\n");
11324 else
11325 vty_out(vty, "%% BGP instance not found\n");
11326 return CMD_WARNING;
11327 }
11328
11329 return CMD_SUCCESS;
11330 }
11331
11332 /* `show [ip] bgp summary' commands. */
11333 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11334 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11335 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11336 "]] [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]",
11337 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11338 BGP_SAFI_WITH_LABEL_HELP_STR
11339 "Display the entries for all address families\n"
11340 "Summary of BGP neighbor status\n"
11341 "Show only sessions in Established state\n"
11342 "Show only sessions not in Established state\n"
11343 "Show only the specified neighbor session\n"
11344 "Neighbor to display information about\n"
11345 "Neighbor to display information about\n"
11346 "Neighbor on BGP configured interface\n"
11347 "Show only the specified remote AS sessions\n"
11348 "AS number\n"
11349 "Internal (iBGP) AS sessions\n"
11350 "External (eBGP) AS sessions\n"
11351 "Shorten the information on BGP instances\n"
11352 "Increase table width for longer output\n" JSON_STR)
11353 {
11354 char *vrf = NULL;
11355 afi_t afi = AFI_MAX;
11356 safi_t safi = SAFI_MAX;
11357 as_t as = 0; /* 0 means AS filter not set */
11358 int as_type = AS_UNSPECIFIED;
11359 uint16_t show_flags = 0;
11360
11361 int idx = 0;
11362
11363 /* show [ip] bgp */
11364 if (!all && argv_find(argv, argc, "ip", &idx))
11365 afi = AFI_IP;
11366 /* [<vrf> VIEWVRFNAME] */
11367 if (argv_find(argv, argc, "vrf", &idx)) {
11368 vrf = argv[idx + 1]->arg;
11369 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11370 vrf = NULL;
11371 } else if (argv_find(argv, argc, "view", &idx))
11372 /* [<view> VIEWVRFNAME] */
11373 vrf = argv[idx + 1]->arg;
11374 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11375 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11376 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11377 }
11378
11379 if (argv_find(argv, argc, "failed", &idx))
11380 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11381
11382 if (argv_find(argv, argc, "established", &idx))
11383 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11384
11385 if (argv_find(argv, argc, "remote-as", &idx)) {
11386 if (argv[idx + 1]->arg[0] == 'i')
11387 as_type = AS_INTERNAL;
11388 else if (argv[idx + 1]->arg[0] == 'e')
11389 as_type = AS_EXTERNAL;
11390 else
11391 as = (as_t)atoi(argv[idx + 1]->arg);
11392 }
11393
11394 if (argv_find(argv, argc, "terse", &idx))
11395 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11396
11397 if (argv_find(argv, argc, "wide", &idx))
11398 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11399
11400 if (argv_find(argv, argc, "json", &idx))
11401 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11402
11403 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11404 show_flags);
11405 }
11406
11407 const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11408 {
11409 if (for_json)
11410 return get_afi_safi_json_str(afi, safi);
11411 else
11412 return get_afi_safi_vty_str(afi, safi);
11413 }
11414
11415
11416 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11417 afi_t afi, safi_t safi,
11418 uint16_t adv_smcap, uint16_t adv_rmcap,
11419 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11420 bool use_json, json_object *json_pref)
11421 {
11422 /* Send-Mode */
11423 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11424 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11425 if (use_json) {
11426 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11427 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11428 json_object_string_add(json_pref, "sendMode",
11429 "advertisedAndReceived");
11430 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11431 json_object_string_add(json_pref, "sendMode",
11432 "advertised");
11433 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11434 json_object_string_add(json_pref, "sendMode",
11435 "received");
11436 } else {
11437 vty_out(vty, " Send-mode: ");
11438 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11439 vty_out(vty, "advertised");
11440 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11441 vty_out(vty, "%sreceived",
11442 CHECK_FLAG(p->af_cap[afi][safi],
11443 adv_smcap)
11444 ? ", "
11445 : "");
11446 vty_out(vty, "\n");
11447 }
11448 }
11449
11450 /* Receive-Mode */
11451 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11452 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11453 if (use_json) {
11454 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11455 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11456 json_object_string_add(json_pref, "recvMode",
11457 "advertisedAndReceived");
11458 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11459 json_object_string_add(json_pref, "recvMode",
11460 "advertised");
11461 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11462 json_object_string_add(json_pref, "recvMode",
11463 "received");
11464 } else {
11465 vty_out(vty, " Receive-mode: ");
11466 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11467 vty_out(vty, "advertised");
11468 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11469 vty_out(vty, "%sreceived",
11470 CHECK_FLAG(p->af_cap[afi][safi],
11471 adv_rmcap)
11472 ? ", "
11473 : "");
11474 vty_out(vty, "\n");
11475 }
11476 }
11477 }
11478
11479 static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11480 struct peer *p,
11481 bool use_json,
11482 json_object *json)
11483 {
11484 bool rbit = false;
11485 bool nbit = false;
11486
11487 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11488 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11489 && (peer_established(p))) {
11490 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11491 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
11492 }
11493
11494 if (use_json) {
11495 json_object_boolean_add(json, "rBit", rbit);
11496 json_object_boolean_add(json, "nBit", nbit);
11497 } else {
11498 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11499 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
11500 }
11501 }
11502
11503 static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11504 struct peer *peer,
11505 bool use_json,
11506 json_object *json)
11507 {
11508 const char *mode = "NotApplicable";
11509
11510 if (!use_json)
11511 vty_out(vty, "\n Remote GR Mode: ");
11512
11513 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11514 && (peer_established(peer))) {
11515
11516 if ((peer->nsf_af_count == 0)
11517 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11518
11519 mode = "Disable";
11520
11521 } else if (peer->nsf_af_count == 0
11522 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11523
11524 mode = "Helper";
11525
11526 } else if (peer->nsf_af_count != 0
11527 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11528
11529 mode = "Restart";
11530 }
11531 }
11532
11533 if (use_json) {
11534 json_object_string_add(json, "remoteGrMode", mode);
11535 } else
11536 vty_out(vty, mode, "\n");
11537 }
11538
11539 static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11540 struct peer *p,
11541 bool use_json,
11542 json_object *json)
11543 {
11544 const char *mode = "Invalid";
11545
11546 if (!use_json)
11547 vty_out(vty, " Local GR Mode: ");
11548
11549 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11550 mode = "Helper";
11551 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11552 mode = "Restart";
11553 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11554 mode = "Disable";
11555 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11556 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11557 mode = "Helper*";
11558 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11559 mode = "Restart*";
11560 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11561 mode = "Disable*";
11562 else
11563 mode = "Invalid*";
11564 }
11565
11566 if (use_json) {
11567 json_object_string_add(json, "localGrMode", mode);
11568 } else {
11569 vty_out(vty, mode, "\n");
11570 }
11571 }
11572
11573 static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11574 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11575 {
11576 afi_t afi;
11577 safi_t safi;
11578 json_object *json_afi_safi = NULL;
11579 json_object *json_timer = NULL;
11580 json_object *json_endofrib_status = NULL;
11581 bool eor_flag = false;
11582
11583 FOREACH_AFI_SAFI_NSF (afi, safi) {
11584 if (!peer->afc[afi][safi])
11585 continue;
11586
11587 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11588 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11589 continue;
11590
11591 if (use_json) {
11592 json_afi_safi = json_object_new_object();
11593 json_endofrib_status = json_object_new_object();
11594 json_timer = json_object_new_object();
11595 }
11596
11597 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11598 eor_flag = true;
11599 else
11600 eor_flag = false;
11601
11602 if (!use_json) {
11603 vty_out(vty, " %s:\n",
11604 get_afi_safi_str(afi, safi, false));
11605
11606 vty_out(vty, " F bit: ");
11607 }
11608
11609 if (peer->nsf[afi][safi] &&
11610 CHECK_FLAG(peer->af_cap[afi][safi],
11611 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11612
11613 if (use_json) {
11614 json_object_boolean_true_add(json_afi_safi,
11615 "fBit");
11616 } else
11617 vty_out(vty, "True\n");
11618 } else {
11619 if (use_json)
11620 json_object_boolean_false_add(json_afi_safi,
11621 "fBit");
11622 else
11623 vty_out(vty, "False\n");
11624 }
11625
11626 if (!use_json)
11627 vty_out(vty, " End-of-RIB sent: ");
11628
11629 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11630 PEER_STATUS_EOR_SEND)) {
11631 if (use_json) {
11632 json_object_boolean_true_add(
11633 json_endofrib_status, "endOfRibSend");
11634
11635 PRINT_EOR_JSON(eor_flag);
11636 } else {
11637 vty_out(vty, "Yes\n");
11638 vty_out(vty,
11639 " End-of-RIB sent after update: ");
11640
11641 PRINT_EOR(eor_flag);
11642 }
11643 } else {
11644 if (use_json) {
11645 json_object_boolean_false_add(
11646 json_endofrib_status, "endOfRibSend");
11647 json_object_boolean_false_add(
11648 json_endofrib_status,
11649 "endOfRibSentAfterUpdate");
11650 } else {
11651 vty_out(vty, "No\n");
11652 vty_out(vty,
11653 " End-of-RIB sent after update: ");
11654 vty_out(vty, "No\n");
11655 }
11656 }
11657
11658 if (!use_json)
11659 vty_out(vty, " End-of-RIB received: ");
11660
11661 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11662 PEER_STATUS_EOR_RECEIVED)) {
11663 if (use_json)
11664 json_object_boolean_true_add(
11665 json_endofrib_status, "endOfRibRecv");
11666 else
11667 vty_out(vty, "Yes\n");
11668 } else {
11669 if (use_json)
11670 json_object_boolean_false_add(
11671 json_endofrib_status, "endOfRibRecv");
11672 else
11673 vty_out(vty, "No\n");
11674 }
11675
11676 if (use_json) {
11677 json_object_int_add(json_timer, "stalePathTimer",
11678 peer->bgp->stalepath_time);
11679
11680 if (peer->t_gr_stale != NULL) {
11681 json_object_int_add(json_timer,
11682 "stalePathTimerRemaining",
11683 thread_timer_remain_second(
11684 peer->t_gr_stale));
11685 }
11686
11687 /* Display Configured Selection
11688 * Deferral only when when
11689 * Gr mode is enabled.
11690 */
11691 if (CHECK_FLAG(peer->flags,
11692 PEER_FLAG_GRACEFUL_RESTART)) {
11693 json_object_int_add(json_timer,
11694 "selectionDeferralTimer",
11695 peer->bgp->stalepath_time);
11696 }
11697
11698 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11699 NULL) {
11700
11701 json_object_int_add(
11702 json_timer,
11703 "selectionDeferralTimerRemaining",
11704 thread_timer_remain_second(
11705 peer->bgp->gr_info[afi][safi]
11706 .t_select_deferral));
11707 }
11708 } else {
11709 vty_out(vty, " Timers:\n");
11710 vty_out(vty,
11711 " Configured Stale Path Time(sec): %u\n",
11712 peer->bgp->stalepath_time);
11713
11714 if (peer->t_gr_stale != NULL)
11715 vty_out(vty,
11716 " Stale Path Remaining(sec): %ld\n",
11717 thread_timer_remain_second(
11718 peer->t_gr_stale));
11719 /* Display Configured Selection
11720 * Deferral only when when
11721 * Gr mode is enabled.
11722 */
11723 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11724 vty_out(vty,
11725 " Configured Selection Deferral Time(sec): %u\n",
11726 peer->bgp->select_defer_time);
11727
11728 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11729 NULL)
11730 vty_out(vty,
11731 " Selection Deferral Time Remaining(sec): %ld\n",
11732 thread_timer_remain_second(
11733 peer->bgp->gr_info[afi][safi]
11734 .t_select_deferral));
11735 }
11736 if (use_json) {
11737 json_object_object_add(json_afi_safi, "endOfRibStatus",
11738 json_endofrib_status);
11739 json_object_object_add(json_afi_safi, "timers",
11740 json_timer);
11741 json_object_object_add(
11742 json, get_afi_safi_str(afi, safi, true),
11743 json_afi_safi);
11744 }
11745 }
11746 }
11747
11748 static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11749 struct peer *p,
11750 bool use_json,
11751 json_object *json)
11752 {
11753 if (use_json) {
11754 json_object *json_timer = NULL;
11755
11756 json_timer = json_object_new_object();
11757
11758 json_object_int_add(json_timer, "configuredRestartTimer",
11759 p->bgp->restart_time);
11760
11761 json_object_int_add(json_timer, "receivedRestartTimer",
11762 p->v_gr_restart);
11763
11764 if (p->t_gr_restart != NULL)
11765 json_object_int_add(
11766 json_timer, "restartTimerRemaining",
11767 thread_timer_remain_second(p->t_gr_restart));
11768
11769 json_object_object_add(json, "timers", json_timer);
11770 } else {
11771
11772 vty_out(vty, " Timers:\n");
11773 vty_out(vty, " Configured Restart Time(sec): %u\n",
11774 p->bgp->restart_time);
11775
11776 vty_out(vty, " Received Restart Time(sec): %u\n",
11777 p->v_gr_restart);
11778 if (p->t_gr_restart != NULL)
11779 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11780 thread_timer_remain_second(p->t_gr_restart));
11781 if (p->t_gr_restart != NULL) {
11782 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11783 thread_timer_remain_second(p->t_gr_restart));
11784 }
11785 }
11786 }
11787
11788 static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11789 bool use_json, json_object *json)
11790 {
11791 char dn_flag[2] = {0};
11792 /* '*' + v6 address of neighbor */
11793 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11794
11795 if (!p->conf_if && peer_dynamic_neighbor(p))
11796 dn_flag[0] = '*';
11797
11798 if (p->conf_if) {
11799 if (use_json)
11800 json_object_string_addf(json, "neighborAddr", "%pSU",
11801 &p->su);
11802 else
11803 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11804 &p->su);
11805 } else {
11806 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11807 p->host);
11808
11809 if (use_json)
11810 json_object_string_add(json, "neighborAddr",
11811 neighborAddr);
11812 else
11813 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11814 }
11815
11816 /* more gr info in new format */
11817 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11818 }
11819
11820 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11821 safi_t safi, bool use_json,
11822 json_object *json_neigh)
11823 {
11824 struct bgp_filter *filter;
11825 struct peer_af *paf;
11826 char orf_pfx_name[BUFSIZ];
11827 int orf_pfx_count;
11828 json_object *json_af = NULL;
11829 json_object *json_prefA = NULL;
11830 json_object *json_prefB = NULL;
11831 json_object *json_addr = NULL;
11832 json_object *json_advmap = NULL;
11833
11834 if (use_json) {
11835 json_addr = json_object_new_object();
11836 json_af = json_object_new_object();
11837 filter = &p->filter[afi][safi];
11838
11839 if (peer_group_active(p))
11840 json_object_string_add(json_addr, "peerGroupMember",
11841 p->group->name);
11842
11843 paf = peer_af_find(p, afi, safi);
11844 if (paf && PAF_SUBGRP(paf)) {
11845 json_object_int_add(json_addr, "updateGroupId",
11846 PAF_UPDGRP(paf)->id);
11847 json_object_int_add(json_addr, "subGroupId",
11848 PAF_SUBGRP(paf)->id);
11849 json_object_int_add(json_addr, "packetQueueLength",
11850 bpacket_queue_virtual_length(paf));
11851 }
11852
11853 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11854 || CHECK_FLAG(p->af_cap[afi][safi],
11855 PEER_CAP_ORF_PREFIX_SM_RCV)
11856 || CHECK_FLAG(p->af_cap[afi][safi],
11857 PEER_CAP_ORF_PREFIX_RM_ADV)
11858 || CHECK_FLAG(p->af_cap[afi][safi],
11859 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11860 json_object_int_add(json_af, "orfType",
11861 ORF_TYPE_PREFIX);
11862 json_prefA = json_object_new_object();
11863 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11864 PEER_CAP_ORF_PREFIX_SM_ADV,
11865 PEER_CAP_ORF_PREFIX_RM_ADV,
11866 PEER_CAP_ORF_PREFIX_SM_RCV,
11867 PEER_CAP_ORF_PREFIX_RM_RCV,
11868 use_json, json_prefA);
11869 json_object_object_add(json_af, "orfPrefixList",
11870 json_prefA);
11871 }
11872
11873 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11874 || CHECK_FLAG(p->af_cap[afi][safi],
11875 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11876 || CHECK_FLAG(p->af_cap[afi][safi],
11877 PEER_CAP_ORF_PREFIX_RM_ADV)
11878 || CHECK_FLAG(p->af_cap[afi][safi],
11879 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11880 json_object_int_add(json_af, "orfOldType",
11881 ORF_TYPE_PREFIX_OLD);
11882 json_prefB = json_object_new_object();
11883 bgp_show_peer_afi_orf_cap(
11884 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11885 PEER_CAP_ORF_PREFIX_RM_ADV,
11886 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11887 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11888 json_prefB);
11889 json_object_object_add(json_af, "orfOldPrefixList",
11890 json_prefB);
11891 }
11892
11893 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11894 || CHECK_FLAG(p->af_cap[afi][safi],
11895 PEER_CAP_ORF_PREFIX_SM_RCV)
11896 || CHECK_FLAG(p->af_cap[afi][safi],
11897 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11898 || CHECK_FLAG(p->af_cap[afi][safi],
11899 PEER_CAP_ORF_PREFIX_RM_ADV)
11900 || CHECK_FLAG(p->af_cap[afi][safi],
11901 PEER_CAP_ORF_PREFIX_RM_RCV)
11902 || CHECK_FLAG(p->af_cap[afi][safi],
11903 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11904 json_object_object_add(json_addr, "afDependentCap",
11905 json_af);
11906 else
11907 json_object_free(json_af);
11908
11909 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11910 p->host, afi, safi);
11911 orf_pfx_count = prefix_bgp_show_prefix_list(
11912 NULL, afi, orf_pfx_name, use_json);
11913
11914 if (CHECK_FLAG(p->af_sflags[afi][safi],
11915 PEER_STATUS_ORF_PREFIX_SEND)
11916 || orf_pfx_count) {
11917 if (CHECK_FLAG(p->af_sflags[afi][safi],
11918 PEER_STATUS_ORF_PREFIX_SEND))
11919 json_object_boolean_true_add(json_neigh,
11920 "orfSent");
11921 if (orf_pfx_count)
11922 json_object_int_add(json_addr, "orfRecvCounter",
11923 orf_pfx_count);
11924 }
11925 if (CHECK_FLAG(p->af_sflags[afi][safi],
11926 PEER_STATUS_ORF_WAIT_REFRESH))
11927 json_object_string_add(
11928 json_addr, "orfFirstUpdate",
11929 "deferredUntilORFOrRouteRefreshRecvd");
11930
11931 if (CHECK_FLAG(p->af_flags[afi][safi],
11932 PEER_FLAG_REFLECTOR_CLIENT))
11933 json_object_boolean_true_add(json_addr,
11934 "routeReflectorClient");
11935 if (CHECK_FLAG(p->af_flags[afi][safi],
11936 PEER_FLAG_RSERVER_CLIENT))
11937 json_object_boolean_true_add(json_addr,
11938 "routeServerClient");
11939 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11940 json_object_boolean_true_add(json_addr,
11941 "inboundSoftConfigPermit");
11942
11943 if (CHECK_FLAG(p->af_flags[afi][safi],
11944 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11945 json_object_boolean_true_add(
11946 json_addr,
11947 "privateAsNumsAllReplacedInUpdatesToNbr");
11948 else if (CHECK_FLAG(p->af_flags[afi][safi],
11949 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11950 json_object_boolean_true_add(
11951 json_addr,
11952 "privateAsNumsReplacedInUpdatesToNbr");
11953 else if (CHECK_FLAG(p->af_flags[afi][safi],
11954 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11955 json_object_boolean_true_add(
11956 json_addr,
11957 "privateAsNumsAllRemovedInUpdatesToNbr");
11958 else if (CHECK_FLAG(p->af_flags[afi][safi],
11959 PEER_FLAG_REMOVE_PRIVATE_AS))
11960 json_object_boolean_true_add(
11961 json_addr,
11962 "privateAsNumsRemovedInUpdatesToNbr");
11963
11964 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11965 json_object_boolean_true_add(
11966 json_addr,
11967 bgp_addpath_names(p->addpath_type[afi][safi])
11968 ->type_json_name);
11969
11970 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11971 json_object_string_add(json_addr,
11972 "overrideASNsInOutboundUpdates",
11973 "ifAspathEqualRemoteAs");
11974
11975 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11976 || CHECK_FLAG(p->af_flags[afi][safi],
11977 PEER_FLAG_FORCE_NEXTHOP_SELF))
11978 json_object_boolean_true_add(json_addr,
11979 "routerAlwaysNextHop");
11980 if (CHECK_FLAG(p->af_flags[afi][safi],
11981 PEER_FLAG_AS_PATH_UNCHANGED))
11982 json_object_boolean_true_add(
11983 json_addr, "unchangedAsPathPropogatedToNbr");
11984 if (CHECK_FLAG(p->af_flags[afi][safi],
11985 PEER_FLAG_NEXTHOP_UNCHANGED))
11986 json_object_boolean_true_add(
11987 json_addr, "unchangedNextHopPropogatedToNbr");
11988 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11989 json_object_boolean_true_add(
11990 json_addr, "unchangedMedPropogatedToNbr");
11991 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11992 || CHECK_FLAG(p->af_flags[afi][safi],
11993 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11994 if (CHECK_FLAG(p->af_flags[afi][safi],
11995 PEER_FLAG_SEND_COMMUNITY)
11996 && CHECK_FLAG(p->af_flags[afi][safi],
11997 PEER_FLAG_SEND_EXT_COMMUNITY))
11998 json_object_string_add(json_addr,
11999 "commAttriSentToNbr",
12000 "extendedAndStandard");
12001 else if (CHECK_FLAG(p->af_flags[afi][safi],
12002 PEER_FLAG_SEND_EXT_COMMUNITY))
12003 json_object_string_add(json_addr,
12004 "commAttriSentToNbr",
12005 "extended");
12006 else
12007 json_object_string_add(json_addr,
12008 "commAttriSentToNbr",
12009 "standard");
12010 }
12011 if (CHECK_FLAG(p->af_flags[afi][safi],
12012 PEER_FLAG_DEFAULT_ORIGINATE)) {
12013 if (p->default_rmap[afi][safi].name)
12014 json_object_string_add(
12015 json_addr, "defaultRouteMap",
12016 p->default_rmap[afi][safi].name);
12017
12018 if (paf && PAF_SUBGRP(paf)
12019 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12020 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12021 json_object_boolean_true_add(json_addr,
12022 "defaultSent");
12023 else
12024 json_object_boolean_true_add(json_addr,
12025 "defaultNotSent");
12026 }
12027
12028 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12029 if (is_evpn_enabled())
12030 json_object_boolean_true_add(
12031 json_addr, "advertiseAllVnis");
12032 }
12033
12034 if (filter->plist[FILTER_IN].name
12035 || filter->dlist[FILTER_IN].name
12036 || filter->aslist[FILTER_IN].name
12037 || filter->map[RMAP_IN].name)
12038 json_object_boolean_true_add(json_addr,
12039 "inboundPathPolicyConfig");
12040 if (filter->plist[FILTER_OUT].name
12041 || filter->dlist[FILTER_OUT].name
12042 || filter->aslist[FILTER_OUT].name
12043 || filter->map[RMAP_OUT].name || filter->usmap.name)
12044 json_object_boolean_true_add(
12045 json_addr, "outboundPathPolicyConfig");
12046
12047 /* prefix-list */
12048 if (filter->plist[FILTER_IN].name)
12049 json_object_string_add(json_addr,
12050 "incomingUpdatePrefixFilterList",
12051 filter->plist[FILTER_IN].name);
12052 if (filter->plist[FILTER_OUT].name)
12053 json_object_string_add(json_addr,
12054 "outgoingUpdatePrefixFilterList",
12055 filter->plist[FILTER_OUT].name);
12056
12057 /* distribute-list */
12058 if (filter->dlist[FILTER_IN].name)
12059 json_object_string_add(
12060 json_addr, "incomingUpdateNetworkFilterList",
12061 filter->dlist[FILTER_IN].name);
12062 if (filter->dlist[FILTER_OUT].name)
12063 json_object_string_add(
12064 json_addr, "outgoingUpdateNetworkFilterList",
12065 filter->dlist[FILTER_OUT].name);
12066
12067 /* filter-list. */
12068 if (filter->aslist[FILTER_IN].name)
12069 json_object_string_add(json_addr,
12070 "incomingUpdateAsPathFilterList",
12071 filter->aslist[FILTER_IN].name);
12072 if (filter->aslist[FILTER_OUT].name)
12073 json_object_string_add(json_addr,
12074 "outgoingUpdateAsPathFilterList",
12075 filter->aslist[FILTER_OUT].name);
12076
12077 /* route-map. */
12078 if (filter->map[RMAP_IN].name)
12079 json_object_string_add(
12080 json_addr, "routeMapForIncomingAdvertisements",
12081 filter->map[RMAP_IN].name);
12082 if (filter->map[RMAP_OUT].name)
12083 json_object_string_add(
12084 json_addr, "routeMapForOutgoingAdvertisements",
12085 filter->map[RMAP_OUT].name);
12086
12087 /* ebgp-requires-policy (inbound) */
12088 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12089 && !bgp_inbound_policy_exists(p, filter))
12090 json_object_string_add(
12091 json_addr, "inboundEbgpRequiresPolicy",
12092 "Inbound updates discarded due to missing policy");
12093
12094 /* ebgp-requires-policy (outbound) */
12095 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12096 && (!bgp_outbound_policy_exists(p, filter)))
12097 json_object_string_add(
12098 json_addr, "outboundEbgpRequiresPolicy",
12099 "Outbound updates discarded due to missing policy");
12100
12101 /* unsuppress-map */
12102 if (filter->usmap.name)
12103 json_object_string_add(json_addr,
12104 "selectiveUnsuppressRouteMap",
12105 filter->usmap.name);
12106
12107 /* advertise-map */
12108 if (filter->advmap.aname) {
12109 json_advmap = json_object_new_object();
12110 json_object_string_add(json_advmap, "condition",
12111 filter->advmap.condition
12112 ? "EXIST"
12113 : "NON_EXIST");
12114 json_object_string_add(json_advmap, "conditionMap",
12115 filter->advmap.cname);
12116 json_object_string_add(json_advmap, "advertiseMap",
12117 filter->advmap.aname);
12118 json_object_string_add(
12119 json_advmap, "advertiseStatus",
12120 filter->advmap.update_type ==
12121 UPDATE_TYPE_ADVERTISE
12122 ? "Advertise"
12123 : "Withdraw");
12124 json_object_object_add(json_addr, "advertiseMap",
12125 json_advmap);
12126 }
12127
12128 /* Receive prefix count */
12129 json_object_int_add(json_addr, "acceptedPrefixCounter",
12130 p->pcount[afi][safi]);
12131 if (paf && PAF_SUBGRP(paf))
12132 json_object_int_add(json_addr, "sentPrefixCounter",
12133 (PAF_SUBGRP(paf))->scount);
12134
12135 /* Maximum prefix */
12136 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12137 json_object_int_add(json_addr, "prefixOutAllowedMax",
12138 p->pmax_out[afi][safi]);
12139
12140 /* Maximum prefix */
12141 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12142 json_object_int_add(json_addr, "prefixAllowedMax",
12143 p->pmax[afi][safi]);
12144 if (CHECK_FLAG(p->af_flags[afi][safi],
12145 PEER_FLAG_MAX_PREFIX_WARNING))
12146 json_object_boolean_true_add(
12147 json_addr, "prefixAllowedMaxWarning");
12148 json_object_int_add(json_addr,
12149 "prefixAllowedWarningThresh",
12150 p->pmax_threshold[afi][safi]);
12151 if (p->pmax_restart[afi][safi])
12152 json_object_int_add(
12153 json_addr,
12154 "prefixAllowedRestartIntervalMsecs",
12155 p->pmax_restart[afi][safi] * 60000);
12156 }
12157 json_object_object_add(json_neigh,
12158 get_afi_safi_str(afi, safi, true),
12159 json_addr);
12160
12161 } else {
12162 filter = &p->filter[afi][safi];
12163
12164 vty_out(vty, " For address family: %s\n",
12165 get_afi_safi_str(afi, safi, false));
12166
12167 if (peer_group_active(p))
12168 vty_out(vty, " %s peer-group member\n",
12169 p->group->name);
12170
12171 paf = peer_af_find(p, afi, safi);
12172 if (paf && PAF_SUBGRP(paf)) {
12173 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12174 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12175 vty_out(vty, " Packet Queue length %d\n",
12176 bpacket_queue_virtual_length(paf));
12177 } else {
12178 vty_out(vty, " Not part of any update group\n");
12179 }
12180 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12181 || CHECK_FLAG(p->af_cap[afi][safi],
12182 PEER_CAP_ORF_PREFIX_SM_RCV)
12183 || CHECK_FLAG(p->af_cap[afi][safi],
12184 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12185 || CHECK_FLAG(p->af_cap[afi][safi],
12186 PEER_CAP_ORF_PREFIX_RM_ADV)
12187 || CHECK_FLAG(p->af_cap[afi][safi],
12188 PEER_CAP_ORF_PREFIX_RM_RCV)
12189 || CHECK_FLAG(p->af_cap[afi][safi],
12190 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12191 vty_out(vty, " AF-dependant capabilities:\n");
12192
12193 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12194 || CHECK_FLAG(p->af_cap[afi][safi],
12195 PEER_CAP_ORF_PREFIX_SM_RCV)
12196 || CHECK_FLAG(p->af_cap[afi][safi],
12197 PEER_CAP_ORF_PREFIX_RM_ADV)
12198 || CHECK_FLAG(p->af_cap[afi][safi],
12199 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12200 vty_out(vty,
12201 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12202 ORF_TYPE_PREFIX);
12203 bgp_show_peer_afi_orf_cap(
12204 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12205 PEER_CAP_ORF_PREFIX_RM_ADV,
12206 PEER_CAP_ORF_PREFIX_SM_RCV,
12207 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12208 }
12209 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12210 || CHECK_FLAG(p->af_cap[afi][safi],
12211 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12212 || CHECK_FLAG(p->af_cap[afi][safi],
12213 PEER_CAP_ORF_PREFIX_RM_ADV)
12214 || CHECK_FLAG(p->af_cap[afi][safi],
12215 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12216 vty_out(vty,
12217 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12218 ORF_TYPE_PREFIX_OLD);
12219 bgp_show_peer_afi_orf_cap(
12220 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12221 PEER_CAP_ORF_PREFIX_RM_ADV,
12222 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12223 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12224 }
12225
12226 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12227 p->host, afi, safi);
12228 orf_pfx_count = prefix_bgp_show_prefix_list(
12229 NULL, afi, orf_pfx_name, use_json);
12230
12231 if (CHECK_FLAG(p->af_sflags[afi][safi],
12232 PEER_STATUS_ORF_PREFIX_SEND)
12233 || orf_pfx_count) {
12234 vty_out(vty, " Outbound Route Filter (ORF):");
12235 if (CHECK_FLAG(p->af_sflags[afi][safi],
12236 PEER_STATUS_ORF_PREFIX_SEND))
12237 vty_out(vty, " sent;");
12238 if (orf_pfx_count)
12239 vty_out(vty, " received (%d entries)",
12240 orf_pfx_count);
12241 vty_out(vty, "\n");
12242 }
12243 if (CHECK_FLAG(p->af_sflags[afi][safi],
12244 PEER_STATUS_ORF_WAIT_REFRESH))
12245 vty_out(vty,
12246 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12247
12248 if (CHECK_FLAG(p->af_flags[afi][safi],
12249 PEER_FLAG_REFLECTOR_CLIENT))
12250 vty_out(vty, " Route-Reflector Client\n");
12251 if (CHECK_FLAG(p->af_flags[afi][safi],
12252 PEER_FLAG_RSERVER_CLIENT))
12253 vty_out(vty, " Route-Server Client\n");
12254 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12255 vty_out(vty,
12256 " Inbound soft reconfiguration allowed\n");
12257
12258 if (CHECK_FLAG(p->af_flags[afi][safi],
12259 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12260 vty_out(vty,
12261 " Private AS numbers (all) replaced in updates to this neighbor\n");
12262 else if (CHECK_FLAG(p->af_flags[afi][safi],
12263 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12264 vty_out(vty,
12265 " Private AS numbers replaced in updates to this neighbor\n");
12266 else if (CHECK_FLAG(p->af_flags[afi][safi],
12267 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12268 vty_out(vty,
12269 " Private AS numbers (all) removed in updates to this neighbor\n");
12270 else if (CHECK_FLAG(p->af_flags[afi][safi],
12271 PEER_FLAG_REMOVE_PRIVATE_AS))
12272 vty_out(vty,
12273 " Private AS numbers removed in updates to this neighbor\n");
12274
12275 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12276 vty_out(vty, " %s\n",
12277 bgp_addpath_names(p->addpath_type[afi][safi])
12278 ->human_description);
12279
12280 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12281 vty_out(vty,
12282 " Override ASNs in outbound updates if aspath equals remote-as\n");
12283
12284 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12285 || CHECK_FLAG(p->af_flags[afi][safi],
12286 PEER_FLAG_FORCE_NEXTHOP_SELF))
12287 vty_out(vty, " NEXT_HOP is always this router\n");
12288 if (CHECK_FLAG(p->af_flags[afi][safi],
12289 PEER_FLAG_AS_PATH_UNCHANGED))
12290 vty_out(vty,
12291 " AS_PATH is propagated unchanged to this neighbor\n");
12292 if (CHECK_FLAG(p->af_flags[afi][safi],
12293 PEER_FLAG_NEXTHOP_UNCHANGED))
12294 vty_out(vty,
12295 " NEXT_HOP is propagated unchanged to this neighbor\n");
12296 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12297 vty_out(vty,
12298 " MED is propagated unchanged to this neighbor\n");
12299 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12300 || CHECK_FLAG(p->af_flags[afi][safi],
12301 PEER_FLAG_SEND_EXT_COMMUNITY)
12302 || CHECK_FLAG(p->af_flags[afi][safi],
12303 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12304 vty_out(vty,
12305 " Community attribute sent to this neighbor");
12306 if (CHECK_FLAG(p->af_flags[afi][safi],
12307 PEER_FLAG_SEND_COMMUNITY)
12308 && CHECK_FLAG(p->af_flags[afi][safi],
12309 PEER_FLAG_SEND_EXT_COMMUNITY)
12310 && CHECK_FLAG(p->af_flags[afi][safi],
12311 PEER_FLAG_SEND_LARGE_COMMUNITY))
12312 vty_out(vty, "(all)\n");
12313 else if (CHECK_FLAG(p->af_flags[afi][safi],
12314 PEER_FLAG_SEND_LARGE_COMMUNITY))
12315 vty_out(vty, "(large)\n");
12316 else if (CHECK_FLAG(p->af_flags[afi][safi],
12317 PEER_FLAG_SEND_EXT_COMMUNITY))
12318 vty_out(vty, "(extended)\n");
12319 else
12320 vty_out(vty, "(standard)\n");
12321 }
12322 if (CHECK_FLAG(p->af_flags[afi][safi],
12323 PEER_FLAG_DEFAULT_ORIGINATE)) {
12324 vty_out(vty, " Default information originate,");
12325
12326 if (p->default_rmap[afi][safi].name)
12327 vty_out(vty, " default route-map %s%s,",
12328 p->default_rmap[afi][safi].map ? "*"
12329 : "",
12330 p->default_rmap[afi][safi].name);
12331 if (paf && PAF_SUBGRP(paf)
12332 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12333 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12334 vty_out(vty, " default sent\n");
12335 else
12336 vty_out(vty, " default not sent\n");
12337 }
12338
12339 /* advertise-vni-all */
12340 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12341 if (is_evpn_enabled())
12342 vty_out(vty, " advertise-all-vni\n");
12343 }
12344
12345 if (filter->plist[FILTER_IN].name
12346 || filter->dlist[FILTER_IN].name
12347 || filter->aslist[FILTER_IN].name
12348 || filter->map[RMAP_IN].name)
12349 vty_out(vty, " Inbound path policy configured\n");
12350 if (filter->plist[FILTER_OUT].name
12351 || filter->dlist[FILTER_OUT].name
12352 || filter->aslist[FILTER_OUT].name
12353 || filter->map[RMAP_OUT].name || filter->usmap.name)
12354 vty_out(vty, " Outbound path policy configured\n");
12355
12356 /* prefix-list */
12357 if (filter->plist[FILTER_IN].name)
12358 vty_out(vty,
12359 " Incoming update prefix filter list is %s%s\n",
12360 filter->plist[FILTER_IN].plist ? "*" : "",
12361 filter->plist[FILTER_IN].name);
12362 if (filter->plist[FILTER_OUT].name)
12363 vty_out(vty,
12364 " Outgoing update prefix filter list is %s%s\n",
12365 filter->plist[FILTER_OUT].plist ? "*" : "",
12366 filter->plist[FILTER_OUT].name);
12367
12368 /* distribute-list */
12369 if (filter->dlist[FILTER_IN].name)
12370 vty_out(vty,
12371 " Incoming update network filter list is %s%s\n",
12372 filter->dlist[FILTER_IN].alist ? "*" : "",
12373 filter->dlist[FILTER_IN].name);
12374 if (filter->dlist[FILTER_OUT].name)
12375 vty_out(vty,
12376 " Outgoing update network filter list is %s%s\n",
12377 filter->dlist[FILTER_OUT].alist ? "*" : "",
12378 filter->dlist[FILTER_OUT].name);
12379
12380 /* filter-list. */
12381 if (filter->aslist[FILTER_IN].name)
12382 vty_out(vty,
12383 " Incoming update AS path filter list is %s%s\n",
12384 filter->aslist[FILTER_IN].aslist ? "*" : "",
12385 filter->aslist[FILTER_IN].name);
12386 if (filter->aslist[FILTER_OUT].name)
12387 vty_out(vty,
12388 " Outgoing update AS path filter list is %s%s\n",
12389 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12390 filter->aslist[FILTER_OUT].name);
12391
12392 /* route-map. */
12393 if (filter->map[RMAP_IN].name)
12394 vty_out(vty,
12395 " Route map for incoming advertisements is %s%s\n",
12396 filter->map[RMAP_IN].map ? "*" : "",
12397 filter->map[RMAP_IN].name);
12398 if (filter->map[RMAP_OUT].name)
12399 vty_out(vty,
12400 " Route map for outgoing advertisements is %s%s\n",
12401 filter->map[RMAP_OUT].map ? "*" : "",
12402 filter->map[RMAP_OUT].name);
12403
12404 /* ebgp-requires-policy (inbound) */
12405 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12406 && !bgp_inbound_policy_exists(p, filter))
12407 vty_out(vty,
12408 " Inbound updates discarded due to missing policy\n");
12409
12410 /* ebgp-requires-policy (outbound) */
12411 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12412 && !bgp_outbound_policy_exists(p, filter))
12413 vty_out(vty,
12414 " Outbound updates discarded due to missing policy\n");
12415
12416 /* unsuppress-map */
12417 if (filter->usmap.name)
12418 vty_out(vty,
12419 " Route map for selective unsuppress is %s%s\n",
12420 filter->usmap.map ? "*" : "",
12421 filter->usmap.name);
12422
12423 /* advertise-map */
12424 if (filter->advmap.aname && filter->advmap.cname)
12425 vty_out(vty,
12426 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12427 filter->advmap.condition ? "EXIST"
12428 : "NON_EXIST",
12429 filter->advmap.cmap ? "*" : "",
12430 filter->advmap.cname,
12431 filter->advmap.amap ? "*" : "",
12432 filter->advmap.aname,
12433 filter->advmap.update_type ==
12434 UPDATE_TYPE_ADVERTISE
12435 ? "Advertise"
12436 : "Withdraw");
12437
12438 /* Receive prefix count */
12439 vty_out(vty, " %u accepted prefixes\n",
12440 p->pcount[afi][safi]);
12441
12442 /* maximum-prefix-out */
12443 if (CHECK_FLAG(p->af_flags[afi][safi],
12444 PEER_FLAG_MAX_PREFIX_OUT))
12445 vty_out(vty,
12446 " Maximum allowed prefixes sent %u\n",
12447 p->pmax_out[afi][safi]);
12448
12449 /* Maximum prefix */
12450 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12451 vty_out(vty,
12452 " Maximum prefixes allowed %u%s\n",
12453 p->pmax[afi][safi],
12454 CHECK_FLAG(p->af_flags[afi][safi],
12455 PEER_FLAG_MAX_PREFIX_WARNING)
12456 ? " (warning-only)"
12457 : "");
12458 vty_out(vty, " Threshold for warning message %d%%",
12459 p->pmax_threshold[afi][safi]);
12460 if (p->pmax_restart[afi][safi])
12461 vty_out(vty, ", restart interval %d min",
12462 p->pmax_restart[afi][safi]);
12463 vty_out(vty, "\n");
12464 }
12465
12466 vty_out(vty, "\n");
12467 }
12468 }
12469
12470 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12471 json_object *json)
12472 {
12473 struct bgp *bgp;
12474 char buf1[PREFIX2STR_BUFFER];
12475 char timebuf[BGP_UPTIME_LEN];
12476 char dn_flag[2];
12477 afi_t afi;
12478 safi_t safi;
12479 uint16_t i;
12480 uint8_t *msg;
12481 json_object *json_neigh = NULL;
12482 time_t epoch_tbuf;
12483 uint32_t sync_tcp_mss;
12484
12485 bgp = p->bgp;
12486
12487 if (use_json)
12488 json_neigh = json_object_new_object();
12489
12490 memset(dn_flag, '\0', sizeof(dn_flag));
12491 if (!p->conf_if && peer_dynamic_neighbor(p))
12492 dn_flag[0] = '*';
12493
12494 if (!use_json) {
12495 if (p->conf_if) /* Configured interface name. */
12496 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12497 &p->su);
12498 else /* Configured IP address. */
12499 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12500 p->host);
12501 }
12502
12503 if (use_json) {
12504 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12505 json_object_string_add(json_neigh, "bgpNeighborAddr",
12506 "none");
12507 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12508 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12509 "%pSU", &p->su);
12510
12511 json_object_int_add(json_neigh, "remoteAs", p->as);
12512
12513 if (p->change_local_as)
12514 json_object_int_add(json_neigh, "localAs",
12515 p->change_local_as);
12516 else
12517 json_object_int_add(json_neigh, "localAs", p->local_as);
12518
12519 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12520 json_object_boolean_true_add(json_neigh,
12521 "localAsNoPrepend");
12522
12523 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12524 json_object_boolean_true_add(json_neigh,
12525 "localAsReplaceAs");
12526 } else {
12527 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12528 || (p->as_type == AS_INTERNAL))
12529 vty_out(vty, "remote AS %u, ", p->as);
12530 else
12531 vty_out(vty, "remote AS Unspecified, ");
12532 vty_out(vty, "local AS %u%s%s, ",
12533 p->change_local_as ? p->change_local_as : p->local_as,
12534 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12535 ? " no-prepend"
12536 : "",
12537 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12538 ? " replace-as"
12539 : "");
12540 }
12541 /* peer type internal or confed-internal */
12542 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12543 if (use_json) {
12544 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12545 json_object_boolean_true_add(
12546 json_neigh, "nbrConfedInternalLink");
12547 else
12548 json_object_boolean_true_add(json_neigh,
12549 "nbrInternalLink");
12550 } else {
12551 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12552 vty_out(vty, "confed-internal link\n");
12553 else
12554 vty_out(vty, "internal link\n");
12555 }
12556 /* peer type external or confed-external */
12557 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12558 if (use_json) {
12559 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12560 json_object_boolean_true_add(
12561 json_neigh, "nbrConfedExternalLink");
12562 else
12563 json_object_boolean_true_add(json_neigh,
12564 "nbrExternalLink");
12565 } else {
12566 if (bgp_confederation_peers_check(bgp, p->as))
12567 vty_out(vty, "confed-external link\n");
12568 else
12569 vty_out(vty, "external link\n");
12570 }
12571 } else {
12572 if (use_json)
12573 json_object_boolean_true_add(json_neigh,
12574 "nbrUnspecifiedLink");
12575 else
12576 vty_out(vty, "unspecified link\n");
12577 }
12578
12579 /* Roles */
12580 if (use_json) {
12581 json_object_string_add(json_neigh, "localRole",
12582 bgp_get_name_by_role(p->local_role));
12583 json_object_string_add(json_neigh, "remoteRole",
12584 bgp_get_name_by_role(p->remote_role));
12585 } else {
12586 vty_out(vty, " Local Role: %s\n",
12587 bgp_get_name_by_role(p->local_role));
12588 vty_out(vty, " Remote Role: %s\n",
12589 bgp_get_name_by_role(p->remote_role));
12590 }
12591
12592
12593 /* Description. */
12594 if (p->desc) {
12595 if (use_json)
12596 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12597 else
12598 vty_out(vty, " Description: %s\n", p->desc);
12599 }
12600
12601 if (p->hostname) {
12602 if (use_json) {
12603 if (p->hostname)
12604 json_object_string_add(json_neigh, "hostname",
12605 p->hostname);
12606
12607 if (p->domainname)
12608 json_object_string_add(json_neigh, "domainname",
12609 p->domainname);
12610 } else {
12611 if (p->domainname && (p->domainname[0] != '\0'))
12612 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12613 p->domainname);
12614 else
12615 vty_out(vty, "Hostname: %s\n", p->hostname);
12616 }
12617 }
12618
12619 /* Peer-group */
12620 if (p->group) {
12621 if (use_json) {
12622 json_object_string_add(json_neigh, "peerGroup",
12623 p->group->name);
12624
12625 if (dn_flag[0]) {
12626 struct prefix prefix, *range = NULL;
12627
12628 if (sockunion2hostprefix(&(p->su), &prefix))
12629 range = peer_group_lookup_dynamic_neighbor_range(
12630 p->group, &prefix);
12631
12632 if (range) {
12633 json_object_string_addf(
12634 json_neigh,
12635 "peerSubnetRangeGroup", "%pFX",
12636 range);
12637 }
12638 }
12639 } else {
12640 vty_out(vty,
12641 " Member of peer-group %s for session parameters\n",
12642 p->group->name);
12643
12644 if (dn_flag[0]) {
12645 struct prefix prefix, *range = NULL;
12646
12647 if (sockunion2hostprefix(&(p->su), &prefix))
12648 range = peer_group_lookup_dynamic_neighbor_range(
12649 p->group, &prefix);
12650
12651 if (range) {
12652 vty_out(vty,
12653 " Belongs to the subnet range group: %pFX\n",
12654 range);
12655 }
12656 }
12657 }
12658 }
12659
12660 if (use_json) {
12661 /* Administrative shutdown. */
12662 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12663 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12664 json_object_boolean_true_add(json_neigh,
12665 "adminShutDown");
12666
12667 /* BGP Version. */
12668 json_object_int_add(json_neigh, "bgpVersion", 4);
12669 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12670 &p->remote_id);
12671 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12672 &bgp->router_id);
12673
12674 /* Confederation */
12675 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12676 && bgp_confederation_peers_check(bgp, p->as))
12677 json_object_boolean_true_add(json_neigh,
12678 "nbrCommonAdmin");
12679
12680 /* Status. */
12681 json_object_string_add(
12682 json_neigh, "bgpState",
12683 lookup_msg(bgp_status_msg, p->status, NULL));
12684
12685 if (peer_established(p)) {
12686 time_t uptime;
12687
12688 uptime = bgp_clock();
12689 uptime -= p->uptime;
12690 epoch_tbuf = time(NULL) - uptime;
12691
12692 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12693 uptime * 1000);
12694 json_object_string_add(json_neigh, "bgpTimerUpString",
12695 peer_uptime(p->uptime, timebuf,
12696 BGP_UPTIME_LEN, 0,
12697 NULL));
12698 json_object_int_add(json_neigh,
12699 "bgpTimerUpEstablishedEpoch",
12700 epoch_tbuf);
12701 }
12702
12703 else if (p->status == Active) {
12704 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12705 json_object_string_add(json_neigh, "bgpStateIs",
12706 "passive");
12707 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12708 json_object_string_add(json_neigh, "bgpStateIs",
12709 "passiveNSF");
12710 }
12711
12712 /* read timer */
12713 time_t uptime;
12714 struct tm tm;
12715
12716 uptime = bgp_clock();
12717 uptime -= p->readtime;
12718 gmtime_r(&uptime, &tm);
12719
12720 json_object_int_add(json_neigh, "bgpTimerLastRead",
12721 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12722 + (tm.tm_hour * 3600000));
12723
12724 uptime = bgp_clock();
12725 uptime -= p->last_write;
12726 gmtime_r(&uptime, &tm);
12727
12728 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12729 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12730 + (tm.tm_hour * 3600000));
12731
12732 uptime = bgp_clock();
12733 uptime -= p->update_time;
12734 gmtime_r(&uptime, &tm);
12735
12736 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12737 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12738 + (tm.tm_hour * 3600000));
12739
12740 /* Configured timer values. */
12741 json_object_int_add(json_neigh,
12742 "bgpTimerConfiguredHoldTimeMsecs",
12743 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12744 ? p->holdtime * 1000
12745 : bgp->default_holdtime * 1000);
12746 json_object_int_add(json_neigh,
12747 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12748 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12749 ? p->keepalive * 1000
12750 : bgp->default_keepalive * 1000);
12751 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12752 p->v_holdtime * 1000);
12753 json_object_int_add(json_neigh,
12754 "bgpTimerKeepAliveIntervalMsecs",
12755 p->v_keepalive * 1000);
12756 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12757 json_object_int_add(json_neigh,
12758 "bgpTimerDelayOpenTimeMsecs",
12759 p->v_delayopen * 1000);
12760 }
12761
12762 /* Configured and Synced tcp-mss value for peer */
12763 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12764 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12765 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12766 p->tcp_mss);
12767 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12768 sync_tcp_mss);
12769 }
12770
12771 /* Extended Optional Parameters Length for BGP OPEN Message */
12772 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12773 json_object_boolean_true_add(
12774 json_neigh, "extendedOptionalParametersLength");
12775 else
12776 json_object_boolean_false_add(
12777 json_neigh, "extendedOptionalParametersLength");
12778
12779 /* Conditional advertisements */
12780 json_object_int_add(
12781 json_neigh,
12782 "bgpTimerConfiguredConditionalAdvertisementsSec",
12783 bgp->condition_check_period);
12784 if (thread_is_scheduled(bgp->t_condition_check))
12785 json_object_int_add(
12786 json_neigh,
12787 "bgpTimerUntilConditionalAdvertisementsSec",
12788 thread_timer_remain_second(
12789 bgp->t_condition_check));
12790 } else {
12791 /* Administrative shutdown. */
12792 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12793 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12794 vty_out(vty, " Administratively shut down\n");
12795
12796 /* BGP Version. */
12797 vty_out(vty, " BGP version 4");
12798 vty_out(vty, ", remote router ID %s",
12799 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12800 vty_out(vty, ", local router ID %s\n",
12801 inet_ntop(AF_INET, &bgp->router_id, buf1,
12802 sizeof(buf1)));
12803
12804 /* Confederation */
12805 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12806 && bgp_confederation_peers_check(bgp, p->as))
12807 vty_out(vty,
12808 " Neighbor under common administration\n");
12809
12810 /* Status. */
12811 vty_out(vty, " BGP state = %s",
12812 lookup_msg(bgp_status_msg, p->status, NULL));
12813
12814 if (peer_established(p))
12815 vty_out(vty, ", up for %8s",
12816 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12817 0, NULL));
12818
12819 else if (p->status == Active) {
12820 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12821 vty_out(vty, " (passive)");
12822 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12823 vty_out(vty, " (NSF passive)");
12824 }
12825 vty_out(vty, "\n");
12826
12827 /* read timer */
12828 vty_out(vty, " Last read %s",
12829 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12830 NULL));
12831 vty_out(vty, ", Last write %s\n",
12832 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12833 NULL));
12834
12835 /* Configured timer values. */
12836 vty_out(vty,
12837 " Hold time is %d seconds, keepalive interval is %d seconds\n",
12838 p->v_holdtime, p->v_keepalive);
12839 vty_out(vty, " Configured hold time is %d seconds",
12840 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12841 ? p->holdtime
12842 : bgp->default_holdtime);
12843 vty_out(vty, ", keepalive interval is %d seconds\n",
12844 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12845 ? p->keepalive
12846 : bgp->default_keepalive);
12847 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12848 vty_out(vty,
12849 " Configured DelayOpenTime is %d seconds\n",
12850 p->delayopen);
12851
12852 /* Configured and synced tcp-mss value for peer */
12853 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12854 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12855 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12856 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12857 }
12858
12859 /* Extended Optional Parameters Length for BGP OPEN Message */
12860 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12861 vty_out(vty,
12862 " Extended Optional Parameters Length is enabled\n");
12863
12864 /* Conditional advertisements */
12865 vty_out(vty,
12866 " Configured conditional advertisements interval is %d seconds\n",
12867 bgp->condition_check_period);
12868 if (thread_is_scheduled(bgp->t_condition_check))
12869 vty_out(vty,
12870 " Time until conditional advertisements begin is %lu seconds\n",
12871 thread_timer_remain_second(
12872 bgp->t_condition_check));
12873 }
12874 /* Capability. */
12875 if (peer_established(p) &&
12876 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12877 if (use_json) {
12878 json_object *json_cap = NULL;
12879
12880 json_cap = json_object_new_object();
12881
12882 /* AS4 */
12883 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12884 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12885 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12886 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12887 json_object_string_add(
12888 json_cap, "4byteAs",
12889 "advertisedAndReceived");
12890 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12891 json_object_string_add(json_cap,
12892 "4byteAs",
12893 "advertised");
12894 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12895 json_object_string_add(json_cap,
12896 "4byteAs",
12897 "received");
12898 }
12899
12900 /* Extended Message Support */
12901 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12902 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12903 json_object_string_add(json_cap,
12904 "extendedMessage",
12905 "advertisedAndReceived");
12906 else if (CHECK_FLAG(p->cap,
12907 PEER_CAP_EXTENDED_MESSAGE_ADV))
12908 json_object_string_add(json_cap,
12909 "extendedMessage",
12910 "advertised");
12911 else if (CHECK_FLAG(p->cap,
12912 PEER_CAP_EXTENDED_MESSAGE_RCV))
12913 json_object_string_add(json_cap,
12914 "extendedMessage",
12915 "received");
12916
12917 /* AddPath */
12918 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12919 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12920 json_object *json_add = NULL;
12921 const char *print_store;
12922
12923 json_add = json_object_new_object();
12924
12925 FOREACH_AFI_SAFI (afi, safi) {
12926 json_object *json_sub = NULL;
12927 json_sub = json_object_new_object();
12928 print_store = get_afi_safi_str(
12929 afi, safi, true);
12930
12931 if (CHECK_FLAG(
12932 p->af_cap[afi][safi],
12933 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12934 CHECK_FLAG(
12935 p->af_cap[afi][safi],
12936 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12937 if (CHECK_FLAG(
12938 p->af_cap[afi]
12939 [safi],
12940 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12941 CHECK_FLAG(
12942 p->af_cap[afi]
12943 [safi],
12944 PEER_CAP_ADDPATH_AF_TX_RCV))
12945 json_object_boolean_true_add(
12946 json_sub,
12947 "txAdvertisedAndReceived");
12948 else if (
12949 CHECK_FLAG(
12950 p->af_cap[afi]
12951 [safi],
12952 PEER_CAP_ADDPATH_AF_TX_ADV))
12953 json_object_boolean_true_add(
12954 json_sub,
12955 "txAdvertised");
12956 else if (
12957 CHECK_FLAG(
12958 p->af_cap[afi]
12959 [safi],
12960 PEER_CAP_ADDPATH_AF_TX_RCV))
12961 json_object_boolean_true_add(
12962 json_sub,
12963 "txReceived");
12964 }
12965
12966 if (CHECK_FLAG(
12967 p->af_cap[afi][safi],
12968 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12969 CHECK_FLAG(
12970 p->af_cap[afi][safi],
12971 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12972 if (CHECK_FLAG(
12973 p->af_cap[afi]
12974 [safi],
12975 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12976 CHECK_FLAG(
12977 p->af_cap[afi]
12978 [safi],
12979 PEER_CAP_ADDPATH_AF_RX_RCV))
12980 json_object_boolean_true_add(
12981 json_sub,
12982 "rxAdvertisedAndReceived");
12983 else if (
12984 CHECK_FLAG(
12985 p->af_cap[afi]
12986 [safi],
12987 PEER_CAP_ADDPATH_AF_RX_ADV))
12988 json_object_boolean_true_add(
12989 json_sub,
12990 "rxAdvertised");
12991 else if (
12992 CHECK_FLAG(
12993 p->af_cap[afi]
12994 [safi],
12995 PEER_CAP_ADDPATH_AF_RX_RCV))
12996 json_object_boolean_true_add(
12997 json_sub,
12998 "rxReceived");
12999 }
13000
13001 if (CHECK_FLAG(
13002 p->af_cap[afi][safi],
13003 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13004 CHECK_FLAG(
13005 p->af_cap[afi][safi],
13006 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13007 CHECK_FLAG(
13008 p->af_cap[afi][safi],
13009 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13010 CHECK_FLAG(
13011 p->af_cap[afi][safi],
13012 PEER_CAP_ADDPATH_AF_RX_RCV))
13013 json_object_object_add(
13014 json_add, print_store,
13015 json_sub);
13016 else
13017 json_object_free(json_sub);
13018 }
13019
13020 json_object_object_add(json_cap, "addPath",
13021 json_add);
13022 }
13023
13024 /* Dynamic */
13025 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13026 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13027 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13028 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13029 json_object_string_add(
13030 json_cap, "dynamic",
13031 "advertisedAndReceived");
13032 else if (CHECK_FLAG(p->cap,
13033 PEER_CAP_DYNAMIC_ADV))
13034 json_object_string_add(json_cap,
13035 "dynamic",
13036 "advertised");
13037 else if (CHECK_FLAG(p->cap,
13038 PEER_CAP_DYNAMIC_RCV))
13039 json_object_string_add(json_cap,
13040 "dynamic",
13041 "received");
13042 }
13043
13044 /* Role */
13045 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13046 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13047 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13048 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13049 json_object_string_add(
13050 json_cap, "role",
13051 "advertisedAndReceived");
13052 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13053 json_object_string_add(json_cap, "role",
13054 "advertised");
13055 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13056 json_object_string_add(json_cap, "role",
13057 "received");
13058 }
13059
13060 /* Extended nexthop */
13061 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13062 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13063 json_object *json_nxt = NULL;
13064 const char *print_store;
13065
13066
13067 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13068 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13069 json_object_string_add(
13070 json_cap, "extendedNexthop",
13071 "advertisedAndReceived");
13072 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13073 json_object_string_add(
13074 json_cap, "extendedNexthop",
13075 "advertised");
13076 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13077 json_object_string_add(
13078 json_cap, "extendedNexthop",
13079 "received");
13080
13081 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13082 json_nxt = json_object_new_object();
13083
13084 for (safi = SAFI_UNICAST;
13085 safi < SAFI_MAX; safi++) {
13086 if (CHECK_FLAG(
13087 p->af_cap[AFI_IP]
13088 [safi],
13089 PEER_CAP_ENHE_AF_RCV)) {
13090 print_store =
13091 get_afi_safi_str(
13092 AFI_IP,
13093 safi,
13094 true);
13095 json_object_string_add(
13096 json_nxt,
13097 print_store,
13098 "recieved"); /* misspelled for compatibility */
13099 }
13100 }
13101 json_object_object_add(
13102 json_cap,
13103 "extendedNexthopFamililesByPeer",
13104 json_nxt);
13105 }
13106 }
13107
13108 /* Long-lived Graceful Restart */
13109 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13110 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13111 json_object *json_llgr = NULL;
13112 const char *afi_safi_str;
13113
13114 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13115 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13116 json_object_string_add(
13117 json_cap,
13118 "longLivedGracefulRestart",
13119 "advertisedAndReceived");
13120 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13121 json_object_string_add(
13122 json_cap,
13123 "longLivedGracefulRestart",
13124 "advertised");
13125 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13126 json_object_string_add(
13127 json_cap,
13128 "longLivedGracefulRestart",
13129 "received");
13130
13131 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13132 json_llgr = json_object_new_object();
13133
13134 FOREACH_AFI_SAFI (afi, safi) {
13135 if (CHECK_FLAG(
13136 p->af_cap[afi]
13137 [safi],
13138 PEER_CAP_ENHE_AF_RCV)) {
13139 afi_safi_str =
13140 get_afi_safi_str(
13141 afi,
13142 safi,
13143 true);
13144 json_object_string_add(
13145 json_llgr,
13146 afi_safi_str,
13147 "received");
13148 }
13149 }
13150 json_object_object_add(
13151 json_cap,
13152 "longLivedGracefulRestartByPeer",
13153 json_llgr);
13154 }
13155 }
13156
13157 /* Route Refresh */
13158 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13159 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13160 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13161 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13162 (CHECK_FLAG(p->cap,
13163 PEER_CAP_REFRESH_NEW_RCV) ||
13164 CHECK_FLAG(p->cap,
13165 PEER_CAP_REFRESH_OLD_RCV))) {
13166 if (CHECK_FLAG(
13167 p->cap,
13168 PEER_CAP_REFRESH_OLD_RCV) &&
13169 CHECK_FLAG(
13170 p->cap,
13171 PEER_CAP_REFRESH_NEW_RCV))
13172 json_object_string_add(
13173 json_cap,
13174 "routeRefresh",
13175 "advertisedAndReceivedOldNew");
13176 else {
13177 if (CHECK_FLAG(
13178 p->cap,
13179 PEER_CAP_REFRESH_OLD_RCV))
13180 json_object_string_add(
13181 json_cap,
13182 "routeRefresh",
13183 "advertisedAndReceivedOld");
13184 else
13185 json_object_string_add(
13186 json_cap,
13187 "routeRefresh",
13188 "advertisedAndReceivedNew");
13189 }
13190 } else if (CHECK_FLAG(p->cap,
13191 PEER_CAP_REFRESH_ADV))
13192 json_object_string_add(json_cap,
13193 "routeRefresh",
13194 "advertised");
13195 else if (CHECK_FLAG(p->cap,
13196 PEER_CAP_REFRESH_NEW_RCV) ||
13197 CHECK_FLAG(p->cap,
13198 PEER_CAP_REFRESH_OLD_RCV))
13199 json_object_string_add(json_cap,
13200 "routeRefresh",
13201 "received");
13202 }
13203
13204 /* Enhanced Route Refresh */
13205 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13206 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13207 if (CHECK_FLAG(p->cap,
13208 PEER_CAP_ENHANCED_RR_ADV) &&
13209 CHECK_FLAG(p->cap,
13210 PEER_CAP_ENHANCED_RR_RCV))
13211 json_object_string_add(
13212 json_cap,
13213 "enhancedRouteRefresh",
13214 "advertisedAndReceived");
13215 else if (CHECK_FLAG(p->cap,
13216 PEER_CAP_ENHANCED_RR_ADV))
13217 json_object_string_add(
13218 json_cap,
13219 "enhancedRouteRefresh",
13220 "advertised");
13221 else if (CHECK_FLAG(p->cap,
13222 PEER_CAP_ENHANCED_RR_RCV))
13223 json_object_string_add(
13224 json_cap,
13225 "enhancedRouteRefresh",
13226 "received");
13227 }
13228
13229 /* Multiprotocol Extensions */
13230 json_object *json_multi = NULL;
13231
13232 json_multi = json_object_new_object();
13233
13234 FOREACH_AFI_SAFI (afi, safi) {
13235 if (p->afc_adv[afi][safi] ||
13236 p->afc_recv[afi][safi]) {
13237 json_object *json_exten = NULL;
13238 json_exten = json_object_new_object();
13239
13240 if (p->afc_adv[afi][safi] &&
13241 p->afc_recv[afi][safi])
13242 json_object_boolean_true_add(
13243 json_exten,
13244 "advertisedAndReceived");
13245 else if (p->afc_adv[afi][safi])
13246 json_object_boolean_true_add(
13247 json_exten,
13248 "advertised");
13249 else if (p->afc_recv[afi][safi])
13250 json_object_boolean_true_add(
13251 json_exten, "received");
13252
13253 json_object_object_add(
13254 json_multi,
13255 get_afi_safi_str(afi, safi,
13256 true),
13257 json_exten);
13258 }
13259 }
13260 json_object_object_add(json_cap,
13261 "multiprotocolExtensions",
13262 json_multi);
13263
13264 /* Hostname capabilities */
13265 json_object *json_hname = NULL;
13266
13267 json_hname = json_object_new_object();
13268
13269 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13270 json_object_string_add(
13271 json_hname, "advHostName",
13272 bgp->peer_self->hostname
13273 ? bgp->peer_self->hostname
13274 : "n/a");
13275 json_object_string_add(
13276 json_hname, "advDomainName",
13277 bgp->peer_self->domainname
13278 ? bgp->peer_self->domainname
13279 : "n/a");
13280 }
13281
13282
13283 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13284 json_object_string_add(
13285 json_hname, "rcvHostName",
13286 p->hostname ? p->hostname : "n/a");
13287 json_object_string_add(
13288 json_hname, "rcvDomainName",
13289 p->domainname ? p->domainname : "n/a");
13290 }
13291
13292 json_object_object_add(json_cap, "hostName",
13293 json_hname);
13294
13295 /* Graceful Restart */
13296 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13297 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13298 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13299 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13300 json_object_string_add(
13301 json_cap, "gracefulRestart",
13302 "advertisedAndReceived");
13303 else if (CHECK_FLAG(p->cap,
13304 PEER_CAP_RESTART_ADV))
13305 json_object_string_add(
13306 json_cap,
13307 "gracefulRestartCapability",
13308 "advertised");
13309 else if (CHECK_FLAG(p->cap,
13310 PEER_CAP_RESTART_RCV))
13311 json_object_string_add(
13312 json_cap,
13313 "gracefulRestartCapability",
13314 "received");
13315
13316 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13317 int restart_af_count = 0;
13318 json_object *json_restart = NULL;
13319 json_restart = json_object_new_object();
13320
13321 json_object_int_add(
13322 json_cap,
13323 "gracefulRestartRemoteTimerMsecs",
13324 p->v_gr_restart * 1000);
13325
13326 FOREACH_AFI_SAFI (afi, safi) {
13327 if (CHECK_FLAG(
13328 p->af_cap[afi]
13329 [safi],
13330 PEER_CAP_RESTART_AF_RCV)) {
13331 json_object *json_sub =
13332 NULL;
13333 json_sub =
13334 json_object_new_object();
13335
13336 if (CHECK_FLAG(
13337 p->af_cap
13338 [afi]
13339 [safi],
13340 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13341 json_object_boolean_true_add(
13342 json_sub,
13343 "preserved");
13344 restart_af_count++;
13345 json_object_object_add(
13346 json_restart,
13347 get_afi_safi_str(
13348 afi,
13349 safi,
13350 true),
13351 json_sub);
13352 }
13353 }
13354 if (!restart_af_count) {
13355 json_object_string_add(
13356 json_cap,
13357 "addressFamiliesByPeer",
13358 "none");
13359 json_object_free(json_restart);
13360 } else
13361 json_object_object_add(
13362 json_cap,
13363 "addressFamiliesByPeer",
13364 json_restart);
13365 }
13366 }
13367 json_object_object_add(
13368 json_neigh, "neighborCapabilities", json_cap);
13369 } else {
13370 vty_out(vty, " Neighbor capabilities:\n");
13371
13372 /* AS4 */
13373 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13374 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13375 vty_out(vty, " 4 Byte AS:");
13376 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13377 vty_out(vty, " advertised");
13378 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13379 vty_out(vty, " %sreceived",
13380 CHECK_FLAG(p->cap,
13381 PEER_CAP_AS4_ADV)
13382 ? "and "
13383 : "");
13384 vty_out(vty, "\n");
13385 }
13386
13387 /* Extended Message Support */
13388 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13389 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13390 vty_out(vty, " Extended Message:");
13391 if (CHECK_FLAG(p->cap,
13392 PEER_CAP_EXTENDED_MESSAGE_ADV))
13393 vty_out(vty, " advertised");
13394 if (CHECK_FLAG(p->cap,
13395 PEER_CAP_EXTENDED_MESSAGE_RCV))
13396 vty_out(vty, " %sreceived",
13397 CHECK_FLAG(
13398 p->cap,
13399 PEER_CAP_EXTENDED_MESSAGE_ADV)
13400 ? "and "
13401 : "");
13402 vty_out(vty, "\n");
13403 }
13404
13405 /* AddPath */
13406 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13407 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13408 vty_out(vty, " AddPath:\n");
13409
13410 FOREACH_AFI_SAFI (afi, safi) {
13411 if (CHECK_FLAG(
13412 p->af_cap[afi][safi],
13413 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13414 CHECK_FLAG(
13415 p->af_cap[afi][safi],
13416 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13417 vty_out(vty, " %s: TX ",
13418 get_afi_safi_str(
13419 afi, safi,
13420 false));
13421
13422 if (CHECK_FLAG(
13423 p->af_cap[afi]
13424 [safi],
13425 PEER_CAP_ADDPATH_AF_TX_ADV))
13426 vty_out(vty,
13427 "advertised");
13428
13429 if (CHECK_FLAG(
13430 p->af_cap[afi]
13431 [safi],
13432 PEER_CAP_ADDPATH_AF_TX_RCV))
13433 vty_out(vty,
13434 "%sreceived",
13435 CHECK_FLAG(
13436 p->af_cap
13437 [afi]
13438 [safi],
13439 PEER_CAP_ADDPATH_AF_TX_ADV)
13440 ? " and "
13441 : "");
13442
13443 vty_out(vty, "\n");
13444 }
13445
13446 if (CHECK_FLAG(
13447 p->af_cap[afi][safi],
13448 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13449 CHECK_FLAG(
13450 p->af_cap[afi][safi],
13451 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13452 vty_out(vty, " %s: RX ",
13453 get_afi_safi_str(
13454 afi, safi,
13455 false));
13456
13457 if (CHECK_FLAG(
13458 p->af_cap[afi]
13459 [safi],
13460 PEER_CAP_ADDPATH_AF_RX_ADV))
13461 vty_out(vty,
13462 "advertised");
13463
13464 if (CHECK_FLAG(
13465 p->af_cap[afi]
13466 [safi],
13467 PEER_CAP_ADDPATH_AF_RX_RCV))
13468 vty_out(vty,
13469 "%sreceived",
13470 CHECK_FLAG(
13471 p->af_cap
13472 [afi]
13473 [safi],
13474 PEER_CAP_ADDPATH_AF_RX_ADV)
13475 ? " and "
13476 : "");
13477
13478 vty_out(vty, "\n");
13479 }
13480 }
13481 }
13482
13483 /* Dynamic */
13484 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13485 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13486 vty_out(vty, " Dynamic:");
13487 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13488 vty_out(vty, " advertised");
13489 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13490 vty_out(vty, " %sreceived",
13491 CHECK_FLAG(p->cap,
13492 PEER_CAP_DYNAMIC_ADV)
13493 ? "and "
13494 : "");
13495 vty_out(vty, "\n");
13496 }
13497
13498 /* Role */
13499 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13500 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13501 vty_out(vty, " Role:");
13502 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13503 vty_out(vty, " advertised");
13504 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13505 vty_out(vty, " %sreceived",
13506 CHECK_FLAG(p->cap,
13507 PEER_CAP_ROLE_ADV)
13508 ? "and "
13509 : "");
13510 vty_out(vty, "\n");
13511 }
13512
13513 /* Extended nexthop */
13514 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13515 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13516 vty_out(vty, " Extended nexthop:");
13517 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13518 vty_out(vty, " advertised");
13519 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13520 vty_out(vty, " %sreceived",
13521 CHECK_FLAG(p->cap,
13522 PEER_CAP_ENHE_ADV)
13523 ? "and "
13524 : "");
13525 vty_out(vty, "\n");
13526
13527 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13528 vty_out(vty,
13529 " Address families by peer:\n ");
13530 for (safi = SAFI_UNICAST;
13531 safi < SAFI_MAX; safi++)
13532 if (CHECK_FLAG(
13533 p->af_cap[AFI_IP]
13534 [safi],
13535 PEER_CAP_ENHE_AF_RCV))
13536 vty_out(vty,
13537 " %s\n",
13538 get_afi_safi_str(
13539 AFI_IP,
13540 safi,
13541 false));
13542 }
13543 }
13544
13545 /* Long-lived Graceful Restart */
13546 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13547 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13548 vty_out(vty,
13549 " Long-lived Graceful Restart:");
13550 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13551 vty_out(vty, " advertised");
13552 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13553 vty_out(vty, " %sreceived",
13554 CHECK_FLAG(p->cap,
13555 PEER_CAP_LLGR_ADV)
13556 ? "and "
13557 : "");
13558 vty_out(vty, "\n");
13559
13560 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13561 vty_out(vty,
13562 " Address families by peer:\n");
13563 FOREACH_AFI_SAFI (afi, safi)
13564 if (CHECK_FLAG(
13565 p->af_cap[afi]
13566 [safi],
13567 PEER_CAP_LLGR_AF_RCV))
13568 vty_out(vty,
13569 " %s\n",
13570 get_afi_safi_str(
13571 afi,
13572 safi,
13573 false));
13574 }
13575 }
13576
13577 /* Route Refresh */
13578 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13579 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13580 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13581 vty_out(vty, " Route refresh:");
13582 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13583 vty_out(vty, " advertised");
13584 if (CHECK_FLAG(p->cap,
13585 PEER_CAP_REFRESH_NEW_RCV) ||
13586 CHECK_FLAG(p->cap,
13587 PEER_CAP_REFRESH_OLD_RCV))
13588 vty_out(vty, " %sreceived(%s)",
13589 CHECK_FLAG(p->cap,
13590 PEER_CAP_REFRESH_ADV)
13591 ? "and "
13592 : "",
13593 (CHECK_FLAG(
13594 p->cap,
13595 PEER_CAP_REFRESH_OLD_RCV) &&
13596 CHECK_FLAG(
13597 p->cap,
13598 PEER_CAP_REFRESH_NEW_RCV))
13599 ? "old & new"
13600 : CHECK_FLAG(
13601 p->cap,
13602 PEER_CAP_REFRESH_OLD_RCV)
13603 ? "old"
13604 : "new");
13605
13606 vty_out(vty, "\n");
13607 }
13608
13609 /* Enhanced Route Refresh */
13610 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13611 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13612 vty_out(vty, " Enhanced Route Refresh:");
13613 if (CHECK_FLAG(p->cap,
13614 PEER_CAP_ENHANCED_RR_ADV))
13615 vty_out(vty, " advertised");
13616 if (CHECK_FLAG(p->cap,
13617 PEER_CAP_ENHANCED_RR_RCV))
13618 vty_out(vty, " %sreceived",
13619 CHECK_FLAG(p->cap,
13620 PEER_CAP_REFRESH_ADV)
13621 ? "and "
13622 : "");
13623 vty_out(vty, "\n");
13624 }
13625
13626 /* Multiprotocol Extensions */
13627 FOREACH_AFI_SAFI (afi, safi)
13628 if (p->afc_adv[afi][safi] ||
13629 p->afc_recv[afi][safi]) {
13630 vty_out(vty, " Address Family %s:",
13631 get_afi_safi_str(afi, safi,
13632 false));
13633 if (p->afc_adv[afi][safi])
13634 vty_out(vty, " advertised");
13635 if (p->afc_recv[afi][safi])
13636 vty_out(vty, " %sreceived",
13637 p->afc_adv[afi][safi]
13638 ? "and "
13639 : "");
13640 vty_out(vty, "\n");
13641 }
13642
13643 /* Hostname capability */
13644 vty_out(vty, " Hostname Capability:");
13645
13646 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13647 vty_out(vty,
13648 " advertised (name: %s,domain name: %s)",
13649 bgp->peer_self->hostname
13650 ? bgp->peer_self->hostname
13651 : "n/a",
13652 bgp->peer_self->domainname
13653 ? bgp->peer_self->domainname
13654 : "n/a");
13655 } else {
13656 vty_out(vty, " not advertised");
13657 }
13658
13659 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13660 vty_out(vty,
13661 " received (name: %s,domain name: %s)",
13662 p->hostname ? p->hostname : "n/a",
13663 p->domainname ? p->domainname : "n/a");
13664 } else {
13665 vty_out(vty, " not received");
13666 }
13667
13668 vty_out(vty, "\n");
13669
13670 /* Graceful Restart */
13671 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13672 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13673 vty_out(vty,
13674 " Graceful Restart Capability:");
13675 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13676 vty_out(vty, " advertised");
13677 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13678 vty_out(vty, " %sreceived",
13679 CHECK_FLAG(p->cap,
13680 PEER_CAP_RESTART_ADV)
13681 ? "and "
13682 : "");
13683 vty_out(vty, "\n");
13684
13685 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13686 int restart_af_count = 0;
13687
13688 vty_out(vty,
13689 " Remote Restart timer is %d seconds\n",
13690 p->v_gr_restart);
13691 vty_out(vty,
13692 " Address families by peer:\n ");
13693
13694 FOREACH_AFI_SAFI (afi, safi)
13695 if (CHECK_FLAG(
13696 p->af_cap[afi]
13697 [safi],
13698 PEER_CAP_RESTART_AF_RCV)) {
13699 vty_out(vty, "%s%s(%s)",
13700 restart_af_count
13701 ? ", "
13702 : "",
13703 get_afi_safi_str(
13704 afi,
13705 safi,
13706 false),
13707 CHECK_FLAG(
13708 p->af_cap
13709 [afi]
13710 [safi],
13711 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13712 ? "preserved"
13713 : "not preserved");
13714 restart_af_count++;
13715 }
13716 if (!restart_af_count)
13717 vty_out(vty, "none");
13718 vty_out(vty, "\n");
13719 }
13720 } /* Graceful Restart */
13721 }
13722 }
13723
13724 /* graceful restart information */
13725 json_object *json_grace = NULL;
13726 json_object *json_grace_send = NULL;
13727 json_object *json_grace_recv = NULL;
13728 int eor_send_af_count = 0;
13729 int eor_receive_af_count = 0;
13730
13731 if (use_json) {
13732 json_grace = json_object_new_object();
13733 json_grace_send = json_object_new_object();
13734 json_grace_recv = json_object_new_object();
13735
13736 if ((peer_established(p)) &&
13737 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13738 FOREACH_AFI_SAFI (afi, safi) {
13739 if (CHECK_FLAG(p->af_sflags[afi][safi],
13740 PEER_STATUS_EOR_SEND)) {
13741 json_object_boolean_true_add(
13742 json_grace_send,
13743 get_afi_safi_str(afi, safi,
13744 true));
13745 eor_send_af_count++;
13746 }
13747 }
13748 FOREACH_AFI_SAFI (afi, safi) {
13749 if (CHECK_FLAG(p->af_sflags[afi][safi],
13750 PEER_STATUS_EOR_RECEIVED)) {
13751 json_object_boolean_true_add(
13752 json_grace_recv,
13753 get_afi_safi_str(afi, safi,
13754 true));
13755 eor_receive_af_count++;
13756 }
13757 }
13758 }
13759 json_object_object_add(json_grace, "endOfRibSend",
13760 json_grace_send);
13761 json_object_object_add(json_grace, "endOfRibRecv",
13762 json_grace_recv);
13763
13764
13765 if (p->t_gr_restart)
13766 json_object_int_add(
13767 json_grace, "gracefulRestartTimerMsecs",
13768 thread_timer_remain_second(p->t_gr_restart) *
13769 1000);
13770
13771 if (p->t_gr_stale)
13772 json_object_int_add(
13773 json_grace, "gracefulStalepathTimerMsecs",
13774 thread_timer_remain_second(p->t_gr_stale) *
13775 1000);
13776 /* more gr info in new format */
13777 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13778 json_object_object_add(json_neigh, "gracefulRestartInfo",
13779 json_grace);
13780 } else {
13781 vty_out(vty, " Graceful restart information:\n");
13782 if ((peer_established(p)) &&
13783 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13784
13785 vty_out(vty, " End-of-RIB send: ");
13786 FOREACH_AFI_SAFI (afi, safi) {
13787 if (CHECK_FLAG(p->af_sflags[afi][safi],
13788 PEER_STATUS_EOR_SEND)) {
13789 vty_out(vty, "%s%s",
13790 eor_send_af_count ? ", " : "",
13791 get_afi_safi_str(afi, safi,
13792 false));
13793 eor_send_af_count++;
13794 }
13795 }
13796 vty_out(vty, "\n");
13797 vty_out(vty, " End-of-RIB received: ");
13798 FOREACH_AFI_SAFI (afi, safi) {
13799 if (CHECK_FLAG(p->af_sflags[afi][safi],
13800 PEER_STATUS_EOR_RECEIVED)) {
13801 vty_out(vty, "%s%s",
13802 eor_receive_af_count ? ", "
13803 : "",
13804 get_afi_safi_str(afi, safi,
13805 false));
13806 eor_receive_af_count++;
13807 }
13808 }
13809 vty_out(vty, "\n");
13810 }
13811
13812 if (p->t_gr_restart)
13813 vty_out(vty,
13814 " The remaining time of restart timer is %ld\n",
13815 thread_timer_remain_second(p->t_gr_restart));
13816
13817 if (p->t_gr_stale)
13818 vty_out(vty,
13819 " The remaining time of stalepath timer is %ld\n",
13820 thread_timer_remain_second(p->t_gr_stale));
13821
13822 /* more gr info in new format */
13823 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13824 }
13825
13826 if (use_json) {
13827 json_object *json_stat = NULL;
13828 json_stat = json_object_new_object();
13829 /* Packet counts. */
13830
13831 atomic_size_t outq_count, inq_count;
13832 outq_count = atomic_load_explicit(&p->obuf->count,
13833 memory_order_relaxed);
13834 inq_count = atomic_load_explicit(&p->ibuf->count,
13835 memory_order_relaxed);
13836
13837 json_object_int_add(json_stat, "depthInq",
13838 (unsigned long)inq_count);
13839 json_object_int_add(json_stat, "depthOutq",
13840 (unsigned long)outq_count);
13841 json_object_int_add(json_stat, "opensSent",
13842 atomic_load_explicit(&p->open_out,
13843 memory_order_relaxed));
13844 json_object_int_add(json_stat, "opensRecv",
13845 atomic_load_explicit(&p->open_in,
13846 memory_order_relaxed));
13847 json_object_int_add(json_stat, "notificationsSent",
13848 atomic_load_explicit(&p->notify_out,
13849 memory_order_relaxed));
13850 json_object_int_add(json_stat, "notificationsRecv",
13851 atomic_load_explicit(&p->notify_in,
13852 memory_order_relaxed));
13853 json_object_int_add(json_stat, "updatesSent",
13854 atomic_load_explicit(&p->update_out,
13855 memory_order_relaxed));
13856 json_object_int_add(json_stat, "updatesRecv",
13857 atomic_load_explicit(&p->update_in,
13858 memory_order_relaxed));
13859 json_object_int_add(json_stat, "keepalivesSent",
13860 atomic_load_explicit(&p->keepalive_out,
13861 memory_order_relaxed));
13862 json_object_int_add(json_stat, "keepalivesRecv",
13863 atomic_load_explicit(&p->keepalive_in,
13864 memory_order_relaxed));
13865 json_object_int_add(json_stat, "routeRefreshSent",
13866 atomic_load_explicit(&p->refresh_out,
13867 memory_order_relaxed));
13868 json_object_int_add(json_stat, "routeRefreshRecv",
13869 atomic_load_explicit(&p->refresh_in,
13870 memory_order_relaxed));
13871 json_object_int_add(json_stat, "capabilitySent",
13872 atomic_load_explicit(&p->dynamic_cap_out,
13873 memory_order_relaxed));
13874 json_object_int_add(json_stat, "capabilityRecv",
13875 atomic_load_explicit(&p->dynamic_cap_in,
13876 memory_order_relaxed));
13877 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13878 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13879 json_object_object_add(json_neigh, "messageStats", json_stat);
13880 } else {
13881 atomic_size_t outq_count, inq_count, open_out, open_in,
13882 notify_out, notify_in, update_out, update_in,
13883 keepalive_out, keepalive_in, refresh_out, refresh_in,
13884 dynamic_cap_out, dynamic_cap_in;
13885 outq_count = atomic_load_explicit(&p->obuf->count,
13886 memory_order_relaxed);
13887 inq_count = atomic_load_explicit(&p->ibuf->count,
13888 memory_order_relaxed);
13889 open_out = atomic_load_explicit(&p->open_out,
13890 memory_order_relaxed);
13891 open_in =
13892 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13893 notify_out = atomic_load_explicit(&p->notify_out,
13894 memory_order_relaxed);
13895 notify_in = atomic_load_explicit(&p->notify_in,
13896 memory_order_relaxed);
13897 update_out = atomic_load_explicit(&p->update_out,
13898 memory_order_relaxed);
13899 update_in = atomic_load_explicit(&p->update_in,
13900 memory_order_relaxed);
13901 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13902 memory_order_relaxed);
13903 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13904 memory_order_relaxed);
13905 refresh_out = atomic_load_explicit(&p->refresh_out,
13906 memory_order_relaxed);
13907 refresh_in = atomic_load_explicit(&p->refresh_in,
13908 memory_order_relaxed);
13909 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13910 memory_order_relaxed);
13911 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13912 memory_order_relaxed);
13913
13914 /* Packet counts. */
13915 vty_out(vty, " Message statistics:\n");
13916 vty_out(vty, " Inq depth is %zu\n", inq_count);
13917 vty_out(vty, " Outq depth is %zu\n", outq_count);
13918 vty_out(vty, " Sent Rcvd\n");
13919 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13920 open_in);
13921 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13922 notify_in);
13923 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13924 update_in);
13925 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13926 keepalive_in);
13927 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13928 refresh_in);
13929 vty_out(vty, " Capability: %10zu %10zu\n",
13930 dynamic_cap_out, dynamic_cap_in);
13931 vty_out(vty, " Total: %10u %10u\n",
13932 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
13933 }
13934
13935 if (use_json) {
13936 /* advertisement-interval */
13937 json_object_int_add(json_neigh,
13938 "minBtwnAdvertisementRunsTimerMsecs",
13939 p->v_routeadv * 1000);
13940
13941 /* Update-source. */
13942 if (p->update_if || p->update_source) {
13943 if (p->update_if)
13944 json_object_string_add(json_neigh,
13945 "updateSource",
13946 p->update_if);
13947 else if (p->update_source)
13948 json_object_string_addf(json_neigh,
13949 "updateSource", "%pSU",
13950 p->update_source);
13951 }
13952 } else {
13953 /* advertisement-interval */
13954 vty_out(vty,
13955 " Minimum time between advertisement runs is %d seconds\n",
13956 p->v_routeadv);
13957
13958 /* Update-source. */
13959 if (p->update_if || p->update_source) {
13960 vty_out(vty, " Update source is ");
13961 if (p->update_if)
13962 vty_out(vty, "%s", p->update_if);
13963 else if (p->update_source)
13964 vty_out(vty, "%pSU", p->update_source);
13965 vty_out(vty, "\n");
13966 }
13967
13968 vty_out(vty, "\n");
13969 }
13970
13971 /* Address Family Information */
13972 json_object *json_hold = NULL;
13973
13974 if (use_json)
13975 json_hold = json_object_new_object();
13976
13977 FOREACH_AFI_SAFI (afi, safi)
13978 if (p->afc[afi][safi])
13979 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13980 json_hold);
13981
13982 if (use_json) {
13983 json_object_object_add(json_neigh, "addressFamilyInfo",
13984 json_hold);
13985 json_object_int_add(json_neigh, "connectionsEstablished",
13986 p->established);
13987 json_object_int_add(json_neigh, "connectionsDropped",
13988 p->dropped);
13989 } else
13990 vty_out(vty, " Connections established %d; dropped %d\n",
13991 p->established, p->dropped);
13992
13993 if (!p->last_reset) {
13994 if (use_json)
13995 json_object_string_add(json_neigh, "lastReset",
13996 "never");
13997 else
13998 vty_out(vty, " Last reset never\n");
13999 } else {
14000 if (use_json) {
14001 time_t uptime;
14002 struct tm tm;
14003
14004 uptime = bgp_clock();
14005 uptime -= p->resettime;
14006 gmtime_r(&uptime, &tm);
14007
14008 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14009 (tm.tm_sec * 1000)
14010 + (tm.tm_min * 60000)
14011 + (tm.tm_hour * 3600000));
14012 bgp_show_peer_reset(NULL, p, json_neigh, true);
14013 } else {
14014 vty_out(vty, " Last reset %s, ",
14015 peer_uptime(p->resettime, timebuf,
14016 BGP_UPTIME_LEN, 0, NULL));
14017
14018 bgp_show_peer_reset(vty, p, NULL, false);
14019 if (p->last_reset_cause_size) {
14020 msg = p->last_reset_cause;
14021 vty_out(vty,
14022 " Message received that caused BGP to send a NOTIFICATION:\n ");
14023 for (i = 1; i <= p->last_reset_cause_size;
14024 i++) {
14025 vty_out(vty, "%02X", *msg++);
14026
14027 if (i != p->last_reset_cause_size) {
14028 if (i % 16 == 0) {
14029 vty_out(vty, "\n ");
14030 } else if (i % 4 == 0) {
14031 vty_out(vty, " ");
14032 }
14033 }
14034 }
14035 vty_out(vty, "\n");
14036 }
14037 }
14038 }
14039
14040 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14041 if (use_json)
14042 json_object_boolean_true_add(json_neigh,
14043 "prefixesConfigExceedMax");
14044 else
14045 vty_out(vty,
14046 " Peer had exceeded the max. no. of prefixes configured.\n");
14047
14048 if (p->t_pmax_restart) {
14049 if (use_json) {
14050 json_object_boolean_true_add(
14051 json_neigh, "reducePrefixNumFrom");
14052 json_object_int_add(json_neigh,
14053 "restartInTimerMsec",
14054 thread_timer_remain_second(
14055 p->t_pmax_restart)
14056 * 1000);
14057 } else
14058 vty_out(vty,
14059 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14060 p->host, thread_timer_remain_second(
14061 p->t_pmax_restart));
14062 } else {
14063 if (use_json)
14064 json_object_boolean_true_add(
14065 json_neigh,
14066 "reducePrefixNumAndClearIpBgp");
14067 else
14068 vty_out(vty,
14069 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14070 p->host);
14071 }
14072 }
14073
14074 /* EBGP Multihop and GTSM */
14075 if (p->sort != BGP_PEER_IBGP) {
14076 if (use_json) {
14077 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14078 json_object_int_add(json_neigh,
14079 "externalBgpNbrMaxHopsAway",
14080 p->gtsm_hops);
14081 else
14082 json_object_int_add(json_neigh,
14083 "externalBgpNbrMaxHopsAway",
14084 p->ttl);
14085 } else {
14086 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14087 vty_out(vty,
14088 " External BGP neighbor may be up to %d hops away.\n",
14089 p->gtsm_hops);
14090 else
14091 vty_out(vty,
14092 " External BGP neighbor may be up to %d hops away.\n",
14093 p->ttl);
14094 }
14095 } else {
14096 if (use_json) {
14097 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14098 json_object_int_add(json_neigh,
14099 "internalBgpNbrMaxHopsAway",
14100 p->gtsm_hops);
14101 else
14102 json_object_int_add(json_neigh,
14103 "internalBgpNbrMaxHopsAway",
14104 p->ttl);
14105 } else {
14106 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14107 vty_out(vty,
14108 " Internal BGP neighbor may be up to %d hops away.\n",
14109 p->gtsm_hops);
14110 else
14111 vty_out(vty,
14112 " Internal BGP neighbor may be up to %d hops away.\n",
14113 p->ttl);
14114 }
14115 }
14116
14117 /* Local address. */
14118 if (p->su_local) {
14119 if (use_json) {
14120 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14121 p->su_local);
14122 json_object_int_add(json_neigh, "portLocal",
14123 ntohs(p->su_local->sin.sin_port));
14124 } else
14125 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14126 p->su_local, ntohs(p->su_local->sin.sin_port));
14127 } else {
14128 if (use_json) {
14129 json_object_string_add(json_neigh, "hostLocal",
14130 "Unknown");
14131 json_object_int_add(json_neigh, "portLocal", -1);
14132 }
14133 }
14134
14135 /* Remote address. */
14136 if (p->su_remote) {
14137 if (use_json) {
14138 json_object_string_addf(json_neigh, "hostForeign",
14139 "%pSU", p->su_remote);
14140 json_object_int_add(json_neigh, "portForeign",
14141 ntohs(p->su_remote->sin.sin_port));
14142 } else
14143 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14144 p->su_remote,
14145 ntohs(p->su_remote->sin.sin_port));
14146 } else {
14147 if (use_json) {
14148 json_object_string_add(json_neigh, "hostForeign",
14149 "Unknown");
14150 json_object_int_add(json_neigh, "portForeign", -1);
14151 }
14152 }
14153
14154 /* Nexthop display. */
14155 if (p->su_local) {
14156 if (use_json) {
14157 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14158 &p->nexthop.v4);
14159 json_object_string_addf(json_neigh, "nexthopGlobal",
14160 "%pI6", &p->nexthop.v6_global);
14161 json_object_string_addf(json_neigh, "nexthopLocal",
14162 "%pI6", &p->nexthop.v6_local);
14163 if (p->shared_network)
14164 json_object_string_add(json_neigh,
14165 "bgpConnection",
14166 "sharedNetwork");
14167 else
14168 json_object_string_add(json_neigh,
14169 "bgpConnection",
14170 "nonSharedNetwork");
14171 } else {
14172 vty_out(vty, "Nexthop: %s\n",
14173 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14174 sizeof(buf1)));
14175 vty_out(vty, "Nexthop global: %s\n",
14176 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14177 sizeof(buf1)));
14178 vty_out(vty, "Nexthop local: %s\n",
14179 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14180 sizeof(buf1)));
14181 vty_out(vty, "BGP connection: %s\n",
14182 p->shared_network ? "shared network"
14183 : "non shared network");
14184 }
14185 }
14186
14187 /* Timer information. */
14188 if (use_json) {
14189 json_object_int_add(json_neigh, "connectRetryTimer",
14190 p->v_connect);
14191 if (peer_established(p) && p->rtt)
14192 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14193 p->rtt);
14194 if (p->t_start)
14195 json_object_int_add(
14196 json_neigh, "nextStartTimerDueInMsecs",
14197 thread_timer_remain_second(p->t_start) * 1000);
14198 if (p->t_connect)
14199 json_object_int_add(
14200 json_neigh, "nextConnectTimerDueInMsecs",
14201 thread_timer_remain_second(p->t_connect)
14202 * 1000);
14203 if (p->t_routeadv) {
14204 json_object_int_add(json_neigh, "mraiInterval",
14205 p->v_routeadv);
14206 json_object_int_add(
14207 json_neigh, "mraiTimerExpireInMsecs",
14208 thread_timer_remain_second(p->t_routeadv)
14209 * 1000);
14210 }
14211 if (p->password)
14212 json_object_int_add(json_neigh, "authenticationEnabled",
14213 1);
14214
14215 if (p->t_read)
14216 json_object_string_add(json_neigh, "readThread", "on");
14217 else
14218 json_object_string_add(json_neigh, "readThread", "off");
14219
14220 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14221 json_object_string_add(json_neigh, "writeThread", "on");
14222 else
14223 json_object_string_add(json_neigh, "writeThread",
14224 "off");
14225 } else {
14226 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14227 p->v_connect);
14228 if (peer_established(p) && p->rtt)
14229 vty_out(vty, "Estimated round trip time: %d ms\n",
14230 p->rtt);
14231 if (p->t_start)
14232 vty_out(vty, "Next start timer due in %ld seconds\n",
14233 thread_timer_remain_second(p->t_start));
14234 if (p->t_connect)
14235 vty_out(vty, "Next connect timer due in %ld seconds\n",
14236 thread_timer_remain_second(p->t_connect));
14237 if (p->t_routeadv)
14238 vty_out(vty,
14239 "MRAI (interval %u) timer expires in %ld seconds\n",
14240 p->v_routeadv,
14241 thread_timer_remain_second(p->t_routeadv));
14242 if (p->password)
14243 vty_out(vty, "Peer Authentication Enabled\n");
14244
14245 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14246 p->t_read ? "on" : "off",
14247 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14248 ? "on"
14249 : "off", p->fd);
14250 }
14251
14252 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14253 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14254 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14255
14256 if (!use_json)
14257 vty_out(vty, "\n");
14258
14259 /* BFD information. */
14260 if (p->bfd_config)
14261 bgp_bfd_show_info(vty, p, json_neigh);
14262
14263 if (use_json) {
14264 if (p->conf_if) /* Configured interface name. */
14265 json_object_object_add(json, p->conf_if, json_neigh);
14266 else /* Configured IP address. */
14267 json_object_object_add(json, p->host, json_neigh);
14268 }
14269 }
14270
14271 static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14272 enum show_type type,
14273 union sockunion *su,
14274 const char *conf_if, afi_t afi,
14275 bool use_json)
14276 {
14277 struct listnode *node, *nnode;
14278 struct peer *peer;
14279 int find = 0;
14280 safi_t safi = SAFI_UNICAST;
14281 json_object *json = NULL;
14282 json_object *json_neighbor = NULL;
14283
14284 if (use_json) {
14285 json = json_object_new_object();
14286 json_neighbor = json_object_new_object();
14287 }
14288
14289 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14290
14291 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14292 continue;
14293
14294 if ((peer->afc[afi][safi]) == 0)
14295 continue;
14296
14297 if (type == show_all) {
14298 bgp_show_peer_gr_status(vty, peer, use_json,
14299 json_neighbor);
14300
14301 if (use_json) {
14302 json_object_object_add(json, peer->host,
14303 json_neighbor);
14304 json_neighbor = NULL;
14305 }
14306
14307 } else if (type == show_peer) {
14308 if (conf_if) {
14309 if ((peer->conf_if
14310 && !strcmp(peer->conf_if, conf_if))
14311 || (peer->hostname
14312 && !strcmp(peer->hostname, conf_if))) {
14313 find = 1;
14314 bgp_show_peer_gr_status(vty, peer,
14315 use_json,
14316 json_neighbor);
14317 }
14318 } else {
14319 if (sockunion_same(&peer->su, su)) {
14320 find = 1;
14321 bgp_show_peer_gr_status(vty, peer,
14322 use_json,
14323 json_neighbor);
14324 }
14325 }
14326 if (use_json && find)
14327 json_object_object_add(json, peer->host,
14328 json_neighbor);
14329 }
14330
14331 if (find) {
14332 json_neighbor = NULL;
14333 break;
14334 }
14335 }
14336
14337 if (type == show_peer && !find) {
14338 if (use_json)
14339 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14340 else
14341 vty_out(vty, "%% No such neighbor\n");
14342 }
14343 if (use_json) {
14344 if (json_neighbor)
14345 json_object_free(json_neighbor);
14346 vty_json(vty, json);
14347 } else {
14348 vty_out(vty, "\n");
14349 }
14350
14351 return CMD_SUCCESS;
14352 }
14353
14354 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14355 enum show_type type, union sockunion *su,
14356 const char *conf_if, bool use_json,
14357 json_object *json)
14358 {
14359 struct listnode *node, *nnode;
14360 struct peer *peer;
14361 int find = 0;
14362 bool nbr_output = false;
14363 afi_t afi = AFI_MAX;
14364 safi_t safi = SAFI_MAX;
14365
14366 if (type == show_ipv4_peer || type == show_ipv4_all) {
14367 afi = AFI_IP;
14368 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14369 afi = AFI_IP6;
14370 }
14371
14372 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14373 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14374 continue;
14375
14376 switch (type) {
14377 case show_all:
14378 bgp_show_peer(vty, peer, use_json, json);
14379 nbr_output = true;
14380 break;
14381 case show_peer:
14382 if (conf_if) {
14383 if ((peer->conf_if
14384 && !strcmp(peer->conf_if, conf_if))
14385 || (peer->hostname
14386 && !strcmp(peer->hostname, conf_if))) {
14387 find = 1;
14388 bgp_show_peer(vty, peer, use_json,
14389 json);
14390 }
14391 } else {
14392 if (sockunion_same(&peer->su, su)) {
14393 find = 1;
14394 bgp_show_peer(vty, peer, use_json,
14395 json);
14396 }
14397 }
14398 break;
14399 case show_ipv4_peer:
14400 case show_ipv6_peer:
14401 FOREACH_SAFI (safi) {
14402 if (peer->afc[afi][safi]) {
14403 if (conf_if) {
14404 if ((peer->conf_if
14405 && !strcmp(peer->conf_if, conf_if))
14406 || (peer->hostname
14407 && !strcmp(peer->hostname, conf_if))) {
14408 find = 1;
14409 bgp_show_peer(vty, peer, use_json,
14410 json);
14411 break;
14412 }
14413 } else {
14414 if (sockunion_same(&peer->su, su)) {
14415 find = 1;
14416 bgp_show_peer(vty, peer, use_json,
14417 json);
14418 break;
14419 }
14420 }
14421 }
14422 }
14423 break;
14424 case show_ipv4_all:
14425 case show_ipv6_all:
14426 FOREACH_SAFI (safi) {
14427 if (peer->afc[afi][safi]) {
14428 bgp_show_peer(vty, peer, use_json, json);
14429 nbr_output = true;
14430 break;
14431 }
14432 }
14433 break;
14434 }
14435 }
14436
14437 if ((type == show_peer || type == show_ipv4_peer ||
14438 type == show_ipv6_peer) && !find) {
14439 if (use_json)
14440 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14441 else
14442 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14443 }
14444
14445 if (type != show_peer && type != show_ipv4_peer &&
14446 type != show_ipv6_peer && !nbr_output && !use_json)
14447 vty_out(vty, "%% No BGP neighbors found\n");
14448
14449 if (use_json) {
14450 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14451 json, JSON_C_TO_STRING_PRETTY));
14452 } else {
14453 vty_out(vty, "\n");
14454 }
14455
14456 return CMD_SUCCESS;
14457 }
14458
14459 static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14460 enum show_type type,
14461 const char *ip_str,
14462 afi_t afi, bool use_json)
14463 {
14464
14465 int ret;
14466 struct bgp *bgp;
14467 union sockunion su;
14468
14469 bgp = bgp_get_default();
14470
14471 if (!bgp)
14472 return;
14473
14474 if (!use_json)
14475 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14476 NULL);
14477
14478 if (ip_str) {
14479 ret = str2sockunion(ip_str, &su);
14480 if (ret < 0)
14481 bgp_show_neighbor_graceful_restart(
14482 vty, bgp, type, NULL, ip_str, afi, use_json);
14483 else
14484 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14485 NULL, afi, use_json);
14486 } else
14487 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14488 afi, use_json);
14489 }
14490
14491 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14492 enum show_type type,
14493 const char *ip_str,
14494 bool use_json)
14495 {
14496 struct listnode *node, *nnode;
14497 struct bgp *bgp;
14498 union sockunion su;
14499 json_object *json = NULL;
14500 int ret, is_first = 1;
14501 bool nbr_output = false;
14502
14503 if (use_json)
14504 vty_out(vty, "{\n");
14505
14506 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14507 nbr_output = true;
14508 if (use_json) {
14509 if (!(json = json_object_new_object())) {
14510 flog_err(
14511 EC_BGP_JSON_MEM_ERROR,
14512 "Unable to allocate memory for JSON object");
14513 vty_out(vty,
14514 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14515 return;
14516 }
14517
14518 json_object_int_add(json, "vrfId",
14519 (bgp->vrf_id == VRF_UNKNOWN)
14520 ? -1
14521 : (int64_t)bgp->vrf_id);
14522 json_object_string_add(
14523 json, "vrfName",
14524 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14525 ? VRF_DEFAULT_NAME
14526 : bgp->name);
14527
14528 if (!is_first)
14529 vty_out(vty, ",\n");
14530 else
14531 is_first = 0;
14532
14533 vty_out(vty, "\"%s\":",
14534 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14535 ? VRF_DEFAULT_NAME
14536 : bgp->name);
14537 } else {
14538 vty_out(vty, "\nInstance %s:\n",
14539 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14540 ? VRF_DEFAULT_NAME
14541 : bgp->name);
14542 }
14543
14544 if (type == show_peer || type == show_ipv4_peer ||
14545 type == show_ipv6_peer) {
14546 ret = str2sockunion(ip_str, &su);
14547 if (ret < 0)
14548 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14549 use_json, json);
14550 else
14551 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14552 use_json, json);
14553 } else {
14554 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14555 use_json, json);
14556 }
14557 json_object_free(json);
14558 json = NULL;
14559 }
14560
14561 if (use_json)
14562 vty_out(vty, "}\n");
14563 else if (!nbr_output)
14564 vty_out(vty, "%% BGP instance not found\n");
14565 }
14566
14567 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14568 enum show_type type, const char *ip_str,
14569 bool use_json)
14570 {
14571 int ret;
14572 struct bgp *bgp;
14573 union sockunion su;
14574 json_object *json = NULL;
14575
14576 if (name) {
14577 if (strmatch(name, "all")) {
14578 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14579 use_json);
14580 return CMD_SUCCESS;
14581 } else {
14582 bgp = bgp_lookup_by_name(name);
14583 if (!bgp) {
14584 if (use_json) {
14585 json = json_object_new_object();
14586 vty_json(vty, json);
14587 } else
14588 vty_out(vty,
14589 "%% BGP instance not found\n");
14590
14591 return CMD_WARNING;
14592 }
14593 }
14594 } else {
14595 bgp = bgp_get_default();
14596 }
14597
14598 if (bgp) {
14599 json = json_object_new_object();
14600 if (ip_str) {
14601 ret = str2sockunion(ip_str, &su);
14602 if (ret < 0)
14603 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14604 use_json, json);
14605 else
14606 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14607 use_json, json);
14608 } else {
14609 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14610 json);
14611 }
14612 json_object_free(json);
14613 } else {
14614 if (use_json)
14615 vty_out(vty, "{}\n");
14616 else
14617 vty_out(vty, "%% BGP instance not found\n");
14618 }
14619
14620 return CMD_SUCCESS;
14621 }
14622
14623
14624
14625 /* "show [ip] bgp neighbors graceful-restart" commands. */
14626 DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14627 show_ip_bgp_neighbors_graceful_restart_cmd,
14628 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14629 SHOW_STR
14630 BGP_STR
14631 IP_STR
14632 IPV6_STR
14633 NEIGHBOR_STR
14634 "Neighbor to display information about\n"
14635 "Neighbor to display information about\n"
14636 "Neighbor on BGP configured interface\n"
14637 GR_SHOW
14638 JSON_STR)
14639 {
14640 char *sh_arg = NULL;
14641 enum show_type sh_type;
14642 int idx = 0;
14643 afi_t afi = AFI_MAX;
14644 bool uj = use_json(argc, argv);
14645
14646 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14647 afi = AFI_MAX;
14648
14649 idx++;
14650
14651 if (argv_find(argv, argc, "A.B.C.D", &idx)
14652 || argv_find(argv, argc, "X:X::X:X", &idx)
14653 || argv_find(argv, argc, "WORD", &idx)) {
14654 sh_type = show_peer;
14655 sh_arg = argv[idx]->arg;
14656 } else
14657 sh_type = show_all;
14658
14659 if (!argv_find(argv, argc, "graceful-restart", &idx))
14660 return CMD_SUCCESS;
14661
14662
14663 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14664 afi, uj);
14665 }
14666
14667 /* "show [ip] bgp neighbors" commands. */
14668 DEFUN (show_ip_bgp_neighbors,
14669 show_ip_bgp_neighbors_cmd,
14670 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14671 SHOW_STR
14672 IP_STR
14673 BGP_STR
14674 BGP_INSTANCE_HELP_STR
14675 "Address Family\n"
14676 "Address Family\n"
14677 "Detailed information on TCP and BGP neighbor connections\n"
14678 "Neighbor to display information about\n"
14679 "Neighbor to display information about\n"
14680 "Neighbor on BGP configured interface\n"
14681 JSON_STR)
14682 {
14683 char *vrf = NULL;
14684 char *sh_arg = NULL;
14685 enum show_type sh_type;
14686 afi_t afi = AFI_MAX;
14687
14688 bool uj = use_json(argc, argv);
14689
14690 int idx = 0;
14691
14692 /* [<vrf> VIEWVRFNAME] */
14693 if (argv_find(argv, argc, "vrf", &idx)) {
14694 vrf = argv[idx + 1]->arg;
14695 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14696 vrf = NULL;
14697 } else if (argv_find(argv, argc, "view", &idx))
14698 /* [<view> VIEWVRFNAME] */
14699 vrf = argv[idx + 1]->arg;
14700
14701 idx++;
14702
14703 if (argv_find(argv, argc, "ipv4", &idx)) {
14704 sh_type = show_ipv4_all;
14705 afi = AFI_IP;
14706 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14707 sh_type = show_ipv6_all;
14708 afi = AFI_IP6;
14709 } else {
14710 sh_type = show_all;
14711 }
14712
14713 if (argv_find(argv, argc, "A.B.C.D", &idx)
14714 || argv_find(argv, argc, "X:X::X:X", &idx)
14715 || argv_find(argv, argc, "WORD", &idx)) {
14716 sh_type = show_peer;
14717 sh_arg = argv[idx]->arg;
14718 }
14719
14720 if (sh_type == show_peer && afi == AFI_IP) {
14721 sh_type = show_ipv4_peer;
14722 } else if (sh_type == show_peer && afi == AFI_IP6) {
14723 sh_type = show_ipv6_peer;
14724 }
14725
14726 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14727 }
14728
14729 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
14730 paths' and `show ip mbgp paths'. Those functions results are the
14731 same.*/
14732 DEFUN (show_ip_bgp_paths,
14733 show_ip_bgp_paths_cmd,
14734 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14735 SHOW_STR
14736 IP_STR
14737 BGP_STR
14738 BGP_SAFI_HELP_STR
14739 "Path information\n")
14740 {
14741 vty_out(vty, "Address Refcnt Path\n");
14742 aspath_print_all_vty(vty);
14743 return CMD_SUCCESS;
14744 }
14745
14746 #include "hash.h"
14747
14748 static void community_show_all_iterator(struct hash_bucket *bucket,
14749 struct vty *vty)
14750 {
14751 struct community *com;
14752
14753 com = (struct community *)bucket->data;
14754 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14755 community_str(com, false, false));
14756 }
14757
14758 /* Show BGP's community internal data. */
14759 DEFUN (show_ip_bgp_community_info,
14760 show_ip_bgp_community_info_cmd,
14761 "show [ip] bgp community-info",
14762 SHOW_STR
14763 IP_STR
14764 BGP_STR
14765 "List all bgp community information\n")
14766 {
14767 vty_out(vty, "Address Refcnt Community\n");
14768
14769 hash_iterate(community_hash(),
14770 (void (*)(struct hash_bucket *,
14771 void *))community_show_all_iterator,
14772 vty);
14773
14774 return CMD_SUCCESS;
14775 }
14776
14777 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14778 struct vty *vty)
14779 {
14780 struct lcommunity *lcom;
14781
14782 lcom = (struct lcommunity *)bucket->data;
14783 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14784 lcommunity_str(lcom, false, false));
14785 }
14786
14787 /* Show BGP's community internal data. */
14788 DEFUN (show_ip_bgp_lcommunity_info,
14789 show_ip_bgp_lcommunity_info_cmd,
14790 "show ip bgp large-community-info",
14791 SHOW_STR
14792 IP_STR
14793 BGP_STR
14794 "List all bgp large-community information\n")
14795 {
14796 vty_out(vty, "Address Refcnt Large-community\n");
14797
14798 hash_iterate(lcommunity_hash(),
14799 (void (*)(struct hash_bucket *,
14800 void *))lcommunity_show_all_iterator,
14801 vty);
14802
14803 return CMD_SUCCESS;
14804 }
14805 /* Graceful Restart */
14806
14807 static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14808 struct bgp *bgp,
14809 bool use_json,
14810 json_object *json)
14811 {
14812
14813
14814 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14815
14816 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14817
14818 switch (bgp_global_gr_mode) {
14819
14820 case GLOBAL_HELPER:
14821 vty_out(vty, "Global BGP GR Mode : Helper\n");
14822 break;
14823
14824 case GLOBAL_GR:
14825 vty_out(vty, "Global BGP GR Mode : Restart\n");
14826 break;
14827
14828 case GLOBAL_DISABLE:
14829 vty_out(vty, "Global BGP GR Mode : Disable\n");
14830 break;
14831
14832 case GLOBAL_INVALID:
14833 vty_out(vty,
14834 "Global BGP GR Mode Invalid\n");
14835 break;
14836 }
14837 vty_out(vty, "\n");
14838 }
14839
14840 static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14841 enum show_type type,
14842 const char *ip_str,
14843 afi_t afi, bool use_json)
14844 {
14845 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14846 afi = AFI_IP;
14847
14848 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14849
14850 bgp_show_neighbor_graceful_restart_vty(
14851 vty, type, ip_str, afi, use_json);
14852 afi++;
14853 }
14854 } else if (afi != AFI_MAX) {
14855 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14856 use_json);
14857 } else {
14858 return CMD_ERR_INCOMPLETE;
14859 }
14860
14861 return CMD_SUCCESS;
14862 }
14863 /* Graceful Restart */
14864
14865 DEFUN (show_ip_bgp_attr_info,
14866 show_ip_bgp_attr_info_cmd,
14867 "show [ip] bgp attribute-info",
14868 SHOW_STR
14869 IP_STR
14870 BGP_STR
14871 "List all bgp attribute information\n")
14872 {
14873 attr_show_all(vty);
14874 return CMD_SUCCESS;
14875 }
14876
14877 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14878 afi_t afi, safi_t safi,
14879 bool use_json, json_object *json)
14880 {
14881 struct bgp *bgp;
14882 struct listnode *node;
14883 char *vname;
14884 char buf1[INET6_ADDRSTRLEN];
14885 char *ecom_str;
14886 enum vpn_policy_direction dir;
14887
14888 if (json) {
14889 json_object *json_import_vrfs = NULL;
14890 json_object *json_export_vrfs = NULL;
14891
14892 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14893
14894 if (!bgp) {
14895 vty_json(vty, json);
14896
14897 return CMD_WARNING;
14898 }
14899
14900 /* Provide context for the block */
14901 json_object_string_add(json, "vrf", name ? name : "default");
14902 json_object_string_add(json, "afiSafi",
14903 get_afi_safi_str(afi, safi, true));
14904
14905 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14906 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14907 json_object_string_add(json, "importFromVrfs", "none");
14908 json_object_string_add(json, "importRts", "none");
14909 } else {
14910 json_import_vrfs = json_object_new_array();
14911
14912 for (ALL_LIST_ELEMENTS_RO(
14913 bgp->vpn_policy[afi].import_vrf,
14914 node, vname))
14915 json_object_array_add(json_import_vrfs,
14916 json_object_new_string(vname));
14917
14918 json_object_object_add(json, "importFromVrfs",
14919 json_import_vrfs);
14920 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14921 if (bgp->vpn_policy[afi].rtlist[dir]) {
14922 ecom_str = ecommunity_ecom2str(
14923 bgp->vpn_policy[afi].rtlist[dir],
14924 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14925 json_object_string_add(json, "importRts",
14926 ecom_str);
14927 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14928 } else
14929 json_object_string_add(json, "importRts",
14930 "none");
14931 }
14932
14933 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14934 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14935 json_object_string_add(json, "exportToVrfs", "none");
14936 json_object_string_add(json, "routeDistinguisher",
14937 "none");
14938 json_object_string_add(json, "exportRts", "none");
14939 } else {
14940 json_export_vrfs = json_object_new_array();
14941
14942 for (ALL_LIST_ELEMENTS_RO(
14943 bgp->vpn_policy[afi].export_vrf,
14944 node, vname))
14945 json_object_array_add(json_export_vrfs,
14946 json_object_new_string(vname));
14947 json_object_object_add(json, "exportToVrfs",
14948 json_export_vrfs);
14949 json_object_string_add(json, "routeDistinguisher",
14950 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14951 buf1, RD_ADDRSTRLEN));
14952
14953 dir = BGP_VPN_POLICY_DIR_TOVPN;
14954 if (bgp->vpn_policy[afi].rtlist[dir]) {
14955 ecom_str = ecommunity_ecom2str(
14956 bgp->vpn_policy[afi].rtlist[dir],
14957 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14958 json_object_string_add(json, "exportRts",
14959 ecom_str);
14960 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14961 } else
14962 json_object_string_add(json, "exportRts",
14963 "none");
14964 }
14965
14966 if (use_json) {
14967 vty_json(vty, json);
14968 }
14969 } else {
14970 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14971
14972 if (!bgp) {
14973 vty_out(vty, "%% No such BGP instance exist\n");
14974 return CMD_WARNING;
14975 }
14976
14977 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14978 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14979 vty_out(vty,
14980 "This VRF is not importing %s routes from any other VRF\n",
14981 get_afi_safi_str(afi, safi, false));
14982 else {
14983 vty_out(vty,
14984 "This VRF is importing %s routes from the following VRFs:\n",
14985 get_afi_safi_str(afi, safi, false));
14986
14987 for (ALL_LIST_ELEMENTS_RO(
14988 bgp->vpn_policy[afi].import_vrf,
14989 node, vname))
14990 vty_out(vty, " %s\n", vname);
14991
14992 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14993 ecom_str = NULL;
14994 if (bgp->vpn_policy[afi].rtlist[dir]) {
14995 ecom_str = ecommunity_ecom2str(
14996 bgp->vpn_policy[afi].rtlist[dir],
14997 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14998 vty_out(vty, "Import RT(s): %s\n", ecom_str);
14999
15000 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15001 } else
15002 vty_out(vty, "Import RT(s):\n");
15003 }
15004
15005 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15006 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15007 vty_out(vty,
15008 "This VRF is not exporting %s routes to any other VRF\n",
15009 get_afi_safi_str(afi, safi, false));
15010 else {
15011 vty_out(vty,
15012 "This VRF is exporting %s routes to the following VRFs:\n",
15013 get_afi_safi_str(afi, safi, false));
15014
15015 for (ALL_LIST_ELEMENTS_RO(
15016 bgp->vpn_policy[afi].export_vrf,
15017 node, vname))
15018 vty_out(vty, " %s\n", vname);
15019
15020 vty_out(vty, "RD: %s\n",
15021 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15022 buf1, RD_ADDRSTRLEN));
15023
15024 dir = BGP_VPN_POLICY_DIR_TOVPN;
15025 if (bgp->vpn_policy[afi].rtlist[dir]) {
15026 ecom_str = ecommunity_ecom2str(
15027 bgp->vpn_policy[afi].rtlist[dir],
15028 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15029 vty_out(vty, "Export RT: %s\n", ecom_str);
15030 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15031 } else
15032 vty_out(vty, "Import RT(s):\n");
15033 }
15034 }
15035
15036 return CMD_SUCCESS;
15037 }
15038
15039 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15040 safi_t safi, bool use_json)
15041 {
15042 struct listnode *node, *nnode;
15043 struct bgp *bgp;
15044 char *vrf_name = NULL;
15045 json_object *json = NULL;
15046 json_object *json_vrf = NULL;
15047 json_object *json_vrfs = NULL;
15048
15049 if (use_json) {
15050 json = json_object_new_object();
15051 json_vrfs = json_object_new_object();
15052 }
15053
15054 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15055
15056 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15057 vrf_name = bgp->name;
15058
15059 if (use_json) {
15060 json_vrf = json_object_new_object();
15061 } else {
15062 vty_out(vty, "\nInstance %s:\n",
15063 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15064 ? VRF_DEFAULT_NAME : bgp->name);
15065 }
15066 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15067 if (use_json) {
15068 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15069 json_object_object_add(json_vrfs,
15070 VRF_DEFAULT_NAME, json_vrf);
15071 else
15072 json_object_object_add(json_vrfs, vrf_name,
15073 json_vrf);
15074 }
15075 }
15076
15077 if (use_json) {
15078 json_object_object_add(json, "vrfs", json_vrfs);
15079 vty_json(vty, json);
15080 }
15081
15082 return CMD_SUCCESS;
15083 }
15084
15085 /* "show [ip] bgp route-leak" command. */
15086 DEFUN (show_ip_bgp_route_leak,
15087 show_ip_bgp_route_leak_cmd,
15088 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15089 SHOW_STR
15090 IP_STR
15091 BGP_STR
15092 BGP_INSTANCE_HELP_STR
15093 BGP_AFI_HELP_STR
15094 BGP_SAFI_HELP_STR
15095 "Route leaking information\n"
15096 JSON_STR)
15097 {
15098 char *vrf = NULL;
15099 afi_t afi = AFI_MAX;
15100 safi_t safi = SAFI_MAX;
15101
15102 bool uj = use_json(argc, argv);
15103 int idx = 0;
15104 json_object *json = NULL;
15105
15106 /* show [ip] bgp */
15107 if (argv_find(argv, argc, "ip", &idx)) {
15108 afi = AFI_IP;
15109 safi = SAFI_UNICAST;
15110 }
15111 /* [vrf VIEWVRFNAME] */
15112 if (argv_find(argv, argc, "view", &idx)) {
15113 vty_out(vty,
15114 "%% This command is not applicable to BGP views\n");
15115 return CMD_WARNING;
15116 }
15117
15118 if (argv_find(argv, argc, "vrf", &idx)) {
15119 vrf = argv[idx + 1]->arg;
15120 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15121 vrf = NULL;
15122 }
15123 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15124 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
15125 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15126
15127 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15128 vty_out(vty,
15129 "%% This command is applicable only for unicast ipv4|ipv6\n");
15130 return CMD_WARNING;
15131 }
15132
15133 if (vrf && strmatch(vrf, "all"))
15134 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15135
15136 if (uj)
15137 json = json_object_new_object();
15138
15139 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15140 }
15141
15142 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15143 safi_t safi)
15144 {
15145 struct listnode *node, *nnode;
15146 struct bgp *bgp;
15147
15148 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15149 vty_out(vty, "\nInstance %s:\n",
15150 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15151 ? VRF_DEFAULT_NAME
15152 : bgp->name);
15153 update_group_show(bgp, afi, safi, vty, 0);
15154 }
15155 }
15156
15157 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15158 int safi, uint64_t subgrp_id)
15159 {
15160 struct bgp *bgp;
15161
15162 if (name) {
15163 if (strmatch(name, "all")) {
15164 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15165 return CMD_SUCCESS;
15166 } else {
15167 bgp = bgp_lookup_by_name(name);
15168 }
15169 } else {
15170 bgp = bgp_get_default();
15171 }
15172
15173 if (bgp)
15174 update_group_show(bgp, afi, safi, vty, subgrp_id);
15175 return CMD_SUCCESS;
15176 }
15177
15178 DEFUN (show_ip_bgp_updgrps,
15179 show_ip_bgp_updgrps_cmd,
15180 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15181 SHOW_STR
15182 IP_STR
15183 BGP_STR
15184 BGP_INSTANCE_HELP_STR
15185 BGP_AFI_HELP_STR
15186 BGP_SAFI_WITH_LABEL_HELP_STR
15187 "Detailed info about dynamic update groups\n"
15188 "Specific subgroup to display detailed info for\n")
15189 {
15190 char *vrf = NULL;
15191 afi_t afi = AFI_IP6;
15192 safi_t safi = SAFI_UNICAST;
15193 uint64_t subgrp_id = 0;
15194
15195 int idx = 0;
15196
15197 /* show [ip] bgp */
15198 if (argv_find(argv, argc, "ip", &idx))
15199 afi = AFI_IP;
15200 /* [<vrf> VIEWVRFNAME] */
15201 if (argv_find(argv, argc, "vrf", &idx)) {
15202 vrf = argv[idx + 1]->arg;
15203 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15204 vrf = NULL;
15205 } else if (argv_find(argv, argc, "view", &idx))
15206 /* [<view> VIEWVRFNAME] */
15207 vrf = argv[idx + 1]->arg;
15208 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15209 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15210 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15211 }
15212
15213 /* get subgroup id, if provided */
15214 idx = argc - 1;
15215 if (argv[idx]->type == VARIABLE_TKN)
15216 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15217
15218 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15219 }
15220
15221 DEFUN (show_bgp_instance_all_ipv6_updgrps,
15222 show_bgp_instance_all_ipv6_updgrps_cmd,
15223 "show [ip] bgp <view|vrf> all update-groups",
15224 SHOW_STR
15225 IP_STR
15226 BGP_STR
15227 BGP_INSTANCE_ALL_HELP_STR
15228 "Detailed info about dynamic update groups\n")
15229 {
15230 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15231 return CMD_SUCCESS;
15232 }
15233
15234 DEFUN (show_bgp_l2vpn_evpn_updgrps,
15235 show_bgp_l2vpn_evpn_updgrps_cmd,
15236 "show [ip] bgp l2vpn evpn update-groups",
15237 SHOW_STR
15238 IP_STR
15239 BGP_STR
15240 "l2vpn address family\n"
15241 "evpn sub-address family\n"
15242 "Detailed info about dynamic update groups\n")
15243 {
15244 char *vrf = NULL;
15245 uint64_t subgrp_id = 0;
15246
15247 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15248 return CMD_SUCCESS;
15249 }
15250
15251 DEFUN (show_bgp_updgrps_stats,
15252 show_bgp_updgrps_stats_cmd,
15253 "show [ip] bgp update-groups statistics",
15254 SHOW_STR
15255 IP_STR
15256 BGP_STR
15257 "Detailed info about dynamic update groups\n"
15258 "Statistics\n")
15259 {
15260 struct bgp *bgp;
15261
15262 bgp = bgp_get_default();
15263 if (bgp)
15264 update_group_show_stats(bgp, vty);
15265
15266 return CMD_SUCCESS;
15267 }
15268
15269 DEFUN (show_bgp_instance_updgrps_stats,
15270 show_bgp_instance_updgrps_stats_cmd,
15271 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15272 SHOW_STR
15273 IP_STR
15274 BGP_STR
15275 BGP_INSTANCE_HELP_STR
15276 "Detailed info about dynamic update groups\n"
15277 "Statistics\n")
15278 {
15279 int idx_word = 3;
15280 struct bgp *bgp;
15281
15282 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15283 if (bgp)
15284 update_group_show_stats(bgp, vty);
15285
15286 return CMD_SUCCESS;
15287 }
15288
15289 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15290 afi_t afi, safi_t safi,
15291 const char *what, uint64_t subgrp_id)
15292 {
15293 struct bgp *bgp;
15294
15295 if (name)
15296 bgp = bgp_lookup_by_name(name);
15297 else
15298 bgp = bgp_get_default();
15299
15300 if (bgp) {
15301 if (!strcmp(what, "advertise-queue"))
15302 update_group_show_adj_queue(bgp, afi, safi, vty,
15303 subgrp_id);
15304 else if (!strcmp(what, "advertised-routes"))
15305 update_group_show_advertised(bgp, afi, safi, vty,
15306 subgrp_id);
15307 else if (!strcmp(what, "packet-queue"))
15308 update_group_show_packet_queue(bgp, afi, safi, vty,
15309 subgrp_id);
15310 }
15311 }
15312
15313 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15314 show_ip_bgp_instance_updgrps_adj_s_cmd,
15315 "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",
15316 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15317 BGP_SAFI_HELP_STR
15318 "Detailed info about dynamic update groups\n"
15319 "Specific subgroup to display info for\n"
15320 "Advertisement queue\n"
15321 "Announced routes\n"
15322 "Packet queue\n")
15323 {
15324 uint64_t subgrp_id = 0;
15325 afi_t afiz;
15326 safi_t safiz;
15327 if (sgid)
15328 subgrp_id = strtoull(sgid, NULL, 10);
15329
15330 if (!ip && !afi)
15331 afiz = AFI_IP6;
15332 if (!ip && afi)
15333 afiz = bgp_vty_afi_from_str(afi);
15334 if (ip && !afi)
15335 afiz = AFI_IP;
15336 if (ip && afi) {
15337 afiz = bgp_vty_afi_from_str(afi);
15338 if (afiz != AFI_IP)
15339 vty_out(vty,
15340 "%% Cannot specify both 'ip' and 'ipv6'\n");
15341 return CMD_WARNING;
15342 }
15343
15344 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15345
15346 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15347 return CMD_SUCCESS;
15348 }
15349
15350 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15351 json_object *json)
15352 {
15353 struct listnode *node, *nnode;
15354 struct prefix *range;
15355 struct peer *conf;
15356 struct peer *peer;
15357 afi_t afi;
15358 safi_t safi;
15359 const char *peer_status;
15360 int lr_count;
15361 int dynamic;
15362 bool af_cfgd;
15363 json_object *json_peer_group = NULL;
15364 json_object *json_peer_group_afc = NULL;
15365 json_object *json_peer_group_members = NULL;
15366 json_object *json_peer_group_dynamic = NULL;
15367 json_object *json_peer_group_dynamic_af = NULL;
15368 json_object *json_peer_group_ranges = NULL;
15369
15370 conf = group->conf;
15371
15372 if (json) {
15373 json_peer_group = json_object_new_object();
15374 json_peer_group_afc = json_object_new_array();
15375 }
15376
15377 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15378 if (json)
15379 json_object_int_add(json_peer_group, "remoteAs",
15380 conf->as);
15381 else
15382 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15383 group->name, conf->as);
15384 } else if (conf->as_type == AS_INTERNAL) {
15385 if (json)
15386 json_object_int_add(json_peer_group, "remoteAs",
15387 group->bgp->as);
15388 else
15389 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15390 group->name, group->bgp->as);
15391 } else {
15392 if (!json)
15393 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15394 }
15395
15396 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15397 if (json)
15398 json_object_string_add(json_peer_group, "type",
15399 "internal");
15400 else
15401 vty_out(vty, " Peer-group type is internal\n");
15402 } else {
15403 if (json)
15404 json_object_string_add(json_peer_group, "type",
15405 "external");
15406 else
15407 vty_out(vty, " Peer-group type is external\n");
15408 }
15409
15410 /* Display AFs configured. */
15411 if (!json)
15412 vty_out(vty, " Configured address-families:");
15413
15414 FOREACH_AFI_SAFI (afi, safi) {
15415 if (conf->afc[afi][safi]) {
15416 af_cfgd = true;
15417 if (json)
15418 json_object_array_add(
15419 json_peer_group_afc,
15420 json_object_new_string(get_afi_safi_str(
15421 afi, safi, false)));
15422 else
15423 vty_out(vty, " %s;",
15424 get_afi_safi_str(afi, safi, false));
15425 }
15426 }
15427
15428 if (json) {
15429 json_object_object_add(json_peer_group,
15430 "addressFamiliesConfigured",
15431 json_peer_group_afc);
15432 } else {
15433 if (!af_cfgd)
15434 vty_out(vty, " none\n");
15435 else
15436 vty_out(vty, "\n");
15437 }
15438
15439 /* Display listen ranges (for dynamic neighbors), if any */
15440 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15441 lr_count = listcount(group->listen_range[afi]);
15442 if (lr_count) {
15443 if (json) {
15444 if (!json_peer_group_dynamic)
15445 json_peer_group_dynamic =
15446 json_object_new_object();
15447
15448 json_peer_group_dynamic_af =
15449 json_object_new_object();
15450 json_peer_group_ranges =
15451 json_object_new_array();
15452 json_object_int_add(json_peer_group_dynamic_af,
15453 "count", lr_count);
15454 } else {
15455 vty_out(vty, " %d %s listen range(s)\n",
15456 lr_count, afi2str(afi));
15457 }
15458
15459 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15460 nnode, range)) {
15461 if (json) {
15462 char buf[BUFSIZ];
15463
15464 snprintfrr(buf, sizeof(buf), "%pFX",
15465 range);
15466
15467 json_object_array_add(
15468 json_peer_group_ranges,
15469 json_object_new_string(buf));
15470 } else {
15471 vty_out(vty, " %pFX\n", range);
15472 }
15473 }
15474
15475 if (json) {
15476 json_object_object_add(
15477 json_peer_group_dynamic_af, "ranges",
15478 json_peer_group_ranges);
15479
15480 json_object_object_add(
15481 json_peer_group_dynamic, afi2str(afi),
15482 json_peer_group_dynamic_af);
15483 }
15484 }
15485 }
15486
15487 if (json_peer_group_dynamic)
15488 json_object_object_add(json_peer_group, "dynamicRanges",
15489 json_peer_group_dynamic);
15490
15491 /* Display group members and their status */
15492 if (listcount(group->peer)) {
15493 if (json)
15494 json_peer_group_members = json_object_new_object();
15495 else
15496 vty_out(vty, " Peer-group members:\n");
15497 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15498 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15499 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15500 peer_status = "Idle (Admin)";
15501 else if (CHECK_FLAG(peer->sflags,
15502 PEER_STATUS_PREFIX_OVERFLOW))
15503 peer_status = "Idle (PfxCt)";
15504 else
15505 peer_status = lookup_msg(bgp_status_msg,
15506 peer->status, NULL);
15507
15508 dynamic = peer_dynamic_neighbor(peer);
15509
15510 if (json) {
15511 json_object *json_peer_group_member =
15512 json_object_new_object();
15513
15514 json_object_string_add(json_peer_group_member,
15515 "status", peer_status);
15516
15517 if (dynamic)
15518 json_object_boolean_true_add(
15519 json_peer_group_member,
15520 "dynamic");
15521
15522 json_object_object_add(json_peer_group_members,
15523 peer->host,
15524 json_peer_group_member);
15525 } else {
15526 vty_out(vty, " %s %s %s \n", peer->host,
15527 dynamic ? "(dynamic)" : "",
15528 peer_status);
15529 }
15530 }
15531 if (json)
15532 json_object_object_add(json_peer_group, "members",
15533 json_peer_group_members);
15534 }
15535
15536 if (json)
15537 json_object_object_add(json, group->name, json_peer_group);
15538
15539 return CMD_SUCCESS;
15540 }
15541
15542 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15543 const char *group_name, bool uj)
15544 {
15545 struct bgp *bgp;
15546 struct listnode *node, *nnode;
15547 struct peer_group *group;
15548 bool found = false;
15549 json_object *json = NULL;
15550
15551 if (uj)
15552 json = json_object_new_object();
15553
15554 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15555
15556 if (!bgp) {
15557 if (uj)
15558 vty_json(vty, json);
15559 else
15560 vty_out(vty, "%% BGP instance not found\n");
15561
15562 return CMD_WARNING;
15563 }
15564
15565 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15566 if (group_name) {
15567 if (strmatch(group->name, group_name)) {
15568 bgp_show_one_peer_group(vty, group, json);
15569 found = true;
15570 break;
15571 }
15572 } else {
15573 bgp_show_one_peer_group(vty, group, json);
15574 }
15575 }
15576
15577 if (group_name && !found && !uj)
15578 vty_out(vty, "%% No such peer-group\n");
15579
15580 if (uj)
15581 vty_json(vty, json);
15582
15583 return CMD_SUCCESS;
15584 }
15585
15586 DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15587 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15588 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15589 "Detailed information on BGP peer groups\n"
15590 "Peer group name\n" JSON_STR)
15591 {
15592 char *vrf, *pg;
15593 int idx = 0;
15594 bool uj = use_json(argc, argv);
15595
15596 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15597 : NULL;
15598 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15599
15600 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
15601 }
15602
15603
15604 /* Redistribute VTY commands. */
15605
15606 DEFUN (bgp_redistribute_ipv4,
15607 bgp_redistribute_ipv4_cmd,
15608 "redistribute " FRR_IP_REDIST_STR_BGPD,
15609 "Redistribute information from another routing protocol\n"
15610 FRR_IP_REDIST_HELP_STR_BGPD)
15611 {
15612 VTY_DECLVAR_CONTEXT(bgp, bgp);
15613 int idx_protocol = 1;
15614 int type;
15615
15616 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15617 if (type < 0) {
15618 vty_out(vty, "%% Invalid route type\n");
15619 return CMD_WARNING_CONFIG_FAILED;
15620 }
15621
15622 bgp_redist_add(bgp, AFI_IP, type, 0);
15623 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
15624 }
15625
15626 ALIAS_HIDDEN(
15627 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15628 "redistribute " FRR_IP_REDIST_STR_BGPD,
15629 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15630
15631 DEFUN (bgp_redistribute_ipv4_rmap,
15632 bgp_redistribute_ipv4_rmap_cmd,
15633 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15634 "Redistribute information from another routing protocol\n"
15635 FRR_IP_REDIST_HELP_STR_BGPD
15636 "Route map reference\n"
15637 "Pointer to route-map entries\n")
15638 {
15639 VTY_DECLVAR_CONTEXT(bgp, bgp);
15640 int idx_protocol = 1;
15641 int idx_word = 3;
15642 int type;
15643 struct bgp_redist *red;
15644 bool changed;
15645 struct route_map *route_map = route_map_lookup_warn_noexist(
15646 vty, argv[idx_word]->arg);
15647
15648 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15649 if (type < 0) {
15650 vty_out(vty, "%% Invalid route type\n");
15651 return CMD_WARNING_CONFIG_FAILED;
15652 }
15653
15654 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15655 changed =
15656 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15657 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15658 }
15659
15660 ALIAS_HIDDEN(
15661 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15662 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
15663 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15664 "Route map reference\n"
15665 "Pointer to route-map entries\n")
15666
15667 DEFUN (bgp_redistribute_ipv4_metric,
15668 bgp_redistribute_ipv4_metric_cmd,
15669 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15670 "Redistribute information from another routing protocol\n"
15671 FRR_IP_REDIST_HELP_STR_BGPD
15672 "Metric for redistributed routes\n"
15673 "Default metric\n")
15674 {
15675 VTY_DECLVAR_CONTEXT(bgp, bgp);
15676 int idx_protocol = 1;
15677 int idx_number = 3;
15678 int type;
15679 uint32_t metric;
15680 struct bgp_redist *red;
15681 bool changed;
15682
15683 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15684 if (type < 0) {
15685 vty_out(vty, "%% Invalid route type\n");
15686 return CMD_WARNING_CONFIG_FAILED;
15687 }
15688 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15689
15690 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15691 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15692 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15693 }
15694
15695 ALIAS_HIDDEN(
15696 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15697 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15698 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15699 "Metric for redistributed routes\n"
15700 "Default metric\n")
15701
15702 DEFUN (bgp_redistribute_ipv4_rmap_metric,
15703 bgp_redistribute_ipv4_rmap_metric_cmd,
15704 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
15705 "Redistribute information from another routing protocol\n"
15706 FRR_IP_REDIST_HELP_STR_BGPD
15707 "Route map reference\n"
15708 "Pointer to route-map entries\n"
15709 "Metric for redistributed routes\n"
15710 "Default metric\n")
15711 {
15712 VTY_DECLVAR_CONTEXT(bgp, bgp);
15713 int idx_protocol = 1;
15714 int idx_word = 3;
15715 int idx_number = 5;
15716 int type;
15717 uint32_t metric;
15718 struct bgp_redist *red;
15719 bool changed;
15720 struct route_map *route_map =
15721 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15722
15723 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15724 if (type < 0) {
15725 vty_out(vty, "%% Invalid route type\n");
15726 return CMD_WARNING_CONFIG_FAILED;
15727 }
15728 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15729
15730 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15731 changed =
15732 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15733 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15734 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15735 }
15736
15737 ALIAS_HIDDEN(
15738 bgp_redistribute_ipv4_rmap_metric,
15739 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15740 "redistribute " FRR_IP_REDIST_STR_BGPD
15741 " route-map RMAP_NAME metric (0-4294967295)",
15742 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15743 "Route map reference\n"
15744 "Pointer to route-map entries\n"
15745 "Metric for redistributed routes\n"
15746 "Default metric\n")
15747
15748 DEFUN (bgp_redistribute_ipv4_metric_rmap,
15749 bgp_redistribute_ipv4_metric_rmap_cmd,
15750 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
15751 "Redistribute information from another routing protocol\n"
15752 FRR_IP_REDIST_HELP_STR_BGPD
15753 "Metric for redistributed routes\n"
15754 "Default metric\n"
15755 "Route map reference\n"
15756 "Pointer to route-map entries\n")
15757 {
15758 VTY_DECLVAR_CONTEXT(bgp, bgp);
15759 int idx_protocol = 1;
15760 int idx_number = 3;
15761 int idx_word = 5;
15762 int type;
15763 uint32_t metric;
15764 struct bgp_redist *red;
15765 bool changed;
15766 struct route_map *route_map =
15767 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15768
15769 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15770 if (type < 0) {
15771 vty_out(vty, "%% Invalid route type\n");
15772 return CMD_WARNING_CONFIG_FAILED;
15773 }
15774 metric = strtoul(argv[idx_number]->arg, NULL, 10);
15775
15776 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15777 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15778 changed |=
15779 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15780 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
15781 }
15782
15783 ALIAS_HIDDEN(
15784 bgp_redistribute_ipv4_metric_rmap,
15785 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15786 "redistribute " FRR_IP_REDIST_STR_BGPD
15787 " metric (0-4294967295) route-map RMAP_NAME",
15788 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15789 "Metric for redistributed routes\n"
15790 "Default metric\n"
15791 "Route map reference\n"
15792 "Pointer to route-map entries\n")
15793
15794 DEFUN (bgp_redistribute_ipv4_ospf,
15795 bgp_redistribute_ipv4_ospf_cmd,
15796 "redistribute <ospf|table> (1-65535)",
15797 "Redistribute information from another routing protocol\n"
15798 "Open Shortest Path First (OSPFv2)\n"
15799 "Non-main Kernel Routing Table\n"
15800 "Instance ID/Table ID\n")
15801 {
15802 VTY_DECLVAR_CONTEXT(bgp, bgp);
15803 int idx_ospf_table = 1;
15804 int idx_number = 2;
15805 unsigned short instance;
15806 unsigned short protocol;
15807
15808 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15809
15810 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15811 protocol = ZEBRA_ROUTE_OSPF;
15812 else
15813 protocol = ZEBRA_ROUTE_TABLE;
15814
15815 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15816 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
15817 }
15818
15819 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15820 "redistribute <ospf|table> (1-65535)",
15821 "Redistribute information from another routing protocol\n"
15822 "Open Shortest Path First (OSPFv2)\n"
15823 "Non-main Kernel Routing Table\n"
15824 "Instance ID/Table ID\n")
15825
15826 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15827 bgp_redistribute_ipv4_ospf_rmap_cmd,
15828 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15829 "Redistribute information from another routing protocol\n"
15830 "Open Shortest Path First (OSPFv2)\n"
15831 "Non-main Kernel Routing Table\n"
15832 "Instance ID/Table ID\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_word = 4;
15840 struct bgp_redist *red;
15841 unsigned short instance;
15842 int protocol;
15843 bool changed;
15844 struct route_map *route_map =
15845 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15846
15847 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15848 protocol = ZEBRA_ROUTE_OSPF;
15849 else
15850 protocol = ZEBRA_ROUTE_TABLE;
15851
15852 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15853 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15854 changed =
15855 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15856 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15857 }
15858
15859 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15860 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15861 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
15862 "Redistribute information from another routing protocol\n"
15863 "Open Shortest Path First (OSPFv2)\n"
15864 "Non-main Kernel Routing Table\n"
15865 "Instance ID/Table ID\n"
15866 "Route map reference\n"
15867 "Pointer to route-map entries\n")
15868
15869 DEFUN (bgp_redistribute_ipv4_ospf_metric,
15870 bgp_redistribute_ipv4_ospf_metric_cmd,
15871 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15872 "Redistribute information from another routing protocol\n"
15873 "Open Shortest Path First (OSPFv2)\n"
15874 "Non-main Kernel Routing Table\n"
15875 "Instance ID/Table ID\n"
15876 "Metric for redistributed routes\n"
15877 "Default metric\n")
15878 {
15879 VTY_DECLVAR_CONTEXT(bgp, bgp);
15880 int idx_ospf_table = 1;
15881 int idx_number = 2;
15882 int idx_number_2 = 4;
15883 uint32_t metric;
15884 struct bgp_redist *red;
15885 unsigned short instance;
15886 int protocol;
15887 bool changed;
15888
15889 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15890 protocol = ZEBRA_ROUTE_OSPF;
15891 else
15892 protocol = ZEBRA_ROUTE_TABLE;
15893
15894 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15895 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15896
15897 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15898 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15899 metric);
15900 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15901 }
15902
15903 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15904 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15905 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15906 "Redistribute information from another routing protocol\n"
15907 "Open Shortest Path First (OSPFv2)\n"
15908 "Non-main Kernel Routing Table\n"
15909 "Instance ID/Table ID\n"
15910 "Metric for redistributed routes\n"
15911 "Default metric\n")
15912
15913 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15914 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15915 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
15916 "Redistribute information from another routing protocol\n"
15917 "Open Shortest Path First (OSPFv2)\n"
15918 "Non-main Kernel Routing Table\n"
15919 "Instance ID/Table ID\n"
15920 "Route map reference\n"
15921 "Pointer to route-map entries\n"
15922 "Metric for redistributed routes\n"
15923 "Default metric\n")
15924 {
15925 VTY_DECLVAR_CONTEXT(bgp, bgp);
15926 int idx_ospf_table = 1;
15927 int idx_number = 2;
15928 int idx_word = 4;
15929 int idx_number_2 = 6;
15930 uint32_t metric;
15931 struct bgp_redist *red;
15932 unsigned short instance;
15933 int protocol;
15934 bool changed;
15935 struct route_map *route_map =
15936 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15937
15938 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15939 protocol = ZEBRA_ROUTE_OSPF;
15940 else
15941 protocol = ZEBRA_ROUTE_TABLE;
15942
15943 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15944 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15945
15946 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15947 changed =
15948 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15949 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15950 metric);
15951 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
15952 }
15953
15954 ALIAS_HIDDEN(
15955 bgp_redistribute_ipv4_ospf_rmap_metric,
15956 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15957 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
15958 "Redistribute information from another routing protocol\n"
15959 "Open Shortest Path First (OSPFv2)\n"
15960 "Non-main Kernel Routing Table\n"
15961 "Instance ID/Table ID\n"
15962 "Route map reference\n"
15963 "Pointer to route-map entries\n"
15964 "Metric for redistributed routes\n"
15965 "Default metric\n")
15966
15967 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15968 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15969 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
15970 "Redistribute information from another routing protocol\n"
15971 "Open Shortest Path First (OSPFv2)\n"
15972 "Non-main Kernel Routing Table\n"
15973 "Instance ID/Table ID\n"
15974 "Metric for redistributed routes\n"
15975 "Default metric\n"
15976 "Route map reference\n"
15977 "Pointer to route-map entries\n")
15978 {
15979 VTY_DECLVAR_CONTEXT(bgp, bgp);
15980 int idx_ospf_table = 1;
15981 int idx_number = 2;
15982 int idx_number_2 = 4;
15983 int idx_word = 6;
15984 uint32_t metric;
15985 struct bgp_redist *red;
15986 unsigned short instance;
15987 int protocol;
15988 bool changed;
15989 struct route_map *route_map =
15990 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15991
15992 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15993 protocol = ZEBRA_ROUTE_OSPF;
15994 else
15995 protocol = ZEBRA_ROUTE_TABLE;
15996
15997 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15998 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
15999
16000 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16001 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16002 metric);
16003 changed |=
16004 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16005 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
16006 }
16007
16008 ALIAS_HIDDEN(
16009 bgp_redistribute_ipv4_ospf_metric_rmap,
16010 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16011 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
16012 "Redistribute information from another routing protocol\n"
16013 "Open Shortest Path First (OSPFv2)\n"
16014 "Non-main Kernel Routing Table\n"
16015 "Instance ID/Table ID\n"
16016 "Metric for redistributed routes\n"
16017 "Default metric\n"
16018 "Route map reference\n"
16019 "Pointer to route-map entries\n")
16020
16021 DEFUN (no_bgp_redistribute_ipv4_ospf,
16022 no_bgp_redistribute_ipv4_ospf_cmd,
16023 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16024 NO_STR
16025 "Redistribute information from another routing protocol\n"
16026 "Open Shortest Path First (OSPFv2)\n"
16027 "Non-main Kernel Routing Table\n"
16028 "Instance ID/Table ID\n"
16029 "Metric for redistributed routes\n"
16030 "Default metric\n"
16031 "Route map reference\n"
16032 "Pointer to route-map entries\n")
16033 {
16034 VTY_DECLVAR_CONTEXT(bgp, bgp);
16035 int idx_ospf_table = 2;
16036 int idx_number = 3;
16037 unsigned short instance;
16038 int protocol;
16039
16040 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16041 protocol = ZEBRA_ROUTE_OSPF;
16042 else
16043 protocol = ZEBRA_ROUTE_TABLE;
16044
16045 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16046 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
16047 }
16048
16049 ALIAS_HIDDEN(
16050 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
16051 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
16052 NO_STR
16053 "Redistribute information from another routing protocol\n"
16054 "Open Shortest Path First (OSPFv2)\n"
16055 "Non-main Kernel Routing Table\n"
16056 "Instance ID/Table ID\n"
16057 "Metric for redistributed routes\n"
16058 "Default metric\n"
16059 "Route map reference\n"
16060 "Pointer to route-map entries\n")
16061
16062 DEFUN (no_bgp_redistribute_ipv4,
16063 no_bgp_redistribute_ipv4_cmd,
16064 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16065 NO_STR
16066 "Redistribute information from another routing protocol\n"
16067 FRR_IP_REDIST_HELP_STR_BGPD
16068 "Metric for redistributed routes\n"
16069 "Default metric\n"
16070 "Route map reference\n"
16071 "Pointer to route-map entries\n")
16072 {
16073 VTY_DECLVAR_CONTEXT(bgp, bgp);
16074 int idx_protocol = 2;
16075 int type;
16076
16077 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16078 if (type < 0) {
16079 vty_out(vty, "%% Invalid route type\n");
16080 return CMD_WARNING_CONFIG_FAILED;
16081 }
16082 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
16083 }
16084
16085 ALIAS_HIDDEN(
16086 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16087 "no redistribute " FRR_IP_REDIST_STR_BGPD
16088 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16089 NO_STR
16090 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16091 "Metric for redistributed routes\n"
16092 "Default metric\n"
16093 "Route map reference\n"
16094 "Pointer to route-map entries\n")
16095
16096 DEFUN (bgp_redistribute_ipv6,
16097 bgp_redistribute_ipv6_cmd,
16098 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16099 "Redistribute information from another routing protocol\n"
16100 FRR_IP6_REDIST_HELP_STR_BGPD)
16101 {
16102 VTY_DECLVAR_CONTEXT(bgp, bgp);
16103 int idx_protocol = 1;
16104 int type;
16105
16106 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16107 if (type < 0) {
16108 vty_out(vty, "%% Invalid route type\n");
16109 return CMD_WARNING_CONFIG_FAILED;
16110 }
16111
16112 bgp_redist_add(bgp, AFI_IP6, type, 0);
16113 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
16114 }
16115
16116 DEFUN (bgp_redistribute_ipv6_rmap,
16117 bgp_redistribute_ipv6_rmap_cmd,
16118 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
16119 "Redistribute information from another routing protocol\n"
16120 FRR_IP6_REDIST_HELP_STR_BGPD
16121 "Route map reference\n"
16122 "Pointer to route-map entries\n")
16123 {
16124 VTY_DECLVAR_CONTEXT(bgp, bgp);
16125 int idx_protocol = 1;
16126 int idx_word = 3;
16127 int type;
16128 struct bgp_redist *red;
16129 bool changed;
16130 struct route_map *route_map =
16131 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16132
16133 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16134 if (type < 0) {
16135 vty_out(vty, "%% Invalid route type\n");
16136 return CMD_WARNING_CONFIG_FAILED;
16137 }
16138
16139 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16140 changed =
16141 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16142 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16143 }
16144
16145 DEFUN (bgp_redistribute_ipv6_metric,
16146 bgp_redistribute_ipv6_metric_cmd,
16147 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16148 "Redistribute information from another routing protocol\n"
16149 FRR_IP6_REDIST_HELP_STR_BGPD
16150 "Metric for redistributed routes\n"
16151 "Default metric\n")
16152 {
16153 VTY_DECLVAR_CONTEXT(bgp, bgp);
16154 int idx_protocol = 1;
16155 int idx_number = 3;
16156 int type;
16157 uint32_t metric;
16158 struct bgp_redist *red;
16159 bool changed;
16160
16161 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16162 if (type < 0) {
16163 vty_out(vty, "%% Invalid route type\n");
16164 return CMD_WARNING_CONFIG_FAILED;
16165 }
16166 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16167
16168 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16169 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16170 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16171 }
16172
16173 DEFUN (bgp_redistribute_ipv6_rmap_metric,
16174 bgp_redistribute_ipv6_rmap_metric_cmd,
16175 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
16176 "Redistribute information from another routing protocol\n"
16177 FRR_IP6_REDIST_HELP_STR_BGPD
16178 "Route map reference\n"
16179 "Pointer to route-map entries\n"
16180 "Metric for redistributed routes\n"
16181 "Default metric\n")
16182 {
16183 VTY_DECLVAR_CONTEXT(bgp, bgp);
16184 int idx_protocol = 1;
16185 int idx_word = 3;
16186 int idx_number = 5;
16187 int type;
16188 uint32_t metric;
16189 struct bgp_redist *red;
16190 bool changed;
16191 struct route_map *route_map =
16192 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16193
16194 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16195 if (type < 0) {
16196 vty_out(vty, "%% Invalid route type\n");
16197 return CMD_WARNING_CONFIG_FAILED;
16198 }
16199 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16200
16201 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16202 changed =
16203 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16204 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16205 metric);
16206 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16207 }
16208
16209 DEFUN (bgp_redistribute_ipv6_metric_rmap,
16210 bgp_redistribute_ipv6_metric_rmap_cmd,
16211 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
16212 "Redistribute information from another routing protocol\n"
16213 FRR_IP6_REDIST_HELP_STR_BGPD
16214 "Metric for redistributed routes\n"
16215 "Default metric\n"
16216 "Route map reference\n"
16217 "Pointer to route-map entries\n")
16218 {
16219 VTY_DECLVAR_CONTEXT(bgp, bgp);
16220 int idx_protocol = 1;
16221 int idx_number = 3;
16222 int idx_word = 5;
16223 int type;
16224 uint32_t metric;
16225 struct bgp_redist *red;
16226 bool changed;
16227 struct route_map *route_map =
16228 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16229
16230 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16231 if (type < 0) {
16232 vty_out(vty, "%% Invalid route type\n");
16233 return CMD_WARNING_CONFIG_FAILED;
16234 }
16235 metric = strtoul(argv[idx_number]->arg, NULL, 10);
16236
16237 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16238 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16239 metric);
16240 changed |=
16241 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16242 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
16243 }
16244
16245 DEFUN (no_bgp_redistribute_ipv6,
16246 no_bgp_redistribute_ipv6_cmd,
16247 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
16248 NO_STR
16249 "Redistribute information from another routing protocol\n"
16250 FRR_IP6_REDIST_HELP_STR_BGPD
16251 "Metric for redistributed routes\n"
16252 "Default metric\n"
16253 "Route map reference\n"
16254 "Pointer to route-map entries\n")
16255 {
16256 VTY_DECLVAR_CONTEXT(bgp, bgp);
16257 int idx_protocol = 2;
16258 int type;
16259
16260 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16261 if (type < 0) {
16262 vty_out(vty, "%% Invalid route type\n");
16263 return CMD_WARNING_CONFIG_FAILED;
16264 }
16265
16266 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
16267 }
16268
16269 /* Neighbor update tcp-mss. */
16270 static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16271 const char *tcp_mss_str)
16272 {
16273 struct peer *peer;
16274 uint32_t tcp_mss_val = 0;
16275
16276 peer = peer_and_group_lookup_vty(vty, peer_str);
16277 if (!peer)
16278 return CMD_WARNING_CONFIG_FAILED;
16279
16280 if (tcp_mss_str) {
16281 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16282 peer_tcp_mss_set(peer, tcp_mss_val);
16283 } else {
16284 peer_tcp_mss_unset(peer);
16285 }
16286
16287 return CMD_SUCCESS;
16288 }
16289
16290 DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16291 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16292 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16293 "TCP max segment size\n"
16294 "TCP MSS value\n")
16295 {
16296 int peer_index = 1;
16297 int mss_index = 3;
16298
16299 vty_out(vty,
16300 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16301 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16302 argv[mss_index]->arg);
16303 }
16304
16305 DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16306 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16308 "TCP max segment size\n"
16309 "TCP MSS value\n")
16310 {
16311 int peer_index = 2;
16312
16313 vty_out(vty,
16314 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16315 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16316 }
16317
16318 static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16319 afi_t afi, safi_t safi)
16320 {
16321 int i;
16322
16323 /* Unicast redistribution only. */
16324 if (safi != SAFI_UNICAST)
16325 return;
16326
16327 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16328 /* Redistribute BGP does not make sense. */
16329 if (i != ZEBRA_ROUTE_BGP) {
16330 struct list *red_list;
16331 struct listnode *node;
16332 struct bgp_redist *red;
16333
16334 red_list = bgp->redist[afi][i];
16335 if (!red_list)
16336 continue;
16337
16338 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16339 /* "redistribute" configuration. */
16340 vty_out(vty, " redistribute %s",
16341 zebra_route_string(i));
16342 if (red->instance)
16343 vty_out(vty, " %d", red->instance);
16344 if (red->redist_metric_flag)
16345 vty_out(vty, " metric %u",
16346 red->redist_metric);
16347 if (red->rmap.name)
16348 vty_out(vty, " route-map %s",
16349 red->rmap.name);
16350 vty_out(vty, "\n");
16351 }
16352 }
16353 }
16354 }
16355
16356 /* peer-group helpers for config-write */
16357
16358 static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
16359 {
16360 if (!peer_group_active(peer)) {
16361 if (CHECK_FLAG(peer->flags_invert, flag))
16362 return !CHECK_FLAG(peer->flags, flag);
16363 else
16364 return !!CHECK_FLAG(peer->flags, flag);
16365 }
16366
16367 return !!CHECK_FLAG(peer->flags_override, flag);
16368 }
16369
16370 static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16371 uint32_t flag)
16372 {
16373 if (!peer_group_active(peer)) {
16374 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16375 return !peer_af_flag_check(peer, afi, safi, flag);
16376 else
16377 return !!peer_af_flag_check(peer, afi, safi, flag);
16378 }
16379
16380 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16381 }
16382
16383 static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16384 uint8_t type, int direct)
16385 {
16386 struct bgp_filter *filter;
16387
16388 if (peer_group_active(peer))
16389 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16390 type);
16391
16392 filter = &peer->filter[afi][safi];
16393 switch (type) {
16394 case PEER_FT_DISTRIBUTE_LIST:
16395 return !!(filter->dlist[direct].name);
16396 case PEER_FT_FILTER_LIST:
16397 return !!(filter->aslist[direct].name);
16398 case PEER_FT_PREFIX_LIST:
16399 return !!(filter->plist[direct].name);
16400 case PEER_FT_ROUTE_MAP:
16401 return !!(filter->map[direct].name);
16402 case PEER_FT_UNSUPPRESS_MAP:
16403 return !!(filter->usmap.name);
16404 case PEER_FT_ADVERTISE_MAP:
16405 return !!(filter->advmap.aname
16406 && ((filter->advmap.condition == direct)
16407 && filter->advmap.cname));
16408 default:
16409 return false;
16410 }
16411 }
16412
16413 /* Return true if the addpath type is set for peer and different from
16414 * peer-group.
16415 */
16416 static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16417 safi_t safi)
16418 {
16419 enum bgp_addpath_strat type, g_type;
16420
16421 type = peer->addpath_type[afi][safi];
16422
16423 if (type != BGP_ADDPATH_NONE) {
16424 if (peer_group_active(peer)) {
16425 g_type = peer->group->conf->addpath_type[afi][safi];
16426
16427 if (type != g_type)
16428 return true;
16429 else
16430 return false;
16431 }
16432
16433 return true;
16434 }
16435
16436 return false;
16437 }
16438
16439 /* This is part of the address-family block (unicast only) */
16440 static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16441 afi_t afi)
16442 {
16443 int indent = 2;
16444 uint32_t tovpn_sid_index = 0;
16445
16446 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16447 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16448 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16449 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16450 bgp->vpn_policy[afi]
16451 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16452 else
16453 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16454 bgp->vpn_policy[afi]
16455 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16456 }
16457 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16458 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16459 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16460 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16461 return;
16462
16463 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16464 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16465
16466 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16467
16468 } else {
16469 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16470 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16471 bgp->vpn_policy[afi].tovpn_label);
16472 }
16473 }
16474
16475 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16476 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16477 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16478 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16479 } else if (tovpn_sid_index != 0) {
16480 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16481 tovpn_sid_index);
16482 }
16483
16484 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16485 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16486 char buf[RD_ADDRSTRLEN];
16487 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16488 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16489 sizeof(buf)));
16490 }
16491 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16492 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16493
16494 char buf[PREFIX_STRLEN];
16495 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16496 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16497 sizeof(buf))) {
16498
16499 vty_out(vty, "%*snexthop vpn export %s\n",
16500 indent, "", buf);
16501 }
16502 }
16503 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16504 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16505 && ecommunity_cmp(
16506 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16507 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16508
16509 char *b = ecommunity_ecom2str(
16510 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16511 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16512 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16513 XFREE(MTYPE_ECOMMUNITY_STR, b);
16514 } else {
16515 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16516 char *b = ecommunity_ecom2str(
16517 bgp->vpn_policy[afi]
16518 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16519 ECOMMUNITY_FORMAT_ROUTE_MAP,
16520 ECOMMUNITY_ROUTE_TARGET);
16521 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16522 XFREE(MTYPE_ECOMMUNITY_STR, b);
16523 }
16524 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16525 char *b = ecommunity_ecom2str(
16526 bgp->vpn_policy[afi]
16527 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16528 ECOMMUNITY_FORMAT_ROUTE_MAP,
16529 ECOMMUNITY_ROUTE_TARGET);
16530 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16531 XFREE(MTYPE_ECOMMUNITY_STR, b);
16532 }
16533 }
16534
16535 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16536 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16537 bgp->vpn_policy[afi]
16538 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16539
16540 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16541 char *b = ecommunity_ecom2str(
16542 bgp->vpn_policy[afi]
16543 .import_redirect_rtlist,
16544 ECOMMUNITY_FORMAT_ROUTE_MAP,
16545 ECOMMUNITY_ROUTE_TARGET);
16546
16547 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16548 != ECOMMUNITY_SIZE)
16549 vty_out(vty, "%*srt6 redirect import %s\n",
16550 indent, "", b);
16551 else
16552 vty_out(vty, "%*srt redirect import %s\n",
16553 indent, "", b);
16554 XFREE(MTYPE_ECOMMUNITY_STR, b);
16555 }
16556 }
16557
16558 static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16559 afi_t afi, safi_t safi)
16560 {
16561 struct bgp_filter *filter;
16562 char *addr;
16563
16564 addr = peer->host;
16565 filter = &peer->filter[afi][safi];
16566
16567 /* distribute-list. */
16568 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16569 FILTER_IN))
16570 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16571 filter->dlist[FILTER_IN].name);
16572
16573 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16574 FILTER_OUT))
16575 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16576 filter->dlist[FILTER_OUT].name);
16577
16578 /* prefix-list. */
16579 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16580 FILTER_IN))
16581 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16582 filter->plist[FILTER_IN].name);
16583
16584 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16585 FILTER_OUT))
16586 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16587 filter->plist[FILTER_OUT].name);
16588
16589 /* route-map. */
16590 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16591 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16592 filter->map[RMAP_IN].name);
16593
16594 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16595 RMAP_OUT))
16596 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16597 filter->map[RMAP_OUT].name);
16598
16599 /* unsuppress-map */
16600 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16601 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16602 filter->usmap.name);
16603
16604 /* advertise-map : always applied in OUT direction*/
16605 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16606 CONDITION_NON_EXIST))
16607 vty_out(vty,
16608 " neighbor %s advertise-map %s non-exist-map %s\n",
16609 addr, filter->advmap.aname, filter->advmap.cname);
16610
16611 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16612 CONDITION_EXIST))
16613 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16614 addr, filter->advmap.aname, filter->advmap.cname);
16615
16616 /* filter-list. */
16617 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16618 FILTER_IN))
16619 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16620 filter->aslist[FILTER_IN].name);
16621
16622 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16623 FILTER_OUT))
16624 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16625 filter->aslist[FILTER_OUT].name);
16626 }
16627
16628 /* BGP peer configuration display function. */
16629 static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16630 struct peer *peer)
16631 {
16632 struct peer *g_peer = NULL;
16633 char *addr;
16634 int if_pg_printed = false;
16635 int if_ras_printed = false;
16636
16637 /* Skip dynamic neighbors. */
16638 if (peer_dynamic_neighbor(peer))
16639 return;
16640
16641 if (peer->conf_if)
16642 addr = peer->conf_if;
16643 else
16644 addr = peer->host;
16645
16646 /************************************
16647 ****** Global to the neighbor ******
16648 ************************************/
16649 if (peer->conf_if) {
16650 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16651 vty_out(vty, " neighbor %s interface v6only", addr);
16652 else
16653 vty_out(vty, " neighbor %s interface", addr);
16654
16655 if (peer_group_active(peer)) {
16656 vty_out(vty, " peer-group %s", peer->group->name);
16657 if_pg_printed = true;
16658 } else if (peer->as_type == AS_SPECIFIED) {
16659 vty_out(vty, " remote-as %u", peer->as);
16660 if_ras_printed = true;
16661 } else if (peer->as_type == AS_INTERNAL) {
16662 vty_out(vty, " remote-as internal");
16663 if_ras_printed = true;
16664 } else if (peer->as_type == AS_EXTERNAL) {
16665 vty_out(vty, " remote-as external");
16666 if_ras_printed = true;
16667 }
16668
16669 vty_out(vty, "\n");
16670 }
16671
16672 /* remote-as and peer-group */
16673 /* peer is a member of a peer-group */
16674 if (peer_group_active(peer)) {
16675 g_peer = peer->group->conf;
16676
16677 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16678 if (peer->as_type == AS_SPECIFIED) {
16679 vty_out(vty, " neighbor %s remote-as %u\n",
16680 addr, peer->as);
16681 } else if (peer->as_type == AS_INTERNAL) {
16682 vty_out(vty,
16683 " neighbor %s remote-as internal\n",
16684 addr);
16685 } else if (peer->as_type == AS_EXTERNAL) {
16686 vty_out(vty,
16687 " neighbor %s remote-as external\n",
16688 addr);
16689 }
16690 }
16691
16692 /* For swpX peers we displayed the peer-group
16693 * via 'neighbor swpX interface peer-group PGNAME' */
16694 if (!if_pg_printed)
16695 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16696 peer->group->name);
16697 }
16698
16699 /* peer is NOT a member of a peer-group */
16700 else {
16701 /* peer is a peer-group, declare the peer-group */
16702 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16703 vty_out(vty, " neighbor %s peer-group\n", addr);
16704 }
16705
16706 if (!if_ras_printed) {
16707 if (peer->as_type == AS_SPECIFIED) {
16708 vty_out(vty, " neighbor %s remote-as %u\n",
16709 addr, peer->as);
16710 } else if (peer->as_type == AS_INTERNAL) {
16711 vty_out(vty,
16712 " neighbor %s remote-as internal\n",
16713 addr);
16714 } else if (peer->as_type == AS_EXTERNAL) {
16715 vty_out(vty,
16716 " neighbor %s remote-as external\n",
16717 addr);
16718 }
16719 }
16720 }
16721
16722 /* local-as */
16723 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16724 vty_out(vty, " neighbor %s local-as %u", addr,
16725 peer->change_local_as);
16726 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16727 vty_out(vty, " no-prepend");
16728 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16729 vty_out(vty, " replace-as");
16730 vty_out(vty, "\n");
16731 }
16732
16733 /* description */
16734 if (peer->desc) {
16735 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16736 }
16737
16738 /* shutdown */
16739 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16740 if (peer->tx_shutdown_message)
16741 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16742 peer->tx_shutdown_message);
16743 else
16744 vty_out(vty, " neighbor %s shutdown\n", addr);
16745 }
16746
16747 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16748 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16749 peer->rtt_expected, peer->rtt_keepalive_conf);
16750
16751 /* bfd */
16752 if (peer->bfd_config)
16753 bgp_bfd_peer_config_write(vty, peer, addr);
16754
16755 /* password */
16756 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16757 vty_out(vty, " neighbor %s password %s\n", addr,
16758 peer->password);
16759
16760 /* neighbor solo */
16761 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16762 if (!peer_group_active(peer)) {
16763 vty_out(vty, " neighbor %s solo\n", addr);
16764 }
16765 }
16766
16767 /* BGP port */
16768 if (peer->port != BGP_PORT_DEFAULT) {
16769 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16770 }
16771
16772 /* Local interface name */
16773 if (peer->ifname) {
16774 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16775 }
16776
16777 /* TCP max segment size */
16778 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16779 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16780
16781 /* passive */
16782 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16783 vty_out(vty, " neighbor %s passive\n", addr);
16784
16785 /* ebgp-multihop */
16786 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16787 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16788 && peer->ttl == MAXTTL)) {
16789 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16790 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16791 peer->ttl);
16792 }
16793 }
16794
16795 /* role */
16796 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16797 peer->local_role != ROLE_UNDEFINED)
16798 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
16799 bgp_get_name_by_role(peer->local_role),
16800 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
16801 ? " strict-mode"
16802 : "");
16803
16804 /* ttl-security hops */
16805 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16806 if (!peer_group_active(peer)
16807 || g_peer->gtsm_hops != peer->gtsm_hops) {
16808 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16809 addr, peer->gtsm_hops);
16810 }
16811 }
16812
16813 /* disable-connected-check */
16814 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16815 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16816
16817 /* link-bw-encoding-ieee */
16818 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16819 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16820 addr);
16821
16822 /* extended-optional-parameters */
16823 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16824 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16825 addr);
16826
16827 /* enforce-first-as */
16828 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16829 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16830
16831 /* update-source */
16832 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16833 if (peer->update_source)
16834 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16835 peer->update_source);
16836 else if (peer->update_if)
16837 vty_out(vty, " neighbor %s update-source %s\n", addr,
16838 peer->update_if);
16839 }
16840
16841 /* advertisement-interval */
16842 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16843 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16844 peer->routeadv);
16845
16846 /* timers */
16847 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16848 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16849 peer->keepalive, peer->holdtime);
16850
16851 /* timers connect */
16852 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16853 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16854 peer->connect);
16855 /* need special-case handling for changed default values due to
16856 * config profile / version (because there is no "timers bgp connect"
16857 * command, we need to save this per-peer :/)
16858 */
16859 else if (!peer_group_active(peer) && !peer->connect &&
16860 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16861 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16862 peer->bgp->default_connect_retry);
16863
16864 /* timers delayopen */
16865 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16866 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16867 peer->delayopen);
16868 /* Save config even though flag is not set if default values have been
16869 * changed
16870 */
16871 else if (!peer_group_active(peer) && !peer->delayopen
16872 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16873 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16874 peer->bgp->default_delayopen);
16875
16876 /* capability dynamic */
16877 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16878 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16879
16880 /* capability extended-nexthop */
16881 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16882 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
16883 !peer->conf_if)
16884 vty_out(vty,
16885 " no neighbor %s capability extended-nexthop\n",
16886 addr);
16887 else if (!peer->conf_if)
16888 vty_out(vty,
16889 " neighbor %s capability extended-nexthop\n",
16890 addr);
16891 }
16892
16893 /* dont-capability-negotiation */
16894 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16895 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16896
16897 /* override-capability */
16898 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16899 vty_out(vty, " neighbor %s override-capability\n", addr);
16900
16901 /* strict-capability-match */
16902 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16903 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16904
16905 /* Sender side AS path loop detection. */
16906 if (peer->as_path_loop_detection)
16907 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16908 addr);
16909
16910 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16911 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16912
16913 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16914 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16915 vty_out(vty,
16916 " neighbor %s graceful-restart-helper\n", addr);
16917 } else if (CHECK_FLAG(
16918 peer->peer_gr_new_status_flag,
16919 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16920 vty_out(vty,
16921 " neighbor %s graceful-restart\n", addr);
16922 } else if (
16923 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16924 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16925 && !(CHECK_FLAG(
16926 peer->peer_gr_new_status_flag,
16927 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16928 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16929 addr);
16930 }
16931 }
16932 }
16933
16934 /* BGP peer configuration display function. */
16935 static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16936 struct peer *peer, afi_t afi, safi_t safi)
16937 {
16938 struct peer *g_peer = NULL;
16939 char *addr;
16940 bool flag_scomm, flag_secomm, flag_slcomm;
16941
16942 /* Skip dynamic neighbors. */
16943 if (peer_dynamic_neighbor(peer))
16944 return;
16945
16946 if (peer->conf_if)
16947 addr = peer->conf_if;
16948 else
16949 addr = peer->host;
16950
16951 /************************************
16952 ****** Per AF to the neighbor ******
16953 ************************************/
16954 if (peer_group_active(peer)) {
16955 g_peer = peer->group->conf;
16956
16957 /* If the peer-group is active but peer is not, print a 'no
16958 * activate' */
16959 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16960 vty_out(vty, " no neighbor %s activate\n", addr);
16961 }
16962
16963 /* If the peer-group is not active but peer is, print an
16964 'activate' */
16965 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16966 vty_out(vty, " neighbor %s activate\n", addr);
16967 }
16968 } else {
16969 if (peer->afc[afi][safi]) {
16970 if (safi == SAFI_ENCAP)
16971 vty_out(vty, " neighbor %s activate\n", addr);
16972 else if (!bgp->default_af[afi][safi])
16973 vty_out(vty, " neighbor %s activate\n", addr);
16974 } else {
16975 if (bgp->default_af[afi][safi])
16976 vty_out(vty, " no neighbor %s activate\n",
16977 addr);
16978 }
16979 }
16980
16981 /* addpath TX knobs */
16982 if (peergroup_af_addpath_check(peer, afi, safi)) {
16983 switch (peer->addpath_type[afi][safi]) {
16984 case BGP_ADDPATH_ALL:
16985 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16986 addr);
16987 break;
16988 case BGP_ADDPATH_BEST_PER_AS:
16989 vty_out(vty,
16990 " neighbor %s addpath-tx-bestpath-per-AS\n",
16991 addr);
16992 break;
16993 case BGP_ADDPATH_MAX:
16994 case BGP_ADDPATH_NONE:
16995 break;
16996 }
16997 }
16998
16999 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17000 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17001
17002 /* ORF capability. */
17003 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17004 || peergroup_af_flag_check(peer, afi, safi,
17005 PEER_FLAG_ORF_PREFIX_RM)) {
17006 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17007
17008 if (peergroup_af_flag_check(peer, afi, safi,
17009 PEER_FLAG_ORF_PREFIX_SM)
17010 && peergroup_af_flag_check(peer, afi, safi,
17011 PEER_FLAG_ORF_PREFIX_RM))
17012 vty_out(vty, " both");
17013 else if (peergroup_af_flag_check(peer, afi, safi,
17014 PEER_FLAG_ORF_PREFIX_SM))
17015 vty_out(vty, " send");
17016 else
17017 vty_out(vty, " receive");
17018 vty_out(vty, "\n");
17019 }
17020
17021 /* Route reflector client. */
17022 if (peergroup_af_flag_check(peer, afi, safi,
17023 PEER_FLAG_REFLECTOR_CLIENT)) {
17024 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17025 }
17026
17027 /* next-hop-self force */
17028 if (peergroup_af_flag_check(peer, afi, safi,
17029 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17030 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17031 }
17032
17033 /* next-hop-self */
17034 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17035 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17036 }
17037
17038 /* remove-private-AS */
17039 if (peergroup_af_flag_check(peer, afi, safi,
17040 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17041 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17042 addr);
17043 }
17044
17045 else if (peergroup_af_flag_check(peer, afi, safi,
17046 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17047 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17048 addr);
17049 }
17050
17051 else if (peergroup_af_flag_check(peer, afi, safi,
17052 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17053 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17054 }
17055
17056 else if (peergroup_af_flag_check(peer, afi, safi,
17057 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17058 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17059 }
17060
17061 /* as-override */
17062 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17063 vty_out(vty, " neighbor %s as-override\n", addr);
17064 }
17065
17066 /* send-community print. */
17067 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17068 PEER_FLAG_SEND_COMMUNITY);
17069 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17070 PEER_FLAG_SEND_EXT_COMMUNITY);
17071 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17072 PEER_FLAG_SEND_LARGE_COMMUNITY);
17073
17074 if (flag_scomm && flag_secomm && flag_slcomm) {
17075 vty_out(vty, " no neighbor %s send-community all\n", addr);
17076 } else {
17077 if (flag_scomm)
17078 vty_out(vty, " no neighbor %s send-community\n", addr);
17079 if (flag_secomm)
17080 vty_out(vty,
17081 " no neighbor %s send-community extended\n",
17082 addr);
17083
17084 if (flag_slcomm)
17085 vty_out(vty, " no neighbor %s send-community large\n",
17086 addr);
17087 }
17088
17089 /* Default information */
17090 if (peergroup_af_flag_check(peer, afi, safi,
17091 PEER_FLAG_DEFAULT_ORIGINATE)) {
17092 vty_out(vty, " neighbor %s default-originate", addr);
17093
17094 if (peer->default_rmap[afi][safi].name)
17095 vty_out(vty, " route-map %s",
17096 peer->default_rmap[afi][safi].name);
17097
17098 vty_out(vty, "\n");
17099 }
17100
17101 /* Soft reconfiguration inbound. */
17102 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17103 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17104 addr);
17105 }
17106
17107 /* maximum-prefix. */
17108 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
17109 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
17110 peer->pmax[afi][safi]);
17111
17112 if (peer->pmax_threshold[afi][safi]
17113 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17114 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17115 if (peer_af_flag_check(peer, afi, safi,
17116 PEER_FLAG_MAX_PREFIX_WARNING))
17117 vty_out(vty, " warning-only");
17118 if (peer->pmax_restart[afi][safi])
17119 vty_out(vty, " restart %u",
17120 peer->pmax_restart[afi][safi]);
17121 if (peer_af_flag_check(peer, afi, safi,
17122 PEER_FLAG_MAX_PREFIX_FORCE))
17123 vty_out(vty, " force");
17124
17125 vty_out(vty, "\n");
17126 }
17127
17128 /* maximum-prefix-out */
17129 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
17130 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
17131 addr, peer->pmax_out[afi][safi]);
17132
17133 /* Route server client. */
17134 if (peergroup_af_flag_check(peer, afi, safi,
17135 PEER_FLAG_RSERVER_CLIENT)) {
17136 vty_out(vty, " neighbor %s route-server-client\n", addr);
17137 }
17138
17139 /* Nexthop-local unchanged. */
17140 if (peergroup_af_flag_check(peer, afi, safi,
17141 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17142 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17143 }
17144
17145 /* allowas-in <1-10> */
17146 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17147 if (peer_af_flag_check(peer, afi, safi,
17148 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17149 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17150 } else if (peer->allowas_in[afi][safi] == 3) {
17151 vty_out(vty, " neighbor %s allowas-in\n", addr);
17152 } else {
17153 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17154 peer->allowas_in[afi][safi]);
17155 }
17156 }
17157
17158 /* weight */
17159 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17160 vty_out(vty, " neighbor %s weight %lu\n", addr,
17161 peer->weight[afi][safi]);
17162
17163 /* Filter. */
17164 bgp_config_write_filter(vty, peer, afi, safi);
17165
17166 /* atribute-unchanged. */
17167 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17168 || (safi != SAFI_EVPN
17169 && peer_af_flag_check(peer, afi, safi,
17170 PEER_FLAG_NEXTHOP_UNCHANGED))
17171 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17172
17173 if (!peer_group_active(peer)
17174 || peergroup_af_flag_check(peer, afi, safi,
17175 PEER_FLAG_AS_PATH_UNCHANGED)
17176 || peergroup_af_flag_check(peer, afi, safi,
17177 PEER_FLAG_NEXTHOP_UNCHANGED)
17178 || peergroup_af_flag_check(peer, afi, safi,
17179 PEER_FLAG_MED_UNCHANGED)) {
17180
17181 vty_out(vty,
17182 " neighbor %s attribute-unchanged%s%s%s\n",
17183 addr,
17184 peer_af_flag_check(peer, afi, safi,
17185 PEER_FLAG_AS_PATH_UNCHANGED)
17186 ? " as-path"
17187 : "",
17188 peer_af_flag_check(peer, afi, safi,
17189 PEER_FLAG_NEXTHOP_UNCHANGED)
17190 ? " next-hop"
17191 : "",
17192 peer_af_flag_check(peer, afi, safi,
17193 PEER_FLAG_MED_UNCHANGED)
17194 ? " med"
17195 : "");
17196 }
17197 }
17198 }
17199
17200 /* Address family based peer configuration display. */
17201 static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17202 safi_t safi)
17203 {
17204 struct peer *peer;
17205 struct peer_group *group;
17206 struct listnode *node, *nnode;
17207
17208
17209 vty_frame(vty, " !\n address-family ");
17210 if (afi == AFI_IP) {
17211 if (safi == SAFI_UNICAST)
17212 vty_frame(vty, "ipv4 unicast");
17213 else if (safi == SAFI_LABELED_UNICAST)
17214 vty_frame(vty, "ipv4 labeled-unicast");
17215 else if (safi == SAFI_MULTICAST)
17216 vty_frame(vty, "ipv4 multicast");
17217 else if (safi == SAFI_MPLS_VPN)
17218 vty_frame(vty, "ipv4 vpn");
17219 else if (safi == SAFI_ENCAP)
17220 vty_frame(vty, "ipv4 encap");
17221 else if (safi == SAFI_FLOWSPEC)
17222 vty_frame(vty, "ipv4 flowspec");
17223 } else if (afi == AFI_IP6) {
17224 if (safi == SAFI_UNICAST)
17225 vty_frame(vty, "ipv6 unicast");
17226 else if (safi == SAFI_LABELED_UNICAST)
17227 vty_frame(vty, "ipv6 labeled-unicast");
17228 else if (safi == SAFI_MULTICAST)
17229 vty_frame(vty, "ipv6 multicast");
17230 else if (safi == SAFI_MPLS_VPN)
17231 vty_frame(vty, "ipv6 vpn");
17232 else if (safi == SAFI_ENCAP)
17233 vty_frame(vty, "ipv6 encap");
17234 else if (safi == SAFI_FLOWSPEC)
17235 vty_frame(vty, "ipv6 flowspec");
17236 } else if (afi == AFI_L2VPN) {
17237 if (safi == SAFI_EVPN)
17238 vty_frame(vty, "l2vpn evpn");
17239 }
17240 vty_frame(vty, "\n");
17241
17242 bgp_config_write_distance(vty, bgp, afi, safi);
17243
17244 bgp_config_write_network(vty, bgp, afi, safi);
17245
17246 bgp_config_write_redistribute(vty, bgp, afi, safi);
17247
17248 /* BGP flag dampening. */
17249 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17250 bgp_config_write_damp(vty, afi, safi);
17251
17252 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17253 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17254
17255 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17256 /* Do not display doppelganger peers */
17257 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17258 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17259 }
17260
17261 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17262 bgp_config_write_table_map(vty, bgp, afi, safi);
17263
17264 if (safi == SAFI_EVPN)
17265 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17266
17267 if (safi == SAFI_FLOWSPEC)
17268 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17269
17270 if (safi == SAFI_UNICAST) {
17271 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17272 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17273 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17274
17275 vty_out(vty, " export vpn\n");
17276 }
17277 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17278 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17279
17280 vty_out(vty, " import vpn\n");
17281 }
17282 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17283 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17284 char *name;
17285
17286 for (ALL_LIST_ELEMENTS_RO(
17287 bgp->vpn_policy[afi].import_vrf, node,
17288 name))
17289 vty_out(vty, " import vrf %s\n", name);
17290 }
17291 }
17292
17293 vty_endframe(vty, " exit-address-family\n");
17294 }
17295
17296 int bgp_config_write(struct vty *vty)
17297 {
17298 struct bgp *bgp;
17299 struct peer_group *group;
17300 struct peer *peer;
17301 struct listnode *node, *nnode;
17302 struct listnode *mnode, *mnnode;
17303 afi_t afi;
17304 safi_t safi;
17305
17306 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17307 vty_out(vty, "bgp route-map delay-timer %u\n",
17308 bm->rmap_update_timer);
17309
17310 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17311 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17312 if (bm->v_update_delay != bm->v_establish_wait)
17313 vty_out(vty, " %d", bm->v_establish_wait);
17314 vty_out(vty, "\n");
17315 }
17316
17317 if (bm->wait_for_fib)
17318 vty_out(vty, "bgp suppress-fib-pending\n");
17319
17320 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17321 vty_out(vty, "bgp graceful-shutdown\n");
17322
17323 /* No-RIB (Zebra) option flag configuration */
17324 if (bgp_option_check(BGP_OPT_NO_FIB))
17325 vty_out(vty, "bgp no-rib\n");
17326
17327 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17328 vty_out(vty, "bgp send-extra-data zebra\n");
17329
17330 /* BGP session DSCP value */
17331 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17332 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17333
17334 /* BGP configuration. */
17335 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17336
17337 /* skip all auto created vrf as they dont have user config */
17338 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17339 continue;
17340
17341 /* Router bgp ASN */
17342 vty_out(vty, "router bgp %u", bgp->as);
17343
17344 if (bgp->name)
17345 vty_out(vty, " %s %s",
17346 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17347 ? "view" : "vrf", bgp->name);
17348 vty_out(vty, "\n");
17349
17350 /* BGP fast-external-failover. */
17351 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17352 vty_out(vty, " no bgp fast-external-failover\n");
17353
17354 /* BGP router ID. */
17355 if (bgp->router_id_static.s_addr != INADDR_ANY)
17356 vty_out(vty, " bgp router-id %pI4\n",
17357 &bgp->router_id_static);
17358
17359 /* Suppress fib pending */
17360 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17361 vty_out(vty, " bgp suppress-fib-pending\n");
17362
17363 /* BGP log-neighbor-changes. */
17364 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17365 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17366 vty_out(vty, " %sbgp log-neighbor-changes\n",
17367 CHECK_FLAG(bgp->flags,
17368 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17369 ? ""
17370 : "no ");
17371
17372 /* BGP configuration. */
17373 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17374 vty_out(vty, " bgp always-compare-med\n");
17375
17376 /* RFC8212 default eBGP policy. */
17377 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17378 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17379 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17380 CHECK_FLAG(bgp->flags,
17381 BGP_FLAG_EBGP_REQUIRES_POLICY)
17382 ? ""
17383 : "no ");
17384
17385 /* draft-ietf-idr-deprecate-as-set-confed-set */
17386 if (bgp->reject_as_sets)
17387 vty_out(vty, " bgp reject-as-sets\n");
17388
17389 /* Suppress duplicate updates if the route actually not changed
17390 */
17391 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17392 != SAVE_BGP_SUPPRESS_DUPLICATES)
17393 vty_out(vty, " %sbgp suppress-duplicates\n",
17394 CHECK_FLAG(bgp->flags,
17395 BGP_FLAG_SUPPRESS_DUPLICATES)
17396 ? ""
17397 : "no ");
17398
17399 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17400 */
17401 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17402 SAVE_BGP_HARD_ADMIN_RESET)
17403 vty_out(vty, " %sbgp hard-administrative-reset\n",
17404 CHECK_FLAG(bgp->flags,
17405 BGP_FLAG_HARD_ADMIN_RESET)
17406 ? ""
17407 : "no ");
17408
17409 /* BGP default <afi>-<safi> */
17410 FOREACH_AFI_SAFI (afi, safi) {
17411 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17412 if (!bgp->default_af[afi][safi])
17413 vty_out(vty, " no bgp default %s\n",
17414 get_bgp_default_af_flag(afi,
17415 safi));
17416 } else if (bgp->default_af[afi][safi])
17417 vty_out(vty, " bgp default %s\n",
17418 get_bgp_default_af_flag(afi, safi));
17419 }
17420
17421 /* BGP default local-preference. */
17422 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17423 vty_out(vty, " bgp default local-preference %u\n",
17424 bgp->default_local_pref);
17425
17426 /* BGP default show-hostname */
17427 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17428 != SAVE_BGP_SHOW_HOSTNAME)
17429 vty_out(vty, " %sbgp default show-hostname\n",
17430 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17431 ? ""
17432 : "no ");
17433
17434 /* BGP default show-nexthop-hostname */
17435 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17436 != SAVE_BGP_SHOW_HOSTNAME)
17437 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17438 CHECK_FLAG(bgp->flags,
17439 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17440 ? ""
17441 : "no ");
17442
17443 /* BGP default subgroup-pkt-queue-max. */
17444 if (bgp->default_subgroup_pkt_queue_max
17445 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17446 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17447 bgp->default_subgroup_pkt_queue_max);
17448
17449 /* BGP client-to-client reflection. */
17450 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17451 vty_out(vty, " no bgp client-to-client reflection\n");
17452
17453 /* BGP cluster ID. */
17454 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17455 vty_out(vty, " bgp cluster-id %pI4\n",
17456 &bgp->cluster_id);
17457
17458 /* Disable ebgp connected nexthop check */
17459 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17460 vty_out(vty,
17461 " bgp disable-ebgp-connected-route-check\n");
17462
17463 /* Confederation identifier*/
17464 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17465 vty_out(vty, " bgp confederation identifier %u\n",
17466 bgp->confed_id);
17467
17468 /* Confederation peer */
17469 if (bgp->confed_peers_cnt > 0) {
17470 int i;
17471
17472 vty_out(vty, " bgp confederation peers");
17473
17474 for (i = 0; i < bgp->confed_peers_cnt; i++)
17475 vty_out(vty, " %u", bgp->confed_peers[i]);
17476
17477 vty_out(vty, "\n");
17478 }
17479
17480 /* BGP deterministic-med. */
17481 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17482 != SAVE_BGP_DETERMINISTIC_MED)
17483 vty_out(vty, " %sbgp deterministic-med\n",
17484 CHECK_FLAG(bgp->flags,
17485 BGP_FLAG_DETERMINISTIC_MED)
17486 ? ""
17487 : "no ");
17488
17489 /* BGP update-delay. */
17490 bgp_config_write_update_delay(vty, bgp);
17491
17492 if (bgp->v_maxmed_onstartup
17493 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17494 vty_out(vty, " bgp max-med on-startup %u",
17495 bgp->v_maxmed_onstartup);
17496 if (bgp->maxmed_onstartup_value
17497 != BGP_MAXMED_VALUE_DEFAULT)
17498 vty_out(vty, " %u",
17499 bgp->maxmed_onstartup_value);
17500 vty_out(vty, "\n");
17501 }
17502 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17503 vty_out(vty, " bgp max-med administrative");
17504 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17505 vty_out(vty, " %u", bgp->maxmed_admin_value);
17506 vty_out(vty, "\n");
17507 }
17508
17509 /* write quanta */
17510 bgp_config_write_wpkt_quanta(vty, bgp);
17511 /* read quanta */
17512 bgp_config_write_rpkt_quanta(vty, bgp);
17513
17514 /* coalesce time */
17515 bgp_config_write_coalesce_time(vty, bgp);
17516
17517 /* BGP per-instance graceful-shutdown */
17518 /* BGP-wide settings and per-instance settings are mutually
17519 * exclusive.
17520 */
17521 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17522 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17523 vty_out(vty, " bgp graceful-shutdown\n");
17524
17525 /* Long-lived Graceful Restart */
17526 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17527 vty_out(vty,
17528 " bgp long-lived-graceful-restart stale-time %u\n",
17529 bgp->llgr_stale_time);
17530
17531 /* BGP graceful-restart. */
17532 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17533 vty_out(vty,
17534 " bgp graceful-restart stalepath-time %u\n",
17535 bgp->stalepath_time);
17536
17537 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17538 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17539 bgp->restart_time);
17540
17541 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17542 SAVE_BGP_GRACEFUL_NOTIFICATION)
17543 vty_out(vty, " %sbgp graceful-restart notification\n",
17544 CHECK_FLAG(bgp->flags,
17545 BGP_FLAG_GRACEFUL_NOTIFICATION)
17546 ? ""
17547 : "no ");
17548
17549 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17550 vty_out(vty,
17551 " bgp graceful-restart select-defer-time %u\n",
17552 bgp->select_defer_time);
17553
17554 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17555 vty_out(vty, " bgp graceful-restart\n");
17556
17557 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17558 vty_out(vty, " bgp graceful-restart-disable\n");
17559
17560 /* BGP graceful-restart Preserve State F bit. */
17561 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17562 vty_out(vty,
17563 " bgp graceful-restart preserve-fw-state\n");
17564
17565 /* Stale timer for RIB */
17566 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17567 vty_out(vty,
17568 " bgp graceful-restart rib-stale-time %u\n",
17569 bgp->rib_stale_time);
17570
17571 /* BGP bestpath method. */
17572 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17573 vty_out(vty, " bgp bestpath as-path ignore\n");
17574 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17575 vty_out(vty, " bgp bestpath as-path confed\n");
17576
17577 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17578 if (CHECK_FLAG(bgp->flags,
17579 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17580 vty_out(vty,
17581 " bgp bestpath as-path multipath-relax as-set\n");
17582 } else {
17583 vty_out(vty,
17584 " bgp bestpath as-path multipath-relax\n");
17585 }
17586 }
17587
17588 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17589 vty_out(vty,
17590 " bgp route-reflector allow-outbound-policy\n");
17591 }
17592 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17593 vty_out(vty, " bgp bestpath compare-routerid\n");
17594 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17595 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17596 vty_out(vty, " bgp bestpath med");
17597 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17598 vty_out(vty, " confed");
17599 if (CHECK_FLAG(bgp->flags,
17600 BGP_FLAG_MED_MISSING_AS_WORST))
17601 vty_out(vty, " missing-as-worst");
17602 vty_out(vty, "\n");
17603 }
17604
17605 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17606 vty_out(vty,
17607 " bgp bestpath peer-type multipath-relax\n");
17608
17609 /* Link bandwidth handling. */
17610 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17611 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17612 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17613 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17614 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17615 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17616
17617 /* BGP network import check. */
17618 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17619 != SAVE_BGP_IMPORT_CHECK)
17620 vty_out(vty, " %sbgp network import-check\n",
17621 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17622 ? ""
17623 : "no ");
17624
17625 /* BGP timers configuration. */
17626 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17627 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17628 vty_out(vty, " timers bgp %u %u\n",
17629 bgp->default_keepalive, bgp->default_holdtime);
17630
17631 /* BGP minimum holdtime configuration. */
17632 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17633 && bgp->default_min_holdtime != 0)
17634 vty_out(vty, " bgp minimum-holdtime %u\n",
17635 bgp->default_min_holdtime);
17636
17637 /* Conditional advertisement timer configuration */
17638 if (bgp->condition_check_period
17639 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17640 vty_out(vty,
17641 " bgp conditional-advertisement timer %u\n",
17642 bgp->condition_check_period);
17643
17644 /* peer-group */
17645 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17646 bgp_config_write_peer_global(vty, bgp, group->conf);
17647 }
17648
17649 /* Normal neighbor configuration. */
17650 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17651 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17652 bgp_config_write_peer_global(vty, bgp, peer);
17653 }
17654
17655 /* listen range and limit for dynamic BGP neighbors */
17656 bgp_config_write_listen(vty, bgp);
17657
17658 /*
17659 * BGP default autoshutdown neighbors
17660 *
17661 * This must be placed after any peer and peer-group
17662 * configuration, to avoid setting all peers to shutdown after
17663 * a daemon restart, which is undesired behavior. (see #2286)
17664 */
17665 if (bgp->autoshutdown)
17666 vty_out(vty, " bgp default shutdown\n");
17667
17668 /* BGP instance administrative shutdown */
17669 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17670 vty_out(vty, " bgp shutdown\n");
17671
17672 if (bgp->allow_martian)
17673 vty_out(vty, " bgp allow-martian-nexthop\n");
17674
17675 if (bgp->fast_convergence)
17676 vty_out(vty, " bgp fast-convergence\n");
17677
17678 if (bgp->srv6_enabled) {
17679 vty_frame(vty, " !\n segment-routing srv6\n");
17680 if (strlen(bgp->srv6_locator_name))
17681 vty_out(vty, " locator %s\n",
17682 bgp->srv6_locator_name);
17683 vty_endframe(vty, " exit\n");
17684 }
17685
17686
17687 /* IPv4 unicast configuration. */
17688 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17689
17690 /* IPv4 multicast configuration. */
17691 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17692
17693 /* IPv4 labeled-unicast configuration. */
17694 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17695
17696 /* IPv4 VPN configuration. */
17697 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17698
17699 /* ENCAPv4 configuration. */
17700 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17701
17702 /* FLOWSPEC v4 configuration. */
17703 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17704
17705 /* IPv6 unicast configuration. */
17706 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17707
17708 /* IPv6 multicast configuration. */
17709 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17710
17711 /* IPv6 labeled-unicast configuration. */
17712 bgp_config_write_family(vty, bgp, AFI_IP6,
17713 SAFI_LABELED_UNICAST);
17714
17715 /* IPv6 VPN configuration. */
17716 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17717
17718 /* ENCAPv6 configuration. */
17719 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17720
17721 /* FLOWSPEC v6 configuration. */
17722 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17723
17724 /* EVPN configuration. */
17725 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17726
17727 hook_call(bgp_inst_config_write, bgp, vty);
17728
17729 #ifdef ENABLE_BGP_VNC
17730 bgp_rfapi_cfg_write(vty, bgp);
17731 #endif
17732
17733 vty_out(vty, "exit\n");
17734 vty_out(vty, "!\n");
17735 }
17736 return 0;
17737 }
17738
17739
17740 /* BGP node structure. */
17741 static struct cmd_node bgp_node = {
17742 .name = "bgp",
17743 .node = BGP_NODE,
17744 .parent_node = CONFIG_NODE,
17745 .prompt = "%s(config-router)# ",
17746 .config_write = bgp_config_write,
17747 };
17748
17749 static struct cmd_node bgp_ipv4_unicast_node = {
17750 .name = "bgp ipv4 unicast",
17751 .node = BGP_IPV4_NODE,
17752 .parent_node = BGP_NODE,
17753 .prompt = "%s(config-router-af)# ",
17754 .no_xpath = true,
17755 };
17756
17757 static struct cmd_node bgp_ipv4_multicast_node = {
17758 .name = "bgp ipv4 multicast",
17759 .node = BGP_IPV4M_NODE,
17760 .parent_node = BGP_NODE,
17761 .prompt = "%s(config-router-af)# ",
17762 .no_xpath = true,
17763 };
17764
17765 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17766 .name = "bgp ipv4 labeled unicast",
17767 .node = BGP_IPV4L_NODE,
17768 .parent_node = BGP_NODE,
17769 .prompt = "%s(config-router-af)# ",
17770 .no_xpath = true,
17771 };
17772
17773 static struct cmd_node bgp_ipv6_unicast_node = {
17774 .name = "bgp ipv6 unicast",
17775 .node = BGP_IPV6_NODE,
17776 .parent_node = BGP_NODE,
17777 .prompt = "%s(config-router-af)# ",
17778 .no_xpath = true,
17779 };
17780
17781 static struct cmd_node bgp_ipv6_multicast_node = {
17782 .name = "bgp ipv6 multicast",
17783 .node = BGP_IPV6M_NODE,
17784 .parent_node = BGP_NODE,
17785 .prompt = "%s(config-router-af)# ",
17786 .no_xpath = true,
17787 };
17788
17789 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17790 .name = "bgp ipv6 labeled unicast",
17791 .node = BGP_IPV6L_NODE,
17792 .parent_node = BGP_NODE,
17793 .prompt = "%s(config-router-af)# ",
17794 .no_xpath = true,
17795 };
17796
17797 static struct cmd_node bgp_vpnv4_node = {
17798 .name = "bgp vpnv4",
17799 .node = BGP_VPNV4_NODE,
17800 .parent_node = BGP_NODE,
17801 .prompt = "%s(config-router-af)# ",
17802 .no_xpath = true,
17803 };
17804
17805 static struct cmd_node bgp_vpnv6_node = {
17806 .name = "bgp vpnv6",
17807 .node = BGP_VPNV6_NODE,
17808 .parent_node = BGP_NODE,
17809 .prompt = "%s(config-router-af-vpnv6)# ",
17810 .no_xpath = true,
17811 };
17812
17813 static struct cmd_node bgp_evpn_node = {
17814 .name = "bgp evpn",
17815 .node = BGP_EVPN_NODE,
17816 .parent_node = BGP_NODE,
17817 .prompt = "%s(config-router-evpn)# ",
17818 .no_xpath = true,
17819 };
17820
17821 static struct cmd_node bgp_evpn_vni_node = {
17822 .name = "bgp evpn vni",
17823 .node = BGP_EVPN_VNI_NODE,
17824 .parent_node = BGP_EVPN_NODE,
17825 .prompt = "%s(config-router-af-vni)# ",
17826 };
17827
17828 static struct cmd_node bgp_flowspecv4_node = {
17829 .name = "bgp ipv4 flowspec",
17830 .node = BGP_FLOWSPECV4_NODE,
17831 .parent_node = BGP_NODE,
17832 .prompt = "%s(config-router-af)# ",
17833 .no_xpath = true,
17834 };
17835
17836 static struct cmd_node bgp_flowspecv6_node = {
17837 .name = "bgp ipv6 flowspec",
17838 .node = BGP_FLOWSPECV6_NODE,
17839 .parent_node = BGP_NODE,
17840 .prompt = "%s(config-router-af-vpnv6)# ",
17841 .no_xpath = true,
17842 };
17843
17844 static struct cmd_node bgp_srv6_node = {
17845 .name = "bgp srv6",
17846 .node = BGP_SRV6_NODE,
17847 .parent_node = BGP_NODE,
17848 .prompt = "%s(config-router-srv6)# ",
17849 };
17850
17851 static void community_list_vty(void);
17852
17853 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17854 {
17855 struct bgp *bgp;
17856 struct peer_group *group;
17857 struct listnode *lnbgp, *lnpeer;
17858
17859 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17860 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17861 vector_set(comps,
17862 XSTRDUP(MTYPE_COMPLETION, group->name));
17863 }
17864 }
17865
17866 static void bgp_ac_peer(vector comps, struct cmd_token *token)
17867 {
17868 struct bgp *bgp;
17869 struct peer *peer;
17870 struct listnode *lnbgp, *lnpeer;
17871
17872 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17873 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17874 /* only provide suggestions on the appropriate input
17875 * token type,
17876 * they'll otherwise show up multiple times */
17877 enum cmd_token_type match_type;
17878 char *name = peer->host;
17879
17880 if (peer->conf_if) {
17881 match_type = VARIABLE_TKN;
17882 name = peer->conf_if;
17883 } else if (strchr(peer->host, ':'))
17884 match_type = IPV6_TKN;
17885 else
17886 match_type = IPV4_TKN;
17887
17888 if (token->type != match_type)
17889 continue;
17890
17891 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17892 }
17893 }
17894 }
17895
17896 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17897 {
17898 bgp_ac_peer(comps, token);
17899
17900 if (token->type == VARIABLE_TKN)
17901 bgp_ac_peergroup(comps, token);
17902 }
17903
17904 static const struct cmd_variable_handler bgp_var_neighbor[] = {
17905 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17906 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17907 {.varname = "peer", .completions = bgp_ac_neighbor},
17908 {.completions = NULL}};
17909
17910 static const struct cmd_variable_handler bgp_var_peergroup[] = {
17911 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17912 {.completions = NULL} };
17913
17914 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
17915
17916 static struct thread *t_bgp_cfg;
17917
17918 bool bgp_config_inprocess(void)
17919 {
17920 return thread_is_scheduled(t_bgp_cfg);
17921 }
17922
17923 static void bgp_config_finish(struct thread *t)
17924 {
17925 struct listnode *node;
17926 struct bgp *bgp;
17927
17928 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
17929 hook_call(bgp_config_end, bgp);
17930 }
17931
17932 static void bgp_config_start(void)
17933 {
17934 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
17935 THREAD_OFF(t_bgp_cfg);
17936 thread_add_timer(bm->master, bgp_config_finish, NULL,
17937 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
17938 }
17939
17940 /* When we receive a hook the configuration is read,
17941 * we start a timer to make sure we postpone sending
17942 * EoR before route-maps are processed.
17943 * This is especially valid if using `bgp route-map delay-timer`.
17944 */
17945 static void bgp_config_end(void)
17946 {
17947 #define BGP_POST_CONFIG_DELAY_SECONDS 1
17948 uint32_t bgp_post_config_delay =
17949 thread_is_scheduled(bm->t_rmap_update)
17950 ? thread_timer_remain_second(bm->t_rmap_update)
17951 : BGP_POST_CONFIG_DELAY_SECONDS;
17952
17953 /* If BGP config processing thread isn't running, then
17954 * we can return and rely it's properly handled.
17955 */
17956 if (!bgp_config_inprocess())
17957 return;
17958
17959 THREAD_OFF(t_bgp_cfg);
17960
17961 /* Start a new timer to make sure we don't send EoR
17962 * before route-maps are processed.
17963 */
17964 thread_add_timer(bm->master, bgp_config_finish, NULL,
17965 bgp_post_config_delay, &t_bgp_cfg);
17966 }
17967
17968 void bgp_vty_init(void)
17969 {
17970 cmd_variable_handler_register(bgp_var_neighbor);
17971 cmd_variable_handler_register(bgp_var_peergroup);
17972
17973 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
17974
17975 /* Install bgp top node. */
17976 install_node(&bgp_node);
17977 install_node(&bgp_ipv4_unicast_node);
17978 install_node(&bgp_ipv4_multicast_node);
17979 install_node(&bgp_ipv4_labeled_unicast_node);
17980 install_node(&bgp_ipv6_unicast_node);
17981 install_node(&bgp_ipv6_multicast_node);
17982 install_node(&bgp_ipv6_labeled_unicast_node);
17983 install_node(&bgp_vpnv4_node);
17984 install_node(&bgp_vpnv6_node);
17985 install_node(&bgp_evpn_node);
17986 install_node(&bgp_evpn_vni_node);
17987 install_node(&bgp_flowspecv4_node);
17988 install_node(&bgp_flowspecv6_node);
17989 install_node(&bgp_srv6_node);
17990
17991 /* Install default VTY commands to new nodes. */
17992 install_default(BGP_NODE);
17993 install_default(BGP_IPV4_NODE);
17994 install_default(BGP_IPV4M_NODE);
17995 install_default(BGP_IPV4L_NODE);
17996 install_default(BGP_IPV6_NODE);
17997 install_default(BGP_IPV6M_NODE);
17998 install_default(BGP_IPV6L_NODE);
17999 install_default(BGP_VPNV4_NODE);
18000 install_default(BGP_VPNV6_NODE);
18001 install_default(BGP_FLOWSPECV4_NODE);
18002 install_default(BGP_FLOWSPECV6_NODE);
18003 install_default(BGP_EVPN_NODE);
18004 install_default(BGP_EVPN_VNI_NODE);
18005 install_default(BGP_SRV6_NODE);
18006
18007 /* "bgp local-mac" hidden commands. */
18008 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18009 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18010
18011 /* "bgp suppress-fib-pending" global */
18012 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18013
18014 /* bgp route-map delay-timer commands. */
18015 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18016 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18017
18018 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18019
18020 /* bgp fast-convergence command */
18021 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18022 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18023
18024 /* global bgp update-delay command */
18025 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18026 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18027
18028 /* global bgp graceful-shutdown command */
18029 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18030 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18031
18032 /* Dummy commands (Currently not supported) */
18033 install_element(BGP_NODE, &no_synchronization_cmd);
18034 install_element(BGP_NODE, &no_auto_summary_cmd);
18035
18036 /* "router bgp" commands. */
18037 install_element(CONFIG_NODE, &router_bgp_cmd);
18038
18039 /* "no router bgp" commands. */
18040 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18041
18042 /* "bgp session-dscp command */
18043 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18044 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18045
18046 /* "bgp router-id" commands. */
18047 install_element(BGP_NODE, &bgp_router_id_cmd);
18048 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18049
18050 /* "bgp suppress-fib-pending" command */
18051 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18052
18053 /* "bgp cluster-id" commands. */
18054 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18055 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18056
18057 /* "bgp no-rib" commands. */
18058 install_element(CONFIG_NODE, &bgp_norib_cmd);
18059 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18060
18061 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18062
18063 /* "bgp confederation" commands. */
18064 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18065 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18066
18067 /* "bgp confederation peers" commands. */
18068 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18069 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18070
18071 /* bgp max-med command */
18072 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18073 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18074 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18075 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18076 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18077
18078 /* "neighbor role" commands. */
18079 install_element(BGP_NODE, &neighbor_role_cmd);
18080 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18081 install_element(BGP_NODE, &no_neighbor_role_cmd);
18082
18083 /* bgp disable-ebgp-connected-nh-check */
18084 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18085 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18086
18087 /* bgp update-delay command */
18088 install_element(BGP_NODE, &bgp_update_delay_cmd);
18089 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
18090
18091 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
18092 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
18093
18094 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18095 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18096
18097 /* "maximum-paths" commands. */
18098 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18099 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18100 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18101 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18102 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18103 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18104 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18105 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18106 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18107 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18108 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18109 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18110 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18111 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18112 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18113
18114 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18115 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18116 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18117 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18118 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18119 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18120 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18121 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18122 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18123 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18124
18125 /* "timers bgp" commands. */
18126 install_element(BGP_NODE, &bgp_timers_cmd);
18127 install_element(BGP_NODE, &no_bgp_timers_cmd);
18128
18129 /* "minimum-holdtime" commands. */
18130 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18131 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18132
18133 /* route-map delay-timer commands - per instance for backwards compat.
18134 */
18135 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18136 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18137
18138 /* "bgp client-to-client reflection" commands */
18139 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18140 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18141
18142 /* "bgp always-compare-med" commands */
18143 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18144 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18145
18146 /* bgp ebgp-requires-policy */
18147 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18148 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18149
18150 /* bgp suppress-duplicates */
18151 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18152 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18153
18154 /* bgp reject-as-sets */
18155 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18156 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18157
18158 /* "bgp deterministic-med" commands */
18159 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18160 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18161
18162 /* "bgp graceful-restart" command */
18163 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18164 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
18165
18166 /* "bgp graceful-restart-disable" command */
18167 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18168 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
18169
18170 /* "neighbor a:b:c:d graceful-restart" command */
18171 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18172 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
18173
18174 /* "neighbor a:b:c:d graceful-restart-disable" command */
18175 install_element(BGP_NODE,
18176 &bgp_neighbor_graceful_restart_disable_set_cmd);
18177 install_element(BGP_NODE,
18178 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18179
18180 /* "neighbor a:b:c:d graceful-restart-helper" command */
18181 install_element(BGP_NODE,
18182 &bgp_neighbor_graceful_restart_helper_set_cmd);
18183 install_element(BGP_NODE,
18184 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18185
18186 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18187 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18188 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18189 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
18190 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
18191 install_element(BGP_NODE,
18192 &no_bgp_graceful_restart_select_defer_time_cmd);
18193 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18194 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18195 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
18196
18197 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18198 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
18199 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18200 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
18201
18202 /* "bgp graceful-shutdown" commands */
18203 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18204 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18205
18206 /* "bgp hard-administrative-reset" commands */
18207 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18208
18209 /* "bgp long-lived-graceful-restart" commands */
18210 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18211 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18212
18213 /* "bgp fast-external-failover" commands */
18214 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18215 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18216
18217 /* "bgp bestpath compare-routerid" commands */
18218 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18219 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18220
18221 /* "bgp bestpath as-path ignore" commands */
18222 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18223 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18224
18225 /* "bgp bestpath as-path confed" commands */
18226 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18227 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18228
18229 /* "bgp bestpath as-path multipath-relax" commands */
18230 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18231 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18232
18233 /* "bgp bestpath peer-type multipath-relax" commands */
18234 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18235 install_element(BGP_NODE,
18236 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18237
18238 /* "bgp log-neighbor-changes" commands */
18239 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18240 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18241
18242 /* "bgp bestpath med" commands */
18243 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18244 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18245
18246 /* "bgp bestpath bandwidth" commands */
18247 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
18248 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
18249
18250 /* "no bgp default <afi>-<safi>" commands. */
18251 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
18252
18253 /* "bgp network import-check" commands. */
18254 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18255 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18256 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18257
18258 /* "bgp default local-preference" commands. */
18259 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18260 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18261
18262 /* bgp default show-hostname */
18263 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18264 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18265
18266 /* bgp default show-nexthop-hostname */
18267 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18268 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18269
18270 /* "bgp default subgroup-pkt-queue-max" commands. */
18271 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18272 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18273
18274 /* bgp ibgp-allow-policy-mods command */
18275 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18276 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18277
18278 /* "bgp listen limit" commands. */
18279 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18280 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18281
18282 /* "bgp listen range" commands. */
18283 install_element(BGP_NODE, &bgp_listen_range_cmd);
18284 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18285
18286 /* "bgp default shutdown" command */
18287 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
18288
18289 /* "bgp shutdown" commands */
18290 install_element(BGP_NODE, &bgp_shutdown_cmd);
18291 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
18292 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
18293 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
18294
18295 /* "neighbor remote-as" commands. */
18296 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18297 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18298 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18299 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18300 install_element(BGP_NODE,
18301 &neighbor_interface_v6only_config_remote_as_cmd);
18302 install_element(BGP_NODE, &no_neighbor_cmd);
18303 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18304
18305 /* "neighbor peer-group" commands. */
18306 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18307 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18308 install_element(BGP_NODE,
18309 &no_neighbor_interface_peer_group_remote_as_cmd);
18310
18311 /* "neighbor local-as" commands. */
18312 install_element(BGP_NODE, &neighbor_local_as_cmd);
18313 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18314 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18315 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18316
18317 /* "neighbor solo" commands. */
18318 install_element(BGP_NODE, &neighbor_solo_cmd);
18319 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18320
18321 /* "neighbor password" commands. */
18322 install_element(BGP_NODE, &neighbor_password_cmd);
18323 install_element(BGP_NODE, &no_neighbor_password_cmd);
18324
18325 /* "neighbor activate" commands. */
18326 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18327 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18328 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18329 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18330 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18331 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18332 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18333 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18334 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
18335 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18336 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
18337 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18338
18339 /* "no neighbor activate" commands. */
18340 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18341 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18342 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18343 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18344 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18345 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18346 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18347 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18348 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
18349 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18350 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
18351 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18352
18353 /* "neighbor peer-group" set commands. */
18354 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18355 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18356 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18357 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18358 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18359 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18360 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18361 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18362 install_element(BGP_FLOWSPECV4_NODE,
18363 &neighbor_set_peer_group_hidden_cmd);
18364 install_element(BGP_FLOWSPECV6_NODE,
18365 &neighbor_set_peer_group_hidden_cmd);
18366
18367 /* "no neighbor peer-group unset" commands. */
18368 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18369 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18370 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18371 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18372 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18373 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18374 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18375 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18376 install_element(BGP_FLOWSPECV4_NODE,
18377 &no_neighbor_set_peer_group_hidden_cmd);
18378 install_element(BGP_FLOWSPECV6_NODE,
18379 &no_neighbor_set_peer_group_hidden_cmd);
18380
18381 /* "neighbor softreconfiguration inbound" commands.*/
18382 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18383 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18384 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18385 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18386 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18387 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18388 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18389 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18390 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18391 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18392 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18393 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18394 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18395 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18396 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18397 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18398 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18399 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18400 install_element(BGP_FLOWSPECV4_NODE,
18401 &neighbor_soft_reconfiguration_cmd);
18402 install_element(BGP_FLOWSPECV4_NODE,
18403 &no_neighbor_soft_reconfiguration_cmd);
18404 install_element(BGP_FLOWSPECV6_NODE,
18405 &neighbor_soft_reconfiguration_cmd);
18406 install_element(BGP_FLOWSPECV6_NODE,
18407 &no_neighbor_soft_reconfiguration_cmd);
18408 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18409 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18410
18411 /* "neighbor attribute-unchanged" commands. */
18412 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18413 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18414 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18415 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18416 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18417 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18418 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18419 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18420 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18421 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18422 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18423 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18424 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18425 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18426 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18427 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18428 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18429 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18430
18431 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18432 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18433
18434 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18435 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18436 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18437 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18438
18439 /* "nexthop-local unchanged" commands */
18440 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18441 install_element(BGP_IPV6_NODE,
18442 &no_neighbor_nexthop_local_unchanged_cmd);
18443
18444 /* "neighbor next-hop-self" commands. */
18445 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18446 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18447 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18448 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18449 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18450 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18451 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18452 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18453 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18454 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18455 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18456 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18457 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18458 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18459 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18460 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18461 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18462 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18463 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18464 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18465
18466 /* "neighbor next-hop-self force" commands. */
18467 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18468 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18469 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18470 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18471 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18472 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18473 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18474 install_element(BGP_IPV4_NODE,
18475 &no_neighbor_nexthop_self_all_hidden_cmd);
18476 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18477 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18478 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18479 install_element(BGP_IPV4M_NODE,
18480 &no_neighbor_nexthop_self_all_hidden_cmd);
18481 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18482 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18483 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18484 install_element(BGP_IPV4L_NODE,
18485 &no_neighbor_nexthop_self_all_hidden_cmd);
18486 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18487 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18488 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18489 install_element(BGP_IPV6_NODE,
18490 &no_neighbor_nexthop_self_all_hidden_cmd);
18491 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18492 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18493 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18494 install_element(BGP_IPV6M_NODE,
18495 &no_neighbor_nexthop_self_all_hidden_cmd);
18496 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18497 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18498 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18499 install_element(BGP_IPV6L_NODE,
18500 &no_neighbor_nexthop_self_all_hidden_cmd);
18501 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18502 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18503 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18504 install_element(BGP_VPNV4_NODE,
18505 &no_neighbor_nexthop_self_all_hidden_cmd);
18506 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18507 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18508 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18509 install_element(BGP_VPNV6_NODE,
18510 &no_neighbor_nexthop_self_all_hidden_cmd);
18511 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18512 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18513
18514 /* "neighbor as-override" commands. */
18515 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18516 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18517 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18518 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18519 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18520 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18521 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18522 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18523 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18524 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18525 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18526 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18527 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18528 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18529 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18530 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18531 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18532 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18533
18534 /* "neighbor remove-private-AS" commands. */
18535 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18536 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18537 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18538 install_element(BGP_NODE,
18539 &no_neighbor_remove_private_as_all_hidden_cmd);
18540 install_element(BGP_NODE,
18541 &neighbor_remove_private_as_replace_as_hidden_cmd);
18542 install_element(BGP_NODE,
18543 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18544 install_element(BGP_NODE,
18545 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18546 install_element(
18547 BGP_NODE,
18548 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18549 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18550 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18551 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18552 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18553 install_element(BGP_IPV4_NODE,
18554 &neighbor_remove_private_as_replace_as_cmd);
18555 install_element(BGP_IPV4_NODE,
18556 &no_neighbor_remove_private_as_replace_as_cmd);
18557 install_element(BGP_IPV4_NODE,
18558 &neighbor_remove_private_as_all_replace_as_cmd);
18559 install_element(BGP_IPV4_NODE,
18560 &no_neighbor_remove_private_as_all_replace_as_cmd);
18561 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18562 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18563 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18564 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18565 install_element(BGP_IPV4M_NODE,
18566 &neighbor_remove_private_as_replace_as_cmd);
18567 install_element(BGP_IPV4M_NODE,
18568 &no_neighbor_remove_private_as_replace_as_cmd);
18569 install_element(BGP_IPV4M_NODE,
18570 &neighbor_remove_private_as_all_replace_as_cmd);
18571 install_element(BGP_IPV4M_NODE,
18572 &no_neighbor_remove_private_as_all_replace_as_cmd);
18573 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18574 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18575 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18576 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18577 install_element(BGP_IPV4L_NODE,
18578 &neighbor_remove_private_as_replace_as_cmd);
18579 install_element(BGP_IPV4L_NODE,
18580 &no_neighbor_remove_private_as_replace_as_cmd);
18581 install_element(BGP_IPV4L_NODE,
18582 &neighbor_remove_private_as_all_replace_as_cmd);
18583 install_element(BGP_IPV4L_NODE,
18584 &no_neighbor_remove_private_as_all_replace_as_cmd);
18585 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18586 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18587 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18588 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18589 install_element(BGP_IPV6_NODE,
18590 &neighbor_remove_private_as_replace_as_cmd);
18591 install_element(BGP_IPV6_NODE,
18592 &no_neighbor_remove_private_as_replace_as_cmd);
18593 install_element(BGP_IPV6_NODE,
18594 &neighbor_remove_private_as_all_replace_as_cmd);
18595 install_element(BGP_IPV6_NODE,
18596 &no_neighbor_remove_private_as_all_replace_as_cmd);
18597 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18598 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18599 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18600 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18601 install_element(BGP_IPV6M_NODE,
18602 &neighbor_remove_private_as_replace_as_cmd);
18603 install_element(BGP_IPV6M_NODE,
18604 &no_neighbor_remove_private_as_replace_as_cmd);
18605 install_element(BGP_IPV6M_NODE,
18606 &neighbor_remove_private_as_all_replace_as_cmd);
18607 install_element(BGP_IPV6M_NODE,
18608 &no_neighbor_remove_private_as_all_replace_as_cmd);
18609 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18610 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18611 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18612 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18613 install_element(BGP_IPV6L_NODE,
18614 &neighbor_remove_private_as_replace_as_cmd);
18615 install_element(BGP_IPV6L_NODE,
18616 &no_neighbor_remove_private_as_replace_as_cmd);
18617 install_element(BGP_IPV6L_NODE,
18618 &neighbor_remove_private_as_all_replace_as_cmd);
18619 install_element(BGP_IPV6L_NODE,
18620 &no_neighbor_remove_private_as_all_replace_as_cmd);
18621 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18622 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18623 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18624 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18625 install_element(BGP_VPNV4_NODE,
18626 &neighbor_remove_private_as_replace_as_cmd);
18627 install_element(BGP_VPNV4_NODE,
18628 &no_neighbor_remove_private_as_replace_as_cmd);
18629 install_element(BGP_VPNV4_NODE,
18630 &neighbor_remove_private_as_all_replace_as_cmd);
18631 install_element(BGP_VPNV4_NODE,
18632 &no_neighbor_remove_private_as_all_replace_as_cmd);
18633 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18634 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18635 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18636 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18637 install_element(BGP_VPNV6_NODE,
18638 &neighbor_remove_private_as_replace_as_cmd);
18639 install_element(BGP_VPNV6_NODE,
18640 &no_neighbor_remove_private_as_replace_as_cmd);
18641 install_element(BGP_VPNV6_NODE,
18642 &neighbor_remove_private_as_all_replace_as_cmd);
18643 install_element(BGP_VPNV6_NODE,
18644 &no_neighbor_remove_private_as_all_replace_as_cmd);
18645
18646 /* "neighbor send-community" commands.*/
18647 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18648 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18649 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18650 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18651 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18652 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18653 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18654 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18655 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18656 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18657 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18658 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18659 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18660 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18661 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18662 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18663 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18664 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18665 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18666 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18667 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18668 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18669 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18670 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18671 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18672 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18673 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18674 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18675 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18676 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18677 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18678 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18679 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18680 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18681 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18682 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18683
18684 /* "neighbor route-reflector" commands.*/
18685 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18686 install_element(BGP_NODE,
18687 &no_neighbor_route_reflector_client_hidden_cmd);
18688 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18689 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18690 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18691 install_element(BGP_IPV4M_NODE,
18692 &no_neighbor_route_reflector_client_cmd);
18693 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18694 install_element(BGP_IPV4L_NODE,
18695 &no_neighbor_route_reflector_client_cmd);
18696 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18697 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18698 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18699 install_element(BGP_IPV6M_NODE,
18700 &no_neighbor_route_reflector_client_cmd);
18701 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18702 install_element(BGP_IPV6L_NODE,
18703 &no_neighbor_route_reflector_client_cmd);
18704 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18705 install_element(BGP_VPNV4_NODE,
18706 &no_neighbor_route_reflector_client_cmd);
18707 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18708 install_element(BGP_VPNV6_NODE,
18709 &no_neighbor_route_reflector_client_cmd);
18710 install_element(BGP_FLOWSPECV4_NODE,
18711 &neighbor_route_reflector_client_cmd);
18712 install_element(BGP_FLOWSPECV4_NODE,
18713 &no_neighbor_route_reflector_client_cmd);
18714 install_element(BGP_FLOWSPECV6_NODE,
18715 &neighbor_route_reflector_client_cmd);
18716 install_element(BGP_FLOWSPECV6_NODE,
18717 &no_neighbor_route_reflector_client_cmd);
18718 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18719 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18720
18721 /* "neighbor route-server" commands.*/
18722 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18723 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18724 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18725 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18726 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18727 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18728 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18729 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18730 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18731 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18732 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18733 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18734 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18735 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18736 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18737 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18738 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18739 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18740 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18741 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18742 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18743 install_element(BGP_FLOWSPECV4_NODE,
18744 &no_neighbor_route_server_client_cmd);
18745 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18746 install_element(BGP_FLOWSPECV6_NODE,
18747 &no_neighbor_route_server_client_cmd);
18748
18749 /* "neighbor disable-addpath-rx" commands. */
18750 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18751 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18752 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18753 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18754 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18755 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18756 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18757 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18758 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18759 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18760 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18761 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18762 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18763 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18764 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18765 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18766
18767 /* "neighbor addpath-tx-all-paths" commands.*/
18768 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18769 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18770 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18771 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18772 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18773 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18774 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18775 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18776 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18777 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18778 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18779 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18780 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18781 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18782 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18783 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18784 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18785 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18786
18787 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18788 install_element(BGP_NODE,
18789 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18790 install_element(BGP_NODE,
18791 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18792 install_element(BGP_IPV4_NODE,
18793 &neighbor_addpath_tx_bestpath_per_as_cmd);
18794 install_element(BGP_IPV4_NODE,
18795 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18796 install_element(BGP_IPV4M_NODE,
18797 &neighbor_addpath_tx_bestpath_per_as_cmd);
18798 install_element(BGP_IPV4M_NODE,
18799 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18800 install_element(BGP_IPV4L_NODE,
18801 &neighbor_addpath_tx_bestpath_per_as_cmd);
18802 install_element(BGP_IPV4L_NODE,
18803 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18804 install_element(BGP_IPV6_NODE,
18805 &neighbor_addpath_tx_bestpath_per_as_cmd);
18806 install_element(BGP_IPV6_NODE,
18807 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18808 install_element(BGP_IPV6M_NODE,
18809 &neighbor_addpath_tx_bestpath_per_as_cmd);
18810 install_element(BGP_IPV6M_NODE,
18811 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18812 install_element(BGP_IPV6L_NODE,
18813 &neighbor_addpath_tx_bestpath_per_as_cmd);
18814 install_element(BGP_IPV6L_NODE,
18815 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18816 install_element(BGP_VPNV4_NODE,
18817 &neighbor_addpath_tx_bestpath_per_as_cmd);
18818 install_element(BGP_VPNV4_NODE,
18819 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18820 install_element(BGP_VPNV6_NODE,
18821 &neighbor_addpath_tx_bestpath_per_as_cmd);
18822 install_element(BGP_VPNV6_NODE,
18823 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18824
18825 /* "neighbor sender-as-path-loop-detection" commands. */
18826 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18827 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18828
18829 /* "neighbor passive" commands. */
18830 install_element(BGP_NODE, &neighbor_passive_cmd);
18831 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18832
18833
18834 /* "neighbor shutdown" commands. */
18835 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18836 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18837 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18838 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18839 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18840 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18841
18842 /* "neighbor capability extended-nexthop" commands.*/
18843 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18844 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18845
18846 /* "neighbor capability orf prefix-list" commands.*/
18847 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18848 install_element(BGP_NODE,
18849 &no_neighbor_capability_orf_prefix_hidden_cmd);
18850 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18851 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18852 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18853 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18854 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18855 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18856 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18857 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18858 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18859 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18860 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18861 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18862
18863 /* "neighbor capability dynamic" commands.*/
18864 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18865 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18866
18867 /* "neighbor dont-capability-negotiate" commands. */
18868 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18869 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18870
18871 /* "neighbor ebgp-multihop" commands. */
18872 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18873 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18874 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18875
18876 /* "neighbor disable-connected-check" commands. */
18877 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18878 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18879
18880 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18881 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18882 install_element(BGP_NODE,
18883 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
18884
18885 /* "neighbor extended-optional-parameters" commands. */
18886 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18887 install_element(BGP_NODE,
18888 &no_neighbor_extended_optional_parameters_cmd);
18889
18890 /* "neighbor enforce-first-as" commands. */
18891 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18892 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18893
18894 /* "neighbor description" commands. */
18895 install_element(BGP_NODE, &neighbor_description_cmd);
18896 install_element(BGP_NODE, &no_neighbor_description_cmd);
18897 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18898
18899 /* "neighbor update-source" commands. "*/
18900 install_element(BGP_NODE, &neighbor_update_source_cmd);
18901 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18902
18903 /* "neighbor default-originate" commands. */
18904 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18905 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18906 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18907 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18908 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18909 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18910 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18911 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18912 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18913 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18914 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18915 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18916 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18917 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18918 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18919 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18920 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18921 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18922 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18923 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18924 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18925
18926 /* "neighbor port" commands. */
18927 install_element(BGP_NODE, &neighbor_port_cmd);
18928 install_element(BGP_NODE, &no_neighbor_port_cmd);
18929
18930 /* "neighbor weight" commands. */
18931 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18932 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18933
18934 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18935 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18936 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18937 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18938 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18939 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18940 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18941 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18942 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18943 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18944 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18945 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18946 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18947 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18948 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18949 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18950
18951 /* "neighbor override-capability" commands. */
18952 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18953 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18954
18955 /* "neighbor strict-capability-match" commands. */
18956 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18957 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18958
18959 /* "neighbor timers" commands. */
18960 install_element(BGP_NODE, &neighbor_timers_cmd);
18961 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18962
18963 /* "neighbor timers connect" commands. */
18964 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18965 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18966
18967 /* "neighbor timers delayopen" commands. */
18968 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18969 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18970
18971 /* "neighbor advertisement-interval" commands. */
18972 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18973 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18974
18975 /* "neighbor interface" commands. */
18976 install_element(BGP_NODE, &neighbor_interface_cmd);
18977 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18978
18979 /* "neighbor distribute" commands. */
18980 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18981 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18982 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18983 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18984 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18985 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18986 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18987 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18988 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18989 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18990 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18991 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18992 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18993 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18994 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18995 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18996 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18997 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18998
18999 /* "neighbor prefix-list" commands. */
19000 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
19001 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
19002 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
19003 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
19004 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
19005 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
19006 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
19007 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
19008 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
19009 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
19010 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
19011 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
19012 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
19013 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
19014 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
19015 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
19016 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
19017 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
19018 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
19019 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
19020 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
19021 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
19022
19023 /* "neighbor filter-list" commands. */
19024 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19025 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19026 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19027 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19028 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19029 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19030 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19031 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19032 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19033 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19034 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19035 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19036 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19037 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19038 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19039 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19040 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19041 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
19042 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19043 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19044 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19045 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
19046
19047 /* "neighbor route-map" commands. */
19048 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19049 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
19050 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
19051 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
19052 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
19053 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
19054 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
19055 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
19056 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
19057 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
19058 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
19059 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
19060 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
19061 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
19062 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
19063 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
19064 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
19065 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
19066 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
19067 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
19068 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
19069 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
19070 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
19071 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
19072
19073 /* "neighbor unsuppress-map" commands. */
19074 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19075 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19076 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19077 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19078 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19079 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19080 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19081 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19082 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19083 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19084 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19085 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19086 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19087 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19088 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19089 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19090 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19091 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19092
19093 /* "neighbor advertise-map" commands. */
19094 install_element(BGP_NODE, &bgp_condadv_period_cmd);
19095 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
19096 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
19097 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
19098 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
19099 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
19100 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
19101 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
19102 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
19103 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
19104
19105 /* neighbor maximum-prefix-out commands. */
19106 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19107 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19108 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19109 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19110 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19111 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19112 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19113 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19114 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19115 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19116 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19117 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19118 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19119 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19120 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19121 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19122 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19123 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19124
19125 /* "neighbor maximum-prefix" commands. */
19126 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19127 install_element(BGP_NODE,
19128 &neighbor_maximum_prefix_threshold_hidden_cmd);
19129 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19130 install_element(BGP_NODE,
19131 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19132 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19133 install_element(BGP_NODE,
19134 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19135 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19136 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19137 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19138 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19139 install_element(BGP_IPV4_NODE,
19140 &neighbor_maximum_prefix_threshold_warning_cmd);
19141 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19142 install_element(BGP_IPV4_NODE,
19143 &neighbor_maximum_prefix_threshold_restart_cmd);
19144 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19145 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19146 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19147 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19148 install_element(BGP_IPV4M_NODE,
19149 &neighbor_maximum_prefix_threshold_warning_cmd);
19150 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19151 install_element(BGP_IPV4M_NODE,
19152 &neighbor_maximum_prefix_threshold_restart_cmd);
19153 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19154 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19155 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19156 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19157 install_element(BGP_IPV4L_NODE,
19158 &neighbor_maximum_prefix_threshold_warning_cmd);
19159 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19160 install_element(BGP_IPV4L_NODE,
19161 &neighbor_maximum_prefix_threshold_restart_cmd);
19162 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19163 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19164 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19165 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19166 install_element(BGP_IPV6_NODE,
19167 &neighbor_maximum_prefix_threshold_warning_cmd);
19168 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19169 install_element(BGP_IPV6_NODE,
19170 &neighbor_maximum_prefix_threshold_restart_cmd);
19171 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19172 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19173 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19174 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19175 install_element(BGP_IPV6M_NODE,
19176 &neighbor_maximum_prefix_threshold_warning_cmd);
19177 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19178 install_element(BGP_IPV6M_NODE,
19179 &neighbor_maximum_prefix_threshold_restart_cmd);
19180 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19181 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19182 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19183 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19184 install_element(BGP_IPV6L_NODE,
19185 &neighbor_maximum_prefix_threshold_warning_cmd);
19186 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19187 install_element(BGP_IPV6L_NODE,
19188 &neighbor_maximum_prefix_threshold_restart_cmd);
19189 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19190 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19191 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19192 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19193 install_element(BGP_VPNV4_NODE,
19194 &neighbor_maximum_prefix_threshold_warning_cmd);
19195 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19196 install_element(BGP_VPNV4_NODE,
19197 &neighbor_maximum_prefix_threshold_restart_cmd);
19198 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19199 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19200 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19201 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19202 install_element(BGP_VPNV6_NODE,
19203 &neighbor_maximum_prefix_threshold_warning_cmd);
19204 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19205 install_element(BGP_VPNV6_NODE,
19206 &neighbor_maximum_prefix_threshold_restart_cmd);
19207 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19208
19209 /* "neighbor allowas-in" */
19210 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19211 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19212 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19213 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19214 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19215 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19216 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19217 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19218 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19219 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19220 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19221 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19222 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19223 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19224 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19225 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19226 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19227 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19228 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19229 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19230
19231 /* address-family commands. */
19232 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19233 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
19234 #ifdef KEEP_OLD_VPN_COMMANDS
19235 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19236 install_element(BGP_NODE, &address_family_vpnv6_cmd);
19237 #endif /* KEEP_OLD_VPN_COMMANDS */
19238
19239 install_element(BGP_NODE, &address_family_evpn_cmd);
19240
19241 /* "exit-address-family" command. */
19242 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19243 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19244 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19245 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19246 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19247 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19248 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19249 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
19250 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19251 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
19252 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19253
19254 /* "clear ip bgp commands" */
19255 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19256
19257 /* clear ip bgp prefix */
19258 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19259 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19260 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19261
19262 /* "show [ip] bgp summary" commands. */
19263 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
19264 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
19265 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
19266 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
19267 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19268 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
19269 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19270
19271 /* "show [ip] bgp neighbors" commands. */
19272 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19273
19274 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
19275
19276 /* "show [ip] bgp peer-group" commands. */
19277 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19278
19279 /* "show [ip] bgp paths" commands. */
19280 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19281
19282 /* "show [ip] bgp community" commands. */
19283 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19284
19285 /* "show ip bgp large-community" commands. */
19286 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19287 /* "show [ip] bgp attribute-info" commands. */
19288 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
19289 /* "show [ip] bgp route-leak" command */
19290 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
19291
19292 /* "redistribute" commands. */
19293 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19294 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19295 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19296 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19297 install_element(BGP_NODE,
19298 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19299 install_element(BGP_NODE,
19300 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19301 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19302 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19303 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19304 install_element(BGP_NODE,
19305 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19306 install_element(BGP_NODE,
19307 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19308 install_element(BGP_NODE,
19309 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19310 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19311 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19312 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19313 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19314 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19315 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19316 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19317 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19318 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19319 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19320 install_element(BGP_IPV4_NODE,
19321 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19322 install_element(BGP_IPV4_NODE,
19323 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19324 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19325 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19326 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19327 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19328 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19329 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19330
19331 /* import|export vpn [route-map RMAP_NAME] */
19332 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19333 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
19334
19335 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19336 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19337
19338 /* ttl_security commands */
19339 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19340 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19341
19342 /* "show [ip] bgp memory" commands. */
19343 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19344
19345 /* "show bgp martian next-hop" */
19346 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19347
19348 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19349
19350 /* "show [ip] bgp views" commands. */
19351 install_element(VIEW_NODE, &show_bgp_views_cmd);
19352
19353 /* "show [ip] bgp vrfs" commands. */
19354 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19355
19356 /* Community-list. */
19357 community_list_vty();
19358
19359 community_alias_vty();
19360
19361 /* vpn-policy commands */
19362 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19363 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19364 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19365 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19366 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19367 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19368 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19369 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19370 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19371 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
19372 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19373 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
19374
19375 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19376 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19377
19378 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19379 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19380 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19381 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
19382 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19383 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19384 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19385 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
19386 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19387 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
19388
19389 /* tcp-mss command */
19390 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19391 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
19392
19393 /* srv6 commands */
19394 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
19395 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
19396 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
19397 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
19398 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
19399 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19400 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
19401 }
19402
19403 #include "memory.h"
19404 #include "bgp_regex.h"
19405 #include "bgp_clist.h"
19406 #include "bgp_ecommunity.h"
19407
19408 /* VTY functions. */
19409
19410 /* Direction value to string conversion. */
19411 static const char *community_direct_str(int direct)
19412 {
19413 switch (direct) {
19414 case COMMUNITY_DENY:
19415 return "deny";
19416 case COMMUNITY_PERMIT:
19417 return "permit";
19418 default:
19419 return "unknown";
19420 }
19421 }
19422
19423 /* Display error string. */
19424 static void community_list_perror(struct vty *vty, int ret)
19425 {
19426 switch (ret) {
19427 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19428 vty_out(vty, "%% Can't find community-list\n");
19429 break;
19430 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19431 vty_out(vty, "%% Malformed community-list value\n");
19432 break;
19433 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19434 vty_out(vty,
19435 "%% Community name conflict, previously defined as standard community\n");
19436 break;
19437 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19438 vty_out(vty,
19439 "%% Community name conflict, previously defined as expanded community\n");
19440 break;
19441 }
19442 }
19443
19444 /* "community-list" keyword help string. */
19445 #define COMMUNITY_LIST_STR "Add a community list entry\n"
19446
19447 /*community-list standard */
19448 DEFUN (community_list_standard,
19449 bgp_community_list_standard_cmd,
19450 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19451 BGP_STR
19452 COMMUNITY_LIST_STR
19453 "Community list number (standard)\n"
19454 "Add an standard community-list entry\n"
19455 "Community list name\n"
19456 "Sequence number of an entry\n"
19457 "Sequence number\n"
19458 "Specify community to reject\n"
19459 "Specify community to accept\n"
19460 COMMUNITY_VAL_STR)
19461 {
19462 char *cl_name_or_number = NULL;
19463 char *seq = NULL;
19464 int direct = 0;
19465 int style = COMMUNITY_LIST_STANDARD;
19466 int idx = 0;
19467
19468 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19469 seq = argv[idx]->arg;
19470
19471 idx = 0;
19472 argv_find(argv, argc, "(1-99)", &idx);
19473 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19474 cl_name_or_number = argv[idx]->arg;
19475 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19476 : COMMUNITY_DENY;
19477 argv_find(argv, argc, "AA:NN", &idx);
19478 char *str = argv_concat(argv, argc, idx);
19479
19480 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19481 direct, style);
19482
19483 XFREE(MTYPE_TMP, str);
19484
19485 if (ret < 0) {
19486 /* Display error string. */
19487 community_list_perror(vty, ret);
19488 return CMD_WARNING_CONFIG_FAILED;
19489 }
19490
19491 return CMD_SUCCESS;
19492 }
19493
19494 DEFUN (no_community_list_standard_all,
19495 no_bgp_community_list_standard_all_cmd,
19496 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19497 NO_STR
19498 BGP_STR
19499 COMMUNITY_LIST_STR
19500 "Community list number (standard)\n"
19501 "Add an standard community-list entry\n"
19502 "Community list name\n"
19503 "Sequence number of an entry\n"
19504 "Sequence number\n"
19505 "Specify community to reject\n"
19506 "Specify community to accept\n"
19507 COMMUNITY_VAL_STR)
19508 {
19509 char *cl_name_or_number = NULL;
19510 char *str = NULL;
19511 int direct = 0;
19512 int style = COMMUNITY_LIST_STANDARD;
19513 char *seq = NULL;
19514 int idx = 0;
19515
19516 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19517 seq = argv[idx]->arg;
19518
19519 idx = 0;
19520 argv_find(argv, argc, "permit", &idx);
19521 argv_find(argv, argc, "deny", &idx);
19522
19523 if (idx) {
19524 direct = argv_find(argv, argc, "permit", &idx)
19525 ? COMMUNITY_PERMIT
19526 : COMMUNITY_DENY;
19527
19528 idx = 0;
19529 argv_find(argv, argc, "AA:NN", &idx);
19530 str = argv_concat(argv, argc, idx);
19531 }
19532
19533 idx = 0;
19534 argv_find(argv, argc, "(1-99)", &idx);
19535 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19536 cl_name_or_number = argv[idx]->arg;
19537
19538 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19539 direct, style);
19540
19541 XFREE(MTYPE_TMP, str);
19542
19543 if (ret < 0) {
19544 community_list_perror(vty, ret);
19545 return CMD_WARNING_CONFIG_FAILED;
19546 }
19547
19548 return CMD_SUCCESS;
19549 }
19550
19551 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19552 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
19553 NO_STR BGP_STR COMMUNITY_LIST_STR
19554 "Community list number (standard)\n"
19555 "Add an standard community-list entry\n"
19556 "Community list name\n")
19557
19558 /*community-list expanded */
19559 DEFUN (community_list_expanded_all,
19560 bgp_community_list_expanded_all_cmd,
19561 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19562 BGP_STR
19563 COMMUNITY_LIST_STR
19564 "Community list number (expanded)\n"
19565 "Add an expanded community-list entry\n"
19566 "Community list name\n"
19567 "Sequence number of an entry\n"
19568 "Sequence number\n"
19569 "Specify community to reject\n"
19570 "Specify community to accept\n"
19571 COMMUNITY_VAL_STR)
19572 {
19573 char *cl_name_or_number = NULL;
19574 char *seq = NULL;
19575 int direct = 0;
19576 int style = COMMUNITY_LIST_EXPANDED;
19577 int idx = 0;
19578
19579 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19580 seq = argv[idx]->arg;
19581
19582 idx = 0;
19583
19584 argv_find(argv, argc, "(100-500)", &idx);
19585 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19586 cl_name_or_number = argv[idx]->arg;
19587 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19588 : COMMUNITY_DENY;
19589 argv_find(argv, argc, "AA:NN", &idx);
19590 char *str = argv_concat(argv, argc, idx);
19591
19592 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19593 direct, style);
19594
19595 XFREE(MTYPE_TMP, str);
19596
19597 if (ret < 0) {
19598 /* Display error string. */
19599 community_list_perror(vty, ret);
19600 return CMD_WARNING_CONFIG_FAILED;
19601 }
19602
19603 return CMD_SUCCESS;
19604 }
19605
19606 DEFUN (no_community_list_expanded_all,
19607 no_bgp_community_list_expanded_all_cmd,
19608 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
19609 NO_STR
19610 BGP_STR
19611 COMMUNITY_LIST_STR
19612 "Community list number (expanded)\n"
19613 "Add an expanded community-list entry\n"
19614 "Community list name\n"
19615 "Sequence number of an entry\n"
19616 "Sequence number\n"
19617 "Specify community to reject\n"
19618 "Specify community to accept\n"
19619 COMMUNITY_VAL_STR)
19620 {
19621 char *cl_name_or_number = NULL;
19622 char *seq = NULL;
19623 char *str = NULL;
19624 int direct = 0;
19625 int style = COMMUNITY_LIST_EXPANDED;
19626 int idx = 0;
19627
19628 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19629 seq = argv[idx]->arg;
19630
19631 idx = 0;
19632 argv_find(argv, argc, "permit", &idx);
19633 argv_find(argv, argc, "deny", &idx);
19634
19635 if (idx) {
19636 direct = argv_find(argv, argc, "permit", &idx)
19637 ? COMMUNITY_PERMIT
19638 : COMMUNITY_DENY;
19639
19640 idx = 0;
19641 argv_find(argv, argc, "AA:NN", &idx);
19642 str = argv_concat(argv, argc, idx);
19643 }
19644
19645 idx = 0;
19646 argv_find(argv, argc, "(100-500)", &idx);
19647 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
19648 cl_name_or_number = argv[idx]->arg;
19649
19650 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19651 direct, style);
19652
19653 XFREE(MTYPE_TMP, str);
19654
19655 if (ret < 0) {
19656 community_list_perror(vty, ret);
19657 return CMD_WARNING_CONFIG_FAILED;
19658 }
19659
19660 return CMD_SUCCESS;
19661 }
19662
19663 ALIAS(no_community_list_expanded_all,
19664 no_bgp_community_list_expanded_all_list_cmd,
19665 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
19666 NO_STR BGP_STR COMMUNITY_LIST_STR
19667 "Community list number (expanded)\n"
19668 "Add an expanded community-list entry\n"
19669 "Community list name\n")
19670
19671 /* Return configuration string of community-list entry. */
19672 static const char *community_list_config_str(struct community_entry *entry)
19673 {
19674 const char *str;
19675
19676 if (entry->any)
19677 str = "";
19678 else {
19679 if (entry->style == COMMUNITY_LIST_STANDARD)
19680 str = community_str(entry->u.com, false, false);
19681 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19682 str = lcommunity_str(entry->u.lcom, false, false);
19683 else
19684 str = entry->config;
19685 }
19686 return str;
19687 }
19688
19689 static void community_list_show(struct vty *vty, struct community_list *list)
19690 {
19691 struct community_entry *entry;
19692
19693 for (entry = list->head; entry; entry = entry->next) {
19694 if (entry == list->head) {
19695 if (all_digit(list->name))
19696 vty_out(vty, "Community %s list %s\n",
19697 entry->style == COMMUNITY_LIST_STANDARD
19698 ? "standard"
19699 : "(expanded) access",
19700 list->name);
19701 else
19702 vty_out(vty, "Named Community %s list %s\n",
19703 entry->style == COMMUNITY_LIST_STANDARD
19704 ? "standard"
19705 : "expanded",
19706 list->name);
19707 }
19708 if (entry->any)
19709 vty_out(vty, " %s\n",
19710 community_direct_str(entry->direct));
19711 else
19712 vty_out(vty, " %s %s\n",
19713 community_direct_str(entry->direct),
19714 community_list_config_str(entry));
19715 }
19716 }
19717
19718 DEFUN (show_community_list,
19719 show_bgp_community_list_cmd,
19720 "show bgp community-list",
19721 SHOW_STR
19722 BGP_STR
19723 "List community-list\n")
19724 {
19725 struct community_list *list;
19726 struct community_list_master *cm;
19727
19728 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19729 if (!cm)
19730 return CMD_SUCCESS;
19731
19732 for (list = cm->num.head; list; list = list->next)
19733 community_list_show(vty, list);
19734
19735 for (list = cm->str.head; list; list = list->next)
19736 community_list_show(vty, list);
19737
19738 return CMD_SUCCESS;
19739 }
19740
19741 DEFUN (show_community_list_arg,
19742 show_bgp_community_list_arg_cmd,
19743 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
19744 SHOW_STR
19745 BGP_STR
19746 "List community-list\n"
19747 "Community-list number\n"
19748 "Community-list name\n"
19749 "Detailed information on community-list\n")
19750 {
19751 int idx_comm_list = 3;
19752 struct community_list *list;
19753
19754 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19755 COMMUNITY_LIST_MASTER);
19756 if (!list) {
19757 vty_out(vty, "%% Can't find community-list\n");
19758 return CMD_WARNING;
19759 }
19760
19761 community_list_show(vty, list);
19762
19763 return CMD_SUCCESS;
19764 }
19765
19766 /*
19767 * Large Community code.
19768 */
19769 static int lcommunity_list_set_vty(struct vty *vty, int argc,
19770 struct cmd_token **argv, int style,
19771 int reject_all_digit_name)
19772 {
19773 int ret;
19774 int direct;
19775 char *str;
19776 int idx = 0;
19777 char *cl_name;
19778 char *seq = NULL;
19779
19780 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19781 seq = argv[idx]->arg;
19782
19783 idx = 0;
19784 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19785 : COMMUNITY_DENY;
19786
19787 /* All digit name check. */
19788 idx = 0;
19789 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19790 argv_find(argv, argc, "(1-99)", &idx);
19791 argv_find(argv, argc, "(100-500)", &idx);
19792 cl_name = argv[idx]->arg;
19793 if (reject_all_digit_name && all_digit(cl_name)) {
19794 vty_out(vty, "%% Community name cannot have all digits\n");
19795 return CMD_WARNING_CONFIG_FAILED;
19796 }
19797
19798 idx = 0;
19799 argv_find(argv, argc, "AA:BB:CC", &idx);
19800 argv_find(argv, argc, "LINE", &idx);
19801 /* Concat community string argument. */
19802 if (idx)
19803 str = argv_concat(argv, argc, idx);
19804 else
19805 str = NULL;
19806
19807 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19808
19809 /* Free temporary community list string allocated by
19810 argv_concat(). */
19811 XFREE(MTYPE_TMP, str);
19812
19813 if (ret < 0) {
19814 community_list_perror(vty, ret);
19815 return CMD_WARNING_CONFIG_FAILED;
19816 }
19817 return CMD_SUCCESS;
19818 }
19819
19820 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19821 struct cmd_token **argv, int style)
19822 {
19823 int ret;
19824 int direct = 0;
19825 char *str = NULL;
19826 int idx = 0;
19827 char *seq = NULL;
19828
19829 if (argv_find(argv, argc, "(0-4294967295)", &idx))
19830 seq = argv[idx]->arg;
19831
19832 idx = 0;
19833 argv_find(argv, argc, "permit", &idx);
19834 argv_find(argv, argc, "deny", &idx);
19835
19836 if (idx) {
19837 /* Check the list direct. */
19838 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19839 direct = COMMUNITY_PERMIT;
19840 else
19841 direct = COMMUNITY_DENY;
19842
19843 idx = 0;
19844 argv_find(argv, argc, "LINE", &idx);
19845 argv_find(argv, argc, "AA:AA:NN", &idx);
19846 /* Concat community string argument. */
19847 str = argv_concat(argv, argc, idx);
19848 }
19849
19850 idx = 0;
19851 argv_find(argv, argc, "(1-99)", &idx);
19852 argv_find(argv, argc, "(100-500)", &idx);
19853 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
19854
19855 /* Unset community list. */
19856 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19857 style);
19858
19859 /* Free temporary community list string allocated by
19860 argv_concat(). */
19861 XFREE(MTYPE_TMP, str);
19862
19863 if (ret < 0) {
19864 community_list_perror(vty, ret);
19865 return CMD_WARNING_CONFIG_FAILED;
19866 }
19867
19868 return CMD_SUCCESS;
19869 }
19870
19871 /* "large-community-list" keyword help string. */
19872 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19873 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19874
19875 DEFUN (lcommunity_list_standard,
19876 bgp_lcommunity_list_standard_cmd,
19877 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19878 BGP_STR
19879 LCOMMUNITY_LIST_STR
19880 "Large Community list number (standard)\n"
19881 "Sequence number of an entry\n"
19882 "Sequence number\n"
19883 "Specify large community to reject\n"
19884 "Specify large community to accept\n"
19885 LCOMMUNITY_VAL_STR)
19886 {
19887 return lcommunity_list_set_vty(vty, argc, argv,
19888 LARGE_COMMUNITY_LIST_STANDARD, 0);
19889 }
19890
19891 DEFUN (lcommunity_list_expanded,
19892 bgp_lcommunity_list_expanded_cmd,
19893 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
19894 BGP_STR
19895 LCOMMUNITY_LIST_STR
19896 "Large Community list number (expanded)\n"
19897 "Sequence number of an entry\n"
19898 "Sequence number\n"
19899 "Specify large community to reject\n"
19900 "Specify large community to accept\n"
19901 "An ordered list as a regular-expression\n")
19902 {
19903 return lcommunity_list_set_vty(vty, argc, argv,
19904 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19905 }
19906
19907 DEFUN (lcommunity_list_name_standard,
19908 bgp_lcommunity_list_name_standard_cmd,
19909 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
19910 BGP_STR
19911 LCOMMUNITY_LIST_STR
19912 "Specify standard large-community-list\n"
19913 "Large Community list name\n"
19914 "Sequence number of an entry\n"
19915 "Sequence number\n"
19916 "Specify large community to reject\n"
19917 "Specify large community to accept\n"
19918 LCOMMUNITY_VAL_STR)
19919 {
19920 return lcommunity_list_set_vty(vty, argc, argv,
19921 LARGE_COMMUNITY_LIST_STANDARD, 1);
19922 }
19923
19924 DEFUN (lcommunity_list_name_expanded,
19925 bgp_lcommunity_list_name_expanded_cmd,
19926 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
19927 BGP_STR
19928 LCOMMUNITY_LIST_STR
19929 "Specify expanded large-community-list\n"
19930 "Large Community list name\n"
19931 "Sequence number of an entry\n"
19932 "Sequence number\n"
19933 "Specify large community to reject\n"
19934 "Specify large community to accept\n"
19935 "An ordered list as a regular-expression\n")
19936 {
19937 return lcommunity_list_set_vty(vty, argc, argv,
19938 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19939 }
19940
19941 DEFUN (no_lcommunity_list_all,
19942 no_bgp_lcommunity_list_all_cmd,
19943 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
19944 NO_STR
19945 BGP_STR
19946 LCOMMUNITY_LIST_STR
19947 "Large Community list number (standard)\n"
19948 "Large Community list number (expanded)\n"
19949 "Large Community list name\n")
19950 {
19951 return lcommunity_list_unset_vty(vty, argc, argv,
19952 LARGE_COMMUNITY_LIST_STANDARD);
19953 }
19954
19955 DEFUN (no_lcommunity_list_name_standard_all,
19956 no_bgp_lcommunity_list_name_standard_all_cmd,
19957 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
19958 NO_STR
19959 BGP_STR
19960 LCOMMUNITY_LIST_STR
19961 "Specify standard large-community-list\n"
19962 "Large Community list name\n")
19963 {
19964 return lcommunity_list_unset_vty(vty, argc, argv,
19965 LARGE_COMMUNITY_LIST_STANDARD);
19966 }
19967
19968 DEFUN (no_lcommunity_list_name_expanded_all,
19969 no_bgp_lcommunity_list_name_expanded_all_cmd,
19970 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
19971 NO_STR
19972 BGP_STR
19973 LCOMMUNITY_LIST_STR
19974 "Specify expanded large-community-list\n"
19975 "Large Community list name\n")
19976 {
19977 return lcommunity_list_unset_vty(vty, argc, argv,
19978 LARGE_COMMUNITY_LIST_EXPANDED);
19979 }
19980
19981 DEFUN (no_lcommunity_list_standard,
19982 no_bgp_lcommunity_list_standard_cmd,
19983 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
19984 NO_STR
19985 BGP_STR
19986 LCOMMUNITY_LIST_STR
19987 "Large Community list number (standard)\n"
19988 "Sequence number of an entry\n"
19989 "Sequence number\n"
19990 "Specify large community to reject\n"
19991 "Specify large community to accept\n"
19992 LCOMMUNITY_VAL_STR)
19993 {
19994 return lcommunity_list_unset_vty(vty, argc, argv,
19995 LARGE_COMMUNITY_LIST_STANDARD);
19996 }
19997
19998 DEFUN (no_lcommunity_list_expanded,
19999 no_bgp_lcommunity_list_expanded_cmd,
20000 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
20001 NO_STR
20002 BGP_STR
20003 LCOMMUNITY_LIST_STR
20004 "Large Community list number (expanded)\n"
20005 "Sequence number of an entry\n"
20006 "Sequence number\n"
20007 "Specify large community to reject\n"
20008 "Specify large community to accept\n"
20009 "An ordered list as a regular-expression\n")
20010 {
20011 return lcommunity_list_unset_vty(vty, argc, argv,
20012 LARGE_COMMUNITY_LIST_EXPANDED);
20013 }
20014
20015 DEFUN (no_lcommunity_list_name_standard,
20016 no_bgp_lcommunity_list_name_standard_cmd,
20017 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
20018 NO_STR
20019 BGP_STR
20020 LCOMMUNITY_LIST_STR
20021 "Specify standard large-community-list\n"
20022 "Large Community list name\n"
20023 "Sequence number of an entry\n"
20024 "Sequence number\n"
20025 "Specify large community to reject\n"
20026 "Specify large community to accept\n"
20027 LCOMMUNITY_VAL_STR)
20028 {
20029 return lcommunity_list_unset_vty(vty, argc, argv,
20030 LARGE_COMMUNITY_LIST_STANDARD);
20031 }
20032
20033 DEFUN (no_lcommunity_list_name_expanded,
20034 no_bgp_lcommunity_list_name_expanded_cmd,
20035 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
20036 NO_STR
20037 BGP_STR
20038 LCOMMUNITY_LIST_STR
20039 "Specify expanded large-community-list\n"
20040 "Large community list name\n"
20041 "Sequence number of an entry\n"
20042 "Sequence number\n"
20043 "Specify large community to reject\n"
20044 "Specify large community to accept\n"
20045 "An ordered list as a regular-expression\n")
20046 {
20047 return lcommunity_list_unset_vty(vty, argc, argv,
20048 LARGE_COMMUNITY_LIST_EXPANDED);
20049 }
20050
20051 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20052 {
20053 struct community_entry *entry;
20054
20055 for (entry = list->head; entry; entry = entry->next) {
20056 if (entry == list->head) {
20057 if (all_digit(list->name))
20058 vty_out(vty, "Large community %s list %s\n",
20059 entry->style ==
20060 LARGE_COMMUNITY_LIST_STANDARD
20061 ? "standard"
20062 : "(expanded) access",
20063 list->name);
20064 else
20065 vty_out(vty,
20066 "Named large community %s list %s\n",
20067 entry->style ==
20068 LARGE_COMMUNITY_LIST_STANDARD
20069 ? "standard"
20070 : "expanded",
20071 list->name);
20072 }
20073 if (entry->any)
20074 vty_out(vty, " %s\n",
20075 community_direct_str(entry->direct));
20076 else
20077 vty_out(vty, " %s %s\n",
20078 community_direct_str(entry->direct),
20079 community_list_config_str(entry));
20080 }
20081 }
20082
20083 DEFUN (show_lcommunity_list,
20084 show_bgp_lcommunity_list_cmd,
20085 "show bgp large-community-list",
20086 SHOW_STR
20087 BGP_STR
20088 "List large-community list\n")
20089 {
20090 struct community_list *list;
20091 struct community_list_master *cm;
20092
20093 cm = community_list_master_lookup(bgp_clist,
20094 LARGE_COMMUNITY_LIST_MASTER);
20095 if (!cm)
20096 return CMD_SUCCESS;
20097
20098 for (list = cm->num.head; list; list = list->next)
20099 lcommunity_list_show(vty, list);
20100
20101 for (list = cm->str.head; list; list = list->next)
20102 lcommunity_list_show(vty, list);
20103
20104 return CMD_SUCCESS;
20105 }
20106
20107 DEFUN (show_lcommunity_list_arg,
20108 show_bgp_lcommunity_list_arg_cmd,
20109 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
20110 SHOW_STR
20111 BGP_STR
20112 "List large-community list\n"
20113 "Large-community-list number\n"
20114 "Large-community-list name\n"
20115 "Detailed information on large-community-list\n")
20116 {
20117 struct community_list *list;
20118
20119 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
20120 LARGE_COMMUNITY_LIST_MASTER);
20121 if (!list) {
20122 vty_out(vty, "%% Can't find large-community-list\n");
20123 return CMD_WARNING;
20124 }
20125
20126 lcommunity_list_show(vty, list);
20127
20128 return CMD_SUCCESS;
20129 }
20130
20131 /* "extcommunity-list" keyword help string. */
20132 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20133 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20134
20135 DEFUN (extcommunity_list_standard,
20136 bgp_extcommunity_list_standard_cmd,
20137 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20138 BGP_STR
20139 EXTCOMMUNITY_LIST_STR
20140 "Extended Community list number (standard)\n"
20141 "Specify standard extcommunity-list\n"
20142 "Community list name\n"
20143 "Sequence number of an entry\n"
20144 "Sequence number\n"
20145 "Specify community to reject\n"
20146 "Specify community to accept\n"
20147 EXTCOMMUNITY_VAL_STR)
20148 {
20149 int style = EXTCOMMUNITY_LIST_STANDARD;
20150 int direct = 0;
20151 char *cl_number_or_name = NULL;
20152 char *seq = NULL;
20153
20154 int idx = 0;
20155
20156 argv_find(argv, argc, "(1-99)", &idx);
20157 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20158 cl_number_or_name = argv[idx]->arg;
20159
20160 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20161 seq = argv[idx]->arg;
20162
20163 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20164 : COMMUNITY_DENY;
20165 argv_find(argv, argc, "AA:NN", &idx);
20166 char *str = argv_concat(argv, argc, idx);
20167
20168 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20169 direct, style);
20170
20171 XFREE(MTYPE_TMP, str);
20172
20173 if (ret < 0) {
20174 community_list_perror(vty, ret);
20175 return CMD_WARNING_CONFIG_FAILED;
20176 }
20177
20178 return CMD_SUCCESS;
20179 }
20180
20181 DEFUN (extcommunity_list_name_expanded,
20182 bgp_extcommunity_list_name_expanded_cmd,
20183 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20184 BGP_STR
20185 EXTCOMMUNITY_LIST_STR
20186 "Extended Community list number (expanded)\n"
20187 "Specify expanded extcommunity-list\n"
20188 "Extended Community list name\n"
20189 "Sequence number of an entry\n"
20190 "Sequence number\n"
20191 "Specify community to reject\n"
20192 "Specify community to accept\n"
20193 "An ordered list as a regular-expression\n")
20194 {
20195 int style = EXTCOMMUNITY_LIST_EXPANDED;
20196 int direct = 0;
20197 char *cl_number_or_name = NULL;
20198 char *seq = NULL;
20199 int idx = 0;
20200
20201 argv_find(argv, argc, "(100-500)", &idx);
20202 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20203 cl_number_or_name = argv[idx]->arg;
20204
20205 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20206 seq = argv[idx]->arg;
20207
20208 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20209 : COMMUNITY_DENY;
20210 argv_find(argv, argc, "LINE", &idx);
20211 char *str = argv_concat(argv, argc, idx);
20212
20213 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
20214 direct, style);
20215
20216 XFREE(MTYPE_TMP, str);
20217
20218 if (ret < 0) {
20219 community_list_perror(vty, ret);
20220 return CMD_WARNING_CONFIG_FAILED;
20221 }
20222
20223 return CMD_SUCCESS;
20224 }
20225
20226 DEFUN (no_extcommunity_list_standard_all,
20227 no_bgp_extcommunity_list_standard_all_cmd,
20228 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
20229 NO_STR
20230 BGP_STR
20231 EXTCOMMUNITY_LIST_STR
20232 "Extended Community list number (standard)\n"
20233 "Specify standard extcommunity-list\n"
20234 "Community list name\n"
20235 "Sequence number of an entry\n"
20236 "Sequence number\n"
20237 "Specify community to reject\n"
20238 "Specify community to accept\n"
20239 EXTCOMMUNITY_VAL_STR)
20240 {
20241 int style = EXTCOMMUNITY_LIST_STANDARD;
20242 int direct = 0;
20243 char *cl_number_or_name = NULL;
20244 char *str = NULL;
20245 char *seq = NULL;
20246 int idx = 0;
20247
20248 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20249 seq = argv[idx]->arg;
20250
20251 idx = 0;
20252 argv_find(argv, argc, "permit", &idx);
20253 argv_find(argv, argc, "deny", &idx);
20254 if (idx) {
20255 direct = argv_find(argv, argc, "permit", &idx)
20256 ? COMMUNITY_PERMIT
20257 : COMMUNITY_DENY;
20258
20259 idx = 0;
20260 argv_find(argv, argc, "AA:NN", &idx);
20261 str = argv_concat(argv, argc, idx);
20262 }
20263
20264 idx = 0;
20265 argv_find(argv, argc, "(1-99)", &idx);
20266 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20267 cl_number_or_name = argv[idx]->arg;
20268
20269 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20270 seq, direct, style);
20271
20272 XFREE(MTYPE_TMP, str);
20273
20274 if (ret < 0) {
20275 community_list_perror(vty, ret);
20276 return CMD_WARNING_CONFIG_FAILED;
20277 }
20278
20279 return CMD_SUCCESS;
20280 }
20281
20282 ALIAS(no_extcommunity_list_standard_all,
20283 no_bgp_extcommunity_list_standard_all_list_cmd,
20284 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
20285 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20286 "Extended Community list number (standard)\n"
20287 "Specify standard extcommunity-list\n"
20288 "Community list name\n")
20289
20290 DEFUN (no_extcommunity_list_expanded_all,
20291 no_bgp_extcommunity_list_expanded_all_cmd,
20292 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
20293 NO_STR
20294 BGP_STR
20295 EXTCOMMUNITY_LIST_STR
20296 "Extended Community list number (expanded)\n"
20297 "Specify expanded extcommunity-list\n"
20298 "Extended Community list name\n"
20299 "Sequence number of an entry\n"
20300 "Sequence number\n"
20301 "Specify community to reject\n"
20302 "Specify community to accept\n"
20303 "An ordered list as a regular-expression\n")
20304 {
20305 int style = EXTCOMMUNITY_LIST_EXPANDED;
20306 int direct = 0;
20307 char *cl_number_or_name = NULL;
20308 char *str = NULL;
20309 char *seq = NULL;
20310 int idx = 0;
20311
20312 if (argv_find(argv, argc, "(0-4294967295)", &idx))
20313 seq = argv[idx]->arg;
20314
20315 idx = 0;
20316 argv_find(argv, argc, "permit", &idx);
20317 argv_find(argv, argc, "deny", &idx);
20318
20319 if (idx) {
20320 direct = argv_find(argv, argc, "permit", &idx)
20321 ? COMMUNITY_PERMIT
20322 : COMMUNITY_DENY;
20323
20324 idx = 0;
20325 argv_find(argv, argc, "LINE", &idx);
20326 str = argv_concat(argv, argc, idx);
20327 }
20328
20329 idx = 0;
20330 argv_find(argv, argc, "(100-500)", &idx);
20331 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
20332 cl_number_or_name = argv[idx]->arg;
20333
20334 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
20335 seq, direct, style);
20336
20337 XFREE(MTYPE_TMP, str);
20338
20339 if (ret < 0) {
20340 community_list_perror(vty, ret);
20341 return CMD_WARNING_CONFIG_FAILED;
20342 }
20343
20344 return CMD_SUCCESS;
20345 }
20346
20347 ALIAS(no_extcommunity_list_expanded_all,
20348 no_bgp_extcommunity_list_expanded_all_list_cmd,
20349 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
20350 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
20351 "Extended Community list number (expanded)\n"
20352 "Specify expanded extcommunity-list\n"
20353 "Extended Community list name\n")
20354
20355 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
20356 {
20357 struct community_entry *entry;
20358
20359 for (entry = list->head; entry; entry = entry->next) {
20360 if (entry == list->head) {
20361 if (all_digit(list->name))
20362 vty_out(vty, "Extended community %s list %s\n",
20363 entry->style == EXTCOMMUNITY_LIST_STANDARD
20364 ? "standard"
20365 : "(expanded) access",
20366 list->name);
20367 else
20368 vty_out(vty,
20369 "Named extended community %s list %s\n",
20370 entry->style == EXTCOMMUNITY_LIST_STANDARD
20371 ? "standard"
20372 : "expanded",
20373 list->name);
20374 }
20375 if (entry->any)
20376 vty_out(vty, " %s\n",
20377 community_direct_str(entry->direct));
20378 else
20379 vty_out(vty, " %s %s\n",
20380 community_direct_str(entry->direct),
20381 community_list_config_str(entry));
20382 }
20383 }
20384
20385 DEFUN (show_extcommunity_list,
20386 show_bgp_extcommunity_list_cmd,
20387 "show bgp extcommunity-list",
20388 SHOW_STR
20389 BGP_STR
20390 "List extended-community list\n")
20391 {
20392 struct community_list *list;
20393 struct community_list_master *cm;
20394
20395 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20396 if (!cm)
20397 return CMD_SUCCESS;
20398
20399 for (list = cm->num.head; list; list = list->next)
20400 extcommunity_list_show(vty, list);
20401
20402 for (list = cm->str.head; list; list = list->next)
20403 extcommunity_list_show(vty, list);
20404
20405 return CMD_SUCCESS;
20406 }
20407
20408 DEFUN (show_extcommunity_list_arg,
20409 show_bgp_extcommunity_list_arg_cmd,
20410 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
20411 SHOW_STR
20412 BGP_STR
20413 "List extended-community list\n"
20414 "Extcommunity-list number\n"
20415 "Extcommunity-list name\n"
20416 "Detailed information on extcommunity-list\n")
20417 {
20418 int idx_comm_list = 3;
20419 struct community_list *list;
20420
20421 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20422 EXTCOMMUNITY_LIST_MASTER);
20423 if (!list) {
20424 vty_out(vty, "%% Can't find extcommunity-list\n");
20425 return CMD_WARNING;
20426 }
20427
20428 extcommunity_list_show(vty, list);
20429
20430 return CMD_SUCCESS;
20431 }
20432
20433 /* Display community-list and extcommunity-list configuration. */
20434 static int community_list_config_write(struct vty *vty)
20435 {
20436 struct community_list *list;
20437 struct community_entry *entry;
20438 struct community_list_master *cm;
20439 int write = 0;
20440
20441 /* Community-list. */
20442 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20443
20444 for (list = cm->num.head; list; list = list->next)
20445 for (entry = list->head; entry; entry = entry->next) {
20446 vty_out(vty,
20447 "bgp community-list %s seq %" PRId64 " %s %s\n",
20448 list->name, entry->seq,
20449 community_direct_str(entry->direct),
20450 community_list_config_str(entry));
20451 write++;
20452 }
20453 for (list = cm->str.head; list; list = list->next)
20454 for (entry = list->head; entry; entry = entry->next) {
20455 vty_out(vty,
20456 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20457 entry->style == COMMUNITY_LIST_STANDARD
20458 ? "standard"
20459 : "expanded",
20460 list->name, entry->seq,
20461 community_direct_str(entry->direct),
20462 community_list_config_str(entry));
20463 write++;
20464 }
20465
20466 /* Extcommunity-list. */
20467 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20468
20469 for (list = cm->num.head; list; list = list->next)
20470 for (entry = list->head; entry; entry = entry->next) {
20471 vty_out(vty,
20472 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20473 list->name, entry->seq,
20474 community_direct_str(entry->direct),
20475 community_list_config_str(entry));
20476 write++;
20477 }
20478 for (list = cm->str.head; list; list = list->next)
20479 for (entry = list->head; entry; entry = entry->next) {
20480 vty_out(vty,
20481 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20482 entry->style == EXTCOMMUNITY_LIST_STANDARD
20483 ? "standard"
20484 : "expanded",
20485 list->name, entry->seq,
20486 community_direct_str(entry->direct),
20487 community_list_config_str(entry));
20488 write++;
20489 }
20490
20491
20492 /* lcommunity-list. */
20493 cm = community_list_master_lookup(bgp_clist,
20494 LARGE_COMMUNITY_LIST_MASTER);
20495
20496 for (list = cm->num.head; list; list = list->next)
20497 for (entry = list->head; entry; entry = entry->next) {
20498 vty_out(vty,
20499 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20500 list->name, entry->seq,
20501 community_direct_str(entry->direct),
20502 community_list_config_str(entry));
20503 write++;
20504 }
20505 for (list = cm->str.head; list; list = list->next)
20506 for (entry = list->head; entry; entry = entry->next) {
20507 vty_out(vty,
20508 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20509
20510 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20511 ? "standard"
20512 : "expanded",
20513 list->name, entry->seq, community_direct_str(entry->direct),
20514 community_list_config_str(entry));
20515 write++;
20516 }
20517
20518 return write;
20519 }
20520
20521 static int community_list_config_write(struct vty *vty);
20522 static struct cmd_node community_list_node = {
20523 .name = "community list",
20524 .node = COMMUNITY_LIST_NODE,
20525 .prompt = "",
20526 .config_write = community_list_config_write,
20527 };
20528
20529 static void community_list_vty(void)
20530 {
20531 install_node(&community_list_node);
20532
20533 /* Community-list. */
20534 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20535 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20536 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20537 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20538 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20539 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20540 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20541 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20542
20543 /* Extcommunity-list. */
20544 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20545 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20546 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20547 install_element(CONFIG_NODE,
20548 &no_bgp_extcommunity_list_standard_all_list_cmd);
20549 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20550 install_element(CONFIG_NODE,
20551 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20552 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20553 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20554
20555 /* Large Community List */
20556 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20557 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20558 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20559 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20560 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20561 install_element(CONFIG_NODE,
20562 &no_bgp_lcommunity_list_name_standard_all_cmd);
20563 install_element(CONFIG_NODE,
20564 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20565 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20566 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20567 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20568 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20569 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20570 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20571
20572 bgp_community_list_command_completion_setup();
20573 }
20574
20575 static struct cmd_node community_alias_node = {
20576 .name = "community alias",
20577 .node = COMMUNITY_ALIAS_NODE,
20578 .prompt = "",
20579 .config_write = bgp_community_alias_write,
20580 };
20581
20582 void community_alias_vty(void)
20583 {
20584 install_node(&community_alias_node);
20585
20586 /* Community-list. */
20587 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20588
20589 bgp_community_alias_command_completion_setup();
20590 }