]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #3188 from opensourcerouting/bgp-snmp-fix-rename
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
718e3744 25#include "prefix.h"
26#include "plist.h"
27#include "buffer.h"
28#include "linklist.h"
29#include "stream.h"
30#include "thread.h"
31#include "log.h"
3b8b1855 32#include "memory.h"
fc7948fa 33#include "memory_vty.h"
4bf6a362 34#include "hash.h"
3f9c7369 35#include "queue.h"
039f3a34 36#include "filter.h"
5d5ba018 37#include "frrstr.h"
718e3744 38
39#include "bgpd/bgpd.h"
4bf6a362 40#include "bgpd/bgp_advertise.h"
718e3744 41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_aspath.h"
43#include "bgpd/bgp_community.h"
4bf6a362 44#include "bgpd/bgp_ecommunity.h"
57d187bc 45#include "bgpd/bgp_lcommunity.h"
4bf6a362 46#include "bgpd/bgp_damp.h"
718e3744 47#include "bgpd/bgp_debug.h"
14454c9f 48#include "bgpd/bgp_errors.h"
e0701b79 49#include "bgpd/bgp_fsm.h"
4bf6a362 50#include "bgpd/bgp_nexthop.h"
718e3744 51#include "bgpd/bgp_open.h"
4bf6a362 52#include "bgpd/bgp_regex.h"
718e3744 53#include "bgpd/bgp_route.h"
c016b6c7 54#include "bgpd/bgp_mplsvpn.h"
718e3744 55#include "bgpd/bgp_zebra.h"
fee0f4c6 56#include "bgpd/bgp_table.h"
94f2b392 57#include "bgpd/bgp_vty.h"
165b5fff 58#include "bgpd/bgp_mpath.h"
cb1faec9 59#include "bgpd/bgp_packet.h"
3f9c7369 60#include "bgpd/bgp_updgrp.h"
c43ed2e4 61#include "bgpd/bgp_bfd.h"
555e09d4 62#include "bgpd/bgp_io.h"
94c2f693 63#include "bgpd/bgp_evpn.h"
718e3744 64
d62a17ae 65static struct peer_group *listen_range_exists(struct bgp *bgp,
66 struct prefix *range, int exact);
67
68static enum node_type bgp_node_type(afi_t afi, safi_t safi)
69{
70 switch (afi) {
71 case AFI_IP:
72 switch (safi) {
73 case SAFI_UNICAST:
74 return BGP_IPV4_NODE;
75 break;
76 case SAFI_MULTICAST:
77 return BGP_IPV4M_NODE;
78 break;
79 case SAFI_LABELED_UNICAST:
80 return BGP_IPV4L_NODE;
81 break;
82 case SAFI_MPLS_VPN:
83 return BGP_VPNV4_NODE;
84 break;
7c40bf39 85 case SAFI_FLOWSPEC:
86 return BGP_FLOWSPECV4_NODE;
5c525538
RW
87 default:
88 /* not expected */
89 return BGP_IPV4_NODE;
90 break;
d62a17ae 91 }
92 break;
93 case AFI_IP6:
94 switch (safi) {
95 case SAFI_UNICAST:
96 return BGP_IPV6_NODE;
97 break;
98 case SAFI_MULTICAST:
99 return BGP_IPV6M_NODE;
100 break;
101 case SAFI_LABELED_UNICAST:
102 return BGP_IPV6L_NODE;
103 break;
104 case SAFI_MPLS_VPN:
105 return BGP_VPNV6_NODE;
106 break;
7c40bf39 107 case SAFI_FLOWSPEC:
108 return BGP_FLOWSPECV6_NODE;
5c525538
RW
109 default:
110 /* not expected */
111 return BGP_IPV4_NODE;
112 break;
d62a17ae 113 }
114 break;
115 case AFI_L2VPN:
116 return BGP_EVPN_NODE;
117 break;
118 case AFI_MAX:
119 // We should never be here but to clarify the switch statement..
120 return BGP_IPV4_NODE;
121 break;
122 }
123
124 // Impossible to happen
125 return BGP_IPV4_NODE;
f51bae9c 126}
20eb8864 127
718e3744 128/* Utility function to get address family from current node. */
d62a17ae 129afi_t bgp_node_afi(struct vty *vty)
130{
131 afi_t afi;
132 switch (vty->node) {
133 case BGP_IPV6_NODE:
134 case BGP_IPV6M_NODE:
135 case BGP_IPV6L_NODE:
136 case BGP_VPNV6_NODE:
7c40bf39 137 case BGP_FLOWSPECV6_NODE:
d62a17ae 138 afi = AFI_IP6;
139 break;
140 case BGP_EVPN_NODE:
141 afi = AFI_L2VPN;
142 break;
143 default:
144 afi = AFI_IP;
145 break;
146 }
147 return afi;
718e3744 148}
149
150/* Utility function to get subsequent address family from current
151 node. */
d62a17ae 152safi_t bgp_node_safi(struct vty *vty)
153{
154 safi_t safi;
155 switch (vty->node) {
156 case BGP_VPNV4_NODE:
157 case BGP_VPNV6_NODE:
158 safi = SAFI_MPLS_VPN;
159 break;
160 case BGP_IPV4M_NODE:
161 case BGP_IPV6M_NODE:
162 safi = SAFI_MULTICAST;
163 break;
164 case BGP_EVPN_NODE:
165 safi = SAFI_EVPN;
166 break;
167 case BGP_IPV4L_NODE:
168 case BGP_IPV6L_NODE:
169 safi = SAFI_LABELED_UNICAST;
170 break;
7c40bf39 171 case BGP_FLOWSPECV4_NODE:
172 case BGP_FLOWSPECV6_NODE:
173 safi = SAFI_FLOWSPEC;
174 break;
d62a17ae 175 default:
176 safi = SAFI_UNICAST;
177 break;
178 }
179 return safi;
718e3744 180}
181
55f91488
QY
182/**
183 * Converts an AFI in string form to afi_t
184 *
185 * @param afi string, one of
186 * - "ipv4"
187 * - "ipv6"
81cf0de5 188 * - "l2vpn"
55f91488
QY
189 * @return the corresponding afi_t
190 */
d62a17ae 191afi_t bgp_vty_afi_from_str(const char *afi_str)
192{
193 afi_t afi = AFI_MAX; /* unknown */
194 if (strmatch(afi_str, "ipv4"))
195 afi = AFI_IP;
196 else if (strmatch(afi_str, "ipv6"))
197 afi = AFI_IP6;
81cf0de5
CS
198 else if (strmatch(afi_str, "l2vpn"))
199 afi = AFI_L2VPN;
d62a17ae 200 return afi;
201}
202
203int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
204 afi_t *afi)
205{
206 int ret = 0;
207 if (argv_find(argv, argc, "ipv4", index)) {
208 ret = 1;
209 if (afi)
210 *afi = AFI_IP;
211 } else if (argv_find(argv, argc, "ipv6", index)) {
212 ret = 1;
213 if (afi)
214 *afi = AFI_IP6;
215 }
216 return ret;
46f296b4
LB
217}
218
375a2e67 219/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 220safi_t bgp_vty_safi_from_str(const char *safi_str)
221{
222 safi_t safi = SAFI_MAX; /* unknown */
223 if (strmatch(safi_str, "multicast"))
224 safi = SAFI_MULTICAST;
225 else if (strmatch(safi_str, "unicast"))
226 safi = SAFI_UNICAST;
227 else if (strmatch(safi_str, "vpn"))
228 safi = SAFI_MPLS_VPN;
81cf0de5
CS
229 else if (strmatch(safi_str, "evpn"))
230 safi = SAFI_EVPN;
d62a17ae 231 else if (strmatch(safi_str, "labeled-unicast"))
232 safi = SAFI_LABELED_UNICAST;
7c40bf39 233 else if (strmatch(safi_str, "flowspec"))
234 safi = SAFI_FLOWSPEC;
d62a17ae 235 return safi;
236}
237
238int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
239 safi_t *safi)
240{
241 int ret = 0;
242 if (argv_find(argv, argc, "unicast", index)) {
243 ret = 1;
244 if (safi)
245 *safi = SAFI_UNICAST;
246 } else if (argv_find(argv, argc, "multicast", index)) {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_MULTICAST;
250 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
251 ret = 1;
252 if (safi)
253 *safi = SAFI_LABELED_UNICAST;
254 } else if (argv_find(argv, argc, "vpn", index)) {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_MPLS_VPN;
7c40bf39 258 } else if (argv_find(argv, argc, "flowspec", index)) {
259 ret = 1;
260 if (safi)
261 *safi = SAFI_FLOWSPEC;
d62a17ae 262 }
263 return ret;
46f296b4
LB
264}
265
7eeee51e 266/*
f212a857 267 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 268 *
f212a857
DS
269 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
270 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
271 * to appropriate values for the calling function. This is to allow the
272 * calling function to make decisions appropriate for the show command
273 * that is being parsed.
274 *
275 * The show commands are generally of the form:
d62a17ae 276 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
277 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
278 *
279 * Since we use argv_find if the show command in particular doesn't have:
280 * [ip]
18c57037 281 * [<view|vrf> VIEWVRFNAME]
375a2e67 282 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
283 * The command parsing should still be ok.
284 *
285 * vty -> The vty for the command so we can output some useful data in
286 * the event of a parse error in the vrf.
287 * argv -> The command tokens
288 * argc -> How many command tokens we have
d62a17ae 289 * idx -> The current place in the command, generally should be 0 for this
290 * function
7eeee51e
DS
291 * afi -> The parsed afi if it was included in the show command, returned here
292 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 293 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
294 *
295 * The function returns the correct location in the parse tree for the
296 * last token found.
0e37c258
DS
297 *
298 * Returns 0 for failure to parse correctly, else the idx position of where
299 * it found the last token.
7eeee51e 300 */
d62a17ae 301int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
302 struct cmd_token **argv, int argc,
303 int *idx, afi_t *afi, safi_t *safi,
9f049418 304 struct bgp **bgp, bool use_json)
d62a17ae 305{
306 char *vrf_name = NULL;
307
308 assert(afi);
309 assert(safi);
310 assert(bgp);
311
312 if (argv_find(argv, argc, "ip", idx))
313 *afi = AFI_IP;
314
9a8bdf1c 315 if (argv_find(argv, argc, "view", idx))
d62a17ae 316 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
317 else if (argv_find(argv, argc, "vrf", idx)) {
318 vrf_name = argv[*idx + 1]->arg;
319 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
320 vrf_name = NULL;
321 }
322 if (vrf_name) {
d62a17ae 323 if (strmatch(vrf_name, "all"))
324 *bgp = NULL;
325 else {
326 *bgp = bgp_lookup_by_name(vrf_name);
327 if (!*bgp) {
ca61fd25
DS
328 if (use_json)
329 vty_out(vty, "{}\n");
330 else
331 vty_out(vty, "View/Vrf %s is unknown\n",
332 vrf_name);
d62a17ae 333 *idx = 0;
334 return 0;
335 }
336 }
337 } else {
338 *bgp = bgp_get_default();
339 if (!*bgp) {
ca61fd25
DS
340 if (use_json)
341 vty_out(vty, "{}\n");
342 else
343 vty_out(vty,
344 "Default BGP instance not found\n");
d62a17ae 345 *idx = 0;
346 return 0;
347 }
348 }
349
350 if (argv_find_and_parse_afi(argv, argc, idx, afi))
351 argv_find_and_parse_safi(argv, argc, idx, safi);
352
353 *idx += 1;
354 return *idx;
355}
356
357static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
358{
359 struct interface *ifp = NULL;
360
361 if (su->sa.sa_family == AF_INET)
362 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
363 else if (su->sa.sa_family == AF_INET6)
364 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
365 su->sin6.sin6_scope_id,
366 bgp->vrf_id);
367
368 if (ifp)
369 return 1;
370
371 return 0;
718e3744 372}
373
374/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
375/* This is used only for configuration, so disallow if attempted on
376 * a dynamic neighbor.
377 */
d62a17ae 378static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
379{
380 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
381 int ret;
382 union sockunion su;
383 struct peer *peer;
384
385 if (!bgp) {
386 return NULL;
387 }
388
389 ret = str2sockunion(ip_str, &su);
390 if (ret < 0) {
391 peer = peer_lookup_by_conf_if(bgp, ip_str);
392 if (!peer) {
393 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
394 == NULL) {
395 vty_out(vty,
396 "%% Malformed address or name: %s\n",
397 ip_str);
398 return NULL;
399 }
400 }
401 } else {
402 peer = peer_lookup(bgp, &su);
403 if (!peer) {
404 vty_out(vty,
405 "%% Specify remote-as or peer-group commands first\n");
406 return NULL;
407 }
408 if (peer_dynamic_neighbor(peer)) {
409 vty_out(vty,
410 "%% Operation not allowed on a dynamic neighbor\n");
411 return NULL;
412 }
413 }
414 return peer;
718e3744 415}
416
417/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
418/* This is used only for configuration, so disallow if attempted on
419 * a dynamic neighbor.
420 */
d62a17ae 421struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
422{
423 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
424 int ret;
425 union sockunion su;
426 struct peer *peer = NULL;
427 struct peer_group *group = NULL;
428
429 if (!bgp) {
430 return NULL;
431 }
432
433 ret = str2sockunion(peer_str, &su);
434 if (ret == 0) {
435 /* IP address, locate peer. */
436 peer = peer_lookup(bgp, &su);
437 } else {
438 /* Not IP, could match either peer configured on interface or a
439 * group. */
440 peer = peer_lookup_by_conf_if(bgp, peer_str);
441 if (!peer)
442 group = peer_group_lookup(bgp, peer_str);
443 }
444
445 if (peer) {
446 if (peer_dynamic_neighbor(peer)) {
447 vty_out(vty,
448 "%% Operation not allowed on a dynamic neighbor\n");
449 return NULL;
450 }
451
452 return peer;
453 }
454
455 if (group)
456 return group->conf;
457
458 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
459
460 return NULL;
461}
462
463int bgp_vty_return(struct vty *vty, int ret)
464{
465 const char *str = NULL;
466
467 switch (ret) {
468 case BGP_ERR_INVALID_VALUE:
469 str = "Invalid value";
470 break;
471 case BGP_ERR_INVALID_FLAG:
472 str = "Invalid flag";
473 break;
474 case BGP_ERR_PEER_GROUP_SHUTDOWN:
475 str = "Peer-group has been shutdown. Activate the peer-group first";
476 break;
477 case BGP_ERR_PEER_FLAG_CONFLICT:
478 str = "Can't set override-capability and strict-capability-match at the same time";
479 break;
480 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
481 str = "Specify remote-as or peer-group remote AS first";
482 break;
483 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
484 str = "Cannot change the peer-group. Deconfigure first";
485 break;
486 case BGP_ERR_PEER_GROUP_MISMATCH:
487 str = "Peer is not a member of this peer-group";
488 break;
489 case BGP_ERR_PEER_FILTER_CONFLICT:
490 str = "Prefix/distribute list can not co-exist";
491 break;
492 case BGP_ERR_NOT_INTERNAL_PEER:
493 str = "Invalid command. Not an internal neighbor";
494 break;
495 case BGP_ERR_REMOVE_PRIVATE_AS:
496 str = "remove-private-AS cannot be configured for IBGP peers";
497 break;
498 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
499 str = "Local-AS allowed only for EBGP peers";
500 break;
501 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
502 str = "Cannot have local-as same as BGP AS number";
503 break;
504 case BGP_ERR_TCPSIG_FAILED:
505 str = "Error while applying TCP-Sig to session(s)";
506 break;
507 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
508 str = "ebgp-multihop and ttl-security cannot be configured together";
509 break;
510 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
511 str = "ttl-security only allowed for EBGP peers";
512 break;
513 case BGP_ERR_AS_OVERRIDE:
514 str = "as-override cannot be configured for IBGP peers";
515 break;
516 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
517 str = "Invalid limit for number of dynamic neighbors";
518 break;
519 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
520 str = "Dynamic neighbor listen range already exists";
521 break;
522 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
523 str = "Operation not allowed on a dynamic neighbor";
524 break;
525 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
526 str = "Operation not allowed on a directly connected neighbor";
527 break;
528 case BGP_ERR_PEER_SAFI_CONFLICT:
529 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
530 break;
531 }
532 if (str) {
533 vty_out(vty, "%% %s\n", str);
534 return CMD_WARNING_CONFIG_FAILED;
535 }
536 return CMD_SUCCESS;
718e3744 537}
538
7aafcaca 539/* BGP clear sort. */
d62a17ae 540enum clear_sort {
541 clear_all,
542 clear_peer,
543 clear_group,
544 clear_external,
545 clear_as
7aafcaca
DS
546};
547
d62a17ae 548static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
549 safi_t safi, int error)
550{
551 switch (error) {
552 case BGP_ERR_AF_UNCONFIGURED:
553 vty_out(vty,
554 "%%BGP: Enable %s address family for the neighbor %s\n",
555 afi_safi_print(afi, safi), peer->host);
556 break;
557 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
558 vty_out(vty,
559 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
560 peer->host);
561 break;
562 default:
563 break;
564 }
7aafcaca
DS
565}
566
567/* `clear ip bgp' functions. */
d62a17ae 568static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
569 enum clear_sort sort, enum bgp_clear_type stype,
570 const char *arg)
571{
572 int ret;
3ae8bfa5 573 bool found = false;
d62a17ae 574 struct peer *peer;
575 struct listnode *node, *nnode;
576
577 /* Clear all neighbors. */
578 /*
579 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
580 * nodes on the BGP instance as that may get freed if it is a
581 * doppelganger
d62a17ae 582 */
583 if (sort == clear_all) {
584 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
585 if (!peer->afc[afi][safi])
586 continue;
587
d62a17ae 588 if (stype == BGP_CLEAR_SOFT_NONE)
589 ret = peer_clear(peer, &nnode);
d62a17ae 590 else
3ae8bfa5 591 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 592
593 if (ret < 0)
594 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
595 else
596 found = true;
04b6bdc0 597 }
d62a17ae 598
599 /* This is to apply read-only mode on this clear. */
600 if (stype == BGP_CLEAR_SOFT_NONE)
601 bgp->update_delay_over = 0;
602
3ae8bfa5
PM
603 if (!found)
604 vty_out(vty, "%%BGP: No %s peer configured",
605 afi_safi_print(afi, safi));
606
d62a17ae 607 return CMD_SUCCESS;
7aafcaca
DS
608 }
609
3ae8bfa5 610 /* Clear specified neighbor. */
d62a17ae 611 if (sort == clear_peer) {
612 union sockunion su;
d62a17ae 613
614 /* Make sockunion for lookup. */
615 ret = str2sockunion(arg, &su);
616 if (ret < 0) {
617 peer = peer_lookup_by_conf_if(bgp, arg);
618 if (!peer) {
619 peer = peer_lookup_by_hostname(bgp, arg);
620 if (!peer) {
621 vty_out(vty,
622 "Malformed address or name: %s\n",
623 arg);
624 return CMD_WARNING;
625 }
626 }
627 } else {
628 peer = peer_lookup(bgp, &su);
629 if (!peer) {
630 vty_out(vty,
631 "%%BGP: Unknown neighbor - \"%s\"\n",
632 arg);
633 return CMD_WARNING;
634 }
635 }
7aafcaca 636
3ae8bfa5
PM
637 if (!peer->afc[afi][safi])
638 ret = BGP_ERR_AF_UNCONFIGURED;
639 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 640 ret = peer_clear(peer, NULL);
641 else
642 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 643
d62a17ae 644 if (ret < 0)
645 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 646
d62a17ae 647 return CMD_SUCCESS;
7aafcaca 648 }
7aafcaca 649
3ae8bfa5 650 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 651 if (sort == clear_group) {
652 struct peer_group *group;
7aafcaca 653
d62a17ae 654 group = peer_group_lookup(bgp, arg);
655 if (!group) {
656 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
657 return CMD_WARNING;
658 }
659
660 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 661 if (!peer->afc[afi][safi])
662 continue;
663
3ae8bfa5
PM
664 if (stype == BGP_CLEAR_SOFT_NONE)
665 ret = peer_clear(peer, NULL);
666 else
667 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 668
d62a17ae 669 if (ret < 0)
670 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
671 else
672 found = true;
d62a17ae 673 }
3ae8bfa5
PM
674
675 if (!found)
676 vty_out(vty,
677 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
678 afi_safi_print(afi, safi), arg);
679
d62a17ae 680 return CMD_SUCCESS;
7aafcaca 681 }
7aafcaca 682
3ae8bfa5 683 /* Clear all external (eBGP) neighbors. */
d62a17ae 684 if (sort == clear_external) {
685 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
686 if (peer->sort == BGP_PEER_IBGP)
687 continue;
7aafcaca 688
3ae8bfa5
PM
689 if (!peer->afc[afi][safi])
690 continue;
691
d62a17ae 692 if (stype == BGP_CLEAR_SOFT_NONE)
693 ret = peer_clear(peer, &nnode);
694 else
695 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 696
d62a17ae 697 if (ret < 0)
698 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
699 else
700 found = true;
d62a17ae 701 }
3ae8bfa5
PM
702
703 if (!found)
704 vty_out(vty,
705 "%%BGP: No external %s peer is configured\n",
706 afi_safi_print(afi, safi));
707
d62a17ae 708 return CMD_SUCCESS;
709 }
710
3ae8bfa5 711 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 712 if (sort == clear_as) {
3ae8bfa5 713 as_t as = strtoul(arg, NULL, 10);
d62a17ae 714
715 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
716 if (peer->as != as)
717 continue;
718
3ae8bfa5
PM
719 if (!peer->afc[afi][safi])
720 ret = BGP_ERR_AF_UNCONFIGURED;
721 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 722 ret = peer_clear(peer, &nnode);
723 else
724 ret = peer_clear_soft(peer, afi, safi, stype);
725
726 if (ret < 0)
727 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
728 else
729 found = true;
d62a17ae 730 }
3ae8bfa5
PM
731
732 if (!found)
d62a17ae 733 vty_out(vty,
3ae8bfa5
PM
734 "%%BGP: No %s peer is configured with AS %s\n",
735 afi_safi_print(afi, safi), arg);
736
d62a17ae 737 return CMD_SUCCESS;
738 }
739
740 return CMD_SUCCESS;
741}
742
743static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
744 safi_t safi, enum clear_sort sort,
745 enum bgp_clear_type stype, const char *arg)
746{
747 struct bgp *bgp;
748
749 /* BGP structure lookup. */
750 if (name) {
751 bgp = bgp_lookup_by_name(name);
752 if (bgp == NULL) {
753 vty_out(vty, "Can't find BGP instance %s\n", name);
754 return CMD_WARNING;
755 }
756 } else {
757 bgp = bgp_get_default();
758 if (bgp == NULL) {
759 vty_out(vty, "No BGP process is configured\n");
760 return CMD_WARNING;
761 }
762 }
763
764 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
765}
766
767/* clear soft inbound */
d62a17ae 768static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 769{
d62a17ae 770 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
771 BGP_CLEAR_SOFT_IN, NULL);
772 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
773 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
774}
775
776/* clear soft outbound */
d62a17ae 777static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 778{
d62a17ae 779 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
780 BGP_CLEAR_SOFT_OUT, NULL);
781 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
782 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
783}
784
785
f787d7a0 786#ifndef VTYSH_EXTRACT_PL
2e4c2296 787#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
788#endif
789
718e3744 790/* BGP global configuration. */
bee57a7a 791#if (CONFDATE > 20190601)
1cc40660
DS
792CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
793CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
794#endif
795DEFUN_HIDDEN (bgp_multiple_instance_func,
796 bgp_multiple_instance_cmd,
797 "bgp multiple-instance",
798 BGP_STR
799 "Enable bgp multiple instance\n")
718e3744 800{
d62a17ae 801 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
802 return CMD_SUCCESS;
718e3744 803}
804
1cc40660 805DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 806 no_bgp_multiple_instance_cmd,
807 "no bgp multiple-instance",
808 NO_STR
809 BGP_STR
810 "BGP multiple instance\n")
811{
d62a17ae 812 int ret;
718e3744 813
1cc40660
DS
814 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
815 vty_out(vty, "if you are using this please let the developers know\n");
b7cd3069 816 zlog_info("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 817 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
818 if (ret < 0) {
819 vty_out(vty, "%% There are more than two BGP instances\n");
820 return CMD_WARNING_CONFIG_FAILED;
821 }
822 return CMD_SUCCESS;
718e3744 823}
824
bee57a7a 825#if (CONFDATE > 20190601)
798467a2
DS
826CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
827CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
828#endif
829DEFUN_HIDDEN (bgp_config_type,
830 bgp_config_type_cmd,
831 "bgp config-type <cisco|zebra>",
832 BGP_STR
833 "Configuration type\n"
834 "cisco\n"
835 "zebra\n")
718e3744 836{
d62a17ae 837 int idx = 0;
798467a2
DS
838 if (argv_find(argv, argc, "cisco", &idx)) {
839 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
840 vty_out(vty, "if you are using this please let the developers know!\n");
b7cd3069 841 zlog_info("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 842 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 843 } else
d62a17ae 844 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 845
d62a17ae 846 return CMD_SUCCESS;
718e3744 847}
848
798467a2
DS
849DEFUN_HIDDEN (no_bgp_config_type,
850 no_bgp_config_type_cmd,
851 "no bgp config-type [<cisco|zebra>]",
852 NO_STR
853 BGP_STR
854 "Display configuration type\n"
855 "cisco\n"
856 "zebra\n")
718e3744 857{
d62a17ae 858 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
859 return CMD_SUCCESS;
718e3744 860}
861
813d4307 862
718e3744 863DEFUN (no_synchronization,
864 no_synchronization_cmd,
865 "no synchronization",
866 NO_STR
867 "Perform IGP synchronization\n")
868{
d62a17ae 869 return CMD_SUCCESS;
718e3744 870}
871
872DEFUN (no_auto_summary,
873 no_auto_summary_cmd,
874 "no auto-summary",
875 NO_STR
876 "Enable automatic network number summarization\n")
877{
d62a17ae 878 return CMD_SUCCESS;
718e3744 879}
3d515fd9 880
718e3744 881/* "router bgp" commands. */
505e5056 882DEFUN_NOSH (router_bgp,
f412b39a 883 router_bgp_cmd,
18c57037 884 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 885 ROUTER_STR
886 BGP_STR
31500417
DW
887 AS_STR
888 BGP_INSTANCE_HELP_STR)
718e3744 889{
d62a17ae 890 int idx_asn = 2;
891 int idx_view_vrf = 3;
892 int idx_vrf = 4;
893 int ret;
894 as_t as;
895 struct bgp *bgp;
896 const char *name = NULL;
897 enum bgp_instance_type inst_type;
898
899 // "router bgp" without an ASN
900 if (argc == 2) {
901 // Pending: Make VRF option available for ASN less config
902 bgp = bgp_get_default();
903
904 if (bgp == NULL) {
905 vty_out(vty, "%% No BGP process is configured\n");
906 return CMD_WARNING_CONFIG_FAILED;
907 }
908
909 if (listcount(bm->bgp) > 1) {
996c9314 910 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 911 return CMD_WARNING_CONFIG_FAILED;
912 }
913 }
914
915 // "router bgp X"
916 else {
917 as = strtoul(argv[idx_asn]->arg, NULL, 10);
918
919 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
920 if (argc > 3) {
921 name = argv[idx_vrf]->arg;
922
9a8bdf1c
PG
923 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
924 if (strmatch(name, VRF_DEFAULT_NAME))
925 name = NULL;
926 else
927 inst_type = BGP_INSTANCE_TYPE_VRF;
928 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 929 inst_type = BGP_INSTANCE_TYPE_VIEW;
930 }
931
932 ret = bgp_get(&bgp, &as, name, inst_type);
933 switch (ret) {
934 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
935 vty_out(vty,
936 "Please specify 'bgp multiple-instance' first\n");
937 return CMD_WARNING_CONFIG_FAILED;
938 case BGP_ERR_AS_MISMATCH:
939 vty_out(vty, "BGP is already running; AS is %u\n", as);
940 return CMD_WARNING_CONFIG_FAILED;
941 case BGP_ERR_INSTANCE_MISMATCH:
942 vty_out(vty,
943 "BGP instance name and AS number mismatch\n");
944 vty_out(vty,
945 "BGP instance is already running; AS is %u\n",
946 as);
947 return CMD_WARNING_CONFIG_FAILED;
948 }
949
3bd70bf8
PZ
950 /*
951 * If we just instantiated the default instance, complete
952 * any pending VRF-VPN leaking that was configured via
953 * earlier "router bgp X vrf FOO" blocks.
954 */
955 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
956 vpn_leak_postchange_all();
957
d62a17ae 958 /* Pending: handle when user tries to change a view to vrf n vv.
959 */
960 }
961
0b5131c9
MK
962 /* unset the auto created flag as the user config is now present */
963 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 964 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
965
966 return CMD_SUCCESS;
718e3744 967}
968
718e3744 969/* "no router bgp" commands. */
970DEFUN (no_router_bgp,
971 no_router_bgp_cmd,
18c57037 972 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 973 NO_STR
974 ROUTER_STR
975 BGP_STR
31500417
DW
976 AS_STR
977 BGP_INSTANCE_HELP_STR)
718e3744 978{
d62a17ae 979 int idx_asn = 3;
980 int idx_vrf = 5;
981 as_t as;
982 struct bgp *bgp;
983 const char *name = NULL;
718e3744 984
d62a17ae 985 // "no router bgp" without an ASN
986 if (argc == 3) {
987 // Pending: Make VRF option available for ASN less config
988 bgp = bgp_get_default();
718e3744 989
d62a17ae 990 if (bgp == NULL) {
991 vty_out(vty, "%% No BGP process is configured\n");
992 return CMD_WARNING_CONFIG_FAILED;
993 }
7fb21a9f 994
d62a17ae 995 if (listcount(bm->bgp) > 1) {
996c9314 996 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 997 return CMD_WARNING_CONFIG_FAILED;
998 }
0b5131c9
MK
999
1000 if (bgp->l3vni) {
1001 vty_out(vty, "%% Please unconfigure l3vni %u",
1002 bgp->l3vni);
1003 return CMD_WARNING_CONFIG_FAILED;
1004 }
d62a17ae 1005 } else {
1006 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1007
d62a17ae 1008 if (argc > 4)
1009 name = argv[idx_vrf]->arg;
7fb21a9f 1010
d62a17ae 1011 /* Lookup bgp structure. */
1012 bgp = bgp_lookup(as, name);
1013 if (!bgp) {
1014 vty_out(vty, "%% Can't find BGP instance\n");
1015 return CMD_WARNING_CONFIG_FAILED;
1016 }
0b5131c9
MK
1017
1018 if (bgp->l3vni) {
1019 vty_out(vty, "%% Please unconfigure l3vni %u",
1020 bgp->l3vni);
1021 return CMD_WARNING_CONFIG_FAILED;
1022 }
d62a17ae 1023 }
718e3744 1024
d62a17ae 1025 bgp_delete(bgp);
718e3744 1026
d62a17ae 1027 return CMD_SUCCESS;
718e3744 1028}
1029
6b0655a2 1030
718e3744 1031/* BGP router-id. */
1032
f787d7a0 1033DEFPY (bgp_router_id,
718e3744 1034 bgp_router_id_cmd,
1035 "bgp router-id A.B.C.D",
1036 BGP_STR
1037 "Override configured router identifier\n"
1038 "Manually configured router identifier\n")
1039{
d62a17ae 1040 VTY_DECLVAR_CONTEXT(bgp, bgp);
1041 bgp_router_id_static_set(bgp, router_id);
1042 return CMD_SUCCESS;
718e3744 1043}
1044
f787d7a0 1045DEFPY (no_bgp_router_id,
718e3744 1046 no_bgp_router_id_cmd,
31500417 1047 "no bgp router-id [A.B.C.D]",
718e3744 1048 NO_STR
1049 BGP_STR
31500417
DW
1050 "Override configured router identifier\n"
1051 "Manually configured router identifier\n")
718e3744 1052{
d62a17ae 1053 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1054
d62a17ae 1055 if (router_id_str) {
1056 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1057 vty_out(vty, "%% BGP router-id doesn't match\n");
1058 return CMD_WARNING_CONFIG_FAILED;
1059 }
e018c7cc 1060 }
718e3744 1061
d62a17ae 1062 router_id.s_addr = 0;
1063 bgp_router_id_static_set(bgp, router_id);
718e3744 1064
d62a17ae 1065 return CMD_SUCCESS;
718e3744 1066}
1067
6b0655a2 1068
718e3744 1069/* BGP Cluster ID. */
718e3744 1070DEFUN (bgp_cluster_id,
1071 bgp_cluster_id_cmd,
838758ac 1072 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1073 BGP_STR
1074 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1075 "Route-Reflector Cluster-id in IP address format\n"
1076 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1077{
d62a17ae 1078 VTY_DECLVAR_CONTEXT(bgp, bgp);
1079 int idx_ipv4 = 2;
1080 int ret;
1081 struct in_addr cluster;
718e3744 1082
d62a17ae 1083 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1084 if (!ret) {
1085 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1086 return CMD_WARNING_CONFIG_FAILED;
1087 }
718e3744 1088
d62a17ae 1089 bgp_cluster_id_set(bgp, &cluster);
1090 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1091
d62a17ae 1092 return CMD_SUCCESS;
718e3744 1093}
1094
718e3744 1095DEFUN (no_bgp_cluster_id,
1096 no_bgp_cluster_id_cmd,
c7178fe7 1097 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1098 NO_STR
1099 BGP_STR
838758ac
DW
1100 "Configure Route-Reflector Cluster-id\n"
1101 "Route-Reflector Cluster-id in IP address format\n"
1102 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1103{
d62a17ae 1104 VTY_DECLVAR_CONTEXT(bgp, bgp);
1105 bgp_cluster_id_unset(bgp);
1106 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1107
d62a17ae 1108 return CMD_SUCCESS;
718e3744 1109}
1110
718e3744 1111DEFUN (bgp_confederation_identifier,
1112 bgp_confederation_identifier_cmd,
9ccf14f7 1113 "bgp confederation identifier (1-4294967295)",
718e3744 1114 "BGP specific commands\n"
1115 "AS confederation parameters\n"
1116 "AS number\n"
1117 "Set routing domain confederation AS\n")
1118{
d62a17ae 1119 VTY_DECLVAR_CONTEXT(bgp, bgp);
1120 int idx_number = 3;
1121 as_t as;
718e3744 1122
d62a17ae 1123 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1124
d62a17ae 1125 bgp_confederation_id_set(bgp, as);
718e3744 1126
d62a17ae 1127 return CMD_SUCCESS;
718e3744 1128}
1129
1130DEFUN (no_bgp_confederation_identifier,
1131 no_bgp_confederation_identifier_cmd,
838758ac 1132 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1133 NO_STR
1134 "BGP specific commands\n"
1135 "AS confederation parameters\n"
3a2d747c
QY
1136 "AS number\n"
1137 "Set routing domain confederation AS\n")
718e3744 1138{
d62a17ae 1139 VTY_DECLVAR_CONTEXT(bgp, bgp);
1140 bgp_confederation_id_unset(bgp);
718e3744 1141
d62a17ae 1142 return CMD_SUCCESS;
718e3744 1143}
1144
718e3744 1145DEFUN (bgp_confederation_peers,
1146 bgp_confederation_peers_cmd,
12dcf78e 1147 "bgp confederation peers (1-4294967295)...",
718e3744 1148 "BGP specific commands\n"
1149 "AS confederation parameters\n"
1150 "Peer ASs in BGP confederation\n"
1151 AS_STR)
1152{
d62a17ae 1153 VTY_DECLVAR_CONTEXT(bgp, bgp);
1154 int idx_asn = 3;
1155 as_t as;
1156 int i;
718e3744 1157
d62a17ae 1158 for (i = idx_asn; i < argc; i++) {
1159 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1160
d62a17ae 1161 if (bgp->as == as) {
1162 vty_out(vty,
1163 "%% Local member-AS not allowed in confed peer list\n");
1164 continue;
1165 }
718e3744 1166
d62a17ae 1167 bgp_confederation_peers_add(bgp, as);
1168 }
1169 return CMD_SUCCESS;
718e3744 1170}
1171
1172DEFUN (no_bgp_confederation_peers,
1173 no_bgp_confederation_peers_cmd,
e83a9414 1174 "no bgp confederation peers (1-4294967295)...",
718e3744 1175 NO_STR
1176 "BGP specific commands\n"
1177 "AS confederation parameters\n"
1178 "Peer ASs in BGP confederation\n"
1179 AS_STR)
1180{
d62a17ae 1181 VTY_DECLVAR_CONTEXT(bgp, bgp);
1182 int idx_asn = 4;
1183 as_t as;
1184 int i;
718e3744 1185
d62a17ae 1186 for (i = idx_asn; i < argc; i++) {
1187 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1188
d62a17ae 1189 bgp_confederation_peers_remove(bgp, as);
1190 }
1191 return CMD_SUCCESS;
718e3744 1192}
6b0655a2 1193
5e242b0d
DS
1194/**
1195 * Central routine for maximum-paths configuration.
1196 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1197 * @set: 1 for setting values, 0 for removing the max-paths config.
1198 */
d62a17ae 1199static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1200 const char *mpaths, uint16_t options,
d62a17ae 1201 int set)
1202{
1203 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1204 uint16_t maxpaths = 0;
d62a17ae 1205 int ret;
1206 afi_t afi;
1207 safi_t safi;
1208
1209 afi = bgp_node_afi(vty);
1210 safi = bgp_node_safi(vty);
1211
1212 if (set) {
1213 maxpaths = strtol(mpaths, NULL, 10);
1214 if (maxpaths > multipath_num) {
1215 vty_out(vty,
1216 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1217 maxpaths, multipath_num);
1218 return CMD_WARNING_CONFIG_FAILED;
1219 }
1220 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1221 options);
1222 } else
1223 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1224
1225 if (ret < 0) {
1226 vty_out(vty,
1227 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1228 (set == 1) ? "" : "un",
1229 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1230 maxpaths, afi, safi);
1231 return CMD_WARNING_CONFIG_FAILED;
1232 }
1233
1234 bgp_recalculate_all_bestpaths(bgp);
1235
1236 return CMD_SUCCESS;
165b5fff
JB
1237}
1238
abc920f8
DS
1239DEFUN (bgp_maxmed_admin,
1240 bgp_maxmed_admin_cmd,
1241 "bgp max-med administrative ",
1242 BGP_STR
1243 "Advertise routes with max-med\n"
1244 "Administratively applied, for an indefinite period\n")
1245{
d62a17ae 1246 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1247
d62a17ae 1248 bgp->v_maxmed_admin = 1;
1249 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1250
d62a17ae 1251 bgp_maxmed_update(bgp);
abc920f8 1252
d62a17ae 1253 return CMD_SUCCESS;
abc920f8
DS
1254}
1255
1256DEFUN (bgp_maxmed_admin_medv,
1257 bgp_maxmed_admin_medv_cmd,
4668a151 1258 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1259 BGP_STR
1260 "Advertise routes with max-med\n"
1261 "Administratively applied, for an indefinite period\n"
1262 "Max MED value to be used\n")
1263{
d62a17ae 1264 VTY_DECLVAR_CONTEXT(bgp, bgp);
1265 int idx_number = 3;
abc920f8 1266
d62a17ae 1267 bgp->v_maxmed_admin = 1;
1268 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1269
d62a17ae 1270 bgp_maxmed_update(bgp);
abc920f8 1271
d62a17ae 1272 return CMD_SUCCESS;
abc920f8
DS
1273}
1274
1275DEFUN (no_bgp_maxmed_admin,
1276 no_bgp_maxmed_admin_cmd,
4668a151 1277 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1278 NO_STR
1279 BGP_STR
1280 "Advertise routes with max-med\n"
838758ac
DW
1281 "Administratively applied, for an indefinite period\n"
1282 "Max MED value to be used\n")
abc920f8 1283{
d62a17ae 1284 VTY_DECLVAR_CONTEXT(bgp, bgp);
1285 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1286 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1287 bgp_maxmed_update(bgp);
abc920f8 1288
d62a17ae 1289 return CMD_SUCCESS;
abc920f8
DS
1290}
1291
abc920f8
DS
1292DEFUN (bgp_maxmed_onstartup,
1293 bgp_maxmed_onstartup_cmd,
4668a151 1294 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1295 BGP_STR
1296 "Advertise routes with max-med\n"
1297 "Effective on a startup\n"
1298 "Time (seconds) period for max-med\n"
1299 "Max MED value to be used\n")
1300{
d62a17ae 1301 VTY_DECLVAR_CONTEXT(bgp, bgp);
1302 int idx = 0;
4668a151 1303
d62a17ae 1304 argv_find(argv, argc, "(5-86400)", &idx);
1305 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1306 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1307 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1308 else
1309 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1310
d62a17ae 1311 bgp_maxmed_update(bgp);
abc920f8 1312
d62a17ae 1313 return CMD_SUCCESS;
abc920f8
DS
1314}
1315
1316DEFUN (no_bgp_maxmed_onstartup,
1317 no_bgp_maxmed_onstartup_cmd,
4668a151 1318 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1319 NO_STR
1320 BGP_STR
1321 "Advertise routes with max-med\n"
838758ac
DW
1322 "Effective on a startup\n"
1323 "Time (seconds) period for max-med\n"
1324 "Max MED value to be used\n")
abc920f8 1325{
d62a17ae 1326 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1327
d62a17ae 1328 /* Cancel max-med onstartup if its on */
1329 if (bgp->t_maxmed_onstartup) {
1330 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1331 bgp->maxmed_onstartup_over = 1;
1332 }
abc920f8 1333
d62a17ae 1334 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1335 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1336
d62a17ae 1337 bgp_maxmed_update(bgp);
abc920f8 1338
d62a17ae 1339 return CMD_SUCCESS;
abc920f8
DS
1340}
1341
d62a17ae 1342static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1343 const char *wait)
f188f2c4 1344{
d62a17ae 1345 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1346 uint16_t update_delay;
1347 uint16_t establish_wait;
f188f2c4 1348
d62a17ae 1349 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1350
d62a17ae 1351 if (!wait) /* update-delay <delay> */
1352 {
1353 bgp->v_update_delay = update_delay;
1354 bgp->v_establish_wait = bgp->v_update_delay;
1355 return CMD_SUCCESS;
1356 }
f188f2c4 1357
d62a17ae 1358 /* update-delay <delay> <establish-wait> */
1359 establish_wait = atoi(wait);
1360 if (update_delay < establish_wait) {
1361 vty_out(vty,
1362 "%%Failed: update-delay less than the establish-wait!\n");
1363 return CMD_WARNING_CONFIG_FAILED;
1364 }
f188f2c4 1365
d62a17ae 1366 bgp->v_update_delay = update_delay;
1367 bgp->v_establish_wait = establish_wait;
f188f2c4 1368
d62a17ae 1369 return CMD_SUCCESS;
f188f2c4
DS
1370}
1371
d62a17ae 1372static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1373{
d62a17ae 1374 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1375
d62a17ae 1376 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1377 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1378
d62a17ae 1379 return CMD_SUCCESS;
f188f2c4
DS
1380}
1381
2b791107 1382void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1383{
d62a17ae 1384 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1385 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1386 if (bgp->v_update_delay != bgp->v_establish_wait)
1387 vty_out(vty, " %d", bgp->v_establish_wait);
1388 vty_out(vty, "\n");
1389 }
f188f2c4
DS
1390}
1391
1392
1393/* Update-delay configuration */
1394DEFUN (bgp_update_delay,
1395 bgp_update_delay_cmd,
6147e2c6 1396 "update-delay (0-3600)",
f188f2c4
DS
1397 "Force initial delay for best-path and updates\n"
1398 "Seconds\n")
1399{
d62a17ae 1400 int idx_number = 1;
1401 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1402}
1403
1404DEFUN (bgp_update_delay_establish_wait,
1405 bgp_update_delay_establish_wait_cmd,
6147e2c6 1406 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1407 "Force initial delay for best-path and updates\n"
1408 "Seconds\n"
f188f2c4
DS
1409 "Seconds\n")
1410{
d62a17ae 1411 int idx_number = 1;
1412 int idx_number_2 = 2;
1413 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1414 argv[idx_number_2]->arg);
f188f2c4
DS
1415}
1416
1417/* Update-delay deconfiguration */
1418DEFUN (no_bgp_update_delay,
1419 no_bgp_update_delay_cmd,
838758ac
DW
1420 "no update-delay [(0-3600) [(1-3600)]]",
1421 NO_STR
f188f2c4 1422 "Force initial delay for best-path and updates\n"
838758ac 1423 "Seconds\n"
7111c1a0 1424 "Seconds\n")
f188f2c4 1425{
d62a17ae 1426 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1427}
1428
5e242b0d 1429
d62a17ae 1430static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1431 char set)
cb1faec9 1432{
d62a17ae 1433 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1434
555e09d4
QY
1435 if (set) {
1436 uint32_t quanta = strtoul(num, NULL, 10);
1437 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1438 memory_order_relaxed);
1439 } else {
1440 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1441 memory_order_relaxed);
1442 }
1443
1444 return CMD_SUCCESS;
1445}
1446
1447static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1448 char set)
1449{
1450 VTY_DECLVAR_CONTEXT(bgp, bgp);
1451
1452 if (set) {
1453 uint32_t quanta = strtoul(num, NULL, 10);
1454 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1455 memory_order_relaxed);
1456 } else {
1457 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1458 memory_order_relaxed);
1459 }
cb1faec9 1460
d62a17ae 1461 return CMD_SUCCESS;
cb1faec9
DS
1462}
1463
2b791107 1464void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1465{
555e09d4
QY
1466 uint32_t quanta =
1467 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1468 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1469 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1470}
1471
555e09d4
QY
1472void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1473{
1474 uint32_t quanta =
1475 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1476 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1477 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1478}
cb1faec9 1479
555e09d4 1480/* Packet quanta configuration */
cb1faec9
DS
1481DEFUN (bgp_wpkt_quanta,
1482 bgp_wpkt_quanta_cmd,
555e09d4 1483 "write-quanta (1-10)",
cb1faec9
DS
1484 "How many packets to write to peer socket per run\n"
1485 "Number of packets\n")
1486{
d62a17ae 1487 int idx_number = 1;
1488 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1489}
1490
cb1faec9
DS
1491DEFUN (no_bgp_wpkt_quanta,
1492 no_bgp_wpkt_quanta_cmd,
555e09d4 1493 "no write-quanta (1-10)",
d7fa34c1 1494 NO_STR
555e09d4 1495 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1496 "Number of packets\n")
1497{
d62a17ae 1498 int idx_number = 2;
1499 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1500}
1501
555e09d4
QY
1502DEFUN (bgp_rpkt_quanta,
1503 bgp_rpkt_quanta_cmd,
1504 "read-quanta (1-10)",
1505 "How many packets to read from peer socket per I/O cycle\n"
1506 "Number of packets\n")
1507{
1508 int idx_number = 1;
1509 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1510}
1511
1512DEFUN (no_bgp_rpkt_quanta,
1513 no_bgp_rpkt_quanta_cmd,
1514 "no read-quanta (1-10)",
1515 NO_STR
1516 "How many packets to read from peer socket per I/O cycle\n"
1517 "Number of packets\n")
1518{
1519 int idx_number = 2;
1520 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1521}
1522
2b791107 1523void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1524{
37a333fe 1525 if (!bgp->heuristic_coalesce)
d62a17ae 1526 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1527}
1528
1529
1530DEFUN (bgp_coalesce_time,
1531 bgp_coalesce_time_cmd,
6147e2c6 1532 "coalesce-time (0-4294967295)",
3f9c7369
DS
1533 "Subgroup coalesce timer\n"
1534 "Subgroup coalesce timer value (in ms)\n")
1535{
d62a17ae 1536 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1537
d62a17ae 1538 int idx = 0;
1539 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1540 bgp->heuristic_coalesce = false;
d62a17ae 1541 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1542 return CMD_SUCCESS;
3f9c7369
DS
1543}
1544
1545DEFUN (no_bgp_coalesce_time,
1546 no_bgp_coalesce_time_cmd,
6147e2c6 1547 "no coalesce-time (0-4294967295)",
3a2d747c 1548 NO_STR
3f9c7369
DS
1549 "Subgroup coalesce timer\n"
1550 "Subgroup coalesce timer value (in ms)\n")
1551{
d62a17ae 1552 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1553
37a333fe 1554 bgp->heuristic_coalesce = true;
d62a17ae 1555 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1556 return CMD_SUCCESS;
3f9c7369
DS
1557}
1558
5e242b0d
DS
1559/* Maximum-paths configuration */
1560DEFUN (bgp_maxpaths,
1561 bgp_maxpaths_cmd,
6319fd63 1562 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1563 "Forward packets over multiple paths\n"
1564 "Number of paths\n")
1565{
d62a17ae 1566 int idx_number = 1;
1567 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1568 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1569}
1570
d62a17ae 1571ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1572 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1573 "Forward packets over multiple paths\n"
1574 "Number of paths\n")
596c17ba 1575
165b5fff
JB
1576DEFUN (bgp_maxpaths_ibgp,
1577 bgp_maxpaths_ibgp_cmd,
6319fd63 1578 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1579 "Forward packets over multiple paths\n"
1580 "iBGP-multipath\n"
1581 "Number of paths\n")
1582{
d62a17ae 1583 int idx_number = 2;
1584 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1585 argv[idx_number]->arg, 0, 1);
5e242b0d 1586}
165b5fff 1587
d62a17ae 1588ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1589 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1590 "Forward packets over multiple paths\n"
1591 "iBGP-multipath\n"
1592 "Number of paths\n")
596c17ba 1593
5e242b0d
DS
1594DEFUN (bgp_maxpaths_ibgp_cluster,
1595 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1596 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1597 "Forward packets over multiple paths\n"
1598 "iBGP-multipath\n"
1599 "Number of paths\n"
1600 "Match the cluster length\n")
1601{
d62a17ae 1602 int idx_number = 2;
1603 return bgp_maxpaths_config_vty(
1604 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1605 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1606}
1607
d62a17ae 1608ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1609 "maximum-paths ibgp " CMD_RANGE_STR(
1610 1, MULTIPATH_NUM) " equal-cluster-length",
1611 "Forward packets over multiple paths\n"
1612 "iBGP-multipath\n"
1613 "Number of paths\n"
1614 "Match the cluster length\n")
596c17ba 1615
165b5fff
JB
1616DEFUN (no_bgp_maxpaths,
1617 no_bgp_maxpaths_cmd,
6319fd63 1618 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1619 NO_STR
1620 "Forward packets over multiple paths\n"
1621 "Number of paths\n")
1622{
d62a17ae 1623 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1624}
1625
d62a17ae 1626ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1627 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1628 "Forward packets over multiple paths\n"
1629 "Number of paths\n")
596c17ba 1630
165b5fff
JB
1631DEFUN (no_bgp_maxpaths_ibgp,
1632 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1633 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1634 NO_STR
1635 "Forward packets over multiple paths\n"
1636 "iBGP-multipath\n"
838758ac
DW
1637 "Number of paths\n"
1638 "Match the cluster length\n")
165b5fff 1639{
d62a17ae 1640 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1641}
1642
d62a17ae 1643ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1644 "no maximum-paths ibgp [" CMD_RANGE_STR(
1645 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1646 NO_STR
1647 "Forward packets over multiple paths\n"
1648 "iBGP-multipath\n"
1649 "Number of paths\n"
1650 "Match the cluster length\n")
596c17ba 1651
2b791107 1652void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1653 safi_t safi)
165b5fff 1654{
d62a17ae 1655 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1656 vty_out(vty, " maximum-paths %d\n",
1657 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1658 }
165b5fff 1659
d62a17ae 1660 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1661 vty_out(vty, " maximum-paths ibgp %d",
1662 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1663 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1664 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1665 vty_out(vty, " equal-cluster-length");
1666 vty_out(vty, "\n");
1667 }
165b5fff 1668}
6b0655a2 1669
718e3744 1670/* BGP timers. */
1671
1672DEFUN (bgp_timers,
1673 bgp_timers_cmd,
6147e2c6 1674 "timers bgp (0-65535) (0-65535)",
718e3744 1675 "Adjust routing timers\n"
1676 "BGP timers\n"
1677 "Keepalive interval\n"
1678 "Holdtime\n")
1679{
d62a17ae 1680 VTY_DECLVAR_CONTEXT(bgp, bgp);
1681 int idx_number = 2;
1682 int idx_number_2 = 3;
1683 unsigned long keepalive = 0;
1684 unsigned long holdtime = 0;
718e3744 1685
d62a17ae 1686 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1687 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1688
d62a17ae 1689 /* Holdtime value check. */
1690 if (holdtime < 3 && holdtime != 0) {
1691 vty_out(vty,
1692 "%% hold time value must be either 0 or greater than 3\n");
1693 return CMD_WARNING_CONFIG_FAILED;
1694 }
718e3744 1695
d62a17ae 1696 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1697
d62a17ae 1698 return CMD_SUCCESS;
718e3744 1699}
1700
1701DEFUN (no_bgp_timers,
1702 no_bgp_timers_cmd,
838758ac 1703 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1704 NO_STR
1705 "Adjust routing timers\n"
838758ac
DW
1706 "BGP timers\n"
1707 "Keepalive interval\n"
1708 "Holdtime\n")
718e3744 1709{
d62a17ae 1710 VTY_DECLVAR_CONTEXT(bgp, bgp);
1711 bgp_timers_unset(bgp);
718e3744 1712
d62a17ae 1713 return CMD_SUCCESS;
718e3744 1714}
1715
6b0655a2 1716
718e3744 1717DEFUN (bgp_client_to_client_reflection,
1718 bgp_client_to_client_reflection_cmd,
1719 "bgp client-to-client reflection",
1720 "BGP specific commands\n"
1721 "Configure client to client route reflection\n"
1722 "reflection of routes allowed\n")
1723{
d62a17ae 1724 VTY_DECLVAR_CONTEXT(bgp, bgp);
1725 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1726 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1727
d62a17ae 1728 return CMD_SUCCESS;
718e3744 1729}
1730
1731DEFUN (no_bgp_client_to_client_reflection,
1732 no_bgp_client_to_client_reflection_cmd,
1733 "no bgp client-to-client reflection",
1734 NO_STR
1735 "BGP specific commands\n"
1736 "Configure client to client route reflection\n"
1737 "reflection of routes allowed\n")
1738{
d62a17ae 1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1741 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1742
d62a17ae 1743 return CMD_SUCCESS;
718e3744 1744}
1745
1746/* "bgp always-compare-med" configuration. */
1747DEFUN (bgp_always_compare_med,
1748 bgp_always_compare_med_cmd,
1749 "bgp always-compare-med",
1750 "BGP specific commands\n"
1751 "Allow comparing MED from different neighbors\n")
1752{
d62a17ae 1753 VTY_DECLVAR_CONTEXT(bgp, bgp);
1754 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1755 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1756
d62a17ae 1757 return CMD_SUCCESS;
718e3744 1758}
1759
1760DEFUN (no_bgp_always_compare_med,
1761 no_bgp_always_compare_med_cmd,
1762 "no bgp always-compare-med",
1763 NO_STR
1764 "BGP specific commands\n"
1765 "Allow comparing MED from different neighbors\n")
1766{
d62a17ae 1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1769 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1770
d62a17ae 1771 return CMD_SUCCESS;
718e3744 1772}
6b0655a2 1773
718e3744 1774/* "bgp deterministic-med" configuration. */
1775DEFUN (bgp_deterministic_med,
1776 bgp_deterministic_med_cmd,
1777 "bgp deterministic-med",
1778 "BGP specific commands\n"
1779 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1780{
d62a17ae 1781 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1782
d62a17ae 1783 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1784 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1785 bgp_recalculate_all_bestpaths(bgp);
1786 }
7aafcaca 1787
d62a17ae 1788 return CMD_SUCCESS;
718e3744 1789}
1790
1791DEFUN (no_bgp_deterministic_med,
1792 no_bgp_deterministic_med_cmd,
1793 "no bgp deterministic-med",
1794 NO_STR
1795 "BGP specific commands\n"
1796 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1797{
d62a17ae 1798 VTY_DECLVAR_CONTEXT(bgp, bgp);
1799 int bestpath_per_as_used;
1800 afi_t afi;
1801 safi_t safi;
1802 struct peer *peer;
1803 struct listnode *node, *nnode;
1804
1805 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1806 bestpath_per_as_used = 0;
1807
1808 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1809 FOREACH_AFI_SAFI (afi, safi)
1810 if (CHECK_FLAG(
1811 peer->af_flags[afi][safi],
1812 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1813 bestpath_per_as_used = 1;
1814 break;
1815 }
d62a17ae 1816
1817 if (bestpath_per_as_used)
1818 break;
1819 }
1820
1821 if (bestpath_per_as_used) {
1822 vty_out(vty,
1823 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1824 return CMD_WARNING_CONFIG_FAILED;
1825 } else {
1826 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1827 bgp_recalculate_all_bestpaths(bgp);
1828 }
1829 }
1830
1831 return CMD_SUCCESS;
718e3744 1832}
538621f2 1833
1834/* "bgp graceful-restart" configuration. */
1835DEFUN (bgp_graceful_restart,
1836 bgp_graceful_restart_cmd,
1837 "bgp graceful-restart",
1838 "BGP specific commands\n"
1839 "Graceful restart capability parameters\n")
1840{
d62a17ae 1841 VTY_DECLVAR_CONTEXT(bgp, bgp);
1842 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1843 return CMD_SUCCESS;
538621f2 1844}
1845
1846DEFUN (no_bgp_graceful_restart,
1847 no_bgp_graceful_restart_cmd,
1848 "no bgp graceful-restart",
1849 NO_STR
1850 "BGP specific commands\n"
1851 "Graceful restart capability parameters\n")
1852{
d62a17ae 1853 VTY_DECLVAR_CONTEXT(bgp, bgp);
1854 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1855 return CMD_SUCCESS;
538621f2 1856}
1857
93406d87 1858DEFUN (bgp_graceful_restart_stalepath_time,
1859 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1860 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1861 "BGP specific commands\n"
1862 "Graceful restart capability parameters\n"
1863 "Set the max time to hold onto restarting peer's stale paths\n"
1864 "Delay value (seconds)\n")
1865{
d62a17ae 1866 VTY_DECLVAR_CONTEXT(bgp, bgp);
1867 int idx_number = 3;
d7c0a89a 1868 uint32_t stalepath;
93406d87 1869
d62a17ae 1870 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1871 bgp->stalepath_time = stalepath;
1872 return CMD_SUCCESS;
93406d87 1873}
1874
eb6f1b41
PG
1875DEFUN (bgp_graceful_restart_restart_time,
1876 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1877 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1878 "BGP specific commands\n"
1879 "Graceful restart capability parameters\n"
1880 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1881 "Delay value (seconds)\n")
1882{
d62a17ae 1883 VTY_DECLVAR_CONTEXT(bgp, bgp);
1884 int idx_number = 3;
d7c0a89a 1885 uint32_t restart;
eb6f1b41 1886
d62a17ae 1887 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1888 bgp->restart_time = restart;
1889 return CMD_SUCCESS;
eb6f1b41
PG
1890}
1891
93406d87 1892DEFUN (no_bgp_graceful_restart_stalepath_time,
1893 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1894 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1895 NO_STR
1896 "BGP specific commands\n"
1897 "Graceful restart capability parameters\n"
838758ac
DW
1898 "Set the max time to hold onto restarting peer's stale paths\n"
1899 "Delay value (seconds)\n")
93406d87 1900{
d62a17ae 1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1902
d62a17ae 1903 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1904 return CMD_SUCCESS;
93406d87 1905}
1906
eb6f1b41
PG
1907DEFUN (no_bgp_graceful_restart_restart_time,
1908 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1909 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1910 NO_STR
1911 "BGP specific commands\n"
1912 "Graceful restart capability parameters\n"
838758ac
DW
1913 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1914 "Delay value (seconds)\n")
eb6f1b41 1915{
d62a17ae 1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1917
d62a17ae 1918 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1919 return CMD_SUCCESS;
eb6f1b41
PG
1920}
1921
43fc21b3
JC
1922DEFUN (bgp_graceful_restart_preserve_fw,
1923 bgp_graceful_restart_preserve_fw_cmd,
1924 "bgp graceful-restart preserve-fw-state",
1925 "BGP specific commands\n"
1926 "Graceful restart capability parameters\n"
1927 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1928{
d62a17ae 1929 VTY_DECLVAR_CONTEXT(bgp, bgp);
1930 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1931 return CMD_SUCCESS;
43fc21b3
JC
1932}
1933
1934DEFUN (no_bgp_graceful_restart_preserve_fw,
1935 no_bgp_graceful_restart_preserve_fw_cmd,
1936 "no bgp graceful-restart preserve-fw-state",
1937 NO_STR
1938 "BGP specific commands\n"
1939 "Graceful restart capability parameters\n"
1940 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1941{
d62a17ae 1942 VTY_DECLVAR_CONTEXT(bgp, bgp);
1943 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1944 return CMD_SUCCESS;
43fc21b3
JC
1945}
1946
7f323236
DW
1947static void bgp_redistribute_redo(struct bgp *bgp)
1948{
1949 afi_t afi;
1950 int i;
1951 struct list *red_list;
1952 struct listnode *node;
1953 struct bgp_redist *red;
1954
a4d82a8a
PZ
1955 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1956 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1957
a4d82a8a
PZ
1958 red_list = bgp->redist[afi][i];
1959 if (!red_list)
1960 continue;
7f323236 1961
a4d82a8a 1962 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1963 bgp_redistribute_resend(bgp, afi, i,
1964 red->instance);
1965 }
1966 }
1967 }
1968}
1969
1970/* "bgp graceful-shutdown" configuration */
1971DEFUN (bgp_graceful_shutdown,
1972 bgp_graceful_shutdown_cmd,
1973 "bgp graceful-shutdown",
1974 BGP_STR
1975 "Graceful shutdown parameters\n")
1976{
1977 VTY_DECLVAR_CONTEXT(bgp, bgp);
1978
1979 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1980 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1981 bgp_static_redo_import_check(bgp);
1982 bgp_redistribute_redo(bgp);
1983 bgp_clear_star_soft_out(vty, bgp->name);
1984 bgp_clear_star_soft_in(vty, bgp->name);
1985 }
1986
1987 return CMD_SUCCESS;
1988}
1989
1990DEFUN (no_bgp_graceful_shutdown,
1991 no_bgp_graceful_shutdown_cmd,
1992 "no bgp graceful-shutdown",
1993 NO_STR
1994 BGP_STR
1995 "Graceful shutdown parameters\n")
1996{
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998
1999 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2000 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2001 bgp_static_redo_import_check(bgp);
2002 bgp_redistribute_redo(bgp);
2003 bgp_clear_star_soft_out(vty, bgp->name);
2004 bgp_clear_star_soft_in(vty, bgp->name);
2005 }
2006
2007 return CMD_SUCCESS;
2008}
2009
718e3744 2010/* "bgp fast-external-failover" configuration. */
2011DEFUN (bgp_fast_external_failover,
2012 bgp_fast_external_failover_cmd,
2013 "bgp fast-external-failover",
2014 BGP_STR
2015 "Immediately reset session if a link to a directly connected external peer goes down\n")
2016{
d62a17ae 2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2019 return CMD_SUCCESS;
718e3744 2020}
2021
2022DEFUN (no_bgp_fast_external_failover,
2023 no_bgp_fast_external_failover_cmd,
2024 "no bgp fast-external-failover",
2025 NO_STR
2026 BGP_STR
2027 "Immediately reset session if a link to a directly connected external peer goes down\n")
2028{
d62a17ae 2029 VTY_DECLVAR_CONTEXT(bgp, bgp);
2030 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2031 return CMD_SUCCESS;
718e3744 2032}
6b0655a2 2033
718e3744 2034/* "bgp enforce-first-as" configuration. */
ec4f0750 2035#if CONFDATE > 20190517
47cbc09b
PM
2036CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2037#endif
2038
f07e1c4f
QY
2039DEFUN_HIDDEN (bgp_enforce_first_as,
2040 bgp_enforce_first_as_cmd,
2041 "[no] bgp enforce-first-as",
2042 NO_STR
2043 BGP_STR
2044 "Enforce the first AS for EBGP routes\n")
718e3744 2045{
d62a17ae 2046 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2047
f07e1c4f
QY
2048 if (strmatch(argv[0]->text, "no"))
2049 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2050 else
2051 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2052
d62a17ae 2053 return CMD_SUCCESS;
718e3744 2054}
6b0655a2 2055
718e3744 2056/* "bgp bestpath compare-routerid" configuration. */
2057DEFUN (bgp_bestpath_compare_router_id,
2058 bgp_bestpath_compare_router_id_cmd,
2059 "bgp bestpath compare-routerid",
2060 "BGP specific commands\n"
2061 "Change the default bestpath selection\n"
2062 "Compare router-id for identical EBGP paths\n")
2063{
d62a17ae 2064 VTY_DECLVAR_CONTEXT(bgp, bgp);
2065 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2066 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2067
d62a17ae 2068 return CMD_SUCCESS;
718e3744 2069}
2070
2071DEFUN (no_bgp_bestpath_compare_router_id,
2072 no_bgp_bestpath_compare_router_id_cmd,
2073 "no bgp bestpath compare-routerid",
2074 NO_STR
2075 "BGP specific commands\n"
2076 "Change the default bestpath selection\n"
2077 "Compare router-id for identical EBGP paths\n")
2078{
d62a17ae 2079 VTY_DECLVAR_CONTEXT(bgp, bgp);
2080 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2081 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2082
d62a17ae 2083 return CMD_SUCCESS;
718e3744 2084}
6b0655a2 2085
718e3744 2086/* "bgp bestpath as-path ignore" configuration. */
2087DEFUN (bgp_bestpath_aspath_ignore,
2088 bgp_bestpath_aspath_ignore_cmd,
2089 "bgp bestpath as-path ignore",
2090 "BGP specific commands\n"
2091 "Change the default bestpath selection\n"
2092 "AS-path attribute\n"
2093 "Ignore as-path length in selecting a route\n")
2094{
d62a17ae 2095 VTY_DECLVAR_CONTEXT(bgp, bgp);
2096 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2097 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2098
d62a17ae 2099 return CMD_SUCCESS;
718e3744 2100}
2101
2102DEFUN (no_bgp_bestpath_aspath_ignore,
2103 no_bgp_bestpath_aspath_ignore_cmd,
2104 "no bgp bestpath as-path ignore",
2105 NO_STR
2106 "BGP specific commands\n"
2107 "Change the default bestpath selection\n"
2108 "AS-path attribute\n"
2109 "Ignore as-path length in selecting a route\n")
2110{
d62a17ae 2111 VTY_DECLVAR_CONTEXT(bgp, bgp);
2112 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2113 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2114
d62a17ae 2115 return CMD_SUCCESS;
718e3744 2116}
6b0655a2 2117
6811845b 2118/* "bgp bestpath as-path confed" configuration. */
2119DEFUN (bgp_bestpath_aspath_confed,
2120 bgp_bestpath_aspath_confed_cmd,
2121 "bgp bestpath as-path confed",
2122 "BGP specific commands\n"
2123 "Change the default bestpath selection\n"
2124 "AS-path attribute\n"
2125 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2126{
d62a17ae 2127 VTY_DECLVAR_CONTEXT(bgp, bgp);
2128 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2129 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2130
d62a17ae 2131 return CMD_SUCCESS;
6811845b 2132}
2133
2134DEFUN (no_bgp_bestpath_aspath_confed,
2135 no_bgp_bestpath_aspath_confed_cmd,
2136 "no bgp bestpath as-path confed",
2137 NO_STR
2138 "BGP specific commands\n"
2139 "Change the default bestpath selection\n"
2140 "AS-path attribute\n"
2141 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2142{
d62a17ae 2143 VTY_DECLVAR_CONTEXT(bgp, bgp);
2144 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2145 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2146
d62a17ae 2147 return CMD_SUCCESS;
6811845b 2148}
6b0655a2 2149
2fdd455c
PM
2150/* "bgp bestpath as-path multipath-relax" configuration. */
2151DEFUN (bgp_bestpath_aspath_multipath_relax,
2152 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2153 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2154 "BGP specific commands\n"
2155 "Change the default bestpath selection\n"
2156 "AS-path attribute\n"
2157 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2158 "Generate an AS_SET\n"
16fc1eec
DS
2159 "Do not generate an AS_SET\n")
2160{
d62a17ae 2161 VTY_DECLVAR_CONTEXT(bgp, bgp);
2162 int idx = 0;
2163 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2164
d62a17ae 2165 /* no-as-set is now the default behavior so we can silently
2166 * ignore it */
2167 if (argv_find(argv, argc, "as-set", &idx))
2168 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2169 else
2170 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2171
d62a17ae 2172 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2173
d62a17ae 2174 return CMD_SUCCESS;
16fc1eec
DS
2175}
2176
219178b6
DW
2177DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2178 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2179 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2180 NO_STR
2181 "BGP specific commands\n"
2182 "Change the default bestpath selection\n"
2183 "AS-path attribute\n"
2184 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2185 "Generate an AS_SET\n"
16fc1eec
DS
2186 "Do not generate an AS_SET\n")
2187{
d62a17ae 2188 VTY_DECLVAR_CONTEXT(bgp, bgp);
2189 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2190 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2191 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2192
d62a17ae 2193 return CMD_SUCCESS;
2fdd455c 2194}
6b0655a2 2195
848973c7 2196/* "bgp log-neighbor-changes" configuration. */
2197DEFUN (bgp_log_neighbor_changes,
2198 bgp_log_neighbor_changes_cmd,
2199 "bgp log-neighbor-changes",
2200 "BGP specific commands\n"
2201 "Log neighbor up/down and reset reason\n")
2202{
d62a17ae 2203 VTY_DECLVAR_CONTEXT(bgp, bgp);
2204 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2205 return CMD_SUCCESS;
848973c7 2206}
2207
2208DEFUN (no_bgp_log_neighbor_changes,
2209 no_bgp_log_neighbor_changes_cmd,
2210 "no bgp log-neighbor-changes",
2211 NO_STR
2212 "BGP specific commands\n"
2213 "Log neighbor up/down and reset reason\n")
2214{
d62a17ae 2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
2216 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2217 return CMD_SUCCESS;
848973c7 2218}
6b0655a2 2219
718e3744 2220/* "bgp bestpath med" configuration. */
2221DEFUN (bgp_bestpath_med,
2222 bgp_bestpath_med_cmd,
2d8c1a4d 2223 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2224 "BGP specific commands\n"
2225 "Change the default bestpath selection\n"
2226 "MED attribute\n"
2227 "Compare MED among confederation paths\n"
838758ac
DW
2228 "Treat missing MED as the least preferred one\n"
2229 "Treat missing MED as the least preferred one\n"
2230 "Compare MED among confederation paths\n")
718e3744 2231{
d62a17ae 2232 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2233
d62a17ae 2234 int idx = 0;
2235 if (argv_find(argv, argc, "confed", &idx))
2236 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2237 idx = 0;
2238 if (argv_find(argv, argc, "missing-as-worst", &idx))
2239 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2240
d62a17ae 2241 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2242
d62a17ae 2243 return CMD_SUCCESS;
718e3744 2244}
2245
718e3744 2246DEFUN (no_bgp_bestpath_med,
2247 no_bgp_bestpath_med_cmd,
2d8c1a4d 2248 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2249 NO_STR
2250 "BGP specific commands\n"
2251 "Change the default bestpath selection\n"
2252 "MED attribute\n"
2253 "Compare MED among confederation paths\n"
3a2d747c
QY
2254 "Treat missing MED as the least preferred one\n"
2255 "Treat missing MED as the least preferred one\n"
2256 "Compare MED among confederation paths\n")
718e3744 2257{
d62a17ae 2258 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2259
d62a17ae 2260 int idx = 0;
2261 if (argv_find(argv, argc, "confed", &idx))
2262 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2263 idx = 0;
2264 if (argv_find(argv, argc, "missing-as-worst", &idx))
2265 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2266
d62a17ae 2267 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2268
d62a17ae 2269 return CMD_SUCCESS;
718e3744 2270}
2271
718e3744 2272/* "no bgp default ipv4-unicast". */
2273DEFUN (no_bgp_default_ipv4_unicast,
2274 no_bgp_default_ipv4_unicast_cmd,
2275 "no bgp default ipv4-unicast",
2276 NO_STR
2277 "BGP specific commands\n"
2278 "Configure BGP defaults\n"
2279 "Activate ipv4-unicast for a peer by default\n")
2280{
d62a17ae 2281 VTY_DECLVAR_CONTEXT(bgp, bgp);
2282 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2283 return CMD_SUCCESS;
718e3744 2284}
2285
2286DEFUN (bgp_default_ipv4_unicast,
2287 bgp_default_ipv4_unicast_cmd,
2288 "bgp default ipv4-unicast",
2289 "BGP specific commands\n"
2290 "Configure BGP defaults\n"
2291 "Activate ipv4-unicast for a peer by default\n")
2292{
d62a17ae 2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2295 return CMD_SUCCESS;
718e3744 2296}
6b0655a2 2297
04b6bdc0
DW
2298/* Display hostname in certain command outputs */
2299DEFUN (bgp_default_show_hostname,
2300 bgp_default_show_hostname_cmd,
2301 "bgp default show-hostname",
2302 "BGP specific commands\n"
2303 "Configure BGP defaults\n"
2304 "Show hostname in certain command ouputs\n")
2305{
d62a17ae 2306 VTY_DECLVAR_CONTEXT(bgp, bgp);
2307 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2308 return CMD_SUCCESS;
04b6bdc0
DW
2309}
2310
2311DEFUN (no_bgp_default_show_hostname,
2312 no_bgp_default_show_hostname_cmd,
2313 "no bgp default show-hostname",
2314 NO_STR
2315 "BGP specific commands\n"
2316 "Configure BGP defaults\n"
2317 "Show hostname in certain command ouputs\n")
2318{
d62a17ae 2319 VTY_DECLVAR_CONTEXT(bgp, bgp);
2320 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2321 return CMD_SUCCESS;
04b6bdc0
DW
2322}
2323
8233ef81 2324/* "bgp network import-check" configuration. */
718e3744 2325DEFUN (bgp_network_import_check,
2326 bgp_network_import_check_cmd,
5623e905 2327 "bgp network import-check",
718e3744 2328 "BGP specific commands\n"
2329 "BGP network command\n"
5623e905 2330 "Check BGP network route exists in IGP\n")
718e3744 2331{
d62a17ae 2332 VTY_DECLVAR_CONTEXT(bgp, bgp);
2333 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2334 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2335 bgp_static_redo_import_check(bgp);
2336 }
078430f6 2337
d62a17ae 2338 return CMD_SUCCESS;
718e3744 2339}
2340
d62a17ae 2341ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2342 "bgp network import-check exact",
2343 "BGP specific commands\n"
2344 "BGP network command\n"
2345 "Check BGP network route exists in IGP\n"
2346 "Match route precisely\n")
8233ef81 2347
718e3744 2348DEFUN (no_bgp_network_import_check,
2349 no_bgp_network_import_check_cmd,
5623e905 2350 "no bgp network import-check",
718e3744 2351 NO_STR
2352 "BGP specific commands\n"
2353 "BGP network command\n"
2354 "Check BGP network route exists in IGP\n")
2355{
d62a17ae 2356 VTY_DECLVAR_CONTEXT(bgp, bgp);
2357 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2358 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2359 bgp_static_redo_import_check(bgp);
2360 }
5623e905 2361
d62a17ae 2362 return CMD_SUCCESS;
718e3744 2363}
6b0655a2 2364
718e3744 2365DEFUN (bgp_default_local_preference,
2366 bgp_default_local_preference_cmd,
6147e2c6 2367 "bgp default local-preference (0-4294967295)",
718e3744 2368 "BGP specific commands\n"
2369 "Configure BGP defaults\n"
2370 "local preference (higher=more preferred)\n"
2371 "Configure default local preference value\n")
2372{
d62a17ae 2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
2374 int idx_number = 3;
d7c0a89a 2375 uint32_t local_pref;
718e3744 2376
d62a17ae 2377 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2378
d62a17ae 2379 bgp_default_local_preference_set(bgp, local_pref);
2380 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2381
d62a17ae 2382 return CMD_SUCCESS;
718e3744 2383}
2384
2385DEFUN (no_bgp_default_local_preference,
2386 no_bgp_default_local_preference_cmd,
838758ac 2387 "no bgp default local-preference [(0-4294967295)]",
718e3744 2388 NO_STR
2389 "BGP specific commands\n"
2390 "Configure BGP defaults\n"
838758ac
DW
2391 "local preference (higher=more preferred)\n"
2392 "Configure default local preference value\n")
718e3744 2393{
d62a17ae 2394 VTY_DECLVAR_CONTEXT(bgp, bgp);
2395 bgp_default_local_preference_unset(bgp);
2396 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2397
d62a17ae 2398 return CMD_SUCCESS;
718e3744 2399}
2400
6b0655a2 2401
3f9c7369
DS
2402DEFUN (bgp_default_subgroup_pkt_queue_max,
2403 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2404 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2405 "BGP specific commands\n"
2406 "Configure BGP defaults\n"
2407 "subgroup-pkt-queue-max\n"
2408 "Configure subgroup packet queue max\n")
8bd9d948 2409{
d62a17ae 2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411 int idx_number = 3;
d7c0a89a 2412 uint32_t max_size;
8bd9d948 2413
d62a17ae 2414 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2415
d62a17ae 2416 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2417
d62a17ae 2418 return CMD_SUCCESS;
3f9c7369
DS
2419}
2420
2421DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2422 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2423 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2424 NO_STR
2425 "BGP specific commands\n"
2426 "Configure BGP defaults\n"
838758ac
DW
2427 "subgroup-pkt-queue-max\n"
2428 "Configure subgroup packet queue max\n")
3f9c7369 2429{
d62a17ae 2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2432 return CMD_SUCCESS;
8bd9d948
DS
2433}
2434
813d4307 2435
8bd9d948
DS
2436DEFUN (bgp_rr_allow_outbound_policy,
2437 bgp_rr_allow_outbound_policy_cmd,
2438 "bgp route-reflector allow-outbound-policy",
2439 "BGP specific commands\n"
2440 "Allow modifications made by out route-map\n"
2441 "on ibgp neighbors\n")
2442{
d62a17ae 2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2444
d62a17ae 2445 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2446 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2447 update_group_announce_rrclients(bgp);
2448 bgp_clear_star_soft_out(vty, bgp->name);
2449 }
8bd9d948 2450
d62a17ae 2451 return CMD_SUCCESS;
8bd9d948
DS
2452}
2453
2454DEFUN (no_bgp_rr_allow_outbound_policy,
2455 no_bgp_rr_allow_outbound_policy_cmd,
2456 "no bgp route-reflector allow-outbound-policy",
2457 NO_STR
2458 "BGP specific commands\n"
2459 "Allow modifications made by out route-map\n"
2460 "on ibgp neighbors\n")
2461{
d62a17ae 2462 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2463
d62a17ae 2464 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2465 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2466 update_group_announce_rrclients(bgp);
2467 bgp_clear_star_soft_out(vty, bgp->name);
2468 }
8bd9d948 2469
d62a17ae 2470 return CMD_SUCCESS;
8bd9d948
DS
2471}
2472
f14e6fdb
DS
2473DEFUN (bgp_listen_limit,
2474 bgp_listen_limit_cmd,
9ccf14f7 2475 "bgp listen limit (1-5000)",
f14e6fdb
DS
2476 "BGP specific commands\n"
2477 "Configure BGP defaults\n"
2478 "maximum number of BGP Dynamic Neighbors that can be created\n"
2479 "Configure Dynamic Neighbors listen limit value\n")
2480{
d62a17ae 2481 VTY_DECLVAR_CONTEXT(bgp, bgp);
2482 int idx_number = 3;
2483 int listen_limit;
f14e6fdb 2484
d62a17ae 2485 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2486
d62a17ae 2487 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2488
d62a17ae 2489 return CMD_SUCCESS;
f14e6fdb
DS
2490}
2491
2492DEFUN (no_bgp_listen_limit,
2493 no_bgp_listen_limit_cmd,
838758ac 2494 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2495 "BGP specific commands\n"
2496 "Configure BGP defaults\n"
2497 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2498 "Configure Dynamic Neighbors listen limit value to default\n"
2499 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2500{
d62a17ae 2501 VTY_DECLVAR_CONTEXT(bgp, bgp);
2502 bgp_listen_limit_unset(bgp);
2503 return CMD_SUCCESS;
f14e6fdb
DS
2504}
2505
2506
20eb8864 2507/*
2508 * Check if this listen range is already configured. Check for exact
2509 * match or overlap based on input.
2510 */
d62a17ae 2511static struct peer_group *listen_range_exists(struct bgp *bgp,
2512 struct prefix *range, int exact)
2513{
2514 struct listnode *node, *nnode;
2515 struct listnode *node1, *nnode1;
2516 struct peer_group *group;
2517 struct prefix *lr;
2518 afi_t afi;
2519 int match;
2520
2521 afi = family2afi(range->family);
2522 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2523 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2524 lr)) {
2525 if (exact)
2526 match = prefix_same(range, lr);
2527 else
2528 match = (prefix_match(range, lr)
2529 || prefix_match(lr, range));
2530 if (match)
2531 return group;
2532 }
2533 }
2534
2535 return NULL;
20eb8864 2536}
2537
f14e6fdb
DS
2538DEFUN (bgp_listen_range,
2539 bgp_listen_range_cmd,
9ccf14f7 2540 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2541 "BGP specific commands\n"
d7fa34c1
QY
2542 "Configure BGP dynamic neighbors listen range\n"
2543 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2544 NEIGHBOR_ADDR_STR
2545 "Member of the peer-group\n"
2546 "Peer-group name\n")
f14e6fdb 2547{
d62a17ae 2548 VTY_DECLVAR_CONTEXT(bgp, bgp);
2549 struct prefix range;
2550 struct peer_group *group, *existing_group;
2551 afi_t afi;
2552 int ret;
2553 int idx = 0;
2554
2555 argv_find(argv, argc, "A.B.C.D/M", &idx);
2556 argv_find(argv, argc, "X:X::X:X/M", &idx);
2557 char *prefix = argv[idx]->arg;
2558 argv_find(argv, argc, "WORD", &idx);
2559 char *peergroup = argv[idx]->arg;
2560
2561 /* Convert IP prefix string to struct prefix. */
2562 ret = str2prefix(prefix, &range);
2563 if (!ret) {
2564 vty_out(vty, "%% Malformed listen range\n");
2565 return CMD_WARNING_CONFIG_FAILED;
2566 }
2567
2568 afi = family2afi(range.family);
2569
2570 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2571 vty_out(vty,
2572 "%% Malformed listen range (link-local address)\n");
2573 return CMD_WARNING_CONFIG_FAILED;
2574 }
2575
2576 apply_mask(&range);
2577
2578 /* Check if same listen range is already configured. */
2579 existing_group = listen_range_exists(bgp, &range, 1);
2580 if (existing_group) {
2581 if (strcmp(existing_group->name, peergroup) == 0)
2582 return CMD_SUCCESS;
2583 else {
2584 vty_out(vty,
2585 "%% Same listen range is attached to peer-group %s\n",
2586 existing_group->name);
2587 return CMD_WARNING_CONFIG_FAILED;
2588 }
2589 }
2590
2591 /* Check if an overlapping listen range exists. */
2592 if (listen_range_exists(bgp, &range, 0)) {
2593 vty_out(vty,
2594 "%% Listen range overlaps with existing listen range\n");
2595 return CMD_WARNING_CONFIG_FAILED;
2596 }
2597
2598 group = peer_group_lookup(bgp, peergroup);
2599 if (!group) {
2600 vty_out(vty, "%% Configure the peer-group first\n");
2601 return CMD_WARNING_CONFIG_FAILED;
2602 }
2603
2604 ret = peer_group_listen_range_add(group, &range);
2605 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2606}
2607
2608DEFUN (no_bgp_listen_range,
2609 no_bgp_listen_range_cmd,
d7fa34c1
QY
2610 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2611 NO_STR
f14e6fdb 2612 "BGP specific commands\n"
d7fa34c1
QY
2613 "Unconfigure BGP dynamic neighbors listen range\n"
2614 "Unconfigure BGP dynamic neighbors listen range\n"
2615 NEIGHBOR_ADDR_STR
2616 "Member of the peer-group\n"
2617 "Peer-group name\n")
f14e6fdb 2618{
d62a17ae 2619 VTY_DECLVAR_CONTEXT(bgp, bgp);
2620 struct prefix range;
2621 struct peer_group *group;
2622 afi_t afi;
2623 int ret;
2624 int idx = 0;
2625
2626 argv_find(argv, argc, "A.B.C.D/M", &idx);
2627 argv_find(argv, argc, "X:X::X:X/M", &idx);
2628 char *prefix = argv[idx]->arg;
2629 argv_find(argv, argc, "WORD", &idx);
2630 char *peergroup = argv[idx]->arg;
2631
2632 /* Convert IP prefix string to struct prefix. */
2633 ret = str2prefix(prefix, &range);
2634 if (!ret) {
2635 vty_out(vty, "%% Malformed listen range\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
2638
2639 afi = family2afi(range.family);
2640
2641 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2642 vty_out(vty,
2643 "%% Malformed listen range (link-local address)\n");
2644 return CMD_WARNING_CONFIG_FAILED;
2645 }
2646
2647 apply_mask(&range);
2648
2649 group = peer_group_lookup(bgp, peergroup);
2650 if (!group) {
2651 vty_out(vty, "%% Peer-group does not exist\n");
2652 return CMD_WARNING_CONFIG_FAILED;
2653 }
2654
2655 ret = peer_group_listen_range_del(group, &range);
2656 return bgp_vty_return(vty, ret);
2657}
2658
2b791107 2659void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2660{
2661 struct peer_group *group;
2662 struct listnode *node, *nnode, *rnode, *nrnode;
2663 struct prefix *range;
2664 afi_t afi;
2665 char buf[PREFIX2STR_BUFFER];
2666
2667 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2668 vty_out(vty, " bgp listen limit %d\n",
2669 bgp->dynamic_neighbors_limit);
2670
2671 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2672 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2673 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2674 nrnode, range)) {
2675 prefix2str(range, buf, sizeof(buf));
2676 vty_out(vty,
2677 " bgp listen range %s peer-group %s\n",
2678 buf, group->name);
2679 }
2680 }
2681 }
f14e6fdb
DS
2682}
2683
2684
907f92c8
DS
2685DEFUN (bgp_disable_connected_route_check,
2686 bgp_disable_connected_route_check_cmd,
2687 "bgp disable-ebgp-connected-route-check",
2688 "BGP specific commands\n"
2689 "Disable checking if nexthop is connected on ebgp sessions\n")
2690{
d62a17ae 2691 VTY_DECLVAR_CONTEXT(bgp, bgp);
2692 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2693 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2694
d62a17ae 2695 return CMD_SUCCESS;
907f92c8
DS
2696}
2697
2698DEFUN (no_bgp_disable_connected_route_check,
2699 no_bgp_disable_connected_route_check_cmd,
2700 "no bgp disable-ebgp-connected-route-check",
2701 NO_STR
2702 "BGP specific commands\n"
2703 "Disable checking if nexthop is connected on ebgp sessions\n")
2704{
d62a17ae 2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2707 bgp_clear_star_soft_in(vty, bgp->name);
2708
2709 return CMD_SUCCESS;
2710}
2711
2712
2713static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2714 const char *as_str, afi_t afi, safi_t safi)
2715{
2716 VTY_DECLVAR_CONTEXT(bgp, bgp);
2717 int ret;
2718 as_t as;
2719 int as_type = AS_SPECIFIED;
2720 union sockunion su;
2721
2722 if (as_str[0] == 'i') {
2723 as = 0;
2724 as_type = AS_INTERNAL;
2725 } else if (as_str[0] == 'e') {
2726 as = 0;
2727 as_type = AS_EXTERNAL;
2728 } else {
2729 /* Get AS number. */
2730 as = strtoul(as_str, NULL, 10);
2731 }
2732
2733 /* If peer is peer group, call proper function. */
2734 ret = str2sockunion(peer_str, &su);
2735 if (ret < 0) {
2736 /* Check for peer by interface */
2737 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2738 safi);
2739 if (ret < 0) {
2740 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2741 if (ret < 0) {
2742 vty_out(vty,
2743 "%% Create the peer-group or interface first\n");
2744 return CMD_WARNING_CONFIG_FAILED;
2745 }
2746 return CMD_SUCCESS;
2747 }
2748 } else {
2749 if (peer_address_self_check(bgp, &su)) {
2750 vty_out(vty,
2751 "%% Can not configure the local system as neighbor\n");
2752 return CMD_WARNING_CONFIG_FAILED;
2753 }
2754 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2755 }
2756
2757 /* This peer belongs to peer group. */
2758 switch (ret) {
2759 case BGP_ERR_PEER_GROUP_MEMBER:
2760 vty_out(vty,
2761 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2762 as);
2763 return CMD_WARNING_CONFIG_FAILED;
2764 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2765 vty_out(vty,
2766 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2767 as, as_str);
2768 return CMD_WARNING_CONFIG_FAILED;
2769 }
2770 return bgp_vty_return(vty, ret);
718e3744 2771}
2772
f26845f9
QY
2773DEFUN (bgp_default_shutdown,
2774 bgp_default_shutdown_cmd,
2775 "[no] bgp default shutdown",
2776 NO_STR
2777 BGP_STR
2778 "Configure BGP defaults\n"
b012cbe2 2779 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2780{
2781 VTY_DECLVAR_CONTEXT(bgp, bgp);
2782 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2783 return CMD_SUCCESS;
2784}
2785
718e3744 2786DEFUN (neighbor_remote_as,
2787 neighbor_remote_as_cmd,
3a2d747c 2788 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2789 NEIGHBOR_STR
2790 NEIGHBOR_ADDR_STR2
2791 "Specify a BGP neighbor\n"
d7fa34c1 2792 AS_STR
3a2d747c
QY
2793 "Internal BGP peer\n"
2794 "External BGP peer\n")
718e3744 2795{
d62a17ae 2796 int idx_peer = 1;
2797 int idx_remote_as = 3;
2798 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2799 argv[idx_remote_as]->arg, AFI_IP,
2800 SAFI_UNICAST);
2801}
2802
2803static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2804 afi_t afi, safi_t safi, int v6only,
2805 const char *peer_group_name,
2806 const char *as_str)
2807{
2808 VTY_DECLVAR_CONTEXT(bgp, bgp);
2809 as_t as = 0;
2810 int as_type = AS_UNSPECIFIED;
2811 struct peer *peer;
2812 struct peer_group *group;
2813 int ret = 0;
2814 union sockunion su;
2815
2816 group = peer_group_lookup(bgp, conf_if);
2817
2818 if (group) {
2819 vty_out(vty, "%% Name conflict with peer-group \n");
2820 return CMD_WARNING_CONFIG_FAILED;
2821 }
2822
2823 if (as_str) {
2824 if (as_str[0] == 'i') {
2825 as_type = AS_INTERNAL;
2826 } else if (as_str[0] == 'e') {
2827 as_type = AS_EXTERNAL;
2828 } else {
2829 /* Get AS number. */
2830 as = strtoul(as_str, NULL, 10);
2831 as_type = AS_SPECIFIED;
2832 }
2833 }
2834
2835 peer = peer_lookup_by_conf_if(bgp, conf_if);
2836 if (peer) {
2837 if (as_str)
cc4d4ce8 2838 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 2839 afi, safi);
2840 } else {
2841 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2842 && afi == AFI_IP && safi == SAFI_UNICAST)
2843 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2844 as_type, 0, 0, NULL);
2845 else
2846 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2847 as_type, afi, safi, NULL);
2848
2849 if (!peer) {
2850 vty_out(vty, "%% BGP failed to create peer\n");
2851 return CMD_WARNING_CONFIG_FAILED;
2852 }
2853
2854 if (v6only)
527de3dc 2855 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2856
2857 /* Request zebra to initiate IPv6 RAs on this interface. We do
2858 * this
2859 * any unnumbered peer in order to not worry about run-time
2860 * transitions
2861 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2862 * address
2863 * gets deleted later etc.)
2864 */
2865 if (peer->ifp)
2866 bgp_zebra_initiate_radv(bgp, peer);
2867 }
2868
2869 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2870 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2871 if (v6only)
527de3dc 2872 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2873 else
527de3dc 2874 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2875
2876 /* v6only flag changed. Reset bgp seesion */
2877 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2878 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2879 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2880 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2881 } else
2882 bgp_session_reset(peer);
2883 }
2884
9fb964de
PM
2885 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2886 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2887 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2888 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2889 }
d62a17ae 2890
2891 if (peer_group_name) {
2892 group = peer_group_lookup(bgp, peer_group_name);
2893 if (!group) {
2894 vty_out(vty, "%% Configure the peer-group first\n");
2895 return CMD_WARNING_CONFIG_FAILED;
2896 }
2897
2898 ret = peer_group_bind(bgp, &su, peer, group, &as);
2899 }
2900
2901 return bgp_vty_return(vty, ret);
a80beece
DS
2902}
2903
4c48cf63
DW
2904DEFUN (neighbor_interface_config,
2905 neighbor_interface_config_cmd,
31500417 2906 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2907 NEIGHBOR_STR
2908 "Interface name or neighbor tag\n"
31500417
DW
2909 "Enable BGP on interface\n"
2910 "Member of the peer-group\n"
16cedbb0 2911 "Peer-group name\n")
4c48cf63 2912{
d62a17ae 2913 int idx_word = 1;
2914 int idx_peer_group_word = 4;
31500417 2915
d62a17ae 2916 if (argc > idx_peer_group_word)
2917 return peer_conf_interface_get(
2918 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2919 argv[idx_peer_group_word]->arg, NULL);
2920 else
2921 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2922 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2923}
2924
4c48cf63
DW
2925DEFUN (neighbor_interface_config_v6only,
2926 neighbor_interface_config_v6only_cmd,
31500417 2927 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2928 NEIGHBOR_STR
2929 "Interface name or neighbor tag\n"
2930 "Enable BGP on interface\n"
31500417
DW
2931 "Enable BGP with v6 link-local only\n"
2932 "Member of the peer-group\n"
16cedbb0 2933 "Peer-group name\n")
4c48cf63 2934{
d62a17ae 2935 int idx_word = 1;
2936 int idx_peer_group_word = 5;
31500417 2937
d62a17ae 2938 if (argc > idx_peer_group_word)
2939 return peer_conf_interface_get(
2940 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2941 argv[idx_peer_group_word]->arg, NULL);
31500417 2942
d62a17ae 2943 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2944 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2945}
2946
a80beece 2947
b3a39dc5
DD
2948DEFUN (neighbor_interface_config_remote_as,
2949 neighbor_interface_config_remote_as_cmd,
3a2d747c 2950 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2951 NEIGHBOR_STR
2952 "Interface name or neighbor tag\n"
2953 "Enable BGP on interface\n"
3a2d747c 2954 "Specify a BGP neighbor\n"
d7fa34c1 2955 AS_STR
3a2d747c
QY
2956 "Internal BGP peer\n"
2957 "External BGP peer\n")
b3a39dc5 2958{
d62a17ae 2959 int idx_word = 1;
2960 int idx_remote_as = 4;
2961 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2962 SAFI_UNICAST, 0, NULL,
2963 argv[idx_remote_as]->arg);
b3a39dc5
DD
2964}
2965
2966DEFUN (neighbor_interface_v6only_config_remote_as,
2967 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2968 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2969 NEIGHBOR_STR
2970 "Interface name or neighbor tag\n"
3a2d747c 2971 "Enable BGP with v6 link-local only\n"
b3a39dc5 2972 "Enable BGP on interface\n"
3a2d747c 2973 "Specify a BGP neighbor\n"
d7fa34c1 2974 AS_STR
3a2d747c
QY
2975 "Internal BGP peer\n"
2976 "External BGP peer\n")
b3a39dc5 2977{
d62a17ae 2978 int idx_word = 1;
2979 int idx_remote_as = 5;
2980 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2981 SAFI_UNICAST, 1, NULL,
2982 argv[idx_remote_as]->arg);
b3a39dc5
DD
2983}
2984
718e3744 2985DEFUN (neighbor_peer_group,
2986 neighbor_peer_group_cmd,
2987 "neighbor WORD peer-group",
2988 NEIGHBOR_STR
a80beece 2989 "Interface name or neighbor tag\n"
718e3744 2990 "Configure peer-group\n")
2991{
d62a17ae 2992 VTY_DECLVAR_CONTEXT(bgp, bgp);
2993 int idx_word = 1;
2994 struct peer *peer;
2995 struct peer_group *group;
718e3744 2996
d62a17ae 2997 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2998 if (peer) {
2999 vty_out(vty, "%% Name conflict with interface: \n");
3000 return CMD_WARNING_CONFIG_FAILED;
3001 }
718e3744 3002
d62a17ae 3003 group = peer_group_get(bgp, argv[idx_word]->arg);
3004 if (!group) {
3005 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3006 return CMD_WARNING_CONFIG_FAILED;
3007 }
718e3744 3008
d62a17ae 3009 return CMD_SUCCESS;
718e3744 3010}
3011
3012DEFUN (no_neighbor,
3013 no_neighbor_cmd,
dab8cd00 3014 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3015 NO_STR
3016 NEIGHBOR_STR
3a2d747c
QY
3017 NEIGHBOR_ADDR_STR2
3018 "Specify a BGP neighbor\n"
3019 AS_STR
3020 "Internal BGP peer\n"
3021 "External BGP peer\n")
718e3744 3022{
d62a17ae 3023 VTY_DECLVAR_CONTEXT(bgp, bgp);
3024 int idx_peer = 2;
3025 int ret;
3026 union sockunion su;
3027 struct peer_group *group;
3028 struct peer *peer;
3029 struct peer *other;
3030
3031 ret = str2sockunion(argv[idx_peer]->arg, &su);
3032 if (ret < 0) {
3033 /* look up for neighbor by interface name config. */
3034 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3035 if (peer) {
3036 /* Request zebra to terminate IPv6 RAs on this
3037 * interface. */
3038 if (peer->ifp)
3039 bgp_zebra_terminate_radv(peer->bgp, peer);
3040 peer_delete(peer);
3041 return CMD_SUCCESS;
3042 }
f14e6fdb 3043
d62a17ae 3044 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3045 if (group)
3046 peer_group_delete(group);
3047 else {
3048 vty_out(vty, "%% Create the peer-group first\n");
3049 return CMD_WARNING_CONFIG_FAILED;
3050 }
3051 } else {
3052 peer = peer_lookup(bgp, &su);
3053 if (peer) {
3054 if (peer_dynamic_neighbor(peer)) {
3055 vty_out(vty,
3056 "%% Operation not allowed on a dynamic neighbor\n");
3057 return CMD_WARNING_CONFIG_FAILED;
3058 }
3059
3060 other = peer->doppelganger;
3061 peer_delete(peer);
3062 if (other && other->status != Deleted)
3063 peer_delete(other);
3064 }
1ff9a340 3065 }
718e3744 3066
d62a17ae 3067 return CMD_SUCCESS;
718e3744 3068}
3069
a80beece
DS
3070DEFUN (no_neighbor_interface_config,
3071 no_neighbor_interface_config_cmd,
31500417 3072 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3073 NO_STR
3074 NEIGHBOR_STR
3075 "Interface name\n"
31500417
DW
3076 "Configure BGP on interface\n"
3077 "Enable BGP with v6 link-local only\n"
3078 "Member of the peer-group\n"
16cedbb0 3079 "Peer-group name\n"
3a2d747c
QY
3080 "Specify a BGP neighbor\n"
3081 AS_STR
3082 "Internal BGP peer\n"
3083 "External BGP peer\n")
a80beece 3084{
d62a17ae 3085 VTY_DECLVAR_CONTEXT(bgp, bgp);
3086 int idx_word = 2;
3087 struct peer *peer;
3088
3089 /* look up for neighbor by interface name config. */
3090 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3091 if (peer) {
3092 /* Request zebra to terminate IPv6 RAs on this interface. */
3093 if (peer->ifp)
3094 bgp_zebra_terminate_radv(peer->bgp, peer);
3095 peer_delete(peer);
3096 } else {
3097 vty_out(vty, "%% Create the bgp interface first\n");
3098 return CMD_WARNING_CONFIG_FAILED;
3099 }
3100 return CMD_SUCCESS;
a80beece
DS
3101}
3102
718e3744 3103DEFUN (no_neighbor_peer_group,
3104 no_neighbor_peer_group_cmd,
3105 "no neighbor WORD peer-group",
3106 NO_STR
3107 NEIGHBOR_STR
3108 "Neighbor tag\n"
3109 "Configure peer-group\n")
3110{
d62a17ae 3111 VTY_DECLVAR_CONTEXT(bgp, bgp);
3112 int idx_word = 2;
3113 struct peer_group *group;
718e3744 3114
d62a17ae 3115 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3116 if (group)
3117 peer_group_delete(group);
3118 else {
3119 vty_out(vty, "%% Create the peer-group first\n");
3120 return CMD_WARNING_CONFIG_FAILED;
3121 }
3122 return CMD_SUCCESS;
718e3744 3123}
3124
a80beece
DS
3125DEFUN (no_neighbor_interface_peer_group_remote_as,
3126 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3127 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3128 NO_STR
3129 NEIGHBOR_STR
a80beece 3130 "Interface name or neighbor tag\n"
718e3744 3131 "Specify a BGP neighbor\n"
3a2d747c
QY
3132 AS_STR
3133 "Internal BGP peer\n"
3134 "External BGP peer\n")
718e3744 3135{
d62a17ae 3136 VTY_DECLVAR_CONTEXT(bgp, bgp);
3137 int idx_word = 2;
3138 struct peer_group *group;
3139 struct peer *peer;
3140
3141 /* look up for neighbor by interface name config. */
3142 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3143 if (peer) {
3144 peer_as_change(peer, 0, AS_SPECIFIED);
3145 return CMD_SUCCESS;
3146 }
3147
3148 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3149 if (group)
3150 peer_group_remote_as_delete(group);
3151 else {
3152 vty_out(vty, "%% Create the peer-group or interface first\n");
3153 return CMD_WARNING_CONFIG_FAILED;
3154 }
3155 return CMD_SUCCESS;
718e3744 3156}
6b0655a2 3157
718e3744 3158DEFUN (neighbor_local_as,
3159 neighbor_local_as_cmd,
9ccf14f7 3160 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3161 NEIGHBOR_STR
3162 NEIGHBOR_ADDR_STR2
3163 "Specify a local-as number\n"
3164 "AS number used as local AS\n")
3165{
d62a17ae 3166 int idx_peer = 1;
3167 int idx_number = 3;
3168 struct peer *peer;
3169 int ret;
3170 as_t as;
718e3744 3171
d62a17ae 3172 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3173 if (!peer)
3174 return CMD_WARNING_CONFIG_FAILED;
718e3744 3175
d62a17ae 3176 as = strtoul(argv[idx_number]->arg, NULL, 10);
3177 ret = peer_local_as_set(peer, as, 0, 0);
3178 return bgp_vty_return(vty, ret);
718e3744 3179}
3180
3181DEFUN (neighbor_local_as_no_prepend,
3182 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3183 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3184 NEIGHBOR_STR
3185 NEIGHBOR_ADDR_STR2
3186 "Specify a local-as number\n"
3187 "AS number used as local AS\n"
3188 "Do not prepend local-as to updates from ebgp peers\n")
3189{
d62a17ae 3190 int idx_peer = 1;
3191 int idx_number = 3;
3192 struct peer *peer;
3193 int ret;
3194 as_t as;
718e3744 3195
d62a17ae 3196 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3197 if (!peer)
3198 return CMD_WARNING_CONFIG_FAILED;
718e3744 3199
d62a17ae 3200 as = strtoul(argv[idx_number]->arg, NULL, 10);
3201 ret = peer_local_as_set(peer, as, 1, 0);
3202 return bgp_vty_return(vty, ret);
718e3744 3203}
3204
9d3f9705
AC
3205DEFUN (neighbor_local_as_no_prepend_replace_as,
3206 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3207 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3208 NEIGHBOR_STR
3209 NEIGHBOR_ADDR_STR2
3210 "Specify a local-as number\n"
3211 "AS number used as local AS\n"
3212 "Do not prepend local-as to updates from ebgp peers\n"
3213 "Do not prepend local-as to updates from ibgp peers\n")
3214{
d62a17ae 3215 int idx_peer = 1;
3216 int idx_number = 3;
3217 struct peer *peer;
3218 int ret;
3219 as_t as;
9d3f9705 3220
d62a17ae 3221 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3222 if (!peer)
3223 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3224
d62a17ae 3225 as = strtoul(argv[idx_number]->arg, NULL, 10);
3226 ret = peer_local_as_set(peer, as, 1, 1);
3227 return bgp_vty_return(vty, ret);
9d3f9705
AC
3228}
3229
718e3744 3230DEFUN (no_neighbor_local_as,
3231 no_neighbor_local_as_cmd,
a636c635 3232 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3233 NO_STR
3234 NEIGHBOR_STR
3235 NEIGHBOR_ADDR_STR2
a636c635
DW
3236 "Specify a local-as number\n"
3237 "AS number used as local AS\n"
3238 "Do not prepend local-as to updates from ebgp peers\n"
3239 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3240{
d62a17ae 3241 int idx_peer = 2;
3242 struct peer *peer;
3243 int ret;
718e3744 3244
d62a17ae 3245 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3246 if (!peer)
3247 return CMD_WARNING_CONFIG_FAILED;
718e3744 3248
d62a17ae 3249 ret = peer_local_as_unset(peer);
3250 return bgp_vty_return(vty, ret);
718e3744 3251}
3252
718e3744 3253
3f9c7369
DS
3254DEFUN (neighbor_solo,
3255 neighbor_solo_cmd,
9ccf14f7 3256 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3257 NEIGHBOR_STR
3258 NEIGHBOR_ADDR_STR2
3259 "Solo peer - part of its own update group\n")
3260{
d62a17ae 3261 int idx_peer = 1;
3262 struct peer *peer;
3263 int ret;
3f9c7369 3264
d62a17ae 3265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3266 if (!peer)
3267 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3268
d62a17ae 3269 ret = update_group_adjust_soloness(peer, 1);
3270 return bgp_vty_return(vty, ret);
3f9c7369
DS
3271}
3272
3273DEFUN (no_neighbor_solo,
3274 no_neighbor_solo_cmd,
9ccf14f7 3275 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3276 NO_STR
3277 NEIGHBOR_STR
3278 NEIGHBOR_ADDR_STR2
3279 "Solo peer - part of its own update group\n")
3280{
d62a17ae 3281 int idx_peer = 2;
3282 struct peer *peer;
3283 int ret;
3f9c7369 3284
d62a17ae 3285 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3286 if (!peer)
3287 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3288
d62a17ae 3289 ret = update_group_adjust_soloness(peer, 0);
3290 return bgp_vty_return(vty, ret);
3f9c7369
DS
3291}
3292
0df7c91f
PJ
3293DEFUN (neighbor_password,
3294 neighbor_password_cmd,
9ccf14f7 3295 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3296 NEIGHBOR_STR
3297 NEIGHBOR_ADDR_STR2
3298 "Set a password\n"
3299 "The password\n")
3300{
d62a17ae 3301 int idx_peer = 1;
3302 int idx_line = 3;
3303 struct peer *peer;
3304 int ret;
0df7c91f 3305
d62a17ae 3306 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3307 if (!peer)
3308 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3309
d62a17ae 3310 ret = peer_password_set(peer, argv[idx_line]->arg);
3311 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3312}
3313
3314DEFUN (no_neighbor_password,
3315 no_neighbor_password_cmd,
a636c635 3316 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3317 NO_STR
3318 NEIGHBOR_STR
3319 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3320 "Set a password\n"
3321 "The password\n")
0df7c91f 3322{
d62a17ae 3323 int idx_peer = 2;
3324 struct peer *peer;
3325 int ret;
0df7c91f 3326
d62a17ae 3327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3328 if (!peer)
3329 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3330
d62a17ae 3331 ret = peer_password_unset(peer);
3332 return bgp_vty_return(vty, ret);
0df7c91f 3333}
6b0655a2 3334
718e3744 3335DEFUN (neighbor_activate,
3336 neighbor_activate_cmd,
9ccf14f7 3337 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3338 NEIGHBOR_STR
3339 NEIGHBOR_ADDR_STR2
3340 "Enable the Address Family for this Neighbor\n")
3341{
d62a17ae 3342 int idx_peer = 1;
3343 int ret;
3344 struct peer *peer;
718e3744 3345
d62a17ae 3346 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3347 if (!peer)
3348 return CMD_WARNING_CONFIG_FAILED;
718e3744 3349
d62a17ae 3350 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3351 return bgp_vty_return(vty, ret);
718e3744 3352}
3353
d62a17ae 3354ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3355 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3356 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3357 "Enable the Address Family for this Neighbor\n")
596c17ba 3358
718e3744 3359DEFUN (no_neighbor_activate,
3360 no_neighbor_activate_cmd,
9ccf14f7 3361 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3362 NO_STR
3363 NEIGHBOR_STR
3364 NEIGHBOR_ADDR_STR2
3365 "Enable the Address Family for this Neighbor\n")
3366{
d62a17ae 3367 int idx_peer = 2;
3368 int ret;
3369 struct peer *peer;
718e3744 3370
d62a17ae 3371 /* Lookup peer. */
3372 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3373 if (!peer)
3374 return CMD_WARNING_CONFIG_FAILED;
718e3744 3375
d62a17ae 3376 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3377 return bgp_vty_return(vty, ret);
718e3744 3378}
6b0655a2 3379
d62a17ae 3380ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3381 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3382 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3383 "Enable the Address Family for this Neighbor\n")
596c17ba 3384
718e3744 3385DEFUN (neighbor_set_peer_group,
3386 neighbor_set_peer_group_cmd,
9ccf14f7 3387 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3388 NEIGHBOR_STR
a80beece 3389 NEIGHBOR_ADDR_STR2
718e3744 3390 "Member of the peer-group\n"
16cedbb0 3391 "Peer-group name\n")
718e3744 3392{
d62a17ae 3393 VTY_DECLVAR_CONTEXT(bgp, bgp);
3394 int idx_peer = 1;
3395 int idx_word = 3;
3396 int ret;
3397 as_t as;
3398 union sockunion su;
3399 struct peer *peer;
3400 struct peer_group *group;
3401
d62a17ae 3402 ret = str2sockunion(argv[idx_peer]->arg, &su);
3403 if (ret < 0) {
3404 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3405 if (!peer) {
3406 vty_out(vty, "%% Malformed address or name: %s\n",
3407 argv[idx_peer]->arg);
3408 return CMD_WARNING_CONFIG_FAILED;
3409 }
3410 } else {
3411 if (peer_address_self_check(bgp, &su)) {
3412 vty_out(vty,
3413 "%% Can not configure the local system as neighbor\n");
3414 return CMD_WARNING_CONFIG_FAILED;
3415 }
3416
3417 /* Disallow for dynamic neighbor. */
3418 peer = peer_lookup(bgp, &su);
3419 if (peer && peer_dynamic_neighbor(peer)) {
3420 vty_out(vty,
3421 "%% Operation not allowed on a dynamic neighbor\n");
3422 return CMD_WARNING_CONFIG_FAILED;
3423 }
3424 }
3425
3426 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3427 if (!group) {
3428 vty_out(vty, "%% Configure the peer-group first\n");
3429 return CMD_WARNING_CONFIG_FAILED;
3430 }
3431
3432 ret = peer_group_bind(bgp, &su, peer, group, &as);
3433
3434 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3435 vty_out(vty,
3436 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3437 as);
3438 return CMD_WARNING_CONFIG_FAILED;
3439 }
3440
3441 return bgp_vty_return(vty, ret);
3442}
3443
3444ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3445 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3446 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3447 "Member of the peer-group\n"
3448 "Peer-group name\n")
596c17ba 3449
718e3744 3450DEFUN (no_neighbor_set_peer_group,
3451 no_neighbor_set_peer_group_cmd,
9ccf14f7 3452 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3453 NO_STR
3454 NEIGHBOR_STR
a80beece 3455 NEIGHBOR_ADDR_STR2
718e3744 3456 "Member of the peer-group\n"
16cedbb0 3457 "Peer-group name\n")
718e3744 3458{
d62a17ae 3459 VTY_DECLVAR_CONTEXT(bgp, bgp);
3460 int idx_peer = 2;
3461 int idx_word = 4;
3462 int ret;
3463 struct peer *peer;
3464 struct peer_group *group;
3465
3466 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3467 if (!peer)
3468 return CMD_WARNING_CONFIG_FAILED;
3469
3470 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3471 if (!group) {
3472 vty_out(vty, "%% Configure the peer-group first\n");
3473 return CMD_WARNING_CONFIG_FAILED;
3474 }
718e3744 3475
827ed707 3476 ret = peer_delete(peer);
718e3744 3477
d62a17ae 3478 return bgp_vty_return(vty, ret);
718e3744 3479}
6b0655a2 3480
d62a17ae 3481ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3482 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3483 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3484 "Member of the peer-group\n"
3485 "Peer-group name\n")
596c17ba 3486
d62a17ae 3487static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3488 uint32_t flag, int set)
718e3744 3489{
d62a17ae 3490 int ret;
3491 struct peer *peer;
718e3744 3492
d62a17ae 3493 peer = peer_and_group_lookup_vty(vty, ip_str);
3494 if (!peer)
3495 return CMD_WARNING_CONFIG_FAILED;
718e3744 3496
7ebe625c
QY
3497 /*
3498 * If 'neighbor <interface>', then this is for directly connected peers,
3499 * we should not accept disable-connected-check.
3500 */
3501 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3502 vty_out(vty,
3503 "%s is directly connected peer, cannot accept disable-"
3504 "connected-check\n",
3505 ip_str);
3506 return CMD_WARNING_CONFIG_FAILED;
3507 }
3508
d62a17ae 3509 if (!set && flag == PEER_FLAG_SHUTDOWN)
3510 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3511
d62a17ae 3512 if (set)
3513 ret = peer_flag_set(peer, flag);
3514 else
3515 ret = peer_flag_unset(peer, flag);
718e3744 3516
d62a17ae 3517 return bgp_vty_return(vty, ret);
718e3744 3518}
3519
47cbc09b 3520static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3521{
d62a17ae 3522 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3523}
3524
d62a17ae 3525static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3526 uint32_t flag)
718e3744 3527{
d62a17ae 3528 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3529}
3530
3531/* neighbor passive. */
3532DEFUN (neighbor_passive,
3533 neighbor_passive_cmd,
9ccf14f7 3534 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3535 NEIGHBOR_STR
3536 NEIGHBOR_ADDR_STR2
3537 "Don't send open messages to this neighbor\n")
3538{
d62a17ae 3539 int idx_peer = 1;
3540 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3541}
3542
3543DEFUN (no_neighbor_passive,
3544 no_neighbor_passive_cmd,
9ccf14f7 3545 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3546 NO_STR
3547 NEIGHBOR_STR
3548 NEIGHBOR_ADDR_STR2
3549 "Don't send open messages to this neighbor\n")
3550{
d62a17ae 3551 int idx_peer = 2;
3552 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3553}
6b0655a2 3554
718e3744 3555/* neighbor shutdown. */
73d70fa6
DL
3556DEFUN (neighbor_shutdown_msg,
3557 neighbor_shutdown_msg_cmd,
3558 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3559 NEIGHBOR_STR
3560 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3561 "Administratively shut down this neighbor\n"
3562 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3563 "Shutdown message\n")
718e3744 3564{
d62a17ae 3565 int idx_peer = 1;
73d70fa6 3566
d62a17ae 3567 if (argc >= 5) {
3568 struct peer *peer =
3569 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3570 char *message;
73d70fa6 3571
d62a17ae 3572 if (!peer)
3573 return CMD_WARNING_CONFIG_FAILED;
3574 message = argv_concat(argv, argc, 4);
3575 peer_tx_shutdown_message_set(peer, message);
3576 XFREE(MTYPE_TMP, message);
3577 }
73d70fa6 3578
d62a17ae 3579 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3580}
3581
d62a17ae 3582ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3583 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3584 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3585 "Administratively shut down this neighbor\n")
73d70fa6
DL
3586
3587DEFUN (no_neighbor_shutdown_msg,
3588 no_neighbor_shutdown_msg_cmd,
3589 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3590 NO_STR
3591 NEIGHBOR_STR
3592 NEIGHBOR_ADDR_STR2
3593 "Administratively shut down this neighbor\n"
3594 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3595 "Shutdown message\n")
718e3744 3596{
d62a17ae 3597 int idx_peer = 2;
73d70fa6 3598
d62a17ae 3599 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3600 PEER_FLAG_SHUTDOWN);
718e3744 3601}
6b0655a2 3602
d62a17ae 3603ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3604 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3605 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3606 "Administratively shut down this neighbor\n")
73d70fa6 3607
718e3744 3608/* neighbor capability dynamic. */
3609DEFUN (neighbor_capability_dynamic,
3610 neighbor_capability_dynamic_cmd,
9ccf14f7 3611 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3612 NEIGHBOR_STR
3613 NEIGHBOR_ADDR_STR2
3614 "Advertise capability to the peer\n"
3615 "Advertise dynamic capability to this neighbor\n")
3616{
d62a17ae 3617 int idx_peer = 1;
3618 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3619 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3620}
3621
3622DEFUN (no_neighbor_capability_dynamic,
3623 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3624 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3625 NO_STR
3626 NEIGHBOR_STR
3627 NEIGHBOR_ADDR_STR2
3628 "Advertise capability to the peer\n"
3629 "Advertise dynamic capability to this neighbor\n")
3630{
d62a17ae 3631 int idx_peer = 2;
3632 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3633 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3634}
6b0655a2 3635
718e3744 3636/* neighbor dont-capability-negotiate */
3637DEFUN (neighbor_dont_capability_negotiate,
3638 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3639 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3640 NEIGHBOR_STR
3641 NEIGHBOR_ADDR_STR2
3642 "Do not perform capability negotiation\n")
3643{
d62a17ae 3644 int idx_peer = 1;
3645 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3646 PEER_FLAG_DONT_CAPABILITY);
718e3744 3647}
3648
3649DEFUN (no_neighbor_dont_capability_negotiate,
3650 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3651 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3652 NO_STR
3653 NEIGHBOR_STR
3654 NEIGHBOR_ADDR_STR2
3655 "Do not perform capability negotiation\n")
3656{
d62a17ae 3657 int idx_peer = 2;
3658 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3659 PEER_FLAG_DONT_CAPABILITY);
718e3744 3660}
6b0655a2 3661
8a92a8a0
DS
3662/* neighbor capability extended next hop encoding */
3663DEFUN (neighbor_capability_enhe,
3664 neighbor_capability_enhe_cmd,
9ccf14f7 3665 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3666 NEIGHBOR_STR
3667 NEIGHBOR_ADDR_STR2
3668 "Advertise capability to the peer\n"
3669 "Advertise extended next-hop capability to the peer\n")
3670{
d62a17ae 3671 int idx_peer = 1;
3672 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3673 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3674}
3675
3676DEFUN (no_neighbor_capability_enhe,
3677 no_neighbor_capability_enhe_cmd,
9ccf14f7 3678 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3679 NO_STR
3680 NEIGHBOR_STR
3681 NEIGHBOR_ADDR_STR2
3682 "Advertise capability to the peer\n"
3683 "Advertise extended next-hop capability to the peer\n")
3684{
d62a17ae 3685 int idx_peer = 2;
3686 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3687 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3688}
3689
d62a17ae 3690static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3691 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3692 int set)
718e3744 3693{
d62a17ae 3694 int ret;
3695 struct peer *peer;
718e3744 3696
d62a17ae 3697 peer = peer_and_group_lookup_vty(vty, peer_str);
3698 if (!peer)
3699 return CMD_WARNING_CONFIG_FAILED;
718e3744 3700
d62a17ae 3701 if (set)
3702 ret = peer_af_flag_set(peer, afi, safi, flag);
3703 else
3704 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3705
d62a17ae 3706 return bgp_vty_return(vty, ret);
718e3744 3707}
3708
d62a17ae 3709static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3710 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3711{
d62a17ae 3712 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3713}
3714
d62a17ae 3715static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3716 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3717{
d62a17ae 3718 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3719}
6b0655a2 3720
718e3744 3721/* neighbor capability orf prefix-list. */
3722DEFUN (neighbor_capability_orf_prefix,
3723 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3724 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3725 NEIGHBOR_STR
3726 NEIGHBOR_ADDR_STR2
3727 "Advertise capability to the peer\n"
3728 "Advertise ORF capability to the peer\n"
3729 "Advertise prefixlist ORF capability to this neighbor\n"
3730 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3731 "Capability to RECEIVE the ORF from this neighbor\n"
3732 "Capability to SEND the ORF to this neighbor\n")
3733{
d62a17ae 3734 int idx_peer = 1;
3735 int idx_send_recv = 5;
d7c0a89a 3736 uint16_t flag = 0;
d62a17ae 3737
3738 if (strmatch(argv[idx_send_recv]->text, "send"))
3739 flag = PEER_FLAG_ORF_PREFIX_SM;
3740 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3741 flag = PEER_FLAG_ORF_PREFIX_RM;
3742 else if (strmatch(argv[idx_send_recv]->text, "both"))
3743 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3744 else {
3745 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3746 return CMD_WARNING_CONFIG_FAILED;
3747 }
3748
3749 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3750 bgp_node_safi(vty), flag);
3751}
3752
3753ALIAS_HIDDEN(
3754 neighbor_capability_orf_prefix,
3755 neighbor_capability_orf_prefix_hidden_cmd,
3756 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3757 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3758 "Advertise capability to the peer\n"
3759 "Advertise ORF capability to the peer\n"
3760 "Advertise prefixlist ORF capability to this neighbor\n"
3761 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3762 "Capability to RECEIVE the ORF from this neighbor\n"
3763 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3764
718e3744 3765DEFUN (no_neighbor_capability_orf_prefix,
3766 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3767 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3768 NO_STR
3769 NEIGHBOR_STR
3770 NEIGHBOR_ADDR_STR2
3771 "Advertise capability to the peer\n"
3772 "Advertise ORF capability to the peer\n"
3773 "Advertise prefixlist ORF capability to this neighbor\n"
3774 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3775 "Capability to RECEIVE the ORF from this neighbor\n"
3776 "Capability to SEND the ORF to this neighbor\n")
3777{
d62a17ae 3778 int idx_peer = 2;
3779 int idx_send_recv = 6;
d7c0a89a 3780 uint16_t flag = 0;
d62a17ae 3781
3782 if (strmatch(argv[idx_send_recv]->text, "send"))
3783 flag = PEER_FLAG_ORF_PREFIX_SM;
3784 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3785 flag = PEER_FLAG_ORF_PREFIX_RM;
3786 else if (strmatch(argv[idx_send_recv]->text, "both"))
3787 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3788 else {
3789 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3790 return CMD_WARNING_CONFIG_FAILED;
3791 }
3792
3793 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3794 bgp_node_afi(vty), bgp_node_safi(vty),
3795 flag);
3796}
3797
3798ALIAS_HIDDEN(
3799 no_neighbor_capability_orf_prefix,
3800 no_neighbor_capability_orf_prefix_hidden_cmd,
3801 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3802 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3803 "Advertise capability to the peer\n"
3804 "Advertise ORF capability to the peer\n"
3805 "Advertise prefixlist ORF capability to this neighbor\n"
3806 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3807 "Capability to RECEIVE the ORF from this neighbor\n"
3808 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3809
718e3744 3810/* neighbor next-hop-self. */
3811DEFUN (neighbor_nexthop_self,
3812 neighbor_nexthop_self_cmd,
9ccf14f7 3813 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3814 NEIGHBOR_STR
3815 NEIGHBOR_ADDR_STR2
a538debe 3816 "Disable the next hop calculation for this neighbor\n")
718e3744 3817{
d62a17ae 3818 int idx_peer = 1;
3819 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3820 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3821}
9e7a53c1 3822
d62a17ae 3823ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3824 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3825 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3826 "Disable the next hop calculation for this neighbor\n")
596c17ba 3827
a538debe
DS
3828/* neighbor next-hop-self. */
3829DEFUN (neighbor_nexthop_self_force,
3830 neighbor_nexthop_self_force_cmd,
9ccf14f7 3831 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3832 NEIGHBOR_STR
3833 NEIGHBOR_ADDR_STR2
3834 "Disable the next hop calculation for this neighbor\n"
3835 "Set the next hop to self for reflected routes\n")
3836{
d62a17ae 3837 int idx_peer = 1;
3838 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3839 bgp_node_safi(vty),
3840 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3841}
3842
d62a17ae 3843ALIAS_HIDDEN(neighbor_nexthop_self_force,
3844 neighbor_nexthop_self_force_hidden_cmd,
3845 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3846 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3847 "Disable the next hop calculation for this neighbor\n"
3848 "Set the next hop to self for reflected routes\n")
596c17ba 3849
718e3744 3850DEFUN (no_neighbor_nexthop_self,
3851 no_neighbor_nexthop_self_cmd,
9ccf14f7 3852 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3853 NO_STR
3854 NEIGHBOR_STR
3855 NEIGHBOR_ADDR_STR2
a538debe 3856 "Disable the next hop calculation for this neighbor\n")
718e3744 3857{
d62a17ae 3858 int idx_peer = 2;
3859 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3860 bgp_node_afi(vty), bgp_node_safi(vty),
3861 PEER_FLAG_NEXTHOP_SELF);
718e3744 3862}
6b0655a2 3863
d62a17ae 3864ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3865 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3866 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3867 "Disable the next hop calculation for this neighbor\n")
596c17ba 3868
88b8ed8d 3869DEFUN (no_neighbor_nexthop_self_force,
a538debe 3870 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3871 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3872 NO_STR
3873 NEIGHBOR_STR
3874 NEIGHBOR_ADDR_STR2
3875 "Disable the next hop calculation for this neighbor\n"
3876 "Set the next hop to self for reflected routes\n")
88b8ed8d 3877{
d62a17ae 3878 int idx_peer = 2;
3879 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3880 bgp_node_afi(vty), bgp_node_safi(vty),
3881 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3882}
a538debe 3883
d62a17ae 3884ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3885 no_neighbor_nexthop_self_force_hidden_cmd,
3886 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3887 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3888 "Disable the next hop calculation for this neighbor\n"
3889 "Set the next hop to self for reflected routes\n")
596c17ba 3890
c7122e14
DS
3891/* neighbor as-override */
3892DEFUN (neighbor_as_override,
3893 neighbor_as_override_cmd,
9ccf14f7 3894 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3895 NEIGHBOR_STR
3896 NEIGHBOR_ADDR_STR2
3897 "Override ASNs in outbound updates if aspath equals remote-as\n")
3898{
d62a17ae 3899 int idx_peer = 1;
3900 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3901 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3902}
3903
d62a17ae 3904ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3905 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3906 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3907 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3908
c7122e14
DS
3909DEFUN (no_neighbor_as_override,
3910 no_neighbor_as_override_cmd,
9ccf14f7 3911 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3912 NO_STR
3913 NEIGHBOR_STR
3914 NEIGHBOR_ADDR_STR2
3915 "Override ASNs in outbound updates if aspath equals remote-as\n")
3916{
d62a17ae 3917 int idx_peer = 2;
3918 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3919 bgp_node_afi(vty), bgp_node_safi(vty),
3920 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3921}
3922
d62a17ae 3923ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3924 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3925 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3926 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3927
718e3744 3928/* neighbor remove-private-AS. */
3929DEFUN (neighbor_remove_private_as,
3930 neighbor_remove_private_as_cmd,
9ccf14f7 3931 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3932 NEIGHBOR_STR
3933 NEIGHBOR_ADDR_STR2
5000f21c 3934 "Remove private ASNs in outbound updates\n")
718e3744 3935{
d62a17ae 3936 int idx_peer = 1;
3937 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3938 bgp_node_safi(vty),
3939 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3940}
3941
d62a17ae 3942ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3943 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3944 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3945 "Remove private ASNs in outbound updates\n")
596c17ba 3946
5000f21c
DS
3947DEFUN (neighbor_remove_private_as_all,
3948 neighbor_remove_private_as_all_cmd,
9ccf14f7 3949 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3950 NEIGHBOR_STR
3951 NEIGHBOR_ADDR_STR2
3952 "Remove private ASNs in outbound updates\n"
efd7904e 3953 "Apply to all AS numbers\n")
5000f21c 3954{
d62a17ae 3955 int idx_peer = 1;
3956 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3957 bgp_node_safi(vty),
3958 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3959}
3960
d62a17ae 3961ALIAS_HIDDEN(neighbor_remove_private_as_all,
3962 neighbor_remove_private_as_all_hidden_cmd,
3963 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3964 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3965 "Remove private ASNs in outbound updates\n"
3966 "Apply to all AS numbers")
596c17ba 3967
5000f21c
DS
3968DEFUN (neighbor_remove_private_as_replace_as,
3969 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3970 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3971 NEIGHBOR_STR
3972 NEIGHBOR_ADDR_STR2
3973 "Remove private ASNs in outbound updates\n"
3974 "Replace private ASNs with our ASN in outbound updates\n")
3975{
d62a17ae 3976 int idx_peer = 1;
3977 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3978 bgp_node_safi(vty),
3979 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3980}
3981
d62a17ae 3982ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3983 neighbor_remove_private_as_replace_as_hidden_cmd,
3984 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3985 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3986 "Remove private ASNs in outbound updates\n"
3987 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3988
5000f21c
DS
3989DEFUN (neighbor_remove_private_as_all_replace_as,
3990 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3991 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3992 NEIGHBOR_STR
3993 NEIGHBOR_ADDR_STR2
3994 "Remove private ASNs in outbound updates\n"
16cedbb0 3995 "Apply to all AS numbers\n"
5000f21c
DS
3996 "Replace private ASNs with our ASN in outbound updates\n")
3997{
d62a17ae 3998 int idx_peer = 1;
3999 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4000 bgp_node_safi(vty),
4001 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4002}
4003
d62a17ae 4004ALIAS_HIDDEN(
4005 neighbor_remove_private_as_all_replace_as,
4006 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4007 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4008 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4009 "Remove private ASNs in outbound updates\n"
4010 "Apply to all AS numbers\n"
4011 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4012
718e3744 4013DEFUN (no_neighbor_remove_private_as,
4014 no_neighbor_remove_private_as_cmd,
9ccf14f7 4015 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4016 NO_STR
4017 NEIGHBOR_STR
4018 NEIGHBOR_ADDR_STR2
5000f21c 4019 "Remove private ASNs in outbound updates\n")
718e3744 4020{
d62a17ae 4021 int idx_peer = 2;
4022 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4023 bgp_node_afi(vty), bgp_node_safi(vty),
4024 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4025}
6b0655a2 4026
d62a17ae 4027ALIAS_HIDDEN(no_neighbor_remove_private_as,
4028 no_neighbor_remove_private_as_hidden_cmd,
4029 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4031 "Remove private ASNs in outbound updates\n")
596c17ba 4032
88b8ed8d 4033DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4034 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4035 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4036 NO_STR
4037 NEIGHBOR_STR
4038 NEIGHBOR_ADDR_STR2
4039 "Remove private ASNs in outbound updates\n"
16cedbb0 4040 "Apply to all AS numbers\n")
88b8ed8d 4041{
d62a17ae 4042 int idx_peer = 2;
4043 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4044 bgp_node_afi(vty), bgp_node_safi(vty),
4045 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4046}
5000f21c 4047
d62a17ae 4048ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4049 no_neighbor_remove_private_as_all_hidden_cmd,
4050 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4051 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4052 "Remove private ASNs in outbound updates\n"
4053 "Apply to all AS numbers\n")
596c17ba 4054
88b8ed8d 4055DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4056 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4057 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4058 NO_STR
4059 NEIGHBOR_STR
4060 NEIGHBOR_ADDR_STR2
4061 "Remove private ASNs in outbound updates\n"
4062 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4063{
d62a17ae 4064 int idx_peer = 2;
4065 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4066 bgp_node_afi(vty), bgp_node_safi(vty),
4067 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4068}
5000f21c 4069
d62a17ae 4070ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4071 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4072 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4073 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4074 "Remove private ASNs in outbound updates\n"
4075 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4076
88b8ed8d 4077DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4078 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4079 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4080 NO_STR
4081 NEIGHBOR_STR
4082 NEIGHBOR_ADDR_STR2
4083 "Remove private ASNs in outbound updates\n"
16cedbb0 4084 "Apply to all AS numbers\n"
5000f21c 4085 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4086{
d62a17ae 4087 int idx_peer = 2;
4088 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4089 bgp_node_afi(vty), bgp_node_safi(vty),
4090 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4091}
5000f21c 4092
d62a17ae 4093ALIAS_HIDDEN(
4094 no_neighbor_remove_private_as_all_replace_as,
4095 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4096 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4097 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4098 "Remove private ASNs in outbound updates\n"
4099 "Apply to all AS numbers\n"
4100 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4101
5000f21c 4102
718e3744 4103/* neighbor send-community. */
4104DEFUN (neighbor_send_community,
4105 neighbor_send_community_cmd,
9ccf14f7 4106 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4107 NEIGHBOR_STR
4108 NEIGHBOR_ADDR_STR2
4109 "Send Community attribute to this neighbor\n")
4110{
d62a17ae 4111 int idx_peer = 1;
27c05d4d 4112
d62a17ae 4113 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4114 bgp_node_safi(vty),
4115 PEER_FLAG_SEND_COMMUNITY);
718e3744 4116}
4117
d62a17ae 4118ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4119 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4120 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4121 "Send Community attribute to this neighbor\n")
596c17ba 4122
718e3744 4123DEFUN (no_neighbor_send_community,
4124 no_neighbor_send_community_cmd,
9ccf14f7 4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4126 NO_STR
4127 NEIGHBOR_STR
4128 NEIGHBOR_ADDR_STR2
4129 "Send Community attribute to this neighbor\n")
4130{
d62a17ae 4131 int idx_peer = 2;
27c05d4d 4132
d62a17ae 4133 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4134 bgp_node_afi(vty), bgp_node_safi(vty),
4135 PEER_FLAG_SEND_COMMUNITY);
718e3744 4136}
6b0655a2 4137
d62a17ae 4138ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4139 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4140 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4141 "Send Community attribute to this neighbor\n")
596c17ba 4142
718e3744 4143/* neighbor send-community extended. */
4144DEFUN (neighbor_send_community_type,
4145 neighbor_send_community_type_cmd,
57d187bc 4146 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4147 NEIGHBOR_STR
4148 NEIGHBOR_ADDR_STR2
4149 "Send Community attribute to this neighbor\n"
4150 "Send Standard and Extended Community attributes\n"
57d187bc 4151 "Send Standard, Large and Extended Community attributes\n"
718e3744 4152 "Send Extended Community attributes\n"
57d187bc
JS
4153 "Send Standard Community attributes\n"
4154 "Send Large Community attributes\n")
718e3744 4155{
27c05d4d 4156 int idx_peer = 1;
d7c0a89a 4157 uint32_t flag = 0;
27c05d4d 4158 const char *type = argv[argc - 1]->text;
d62a17ae 4159
27c05d4d 4160 if (strmatch(type, "standard")) {
d62a17ae 4161 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4162 } else if (strmatch(type, "extended")) {
d62a17ae 4163 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4164 } else if (strmatch(type, "large")) {
d62a17ae 4165 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4166 } else if (strmatch(type, "both")) {
d62a17ae 4167 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4168 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4169 } else { /* if (strmatch(type, "all")) */
d62a17ae 4170 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4171 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4172 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4173 }
4174
27c05d4d 4175 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4176 bgp_node_safi(vty), flag);
4177}
4178
4179ALIAS_HIDDEN(
4180 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4181 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4183 "Send Community attribute to this neighbor\n"
4184 "Send Standard and Extended Community attributes\n"
4185 "Send Standard, Large and Extended Community attributes\n"
4186 "Send Extended Community attributes\n"
4187 "Send Standard Community attributes\n"
4188 "Send Large Community attributes\n")
596c17ba 4189
718e3744 4190DEFUN (no_neighbor_send_community_type,
4191 no_neighbor_send_community_type_cmd,
57d187bc 4192 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4193 NO_STR
4194 NEIGHBOR_STR
4195 NEIGHBOR_ADDR_STR2
4196 "Send Community attribute to this neighbor\n"
4197 "Send Standard and Extended Community attributes\n"
57d187bc 4198 "Send Standard, Large and Extended Community attributes\n"
718e3744 4199 "Send Extended Community attributes\n"
57d187bc
JS
4200 "Send Standard Community attributes\n"
4201 "Send Large Community attributes\n")
718e3744 4202{
d62a17ae 4203 int idx_peer = 2;
27c05d4d 4204 uint32_t flag = 0;
d62a17ae 4205 const char *type = argv[argc - 1]->text;
4206
27c05d4d
PM
4207 if (strmatch(type, "standard")) {
4208 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4209 } else if (strmatch(type, "extended")) {
4210 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4211 } else if (strmatch(type, "large")) {
4212 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4213 } else if (strmatch(type, "both")) {
4214 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4215 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4216 } else { /* if (strmatch(type, "all")) */
4217 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4218 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4219 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4220 }
4221
4222 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4223 bgp_node_afi(vty), bgp_node_safi(vty),
4224 flag);
d62a17ae 4225}
4226
4227ALIAS_HIDDEN(
4228 no_neighbor_send_community_type,
4229 no_neighbor_send_community_type_hidden_cmd,
4230 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4231 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4232 "Send Community attribute to this neighbor\n"
4233 "Send Standard and Extended Community attributes\n"
4234 "Send Standard, Large and Extended Community attributes\n"
4235 "Send Extended Community attributes\n"
4236 "Send Standard Community attributes\n"
4237 "Send Large Community attributes\n")
596c17ba 4238
718e3744 4239/* neighbor soft-reconfig. */
4240DEFUN (neighbor_soft_reconfiguration,
4241 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4242 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4243 NEIGHBOR_STR
4244 NEIGHBOR_ADDR_STR2
4245 "Per neighbor soft reconfiguration\n"
4246 "Allow inbound soft reconfiguration for this neighbor\n")
4247{
d62a17ae 4248 int idx_peer = 1;
4249 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4250 bgp_node_safi(vty),
4251 PEER_FLAG_SOFT_RECONFIG);
718e3744 4252}
4253
d62a17ae 4254ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4255 neighbor_soft_reconfiguration_hidden_cmd,
4256 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4257 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4258 "Per neighbor soft reconfiguration\n"
4259 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4260
718e3744 4261DEFUN (no_neighbor_soft_reconfiguration,
4262 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4263 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4264 NO_STR
4265 NEIGHBOR_STR
4266 NEIGHBOR_ADDR_STR2
4267 "Per neighbor soft reconfiguration\n"
4268 "Allow inbound soft reconfiguration for this neighbor\n")
4269{
d62a17ae 4270 int idx_peer = 2;
4271 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4272 bgp_node_afi(vty), bgp_node_safi(vty),
4273 PEER_FLAG_SOFT_RECONFIG);
718e3744 4274}
6b0655a2 4275
d62a17ae 4276ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4277 no_neighbor_soft_reconfiguration_hidden_cmd,
4278 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4279 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4280 "Per neighbor soft reconfiguration\n"
4281 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4282
718e3744 4283DEFUN (neighbor_route_reflector_client,
4284 neighbor_route_reflector_client_cmd,
9ccf14f7 4285 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4286 NEIGHBOR_STR
4287 NEIGHBOR_ADDR_STR2
4288 "Configure a neighbor as Route Reflector client\n")
4289{
d62a17ae 4290 int idx_peer = 1;
4291 struct peer *peer;
718e3744 4292
4293
d62a17ae 4294 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4295 if (!peer)
4296 return CMD_WARNING_CONFIG_FAILED;
718e3744 4297
d62a17ae 4298 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4299 bgp_node_safi(vty),
4300 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4301}
4302
d62a17ae 4303ALIAS_HIDDEN(neighbor_route_reflector_client,
4304 neighbor_route_reflector_client_hidden_cmd,
4305 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4306 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4307 "Configure a neighbor as Route Reflector client\n")
596c17ba 4308
718e3744 4309DEFUN (no_neighbor_route_reflector_client,
4310 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4311 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4312 NO_STR
4313 NEIGHBOR_STR
4314 NEIGHBOR_ADDR_STR2
4315 "Configure a neighbor as Route Reflector client\n")
4316{
d62a17ae 4317 int idx_peer = 2;
4318 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4319 bgp_node_afi(vty), bgp_node_safi(vty),
4320 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4321}
6b0655a2 4322
d62a17ae 4323ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4324 no_neighbor_route_reflector_client_hidden_cmd,
4325 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4326 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4327 "Configure a neighbor as Route Reflector client\n")
596c17ba 4328
718e3744 4329/* neighbor route-server-client. */
4330DEFUN (neighbor_route_server_client,
4331 neighbor_route_server_client_cmd,
9ccf14f7 4332 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4333 NEIGHBOR_STR
4334 NEIGHBOR_ADDR_STR2
4335 "Configure a neighbor as Route Server client\n")
4336{
d62a17ae 4337 int idx_peer = 1;
4338 struct peer *peer;
2a3d5731 4339
d62a17ae 4340 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4341 if (!peer)
4342 return CMD_WARNING_CONFIG_FAILED;
4343 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4344 bgp_node_safi(vty),
4345 PEER_FLAG_RSERVER_CLIENT);
718e3744 4346}
4347
d62a17ae 4348ALIAS_HIDDEN(neighbor_route_server_client,
4349 neighbor_route_server_client_hidden_cmd,
4350 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4351 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4352 "Configure a neighbor as Route Server client\n")
596c17ba 4353
718e3744 4354DEFUN (no_neighbor_route_server_client,
4355 no_neighbor_route_server_client_cmd,
9ccf14f7 4356 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4357 NO_STR
4358 NEIGHBOR_STR
4359 NEIGHBOR_ADDR_STR2
4360 "Configure a neighbor as Route Server client\n")
fee0f4c6 4361{
d62a17ae 4362 int idx_peer = 2;
4363 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4364 bgp_node_afi(vty), bgp_node_safi(vty),
4365 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4366}
6b0655a2 4367
d62a17ae 4368ALIAS_HIDDEN(no_neighbor_route_server_client,
4369 no_neighbor_route_server_client_hidden_cmd,
4370 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4371 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4372 "Configure a neighbor as Route Server client\n")
596c17ba 4373
fee0f4c6 4374DEFUN (neighbor_nexthop_local_unchanged,
4375 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4376 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4377 NEIGHBOR_STR
4378 NEIGHBOR_ADDR_STR2
4379 "Configure treatment of outgoing link-local nexthop attribute\n"
4380 "Leave link-local nexthop unchanged for this peer\n")
4381{
d62a17ae 4382 int idx_peer = 1;
4383 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4384 bgp_node_safi(vty),
4385 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4386}
6b0655a2 4387
fee0f4c6 4388DEFUN (no_neighbor_nexthop_local_unchanged,
4389 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4390 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4391 NO_STR
4392 NEIGHBOR_STR
4393 NEIGHBOR_ADDR_STR2
4394 "Configure treatment of outgoing link-local-nexthop attribute\n"
4395 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4396{
d62a17ae 4397 int idx_peer = 2;
4398 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4399 bgp_node_afi(vty), bgp_node_safi(vty),
4400 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4401}
6b0655a2 4402
718e3744 4403DEFUN (neighbor_attr_unchanged,
4404 neighbor_attr_unchanged_cmd,
a8206004 4405 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4406 NEIGHBOR_STR
4407 NEIGHBOR_ADDR_STR2
4408 "BGP attribute is propagated unchanged to this neighbor\n"
4409 "As-path attribute\n"
4410 "Nexthop attribute\n"
a8206004 4411 "Med attribute\n")
718e3744 4412{
d62a17ae 4413 int idx = 0;
8eeb0335
DW
4414 char *peer_str = argv[1]->arg;
4415 struct peer *peer;
d7c0a89a 4416 uint16_t flags = 0;
8eeb0335
DW
4417 afi_t afi = bgp_node_afi(vty);
4418 safi_t safi = bgp_node_safi(vty);
4419
4420 peer = peer_and_group_lookup_vty(vty, peer_str);
4421 if (!peer)
4422 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4423
4424 if (argv_find(argv, argc, "as-path", &idx))
4425 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4426 idx = 0;
4427 if (argv_find(argv, argc, "next-hop", &idx))
4428 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4429 idx = 0;
4430 if (argv_find(argv, argc, "med", &idx))
4431 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4432
8eeb0335
DW
4433 /* no flags means all of them! */
4434 if (!flags) {
d62a17ae 4435 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4436 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4437 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4438 } else {
a4d82a8a
PZ
4439 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4440 && peer_af_flag_check(peer, afi, safi,
4441 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4442 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4443 PEER_FLAG_AS_PATH_UNCHANGED);
4444 }
4445
a4d82a8a
PZ
4446 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4447 && peer_af_flag_check(peer, afi, safi,
4448 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4449 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4450 PEER_FLAG_NEXTHOP_UNCHANGED);
4451 }
4452
a4d82a8a
PZ
4453 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4454 && peer_af_flag_check(peer, afi, safi,
4455 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4456 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4457 PEER_FLAG_MED_UNCHANGED);
4458 }
d62a17ae 4459 }
4460
8eeb0335 4461 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4462}
4463
4464ALIAS_HIDDEN(
4465 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4466 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4467 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4468 "BGP attribute is propagated unchanged to this neighbor\n"
4469 "As-path attribute\n"
4470 "Nexthop attribute\n"
4471 "Med attribute\n")
596c17ba 4472
718e3744 4473DEFUN (no_neighbor_attr_unchanged,
4474 no_neighbor_attr_unchanged_cmd,
a8206004 4475 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4476 NO_STR
718e3744 4477 NEIGHBOR_STR
4478 NEIGHBOR_ADDR_STR2
31500417
DW
4479 "BGP attribute is propagated unchanged to this neighbor\n"
4480 "As-path attribute\n"
40e718b5 4481 "Nexthop attribute\n"
a8206004 4482 "Med attribute\n")
718e3744 4483{
d62a17ae 4484 int idx = 0;
4485 char *peer = argv[2]->arg;
d7c0a89a 4486 uint16_t flags = 0;
d62a17ae 4487
4488 if (argv_find(argv, argc, "as-path", &idx))
4489 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4490 idx = 0;
4491 if (argv_find(argv, argc, "next-hop", &idx))
4492 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4493 idx = 0;
4494 if (argv_find(argv, argc, "med", &idx))
4495 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4496
4497 if (!flags) // no flags means all of them!
4498 {
4499 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4500 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4501 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4502 }
4503
4504 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4505 bgp_node_safi(vty), flags);
4506}
4507
4508ALIAS_HIDDEN(
4509 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4510 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4511 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4512 "BGP attribute is propagated unchanged to this neighbor\n"
4513 "As-path attribute\n"
4514 "Nexthop attribute\n"
4515 "Med attribute\n")
718e3744 4516
718e3744 4517/* EBGP multihop configuration. */
d62a17ae 4518static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4519 const char *ttl_str)
718e3744 4520{
d62a17ae 4521 struct peer *peer;
4522 unsigned int ttl;
718e3744 4523
d62a17ae 4524 peer = peer_and_group_lookup_vty(vty, ip_str);
4525 if (!peer)
4526 return CMD_WARNING_CONFIG_FAILED;
718e3744 4527
d62a17ae 4528 if (peer->conf_if)
4529 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4530
d62a17ae 4531 if (!ttl_str)
4532 ttl = MAXTTL;
4533 else
4534 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4535
d62a17ae 4536 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4537}
4538
d62a17ae 4539static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4540{
d62a17ae 4541 struct peer *peer;
718e3744 4542
d62a17ae 4543 peer = peer_and_group_lookup_vty(vty, ip_str);
4544 if (!peer)
4545 return CMD_WARNING_CONFIG_FAILED;
718e3744 4546
d62a17ae 4547 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4548}
4549
4550/* neighbor ebgp-multihop. */
4551DEFUN (neighbor_ebgp_multihop,
4552 neighbor_ebgp_multihop_cmd,
9ccf14f7 4553 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4554 NEIGHBOR_STR
4555 NEIGHBOR_ADDR_STR2
4556 "Allow EBGP neighbors not on directly connected networks\n")
4557{
d62a17ae 4558 int idx_peer = 1;
4559 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4560}
4561
4562DEFUN (neighbor_ebgp_multihop_ttl,
4563 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4564 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4565 NEIGHBOR_STR
4566 NEIGHBOR_ADDR_STR2
4567 "Allow EBGP neighbors not on directly connected networks\n"
4568 "maximum hop count\n")
4569{
d62a17ae 4570 int idx_peer = 1;
4571 int idx_number = 3;
4572 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4573 argv[idx_number]->arg);
718e3744 4574}
4575
4576DEFUN (no_neighbor_ebgp_multihop,
4577 no_neighbor_ebgp_multihop_cmd,
a636c635 4578 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4579 NO_STR
4580 NEIGHBOR_STR
4581 NEIGHBOR_ADDR_STR2
a636c635
DW
4582 "Allow EBGP neighbors not on directly connected networks\n"
4583 "maximum hop count\n")
718e3744 4584{
d62a17ae 4585 int idx_peer = 2;
4586 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4587}
4588
6b0655a2 4589
6ffd2079 4590/* disable-connected-check */
4591DEFUN (neighbor_disable_connected_check,
4592 neighbor_disable_connected_check_cmd,
7ebe625c 4593 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4594 NEIGHBOR_STR
7ebe625c 4595 NEIGHBOR_ADDR_STR2
a636c635
DW
4596 "one-hop away EBGP peer using loopback address\n"
4597 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4598{
d62a17ae 4599 int idx_peer = 1;
4600 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4601 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4602}
4603
4604DEFUN (no_neighbor_disable_connected_check,
4605 no_neighbor_disable_connected_check_cmd,
7ebe625c 4606 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4607 NO_STR
4608 NEIGHBOR_STR
7ebe625c 4609 NEIGHBOR_ADDR_STR2
a636c635
DW
4610 "one-hop away EBGP peer using loopback address\n"
4611 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4612{
d62a17ae 4613 int idx_peer = 2;
4614 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4615 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4616}
4617
47cbc09b
PM
4618
4619/* enforce-first-as */
4620DEFUN (neighbor_enforce_first_as,
4621 neighbor_enforce_first_as_cmd,
4622 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4623 NEIGHBOR_STR
4624 NEIGHBOR_ADDR_STR2
4625 "Enforce the first AS for EBGP routes\n")
4626{
4627 int idx_peer = 1;
4628
4629 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4630 PEER_FLAG_ENFORCE_FIRST_AS);
4631}
4632
4633DEFUN (no_neighbor_enforce_first_as,
4634 no_neighbor_enforce_first_as_cmd,
4635 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4636 NO_STR
4637 NEIGHBOR_STR
4638 NEIGHBOR_ADDR_STR2
4639 "Enforce the first AS for EBGP routes\n")
4640{
4641 int idx_peer = 2;
4642
4643 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4644 PEER_FLAG_ENFORCE_FIRST_AS);
4645}
4646
4647
718e3744 4648DEFUN (neighbor_description,
4649 neighbor_description_cmd,
e961923c 4650 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4651 NEIGHBOR_STR
4652 NEIGHBOR_ADDR_STR2
4653 "Neighbor specific description\n"
4654 "Up to 80 characters describing this neighbor\n")
4655{
d62a17ae 4656 int idx_peer = 1;
4657 int idx_line = 3;
4658 struct peer *peer;
4659 char *str;
718e3744 4660
d62a17ae 4661 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4662 if (!peer)
4663 return CMD_WARNING_CONFIG_FAILED;
718e3744 4664
d62a17ae 4665 str = argv_concat(argv, argc, idx_line);
718e3744 4666
d62a17ae 4667 peer_description_set(peer, str);
718e3744 4668
d62a17ae 4669 XFREE(MTYPE_TMP, str);
718e3744 4670
d62a17ae 4671 return CMD_SUCCESS;
718e3744 4672}
4673
4674DEFUN (no_neighbor_description,
4675 no_neighbor_description_cmd,
a14810f4 4676 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4677 NO_STR
4678 NEIGHBOR_STR
4679 NEIGHBOR_ADDR_STR2
a14810f4 4680 "Neighbor specific description\n")
718e3744 4681{
d62a17ae 4682 int idx_peer = 2;
4683 struct peer *peer;
718e3744 4684
d62a17ae 4685 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4686 if (!peer)
4687 return CMD_WARNING_CONFIG_FAILED;
718e3744 4688
d62a17ae 4689 peer_description_unset(peer);
718e3744 4690
d62a17ae 4691 return CMD_SUCCESS;
718e3744 4692}
4693
a14810f4
PM
4694ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4695 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4696 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4697 "Neighbor specific description\n"
4698 "Up to 80 characters describing this neighbor\n")
6b0655a2 4699
718e3744 4700/* Neighbor update-source. */
d62a17ae 4701static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4702 const char *source_str)
4703{
4704 struct peer *peer;
4705 struct prefix p;
a14810f4 4706 union sockunion su;
d62a17ae 4707
4708 peer = peer_and_group_lookup_vty(vty, peer_str);
4709 if (!peer)
4710 return CMD_WARNING_CONFIG_FAILED;
4711
4712 if (peer->conf_if)
4713 return CMD_WARNING;
4714
4715 if (source_str) {
a14810f4 4716 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4717 peer_update_source_addr_set(peer, &su);
4718 else {
4719 if (str2prefix(source_str, &p)) {
4720 vty_out(vty,
4721 "%% Invalid update-source, remove prefix length \n");
4722 return CMD_WARNING_CONFIG_FAILED;
4723 } else
4724 peer_update_source_if_set(peer, source_str);
4725 }
4726 } else
4727 peer_update_source_unset(peer);
4728
4729 return CMD_SUCCESS;
4730}
4731
4732#define BGP_UPDATE_SOURCE_HELP_STR \
4733 "IPv4 address\n" \
4734 "IPv6 address\n" \
4735 "Interface name (requires zebra to be running)\n"
369688c0 4736
718e3744 4737DEFUN (neighbor_update_source,
4738 neighbor_update_source_cmd,
9ccf14f7 4739 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4740 NEIGHBOR_STR
4741 NEIGHBOR_ADDR_STR2
4742 "Source of routing updates\n"
369688c0 4743 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4744{
d62a17ae 4745 int idx_peer = 1;
4746 int idx_peer_2 = 3;
4747 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4748 argv[idx_peer_2]->arg);
718e3744 4749}
4750
4751DEFUN (no_neighbor_update_source,
4752 no_neighbor_update_source_cmd,
c7178fe7 4753 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4754 NO_STR
4755 NEIGHBOR_STR
4756 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4757 "Source of routing updates\n"
4758 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4759{
d62a17ae 4760 int idx_peer = 2;
4761 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4762}
6b0655a2 4763
d62a17ae 4764static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4765 afi_t afi, safi_t safi,
4766 const char *rmap, int set)
718e3744 4767{
d62a17ae 4768 int ret;
4769 struct peer *peer;
1de27621 4770 struct route_map *route_map;
718e3744 4771
d62a17ae 4772 peer = peer_and_group_lookup_vty(vty, peer_str);
4773 if (!peer)
4774 return CMD_WARNING_CONFIG_FAILED;
718e3744 4775
1de27621
DA
4776 if (set) {
4777 route_map = route_map_lookup_warn_noexist(vty, rmap);
4778 ret = peer_default_originate_set(peer, afi, safi,
4779 rmap, route_map);
4780 } else
d62a17ae 4781 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4782
d62a17ae 4783 return bgp_vty_return(vty, ret);
718e3744 4784}
4785
4786/* neighbor default-originate. */
4787DEFUN (neighbor_default_originate,
4788 neighbor_default_originate_cmd,
9ccf14f7 4789 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4790 NEIGHBOR_STR
4791 NEIGHBOR_ADDR_STR2
4792 "Originate default route to this neighbor\n")
4793{
d62a17ae 4794 int idx_peer = 1;
4795 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4796 bgp_node_afi(vty),
4797 bgp_node_safi(vty), NULL, 1);
718e3744 4798}
4799
d62a17ae 4800ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4801 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4803 "Originate default route to this neighbor\n")
596c17ba 4804
718e3744 4805DEFUN (neighbor_default_originate_rmap,
4806 neighbor_default_originate_rmap_cmd,
9ccf14f7 4807 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4808 NEIGHBOR_STR
4809 NEIGHBOR_ADDR_STR2
4810 "Originate default route to this neighbor\n"
4811 "Route-map to specify criteria to originate default\n"
4812 "route-map name\n")
4813{
d62a17ae 4814 int idx_peer = 1;
4815 int idx_word = 4;
4816 return peer_default_originate_set_vty(
4817 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4818 argv[idx_word]->arg, 1);
718e3744 4819}
4820
d62a17ae 4821ALIAS_HIDDEN(
4822 neighbor_default_originate_rmap,
4823 neighbor_default_originate_rmap_hidden_cmd,
4824 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4825 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4826 "Originate default route to this neighbor\n"
4827 "Route-map to specify criteria to originate default\n"
4828 "route-map name\n")
596c17ba 4829
718e3744 4830DEFUN (no_neighbor_default_originate,
4831 no_neighbor_default_originate_cmd,
a636c635 4832 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4833 NO_STR
4834 NEIGHBOR_STR
4835 NEIGHBOR_ADDR_STR2
a636c635
DW
4836 "Originate default route to this neighbor\n"
4837 "Route-map to specify criteria to originate default\n"
4838 "route-map name\n")
718e3744 4839{
d62a17ae 4840 int idx_peer = 2;
4841 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4842 bgp_node_afi(vty),
4843 bgp_node_safi(vty), NULL, 0);
718e3744 4844}
4845
d62a17ae 4846ALIAS_HIDDEN(
4847 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4848 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4849 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4850 "Originate default route to this neighbor\n"
4851 "Route-map to specify criteria to originate default\n"
4852 "route-map name\n")
596c17ba 4853
6b0655a2 4854
718e3744 4855/* Set neighbor's BGP port. */
d62a17ae 4856static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4857 const char *port_str)
4858{
4859 struct peer *peer;
d7c0a89a 4860 uint16_t port;
d62a17ae 4861 struct servent *sp;
4862
4863 peer = peer_lookup_vty(vty, ip_str);
4864 if (!peer)
4865 return CMD_WARNING_CONFIG_FAILED;
4866
4867 if (!port_str) {
4868 sp = getservbyname("bgp", "tcp");
4869 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4870 } else {
4871 port = strtoul(port_str, NULL, 10);
4872 }
718e3744 4873
d62a17ae 4874 peer_port_set(peer, port);
718e3744 4875
d62a17ae 4876 return CMD_SUCCESS;
718e3744 4877}
4878
f418446b 4879/* Set specified peer's BGP port. */
718e3744 4880DEFUN (neighbor_port,
4881 neighbor_port_cmd,
9ccf14f7 4882 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4883 NEIGHBOR_STR
4884 NEIGHBOR_ADDR_STR
4885 "Neighbor's BGP port\n"
4886 "TCP port number\n")
4887{
d62a17ae 4888 int idx_ip = 1;
4889 int idx_number = 3;
4890 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4891 argv[idx_number]->arg);
718e3744 4892}
4893
4894DEFUN (no_neighbor_port,
4895 no_neighbor_port_cmd,
9ccf14f7 4896 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4897 NO_STR
4898 NEIGHBOR_STR
4899 NEIGHBOR_ADDR_STR
8334fd5a
DW
4900 "Neighbor's BGP port\n"
4901 "TCP port number\n")
718e3744 4902{
d62a17ae 4903 int idx_ip = 2;
4904 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4905}
4906
6b0655a2 4907
718e3744 4908/* neighbor weight. */
d62a17ae 4909static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4910 safi_t safi, const char *weight_str)
718e3744 4911{
d62a17ae 4912 int ret;
4913 struct peer *peer;
4914 unsigned long weight;
718e3744 4915
d62a17ae 4916 peer = peer_and_group_lookup_vty(vty, ip_str);
4917 if (!peer)
4918 return CMD_WARNING_CONFIG_FAILED;
718e3744 4919
d62a17ae 4920 weight = strtoul(weight_str, NULL, 10);
718e3744 4921
d62a17ae 4922 ret = peer_weight_set(peer, afi, safi, weight);
4923 return bgp_vty_return(vty, ret);
718e3744 4924}
4925
d62a17ae 4926static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4927 safi_t safi)
718e3744 4928{
d62a17ae 4929 int ret;
4930 struct peer *peer;
718e3744 4931
d62a17ae 4932 peer = peer_and_group_lookup_vty(vty, ip_str);
4933 if (!peer)
4934 return CMD_WARNING_CONFIG_FAILED;
718e3744 4935
d62a17ae 4936 ret = peer_weight_unset(peer, afi, safi);
4937 return bgp_vty_return(vty, ret);
718e3744 4938}
4939
4940DEFUN (neighbor_weight,
4941 neighbor_weight_cmd,
9ccf14f7 4942 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4943 NEIGHBOR_STR
4944 NEIGHBOR_ADDR_STR2
4945 "Set default weight for routes from this neighbor\n"
4946 "default weight\n")
4947{
d62a17ae 4948 int idx_peer = 1;
4949 int idx_number = 3;
4950 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4951 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4952}
4953
d62a17ae 4954ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4955 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4957 "Set default weight for routes from this neighbor\n"
4958 "default weight\n")
596c17ba 4959
718e3744 4960DEFUN (no_neighbor_weight,
4961 no_neighbor_weight_cmd,
9ccf14f7 4962 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4963 NO_STR
4964 NEIGHBOR_STR
4965 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4966 "Set default weight for routes from this neighbor\n"
4967 "default weight\n")
718e3744 4968{
d62a17ae 4969 int idx_peer = 2;
4970 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4971 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4972}
4973
d62a17ae 4974ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4975 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4976 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4977 "Set default weight for routes from this neighbor\n"
4978 "default weight\n")
596c17ba 4979
6b0655a2 4980
718e3744 4981/* Override capability negotiation. */
4982DEFUN (neighbor_override_capability,
4983 neighbor_override_capability_cmd,
9ccf14f7 4984 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4985 NEIGHBOR_STR
4986 NEIGHBOR_ADDR_STR2
4987 "Override capability negotiation result\n")
4988{
d62a17ae 4989 int idx_peer = 1;
4990 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4991 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4992}
4993
4994DEFUN (no_neighbor_override_capability,
4995 no_neighbor_override_capability_cmd,
9ccf14f7 4996 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4997 NO_STR
4998 NEIGHBOR_STR
4999 NEIGHBOR_ADDR_STR2
5000 "Override capability negotiation result\n")
5001{
d62a17ae 5002 int idx_peer = 2;
5003 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5004 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5005}
6b0655a2 5006
718e3744 5007DEFUN (neighbor_strict_capability,
5008 neighbor_strict_capability_cmd,
9fb964de 5009 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5010 NEIGHBOR_STR
9fb964de 5011 NEIGHBOR_ADDR_STR2
718e3744 5012 "Strict capability negotiation match\n")
5013{
9fb964de
PM
5014 int idx_peer = 1;
5015
5016 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5017 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5018}
5019
5020DEFUN (no_neighbor_strict_capability,
5021 no_neighbor_strict_capability_cmd,
9fb964de 5022 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5023 NO_STR
5024 NEIGHBOR_STR
9fb964de 5025 NEIGHBOR_ADDR_STR2
718e3744 5026 "Strict capability negotiation match\n")
5027{
9fb964de
PM
5028 int idx_peer = 2;
5029
5030 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5031 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5032}
6b0655a2 5033
d62a17ae 5034static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5035 const char *keep_str, const char *hold_str)
718e3744 5036{
d62a17ae 5037 int ret;
5038 struct peer *peer;
d7c0a89a
QY
5039 uint32_t keepalive;
5040 uint32_t holdtime;
718e3744 5041
d62a17ae 5042 peer = peer_and_group_lookup_vty(vty, ip_str);
5043 if (!peer)
5044 return CMD_WARNING_CONFIG_FAILED;
718e3744 5045
d62a17ae 5046 keepalive = strtoul(keep_str, NULL, 10);
5047 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5048
d62a17ae 5049 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5050
d62a17ae 5051 return bgp_vty_return(vty, ret);
718e3744 5052}
6b0655a2 5053
d62a17ae 5054static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5055{
d62a17ae 5056 int ret;
5057 struct peer *peer;
718e3744 5058
d62a17ae 5059 peer = peer_and_group_lookup_vty(vty, ip_str);
5060 if (!peer)
5061 return CMD_WARNING_CONFIG_FAILED;
718e3744 5062
d62a17ae 5063 ret = peer_timers_unset(peer);
718e3744 5064
d62a17ae 5065 return bgp_vty_return(vty, ret);
718e3744 5066}
5067
5068DEFUN (neighbor_timers,
5069 neighbor_timers_cmd,
9ccf14f7 5070 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5071 NEIGHBOR_STR
5072 NEIGHBOR_ADDR_STR2
5073 "BGP per neighbor timers\n"
5074 "Keepalive interval\n"
5075 "Holdtime\n")
5076{
d62a17ae 5077 int idx_peer = 1;
5078 int idx_number = 3;
5079 int idx_number_2 = 4;
5080 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5081 argv[idx_number]->arg,
5082 argv[idx_number_2]->arg);
718e3744 5083}
5084
5085DEFUN (no_neighbor_timers,
5086 no_neighbor_timers_cmd,
9ccf14f7 5087 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5088 NO_STR
5089 NEIGHBOR_STR
5090 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5091 "BGP per neighbor timers\n"
5092 "Keepalive interval\n"
5093 "Holdtime\n")
718e3744 5094{
d62a17ae 5095 int idx_peer = 2;
5096 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5097}
6b0655a2 5098
813d4307 5099
d62a17ae 5100static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5101 const char *time_str)
718e3744 5102{
d62a17ae 5103 int ret;
5104 struct peer *peer;
d7c0a89a 5105 uint32_t connect;
718e3744 5106
d62a17ae 5107 peer = peer_and_group_lookup_vty(vty, ip_str);
5108 if (!peer)
5109 return CMD_WARNING_CONFIG_FAILED;
718e3744 5110
d62a17ae 5111 connect = strtoul(time_str, NULL, 10);
718e3744 5112
d62a17ae 5113 ret = peer_timers_connect_set(peer, connect);
718e3744 5114
d62a17ae 5115 return bgp_vty_return(vty, ret);
718e3744 5116}
5117
d62a17ae 5118static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5119{
d62a17ae 5120 int ret;
5121 struct peer *peer;
718e3744 5122
d62a17ae 5123 peer = peer_and_group_lookup_vty(vty, ip_str);
5124 if (!peer)
5125 return CMD_WARNING_CONFIG_FAILED;
718e3744 5126
d62a17ae 5127 ret = peer_timers_connect_unset(peer);
718e3744 5128
d62a17ae 5129 return bgp_vty_return(vty, ret);
718e3744 5130}
5131
5132DEFUN (neighbor_timers_connect,
5133 neighbor_timers_connect_cmd,
9ccf14f7 5134 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5135 NEIGHBOR_STR
966f821c 5136 NEIGHBOR_ADDR_STR2
718e3744 5137 "BGP per neighbor timers\n"
5138 "BGP connect timer\n"
5139 "Connect timer\n")
5140{
d62a17ae 5141 int idx_peer = 1;
5142 int idx_number = 4;
5143 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5144 argv[idx_number]->arg);
718e3744 5145}
5146
5147DEFUN (no_neighbor_timers_connect,
5148 no_neighbor_timers_connect_cmd,
9ccf14f7 5149 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5150 NO_STR
5151 NEIGHBOR_STR
966f821c 5152 NEIGHBOR_ADDR_STR2
718e3744 5153 "BGP per neighbor timers\n"
8334fd5a
DW
5154 "BGP connect timer\n"
5155 "Connect timer\n")
718e3744 5156{
d62a17ae 5157 int idx_peer = 2;
5158 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5159}
5160
6b0655a2 5161
d62a17ae 5162static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5163 const char *time_str, int set)
718e3744 5164{
d62a17ae 5165 int ret;
5166 struct peer *peer;
d7c0a89a 5167 uint32_t routeadv = 0;
718e3744 5168
d62a17ae 5169 peer = peer_and_group_lookup_vty(vty, ip_str);
5170 if (!peer)
5171 return CMD_WARNING_CONFIG_FAILED;
718e3744 5172
d62a17ae 5173 if (time_str)
5174 routeadv = strtoul(time_str, NULL, 10);
718e3744 5175
d62a17ae 5176 if (set)
5177 ret = peer_advertise_interval_set(peer, routeadv);
5178 else
5179 ret = peer_advertise_interval_unset(peer);
718e3744 5180
d62a17ae 5181 return bgp_vty_return(vty, ret);
718e3744 5182}
5183
5184DEFUN (neighbor_advertise_interval,
5185 neighbor_advertise_interval_cmd,
9ccf14f7 5186 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5187 NEIGHBOR_STR
966f821c 5188 NEIGHBOR_ADDR_STR2
718e3744 5189 "Minimum interval between sending BGP routing updates\n"
5190 "time in seconds\n")
5191{
d62a17ae 5192 int idx_peer = 1;
5193 int idx_number = 3;
5194 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5195 argv[idx_number]->arg, 1);
718e3744 5196}
5197
5198DEFUN (no_neighbor_advertise_interval,
5199 no_neighbor_advertise_interval_cmd,
9ccf14f7 5200 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5201 NO_STR
5202 NEIGHBOR_STR
966f821c 5203 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5204 "Minimum interval between sending BGP routing updates\n"
5205 "time in seconds\n")
718e3744 5206{
d62a17ae 5207 int idx_peer = 2;
5208 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5209}
5210
6b0655a2 5211
518f0eb1
DS
5212/* Time to wait before processing route-map updates */
5213DEFUN (bgp_set_route_map_delay_timer,
5214 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5215 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5216 SET_STR
5217 "BGP route-map delay timer\n"
5218 "Time in secs to wait before processing route-map changes\n"
f414725f 5219 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5220{
d62a17ae 5221 int idx_number = 3;
d7c0a89a 5222 uint32_t rmap_delay_timer;
d62a17ae 5223
5224 if (argv[idx_number]->arg) {
5225 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5226 bm->rmap_update_timer = rmap_delay_timer;
5227
5228 /* if the dynamic update handling is being disabled, and a timer
5229 * is
5230 * running, stop the timer and act as if the timer has already
5231 * fired.
5232 */
5233 if (!rmap_delay_timer && bm->t_rmap_update) {
5234 BGP_TIMER_OFF(bm->t_rmap_update);
5235 thread_execute(bm->master, bgp_route_map_update_timer,
5236 NULL, 0);
5237 }
5238 return CMD_SUCCESS;
5239 } else {
5240 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5241 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5242 }
518f0eb1
DS
5243}
5244
5245DEFUN (no_bgp_set_route_map_delay_timer,
5246 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5247 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5248 NO_STR
3a2d747c 5249 BGP_STR
518f0eb1 5250 "Default BGP route-map delay timer\n"
8334fd5a
DW
5251 "Reset to default time to wait for processing route-map changes\n"
5252 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5253{
518f0eb1 5254
d62a17ae 5255 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5256
d62a17ae 5257 return CMD_SUCCESS;
518f0eb1
DS
5258}
5259
f414725f 5260
718e3744 5261/* neighbor interface */
d62a17ae 5262static int peer_interface_vty(struct vty *vty, const char *ip_str,
5263 const char *str)
718e3744 5264{
d62a17ae 5265 struct peer *peer;
718e3744 5266
d62a17ae 5267 peer = peer_lookup_vty(vty, ip_str);
5268 if (!peer || peer->conf_if) {
5269 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5270 return CMD_WARNING_CONFIG_FAILED;
5271 }
718e3744 5272
d62a17ae 5273 if (str)
5274 peer_interface_set(peer, str);
5275 else
5276 peer_interface_unset(peer);
718e3744 5277
d62a17ae 5278 return CMD_SUCCESS;
718e3744 5279}
5280
5281DEFUN (neighbor_interface,
5282 neighbor_interface_cmd,
9ccf14f7 5283 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5284 NEIGHBOR_STR
5285 NEIGHBOR_ADDR_STR
5286 "Interface\n"
5287 "Interface name\n")
5288{
d62a17ae 5289 int idx_ip = 1;
5290 int idx_word = 3;
5291 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5292}
5293
5294DEFUN (no_neighbor_interface,
5295 no_neighbor_interface_cmd,
9ccf14f7 5296 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5297 NO_STR
5298 NEIGHBOR_STR
16cedbb0 5299 NEIGHBOR_ADDR_STR2
718e3744 5300 "Interface\n"
5301 "Interface name\n")
5302{
d62a17ae 5303 int idx_peer = 2;
5304 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5305}
6b0655a2 5306
718e3744 5307DEFUN (neighbor_distribute_list,
5308 neighbor_distribute_list_cmd,
9ccf14f7 5309 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5310 NEIGHBOR_STR
5311 NEIGHBOR_ADDR_STR2
5312 "Filter updates to/from this neighbor\n"
5313 "IP access-list number\n"
5314 "IP access-list number (expanded range)\n"
5315 "IP Access-list name\n"
5316 "Filter incoming updates\n"
5317 "Filter outgoing updates\n")
5318{
d62a17ae 5319 int idx_peer = 1;
5320 int idx_acl = 3;
5321 int direct, ret;
5322 struct peer *peer;
a8206004 5323
d62a17ae 5324 const char *pstr = argv[idx_peer]->arg;
5325 const char *acl = argv[idx_acl]->arg;
5326 const char *inout = argv[argc - 1]->text;
a8206004 5327
d62a17ae 5328 peer = peer_and_group_lookup_vty(vty, pstr);
5329 if (!peer)
5330 return CMD_WARNING_CONFIG_FAILED;
a8206004 5331
d62a17ae 5332 /* Check filter direction. */
5333 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5334 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5335 direct, acl);
a8206004 5336
d62a17ae 5337 return bgp_vty_return(vty, ret);
718e3744 5338}
5339
d62a17ae 5340ALIAS_HIDDEN(
5341 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5342 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5343 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5344 "Filter updates to/from this neighbor\n"
5345 "IP access-list number\n"
5346 "IP access-list number (expanded range)\n"
5347 "IP Access-list name\n"
5348 "Filter incoming updates\n"
5349 "Filter outgoing updates\n")
596c17ba 5350
718e3744 5351DEFUN (no_neighbor_distribute_list,
5352 no_neighbor_distribute_list_cmd,
9ccf14f7 5353 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5354 NO_STR
5355 NEIGHBOR_STR
5356 NEIGHBOR_ADDR_STR2
5357 "Filter updates to/from this neighbor\n"
5358 "IP access-list number\n"
5359 "IP access-list number (expanded range)\n"
5360 "IP Access-list name\n"
5361 "Filter incoming updates\n"
5362 "Filter outgoing updates\n")
5363{
d62a17ae 5364 int idx_peer = 2;
5365 int direct, ret;
5366 struct peer *peer;
a8206004 5367
d62a17ae 5368 const char *pstr = argv[idx_peer]->arg;
5369 const char *inout = argv[argc - 1]->text;
a8206004 5370
d62a17ae 5371 peer = peer_and_group_lookup_vty(vty, pstr);
5372 if (!peer)
5373 return CMD_WARNING_CONFIG_FAILED;
a8206004 5374
d62a17ae 5375 /* Check filter direction. */
5376 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5377 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5378 direct);
a8206004 5379
d62a17ae 5380 return bgp_vty_return(vty, ret);
718e3744 5381}
6b0655a2 5382
d62a17ae 5383ALIAS_HIDDEN(
5384 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5385 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5386 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5387 "Filter updates to/from this neighbor\n"
5388 "IP access-list number\n"
5389 "IP access-list number (expanded range)\n"
5390 "IP Access-list name\n"
5391 "Filter incoming updates\n"
5392 "Filter outgoing updates\n")
596c17ba 5393
718e3744 5394/* Set prefix list to the peer. */
d62a17ae 5395static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5396 afi_t afi, safi_t safi,
5397 const char *name_str,
5398 const char *direct_str)
718e3744 5399{
d62a17ae 5400 int ret;
d62a17ae 5401 int direct = FILTER_IN;
cf9ac8bf 5402 struct peer *peer;
718e3744 5403
d62a17ae 5404 peer = peer_and_group_lookup_vty(vty, ip_str);
5405 if (!peer)
5406 return CMD_WARNING_CONFIG_FAILED;
718e3744 5407
d62a17ae 5408 /* Check filter direction. */
5409 if (strncmp(direct_str, "i", 1) == 0)
5410 direct = FILTER_IN;
5411 else if (strncmp(direct_str, "o", 1) == 0)
5412 direct = FILTER_OUT;
718e3744 5413
d62a17ae 5414 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5415
d62a17ae 5416 return bgp_vty_return(vty, ret);
718e3744 5417}
5418
d62a17ae 5419static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5420 afi_t afi, safi_t safi,
5421 const char *direct_str)
718e3744 5422{
d62a17ae 5423 int ret;
5424 struct peer *peer;
5425 int direct = FILTER_IN;
718e3744 5426
d62a17ae 5427 peer = peer_and_group_lookup_vty(vty, ip_str);
5428 if (!peer)
5429 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5430
d62a17ae 5431 /* Check filter direction. */
5432 if (strncmp(direct_str, "i", 1) == 0)
5433 direct = FILTER_IN;
5434 else if (strncmp(direct_str, "o", 1) == 0)
5435 direct = FILTER_OUT;
718e3744 5436
d62a17ae 5437 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5438
d62a17ae 5439 return bgp_vty_return(vty, ret);
718e3744 5440}
5441
5442DEFUN (neighbor_prefix_list,
5443 neighbor_prefix_list_cmd,
9ccf14f7 5444 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5445 NEIGHBOR_STR
5446 NEIGHBOR_ADDR_STR2
5447 "Filter updates to/from this neighbor\n"
5448 "Name of a prefix list\n"
5449 "Filter incoming updates\n"
5450 "Filter outgoing updates\n")
5451{
d62a17ae 5452 int idx_peer = 1;
5453 int idx_word = 3;
5454 int idx_in_out = 4;
5455 return peer_prefix_list_set_vty(
5456 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5457 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5458}
5459
d62a17ae 5460ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5461 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5462 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5463 "Filter updates to/from this neighbor\n"
5464 "Name of a prefix list\n"
5465 "Filter incoming updates\n"
5466 "Filter outgoing updates\n")
596c17ba 5467
718e3744 5468DEFUN (no_neighbor_prefix_list,
5469 no_neighbor_prefix_list_cmd,
9ccf14f7 5470 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5471 NO_STR
5472 NEIGHBOR_STR
5473 NEIGHBOR_ADDR_STR2
5474 "Filter updates to/from this neighbor\n"
5475 "Name of a prefix list\n"
5476 "Filter incoming updates\n"
5477 "Filter outgoing updates\n")
5478{
d62a17ae 5479 int idx_peer = 2;
5480 int idx_in_out = 5;
5481 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5482 bgp_node_afi(vty), bgp_node_safi(vty),
5483 argv[idx_in_out]->arg);
718e3744 5484}
6b0655a2 5485
d62a17ae 5486ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5487 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5488 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5489 "Filter updates to/from this neighbor\n"
5490 "Name of a prefix list\n"
5491 "Filter incoming updates\n"
5492 "Filter outgoing updates\n")
596c17ba 5493
d62a17ae 5494static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5495 safi_t safi, const char *name_str,
5496 const char *direct_str)
718e3744 5497{
d62a17ae 5498 int ret;
5499 struct peer *peer;
5500 int direct = FILTER_IN;
718e3744 5501
d62a17ae 5502 peer = peer_and_group_lookup_vty(vty, ip_str);
5503 if (!peer)
5504 return CMD_WARNING_CONFIG_FAILED;
718e3744 5505
d62a17ae 5506 /* Check filter direction. */
5507 if (strncmp(direct_str, "i", 1) == 0)
5508 direct = FILTER_IN;
5509 else if (strncmp(direct_str, "o", 1) == 0)
5510 direct = FILTER_OUT;
718e3744 5511
d62a17ae 5512 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5513
d62a17ae 5514 return bgp_vty_return(vty, ret);
718e3744 5515}
5516
d62a17ae 5517static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5518 safi_t safi, const char *direct_str)
718e3744 5519{
d62a17ae 5520 int ret;
5521 struct peer *peer;
5522 int direct = FILTER_IN;
718e3744 5523
d62a17ae 5524 peer = peer_and_group_lookup_vty(vty, ip_str);
5525 if (!peer)
5526 return CMD_WARNING_CONFIG_FAILED;
718e3744 5527
d62a17ae 5528 /* Check filter direction. */
5529 if (strncmp(direct_str, "i", 1) == 0)
5530 direct = FILTER_IN;
5531 else if (strncmp(direct_str, "o", 1) == 0)
5532 direct = FILTER_OUT;
718e3744 5533
d62a17ae 5534 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5535
d62a17ae 5536 return bgp_vty_return(vty, ret);
718e3744 5537}
5538
5539DEFUN (neighbor_filter_list,
5540 neighbor_filter_list_cmd,
9ccf14f7 5541 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5542 NEIGHBOR_STR
5543 NEIGHBOR_ADDR_STR2
5544 "Establish BGP filters\n"
5545 "AS path access-list name\n"
5546 "Filter incoming routes\n"
5547 "Filter outgoing routes\n")
5548{
d62a17ae 5549 int idx_peer = 1;
5550 int idx_word = 3;
5551 int idx_in_out = 4;
5552 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5553 bgp_node_safi(vty), argv[idx_word]->arg,
5554 argv[idx_in_out]->arg);
718e3744 5555}
5556
d62a17ae 5557ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5558 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5559 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5560 "Establish BGP filters\n"
5561 "AS path access-list name\n"
5562 "Filter incoming routes\n"
5563 "Filter outgoing routes\n")
596c17ba 5564
718e3744 5565DEFUN (no_neighbor_filter_list,
5566 no_neighbor_filter_list_cmd,
9ccf14f7 5567 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5568 NO_STR
5569 NEIGHBOR_STR
5570 NEIGHBOR_ADDR_STR2
5571 "Establish BGP filters\n"
5572 "AS path access-list name\n"
5573 "Filter incoming routes\n"
5574 "Filter outgoing routes\n")
5575{
d62a17ae 5576 int idx_peer = 2;
5577 int idx_in_out = 5;
5578 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5579 bgp_node_afi(vty), bgp_node_safi(vty),
5580 argv[idx_in_out]->arg);
718e3744 5581}
6b0655a2 5582
d62a17ae 5583ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5584 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5585 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5586 "Establish BGP filters\n"
5587 "AS path access-list name\n"
5588 "Filter incoming routes\n"
5589 "Filter outgoing routes\n")
596c17ba 5590
718e3744 5591/* Set route-map to the peer. */
d62a17ae 5592static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5593 afi_t afi, safi_t safi, const char *name_str,
5594 const char *direct_str)
718e3744 5595{
d62a17ae 5596 int ret;
5597 struct peer *peer;
5598 int direct = RMAP_IN;
1de27621 5599 struct route_map *route_map;
718e3744 5600
d62a17ae 5601 peer = peer_and_group_lookup_vty(vty, ip_str);
5602 if (!peer)
5603 return CMD_WARNING_CONFIG_FAILED;
718e3744 5604
d62a17ae 5605 /* Check filter direction. */
5606 if (strncmp(direct_str, "in", 2) == 0)
5607 direct = RMAP_IN;
5608 else if (strncmp(direct_str, "o", 1) == 0)
5609 direct = RMAP_OUT;
718e3744 5610
1de27621
DA
5611 route_map = route_map_lookup_warn_noexist(vty, name_str);
5612 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5613
d62a17ae 5614 return bgp_vty_return(vty, ret);
718e3744 5615}
5616
d62a17ae 5617static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5618 afi_t afi, safi_t safi,
5619 const char *direct_str)
718e3744 5620{
d62a17ae 5621 int ret;
5622 struct peer *peer;
5623 int direct = RMAP_IN;
718e3744 5624
d62a17ae 5625 peer = peer_and_group_lookup_vty(vty, ip_str);
5626 if (!peer)
5627 return CMD_WARNING_CONFIG_FAILED;
718e3744 5628
d62a17ae 5629 /* Check filter direction. */
5630 if (strncmp(direct_str, "in", 2) == 0)
5631 direct = RMAP_IN;
5632 else if (strncmp(direct_str, "o", 1) == 0)
5633 direct = RMAP_OUT;
718e3744 5634
d62a17ae 5635 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5636
d62a17ae 5637 return bgp_vty_return(vty, ret);
718e3744 5638}
5639
5640DEFUN (neighbor_route_map,
5641 neighbor_route_map_cmd,
9ccf14f7 5642 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5643 NEIGHBOR_STR
5644 NEIGHBOR_ADDR_STR2
5645 "Apply route map to neighbor\n"
5646 "Name of route map\n"
5647 "Apply map to incoming routes\n"
2a3d5731 5648 "Apply map to outbound routes\n")
718e3744 5649{
d62a17ae 5650 int idx_peer = 1;
5651 int idx_word = 3;
5652 int idx_in_out = 4;
5653 return peer_route_map_set_vty(
5654 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5655 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5656}
5657
d62a17ae 5658ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5659 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5660 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5661 "Apply route map to neighbor\n"
5662 "Name of route map\n"
5663 "Apply map to incoming routes\n"
5664 "Apply map to outbound routes\n")
596c17ba 5665
718e3744 5666DEFUN (no_neighbor_route_map,
5667 no_neighbor_route_map_cmd,
9ccf14f7 5668 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5669 NO_STR
5670 NEIGHBOR_STR
5671 NEIGHBOR_ADDR_STR2
5672 "Apply route map to neighbor\n"
5673 "Name of route map\n"
5674 "Apply map to incoming routes\n"
2a3d5731 5675 "Apply map to outbound routes\n")
718e3744 5676{
d62a17ae 5677 int idx_peer = 2;
5678 int idx_in_out = 5;
5679 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5680 bgp_node_afi(vty), bgp_node_safi(vty),
5681 argv[idx_in_out]->arg);
718e3744 5682}
6b0655a2 5683
d62a17ae 5684ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5685 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5686 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5687 "Apply route map to neighbor\n"
5688 "Name of route map\n"
5689 "Apply map to incoming routes\n"
5690 "Apply map to outbound routes\n")
596c17ba 5691
718e3744 5692/* Set unsuppress-map to the peer. */
d62a17ae 5693static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5694 afi_t afi, safi_t safi,
5695 const char *name_str)
718e3744 5696{
d62a17ae 5697 int ret;
5698 struct peer *peer;
1de27621 5699 struct route_map *route_map;
718e3744 5700
d62a17ae 5701 peer = peer_and_group_lookup_vty(vty, ip_str);
5702 if (!peer)
5703 return CMD_WARNING_CONFIG_FAILED;
718e3744 5704
1de27621
DA
5705 route_map = route_map_lookup_warn_noexist(vty, name_str);
5706 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5707
d62a17ae 5708 return bgp_vty_return(vty, ret);
718e3744 5709}
5710
5711/* Unset route-map from the peer. */
d62a17ae 5712static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5713 afi_t afi, safi_t safi)
718e3744 5714{
d62a17ae 5715 int ret;
5716 struct peer *peer;
718e3744 5717
d62a17ae 5718 peer = peer_and_group_lookup_vty(vty, ip_str);
5719 if (!peer)
5720 return CMD_WARNING_CONFIG_FAILED;
718e3744 5721
d62a17ae 5722 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5723
d62a17ae 5724 return bgp_vty_return(vty, ret);
718e3744 5725}
5726
5727DEFUN (neighbor_unsuppress_map,
5728 neighbor_unsuppress_map_cmd,
9ccf14f7 5729 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5730 NEIGHBOR_STR
5731 NEIGHBOR_ADDR_STR2
5732 "Route-map to selectively unsuppress suppressed routes\n"
5733 "Name of route map\n")
5734{
d62a17ae 5735 int idx_peer = 1;
5736 int idx_word = 3;
5737 return peer_unsuppress_map_set_vty(
5738 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5739 argv[idx_word]->arg);
718e3744 5740}
5741
d62a17ae 5742ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5743 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5744 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5745 "Route-map to selectively unsuppress suppressed routes\n"
5746 "Name of route map\n")
596c17ba 5747
718e3744 5748DEFUN (no_neighbor_unsuppress_map,
5749 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5750 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5751 NO_STR
5752 NEIGHBOR_STR
5753 NEIGHBOR_ADDR_STR2
5754 "Route-map to selectively unsuppress suppressed routes\n"
5755 "Name of route map\n")
5756{
d62a17ae 5757 int idx_peer = 2;
5758 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5759 bgp_node_afi(vty),
5760 bgp_node_safi(vty));
718e3744 5761}
6b0655a2 5762
d62a17ae 5763ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5764 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5765 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5766 "Route-map to selectively unsuppress suppressed routes\n"
5767 "Name of route map\n")
596c17ba 5768
d62a17ae 5769static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5770 afi_t afi, safi_t safi,
5771 const char *num_str,
5772 const char *threshold_str, int warning,
5773 const char *restart_str)
718e3744 5774{
d62a17ae 5775 int ret;
5776 struct peer *peer;
d7c0a89a
QY
5777 uint32_t max;
5778 uint8_t threshold;
5779 uint16_t restart;
718e3744 5780
d62a17ae 5781 peer = peer_and_group_lookup_vty(vty, ip_str);
5782 if (!peer)
5783 return CMD_WARNING_CONFIG_FAILED;
718e3744 5784
d62a17ae 5785 max = strtoul(num_str, NULL, 10);
5786 if (threshold_str)
5787 threshold = atoi(threshold_str);
5788 else
5789 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5790
d62a17ae 5791 if (restart_str)
5792 restart = atoi(restart_str);
5793 else
5794 restart = 0;
0a486e5f 5795
d62a17ae 5796 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5797 restart);
718e3744 5798
d62a17ae 5799 return bgp_vty_return(vty, ret);
718e3744 5800}
5801
d62a17ae 5802static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5803 afi_t afi, safi_t safi)
718e3744 5804{
d62a17ae 5805 int ret;
5806 struct peer *peer;
718e3744 5807
d62a17ae 5808 peer = peer_and_group_lookup_vty(vty, ip_str);
5809 if (!peer)
5810 return CMD_WARNING_CONFIG_FAILED;
718e3744 5811
d62a17ae 5812 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5813
d62a17ae 5814 return bgp_vty_return(vty, ret);
718e3744 5815}
5816
5817/* Maximum number of prefix configuration. prefix count is different
5818 for each peer configuration. So this configuration can be set for
5819 each peer configuration. */
5820DEFUN (neighbor_maximum_prefix,
5821 neighbor_maximum_prefix_cmd,
9ccf14f7 5822 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5823 NEIGHBOR_STR
5824 NEIGHBOR_ADDR_STR2
5825 "Maximum number of prefix accept from this peer\n"
5826 "maximum no. of prefix limit\n")
5827{
d62a17ae 5828 int idx_peer = 1;
5829 int idx_number = 3;
5830 return peer_maximum_prefix_set_vty(
5831 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5832 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5833}
5834
d62a17ae 5835ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5836 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5837 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5838 "Maximum number of prefix accept from this peer\n"
5839 "maximum no. of prefix limit\n")
596c17ba 5840
e0701b79 5841DEFUN (neighbor_maximum_prefix_threshold,
5842 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5843 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5844 NEIGHBOR_STR
5845 NEIGHBOR_ADDR_STR2
5846 "Maximum number of prefix accept from this peer\n"
5847 "maximum no. of prefix limit\n"
5848 "Threshold value (%) at which to generate a warning msg\n")
5849{
d62a17ae 5850 int idx_peer = 1;
5851 int idx_number = 3;
5852 int idx_number_2 = 4;
5853 return peer_maximum_prefix_set_vty(
5854 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5855 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5856}
e0701b79 5857
d62a17ae 5858ALIAS_HIDDEN(
5859 neighbor_maximum_prefix_threshold,
5860 neighbor_maximum_prefix_threshold_hidden_cmd,
5861 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5862 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5863 "Maximum number of prefix accept from this peer\n"
5864 "maximum no. of prefix limit\n"
5865 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5866
718e3744 5867DEFUN (neighbor_maximum_prefix_warning,
5868 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5869 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Maximum number of prefix accept from this peer\n"
5873 "maximum no. of prefix limit\n"
5874 "Only give warning message when limit is exceeded\n")
5875{
d62a17ae 5876 int idx_peer = 1;
5877 int idx_number = 3;
5878 return peer_maximum_prefix_set_vty(
5879 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5880 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5881}
5882
d62a17ae 5883ALIAS_HIDDEN(
5884 neighbor_maximum_prefix_warning,
5885 neighbor_maximum_prefix_warning_hidden_cmd,
5886 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5887 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5888 "Maximum number of prefix accept from this peer\n"
5889 "maximum no. of prefix limit\n"
5890 "Only give warning message when limit is exceeded\n")
596c17ba 5891
e0701b79 5892DEFUN (neighbor_maximum_prefix_threshold_warning,
5893 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5894 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5895 NEIGHBOR_STR
5896 NEIGHBOR_ADDR_STR2
5897 "Maximum number of prefix accept from this peer\n"
5898 "maximum no. of prefix limit\n"
5899 "Threshold value (%) at which to generate a warning msg\n"
5900 "Only give warning message when limit is exceeded\n")
5901{
d62a17ae 5902 int idx_peer = 1;
5903 int idx_number = 3;
5904 int idx_number_2 = 4;
5905 return peer_maximum_prefix_set_vty(
5906 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5907 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5908}
5909
d62a17ae 5910ALIAS_HIDDEN(
5911 neighbor_maximum_prefix_threshold_warning,
5912 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5913 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5914 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5915 "Maximum number of prefix accept from this peer\n"
5916 "maximum no. of prefix limit\n"
5917 "Threshold value (%) at which to generate a warning msg\n"
5918 "Only give warning message when limit is exceeded\n")
596c17ba 5919
0a486e5f 5920DEFUN (neighbor_maximum_prefix_restart,
5921 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5922 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5923 NEIGHBOR_STR
5924 NEIGHBOR_ADDR_STR2
5925 "Maximum number of prefix accept from this peer\n"
5926 "maximum no. of prefix limit\n"
5927 "Restart bgp connection after limit is exceeded\n"
efd7904e 5928 "Restart interval in minutes\n")
0a486e5f 5929{
d62a17ae 5930 int idx_peer = 1;
5931 int idx_number = 3;
5932 int idx_number_2 = 5;
5933 return peer_maximum_prefix_set_vty(
5934 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5935 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5936}
5937
d62a17ae 5938ALIAS_HIDDEN(
5939 neighbor_maximum_prefix_restart,
5940 neighbor_maximum_prefix_restart_hidden_cmd,
5941 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5942 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5943 "Maximum number of prefix accept from this peer\n"
5944 "maximum no. of prefix limit\n"
5945 "Restart bgp connection after limit is exceeded\n"
efd7904e 5946 "Restart interval in minutes\n")
596c17ba 5947
0a486e5f 5948DEFUN (neighbor_maximum_prefix_threshold_restart,
5949 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5950 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5951 NEIGHBOR_STR
5952 NEIGHBOR_ADDR_STR2
16cedbb0 5953 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5954 "maximum no. of prefix limit\n"
5955 "Threshold value (%) at which to generate a warning msg\n"
5956 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5957 "Restart interval in minutes\n")
0a486e5f 5958{
d62a17ae 5959 int idx_peer = 1;
5960 int idx_number = 3;
5961 int idx_number_2 = 4;
5962 int idx_number_3 = 6;
5963 return peer_maximum_prefix_set_vty(
5964 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5965 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5966 argv[idx_number_3]->arg);
5967}
5968
5969ALIAS_HIDDEN(
5970 neighbor_maximum_prefix_threshold_restart,
5971 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5972 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5973 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5974 "Maximum number of prefixes to accept from this peer\n"
5975 "maximum no. of prefix limit\n"
5976 "Threshold value (%) at which to generate a warning msg\n"
5977 "Restart bgp connection after limit is exceeded\n"
5978 "Restart interval in minutes\n")
596c17ba 5979
718e3744 5980DEFUN (no_neighbor_maximum_prefix,
5981 no_neighbor_maximum_prefix_cmd,
d04c479d 5982 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5983 NO_STR
5984 NEIGHBOR_STR
5985 NEIGHBOR_ADDR_STR2
16cedbb0 5986 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5987 "maximum no. of prefix limit\n"
5988 "Threshold value (%) at which to generate a warning msg\n"
5989 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5990 "Restart interval in minutes\n"
31500417 5991 "Only give warning message when limit is exceeded\n")
718e3744 5992{
d62a17ae 5993 int idx_peer = 2;
5994 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5995 bgp_node_afi(vty),
5996 bgp_node_safi(vty));
718e3744 5997}
e52702f2 5998
d62a17ae 5999ALIAS_HIDDEN(
6000 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6001 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6002 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6003 "Maximum number of prefixes to accept from this peer\n"
6004 "maximum no. of prefix limit\n"
6005 "Threshold value (%) at which to generate a warning msg\n"
6006 "Restart bgp connection after limit is exceeded\n"
6007 "Restart interval in minutes\n"
6008 "Only give warning message when limit is exceeded\n")
596c17ba 6009
718e3744 6010
718e3744 6011/* "neighbor allowas-in" */
6012DEFUN (neighbor_allowas_in,
6013 neighbor_allowas_in_cmd,
fd8503f5 6014 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6015 NEIGHBOR_STR
6016 NEIGHBOR_ADDR_STR2
31500417 6017 "Accept as-path with my AS present in it\n"
fd8503f5
QY
6018 "Number of occurances of AS number\n"
6019 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6020{
d62a17ae 6021 int idx_peer = 1;
6022 int idx_number_origin = 3;
6023 int ret;
6024 int origin = 0;
6025 struct peer *peer;
6026 int allow_num = 0;
6027
6028 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6029 if (!peer)
6030 return CMD_WARNING_CONFIG_FAILED;
6031
6032 if (argc <= idx_number_origin)
6033 allow_num = 3;
6034 else {
6035 if (argv[idx_number_origin]->type == WORD_TKN)
6036 origin = 1;
6037 else
6038 allow_num = atoi(argv[idx_number_origin]->arg);
6039 }
6040
6041 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6042 allow_num, origin);
6043
6044 return bgp_vty_return(vty, ret);
6045}
6046
6047ALIAS_HIDDEN(
6048 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6049 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6050 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6051 "Accept as-path with my AS present in it\n"
6052 "Number of occurances of AS number\n"
6053 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6054
718e3744 6055DEFUN (no_neighbor_allowas_in,
6056 no_neighbor_allowas_in_cmd,
fd8503f5 6057 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6058 NO_STR
6059 NEIGHBOR_STR
6060 NEIGHBOR_ADDR_STR2
8334fd5a 6061 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
6062 "Number of occurances of AS number\n"
6063 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6064{
d62a17ae 6065 int idx_peer = 2;
6066 int ret;
6067 struct peer *peer;
718e3744 6068
d62a17ae 6069 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6070 if (!peer)
6071 return CMD_WARNING_CONFIG_FAILED;
718e3744 6072
d62a17ae 6073 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6074 bgp_node_safi(vty));
718e3744 6075
d62a17ae 6076 return bgp_vty_return(vty, ret);
718e3744 6077}
6b0655a2 6078
d62a17ae 6079ALIAS_HIDDEN(
6080 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6081 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6082 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6083 "allow local ASN appears in aspath attribute\n"
6084 "Number of occurances of AS number\n"
6085 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6086
fa411a21
NH
6087DEFUN (neighbor_ttl_security,
6088 neighbor_ttl_security_cmd,
7ebe625c 6089 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6090 NEIGHBOR_STR
7ebe625c 6091 NEIGHBOR_ADDR_STR2
16cedbb0 6092 "BGP ttl-security parameters\n"
d7fa34c1
QY
6093 "Specify the maximum number of hops to the BGP peer\n"
6094 "Number of hops to BGP peer\n")
fa411a21 6095{
d62a17ae 6096 int idx_peer = 1;
6097 int idx_number = 4;
6098 struct peer *peer;
6099 int gtsm_hops;
6100
6101 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6102 if (!peer)
6103 return CMD_WARNING_CONFIG_FAILED;
6104
6105 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6106
7ebe625c
QY
6107 /*
6108 * If 'neighbor swpX', then this is for directly connected peers,
6109 * we should not accept a ttl-security hops value greater than 1.
6110 */
6111 if (peer->conf_if && (gtsm_hops > 1)) {
6112 vty_out(vty,
6113 "%s is directly connected peer, hops cannot exceed 1\n",
6114 argv[idx_peer]->arg);
6115 return CMD_WARNING_CONFIG_FAILED;
6116 }
6117
d62a17ae 6118 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6119}
6120
6121DEFUN (no_neighbor_ttl_security,
6122 no_neighbor_ttl_security_cmd,
7ebe625c 6123 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6124 NO_STR
6125 NEIGHBOR_STR
7ebe625c 6126 NEIGHBOR_ADDR_STR2
16cedbb0 6127 "BGP ttl-security parameters\n"
3a2d747c
QY
6128 "Specify the maximum number of hops to the BGP peer\n"
6129 "Number of hops to BGP peer\n")
fa411a21 6130{
d62a17ae 6131 int idx_peer = 2;
6132 struct peer *peer;
fa411a21 6133
d62a17ae 6134 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6135 if (!peer)
6136 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6137
d62a17ae 6138 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6139}
6b0655a2 6140
adbac85e
DW
6141DEFUN (neighbor_addpath_tx_all_paths,
6142 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6143 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6144 NEIGHBOR_STR
6145 NEIGHBOR_ADDR_STR2
6146 "Use addpath to advertise all paths to a neighbor\n")
6147{
d62a17ae 6148 int idx_peer = 1;
6149 struct peer *peer;
adbac85e 6150
d62a17ae 6151 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6152 if (!peer)
6153 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6154
d62a17ae 6155 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6156 bgp_node_safi(vty),
6157 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6158}
6159
d62a17ae 6160ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6161 neighbor_addpath_tx_all_paths_hidden_cmd,
6162 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6163 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6164 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6165
adbac85e
DW
6166DEFUN (no_neighbor_addpath_tx_all_paths,
6167 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6168 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6169 NO_STR
6170 NEIGHBOR_STR
6171 NEIGHBOR_ADDR_STR2
6172 "Use addpath to advertise all paths to a neighbor\n")
6173{
d62a17ae 6174 int idx_peer = 2;
6175 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6176 bgp_node_afi(vty), bgp_node_safi(vty),
6177 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6178}
6179
d62a17ae 6180ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6181 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6182 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6183 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6184 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6185
06370dac
DW
6186DEFUN (neighbor_addpath_tx_bestpath_per_as,
6187 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6188 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
6191 "Use addpath to advertise the bestpath per each neighboring AS\n")
6192{
d62a17ae 6193 int idx_peer = 1;
6194 struct peer *peer;
06370dac 6195
d62a17ae 6196 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6197 if (!peer)
6198 return CMD_WARNING_CONFIG_FAILED;
06370dac 6199
d62a17ae 6200 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6201 bgp_node_safi(vty),
6202 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6203}
6204
d62a17ae 6205ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6206 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6207 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6208 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6209 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6210
06370dac
DW
6211DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6212 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6213 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6214 NO_STR
6215 NEIGHBOR_STR
6216 NEIGHBOR_ADDR_STR2
6217 "Use addpath to advertise the bestpath per each neighboring AS\n")
6218{
d62a17ae 6219 int idx_peer = 2;
6220 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6221 bgp_node_afi(vty), bgp_node_safi(vty),
6222 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6223}
6224
d62a17ae 6225ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6226 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6227 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6228 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6229 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6230
b9c7bc5a
PZ
6231static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6232 struct ecommunity **list)
ddb5b488 6233{
b9c7bc5a
PZ
6234 struct ecommunity *ecom = NULL;
6235 struct ecommunity *ecomadd;
ddb5b488 6236
b9c7bc5a 6237 for (; argc; --argc, ++argv) {
ddb5b488 6238
b9c7bc5a
PZ
6239 ecomadd = ecommunity_str2com(argv[0]->arg,
6240 ECOMMUNITY_ROUTE_TARGET, 0);
6241 if (!ecomadd) {
6242 vty_out(vty, "Malformed community-list value\n");
6243 if (ecom)
6244 ecommunity_free(&ecom);
6245 return CMD_WARNING_CONFIG_FAILED;
6246 }
ddb5b488 6247
b9c7bc5a
PZ
6248 if (ecom) {
6249 ecommunity_merge(ecom, ecomadd);
6250 ecommunity_free(&ecomadd);
6251 } else {
6252 ecom = ecomadd;
6253 }
6254 }
6255
6256 if (*list) {
6257 ecommunity_free(&*list);
ddb5b488 6258 }
b9c7bc5a
PZ
6259 *list = ecom;
6260
6261 return CMD_SUCCESS;
ddb5b488
PZ
6262}
6263
0ca70ba5
DS
6264/*
6265 * v2vimport is true if we are handling a `import vrf ...` command
6266 */
6267static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6268{
0ca70ba5
DS
6269 afi_t afi;
6270
ddb5b488 6271 switch (vty->node) {
b9c7bc5a 6272 case BGP_IPV4_NODE:
0ca70ba5
DS
6273 afi = AFI_IP;
6274 break;
b9c7bc5a 6275 case BGP_IPV6_NODE:
0ca70ba5
DS
6276 afi = AFI_IP6;
6277 break;
ddb5b488
PZ
6278 default:
6279 vty_out(vty,
b9c7bc5a 6280 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6281 return AFI_MAX;
ddb5b488 6282 }
69b07479 6283
0ca70ba5
DS
6284 if (!v2vimport) {
6285 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6286 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6287 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6288 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6289 vty_out(vty,
6290 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6291 return AFI_MAX;
6292 }
6293 } else {
6294 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6295 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6296 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6297 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6298 vty_out(vty,
6299 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6300 return AFI_MAX;
6301 }
6302 }
6303 return afi;
ddb5b488
PZ
6304}
6305
b9c7bc5a
PZ
6306DEFPY (af_rd_vpn_export,
6307 af_rd_vpn_export_cmd,
6308 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6309 NO_STR
ddb5b488 6310 "Specify route distinguisher\n"
b9c7bc5a
PZ
6311 "Between current address-family and vpn\n"
6312 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6313 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6314{
6315 VTY_DECLVAR_CONTEXT(bgp, bgp);
6316 struct prefix_rd prd;
6317 int ret;
ddb5b488 6318 afi_t afi;
b9c7bc5a
PZ
6319 int idx = 0;
6320 int yes = 1;
ddb5b488 6321
b9c7bc5a 6322 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6323 yes = 0;
b9c7bc5a
PZ
6324
6325 if (yes) {
6326 ret = str2prefix_rd(rd_str, &prd);
6327 if (!ret) {
6328 vty_out(vty, "%% Malformed rd\n");
6329 return CMD_WARNING_CONFIG_FAILED;
6330 }
ddb5b488
PZ
6331 }
6332
0ca70ba5 6333 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6334 if (afi == AFI_MAX)
6335 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6336
69b07479
DS
6337 /*
6338 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6339 */
6340 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6341 bgp_get_default(), bgp);
ddb5b488 6342
69b07479
DS
6343 if (yes) {
6344 bgp->vpn_policy[afi].tovpn_rd = prd;
6345 SET_FLAG(bgp->vpn_policy[afi].flags,
6346 BGP_VPN_POLICY_TOVPN_RD_SET);
6347 } else {
6348 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6349 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6350 }
6351
69b07479
DS
6352 /* post-change: re-export vpn routes */
6353 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6354 bgp_get_default(), bgp);
6355
ddb5b488
PZ
6356 return CMD_SUCCESS;
6357}
6358
b9c7bc5a
PZ
6359ALIAS (af_rd_vpn_export,
6360 af_no_rd_vpn_export_cmd,
6361 "no rd vpn export",
ddb5b488 6362 NO_STR
b9c7bc5a
PZ
6363 "Specify route distinguisher\n"
6364 "Between current address-family and vpn\n"
6365 "For routes leaked from current address-family to vpn\n")
ddb5b488 6366
b9c7bc5a
PZ
6367DEFPY (af_label_vpn_export,
6368 af_label_vpn_export_cmd,
e70e9f8e 6369 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6370 NO_STR
ddb5b488 6371 "label value for VRF\n"
b9c7bc5a
PZ
6372 "Between current address-family and vpn\n"
6373 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6374 "Label Value <0-1048575>\n"
6375 "Automatically assign a label\n")
ddb5b488
PZ
6376{
6377 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6378 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6379 afi_t afi;
b9c7bc5a
PZ
6380 int idx = 0;
6381 int yes = 1;
6382
6383 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6384 yes = 0;
ddb5b488 6385
21a16cc2
PZ
6386 /* If "no ...", squash trailing parameter */
6387 if (!yes)
6388 label_auto = NULL;
6389
e70e9f8e
PZ
6390 if (yes) {
6391 if (!label_auto)
6392 label = label_val; /* parser should force unsigned */
6393 }
ddb5b488 6394
0ca70ba5 6395 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6396 if (afi == AFI_MAX)
6397 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6398
e70e9f8e 6399
69b07479
DS
6400 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6401 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6402 /* no change */
6403 return CMD_SUCCESS;
e70e9f8e 6404
69b07479
DS
6405 /*
6406 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6407 */
6408 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6409 bgp_get_default(), bgp);
6410
6411 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6412 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6413
6414 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6415
6416 /*
6417 * label has previously been automatically
6418 * assigned by labelpool: release it
6419 *
6420 * NB if tovpn_label == MPLS_LABEL_NONE it
6421 * means the automatic assignment is in flight
6422 * and therefore the labelpool callback must
6423 * detect that the auto label is not needed.
6424 */
6425
6426 bgp_lp_release(LP_TYPE_VRF,
6427 &bgp->vpn_policy[afi],
6428 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6429 }
69b07479
DS
6430 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6431 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6432 }
ddb5b488 6433
69b07479
DS
6434 bgp->vpn_policy[afi].tovpn_label = label;
6435 if (label_auto) {
6436 SET_FLAG(bgp->vpn_policy[afi].flags,
6437 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6438 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6439 vpn_leak_label_callback);
ddb5b488
PZ
6440 }
6441
69b07479
DS
6442 /* post-change: re-export vpn routes */
6443 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6444 bgp_get_default(), bgp);
6445
ddb5b488
PZ
6446 return CMD_SUCCESS;
6447}
6448
b9c7bc5a
PZ
6449ALIAS (af_label_vpn_export,
6450 af_no_label_vpn_export_cmd,
6451 "no label vpn export",
6452 NO_STR
6453 "label value for VRF\n"
6454 "Between current address-family and vpn\n"
6455 "For routes leaked from current address-family to vpn\n")
ddb5b488 6456
b9c7bc5a
PZ
6457DEFPY (af_nexthop_vpn_export,
6458 af_nexthop_vpn_export_cmd,
6459 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6460 NO_STR
ddb5b488 6461 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6462 "Between current address-family and vpn\n"
6463 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6464 "IPv4 prefix\n"
6465 "IPv6 prefix\n")
6466{
6467 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6468 afi_t afi;
ddb5b488 6469 struct prefix p;
b9c7bc5a
PZ
6470 int idx = 0;
6471 int yes = 1;
ddb5b488 6472
b9c7bc5a 6473 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6474 yes = 0;
b9c7bc5a
PZ
6475
6476 if (yes) {
6477 if (!sockunion2hostprefix(nexthop_str, &p))
6478 return CMD_WARNING_CONFIG_FAILED;
6479 }
ddb5b488 6480
0ca70ba5 6481 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6482 if (afi == AFI_MAX)
6483 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6484
69b07479
DS
6485 /*
6486 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6487 */
6488 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6489 bgp_get_default(), bgp);
ddb5b488 6490
69b07479
DS
6491 if (yes) {
6492 bgp->vpn_policy[afi].tovpn_nexthop = p;
6493 SET_FLAG(bgp->vpn_policy[afi].flags,
6494 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6495 } else {
6496 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6497 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6498 }
6499
69b07479
DS
6500 /* post-change: re-export vpn routes */
6501 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6502 bgp_get_default(), bgp);
6503
ddb5b488
PZ
6504 return CMD_SUCCESS;
6505}
6506
b9c7bc5a
PZ
6507ALIAS (af_nexthop_vpn_export,
6508 af_no_nexthop_vpn_export_cmd,
6509 "no nexthop vpn export",
ddb5b488 6510 NO_STR
b9c7bc5a
PZ
6511 "Specify next hop to use for VRF advertised prefixes\n"
6512 "Between current address-family and vpn\n"
6513 "For routes leaked from current address-family to vpn\n")
ddb5b488 6514
b9c7bc5a 6515static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6516{
b9c7bc5a
PZ
6517 if (!strcmp(dstr, "import")) {
6518 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6519 } else if (!strcmp(dstr, "export")) {
6520 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6521 } else if (!strcmp(dstr, "both")) {
6522 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6523 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6524 } else {
6525 vty_out(vty, "%% direction parse error\n");
6526 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6527 }
ddb5b488
PZ
6528 return CMD_SUCCESS;
6529}
6530
b9c7bc5a
PZ
6531DEFPY (af_rt_vpn_imexport,
6532 af_rt_vpn_imexport_cmd,
6533 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6534 NO_STR
6535 "Specify route target list\n"
ddb5b488 6536 "Specify route target list\n"
b9c7bc5a
PZ
6537 "Between current address-family and vpn\n"
6538 "For routes leaked from vpn to current address-family: match any\n"
6539 "For routes leaked from current address-family to vpn: set\n"
6540 "both import: match any and export: set\n"
ddb5b488
PZ
6541 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6542{
6543 VTY_DECLVAR_CONTEXT(bgp, bgp);
6544 int ret;
6545 struct ecommunity *ecom = NULL;
6546 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6547 vpn_policy_direction_t dir;
6548 afi_t afi;
6549 int idx = 0;
b9c7bc5a 6550 int yes = 1;
ddb5b488 6551
b9c7bc5a 6552 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6553 yes = 0;
b9c7bc5a 6554
0ca70ba5 6555 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6556 if (afi == AFI_MAX)
6557 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6558
b9c7bc5a 6559 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6560 if (ret != CMD_SUCCESS)
6561 return ret;
6562
b9c7bc5a
PZ
6563 if (yes) {
6564 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6565 vty_out(vty, "%% Missing RTLIST\n");
6566 return CMD_WARNING_CONFIG_FAILED;
6567 }
6568 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6569 if (ret != CMD_SUCCESS) {
6570 return ret;
6571 }
ddb5b488
PZ
6572 }
6573
69b07479
DS
6574 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6575 if (!dodir[dir])
ddb5b488 6576 continue;
ddb5b488 6577
69b07479 6578 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6579
69b07479
DS
6580 if (yes) {
6581 if (bgp->vpn_policy[afi].rtlist[dir])
6582 ecommunity_free(
6583 &bgp->vpn_policy[afi].rtlist[dir]);
6584 bgp->vpn_policy[afi].rtlist[dir] =
6585 ecommunity_dup(ecom);
6586 } else {
6587 if (bgp->vpn_policy[afi].rtlist[dir])
6588 ecommunity_free(
6589 &bgp->vpn_policy[afi].rtlist[dir]);
6590 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6591 }
69b07479
DS
6592
6593 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6594 }
69b07479 6595
d555f3e9
PZ
6596 if (ecom)
6597 ecommunity_free(&ecom);
ddb5b488
PZ
6598
6599 return CMD_SUCCESS;
6600}
6601
b9c7bc5a
PZ
6602ALIAS (af_rt_vpn_imexport,
6603 af_no_rt_vpn_imexport_cmd,
6604 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6605 NO_STR
6606 "Specify route target list\n"
b9c7bc5a
PZ
6607 "Specify route target list\n"
6608 "Between current address-family and vpn\n"
6609 "For routes leaked from vpn to current address-family\n"
6610 "For routes leaked from current address-family to vpn\n"
6611 "both import and export\n")
6612
6613DEFPY (af_route_map_vpn_imexport,
6614 af_route_map_vpn_imexport_cmd,
6615/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6616 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6617 NO_STR
ddb5b488 6618 "Specify route map\n"
b9c7bc5a
PZ
6619 "Between current address-family and vpn\n"
6620 "For routes leaked from vpn to current address-family\n"
6621 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6622 "name of route-map\n")
6623{
6624 VTY_DECLVAR_CONTEXT(bgp, bgp);
6625 int ret;
6626 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6627 vpn_policy_direction_t dir;
6628 afi_t afi;
ddb5b488 6629 int idx = 0;
b9c7bc5a 6630 int yes = 1;
ddb5b488 6631
b9c7bc5a 6632 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6633 yes = 0;
b9c7bc5a 6634
0ca70ba5 6635 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6636 if (afi == AFI_MAX)
6637 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6638
b9c7bc5a 6639 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6640 if (ret != CMD_SUCCESS)
6641 return ret;
6642
69b07479
DS
6643 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6644 if (!dodir[dir])
ddb5b488 6645 continue;
ddb5b488 6646
69b07479 6647 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6648
69b07479
DS
6649 if (yes) {
6650 if (bgp->vpn_policy[afi].rmap_name[dir])
6651 XFREE(MTYPE_ROUTE_MAP_NAME,
6652 bgp->vpn_policy[afi].rmap_name[dir]);
6653 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6654 MTYPE_ROUTE_MAP_NAME, rmap_str);
6655 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6656 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6657 if (!bgp->vpn_policy[afi].rmap[dir])
6658 return CMD_SUCCESS;
6659 } else {
6660 if (bgp->vpn_policy[afi].rmap_name[dir])
6661 XFREE(MTYPE_ROUTE_MAP_NAME,
6662 bgp->vpn_policy[afi].rmap_name[dir]);
6663 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6664 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6665 }
69b07479
DS
6666
6667 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6668 }
6669
6670 return CMD_SUCCESS;
6671}
6672
b9c7bc5a
PZ
6673ALIAS (af_route_map_vpn_imexport,
6674 af_no_route_map_vpn_imexport_cmd,
6675 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6676 NO_STR
6677 "Specify route map\n"
b9c7bc5a
PZ
6678 "Between current address-family and vpn\n"
6679 "For routes leaked from vpn to current address-family\n"
6680 "For routes leaked from current address-family to vpn\n")
6681
bb4f6190
DS
6682DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6683 "[no] import vrf route-map RMAP$rmap_str",
6684 NO_STR
6685 "Import routes from another VRF\n"
6686 "Vrf routes being filtered\n"
6687 "Specify route map\n"
6688 "name of route-map\n")
6689{
6690 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6691 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6692 afi_t afi;
6693 int idx = 0;
6694 int yes = 1;
6695 struct bgp *bgp_default;
6696
6697 if (argv_find(argv, argc, "no", &idx))
6698 yes = 0;
6699
0ca70ba5 6700 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6701 if (afi == AFI_MAX)
6702 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6703
6704 bgp_default = bgp_get_default();
6705 if (!bgp_default) {
6706 int32_t ret;
6707 as_t as = bgp->as;
6708
6709 /* Auto-create assuming the same AS */
6710 ret = bgp_get(&bgp_default, &as, NULL,
6711 BGP_INSTANCE_TYPE_DEFAULT);
6712
6713 if (ret) {
6714 vty_out(vty,
6715 "VRF default is not configured as a bgp instance\n");
6716 return CMD_WARNING;
6717 }
6718 }
6719
69b07479 6720 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6721
69b07479
DS
6722 if (yes) {
6723 if (bgp->vpn_policy[afi].rmap_name[dir])
6724 XFREE(MTYPE_ROUTE_MAP_NAME,
6725 bgp->vpn_policy[afi].rmap_name[dir]);
6726 bgp->vpn_policy[afi].rmap_name[dir] =
6727 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6728 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6729 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6730 if (!bgp->vpn_policy[afi].rmap[dir])
6731 return CMD_SUCCESS;
6732 } else {
6733 if (bgp->vpn_policy[afi].rmap_name[dir])
6734 XFREE(MTYPE_ROUTE_MAP_NAME,
6735 bgp->vpn_policy[afi].rmap_name[dir]);
6736 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6737 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6738 }
6739
69b07479
DS
6740 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6741
bb4f6190
DS
6742 return CMD_SUCCESS;
6743}
6744
6745ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6746 "no import vrf route-map",
6747 NO_STR
6748 "Import routes from another VRF\n"
6749 "Vrf routes being filtered\n"
6750 "Specify route map\n")
6751
12a844a5
DS
6752DEFPY (bgp_imexport_vrf,
6753 bgp_imexport_vrf_cmd,
6754 "[no] import vrf NAME$import_name",
6755 NO_STR
6756 "Import routes from another VRF\n"
6757 "VRF to import from\n"
6758 "The name of the VRF\n")
6759{
6760 VTY_DECLVAR_CONTEXT(bgp, bgp);
6761 struct listnode *node;
79ef8664
DS
6762 struct bgp *vrf_bgp, *bgp_default;
6763 int32_t ret = 0;
6764 as_t as = bgp->as;
12a844a5
DS
6765 bool remove = false;
6766 int32_t idx = 0;
6767 char *vname;
a8dadcf6 6768 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6769 safi_t safi;
6770 afi_t afi;
6771
867f0cca 6772 if (import_name == NULL) {
6773 vty_out(vty, "%% Missing import name\n");
6774 return CMD_WARNING;
6775 }
6776
12a844a5
DS
6777 if (argv_find(argv, argc, "no", &idx))
6778 remove = true;
6779
0ca70ba5
DS
6780 afi = vpn_policy_getafi(vty, bgp, true);
6781 if (afi == AFI_MAX)
6782 return CMD_WARNING_CONFIG_FAILED;
6783
12a844a5
DS
6784 safi = bgp_node_safi(vty);
6785
25679caa
DS
6786 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6787 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6788 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6789 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6790 remove ? "unimport" : "import", import_name);
6791 return CMD_WARNING;
6792 }
6793
79ef8664
DS
6794 bgp_default = bgp_get_default();
6795 if (!bgp_default) {
6796 /* Auto-create assuming the same AS */
6797 ret = bgp_get(&bgp_default, &as, NULL,
6798 BGP_INSTANCE_TYPE_DEFAULT);
6799
6800 if (ret) {
6801 vty_out(vty,
6802 "VRF default is not configured as a bgp instance\n");
6803 return CMD_WARNING;
6804 }
6805 }
6806
12a844a5
DS
6807 vrf_bgp = bgp_lookup_by_name(import_name);
6808 if (!vrf_bgp) {
79ef8664
DS
6809 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6810 vrf_bgp = bgp_default;
6811 else
0fb8d6e6
DS
6812 /* Auto-create assuming the same AS */
6813 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6814
6e2c7fe6 6815 if (ret) {
020a3f60
DS
6816 vty_out(vty,
6817 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6818 import_name);
6819 return CMD_WARNING;
6820 }
12a844a5
DS
6821 }
6822
12a844a5 6823 if (remove) {
44338987 6824 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6825 } else {
44338987 6826 /* Already importing from "import_vrf"? */
12a844a5
DS
6827 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6828 vname)) {
6829 if (strcmp(vname, import_name) == 0)
6830 return CMD_WARNING;
6831 }
6832
44338987 6833 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6834 }
6835
6836 return CMD_SUCCESS;
6837}
6838
b9c7bc5a
PZ
6839/* This command is valid only in a bgp vrf instance or the default instance */
6840DEFPY (bgp_imexport_vpn,
6841 bgp_imexport_vpn_cmd,
6842 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6843 NO_STR
6844 "Import routes to this address-family\n"
6845 "Export routes from this address-family\n"
6846 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6847{
6848 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6849 int previous_state;
ddb5b488 6850 afi_t afi;
b9c7bc5a 6851 safi_t safi;
ddb5b488 6852 int idx = 0;
b9c7bc5a
PZ
6853 int yes = 1;
6854 int flag;
6855 vpn_policy_direction_t dir;
ddb5b488 6856
b9c7bc5a 6857 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6858 yes = 0;
ddb5b488 6859
b9c7bc5a
PZ
6860 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6861 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6862
b9c7bc5a
PZ
6863 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6864 return CMD_WARNING_CONFIG_FAILED;
6865 }
ddb5b488 6866
b9c7bc5a
PZ
6867 afi = bgp_node_afi(vty);
6868 safi = bgp_node_safi(vty);
6869 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6870 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6871 return CMD_WARNING_CONFIG_FAILED;
6872 }
ddb5b488 6873
b9c7bc5a
PZ
6874 if (!strcmp(direction_str, "import")) {
6875 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6876 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6877 } else if (!strcmp(direction_str, "export")) {
6878 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6879 dir = BGP_VPN_POLICY_DIR_TOVPN;
6880 } else {
6881 vty_out(vty, "%% unknown direction %s\n", direction_str);
6882 return CMD_WARNING_CONFIG_FAILED;
6883 }
6884
6885 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6886
b9c7bc5a
PZ
6887 if (yes) {
6888 SET_FLAG(bgp->af_flags[afi][safi], flag);
6889 if (!previous_state) {
6890 /* trigger export current vrf */
ddb5b488
PZ
6891 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6892 }
b9c7bc5a
PZ
6893 } else {
6894 if (previous_state) {
6895 /* trigger un-export current vrf */
6896 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6897 }
6898 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6899 }
6900
6901 return CMD_SUCCESS;
6902}
6903
301ad80a
PG
6904DEFPY (af_routetarget_import,
6905 af_routetarget_import_cmd,
6906 "[no] <rt|route-target> redirect import RTLIST...",
6907 NO_STR
6908 "Specify route target list\n"
6909 "Specify route target list\n"
6910 "Flow-spec redirect type route target\n"
6911 "Import routes to this address-family\n"
6912 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6913{
6914 VTY_DECLVAR_CONTEXT(bgp, bgp);
6915 int ret;
6916 struct ecommunity *ecom = NULL;
301ad80a
PG
6917 afi_t afi;
6918 int idx = 0;
6919 int yes = 1;
6920
6921 if (argv_find(argv, argc, "no", &idx))
6922 yes = 0;
6923
0ca70ba5 6924 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6925 if (afi == AFI_MAX)
6926 return CMD_WARNING_CONFIG_FAILED;
6927
301ad80a
PG
6928 if (yes) {
6929 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6930 vty_out(vty, "%% Missing RTLIST\n");
6931 return CMD_WARNING_CONFIG_FAILED;
6932 }
6933 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6934 if (ret != CMD_SUCCESS)
6935 return ret;
6936 }
69b07479
DS
6937
6938 if (yes) {
6939 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6940 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6941 .import_redirect_rtlist);
69b07479
DS
6942 bgp->vpn_policy[afi].import_redirect_rtlist =
6943 ecommunity_dup(ecom);
6944 } else {
6945 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6946 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6947 .import_redirect_rtlist);
69b07479 6948 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 6949 }
69b07479 6950
301ad80a
PG
6951 if (ecom)
6952 ecommunity_free(&ecom);
6953
6954 return CMD_SUCCESS;
6955}
6956
505e5056 6957DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 6958 address_family_ipv4_safi_cmd,
6959 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6960 "Enter Address Family command mode\n"
6961 "Address Family\n"
6962 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6963{
f51bae9c 6964
d62a17ae 6965 if (argc == 3) {
2131d5cf 6966 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6967 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6968 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6969 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6970 && safi != SAFI_EVPN) {
31947174
MK
6971 vty_out(vty,
6972 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6973 return CMD_WARNING_CONFIG_FAILED;
6974 }
d62a17ae 6975 vty->node = bgp_node_type(AFI_IP, safi);
6976 } else
6977 vty->node = BGP_IPV4_NODE;
718e3744 6978
d62a17ae 6979 return CMD_SUCCESS;
718e3744 6980}
6981
505e5056 6982DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 6983 address_family_ipv6_safi_cmd,
6984 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6985 "Enter Address Family command mode\n"
6986 "Address Family\n"
6987 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6988{
d62a17ae 6989 if (argc == 3) {
2131d5cf 6990 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6991 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6992 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6993 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6994 && safi != SAFI_EVPN) {
31947174
MK
6995 vty_out(vty,
6996 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6997 return CMD_WARNING_CONFIG_FAILED;
6998 }
d62a17ae 6999 vty->node = bgp_node_type(AFI_IP6, safi);
7000 } else
7001 vty->node = BGP_IPV6_NODE;
25ffbdc1 7002
d62a17ae 7003 return CMD_SUCCESS;
25ffbdc1 7004}
718e3744 7005
d6902373 7006#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7007DEFUN_NOSH (address_family_vpnv4,
718e3744 7008 address_family_vpnv4_cmd,
8334fd5a 7009 "address-family vpnv4 [unicast]",
718e3744 7010 "Enter Address Family command mode\n"
8c3deaae 7011 "Address Family\n"
3a2d747c 7012 "Address Family modifier\n")
718e3744 7013{
d62a17ae 7014 vty->node = BGP_VPNV4_NODE;
7015 return CMD_SUCCESS;
718e3744 7016}
7017
505e5056 7018DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7019 address_family_vpnv6_cmd,
8334fd5a 7020 "address-family vpnv6 [unicast]",
8ecd3266 7021 "Enter Address Family command mode\n"
8c3deaae 7022 "Address Family\n"
3a2d747c 7023 "Address Family modifier\n")
8ecd3266 7024{
d62a17ae 7025 vty->node = BGP_VPNV6_NODE;
7026 return CMD_SUCCESS;
8ecd3266 7027}
c016b6c7 7028#endif
d6902373 7029
505e5056 7030DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7031 address_family_evpn_cmd,
7111c1a0 7032 "address-family l2vpn evpn",
4e0b7b6d 7033 "Enter Address Family command mode\n"
7111c1a0
QY
7034 "Address Family\n"
7035 "Address Family modifier\n")
4e0b7b6d 7036{
2131d5cf 7037 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7038 vty->node = BGP_EVPN_NODE;
7039 return CMD_SUCCESS;
4e0b7b6d
PG
7040}
7041
505e5056 7042DEFUN_NOSH (exit_address_family,
718e3744 7043 exit_address_family_cmd,
7044 "exit-address-family",
7045 "Exit from Address Family configuration mode\n")
7046{
d62a17ae 7047 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7048 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7049 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7050 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7051 || vty->node == BGP_EVPN_NODE
7052 || vty->node == BGP_FLOWSPECV4_NODE
7053 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7054 vty->node = BGP_NODE;
7055 return CMD_SUCCESS;
718e3744 7056}
6b0655a2 7057
8ad7271d 7058/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7059static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7060 const char *ip_str, afi_t afi, safi_t safi,
7061 struct prefix_rd *prd)
7062{
7063 int ret;
7064 struct prefix match;
7065 struct bgp_node *rn;
7066 struct bgp_node *rm;
7067 struct bgp *bgp;
7068 struct bgp_table *table;
7069 struct bgp_table *rib;
7070
7071 /* BGP structure lookup. */
7072 if (view_name) {
7073 bgp = bgp_lookup_by_name(view_name);
7074 if (bgp == NULL) {
7075 vty_out(vty, "%% Can't find BGP instance %s\n",
7076 view_name);
7077 return CMD_WARNING;
7078 }
7079 } else {
7080 bgp = bgp_get_default();
7081 if (bgp == NULL) {
7082 vty_out(vty, "%% No BGP process is configured\n");
7083 return CMD_WARNING;
7084 }
7085 }
7086
7087 /* Check IP address argument. */
7088 ret = str2prefix(ip_str, &match);
7089 if (!ret) {
7090 vty_out(vty, "%% address is malformed\n");
7091 return CMD_WARNING;
7092 }
7093
7094 match.family = afi2family(afi);
7095 rib = bgp->rib[afi][safi];
7096
7097 if (safi == SAFI_MPLS_VPN) {
7098 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7099 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7100 continue;
7101
7102 if ((table = rn->info) != NULL) {
7103 if ((rm = bgp_node_match(table, &match))
7104 != NULL) {
7105 if (rm->p.prefixlen
7106 == match.prefixlen) {
343cdb61 7107 SET_FLAG(rm->flags,
d62a17ae 7108 BGP_NODE_USER_CLEAR);
7109 bgp_process(bgp, rm, afi, safi);
7110 }
7111 bgp_unlock_node(rm);
7112 }
7113 }
7114 }
7115 } else {
7116 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7117 if (rn->p.prefixlen == match.prefixlen) {
7118 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7119 bgp_process(bgp, rn, afi, safi);
7120 }
7121 bgp_unlock_node(rn);
7122 }
7123 }
7124
7125 return CMD_SUCCESS;
8ad7271d
DS
7126}
7127
b09b5ae0 7128/* one clear bgp command to rule them all */
718e3744 7129DEFUN (clear_ip_bgp_all,
7130 clear_ip_bgp_all_cmd,
c1a44e43 7131 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 7132 CLEAR_STR
7133 IP_STR
7134 BGP_STR
838758ac 7135 BGP_INSTANCE_HELP_STR
510afcd6
DS
7136 BGP_AFI_HELP_STR
7137 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7138 "Clear all peers\n"
7139 "BGP neighbor address to clear\n"
a80beece 7140 "BGP IPv6 neighbor to clear\n"
838758ac 7141 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7142 "Clear peers with the AS number\n"
7143 "Clear all external peers\n"
718e3744 7144 "Clear all members of peer-group\n"
b09b5ae0 7145 "BGP peer-group name\n"
b09b5ae0
DW
7146 BGP_SOFT_STR
7147 BGP_SOFT_IN_STR
b09b5ae0
DW
7148 BGP_SOFT_OUT_STR
7149 BGP_SOFT_IN_STR
7150 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7151 BGP_SOFT_OUT_STR)
718e3744 7152{
d62a17ae 7153 char *vrf = NULL;
7154
7155 afi_t afi = AFI_IP6;
7156 safi_t safi = SAFI_UNICAST;
7157 enum clear_sort clr_sort = clear_peer;
7158 enum bgp_clear_type clr_type;
7159 char *clr_arg = NULL;
7160
7161 int idx = 0;
7162
7163 /* clear [ip] bgp */
7164 if (argv_find(argv, argc, "ip", &idx))
7165 afi = AFI_IP;
7166
9a8bdf1c
PG
7167 /* [<vrf> VIEWVRFNAME] */
7168 if (argv_find(argv, argc, "vrf", &idx)) {
7169 vrf = argv[idx + 1]->arg;
7170 idx += 2;
7171 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7172 vrf = NULL;
7173 } else if (argv_find(argv, argc, "view", &idx)) {
7174 /* [<view> VIEWVRFNAME] */
d62a17ae 7175 vrf = argv[idx + 1]->arg;
7176 idx += 2;
7177 }
d62a17ae 7178 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7179 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7180 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7181
7182 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7183 if (argv_find(argv, argc, "*", &idx)) {
7184 clr_sort = clear_all;
7185 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7186 clr_sort = clear_peer;
7187 clr_arg = argv[idx]->arg;
7188 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7189 clr_sort = clear_peer;
7190 clr_arg = argv[idx]->arg;
7191 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7192 clr_sort = clear_group;
7193 idx++;
7194 clr_arg = argv[idx]->arg;
7195 } else if (argv_find(argv, argc, "WORD", &idx)) {
7196 clr_sort = clear_peer;
7197 clr_arg = argv[idx]->arg;
7198 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7199 clr_sort = clear_as;
7200 clr_arg = argv[idx]->arg;
7201 } else if (argv_find(argv, argc, "external", &idx)) {
7202 clr_sort = clear_external;
7203 }
7204
7205 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7206 if (argv_find(argv, argc, "soft", &idx)) {
7207 if (argv_find(argv, argc, "in", &idx)
7208 || argv_find(argv, argc, "out", &idx))
7209 clr_type = strmatch(argv[idx]->text, "in")
7210 ? BGP_CLEAR_SOFT_IN
7211 : BGP_CLEAR_SOFT_OUT;
7212 else
7213 clr_type = BGP_CLEAR_SOFT_BOTH;
7214 } else if (argv_find(argv, argc, "in", &idx)) {
7215 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7216 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7217 : BGP_CLEAR_SOFT_IN;
7218 } else if (argv_find(argv, argc, "out", &idx)) {
7219 clr_type = BGP_CLEAR_SOFT_OUT;
7220 } else
7221 clr_type = BGP_CLEAR_SOFT_NONE;
7222
7223 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7224}
01080f7c 7225
8ad7271d
DS
7226DEFUN (clear_ip_bgp_prefix,
7227 clear_ip_bgp_prefix_cmd,
18c57037 7228 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7229 CLEAR_STR
7230 IP_STR
7231 BGP_STR
838758ac 7232 BGP_INSTANCE_HELP_STR
8ad7271d 7233 "Clear bestpath and re-advertise\n"
0c7b1b01 7234 "IPv4 prefix\n")
8ad7271d 7235{
d62a17ae 7236 char *vrf = NULL;
7237 char *prefix = NULL;
8ad7271d 7238
d62a17ae 7239 int idx = 0;
01080f7c 7240
d62a17ae 7241 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7242 if (argv_find(argv, argc, "vrf", &idx)) {
7243 vrf = argv[idx + 1]->arg;
7244 idx += 2;
7245 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7246 vrf = NULL;
7247 } else if (argv_find(argv, argc, "view", &idx)) {
7248 /* [<view> VIEWVRFNAME] */
7249 vrf = argv[idx + 1]->arg;
7250 idx += 2;
7251 }
0c7b1b01 7252
d62a17ae 7253 prefix = argv[argc - 1]->arg;
8ad7271d 7254
d62a17ae 7255 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7256}
8ad7271d 7257
b09b5ae0
DW
7258DEFUN (clear_bgp_ipv6_safi_prefix,
7259 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7260 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7261 CLEAR_STR
3a2d747c 7262 IP_STR
718e3744 7263 BGP_STR
8c3deaae 7264 "Address Family\n"
46f296b4 7265 BGP_SAFI_HELP_STR
b09b5ae0 7266 "Clear bestpath and re-advertise\n"
0c7b1b01 7267 "IPv6 prefix\n")
718e3744 7268{
9b475e76
PG
7269 int idx_safi = 0;
7270 int idx_ipv6_prefix = 0;
7271 safi_t safi = SAFI_UNICAST;
7272 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7273 argv[idx_ipv6_prefix]->arg : NULL;
7274
7275 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7276 return bgp_clear_prefix(
9b475e76
PG
7277 vty, NULL, prefix, AFI_IP6,
7278 safi, NULL);
838758ac 7279}
01080f7c 7280
b09b5ae0
DW
7281DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7282 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7283 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7284 CLEAR_STR
3a2d747c 7285 IP_STR
718e3744 7286 BGP_STR
838758ac 7287 BGP_INSTANCE_HELP_STR
8c3deaae 7288 "Address Family\n"
46f296b4 7289 BGP_SAFI_HELP_STR
b09b5ae0 7290 "Clear bestpath and re-advertise\n"
0c7b1b01 7291 "IPv6 prefix\n")
718e3744 7292{
9b475e76 7293 int idx_safi = 0;
9a8bdf1c 7294 int idx_vrfview = 0;
9b475e76
PG
7295 int idx_ipv6_prefix = 0;
7296 safi_t safi = SAFI_UNICAST;
7297 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7298 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7299 char *vrfview = NULL;
9b475e76 7300
9a8bdf1c
PG
7301 /* [<view|vrf> VIEWVRFNAME] */
7302 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7303 vrfview = argv[idx_vrfview + 1]->arg;
7304 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7305 vrfview = NULL;
7306 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7307 /* [<view> VIEWVRFNAME] */
7308 vrfview = argv[idx_vrfview + 1]->arg;
7309 }
9b475e76
PG
7310 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7311
d62a17ae 7312 return bgp_clear_prefix(
9b475e76
PG
7313 vty, vrfview, prefix,
7314 AFI_IP6, safi, NULL);
718e3744 7315}
7316
b09b5ae0
DW
7317DEFUN (show_bgp_views,
7318 show_bgp_views_cmd,
d6e3c605 7319 "show [ip] bgp views",
b09b5ae0 7320 SHOW_STR
d6e3c605 7321 IP_STR
01080f7c 7322 BGP_STR
b09b5ae0 7323 "Show the defined BGP views\n")
01080f7c 7324{
d62a17ae 7325 struct list *inst = bm->bgp;
7326 struct listnode *node;
7327 struct bgp *bgp;
01080f7c 7328
d62a17ae 7329 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7330 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7331 return CMD_WARNING;
7332 }
e52702f2 7333
d62a17ae 7334 vty_out(vty, "Defined BGP views:\n");
7335 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7336 /* Skip VRFs. */
7337 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7338 continue;
7339 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7340 bgp->as);
7341 }
e52702f2 7342
d62a17ae 7343 return CMD_SUCCESS;
e0081f70
ML
7344}
7345
8386ac43 7346DEFUN (show_bgp_vrfs,
7347 show_bgp_vrfs_cmd,
d6e3c605 7348 "show [ip] bgp vrfs [json]",
8386ac43 7349 SHOW_STR
d6e3c605 7350 IP_STR
8386ac43 7351 BGP_STR
7352 "Show BGP VRFs\n"
9973d184 7353 JSON_STR)
8386ac43 7354{
fe1dc5a3 7355 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7356 struct list *inst = bm->bgp;
7357 struct listnode *node;
7358 struct bgp *bgp;
9f049418 7359 bool uj = use_json(argc, argv);
d62a17ae 7360 json_object *json = NULL;
7361 json_object *json_vrfs = NULL;
7362 int count = 0;
d62a17ae 7363
7364 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7365 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7366 return CMD_WARNING;
7367 }
7368
7369 if (uj) {
7370 json = json_object_new_object();
7371 json_vrfs = json_object_new_object();
7372 }
7373
7374 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7375 const char *name, *type;
7376 struct peer *peer;
7fe96307 7377 struct listnode *node2, *nnode2;
d62a17ae 7378 int peers_cfg, peers_estb;
7379 json_object *json_vrf = NULL;
d62a17ae 7380
7381 /* Skip Views. */
7382 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7383 continue;
7384
7385 count++;
7386 if (!uj && count == 1)
fe1dc5a3
MK
7387 vty_out(vty,
7388 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7389 "Type", "Id", "routerId", "#PeersVfg",
7390 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7391
7392 peers_cfg = peers_estb = 0;
7393 if (uj)
7394 json_vrf = json_object_new_object();
7395
7396
7fe96307 7397 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7398 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7399 continue;
7400 peers_cfg++;
7401 if (peer->status == Established)
7402 peers_estb++;
7403 }
7404
7405 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7406 name = "Default";
7407 type = "DFLT";
7408 } else {
7409 name = bgp->name;
7410 type = "VRF";
7411 }
7412
a8bf7d9c 7413
d62a17ae 7414 if (uj) {
a4d82a8a
PZ
7415 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7416 ? -1
7417 : (int64_t)bgp->vrf_id;
d62a17ae 7418 json_object_string_add(json_vrf, "type", type);
7419 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7420 json_object_string_add(json_vrf, "routerId",
7421 inet_ntoa(bgp->router_id));
7422 json_object_int_add(json_vrf, "numConfiguredPeers",
7423 peers_cfg);
7424 json_object_int_add(json_vrf, "numEstablishedPeers",
7425 peers_estb);
7426
fe1dc5a3 7427 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7428 json_object_string_add(
7429 json_vrf, "rmac",
7430 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7431 json_object_object_add(json_vrfs, name, json_vrf);
7432 } else
fe1dc5a3
MK
7433 vty_out(vty,
7434 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7435 type,
7436 bgp->vrf_id == VRF_UNKNOWN ? -1
7437 : (int)bgp->vrf_id,
7438 inet_ntoa(bgp->router_id), peers_cfg,
7439 peers_estb, name, bgp->l3vni,
fe1dc5a3 7440 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7441 }
7442
7443 if (uj) {
7444 json_object_object_add(json, "vrfs", json_vrfs);
7445
7446 json_object_int_add(json, "totalVrfs", count);
7447
996c9314
LB
7448 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7449 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7450 json_object_free(json);
7451 } else {
7452 if (count)
7453 vty_out(vty,
7454 "\nTotal number of VRFs (including default): %d\n",
7455 count);
7456 }
7457
7458 return CMD_SUCCESS;
8386ac43 7459}
7460
acf71666
MK
7461
7462static void show_tip_entry(struct hash_backet *backet, void *args)
7463{
0291c246 7464 struct vty *vty = (struct vty *)args;
60466a63 7465 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7466
60466a63 7467 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7468 tip->refcnt);
7469}
7470
7471static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7472{
7473 vty_out(vty, "self nexthop database:\n");
af97a18b 7474 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7475
7476 vty_out(vty, "Tunnel-ip database:\n");
7477 hash_iterate(bgp->tip_hash,
7478 (void (*)(struct hash_backet *, void *))show_tip_entry,
7479 vty);
7480}
7481
15c81ca4
DS
7482DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7483 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7484 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7485 "martian next-hops\n"
7486 "martian next-hop database\n")
acf71666 7487{
0291c246 7488 struct bgp *bgp = NULL;
15c81ca4 7489 int idx = 0;
9a8bdf1c
PG
7490 char *name = NULL;
7491
7492 /* [<vrf> VIEWVRFNAME] */
7493 if (argv_find(argv, argc, "vrf", &idx)) {
7494 name = argv[idx + 1]->arg;
7495 if (name && strmatch(name, VRF_DEFAULT_NAME))
7496 name = NULL;
7497 } else if (argv_find(argv, argc, "view", &idx))
7498 /* [<view> VIEWVRFNAME] */
7499 name = argv[idx + 1]->arg;
7500 if (name)
7501 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7502 else
7503 bgp = bgp_get_default();
acf71666 7504
acf71666
MK
7505 if (!bgp) {
7506 vty_out(vty, "%% No BGP process is configured\n");
7507 return CMD_WARNING;
7508 }
7509 bgp_show_martian_nexthops(vty, bgp);
7510
7511 return CMD_SUCCESS;
7512}
7513
f412b39a 7514DEFUN (show_bgp_memory,
4bf6a362 7515 show_bgp_memory_cmd,
7fa12b13 7516 "show [ip] bgp memory",
4bf6a362 7517 SHOW_STR
3a2d747c 7518 IP_STR
4bf6a362
PJ
7519 BGP_STR
7520 "Global BGP memory statistics\n")
7521{
d62a17ae 7522 char memstrbuf[MTYPE_MEMSTR_LEN];
7523 unsigned long count;
7524
7525 /* RIB related usage stats */
7526 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7527 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7528 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7529 count * sizeof(struct bgp_node)));
7530
7531 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7532 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7533 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7534 count * sizeof(struct bgp_path_info)));
d62a17ae 7535 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7536 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7537 count,
4b7e6066
DS
7538 mtype_memstr(
7539 memstrbuf, sizeof(memstrbuf),
7540 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7541
7542 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7543 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7544 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7545 count * sizeof(struct bgp_static)));
7546
7547 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7548 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7549 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7550 count * sizeof(struct bpacket)));
7551
7552 /* Adj-In/Out */
7553 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7554 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7555 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7556 count * sizeof(struct bgp_adj_in)));
7557 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7558 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7559 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7560 count * sizeof(struct bgp_adj_out)));
7561
7562 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7563 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7564 count,
7565 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7566 count * sizeof(struct bgp_nexthop_cache)));
7567
7568 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7569 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7570 count,
7571 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7572 count * sizeof(struct bgp_damp_info)));
7573
7574 /* Attributes */
7575 count = attr_count();
7576 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7577 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7578 count * sizeof(struct attr)));
7579
7580 if ((count = attr_unknown_count()))
7581 vty_out(vty, "%ld unknown attributes\n", count);
7582
7583 /* AS_PATH attributes */
7584 count = aspath_count();
7585 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7586 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7587 count * sizeof(struct aspath)));
7588
7589 count = mtype_stats_alloc(MTYPE_AS_SEG);
7590 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7591 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7592 count * sizeof(struct assegment)));
7593
7594 /* Other attributes */
7595 if ((count = community_count()))
7596 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7597 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7598 count * sizeof(struct community)));
d62a17ae 7599 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7600 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7601 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7602 count * sizeof(struct ecommunity)));
d62a17ae 7603 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7604 vty_out(vty,
7605 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7606 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7607 count * sizeof(struct lcommunity)));
d62a17ae 7608
7609 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7610 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7611 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7612 count * sizeof(struct cluster_list)));
7613
7614 /* Peer related usage */
7615 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7616 vty_out(vty, "%ld peers, using %s of memory\n", count,
7617 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7618 count * sizeof(struct peer)));
7619
7620 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7621 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7622 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7623 count * sizeof(struct peer_group)));
7624
7625 /* Other */
7626 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7627 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7628 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7629 count * sizeof(struct hash)));
7630 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7631 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7632 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7633 count * sizeof(struct hash_backet)));
7634 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7635 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7636 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7637 count * sizeof(regex_t)));
d62a17ae 7638 return CMD_SUCCESS;
4bf6a362 7639}
fee0f4c6 7640
57a9c8a8
DS
7641static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7642{
7643 json_object *bestpath = json_object_new_object();
7644
7645 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7646 json_object_string_add(bestpath, "asPath", "ignore");
7647
7648 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7649 json_object_string_add(bestpath, "asPath", "confed");
7650
7651 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7652 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7653 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7654 "as-set");
7655 else
a4d82a8a 7656 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7657 "true");
7658 } else
a4d82a8a 7659 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7660
7661 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7662 json_object_string_add(bestpath, "compareRouterId", "true");
7663 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7664 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7665 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7666 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7667 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7668 json_object_string_add(bestpath, "med",
7669 "missing-as-worst");
7670 else
7671 json_object_string_add(bestpath, "med", "true");
7672 }
7673
7674 json_object_object_add(json, "bestPath", bestpath);
7675}
7676
718e3744 7677/* Show BGP peer's summary information. */
d62a17ae 7678static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9f049418 7679 bool use_json, json_object *json)
d62a17ae 7680{
7681 struct peer *peer;
7682 struct listnode *node, *nnode;
7683 unsigned int count = 0, dn_count = 0;
7684 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7685 char neighbor_buf[VTY_BUFSIZ];
7686 int neighbor_col_default_width = 16;
7687 int len;
7688 int max_neighbor_width = 0;
7689 int pfx_rcd_safi;
7690 json_object *json_peer = NULL;
7691 json_object *json_peers = NULL;
37d4e0df 7692 struct peer_af *paf;
d62a17ae 7693
7694 /* labeled-unicast routes are installed in the unicast table so in order
7695 * to
7696 * display the correct PfxRcd value we must look at SAFI_UNICAST
7697 */
7698 if (safi == SAFI_LABELED_UNICAST)
7699 pfx_rcd_safi = SAFI_UNICAST;
7700 else
7701 pfx_rcd_safi = safi;
7702
7703 if (use_json) {
7704 if (json == NULL)
7705 json = json_object_new_object();
7706
7707 json_peers = json_object_new_object();
7708 } else {
7709 /* Loop over all neighbors that will be displayed to determine
7710 * how many
7711 * characters are needed for the Neighbor column
7712 */
7713 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7714 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7715 continue;
7716
7717 if (peer->afc[afi][safi]) {
7718 memset(dn_flag, '\0', sizeof(dn_flag));
7719 if (peer_dynamic_neighbor(peer))
7720 dn_flag[0] = '*';
7721
7722 if (peer->hostname
7723 && bgp_flag_check(bgp,
7724 BGP_FLAG_SHOW_HOSTNAME))
7725 sprintf(neighbor_buf, "%s%s(%s) ",
7726 dn_flag, peer->hostname,
7727 peer->host);
7728 else
7729 sprintf(neighbor_buf, "%s%s ", dn_flag,
7730 peer->host);
7731
7732 len = strlen(neighbor_buf);
7733
7734 if (len > max_neighbor_width)
7735 max_neighbor_width = len;
7736 }
7737 }
f933309e 7738
d62a17ae 7739 /* Originally we displayed the Neighbor column as 16
7740 * characters wide so make that the default
7741 */
7742 if (max_neighbor_width < neighbor_col_default_width)
7743 max_neighbor_width = neighbor_col_default_width;
7744 }
f933309e 7745
d62a17ae 7746 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7747 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7748 continue;
7749
ea47320b
DL
7750 if (!peer->afc[afi][safi])
7751 continue;
d62a17ae 7752
ea47320b
DL
7753 if (!count) {
7754 unsigned long ents;
7755 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7756 int64_t vrf_id_ui;
d62a17ae 7757
a4d82a8a
PZ
7758 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7759 ? -1
7760 : (int64_t)bgp->vrf_id;
ea47320b
DL
7761
7762 /* Usage summary and header */
7763 if (use_json) {
7764 json_object_string_add(
7765 json, "routerId",
7766 inet_ntoa(bgp->router_id));
60466a63
QY
7767 json_object_int_add(json, "as", bgp->as);
7768 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7769 json_object_string_add(
7770 json, "vrfName",
7771 (bgp->inst_type
7772 == BGP_INSTANCE_TYPE_DEFAULT)
7773 ? "Default"
7774 : bgp->name);
7775 } else {
7776 vty_out(vty,
7777 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7778 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7779 bgp->vrf_id == VRF_UNKNOWN
7780 ? -1
7781 : (int)bgp->vrf_id);
ea47320b
DL
7782 vty_out(vty, "\n");
7783 }
d62a17ae 7784
ea47320b 7785 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7786 if (use_json) {
ea47320b 7787 json_object_int_add(
60466a63 7788 json, "updateDelayLimit",
ea47320b 7789 bgp->v_update_delay);
d62a17ae 7790
ea47320b
DL
7791 if (bgp->v_update_delay
7792 != bgp->v_establish_wait)
d62a17ae 7793 json_object_int_add(
7794 json,
ea47320b
DL
7795 "updateDelayEstablishWait",
7796 bgp->v_establish_wait);
d62a17ae 7797
60466a63 7798 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7799 json_object_string_add(
7800 json,
7801 "updateDelayFirstNeighbor",
7802 bgp->update_delay_begin_time);
7803 json_object_boolean_true_add(
7804 json,
7805 "updateDelayInProgress");
7806 } else {
7807 if (bgp->update_delay_over) {
d62a17ae 7808 json_object_string_add(
7809 json,
7810 "updateDelayFirstNeighbor",
7811 bgp->update_delay_begin_time);
ea47320b 7812 json_object_string_add(
d62a17ae 7813 json,
ea47320b
DL
7814 "updateDelayBestpathResumed",
7815 bgp->update_delay_end_time);
7816 json_object_string_add(
d62a17ae 7817 json,
ea47320b
DL
7818 "updateDelayZebraUpdateResume",
7819 bgp->update_delay_zebra_resume_time);
7820 json_object_string_add(
7821 json,
7822 "updateDelayPeerUpdateResume",
7823 bgp->update_delay_peers_resume_time);
d62a17ae 7824 }
ea47320b
DL
7825 }
7826 } else {
7827 vty_out(vty,
7828 "Read-only mode update-delay limit: %d seconds\n",
7829 bgp->v_update_delay);
7830 if (bgp->v_update_delay
7831 != bgp->v_establish_wait)
d62a17ae 7832 vty_out(vty,
ea47320b
DL
7833 " Establish wait: %d seconds\n",
7834 bgp->v_establish_wait);
d62a17ae 7835
60466a63 7836 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7837 vty_out(vty,
7838 " First neighbor established: %s\n",
7839 bgp->update_delay_begin_time);
7840 vty_out(vty,
7841 " Delay in progress\n");
7842 } else {
7843 if (bgp->update_delay_over) {
d62a17ae 7844 vty_out(vty,
7845 " First neighbor established: %s\n",
7846 bgp->update_delay_begin_time);
7847 vty_out(vty,
ea47320b
DL
7848 " Best-paths resumed: %s\n",
7849 bgp->update_delay_end_time);
7850 vty_out(vty,
7851 " zebra update resumed: %s\n",
7852 bgp->update_delay_zebra_resume_time);
7853 vty_out(vty,
7854 " peers update resumed: %s\n",
7855 bgp->update_delay_peers_resume_time);
d62a17ae 7856 }
7857 }
7858 }
ea47320b 7859 }
d62a17ae 7860
ea47320b
DL
7861 if (use_json) {
7862 if (bgp_maxmed_onstartup_configured(bgp)
7863 && bgp->maxmed_active)
7864 json_object_boolean_true_add(
60466a63 7865 json, "maxMedOnStartup");
ea47320b
DL
7866 if (bgp->v_maxmed_admin)
7867 json_object_boolean_true_add(
60466a63 7868 json, "maxMedAdministrative");
d62a17ae 7869
ea47320b
DL
7870 json_object_int_add(
7871 json, "tableVersion",
60466a63 7872 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7873
60466a63
QY
7874 ents = bgp_table_count(bgp->rib[afi][safi]);
7875 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7876 json_object_int_add(
7877 json, "ribMemory",
7878 ents * sizeof(struct bgp_node));
d62a17ae 7879
ea47320b 7880 ents = listcount(bgp->peer);
60466a63
QY
7881 json_object_int_add(json, "peerCount", ents);
7882 json_object_int_add(json, "peerMemory",
7883 ents * sizeof(struct peer));
d62a17ae 7884
ea47320b
DL
7885 if ((ents = listcount(bgp->group))) {
7886 json_object_int_add(
60466a63 7887 json, "peerGroupCount", ents);
ea47320b
DL
7888 json_object_int_add(
7889 json, "peerGroupMemory",
996c9314
LB
7890 ents * sizeof(struct
7891 peer_group));
ea47320b 7892 }
d62a17ae 7893
ea47320b
DL
7894 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7895 BGP_CONFIG_DAMPENING))
7896 json_object_boolean_true_add(
60466a63 7897 json, "dampeningEnabled");
ea47320b
DL
7898 } else {
7899 if (bgp_maxmed_onstartup_configured(bgp)
7900 && bgp->maxmed_active)
d62a17ae 7901 vty_out(vty,
ea47320b
DL
7902 "Max-med on-startup active\n");
7903 if (bgp->v_maxmed_admin)
d62a17ae 7904 vty_out(vty,
ea47320b 7905 "Max-med administrative active\n");
d62a17ae 7906
60466a63
QY
7907 vty_out(vty, "BGP table version %" PRIu64 "\n",
7908 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7909
60466a63 7910 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7911 vty_out(vty,
7912 "RIB entries %ld, using %s of memory\n",
7913 ents,
996c9314
LB
7914 mtype_memstr(memstrbuf,
7915 sizeof(memstrbuf),
7916 ents * sizeof(struct
7917 bgp_node)));
ea47320b
DL
7918
7919 /* Peer related usage */
7920 ents = listcount(bgp->peer);
60466a63 7921 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7922 ents,
7923 mtype_memstr(
60466a63
QY
7924 memstrbuf, sizeof(memstrbuf),
7925 ents * sizeof(struct peer)));
ea47320b
DL
7926
7927 if ((ents = listcount(bgp->group)))
d62a17ae 7928 vty_out(vty,
ea47320b 7929 "Peer groups %ld, using %s of memory\n",
d62a17ae 7930 ents,
7931 mtype_memstr(
7932 memstrbuf,
7933 sizeof(memstrbuf),
996c9314
LB
7934 ents * sizeof(struct
7935 peer_group)));
d62a17ae 7936
ea47320b
DL
7937 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7938 BGP_CONFIG_DAMPENING))
60466a63 7939 vty_out(vty, "Dampening enabled.\n");
ea47320b 7940 vty_out(vty, "\n");
d62a17ae 7941
ea47320b
DL
7942 /* Subtract 8 here because 'Neighbor' is
7943 * 8 characters */
7944 vty_out(vty, "Neighbor");
60466a63
QY
7945 vty_out(vty, "%*s", max_neighbor_width - 8,
7946 " ");
ea47320b
DL
7947 vty_out(vty,
7948 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7949 }
ea47320b 7950 }
d62a17ae 7951
ea47320b 7952 count++;
d62a17ae 7953
ea47320b
DL
7954 if (use_json) {
7955 json_peer = json_object_new_object();
d62a17ae 7956
b4e9dcba
DD
7957 if (peer_dynamic_neighbor(peer)) {
7958 dn_count++;
60466a63
QY
7959 json_object_boolean_true_add(json_peer,
7960 "dynamicPeer");
b4e9dcba 7961 }
d62a17ae 7962
ea47320b 7963 if (peer->hostname)
60466a63 7964 json_object_string_add(json_peer, "hostname",
ea47320b 7965 peer->hostname);
d62a17ae 7966
ea47320b 7967 if (peer->domainname)
60466a63
QY
7968 json_object_string_add(json_peer, "domainname",
7969 peer->domainname);
d62a17ae 7970
60466a63 7971 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7972 json_object_int_add(json_peer, "version", 4);
60466a63 7973 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7974 PEER_TOTAL_RX(peer));
60466a63 7975 json_object_int_add(json_peer, "msgSent",
0112e9e0 7976 PEER_TOTAL_TX(peer));
ea47320b
DL
7977
7978 json_object_int_add(json_peer, "tableVersion",
7979 peer->version[afi][safi]);
7980 json_object_int_add(json_peer, "outq",
7981 peer->obuf->count);
7982 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7983 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7984 use_json, json_peer);
7985 json_object_int_add(json_peer, "prefixReceivedCount",
7986 peer->pcount[afi][pfx_rcd_safi]);
37d4e0df
AD
7987 paf = peer_af_find(peer, afi, pfx_rcd_safi);
7988 if (paf && PAF_SUBGRP(paf))
7989 json_object_int_add(json_peer,
7990 "pfxSnt",
7991 (PAF_SUBGRP(paf))->scount);
d62a17ae 7992
ea47320b 7993 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7994 json_object_string_add(json_peer, "state",
ea47320b 7995 "Idle (Admin)");
9199a725
TM
7996 else if (peer->afc_recv[afi][safi])
7997 json_object_string_add(
7998 json_peer, "state",
7999 lookup_msg(bgp_status_msg, peer->status,
8000 NULL));
60466a63
QY
8001 else if (CHECK_FLAG(peer->sflags,
8002 PEER_STATUS_PREFIX_OVERFLOW))
8003 json_object_string_add(json_peer, "state",
ea47320b
DL
8004 "Idle (PfxCt)");
8005 else
8006 json_object_string_add(
8007 json_peer, "state",
60466a63
QY
8008 lookup_msg(bgp_status_msg, peer->status,
8009 NULL));
ea47320b
DL
8010
8011 if (peer->conf_if)
60466a63 8012 json_object_string_add(json_peer, "idType",
ea47320b
DL
8013 "interface");
8014 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8015 json_object_string_add(json_peer, "idType",
8016 "ipv4");
ea47320b 8017 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8018 json_object_string_add(json_peer, "idType",
8019 "ipv6");
d62a17ae 8020
ea47320b
DL
8021 json_object_object_add(json_peers, peer->host,
8022 json_peer);
8023 } else {
8024 memset(dn_flag, '\0', sizeof(dn_flag));
8025 if (peer_dynamic_neighbor(peer)) {
8026 dn_count++;
8027 dn_flag[0] = '*';
8028 }
d62a17ae 8029
ea47320b 8030 if (peer->hostname
60466a63 8031 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 8032 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 8033 peer->hostname, peer->host);
ea47320b 8034 else
60466a63 8035 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
8036
8037 /* pad the neighbor column with spaces */
8038 if (len < max_neighbor_width)
60466a63
QY
8039 vty_out(vty, "%*s", max_neighbor_width - len,
8040 " ");
ea47320b 8041
86a55b99 8042 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
8043 peer->as, PEER_TOTAL_RX(peer),
8044 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8045 0, peer->obuf->count,
d62a17ae 8046 peer_uptime(peer->uptime, timebuf,
ea47320b 8047 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8048
ea47320b 8049 if (peer->status == Established)
2f8f4f10 8050 if (peer->afc_recv[afi][safi])
95077abf 8051 vty_out(vty, " %12ld",
a4d82a8a
PZ
8052 peer->pcount[afi]
8053 [pfx_rcd_safi]);
95077abf
DW
8054 else
8055 vty_out(vty, " NoNeg");
ea47320b 8056 else {
60466a63 8057 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8058 vty_out(vty, " Idle (Admin)");
60466a63
QY
8059 else if (CHECK_FLAG(
8060 peer->sflags,
8061 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8062 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8063 else
ea47320b 8064 vty_out(vty, " %12s",
60466a63
QY
8065 lookup_msg(bgp_status_msg,
8066 peer->status, NULL));
d62a17ae 8067 }
ea47320b 8068 vty_out(vty, "\n");
d62a17ae 8069 }
8070 }
f933309e 8071
d62a17ae 8072 if (use_json) {
8073 json_object_object_add(json, "peers", json_peers);
8074
8075 json_object_int_add(json, "totalPeers", count);
8076 json_object_int_add(json, "dynamicPeers", dn_count);
8077
57a9c8a8
DS
8078 bgp_show_bestpath_json(bgp, json);
8079
996c9314
LB
8080 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8081 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8082 json_object_free(json);
8083 } else {
8084 if (count)
8085 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8086 else {
d6ceaca3 8087 vty_out(vty, "No %s neighbor is configured\n",
8088 afi_safi_print(afi, safi));
d62a17ae 8089 }
b05a1c8b 8090
d6ceaca3 8091 if (dn_count) {
d62a17ae 8092 vty_out(vty, "* - dynamic neighbor\n");
8093 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8094 dn_count, bgp->dynamic_neighbors_limit);
8095 }
8096 }
1ff9a340 8097
d62a17ae 8098 return CMD_SUCCESS;
718e3744 8099}
8100
d62a17ae 8101static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9f049418 8102 int safi, bool use_json,
d62a17ae 8103 json_object *json)
8104{
8105 int is_first = 1;
8106 int afi_wildcard = (afi == AFI_MAX);
8107 int safi_wildcard = (safi == SAFI_MAX);
8108 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8109 bool nbr_output = false;
d62a17ae 8110
8111 if (use_json && is_wildcard)
8112 vty_out(vty, "{\n");
8113 if (afi_wildcard)
8114 afi = 1; /* AFI_IP */
8115 while (afi < AFI_MAX) {
8116 if (safi_wildcard)
8117 safi = 1; /* SAFI_UNICAST */
8118 while (safi < SAFI_MAX) {
318cac96 8119 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8120 nbr_output = true;
d62a17ae 8121 if (is_wildcard) {
8122 /*
8123 * So limit output to those afi/safi
8124 * pairs that
8125 * actualy have something interesting in
8126 * them
8127 */
8128 if (use_json) {
8129 json = json_object_new_object();
8130
8131 if (!is_first)
8132 vty_out(vty, ",\n");
8133 else
8134 is_first = 0;
8135
8136 vty_out(vty, "\"%s\":",
8137 afi_safi_json(afi,
8138 safi));
8139 } else {
8140 vty_out(vty, "\n%s Summary:\n",
8141 afi_safi_print(afi,
8142 safi));
8143 }
8144 }
8145 bgp_show_summary(vty, bgp, afi, safi, use_json,
8146 json);
8147 }
8148 safi++;
d62a17ae 8149 if (!safi_wildcard)
8150 safi = SAFI_MAX;
8151 }
8152 afi++;
ee851c8c 8153 if (!afi_wildcard)
d62a17ae 8154 afi = AFI_MAX;
8155 }
8156
8157 if (use_json && is_wildcard)
8158 vty_out(vty, "}\n");
ca61fd25
DS
8159 else if (!nbr_output) {
8160 if (use_json)
8161 vty_out(vty, "{}\n");
8162 else
8163 vty_out(vty, "%% No BGP neighbors found\n");
8164 }
d62a17ae 8165}
8166
8167static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9f049418 8168 safi_t safi, bool use_json)
d62a17ae 8169{
8170 struct listnode *node, *nnode;
8171 struct bgp *bgp;
8172 json_object *json = NULL;
8173 int is_first = 1;
9f049418 8174 bool nbr_output = false;
d62a17ae 8175
8176 if (use_json)
8177 vty_out(vty, "{\n");
8178
8179 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8180 nbr_output = true;
d62a17ae 8181 if (use_json) {
8182 json = json_object_new_object();
8183
8184 if (!is_first)
8185 vty_out(vty, ",\n");
8186 else
8187 is_first = 0;
8188
8189 vty_out(vty, "\"%s\":",
8190 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8191 ? "Default"
8192 : bgp->name);
8193 } else {
8194 vty_out(vty, "\nInstance %s:\n",
8195 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8196 ? "Default"
8197 : bgp->name);
8198 }
8199 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8200 }
8201
8202 if (use_json)
8203 vty_out(vty, "}\n");
9f049418
DS
8204 else if (!nbr_output)
8205 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8206}
8207
8208int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9f049418 8209 safi_t safi, bool use_json)
d62a17ae 8210{
8211 struct bgp *bgp;
8212
8213 if (name) {
8214 if (strmatch(name, "all")) {
8215 bgp_show_all_instances_summary_vty(vty, afi, safi,
8216 use_json);
8217 return CMD_SUCCESS;
8218 } else {
8219 bgp = bgp_lookup_by_name(name);
8220
8221 if (!bgp) {
8222 if (use_json)
8223 vty_out(vty, "{}\n");
8224 else
8225 vty_out(vty,
ca61fd25 8226 "%% BGP instance not found\n");
d62a17ae 8227 return CMD_WARNING;
8228 }
8229
8230 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8231 NULL);
8232 return CMD_SUCCESS;
8233 }
8234 }
8235
8236 bgp = bgp_get_default();
8237
8238 if (bgp)
8239 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
9f049418 8240 else {
ca61fd25
DS
8241 if (use_json)
8242 vty_out(vty, "{}\n");
8243 else
8244 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8245 return CMD_WARNING;
8246 }
d62a17ae 8247
8248 return CMD_SUCCESS;
4fb25c53
DW
8249}
8250
716b2d8a 8251/* `show [ip] bgp summary' commands. */
47fc97cc 8252DEFUN (show_ip_bgp_summary,
718e3744 8253 show_ip_bgp_summary_cmd,
dd6bd0f1 8254 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8255 SHOW_STR
8256 IP_STR
8257 BGP_STR
8386ac43 8258 BGP_INSTANCE_HELP_STR
46f296b4 8259 BGP_AFI_HELP_STR
dd6bd0f1 8260 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8261 "Summary of BGP neighbor status\n"
9973d184 8262 JSON_STR)
718e3744 8263{
d62a17ae 8264 char *vrf = NULL;
8265 afi_t afi = AFI_MAX;
8266 safi_t safi = SAFI_MAX;
8267
8268 int idx = 0;
8269
8270 /* show [ip] bgp */
8271 if (argv_find(argv, argc, "ip", &idx))
8272 afi = AFI_IP;
9a8bdf1c
PG
8273 /* [<vrf> VIEWVRFNAME] */
8274 if (argv_find(argv, argc, "vrf", &idx)) {
8275 vrf = argv[idx + 1]->arg;
8276 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8277 vrf = NULL;
8278 } else if (argv_find(argv, argc, "view", &idx))
8279 /* [<view> VIEWVRFNAME] */
8280 vrf = argv[idx + 1]->arg;
d62a17ae 8281 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8282 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8283 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8284 }
8285
9f049418 8286 bool uj = use_json(argc, argv);
d62a17ae 8287
8288 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8289}
8290
8291const char *afi_safi_print(afi_t afi, safi_t safi)
8292{
8293 if (afi == AFI_IP && safi == SAFI_UNICAST)
8294 return "IPv4 Unicast";
8295 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8296 return "IPv4 Multicast";
8297 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8298 return "IPv4 Labeled Unicast";
8299 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8300 return "IPv4 VPN";
8301 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8302 return "IPv4 Encap";
7c40bf39 8303 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8304 return "IPv4 Flowspec";
d62a17ae 8305 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8306 return "IPv6 Unicast";
8307 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8308 return "IPv6 Multicast";
8309 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8310 return "IPv6 Labeled Unicast";
8311 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8312 return "IPv6 VPN";
8313 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8314 return "IPv6 Encap";
7c40bf39 8315 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8316 return "IPv6 Flowspec";
d62a17ae 8317 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8318 return "L2VPN EVPN";
8319 else
8320 return "Unknown";
538621f2 8321}
8322
b9f77ec8
DS
8323/*
8324 * Please note that we have intentionally camelCased
8325 * the return strings here. So if you want
8326 * to use this function, please ensure you
8327 * are doing this within json output
8328 */
d62a17ae 8329const char *afi_safi_json(afi_t afi, safi_t safi)
8330{
8331 if (afi == AFI_IP && safi == SAFI_UNICAST)
8332 return "ipv4Unicast";
8333 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8334 return "ipv4Multicast";
8335 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8336 return "ipv4LabeledUnicast";
8337 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8338 return "ipv4Vpn";
8339 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8340 return "ipv4Encap";
7c40bf39 8341 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8342 return "ipv4Flowspec";
d62a17ae 8343 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8344 return "ipv6Unicast";
8345 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8346 return "ipv6Multicast";
8347 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8348 return "ipv6LabeledUnicast";
8349 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8350 return "ipv6Vpn";
8351 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8352 return "ipv6Encap";
7c40bf39 8353 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8354 return "ipv6Flowspec";
d62a17ae 8355 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8356 return "l2VpnEvpn";
8357 else
8358 return "Unknown";
27162734
LB
8359}
8360
718e3744 8361/* Show BGP peer's information. */
d62a17ae 8362enum show_type { show_all, show_peer };
8363
8364static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8365 afi_t afi, safi_t safi,
d7c0a89a
QY
8366 uint16_t adv_smcap, uint16_t adv_rmcap,
8367 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8368 bool use_json, json_object *json_pref)
d62a17ae 8369{
8370 /* Send-Mode */
8371 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8372 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8373 if (use_json) {
8374 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8375 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8376 json_object_string_add(json_pref, "sendMode",
8377 "advertisedAndReceived");
8378 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8379 json_object_string_add(json_pref, "sendMode",
8380 "advertised");
8381 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8382 json_object_string_add(json_pref, "sendMode",
8383 "received");
8384 } else {
8385 vty_out(vty, " Send-mode: ");
8386 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8387 vty_out(vty, "advertised");
8388 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8389 vty_out(vty, "%sreceived",
8390 CHECK_FLAG(p->af_cap[afi][safi],
8391 adv_smcap)
8392 ? ", "
8393 : "");
8394 vty_out(vty, "\n");
8395 }
8396 }
8397
8398 /* Receive-Mode */
8399 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8400 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8401 if (use_json) {
8402 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8403 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8404 json_object_string_add(json_pref, "recvMode",
8405 "advertisedAndReceived");
8406 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8407 json_object_string_add(json_pref, "recvMode",
8408 "advertised");
8409 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8410 json_object_string_add(json_pref, "recvMode",
8411 "received");
8412 } else {
8413 vty_out(vty, " Receive-mode: ");
8414 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8415 vty_out(vty, "advertised");
8416 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8417 vty_out(vty, "%sreceived",
8418 CHECK_FLAG(p->af_cap[afi][safi],
8419 adv_rmcap)
8420 ? ", "
8421 : "");
8422 vty_out(vty, "\n");
8423 }
8424 }
8425}
8426
8427static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8428 safi_t safi, bool use_json,
d62a17ae 8429 json_object *json_neigh)
8430{
0291c246
MK
8431 struct bgp_filter *filter;
8432 struct peer_af *paf;
8433 char orf_pfx_name[BUFSIZ];
8434 int orf_pfx_count;
8435 json_object *json_af = NULL;
8436 json_object *json_prefA = NULL;
8437 json_object *json_prefB = NULL;
8438 json_object *json_addr = NULL;
d62a17ae 8439
8440 if (use_json) {
8441 json_addr = json_object_new_object();
8442 json_af = json_object_new_object();
8443 filter = &p->filter[afi][safi];
8444
8445 if (peer_group_active(p))
8446 json_object_string_add(json_addr, "peerGroupMember",
8447 p->group->name);
8448
8449 paf = peer_af_find(p, afi, safi);
8450 if (paf && PAF_SUBGRP(paf)) {
8451 json_object_int_add(json_addr, "updateGroupId",
8452 PAF_UPDGRP(paf)->id);
8453 json_object_int_add(json_addr, "subGroupId",
8454 PAF_SUBGRP(paf)->id);
8455 json_object_int_add(json_addr, "packetQueueLength",
8456 bpacket_queue_virtual_length(paf));
8457 }
8458
8459 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8460 || CHECK_FLAG(p->af_cap[afi][safi],
8461 PEER_CAP_ORF_PREFIX_SM_RCV)
8462 || CHECK_FLAG(p->af_cap[afi][safi],
8463 PEER_CAP_ORF_PREFIX_RM_ADV)
8464 || CHECK_FLAG(p->af_cap[afi][safi],
8465 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8466 json_object_int_add(json_af, "orfType",
8467 ORF_TYPE_PREFIX);
8468 json_prefA = json_object_new_object();
8469 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8470 PEER_CAP_ORF_PREFIX_SM_ADV,
8471 PEER_CAP_ORF_PREFIX_RM_ADV,
8472 PEER_CAP_ORF_PREFIX_SM_RCV,
8473 PEER_CAP_ORF_PREFIX_RM_RCV,
8474 use_json, json_prefA);
8475 json_object_object_add(json_af, "orfPrefixList",
8476 json_prefA);
8477 }
8478
8479 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8480 || CHECK_FLAG(p->af_cap[afi][safi],
8481 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8482 || CHECK_FLAG(p->af_cap[afi][safi],
8483 PEER_CAP_ORF_PREFIX_RM_ADV)
8484 || CHECK_FLAG(p->af_cap[afi][safi],
8485 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8486 json_object_int_add(json_af, "orfOldType",
8487 ORF_TYPE_PREFIX_OLD);
8488 json_prefB = json_object_new_object();
8489 bgp_show_peer_afi_orf_cap(
8490 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8491 PEER_CAP_ORF_PREFIX_RM_ADV,
8492 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8493 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8494 json_prefB);
8495 json_object_object_add(json_af, "orfOldPrefixList",
8496 json_prefB);
8497 }
8498
8499 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8500 || CHECK_FLAG(p->af_cap[afi][safi],
8501 PEER_CAP_ORF_PREFIX_SM_RCV)
8502 || CHECK_FLAG(p->af_cap[afi][safi],
8503 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8504 || CHECK_FLAG(p->af_cap[afi][safi],
8505 PEER_CAP_ORF_PREFIX_RM_ADV)
8506 || CHECK_FLAG(p->af_cap[afi][safi],
8507 PEER_CAP_ORF_PREFIX_RM_RCV)
8508 || CHECK_FLAG(p->af_cap[afi][safi],
8509 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8510 json_object_object_add(json_addr, "afDependentCap",
8511 json_af);
8512 else
8513 json_object_free(json_af);
8514
8515 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8516 orf_pfx_count = prefix_bgp_show_prefix_list(
8517 NULL, afi, orf_pfx_name, use_json);
8518
8519 if (CHECK_FLAG(p->af_sflags[afi][safi],
8520 PEER_STATUS_ORF_PREFIX_SEND)
8521 || orf_pfx_count) {
8522 if (CHECK_FLAG(p->af_sflags[afi][safi],
8523 PEER_STATUS_ORF_PREFIX_SEND))
8524 json_object_boolean_true_add(json_neigh,
8525 "orfSent");
8526 if (orf_pfx_count)
8527 json_object_int_add(json_addr, "orfRecvCounter",
8528 orf_pfx_count);
8529 }
8530 if (CHECK_FLAG(p->af_sflags[afi][safi],
8531 PEER_STATUS_ORF_WAIT_REFRESH))
8532 json_object_string_add(
8533 json_addr, "orfFirstUpdate",
8534 "deferredUntilORFOrRouteRefreshRecvd");
8535
8536 if (CHECK_FLAG(p->af_flags[afi][safi],
8537 PEER_FLAG_REFLECTOR_CLIENT))
8538 json_object_boolean_true_add(json_addr,
8539 "routeReflectorClient");
8540 if (CHECK_FLAG(p->af_flags[afi][safi],
8541 PEER_FLAG_RSERVER_CLIENT))
8542 json_object_boolean_true_add(json_addr,
8543 "routeServerClient");
8544 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8545 json_object_boolean_true_add(json_addr,
8546 "inboundSoftConfigPermit");
8547
8548 if (CHECK_FLAG(p->af_flags[afi][safi],
8549 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8550 json_object_boolean_true_add(
8551 json_addr,
8552 "privateAsNumsAllReplacedInUpdatesToNbr");
8553 else if (CHECK_FLAG(p->af_flags[afi][safi],
8554 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8555 json_object_boolean_true_add(
8556 json_addr,
8557 "privateAsNumsReplacedInUpdatesToNbr");
8558 else if (CHECK_FLAG(p->af_flags[afi][safi],
8559 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8560 json_object_boolean_true_add(
8561 json_addr,
8562 "privateAsNumsAllRemovedInUpdatesToNbr");
8563 else if (CHECK_FLAG(p->af_flags[afi][safi],
8564 PEER_FLAG_REMOVE_PRIVATE_AS))
8565 json_object_boolean_true_add(
8566 json_addr,
8567 "privateAsNumsRemovedInUpdatesToNbr");
8568
8569 if (CHECK_FLAG(p->af_flags[afi][safi],
8570 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8571 json_object_boolean_true_add(json_addr,
8572 "addpathTxAllPaths");
8573
8574 if (CHECK_FLAG(p->af_flags[afi][safi],
8575 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8576 json_object_boolean_true_add(json_addr,
8577 "addpathTxBestpathPerAS");
8578
8579 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8580 json_object_string_add(json_addr,
8581 "overrideASNsInOutboundUpdates",
8582 "ifAspathEqualRemoteAs");
8583
8584 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8585 || CHECK_FLAG(p->af_flags[afi][safi],
8586 PEER_FLAG_FORCE_NEXTHOP_SELF))
8587 json_object_boolean_true_add(json_addr,
8588 "routerAlwaysNextHop");
8589 if (CHECK_FLAG(p->af_flags[afi][safi],
8590 PEER_FLAG_AS_PATH_UNCHANGED))
8591 json_object_boolean_true_add(
8592 json_addr, "unchangedAsPathPropogatedToNbr");
8593 if (CHECK_FLAG(p->af_flags[afi][safi],
8594 PEER_FLAG_NEXTHOP_UNCHANGED))
8595 json_object_boolean_true_add(
8596 json_addr, "unchangedNextHopPropogatedToNbr");
8597 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8598 json_object_boolean_true_add(
8599 json_addr, "unchangedMedPropogatedToNbr");
8600 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8601 || CHECK_FLAG(p->af_flags[afi][safi],
8602 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8603 if (CHECK_FLAG(p->af_flags[afi][safi],
8604 PEER_FLAG_SEND_COMMUNITY)
8605 && CHECK_FLAG(p->af_flags[afi][safi],
8606 PEER_FLAG_SEND_EXT_COMMUNITY))
8607 json_object_string_add(json_addr,
8608 "commAttriSentToNbr",
8609 "extendedAndStandard");
8610 else if (CHECK_FLAG(p->af_flags[afi][safi],
8611 PEER_FLAG_SEND_EXT_COMMUNITY))
8612 json_object_string_add(json_addr,
8613 "commAttriSentToNbr",
8614 "extended");
8615 else
8616 json_object_string_add(json_addr,
8617 "commAttriSentToNbr",
8618 "standard");
8619 }
8620 if (CHECK_FLAG(p->af_flags[afi][safi],
8621 PEER_FLAG_DEFAULT_ORIGINATE)) {
8622 if (p->default_rmap[afi][safi].name)
8623 json_object_string_add(
8624 json_addr, "defaultRouteMap",
8625 p->default_rmap[afi][safi].name);
8626
8627 if (paf && PAF_SUBGRP(paf)
8628 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8629 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8630 json_object_boolean_true_add(json_addr,
8631 "defaultSent");
8632 else
8633 json_object_boolean_true_add(json_addr,
8634 "defaultNotSent");
8635 }
8636
dff8f48d 8637 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8638 if (is_evpn_enabled())
60466a63
QY
8639 json_object_boolean_true_add(
8640 json_addr, "advertiseAllVnis");
dff8f48d
MK
8641 }
8642
d62a17ae 8643 if (filter->plist[FILTER_IN].name
8644 || filter->dlist[FILTER_IN].name
8645 || filter->aslist[FILTER_IN].name
8646 || filter->map[RMAP_IN].name)
8647 json_object_boolean_true_add(json_addr,
8648 "inboundPathPolicyConfig");
8649 if (filter->plist[FILTER_OUT].name
8650 || filter->dlist[FILTER_OUT].name
8651 || filter->aslist[FILTER_OUT].name
8652 || filter->map[RMAP_OUT].name || filter->usmap.name)
8653 json_object_boolean_true_add(
8654 json_addr, "outboundPathPolicyConfig");
8655
8656 /* prefix-list */
8657 if (filter->plist[FILTER_IN].name)
8658 json_object_string_add(json_addr,
8659 "incomingUpdatePrefixFilterList",
8660 filter->plist[FILTER_IN].name);
8661 if (filter->plist[FILTER_OUT].name)
8662 json_object_string_add(json_addr,
8663 "outgoingUpdatePrefixFilterList",
8664 filter->plist[FILTER_OUT].name);
8665
8666 /* distribute-list */
8667 if (filter->dlist[FILTER_IN].name)
8668 json_object_string_add(
8669 json_addr, "incomingUpdateNetworkFilterList",
8670 filter->dlist[FILTER_IN].name);
8671 if (filter->dlist[FILTER_OUT].name)
8672 json_object_string_add(
8673 json_addr, "outgoingUpdateNetworkFilterList",
8674 filter->dlist[FILTER_OUT].name);
8675
8676 /* filter-list. */
8677 if (filter->aslist[FILTER_IN].name)
8678 json_object_string_add(json_addr,
8679 "incomingUpdateAsPathFilterList",
8680 filter->aslist[FILTER_IN].name);
8681 if (filter->aslist[FILTER_OUT].name)
8682 json_object_string_add(json_addr,
8683 "outgoingUpdateAsPathFilterList",
8684 filter->aslist[FILTER_OUT].name);
8685
8686 /* route-map. */
8687 if (filter->map[RMAP_IN].name)
8688 json_object_string_add(
8689 json_addr, "routeMapForIncomingAdvertisements",
8690 filter->map[RMAP_IN].name);
8691 if (filter->map[RMAP_OUT].name)
8692 json_object_string_add(
8693 json_addr, "routeMapForOutgoingAdvertisements",
8694 filter->map[RMAP_OUT].name);
8695
8696 /* unsuppress-map */
8697 if (filter->usmap.name)
8698 json_object_string_add(json_addr,
8699 "selectiveUnsuppressRouteMap",
8700 filter->usmap.name);
8701
8702 /* Receive prefix count */
8703 json_object_int_add(json_addr, "acceptedPrefixCounter",
8704 p->pcount[afi][safi]);
37d4e0df
AD
8705 if (paf && PAF_SUBGRP(paf))
8706 json_object_int_add(json_addr, "sentPrefixCounter",
8707 (PAF_SUBGRP(paf))->scount);
d62a17ae 8708
8709 /* Maximum prefix */
8710 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8711 json_object_int_add(json_addr, "prefixAllowedMax",
8712 p->pmax[afi][safi]);
8713 if (CHECK_FLAG(p->af_flags[afi][safi],
8714 PEER_FLAG_MAX_PREFIX_WARNING))
8715 json_object_boolean_true_add(
8716 json_addr, "prefixAllowedMaxWarning");
8717 json_object_int_add(json_addr,
8718 "prefixAllowedWarningThresh",
8719 p->pmax_threshold[afi][safi]);
8720 if (p->pmax_restart[afi][safi])
8721 json_object_int_add(
8722 json_addr,
8723 "prefixAllowedRestartIntervalMsecs",
8724 p->pmax_restart[afi][safi] * 60000);
8725 }
8726 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8727 json_addr);
8728
8729 } else {
8730 filter = &p->filter[afi][safi];
8731
8732 vty_out(vty, " For address family: %s\n",
8733 afi_safi_print(afi, safi));
8734
8735 if (peer_group_active(p))
8736 vty_out(vty, " %s peer-group member\n",
8737 p->group->name);
8738
8739 paf = peer_af_find(p, afi, safi);
8740 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8741 vty_out(vty, " Update group %" PRIu64
8742 ", subgroup %" PRIu64 "\n",
d62a17ae 8743 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8744 vty_out(vty, " Packet Queue length %d\n",
8745 bpacket_queue_virtual_length(paf));
8746 } else {
8747 vty_out(vty, " Not part of any update group\n");
8748 }
8749 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8750 || CHECK_FLAG(p->af_cap[afi][safi],
8751 PEER_CAP_ORF_PREFIX_SM_RCV)
8752 || CHECK_FLAG(p->af_cap[afi][safi],
8753 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8754 || CHECK_FLAG(p->af_cap[afi][safi],
8755 PEER_CAP_ORF_PREFIX_RM_ADV)
8756 || CHECK_FLAG(p->af_cap[afi][safi],
8757 PEER_CAP_ORF_PREFIX_RM_RCV)
8758 || CHECK_FLAG(p->af_cap[afi][safi],
8759 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8760 vty_out(vty, " AF-dependant capabilities:\n");
8761
8762 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8763 || CHECK_FLAG(p->af_cap[afi][safi],
8764 PEER_CAP_ORF_PREFIX_SM_RCV)
8765 || CHECK_FLAG(p->af_cap[afi][safi],
8766 PEER_CAP_ORF_PREFIX_RM_ADV)
8767 || CHECK_FLAG(p->af_cap[afi][safi],
8768 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8769 vty_out(vty,
8770 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8771 ORF_TYPE_PREFIX);
8772 bgp_show_peer_afi_orf_cap(
8773 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8774 PEER_CAP_ORF_PREFIX_RM_ADV,
8775 PEER_CAP_ORF_PREFIX_SM_RCV,
8776 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8777 }
8778 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8779 || CHECK_FLAG(p->af_cap[afi][safi],
8780 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8781 || CHECK_FLAG(p->af_cap[afi][safi],
8782 PEER_CAP_ORF_PREFIX_RM_ADV)
8783 || CHECK_FLAG(p->af_cap[afi][safi],
8784 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8785 vty_out(vty,
8786 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8787 ORF_TYPE_PREFIX_OLD);
8788 bgp_show_peer_afi_orf_cap(
8789 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8790 PEER_CAP_ORF_PREFIX_RM_ADV,
8791 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8792 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8793 }
8794
8795 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8796 orf_pfx_count = prefix_bgp_show_prefix_list(
8797 NULL, afi, orf_pfx_name, use_json);
8798
8799 if (CHECK_FLAG(p->af_sflags[afi][safi],
8800 PEER_STATUS_ORF_PREFIX_SEND)
8801 || orf_pfx_count) {
8802 vty_out(vty, " Outbound Route Filter (ORF):");
8803 if (CHECK_FLAG(p->af_sflags[afi][safi],
8804 PEER_STATUS_ORF_PREFIX_SEND))
8805 vty_out(vty, " sent;");
8806 if (orf_pfx_count)
8807 vty_out(vty, " received (%d entries)",
8808 orf_pfx_count);
8809 vty_out(vty, "\n");
8810 }
8811 if (CHECK_FLAG(p->af_sflags[afi][safi],
8812 PEER_STATUS_ORF_WAIT_REFRESH))
8813 vty_out(vty,
8814 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8815
8816 if (CHECK_FLAG(p->af_flags[afi][safi],
8817 PEER_FLAG_REFLECTOR_CLIENT))
8818 vty_out(vty, " Route-Reflector Client\n");
8819 if (CHECK_FLAG(p->af_flags[afi][safi],
8820 PEER_FLAG_RSERVER_CLIENT))
8821 vty_out(vty, " Route-Server Client\n");
8822 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8823 vty_out(vty,
8824 " Inbound soft reconfiguration allowed\n");
8825
8826 if (CHECK_FLAG(p->af_flags[afi][safi],
8827 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8828 vty_out(vty,
8829 " Private AS numbers (all) replaced in updates to this neighbor\n");
8830 else if (CHECK_FLAG(p->af_flags[afi][safi],
8831 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8832 vty_out(vty,
8833 " Private AS numbers replaced in updates to this neighbor\n");
8834 else if (CHECK_FLAG(p->af_flags[afi][safi],
8835 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8836 vty_out(vty,
8837 " Private AS numbers (all) removed in updates to this neighbor\n");
8838 else if (CHECK_FLAG(p->af_flags[afi][safi],
8839 PEER_FLAG_REMOVE_PRIVATE_AS))
8840 vty_out(vty,
8841 " Private AS numbers removed in updates to this neighbor\n");
8842
8843 if (CHECK_FLAG(p->af_flags[afi][safi],
8844 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8845 vty_out(vty, " Advertise all paths via addpath\n");
8846
8847 if (CHECK_FLAG(p->af_flags[afi][safi],
8848 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8849 vty_out(vty,
8850 " Advertise bestpath per AS via addpath\n");
8851
8852 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8853 vty_out(vty,
8854 " Override ASNs in outbound updates if aspath equals remote-as\n");
8855
8856 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8857 || CHECK_FLAG(p->af_flags[afi][safi],
8858 PEER_FLAG_FORCE_NEXTHOP_SELF))
8859 vty_out(vty, " NEXT_HOP is always this router\n");
8860 if (CHECK_FLAG(p->af_flags[afi][safi],
8861 PEER_FLAG_AS_PATH_UNCHANGED))
8862 vty_out(vty,
8863 " AS_PATH is propagated unchanged to this neighbor\n");
8864 if (CHECK_FLAG(p->af_flags[afi][safi],
8865 PEER_FLAG_NEXTHOP_UNCHANGED))
8866 vty_out(vty,
8867 " NEXT_HOP is propagated unchanged to this neighbor\n");
8868 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8869 vty_out(vty,
8870 " MED is propagated unchanged to this neighbor\n");
8871 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8872 || CHECK_FLAG(p->af_flags[afi][safi],
8873 PEER_FLAG_SEND_EXT_COMMUNITY)
8874 || CHECK_FLAG(p->af_flags[afi][safi],
8875 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8876 vty_out(vty,
8877 " Community attribute sent to this neighbor");
8878 if (CHECK_FLAG(p->af_flags[afi][safi],
8879 PEER_FLAG_SEND_COMMUNITY)
8880 && CHECK_FLAG(p->af_flags[afi][safi],
8881 PEER_FLAG_SEND_EXT_COMMUNITY)
8882 && CHECK_FLAG(p->af_flags[afi][safi],
8883 PEER_FLAG_SEND_LARGE_COMMUNITY))
8884 vty_out(vty, "(all)\n");
8885 else if (CHECK_FLAG(p->af_flags[afi][safi],
8886 PEER_FLAG_SEND_LARGE_COMMUNITY))
8887 vty_out(vty, "(large)\n");
8888 else if (CHECK_FLAG(p->af_flags[afi][safi],
8889 PEER_FLAG_SEND_EXT_COMMUNITY))
8890 vty_out(vty, "(extended)\n");
8891 else
8892 vty_out(vty, "(standard)\n");
8893 }
8894 if (CHECK_FLAG(p->af_flags[afi][safi],
8895 PEER_FLAG_DEFAULT_ORIGINATE)) {
8896 vty_out(vty, " Default information originate,");
8897
8898 if (p->default_rmap[afi][safi].name)
8899 vty_out(vty, " default route-map %s%s,",
8900 p->default_rmap[afi][safi].map ? "*"
8901 : "",
8902 p->default_rmap[afi][safi].name);
8903 if (paf && PAF_SUBGRP(paf)
8904 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8905 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8906 vty_out(vty, " default sent\n");
8907 else
8908 vty_out(vty, " default not sent\n");
8909 }
8910
dff8f48d
MK
8911 /* advertise-vni-all */
8912 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8913 if (is_evpn_enabled())
dff8f48d
MK
8914 vty_out(vty, " advertise-all-vni\n");
8915 }
8916
d62a17ae 8917 if (filter->plist[FILTER_IN].name
8918 || filter->dlist[FILTER_IN].name
8919 || filter->aslist[FILTER_IN].name
8920 || filter->map[RMAP_IN].name)
8921 vty_out(vty, " Inbound path policy configured\n");
8922 if (filter->plist[FILTER_OUT].name
8923 || filter->dlist[FILTER_OUT].name
8924 || filter->aslist[FILTER_OUT].name
8925 || filter->map[RMAP_OUT].name || filter->usmap.name)
8926 vty_out(vty, " Outbound path policy configured\n");
8927
8928 /* prefix-list */
8929 if (filter->plist[FILTER_IN].name)
8930 vty_out(vty,
8931 " Incoming update prefix filter list is %s%s\n",
8932 filter->plist[FILTER_IN].plist ? "*" : "",
8933 filter->plist[FILTER_IN].name);
8934 if (filter->plist[FILTER_OUT].name)
8935 vty_out(vty,
8936 " Outgoing update prefix filter list is %s%s\n",
8937 filter->plist[FILTER_OUT].plist ? "*" : "",
8938 filter->plist[FILTER_OUT].name);
8939
8940 /* distribute-list */
8941 if (filter->dlist[FILTER_IN].name)
8942 vty_out(vty,
8943 " Incoming update network filter list is %s%s\n",
8944 filter->dlist[FILTER_IN].alist ? "*" : "",
8945 filter->dlist[FILTER_IN].name);
8946 if (filter->dlist[FILTER_OUT].name)
8947 vty_out(vty,
8948 " Outgoing update network filter list is %s%s\n",
8949 filter->dlist[FILTER_OUT].alist ? "*" : "",
8950 filter->dlist[FILTER_OUT].name);
8951
8952 /* filter-list. */
8953 if (filter->aslist[FILTER_IN].name)
8954 vty_out(vty,
8955 " Incoming update AS path filter list is %s%s\n",
8956 filter->aslist[FILTER_IN].aslist ? "*" : "",
8957 filter->aslist[FILTER_IN].name);
8958 if (filter->aslist[FILTER_OUT].name)
8959 vty_out(vty,
8960 " Outgoing update AS path filter list is %s%s\n",
8961 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8962 filter->aslist[FILTER_OUT].name);
8963
8964 /* route-map. */
8965 if (filter->map[RMAP_IN].name)
8966 vty_out(vty,
8967 " Route map for incoming advertisements is %s%s\n",
8968 filter->map[RMAP_IN].map ? "*" : "",
8969 filter->map[RMAP_IN].name);
8970 if (filter->map[RMAP_OUT].name)
8971 vty_out(vty,
8972 " Route map for outgoing advertisements is %s%s\n",
8973 filter->map[RMAP_OUT].map ? "*" : "",
8974 filter->map[RMAP_OUT].name);
8975
8976 /* unsuppress-map */
8977 if (filter->usmap.name)
8978 vty_out(vty,
8979 " Route map for selective unsuppress is %s%s\n",
8980 filter->usmap.map ? "*" : "",
8981 filter->usmap.name);
8982
8983 /* Receive prefix count */
8984 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8985
8986 /* Maximum prefix */
8987 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8988 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8989 p->pmax[afi][safi],
8990 CHECK_FLAG(p->af_flags[afi][safi],
8991 PEER_FLAG_MAX_PREFIX_WARNING)
8992 ? " (warning-only)"
8993 : "");
8994 vty_out(vty, " Threshold for warning message %d%%",
8995 p->pmax_threshold[afi][safi]);
8996 if (p->pmax_restart[afi][safi])
8997 vty_out(vty, ", restart interval %d min",
8998 p->pmax_restart[afi][safi]);
8999 vty_out(vty, "\n");
9000 }
9001
9002 vty_out(vty, "\n");
9003 }
9004}
9005
9f049418 9006static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9007 json_object *json)
718e3744 9008{
d62a17ae 9009 struct bgp *bgp;
9010 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9011 char timebuf[BGP_UPTIME_LEN];
9012 char dn_flag[2];
9013 const char *subcode_str;
9014 const char *code_str;
9015 afi_t afi;
9016 safi_t safi;
d7c0a89a
QY
9017 uint16_t i;
9018 uint8_t *msg;
d62a17ae 9019 json_object *json_neigh = NULL;
9020 time_t epoch_tbuf;
718e3744 9021
d62a17ae 9022 bgp = p->bgp;
9023
9024 if (use_json)
9025 json_neigh = json_object_new_object();
9026
9027 memset(dn_flag, '\0', sizeof(dn_flag));
9028 if (!p->conf_if && peer_dynamic_neighbor(p))
9029 dn_flag[0] = '*';
9030
9031 if (!use_json) {
9032 if (p->conf_if) /* Configured interface name. */
9033 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9034 BGP_PEER_SU_UNSPEC(p)
9035 ? "None"
9036 : sockunion2str(&p->su, buf,
9037 SU_ADDRSTRLEN));
9038 else /* Configured IP address. */
9039 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9040 p->host);
9041 }
9042
9043 if (use_json) {
9044 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9045 json_object_string_add(json_neigh, "bgpNeighborAddr",
9046 "none");
9047 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9048 json_object_string_add(
9049 json_neigh, "bgpNeighborAddr",
9050 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9051
9052 json_object_int_add(json_neigh, "remoteAs", p->as);
9053
9054 if (p->change_local_as)
9055 json_object_int_add(json_neigh, "localAs",
9056 p->change_local_as);
9057 else
9058 json_object_int_add(json_neigh, "localAs", p->local_as);
9059
9060 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9061 json_object_boolean_true_add(json_neigh,
9062 "localAsNoPrepend");
9063
9064 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9065 json_object_boolean_true_add(json_neigh,
9066 "localAsReplaceAs");
9067 } else {
9068 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9069 || (p->as_type == AS_INTERNAL))
9070 vty_out(vty, "remote AS %u, ", p->as);
9071 else
9072 vty_out(vty, "remote AS Unspecified, ");
9073 vty_out(vty, "local AS %u%s%s, ",
9074 p->change_local_as ? p->change_local_as : p->local_as,
9075 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9076 ? " no-prepend"
9077 : "",
9078 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9079 ? " replace-as"
9080 : "");
9081 }
9082 /* peer type internal, external, confed-internal or confed-external */
9083 if (p->as == p->local_as) {
9084 if (use_json) {
9085 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9086 json_object_boolean_true_add(
9087 json_neigh, "nbrConfedInternalLink");
9088 else
9089 json_object_boolean_true_add(json_neigh,
9090 "nbrInternalLink");
9091 } else {
9092 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9093 vty_out(vty, "confed-internal link\n");
9094 else
9095 vty_out(vty, "internal link\n");
9096 }
9097 } else {
9098 if (use_json) {
9099 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9100 json_object_boolean_true_add(
9101 json_neigh, "nbrConfedExternalLink");
9102 else
9103 json_object_boolean_true_add(json_neigh,
9104 "nbrExternalLink");
9105 } else {
9106 if (bgp_confederation_peers_check(bgp, p->as))
9107 vty_out(vty, "confed-external link\n");
9108 else
9109 vty_out(vty, "external link\n");
9110 }
9111 }
9112
9113 /* Description. */
9114 if (p->desc) {
9115 if (use_json)
9116 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9117 else
9118 vty_out(vty, " Description: %s\n", p->desc);
9119 }
9120
9121 if (p->hostname) {
9122 if (use_json) {
9123 if (p->hostname)
9124 json_object_string_add(json_neigh, "hostname",
9125 p->hostname);
9126
9127 if (p->domainname)
9128 json_object_string_add(json_neigh, "domainname",
9129 p->domainname);
9130 } else {
9131 if (p->domainname && (p->domainname[0] != '\0'))
9132 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9133 p->domainname);
9134 else
9135 vty_out(vty, "Hostname: %s\n", p->hostname);
9136 }
9137 }
9138
9139 /* Peer-group */
9140 if (p->group) {
9141 if (use_json) {
9142 json_object_string_add(json_neigh, "peerGroup",
9143 p->group->name);
9144
9145 if (dn_flag[0]) {
9146 struct prefix prefix, *range = NULL;
9147
9148 sockunion2hostprefix(&(p->su), &prefix);
9149 range = peer_group_lookup_dynamic_neighbor_range(
9150 p->group, &prefix);
9151
9152 if (range) {
9153 prefix2str(range, buf1, sizeof(buf1));
9154 json_object_string_add(
9155 json_neigh,
9156 "peerSubnetRangeGroup", buf1);
9157 }
9158 }
9159 } else {
9160 vty_out(vty,
9161 " Member of peer-group %s for session parameters\n",
9162 p->group->name);
9163
9164 if (dn_flag[0]) {
9165 struct prefix prefix, *range = NULL;
9166
9167 sockunion2hostprefix(&(p->su), &prefix);
9168 range = peer_group_lookup_dynamic_neighbor_range(
9169 p->group, &prefix);
9170
9171 if (range) {
9172 prefix2str(range, buf1, sizeof(buf1));
9173 vty_out(vty,
9174 " Belongs to the subnet range group: %s\n",
9175 buf1);
9176 }
9177 }
9178 }
9179 }
9180
9181 if (use_json) {
9182 /* Administrative shutdown. */
9183 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9184 json_object_boolean_true_add(json_neigh,
9185 "adminShutDown");
9186
9187 /* BGP Version. */
9188 json_object_int_add(json_neigh, "bgpVersion", 4);
9189 json_object_string_add(
9190 json_neigh, "remoteRouterId",
9191 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9192 json_object_string_add(
9193 json_neigh, "localRouterId",
9194 inet_ntop(AF_INET, &bgp->router_id, buf1,
9195 sizeof(buf1)));
d62a17ae 9196
9197 /* Confederation */
9198 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9199 && bgp_confederation_peers_check(bgp, p->as))
9200 json_object_boolean_true_add(json_neigh,
9201 "nbrCommonAdmin");
9202
9203 /* Status. */
9204 json_object_string_add(
9205 json_neigh, "bgpState",
9206 lookup_msg(bgp_status_msg, p->status, NULL));
9207
9208 if (p->status == Established) {
9209 time_t uptime;
d62a17ae 9210
9211 uptime = bgp_clock();
9212 uptime -= p->uptime;
d62a17ae 9213 epoch_tbuf = time(NULL) - uptime;
9214
bee57a7a 9215#if CONFDATE > 20200101
a4d82a8a
PZ
9216 CPP_NOTICE(
9217 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9218#endif
9219 /*
9220 * bgpTimerUp was miliseconds that was accurate
9221 * up to 1 day, then the value returned
9222 * became garbage. So in order to provide
9223 * some level of backwards compatability,
9224 * we still provde the data, but now
9225 * we are returning the correct value
9226 * and also adding a new bgpTimerUpMsec
9227 * which will allow us to deprecate
9228 * this eventually
9229 */
d62a17ae 9230 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9231 uptime * 1000);
d3c7efed
DS
9232 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9233 uptime * 1000);
d62a17ae 9234 json_object_string_add(json_neigh, "bgpTimerUpString",
9235 peer_uptime(p->uptime, timebuf,
9236 BGP_UPTIME_LEN, 0,
9237 NULL));
9238 json_object_int_add(json_neigh,
9239 "bgpTimerUpEstablishedEpoch",
9240 epoch_tbuf);
9241 }
9242
9243 else if (p->status == Active) {
9244 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9245 json_object_string_add(json_neigh, "bgpStateIs",
9246 "passive");
9247 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9248 json_object_string_add(json_neigh, "bgpStateIs",
9249 "passiveNSF");
9250 }
9251
9252 /* read timer */
9253 time_t uptime;
9254 struct tm *tm;
9255
9256 uptime = bgp_clock();
9257 uptime -= p->readtime;
9258 tm = gmtime(&uptime);
9259 json_object_int_add(json_neigh, "bgpTimerLastRead",
9260 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9261 + (tm->tm_hour * 3600000));
9262
9263 uptime = bgp_clock();
9264 uptime -= p->last_write;
9265 tm = gmtime(&uptime);
9266 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9267 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9268 + (tm->tm_hour * 3600000));
9269
9270 uptime = bgp_clock();
9271 uptime -= p->update_time;
9272 tm = gmtime(&uptime);
9273 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9274 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9275 + (tm->tm_hour * 3600000));
9276
9277 /* Configured timer values. */
9278 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9279 p->v_holdtime * 1000);
9280 json_object_int_add(json_neigh,
9281 "bgpTimerKeepAliveIntervalMsecs",
9282 p->v_keepalive * 1000);
b90a8e13 9283 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9284 json_object_int_add(json_neigh,
9285 "bgpTimerConfiguredHoldTimeMsecs",
9286 p->holdtime * 1000);
9287 json_object_int_add(
9288 json_neigh,
9289 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9290 p->keepalive * 1000);
d25e4efc 9291 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9292 || (bgp->default_keepalive
9293 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9294 json_object_int_add(json_neigh,
9295 "bgpTimerConfiguredHoldTimeMsecs",
9296 bgp->default_holdtime);
9297 json_object_int_add(
9298 json_neigh,
9299 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9300 bgp->default_keepalive);
d62a17ae 9301 }
9302 } else {
9303 /* Administrative shutdown. */
9304 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9305 vty_out(vty, " Administratively shut down\n");
9306
9307 /* BGP Version. */
9308 vty_out(vty, " BGP version 4");
0e38aeb4 9309 vty_out(vty, ", remote router ID %s",
d62a17ae 9310 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9311 vty_out(vty, ", local router ID %s\n",
9312 inet_ntop(AF_INET, &bgp->router_id, buf1,
9313 sizeof(buf1)));
d62a17ae 9314
9315 /* Confederation */
9316 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9317 && bgp_confederation_peers_check(bgp, p->as))
9318 vty_out(vty,
9319 " Neighbor under common administration\n");
9320
9321 /* Status. */
9322 vty_out(vty, " BGP state = %s",
9323 lookup_msg(bgp_status_msg, p->status, NULL));
9324
9325 if (p->status == Established)
9326 vty_out(vty, ", up for %8s",
9327 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9328 0, NULL));
9329
9330 else if (p->status == Active) {
9331 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9332 vty_out(vty, " (passive)");
9333 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9334 vty_out(vty, " (NSF passive)");
9335 }
9336 vty_out(vty, "\n");
9337
9338 /* read timer */
9339 vty_out(vty, " Last read %s",
9340 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9341 NULL));
9342 vty_out(vty, ", Last write %s\n",
9343 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9344 NULL));
9345
9346 /* Configured timer values. */
9347 vty_out(vty,
9348 " Hold time is %d, keepalive interval is %d seconds\n",
9349 p->v_holdtime, p->v_keepalive);
b90a8e13 9350 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9351 vty_out(vty, " Configured hold time is %d",
9352 p->holdtime);
9353 vty_out(vty, ", keepalive interval is %d seconds\n",
9354 p->keepalive);
d25e4efc 9355 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9356 || (bgp->default_keepalive
9357 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9358 vty_out(vty, " Configured hold time is %d",
9359 bgp->default_holdtime);
9360 vty_out(vty, ", keepalive interval is %d seconds\n",
9361 bgp->default_keepalive);
d62a17ae 9362 }
9363 }
9364 /* Capability. */
9365 if (p->status == Established) {
9366 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9367 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9368 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9369 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9370 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9371 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9372 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9373 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9374 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9375 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9376 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9377 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9378 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9379 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9380 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9381 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9382 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9383 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9384 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9385 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9386 if (use_json) {
9387 json_object *json_cap = NULL;
9388
9389 json_cap = json_object_new_object();
9390
9391 /* AS4 */
9392 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9393 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9394 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9395 && CHECK_FLAG(p->cap,
9396 PEER_CAP_AS4_RCV))
9397 json_object_string_add(
9398 json_cap, "4byteAs",
9399 "advertisedAndReceived");
9400 else if (CHECK_FLAG(p->cap,
9401 PEER_CAP_AS4_ADV))
9402 json_object_string_add(
9403 json_cap, "4byteAs",
9404 "advertised");
9405 else if (CHECK_FLAG(p->cap,
9406 PEER_CAP_AS4_RCV))
9407 json_object_string_add(
9408 json_cap, "4byteAs",
9409 "received");
9410 }
9411
9412 /* AddPath */
9413 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9414 || CHECK_FLAG(p->cap,
9415 PEER_CAP_ADDPATH_ADV)) {
9416 json_object *json_add = NULL;
9417 const char *print_store;
9418
9419 json_add = json_object_new_object();
9420
05c7a1cc
QY
9421 FOREACH_AFI_SAFI (afi, safi) {
9422 json_object *json_sub = NULL;
9423 json_sub =
9424 json_object_new_object();
9425 print_store = afi_safi_print(
9426 afi, safi);
d62a17ae 9427
05c7a1cc
QY
9428 if (CHECK_FLAG(
9429 p->af_cap[afi]
9430 [safi],
9431 PEER_CAP_ADDPATH_AF_TX_ADV)
9432 || CHECK_FLAG(
9433 p->af_cap[afi]
9434 [safi],
9435 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9436 if (CHECK_FLAG(
9437 p->af_cap
9438 [afi]
9439 [safi],
9440 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9441 && CHECK_FLAG(
d62a17ae 9442 p->af_cap
9443 [afi]
9444 [safi],
05c7a1cc
QY
9445 PEER_CAP_ADDPATH_AF_TX_RCV))
9446 json_object_boolean_true_add(
9447 json_sub,
9448 "txAdvertisedAndReceived");
9449 else if (
9450 CHECK_FLAG(
9451 p->af_cap
9452 [afi]
9453 [safi],
9454 PEER_CAP_ADDPATH_AF_TX_ADV))
9455 json_object_boolean_true_add(
9456 json_sub,
9457 "txAdvertised");
9458 else if (
9459 CHECK_FLAG(
9460 p->af_cap
9461 [afi]
9462 [safi],
9463 PEER_CAP_ADDPATH_AF_TX_RCV))
9464 json_object_boolean_true_add(
9465 json_sub,
9466 "txReceived");
9467 }
d62a17ae 9468
05c7a1cc
QY
9469 if (CHECK_FLAG(
9470 p->af_cap[afi]
9471 [safi],
9472 PEER_CAP_ADDPATH_AF_RX_ADV)
9473 || CHECK_FLAG(
9474 p->af_cap[afi]
9475 [safi],
9476 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9477 if (CHECK_FLAG(
9478 p->af_cap
9479 [afi]
9480 [safi],
9481 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9482 && CHECK_FLAG(
d62a17ae 9483 p->af_cap
9484 [afi]
9485 [safi],
9486 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9487 json_object_boolean_true_add(
9488 json_sub,
9489 "rxAdvertisedAndReceived");
9490 else if (
9491 CHECK_FLAG(
9492 p->af_cap
9493 [afi]
9494 [safi],
9495 PEER_CAP_ADDPATH_AF_RX_ADV))
9496 json_object_boolean_true_add(
9497 json_sub,
9498 "rxAdvertised");
9499 else if (
9500 CHECK_FLAG(
9501 p->af_cap
9502 [afi]
9503 [safi],
9504 PEER_CAP_ADDPATH_AF_RX_RCV))
9505 json_object_boolean_true_add(
9506 json_sub,
9507 "rxReceived");
d62a17ae 9508 }
9509
05c7a1cc
QY
9510 if (CHECK_FLAG(
9511 p->af_cap[afi]
9512 [safi],
9513 PEER_CAP_ADDPATH_AF_TX_ADV)
9514 || CHECK_FLAG(
9515 p->af_cap[afi]
9516 [safi],
9517 PEER_CAP_ADDPATH_AF_TX_RCV)
9518 || CHECK_FLAG(
9519 p->af_cap[afi]
9520 [safi],
9521 PEER_CAP_ADDPATH_AF_RX_ADV)
9522 || CHECK_FLAG(
9523 p->af_cap[afi]
9524 [safi],
9525 PEER_CAP_ADDPATH_AF_RX_RCV))
9526 json_object_object_add(
9527 json_add,
9528 print_store,
9529 json_sub);
9530 else
9531 json_object_free(
9532 json_sub);
9533 }
9534
d62a17ae 9535 json_object_object_add(
9536 json_cap, "addPath", json_add);
9537 }
9538
9539 /* Dynamic */
9540 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9541 || CHECK_FLAG(p->cap,
9542 PEER_CAP_DYNAMIC_ADV)) {
9543 if (CHECK_FLAG(p->cap,
9544 PEER_CAP_DYNAMIC_ADV)
9545 && CHECK_FLAG(p->cap,
9546 PEER_CAP_DYNAMIC_RCV))
9547 json_object_string_add(
9548 json_cap, "dynamic",
9549 "advertisedAndReceived");
9550 else if (CHECK_FLAG(
9551 p->cap,
9552 PEER_CAP_DYNAMIC_ADV))
9553 json_object_string_add(
9554 json_cap, "dynamic",
9555 "advertised");
9556 else if (CHECK_FLAG(
9557 p->cap,
9558 PEER_CAP_DYNAMIC_RCV))
9559 json_object_string_add(
9560 json_cap, "dynamic",
9561 "received");
9562 }
9563
9564 /* Extended nexthop */
9565 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9566 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9567 json_object *json_nxt = NULL;
9568 const char *print_store;
9569
9570
9571 if (CHECK_FLAG(p->cap,
9572 PEER_CAP_ENHE_ADV)
9573 && CHECK_FLAG(p->cap,
9574 PEER_CAP_ENHE_RCV))
9575 json_object_string_add(
9576 json_cap,
9577 "extendedNexthop",
9578 "advertisedAndReceived");
9579 else if (CHECK_FLAG(p->cap,
9580 PEER_CAP_ENHE_ADV))
9581 json_object_string_add(
9582 json_cap,
9583 "extendedNexthop",
9584 "advertised");
9585 else if (CHECK_FLAG(p->cap,
9586 PEER_CAP_ENHE_RCV))
9587 json_object_string_add(
9588 json_cap,
9589 "extendedNexthop",
9590 "received");
9591
9592 if (CHECK_FLAG(p->cap,
9593 PEER_CAP_ENHE_RCV)) {
9594 json_nxt =
9595 json_object_new_object();
9596
9597 for (safi = SAFI_UNICAST;
9598 safi < SAFI_MAX; safi++) {
9599 if (CHECK_FLAG(
9600 p->af_cap
9601 [AFI_IP]
9602 [safi],
9603 PEER_CAP_ENHE_AF_RCV)) {
9604 print_store = afi_safi_print(
9605 AFI_IP,
9606 safi);
9607 json_object_string_add(
9608 json_nxt,
9609 print_store,
9610 "recieved");
9611 }
9612 }
9613 json_object_object_add(
9614 json_cap,
9615 "extendedNexthopFamililesByPeer",
9616 json_nxt);
9617 }
9618 }
9619
9620 /* Route Refresh */
9621 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9622 || CHECK_FLAG(p->cap,
9623 PEER_CAP_REFRESH_NEW_RCV)
9624 || CHECK_FLAG(p->cap,
9625 PEER_CAP_REFRESH_OLD_RCV)) {
9626 if (CHECK_FLAG(p->cap,
9627 PEER_CAP_REFRESH_ADV)
9628 && (CHECK_FLAG(
9629 p->cap,
9630 PEER_CAP_REFRESH_NEW_RCV)
9631 || CHECK_FLAG(
9632 p->cap,
9633 PEER_CAP_REFRESH_OLD_RCV))) {
9634 if (CHECK_FLAG(
9635 p->cap,
9636 PEER_CAP_REFRESH_OLD_RCV)
9637 && CHECK_FLAG(
9638 p->cap,
9639 PEER_CAP_REFRESH_NEW_RCV))
9640 json_object_string_add(
9641 json_cap,
9642 "routeRefresh",
9643 "advertisedAndReceivedOldNew");
9644 else {
9645 if (CHECK_FLAG(
9646 p->cap,
9647 PEER_CAP_REFRESH_OLD_RCV))
9648 json_object_string_add(
9649 json_cap,
9650 "routeRefresh",
9651 "advertisedAndReceivedOld");
9652 else
9653 json_object_string_add(
9654 json_cap,
9655 "routeRefresh",
9656 "advertisedAndReceivedNew");
9657 }
9658 } else if (
9659 CHECK_FLAG(
9660 p->cap,
9661 PEER_CAP_REFRESH_ADV))
9662 json_object_string_add(
9663 json_cap,
9664 "routeRefresh",
9665 "advertised");
9666 else if (
9667 CHECK_FLAG(
9668 p->cap,
9669 PEER_CAP_REFRESH_NEW_RCV)
9670 || CHECK_FLAG(
9671 p->cap,
9672 PEER_CAP_REFRESH_OLD_RCV))
9673 json_object_string_add(
9674 json_cap,
9675 "routeRefresh",
9676 "received");
9677 }
9678
9679 /* Multiprotocol Extensions */
9680 json_object *json_multi = NULL;
9681 json_multi = json_object_new_object();
9682
05c7a1cc
QY
9683 FOREACH_AFI_SAFI (afi, safi) {
9684 if (p->afc_adv[afi][safi]
9685 || p->afc_recv[afi][safi]) {
9686 json_object *json_exten = NULL;
9687 json_exten =
9688 json_object_new_object();
9689
d62a17ae 9690 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9691 && p->afc_recv[afi][safi])
9692 json_object_boolean_true_add(
9693 json_exten,
9694 "advertisedAndReceived");
9695 else if (p->afc_adv[afi][safi])
9696 json_object_boolean_true_add(
9697 json_exten,
9698 "advertised");
9699 else if (p->afc_recv[afi][safi])
9700 json_object_boolean_true_add(
9701 json_exten,
9702 "received");
d62a17ae 9703
05c7a1cc
QY
9704 json_object_object_add(
9705 json_multi,
9706 afi_safi_print(afi,
9707 safi),
9708 json_exten);
d62a17ae 9709 }
9710 }
9711 json_object_object_add(
9712 json_cap, "multiprotocolExtensions",
9713 json_multi);
9714
d77114b7 9715 /* Hostname capabilities */
60466a63 9716 json_object *json_hname = NULL;
d77114b7
MK
9717
9718 json_hname = json_object_new_object();
9719
9720 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9721 json_object_string_add(
60466a63
QY
9722 json_hname, "advHostName",
9723 bgp->peer_self->hostname
9724 ? bgp->peer_self
9725 ->hostname
d77114b7
MK
9726 : "n/a");
9727 json_object_string_add(
60466a63
QY
9728 json_hname, "advDomainName",
9729 bgp->peer_self->domainname
9730 ? bgp->peer_self
9731 ->domainname
d77114b7
MK
9732 : "n/a");
9733 }
9734
9735
9736 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9737 json_object_string_add(
60466a63
QY
9738 json_hname, "rcvHostName",
9739 p->hostname ? p->hostname
9740 : "n/a");
d77114b7 9741 json_object_string_add(
60466a63
QY
9742 json_hname, "rcvDomainName",
9743 p->domainname ? p->domainname
9744 : "n/a");
d77114b7
MK
9745 }
9746
60466a63 9747 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9748 json_hname);
9749
d62a17ae 9750 /* Gracefull Restart */
9751 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9752 || CHECK_FLAG(p->cap,
9753 PEER_CAP_RESTART_ADV)) {
9754 if (CHECK_FLAG(p->cap,
9755 PEER_CAP_RESTART_ADV)
9756 && CHECK_FLAG(p->cap,
9757 PEER_CAP_RESTART_RCV))
9758 json_object_string_add(
9759 json_cap,
9760 "gracefulRestart",
9761 "advertisedAndReceived");
9762 else if (CHECK_FLAG(
9763 p->cap,
9764 PEER_CAP_RESTART_ADV))
9765 json_object_string_add(
9766 json_cap,
9767 "gracefulRestartCapability",
9768 "advertised");
9769 else if (CHECK_FLAG(
9770 p->cap,
9771 PEER_CAP_RESTART_RCV))
9772 json_object_string_add(
9773 json_cap,
9774 "gracefulRestartCapability",
9775 "received");
9776
9777 if (CHECK_FLAG(p->cap,
9778 PEER_CAP_RESTART_RCV)) {
9779 int restart_af_count = 0;
9780 json_object *json_restart =
9781 NULL;
9782 json_restart =
9783 json_object_new_object();
9784
9785 json_object_int_add(
9786 json_cap,
9787 "gracefulRestartRemoteTimerMsecs",
9788 p->v_gr_restart * 1000);
9789
05c7a1cc
QY
9790 FOREACH_AFI_SAFI (afi, safi) {
9791 if (CHECK_FLAG(
9792 p->af_cap
9793 [afi]
9794 [safi],
9795 PEER_CAP_RESTART_AF_RCV)) {
9796 json_object *
9797 json_sub =
9798 NULL;
9799 json_sub =
9800 json_object_new_object();
9801
d62a17ae 9802 if (CHECK_FLAG(
9803 p->af_cap
9804 [afi]
9805 [safi],
05c7a1cc
QY
9806 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9807 json_object_boolean_true_add(
9808 json_sub,
9809 "preserved");
9810 restart_af_count++;
9811 json_object_object_add(
9812 json_restart,
9813 afi_safi_print(
9814 afi,
9815 safi),
9816 json_sub);
d62a17ae 9817 }
9818 }
9819 if (!restart_af_count) {
9820 json_object_string_add(
9821 json_cap,
9822 "addressFamiliesByPeer",
9823 "none");
9824 json_object_free(
9825 json_restart);
9826 } else
9827 json_object_object_add(
9828 json_cap,
9829 "addressFamiliesByPeer",
9830 json_restart);
9831 }
9832 }
9833 json_object_object_add(json_neigh,
9834 "neighborCapabilities",
9835 json_cap);
9836 } else {
9837 vty_out(vty, " Neighbor capabilities:\n");
9838
9839 /* AS4 */
9840 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9841 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9842 vty_out(vty, " 4 Byte AS:");
9843 if (CHECK_FLAG(p->cap,
9844 PEER_CAP_AS4_ADV))
9845 vty_out(vty, " advertised");
9846 if (CHECK_FLAG(p->cap,
9847 PEER_CAP_AS4_RCV))
9848 vty_out(vty, " %sreceived",
9849 CHECK_FLAG(
9850 p->cap,
9851 PEER_CAP_AS4_ADV)
9852 ? "and "
9853 : "");
9854 vty_out(vty, "\n");
9855 }
9856
9857 /* AddPath */
9858 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9859 || CHECK_FLAG(p->cap,
9860 PEER_CAP_ADDPATH_ADV)) {
9861 vty_out(vty, " AddPath:\n");
9862
05c7a1cc
QY
9863 FOREACH_AFI_SAFI (afi, safi) {
9864 if (CHECK_FLAG(
9865 p->af_cap[afi]
9866 [safi],
9867 PEER_CAP_ADDPATH_AF_TX_ADV)
9868 || CHECK_FLAG(
9869 p->af_cap[afi]
9870 [safi],
9871 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9872 vty_out(vty,
9873 " %s: TX ",
9874 afi_safi_print(
9875 afi,
9876 safi));
9877
d62a17ae 9878 if (CHECK_FLAG(
9879 p->af_cap
9880 [afi]
9881 [safi],
05c7a1cc 9882 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9883 vty_out(vty,
05c7a1cc 9884 "advertised %s",
d62a17ae 9885 afi_safi_print(
9886 afi,
9887 safi));
9888
05c7a1cc
QY
9889 if (CHECK_FLAG(
9890 p->af_cap
9891 [afi]
9892 [safi],
9893 PEER_CAP_ADDPATH_AF_TX_RCV))
9894 vty_out(vty,
9895 "%sreceived",
9896 CHECK_FLAG(
9897 p->af_cap
9898 [afi]
9899 [safi],
9900 PEER_CAP_ADDPATH_AF_TX_ADV)
9901 ? " and "
9902 : "");
d62a17ae 9903
05c7a1cc
QY
9904 vty_out(vty, "\n");
9905 }
d62a17ae 9906
05c7a1cc
QY
9907 if (CHECK_FLAG(
9908 p->af_cap[afi]
9909 [safi],
9910 PEER_CAP_ADDPATH_AF_RX_ADV)
9911 || CHECK_FLAG(
9912 p->af_cap[afi]
9913 [safi],
9914 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9915 vty_out(vty,
9916 " %s: RX ",
9917 afi_safi_print(
9918 afi,
9919 safi));
d62a17ae 9920
9921 if (CHECK_FLAG(
9922 p->af_cap
9923 [afi]
9924 [safi],
05c7a1cc 9925 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9926 vty_out(vty,
05c7a1cc 9927 "advertised %s",
d62a17ae 9928 afi_safi_print(
9929 afi,
9930 safi));
9931
05c7a1cc
QY
9932 if (CHECK_FLAG(
9933 p->af_cap
9934 [afi]
9935 [safi],
9936 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9937 vty_out(vty,
05c7a1cc
QY
9938 "%sreceived",
9939 CHECK_FLAG(
9940 p->af_cap
9941 [afi]
9942 [safi],
9943 PEER_CAP_ADDPATH_AF_RX_ADV)
9944 ? " and "
9945 : "");
9946
9947 vty_out(vty, "\n");
d62a17ae 9948 }
05c7a1cc 9949 }
d62a17ae 9950 }
9951
9952 /* Dynamic */
9953 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9954 || CHECK_FLAG(p->cap,
9955 PEER_CAP_DYNAMIC_ADV)) {
9956 vty_out(vty, " Dynamic:");
9957 if (CHECK_FLAG(p->cap,
9958 PEER_CAP_DYNAMIC_ADV))
9959 vty_out(vty, " advertised");
9960 if (CHECK_FLAG(p->cap,
9961 PEER_CAP_DYNAMIC_RCV))
9962 vty_out(vty, " %sreceived",
9963 CHECK_FLAG(
9964 p->cap,
9965 PEER_CAP_DYNAMIC_ADV)
9966 ? "and "
9967 : "");
9968 vty_out(vty, "\n");
9969 }
9970
9971 /* Extended nexthop */
9972 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9973 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9974 vty_out(vty, " Extended nexthop:");
9975 if (CHECK_FLAG(p->cap,
9976 PEER_CAP_ENHE_ADV))
9977 vty_out(vty, " advertised");
9978 if (CHECK_FLAG(p->cap,
9979 PEER_CAP_ENHE_RCV))
9980 vty_out(vty, " %sreceived",
9981 CHECK_FLAG(
9982 p->cap,
9983 PEER_CAP_ENHE_ADV)
9984 ? "and "
9985 : "");
9986 vty_out(vty, "\n");
9987
9988 if (CHECK_FLAG(p->cap,
9989 PEER_CAP_ENHE_RCV)) {
9990 vty_out(vty,
9991 " Address families by peer:\n ");
9992 for (safi = SAFI_UNICAST;
9993 safi < SAFI_MAX; safi++)
9994 if (CHECK_FLAG(
9995 p->af_cap
9996 [AFI_IP]
9997 [safi],
9998 PEER_CAP_ENHE_AF_RCV))
9999 vty_out(vty,
10000 " %s\n",
10001 afi_safi_print(
10002 AFI_IP,
10003 safi));
10004 }
10005 }
10006
10007 /* Route Refresh */
10008 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10009 || CHECK_FLAG(p->cap,
10010 PEER_CAP_REFRESH_NEW_RCV)
10011 || CHECK_FLAG(p->cap,
10012 PEER_CAP_REFRESH_OLD_RCV)) {
10013 vty_out(vty, " Route refresh:");
10014 if (CHECK_FLAG(p->cap,
10015 PEER_CAP_REFRESH_ADV))
10016 vty_out(vty, " advertised");
10017 if (CHECK_FLAG(p->cap,
10018 PEER_CAP_REFRESH_NEW_RCV)
10019 || CHECK_FLAG(
10020 p->cap,
10021 PEER_CAP_REFRESH_OLD_RCV))
10022 vty_out(vty, " %sreceived(%s)",
10023 CHECK_FLAG(
10024 p->cap,
10025 PEER_CAP_REFRESH_ADV)
10026 ? "and "
10027 : "",
10028 (CHECK_FLAG(
10029 p->cap,
10030 PEER_CAP_REFRESH_OLD_RCV)
10031 && CHECK_FLAG(
10032 p->cap,
10033 PEER_CAP_REFRESH_NEW_RCV))
10034 ? "old & new"
10035 : CHECK_FLAG(
10036 p->cap,
10037 PEER_CAP_REFRESH_OLD_RCV)
10038 ? "old"
10039 : "new");
10040
10041 vty_out(vty, "\n");
10042 }
10043
10044 /* Multiprotocol Extensions */
05c7a1cc
QY
10045 FOREACH_AFI_SAFI (afi, safi)
10046 if (p->afc_adv[afi][safi]
10047 || p->afc_recv[afi][safi]) {
10048 vty_out(vty,
10049 " Address Family %s:",
10050 afi_safi_print(afi,
10051 safi));
10052 if (p->afc_adv[afi][safi])
d62a17ae 10053 vty_out(vty,
05c7a1cc
QY
10054 " advertised");
10055 if (p->afc_recv[afi][safi])
10056 vty_out(vty,
10057 " %sreceived",
10058 p->afc_adv[afi]
10059 [safi]
10060 ? "and "
10061 : "");
10062 vty_out(vty, "\n");
10063 }
d62a17ae 10064
10065 /* Hostname capability */
60466a63 10066 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10067
10068 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10069 vty_out(vty,
10070 " advertised (name: %s,domain name: %s)",
60466a63
QY
10071 bgp->peer_self->hostname
10072 ? bgp->peer_self
10073 ->hostname
d77114b7 10074 : "n/a",
60466a63
QY
10075 bgp->peer_self->domainname
10076 ? bgp->peer_self
10077 ->domainname
d77114b7
MK
10078 : "n/a");
10079 } else {
10080 vty_out(vty, " not advertised");
d62a17ae 10081 }
10082
d77114b7 10083 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10084 vty_out(vty,
10085 " received (name: %s,domain name: %s)",
60466a63
QY
10086 p->hostname ? p->hostname
10087 : "n/a",
10088 p->domainname ? p->domainname
10089 : "n/a");
d77114b7
MK
10090 } else {
10091 vty_out(vty, " not received");
10092 }
10093
10094 vty_out(vty, "\n");
10095
d62a17ae 10096 /* Gracefull Restart */
10097 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10098 || CHECK_FLAG(p->cap,
10099 PEER_CAP_RESTART_ADV)) {
10100 vty_out(vty,
10101 " Graceful Restart Capabilty:");
10102 if (CHECK_FLAG(p->cap,
10103 PEER_CAP_RESTART_ADV))
10104 vty_out(vty, " advertised");
10105 if (CHECK_FLAG(p->cap,
10106 PEER_CAP_RESTART_RCV))
10107 vty_out(vty, " %sreceived",
10108 CHECK_FLAG(
10109 p->cap,
10110 PEER_CAP_RESTART_ADV)
10111 ? "and "
10112 : "");
10113 vty_out(vty, "\n");
10114
10115 if (CHECK_FLAG(p->cap,
10116 PEER_CAP_RESTART_RCV)) {
10117 int restart_af_count = 0;
10118
10119 vty_out(vty,
10120 " Remote Restart timer is %d seconds\n",
10121 p->v_gr_restart);
10122 vty_out(vty,
10123 " Address families by peer:\n ");
10124
05c7a1cc
QY
10125 FOREACH_AFI_SAFI (afi, safi)
10126 if (CHECK_FLAG(
10127 p->af_cap
10128 [afi]
10129 [safi],
10130 PEER_CAP_RESTART_AF_RCV)) {
10131 vty_out(vty,
10132 "%s%s(%s)",
10133 restart_af_count
10134 ? ", "
10135 : "",
10136 afi_safi_print(
10137 afi,
10138 safi),
10139 CHECK_FLAG(
10140 p->af_cap
10141 [afi]
10142 [safi],
10143 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10144 ? "preserved"
10145 : "not preserved");
10146 restart_af_count++;
10147 }
d62a17ae 10148 if (!restart_af_count)
10149 vty_out(vty, "none");
10150 vty_out(vty, "\n");
10151 }
10152 }
10153 }
10154 }
10155 }
10156
10157 /* graceful restart information */
10158 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10159 || p->t_gr_stale) {
10160 json_object *json_grace = NULL;
10161 json_object *json_grace_send = NULL;
10162 json_object *json_grace_recv = NULL;
10163 int eor_send_af_count = 0;
10164 int eor_receive_af_count = 0;
10165
10166 if (use_json) {
10167 json_grace = json_object_new_object();
10168 json_grace_send = json_object_new_object();
10169 json_grace_recv = json_object_new_object();
10170
10171 if (p->status == Established) {
05c7a1cc
QY
10172 FOREACH_AFI_SAFI (afi, safi) {
10173 if (CHECK_FLAG(p->af_sflags[afi][safi],
10174 PEER_STATUS_EOR_SEND)) {
10175 json_object_boolean_true_add(
10176 json_grace_send,
10177 afi_safi_print(afi,
10178 safi));
10179 eor_send_af_count++;
d62a17ae 10180 }
10181 }
05c7a1cc
QY
10182 FOREACH_AFI_SAFI (afi, safi) {
10183 if (CHECK_FLAG(
10184 p->af_sflags[afi][safi],
10185 PEER_STATUS_EOR_RECEIVED)) {
10186 json_object_boolean_true_add(
10187 json_grace_recv,
10188 afi_safi_print(afi,
10189 safi));
10190 eor_receive_af_count++;
d62a17ae 10191 }
10192 }
10193 }
10194
10195 json_object_object_add(json_grace, "endOfRibSend",
10196 json_grace_send);
10197 json_object_object_add(json_grace, "endOfRibRecv",
10198 json_grace_recv);
10199
10200 if (p->t_gr_restart)
10201 json_object_int_add(json_grace,
10202 "gracefulRestartTimerMsecs",
10203 thread_timer_remain_second(
10204 p->t_gr_restart)
10205 * 1000);
10206
10207 if (p->t_gr_stale)
10208 json_object_int_add(
10209 json_grace,
10210 "gracefulStalepathTimerMsecs",
10211 thread_timer_remain_second(
10212 p->t_gr_stale)
10213 * 1000);
10214
10215 json_object_object_add(
10216 json_neigh, "gracefulRestartInfo", json_grace);
10217 } else {
10218 vty_out(vty, " Graceful restart informations:\n");
10219 if (p->status == Established) {
10220 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10221 FOREACH_AFI_SAFI (afi, safi) {
10222 if (CHECK_FLAG(p->af_sflags[afi][safi],
10223 PEER_STATUS_EOR_SEND)) {
10224 vty_out(vty, "%s%s",
10225 eor_send_af_count ? ", "
10226 : "",
10227 afi_safi_print(afi,
10228 safi));
10229 eor_send_af_count++;
d62a17ae 10230 }
10231 }
10232 vty_out(vty, "\n");
10233 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10234 FOREACH_AFI_SAFI (afi, safi) {
10235 if (CHECK_FLAG(
10236 p->af_sflags[afi][safi],
10237 PEER_STATUS_EOR_RECEIVED)) {
10238 vty_out(vty, "%s%s",
10239 eor_receive_af_count
10240 ? ", "
10241 : "",
10242 afi_safi_print(afi,
10243 safi));
10244 eor_receive_af_count++;
d62a17ae 10245 }
10246 }
10247 vty_out(vty, "\n");
10248 }
10249
10250 if (p->t_gr_restart)
10251 vty_out(vty,
10252 " The remaining time of restart timer is %ld\n",
10253 thread_timer_remain_second(
10254 p->t_gr_restart));
10255
10256 if (p->t_gr_stale)
10257 vty_out(vty,
10258 " The remaining time of stalepath timer is %ld\n",
10259 thread_timer_remain_second(
10260 p->t_gr_stale));
10261 }
10262 }
10263 if (use_json) {
10264 json_object *json_stat = NULL;
10265 json_stat = json_object_new_object();
10266 /* Packet counts. */
10267 json_object_int_add(json_stat, "depthInq", 0);
10268 json_object_int_add(json_stat, "depthOutq",
10269 (unsigned long)p->obuf->count);
0112e9e0
QY
10270 json_object_int_add(json_stat, "opensSent",
10271 atomic_load_explicit(&p->open_out,
10272 memory_order_relaxed));
10273 json_object_int_add(json_stat, "opensRecv",
10274 atomic_load_explicit(&p->open_in,
10275 memory_order_relaxed));
d62a17ae 10276 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10277 atomic_load_explicit(&p->notify_out,
10278 memory_order_relaxed));
d62a17ae 10279 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10280 atomic_load_explicit(&p->notify_in,
10281 memory_order_relaxed));
10282 json_object_int_add(json_stat, "updatesSent",
10283 atomic_load_explicit(&p->update_out,
10284 memory_order_relaxed));
10285 json_object_int_add(json_stat, "updatesRecv",
10286 atomic_load_explicit(&p->update_in,
10287 memory_order_relaxed));
d62a17ae 10288 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10289 atomic_load_explicit(&p->keepalive_out,
10290 memory_order_relaxed));
d62a17ae 10291 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10292 atomic_load_explicit(&p->keepalive_in,
10293 memory_order_relaxed));
d62a17ae 10294 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10295 atomic_load_explicit(&p->refresh_out,
10296 memory_order_relaxed));
d62a17ae 10297 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10298 atomic_load_explicit(&p->refresh_in,
10299 memory_order_relaxed));
d62a17ae 10300 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10301 atomic_load_explicit(&p->dynamic_cap_out,
10302 memory_order_relaxed));
d62a17ae 10303 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10304 atomic_load_explicit(&p->dynamic_cap_in,
10305 memory_order_relaxed));
10306 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10307 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10308 json_object_object_add(json_neigh, "messageStats", json_stat);
10309 } else {
10310 /* Packet counts. */
10311 vty_out(vty, " Message statistics:\n");
10312 vty_out(vty, " Inq depth is 0\n");
10313 vty_out(vty, " Outq depth is %lu\n",
10314 (unsigned long)p->obuf->count);
10315 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10316 vty_out(vty, " Opens: %10d %10d\n",
10317 atomic_load_explicit(&p->open_out,
10318 memory_order_relaxed),
10319 atomic_load_explicit(&p->open_in,
10320 memory_order_relaxed));
10321 vty_out(vty, " Notifications: %10d %10d\n",
10322 atomic_load_explicit(&p->notify_out,
10323 memory_order_relaxed),
10324 atomic_load_explicit(&p->notify_in,
10325 memory_order_relaxed));
10326 vty_out(vty, " Updates: %10d %10d\n",
10327 atomic_load_explicit(&p->update_out,
10328 memory_order_relaxed),
10329 atomic_load_explicit(&p->update_in,
10330 memory_order_relaxed));
10331 vty_out(vty, " Keepalives: %10d %10d\n",
10332 atomic_load_explicit(&p->keepalive_out,
10333 memory_order_relaxed),
10334 atomic_load_explicit(&p->keepalive_in,
10335 memory_order_relaxed));
10336 vty_out(vty, " Route Refresh: %10d %10d\n",
10337 atomic_load_explicit(&p->refresh_out,
10338 memory_order_relaxed),
10339 atomic_load_explicit(&p->refresh_in,
10340 memory_order_relaxed));
d62a17ae 10341 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10342 atomic_load_explicit(&p->dynamic_cap_out,
10343 memory_order_relaxed),
10344 atomic_load_explicit(&p->dynamic_cap_in,
10345 memory_order_relaxed));
10346 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10347 PEER_TOTAL_RX(p));
d62a17ae 10348 }
10349
10350 if (use_json) {
10351 /* advertisement-interval */
10352 json_object_int_add(json_neigh,
10353 "minBtwnAdvertisementRunsTimerMsecs",
10354 p->v_routeadv * 1000);
10355
10356 /* Update-source. */
10357 if (p->update_if || p->update_source) {
10358 if (p->update_if)
10359 json_object_string_add(json_neigh,
10360 "updateSource",
10361 p->update_if);
10362 else if (p->update_source)
10363 json_object_string_add(
10364 json_neigh, "updateSource",
10365 sockunion2str(p->update_source, buf1,
10366 SU_ADDRSTRLEN));
10367 }
10368 } else {
10369 /* advertisement-interval */
10370 vty_out(vty,
10371 " Minimum time between advertisement runs is %d seconds\n",
10372 p->v_routeadv);
10373
10374 /* Update-source. */
10375 if (p->update_if || p->update_source) {
10376 vty_out(vty, " Update source is ");
10377 if (p->update_if)
10378 vty_out(vty, "%s", p->update_if);
10379 else if (p->update_source)
10380 vty_out(vty, "%s",
10381 sockunion2str(p->update_source, buf1,
10382 SU_ADDRSTRLEN));
10383 vty_out(vty, "\n");
10384 }
10385
10386 vty_out(vty, "\n");
10387 }
10388
10389 /* Address Family Information */
10390 json_object *json_hold = NULL;
10391
10392 if (use_json)
10393 json_hold = json_object_new_object();
10394
05c7a1cc
QY
10395 FOREACH_AFI_SAFI (afi, safi)
10396 if (p->afc[afi][safi])
10397 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10398 json_hold);
d62a17ae 10399
10400 if (use_json) {
10401 json_object_object_add(json_neigh, "addressFamilyInfo",
10402 json_hold);
10403 json_object_int_add(json_neigh, "connectionsEstablished",
10404 p->established);
10405 json_object_int_add(json_neigh, "connectionsDropped",
10406 p->dropped);
10407 } else
10408 vty_out(vty, " Connections established %d; dropped %d\n",
10409 p->established, p->dropped);
10410
10411 if (!p->last_reset) {
10412 if (use_json)
10413 json_object_string_add(json_neigh, "lastReset",
10414 "never");
10415 else
10416 vty_out(vty, " Last reset never\n");
10417 } else {
10418 if (use_json) {
10419 time_t uptime;
10420 struct tm *tm;
10421
10422 uptime = bgp_clock();
10423 uptime -= p->resettime;
10424 tm = gmtime(&uptime);
10425 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10426 (tm->tm_sec * 1000)
10427 + (tm->tm_min * 60000)
10428 + (tm->tm_hour * 3600000));
10429 json_object_string_add(
10430 json_neigh, "lastResetDueTo",
10431 peer_down_str[(int)p->last_reset]);
10432 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10433 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10434 char errorcodesubcode_hexstr[5];
10435 char errorcodesubcode_str[256];
10436
10437 code_str = bgp_notify_code_str(p->notify.code);
10438 subcode_str = bgp_notify_subcode_str(
10439 p->notify.code, p->notify.subcode);
10440
10441 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10442 p->notify.code, p->notify.subcode);
10443 json_object_string_add(json_neigh,
10444 "lastErrorCodeSubcode",
10445 errorcodesubcode_hexstr);
10446 snprintf(errorcodesubcode_str, 255, "%s%s",
10447 code_str, subcode_str);
10448 json_object_string_add(json_neigh,
10449 "lastNotificationReason",
10450 errorcodesubcode_str);
10451 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10452 && p->notify.code == BGP_NOTIFY_CEASE
10453 && (p->notify.subcode
10454 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10455 || p->notify.subcode
10456 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10457 && p->notify.length) {
10458 char msgbuf[1024];
10459 const char *msg_str;
10460
10461 msg_str = bgp_notify_admin_message(
10462 msgbuf, sizeof(msgbuf),
d7c0a89a 10463 (uint8_t *)p->notify.data,
d62a17ae 10464 p->notify.length);
10465 if (msg_str)
10466 json_object_string_add(
10467 json_neigh,
10468 "lastShutdownDescription",
10469 msg_str);
10470 }
10471 }
10472 } else {
10473 vty_out(vty, " Last reset %s, ",
10474 peer_uptime(p->resettime, timebuf,
10475 BGP_UPTIME_LEN, 0, NULL));
10476
10477 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10478 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10479 code_str = bgp_notify_code_str(p->notify.code);
10480 subcode_str = bgp_notify_subcode_str(
10481 p->notify.code, p->notify.subcode);
10482 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10483 p->last_reset == PEER_DOWN_NOTIFY_SEND
10484 ? "sent"
10485 : "received",
10486 code_str, subcode_str);
10487 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10488 && p->notify.code == BGP_NOTIFY_CEASE
10489 && (p->notify.subcode
10490 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10491 || p->notify.subcode
10492 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10493 && p->notify.length) {
10494 char msgbuf[1024];
10495 const char *msg_str;
10496
10497 msg_str = bgp_notify_admin_message(
10498 msgbuf, sizeof(msgbuf),
d7c0a89a 10499 (uint8_t *)p->notify.data,
d62a17ae 10500 p->notify.length);
10501 if (msg_str)
10502 vty_out(vty,
10503 " Message: \"%s\"\n",
10504 msg_str);
10505 }
10506 } else {
10507 vty_out(vty, "due to %s\n",
10508 peer_down_str[(int)p->last_reset]);
10509 }
10510
10511 if (p->last_reset_cause_size) {
10512 msg = p->last_reset_cause;
10513 vty_out(vty,
10514 " Message received that caused BGP to send a NOTIFICATION:\n ");
10515 for (i = 1; i <= p->last_reset_cause_size;
10516 i++) {
10517 vty_out(vty, "%02X", *msg++);
10518
10519 if (i != p->last_reset_cause_size) {
10520 if (i % 16 == 0) {
10521 vty_out(vty, "\n ");
10522 } else if (i % 4 == 0) {
10523 vty_out(vty, " ");
10524 }
10525 }
10526 }
10527 vty_out(vty, "\n");
10528 }
10529 }
10530 }
10531
10532 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10533 if (use_json)
10534 json_object_boolean_true_add(json_neigh,
10535 "prefixesConfigExceedMax");
10536 else
10537 vty_out(vty,
10538 " Peer had exceeded the max. no. of prefixes configured.\n");
10539
10540 if (p->t_pmax_restart) {
10541 if (use_json) {
10542 json_object_boolean_true_add(
10543 json_neigh, "reducePrefixNumFrom");
10544 json_object_int_add(json_neigh,
10545 "restartInTimerMsec",
10546 thread_timer_remain_second(
10547 p->t_pmax_restart)
10548 * 1000);
10549 } else
10550 vty_out(vty,
10551 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10552 p->host, thread_timer_remain_second(
10553 p->t_pmax_restart));
d62a17ae 10554 } else {
10555 if (use_json)
10556 json_object_boolean_true_add(
10557 json_neigh,
10558 "reducePrefixNumAndClearIpBgp");
10559 else
10560 vty_out(vty,
10561 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10562 p->host);
10563 }
10564 }
10565
10566 /* EBGP Multihop and GTSM */
10567 if (p->sort != BGP_PEER_IBGP) {
10568 if (use_json) {
10569 if (p->gtsm_hops > 0)
10570 json_object_int_add(json_neigh,
10571 "externalBgpNbrMaxHopsAway",
10572 p->gtsm_hops);
10573 else if (p->ttl > 1)
10574 json_object_int_add(json_neigh,
10575 "externalBgpNbrMaxHopsAway",
10576 p->ttl);
10577 } else {
10578 if (p->gtsm_hops > 0)
10579 vty_out(vty,
10580 " External BGP neighbor may be up to %d hops away.\n",
10581 p->gtsm_hops);
10582 else if (p->ttl > 1)
10583 vty_out(vty,
10584 " External BGP neighbor may be up to %d hops away.\n",
10585 p->ttl);
10586 }
10587 } else {
10588 if (p->gtsm_hops > 0) {
10589 if (use_json)
10590 json_object_int_add(json_neigh,
10591 "internalBgpNbrMaxHopsAway",
10592 p->gtsm_hops);
10593 else
10594 vty_out(vty,
10595 " Internal BGP neighbor may be up to %d hops away.\n",
10596 p->gtsm_hops);
10597 }
10598 }
10599
10600 /* Local address. */
10601 if (p->su_local) {
10602 if (use_json) {
10603 json_object_string_add(json_neigh, "hostLocal",
10604 sockunion2str(p->su_local, buf1,
10605 SU_ADDRSTRLEN));
10606 json_object_int_add(json_neigh, "portLocal",
10607 ntohs(p->su_local->sin.sin_port));
10608 } else
10609 vty_out(vty, "Local host: %s, Local port: %d\n",
10610 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10611 ntohs(p->su_local->sin.sin_port));
10612 }
10613
10614 /* Remote address. */
10615 if (p->su_remote) {
10616 if (use_json) {
10617 json_object_string_add(json_neigh, "hostForeign",
10618 sockunion2str(p->su_remote, buf1,
10619 SU_ADDRSTRLEN));
10620 json_object_int_add(json_neigh, "portForeign",
10621 ntohs(p->su_remote->sin.sin_port));
10622 } else
10623 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10624 sockunion2str(p->su_remote, buf1,
10625 SU_ADDRSTRLEN),
10626 ntohs(p->su_remote->sin.sin_port));
10627 }
10628
10629 /* Nexthop display. */
10630 if (p->su_local) {
10631 if (use_json) {
10632 json_object_string_add(json_neigh, "nexthop",
10633 inet_ntop(AF_INET,
10634 &p->nexthop.v4, buf1,
10635 sizeof(buf1)));
10636 json_object_string_add(json_neigh, "nexthopGlobal",
10637 inet_ntop(AF_INET6,
10638 &p->nexthop.v6_global,
10639 buf1, sizeof(buf1)));
10640 json_object_string_add(json_neigh, "nexthopLocal",
10641 inet_ntop(AF_INET6,
10642 &p->nexthop.v6_local,
10643 buf1, sizeof(buf1)));
10644 if (p->shared_network)
10645 json_object_string_add(json_neigh,
10646 "bgpConnection",
10647 "sharedNetwork");
10648 else
10649 json_object_string_add(json_neigh,
10650 "bgpConnection",
10651 "nonSharedNetwork");
10652 } else {
10653 vty_out(vty, "Nexthop: %s\n",
10654 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10655 sizeof(buf1)));
10656 vty_out(vty, "Nexthop global: %s\n",
10657 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10658 sizeof(buf1)));
10659 vty_out(vty, "Nexthop local: %s\n",
10660 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10661 sizeof(buf1)));
10662 vty_out(vty, "BGP connection: %s\n",
10663 p->shared_network ? "shared network"
10664 : "non shared network");
10665 }
10666 }
10667
10668 /* Timer information. */
10669 if (use_json) {
10670 json_object_int_add(json_neigh, "connectRetryTimer",
10671 p->v_connect);
10672 if (p->status == Established && p->rtt)
10673 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10674 p->rtt);
10675 if (p->t_start)
10676 json_object_int_add(
10677 json_neigh, "nextStartTimerDueInMsecs",
10678 thread_timer_remain_second(p->t_start) * 1000);
10679 if (p->t_connect)
10680 json_object_int_add(
10681 json_neigh, "nextConnectTimerDueInMsecs",
10682 thread_timer_remain_second(p->t_connect)
10683 * 1000);
10684 if (p->t_routeadv) {
10685 json_object_int_add(json_neigh, "mraiInterval",
10686 p->v_routeadv);
10687 json_object_int_add(
10688 json_neigh, "mraiTimerExpireInMsecs",
10689 thread_timer_remain_second(p->t_routeadv)
10690 * 1000);
10691 }
10692 if (p->password)
10693 json_object_int_add(json_neigh, "authenticationEnabled",
10694 1);
10695
10696 if (p->t_read)
10697 json_object_string_add(json_neigh, "readThread", "on");
10698 else
10699 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10700
10701 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10702 json_object_string_add(json_neigh, "writeThread", "on");
10703 else
10704 json_object_string_add(json_neigh, "writeThread",
10705 "off");
10706 } else {
10707 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10708 p->v_connect);
10709 if (p->status == Established && p->rtt)
10710 vty_out(vty, "Estimated round trip time: %d ms\n",
10711 p->rtt);
10712 if (p->t_start)
10713 vty_out(vty, "Next start timer due in %ld seconds\n",
10714 thread_timer_remain_second(p->t_start));
10715 if (p->t_connect)
10716 vty_out(vty, "Next connect timer due in %ld seconds\n",
10717 thread_timer_remain_second(p->t_connect));
10718 if (p->t_routeadv)
10719 vty_out(vty,
10720 "MRAI (interval %u) timer expires in %ld seconds\n",
10721 p->v_routeadv,
10722 thread_timer_remain_second(p->t_routeadv));
10723 if (p->password)
10724 vty_out(vty, "Peer Authentication Enabled\n");
10725
10726 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10727 p->t_read ? "on" : "off",
10728 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10729 ? "on"
10730 : "off");
d62a17ae 10731 }
10732
10733 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10734 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10735 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10736
10737 if (!use_json)
10738 vty_out(vty, "\n");
10739
10740 /* BFD information. */
10741 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10742
10743 if (use_json) {
10744 if (p->conf_if) /* Configured interface name. */
10745 json_object_object_add(json, p->conf_if, json_neigh);
10746 else /* Configured IP address. */
10747 json_object_object_add(json, p->host, json_neigh);
10748 }
10749}
10750
10751static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10752 enum show_type type, union sockunion *su,
9f049418 10753 const char *conf_if, bool use_json,
d62a17ae 10754 json_object *json)
10755{
10756 struct listnode *node, *nnode;
10757 struct peer *peer;
10758 int find = 0;
9f049418 10759 bool nbr_output = false;
d62a17ae 10760
10761 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10762 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10763 continue;
10764
10765 switch (type) {
10766 case show_all:
10767 bgp_show_peer(vty, peer, use_json, json);
9f049418 10768 nbr_output = true;
d62a17ae 10769 break;
10770 case show_peer:
10771 if (conf_if) {
10772 if ((peer->conf_if
10773 && !strcmp(peer->conf_if, conf_if))
10774 || (peer->hostname
10775 && !strcmp(peer->hostname, conf_if))) {
10776 find = 1;
10777 bgp_show_peer(vty, peer, use_json,
10778 json);
10779 }
10780 } else {
10781 if (sockunion_same(&peer->su, su)) {
10782 find = 1;
10783 bgp_show_peer(vty, peer, use_json,
10784 json);
10785 }
10786 }
10787 break;
10788 }
10789 }
10790
10791 if (type == show_peer && !find) {
10792 if (use_json)
10793 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10794 else
88b7d255 10795 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10796 }
10797
9f049418 10798 if (type != show_peer && !nbr_output && !use_json)
94d4c685 10799 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 10800
d62a17ae 10801 if (use_json) {
996c9314
LB
10802 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10803 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10804 json_object_free(json);
10805 } else {
10806 vty_out(vty, "\n");
10807 }
10808
10809 return CMD_SUCCESS;
10810}
10811
10812static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10813 enum show_type type,
10814 const char *ip_str,
9f049418 10815 bool use_json)
d62a17ae 10816{
0291c246
MK
10817 struct listnode *node, *nnode;
10818 struct bgp *bgp;
71aedaa3 10819 union sockunion su;
0291c246 10820 json_object *json = NULL;
71aedaa3 10821 int ret, is_first = 1;
9f049418 10822 bool nbr_output = false;
d62a17ae 10823
10824 if (use_json)
10825 vty_out(vty, "{\n");
10826
10827 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10828 nbr_output = true;
d62a17ae 10829 if (use_json) {
10830 if (!(json = json_object_new_object())) {
af4c2728 10831 flog_err(
e50f7cfd 10832 EC_BGP_JSON_MEM_ERROR,
d62a17ae 10833 "Unable to allocate memory for JSON object");
10834 vty_out(vty,
10835 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10836 return;
10837 }
10838
10839 json_object_int_add(json, "vrfId",
10840 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10841 ? -1
10842 : (int64_t)bgp->vrf_id);
d62a17ae 10843 json_object_string_add(
10844 json, "vrfName",
10845 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10846 ? "Default"
10847 : bgp->name);
10848
10849 if (!is_first)
10850 vty_out(vty, ",\n");
10851 else
10852 is_first = 0;
10853
10854 vty_out(vty, "\"%s\":",
10855 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10856 ? "Default"
10857 : bgp->name);
10858 } else {
10859 vty_out(vty, "\nInstance %s:\n",
10860 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10861 ? "Default"
10862 : bgp->name);
10863 }
71aedaa3
DS
10864
10865 if (type == show_peer) {
10866 ret = str2sockunion(ip_str, &su);
10867 if (ret < 0)
10868 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10869 use_json, json);
10870 else
10871 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10872 use_json, json);
10873 } else {
10874 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10875 use_json, json);
10876 }
d62a17ae 10877 }
10878
10879 if (use_json)
10880 vty_out(vty, "}\n");
9f049418
DS
10881 else if (!nbr_output)
10882 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10883}
10884
10885static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10886 enum show_type type, const char *ip_str,
9f049418 10887 bool use_json)
d62a17ae 10888{
10889 int ret;
10890 struct bgp *bgp;
10891 union sockunion su;
10892 json_object *json = NULL;
10893
10894 if (name) {
10895 if (strmatch(name, "all")) {
71aedaa3
DS
10896 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10897 use_json);
d62a17ae 10898 return CMD_SUCCESS;
10899 } else {
10900 bgp = bgp_lookup_by_name(name);
10901 if (!bgp) {
10902 if (use_json) {
10903 json = json_object_new_object();
d62a17ae 10904 vty_out(vty, "%s\n",
10905 json_object_to_json_string_ext(
10906 json,
10907 JSON_C_TO_STRING_PRETTY));
10908 json_object_free(json);
10909 } else
10910 vty_out(vty,
9f049418 10911 "%% BGP instance not found\n");
d62a17ae 10912
10913 return CMD_WARNING;
10914 }
10915 }
10916 } else {
10917 bgp = bgp_get_default();
10918 }
10919
10920 if (bgp) {
10921 json = json_object_new_object();
10922 if (ip_str) {
10923 ret = str2sockunion(ip_str, &su);
10924 if (ret < 0)
10925 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10926 use_json, json);
10927 else
10928 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10929 use_json, json);
10930 } else {
10931 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10932 json);
10933 }
10934 json_object_free(json);
ca61fd25
DS
10935 } else {
10936 if (use_json)
10937 vty_out(vty, "{}\n");
10938 else
10939 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10940 }
10941
10942 return CMD_SUCCESS;
4fb25c53
DW
10943}
10944
716b2d8a 10945/* "show [ip] bgp neighbors" commands. */
718e3744 10946DEFUN (show_ip_bgp_neighbors,
10947 show_ip_bgp_neighbors_cmd,
24345e82 10948 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10949 SHOW_STR
10950 IP_STR
10951 BGP_STR
f2a8972b 10952 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10953 "Address Family\n"
10954 "Address Family\n"
718e3744 10955 "Detailed information on TCP and BGP neighbor connections\n"
10956 "Neighbor to display information about\n"
a80beece 10957 "Neighbor to display information about\n"
91d37724 10958 "Neighbor on BGP configured interface\n"
9973d184 10959 JSON_STR)
718e3744 10960{
d62a17ae 10961 char *vrf = NULL;
10962 char *sh_arg = NULL;
10963 enum show_type sh_type;
718e3744 10964
9f049418 10965 bool uj = use_json(argc, argv);
718e3744 10966
d62a17ae 10967 int idx = 0;
718e3744 10968
9a8bdf1c
PG
10969 /* [<vrf> VIEWVRFNAME] */
10970 if (argv_find(argv, argc, "vrf", &idx)) {
10971 vrf = argv[idx + 1]->arg;
10972 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10973 vrf = NULL;
10974 } else if (argv_find(argv, argc, "view", &idx))
10975 /* [<view> VIEWVRFNAME] */
d62a17ae 10976 vrf = argv[idx + 1]->arg;
718e3744 10977
d62a17ae 10978 idx++;
10979 if (argv_find(argv, argc, "A.B.C.D", &idx)
10980 || argv_find(argv, argc, "X:X::X:X", &idx)
10981 || argv_find(argv, argc, "WORD", &idx)) {
10982 sh_type = show_peer;
10983 sh_arg = argv[idx]->arg;
10984 } else
10985 sh_type = show_all;
856ca177 10986
d62a17ae 10987 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10988}
10989
716b2d8a 10990/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10991 paths' and `show ip mbgp paths'. Those functions results are the
10992 same.*/
f412b39a 10993DEFUN (show_ip_bgp_paths,
718e3744 10994 show_ip_bgp_paths_cmd,
46f296b4 10995 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10996 SHOW_STR
10997 IP_STR
10998 BGP_STR
46f296b4 10999 BGP_SAFI_HELP_STR
718e3744 11000 "Path information\n")
11001{
d62a17ae 11002 vty_out(vty, "Address Refcnt Path\n");
11003 aspath_print_all_vty(vty);
11004 return CMD_SUCCESS;
718e3744 11005}
11006
718e3744 11007#include "hash.h"
11008
d62a17ae 11009static void community_show_all_iterator(struct hash_backet *backet,
11010 struct vty *vty)
718e3744 11011{
d62a17ae 11012 struct community *com;
718e3744 11013
d62a17ae 11014 com = (struct community *)backet->data;
3f65c5b1 11015 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11016 community_str(com, false));
718e3744 11017}
11018
11019/* Show BGP's community internal data. */
f412b39a 11020DEFUN (show_ip_bgp_community_info,
718e3744 11021 show_ip_bgp_community_info_cmd,
bec37ba5 11022 "show [ip] bgp community-info",
718e3744 11023 SHOW_STR
11024 IP_STR
11025 BGP_STR
11026 "List all bgp community information\n")
11027{
d62a17ae 11028 vty_out(vty, "Address Refcnt Community\n");
718e3744 11029
d62a17ae 11030 hash_iterate(community_hash(),
11031 (void (*)(struct hash_backet *,
11032 void *))community_show_all_iterator,
11033 vty);
718e3744 11034
d62a17ae 11035 return CMD_SUCCESS;
718e3744 11036}
11037
d62a17ae 11038static void lcommunity_show_all_iterator(struct hash_backet *backet,
11039 struct vty *vty)
57d187bc 11040{
d62a17ae 11041 struct lcommunity *lcom;
57d187bc 11042
d62a17ae 11043 lcom = (struct lcommunity *)backet->data;
3f65c5b1 11044 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11045 lcommunity_str(lcom, false));
57d187bc
JS
11046}
11047
11048/* Show BGP's community internal data. */
11049DEFUN (show_ip_bgp_lcommunity_info,
11050 show_ip_bgp_lcommunity_info_cmd,
11051 "show ip bgp large-community-info",
11052 SHOW_STR
11053 IP_STR
11054 BGP_STR
11055 "List all bgp large-community information\n")
11056{
d62a17ae 11057 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11058
d62a17ae 11059 hash_iterate(lcommunity_hash(),
11060 (void (*)(struct hash_backet *,
11061 void *))lcommunity_show_all_iterator,
11062 vty);
57d187bc 11063
d62a17ae 11064 return CMD_SUCCESS;
57d187bc
JS
11065}
11066
11067
f412b39a 11068DEFUN (show_ip_bgp_attr_info,
718e3744 11069 show_ip_bgp_attr_info_cmd,
bec37ba5 11070 "show [ip] bgp attribute-info",
718e3744 11071 SHOW_STR
11072 IP_STR
11073 BGP_STR
11074 "List all bgp attribute information\n")
11075{
d62a17ae 11076 attr_show_all(vty);
11077 return CMD_SUCCESS;
718e3744 11078}
6b0655a2 11079
9f049418
DS
11080static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11081 safi_t safi, bool use_json)
53089bec 11082{
11083 struct bgp *bgp;
11084 struct listnode *node;
11085 char *vname;
11086 char buf1[INET6_ADDRSTRLEN];
11087 char *ecom_str;
11088 vpn_policy_direction_t dir;
11089
b46dfd20
DS
11090 if (use_json) {
11091 json_object *json = NULL;
11092 json_object *json_import_vrfs = NULL;
11093 json_object *json_export_vrfs = NULL;
11094
11095 json = json_object_new_object();
b46dfd20 11096
b46dfd20
DS
11097 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11098
53089bec 11099 if (!bgp) {
b46dfd20
DS
11100 vty_out(vty, "%s\n",
11101 json_object_to_json_string_ext(
11102 json,
11103 JSON_C_TO_STRING_PRETTY));
11104 json_object_free(json);
11105
53089bec 11106 return CMD_WARNING;
11107 }
b46dfd20 11108
94d4c685
DS
11109 /* Provide context for the block */
11110 json_object_string_add(json, "vrf", name ? name : "default");
11111 json_object_string_add(json, "afiSafi",
11112 afi_safi_print(afi, safi));
11113
b46dfd20
DS
11114 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11115 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11116 json_object_string_add(json, "importFromVrfs", "none");
11117 json_object_string_add(json, "importRts", "none");
11118 } else {
6ce24e52
DS
11119 json_import_vrfs = json_object_new_array();
11120
b46dfd20
DS
11121 for (ALL_LIST_ELEMENTS_RO(
11122 bgp->vpn_policy[afi].import_vrf,
11123 node, vname))
11124 json_object_array_add(json_import_vrfs,
11125 json_object_new_string(vname));
11126
11127 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11128 ecom_str = ecommunity_ecom2str(
11129 bgp->vpn_policy[afi].rtlist[dir],
11130 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11131 json_object_object_add(json, "importFromVrfs",
11132 json_import_vrfs);
11133 json_object_string_add(json, "importRts", ecom_str);
11134
11135 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11136 }
11137
11138 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11139 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11140 json_object_string_add(json, "exportToVrfs", "none");
11141 json_object_string_add(json, "routeDistinguisher",
11142 "none");
11143 json_object_string_add(json, "exportRts", "none");
11144 } else {
6ce24e52
DS
11145 json_export_vrfs = json_object_new_array();
11146
b46dfd20
DS
11147 for (ALL_LIST_ELEMENTS_RO(
11148 bgp->vpn_policy[afi].export_vrf,
11149 node, vname))
11150 json_object_array_add(json_export_vrfs,
11151 json_object_new_string(vname));
11152 json_object_object_add(json, "exportToVrfs",
11153 json_export_vrfs);
11154 json_object_string_add(json, "routeDistinguisher",
11155 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11156 buf1, RD_ADDRSTRLEN));
11157
11158 dir = BGP_VPN_POLICY_DIR_TOVPN;
11159 ecom_str = ecommunity_ecom2str(
11160 bgp->vpn_policy[afi].rtlist[dir],
11161 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11162 json_object_string_add(json, "exportRts", ecom_str);
11163
11164 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11165 }
11166
11167 vty_out(vty, "%s\n",
11168 json_object_to_json_string_ext(json,
11169 JSON_C_TO_STRING_PRETTY));
11170 json_object_free(json);
11171
53089bec 11172 } else {
b46dfd20
DS
11173 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11174
53089bec 11175 if (!bgp) {
b46dfd20 11176 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11177 return CMD_WARNING;
11178 }
53089bec 11179
b46dfd20
DS
11180 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11181 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11182 vty_out(vty,
11183 "This VRF is not importing %s routes from any other VRF\n",
11184 afi_safi_print(afi, safi));
11185 else {
11186 vty_out(vty,
11187 "This VRF is importing %s routes from the following VRFs:\n",
11188 afi_safi_print(afi, safi));
11189
11190 for (ALL_LIST_ELEMENTS_RO(
11191 bgp->vpn_policy[afi].import_vrf,
11192 node, vname))
11193 vty_out(vty, " %s\n", vname);
11194
11195 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11196 ecom_str = ecommunity_ecom2str(
11197 bgp->vpn_policy[afi].rtlist[dir],
11198 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11199 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11200
11201 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11202 }
53089bec 11203
b46dfd20
DS
11204 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11205 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11206 vty_out(vty,
11207 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11208 afi_safi_print(afi, safi));
b46dfd20
DS
11209 else {
11210 vty_out(vty,
04c9077f 11211 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11212 afi_safi_print(afi, safi));
b46dfd20
DS
11213
11214 for (ALL_LIST_ELEMENTS_RO(
11215 bgp->vpn_policy[afi].export_vrf,
11216 node, vname))
11217 vty_out(vty, " %s\n", vname);
11218
11219 vty_out(vty, "RD: %s\n",
11220 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11221 buf1, RD_ADDRSTRLEN));
11222
11223 dir = BGP_VPN_POLICY_DIR_TOVPN;
11224 ecom_str = ecommunity_ecom2str(
11225 bgp->vpn_policy[afi].rtlist[dir],
11226 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11227 vty_out(vty, "Export RT: %s\n", ecom_str);
04c9077f 11228 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11229 }
53089bec 11230 }
11231
11232 return CMD_SUCCESS;
11233}
11234
11235/* "show [ip] bgp route-leak" command. */
11236DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11237 show_ip_bgp_route_leak_cmd,
11238 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11239 SHOW_STR
11240 IP_STR
11241 BGP_STR
11242 BGP_INSTANCE_HELP_STR
11243 BGP_AFI_HELP_STR
11244 BGP_SAFI_HELP_STR
11245 "Route leaking information\n"
11246 JSON_STR)
53089bec 11247{
11248 char *vrf = NULL;
11249 afi_t afi = AFI_MAX;
11250 safi_t safi = SAFI_MAX;
11251
9f049418 11252 bool uj = use_json(argc, argv);
53089bec 11253 int idx = 0;
11254
11255 /* show [ip] bgp */
11256 if (argv_find(argv, argc, "ip", &idx)) {
11257 afi = AFI_IP;
11258 safi = SAFI_UNICAST;
11259 }
11260 /* [vrf VIEWVRFNAME] */
11261 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11262 vty_out(vty,
11263 "%% This command is not applicable to BGP views\n");
53089bec 11264 return CMD_WARNING;
11265 }
11266
9a8bdf1c
PG
11267 if (argv_find(argv, argc, "vrf", &idx)) {
11268 vrf = argv[idx + 1]->arg;
11269 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11270 vrf = NULL;
11271 }
53089bec 11272 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11273 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11274 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11275 }
11276
11277 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11278 vty_out(vty,
11279 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11280 return CMD_WARNING;
11281 }
11282
b46dfd20 11283 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
53089bec 11284}
11285
d62a17ae 11286static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11287 safi_t safi)
f186de26 11288{
d62a17ae 11289 struct listnode *node, *nnode;
11290 struct bgp *bgp;
f186de26 11291
d62a17ae 11292 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11293 vty_out(vty, "\nInstance %s:\n",
11294 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11295 ? "Default"
11296 : bgp->name);
11297 update_group_show(bgp, afi, safi, vty, 0);
11298 }
f186de26 11299}
11300
d62a17ae 11301static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11302 int safi, uint64_t subgrp_id)
4fb25c53 11303{
d62a17ae 11304 struct bgp *bgp;
4fb25c53 11305
d62a17ae 11306 if (name) {
11307 if (strmatch(name, "all")) {
11308 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11309 return CMD_SUCCESS;
11310 } else {
11311 bgp = bgp_lookup_by_name(name);
11312 }
11313 } else {
11314 bgp = bgp_get_default();
11315 }
4fb25c53 11316
d62a17ae 11317 if (bgp)
11318 update_group_show(bgp, afi, safi, vty, subgrp_id);
11319 return CMD_SUCCESS;
4fb25c53
DW
11320}
11321
8fe8a7f6
DS
11322DEFUN (show_ip_bgp_updgrps,
11323 show_ip_bgp_updgrps_cmd,
c1a44e43 11324 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11325 SHOW_STR
11326 IP_STR
11327 BGP_STR
11328 BGP_INSTANCE_HELP_STR
c9e571b4 11329 BGP_AFI_HELP_STR
9bedbb1e 11330 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11331 "Detailed info about dynamic update groups\n"
11332 "Specific subgroup to display detailed info for\n")
8386ac43 11333{
d62a17ae 11334 char *vrf = NULL;
11335 afi_t afi = AFI_IP6;
11336 safi_t safi = SAFI_UNICAST;
11337 uint64_t subgrp_id = 0;
11338
11339 int idx = 0;
11340
11341 /* show [ip] bgp */
11342 if (argv_find(argv, argc, "ip", &idx))
11343 afi = AFI_IP;
9a8bdf1c
PG
11344 /* [<vrf> VIEWVRFNAME] */
11345 if (argv_find(argv, argc, "vrf", &idx)) {
11346 vrf = argv[idx + 1]->arg;
11347 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11348 vrf = NULL;
11349 } else if (argv_find(argv, argc, "view", &idx))
11350 /* [<view> VIEWVRFNAME] */
11351 vrf = argv[idx + 1]->arg;
d62a17ae 11352 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11353 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11354 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11355 }
5bf15956 11356
d62a17ae 11357 /* get subgroup id, if provided */
11358 idx = argc - 1;
11359 if (argv[idx]->type == VARIABLE_TKN)
11360 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11361
d62a17ae 11362 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11363}
11364
f186de26 11365DEFUN (show_bgp_instance_all_ipv6_updgrps,
11366 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11367 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11368 SHOW_STR
716b2d8a 11369 IP_STR
f186de26 11370 BGP_STR
11371 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11372 "Detailed info about dynamic update groups\n")
f186de26 11373{
d62a17ae 11374 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11375 return CMD_SUCCESS;
f186de26 11376}
11377
5bf15956
DW
11378DEFUN (show_bgp_updgrps_stats,
11379 show_bgp_updgrps_stats_cmd,
716b2d8a 11380 "show [ip] bgp update-groups statistics",
3f9c7369 11381 SHOW_STR
716b2d8a 11382 IP_STR
3f9c7369 11383 BGP_STR
0c7b1b01 11384 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11385 "Statistics\n")
11386{
d62a17ae 11387 struct bgp *bgp;
3f9c7369 11388
d62a17ae 11389 bgp = bgp_get_default();
11390 if (bgp)
11391 update_group_show_stats(bgp, vty);
3f9c7369 11392
d62a17ae 11393 return CMD_SUCCESS;
3f9c7369
DS
11394}
11395
8386ac43 11396DEFUN (show_bgp_instance_updgrps_stats,
11397 show_bgp_instance_updgrps_stats_cmd,
18c57037 11398 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11399 SHOW_STR
716b2d8a 11400 IP_STR
8386ac43 11401 BGP_STR
11402 BGP_INSTANCE_HELP_STR
0c7b1b01 11403 "Detailed info about dynamic update groups\n"
8386ac43 11404 "Statistics\n")
11405{
d62a17ae 11406 int idx_word = 3;
11407 struct bgp *bgp;
8386ac43 11408
d62a17ae 11409 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11410 if (bgp)
11411 update_group_show_stats(bgp, vty);
8386ac43 11412
d62a17ae 11413 return CMD_SUCCESS;
8386ac43 11414}
11415
d62a17ae 11416static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11417 afi_t afi, safi_t safi,
11418 const char *what, uint64_t subgrp_id)
3f9c7369 11419{
d62a17ae 11420 struct bgp *bgp;
8386ac43 11421
d62a17ae 11422 if (name)
11423 bgp = bgp_lookup_by_name(name);
11424 else
11425 bgp = bgp_get_default();
8386ac43 11426
d62a17ae 11427 if (bgp) {
11428 if (!strcmp(what, "advertise-queue"))
11429 update_group_show_adj_queue(bgp, afi, safi, vty,
11430 subgrp_id);
11431 else if (!strcmp(what, "advertised-routes"))
11432 update_group_show_advertised(bgp, afi, safi, vty,
11433 subgrp_id);
11434 else if (!strcmp(what, "packet-queue"))
11435 update_group_show_packet_queue(bgp, afi, safi, vty,
11436 subgrp_id);
11437 }
3f9c7369
DS
11438}
11439
dc64bdec
QY
11440DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11441 show_ip_bgp_instance_updgrps_adj_s_cmd,
11442 "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",
11443 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11444 BGP_SAFI_HELP_STR
11445 "Detailed info about dynamic update groups\n"
11446 "Specific subgroup to display info for\n"
11447 "Advertisement queue\n"
11448 "Announced routes\n"
11449 "Packet queue\n")
3f9c7369 11450{
dc64bdec
QY
11451 uint64_t subgrp_id = 0;
11452 afi_t afiz;
11453 safi_t safiz;
11454 if (sgid)
11455 subgrp_id = strtoull(sgid, NULL, 10);
11456
11457 if (!ip && !afi)
11458 afiz = AFI_IP6;
11459 if (!ip && afi)
11460 afiz = bgp_vty_afi_from_str(afi);
11461 if (ip && !afi)
11462 afiz = AFI_IP;
11463 if (ip && afi) {
11464 afiz = bgp_vty_afi_from_str(afi);
11465 if (afiz != AFI_IP)
11466 vty_out(vty,
11467 "%% Cannot specify both 'ip' and 'ipv6'\n");
11468 return CMD_WARNING;
11469 }
d62a17ae 11470
dc64bdec 11471 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11472
dc64bdec 11473 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11474 return CMD_SUCCESS;
11475}
11476
d62a17ae 11477static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11478{
11479 struct listnode *node, *nnode;
11480 struct prefix *range;
11481 struct peer *conf;
11482 struct peer *peer;
11483 char buf[PREFIX2STR_BUFFER];
11484 afi_t afi;
11485 safi_t safi;
11486 const char *peer_status;
11487 const char *af_str;
11488 int lr_count;
11489 int dynamic;
11490 int af_cfgd;
11491
11492 conf = group->conf;
11493
11494 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11495 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11496 conf->as);
11497 } else if (conf->as_type == AS_INTERNAL) {
11498 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11499 group->bgp->as);
11500 } else {
11501 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11502 }
f14e6fdb 11503
d62a17ae 11504 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11505 vty_out(vty, " Peer-group type is internal\n");
11506 else
11507 vty_out(vty, " Peer-group type is external\n");
11508
11509 /* Display AFs configured. */
11510 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11511 FOREACH_AFI_SAFI (afi, safi) {
11512 if (conf->afc[afi][safi]) {
11513 af_cfgd = 1;
11514 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11515 }
05c7a1cc 11516 }
d62a17ae 11517 if (!af_cfgd)
11518 vty_out(vty, " none\n");
11519 else
11520 vty_out(vty, "\n");
11521
11522 /* Display listen ranges (for dynamic neighbors), if any */
11523 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11524 if (afi == AFI_IP)
11525 af_str = "IPv4";
11526 else if (afi == AFI_IP6)
11527 af_str = "IPv6";
11528 else
11529 af_str = "???";
11530 lr_count = listcount(group->listen_range[afi]);
11531 if (lr_count) {
11532 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11533 af_str);
11534
11535
11536 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11537 nnode, range)) {
11538 prefix2str(range, buf, sizeof(buf));
11539 vty_out(vty, " %s\n", buf);
11540 }
11541 }
11542 }
f14e6fdb 11543
d62a17ae 11544 /* Display group members and their status */
11545 if (listcount(group->peer)) {
11546 vty_out(vty, " Peer-group members:\n");
11547 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11548 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11549 peer_status = "Idle (Admin)";
11550 else if (CHECK_FLAG(peer->sflags,
11551 PEER_STATUS_PREFIX_OVERFLOW))
11552 peer_status = "Idle (PfxCt)";
11553 else
11554 peer_status = lookup_msg(bgp_status_msg,
11555 peer->status, NULL);
11556
11557 dynamic = peer_dynamic_neighbor(peer);
11558 vty_out(vty, " %s %s %s \n", peer->host,
11559 dynamic ? "(dynamic)" : "", peer_status);
11560 }
11561 }
f14e6fdb 11562
d62a17ae 11563 return CMD_SUCCESS;
11564}
11565
ff9959b0
QY
11566static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11567 const char *group_name)
d62a17ae 11568{
ff9959b0 11569 struct bgp *bgp;
d62a17ae 11570 struct listnode *node, *nnode;
11571 struct peer_group *group;
ff9959b0
QY
11572 bool found = false;
11573
11574 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11575
11576 if (!bgp) {
9f049418 11577 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
11578 return CMD_WARNING;
11579 }
d62a17ae 11580
11581 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11582 if (group_name) {
11583 if (strmatch(group->name, group_name)) {
d62a17ae 11584 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11585 found = true;
11586 break;
d62a17ae 11587 }
ff9959b0
QY
11588 } else {
11589 bgp_show_one_peer_group(vty, group);
d62a17ae 11590 }
f14e6fdb 11591 }
f14e6fdb 11592
ff9959b0 11593 if (group_name && !found)
d62a17ae 11594 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11595
d62a17ae 11596 return CMD_SUCCESS;
f14e6fdb
DS
11597}
11598
f14e6fdb
DS
11599DEFUN (show_ip_bgp_peer_groups,
11600 show_ip_bgp_peer_groups_cmd,
18c57037 11601 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11602 SHOW_STR
11603 IP_STR
11604 BGP_STR
8386ac43 11605 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11606 "Detailed information on BGP peer groups\n"
11607 "Peer group name\n")
f14e6fdb 11608{
d62a17ae 11609 char *vrf, *pg;
d62a17ae 11610 int idx = 0;
f14e6fdb 11611
a4d82a8a
PZ
11612 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11613 : NULL;
d62a17ae 11614 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11615
ff9959b0 11616 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11617}
3f9c7369 11618
d6e3c605 11619
718e3744 11620/* Redistribute VTY commands. */
11621
718e3744 11622DEFUN (bgp_redistribute_ipv4,
11623 bgp_redistribute_ipv4_cmd,
40d1cbfb 11624 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11625 "Redistribute information from another routing protocol\n"
ab0181ee 11626 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11627{
d62a17ae 11628 VTY_DECLVAR_CONTEXT(bgp, bgp);
11629 int idx_protocol = 1;
11630 int type;
718e3744 11631
d62a17ae 11632 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11633 if (type < 0) {
11634 vty_out(vty, "%% Invalid route type\n");
11635 return CMD_WARNING_CONFIG_FAILED;
11636 }
7f323236 11637
d62a17ae 11638 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11639 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11640}
11641
d62a17ae 11642ALIAS_HIDDEN(
11643 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11644 "redistribute " FRR_IP_REDIST_STR_BGPD,
11645 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11646
718e3744 11647DEFUN (bgp_redistribute_ipv4_rmap,
11648 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11649 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11650 "Redistribute information from another routing protocol\n"
ab0181ee 11651 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11652 "Route map reference\n"
11653 "Pointer to route-map entries\n")
11654{
d62a17ae 11655 VTY_DECLVAR_CONTEXT(bgp, bgp);
11656 int idx_protocol = 1;
11657 int idx_word = 3;
11658 int type;
11659 struct bgp_redist *red;
e923dd62 11660 bool changed;
1de27621
DA
11661 struct route_map *route_map = route_map_lookup_warn_noexist(
11662 vty, argv[idx_word]->arg);
718e3744 11663
d62a17ae 11664 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11665 if (type < 0) {
11666 vty_out(vty, "%% Invalid route type\n");
11667 return CMD_WARNING_CONFIG_FAILED;
11668 }
718e3744 11669
d62a17ae 11670 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
11671 changed =
11672 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11673 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 11674}
11675
d62a17ae 11676ALIAS_HIDDEN(
11677 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11678 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11679 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11680 "Route map reference\n"
11681 "Pointer to route-map entries\n")
596c17ba 11682
718e3744 11683DEFUN (bgp_redistribute_ipv4_metric,
11684 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11685 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11686 "Redistribute information from another routing protocol\n"
ab0181ee 11687 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11688 "Metric for redistributed routes\n"
11689 "Default metric\n")
11690{
d62a17ae 11691 VTY_DECLVAR_CONTEXT(bgp, bgp);
11692 int idx_protocol = 1;
11693 int idx_number = 3;
11694 int type;
d7c0a89a 11695 uint32_t metric;
d62a17ae 11696 struct bgp_redist *red;
e923dd62 11697 bool changed;
d62a17ae 11698
11699 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11700 if (type < 0) {
11701 vty_out(vty, "%% Invalid route type\n");
11702 return CMD_WARNING_CONFIG_FAILED;
11703 }
11704 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11705
11706 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11707 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11708 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11709}
11710
11711ALIAS_HIDDEN(
11712 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11713 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11714 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11715 "Metric for redistributed routes\n"
11716 "Default metric\n")
596c17ba 11717
718e3744 11718DEFUN (bgp_redistribute_ipv4_rmap_metric,
11719 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11720 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11721 "Redistribute information from another routing protocol\n"
ab0181ee 11722 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11723 "Route map reference\n"
11724 "Pointer to route-map entries\n"
11725 "Metric for redistributed routes\n"
11726 "Default metric\n")
11727{
d62a17ae 11728 VTY_DECLVAR_CONTEXT(bgp, bgp);
11729 int idx_protocol = 1;
11730 int idx_word = 3;
11731 int idx_number = 5;
11732 int type;
d7c0a89a 11733 uint32_t metric;
d62a17ae 11734 struct bgp_redist *red;
e923dd62 11735 bool changed;
1de27621
DA
11736 struct route_map *route_map =
11737 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11738
11739 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11740 if (type < 0) {
11741 vty_out(vty, "%% Invalid route type\n");
11742 return CMD_WARNING_CONFIG_FAILED;
11743 }
11744 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11745
11746 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
11747 changed =
11748 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11749 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11750 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11751}
11752
11753ALIAS_HIDDEN(
11754 bgp_redistribute_ipv4_rmap_metric,
11755 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11756 "redistribute " FRR_IP_REDIST_STR_BGPD
11757 " route-map WORD metric (0-4294967295)",
11758 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11759 "Route map reference\n"
11760 "Pointer to route-map entries\n"
11761 "Metric for redistributed routes\n"
11762 "Default metric\n")
596c17ba 11763
718e3744 11764DEFUN (bgp_redistribute_ipv4_metric_rmap,
11765 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11766 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11767 "Redistribute information from another routing protocol\n"
ab0181ee 11768 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11769 "Metric for redistributed routes\n"
11770 "Default metric\n"
11771 "Route map reference\n"
11772 "Pointer to route-map entries\n")
11773{
d62a17ae 11774 VTY_DECLVAR_CONTEXT(bgp, bgp);
11775 int idx_protocol = 1;
11776 int idx_number = 3;
11777 int idx_word = 5;
11778 int type;
d7c0a89a 11779 uint32_t metric;
d62a17ae 11780 struct bgp_redist *red;
e923dd62 11781 bool changed;
1de27621
DA
11782 struct route_map *route_map =
11783 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11784
11785 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11786 if (type < 0) {
11787 vty_out(vty, "%% Invalid route type\n");
11788 return CMD_WARNING_CONFIG_FAILED;
11789 }
11790 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11791
11792 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11793 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
11794 changed |=
11795 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11796 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11797}
11798
11799ALIAS_HIDDEN(
11800 bgp_redistribute_ipv4_metric_rmap,
11801 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11802 "redistribute " FRR_IP_REDIST_STR_BGPD
11803 " metric (0-4294967295) route-map WORD",
11804 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11805 "Metric for redistributed routes\n"
11806 "Default metric\n"
11807 "Route map reference\n"
11808 "Pointer to route-map entries\n")
596c17ba 11809
7c8ff89e
DS
11810DEFUN (bgp_redistribute_ipv4_ospf,
11811 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11812 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11813 "Redistribute information from another routing protocol\n"
11814 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11815 "Non-main Kernel Routing Table\n"
11816 "Instance ID/Table ID\n")
7c8ff89e 11817{
d62a17ae 11818 VTY_DECLVAR_CONTEXT(bgp, bgp);
11819 int idx_ospf_table = 1;
11820 int idx_number = 2;
d7c0a89a
QY
11821 unsigned short instance;
11822 unsigned short protocol;
7c8ff89e 11823
d62a17ae 11824 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11825
d62a17ae 11826 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11827 protocol = ZEBRA_ROUTE_OSPF;
11828 else
11829 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11830
d62a17ae 11831 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11832 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
11833}
11834
d62a17ae 11835ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11836 "redistribute <ospf|table> (1-65535)",
11837 "Redistribute information from another routing protocol\n"
11838 "Open Shortest Path First (OSPFv2)\n"
11839 "Non-main Kernel Routing Table\n"
11840 "Instance ID/Table ID\n")
596c17ba 11841
7c8ff89e
DS
11842DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11843 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11844 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11845 "Redistribute information from another routing protocol\n"
11846 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11847 "Non-main Kernel Routing Table\n"
11848 "Instance ID/Table ID\n"
7c8ff89e
DS
11849 "Route map reference\n"
11850 "Pointer to route-map entries\n")
11851{
d62a17ae 11852 VTY_DECLVAR_CONTEXT(bgp, bgp);
11853 int idx_ospf_table = 1;
11854 int idx_number = 2;
11855 int idx_word = 4;
11856 struct bgp_redist *red;
d7c0a89a 11857 unsigned short instance;
d62a17ae 11858 int protocol;
e923dd62 11859 bool changed;
1de27621
DA
11860 struct route_map *route_map =
11861 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11862
11863 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11864 protocol = ZEBRA_ROUTE_OSPF;
11865 else
11866 protocol = ZEBRA_ROUTE_TABLE;
11867
11868 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11869 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
11870 changed =
11871 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11872 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11873}
11874
11875ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11876 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11877 "redistribute <ospf|table> (1-65535) route-map WORD",
11878 "Redistribute information from another routing protocol\n"
11879 "Open Shortest Path First (OSPFv2)\n"
11880 "Non-main Kernel Routing Table\n"
11881 "Instance ID/Table ID\n"
11882 "Route map reference\n"
11883 "Pointer to route-map entries\n")
596c17ba 11884
7c8ff89e
DS
11885DEFUN (bgp_redistribute_ipv4_ospf_metric,
11886 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11887 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11888 "Redistribute information from another routing protocol\n"
11889 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11890 "Non-main Kernel Routing Table\n"
11891 "Instance ID/Table ID\n"
7c8ff89e
DS
11892 "Metric for redistributed routes\n"
11893 "Default metric\n")
11894{
d62a17ae 11895 VTY_DECLVAR_CONTEXT(bgp, bgp);
11896 int idx_ospf_table = 1;
11897 int idx_number = 2;
11898 int idx_number_2 = 4;
d7c0a89a 11899 uint32_t metric;
d62a17ae 11900 struct bgp_redist *red;
d7c0a89a 11901 unsigned short instance;
d62a17ae 11902 int protocol;
e923dd62 11903 bool changed;
d62a17ae 11904
11905 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11906 protocol = ZEBRA_ROUTE_OSPF;
11907 else
11908 protocol = ZEBRA_ROUTE_TABLE;
11909
11910 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11911 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11912
11913 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11914 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11915 metric);
11916 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11917}
11918
11919ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11920 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11921 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11922 "Redistribute information from another routing protocol\n"
11923 "Open Shortest Path First (OSPFv2)\n"
11924 "Non-main Kernel Routing Table\n"
11925 "Instance ID/Table ID\n"
11926 "Metric for redistributed routes\n"
11927 "Default metric\n")
596c17ba 11928
7c8ff89e
DS
11929DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11930 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11931 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11932 "Redistribute information from another routing protocol\n"
11933 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11934 "Non-main Kernel Routing Table\n"
11935 "Instance ID/Table ID\n"
7c8ff89e
DS
11936 "Route map reference\n"
11937 "Pointer to route-map entries\n"
11938 "Metric for redistributed routes\n"
11939 "Default metric\n")
11940{
d62a17ae 11941 VTY_DECLVAR_CONTEXT(bgp, bgp);
11942 int idx_ospf_table = 1;
11943 int idx_number = 2;
11944 int idx_word = 4;
11945 int idx_number_2 = 6;
d7c0a89a 11946 uint32_t metric;
d62a17ae 11947 struct bgp_redist *red;
d7c0a89a 11948 unsigned short instance;
d62a17ae 11949 int protocol;
e923dd62 11950 bool changed;
1de27621
DA
11951 struct route_map *route_map =
11952 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11953
11954 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11955 protocol = ZEBRA_ROUTE_OSPF;
11956 else
11957 protocol = ZEBRA_ROUTE_TABLE;
11958
11959 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11960 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11961
11962 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
11963 changed =
11964 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11965 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11966 metric);
11967 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11968}
11969
11970ALIAS_HIDDEN(
11971 bgp_redistribute_ipv4_ospf_rmap_metric,
11972 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11973 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11974 "Redistribute information from another routing protocol\n"
11975 "Open Shortest Path First (OSPFv2)\n"
11976 "Non-main Kernel Routing Table\n"
11977 "Instance ID/Table ID\n"
11978 "Route map reference\n"
11979 "Pointer to route-map entries\n"
11980 "Metric for redistributed routes\n"
11981 "Default metric\n")
596c17ba 11982
7c8ff89e
DS
11983DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11984 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11985 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11986 "Redistribute information from another routing protocol\n"
11987 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11988 "Non-main Kernel Routing Table\n"
11989 "Instance ID/Table ID\n"
7c8ff89e
DS
11990 "Metric for redistributed routes\n"
11991 "Default metric\n"
11992 "Route map reference\n"
11993 "Pointer to route-map entries\n")
11994{
d62a17ae 11995 VTY_DECLVAR_CONTEXT(bgp, bgp);
11996 int idx_ospf_table = 1;
11997 int idx_number = 2;
11998 int idx_number_2 = 4;
11999 int idx_word = 6;
d7c0a89a 12000 uint32_t metric;
d62a17ae 12001 struct bgp_redist *red;
d7c0a89a 12002 unsigned short instance;
d62a17ae 12003 int protocol;
e923dd62 12004 bool changed;
1de27621
DA
12005 struct route_map *route_map =
12006 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12007
12008 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12009 protocol = ZEBRA_ROUTE_OSPF;
12010 else
12011 protocol = ZEBRA_ROUTE_TABLE;
12012
12013 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12014 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12015
12016 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12017 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12018 metric);
1de27621
DA
12019 changed |=
12020 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12021 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12022}
12023
12024ALIAS_HIDDEN(
12025 bgp_redistribute_ipv4_ospf_metric_rmap,
12026 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12027 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12028 "Redistribute information from another routing protocol\n"
12029 "Open Shortest Path First (OSPFv2)\n"
12030 "Non-main Kernel Routing Table\n"
12031 "Instance ID/Table ID\n"
12032 "Metric for redistributed routes\n"
12033 "Default metric\n"
12034 "Route map reference\n"
12035 "Pointer to route-map entries\n")
596c17ba 12036
7c8ff89e
DS
12037DEFUN (no_bgp_redistribute_ipv4_ospf,
12038 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 12039 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
12040 NO_STR
12041 "Redistribute information from another routing protocol\n"
12042 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12043 "Non-main Kernel Routing Table\n"
31500417
DW
12044 "Instance ID/Table ID\n"
12045 "Metric for redistributed routes\n"
12046 "Default metric\n"
12047 "Route map reference\n"
12048 "Pointer to route-map entries\n")
7c8ff89e 12049{
d62a17ae 12050 VTY_DECLVAR_CONTEXT(bgp, bgp);
12051 int idx_ospf_table = 2;
12052 int idx_number = 3;
d7c0a89a 12053 unsigned short instance;
d62a17ae 12054 int protocol;
12055
12056 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12057 protocol = ZEBRA_ROUTE_OSPF;
12058 else
12059 protocol = ZEBRA_ROUTE_TABLE;
12060
12061 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12062 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12063}
12064
12065ALIAS_HIDDEN(
12066 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12067 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12068 NO_STR
12069 "Redistribute information from another routing protocol\n"
12070 "Open Shortest Path First (OSPFv2)\n"
12071 "Non-main Kernel Routing Table\n"
12072 "Instance ID/Table ID\n"
12073 "Metric for redistributed routes\n"
12074 "Default metric\n"
12075 "Route map reference\n"
12076 "Pointer to route-map entries\n")
596c17ba 12077
718e3744 12078DEFUN (no_bgp_redistribute_ipv4,
12079 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 12080 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12081 NO_STR
12082 "Redistribute information from another routing protocol\n"
3b14d86e 12083 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12084 "Metric for redistributed routes\n"
12085 "Default metric\n"
12086 "Route map reference\n"
12087 "Pointer to route-map entries\n")
718e3744 12088{
d62a17ae 12089 VTY_DECLVAR_CONTEXT(bgp, bgp);
12090 int idx_protocol = 2;
12091 int type;
12092
12093 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12094 if (type < 0) {
12095 vty_out(vty, "%% Invalid route type\n");
12096 return CMD_WARNING_CONFIG_FAILED;
12097 }
12098 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12099}
12100
12101ALIAS_HIDDEN(
12102 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12103 "no redistribute " FRR_IP_REDIST_STR_BGPD
12104 " [metric (0-4294967295)] [route-map WORD]",
12105 NO_STR
12106 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12107 "Metric for redistributed routes\n"
12108 "Default metric\n"
12109 "Route map reference\n"
12110 "Pointer to route-map entries\n")
596c17ba 12111
718e3744 12112DEFUN (bgp_redistribute_ipv6,
12113 bgp_redistribute_ipv6_cmd,
40d1cbfb 12114 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12115 "Redistribute information from another routing protocol\n"
ab0181ee 12116 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12117{
d62a17ae 12118 VTY_DECLVAR_CONTEXT(bgp, bgp);
12119 int idx_protocol = 1;
12120 int type;
718e3744 12121
d62a17ae 12122 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12123 if (type < 0) {
12124 vty_out(vty, "%% Invalid route type\n");
12125 return CMD_WARNING_CONFIG_FAILED;
12126 }
718e3744 12127
d62a17ae 12128 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12129 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12130}
12131
12132DEFUN (bgp_redistribute_ipv6_rmap,
12133 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12134 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12135 "Redistribute information from another routing protocol\n"
ab0181ee 12136 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12137 "Route map reference\n"
12138 "Pointer to route-map entries\n")
12139{
d62a17ae 12140 VTY_DECLVAR_CONTEXT(bgp, bgp);
12141 int idx_protocol = 1;
12142 int idx_word = 3;
12143 int type;
12144 struct bgp_redist *red;
e923dd62 12145 bool changed;
1de27621
DA
12146 struct route_map *route_map =
12147 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12148
d62a17ae 12149 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12150 if (type < 0) {
12151 vty_out(vty, "%% Invalid route type\n");
12152 return CMD_WARNING_CONFIG_FAILED;
12153 }
718e3744 12154
d62a17ae 12155 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12156 changed =
12157 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12158 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12159}
12160
12161DEFUN (bgp_redistribute_ipv6_metric,
12162 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12163 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12164 "Redistribute information from another routing protocol\n"
ab0181ee 12165 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12166 "Metric for redistributed routes\n"
12167 "Default metric\n")
12168{
d62a17ae 12169 VTY_DECLVAR_CONTEXT(bgp, bgp);
12170 int idx_protocol = 1;
12171 int idx_number = 3;
12172 int type;
d7c0a89a 12173 uint32_t metric;
d62a17ae 12174 struct bgp_redist *red;
e923dd62 12175 bool changed;
d62a17ae 12176
12177 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12178 if (type < 0) {
12179 vty_out(vty, "%% Invalid route type\n");
12180 return CMD_WARNING_CONFIG_FAILED;
12181 }
12182 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12183
d62a17ae 12184 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12185 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12186 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12187}
12188
12189DEFUN (bgp_redistribute_ipv6_rmap_metric,
12190 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12191 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12192 "Redistribute information from another routing protocol\n"
ab0181ee 12193 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12194 "Route map reference\n"
12195 "Pointer to route-map entries\n"
12196 "Metric for redistributed routes\n"
12197 "Default metric\n")
12198{
d62a17ae 12199 VTY_DECLVAR_CONTEXT(bgp, bgp);
12200 int idx_protocol = 1;
12201 int idx_word = 3;
12202 int idx_number = 5;
12203 int type;
d7c0a89a 12204 uint32_t metric;
d62a17ae 12205 struct bgp_redist *red;
e923dd62 12206 bool changed;
1de27621
DA
12207 struct route_map *route_map =
12208 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12209
12210 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12211 if (type < 0) {
12212 vty_out(vty, "%% Invalid route type\n");
12213 return CMD_WARNING_CONFIG_FAILED;
12214 }
12215 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12216
d62a17ae 12217 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12218 changed =
12219 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12220 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12221 metric);
12222 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12223}
12224
12225DEFUN (bgp_redistribute_ipv6_metric_rmap,
12226 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12227 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12228 "Redistribute information from another routing protocol\n"
ab0181ee 12229 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12230 "Metric for redistributed routes\n"
12231 "Default metric\n"
12232 "Route map reference\n"
12233 "Pointer to route-map entries\n")
12234{
d62a17ae 12235 VTY_DECLVAR_CONTEXT(bgp, bgp);
12236 int idx_protocol = 1;
12237 int idx_number = 3;
12238 int idx_word = 5;
12239 int type;
d7c0a89a 12240 uint32_t metric;
d62a17ae 12241 struct bgp_redist *red;
e923dd62 12242 bool changed;
1de27621
DA
12243 struct route_map *route_map =
12244 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12245
12246 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12247 if (type < 0) {
12248 vty_out(vty, "%% Invalid route type\n");
12249 return CMD_WARNING_CONFIG_FAILED;
12250 }
12251 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12252
d62a17ae 12253 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12254 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12255 metric);
1de27621
DA
12256 changed |=
12257 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12258 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12259}
12260
12261DEFUN (no_bgp_redistribute_ipv6,
12262 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12263 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12264 NO_STR
12265 "Redistribute information from another routing protocol\n"
3b14d86e 12266 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12267 "Metric for redistributed routes\n"
12268 "Default metric\n"
12269 "Route map reference\n"
12270 "Pointer to route-map entries\n")
718e3744 12271{
d62a17ae 12272 VTY_DECLVAR_CONTEXT(bgp, bgp);
12273 int idx_protocol = 2;
12274 int type;
718e3744 12275
d62a17ae 12276 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12277 if (type < 0) {
12278 vty_out(vty, "%% Invalid route type\n");
12279 return CMD_WARNING_CONFIG_FAILED;
12280 }
718e3744 12281
d62a17ae 12282 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12283}
12284
2b791107 12285void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12286 safi_t safi)
d62a17ae 12287{
12288 int i;
12289
12290 /* Unicast redistribution only. */
12291 if (safi != SAFI_UNICAST)
2b791107 12292 return;
d62a17ae 12293
12294 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12295 /* Redistribute BGP does not make sense. */
12296 if (i != ZEBRA_ROUTE_BGP) {
12297 struct list *red_list;
12298 struct listnode *node;
12299 struct bgp_redist *red;
12300
12301 red_list = bgp->redist[afi][i];
12302 if (!red_list)
12303 continue;
12304
12305 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12306 /* "redistribute" configuration. */
12307 vty_out(vty, " redistribute %s",
12308 zebra_route_string(i));
12309 if (red->instance)
12310 vty_out(vty, " %d", red->instance);
12311 if (red->redist_metric_flag)
12312 vty_out(vty, " metric %u",
12313 red->redist_metric);
12314 if (red->rmap.name)
12315 vty_out(vty, " route-map %s",
12316 red->rmap.name);
12317 vty_out(vty, "\n");
12318 }
12319 }
12320 }
718e3744 12321}
6b0655a2 12322
b9c7bc5a
PZ
12323/* This is part of the address-family block (unicast only) */
12324void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12325 afi_t afi)
12326{
b9c7bc5a 12327 int indent = 2;
ddb5b488 12328
bb4f6190
DS
12329 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12330 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12331 bgp->vpn_policy[afi]
12332 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12333
12a844a5
DS
12334 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12335 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12336 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12337 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12338 return;
12339
e70e9f8e
PZ
12340 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12341 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12342
12343 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12344
12345 } else {
12346 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12347 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12348 bgp->vpn_policy[afi].tovpn_label);
12349 }
ddb5b488
PZ
12350 }
12351 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12352 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12353 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12354 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12355 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12356 sizeof(buf)));
12357 }
12358 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12359 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12360
12361 char buf[PREFIX_STRLEN];
12362 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12363 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12364 sizeof(buf))) {
12365
b9c7bc5a
PZ
12366 vty_out(vty, "%*snexthop vpn export %s\n",
12367 indent, "", buf);
ddb5b488
PZ
12368 }
12369 }
12370 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12371 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12372 && ecommunity_cmp(
12373 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12374 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12375
12376 char *b = ecommunity_ecom2str(
12377 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12378 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12379 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12380 XFREE(MTYPE_ECOMMUNITY_STR, b);
12381 } else {
12382 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12383 char *b = ecommunity_ecom2str(
12384 bgp->vpn_policy[afi]
12385 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12386 ECOMMUNITY_FORMAT_ROUTE_MAP,
12387 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12388 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12389 XFREE(MTYPE_ECOMMUNITY_STR, b);
12390 }
12391 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12392 char *b = ecommunity_ecom2str(
12393 bgp->vpn_policy[afi]
12394 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12395 ECOMMUNITY_FORMAT_ROUTE_MAP,
12396 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12397 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12398 XFREE(MTYPE_ECOMMUNITY_STR, b);
12399 }
12400 }
bb4f6190
DS
12401
12402 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12403 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12404 bgp->vpn_policy[afi]
12405 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12406
301ad80a
PG
12407 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12408 char *b = ecommunity_ecom2str(
12409 bgp->vpn_policy[afi]
12410 .import_redirect_rtlist,
12411 ECOMMUNITY_FORMAT_ROUTE_MAP,
12412 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12413
301ad80a
PG
12414 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12415 XFREE(MTYPE_ECOMMUNITY_STR, b);
12416 }
ddb5b488
PZ
12417}
12418
12419
718e3744 12420/* BGP node structure. */
d62a17ae 12421static struct cmd_node bgp_node = {
9d303b37 12422 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12423};
12424
d62a17ae 12425static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12426 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12427};
12428
d62a17ae 12429static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12430 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12431};
12432
d62a17ae 12433static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12434 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12435};
12436
d62a17ae 12437static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12438 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12439};
12440
d62a17ae 12441static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12442 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12443};
12444
d62a17ae 12445static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12446 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12447};
12448
d62a17ae 12449static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12450 "%s(config-router-af)# ", 1};
6b0655a2 12451
d62a17ae 12452static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12453 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12454
d62a17ae 12455static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12456 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12457
d62a17ae 12458static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12459 "%s(config-router-af-vni)# ", 1};
90e60aa7 12460
7c40bf39 12461static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12462 "%s(config-router-af)# ", 1};
12463
12464static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12465 "%s(config-router-af-vpnv6)# ", 1};
12466
d62a17ae 12467static void community_list_vty(void);
1f8ae70b 12468
d62a17ae 12469static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12470{
d62a17ae 12471 struct bgp *bgp;
12472 struct peer *peer;
d62a17ae 12473 struct listnode *lnbgp, *lnpeer;
b8a815e5 12474
d62a17ae 12475 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12476 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12477 /* only provide suggestions on the appropriate input
12478 * token type,
12479 * they'll otherwise show up multiple times */
12480 enum cmd_token_type match_type;
12481 char *name = peer->host;
d48ed3e0 12482
d62a17ae 12483 if (peer->conf_if) {
12484 match_type = VARIABLE_TKN;
12485 name = peer->conf_if;
12486 } else if (strchr(peer->host, ':'))
12487 match_type = IPV6_TKN;
12488 else
12489 match_type = IPV4_TKN;
d48ed3e0 12490
d62a17ae 12491 if (token->type != match_type)
12492 continue;
d48ed3e0 12493
d62a17ae 12494 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12495 }
d62a17ae 12496 }
b8a815e5
DL
12497}
12498
12499static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12500 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12501 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12502 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12503 {.completions = NULL}};
12504
47a306a0
DS
12505static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12506{
12507 struct bgp *bgp;
12508 struct peer_group *group;
12509 struct listnode *lnbgp, *lnpeer;
12510
12511 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12512 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12513 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12514 group->name));
12515 }
12516}
12517
12518static const struct cmd_variable_handler bgp_var_peergroup[] = {
12519 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12520 {.completions = NULL} };
12521
d62a17ae 12522void bgp_vty_init(void)
12523{
12524 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12525 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12526
12527 /* Install bgp top node. */
12528 install_node(&bgp_node, bgp_config_write);
12529 install_node(&bgp_ipv4_unicast_node, NULL);
12530 install_node(&bgp_ipv4_multicast_node, NULL);
12531 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12532 install_node(&bgp_ipv6_unicast_node, NULL);
12533 install_node(&bgp_ipv6_multicast_node, NULL);
12534 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12535 install_node(&bgp_vpnv4_node, NULL);
12536 install_node(&bgp_vpnv6_node, NULL);
12537 install_node(&bgp_evpn_node, NULL);
12538 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12539 install_node(&bgp_flowspecv4_node, NULL);
12540 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12541
12542 /* Install default VTY commands to new nodes. */
12543 install_default(BGP_NODE);
12544 install_default(BGP_IPV4_NODE);
12545 install_default(BGP_IPV4M_NODE);
12546 install_default(BGP_IPV4L_NODE);
12547 install_default(BGP_IPV6_NODE);
12548 install_default(BGP_IPV6M_NODE);
12549 install_default(BGP_IPV6L_NODE);
12550 install_default(BGP_VPNV4_NODE);
12551 install_default(BGP_VPNV6_NODE);
7c40bf39 12552 install_default(BGP_FLOWSPECV4_NODE);
12553 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12554 install_default(BGP_EVPN_NODE);
12555 install_default(BGP_EVPN_VNI_NODE);
12556
12557 /* "bgp multiple-instance" commands. */
12558 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12559 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12560
12561 /* "bgp config-type" commands. */
12562 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12563 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12564
12565 /* bgp route-map delay-timer commands. */
12566 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12567 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12568
12569 /* Dummy commands (Currently not supported) */
12570 install_element(BGP_NODE, &no_synchronization_cmd);
12571 install_element(BGP_NODE, &no_auto_summary_cmd);
12572
12573 /* "router bgp" commands. */
12574 install_element(CONFIG_NODE, &router_bgp_cmd);
12575
12576 /* "no router bgp" commands. */
12577 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12578
12579 /* "bgp router-id" commands. */
12580 install_element(BGP_NODE, &bgp_router_id_cmd);
12581 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12582
12583 /* "bgp cluster-id" commands. */
12584 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12585 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12586
12587 /* "bgp confederation" commands. */
12588 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12589 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12590
12591 /* "bgp confederation peers" commands. */
12592 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12593 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12594
12595 /* bgp max-med command */
12596 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12597 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12598 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12599 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12600 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12601
12602 /* bgp disable-ebgp-connected-nh-check */
12603 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12604 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12605
12606 /* bgp update-delay command */
12607 install_element(BGP_NODE, &bgp_update_delay_cmd);
12608 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12609 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12610
12611 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12612 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12613 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12614 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12615
12616 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12617 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12618
12619 /* "maximum-paths" commands. */
12620 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12621 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12622 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12623 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12624 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12625 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12626 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12627 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12628 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12629 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12630 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12631 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12632 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12633 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12634 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12635
12636 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12637 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12638 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12639 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12640 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12641
12642 /* "timers bgp" commands. */
12643 install_element(BGP_NODE, &bgp_timers_cmd);
12644 install_element(BGP_NODE, &no_bgp_timers_cmd);
12645
12646 /* route-map delay-timer commands - per instance for backwards compat.
12647 */
12648 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12649 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12650
12651 /* "bgp client-to-client reflection" commands */
12652 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12653 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12654
12655 /* "bgp always-compare-med" commands */
12656 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12657 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12658
12659 /* "bgp deterministic-med" commands */
12660 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12661 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12662
12663 /* "bgp graceful-restart" commands */
12664 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12665 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12666 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12667 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12668 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12669 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12670
12671 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12672 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12673
7f323236
DW
12674 /* "bgp graceful-shutdown" commands */
12675 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12676 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12677
d62a17ae 12678 /* "bgp fast-external-failover" commands */
12679 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12680 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12681
12682 /* "bgp enforce-first-as" commands */
12683 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 12684
12685 /* "bgp bestpath compare-routerid" commands */
12686 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12687 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12688
12689 /* "bgp bestpath as-path ignore" commands */
12690 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12691 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12692
12693 /* "bgp bestpath as-path confed" commands */
12694 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12695 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12696
12697 /* "bgp bestpath as-path multipath-relax" commands */
12698 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12699 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12700
12701 /* "bgp log-neighbor-changes" commands */
12702 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12703 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12704
12705 /* "bgp bestpath med" commands */
12706 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12707 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12708
12709 /* "no bgp default ipv4-unicast" commands. */
12710 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12711 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12712
12713 /* "bgp network import-check" commands. */
12714 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12715 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12716 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12717
12718 /* "bgp default local-preference" commands. */
12719 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12720 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12721
12722 /* bgp default show-hostname */
12723 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12724 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12725
12726 /* "bgp default subgroup-pkt-queue-max" commands. */
12727 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12728 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12729
12730 /* bgp ibgp-allow-policy-mods command */
12731 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12732 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12733
12734 /* "bgp listen limit" commands. */
12735 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12736 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12737
12738 /* "bgp listen range" commands. */
12739 install_element(BGP_NODE, &bgp_listen_range_cmd);
12740 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12741
8175f54a 12742 /* "bgp default shutdown" command */
f26845f9
QY
12743 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12744
d62a17ae 12745 /* "neighbor remote-as" commands. */
12746 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12747 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12748 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12749 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12750 install_element(BGP_NODE,
12751 &neighbor_interface_v6only_config_remote_as_cmd);
12752 install_element(BGP_NODE, &no_neighbor_cmd);
12753 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12754
12755 /* "neighbor peer-group" commands. */
12756 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12757 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12758 install_element(BGP_NODE,
12759 &no_neighbor_interface_peer_group_remote_as_cmd);
12760
12761 /* "neighbor local-as" commands. */
12762 install_element(BGP_NODE, &neighbor_local_as_cmd);
12763 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12764 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12765 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12766
12767 /* "neighbor solo" commands. */
12768 install_element(BGP_NODE, &neighbor_solo_cmd);
12769 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12770
12771 /* "neighbor password" commands. */
12772 install_element(BGP_NODE, &neighbor_password_cmd);
12773 install_element(BGP_NODE, &no_neighbor_password_cmd);
12774
12775 /* "neighbor activate" commands. */
12776 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12777 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12778 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12779 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12780 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12781 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12782 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12783 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12784 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12785 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12786 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12787 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12788
12789 /* "no neighbor activate" commands. */
12790 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12791 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12792 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12793 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12794 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12795 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12796 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12797 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12798 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12799 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12800 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12801 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12802
12803 /* "neighbor peer-group" set commands. */
12804 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12805 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12806 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12807 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12808 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12809 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12810 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12811 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12812 install_element(BGP_FLOWSPECV4_NODE,
12813 &neighbor_set_peer_group_hidden_cmd);
12814 install_element(BGP_FLOWSPECV6_NODE,
12815 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12816
12817 /* "no neighbor peer-group unset" commands. */
12818 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12819 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12820 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12821 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12822 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12823 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12824 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12825 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12826 install_element(BGP_FLOWSPECV4_NODE,
12827 &no_neighbor_set_peer_group_hidden_cmd);
12828 install_element(BGP_FLOWSPECV6_NODE,
12829 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12830
12831 /* "neighbor softreconfiguration inbound" commands.*/
12832 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12833 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12834 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12835 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12836 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12837 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12838 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12839 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12840 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12841 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12842 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12843 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12844 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12845 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12846 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12847 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12848 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12849 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12850 install_element(BGP_FLOWSPECV4_NODE,
12851 &neighbor_soft_reconfiguration_cmd);
12852 install_element(BGP_FLOWSPECV4_NODE,
12853 &no_neighbor_soft_reconfiguration_cmd);
12854 install_element(BGP_FLOWSPECV6_NODE,
12855 &neighbor_soft_reconfiguration_cmd);
12856 install_element(BGP_FLOWSPECV6_NODE,
12857 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12858
12859 /* "neighbor attribute-unchanged" commands. */
12860 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12861 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12862 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12863 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12864 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12865 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12866 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12867 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12868 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12869 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12870 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12871 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12872 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12873 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12874 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12875 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12876 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12877 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12878
12879 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12880 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12881
12882 /* "nexthop-local unchanged" commands */
12883 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12884 install_element(BGP_IPV6_NODE,
12885 &no_neighbor_nexthop_local_unchanged_cmd);
12886
12887 /* "neighbor next-hop-self" commands. */
12888 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12889 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12890 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12891 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12892 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12893 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12894 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12895 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12896 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12897 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12898 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12899 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12900 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12901 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12902 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12903 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12904 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12905 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
12906 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12907 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 12908
12909 /* "neighbor next-hop-self force" commands. */
12910 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12911 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12912 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12913 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12914 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12915 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12916 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12917 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12918 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12919 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12920 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12921 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12922 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12923 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12924 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12925 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12926 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12927 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12928
12929 /* "neighbor as-override" commands. */
12930 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12931 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12932 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12933 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12934 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12935 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12936 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12937 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12938 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12939 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12940 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12941 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12942 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12943 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12944 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12945 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12946 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12947 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12948
12949 /* "neighbor remove-private-AS" commands. */
12950 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12951 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12952 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12953 install_element(BGP_NODE,
12954 &no_neighbor_remove_private_as_all_hidden_cmd);
12955 install_element(BGP_NODE,
12956 &neighbor_remove_private_as_replace_as_hidden_cmd);
12957 install_element(BGP_NODE,
12958 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12959 install_element(BGP_NODE,
12960 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12961 install_element(
12962 BGP_NODE,
12963 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12964 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12965 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12966 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12967 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12968 install_element(BGP_IPV4_NODE,
12969 &neighbor_remove_private_as_replace_as_cmd);
12970 install_element(BGP_IPV4_NODE,
12971 &no_neighbor_remove_private_as_replace_as_cmd);
12972 install_element(BGP_IPV4_NODE,
12973 &neighbor_remove_private_as_all_replace_as_cmd);
12974 install_element(BGP_IPV4_NODE,
12975 &no_neighbor_remove_private_as_all_replace_as_cmd);
12976 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12977 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12978 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12979 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12980 install_element(BGP_IPV4M_NODE,
12981 &neighbor_remove_private_as_replace_as_cmd);
12982 install_element(BGP_IPV4M_NODE,
12983 &no_neighbor_remove_private_as_replace_as_cmd);
12984 install_element(BGP_IPV4M_NODE,
12985 &neighbor_remove_private_as_all_replace_as_cmd);
12986 install_element(BGP_IPV4M_NODE,
12987 &no_neighbor_remove_private_as_all_replace_as_cmd);
12988 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12989 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12990 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12991 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12992 install_element(BGP_IPV4L_NODE,
12993 &neighbor_remove_private_as_replace_as_cmd);
12994 install_element(BGP_IPV4L_NODE,
12995 &no_neighbor_remove_private_as_replace_as_cmd);
12996 install_element(BGP_IPV4L_NODE,
12997 &neighbor_remove_private_as_all_replace_as_cmd);
12998 install_element(BGP_IPV4L_NODE,
12999 &no_neighbor_remove_private_as_all_replace_as_cmd);
13000 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13001 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13002 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13003 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13004 install_element(BGP_IPV6_NODE,
13005 &neighbor_remove_private_as_replace_as_cmd);
13006 install_element(BGP_IPV6_NODE,
13007 &no_neighbor_remove_private_as_replace_as_cmd);
13008 install_element(BGP_IPV6_NODE,
13009 &neighbor_remove_private_as_all_replace_as_cmd);
13010 install_element(BGP_IPV6_NODE,
13011 &no_neighbor_remove_private_as_all_replace_as_cmd);
13012 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13013 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13014 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13015 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13016 install_element(BGP_IPV6M_NODE,
13017 &neighbor_remove_private_as_replace_as_cmd);
13018 install_element(BGP_IPV6M_NODE,
13019 &no_neighbor_remove_private_as_replace_as_cmd);
13020 install_element(BGP_IPV6M_NODE,
13021 &neighbor_remove_private_as_all_replace_as_cmd);
13022 install_element(BGP_IPV6M_NODE,
13023 &no_neighbor_remove_private_as_all_replace_as_cmd);
13024 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13025 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13026 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13027 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13028 install_element(BGP_IPV6L_NODE,
13029 &neighbor_remove_private_as_replace_as_cmd);
13030 install_element(BGP_IPV6L_NODE,
13031 &no_neighbor_remove_private_as_replace_as_cmd);
13032 install_element(BGP_IPV6L_NODE,
13033 &neighbor_remove_private_as_all_replace_as_cmd);
13034 install_element(BGP_IPV6L_NODE,
13035 &no_neighbor_remove_private_as_all_replace_as_cmd);
13036 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13037 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13038 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13039 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13040 install_element(BGP_VPNV4_NODE,
13041 &neighbor_remove_private_as_replace_as_cmd);
13042 install_element(BGP_VPNV4_NODE,
13043 &no_neighbor_remove_private_as_replace_as_cmd);
13044 install_element(BGP_VPNV4_NODE,
13045 &neighbor_remove_private_as_all_replace_as_cmd);
13046 install_element(BGP_VPNV4_NODE,
13047 &no_neighbor_remove_private_as_all_replace_as_cmd);
13048 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13049 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13050 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13051 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13052 install_element(BGP_VPNV6_NODE,
13053 &neighbor_remove_private_as_replace_as_cmd);
13054 install_element(BGP_VPNV6_NODE,
13055 &no_neighbor_remove_private_as_replace_as_cmd);
13056 install_element(BGP_VPNV6_NODE,
13057 &neighbor_remove_private_as_all_replace_as_cmd);
13058 install_element(BGP_VPNV6_NODE,
13059 &no_neighbor_remove_private_as_all_replace_as_cmd);
13060
13061 /* "neighbor send-community" commands.*/
13062 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13063 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13064 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13065 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13066 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13067 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13068 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13069 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13070 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13071 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13072 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13073 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13074 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13075 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13076 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13077 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13078 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13079 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13080 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13081 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13082 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13083 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13084 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13085 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13086 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13087 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13088 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13089 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13090 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13091 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13092 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13093 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13094 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13095 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13096 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13097 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13098
13099 /* "neighbor route-reflector" commands.*/
13100 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13101 install_element(BGP_NODE,
13102 &no_neighbor_route_reflector_client_hidden_cmd);
13103 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13104 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13105 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13106 install_element(BGP_IPV4M_NODE,
13107 &no_neighbor_route_reflector_client_cmd);
13108 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13109 install_element(BGP_IPV4L_NODE,
13110 &no_neighbor_route_reflector_client_cmd);
13111 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13112 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13113 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13114 install_element(BGP_IPV6M_NODE,
13115 &no_neighbor_route_reflector_client_cmd);
13116 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13117 install_element(BGP_IPV6L_NODE,
13118 &no_neighbor_route_reflector_client_cmd);
13119 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13120 install_element(BGP_VPNV4_NODE,
13121 &no_neighbor_route_reflector_client_cmd);
13122 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13123 install_element(BGP_VPNV6_NODE,
13124 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13125 install_element(BGP_FLOWSPECV4_NODE,
13126 &neighbor_route_reflector_client_cmd);
13127 install_element(BGP_FLOWSPECV4_NODE,
13128 &no_neighbor_route_reflector_client_cmd);
13129 install_element(BGP_FLOWSPECV6_NODE,
13130 &neighbor_route_reflector_client_cmd);
13131 install_element(BGP_FLOWSPECV6_NODE,
13132 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13133 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13134 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13135
13136 /* "neighbor route-server" commands.*/
13137 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13138 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13139 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13140 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13141 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13142 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13143 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13144 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13145 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13146 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13147 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13148 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13149 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13150 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13151 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13152 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13153 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13154 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13155 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13156 install_element(BGP_FLOWSPECV4_NODE,
13157 &no_neighbor_route_server_client_cmd);
13158 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13159 install_element(BGP_FLOWSPECV6_NODE,
13160 &no_neighbor_route_server_client_cmd);
d62a17ae 13161
13162 /* "neighbor addpath-tx-all-paths" commands.*/
13163 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13164 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13165 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13166 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13167 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13168 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13169 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13170 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13171 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13172 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13173 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13174 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13175 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13176 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13177 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13178 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13179 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13180 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13181
13182 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13183 install_element(BGP_NODE,
13184 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13185 install_element(BGP_NODE,
13186 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13187 install_element(BGP_IPV4_NODE,
13188 &neighbor_addpath_tx_bestpath_per_as_cmd);
13189 install_element(BGP_IPV4_NODE,
13190 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13191 install_element(BGP_IPV4M_NODE,
13192 &neighbor_addpath_tx_bestpath_per_as_cmd);
13193 install_element(BGP_IPV4M_NODE,
13194 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13195 install_element(BGP_IPV4L_NODE,
13196 &neighbor_addpath_tx_bestpath_per_as_cmd);
13197 install_element(BGP_IPV4L_NODE,
13198 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13199 install_element(BGP_IPV6_NODE,
13200 &neighbor_addpath_tx_bestpath_per_as_cmd);
13201 install_element(BGP_IPV6_NODE,
13202 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13203 install_element(BGP_IPV6M_NODE,
13204 &neighbor_addpath_tx_bestpath_per_as_cmd);
13205 install_element(BGP_IPV6M_NODE,
13206 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13207 install_element(BGP_IPV6L_NODE,
13208 &neighbor_addpath_tx_bestpath_per_as_cmd);
13209 install_element(BGP_IPV6L_NODE,
13210 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13211 install_element(BGP_VPNV4_NODE,
13212 &neighbor_addpath_tx_bestpath_per_as_cmd);
13213 install_element(BGP_VPNV4_NODE,
13214 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13215 install_element(BGP_VPNV6_NODE,
13216 &neighbor_addpath_tx_bestpath_per_as_cmd);
13217 install_element(BGP_VPNV6_NODE,
13218 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13219
13220 /* "neighbor passive" commands. */
13221 install_element(BGP_NODE, &neighbor_passive_cmd);
13222 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13223
13224
13225 /* "neighbor shutdown" commands. */
13226 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13227 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13228 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13229 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13230
13231 /* "neighbor capability extended-nexthop" commands.*/
13232 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13233 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13234
13235 /* "neighbor capability orf prefix-list" commands.*/
13236 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13237 install_element(BGP_NODE,
13238 &no_neighbor_capability_orf_prefix_hidden_cmd);
13239 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13240 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13241 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13242 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13243 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13244 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13245 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13246 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13247 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13248 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13249 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13250 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13251
13252 /* "neighbor capability dynamic" commands.*/
13253 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13254 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13255
13256 /* "neighbor dont-capability-negotiate" commands. */
13257 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13258 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13259
13260 /* "neighbor ebgp-multihop" commands. */
13261 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13262 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13263 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13264
13265 /* "neighbor disable-connected-check" commands. */
13266 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13267 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13268
47cbc09b
PM
13269 /* "neighbor enforce-first-as" commands. */
13270 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13271 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13272
d62a17ae 13273 /* "neighbor description" commands. */
13274 install_element(BGP_NODE, &neighbor_description_cmd);
13275 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13276 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13277
13278 /* "neighbor update-source" commands. "*/
13279 install_element(BGP_NODE, &neighbor_update_source_cmd);
13280 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13281
13282 /* "neighbor default-originate" commands. */
13283 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13284 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13285 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13286 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13287 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13288 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13289 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13290 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13291 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13292 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13293 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13294 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13295 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13296 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13297 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13298 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13299 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13300 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13301 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13302 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13303 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13304
13305 /* "neighbor port" commands. */
13306 install_element(BGP_NODE, &neighbor_port_cmd);
13307 install_element(BGP_NODE, &no_neighbor_port_cmd);
13308
13309 /* "neighbor weight" commands. */
13310 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13311 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13312
13313 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13314 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13315 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13316 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13317 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13318 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13319 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13320 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13321 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13322 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13323 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13324 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13325 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13326 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13327 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13328 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13329
13330 /* "neighbor override-capability" commands. */
13331 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13332 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13333
13334 /* "neighbor strict-capability-match" commands. */
13335 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13336 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13337
13338 /* "neighbor timers" commands. */
13339 install_element(BGP_NODE, &neighbor_timers_cmd);
13340 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13341
13342 /* "neighbor timers connect" commands. */
13343 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13344 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13345
13346 /* "neighbor advertisement-interval" commands. */
13347 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13348 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13349
13350 /* "neighbor interface" commands. */
13351 install_element(BGP_NODE, &neighbor_interface_cmd);
13352 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13353
13354 /* "neighbor distribute" commands. */
13355 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13356 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13357 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13358 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13359 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13360 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13361 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13362 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13363 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13364 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13365 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13366 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13367 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13368 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13369 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13370 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13371 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13372 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13373
13374 /* "neighbor prefix-list" commands. */
13375 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13376 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13377 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13378 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13379 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13380 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13381 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13382 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13383 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13384 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13385 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13386 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13387 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13388 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13389 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13390 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13391 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13392 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13393 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13394 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13395 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13396 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13397
13398 /* "neighbor filter-list" commands. */
13399 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13400 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13401 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13402 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13403 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13404 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13405 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13406 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13407 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13408 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13409 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13410 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13411 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13412 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13413 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13414 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13415 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13416 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13417 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13418 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13419 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13420 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13421
13422 /* "neighbor route-map" commands. */
13423 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13424 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13425 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13426 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13427 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13428 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13429 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13430 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13431 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13432 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13433 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13434 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13435 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13436 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13437 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13438 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13439 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13440 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13441 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13442 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13443 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13444 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13445 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13446 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13447
13448 /* "neighbor unsuppress-map" commands. */
13449 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13450 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13451 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13452 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13453 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13454 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13455 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13456 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13457 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13458 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13459 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13460 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13461 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13462 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13463 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13464 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13465 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13466 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13467
13468 /* "neighbor maximum-prefix" commands. */
13469 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13470 install_element(BGP_NODE,
13471 &neighbor_maximum_prefix_threshold_hidden_cmd);
13472 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13473 install_element(BGP_NODE,
13474 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13475 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13476 install_element(BGP_NODE,
13477 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13478 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13479 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13480 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13481 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13482 install_element(BGP_IPV4_NODE,
13483 &neighbor_maximum_prefix_threshold_warning_cmd);
13484 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13485 install_element(BGP_IPV4_NODE,
13486 &neighbor_maximum_prefix_threshold_restart_cmd);
13487 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13488 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13489 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13490 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13491 install_element(BGP_IPV4M_NODE,
13492 &neighbor_maximum_prefix_threshold_warning_cmd);
13493 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13494 install_element(BGP_IPV4M_NODE,
13495 &neighbor_maximum_prefix_threshold_restart_cmd);
13496 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13497 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13498 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13499 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13500 install_element(BGP_IPV4L_NODE,
13501 &neighbor_maximum_prefix_threshold_warning_cmd);
13502 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13503 install_element(BGP_IPV4L_NODE,
13504 &neighbor_maximum_prefix_threshold_restart_cmd);
13505 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13506 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13507 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13508 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13509 install_element(BGP_IPV6_NODE,
13510 &neighbor_maximum_prefix_threshold_warning_cmd);
13511 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13512 install_element(BGP_IPV6_NODE,
13513 &neighbor_maximum_prefix_threshold_restart_cmd);
13514 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13515 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13516 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13517 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13518 install_element(BGP_IPV6M_NODE,
13519 &neighbor_maximum_prefix_threshold_warning_cmd);
13520 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13521 install_element(BGP_IPV6M_NODE,
13522 &neighbor_maximum_prefix_threshold_restart_cmd);
13523 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13524 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13525 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13526 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13527 install_element(BGP_IPV6L_NODE,
13528 &neighbor_maximum_prefix_threshold_warning_cmd);
13529 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13530 install_element(BGP_IPV6L_NODE,
13531 &neighbor_maximum_prefix_threshold_restart_cmd);
13532 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13533 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13534 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13535 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13536 install_element(BGP_VPNV4_NODE,
13537 &neighbor_maximum_prefix_threshold_warning_cmd);
13538 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13539 install_element(BGP_VPNV4_NODE,
13540 &neighbor_maximum_prefix_threshold_restart_cmd);
13541 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13542 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13543 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13544 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13545 install_element(BGP_VPNV6_NODE,
13546 &neighbor_maximum_prefix_threshold_warning_cmd);
13547 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13548 install_element(BGP_VPNV6_NODE,
13549 &neighbor_maximum_prefix_threshold_restart_cmd);
13550 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13551
13552 /* "neighbor allowas-in" */
13553 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13554 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13555 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13556 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13557 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13558 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13559 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13560 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13561 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13562 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13563 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13564 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13565 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13566 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13567 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13568 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13569 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13570 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13571 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13572 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13573
13574 /* address-family commands. */
13575 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13576 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13577#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13578 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13579 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13580#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13581
d62a17ae 13582 install_element(BGP_NODE, &address_family_evpn_cmd);
13583
13584 /* "exit-address-family" command. */
13585 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13586 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13587 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13588 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13589 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13590 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13591 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13592 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13593 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13594 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13595 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13596
13597 /* "clear ip bgp commands" */
13598 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13599
13600 /* clear ip bgp prefix */
13601 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13602 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13603 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13604
13605 /* "show [ip] bgp summary" commands. */
13606 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13607 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13608 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13609 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13610 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13611 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13612
13613 /* "show [ip] bgp neighbors" commands. */
13614 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13615
13616 /* "show [ip] bgp peer-group" commands. */
13617 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13618
13619 /* "show [ip] bgp paths" commands. */
13620 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13621
13622 /* "show [ip] bgp community" commands. */
13623 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13624
13625 /* "show ip bgp large-community" commands. */
13626 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13627 /* "show [ip] bgp attribute-info" commands. */
13628 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13629 /* "show [ip] bgp route-leak" command */
13630 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13631
13632 /* "redistribute" commands. */
13633 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13634 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13635 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13636 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13637 install_element(BGP_NODE,
13638 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13639 install_element(BGP_NODE,
13640 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13641 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13642 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13643 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13644 install_element(BGP_NODE,
13645 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13646 install_element(BGP_NODE,
13647 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13648 install_element(BGP_NODE,
13649 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13650 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13651 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13652 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13653 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13654 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13655 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13656 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13657 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13658 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13659 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13660 install_element(BGP_IPV4_NODE,
13661 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13662 install_element(BGP_IPV4_NODE,
13663 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13664 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13665 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13666 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13667 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13668 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13669 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13670
b9c7bc5a
PZ
13671 /* import|export vpn [route-map WORD] */
13672 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13673 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13674
12a844a5
DS
13675 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13676 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13677
d62a17ae 13678 /* ttl_security commands */
13679 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13680 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13681
13682 /* "show [ip] bgp memory" commands. */
13683 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13684
acf71666
MK
13685 /* "show bgp martian next-hop" */
13686 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13687
d62a17ae 13688 /* "show [ip] bgp views" commands. */
13689 install_element(VIEW_NODE, &show_bgp_views_cmd);
13690
13691 /* "show [ip] bgp vrfs" commands. */
13692 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13693
13694 /* Community-list. */
13695 community_list_vty();
ddb5b488
PZ
13696
13697 /* vpn-policy commands */
b9c7bc5a
PZ
13698 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13699 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13700 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13701 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13702 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13703 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13704 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13705 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13706 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13707 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13708 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13709 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13710
301ad80a
PG
13711 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13712 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13713
b9c7bc5a
PZ
13714 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13715 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13716 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13717 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13718 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13719 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13720 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13721 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13722 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13723 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13724 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13725 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13726}
6b0655a2 13727
718e3744 13728#include "memory.h"
13729#include "bgp_regex.h"
13730#include "bgp_clist.h"
13731#include "bgp_ecommunity.h"
13732
13733/* VTY functions. */
13734
13735/* Direction value to string conversion. */
d62a17ae 13736static const char *community_direct_str(int direct)
13737{
13738 switch (direct) {
13739 case COMMUNITY_DENY:
13740 return "deny";
13741 case COMMUNITY_PERMIT:
13742 return "permit";
13743 default:
13744 return "unknown";
13745 }
718e3744 13746}
13747
13748/* Display error string. */
d62a17ae 13749static void community_list_perror(struct vty *vty, int ret)
13750{
13751 switch (ret) {
13752 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13753 vty_out(vty, "%% Can't find community-list\n");
13754 break;
13755 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13756 vty_out(vty, "%% Malformed community-list value\n");
13757 break;
13758 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13759 vty_out(vty,
13760 "%% Community name conflict, previously defined as standard community\n");
13761 break;
13762 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13763 vty_out(vty,
13764 "%% Community name conflict, previously defined as expanded community\n");
13765 break;
13766 }
718e3744 13767}
13768
5bf15956
DW
13769/* "community-list" keyword help string. */
13770#define COMMUNITY_LIST_STR "Add a community list entry\n"
13771
7336e101
SP
13772/*community-list standard */
13773DEFUN (community_list_standard,
13774 bgp_community_list_standard_cmd,
13775 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13776 BGP_STR
718e3744 13777 COMMUNITY_LIST_STR
13778 "Community list number (standard)\n"
5bf15956 13779 "Add an standard community-list entry\n"
718e3744 13780 "Community list name\n"
13781 "Specify community to reject\n"
13782 "Specify community to accept\n"
13783 COMMUNITY_VAL_STR)
13784{
d62a17ae 13785 char *cl_name_or_number = NULL;
13786 int direct = 0;
13787 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13788
d62a17ae 13789 int idx = 0;
7336e101
SP
13790
13791 if (argv_find(argv, argc, "ip", &idx)) {
13792 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13793 vty_out(vty, "if you are using this please migrate to the below command.\n");
13794 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13795 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13796 }
13797
d62a17ae 13798 argv_find(argv, argc, "(1-99)", &idx);
13799 argv_find(argv, argc, "WORD", &idx);
13800 cl_name_or_number = argv[idx]->arg;
13801 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13802 : COMMUNITY_DENY;
13803 argv_find(argv, argc, "AA:NN", &idx);
13804 char *str = argv_concat(argv, argc, idx);
42f914d4 13805
d62a17ae 13806 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13807 style);
42f914d4 13808
d62a17ae 13809 XFREE(MTYPE_TMP, str);
42f914d4 13810
d62a17ae 13811 if (ret < 0) {
13812 /* Display error string. */
13813 community_list_perror(vty, ret);
13814 return CMD_WARNING_CONFIG_FAILED;
13815 }
42f914d4 13816
d62a17ae 13817 return CMD_SUCCESS;
718e3744 13818}
13819
7336e101
SP
13820#if CONFDATE > 20191005
13821CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
13822#endif
13823ALIAS (community_list_standard,
13824 ip_community_list_standard_cmd,
13825 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13826 IP_STR
13827 COMMUNITY_LIST_STR
13828 "Community list number (standard)\n"
5bf15956
DW
13829 "Add an standard community-list entry\n"
13830 "Community list name\n"
718e3744 13831 "Specify community to reject\n"
13832 "Specify community to accept\n"
13833 COMMUNITY_VAL_STR)
7336e101
SP
13834
13835DEFUN (no_community_list_standard_all,
13836 no_bgp_community_list_standard_all_cmd,
13837 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13838 NO_STR
13839 BGP_STR
13840 COMMUNITY_LIST_STR
13841 "Community list number (standard)\n"
13842 "Add an standard community-list entry\n"
13843 "Community list name\n"
13844 "Specify community to reject\n"
13845 "Specify community to accept\n"
13846 COMMUNITY_VAL_STR)
718e3744 13847{
d62a17ae 13848 char *cl_name_or_number = NULL;
13849 int direct = 0;
13850 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13851
d62a17ae 13852 int idx = 0;
7336e101
SP
13853
13854 if (argv_find(argv, argc, "ip", &idx)) {
13855 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
13856 vty_out(vty, "if you are using this please migrate to the below command.\n");
13857 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13858 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
13859 }
13860
d62a17ae 13861 argv_find(argv, argc, "(1-99)", &idx);
13862 argv_find(argv, argc, "WORD", &idx);
13863 cl_name_or_number = argv[idx]->arg;
13864 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13865 : COMMUNITY_DENY;
13866 argv_find(argv, argc, "AA:NN", &idx);
13867 char *str = argv_concat(argv, argc, idx);
42f914d4 13868
d62a17ae 13869 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13870 direct, style);
42f914d4 13871
d62a17ae 13872 XFREE(MTYPE_TMP, str);
daf9ddbb 13873
d62a17ae 13874 if (ret < 0) {
13875 community_list_perror(vty, ret);
13876 return CMD_WARNING_CONFIG_FAILED;
13877 }
42f914d4 13878
d62a17ae 13879 return CMD_SUCCESS;
718e3744 13880}
7336e101
SP
13881ALIAS (no_community_list_standard_all,
13882 no_ip_community_list_standard_all_cmd,
13883 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13884 NO_STR
718e3744 13885 IP_STR
13886 COMMUNITY_LIST_STR
7336e101
SP
13887 "Community list number (standard)\n"
13888 "Add an standard community-list entry\n"
13889 "Community list name\n"
13890 "Specify community to reject\n"
13891 "Specify community to accept\n"
13892 COMMUNITY_VAL_STR)
13893
13894/*community-list expanded */
13895DEFUN (community_list_expanded_all,
13896 bgp_community_list_expanded_all_cmd,
13897 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13898 BGP_STR
13899 COMMUNITY_LIST_STR
718e3744 13900 "Community list number (expanded)\n"
5bf15956 13901 "Add an expanded community-list entry\n"
718e3744 13902 "Community list name\n"
13903 "Specify community to reject\n"
13904 "Specify community to accept\n"
13905 COMMUNITY_VAL_STR)
13906{
d62a17ae 13907 char *cl_name_or_number = NULL;
13908 int direct = 0;
13909 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13910
d62a17ae 13911 int idx = 0;
7336e101
SP
13912 if (argv_find(argv, argc, "ip", &idx)) {
13913 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13914 vty_out(vty, "if you are using this please migrate to the below command.\n");
13915 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13916 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13917 }
d62a17ae 13918 argv_find(argv, argc, "(100-500)", &idx);
13919 argv_find(argv, argc, "WORD", &idx);
13920 cl_name_or_number = argv[idx]->arg;
13921 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13922 : COMMUNITY_DENY;
13923 argv_find(argv, argc, "AA:NN", &idx);
13924 char *str = argv_concat(argv, argc, idx);
42f914d4 13925
d62a17ae 13926 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13927 style);
42f914d4 13928
d62a17ae 13929 XFREE(MTYPE_TMP, str);
42f914d4 13930
d62a17ae 13931 if (ret < 0) {
13932 /* Display error string. */
13933 community_list_perror(vty, ret);
13934 return CMD_WARNING_CONFIG_FAILED;
13935 }
42f914d4 13936
d62a17ae 13937 return CMD_SUCCESS;
718e3744 13938}
13939
7336e101
SP
13940ALIAS (community_list_expanded_all,
13941 ip_community_list_expanded_all_cmd,
13942 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13943 IP_STR
13944 COMMUNITY_LIST_STR
5bf15956
DW
13945 "Community list number (expanded)\n"
13946 "Add an expanded community-list entry\n"
718e3744 13947 "Community list name\n"
13948 "Specify community to reject\n"
13949 "Specify community to accept\n"
5bf15956 13950 COMMUNITY_VAL_STR)
7336e101
SP
13951
13952DEFUN (no_community_list_expanded_all,
13953 no_bgp_community_list_expanded_all_cmd,
13954 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13955 NO_STR
13956 BGP_STR
13957 COMMUNITY_LIST_STR
13958 "Community list number (expanded)\n"
13959 "Add an expanded community-list entry\n"
13960 "Community list name\n"
13961 "Specify community to reject\n"
13962 "Specify community to accept\n"
13963 COMMUNITY_VAL_STR)
718e3744 13964{
d62a17ae 13965 char *cl_name_or_number = NULL;
13966 int direct = 0;
13967 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13968
d62a17ae 13969 int idx = 0;
7336e101
SP
13970 if (argv_find(argv, argc, "ip", &idx)) {
13971 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13972 vty_out(vty, "if you are using this please migrate to the below command.\n");
13973 vty_out(vty, "'no community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13974 zlog_warn("Deprecated option: 'no community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13975 }
d62a17ae 13976 argv_find(argv, argc, "(100-500)", &idx);
13977 argv_find(argv, argc, "WORD", &idx);
13978 cl_name_or_number = argv[idx]->arg;
13979 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13980 : COMMUNITY_DENY;
13981 argv_find(argv, argc, "AA:NN", &idx);
13982 char *str = argv_concat(argv, argc, idx);
42f914d4 13983
d62a17ae 13984 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13985 direct, style);
42f914d4 13986
d62a17ae 13987 XFREE(MTYPE_TMP, str);
daf9ddbb 13988
d62a17ae 13989 if (ret < 0) {
13990 community_list_perror(vty, ret);
13991 return CMD_WARNING_CONFIG_FAILED;
13992 }
42f914d4 13993
d62a17ae 13994 return CMD_SUCCESS;
718e3744 13995}
13996
7336e101
SP
13997ALIAS (no_community_list_expanded_all,
13998 no_ip_community_list_expanded_all_cmd,
13999 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14000 NO_STR
14001 IP_STR
14002 COMMUNITY_LIST_STR
14003 "Community list number (expanded)\n"
14004 "Add an expanded community-list entry\n"
14005 "Community list name\n"
14006 "Specify community to reject\n"
14007 "Specify community to accept\n"
14008 COMMUNITY_VAL_STR)
14009
8d9b8ed9
PM
14010/* Return configuration string of community-list entry. */
14011static const char *community_list_config_str(struct community_entry *entry)
14012{
14013 const char *str;
14014
14015 if (entry->any)
14016 str = "";
14017 else {
14018 if (entry->style == COMMUNITY_LIST_STANDARD)
14019 str = community_str(entry->u.com, false);
14020 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14021 str = lcommunity_str(entry->u.lcom, false);
14022 else
14023 str = entry->config;
14024 }
14025 return str;
14026}
14027
d62a17ae 14028static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14029{
d62a17ae 14030 struct community_entry *entry;
718e3744 14031
d62a17ae 14032 for (entry = list->head; entry; entry = entry->next) {
14033 if (entry == list->head) {
14034 if (all_digit(list->name))
14035 vty_out(vty, "Community %s list %s\n",
14036 entry->style == COMMUNITY_LIST_STANDARD
14037 ? "standard"
14038 : "(expanded) access",
14039 list->name);
14040 else
14041 vty_out(vty, "Named Community %s list %s\n",
14042 entry->style == COMMUNITY_LIST_STANDARD
14043 ? "standard"
14044 : "expanded",
14045 list->name);
14046 }
14047 if (entry->any)
14048 vty_out(vty, " %s\n",
14049 community_direct_str(entry->direct));
14050 else
14051 vty_out(vty, " %s %s\n",
14052 community_direct_str(entry->direct),
8d9b8ed9 14053 community_list_config_str(entry));
d62a17ae 14054 }
718e3744 14055}
14056
7336e101
SP
14057DEFUN (show_community_list,
14058 show_bgp_community_list_cmd,
14059 "show bgp community-list",
718e3744 14060 SHOW_STR
7336e101 14061 BGP_STR
718e3744 14062 "List community-list\n")
14063{
d62a17ae 14064 struct community_list *list;
14065 struct community_list_master *cm;
718e3744 14066
7336e101
SP
14067 int idx = 0;
14068 if (argv_find(argv, argc, "ip", &idx)) {
14069 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14070 vty_out(vty, "if you are using this please migrate to the below command.\n");
14071 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14072 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14073 }
d62a17ae 14074 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14075 if (!cm)
14076 return CMD_SUCCESS;
718e3744 14077
d62a17ae 14078 for (list = cm->num.head; list; list = list->next)
14079 community_list_show(vty, list);
718e3744 14080
d62a17ae 14081 for (list = cm->str.head; list; list = list->next)
14082 community_list_show(vty, list);
718e3744 14083
d62a17ae 14084 return CMD_SUCCESS;
718e3744 14085}
14086
7336e101
SP
14087ALIAS (show_community_list,
14088 show_ip_community_list_cmd,
14089 "show ip community-list",
718e3744 14090 SHOW_STR
14091 IP_STR
7336e101
SP
14092 "List community-list\n")
14093
14094DEFUN (show_community_list_arg,
14095 show_bgp_community_list_arg_cmd,
14096 "show bgp community-list <(1-500)|WORD>",
14097 SHOW_STR
14098 BGP_STR
718e3744 14099 "List community-list\n"
14100 "Community-list number\n"
14101 "Community-list name\n")
14102{
d62a17ae 14103 int idx_comm_list = 3;
14104 struct community_list *list;
718e3744 14105
7336e101
SP
14106 int idx = 0;
14107 if (argv_find(argv, argc, "ip", &idx)) {
14108 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14109 vty_out(vty, "if you are using this please migrate to the below command.\n");
14110 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14111 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14112 }
d62a17ae 14113 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14114 COMMUNITY_LIST_MASTER);
14115 if (!list) {
14116 vty_out(vty, "%% Can't find community-list\n");
14117 return CMD_WARNING;
14118 }
718e3744 14119
d62a17ae 14120 community_list_show(vty, list);
718e3744 14121
d62a17ae 14122 return CMD_SUCCESS;
718e3744 14123}
6b0655a2 14124
7336e101
SP
14125ALIAS (show_community_list_arg,
14126 show_ip_community_list_arg_cmd,
14127 "show ip community-list <(1-500)|WORD>",
14128 SHOW_STR
14129 IP_STR
14130 "List community-list\n"
14131 "Community-list number\n"
14132 "Community-list name\n")
14133
57d187bc
JS
14134/*
14135 * Large Community code.
14136 */
d62a17ae 14137static int lcommunity_list_set_vty(struct vty *vty, int argc,
14138 struct cmd_token **argv, int style,
14139 int reject_all_digit_name)
14140{
14141 int ret;
14142 int direct;
14143 char *str;
14144 int idx = 0;
14145 char *cl_name;
14146
7336e101
SP
14147 if (argv_find(argv, argc, "ip", &idx)) {
14148 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14149 vty_out(vty, "if you are using this please migrate to the below command.\n");
14150 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14151 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14152 }
d62a17ae 14153 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14154 : COMMUNITY_DENY;
14155
14156 /* All digit name check. */
14157 idx = 0;
14158 argv_find(argv, argc, "WORD", &idx);
14159 argv_find(argv, argc, "(1-99)", &idx);
14160 argv_find(argv, argc, "(100-500)", &idx);
14161 cl_name = argv[idx]->arg;
14162 if (reject_all_digit_name && all_digit(cl_name)) {
14163 vty_out(vty, "%% Community name cannot have all digits\n");
14164 return CMD_WARNING_CONFIG_FAILED;
14165 }
14166
14167 idx = 0;
14168 argv_find(argv, argc, "AA:BB:CC", &idx);
14169 argv_find(argv, argc, "LINE", &idx);
14170 /* Concat community string argument. */
14171 if (idx)
14172 str = argv_concat(argv, argc, idx);
14173 else
14174 str = NULL;
14175
14176 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14177
14178 /* Free temporary community list string allocated by
14179 argv_concat(). */
14180 if (str)
14181 XFREE(MTYPE_TMP, str);
14182
14183 if (ret < 0) {
14184 community_list_perror(vty, ret);
14185 return CMD_WARNING_CONFIG_FAILED;
14186 }
14187 return CMD_SUCCESS;
14188}
14189
14190static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14191 struct cmd_token **argv, int style)
14192{
14193 int ret;
14194 int direct = 0;
14195 char *str = NULL;
14196 int idx = 0;
14197
7336e101
SP
14198 if (argv_find(argv, argc, "ip", &idx)) {
14199 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14200 vty_out(vty, "if you are using this please migrate to the below command.\n");
14201 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14202 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14203 }
d62a17ae 14204 argv_find(argv, argc, "permit", &idx);
14205 argv_find(argv, argc, "deny", &idx);
14206
14207 if (idx) {
14208 /* Check the list direct. */
14209 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14210 direct = COMMUNITY_PERMIT;
14211 else
14212 direct = COMMUNITY_DENY;
14213
14214 idx = 0;
14215 argv_find(argv, argc, "LINE", &idx);
14216 argv_find(argv, argc, "AA:AA:NN", &idx);
14217 /* Concat community string argument. */
14218 str = argv_concat(argv, argc, idx);
14219 }
14220
14221 idx = 0;
14222 argv_find(argv, argc, "(1-99)", &idx);
14223 argv_find(argv, argc, "(100-500)", &idx);
14224 argv_find(argv, argc, "WORD", &idx);
14225
14226 /* Unset community list. */
14227 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14228 style);
14229
14230 /* Free temporary community list string allocated by
14231 argv_concat(). */
14232 if (str)
14233 XFREE(MTYPE_TMP, str);
14234
14235 if (ret < 0) {
14236 community_list_perror(vty, ret);
14237 return CMD_WARNING_CONFIG_FAILED;
14238 }
14239
14240 return CMD_SUCCESS;
57d187bc
JS
14241}
14242
14243/* "large-community-list" keyword help string. */
14244#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14245#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14246
7336e101
SP
14247#if CONFDATE > 20191005
14248CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14249#endif
14250DEFUN (lcommunity_list_standard,
14251 bgp_lcommunity_list_standard_cmd,
14252 "bgp large-community-list (1-99) <deny|permit>",
14253 BGP_STR
14254 LCOMMUNITY_LIST_STR
14255 "Large Community list number (standard)\n"
14256 "Specify large community to reject\n"
14257 "Specify large community to accept\n")
14258{
14259 return lcommunity_list_set_vty(vty, argc, argv,
14260 LARGE_COMMUNITY_LIST_STANDARD, 0);
14261}
14262
14263ALIAS (lcommunity_list_standard,
57d187bc 14264 ip_lcommunity_list_standard_cmd,
52951b63
DS
14265 "ip large-community-list (1-99) <deny|permit>",
14266 IP_STR
14267 LCOMMUNITY_LIST_STR
14268 "Large Community list number (standard)\n"
14269 "Specify large community to reject\n"
7111c1a0 14270 "Specify large community to accept\n")
7336e101
SP
14271
14272DEFUN (lcommunity_list_standard1,
14273 bgp_lcommunity_list_standard1_cmd,
14274 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14275 BGP_STR
14276 LCOMMUNITY_LIST_STR
14277 "Large Community list number (standard)\n"
14278 "Specify large community to reject\n"
14279 "Specify large community to accept\n"
14280 LCOMMUNITY_VAL_STR)
52951b63 14281{
d62a17ae 14282 return lcommunity_list_set_vty(vty, argc, argv,
14283 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14284}
14285
7336e101 14286ALIAS (lcommunity_list_standard1,
52951b63
DS
14287 ip_lcommunity_list_standard1_cmd,
14288 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14289 IP_STR
14290 LCOMMUNITY_LIST_STR
14291 "Large Community list number (standard)\n"
14292 "Specify large community to reject\n"
14293 "Specify large community to accept\n"
14294 LCOMMUNITY_VAL_STR)
7336e101
SP
14295
14296DEFUN (lcommunity_list_expanded,
14297 bgp_lcommunity_list_expanded_cmd,
14298 "bgp large-community-list (100-500) <deny|permit> LINE...",
14299 BGP_STR
14300 LCOMMUNITY_LIST_STR
14301 "Large Community list number (expanded)\n"
14302 "Specify large community to reject\n"
14303 "Specify large community to accept\n"
14304 "An ordered list as a regular-expression\n")
57d187bc 14305{
d62a17ae 14306 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14307 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14308}
14309
7336e101 14310ALIAS (lcommunity_list_expanded,
57d187bc
JS
14311 ip_lcommunity_list_expanded_cmd,
14312 "ip large-community-list (100-500) <deny|permit> LINE...",
14313 IP_STR
14314 LCOMMUNITY_LIST_STR
14315 "Large Community list number (expanded)\n"
14316 "Specify large community to reject\n"
14317 "Specify large community to accept\n"
14318 "An ordered list as a regular-expression\n")
7336e101
SP
14319
14320DEFUN (lcommunity_list_name_standard,
14321 bgp_lcommunity_list_name_standard_cmd,
14322 "bgp large-community-list standard WORD <deny|permit>",
14323 BGP_STR
14324 LCOMMUNITY_LIST_STR
14325 "Specify standard large-community-list\n"
14326 "Large Community list name\n"
14327 "Specify large community to reject\n"
14328 "Specify large community to accept\n")
57d187bc 14329{
d62a17ae 14330 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14331 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14332}
14333
7336e101 14334ALIAS (lcommunity_list_name_standard,
57d187bc 14335 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14336 "ip large-community-list standard WORD <deny|permit>",
14337 IP_STR
14338 LCOMMUNITY_LIST_STR
14339 "Specify standard large-community-list\n"
14340 "Large Community list name\n"
14341 "Specify large community to reject\n"
14342 "Specify large community to accept\n")
7336e101
SP
14343
14344DEFUN (lcommunity_list_name_standard1,
14345 bgp_lcommunity_list_name_standard1_cmd,
14346 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14347 BGP_STR
14348 LCOMMUNITY_LIST_STR
14349 "Specify standard large-community-list\n"
14350 "Large Community list name\n"
14351 "Specify large community to reject\n"
14352 "Specify large community to accept\n"
14353 LCOMMUNITY_VAL_STR)
52951b63 14354{
d62a17ae 14355 return lcommunity_list_set_vty(vty, argc, argv,
14356 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14357}
14358
7336e101 14359ALIAS (lcommunity_list_name_standard1,
52951b63
DS
14360 ip_lcommunity_list_name_standard1_cmd,
14361 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14362 IP_STR
14363 LCOMMUNITY_LIST_STR
14364 "Specify standard large-community-list\n"
14365 "Large Community list name\n"
14366 "Specify large community to reject\n"
14367 "Specify large community to accept\n"
14368 LCOMMUNITY_VAL_STR)
7336e101
SP
14369
14370DEFUN (lcommunity_list_name_expanded,
14371 bgp_lcommunity_list_name_expanded_cmd,
14372 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14373 BGP_STR
14374 LCOMMUNITY_LIST_STR
14375 "Specify expanded large-community-list\n"
14376 "Large Community list name\n"
14377 "Specify large community to reject\n"
14378 "Specify large community to accept\n"
14379 "An ordered list as a regular-expression\n")
57d187bc 14380{
d62a17ae 14381 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14382 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14383}
14384
7336e101 14385ALIAS (lcommunity_list_name_expanded,
57d187bc
JS
14386 ip_lcommunity_list_name_expanded_cmd,
14387 "ip large-community-list expanded WORD <deny|permit> LINE...",
14388 IP_STR
14389 LCOMMUNITY_LIST_STR
14390 "Specify expanded large-community-list\n"
14391 "Large Community list name\n"
14392 "Specify large community to reject\n"
14393 "Specify large community to accept\n"
14394 "An ordered list as a regular-expression\n")
7336e101
SP
14395
14396DEFUN (no_lcommunity_list_standard_all,
14397 no_bgp_lcommunity_list_standard_all_cmd,
14398 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14399 NO_STR
14400 BGP_STR
14401 LCOMMUNITY_LIST_STR
14402 "Large Community list number (standard)\n"
14403 "Large Community list number (expanded)\n"
14404 "Large Community list name\n")
57d187bc 14405{
7336e101
SP
14406 return lcommunity_list_unset_vty(vty, argc, argv,
14407 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14408}
14409
7336e101 14410ALIAS (no_lcommunity_list_standard_all,
57d187bc
JS
14411 no_ip_lcommunity_list_standard_all_cmd,
14412 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14413 NO_STR
14414 IP_STR
14415 LCOMMUNITY_LIST_STR
14416 "Large Community list number (standard)\n"
14417 "Large Community list number (expanded)\n"
14418 "Large Community list name\n")
7336e101
SP
14419
14420DEFUN (no_lcommunity_list_name_expanded_all,
14421 no_bgp_lcommunity_list_name_expanded_all_cmd,
14422 "no bgp large-community-list expanded WORD",
14423 NO_STR
14424 BGP_STR
14425 LCOMMUNITY_LIST_STR
14426 "Specify expanded large-community-list\n"
14427 "Large Community list name\n")
57d187bc 14428{
d62a17ae 14429 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14430 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14431}
14432
7336e101 14433ALIAS (no_lcommunity_list_name_expanded_all,
57d187bc
JS
14434 no_ip_lcommunity_list_name_expanded_all_cmd,
14435 "no ip large-community-list expanded WORD",
14436 NO_STR
14437 IP_STR
14438 LCOMMUNITY_LIST_STR
14439 "Specify expanded large-community-list\n"
14440 "Large Community list name\n")
7336e101
SP
14441
14442DEFUN (no_lcommunity_list_standard,
14443 no_bgp_lcommunity_list_standard_cmd,
14444 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14445 NO_STR
14446 BGP_STR
14447 LCOMMUNITY_LIST_STR
14448 "Large Community list number (standard)\n"
14449 "Specify large community to reject\n"
14450 "Specify large community to accept\n"
14451 LCOMMUNITY_VAL_STR)
57d187bc 14452{
d62a17ae 14453 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14454 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14455}
14456
7336e101 14457ALIAS (no_lcommunity_list_standard,
57d187bc
JS
14458 no_ip_lcommunity_list_standard_cmd,
14459 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14460 NO_STR
14461 IP_STR
14462 LCOMMUNITY_LIST_STR
14463 "Large Community list number (standard)\n"
14464 "Specify large community to reject\n"
14465 "Specify large community to accept\n"
14466 LCOMMUNITY_VAL_STR)
7336e101
SP
14467
14468DEFUN (no_lcommunity_list_expanded,
14469 no_bgp_lcommunity_list_expanded_cmd,
14470 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14471 NO_STR
14472 BGP_STR
14473 LCOMMUNITY_LIST_STR
14474 "Large Community list number (expanded)\n"
14475 "Specify large community to reject\n"
14476 "Specify large community to accept\n"
14477 "An ordered list as a regular-expression\n")
57d187bc 14478{
d62a17ae 14479 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14480 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14481}
14482
7336e101 14483ALIAS (no_lcommunity_list_expanded,
57d187bc
JS
14484 no_ip_lcommunity_list_expanded_cmd,
14485 "no ip large-community-list (100-500) <deny|permit> LINE...",
14486 NO_STR
14487 IP_STR
14488 LCOMMUNITY_LIST_STR
14489 "Large Community list number (expanded)\n"
14490 "Specify large community to reject\n"
14491 "Specify large community to accept\n"
14492 "An ordered list as a regular-expression\n")
7336e101
SP
14493
14494DEFUN (no_lcommunity_list_name_standard,
14495 no_bgp_lcommunity_list_name_standard_cmd,
14496 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14497 NO_STR
14498 BGP_STR
14499 LCOMMUNITY_LIST_STR
14500 "Specify standard large-community-list\n"
14501 "Large Community list name\n"
14502 "Specify large community to reject\n"
14503 "Specify large community to accept\n"
14504 LCOMMUNITY_VAL_STR)
57d187bc 14505{
d62a17ae 14506 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14507 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14508}
14509
7336e101 14510ALIAS (no_lcommunity_list_name_standard,
57d187bc
JS
14511 no_ip_lcommunity_list_name_standard_cmd,
14512 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14513 NO_STR
14514 IP_STR
14515 LCOMMUNITY_LIST_STR
14516 "Specify standard large-community-list\n"
14517 "Large Community list name\n"
14518 "Specify large community to reject\n"
14519 "Specify large community to accept\n"
14520 LCOMMUNITY_VAL_STR)
7336e101
SP
14521
14522DEFUN (no_lcommunity_list_name_expanded,
14523 no_bgp_lcommunity_list_name_expanded_cmd,
14524 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14525 NO_STR
14526 BGP_STR
14527 LCOMMUNITY_LIST_STR
14528 "Specify expanded large-community-list\n"
14529 "Large community list name\n"
14530 "Specify large community to reject\n"
14531 "Specify large community to accept\n"
14532 "An ordered list as a regular-expression\n")
57d187bc 14533{
d62a17ae 14534 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14535 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14536}
14537
7336e101 14538ALIAS (no_lcommunity_list_name_expanded,
57d187bc
JS
14539 no_ip_lcommunity_list_name_expanded_cmd,
14540 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14541 NO_STR
14542 IP_STR
14543 LCOMMUNITY_LIST_STR
14544 "Specify expanded large-community-list\n"
14545 "Large community list name\n"
14546 "Specify large community to reject\n"
14547 "Specify large community to accept\n"
14548 "An ordered list as a regular-expression\n")
d62a17ae 14549
14550static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14551{
14552 struct community_entry *entry;
14553
14554 for (entry = list->head; entry; entry = entry->next) {
14555 if (entry == list->head) {
14556 if (all_digit(list->name))
14557 vty_out(vty, "Large community %s list %s\n",
14558 entry->style == EXTCOMMUNITY_LIST_STANDARD
14559 ? "standard"
14560 : "(expanded) access",
14561 list->name);
14562 else
14563 vty_out(vty,
14564 "Named large community %s list %s\n",
14565 entry->style == EXTCOMMUNITY_LIST_STANDARD
14566 ? "standard"
14567 : "expanded",
14568 list->name);
14569 }
14570 if (entry->any)
14571 vty_out(vty, " %s\n",
14572 community_direct_str(entry->direct));
14573 else
14574 vty_out(vty, " %s %s\n",
14575 community_direct_str(entry->direct),
8d9b8ed9 14576 community_list_config_str(entry));
d62a17ae 14577 }
57d187bc
JS
14578}
14579
7336e101
SP
14580DEFUN (show_lcommunity_list,
14581 show_bgp_lcommunity_list_cmd,
14582 "show bgp large-community-list",
57d187bc 14583 SHOW_STR
7336e101 14584 BGP_STR
57d187bc
JS
14585 "List large-community list\n")
14586{
d62a17ae 14587 struct community_list *list;
14588 struct community_list_master *cm;
7336e101
SP
14589 int idx = 0;
14590
14591 if (argv_find(argv, argc, "ip", &idx)) {
14592 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14593 vty_out(vty, "if you are using this please migrate to the below command.\n");
14594 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14595 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14596 }
57d187bc 14597
d62a17ae 14598 cm = community_list_master_lookup(bgp_clist,
14599 LARGE_COMMUNITY_LIST_MASTER);
14600 if (!cm)
14601 return CMD_SUCCESS;
57d187bc 14602
d62a17ae 14603 for (list = cm->num.head; list; list = list->next)
14604 lcommunity_list_show(vty, list);
57d187bc 14605
d62a17ae 14606 for (list = cm->str.head; list; list = list->next)
14607 lcommunity_list_show(vty, list);
57d187bc 14608
d62a17ae 14609 return CMD_SUCCESS;
57d187bc
JS
14610}
14611
7336e101
SP
14612ALIAS (show_lcommunity_list,
14613 show_ip_lcommunity_list_cmd,
14614 "show ip large-community-list",
57d187bc
JS
14615 SHOW_STR
14616 IP_STR
7336e101
SP
14617 "List large-community list\n")
14618
14619DEFUN (show_lcommunity_list_arg,
14620 show_bgp_lcommunity_list_arg_cmd,
14621 "show bgp large-community-list <(1-500)|WORD>",
14622 SHOW_STR
14623 BGP_STR
57d187bc
JS
14624 "List large-community list\n"
14625 "large-community-list number\n"
14626 "large-community-list name\n")
14627{
d62a17ae 14628 struct community_list *list;
7336e101
SP
14629 int idx = 0;
14630
14631 if (argv_find(argv, argc, "ip", &idx)) {
14632 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14633 vty_out(vty, "if you are using this please migrate to the below command.\n");
14634 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14635 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14636 }
57d187bc 14637
d62a17ae 14638 list = community_list_lookup(bgp_clist, argv[3]->arg,
14639 LARGE_COMMUNITY_LIST_MASTER);
14640 if (!list) {
14641 vty_out(vty, "%% Can't find extcommunity-list\n");
14642 return CMD_WARNING;
14643 }
57d187bc 14644
d62a17ae 14645 lcommunity_list_show(vty, list);
57d187bc 14646
d62a17ae 14647 return CMD_SUCCESS;
57d187bc
JS
14648}
14649
7336e101
SP
14650ALIAS (show_lcommunity_list_arg,
14651 show_ip_lcommunity_list_arg_cmd,
14652 "show ip large-community-list <(1-500)|WORD>",
14653 SHOW_STR
14654 IP_STR
14655 "List large-community list\n"
14656 "large-community-list number\n"
14657 "large-community-list name\n")
14658
718e3744 14659/* "extcommunity-list" keyword help string. */
14660#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14661#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14662
7336e101
SP
14663DEFUN (extcommunity_list_standard,
14664 bgp_extcommunity_list_standard_cmd,
14665 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14666 BGP_STR
718e3744 14667 EXTCOMMUNITY_LIST_STR
14668 "Extended Community list number (standard)\n"
718e3744 14669 "Specify standard extcommunity-list\n"
5bf15956 14670 "Community list name\n"
718e3744 14671 "Specify community to reject\n"
14672 "Specify community to accept\n"
14673 EXTCOMMUNITY_VAL_STR)
14674{
d62a17ae 14675 int style = EXTCOMMUNITY_LIST_STANDARD;
14676 int direct = 0;
14677 char *cl_number_or_name = NULL;
42f914d4 14678
d62a17ae 14679 int idx = 0;
7336e101
SP
14680 if (argv_find(argv, argc, "ip", &idx)) {
14681 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14682 vty_out(vty, "if you are using this please migrate to the below command.\n");
14683 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14684 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14685 }
d62a17ae 14686 argv_find(argv, argc, "(1-99)", &idx);
14687 argv_find(argv, argc, "WORD", &idx);
14688 cl_number_or_name = argv[idx]->arg;
14689 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14690 : COMMUNITY_DENY;
14691 argv_find(argv, argc, "AA:NN", &idx);
14692 char *str = argv_concat(argv, argc, idx);
42f914d4 14693
d62a17ae 14694 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14695 direct, style);
42f914d4 14696
d62a17ae 14697 XFREE(MTYPE_TMP, str);
42f914d4 14698
d62a17ae 14699 if (ret < 0) {
14700 community_list_perror(vty, ret);
14701 return CMD_WARNING_CONFIG_FAILED;
14702 }
42f914d4 14703
d62a17ae 14704 return CMD_SUCCESS;
718e3744 14705}
14706
7336e101
SP
14707#if CONFDATE > 20191005
14708CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14709#endif
14710ALIAS (extcommunity_list_standard,
14711 ip_extcommunity_list_standard_cmd,
14712 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14713 IP_STR
14714 EXTCOMMUNITY_LIST_STR
7336e101
SP
14715 "Extended Community list number (standard)\n"
14716 "Specify standard extcommunity-list\n"
14717 "Community list name\n"
14718 "Specify community to reject\n"
14719 "Specify community to accept\n"
14720 EXTCOMMUNITY_VAL_STR)
14721
14722DEFUN (extcommunity_list_name_expanded,
14723 bgp_extcommunity_list_name_expanded_cmd,
14724 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14725 BGP_STR
14726 EXTCOMMUNITY_LIST_STR
5bf15956 14727 "Extended Community list number (expanded)\n"
718e3744 14728 "Specify expanded extcommunity-list\n"
14729 "Extended Community list name\n"
14730 "Specify community to reject\n"
14731 "Specify community to accept\n"
14732 "An ordered list as a regular-expression\n")
14733{
d62a17ae 14734 int style = EXTCOMMUNITY_LIST_EXPANDED;
14735 int direct = 0;
14736 char *cl_number_or_name = NULL;
42f914d4 14737
d62a17ae 14738 int idx = 0;
7336e101
SP
14739 if (argv_find(argv, argc, "ip", &idx)) {
14740 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14741 vty_out(vty, "if you are using this please migrate to the below command.\n");
14742 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14743 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14744 }
14745
d62a17ae 14746 argv_find(argv, argc, "(100-500)", &idx);
14747 argv_find(argv, argc, "WORD", &idx);
14748 cl_number_or_name = argv[idx]->arg;
14749 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14750 : COMMUNITY_DENY;
14751 argv_find(argv, argc, "LINE", &idx);
14752 char *str = argv_concat(argv, argc, idx);
42f914d4 14753
d62a17ae 14754 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14755 direct, style);
42f914d4 14756
d62a17ae 14757 XFREE(MTYPE_TMP, str);
42f914d4 14758
d62a17ae 14759 if (ret < 0) {
14760 community_list_perror(vty, ret);
14761 return CMD_WARNING_CONFIG_FAILED;
14762 }
42f914d4 14763
d62a17ae 14764 return CMD_SUCCESS;
718e3744 14765}
14766
7336e101
SP
14767ALIAS (extcommunity_list_name_expanded,
14768 ip_extcommunity_list_name_expanded_cmd,
14769 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
813d4307
DW
14770 IP_STR
14771 EXTCOMMUNITY_LIST_STR
7336e101
SP
14772 "Extended Community list number (expanded)\n"
14773 "Specify expanded extcommunity-list\n"
14774 "Extended Community list name\n"
14775 "Specify community to reject\n"
14776 "Specify community to accept\n"
14777 "An ordered list as a regular-expression\n")
14778
14779DEFUN (no_extcommunity_list_standard_all,
14780 no_bgp_extcommunity_list_standard_all_cmd,
14781 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14782 NO_STR
14783 BGP_STR
14784 EXTCOMMUNITY_LIST_STR
813d4307 14785 "Extended Community list number (standard)\n"
718e3744 14786 "Specify standard extcommunity-list\n"
5bf15956 14787 "Community list name\n"
718e3744 14788 "Specify community to reject\n"
14789 "Specify community to accept\n"
14790 EXTCOMMUNITY_VAL_STR)
14791{
d62a17ae 14792 int style = EXTCOMMUNITY_LIST_STANDARD;
14793 int direct = 0;
14794 char *cl_number_or_name = NULL;
42f914d4 14795
d62a17ae 14796 int idx = 0;
7336e101
SP
14797 if (argv_find(argv, argc, "ip", &idx)) {
14798 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14799 vty_out(vty, "if you are using this please migrate to the below command.\n");
14800 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14801 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14802 }
d62a17ae 14803 argv_find(argv, argc, "(1-99)", &idx);
14804 argv_find(argv, argc, "WORD", &idx);
14805 cl_number_or_name = argv[idx]->arg;
14806 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14807 : COMMUNITY_DENY;
14808 argv_find(argv, argc, "AA:NN", &idx);
14809 char *str = argv_concat(argv, argc, idx);
42f914d4 14810
d62a17ae 14811 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14812 direct, style);
42f914d4 14813
d62a17ae 14814 XFREE(MTYPE_TMP, str);
42f914d4 14815
d62a17ae 14816 if (ret < 0) {
14817 community_list_perror(vty, ret);
14818 return CMD_WARNING_CONFIG_FAILED;
14819 }
42f914d4 14820
d62a17ae 14821 return CMD_SUCCESS;
718e3744 14822}
14823
7336e101
SP
14824ALIAS (no_extcommunity_list_standard_all,
14825 no_ip_extcommunity_list_standard_all_cmd,
14826 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14827 NO_STR
14828 IP_STR
14829 EXTCOMMUNITY_LIST_STR
7336e101
SP
14830 "Extended Community list number (standard)\n"
14831 "Specify standard extcommunity-list\n"
14832 "Community list name\n"
14833 "Specify community to reject\n"
14834 "Specify community to accept\n"
14835 EXTCOMMUNITY_VAL_STR)
14836
14837DEFUN (no_extcommunity_list_expanded_all,
14838 no_bgp_extcommunity_list_expanded_all_cmd,
14839 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14840 NO_STR
14841 BGP_STR
14842 EXTCOMMUNITY_LIST_STR
718e3744 14843 "Extended Community list number (expanded)\n"
718e3744 14844 "Specify expanded extcommunity-list\n"
5bf15956 14845 "Extended Community list name\n"
718e3744 14846 "Specify community to reject\n"
14847 "Specify community to accept\n"
14848 "An ordered list as a regular-expression\n")
14849{
d62a17ae 14850 int style = EXTCOMMUNITY_LIST_EXPANDED;
14851 int direct = 0;
14852 char *cl_number_or_name = NULL;
42f914d4 14853
d62a17ae 14854 int idx = 0;
7336e101
SP
14855 if (argv_find(argv, argc, "ip", &idx)) {
14856 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14857 vty_out(vty, "if you are using this please migrate to the below command.\n");
14858 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14859 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14860 }
d62a17ae 14861 argv_find(argv, argc, "(100-500)", &idx);
14862 argv_find(argv, argc, "WORD", &idx);
14863 cl_number_or_name = argv[idx]->arg;
14864 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14865 : COMMUNITY_DENY;
14866 argv_find(argv, argc, "LINE", &idx);
14867 char *str = argv_concat(argv, argc, idx);
42f914d4 14868
d62a17ae 14869 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14870 direct, style);
42f914d4 14871
d62a17ae 14872 XFREE(MTYPE_TMP, str);
42f914d4 14873
d62a17ae 14874 if (ret < 0) {
14875 community_list_perror(vty, ret);
14876 return CMD_WARNING_CONFIG_FAILED;
14877 }
42f914d4 14878
d62a17ae 14879 return CMD_SUCCESS;
718e3744 14880}
14881
7336e101
SP
14882ALIAS (no_extcommunity_list_expanded_all,
14883 no_ip_extcommunity_list_expanded_all_cmd,
14884 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14885 NO_STR
14886 IP_STR
14887 EXTCOMMUNITY_LIST_STR
14888 "Extended Community list number (expanded)\n"
14889 "Specify expanded extcommunity-list\n"
14890 "Extended Community list name\n"
14891 "Specify community to reject\n"
14892 "Specify community to accept\n"
14893 "An ordered list as a regular-expression\n")
14894
d62a17ae 14895static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14896{
d62a17ae 14897 struct community_entry *entry;
718e3744 14898
d62a17ae 14899 for (entry = list->head; entry; entry = entry->next) {
14900 if (entry == list->head) {
14901 if (all_digit(list->name))
14902 vty_out(vty, "Extended community %s list %s\n",
14903 entry->style == EXTCOMMUNITY_LIST_STANDARD
14904 ? "standard"
14905 : "(expanded) access",
14906 list->name);
14907 else
14908 vty_out(vty,
14909 "Named extended community %s list %s\n",
14910 entry->style == EXTCOMMUNITY_LIST_STANDARD
14911 ? "standard"
14912 : "expanded",
14913 list->name);
14914 }
14915 if (entry->any)
14916 vty_out(vty, " %s\n",
14917 community_direct_str(entry->direct));
14918 else
14919 vty_out(vty, " %s %s\n",
14920 community_direct_str(entry->direct),
8d9b8ed9 14921 community_list_config_str(entry));
d62a17ae 14922 }
718e3744 14923}
14924
7336e101
SP
14925DEFUN (show_extcommunity_list,
14926 show_bgp_extcommunity_list_cmd,
14927 "show bgp extcommunity-list",
718e3744 14928 SHOW_STR
7336e101 14929 BGP_STR
718e3744 14930 "List extended-community list\n")
14931{
d62a17ae 14932 struct community_list *list;
14933 struct community_list_master *cm;
7336e101 14934 int idx = 0;
718e3744 14935
7336e101
SP
14936 if (argv_find(argv, argc, "ip", &idx)) {
14937 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14938 vty_out(vty, "if you are using this please migrate to the below command.\n");
14939 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
14940 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
14941 }
d62a17ae 14942 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14943 if (!cm)
14944 return CMD_SUCCESS;
718e3744 14945
d62a17ae 14946 for (list = cm->num.head; list; list = list->next)
14947 extcommunity_list_show(vty, list);
718e3744 14948
d62a17ae 14949 for (list = cm->str.head; list; list = list->next)
14950 extcommunity_list_show(vty, list);
718e3744 14951
d62a17ae 14952 return CMD_SUCCESS;
718e3744 14953}
14954
7336e101
SP
14955ALIAS (show_extcommunity_list,
14956 show_ip_extcommunity_list_cmd,
14957 "show ip extcommunity-list",
718e3744 14958 SHOW_STR
14959 IP_STR
7336e101
SP
14960 "List extended-community list\n")
14961
14962DEFUN (show_extcommunity_list_arg,
14963 show_bgp_extcommunity_list_arg_cmd,
14964 "show bgp extcommunity-list <(1-500)|WORD>",
14965 SHOW_STR
14966 BGP_STR
718e3744 14967 "List extended-community list\n"
14968 "Extcommunity-list number\n"
14969 "Extcommunity-list name\n")
14970{
d62a17ae 14971 int idx_comm_list = 3;
14972 struct community_list *list;
7336e101 14973 int idx = 0;
718e3744 14974
7336e101
SP
14975 if (argv_find(argv, argc, "ip", &idx)) {
14976 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14977 vty_out(vty, "if you are using this please migrate to the below command.\n");
14978 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
14979 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
14980 }
d62a17ae 14981 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14982 EXTCOMMUNITY_LIST_MASTER);
14983 if (!list) {
14984 vty_out(vty, "%% Can't find extcommunity-list\n");
14985 return CMD_WARNING;
14986 }
718e3744 14987
d62a17ae 14988 extcommunity_list_show(vty, list);
718e3744 14989
d62a17ae 14990 return CMD_SUCCESS;
718e3744 14991}
6b0655a2 14992
7336e101
SP
14993ALIAS (show_extcommunity_list_arg,
14994 show_ip_extcommunity_list_arg_cmd,
14995 "show ip extcommunity-list <(1-500)|WORD>",
14996 SHOW_STR
14997 IP_STR
14998 "List extended-community list\n"
14999 "Extcommunity-list number\n"
15000 "Extcommunity-list name\n")
15001
718e3744 15002/* Display community-list and extcommunity-list configuration. */
d62a17ae 15003static int community_list_config_write(struct vty *vty)
15004{
15005 struct community_list *list;
15006 struct community_entry *entry;
15007 struct community_list_master *cm;
15008 int write = 0;
15009
15010 /* Community-list. */
15011 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15012
15013 for (list = cm->num.head; list; list = list->next)
15014 for (entry = list->head; entry; entry = entry->next) {
7336e101 15015 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15016 community_direct_str(entry->direct),
15017 community_list_config_str(entry));
15018 write++;
15019 }
15020 for (list = cm->str.head; list; list = list->next)
15021 for (entry = list->head; entry; entry = entry->next) {
7336e101 15022 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15023 entry->style == COMMUNITY_LIST_STANDARD
15024 ? "standard"
15025 : "expanded",
15026 list->name, community_direct_str(entry->direct),
15027 community_list_config_str(entry));
15028 write++;
15029 }
15030
15031 /* Extcommunity-list. */
15032 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15033
15034 for (list = cm->num.head; list; list = list->next)
15035 for (entry = list->head; entry; entry = entry->next) {
7336e101 15036 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15037 list->name, community_direct_str(entry->direct),
15038 community_list_config_str(entry));
15039 write++;
15040 }
15041 for (list = cm->str.head; list; list = list->next)
15042 for (entry = list->head; entry; entry = entry->next) {
7336e101 15043 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15044 entry->style == EXTCOMMUNITY_LIST_STANDARD
15045 ? "standard"
15046 : "expanded",
15047 list->name, community_direct_str(entry->direct),
15048 community_list_config_str(entry));
15049 write++;
15050 }
15051
15052
15053 /* lcommunity-list. */
15054 cm = community_list_master_lookup(bgp_clist,
15055 LARGE_COMMUNITY_LIST_MASTER);
15056
15057 for (list = cm->num.head; list; list = list->next)
15058 for (entry = list->head; entry; entry = entry->next) {
7336e101 15059 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15060 list->name, community_direct_str(entry->direct),
15061 community_list_config_str(entry));
15062 write++;
15063 }
15064 for (list = cm->str.head; list; list = list->next)
15065 for (entry = list->head; entry; entry = entry->next) {
7336e101 15066 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15067 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15068 ? "standard"
15069 : "expanded",
15070 list->name, community_direct_str(entry->direct),
15071 community_list_config_str(entry));
15072 write++;
15073 }
15074
15075 return write;
15076}
15077
15078static struct cmd_node community_list_node = {
15079 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15080};
15081
d62a17ae 15082static void community_list_vty(void)
15083{
15084 install_node(&community_list_node, community_list_config_write);
15085
15086 /* Community-list. */
7336e101
SP
15087 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15088 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15089 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15090 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15091 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15092 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15093 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15094 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15095 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15096 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15097 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15098 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15099
15100 /* Extcommunity-list. */
7336e101
SP
15101 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15102 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15103 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15104 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15105 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15106 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15107 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15108 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15109 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15110 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15111 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15112 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15113
15114 /* Large Community List */
7336e101
SP
15115 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15116 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15117 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15118 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15119 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15120 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15121 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15122 install_element(CONFIG_NODE,
15123 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15124 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15125 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15126 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15127 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15128 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15129 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
d62a17ae 15130 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15131 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15132 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15133 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15134 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15135 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15136 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15137 install_element(CONFIG_NODE,
15138 &no_ip_lcommunity_list_name_expanded_all_cmd);
15139 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15140 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15141 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15142 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15143 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15144 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 15145}