]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #3056 from pacovn/Coverity_1473285_Explicit_null_dereferenced
[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)
2838 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
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;
718e3744 4770
d62a17ae 4771 peer = peer_and_group_lookup_vty(vty, peer_str);
4772 if (!peer)
4773 return CMD_WARNING_CONFIG_FAILED;
718e3744 4774
d62a17ae 4775 if (set)
4776 ret = peer_default_originate_set(peer, afi, safi, rmap);
4777 else
4778 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4779
d62a17ae 4780 return bgp_vty_return(vty, ret);
718e3744 4781}
4782
4783/* neighbor default-originate. */
4784DEFUN (neighbor_default_originate,
4785 neighbor_default_originate_cmd,
9ccf14f7 4786 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4787 NEIGHBOR_STR
4788 NEIGHBOR_ADDR_STR2
4789 "Originate default route to this neighbor\n")
4790{
d62a17ae 4791 int idx_peer = 1;
4792 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4793 bgp_node_afi(vty),
4794 bgp_node_safi(vty), NULL, 1);
718e3744 4795}
4796
d62a17ae 4797ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4798 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4800 "Originate default route to this neighbor\n")
596c17ba 4801
718e3744 4802DEFUN (neighbor_default_originate_rmap,
4803 neighbor_default_originate_rmap_cmd,
9ccf14f7 4804 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4805 NEIGHBOR_STR
4806 NEIGHBOR_ADDR_STR2
4807 "Originate default route to this neighbor\n"
4808 "Route-map to specify criteria to originate default\n"
4809 "route-map name\n")
4810{
d62a17ae 4811 int idx_peer = 1;
4812 int idx_word = 4;
4813 return peer_default_originate_set_vty(
4814 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4815 argv[idx_word]->arg, 1);
718e3744 4816}
4817
d62a17ae 4818ALIAS_HIDDEN(
4819 neighbor_default_originate_rmap,
4820 neighbor_default_originate_rmap_hidden_cmd,
4821 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4822 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4823 "Originate default route to this neighbor\n"
4824 "Route-map to specify criteria to originate default\n"
4825 "route-map name\n")
596c17ba 4826
718e3744 4827DEFUN (no_neighbor_default_originate,
4828 no_neighbor_default_originate_cmd,
a636c635 4829 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4830 NO_STR
4831 NEIGHBOR_STR
4832 NEIGHBOR_ADDR_STR2
a636c635
DW
4833 "Originate default route to this neighbor\n"
4834 "Route-map to specify criteria to originate default\n"
4835 "route-map name\n")
718e3744 4836{
d62a17ae 4837 int idx_peer = 2;
4838 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4839 bgp_node_afi(vty),
4840 bgp_node_safi(vty), NULL, 0);
718e3744 4841}
4842
d62a17ae 4843ALIAS_HIDDEN(
4844 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4845 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4846 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4847 "Originate default route to this neighbor\n"
4848 "Route-map to specify criteria to originate default\n"
4849 "route-map name\n")
596c17ba 4850
6b0655a2 4851
718e3744 4852/* Set neighbor's BGP port. */
d62a17ae 4853static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4854 const char *port_str)
4855{
4856 struct peer *peer;
d7c0a89a 4857 uint16_t port;
d62a17ae 4858 struct servent *sp;
4859
4860 peer = peer_lookup_vty(vty, ip_str);
4861 if (!peer)
4862 return CMD_WARNING_CONFIG_FAILED;
4863
4864 if (!port_str) {
4865 sp = getservbyname("bgp", "tcp");
4866 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4867 } else {
4868 port = strtoul(port_str, NULL, 10);
4869 }
718e3744 4870
d62a17ae 4871 peer_port_set(peer, port);
718e3744 4872
d62a17ae 4873 return CMD_SUCCESS;
718e3744 4874}
4875
f418446b 4876/* Set specified peer's BGP port. */
718e3744 4877DEFUN (neighbor_port,
4878 neighbor_port_cmd,
9ccf14f7 4879 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4880 NEIGHBOR_STR
4881 NEIGHBOR_ADDR_STR
4882 "Neighbor's BGP port\n"
4883 "TCP port number\n")
4884{
d62a17ae 4885 int idx_ip = 1;
4886 int idx_number = 3;
4887 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4888 argv[idx_number]->arg);
718e3744 4889}
4890
4891DEFUN (no_neighbor_port,
4892 no_neighbor_port_cmd,
9ccf14f7 4893 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4894 NO_STR
4895 NEIGHBOR_STR
4896 NEIGHBOR_ADDR_STR
8334fd5a
DW
4897 "Neighbor's BGP port\n"
4898 "TCP port number\n")
718e3744 4899{
d62a17ae 4900 int idx_ip = 2;
4901 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4902}
4903
6b0655a2 4904
718e3744 4905/* neighbor weight. */
d62a17ae 4906static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4907 safi_t safi, const char *weight_str)
718e3744 4908{
d62a17ae 4909 int ret;
4910 struct peer *peer;
4911 unsigned long weight;
718e3744 4912
d62a17ae 4913 peer = peer_and_group_lookup_vty(vty, ip_str);
4914 if (!peer)
4915 return CMD_WARNING_CONFIG_FAILED;
718e3744 4916
d62a17ae 4917 weight = strtoul(weight_str, NULL, 10);
718e3744 4918
d62a17ae 4919 ret = peer_weight_set(peer, afi, safi, weight);
4920 return bgp_vty_return(vty, ret);
718e3744 4921}
4922
d62a17ae 4923static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4924 safi_t safi)
718e3744 4925{
d62a17ae 4926 int ret;
4927 struct peer *peer;
718e3744 4928
d62a17ae 4929 peer = peer_and_group_lookup_vty(vty, ip_str);
4930 if (!peer)
4931 return CMD_WARNING_CONFIG_FAILED;
718e3744 4932
d62a17ae 4933 ret = peer_weight_unset(peer, afi, safi);
4934 return bgp_vty_return(vty, ret);
718e3744 4935}
4936
4937DEFUN (neighbor_weight,
4938 neighbor_weight_cmd,
9ccf14f7 4939 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4940 NEIGHBOR_STR
4941 NEIGHBOR_ADDR_STR2
4942 "Set default weight for routes from this neighbor\n"
4943 "default weight\n")
4944{
d62a17ae 4945 int idx_peer = 1;
4946 int idx_number = 3;
4947 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4948 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4949}
4950
d62a17ae 4951ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4952 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4953 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4954 "Set default weight for routes from this neighbor\n"
4955 "default weight\n")
596c17ba 4956
718e3744 4957DEFUN (no_neighbor_weight,
4958 no_neighbor_weight_cmd,
9ccf14f7 4959 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4960 NO_STR
4961 NEIGHBOR_STR
4962 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4963 "Set default weight for routes from this neighbor\n"
4964 "default weight\n")
718e3744 4965{
d62a17ae 4966 int idx_peer = 2;
4967 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4968 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4969}
4970
d62a17ae 4971ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4972 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4974 "Set default weight for routes from this neighbor\n"
4975 "default weight\n")
596c17ba 4976
6b0655a2 4977
718e3744 4978/* Override capability negotiation. */
4979DEFUN (neighbor_override_capability,
4980 neighbor_override_capability_cmd,
9ccf14f7 4981 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4982 NEIGHBOR_STR
4983 NEIGHBOR_ADDR_STR2
4984 "Override capability negotiation result\n")
4985{
d62a17ae 4986 int idx_peer = 1;
4987 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4988 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4989}
4990
4991DEFUN (no_neighbor_override_capability,
4992 no_neighbor_override_capability_cmd,
9ccf14f7 4993 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4994 NO_STR
4995 NEIGHBOR_STR
4996 NEIGHBOR_ADDR_STR2
4997 "Override capability negotiation result\n")
4998{
d62a17ae 4999 int idx_peer = 2;
5000 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5001 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5002}
6b0655a2 5003
718e3744 5004DEFUN (neighbor_strict_capability,
5005 neighbor_strict_capability_cmd,
9fb964de 5006 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5007 NEIGHBOR_STR
9fb964de 5008 NEIGHBOR_ADDR_STR2
718e3744 5009 "Strict capability negotiation match\n")
5010{
9fb964de
PM
5011 int idx_peer = 1;
5012
5013 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5014 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5015}
5016
5017DEFUN (no_neighbor_strict_capability,
5018 no_neighbor_strict_capability_cmd,
9fb964de 5019 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5020 NO_STR
5021 NEIGHBOR_STR
9fb964de 5022 NEIGHBOR_ADDR_STR2
718e3744 5023 "Strict capability negotiation match\n")
5024{
9fb964de
PM
5025 int idx_peer = 2;
5026
5027 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5028 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5029}
6b0655a2 5030
d62a17ae 5031static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5032 const char *keep_str, const char *hold_str)
718e3744 5033{
d62a17ae 5034 int ret;
5035 struct peer *peer;
d7c0a89a
QY
5036 uint32_t keepalive;
5037 uint32_t holdtime;
718e3744 5038
d62a17ae 5039 peer = peer_and_group_lookup_vty(vty, ip_str);
5040 if (!peer)
5041 return CMD_WARNING_CONFIG_FAILED;
718e3744 5042
d62a17ae 5043 keepalive = strtoul(keep_str, NULL, 10);
5044 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5045
d62a17ae 5046 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5047
d62a17ae 5048 return bgp_vty_return(vty, ret);
718e3744 5049}
6b0655a2 5050
d62a17ae 5051static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5052{
d62a17ae 5053 int ret;
5054 struct peer *peer;
718e3744 5055
d62a17ae 5056 peer = peer_and_group_lookup_vty(vty, ip_str);
5057 if (!peer)
5058 return CMD_WARNING_CONFIG_FAILED;
718e3744 5059
d62a17ae 5060 ret = peer_timers_unset(peer);
718e3744 5061
d62a17ae 5062 return bgp_vty_return(vty, ret);
718e3744 5063}
5064
5065DEFUN (neighbor_timers,
5066 neighbor_timers_cmd,
9ccf14f7 5067 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5068 NEIGHBOR_STR
5069 NEIGHBOR_ADDR_STR2
5070 "BGP per neighbor timers\n"
5071 "Keepalive interval\n"
5072 "Holdtime\n")
5073{
d62a17ae 5074 int idx_peer = 1;
5075 int idx_number = 3;
5076 int idx_number_2 = 4;
5077 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5078 argv[idx_number]->arg,
5079 argv[idx_number_2]->arg);
718e3744 5080}
5081
5082DEFUN (no_neighbor_timers,
5083 no_neighbor_timers_cmd,
9ccf14f7 5084 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5085 NO_STR
5086 NEIGHBOR_STR
5087 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5088 "BGP per neighbor timers\n"
5089 "Keepalive interval\n"
5090 "Holdtime\n")
718e3744 5091{
d62a17ae 5092 int idx_peer = 2;
5093 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5094}
6b0655a2 5095
813d4307 5096
d62a17ae 5097static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5098 const char *time_str)
718e3744 5099{
d62a17ae 5100 int ret;
5101 struct peer *peer;
d7c0a89a 5102 uint32_t connect;
718e3744 5103
d62a17ae 5104 peer = peer_and_group_lookup_vty(vty, ip_str);
5105 if (!peer)
5106 return CMD_WARNING_CONFIG_FAILED;
718e3744 5107
d62a17ae 5108 connect = strtoul(time_str, NULL, 10);
718e3744 5109
d62a17ae 5110 ret = peer_timers_connect_set(peer, connect);
718e3744 5111
d62a17ae 5112 return bgp_vty_return(vty, ret);
718e3744 5113}
5114
d62a17ae 5115static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5116{
d62a17ae 5117 int ret;
5118 struct peer *peer;
718e3744 5119
d62a17ae 5120 peer = peer_and_group_lookup_vty(vty, ip_str);
5121 if (!peer)
5122 return CMD_WARNING_CONFIG_FAILED;
718e3744 5123
d62a17ae 5124 ret = peer_timers_connect_unset(peer);
718e3744 5125
d62a17ae 5126 return bgp_vty_return(vty, ret);
718e3744 5127}
5128
5129DEFUN (neighbor_timers_connect,
5130 neighbor_timers_connect_cmd,
9ccf14f7 5131 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5132 NEIGHBOR_STR
966f821c 5133 NEIGHBOR_ADDR_STR2
718e3744 5134 "BGP per neighbor timers\n"
5135 "BGP connect timer\n"
5136 "Connect timer\n")
5137{
d62a17ae 5138 int idx_peer = 1;
5139 int idx_number = 4;
5140 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5141 argv[idx_number]->arg);
718e3744 5142}
5143
5144DEFUN (no_neighbor_timers_connect,
5145 no_neighbor_timers_connect_cmd,
9ccf14f7 5146 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5147 NO_STR
5148 NEIGHBOR_STR
966f821c 5149 NEIGHBOR_ADDR_STR2
718e3744 5150 "BGP per neighbor timers\n"
8334fd5a
DW
5151 "BGP connect timer\n"
5152 "Connect timer\n")
718e3744 5153{
d62a17ae 5154 int idx_peer = 2;
5155 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5156}
5157
6b0655a2 5158
d62a17ae 5159static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5160 const char *time_str, int set)
718e3744 5161{
d62a17ae 5162 int ret;
5163 struct peer *peer;
d7c0a89a 5164 uint32_t routeadv = 0;
718e3744 5165
d62a17ae 5166 peer = peer_and_group_lookup_vty(vty, ip_str);
5167 if (!peer)
5168 return CMD_WARNING_CONFIG_FAILED;
718e3744 5169
d62a17ae 5170 if (time_str)
5171 routeadv = strtoul(time_str, NULL, 10);
718e3744 5172
d62a17ae 5173 if (set)
5174 ret = peer_advertise_interval_set(peer, routeadv);
5175 else
5176 ret = peer_advertise_interval_unset(peer);
718e3744 5177
d62a17ae 5178 return bgp_vty_return(vty, ret);
718e3744 5179}
5180
5181DEFUN (neighbor_advertise_interval,
5182 neighbor_advertise_interval_cmd,
9ccf14f7 5183 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5184 NEIGHBOR_STR
966f821c 5185 NEIGHBOR_ADDR_STR2
718e3744 5186 "Minimum interval between sending BGP routing updates\n"
5187 "time in seconds\n")
5188{
d62a17ae 5189 int idx_peer = 1;
5190 int idx_number = 3;
5191 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5192 argv[idx_number]->arg, 1);
718e3744 5193}
5194
5195DEFUN (no_neighbor_advertise_interval,
5196 no_neighbor_advertise_interval_cmd,
9ccf14f7 5197 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5198 NO_STR
5199 NEIGHBOR_STR
966f821c 5200 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5201 "Minimum interval between sending BGP routing updates\n"
5202 "time in seconds\n")
718e3744 5203{
d62a17ae 5204 int idx_peer = 2;
5205 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5206}
5207
6b0655a2 5208
518f0eb1
DS
5209/* Time to wait before processing route-map updates */
5210DEFUN (bgp_set_route_map_delay_timer,
5211 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5212 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5213 SET_STR
5214 "BGP route-map delay timer\n"
5215 "Time in secs to wait before processing route-map changes\n"
f414725f 5216 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5217{
d62a17ae 5218 int idx_number = 3;
d7c0a89a 5219 uint32_t rmap_delay_timer;
d62a17ae 5220
5221 if (argv[idx_number]->arg) {
5222 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5223 bm->rmap_update_timer = rmap_delay_timer;
5224
5225 /* if the dynamic update handling is being disabled, and a timer
5226 * is
5227 * running, stop the timer and act as if the timer has already
5228 * fired.
5229 */
5230 if (!rmap_delay_timer && bm->t_rmap_update) {
5231 BGP_TIMER_OFF(bm->t_rmap_update);
5232 thread_execute(bm->master, bgp_route_map_update_timer,
5233 NULL, 0);
5234 }
5235 return CMD_SUCCESS;
5236 } else {
5237 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5238 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5239 }
518f0eb1
DS
5240}
5241
5242DEFUN (no_bgp_set_route_map_delay_timer,
5243 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5244 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5245 NO_STR
3a2d747c 5246 BGP_STR
518f0eb1 5247 "Default BGP route-map delay timer\n"
8334fd5a
DW
5248 "Reset to default time to wait for processing route-map changes\n"
5249 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5250{
518f0eb1 5251
d62a17ae 5252 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5253
d62a17ae 5254 return CMD_SUCCESS;
518f0eb1
DS
5255}
5256
f414725f 5257
718e3744 5258/* neighbor interface */
d62a17ae 5259static int peer_interface_vty(struct vty *vty, const char *ip_str,
5260 const char *str)
718e3744 5261{
d62a17ae 5262 struct peer *peer;
718e3744 5263
d62a17ae 5264 peer = peer_lookup_vty(vty, ip_str);
5265 if (!peer || peer->conf_if) {
5266 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5267 return CMD_WARNING_CONFIG_FAILED;
5268 }
718e3744 5269
d62a17ae 5270 if (str)
5271 peer_interface_set(peer, str);
5272 else
5273 peer_interface_unset(peer);
718e3744 5274
d62a17ae 5275 return CMD_SUCCESS;
718e3744 5276}
5277
5278DEFUN (neighbor_interface,
5279 neighbor_interface_cmd,
9ccf14f7 5280 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5281 NEIGHBOR_STR
5282 NEIGHBOR_ADDR_STR
5283 "Interface\n"
5284 "Interface name\n")
5285{
d62a17ae 5286 int idx_ip = 1;
5287 int idx_word = 3;
5288 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5289}
5290
5291DEFUN (no_neighbor_interface,
5292 no_neighbor_interface_cmd,
9ccf14f7 5293 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5294 NO_STR
5295 NEIGHBOR_STR
16cedbb0 5296 NEIGHBOR_ADDR_STR2
718e3744 5297 "Interface\n"
5298 "Interface name\n")
5299{
d62a17ae 5300 int idx_peer = 2;
5301 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5302}
6b0655a2 5303
718e3744 5304DEFUN (neighbor_distribute_list,
5305 neighbor_distribute_list_cmd,
9ccf14f7 5306 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5307 NEIGHBOR_STR
5308 NEIGHBOR_ADDR_STR2
5309 "Filter updates to/from this neighbor\n"
5310 "IP access-list number\n"
5311 "IP access-list number (expanded range)\n"
5312 "IP Access-list name\n"
5313 "Filter incoming updates\n"
5314 "Filter outgoing updates\n")
5315{
d62a17ae 5316 int idx_peer = 1;
5317 int idx_acl = 3;
5318 int direct, ret;
5319 struct peer *peer;
a8206004 5320
d62a17ae 5321 const char *pstr = argv[idx_peer]->arg;
5322 const char *acl = argv[idx_acl]->arg;
5323 const char *inout = argv[argc - 1]->text;
a8206004 5324
d62a17ae 5325 peer = peer_and_group_lookup_vty(vty, pstr);
5326 if (!peer)
5327 return CMD_WARNING_CONFIG_FAILED;
a8206004 5328
d62a17ae 5329 /* Check filter direction. */
5330 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5331 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5332 direct, acl);
a8206004 5333
d62a17ae 5334 return bgp_vty_return(vty, ret);
718e3744 5335}
5336
d62a17ae 5337ALIAS_HIDDEN(
5338 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5339 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5340 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5341 "Filter updates to/from this neighbor\n"
5342 "IP access-list number\n"
5343 "IP access-list number (expanded range)\n"
5344 "IP Access-list name\n"
5345 "Filter incoming updates\n"
5346 "Filter outgoing updates\n")
596c17ba 5347
718e3744 5348DEFUN (no_neighbor_distribute_list,
5349 no_neighbor_distribute_list_cmd,
9ccf14f7 5350 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5351 NO_STR
5352 NEIGHBOR_STR
5353 NEIGHBOR_ADDR_STR2
5354 "Filter updates to/from this neighbor\n"
5355 "IP access-list number\n"
5356 "IP access-list number (expanded range)\n"
5357 "IP Access-list name\n"
5358 "Filter incoming updates\n"
5359 "Filter outgoing updates\n")
5360{
d62a17ae 5361 int idx_peer = 2;
5362 int direct, ret;
5363 struct peer *peer;
a8206004 5364
d62a17ae 5365 const char *pstr = argv[idx_peer]->arg;
5366 const char *inout = argv[argc - 1]->text;
a8206004 5367
d62a17ae 5368 peer = peer_and_group_lookup_vty(vty, pstr);
5369 if (!peer)
5370 return CMD_WARNING_CONFIG_FAILED;
a8206004 5371
d62a17ae 5372 /* Check filter direction. */
5373 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5374 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5375 direct);
a8206004 5376
d62a17ae 5377 return bgp_vty_return(vty, ret);
718e3744 5378}
6b0655a2 5379
d62a17ae 5380ALIAS_HIDDEN(
5381 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5382 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5383 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5384 "Filter updates to/from this neighbor\n"
5385 "IP access-list number\n"
5386 "IP access-list number (expanded range)\n"
5387 "IP Access-list name\n"
5388 "Filter incoming updates\n"
5389 "Filter outgoing updates\n")
596c17ba 5390
718e3744 5391/* Set prefix list to the peer. */
d62a17ae 5392static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5393 afi_t afi, safi_t safi,
5394 const char *name_str,
5395 const char *direct_str)
718e3744 5396{
d62a17ae 5397 int ret;
d62a17ae 5398 int direct = FILTER_IN;
cf9ac8bf 5399 struct peer *peer;
718e3744 5400
d62a17ae 5401 peer = peer_and_group_lookup_vty(vty, ip_str);
5402 if (!peer)
5403 return CMD_WARNING_CONFIG_FAILED;
718e3744 5404
d62a17ae 5405 /* Check filter direction. */
5406 if (strncmp(direct_str, "i", 1) == 0)
5407 direct = FILTER_IN;
5408 else if (strncmp(direct_str, "o", 1) == 0)
5409 direct = FILTER_OUT;
718e3744 5410
d62a17ae 5411 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5412
d62a17ae 5413 return bgp_vty_return(vty, ret);
718e3744 5414}
5415
d62a17ae 5416static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5417 afi_t afi, safi_t safi,
5418 const char *direct_str)
718e3744 5419{
d62a17ae 5420 int ret;
5421 struct peer *peer;
5422 int direct = FILTER_IN;
718e3744 5423
d62a17ae 5424 peer = peer_and_group_lookup_vty(vty, ip_str);
5425 if (!peer)
5426 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5427
d62a17ae 5428 /* Check filter direction. */
5429 if (strncmp(direct_str, "i", 1) == 0)
5430 direct = FILTER_IN;
5431 else if (strncmp(direct_str, "o", 1) == 0)
5432 direct = FILTER_OUT;
718e3744 5433
d62a17ae 5434 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5435
d62a17ae 5436 return bgp_vty_return(vty, ret);
718e3744 5437}
5438
5439DEFUN (neighbor_prefix_list,
5440 neighbor_prefix_list_cmd,
9ccf14f7 5441 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5442 NEIGHBOR_STR
5443 NEIGHBOR_ADDR_STR2
5444 "Filter updates to/from this neighbor\n"
5445 "Name of a prefix list\n"
5446 "Filter incoming updates\n"
5447 "Filter outgoing updates\n")
5448{
d62a17ae 5449 int idx_peer = 1;
5450 int idx_word = 3;
5451 int idx_in_out = 4;
5452 return peer_prefix_list_set_vty(
5453 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5454 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5455}
5456
d62a17ae 5457ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5458 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5459 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5460 "Filter updates to/from this neighbor\n"
5461 "Name of a prefix list\n"
5462 "Filter incoming updates\n"
5463 "Filter outgoing updates\n")
596c17ba 5464
718e3744 5465DEFUN (no_neighbor_prefix_list,
5466 no_neighbor_prefix_list_cmd,
9ccf14f7 5467 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5468 NO_STR
5469 NEIGHBOR_STR
5470 NEIGHBOR_ADDR_STR2
5471 "Filter updates to/from this neighbor\n"
5472 "Name of a prefix list\n"
5473 "Filter incoming updates\n"
5474 "Filter outgoing updates\n")
5475{
d62a17ae 5476 int idx_peer = 2;
5477 int idx_in_out = 5;
5478 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5479 bgp_node_afi(vty), bgp_node_safi(vty),
5480 argv[idx_in_out]->arg);
718e3744 5481}
6b0655a2 5482
d62a17ae 5483ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5484 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5485 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5486 "Filter updates to/from this neighbor\n"
5487 "Name of a prefix list\n"
5488 "Filter incoming updates\n"
5489 "Filter outgoing updates\n")
596c17ba 5490
d62a17ae 5491static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5492 safi_t safi, const char *name_str,
5493 const char *direct_str)
718e3744 5494{
d62a17ae 5495 int ret;
5496 struct peer *peer;
5497 int direct = FILTER_IN;
718e3744 5498
d62a17ae 5499 peer = peer_and_group_lookup_vty(vty, ip_str);
5500 if (!peer)
5501 return CMD_WARNING_CONFIG_FAILED;
718e3744 5502
d62a17ae 5503 /* Check filter direction. */
5504 if (strncmp(direct_str, "i", 1) == 0)
5505 direct = FILTER_IN;
5506 else if (strncmp(direct_str, "o", 1) == 0)
5507 direct = FILTER_OUT;
718e3744 5508
d62a17ae 5509 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5510
d62a17ae 5511 return bgp_vty_return(vty, ret);
718e3744 5512}
5513
d62a17ae 5514static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5515 safi_t safi, const char *direct_str)
718e3744 5516{
d62a17ae 5517 int ret;
5518 struct peer *peer;
5519 int direct = FILTER_IN;
718e3744 5520
d62a17ae 5521 peer = peer_and_group_lookup_vty(vty, ip_str);
5522 if (!peer)
5523 return CMD_WARNING_CONFIG_FAILED;
718e3744 5524
d62a17ae 5525 /* Check filter direction. */
5526 if (strncmp(direct_str, "i", 1) == 0)
5527 direct = FILTER_IN;
5528 else if (strncmp(direct_str, "o", 1) == 0)
5529 direct = FILTER_OUT;
718e3744 5530
d62a17ae 5531 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5532
d62a17ae 5533 return bgp_vty_return(vty, ret);
718e3744 5534}
5535
5536DEFUN (neighbor_filter_list,
5537 neighbor_filter_list_cmd,
9ccf14f7 5538 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5539 NEIGHBOR_STR
5540 NEIGHBOR_ADDR_STR2
5541 "Establish BGP filters\n"
5542 "AS path access-list name\n"
5543 "Filter incoming routes\n"
5544 "Filter outgoing routes\n")
5545{
d62a17ae 5546 int idx_peer = 1;
5547 int idx_word = 3;
5548 int idx_in_out = 4;
5549 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5550 bgp_node_safi(vty), argv[idx_word]->arg,
5551 argv[idx_in_out]->arg);
718e3744 5552}
5553
d62a17ae 5554ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5555 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5556 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5557 "Establish BGP filters\n"
5558 "AS path access-list name\n"
5559 "Filter incoming routes\n"
5560 "Filter outgoing routes\n")
596c17ba 5561
718e3744 5562DEFUN (no_neighbor_filter_list,
5563 no_neighbor_filter_list_cmd,
9ccf14f7 5564 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5565 NO_STR
5566 NEIGHBOR_STR
5567 NEIGHBOR_ADDR_STR2
5568 "Establish BGP filters\n"
5569 "AS path access-list name\n"
5570 "Filter incoming routes\n"
5571 "Filter outgoing routes\n")
5572{
d62a17ae 5573 int idx_peer = 2;
5574 int idx_in_out = 5;
5575 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5576 bgp_node_afi(vty), bgp_node_safi(vty),
5577 argv[idx_in_out]->arg);
718e3744 5578}
6b0655a2 5579
d62a17ae 5580ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5581 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5582 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5583 "Establish BGP filters\n"
5584 "AS path access-list name\n"
5585 "Filter incoming routes\n"
5586 "Filter outgoing routes\n")
596c17ba 5587
718e3744 5588/* Set route-map to the peer. */
d62a17ae 5589static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5590 afi_t afi, safi_t safi, const char *name_str,
5591 const char *direct_str)
718e3744 5592{
d62a17ae 5593 int ret;
5594 struct peer *peer;
5595 int direct = RMAP_IN;
718e3744 5596
d62a17ae 5597 peer = peer_and_group_lookup_vty(vty, ip_str);
5598 if (!peer)
5599 return CMD_WARNING_CONFIG_FAILED;
718e3744 5600
d62a17ae 5601 /* Check filter direction. */
5602 if (strncmp(direct_str, "in", 2) == 0)
5603 direct = RMAP_IN;
5604 else if (strncmp(direct_str, "o", 1) == 0)
5605 direct = RMAP_OUT;
718e3744 5606
d62a17ae 5607 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5608
d62a17ae 5609 return bgp_vty_return(vty, ret);
718e3744 5610}
5611
d62a17ae 5612static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5613 afi_t afi, safi_t safi,
5614 const char *direct_str)
718e3744 5615{
d62a17ae 5616 int ret;
5617 struct peer *peer;
5618 int direct = RMAP_IN;
718e3744 5619
d62a17ae 5620 peer = peer_and_group_lookup_vty(vty, ip_str);
5621 if (!peer)
5622 return CMD_WARNING_CONFIG_FAILED;
718e3744 5623
d62a17ae 5624 /* Check filter direction. */
5625 if (strncmp(direct_str, "in", 2) == 0)
5626 direct = RMAP_IN;
5627 else if (strncmp(direct_str, "o", 1) == 0)
5628 direct = RMAP_OUT;
718e3744 5629
d62a17ae 5630 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5631
d62a17ae 5632 return bgp_vty_return(vty, ret);
718e3744 5633}
5634
5635DEFUN (neighbor_route_map,
5636 neighbor_route_map_cmd,
9ccf14f7 5637 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5638 NEIGHBOR_STR
5639 NEIGHBOR_ADDR_STR2
5640 "Apply route map to neighbor\n"
5641 "Name of route map\n"
5642 "Apply map to incoming routes\n"
2a3d5731 5643 "Apply map to outbound routes\n")
718e3744 5644{
d62a17ae 5645 int idx_peer = 1;
5646 int idx_word = 3;
5647 int idx_in_out = 4;
5648 return peer_route_map_set_vty(
5649 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5650 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5651}
5652
d62a17ae 5653ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5654 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5655 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5656 "Apply route map to neighbor\n"
5657 "Name of route map\n"
5658 "Apply map to incoming routes\n"
5659 "Apply map to outbound routes\n")
596c17ba 5660
718e3744 5661DEFUN (no_neighbor_route_map,
5662 no_neighbor_route_map_cmd,
9ccf14f7 5663 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5664 NO_STR
5665 NEIGHBOR_STR
5666 NEIGHBOR_ADDR_STR2
5667 "Apply route map to neighbor\n"
5668 "Name of route map\n"
5669 "Apply map to incoming routes\n"
2a3d5731 5670 "Apply map to outbound routes\n")
718e3744 5671{
d62a17ae 5672 int idx_peer = 2;
5673 int idx_in_out = 5;
5674 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5675 bgp_node_afi(vty), bgp_node_safi(vty),
5676 argv[idx_in_out]->arg);
718e3744 5677}
6b0655a2 5678
d62a17ae 5679ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5680 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5681 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5682 "Apply route map to neighbor\n"
5683 "Name of route map\n"
5684 "Apply map to incoming routes\n"
5685 "Apply map to outbound routes\n")
596c17ba 5686
718e3744 5687/* Set unsuppress-map to the peer. */
d62a17ae 5688static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5689 afi_t afi, safi_t safi,
5690 const char *name_str)
718e3744 5691{
d62a17ae 5692 int ret;
5693 struct peer *peer;
718e3744 5694
d62a17ae 5695 peer = peer_and_group_lookup_vty(vty, ip_str);
5696 if (!peer)
5697 return CMD_WARNING_CONFIG_FAILED;
718e3744 5698
d62a17ae 5699 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5700
d62a17ae 5701 return bgp_vty_return(vty, ret);
718e3744 5702}
5703
5704/* Unset route-map from the peer. */
d62a17ae 5705static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5706 afi_t afi, safi_t safi)
718e3744 5707{
d62a17ae 5708 int ret;
5709 struct peer *peer;
718e3744 5710
d62a17ae 5711 peer = peer_and_group_lookup_vty(vty, ip_str);
5712 if (!peer)
5713 return CMD_WARNING_CONFIG_FAILED;
718e3744 5714
d62a17ae 5715 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5716
d62a17ae 5717 return bgp_vty_return(vty, ret);
718e3744 5718}
5719
5720DEFUN (neighbor_unsuppress_map,
5721 neighbor_unsuppress_map_cmd,
9ccf14f7 5722 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5723 NEIGHBOR_STR
5724 NEIGHBOR_ADDR_STR2
5725 "Route-map to selectively unsuppress suppressed routes\n"
5726 "Name of route map\n")
5727{
d62a17ae 5728 int idx_peer = 1;
5729 int idx_word = 3;
5730 return peer_unsuppress_map_set_vty(
5731 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5732 argv[idx_word]->arg);
718e3744 5733}
5734
d62a17ae 5735ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5736 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5737 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5738 "Route-map to selectively unsuppress suppressed routes\n"
5739 "Name of route map\n")
596c17ba 5740
718e3744 5741DEFUN (no_neighbor_unsuppress_map,
5742 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5743 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5744 NO_STR
5745 NEIGHBOR_STR
5746 NEIGHBOR_ADDR_STR2
5747 "Route-map to selectively unsuppress suppressed routes\n"
5748 "Name of route map\n")
5749{
d62a17ae 5750 int idx_peer = 2;
5751 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5752 bgp_node_afi(vty),
5753 bgp_node_safi(vty));
718e3744 5754}
6b0655a2 5755
d62a17ae 5756ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5757 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5758 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5759 "Route-map to selectively unsuppress suppressed routes\n"
5760 "Name of route map\n")
596c17ba 5761
d62a17ae 5762static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5763 afi_t afi, safi_t safi,
5764 const char *num_str,
5765 const char *threshold_str, int warning,
5766 const char *restart_str)
718e3744 5767{
d62a17ae 5768 int ret;
5769 struct peer *peer;
d7c0a89a
QY
5770 uint32_t max;
5771 uint8_t threshold;
5772 uint16_t restart;
718e3744 5773
d62a17ae 5774 peer = peer_and_group_lookup_vty(vty, ip_str);
5775 if (!peer)
5776 return CMD_WARNING_CONFIG_FAILED;
718e3744 5777
d62a17ae 5778 max = strtoul(num_str, NULL, 10);
5779 if (threshold_str)
5780 threshold = atoi(threshold_str);
5781 else
5782 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5783
d62a17ae 5784 if (restart_str)
5785 restart = atoi(restart_str);
5786 else
5787 restart = 0;
0a486e5f 5788
d62a17ae 5789 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5790 restart);
718e3744 5791
d62a17ae 5792 return bgp_vty_return(vty, ret);
718e3744 5793}
5794
d62a17ae 5795static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5796 afi_t afi, safi_t safi)
718e3744 5797{
d62a17ae 5798 int ret;
5799 struct peer *peer;
718e3744 5800
d62a17ae 5801 peer = peer_and_group_lookup_vty(vty, ip_str);
5802 if (!peer)
5803 return CMD_WARNING_CONFIG_FAILED;
718e3744 5804
d62a17ae 5805 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5806
d62a17ae 5807 return bgp_vty_return(vty, ret);
718e3744 5808}
5809
5810/* Maximum number of prefix configuration. prefix count is different
5811 for each peer configuration. So this configuration can be set for
5812 each peer configuration. */
5813DEFUN (neighbor_maximum_prefix,
5814 neighbor_maximum_prefix_cmd,
9ccf14f7 5815 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5816 NEIGHBOR_STR
5817 NEIGHBOR_ADDR_STR2
5818 "Maximum number of prefix accept from this peer\n"
5819 "maximum no. of prefix limit\n")
5820{
d62a17ae 5821 int idx_peer = 1;
5822 int idx_number = 3;
5823 return peer_maximum_prefix_set_vty(
5824 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5825 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5826}
5827
d62a17ae 5828ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Maximum number of prefix accept from this peer\n"
5832 "maximum no. of prefix limit\n")
596c17ba 5833
e0701b79 5834DEFUN (neighbor_maximum_prefix_threshold,
5835 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5836 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5837 NEIGHBOR_STR
5838 NEIGHBOR_ADDR_STR2
5839 "Maximum number of prefix accept from this peer\n"
5840 "maximum no. of prefix limit\n"
5841 "Threshold value (%) at which to generate a warning msg\n")
5842{
d62a17ae 5843 int idx_peer = 1;
5844 int idx_number = 3;
5845 int idx_number_2 = 4;
5846 return peer_maximum_prefix_set_vty(
5847 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5848 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5849}
e0701b79 5850
d62a17ae 5851ALIAS_HIDDEN(
5852 neighbor_maximum_prefix_threshold,
5853 neighbor_maximum_prefix_threshold_hidden_cmd,
5854 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5855 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5856 "Maximum number of prefix accept from this peer\n"
5857 "maximum no. of prefix limit\n"
5858 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5859
718e3744 5860DEFUN (neighbor_maximum_prefix_warning,
5861 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5862 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5863 NEIGHBOR_STR
5864 NEIGHBOR_ADDR_STR2
5865 "Maximum number of prefix accept from this peer\n"
5866 "maximum no. of prefix limit\n"
5867 "Only give warning message when limit is exceeded\n")
5868{
d62a17ae 5869 int idx_peer = 1;
5870 int idx_number = 3;
5871 return peer_maximum_prefix_set_vty(
5872 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5873 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5874}
5875
d62a17ae 5876ALIAS_HIDDEN(
5877 neighbor_maximum_prefix_warning,
5878 neighbor_maximum_prefix_warning_hidden_cmd,
5879 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5880 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5881 "Maximum number of prefix accept from this peer\n"
5882 "maximum no. of prefix limit\n"
5883 "Only give warning message when limit is exceeded\n")
596c17ba 5884
e0701b79 5885DEFUN (neighbor_maximum_prefix_threshold_warning,
5886 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5887 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5888 NEIGHBOR_STR
5889 NEIGHBOR_ADDR_STR2
5890 "Maximum number of prefix accept from this peer\n"
5891 "maximum no. of prefix limit\n"
5892 "Threshold value (%) at which to generate a warning msg\n"
5893 "Only give warning message when limit is exceeded\n")
5894{
d62a17ae 5895 int idx_peer = 1;
5896 int idx_number = 3;
5897 int idx_number_2 = 4;
5898 return peer_maximum_prefix_set_vty(
5899 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5900 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5901}
5902
d62a17ae 5903ALIAS_HIDDEN(
5904 neighbor_maximum_prefix_threshold_warning,
5905 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5906 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5908 "Maximum number of prefix accept from this peer\n"
5909 "maximum no. of prefix limit\n"
5910 "Threshold value (%) at which to generate a warning msg\n"
5911 "Only give warning message when limit is exceeded\n")
596c17ba 5912
0a486e5f 5913DEFUN (neighbor_maximum_prefix_restart,
5914 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5915 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5916 NEIGHBOR_STR
5917 NEIGHBOR_ADDR_STR2
5918 "Maximum number of prefix accept from this peer\n"
5919 "maximum no. of prefix limit\n"
5920 "Restart bgp connection after limit is exceeded\n"
efd7904e 5921 "Restart interval in minutes\n")
0a486e5f 5922{
d62a17ae 5923 int idx_peer = 1;
5924 int idx_number = 3;
5925 int idx_number_2 = 5;
5926 return peer_maximum_prefix_set_vty(
5927 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5928 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5929}
5930
d62a17ae 5931ALIAS_HIDDEN(
5932 neighbor_maximum_prefix_restart,
5933 neighbor_maximum_prefix_restart_hidden_cmd,
5934 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5935 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5936 "Maximum number of prefix accept from this peer\n"
5937 "maximum no. of prefix limit\n"
5938 "Restart bgp connection after limit is exceeded\n"
efd7904e 5939 "Restart interval in minutes\n")
596c17ba 5940
0a486e5f 5941DEFUN (neighbor_maximum_prefix_threshold_restart,
5942 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5943 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5944 NEIGHBOR_STR
5945 NEIGHBOR_ADDR_STR2
16cedbb0 5946 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5947 "maximum no. of prefix limit\n"
5948 "Threshold value (%) at which to generate a warning msg\n"
5949 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5950 "Restart interval in minutes\n")
0a486e5f 5951{
d62a17ae 5952 int idx_peer = 1;
5953 int idx_number = 3;
5954 int idx_number_2 = 4;
5955 int idx_number_3 = 6;
5956 return peer_maximum_prefix_set_vty(
5957 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5958 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5959 argv[idx_number_3]->arg);
5960}
5961
5962ALIAS_HIDDEN(
5963 neighbor_maximum_prefix_threshold_restart,
5964 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5965 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5966 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "Maximum number of prefixes to accept from this peer\n"
5968 "maximum no. of prefix limit\n"
5969 "Threshold value (%) at which to generate a warning msg\n"
5970 "Restart bgp connection after limit is exceeded\n"
5971 "Restart interval in minutes\n")
596c17ba 5972
718e3744 5973DEFUN (no_neighbor_maximum_prefix,
5974 no_neighbor_maximum_prefix_cmd,
d04c479d 5975 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5976 NO_STR
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
16cedbb0 5979 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5980 "maximum no. of prefix limit\n"
5981 "Threshold value (%) at which to generate a warning msg\n"
5982 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5983 "Restart interval in minutes\n"
31500417 5984 "Only give warning message when limit is exceeded\n")
718e3744 5985{
d62a17ae 5986 int idx_peer = 2;
5987 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5988 bgp_node_afi(vty),
5989 bgp_node_safi(vty));
718e3744 5990}
e52702f2 5991
d62a17ae 5992ALIAS_HIDDEN(
5993 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5994 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5995 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5996 "Maximum number of prefixes to accept from this peer\n"
5997 "maximum no. of prefix limit\n"
5998 "Threshold value (%) at which to generate a warning msg\n"
5999 "Restart bgp connection after limit is exceeded\n"
6000 "Restart interval in minutes\n"
6001 "Only give warning message when limit is exceeded\n")
596c17ba 6002
718e3744 6003
718e3744 6004/* "neighbor allowas-in" */
6005DEFUN (neighbor_allowas_in,
6006 neighbor_allowas_in_cmd,
fd8503f5 6007 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6008 NEIGHBOR_STR
6009 NEIGHBOR_ADDR_STR2
31500417 6010 "Accept as-path with my AS present in it\n"
fd8503f5
QY
6011 "Number of occurances of AS number\n"
6012 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6013{
d62a17ae 6014 int idx_peer = 1;
6015 int idx_number_origin = 3;
6016 int ret;
6017 int origin = 0;
6018 struct peer *peer;
6019 int allow_num = 0;
6020
6021 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6022 if (!peer)
6023 return CMD_WARNING_CONFIG_FAILED;
6024
6025 if (argc <= idx_number_origin)
6026 allow_num = 3;
6027 else {
6028 if (argv[idx_number_origin]->type == WORD_TKN)
6029 origin = 1;
6030 else
6031 allow_num = atoi(argv[idx_number_origin]->arg);
6032 }
6033
6034 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6035 allow_num, origin);
6036
6037 return bgp_vty_return(vty, ret);
6038}
6039
6040ALIAS_HIDDEN(
6041 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6042 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6043 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6044 "Accept as-path with my AS present in it\n"
6045 "Number of occurances of AS number\n"
6046 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6047
718e3744 6048DEFUN (no_neighbor_allowas_in,
6049 no_neighbor_allowas_in_cmd,
fd8503f5 6050 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6051 NO_STR
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
8334fd5a 6054 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
6055 "Number of occurances of AS number\n"
6056 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6057{
d62a17ae 6058 int idx_peer = 2;
6059 int ret;
6060 struct peer *peer;
718e3744 6061
d62a17ae 6062 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6063 if (!peer)
6064 return CMD_WARNING_CONFIG_FAILED;
718e3744 6065
d62a17ae 6066 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6067 bgp_node_safi(vty));
718e3744 6068
d62a17ae 6069 return bgp_vty_return(vty, ret);
718e3744 6070}
6b0655a2 6071
d62a17ae 6072ALIAS_HIDDEN(
6073 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6074 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6075 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6076 "allow local ASN appears in aspath attribute\n"
6077 "Number of occurances of AS number\n"
6078 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6079
fa411a21
NH
6080DEFUN (neighbor_ttl_security,
6081 neighbor_ttl_security_cmd,
7ebe625c 6082 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6083 NEIGHBOR_STR
7ebe625c 6084 NEIGHBOR_ADDR_STR2
16cedbb0 6085 "BGP ttl-security parameters\n"
d7fa34c1
QY
6086 "Specify the maximum number of hops to the BGP peer\n"
6087 "Number of hops to BGP peer\n")
fa411a21 6088{
d62a17ae 6089 int idx_peer = 1;
6090 int idx_number = 4;
6091 struct peer *peer;
6092 int gtsm_hops;
6093
6094 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6095 if (!peer)
6096 return CMD_WARNING_CONFIG_FAILED;
6097
6098 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6099
7ebe625c
QY
6100 /*
6101 * If 'neighbor swpX', then this is for directly connected peers,
6102 * we should not accept a ttl-security hops value greater than 1.
6103 */
6104 if (peer->conf_if && (gtsm_hops > 1)) {
6105 vty_out(vty,
6106 "%s is directly connected peer, hops cannot exceed 1\n",
6107 argv[idx_peer]->arg);
6108 return CMD_WARNING_CONFIG_FAILED;
6109 }
6110
d62a17ae 6111 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6112}
6113
6114DEFUN (no_neighbor_ttl_security,
6115 no_neighbor_ttl_security_cmd,
7ebe625c 6116 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6117 NO_STR
6118 NEIGHBOR_STR
7ebe625c 6119 NEIGHBOR_ADDR_STR2
16cedbb0 6120 "BGP ttl-security parameters\n"
3a2d747c
QY
6121 "Specify the maximum number of hops to the BGP peer\n"
6122 "Number of hops to BGP peer\n")
fa411a21 6123{
d62a17ae 6124 int idx_peer = 2;
6125 struct peer *peer;
fa411a21 6126
d62a17ae 6127 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6128 if (!peer)
6129 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6130
d62a17ae 6131 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6132}
6b0655a2 6133
adbac85e
DW
6134DEFUN (neighbor_addpath_tx_all_paths,
6135 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6136 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6137 NEIGHBOR_STR
6138 NEIGHBOR_ADDR_STR2
6139 "Use addpath to advertise all paths to a neighbor\n")
6140{
d62a17ae 6141 int idx_peer = 1;
6142 struct peer *peer;
adbac85e 6143
d62a17ae 6144 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6145 if (!peer)
6146 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6147
d62a17ae 6148 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6149 bgp_node_safi(vty),
6150 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6151}
6152
d62a17ae 6153ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6154 neighbor_addpath_tx_all_paths_hidden_cmd,
6155 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6156 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6157 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6158
adbac85e
DW
6159DEFUN (no_neighbor_addpath_tx_all_paths,
6160 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6161 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6162 NO_STR
6163 NEIGHBOR_STR
6164 NEIGHBOR_ADDR_STR2
6165 "Use addpath to advertise all paths to a neighbor\n")
6166{
d62a17ae 6167 int idx_peer = 2;
6168 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6169 bgp_node_afi(vty), bgp_node_safi(vty),
6170 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6171}
6172
d62a17ae 6173ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6174 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6175 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6176 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6177 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6178
06370dac
DW
6179DEFUN (neighbor_addpath_tx_bestpath_per_as,
6180 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6181 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6182 NEIGHBOR_STR
6183 NEIGHBOR_ADDR_STR2
6184 "Use addpath to advertise the bestpath per each neighboring AS\n")
6185{
d62a17ae 6186 int idx_peer = 1;
6187 struct peer *peer;
06370dac 6188
d62a17ae 6189 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6190 if (!peer)
6191 return CMD_WARNING_CONFIG_FAILED;
06370dac 6192
d62a17ae 6193 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6194 bgp_node_safi(vty),
6195 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6196}
6197
d62a17ae 6198ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6199 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6200 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6201 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6202 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6203
06370dac
DW
6204DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6205 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6206 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6207 NO_STR
6208 NEIGHBOR_STR
6209 NEIGHBOR_ADDR_STR2
6210 "Use addpath to advertise the bestpath per each neighboring AS\n")
6211{
d62a17ae 6212 int idx_peer = 2;
6213 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6214 bgp_node_afi(vty), bgp_node_safi(vty),
6215 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6216}
6217
d62a17ae 6218ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6219 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6220 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6221 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6222 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6223
b9c7bc5a
PZ
6224static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6225 struct ecommunity **list)
ddb5b488 6226{
b9c7bc5a
PZ
6227 struct ecommunity *ecom = NULL;
6228 struct ecommunity *ecomadd;
ddb5b488 6229
b9c7bc5a 6230 for (; argc; --argc, ++argv) {
ddb5b488 6231
b9c7bc5a
PZ
6232 ecomadd = ecommunity_str2com(argv[0]->arg,
6233 ECOMMUNITY_ROUTE_TARGET, 0);
6234 if (!ecomadd) {
6235 vty_out(vty, "Malformed community-list value\n");
6236 if (ecom)
6237 ecommunity_free(&ecom);
6238 return CMD_WARNING_CONFIG_FAILED;
6239 }
ddb5b488 6240
b9c7bc5a
PZ
6241 if (ecom) {
6242 ecommunity_merge(ecom, ecomadd);
6243 ecommunity_free(&ecomadd);
6244 } else {
6245 ecom = ecomadd;
6246 }
6247 }
6248
6249 if (*list) {
6250 ecommunity_free(&*list);
ddb5b488 6251 }
b9c7bc5a
PZ
6252 *list = ecom;
6253
6254 return CMD_SUCCESS;
ddb5b488
PZ
6255}
6256
0ca70ba5
DS
6257/*
6258 * v2vimport is true if we are handling a `import vrf ...` command
6259 */
6260static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6261{
0ca70ba5
DS
6262 afi_t afi;
6263
ddb5b488 6264 switch (vty->node) {
b9c7bc5a 6265 case BGP_IPV4_NODE:
0ca70ba5
DS
6266 afi = AFI_IP;
6267 break;
b9c7bc5a 6268 case BGP_IPV6_NODE:
0ca70ba5
DS
6269 afi = AFI_IP6;
6270 break;
ddb5b488
PZ
6271 default:
6272 vty_out(vty,
b9c7bc5a 6273 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6274 return AFI_MAX;
ddb5b488 6275 }
69b07479 6276
0ca70ba5
DS
6277 if (!v2vimport) {
6278 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6279 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6280 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6281 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6282 vty_out(vty,
6283 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6284 return AFI_MAX;
6285 }
6286 } else {
6287 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6288 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6289 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6290 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6291 vty_out(vty,
6292 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6293 return AFI_MAX;
6294 }
6295 }
6296 return afi;
ddb5b488
PZ
6297}
6298
b9c7bc5a
PZ
6299DEFPY (af_rd_vpn_export,
6300 af_rd_vpn_export_cmd,
6301 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6302 NO_STR
ddb5b488 6303 "Specify route distinguisher\n"
b9c7bc5a
PZ
6304 "Between current address-family and vpn\n"
6305 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6306 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6307{
6308 VTY_DECLVAR_CONTEXT(bgp, bgp);
6309 struct prefix_rd prd;
6310 int ret;
ddb5b488 6311 afi_t afi;
b9c7bc5a
PZ
6312 int idx = 0;
6313 int yes = 1;
ddb5b488 6314
b9c7bc5a 6315 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6316 yes = 0;
b9c7bc5a
PZ
6317
6318 if (yes) {
6319 ret = str2prefix_rd(rd_str, &prd);
6320 if (!ret) {
6321 vty_out(vty, "%% Malformed rd\n");
6322 return CMD_WARNING_CONFIG_FAILED;
6323 }
ddb5b488
PZ
6324 }
6325
0ca70ba5 6326 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6327 if (afi == AFI_MAX)
6328 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6329
69b07479
DS
6330 /*
6331 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6332 */
6333 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6334 bgp_get_default(), bgp);
ddb5b488 6335
69b07479
DS
6336 if (yes) {
6337 bgp->vpn_policy[afi].tovpn_rd = prd;
6338 SET_FLAG(bgp->vpn_policy[afi].flags,
6339 BGP_VPN_POLICY_TOVPN_RD_SET);
6340 } else {
6341 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6342 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6343 }
6344
69b07479
DS
6345 /* post-change: re-export vpn routes */
6346 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6347 bgp_get_default(), bgp);
6348
ddb5b488
PZ
6349 return CMD_SUCCESS;
6350}
6351
b9c7bc5a
PZ
6352ALIAS (af_rd_vpn_export,
6353 af_no_rd_vpn_export_cmd,
6354 "no rd vpn export",
ddb5b488 6355 NO_STR
b9c7bc5a
PZ
6356 "Specify route distinguisher\n"
6357 "Between current address-family and vpn\n"
6358 "For routes leaked from current address-family to vpn\n")
ddb5b488 6359
b9c7bc5a
PZ
6360DEFPY (af_label_vpn_export,
6361 af_label_vpn_export_cmd,
e70e9f8e 6362 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6363 NO_STR
ddb5b488 6364 "label value for VRF\n"
b9c7bc5a
PZ
6365 "Between current address-family and vpn\n"
6366 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6367 "Label Value <0-1048575>\n"
6368 "Automatically assign a label\n")
ddb5b488
PZ
6369{
6370 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6371 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6372 afi_t afi;
b9c7bc5a
PZ
6373 int idx = 0;
6374 int yes = 1;
6375
6376 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6377 yes = 0;
ddb5b488 6378
21a16cc2
PZ
6379 /* If "no ...", squash trailing parameter */
6380 if (!yes)
6381 label_auto = NULL;
6382
e70e9f8e
PZ
6383 if (yes) {
6384 if (!label_auto)
6385 label = label_val; /* parser should force unsigned */
6386 }
ddb5b488 6387
0ca70ba5 6388 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6389 if (afi == AFI_MAX)
6390 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6391
e70e9f8e 6392
69b07479
DS
6393 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6394 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6395 /* no change */
6396 return CMD_SUCCESS;
e70e9f8e 6397
69b07479
DS
6398 /*
6399 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6400 */
6401 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6402 bgp_get_default(), bgp);
6403
6404 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6405 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6406
6407 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6408
6409 /*
6410 * label has previously been automatically
6411 * assigned by labelpool: release it
6412 *
6413 * NB if tovpn_label == MPLS_LABEL_NONE it
6414 * means the automatic assignment is in flight
6415 * and therefore the labelpool callback must
6416 * detect that the auto label is not needed.
6417 */
6418
6419 bgp_lp_release(LP_TYPE_VRF,
6420 &bgp->vpn_policy[afi],
6421 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6422 }
69b07479
DS
6423 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6424 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6425 }
ddb5b488 6426
69b07479
DS
6427 bgp->vpn_policy[afi].tovpn_label = label;
6428 if (label_auto) {
6429 SET_FLAG(bgp->vpn_policy[afi].flags,
6430 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6431 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6432 vpn_leak_label_callback);
ddb5b488
PZ
6433 }
6434
69b07479
DS
6435 /* post-change: re-export vpn routes */
6436 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6437 bgp_get_default(), bgp);
6438
ddb5b488
PZ
6439 return CMD_SUCCESS;
6440}
6441
b9c7bc5a
PZ
6442ALIAS (af_label_vpn_export,
6443 af_no_label_vpn_export_cmd,
6444 "no label vpn export",
6445 NO_STR
6446 "label value for VRF\n"
6447 "Between current address-family and vpn\n"
6448 "For routes leaked from current address-family to vpn\n")
ddb5b488 6449
b9c7bc5a
PZ
6450DEFPY (af_nexthop_vpn_export,
6451 af_nexthop_vpn_export_cmd,
6452 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6453 NO_STR
ddb5b488 6454 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6455 "Between current address-family and vpn\n"
6456 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6457 "IPv4 prefix\n"
6458 "IPv6 prefix\n")
6459{
6460 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6461 afi_t afi;
ddb5b488 6462 struct prefix p;
b9c7bc5a
PZ
6463 int idx = 0;
6464 int yes = 1;
ddb5b488 6465
b9c7bc5a 6466 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6467 yes = 0;
b9c7bc5a
PZ
6468
6469 if (yes) {
6470 if (!sockunion2hostprefix(nexthop_str, &p))
6471 return CMD_WARNING_CONFIG_FAILED;
6472 }
ddb5b488 6473
0ca70ba5 6474 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6475 if (afi == AFI_MAX)
6476 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6477
69b07479
DS
6478 /*
6479 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6480 */
6481 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6482 bgp_get_default(), bgp);
ddb5b488 6483
69b07479
DS
6484 if (yes) {
6485 bgp->vpn_policy[afi].tovpn_nexthop = p;
6486 SET_FLAG(bgp->vpn_policy[afi].flags,
6487 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6488 } else {
6489 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6490 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6491 }
6492
69b07479
DS
6493 /* post-change: re-export vpn routes */
6494 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6495 bgp_get_default(), bgp);
6496
ddb5b488
PZ
6497 return CMD_SUCCESS;
6498}
6499
b9c7bc5a
PZ
6500ALIAS (af_nexthop_vpn_export,
6501 af_no_nexthop_vpn_export_cmd,
6502 "no nexthop vpn export",
ddb5b488 6503 NO_STR
b9c7bc5a
PZ
6504 "Specify next hop to use for VRF advertised prefixes\n"
6505 "Between current address-family and vpn\n"
6506 "For routes leaked from current address-family to vpn\n")
ddb5b488 6507
b9c7bc5a 6508static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6509{
b9c7bc5a
PZ
6510 if (!strcmp(dstr, "import")) {
6511 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6512 } else if (!strcmp(dstr, "export")) {
6513 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6514 } else if (!strcmp(dstr, "both")) {
6515 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6516 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6517 } else {
6518 vty_out(vty, "%% direction parse error\n");
6519 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6520 }
ddb5b488
PZ
6521 return CMD_SUCCESS;
6522}
6523
b9c7bc5a
PZ
6524DEFPY (af_rt_vpn_imexport,
6525 af_rt_vpn_imexport_cmd,
6526 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6527 NO_STR
6528 "Specify route target list\n"
ddb5b488 6529 "Specify route target list\n"
b9c7bc5a
PZ
6530 "Between current address-family and vpn\n"
6531 "For routes leaked from vpn to current address-family: match any\n"
6532 "For routes leaked from current address-family to vpn: set\n"
6533 "both import: match any and export: set\n"
ddb5b488
PZ
6534 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6535{
6536 VTY_DECLVAR_CONTEXT(bgp, bgp);
6537 int ret;
6538 struct ecommunity *ecom = NULL;
6539 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6540 vpn_policy_direction_t dir;
6541 afi_t afi;
6542 int idx = 0;
b9c7bc5a 6543 int yes = 1;
ddb5b488 6544
b9c7bc5a 6545 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6546 yes = 0;
b9c7bc5a 6547
0ca70ba5 6548 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6549 if (afi == AFI_MAX)
6550 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6551
b9c7bc5a 6552 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6553 if (ret != CMD_SUCCESS)
6554 return ret;
6555
b9c7bc5a
PZ
6556 if (yes) {
6557 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6558 vty_out(vty, "%% Missing RTLIST\n");
6559 return CMD_WARNING_CONFIG_FAILED;
6560 }
6561 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6562 if (ret != CMD_SUCCESS) {
6563 return ret;
6564 }
ddb5b488
PZ
6565 }
6566
69b07479
DS
6567 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6568 if (!dodir[dir])
ddb5b488 6569 continue;
ddb5b488 6570
69b07479 6571 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6572
69b07479
DS
6573 if (yes) {
6574 if (bgp->vpn_policy[afi].rtlist[dir])
6575 ecommunity_free(
6576 &bgp->vpn_policy[afi].rtlist[dir]);
6577 bgp->vpn_policy[afi].rtlist[dir] =
6578 ecommunity_dup(ecom);
6579 } else {
6580 if (bgp->vpn_policy[afi].rtlist[dir])
6581 ecommunity_free(
6582 &bgp->vpn_policy[afi].rtlist[dir]);
6583 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6584 }
69b07479
DS
6585
6586 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6587 }
69b07479 6588
d555f3e9
PZ
6589 if (ecom)
6590 ecommunity_free(&ecom);
ddb5b488
PZ
6591
6592 return CMD_SUCCESS;
6593}
6594
b9c7bc5a
PZ
6595ALIAS (af_rt_vpn_imexport,
6596 af_no_rt_vpn_imexport_cmd,
6597 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6598 NO_STR
6599 "Specify route target list\n"
b9c7bc5a
PZ
6600 "Specify route target list\n"
6601 "Between current address-family and vpn\n"
6602 "For routes leaked from vpn to current address-family\n"
6603 "For routes leaked from current address-family to vpn\n"
6604 "both import and export\n")
6605
6606DEFPY (af_route_map_vpn_imexport,
6607 af_route_map_vpn_imexport_cmd,
6608/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6609 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6610 NO_STR
ddb5b488 6611 "Specify route map\n"
b9c7bc5a
PZ
6612 "Between current address-family and vpn\n"
6613 "For routes leaked from vpn to current address-family\n"
6614 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6615 "name of route-map\n")
6616{
6617 VTY_DECLVAR_CONTEXT(bgp, bgp);
6618 int ret;
6619 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6620 vpn_policy_direction_t dir;
6621 afi_t afi;
ddb5b488 6622 int idx = 0;
b9c7bc5a 6623 int yes = 1;
ddb5b488 6624
b9c7bc5a 6625 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6626 yes = 0;
b9c7bc5a 6627
0ca70ba5 6628 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6629 if (afi == AFI_MAX)
6630 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6631
b9c7bc5a 6632 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6633 if (ret != CMD_SUCCESS)
6634 return ret;
6635
69b07479
DS
6636 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6637 if (!dodir[dir])
ddb5b488 6638 continue;
ddb5b488 6639
69b07479 6640 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6641
69b07479
DS
6642 if (yes) {
6643 if (bgp->vpn_policy[afi].rmap_name[dir])
6644 XFREE(MTYPE_ROUTE_MAP_NAME,
6645 bgp->vpn_policy[afi].rmap_name[dir]);
6646 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6647 MTYPE_ROUTE_MAP_NAME, rmap_str);
6648 bgp->vpn_policy[afi].rmap[dir] =
6649 route_map_lookup_by_name(rmap_str);
6650 if (!bgp->vpn_policy[afi].rmap[dir])
6651 return CMD_SUCCESS;
6652 } else {
6653 if (bgp->vpn_policy[afi].rmap_name[dir])
6654 XFREE(MTYPE_ROUTE_MAP_NAME,
6655 bgp->vpn_policy[afi].rmap_name[dir]);
6656 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6657 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6658 }
69b07479
DS
6659
6660 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6661 }
6662
6663 return CMD_SUCCESS;
6664}
6665
b9c7bc5a
PZ
6666ALIAS (af_route_map_vpn_imexport,
6667 af_no_route_map_vpn_imexport_cmd,
6668 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6669 NO_STR
6670 "Specify route map\n"
b9c7bc5a
PZ
6671 "Between current address-family and vpn\n"
6672 "For routes leaked from vpn to current address-family\n"
6673 "For routes leaked from current address-family to vpn\n")
6674
bb4f6190
DS
6675DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6676 "[no] import vrf route-map RMAP$rmap_str",
6677 NO_STR
6678 "Import routes from another VRF\n"
6679 "Vrf routes being filtered\n"
6680 "Specify route map\n"
6681 "name of route-map\n")
6682{
6683 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6684 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6685 afi_t afi;
6686 int idx = 0;
6687 int yes = 1;
6688 struct bgp *bgp_default;
6689
6690 if (argv_find(argv, argc, "no", &idx))
6691 yes = 0;
6692
0ca70ba5 6693 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6694 if (afi == AFI_MAX)
6695 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6696
6697 bgp_default = bgp_get_default();
6698 if (!bgp_default) {
6699 int32_t ret;
6700 as_t as = bgp->as;
6701
6702 /* Auto-create assuming the same AS */
6703 ret = bgp_get(&bgp_default, &as, NULL,
6704 BGP_INSTANCE_TYPE_DEFAULT);
6705
6706 if (ret) {
6707 vty_out(vty,
6708 "VRF default is not configured as a bgp instance\n");
6709 return CMD_WARNING;
6710 }
6711 }
6712
69b07479 6713 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6714
69b07479
DS
6715 if (yes) {
6716 if (bgp->vpn_policy[afi].rmap_name[dir])
6717 XFREE(MTYPE_ROUTE_MAP_NAME,
6718 bgp->vpn_policy[afi].rmap_name[dir]);
6719 bgp->vpn_policy[afi].rmap_name[dir] =
6720 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6721 bgp->vpn_policy[afi].rmap[dir] =
6722 route_map_lookup_by_name(rmap_str);
6723 if (!bgp->vpn_policy[afi].rmap[dir])
6724 return CMD_SUCCESS;
6725 } else {
6726 if (bgp->vpn_policy[afi].rmap_name[dir])
6727 XFREE(MTYPE_ROUTE_MAP_NAME,
6728 bgp->vpn_policy[afi].rmap_name[dir]);
6729 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6730 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6731 }
6732
69b07479
DS
6733 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6734
bb4f6190
DS
6735 return CMD_SUCCESS;
6736}
6737
6738ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6739 "no import vrf route-map",
6740 NO_STR
6741 "Import routes from another VRF\n"
6742 "Vrf routes being filtered\n"
6743 "Specify route map\n")
6744
12a844a5
DS
6745DEFPY (bgp_imexport_vrf,
6746 bgp_imexport_vrf_cmd,
6747 "[no] import vrf NAME$import_name",
6748 NO_STR
6749 "Import routes from another VRF\n"
6750 "VRF to import from\n"
6751 "The name of the VRF\n")
6752{
6753 VTY_DECLVAR_CONTEXT(bgp, bgp);
6754 struct listnode *node;
79ef8664
DS
6755 struct bgp *vrf_bgp, *bgp_default;
6756 int32_t ret = 0;
6757 as_t as = bgp->as;
12a844a5
DS
6758 bool remove = false;
6759 int32_t idx = 0;
6760 char *vname;
a8dadcf6 6761 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6762 safi_t safi;
6763 afi_t afi;
6764
867f0cca 6765 if (import_name == NULL) {
6766 vty_out(vty, "%% Missing import name\n");
6767 return CMD_WARNING;
6768 }
6769
12a844a5
DS
6770 if (argv_find(argv, argc, "no", &idx))
6771 remove = true;
6772
0ca70ba5
DS
6773 afi = vpn_policy_getafi(vty, bgp, true);
6774 if (afi == AFI_MAX)
6775 return CMD_WARNING_CONFIG_FAILED;
6776
12a844a5
DS
6777 safi = bgp_node_safi(vty);
6778
25679caa
DS
6779 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6780 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6781 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6782 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6783 remove ? "unimport" : "import", import_name);
6784 return CMD_WARNING;
6785 }
6786
79ef8664
DS
6787 bgp_default = bgp_get_default();
6788 if (!bgp_default) {
6789 /* Auto-create assuming the same AS */
6790 ret = bgp_get(&bgp_default, &as, NULL,
6791 BGP_INSTANCE_TYPE_DEFAULT);
6792
6793 if (ret) {
6794 vty_out(vty,
6795 "VRF default is not configured as a bgp instance\n");
6796 return CMD_WARNING;
6797 }
6798 }
6799
12a844a5
DS
6800 vrf_bgp = bgp_lookup_by_name(import_name);
6801 if (!vrf_bgp) {
79ef8664
DS
6802 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6803 vrf_bgp = bgp_default;
6804 else
0fb8d6e6
DS
6805 /* Auto-create assuming the same AS */
6806 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6807
6e2c7fe6 6808 if (ret) {
020a3f60
DS
6809 vty_out(vty,
6810 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6811 import_name);
6812 return CMD_WARNING;
6813 }
12a844a5
DS
6814 }
6815
12a844a5 6816 if (remove) {
44338987 6817 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6818 } else {
44338987 6819 /* Already importing from "import_vrf"? */
12a844a5
DS
6820 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6821 vname)) {
6822 if (strcmp(vname, import_name) == 0)
6823 return CMD_WARNING;
6824 }
6825
44338987 6826 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6827 }
6828
6829 return CMD_SUCCESS;
6830}
6831
b9c7bc5a
PZ
6832/* This command is valid only in a bgp vrf instance or the default instance */
6833DEFPY (bgp_imexport_vpn,
6834 bgp_imexport_vpn_cmd,
6835 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6836 NO_STR
6837 "Import routes to this address-family\n"
6838 "Export routes from this address-family\n"
6839 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6840{
6841 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6842 int previous_state;
ddb5b488 6843 afi_t afi;
b9c7bc5a 6844 safi_t safi;
ddb5b488 6845 int idx = 0;
b9c7bc5a
PZ
6846 int yes = 1;
6847 int flag;
6848 vpn_policy_direction_t dir;
ddb5b488 6849
b9c7bc5a 6850 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6851 yes = 0;
ddb5b488 6852
b9c7bc5a
PZ
6853 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6854 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6855
b9c7bc5a
PZ
6856 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6857 return CMD_WARNING_CONFIG_FAILED;
6858 }
ddb5b488 6859
b9c7bc5a
PZ
6860 afi = bgp_node_afi(vty);
6861 safi = bgp_node_safi(vty);
6862 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6863 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6864 return CMD_WARNING_CONFIG_FAILED;
6865 }
ddb5b488 6866
b9c7bc5a
PZ
6867 if (!strcmp(direction_str, "import")) {
6868 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6869 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6870 } else if (!strcmp(direction_str, "export")) {
6871 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6872 dir = BGP_VPN_POLICY_DIR_TOVPN;
6873 } else {
6874 vty_out(vty, "%% unknown direction %s\n", direction_str);
6875 return CMD_WARNING_CONFIG_FAILED;
6876 }
6877
6878 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6879
b9c7bc5a
PZ
6880 if (yes) {
6881 SET_FLAG(bgp->af_flags[afi][safi], flag);
6882 if (!previous_state) {
6883 /* trigger export current vrf */
ddb5b488
PZ
6884 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6885 }
b9c7bc5a
PZ
6886 } else {
6887 if (previous_state) {
6888 /* trigger un-export current vrf */
6889 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6890 }
6891 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6892 }
6893
6894 return CMD_SUCCESS;
6895}
6896
301ad80a
PG
6897DEFPY (af_routetarget_import,
6898 af_routetarget_import_cmd,
6899 "[no] <rt|route-target> redirect import RTLIST...",
6900 NO_STR
6901 "Specify route target list\n"
6902 "Specify route target list\n"
6903 "Flow-spec redirect type route target\n"
6904 "Import routes to this address-family\n"
6905 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6906{
6907 VTY_DECLVAR_CONTEXT(bgp, bgp);
6908 int ret;
6909 struct ecommunity *ecom = NULL;
301ad80a
PG
6910 afi_t afi;
6911 int idx = 0;
6912 int yes = 1;
6913
6914 if (argv_find(argv, argc, "no", &idx))
6915 yes = 0;
6916
0ca70ba5 6917 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6918 if (afi == AFI_MAX)
6919 return CMD_WARNING_CONFIG_FAILED;
6920
301ad80a
PG
6921 if (yes) {
6922 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6923 vty_out(vty, "%% Missing RTLIST\n");
6924 return CMD_WARNING_CONFIG_FAILED;
6925 }
6926 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6927 if (ret != CMD_SUCCESS)
6928 return ret;
6929 }
69b07479
DS
6930
6931 if (yes) {
6932 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6933 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6934 .import_redirect_rtlist);
69b07479
DS
6935 bgp->vpn_policy[afi].import_redirect_rtlist =
6936 ecommunity_dup(ecom);
6937 } else {
6938 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6939 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 6940 .import_redirect_rtlist);
69b07479 6941 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 6942 }
69b07479 6943
301ad80a
PG
6944 if (ecom)
6945 ecommunity_free(&ecom);
6946
6947 return CMD_SUCCESS;
6948}
6949
505e5056 6950DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 6951 address_family_ipv4_safi_cmd,
6952 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6953 "Enter Address Family command mode\n"
6954 "Address Family\n"
6955 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6956{
f51bae9c 6957
d62a17ae 6958 if (argc == 3) {
2131d5cf 6959 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6960 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6961 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6962 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6963 && safi != SAFI_EVPN) {
31947174
MK
6964 vty_out(vty,
6965 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6966 return CMD_WARNING_CONFIG_FAILED;
6967 }
d62a17ae 6968 vty->node = bgp_node_type(AFI_IP, safi);
6969 } else
6970 vty->node = BGP_IPV4_NODE;
718e3744 6971
d62a17ae 6972 return CMD_SUCCESS;
718e3744 6973}
6974
505e5056 6975DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 6976 address_family_ipv6_safi_cmd,
6977 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6978 "Enter Address Family command mode\n"
6979 "Address Family\n"
6980 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6981{
d62a17ae 6982 if (argc == 3) {
2131d5cf 6983 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6984 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6985 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6986 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6987 && safi != SAFI_EVPN) {
31947174
MK
6988 vty_out(vty,
6989 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6990 return CMD_WARNING_CONFIG_FAILED;
6991 }
d62a17ae 6992 vty->node = bgp_node_type(AFI_IP6, safi);
6993 } else
6994 vty->node = BGP_IPV6_NODE;
25ffbdc1 6995
d62a17ae 6996 return CMD_SUCCESS;
25ffbdc1 6997}
718e3744 6998
d6902373 6999#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7000DEFUN_NOSH (address_family_vpnv4,
718e3744 7001 address_family_vpnv4_cmd,
8334fd5a 7002 "address-family vpnv4 [unicast]",
718e3744 7003 "Enter Address Family command mode\n"
8c3deaae 7004 "Address Family\n"
3a2d747c 7005 "Address Family modifier\n")
718e3744 7006{
d62a17ae 7007 vty->node = BGP_VPNV4_NODE;
7008 return CMD_SUCCESS;
718e3744 7009}
7010
505e5056 7011DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7012 address_family_vpnv6_cmd,
8334fd5a 7013 "address-family vpnv6 [unicast]",
8ecd3266 7014 "Enter Address Family command mode\n"
8c3deaae 7015 "Address Family\n"
3a2d747c 7016 "Address Family modifier\n")
8ecd3266 7017{
d62a17ae 7018 vty->node = BGP_VPNV6_NODE;
7019 return CMD_SUCCESS;
8ecd3266 7020}
c016b6c7 7021#endif
d6902373 7022
505e5056 7023DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7024 address_family_evpn_cmd,
7111c1a0 7025 "address-family l2vpn evpn",
4e0b7b6d 7026 "Enter Address Family command mode\n"
7111c1a0
QY
7027 "Address Family\n"
7028 "Address Family modifier\n")
4e0b7b6d 7029{
2131d5cf 7030 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7031 vty->node = BGP_EVPN_NODE;
7032 return CMD_SUCCESS;
4e0b7b6d
PG
7033}
7034
505e5056 7035DEFUN_NOSH (exit_address_family,
718e3744 7036 exit_address_family_cmd,
7037 "exit-address-family",
7038 "Exit from Address Family configuration mode\n")
7039{
d62a17ae 7040 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7041 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7042 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7043 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7044 || vty->node == BGP_EVPN_NODE
7045 || vty->node == BGP_FLOWSPECV4_NODE
7046 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7047 vty->node = BGP_NODE;
7048 return CMD_SUCCESS;
718e3744 7049}
6b0655a2 7050
8ad7271d 7051/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7052static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7053 const char *ip_str, afi_t afi, safi_t safi,
7054 struct prefix_rd *prd)
7055{
7056 int ret;
7057 struct prefix match;
7058 struct bgp_node *rn;
7059 struct bgp_node *rm;
7060 struct bgp *bgp;
7061 struct bgp_table *table;
7062 struct bgp_table *rib;
7063
7064 /* BGP structure lookup. */
7065 if (view_name) {
7066 bgp = bgp_lookup_by_name(view_name);
7067 if (bgp == NULL) {
7068 vty_out(vty, "%% Can't find BGP instance %s\n",
7069 view_name);
7070 return CMD_WARNING;
7071 }
7072 } else {
7073 bgp = bgp_get_default();
7074 if (bgp == NULL) {
7075 vty_out(vty, "%% No BGP process is configured\n");
7076 return CMD_WARNING;
7077 }
7078 }
7079
7080 /* Check IP address argument. */
7081 ret = str2prefix(ip_str, &match);
7082 if (!ret) {
7083 vty_out(vty, "%% address is malformed\n");
7084 return CMD_WARNING;
7085 }
7086
7087 match.family = afi2family(afi);
7088 rib = bgp->rib[afi][safi];
7089
7090 if (safi == SAFI_MPLS_VPN) {
7091 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7092 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7093 continue;
7094
7095 if ((table = rn->info) != NULL) {
7096 if ((rm = bgp_node_match(table, &match))
7097 != NULL) {
7098 if (rm->p.prefixlen
7099 == match.prefixlen) {
343cdb61 7100 SET_FLAG(rm->flags,
d62a17ae 7101 BGP_NODE_USER_CLEAR);
7102 bgp_process(bgp, rm, afi, safi);
7103 }
7104 bgp_unlock_node(rm);
7105 }
7106 }
7107 }
7108 } else {
7109 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7110 if (rn->p.prefixlen == match.prefixlen) {
7111 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7112 bgp_process(bgp, rn, afi, safi);
7113 }
7114 bgp_unlock_node(rn);
7115 }
7116 }
7117
7118 return CMD_SUCCESS;
8ad7271d
DS
7119}
7120
b09b5ae0 7121/* one clear bgp command to rule them all */
718e3744 7122DEFUN (clear_ip_bgp_all,
7123 clear_ip_bgp_all_cmd,
c1a44e43 7124 "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 7125 CLEAR_STR
7126 IP_STR
7127 BGP_STR
838758ac 7128 BGP_INSTANCE_HELP_STR
510afcd6
DS
7129 BGP_AFI_HELP_STR
7130 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7131 "Clear all peers\n"
7132 "BGP neighbor address to clear\n"
a80beece 7133 "BGP IPv6 neighbor to clear\n"
838758ac 7134 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7135 "Clear peers with the AS number\n"
7136 "Clear all external peers\n"
718e3744 7137 "Clear all members of peer-group\n"
b09b5ae0 7138 "BGP peer-group name\n"
b09b5ae0
DW
7139 BGP_SOFT_STR
7140 BGP_SOFT_IN_STR
b09b5ae0
DW
7141 BGP_SOFT_OUT_STR
7142 BGP_SOFT_IN_STR
7143 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7144 BGP_SOFT_OUT_STR)
718e3744 7145{
d62a17ae 7146 char *vrf = NULL;
7147
7148 afi_t afi = AFI_IP6;
7149 safi_t safi = SAFI_UNICAST;
7150 enum clear_sort clr_sort = clear_peer;
7151 enum bgp_clear_type clr_type;
7152 char *clr_arg = NULL;
7153
7154 int idx = 0;
7155
7156 /* clear [ip] bgp */
7157 if (argv_find(argv, argc, "ip", &idx))
7158 afi = AFI_IP;
7159
9a8bdf1c
PG
7160 /* [<vrf> VIEWVRFNAME] */
7161 if (argv_find(argv, argc, "vrf", &idx)) {
7162 vrf = argv[idx + 1]->arg;
7163 idx += 2;
7164 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7165 vrf = NULL;
7166 } else if (argv_find(argv, argc, "view", &idx)) {
7167 /* [<view> VIEWVRFNAME] */
d62a17ae 7168 vrf = argv[idx + 1]->arg;
7169 idx += 2;
7170 }
d62a17ae 7171 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7172 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7173 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7174
7175 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7176 if (argv_find(argv, argc, "*", &idx)) {
7177 clr_sort = clear_all;
7178 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7179 clr_sort = clear_peer;
7180 clr_arg = argv[idx]->arg;
7181 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7182 clr_sort = clear_peer;
7183 clr_arg = argv[idx]->arg;
7184 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7185 clr_sort = clear_group;
7186 idx++;
7187 clr_arg = argv[idx]->arg;
7188 } else if (argv_find(argv, argc, "WORD", &idx)) {
7189 clr_sort = clear_peer;
7190 clr_arg = argv[idx]->arg;
7191 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7192 clr_sort = clear_as;
7193 clr_arg = argv[idx]->arg;
7194 } else if (argv_find(argv, argc, "external", &idx)) {
7195 clr_sort = clear_external;
7196 }
7197
7198 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7199 if (argv_find(argv, argc, "soft", &idx)) {
7200 if (argv_find(argv, argc, "in", &idx)
7201 || argv_find(argv, argc, "out", &idx))
7202 clr_type = strmatch(argv[idx]->text, "in")
7203 ? BGP_CLEAR_SOFT_IN
7204 : BGP_CLEAR_SOFT_OUT;
7205 else
7206 clr_type = BGP_CLEAR_SOFT_BOTH;
7207 } else if (argv_find(argv, argc, "in", &idx)) {
7208 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7209 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7210 : BGP_CLEAR_SOFT_IN;
7211 } else if (argv_find(argv, argc, "out", &idx)) {
7212 clr_type = BGP_CLEAR_SOFT_OUT;
7213 } else
7214 clr_type = BGP_CLEAR_SOFT_NONE;
7215
7216 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7217}
01080f7c 7218
8ad7271d
DS
7219DEFUN (clear_ip_bgp_prefix,
7220 clear_ip_bgp_prefix_cmd,
18c57037 7221 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7222 CLEAR_STR
7223 IP_STR
7224 BGP_STR
838758ac 7225 BGP_INSTANCE_HELP_STR
8ad7271d 7226 "Clear bestpath and re-advertise\n"
0c7b1b01 7227 "IPv4 prefix\n")
8ad7271d 7228{
d62a17ae 7229 char *vrf = NULL;
7230 char *prefix = NULL;
8ad7271d 7231
d62a17ae 7232 int idx = 0;
01080f7c 7233
d62a17ae 7234 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7235 if (argv_find(argv, argc, "vrf", &idx)) {
7236 vrf = argv[idx + 1]->arg;
7237 idx += 2;
7238 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7239 vrf = NULL;
7240 } else if (argv_find(argv, argc, "view", &idx)) {
7241 /* [<view> VIEWVRFNAME] */
7242 vrf = argv[idx + 1]->arg;
7243 idx += 2;
7244 }
0c7b1b01 7245
d62a17ae 7246 prefix = argv[argc - 1]->arg;
8ad7271d 7247
d62a17ae 7248 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7249}
8ad7271d 7250
b09b5ae0
DW
7251DEFUN (clear_bgp_ipv6_safi_prefix,
7252 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7253 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7254 CLEAR_STR
3a2d747c 7255 IP_STR
718e3744 7256 BGP_STR
8c3deaae 7257 "Address Family\n"
46f296b4 7258 BGP_SAFI_HELP_STR
b09b5ae0 7259 "Clear bestpath and re-advertise\n"
0c7b1b01 7260 "IPv6 prefix\n")
718e3744 7261{
9b475e76
PG
7262 int idx_safi = 0;
7263 int idx_ipv6_prefix = 0;
7264 safi_t safi = SAFI_UNICAST;
7265 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7266 argv[idx_ipv6_prefix]->arg : NULL;
7267
7268 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7269 return bgp_clear_prefix(
9b475e76
PG
7270 vty, NULL, prefix, AFI_IP6,
7271 safi, NULL);
838758ac 7272}
01080f7c 7273
b09b5ae0
DW
7274DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7275 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7276 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7277 CLEAR_STR
3a2d747c 7278 IP_STR
718e3744 7279 BGP_STR
838758ac 7280 BGP_INSTANCE_HELP_STR
8c3deaae 7281 "Address Family\n"
46f296b4 7282 BGP_SAFI_HELP_STR
b09b5ae0 7283 "Clear bestpath and re-advertise\n"
0c7b1b01 7284 "IPv6 prefix\n")
718e3744 7285{
9b475e76 7286 int idx_safi = 0;
9a8bdf1c 7287 int idx_vrfview = 0;
9b475e76
PG
7288 int idx_ipv6_prefix = 0;
7289 safi_t safi = SAFI_UNICAST;
7290 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7291 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7292 char *vrfview = NULL;
9b475e76 7293
9a8bdf1c
PG
7294 /* [<view|vrf> VIEWVRFNAME] */
7295 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7296 vrfview = argv[idx_vrfview + 1]->arg;
7297 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7298 vrfview = NULL;
7299 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7300 /* [<view> VIEWVRFNAME] */
7301 vrfview = argv[idx_vrfview + 1]->arg;
7302 }
9b475e76
PG
7303 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7304
d62a17ae 7305 return bgp_clear_prefix(
9b475e76
PG
7306 vty, vrfview, prefix,
7307 AFI_IP6, safi, NULL);
718e3744 7308}
7309
b09b5ae0
DW
7310DEFUN (show_bgp_views,
7311 show_bgp_views_cmd,
d6e3c605 7312 "show [ip] bgp views",
b09b5ae0 7313 SHOW_STR
d6e3c605 7314 IP_STR
01080f7c 7315 BGP_STR
b09b5ae0 7316 "Show the defined BGP views\n")
01080f7c 7317{
d62a17ae 7318 struct list *inst = bm->bgp;
7319 struct listnode *node;
7320 struct bgp *bgp;
01080f7c 7321
d62a17ae 7322 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7323 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7324 return CMD_WARNING;
7325 }
e52702f2 7326
d62a17ae 7327 vty_out(vty, "Defined BGP views:\n");
7328 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7329 /* Skip VRFs. */
7330 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7331 continue;
7332 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7333 bgp->as);
7334 }
e52702f2 7335
d62a17ae 7336 return CMD_SUCCESS;
e0081f70
ML
7337}
7338
8386ac43 7339DEFUN (show_bgp_vrfs,
7340 show_bgp_vrfs_cmd,
d6e3c605 7341 "show [ip] bgp vrfs [json]",
8386ac43 7342 SHOW_STR
d6e3c605 7343 IP_STR
8386ac43 7344 BGP_STR
7345 "Show BGP VRFs\n"
9973d184 7346 JSON_STR)
8386ac43 7347{
fe1dc5a3 7348 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7349 struct list *inst = bm->bgp;
7350 struct listnode *node;
7351 struct bgp *bgp;
9f049418 7352 bool uj = use_json(argc, argv);
d62a17ae 7353 json_object *json = NULL;
7354 json_object *json_vrfs = NULL;
7355 int count = 0;
d62a17ae 7356
7357 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7358 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7359 return CMD_WARNING;
7360 }
7361
7362 if (uj) {
7363 json = json_object_new_object();
7364 json_vrfs = json_object_new_object();
7365 }
7366
7367 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7368 const char *name, *type;
7369 struct peer *peer;
7fe96307 7370 struct listnode *node2, *nnode2;
d62a17ae 7371 int peers_cfg, peers_estb;
7372 json_object *json_vrf = NULL;
d62a17ae 7373
7374 /* Skip Views. */
7375 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7376 continue;
7377
7378 count++;
7379 if (!uj && count == 1)
fe1dc5a3
MK
7380 vty_out(vty,
7381 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7382 "Type", "Id", "routerId", "#PeersVfg",
7383 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7384
7385 peers_cfg = peers_estb = 0;
7386 if (uj)
7387 json_vrf = json_object_new_object();
7388
7389
7fe96307 7390 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7391 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7392 continue;
7393 peers_cfg++;
7394 if (peer->status == Established)
7395 peers_estb++;
7396 }
7397
7398 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7399 name = "Default";
7400 type = "DFLT";
7401 } else {
7402 name = bgp->name;
7403 type = "VRF";
7404 }
7405
a8bf7d9c 7406
d62a17ae 7407 if (uj) {
a4d82a8a
PZ
7408 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7409 ? -1
7410 : (int64_t)bgp->vrf_id;
d62a17ae 7411 json_object_string_add(json_vrf, "type", type);
7412 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7413 json_object_string_add(json_vrf, "routerId",
7414 inet_ntoa(bgp->router_id));
7415 json_object_int_add(json_vrf, "numConfiguredPeers",
7416 peers_cfg);
7417 json_object_int_add(json_vrf, "numEstablishedPeers",
7418 peers_estb);
7419
fe1dc5a3 7420 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7421 json_object_string_add(
7422 json_vrf, "rmac",
7423 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7424 json_object_object_add(json_vrfs, name, json_vrf);
7425 } else
fe1dc5a3
MK
7426 vty_out(vty,
7427 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7428 type,
7429 bgp->vrf_id == VRF_UNKNOWN ? -1
7430 : (int)bgp->vrf_id,
7431 inet_ntoa(bgp->router_id), peers_cfg,
7432 peers_estb, name, bgp->l3vni,
fe1dc5a3 7433 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7434 }
7435
7436 if (uj) {
7437 json_object_object_add(json, "vrfs", json_vrfs);
7438
7439 json_object_int_add(json, "totalVrfs", count);
7440
996c9314
LB
7441 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7442 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7443 json_object_free(json);
7444 } else {
7445 if (count)
7446 vty_out(vty,
7447 "\nTotal number of VRFs (including default): %d\n",
7448 count);
7449 }
7450
7451 return CMD_SUCCESS;
8386ac43 7452}
7453
acf71666
MK
7454static void show_address_entry(struct hash_backet *backet, void *args)
7455{
60466a63
QY
7456 struct vty *vty = (struct vty *)args;
7457 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7458
60466a63 7459 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7460 addr->refcnt);
7461}
7462
7463static void show_tip_entry(struct hash_backet *backet, void *args)
7464{
0291c246 7465 struct vty *vty = (struct vty *)args;
60466a63 7466 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7467
60466a63 7468 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7469 tip->refcnt);
7470}
7471
7472static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7473{
7474 vty_out(vty, "self nexthop database:\n");
7475 hash_iterate(bgp->address_hash,
7476 (void (*)(struct hash_backet *, void *))show_address_entry,
7477 vty);
7478
7479 vty_out(vty, "Tunnel-ip database:\n");
7480 hash_iterate(bgp->tip_hash,
7481 (void (*)(struct hash_backet *, void *))show_tip_entry,
7482 vty);
7483}
7484
15c81ca4
DS
7485DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7486 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7487 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7488 "martian next-hops\n"
7489 "martian next-hop database\n")
acf71666 7490{
0291c246 7491 struct bgp *bgp = NULL;
15c81ca4 7492 int idx = 0;
9a8bdf1c
PG
7493 char *name = NULL;
7494
7495 /* [<vrf> VIEWVRFNAME] */
7496 if (argv_find(argv, argc, "vrf", &idx)) {
7497 name = argv[idx + 1]->arg;
7498 if (name && strmatch(name, VRF_DEFAULT_NAME))
7499 name = NULL;
7500 } else if (argv_find(argv, argc, "view", &idx))
7501 /* [<view> VIEWVRFNAME] */
7502 name = argv[idx + 1]->arg;
7503 if (name)
7504 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7505 else
7506 bgp = bgp_get_default();
acf71666 7507
acf71666
MK
7508 if (!bgp) {
7509 vty_out(vty, "%% No BGP process is configured\n");
7510 return CMD_WARNING;
7511 }
7512 bgp_show_martian_nexthops(vty, bgp);
7513
7514 return CMD_SUCCESS;
7515}
7516
f412b39a 7517DEFUN (show_bgp_memory,
4bf6a362 7518 show_bgp_memory_cmd,
7fa12b13 7519 "show [ip] bgp memory",
4bf6a362 7520 SHOW_STR
3a2d747c 7521 IP_STR
4bf6a362
PJ
7522 BGP_STR
7523 "Global BGP memory statistics\n")
7524{
d62a17ae 7525 char memstrbuf[MTYPE_MEMSTR_LEN];
7526 unsigned long count;
7527
7528 /* RIB related usage stats */
7529 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7530 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7531 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7532 count * sizeof(struct bgp_node)));
7533
7534 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7535 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7536 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7537 count * sizeof(struct bgp_info)));
7538 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7539 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7540 count,
7541 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7542 count * sizeof(struct bgp_info_extra)));
7543
7544 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7545 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7546 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7547 count * sizeof(struct bgp_static)));
7548
7549 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7550 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7551 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7552 count * sizeof(struct bpacket)));
7553
7554 /* Adj-In/Out */
7555 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7556 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7557 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7558 count * sizeof(struct bgp_adj_in)));
7559 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7560 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7561 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7562 count * sizeof(struct bgp_adj_out)));
7563
7564 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7565 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7566 count,
7567 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7568 count * sizeof(struct bgp_nexthop_cache)));
7569
7570 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7571 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7572 count,
7573 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7574 count * sizeof(struct bgp_damp_info)));
7575
7576 /* Attributes */
7577 count = attr_count();
7578 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7579 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7580 count * sizeof(struct attr)));
7581
7582 if ((count = attr_unknown_count()))
7583 vty_out(vty, "%ld unknown attributes\n", count);
7584
7585 /* AS_PATH attributes */
7586 count = aspath_count();
7587 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7588 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7589 count * sizeof(struct aspath)));
7590
7591 count = mtype_stats_alloc(MTYPE_AS_SEG);
7592 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7593 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7594 count * sizeof(struct assegment)));
7595
7596 /* Other attributes */
7597 if ((count = community_count()))
7598 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7599 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7600 count * sizeof(struct community)));
d62a17ae 7601 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7602 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7603 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7604 count * sizeof(struct ecommunity)));
d62a17ae 7605 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7606 vty_out(vty,
7607 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7608 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7609 count * sizeof(struct lcommunity)));
d62a17ae 7610
7611 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7612 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7613 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7614 count * sizeof(struct cluster_list)));
7615
7616 /* Peer related usage */
7617 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7618 vty_out(vty, "%ld peers, using %s of memory\n", count,
7619 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7620 count * sizeof(struct peer)));
7621
7622 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7623 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7624 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7625 count * sizeof(struct peer_group)));
7626
7627 /* Other */
7628 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7629 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7630 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7631 count * sizeof(struct hash)));
7632 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7633 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7634 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7635 count * sizeof(struct hash_backet)));
7636 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7637 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7638 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7639 count * sizeof(regex_t)));
d62a17ae 7640 return CMD_SUCCESS;
4bf6a362 7641}
fee0f4c6 7642
57a9c8a8
DS
7643static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7644{
7645 json_object *bestpath = json_object_new_object();
7646
7647 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7648 json_object_string_add(bestpath, "asPath", "ignore");
7649
7650 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7651 json_object_string_add(bestpath, "asPath", "confed");
7652
7653 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7654 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7655 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7656 "as-set");
7657 else
a4d82a8a 7658 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7659 "true");
7660 } else
a4d82a8a 7661 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7662
7663 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7664 json_object_string_add(bestpath, "compareRouterId", "true");
7665 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7666 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7667 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7668 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7669 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7670 json_object_string_add(bestpath, "med",
7671 "missing-as-worst");
7672 else
7673 json_object_string_add(bestpath, "med", "true");
7674 }
7675
7676 json_object_object_add(json, "bestPath", bestpath);
7677}
7678
718e3744 7679/* Show BGP peer's summary information. */
d62a17ae 7680static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9f049418 7681 bool use_json, json_object *json)
d62a17ae 7682{
7683 struct peer *peer;
7684 struct listnode *node, *nnode;
7685 unsigned int count = 0, dn_count = 0;
7686 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7687 char neighbor_buf[VTY_BUFSIZ];
7688 int neighbor_col_default_width = 16;
7689 int len;
7690 int max_neighbor_width = 0;
7691 int pfx_rcd_safi;
7692 json_object *json_peer = NULL;
7693 json_object *json_peers = NULL;
7694
7695 /* labeled-unicast routes are installed in the unicast table so in order
7696 * to
7697 * display the correct PfxRcd value we must look at SAFI_UNICAST
7698 */
7699 if (safi == SAFI_LABELED_UNICAST)
7700 pfx_rcd_safi = SAFI_UNICAST;
7701 else
7702 pfx_rcd_safi = safi;
7703
7704 if (use_json) {
7705 if (json == NULL)
7706 json = json_object_new_object();
7707
7708 json_peers = json_object_new_object();
7709 } else {
7710 /* Loop over all neighbors that will be displayed to determine
7711 * how many
7712 * characters are needed for the Neighbor column
7713 */
7714 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7715 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7716 continue;
7717
7718 if (peer->afc[afi][safi]) {
7719 memset(dn_flag, '\0', sizeof(dn_flag));
7720 if (peer_dynamic_neighbor(peer))
7721 dn_flag[0] = '*';
7722
7723 if (peer->hostname
7724 && bgp_flag_check(bgp,
7725 BGP_FLAG_SHOW_HOSTNAME))
7726 sprintf(neighbor_buf, "%s%s(%s) ",
7727 dn_flag, peer->hostname,
7728 peer->host);
7729 else
7730 sprintf(neighbor_buf, "%s%s ", dn_flag,
7731 peer->host);
7732
7733 len = strlen(neighbor_buf);
7734
7735 if (len > max_neighbor_width)
7736 max_neighbor_width = len;
7737 }
7738 }
f933309e 7739
d62a17ae 7740 /* Originally we displayed the Neighbor column as 16
7741 * characters wide so make that the default
7742 */
7743 if (max_neighbor_width < neighbor_col_default_width)
7744 max_neighbor_width = neighbor_col_default_width;
7745 }
f933309e 7746
d62a17ae 7747 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7748 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7749 continue;
7750
ea47320b
DL
7751 if (!peer->afc[afi][safi])
7752 continue;
d62a17ae 7753
ea47320b
DL
7754 if (!count) {
7755 unsigned long ents;
7756 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7757 int64_t vrf_id_ui;
d62a17ae 7758
a4d82a8a
PZ
7759 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7760 ? -1
7761 : (int64_t)bgp->vrf_id;
ea47320b
DL
7762
7763 /* Usage summary and header */
7764 if (use_json) {
7765 json_object_string_add(
7766 json, "routerId",
7767 inet_ntoa(bgp->router_id));
60466a63
QY
7768 json_object_int_add(json, "as", bgp->as);
7769 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7770 json_object_string_add(
7771 json, "vrfName",
7772 (bgp->inst_type
7773 == BGP_INSTANCE_TYPE_DEFAULT)
7774 ? "Default"
7775 : bgp->name);
7776 } else {
7777 vty_out(vty,
7778 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7779 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7780 bgp->vrf_id == VRF_UNKNOWN
7781 ? -1
7782 : (int)bgp->vrf_id);
ea47320b
DL
7783 vty_out(vty, "\n");
7784 }
d62a17ae 7785
ea47320b 7786 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7787 if (use_json) {
ea47320b 7788 json_object_int_add(
60466a63 7789 json, "updateDelayLimit",
ea47320b 7790 bgp->v_update_delay);
d62a17ae 7791
ea47320b
DL
7792 if (bgp->v_update_delay
7793 != bgp->v_establish_wait)
d62a17ae 7794 json_object_int_add(
7795 json,
ea47320b
DL
7796 "updateDelayEstablishWait",
7797 bgp->v_establish_wait);
d62a17ae 7798
60466a63 7799 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7800 json_object_string_add(
7801 json,
7802 "updateDelayFirstNeighbor",
7803 bgp->update_delay_begin_time);
7804 json_object_boolean_true_add(
7805 json,
7806 "updateDelayInProgress");
7807 } else {
7808 if (bgp->update_delay_over) {
d62a17ae 7809 json_object_string_add(
7810 json,
7811 "updateDelayFirstNeighbor",
7812 bgp->update_delay_begin_time);
ea47320b 7813 json_object_string_add(
d62a17ae 7814 json,
ea47320b
DL
7815 "updateDelayBestpathResumed",
7816 bgp->update_delay_end_time);
7817 json_object_string_add(
d62a17ae 7818 json,
ea47320b
DL
7819 "updateDelayZebraUpdateResume",
7820 bgp->update_delay_zebra_resume_time);
7821 json_object_string_add(
7822 json,
7823 "updateDelayPeerUpdateResume",
7824 bgp->update_delay_peers_resume_time);
d62a17ae 7825 }
ea47320b
DL
7826 }
7827 } else {
7828 vty_out(vty,
7829 "Read-only mode update-delay limit: %d seconds\n",
7830 bgp->v_update_delay);
7831 if (bgp->v_update_delay
7832 != bgp->v_establish_wait)
d62a17ae 7833 vty_out(vty,
ea47320b
DL
7834 " Establish wait: %d seconds\n",
7835 bgp->v_establish_wait);
d62a17ae 7836
60466a63 7837 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7838 vty_out(vty,
7839 " First neighbor established: %s\n",
7840 bgp->update_delay_begin_time);
7841 vty_out(vty,
7842 " Delay in progress\n");
7843 } else {
7844 if (bgp->update_delay_over) {
d62a17ae 7845 vty_out(vty,
7846 " First neighbor established: %s\n",
7847 bgp->update_delay_begin_time);
7848 vty_out(vty,
ea47320b
DL
7849 " Best-paths resumed: %s\n",
7850 bgp->update_delay_end_time);
7851 vty_out(vty,
7852 " zebra update resumed: %s\n",
7853 bgp->update_delay_zebra_resume_time);
7854 vty_out(vty,
7855 " peers update resumed: %s\n",
7856 bgp->update_delay_peers_resume_time);
d62a17ae 7857 }
7858 }
7859 }
ea47320b 7860 }
d62a17ae 7861
ea47320b
DL
7862 if (use_json) {
7863 if (bgp_maxmed_onstartup_configured(bgp)
7864 && bgp->maxmed_active)
7865 json_object_boolean_true_add(
60466a63 7866 json, "maxMedOnStartup");
ea47320b
DL
7867 if (bgp->v_maxmed_admin)
7868 json_object_boolean_true_add(
60466a63 7869 json, "maxMedAdministrative");
d62a17ae 7870
ea47320b
DL
7871 json_object_int_add(
7872 json, "tableVersion",
60466a63 7873 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7874
60466a63
QY
7875 ents = bgp_table_count(bgp->rib[afi][safi]);
7876 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7877 json_object_int_add(
7878 json, "ribMemory",
7879 ents * sizeof(struct bgp_node));
d62a17ae 7880
ea47320b 7881 ents = listcount(bgp->peer);
60466a63
QY
7882 json_object_int_add(json, "peerCount", ents);
7883 json_object_int_add(json, "peerMemory",
7884 ents * sizeof(struct peer));
d62a17ae 7885
ea47320b
DL
7886 if ((ents = listcount(bgp->group))) {
7887 json_object_int_add(
60466a63 7888 json, "peerGroupCount", ents);
ea47320b
DL
7889 json_object_int_add(
7890 json, "peerGroupMemory",
996c9314
LB
7891 ents * sizeof(struct
7892 peer_group));
ea47320b 7893 }
d62a17ae 7894
ea47320b
DL
7895 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7896 BGP_CONFIG_DAMPENING))
7897 json_object_boolean_true_add(
60466a63 7898 json, "dampeningEnabled");
ea47320b
DL
7899 } else {
7900 if (bgp_maxmed_onstartup_configured(bgp)
7901 && bgp->maxmed_active)
d62a17ae 7902 vty_out(vty,
ea47320b
DL
7903 "Max-med on-startup active\n");
7904 if (bgp->v_maxmed_admin)
d62a17ae 7905 vty_out(vty,
ea47320b 7906 "Max-med administrative active\n");
d62a17ae 7907
60466a63
QY
7908 vty_out(vty, "BGP table version %" PRIu64 "\n",
7909 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7910
60466a63 7911 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7912 vty_out(vty,
7913 "RIB entries %ld, using %s of memory\n",
7914 ents,
996c9314
LB
7915 mtype_memstr(memstrbuf,
7916 sizeof(memstrbuf),
7917 ents * sizeof(struct
7918 bgp_node)));
ea47320b
DL
7919
7920 /* Peer related usage */
7921 ents = listcount(bgp->peer);
60466a63 7922 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7923 ents,
7924 mtype_memstr(
60466a63
QY
7925 memstrbuf, sizeof(memstrbuf),
7926 ents * sizeof(struct peer)));
ea47320b
DL
7927
7928 if ((ents = listcount(bgp->group)))
d62a17ae 7929 vty_out(vty,
ea47320b 7930 "Peer groups %ld, using %s of memory\n",
d62a17ae 7931 ents,
7932 mtype_memstr(
7933 memstrbuf,
7934 sizeof(memstrbuf),
996c9314
LB
7935 ents * sizeof(struct
7936 peer_group)));
d62a17ae 7937
ea47320b
DL
7938 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7939 BGP_CONFIG_DAMPENING))
60466a63 7940 vty_out(vty, "Dampening enabled.\n");
ea47320b 7941 vty_out(vty, "\n");
d62a17ae 7942
ea47320b
DL
7943 /* Subtract 8 here because 'Neighbor' is
7944 * 8 characters */
7945 vty_out(vty, "Neighbor");
60466a63
QY
7946 vty_out(vty, "%*s", max_neighbor_width - 8,
7947 " ");
ea47320b
DL
7948 vty_out(vty,
7949 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7950 }
ea47320b 7951 }
d62a17ae 7952
ea47320b 7953 count++;
d62a17ae 7954
ea47320b
DL
7955 if (use_json) {
7956 json_peer = json_object_new_object();
d62a17ae 7957
b4e9dcba
DD
7958 if (peer_dynamic_neighbor(peer)) {
7959 dn_count++;
60466a63
QY
7960 json_object_boolean_true_add(json_peer,
7961 "dynamicPeer");
b4e9dcba 7962 }
d62a17ae 7963
ea47320b 7964 if (peer->hostname)
60466a63 7965 json_object_string_add(json_peer, "hostname",
ea47320b 7966 peer->hostname);
d62a17ae 7967
ea47320b 7968 if (peer->domainname)
60466a63
QY
7969 json_object_string_add(json_peer, "domainname",
7970 peer->domainname);
d62a17ae 7971
60466a63 7972 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7973 json_object_int_add(json_peer, "version", 4);
60466a63 7974 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7975 PEER_TOTAL_RX(peer));
60466a63 7976 json_object_int_add(json_peer, "msgSent",
0112e9e0 7977 PEER_TOTAL_TX(peer));
ea47320b
DL
7978
7979 json_object_int_add(json_peer, "tableVersion",
7980 peer->version[afi][safi]);
7981 json_object_int_add(json_peer, "outq",
7982 peer->obuf->count);
7983 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7984 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7985 use_json, json_peer);
7986 json_object_int_add(json_peer, "prefixReceivedCount",
7987 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7988
ea47320b 7989 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7990 json_object_string_add(json_peer, "state",
ea47320b 7991 "Idle (Admin)");
9199a725
TM
7992 else if (peer->afc_recv[afi][safi])
7993 json_object_string_add(
7994 json_peer, "state",
7995 lookup_msg(bgp_status_msg, peer->status,
7996 NULL));
60466a63
QY
7997 else if (CHECK_FLAG(peer->sflags,
7998 PEER_STATUS_PREFIX_OVERFLOW))
7999 json_object_string_add(json_peer, "state",
ea47320b
DL
8000 "Idle (PfxCt)");
8001 else
8002 json_object_string_add(
8003 json_peer, "state",
60466a63
QY
8004 lookup_msg(bgp_status_msg, peer->status,
8005 NULL));
ea47320b
DL
8006
8007 if (peer->conf_if)
60466a63 8008 json_object_string_add(json_peer, "idType",
ea47320b
DL
8009 "interface");
8010 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8011 json_object_string_add(json_peer, "idType",
8012 "ipv4");
ea47320b 8013 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8014 json_object_string_add(json_peer, "idType",
8015 "ipv6");
d62a17ae 8016
ea47320b
DL
8017 json_object_object_add(json_peers, peer->host,
8018 json_peer);
8019 } else {
8020 memset(dn_flag, '\0', sizeof(dn_flag));
8021 if (peer_dynamic_neighbor(peer)) {
8022 dn_count++;
8023 dn_flag[0] = '*';
8024 }
d62a17ae 8025
ea47320b 8026 if (peer->hostname
60466a63 8027 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 8028 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 8029 peer->hostname, peer->host);
ea47320b 8030 else
60466a63 8031 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
8032
8033 /* pad the neighbor column with spaces */
8034 if (len < max_neighbor_width)
60466a63
QY
8035 vty_out(vty, "%*s", max_neighbor_width - len,
8036 " ");
ea47320b 8037
86a55b99 8038 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
8039 peer->as, PEER_TOTAL_RX(peer),
8040 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8041 0, peer->obuf->count,
d62a17ae 8042 peer_uptime(peer->uptime, timebuf,
ea47320b 8043 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8044
ea47320b 8045 if (peer->status == Established)
2f8f4f10 8046 if (peer->afc_recv[afi][safi])
95077abf 8047 vty_out(vty, " %12ld",
a4d82a8a
PZ
8048 peer->pcount[afi]
8049 [pfx_rcd_safi]);
95077abf
DW
8050 else
8051 vty_out(vty, " NoNeg");
ea47320b 8052 else {
60466a63 8053 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8054 vty_out(vty, " Idle (Admin)");
60466a63
QY
8055 else if (CHECK_FLAG(
8056 peer->sflags,
8057 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8058 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8059 else
ea47320b 8060 vty_out(vty, " %12s",
60466a63
QY
8061 lookup_msg(bgp_status_msg,
8062 peer->status, NULL));
d62a17ae 8063 }
ea47320b 8064 vty_out(vty, "\n");
d62a17ae 8065 }
8066 }
f933309e 8067
d62a17ae 8068 if (use_json) {
8069 json_object_object_add(json, "peers", json_peers);
8070
8071 json_object_int_add(json, "totalPeers", count);
8072 json_object_int_add(json, "dynamicPeers", dn_count);
8073
57a9c8a8
DS
8074 bgp_show_bestpath_json(bgp, json);
8075
996c9314
LB
8076 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8077 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8078 json_object_free(json);
8079 } else {
8080 if (count)
8081 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8082 else {
d6ceaca3 8083 vty_out(vty, "No %s neighbor is configured\n",
8084 afi_safi_print(afi, safi));
d62a17ae 8085 }
b05a1c8b 8086
d6ceaca3 8087 if (dn_count) {
d62a17ae 8088 vty_out(vty, "* - dynamic neighbor\n");
8089 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8090 dn_count, bgp->dynamic_neighbors_limit);
8091 }
8092 }
1ff9a340 8093
d62a17ae 8094 return CMD_SUCCESS;
718e3744 8095}
8096
d62a17ae 8097static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9f049418 8098 int safi, bool use_json,
d62a17ae 8099 json_object *json)
8100{
8101 int is_first = 1;
8102 int afi_wildcard = (afi == AFI_MAX);
8103 int safi_wildcard = (safi == SAFI_MAX);
8104 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8105 bool nbr_output = false;
d62a17ae 8106
8107 if (use_json && is_wildcard)
8108 vty_out(vty, "{\n");
8109 if (afi_wildcard)
8110 afi = 1; /* AFI_IP */
8111 while (afi < AFI_MAX) {
8112 if (safi_wildcard)
8113 safi = 1; /* SAFI_UNICAST */
8114 while (safi < SAFI_MAX) {
318cac96 8115 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8116 nbr_output = true;
d62a17ae 8117 if (is_wildcard) {
8118 /*
8119 * So limit output to those afi/safi
8120 * pairs that
8121 * actualy have something interesting in
8122 * them
8123 */
8124 if (use_json) {
8125 json = json_object_new_object();
8126
8127 if (!is_first)
8128 vty_out(vty, ",\n");
8129 else
8130 is_first = 0;
8131
8132 vty_out(vty, "\"%s\":",
8133 afi_safi_json(afi,
8134 safi));
8135 } else {
8136 vty_out(vty, "\n%s Summary:\n",
8137 afi_safi_print(afi,
8138 safi));
8139 }
8140 }
8141 bgp_show_summary(vty, bgp, afi, safi, use_json,
8142 json);
8143 }
8144 safi++;
d62a17ae 8145 if (!safi_wildcard)
8146 safi = SAFI_MAX;
8147 }
8148 afi++;
ee851c8c 8149 if (!afi_wildcard)
d62a17ae 8150 afi = AFI_MAX;
8151 }
8152
8153 if (use_json && is_wildcard)
8154 vty_out(vty, "}\n");
ca61fd25
DS
8155 else if (!nbr_output) {
8156 if (use_json)
8157 vty_out(vty, "{}\n");
8158 else
8159 vty_out(vty, "%% No BGP neighbors found\n");
8160 }
d62a17ae 8161}
8162
8163static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9f049418 8164 safi_t safi, bool use_json)
d62a17ae 8165{
8166 struct listnode *node, *nnode;
8167 struct bgp *bgp;
8168 json_object *json = NULL;
8169 int is_first = 1;
9f049418 8170 bool nbr_output = false;
d62a17ae 8171
8172 if (use_json)
8173 vty_out(vty, "{\n");
8174
8175 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8176 nbr_output = true;
d62a17ae 8177 if (use_json) {
8178 json = json_object_new_object();
8179
8180 if (!is_first)
8181 vty_out(vty, ",\n");
8182 else
8183 is_first = 0;
8184
8185 vty_out(vty, "\"%s\":",
8186 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8187 ? "Default"
8188 : bgp->name);
8189 } else {
8190 vty_out(vty, "\nInstance %s:\n",
8191 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8192 ? "Default"
8193 : bgp->name);
8194 }
8195 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8196 }
8197
8198 if (use_json)
8199 vty_out(vty, "}\n");
9f049418
DS
8200 else if (!nbr_output)
8201 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8202}
8203
8204int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9f049418 8205 safi_t safi, bool use_json)
d62a17ae 8206{
8207 struct bgp *bgp;
8208
8209 if (name) {
8210 if (strmatch(name, "all")) {
8211 bgp_show_all_instances_summary_vty(vty, afi, safi,
8212 use_json);
8213 return CMD_SUCCESS;
8214 } else {
8215 bgp = bgp_lookup_by_name(name);
8216
8217 if (!bgp) {
8218 if (use_json)
8219 vty_out(vty, "{}\n");
8220 else
8221 vty_out(vty,
ca61fd25 8222 "%% BGP instance not found\n");
d62a17ae 8223 return CMD_WARNING;
8224 }
8225
8226 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8227 NULL);
8228 return CMD_SUCCESS;
8229 }
8230 }
8231
8232 bgp = bgp_get_default();
8233
8234 if (bgp)
8235 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
9f049418 8236 else {
ca61fd25
DS
8237 if (use_json)
8238 vty_out(vty, "{}\n");
8239 else
8240 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8241 return CMD_WARNING;
8242 }
d62a17ae 8243
8244 return CMD_SUCCESS;
4fb25c53
DW
8245}
8246
716b2d8a 8247/* `show [ip] bgp summary' commands. */
47fc97cc 8248DEFUN (show_ip_bgp_summary,
718e3744 8249 show_ip_bgp_summary_cmd,
dd6bd0f1 8250 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8251 SHOW_STR
8252 IP_STR
8253 BGP_STR
8386ac43 8254 BGP_INSTANCE_HELP_STR
46f296b4 8255 BGP_AFI_HELP_STR
dd6bd0f1 8256 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8257 "Summary of BGP neighbor status\n"
9973d184 8258 JSON_STR)
718e3744 8259{
d62a17ae 8260 char *vrf = NULL;
8261 afi_t afi = AFI_MAX;
8262 safi_t safi = SAFI_MAX;
8263
8264 int idx = 0;
8265
8266 /* show [ip] bgp */
8267 if (argv_find(argv, argc, "ip", &idx))
8268 afi = AFI_IP;
9a8bdf1c
PG
8269 /* [<vrf> VIEWVRFNAME] */
8270 if (argv_find(argv, argc, "vrf", &idx)) {
8271 vrf = argv[idx + 1]->arg;
8272 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8273 vrf = NULL;
8274 } else if (argv_find(argv, argc, "view", &idx))
8275 /* [<view> VIEWVRFNAME] */
8276 vrf = argv[idx + 1]->arg;
d62a17ae 8277 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8278 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8279 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8280 }
8281
9f049418 8282 bool uj = use_json(argc, argv);
d62a17ae 8283
8284 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8285}
8286
8287const char *afi_safi_print(afi_t afi, safi_t safi)
8288{
8289 if (afi == AFI_IP && safi == SAFI_UNICAST)
8290 return "IPv4 Unicast";
8291 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8292 return "IPv4 Multicast";
8293 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8294 return "IPv4 Labeled Unicast";
8295 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8296 return "IPv4 VPN";
8297 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8298 return "IPv4 Encap";
7c40bf39 8299 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8300 return "IPv4 Flowspec";
d62a17ae 8301 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8302 return "IPv6 Unicast";
8303 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8304 return "IPv6 Multicast";
8305 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8306 return "IPv6 Labeled Unicast";
8307 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8308 return "IPv6 VPN";
8309 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8310 return "IPv6 Encap";
7c40bf39 8311 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8312 return "IPv6 Flowspec";
d62a17ae 8313 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8314 return "L2VPN EVPN";
8315 else
8316 return "Unknown";
538621f2 8317}
8318
b9f77ec8
DS
8319/*
8320 * Please note that we have intentionally camelCased
8321 * the return strings here. So if you want
8322 * to use this function, please ensure you
8323 * are doing this within json output
8324 */
d62a17ae 8325const char *afi_safi_json(afi_t afi, safi_t safi)
8326{
8327 if (afi == AFI_IP && safi == SAFI_UNICAST)
8328 return "ipv4Unicast";
8329 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8330 return "ipv4Multicast";
8331 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8332 return "ipv4LabeledUnicast";
8333 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8334 return "ipv4Vpn";
8335 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8336 return "ipv4Encap";
7c40bf39 8337 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8338 return "ipv4Flowspec";
d62a17ae 8339 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8340 return "ipv6Unicast";
8341 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8342 return "ipv6Multicast";
8343 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8344 return "ipv6LabeledUnicast";
8345 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8346 return "ipv6Vpn";
8347 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8348 return "ipv6Encap";
7c40bf39 8349 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8350 return "ipv6Flowspec";
d62a17ae 8351 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8352 return "l2VpnEvpn";
8353 else
8354 return "Unknown";
27162734
LB
8355}
8356
718e3744 8357/* Show BGP peer's information. */
d62a17ae 8358enum show_type { show_all, show_peer };
8359
8360static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8361 afi_t afi, safi_t safi,
d7c0a89a
QY
8362 uint16_t adv_smcap, uint16_t adv_rmcap,
8363 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8364 bool use_json, json_object *json_pref)
d62a17ae 8365{
8366 /* Send-Mode */
8367 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8368 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8369 if (use_json) {
8370 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8371 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8372 json_object_string_add(json_pref, "sendMode",
8373 "advertisedAndReceived");
8374 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8375 json_object_string_add(json_pref, "sendMode",
8376 "advertised");
8377 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8378 json_object_string_add(json_pref, "sendMode",
8379 "received");
8380 } else {
8381 vty_out(vty, " Send-mode: ");
8382 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8383 vty_out(vty, "advertised");
8384 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8385 vty_out(vty, "%sreceived",
8386 CHECK_FLAG(p->af_cap[afi][safi],
8387 adv_smcap)
8388 ? ", "
8389 : "");
8390 vty_out(vty, "\n");
8391 }
8392 }
8393
8394 /* Receive-Mode */
8395 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8396 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8397 if (use_json) {
8398 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8399 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8400 json_object_string_add(json_pref, "recvMode",
8401 "advertisedAndReceived");
8402 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8403 json_object_string_add(json_pref, "recvMode",
8404 "advertised");
8405 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8406 json_object_string_add(json_pref, "recvMode",
8407 "received");
8408 } else {
8409 vty_out(vty, " Receive-mode: ");
8410 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8411 vty_out(vty, "advertised");
8412 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8413 vty_out(vty, "%sreceived",
8414 CHECK_FLAG(p->af_cap[afi][safi],
8415 adv_rmcap)
8416 ? ", "
8417 : "");
8418 vty_out(vty, "\n");
8419 }
8420 }
8421}
8422
8423static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8424 safi_t safi, bool use_json,
d62a17ae 8425 json_object *json_neigh)
8426{
0291c246
MK
8427 struct bgp_filter *filter;
8428 struct peer_af *paf;
8429 char orf_pfx_name[BUFSIZ];
8430 int orf_pfx_count;
8431 json_object *json_af = NULL;
8432 json_object *json_prefA = NULL;
8433 json_object *json_prefB = NULL;
8434 json_object *json_addr = NULL;
d62a17ae 8435
8436 if (use_json) {
8437 json_addr = json_object_new_object();
8438 json_af = json_object_new_object();
8439 filter = &p->filter[afi][safi];
8440
8441 if (peer_group_active(p))
8442 json_object_string_add(json_addr, "peerGroupMember",
8443 p->group->name);
8444
8445 paf = peer_af_find(p, afi, safi);
8446 if (paf && PAF_SUBGRP(paf)) {
8447 json_object_int_add(json_addr, "updateGroupId",
8448 PAF_UPDGRP(paf)->id);
8449 json_object_int_add(json_addr, "subGroupId",
8450 PAF_SUBGRP(paf)->id);
8451 json_object_int_add(json_addr, "packetQueueLength",
8452 bpacket_queue_virtual_length(paf));
8453 }
8454
8455 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8456 || CHECK_FLAG(p->af_cap[afi][safi],
8457 PEER_CAP_ORF_PREFIX_SM_RCV)
8458 || CHECK_FLAG(p->af_cap[afi][safi],
8459 PEER_CAP_ORF_PREFIX_RM_ADV)
8460 || CHECK_FLAG(p->af_cap[afi][safi],
8461 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8462 json_object_int_add(json_af, "orfType",
8463 ORF_TYPE_PREFIX);
8464 json_prefA = json_object_new_object();
8465 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8466 PEER_CAP_ORF_PREFIX_SM_ADV,
8467 PEER_CAP_ORF_PREFIX_RM_ADV,
8468 PEER_CAP_ORF_PREFIX_SM_RCV,
8469 PEER_CAP_ORF_PREFIX_RM_RCV,
8470 use_json, json_prefA);
8471 json_object_object_add(json_af, "orfPrefixList",
8472 json_prefA);
8473 }
8474
8475 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8476 || CHECK_FLAG(p->af_cap[afi][safi],
8477 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8478 || CHECK_FLAG(p->af_cap[afi][safi],
8479 PEER_CAP_ORF_PREFIX_RM_ADV)
8480 || CHECK_FLAG(p->af_cap[afi][safi],
8481 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8482 json_object_int_add(json_af, "orfOldType",
8483 ORF_TYPE_PREFIX_OLD);
8484 json_prefB = json_object_new_object();
8485 bgp_show_peer_afi_orf_cap(
8486 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8487 PEER_CAP_ORF_PREFIX_RM_ADV,
8488 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8489 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8490 json_prefB);
8491 json_object_object_add(json_af, "orfOldPrefixList",
8492 json_prefB);
8493 }
8494
8495 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8496 || CHECK_FLAG(p->af_cap[afi][safi],
8497 PEER_CAP_ORF_PREFIX_SM_RCV)
8498 || CHECK_FLAG(p->af_cap[afi][safi],
8499 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8500 || CHECK_FLAG(p->af_cap[afi][safi],
8501 PEER_CAP_ORF_PREFIX_RM_ADV)
8502 || CHECK_FLAG(p->af_cap[afi][safi],
8503 PEER_CAP_ORF_PREFIX_RM_RCV)
8504 || CHECK_FLAG(p->af_cap[afi][safi],
8505 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8506 json_object_object_add(json_addr, "afDependentCap",
8507 json_af);
8508 else
8509 json_object_free(json_af);
8510
8511 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8512 orf_pfx_count = prefix_bgp_show_prefix_list(
8513 NULL, afi, orf_pfx_name, use_json);
8514
8515 if (CHECK_FLAG(p->af_sflags[afi][safi],
8516 PEER_STATUS_ORF_PREFIX_SEND)
8517 || orf_pfx_count) {
8518 if (CHECK_FLAG(p->af_sflags[afi][safi],
8519 PEER_STATUS_ORF_PREFIX_SEND))
8520 json_object_boolean_true_add(json_neigh,
8521 "orfSent");
8522 if (orf_pfx_count)
8523 json_object_int_add(json_addr, "orfRecvCounter",
8524 orf_pfx_count);
8525 }
8526 if (CHECK_FLAG(p->af_sflags[afi][safi],
8527 PEER_STATUS_ORF_WAIT_REFRESH))
8528 json_object_string_add(
8529 json_addr, "orfFirstUpdate",
8530 "deferredUntilORFOrRouteRefreshRecvd");
8531
8532 if (CHECK_FLAG(p->af_flags[afi][safi],
8533 PEER_FLAG_REFLECTOR_CLIENT))
8534 json_object_boolean_true_add(json_addr,
8535 "routeReflectorClient");
8536 if (CHECK_FLAG(p->af_flags[afi][safi],
8537 PEER_FLAG_RSERVER_CLIENT))
8538 json_object_boolean_true_add(json_addr,
8539 "routeServerClient");
8540 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8541 json_object_boolean_true_add(json_addr,
8542 "inboundSoftConfigPermit");
8543
8544 if (CHECK_FLAG(p->af_flags[afi][safi],
8545 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8546 json_object_boolean_true_add(
8547 json_addr,
8548 "privateAsNumsAllReplacedInUpdatesToNbr");
8549 else if (CHECK_FLAG(p->af_flags[afi][safi],
8550 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8551 json_object_boolean_true_add(
8552 json_addr,
8553 "privateAsNumsReplacedInUpdatesToNbr");
8554 else if (CHECK_FLAG(p->af_flags[afi][safi],
8555 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8556 json_object_boolean_true_add(
8557 json_addr,
8558 "privateAsNumsAllRemovedInUpdatesToNbr");
8559 else if (CHECK_FLAG(p->af_flags[afi][safi],
8560 PEER_FLAG_REMOVE_PRIVATE_AS))
8561 json_object_boolean_true_add(
8562 json_addr,
8563 "privateAsNumsRemovedInUpdatesToNbr");
8564
8565 if (CHECK_FLAG(p->af_flags[afi][safi],
8566 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8567 json_object_boolean_true_add(json_addr,
8568 "addpathTxAllPaths");
8569
8570 if (CHECK_FLAG(p->af_flags[afi][safi],
8571 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8572 json_object_boolean_true_add(json_addr,
8573 "addpathTxBestpathPerAS");
8574
8575 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8576 json_object_string_add(json_addr,
8577 "overrideASNsInOutboundUpdates",
8578 "ifAspathEqualRemoteAs");
8579
8580 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8581 || CHECK_FLAG(p->af_flags[afi][safi],
8582 PEER_FLAG_FORCE_NEXTHOP_SELF))
8583 json_object_boolean_true_add(json_addr,
8584 "routerAlwaysNextHop");
8585 if (CHECK_FLAG(p->af_flags[afi][safi],
8586 PEER_FLAG_AS_PATH_UNCHANGED))
8587 json_object_boolean_true_add(
8588 json_addr, "unchangedAsPathPropogatedToNbr");
8589 if (CHECK_FLAG(p->af_flags[afi][safi],
8590 PEER_FLAG_NEXTHOP_UNCHANGED))
8591 json_object_boolean_true_add(
8592 json_addr, "unchangedNextHopPropogatedToNbr");
8593 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8594 json_object_boolean_true_add(
8595 json_addr, "unchangedMedPropogatedToNbr");
8596 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8597 || CHECK_FLAG(p->af_flags[afi][safi],
8598 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8599 if (CHECK_FLAG(p->af_flags[afi][safi],
8600 PEER_FLAG_SEND_COMMUNITY)
8601 && CHECK_FLAG(p->af_flags[afi][safi],
8602 PEER_FLAG_SEND_EXT_COMMUNITY))
8603 json_object_string_add(json_addr,
8604 "commAttriSentToNbr",
8605 "extendedAndStandard");
8606 else if (CHECK_FLAG(p->af_flags[afi][safi],
8607 PEER_FLAG_SEND_EXT_COMMUNITY))
8608 json_object_string_add(json_addr,
8609 "commAttriSentToNbr",
8610 "extended");
8611 else
8612 json_object_string_add(json_addr,
8613 "commAttriSentToNbr",
8614 "standard");
8615 }
8616 if (CHECK_FLAG(p->af_flags[afi][safi],
8617 PEER_FLAG_DEFAULT_ORIGINATE)) {
8618 if (p->default_rmap[afi][safi].name)
8619 json_object_string_add(
8620 json_addr, "defaultRouteMap",
8621 p->default_rmap[afi][safi].name);
8622
8623 if (paf && PAF_SUBGRP(paf)
8624 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8625 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8626 json_object_boolean_true_add(json_addr,
8627 "defaultSent");
8628 else
8629 json_object_boolean_true_add(json_addr,
8630 "defaultNotSent");
8631 }
8632
dff8f48d 8633 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8634 if (is_evpn_enabled())
60466a63
QY
8635 json_object_boolean_true_add(
8636 json_addr, "advertiseAllVnis");
dff8f48d
MK
8637 }
8638
d62a17ae 8639 if (filter->plist[FILTER_IN].name
8640 || filter->dlist[FILTER_IN].name
8641 || filter->aslist[FILTER_IN].name
8642 || filter->map[RMAP_IN].name)
8643 json_object_boolean_true_add(json_addr,
8644 "inboundPathPolicyConfig");
8645 if (filter->plist[FILTER_OUT].name
8646 || filter->dlist[FILTER_OUT].name
8647 || filter->aslist[FILTER_OUT].name
8648 || filter->map[RMAP_OUT].name || filter->usmap.name)
8649 json_object_boolean_true_add(
8650 json_addr, "outboundPathPolicyConfig");
8651
8652 /* prefix-list */
8653 if (filter->plist[FILTER_IN].name)
8654 json_object_string_add(json_addr,
8655 "incomingUpdatePrefixFilterList",
8656 filter->plist[FILTER_IN].name);
8657 if (filter->plist[FILTER_OUT].name)
8658 json_object_string_add(json_addr,
8659 "outgoingUpdatePrefixFilterList",
8660 filter->plist[FILTER_OUT].name);
8661
8662 /* distribute-list */
8663 if (filter->dlist[FILTER_IN].name)
8664 json_object_string_add(
8665 json_addr, "incomingUpdateNetworkFilterList",
8666 filter->dlist[FILTER_IN].name);
8667 if (filter->dlist[FILTER_OUT].name)
8668 json_object_string_add(
8669 json_addr, "outgoingUpdateNetworkFilterList",
8670 filter->dlist[FILTER_OUT].name);
8671
8672 /* filter-list. */
8673 if (filter->aslist[FILTER_IN].name)
8674 json_object_string_add(json_addr,
8675 "incomingUpdateAsPathFilterList",
8676 filter->aslist[FILTER_IN].name);
8677 if (filter->aslist[FILTER_OUT].name)
8678 json_object_string_add(json_addr,
8679 "outgoingUpdateAsPathFilterList",
8680 filter->aslist[FILTER_OUT].name);
8681
8682 /* route-map. */
8683 if (filter->map[RMAP_IN].name)
8684 json_object_string_add(
8685 json_addr, "routeMapForIncomingAdvertisements",
8686 filter->map[RMAP_IN].name);
8687 if (filter->map[RMAP_OUT].name)
8688 json_object_string_add(
8689 json_addr, "routeMapForOutgoingAdvertisements",
8690 filter->map[RMAP_OUT].name);
8691
8692 /* unsuppress-map */
8693 if (filter->usmap.name)
8694 json_object_string_add(json_addr,
8695 "selectiveUnsuppressRouteMap",
8696 filter->usmap.name);
8697
8698 /* Receive prefix count */
8699 json_object_int_add(json_addr, "acceptedPrefixCounter",
8700 p->pcount[afi][safi]);
8701
8702 /* Maximum prefix */
8703 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8704 json_object_int_add(json_addr, "prefixAllowedMax",
8705 p->pmax[afi][safi]);
8706 if (CHECK_FLAG(p->af_flags[afi][safi],
8707 PEER_FLAG_MAX_PREFIX_WARNING))
8708 json_object_boolean_true_add(
8709 json_addr, "prefixAllowedMaxWarning");
8710 json_object_int_add(json_addr,
8711 "prefixAllowedWarningThresh",
8712 p->pmax_threshold[afi][safi]);
8713 if (p->pmax_restart[afi][safi])
8714 json_object_int_add(
8715 json_addr,
8716 "prefixAllowedRestartIntervalMsecs",
8717 p->pmax_restart[afi][safi] * 60000);
8718 }
8719 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8720 json_addr);
8721
8722 } else {
8723 filter = &p->filter[afi][safi];
8724
8725 vty_out(vty, " For address family: %s\n",
8726 afi_safi_print(afi, safi));
8727
8728 if (peer_group_active(p))
8729 vty_out(vty, " %s peer-group member\n",
8730 p->group->name);
8731
8732 paf = peer_af_find(p, afi, safi);
8733 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8734 vty_out(vty, " Update group %" PRIu64
8735 ", subgroup %" PRIu64 "\n",
d62a17ae 8736 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8737 vty_out(vty, " Packet Queue length %d\n",
8738 bpacket_queue_virtual_length(paf));
8739 } else {
8740 vty_out(vty, " Not part of any update group\n");
8741 }
8742 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8743 || CHECK_FLAG(p->af_cap[afi][safi],
8744 PEER_CAP_ORF_PREFIX_SM_RCV)
8745 || CHECK_FLAG(p->af_cap[afi][safi],
8746 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8747 || CHECK_FLAG(p->af_cap[afi][safi],
8748 PEER_CAP_ORF_PREFIX_RM_ADV)
8749 || CHECK_FLAG(p->af_cap[afi][safi],
8750 PEER_CAP_ORF_PREFIX_RM_RCV)
8751 || CHECK_FLAG(p->af_cap[afi][safi],
8752 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8753 vty_out(vty, " AF-dependant capabilities:\n");
8754
8755 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8756 || CHECK_FLAG(p->af_cap[afi][safi],
8757 PEER_CAP_ORF_PREFIX_SM_RCV)
8758 || CHECK_FLAG(p->af_cap[afi][safi],
8759 PEER_CAP_ORF_PREFIX_RM_ADV)
8760 || CHECK_FLAG(p->af_cap[afi][safi],
8761 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8762 vty_out(vty,
8763 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8764 ORF_TYPE_PREFIX);
8765 bgp_show_peer_afi_orf_cap(
8766 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8767 PEER_CAP_ORF_PREFIX_RM_ADV,
8768 PEER_CAP_ORF_PREFIX_SM_RCV,
8769 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8770 }
8771 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8772 || CHECK_FLAG(p->af_cap[afi][safi],
8773 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8774 || CHECK_FLAG(p->af_cap[afi][safi],
8775 PEER_CAP_ORF_PREFIX_RM_ADV)
8776 || CHECK_FLAG(p->af_cap[afi][safi],
8777 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8778 vty_out(vty,
8779 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8780 ORF_TYPE_PREFIX_OLD);
8781 bgp_show_peer_afi_orf_cap(
8782 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8783 PEER_CAP_ORF_PREFIX_RM_ADV,
8784 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8785 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8786 }
8787
8788 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8789 orf_pfx_count = prefix_bgp_show_prefix_list(
8790 NULL, afi, orf_pfx_name, use_json);
8791
8792 if (CHECK_FLAG(p->af_sflags[afi][safi],
8793 PEER_STATUS_ORF_PREFIX_SEND)
8794 || orf_pfx_count) {
8795 vty_out(vty, " Outbound Route Filter (ORF):");
8796 if (CHECK_FLAG(p->af_sflags[afi][safi],
8797 PEER_STATUS_ORF_PREFIX_SEND))
8798 vty_out(vty, " sent;");
8799 if (orf_pfx_count)
8800 vty_out(vty, " received (%d entries)",
8801 orf_pfx_count);
8802 vty_out(vty, "\n");
8803 }
8804 if (CHECK_FLAG(p->af_sflags[afi][safi],
8805 PEER_STATUS_ORF_WAIT_REFRESH))
8806 vty_out(vty,
8807 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8808
8809 if (CHECK_FLAG(p->af_flags[afi][safi],
8810 PEER_FLAG_REFLECTOR_CLIENT))
8811 vty_out(vty, " Route-Reflector Client\n");
8812 if (CHECK_FLAG(p->af_flags[afi][safi],
8813 PEER_FLAG_RSERVER_CLIENT))
8814 vty_out(vty, " Route-Server Client\n");
8815 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8816 vty_out(vty,
8817 " Inbound soft reconfiguration allowed\n");
8818
8819 if (CHECK_FLAG(p->af_flags[afi][safi],
8820 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8821 vty_out(vty,
8822 " Private AS numbers (all) replaced in updates to this neighbor\n");
8823 else if (CHECK_FLAG(p->af_flags[afi][safi],
8824 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8825 vty_out(vty,
8826 " Private AS numbers replaced in updates to this neighbor\n");
8827 else if (CHECK_FLAG(p->af_flags[afi][safi],
8828 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8829 vty_out(vty,
8830 " Private AS numbers (all) removed in updates to this neighbor\n");
8831 else if (CHECK_FLAG(p->af_flags[afi][safi],
8832 PEER_FLAG_REMOVE_PRIVATE_AS))
8833 vty_out(vty,
8834 " Private AS numbers removed in updates to this neighbor\n");
8835
8836 if (CHECK_FLAG(p->af_flags[afi][safi],
8837 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8838 vty_out(vty, " Advertise all paths via addpath\n");
8839
8840 if (CHECK_FLAG(p->af_flags[afi][safi],
8841 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8842 vty_out(vty,
8843 " Advertise bestpath per AS via addpath\n");
8844
8845 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8846 vty_out(vty,
8847 " Override ASNs in outbound updates if aspath equals remote-as\n");
8848
8849 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8850 || CHECK_FLAG(p->af_flags[afi][safi],
8851 PEER_FLAG_FORCE_NEXTHOP_SELF))
8852 vty_out(vty, " NEXT_HOP is always this router\n");
8853 if (CHECK_FLAG(p->af_flags[afi][safi],
8854 PEER_FLAG_AS_PATH_UNCHANGED))
8855 vty_out(vty,
8856 " AS_PATH is propagated unchanged to this neighbor\n");
8857 if (CHECK_FLAG(p->af_flags[afi][safi],
8858 PEER_FLAG_NEXTHOP_UNCHANGED))
8859 vty_out(vty,
8860 " NEXT_HOP is propagated unchanged to this neighbor\n");
8861 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8862 vty_out(vty,
8863 " MED is propagated unchanged to this neighbor\n");
8864 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8865 || CHECK_FLAG(p->af_flags[afi][safi],
8866 PEER_FLAG_SEND_EXT_COMMUNITY)
8867 || CHECK_FLAG(p->af_flags[afi][safi],
8868 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8869 vty_out(vty,
8870 " Community attribute sent to this neighbor");
8871 if (CHECK_FLAG(p->af_flags[afi][safi],
8872 PEER_FLAG_SEND_COMMUNITY)
8873 && CHECK_FLAG(p->af_flags[afi][safi],
8874 PEER_FLAG_SEND_EXT_COMMUNITY)
8875 && CHECK_FLAG(p->af_flags[afi][safi],
8876 PEER_FLAG_SEND_LARGE_COMMUNITY))
8877 vty_out(vty, "(all)\n");
8878 else if (CHECK_FLAG(p->af_flags[afi][safi],
8879 PEER_FLAG_SEND_LARGE_COMMUNITY))
8880 vty_out(vty, "(large)\n");
8881 else if (CHECK_FLAG(p->af_flags[afi][safi],
8882 PEER_FLAG_SEND_EXT_COMMUNITY))
8883 vty_out(vty, "(extended)\n");
8884 else
8885 vty_out(vty, "(standard)\n");
8886 }
8887 if (CHECK_FLAG(p->af_flags[afi][safi],
8888 PEER_FLAG_DEFAULT_ORIGINATE)) {
8889 vty_out(vty, " Default information originate,");
8890
8891 if (p->default_rmap[afi][safi].name)
8892 vty_out(vty, " default route-map %s%s,",
8893 p->default_rmap[afi][safi].map ? "*"
8894 : "",
8895 p->default_rmap[afi][safi].name);
8896 if (paf && PAF_SUBGRP(paf)
8897 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8898 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8899 vty_out(vty, " default sent\n");
8900 else
8901 vty_out(vty, " default not sent\n");
8902 }
8903
dff8f48d
MK
8904 /* advertise-vni-all */
8905 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8906 if (is_evpn_enabled())
dff8f48d
MK
8907 vty_out(vty, " advertise-all-vni\n");
8908 }
8909
d62a17ae 8910 if (filter->plist[FILTER_IN].name
8911 || filter->dlist[FILTER_IN].name
8912 || filter->aslist[FILTER_IN].name
8913 || filter->map[RMAP_IN].name)
8914 vty_out(vty, " Inbound path policy configured\n");
8915 if (filter->plist[FILTER_OUT].name
8916 || filter->dlist[FILTER_OUT].name
8917 || filter->aslist[FILTER_OUT].name
8918 || filter->map[RMAP_OUT].name || filter->usmap.name)
8919 vty_out(vty, " Outbound path policy configured\n");
8920
8921 /* prefix-list */
8922 if (filter->plist[FILTER_IN].name)
8923 vty_out(vty,
8924 " Incoming update prefix filter list is %s%s\n",
8925 filter->plist[FILTER_IN].plist ? "*" : "",
8926 filter->plist[FILTER_IN].name);
8927 if (filter->plist[FILTER_OUT].name)
8928 vty_out(vty,
8929 " Outgoing update prefix filter list is %s%s\n",
8930 filter->plist[FILTER_OUT].plist ? "*" : "",
8931 filter->plist[FILTER_OUT].name);
8932
8933 /* distribute-list */
8934 if (filter->dlist[FILTER_IN].name)
8935 vty_out(vty,
8936 " Incoming update network filter list is %s%s\n",
8937 filter->dlist[FILTER_IN].alist ? "*" : "",
8938 filter->dlist[FILTER_IN].name);
8939 if (filter->dlist[FILTER_OUT].name)
8940 vty_out(vty,
8941 " Outgoing update network filter list is %s%s\n",
8942 filter->dlist[FILTER_OUT].alist ? "*" : "",
8943 filter->dlist[FILTER_OUT].name);
8944
8945 /* filter-list. */
8946 if (filter->aslist[FILTER_IN].name)
8947 vty_out(vty,
8948 " Incoming update AS path filter list is %s%s\n",
8949 filter->aslist[FILTER_IN].aslist ? "*" : "",
8950 filter->aslist[FILTER_IN].name);
8951 if (filter->aslist[FILTER_OUT].name)
8952 vty_out(vty,
8953 " Outgoing update AS path filter list is %s%s\n",
8954 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8955 filter->aslist[FILTER_OUT].name);
8956
8957 /* route-map. */
8958 if (filter->map[RMAP_IN].name)
8959 vty_out(vty,
8960 " Route map for incoming advertisements is %s%s\n",
8961 filter->map[RMAP_IN].map ? "*" : "",
8962 filter->map[RMAP_IN].name);
8963 if (filter->map[RMAP_OUT].name)
8964 vty_out(vty,
8965 " Route map for outgoing advertisements is %s%s\n",
8966 filter->map[RMAP_OUT].map ? "*" : "",
8967 filter->map[RMAP_OUT].name);
8968
8969 /* unsuppress-map */
8970 if (filter->usmap.name)
8971 vty_out(vty,
8972 " Route map for selective unsuppress is %s%s\n",
8973 filter->usmap.map ? "*" : "",
8974 filter->usmap.name);
8975
8976 /* Receive prefix count */
8977 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8978
8979 /* Maximum prefix */
8980 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8981 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8982 p->pmax[afi][safi],
8983 CHECK_FLAG(p->af_flags[afi][safi],
8984 PEER_FLAG_MAX_PREFIX_WARNING)
8985 ? " (warning-only)"
8986 : "");
8987 vty_out(vty, " Threshold for warning message %d%%",
8988 p->pmax_threshold[afi][safi]);
8989 if (p->pmax_restart[afi][safi])
8990 vty_out(vty, ", restart interval %d min",
8991 p->pmax_restart[afi][safi]);
8992 vty_out(vty, "\n");
8993 }
8994
8995 vty_out(vty, "\n");
8996 }
8997}
8998
9f049418 8999static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9000 json_object *json)
718e3744 9001{
d62a17ae 9002 struct bgp *bgp;
9003 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9004 char timebuf[BGP_UPTIME_LEN];
9005 char dn_flag[2];
9006 const char *subcode_str;
9007 const char *code_str;
9008 afi_t afi;
9009 safi_t safi;
d7c0a89a
QY
9010 uint16_t i;
9011 uint8_t *msg;
d62a17ae 9012 json_object *json_neigh = NULL;
9013 time_t epoch_tbuf;
718e3744 9014
d62a17ae 9015 bgp = p->bgp;
9016
9017 if (use_json)
9018 json_neigh = json_object_new_object();
9019
9020 memset(dn_flag, '\0', sizeof(dn_flag));
9021 if (!p->conf_if && peer_dynamic_neighbor(p))
9022 dn_flag[0] = '*';
9023
9024 if (!use_json) {
9025 if (p->conf_if) /* Configured interface name. */
9026 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9027 BGP_PEER_SU_UNSPEC(p)
9028 ? "None"
9029 : sockunion2str(&p->su, buf,
9030 SU_ADDRSTRLEN));
9031 else /* Configured IP address. */
9032 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9033 p->host);
9034 }
9035
9036 if (use_json) {
9037 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9038 json_object_string_add(json_neigh, "bgpNeighborAddr",
9039 "none");
9040 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9041 json_object_string_add(
9042 json_neigh, "bgpNeighborAddr",
9043 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9044
9045 json_object_int_add(json_neigh, "remoteAs", p->as);
9046
9047 if (p->change_local_as)
9048 json_object_int_add(json_neigh, "localAs",
9049 p->change_local_as);
9050 else
9051 json_object_int_add(json_neigh, "localAs", p->local_as);
9052
9053 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9054 json_object_boolean_true_add(json_neigh,
9055 "localAsNoPrepend");
9056
9057 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9058 json_object_boolean_true_add(json_neigh,
9059 "localAsReplaceAs");
9060 } else {
9061 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9062 || (p->as_type == AS_INTERNAL))
9063 vty_out(vty, "remote AS %u, ", p->as);
9064 else
9065 vty_out(vty, "remote AS Unspecified, ");
9066 vty_out(vty, "local AS %u%s%s, ",
9067 p->change_local_as ? p->change_local_as : p->local_as,
9068 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9069 ? " no-prepend"
9070 : "",
9071 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9072 ? " replace-as"
9073 : "");
9074 }
9075 /* peer type internal, external, confed-internal or confed-external */
9076 if (p->as == p->local_as) {
9077 if (use_json) {
9078 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9079 json_object_boolean_true_add(
9080 json_neigh, "nbrConfedInternalLink");
9081 else
9082 json_object_boolean_true_add(json_neigh,
9083 "nbrInternalLink");
9084 } else {
9085 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9086 vty_out(vty, "confed-internal link\n");
9087 else
9088 vty_out(vty, "internal link\n");
9089 }
9090 } else {
9091 if (use_json) {
9092 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9093 json_object_boolean_true_add(
9094 json_neigh, "nbrConfedExternalLink");
9095 else
9096 json_object_boolean_true_add(json_neigh,
9097 "nbrExternalLink");
9098 } else {
9099 if (bgp_confederation_peers_check(bgp, p->as))
9100 vty_out(vty, "confed-external link\n");
9101 else
9102 vty_out(vty, "external link\n");
9103 }
9104 }
9105
9106 /* Description. */
9107 if (p->desc) {
9108 if (use_json)
9109 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9110 else
9111 vty_out(vty, " Description: %s\n", p->desc);
9112 }
9113
9114 if (p->hostname) {
9115 if (use_json) {
9116 if (p->hostname)
9117 json_object_string_add(json_neigh, "hostname",
9118 p->hostname);
9119
9120 if (p->domainname)
9121 json_object_string_add(json_neigh, "domainname",
9122 p->domainname);
9123 } else {
9124 if (p->domainname && (p->domainname[0] != '\0'))
9125 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9126 p->domainname);
9127 else
9128 vty_out(vty, "Hostname: %s\n", p->hostname);
9129 }
9130 }
9131
9132 /* Peer-group */
9133 if (p->group) {
9134 if (use_json) {
9135 json_object_string_add(json_neigh, "peerGroup",
9136 p->group->name);
9137
9138 if (dn_flag[0]) {
9139 struct prefix prefix, *range = NULL;
9140
9141 sockunion2hostprefix(&(p->su), &prefix);
9142 range = peer_group_lookup_dynamic_neighbor_range(
9143 p->group, &prefix);
9144
9145 if (range) {
9146 prefix2str(range, buf1, sizeof(buf1));
9147 json_object_string_add(
9148 json_neigh,
9149 "peerSubnetRangeGroup", buf1);
9150 }
9151 }
9152 } else {
9153 vty_out(vty,
9154 " Member of peer-group %s for session parameters\n",
9155 p->group->name);
9156
9157 if (dn_flag[0]) {
9158 struct prefix prefix, *range = NULL;
9159
9160 sockunion2hostprefix(&(p->su), &prefix);
9161 range = peer_group_lookup_dynamic_neighbor_range(
9162 p->group, &prefix);
9163
9164 if (range) {
9165 prefix2str(range, buf1, sizeof(buf1));
9166 vty_out(vty,
9167 " Belongs to the subnet range group: %s\n",
9168 buf1);
9169 }
9170 }
9171 }
9172 }
9173
9174 if (use_json) {
9175 /* Administrative shutdown. */
9176 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9177 json_object_boolean_true_add(json_neigh,
9178 "adminShutDown");
9179
9180 /* BGP Version. */
9181 json_object_int_add(json_neigh, "bgpVersion", 4);
9182 json_object_string_add(
9183 json_neigh, "remoteRouterId",
9184 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9185 json_object_string_add(
9186 json_neigh, "localRouterId",
9187 inet_ntop(AF_INET, &bgp->router_id, buf1,
9188 sizeof(buf1)));
d62a17ae 9189
9190 /* Confederation */
9191 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9192 && bgp_confederation_peers_check(bgp, p->as))
9193 json_object_boolean_true_add(json_neigh,
9194 "nbrCommonAdmin");
9195
9196 /* Status. */
9197 json_object_string_add(
9198 json_neigh, "bgpState",
9199 lookup_msg(bgp_status_msg, p->status, NULL));
9200
9201 if (p->status == Established) {
9202 time_t uptime;
d62a17ae 9203
9204 uptime = bgp_clock();
9205 uptime -= p->uptime;
d62a17ae 9206 epoch_tbuf = time(NULL) - uptime;
9207
bee57a7a 9208#if CONFDATE > 20200101
a4d82a8a
PZ
9209 CPP_NOTICE(
9210 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9211#endif
9212 /*
9213 * bgpTimerUp was miliseconds that was accurate
9214 * up to 1 day, then the value returned
9215 * became garbage. So in order to provide
9216 * some level of backwards compatability,
9217 * we still provde the data, but now
9218 * we are returning the correct value
9219 * and also adding a new bgpTimerUpMsec
9220 * which will allow us to deprecate
9221 * this eventually
9222 */
d62a17ae 9223 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9224 uptime * 1000);
d3c7efed
DS
9225 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9226 uptime * 1000);
d62a17ae 9227 json_object_string_add(json_neigh, "bgpTimerUpString",
9228 peer_uptime(p->uptime, timebuf,
9229 BGP_UPTIME_LEN, 0,
9230 NULL));
9231 json_object_int_add(json_neigh,
9232 "bgpTimerUpEstablishedEpoch",
9233 epoch_tbuf);
9234 }
9235
9236 else if (p->status == Active) {
9237 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9238 json_object_string_add(json_neigh, "bgpStateIs",
9239 "passive");
9240 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9241 json_object_string_add(json_neigh, "bgpStateIs",
9242 "passiveNSF");
9243 }
9244
9245 /* read timer */
9246 time_t uptime;
9247 struct tm *tm;
9248
9249 uptime = bgp_clock();
9250 uptime -= p->readtime;
9251 tm = gmtime(&uptime);
9252 json_object_int_add(json_neigh, "bgpTimerLastRead",
9253 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9254 + (tm->tm_hour * 3600000));
9255
9256 uptime = bgp_clock();
9257 uptime -= p->last_write;
9258 tm = gmtime(&uptime);
9259 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9260 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9261 + (tm->tm_hour * 3600000));
9262
9263 uptime = bgp_clock();
9264 uptime -= p->update_time;
9265 tm = gmtime(&uptime);
9266 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9267 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9268 + (tm->tm_hour * 3600000));
9269
9270 /* Configured timer values. */
9271 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9272 p->v_holdtime * 1000);
9273 json_object_int_add(json_neigh,
9274 "bgpTimerKeepAliveIntervalMsecs",
9275 p->v_keepalive * 1000);
b90a8e13 9276 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9277 json_object_int_add(json_neigh,
9278 "bgpTimerConfiguredHoldTimeMsecs",
9279 p->holdtime * 1000);
9280 json_object_int_add(
9281 json_neigh,
9282 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9283 p->keepalive * 1000);
d25e4efc 9284 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9285 || (bgp->default_keepalive
9286 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9287 json_object_int_add(json_neigh,
9288 "bgpTimerConfiguredHoldTimeMsecs",
9289 bgp->default_holdtime);
9290 json_object_int_add(
9291 json_neigh,
9292 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9293 bgp->default_keepalive);
d62a17ae 9294 }
9295 } else {
9296 /* Administrative shutdown. */
9297 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9298 vty_out(vty, " Administratively shut down\n");
9299
9300 /* BGP Version. */
9301 vty_out(vty, " BGP version 4");
0e38aeb4 9302 vty_out(vty, ", remote router ID %s",
d62a17ae 9303 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9304 vty_out(vty, ", local router ID %s\n",
9305 inet_ntop(AF_INET, &bgp->router_id, buf1,
9306 sizeof(buf1)));
d62a17ae 9307
9308 /* Confederation */
9309 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9310 && bgp_confederation_peers_check(bgp, p->as))
9311 vty_out(vty,
9312 " Neighbor under common administration\n");
9313
9314 /* Status. */
9315 vty_out(vty, " BGP state = %s",
9316 lookup_msg(bgp_status_msg, p->status, NULL));
9317
9318 if (p->status == Established)
9319 vty_out(vty, ", up for %8s",
9320 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9321 0, NULL));
9322
9323 else if (p->status == Active) {
9324 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9325 vty_out(vty, " (passive)");
9326 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9327 vty_out(vty, " (NSF passive)");
9328 }
9329 vty_out(vty, "\n");
9330
9331 /* read timer */
9332 vty_out(vty, " Last read %s",
9333 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9334 NULL));
9335 vty_out(vty, ", Last write %s\n",
9336 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9337 NULL));
9338
9339 /* Configured timer values. */
9340 vty_out(vty,
9341 " Hold time is %d, keepalive interval is %d seconds\n",
9342 p->v_holdtime, p->v_keepalive);
b90a8e13 9343 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9344 vty_out(vty, " Configured hold time is %d",
9345 p->holdtime);
9346 vty_out(vty, ", keepalive interval is %d seconds\n",
9347 p->keepalive);
d25e4efc 9348 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9349 || (bgp->default_keepalive
9350 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9351 vty_out(vty, " Configured hold time is %d",
9352 bgp->default_holdtime);
9353 vty_out(vty, ", keepalive interval is %d seconds\n",
9354 bgp->default_keepalive);
d62a17ae 9355 }
9356 }
9357 /* Capability. */
9358 if (p->status == Established) {
9359 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9360 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9361 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9362 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9363 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9364 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9365 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9366 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9367 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9368 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9369 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9370 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9371 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9372 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9373 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9374 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9375 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9376 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9377 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9378 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9379 if (use_json) {
9380 json_object *json_cap = NULL;
9381
9382 json_cap = json_object_new_object();
9383
9384 /* AS4 */
9385 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9386 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9387 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9388 && CHECK_FLAG(p->cap,
9389 PEER_CAP_AS4_RCV))
9390 json_object_string_add(
9391 json_cap, "4byteAs",
9392 "advertisedAndReceived");
9393 else if (CHECK_FLAG(p->cap,
9394 PEER_CAP_AS4_ADV))
9395 json_object_string_add(
9396 json_cap, "4byteAs",
9397 "advertised");
9398 else if (CHECK_FLAG(p->cap,
9399 PEER_CAP_AS4_RCV))
9400 json_object_string_add(
9401 json_cap, "4byteAs",
9402 "received");
9403 }
9404
9405 /* AddPath */
9406 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9407 || CHECK_FLAG(p->cap,
9408 PEER_CAP_ADDPATH_ADV)) {
9409 json_object *json_add = NULL;
9410 const char *print_store;
9411
9412 json_add = json_object_new_object();
9413
05c7a1cc
QY
9414 FOREACH_AFI_SAFI (afi, safi) {
9415 json_object *json_sub = NULL;
9416 json_sub =
9417 json_object_new_object();
9418 print_store = afi_safi_print(
9419 afi, safi);
d62a17ae 9420
05c7a1cc
QY
9421 if (CHECK_FLAG(
9422 p->af_cap[afi]
9423 [safi],
9424 PEER_CAP_ADDPATH_AF_TX_ADV)
9425 || CHECK_FLAG(
9426 p->af_cap[afi]
9427 [safi],
9428 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9429 if (CHECK_FLAG(
9430 p->af_cap
9431 [afi]
9432 [safi],
9433 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9434 && CHECK_FLAG(
d62a17ae 9435 p->af_cap
9436 [afi]
9437 [safi],
05c7a1cc
QY
9438 PEER_CAP_ADDPATH_AF_TX_RCV))
9439 json_object_boolean_true_add(
9440 json_sub,
9441 "txAdvertisedAndReceived");
9442 else if (
9443 CHECK_FLAG(
9444 p->af_cap
9445 [afi]
9446 [safi],
9447 PEER_CAP_ADDPATH_AF_TX_ADV))
9448 json_object_boolean_true_add(
9449 json_sub,
9450 "txAdvertised");
9451 else if (
9452 CHECK_FLAG(
9453 p->af_cap
9454 [afi]
9455 [safi],
9456 PEER_CAP_ADDPATH_AF_TX_RCV))
9457 json_object_boolean_true_add(
9458 json_sub,
9459 "txReceived");
9460 }
d62a17ae 9461
05c7a1cc
QY
9462 if (CHECK_FLAG(
9463 p->af_cap[afi]
9464 [safi],
9465 PEER_CAP_ADDPATH_AF_RX_ADV)
9466 || CHECK_FLAG(
9467 p->af_cap[afi]
9468 [safi],
9469 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9470 if (CHECK_FLAG(
9471 p->af_cap
9472 [afi]
9473 [safi],
9474 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9475 && CHECK_FLAG(
d62a17ae 9476 p->af_cap
9477 [afi]
9478 [safi],
9479 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9480 json_object_boolean_true_add(
9481 json_sub,
9482 "rxAdvertisedAndReceived");
9483 else if (
9484 CHECK_FLAG(
9485 p->af_cap
9486 [afi]
9487 [safi],
9488 PEER_CAP_ADDPATH_AF_RX_ADV))
9489 json_object_boolean_true_add(
9490 json_sub,
9491 "rxAdvertised");
9492 else if (
9493 CHECK_FLAG(
9494 p->af_cap
9495 [afi]
9496 [safi],
9497 PEER_CAP_ADDPATH_AF_RX_RCV))
9498 json_object_boolean_true_add(
9499 json_sub,
9500 "rxReceived");
d62a17ae 9501 }
9502
05c7a1cc
QY
9503 if (CHECK_FLAG(
9504 p->af_cap[afi]
9505 [safi],
9506 PEER_CAP_ADDPATH_AF_TX_ADV)
9507 || CHECK_FLAG(
9508 p->af_cap[afi]
9509 [safi],
9510 PEER_CAP_ADDPATH_AF_TX_RCV)
9511 || CHECK_FLAG(
9512 p->af_cap[afi]
9513 [safi],
9514 PEER_CAP_ADDPATH_AF_RX_ADV)
9515 || CHECK_FLAG(
9516 p->af_cap[afi]
9517 [safi],
9518 PEER_CAP_ADDPATH_AF_RX_RCV))
9519 json_object_object_add(
9520 json_add,
9521 print_store,
9522 json_sub);
9523 else
9524 json_object_free(
9525 json_sub);
9526 }
9527
d62a17ae 9528 json_object_object_add(
9529 json_cap, "addPath", json_add);
9530 }
9531
9532 /* Dynamic */
9533 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9534 || CHECK_FLAG(p->cap,
9535 PEER_CAP_DYNAMIC_ADV)) {
9536 if (CHECK_FLAG(p->cap,
9537 PEER_CAP_DYNAMIC_ADV)
9538 && CHECK_FLAG(p->cap,
9539 PEER_CAP_DYNAMIC_RCV))
9540 json_object_string_add(
9541 json_cap, "dynamic",
9542 "advertisedAndReceived");
9543 else if (CHECK_FLAG(
9544 p->cap,
9545 PEER_CAP_DYNAMIC_ADV))
9546 json_object_string_add(
9547 json_cap, "dynamic",
9548 "advertised");
9549 else if (CHECK_FLAG(
9550 p->cap,
9551 PEER_CAP_DYNAMIC_RCV))
9552 json_object_string_add(
9553 json_cap, "dynamic",
9554 "received");
9555 }
9556
9557 /* Extended nexthop */
9558 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9559 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9560 json_object *json_nxt = NULL;
9561 const char *print_store;
9562
9563
9564 if (CHECK_FLAG(p->cap,
9565 PEER_CAP_ENHE_ADV)
9566 && CHECK_FLAG(p->cap,
9567 PEER_CAP_ENHE_RCV))
9568 json_object_string_add(
9569 json_cap,
9570 "extendedNexthop",
9571 "advertisedAndReceived");
9572 else if (CHECK_FLAG(p->cap,
9573 PEER_CAP_ENHE_ADV))
9574 json_object_string_add(
9575 json_cap,
9576 "extendedNexthop",
9577 "advertised");
9578 else if (CHECK_FLAG(p->cap,
9579 PEER_CAP_ENHE_RCV))
9580 json_object_string_add(
9581 json_cap,
9582 "extendedNexthop",
9583 "received");
9584
9585 if (CHECK_FLAG(p->cap,
9586 PEER_CAP_ENHE_RCV)) {
9587 json_nxt =
9588 json_object_new_object();
9589
9590 for (safi = SAFI_UNICAST;
9591 safi < SAFI_MAX; safi++) {
9592 if (CHECK_FLAG(
9593 p->af_cap
9594 [AFI_IP]
9595 [safi],
9596 PEER_CAP_ENHE_AF_RCV)) {
9597 print_store = afi_safi_print(
9598 AFI_IP,
9599 safi);
9600 json_object_string_add(
9601 json_nxt,
9602 print_store,
9603 "recieved");
9604 }
9605 }
9606 json_object_object_add(
9607 json_cap,
9608 "extendedNexthopFamililesByPeer",
9609 json_nxt);
9610 }
9611 }
9612
9613 /* Route Refresh */
9614 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9615 || CHECK_FLAG(p->cap,
9616 PEER_CAP_REFRESH_NEW_RCV)
9617 || CHECK_FLAG(p->cap,
9618 PEER_CAP_REFRESH_OLD_RCV)) {
9619 if (CHECK_FLAG(p->cap,
9620 PEER_CAP_REFRESH_ADV)
9621 && (CHECK_FLAG(
9622 p->cap,
9623 PEER_CAP_REFRESH_NEW_RCV)
9624 || CHECK_FLAG(
9625 p->cap,
9626 PEER_CAP_REFRESH_OLD_RCV))) {
9627 if (CHECK_FLAG(
9628 p->cap,
9629 PEER_CAP_REFRESH_OLD_RCV)
9630 && CHECK_FLAG(
9631 p->cap,
9632 PEER_CAP_REFRESH_NEW_RCV))
9633 json_object_string_add(
9634 json_cap,
9635 "routeRefresh",
9636 "advertisedAndReceivedOldNew");
9637 else {
9638 if (CHECK_FLAG(
9639 p->cap,
9640 PEER_CAP_REFRESH_OLD_RCV))
9641 json_object_string_add(
9642 json_cap,
9643 "routeRefresh",
9644 "advertisedAndReceivedOld");
9645 else
9646 json_object_string_add(
9647 json_cap,
9648 "routeRefresh",
9649 "advertisedAndReceivedNew");
9650 }
9651 } else if (
9652 CHECK_FLAG(
9653 p->cap,
9654 PEER_CAP_REFRESH_ADV))
9655 json_object_string_add(
9656 json_cap,
9657 "routeRefresh",
9658 "advertised");
9659 else if (
9660 CHECK_FLAG(
9661 p->cap,
9662 PEER_CAP_REFRESH_NEW_RCV)
9663 || CHECK_FLAG(
9664 p->cap,
9665 PEER_CAP_REFRESH_OLD_RCV))
9666 json_object_string_add(
9667 json_cap,
9668 "routeRefresh",
9669 "received");
9670 }
9671
9672 /* Multiprotocol Extensions */
9673 json_object *json_multi = NULL;
9674 json_multi = json_object_new_object();
9675
05c7a1cc
QY
9676 FOREACH_AFI_SAFI (afi, safi) {
9677 if (p->afc_adv[afi][safi]
9678 || p->afc_recv[afi][safi]) {
9679 json_object *json_exten = NULL;
9680 json_exten =
9681 json_object_new_object();
9682
d62a17ae 9683 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9684 && p->afc_recv[afi][safi])
9685 json_object_boolean_true_add(
9686 json_exten,
9687 "advertisedAndReceived");
9688 else if (p->afc_adv[afi][safi])
9689 json_object_boolean_true_add(
9690 json_exten,
9691 "advertised");
9692 else if (p->afc_recv[afi][safi])
9693 json_object_boolean_true_add(
9694 json_exten,
9695 "received");
d62a17ae 9696
05c7a1cc
QY
9697 json_object_object_add(
9698 json_multi,
9699 afi_safi_print(afi,
9700 safi),
9701 json_exten);
d62a17ae 9702 }
9703 }
9704 json_object_object_add(
9705 json_cap, "multiprotocolExtensions",
9706 json_multi);
9707
d77114b7 9708 /* Hostname capabilities */
60466a63 9709 json_object *json_hname = NULL;
d77114b7
MK
9710
9711 json_hname = json_object_new_object();
9712
9713 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9714 json_object_string_add(
60466a63
QY
9715 json_hname, "advHostName",
9716 bgp->peer_self->hostname
9717 ? bgp->peer_self
9718 ->hostname
d77114b7
MK
9719 : "n/a");
9720 json_object_string_add(
60466a63
QY
9721 json_hname, "advDomainName",
9722 bgp->peer_self->domainname
9723 ? bgp->peer_self
9724 ->domainname
d77114b7
MK
9725 : "n/a");
9726 }
9727
9728
9729 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9730 json_object_string_add(
60466a63
QY
9731 json_hname, "rcvHostName",
9732 p->hostname ? p->hostname
9733 : "n/a");
d77114b7 9734 json_object_string_add(
60466a63
QY
9735 json_hname, "rcvDomainName",
9736 p->domainname ? p->domainname
9737 : "n/a");
d77114b7
MK
9738 }
9739
60466a63 9740 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9741 json_hname);
9742
d62a17ae 9743 /* Gracefull Restart */
9744 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9745 || CHECK_FLAG(p->cap,
9746 PEER_CAP_RESTART_ADV)) {
9747 if (CHECK_FLAG(p->cap,
9748 PEER_CAP_RESTART_ADV)
9749 && CHECK_FLAG(p->cap,
9750 PEER_CAP_RESTART_RCV))
9751 json_object_string_add(
9752 json_cap,
9753 "gracefulRestart",
9754 "advertisedAndReceived");
9755 else if (CHECK_FLAG(
9756 p->cap,
9757 PEER_CAP_RESTART_ADV))
9758 json_object_string_add(
9759 json_cap,
9760 "gracefulRestartCapability",
9761 "advertised");
9762 else if (CHECK_FLAG(
9763 p->cap,
9764 PEER_CAP_RESTART_RCV))
9765 json_object_string_add(
9766 json_cap,
9767 "gracefulRestartCapability",
9768 "received");
9769
9770 if (CHECK_FLAG(p->cap,
9771 PEER_CAP_RESTART_RCV)) {
9772 int restart_af_count = 0;
9773 json_object *json_restart =
9774 NULL;
9775 json_restart =
9776 json_object_new_object();
9777
9778 json_object_int_add(
9779 json_cap,
9780 "gracefulRestartRemoteTimerMsecs",
9781 p->v_gr_restart * 1000);
9782
05c7a1cc
QY
9783 FOREACH_AFI_SAFI (afi, safi) {
9784 if (CHECK_FLAG(
9785 p->af_cap
9786 [afi]
9787 [safi],
9788 PEER_CAP_RESTART_AF_RCV)) {
9789 json_object *
9790 json_sub =
9791 NULL;
9792 json_sub =
9793 json_object_new_object();
9794
d62a17ae 9795 if (CHECK_FLAG(
9796 p->af_cap
9797 [afi]
9798 [safi],
05c7a1cc
QY
9799 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9800 json_object_boolean_true_add(
9801 json_sub,
9802 "preserved");
9803 restart_af_count++;
9804 json_object_object_add(
9805 json_restart,
9806 afi_safi_print(
9807 afi,
9808 safi),
9809 json_sub);
d62a17ae 9810 }
9811 }
9812 if (!restart_af_count) {
9813 json_object_string_add(
9814 json_cap,
9815 "addressFamiliesByPeer",
9816 "none");
9817 json_object_free(
9818 json_restart);
9819 } else
9820 json_object_object_add(
9821 json_cap,
9822 "addressFamiliesByPeer",
9823 json_restart);
9824 }
9825 }
9826 json_object_object_add(json_neigh,
9827 "neighborCapabilities",
9828 json_cap);
9829 } else {
9830 vty_out(vty, " Neighbor capabilities:\n");
9831
9832 /* AS4 */
9833 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9834 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9835 vty_out(vty, " 4 Byte AS:");
9836 if (CHECK_FLAG(p->cap,
9837 PEER_CAP_AS4_ADV))
9838 vty_out(vty, " advertised");
9839 if (CHECK_FLAG(p->cap,
9840 PEER_CAP_AS4_RCV))
9841 vty_out(vty, " %sreceived",
9842 CHECK_FLAG(
9843 p->cap,
9844 PEER_CAP_AS4_ADV)
9845 ? "and "
9846 : "");
9847 vty_out(vty, "\n");
9848 }
9849
9850 /* AddPath */
9851 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9852 || CHECK_FLAG(p->cap,
9853 PEER_CAP_ADDPATH_ADV)) {
9854 vty_out(vty, " AddPath:\n");
9855
05c7a1cc
QY
9856 FOREACH_AFI_SAFI (afi, safi) {
9857 if (CHECK_FLAG(
9858 p->af_cap[afi]
9859 [safi],
9860 PEER_CAP_ADDPATH_AF_TX_ADV)
9861 || CHECK_FLAG(
9862 p->af_cap[afi]
9863 [safi],
9864 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9865 vty_out(vty,
9866 " %s: TX ",
9867 afi_safi_print(
9868 afi,
9869 safi));
9870
d62a17ae 9871 if (CHECK_FLAG(
9872 p->af_cap
9873 [afi]
9874 [safi],
05c7a1cc 9875 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9876 vty_out(vty,
05c7a1cc 9877 "advertised %s",
d62a17ae 9878 afi_safi_print(
9879 afi,
9880 safi));
9881
05c7a1cc
QY
9882 if (CHECK_FLAG(
9883 p->af_cap
9884 [afi]
9885 [safi],
9886 PEER_CAP_ADDPATH_AF_TX_RCV))
9887 vty_out(vty,
9888 "%sreceived",
9889 CHECK_FLAG(
9890 p->af_cap
9891 [afi]
9892 [safi],
9893 PEER_CAP_ADDPATH_AF_TX_ADV)
9894 ? " and "
9895 : "");
d62a17ae 9896
05c7a1cc
QY
9897 vty_out(vty, "\n");
9898 }
d62a17ae 9899
05c7a1cc
QY
9900 if (CHECK_FLAG(
9901 p->af_cap[afi]
9902 [safi],
9903 PEER_CAP_ADDPATH_AF_RX_ADV)
9904 || CHECK_FLAG(
9905 p->af_cap[afi]
9906 [safi],
9907 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9908 vty_out(vty,
9909 " %s: RX ",
9910 afi_safi_print(
9911 afi,
9912 safi));
d62a17ae 9913
9914 if (CHECK_FLAG(
9915 p->af_cap
9916 [afi]
9917 [safi],
05c7a1cc 9918 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9919 vty_out(vty,
05c7a1cc 9920 "advertised %s",
d62a17ae 9921 afi_safi_print(
9922 afi,
9923 safi));
9924
05c7a1cc
QY
9925 if (CHECK_FLAG(
9926 p->af_cap
9927 [afi]
9928 [safi],
9929 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9930 vty_out(vty,
05c7a1cc
QY
9931 "%sreceived",
9932 CHECK_FLAG(
9933 p->af_cap
9934 [afi]
9935 [safi],
9936 PEER_CAP_ADDPATH_AF_RX_ADV)
9937 ? " and "
9938 : "");
9939
9940 vty_out(vty, "\n");
d62a17ae 9941 }
05c7a1cc 9942 }
d62a17ae 9943 }
9944
9945 /* Dynamic */
9946 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9947 || CHECK_FLAG(p->cap,
9948 PEER_CAP_DYNAMIC_ADV)) {
9949 vty_out(vty, " Dynamic:");
9950 if (CHECK_FLAG(p->cap,
9951 PEER_CAP_DYNAMIC_ADV))
9952 vty_out(vty, " advertised");
9953 if (CHECK_FLAG(p->cap,
9954 PEER_CAP_DYNAMIC_RCV))
9955 vty_out(vty, " %sreceived",
9956 CHECK_FLAG(
9957 p->cap,
9958 PEER_CAP_DYNAMIC_ADV)
9959 ? "and "
9960 : "");
9961 vty_out(vty, "\n");
9962 }
9963
9964 /* Extended nexthop */
9965 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9966 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9967 vty_out(vty, " Extended nexthop:");
9968 if (CHECK_FLAG(p->cap,
9969 PEER_CAP_ENHE_ADV))
9970 vty_out(vty, " advertised");
9971 if (CHECK_FLAG(p->cap,
9972 PEER_CAP_ENHE_RCV))
9973 vty_out(vty, " %sreceived",
9974 CHECK_FLAG(
9975 p->cap,
9976 PEER_CAP_ENHE_ADV)
9977 ? "and "
9978 : "");
9979 vty_out(vty, "\n");
9980
9981 if (CHECK_FLAG(p->cap,
9982 PEER_CAP_ENHE_RCV)) {
9983 vty_out(vty,
9984 " Address families by peer:\n ");
9985 for (safi = SAFI_UNICAST;
9986 safi < SAFI_MAX; safi++)
9987 if (CHECK_FLAG(
9988 p->af_cap
9989 [AFI_IP]
9990 [safi],
9991 PEER_CAP_ENHE_AF_RCV))
9992 vty_out(vty,
9993 " %s\n",
9994 afi_safi_print(
9995 AFI_IP,
9996 safi));
9997 }
9998 }
9999
10000 /* Route Refresh */
10001 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10002 || CHECK_FLAG(p->cap,
10003 PEER_CAP_REFRESH_NEW_RCV)
10004 || CHECK_FLAG(p->cap,
10005 PEER_CAP_REFRESH_OLD_RCV)) {
10006 vty_out(vty, " Route refresh:");
10007 if (CHECK_FLAG(p->cap,
10008 PEER_CAP_REFRESH_ADV))
10009 vty_out(vty, " advertised");
10010 if (CHECK_FLAG(p->cap,
10011 PEER_CAP_REFRESH_NEW_RCV)
10012 || CHECK_FLAG(
10013 p->cap,
10014 PEER_CAP_REFRESH_OLD_RCV))
10015 vty_out(vty, " %sreceived(%s)",
10016 CHECK_FLAG(
10017 p->cap,
10018 PEER_CAP_REFRESH_ADV)
10019 ? "and "
10020 : "",
10021 (CHECK_FLAG(
10022 p->cap,
10023 PEER_CAP_REFRESH_OLD_RCV)
10024 && CHECK_FLAG(
10025 p->cap,
10026 PEER_CAP_REFRESH_NEW_RCV))
10027 ? "old & new"
10028 : CHECK_FLAG(
10029 p->cap,
10030 PEER_CAP_REFRESH_OLD_RCV)
10031 ? "old"
10032 : "new");
10033
10034 vty_out(vty, "\n");
10035 }
10036
10037 /* Multiprotocol Extensions */
05c7a1cc
QY
10038 FOREACH_AFI_SAFI (afi, safi)
10039 if (p->afc_adv[afi][safi]
10040 || p->afc_recv[afi][safi]) {
10041 vty_out(vty,
10042 " Address Family %s:",
10043 afi_safi_print(afi,
10044 safi));
10045 if (p->afc_adv[afi][safi])
d62a17ae 10046 vty_out(vty,
05c7a1cc
QY
10047 " advertised");
10048 if (p->afc_recv[afi][safi])
10049 vty_out(vty,
10050 " %sreceived",
10051 p->afc_adv[afi]
10052 [safi]
10053 ? "and "
10054 : "");
10055 vty_out(vty, "\n");
10056 }
d62a17ae 10057
10058 /* Hostname capability */
60466a63 10059 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10060
10061 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10062 vty_out(vty,
10063 " advertised (name: %s,domain name: %s)",
60466a63
QY
10064 bgp->peer_self->hostname
10065 ? bgp->peer_self
10066 ->hostname
d77114b7 10067 : "n/a",
60466a63
QY
10068 bgp->peer_self->domainname
10069 ? bgp->peer_self
10070 ->domainname
d77114b7
MK
10071 : "n/a");
10072 } else {
10073 vty_out(vty, " not advertised");
d62a17ae 10074 }
10075
d77114b7 10076 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10077 vty_out(vty,
10078 " received (name: %s,domain name: %s)",
60466a63
QY
10079 p->hostname ? p->hostname
10080 : "n/a",
10081 p->domainname ? p->domainname
10082 : "n/a");
d77114b7
MK
10083 } else {
10084 vty_out(vty, " not received");
10085 }
10086
10087 vty_out(vty, "\n");
10088
d62a17ae 10089 /* Gracefull Restart */
10090 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10091 || CHECK_FLAG(p->cap,
10092 PEER_CAP_RESTART_ADV)) {
10093 vty_out(vty,
10094 " Graceful Restart Capabilty:");
10095 if (CHECK_FLAG(p->cap,
10096 PEER_CAP_RESTART_ADV))
10097 vty_out(vty, " advertised");
10098 if (CHECK_FLAG(p->cap,
10099 PEER_CAP_RESTART_RCV))
10100 vty_out(vty, " %sreceived",
10101 CHECK_FLAG(
10102 p->cap,
10103 PEER_CAP_RESTART_ADV)
10104 ? "and "
10105 : "");
10106 vty_out(vty, "\n");
10107
10108 if (CHECK_FLAG(p->cap,
10109 PEER_CAP_RESTART_RCV)) {
10110 int restart_af_count = 0;
10111
10112 vty_out(vty,
10113 " Remote Restart timer is %d seconds\n",
10114 p->v_gr_restart);
10115 vty_out(vty,
10116 " Address families by peer:\n ");
10117
05c7a1cc
QY
10118 FOREACH_AFI_SAFI (afi, safi)
10119 if (CHECK_FLAG(
10120 p->af_cap
10121 [afi]
10122 [safi],
10123 PEER_CAP_RESTART_AF_RCV)) {
10124 vty_out(vty,
10125 "%s%s(%s)",
10126 restart_af_count
10127 ? ", "
10128 : "",
10129 afi_safi_print(
10130 afi,
10131 safi),
10132 CHECK_FLAG(
10133 p->af_cap
10134 [afi]
10135 [safi],
10136 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10137 ? "preserved"
10138 : "not preserved");
10139 restart_af_count++;
10140 }
d62a17ae 10141 if (!restart_af_count)
10142 vty_out(vty, "none");
10143 vty_out(vty, "\n");
10144 }
10145 }
10146 }
10147 }
10148 }
10149
10150 /* graceful restart information */
10151 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10152 || p->t_gr_stale) {
10153 json_object *json_grace = NULL;
10154 json_object *json_grace_send = NULL;
10155 json_object *json_grace_recv = NULL;
10156 int eor_send_af_count = 0;
10157 int eor_receive_af_count = 0;
10158
10159 if (use_json) {
10160 json_grace = json_object_new_object();
10161 json_grace_send = json_object_new_object();
10162 json_grace_recv = json_object_new_object();
10163
10164 if (p->status == Established) {
05c7a1cc
QY
10165 FOREACH_AFI_SAFI (afi, safi) {
10166 if (CHECK_FLAG(p->af_sflags[afi][safi],
10167 PEER_STATUS_EOR_SEND)) {
10168 json_object_boolean_true_add(
10169 json_grace_send,
10170 afi_safi_print(afi,
10171 safi));
10172 eor_send_af_count++;
d62a17ae 10173 }
10174 }
05c7a1cc
QY
10175 FOREACH_AFI_SAFI (afi, safi) {
10176 if (CHECK_FLAG(
10177 p->af_sflags[afi][safi],
10178 PEER_STATUS_EOR_RECEIVED)) {
10179 json_object_boolean_true_add(
10180 json_grace_recv,
10181 afi_safi_print(afi,
10182 safi));
10183 eor_receive_af_count++;
d62a17ae 10184 }
10185 }
10186 }
10187
10188 json_object_object_add(json_grace, "endOfRibSend",
10189 json_grace_send);
10190 json_object_object_add(json_grace, "endOfRibRecv",
10191 json_grace_recv);
10192
10193 if (p->t_gr_restart)
10194 json_object_int_add(json_grace,
10195 "gracefulRestartTimerMsecs",
10196 thread_timer_remain_second(
10197 p->t_gr_restart)
10198 * 1000);
10199
10200 if (p->t_gr_stale)
10201 json_object_int_add(
10202 json_grace,
10203 "gracefulStalepathTimerMsecs",
10204 thread_timer_remain_second(
10205 p->t_gr_stale)
10206 * 1000);
10207
10208 json_object_object_add(
10209 json_neigh, "gracefulRestartInfo", json_grace);
10210 } else {
10211 vty_out(vty, " Graceful restart informations:\n");
10212 if (p->status == Established) {
10213 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10214 FOREACH_AFI_SAFI (afi, safi) {
10215 if (CHECK_FLAG(p->af_sflags[afi][safi],
10216 PEER_STATUS_EOR_SEND)) {
10217 vty_out(vty, "%s%s",
10218 eor_send_af_count ? ", "
10219 : "",
10220 afi_safi_print(afi,
10221 safi));
10222 eor_send_af_count++;
d62a17ae 10223 }
10224 }
10225 vty_out(vty, "\n");
10226 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10227 FOREACH_AFI_SAFI (afi, safi) {
10228 if (CHECK_FLAG(
10229 p->af_sflags[afi][safi],
10230 PEER_STATUS_EOR_RECEIVED)) {
10231 vty_out(vty, "%s%s",
10232 eor_receive_af_count
10233 ? ", "
10234 : "",
10235 afi_safi_print(afi,
10236 safi));
10237 eor_receive_af_count++;
d62a17ae 10238 }
10239 }
10240 vty_out(vty, "\n");
10241 }
10242
10243 if (p->t_gr_restart)
10244 vty_out(vty,
10245 " The remaining time of restart timer is %ld\n",
10246 thread_timer_remain_second(
10247 p->t_gr_restart));
10248
10249 if (p->t_gr_stale)
10250 vty_out(vty,
10251 " The remaining time of stalepath timer is %ld\n",
10252 thread_timer_remain_second(
10253 p->t_gr_stale));
10254 }
10255 }
10256 if (use_json) {
10257 json_object *json_stat = NULL;
10258 json_stat = json_object_new_object();
10259 /* Packet counts. */
10260 json_object_int_add(json_stat, "depthInq", 0);
10261 json_object_int_add(json_stat, "depthOutq",
10262 (unsigned long)p->obuf->count);
0112e9e0
QY
10263 json_object_int_add(json_stat, "opensSent",
10264 atomic_load_explicit(&p->open_out,
10265 memory_order_relaxed));
10266 json_object_int_add(json_stat, "opensRecv",
10267 atomic_load_explicit(&p->open_in,
10268 memory_order_relaxed));
d62a17ae 10269 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10270 atomic_load_explicit(&p->notify_out,
10271 memory_order_relaxed));
d62a17ae 10272 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10273 atomic_load_explicit(&p->notify_in,
10274 memory_order_relaxed));
10275 json_object_int_add(json_stat, "updatesSent",
10276 atomic_load_explicit(&p->update_out,
10277 memory_order_relaxed));
10278 json_object_int_add(json_stat, "updatesRecv",
10279 atomic_load_explicit(&p->update_in,
10280 memory_order_relaxed));
d62a17ae 10281 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10282 atomic_load_explicit(&p->keepalive_out,
10283 memory_order_relaxed));
d62a17ae 10284 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10285 atomic_load_explicit(&p->keepalive_in,
10286 memory_order_relaxed));
d62a17ae 10287 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10288 atomic_load_explicit(&p->refresh_out,
10289 memory_order_relaxed));
d62a17ae 10290 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10291 atomic_load_explicit(&p->refresh_in,
10292 memory_order_relaxed));
d62a17ae 10293 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10294 atomic_load_explicit(&p->dynamic_cap_out,
10295 memory_order_relaxed));
d62a17ae 10296 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10297 atomic_load_explicit(&p->dynamic_cap_in,
10298 memory_order_relaxed));
10299 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10300 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10301 json_object_object_add(json_neigh, "messageStats", json_stat);
10302 } else {
10303 /* Packet counts. */
10304 vty_out(vty, " Message statistics:\n");
10305 vty_out(vty, " Inq depth is 0\n");
10306 vty_out(vty, " Outq depth is %lu\n",
10307 (unsigned long)p->obuf->count);
10308 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10309 vty_out(vty, " Opens: %10d %10d\n",
10310 atomic_load_explicit(&p->open_out,
10311 memory_order_relaxed),
10312 atomic_load_explicit(&p->open_in,
10313 memory_order_relaxed));
10314 vty_out(vty, " Notifications: %10d %10d\n",
10315 atomic_load_explicit(&p->notify_out,
10316 memory_order_relaxed),
10317 atomic_load_explicit(&p->notify_in,
10318 memory_order_relaxed));
10319 vty_out(vty, " Updates: %10d %10d\n",
10320 atomic_load_explicit(&p->update_out,
10321 memory_order_relaxed),
10322 atomic_load_explicit(&p->update_in,
10323 memory_order_relaxed));
10324 vty_out(vty, " Keepalives: %10d %10d\n",
10325 atomic_load_explicit(&p->keepalive_out,
10326 memory_order_relaxed),
10327 atomic_load_explicit(&p->keepalive_in,
10328 memory_order_relaxed));
10329 vty_out(vty, " Route Refresh: %10d %10d\n",
10330 atomic_load_explicit(&p->refresh_out,
10331 memory_order_relaxed),
10332 atomic_load_explicit(&p->refresh_in,
10333 memory_order_relaxed));
d62a17ae 10334 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10335 atomic_load_explicit(&p->dynamic_cap_out,
10336 memory_order_relaxed),
10337 atomic_load_explicit(&p->dynamic_cap_in,
10338 memory_order_relaxed));
10339 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10340 PEER_TOTAL_RX(p));
d62a17ae 10341 }
10342
10343 if (use_json) {
10344 /* advertisement-interval */
10345 json_object_int_add(json_neigh,
10346 "minBtwnAdvertisementRunsTimerMsecs",
10347 p->v_routeadv * 1000);
10348
10349 /* Update-source. */
10350 if (p->update_if || p->update_source) {
10351 if (p->update_if)
10352 json_object_string_add(json_neigh,
10353 "updateSource",
10354 p->update_if);
10355 else if (p->update_source)
10356 json_object_string_add(
10357 json_neigh, "updateSource",
10358 sockunion2str(p->update_source, buf1,
10359 SU_ADDRSTRLEN));
10360 }
10361 } else {
10362 /* advertisement-interval */
10363 vty_out(vty,
10364 " Minimum time between advertisement runs is %d seconds\n",
10365 p->v_routeadv);
10366
10367 /* Update-source. */
10368 if (p->update_if || p->update_source) {
10369 vty_out(vty, " Update source is ");
10370 if (p->update_if)
10371 vty_out(vty, "%s", p->update_if);
10372 else if (p->update_source)
10373 vty_out(vty, "%s",
10374 sockunion2str(p->update_source, buf1,
10375 SU_ADDRSTRLEN));
10376 vty_out(vty, "\n");
10377 }
10378
10379 vty_out(vty, "\n");
10380 }
10381
10382 /* Address Family Information */
10383 json_object *json_hold = NULL;
10384
10385 if (use_json)
10386 json_hold = json_object_new_object();
10387
05c7a1cc
QY
10388 FOREACH_AFI_SAFI (afi, safi)
10389 if (p->afc[afi][safi])
10390 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10391 json_hold);
d62a17ae 10392
10393 if (use_json) {
10394 json_object_object_add(json_neigh, "addressFamilyInfo",
10395 json_hold);
10396 json_object_int_add(json_neigh, "connectionsEstablished",
10397 p->established);
10398 json_object_int_add(json_neigh, "connectionsDropped",
10399 p->dropped);
10400 } else
10401 vty_out(vty, " Connections established %d; dropped %d\n",
10402 p->established, p->dropped);
10403
10404 if (!p->last_reset) {
10405 if (use_json)
10406 json_object_string_add(json_neigh, "lastReset",
10407 "never");
10408 else
10409 vty_out(vty, " Last reset never\n");
10410 } else {
10411 if (use_json) {
10412 time_t uptime;
10413 struct tm *tm;
10414
10415 uptime = bgp_clock();
10416 uptime -= p->resettime;
10417 tm = gmtime(&uptime);
10418 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10419 (tm->tm_sec * 1000)
10420 + (tm->tm_min * 60000)
10421 + (tm->tm_hour * 3600000));
10422 json_object_string_add(
10423 json_neigh, "lastResetDueTo",
10424 peer_down_str[(int)p->last_reset]);
10425 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10426 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10427 char errorcodesubcode_hexstr[5];
10428 char errorcodesubcode_str[256];
10429
10430 code_str = bgp_notify_code_str(p->notify.code);
10431 subcode_str = bgp_notify_subcode_str(
10432 p->notify.code, p->notify.subcode);
10433
10434 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10435 p->notify.code, p->notify.subcode);
10436 json_object_string_add(json_neigh,
10437 "lastErrorCodeSubcode",
10438 errorcodesubcode_hexstr);
10439 snprintf(errorcodesubcode_str, 255, "%s%s",
10440 code_str, subcode_str);
10441 json_object_string_add(json_neigh,
10442 "lastNotificationReason",
10443 errorcodesubcode_str);
10444 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10445 && p->notify.code == BGP_NOTIFY_CEASE
10446 && (p->notify.subcode
10447 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10448 || p->notify.subcode
10449 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10450 && p->notify.length) {
10451 char msgbuf[1024];
10452 const char *msg_str;
10453
10454 msg_str = bgp_notify_admin_message(
10455 msgbuf, sizeof(msgbuf),
d7c0a89a 10456 (uint8_t *)p->notify.data,
d62a17ae 10457 p->notify.length);
10458 if (msg_str)
10459 json_object_string_add(
10460 json_neigh,
10461 "lastShutdownDescription",
10462 msg_str);
10463 }
10464 }
10465 } else {
10466 vty_out(vty, " Last reset %s, ",
10467 peer_uptime(p->resettime, timebuf,
10468 BGP_UPTIME_LEN, 0, NULL));
10469
10470 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10471 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10472 code_str = bgp_notify_code_str(p->notify.code);
10473 subcode_str = bgp_notify_subcode_str(
10474 p->notify.code, p->notify.subcode);
10475 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10476 p->last_reset == PEER_DOWN_NOTIFY_SEND
10477 ? "sent"
10478 : "received",
10479 code_str, subcode_str);
10480 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10481 && p->notify.code == BGP_NOTIFY_CEASE
10482 && (p->notify.subcode
10483 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10484 || p->notify.subcode
10485 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10486 && p->notify.length) {
10487 char msgbuf[1024];
10488 const char *msg_str;
10489
10490 msg_str = bgp_notify_admin_message(
10491 msgbuf, sizeof(msgbuf),
d7c0a89a 10492 (uint8_t *)p->notify.data,
d62a17ae 10493 p->notify.length);
10494 if (msg_str)
10495 vty_out(vty,
10496 " Message: \"%s\"\n",
10497 msg_str);
10498 }
10499 } else {
10500 vty_out(vty, "due to %s\n",
10501 peer_down_str[(int)p->last_reset]);
10502 }
10503
10504 if (p->last_reset_cause_size) {
10505 msg = p->last_reset_cause;
10506 vty_out(vty,
10507 " Message received that caused BGP to send a NOTIFICATION:\n ");
10508 for (i = 1; i <= p->last_reset_cause_size;
10509 i++) {
10510 vty_out(vty, "%02X", *msg++);
10511
10512 if (i != p->last_reset_cause_size) {
10513 if (i % 16 == 0) {
10514 vty_out(vty, "\n ");
10515 } else if (i % 4 == 0) {
10516 vty_out(vty, " ");
10517 }
10518 }
10519 }
10520 vty_out(vty, "\n");
10521 }
10522 }
10523 }
10524
10525 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10526 if (use_json)
10527 json_object_boolean_true_add(json_neigh,
10528 "prefixesConfigExceedMax");
10529 else
10530 vty_out(vty,
10531 " Peer had exceeded the max. no. of prefixes configured.\n");
10532
10533 if (p->t_pmax_restart) {
10534 if (use_json) {
10535 json_object_boolean_true_add(
10536 json_neigh, "reducePrefixNumFrom");
10537 json_object_int_add(json_neigh,
10538 "restartInTimerMsec",
10539 thread_timer_remain_second(
10540 p->t_pmax_restart)
10541 * 1000);
10542 } else
10543 vty_out(vty,
10544 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10545 p->host, thread_timer_remain_second(
10546 p->t_pmax_restart));
d62a17ae 10547 } else {
10548 if (use_json)
10549 json_object_boolean_true_add(
10550 json_neigh,
10551 "reducePrefixNumAndClearIpBgp");
10552 else
10553 vty_out(vty,
10554 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10555 p->host);
10556 }
10557 }
10558
10559 /* EBGP Multihop and GTSM */
10560 if (p->sort != BGP_PEER_IBGP) {
10561 if (use_json) {
10562 if (p->gtsm_hops > 0)
10563 json_object_int_add(json_neigh,
10564 "externalBgpNbrMaxHopsAway",
10565 p->gtsm_hops);
10566 else if (p->ttl > 1)
10567 json_object_int_add(json_neigh,
10568 "externalBgpNbrMaxHopsAway",
10569 p->ttl);
10570 } else {
10571 if (p->gtsm_hops > 0)
10572 vty_out(vty,
10573 " External BGP neighbor may be up to %d hops away.\n",
10574 p->gtsm_hops);
10575 else if (p->ttl > 1)
10576 vty_out(vty,
10577 " External BGP neighbor may be up to %d hops away.\n",
10578 p->ttl);
10579 }
10580 } else {
10581 if (p->gtsm_hops > 0) {
10582 if (use_json)
10583 json_object_int_add(json_neigh,
10584 "internalBgpNbrMaxHopsAway",
10585 p->gtsm_hops);
10586 else
10587 vty_out(vty,
10588 " Internal BGP neighbor may be up to %d hops away.\n",
10589 p->gtsm_hops);
10590 }
10591 }
10592
10593 /* Local address. */
10594 if (p->su_local) {
10595 if (use_json) {
10596 json_object_string_add(json_neigh, "hostLocal",
10597 sockunion2str(p->su_local, buf1,
10598 SU_ADDRSTRLEN));
10599 json_object_int_add(json_neigh, "portLocal",
10600 ntohs(p->su_local->sin.sin_port));
10601 } else
10602 vty_out(vty, "Local host: %s, Local port: %d\n",
10603 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10604 ntohs(p->su_local->sin.sin_port));
10605 }
10606
10607 /* Remote address. */
10608 if (p->su_remote) {
10609 if (use_json) {
10610 json_object_string_add(json_neigh, "hostForeign",
10611 sockunion2str(p->su_remote, buf1,
10612 SU_ADDRSTRLEN));
10613 json_object_int_add(json_neigh, "portForeign",
10614 ntohs(p->su_remote->sin.sin_port));
10615 } else
10616 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10617 sockunion2str(p->su_remote, buf1,
10618 SU_ADDRSTRLEN),
10619 ntohs(p->su_remote->sin.sin_port));
10620 }
10621
10622 /* Nexthop display. */
10623 if (p->su_local) {
10624 if (use_json) {
10625 json_object_string_add(json_neigh, "nexthop",
10626 inet_ntop(AF_INET,
10627 &p->nexthop.v4, buf1,
10628 sizeof(buf1)));
10629 json_object_string_add(json_neigh, "nexthopGlobal",
10630 inet_ntop(AF_INET6,
10631 &p->nexthop.v6_global,
10632 buf1, sizeof(buf1)));
10633 json_object_string_add(json_neigh, "nexthopLocal",
10634 inet_ntop(AF_INET6,
10635 &p->nexthop.v6_local,
10636 buf1, sizeof(buf1)));
10637 if (p->shared_network)
10638 json_object_string_add(json_neigh,
10639 "bgpConnection",
10640 "sharedNetwork");
10641 else
10642 json_object_string_add(json_neigh,
10643 "bgpConnection",
10644 "nonSharedNetwork");
10645 } else {
10646 vty_out(vty, "Nexthop: %s\n",
10647 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10648 sizeof(buf1)));
10649 vty_out(vty, "Nexthop global: %s\n",
10650 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10651 sizeof(buf1)));
10652 vty_out(vty, "Nexthop local: %s\n",
10653 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10654 sizeof(buf1)));
10655 vty_out(vty, "BGP connection: %s\n",
10656 p->shared_network ? "shared network"
10657 : "non shared network");
10658 }
10659 }
10660
10661 /* Timer information. */
10662 if (use_json) {
10663 json_object_int_add(json_neigh, "connectRetryTimer",
10664 p->v_connect);
10665 if (p->status == Established && p->rtt)
10666 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10667 p->rtt);
10668 if (p->t_start)
10669 json_object_int_add(
10670 json_neigh, "nextStartTimerDueInMsecs",
10671 thread_timer_remain_second(p->t_start) * 1000);
10672 if (p->t_connect)
10673 json_object_int_add(
10674 json_neigh, "nextConnectTimerDueInMsecs",
10675 thread_timer_remain_second(p->t_connect)
10676 * 1000);
10677 if (p->t_routeadv) {
10678 json_object_int_add(json_neigh, "mraiInterval",
10679 p->v_routeadv);
10680 json_object_int_add(
10681 json_neigh, "mraiTimerExpireInMsecs",
10682 thread_timer_remain_second(p->t_routeadv)
10683 * 1000);
10684 }
10685 if (p->password)
10686 json_object_int_add(json_neigh, "authenticationEnabled",
10687 1);
10688
10689 if (p->t_read)
10690 json_object_string_add(json_neigh, "readThread", "on");
10691 else
10692 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10693
10694 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10695 json_object_string_add(json_neigh, "writeThread", "on");
10696 else
10697 json_object_string_add(json_neigh, "writeThread",
10698 "off");
10699 } else {
10700 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10701 p->v_connect);
10702 if (p->status == Established && p->rtt)
10703 vty_out(vty, "Estimated round trip time: %d ms\n",
10704 p->rtt);
10705 if (p->t_start)
10706 vty_out(vty, "Next start timer due in %ld seconds\n",
10707 thread_timer_remain_second(p->t_start));
10708 if (p->t_connect)
10709 vty_out(vty, "Next connect timer due in %ld seconds\n",
10710 thread_timer_remain_second(p->t_connect));
10711 if (p->t_routeadv)
10712 vty_out(vty,
10713 "MRAI (interval %u) timer expires in %ld seconds\n",
10714 p->v_routeadv,
10715 thread_timer_remain_second(p->t_routeadv));
10716 if (p->password)
10717 vty_out(vty, "Peer Authentication Enabled\n");
10718
10719 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10720 p->t_read ? "on" : "off",
10721 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10722 ? "on"
10723 : "off");
d62a17ae 10724 }
10725
10726 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10727 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10728 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10729
10730 if (!use_json)
10731 vty_out(vty, "\n");
10732
10733 /* BFD information. */
10734 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10735
10736 if (use_json) {
10737 if (p->conf_if) /* Configured interface name. */
10738 json_object_object_add(json, p->conf_if, json_neigh);
10739 else /* Configured IP address. */
10740 json_object_object_add(json, p->host, json_neigh);
10741 }
10742}
10743
10744static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10745 enum show_type type, union sockunion *su,
9f049418 10746 const char *conf_if, bool use_json,
d62a17ae 10747 json_object *json)
10748{
10749 struct listnode *node, *nnode;
10750 struct peer *peer;
10751 int find = 0;
9f049418 10752 bool nbr_output = false;
d62a17ae 10753
10754 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10755 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10756 continue;
10757
10758 switch (type) {
10759 case show_all:
10760 bgp_show_peer(vty, peer, use_json, json);
9f049418 10761 nbr_output = true;
d62a17ae 10762 break;
10763 case show_peer:
10764 if (conf_if) {
10765 if ((peer->conf_if
10766 && !strcmp(peer->conf_if, conf_if))
10767 || (peer->hostname
10768 && !strcmp(peer->hostname, conf_if))) {
10769 find = 1;
10770 bgp_show_peer(vty, peer, use_json,
10771 json);
10772 }
10773 } else {
10774 if (sockunion_same(&peer->su, su)) {
10775 find = 1;
10776 bgp_show_peer(vty, peer, use_json,
10777 json);
10778 }
10779 }
10780 break;
10781 }
10782 }
10783
10784 if (type == show_peer && !find) {
10785 if (use_json)
10786 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10787 else
88b7d255 10788 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10789 }
10790
9f049418 10791 if (type != show_peer && !nbr_output && !use_json)
94d4c685 10792 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 10793
d62a17ae 10794 if (use_json) {
996c9314
LB
10795 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10796 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10797 json_object_free(json);
10798 } else {
10799 vty_out(vty, "\n");
10800 }
10801
10802 return CMD_SUCCESS;
10803}
10804
10805static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10806 enum show_type type,
10807 const char *ip_str,
9f049418 10808 bool use_json)
d62a17ae 10809{
0291c246
MK
10810 struct listnode *node, *nnode;
10811 struct bgp *bgp;
71aedaa3 10812 union sockunion su;
0291c246 10813 json_object *json = NULL;
71aedaa3 10814 int ret, is_first = 1;
9f049418 10815 bool nbr_output = false;
d62a17ae 10816
10817 if (use_json)
10818 vty_out(vty, "{\n");
10819
10820 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10821 nbr_output = true;
d62a17ae 10822 if (use_json) {
10823 if (!(json = json_object_new_object())) {
af4c2728 10824 flog_err(
e50f7cfd 10825 EC_BGP_JSON_MEM_ERROR,
d62a17ae 10826 "Unable to allocate memory for JSON object");
10827 vty_out(vty,
10828 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10829 return;
10830 }
10831
10832 json_object_int_add(json, "vrfId",
10833 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10834 ? -1
10835 : (int64_t)bgp->vrf_id);
d62a17ae 10836 json_object_string_add(
10837 json, "vrfName",
10838 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10839 ? "Default"
10840 : bgp->name);
10841
10842 if (!is_first)
10843 vty_out(vty, ",\n");
10844 else
10845 is_first = 0;
10846
10847 vty_out(vty, "\"%s\":",
10848 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10849 ? "Default"
10850 : bgp->name);
10851 } else {
10852 vty_out(vty, "\nInstance %s:\n",
10853 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10854 ? "Default"
10855 : bgp->name);
10856 }
71aedaa3
DS
10857
10858 if (type == show_peer) {
10859 ret = str2sockunion(ip_str, &su);
10860 if (ret < 0)
10861 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10862 use_json, json);
10863 else
10864 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10865 use_json, json);
10866 } else {
10867 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10868 use_json, json);
10869 }
d62a17ae 10870 }
10871
10872 if (use_json)
10873 vty_out(vty, "}\n");
9f049418
DS
10874 else if (!nbr_output)
10875 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10876}
10877
10878static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10879 enum show_type type, const char *ip_str,
9f049418 10880 bool use_json)
d62a17ae 10881{
10882 int ret;
10883 struct bgp *bgp;
10884 union sockunion su;
10885 json_object *json = NULL;
10886
10887 if (name) {
10888 if (strmatch(name, "all")) {
71aedaa3
DS
10889 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10890 use_json);
d62a17ae 10891 return CMD_SUCCESS;
10892 } else {
10893 bgp = bgp_lookup_by_name(name);
10894 if (!bgp) {
10895 if (use_json) {
10896 json = json_object_new_object();
d62a17ae 10897 vty_out(vty, "%s\n",
10898 json_object_to_json_string_ext(
10899 json,
10900 JSON_C_TO_STRING_PRETTY));
10901 json_object_free(json);
10902 } else
10903 vty_out(vty,
9f049418 10904 "%% BGP instance not found\n");
d62a17ae 10905
10906 return CMD_WARNING;
10907 }
10908 }
10909 } else {
10910 bgp = bgp_get_default();
10911 }
10912
10913 if (bgp) {
10914 json = json_object_new_object();
10915 if (ip_str) {
10916 ret = str2sockunion(ip_str, &su);
10917 if (ret < 0)
10918 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10919 use_json, json);
10920 else
10921 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10922 use_json, json);
10923 } else {
10924 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10925 json);
10926 }
10927 json_object_free(json);
ca61fd25
DS
10928 } else {
10929 if (use_json)
10930 vty_out(vty, "{}\n");
10931 else
10932 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10933 }
10934
10935 return CMD_SUCCESS;
4fb25c53
DW
10936}
10937
716b2d8a 10938/* "show [ip] bgp neighbors" commands. */
718e3744 10939DEFUN (show_ip_bgp_neighbors,
10940 show_ip_bgp_neighbors_cmd,
24345e82 10941 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10942 SHOW_STR
10943 IP_STR
10944 BGP_STR
f2a8972b 10945 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10946 "Address Family\n"
10947 "Address Family\n"
718e3744 10948 "Detailed information on TCP and BGP neighbor connections\n"
10949 "Neighbor to display information about\n"
a80beece 10950 "Neighbor to display information about\n"
91d37724 10951 "Neighbor on BGP configured interface\n"
9973d184 10952 JSON_STR)
718e3744 10953{
d62a17ae 10954 char *vrf = NULL;
10955 char *sh_arg = NULL;
10956 enum show_type sh_type;
718e3744 10957
9f049418 10958 bool uj = use_json(argc, argv);
718e3744 10959
d62a17ae 10960 int idx = 0;
718e3744 10961
9a8bdf1c
PG
10962 /* [<vrf> VIEWVRFNAME] */
10963 if (argv_find(argv, argc, "vrf", &idx)) {
10964 vrf = argv[idx + 1]->arg;
10965 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10966 vrf = NULL;
10967 } else if (argv_find(argv, argc, "view", &idx))
10968 /* [<view> VIEWVRFNAME] */
d62a17ae 10969 vrf = argv[idx + 1]->arg;
718e3744 10970
d62a17ae 10971 idx++;
10972 if (argv_find(argv, argc, "A.B.C.D", &idx)
10973 || argv_find(argv, argc, "X:X::X:X", &idx)
10974 || argv_find(argv, argc, "WORD", &idx)) {
10975 sh_type = show_peer;
10976 sh_arg = argv[idx]->arg;
10977 } else
10978 sh_type = show_all;
856ca177 10979
d62a17ae 10980 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10981}
10982
716b2d8a 10983/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10984 paths' and `show ip mbgp paths'. Those functions results are the
10985 same.*/
f412b39a 10986DEFUN (show_ip_bgp_paths,
718e3744 10987 show_ip_bgp_paths_cmd,
46f296b4 10988 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10989 SHOW_STR
10990 IP_STR
10991 BGP_STR
46f296b4 10992 BGP_SAFI_HELP_STR
718e3744 10993 "Path information\n")
10994{
d62a17ae 10995 vty_out(vty, "Address Refcnt Path\n");
10996 aspath_print_all_vty(vty);
10997 return CMD_SUCCESS;
718e3744 10998}
10999
718e3744 11000#include "hash.h"
11001
d62a17ae 11002static void community_show_all_iterator(struct hash_backet *backet,
11003 struct vty *vty)
718e3744 11004{
d62a17ae 11005 struct community *com;
718e3744 11006
d62a17ae 11007 com = (struct community *)backet->data;
3f65c5b1 11008 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11009 community_str(com, false));
718e3744 11010}
11011
11012/* Show BGP's community internal data. */
f412b39a 11013DEFUN (show_ip_bgp_community_info,
718e3744 11014 show_ip_bgp_community_info_cmd,
bec37ba5 11015 "show [ip] bgp community-info",
718e3744 11016 SHOW_STR
11017 IP_STR
11018 BGP_STR
11019 "List all bgp community information\n")
11020{
d62a17ae 11021 vty_out(vty, "Address Refcnt Community\n");
718e3744 11022
d62a17ae 11023 hash_iterate(community_hash(),
11024 (void (*)(struct hash_backet *,
11025 void *))community_show_all_iterator,
11026 vty);
718e3744 11027
d62a17ae 11028 return CMD_SUCCESS;
718e3744 11029}
11030
d62a17ae 11031static void lcommunity_show_all_iterator(struct hash_backet *backet,
11032 struct vty *vty)
57d187bc 11033{
d62a17ae 11034 struct lcommunity *lcom;
57d187bc 11035
d62a17ae 11036 lcom = (struct lcommunity *)backet->data;
3f65c5b1 11037 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11038 lcommunity_str(lcom, false));
57d187bc
JS
11039}
11040
11041/* Show BGP's community internal data. */
11042DEFUN (show_ip_bgp_lcommunity_info,
11043 show_ip_bgp_lcommunity_info_cmd,
11044 "show ip bgp large-community-info",
11045 SHOW_STR
11046 IP_STR
11047 BGP_STR
11048 "List all bgp large-community information\n")
11049{
d62a17ae 11050 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11051
d62a17ae 11052 hash_iterate(lcommunity_hash(),
11053 (void (*)(struct hash_backet *,
11054 void *))lcommunity_show_all_iterator,
11055 vty);
57d187bc 11056
d62a17ae 11057 return CMD_SUCCESS;
57d187bc
JS
11058}
11059
11060
f412b39a 11061DEFUN (show_ip_bgp_attr_info,
718e3744 11062 show_ip_bgp_attr_info_cmd,
bec37ba5 11063 "show [ip] bgp attribute-info",
718e3744 11064 SHOW_STR
11065 IP_STR
11066 BGP_STR
11067 "List all bgp attribute information\n")
11068{
d62a17ae 11069 attr_show_all(vty);
11070 return CMD_SUCCESS;
718e3744 11071}
6b0655a2 11072
9f049418
DS
11073static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11074 safi_t safi, bool use_json)
53089bec 11075{
11076 struct bgp *bgp;
11077 struct listnode *node;
11078 char *vname;
11079 char buf1[INET6_ADDRSTRLEN];
11080 char *ecom_str;
11081 vpn_policy_direction_t dir;
11082
b46dfd20
DS
11083 if (use_json) {
11084 json_object *json = NULL;
11085 json_object *json_import_vrfs = NULL;
11086 json_object *json_export_vrfs = NULL;
11087
11088 json = json_object_new_object();
b46dfd20 11089
b46dfd20
DS
11090 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11091
53089bec 11092 if (!bgp) {
b46dfd20
DS
11093 vty_out(vty, "%s\n",
11094 json_object_to_json_string_ext(
11095 json,
11096 JSON_C_TO_STRING_PRETTY));
11097 json_object_free(json);
11098
53089bec 11099 return CMD_WARNING;
11100 }
b46dfd20 11101
94d4c685
DS
11102 /* Provide context for the block */
11103 json_object_string_add(json, "vrf", name ? name : "default");
11104 json_object_string_add(json, "afiSafi",
11105 afi_safi_print(afi, safi));
11106
b46dfd20
DS
11107 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11108 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11109 json_object_string_add(json, "importFromVrfs", "none");
11110 json_object_string_add(json, "importRts", "none");
11111 } else {
6ce24e52
DS
11112 json_import_vrfs = json_object_new_array();
11113
b46dfd20
DS
11114 for (ALL_LIST_ELEMENTS_RO(
11115 bgp->vpn_policy[afi].import_vrf,
11116 node, vname))
11117 json_object_array_add(json_import_vrfs,
11118 json_object_new_string(vname));
11119
11120 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11121 ecom_str = ecommunity_ecom2str(
11122 bgp->vpn_policy[afi].rtlist[dir],
11123 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11124 json_object_object_add(json, "importFromVrfs",
11125 json_import_vrfs);
11126 json_object_string_add(json, "importRts", ecom_str);
11127
11128 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11129 }
11130
11131 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11132 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11133 json_object_string_add(json, "exportToVrfs", "none");
11134 json_object_string_add(json, "routeDistinguisher",
11135 "none");
11136 json_object_string_add(json, "exportRts", "none");
11137 } else {
6ce24e52
DS
11138 json_export_vrfs = json_object_new_array();
11139
b46dfd20
DS
11140 for (ALL_LIST_ELEMENTS_RO(
11141 bgp->vpn_policy[afi].export_vrf,
11142 node, vname))
11143 json_object_array_add(json_export_vrfs,
11144 json_object_new_string(vname));
11145 json_object_object_add(json, "exportToVrfs",
11146 json_export_vrfs);
11147 json_object_string_add(json, "routeDistinguisher",
11148 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11149 buf1, RD_ADDRSTRLEN));
11150
11151 dir = BGP_VPN_POLICY_DIR_TOVPN;
11152 ecom_str = ecommunity_ecom2str(
11153 bgp->vpn_policy[afi].rtlist[dir],
11154 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11155 json_object_string_add(json, "exportRts", ecom_str);
11156
11157 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11158 }
11159
11160 vty_out(vty, "%s\n",
11161 json_object_to_json_string_ext(json,
11162 JSON_C_TO_STRING_PRETTY));
11163 json_object_free(json);
11164
53089bec 11165 } else {
b46dfd20
DS
11166 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11167
53089bec 11168 if (!bgp) {
b46dfd20 11169 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11170 return CMD_WARNING;
11171 }
53089bec 11172
b46dfd20
DS
11173 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11174 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11175 vty_out(vty,
11176 "This VRF is not importing %s routes from any other VRF\n",
11177 afi_safi_print(afi, safi));
11178 else {
11179 vty_out(vty,
11180 "This VRF is importing %s routes from the following VRFs:\n",
11181 afi_safi_print(afi, safi));
11182
11183 for (ALL_LIST_ELEMENTS_RO(
11184 bgp->vpn_policy[afi].import_vrf,
11185 node, vname))
11186 vty_out(vty, " %s\n", vname);
11187
11188 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11189 ecom_str = ecommunity_ecom2str(
11190 bgp->vpn_policy[afi].rtlist[dir],
11191 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11192 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11193
11194 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11195 }
53089bec 11196
b46dfd20
DS
11197 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11198 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11199 vty_out(vty,
11200 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11201 afi_safi_print(afi, safi));
b46dfd20
DS
11202 else {
11203 vty_out(vty,
04c9077f 11204 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11205 afi_safi_print(afi, safi));
b46dfd20
DS
11206
11207 for (ALL_LIST_ELEMENTS_RO(
11208 bgp->vpn_policy[afi].export_vrf,
11209 node, vname))
11210 vty_out(vty, " %s\n", vname);
11211
11212 vty_out(vty, "RD: %s\n",
11213 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11214 buf1, RD_ADDRSTRLEN));
11215
11216 dir = BGP_VPN_POLICY_DIR_TOVPN;
11217 ecom_str = ecommunity_ecom2str(
11218 bgp->vpn_policy[afi].rtlist[dir],
11219 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11220 vty_out(vty, "Export RT: %s\n", ecom_str);
04c9077f 11221 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11222 }
53089bec 11223 }
11224
11225 return CMD_SUCCESS;
11226}
11227
11228/* "show [ip] bgp route-leak" command. */
11229DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11230 show_ip_bgp_route_leak_cmd,
11231 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11232 SHOW_STR
11233 IP_STR
11234 BGP_STR
11235 BGP_INSTANCE_HELP_STR
11236 BGP_AFI_HELP_STR
11237 BGP_SAFI_HELP_STR
11238 "Route leaking information\n"
11239 JSON_STR)
53089bec 11240{
11241 char *vrf = NULL;
11242 afi_t afi = AFI_MAX;
11243 safi_t safi = SAFI_MAX;
11244
9f049418 11245 bool uj = use_json(argc, argv);
53089bec 11246 int idx = 0;
11247
11248 /* show [ip] bgp */
11249 if (argv_find(argv, argc, "ip", &idx)) {
11250 afi = AFI_IP;
11251 safi = SAFI_UNICAST;
11252 }
11253 /* [vrf VIEWVRFNAME] */
11254 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11255 vty_out(vty,
11256 "%% This command is not applicable to BGP views\n");
53089bec 11257 return CMD_WARNING;
11258 }
11259
9a8bdf1c
PG
11260 if (argv_find(argv, argc, "vrf", &idx)) {
11261 vrf = argv[idx + 1]->arg;
11262 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11263 vrf = NULL;
11264 }
53089bec 11265 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11266 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11267 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11268 }
11269
11270 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11271 vty_out(vty,
11272 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11273 return CMD_WARNING;
11274 }
11275
b46dfd20 11276 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
53089bec 11277}
11278
d62a17ae 11279static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11280 safi_t safi)
f186de26 11281{
d62a17ae 11282 struct listnode *node, *nnode;
11283 struct bgp *bgp;
f186de26 11284
d62a17ae 11285 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11286 vty_out(vty, "\nInstance %s:\n",
11287 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11288 ? "Default"
11289 : bgp->name);
11290 update_group_show(bgp, afi, safi, vty, 0);
11291 }
f186de26 11292}
11293
d62a17ae 11294static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11295 int safi, uint64_t subgrp_id)
4fb25c53 11296{
d62a17ae 11297 struct bgp *bgp;
4fb25c53 11298
d62a17ae 11299 if (name) {
11300 if (strmatch(name, "all")) {
11301 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11302 return CMD_SUCCESS;
11303 } else {
11304 bgp = bgp_lookup_by_name(name);
11305 }
11306 } else {
11307 bgp = bgp_get_default();
11308 }
4fb25c53 11309
d62a17ae 11310 if (bgp)
11311 update_group_show(bgp, afi, safi, vty, subgrp_id);
11312 return CMD_SUCCESS;
4fb25c53
DW
11313}
11314
8fe8a7f6
DS
11315DEFUN (show_ip_bgp_updgrps,
11316 show_ip_bgp_updgrps_cmd,
c1a44e43 11317 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11318 SHOW_STR
11319 IP_STR
11320 BGP_STR
11321 BGP_INSTANCE_HELP_STR
c9e571b4 11322 BGP_AFI_HELP_STR
9bedbb1e 11323 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11324 "Detailed info about dynamic update groups\n"
11325 "Specific subgroup to display detailed info for\n")
8386ac43 11326{
d62a17ae 11327 char *vrf = NULL;
11328 afi_t afi = AFI_IP6;
11329 safi_t safi = SAFI_UNICAST;
11330 uint64_t subgrp_id = 0;
11331
11332 int idx = 0;
11333
11334 /* show [ip] bgp */
11335 if (argv_find(argv, argc, "ip", &idx))
11336 afi = AFI_IP;
9a8bdf1c
PG
11337 /* [<vrf> VIEWVRFNAME] */
11338 if (argv_find(argv, argc, "vrf", &idx)) {
11339 vrf = argv[idx + 1]->arg;
11340 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11341 vrf = NULL;
11342 } else if (argv_find(argv, argc, "view", &idx))
11343 /* [<view> VIEWVRFNAME] */
11344 vrf = argv[idx + 1]->arg;
d62a17ae 11345 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11346 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11347 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11348 }
5bf15956 11349
d62a17ae 11350 /* get subgroup id, if provided */
11351 idx = argc - 1;
11352 if (argv[idx]->type == VARIABLE_TKN)
11353 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11354
d62a17ae 11355 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11356}
11357
f186de26 11358DEFUN (show_bgp_instance_all_ipv6_updgrps,
11359 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11360 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11361 SHOW_STR
716b2d8a 11362 IP_STR
f186de26 11363 BGP_STR
11364 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11365 "Detailed info about dynamic update groups\n")
f186de26 11366{
d62a17ae 11367 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11368 return CMD_SUCCESS;
f186de26 11369}
11370
5bf15956
DW
11371DEFUN (show_bgp_updgrps_stats,
11372 show_bgp_updgrps_stats_cmd,
716b2d8a 11373 "show [ip] bgp update-groups statistics",
3f9c7369 11374 SHOW_STR
716b2d8a 11375 IP_STR
3f9c7369 11376 BGP_STR
0c7b1b01 11377 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11378 "Statistics\n")
11379{
d62a17ae 11380 struct bgp *bgp;
3f9c7369 11381
d62a17ae 11382 bgp = bgp_get_default();
11383 if (bgp)
11384 update_group_show_stats(bgp, vty);
3f9c7369 11385
d62a17ae 11386 return CMD_SUCCESS;
3f9c7369
DS
11387}
11388
8386ac43 11389DEFUN (show_bgp_instance_updgrps_stats,
11390 show_bgp_instance_updgrps_stats_cmd,
18c57037 11391 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11392 SHOW_STR
716b2d8a 11393 IP_STR
8386ac43 11394 BGP_STR
11395 BGP_INSTANCE_HELP_STR
0c7b1b01 11396 "Detailed info about dynamic update groups\n"
8386ac43 11397 "Statistics\n")
11398{
d62a17ae 11399 int idx_word = 3;
11400 struct bgp *bgp;
8386ac43 11401
d62a17ae 11402 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11403 if (bgp)
11404 update_group_show_stats(bgp, vty);
8386ac43 11405
d62a17ae 11406 return CMD_SUCCESS;
8386ac43 11407}
11408
d62a17ae 11409static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11410 afi_t afi, safi_t safi,
11411 const char *what, uint64_t subgrp_id)
3f9c7369 11412{
d62a17ae 11413 struct bgp *bgp;
8386ac43 11414
d62a17ae 11415 if (name)
11416 bgp = bgp_lookup_by_name(name);
11417 else
11418 bgp = bgp_get_default();
8386ac43 11419
d62a17ae 11420 if (bgp) {
11421 if (!strcmp(what, "advertise-queue"))
11422 update_group_show_adj_queue(bgp, afi, safi, vty,
11423 subgrp_id);
11424 else if (!strcmp(what, "advertised-routes"))
11425 update_group_show_advertised(bgp, afi, safi, vty,
11426 subgrp_id);
11427 else if (!strcmp(what, "packet-queue"))
11428 update_group_show_packet_queue(bgp, afi, safi, vty,
11429 subgrp_id);
11430 }
3f9c7369
DS
11431}
11432
dc64bdec
QY
11433DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11434 show_ip_bgp_instance_updgrps_adj_s_cmd,
11435 "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",
11436 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11437 BGP_SAFI_HELP_STR
11438 "Detailed info about dynamic update groups\n"
11439 "Specific subgroup to display info for\n"
11440 "Advertisement queue\n"
11441 "Announced routes\n"
11442 "Packet queue\n")
3f9c7369 11443{
dc64bdec
QY
11444 uint64_t subgrp_id = 0;
11445 afi_t afiz;
11446 safi_t safiz;
11447 if (sgid)
11448 subgrp_id = strtoull(sgid, NULL, 10);
11449
11450 if (!ip && !afi)
11451 afiz = AFI_IP6;
11452 if (!ip && afi)
11453 afiz = bgp_vty_afi_from_str(afi);
11454 if (ip && !afi)
11455 afiz = AFI_IP;
11456 if (ip && afi) {
11457 afiz = bgp_vty_afi_from_str(afi);
11458 if (afiz != AFI_IP)
11459 vty_out(vty,
11460 "%% Cannot specify both 'ip' and 'ipv6'\n");
11461 return CMD_WARNING;
11462 }
d62a17ae 11463
dc64bdec 11464 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11465
dc64bdec 11466 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11467 return CMD_SUCCESS;
11468}
11469
d62a17ae 11470static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11471{
11472 struct listnode *node, *nnode;
11473 struct prefix *range;
11474 struct peer *conf;
11475 struct peer *peer;
11476 char buf[PREFIX2STR_BUFFER];
11477 afi_t afi;
11478 safi_t safi;
11479 const char *peer_status;
11480 const char *af_str;
11481 int lr_count;
11482 int dynamic;
11483 int af_cfgd;
11484
11485 conf = group->conf;
11486
11487 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11488 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11489 conf->as);
11490 } else if (conf->as_type == AS_INTERNAL) {
11491 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11492 group->bgp->as);
11493 } else {
11494 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11495 }
f14e6fdb 11496
d62a17ae 11497 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11498 vty_out(vty, " Peer-group type is internal\n");
11499 else
11500 vty_out(vty, " Peer-group type is external\n");
11501
11502 /* Display AFs configured. */
11503 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11504 FOREACH_AFI_SAFI (afi, safi) {
11505 if (conf->afc[afi][safi]) {
11506 af_cfgd = 1;
11507 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11508 }
05c7a1cc 11509 }
d62a17ae 11510 if (!af_cfgd)
11511 vty_out(vty, " none\n");
11512 else
11513 vty_out(vty, "\n");
11514
11515 /* Display listen ranges (for dynamic neighbors), if any */
11516 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11517 if (afi == AFI_IP)
11518 af_str = "IPv4";
11519 else if (afi == AFI_IP6)
11520 af_str = "IPv6";
11521 else
11522 af_str = "???";
11523 lr_count = listcount(group->listen_range[afi]);
11524 if (lr_count) {
11525 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11526 af_str);
11527
11528
11529 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11530 nnode, range)) {
11531 prefix2str(range, buf, sizeof(buf));
11532 vty_out(vty, " %s\n", buf);
11533 }
11534 }
11535 }
f14e6fdb 11536
d62a17ae 11537 /* Display group members and their status */
11538 if (listcount(group->peer)) {
11539 vty_out(vty, " Peer-group members:\n");
11540 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11541 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11542 peer_status = "Idle (Admin)";
11543 else if (CHECK_FLAG(peer->sflags,
11544 PEER_STATUS_PREFIX_OVERFLOW))
11545 peer_status = "Idle (PfxCt)";
11546 else
11547 peer_status = lookup_msg(bgp_status_msg,
11548 peer->status, NULL);
11549
11550 dynamic = peer_dynamic_neighbor(peer);
11551 vty_out(vty, " %s %s %s \n", peer->host,
11552 dynamic ? "(dynamic)" : "", peer_status);
11553 }
11554 }
f14e6fdb 11555
d62a17ae 11556 return CMD_SUCCESS;
11557}
11558
ff9959b0
QY
11559static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11560 const char *group_name)
d62a17ae 11561{
ff9959b0 11562 struct bgp *bgp;
d62a17ae 11563 struct listnode *node, *nnode;
11564 struct peer_group *group;
ff9959b0
QY
11565 bool found = false;
11566
11567 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11568
11569 if (!bgp) {
9f049418 11570 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
11571 return CMD_WARNING;
11572 }
d62a17ae 11573
11574 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11575 if (group_name) {
11576 if (strmatch(group->name, group_name)) {
d62a17ae 11577 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11578 found = true;
11579 break;
d62a17ae 11580 }
ff9959b0
QY
11581 } else {
11582 bgp_show_one_peer_group(vty, group);
d62a17ae 11583 }
f14e6fdb 11584 }
f14e6fdb 11585
ff9959b0 11586 if (group_name && !found)
d62a17ae 11587 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11588
d62a17ae 11589 return CMD_SUCCESS;
f14e6fdb
DS
11590}
11591
f14e6fdb
DS
11592DEFUN (show_ip_bgp_peer_groups,
11593 show_ip_bgp_peer_groups_cmd,
18c57037 11594 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11595 SHOW_STR
11596 IP_STR
11597 BGP_STR
8386ac43 11598 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11599 "Detailed information on BGP peer groups\n"
11600 "Peer group name\n")
f14e6fdb 11601{
d62a17ae 11602 char *vrf, *pg;
d62a17ae 11603 int idx = 0;
f14e6fdb 11604
a4d82a8a
PZ
11605 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11606 : NULL;
d62a17ae 11607 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11608
ff9959b0 11609 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11610}
3f9c7369 11611
d6e3c605 11612
718e3744 11613/* Redistribute VTY commands. */
11614
718e3744 11615DEFUN (bgp_redistribute_ipv4,
11616 bgp_redistribute_ipv4_cmd,
40d1cbfb 11617 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11618 "Redistribute information from another routing protocol\n"
ab0181ee 11619 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11620{
d62a17ae 11621 VTY_DECLVAR_CONTEXT(bgp, bgp);
11622 int idx_protocol = 1;
11623 int type;
718e3744 11624
d62a17ae 11625 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11626 if (type < 0) {
11627 vty_out(vty, "%% Invalid route type\n");
11628 return CMD_WARNING_CONFIG_FAILED;
11629 }
7f323236 11630
d62a17ae 11631 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11632 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11633}
11634
d62a17ae 11635ALIAS_HIDDEN(
11636 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11637 "redistribute " FRR_IP_REDIST_STR_BGPD,
11638 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11639
718e3744 11640DEFUN (bgp_redistribute_ipv4_rmap,
11641 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11642 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11643 "Redistribute information from another routing protocol\n"
ab0181ee 11644 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11645 "Route map reference\n"
11646 "Pointer to route-map entries\n")
11647{
d62a17ae 11648 VTY_DECLVAR_CONTEXT(bgp, bgp);
11649 int idx_protocol = 1;
11650 int idx_word = 3;
11651 int type;
11652 struct bgp_redist *red;
e923dd62 11653 bool changed;
718e3744 11654
d62a17ae 11655 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11656 if (type < 0) {
11657 vty_out(vty, "%% Invalid route type\n");
11658 return CMD_WARNING_CONFIG_FAILED;
11659 }
718e3744 11660
d62a17ae 11661 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11662 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11663 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 11664}
11665
d62a17ae 11666ALIAS_HIDDEN(
11667 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11668 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11669 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11670 "Route map reference\n"
11671 "Pointer to route-map entries\n")
596c17ba 11672
718e3744 11673DEFUN (bgp_redistribute_ipv4_metric,
11674 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11675 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11676 "Redistribute information from another routing protocol\n"
ab0181ee 11677 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11678 "Metric for redistributed routes\n"
11679 "Default metric\n")
11680{
d62a17ae 11681 VTY_DECLVAR_CONTEXT(bgp, bgp);
11682 int idx_protocol = 1;
11683 int idx_number = 3;
11684 int type;
d7c0a89a 11685 uint32_t metric;
d62a17ae 11686 struct bgp_redist *red;
e923dd62 11687 bool changed;
d62a17ae 11688
11689 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11690 if (type < 0) {
11691 vty_out(vty, "%% Invalid route type\n");
11692 return CMD_WARNING_CONFIG_FAILED;
11693 }
11694 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11695
11696 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11697 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11698 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11699}
11700
11701ALIAS_HIDDEN(
11702 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11703 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11704 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11705 "Metric for redistributed routes\n"
11706 "Default metric\n")
596c17ba 11707
718e3744 11708DEFUN (bgp_redistribute_ipv4_rmap_metric,
11709 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11710 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11711 "Redistribute information from another routing protocol\n"
ab0181ee 11712 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11713 "Route map reference\n"
11714 "Pointer to route-map entries\n"
11715 "Metric for redistributed routes\n"
11716 "Default metric\n")
11717{
d62a17ae 11718 VTY_DECLVAR_CONTEXT(bgp, bgp);
11719 int idx_protocol = 1;
11720 int idx_word = 3;
11721 int idx_number = 5;
11722 int type;
d7c0a89a 11723 uint32_t metric;
d62a17ae 11724 struct bgp_redist *red;
e923dd62 11725 bool changed;
d62a17ae 11726
11727 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11728 if (type < 0) {
11729 vty_out(vty, "%% Invalid route type\n");
11730 return CMD_WARNING_CONFIG_FAILED;
11731 }
11732 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11733
11734 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11735 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11736 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11737 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11738}
11739
11740ALIAS_HIDDEN(
11741 bgp_redistribute_ipv4_rmap_metric,
11742 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11743 "redistribute " FRR_IP_REDIST_STR_BGPD
11744 " route-map WORD metric (0-4294967295)",
11745 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11746 "Route map reference\n"
11747 "Pointer to route-map entries\n"
11748 "Metric for redistributed routes\n"
11749 "Default metric\n")
596c17ba 11750
718e3744 11751DEFUN (bgp_redistribute_ipv4_metric_rmap,
11752 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11753 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11754 "Redistribute information from another routing protocol\n"
ab0181ee 11755 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11756 "Metric for redistributed routes\n"
11757 "Default metric\n"
11758 "Route map reference\n"
11759 "Pointer to route-map entries\n")
11760{
d62a17ae 11761 VTY_DECLVAR_CONTEXT(bgp, bgp);
11762 int idx_protocol = 1;
11763 int idx_number = 3;
11764 int idx_word = 5;
11765 int type;
d7c0a89a 11766 uint32_t metric;
d62a17ae 11767 struct bgp_redist *red;
e923dd62 11768 bool changed;
d62a17ae 11769
11770 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11771 if (type < 0) {
11772 vty_out(vty, "%% Invalid route type\n");
11773 return CMD_WARNING_CONFIG_FAILED;
11774 }
11775 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11776
11777 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11778 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11779 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11780 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11781}
11782
11783ALIAS_HIDDEN(
11784 bgp_redistribute_ipv4_metric_rmap,
11785 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11786 "redistribute " FRR_IP_REDIST_STR_BGPD
11787 " metric (0-4294967295) route-map WORD",
11788 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11789 "Metric for redistributed routes\n"
11790 "Default metric\n"
11791 "Route map reference\n"
11792 "Pointer to route-map entries\n")
596c17ba 11793
7c8ff89e
DS
11794DEFUN (bgp_redistribute_ipv4_ospf,
11795 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11796 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11797 "Redistribute information from another routing protocol\n"
11798 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11799 "Non-main Kernel Routing Table\n"
11800 "Instance ID/Table ID\n")
7c8ff89e 11801{
d62a17ae 11802 VTY_DECLVAR_CONTEXT(bgp, bgp);
11803 int idx_ospf_table = 1;
11804 int idx_number = 2;
d7c0a89a
QY
11805 unsigned short instance;
11806 unsigned short protocol;
7c8ff89e 11807
d62a17ae 11808 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11809
d62a17ae 11810 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11811 protocol = ZEBRA_ROUTE_OSPF;
11812 else
11813 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11814
d62a17ae 11815 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11816 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
11817}
11818
d62a17ae 11819ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11820 "redistribute <ospf|table> (1-65535)",
11821 "Redistribute information from another routing protocol\n"
11822 "Open Shortest Path First (OSPFv2)\n"
11823 "Non-main Kernel Routing Table\n"
11824 "Instance ID/Table ID\n")
596c17ba 11825
7c8ff89e
DS
11826DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11827 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11828 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11829 "Redistribute information from another routing protocol\n"
11830 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11831 "Non-main Kernel Routing Table\n"
11832 "Instance ID/Table ID\n"
7c8ff89e
DS
11833 "Route map reference\n"
11834 "Pointer to route-map entries\n")
11835{
d62a17ae 11836 VTY_DECLVAR_CONTEXT(bgp, bgp);
11837 int idx_ospf_table = 1;
11838 int idx_number = 2;
11839 int idx_word = 4;
11840 struct bgp_redist *red;
d7c0a89a 11841 unsigned short instance;
d62a17ae 11842 int protocol;
e923dd62 11843 bool changed;
d62a17ae 11844
11845 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11846 protocol = ZEBRA_ROUTE_OSPF;
11847 else
11848 protocol = ZEBRA_ROUTE_TABLE;
11849
11850 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11851 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11852 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11853 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11854}
11855
11856ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11857 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11858 "redistribute <ospf|table> (1-65535) route-map WORD",
11859 "Redistribute information from another routing protocol\n"
11860 "Open Shortest Path First (OSPFv2)\n"
11861 "Non-main Kernel Routing Table\n"
11862 "Instance ID/Table ID\n"
11863 "Route map reference\n"
11864 "Pointer to route-map entries\n")
596c17ba 11865
7c8ff89e
DS
11866DEFUN (bgp_redistribute_ipv4_ospf_metric,
11867 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11868 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11869 "Redistribute information from another routing protocol\n"
11870 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11871 "Non-main Kernel Routing Table\n"
11872 "Instance ID/Table ID\n"
7c8ff89e
DS
11873 "Metric for redistributed routes\n"
11874 "Default metric\n")
11875{
d62a17ae 11876 VTY_DECLVAR_CONTEXT(bgp, bgp);
11877 int idx_ospf_table = 1;
11878 int idx_number = 2;
11879 int idx_number_2 = 4;
d7c0a89a 11880 uint32_t metric;
d62a17ae 11881 struct bgp_redist *red;
d7c0a89a 11882 unsigned short instance;
d62a17ae 11883 int protocol;
e923dd62 11884 bool changed;
d62a17ae 11885
11886 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11887 protocol = ZEBRA_ROUTE_OSPF;
11888 else
11889 protocol = ZEBRA_ROUTE_TABLE;
11890
11891 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11892 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11893
11894 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11895 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11896 metric);
11897 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11898}
11899
11900ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11901 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11902 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11903 "Redistribute information from another routing protocol\n"
11904 "Open Shortest Path First (OSPFv2)\n"
11905 "Non-main Kernel Routing Table\n"
11906 "Instance ID/Table ID\n"
11907 "Metric for redistributed routes\n"
11908 "Default metric\n")
596c17ba 11909
7c8ff89e
DS
11910DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11911 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11912 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11913 "Redistribute information from another routing protocol\n"
11914 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11915 "Non-main Kernel Routing Table\n"
11916 "Instance ID/Table ID\n"
7c8ff89e
DS
11917 "Route map reference\n"
11918 "Pointer to route-map entries\n"
11919 "Metric for redistributed routes\n"
11920 "Default metric\n")
11921{
d62a17ae 11922 VTY_DECLVAR_CONTEXT(bgp, bgp);
11923 int idx_ospf_table = 1;
11924 int idx_number = 2;
11925 int idx_word = 4;
11926 int idx_number_2 = 6;
d7c0a89a 11927 uint32_t metric;
d62a17ae 11928 struct bgp_redist *red;
d7c0a89a 11929 unsigned short instance;
d62a17ae 11930 int protocol;
e923dd62 11931 bool changed;
d62a17ae 11932
11933 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11934 protocol = ZEBRA_ROUTE_OSPF;
11935 else
11936 protocol = ZEBRA_ROUTE_TABLE;
11937
11938 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11939 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11940
11941 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11942 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11943 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11944 metric);
11945 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11946}
11947
11948ALIAS_HIDDEN(
11949 bgp_redistribute_ipv4_ospf_rmap_metric,
11950 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11951 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11952 "Redistribute information from another routing protocol\n"
11953 "Open Shortest Path First (OSPFv2)\n"
11954 "Non-main Kernel Routing Table\n"
11955 "Instance ID/Table ID\n"
11956 "Route map reference\n"
11957 "Pointer to route-map entries\n"
11958 "Metric for redistributed routes\n"
11959 "Default metric\n")
596c17ba 11960
7c8ff89e
DS
11961DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11962 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11963 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11964 "Redistribute information from another routing protocol\n"
11965 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11966 "Non-main Kernel Routing Table\n"
11967 "Instance ID/Table ID\n"
7c8ff89e
DS
11968 "Metric for redistributed routes\n"
11969 "Default metric\n"
11970 "Route map reference\n"
11971 "Pointer to route-map entries\n")
11972{
d62a17ae 11973 VTY_DECLVAR_CONTEXT(bgp, bgp);
11974 int idx_ospf_table = 1;
11975 int idx_number = 2;
11976 int idx_number_2 = 4;
11977 int idx_word = 6;
d7c0a89a 11978 uint32_t metric;
d62a17ae 11979 struct bgp_redist *red;
d7c0a89a 11980 unsigned short instance;
d62a17ae 11981 int protocol;
e923dd62 11982 bool changed;
d62a17ae 11983
11984 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11985 protocol = ZEBRA_ROUTE_OSPF;
11986 else
11987 protocol = ZEBRA_ROUTE_TABLE;
11988
11989 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11990 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11991
11992 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11993 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11994 metric);
11995 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11996 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 11997}
11998
11999ALIAS_HIDDEN(
12000 bgp_redistribute_ipv4_ospf_metric_rmap,
12001 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12002 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12003 "Redistribute information from another routing protocol\n"
12004 "Open Shortest Path First (OSPFv2)\n"
12005 "Non-main Kernel Routing Table\n"
12006 "Instance ID/Table ID\n"
12007 "Metric for redistributed routes\n"
12008 "Default metric\n"
12009 "Route map reference\n"
12010 "Pointer to route-map entries\n")
596c17ba 12011
7c8ff89e
DS
12012DEFUN (no_bgp_redistribute_ipv4_ospf,
12013 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 12014 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
12015 NO_STR
12016 "Redistribute information from another routing protocol\n"
12017 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12018 "Non-main Kernel Routing Table\n"
31500417
DW
12019 "Instance ID/Table ID\n"
12020 "Metric for redistributed routes\n"
12021 "Default metric\n"
12022 "Route map reference\n"
12023 "Pointer to route-map entries\n")
7c8ff89e 12024{
d62a17ae 12025 VTY_DECLVAR_CONTEXT(bgp, bgp);
12026 int idx_ospf_table = 2;
12027 int idx_number = 3;
d7c0a89a 12028 unsigned short instance;
d62a17ae 12029 int protocol;
12030
12031 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12032 protocol = ZEBRA_ROUTE_OSPF;
12033 else
12034 protocol = ZEBRA_ROUTE_TABLE;
12035
12036 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12037 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12038}
12039
12040ALIAS_HIDDEN(
12041 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12042 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12043 NO_STR
12044 "Redistribute information from another routing protocol\n"
12045 "Open Shortest Path First (OSPFv2)\n"
12046 "Non-main Kernel Routing Table\n"
12047 "Instance ID/Table ID\n"
12048 "Metric for redistributed routes\n"
12049 "Default metric\n"
12050 "Route map reference\n"
12051 "Pointer to route-map entries\n")
596c17ba 12052
718e3744 12053DEFUN (no_bgp_redistribute_ipv4,
12054 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 12055 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12056 NO_STR
12057 "Redistribute information from another routing protocol\n"
3b14d86e 12058 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12059 "Metric for redistributed routes\n"
12060 "Default metric\n"
12061 "Route map reference\n"
12062 "Pointer to route-map entries\n")
718e3744 12063{
d62a17ae 12064 VTY_DECLVAR_CONTEXT(bgp, bgp);
12065 int idx_protocol = 2;
12066 int type;
12067
12068 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12069 if (type < 0) {
12070 vty_out(vty, "%% Invalid route type\n");
12071 return CMD_WARNING_CONFIG_FAILED;
12072 }
12073 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12074}
12075
12076ALIAS_HIDDEN(
12077 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12078 "no redistribute " FRR_IP_REDIST_STR_BGPD
12079 " [metric (0-4294967295)] [route-map WORD]",
12080 NO_STR
12081 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12082 "Metric for redistributed routes\n"
12083 "Default metric\n"
12084 "Route map reference\n"
12085 "Pointer to route-map entries\n")
596c17ba 12086
718e3744 12087DEFUN (bgp_redistribute_ipv6,
12088 bgp_redistribute_ipv6_cmd,
40d1cbfb 12089 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12090 "Redistribute information from another routing protocol\n"
ab0181ee 12091 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12092{
d62a17ae 12093 VTY_DECLVAR_CONTEXT(bgp, bgp);
12094 int idx_protocol = 1;
12095 int type;
718e3744 12096
d62a17ae 12097 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12098 if (type < 0) {
12099 vty_out(vty, "%% Invalid route type\n");
12100 return CMD_WARNING_CONFIG_FAILED;
12101 }
718e3744 12102
d62a17ae 12103 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12104 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12105}
12106
12107DEFUN (bgp_redistribute_ipv6_rmap,
12108 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12109 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12110 "Redistribute information from another routing protocol\n"
ab0181ee 12111 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12112 "Route map reference\n"
12113 "Pointer to route-map entries\n")
12114{
d62a17ae 12115 VTY_DECLVAR_CONTEXT(bgp, bgp);
12116 int idx_protocol = 1;
12117 int idx_word = 3;
12118 int type;
12119 struct bgp_redist *red;
e923dd62 12120 bool changed;
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 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12129 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12130 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12131}
12132
12133DEFUN (bgp_redistribute_ipv6_metric,
12134 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12135 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12136 "Redistribute information from another routing protocol\n"
ab0181ee 12137 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12138 "Metric for redistributed routes\n"
12139 "Default metric\n")
12140{
d62a17ae 12141 VTY_DECLVAR_CONTEXT(bgp, bgp);
12142 int idx_protocol = 1;
12143 int idx_number = 3;
12144 int type;
d7c0a89a 12145 uint32_t metric;
d62a17ae 12146 struct bgp_redist *red;
e923dd62 12147 bool changed;
d62a17ae 12148
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 }
12154 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12155
d62a17ae 12156 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12157 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12158 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12159}
12160
12161DEFUN (bgp_redistribute_ipv6_rmap_metric,
12162 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12163 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12164 "Redistribute information from another routing protocol\n"
ab0181ee 12165 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12166 "Route map reference\n"
12167 "Pointer to route-map entries\n"
12168 "Metric for redistributed routes\n"
12169 "Default metric\n")
12170{
d62a17ae 12171 VTY_DECLVAR_CONTEXT(bgp, bgp);
12172 int idx_protocol = 1;
12173 int idx_word = 3;
12174 int idx_number = 5;
12175 int type;
d7c0a89a 12176 uint32_t metric;
d62a17ae 12177 struct bgp_redist *red;
e923dd62 12178 bool changed;
d62a17ae 12179
12180 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12181 if (type < 0) {
12182 vty_out(vty, "%% Invalid route type\n");
12183 return CMD_WARNING_CONFIG_FAILED;
12184 }
12185 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12186
d62a17ae 12187 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12188 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12189 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12190 metric);
12191 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12192}
12193
12194DEFUN (bgp_redistribute_ipv6_metric_rmap,
12195 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12196 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12197 "Redistribute information from another routing protocol\n"
ab0181ee 12198 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12199 "Metric for redistributed routes\n"
12200 "Default metric\n"
12201 "Route map reference\n"
12202 "Pointer to route-map entries\n")
12203{
d62a17ae 12204 VTY_DECLVAR_CONTEXT(bgp, bgp);
12205 int idx_protocol = 1;
12206 int idx_number = 3;
12207 int idx_word = 5;
12208 int type;
d7c0a89a 12209 uint32_t metric;
d62a17ae 12210 struct bgp_redist *red;
e923dd62 12211 bool changed;
d62a17ae 12212
12213 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12214 if (type < 0) {
12215 vty_out(vty, "%% Invalid route type\n");
12216 return CMD_WARNING_CONFIG_FAILED;
12217 }
12218 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12219
d62a17ae 12220 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12221 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12222 metric);
12223 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12224 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12225}
12226
12227DEFUN (no_bgp_redistribute_ipv6,
12228 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12229 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12230 NO_STR
12231 "Redistribute information from another routing protocol\n"
3b14d86e 12232 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12233 "Metric for redistributed routes\n"
12234 "Default metric\n"
12235 "Route map reference\n"
12236 "Pointer to route-map entries\n")
718e3744 12237{
d62a17ae 12238 VTY_DECLVAR_CONTEXT(bgp, bgp);
12239 int idx_protocol = 2;
12240 int type;
718e3744 12241
d62a17ae 12242 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12243 if (type < 0) {
12244 vty_out(vty, "%% Invalid route type\n");
12245 return CMD_WARNING_CONFIG_FAILED;
12246 }
718e3744 12247
d62a17ae 12248 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12249}
12250
2b791107 12251void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12252 safi_t safi)
d62a17ae 12253{
12254 int i;
12255
12256 /* Unicast redistribution only. */
12257 if (safi != SAFI_UNICAST)
2b791107 12258 return;
d62a17ae 12259
12260 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12261 /* Redistribute BGP does not make sense. */
12262 if (i != ZEBRA_ROUTE_BGP) {
12263 struct list *red_list;
12264 struct listnode *node;
12265 struct bgp_redist *red;
12266
12267 red_list = bgp->redist[afi][i];
12268 if (!red_list)
12269 continue;
12270
12271 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12272 /* "redistribute" configuration. */
12273 vty_out(vty, " redistribute %s",
12274 zebra_route_string(i));
12275 if (red->instance)
12276 vty_out(vty, " %d", red->instance);
12277 if (red->redist_metric_flag)
12278 vty_out(vty, " metric %u",
12279 red->redist_metric);
12280 if (red->rmap.name)
12281 vty_out(vty, " route-map %s",
12282 red->rmap.name);
12283 vty_out(vty, "\n");
12284 }
12285 }
12286 }
718e3744 12287}
6b0655a2 12288
b9c7bc5a
PZ
12289/* This is part of the address-family block (unicast only) */
12290void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12291 afi_t afi)
12292{
b9c7bc5a 12293 int indent = 2;
ddb5b488 12294
bb4f6190
DS
12295 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12296 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12297 bgp->vpn_policy[afi]
12298 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12299
12a844a5
DS
12300 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12301 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12302 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12303 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12304 return;
12305
e70e9f8e
PZ
12306 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12307 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12308
12309 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12310
12311 } else {
12312 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12313 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12314 bgp->vpn_policy[afi].tovpn_label);
12315 }
ddb5b488
PZ
12316 }
12317 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12318 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12319 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12320 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12321 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12322 sizeof(buf)));
12323 }
12324 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12325 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12326
12327 char buf[PREFIX_STRLEN];
12328 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12329 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12330 sizeof(buf))) {
12331
b9c7bc5a
PZ
12332 vty_out(vty, "%*snexthop vpn export %s\n",
12333 indent, "", buf);
ddb5b488
PZ
12334 }
12335 }
12336 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12337 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12338 && ecommunity_cmp(
12339 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12340 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12341
12342 char *b = ecommunity_ecom2str(
12343 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12344 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12345 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12346 XFREE(MTYPE_ECOMMUNITY_STR, b);
12347 } else {
12348 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12349 char *b = ecommunity_ecom2str(
12350 bgp->vpn_policy[afi]
12351 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12352 ECOMMUNITY_FORMAT_ROUTE_MAP,
12353 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12354 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12355 XFREE(MTYPE_ECOMMUNITY_STR, b);
12356 }
12357 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12358 char *b = ecommunity_ecom2str(
12359 bgp->vpn_policy[afi]
12360 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12361 ECOMMUNITY_FORMAT_ROUTE_MAP,
12362 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12363 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12364 XFREE(MTYPE_ECOMMUNITY_STR, b);
12365 }
12366 }
bb4f6190
DS
12367
12368 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12369 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12370 bgp->vpn_policy[afi]
12371 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12372
301ad80a
PG
12373 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12374 char *b = ecommunity_ecom2str(
12375 bgp->vpn_policy[afi]
12376 .import_redirect_rtlist,
12377 ECOMMUNITY_FORMAT_ROUTE_MAP,
12378 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12379
301ad80a
PG
12380 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12381 XFREE(MTYPE_ECOMMUNITY_STR, b);
12382 }
ddb5b488
PZ
12383}
12384
12385
718e3744 12386/* BGP node structure. */
d62a17ae 12387static struct cmd_node bgp_node = {
9d303b37 12388 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12389};
12390
d62a17ae 12391static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12392 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12393};
12394
d62a17ae 12395static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12396 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12397};
12398
d62a17ae 12399static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12400 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12401};
12402
d62a17ae 12403static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12404 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12405};
12406
d62a17ae 12407static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12408 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12409};
12410
d62a17ae 12411static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12412 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12413};
12414
d62a17ae 12415static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12416 "%s(config-router-af)# ", 1};
6b0655a2 12417
d62a17ae 12418static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12419 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12420
d62a17ae 12421static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12422 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12423
d62a17ae 12424static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12425 "%s(config-router-af-vni)# ", 1};
90e60aa7 12426
7c40bf39 12427static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12428 "%s(config-router-af)# ", 1};
12429
12430static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12431 "%s(config-router-af-vpnv6)# ", 1};
12432
d62a17ae 12433static void community_list_vty(void);
1f8ae70b 12434
d62a17ae 12435static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12436{
d62a17ae 12437 struct bgp *bgp;
12438 struct peer *peer;
d62a17ae 12439 struct listnode *lnbgp, *lnpeer;
b8a815e5 12440
d62a17ae 12441 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12442 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12443 /* only provide suggestions on the appropriate input
12444 * token type,
12445 * they'll otherwise show up multiple times */
12446 enum cmd_token_type match_type;
12447 char *name = peer->host;
d48ed3e0 12448
d62a17ae 12449 if (peer->conf_if) {
12450 match_type = VARIABLE_TKN;
12451 name = peer->conf_if;
12452 } else if (strchr(peer->host, ':'))
12453 match_type = IPV6_TKN;
12454 else
12455 match_type = IPV4_TKN;
d48ed3e0 12456
d62a17ae 12457 if (token->type != match_type)
12458 continue;
d48ed3e0 12459
d62a17ae 12460 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12461 }
d62a17ae 12462 }
b8a815e5
DL
12463}
12464
12465static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12466 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12467 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12468 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12469 {.completions = NULL}};
12470
47a306a0
DS
12471static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12472{
12473 struct bgp *bgp;
12474 struct peer_group *group;
12475 struct listnode *lnbgp, *lnpeer;
12476
12477 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12478 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12479 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12480 group->name));
12481 }
12482}
12483
12484static const struct cmd_variable_handler bgp_var_peergroup[] = {
12485 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12486 {.completions = NULL} };
12487
d62a17ae 12488void bgp_vty_init(void)
12489{
12490 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12491 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12492
12493 /* Install bgp top node. */
12494 install_node(&bgp_node, bgp_config_write);
12495 install_node(&bgp_ipv4_unicast_node, NULL);
12496 install_node(&bgp_ipv4_multicast_node, NULL);
12497 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12498 install_node(&bgp_ipv6_unicast_node, NULL);
12499 install_node(&bgp_ipv6_multicast_node, NULL);
12500 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12501 install_node(&bgp_vpnv4_node, NULL);
12502 install_node(&bgp_vpnv6_node, NULL);
12503 install_node(&bgp_evpn_node, NULL);
12504 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12505 install_node(&bgp_flowspecv4_node, NULL);
12506 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12507
12508 /* Install default VTY commands to new nodes. */
12509 install_default(BGP_NODE);
12510 install_default(BGP_IPV4_NODE);
12511 install_default(BGP_IPV4M_NODE);
12512 install_default(BGP_IPV4L_NODE);
12513 install_default(BGP_IPV6_NODE);
12514 install_default(BGP_IPV6M_NODE);
12515 install_default(BGP_IPV6L_NODE);
12516 install_default(BGP_VPNV4_NODE);
12517 install_default(BGP_VPNV6_NODE);
7c40bf39 12518 install_default(BGP_FLOWSPECV4_NODE);
12519 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12520 install_default(BGP_EVPN_NODE);
12521 install_default(BGP_EVPN_VNI_NODE);
12522
12523 /* "bgp multiple-instance" commands. */
12524 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12525 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12526
12527 /* "bgp config-type" commands. */
12528 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12529 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12530
12531 /* bgp route-map delay-timer commands. */
12532 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12533 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12534
12535 /* Dummy commands (Currently not supported) */
12536 install_element(BGP_NODE, &no_synchronization_cmd);
12537 install_element(BGP_NODE, &no_auto_summary_cmd);
12538
12539 /* "router bgp" commands. */
12540 install_element(CONFIG_NODE, &router_bgp_cmd);
12541
12542 /* "no router bgp" commands. */
12543 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12544
12545 /* "bgp router-id" commands. */
12546 install_element(BGP_NODE, &bgp_router_id_cmd);
12547 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12548
12549 /* "bgp cluster-id" commands. */
12550 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12551 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12552
12553 /* "bgp confederation" commands. */
12554 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12555 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12556
12557 /* "bgp confederation peers" commands. */
12558 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12559 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12560
12561 /* bgp max-med command */
12562 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12563 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12564 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12565 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12566 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12567
12568 /* bgp disable-ebgp-connected-nh-check */
12569 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12570 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12571
12572 /* bgp update-delay command */
12573 install_element(BGP_NODE, &bgp_update_delay_cmd);
12574 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12575 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12576
12577 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12578 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12579 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12580 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12581
12582 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12583 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12584
12585 /* "maximum-paths" commands. */
12586 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12587 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12588 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12589 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12590 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12591 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12592 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12593 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12594 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12595 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12596 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12597 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12598 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12599 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12600 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12601
12602 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12603 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12604 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12605 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12606 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12607
12608 /* "timers bgp" commands. */
12609 install_element(BGP_NODE, &bgp_timers_cmd);
12610 install_element(BGP_NODE, &no_bgp_timers_cmd);
12611
12612 /* route-map delay-timer commands - per instance for backwards compat.
12613 */
12614 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12615 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12616
12617 /* "bgp client-to-client reflection" commands */
12618 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12619 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12620
12621 /* "bgp always-compare-med" commands */
12622 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12623 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12624
12625 /* "bgp deterministic-med" commands */
12626 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12627 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12628
12629 /* "bgp graceful-restart" commands */
12630 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12631 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12632 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12633 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12634 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12635 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12636
12637 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12638 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12639
7f323236
DW
12640 /* "bgp graceful-shutdown" commands */
12641 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12642 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12643
d62a17ae 12644 /* "bgp fast-external-failover" commands */
12645 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12646 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12647
12648 /* "bgp enforce-first-as" commands */
12649 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 12650
12651 /* "bgp bestpath compare-routerid" commands */
12652 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12653 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12654
12655 /* "bgp bestpath as-path ignore" commands */
12656 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12657 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12658
12659 /* "bgp bestpath as-path confed" commands */
12660 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12661 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12662
12663 /* "bgp bestpath as-path multipath-relax" commands */
12664 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12665 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12666
12667 /* "bgp log-neighbor-changes" commands */
12668 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12669 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12670
12671 /* "bgp bestpath med" commands */
12672 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12673 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12674
12675 /* "no bgp default ipv4-unicast" commands. */
12676 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12677 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12678
12679 /* "bgp network import-check" commands. */
12680 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12681 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12682 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12683
12684 /* "bgp default local-preference" commands. */
12685 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12686 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12687
12688 /* bgp default show-hostname */
12689 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12690 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12691
12692 /* "bgp default subgroup-pkt-queue-max" commands. */
12693 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12694 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12695
12696 /* bgp ibgp-allow-policy-mods command */
12697 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12698 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12699
12700 /* "bgp listen limit" commands. */
12701 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12702 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12703
12704 /* "bgp listen range" commands. */
12705 install_element(BGP_NODE, &bgp_listen_range_cmd);
12706 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12707
8175f54a 12708 /* "bgp default shutdown" command */
f26845f9
QY
12709 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12710
d62a17ae 12711 /* "neighbor remote-as" commands. */
12712 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12713 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12714 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12715 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12716 install_element(BGP_NODE,
12717 &neighbor_interface_v6only_config_remote_as_cmd);
12718 install_element(BGP_NODE, &no_neighbor_cmd);
12719 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12720
12721 /* "neighbor peer-group" commands. */
12722 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12723 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12724 install_element(BGP_NODE,
12725 &no_neighbor_interface_peer_group_remote_as_cmd);
12726
12727 /* "neighbor local-as" commands. */
12728 install_element(BGP_NODE, &neighbor_local_as_cmd);
12729 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12730 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12731 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12732
12733 /* "neighbor solo" commands. */
12734 install_element(BGP_NODE, &neighbor_solo_cmd);
12735 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12736
12737 /* "neighbor password" commands. */
12738 install_element(BGP_NODE, &neighbor_password_cmd);
12739 install_element(BGP_NODE, &no_neighbor_password_cmd);
12740
12741 /* "neighbor activate" commands. */
12742 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12743 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12744 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12745 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12746 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12747 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12748 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12749 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12750 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12751 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12752 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12753 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12754
12755 /* "no neighbor activate" commands. */
12756 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12757 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12758 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12759 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12760 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12761 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12762 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12763 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12764 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12765 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12766 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12767 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12768
12769 /* "neighbor peer-group" set commands. */
12770 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12771 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12772 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12773 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12774 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12775 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12776 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12777 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12778 install_element(BGP_FLOWSPECV4_NODE,
12779 &neighbor_set_peer_group_hidden_cmd);
12780 install_element(BGP_FLOWSPECV6_NODE,
12781 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12782
12783 /* "no neighbor peer-group unset" commands. */
12784 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12785 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12786 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12787 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12788 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12789 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12790 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12791 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12792 install_element(BGP_FLOWSPECV4_NODE,
12793 &no_neighbor_set_peer_group_hidden_cmd);
12794 install_element(BGP_FLOWSPECV6_NODE,
12795 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12796
12797 /* "neighbor softreconfiguration inbound" commands.*/
12798 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12799 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12800 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12801 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12802 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12803 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12804 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12805 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12806 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12807 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12808 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12809 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12810 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12811 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12812 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12813 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12814 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12815 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12816 install_element(BGP_FLOWSPECV4_NODE,
12817 &neighbor_soft_reconfiguration_cmd);
12818 install_element(BGP_FLOWSPECV4_NODE,
12819 &no_neighbor_soft_reconfiguration_cmd);
12820 install_element(BGP_FLOWSPECV6_NODE,
12821 &neighbor_soft_reconfiguration_cmd);
12822 install_element(BGP_FLOWSPECV6_NODE,
12823 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12824
12825 /* "neighbor attribute-unchanged" commands. */
12826 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12827 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12828 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12829 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12830 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12831 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12832 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12833 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12834 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12835 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12836 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12837 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12838 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12839 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12840 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12841 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12842 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12843 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12844
12845 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12846 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12847
12848 /* "nexthop-local unchanged" commands */
12849 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12850 install_element(BGP_IPV6_NODE,
12851 &no_neighbor_nexthop_local_unchanged_cmd);
12852
12853 /* "neighbor next-hop-self" commands. */
12854 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12855 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12856 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12857 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12858 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12859 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12860 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12861 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12862 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12863 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12864 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12865 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12866 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12867 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12868 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12869 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12870 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12871 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
12872 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12873 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 12874
12875 /* "neighbor next-hop-self force" commands. */
12876 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12877 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12878 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12879 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12880 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12881 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12882 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12883 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12884 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12885 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12886 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12887 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12888 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12889 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12890 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12891 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12892 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12893 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12894
12895 /* "neighbor as-override" commands. */
12896 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12897 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12898 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12899 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12900 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12901 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12902 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12903 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12904 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12905 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12906 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12907 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12908 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12909 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12910 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12911 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12912 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12913 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12914
12915 /* "neighbor remove-private-AS" commands. */
12916 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12917 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12918 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12919 install_element(BGP_NODE,
12920 &no_neighbor_remove_private_as_all_hidden_cmd);
12921 install_element(BGP_NODE,
12922 &neighbor_remove_private_as_replace_as_hidden_cmd);
12923 install_element(BGP_NODE,
12924 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12925 install_element(BGP_NODE,
12926 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12927 install_element(
12928 BGP_NODE,
12929 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12930 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12931 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12932 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12933 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12934 install_element(BGP_IPV4_NODE,
12935 &neighbor_remove_private_as_replace_as_cmd);
12936 install_element(BGP_IPV4_NODE,
12937 &no_neighbor_remove_private_as_replace_as_cmd);
12938 install_element(BGP_IPV4_NODE,
12939 &neighbor_remove_private_as_all_replace_as_cmd);
12940 install_element(BGP_IPV4_NODE,
12941 &no_neighbor_remove_private_as_all_replace_as_cmd);
12942 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12943 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12944 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12945 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12946 install_element(BGP_IPV4M_NODE,
12947 &neighbor_remove_private_as_replace_as_cmd);
12948 install_element(BGP_IPV4M_NODE,
12949 &no_neighbor_remove_private_as_replace_as_cmd);
12950 install_element(BGP_IPV4M_NODE,
12951 &neighbor_remove_private_as_all_replace_as_cmd);
12952 install_element(BGP_IPV4M_NODE,
12953 &no_neighbor_remove_private_as_all_replace_as_cmd);
12954 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12955 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12956 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12957 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12958 install_element(BGP_IPV4L_NODE,
12959 &neighbor_remove_private_as_replace_as_cmd);
12960 install_element(BGP_IPV4L_NODE,
12961 &no_neighbor_remove_private_as_replace_as_cmd);
12962 install_element(BGP_IPV4L_NODE,
12963 &neighbor_remove_private_as_all_replace_as_cmd);
12964 install_element(BGP_IPV4L_NODE,
12965 &no_neighbor_remove_private_as_all_replace_as_cmd);
12966 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12967 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12968 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12969 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12970 install_element(BGP_IPV6_NODE,
12971 &neighbor_remove_private_as_replace_as_cmd);
12972 install_element(BGP_IPV6_NODE,
12973 &no_neighbor_remove_private_as_replace_as_cmd);
12974 install_element(BGP_IPV6_NODE,
12975 &neighbor_remove_private_as_all_replace_as_cmd);
12976 install_element(BGP_IPV6_NODE,
12977 &no_neighbor_remove_private_as_all_replace_as_cmd);
12978 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12979 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12980 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12981 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12982 install_element(BGP_IPV6M_NODE,
12983 &neighbor_remove_private_as_replace_as_cmd);
12984 install_element(BGP_IPV6M_NODE,
12985 &no_neighbor_remove_private_as_replace_as_cmd);
12986 install_element(BGP_IPV6M_NODE,
12987 &neighbor_remove_private_as_all_replace_as_cmd);
12988 install_element(BGP_IPV6M_NODE,
12989 &no_neighbor_remove_private_as_all_replace_as_cmd);
12990 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12991 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12992 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12993 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12994 install_element(BGP_IPV6L_NODE,
12995 &neighbor_remove_private_as_replace_as_cmd);
12996 install_element(BGP_IPV6L_NODE,
12997 &no_neighbor_remove_private_as_replace_as_cmd);
12998 install_element(BGP_IPV6L_NODE,
12999 &neighbor_remove_private_as_all_replace_as_cmd);
13000 install_element(BGP_IPV6L_NODE,
13001 &no_neighbor_remove_private_as_all_replace_as_cmd);
13002 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13003 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13004 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13005 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13006 install_element(BGP_VPNV4_NODE,
13007 &neighbor_remove_private_as_replace_as_cmd);
13008 install_element(BGP_VPNV4_NODE,
13009 &no_neighbor_remove_private_as_replace_as_cmd);
13010 install_element(BGP_VPNV4_NODE,
13011 &neighbor_remove_private_as_all_replace_as_cmd);
13012 install_element(BGP_VPNV4_NODE,
13013 &no_neighbor_remove_private_as_all_replace_as_cmd);
13014 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13015 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13016 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13017 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13018 install_element(BGP_VPNV6_NODE,
13019 &neighbor_remove_private_as_replace_as_cmd);
13020 install_element(BGP_VPNV6_NODE,
13021 &no_neighbor_remove_private_as_replace_as_cmd);
13022 install_element(BGP_VPNV6_NODE,
13023 &neighbor_remove_private_as_all_replace_as_cmd);
13024 install_element(BGP_VPNV6_NODE,
13025 &no_neighbor_remove_private_as_all_replace_as_cmd);
13026
13027 /* "neighbor send-community" commands.*/
13028 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13029 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13030 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13031 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13032 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13033 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13034 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13035 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13036 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13037 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13038 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13039 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13040 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13041 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13042 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13043 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13044 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13045 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13046 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13047 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13048 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13049 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13050 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13051 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13052 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13053 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13054 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13055 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13056 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13057 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13058 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13059 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13060 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13061 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13062 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13063 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13064
13065 /* "neighbor route-reflector" commands.*/
13066 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13067 install_element(BGP_NODE,
13068 &no_neighbor_route_reflector_client_hidden_cmd);
13069 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13070 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13071 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13072 install_element(BGP_IPV4M_NODE,
13073 &no_neighbor_route_reflector_client_cmd);
13074 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13075 install_element(BGP_IPV4L_NODE,
13076 &no_neighbor_route_reflector_client_cmd);
13077 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13078 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13079 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13080 install_element(BGP_IPV6M_NODE,
13081 &no_neighbor_route_reflector_client_cmd);
13082 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13083 install_element(BGP_IPV6L_NODE,
13084 &no_neighbor_route_reflector_client_cmd);
13085 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13086 install_element(BGP_VPNV4_NODE,
13087 &no_neighbor_route_reflector_client_cmd);
13088 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13089 install_element(BGP_VPNV6_NODE,
13090 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13091 install_element(BGP_FLOWSPECV4_NODE,
13092 &neighbor_route_reflector_client_cmd);
13093 install_element(BGP_FLOWSPECV4_NODE,
13094 &no_neighbor_route_reflector_client_cmd);
13095 install_element(BGP_FLOWSPECV6_NODE,
13096 &neighbor_route_reflector_client_cmd);
13097 install_element(BGP_FLOWSPECV6_NODE,
13098 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13099 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13100 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13101
13102 /* "neighbor route-server" commands.*/
13103 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13104 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13105 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13106 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13107 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13108 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13109 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13110 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13111 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13112 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13113 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13114 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13115 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13116 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13117 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13118 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13119 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13120 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13121 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13122 install_element(BGP_FLOWSPECV4_NODE,
13123 &no_neighbor_route_server_client_cmd);
13124 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13125 install_element(BGP_FLOWSPECV6_NODE,
13126 &no_neighbor_route_server_client_cmd);
d62a17ae 13127
13128 /* "neighbor addpath-tx-all-paths" commands.*/
13129 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13130 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13131 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13132 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13133 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13134 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13135 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13136 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13137 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13138 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13139 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13140 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13141 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13142 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13143 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13144 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13145 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13146 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13147
13148 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13149 install_element(BGP_NODE,
13150 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13151 install_element(BGP_NODE,
13152 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13153 install_element(BGP_IPV4_NODE,
13154 &neighbor_addpath_tx_bestpath_per_as_cmd);
13155 install_element(BGP_IPV4_NODE,
13156 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13157 install_element(BGP_IPV4M_NODE,
13158 &neighbor_addpath_tx_bestpath_per_as_cmd);
13159 install_element(BGP_IPV4M_NODE,
13160 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13161 install_element(BGP_IPV4L_NODE,
13162 &neighbor_addpath_tx_bestpath_per_as_cmd);
13163 install_element(BGP_IPV4L_NODE,
13164 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13165 install_element(BGP_IPV6_NODE,
13166 &neighbor_addpath_tx_bestpath_per_as_cmd);
13167 install_element(BGP_IPV6_NODE,
13168 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13169 install_element(BGP_IPV6M_NODE,
13170 &neighbor_addpath_tx_bestpath_per_as_cmd);
13171 install_element(BGP_IPV6M_NODE,
13172 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13173 install_element(BGP_IPV6L_NODE,
13174 &neighbor_addpath_tx_bestpath_per_as_cmd);
13175 install_element(BGP_IPV6L_NODE,
13176 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13177 install_element(BGP_VPNV4_NODE,
13178 &neighbor_addpath_tx_bestpath_per_as_cmd);
13179 install_element(BGP_VPNV4_NODE,
13180 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13181 install_element(BGP_VPNV6_NODE,
13182 &neighbor_addpath_tx_bestpath_per_as_cmd);
13183 install_element(BGP_VPNV6_NODE,
13184 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13185
13186 /* "neighbor passive" commands. */
13187 install_element(BGP_NODE, &neighbor_passive_cmd);
13188 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13189
13190
13191 /* "neighbor shutdown" commands. */
13192 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13193 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13194 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13195 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13196
13197 /* "neighbor capability extended-nexthop" commands.*/
13198 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13199 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13200
13201 /* "neighbor capability orf prefix-list" commands.*/
13202 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13203 install_element(BGP_NODE,
13204 &no_neighbor_capability_orf_prefix_hidden_cmd);
13205 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13206 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13207 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13208 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13209 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13210 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13211 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13212 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13213 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13214 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13215 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13216 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13217
13218 /* "neighbor capability dynamic" commands.*/
13219 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13220 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13221
13222 /* "neighbor dont-capability-negotiate" commands. */
13223 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13224 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13225
13226 /* "neighbor ebgp-multihop" commands. */
13227 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13228 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13229 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13230
13231 /* "neighbor disable-connected-check" commands. */
13232 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13233 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13234
47cbc09b
PM
13235 /* "neighbor enforce-first-as" commands. */
13236 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13237 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13238
d62a17ae 13239 /* "neighbor description" commands. */
13240 install_element(BGP_NODE, &neighbor_description_cmd);
13241 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13242 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13243
13244 /* "neighbor update-source" commands. "*/
13245 install_element(BGP_NODE, &neighbor_update_source_cmd);
13246 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13247
13248 /* "neighbor default-originate" commands. */
13249 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13250 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13251 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13252 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13253 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13254 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13255 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13256 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13257 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13258 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13259 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13260 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13261 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13262 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13263 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13264 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13265 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13266 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13267 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13268 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13269 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13270
13271 /* "neighbor port" commands. */
13272 install_element(BGP_NODE, &neighbor_port_cmd);
13273 install_element(BGP_NODE, &no_neighbor_port_cmd);
13274
13275 /* "neighbor weight" commands. */
13276 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13277 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13278
13279 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13280 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13281 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13282 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13283 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13284 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13285 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13286 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13287 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13288 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13289 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13290 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13291 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13292 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13293 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13294 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13295
13296 /* "neighbor override-capability" commands. */
13297 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13298 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13299
13300 /* "neighbor strict-capability-match" commands. */
13301 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13302 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13303
13304 /* "neighbor timers" commands. */
13305 install_element(BGP_NODE, &neighbor_timers_cmd);
13306 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13307
13308 /* "neighbor timers connect" commands. */
13309 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13310 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13311
13312 /* "neighbor advertisement-interval" commands. */
13313 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13314 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13315
13316 /* "neighbor interface" commands. */
13317 install_element(BGP_NODE, &neighbor_interface_cmd);
13318 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13319
13320 /* "neighbor distribute" commands. */
13321 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13322 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13323 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13324 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13325 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13326 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13327 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13328 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13329 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13330 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13331 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13332 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13333 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13334 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13335 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13336 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13337 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13338 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13339
13340 /* "neighbor prefix-list" commands. */
13341 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13342 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13343 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13344 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13345 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13346 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13347 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13348 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13349 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13350 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13351 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13352 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13353 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13354 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13355 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13356 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13357 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13358 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13359 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13360 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13361 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13362 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13363
13364 /* "neighbor filter-list" commands. */
13365 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13366 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13367 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13368 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13369 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13370 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13371 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13372 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13373 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13374 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13375 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13376 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13377 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13378 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13379 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13380 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13381 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13382 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13383 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13384 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13385 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13386 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13387
13388 /* "neighbor route-map" commands. */
13389 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13390 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13391 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13392 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13393 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13394 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13395 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13396 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13397 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13398 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13399 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13400 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13401 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13402 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13403 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13404 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13405 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13406 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13407 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13408 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13409 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13410 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13411 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13412 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13413
13414 /* "neighbor unsuppress-map" commands. */
13415 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13416 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13417 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13418 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13419 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13420 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13421 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13422 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13423 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13424 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13425 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13426 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13427 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13428 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13429 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13430 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13431 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13432 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13433
13434 /* "neighbor maximum-prefix" commands. */
13435 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13436 install_element(BGP_NODE,
13437 &neighbor_maximum_prefix_threshold_hidden_cmd);
13438 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13439 install_element(BGP_NODE,
13440 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13441 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13442 install_element(BGP_NODE,
13443 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13444 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13445 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13446 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13447 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13448 install_element(BGP_IPV4_NODE,
13449 &neighbor_maximum_prefix_threshold_warning_cmd);
13450 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13451 install_element(BGP_IPV4_NODE,
13452 &neighbor_maximum_prefix_threshold_restart_cmd);
13453 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13454 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13455 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13456 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13457 install_element(BGP_IPV4M_NODE,
13458 &neighbor_maximum_prefix_threshold_warning_cmd);
13459 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13460 install_element(BGP_IPV4M_NODE,
13461 &neighbor_maximum_prefix_threshold_restart_cmd);
13462 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13463 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13464 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13465 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13466 install_element(BGP_IPV4L_NODE,
13467 &neighbor_maximum_prefix_threshold_warning_cmd);
13468 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13469 install_element(BGP_IPV4L_NODE,
13470 &neighbor_maximum_prefix_threshold_restart_cmd);
13471 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13472 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13473 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13474 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13475 install_element(BGP_IPV6_NODE,
13476 &neighbor_maximum_prefix_threshold_warning_cmd);
13477 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13478 install_element(BGP_IPV6_NODE,
13479 &neighbor_maximum_prefix_threshold_restart_cmd);
13480 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13481 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13482 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13483 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13484 install_element(BGP_IPV6M_NODE,
13485 &neighbor_maximum_prefix_threshold_warning_cmd);
13486 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13487 install_element(BGP_IPV6M_NODE,
13488 &neighbor_maximum_prefix_threshold_restart_cmd);
13489 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13490 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13491 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13492 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13493 install_element(BGP_IPV6L_NODE,
13494 &neighbor_maximum_prefix_threshold_warning_cmd);
13495 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13496 install_element(BGP_IPV6L_NODE,
13497 &neighbor_maximum_prefix_threshold_restart_cmd);
13498 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13499 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13500 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13501 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13502 install_element(BGP_VPNV4_NODE,
13503 &neighbor_maximum_prefix_threshold_warning_cmd);
13504 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13505 install_element(BGP_VPNV4_NODE,
13506 &neighbor_maximum_prefix_threshold_restart_cmd);
13507 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13508 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13509 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13510 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13511 install_element(BGP_VPNV6_NODE,
13512 &neighbor_maximum_prefix_threshold_warning_cmd);
13513 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13514 install_element(BGP_VPNV6_NODE,
13515 &neighbor_maximum_prefix_threshold_restart_cmd);
13516 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13517
13518 /* "neighbor allowas-in" */
13519 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13520 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13521 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13522 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13523 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13524 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13525 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13526 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13527 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13528 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13529 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13530 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13531 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13532 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13533 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13534 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13535 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13536 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13537 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13538 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13539
13540 /* address-family commands. */
13541 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13542 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13543#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13544 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13545 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13546#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13547
d62a17ae 13548 install_element(BGP_NODE, &address_family_evpn_cmd);
13549
13550 /* "exit-address-family" command. */
13551 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13552 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13553 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13554 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13555 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13556 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13557 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13558 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13559 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13560 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13561 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13562
13563 /* "clear ip bgp commands" */
13564 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13565
13566 /* clear ip bgp prefix */
13567 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13568 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13569 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13570
13571 /* "show [ip] bgp summary" commands. */
13572 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 13573 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13574 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13575 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13576 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13577 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13578
13579 /* "show [ip] bgp neighbors" commands. */
13580 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13581
13582 /* "show [ip] bgp peer-group" commands. */
13583 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13584
13585 /* "show [ip] bgp paths" commands. */
13586 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13587
13588 /* "show [ip] bgp community" commands. */
13589 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13590
13591 /* "show ip bgp large-community" commands. */
13592 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13593 /* "show [ip] bgp attribute-info" commands. */
13594 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13595 /* "show [ip] bgp route-leak" command */
13596 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13597
13598 /* "redistribute" commands. */
13599 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13600 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13601 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13602 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13603 install_element(BGP_NODE,
13604 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13605 install_element(BGP_NODE,
13606 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13607 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13608 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13609 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13610 install_element(BGP_NODE,
13611 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13612 install_element(BGP_NODE,
13613 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13614 install_element(BGP_NODE,
13615 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13616 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13617 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13618 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13619 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13620 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13621 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13622 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13623 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13624 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13625 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13626 install_element(BGP_IPV4_NODE,
13627 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13628 install_element(BGP_IPV4_NODE,
13629 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13630 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13631 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13632 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13633 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13634 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13635 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13636
b9c7bc5a
PZ
13637 /* import|export vpn [route-map WORD] */
13638 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13639 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13640
12a844a5
DS
13641 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13642 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13643
d62a17ae 13644 /* ttl_security commands */
13645 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13646 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13647
13648 /* "show [ip] bgp memory" commands. */
13649 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13650
acf71666
MK
13651 /* "show bgp martian next-hop" */
13652 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13653
d62a17ae 13654 /* "show [ip] bgp views" commands. */
13655 install_element(VIEW_NODE, &show_bgp_views_cmd);
13656
13657 /* "show [ip] bgp vrfs" commands. */
13658 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13659
13660 /* Community-list. */
13661 community_list_vty();
ddb5b488
PZ
13662
13663 /* vpn-policy commands */
b9c7bc5a
PZ
13664 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13665 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13666 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13667 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13668 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13669 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13670 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13671 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13672 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13673 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13674 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13675 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13676
301ad80a
PG
13677 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13678 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13679
b9c7bc5a
PZ
13680 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13681 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13682 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13683 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13684 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13685 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13686 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13687 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13688 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13689 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13690 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13691 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13692}
6b0655a2 13693
718e3744 13694#include "memory.h"
13695#include "bgp_regex.h"
13696#include "bgp_clist.h"
13697#include "bgp_ecommunity.h"
13698
13699/* VTY functions. */
13700
13701/* Direction value to string conversion. */
d62a17ae 13702static const char *community_direct_str(int direct)
13703{
13704 switch (direct) {
13705 case COMMUNITY_DENY:
13706 return "deny";
13707 case COMMUNITY_PERMIT:
13708 return "permit";
13709 default:
13710 return "unknown";
13711 }
718e3744 13712}
13713
13714/* Display error string. */
d62a17ae 13715static void community_list_perror(struct vty *vty, int ret)
13716{
13717 switch (ret) {
13718 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13719 vty_out(vty, "%% Can't find community-list\n");
13720 break;
13721 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13722 vty_out(vty, "%% Malformed community-list value\n");
13723 break;
13724 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13725 vty_out(vty,
13726 "%% Community name conflict, previously defined as standard community\n");
13727 break;
13728 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13729 vty_out(vty,
13730 "%% Community name conflict, previously defined as expanded community\n");
13731 break;
13732 }
718e3744 13733}
13734
5bf15956
DW
13735/* "community-list" keyword help string. */
13736#define COMMUNITY_LIST_STR "Add a community list entry\n"
13737
5bf15956 13738/* ip community-list standard */
718e3744 13739DEFUN (ip_community_list_standard,
13740 ip_community_list_standard_cmd,
e961923c 13741 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13742 IP_STR
13743 COMMUNITY_LIST_STR
13744 "Community list number (standard)\n"
5bf15956 13745 "Add an standard community-list entry\n"
718e3744 13746 "Community list name\n"
13747 "Specify community to reject\n"
13748 "Specify community to accept\n"
13749 COMMUNITY_VAL_STR)
13750{
d62a17ae 13751 char *cl_name_or_number = NULL;
13752 int direct = 0;
13753 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13754
d62a17ae 13755 int idx = 0;
13756 argv_find(argv, argc, "(1-99)", &idx);
13757 argv_find(argv, argc, "WORD", &idx);
13758 cl_name_or_number = argv[idx]->arg;
13759 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13760 : COMMUNITY_DENY;
13761 argv_find(argv, argc, "AA:NN", &idx);
13762 char *str = argv_concat(argv, argc, idx);
42f914d4 13763
d62a17ae 13764 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13765 style);
42f914d4 13766
d62a17ae 13767 XFREE(MTYPE_TMP, str);
42f914d4 13768
d62a17ae 13769 if (ret < 0) {
13770 /* Display error string. */
13771 community_list_perror(vty, ret);
13772 return CMD_WARNING_CONFIG_FAILED;
13773 }
42f914d4 13774
d62a17ae 13775 return CMD_SUCCESS;
718e3744 13776}
13777
fee6e4e4 13778DEFUN (no_ip_community_list_standard_all,
13779 no_ip_community_list_standard_all_cmd,
e961923c 13780 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13781 NO_STR
13782 IP_STR
13783 COMMUNITY_LIST_STR
13784 "Community list number (standard)\n"
5bf15956
DW
13785 "Add an standard community-list entry\n"
13786 "Community list name\n"
718e3744 13787 "Specify community to reject\n"
13788 "Specify community to accept\n"
13789 COMMUNITY_VAL_STR)
13790{
d62a17ae 13791 char *cl_name_or_number = NULL;
13792 int direct = 0;
13793 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13794
d62a17ae 13795 int idx = 0;
13796 argv_find(argv, argc, "(1-99)", &idx);
13797 argv_find(argv, argc, "WORD", &idx);
13798 cl_name_or_number = argv[idx]->arg;
13799 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13800 : COMMUNITY_DENY;
13801 argv_find(argv, argc, "AA:NN", &idx);
13802 char *str = argv_concat(argv, argc, idx);
42f914d4 13803
d62a17ae 13804 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13805 direct, style);
42f914d4 13806
d62a17ae 13807 XFREE(MTYPE_TMP, str);
daf9ddbb 13808
d62a17ae 13809 if (ret < 0) {
13810 community_list_perror(vty, ret);
13811 return CMD_WARNING_CONFIG_FAILED;
13812 }
42f914d4 13813
d62a17ae 13814 return CMD_SUCCESS;
718e3744 13815}
13816
5bf15956
DW
13817/* ip community-list expanded */
13818DEFUN (ip_community_list_expanded_all,
13819 ip_community_list_expanded_all_cmd,
42f914d4 13820 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13821 IP_STR
13822 COMMUNITY_LIST_STR
13823 "Community list number (expanded)\n"
5bf15956 13824 "Add an expanded community-list entry\n"
718e3744 13825 "Community list name\n"
13826 "Specify community to reject\n"
13827 "Specify community to accept\n"
13828 COMMUNITY_VAL_STR)
13829{
d62a17ae 13830 char *cl_name_or_number = NULL;
13831 int direct = 0;
13832 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13833
d62a17ae 13834 int idx = 0;
13835 argv_find(argv, argc, "(100-500)", &idx);
13836 argv_find(argv, argc, "WORD", &idx);
13837 cl_name_or_number = argv[idx]->arg;
13838 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13839 : COMMUNITY_DENY;
13840 argv_find(argv, argc, "AA:NN", &idx);
13841 char *str = argv_concat(argv, argc, idx);
42f914d4 13842
d62a17ae 13843 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13844 style);
42f914d4 13845
d62a17ae 13846 XFREE(MTYPE_TMP, str);
42f914d4 13847
d62a17ae 13848 if (ret < 0) {
13849 /* Display error string. */
13850 community_list_perror(vty, ret);
13851 return CMD_WARNING_CONFIG_FAILED;
13852 }
42f914d4 13853
d62a17ae 13854 return CMD_SUCCESS;
718e3744 13855}
13856
5bf15956
DW
13857DEFUN (no_ip_community_list_expanded_all,
13858 no_ip_community_list_expanded_all_cmd,
42f914d4 13859 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13860 NO_STR
13861 IP_STR
13862 COMMUNITY_LIST_STR
5bf15956
DW
13863 "Community list number (expanded)\n"
13864 "Add an expanded community-list entry\n"
718e3744 13865 "Community list name\n"
13866 "Specify community to reject\n"
13867 "Specify community to accept\n"
5bf15956 13868 COMMUNITY_VAL_STR)
718e3744 13869{
d62a17ae 13870 char *cl_name_or_number = NULL;
13871 int direct = 0;
13872 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13873
d62a17ae 13874 int idx = 0;
13875 argv_find(argv, argc, "(100-500)", &idx);
13876 argv_find(argv, argc, "WORD", &idx);
13877 cl_name_or_number = argv[idx]->arg;
13878 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13879 : COMMUNITY_DENY;
13880 argv_find(argv, argc, "AA:NN", &idx);
13881 char *str = argv_concat(argv, argc, idx);
42f914d4 13882
d62a17ae 13883 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 13884 direct, style);
42f914d4 13885
d62a17ae 13886 XFREE(MTYPE_TMP, str);
daf9ddbb 13887
d62a17ae 13888 if (ret < 0) {
13889 community_list_perror(vty, ret);
13890 return CMD_WARNING_CONFIG_FAILED;
13891 }
42f914d4 13892
d62a17ae 13893 return CMD_SUCCESS;
718e3744 13894}
13895
8d9b8ed9
PM
13896/* Return configuration string of community-list entry. */
13897static const char *community_list_config_str(struct community_entry *entry)
13898{
13899 const char *str;
13900
13901 if (entry->any)
13902 str = "";
13903 else {
13904 if (entry->style == COMMUNITY_LIST_STANDARD)
13905 str = community_str(entry->u.com, false);
13906 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13907 str = lcommunity_str(entry->u.lcom, false);
13908 else
13909 str = entry->config;
13910 }
13911 return str;
13912}
13913
d62a17ae 13914static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13915{
d62a17ae 13916 struct community_entry *entry;
718e3744 13917
d62a17ae 13918 for (entry = list->head; entry; entry = entry->next) {
13919 if (entry == list->head) {
13920 if (all_digit(list->name))
13921 vty_out(vty, "Community %s list %s\n",
13922 entry->style == COMMUNITY_LIST_STANDARD
13923 ? "standard"
13924 : "(expanded) access",
13925 list->name);
13926 else
13927 vty_out(vty, "Named Community %s list %s\n",
13928 entry->style == COMMUNITY_LIST_STANDARD
13929 ? "standard"
13930 : "expanded",
13931 list->name);
13932 }
13933 if (entry->any)
13934 vty_out(vty, " %s\n",
13935 community_direct_str(entry->direct));
13936 else
13937 vty_out(vty, " %s %s\n",
13938 community_direct_str(entry->direct),
8d9b8ed9 13939 community_list_config_str(entry));
d62a17ae 13940 }
718e3744 13941}
13942
13943DEFUN (show_ip_community_list,
13944 show_ip_community_list_cmd,
13945 "show ip community-list",
13946 SHOW_STR
13947 IP_STR
13948 "List community-list\n")
13949{
d62a17ae 13950 struct community_list *list;
13951 struct community_list_master *cm;
718e3744 13952
d62a17ae 13953 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13954 if (!cm)
13955 return CMD_SUCCESS;
718e3744 13956
d62a17ae 13957 for (list = cm->num.head; list; list = list->next)
13958 community_list_show(vty, list);
718e3744 13959
d62a17ae 13960 for (list = cm->str.head; list; list = list->next)
13961 community_list_show(vty, list);
718e3744 13962
d62a17ae 13963 return CMD_SUCCESS;
718e3744 13964}
13965
13966DEFUN (show_ip_community_list_arg,
13967 show_ip_community_list_arg_cmd,
6147e2c6 13968 "show ip community-list <(1-500)|WORD>",
718e3744 13969 SHOW_STR
13970 IP_STR
13971 "List community-list\n"
13972 "Community-list number\n"
13973 "Community-list name\n")
13974{
d62a17ae 13975 int idx_comm_list = 3;
13976 struct community_list *list;
718e3744 13977
d62a17ae 13978 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13979 COMMUNITY_LIST_MASTER);
13980 if (!list) {
13981 vty_out(vty, "%% Can't find community-list\n");
13982 return CMD_WARNING;
13983 }
718e3744 13984
d62a17ae 13985 community_list_show(vty, list);
718e3744 13986
d62a17ae 13987 return CMD_SUCCESS;
718e3744 13988}
6b0655a2 13989
57d187bc
JS
13990/*
13991 * Large Community code.
13992 */
d62a17ae 13993static int lcommunity_list_set_vty(struct vty *vty, int argc,
13994 struct cmd_token **argv, int style,
13995 int reject_all_digit_name)
13996{
13997 int ret;
13998 int direct;
13999 char *str;
14000 int idx = 0;
14001 char *cl_name;
14002
14003 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14004 : COMMUNITY_DENY;
14005
14006 /* All digit name check. */
14007 idx = 0;
14008 argv_find(argv, argc, "WORD", &idx);
14009 argv_find(argv, argc, "(1-99)", &idx);
14010 argv_find(argv, argc, "(100-500)", &idx);
14011 cl_name = argv[idx]->arg;
14012 if (reject_all_digit_name && all_digit(cl_name)) {
14013 vty_out(vty, "%% Community name cannot have all digits\n");
14014 return CMD_WARNING_CONFIG_FAILED;
14015 }
14016
14017 idx = 0;
14018 argv_find(argv, argc, "AA:BB:CC", &idx);
14019 argv_find(argv, argc, "LINE", &idx);
14020 /* Concat community string argument. */
14021 if (idx)
14022 str = argv_concat(argv, argc, idx);
14023 else
14024 str = NULL;
14025
14026 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14027
14028 /* Free temporary community list string allocated by
14029 argv_concat(). */
14030 if (str)
14031 XFREE(MTYPE_TMP, str);
14032
14033 if (ret < 0) {
14034 community_list_perror(vty, ret);
14035 return CMD_WARNING_CONFIG_FAILED;
14036 }
14037 return CMD_SUCCESS;
14038}
14039
14040static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14041 struct cmd_token **argv, int style)
14042{
14043 int ret;
14044 int direct = 0;
14045 char *str = NULL;
14046 int idx = 0;
14047
14048 argv_find(argv, argc, "permit", &idx);
14049 argv_find(argv, argc, "deny", &idx);
14050
14051 if (idx) {
14052 /* Check the list direct. */
14053 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14054 direct = COMMUNITY_PERMIT;
14055 else
14056 direct = COMMUNITY_DENY;
14057
14058 idx = 0;
14059 argv_find(argv, argc, "LINE", &idx);
14060 argv_find(argv, argc, "AA:AA:NN", &idx);
14061 /* Concat community string argument. */
14062 str = argv_concat(argv, argc, idx);
14063 }
14064
14065 idx = 0;
14066 argv_find(argv, argc, "(1-99)", &idx);
14067 argv_find(argv, argc, "(100-500)", &idx);
14068 argv_find(argv, argc, "WORD", &idx);
14069
14070 /* Unset community list. */
14071 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14072 style);
14073
14074 /* Free temporary community list string allocated by
14075 argv_concat(). */
14076 if (str)
14077 XFREE(MTYPE_TMP, str);
14078
14079 if (ret < 0) {
14080 community_list_perror(vty, ret);
14081 return CMD_WARNING_CONFIG_FAILED;
14082 }
14083
14084 return CMD_SUCCESS;
57d187bc
JS
14085}
14086
14087/* "large-community-list" keyword help string. */
14088#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14089#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14090
14091DEFUN (ip_lcommunity_list_standard,
14092 ip_lcommunity_list_standard_cmd,
52951b63
DS
14093 "ip large-community-list (1-99) <deny|permit>",
14094 IP_STR
14095 LCOMMUNITY_LIST_STR
14096 "Large Community list number (standard)\n"
14097 "Specify large community to reject\n"
7111c1a0 14098 "Specify large community to accept\n")
52951b63 14099{
d62a17ae 14100 return lcommunity_list_set_vty(vty, argc, argv,
14101 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14102}
14103
14104DEFUN (ip_lcommunity_list_standard1,
14105 ip_lcommunity_list_standard1_cmd,
14106 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14107 IP_STR
14108 LCOMMUNITY_LIST_STR
14109 "Large Community list number (standard)\n"
14110 "Specify large community to reject\n"
14111 "Specify large community to accept\n"
14112 LCOMMUNITY_VAL_STR)
14113{
d62a17ae 14114 return lcommunity_list_set_vty(vty, argc, argv,
14115 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
14116}
14117
14118DEFUN (ip_lcommunity_list_expanded,
14119 ip_lcommunity_list_expanded_cmd,
14120 "ip large-community-list (100-500) <deny|permit> LINE...",
14121 IP_STR
14122 LCOMMUNITY_LIST_STR
14123 "Large Community list number (expanded)\n"
14124 "Specify large community to reject\n"
14125 "Specify large community to accept\n"
14126 "An ordered list as a regular-expression\n")
14127{
d62a17ae 14128 return lcommunity_list_set_vty(vty, argc, argv,
14129 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14130}
14131
14132DEFUN (ip_lcommunity_list_name_standard,
14133 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14134 "ip large-community-list standard WORD <deny|permit>",
14135 IP_STR
14136 LCOMMUNITY_LIST_STR
14137 "Specify standard large-community-list\n"
14138 "Large Community list name\n"
14139 "Specify large community to reject\n"
14140 "Specify large community to accept\n")
14141{
d62a17ae 14142 return lcommunity_list_set_vty(vty, argc, argv,
14143 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14144}
14145
14146DEFUN (ip_lcommunity_list_name_standard1,
14147 ip_lcommunity_list_name_standard1_cmd,
14148 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14149 IP_STR
14150 LCOMMUNITY_LIST_STR
14151 "Specify standard large-community-list\n"
14152 "Large Community list name\n"
14153 "Specify large community to reject\n"
14154 "Specify large community to accept\n"
14155 LCOMMUNITY_VAL_STR)
14156{
d62a17ae 14157 return lcommunity_list_set_vty(vty, argc, argv,
14158 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14159}
14160
14161DEFUN (ip_lcommunity_list_name_expanded,
14162 ip_lcommunity_list_name_expanded_cmd,
14163 "ip large-community-list expanded WORD <deny|permit> LINE...",
14164 IP_STR
14165 LCOMMUNITY_LIST_STR
14166 "Specify expanded large-community-list\n"
14167 "Large Community list name\n"
14168 "Specify large community to reject\n"
14169 "Specify large community to accept\n"
14170 "An ordered list as a regular-expression\n")
14171{
d62a17ae 14172 return lcommunity_list_set_vty(vty, argc, argv,
14173 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14174}
14175
14176DEFUN (no_ip_lcommunity_list_standard_all,
14177 no_ip_lcommunity_list_standard_all_cmd,
14178 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14179 NO_STR
14180 IP_STR
14181 LCOMMUNITY_LIST_STR
14182 "Large Community list number (standard)\n"
14183 "Large Community list number (expanded)\n"
14184 "Large Community list name\n")
14185{
d62a17ae 14186 return lcommunity_list_unset_vty(vty, argc, argv,
14187 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14188}
14189
14190DEFUN (no_ip_lcommunity_list_name_expanded_all,
14191 no_ip_lcommunity_list_name_expanded_all_cmd,
14192 "no ip large-community-list expanded WORD",
14193 NO_STR
14194 IP_STR
14195 LCOMMUNITY_LIST_STR
14196 "Specify expanded large-community-list\n"
14197 "Large Community list name\n")
14198{
d62a17ae 14199 return lcommunity_list_unset_vty(vty, argc, argv,
14200 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14201}
14202
14203DEFUN (no_ip_lcommunity_list_standard,
14204 no_ip_lcommunity_list_standard_cmd,
14205 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14206 NO_STR
14207 IP_STR
14208 LCOMMUNITY_LIST_STR
14209 "Large Community list number (standard)\n"
14210 "Specify large community to reject\n"
14211 "Specify large community to accept\n"
14212 LCOMMUNITY_VAL_STR)
14213{
d62a17ae 14214 return lcommunity_list_unset_vty(vty, argc, argv,
14215 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14216}
14217
14218DEFUN (no_ip_lcommunity_list_expanded,
14219 no_ip_lcommunity_list_expanded_cmd,
14220 "no ip large-community-list (100-500) <deny|permit> LINE...",
14221 NO_STR
14222 IP_STR
14223 LCOMMUNITY_LIST_STR
14224 "Large Community list number (expanded)\n"
14225 "Specify large community to reject\n"
14226 "Specify large community to accept\n"
14227 "An ordered list as a regular-expression\n")
14228{
d62a17ae 14229 return lcommunity_list_unset_vty(vty, argc, argv,
14230 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14231}
14232
14233DEFUN (no_ip_lcommunity_list_name_standard,
14234 no_ip_lcommunity_list_name_standard_cmd,
14235 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14236 NO_STR
14237 IP_STR
14238 LCOMMUNITY_LIST_STR
14239 "Specify standard large-community-list\n"
14240 "Large Community list name\n"
14241 "Specify large community to reject\n"
14242 "Specify large community to accept\n"
14243 LCOMMUNITY_VAL_STR)
14244{
d62a17ae 14245 return lcommunity_list_unset_vty(vty, argc, argv,
14246 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14247}
14248
14249DEFUN (no_ip_lcommunity_list_name_expanded,
14250 no_ip_lcommunity_list_name_expanded_cmd,
14251 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14252 NO_STR
14253 IP_STR
14254 LCOMMUNITY_LIST_STR
14255 "Specify expanded large-community-list\n"
14256 "Large community list name\n"
14257 "Specify large community to reject\n"
14258 "Specify large community to accept\n"
14259 "An ordered list as a regular-expression\n")
14260{
d62a17ae 14261 return lcommunity_list_unset_vty(vty, argc, argv,
14262 LARGE_COMMUNITY_LIST_EXPANDED);
14263}
14264
14265static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14266{
14267 struct community_entry *entry;
14268
14269 for (entry = list->head; entry; entry = entry->next) {
14270 if (entry == list->head) {
14271 if (all_digit(list->name))
14272 vty_out(vty, "Large community %s list %s\n",
14273 entry->style == EXTCOMMUNITY_LIST_STANDARD
14274 ? "standard"
14275 : "(expanded) access",
14276 list->name);
14277 else
14278 vty_out(vty,
14279 "Named large community %s list %s\n",
14280 entry->style == EXTCOMMUNITY_LIST_STANDARD
14281 ? "standard"
14282 : "expanded",
14283 list->name);
14284 }
14285 if (entry->any)
14286 vty_out(vty, " %s\n",
14287 community_direct_str(entry->direct));
14288 else
14289 vty_out(vty, " %s %s\n",
14290 community_direct_str(entry->direct),
8d9b8ed9 14291 community_list_config_str(entry));
d62a17ae 14292 }
57d187bc
JS
14293}
14294
14295DEFUN (show_ip_lcommunity_list,
14296 show_ip_lcommunity_list_cmd,
14297 "show ip large-community-list",
14298 SHOW_STR
14299 IP_STR
14300 "List large-community list\n")
14301{
d62a17ae 14302 struct community_list *list;
14303 struct community_list_master *cm;
57d187bc 14304
d62a17ae 14305 cm = community_list_master_lookup(bgp_clist,
14306 LARGE_COMMUNITY_LIST_MASTER);
14307 if (!cm)
14308 return CMD_SUCCESS;
57d187bc 14309
d62a17ae 14310 for (list = cm->num.head; list; list = list->next)
14311 lcommunity_list_show(vty, list);
57d187bc 14312
d62a17ae 14313 for (list = cm->str.head; list; list = list->next)
14314 lcommunity_list_show(vty, list);
57d187bc 14315
d62a17ae 14316 return CMD_SUCCESS;
57d187bc
JS
14317}
14318
14319DEFUN (show_ip_lcommunity_list_arg,
14320 show_ip_lcommunity_list_arg_cmd,
14321 "show ip large-community-list <(1-500)|WORD>",
14322 SHOW_STR
14323 IP_STR
14324 "List large-community list\n"
14325 "large-community-list number\n"
14326 "large-community-list name\n")
14327{
d62a17ae 14328 struct community_list *list;
57d187bc 14329
d62a17ae 14330 list = community_list_lookup(bgp_clist, argv[3]->arg,
14331 LARGE_COMMUNITY_LIST_MASTER);
14332 if (!list) {
14333 vty_out(vty, "%% Can't find extcommunity-list\n");
14334 return CMD_WARNING;
14335 }
57d187bc 14336
d62a17ae 14337 lcommunity_list_show(vty, list);
57d187bc 14338
d62a17ae 14339 return CMD_SUCCESS;
57d187bc
JS
14340}
14341
718e3744 14342/* "extcommunity-list" keyword help string. */
14343#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14344#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14345
14346DEFUN (ip_extcommunity_list_standard,
14347 ip_extcommunity_list_standard_cmd,
e961923c 14348 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14349 IP_STR
14350 EXTCOMMUNITY_LIST_STR
14351 "Extended Community list number (standard)\n"
718e3744 14352 "Specify standard extcommunity-list\n"
5bf15956 14353 "Community list name\n"
718e3744 14354 "Specify community to reject\n"
14355 "Specify community to accept\n"
14356 EXTCOMMUNITY_VAL_STR)
14357{
d62a17ae 14358 int style = EXTCOMMUNITY_LIST_STANDARD;
14359 int direct = 0;
14360 char *cl_number_or_name = NULL;
42f914d4 14361
d62a17ae 14362 int idx = 0;
14363 argv_find(argv, argc, "(1-99)", &idx);
14364 argv_find(argv, argc, "WORD", &idx);
14365 cl_number_or_name = argv[idx]->arg;
14366 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14367 : COMMUNITY_DENY;
14368 argv_find(argv, argc, "AA:NN", &idx);
14369 char *str = argv_concat(argv, argc, idx);
42f914d4 14370
d62a17ae 14371 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14372 direct, style);
42f914d4 14373
d62a17ae 14374 XFREE(MTYPE_TMP, str);
42f914d4 14375
d62a17ae 14376 if (ret < 0) {
14377 community_list_perror(vty, ret);
14378 return CMD_WARNING_CONFIG_FAILED;
14379 }
42f914d4 14380
d62a17ae 14381 return CMD_SUCCESS;
718e3744 14382}
14383
718e3744 14384DEFUN (ip_extcommunity_list_name_expanded,
14385 ip_extcommunity_list_name_expanded_cmd,
e961923c 14386 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14387 IP_STR
14388 EXTCOMMUNITY_LIST_STR
5bf15956 14389 "Extended Community list number (expanded)\n"
718e3744 14390 "Specify expanded extcommunity-list\n"
14391 "Extended Community list name\n"
14392 "Specify community to reject\n"
14393 "Specify community to accept\n"
14394 "An ordered list as a regular-expression\n")
14395{
d62a17ae 14396 int style = EXTCOMMUNITY_LIST_EXPANDED;
14397 int direct = 0;
14398 char *cl_number_or_name = NULL;
42f914d4 14399
d62a17ae 14400 int idx = 0;
14401 argv_find(argv, argc, "(100-500)", &idx);
14402 argv_find(argv, argc, "WORD", &idx);
14403 cl_number_or_name = argv[idx]->arg;
14404 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14405 : COMMUNITY_DENY;
14406 argv_find(argv, argc, "LINE", &idx);
14407 char *str = argv_concat(argv, argc, idx);
42f914d4 14408
d62a17ae 14409 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14410 direct, style);
42f914d4 14411
d62a17ae 14412 XFREE(MTYPE_TMP, str);
42f914d4 14413
d62a17ae 14414 if (ret < 0) {
14415 community_list_perror(vty, ret);
14416 return CMD_WARNING_CONFIG_FAILED;
14417 }
42f914d4 14418
d62a17ae 14419 return CMD_SUCCESS;
718e3744 14420}
14421
fee6e4e4 14422DEFUN (no_ip_extcommunity_list_standard_all,
14423 no_ip_extcommunity_list_standard_all_cmd,
e961923c 14424 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
14425 NO_STR
14426 IP_STR
14427 EXTCOMMUNITY_LIST_STR
14428 "Extended Community list number (standard)\n"
718e3744 14429 "Specify standard extcommunity-list\n"
5bf15956 14430 "Community list name\n"
718e3744 14431 "Specify community to reject\n"
14432 "Specify community to accept\n"
14433 EXTCOMMUNITY_VAL_STR)
14434{
d62a17ae 14435 int style = EXTCOMMUNITY_LIST_STANDARD;
14436 int direct = 0;
14437 char *cl_number_or_name = NULL;
42f914d4 14438
d62a17ae 14439 int idx = 0;
14440 argv_find(argv, argc, "(1-99)", &idx);
14441 argv_find(argv, argc, "WORD", &idx);
14442 cl_number_or_name = argv[idx]->arg;
14443 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14444 : COMMUNITY_DENY;
14445 argv_find(argv, argc, "AA:NN", &idx);
14446 char *str = argv_concat(argv, argc, idx);
42f914d4 14447
d62a17ae 14448 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14449 direct, style);
42f914d4 14450
d62a17ae 14451 XFREE(MTYPE_TMP, str);
42f914d4 14452
d62a17ae 14453 if (ret < 0) {
14454 community_list_perror(vty, ret);
14455 return CMD_WARNING_CONFIG_FAILED;
14456 }
42f914d4 14457
d62a17ae 14458 return CMD_SUCCESS;
718e3744 14459}
14460
5bf15956
DW
14461DEFUN (no_ip_extcommunity_list_expanded_all,
14462 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 14463 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 14464 NO_STR
14465 IP_STR
14466 EXTCOMMUNITY_LIST_STR
14467 "Extended Community list number (expanded)\n"
718e3744 14468 "Specify expanded extcommunity-list\n"
5bf15956 14469 "Extended Community list name\n"
718e3744 14470 "Specify community to reject\n"
14471 "Specify community to accept\n"
14472 "An ordered list as a regular-expression\n")
14473{
d62a17ae 14474 int style = EXTCOMMUNITY_LIST_EXPANDED;
14475 int direct = 0;
14476 char *cl_number_or_name = NULL;
42f914d4 14477
d62a17ae 14478 int idx = 0;
14479 argv_find(argv, argc, "(100-500)", &idx);
14480 argv_find(argv, argc, "WORD", &idx);
14481 cl_number_or_name = argv[idx]->arg;
14482 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14483 : COMMUNITY_DENY;
14484 argv_find(argv, argc, "LINE", &idx);
14485 char *str = argv_concat(argv, argc, idx);
42f914d4 14486
d62a17ae 14487 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 14488 direct, style);
42f914d4 14489
d62a17ae 14490 XFREE(MTYPE_TMP, str);
42f914d4 14491
d62a17ae 14492 if (ret < 0) {
14493 community_list_perror(vty, ret);
14494 return CMD_WARNING_CONFIG_FAILED;
14495 }
42f914d4 14496
d62a17ae 14497 return CMD_SUCCESS;
718e3744 14498}
14499
d62a17ae 14500static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 14501{
d62a17ae 14502 struct community_entry *entry;
718e3744 14503
d62a17ae 14504 for (entry = list->head; entry; entry = entry->next) {
14505 if (entry == list->head) {
14506 if (all_digit(list->name))
14507 vty_out(vty, "Extended community %s list %s\n",
14508 entry->style == EXTCOMMUNITY_LIST_STANDARD
14509 ? "standard"
14510 : "(expanded) access",
14511 list->name);
14512 else
14513 vty_out(vty,
14514 "Named extended community %s list %s\n",
14515 entry->style == EXTCOMMUNITY_LIST_STANDARD
14516 ? "standard"
14517 : "expanded",
14518 list->name);
14519 }
14520 if (entry->any)
14521 vty_out(vty, " %s\n",
14522 community_direct_str(entry->direct));
14523 else
14524 vty_out(vty, " %s %s\n",
14525 community_direct_str(entry->direct),
8d9b8ed9 14526 community_list_config_str(entry));
d62a17ae 14527 }
718e3744 14528}
14529
14530DEFUN (show_ip_extcommunity_list,
14531 show_ip_extcommunity_list_cmd,
14532 "show ip extcommunity-list",
14533 SHOW_STR
14534 IP_STR
14535 "List extended-community list\n")
14536{
d62a17ae 14537 struct community_list *list;
14538 struct community_list_master *cm;
718e3744 14539
d62a17ae 14540 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14541 if (!cm)
14542 return CMD_SUCCESS;
718e3744 14543
d62a17ae 14544 for (list = cm->num.head; list; list = list->next)
14545 extcommunity_list_show(vty, list);
718e3744 14546
d62a17ae 14547 for (list = cm->str.head; list; list = list->next)
14548 extcommunity_list_show(vty, list);
718e3744 14549
d62a17ae 14550 return CMD_SUCCESS;
718e3744 14551}
14552
14553DEFUN (show_ip_extcommunity_list_arg,
14554 show_ip_extcommunity_list_arg_cmd,
6147e2c6 14555 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 14556 SHOW_STR
14557 IP_STR
14558 "List extended-community list\n"
14559 "Extcommunity-list number\n"
14560 "Extcommunity-list name\n")
14561{
d62a17ae 14562 int idx_comm_list = 3;
14563 struct community_list *list;
718e3744 14564
d62a17ae 14565 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14566 EXTCOMMUNITY_LIST_MASTER);
14567 if (!list) {
14568 vty_out(vty, "%% Can't find extcommunity-list\n");
14569 return CMD_WARNING;
14570 }
718e3744 14571
d62a17ae 14572 extcommunity_list_show(vty, list);
718e3744 14573
d62a17ae 14574 return CMD_SUCCESS;
718e3744 14575}
6b0655a2 14576
718e3744 14577/* Display community-list and extcommunity-list configuration. */
d62a17ae 14578static int community_list_config_write(struct vty *vty)
14579{
14580 struct community_list *list;
14581 struct community_entry *entry;
14582 struct community_list_master *cm;
14583 int write = 0;
14584
14585 /* Community-list. */
14586 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14587
14588 for (list = cm->num.head; list; list = list->next)
14589 for (entry = list->head; entry; entry = entry->next) {
14590 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14591 community_direct_str(entry->direct),
14592 community_list_config_str(entry));
14593 write++;
14594 }
14595 for (list = cm->str.head; list; list = list->next)
14596 for (entry = list->head; entry; entry = entry->next) {
14597 vty_out(vty, "ip community-list %s %s %s %s\n",
14598 entry->style == COMMUNITY_LIST_STANDARD
14599 ? "standard"
14600 : "expanded",
14601 list->name, community_direct_str(entry->direct),
14602 community_list_config_str(entry));
14603 write++;
14604 }
14605
14606 /* Extcommunity-list. */
14607 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14608
14609 for (list = cm->num.head; list; list = list->next)
14610 for (entry = list->head; entry; entry = entry->next) {
14611 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14612 list->name, community_direct_str(entry->direct),
14613 community_list_config_str(entry));
14614 write++;
14615 }
14616 for (list = cm->str.head; list; list = list->next)
14617 for (entry = list->head; entry; entry = entry->next) {
14618 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14619 entry->style == EXTCOMMUNITY_LIST_STANDARD
14620 ? "standard"
14621 : "expanded",
14622 list->name, community_direct_str(entry->direct),
14623 community_list_config_str(entry));
14624 write++;
14625 }
14626
14627
14628 /* lcommunity-list. */
14629 cm = community_list_master_lookup(bgp_clist,
14630 LARGE_COMMUNITY_LIST_MASTER);
14631
14632 for (list = cm->num.head; list; list = list->next)
14633 for (entry = list->head; entry; entry = entry->next) {
14634 vty_out(vty, "ip large-community-list %s %s %s\n",
14635 list->name, community_direct_str(entry->direct),
14636 community_list_config_str(entry));
14637 write++;
14638 }
14639 for (list = cm->str.head; list; list = list->next)
14640 for (entry = list->head; entry; entry = entry->next) {
14641 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14642 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14643 ? "standard"
14644 : "expanded",
14645 list->name, community_direct_str(entry->direct),
14646 community_list_config_str(entry));
14647 write++;
14648 }
14649
14650 return write;
14651}
14652
14653static struct cmd_node community_list_node = {
14654 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14655};
14656
d62a17ae 14657static void community_list_vty(void)
14658{
14659 install_node(&community_list_node, community_list_config_write);
14660
14661 /* Community-list. */
14662 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14663 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14664 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14665 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14666 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14667 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14668
14669 /* Extcommunity-list. */
14670 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14671 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14672 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14673 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14674 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14675 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14676
14677 /* Large Community List */
14678 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14679 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14680 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14681 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14682 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14683 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14684 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14685 install_element(CONFIG_NODE,
14686 &no_ip_lcommunity_list_name_expanded_all_cmd);
14687 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14688 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14689 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14690 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14691 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14692 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14693}